test.c 2.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903
  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. #if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
  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. wc_Md2 md2;
  2810. byte hash[WC_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 = WC_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 = WC_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 = WC_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 = WC_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 = WC_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 = WC_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 = WC_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, WC_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, WC_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. wc_Md4 md4;
  2990. byte hash[WC_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 = WC_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 = WC_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 = WC_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 = WC_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 = WC_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 = WC_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 = WC_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, WC_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(WC_HASH_TYPE_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. WOLFSSL_DES_key_schedule ks1;
  8021. WOLFSSL_DES_key_schedule ks2;
  8022. WOLFSSL_DES_key_schedule ks3;
  8023. WOLFSSL_DES_cblock iv4;
  8024. byte tmp[sizeof(vector)];
  8025. XMEMCPY(ks1, key3, sizeof(WOLFSSL_DES_key_schedule));
  8026. XMEMCPY(ks2, key3 + 8, sizeof(WOLFSSL_DES_key_schedule));
  8027. XMEMCPY(ks3, key3 + 16, sizeof(WOLFSSL_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(WOLFSSL_DES_cblock));
  8034. wolfSSL_DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  8035. &iv4, WC_DES_ENCRYPT);
  8036. wolfSSL_DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(vector) - i),
  8037. &ks1, &ks2, &ks3, &iv4, WC_DES_ENCRYPT);
  8038. XMEMCPY(cipher, tmp, sizeof(cipher));
  8039. XMEMCPY(iv4, iv3, sizeof(WOLFSSL_DES_cblock));
  8040. wolfSSL_DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  8041. &iv4, WC_DES_DECRYPT);
  8042. wolfSSL_DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(cipher) - i),
  8043. &ks1, &ks2, &ks3, &iv4, WC_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[WC_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 [WC_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, WC_AES_BLOCK_SIZE);
  8309. if (ret != 0)
  8310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8311. if (XMEMCMP(cipher, cipher2, WC_AES_BLOCK_SIZE))
  8312. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8313. #ifdef HAVE_AES_DECRYPT
  8314. ret = wc_AesOfbDecrypt(dec, plain, cipher2, WC_AES_BLOCK_SIZE);
  8315. if (ret != 0)
  8316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8317. if (XMEMCMP(plain, plain2, WC_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, WC_AES_BLOCK_SIZE);
  8342. if (ret != 0)
  8343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8344. if (XMEMCMP(cipher, cipher3, WC_AES_BLOCK_SIZE))
  8345. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8346. #ifdef HAVE_AES_DECRYPT
  8347. ret = wc_AesOfbDecrypt(dec, plain, cipher3, WC_AES_BLOCK_SIZE);
  8348. if (ret != 0)
  8349. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8350. if (XMEMCMP(plain, plain3, WC_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, WC_AES_BLOCK_SIZE);
  8375. if (ret != 0)
  8376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8377. if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE))
  8378. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8379. ret = wc_AesOfbEncrypt(enc, cipher + WC_AES_BLOCK_SIZE,
  8380. plain1 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
  8381. if (ret != 0)
  8382. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8383. if (XMEMCMP(cipher + WC_AES_BLOCK_SIZE, cipher1 + WC_AES_BLOCK_SIZE,
  8384. WC_AES_BLOCK_SIZE))
  8385. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8386. #ifdef HAVE_AES_DECRYPT
  8387. ret = wc_AesOfbDecrypt(dec, plain, cipher1, WC_AES_BLOCK_SIZE);
  8388. if (ret != 0)
  8389. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8390. if (XMEMCMP(plain, plain1, WC_AES_BLOCK_SIZE))
  8391. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8392. ret = wc_AesOfbDecrypt(dec, plain + WC_AES_BLOCK_SIZE,
  8393. cipher1 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
  8394. if (ret != 0)
  8395. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8396. if (XMEMCMP(plain + WC_AES_BLOCK_SIZE, plain1 + WC_AES_BLOCK_SIZE,
  8397. WC_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, WC_AES_BLOCK_SIZE * 3);
  8412. if (ret != 0)
  8413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8414. if (XMEMCMP(cipher, cipher1, WC_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, WC_AES_BLOCK_SIZE * 3);
  8418. if (ret != 0)
  8419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8420. if (XMEMCMP(plain, plain1, WC_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, WC_AES_BLOCK_SIZE * 2);
  8434. ret = wc_AesOfbEncrypt(enc, cipher, cipher, WC_AES_BLOCK_SIZE * 2);
  8435. if (ret != 0)
  8436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8437. if (XMEMCMP(cipher, cipher1, WC_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, WC_AES_BLOCK_SIZE * 2);
  8441. if (ret != 0)
  8442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8443. if (XMEMCMP(cipher, plain1, WC_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, WC_AES_BLOCK_SIZE);
  8463. if (ret != 0)
  8464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8465. if (XMEMCMP(cipher + 3, cipher1 + 3, WC_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, WC_AES_BLOCK_SIZE);
  8474. if (ret != 0)
  8475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8476. if (XMEMCMP(plain + 6, plain1 + 6, WC_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[WC_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 [WC_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, WC_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, WC_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, WC_AES_BLOCK_SIZE * 2);
  8653. if (ret != 0)
  8654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8655. if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE * 2))
  8656. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8657. /* test restarting encryption process */
  8658. ret = wc_AesCfbEncrypt(enc, cipher + (WC_AES_BLOCK_SIZE * 2),
  8659. msg1 + (WC_AES_BLOCK_SIZE * 2), WC_AES_BLOCK_SIZE);
  8660. if (ret != 0)
  8661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8662. if (XMEMCMP(cipher + (WC_AES_BLOCK_SIZE * 2),
  8663. cipher1 + (WC_AES_BLOCK_SIZE * 2), WC_AES_BLOCK_SIZE))
  8664. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8665. #ifdef HAVE_AES_DECRYPT
  8666. ret = wc_AesCfbDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE * 3);
  8667. if (ret != 0)
  8668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8669. if (XMEMCMP(plain, msg1, WC_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, WC_AES_BLOCK_SIZE * 4);
  8694. if (ret != 0)
  8695. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8696. if (XMEMCMP(cipher, cipher2, WC_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, WC_AES_BLOCK_SIZE * 4);
  8700. if (ret != 0)
  8701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8702. if (XMEMCMP(plain, msg2, WC_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. (WC_AES_BLOCK_SIZE * 4) - 31);
  8739. if (ret != 0)
  8740. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8741. if (XMEMCMP(cipher, cipher3, WC_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. (WC_AES_BLOCK_SIZE * 4) - 31);
  8759. if (ret != 0)
  8760. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8761. if (XMEMCMP(plain, msg3, WC_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(WOLFSSL_NO_AES_CFB_1_8)
  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[WC_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 [WC_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, WC_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, WC_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, WC_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. #if !defined(WOLFCRYPT_ONLY) && !defined(HAVE_FIPS)
  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. #if !defined(WOLFCRYPT_ONLY) && !defined(HAVE_FIPS)
  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. #if !defined(WOLFCRYPT_ONLY) && !defined(HAVE_FIPS)
  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[WC_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 [WC_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. !defined(HAVE_FIPS)
  9112. ret = EVP_test(wolfSSL_EVP_aes_128_cfb8(), key1, iv, msg1, sizeof(msg1),
  9113. cipher1, sizeof(cipher1));
  9114. if (ret != 0) {
  9115. return ret;
  9116. }
  9117. #endif
  9118. ret = wc_AesSetKey(enc, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9119. if (ret != 0)
  9120. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9121. #ifdef HAVE_AES_DECRYPT
  9122. /* decrypt uses AES_ENCRYPTION */
  9123. ret = wc_AesSetKey(dec, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9124. if (ret != 0)
  9125. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9126. #endif
  9127. XMEMSET(cipher, 0, sizeof(cipher));
  9128. ret = wc_AesCfb8Encrypt(enc, cipher, msg1, sizeof(msg1));
  9129. if (ret != 0)
  9130. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9131. if (XMEMCMP(cipher, cipher1, sizeof(cipher1)) != 0)
  9132. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9133. #ifdef HAVE_AES_DECRYPT
  9134. ret = wc_AesCfb8Decrypt(dec, plain, cipher, sizeof(msg1));
  9135. if (ret != 0)
  9136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9137. if (XMEMCMP(plain, msg1, sizeof(msg1)) != 0)
  9138. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9139. #endif /* HAVE_AES_DECRYPT */
  9140. #endif /* WOLFSSL_AES_128 */
  9141. #ifdef WOLFSSL_AES_192
  9142. /* 192 key tests */
  9143. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  9144. if (ret != 0)
  9145. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9146. XMEMSET(cipher, 0, sizeof(cipher));
  9147. ret = wc_AesCfb8Encrypt(enc, cipher, msg2, sizeof(msg2));
  9148. if (ret != 0)
  9149. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9150. if (XMEMCMP(cipher, cipher2, sizeof(msg2)) != 0)
  9151. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9152. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) && \
  9153. !defined(HAVE_FIPS)
  9154. ret = EVP_test(wolfSSL_EVP_aes_192_cfb8(), key2, iv2, msg2, sizeof(msg2),
  9155. cipher2, sizeof(msg2));
  9156. if (ret != 0) {
  9157. return ret;
  9158. }
  9159. #endif
  9160. #endif /* WOLFSSL_AES_192 */
  9161. #ifdef WOLFSSL_AES_256
  9162. /* 256 key tests */
  9163. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  9164. if (ret != 0)
  9165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9166. XMEMSET(cipher, 0, sizeof(cipher));
  9167. ret = wc_AesCfb8Encrypt(enc, cipher, msg3, sizeof(msg3));
  9168. if (ret != 0)
  9169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9170. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  9171. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9172. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) && \
  9173. !defined(HAVE_FIPS)
  9174. ret = EVP_test(wolfSSL_EVP_aes_256_cfb8(), key3, iv3, msg3, sizeof(msg3),
  9175. cipher3, sizeof(msg3));
  9176. if (ret != 0) {
  9177. goto out;
  9178. }
  9179. #endif
  9180. #endif /* WOLFSSL_AES_256 */
  9181. out:
  9182. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9183. wc_AesDelete(enc, &enc);
  9184. #else
  9185. wc_AesFree(enc);
  9186. #endif
  9187. #ifdef HAVE_AES_DECRYPT
  9188. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9189. wc_AesDelete(dec, &dec);
  9190. #else
  9191. wc_AesFree(dec);
  9192. #endif
  9193. #endif
  9194. return ret;
  9195. }
  9196. #endif /* !WOLFSSL_NO_AES_CFB_1_8 */
  9197. #endif /* WOLFSSL_AES_CFB */
  9198. #ifndef HAVE_RENESAS_SYNC
  9199. static wc_test_ret_t aes_key_size_test(void)
  9200. {
  9201. wc_test_ret_t ret;
  9202. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9203. Aes *aes = NULL;
  9204. #else
  9205. Aes aes[1];
  9206. #endif
  9207. byte key16[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9208. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9209. #ifndef WOLFSSL_CRYPTOCELL
  9210. byte key24[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9211. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9212. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
  9213. #endif
  9214. byte key32[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9215. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9216. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9217. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9218. byte iv[] = "1234567890abcdef";
  9219. #ifndef HAVE_FIPS
  9220. word32 keySize;
  9221. #endif
  9222. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9223. aes = wc_AesNew(HEAP_HINT, devId, &ret);
  9224. if (aes == NULL)
  9225. return WC_TEST_RET_ENC_EC(ret);
  9226. #else
  9227. ret = wc_AesInit(aes, HEAP_HINT, devId);
  9228. /* 0 check OK for FIPSv1 */
  9229. if (ret != 0)
  9230. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9231. #endif
  9232. #if !defined(HAVE_FIPS) || \
  9233. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  9234. /* w/ FIPS v1 (cert 2425) wc_AesInit just returns 0 always as it's not
  9235. * supported with that FIPS version */
  9236. ret = wc_AesInit(NULL, HEAP_HINT, devId);
  9237. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9238. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9239. #endif
  9240. #ifndef HAVE_FIPS
  9241. /* Parameter Validation testing. */
  9242. ret = wc_AesGetKeySize(NULL, 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(aes, NULL);
  9246. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9247. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9248. ret = wc_AesGetKeySize(NULL, &keySize);
  9249. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9251. /* Crashes in FIPS */
  9252. ret = wc_AesSetKey(NULL, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9253. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9255. #endif
  9256. /* NULL IV indicates to use all zeros IV. */
  9257. ret = wc_AesSetKey(aes, key16, sizeof(key16), NULL, AES_ENCRYPTION);
  9258. #ifdef WOLFSSL_AES_128
  9259. if (ret != 0)
  9260. #else
  9261. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9262. #endif
  9263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9264. ret = wc_AesSetKey(aes, key32, sizeof(key32) - 1, iv, AES_ENCRYPTION);
  9265. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9266. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9267. /* CryptoCell handles rounds internally */
  9268. #if !defined(HAVE_FIPS) && !defined(WOLFSSL_CRYPTOCELL)
  9269. /* PSA don't use aes->rounds */
  9270. #if !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_AES)
  9271. /* Force invalid rounds */
  9272. aes->rounds = 16;
  9273. ret = wc_AesGetKeySize(aes, &keySize);
  9274. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9276. #endif
  9277. #endif
  9278. ret = wc_AesSetKey(aes, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9279. #ifdef WOLFSSL_AES_128
  9280. if (ret != 0)
  9281. #else
  9282. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9283. #endif
  9284. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9285. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_128)
  9286. ret = wc_AesGetKeySize(aes, &keySize);
  9287. if (ret != 0 || keySize != sizeof(key16))
  9288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9289. #endif
  9290. #ifndef WOLFSSL_CRYPTOCELL
  9291. /* Cryptocell only supports AES-128 key size */
  9292. ret = wc_AesSetKey(aes, key24, sizeof(key24), iv, AES_ENCRYPTION);
  9293. #ifdef WOLFSSL_AES_192
  9294. if (ret != 0)
  9295. #else
  9296. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9297. #endif
  9298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9299. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_192)
  9300. ret = wc_AesGetKeySize(aes, &keySize);
  9301. if (ret != 0 || keySize != sizeof(key24))
  9302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9303. #endif
  9304. ret = wc_AesSetKey(aes, key32, sizeof(key32), iv, AES_ENCRYPTION);
  9305. #ifdef WOLFSSL_AES_256
  9306. if (ret != 0)
  9307. #else
  9308. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9309. #endif
  9310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9311. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_256)
  9312. ret = wc_AesGetKeySize(aes, &keySize);
  9313. if (ret != 0 || keySize != sizeof(key32))
  9314. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9315. #endif
  9316. #endif /* !WOLFSSL_CRYPTOCELL */
  9317. ret = 0; /* success */
  9318. out:
  9319. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9320. wc_AesDelete(aes, &aes);
  9321. #else
  9322. wc_AesFree(aes);
  9323. #endif
  9324. return ret;
  9325. }
  9326. #endif /* !HAVE_RENESAS_SYNC */
  9327. #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  9328. /* test vectors from http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html */
  9329. #ifdef WOLFSSL_AES_128
  9330. static wc_test_ret_t aes_xts_128_test(void)
  9331. {
  9332. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9333. XtsAes *aes = NULL;
  9334. #else
  9335. XtsAes aes[1];
  9336. #endif
  9337. int aes_inited = 0;
  9338. wc_test_ret_t ret = 0;
  9339. unsigned char buf[WC_AES_BLOCK_SIZE * 2 + 8];
  9340. unsigned char cipher[WC_AES_BLOCK_SIZE * 2 + 8];
  9341. #ifdef WOLFSSL_AESXTS_STREAM
  9342. struct XtsAesStreamData stream;
  9343. #endif
  9344. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9345. !defined(WOLFSSL_AFALG)
  9346. #define LARGE_XTS_SZ 1024
  9347. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9348. byte* large_input = NULL;
  9349. #else
  9350. byte large_input[LARGE_XTS_SZ];
  9351. #endif
  9352. #endif
  9353. /* 128 key tests */
  9354. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9355. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  9356. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  9357. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  9358. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  9359. };
  9360. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9361. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9362. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9363. };
  9364. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9365. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9366. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9367. };
  9368. /* plain text test of partial block is not from NIST test vector list */
  9369. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9370. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9371. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9372. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9373. };
  9374. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9375. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a,
  9376. 0x82, 0x50, 0x81, 0xd5, 0xbe, 0x47, 0x1c, 0x63
  9377. };
  9378. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9379. 0x39, 0x25, 0x79, 0x05, 0xdf, 0xcc, 0x77, 0x76,
  9380. 0x6c, 0x87, 0x0a, 0x80, 0x6a, 0x60, 0xe3, 0xc0,
  9381. 0x93, 0xd1, 0x2a, 0xcf, 0xcb, 0x51, 0x42, 0xfa,
  9382. 0x09, 0x69, 0x89, 0x62, 0x5b, 0x60, 0xdb, 0x16
  9383. };
  9384. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9385. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9386. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9387. };
  9388. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9389. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9390. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9391. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9392. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9393. };
  9394. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9395. 0xd6, 0xbe, 0x04, 0x6d, 0x41, 0xf2, 0x3b, 0x5e,
  9396. 0xd7, 0x0b, 0x6b, 0x3d, 0x5c, 0x8e, 0x66, 0x23,
  9397. 0x2b, 0xe6, 0xb8, 0x07, 0xd4, 0xdc, 0xc6, 0x0e,
  9398. 0xff, 0x8d, 0xbc, 0x1d, 0x9f, 0x7f, 0xc8, 0x22
  9399. };
  9400. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9401. 0x2b, 0xf7, 0x2c, 0xf3, 0xeb, 0x85, 0xef, 0x7b,
  9402. 0x0b, 0x76, 0xa0, 0xaa, 0xf3, 0x3f, 0x25, 0x8b,
  9403. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a
  9404. };
  9405. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9406. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9407. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9408. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9409. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9410. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9411. };
  9412. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9413. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9414. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9415. };
  9416. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9417. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9418. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9419. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9420. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9421. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9422. };
  9423. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9424. 0xA2, 0x07, 0x47, 0x76, 0x3F, 0xEC, 0x0C, 0x23,
  9425. 0x1B, 0xD0, 0xBD, 0x46, 0x9A, 0x27, 0x38, 0x12,
  9426. 0x95, 0x02, 0x3D, 0x5D, 0xC6, 0x94, 0x51, 0x36,
  9427. 0xA0, 0x85, 0xD2, 0x69, 0x6E, 0x87, 0x0A, 0xBF,
  9428. 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD
  9429. };
  9430. #endif /* HAVE_FIPS */
  9431. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9432. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9433. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9434. #endif
  9435. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  9436. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  9437. ret = EVP_test(wolfSSL_EVP_aes_128_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  9438. if (ret != 0) {
  9439. printf("EVP_aes_128_xts failed!\n");
  9440. goto out;
  9441. }
  9442. #endif
  9443. XMEMSET(buf, 0, sizeof(buf));
  9444. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9445. if (ret != 0)
  9446. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9447. else
  9448. aes_inited = 1;
  9449. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9450. if (ret != 0)
  9451. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9452. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9453. #if defined(WOLFSSL_ASYNC_CRYPT)
  9454. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9455. #endif
  9456. if (ret != 0)
  9457. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9458. if (XMEMCMP(c2, buf, sizeof(c2)))
  9459. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9460. #ifdef WOLFSSL_AESXTS_STREAM
  9461. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9462. #if defined(WOLFSSL_ASYNC_CRYPT)
  9463. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9464. #endif
  9465. if (ret != 0)
  9466. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9467. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream);
  9468. #if defined(WOLFSSL_ASYNC_CRYPT)
  9469. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9470. #endif
  9471. if (ret != 0)
  9472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9473. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream);
  9474. #if defined(WOLFSSL_ASYNC_CRYPT)
  9475. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9476. #endif
  9477. if (ret != 0)
  9478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9479. if (XMEMCMP(c2, buf, sizeof(c2)))
  9480. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9481. #endif /* WOLFSSL_AESXTS_STREAM */
  9482. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9483. defined(WC_C_DYNAMIC_FALLBACK)
  9484. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9485. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9486. #if defined(WOLFSSL_ASYNC_CRYPT)
  9487. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9488. #endif
  9489. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9490. if (ret != 0)
  9491. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9492. if (XMEMCMP(c2, buf, sizeof(c2)))
  9493. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9494. #endif
  9495. XMEMSET(buf, 0, sizeof(buf));
  9496. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9497. if (ret != 0)
  9498. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9499. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9500. #if defined(WOLFSSL_ASYNC_CRYPT)
  9501. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9502. #endif
  9503. if (ret != 0)
  9504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9505. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  9506. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9507. #ifdef WOLFSSL_AESXTS_STREAM
  9508. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i2), &stream);
  9509. #if defined(WOLFSSL_ASYNC_CRYPT)
  9510. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9511. #endif
  9512. if (ret != 0)
  9513. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9514. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  9515. #if defined(WOLFSSL_ASYNC_CRYPT)
  9516. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9517. #endif
  9518. if (ret != 0)
  9519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9520. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9521. #if defined(WOLFSSL_ASYNC_CRYPT)
  9522. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9523. #endif
  9524. if (ret != 0)
  9525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9526. if (XMEMCMP(c1, buf, sizeof(c1)))
  9527. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9528. #endif /* WOLFSSL_AESXTS_STREAM */
  9529. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9530. defined(WC_C_DYNAMIC_FALLBACK)
  9531. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9532. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9533. #if defined(WOLFSSL_ASYNC_CRYPT)
  9534. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9535. #endif
  9536. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9537. if (ret != 0)
  9538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9539. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  9540. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9541. #endif
  9542. /* partial block encryption test */
  9543. XMEMSET(cipher, 0, sizeof(cipher));
  9544. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9545. #if defined(WOLFSSL_ASYNC_CRYPT)
  9546. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9547. #endif
  9548. if (ret != 0)
  9549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9550. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9551. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9552. #ifdef WOLFSSL_AESXTS_STREAM
  9553. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9554. #if defined(WOLFSSL_ASYNC_CRYPT)
  9555. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9556. #endif
  9557. if (ret != 0)
  9558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9559. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  9560. #if defined(WOLFSSL_ASYNC_CRYPT)
  9561. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9562. #endif
  9563. if (ret != 0)
  9564. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9565. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9566. #if defined(WOLFSSL_ASYNC_CRYPT)
  9567. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9568. #endif
  9569. if (ret != 0)
  9570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9571. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  9572. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9573. #endif /* WOLFSSL_AESXTS_STREAM */
  9574. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9575. defined(WC_C_DYNAMIC_FALLBACK)
  9576. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9577. XMEMSET(cipher, 0, sizeof(cipher));
  9578. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9579. #if defined(WOLFSSL_ASYNC_CRYPT)
  9580. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9581. #endif
  9582. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9583. if (ret != 0)
  9584. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9585. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9586. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9587. #endif
  9588. /* partial block decrypt test */
  9589. XMEMSET(buf, 0, sizeof(buf));
  9590. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9591. if (ret != 0)
  9592. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9593. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9594. #if defined(WOLFSSL_ASYNC_CRYPT)
  9595. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9596. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9597. #else
  9598. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9599. #endif
  9600. #endif
  9601. if (ret != 0)
  9602. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9603. if (XMEMCMP(pp, buf, sizeof(pp)))
  9604. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9605. #ifdef WOLFSSL_AESXTS_STREAM
  9606. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9607. #if defined(WOLFSSL_ASYNC_CRYPT)
  9608. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9609. #endif
  9610. if (ret != 0)
  9611. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9612. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  9613. #if defined(WOLFSSL_ASYNC_CRYPT)
  9614. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9615. #endif
  9616. if (ret != 0)
  9617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9618. if (XMEMCMP(pp, buf, sizeof(pp)))
  9619. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9620. #endif /* WOLFSSL_AESXTS_STREAM */
  9621. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9622. defined(WC_C_DYNAMIC_FALLBACK)
  9623. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9624. XMEMSET(buf, 0, sizeof(buf));
  9625. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9626. #if defined(WOLFSSL_ASYNC_CRYPT)
  9627. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9628. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9629. #else
  9630. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9631. #endif
  9632. #endif
  9633. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9634. if (ret != 0)
  9635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9636. if (XMEMCMP(pp, buf, sizeof(pp)))
  9637. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9638. #endif
  9639. /* NIST decrypt test vector */
  9640. XMEMSET(buf, 0, sizeof(buf));
  9641. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9642. #if defined(WOLFSSL_ASYNC_CRYPT)
  9643. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9644. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9645. #else
  9646. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9647. #endif
  9648. #endif
  9649. if (ret != 0)
  9650. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9651. if (XMEMCMP(p1, buf, sizeof(p1)))
  9652. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9653. #ifdef WOLFSSL_AESXTS_STREAM
  9654. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9655. #if defined(WOLFSSL_ASYNC_CRYPT)
  9656. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9657. #endif
  9658. if (ret != 0)
  9659. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9660. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  9661. #if defined(WOLFSSL_ASYNC_CRYPT)
  9662. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9663. #endif
  9664. if (ret != 0)
  9665. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9666. if (XMEMCMP(p1, buf, sizeof(p1)))
  9667. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9668. #endif /* WOLFSSL_AESXTS_STREAM */
  9669. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9670. defined(WC_C_DYNAMIC_FALLBACK)
  9671. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9672. XMEMSET(buf, 0, sizeof(buf));
  9673. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9674. #if defined(WOLFSSL_ASYNC_CRYPT)
  9675. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9676. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9677. #else
  9678. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9679. #endif
  9680. #endif
  9681. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9682. if (ret != 0)
  9683. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9684. if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE))
  9685. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9686. #endif
  9687. /* fail case with decrypting using wrong key */
  9688. XMEMSET(buf, 0, sizeof(buf));
  9689. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9690. #if defined(WOLFSSL_ASYNC_CRYPT)
  9691. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9692. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9693. #else
  9694. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9695. #endif
  9696. #endif
  9697. if (ret != 0)
  9698. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9699. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  9700. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9701. /* set correct key and retest */
  9702. XMEMSET(buf, 0, sizeof(buf));
  9703. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  9704. if (ret != 0)
  9705. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9706. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9707. #if defined(WOLFSSL_ASYNC_CRYPT)
  9708. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9709. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9710. #else
  9711. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9712. #endif
  9713. #endif
  9714. if (ret != 0)
  9715. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9716. if (XMEMCMP(p2, buf, sizeof(p2)))
  9717. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9718. #ifndef HAVE_FIPS
  9719. /* Test ciphertext stealing in-place. */
  9720. XMEMCPY(buf, p3, sizeof(p3));
  9721. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  9722. if (ret != 0)
  9723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9724. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  9725. #if defined(WOLFSSL_ASYNC_CRYPT)
  9726. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9727. #endif
  9728. if (ret != 0)
  9729. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9730. if (XMEMCMP(c3, buf, sizeof(c3)))
  9731. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9732. #ifdef WOLFSSL_AESXTS_STREAM
  9733. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  9734. #if defined(WOLFSSL_ASYNC_CRYPT)
  9735. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9736. #endif
  9737. if (ret != 0)
  9738. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9739. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, WC_AES_BLOCK_SIZE, &stream);
  9740. #if defined(WOLFSSL_ASYNC_CRYPT)
  9741. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9742. #endif
  9743. if (ret != 0)
  9744. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9745. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p3 + WC_AES_BLOCK_SIZE, sizeof(p3) - WC_AES_BLOCK_SIZE, &stream);
  9746. #if defined(WOLFSSL_ASYNC_CRYPT)
  9747. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9748. #endif
  9749. if (ret != 0)
  9750. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9751. if (XMEMCMP(c3, buf, sizeof(c3)))
  9752. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9753. #endif /* WOLFSSL_AESXTS_STREAM */
  9754. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  9755. if (ret != 0)
  9756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9757. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  9758. #if defined(WOLFSSL_ASYNC_CRYPT)
  9759. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9760. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9761. #else
  9762. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9763. #endif
  9764. #endif
  9765. if (ret != 0)
  9766. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9767. if (XMEMCMP(p3, buf, sizeof(p3)))
  9768. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9769. #ifdef WOLFSSL_AESXTS_STREAM
  9770. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  9771. #if defined(WOLFSSL_ASYNC_CRYPT)
  9772. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9773. #endif
  9774. if (ret != 0)
  9775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9776. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, WC_AES_BLOCK_SIZE, &stream);
  9777. #if defined(WOLFSSL_ASYNC_CRYPT)
  9778. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9779. #endif
  9780. if (ret != 0)
  9781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9782. ret = wc_AesXtsDecryptFinal(aes, buf + WC_AES_BLOCK_SIZE, c3 + WC_AES_BLOCK_SIZE, sizeof(c3) - WC_AES_BLOCK_SIZE, &stream);
  9783. #if defined(WOLFSSL_ASYNC_CRYPT)
  9784. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9785. #endif
  9786. if (ret != 0)
  9787. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9788. if (XMEMCMP(p3, buf, sizeof(p3)))
  9789. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9790. #endif /* WOLFSSL_AESXTS_STREAM */
  9791. #endif /* !HAVE_FIPS */
  9792. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9793. !defined(WOLFSSL_AFALG)
  9794. {
  9795. int i;
  9796. int j;
  9797. #ifdef WOLFSSL_AESXTS_STREAM
  9798. int k;
  9799. #endif
  9800. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9801. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  9802. DYNAMIC_TYPE_TMP_BUFFER);
  9803. if (large_input == NULL)
  9804. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  9805. #endif
  9806. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9807. large_input[i] = (byte)i;
  9808. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9809. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9810. if (ret != 0)
  9811. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9812. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9813. sizeof(i1));
  9814. #if defined(WOLFSSL_ASYNC_CRYPT)
  9815. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9816. #endif
  9817. if (ret != 0)
  9818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9819. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9820. if (ret != 0)
  9821. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9822. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9823. sizeof(i1));
  9824. #if defined(WOLFSSL_ASYNC_CRYPT)
  9825. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9826. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9827. WC_ASYNC_FLAG_NONE);
  9828. #else
  9829. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9830. #endif
  9831. #endif
  9832. if (ret != 0)
  9833. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9834. for (i = 0; i < j; i++) {
  9835. if (large_input[i] != (byte)i) {
  9836. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9837. }
  9838. }
  9839. }
  9840. #ifdef WOLFSSL_AESXTS_STREAM
  9841. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9842. large_input[i] = (byte)i;
  9843. /* first, encrypt block by block then decrypt with a one-shot call. */
  9844. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9845. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9846. if (ret != 0)
  9847. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9848. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9849. #if defined(WOLFSSL_ASYNC_CRYPT)
  9850. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9851. #endif
  9852. if (ret != 0)
  9853. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9854. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  9855. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  9856. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9857. else
  9858. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  9859. #if defined(WOLFSSL_ASYNC_CRYPT)
  9860. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9861. #endif
  9862. if (ret != 0)
  9863. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9864. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  9865. break;
  9866. }
  9867. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9868. if (ret != 0)
  9869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9870. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9871. sizeof(i1));
  9872. #if defined(WOLFSSL_ASYNC_CRYPT)
  9873. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9874. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9875. WC_ASYNC_FLAG_NONE);
  9876. #else
  9877. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9878. #endif
  9879. #endif
  9880. if (ret != 0)
  9881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9882. for (i = 0; i < j; i++) {
  9883. if (large_input[i] != (byte)i) {
  9884. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9885. }
  9886. }
  9887. }
  9888. /* second, encrypt with a one-shot call then decrypt block by block. */
  9889. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9890. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9891. if (ret != 0)
  9892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9893. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9894. sizeof(i1));
  9895. #if defined(WOLFSSL_ASYNC_CRYPT)
  9896. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9897. #endif
  9898. if (ret != 0)
  9899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9900. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9901. if (ret != 0)
  9902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9903. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9904. #if defined(WOLFSSL_ASYNC_CRYPT)
  9905. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9906. #endif
  9907. if (ret != 0)
  9908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9909. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  9910. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  9911. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9912. else
  9913. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  9914. #if defined(WOLFSSL_ASYNC_CRYPT)
  9915. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9916. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9917. WC_ASYNC_FLAG_NONE);
  9918. #else
  9919. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9920. #endif
  9921. #endif
  9922. if (ret != 0)
  9923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9924. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  9925. break;
  9926. }
  9927. for (i = 0; i < j; i++) {
  9928. if (large_input[i] != (byte)i) {
  9929. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9930. }
  9931. }
  9932. }
  9933. #endif /* WOLFSSL_AESXTS_STREAM */
  9934. }
  9935. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  9936. * !WOLFSSL_AFALG
  9937. */
  9938. out:
  9939. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9940. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  9941. !defined(WOLFSSL_NO_MALLOC)
  9942. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9943. #endif
  9944. if (aes_inited)
  9945. wc_AesXtsFree(aes);
  9946. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9947. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9948. #endif
  9949. return ret;
  9950. }
  9951. #endif /* WOLFSSL_AES_128 */
  9952. #ifdef WOLFSSL_AES_192
  9953. static wc_test_ret_t aes_xts_192_test(void)
  9954. {
  9955. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9956. XtsAes *aes = NULL;
  9957. #else
  9958. XtsAes aes[1];
  9959. #endif
  9960. int aes_inited = 0;
  9961. wc_test_ret_t ret = 0;
  9962. unsigned char buf[WC_AES_BLOCK_SIZE * 2 + 8];
  9963. unsigned char cipher[WC_AES_BLOCK_SIZE * 2 + 8];
  9964. #ifdef WOLFSSL_AESXTS_STREAM
  9965. struct XtsAesStreamData stream;
  9966. #endif
  9967. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9968. !defined(WOLFSSL_AFALG)
  9969. #define LARGE_XTS_SZ 1024
  9970. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9971. byte* large_input = NULL;
  9972. #else
  9973. byte large_input[LARGE_XTS_SZ];
  9974. #endif
  9975. #endif
  9976. /* 192 bit key tests */
  9977. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9978. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  9979. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  9980. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  9981. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  9982. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  9983. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3
  9984. };
  9985. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9986. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9987. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9988. };
  9989. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9990. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9991. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9992. };
  9993. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9994. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9995. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9996. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9997. };
  9998. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9999. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4,
  10000. 0xdb, 0x4e, 0xd3, 0x69, 0xdf, 0x8e, 0x3a, 0xe0
  10001. };
  10002. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10003. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10004. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10005. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10006. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10007. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10008. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a
  10009. };
  10010. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10011. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  10012. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  10013. };
  10014. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10015. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  10016. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  10017. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  10018. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  10019. };
  10020. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10021. 0x6c, 0xa6, 0xb5, 0x73, 0x48, 0xf1, 0x89, 0xfa,
  10022. 0xdd, 0x80, 0x72, 0x1f, 0xb8, 0x56, 0x0c, 0xa2,
  10023. 0x35, 0xd4, 0x08, 0xbf, 0x24, 0xcb, 0xec, 0xdb,
  10024. 0x81, 0xe0, 0xe6, 0x4f, 0x3d, 0x1c, 0x5c, 0x46
  10025. };
  10026. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  10027. 0xe9, 0x58, 0xfe, 0xab, 0x66, 0xb4, 0xf1, 0x79,
  10028. 0x91, 0x3f, 0x91, 0xdc, 0x6f, 0xdf, 0xd6, 0xac,
  10029. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4
  10030. };
  10031. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  10032. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  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. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10037. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10038. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10039. };
  10040. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  10041. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10042. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10043. };
  10044. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  10045. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10046. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10047. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10048. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10049. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10050. };
  10051. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  10052. 0xa4, 0xf2, 0x71, 0x5d, 0x80, 0x60, 0x68, 0xa0,
  10053. 0x80, 0x61, 0xd7, 0xc1, 0x55, 0xc8, 0x3a, 0x2e,
  10054. 0xd7, 0xf4, 0x62, 0xaf, 0xbd, 0x2d, 0xf9, 0x5f,
  10055. 0xe8, 0xc5, 0x99, 0x3d, 0x58, 0x3c, 0xeb, 0xba,
  10056. 0x86, 0xea, 0x2c, 0x7e, 0x1f, 0xba, 0x81, 0xde
  10057. };
  10058. #endif /* HAVE_FIPS */
  10059. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10060. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10061. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10062. #endif
  10063. XMEMSET(buf, 0, sizeof(buf));
  10064. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10065. if (ret != 0)
  10066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10067. else
  10068. aes_inited = 1;
  10069. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10070. if (ret != 0)
  10071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10072. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10073. #if defined(WOLFSSL_ASYNC_CRYPT)
  10074. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10075. #endif
  10076. if (ret != 0)
  10077. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10078. if (XMEMCMP(c2, buf, sizeof(c2)))
  10079. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10080. #ifdef WOLFSSL_AESXTS_STREAM
  10081. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10082. #if defined(WOLFSSL_ASYNC_CRYPT)
  10083. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10084. #endif
  10085. if (ret != 0)
  10086. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10087. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream);
  10088. #if defined(WOLFSSL_ASYNC_CRYPT)
  10089. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10090. #endif
  10091. if (ret != 0)
  10092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10093. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream);
  10094. #if defined(WOLFSSL_ASYNC_CRYPT)
  10095. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10096. #endif
  10097. if (ret != 0)
  10098. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10099. if (XMEMCMP(c2, buf, sizeof(c2)))
  10100. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10101. #endif /* WOLFSSL_AESXTS_STREAM */
  10102. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10103. defined(WC_C_DYNAMIC_FALLBACK)
  10104. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10105. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10106. #if defined(WOLFSSL_ASYNC_CRYPT)
  10107. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10108. #endif
  10109. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10110. if (ret != 0)
  10111. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10112. if (XMEMCMP(c2, buf, sizeof(c2)))
  10113. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10114. #endif
  10115. XMEMSET(buf, 0, sizeof(buf));
  10116. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10117. if (ret != 0)
  10118. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10119. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10120. #if defined(WOLFSSL_ASYNC_CRYPT)
  10121. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10122. #endif
  10123. if (ret != 0)
  10124. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10125. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  10126. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10127. #ifdef WOLFSSL_AESXTS_STREAM
  10128. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10129. #if defined(WOLFSSL_ASYNC_CRYPT)
  10130. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10131. #endif
  10132. if (ret != 0)
  10133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10134. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10135. #if defined(WOLFSSL_ASYNC_CRYPT)
  10136. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10137. #endif
  10138. if (ret != 0)
  10139. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10140. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10141. #if defined(WOLFSSL_ASYNC_CRYPT)
  10142. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10143. #endif
  10144. if (ret != 0)
  10145. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10146. if (XMEMCMP(c1, buf, sizeof(c1)))
  10147. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10148. #endif /* WOLFSSL_AESXTS_STREAM */
  10149. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10150. defined(WC_C_DYNAMIC_FALLBACK)
  10151. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10152. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10153. #if defined(WOLFSSL_ASYNC_CRYPT)
  10154. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10155. #endif
  10156. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10157. if (ret != 0)
  10158. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10159. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  10160. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10161. #endif
  10162. /* partial block encryption test */
  10163. XMEMSET(cipher, 0, sizeof(cipher));
  10164. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10165. #if defined(WOLFSSL_ASYNC_CRYPT)
  10166. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10167. #endif
  10168. if (ret != 0)
  10169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10170. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10171. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10172. #ifdef WOLFSSL_AESXTS_STREAM
  10173. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10174. #if defined(WOLFSSL_ASYNC_CRYPT)
  10175. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10176. #endif
  10177. if (ret != 0)
  10178. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10179. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  10180. #if defined(WOLFSSL_ASYNC_CRYPT)
  10181. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10182. #endif
  10183. if (ret != 0)
  10184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10185. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10186. #if defined(WOLFSSL_ASYNC_CRYPT)
  10187. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10188. #endif
  10189. if (ret != 0)
  10190. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10191. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  10192. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10193. #endif /* WOLFSSL_AESXTS_STREAM */
  10194. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10195. defined(WC_C_DYNAMIC_FALLBACK)
  10196. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10197. XMEMSET(cipher, 0, sizeof(cipher));
  10198. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10199. #if defined(WOLFSSL_ASYNC_CRYPT)
  10200. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10201. #endif
  10202. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10203. if (ret != 0)
  10204. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10205. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10206. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10207. #endif
  10208. /* partial block decrypt test */
  10209. XMEMSET(buf, 0, sizeof(buf));
  10210. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10211. if (ret != 0)
  10212. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10213. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10214. #if defined(WOLFSSL_ASYNC_CRYPT)
  10215. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10216. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10217. #else
  10218. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10219. #endif
  10220. #endif
  10221. if (ret != 0)
  10222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10223. if (XMEMCMP(pp, buf, sizeof(pp)))
  10224. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10225. #ifdef WOLFSSL_AESXTS_STREAM
  10226. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10227. #if defined(WOLFSSL_ASYNC_CRYPT)
  10228. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10229. #endif
  10230. if (ret != 0)
  10231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10232. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  10233. #if defined(WOLFSSL_ASYNC_CRYPT)
  10234. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10235. #endif
  10236. if (ret != 0)
  10237. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10238. if (XMEMCMP(pp, buf, sizeof(pp)))
  10239. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10240. #endif /* WOLFSSL_AESXTS_STREAM */
  10241. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10242. defined(WC_C_DYNAMIC_FALLBACK)
  10243. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10244. XMEMSET(buf, 0, sizeof(buf));
  10245. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10246. #if defined(WOLFSSL_ASYNC_CRYPT)
  10247. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10248. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10249. #else
  10250. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10251. #endif
  10252. #endif
  10253. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10254. if (ret != 0)
  10255. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10256. if (XMEMCMP(pp, buf, sizeof(pp)))
  10257. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10258. #endif
  10259. /* NIST decrypt test vector */
  10260. XMEMSET(buf, 0, sizeof(buf));
  10261. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10262. #if defined(WOLFSSL_ASYNC_CRYPT)
  10263. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10264. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10265. #else
  10266. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10267. #endif
  10268. #endif
  10269. if (ret != 0)
  10270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10271. if (XMEMCMP(p1, buf, sizeof(p1)))
  10272. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10273. #ifdef WOLFSSL_AESXTS_STREAM
  10274. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10275. #if defined(WOLFSSL_ASYNC_CRYPT)
  10276. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10277. #endif
  10278. if (ret != 0)
  10279. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10280. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10281. #if defined(WOLFSSL_ASYNC_CRYPT)
  10282. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10283. #endif
  10284. if (ret != 0)
  10285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10286. if (XMEMCMP(p1, buf, sizeof(p1)))
  10287. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10288. #endif /* WOLFSSL_AESXTS_STREAM */
  10289. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10290. defined(WC_C_DYNAMIC_FALLBACK)
  10291. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10292. XMEMSET(buf, 0, sizeof(buf));
  10293. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10294. #if defined(WOLFSSL_ASYNC_CRYPT)
  10295. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10296. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10297. #else
  10298. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10299. #endif
  10300. #endif
  10301. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10302. if (ret != 0)
  10303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10304. if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE))
  10305. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10306. #endif
  10307. /* fail case with decrypting using wrong key */
  10308. XMEMSET(buf, 0, sizeof(buf));
  10309. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10310. #if defined(WOLFSSL_ASYNC_CRYPT)
  10311. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10312. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10313. #else
  10314. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10315. #endif
  10316. #endif
  10317. if (ret != 0)
  10318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10319. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  10320. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10321. /* set correct key and retest */
  10322. XMEMSET(buf, 0, sizeof(buf));
  10323. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10324. if (ret != 0)
  10325. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10326. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10327. #if defined(WOLFSSL_ASYNC_CRYPT)
  10328. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10329. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10330. #else
  10331. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10332. #endif
  10333. #endif
  10334. if (ret != 0)
  10335. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10336. if (XMEMCMP(p2, buf, sizeof(p2)))
  10337. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10338. #ifndef HAVE_FIPS
  10339. /* Test ciphertext stealing in-place. */
  10340. XMEMCPY(buf, p3, sizeof(p3));
  10341. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  10342. if (ret != 0)
  10343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10344. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  10345. #if defined(WOLFSSL_ASYNC_CRYPT)
  10346. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10347. #endif
  10348. if (ret != 0)
  10349. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10350. if (XMEMCMP(c3, buf, sizeof(c3)))
  10351. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10352. #ifdef WOLFSSL_AESXTS_STREAM
  10353. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  10354. #if defined(WOLFSSL_ASYNC_CRYPT)
  10355. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10356. #endif
  10357. if (ret != 0)
  10358. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10359. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, WC_AES_BLOCK_SIZE, &stream);
  10360. #if defined(WOLFSSL_ASYNC_CRYPT)
  10361. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10362. #endif
  10363. if (ret != 0)
  10364. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10365. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p3 + WC_AES_BLOCK_SIZE, sizeof(p3) - WC_AES_BLOCK_SIZE, &stream);
  10366. #if defined(WOLFSSL_ASYNC_CRYPT)
  10367. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10368. #endif
  10369. if (ret != 0)
  10370. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10371. if (XMEMCMP(c3, buf, sizeof(c3)))
  10372. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10373. #endif /* WOLFSSL_AESXTS_STREAM */
  10374. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  10375. if (ret != 0)
  10376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10377. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  10378. #if defined(WOLFSSL_ASYNC_CRYPT)
  10379. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10380. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10381. #else
  10382. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10383. #endif
  10384. #endif
  10385. if (ret != 0)
  10386. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10387. if (XMEMCMP(p3, buf, sizeof(p3)))
  10388. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10389. #ifdef WOLFSSL_AESXTS_STREAM
  10390. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  10391. #if defined(WOLFSSL_ASYNC_CRYPT)
  10392. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10393. #endif
  10394. if (ret != 0)
  10395. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10396. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, WC_AES_BLOCK_SIZE, &stream);
  10397. #if defined(WOLFSSL_ASYNC_CRYPT)
  10398. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10399. #endif
  10400. if (ret != 0)
  10401. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10402. ret = wc_AesXtsDecryptFinal(aes, buf + WC_AES_BLOCK_SIZE, c3 + WC_AES_BLOCK_SIZE, sizeof(c3) - WC_AES_BLOCK_SIZE, &stream);
  10403. #if defined(WOLFSSL_ASYNC_CRYPT)
  10404. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10405. #endif
  10406. if (ret != 0)
  10407. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10408. if (XMEMCMP(p3, buf, sizeof(p3)))
  10409. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10410. #endif /* WOLFSSL_AESXTS_STREAM */
  10411. #endif /* !HAVE_FIPS */
  10412. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10413. !defined(WOLFSSL_AFALG)
  10414. {
  10415. int i;
  10416. int j;
  10417. #ifdef WOLFSSL_AESXTS_STREAM
  10418. int k;
  10419. #endif
  10420. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10421. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10422. DYNAMIC_TYPE_TMP_BUFFER);
  10423. if (large_input == NULL)
  10424. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10425. #endif
  10426. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10427. large_input[i] = (byte)i;
  10428. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10429. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10430. if (ret != 0)
  10431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10432. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10433. sizeof(i1));
  10434. #if defined(WOLFSSL_ASYNC_CRYPT)
  10435. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10436. #endif
  10437. if (ret != 0)
  10438. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10439. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10440. if (ret != 0)
  10441. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10442. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10443. sizeof(i1));
  10444. #if defined(WOLFSSL_ASYNC_CRYPT)
  10445. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10446. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10447. WC_ASYNC_FLAG_NONE);
  10448. #else
  10449. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10450. #endif
  10451. #endif
  10452. if (ret != 0)
  10453. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10454. for (i = 0; i < j; i++) {
  10455. if (large_input[i] != (byte)i) {
  10456. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10457. }
  10458. }
  10459. }
  10460. #ifdef WOLFSSL_AESXTS_STREAM
  10461. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10462. large_input[i] = (byte)i;
  10463. /* first, encrypt block by block then decrypt with a one-shot call. */
  10464. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10465. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10466. if (ret != 0)
  10467. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10468. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10469. #if defined(WOLFSSL_ASYNC_CRYPT)
  10470. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10471. #endif
  10472. if (ret != 0)
  10473. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10474. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  10475. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10476. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10477. else
  10478. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  10479. #if defined(WOLFSSL_ASYNC_CRYPT)
  10480. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10481. #endif
  10482. if (ret != 0)
  10483. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10484. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10485. break;
  10486. }
  10487. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10488. if (ret != 0)
  10489. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10490. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10491. sizeof(i1));
  10492. #if defined(WOLFSSL_ASYNC_CRYPT)
  10493. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10494. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10495. WC_ASYNC_FLAG_NONE);
  10496. #else
  10497. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10498. #endif
  10499. #endif
  10500. if (ret != 0)
  10501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10502. for (i = 0; i < j; i++) {
  10503. if (large_input[i] != (byte)i) {
  10504. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10505. }
  10506. }
  10507. }
  10508. /* second, encrypt with a one-shot call then decrypt block by block. */
  10509. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10510. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10511. if (ret != 0)
  10512. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10513. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10514. sizeof(i1));
  10515. #if defined(WOLFSSL_ASYNC_CRYPT)
  10516. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10517. #endif
  10518. if (ret != 0)
  10519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10520. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10521. if (ret != 0)
  10522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10523. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10524. #if defined(WOLFSSL_ASYNC_CRYPT)
  10525. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10526. #endif
  10527. if (ret != 0)
  10528. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10529. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  10530. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10531. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10532. else
  10533. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  10534. #if defined(WOLFSSL_ASYNC_CRYPT)
  10535. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10536. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10537. WC_ASYNC_FLAG_NONE);
  10538. #else
  10539. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10540. #endif
  10541. #endif
  10542. if (ret != 0)
  10543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10544. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10545. break;
  10546. }
  10547. for (i = 0; i < j; i++) {
  10548. if (large_input[i] != (byte)i) {
  10549. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10550. }
  10551. }
  10552. }
  10553. #endif /* WOLFSSL_AESXTS_STREAM */
  10554. }
  10555. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10556. * !WOLFSSL_AFALG
  10557. */
  10558. out:
  10559. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10560. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10561. !defined(WOLFSSL_NO_MALLOC)
  10562. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10563. #endif
  10564. if (aes_inited)
  10565. wc_AesXtsFree(aes);
  10566. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10567. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10568. #endif
  10569. return ret;
  10570. }
  10571. #endif /* WOLFSSL_AES_192 */
  10572. #ifdef WOLFSSL_AES_256
  10573. static wc_test_ret_t aes_xts_256_test(void)
  10574. {
  10575. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10576. XtsAes *aes = NULL;
  10577. #else
  10578. XtsAes aes[1];
  10579. #endif
  10580. int aes_inited = 0;
  10581. wc_test_ret_t ret = 0;
  10582. unsigned char buf[WC_AES_BLOCK_SIZE * 3];
  10583. unsigned char cipher[WC_AES_BLOCK_SIZE * 3];
  10584. #ifdef WOLFSSL_AESXTS_STREAM
  10585. struct XtsAesStreamData stream;
  10586. #endif
  10587. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10588. !defined(WOLFSSL_AFALG)
  10589. #define LARGE_XTS_SZ 1024
  10590. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10591. byte* large_input = NULL;
  10592. #else
  10593. byte large_input[LARGE_XTS_SZ];
  10594. #endif
  10595. #endif
  10596. /* 256 key tests */
  10597. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10598. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  10599. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  10600. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  10601. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  10602. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  10603. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3,
  10604. 0xd6, 0x19, 0xb7, 0xe2, 0xb9, 0x14, 0x1e, 0x58,
  10605. 0x31, 0x8e, 0xea, 0x39, 0x2c, 0xf4, 0x1b, 0x08
  10606. };
  10607. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  10608. 0xad, 0xf8, 0xd9, 0x26, 0x27, 0x46, 0x4a, 0xd2,
  10609. 0xf0, 0x42, 0x8e, 0x84, 0xa9, 0xf8, 0x75, 0x64
  10610. };
  10611. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10612. 0x2e, 0xed, 0xea, 0x52, 0xcd, 0x82, 0x15, 0xe1,
  10613. 0xac, 0xc6, 0x47, 0xe8, 0x10, 0xbb, 0xc3, 0x64,
  10614. 0x2e, 0x87, 0x28, 0x7f, 0x8d, 0x2e, 0x57, 0xe3,
  10615. 0x6c, 0x0a, 0x24, 0xfb, 0xc1, 0x2a, 0x20, 0x2e
  10616. };
  10617. /* plain text test of partial block is not from NIST test vector list */
  10618. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  10619. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  10620. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  10621. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  10622. };
  10623. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10624. 0xcb, 0xaa, 0xd0, 0xe2, 0xf6, 0xce, 0xa3, 0xf5,
  10625. 0x0b, 0x37, 0xf9, 0x34, 0xd4, 0x6a, 0x9b, 0x13,
  10626. 0x0b, 0x9d, 0x54, 0xf0, 0x7e, 0x34, 0xf3, 0x6a,
  10627. 0xf7, 0x93, 0xe8, 0x6f, 0x73, 0xc6, 0xd7, 0xdb
  10628. };
  10629. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10630. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10631. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10632. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10633. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10634. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10635. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a,
  10636. 0xb5, 0xb0, 0xc7, 0xe5, 0x2d, 0xb5, 0x06, 0x12,
  10637. 0xd2, 0xb5, 0x3a, 0xcb, 0x47, 0x8a, 0x53, 0xb4
  10638. };
  10639. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10640. 0xe6, 0x42, 0x19, 0xed, 0xe0, 0xe1, 0xc2, 0xa0,
  10641. 0x0e, 0xf5, 0x58, 0x6a, 0xc4, 0x9b, 0xeb, 0x6f
  10642. };
  10643. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10644. 0x24, 0xcb, 0x76, 0x22, 0x55, 0xb5, 0xa8, 0x00,
  10645. 0xf4, 0x6e, 0x80, 0x60, 0x56, 0x9e, 0x05, 0x53,
  10646. 0xbc, 0xfe, 0x86, 0x55, 0x3b, 0xca, 0xd5, 0x89,
  10647. 0xc7, 0x54, 0x1a, 0x73, 0xac, 0xc3, 0x9a, 0xbd,
  10648. 0x53, 0xc4, 0x07, 0x76, 0xd8, 0xe8, 0x22, 0x61,
  10649. 0x9e, 0xa9, 0xad, 0x77, 0xa0, 0x13, 0x4c, 0xfc
  10650. };
  10651. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10652. 0xa3, 0xc6, 0xf3, 0xf3, 0x82, 0x79, 0x5b, 0x10,
  10653. 0x87, 0xd7, 0x02, 0x50, 0xdb, 0x2c, 0xd3, 0xb1,
  10654. 0xa1, 0x62, 0xa8, 0xb6, 0xdc, 0x12, 0x60, 0x61,
  10655. 0xc1, 0x0a, 0x84, 0xa5, 0x85, 0x3f, 0x3a, 0x89,
  10656. 0xe6, 0x6c, 0xdb, 0xb7, 0x9a, 0xb4, 0x28, 0x9b,
  10657. 0xc3, 0xea, 0xd8, 0x10, 0xe9, 0xc0, 0xaf, 0x92
  10658. };
  10659. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10660. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10661. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10662. #endif
  10663. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  10664. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  10665. ret = EVP_test(wolfSSL_EVP_aes_256_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  10666. if (ret != 0) {
  10667. printf("EVP_aes_256_xts failed\n");
  10668. goto out;
  10669. }
  10670. #endif
  10671. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10672. if (ret != 0)
  10673. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10674. else
  10675. aes_inited = 1;
  10676. XMEMSET(buf, 0, sizeof(buf));
  10677. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10678. if (ret != 0)
  10679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10680. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10681. #if defined(WOLFSSL_ASYNC_CRYPT)
  10682. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10683. #endif
  10684. if (ret != 0)
  10685. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10686. if (XMEMCMP(c2, buf, sizeof(c2)))
  10687. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10688. #ifdef WOLFSSL_AESXTS_STREAM
  10689. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10690. #if defined(WOLFSSL_ASYNC_CRYPT)
  10691. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10692. #endif
  10693. if (ret != 0)
  10694. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10695. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream);
  10696. #if defined(WOLFSSL_ASYNC_CRYPT)
  10697. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10698. #endif
  10699. if (ret != 0)
  10700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10701. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream);
  10702. #if defined(WOLFSSL_ASYNC_CRYPT)
  10703. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10704. #endif
  10705. if (ret != 0)
  10706. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10707. if (XMEMCMP(c2, buf, sizeof(c2)))
  10708. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10709. #endif /* WOLFSSL_AESXTS_STREAM */
  10710. XMEMSET(buf, 0, sizeof(buf));
  10711. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10712. if (ret != 0)
  10713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10714. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10715. #if defined(WOLFSSL_ASYNC_CRYPT)
  10716. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10717. #endif
  10718. if (ret != 0)
  10719. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10720. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  10721. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10722. #ifdef WOLFSSL_AESXTS_STREAM
  10723. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10724. #if defined(WOLFSSL_ASYNC_CRYPT)
  10725. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10726. #endif
  10727. if (ret != 0)
  10728. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10729. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10730. #if defined(WOLFSSL_ASYNC_CRYPT)
  10731. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10732. #endif
  10733. if (ret != 0)
  10734. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10735. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10736. #if defined(WOLFSSL_ASYNC_CRYPT)
  10737. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10738. #endif
  10739. if (ret != 0)
  10740. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10741. if (XMEMCMP(c1, buf, sizeof(c1)))
  10742. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10743. #endif /* WOLFSSL_AESXTS_STREAM */
  10744. /* partial block encryption test */
  10745. XMEMSET(cipher, 0, sizeof(cipher));
  10746. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10747. #if defined(WOLFSSL_ASYNC_CRYPT)
  10748. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10749. #endif
  10750. if (ret != 0)
  10751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10752. /* partial block decrypt test */
  10753. XMEMSET(buf, 0, sizeof(buf));
  10754. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10755. if (ret != 0)
  10756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10757. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10758. #if defined(WOLFSSL_ASYNC_CRYPT)
  10759. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10760. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10761. #else
  10762. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10763. #endif
  10764. #endif
  10765. if (ret != 0)
  10766. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10767. if (XMEMCMP(pp, buf, sizeof(pp)))
  10768. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10769. /* NIST decrypt test vector */
  10770. XMEMSET(buf, 0, sizeof(buf));
  10771. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10772. #if defined(WOLFSSL_ASYNC_CRYPT)
  10773. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10774. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10775. #else
  10776. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10777. #endif
  10778. #endif
  10779. if (ret != 0)
  10780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10781. if (XMEMCMP(p1, buf, sizeof(p1)))
  10782. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10783. #ifdef WOLFSSL_AESXTS_STREAM
  10784. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10785. #if defined(WOLFSSL_ASYNC_CRYPT)
  10786. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10787. #endif
  10788. if (ret != 0)
  10789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10790. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10791. #if defined(WOLFSSL_ASYNC_CRYPT)
  10792. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10793. #endif
  10794. if (ret != 0)
  10795. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10796. if (XMEMCMP(p1, buf, sizeof(p1)))
  10797. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10798. #endif /* WOLFSSL_AESXTS_STREAM */
  10799. XMEMSET(buf, 0, sizeof(buf));
  10800. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10801. if (ret != 0)
  10802. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10803. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10804. #if defined(WOLFSSL_ASYNC_CRYPT)
  10805. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10806. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10807. #else
  10808. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10809. #endif
  10810. #endif
  10811. if (ret != 0)
  10812. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10813. if (XMEMCMP(p2, buf, sizeof(p2)))
  10814. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10815. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10816. !defined(WOLFSSL_AFALG)
  10817. {
  10818. int i;
  10819. int j;
  10820. #ifdef WOLFSSL_AESXTS_STREAM
  10821. int k;
  10822. #endif
  10823. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10824. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10825. DYNAMIC_TYPE_TMP_BUFFER);
  10826. if (large_input == NULL)
  10827. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10828. #endif
  10829. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10830. large_input[i] = (byte)i;
  10831. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10832. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10833. if (ret != 0)
  10834. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10835. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10836. sizeof(i1));
  10837. #if defined(WOLFSSL_ASYNC_CRYPT)
  10838. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10839. #endif
  10840. if (ret != 0)
  10841. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10842. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10843. if (ret != 0)
  10844. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10845. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10846. sizeof(i1));
  10847. #if defined(WOLFSSL_ASYNC_CRYPT)
  10848. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10849. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10850. WC_ASYNC_FLAG_NONE);
  10851. #else
  10852. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10853. #endif
  10854. #endif
  10855. if (ret != 0)
  10856. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10857. for (i = 0; i < j; i++) {
  10858. if (large_input[i] != (byte)i) {
  10859. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10860. }
  10861. }
  10862. }
  10863. #ifdef WOLFSSL_AESXTS_STREAM
  10864. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10865. large_input[i] = (byte)i;
  10866. /* first, encrypt block by block then decrypt with a one-shot call. */
  10867. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10868. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10869. if (ret != 0)
  10870. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10871. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10872. #if defined(WOLFSSL_ASYNC_CRYPT)
  10873. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10874. #endif
  10875. if (ret != 0)
  10876. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10877. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  10878. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10879. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10880. else
  10881. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  10882. #if defined(WOLFSSL_ASYNC_CRYPT)
  10883. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10884. #endif
  10885. if (ret != 0)
  10886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10887. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10888. break;
  10889. }
  10890. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10891. if (ret != 0)
  10892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10893. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10894. sizeof(i1));
  10895. #if defined(WOLFSSL_ASYNC_CRYPT)
  10896. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10897. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10898. WC_ASYNC_FLAG_NONE);
  10899. #else
  10900. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10901. #endif
  10902. #endif
  10903. if (ret != 0)
  10904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10905. for (i = 0; i < j; i++) {
  10906. if (large_input[i] != (byte)i) {
  10907. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10908. }
  10909. }
  10910. }
  10911. /* second, encrypt with a one-shot call then decrypt block by block. */
  10912. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10913. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10914. if (ret != 0)
  10915. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10916. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10917. sizeof(i1));
  10918. #if defined(WOLFSSL_ASYNC_CRYPT)
  10919. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10920. #endif
  10921. if (ret != 0)
  10922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10923. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10924. if (ret != 0)
  10925. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10926. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10927. #if defined(WOLFSSL_ASYNC_CRYPT)
  10928. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10929. #endif
  10930. if (ret != 0)
  10931. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10932. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  10933. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10934. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10935. else
  10936. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  10937. #if defined(WOLFSSL_ASYNC_CRYPT)
  10938. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10939. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10940. WC_ASYNC_FLAG_NONE);
  10941. #else
  10942. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10943. #endif
  10944. #endif
  10945. if (ret != 0)
  10946. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10947. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10948. break;
  10949. }
  10950. for (i = 0; i < j; i++) {
  10951. if (large_input[i] != (byte)i) {
  10952. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10953. }
  10954. }
  10955. }
  10956. #endif /* WOLFSSL_AESXTS_STREAM */
  10957. }
  10958. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10959. * !WOLFSSL_AFALG
  10960. */
  10961. out:
  10962. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10963. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10964. !defined(WOLFSSL_NO_MALLOC)
  10965. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10966. #endif
  10967. if (aes_inited)
  10968. wc_AesXtsFree(aes);
  10969. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10970. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10971. #endif
  10972. return ret;
  10973. }
  10974. #endif /* WOLFSSL_AES_256 */
  10975. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  10976. /* both 128 and 256 bit key test */
  10977. static wc_test_ret_t aes_xts_sector_test(void)
  10978. {
  10979. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10980. XtsAes *aes = NULL;
  10981. #else
  10982. XtsAes aes[1];
  10983. #endif
  10984. int aes_inited = 0;
  10985. wc_test_ret_t ret = 0;
  10986. unsigned char buf[WC_AES_BLOCK_SIZE * 2];
  10987. /* 128 key tests */
  10988. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10989. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  10990. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  10991. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  10992. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  10993. };
  10994. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10995. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  10996. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  10997. };
  10998. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10999. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  11000. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  11001. };
  11002. word64 s1 = 141;
  11003. /* 256 key tests */
  11004. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  11005. 0xef, 0x01, 0x0c, 0xa1, 0xa3, 0x66, 0x3e, 0x32,
  11006. 0x53, 0x43, 0x49, 0xbc, 0x0b, 0xae, 0x62, 0x23,
  11007. 0x2a, 0x15, 0x73, 0x34, 0x85, 0x68, 0xfb, 0x9e,
  11008. 0xf4, 0x17, 0x68, 0xa7, 0x67, 0x4f, 0x50, 0x7a,
  11009. 0x72, 0x7f, 0x98, 0x75, 0x53, 0x97, 0xd0, 0xe0,
  11010. 0xaa, 0x32, 0xf8, 0x30, 0x33, 0x8c, 0xc7, 0xa9,
  11011. 0x26, 0xc7, 0x73, 0xf0, 0x9e, 0x57, 0xb3, 0x57,
  11012. 0xcd, 0x15, 0x6a, 0xfb, 0xca, 0x46, 0xe1, 0xa0
  11013. };
  11014. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  11015. 0xed, 0x98, 0xe0, 0x17, 0x70, 0xa8, 0x53, 0xb4,
  11016. 0x9d, 0xb9, 0xe6, 0xaa, 0xf8, 0x8f, 0x0a, 0x41,
  11017. 0xb9, 0xb5, 0x6e, 0x91, 0xa5, 0xa2, 0xb1, 0x1d,
  11018. 0x40, 0x52, 0x92, 0x54, 0xf5, 0x52, 0x3e, 0x75
  11019. };
  11020. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  11021. 0xca, 0x20, 0xc5, 0x5e, 0x8d, 0xc1, 0x49, 0x68,
  11022. 0x7d, 0x25, 0x41, 0xde, 0x39, 0xc3, 0xdf, 0x63,
  11023. 0x00, 0xbb, 0x5a, 0x16, 0x3c, 0x10, 0xce, 0xd3,
  11024. 0x66, 0x6b, 0x13, 0x57, 0xdb, 0x8b, 0xd3, 0x9d
  11025. };
  11026. word64 s2 = 187;
  11027. #if !defined(BENCH_EMBEDDED) && \
  11028. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11029. /* Sector size for encrypt/decrypt consecutive sectors testcase */
  11030. word32 sectorSz = 512;
  11031. unsigned char data[550];
  11032. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  11033. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11034. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11035. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  11036. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
  11037. };
  11038. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  11039. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11040. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11041. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11042. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11043. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11044. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11045. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11046. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11047. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11048. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11049. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11050. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11051. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11052. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11053. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11054. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11055. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11056. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11057. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11058. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11059. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11060. 0xfc, 0xfd, 0xfe, 0xff,
  11061. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11062. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11063. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11064. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11065. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11066. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11067. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11068. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11069. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11070. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11071. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11072. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11073. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11074. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11075. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11076. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11077. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11078. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11079. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11080. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11081. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11082. 0xfc, 0xfd, 0xfe, 0xff,
  11083. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11084. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11085. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  11086. };
  11087. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  11088. 0xb9, 0x6b, 0x2b, 0xfd, 0x61, 0x87, 0x84, 0xd5, 0x26, 0xd2, 0x8c, 0x62,
  11089. 0x63, 0x01, 0xca, 0x46, 0xb1, 0x82, 0xfa, 0xdc, 0xbc, 0x32, 0x18, 0xe9,
  11090. 0xda, 0xe6, 0xda, 0xd1, 0x1a, 0x52, 0x77, 0xca, 0xdb, 0x0e, 0xbe, 0x37,
  11091. 0x88, 0x36, 0x1c, 0x87, 0x16, 0x60, 0xfe, 0xa8, 0x9e, 0xf6, 0x48, 0x64,
  11092. 0x94, 0x34, 0x64, 0xed, 0xf6, 0x9a, 0xc5, 0x28, 0xc9, 0xed, 0x64, 0x80,
  11093. 0x85, 0xd8, 0x93, 0xa7, 0x50, 0xb1, 0x9d, 0x2f, 0x1e, 0x34, 0xcc, 0xb4,
  11094. 0x03, 0xfb, 0x6b, 0x43, 0x21, 0xa8, 0x5b, 0xc6, 0x59, 0x13, 0xd2, 0xb5,
  11095. 0xf5, 0x7b, 0xf6, 0xb2, 0xa4, 0x7a, 0xd2, 0x50, 0x26, 0xcb, 0xa4, 0x83,
  11096. 0xc3, 0x56, 0xb0, 0xb1, 0x14, 0x34, 0x12, 0x1b, 0xea, 0x26, 0x97, 0x24,
  11097. 0x54, 0xcc, 0x32, 0x4c, 0xa4, 0xc2, 0xa3, 0x07, 0xfa, 0x30, 0xa9, 0xf0,
  11098. 0x91, 0x17, 0x60, 0x68, 0x88, 0x7f, 0x34, 0x7e, 0xbd, 0x20, 0x33, 0x95,
  11099. 0x6e, 0xc0, 0xb6, 0x2b, 0xff, 0x7e, 0x61, 0x35, 0x9a, 0x88, 0xff, 0xd9,
  11100. 0x69, 0x21, 0xe7, 0x8f, 0x45, 0x02, 0xf9, 0xd7, 0xeb, 0xa6, 0x53, 0xf1,
  11101. 0x73, 0x04, 0xf1, 0x0b, 0x85, 0xc6, 0x1f, 0x4a, 0x51, 0x2f, 0x95, 0x87,
  11102. 0x5a, 0x67, 0x37, 0xb2, 0x87, 0xf7, 0xbe, 0x2a, 0x17, 0x57, 0xca, 0xfc,
  11103. 0xdd, 0x5f, 0x37, 0x48, 0x78, 0xbd, 0xfa, 0x75, 0xc9, 0xfa, 0x86, 0x7e,
  11104. 0xc4, 0x0f, 0x60, 0x85, 0xce, 0x12, 0x44, 0x7c, 0xd9, 0xb2, 0x50, 0xd9,
  11105. 0x57, 0x85, 0xa5, 0xd7, 0x68, 0x59, 0x03, 0x09, 0x97, 0x2e, 0x8e, 0xa5,
  11106. 0xe3, 0x98, 0xac, 0x16, 0xfb, 0x6d, 0x54, 0xc5, 0x5d, 0x7a, 0x33, 0x44,
  11107. 0x0a, 0x39, 0x91, 0xcc, 0x9f, 0x67, 0xf9, 0x89, 0xbb, 0x62, 0x02, 0xc4,
  11108. 0x22, 0xec, 0xcf, 0x97, 0x69, 0x81, 0x3d, 0x00, 0xfd, 0xeb, 0x55, 0x08,
  11109. 0xa2, 0xff, 0x97, 0xaa, 0x79, 0xde, 0x3c, 0x8a, 0x78, 0x71, 0x73, 0xa2,
  11110. 0x98, 0x2f, 0xd8, 0x5c, 0x62, 0x1c, 0x5c, 0x23, 0x0a, 0xd1, 0xf1, 0x81,
  11111. 0x8a, 0x12, 0xe7, 0x4d, 0xdd, 0x4f, 0xd4, 0xf1, 0xe8, 0x0f, 0x25, 0x79,
  11112. 0x45, 0x4a, 0x49, 0x49, 0x7e, 0x56, 0x91, 0x4e, 0xaa, 0xba, 0x18, 0xe1,
  11113. 0xe4, 0xbe, 0x21, 0xdc, 0x58, 0x60, 0x6f, 0x6a, 0x7f, 0xdc, 0x5e, 0x74,
  11114. 0x47, 0xbf, 0xeb, 0x84, 0xc4, 0x1e, 0x5a, 0x61, 0x64, 0xc8, 0x63, 0x68,
  11115. 0xfa, 0x17, 0x9c, 0xac, 0x60, 0x1c, 0xa5, 0x6e, 0x00, 0x21, 0x93, 0x3c,
  11116. 0xd7, 0xbb, 0x73, 0x45, 0xf7, 0x34, 0x81, 0x6c, 0xfa, 0xf2, 0x33, 0xfd,
  11117. 0xb1, 0x40, 0x30, 0x6b, 0x30, 0xd1, 0x83, 0x5e, 0x2e, 0x7a, 0xce, 0xa6,
  11118. 0x12, 0x2a, 0x15, 0x03, 0x78, 0x29, 0xb9, 0x07, 0xae, 0xe7, 0xc2, 0x78,
  11119. 0x74, 0x72, 0xa5, 0x0e, 0x6b, 0x1f, 0x78, 0xf2, 0x5a, 0x69, 0xb6, 0x2b,
  11120. 0x99, 0x94, 0x1f, 0x89, 0xd1, 0x21, 0x14, 0x4a, 0x54, 0xab, 0x5a, 0x9f,
  11121. 0xaa, 0xa7, 0x96, 0x0a, 0x21, 0xce, 0x30, 0xb6, 0x70, 0x81, 0xe9, 0xd3,
  11122. 0x71, 0xc0, 0xf1, 0x15, 0xe2, 0xf6, 0xd3, 0xcc, 0x41, 0x15, 0x9d, 0xd5,
  11123. 0xa3, 0xa4, 0xe0, 0xf8, 0x62, 0xc4, 0x76, 0x65, 0x63, 0x89, 0xa7, 0xe2,
  11124. 0xfb, 0xf5, 0xc9, 0x80, 0x15, 0x5b, 0xc1, 0x59, 0xb2, 0xd0, 0x01, 0x3a,
  11125. 0xf9, 0xab, 0x5b, 0x79, 0x54, 0xed, 0x6b, 0xf9, 0x1d, 0x9d, 0x87, 0x63,
  11126. 0x80, 0x4f, 0xec, 0x9c, 0x4f, 0xad, 0x97, 0x04, 0xff, 0x62, 0x4a, 0x17,
  11127. 0xc0, 0x09, 0x2a, 0x2c, 0x23, 0x4b, 0xc3, 0xb6, 0x6d, 0xed, 0xdb, 0x1a,
  11128. 0x6f, 0x56, 0x2b, 0x78, 0x92, 0x3a, 0x5c, 0x7f, 0xb2, 0x63, 0xd3, 0xd5,
  11129. 0x1a, 0xbe, 0xc2, 0x34, 0xc8, 0xad, 0x36, 0xb7, 0x12, 0xb8, 0xe1, 0xb7,
  11130. 0x52, 0x7f, 0x16, 0x84, 0x2c, 0x47, 0x7e, 0xf2, 0xa5, 0x36, 0x2e, 0xad,
  11131. 0xe7, 0xbb, 0xc0, 0x6f, 0x27, 0x8e, 0x41, 0x08, 0x75, 0xe5, 0xff, 0xde,
  11132. 0x08, 0x9f, 0x8c, 0x91, 0xba, 0xc9, 0x9d, 0x9f, 0x27, 0x90, 0x50, 0x44,
  11133. 0x24, 0xe7, 0x3d, 0x6f
  11134. };
  11135. word64 s3 = 0x000000ffffffffff;
  11136. #endif
  11137. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11138. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11139. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11140. #endif
  11141. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11142. if (ret != 0)
  11143. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11144. else
  11145. aes_inited = 1;
  11146. XMEMSET(buf, 0, sizeof(buf));
  11147. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11148. if (ret != 0)
  11149. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11150. ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1);
  11151. #if defined(WOLFSSL_ASYNC_CRYPT)
  11152. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11153. #endif
  11154. if (ret != 0)
  11155. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11156. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  11157. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11158. /* decrypt test */
  11159. XMEMSET(buf, 0, sizeof(buf));
  11160. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11161. if (ret != 0)
  11162. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11163. ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1);
  11164. #if defined(WOLFSSL_ASYNC_CRYPT)
  11165. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11166. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11167. #else
  11168. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11169. #endif
  11170. #endif
  11171. if (ret != 0)
  11172. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11173. if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE))
  11174. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11175. /* 256 bit key tests */
  11176. XMEMSET(buf, 0, sizeof(buf));
  11177. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  11178. if (ret != 0)
  11179. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11180. ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2);
  11181. #if defined(WOLFSSL_ASYNC_CRYPT)
  11182. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11183. #endif
  11184. if (ret != 0)
  11185. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11186. if (XMEMCMP(c2, buf, sizeof(c2)))
  11187. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11188. /* decrypt test */
  11189. XMEMSET(buf, 0, sizeof(buf));
  11190. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  11191. if (ret != 0)
  11192. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11193. ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2);
  11194. #if defined(WOLFSSL_ASYNC_CRYPT)
  11195. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11196. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11197. #else
  11198. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11199. #endif
  11200. #endif
  11201. if (ret != 0)
  11202. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11203. if (XMEMCMP(p2, buf, sizeof(p2)))
  11204. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11205. #if !defined(BENCH_EMBEDDED) && \
  11206. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11207. /* encrypt consecutive sectors test */
  11208. XMEMSET(data, 0, sizeof(buf));
  11209. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  11210. if (ret != 0)
  11211. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11212. ret = wc_AesXtsEncryptConsecutiveSectors(aes, data, p3,
  11213. sizeof(p3), s3, sectorSz);
  11214. #if defined(WOLFSSL_ASYNC_CRYPT)
  11215. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11216. #endif
  11217. if (ret != 0)
  11218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11219. if (XMEMCMP(c3, data, sizeof(c3)))
  11220. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11221. /* decrypt consecutive sectors test */
  11222. XMEMSET(data, 0, sizeof(buf));
  11223. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  11224. if (ret != 0)
  11225. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11226. ret = wc_AesXtsDecryptConsecutiveSectors(aes, data, c3,
  11227. sizeof(c3), s3, sectorSz);
  11228. #if defined(WOLFSSL_ASYNC_CRYPT)
  11229. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11230. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11231. #else
  11232. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11233. #endif
  11234. #endif
  11235. if (ret != 0)
  11236. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11237. if (XMEMCMP(p3, data, sizeof(p3)))
  11238. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11239. #endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */
  11240. out:
  11241. if (aes_inited)
  11242. wc_AesXtsFree(aes);
  11243. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11244. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11245. #endif
  11246. return ret;
  11247. }
  11248. #endif /* WOLFSSL_AES_128 && WOLFSSL_AES_256 */
  11249. #ifdef WOLFSSL_AES_128
  11250. /* testing of bad arguments */
  11251. static wc_test_ret_t aes_xts_args_test(void)
  11252. {
  11253. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11254. XtsAes *aes = NULL;
  11255. #else
  11256. XtsAes aes[1];
  11257. #endif
  11258. int aes_inited = 0;
  11259. wc_test_ret_t ret;
  11260. unsigned char buf[WC_AES_BLOCK_SIZE * 2];
  11261. /* 128 key tests */
  11262. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  11263. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  11264. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  11265. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  11266. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  11267. };
  11268. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  11269. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  11270. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  11271. };
  11272. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  11273. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  11274. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  11275. };
  11276. word64 s1 = 141;
  11277. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11278. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11279. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11280. #endif
  11281. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11282. if (ret != 0)
  11283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11284. else
  11285. aes_inited = 1;
  11286. if (wc_AesXtsSetKeyNoInit(NULL, k1, sizeof(k1), AES_ENCRYPTION) == 0)
  11287. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11288. if (wc_AesXtsSetKeyNoInit(aes, NULL, sizeof(k1), AES_ENCRYPTION) == 0)
  11289. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11290. /* encryption operations */
  11291. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11292. if (ret != 0)
  11293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11294. ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1);
  11295. #if defined(WOLFSSL_ASYNC_CRYPT)
  11296. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11297. #endif
  11298. if (ret == 0)
  11299. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11300. ret = wc_AesXtsEncryptSector(aes, NULL, p1, sizeof(p1), s1);
  11301. #if defined(WOLFSSL_ASYNC_CRYPT)
  11302. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11303. #endif
  11304. if (ret == 0)
  11305. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11306. /* decryption operations */
  11307. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11308. if (ret != 0)
  11309. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11310. ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1);
  11311. #if defined(WOLFSSL_ASYNC_CRYPT)
  11312. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11313. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11314. #else
  11315. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11316. #endif
  11317. #endif
  11318. if (ret == 0)
  11319. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11320. ret = wc_AesXtsDecryptSector(aes, NULL, c1, sizeof(c1), s1);
  11321. #if defined(WOLFSSL_ASYNC_CRYPT)
  11322. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11323. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11324. #else
  11325. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11326. #endif
  11327. #endif
  11328. if (ret == 0)
  11329. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11330. ret = 0;
  11331. out:
  11332. if (aes_inited)
  11333. wc_AesXtsFree(aes);
  11334. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11335. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11336. #endif
  11337. return ret;
  11338. }
  11339. #endif /* WOLFSSL_AES_128 */
  11340. #endif /* WOLFSSL_AES_XTS && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  11341. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  11342. !defined(HAVE_RENESAS_SYNC)
  11343. static wc_test_ret_t aes_cbc_oneshot_test(void)
  11344. {
  11345. byte cipher[WC_AES_BLOCK_SIZE];
  11346. byte plain[WC_AES_BLOCK_SIZE];
  11347. wc_test_ret_t ret;
  11348. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  11349. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  11350. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  11351. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  11352. };
  11353. byte key[] = "0123456789abcdef "; /* align */
  11354. byte iv[] = "1234567890abcdef "; /* align */
  11355. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  11356. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  11357. /* Parameter Validation testing. */
  11358. ret = wc_AesCbcEncryptWithKey(cipher, msg, WC_AES_BLOCK_SIZE, key, 17, NULL);
  11359. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11360. return WC_TEST_RET_ENC_EC(ret);
  11361. #ifdef HAVE_AES_DECRYPT
  11362. ret = wc_AesCbcDecryptWithKey(plain, cipher, WC_AES_BLOCK_SIZE, key, 17, NULL);
  11363. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11364. return WC_TEST_RET_ENC_EC(ret);
  11365. #endif
  11366. ret = wc_AesCbcEncryptWithKey(cipher, msg, WC_AES_BLOCK_SIZE, key,
  11367. WC_AES_BLOCK_SIZE, iv);
  11368. if (ret != 0)
  11369. return WC_TEST_RET_ENC_EC(ret);
  11370. #ifdef HAVE_AES_DECRYPT
  11371. ret = wc_AesCbcDecryptWithKey(plain, cipher, WC_AES_BLOCK_SIZE, key,
  11372. WC_AES_BLOCK_SIZE, iv);
  11373. if (ret != 0)
  11374. return WC_TEST_RET_ENC_EC(ret);
  11375. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE) != 0)
  11376. return WC_TEST_RET_ENC_NC;
  11377. #endif /* HAVE_AES_DECRYPT */
  11378. (void)plain;
  11379. return 0;
  11380. }
  11381. #endif
  11382. #if defined(WOLFSSL_AES_COUNTER) && defined(HAVE_AES_DECRYPT)
  11383. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void)
  11384. {
  11385. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11386. Aes *enc = NULL;
  11387. Aes *dec = NULL;
  11388. #else
  11389. Aes enc[1];
  11390. Aes dec[1];
  11391. #endif
  11392. byte cipher[WC_AES_BLOCK_SIZE * 4];
  11393. byte plain [WC_AES_BLOCK_SIZE * 4];
  11394. wc_test_ret_t ret = 0;
  11395. /* test vectors from "Recommendation for Block Cipher Modes of
  11396. * Operation" NIST Special Publication 800-38A */
  11397. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  11398. {
  11399. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  11400. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  11401. };
  11402. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  11403. {
  11404. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11405. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  11406. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  11407. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  11408. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  11409. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  11410. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  11411. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  11412. };
  11413. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11414. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32[] =
  11415. {
  11416. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,
  11417. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11418. };
  11419. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32_2[] =
  11420. {
  11421. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11422. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xfe
  11423. };
  11424. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64[] =
  11425. {
  11426. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11427. 0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11428. };
  11429. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64_2[] =
  11430. {
  11431. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
  11432. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11433. };
  11434. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96[] =
  11435. {
  11436. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11437. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff
  11438. };
  11439. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96_2[] =
  11440. {
  11441. 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,
  11442. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11443. };
  11444. #endif
  11445. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
  11446. {
  11447. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11448. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11449. };
  11450. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11451. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128_2[] =
  11452. {
  11453. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11454. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11455. };
  11456. #endif
  11457. #ifdef WOLFSSL_AES_128
  11458. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  11459. {
  11460. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  11461. 0xc2
  11462. };
  11463. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Key[] =
  11464. {
  11465. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  11466. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  11467. };
  11468. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Cipher[] =
  11469. {
  11470. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  11471. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  11472. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  11473. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  11474. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  11475. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  11476. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  11477. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  11478. };
  11479. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11480. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32Cipher[] =
  11481. {
  11482. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11483. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11484. 0x7e,0xad,0xea,0x5c,0xd1
  11485. };
  11486. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32CipherLong[] =
  11487. {
  11488. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11489. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11490. 0x7e,0xad,0xea,0x5c,0xd1,0xb7,0x98,0xf0,
  11491. 0x22,0x20,0xfe,0x67,0xb0,0x02,0x23,0x50
  11492. };
  11493. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32_2CipherLong[] =
  11494. {
  11495. 0x6e,0xa1,0x27,0x4d,0xea,0x20,0x5f,0x39,
  11496. 0x68,0xc8,0xb6,0x78,0xde,0xfc,0x53,0x5c,
  11497. 0x90,0xc8,0xf6,0xc6,0xfa,0xe0,0x7b,0x09,
  11498. 0x7c,0xf8,0x9c,0x6a,0x5a,0xa5,0x17,0x7f,
  11499. 0x03,0x92,0x5f,0x4e,0x85,0xea,0x26,0xc9,
  11500. 0x5a,0xc2,0x74,0xe2,0xbf,0xe4,0x1b,0xd4
  11501. };
  11502. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64Cipher[] =
  11503. {
  11504. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11505. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11506. 0xae,0x74,0x94,0x72,0x8e
  11507. };
  11508. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64CipherLong[] =
  11509. {
  11510. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11511. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11512. 0xae,0x74,0x94,0x72,0x8e,0xd0,0x71,0xc0,
  11513. 0x89,0x8a,0xa1,0xb0,0x29,0xa0,0x10,0x9e
  11514. };
  11515. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64_2CipherLong[] =
  11516. {
  11517. 0x3f,0xe7,0xd5,0xf3,0xfa,0x09,0xfe,0x40,
  11518. 0xa6,0xa1,0x32,0x8b,0x57,0x12,0xb9,0xfa,
  11519. 0xf2,0x2d,0xe4,0x3c,0x66,0x1d,0x0a,0x8e,
  11520. 0x46,0xf8,0x2e,0x33,0xce,0x8d,0x4e,0x3b,
  11521. 0x17,0x67,0x9e,0x9f,0x76,0x9e,0xc2,0x99,
  11522. 0xd5,0xd4,0x71,0xed,0xb4,0x33,0xb2,0xcd
  11523. };
  11524. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96Cipher[] =
  11525. {
  11526. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11527. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11528. 0x9d,0x77,0xc9,0x5f,0x38
  11529. };
  11530. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96CipherLong[] =
  11531. {
  11532. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11533. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11534. 0x9d,0x77,0xc9,0x5f,0x38,0xb5,0x6e,0x44,
  11535. 0x21,0x8e,0xda,0x57,0xe0,0x41,0xc7,0x6a
  11536. };
  11537. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96_2CipherLong[] =
  11538. {
  11539. 0xc8,0x81,0x1a,0xbe,0xc7,0x5b,0x93,0x6f,
  11540. 0xe6,0x52,0xe4,0xb1,0x2d,0x1c,0x39,0xbc,
  11541. 0xeb,0x82,0x27,0x0a,0x7e,0xa5,0x0e,0x2d,
  11542. 0x32,0xda,0xbe,0x10,0x7a,0x10,0xcc,0xd3,
  11543. 0x6f,0xc6,0x83,0x28,0x05,0x57,0x8a,0x24,
  11544. 0x44,0x76,0x17,0x81,0xb9,0x5c,0x94,0x81
  11545. };
  11546. #endif
  11547. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
  11548. {
  11549. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11550. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11551. 0xd3,0xda,0xe1,0x5b,0x04
  11552. };
  11553. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128CipherLong[] =
  11554. {
  11555. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11556. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11557. 0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
  11558. 0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
  11559. };
  11560. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11561. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128_2CipherLong[] =
  11562. {
  11563. 0xba,0x76,0xaa,0x54,0xd5,0xb5,0x60,0x67,
  11564. 0xc1,0xa7,0x90,0x3b,0x3f,0xdd,0xfa,0x89,
  11565. 0x24,0xdf,0x0c,0x56,0x5c,0xf4,0x2a,0x68,
  11566. 0x97,0x87,0x13,0xb6,0x7a,0xd1,0x24,0xfd,
  11567. 0x4d,0x3f,0x77,0x4a,0xb9,0xe4,0x7d,0xa2,
  11568. 0xdb,0xb9,0x31,0x5e,0xa3,0x11,0x06,0x80
  11569. };
  11570. #endif
  11571. #endif /* WOLFSSL_AES_128 */
  11572. #ifdef WOLFSSL_AES_192
  11573. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  11574. {
  11575. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  11576. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  11577. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  11578. };
  11579. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  11580. {
  11581. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  11582. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b,
  11583. 0x09,0x03,0x39,0xec,0x0a,0xa6,0xfa,0xef,
  11584. 0xd5,0xcc,0xc2,0xc6,0xf4,0xce,0x8e,0x94,
  11585. 0x1e,0x36,0xb2,0x6b,0xd1,0xeb,0xc6,0x70,
  11586. 0xd1,0xbd,0x1d,0x66,0x56,0x20,0xab,0xf7,
  11587. 0x4f,0x78,0xa7,0xf6,0xd2,0x98,0x09,0x58,
  11588. 0x5a,0x97,0xda,0xec,0x58,0xc6,0xb0,0x50
  11589. };
  11590. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11591. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32Cipher[] =
  11592. {
  11593. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11594. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11595. 0x0c,0x33,0x97,0x06,0xc0
  11596. };
  11597. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32CipherLong[] =
  11598. {
  11599. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11600. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11601. 0x0c,0x33,0x97,0x06,0xc0,0xbe,0x83,0x87,
  11602. 0xdd,0xd3,0xff,0xd8,0xe4,0x6a,0x5b,0x84
  11603. };
  11604. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32_2CipherLong[] =
  11605. {
  11606. 0xf5,0x00,0xa2,0x91,0x54,0xa3,0x76,0xa2,
  11607. 0xdd,0xad,0x16,0x89,0xe5,0xf0,0x1d,0x40,
  11608. 0x84,0xcd,0x74,0x84,0xcb,0x8b,0x9e,0x29,
  11609. 0xa9,0x8a,0x12,0x65,0xa0,0x79,0x5e,0xce,
  11610. 0xd9,0x50,0x65,0x21,0x86,0xb0,0x85,0x0d,
  11611. 0x98,0x2d,0x9a,0x5a,0x11,0xbe,0xa5,0x7f
  11612. };
  11613. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64Cipher[] =
  11614. {
  11615. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11616. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11617. 0x3d,0xf7,0xb4,0xfd,0x8c
  11618. };
  11619. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64CipherLong[] =
  11620. {
  11621. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11622. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11623. 0x3d,0xf7,0xb4,0xfd,0x8c,0x55,0x47,0x10,
  11624. 0xd5,0x91,0x35,0xbe,0xd8,0x0d,0xa5,0x9e
  11625. };
  11626. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64_2CipherLong[] =
  11627. {
  11628. 0x59,0xf1,0xed,0x70,0x62,0x42,0xa8,0x06,
  11629. 0x07,0x36,0xe1,0xc5,0x04,0x79,0xc3,0x9b,
  11630. 0xd1,0x14,0x5c,0xcc,0x6f,0x81,0x5f,0x2f,
  11631. 0xa0,0xde,0xcf,0x61,0x55,0x18,0x7a,0xac,
  11632. 0xb0,0x59,0x37,0x90,0x53,0xb3,0x00,0x88,
  11633. 0xb4,0x49,0x90,0x7b,0x96,0xcd,0xcc,0xc3
  11634. };
  11635. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96Cipher[] =
  11636. {
  11637. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11638. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11639. 0x47,0xb5,0xf3,0x30,0x3b
  11640. };
  11641. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96CipherLong[] =
  11642. {
  11643. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11644. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11645. 0x47,0xb5,0xf3,0x30,0x3b,0xef,0xcd,0x80,
  11646. 0xe3,0x61,0x34,0xef,0x4e,0x1b,0x79,0xc1
  11647. };
  11648. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96_2CipherLong[] =
  11649. {
  11650. 0x3c,0xb2,0xff,0xc0,0x24,0xe1,0xf5,0xc4,
  11651. 0x0f,0xd1,0x0a,0x1b,0xbe,0x1f,0x23,0xa1,
  11652. 0x8e,0xbf,0x2b,0x96,0xb6,0x37,0xc8,0x25,
  11653. 0x06,0x90,0xe2,0xca,0x71,0x24,0x52,0x95,
  11654. 0xaa,0x8c,0x80,0xdf,0xb7,0xd7,0x30,0xb0,
  11655. 0xcc,0x06,0x4f,0x28,0xa2,0x74,0x27,0xf8
  11656. };
  11657. #endif
  11658. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128Cipher[] =
  11659. {
  11660. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11661. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11662. 0x8c,0x68,0xa7,0xd9,0x57
  11663. };
  11664. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128CipherLong[] =
  11665. {
  11666. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11667. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11668. 0x8c,0x68,0xa7,0xd9,0x57,0xab,0x09,0x0f,
  11669. 0x01,0xc4,0x4e,0x62,0xaf,0xc2,0xdf,0x1a
  11670. };
  11671. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11672. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128_2CipherLong[] =
  11673. {
  11674. 0x88,0x0a,0x26,0x4e,0xa8,0x26,0x21,0xe0,
  11675. 0xfc,0xbc,0x63,0xdc,0xd9,0x60,0x52,0xb2,
  11676. 0x99,0x2f,0xbb,0x1e,0x00,0xf5,0x9f,0x6d,
  11677. 0xab,0x48,0x0f,0xc6,0x37,0x12,0x56,0xe3,
  11678. 0x12,0x8d,0x31,0xc8,0xea,0xf4,0x41,0x82,
  11679. 0x7a,0x88,0xe0,0xd7,0xf0,0x67,0x03,0xa4
  11680. };
  11681. #endif
  11682. #endif
  11683. #ifdef WOLFSSL_AES_256
  11684. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  11685. {
  11686. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11687. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11688. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11689. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11690. };
  11691. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  11692. {
  11693. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  11694. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
  11695. 0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,
  11696. 0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
  11697. 0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,
  11698. 0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
  11699. 0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,
  11700. 0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6
  11701. };
  11702. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11703. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32Cipher[] =
  11704. {
  11705. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11706. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11707. 0xa2,0x13,0x47,0x74,0xda
  11708. };
  11709. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32CipherLong[] =
  11710. {
  11711. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11712. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11713. 0xa2,0x13,0x47,0x74,0xda,0x89,0x77,0x40,
  11714. 0x28,0x9c,0xe8,0x19,0x26,0x32,0xd8,0x1f
  11715. };
  11716. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32_2CipherLong[] =
  11717. {
  11718. 0xf6,0xd9,0x22,0xc6,0x80,0x29,0xaf,0x14,
  11719. 0x54,0x6c,0x0a,0xce,0x42,0xea,0x3c,0xa1,
  11720. 0x7c,0xeb,0x36,0x0d,0x8e,0xd7,0x8c,0x59,
  11721. 0xa8,0x09,0x9f,0x9e,0xba,0x5b,0x95,0xfa,
  11722. 0x26,0x8c,0x37,0x59,0xf8,0xae,0x8e,0xaa,
  11723. 0x4d,0xe4,0x1c,0xfe,0x51,0xc7,0xb7,0xcc
  11724. };
  11725. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64Cipher[] =
  11726. {
  11727. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11728. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11729. 0xd4,0x94,0x4c,0xcd,0x4d
  11730. };
  11731. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64CipherLong[] =
  11732. {
  11733. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11734. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11735. 0xd4,0x94,0x4c,0xcd,0x4d,0x47,0x5a,0x92,
  11736. 0x26,0x49,0x81,0x7a,0xda,0x36,0x27,0x01
  11737. };
  11738. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64_2CipherLong[] =
  11739. {
  11740. 0xf7,0x9c,0xbf,0xf6,0xa2,0xaa,0x8a,0x0a,
  11741. 0x63,0x8a,0x20,0x2f,0x12,0xf1,0x8e,0x49,
  11742. 0x30,0xc0,0x8d,0x5c,0x5f,0x8b,0xbc,0x16,
  11743. 0xdd,0x71,0xee,0x13,0x14,0x7b,0xe1,0x25,
  11744. 0xcb,0x87,0x8a,0xc6,0xdc,0x1d,0x54,0x7a,
  11745. 0xe1,0xe4,0x6f,0x0d,0x95,0x1b,0xd1,0x8b
  11746. };
  11747. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96Cipher[] =
  11748. {
  11749. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11750. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11751. 0xb8,0x69,0xa1,0x48,0x45
  11752. };
  11753. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96CipherLong[] =
  11754. {
  11755. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11756. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11757. 0xb8,0x69,0xa1,0x48,0x45,0xf1,0xc6,0x27,
  11758. 0x36,0xa8,0xb2,0x4b,0x0e,0x62,0x6b,0x72
  11759. };
  11760. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96_2CipherLong[] =
  11761. {
  11762. 0xd5,0x56,0x73,0xaa,0xb8,0xe4,0x06,0xf6,
  11763. 0x83,0x45,0x3a,0xb4,0xb9,0x63,0xec,0xad,
  11764. 0x73,0xc5,0xab,0x78,0xb1,0x21,0xab,0xef,
  11765. 0x69,0x15,0xb7,0x0c,0xe9,0xb4,0x3a,0xe7,
  11766. 0xbc,0xc4,0x22,0xbd,0x93,0xba,0x52,0xe0,
  11767. 0x91,0x2f,0x5e,0x8d,0x6d,0x59,0xf7,0xc2
  11768. };
  11769. #endif
  11770. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
  11771. {
  11772. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11773. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11774. 0x4b,0x45,0x7c,0xd6,0x8a
  11775. };
  11776. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128CipherLong[] =
  11777. {
  11778. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11779. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11780. 0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
  11781. 0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
  11782. };
  11783. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11784. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128_2CipherLong[] =
  11785. {
  11786. 0x24,0x5c,0x09,0xa0,0x3b,0x1a,0x5a,0x94,
  11787. 0x2b,0x93,0x56,0x13,0x48,0xa0,0x21,0xce,
  11788. 0x95,0x11,0xa3,0x76,0xd6,0x59,0x88,0x42,
  11789. 0x04,0x71,0x69,0x62,0x28,0xb2,0xee,0x9d,
  11790. 0xd5,0xa0,0xea,0xc7,0x37,0x93,0x92,0xc7,
  11791. 0xf2,0xb6,0x8d,0xd9,0x59,0x1a,0xfa,0xbb
  11792. };
  11793. #endif
  11794. #endif
  11795. int i;
  11796. struct {
  11797. const byte* key;
  11798. int keySz;
  11799. const byte* iv;
  11800. const byte* plain;
  11801. int len;
  11802. const byte* cipher;
  11803. } testVec[] = {
  11804. #ifdef WOLFSSL_AES_128
  11805. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11806. ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
  11807. /* let's try with just 9 bytes, non block size test */
  11808. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11809. ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
  11810. /* and an additional 9 bytes to reuse tmp left buffer */
  11811. { NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
  11812. /* Counter wrapping */
  11813. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11814. ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
  11815. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11816. ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
  11817. ctr128Wrap128CipherLong },
  11818. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11819. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128_2,
  11820. ctrPlain, (int)sizeof(ctr128Wrap128_2CipherLong),
  11821. ctr128Wrap128_2CipherLong },
  11822. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11823. ctrPlain, (int)sizeof(ctr128Wrap96Cipher), ctr128Wrap96Cipher },
  11824. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11825. ctrPlain, (int)sizeof(ctr128Wrap96CipherLong),
  11826. ctr128Wrap96CipherLong },
  11827. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96_2,
  11828. ctrPlain, (int)sizeof(ctr128Wrap96_2CipherLong),
  11829. ctr128Wrap96_2CipherLong },
  11830. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11831. ctrPlain, (int)sizeof(ctr128Wrap64Cipher), ctr128Wrap64Cipher },
  11832. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11833. ctrPlain, (int)sizeof(ctr128Wrap64CipherLong),
  11834. ctr128Wrap64CipherLong },
  11835. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64_2,
  11836. ctrPlain, (int)sizeof(ctr128Wrap64_2CipherLong),
  11837. ctr128Wrap64_2CipherLong },
  11838. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11839. ctrPlain, (int)sizeof(ctr128Wrap32Cipher), ctr128Wrap32Cipher },
  11840. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11841. ctrPlain, (int)sizeof(ctr128Wrap32CipherLong),
  11842. ctr128Wrap32CipherLong },
  11843. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32_2,
  11844. ctrPlain, (int)sizeof(ctr128Wrap32_2CipherLong),
  11845. ctr128Wrap32_2CipherLong },
  11846. #endif
  11847. #endif
  11848. #ifdef WOLFSSL_AES_192
  11849. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11850. ctrPlain, (int)sizeof(ctrPlain), ctr192Cipher },
  11851. /* let's try with just 9 bytes, non block size test */
  11852. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11853. ctrPlain, (int)sizeof(oddCipher), ctr192Cipher },
  11854. /* Counter wrapping */
  11855. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11856. ctrPlain, (int)sizeof(ctr192Wrap128Cipher), ctr192Wrap128Cipher },
  11857. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11858. ctrPlain, (int)sizeof(ctr192Wrap128CipherLong),
  11859. ctr192Wrap128CipherLong },
  11860. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11861. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128_2,
  11862. ctrPlain, (int)sizeof(ctr192Wrap128_2CipherLong),
  11863. ctr192Wrap128_2CipherLong },
  11864. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11865. ctrPlain, (int)sizeof(ctr192Wrap96Cipher), ctr192Wrap96Cipher },
  11866. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11867. ctrPlain, (int)sizeof(ctr192Wrap96CipherLong),
  11868. ctr192Wrap96CipherLong },
  11869. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96_2,
  11870. ctrPlain, (int)sizeof(ctr192Wrap96_2CipherLong),
  11871. ctr192Wrap96_2CipherLong },
  11872. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11873. ctrPlain, (int)sizeof(ctr192Wrap64Cipher), ctr192Wrap64Cipher },
  11874. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11875. ctrPlain, (int)sizeof(ctr192Wrap64CipherLong),
  11876. ctr192Wrap64CipherLong },
  11877. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64_2,
  11878. ctrPlain, (int)sizeof(ctr192Wrap64_2CipherLong),
  11879. ctr192Wrap64_2CipherLong },
  11880. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11881. ctrPlain, (int)sizeof(ctr192Wrap32Cipher), ctr192Wrap32Cipher },
  11882. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11883. ctrPlain, (int)sizeof(ctr192Wrap32CipherLong),
  11884. ctr192Wrap32CipherLong },
  11885. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32_2,
  11886. ctrPlain, (int)sizeof(ctr192Wrap32_2CipherLong),
  11887. ctr192Wrap32_2CipherLong },
  11888. #endif
  11889. #endif
  11890. #ifdef WOLFSSL_AES_256
  11891. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11892. ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
  11893. /* let's try with just 9 bytes, non block size test */
  11894. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11895. ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
  11896. /* Counter wrapping */
  11897. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11898. ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
  11899. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11900. ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
  11901. ctr256Wrap128CipherLong },
  11902. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11903. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128_2,
  11904. ctrPlain, (int)sizeof(ctr256Wrap128_2CipherLong),
  11905. ctr256Wrap128_2CipherLong },
  11906. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11907. ctrPlain, (int)sizeof(ctr256Wrap96Cipher), ctr256Wrap96Cipher },
  11908. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11909. ctrPlain, (int)sizeof(ctr256Wrap96CipherLong),
  11910. ctr256Wrap96CipherLong },
  11911. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96_2,
  11912. ctrPlain, (int)sizeof(ctr256Wrap96_2CipherLong),
  11913. ctr256Wrap96_2CipherLong },
  11914. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11915. ctrPlain, (int)sizeof(ctr256Wrap64Cipher), ctr256Wrap64Cipher },
  11916. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11917. ctrPlain, (int)sizeof(ctr256Wrap64CipherLong),
  11918. ctr256Wrap64CipherLong },
  11919. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64_2,
  11920. ctrPlain, (int)sizeof(ctr256Wrap64_2CipherLong),
  11921. ctr256Wrap64_2CipherLong },
  11922. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11923. ctrPlain, (int)sizeof(ctr256Wrap32Cipher), ctr256Wrap32Cipher },
  11924. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11925. ctrPlain, (int)sizeof(ctr256Wrap32CipherLong),
  11926. ctr256Wrap32CipherLong },
  11927. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32_2,
  11928. ctrPlain, (int)sizeof(ctr256Wrap32_2CipherLong),
  11929. ctr256Wrap32_2CipherLong },
  11930. #endif
  11931. #endif
  11932. };
  11933. #define AES_CTR_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  11934. WOLFSSL_ENTER("aes_ctr_test");
  11935. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11936. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  11937. if (enc == NULL)
  11938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11939. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  11940. if (dec == NULL)
  11941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11942. #else
  11943. XMEMSET(enc, 0, sizeof(Aes));
  11944. XMEMSET(dec, 0, sizeof(Aes));
  11945. ret = wc_AesInit(enc, HEAP_HINT, devId);
  11946. if (ret != 0)
  11947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11948. ret = wc_AesInit(dec, HEAP_HINT, devId);
  11949. if (ret != 0)
  11950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11951. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  11952. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11953. if (testVec[i].key != NULL) {
  11954. ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
  11955. testVec[i].iv, AES_ENCRYPTION);
  11956. if (ret != 0) {
  11957. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11958. }
  11959. /* Ctr only uses encrypt, even on key setup */
  11960. ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
  11961. testVec[i].iv, AES_ENCRYPTION);
  11962. if (ret != 0) {
  11963. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11964. }
  11965. }
  11966. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
  11967. if (ret != 0) {
  11968. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11969. }
  11970. ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
  11971. if (ret != 0) {
  11972. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11973. }
  11974. if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
  11975. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11976. }
  11977. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  11978. if (XMEMCMP(cipher, testVec[i].cipher, (size_t)testVec[i].len)) {
  11979. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11980. }
  11981. #endif
  11982. }
  11983. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11984. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11985. if (testVec[i].key != NULL) {
  11986. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  11987. testVec[i].iv, AES_ENCRYPTION);
  11988. if (ret != 0) {
  11989. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11990. }
  11991. /* Ctr only uses encrypt, even on key setup */
  11992. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  11993. testVec[i].iv, AES_ENCRYPTION);
  11994. if (ret != 0) {
  11995. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11996. }
  11997. }
  11998. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11999. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  12000. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12001. if (ret != 0) {
  12002. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12003. }
  12004. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12005. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12006. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12007. if (ret != 0) {
  12008. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12009. }
  12010. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12011. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12012. }
  12013. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12014. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12015. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12016. }
  12017. #endif
  12018. }
  12019. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  12020. if (testVec[i].key != NULL) {
  12021. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12022. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  12023. testVec[i].iv, AES_ENCRYPTION);
  12024. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12025. if (ret != 0) {
  12026. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12027. }
  12028. /* Ctr only uses encrypt, even on key setup */
  12029. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12030. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  12031. testVec[i].iv, AES_ENCRYPTION);
  12032. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12033. if (ret != 0) {
  12034. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12035. }
  12036. }
  12037. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  12038. if (ret != 0) {
  12039. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12040. }
  12041. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12042. if (ret != 0) {
  12043. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12044. }
  12045. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12046. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12047. }
  12048. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12049. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12050. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12051. }
  12052. #endif
  12053. }
  12054. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12055. out:
  12056. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12057. wc_AesDelete(enc, &enc);
  12058. #else
  12059. wc_AesFree(enc);
  12060. #endif
  12061. #ifdef HAVE_AES_DECRYPT
  12062. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12063. wc_AesDelete(dec, &dec);
  12064. #else
  12065. wc_AesFree(dec);
  12066. #endif
  12067. #endif
  12068. return ret;
  12069. }
  12070. #endif /* WOLFSSL_AES_COUNTER */
  12071. #ifdef HAVE_AES_ECB
  12072. static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12073. {
  12074. wc_test_ret_t ret = 0;
  12075. /* keys padded to block size (16 bytes) */
  12076. WOLFSSL_SMALL_STACK_STATIC const byte key_128[] =
  12077. "0123456789abcdef ";
  12078. WOLFSSL_SMALL_STACK_STATIC const byte key_192[] =
  12079. "0123456789abcdef01234567 ";
  12080. WOLFSSL_SMALL_STACK_STATIC const byte key_256[] =
  12081. "0123456789abcdef0123456789abcdef ";
  12082. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12083. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12084. 0x6e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  12085. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20
  12086. };
  12087. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[WC_AES_BLOCK_SIZE] = {
  12088. 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6,
  12089. 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1
  12090. };
  12091. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[WC_AES_BLOCK_SIZE] = {
  12092. 0x06, 0x57, 0xee, 0x78, 0x3f, 0x96, 0x00, 0xb1,
  12093. 0xec, 0x76, 0x94, 0x30, 0x29, 0xbe, 0x15, 0xab
  12094. };
  12095. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[WC_AES_BLOCK_SIZE] = {
  12096. 0xcd, 0xf2, 0x81, 0x3e, 0x73, 0x3e, 0xf7, 0x33,
  12097. 0x3d, 0x18, 0xfd, 0x41, 0x85, 0x37, 0x04, 0x82
  12098. };
  12099. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] = {
  12100. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12101. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12102. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12103. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12104. };
  12105. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] = {
  12106. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12107. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12108. };
  12109. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] = {
  12110. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12111. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12112. };
  12113. int i;
  12114. struct {
  12115. const byte* key;
  12116. int keySz;
  12117. const byte* iv; /* null uses 0's */
  12118. const byte* plain;
  12119. const byte* verify;
  12120. } testVec[] = {
  12121. { key_128, 16, iv, msg, verify_ecb_128 },
  12122. { key_192, 24, iv, msg, verify_ecb_192 },
  12123. { key_256, 32, iv, msg, verify_ecb_256 },
  12124. { niKey, 32, NULL, niPlain, niCipher }
  12125. };
  12126. #define AES_ECB_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  12127. for (i = 0; i < AES_ECB_TEST_LEN; i++) {
  12128. ret = wc_AesSetKey(enc, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12129. AES_ENCRYPTION);
  12130. if (ret != 0)
  12131. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12132. #ifdef HAVE_AES_DECRYPT
  12133. ret = wc_AesSetKey(dec, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12134. AES_DECRYPTION);
  12135. if (ret != 0)
  12136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12137. #endif
  12138. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12139. ret = wc_AesEcbEncrypt(enc, cipher, testVec[i].plain, WC_AES_BLOCK_SIZE);
  12140. #if defined(WOLFSSL_ASYNC_CRYPT)
  12141. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12142. #endif
  12143. if (ret != 0)
  12144. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12145. if (XMEMCMP(cipher, testVec[i].verify, WC_AES_BLOCK_SIZE)) {
  12146. WOLFSSL_MSG("aes_test cipher vs verify_ecb mismatch!");
  12147. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12148. }
  12149. #ifdef HAVE_AES_DECRYPT
  12150. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12151. ret = wc_AesEcbDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE);
  12152. #if defined(WOLFSSL_ASYNC_CRYPT)
  12153. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12154. #endif
  12155. if (ret != 0)
  12156. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12157. if (XMEMCMP(plain, testVec[i].plain, WC_AES_BLOCK_SIZE))
  12158. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12159. #endif /* HAVE_AES_DECRYPT */
  12160. (void)dec;
  12161. (void)plain;
  12162. }
  12163. out:
  12164. return ret;
  12165. }
  12166. #endif /* HAVE_AES_ECB */
  12167. #ifdef WOLFSSL_AES_DIRECT
  12168. static wc_test_ret_t aes_direct_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12169. {
  12170. wc_test_ret_t ret = 0;
  12171. WOLFSSL_ENTER("aes_direct_test");
  12172. #if defined(WOLFSSL_AES_256)
  12173. {
  12174. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  12175. {
  12176. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12177. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12178. };
  12179. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  12180. {
  12181. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12182. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12183. };
  12184. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  12185. {
  12186. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12187. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12188. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12189. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12190. };
  12191. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12192. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  12193. if (ret != 0)
  12194. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12195. #if !defined(HAVE_SELFTEST) && \
  12196. (defined(WOLFSSL_LINUXKM) || \
  12197. !defined(HAVE_FIPS) || \
  12198. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12199. ret = wc_AesEncryptDirect(enc, cipher, niPlain);
  12200. if (ret != 0)
  12201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12202. #else
  12203. wc_AesEncryptDirect(enc, cipher, niPlain);
  12204. #endif
  12205. if (XMEMCMP(cipher, niCipher, WC_AES_BLOCK_SIZE) != 0)
  12206. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12207. #ifdef HAVE_AES_DECRYPT
  12208. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12209. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  12210. if (ret != 0)
  12211. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12212. #if !defined(HAVE_SELFTEST) && \
  12213. (defined(WOLFSSL_LINUXKM) || \
  12214. !defined(HAVE_FIPS) || \
  12215. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12216. ret = wc_AesDecryptDirect(dec, plain, niCipher);
  12217. if (ret != 0)
  12218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12219. #else
  12220. wc_AesDecryptDirect(dec, plain, niCipher);
  12221. #endif
  12222. if (XMEMCMP(plain, niPlain, WC_AES_BLOCK_SIZE) != 0)
  12223. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12224. #endif /* HAVE_AES_DECRYPT */
  12225. }
  12226. out:
  12227. #endif /* WOLFSSL_AES_256 */
  12228. (void)enc;
  12229. (void)dec;
  12230. (void)cipher;
  12231. (void)plain;
  12232. return ret;
  12233. }
  12234. #endif /* WOLFSSL_AES_DIRECT */
  12235. #ifdef HAVE_AES_CBC
  12236. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void)
  12237. {
  12238. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12239. Aes *enc = NULL;
  12240. #else
  12241. Aes enc[1];
  12242. #endif
  12243. #ifdef HAVE_AES_DECRYPT
  12244. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12245. Aes *dec = NULL;
  12246. #else
  12247. Aes dec[1];
  12248. #endif
  12249. #endif
  12250. byte cipher[WC_AES_BLOCK_SIZE * 4];
  12251. #ifdef HAVE_AES_DECRYPT
  12252. byte plain [WC_AES_BLOCK_SIZE * 4];
  12253. #endif
  12254. wc_test_ret_t ret = 0;
  12255. WOLFSSL_ENTER("aes_cbc_test");
  12256. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12257. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12258. if (enc == NULL)
  12259. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12260. #ifdef HAVE_AES_DECRYPT
  12261. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12262. if (dec == NULL)
  12263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12264. #endif
  12265. #else
  12266. XMEMSET(enc, 0, sizeof(Aes));
  12267. #ifdef HAVE_AES_DECRYPT
  12268. XMEMSET(dec, 0, sizeof(Aes));
  12269. #endif
  12270. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12271. if (ret != 0)
  12272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12273. #ifdef HAVE_AES_DECRYPT
  12274. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12275. if (ret != 0)
  12276. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12277. #endif
  12278. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12279. #ifdef WOLFSSL_AES_128
  12280. {
  12281. /* "Now is the time for all " w/o trailing 0 */
  12282. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12283. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  12284. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  12285. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  12286. };
  12287. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12288. {
  12289. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  12290. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  12291. };
  12292. #ifdef HAVE_RENESAS_SYNC
  12293. const byte *key = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  12294. #else
  12295. /* padded to 16-byye */
  12296. WOLFSSL_SMALL_STACK_STATIC const byte key[] = "0123456789abcdef ";
  12297. #endif
  12298. /* padded to 16-bytes */
  12299. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12300. ret = wc_AesSetKey(enc, key, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  12301. if (ret != 0)
  12302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12303. #ifdef HAVE_AES_DECRYPT
  12304. ret = wc_AesSetKey(dec, key, WC_AES_BLOCK_SIZE, iv, AES_DECRYPTION);
  12305. if (ret != 0)
  12306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12307. #endif
  12308. XMEMSET(cipher, 0, sizeof(cipher));
  12309. ret = wc_AesCbcEncrypt(enc, cipher, msg, WC_AES_BLOCK_SIZE);
  12310. #if defined(WOLFSSL_ASYNC_CRYPT)
  12311. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12312. #endif
  12313. if (ret != 0)
  12314. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12315. #ifdef HAVE_AES_DECRYPT
  12316. XMEMSET(plain, 0, sizeof(plain));
  12317. ret = wc_AesCbcDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE);
  12318. #if defined(WOLFSSL_ASYNC_CRYPT)
  12319. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12320. #endif
  12321. if (ret != 0) {
  12322. WOLFSSL_MSG("failed wc_AesCbcDecrypt");
  12323. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12324. }
  12325. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE)) {
  12326. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain compare");
  12327. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12328. }
  12329. #endif /* HAVE_AES_DECRYPT */
  12330. /* skipped because wrapped key use in case of renesas sm */
  12331. #ifndef HAVE_RENESAS_SYNC
  12332. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE)) {
  12333. WOLFSSL_MSG("wc_AesCbcDecrypt failed cipher-verify compare");
  12334. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12335. }
  12336. #endif
  12337. }
  12338. #endif /* WOLFSSL_AES_128 */
  12339. #if defined(WOLFSSL_AESNI) && defined(HAVE_AES_DECRYPT)
  12340. {
  12341. WOLFSSL_SMALL_STACK_STATIC const byte bigMsg[] = {
  12342. /* "All work and no play makes Jack a dull boy. " */
  12343. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12344. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12345. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12346. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12347. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12348. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12349. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12350. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12351. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12352. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12353. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12354. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12355. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12356. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12357. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12358. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12359. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12360. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12361. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12362. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12363. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12364. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12365. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12366. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12367. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12368. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12369. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12370. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12371. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12372. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12373. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12374. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12375. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12376. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12377. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12378. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12379. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12380. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12381. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12382. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12383. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12384. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12385. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12386. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12387. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12388. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12389. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12390. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20
  12391. };
  12392. WOLFSSL_SMALL_STACK_STATIC const byte bigKey[] =
  12393. "0123456789abcdeffedcba9876543210";
  12394. /* padded to 16-bytes */
  12395. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12396. word32 keySz, msgSz;
  12397. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12398. byte *bigCipher = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12399. DYNAMIC_TYPE_TMP_BUFFER);
  12400. byte *bigPlain = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12401. DYNAMIC_TYPE_TMP_BUFFER);
  12402. if ((bigCipher == NULL) ||
  12403. (bigPlain == NULL)) {
  12404. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12405. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12406. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12407. }
  12408. #else
  12409. byte bigCipher[sizeof(bigMsg)];
  12410. byte bigPlain[sizeof(bigMsg)];
  12411. #endif
  12412. /* Iterate from one WC_AES_BLOCK_SIZE of bigMsg through the whole
  12413. * message by WC_AES_BLOCK_SIZE for each size of AES key. */
  12414. for (keySz = 16; keySz <= 32; keySz += 8) {
  12415. for (msgSz = WC_AES_BLOCK_SIZE;
  12416. msgSz <= sizeof(bigMsg);
  12417. msgSz += WC_AES_BLOCK_SIZE) {
  12418. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12419. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12420. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12421. if (ret != 0) {
  12422. ret = WC_TEST_RET_ENC_EC(ret);
  12423. break;
  12424. }
  12425. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12426. if (ret != 0) {
  12427. ret = WC_TEST_RET_ENC_EC(ret);
  12428. break;
  12429. }
  12430. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12431. #if defined(WOLFSSL_ASYNC_CRYPT)
  12432. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12433. #endif
  12434. if (ret != 0) {
  12435. ret = WC_TEST_RET_ENC_EC(ret);
  12436. break;
  12437. }
  12438. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12439. #if defined(WOLFSSL_ASYNC_CRYPT)
  12440. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12441. #endif
  12442. if (ret != 0) {
  12443. ret = WC_TEST_RET_ENC_EC(ret);
  12444. break;
  12445. }
  12446. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12447. ret = WC_TEST_RET_ENC_NC;
  12448. break;
  12449. }
  12450. }
  12451. if (ret != 0)
  12452. break;
  12453. }
  12454. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12455. /* Iterate from one WC_AES_BLOCK_SIZE of bigMsg through the whole
  12456. * message by WC_AES_BLOCK_SIZE for each size of AES key. */
  12457. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12458. for (keySz = 16; keySz <= 32; keySz += 8) {
  12459. for (msgSz = WC_AES_BLOCK_SIZE;
  12460. msgSz <= sizeof(bigMsg);
  12461. msgSz += WC_AES_BLOCK_SIZE) {
  12462. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12463. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12464. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12465. if (ret != 0) {
  12466. ret = WC_TEST_RET_ENC_EC(ret);
  12467. break;
  12468. }
  12469. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12470. if (ret != 0) {
  12471. ret = WC_TEST_RET_ENC_EC(ret);
  12472. break;
  12473. }
  12474. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12475. #if defined(WOLFSSL_ASYNC_CRYPT)
  12476. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12477. #endif
  12478. if (ret != 0) {
  12479. ret = WC_TEST_RET_ENC_EC(ret);
  12480. break;
  12481. }
  12482. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12483. #if defined(WOLFSSL_ASYNC_CRYPT)
  12484. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12485. #endif
  12486. if (ret != 0) {
  12487. ret = WC_TEST_RET_ENC_EC(ret);
  12488. break;
  12489. }
  12490. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12491. ret = WC_TEST_RET_ENC_NC;
  12492. break;
  12493. }
  12494. }
  12495. if (ret != 0)
  12496. break;
  12497. }
  12498. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12499. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12500. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12501. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12502. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12503. #endif
  12504. if (ret != 0)
  12505. goto out;
  12506. }
  12507. #endif /* WOLFSSL_AESNI && HAVE_AES_DECRYPT */
  12508. /* Test of AES IV state with encrypt/decrypt */
  12509. #if defined(WOLFSSL_AES_128) && !defined(HAVE_RENESAS_SYNC)
  12510. {
  12511. /* Test Vector from "NIST Special Publication 800-38A, 2001 Edition"
  12512. * https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38a.pdf
  12513. */
  12514. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  12515. {
  12516. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  12517. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  12518. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  12519. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51
  12520. };
  12521. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] =
  12522. {
  12523. 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
  12524. 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
  12525. 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
  12526. 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2
  12527. };
  12528. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  12529. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  12530. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  12531. };
  12532. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  12533. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  12534. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  12535. };
  12536. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  12537. if (ret != 0)
  12538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12539. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE * 2);
  12540. ret = wc_AesCbcEncrypt(enc, cipher, msg2, WC_AES_BLOCK_SIZE);
  12541. #if defined(WOLFSSL_ASYNC_CRYPT)
  12542. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12543. #endif
  12544. if (ret != 0)
  12545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12546. #ifndef HAVE_RENESAS_SYNC
  12547. if (XMEMCMP(cipher, verify2, WC_AES_BLOCK_SIZE))
  12548. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12549. #endif
  12550. ret = wc_AesCbcEncrypt(enc, cipher + WC_AES_BLOCK_SIZE,
  12551. msg2 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
  12552. #if defined(WOLFSSL_ASYNC_CRYPT)
  12553. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12554. #endif
  12555. if (ret != 0)
  12556. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12557. if (XMEMCMP(cipher + WC_AES_BLOCK_SIZE, verify2 + WC_AES_BLOCK_SIZE,
  12558. WC_AES_BLOCK_SIZE))
  12559. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12560. #if defined(HAVE_AES_DECRYPT)
  12561. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION);
  12562. if (ret != 0)
  12563. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12564. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE * 2);
  12565. ret = wc_AesCbcDecrypt(dec, plain, verify2, WC_AES_BLOCK_SIZE);
  12566. #if defined(WOLFSSL_ASYNC_CRYPT)
  12567. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12568. #endif
  12569. if (ret != 0)
  12570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12571. if (XMEMCMP(plain, msg2, WC_AES_BLOCK_SIZE))
  12572. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12573. ret = wc_AesCbcDecrypt(dec, plain + WC_AES_BLOCK_SIZE,
  12574. verify2 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
  12575. #if defined(WOLFSSL_ASYNC_CRYPT)
  12576. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12577. #endif
  12578. if (ret != 0)
  12579. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12580. if (XMEMCMP(plain + WC_AES_BLOCK_SIZE, msg2 + WC_AES_BLOCK_SIZE,
  12581. WC_AES_BLOCK_SIZE)) {
  12582. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain-msg2 compare");
  12583. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12584. }
  12585. #endif /* HAVE_AES_DECRYPT */
  12586. aes_cbc_oneshot_test();
  12587. }
  12588. #endif /* WOLFSSL_AES_128 && !HAVE_RENESAS_SYNC */
  12589. out:
  12590. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12591. wc_AesDelete(enc, &enc);
  12592. #else
  12593. wc_AesFree(enc);
  12594. #endif
  12595. #ifdef HAVE_AES_DECRYPT
  12596. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12597. wc_AesDelete(dec, &dec);
  12598. #else
  12599. wc_AesFree(dec);
  12600. #endif
  12601. #endif
  12602. return ret;
  12603. }
  12604. #endif /* HAVE_AES_CBC */
  12605. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12606. static wc_test_ret_t aes_ecb_direct_test(void)
  12607. {
  12608. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12609. Aes *enc = NULL;
  12610. #else
  12611. Aes enc[1];
  12612. #endif
  12613. #if !defined(HAVE_AES_DECRYPT) || \
  12614. (defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC))
  12615. Aes *dec = NULL;
  12616. #else
  12617. Aes dec[1];
  12618. #endif
  12619. byte cipher[WC_AES_BLOCK_SIZE];
  12620. byte plain [WC_AES_BLOCK_SIZE];
  12621. wc_test_ret_t ret = 0;
  12622. WOLFSSL_ENTER("aes_ecb/direct_test");
  12623. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  12624. XMEMSET(enc, 0, sizeof(Aes));
  12625. #ifdef HAVE_AES_DECRYPT
  12626. XMEMSET(dec, 0, sizeof(Aes));
  12627. #endif
  12628. #endif
  12629. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12630. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12631. if (enc == NULL)
  12632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12633. #ifdef HAVE_AES_DECRYPT
  12634. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12635. if (dec == NULL)
  12636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12637. #endif
  12638. #else
  12639. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12640. if (ret != 0)
  12641. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12642. #ifdef HAVE_AES_DECRYPT
  12643. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12644. if (ret != 0)
  12645. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12646. #endif
  12647. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12648. #ifdef HAVE_AES_ECB
  12649. ret = aes_ecb_test(enc, dec, cipher, plain);
  12650. if (ret != 0)
  12651. return ret;
  12652. #endif
  12653. #ifdef WOLFSSL_AES_DIRECT
  12654. ret = aes_direct_test(enc, dec, cipher, plain);
  12655. if (ret != 0)
  12656. return ret;
  12657. #endif
  12658. out:
  12659. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12660. wc_AesDelete(enc, &enc);
  12661. wc_AesDelete(dec, &dec);
  12662. #else
  12663. wc_AesFree(enc);
  12664. wc_AesFree(dec);
  12665. #endif
  12666. return ret;
  12667. }
  12668. #endif /* HAVE_AES_ECB || WOLFSSL_AES_DIRECT */
  12669. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void)
  12670. {
  12671. wc_test_ret_t ret = 0;
  12672. WOLFSSL_ENTER("aes_test");
  12673. #ifndef HAVE_RENESAS_SYNC
  12674. ret = aes_key_size_test();
  12675. if (ret != 0)
  12676. goto out;
  12677. #endif
  12678. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12679. ret = aes_ecb_direct_test();
  12680. if (ret != 0)
  12681. return ret;
  12682. #endif
  12683. out:
  12684. return ret;
  12685. }
  12686. #if defined(WOLFSSL_AES_CFB)
  12687. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void)
  12688. {
  12689. int ret;
  12690. WOLFSSL_ENTER("aes_cfb_test");
  12691. ret = aescfb_test_0();
  12692. if (ret != 0)
  12693. return ret;
  12694. #if !defined(WOLFSSL_NO_AES_CFB_1_8)
  12695. ret = aescfb1_test();
  12696. if (ret != 0)
  12697. return ret;
  12698. ret = aescfb8_test();
  12699. if (ret != 0)
  12700. return ret;
  12701. #endif
  12702. return 0;
  12703. }
  12704. #endif
  12705. #if defined(WOLFSSL_AES_XTS)
  12706. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void)
  12707. {
  12708. int ret = 0;
  12709. WOLFSSL_ENTER("aes_xts_test");
  12710. #ifdef WOLFSSL_AES_128
  12711. ret = aes_xts_128_test();
  12712. if (ret != 0)
  12713. return ret;
  12714. #endif
  12715. #ifdef WOLFSSL_AES_192
  12716. ret = aes_xts_192_test();
  12717. if (ret != 0)
  12718. return ret;
  12719. #endif
  12720. #ifdef WOLFSSL_AES_256
  12721. ret = aes_xts_256_test();
  12722. if (ret != 0)
  12723. return ret;
  12724. #endif
  12725. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  12726. ret = aes_xts_sector_test();
  12727. if (ret != 0)
  12728. return ret;
  12729. #endif
  12730. #ifdef WOLFSSL_AES_128
  12731. ret = aes_xts_args_test();
  12732. if (ret != 0)
  12733. return ret;
  12734. #endif
  12735. return 0;
  12736. }
  12737. #endif
  12738. #ifdef WOLFSSL_AES_192
  12739. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
  12740. {
  12741. wc_test_ret_t ret = 0;
  12742. #ifdef HAVE_AES_CBC
  12743. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12744. Aes *enc = NULL;
  12745. #else
  12746. Aes enc[1];
  12747. #endif
  12748. byte cipher[WC_AES_BLOCK_SIZE];
  12749. #ifdef HAVE_AES_DECRYPT
  12750. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12751. Aes *dec = NULL;
  12752. #else
  12753. Aes dec[1];
  12754. #endif
  12755. byte plain[WC_AES_BLOCK_SIZE];
  12756. #endif
  12757. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  12758. * Appendix F.2.3 */
  12759. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12760. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12761. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12762. };
  12763. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12764. {
  12765. 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  12766. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8
  12767. };
  12768. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12769. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  12770. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  12771. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  12772. };
  12773. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12774. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12775. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12776. };
  12777. WOLFSSL_ENTER("aes192_test");
  12778. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12779. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12780. if (enc == NULL)
  12781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12782. #ifdef HAVE_AES_DECRYPT
  12783. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12784. if (dec == NULL)
  12785. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12786. #endif
  12787. #else
  12788. XMEMSET(enc, 0, sizeof(Aes));
  12789. #ifdef HAVE_AES_DECRYPT
  12790. XMEMSET(dec, 0, sizeof(Aes));
  12791. #endif
  12792. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12793. if (ret != 0)
  12794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12795. #ifdef HAVE_AES_DECRYPT
  12796. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12797. if (ret != 0)
  12798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12799. #endif
  12800. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12801. ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
  12802. if (ret != 0)
  12803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12804. #ifdef HAVE_AES_DECRYPT
  12805. ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION);
  12806. if (ret != 0)
  12807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12808. #endif
  12809. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12810. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12811. #if defined(WOLFSSL_ASYNC_CRYPT)
  12812. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12813. #endif
  12814. if (ret != 0)
  12815. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12816. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12817. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12818. #ifdef HAVE_AES_DECRYPT
  12819. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12820. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12821. #if defined(WOLFSSL_ASYNC_CRYPT)
  12822. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12823. #endif
  12824. if (ret != 0)
  12825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12826. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12827. WOLFSSL_MSG("failed wc_AesCbcDecrypt plain-msg compare");
  12828. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12829. }
  12830. #endif
  12831. out:
  12832. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12833. wc_AesDelete(enc, &enc);
  12834. #else
  12835. wc_AesFree(enc);
  12836. #endif
  12837. #ifdef HAVE_AES_DECRYPT
  12838. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12839. wc_AesDelete(dec, &dec);
  12840. #else
  12841. wc_AesFree(dec);
  12842. #endif
  12843. #endif
  12844. #endif /* HAVE_AES_CBC */
  12845. return ret;
  12846. }
  12847. #endif /* WOLFSSL_AES_192 */
  12848. #ifdef WOLFSSL_AES_256
  12849. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
  12850. {
  12851. #ifdef HAVE_AES_CBC
  12852. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12853. Aes *enc = NULL;
  12854. #else
  12855. Aes enc[1];
  12856. #endif
  12857. byte cipher[WC_AES_BLOCK_SIZE];
  12858. #ifdef HAVE_AES_DECRYPT
  12859. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12860. Aes *dec = NULL;
  12861. #else
  12862. Aes dec[1];
  12863. #endif
  12864. byte plain[WC_AES_BLOCK_SIZE];
  12865. #endif
  12866. #endif /* HAVE_AES_CBC */
  12867. wc_test_ret_t ret = 0;
  12868. #ifdef HAVE_AES_CBC
  12869. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  12870. * Appendix F.2.5 */
  12871. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12872. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12873. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12874. };
  12875. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12876. {
  12877. 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  12878. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6
  12879. };
  12880. #ifdef HAVE_RENESAS_SYNC
  12881. byte *key =
  12882. (byte*)guser_PKCbInfo.wrapped_key_aes256;
  12883. int keySz = (256/8);
  12884. #else
  12885. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12886. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12887. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12888. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12889. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12890. };
  12891. int keySz = (int)sizeof(key);
  12892. #endif
  12893. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12894. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12895. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12896. };
  12897. WOLFSSL_ENTER("aes256_test");
  12898. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12899. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12900. if (enc == NULL)
  12901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12902. #ifdef HAVE_AES_DECRYPT
  12903. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12904. if (dec == NULL)
  12905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12906. #endif
  12907. #else
  12908. XMEMSET(enc, 0, sizeof(Aes));
  12909. #ifdef HAVE_AES_DECRYPT
  12910. XMEMSET(dec, 0, sizeof(Aes));
  12911. #endif
  12912. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12913. if (ret != 0)
  12914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12915. #ifdef HAVE_AES_DECRYPT
  12916. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12917. if (ret != 0)
  12918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12919. #endif
  12920. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12921. ret = wc_AesSetKey(enc, key, (word32)keySz, iv, AES_ENCRYPTION);
  12922. if (ret != 0)
  12923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12924. #ifdef HAVE_AES_DECRYPT
  12925. ret = wc_AesSetKey(dec, key, (word32)keySz, iv, AES_DECRYPTION);
  12926. if (ret != 0)
  12927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12928. #endif
  12929. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12930. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12931. #if defined(WOLFSSL_ASYNC_CRYPT)
  12932. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12933. #endif
  12934. if (ret != 0)
  12935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12936. #ifdef HAVE_AES_DECRYPT
  12937. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12938. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12939. #if defined(WOLFSSL_ASYNC_CRYPT)
  12940. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12941. #endif
  12942. if (ret != 0)
  12943. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12944. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12945. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12946. }
  12947. #endif
  12948. #ifndef HAVE_RENESAS_SYNC
  12949. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12950. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12951. #endif
  12952. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12953. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12954. if (ret != 0)
  12955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12956. #ifdef HAVE_AES_DECRYPT
  12957. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12958. if (ret != 0)
  12959. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12960. #endif
  12961. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12962. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12963. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12964. #if defined(WOLFSSL_ASYNC_CRYPT)
  12965. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12966. #endif
  12967. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12968. if (ret != 0)
  12969. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12970. #ifdef HAVE_AES_DECRYPT
  12971. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12972. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12973. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12974. #if defined(WOLFSSL_ASYNC_CRYPT)
  12975. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12976. #endif
  12977. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12978. if (ret != 0)
  12979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12980. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12981. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12982. }
  12983. #endif
  12984. #ifndef HAVE_RENESAS_SYNC
  12985. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12986. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12987. #endif
  12988. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12989. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12990. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12991. if (ret != 0)
  12992. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12993. #ifdef HAVE_AES_DECRYPT
  12994. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12995. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12996. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12997. if (ret != 0)
  12998. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12999. #endif
  13000. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  13001. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  13002. #if defined(WOLFSSL_ASYNC_CRYPT)
  13003. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13004. #endif
  13005. if (ret != 0)
  13006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13007. #ifdef HAVE_AES_DECRYPT
  13008. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  13009. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  13010. #if defined(WOLFSSL_ASYNC_CRYPT)
  13011. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13012. #endif
  13013. if (ret != 0)
  13014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13015. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  13016. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13017. }
  13018. #endif
  13019. #ifndef HAVE_RENESAS_SYNC
  13020. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  13021. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13022. #endif
  13023. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  13024. out:
  13025. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13026. wc_AesDelete(enc, &enc);
  13027. #else
  13028. wc_AesFree(enc);
  13029. #endif
  13030. #ifdef HAVE_AES_DECRYPT
  13031. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13032. wc_AesDelete(dec, &dec);
  13033. #else
  13034. wc_AesFree(dec);
  13035. #endif
  13036. #endif
  13037. #endif /* HAVE_AES_CBC */
  13038. return ret;
  13039. }
  13040. #endif /* WOLFSSL_AES_256 */
  13041. #ifdef HAVE_AESGCM
  13042. #ifdef WOLFSSL_AES_128
  13043. static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz,
  13044. byte* plain, int plainSz, byte* cipher, int cipherSz,
  13045. byte* aad, int aadSz, byte* tag, int tagSz)
  13046. {
  13047. wc_test_ret_t ret;
  13048. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13049. Aes *enc = NULL;
  13050. Aes *dec = NULL;
  13051. #else
  13052. Aes enc[1];
  13053. Aes dec[1];
  13054. #endif
  13055. byte resultT[WC_AES_BLOCK_SIZE];
  13056. byte resultP[WC_AES_BLOCK_SIZE * 3];
  13057. byte resultC[WC_AES_BLOCK_SIZE * 3];
  13058. XMEMSET(resultT, 0, sizeof(resultT));
  13059. XMEMSET(resultC, 0, sizeof(resultC));
  13060. XMEMSET(resultP, 0, sizeof(resultP));
  13061. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13062. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13063. if (enc == NULL)
  13064. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13065. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13066. if (dec == NULL)
  13067. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13068. #else
  13069. XMEMSET(enc, 0, sizeof(Aes));
  13070. XMEMSET(dec, 0, sizeof(Aes));
  13071. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13072. if (ret != 0)
  13073. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13074. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13075. if (ret != 0)
  13076. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13077. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  13078. ret = wc_AesGcmSetKey(enc, key, (word32)keySz);
  13079. if (ret != 0)
  13080. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13081. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13082. ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, (word32)ivSz,
  13083. resultT, (word32)tagSz, aad, (word32)aadSz);
  13084. #if defined(WOLFSSL_ASYNC_CRYPT)
  13085. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13086. #endif
  13087. if (ret != 0)
  13088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13089. if (cipher != NULL) {
  13090. if (XMEMCMP(cipher, resultC, (word32)cipherSz))
  13091. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13092. }
  13093. if (XMEMCMP(tag, resultT, (unsigned long)tagSz))
  13094. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13095. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13096. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13097. ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz,
  13098. resultT, tagSz, aad, aadSz);
  13099. #if defined(WOLFSSL_ASYNC_CRYPT)
  13100. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13101. #endif
  13102. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13103. if (ret != 0)
  13104. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13105. if (cipher != NULL) {
  13106. if (XMEMCMP(cipher, resultC, (unsigned long)cipherSz))
  13107. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13108. }
  13109. if (XMEMCMP(tag, resultT, tagSz))
  13110. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13111. #endif
  13112. #ifdef HAVE_AES_DECRYPT
  13113. ret = wc_AesGcmSetKey(dec, key, (word32)keySz);
  13114. if (ret != 0)
  13115. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13116. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)cipherSz,
  13117. iv, (word32)ivSz, resultT, (word32)tagSz, aad, (word32)aadSz);
  13118. #if defined(WOLFSSL_ASYNC_CRYPT)
  13119. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13120. #endif
  13121. if (ret != 0)
  13122. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13123. if (plain != NULL) {
  13124. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13125. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13126. }
  13127. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13128. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13129. ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz,
  13130. iv, ivSz, resultT, tagSz, aad, aadSz);
  13131. #if defined(WOLFSSL_ASYNC_CRYPT)
  13132. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13133. #endif
  13134. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13135. if (ret != 0)
  13136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13137. if (plain != NULL) {
  13138. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13139. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13140. }
  13141. #endif
  13142. #endif /* HAVE_AES_DECRYPT */
  13143. ret = 0;
  13144. out:
  13145. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13146. wc_AesDelete(enc, &enc);
  13147. wc_AesDelete(dec, &dec);
  13148. #else
  13149. wc_AesFree(enc);
  13150. wc_AesFree(dec);
  13151. #endif
  13152. return ret;
  13153. }
  13154. #endif
  13155. /* tests that only use 12 byte IV and 16 or less byte AAD
  13156. * test vectors are from NIST SP 800-38D
  13157. * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES*/
  13158. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void)
  13159. {
  13160. #ifdef WOLFSSL_AES_128
  13161. byte key1[] = {
  13162. 0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62,
  13163. 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc
  13164. };
  13165. byte iv1[] = {
  13166. 0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa,
  13167. 0xe4, 0xed, 0x2f, 0x6d
  13168. };
  13169. ALIGN64 byte plain1[] = {
  13170. 0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad,
  13171. 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01,
  13172. 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac,
  13173. 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01
  13174. };
  13175. byte aad1[] = {
  13176. 0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73,
  13177. 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1
  13178. };
  13179. ALIGN64 byte cipher1[] = {
  13180. 0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d,
  13181. 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d,
  13182. 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46,
  13183. 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb
  13184. };
  13185. byte tag1[] = {
  13186. 0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7,
  13187. 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2
  13188. };
  13189. byte key2[] = {
  13190. 0x01, 0x6d, 0xbb, 0x38, 0xda, 0xa7, 0x6d, 0xfe,
  13191. 0x7d, 0xa3, 0x84, 0xeb, 0xf1, 0x24, 0x03, 0x64
  13192. };
  13193. byte iv2[] = {
  13194. 0x07, 0x93, 0xef, 0x3a, 0xda, 0x78, 0x2f, 0x78,
  13195. 0xc9, 0x8a, 0xff, 0xe3
  13196. };
  13197. ALIGN64 byte plain2[] = {
  13198. 0x4b, 0x34, 0xa9, 0xec, 0x57, 0x63, 0x52, 0x4b,
  13199. 0x19, 0x1d, 0x56, 0x16, 0xc5, 0x47, 0xf6, 0xb7
  13200. };
  13201. ALIGN64 byte cipher2[] = {
  13202. 0x60, 0x9a, 0xa3, 0xf4, 0x54, 0x1b, 0xc0, 0xfe,
  13203. 0x99, 0x31, 0xda, 0xad, 0x2e, 0xe1, 0x5d, 0x0c
  13204. };
  13205. byte tag2[] = {
  13206. 0x33, 0xaf, 0xec, 0x59, 0xc4, 0x5b, 0xaf, 0x68,
  13207. 0x9a, 0x5e, 0x1b, 0x13, 0xae, 0x42, 0x36, 0x19
  13208. };
  13209. byte key3[] = {
  13210. 0xb0, 0x1e, 0x45, 0xcc, 0x30, 0x88, 0xaa, 0xba,
  13211. 0x9f, 0xa4, 0x3d, 0x81, 0xd4, 0x81, 0x82, 0x3f
  13212. };
  13213. byte iv3[] = {
  13214. 0x5a, 0x2c, 0x4a, 0x66, 0x46, 0x87, 0x13, 0x45,
  13215. 0x6a, 0x4b, 0xd5, 0xe1
  13216. };
  13217. byte tag3[] = {
  13218. 0x01, 0x42, 0x80, 0xf9, 0x44, 0xf5, 0x3c, 0x68,
  13219. 0x11, 0x64, 0xb2, 0xff
  13220. };
  13221. wc_test_ret_t ret;
  13222. WOLFSSL_ENTER("aesgcm_default_test");
  13223. ret = aesgcm_default_test_helper(key1, sizeof(key1), iv1, sizeof(iv1),
  13224. plain1, sizeof(plain1), cipher1, sizeof(cipher1),
  13225. aad1, sizeof(aad1), tag1, sizeof(tag1));
  13226. if (ret != 0) {
  13227. return ret;
  13228. }
  13229. ret = aesgcm_default_test_helper(key2, sizeof(key2), iv2, sizeof(iv2),
  13230. plain2, sizeof(plain2), cipher2, sizeof(cipher2),
  13231. NULL, 0, tag2, sizeof(tag2));
  13232. if (ret != 0) {
  13233. return ret;
  13234. }
  13235. ret = aesgcm_default_test_helper(key3, sizeof(key3), iv3, sizeof(iv3),
  13236. NULL, 0, NULL, 0,
  13237. NULL, 0, tag3, sizeof(tag3));
  13238. if (ret != 0) {
  13239. return ret;
  13240. }
  13241. #endif
  13242. return 0;
  13243. }
  13244. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
  13245. {
  13246. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13247. Aes *enc = NULL;
  13248. Aes *dec = NULL;
  13249. #else
  13250. Aes enc[1];
  13251. Aes dec[1];
  13252. #endif
  13253. /*
  13254. * This is Test Case 16 from the document Galois/
  13255. * Counter Mode of Operation (GCM) by McGrew and
  13256. * Viega.
  13257. */
  13258. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  13259. {
  13260. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  13261. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  13262. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  13263. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  13264. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  13265. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  13266. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  13267. 0xba, 0x63, 0x7b, 0x39
  13268. };
  13269. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  13270. {
  13271. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13272. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13273. 0xab, 0xad, 0xda, 0xd2
  13274. };
  13275. #ifdef WOLFSSL_AES_256
  13276. #ifdef HAVE_RENESAS_SYNC
  13277. const byte *k1 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  13278. int k1Sz = (int)(256/8);
  13279. #else
  13280. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13281. {
  13282. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13283. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13284. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13285. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  13286. };
  13287. int k1Sz = (int)sizeof(k1);
  13288. #endif
  13289. #endif /* WOLFSSL_AES_256 */
  13290. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13291. {
  13292. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  13293. 0xde, 0xca, 0xf8, 0x88
  13294. };
  13295. #if defined(WOLFSSL_AES_256) || defined(WOLFSSL_AES_192)
  13296. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  13297. {
  13298. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  13299. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  13300. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  13301. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  13302. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  13303. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  13304. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  13305. 0xbc, 0xc9, 0xf6, 0x62
  13306. };
  13307. #endif /* WOLFSSL_AES_256 || WOLFSSL_AES_192 */
  13308. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13309. {
  13310. 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
  13311. 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b
  13312. };
  13313. /* FIPS, QAT and PIC32MZ HW Crypto only support 12-byte IV */
  13314. #if !defined(HAVE_FIPS) && \
  13315. !defined(WOLFSSL_PIC32MZ_CRYPT) && \
  13316. !defined(FREESCALE_LTC) && !defined(FREESCALE_MMCAU) && \
  13317. !defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13318. !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(WOLFSSL_KCAPI_AES) && \
  13319. !(defined(WOLF_CRYPTO_CB) && \
  13320. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  13321. #define ENABLE_NON_12BYTE_IV_TEST
  13322. #ifdef WOLFSSL_AES_192
  13323. /* Test Case 12, uses same plaintext and AAD data. */
  13324. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13325. {
  13326. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13327. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13328. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c
  13329. };
  13330. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13331. {
  13332. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  13333. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  13334. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  13335. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  13336. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  13337. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  13338. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  13339. 0xa6, 0x37, 0xb3, 0x9b
  13340. };
  13341. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  13342. {
  13343. 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
  13344. 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
  13345. 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
  13346. 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
  13347. 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
  13348. 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
  13349. 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
  13350. 0xe9, 0xb7, 0x37, 0x3b
  13351. };
  13352. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13353. {
  13354. 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
  13355. 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9
  13356. };
  13357. #endif /* WOLFSSL_AES_192 */
  13358. #ifdef WOLFSSL_AES_128
  13359. /* The following is an interesting test case from the example
  13360. * FIPS test vectors for AES-GCM. IVlen = 1 byte */
  13361. WOLFSSL_SMALL_STACK_STATIC const byte p3[] =
  13362. {
  13363. 0x57, 0xce, 0x45, 0x1f, 0xa5, 0xe2, 0x35, 0xa5,
  13364. 0x8e, 0x1a, 0xa2, 0x3b, 0x77, 0xcb, 0xaf, 0xe2
  13365. };
  13366. #ifdef HAVE_RENESAS_SYNC
  13367. const byte *k3 =
  13368. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  13369. int k3Sz = (int)(128/8);
  13370. #else
  13371. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  13372. {
  13373. 0xbb, 0x01, 0xd7, 0x03, 0x81, 0x1c, 0x10, 0x1a,
  13374. 0x35, 0xe0, 0xff, 0xd2, 0x91, 0xba, 0xf2, 0x4b
  13375. };
  13376. int k3Sz = (int)sizeof(k3);
  13377. #endif
  13378. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  13379. {
  13380. 0xca
  13381. };
  13382. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  13383. {
  13384. 0x6b, 0x5f, 0xb3, 0x9d, 0xc1, 0xc5, 0x7a, 0x4f,
  13385. 0xf3, 0x51, 0x4d, 0xc2, 0xd5, 0xf0, 0xd0, 0x07
  13386. };
  13387. WOLFSSL_SMALL_STACK_STATIC const byte a3[] =
  13388. {
  13389. 0x40, 0xfc, 0xdc, 0xd7, 0x4a, 0xd7, 0x8b, 0xf1,
  13390. 0x3e, 0x7c, 0x60, 0x55, 0x50, 0x51, 0xdd, 0x54
  13391. };
  13392. WOLFSSL_SMALL_STACK_STATIC const byte t3[] =
  13393. {
  13394. 0x06, 0x90, 0xed, 0x01, 0x34, 0xdd, 0xc6, 0x95,
  13395. 0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
  13396. };
  13397. #endif /* WOLFSSL_AES_128 */
  13398. #ifdef WOLFSSL_AES_256
  13399. int ivlen;
  13400. #endif
  13401. #endif
  13402. byte resultT[sizeof(t1) + WC_AES_BLOCK_SIZE];
  13403. byte resultP[sizeof(p) + WC_AES_BLOCK_SIZE];
  13404. byte resultC[sizeof(p) + WC_AES_BLOCK_SIZE];
  13405. wc_test_ret_t ret = 0;
  13406. int alen = 0;
  13407. int plen = 0;
  13408. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13409. byte buf[sizeof(p) + WC_AES_BLOCK_SIZE];
  13410. byte bufA[sizeof(a) + 1];
  13411. byte *large_aad = (byte*)XMALLOC((size_t)1024 + 16, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13412. #endif
  13413. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM)
  13414. #if !defined(BENCH_AESGCM_LARGE)
  13415. #define BENCH_AESGCM_LARGE 1024
  13416. #endif
  13417. #ifndef WOLFSSL_NO_MALLOC
  13418. byte *large_input = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13419. byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13420. byte *large_outdec = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13421. (void)alen;
  13422. (void)plen;
  13423. if ((! large_input) || (! large_output) || (! large_outdec))
  13424. ERROR_OUT(MEMORY_E, out);
  13425. #else
  13426. byte large_input[BENCH_AESGCM_LARGE];
  13427. byte large_output[BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE];
  13428. byte large_outdec[BENCH_AESGCM_LARGE];
  13429. #endif
  13430. XMEMSET(large_input, 0, BENCH_AESGCM_LARGE);
  13431. XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE);
  13432. XMEMSET(large_outdec, 0, BENCH_AESGCM_LARGE);
  13433. #endif
  13434. WOLFSSL_ENTER("aesgcm_test");
  13435. XMEMSET(resultT, 0, sizeof(resultT));
  13436. XMEMSET(resultC, 0, sizeof(resultC));
  13437. XMEMSET(resultP, 0, sizeof(resultP));
  13438. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13439. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13440. if (enc == NULL)
  13441. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13442. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13443. if (dec == NULL)
  13444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13445. #else
  13446. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13447. if (ret != 0)
  13448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13449. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13450. if (ret != 0)
  13451. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13452. #endif
  13453. #ifdef WOLFSSL_AES_256
  13454. ret = wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13455. if (ret != 0)
  13456. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13457. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13458. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13459. resultT, sizeof(t1), a, sizeof(a));
  13460. #if defined(WOLFSSL_ASYNC_CRYPT)
  13461. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13462. #endif
  13463. if (ret != 0)
  13464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13465. #ifndef HAVE_RENESAS_SYNC
  13466. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13467. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13468. if (XMEMCMP(t1, resultT, sizeof(t1)))
  13469. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13470. #endif
  13471. #ifdef HAVE_AES_DECRYPT
  13472. ret = wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13473. if (ret != 0)
  13474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13475. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1),
  13476. iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13477. #if defined(WOLFSSL_ASYNC_CRYPT)
  13478. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13479. #endif
  13480. if (ret != 0)
  13481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13482. if (XMEMCMP(p, resultP, sizeof(p)))
  13483. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13484. #endif /* HAVE_AES_DECRYPT */
  13485. /* Large buffer test */
  13486. #ifdef BENCH_AESGCM_LARGE
  13487. /* setup test buffer */
  13488. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13489. large_input[alen] = (byte)alen;
  13490. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13491. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13492. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13493. resultT, sizeof(t1), a, sizeof(a));
  13494. #if defined(WOLFSSL_ASYNC_CRYPT)
  13495. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13496. #endif
  13497. if (ret != 0)
  13498. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13499. #ifdef HAVE_AES_DECRYPT
  13500. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13501. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13502. sizeof(t1), a, sizeof(a));
  13503. #if defined(WOLFSSL_ASYNC_CRYPT)
  13504. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13505. #endif
  13506. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13507. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13508. if (ret != 0)
  13509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13510. #endif /* HAVE_AES_DECRYPT */
  13511. #endif /* BENCH_AESGCM_LARGE */
  13512. #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256)
  13513. /* Variable IV length test */
  13514. for (ivlen=1; ivlen<k1Sz; ivlen++) {
  13515. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13516. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1,
  13517. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13518. #if defined(WOLFSSL_ASYNC_CRYPT)
  13519. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13520. #endif
  13521. if (ret != 0)
  13522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13523. #ifdef HAVE_AES_DECRYPT
  13524. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1,
  13525. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13526. #if defined(WOLFSSL_ASYNC_CRYPT)
  13527. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13528. #endif
  13529. if (ret != 0)
  13530. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13531. #endif /* HAVE_AES_DECRYPT */
  13532. }
  13533. #endif
  13534. #if !(defined(WOLF_CRYPTO_CB) && defined(HAVE_INTEL_QA_SYNC))
  13535. /* Variable authenticated data length test */
  13536. for (alen=0; alen<(int)sizeof(p); alen++) {
  13537. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13538. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13539. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13540. #if defined(WOLFSSL_ASYNC_CRYPT)
  13541. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13542. #endif
  13543. if (ret != 0)
  13544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13545. #ifdef HAVE_AES_DECRYPT
  13546. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13547. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13548. #if defined(WOLFSSL_ASYNC_CRYPT)
  13549. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13550. #endif
  13551. if (ret != 0)
  13552. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13553. #endif /* HAVE_AES_DECRYPT */
  13554. }
  13555. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13556. if (! large_aad)
  13557. ERROR_OUT(MEMORY_E, out);
  13558. XMEMSET(large_aad, 0, 1024+16);
  13559. /* Variable authenticated data length test */
  13560. for (alen=0; alen<=1024; alen+=16) {
  13561. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13562. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), 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. #ifdef HAVE_AES_DECRYPT
  13567. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13568. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13569. if (ret != 0)
  13570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13571. #endif /* HAVE_AES_DECRYPT */
  13572. }
  13573. /* Test unaligned memory of all potential arguments */
  13574. ret = wc_AesGcmSetKey(enc, k1, k1Sz);
  13575. if (ret != 0)
  13576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13577. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13578. XMEMCPY(&buf[1], p, sizeof(p));
  13579. XMEMCPY(&bufA[1], a, sizeof(a));
  13580. ret = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1),
  13581. &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13582. if (ret != 0)
  13583. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13584. if (XMEMCMP(c1, &resultC[1], sizeof(c1)))
  13585. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13586. if (XMEMCMP(t1, &resultT[1], sizeof(t1)))
  13587. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13588. #ifdef HAVE_AES_DECRYPT
  13589. ret = wc_AesGcmSetKey(dec, k1, k1Sz);
  13590. if (ret != 0)
  13591. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13592. ret = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1),
  13593. iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13594. if (ret != 0)
  13595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13596. if (XMEMCMP(p, &resultP[1], sizeof(p)))
  13597. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13598. #endif /* HAVE_AES_DECRYPT */
  13599. #endif /* Xilinx Versal */
  13600. #endif
  13601. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13602. #ifdef BENCH_AESGCM_LARGE
  13603. /* Variable plain text length test */
  13604. for (plen=1; plen<BENCH_AESGCM_LARGE; plen++) {
  13605. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13606. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13607. (word32)plen, iv1, sizeof(iv1), resultT,
  13608. sizeof(t1), a, sizeof(a));
  13609. #if defined(WOLFSSL_ASYNC_CRYPT)
  13610. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13611. #endif
  13612. if (ret != 0)
  13613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13614. #ifdef HAVE_AES_DECRYPT
  13615. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13616. (word32)plen, iv1, sizeof(iv1), resultT,
  13617. sizeof(t1), a, sizeof(a));
  13618. #if defined(WOLFSSL_ASYNC_CRYPT)
  13619. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13620. #endif
  13621. if (ret != 0)
  13622. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13623. #endif /* HAVE_AES_DECRYPT */
  13624. }
  13625. #else /* BENCH_AESGCM_LARGE */
  13626. /* Variable plain text length test */
  13627. for (plen=1; plen<(int)sizeof(p); plen++) {
  13628. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13629. ret = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1,
  13630. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13631. #if defined(WOLFSSL_ASYNC_CRYPT)
  13632. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13633. #endif
  13634. if (ret != 0)
  13635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13636. #ifdef HAVE_AES_DECRYPT
  13637. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1,
  13638. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13639. #if defined(WOLFSSL_ASYNC_CRYPT)
  13640. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13641. #endif
  13642. if (ret != 0)
  13643. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13644. #endif /* HAVE_AES_DECRYPT */
  13645. }
  13646. #endif /* BENCH_AESGCM_LARGE */
  13647. #endif
  13648. #endif /* WOLFSSL_AES_256 */
  13649. /* test with IV != 12 bytes */
  13650. #ifdef ENABLE_NON_12BYTE_IV_TEST
  13651. XMEMSET(resultT, 0, sizeof(resultT));
  13652. XMEMSET(resultC, 0, sizeof(resultC));
  13653. XMEMSET(resultP, 0, sizeof(resultP));
  13654. #ifdef WOLFSSL_AES_192
  13655. wc_AesGcmSetKey(enc, k2, sizeof(k2));
  13656. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13657. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2),
  13658. resultT, sizeof(t1), a, sizeof(a));
  13659. #if defined(WOLFSSL_ASYNC_CRYPT)
  13660. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13661. #endif
  13662. if (ret != 0)
  13663. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13664. if (XMEMCMP(c2, resultC, sizeof(c2)))
  13665. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13666. if (XMEMCMP(t2, resultT, sizeof(t1)))
  13667. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13668. #ifdef HAVE_AES_DECRYPT
  13669. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1),
  13670. iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a));
  13671. #if defined(WOLFSSL_ASYNC_CRYPT)
  13672. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13673. #endif
  13674. if (ret != 0)
  13675. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13676. if (XMEMCMP(p, resultP, sizeof(p)))
  13677. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13678. #endif /* HAVE_AES_DECRYPT */
  13679. /* Large buffer test */
  13680. #ifdef BENCH_AESGCM_LARGE
  13681. wc_AesGcmSetKey(enc, k2, (word32)sizeof(k2));
  13682. wc_AesGcmSetKey(dec, k2, (word32)sizeof(k2));
  13683. /* setup test buffer */
  13684. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13685. large_input[alen] = (byte)alen;
  13686. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13687. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13688. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13689. resultT, sizeof(t1), a, sizeof(a));
  13690. #if defined(WOLFSSL_ASYNC_CRYPT)
  13691. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13692. #endif
  13693. if (ret != 0)
  13694. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13695. #ifdef HAVE_AES_DECRYPT
  13696. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13697. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13698. sizeof(t1), a, sizeof(a));
  13699. #if defined(WOLFSSL_ASYNC_CRYPT)
  13700. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13701. #endif
  13702. if (ret != 0)
  13703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13704. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13705. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13706. #endif /* HAVE_AES_DECRYPT */
  13707. #endif /* BENCH_AESGCM_LARGE */
  13708. XMEMSET(resultT, 0, sizeof(resultT));
  13709. XMEMSET(resultC, 0, sizeof(resultC));
  13710. XMEMSET(resultP, 0, sizeof(resultP));
  13711. #endif /* WOLFSSL_AES_192 */
  13712. #ifdef WOLFSSL_AES_128
  13713. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13714. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13715. ret = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3),
  13716. resultT, sizeof(t3), a3, sizeof(a3));
  13717. #if defined(WOLFSSL_ASYNC_CRYPT)
  13718. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13719. #endif
  13720. if (ret != 0)
  13721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13722. #ifndef HAVE_RENESAS_SYNC
  13723. if (XMEMCMP(c3, resultC, sizeof(c3)))
  13724. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13725. if (XMEMCMP(t3, resultT, sizeof(t3)))
  13726. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13727. #endif
  13728. #ifdef HAVE_AES_DECRYPT
  13729. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
  13730. iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3));
  13731. #if defined(WOLFSSL_ASYNC_CRYPT)
  13732. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13733. #endif
  13734. if (ret != 0)
  13735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13736. if (XMEMCMP(p3, resultP, sizeof(p3)))
  13737. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13738. #endif /* HAVE_AES_DECRYPT */
  13739. /* Large buffer test */
  13740. #ifdef BENCH_AESGCM_LARGE
  13741. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13742. wc_AesGcmSetKey(dec, k3, (word32)k3Sz);
  13743. /* setup test buffer */
  13744. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13745. large_input[alen] = (byte)alen;
  13746. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13747. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13748. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13749. resultT, sizeof(t1), a, sizeof(a));
  13750. #if defined(WOLFSSL_ASYNC_CRYPT)
  13751. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13752. #endif
  13753. if (ret != 0)
  13754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13755. #ifdef HAVE_AES_DECRYPT
  13756. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13757. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13758. sizeof(t1), a, sizeof(a));
  13759. #if defined(WOLFSSL_ASYNC_CRYPT)
  13760. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13761. #endif
  13762. if (ret != 0)
  13763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13764. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13765. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13766. #endif /* HAVE_AES_DECRYPT */
  13767. #endif /* BENCH_AESGCM_LARGE */
  13768. #endif /* WOLFSSL_AES_128 */
  13769. #endif /* ENABLE_NON_12BYTE_IV_TEST */
  13770. #if defined(WOLFSSL_AES_256) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13771. !defined(WOLFSSL_XILINX_CRYPT) && \
  13772. !(defined(WOLF_CRYPTO_CB) && \
  13773. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC))
  13774. XMEMSET(resultT, 0, sizeof(resultT));
  13775. XMEMSET(resultC, 0, sizeof(resultC));
  13776. XMEMSET(resultP, 0, sizeof(resultP));
  13777. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13778. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13779. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13780. resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13781. #if defined(WOLFSSL_ASYNC_CRYPT)
  13782. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13783. #endif
  13784. if (ret != 0)
  13785. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13786. #ifndef HAVE_RENESAS_SYNC
  13787. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13788. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13789. if (XMEMCMP(t1, resultT + 1, sizeof(t1) - 1))
  13790. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13791. #endif
  13792. #ifdef HAVE_AES_DECRYPT
  13793. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p),
  13794. iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13795. #if defined(WOLFSSL_ASYNC_CRYPT)
  13796. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13797. #endif
  13798. if (ret != 0)
  13799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13800. if (XMEMCMP(p, resultP, sizeof(p)))
  13801. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13802. #endif /* HAVE_AES_DECRYPT */
  13803. #endif /* WOLFSSL_AES_256 */
  13804. #if !defined(HAVE_FIPS) || \
  13805. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  13806. /* Test encrypt with internally generated IV */
  13807. #if defined(WOLFSSL_AES_256) && !(defined(WC_NO_RNG) || defined(HAVE_SELFTEST)) \
  13808. && !(defined(WOLF_CRYPTO_CB) && defined(HAVE_CAVIUM_OCTEON_SYNC))
  13809. {
  13810. WC_RNG rng;
  13811. byte randIV[12];
  13812. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  13813. if (ret != 0)
  13814. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13815. XMEMSET(randIV, 0, sizeof(randIV));
  13816. XMEMSET(resultT, 0, sizeof(resultT));
  13817. XMEMSET(resultC, 0, sizeof(resultC));
  13818. XMEMSET(resultP, 0, sizeof(resultP));
  13819. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13820. ret = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng);
  13821. if (ret != 0)
  13822. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13823. ret = wc_AesGcmEncrypt_ex(enc,
  13824. resultC, p, sizeof(p),
  13825. randIV, sizeof(randIV),
  13826. resultT, sizeof(t1),
  13827. a, sizeof(a));
  13828. #if defined(WOLFSSL_ASYNC_CRYPT)
  13829. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13830. #endif
  13831. if (ret != 0)
  13832. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13833. /* Check the IV has been set. */
  13834. {
  13835. word32 i, ivSum = 0;
  13836. for (i = 0; i < sizeof(randIV); i++)
  13837. ivSum += randIV[i];
  13838. if (ivSum == 0)
  13839. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13840. }
  13841. #ifdef HAVE_AES_DECRYPT
  13842. wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13843. ret = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng);
  13844. if (ret != 0)
  13845. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13846. ret = wc_AesGcmDecrypt(dec,
  13847. resultP, resultC, sizeof(c1),
  13848. randIV, sizeof(randIV),
  13849. resultT, sizeof(t1),
  13850. a, sizeof(a));
  13851. #if defined(WOLFSSL_ASYNC_CRYPT)
  13852. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13853. #endif
  13854. if (ret != 0)
  13855. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13856. if (XMEMCMP(p, resultP, sizeof(p)))
  13857. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13858. #endif /* HAVE_AES_DECRYPT */
  13859. wc_FreeRng(&rng);
  13860. }
  13861. #endif /* WOLFSSL_AES_256 && !(WC_NO_RNG || HAVE_SELFTEST) */
  13862. #endif /* HAVE_FIPS_VERSION >= 2 */
  13863. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13864. #ifdef WOLFSSL_AES_256
  13865. #ifdef WOLFSSL_AESGCM_STREAM
  13866. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13867. if (ret != 0)
  13868. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13869. ret = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a));
  13870. if (ret != 0)
  13871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13872. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13873. if (ret != 0)
  13874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13875. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13876. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13877. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13878. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13879. #ifdef HAVE_AES_DECRYPT
  13880. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13881. if (ret != 0)
  13882. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13883. ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a));
  13884. if (ret != 0)
  13885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13886. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13887. if (ret != 0)
  13888. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13889. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13890. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13891. #endif
  13892. /* alen is the size to pass in with each update. */
  13893. for (alen = 1; alen < WC_AES_BLOCK_SIZE + 1; alen++) {
  13894. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13895. if (ret != 0)
  13896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13897. /* plen is the offset into AAD to update with. */
  13898. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13899. int len = sizeof(a) - plen;
  13900. if (len > alen) len = alen;
  13901. ret = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13902. if (ret != 0)
  13903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13904. }
  13905. /* plen is the offset into plaintext to update with. */
  13906. for (plen = 0; plen < (int)sizeof(p); plen += alen) {
  13907. int len = sizeof(p) - plen;
  13908. if (len > alen) len = alen;
  13909. ret = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, (word32)len,
  13910. NULL, 0);
  13911. if (ret != 0)
  13912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13913. }
  13914. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13915. if (ret != 0)
  13916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13917. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13918. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13919. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13920. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13921. }
  13922. #ifdef HAVE_AES_DECRYPT
  13923. for (alen = 1; alen < WC_AES_BLOCK_SIZE + 1; alen++) {
  13924. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13925. if (ret != 0)
  13926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13927. /* plen is the offset into AAD to update with. */
  13928. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13929. int len = sizeof(a) - plen;
  13930. if (len > alen) len = alen;
  13931. ret = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13932. if (ret != 0)
  13933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13934. }
  13935. /* plen is the offset into cipher text to update with. */
  13936. for (plen = 0; plen < (int)sizeof(c1); plen += alen) {
  13937. int len = sizeof(c1) - plen;
  13938. if (len > alen) len = alen;
  13939. ret = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, (word32)len,
  13940. NULL, 0);
  13941. if (ret != 0)
  13942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13943. }
  13944. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13945. if (ret != 0)
  13946. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13947. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13948. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13949. }
  13950. #endif /* HAVE_AES_DECRYPT */
  13951. #ifdef BENCH_AESGCM_LARGE
  13952. /* setup test buffer */
  13953. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13954. if (ret != 0)
  13955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13956. ret = wc_AesGcmEncryptUpdate(enc, large_output, large_input,
  13957. BENCH_AESGCM_LARGE, a, sizeof(a));
  13958. if (ret != 0)
  13959. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13960. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13961. if (ret != 0)
  13962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13963. #ifdef HAVE_AES_DECRYPT
  13964. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13965. if (ret != 0)
  13966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13967. ret = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output,
  13968. BENCH_AESGCM_LARGE, a, sizeof(a));
  13969. if (ret != 0)
  13970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13971. ret = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1));
  13972. if (ret != 0)
  13973. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13974. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13975. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13976. #endif /* HAVE_AES_DECRYPT */
  13977. #endif /* BENCH_AESGCM_LARGE */
  13978. #endif /* WOLFSSL_AESGCM_STREAM */
  13979. #endif /* WOLFSSL_AES_256 */
  13980. #endif /* !WOLFSSL_AFALG_XILINX_AES && !WOLFSSL_XILINX_CRYPT */
  13981. ret = 0;
  13982. out:
  13983. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  13984. !defined(WOLFSSL_NO_MALLOC)
  13985. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13986. XFREE(large_output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13987. XFREE(large_outdec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13988. #endif
  13989. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13990. wc_AesDelete(enc, &enc);
  13991. wc_AesDelete(dec, &dec);
  13992. #else
  13993. wc_AesFree(enc);
  13994. wc_AesFree(dec);
  13995. #endif
  13996. return ret;
  13997. }
  13998. #ifdef WOLFSSL_AES_128
  13999. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void)
  14000. {
  14001. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14002. Gmac *gmac;
  14003. #else
  14004. Gmac gmac[1];
  14005. #endif
  14006. wc_test_ret_t ret;
  14007. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14008. {
  14009. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  14010. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  14011. };
  14012. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  14013. {
  14014. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  14015. 0xe2, 0x8c, 0x8f, 0x16
  14016. };
  14017. WOLFSSL_SMALL_STACK_STATIC const byte a1[] =
  14018. {
  14019. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  14020. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  14021. };
  14022. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  14023. {
  14024. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  14025. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14026. };
  14027. #if (!defined(HAVE_FIPS) || \
  14028. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
  14029. /* FIPS builds only allow 16-byte auth tags. */
  14030. /* This sample uses a 15-byte auth tag. */
  14031. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14032. {
  14033. 0x40, 0xf7, 0xec, 0xb2, 0x52, 0x6d, 0xaa, 0xd4,
  14034. 0x74, 0x25, 0x1d, 0xf4, 0x88, 0x9e, 0xf6, 0x5b
  14035. };
  14036. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  14037. {
  14038. 0xee, 0x9c, 0x6e, 0x06, 0x15, 0x45, 0x45, 0x03,
  14039. 0x1a, 0x60, 0x24, 0xa7
  14040. };
  14041. WOLFSSL_SMALL_STACK_STATIC const byte a2[] =
  14042. {
  14043. 0x94, 0x81, 0x2c, 0x87, 0x07, 0x4e, 0x15, 0x18,
  14044. 0x34, 0xb8, 0x35, 0xaf, 0x1c, 0xa5, 0x7e, 0x56
  14045. };
  14046. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  14047. {
  14048. 0xc6, 0x81, 0x79, 0x8e, 0x3d, 0xda, 0xb0, 0x9f,
  14049. 0x8d, 0x83, 0xb0, 0xbb, 0x14, 0xb6, 0x91
  14050. };
  14051. #endif
  14052. byte tag[16];
  14053. WOLFSSL_ENTER("gmac_test");
  14054. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14055. if ((gmac = (Gmac *)XMALLOC(sizeof *gmac, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  14056. return WC_TEST_RET_ENC_ERRNO;
  14057. #endif
  14058. XMEMSET(gmac, 0, sizeof *gmac); /* clear context */
  14059. (void)wc_AesInit(&gmac->aes, HEAP_HINT, INVALID_DEVID); /* Make sure devId updated */
  14060. XMEMSET(tag, 0, sizeof(tag));
  14061. wc_GmacSetKey(gmac, k1, sizeof(k1));
  14062. wc_GmacUpdate(gmac, iv1, sizeof(iv1), a1, sizeof(a1), tag, sizeof(t1));
  14063. if (XMEMCMP(t1, tag, sizeof(t1)) != 0)
  14064. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14065. #if (!defined(HAVE_FIPS) || \
  14066. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) )
  14067. XMEMSET(tag, 0, sizeof(tag));
  14068. wc_GmacSetKey(gmac, k2, sizeof(k2));
  14069. wc_GmacUpdate(gmac, iv2, sizeof(iv2), a2, sizeof(a2), tag, sizeof(t2));
  14070. if (XMEMCMP(t2, tag, sizeof(t2)) != 0)
  14071. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14072. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT)
  14073. {
  14074. WOLFSSL_SMALL_STACK_STATIC const byte badT[] =
  14075. {
  14076. 0xde, 0xad, 0xbe, 0xef, 0x17, 0x2e, 0xd0, 0x43,
  14077. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14078. };
  14079. WC_RNG rng;
  14080. byte iv[12];
  14081. #ifndef HAVE_FIPS
  14082. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14083. if (ret != 0)
  14084. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14085. #else
  14086. ret = wc_InitRng(&rng);
  14087. if (ret != 0)
  14088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14089. #endif
  14090. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14091. t1, sizeof(t1));
  14092. if (ret != 0)
  14093. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14094. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14095. badT, sizeof(badT));
  14096. if (ret != WC_NO_ERR_TRACE(AES_GCM_AUTH_E))
  14097. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14098. ret = wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2),
  14099. t2, sizeof(t2));
  14100. if (ret != 0)
  14101. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14102. XMEMSET(tag, 0, sizeof(tag));
  14103. XMEMSET(iv, 0, sizeof(iv));
  14104. ret = wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14105. tag, sizeof(tag), &rng);
  14106. if (ret != 0)
  14107. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14108. ret = wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14109. tag, sizeof(tag));
  14110. if (ret != 0)
  14111. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14112. wc_FreeRng(&rng);
  14113. }
  14114. #endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */
  14115. #endif /* HAVE_FIPS */
  14116. ret = 0;
  14117. out:
  14118. wc_AesFree(&gmac->aes);
  14119. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14120. XFREE(gmac, HEAP_HINT, DYNAMIC_TYPE_AES);
  14121. #endif
  14122. return ret;
  14123. }
  14124. #endif /* WOLFSSL_AES_128 */
  14125. #endif /* HAVE_AESGCM */
  14126. #if defined(HAVE_AESCCM)
  14127. #if defined(WOLFSSL_AES_256)
  14128. static wc_test_ret_t aesccm_256_test(void)
  14129. {
  14130. wc_test_ret_t ret = 0;
  14131. /* Test vectors from NIST AES CCM 256-bit CAST Example #1 */
  14132. WOLFSSL_SMALL_STACK_STATIC const byte in_key[32] = {
  14133. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14134. 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
  14135. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14136. 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
  14137. };
  14138. WOLFSSL_SMALL_STACK_STATIC const byte in_nonce[7] = {
  14139. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
  14140. WOLFSSL_SMALL_STACK_STATIC const byte in_auth[8] = {
  14141. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  14142. WOLFSSL_SMALL_STACK_STATIC const byte in_plaintext[4] = {
  14143. 0x20, 0x21, 0x22, 0x23};
  14144. WOLFSSL_SMALL_STACK_STATIC const byte exp_ciphertext[4] = {
  14145. 0x8A, 0xB1, 0xA8, 0x74};
  14146. WOLFSSL_SMALL_STACK_STATIC const byte exp_tag[4] = {
  14147. 0x95, 0xFC, 0x08, 0x20};
  14148. byte output[sizeof(in_plaintext)];
  14149. byte atag[sizeof(exp_tag)];
  14150. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14151. Aes* aes = wc_AesNew(HEAP_HINT, devId, &ret);
  14152. if (aes == NULL) {
  14153. ret = WC_TEST_RET_ENC_EC(ret);
  14154. }
  14155. #else
  14156. Aes aes[1];
  14157. ret = wc_AesInit(aes, HEAP_HINT, devId);
  14158. #endif
  14159. if (ret == 0) {
  14160. ret = wc_AesCcmSetKey(aes, in_key, sizeof(in_key));
  14161. }
  14162. if (ret == 0) {
  14163. ret = wc_AesCcmEncrypt(aes, output, in_plaintext, sizeof(in_plaintext),
  14164. in_nonce, sizeof(in_nonce),
  14165. atag, sizeof(atag),
  14166. in_auth, sizeof(in_auth));
  14167. }
  14168. /* Verify we produce the proper ciphertext and tag */
  14169. if (ret == 0 &&
  14170. (XMEMCMP(output, exp_ciphertext, sizeof(output)) ||
  14171. XMEMCMP(atag, exp_tag, sizeof(atag)))) {
  14172. ret = WC_TEST_RET_ENC_NC;
  14173. }
  14174. #ifdef HAVE_AES_DECRYPT
  14175. if (ret == 0) {
  14176. /* decrypt inline */
  14177. ret = wc_AesCcmDecrypt(aes, output, output, sizeof(output),
  14178. in_nonce, sizeof(in_nonce),
  14179. atag, sizeof(atag),
  14180. in_auth, sizeof(in_auth));
  14181. }
  14182. /* Verify decryption was successful */
  14183. if (ret == 0 &&
  14184. XMEMCMP(output, in_plaintext, sizeof(output))) {
  14185. ret = WC_TEST_RET_ENC_NC;
  14186. }
  14187. #endif
  14188. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14189. wc_AesDelete(aes, &aes);
  14190. #else
  14191. wc_AesFree(aes);
  14192. #endif
  14193. return ret;
  14194. }
  14195. #endif /* WOLFSSL_AES_256 */
  14196. #if defined(WOLFSSL_AES_128)
  14197. static wc_test_ret_t aesccm_128_test(void)
  14198. {
  14199. wc_test_ret_t ret;
  14200. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14201. Aes *enc = NULL;
  14202. #else
  14203. Aes enc[1];
  14204. #endif
  14205. /* key */
  14206. WOLFSSL_SMALL_STACK_STATIC const byte k[] =
  14207. {
  14208. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  14209. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  14210. };
  14211. /* nonce */
  14212. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  14213. {
  14214. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  14215. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  14216. };
  14217. /* plaintext */
  14218. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  14219. {
  14220. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14221. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14222. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  14223. };
  14224. /* plaintext - long */
  14225. WOLFSSL_SMALL_STACK_STATIC const byte pl[] =
  14226. {
  14227. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14228. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14229. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  14230. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14231. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  14232. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  14233. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  14234. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14235. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  14236. 0x50
  14237. };
  14238. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  14239. {
  14240. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14241. };
  14242. /* ciphertext */
  14243. WOLFSSL_SMALL_STACK_STATIC const byte c[] =
  14244. {
  14245. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14246. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14247. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  14248. };
  14249. /* tag - authentication */
  14250. WOLFSSL_SMALL_STACK_STATIC const byte t[] =
  14251. {
  14252. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  14253. };
  14254. /* ciphertext - long */
  14255. WOLFSSL_SMALL_STACK_STATIC const byte cl[] =
  14256. {
  14257. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14258. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14259. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0xe0,
  14260. 0x44, 0x2d, 0xbe, 0x25, 0xfa, 0x48, 0x2b, 0xa8,
  14261. 0x36, 0x0b, 0xbf, 0x01, 0xc0, 0x12, 0x45, 0xa4,
  14262. 0x82, 0x9f, 0x20, 0x6c, 0xc3, 0xd6, 0xae, 0x5b,
  14263. 0x54, 0x8d, 0xd0, 0xb1, 0x69, 0x2c, 0xec, 0x5e,
  14264. 0x95, 0xa5, 0x6b, 0x48, 0xc3, 0xc6, 0xc8, 0x9e,
  14265. 0xc7, 0x92, 0x98, 0x9d, 0x26, 0x7d, 0x2a, 0x10,
  14266. 0x0b
  14267. };
  14268. /* tag - authentication - long */
  14269. WOLFSSL_SMALL_STACK_STATIC const byte tl[] =
  14270. {
  14271. 0x89, 0xd8, 0xd2, 0x02, 0xc5, 0xcf, 0xae, 0xf4
  14272. };
  14273. /* tag - authentication - empty plaintext */
  14274. WOLFSSL_SMALL_STACK_STATIC const byte t_empty[] =
  14275. {
  14276. 0xe4, 0x28, 0x8a, 0xc3, 0x78, 0x00, 0x0f, 0xf5
  14277. };
  14278. byte t2[sizeof(t)];
  14279. byte p2[sizeof(p)];
  14280. byte c2[sizeof(c)];
  14281. byte iv2[sizeof(iv)];
  14282. byte pl2[sizeof(pl)];
  14283. byte cl2[sizeof(cl)];
  14284. byte tl2[sizeof(tl)];
  14285. byte t_empty2[sizeof(t_empty)];
  14286. XMEMSET(t2, 0, sizeof(t2));
  14287. XMEMSET(c2, 0, sizeof(c2));
  14288. XMEMSET(p2, 0, sizeof(p2));
  14289. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14290. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  14291. if (enc == NULL)
  14292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14293. #else
  14294. XMEMSET(enc, 0, sizeof(Aes));
  14295. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14296. if (ret != 0)
  14297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14298. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  14299. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14300. if (ret != 0)
  14301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14302. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14303. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14304. t2, sizeof(t2), a, sizeof(a));
  14305. if (ret != 0)
  14306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14307. if (XMEMCMP(c, c2, sizeof(c2)))
  14308. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14309. if (XMEMCMP(t, t2, sizeof(t2)))
  14310. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14311. #ifdef HAVE_AES_DECRYPT
  14312. ret = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv),
  14313. t2, sizeof(t2), a, sizeof(a));
  14314. if (ret != 0)
  14315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14316. if (XMEMCMP(p, p2, sizeof(p2)))
  14317. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14318. /* Test the authentication failure */
  14319. t2[0]++; /* Corrupt the authentication tag. */
  14320. ret = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv),
  14321. t2, sizeof(t2), a, sizeof(a));
  14322. if (ret == 0)
  14323. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14324. /* Clear c2 to compare against p2. p2 should be set to zero in case of
  14325. * authentication fail. */
  14326. XMEMSET(c2, 0, sizeof(c2));
  14327. if (XMEMCMP(p2, c2, sizeof(p2)))
  14328. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14329. #endif
  14330. XMEMSET(t2, 0, sizeof(t2));
  14331. XMEMSET(c2, 0, sizeof(c2));
  14332. XMEMSET(p2, 0, sizeof(p2));
  14333. XMEMSET(iv2, 0, sizeof(iv2));
  14334. wc_AesFree(enc);
  14335. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14336. if (ret != 0)
  14337. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14338. #ifndef HAVE_SELFTEST
  14339. /* selftest build does not have wc_AesCcmSetNonce() or
  14340. * wc_AesCcmEncrypt_ex() */
  14341. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14342. if (ret != 0)
  14343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14344. ret = wc_AesCcmSetNonce(enc, iv, sizeof(iv));
  14345. if (ret != 0)
  14346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14347. ret = wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2),
  14348. t2, sizeof(t2), a, sizeof(a));
  14349. if (ret != 0)
  14350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14351. if (XMEMCMP(iv, iv2, sizeof(iv2)))
  14352. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14353. if (XMEMCMP(c, c2, sizeof(c2)))
  14354. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14355. if (XMEMCMP(t, t2, sizeof(t2)))
  14356. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14357. #endif
  14358. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  14359. /* test fail on invalid IV sizes */
  14360. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14361. if (ret != 0)
  14362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14363. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14364. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14365. t2, 1, a, sizeof(a));
  14366. if (ret == 0) {
  14367. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14368. }
  14369. #endif
  14370. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14371. ret = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv),
  14372. tl2, sizeof(tl2), a, sizeof(a));
  14373. if (ret != 0)
  14374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14375. if (XMEMCMP(cl, cl2, sizeof(cl2)))
  14376. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14377. if (XMEMCMP(tl, tl2, sizeof(tl2)))
  14378. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14379. #ifdef HAVE_AES_DECRYPT
  14380. ret = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv),
  14381. tl2, sizeof(tl2), a, sizeof(a));
  14382. if (ret != 0)
  14383. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14384. if (XMEMCMP(pl, pl2, sizeof(pl2)))
  14385. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14386. #endif
  14387. /* test empty message as null input or output with nonzero inSz. */
  14388. ret = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* 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. ret = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14394. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14395. a, sizeof(a));
  14396. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14397. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14398. #ifdef HAVE_AES_DECRYPT
  14399. ret = wc_AesCcmDecrypt(enc, pl2, NULL /* 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. ret = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14405. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14406. sizeof(a));
  14407. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14408. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14409. #endif
  14410. /* test empty message as null input and output with zero inSz --
  14411. * must either succeed, or fail early with BAD_FUNC_ARG.
  14412. */
  14413. ret = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */,
  14414. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14415. a, sizeof(a));
  14416. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  14417. if (ret != 0)
  14418. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14419. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14420. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14421. #ifdef HAVE_AES_DECRYPT
  14422. ret = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */,
  14423. 0 /* inSz */, iv, sizeof(iv), t_empty2,
  14424. sizeof(t_empty2), a, sizeof(a));
  14425. if (ret != 0)
  14426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14427. #endif
  14428. }
  14429. /* test empty message as zero-length string -- must work. */
  14430. ret = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv,
  14431. sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14432. sizeof(a));
  14433. if (ret != 0)
  14434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14435. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14436. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14437. #ifdef HAVE_AES_DECRYPT
  14438. ret = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */,
  14439. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14440. sizeof(a));
  14441. if (ret != 0)
  14442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14443. #endif
  14444. ret = 0;
  14445. out:
  14446. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14447. wc_AesDelete(enc, &enc);
  14448. #else
  14449. wc_AesFree(enc);
  14450. #endif
  14451. return ret;
  14452. }
  14453. #endif /* WOLFSSL_AES_128 */
  14454. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void)
  14455. {
  14456. wc_test_ret_t ret = 0;
  14457. WOLFSSL_ENTER("aesccm_test");
  14458. #ifdef WOLFSSL_AES_128
  14459. if (ret == 0)
  14460. ret = aesccm_128_test();
  14461. #endif
  14462. #ifdef WOLFSSL_AES_256
  14463. if (ret == 0)
  14464. ret = aesccm_256_test();
  14465. #endif
  14466. return ret;
  14467. }
  14468. #endif /* HAVE_AESCCM */
  14469. #if defined(WOLFSSL_AES_EAX) && \
  14470. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  14471. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void)
  14472. {
  14473. typedef struct {
  14474. byte key[AES_256_KEY_SIZE];
  14475. int key_length;
  14476. byte iv[WC_AES_BLOCK_SIZE];
  14477. int iv_length;
  14478. byte aad[WC_AES_BLOCK_SIZE * 2];
  14479. int aad_length;
  14480. byte msg[WC_AES_BLOCK_SIZE * 2];
  14481. int msg_length;
  14482. byte ct[WC_AES_BLOCK_SIZE * 2];
  14483. int ct_length;
  14484. byte tag[WC_AES_BLOCK_SIZE];
  14485. int tag_length;
  14486. int valid;
  14487. } AadVector;
  14488. /* A small selection of Google wycheproof vectors that use vectors
  14489. * from the original paper: eprint.iacr.org/2003/069
  14490. * https://github.com/google/wycheproof/blob/master/testvectors/aes_eax_test.json
  14491. */
  14492. WOLFSSL_SMALL_STACK_STATIC const AadVector vectors[] = {
  14493. /* Vector from paper - empty message with auth data */
  14494. {
  14495. /* key, key length */
  14496. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  14497. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  14498. /* iv, iv length */
  14499. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  14500. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  14501. /* aad, aad length */
  14502. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  14503. /* msg, msg length */
  14504. {0}, 0,
  14505. /* ct, ct length */
  14506. {0}, 0,
  14507. /* tag, tag length */
  14508. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2,
  14509. 0x7b, 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  14510. /* valid */
  14511. 1,
  14512. },
  14513. /* Vector from paper - no auth data, valid auth tag */
  14514. {
  14515. /* key, key length */
  14516. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14517. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14518. /* iv , iv length */
  14519. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  14520. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  14521. /* aad, aad length */
  14522. {0}, 0,
  14523. /* msg, msg length */
  14524. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14525. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14526. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  14527. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  14528. /* ct, ct length */
  14529. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  14530. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  14531. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  14532. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  14533. /* tag, tag length */
  14534. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  14535. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  14536. /* valid */
  14537. 1,
  14538. },
  14539. /* Vector from paper - no auth data with invalid auth tag */
  14540. {
  14541. /* key, key length */
  14542. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14543. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14544. /* iv, iv length */
  14545. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14546. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  14547. /* aad, aad length */
  14548. {0}, 0,
  14549. /* msg, msg length */
  14550. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14551. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  14552. /* ct , ct length */
  14553. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  14554. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  14555. /* tag, tag length */
  14556. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  14557. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  14558. /* valid */
  14559. 0,
  14560. },
  14561. };
  14562. WOLFSSL_SMALL_STACK_STATIC byte ciphertext[sizeof(vectors[0].ct)];
  14563. WOLFSSL_SMALL_STACK_STATIC byte authtag[sizeof(vectors[0].tag)];
  14564. int i;
  14565. int len;
  14566. wc_test_ret_t ret;
  14567. WOLFSSL_ENTER("aes_eax_test");
  14568. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  14569. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14570. len = sizeof(authtag);
  14571. ret = wc_AesEaxEncryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14572. ciphertext,
  14573. vectors[i].msg, (word32)vectors[i].msg_length,
  14574. vectors[i].iv, (word32)vectors[i].iv_length,
  14575. authtag, (word32)len,
  14576. vectors[i].aad, (word32)vectors[i].aad_length);
  14577. if (ret != 0) {
  14578. return WC_TEST_RET_ENC_EC(ret);
  14579. }
  14580. /* check ciphertext matches vector */
  14581. if (XMEMCMP(ciphertext, vectors[i].ct, (size_t)vectors[i].ct_length)) {
  14582. return WC_TEST_RET_ENC_NC;
  14583. }
  14584. /* check that tag matches vector only for vectors marked as valid */
  14585. ret = XMEMCMP(authtag, vectors[i].tag, len);
  14586. if (vectors[i].valid == 1 && ret != 0 ) {
  14587. return WC_TEST_RET_ENC_NC;
  14588. }
  14589. else if (vectors[i].valid == 0 && ret == 0) {
  14590. return WC_TEST_RET_ENC_NC;
  14591. }
  14592. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14593. ret = wc_AesEaxDecryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14594. ciphertext,
  14595. vectors[i].ct, (word32)vectors[i].ct_length,
  14596. vectors[i].iv, (word32)vectors[i].iv_length,
  14597. authtag, (word32)len,
  14598. vectors[i].aad, (word32)vectors[i].aad_length);
  14599. if (ret != 0) {
  14600. return WC_TEST_RET_ENC_EC(ret);
  14601. }
  14602. /* check decrypted ciphertext matches vector plaintext */
  14603. if (XMEMCMP(ciphertext, vectors[i].msg, (size_t)vectors[i].msg_length)) {
  14604. return WC_TEST_RET_ENC_NC;
  14605. }
  14606. }
  14607. return 0;
  14608. }
  14609. #endif /* WOLFSSL_AES_EAX */
  14610. #ifdef HAVE_AES_KEYWRAP
  14611. #define MAX_KEYWRAP_TEST_OUTLEN 40
  14612. #define MAX_KEYWRAP_TEST_PLAINLEN 32
  14613. typedef struct keywrapVector {
  14614. const byte* kek;
  14615. const byte* data;
  14616. const byte* verify;
  14617. word32 kekLen;
  14618. word32 dataLen;
  14619. word32 verifyLen;
  14620. } keywrapVector;
  14621. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void)
  14622. {
  14623. int wrapSz, plainSz, testSz, i;
  14624. /* test vectors from RFC 3394 (kek, data, verify) */
  14625. #ifdef WOLFSSL_AES_128
  14626. /* Wrap 128 bits of Key Data with a 128-bit KEK */
  14627. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14628. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14629. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14630. };
  14631. WOLFSSL_SMALL_STACK_STATIC const byte d1[] = {
  14632. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14633. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14634. };
  14635. WOLFSSL_SMALL_STACK_STATIC const byte v1[] = {
  14636. 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
  14637. 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
  14638. 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
  14639. };
  14640. #endif /* WOLFSSL_AES_128 */
  14641. #ifdef WOLFSSL_AES_192
  14642. /* Wrap 128 bits of Key Data with a 192-bit KEK */
  14643. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  14644. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14645. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14646. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14647. };
  14648. WOLFSSL_SMALL_STACK_STATIC const byte d2[] = {
  14649. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14650. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14651. };
  14652. WOLFSSL_SMALL_STACK_STATIC const byte v2[] = {
  14653. 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35,
  14654. 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2,
  14655. 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D
  14656. };
  14657. #endif
  14658. #ifdef WOLFSSL_AES_256
  14659. /* Wrap 128 bits of Key Data with a 256-bit KEK */
  14660. WOLFSSL_SMALL_STACK_STATIC const byte k3[] = {
  14661. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14662. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14663. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14664. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14665. };
  14666. WOLFSSL_SMALL_STACK_STATIC const byte d3[] = {
  14667. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14668. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14669. };
  14670. WOLFSSL_SMALL_STACK_STATIC const byte v3[] = {
  14671. 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2,
  14672. 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A,
  14673. 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7
  14674. };
  14675. #endif
  14676. #ifdef WOLFSSL_AES_192
  14677. /* Wrap 192 bits of Key Data with a 192-bit KEK */
  14678. WOLFSSL_SMALL_STACK_STATIC const byte k4[] = {
  14679. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14680. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14681. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14682. };
  14683. WOLFSSL_SMALL_STACK_STATIC const byte d4[] = {
  14684. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14685. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14686. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14687. };
  14688. WOLFSSL_SMALL_STACK_STATIC const byte v4[] = {
  14689. 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32,
  14690. 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC,
  14691. 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93,
  14692. 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2
  14693. };
  14694. #endif
  14695. #ifdef WOLFSSL_AES_256
  14696. /* Wrap 192 bits of Key Data with a 256-bit KEK */
  14697. WOLFSSL_SMALL_STACK_STATIC const byte k5[] = {
  14698. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14699. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14700. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14701. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14702. };
  14703. WOLFSSL_SMALL_STACK_STATIC const byte d5[] = {
  14704. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14705. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14706. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14707. };
  14708. WOLFSSL_SMALL_STACK_STATIC const byte v5[] = {
  14709. 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F,
  14710. 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4,
  14711. 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95,
  14712. 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1
  14713. };
  14714. /* Wrap 256 bits of Key Data with a 256-bit KEK */
  14715. WOLFSSL_SMALL_STACK_STATIC const byte k6[] = {
  14716. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14717. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14718. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14719. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14720. };
  14721. WOLFSSL_SMALL_STACK_STATIC const byte d6[] = {
  14722. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14723. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14724. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14725. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14726. };
  14727. WOLFSSL_SMALL_STACK_STATIC const byte v6[] = {
  14728. 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4,
  14729. 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26,
  14730. 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26,
  14731. 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B,
  14732. 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21
  14733. };
  14734. #endif /* WOLFSSL_AES_256 */
  14735. byte output[MAX_KEYWRAP_TEST_OUTLEN];
  14736. byte plain [MAX_KEYWRAP_TEST_PLAINLEN];
  14737. const keywrapVector test_wrap[] =
  14738. {
  14739. #ifdef WOLFSSL_AES_128
  14740. {k1, d1, v1, sizeof(k1), sizeof(d1), sizeof(v1)},
  14741. #endif
  14742. #ifdef WOLFSSL_AES_192
  14743. {k2, d2, v2, sizeof(k2), sizeof(d2), sizeof(v2)},
  14744. #endif
  14745. #ifdef WOLFSSL_AES_256
  14746. {k3, d3, v3, sizeof(k3), sizeof(d3), sizeof(v3)},
  14747. #endif
  14748. #ifdef WOLFSSL_AES_192
  14749. {k4, d4, v4, sizeof(k4), sizeof(d4), sizeof(v4)},
  14750. #endif
  14751. #ifdef WOLFSSL_AES_256
  14752. {k5, d5, v5, sizeof(k5), sizeof(d5), sizeof(v5)},
  14753. {k6, d6, v6, sizeof(k6), sizeof(d6), sizeof(v6)}
  14754. #endif
  14755. };
  14756. WOLFSSL_ENTER("aeskeywrap_test");
  14757. testSz = sizeof(test_wrap) / sizeof(keywrapVector);
  14758. XMEMSET(output, 0, sizeof(output));
  14759. XMEMSET(plain, 0, sizeof(plain));
  14760. for (i = 0; i < testSz; i++) {
  14761. wrapSz = wc_AesKeyWrap(test_wrap[i].kek, test_wrap[i].kekLen,
  14762. test_wrap[i].data, test_wrap[i].dataLen,
  14763. output, sizeof(output), NULL);
  14764. if ( (wrapSz < 0) || (wrapSz != (int)test_wrap[i].verifyLen) )
  14765. return WC_TEST_RET_ENC_NC;
  14766. if (XMEMCMP(output, test_wrap[i].verify, test_wrap[i].verifyLen) != 0)
  14767. return WC_TEST_RET_ENC_NC;
  14768. plainSz = wc_AesKeyUnWrap((byte*)test_wrap[i].kek, test_wrap[i].kekLen,
  14769. output, (word32)wrapSz,
  14770. plain, sizeof(plain), NULL);
  14771. if ( (plainSz < 0) || (plainSz != (int)test_wrap[i].dataLen) )
  14772. return WC_TEST_RET_ENC_NC;
  14773. if (XMEMCMP(plain, test_wrap[i].data, test_wrap[i].dataLen) != 0)
  14774. return WC_TEST_RET_ENC_I(i);
  14775. }
  14776. return 0;
  14777. }
  14778. #endif /* HAVE_AES_KEYWRAP */
  14779. #endif /* !NO_AES */
  14780. #ifdef HAVE_ARIA
  14781. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz)
  14782. {
  14783. #ifndef DEBUG_WOLFSSL
  14784. (void)strName;
  14785. (void)data;
  14786. (void)dataSz;
  14787. #else
  14788. WOLFSSL_MSG_EX("%s (%d):", strName,dataSz);
  14789. WOLFSSL_BUFFER(data,dataSz);
  14790. #endif
  14791. }
  14792. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID algo)
  14793. {
  14794. byte data[] = TEST_STRING;
  14795. word32 dataSz = TEST_STRING_SZ;
  14796. /* Arbitrarily random long key that we will truncate to the right size */
  14797. byte key[] = { 0x1E, 0xCC, 0x95, 0xCB, 0xD3, 0x74, 0x58, 0x4F,
  14798. 0x6F, 0x8A, 0x70, 0x26, 0xF7, 0x3C, 0x8D, 0xB6,
  14799. 0xDC, 0x32, 0x76, 0x20, 0xCF, 0x05, 0x4A, 0xCF,
  14800. 0x11, 0x86, 0xCD, 0x23, 0x5E, 0xC1, 0x6E, 0x2B };
  14801. byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[WC_AES_BLOCK_SIZE];
  14802. word32 keySz, adSz = 256, authTagSz = sizeof(authTag);
  14803. wc_Aria aria;
  14804. int ret = 0;
  14805. WOLFSSL_ENTER("ariagcm_test");
  14806. XMEMSET((void *)&aria, 0, sizeof(aria));
  14807. ret = wc_AriaInitCrypt(&aria, algo);
  14808. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14809. ret = wc_AriaSetKey(&aria, key);
  14810. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14811. MC_GetObjectValue(aria.hSession, aria.hKey, key, &keySz);
  14812. printOutput("Key", key, keySz);
  14813. WC_RNG rng;
  14814. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14815. if (ret != 0)
  14816. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14817. ret = wc_AriaGcmSetIV(&aria, GCM_NONCE_MID_SZ, NULL, 0, &rng);
  14818. if (ret != 0)
  14819. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14820. wc_FreeRng(&rng);
  14821. printOutput("Plaintext", data, sizeof(data));
  14822. XMEMSET(cipher, 0, sizeof(cipher));
  14823. ret = wc_AriaEncrypt(&aria, cipher, data, dataSz,
  14824. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14825. authTag, authTagSz);
  14826. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14827. printOutput("Ciphertext", cipher, sizeof(cipher));
  14828. printOutput("AuthTag", authTag, sizeof(authTag));
  14829. XMEMSET(plain, 0, sizeof(plain));
  14830. ret = wc_AriaDecrypt(&aria, plain, cipher, dataSz,
  14831. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14832. authTag, authTagSz);
  14833. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14834. printOutput("Plaintext", plain, sizeof(plain));
  14835. if (XMEMCMP(plain, data, dataSz) != 0)
  14836. ERROR_OUT(WC_TEST_RET_ENC_NC,out);
  14837. out:
  14838. if (ret != 0) { wc_AriaFreeCrypt(&aria); }
  14839. else { ret = wc_AriaFreeCrypt(&aria); }
  14840. return ret;
  14841. }
  14842. #endif /* HAVE_ARIA */
  14843. #ifdef HAVE_CAMELLIA
  14844. enum {
  14845. CAM_ECB_ENC, CAM_ECB_DEC, CAM_CBC_ENC, CAM_CBC_DEC
  14846. };
  14847. typedef struct {
  14848. int type;
  14849. const byte* plaintext;
  14850. const byte* iv;
  14851. const byte* ciphertext;
  14852. const byte* key;
  14853. word32 keySz;
  14854. int errorCode;
  14855. } test_vector_t;
  14856. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void)
  14857. {
  14858. /* Camellia ECB Test Plaintext */
  14859. WOLFSSL_SMALL_STACK_STATIC const byte pte[] =
  14860. {
  14861. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14862. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14863. };
  14864. /* Camellia ECB Test Initialization Vector */
  14865. WOLFSSL_SMALL_STACK_STATIC const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  14866. /* Test 1: Camellia ECB 128-bit key */
  14867. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14868. {
  14869. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14870. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14871. };
  14872. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  14873. {
  14874. 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
  14875. 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
  14876. };
  14877. /* Test 2: Camellia ECB 192-bit key */
  14878. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14879. {
  14880. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14881. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14882. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  14883. };
  14884. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  14885. {
  14886. 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
  14887. 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9
  14888. };
  14889. /* Test 3: Camellia ECB 256-bit key */
  14890. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  14891. {
  14892. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14893. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14894. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14895. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  14896. };
  14897. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  14898. {
  14899. 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
  14900. 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09
  14901. };
  14902. /* Camellia CBC Test Plaintext */
  14903. WOLFSSL_SMALL_STACK_STATIC const byte ptc[] =
  14904. {
  14905. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  14906. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  14907. };
  14908. /* Camellia CBC Test Initialization Vector */
  14909. WOLFSSL_SMALL_STACK_STATIC const byte ivc[] =
  14910. {
  14911. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14912. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14913. };
  14914. /* Test 4: Camellia-CBC 128-bit key */
  14915. WOLFSSL_SMALL_STACK_STATIC const byte k4[] =
  14916. {
  14917. 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
  14918. 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
  14919. };
  14920. WOLFSSL_SMALL_STACK_STATIC const byte c4[] =
  14921. {
  14922. 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
  14923. 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB
  14924. };
  14925. /* Test 5: Camellia-CBC 192-bit key */
  14926. WOLFSSL_SMALL_STACK_STATIC const byte k5[] =
  14927. {
  14928. 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
  14929. 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
  14930. 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B
  14931. };
  14932. WOLFSSL_SMALL_STACK_STATIC const byte c5[] =
  14933. {
  14934. 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
  14935. 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93
  14936. };
  14937. /* Test 6: CBC 256-bit key */
  14938. WOLFSSL_SMALL_STACK_STATIC const byte k6[] =
  14939. {
  14940. 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
  14941. 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
  14942. 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
  14943. 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4
  14944. };
  14945. WOLFSSL_SMALL_STACK_STATIC const byte c6[] =
  14946. {
  14947. 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
  14948. 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
  14949. };
  14950. byte out[WC_CAMELLIA_BLOCK_SIZE];
  14951. wc_Camellia cam;
  14952. WOLFSSL_SMALL_STACK_STATIC const test_vector_t testVectors[] =
  14953. {
  14954. {CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114},
  14955. {CAM_ECB_ENC, pte, ive, c2, k2, sizeof(k2), -115},
  14956. {CAM_ECB_ENC, pte, ive, c3, k3, sizeof(k3), -116},
  14957. {CAM_ECB_DEC, pte, ive, c1, k1, sizeof(k1), -117},
  14958. {CAM_ECB_DEC, pte, ive, c2, k2, sizeof(k2), -118},
  14959. {CAM_ECB_DEC, pte, ive, c3, k3, sizeof(k3), -119},
  14960. {CAM_CBC_ENC, ptc, ivc, c4, k4, sizeof(k4), -120},
  14961. {CAM_CBC_ENC, ptc, ivc, c5, k5, sizeof(k5), -121},
  14962. {CAM_CBC_ENC, ptc, ivc, c6, k6, sizeof(k6), -122},
  14963. {CAM_CBC_DEC, ptc, ivc, c4, k4, sizeof(k4), -123},
  14964. {CAM_CBC_DEC, ptc, ivc, c5, k5, sizeof(k5), -124},
  14965. {CAM_CBC_DEC, ptc, ivc, c6, k6, sizeof(k6), -125}
  14966. };
  14967. int i, testsSz;
  14968. int ret;
  14969. WOLFSSL_ENTER("camellia_test");
  14970. testsSz = sizeof(testVectors)/sizeof(test_vector_t);
  14971. for (i = 0; i < testsSz; i++) {
  14972. if (wc_CamelliaSetKey(&cam, testVectors[i].key, testVectors[i].keySz,
  14973. testVectors[i].iv) != 0)
  14974. return testVectors[i].errorCode;
  14975. switch (testVectors[i].type) {
  14976. case CAM_ECB_ENC:
  14977. ret = wc_CamelliaEncryptDirect(&cam, out,
  14978. testVectors[i].plaintext);
  14979. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14980. WC_CAMELLIA_BLOCK_SIZE))
  14981. return testVectors[i].errorCode;
  14982. break;
  14983. case CAM_ECB_DEC:
  14984. ret = wc_CamelliaDecryptDirect(&cam, out,
  14985. testVectors[i].ciphertext);
  14986. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14987. WC_CAMELLIA_BLOCK_SIZE))
  14988. return testVectors[i].errorCode;
  14989. break;
  14990. case CAM_CBC_ENC:
  14991. ret = wc_CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext,
  14992. WC_CAMELLIA_BLOCK_SIZE);
  14993. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14994. WC_CAMELLIA_BLOCK_SIZE))
  14995. return testVectors[i].errorCode;
  14996. break;
  14997. case CAM_CBC_DEC:
  14998. ret = wc_CamelliaCbcDecrypt(&cam, out,
  14999. testVectors[i].ciphertext, WC_CAMELLIA_BLOCK_SIZE);
  15000. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  15001. WC_CAMELLIA_BLOCK_SIZE))
  15002. return testVectors[i].errorCode;
  15003. break;
  15004. default:
  15005. break;
  15006. }
  15007. }
  15008. /* Setting the IV and checking it was actually set. */
  15009. ret = wc_CamelliaSetIV(&cam, ivc);
  15010. if (ret != 0)
  15011. return WC_TEST_RET_ENC_EC(ret);
  15012. if (XMEMCMP(cam.reg, ivc, WC_CAMELLIA_BLOCK_SIZE) != 0)
  15013. return WC_TEST_RET_ENC_NC;
  15014. /* Setting the IV to NULL should be same as all zeros IV */
  15015. ret = wc_CamelliaSetIV(&cam, NULL);
  15016. if (ret != 0)
  15017. return WC_TEST_RET_ENC_EC(ret);
  15018. if (XMEMCMP(cam.reg, ive, WC_CAMELLIA_BLOCK_SIZE) != 0)
  15019. return WC_TEST_RET_ENC_NC;
  15020. /* First parameter should never be null */
  15021. if (wc_CamelliaSetIV(NULL, NULL) == 0)
  15022. return WC_TEST_RET_ENC_NC;
  15023. /* First parameter should never be null, check it fails */
  15024. if (wc_CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0)
  15025. return WC_TEST_RET_ENC_NC;
  15026. /* Key should have a size of 16, 24, or 32 */
  15027. if (wc_CamelliaSetKey(&cam, k1, 0, NULL) == 0)
  15028. return WC_TEST_RET_ENC_NC;
  15029. return 0;
  15030. }
  15031. #endif /* HAVE_CAMELLIA */
  15032. #ifdef WOLFSSL_SM4
  15033. #ifdef WOLFSSL_SM4_ECB
  15034. static int sm4_ecb_test(void)
  15035. {
  15036. /* draft-ribose-cfrg-sm4-10 A.2.1.1 */
  15037. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15038. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15039. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15040. };
  15041. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15042. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15043. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15044. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15045. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15046. };
  15047. WOLFSSL_SMALL_STACK_STATIC const byte c1_ecb[] = {
  15048. 0x5E, 0xC8, 0x14, 0x3D, 0xE5, 0x09, 0xCF, 0xF7,
  15049. 0xB5, 0x17, 0x9F, 0x8F, 0x47, 0x4B, 0x86, 0x19,
  15050. 0x2F, 0x1D, 0x30, 0x5A, 0x7F, 0xB1, 0x7D, 0xF9,
  15051. 0x85, 0xF8, 0x1C, 0x84, 0x82, 0x19, 0x23, 0x04
  15052. };
  15053. wc_Sm4 sm4;
  15054. byte enc[SM4_BLOCK_SIZE * 4];
  15055. byte dec[SM4_BLOCK_SIZE * 4];
  15056. int ret;
  15057. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15058. if (ret != 0)
  15059. return WC_TEST_RET_ENC_EC(ret);
  15060. /* Encrypt and decrypt with ECB. */
  15061. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15062. if (ret != 0)
  15063. return WC_TEST_RET_ENC_EC(ret);
  15064. ret = wc_Sm4EcbEncrypt(&sm4, enc, p1, sizeof(p1));
  15065. if (ret != 0)
  15066. return WC_TEST_RET_ENC_EC(ret);
  15067. if (XMEMCMP(enc, c1_ecb, sizeof(c1_ecb)) != 0)
  15068. return WC_TEST_RET_ENC_NC;
  15069. ret = wc_Sm4EcbDecrypt(&sm4, dec, enc, sizeof(c1_ecb));
  15070. if (ret != 0)
  15071. return WC_TEST_RET_ENC_EC(ret);
  15072. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15073. return WC_TEST_RET_ENC_NC;
  15074. wc_Sm4Free(&sm4);
  15075. return 0;
  15076. }
  15077. #endif
  15078. #ifdef WOLFSSL_SM4_CBC
  15079. static int sm4_cbc_test(void)
  15080. {
  15081. /* draft-ribose-cfrg-sm4-10 A.2.2.1 */
  15082. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15083. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15084. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15085. };
  15086. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15087. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15088. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15089. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15090. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15091. };
  15092. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15093. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15094. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15095. };
  15096. WOLFSSL_SMALL_STACK_STATIC const byte c1_cbc[] = {
  15097. 0x78, 0xEB, 0xB1, 0x1C, 0xC4, 0x0B, 0x0A, 0x48,
  15098. 0x31, 0x2A, 0xAE, 0xB2, 0x04, 0x02, 0x44, 0xCB,
  15099. 0x4C, 0xB7, 0x01, 0x69, 0x51, 0x90, 0x92, 0x26,
  15100. 0x97, 0x9B, 0x0D, 0x15, 0xDC, 0x6A, 0x8F, 0x6D
  15101. };
  15102. wc_Sm4 sm4;
  15103. byte enc[SM4_BLOCK_SIZE * 4];
  15104. byte dec[SM4_BLOCK_SIZE * 4];
  15105. int ret;
  15106. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15107. if (ret != 0)
  15108. return WC_TEST_RET_ENC_EC(ret);
  15109. /* Encrypt and decrypt with CBC. */
  15110. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15111. if (ret != 0)
  15112. return WC_TEST_RET_ENC_EC(ret);
  15113. ret = wc_Sm4SetIV(&sm4, i1);
  15114. if (ret != 0)
  15115. return WC_TEST_RET_ENC_EC(ret);
  15116. ret = wc_Sm4CbcEncrypt(&sm4, enc, p1, sizeof(p1));
  15117. if (ret != 0)
  15118. return WC_TEST_RET_ENC_EC(ret);
  15119. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15120. return WC_TEST_RET_ENC_NC;
  15121. ret = wc_Sm4SetIV(&sm4, i1);
  15122. if (ret != 0)
  15123. return WC_TEST_RET_ENC_EC(ret);
  15124. ret = wc_Sm4CbcDecrypt(&sm4, dec, enc, sizeof(c1_cbc));
  15125. if (ret != 0)
  15126. return WC_TEST_RET_ENC_EC(ret);
  15127. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15128. return WC_TEST_RET_ENC_NC;
  15129. /* Encrypt and decrypt in-place with CBC. */
  15130. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15131. if (ret != 0)
  15132. return WC_TEST_RET_ENC_EC(ret);
  15133. ret = wc_Sm4SetIV(&sm4, i1);
  15134. if (ret != 0)
  15135. return WC_TEST_RET_ENC_EC(ret);
  15136. XMEMCPY(enc, p1, sizeof(p1));
  15137. ret = wc_Sm4CbcEncrypt(&sm4, enc, enc, sizeof(p1));
  15138. if (ret != 0)
  15139. return WC_TEST_RET_ENC_EC(ret);
  15140. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15141. return WC_TEST_RET_ENC_NC;
  15142. ret = wc_Sm4SetIV(&sm4, i1);
  15143. if (ret != 0)
  15144. return WC_TEST_RET_ENC_EC(ret);
  15145. ret = wc_Sm4CbcDecrypt(&sm4, enc, enc, sizeof(c1_cbc));
  15146. if (ret != 0)
  15147. return WC_TEST_RET_ENC_EC(ret);
  15148. if (XMEMCMP(enc, p1, sizeof(p1)) != 0)
  15149. return WC_TEST_RET_ENC_NC;
  15150. wc_Sm4Free(&sm4);
  15151. return 0;
  15152. }
  15153. #endif
  15154. #ifdef WOLFSSL_SM4_CTR
  15155. static int sm4_ctr_test(void)
  15156. {
  15157. /* draft-ribose-cfrg-sm4-10 A.2.5.1 */
  15158. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15159. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15160. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15161. };
  15162. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15163. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15164. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15165. };
  15166. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15167. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15168. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15169. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15170. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15171. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15172. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15173. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15174. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB
  15175. };
  15176. WOLFSSL_SMALL_STACK_STATIC const byte c2_ctr[] = {
  15177. 0xAC, 0x32, 0x36, 0xCB, 0x97, 0x0C, 0xC2, 0x07,
  15178. 0x91, 0x36, 0x4C, 0x39, 0x5A, 0x13, 0x42, 0xD1,
  15179. 0xA3, 0xCB, 0xC1, 0x87, 0x8C, 0x6F, 0x30, 0xCD,
  15180. 0x07, 0x4C, 0xCE, 0x38, 0x5C, 0xDD, 0x70, 0xC7,
  15181. 0xF2, 0x34, 0xBC, 0x0E, 0x24, 0xC1, 0x19, 0x80,
  15182. 0xFD, 0x12, 0x86, 0x31, 0x0C, 0xE3, 0x7B, 0x92,
  15183. 0x6E, 0x02, 0xFC, 0xD0, 0xFA, 0xA0, 0xBA, 0xF3,
  15184. 0x8B, 0x29, 0x33, 0x85, 0x1D, 0x82, 0x45, 0x14
  15185. };
  15186. wc_Sm4 sm4;
  15187. byte enc[SM4_BLOCK_SIZE * 4];
  15188. byte dec[SM4_BLOCK_SIZE * 4];
  15189. int chunk;
  15190. int i;
  15191. int ret;
  15192. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15193. if (ret != 0)
  15194. return WC_TEST_RET_ENC_EC(ret);
  15195. /* Encrypt and decrypt using encrypt with CTR. */
  15196. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15197. if (ret != 0)
  15198. return WC_TEST_RET_ENC_EC(ret);
  15199. ret = wc_Sm4SetIV(&sm4, i1);
  15200. if (ret != 0)
  15201. return WC_TEST_RET_ENC_EC(ret);
  15202. ret = wc_Sm4CtrEncrypt(&sm4, enc, p2, sizeof(p2));
  15203. if (ret != 0)
  15204. return WC_TEST_RET_ENC_EC(ret);
  15205. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15206. return WC_TEST_RET_ENC_NC;
  15207. ret = wc_Sm4SetIV(&sm4, i1);
  15208. if (ret != 0)
  15209. return WC_TEST_RET_ENC_EC(ret);
  15210. ret = wc_Sm4CtrEncrypt(&sm4, dec, enc, sizeof(c2_ctr));
  15211. if (ret != 0)
  15212. return WC_TEST_RET_ENC_EC(ret);
  15213. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15214. return WC_TEST_RET_ENC_NC;
  15215. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15216. ret = wc_Sm4SetIV(&sm4, i1);
  15217. if (ret != 0)
  15218. return WC_TEST_RET_ENC_I(chunk);
  15219. XMEMSET(enc, 0, sizeof(enc));
  15220. for (i = 0; i + chunk <= (int)sizeof(p2); i += chunk) {
  15221. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, chunk);
  15222. if (ret != 0)
  15223. return WC_TEST_RET_ENC_I(i);
  15224. }
  15225. if (i < (int)sizeof(p2)) {
  15226. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, sizeof(p2) - i);
  15227. if (ret != 0)
  15228. return WC_TEST_RET_ENC_I(chunk);
  15229. }
  15230. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15231. return WC_TEST_RET_ENC_I(chunk);
  15232. }
  15233. wc_Sm4Free(&sm4);
  15234. return 0;
  15235. }
  15236. #endif
  15237. #ifdef WOLFSSL_SM4_GCM
  15238. static int sm4_gcm_test(void)
  15239. {
  15240. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15241. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15242. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15243. };
  15244. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15245. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15246. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15247. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15248. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15249. };
  15250. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15251. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15252. 0x08, 0x09, 0x0A, 0x0B
  15253. };
  15254. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15255. 0xFF, 0xEE, 0xDD
  15256. };
  15257. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15258. 0x83, 0xb2, 0x91, 0xcf, 0x22, 0xc9, 0x5f, 0x89,
  15259. 0xde, 0x3d, 0x52, 0x8d, 0xd7, 0x13, 0x50, 0x89
  15260. };
  15261. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15262. 0xff, 0x8b, 0xb2, 0x3b, 0x0a, 0x0a, 0x12, 0xa4,
  15263. 0xa8, 0x4c, 0x4f, 0x67, 0x06, 0x81, 0xbb, 0x88,
  15264. 0x66, 0x17, 0xc7, 0x43, 0xbf, 0xae, 0x41, 0x40,
  15265. 0xec, 0x1e, 0x03, 0x85, 0x2b, 0x56, 0xa8, 0xc0
  15266. };
  15267. /* RFC8998 A.1. */
  15268. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15269. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15270. 0x00, 0x00, 0xAB, 0xCD
  15271. };
  15272. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15273. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15274. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15275. };
  15276. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15277. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15278. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15279. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15280. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15281. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15282. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15283. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15284. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15285. };
  15286. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15287. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15288. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15289. 0xAB, 0xAD, 0xDA, 0xD2
  15290. };
  15291. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15292. 0x17, 0xF3, 0x99, 0xF0, 0x8C, 0x67, 0xD5, 0xEE,
  15293. 0x19, 0xD0, 0xDC, 0x99, 0x69, 0xC4, 0xBB, 0x7D,
  15294. 0x5F, 0xD4, 0x6F, 0xD3, 0x75, 0x64, 0x89, 0x06,
  15295. 0x91, 0x57, 0xB2, 0x82, 0xBB, 0x20, 0x07, 0x35,
  15296. 0xD8, 0x27, 0x10, 0xCA, 0x5C, 0x22, 0xF0, 0xCC,
  15297. 0xFA, 0x7C, 0xBF, 0x93, 0xD4, 0x96, 0xAC, 0x15,
  15298. 0xA5, 0x68, 0x34, 0xCB, 0xCF, 0x98, 0xC3, 0x97,
  15299. 0xB4, 0x02, 0x4A, 0x26, 0x91, 0x23, 0x3B, 0x8D
  15300. };
  15301. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15302. 0x83, 0xDE, 0x35, 0x41, 0xE4, 0xC2, 0xB5, 0x81,
  15303. 0x77, 0xE0, 0x65, 0xA9, 0xBF, 0x7B, 0x62, 0xEC
  15304. };
  15305. wc_Sm4 sm4;
  15306. byte enc[SM4_BLOCK_SIZE * 4];
  15307. byte dec[SM4_BLOCK_SIZE * 4];
  15308. byte tag[SM4_BLOCK_SIZE];
  15309. int ret;
  15310. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15311. if (ret != 0)
  15312. return WC_TEST_RET_ENC_EC(ret);
  15313. /* Encrypt and decrypt using encrypt with GCM. */
  15314. ret = wc_Sm4GcmSetKey(&sm4, k1, sizeof(k1));
  15315. if (ret != 0)
  15316. return WC_TEST_RET_ENC_EC(ret);
  15317. ret = wc_Sm4GcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15318. sizeof(tag), a1, sizeof(a1));
  15319. if (ret != 0)
  15320. return WC_TEST_RET_ENC_EC(ret);
  15321. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15322. return WC_TEST_RET_ENC_NC;
  15323. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15324. return WC_TEST_RET_ENC_NC;
  15325. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15326. sizeof(tag), a1, sizeof(a1));
  15327. if (ret != 0)
  15328. return WC_TEST_RET_ENC_EC(ret);
  15329. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15330. return WC_TEST_RET_ENC_NC;
  15331. /* RFC8998 test vector. */
  15332. ret = wc_Sm4GcmSetKey(&sm4, k2, sizeof(k2));
  15333. if (ret != 0)
  15334. return WC_TEST_RET_ENC_EC(ret);
  15335. ret = wc_Sm4GcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15336. sizeof(tag), a2, sizeof(a2));
  15337. if (ret != 0)
  15338. return WC_TEST_RET_ENC_EC(ret);
  15339. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15340. return WC_TEST_RET_ENC_NC;
  15341. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15342. return WC_TEST_RET_ENC_NC;
  15343. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15344. sizeof(tag), a2, sizeof(a2));
  15345. if (ret != 0)
  15346. return WC_TEST_RET_ENC_EC(ret);
  15347. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15348. return WC_TEST_RET_ENC_NC;
  15349. wc_Sm4Free(&sm4);
  15350. return 0;
  15351. }
  15352. #endif
  15353. #ifdef WOLFSSL_SM4_CCM
  15354. static int sm4_ccm_test(void)
  15355. {
  15356. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15357. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15358. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15359. };
  15360. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15361. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15362. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15363. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15364. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15365. };
  15366. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15367. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15368. 0x08, 0x09, 0x0A, 0x0B
  15369. };
  15370. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15371. 0xFF, 0xEE, 0xDD
  15372. };
  15373. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15374. 0x9a, 0x98, 0x04, 0xb6, 0x0f, 0x19, 0x4a, 0x46,
  15375. 0xba, 0xed, 0xe6, 0x89, 0x69, 0x34, 0xad, 0x61
  15376. };
  15377. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15378. 0xbd, 0xc0, 0x72, 0x60, 0xda, 0x2d, 0x11, 0xdc,
  15379. 0x66, 0x33, 0xcc, 0xec, 0xb2, 0xf4, 0x53, 0x59,
  15380. 0x9e, 0xb1, 0xb3, 0x6b, 0x1f, 0x1c, 0xfb, 0x29,
  15381. 0xf5, 0x37, 0xfc, 0x00, 0xf2, 0x4e, 0x70, 0x6f
  15382. };
  15383. /* RFC8998 A.1. */
  15384. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15385. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15386. 0x00, 0x00, 0xAB, 0xCD
  15387. };
  15388. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15389. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15390. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15391. };
  15392. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15393. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15394. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15395. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15396. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15397. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15398. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15399. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15400. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15401. };
  15402. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15403. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15404. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15405. 0xAB, 0xAD, 0xDA, 0xD2
  15406. };
  15407. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15408. 0x48, 0xAF, 0x93, 0x50, 0x1F, 0xA6, 0x2A, 0xDB,
  15409. 0xCD, 0x41, 0x4C, 0xCE, 0x60, 0x34, 0xD8, 0x95,
  15410. 0xDD, 0xA1, 0xBF, 0x8F, 0x13, 0x2F, 0x04, 0x20,
  15411. 0x98, 0x66, 0x15, 0x72, 0xE7, 0x48, 0x30, 0x94,
  15412. 0xFD, 0x12, 0xE5, 0x18, 0xCE, 0x06, 0x2C, 0x98,
  15413. 0xAC, 0xEE, 0x28, 0xD9, 0x5D, 0xF4, 0x41, 0x6B,
  15414. 0xED, 0x31, 0xA2, 0xF0, 0x44, 0x76, 0xC1, 0x8B,
  15415. 0xB4, 0x0C, 0x84, 0xA7, 0x4B, 0x97, 0xDC, 0x5B
  15416. };
  15417. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15418. 0x16, 0x84, 0x2D, 0x4F, 0xA1, 0x86, 0xF5, 0x6A,
  15419. 0xB3, 0x32, 0x56, 0x97, 0x1F, 0xA1, 0x10, 0xF4
  15420. };
  15421. wc_Sm4 sm4;
  15422. byte enc[SM4_BLOCK_SIZE * 4];
  15423. byte dec[SM4_BLOCK_SIZE * 4];
  15424. byte tag[SM4_BLOCK_SIZE];
  15425. int ret;
  15426. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15427. if (ret != 0)
  15428. return WC_TEST_RET_ENC_EC(ret);
  15429. /* Encrypt and decrypt using encrypt with CCM. */
  15430. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15431. if (ret != 0)
  15432. return WC_TEST_RET_ENC_EC(ret);
  15433. ret = wc_Sm4CcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15434. sizeof(tag), a1, sizeof(a1));
  15435. if (ret != 0)
  15436. return WC_TEST_RET_ENC_EC(ret);
  15437. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15438. return WC_TEST_RET_ENC_NC;
  15439. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15440. return WC_TEST_RET_ENC_NC;
  15441. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15442. sizeof(tag), a1, sizeof(a1));
  15443. if (ret != 0)
  15444. return WC_TEST_RET_ENC_EC(ret);
  15445. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15446. return WC_TEST_RET_ENC_NC;
  15447. /* RFC8998 test vector. */
  15448. ret = wc_Sm4SetKey(&sm4, k2, sizeof(k2));
  15449. if (ret != 0)
  15450. return WC_TEST_RET_ENC_EC(ret);
  15451. ret = wc_Sm4CcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15452. sizeof(tag), a2, sizeof(a2));
  15453. if (ret != 0)
  15454. return WC_TEST_RET_ENC_EC(ret);
  15455. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15456. return WC_TEST_RET_ENC_NC;
  15457. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15458. return WC_TEST_RET_ENC_NC;
  15459. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15460. sizeof(tag), a2, sizeof(a2));
  15461. if (ret != 0)
  15462. return WC_TEST_RET_ENC_EC(ret);
  15463. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15464. return WC_TEST_RET_ENC_NC;
  15465. wc_Sm4Free(&sm4);
  15466. return 0;
  15467. }
  15468. #endif
  15469. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void)
  15470. {
  15471. wc_test_ret_t ret;
  15472. WOLFSSL_ENTER("sm4_test");
  15473. #ifdef WOLFSSL_SM4_ECB
  15474. ret = sm4_ecb_test();
  15475. if (ret != 0)
  15476. return ret;
  15477. #endif
  15478. #ifdef WOLFSSL_SM4_CBC
  15479. ret = sm4_cbc_test();
  15480. if (ret != 0)
  15481. return ret;
  15482. #endif
  15483. #ifdef WOLFSSL_SM4_CTR
  15484. ret = sm4_ctr_test();
  15485. if (ret != 0)
  15486. return ret;
  15487. #endif
  15488. #ifdef WOLFSSL_SM4_GCM
  15489. ret = sm4_gcm_test();
  15490. if (ret != 0)
  15491. return ret;
  15492. #endif
  15493. #ifdef WOLFSSL_SM4_CCM
  15494. ret = sm4_ccm_test();
  15495. if (ret != 0)
  15496. return ret;
  15497. #endif
  15498. return 0;
  15499. }
  15500. #endif
  15501. #ifdef HAVE_XCHACHA
  15502. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void) {
  15503. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15504. 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, /* The dhole (prono */
  15505. 0x75, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x22, 0x64, 0x6f, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x69, 0x73, /* unced "dole") is */
  15506. 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x74, /* also known as t */
  15507. 0x68, 0x65, 0x20, 0x41, 0x73, 0x69, 0x61, 0x74, 0x69, 0x63, 0x20, 0x77, 0x69, 0x6c, 0x64, 0x20, /* he Asiatic wild */
  15508. 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x72, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x61, 0x6e, /* dog, red dog, an */
  15509. 0x64, 0x20, 0x77, 0x68, 0x69, 0x73, 0x74, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x64, 0x6f, 0x67, 0x2e, /* d whistling dog. */
  15510. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, /* It is about the */
  15511. 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x47, 0x65, 0x72, 0x6d, 0x61, /* size of a Germa */
  15512. 0x6e, 0x20, 0x73, 0x68, 0x65, 0x70, 0x68, 0x65, 0x72, 0x64, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6c, /* n shepherd but l */
  15513. 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x61, /* ooks more like a */
  15514. 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x6c, 0x65, 0x67, 0x67, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x78, /* long-legged fox */
  15515. 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x79, 0x20, 0x65, 0x6c, /* . This highly el */
  15516. 0x75, 0x73, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x65, /* usive and skille */
  15517. 0x64, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6c, 0x61, 0x73, /* d jumper is clas */
  15518. 0x73, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x77, 0x6f, 0x6c, 0x76, /* sified with wolv */
  15519. 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6f, 0x79, 0x6f, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x6a, 0x61, 0x63, /* es, coyotes, jac */
  15520. 0x6b, 0x61, 0x6c, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x78, 0x65, 0x73, 0x20, /* kals, and foxes */
  15521. 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x61, 0x78, 0x6f, 0x6e, 0x6f, 0x6d, 0x69, 0x63, /* in the taxonomic */
  15522. 0x20, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x20, 0x43, 0x61, 0x6e, 0x69, 0x64, 0x61, 0x65, 0x2e /* family Canidae. */
  15523. };
  15524. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15525. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15526. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15527. };
  15528. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15529. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15530. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58 }; /* PQRSTUVW */
  15531. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15532. 0x45, 0x59, 0xab, 0xba, 0x4e, 0x48, 0xc1, 0x61, 0x02, 0xe8, 0xbb, 0x2c, 0x05, 0xe6, 0x94, 0x7f,
  15533. 0x50, 0xa7, 0x86, 0xde, 0x16, 0x2f, 0x9b, 0x0b, 0x7e, 0x59, 0x2a, 0x9b, 0x53, 0xd0, 0xd4, 0xe9,
  15534. 0x8d, 0x8d, 0x64, 0x10, 0xd5, 0x40, 0xa1, 0xa6, 0x37, 0x5b, 0x26, 0xd8, 0x0d, 0xac, 0xe4, 0xfa,
  15535. 0xb5, 0x23, 0x84, 0xc7, 0x31, 0xac, 0xbf, 0x16, 0xa5, 0x92, 0x3c, 0x0c, 0x48, 0xd3, 0x57, 0x5d,
  15536. 0x4d, 0x0d, 0x2c, 0x67, 0x3b, 0x66, 0x6f, 0xaa, 0x73, 0x10, 0x61, 0x27, 0x77, 0x01, 0x09, 0x3a,
  15537. 0x6b, 0xf7, 0xa1, 0x58, 0xa8, 0x86, 0x42, 0x92, 0xa4, 0x1c, 0x48, 0xe3, 0xa9, 0xb4, 0xc0, 0xda,
  15538. 0xec, 0xe0, 0xf8, 0xd9, 0x8d, 0x0d, 0x7e, 0x05, 0xb3, 0x7a, 0x30, 0x7b, 0xbb, 0x66, 0x33, 0x31,
  15539. 0x64, 0xec, 0x9e, 0x1b, 0x24, 0xea, 0x0d, 0x6c, 0x3f, 0xfd, 0xdc, 0xec, 0x4f, 0x68, 0xe7, 0x44,
  15540. 0x30, 0x56, 0x19, 0x3a, 0x03, 0xc8, 0x10, 0xe1, 0x13, 0x44, 0xca, 0x06, 0xd8, 0xed, 0x8a, 0x2b,
  15541. 0xfb, 0x1e, 0x8d, 0x48, 0xcf, 0xa6, 0xbc, 0x0e, 0xb4, 0xe2, 0x46, 0x4b, 0x74, 0x81, 0x42, 0x40,
  15542. 0x7c, 0x9f, 0x43, 0x1a, 0xee, 0x76, 0x99, 0x60, 0xe1, 0x5b, 0xa8, 0xb9, 0x68, 0x90, 0x46, 0x6e,
  15543. 0xf2, 0x45, 0x75, 0x99, 0x85, 0x23, 0x85, 0xc6, 0x61, 0xf7, 0x52, 0xce, 0x20, 0xf9, 0xda, 0x0c,
  15544. 0x09, 0xab, 0x6b, 0x19, 0xdf, 0x74, 0xe7, 0x6a, 0x95, 0x96, 0x74, 0x46, 0xf8, 0xd0, 0xfd, 0x41,
  15545. 0x5e, 0x7b, 0xee, 0x2a, 0x12, 0xa1, 0x14, 0xc2, 0x0e, 0xb5, 0x29, 0x2a, 0xe7, 0xa3, 0x49, 0xae,
  15546. 0x57, 0x78, 0x20, 0xd5, 0x52, 0x0a, 0x1f, 0x3f, 0xb6, 0x2a, 0x17, 0xce, 0x6a, 0x7e, 0x68, 0xfa,
  15547. 0x7c, 0x79, 0x11, 0x1d, 0x88, 0x60, 0x92, 0x0b, 0xc0, 0x48, 0xef, 0x43, 0xfe, 0x84, 0x48, 0x6c,
  15548. 0xcb, 0x87, 0xc2, 0x5f, 0x0a, 0xe0, 0x45, 0xf0, 0xcc, 0xe1, 0xe7, 0x98, 0x9a, 0x9a, 0xa2, 0x20,
  15549. 0xa2, 0x8b, 0xdd, 0x48, 0x27, 0xe7, 0x51, 0xa2, 0x4a, 0x6d, 0x5c, 0x62, 0xd7, 0x90, 0xa6, 0x63,
  15550. 0x93, 0xb9, 0x31, 0x11, 0xc1, 0xa5, 0x5d, 0xd7, 0x42, 0x1a, 0x10, 0x18, 0x49, 0x74, 0xc7, 0xc5
  15551. };
  15552. wc_test_ret_t ret;
  15553. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15554. struct ChaCha *chacha = (struct ChaCha *)XMALLOC(sizeof *chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15555. byte *buf1 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15556. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15557. WOLFSSL_ENTER("XChaCha_test");
  15558. if ((chacha == NULL) || (buf1 == NULL) || (buf2 == NULL))
  15559. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15560. #else
  15561. struct ChaCha chacha[1];
  15562. byte buf1[sizeof Plaintext];
  15563. byte buf2[sizeof Plaintext];
  15564. WOLFSSL_ENTER("XChaCha_test");
  15565. #endif
  15566. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15567. if (ret < 0)
  15568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15569. ret = wc_Chacha_Process(chacha, buf1, Plaintext, sizeof Plaintext);
  15570. if (ret < 0)
  15571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15572. if (XMEMCMP(buf1, Ciphertext, sizeof Plaintext))
  15573. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15574. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15575. if (ret < 0)
  15576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15577. ret = wc_Chacha_Process(chacha, buf2, buf1, sizeof Plaintext);
  15578. if (ret < 0)
  15579. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15580. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15581. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15582. out:
  15583. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15584. XFREE(chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15585. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15586. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15587. #endif
  15588. return ret;
  15589. }
  15590. #endif /* HAVE_XCHACHA */
  15591. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  15592. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void) {
  15593. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15594. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, /* Ladies and Gentl */
  15595. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, /* emen of the clas */
  15596. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, /* s of '99: If I c */
  15597. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, /* ould offer you o */
  15598. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, /* nly one tip for */
  15599. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, /* the future, suns */
  15600. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, /* creen would be i */
  15601. 0x74, 0x2e }; /* t. */
  15602. WOLFSSL_SMALL_STACK_STATIC const byte AAD[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; /* PQRS........ */
  15603. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15604. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15605. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15606. };
  15607. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15608. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15609. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }; /* PQRSTUVW */
  15610. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15611. 0xbd, 0x6d, 0x17, 0x9d, 0x3e, 0x83, 0xd4, 0x3b, 0x95, 0x76, 0x57, 0x94, 0x93, 0xc0, 0xe9, 0x39,
  15612. 0x57, 0x2a, 0x17, 0x00, 0x25, 0x2b, 0xfa, 0xcc, 0xbe, 0xd2, 0x90, 0x2c, 0x21, 0x39, 0x6c, 0xbb,
  15613. 0x73, 0x1c, 0x7f, 0x1b, 0x0b, 0x4a, 0xa6, 0x44, 0x0b, 0xf3, 0xa8, 0x2f, 0x4e, 0xda, 0x7e, 0x39,
  15614. 0xae, 0x64, 0xc6, 0x70, 0x8c, 0x54, 0xc2, 0x16, 0xcb, 0x96, 0xb7, 0x2e, 0x12, 0x13, 0xb4, 0x52,
  15615. 0x2f, 0x8c, 0x9b, 0xa4, 0x0d, 0xb5, 0xd9, 0x45, 0xb1, 0x1b, 0x69, 0xb9, 0x82, 0xc1, 0xbb, 0x9e,
  15616. 0x3f, 0x3f, 0xac, 0x2b, 0xc3, 0x69, 0x48, 0x8f, 0x76, 0xb2, 0x38, 0x35, 0x65, 0xd3, 0xff, 0xf9,
  15617. 0x21, 0xf9, 0x66, 0x4c, 0x97, 0x63, 0x7d, 0xa9, 0x76, 0x88, 0x12, 0xf6, 0x15, 0xc6, 0x8b, 0x13,
  15618. 0xb5, 0x2e };
  15619. WOLFSSL_SMALL_STACK_STATIC const byte Tag[] = {
  15620. 0xc0, 0x87, 0x59, 0x24, 0xc1, 0xc7, 0x98, 0x79, 0x47, 0xde, 0xaf, 0xd8, 0x78, 0x0a, 0xcf, 0x49
  15621. };
  15622. wc_test_ret_t ret;
  15623. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15624. byte *buf1 = (byte *)XMALLOC(sizeof Ciphertext + sizeof Tag, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15625. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15626. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15627. if ((buf1 == NULL) || (buf2 == NULL))
  15628. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15629. #else
  15630. byte buf1[sizeof Ciphertext + sizeof Tag];
  15631. byte buf2[sizeof Plaintext];
  15632. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15633. #endif
  15634. ret = wc_XChaCha20Poly1305_Encrypt(buf1, sizeof Ciphertext + sizeof Tag,
  15635. Plaintext, sizeof Plaintext,
  15636. AAD, sizeof AAD,
  15637. IV, sizeof IV,
  15638. Key, sizeof Key);
  15639. if (ret < 0)
  15640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15641. if (XMEMCMP(buf1, Ciphertext, sizeof Ciphertext))
  15642. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15643. if (XMEMCMP(buf1 + sizeof Ciphertext, Tag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE))
  15644. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15645. ret = wc_XChaCha20Poly1305_Decrypt(buf2, sizeof Plaintext,
  15646. buf1, sizeof Ciphertext + sizeof Tag,
  15647. AAD, sizeof AAD,
  15648. IV, sizeof IV,
  15649. Key, sizeof Key);
  15650. if (ret < 0)
  15651. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15652. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15653. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15654. out:
  15655. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15656. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15657. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15658. #endif
  15659. return ret;
  15660. }
  15661. #endif /* defined(HAVE_XCHACHA) && defined(HAVE_POLY1305) */
  15662. #ifndef WC_NO_RNG
  15663. static wc_test_ret_t _rng_test(WC_RNG* rng)
  15664. {
  15665. byte block[32];
  15666. wc_test_ret_t ret;
  15667. int i;
  15668. XMEMSET(block, 0, sizeof(block));
  15669. ret = wc_RNG_GenerateBlock(rng, block, sizeof(block));
  15670. if (ret != 0) {
  15671. return WC_TEST_RET_ENC_EC(ret);
  15672. }
  15673. /* Check for 0's */
  15674. for (i=0; i<(int)sizeof(block); i++) {
  15675. if (block[i] == 0) {
  15676. ret++;
  15677. }
  15678. }
  15679. /* All zeros count check */
  15680. if (ret >= (int)sizeof(block)) {
  15681. return WC_TEST_RET_ENC_NC;
  15682. }
  15683. ret = wc_RNG_GenerateByte(rng, block);
  15684. if (ret != 0) {
  15685. return WC_TEST_RET_ENC_EC(ret);
  15686. }
  15687. /* Parameter validation testing. */
  15688. ret = wc_RNG_GenerateBlock(NULL, block, sizeof(block));
  15689. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15690. return WC_TEST_RET_ENC_EC(ret);
  15691. }
  15692. ret = wc_RNG_GenerateBlock(rng, NULL, sizeof(block));
  15693. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15694. return WC_TEST_RET_ENC_EC(ret);
  15695. }
  15696. ret = wc_RNG_GenerateByte(NULL, block);
  15697. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15698. return WC_TEST_RET_ENC_EC(ret);
  15699. }
  15700. ret = wc_RNG_GenerateByte(rng, NULL);
  15701. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15702. return WC_TEST_RET_ENC_EC(ret);
  15703. }
  15704. return 0;
  15705. }
  15706. static wc_test_ret_t random_rng_test(void)
  15707. {
  15708. WC_RNG localRng;
  15709. WC_RNG* rng;
  15710. wc_test_ret_t ret;
  15711. rng = &localRng;
  15712. /* Test stack based RNG. */
  15713. #ifndef HAVE_FIPS
  15714. ret = wc_InitRng_ex(rng, HEAP_HINT, devId);
  15715. #else
  15716. ret = wc_InitRng(rng);
  15717. #endif
  15718. if (ret != 0)
  15719. return WC_TEST_RET_ENC_EC(ret);
  15720. ret = _rng_test(rng);
  15721. /* Make sure and free RNG */
  15722. wc_FreeRng(rng);
  15723. if (ret != 0)
  15724. return ret;
  15725. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
  15726. {
  15727. byte nonce[8] = { 0 };
  15728. /* Test dynamic RNG */
  15729. rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
  15730. if (rng == NULL)
  15731. return WC_TEST_RET_ENC_ERRNO;
  15732. ret = _rng_test(rng);
  15733. wc_rng_free(rng);
  15734. rng = NULL;
  15735. if (ret != 0)
  15736. return ret;
  15737. /* Test dynamic RNG using extended API */
  15738. ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
  15739. HEAP_HINT, devId);
  15740. if (ret != 0)
  15741. return WC_TEST_RET_ENC_EC(ret);
  15742. ret = _rng_test(rng);
  15743. wc_rng_free(rng);
  15744. if (ret != 0)
  15745. return ret;
  15746. }
  15747. #endif
  15748. return ret;
  15749. }
  15750. #if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  15751. #ifdef WC_RNG_SEED_CB
  15752. static int seed_cb(OS_Seed* os, byte* output, word32 sz)
  15753. {
  15754. word32 i;
  15755. (void)os;
  15756. /* Known answer test. Set the seed to the same value every time. */
  15757. for (i = 0; i < sz; i++)
  15758. output[i] = (byte)i;
  15759. return 0;
  15760. }
  15761. static wc_test_ret_t rng_seed_test(void)
  15762. {
  15763. #ifndef HAVE_FIPS
  15764. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15765. {
  15766. 0x83, 0x46, 0x65, 0x2f, 0x5c, 0x44, 0x16, 0x5f,
  15767. 0xb3, 0x89, 0x26, 0xde, 0x0b, 0x6b, 0xa2, 0x06,
  15768. 0x7e, 0xa7, 0x9a, 0x55, 0x22, 0x01, 0xb0, 0x22,
  15769. 0xf4, 0x7e, 0xa2, 0x66, 0xc4, 0x08, 0x6f, 0xba
  15770. };
  15771. #else
  15772. /* FIPS uses a longer seed, so different check value. */
  15773. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15774. {
  15775. 0xaf, 0x31, 0xcc, 0xef, 0xa9, 0x29, 0x4c, 0x24,
  15776. 0xbd, 0xa5, 0xa3, 0x52, 0x69, 0xf3, 0xb9, 0xb2,
  15777. 0x1e, 0xd4, 0x52, 0x3b, 0x9a, 0x96, 0x06, 0x20,
  15778. 0xc0, 0x5f, 0x44, 0x06, 0x1f, 0x80, 0xdf, 0xe0
  15779. };
  15780. #endif
  15781. byte output[WC_SHA256_DIGEST_SIZE];
  15782. WC_RNG rng;
  15783. wc_test_ret_t ret;
  15784. ret = wc_SetSeed_Cb(seed_cb);
  15785. if (ret != 0) {
  15786. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15787. }
  15788. ret = wc_InitRng(&rng);
  15789. if (ret != 0) {
  15790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15791. }
  15792. ret = wc_RNG_GenerateBlock(&rng, output, sizeof(output));
  15793. if (ret != 0) {
  15794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15795. }
  15796. ret = XMEMCMP(output, check, sizeof(output));
  15797. if (ret != 0) {
  15798. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15799. }
  15800. ret = wc_FreeRng(&rng);
  15801. if (ret != 0) {
  15802. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15803. }
  15804. ret = wc_SetSeed_Cb(wc_GenerateSeed);
  15805. if (ret != 0) {
  15806. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15807. }
  15808. out:
  15809. return ret;
  15810. }
  15811. #endif
  15812. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15813. {
  15814. WOLFSSL_SMALL_STACK_STATIC const byte test1Entropy[] =
  15815. {
  15816. 0xa6, 0x5a, 0xd0, 0xf3, 0x45, 0xdb, 0x4e, 0x0e, 0xff, 0xe8, 0x75, 0xc3,
  15817. 0xa2, 0xe7, 0x1f, 0x42, 0xc7, 0x12, 0x9d, 0x62, 0x0f, 0xf5, 0xc1, 0x19,
  15818. 0xa9, 0xef, 0x55, 0xf0, 0x51, 0x85, 0xe0, 0xfb, 0x85, 0x81, 0xf9, 0x31,
  15819. 0x75, 0x17, 0x27, 0x6e, 0x06, 0xe9, 0x60, 0x7d, 0xdb, 0xcb, 0xcc, 0x2e
  15820. };
  15821. WOLFSSL_SMALL_STACK_STATIC const byte test1Output[] =
  15822. {
  15823. 0xd3, 0xe1, 0x60, 0xc3, 0x5b, 0x99, 0xf3, 0x40, 0xb2, 0x62, 0x82, 0x64,
  15824. 0xd1, 0x75, 0x10, 0x60, 0xe0, 0x04, 0x5d, 0xa3, 0x83, 0xff, 0x57, 0xa5,
  15825. 0x7d, 0x73, 0xa6, 0x73, 0xd2, 0xb8, 0xd8, 0x0d, 0xaa, 0xf6, 0xa6, 0xc3,
  15826. 0x5a, 0x91, 0xbb, 0x45, 0x79, 0xd7, 0x3f, 0xd0, 0xc8, 0xfe, 0xd1, 0x11,
  15827. 0xb0, 0x39, 0x13, 0x06, 0x82, 0x8a, 0xdf, 0xed, 0x52, 0x8f, 0x01, 0x81,
  15828. 0x21, 0xb3, 0xfe, 0xbd, 0xc3, 0x43, 0xe7, 0x97, 0xb8, 0x7d, 0xbb, 0x63,
  15829. 0xdb, 0x13, 0x33, 0xde, 0xd9, 0xd1, 0xec, 0xe1, 0x77, 0xcf, 0xa6, 0xb7,
  15830. 0x1f, 0xe8, 0xab, 0x1d, 0xa4, 0x66, 0x24, 0xed, 0x64, 0x15, 0xe5, 0x1c,
  15831. 0xcd, 0xe2, 0xc7, 0xca, 0x86, 0xe2, 0x83, 0x99, 0x0e, 0xea, 0xeb, 0x91,
  15832. 0x12, 0x04, 0x15, 0x52, 0x8b, 0x22, 0x95, 0x91, 0x02, 0x81, 0xb0, 0x2d,
  15833. 0xd4, 0x31, 0xf4, 0xc9, 0xf7, 0x04, 0x27, 0xdf
  15834. };
  15835. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyA[] =
  15836. {
  15837. 0x63, 0x36, 0x33, 0x77, 0xe4, 0x1e, 0x86, 0x46, 0x8d, 0xeb, 0x0a, 0xb4,
  15838. 0xa8, 0xed, 0x68, 0x3f, 0x6a, 0x13, 0x4e, 0x47, 0xe0, 0x14, 0xc7, 0x00,
  15839. 0x45, 0x4e, 0x81, 0xe9, 0x53, 0x58, 0xa5, 0x69, 0x80, 0x8a, 0xa3, 0x8f,
  15840. 0x2a, 0x72, 0xa6, 0x23, 0x59, 0x91, 0x5a, 0x9f, 0x8a, 0x04, 0xca, 0x68
  15841. };
  15842. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyB[] =
  15843. {
  15844. 0xe6, 0x2b, 0x8a, 0x8e, 0xe8, 0xf1, 0x41, 0xb6, 0x98, 0x05, 0x66, 0xe3,
  15845. 0xbf, 0xe3, 0xc0, 0x49, 0x03, 0xda, 0xd4, 0xac, 0x2c, 0xdf, 0x9f, 0x22,
  15846. 0x80, 0x01, 0x0a, 0x67, 0x39, 0xbc, 0x83, 0xd3
  15847. };
  15848. WOLFSSL_SMALL_STACK_STATIC const byte test2Output[] =
  15849. {
  15850. 0x04, 0xee, 0xc6, 0x3b, 0xb2, 0x31, 0xdf, 0x2c, 0x63, 0x0a, 0x1a, 0xfb,
  15851. 0xe7, 0x24, 0x94, 0x9d, 0x00, 0x5a, 0x58, 0x78, 0x51, 0xe1, 0xaa, 0x79,
  15852. 0x5e, 0x47, 0x73, 0x47, 0xc8, 0xb0, 0x56, 0x62, 0x1c, 0x18, 0xbd, 0xdc,
  15853. 0xdd, 0x8d, 0x99, 0xfc, 0x5f, 0xc2, 0xb9, 0x20, 0x53, 0xd8, 0xcf, 0xac,
  15854. 0xfb, 0x0b, 0xb8, 0x83, 0x12, 0x05, 0xfa, 0xd1, 0xdd, 0xd6, 0xc0, 0x71,
  15855. 0x31, 0x8a, 0x60, 0x18, 0xf0, 0x3b, 0x73, 0xf5, 0xed, 0xe4, 0xd4, 0xd0,
  15856. 0x71, 0xf9, 0xde, 0x03, 0xfd, 0x7a, 0xea, 0x10, 0x5d, 0x92, 0x99, 0xb8,
  15857. 0xaf, 0x99, 0xaa, 0x07, 0x5b, 0xdb, 0x4d, 0xb9, 0xaa, 0x28, 0xc1, 0x8d,
  15858. 0x17, 0x4b, 0x56, 0xee, 0x2a, 0x01, 0x4d, 0x09, 0x88, 0x96, 0xff, 0x22,
  15859. 0x82, 0xc9, 0x55, 0xa8, 0x19, 0x69, 0xe0, 0x69, 0xfa, 0x8c, 0xe0, 0x07,
  15860. 0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17
  15861. };
  15862. byte output[WC_SHA256_DIGEST_SIZE * 4];
  15863. wc_test_ret_t ret;
  15864. WOLFSSL_ENTER("random_test");
  15865. ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
  15866. output, sizeof(output));
  15867. if (ret != 0)
  15868. return WC_TEST_RET_ENC_EC(ret);
  15869. if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
  15870. return WC_TEST_RET_ENC_NC;
  15871. ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
  15872. test2EntropyB, sizeof(test2EntropyB),
  15873. output, sizeof(output));
  15874. if (ret != 0)
  15875. return WC_TEST_RET_ENC_EC(ret);
  15876. if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
  15877. return WC_TEST_RET_ENC_NC;
  15878. /* Basic RNG generate block test */
  15879. if ((ret = random_rng_test()) != 0)
  15880. return ret;
  15881. /* Test the seed check function. */
  15882. #if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
  15883. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  15884. {
  15885. word32 i, outputSz;
  15886. /* Repeat the same byte over and over. Should fail. */
  15887. outputSz = sizeof(output);
  15888. XMEMSET(output, 1, outputSz);
  15889. ret = wc_RNG_TestSeed(output, outputSz);
  15890. if (ret == 0)
  15891. return WC_TEST_RET_ENC_NC;
  15892. /* Every byte of the entropy scratch is different,
  15893. * entropy is a single byte that shouldn't match. */
  15894. outputSz = (sizeof(output) / 2) + 1;
  15895. for (i = 0; i < outputSz; i++)
  15896. output[i] = (byte)i;
  15897. ret = wc_RNG_TestSeed(output, outputSz);
  15898. if (ret != 0)
  15899. return WC_TEST_RET_ENC_EC(ret);
  15900. outputSz = sizeof(output);
  15901. for (i = 0; i < outputSz; i++)
  15902. output[i] = (byte)i;
  15903. ret = wc_RNG_TestSeed(output, outputSz);
  15904. if (ret != 0)
  15905. return WC_TEST_RET_ENC_EC(ret);
  15906. }
  15907. #endif
  15908. /* Test the seed callback. */
  15909. #ifdef WC_RNG_SEED_CB
  15910. if ((ret = rng_seed_test()) != 0)
  15911. return ret;
  15912. #endif
  15913. return 0;
  15914. }
  15915. #else
  15916. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15917. {
  15918. WOLFSSL_ENTER("random_test");
  15919. /* Basic RNG generate block test */
  15920. return random_rng_test();
  15921. }
  15922. #endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
  15923. #endif /* WC_NO_RNG */
  15924. #ifndef MEM_TEST_SZ
  15925. #define MEM_TEST_SZ 1024
  15926. #endif
  15927. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15928. static int simple_mem_test(size_t sz)
  15929. {
  15930. int ret = 0;
  15931. byte* b;
  15932. int i;
  15933. b = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15934. if (b == NULL) {
  15935. return WC_TEST_RET_ENC_NC;
  15936. }
  15937. /* utilize memory */
  15938. for (i = 0; i < (int)sz; i++) {
  15939. b[i] = (byte)i;
  15940. }
  15941. /* read back and verify */
  15942. for (i = 0; i < (int)sz; i++) {
  15943. if (b[i] != (byte)i) {
  15944. ret = WC_TEST_RET_ENC_NC;
  15945. break;
  15946. }
  15947. }
  15948. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15949. return ret;
  15950. }
  15951. #endif
  15952. /* If successful, returns the first letter of the byte array `in`.
  15953. **
  15954. ** This is a deceptively simple test of a read-only embedded Linux file system.
  15955. ** (e.g CFLAGS `-mfdpic` and `-mforce-l32`) for Xtensa Linux ESP32. When the
  15956. ** `-mforce-l32` is missing, access to `in` will fail with Illegal Instruction.
  15957. ** Const is on read-only memory-mapped file system, *not* loaded in app memory.
  15958. **
  15959. ** Edit with caution. See PR #6523. */
  15960. static wc_test_ret_t const_byte_ptr_test(const byte* in, word32 *outJ)
  15961. {
  15962. wc_test_ret_t ret = 0;
  15963. volatile word32 j = (word32)-1; /* must be volatile to properly detect error */
  15964. ret = (wc_test_ret_t)*in; /* accessed *in value. */
  15965. (void)ret;
  15966. j = *outJ; /* Found index to use in const array. */
  15967. if (j == 0) {
  15968. #ifdef WOLFSSL_DEBUG
  15969. printf("Testing const byte ptr reference...\n");
  15970. #endif
  15971. /* although j is zero, in[0] does not detect the Illegal instruction */
  15972. ret = in[j]; /* The big test: can we actually access the `in` data? */
  15973. }
  15974. else {
  15975. ret = WC_TEST_RET_ENC_I(j);
  15976. }
  15977. return ret;
  15978. }
  15979. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
  15980. {
  15981. wc_test_ret_t ret = 0;
  15982. word32 j = 0; /* used in embedded const pointer test */
  15983. WOLFSSL_ENTER("memory_test");
  15984. #if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY)
  15985. int i;
  15986. #endif
  15987. #ifdef WOLFSSL_STATIC_MEMORY
  15988. word32 size[] = { WOLFMEM_BUCKETS };
  15989. word32 dist[] = { WOLFMEM_DIST };
  15990. byte buffer[30000]; /* make large enough to involve many bucket sizes */
  15991. int pad = -(int)((wc_ptr_t)buffer) & (WOLFSSL_STATIC_ALIGN - 1);
  15992. /* pad to account for if head of buffer is not at set memory
  15993. * alignment when tests are ran */
  15994. #endif
  15995. #ifdef WOLFSSL_STATIC_MEMORY
  15996. /* check macro settings */
  15997. if (sizeof(size)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15998. return WC_TEST_RET_ENC_NC;
  15999. }
  16000. if (sizeof(dist)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  16001. return WC_TEST_RET_ENC_NC;
  16002. }
  16003. if (WOLFMEM_DEF_BUCKETS > WOLFMEM_MAX_BUCKETS) {
  16004. return WC_TEST_RET_ENC_NC;
  16005. }
  16006. for (i = 0; i < WOLFMEM_DEF_BUCKETS; i++) {
  16007. if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) {
  16008. /* each element in array should be divisible by alignment size */
  16009. return WC_TEST_RET_ENC_NC;
  16010. }
  16011. }
  16012. for (i = 1; i < WOLFMEM_DEF_BUCKETS; i++) {
  16013. if (size[i - 1] >= size[i]) {
  16014. return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */
  16015. }
  16016. }
  16017. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  16018. /* check that padding size returned is possible */
  16019. if (wolfSSL_MemoryPaddingSz() < WOLFSSL_STATIC_ALIGN) {
  16020. return WC_TEST_RET_ENC_NC; /* no room for wc_Memory struct */
  16021. }
  16022. ret = wolfSSL_MemoryPaddingSz();
  16023. if (ret < 0) {
  16024. return WC_TEST_RET_ENC_EC(ret);
  16025. }
  16026. if (wolfSSL_MemoryPaddingSz() % WOLFSSL_STATIC_ALIGN != 0) {
  16027. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16028. }
  16029. /* check function to return optimum buffer size (rounded down) */
  16030. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_GENERAL);
  16031. if (ret < 0) {
  16032. return WC_TEST_RET_ENC_EC(ret);
  16033. }
  16034. if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) {
  16035. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16036. }
  16037. if ((unsigned int)ret > sizeof(buffer)) {
  16038. return WC_TEST_RET_ENC_NC; /* did not round down as expected */
  16039. }
  16040. if (ret != wolfSSL_StaticBufferSz(buffer, ret, WOLFMEM_GENERAL)) {
  16041. return WC_TEST_RET_ENC_NC; /* return value changed when using suggested
  16042. * value
  16043. */
  16044. }
  16045. ret = wolfSSL_MemoryPaddingSz();
  16046. ret += pad; /* add space that is going to be needed if buffer not aligned */
  16047. if (wolfSSL_StaticBufferSz(buffer, size[0] + ret + 1, WOLFMEM_GENERAL) !=
  16048. (ret + (int)size[0])) {
  16049. return WC_TEST_RET_ENC_NC; /* did not round down to nearest bucket
  16050. * value
  16051. */
  16052. }
  16053. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_IO_POOL);
  16054. if ((ret - pad) < 0) {
  16055. return WC_TEST_RET_ENC_NC;
  16056. }
  16057. if (((ret - pad) % (WOLFMEM_IO_SZ + wolfSSL_MemoryPaddingSz())) != 0) {
  16058. return WC_TEST_RET_ENC_NC; /* not even chunks of memory for IO size */
  16059. }
  16060. if (((ret - pad) % WOLFSSL_STATIC_ALIGN) != 0) {
  16061. return WC_TEST_RET_ENC_NC; /* memory not aligned */
  16062. }
  16063. /* check for passing bad or unknown arguments to functions */
  16064. if (wolfSSL_StaticBufferSz(NULL, 1, WOLFMEM_GENERAL) > 0) {
  16065. return WC_TEST_RET_ENC_NC;
  16066. }
  16067. if (wolfSSL_StaticBufferSz(buffer, 1, WOLFMEM_GENERAL) != 0) {
  16068. return WC_TEST_RET_ENC_NC; /* should round to 0
  16069. since struct + bucket will not fit */
  16070. }
  16071. #endif
  16072. (void)pad;
  16073. (void)dist; /* avoid static analysis warning of variable not used */
  16074. #endif
  16075. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  16076. /* simple test */
  16077. ret = simple_mem_test((size_t)MEM_TEST_SZ);
  16078. if (ret != 0)
  16079. return ret;
  16080. #endif
  16081. #ifdef COMPLEX_MEM_TEST
  16082. /* test various size blocks */
  16083. for (i = 1; i < MEM_TEST_SZ; i*=2) {
  16084. ret = simple_mem_test((size_t)i);
  16085. if (ret != 0)
  16086. return ret;
  16087. }
  16088. #endif
  16089. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) && defined(XREALLOC)
  16090. /* realloc test */
  16091. {
  16092. byte *b = (byte*)XMALLOC(MEM_TEST_SZ, HEAP_HINT,
  16093. DYNAMIC_TYPE_TMP_BUFFER);
  16094. #ifndef WOLFSSL_NO_REALLOC
  16095. byte *c = NULL;
  16096. if (b) {
  16097. c = (byte*)XREALLOC(b, MEM_TEST_SZ+sizeof(word32), HEAP_HINT,
  16098. DYNAMIC_TYPE_TMP_BUFFER);
  16099. if (c)
  16100. b = c;
  16101. }
  16102. #endif
  16103. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16104. if (b == NULL
  16105. #ifndef WOLFSSL_NO_REALLOC
  16106. || c == NULL
  16107. #endif
  16108. ) {
  16109. return WC_TEST_RET_ENC_ERRNO;
  16110. }
  16111. }
  16112. #endif
  16113. if (ret == 0) {
  16114. /* This test is only interesting on embedded R/O Flash systems */
  16115. if (const_byte_ptr_test(const_byte_array, &j) != CBPTR_EXPECTED) {
  16116. ret = 1;
  16117. }
  16118. }
  16119. return ret;
  16120. }
  16121. #ifndef NO_FILESYSTEM
  16122. /* Cert Paths */
  16123. #ifdef FREESCALE_MQX
  16124. #define CERT_PREFIX "a:\\"
  16125. #define CERT_PATH_SEP "\\"
  16126. #elif defined(WOLFSSL_uTKERNEL2)
  16127. #define CERT_PREFIX "/uda/"
  16128. #define CERT_PATH_SEP "/"
  16129. #elif defined(_WIN32_WCE)
  16130. #define CERT_PREFIX "\\windows\\"
  16131. #define CERT_PATH_SEP "\\"
  16132. #elif defined(WOLFSSL_NDS)
  16133. #undef CERT_PREFIX
  16134. #ifndef WOLFSSL_MELONDS
  16135. #define CERT_PREFIX "fat:/_nds/"
  16136. #else
  16137. #define CERT_PREFIX "_nds/"
  16138. #endif
  16139. #define CERT_PATH_SEP "/"
  16140. #endif
  16141. #ifndef CERT_PREFIX
  16142. #define CERT_PREFIX "./"
  16143. #endif
  16144. #ifndef CERT_PATH_SEP
  16145. #define CERT_PATH_SEP "/"
  16146. #endif
  16147. #ifndef CERT_WRITE_TEMP_DIR
  16148. #define CERT_WRITE_TEMP_DIR CERT_PREFIX
  16149. #endif
  16150. #define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
  16151. /* Generated Test Certs */
  16152. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16153. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16154. #if !defined(NO_RSA) && !defined(NO_ASN)
  16155. static const char* clientKey = CERT_ROOT "client-key.der";
  16156. static const char* clientCert = CERT_ROOT "client-cert.der";
  16157. #ifdef WOLFSSL_CERT_EXT
  16158. static const char* clientKeyPub = CERT_ROOT "client-keyPub.der";
  16159. #endif
  16160. #endif /* !NO_RSA && !NO_ASN */
  16161. #endif
  16162. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16163. #if !defined(NO_RSA) && !defined(NO_ASN)
  16164. #if defined(WOLFSSL_CERT_GEN) || defined(HAVE_PKCS7)
  16165. static const char* rsaCaKeyFile = CERT_ROOT "ca-key.der";
  16166. #ifdef WOLFSSL_CERT_GEN
  16167. static const char* rsaCaCertFile = CERT_ROOT "ca-cert.pem";
  16168. #endif
  16169. #if (defined(WOLFSSL_ALT_NAMES) && !defined(WOLFSSL_NO_MALLOC)) || \
  16170. defined(HAVE_PKCS7)
  16171. static const char* rsaCaCertDerFile = CERT_ROOT "ca-cert.der";
  16172. #endif
  16173. #ifdef HAVE_PKCS7
  16174. static const char* rsaServerCertDerFile =
  16175. CERT_ROOT "server-cert.der";
  16176. static const char* rsaServerKeyDerFile =
  16177. CERT_ROOT "server-key.der";
  16178. #endif
  16179. #endif
  16180. #endif /* !NO_RSA && !NO_ASN */
  16181. #endif /* !USE_CERT_BUFFER_* */
  16182. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16183. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16184. #if !defined(NO_ASN) && !defined(NO_DH)
  16185. static const char* dhParamsFile = CERT_ROOT "dh2048.der";
  16186. #endif
  16187. #endif
  16188. #if !defined(NO_ASN) && !defined(NO_DH)
  16189. #if defined(WOLFSSL_DH_EXTRA) && (!defined(HAVE_FIPS) || \
  16190. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  16191. #if !defined(USE_CERT_BUFFERS_2048)
  16192. static const char* dhKeyFile = CERT_ROOT "statickeys/dh-ffdhe2048.der";
  16193. static const char* dhKeyPubFile = CERT_ROOT "statickeys/dh-ffdhe2048-pub.der";
  16194. #endif
  16195. #endif
  16196. #endif
  16197. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16198. #ifndef NO_DSA
  16199. static const char* dsaKey = CERT_ROOT "dsa2048.der";
  16200. #endif
  16201. #endif /* !USE_CERT_BUFFER_* */
  16202. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ECC256)
  16203. #ifdef HAVE_ECC
  16204. /* cert files to be used in rsa cert gen test, check if RSA enabled */
  16205. #ifdef HAVE_ECC_KEY_IMPORT
  16206. static const char* eccKeyDerFile = CERT_ROOT "ecc-key.der";
  16207. #endif
  16208. #endif
  16209. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN)
  16210. #if defined(HAVE_ECC) && defined(WOLFSSL_CERT_GEN) && \
  16211. !defined(NO_ECC_SECP)
  16212. #ifndef NO_RSA
  16213. static const char* eccKeyPubFileDer = CERT_ROOT "ecc-keyPub.der";
  16214. #endif
  16215. #if !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  16216. static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der";
  16217. static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem";
  16218. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16219. static const char* eccCaKey384File =
  16220. CERT_ROOT "ca-ecc384-key.der";
  16221. static const char* eccCaCert384File =
  16222. CERT_ROOT "ca-ecc384-cert.pem";
  16223. #endif
  16224. #endif
  16225. #endif
  16226. #if defined(HAVE_PKCS7) && defined(HAVE_ECC)
  16227. static const char* eccClientKey = CERT_ROOT "ecc-client-key.der";
  16228. static const char* eccClientCert = CERT_ROOT "client-ecc-cert.der";
  16229. #endif
  16230. #endif /* HAVE_ECC */
  16231. #ifdef HAVE_ED25519
  16232. #ifdef WOLFSSL_TEST_CERT
  16233. static const char* serverEd25519Cert =
  16234. CERT_ROOT "ed25519/server-ed25519.der";
  16235. static const char* caEd25519Cert =
  16236. CERT_ROOT "ed25519/ca-ed25519.der";
  16237. #endif
  16238. #endif
  16239. #ifdef HAVE_ED448
  16240. #ifdef WOLFSSL_TEST_CERT
  16241. static const char* serverEd448Cert =
  16242. CERT_ROOT "ed448/server-ed448.der";
  16243. static const char* caEd448Cert = CERT_ROOT "ed448/ca-ed448.der";
  16244. #endif
  16245. #endif
  16246. #endif /* !USE_CERT_BUFFER_* */
  16247. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16248. !defined(NO_FILESYSTEM)
  16249. static const char* certExtNc =
  16250. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nc.der";
  16251. static const char* certExtIa =
  16252. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-ia.der";
  16253. static const char* certExtNct =
  16254. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nct.der";
  16255. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16256. static const char* certBadNegInt =
  16257. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-neg-int.der";
  16258. #endif
  16259. static const char* certBadOid =
  16260. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-oid.der";
  16261. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16262. static const char* certBadUtf8 =
  16263. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-utf8.der";
  16264. #endif
  16265. #endif
  16266. #ifndef NO_WRITE_TEMP_FILES
  16267. #ifdef HAVE_ECC
  16268. #ifndef NO_ECC_SECP
  16269. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16270. !defined(WOLFSSL_NO_MALLOC)
  16271. static const char* certEccPemFile = CERT_WRITE_TEMP_DIR "certecc.pem";
  16272. static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der";
  16273. #endif
  16274. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  16275. static const char* certEccRsaPemFile = CERT_WRITE_TEMP_DIR "certeccrsa.pem";
  16276. static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der";
  16277. #endif
  16278. #endif
  16279. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  16280. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ASN_CRYPT)
  16281. static const char* eccCaKeyPemFile = CERT_WRITE_TEMP_DIR "ecc-key.pem";
  16282. static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der";
  16283. static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der";
  16284. #if defined(HAVE_PKCS8) && !defined(WC_NO_RNG) && \
  16285. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  16286. static const char* eccPkcs8KeyDerFile = CERT_WRITE_TEMP_DIR "ecc-key-pkcs8.der";
  16287. #endif
  16288. #endif /* HAVE_ECC_KEY_EXPORT */
  16289. #endif /* HAVE_ECC */
  16290. #ifndef NO_RSA
  16291. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16292. !defined(WOLFSSL_NO_MALLOC)
  16293. static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der";
  16294. static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der";
  16295. static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem";
  16296. static const char* certPemFile = CERT_WRITE_TEMP_DIR "cert.pem";
  16297. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  16298. static const char* certReqDerFile = CERT_WRITE_TEMP_DIR "certreq.der";
  16299. static const char* certReqPemFile = CERT_WRITE_TEMP_DIR "certreq.pem";
  16300. #endif
  16301. #endif
  16302. #endif /* !NO_RSA */
  16303. #if !defined(NO_RSA) || !defined(NO_DSA)
  16304. #ifdef WOLFSSL_KEY_GEN
  16305. static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
  16306. static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
  16307. #endif
  16308. #endif
  16309. #endif /* !NO_WRITE_TEMP_FILES */
  16310. #endif /* !NO_FILESYSTEM */
  16311. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  16312. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  16313. static CertName certDefaultName;
  16314. static void initDefaultName(void)
  16315. {
  16316. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16317. NameAttrib* n;
  16318. #endif
  16319. XMEMCPY(certDefaultName.country, "US", sizeof("US"));
  16320. certDefaultName.countryEnc = CTC_PRINTABLE;
  16321. XMEMCPY(certDefaultName.state, "Oregon", sizeof("Oregon"));
  16322. certDefaultName.stateEnc = CTC_UTF8;
  16323. XMEMCPY(certDefaultName.street, "Main St", sizeof("Main St"));
  16324. certDefaultName.streetEnc = CTC_UTF8;
  16325. XMEMCPY(certDefaultName.locality, "Portland", sizeof("Portland"));
  16326. certDefaultName.localityEnc = CTC_UTF8;
  16327. XMEMCPY(certDefaultName.sur, "Test", sizeof("Test"));
  16328. certDefaultName.surEnc = CTC_UTF8;
  16329. XMEMCPY(certDefaultName.org, "wolfSSL", sizeof("wolfSSL"));
  16330. certDefaultName.orgEnc = CTC_UTF8;
  16331. XMEMCPY(certDefaultName.unit, "Development", sizeof("Development"));
  16332. certDefaultName.unitEnc = CTC_UTF8;
  16333. XMEMCPY(certDefaultName.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  16334. certDefaultName.commonNameEnc = CTC_UTF8;
  16335. XMEMCPY(certDefaultName.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  16336. certDefaultName.serialDevEnc = CTC_PRINTABLE;
  16337. XMEMCPY(certDefaultName.postalCode, "12-456", sizeof("12-456"));
  16338. certDefaultName.postalCodeEnc = CTC_PRINTABLE;
  16339. #ifdef WOLFSSL_CERT_EXT
  16340. XMEMCPY(certDefaultName.busCat, "Private Organization", sizeof("Private Organization"));
  16341. certDefaultName.busCatEnc = CTC_UTF8;
  16342. XMEMCPY(certDefaultName.joiSt, "US", sizeof("US"));
  16343. certDefaultName.joiStEnc = CTC_PRINTABLE;
  16344. XMEMCPY(certDefaultName.joiC, "Oregon", sizeof("Oregon"));
  16345. certDefaultName.joiCEnc = CTC_PRINTABLE;
  16346. #endif
  16347. XMEMCPY(certDefaultName.email, "info@wolfssl.com", sizeof("info@wolfssl.com"));
  16348. XMEMCPY(certDefaultName.userId, "TestUserID", sizeof("TestUserID"));
  16349. certDefaultName.userIdEnc = CTC_PRINTABLE;
  16350. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16351. /* test having additional OUs and setting DC */
  16352. n = &certDefaultName.name[0];
  16353. n->id = ASN_ORGUNIT_NAME;
  16354. n->type = CTC_UTF8;
  16355. n->sz = XSTRLEN("Development-2");
  16356. XMEMCPY(n->value, "Development-2", sizeof("Development-2"));
  16357. #if CTC_MAX_ATTRIB > 3
  16358. n = &certDefaultName.name[1];
  16359. n->id = ASN_DOMAIN_COMPONENT;
  16360. n->type = CTC_UTF8;
  16361. n->sz = XSTRLEN("com");
  16362. XMEMCPY(n->value, "com", sizeof("com"));
  16363. n = &certDefaultName.name[2];
  16364. n->id = ASN_DOMAIN_COMPONENT;
  16365. n->type = CTC_UTF8;
  16366. n->sz = XSTRLEN("wolfssl");
  16367. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  16368. #endif
  16369. #endif /* WOLFSSL_MULTI_ATTRIB && WOLFSSL_TEST_CERT */
  16370. #ifdef WOLFSSL_CUSTOM_OID
  16371. /* TODO: Add test case for custom OID's */
  16372. #endif
  16373. }
  16374. #ifdef WOLFSSL_CERT_EXT
  16375. #if ((defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  16376. defined(WOLFSSL_TEST_CERT)) || defined(HAVE_ECC)
  16377. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage[] =
  16378. "digitalSignature,nonRepudiation";
  16379. #endif
  16380. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_ASN_TIME)
  16381. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage2[] =
  16382. "digitalSignature,nonRepudiation,keyEncipherment,keyAgreement";
  16383. #endif
  16384. #endif /* WOLFSSL_CERT_EXT */
  16385. #endif /* WOLFSSL_CERT_GEN */
  16386. #ifndef NO_RSA
  16387. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16388. !defined(NO_FILESYSTEM)
  16389. static const byte minSerial[] = { 0x02, 0x01, 0x01 };
  16390. static const byte minName[] = { 0x30, 0x00 };
  16391. static const byte nameBad[] = {
  16392. 0x30, 0x08,
  16393. 0x31, 0x06,
  16394. 0x30, 0x04,
  16395. 0x06, 0x02,
  16396. 0x55, 0x04,
  16397. };
  16398. static const byte minDates[] = {
  16399. 0x30, 0x1e,
  16400. 0x17, 0x0d,
  16401. 0x31, 0x38, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35,
  16402. 0x32, 0x33, 0x31, 0x30, 0x5a,
  16403. 0x17, 0x0d,
  16404. 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x31, 0x35,
  16405. 0x32, 0x33, 0x31, 0x30, 0x5a
  16406. };
  16407. static const byte minPubKey[] = {
  16408. 0x30, 0x1c,
  16409. 0x30, 0x0d,
  16410. 0x06, 0x09,
  16411. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16412. 0x01,
  16413. 0x05, 0x00,
  16414. 0x03, 0x0b,
  16415. 0x00, 0x30, 0x08,
  16416. 0x02, 0x01,
  16417. 0x03,
  16418. 0x02, 0x03,
  16419. 0x01, 0x00, 0x01
  16420. };
  16421. static const byte minSigAlg[] = {
  16422. 0x30, 0x0d,
  16423. 0x06, 0x09,
  16424. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16425. 0x0b,
  16426. 0x05, 0x00
  16427. };
  16428. static const byte minSig[] = {
  16429. 0x03, 0x01,
  16430. 0x00
  16431. };
  16432. static int add_seq(byte* certData, int offset, byte* data, byte length)
  16433. {
  16434. XMEMMOVE(certData + offset + 2, data, length);
  16435. certData[offset++] = 0x30;
  16436. certData[offset++] = length;
  16437. return offset + length;
  16438. }
  16439. static int add_data(byte* certData, int offset, const byte* data, byte length)
  16440. {
  16441. XMEMCPY(certData + offset, data, length);
  16442. return offset + length;
  16443. }
  16444. static wc_test_ret_t cert_asn1_test(void)
  16445. {
  16446. wc_test_ret_t ret;
  16447. int len[3];
  16448. DecodedCert cert;
  16449. byte certData[114];
  16450. byte* badCert = NULL;
  16451. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16452. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16453. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16454. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16455. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16456. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16457. len[1] = add_seq(certData, 0, certData, len[2]);
  16458. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16459. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16460. len[0] = add_seq(certData, 0, certData, len[1]);
  16461. /* Minimal good certificate */
  16462. InitDecodedCert(&cert, certData, len[0], 0);
  16463. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16464. FreeDecodedCert(&cert);
  16465. if (ret != 0)
  16466. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16467. /* Bad issuer name */
  16468. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16469. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16470. len[2] = add_data(certData, len[2], nameBad, (byte)sizeof(nameBad));
  16471. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16472. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16473. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16474. len[1] = add_seq(certData, 0, certData, len[2]);
  16475. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16476. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16477. len[0] = add_seq(certData, 0, certData, len[1]);
  16478. /* Put data into allocated buffer to allow access error checking. */
  16479. badCert = (byte*)XMALLOC(len[0], HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16480. XMEMCPY(badCert, certData, len[0]);
  16481. InitDecodedCert(&cert, badCert, len[0], 0);
  16482. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16483. FreeDecodedCert(&cert);
  16484. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  16485. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16486. }
  16487. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16488. badCert = NULL;
  16489. ret = 0;
  16490. done:
  16491. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16492. return ret;
  16493. }
  16494. static wc_test_ret_t cert_load_bad(const char* fname, byte* tmp, int err)
  16495. {
  16496. wc_test_ret_t ret;
  16497. DecodedCert cert;
  16498. XFILE file;
  16499. size_t bytes;
  16500. if ((fname == NULL) || (tmp == NULL)) {
  16501. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  16502. }
  16503. file = XFOPEN(fname, "rb");
  16504. if (!file) {
  16505. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16506. }
  16507. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16508. XFCLOSE(file);
  16509. if (bytes == 0) {
  16510. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16511. }
  16512. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16513. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16514. FreeDecodedCert(&cert);
  16515. if (ret != err) {
  16516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16517. }
  16518. ret = 0;
  16519. done:
  16520. return ret;
  16521. }
  16522. static wc_test_ret_t cert_bad_asn1_test(void)
  16523. {
  16524. wc_test_ret_t ret = 0;
  16525. byte* tmp;
  16526. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16527. if (tmp == NULL) {
  16528. ret = WC_TEST_RET_ENC_ERRNO;
  16529. }
  16530. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16531. if (ret == 0) {
  16532. /* Serial number: 0xff 0xa8. 0xff and top bit set on next byte invalid.
  16533. */
  16534. ret = cert_load_bad(certBadNegInt, tmp, ASN_EXPECT_0_E);
  16535. }
  16536. #endif
  16537. if (ret == 0) {
  16538. /* Subject name OID: 55 04 f4. Last byte with top bit set invalid. */
  16539. ret = cert_load_bad(certBadOid, tmp, ASN_PARSE_E);
  16540. }
  16541. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16542. if (ret == 0) {
  16543. /* Issuer name UTF8STRING: df 52 4e 44. Top bit of second byte not set.
  16544. */
  16545. ret = cert_load_bad(certBadUtf8, tmp, ASN_PARSE_E);
  16546. }
  16547. #endif
  16548. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16549. return ret;
  16550. }
  16551. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void)
  16552. {
  16553. #if !defined(NO_FILESYSTEM)
  16554. DecodedCert cert;
  16555. byte* tmp;
  16556. size_t bytes;
  16557. XFILE file;
  16558. wc_test_ret_t ret;
  16559. WOLFSSL_ENTER("cert_test");
  16560. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16561. if (tmp == NULL)
  16562. return WC_TEST_RET_ENC_ERRNO;
  16563. /* Certificate with Name Constraints extension. */
  16564. file = XFOPEN(certExtNc, "rb");
  16565. if (!file) {
  16566. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16567. }
  16568. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16569. XFCLOSE(file);
  16570. if (bytes == 0)
  16571. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16572. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16573. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16574. if (ret != 0)
  16575. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16576. FreeDecodedCert(&cert);
  16577. /* Certificate with Inhibit Any Policy extension. */
  16578. file = XFOPEN(certExtIa, "rb");
  16579. if (!file) {
  16580. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16581. }
  16582. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16583. XFCLOSE(file);
  16584. if (bytes == 0)
  16585. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16586. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16587. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16588. if (ret != 0)
  16589. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16590. FreeDecodedCert(&cert);
  16591. /* Certificate with Netscape Certificate Type extension. */
  16592. file = XFOPEN(certExtNct, "rb");
  16593. if (!file) {
  16594. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16595. }
  16596. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16597. XFCLOSE(file);
  16598. if (bytes == 0)
  16599. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16600. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16601. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16602. #ifndef IGNORE_NETSCAPE_CERT_TYPE
  16603. if (ret != 0)
  16604. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16605. #else
  16606. if (ret != WC_NO_ERR_TRACE(ASN_CRIT_EXT_E)) {
  16607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16608. }
  16609. ret = 0;
  16610. #endif
  16611. done:
  16612. FreeDecodedCert(&cert);
  16613. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16614. #endif /* !NO_FILESYSTEM */
  16615. if (ret == 0)
  16616. ret = cert_asn1_test();
  16617. if (ret == 0)
  16618. ret = cert_bad_asn1_test();
  16619. return ret;
  16620. }
  16621. #endif /* WOLFSSL_TEST_CERT */
  16622. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  16623. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  16624. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void)
  16625. {
  16626. DecodedCert cert;
  16627. byte* tmp;
  16628. size_t bytes;
  16629. XFILE file;
  16630. wc_test_ret_t ret;
  16631. /* created from rsa_test : othercert.der */
  16632. byte skid_rsa[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16633. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16634. /* created from rsa_test : othercert.der */
  16635. byte akid_rsa[] = "\x27\x8E\x67\x11\x74\xC3\x26\x1D\x3F\xED"
  16636. "\x33\x63\xB3\xA4\xD8\x1D\x30\xE5\xE8\xD5";
  16637. #ifdef HAVE_ECC
  16638. /* created from ecc_test_cert_gen : certecc.der */
  16639. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16640. /* Authority key id from ./certs/ca-ecc384-cert.pem */
  16641. byte akid_ecc[] = "\xAB\xE0\xC3\x26\x4C\x18\xD4\x72\xBB\xD2"
  16642. "\x84\x8C\x9C\x0A\x05\x92\x80\x12\x53\x52";
  16643. #else
  16644. /* Authority key id from ./certs/ca-ecc-cert.pem */
  16645. byte akid_ecc[] = "\x56\x8E\x9A\xC3\xF0\x42\xDE\x18\xB9\x45"
  16646. "\x55\x6E\xF9\x93\xCF\xEA\xC3\xF3\xA5\x21";
  16647. #endif
  16648. #endif /* HAVE_ECC */
  16649. /* created from rsa_test : cert.der */
  16650. byte kid_ca[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16651. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16652. WOLFSSL_ENTER("certext_test");
  16653. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16654. if (tmp == NULL)
  16655. return WC_TEST_RET_ENC_ERRNO;
  16656. /* load othercert.der (Cert signed by an authority) */
  16657. file = XFOPEN(otherCertDerFile, "rb");
  16658. if (!file) {
  16659. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16660. return WC_TEST_RET_ENC_ERRNO;
  16661. }
  16662. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16663. XFCLOSE(file);
  16664. if (bytes == 0)
  16665. return WC_TEST_RET_ENC_ERRNO;
  16666. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16667. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16668. if (ret != 0)
  16669. return WC_TEST_RET_ENC_EC(ret);
  16670. /* check the SKID from a RSA certificate */
  16671. if ((sizeof(skid_rsa) - 1 != cert.extSubjKeyIdSz) ||
  16672. (XMEMCMP(skid_rsa, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16673. return WC_TEST_RET_ENC_NC;
  16674. /* check the AKID from an RSA certificate */
  16675. if ((sizeof(akid_rsa) - 1 != cert.extAuthKeyIdSz) ||
  16676. (XMEMCMP(akid_rsa, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16677. return WC_TEST_RET_ENC_NC;
  16678. /* check the Key Usage from an RSA certificate */
  16679. if (!cert.extKeyUsageSet)
  16680. return WC_TEST_RET_ENC_NC;
  16681. if (cert.extKeyUsage != (KEYUSE_KEY_ENCIPHER|KEYUSE_KEY_AGREE))
  16682. return WC_TEST_RET_ENC_NC;
  16683. /* check the CA Basic Constraints from an RSA certificate */
  16684. if (cert.isCA)
  16685. return WC_TEST_RET_ENC_NC;
  16686. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16687. /* check the Certificate Policies Id */
  16688. if (cert.extCertPoliciesNb != 1)
  16689. return WC_TEST_RET_ENC_NC;
  16690. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16691. return WC_TEST_RET_ENC_NC;
  16692. #endif
  16693. FreeDecodedCert(&cert);
  16694. #ifdef HAVE_ECC
  16695. /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */
  16696. file = XFOPEN(certEccDerFile, "rb");
  16697. if (!file) {
  16698. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16699. return WC_TEST_RET_ENC_ERRNO;
  16700. }
  16701. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16702. XFCLOSE(file);
  16703. if (bytes == 0)
  16704. return WC_TEST_RET_ENC_ERRNO;
  16705. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16706. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16707. if (ret != 0)
  16708. return WC_TEST_RET_ENC_EC(ret);
  16709. /* check the SKID from a ECC certificate - generated dynamically */
  16710. /* check the AKID from an ECC certificate */
  16711. if ((sizeof(akid_ecc) - 1 != cert.extAuthKeyIdSz) ||
  16712. (XMEMCMP(akid_ecc, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16713. return WC_TEST_RET_ENC_NC;
  16714. /* check the Key Usage from an ECC certificate */
  16715. if (!cert.extKeyUsageSet)
  16716. return WC_TEST_RET_ENC_NC;
  16717. if (cert.extKeyUsage != (KEYUSE_DIGITAL_SIG|KEYUSE_CONTENT_COMMIT))
  16718. return WC_TEST_RET_ENC_NC;
  16719. /* check the CA Basic Constraints from an ECC certificate */
  16720. if (cert.isCA)
  16721. return WC_TEST_RET_ENC_NC;
  16722. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16723. /* check the Certificate Policies Id */
  16724. if (cert.extCertPoliciesNb != 2)
  16725. return WC_TEST_RET_ENC_NC;
  16726. if (strncmp(cert.extCertPolicies[0], "2.4.589440.587.101.2.1.9632587.1", 32))
  16727. return WC_TEST_RET_ENC_NC;
  16728. if (strncmp(cert.extCertPolicies[1], "1.2.13025.489.1.113549", 22))
  16729. return WC_TEST_RET_ENC_NC;
  16730. #endif
  16731. FreeDecodedCert(&cert);
  16732. #endif /* HAVE_ECC */
  16733. /* load cert.der (self signed certificate) */
  16734. file = XFOPEN(certDerFile, "rb");
  16735. if (!file) {
  16736. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16737. return WC_TEST_RET_ENC_ERRNO;
  16738. }
  16739. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16740. XFCLOSE(file);
  16741. if (bytes == 0)
  16742. return WC_TEST_RET_ENC_ERRNO;
  16743. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16744. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16745. if (ret != 0)
  16746. return WC_TEST_RET_ENC_EC(ret);
  16747. /* check the SKID from a CA certificate */
  16748. if ((sizeof(kid_ca) - 1 != cert.extSubjKeyIdSz) ||
  16749. (XMEMCMP(kid_ca, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16750. return WC_TEST_RET_ENC_NC;
  16751. /* check the AKID from an CA certificate */
  16752. if ((sizeof(kid_ca) - 1 != cert.extAuthKeyIdSz) ||
  16753. (XMEMCMP(kid_ca, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16754. return WC_TEST_RET_ENC_NC;
  16755. /* check the Key Usage from CA certificate */
  16756. if (!cert.extKeyUsageSet)
  16757. return WC_TEST_RET_ENC_NC;
  16758. if (cert.extKeyUsage != (KEYUSE_KEY_CERT_SIGN|KEYUSE_CRL_SIGN))
  16759. return WC_TEST_RET_ENC_NC;
  16760. /* check the CA Basic Constraints CA certificate */
  16761. if (!cert.isCA)
  16762. return WC_TEST_RET_ENC_NC;
  16763. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16764. /* check the Certificate Policies Id */
  16765. if (cert.extCertPoliciesNb != 2)
  16766. return WC_TEST_RET_ENC_NC;
  16767. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16768. return WC_TEST_RET_ENC_NC;
  16769. if (strncmp(cert.extCertPolicies[1], "1.2.840.113549.1.9.16.6.5", 25))
  16770. return WC_TEST_RET_ENC_NC;
  16771. #endif
  16772. FreeDecodedCert(&cert);
  16773. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16774. return 0;
  16775. }
  16776. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_TEST_CERT &&
  16777. !NO_FILESYSTEM && !NO_RSA && WOLFSSL_CERT_GEN */
  16778. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  16779. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  16780. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void)
  16781. {
  16782. wc_test_ret_t ret = 0;
  16783. Cert cert;
  16784. FILE* file;
  16785. byte* der;
  16786. word32 derSz;
  16787. WOLFSSL_ENTER("decodedCertCache_test");
  16788. derSz = FOURK_BUF;
  16789. der = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16790. if (der == NULL)
  16791. ret = WC_TEST_RET_ENC_NC;
  16792. if (ret == 0) {
  16793. /* load cert.der */
  16794. file = XFOPEN(certDerFile, "rb");
  16795. if (file != NULL) {
  16796. derSz = (word32)XFREAD(der, 1, FOURK_BUF, file);
  16797. XFCLOSE(file);
  16798. if (derSz == 0)
  16799. ret = WC_TEST_RET_ENC_ERRNO;
  16800. }
  16801. else
  16802. ret = WC_TEST_RET_ENC_ERRNO;
  16803. }
  16804. if (ret == 0) {
  16805. ret = wc_InitCert_ex(&cert, HEAP_HINT, devId);
  16806. if (ret != 0)
  16807. ret = WC_TEST_RET_ENC_EC(ret);
  16808. }
  16809. if (ret == 0) {
  16810. ret = wc_SetSubjectBuffer(&cert, der, derSz);
  16811. if (ret != 0)
  16812. ret = WC_TEST_RET_ENC_EC(ret);
  16813. }
  16814. if (ret == 0) {
  16815. ret = wc_SetSubjectBuffer(NULL, der, derSz);
  16816. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16817. ret = 0;
  16818. else
  16819. ret = WC_TEST_RET_ENC_EC(ret);
  16820. }
  16821. if (ret == 0) {
  16822. ret = wc_SetSubjectRaw(&cert, der, derSz);
  16823. if (ret != 0)
  16824. ret = WC_TEST_RET_ENC_EC(ret);
  16825. }
  16826. if (ret == 0) {
  16827. ret = wc_SetSubjectRaw(NULL, der, derSz);
  16828. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16829. ret = 0;
  16830. else
  16831. ret = WC_TEST_RET_ENC_EC(ret);
  16832. }
  16833. if (ret == 0) {
  16834. ret = wc_SetIssuerBuffer(&cert, der, derSz);
  16835. if (ret != 0)
  16836. ret = WC_TEST_RET_ENC_EC(ret);
  16837. }
  16838. if (ret == 0) {
  16839. ret = wc_SetIssuerBuffer(NULL, der, derSz);
  16840. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16841. ret = 0;
  16842. else
  16843. ret = WC_TEST_RET_ENC_EC(ret);
  16844. }
  16845. if (ret == 0) {
  16846. ret = wc_SetIssuerRaw(&cert, der, derSz);
  16847. if (ret != 0)
  16848. ret = WC_TEST_RET_ENC_EC(ret);
  16849. }
  16850. if (ret == 0) {
  16851. ret = wc_SetIssuerRaw(NULL, der, derSz);
  16852. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16853. ret = 0;
  16854. else
  16855. ret = WC_TEST_RET_ENC_EC(ret);
  16856. }
  16857. #ifdef WOLFSSL_ALT_NAMES
  16858. if (ret == 0) {
  16859. ret = wc_SetAltNamesBuffer(&cert, der, derSz);
  16860. if (ret != 0)
  16861. ret = WC_TEST_RET_ENC_EC(ret);
  16862. }
  16863. if (ret == 0) {
  16864. ret = wc_SetAltNamesBuffer(NULL, der, derSz);
  16865. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16866. ret = 0;
  16867. else
  16868. ret = WC_TEST_RET_ENC_EC(ret);
  16869. }
  16870. if (ret == 0) {
  16871. ret = wc_SetDatesBuffer(&cert, der, derSz);
  16872. if (ret != 0)
  16873. ret = WC_TEST_RET_ENC_EC(ret);
  16874. }
  16875. if (ret == 0) {
  16876. ret = wc_SetDatesBuffer(NULL, der, derSz);
  16877. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16878. ret = 0;
  16879. else
  16880. ret = WC_TEST_RET_ENC_EC(ret);
  16881. }
  16882. #endif
  16883. if (ret == 0) {
  16884. ret = wc_SetAuthKeyIdFromCert(&cert, der, derSz);
  16885. if (ret != 0)
  16886. ret = WC_TEST_RET_ENC_EC(ret);
  16887. }
  16888. if (ret == 0) {
  16889. ret = wc_SetAuthKeyIdFromCert(NULL, der, derSz);
  16890. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16891. ret = 0;
  16892. else
  16893. ret = WC_TEST_RET_ENC_NC;
  16894. }
  16895. wc_SetCert_Free(&cert);
  16896. if (ret == 0) {
  16897. if(cert.decodedCert != NULL)
  16898. ret = WC_TEST_RET_ENC_NC;
  16899. }
  16900. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16901. return ret;
  16902. }
  16903. #endif /* defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) &&
  16904. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) */
  16905. #define RSA_TEST_BYTES 512 /* up to 4096-bit key */
  16906. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  16907. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16908. static wc_test_ret_t rsa_flatten_test(RsaKey* key)
  16909. {
  16910. wc_test_ret_t ret;
  16911. byte e[RSA_TEST_BYTES];
  16912. byte n[RSA_TEST_BYTES];
  16913. word32 eSz = sizeof(e);
  16914. word32 nSz = sizeof(n);
  16915. /* Parameter Validation testing. */
  16916. ret = wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz);
  16917. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16918. return WC_TEST_RET_ENC_EC(ret);
  16919. ret = wc_RsaFlattenPublicKey(key, NULL, &eSz, n, &nSz);
  16920. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16921. return WC_TEST_RET_ENC_EC(ret);
  16922. ret = wc_RsaFlattenPublicKey(key, e, NULL, n, &nSz);
  16923. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16924. return WC_TEST_RET_ENC_EC(ret);
  16925. ret = wc_RsaFlattenPublicKey(key, e, &eSz, NULL, &nSz);
  16926. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16927. return WC_TEST_RET_ENC_EC(ret);
  16928. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, NULL);
  16929. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16930. return WC_TEST_RET_ENC_EC(ret);
  16931. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16932. if (ret != 0)
  16933. return WC_TEST_RET_ENC_EC(ret);
  16934. eSz = 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. eSz = sizeof(e);
  16939. nSz = 0;
  16940. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16941. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16942. return WC_TEST_RET_ENC_EC(ret);
  16943. return 0;
  16944. }
  16945. #endif /* NO_ASN */
  16946. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  16947. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16948. static wc_test_ret_t rsa_export_key_test(RsaKey* key)
  16949. {
  16950. wc_test_ret_t ret;
  16951. byte e[3];
  16952. word32 eSz = sizeof(e);
  16953. byte n[RSA_TEST_BYTES];
  16954. word32 nSz = sizeof(n);
  16955. byte d[RSA_TEST_BYTES];
  16956. word32 dSz = sizeof(d);
  16957. byte p[RSA_TEST_BYTES/2];
  16958. word32 pSz = sizeof(p);
  16959. byte q[RSA_TEST_BYTES/2];
  16960. word32 qSz = sizeof(q);
  16961. word32 zero = 0;
  16962. ret = wc_RsaExportKey(NULL, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16963. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16964. return WC_TEST_RET_ENC_EC(ret);
  16965. ret = wc_RsaExportKey(key, NULL, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16966. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16967. return WC_TEST_RET_ENC_EC(ret);
  16968. ret = wc_RsaExportKey(key, e, NULL, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16969. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16970. return WC_TEST_RET_ENC_EC(ret);
  16971. ret = wc_RsaExportKey(key, e, &eSz, NULL, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16972. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16973. return WC_TEST_RET_ENC_EC(ret);
  16974. ret = wc_RsaExportKey(key, e, &eSz, n, NULL, d, &dSz, p, &pSz, q, &qSz);
  16975. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16976. return WC_TEST_RET_ENC_EC(ret);
  16977. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, NULL, &dSz, p, &pSz, q, &qSz);
  16978. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16979. return WC_TEST_RET_ENC_EC(ret);
  16980. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, NULL, p, &pSz, q, &qSz);
  16981. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16982. return WC_TEST_RET_ENC_EC(ret);
  16983. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, NULL, &pSz, q, &qSz);
  16984. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16985. return WC_TEST_RET_ENC_EC(ret);
  16986. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, NULL, q, &qSz);
  16987. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16988. return WC_TEST_RET_ENC_EC(ret);
  16989. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, NULL, &qSz);
  16990. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16991. return WC_TEST_RET_ENC_EC(ret);
  16992. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, NULL);
  16993. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16994. return WC_TEST_RET_ENC_EC(ret);
  16995. ret = wc_RsaExportKey(key, e, &zero, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16996. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16997. return WC_TEST_RET_ENC_EC(ret);
  16998. ret = wc_RsaExportKey(key, e, &eSz, n, &zero, d, &dSz, p, &pSz, q, &qSz);
  16999. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17000. return WC_TEST_RET_ENC_EC(ret);
  17001. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  17002. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &zero, p, &pSz, q, &qSz);
  17003. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17004. return WC_TEST_RET_ENC_EC(ret);
  17005. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &zero, q, &qSz);
  17006. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17007. return WC_TEST_RET_ENC_EC(ret);
  17008. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &zero);
  17009. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17010. return WC_TEST_RET_ENC_EC(ret);
  17011. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  17012. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  17013. if (ret != 0)
  17014. return WC_TEST_RET_ENC_EC(ret);
  17015. return 0;
  17016. }
  17017. #endif /* !HAVE_FIPS && !NO_ASN && !WOLFSSL_RSA_VERIFY_ONLY */
  17018. #ifndef NO_SIG_WRAPPER
  17019. static wc_test_ret_t rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng)
  17020. {
  17021. wc_test_ret_t ret;
  17022. word32 sigSz;
  17023. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  17024. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  17025. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17026. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17027. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17028. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17029. };
  17030. WOLFSSL_SMALL_STACK_STATIC const byte hashEnc[] = {
  17031. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  17032. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  17033. 0x00, 0x04, 0x20,
  17034. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17035. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17036. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17037. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17038. };
  17039. word32 inLen = (word32)XSTRLEN((char*)in);
  17040. byte out[RSA_TEST_BYTES];
  17041. /* Parameter Validation testing. */
  17042. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_NONE, key, keyLen);
  17043. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17044. return WC_TEST_RET_ENC_EC(ret);
  17045. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, 0);
  17046. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17047. return WC_TEST_RET_ENC_EC(ret);
  17048. sigSz = (word32)modLen;
  17049. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17050. inLen, out, &sigSz, key, keyLen, rng);
  17051. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17052. return WC_TEST_RET_ENC_EC(ret);
  17053. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17054. 0, out, &sigSz, key, keyLen, rng);
  17055. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17056. return WC_TEST_RET_ENC_EC(ret);
  17057. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17058. inLen, NULL, &sigSz, key, keyLen, rng);
  17059. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17060. return WC_TEST_RET_ENC_EC(ret);
  17061. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17062. inLen, out, NULL, key, keyLen, rng);
  17063. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17064. return WC_TEST_RET_ENC_EC(ret);
  17065. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17066. inLen, out, &sigSz, NULL, keyLen, rng);
  17067. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17068. return WC_TEST_RET_ENC_EC(ret);
  17069. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17070. inLen, out, &sigSz, key, 0, rng);
  17071. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17072. return WC_TEST_RET_ENC_EC(ret);
  17073. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17074. inLen, out, &sigSz, key, keyLen, NULL);
  17075. #if defined(WOLFSSL_AFALG_XILINX_RSA) || defined(WOLFSSL_XILINX_CRYPT)
  17076. /* blinding / rng handled with hardware acceleration */
  17077. if (ret != 0)
  17078. #elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
  17079. /* async may not require RNG */
  17080. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17081. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID))
  17082. #else
  17083. if (ret != 0 && ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17084. #endif
  17085. #elif defined(HAVE_FIPS) || !defined(WC_RSA_BLINDING)
  17086. /* FIPS140 implementation does not do blinding */
  17087. if (ret != 0)
  17088. #elif defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY)
  17089. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17090. #elif defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SE050)
  17091. /* RNG is handled by hardware */
  17092. if (ret != 0)
  17093. #else
  17094. if (ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17095. #endif
  17096. return WC_TEST_RET_ENC_EC(ret);
  17097. sigSz = 0;
  17098. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17099. inLen, out, &sigSz, key, keyLen, rng);
  17100. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17101. return WC_TEST_RET_ENC_EC(ret);
  17102. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17103. inLen, out, (word32)modLen, key, keyLen);
  17104. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17105. return WC_TEST_RET_ENC_EC(ret);
  17106. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17107. 0, out, (word32)modLen, key, keyLen);
  17108. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17109. return WC_TEST_RET_ENC_EC(ret);
  17110. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17111. inLen, NULL, (word32)modLen, key, keyLen);
  17112. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17113. return WC_TEST_RET_ENC_EC(ret);
  17114. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17115. inLen, out, 0, key, keyLen);
  17116. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17117. return WC_TEST_RET_ENC_EC(ret);
  17118. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17119. inLen, out, (word32)modLen, NULL, keyLen);
  17120. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17121. return WC_TEST_RET_ENC_EC(ret);
  17122. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17123. inLen, out, (word32)modLen, key, 0);
  17124. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17125. return WC_TEST_RET_ENC_EC(ret);
  17126. #ifndef HAVE_ECC
  17127. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, keyLen);
  17128. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17129. return WC_TEST_RET_ENC_EC(ret);
  17130. #endif
  17131. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17132. return 0;
  17133. #endif
  17134. /* Use APIs. */
  17135. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, keyLen);
  17136. if (ret != modLen)
  17137. return WC_TEST_RET_ENC_EC(ret);
  17138. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA_W_ENC, key, keyLen);
  17139. if (ret != modLen)
  17140. return WC_TEST_RET_ENC_EC(ret);
  17141. sigSz = (word32)ret;
  17142. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  17143. XMEMSET(out, 0, sizeof(out));
  17144. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17145. inLen, out, &sigSz, key, keyLen, rng);
  17146. if (ret != 0)
  17147. return WC_TEST_RET_ENC_EC(ret);
  17148. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17149. inLen, out, (word32)modLen, key, keyLen);
  17150. if (ret != 0)
  17151. return WC_TEST_RET_ENC_EC(ret);
  17152. sigSz = (word32)sizeof(out);
  17153. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17154. in, inLen, out, &sigSz, key, keyLen, rng);
  17155. if (ret != 0)
  17156. return WC_TEST_RET_ENC_EC(ret);
  17157. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17158. in, inLen, out, (word32)modLen, key, keyLen);
  17159. if (ret != 0)
  17160. return WC_TEST_RET_ENC_EC(ret);
  17161. /* Wrong signature type. */
  17162. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17163. inLen, out, (word32)modLen, key, keyLen);
  17164. if (ret == 0)
  17165. return WC_TEST_RET_ENC_EC(ret);
  17166. /* check hash functions */
  17167. sigSz = (word32)sizeof(out);
  17168. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17169. hash, (int)sizeof(hash), out, &sigSz, key, keyLen, rng);
  17170. if (ret != 0)
  17171. return WC_TEST_RET_ENC_EC(ret);
  17172. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17173. hash, (int)sizeof(hash), out, (word32)modLen, key, keyLen);
  17174. if (ret != 0)
  17175. return WC_TEST_RET_ENC_EC(ret);
  17176. sigSz = (word32)sizeof(out);
  17177. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17178. hashEnc, (int)sizeof(hashEnc), out, &sigSz, key, keyLen, rng);
  17179. if (ret != 0)
  17180. return WC_TEST_RET_ENC_EC(ret);
  17181. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17182. hashEnc, (int)sizeof(hashEnc), out, (word32)modLen, key, keyLen);
  17183. if (ret != 0)
  17184. return WC_TEST_RET_ENC_EC(ret);
  17185. #else
  17186. (void)hash;
  17187. (void)hashEnc;
  17188. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  17189. return 0;
  17190. }
  17191. #endif /* !NO_SIG_WRAPPER */
  17192. #ifdef WC_RSA_NONBLOCK
  17193. static wc_test_ret_t rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out,
  17194. word32 outSz, byte* plain, word32 plainSz, WC_RNG* rng)
  17195. {
  17196. wc_test_ret_t ret = 0;
  17197. int count;
  17198. int signSz = 0;
  17199. RsaNb nb;
  17200. byte* inlinePlain = NULL;
  17201. /* Enable non-blocking RSA mode - provide context */
  17202. ret = wc_RsaSetNonBlock(key, &nb);
  17203. if (ret != 0)
  17204. return ret;
  17205. #ifdef WC_RSA_NONBLOCK_TIME
  17206. /* Enable time based RSA blocking. 8 microseconds max (3.1GHz) */
  17207. ret = wc_RsaSetNonBlockTime(key, 8, 3100);
  17208. if (ret != 0)
  17209. return ret;
  17210. #endif
  17211. count = 0;
  17212. do {
  17213. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, rng);
  17214. count++; /* track number of would blocks */
  17215. if (ret == FP_WOULDBLOCK) {
  17216. /* do "other" work here */
  17217. }
  17218. } while (ret == FP_WOULDBLOCK);
  17219. if (ret < 0) {
  17220. return ret;
  17221. }
  17222. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17223. printf("RSA non-block sign: %d times\n", count);
  17224. #endif
  17225. signSz = ret;
  17226. /* Test non-blocking verify */
  17227. XMEMSET(plain, 0, plainSz);
  17228. count = 0;
  17229. do {
  17230. ret = wc_RsaSSL_Verify(out, (word32)signSz, plain, plainSz, key);
  17231. count++; /* track number of would blocks */
  17232. if (ret == FP_WOULDBLOCK) {
  17233. /* do "other" work here */
  17234. }
  17235. } while (ret == FP_WOULDBLOCK);
  17236. if (ret < 0) {
  17237. return ret;
  17238. }
  17239. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17240. printf("RSA non-block verify: %d times\n", count);
  17241. #endif
  17242. if (signSz == ret && XMEMCMP(plain, in, (size_t)ret)) {
  17243. return SIG_VERIFY_E;
  17244. }
  17245. /* Test inline non-blocking verify */
  17246. count = 0;
  17247. do {
  17248. ret = wc_RsaSSL_VerifyInline(out, (word32)signSz, &inlinePlain, key);
  17249. count++; /* track number of would blocks */
  17250. if (ret == FP_WOULDBLOCK) {
  17251. /* do "other" work here */
  17252. }
  17253. } while (ret == FP_WOULDBLOCK);
  17254. if (ret < 0) {
  17255. return ret;
  17256. }
  17257. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17258. printf("RSA non-block inline verify: %d times\n", count);
  17259. #endif
  17260. if (signSz == ret && XMEMCMP(inlinePlain, in, (size_t)ret)) {
  17261. return SIG_VERIFY_E;
  17262. }
  17263. /* Disabling non-block RSA mode */
  17264. ret = wc_RsaSetNonBlock(key, NULL);
  17265. (void)count;
  17266. return 0;
  17267. }
  17268. #endif
  17269. #if !defined(NO_ASN)
  17270. static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
  17271. {
  17272. wc_test_ret_t ret;
  17273. word32 inSz;
  17274. word32 inOutIdx;
  17275. WOLFSSL_SMALL_STACK_STATIC const byte n[2] = { 0x00, 0x23 };
  17276. WOLFSSL_SMALL_STACK_STATIC const byte e[2] = { 0x00, 0x03 };
  17277. WOLFSSL_SMALL_STACK_STATIC const byte good[] = { 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1,
  17278. 0x03 };
  17279. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgId[] = {
  17280. 0x30, 0x18, 0x30, 0x16,
  17281. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17282. 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17283. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgIdNull[] = {
  17284. 0x30, 0x1a, 0x30, 0x18,
  17285. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17286. 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17287. 0x02, 0x1, 0x03 };
  17288. WOLFSSL_SMALL_STACK_STATIC const byte badAlgIdNull[] = {
  17289. 0x30, 0x1b, 0x30, 0x19,
  17290. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17291. 0x05, 0x01, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17292. 0x02, 0x1, 0x03 };
  17293. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitString[] = {
  17294. 0x30, 0x18, 0x30, 0x16,
  17295. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17296. 0x04, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17297. WOLFSSL_SMALL_STACK_STATIC const byte badBitStringLen[] = {
  17298. 0x30, 0x18, 0x30, 0x16,
  17299. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17300. 0x03, 0x0a, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17301. WOLFSSL_SMALL_STACK_STATIC const byte badNoSeq[] = {
  17302. 0x30, 0x16, 0x30, 0x14,
  17303. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17304. 0x07, 0x00, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17305. WOLFSSL_SMALL_STACK_STATIC const byte badNoObj[] = {
  17306. 0x30, 0x0f, 0x30, 0x0d, 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06,
  17307. 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17308. WOLFSSL_SMALL_STACK_STATIC const byte badIntN[] = {
  17309. 0x30, 0x06, 0x02, 0x05, 0x23, 0x02, 0x1, 0x03 };
  17310. WOLFSSL_SMALL_STACK_STATIC const byte badNotIntE[] = {
  17311. 0x30, 0x06, 0x02, 0x01, 0x23, 0x04, 0x1, 0x03 };
  17312. WOLFSSL_SMALL_STACK_STATIC const byte badLength[] = {
  17313. 0x30, 0x04, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17314. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrNoZero[] = {
  17315. 0x30, 0x17, 0x30, 0x15,
  17316. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17317. 0x03, 0x08, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17318. ret = wc_InitRsaKey(keyPub, NULL);
  17319. if (ret != 0)
  17320. return WC_TEST_RET_ENC_EC(ret);
  17321. /* Parameter Validation testing. */
  17322. ret = wc_RsaPublicKeyDecodeRaw(NULL, sizeof(n), e, 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), NULL, sizeof(e), keyPub);
  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, sizeof(n), e, sizeof(e), NULL);
  17333. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17334. ret = WC_TEST_RET_ENC_EC(ret);
  17335. goto done;
  17336. }
  17337. ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub);
  17338. #if defined(USE_INTEGER_HEAP_MATH)
  17339. if (ret != 0)
  17340. #else
  17341. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17342. #endif
  17343. {
  17344. ret = WC_TEST_RET_ENC_EC(ret);
  17345. goto done;
  17346. }
  17347. wc_FreeRsaKey(keyPub);
  17348. ret = wc_InitRsaKey(keyPub, NULL);
  17349. if (ret != 0)
  17350. return WC_TEST_RET_ENC_EC(ret);
  17351. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub);
  17352. #if defined(USE_INTEGER_HEAP_MATH)
  17353. if (ret != 0)
  17354. #else
  17355. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17356. #endif
  17357. {
  17358. ret = WC_TEST_RET_ENC_EC(ret);
  17359. goto done;
  17360. }
  17361. wc_FreeRsaKey(keyPub);
  17362. ret = wc_InitRsaKey(keyPub, NULL);
  17363. if (ret != 0)
  17364. return WC_TEST_RET_ENC_EC(ret);
  17365. /* Use API. */
  17366. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), keyPub);
  17367. if (ret != 0) {
  17368. ret = WC_TEST_RET_ENC_EC(ret);
  17369. goto done;
  17370. }
  17371. wc_FreeRsaKey(keyPub);
  17372. ret = wc_InitRsaKey(keyPub, NULL);
  17373. if (ret != 0)
  17374. return WC_TEST_RET_ENC_EC(ret);
  17375. /* Parameter Validation testing. */
  17376. inSz = sizeof(good);
  17377. ret = wc_RsaPublicKeyDecode(NULL, &inOutIdx, 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, NULL, keyPub, inSz);
  17383. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17384. ret = WC_TEST_RET_ENC_EC(ret);
  17385. goto done;
  17386. }
  17387. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  17388. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17389. ret = WC_TEST_RET_ENC_EC(ret);
  17390. goto done;
  17391. }
  17392. /* Use good data and offset to bad data. */
  17393. inOutIdx = 2;
  17394. inSz = sizeof(good) - inOutIdx;
  17395. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17396. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17397. ret = WC_TEST_RET_ENC_EC(ret);
  17398. goto done;
  17399. }
  17400. inOutIdx = 2;
  17401. inSz = sizeof(goodAlgId) - inOutIdx;
  17402. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17403. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17404. ret = WC_TEST_RET_ENC_EC(ret);
  17405. goto done;
  17406. }
  17407. inOutIdx = 2;
  17408. inSz = sizeof(goodAlgId);
  17409. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17410. #ifndef WOLFSSL_NO_DECODE_EXTRA
  17411. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17412. #else
  17413. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E))
  17414. #endif
  17415. {
  17416. ret = WC_TEST_RET_ENC_EC(ret);
  17417. goto done;
  17418. }
  17419. /* Try different bad data. */
  17420. inSz = sizeof(badAlgIdNull);
  17421. inOutIdx = 0;
  17422. ret = wc_RsaPublicKeyDecode(badAlgIdNull, &inOutIdx, keyPub, inSz);
  17423. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E)) {
  17424. ret = WC_TEST_RET_ENC_EC(ret);
  17425. goto done;
  17426. }
  17427. inSz = sizeof(badNotBitString);
  17428. inOutIdx = 0;
  17429. ret = wc_RsaPublicKeyDecode(badNotBitString, &inOutIdx, keyPub, inSz);
  17430. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E)) {
  17431. ret = WC_TEST_RET_ENC_EC(ret);
  17432. goto done;
  17433. }
  17434. inSz = sizeof(badBitStringLen);
  17435. inOutIdx = 0;
  17436. ret = wc_RsaPublicKeyDecode(badBitStringLen, &inOutIdx, keyPub, inSz);
  17437. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17438. ret = WC_TEST_RET_ENC_EC(ret);
  17439. goto done;
  17440. }
  17441. inSz = sizeof(badNoSeq);
  17442. inOutIdx = 0;
  17443. ret = wc_RsaPublicKeyDecode(badNoSeq, &inOutIdx, keyPub, inSz);
  17444. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17445. ret = WC_TEST_RET_ENC_EC(ret);
  17446. goto done;
  17447. }
  17448. inSz = sizeof(badNoObj);
  17449. inOutIdx = 0;
  17450. ret = wc_RsaPublicKeyDecode(badNoObj, &inOutIdx, keyPub, inSz);
  17451. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E) &&
  17452. ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E))
  17453. {
  17454. ret = WC_TEST_RET_ENC_EC(ret);
  17455. goto done;
  17456. }
  17457. inSz = sizeof(badIntN);
  17458. inOutIdx = 0;
  17459. ret = wc_RsaPublicKeyDecode(badIntN, &inOutIdx, keyPub, inSz);
  17460. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17461. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17462. {
  17463. ret = WC_TEST_RET_ENC_EC(ret);
  17464. goto done;
  17465. }
  17466. inSz = sizeof(badNotIntE);
  17467. inOutIdx = 0;
  17468. ret = wc_RsaPublicKeyDecode(badNotIntE, &inOutIdx, keyPub, inSz);
  17469. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17470. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17471. {
  17472. ret = WC_TEST_RET_ENC_EC(ret);
  17473. goto done;
  17474. }
  17475. /* TODO: Shouldn't pass as the sequence length is too small. */
  17476. inSz = sizeof(badLength);
  17477. inOutIdx = 0;
  17478. ret = wc_RsaPublicKeyDecode(badLength, &inOutIdx, keyPub, inSz);
  17479. #ifndef WOLFSSL_ASN_TEMPLATE
  17480. if (ret != 0)
  17481. #else
  17482. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17483. #endif
  17484. {
  17485. ret = WC_TEST_RET_ENC_EC(ret);
  17486. goto done;
  17487. }
  17488. /* TODO: Shouldn't ignore object id's data. */
  17489. wc_FreeRsaKey(keyPub);
  17490. ret = wc_InitRsaKey(keyPub, NULL);
  17491. if (ret != 0)
  17492. return WC_TEST_RET_ENC_EC(ret);
  17493. inSz = sizeof(badBitStrNoZero);
  17494. inOutIdx = 0;
  17495. ret = wc_RsaPublicKeyDecode(badBitStrNoZero, &inOutIdx, keyPub, inSz);
  17496. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  17497. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17498. {
  17499. ret = WC_TEST_RET_ENC_EC(ret);
  17500. goto done;
  17501. }
  17502. wc_FreeRsaKey(keyPub);
  17503. ret = wc_InitRsaKey(keyPub, NULL);
  17504. if (ret != 0)
  17505. return WC_TEST_RET_ENC_EC(ret);
  17506. /* Valid data cases. */
  17507. inSz = sizeof(good);
  17508. inOutIdx = 0;
  17509. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17510. if (ret != 0) {
  17511. ret = WC_TEST_RET_ENC_EC(ret);
  17512. goto done;
  17513. }
  17514. if (inOutIdx != inSz) {
  17515. ret = WC_TEST_RET_ENC_NC;
  17516. goto done;
  17517. }
  17518. wc_FreeRsaKey(keyPub);
  17519. ret = wc_InitRsaKey(keyPub, NULL);
  17520. if (ret != 0)
  17521. return WC_TEST_RET_ENC_EC(ret);
  17522. inSz = sizeof(goodAlgId);
  17523. inOutIdx = 0;
  17524. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17525. if (ret != 0) {
  17526. ret = WC_TEST_RET_ENC_EC(ret);
  17527. goto done;
  17528. }
  17529. if (inOutIdx != inSz) {
  17530. ret = WC_TEST_RET_ENC_NC;
  17531. goto done;
  17532. }
  17533. wc_FreeRsaKey(keyPub);
  17534. ret = wc_InitRsaKey(keyPub, NULL);
  17535. if (ret != 0)
  17536. return WC_TEST_RET_ENC_EC(ret);
  17537. inSz = sizeof(goodAlgIdNull);
  17538. inOutIdx = 0;
  17539. ret = wc_RsaPublicKeyDecode(goodAlgIdNull, &inOutIdx, keyPub, inSz);
  17540. if (ret != 0) {
  17541. ret = WC_TEST_RET_ENC_EC(ret);
  17542. goto done;
  17543. }
  17544. if (inOutIdx != inSz) {
  17545. ret = WC_TEST_RET_ENC_NC;
  17546. goto done;
  17547. }
  17548. done:
  17549. wc_FreeRsaKey(keyPub);
  17550. return ret;
  17551. }
  17552. #endif
  17553. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  17554. /* Need to create known good signatures to test with this. */
  17555. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  17556. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17557. static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key)
  17558. {
  17559. byte digest[WC_MAX_DIGEST_SIZE];
  17560. wc_test_ret_t ret = 0;
  17561. const char inStr[] = TEST_STRING;
  17562. word32 inLen = (word32)TEST_STRING_SZ;
  17563. word32 outSz;
  17564. word32 plainSz;
  17565. word32 digestSz;
  17566. int i, j;
  17567. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17568. int k, l;
  17569. #endif
  17570. #ifndef WOLFSSL_SE050
  17571. int len;
  17572. #endif
  17573. byte* plain;
  17574. int mgf[] = {
  17575. #ifndef NO_SHA
  17576. WC_MGF1SHA1,
  17577. #endif
  17578. #ifdef WOLFSSL_SHA224
  17579. WC_MGF1SHA224,
  17580. #endif
  17581. WC_MGF1SHA256,
  17582. #ifdef WOLFSSL_SHA384
  17583. WC_MGF1SHA384,
  17584. #endif
  17585. #ifdef WOLFSSL_SHA512
  17586. WC_MGF1SHA512
  17587. #endif
  17588. };
  17589. enum wc_HashType hash[] = {
  17590. #ifndef NO_SHA
  17591. WC_HASH_TYPE_SHA,
  17592. #endif
  17593. #ifdef WOLFSSL_SHA224
  17594. WC_HASH_TYPE_SHA224,
  17595. #endif
  17596. WC_HASH_TYPE_SHA256,
  17597. #ifdef WOLFSSL_SHA384
  17598. WC_HASH_TYPE_SHA384,
  17599. #endif
  17600. #ifdef WOLFSSL_SHA512
  17601. WC_HASH_TYPE_SHA512,
  17602. #endif
  17603. };
  17604. WC_DECLARE_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17605. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17606. WC_DECLARE_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17607. WC_ALLOC_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17608. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17609. WC_ALLOC_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17610. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17611. if (in == NULL || out == NULL || sig == NULL)
  17612. ERROR_OUT(MEMORY_E, exit_rsa_pss);
  17613. #endif
  17614. XMEMCPY(in, inStr, inLen);
  17615. /* Test all combinations of hash and MGF. */
  17616. for (j = 0; j < (int)(sizeof(hash)/sizeof(*hash)); j++) {
  17617. /* Calculate hash of message. */
  17618. ret = wc_Hash(hash[j], in, inLen, digest, sizeof(digest));
  17619. if (ret != 0)
  17620. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17621. digestSz = (word32)wc_HashGetDigestSize(hash[j]);
  17622. #ifdef WOLFSSL_SE050
  17623. /* SE050 only supports MGF matched to same hash type */
  17624. i = j;
  17625. #else
  17626. for (i = 0; i < (int)(sizeof(mgf)/sizeof(*mgf)); i++) {
  17627. #endif
  17628. outSz = RSA_TEST_BYTES;
  17629. do {
  17630. #if defined(WOLFSSL_ASYNC_CRYPT)
  17631. ret = wc_AsyncWait(ret, &key->asyncDev,
  17632. WC_ASYNC_FLAG_CALL_AGAIN);
  17633. #endif
  17634. if (ret >= 0) {
  17635. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz,
  17636. hash[j], mgf[i], -1, key, rng);
  17637. }
  17638. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17639. if (ret <= 0)
  17640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17641. outSz = (word32)ret;
  17642. XMEMCPY(sig, out, outSz);
  17643. plain = NULL;
  17644. TEST_SLEEP();
  17645. do {
  17646. #if defined(WOLFSSL_ASYNC_CRYPT)
  17647. ret = wc_AsyncWait(ret, &key->asyncDev,
  17648. WC_ASYNC_FLAG_CALL_AGAIN);
  17649. #endif
  17650. if (ret >= 0) {
  17651. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[j],
  17652. mgf[i], -1, key);
  17653. }
  17654. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17655. if (ret <= 0)
  17656. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17657. plainSz = (word32)ret;
  17658. TEST_SLEEP();
  17659. #if defined(HAVE_SELFTEST) && \
  17660. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17661. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17662. hash[j], -1);
  17663. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17664. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17665. hash[j], -1, 0);
  17666. #else
  17667. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz,
  17668. hash[j], -1, wc_RsaEncryptSize(key)*8, HEAP_HINT);
  17669. #endif
  17670. if (ret != 0)
  17671. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17672. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17673. for (k = 0; k < (int)(sizeof(mgf)/sizeof(*mgf)); k++) {
  17674. for (l = 0; l < (int)(sizeof(hash)/sizeof(*hash)); l++) {
  17675. if (i == k && j == l)
  17676. continue;
  17677. XMEMCPY(sig, out, outSz);
  17678. do {
  17679. #if defined(WOLFSSL_ASYNC_CRYPT)
  17680. ret = wc_AsyncWait(ret, &key->asyncDev,
  17681. WC_ASYNC_FLAG_CALL_AGAIN);
  17682. #endif
  17683. if (ret >= 0) {
  17684. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz,
  17685. (byte**)&plain, hash[l], mgf[k], -1, key);
  17686. }
  17687. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17688. if (ret >= 0)
  17689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17690. }
  17691. }
  17692. #endif
  17693. #ifndef WOLFSSL_SE050
  17694. } /* end mgf for loop */
  17695. #endif
  17696. }
  17697. /* SE050 generates salts internally only of hash length */
  17698. #ifndef WOLFSSL_SE050
  17699. /* Test that a salt length of zero works. */
  17700. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17701. outSz = RSA_TEST_BYTES;
  17702. do {
  17703. #if defined(WOLFSSL_ASYNC_CRYPT)
  17704. ret = wc_AsyncWait(ret, &key->asyncDev,
  17705. WC_ASYNC_FLAG_CALL_AGAIN);
  17706. #endif
  17707. if (ret >= 0) {
  17708. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17709. mgf[0], 0, key, rng);
  17710. }
  17711. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17712. if (ret <= 0)
  17713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17714. outSz = (word32)ret;
  17715. TEST_SLEEP();
  17716. do {
  17717. #if defined(WOLFSSL_ASYNC_CRYPT)
  17718. ret = wc_AsyncWait(ret, &key->asyncDev,
  17719. WC_ASYNC_FLAG_CALL_AGAIN);
  17720. #endif
  17721. if (ret >= 0) {
  17722. ret = wc_RsaPSS_Verify_ex(out, outSz, sig, outSz, hash[0], mgf[0],
  17723. 0, key);
  17724. }
  17725. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17726. if (ret <= 0)
  17727. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17728. plainSz = (word32)ret;
  17729. TEST_SLEEP();
  17730. do {
  17731. #if defined(WOLFSSL_ASYNC_CRYPT)
  17732. ret = wc_AsyncWait(ret, &key->asyncDev,
  17733. WC_ASYNC_FLAG_CALL_AGAIN);
  17734. #endif
  17735. if (ret >= 0) {
  17736. #if defined(HAVE_SELFTEST) && \
  17737. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17738. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17739. hash[0], 0);
  17740. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17741. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17742. hash[0], 0, 0);
  17743. #else
  17744. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, sig, plainSz,
  17745. hash[0], 0, 0, HEAP_HINT);
  17746. #endif
  17747. }
  17748. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17749. if (ret != 0)
  17750. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17751. XMEMCPY(sig, out, outSz);
  17752. plain = NULL;
  17753. do {
  17754. #if defined(WOLFSSL_ASYNC_CRYPT)
  17755. ret = wc_AsyncWait(ret, &key->asyncDev,
  17756. WC_ASYNC_FLAG_CALL_AGAIN);
  17757. #endif
  17758. if (ret >= 0) {
  17759. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17760. 0, key);
  17761. }
  17762. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17763. if (ret <= 0)
  17764. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17765. plainSz = (word32)ret;
  17766. TEST_SLEEP();
  17767. #if defined(HAVE_SELFTEST) && \
  17768. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17769. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17770. hash[0], 0);
  17771. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17772. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17773. hash[0], 0, 0);
  17774. #else
  17775. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17776. 0, 0, HEAP_HINT);
  17777. #endif
  17778. if (ret != 0)
  17779. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17780. /* Test bad salt lengths in various APIs. */
  17781. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17782. outSz = RSA_TEST_BYTES;
  17783. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17784. len = -2;
  17785. #else
  17786. len = -3;
  17787. #endif
  17788. do {
  17789. #if defined(WOLFSSL_ASYNC_CRYPT)
  17790. ret = wc_AsyncWait(ret, &key->asyncDev,
  17791. WC_ASYNC_FLAG_CALL_AGAIN);
  17792. #endif
  17793. if (ret >= 0) {
  17794. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17795. mgf[0], len, key, rng);
  17796. }
  17797. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17798. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17800. do {
  17801. #if defined(WOLFSSL_ASYNC_CRYPT)
  17802. ret = wc_AsyncWait(ret, &key->asyncDev,
  17803. WC_ASYNC_FLAG_CALL_AGAIN);
  17804. #endif
  17805. if (ret >= 0) {
  17806. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17807. mgf[0], (int)digestSz + 1, key, rng);
  17808. }
  17809. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17810. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17811. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17812. TEST_SLEEP();
  17813. do {
  17814. #if defined(WOLFSSL_ASYNC_CRYPT)
  17815. ret = wc_AsyncWait(ret, &key->asyncDev,
  17816. WC_ASYNC_FLAG_CALL_AGAIN);
  17817. #endif
  17818. if (ret >= 0) {
  17819. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0],
  17820. mgf[0], -2, key);
  17821. }
  17822. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17823. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17824. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17825. TEST_SLEEP();
  17826. do {
  17827. #if defined(WOLFSSL_ASYNC_CRYPT)
  17828. ret = wc_AsyncWait(ret, &key->asyncDev,
  17829. WC_ASYNC_FLAG_CALL_AGAIN);
  17830. #endif
  17831. if (ret >= 0) {
  17832. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17833. (int)digestSz + 1, key);
  17834. }
  17835. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17836. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17837. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17838. TEST_SLEEP();
  17839. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17840. len = -2;
  17841. #else
  17842. len = -3;
  17843. #endif
  17844. #if defined(HAVE_SELFTEST) && \
  17845. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17846. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17847. hash[0], len);
  17848. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17849. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17850. hash[0], len, 0);
  17851. #else
  17852. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17853. len, 0, HEAP_HINT);
  17854. #endif
  17855. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17856. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17857. #ifndef WOLFSSL_PSS_LONG_SALT
  17858. len = (int)(digestSz + 1);
  17859. #else
  17860. len = (int)(plainSz - digestSz - 1);
  17861. #endif
  17862. #if defined(HAVE_SELFTEST) && \
  17863. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17864. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17865. hash[0], len);
  17866. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17868. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17869. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17870. hash[0], len, 0);
  17871. if (ret != WC_NO_ERR_TRACE(BAD_PADDING_E))
  17872. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17873. #else
  17874. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17875. len, 0, HEAP_HINT);
  17876. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17877. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17878. #endif
  17879. ret = 0;
  17880. #endif /* WOLFSSL_SE050 */
  17881. exit_rsa_pss:
  17882. WC_FREE_VAR(sig, HEAP_HINT);
  17883. WC_FREE_VAR(in, HEAP_HINT);
  17884. WC_FREE_VAR(out, HEAP_HINT);
  17885. return ret;
  17886. }
  17887. #endif /* !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY */
  17888. #endif
  17889. #ifdef WC_RSA_NO_PADDING
  17890. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void)
  17891. {
  17892. WC_RNG rng;
  17893. byte* tmp = NULL;
  17894. size_t bytes;
  17895. wc_test_ret_t ret;
  17896. word32 inLen = 0;
  17897. word32 idx = 0;
  17898. word32 outSz = RSA_TEST_BYTES;
  17899. word32 plainSz = RSA_TEST_BYTES;
  17900. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  17901. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  17902. !defined(NO_FILESYSTEM)
  17903. XFILE file;
  17904. #endif
  17905. WC_DECLARE_VAR(key, RsaKey, 1, HEAP_HINT);
  17906. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17907. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17908. WC_ALLOC_VAR(key, RsaKey, 1, HEAP_HINT);
  17909. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17910. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17911. WOLFSSL_ENTER("rsa_no_pad_test");
  17912. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17913. if (key == NULL || out == NULL || plain == NULL)
  17914. ERROR_OUT(MEMORY_E, exit_rsa_nopadding);
  17915. #endif
  17916. /* initialize stack structures */
  17917. XMEMSET(&rng, 0, sizeof(rng));
  17918. XMEMSET(key, 0, sizeof(RsaKey));
  17919. #ifdef USE_CERT_BUFFERS_1024
  17920. bytes = (size_t)sizeof_client_key_der_1024;
  17921. if (bytes < (size_t)sizeof_client_cert_der_1024)
  17922. bytes = (size_t)sizeof_client_cert_der_1024;
  17923. #elif defined(USE_CERT_BUFFERS_2048)
  17924. bytes = (size_t)sizeof_client_key_der_2048;
  17925. if (bytes < (size_t)sizeof_client_cert_der_2048)
  17926. bytes = (size_t)sizeof_client_cert_der_2048;
  17927. #else
  17928. bytes = FOURK_BUF;
  17929. #endif
  17930. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  17931. if (tmp == NULL
  17932. #ifdef WOLFSSL_ASYNC_CRYPT
  17933. || out == NULL || plain == NULL
  17934. #endif
  17935. ) {
  17936. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17937. }
  17938. #ifdef USE_CERT_BUFFERS_1024
  17939. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  17940. #elif defined(USE_CERT_BUFFERS_2048)
  17941. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  17942. #elif defined(USE_CERT_BUFFERS_3072)
  17943. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  17944. #elif defined(USE_CERT_BUFFERS_4096)
  17945. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  17946. #elif !defined(NO_FILESYSTEM)
  17947. file = XFOPEN(clientKey, "rb");
  17948. if (!file) {
  17949. err_sys("can't open clientKey, Please run from wolfSSL home dir",
  17950. WC_TEST_RET_ENC_ERRNO);
  17951. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17952. }
  17953. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  17954. XFCLOSE(file);
  17955. if (bytes == 0)
  17956. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17957. #else
  17958. /* No key to use. */
  17959. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17960. #endif /* USE_CERT_BUFFERS */
  17961. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  17962. if (ret != 0) {
  17963. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17964. }
  17965. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  17966. if (ret != 0) {
  17967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17968. }
  17969. /* after loading in key use tmp as the test buffer */
  17970. #ifndef HAVE_FIPS
  17971. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  17972. #else
  17973. ret = wc_InitRng(&rng);
  17974. #endif
  17975. if (ret != 0) {
  17976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17977. }
  17978. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17979. inLen = (word32)wc_RsaEncryptSize(key);
  17980. outSz = inLen;
  17981. plainSz = inLen;
  17982. XMEMSET(tmp, 7, inLen);
  17983. do {
  17984. #if defined(WOLFSSL_ASYNC_CRYPT)
  17985. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17986. #endif
  17987. if (ret >= 0) {
  17988. ret = wc_RsaDirect(tmp, inLen, out, &outSz, key,
  17989. RSA_PRIVATE_ENCRYPT, &rng);
  17990. }
  17991. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17992. if (ret <= 0) {
  17993. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17994. }
  17995. /* encrypted result should not be the same as input */
  17996. if (XMEMCMP(out, tmp, inLen) == 0) {
  17997. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17998. }
  17999. TEST_SLEEP();
  18000. /* decrypt with public key and compare result */
  18001. do {
  18002. #if defined(WOLFSSL_ASYNC_CRYPT)
  18003. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18004. #endif
  18005. if (ret >= 0) {
  18006. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key,
  18007. RSA_PUBLIC_DECRYPT, &rng);
  18008. }
  18009. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18010. if (ret <= 0) {
  18011. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18012. }
  18013. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18014. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18015. }
  18016. TEST_SLEEP();
  18017. #endif
  18018. #ifdef WC_RSA_BLINDING
  18019. ret = wc_RsaSetRNG(NULL, &rng);
  18020. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18021. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18022. }
  18023. ret = wc_RsaSetRNG(key, &rng);
  18024. if (ret < 0) {
  18025. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18026. }
  18027. #endif
  18028. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18029. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18030. do {
  18031. #if defined(WOLFSSL_ASYNC_CRYPT)
  18032. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18033. #endif
  18034. if (ret >= 0) {
  18035. ret = wc_RsaPublicEncrypt_ex(tmp, inLen, out, outSz, key, &rng,
  18036. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18037. }
  18038. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18039. if (ret < 0) {
  18040. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18041. }
  18042. TEST_SLEEP();
  18043. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18044. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18045. do {
  18046. #if defined(WOLFSSL_ASYNC_CRYPT)
  18047. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18048. #endif
  18049. if (ret >= 0) {
  18050. ret = wc_RsaPrivateDecrypt_ex(out, outSz, plain, plainSz, key,
  18051. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18052. }
  18053. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18054. if (ret < 0) {
  18055. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18056. }
  18057. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18058. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18059. }
  18060. TEST_SLEEP();
  18061. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18062. /* test some bad arguments */
  18063. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key, -1,
  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, plain, &plainSz, NULL, RSA_PUBLIC_DECRYPT,
  18069. &rng);
  18070. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18072. }
  18073. ret = wc_RsaDirect(out, outSz, NULL, &plainSz, key, RSA_PUBLIC_DECRYPT,
  18074. &rng);
  18075. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || plainSz != inLen) {
  18076. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18077. }
  18078. ret = wc_RsaDirect(out, outSz - 10, plain, &plainSz, key,
  18079. RSA_PUBLIC_DECRYPT, &rng);
  18080. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18082. }
  18083. /* if making it to this point of code without hitting an ERROR_OUT then
  18084. * all tests have passed */
  18085. ret = 0;
  18086. exit_rsa_nopadding:
  18087. wc_FreeRsaKey(key);
  18088. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18089. WC_FREE_VAR(key, HEAP_HINT);
  18090. WC_FREE_VAR(out, HEAP_HINT);
  18091. WC_FREE_VAR(plain, HEAP_HINT);
  18092. wc_FreeRng(&rng);
  18093. return ret;
  18094. }
  18095. #endif /* WC_RSA_NO_PADDING */
  18096. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  18097. static wc_test_ret_t rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
  18098. {
  18099. byte* tmp = NULL;
  18100. size_t bytes;
  18101. wc_test_ret_t ret;
  18102. word32 inLen = 0;
  18103. #ifndef NO_ASN
  18104. word32 idx = 0;
  18105. #endif
  18106. word32 outSz = RSA_TEST_BYTES;
  18107. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18108. word32 plainSz = RSA_TEST_BYTES;
  18109. #endif
  18110. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_3072) && \
  18111. !defined(USE_CERT_BUFFERS_4096) && !defined(NO_FILESYSTEM)
  18112. XFILE file;
  18113. #endif
  18114. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18115. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18116. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18117. #endif
  18118. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18119. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18120. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18121. #endif
  18122. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18123. if (out == NULL
  18124. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18125. || plain == NULL
  18126. #endif
  18127. ) {
  18128. ERROR_OUT(MEMORY_E, exit_rsa_even_mod);
  18129. }
  18130. #endif
  18131. #if defined(USE_CERT_BUFFERS_2048)
  18132. bytes = (size_t)sizeof_client_key_der_2048;
  18133. if (bytes < (size_t)sizeof_client_cert_der_2048)
  18134. bytes = (size_t)sizeof_client_cert_der_2048;
  18135. #else
  18136. bytes = FOURK_BUF;
  18137. #endif
  18138. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18139. if (tmp == NULL
  18140. #ifdef WOLFSSL_ASYNC_CRYPT
  18141. || out == NULL || plain == NULL
  18142. #endif
  18143. ) {
  18144. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18145. }
  18146. #if defined(USE_CERT_BUFFERS_2048)
  18147. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  18148. #elif defined(USE_CERT_BUFFERS_3072)
  18149. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  18150. #elif defined(USE_CERT_BUFFERS_4096)
  18151. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  18152. #elif !defined(NO_FILESYSTEM)
  18153. file = XFOPEN(clientKey, "rb");
  18154. if (!file) {
  18155. err_sys("can't open ./certs/client-key.der, "
  18156. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  18157. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18158. }
  18159. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  18160. XFCLOSE(file);
  18161. if (bytes == 0)
  18162. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18163. #else
  18164. /* No key to use. */
  18165. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18166. #endif /* USE_CERT_BUFFERS */
  18167. #ifndef NO_ASN
  18168. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  18169. if (ret != 0) {
  18170. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18171. }
  18172. #else
  18173. #ifdef USE_CERT_BUFFERS_2048
  18174. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  18175. if (ret != 0) {
  18176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18177. }
  18178. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  18179. if (ret != 0) {
  18180. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18181. }
  18182. #ifndef NO_SIG_WRAPPER
  18183. modLen = 2048;
  18184. #endif
  18185. #else
  18186. #error Not supported yet!
  18187. #endif
  18188. #endif
  18189. key->n.dp[0] &= (mp_digit)-2;
  18190. if (ret != 0) {
  18191. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18192. }
  18193. /* after loading in key use tmp as the test buffer */
  18194. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  18195. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM))) && \
  18196. !defined(WOLFSSL_XILINX_CRYPT)
  18197. /* The ARM64_ASM code that was FIPS validated did not return these expected
  18198. * failure codes. These tests cases were added after the assembly was
  18199. * in-lined in the module and validated, these tests will be available in
  18200. * the 140-3 module */
  18201. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18202. inLen = 32;
  18203. outSz = wc_RsaEncryptSize(key);
  18204. XMEMSET(tmp, 7, plainSz);
  18205. ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng);
  18206. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18207. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18208. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18209. {
  18210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18211. }
  18212. ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key);
  18213. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18214. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18215. {
  18216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18217. }
  18218. #endif
  18219. #ifdef WC_RSA_BLINDING
  18220. ret = wc_RsaSetRNG(key, rng);
  18221. if (ret < 0) {
  18222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18223. }
  18224. #endif
  18225. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18226. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18227. ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
  18228. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18229. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18230. {
  18231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18232. }
  18233. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18234. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18235. ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key);
  18236. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18237. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18238. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18239. {
  18240. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18241. }
  18242. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18243. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  18244. /* if making it to this point of code without hitting an ERROR_OUT then
  18245. * all tests have passed */
  18246. ret = 0;
  18247. exit_rsa_even_mod:
  18248. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18249. WC_FREE_VAR(out, HEAP_HINT);
  18250. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18251. WC_FREE_VAR(plain, HEAP_HINT);
  18252. #endif
  18253. (void)out;
  18254. (void)outSz;
  18255. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18256. (void)plain;
  18257. (void)plainSz;
  18258. #endif
  18259. (void)inLen;
  18260. (void)rng;
  18261. return ret;
  18262. }
  18263. #endif /* WOLFSSL_HAVE_SP_RSA */
  18264. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  18265. static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp)
  18266. {
  18267. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18268. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18269. #ifdef WOLFSSL_TEST_CERT
  18270. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18271. #endif
  18272. #else
  18273. RsaKey caKey[1];
  18274. #ifdef WOLFSSL_TEST_CERT
  18275. DecodedCert decode[1];
  18276. #endif
  18277. #endif
  18278. byte* der = NULL;
  18279. wc_test_ret_t ret;
  18280. Cert* myCert = NULL;
  18281. int certSz;
  18282. size_t bytes3;
  18283. word32 idx3 = 0;
  18284. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  18285. XFILE file3;
  18286. #endif
  18287. #if defined(WOLFSSL_ALT_NAMES) && !defined(NO_ASN_TIME)
  18288. struct tm beforeTime;
  18289. struct tm afterTime;
  18290. #endif
  18291. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  18292. (void)keypub;
  18293. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18294. if (caKey == NULL)
  18295. ERROR_OUT(MEMORY_E, exit_rsa);
  18296. #ifdef WOLFSSL_TEST_CERT
  18297. if (decode == NULL)
  18298. ERROR_OUT(MEMORY_E, exit_rsa);
  18299. #endif
  18300. #endif
  18301. XMEMSET(caKey, 0, sizeof *caKey);
  18302. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18303. if (der == NULL) {
  18304. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18305. }
  18306. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18307. if (myCert == NULL) {
  18308. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18309. }
  18310. /* self signed */
  18311. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18312. if (ret != 0) {
  18313. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18314. }
  18315. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18316. XMEMCPY(myCert->serial, mySerial, sizeof(mySerial));
  18317. myCert->serialSz = (int)sizeof(mySerial);
  18318. myCert->isCA = 1;
  18319. #ifndef NO_SHA256
  18320. myCert->sigType = CTC_SHA256wRSA;
  18321. #else
  18322. myCert->sigType = CTC_SHAwRSA;
  18323. #endif
  18324. #ifdef WOLFSSL_CERT_EXT
  18325. /* add Policies */
  18326. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18327. CTC_MAX_CERTPOL_SZ);
  18328. XSTRNCPY(myCert->certPolicies[1], "1.2.840.113549.1.9.16.6.5",
  18329. CTC_MAX_CERTPOL_SZ);
  18330. myCert->certPoliciesNb = 2;
  18331. /* add SKID from the Public Key */
  18332. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL);
  18333. if (ret != 0) {
  18334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18335. }
  18336. /* add AKID from the Public Key */
  18337. ret = wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL);
  18338. if (ret != 0) {
  18339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18340. }
  18341. /* add Key Usage */
  18342. ret = wc_SetKeyUsage(myCert,"cRLSign,keyCertSign");
  18343. if (ret != 0) {
  18344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18345. }
  18346. #ifdef WOLFSSL_EKU_OID
  18347. {
  18348. const char unique[] = "2.16.840.1.111111.100.1.10.1";
  18349. ret = wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0,
  18350. HEAP_HINT);
  18351. if (ret != 0) {
  18352. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18353. }
  18354. }
  18355. #endif /* WOLFSSL_EKU_OID */
  18356. #endif /* WOLFSSL_CERT_EXT */
  18357. do {
  18358. #if defined(WOLFSSL_ASYNC_CRYPT)
  18359. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18360. #endif
  18361. if (ret >= 0) {
  18362. ret = wc_MakeSelfCert(myCert, der, FOURK_BUF, key, rng);
  18363. }
  18364. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18365. if (ret < 0) {
  18366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18367. }
  18368. certSz = (int)ret;
  18369. #ifdef WOLFSSL_TEST_CERT
  18370. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18371. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18372. if (ret != 0) {
  18373. FreeDecodedCert(decode);
  18374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18375. }
  18376. FreeDecodedCert(decode);
  18377. #endif
  18378. ret = SaveDerAndPem(der, certSz, certDerFile, certPemFile,
  18379. CERT_TYPE);
  18380. if (ret != 0) {
  18381. goto exit_rsa;
  18382. }
  18383. /* Setup Certificate */
  18384. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18385. if (ret < 0) {
  18386. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18387. }
  18388. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  18389. /* Get CA Cert for testing */
  18390. #ifdef USE_CERT_BUFFERS_1024
  18391. XMEMCPY(tmp, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  18392. bytes3 = sizeof_ca_cert_der_1024;
  18393. #elif defined(USE_CERT_BUFFERS_2048)
  18394. XMEMCPY(tmp, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  18395. bytes3 = sizeof_ca_cert_der_2048;
  18396. #else
  18397. file3 = XFOPEN(rsaCaCertDerFile, "rb");
  18398. if (!file3) {
  18399. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18400. }
  18401. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18402. XFCLOSE(file3);
  18403. if (bytes3 == 0)
  18404. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18405. #endif /* USE_CERT_BUFFERS */
  18406. #if defined(WOLFSSL_ALT_NAMES)
  18407. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \
  18408. !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  18409. ret = wc_SetAltNames(myCert, rsaCaCertFile);
  18410. if (ret != 0)
  18411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18412. #endif
  18413. /* get alt names from der */
  18414. ret = wc_SetAltNamesBuffer(myCert, tmp, (int)bytes3);
  18415. if (ret != 0)
  18416. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18417. /* get dates from der */
  18418. ret = wc_SetDatesBuffer(myCert, tmp, (int)bytes3);
  18419. if (ret != 0)
  18420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18421. #ifndef NO_ASN_TIME
  18422. ret = wc_GetCertDates(myCert, &beforeTime, &afterTime);
  18423. if (ret < 0)
  18424. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18425. #endif
  18426. #endif /* WOLFSSL_ALT_NAMES */
  18427. #endif /* WOLFSSL_ALT_NAMES || HAVE_PKCS7 */
  18428. /* Get CA Key */
  18429. #ifdef USE_CERT_BUFFERS_1024
  18430. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18431. bytes3 = sizeof_ca_key_der_1024;
  18432. #elif defined(USE_CERT_BUFFERS_2048)
  18433. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18434. bytes3 = sizeof_ca_key_der_2048;
  18435. #else
  18436. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18437. if (!file3) {
  18438. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18439. }
  18440. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18441. XFCLOSE(file3);
  18442. if (bytes3 == 0)
  18443. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18444. #endif /* USE_CERT_BUFFERS */
  18445. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18446. if (ret != 0)
  18447. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18448. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18449. if (ret != 0)
  18450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18451. #ifndef NO_SHA256
  18452. myCert->sigType = CTC_SHA256wRSA;
  18453. #else
  18454. myCert->sigType = CTC_SHAwRSA;
  18455. #endif
  18456. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18457. #ifdef WOLFSSL_CERT_EXT
  18458. /* add Policies */
  18459. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18460. CTC_MAX_CERTPOL_SZ);
  18461. myCert->certPoliciesNb =1;
  18462. /* add SKID from the Public Key */
  18463. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL);
  18464. if (ret != 0)
  18465. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18466. /* add AKID from the CA certificate */
  18467. #if defined(USE_CERT_BUFFERS_2048)
  18468. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18469. sizeof_ca_cert_der_2048);
  18470. #elif defined(USE_CERT_BUFFERS_1024)
  18471. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18472. sizeof_ca_cert_der_1024);
  18473. #else
  18474. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18475. #endif
  18476. if (ret != 0)
  18477. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18478. /* add Key Usage */
  18479. ret = wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement");
  18480. if (ret != 0)
  18481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18482. #endif /* WOLFSSL_CERT_EXT */
  18483. #if defined(USE_CERT_BUFFERS_2048)
  18484. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18485. sizeof_ca_cert_der_2048);
  18486. #elif defined(USE_CERT_BUFFERS_1024)
  18487. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18488. sizeof_ca_cert_der_1024);
  18489. #else
  18490. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18491. #endif
  18492. if (ret < 0)
  18493. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18494. certSz = wc_MakeCert(myCert, der, FOURK_BUF, key, NULL, rng);
  18495. if (certSz < 0) {
  18496. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18497. }
  18498. ret = 0;
  18499. do {
  18500. #if defined(WOLFSSL_ASYNC_CRYPT)
  18501. ret = wc_AsyncWait(ret, &caKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18502. #endif
  18503. if (ret >= 0) {
  18504. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der, FOURK_BUF,
  18505. caKey, NULL, rng);
  18506. }
  18507. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18508. if (ret < 0)
  18509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18510. certSz = (int)ret;
  18511. #ifdef WOLFSSL_TEST_CERT
  18512. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18513. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18514. if (ret != 0) {
  18515. FreeDecodedCert(decode);
  18516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18517. }
  18518. FreeDecodedCert(decode);
  18519. #endif
  18520. ret = SaveDerAndPem(der, certSz, otherCertDerFile, otherCertPemFile,
  18521. CERT_TYPE);
  18522. if (ret != 0) {
  18523. goto exit_rsa;
  18524. }
  18525. exit_rsa:
  18526. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18527. if (caKey != NULL) {
  18528. wc_FreeRsaKey(caKey);
  18529. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18530. }
  18531. #ifdef WOLFSSL_TEST_CERT
  18532. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18533. #endif
  18534. #else
  18535. wc_FreeRsaKey(caKey);
  18536. #endif
  18537. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18538. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18539. return ret;
  18540. }
  18541. #endif
  18542. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP) && \
  18543. defined(WOLFSSL_CERT_GEN)
  18544. /* Make Cert / Sign example for ECC cert and RSA CA */
  18545. static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
  18546. {
  18547. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18548. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18549. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18550. ecc_key *caEccKeyPub = (ecc_key *)XMALLOC(sizeof *caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18551. #ifdef WOLFSSL_TEST_CERT
  18552. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18553. #endif
  18554. #else
  18555. RsaKey caKey[1];
  18556. ecc_key caEccKey[1];
  18557. ecc_key caEccKeyPub[1];
  18558. #ifdef WOLFSSL_TEST_CERT
  18559. DecodedCert decode[1];
  18560. #endif
  18561. #endif
  18562. byte* der = NULL;
  18563. Cert* myCert = NULL;
  18564. int certSz;
  18565. size_t bytes3;
  18566. word32 idx3 = 0;
  18567. #if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
  18568. || !defined(USE_CERT_BUFFERS_256)
  18569. #ifndef NO_FILESYSTEM
  18570. XFILE file3;
  18571. #endif
  18572. #endif
  18573. wc_test_ret_t ret;
  18574. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18575. if ((caKey == NULL) || (caEccKey == NULL) || (caEccKeyPub == NULL)
  18576. #ifdef WOLFSSL_TEST_CERT
  18577. || (decode == NULL)
  18578. #endif
  18579. )
  18580. ERROR_OUT(MEMORY_E, exit_rsa);
  18581. #endif
  18582. XMEMSET(caKey, 0, sizeof *caKey);
  18583. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  18584. XMEMSET(caEccKeyPub, 0, sizeof *caEccKeyPub);
  18585. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18586. if (der == NULL) {
  18587. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18588. }
  18589. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18590. if (myCert == NULL) {
  18591. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18592. }
  18593. /* Get CA Key */
  18594. #ifdef USE_CERT_BUFFERS_1024
  18595. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18596. bytes3 = sizeof_ca_key_der_1024;
  18597. #elif defined(USE_CERT_BUFFERS_2048)
  18598. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18599. bytes3 = sizeof_ca_key_der_2048;
  18600. #else
  18601. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18602. if (!file3) {
  18603. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18604. }
  18605. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18606. XFCLOSE(file3);
  18607. if (bytes3 == 0)
  18608. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18609. #endif /* USE_CERT_BUFFERS */
  18610. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18611. if (ret != 0)
  18612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18613. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18614. if (ret != 0)
  18615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18616. /* Get Cert Key */
  18617. #if defined(USE_CERT_BUFFERS_256)
  18618. {
  18619. XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
  18620. bytes3 = sizeof_ecc_key_pub_der_256;
  18621. }
  18622. #elif !defined(NO_FILESYSTEM)
  18623. {
  18624. file3 = XFOPEN(eccKeyPubFileDer, "rb");
  18625. if (!file3) {
  18626. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18627. }
  18628. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18629. XFCLOSE(file3);
  18630. if (bytes3 == 0)
  18631. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18632. }
  18633. #else
  18634. {
  18635. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
  18636. ERROR_OUT(ASN_PARSE_E, exit_rsa);
  18637. }
  18638. #endif
  18639. ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
  18640. if (ret != 0)
  18641. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18642. idx3 = 0;
  18643. ret = wc_EccPublicKeyDecode(tmp, &idx3, caEccKeyPub, (word32)bytes3);
  18644. if (ret != 0)
  18645. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18646. /* Setup Certificate */
  18647. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18648. if (ret != 0)
  18649. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18650. #ifndef NO_SHA256
  18651. myCert->sigType = CTC_SHA256wRSA;
  18652. #else
  18653. myCert->sigType = CTC_SHAwRSA;
  18654. #endif
  18655. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18656. #ifdef WOLFSSL_CERT_EXT
  18657. /* add Policies */
  18658. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  18659. CTC_MAX_CERTPOL_SZ);
  18660. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  18661. CTC_MAX_CERTPOL_SZ);
  18662. myCert->certPoliciesNb = 2;
  18663. /* add SKID from the Public Key */
  18664. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub);
  18665. if (ret != 0)
  18666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18667. /* add AKID from the CA certificate */
  18668. #if defined(USE_CERT_BUFFERS_2048)
  18669. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18670. sizeof_ca_cert_der_2048);
  18671. #elif defined(USE_CERT_BUFFERS_1024)
  18672. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18673. sizeof_ca_cert_der_1024);
  18674. #else
  18675. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18676. #endif
  18677. if (ret != 0)
  18678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18679. /* add Key Usage */
  18680. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  18681. if (ret != 0)
  18682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18683. #endif /* WOLFSSL_CERT_EXT */
  18684. #if defined(USE_CERT_BUFFERS_2048)
  18685. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18686. sizeof_ca_cert_der_2048);
  18687. #elif defined(USE_CERT_BUFFERS_1024)
  18688. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18689. sizeof_ca_cert_der_1024);
  18690. #else
  18691. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18692. #endif
  18693. if (ret < 0)
  18694. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18695. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, caEccKeyPub, rng);
  18696. if (certSz < 0) {
  18697. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18698. }
  18699. ret = 0;
  18700. do {
  18701. #if defined(WOLFSSL_ASYNC_CRYPT)
  18702. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18703. #endif
  18704. if (ret >= 0) {
  18705. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  18706. FOURK_BUF, caKey, NULL, rng);
  18707. }
  18708. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18709. if (ret < 0)
  18710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18711. certSz = (int)ret;
  18712. #ifdef WOLFSSL_TEST_CERT
  18713. InitDecodedCert(decode, der, certSz, 0);
  18714. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18715. if (ret != 0) {
  18716. FreeDecodedCert(decode);
  18717. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18718. }
  18719. FreeDecodedCert(decode);
  18720. #endif
  18721. ret = SaveDerAndPem(der, certSz, certEccRsaDerFile, certEccRsaPemFile,
  18722. CERT_TYPE);
  18723. if (ret != 0) {
  18724. goto exit_rsa;
  18725. }
  18726. exit_rsa:
  18727. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18728. if (caKey != NULL) {
  18729. wc_FreeRsaKey(caKey);
  18730. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18731. }
  18732. if (caEccKey != NULL) {
  18733. wc_ecc_free(caEccKey);
  18734. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18735. }
  18736. if (caEccKeyPub != NULL) {
  18737. wc_ecc_free(caEccKeyPub);
  18738. XFREE(caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18739. }
  18740. #ifdef WOLFSSL_TEST_CERT
  18741. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18742. #endif
  18743. #else
  18744. wc_FreeRsaKey(caKey);
  18745. wc_ecc_free(caEccKey);
  18746. wc_ecc_free(caEccKeyPub);
  18747. #endif
  18748. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18749. myCert = NULL;
  18750. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18751. der = NULL;
  18752. if (ret >= 0)
  18753. ret = 0;
  18754. return ret;
  18755. }
  18756. #endif /* !NO_RSA && HAVE_ECC && WOLFSSL_CERT_GEN */
  18757. #ifdef WOLFSSL_KEY_GEN
  18758. static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
  18759. {
  18760. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18761. RsaKey *genKey = (RsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18762. #else
  18763. RsaKey genKey[1];
  18764. #endif
  18765. wc_test_ret_t ret;
  18766. #ifndef WOLFSSL_NO_MALLOC
  18767. byte* der = NULL;
  18768. #else
  18769. byte der[1280];
  18770. #endif
  18771. #ifndef WOLFSSL_CRYPTOCELL
  18772. word32 idx = 0;
  18773. #endif
  18774. int derSz = 0;
  18775. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FIPS) && \
  18776. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18777. int keySz = 1024;
  18778. #else
  18779. int keySz = 2048;
  18780. #endif
  18781. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18782. if (! genKey)
  18783. ERROR_OUT(MEMORY_E, exit_rsa);
  18784. #endif
  18785. XMEMSET(genKey, 0, sizeof *genKey);
  18786. ret = wc_InitRsaKey_ex(genKey, HEAP_HINT, devId);
  18787. if (ret != 0)
  18788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18789. #ifdef HAVE_FIPS
  18790. for (;;) {
  18791. #endif
  18792. ret = wc_MakeRsaKey(genKey, keySz, WC_RSA_EXPONENT, rng);
  18793. #if defined(WOLFSSL_ASYNC_CRYPT)
  18794. ret = wc_AsyncWait(ret, &genKey->asyncDev, WC_ASYNC_FLAG_NONE);
  18795. #endif
  18796. #ifdef HAVE_FIPS
  18797. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  18798. continue;
  18799. break;
  18800. }
  18801. #endif
  18802. if (ret != 0)
  18803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18804. TEST_SLEEP();
  18805. #ifdef WOLFSSL_RSA_KEY_CHECK
  18806. ret = wc_CheckRsaKey(genKey);
  18807. if (ret != 0)
  18808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18809. #endif
  18810. #ifndef WOLFSSL_NO_MALLOC
  18811. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18812. if (der == NULL) {
  18813. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18814. }
  18815. derSz = FOURK_BUF;
  18816. #else
  18817. derSz = sizeof(der);
  18818. #endif
  18819. derSz = wc_RsaKeyToDer(genKey, der, derSz);
  18820. if (derSz < 0) {
  18821. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  18822. }
  18823. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  18824. PRIVATEKEY_TYPE);
  18825. if (ret != 0) {
  18826. goto exit_rsa;
  18827. }
  18828. wc_FreeRsaKey(genKey);
  18829. ret = wc_InitRsaKey(genKey, HEAP_HINT);
  18830. if (ret != 0)
  18831. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18832. #ifndef WOLFSSL_CRYPTOCELL
  18833. idx = 0;
  18834. /* The private key part of the key gen pairs from cryptocell can't be exported */
  18835. ret = wc_RsaPrivateKeyDecode(der, &idx, genKey, (word32)derSz);
  18836. if (ret != 0)
  18837. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18838. #endif /* WOLFSSL_CRYPTOCELL */
  18839. exit_rsa:
  18840. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18841. if (genKey) {
  18842. wc_FreeRsaKey(genKey);
  18843. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18844. }
  18845. #else
  18846. wc_FreeRsaKey(genKey);
  18847. #endif
  18848. #ifndef WOLFSSL_NO_MALLOC
  18849. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18850. der = NULL;
  18851. #endif
  18852. return ret;
  18853. }
  18854. #endif
  18855. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18856. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) && \
  18857. (!defined(HAVE_FIPS) || \
  18858. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  18859. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  18860. static wc_test_ret_t rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng)
  18861. {
  18862. wc_test_ret_t ret = 0;
  18863. word32 idx = 0;
  18864. const char inStr[] = TEST_STRING;
  18865. const word32 inLen = (word32)TEST_STRING_SZ;
  18866. const word32 outSz = RSA_TEST_BYTES;
  18867. const word32 plainSz = RSA_TEST_BYTES;
  18868. byte* res = NULL;
  18869. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18870. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18871. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18872. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18873. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18874. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18875. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18876. if (in == NULL || out == NULL || plain == NULL)
  18877. ERROR_OUT(MEMORY_E, exit_rsa);
  18878. #endif
  18879. XMEMCPY(in, inStr, inLen);
  18880. #ifndef NO_SHA
  18881. do {
  18882. #if defined(WOLFSSL_ASYNC_CRYPT)
  18883. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18884. #endif
  18885. if (ret >= 0) {
  18886. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18887. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18888. }
  18889. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18890. if (ret < 0)
  18891. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18892. TEST_SLEEP();
  18893. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18894. idx = (word32)ret;
  18895. do {
  18896. #if defined(WOLFSSL_ASYNC_CRYPT)
  18897. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18898. #endif
  18899. if (ret >= 0) {
  18900. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18901. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18902. }
  18903. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18904. if (ret < 0)
  18905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18906. if (XMEMCMP(plain, in, inLen)) {
  18907. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18908. }
  18909. TEST_SLEEP();
  18910. #endif /* NO_SHA */
  18911. #endif
  18912. #ifndef NO_SHA256
  18913. XMEMSET(plain, 0, plainSz);
  18914. do {
  18915. #if defined(WOLFSSL_ASYNC_CRYPT)
  18916. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18917. #endif
  18918. if (ret >= 0) {
  18919. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18920. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18921. }
  18922. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18923. if (ret < 0)
  18924. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18925. TEST_SLEEP();
  18926. idx = (word32)ret;
  18927. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18928. do {
  18929. #if defined(WOLFSSL_ASYNC_CRYPT)
  18930. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18931. #endif
  18932. if (ret >= 0) {
  18933. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18934. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18935. }
  18936. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18937. if (ret < 0)
  18938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18939. if (XMEMCMP(plain, in, inLen)) {
  18940. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18941. }
  18942. TEST_SLEEP();
  18943. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18944. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18945. do {
  18946. #if defined(WOLFSSL_ASYNC_CRYPT)
  18947. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18948. #endif
  18949. if (ret >= 0) {
  18950. ret = wc_RsaPrivateDecryptInline_ex(out, idx, &res, key,
  18951. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18952. }
  18953. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18954. if (ret < 0)
  18955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18956. if (ret != (int)inLen) {
  18957. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18958. }
  18959. if (XMEMCMP(res, in, inLen)) {
  18960. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18961. }
  18962. TEST_SLEEP();
  18963. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18964. /* check fails if not using the same optional label */
  18965. XMEMSET(plain, 0, plainSz);
  18966. do {
  18967. #if defined(WOLFSSL_ASYNC_CRYPT)
  18968. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18969. #endif
  18970. if (ret >= 0) {
  18971. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18972. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18973. }
  18974. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18975. if (ret < 0)
  18976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18977. TEST_SLEEP();
  18978. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18979. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18980. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18981. /* label is unused in cryptocell and SE050 so it won't detect decrypt error
  18982. * due to label */
  18983. idx = (word32)ret;
  18984. do {
  18985. #if defined(WOLFSSL_ASYNC_CRYPT)
  18986. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18987. #endif
  18988. if (ret >= 0) {
  18989. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18990. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18991. }
  18992. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18993. if (ret > 0) { /* in this case decrypt should fail */
  18994. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18995. }
  18996. ret = 0;
  18997. TEST_SLEEP();
  18998. #endif /* !HAVE_CAVIUM */
  18999. /* check using optional label with encrypt/decrypt */
  19000. XMEMSET(plain, 0, plainSz);
  19001. do {
  19002. #if defined(WOLFSSL_ASYNC_CRYPT)
  19003. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19004. #endif
  19005. if (ret >= 0) {
  19006. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19007. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19008. }
  19009. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19010. if (ret < 0)
  19011. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19012. TEST_SLEEP();
  19013. idx = (word32)ret;
  19014. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19015. do {
  19016. #if defined(WOLFSSL_ASYNC_CRYPT)
  19017. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19018. #endif
  19019. if (ret >= 0) {
  19020. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19021. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19022. }
  19023. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19024. if (ret < 0)
  19025. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19026. if (XMEMCMP(plain, in, inLen)) {
  19027. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19028. }
  19029. TEST_SLEEP();
  19030. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19031. #ifndef NO_SHA
  19032. /* check fail using mismatch hash algorithms */
  19033. XMEMSET(plain, 0, plainSz);
  19034. do {
  19035. #if defined(WOLFSSL_ASYNC_CRYPT)
  19036. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19037. #endif
  19038. if (ret >= 0) {
  19039. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19040. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, in, inLen);
  19041. }
  19042. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19043. if (ret < 0)
  19044. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19045. TEST_SLEEP();
  19046. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  19047. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19048. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  19049. idx = (word32)ret;
  19050. do {
  19051. #if defined(WOLFSSL_ASYNC_CRYPT)
  19052. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19053. #endif
  19054. if (ret >= 0) {
  19055. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19056. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256,
  19057. in, inLen);
  19058. }
  19059. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19060. if (ret > 0) { /* should fail */
  19061. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19062. }
  19063. ret = 0;
  19064. TEST_SLEEP();
  19065. #endif /* !HAVE_CAVIUM */
  19066. #endif /* NO_SHA */
  19067. #endif /* NO_SHA256 */
  19068. #ifdef WOLFSSL_SHA512
  19069. /* Check valid RSA key size is used while using hash length of SHA512
  19070. If key size is less than (hash length * 2) + 2 then is invalid use
  19071. and test, since OAEP padding requires this.
  19072. BAD_FUNC_ARG is returned when this case is not met */
  19073. if (wc_RsaEncryptSize(key) > ((int)WC_SHA512_DIGEST_SIZE * 2) + 2) {
  19074. XMEMSET(plain, 0, plainSz);
  19075. do {
  19076. #if defined(WOLFSSL_ASYNC_CRYPT)
  19077. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19078. #endif
  19079. if (ret >= 0) {
  19080. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19081. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19082. }
  19083. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19084. if (ret < 0)
  19085. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19086. TEST_SLEEP();
  19087. idx = (word32)ret;
  19088. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19089. do {
  19090. #if defined(WOLFSSL_ASYNC_CRYPT)
  19091. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19092. #endif
  19093. if (ret >= 0) {
  19094. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19095. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19096. }
  19097. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19098. if (ret < 0)
  19099. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19100. if (XMEMCMP(plain, in, inLen)) {
  19101. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19102. }
  19103. TEST_SLEEP();
  19104. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19105. }
  19106. #endif /* WOLFSSL_SHA512 */
  19107. /* check using pkcsv15 padding with _ex API */
  19108. XMEMSET(plain, 0, plainSz);
  19109. do {
  19110. #if defined(WOLFSSL_ASYNC_CRYPT)
  19111. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19112. #endif
  19113. if (ret >= 0) {
  19114. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19115. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19116. }
  19117. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19118. if (ret < 0)
  19119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19120. TEST_SLEEP();
  19121. idx = (word32)ret;
  19122. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19123. do {
  19124. #if defined(WOLFSSL_ASYNC_CRYPT)
  19125. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19126. #endif
  19127. if (ret >= 0) {
  19128. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19129. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19130. }
  19131. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19132. if (ret < 0)
  19133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19134. if (XMEMCMP(plain, in, inLen)) {
  19135. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19136. }
  19137. TEST_SLEEP();
  19138. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19139. exit_rsa:
  19140. WC_FREE_VAR(in, HEAP_HINT);
  19141. WC_FREE_VAR(out, HEAP_HINT);
  19142. WC_FREE_VAR(plain, HEAP_HINT);
  19143. (void)idx;
  19144. (void)inStr;
  19145. (void)res;
  19146. if (ret >= 0)
  19147. ret = 0;
  19148. return ret;
  19149. }
  19150. #endif
  19151. #endif
  19152. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
  19153. {
  19154. wc_test_ret_t ret;
  19155. size_t bytes = 0;
  19156. WC_RNG rng;
  19157. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19158. byte* tmp = NULL;
  19159. byte* der = NULL;
  19160. RsaKey *key = NULL;
  19161. #else
  19162. RsaKey key[1];
  19163. byte tmp[FOURK_BUF];
  19164. #endif
  19165. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19166. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19167. RsaKey *keypub = NULL;
  19168. #else
  19169. RsaKey keypub[1];
  19170. #endif
  19171. #endif
  19172. word32 idx = 0;
  19173. const char inStr[] = TEST_STRING;
  19174. const word32 inLen = (word32)TEST_STRING_SZ;
  19175. const word32 outSz = RSA_TEST_BYTES;
  19176. const word32 plainSz = RSA_TEST_BYTES;
  19177. byte* res = NULL;
  19178. #ifndef NO_SIG_WRAPPER
  19179. int modLen;
  19180. #endif
  19181. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19182. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  19183. !defined(NO_FILESYSTEM)
  19184. XFILE file;
  19185. #ifdef WOLFSSL_TEST_CERT
  19186. XFILE file2;
  19187. #endif
  19188. #endif
  19189. #ifdef WOLFSSL_TEST_CERT
  19190. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19191. DecodedCert *cert = (DecodedCert *)XMALLOC(sizeof *cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19192. #else
  19193. DecodedCert cert[1];
  19194. #endif
  19195. #ifndef NO_ASN_TIME
  19196. struct tm timearg;
  19197. const byte* date;
  19198. byte dateFormat;
  19199. int dateLength;
  19200. #endif
  19201. #endif
  19202. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19203. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19204. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19205. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19206. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19207. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19208. WOLFSSL_ENTER("rsa_test");
  19209. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  19210. if (in == NULL || out == NULL || plain == NULL)
  19211. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19212. #endif
  19213. XMEMCPY(in, inStr, inLen);
  19214. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19215. key = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19216. if (key == NULL)
  19217. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19218. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19219. keypub = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19220. if (keypub == NULL)
  19221. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19222. #endif
  19223. #ifdef WOLFSSL_TEST_CERT
  19224. if (cert == NULL)
  19225. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19226. #endif
  19227. #else /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19228. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19229. if (ret != 0)
  19230. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19231. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19232. ret = wc_InitRsaKey_ex(keypub, HEAP_HINT, devId);
  19233. if (ret != 0)
  19234. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19235. #endif
  19236. #endif /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19237. /* initialize stack structures */
  19238. XMEMSET(&rng, 0, sizeof(rng));
  19239. #if !defined(NO_ASN)
  19240. ret = rsa_decode_test(key);
  19241. if (ret != 0)
  19242. ERROR_OUT(ret, exit_rsa);
  19243. #endif
  19244. #ifdef USE_CERT_BUFFERS_1024
  19245. bytes = (size_t)sizeof_client_key_der_1024;
  19246. if (bytes < (size_t)sizeof_client_cert_der_1024)
  19247. bytes = (size_t)sizeof_client_cert_der_1024;
  19248. #elif defined(USE_CERT_BUFFERS_2048)
  19249. bytes = (size_t)sizeof_client_key_der_2048;
  19250. if (bytes < (size_t)sizeof_client_cert_der_2048)
  19251. bytes = (size_t)sizeof_client_cert_der_2048;
  19252. #elif defined(USE_CERT_BUFFERS_3072)
  19253. bytes = (size_t)sizeof_client_key_der_3072;
  19254. if (bytes < (size_t)sizeof_client_cert_der_3072)
  19255. bytes = (size_t)sizeof_client_cert_der_3072;
  19256. #elif defined(USE_CERT_BUFFERS_4096)
  19257. bytes = (size_t)sizeof_client_key_der_4096;
  19258. if (bytes < (size_t)sizeof_client_cert_der_4096)
  19259. bytes = (size_t)sizeof_client_cert_der_4096;
  19260. #else
  19261. bytes = FOURK_BUF;
  19262. #endif
  19263. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19264. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19265. if (tmp == NULL)
  19266. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19267. #endif
  19268. #ifdef USE_CERT_BUFFERS_1024
  19269. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  19270. #elif defined(USE_CERT_BUFFERS_2048)
  19271. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  19272. #elif defined(USE_CERT_BUFFERS_3072)
  19273. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  19274. #elif defined(USE_CERT_BUFFERS_4096)
  19275. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  19276. #elif !defined(NO_FILESYSTEM)
  19277. file = XFOPEN(clientKey, "rb");
  19278. if (!file) {
  19279. err_sys("can't open ./certs/client-key.der, "
  19280. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19281. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19282. }
  19283. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19284. XFCLOSE(file);
  19285. if (bytes == 0)
  19286. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19287. #else
  19288. /* No key to use. */
  19289. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19290. #endif /* USE_CERT_BUFFERS */
  19291. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19292. if (ret != 0)
  19293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19294. #ifndef NO_ASN
  19295. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  19296. if (ret != 0)
  19297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19298. #ifndef NO_SIG_WRAPPER
  19299. modLen = wc_RsaEncryptSize(key);
  19300. #endif
  19301. #else
  19302. #ifdef USE_CERT_BUFFERS_2048
  19303. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  19304. if (ret != 0)
  19305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19306. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  19307. if (ret != 0)
  19308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19309. #ifndef NO_SIG_WRAPPER
  19310. modLen = 2048;
  19311. #endif
  19312. #else
  19313. #error Not supported yet!
  19314. #endif
  19315. #endif
  19316. #ifndef WC_NO_RNG
  19317. #ifndef HAVE_FIPS
  19318. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  19319. #else
  19320. ret = wc_InitRng(&rng);
  19321. #endif
  19322. if (ret != 0)
  19323. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19324. #endif
  19325. #ifndef NO_SIG_WRAPPER
  19326. ret = rsa_sig_test(key, sizeof *key, modLen, &rng);
  19327. if (ret != 0)
  19328. goto exit_rsa;
  19329. #endif
  19330. #ifdef WC_RSA_NONBLOCK
  19331. ret = rsa_nb_test(key, in, inLen, out, outSz, plain, plainSz, &rng);
  19332. if (ret != 0)
  19333. goto exit_rsa;
  19334. #endif
  19335. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19336. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19337. do {
  19338. #if defined(WOLFSSL_ASYNC_CRYPT)
  19339. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19340. #endif
  19341. if (ret >= 0) {
  19342. ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, key, &rng);
  19343. }
  19344. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19345. if (ret < 0)
  19346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19347. TEST_SLEEP();
  19348. #ifdef WC_RSA_BLINDING
  19349. {
  19350. wc_test_ret_t tmpret = ret;
  19351. ret = wc_RsaSetRNG(key, &rng);
  19352. if (ret < 0)
  19353. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19354. ret = tmpret;
  19355. }
  19356. #endif
  19357. idx = (word32)ret; /* save off encrypted length */
  19358. do {
  19359. #if defined(WOLFSSL_ASYNC_CRYPT)
  19360. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19361. #endif
  19362. if (ret >= 0) {
  19363. ret = wc_RsaPrivateDecrypt(out, idx, plain, plainSz, key);
  19364. }
  19365. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19366. if (ret < 0)
  19367. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19368. if (XMEMCMP(plain, in, inLen)) {
  19369. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19370. }
  19371. TEST_SLEEP();
  19372. do {
  19373. #if defined(WOLFSSL_ASYNC_CRYPT)
  19374. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19375. #endif
  19376. if (ret >= 0) {
  19377. ret = wc_RsaPrivateDecryptInline(out, idx, &res, key);
  19378. }
  19379. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19380. if (ret < 0)
  19381. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19382. if (ret != (int)inLen) {
  19383. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19384. }
  19385. if (XMEMCMP(res, in, inLen)) {
  19386. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19387. }
  19388. TEST_SLEEP();
  19389. do {
  19390. #if defined(WOLFSSL_ASYNC_CRYPT)
  19391. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19392. #endif
  19393. if (ret >= 0) {
  19394. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng);
  19395. }
  19396. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19397. if (ret < 0)
  19398. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19399. TEST_SLEEP();
  19400. #elif defined(WOLFSSL_PUBLIC_MP)
  19401. {
  19402. static const byte signature_2048[] = {
  19403. 0x07, 0x6f, 0xc9, 0x85, 0x73, 0x9e, 0x21, 0x79,
  19404. 0x47, 0xf1, 0xa3, 0xd7, 0xf4, 0x27, 0x29, 0xbe,
  19405. 0x99, 0x5d, 0xac, 0xb2, 0x10, 0x3f, 0x95, 0xda,
  19406. 0x89, 0x23, 0xb8, 0x96, 0x13, 0x57, 0x72, 0x30,
  19407. 0xa1, 0xfe, 0x5a, 0x68, 0x9c, 0x99, 0x9d, 0x1e,
  19408. 0x05, 0xa4, 0x80, 0xb0, 0xbb, 0xd9, 0xd9, 0xa1,
  19409. 0x69, 0x97, 0x74, 0xb3, 0x41, 0x21, 0x3b, 0x47,
  19410. 0xf5, 0x51, 0xb1, 0xfb, 0xc7, 0xaa, 0xcc, 0xdc,
  19411. 0xcd, 0x76, 0xa0, 0x28, 0x4d, 0x27, 0x14, 0xa4,
  19412. 0xb9, 0x41, 0x68, 0x7c, 0xb3, 0x66, 0xe6, 0x6f,
  19413. 0x40, 0x76, 0xe4, 0x12, 0xfd, 0xae, 0x29, 0xb5,
  19414. 0x63, 0x60, 0x87, 0xce, 0x49, 0x6b, 0xf3, 0x05,
  19415. 0x9a, 0x14, 0xb5, 0xcc, 0xcd, 0xf7, 0x30, 0x95,
  19416. 0xd2, 0x72, 0x52, 0x1d, 0x5b, 0x7e, 0xef, 0x4a,
  19417. 0x02, 0x96, 0x21, 0x6c, 0x55, 0xa5, 0x15, 0xb1,
  19418. 0x57, 0x63, 0x2c, 0xa3, 0x8e, 0x9d, 0x3d, 0x45,
  19419. 0xcc, 0xb8, 0xe6, 0xa1, 0xc8, 0x59, 0xcd, 0xf5,
  19420. 0xdc, 0x0a, 0x51, 0xb6, 0x9d, 0xfb, 0xf4, 0x6b,
  19421. 0xfd, 0x32, 0x71, 0x6e, 0xcf, 0xcb, 0xb3, 0xd9,
  19422. 0xe0, 0x4a, 0x77, 0x34, 0xd6, 0x61, 0xf5, 0x7c,
  19423. 0xf9, 0xa9, 0xa4, 0xb0, 0x8e, 0x3b, 0xd6, 0x04,
  19424. 0xe0, 0xde, 0x2b, 0x5b, 0x5a, 0xbf, 0xd9, 0xef,
  19425. 0x8d, 0xa3, 0xf5, 0xb1, 0x67, 0xf3, 0xb9, 0x72,
  19426. 0x0a, 0x37, 0x12, 0x35, 0x6c, 0x8e, 0x10, 0x8b,
  19427. 0x38, 0x06, 0x16, 0x4b, 0x20, 0x20, 0x13, 0x00,
  19428. 0x2e, 0x6d, 0xc2, 0x59, 0x23, 0x67, 0x4a, 0x6d,
  19429. 0xa1, 0x46, 0x8b, 0xee, 0xcf, 0x44, 0xb4, 0x3e,
  19430. 0x56, 0x75, 0x00, 0x68, 0xb5, 0x7d, 0x0f, 0x20,
  19431. 0x79, 0x5d, 0x7f, 0x12, 0x15, 0x32, 0x89, 0x61,
  19432. 0x6b, 0x29, 0xb7, 0x52, 0xf5, 0x25, 0xd8, 0x98,
  19433. 0xe8, 0x6f, 0xf9, 0x22, 0xb4, 0xbb, 0xe5, 0xff,
  19434. 0xd0, 0x92, 0x86, 0x9a, 0x88, 0xa2, 0xaf, 0x6b
  19435. };
  19436. ret = sizeof(signature_2048);
  19437. XMEMCPY(out, signature_2048, ret);
  19438. }
  19439. #endif
  19440. #if !defined(WC_NO_RNG) && !defined(WC_NO_RSA_OAEP) && \
  19441. !defined(WOLFSSL_RSA_VERIFY_ONLY) && defined(WOLFSSL_PUBLIC_MP) && \
  19442. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19443. idx = (word32)ret;
  19444. XMEMSET(plain, 0, plainSz);
  19445. do {
  19446. #if defined(WOLFSSL_ASYNC_CRYPT)
  19447. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19448. #endif
  19449. if (ret >= 0) {
  19450. #ifndef WOLFSSL_RSA_VERIFY_INLINE
  19451. #if defined(WOLFSSL_CRYPTOCELL)
  19452. /*
  19453. Cryptocell requires the input data and signature byte array to verify.
  19454. first argument must be the input data
  19455. second argument must be the length of input data
  19456. third argument must be the signature byte array or the output from
  19457. wc_RsaSSL_Sign()
  19458. fourth argument must be the length of the signature byte array
  19459. */
  19460. ret = wc_RsaSSL_Verify(in, inLen, out, outSz, key);
  19461. #else
  19462. ret = wc_RsaSSL_Verify(out, idx, plain, plainSz, key);
  19463. #endif /* WOLFSSL_CRYPTOCELL */
  19464. #else
  19465. byte* dec = NULL;
  19466. ret = wc_RsaSSL_VerifyInline(out, idx, &dec, key);
  19467. if (ret > 0) {
  19468. XMEMCPY(plain, dec, ret);
  19469. }
  19470. #endif
  19471. }
  19472. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19473. if (ret < 0)
  19474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19475. if (XMEMCMP(plain, in, (size_t)ret)) {
  19476. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19477. }
  19478. TEST_SLEEP();
  19479. #endif
  19480. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  19481. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG)
  19482. #if (!defined(HAVE_FIPS) || \
  19483. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  19484. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19485. ret = rsa_oaep_padding_test(key, &rng);
  19486. if (ret != 0)
  19487. goto exit_rsa;
  19488. #endif /* !HAVE_FIPS */
  19489. #endif /* WC_NO_RSA_OAEP && !WC_NO_RNG */
  19490. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  19491. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  19492. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19493. ret = rsa_export_key_test(key);
  19494. if (ret != 0)
  19495. goto exit_rsa;
  19496. #endif
  19497. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19498. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19499. ret = rsa_flatten_test(key);
  19500. if (ret != 0)
  19501. goto exit_rsa;
  19502. #endif
  19503. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_ASN) && \
  19504. !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19505. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  19506. (void)clientCert;
  19507. #endif
  19508. #ifdef WOLFSSL_TEST_CERT
  19509. #ifdef USE_CERT_BUFFERS_1024
  19510. XMEMCPY(tmp, client_cert_der_1024, (size_t)sizeof_client_cert_der_1024);
  19511. bytes = (size_t)sizeof_client_cert_der_1024;
  19512. #elif defined(USE_CERT_BUFFERS_2048)
  19513. XMEMCPY(tmp, client_cert_der_2048, (size_t)sizeof_client_cert_der_2048);
  19514. bytes = (size_t)sizeof_client_cert_der_2048;
  19515. #elif defined(USE_CERT_BUFFERS_3072)
  19516. XMEMCPY(tmp, client_cert_der_3072, (size_t)sizeof_client_cert_der_3072);
  19517. bytes = (size_t)sizeof_client_cert_der_3072;
  19518. #elif defined(USE_CERT_BUFFERS_4096)
  19519. XMEMCPY(tmp, client_cert_der_4096, (size_t)sizeof_client_cert_der_4096);
  19520. bytes = (size_t)sizeof_client_cert_der_4096;
  19521. #elif !defined(NO_FILESYSTEM)
  19522. file2 = XFOPEN(clientCert, "rb");
  19523. if (!file2) {
  19524. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19525. }
  19526. bytes = XFREAD(tmp, 1, FOURK_BUF, file2);
  19527. XFCLOSE(file2);
  19528. if (bytes == 0)
  19529. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19530. #else
  19531. /* No certificate to use. */
  19532. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19533. #endif
  19534. InitDecodedCert(cert, tmp, (word32)bytes, NULL);
  19535. ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL);
  19536. if (ret != 0) {
  19537. FreeDecodedCert(cert);
  19538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19539. }
  19540. #ifndef NO_ASN_TIME
  19541. ret = wc_GetDateInfo(cert->afterDate, cert->afterDateLen, &date,
  19542. &dateFormat, &dateLength);
  19543. if (ret != 0) {
  19544. FreeDecodedCert(cert);
  19545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19546. }
  19547. ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg);
  19548. if (ret != 0) {
  19549. FreeDecodedCert(cert);
  19550. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19551. }
  19552. #endif
  19553. FreeDecodedCert(cert);
  19554. #endif /* WOLFSSL_TEST_CERT */
  19555. #ifdef WOLFSSL_CERT_EXT
  19556. #ifdef USE_CERT_BUFFERS_1024
  19557. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  19558. bytes = sizeof_client_keypub_der_1024;
  19559. #elif defined(USE_CERT_BUFFERS_2048)
  19560. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  19561. bytes = sizeof_client_keypub_der_2048;
  19562. #elif defined(USE_CERT_BUFFERS_3072)
  19563. XMEMCPY(tmp, client_keypub_der_3072, sizeof_client_keypub_der_3072);
  19564. bytes = sizeof_client_keypub_der_3072;
  19565. #elif defined(USE_CERT_BUFFERS_4096)
  19566. XMEMCPY(tmp, client_keypub_der_4096, sizeof_client_keypub_der_4096);
  19567. bytes = sizeof_client_keypub_der_4096;
  19568. #else
  19569. file = XFOPEN(clientKeyPub, "rb");
  19570. if (!file) {
  19571. err_sys("can't open ./certs/client-keyPub.der, "
  19572. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19573. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19574. }
  19575. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19576. XFCLOSE(file);
  19577. if (bytes == 0)
  19578. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19579. #endif /* USE_CERT_BUFFERS */
  19580. ret = wc_InitRsaKey(keypub, HEAP_HINT);
  19581. if (ret != 0)
  19582. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19583. idx = 0;
  19584. ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
  19585. if (ret != 0)
  19586. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19587. #endif /* WOLFSSL_CERT_EXT */
  19588. #ifdef WOLFSSL_KEY_GEN
  19589. ret = rsa_keygen_test(&rng);
  19590. if (ret != 0)
  19591. goto exit_rsa;
  19592. #endif
  19593. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  19594. !defined(WOLFSSL_NO_MALLOC)
  19595. /* Make Cert / Sign example for RSA cert and RSA CA */
  19596. ret = rsa_certgen_test(key, keypub, &rng, tmp);
  19597. if (ret != 0)
  19598. goto exit_rsa;
  19599. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP)
  19600. ret = rsa_ecc_certgen_test(&rng, tmp);
  19601. if (ret != 0)
  19602. goto exit_rsa;
  19603. #endif
  19604. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  19605. {
  19606. Cert *req;
  19607. int derSz;
  19608. #ifndef WOLFSSL_SMALL_STACK
  19609. byte* der = NULL;
  19610. #endif
  19611. req = (Cert *)XMALLOC(sizeof *req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19612. if (! req)
  19613. ERROR_OUT(MEMORY_E, exit_rsa);
  19614. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,DYNAMIC_TYPE_TMP_BUFFER);
  19615. if (der == NULL) {
  19616. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19617. }
  19618. ret = wc_InitCert_ex(req, HEAP_HINT, devId);
  19619. if (ret != 0)
  19620. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19621. req->version = 0;
  19622. req->isCA = 1;
  19623. XSTRNCPY(req->challengePw, "wolf123", CTC_NAME_SIZE);
  19624. XMEMCPY(&req->subject, &certDefaultName, sizeof(CertName));
  19625. #ifndef NO_SHA256
  19626. req->sigType = CTC_SHA256wRSA;
  19627. #else
  19628. req->sigType = CTC_SHAwRSA;
  19629. #endif
  19630. #ifdef WOLFSSL_CERT_EXT
  19631. /* add SKID from the Public Key */
  19632. ret = wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL);
  19633. if (ret != 0)
  19634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19635. /* add Key Usage */
  19636. ret = wc_SetKeyUsage(req, certKeyUsage2);
  19637. if (ret != 0)
  19638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19639. /* add Extended Key Usage */
  19640. ret = wc_SetExtKeyUsage(req,
  19641. "serverAuth,clientAuth,codeSigning,"
  19642. "emailProtection,timeStamping,OCSPSigning");
  19643. if (ret != 0)
  19644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19645. #ifdef WOLFSSL_EKU_OID
  19646. {
  19647. WOLFSSL_SMALL_STACK_STATIC const char unique[] =
  19648. "2.16.840.1.111111.100.1.10.1";
  19649. ret = wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0,
  19650. HEAP_HINT);
  19651. if (ret != 0)
  19652. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19653. }
  19654. #endif /* WOLFSSL_EKU_OID */
  19655. #endif /* WOLFSSL_CERT_EXT */
  19656. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19657. if (derSz < 0) {
  19658. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19659. }
  19660. #ifdef WOLFSSL_CERT_EXT
  19661. /* Try again with "any" flag set, will override all others */
  19662. ret = wc_SetExtKeyUsage(req, "any");
  19663. if (ret != 0)
  19664. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19665. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19666. if (derSz < 0) {
  19667. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19668. }
  19669. #endif /* WOLFSSL_CERT_EXT */
  19670. ret = 0;
  19671. do {
  19672. #if defined(WOLFSSL_ASYNC_CRYPT)
  19673. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19674. #endif
  19675. if (ret >= 0) {
  19676. ret = wc_SignCert(req->bodySz, req->sigType, der, FOURK_BUF,
  19677. key, NULL, &rng);
  19678. }
  19679. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19680. if (ret < 0)
  19681. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19682. derSz = (int)ret;
  19683. ret = SaveDerAndPem(der, derSz, certReqDerFile, certReqPemFile,
  19684. CERTREQ_TYPE);
  19685. if (ret != 0) {
  19686. goto exit_rsa;
  19687. }
  19688. derSz = wc_MakeCertReq_ex(req, der, FOURK_BUF, RSA_TYPE, key);
  19689. if (derSz < 0) {
  19690. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19691. }
  19692. /* Test getting the size of the buffer without providing the buffer.
  19693. * derSz is set to the "largest buffer" we are willing to allocate. */
  19694. derSz = wc_MakeCertReq(req, NULL, 10000, key, NULL);
  19695. if (derSz < 0) {
  19696. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19697. }
  19698. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19699. XFREE(req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19700. der = NULL;
  19701. }
  19702. #endif /* WOLFSSL_CERT_REQ */
  19703. #endif /* WOLFSSL_CERT_GEN */
  19704. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  19705. /* Need to create known good signatures to test with this. */
  19706. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19707. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19708. ret = rsa_pss_test(&rng, key);
  19709. if (ret != 0)
  19710. goto exit_rsa;
  19711. #endif
  19712. #endif
  19713. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  19714. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19715. /* New key to be loaded in rsa_even_mod_test(). */
  19716. if (key != NULL)
  19717. #endif
  19718. wc_FreeRsaKey(key);
  19719. /* New key to be loaded in rsa_even_mod_test(). */
  19720. ret = rsa_even_mod_test(&rng, key);
  19721. #endif
  19722. exit_rsa:
  19723. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19724. wc_DeleteRsaKey(key, &key);
  19725. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19726. wc_DeleteRsaKey(keypub, &keypub);
  19727. #endif
  19728. #ifdef WOLFSSL_TEST_CERT
  19729. XFREE(cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19730. #endif
  19731. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19732. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19733. #else
  19734. wc_FreeRsaKey(key);
  19735. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19736. wc_FreeRsaKey(keypub);
  19737. #endif
  19738. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19739. wc_FreeRng(&rng);
  19740. WC_FREE_VAR(in, HEAP_HINT);
  19741. WC_FREE_VAR(out, HEAP_HINT);
  19742. WC_FREE_VAR(plain, HEAP_HINT);
  19743. (void)res;
  19744. (void)bytes;
  19745. (void)idx;
  19746. (void)in;
  19747. (void)out;
  19748. (void)plain;
  19749. (void)idx;
  19750. (void)inStr;
  19751. (void)inLen;
  19752. (void)outSz;
  19753. (void)plainSz;
  19754. /* ret can be greater then 0 with certgen but all negative values should
  19755. * be returned and treated as an error */
  19756. if (ret >= 0) {
  19757. return 0;
  19758. }
  19759. else {
  19760. return ret;
  19761. }
  19762. }
  19763. #endif /* !NO_RSA */
  19764. #ifndef NO_DH
  19765. static wc_test_ret_t dh_fips_generate_test(WC_RNG *rng)
  19766. {
  19767. wc_test_ret_t ret = 0;
  19768. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19769. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19770. #else
  19771. DhKey key[1];
  19772. #endif
  19773. WOLFSSL_SMALL_STACK_STATIC const byte p[] = {
  19774. 0xc5, 0x7c, 0xa2, 0x4f, 0x4b, 0xd6, 0x8c, 0x3c,
  19775. 0xda, 0xc7, 0xba, 0xaa, 0xea, 0x2e, 0x5c, 0x1e,
  19776. 0x18, 0xb2, 0x7b, 0x8c, 0x55, 0x65, 0x9f, 0xea,
  19777. 0xe0, 0xa1, 0x36, 0x53, 0x2b, 0x36, 0xe0, 0x4e,
  19778. 0x3e, 0x64, 0xa9, 0xe4, 0xfc, 0x8f, 0x32, 0x62,
  19779. 0x97, 0xe4, 0xbe, 0xf7, 0xc1, 0xde, 0x07, 0x5a,
  19780. 0x89, 0x28, 0xf3, 0xfe, 0x4f, 0xfe, 0x68, 0xbc,
  19781. 0xfb, 0x0a, 0x7c, 0xa4, 0xb3, 0x14, 0x48, 0x89,
  19782. 0x9f, 0xaf, 0xb8, 0x43, 0xe2, 0xa0, 0x62, 0x5c,
  19783. 0xb4, 0x88, 0x3f, 0x06, 0x50, 0x11, 0xfe, 0x65,
  19784. 0x8d, 0x49, 0xd2, 0xf5, 0x4b, 0x74, 0x79, 0xdb,
  19785. 0x06, 0x62, 0x92, 0x89, 0xed, 0xda, 0xcb, 0x87,
  19786. 0x37, 0x16, 0xd2, 0xa1, 0x7a, 0xe8, 0xde, 0x92,
  19787. 0xee, 0x3e, 0x41, 0x4a, 0x91, 0x5e, 0xed, 0xf3,
  19788. 0x6c, 0x6b, 0x7e, 0xfd, 0x15, 0x92, 0x18, 0xfc,
  19789. 0xa7, 0xac, 0x42, 0x85, 0x57, 0xe9, 0xdc, 0xda,
  19790. 0x55, 0xc9, 0x8b, 0x28, 0x9e, 0xc1, 0xc4, 0x46,
  19791. 0x4d, 0x88, 0xed, 0x62, 0x8e, 0xdb, 0x3f, 0xb9,
  19792. 0xd7, 0xc8, 0xe3, 0xcf, 0xb8, 0x34, 0x2c, 0xd2,
  19793. 0x6f, 0x28, 0x06, 0x41, 0xe3, 0x66, 0x8c, 0xfc,
  19794. 0x72, 0xff, 0x26, 0x3b, 0x6b, 0x6c, 0x6f, 0x73,
  19795. 0xde, 0xf2, 0x90, 0x29, 0xe0, 0x61, 0x32, 0xc4,
  19796. 0x12, 0x74, 0x09, 0x52, 0xec, 0xf3, 0x1b, 0xa6,
  19797. 0x45, 0x98, 0xac, 0xf9, 0x1c, 0x65, 0x8e, 0x3a,
  19798. 0x91, 0x84, 0x4b, 0x23, 0x8a, 0xb2, 0x3c, 0xc9,
  19799. 0xfa, 0xea, 0xf1, 0x38, 0xce, 0xd8, 0x05, 0xe0,
  19800. 0xfa, 0x44, 0x68, 0x1f, 0xeb, 0xd9, 0x57, 0xb8,
  19801. 0x4a, 0x97, 0x5b, 0x88, 0xc5, 0xf1, 0xbb, 0xb0,
  19802. 0x49, 0xc3, 0x91, 0x7c, 0xd3, 0x13, 0xb9, 0x47,
  19803. 0xbb, 0x91, 0x8f, 0xe5, 0x26, 0x07, 0xab, 0xa9,
  19804. 0xc5, 0xd0, 0x3d, 0x95, 0x41, 0x26, 0x92, 0x9d,
  19805. 0x13, 0x67, 0xf2, 0x7e, 0x11, 0x88, 0xdc, 0x2d
  19806. };
  19807. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  19808. 0x4a, 0x1a, 0xf3, 0xa4, 0x92, 0xe9, 0xee, 0x74,
  19809. 0x6e, 0x57, 0xd5, 0x8c, 0x2c, 0x5b, 0x41, 0x41,
  19810. 0x5e, 0xd4, 0x55, 0x19, 0xdc, 0xd9, 0x32, 0x91,
  19811. 0xf7, 0xfd, 0xc2, 0x57, 0xff, 0x03, 0x14, 0xdb,
  19812. 0xf1, 0xb7, 0x60, 0x0c, 0x43, 0x59, 0x3f, 0xff,
  19813. 0xac, 0xf1, 0x80, 0x9a, 0x15, 0x6f, 0xd8, 0x6e,
  19814. 0xb7, 0x85, 0x18, 0xc8, 0xec, 0x4e, 0x59, 0x4a,
  19815. 0xe2, 0x91, 0x43, 0x4c, 0xeb, 0x95, 0xb6, 0x2e,
  19816. 0x9a, 0xea, 0x53, 0x68, 0x80, 0x64, 0x69, 0x40,
  19817. 0xf9, 0xec, 0xbd, 0x85, 0x89, 0x26, 0x97, 0x67,
  19818. 0xaf, 0xb0, 0xad, 0x00, 0x1b, 0xd4, 0xfd, 0x94,
  19819. 0xd3, 0xe9, 0x92, 0xb1, 0xb4, 0xbc, 0x5a, 0xaa,
  19820. 0x92, 0x80, 0x89, 0x3b, 0x39, 0x05, 0x6c, 0x22,
  19821. 0x26, 0xfe, 0x5a, 0x28, 0x6c, 0x37, 0x50, 0x5a,
  19822. 0x38, 0x99, 0xcf, 0xf3, 0xc1, 0x96, 0x45, 0xdc,
  19823. 0x01, 0xcb, 0x20, 0x87, 0xa5, 0x00, 0x8c, 0xf5,
  19824. 0x4d, 0xc2, 0xef, 0xb8, 0x9b, 0xd1, 0x87, 0xbe,
  19825. 0xed, 0xd5, 0x0a, 0x29, 0x15, 0x34, 0x59, 0x4c,
  19826. 0x3a, 0x05, 0x22, 0x05, 0x44, 0x4f, 0x9f, 0xc8,
  19827. 0x47, 0x12, 0x24, 0x8e, 0xa8, 0x79, 0xe4, 0x67,
  19828. 0xba, 0x4d, 0x5b, 0x75, 0x56, 0x95, 0xeb, 0xe8,
  19829. 0x8a, 0xfa, 0x8e, 0x01, 0x8c, 0x1b, 0x74, 0x63,
  19830. 0xd9, 0x2f, 0xf7, 0xd3, 0x44, 0x8f, 0xa8, 0xf5,
  19831. 0xaf, 0x6c, 0x4f, 0xdb, 0xe7, 0xc9, 0x6c, 0x71,
  19832. 0x22, 0xa3, 0x1d, 0xf1, 0x40, 0xb2, 0xe0, 0x9a,
  19833. 0xb6, 0x72, 0xc9, 0xc0, 0x13, 0x16, 0xa2, 0x4a,
  19834. 0xe1, 0x92, 0xc7, 0x54, 0x23, 0xab, 0x9d, 0xa1,
  19835. 0xa1, 0xe5, 0x0b, 0xed, 0xba, 0xe8, 0x84, 0x37,
  19836. 0xb2, 0xe7, 0xfe, 0x32, 0x8d, 0xfa, 0x1c, 0x53,
  19837. 0x77, 0x97, 0xc7, 0xf3, 0x48, 0xc9, 0xdb, 0x2d,
  19838. 0x75, 0x52, 0x9d, 0x42, 0x51, 0x78, 0x62, 0x68,
  19839. 0x05, 0x45, 0x15, 0xf8, 0xa2, 0x4e, 0xf3, 0x0b
  19840. };
  19841. WOLFSSL_SMALL_STACK_STATIC const byte q[] = {
  19842. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19843. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19844. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19845. 0x40, 0x52, 0xed, 0x41
  19846. };
  19847. WOLFSSL_SMALL_STACK_STATIC const byte q0[] = {
  19848. 0x00,
  19849. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19850. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19851. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19852. 0x40, 0x52, 0xed, 0x41
  19853. };
  19854. byte priv[256];
  19855. byte pub[256];
  19856. word32 privSz = sizeof(priv);
  19857. word32 pubSz = sizeof(pub);
  19858. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19859. if (key == NULL)
  19860. ERROR_OUT(MEMORY_E, exit_gen_test);
  19861. #endif
  19862. /* Parameter Validation testing. */
  19863. ret = wc_DhGenerateKeyPair(NULL, rng, priv, &privSz, pub, &pubSz);
  19864. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19866. ret = wc_DhGenerateKeyPair(key, NULL, priv, &privSz, pub, &pubSz);
  19867. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19868. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19869. ret = wc_DhGenerateKeyPair(key, rng, NULL, &privSz, pub, &pubSz);
  19870. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19872. ret = wc_DhGenerateKeyPair(key, rng, priv, NULL, pub, &pubSz);
  19873. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19875. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, NULL, &pubSz);
  19876. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19877. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19878. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, NULL);
  19879. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19881. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19882. if (ret != 0)
  19883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19884. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q0, sizeof(q0));
  19885. if (ret != 0)
  19886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19887. wc_FreeDhKey(key);
  19888. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19889. if (ret != 0)
  19890. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19891. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q, sizeof(q));
  19892. if (ret != 0)
  19893. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19894. /* Use API. */
  19895. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19896. #if defined(WOLFSSL_ASYNC_CRYPT)
  19897. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19898. #endif
  19899. if (ret != 0)
  19900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19901. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q0, sizeof(q0));
  19902. if (ret != 0)
  19903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19904. wc_FreeDhKey(key);
  19905. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19906. if (ret != 0)
  19907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19908. ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
  19909. if (ret != 0)
  19910. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19911. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q, sizeof(q));
  19912. if (ret != 0)
  19913. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19914. #ifndef HAVE_SELFTEST
  19915. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19916. if (ret != 0)
  19917. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19918. /* Taint the public key so the check fails. */
  19919. pub[0]++;
  19920. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19921. if (ret != WC_NO_ERR_TRACE(MP_CMP_E)) {
  19922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19923. }
  19924. #ifdef WOLFSSL_KEY_GEN
  19925. wc_FreeDhKey(key);
  19926. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19927. if (ret != 0)
  19928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19929. ret = wc_DhGenerateParams(rng, 2048, key);
  19930. if (ret != 0)
  19931. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19932. privSz = sizeof(priv);
  19933. pubSz = sizeof(pub);
  19934. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19935. #if defined(WOLFSSL_ASYNC_CRYPT)
  19936. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19937. #endif
  19938. if (ret != 0)
  19939. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19940. #endif /* WOLFSSL_KEY_GEN */
  19941. #endif /* HAVE_SELFTEST */
  19942. ret = 0;
  19943. exit_gen_test:
  19944. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19945. if (key) {
  19946. wc_FreeDhKey(key);
  19947. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19948. }
  19949. #else
  19950. wc_FreeDhKey(key);
  19951. #endif
  19952. return ret;
  19953. }
  19954. static wc_test_ret_t dh_generate_test(WC_RNG *rng)
  19955. {
  19956. wc_test_ret_t ret = 0;
  19957. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19958. DhKey *smallKey = NULL;
  19959. #else
  19960. DhKey smallKey[1];
  19961. #endif
  19962. byte p[2] = { 1, 7 }; /* 263 in decimal */
  19963. byte g[2] = { 0, 2 };
  19964. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19965. #ifdef WOLFSSL_DH_CONST
  19966. /* the table for constant DH lookup will round to the lowest byte size 21 */
  19967. byte priv[21];
  19968. byte pub[21];
  19969. #else
  19970. byte priv[2];
  19971. byte pub[2];
  19972. #endif
  19973. word32 privSz = sizeof(priv);
  19974. word32 pubSz = sizeof(pub);
  19975. #endif
  19976. int smallKey_inited = 0;
  19977. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19978. if ((smallKey = (DhKey *)XMALLOC(sizeof(*smallKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  19979. return WC_TEST_RET_ENC_ERRNO;
  19980. #endif
  19981. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19982. if (ret != 0)
  19983. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19984. smallKey_inited = 1;
  19985. /* Parameter Validation testing. */
  19986. ret = wc_InitDhKey_ex(NULL, HEAP_HINT, devId);
  19987. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19988. return WC_TEST_RET_ENC_EC(ret);
  19989. wc_FreeDhKey(NULL);
  19990. ret = wc_DhSetKey(NULL, p, sizeof(p), g, sizeof(g));
  19991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19992. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19993. }
  19994. ret = wc_DhSetKey(smallKey, NULL, sizeof(p), g, sizeof(g));
  19995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19996. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19997. }
  19998. ret = wc_DhSetKey(smallKey, p, 0, g, sizeof(g));
  19999. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  20000. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20001. }
  20002. ret = wc_DhSetKey(smallKey, p, sizeof(p), NULL, sizeof(g));
  20003. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  20004. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20005. }
  20006. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, 0);
  20007. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  20008. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20009. }
  20010. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, sizeof(g));
  20011. if (ret != 0)
  20012. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20013. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  20014. /* Use API. */
  20015. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20016. #if defined(WOLFSSL_ASYNC_CRYPT)
  20017. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20018. #endif
  20019. if (ret != 0) {
  20020. ret = WC_TEST_RET_ENC_EC(ret);
  20021. }
  20022. #else
  20023. (void)rng;
  20024. #if defined(HAVE_FIPS) || !defined(WOLFSSL_NO_DH186)
  20025. ret = 0;
  20026. #endif
  20027. #endif
  20028. #if !defined(HAVE_FIPS) && defined(WOLFSSL_NO_DH186)
  20029. {
  20030. byte priv[260];
  20031. byte pub[260];
  20032. word32 privSz = sizeof(priv);
  20033. word32 pubSz = sizeof(pub);
  20034. /* test odd ball param generation with DH */
  20035. wc_FreeDhKey(smallKey);
  20036. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  20037. if (ret != 0)
  20038. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20039. /* should fail since modSz is 16 and group size is 20 */
  20040. ret = wc_DhGenerateParams(rng, 128, smallKey);
  20041. if (ret == 0)
  20042. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20043. ret = wc_DhGenerateParams(rng, 2056, smallKey);
  20044. if (ret != 0)
  20045. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20046. privSz = sizeof(priv);
  20047. pubSz = sizeof(pub);
  20048. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20049. #if defined(WOLFSSL_ASYNC_CRYPT)
  20050. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20051. #endif
  20052. if (ret != 0)
  20053. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20054. }
  20055. #endif /* !HAVE_FIPS and WOLFSSL_NO_DH186 */
  20056. exit_gen_test:
  20057. if (smallKey_inited)
  20058. wc_FreeDhKey(smallKey);
  20059. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20060. XFREE(smallKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20061. #endif
  20062. return ret;
  20063. }
  20064. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20065. typedef struct dh_pubvalue_test {
  20066. const byte* data;
  20067. word32 len;
  20068. } dh_pubvalue_test;
  20069. static wc_test_ret_t dh_test_check_pubvalue(void)
  20070. {
  20071. wc_test_ret_t ret;
  20072. word32 i;
  20073. WOLFSSL_SMALL_STACK_STATIC const byte prime[] = {0x01, 0x00, 0x01};
  20074. WOLFSSL_SMALL_STACK_STATIC const byte pubValZero[] = { 0x00 };
  20075. WOLFSSL_SMALL_STACK_STATIC const byte pubValZeroLong[] = { 0x00, 0x00, 0x00 };
  20076. WOLFSSL_SMALL_STACK_STATIC const byte pubValOne[] = { 0x01 };
  20077. WOLFSSL_SMALL_STACK_STATIC const byte pubValOneLong[] = { 0x00, 0x00, 0x01 };
  20078. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeMinusOne[] = { 0x01, 0x00, 0x00 };
  20079. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeLong[] = {0x00, 0x01, 0x00, 0x01};
  20080. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimePlusOne[] = { 0x01, 0x00, 0x02 };
  20081. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig0[] = { 0x02, 0x00, 0x01 };
  20082. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig1[] = { 0x01, 0x01, 0x01 };
  20083. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooLong[] = { 0x01, 0x00, 0x00, 0x01 };
  20084. const dh_pubvalue_test dh_pubval_fail[] = {
  20085. { prime, sizeof(prime) },
  20086. { pubValZero, sizeof(pubValZero) },
  20087. { pubValZeroLong, sizeof(pubValZeroLong) },
  20088. { pubValOne, sizeof(pubValOne) },
  20089. { pubValOneLong, sizeof(pubValOneLong) },
  20090. { pubValPrimeMinusOne, sizeof(pubValPrimeMinusOne) },
  20091. { pubValPrimeLong, sizeof(pubValPrimeLong) },
  20092. { pubValPrimePlusOne, sizeof(pubValPrimePlusOne) },
  20093. { pubValTooBig0, sizeof(pubValTooBig0) },
  20094. { pubValTooBig1, sizeof(pubValTooBig1) },
  20095. { pubValTooLong, sizeof(pubValTooLong) },
  20096. };
  20097. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwo[] = { 0x02 };
  20098. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwoLong[] = { 0x00, 0x00, 0x02 };
  20099. WOLFSSL_SMALL_STACK_STATIC const byte pubValGood[] = { 0x12, 0x34 };
  20100. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLen[] = { 0x00, 0x12, 0x34 };
  20101. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLong[] = { 0x00, 0x00, 0x12, 0x34 };
  20102. const dh_pubvalue_test dh_pubval_pass[] = {
  20103. { pubValTwo, sizeof(pubValTwo) },
  20104. { pubValTwoLong, sizeof(pubValTwoLong) },
  20105. { pubValGood, sizeof(pubValGood) },
  20106. { pubValGoodLen, sizeof(pubValGoodLen) },
  20107. { pubValGoodLong, sizeof(pubValGoodLong) },
  20108. };
  20109. for (i = 0; i < sizeof(dh_pubval_fail) / sizeof(*dh_pubval_fail); i++) {
  20110. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_fail[i].data,
  20111. dh_pubval_fail[i].len);
  20112. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  20113. return WC_TEST_RET_ENC_I(i);
  20114. }
  20115. for (i = 0; i < sizeof(dh_pubval_pass) / sizeof(*dh_pubval_pass); i++) {
  20116. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_pass[i].data,
  20117. dh_pubval_pass[i].len);
  20118. if (ret != 0)
  20119. return WC_TEST_RET_ENC_I(i);
  20120. }
  20121. return 0;
  20122. }
  20123. #endif
  20124. #if defined(HAVE_FFDHE)
  20125. #if defined(HAVE_FFDHE_4096)
  20126. #define MAX_DH_PRIV_SZ 39
  20127. #define MAX_DH_KEY_SZ 512
  20128. #elif defined(HAVE_FFDHE_3072)
  20129. #define MAX_DH_PRIV_SZ 34
  20130. #define MAX_DH_KEY_SZ 384
  20131. #else
  20132. #define MAX_DH_PRIV_SZ 29
  20133. #define MAX_DH_KEY_SZ 256
  20134. #endif
  20135. #ifndef WC_NO_RNG
  20136. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20137. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20138. #ifdef HAVE_PUBLIC_FFDHE
  20139. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, const DhParams* params)
  20140. #else
  20141. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, int name)
  20142. #endif
  20143. {
  20144. wc_test_ret_t ret;
  20145. word32 privSz, pubSz, privSz2, pubSz2;
  20146. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20147. byte *priv = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20148. byte *pub = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20149. byte *priv2 = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20150. byte *pub2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20151. byte *agree = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20152. byte *agree2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20153. DhKey *key = (DhKey*)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20154. DhKey *key2 = (DhKey*)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20155. #else
  20156. byte priv[MAX_DH_PRIV_SZ];
  20157. byte pub[MAX_DH_KEY_SZ];
  20158. byte priv2[MAX_DH_PRIV_SZ];
  20159. byte pub2[MAX_DH_KEY_SZ];
  20160. byte agree[MAX_DH_KEY_SZ];
  20161. byte agree2[MAX_DH_KEY_SZ];
  20162. DhKey key[1];
  20163. DhKey key2[1];
  20164. #endif
  20165. word32 agreeSz = MAX_DH_KEY_SZ;
  20166. word32 agreeSz2 = MAX_DH_KEY_SZ;
  20167. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20168. if ((priv == NULL) ||
  20169. (pub == NULL) ||
  20170. (priv2 == NULL) ||
  20171. (pub2 == NULL) ||
  20172. (agree == NULL) ||
  20173. (agree2 == NULL) ||
  20174. (key == NULL) ||
  20175. (key2 == NULL))
  20176. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20177. #endif
  20178. pubSz = MAX_DH_KEY_SZ;
  20179. pubSz2 = MAX_DH_KEY_SZ;
  20180. #ifdef HAVE_PUBLIC_FFDHE
  20181. privSz = MAX_DH_PRIV_SZ;
  20182. privSz2 = MAX_DH_PRIV_SZ;
  20183. #else
  20184. privSz = wc_DhGetNamedKeyMinSize(name);
  20185. privSz2 = privSz;
  20186. #endif
  20187. XMEMSET(key, 0, sizeof(*key));
  20188. XMEMSET(key2, 0, sizeof(*key2));
  20189. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20190. if (ret != 0)
  20191. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20192. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20193. if (ret != 0)
  20194. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20195. #ifdef HAVE_PUBLIC_FFDHE
  20196. ret = wc_DhSetKey(key, params->p, params->p_len, params->g, params->g_len);
  20197. #else
  20198. ret = wc_DhSetNamedKey(key, name);
  20199. #endif
  20200. if (ret != 0)
  20201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20202. #ifdef HAVE_PUBLIC_FFDHE
  20203. ret = wc_DhSetKey(key2, params->p, params->p_len, params->g,
  20204. params->g_len);
  20205. #else
  20206. ret = wc_DhSetNamedKey(key2, name);
  20207. #endif
  20208. if (ret != 0)
  20209. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20210. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20211. #if defined(WOLFSSL_ASYNC_CRYPT)
  20212. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20213. #endif
  20214. if (ret != 0)
  20215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20216. ret = wc_DhGenerateKeyPair(key2, rng, priv2, &privSz2, pub2, &pubSz2);
  20217. #if defined(WOLFSSL_ASYNC_CRYPT)
  20218. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20219. #endif
  20220. if (ret != 0)
  20221. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20222. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20223. #if defined(WOLFSSL_ASYNC_CRYPT)
  20224. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20225. #endif
  20226. if (ret != 0)
  20227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20228. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20229. #if defined(WOLFSSL_ASYNC_CRYPT)
  20230. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20231. #endif
  20232. if (ret != 0)
  20233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20234. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20235. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20236. }
  20237. #if (defined(WOLFSSL_HAVE_SP_DH) || defined(USE_FAST_MATH)) && \
  20238. !defined(HAVE_INTEL_QA)
  20239. /* Make p even */
  20240. key->p.dp[0] &= (mp_digit)-2;
  20241. if (ret != 0)
  20242. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20243. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20244. #if defined(WOLFSSL_ASYNC_CRYPT)
  20245. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20246. #endif
  20247. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20248. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  20249. {
  20250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20251. }
  20252. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20253. #if defined(WOLFSSL_ASYNC_CRYPT)
  20254. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20255. #endif
  20256. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20257. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20258. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20259. {
  20260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20261. }
  20262. #ifndef HAVE_SELFTEST
  20263. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  20264. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20265. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20266. ret != WC_NO_ERR_TRACE(MP_CMP_E) &&
  20267. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20268. {
  20269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20270. }
  20271. #endif
  20272. /* Getting here means success - set ret to 0. */
  20273. ret = 0;
  20274. #endif /* (SP DH or Fast Math) and not Intel QuickAssist */
  20275. done:
  20276. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) && \
  20277. !defined(WC_NO_RNG)
  20278. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20279. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20280. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20281. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20282. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20283. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20284. if (key) {
  20285. wc_FreeDhKey(key);
  20286. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20287. }
  20288. if (key2) {
  20289. wc_FreeDhKey(key2);
  20290. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20291. }
  20292. #else
  20293. wc_FreeDhKey(key);
  20294. wc_FreeDhKey(key2);
  20295. #endif
  20296. return ret;
  20297. }
  20298. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  20299. #endif /* !WC_NO_RNG */
  20300. #endif /* HAVE_FFDHE */
  20301. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void)
  20302. {
  20303. wc_test_ret_t ret;
  20304. word32 bytes;
  20305. word32 idx = 0;
  20306. word32 privSz = 0;
  20307. word32 pubSz = 0;
  20308. word32 privSz2 = 0;
  20309. word32 pubSz2 = 0;
  20310. #ifndef WC_NO_RNG
  20311. WC_RNG rng;
  20312. int rngInit = 0;
  20313. #endif
  20314. int keyInit = 0, key2Init = 0;
  20315. #define DH_TEST_TMP_SIZE 1024
  20316. #if !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  20317. #define DH_TEST_BUF_SIZE 256
  20318. #else
  20319. #define DH_TEST_BUF_SIZE 512
  20320. #endif
  20321. #ifndef WC_NO_RNG
  20322. word32 agreeSz = DH_TEST_BUF_SIZE;
  20323. word32 agreeSz2 = DH_TEST_BUF_SIZE;
  20324. #endif
  20325. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20326. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20327. DhKey *key2 = (DhKey *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20328. byte *tmp = (byte *)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20329. #else
  20330. DhKey key[1];
  20331. DhKey key2[1];
  20332. byte tmp[DH_TEST_TMP_SIZE];
  20333. #endif
  20334. #ifndef WC_NO_RNG
  20335. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20336. byte *priv = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20337. byte *pub = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20338. byte *priv2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20339. byte *pub2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20340. byte *agree = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20341. byte *agree2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20342. if (priv == NULL || pub == NULL || priv2 == NULL || pub2 == NULL ||
  20343. agree == NULL || agree2 == NULL) {
  20344. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20345. }
  20346. #else
  20347. byte priv[DH_TEST_BUF_SIZE];
  20348. byte pub[DH_TEST_BUF_SIZE];
  20349. byte priv2[DH_TEST_BUF_SIZE];
  20350. byte pub2[DH_TEST_BUF_SIZE];
  20351. byte agree[DH_TEST_BUF_SIZE];
  20352. byte agree2[DH_TEST_BUF_SIZE];
  20353. #endif
  20354. #endif /* !WC_NO_RNG */
  20355. WOLFSSL_ENTER("dh_test");
  20356. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20357. if (key == NULL || key2 == NULL || tmp == NULL) {
  20358. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20359. }
  20360. #endif
  20361. #ifdef USE_CERT_BUFFERS_1024
  20362. XMEMCPY(tmp, dh_key_der_1024, (size_t)sizeof_dh_key_der_1024);
  20363. bytes = (size_t)sizeof_dh_key_der_1024;
  20364. #elif defined(USE_CERT_BUFFERS_2048)
  20365. XMEMCPY(tmp, dh_key_der_2048, (size_t)sizeof_dh_key_der_2048);
  20366. bytes = (size_t)sizeof_dh_key_der_2048;
  20367. #elif defined(USE_CERT_BUFFERS_3072)
  20368. XMEMCPY(tmp, dh_key_der_3072, (size_t)sizeof_dh_key_der_3072);
  20369. bytes = (size_t)sizeof_dh_key_der_3072;
  20370. #elif defined(USE_CERT_BUFFERS_4096)
  20371. XMEMCPY(tmp, dh_key_der_4096, (size_t)sizeof_dh_key_der_4096);
  20372. bytes = (size_t)sizeof_dh_key_der_4096;
  20373. #elif defined(NO_ASN)
  20374. /* don't use file, no DER parsing */
  20375. #elif !defined(NO_FILESYSTEM)
  20376. {
  20377. XFILE file = XFOPEN(dhParamsFile, "rb");
  20378. if (! file)
  20379. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20380. bytes = (word32) XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20381. XFCLOSE(file);
  20382. if (bytes == 0)
  20383. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20384. }
  20385. #else
  20386. /* No DH key to use. */
  20387. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20388. #endif /* USE_CERT_BUFFERS */
  20389. (void)idx;
  20390. (void)tmp;
  20391. (void)bytes;
  20392. pubSz = DH_TEST_BUF_SIZE;
  20393. pubSz2 = DH_TEST_BUF_SIZE;
  20394. privSz = DH_TEST_BUF_SIZE;
  20395. privSz2 = DH_TEST_BUF_SIZE;
  20396. #ifndef WC_NO_RNG
  20397. XMEMSET(&rng, 0, sizeof(rng));
  20398. #endif
  20399. /* Use API for coverage. */
  20400. ret = wc_InitDhKey(key);
  20401. if (ret != 0)
  20402. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20403. wc_FreeDhKey(key);
  20404. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20405. if (ret != 0)
  20406. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20407. keyInit = 1;
  20408. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20409. if (ret != 0)
  20410. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20411. key2Init = 1;
  20412. #ifdef NO_ASN
  20413. #ifndef WOLFSSL_SP_MATH
  20414. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20415. if (ret != 0)
  20416. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20417. ret = wc_DhSetKey(key2, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20418. if (ret != 0)
  20419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20420. #else
  20421. ret = wc_DhSetKey(key, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20422. sizeof(dh2048_g));
  20423. if (ret != 0)
  20424. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20425. ret = wc_DhSetKey(key2, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20426. sizeof(dh2048_g));
  20427. if (ret != 0)
  20428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20429. #endif
  20430. #else
  20431. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20432. if (ret != 0)
  20433. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20434. idx = 0;
  20435. ret = wc_DhKeyDecode(tmp, &idx, key2, bytes);
  20436. if (ret != 0)
  20437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20438. #endif
  20439. #ifndef WC_NO_RNG
  20440. #ifndef HAVE_FIPS
  20441. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20442. #else
  20443. ret = wc_InitRng(&rng);
  20444. #endif
  20445. if (ret != 0)
  20446. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20447. rngInit = 1;
  20448. ret = wc_DhGenerateKeyPair(key, &rng, priv, &privSz, pub, &pubSz);
  20449. #if defined(WOLFSSL_ASYNC_CRYPT)
  20450. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20451. #endif
  20452. if (ret != 0)
  20453. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20454. ret = wc_DhGenerateKeyPair(key2, &rng, priv2, &privSz2, pub2, &pubSz2);
  20455. #if defined(WOLFSSL_ASYNC_CRYPT)
  20456. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20457. #endif
  20458. if (ret != 0)
  20459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20460. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20461. #if defined(WOLFSSL_ASYNC_CRYPT)
  20462. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20463. #endif
  20464. if (ret != 0)
  20465. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20466. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20467. #if defined(WOLFSSL_ASYNC_CRYPT)
  20468. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20469. #endif
  20470. if (ret != 0)
  20471. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20472. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20473. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20474. }
  20475. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) && \
  20476. !defined(HAVE_SELFTEST)
  20477. agreeSz = DH_TEST_BUF_SIZE;
  20478. agreeSz2 = DH_TEST_BUF_SIZE;
  20479. ret = wc_DhAgree_ct(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20480. if (ret != 0)
  20481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20482. ret = wc_DhAgree_ct(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20483. if (ret != 0)
  20484. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20485. #ifdef WOLFSSL_PUBLIC_MP
  20486. if (agreeSz != (word32)mp_unsigned_bin_size(&key->p))
  20487. {
  20488. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20489. }
  20490. #endif
  20491. if (agreeSz != agreeSz2)
  20492. {
  20493. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20494. }
  20495. if (XMEMCMP(agree, agree2, agreeSz) != 0)
  20496. {
  20497. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20498. }
  20499. #endif /* (!HAVE_FIPS || FIPS_VERSION_GE(7,0)) && !HAVE_SELFTEST */
  20500. #endif /* !WC_NO_RNG */
  20501. #if defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20502. ret = wc_DhCheckPrivKey(NULL, NULL, 0);
  20503. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20505. ret = wc_DhCheckPrivKey(key, priv, privSz);
  20506. if (ret != 0)
  20507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20508. ret = wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  20509. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20511. {
  20512. word32 pSz, qSz, gSz;
  20513. ret = wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz);
  20514. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  20515. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20516. }
  20517. #endif
  20518. /* Test DH key import / export */
  20519. #if defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM) && \
  20520. (!defined(HAVE_FIPS) || \
  20521. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  20522. wc_FreeDhKey(key);
  20523. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20524. if (ret != 0)
  20525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20526. #ifndef NO_ASN
  20527. {
  20528. /* DH Private - Key Export / Import */
  20529. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20530. byte *tmp2;
  20531. #else
  20532. byte tmp2[DH_TEST_TMP_SIZE];
  20533. #endif
  20534. #if defined(USE_CERT_BUFFERS_2048)
  20535. XMEMCPY(tmp, dh_ffdhe_statickey_der_2048, sizeof_dh_ffdhe_statickey_der_2048);
  20536. bytes = sizeof_dh_ffdhe_statickey_der_2048;
  20537. #else
  20538. XFILE file = XFOPEN(dhKeyFile, "rb");
  20539. if (!file)
  20540. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20541. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20542. XFCLOSE(file);
  20543. if (bytes == 0)
  20544. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20545. #endif
  20546. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20547. tmp2 = (byte*)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20548. if (tmp2 == NULL)
  20549. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20550. #endif
  20551. idx = 0;
  20552. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20553. /* Import DH Private key as DER */
  20554. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20555. if (ret == 0) {
  20556. /* Export as DER */
  20557. idx = DH_TEST_TMP_SIZE;
  20558. ret = wc_DhPrivKeyToDer(key, tmp2, &idx);
  20559. }
  20560. /* Verify export matches original */
  20561. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20562. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20563. }
  20564. /* DH Public Key - Export / Import */
  20565. #if defined(USE_CERT_BUFFERS_2048)
  20566. XMEMCPY(tmp, dh_ffdhe_pub_statickey_der_2048, sizeof_dh_ffdhe_pub_statickey_der_2048);
  20567. bytes = sizeof_dh_ffdhe_pub_statickey_der_2048;
  20568. #else
  20569. file = XFOPEN(dhKeyPubFile, "rb");
  20570. if (!file)
  20571. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20572. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20573. XFCLOSE(file);
  20574. if (bytes == 0)
  20575. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20576. #endif
  20577. /* for HAVE_WOLF_BIGINT prevent leak */
  20578. wc_FreeDhKey(key);
  20579. (void)wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20580. idx = 0;
  20581. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20582. /* Import DH Public key as DER */
  20583. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20584. if (ret == 0) {
  20585. /* Export as DER */
  20586. idx = DH_TEST_TMP_SIZE;
  20587. ret = wc_DhPubKeyToDer(key, tmp2, &idx);
  20588. }
  20589. /* Verify export matches original */
  20590. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20591. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20592. }
  20593. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20594. XFREE(tmp2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20595. #endif
  20596. }
  20597. #else
  20598. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20599. if (ret != 0)
  20600. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20601. #endif /* !NO_ASN */
  20602. privSz = DH_TEST_BUF_SIZE;
  20603. pubSz = DH_TEST_BUF_SIZE;
  20604. ret = wc_DhExportKeyPair(key, priv, &privSz, pub, &pubSz);
  20605. if (ret != 0)
  20606. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20607. ret = wc_DhImportKeyPair(key2, priv, privSz, pub, pubSz);
  20608. if (ret != 0)
  20609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20610. #endif /* WOLFSSL_DH_EXTRA && !NO_FILESYSTEM && !FIPS <= 2 */
  20611. #ifndef WC_NO_RNG
  20612. ret = dh_generate_test(&rng);
  20613. if (ret != 0)
  20614. ERROR_OUT(ret, done);
  20615. ret = dh_fips_generate_test(&rng);
  20616. if (ret != 0)
  20617. ERROR_OUT(ret, done);
  20618. #endif /* !WC_NO_RNG */
  20619. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20620. ret = dh_test_check_pubvalue();
  20621. if (ret != 0)
  20622. ERROR_OUT(ret, done);
  20623. #endif
  20624. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20625. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20626. /* RNG with DH and SP_ASM code not supported in the in-lined FIPS ASM code,
  20627. * this will be available for testing in the 140-3 module */
  20628. #ifndef WC_NO_RNG
  20629. /* Specialized code for key gen when using FFDHE-2048, FFDHE-3072 and FFDHE-4096 */
  20630. #ifdef HAVE_FFDHE_2048
  20631. #ifdef HAVE_PUBLIC_FFDHE
  20632. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe2048_Get());
  20633. #else
  20634. ret = dh_ffdhe_test(&rng, WC_FFDHE_2048);
  20635. #endif
  20636. if (ret != 0)
  20637. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20638. #endif
  20639. #ifdef HAVE_FFDHE_3072
  20640. #ifdef HAVE_PUBLIC_FFDHE
  20641. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe3072_Get());
  20642. #else
  20643. ret = dh_ffdhe_test(&rng, WC_FFDHE_3072);
  20644. #endif
  20645. if (ret != 0)
  20646. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20647. #endif
  20648. #ifdef HAVE_FFDHE_4096
  20649. #ifdef HAVE_PUBLIC_FFDHE
  20650. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe4096_Get());
  20651. #else
  20652. ret = dh_ffdhe_test(&rng, WC_FFDHE_4096);
  20653. #endif
  20654. if (ret != 0)
  20655. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20656. #endif
  20657. #endif /* !WC_NO_RNG */
  20658. #endif /* HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM64_ASM */
  20659. wc_FreeDhKey(key);
  20660. keyInit = 0;
  20661. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  20662. !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(WC_NO_RNG)
  20663. /* Test Check Key */
  20664. ret = wc_DhSetCheckKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g),
  20665. NULL, 0, 0, &rng);
  20666. if (ret != 0)
  20667. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20668. keyInit = 1; /* DhSetCheckKey also initializes the key, free it */
  20669. #endif
  20670. done:
  20671. #ifndef WC_NO_RNG
  20672. if (rngInit)
  20673. wc_FreeRng(&rng);
  20674. #endif
  20675. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20676. if (key) {
  20677. if (keyInit)
  20678. wc_FreeDhKey(key);
  20679. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20680. }
  20681. if (key2) {
  20682. if (key2Init)
  20683. wc_FreeDhKey(key2);
  20684. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20685. }
  20686. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20687. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20688. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20689. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20690. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20691. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20692. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20693. #else
  20694. if (keyInit)
  20695. wc_FreeDhKey(key);
  20696. if (key2Init)
  20697. wc_FreeDhKey(key2);
  20698. #endif
  20699. (void)privSz;
  20700. (void)pubSz;
  20701. (void)pubSz2;
  20702. (void)privSz2;
  20703. return ret;
  20704. #undef DH_TEST_BUF_SIZE
  20705. #undef DH_TEST_TMP_SIZE
  20706. }
  20707. #endif /* NO_DH */
  20708. #ifndef NO_DSA
  20709. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void)
  20710. {
  20711. wc_test_ret_t ret = 0;
  20712. int answer;
  20713. word32 bytes;
  20714. word32 idx = 0;
  20715. WC_RNG rng;
  20716. int rng_inited = 0;
  20717. wc_Sha sha;
  20718. byte hash[WC_SHA_DIGEST_SIZE];
  20719. byte signature[40];
  20720. int key_inited = 0;
  20721. #ifdef WOLFSSL_KEY_GEN
  20722. byte* der = 0;
  20723. int derIn_inited = 0;
  20724. int genKey_inited = 0;
  20725. #endif
  20726. #define DSA_TEST_TMP_SIZE 1024
  20727. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20728. byte *tmp = (byte *)XMALLOC(DSA_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20729. DsaKey *key = (DsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20730. #ifdef WOLFSSL_KEY_GEN
  20731. DsaKey *derIn = (DsaKey *)XMALLOC(sizeof *derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20732. DsaKey *genKey = (DsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20733. #endif
  20734. WOLFSSL_ENTER("dsa_test");
  20735. if ((tmp == NULL) ||
  20736. (key == NULL)
  20737. #ifdef WOLFSSL_KEY_GEN
  20738. || (derIn == NULL)
  20739. || (genKey == NULL)
  20740. #endif
  20741. ) {
  20742. ret = WC_TEST_RET_ENC_NC;
  20743. goto out;
  20744. }
  20745. #else
  20746. byte tmp[1024];
  20747. DsaKey key[1];
  20748. #ifdef WOLFSSL_KEY_GEN
  20749. DsaKey derIn[1];
  20750. DsaKey genKey[1];
  20751. #endif
  20752. #endif
  20753. #ifdef USE_CERT_BUFFERS_1024
  20754. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20755. bytes = sizeof_dsa_key_der_1024;
  20756. #elif defined(USE_CERT_BUFFERS_2048)
  20757. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20758. bytes = sizeof_dsa_key_der_2048;
  20759. #else
  20760. {
  20761. XFILE file = XFOPEN(dsaKey, "rb");
  20762. if (!file)
  20763. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20764. bytes = (word32) XFREAD(tmp, 1, DSA_TEST_TMP_SIZE, file);
  20765. XFCLOSE(file);
  20766. if (bytes == 0)
  20767. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20768. }
  20769. #endif /* USE_CERT_BUFFERS */
  20770. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  20771. if (ret != 0)
  20772. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20773. wc_ShaUpdate(&sha, tmp, bytes);
  20774. wc_ShaFinal(&sha, hash);
  20775. wc_ShaFree(&sha);
  20776. ret = wc_InitDsaKey(key);
  20777. if (ret != 0)
  20778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20779. key_inited = 1;
  20780. ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes);
  20781. if (ret != 0)
  20782. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20783. #ifndef HAVE_FIPS
  20784. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20785. #else
  20786. ret = wc_InitRng(&rng);
  20787. #endif
  20788. if (ret != 0)
  20789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20790. rng_inited = 1;
  20791. ret = wc_DsaSign(hash, signature, key, &rng);
  20792. if (ret != 0)
  20793. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20794. ret = wc_DsaVerify(hash, signature, key, &answer);
  20795. if (ret != 0)
  20796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20797. if (answer != 1)
  20798. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20799. wc_FreeDsaKey(key);
  20800. key_inited = 0;
  20801. ret = wc_InitDsaKey_h(key, NULL);
  20802. if (ret != 0)
  20803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20804. key_inited = 1;
  20805. #ifdef WOLFSSL_KEY_GEN
  20806. {
  20807. int derSz = 0;
  20808. ret = wc_InitDsaKey(genKey);
  20809. if (ret != 0)
  20810. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20811. genKey_inited = 1;
  20812. ret = wc_MakeDsaParameters(&rng, 1024, genKey);
  20813. if (ret != 0)
  20814. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20815. ret = wc_MakeDsaKey(&rng, genKey);
  20816. if (ret != 0)
  20817. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20818. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20819. if (der == NULL)
  20820. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20821. derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF);
  20822. if (derSz < 0)
  20823. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out);
  20824. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  20825. DSA_PRIVATEKEY_TYPE);
  20826. if (ret != 0)
  20827. goto out;
  20828. ret = wc_InitDsaKey(derIn);
  20829. if (ret != 0)
  20830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20831. derIn_inited = 1;
  20832. idx = 0;
  20833. ret = wc_DsaPrivateKeyDecode(der, &idx, derIn, (word32)derSz);
  20834. if (ret != 0)
  20835. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20836. }
  20837. #endif /* WOLFSSL_KEY_GEN */
  20838. out:
  20839. #ifdef WOLFSSL_KEY_GEN
  20840. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20841. #endif
  20842. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20843. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20844. if (key) {
  20845. if (key_inited)
  20846. wc_FreeDsaKey(key);
  20847. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20848. }
  20849. #ifdef WOLFSSL_KEY_GEN
  20850. if (derIn) {
  20851. if (derIn_inited)
  20852. wc_FreeDsaKey(derIn);
  20853. XFREE(derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20854. }
  20855. if (genKey) {
  20856. if (genKey_inited)
  20857. wc_FreeDsaKey(genKey);
  20858. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20859. }
  20860. #endif
  20861. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  20862. if (key_inited)
  20863. wc_FreeDsaKey(key);
  20864. #ifdef WOLFSSL_KEY_GEN
  20865. if (derIn_inited)
  20866. wc_FreeDsaKey(derIn);
  20867. if (genKey_inited)
  20868. wc_FreeDsaKey(genKey);
  20869. #endif
  20870. #endif
  20871. if (rng_inited)
  20872. wc_FreeRng(&rng);
  20873. return ret;
  20874. }
  20875. #endif /* NO_DSA */
  20876. #ifdef WOLFCRYPT_HAVE_SRP
  20877. static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
  20878. {
  20879. wc_test_ret_t ret = WC_TEST_RET_ENC_NC;
  20880. WC_RNG rng;
  20881. if(NULL == buf || !size)
  20882. return WC_TEST_RET_ENC_NC;
  20883. if (buf && size && wc_InitRng_ex(&rng, HEAP_HINT, devId) == 0) {
  20884. ret = wc_RNG_GenerateBlock(&rng, (byte *)buf, size);
  20885. wc_FreeRng(&rng);
  20886. }
  20887. return ret;
  20888. }
  20889. static wc_test_ret_t srp_test_digest(SrpType dgstType)
  20890. {
  20891. wc_test_ret_t r;
  20892. byte clientPubKey[192]; /* A */
  20893. byte serverPubKey[192]; /* B */
  20894. word32 clientPubKeySz = 192;
  20895. word32 serverPubKeySz = 192;
  20896. byte username[] = "user";
  20897. word32 usernameSz = 4;
  20898. byte password[] = "password";
  20899. word32 passwordSz = 8;
  20900. WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
  20901. 0xfc, 0x58, 0x7a, 0x8a, 0x70, 0xfb, 0x5a, 0x9a,
  20902. 0x5d, 0x39, 0x48, 0xbf, 0x1c, 0x46, 0xd8, 0x3b,
  20903. 0x7a, 0xe9, 0x1f, 0x85, 0x36, 0x18, 0xc4, 0x35,
  20904. 0x3f, 0xf8, 0x8a, 0x8f, 0x8c, 0x10, 0x2e, 0x01,
  20905. 0x58, 0x1d, 0x41, 0xcb, 0xc4, 0x47, 0xa8, 0xaf,
  20906. 0x9a, 0x6f, 0x58, 0x14, 0xa4, 0x68, 0xf0, 0x9c,
  20907. 0xa6, 0xe7, 0xbf, 0x0d, 0xe9, 0x62, 0x0b, 0xd7,
  20908. 0x26, 0x46, 0x5b, 0x27, 0xcb, 0x4c, 0xf9, 0x7e,
  20909. 0x1e, 0x8b, 0xe6, 0xdd, 0x29, 0xb7, 0xb7, 0x15,
  20910. 0x2e, 0xcf, 0x23, 0xa6, 0x4b, 0x97, 0x9f, 0x89,
  20911. 0xd4, 0x86, 0xc4, 0x90, 0x63, 0x92, 0xf4, 0x30,
  20912. 0x26, 0x69, 0x48, 0x9d, 0x7a, 0x4f, 0xad, 0xb5,
  20913. 0x6a, 0x51, 0xad, 0xeb, 0xf9, 0x90, 0x31, 0x77,
  20914. 0x53, 0x30, 0x2a, 0x85, 0xf7, 0x11, 0x21, 0x0c,
  20915. 0xb8, 0x4b, 0x56, 0x03, 0x5e, 0xbb, 0x25, 0x33,
  20916. 0x7c, 0xd9, 0x5a, 0xd1, 0x5c, 0xb2, 0xd4, 0x53,
  20917. 0xc5, 0x16, 0x68, 0xf0, 0xdf, 0x48, 0x55, 0x3e,
  20918. 0xd4, 0x59, 0x87, 0x64, 0x59, 0xaa, 0x39, 0x01,
  20919. 0x45, 0x89, 0x9c, 0x72, 0xff, 0xdd, 0x8f, 0x6d,
  20920. 0xa0, 0x42, 0xbc, 0x6f, 0x6e, 0x62, 0x18, 0x2d,
  20921. 0x50, 0xe8, 0x18, 0x97, 0x87, 0xfc, 0xef, 0x1f,
  20922. 0xf5, 0x53, 0x68, 0xe8, 0x49, 0xd1, 0xa2, 0xe8,
  20923. 0xb9, 0x26, 0x03, 0xba, 0xb5, 0x58, 0x6f, 0x6c,
  20924. 0x8b, 0x08, 0xa1, 0x7b, 0x6f, 0x42, 0xc9, 0x53
  20925. };
  20926. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  20927. 0x02
  20928. };
  20929. byte salt[10];
  20930. byte verifier[192];
  20931. word32 v_size = sizeof(verifier);
  20932. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  20933. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  20934. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20935. Srp *cli = (Srp *)XMALLOC(sizeof *cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20936. Srp *srv = (Srp *)XMALLOC(sizeof *srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20937. byte *clientProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20938. DYNAMIC_TYPE_TMP_BUFFER); /* M1 */
  20939. byte *serverProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20940. DYNAMIC_TYPE_TMP_BUFFER); /* M2 */
  20941. if ((cli == NULL) ||
  20942. (srv == NULL) ||
  20943. (clientProof == NULL) ||
  20944. (serverProof == NULL)) {
  20945. r = WC_TEST_RET_ENC_NC;
  20946. goto out;
  20947. }
  20948. #else
  20949. Srp cli[1], srv[1];
  20950. byte clientProof[SRP_MAX_DIGEST_SIZE]; /* M1 */
  20951. byte serverProof[SRP_MAX_DIGEST_SIZE]; /* M2 */
  20952. #endif
  20953. /* set as 0's so if second init on srv not called SrpTerm is not on
  20954. * garbage values */
  20955. XMEMSET(srv, 0, sizeof *srv);
  20956. XMEMSET(cli, 0, sizeof *cli);
  20957. /* generating random salt */
  20958. r = generate_random_salt(salt, sizeof(salt));
  20959. /* client knows username and password. */
  20960. /* server knows N, g, salt and verifier. */
  20961. if (!r) r = wc_SrpInit_ex(cli, dgstType, SRP_CLIENT_SIDE, HEAP_HINT, devId);
  20962. if (!r) r = wc_SrpSetUsername(cli, username, usernameSz);
  20963. /* loading N, g and salt in advance to generate the verifier. */
  20964. if (!r) r = wc_SrpSetParams(cli, N, sizeof(N),
  20965. g, sizeof(g),
  20966. salt, sizeof(salt));
  20967. if (!r) r = wc_SrpSetPassword(cli, password, passwordSz);
  20968. if (!r) r = wc_SrpGetVerifier(cli, verifier, &v_size);
  20969. /* client sends username to server */
  20970. if (!r) r = wc_SrpInit_ex(srv, dgstType, SRP_SERVER_SIDE, HEAP_HINT, devId);
  20971. if (!r) r = wc_SrpSetUsername(srv, username, usernameSz);
  20972. if (!r) r = wc_SrpSetParams(srv, N, sizeof(N),
  20973. g, sizeof(g),
  20974. salt, sizeof(salt));
  20975. if (!r) r = wc_SrpSetVerifier(srv, verifier, v_size);
  20976. if (!r) r = wc_SrpGetPublic(srv, serverPubKey, &serverPubKeySz);
  20977. /* server sends N, g, salt and B to client */
  20978. if (!r) r = wc_SrpGetPublic(cli, clientPubKey, &clientPubKeySz);
  20979. if (!r) r = wc_SrpComputeKey(cli, clientPubKey, clientPubKeySz,
  20980. serverPubKey, serverPubKeySz);
  20981. if (!r) r = wc_SrpGetProof(cli, clientProof, &clientProofSz);
  20982. /* client sends A and M1 to server */
  20983. if (!r) r = wc_SrpComputeKey(srv, clientPubKey, clientPubKeySz,
  20984. serverPubKey, serverPubKeySz);
  20985. if (!r) r = wc_SrpVerifyPeersProof(srv, clientProof, clientProofSz);
  20986. if (!r) r = wc_SrpGetProof(srv, serverProof, &serverProofSz);
  20987. /* server sends M2 to client */
  20988. if (!r) r = wc_SrpVerifyPeersProof(cli, serverProof, serverProofSz);
  20989. wc_SrpTerm(cli);
  20990. wc_SrpTerm(srv);
  20991. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20992. out:
  20993. XFREE(cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20994. XFREE(srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20995. XFREE(clientProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20996. XFREE(serverProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20997. #endif
  20998. return r;
  20999. }
  21000. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void)
  21001. {
  21002. wc_test_ret_t ret;
  21003. WOLFSSL_ENTER("srp_test");
  21004. #ifndef NO_SHA
  21005. ret = srp_test_digest(SRP_TYPE_SHA);
  21006. if (ret != 0)
  21007. return ret;
  21008. #endif
  21009. #ifndef NO_SHA256
  21010. ret = srp_test_digest(SRP_TYPE_SHA256);
  21011. if (ret != 0)
  21012. return ret;
  21013. #endif
  21014. #ifdef WOLFSSL_SHA384
  21015. ret = srp_test_digest(SRP_TYPE_SHA384);
  21016. if (ret != 0)
  21017. return ret;
  21018. #endif
  21019. #ifdef WOLFSSL_SHA512
  21020. ret = srp_test_digest(SRP_TYPE_SHA512);
  21021. if (ret != 0)
  21022. return ret;
  21023. #endif
  21024. return ret;
  21025. }
  21026. #endif /* WOLFCRYPT_HAVE_SRP */
  21027. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  21028. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  21029. static wc_test_ret_t openssl_aes_test(void)
  21030. {
  21031. #ifdef HAVE_AES_CBC
  21032. #ifdef WOLFSSL_AES_128
  21033. {
  21034. /* EVP_CipherUpdate test */
  21035. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21036. {
  21037. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21038. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21039. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21040. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21041. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21042. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21043. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21044. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21045. };
  21046. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21047. "0123456789abcdef "; /* align */
  21048. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21049. "1234567890abcdef "; /* align */
  21050. byte cipher[WC_AES_BLOCK_SIZE * 4];
  21051. byte plain [WC_AES_BLOCK_SIZE * 4];
  21052. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21053. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21054. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21055. #else
  21056. WOLFSSL_EVP_CIPHER_CTX en[1];
  21057. WOLFSSL_EVP_CIPHER_CTX de[1];
  21058. #endif
  21059. int outlen ;
  21060. int total = 0;
  21061. int i;
  21062. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21063. if ((en == NULL) || (de == NULL))
  21064. return MEMORY_E;
  21065. #endif
  21066. wolfSSL_EVP_CIPHER_CTX_init(en);
  21067. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21068. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21069. return WC_TEST_RET_ENC_NC;
  21070. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21071. (byte*)cbcPlain, 9) == 0)
  21072. return WC_TEST_RET_ENC_NC;
  21073. if (outlen != 0)
  21074. return WC_TEST_RET_ENC_NC;
  21075. total += outlen;
  21076. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21077. (byte*)&cbcPlain[9] , 9) == 0)
  21078. return WC_TEST_RET_ENC_NC;
  21079. if (outlen != 16)
  21080. return WC_TEST_RET_ENC_NC;
  21081. total += outlen;
  21082. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21083. return WC_TEST_RET_ENC_NC;
  21084. if (outlen != 16)
  21085. return WC_TEST_RET_ENC_NC;
  21086. total += outlen;
  21087. if (total != 32)
  21088. return 3408;
  21089. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21090. total = 0;
  21091. wolfSSL_EVP_CIPHER_CTX_init(de);
  21092. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21093. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21094. return WC_TEST_RET_ENC_NC;
  21095. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  21096. return WC_TEST_RET_ENC_NC;
  21097. if (outlen != 0)
  21098. return WC_TEST_RET_ENC_NC;
  21099. total += outlen;
  21100. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21101. (byte*)&cipher[6], 12) == 0)
  21102. return WC_TEST_RET_ENC_NC;
  21103. if (outlen != 0)
  21104. total += outlen;
  21105. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21106. (byte*)&cipher[6+12], 14) == 0)
  21107. return WC_TEST_RET_ENC_NC;
  21108. if (outlen != 16)
  21109. return WC_TEST_RET_ENC_NC;
  21110. total += outlen;
  21111. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21112. return WC_TEST_RET_ENC_NC;
  21113. if (outlen != 2)
  21114. return WC_TEST_RET_ENC_NC;
  21115. total += outlen;
  21116. if (total != 18)
  21117. return 3427;
  21118. if (XMEMCMP(plain, cbcPlain, 18))
  21119. return WC_TEST_RET_ENC_NC;
  21120. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21121. /* test with encrypting/decrypting more than 16 bytes at once */
  21122. total = 0;
  21123. wolfSSL_EVP_CIPHER_CTX_init(en);
  21124. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21125. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21126. return WC_TEST_RET_ENC_NC;
  21127. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21128. (byte*)cbcPlain, 17) == 0)
  21129. return WC_TEST_RET_ENC_NC;
  21130. if (outlen != 16)
  21131. return WC_TEST_RET_ENC_NC;
  21132. total += outlen;
  21133. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21134. (byte*)&cbcPlain[17] , 1) == 0)
  21135. return WC_TEST_RET_ENC_NC;
  21136. if (outlen != 0)
  21137. return WC_TEST_RET_ENC_NC;
  21138. total += outlen;
  21139. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21140. return WC_TEST_RET_ENC_NC;
  21141. if (outlen != 16)
  21142. return WC_TEST_RET_ENC_NC;
  21143. total += outlen;
  21144. if (total != 32)
  21145. return WC_TEST_RET_ENC_NC;
  21146. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21147. total = 0;
  21148. wolfSSL_EVP_CIPHER_CTX_init(de);
  21149. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21150. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21151. return WC_TEST_RET_ENC_NC;
  21152. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 17) == 0)
  21153. return WC_TEST_RET_ENC_NC;
  21154. if (outlen != 16)
  21155. return WC_TEST_RET_ENC_NC;
  21156. total += outlen;
  21157. /* final call on non block size should fail */
  21158. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21159. return WC_TEST_RET_ENC_NC;
  21160. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21161. (byte*)&cipher[17], 1) == 0)
  21162. return WC_TEST_RET_ENC_NC;
  21163. if (outlen != 0)
  21164. total += outlen;
  21165. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21166. (byte*)&cipher[17+1], 14) == 0)
  21167. return WC_TEST_RET_ENC_NC;
  21168. if (outlen != 0)
  21169. return WC_TEST_RET_ENC_NC;
  21170. total += outlen;
  21171. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21172. return WC_TEST_RET_ENC_NC;
  21173. if (outlen != 2)
  21174. return WC_TEST_RET_ENC_NC;
  21175. total += outlen;
  21176. if (total != 18)
  21177. return WC_TEST_RET_ENC_NC;
  21178. if (XMEMCMP(plain, cbcPlain, 18))
  21179. return WC_TEST_RET_ENC_NC;
  21180. /* test byte by byte decrypt */
  21181. for (i = 0; i < WC_AES_BLOCK_SIZE * 3; i++) {
  21182. plain[i] = i;
  21183. }
  21184. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21185. total = 0;
  21186. wolfSSL_EVP_CIPHER_CTX_init(en);
  21187. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21188. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21189. return WC_TEST_RET_ENC_NC;
  21190. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21191. (byte*)plain, WC_AES_BLOCK_SIZE * 3) == 0)
  21192. return WC_TEST_RET_ENC_NC;
  21193. if (outlen != WC_AES_BLOCK_SIZE * 3)
  21194. return WC_TEST_RET_ENC_NC;
  21195. total += outlen;
  21196. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21197. return WC_TEST_RET_ENC_NC;
  21198. if (outlen != WC_AES_BLOCK_SIZE)
  21199. return WC_TEST_RET_ENC_NC;
  21200. total += outlen;
  21201. if (total != sizeof(plain))
  21202. return WC_TEST_RET_ENC_NC;
  21203. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21204. total = 0;
  21205. wolfSSL_EVP_CIPHER_CTX_init(de);
  21206. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21207. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21208. return WC_TEST_RET_ENC_NC;
  21209. for (i = 0; i < WC_AES_BLOCK_SIZE * 4; i++) {
  21210. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain + total, &outlen,
  21211. (byte*)cipher + i, 1) == 0)
  21212. return WC_TEST_RET_ENC_NC;
  21213. if (outlen > 0) {
  21214. int j;
  21215. total += outlen;
  21216. for (j = 0; j < total; j++) {
  21217. if (plain[j] != j) {
  21218. return WC_TEST_RET_ENC_NC;
  21219. }
  21220. }
  21221. }
  21222. }
  21223. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21224. return WC_TEST_RET_ENC_NC;
  21225. total += outlen;
  21226. if (total != WC_AES_BLOCK_SIZE * 3) {
  21227. return WC_TEST_RET_ENC_NC;
  21228. }
  21229. for (i = 0; i < WC_AES_BLOCK_SIZE * 3; i++) {
  21230. if (plain[i] != i) {
  21231. return WC_TEST_RET_ENC_NC;
  21232. }
  21233. }
  21234. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21235. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21236. wolfSSL_EVP_CIPHER_CTX_free(en);
  21237. wolfSSL_EVP_CIPHER_CTX_free(de);
  21238. #endif
  21239. }
  21240. /* set buffers to be exact size to catch potential over read/write */
  21241. {
  21242. /* EVP_CipherUpdate test */
  21243. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21244. {
  21245. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21246. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21247. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21248. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21249. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21250. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21251. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21252. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21253. };
  21254. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21255. "0123456789abcdef "; /* align */
  21256. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21257. "1234567890abcdef "; /* align */
  21258. #define EVP_TEST_BUF_SZ 18
  21259. #define EVP_TEST_BUF_PAD 32
  21260. byte cipher[EVP_TEST_BUF_SZ];
  21261. byte plain [EVP_TEST_BUF_SZ];
  21262. byte padded[EVP_TEST_BUF_PAD];
  21263. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21264. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21265. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21266. #else
  21267. WOLFSSL_EVP_CIPHER_CTX en[1];
  21268. WOLFSSL_EVP_CIPHER_CTX de[1];
  21269. #endif
  21270. int outlen ;
  21271. int total = 0;
  21272. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21273. if ((en == NULL) || (de == NULL))
  21274. return MEMORY_E;
  21275. #endif
  21276. wolfSSL_EVP_CIPHER_CTX_init(en);
  21277. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21278. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21279. return WC_TEST_RET_ENC_NC;
  21280. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != 1)
  21281. return WC_TEST_RET_ENC_NC;
  21282. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21283. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21284. return WC_TEST_RET_ENC_NC;
  21285. if (outlen != 16)
  21286. return WC_TEST_RET_ENC_NC;
  21287. total += outlen;
  21288. /* should fail here */
  21289. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0)
  21290. return WC_TEST_RET_ENC_NC;
  21291. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21292. /* turn padding back on and do successful encrypt */
  21293. total = 0;
  21294. wolfSSL_EVP_CIPHER_CTX_init(en);
  21295. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21296. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21297. return WC_TEST_RET_ENC_NC;
  21298. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != 1)
  21299. return WC_TEST_RET_ENC_NC;
  21300. if (wolfSSL_EVP_CipherUpdate(en, (byte*)padded, &outlen,
  21301. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21302. return WC_TEST_RET_ENC_NC;
  21303. if (outlen != 16)
  21304. return WC_TEST_RET_ENC_NC;
  21305. total += outlen;
  21306. if (wolfSSL_EVP_CipherFinal(en, (byte*)&padded[total], &outlen) == 0)
  21307. return WC_TEST_RET_ENC_NC;
  21308. total += outlen;
  21309. if (total != 32)
  21310. return WC_TEST_RET_ENC_NC;
  21311. XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ);
  21312. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21313. /* test out of bounds read on buffers w/o padding during decryption */
  21314. total = 0;
  21315. wolfSSL_EVP_CIPHER_CTX_init(de);
  21316. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21317. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21318. return WC_TEST_RET_ENC_NC;
  21319. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 0) != 1)
  21320. return WC_TEST_RET_ENC_NC;
  21321. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher,
  21322. EVP_TEST_BUF_SZ) == 0)
  21323. return WC_TEST_RET_ENC_NC;
  21324. if (outlen != 16)
  21325. return WC_TEST_RET_ENC_NC;
  21326. total += outlen;
  21327. /* should fail since not using padding */
  21328. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21329. return WC_TEST_RET_ENC_NC;
  21330. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21331. total = 0;
  21332. wolfSSL_EVP_CIPHER_CTX_init(de);
  21333. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21334. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21335. return WC_TEST_RET_ENC_NC;
  21336. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 1) != 1)
  21337. return WC_TEST_RET_ENC_NC;
  21338. if (wolfSSL_EVP_CipherUpdate(de, (byte*)padded, &outlen, (byte*)padded,
  21339. EVP_TEST_BUF_PAD) == 0)
  21340. return WC_TEST_RET_ENC_NC;
  21341. if (outlen != 16)
  21342. return WC_TEST_RET_ENC_NC;
  21343. total += outlen;
  21344. if (wolfSSL_EVP_CipherFinal(de, (byte*)&padded[total], &outlen) == 0)
  21345. return WC_TEST_RET_ENC_NC;
  21346. if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ))
  21347. return WC_TEST_RET_ENC_NC;
  21348. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21349. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21350. wolfSSL_EVP_CIPHER_CTX_free(en);
  21351. wolfSSL_EVP_CIPHER_CTX_free(de);
  21352. #endif
  21353. }
  21354. { /* evp_cipher test: EVP_aes_128_cbc */
  21355. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21356. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21357. #else
  21358. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21359. #endif
  21360. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  21361. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  21362. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  21363. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  21364. };
  21365. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21366. {
  21367. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  21368. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  21369. };
  21370. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21371. "0123456789abcdef "; /* align */
  21372. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21373. "1234567890abcdef "; /* align */
  21374. byte cipher[WC_AES_BLOCK_SIZE * 4];
  21375. byte plain [WC_AES_BLOCK_SIZE * 4];
  21376. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21377. if (ctx == NULL)
  21378. return MEMORY_E;
  21379. #endif
  21380. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21381. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1) == 0)
  21382. return WC_TEST_RET_ENC_NC;
  21383. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21384. return WC_TEST_RET_ENC_NC;
  21385. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  21386. return WC_TEST_RET_ENC_NC;
  21387. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21388. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21389. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0) == 0)
  21390. return WC_TEST_RET_ENC_NC;
  21391. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21392. return WC_TEST_RET_ENC_NC;
  21393. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  21394. return WC_TEST_RET_ENC_NC;
  21395. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21396. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21397. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21398. #endif
  21399. } /* end evp_cipher test: EVP_aes_128_cbc*/
  21400. #endif /* WOLFSSL_AES_128 */
  21401. #endif /* HAVE_AES_CBC */
  21402. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21403. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  21404. { /* evp_cipher test: EVP_aes_256_ecb*/
  21405. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21406. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21407. #else
  21408. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21409. #endif
  21410. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21411. {
  21412. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21413. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21414. };
  21415. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21416. {
  21417. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21418. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21419. };
  21420. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21421. {
  21422. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21423. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21424. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21425. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21426. };
  21427. byte cipher[WC_AES_BLOCK_SIZE * 4];
  21428. byte plain [WC_AES_BLOCK_SIZE * 4];
  21429. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21430. if (ctx == NULL)
  21431. return MEMORY_E;
  21432. #endif
  21433. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21434. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1) == 0)
  21435. return WC_TEST_RET_ENC_NC;
  21436. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21437. return WC_TEST_RET_ENC_NC;
  21438. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  21439. return WC_TEST_RET_ENC_NC;
  21440. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21441. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0) == 0)
  21442. return WC_TEST_RET_ENC_NC;
  21443. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21444. return WC_TEST_RET_ENC_NC;
  21445. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  21446. return WC_TEST_RET_ENC_NC;
  21447. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21448. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21449. #endif
  21450. } /* end evp_cipher test */
  21451. #endif /* HAVE_AES_ECB && WOLFSSL_AES_256 */
  21452. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  21453. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  21454. {
  21455. /* Test: AES_encrypt/decrypt/set Key */
  21456. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21457. WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21458. #ifdef HAVE_AES_DECRYPT
  21459. WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21460. #endif
  21461. #else
  21462. WOLFSSL_AES_KEY enc[1];
  21463. #ifdef HAVE_AES_DECRYPT
  21464. WOLFSSL_AES_KEY dec[1];
  21465. #endif
  21466. #endif
  21467. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21468. {
  21469. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21470. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21471. };
  21472. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21473. {
  21474. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21475. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21476. };
  21477. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21478. {
  21479. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21480. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21481. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21482. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21483. };
  21484. byte plain[sizeof(msg)];
  21485. byte cipher[sizeof(msg)];
  21486. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21487. if (enc == NULL)
  21488. return MEMORY_E;
  21489. #ifdef HAVE_AES_DECRYPT
  21490. if (dec == NULL)
  21491. return MEMORY_E;
  21492. #endif
  21493. #endif
  21494. wolfSSL_AES_set_encrypt_key(key, sizeof(key)*8, enc);
  21495. wolfSSL_AES_set_decrypt_key(key, sizeof(key)*8, dec);
  21496. wolfSSL_AES_encrypt(msg, cipher, enc);
  21497. #ifdef HAVE_AES_DECRYPT
  21498. wolfSSL_AES_decrypt(cipher, plain, dec);
  21499. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  21500. return WC_TEST_RET_ENC_NC;
  21501. #endif /* HAVE_AES_DECRYPT */
  21502. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  21503. return WC_TEST_RET_ENC_NC;
  21504. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21505. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21506. #ifdef HAVE_AES_DECRYPT
  21507. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21508. #endif
  21509. #endif
  21510. }
  21511. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  21512. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21513. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  21514. #ifdef WOLFSSL_AES_COUNTER
  21515. {
  21516. byte plainBuff [64];
  21517. byte cipherBuff[64];
  21518. #ifdef WOLFSSL_AES_128
  21519. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  21520. {
  21521. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21522. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21523. };
  21524. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  21525. {
  21526. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21527. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21528. };
  21529. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  21530. {
  21531. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21532. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21533. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21534. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21535. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21536. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21537. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21538. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21539. };
  21540. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  21541. {
  21542. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  21543. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  21544. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  21545. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  21546. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  21547. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  21548. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  21549. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  21550. };
  21551. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  21552. {
  21553. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  21554. 0xc2
  21555. };
  21556. #endif
  21557. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21558. * NIST Special Publication 800-38A */
  21559. #ifdef WOLFSSL_AES_192
  21560. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  21561. {
  21562. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  21563. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  21564. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  21565. };
  21566. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  21567. {
  21568. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21569. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21570. };
  21571. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  21572. {
  21573. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21574. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21575. };
  21576. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  21577. {
  21578. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  21579. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  21580. };
  21581. #endif /* WOLFSSL_AES_192 */
  21582. #ifdef WOLFSSL_AES_256
  21583. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21584. * NIST Special Publication 800-38A */
  21585. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  21586. {
  21587. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21588. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21589. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21590. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21591. };
  21592. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  21593. {
  21594. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21595. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21596. };
  21597. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  21598. {
  21599. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21600. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21601. };
  21602. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  21603. {
  21604. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  21605. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  21606. };
  21607. #endif /* WOLFSSL_AES_256 */
  21608. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21609. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21610. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21611. #else
  21612. WOLFSSL_EVP_CIPHER_CTX en[1];
  21613. WOLFSSL_EVP_CIPHER_CTX de[1];
  21614. #endif
  21615. #ifdef WOLFSSL_AES_128
  21616. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21617. WOLFSSL_EVP_CIPHER_CTX *p_en;
  21618. WOLFSSL_EVP_CIPHER_CTX *p_de;
  21619. #endif
  21620. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21621. if ((en == NULL) || (de == NULL))
  21622. return MEMORY_E;
  21623. #endif
  21624. wolfSSL_EVP_CIPHER_CTX_init(en);
  21625. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21626. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21627. return WC_TEST_RET_ENC_NC;
  21628. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  21629. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  21630. return WC_TEST_RET_ENC_NC;
  21631. wolfSSL_EVP_CIPHER_CTX_init(de);
  21632. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21633. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21634. return WC_TEST_RET_ENC_NC;
  21635. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21636. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  21637. return WC_TEST_RET_ENC_NC;
  21638. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21639. return WC_TEST_RET_ENC_NC;
  21640. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21641. return WC_TEST_RET_ENC_NC;
  21642. if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4))
  21643. return WC_TEST_RET_ENC_NC;
  21644. if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4))
  21645. return WC_TEST_RET_ENC_NC;
  21646. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21647. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  21648. if (p_en == NULL)
  21649. return WC_TEST_RET_ENC_ERRNO;
  21650. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  21651. if (p_de == NULL)
  21652. return WC_TEST_RET_ENC_ERRNO;
  21653. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  21654. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21655. return WC_TEST_RET_ENC_NC;
  21656. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  21657. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  21658. return WC_TEST_RET_ENC_NC;
  21659. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  21660. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21661. return WC_TEST_RET_ENC_NC;
  21662. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  21663. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  21664. return WC_TEST_RET_ENC_NC;
  21665. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21666. return WC_TEST_RET_ENC_NC;
  21667. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21668. return WC_TEST_RET_ENC_NC;
  21669. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  21670. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  21671. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  21672. if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4))
  21673. return WC_TEST_RET_ENC_NC;
  21674. if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4))
  21675. return WC_TEST_RET_ENC_NC;
  21676. wolfSSL_EVP_CIPHER_CTX_init(en);
  21677. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21678. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21679. return WC_TEST_RET_ENC_NC;
  21680. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21681. return WC_TEST_RET_ENC_NC;
  21682. wolfSSL_EVP_CIPHER_CTX_init(de);
  21683. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21684. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21685. return WC_TEST_RET_ENC_NC;
  21686. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21687. return WC_TEST_RET_ENC_NC;
  21688. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21689. return WC_TEST_RET_ENC_NC;
  21690. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  21691. return WC_TEST_RET_ENC_NC;
  21692. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21693. return WC_TEST_RET_ENC_NC;
  21694. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21695. return WC_TEST_RET_ENC_NC;
  21696. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21697. return WC_TEST_RET_ENC_NC;
  21698. if (XMEMCMP(cipherBuff, oddCipher, 9))
  21699. return WC_TEST_RET_ENC_NC;
  21700. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21701. return WC_TEST_RET_ENC_NC;
  21702. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21703. return WC_TEST_RET_ENC_NC;
  21704. #endif /* WOLFSSL_AES_128 */
  21705. #ifdef WOLFSSL_AES_192
  21706. wolfSSL_EVP_CIPHER_CTX_init(en);
  21707. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  21708. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21709. return WC_TEST_RET_ENC_NC;
  21710. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  21711. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  21712. return WC_TEST_RET_ENC_NC;
  21713. wolfSSL_EVP_CIPHER_CTX_init(de);
  21714. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  21715. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21716. return WC_TEST_RET_ENC_NC;
  21717. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21718. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21719. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  21720. return WC_TEST_RET_ENC_NC;
  21721. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  21722. return WC_TEST_RET_ENC_NC;
  21723. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  21724. return WC_TEST_RET_ENC_NC;
  21725. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21726. return WC_TEST_RET_ENC_NC;
  21727. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21728. return WC_TEST_RET_ENC_NC;
  21729. #endif /* WOLFSSL_AES_192 */
  21730. #ifdef WOLFSSL_AES_256
  21731. wolfSSL_EVP_CIPHER_CTX_init(en);
  21732. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  21733. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21734. return WC_TEST_RET_ENC_NC;
  21735. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  21736. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  21737. return WC_TEST_RET_ENC_NC;
  21738. wolfSSL_EVP_CIPHER_CTX_init(de);
  21739. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  21740. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21741. return WC_TEST_RET_ENC_NC;
  21742. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21743. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21744. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  21745. return WC_TEST_RET_ENC_NC;
  21746. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  21747. return WC_TEST_RET_ENC_NC;
  21748. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  21749. return WC_TEST_RET_ENC_NC;
  21750. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21751. return WC_TEST_RET_ENC_NC;
  21752. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21753. return WC_TEST_RET_ENC_NC;
  21754. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21755. wolfSSL_EVP_CIPHER_CTX_free(en);
  21756. wolfSSL_EVP_CIPHER_CTX_free(de);
  21757. #endif
  21758. #endif /* WOLFSSL_AES_256 */
  21759. }
  21760. #endif /* HAVE_AES_COUNTER */
  21761. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21762. #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128)
  21763. {
  21764. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21765. WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21766. WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21767. #else
  21768. WOLFSSL_AES_KEY enc[1];
  21769. WOLFSSL_AES_KEY dec[1];
  21770. #endif
  21771. WOLFSSL_SMALL_STACK_STATIC const byte setIv[] = {
  21772. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  21773. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  21774. };
  21775. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21776. {
  21777. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21778. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21779. };
  21780. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  21781. {
  21782. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  21783. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  21784. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  21785. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b
  21786. };
  21787. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21788. {
  21789. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21790. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21791. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21792. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51
  21793. };
  21794. byte cipher[WC_AES_BLOCK_SIZE * 2];
  21795. byte iv[WC_AES_BLOCK_SIZE]; /* iv buffer is updeated by API */
  21796. int num = 0;
  21797. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21798. if ((enc == NULL) || (dec == NULL))
  21799. return MEMORY_E;
  21800. #endif
  21801. XMEMCPY(iv, setIv, sizeof(setIv));
  21802. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, enc);
  21803. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, dec);
  21804. wolfSSL_AES_cfb128_encrypt(msg, cipher, WC_AES_BLOCK_SIZE - 1, enc, iv,
  21805. &num, AES_ENCRYPTION);
  21806. if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE - 1))
  21807. return WC_TEST_RET_ENC_NC;
  21808. if (num != 15) /* should have used 15 of the 16 bytes */
  21809. return WC_TEST_RET_ENC_NC;
  21810. wolfSSL_AES_cfb128_encrypt(msg + WC_AES_BLOCK_SIZE - 1,
  21811. cipher + WC_AES_BLOCK_SIZE - 1, WC_AES_BLOCK_SIZE + 1, enc, iv,
  21812. &num, AES_ENCRYPTION);
  21813. if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE * 2))
  21814. return WC_TEST_RET_ENC_NC;
  21815. if (num != 0)
  21816. return WC_TEST_RET_ENC_NC;
  21817. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21818. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21819. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21820. #endif
  21821. }
  21822. #endif /* WOLFSSL_AES_CFB && WOLFSSL_AES_128 */
  21823. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21824. return 0;
  21825. }
  21826. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  21827. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void)
  21828. {
  21829. wc_test_ret_t ret;
  21830. #ifdef WOLFSSL_SMALL_STACK
  21831. WOLFSSL_EVP_MD_CTX *md_ctx = (WOLFSSL_EVP_MD_CTX *)XMALLOC(sizeof(WOLFSSL_EVP_MD_CTX), NULL, DYNAMIC_TYPE_OPENSSL);
  21832. #else
  21833. WOLFSSL_EVP_MD_CTX md_ctx[1];
  21834. #endif
  21835. testVector a, b, c, d, e, f;
  21836. byte hash[WC_SHA256_DIGEST_SIZE*2]; /* max size */
  21837. #ifdef WOLFSSL_SMALL_STACK
  21838. if (md_ctx == NULL)
  21839. return WC_TEST_RET_ENC_EC(MEMORY_E);
  21840. #endif
  21841. WOLFSSL_ENTER("openssl_test");
  21842. a.inLen = 0;
  21843. b.inLen = c.inLen = d.inLen = e.inLen = f.inLen = a.inLen;
  21844. (void)a;
  21845. (void)b;
  21846. (void)c;
  21847. (void)d;
  21848. (void)e;
  21849. (void)f;
  21850. /* test malloc / free , 10 is an arbitrary amount of memory chosen */
  21851. {
  21852. byte* p;
  21853. p = (byte*)wolfSSL_CRYPTO_malloc(10, "", 0);
  21854. if (p == NULL) {
  21855. return WC_TEST_RET_ENC_NC;
  21856. }
  21857. XMEMSET(p, 0, 10);
  21858. wolfSSL_CRYPTO_free(p, "", 0);
  21859. }
  21860. #ifndef NO_MD5
  21861. a.input = "1234567890123456789012345678901234567890123456789012345678"
  21862. "9012345678901234567890";
  21863. a.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  21864. "\x7a";
  21865. a.inLen = XSTRLEN(a.input);
  21866. a.outLen = WC_MD5_DIGEST_SIZE;
  21867. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21868. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_md5());
  21869. if (ret == WOLFSSL_SUCCESS) {
  21870. ret = wolfSSL_EVP_DigestUpdate(md_ctx, a.input, (unsigned long)a.inLen);
  21871. }
  21872. if (ret == WOLFSSL_SUCCESS) {
  21873. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21874. }
  21875. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21876. if (ret != WOLFSSL_SUCCESS)
  21877. return WC_TEST_RET_ENC_NC;
  21878. if (XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE) != 0)
  21879. return WC_TEST_RET_ENC_NC;
  21880. #endif /* NO_MD5 */
  21881. #ifndef NO_SHA
  21882. b.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21883. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21884. "aaaaaaaaaa";
  21885. b.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  21886. "\x53\x99\x5E\x26\xA0";
  21887. b.inLen = XSTRLEN(b.input);
  21888. b.outLen = WC_SHA_DIGEST_SIZE;
  21889. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21890. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha1());
  21891. if (ret == WOLFSSL_SUCCESS) {
  21892. ret = wolfSSL_EVP_DigestUpdate(md_ctx, b.input, (unsigned long)b.inLen);
  21893. if (ret == WOLFSSL_SUCCESS)
  21894. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21895. }
  21896. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21897. if (ret != WOLFSSL_SUCCESS)
  21898. return WC_TEST_RET_ENC_NC;
  21899. if (XMEMCMP(hash, b.output, b.outLen) != 0)
  21900. return WC_TEST_RET_ENC_NC;
  21901. #endif /* NO_SHA */
  21902. #ifdef WOLFSSL_SHA224
  21903. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21904. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21905. e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99"
  21906. "\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3";
  21907. e.inLen = XSTRLEN(e.input);
  21908. e.outLen = WC_SHA224_DIGEST_SIZE;
  21909. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21910. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha224());
  21911. if (ret == WOLFSSL_SUCCESS) {
  21912. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21913. if (ret == WOLFSSL_SUCCESS)
  21914. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21915. }
  21916. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21917. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21918. return WC_TEST_RET_ENC_NC;
  21919. }
  21920. #endif /* WOLFSSL_SHA224 */
  21921. #ifndef NO_SHA256
  21922. d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  21923. d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  21924. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  21925. "\x06\xC1";
  21926. d.inLen = XSTRLEN(d.input);
  21927. d.outLen = WC_SHA256_DIGEST_SIZE;
  21928. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21929. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha256());
  21930. if (ret == WOLFSSL_SUCCESS) {
  21931. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21932. if (ret == WOLFSSL_SUCCESS)
  21933. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21934. }
  21935. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21936. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21937. return WC_TEST_RET_ENC_NC;
  21938. }
  21939. #endif /* !NO_SHA256 */
  21940. #ifdef WOLFSSL_SHA384
  21941. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21942. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21943. e.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  21944. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  21945. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  21946. "\x74\x60\x39";
  21947. e.inLen = XSTRLEN(e.input);
  21948. e.outLen = WC_SHA384_DIGEST_SIZE;
  21949. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21950. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha384());
  21951. if (ret == WOLFSSL_SUCCESS) {
  21952. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21953. if (ret == WOLFSSL_SUCCESS)
  21954. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21955. }
  21956. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21957. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21958. return WC_TEST_RET_ENC_NC;
  21959. }
  21960. #endif /* WOLFSSL_SHA384 */
  21961. #ifdef WOLFSSL_SHA512
  21962. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21963. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21964. f.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  21965. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  21966. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  21967. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  21968. "\x87\x4b\xe9\x09";
  21969. f.inLen = XSTRLEN(f.input);
  21970. f.outLen = WC_SHA512_DIGEST_SIZE;
  21971. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21972. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512());
  21973. if (ret == WOLFSSL_SUCCESS) {
  21974. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21975. if (ret == WOLFSSL_SUCCESS)
  21976. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21977. }
  21978. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21979. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21980. return WC_TEST_RET_ENC_NC;
  21981. }
  21982. #if !defined(WOLFSSL_NOSHA512_224) && \
  21983. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21984. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21985. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21986. f.output = "\x23\xfe\xc5\xbb\x94\xd6\x0b\x23\x30\x81\x92\x64\x0b\x0c\x45"
  21987. "\x33\x35\xd6\x64\x73\x4f\xe4\x0e\x72\x68\x67\x4a\xf9";
  21988. f.inLen = XSTRLEN(f.input);
  21989. f.outLen = WC_SHA512_224_DIGEST_SIZE;
  21990. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21991. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_224());
  21992. if (ret == WOLFSSL_SUCCESS) {
  21993. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21994. if (ret == WOLFSSL_SUCCESS)
  21995. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21996. }
  21997. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21998. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21999. return WC_TEST_RET_ENC_NC;
  22000. }
  22001. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  22002. #if !defined(WOLFSSL_NOSHA512_256) && \
  22003. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  22004. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22005. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22006. f.output = "\x39\x28\xe1\x84\xfb\x86\x90\xf8\x40\xda\x39\x88\x12\x1d\x31"
  22007. "\xbe\x65\xcb\x9d\x3e\xf8\x3e\xe6\x14\x6f\xea\xc8\x61\xe1\x9b"
  22008. "\x56\x3a";
  22009. f.inLen = XSTRLEN(f.input);
  22010. f.outLen = WC_SHA512_256_DIGEST_SIZE;
  22011. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22012. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_256());
  22013. if (ret == WOLFSSL_SUCCESS) {
  22014. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22015. if (ret == WOLFSSL_SUCCESS)
  22016. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22017. }
  22018. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22019. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  22020. return WC_TEST_RET_ENC_NC;
  22021. }
  22022. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  22023. #endif /* WOLFSSL_SHA512 */
  22024. #ifdef WOLFSSL_SHA3
  22025. #ifndef WOLFSSL_NOSHA3_224
  22026. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22027. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22028. e.output = "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a"
  22029. "\xe5\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc";
  22030. e.inLen = XSTRLEN(e.input);
  22031. e.outLen = WC_SHA3_224_DIGEST_SIZE;
  22032. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22033. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_224());
  22034. if (ret == WOLFSSL_SUCCESS) {
  22035. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22036. if (ret == WOLFSSL_SUCCESS)
  22037. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22038. }
  22039. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22040. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22041. return WC_TEST_RET_ENC_NC;
  22042. }
  22043. #endif /* WOLFSSL_NOSHA3_224 */
  22044. #ifndef WOLFSSL_NOSHA3_256
  22045. d.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22046. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22047. d.output = "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf"
  22048. "\xdb\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad"
  22049. "\x1d\x18";
  22050. d.inLen = XSTRLEN(d.input);
  22051. d.outLen = WC_SHA3_256_DIGEST_SIZE;
  22052. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22053. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_256());
  22054. if (ret == WOLFSSL_SUCCESS) {
  22055. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  22056. if (ret == WOLFSSL_SUCCESS)
  22057. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22058. }
  22059. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22060. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  22061. return WC_TEST_RET_ENC_NC;
  22062. }
  22063. #endif /* WOLFSSL_NOSHA3_256 */
  22064. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22065. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22066. e.output = "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47"
  22067. "\x91\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6"
  22068. "\x25\xdc\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79"
  22069. "\xaa\x7f\xc7";
  22070. e.inLen = XSTRLEN(e.input);
  22071. e.outLen = WC_SHA3_384_DIGEST_SIZE;
  22072. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22073. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_384());
  22074. if (ret == WOLFSSL_SUCCESS) {
  22075. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22076. if (ret == WOLFSSL_SUCCESS)
  22077. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22078. }
  22079. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22080. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22081. return WC_TEST_RET_ENC_NC;
  22082. }
  22083. #ifndef WOLFSSL_NOSHA3_512
  22084. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22085. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22086. f.output = "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78"
  22087. "\xf9\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18"
  22088. "\xa4\xfa\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8"
  22089. "\x2e\x21\x89\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55"
  22090. "\xf2\x1d\xd1\x85";
  22091. f.inLen = XSTRLEN(f.input);
  22092. f.outLen = WC_SHA3_512_DIGEST_SIZE;
  22093. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22094. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_512());
  22095. if (ret == WOLFSSL_SUCCESS) {
  22096. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22097. if (ret == WOLFSSL_SUCCESS)
  22098. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22099. }
  22100. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22101. if (ret != WOLFSSL_SUCCESS ||
  22102. XMEMCMP(hash, f.output, f.outLen) != 0) {
  22103. return WC_TEST_RET_ENC_NC;
  22104. }
  22105. #endif /* WOLFSSL_NOSHA3_512 */
  22106. #endif /* WOLFSSL_SHA3 */
  22107. #ifdef WOLFSSL_SMALL_STACK
  22108. XFREE(md_ctx, NULL, DYNAMIC_TYPE_OPENSSL);
  22109. md_ctx = NULL;
  22110. #endif
  22111. #ifndef WC_NO_RNG
  22112. if (wolfSSL_RAND_bytes(hash, sizeof(hash)) != WOLFSSL_SUCCESS)
  22113. return WC_TEST_RET_ENC_NC;
  22114. #endif
  22115. #ifndef NO_MD5
  22116. c.input = "what do ya want for nothing?";
  22117. c.output = "\x55\x78\xe8\x48\x4b\xcc\x93\x80\x93\xec\x53\xaf\x22\xd6\x14"
  22118. "\x76";
  22119. c.inLen = XSTRLEN(c.input);
  22120. c.outLen = WC_MD5_DIGEST_SIZE;
  22121. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)
  22122. /* Expect failure with MD5 + HMAC when using FIPS 140-3. */
  22123. if (wolfSSL_HMAC(wolfSSL_EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22124. hash, 0) != NULL)
  22125. #else
  22126. if (wolfSSL_HMAC(wolfSSL_EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22127. hash, 0) == NULL ||
  22128. XMEMCMP(hash, c.output, c.outLen) != 0)
  22129. #endif
  22130. {
  22131. return WC_TEST_RET_ENC_NC;
  22132. }
  22133. #endif /* NO_MD5 */
  22134. #ifndef NO_DES3
  22135. { /* des test */
  22136. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  22137. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22138. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22139. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22140. };
  22141. byte plain[24];
  22142. byte cipher[24];
  22143. WOLFSSL_const_DES_cblock key = {
  22144. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  22145. };
  22146. WOLFSSL_DES_cblock iv = {
  22147. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  22148. };
  22149. WOLFSSL_DES_key_schedule sched;
  22150. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22151. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  22152. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  22153. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  22154. };
  22155. wolfSSL_DES_key_sched(&key, &sched);
  22156. wolfSSL_DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, WC_DES_ENCRYPT);
  22157. wolfSSL_DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, WC_DES_DECRYPT);
  22158. if (XMEMCMP(plain, vector, sizeof(vector)) != 0)
  22159. return WC_TEST_RET_ENC_NC;
  22160. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22161. return WC_TEST_RET_ENC_NC;
  22162. /* test changing iv */
  22163. wolfSSL_DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, WC_DES_ENCRYPT);
  22164. wolfSSL_DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, WC_DES_ENCRYPT);
  22165. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22166. return WC_TEST_RET_ENC_NC;
  22167. } /* end des test */
  22168. #endif /* NO_DES3 */
  22169. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  22170. if ((ret = openssl_aes_test()) != 0) {
  22171. return ret;
  22172. }
  22173. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  22174. { /* evp_cipher test: EVP_aes_128_cbc */
  22175. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22176. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22177. #else
  22178. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22179. #endif
  22180. int idx, cipherSz, plainSz;
  22181. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  22182. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22183. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22184. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22185. };
  22186. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22187. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22188. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22189. 0x3b,0x5d,0x41,0x97,0x94,0x25,0xa4,0xb4,
  22190. 0xae,0x7b,0x34,0xd0,0x3f,0x0c,0xbc,0x06
  22191. };
  22192. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  22193. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22194. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22195. 0x7d,0x37,0x7b,0x0b,0x44,0xaa,0xb5,0xf0,
  22196. 0x5f,0x34,0xb4,0xde,0xb5,0xbd,0x2a,0xbb
  22197. };
  22198. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22199. "0123456789abcdef "; /* align */
  22200. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  22201. "1234567890abcdef "; /* align */
  22202. byte cipher[WC_AES_BLOCK_SIZE * 4];
  22203. byte plain [WC_AES_BLOCK_SIZE * 4];
  22204. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22205. if (ctx == NULL)
  22206. return MEMORY_E;
  22207. #endif
  22208. cipherSz = 0;
  22209. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22210. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22211. if (ret == WOLFSSL_SUCCESS) {
  22212. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, (byte*)msg, sizeof(msg));
  22213. if (ret == WOLFSSL_SUCCESS)
  22214. cipherSz += idx;
  22215. }
  22216. if (ret == WOLFSSL_SUCCESS) {
  22217. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22218. if (ret == WOLFSSL_SUCCESS)
  22219. cipherSz += idx;
  22220. }
  22221. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22222. if (ret != WOLFSSL_SUCCESS)
  22223. return WC_TEST_RET_ENC_NC;
  22224. if (cipherSz != (int)sizeof(verify) || XMEMCMP(cipher, verify, cipherSz))
  22225. return WC_TEST_RET_ENC_NC;
  22226. /* check partial decrypt (not enough padding for full block) */
  22227. plainSz = 0;
  22228. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22229. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22230. if (ret == WOLFSSL_SUCCESS) {
  22231. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, 1);
  22232. if (ret == WOLFSSL_SUCCESS)
  22233. plainSz += idx;
  22234. }
  22235. if (ret == WOLFSSL_SUCCESS) {
  22236. /* this test should fail... not enough padding for full block */
  22237. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22238. if (plainSz == 0 && ret != WOLFSSL_SUCCESS)
  22239. ret = WOLFSSL_SUCCESS;
  22240. else
  22241. ret = WC_TEST_RET_ENC_NC;
  22242. }
  22243. else
  22244. ret = WC_TEST_RET_ENC_NC;
  22245. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22246. if (ret != WOLFSSL_SUCCESS)
  22247. return ret;
  22248. plainSz = 0;
  22249. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22250. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22251. if (ret == WOLFSSL_SUCCESS) {
  22252. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, cipherSz);
  22253. if (ret == WOLFSSL_SUCCESS)
  22254. plainSz += idx;
  22255. }
  22256. if (ret == WOLFSSL_SUCCESS) {
  22257. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22258. if (ret == WOLFSSL_SUCCESS)
  22259. plainSz += idx;
  22260. }
  22261. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22262. if (ret != WOLFSSL_SUCCESS)
  22263. return WC_TEST_RET_ENC_NC;
  22264. if (plainSz != (int)sizeof(msg) || XMEMCMP(plain, msg, sizeof(msg)))
  22265. return WC_TEST_RET_ENC_NC;
  22266. cipherSz = 0;
  22267. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22268. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22269. if (ret == WOLFSSL_SUCCESS) {
  22270. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, msg, WC_AES_BLOCK_SIZE);
  22271. if (ret == WOLFSSL_SUCCESS)
  22272. cipherSz += idx;
  22273. }
  22274. if (ret == WOLFSSL_SUCCESS) {
  22275. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22276. if (ret == WOLFSSL_SUCCESS)
  22277. cipherSz += idx;
  22278. }
  22279. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22280. if (ret != WOLFSSL_SUCCESS)
  22281. return WC_TEST_RET_ENC_NC;
  22282. if (cipherSz != (int)sizeof(verify2) || XMEMCMP(cipher, verify2, cipherSz))
  22283. return WC_TEST_RET_ENC_NC;
  22284. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22285. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22286. #endif
  22287. } /* end evp_cipher test: EVP_aes_128_cbc*/
  22288. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22289. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  22290. { /* evp_cipher test: EVP_aes_256_ecb*/
  22291. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22292. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22293. #else
  22294. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22295. #endif
  22296. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  22297. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22298. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22299. };
  22300. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22301. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22302. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22303. };
  22304. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  22305. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22306. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22307. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22308. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22309. };
  22310. byte cipher[WC_AES_BLOCK_SIZE * 4];
  22311. byte plain [WC_AES_BLOCK_SIZE * 4];
  22312. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22313. if (ctx == NULL)
  22314. return MEMORY_E;
  22315. #endif
  22316. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22317. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1);
  22318. if (ret == WOLFSSL_SUCCESS)
  22319. ret = wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16);
  22320. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22321. if (ret != 16)
  22322. return WC_TEST_RET_ENC_NC;
  22323. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  22324. return WC_TEST_RET_ENC_NC;
  22325. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22326. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0);
  22327. if (ret == WOLFSSL_SUCCESS)
  22328. ret = wolfSSL_EVP_Cipher(ctx, plain, cipher, 16);
  22329. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22330. if (ret != 16)
  22331. return WC_TEST_RET_ENC_NC;
  22332. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  22333. return WC_TEST_RET_ENC_NC;
  22334. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22335. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22336. #endif
  22337. } /* end evp_cipher test */
  22338. #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */
  22339. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  22340. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  22341. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  22342. {
  22343. /* Test: AES_encrypt/decrypt/set Key */
  22344. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22345. WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22346. #ifdef HAVE_AES_DECRYPT
  22347. WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22348. #endif
  22349. #else
  22350. WOLFSSL_AES_KEY enc[1];
  22351. #ifdef HAVE_AES_DECRYPT
  22352. WOLFSSL_AES_KEY dec[1];
  22353. #endif
  22354. #endif
  22355. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  22356. {
  22357. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22358. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22359. };
  22360. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  22361. {
  22362. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22363. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22364. };
  22365. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22366. {
  22367. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22368. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22369. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22370. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22371. };
  22372. byte plain[sizeof(msg)];
  22373. byte cipher[sizeof(msg)];
  22374. printf("openSSL extra test\n") ;
  22375. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22376. if (enc == NULL)
  22377. return MEMORY_E;
  22378. #ifdef HAVE_AES_DECRYPT
  22379. if (dec == NULL)
  22380. return MEMORY_E;
  22381. #endif
  22382. #endif
  22383. wolfSSL_AES_set_encrypt_key(key, sizeof(key)*8, enc);
  22384. wolfSSL_AES_set_decrypt_key(key, sizeof(key)*8, dec);
  22385. wolfSSL_AES_encrypt(msg, cipher, enc);
  22386. #ifdef HAVE_AES_DECRYPT
  22387. wolfSSL_AES_decrypt(cipher, plain, dec);
  22388. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  22389. return WC_TEST_RET_ENC_NC;
  22390. #endif /* HAVE_AES_DECRYPT */
  22391. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  22392. return WC_TEST_RET_ENC_NC;
  22393. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22394. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22395. #ifdef HAVE_AES_DECRYPT
  22396. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22397. #endif
  22398. #endif
  22399. }
  22400. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  22401. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  22402. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  22403. #ifdef WOLFSSL_AES_COUNTER
  22404. {
  22405. byte plainBuff [64];
  22406. byte cipherBuff[64];
  22407. #ifdef WOLFSSL_AES_128
  22408. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  22409. {
  22410. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  22411. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  22412. };
  22413. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  22414. {
  22415. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22416. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22417. };
  22418. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  22419. {
  22420. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22421. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22422. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22423. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22424. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22425. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22426. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22427. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22428. };
  22429. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  22430. {
  22431. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  22432. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  22433. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  22434. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  22435. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  22436. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  22437. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  22438. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  22439. };
  22440. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  22441. {
  22442. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  22443. 0xc2
  22444. };
  22445. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22446. WOLFSSL_EVP_CIPHER_CTX *p_en;
  22447. WOLFSSL_EVP_CIPHER_CTX *p_de;
  22448. #endif
  22449. #endif /* WOLFSSL_AES_128 */
  22450. #ifdef WOLFSSL_AES_192
  22451. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22452. * NIST Special Publication 800-38A */
  22453. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  22454. {
  22455. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  22456. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  22457. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  22458. };
  22459. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  22460. {
  22461. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22462. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22463. };
  22464. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  22465. {
  22466. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22467. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22468. };
  22469. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  22470. {
  22471. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  22472. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  22473. };
  22474. #endif /* WOLFSSL_AES_192 */
  22475. #ifdef WOLFSSL_AES_256
  22476. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22477. * NIST Special Publication 800-38A */
  22478. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  22479. {
  22480. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22481. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22482. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22483. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22484. };
  22485. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  22486. {
  22487. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22488. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22489. };
  22490. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  22491. {
  22492. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22493. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22494. };
  22495. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  22496. {
  22497. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  22498. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  22499. };
  22500. #endif /* WOLFSSL_AES_256 */
  22501. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22502. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22503. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22504. if ((en == NULL) || (de == NULL))
  22505. return MEMORY_E;
  22506. #else
  22507. WOLFSSL_EVP_CIPHER_CTX en[1];
  22508. WOLFSSL_EVP_CIPHER_CTX de[1];
  22509. #endif
  22510. #ifdef WOLFSSL_AES_128
  22511. wolfSSL_EVP_CIPHER_CTX_init(en);
  22512. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22513. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22514. return WC_TEST_RET_ENC_NC;
  22515. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  22516. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  22517. return WC_TEST_RET_ENC_NC;
  22518. wolfSSL_EVP_CIPHER_CTX_init(de);
  22519. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22520. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22521. return WC_TEST_RET_ENC_NC;
  22522. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22523. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  22524. return WC_TEST_RET_ENC_NC;
  22525. if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4))
  22526. return WC_TEST_RET_ENC_NC;
  22527. if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4))
  22528. return WC_TEST_RET_ENC_NC;
  22529. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22530. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22531. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22532. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  22533. if (p_en == NULL)
  22534. return WC_TEST_RET_ENC_ERRNO;
  22535. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  22536. if (p_de == NULL)
  22537. return WC_TEST_RET_ENC_ERRNO;
  22538. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  22539. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22540. return WC_TEST_RET_ENC_NC;
  22541. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  22542. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  22543. return WC_TEST_RET_ENC_NC;
  22544. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  22545. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22546. return WC_TEST_RET_ENC_NC;
  22547. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  22548. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  22549. return WC_TEST_RET_ENC_NC;
  22550. wolfSSL_EVP_CIPHER_CTX_cleanup(p_en);
  22551. wolfSSL_EVP_CIPHER_CTX_cleanup(p_de);
  22552. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  22553. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  22554. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  22555. if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4))
  22556. return WC_TEST_RET_ENC_NC;
  22557. if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4))
  22558. return WC_TEST_RET_ENC_NC;
  22559. wolfSSL_EVP_CIPHER_CTX_init(en);
  22560. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22561. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22562. return WC_TEST_RET_ENC_NC;
  22563. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22564. return WC_TEST_RET_ENC_NC;
  22565. wolfSSL_EVP_CIPHER_CTX_init(de);
  22566. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22567. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22568. return WC_TEST_RET_ENC_NC;
  22569. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22570. return WC_TEST_RET_ENC_NC;
  22571. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22572. return WC_TEST_RET_ENC_NC;
  22573. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  22574. return WC_TEST_RET_ENC_NC;
  22575. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22576. return WC_TEST_RET_ENC_NC;
  22577. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22578. return WC_TEST_RET_ENC_NC;
  22579. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22580. return WC_TEST_RET_ENC_NC;
  22581. if (XMEMCMP(cipherBuff, oddCipher, 9))
  22582. return WC_TEST_RET_ENC_NC;
  22583. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22584. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22585. #endif /* WOLFSSL_AES_128 */
  22586. #ifdef WOLFSSL_AES_192
  22587. wolfSSL_EVP_CIPHER_CTX_init(en);
  22588. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  22589. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22590. return WC_TEST_RET_ENC_NC;
  22591. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  22592. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  22593. return WC_TEST_RET_ENC_NC;
  22594. wolfSSL_EVP_CIPHER_CTX_init(de);
  22595. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  22596. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22597. return WC_TEST_RET_ENC_NC;
  22598. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22599. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22600. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  22601. return WC_TEST_RET_ENC_NC;
  22602. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  22603. return WC_TEST_RET_ENC_NC;
  22604. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  22605. return WC_TEST_RET_ENC_NC;
  22606. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22607. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22608. #endif /* WOLFSSL_AES_192 */
  22609. #ifdef WOLFSSL_AES_256
  22610. wolfSSL_EVP_CIPHER_CTX_init(en);
  22611. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  22612. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22613. return WC_TEST_RET_ENC_NC;
  22614. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  22615. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  22616. return WC_TEST_RET_ENC_NC;
  22617. wolfSSL_EVP_CIPHER_CTX_init(de);
  22618. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  22619. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22620. return WC_TEST_RET_ENC_NC;
  22621. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22622. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22623. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  22624. return WC_TEST_RET_ENC_NC;
  22625. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  22626. return WC_TEST_RET_ENC_NC;
  22627. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  22628. return WC_TEST_RET_ENC_NC;
  22629. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22630. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22631. #endif /* WOLFSSL_AES_256 */
  22632. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22633. wolfSSL_EVP_CIPHER_CTX_free(en);
  22634. wolfSSL_EVP_CIPHER_CTX_free(de);
  22635. #endif
  22636. }
  22637. #endif /* HAVE_AES_COUNTER */
  22638. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22639. {
  22640. /* EVP_CipherUpdate test */
  22641. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  22642. {
  22643. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22644. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22645. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22646. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22647. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22648. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22649. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22650. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22651. };
  22652. byte key[] = "0123456789abcdef "; /* align */
  22653. byte iv[] = "1234567890abcdef "; /* align */
  22654. byte cipher[WC_AES_BLOCK_SIZE * 4];
  22655. byte plain [WC_AES_BLOCK_SIZE * 4];
  22656. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22657. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22658. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22659. #else
  22660. WOLFSSL_EVP_CIPHER_CTX en[1];
  22661. WOLFSSL_EVP_CIPHER_CTX de[1];
  22662. #endif
  22663. int outlen ;
  22664. int total = 0;
  22665. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22666. if ((en == NULL) || (de == NULL))
  22667. return MEMORY_E;
  22668. #endif
  22669. wolfSSL_EVP_CIPHER_CTX_init(en);
  22670. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22671. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22672. return WC_TEST_RET_ENC_NC;
  22673. /* openSSL compatibility, if(inlen == 0)return 1; */
  22674. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22675. (byte*)cbcPlain, 0) != 1)
  22676. return WC_TEST_RET_ENC_NC;
  22677. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22678. return WC_TEST_RET_ENC_NC;
  22679. wolfSSL_EVP_CIPHER_CTX_init(en);
  22680. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22681. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22682. return WC_TEST_RET_ENC_NC;
  22683. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22684. (byte*)cbcPlain, 9) == 0)
  22685. return WC_TEST_RET_ENC_NC;
  22686. if(outlen != 0)
  22687. return WC_TEST_RET_ENC_NC;
  22688. total += outlen;
  22689. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  22690. (byte*)&cbcPlain[9] , 9) == 0)
  22691. return WC_TEST_RET_ENC_NC;
  22692. if(outlen != 16)
  22693. return WC_TEST_RET_ENC_NC;
  22694. total += outlen;
  22695. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22696. return WC_TEST_RET_ENC_NC;
  22697. if(outlen != 16)
  22698. return WC_TEST_RET_ENC_NC;
  22699. total += outlen;
  22700. if(total != 32)
  22701. return WC_TEST_RET_ENC_NC;
  22702. total = 0;
  22703. wolfSSL_EVP_CIPHER_CTX_init(de);
  22704. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  22705. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22706. return WC_TEST_RET_ENC_NC;
  22707. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22708. return WC_TEST_RET_ENC_NC;
  22709. if(outlen != 0)
  22710. return WC_TEST_RET_ENC_NC;
  22711. total += outlen;
  22712. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22713. (byte*)&cipher[6], 12) == 0)
  22714. return WC_TEST_RET_ENC_NC;
  22715. if(outlen != 0)
  22716. total += outlen;
  22717. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22718. (byte*)&cipher[6+12], 14) == 0)
  22719. return WC_TEST_RET_ENC_NC;
  22720. if(outlen != 16)
  22721. return WC_TEST_RET_ENC_NC;
  22722. total += outlen;
  22723. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  22724. return WC_TEST_RET_ENC_NC;
  22725. if(outlen != 2)
  22726. return WC_TEST_RET_ENC_NC;
  22727. total += outlen;
  22728. if(total != 18)
  22729. return WC_TEST_RET_ENC_NC;
  22730. if (XMEMCMP(plain, cbcPlain, 18))
  22731. return WC_TEST_RET_ENC_NC;
  22732. total = 0;
  22733. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22734. return WC_TEST_RET_ENC_NC;
  22735. wolfSSL_EVP_CIPHER_CTX_init(en);
  22736. if (wolfSSL_EVP_EncryptInit(en, wolfSSL_EVP_aes_128_cbc(),
  22737. (unsigned char*)key, (unsigned char*)iv) == 0)
  22738. return WC_TEST_RET_ENC_NC;
  22739. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0)
  22740. return WC_TEST_RET_ENC_NC;
  22741. if(outlen != 0)
  22742. return WC_TEST_RET_ENC_NC;
  22743. total += outlen;
  22744. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0)
  22745. return WC_TEST_RET_ENC_NC;
  22746. if(outlen != 16)
  22747. return WC_TEST_RET_ENC_NC;
  22748. total += outlen;
  22749. if (wolfSSL_EVP_EncryptFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22750. return WC_TEST_RET_ENC_NC;
  22751. if(outlen != 16)
  22752. return WC_TEST_RET_ENC_NC;
  22753. total += outlen;
  22754. if(total != 32)
  22755. return 3438;
  22756. total = 0;
  22757. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22758. return WC_TEST_RET_ENC_NC;
  22759. wolfSSL_EVP_CIPHER_CTX_init(de);
  22760. if (wolfSSL_EVP_DecryptInit(de, wolfSSL_EVP_aes_128_cbc(),
  22761. (unsigned char*)key, (unsigned char*)iv) == 0)
  22762. return WC_TEST_RET_ENC_NC;
  22763. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22764. return WC_TEST_RET_ENC_NC;
  22765. if(outlen != 0)
  22766. return WC_TEST_RET_ENC_NC;
  22767. total += outlen;
  22768. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0)
  22769. return WC_TEST_RET_ENC_NC;
  22770. if(outlen != 0)
  22771. total += outlen;
  22772. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0)
  22773. return WC_TEST_RET_ENC_NC;
  22774. if(outlen != 16)
  22775. return WC_TEST_RET_ENC_NC;
  22776. total += outlen;
  22777. if (wolfSSL_EVP_DecryptFinal(de, (byte*)&plain[total], &outlen) == 0)
  22778. return WC_TEST_RET_ENC_NC;
  22779. if(outlen != 2)
  22780. return WC_TEST_RET_ENC_NC;
  22781. total += outlen;
  22782. if(total != 18)
  22783. return 3447;
  22784. if (XMEMCMP(plain, cbcPlain, 18))
  22785. return WC_TEST_RET_ENC_NC;
  22786. if (wolfSSL_EVP_Cipher_key_length(NULL) != 0)
  22787. return WC_TEST_RET_ENC_NC;
  22788. if (wolfSSL_EVP_Cipher_key_length(wolfSSL_EVP_aes_128_cbc()) != 16)
  22789. return WC_TEST_RET_ENC_NC;
  22790. if (wolfSSL_EVP_CIPHER_CTX_mode(NULL) != 0)
  22791. return WC_TEST_RET_ENC_NC;
  22792. if (wolfSSL_EVP_CIPHER_CTX_mode(en) != (en->flags & WOLFSSL_EVP_CIPH_MODE))
  22793. return WC_TEST_RET_ENC_NC;
  22794. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22795. return WC_TEST_RET_ENC_NC;
  22796. wolfSSL_EVP_CIPHER_CTX_init(en);
  22797. if (wolfSSL_EVP_CipherInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22798. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22799. return WC_TEST_RET_ENC_NC;
  22800. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22801. return WC_TEST_RET_ENC_NC;
  22802. wolfSSL_EVP_CIPHER_CTX_init(en);
  22803. if (wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22804. (unsigned char*)key, (unsigned char*)iv) == 0)
  22805. return WC_TEST_RET_ENC_NC;
  22806. if (wolfSSL_EVP_EncryptFinal_ex(NULL, NULL, NULL)
  22807. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22808. {
  22809. return WC_TEST_RET_ENC_NC;
  22810. }
  22811. if (wolfSSL_EVP_EncryptFinal(NULL, NULL, NULL)
  22812. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22813. {
  22814. return WC_TEST_RET_ENC_NC;
  22815. }
  22816. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22817. return WC_TEST_RET_ENC_NC;
  22818. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22819. return WC_TEST_RET_ENC_NC;
  22820. wolfSSL_EVP_CIPHER_CTX_init(de);
  22821. if (wolfSSL_EVP_DecryptInit_ex(de, wolfSSL_EVP_aes_128_cbc(), NULL,
  22822. (unsigned char*)key, (unsigned char*)iv) == 0)
  22823. return WC_TEST_RET_ENC_NC;
  22824. if (wolfSSL_EVP_DecryptFinal(NULL, NULL, NULL)
  22825. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22826. {
  22827. return WC_TEST_RET_ENC_NC;
  22828. }
  22829. if (wolfSSL_EVP_DecryptFinal_ex(NULL, NULL, NULL)
  22830. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22831. {
  22832. return WC_TEST_RET_ENC_NC;
  22833. }
  22834. if (wolfSSL_EVP_CIPHER_CTX_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22835. return WC_TEST_RET_ENC_NC;
  22836. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22837. return WC_TEST_RET_ENC_NC;
  22838. wolfSSL_EVP_CIPHER_CTX_init(en);
  22839. wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22840. (unsigned char*)key, (unsigned char*)iv);
  22841. if (wolfSSL_EVP_CIPHER_CTX_block_size(en) != en->block_size)
  22842. return WC_TEST_RET_ENC_NC;
  22843. if (wolfSSL_EVP_CIPHER_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22844. return WC_TEST_RET_ENC_NC;
  22845. if (wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_128_cbc()) != WC_AES_BLOCK_SIZE)
  22846. return WC_TEST_RET_ENC_NC;
  22847. if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0)
  22848. return WC_TEST_RET_ENC_NC;
  22849. if (wolfSSL_EVP_CIPHER_flags(wolfSSL_EVP_aes_128_cbc()) != WOLFSSL_EVP_CIPH_CBC_MODE)
  22850. return WC_TEST_RET_ENC_NC;
  22851. wolfSSL_EVP_CIPHER_CTX_clear_flags(en, 0xFFFFFFFF);
  22852. wolfSSL_EVP_CIPHER_CTX_set_flags(en, 42);
  22853. if (en->flags != 42)
  22854. return WC_TEST_RET_ENC_NC;
  22855. if (wolfSSL_EVP_CIPHER_CTX_set_padding(NULL, 0) !=
  22856. WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22857. return WC_TEST_RET_ENC_NC;
  22858. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != WOLFSSL_SUCCESS)
  22859. return WC_TEST_RET_ENC_NC;
  22860. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != WOLFSSL_SUCCESS)
  22861. return WC_TEST_RET_ENC_NC;
  22862. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22863. return WC_TEST_RET_ENC_NC;
  22864. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22865. return WC_TEST_RET_ENC_NC;
  22866. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22867. wolfSSL_EVP_CIPHER_CTX_free(en);
  22868. wolfSSL_EVP_CIPHER_CTX_free(de);
  22869. #endif
  22870. }
  22871. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22872. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  22873. return 0;
  22874. }
  22875. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void)
  22876. {
  22877. wc_test_ret_t ret = 0;
  22878. #if !defined(NO_SHA256) && !defined(NO_SHA)
  22879. WOLFSSL_EVP_MD_CTX* ctx;
  22880. WOLFSSL_EVP_MD_CTX* ctx2;
  22881. WOLFSSL_ENTER("openSSL_evpMD_test");
  22882. ctx = wolfSSL_EVP_MD_CTX_new();
  22883. ctx2 = wolfSSL_EVP_MD_CTX_new();
  22884. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha256());
  22885. if (ret != WOLFSSL_SUCCESS) {
  22886. ret = WC_TEST_RET_ENC_NC;
  22887. goto openSSL_evpMD_test_done;
  22888. }
  22889. ret = wolfSSL_EVP_MD_CTX_copy(ctx2, ctx);
  22890. if (ret != WOLFSSL_SUCCESS) {
  22891. ret = WC_TEST_RET_ENC_NC;
  22892. goto openSSL_evpMD_test_done;
  22893. }
  22894. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22895. ret = WC_TEST_RET_ENC_NC;
  22896. goto openSSL_evpMD_test_done;
  22897. }
  22898. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha1());
  22899. if (ret != WOLFSSL_SUCCESS) {
  22900. ret = WC_TEST_RET_ENC_NC;
  22901. goto openSSL_evpMD_test_done;
  22902. }
  22903. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22904. ret = WC_TEST_RET_ENC_NC;
  22905. goto openSSL_evpMD_test_done;
  22906. }
  22907. ret = wolfSSL_EVP_MD_CTX_copy_ex(ctx2, ctx);
  22908. if (ret != WOLFSSL_SUCCESS) {
  22909. ret = WC_TEST_RET_ENC_NC;
  22910. goto openSSL_evpMD_test_done;
  22911. }
  22912. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) == wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22913. ret = WC_TEST_RET_ENC_NC;
  22914. goto openSSL_evpMD_test_done;
  22915. }
  22916. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha1()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22917. ret = WC_TEST_RET_ENC_NC;
  22918. goto openSSL_evpMD_test_done;
  22919. }
  22920. if (wolfSSL_EVP_DigestInit_ex(ctx, wolfSSL_EVP_sha1(), NULL) != WOLFSSL_SUCCESS) {
  22921. ret = WC_TEST_RET_ENC_NC;
  22922. goto openSSL_evpMD_test_done;
  22923. }
  22924. if (wolfSSL_EVP_add_digest(NULL) != 0) {
  22925. ret = WC_TEST_RET_ENC_NC;
  22926. goto openSSL_evpMD_test_done;
  22927. }
  22928. if (wolfSSL_EVP_add_cipher(NULL) != 0) {
  22929. ret = WC_TEST_RET_ENC_NC;
  22930. goto openSSL_evpMD_test_done;
  22931. }
  22932. ret = 0; /* got to success state without jumping to end with a fail */
  22933. openSSL_evpMD_test_done:
  22934. wolfSSL_EVP_MD_CTX_free(ctx);
  22935. wolfSSL_EVP_MD_CTX_free(ctx2);
  22936. #endif /* NO_SHA256 */
  22937. return ret;
  22938. }
  22939. #ifdef DEBUG_SIGN
  22940. static void show(const char *title, const char *p, unsigned int s) {
  22941. char* i;
  22942. printf("%s: ", title);
  22943. for (i = p;
  22944. i < p + s;
  22945. printf("%c", *i), i++);
  22946. printf("\n");
  22947. }
  22948. #else
  22949. #define show(a,b,c) WC_DO_NOTHING
  22950. #endif
  22951. #define FOURK_BUFF 4096
  22952. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void)
  22953. {
  22954. wc_test_ret_t ret = 0;
  22955. #if !defined(NO_RSA) && !defined(NO_SHA)
  22956. byte* prvTmp;
  22957. byte* pubTmp;
  22958. int prvBytes;
  22959. int pubBytes;
  22960. WOLFSSL_RSA *prvRsa = NULL;
  22961. WOLFSSL_RSA *pubRsa = NULL;
  22962. WOLFSSL_EVP_PKEY *prvPkey = NULL;
  22963. WOLFSSL_EVP_PKEY *pubPkey = NULL;
  22964. WOLFSSL_EVP_PKEY_CTX *enc = NULL;
  22965. WOLFSSL_EVP_PKEY_CTX *dec = NULL;
  22966. byte in[] = TEST_STRING;
  22967. byte out[256];
  22968. size_t outlen;
  22969. size_t keySz;
  22970. byte plain[256];
  22971. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  22972. XFILE keyFile;
  22973. XFILE keypubFile;
  22974. char cliKey[] = "./certs/client-key.der";
  22975. char cliKeypub[] = "./certs/client-keyPub.der";
  22976. #endif
  22977. WOLFSSL_ENTER("openssl_pkey0_test");
  22978. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22979. if (prvTmp == NULL)
  22980. return WC_TEST_RET_ENC_ERRNO;
  22981. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22982. if (pubTmp == NULL) {
  22983. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22984. return WC_TEST_RET_ENC_NC;
  22985. }
  22986. #ifdef USE_CERT_BUFFERS_1024
  22987. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  22988. prvBytes = sizeof_client_key_der_1024;
  22989. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  22990. pubBytes = sizeof_client_keypub_der_1024;
  22991. #elif defined(USE_CERT_BUFFERS_2048)
  22992. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  22993. prvBytes = sizeof_client_key_der_2048;
  22994. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  22995. pubBytes = sizeof_client_keypub_der_2048;
  22996. #else
  22997. keyFile = XFOPEN(cliKey, "rb");
  22998. if (!keyFile) {
  22999. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23000. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23001. err_sys("can't open ./certs/client-key.der, "
  23002. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23003. return WC_TEST_RET_ENC_ERRNO;
  23004. }
  23005. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23006. XFCLOSE(keyFile);
  23007. if (prvBytes == 0) {
  23008. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23009. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23010. return WC_TEST_RET_ENC_ERRNO;
  23011. }
  23012. keypubFile = XFOPEN(cliKeypub, "rb");
  23013. if (!keypubFile) {
  23014. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23015. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23016. err_sys("can't open ./certs/client-cert.der, "
  23017. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23018. return WC_TEST_RET_ENC_ERRNO;
  23019. }
  23020. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23021. XFCLOSE(keypubFile);
  23022. if (pubBytes == 0) {
  23023. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23024. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23025. return WC_TEST_RET_ENC_ERRNO;
  23026. }
  23027. #endif /* USE_CERT_BUFFERS */
  23028. prvRsa = wolfSSL_RSA_new();
  23029. pubRsa = wolfSSL_RSA_new();
  23030. if((prvRsa == NULL) || (pubRsa == NULL)){
  23031. printf("error with RSA_new\n");
  23032. ret = WC_TEST_RET_ENC_ERRNO;
  23033. goto openssl_pkey0_test_done;
  23034. }
  23035. ret = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23036. if(ret != WOLFSSL_SUCCESS){
  23037. printf("error with RSA_LoadDer_ex\n");
  23038. ret = WC_TEST_RET_ENC_EC(ret);
  23039. goto openssl_pkey0_test_done;
  23040. }
  23041. ret = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23042. if(ret != WOLFSSL_SUCCESS){
  23043. printf("error with RSA_LoadDer_ex\n");
  23044. ret = WC_TEST_RET_ENC_EC(ret);
  23045. goto openssl_pkey0_test_done;
  23046. }
  23047. keySz = (size_t)wolfSSL_RSA_size(pubRsa);
  23048. prvPkey = wolfSSL_EVP_PKEY_new();
  23049. pubPkey = wolfSSL_EVP_PKEY_new();
  23050. if((prvPkey == NULL) || (pubPkey == NULL)){
  23051. printf("error with PKEY_new\n");
  23052. ret = WC_TEST_RET_ENC_NC;
  23053. goto openssl_pkey0_test_done;
  23054. }
  23055. ret = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23056. ret += wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23057. if(ret != 2){
  23058. printf("error with PKEY_set1_RSA\n");
  23059. ret = WC_TEST_RET_ENC_I(ret);
  23060. goto openssl_pkey0_test_done;
  23061. }
  23062. dec = wolfSSL_EVP_PKEY_CTX_new(prvPkey, NULL);
  23063. enc = wolfSSL_EVP_PKEY_CTX_new(pubPkey, NULL);
  23064. if((dec == NULL)||(enc==NULL)){
  23065. printf("error with EVP_PKEY_CTX_new\n");
  23066. ret = WC_TEST_RET_ENC_NC;
  23067. goto openssl_pkey0_test_done;
  23068. }
  23069. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23070. if (ret != 1) {
  23071. printf("error with decrypt init\n");
  23072. ret = WC_TEST_RET_ENC_NC;
  23073. goto openssl_pkey0_test_done;
  23074. }
  23075. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23076. if (ret != 1) {
  23077. printf("error with encrypt init\n");
  23078. ret = WC_TEST_RET_ENC_NC;
  23079. goto openssl_pkey0_test_done;
  23080. }
  23081. XMEMSET(out, 0, sizeof(out));
  23082. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23083. if (ret != 1) {
  23084. printf("error encrypting msg\n");
  23085. ret = WC_TEST_RET_ENC_NC;
  23086. goto openssl_pkey0_test_done;
  23087. }
  23088. show("encrypted msg", out, outlen);
  23089. XMEMSET(plain, 0, sizeof(plain));
  23090. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23091. if (ret != 1) {
  23092. printf("error decrypting msg\n");
  23093. ret = WC_TEST_RET_ENC_NC;
  23094. goto openssl_pkey0_test_done;
  23095. }
  23096. show("decrypted msg", plain, outlen);
  23097. /* RSA_PKCS1_OAEP_PADDING test */
  23098. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23099. if (ret != 1) {
  23100. printf("error with decrypt init\n");
  23101. ret = WC_TEST_RET_ENC_NC;
  23102. goto openssl_pkey0_test_done;
  23103. }
  23104. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23105. if (ret != 1) {
  23106. printf("error with encrypt init\n");
  23107. ret = WC_TEST_RET_ENC_NC;
  23108. goto openssl_pkey0_test_done;
  23109. }
  23110. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23111. printf("first set rsa padding error\n");
  23112. ret = WC_TEST_RET_ENC_EC(ret);
  23113. goto openssl_pkey0_test_done;
  23114. }
  23115. #ifndef HAVE_FIPS
  23116. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23117. printf("second set rsa padding error\n");
  23118. ret = WC_TEST_RET_ENC_EC(ret);
  23119. goto openssl_pkey0_test_done;
  23120. }
  23121. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23122. printf("third set rsa padding error\n");
  23123. ret = WC_TEST_RET_ENC_EC(ret);
  23124. goto openssl_pkey0_test_done;
  23125. }
  23126. #endif
  23127. XMEMSET(out, 0, sizeof(out));
  23128. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23129. if (ret != 1) {
  23130. printf("error encrypting msg\n");
  23131. ret = WC_TEST_RET_ENC_NC;
  23132. goto openssl_pkey0_test_done;
  23133. }
  23134. show("encrypted msg", out, outlen);
  23135. XMEMSET(plain, 0, sizeof(plain));
  23136. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23137. if (ret != 1) {
  23138. printf("error decrypting msg\n");
  23139. ret = WC_TEST_RET_ENC_NC;
  23140. goto openssl_pkey0_test_done;
  23141. }
  23142. show("decrypted msg", plain, outlen);
  23143. ret = 0; /* made it to this point without error then set success */
  23144. openssl_pkey0_test_done:
  23145. wolfSSL_RSA_free(prvRsa);
  23146. wolfSSL_RSA_free(pubRsa);
  23147. wolfSSL_EVP_PKEY_free(pubPkey);
  23148. wolfSSL_EVP_PKEY_free(prvPkey);
  23149. wolfSSL_EVP_PKEY_CTX_free(dec);
  23150. wolfSSL_EVP_PKEY_CTX_free(enc);
  23151. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23152. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23153. #endif /* NO_RSA */
  23154. return ret;
  23155. }
  23156. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void)
  23157. {
  23158. wc_test_ret_t ret = 0;
  23159. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_SHA)
  23160. WOLFSSL_EVP_PKEY_CTX* dec = NULL;
  23161. WOLFSSL_EVP_PKEY_CTX* enc = NULL;
  23162. WOLFSSL_EVP_PKEY* pubKey = NULL;
  23163. WOLFSSL_EVP_PKEY* prvKey = NULL;
  23164. WOLFSSL_X509* x509 = NULL;
  23165. WOLFSSL_SMALL_STACK_STATIC const unsigned char msg[] = "sugar slapped";
  23166. const unsigned char* clikey;
  23167. long cliKeySz;
  23168. size_t outlen;
  23169. int keyLenBits = 2048;
  23170. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23171. unsigned char *tmp = (unsigned char *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23172. unsigned char *cipher = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23173. unsigned char *plain = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23174. if ((tmp == NULL) ||
  23175. (cipher == NULL) ||
  23176. (plain == NULL)) {
  23177. ret = WC_TEST_RET_ENC_NC;
  23178. goto openssl_pkey1_test_done;
  23179. }
  23180. #else
  23181. unsigned char tmp[FOURK_BUF];
  23182. unsigned char cipher[RSA_TEST_BYTES];
  23183. unsigned char plain[RSA_TEST_BYTES];
  23184. #endif
  23185. WOLFSSL_ENTER("openssl_pkey1_test");
  23186. #if defined(USE_CERT_BUFFERS_1024)
  23187. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  23188. cliKeySz = (long)sizeof_client_key_der_1024;
  23189. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_1024,
  23190. sizeof_client_cert_der_1024, SSL_FILETYPE_ASN1);
  23191. keyLenBits = 1024;
  23192. #elif defined(USE_CERT_BUFFERS_2048)
  23193. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  23194. cliKeySz = (long)sizeof_client_key_der_2048;
  23195. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_2048,
  23196. sizeof_client_cert_der_2048, SSL_FILETYPE_ASN1);
  23197. #elif defined(USE_CERT_BUFFERS_3072)
  23198. XMEMCPY(tmp, client_key_der_3072, sizeof_client_key_der_3072);
  23199. cliKeySz = (long)sizeof_client_key_der_3072;
  23200. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_3072,
  23201. sizeof_client_cert_der_3072, SSL_FILETYPE_ASN1);
  23202. keyLenBits = 3072;
  23203. #elif defined(USE_CERT_BUFFERS_4096)
  23204. XMEMCPY(tmp, client_key_der_4096, sizeof_client_key_der_4096);
  23205. cliKeySz = (long)sizeof_client_key_der_4096;
  23206. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_4096,
  23207. sizeof_client_cert_der_4096, SSL_FILETYPE_ASN1);
  23208. keyLenBits = 4096;
  23209. #else
  23210. {
  23211. XFILE f;
  23212. f = XFOPEN(clientKey, "rb");
  23213. if (!f) {
  23214. err_sys("can't open ./certs/client-key.der, "
  23215. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23216. ret = WC_TEST_RET_ENC_ERRNO;
  23217. goto openssl_pkey1_test_done;
  23218. }
  23219. cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f);
  23220. XFCLOSE(f);
  23221. if (cliKeySz == 0)
  23222. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, openssl_pkey1_test_done);
  23223. }
  23224. /* using existing wolfSSL api to get public and private key */
  23225. x509 = wolfSSL_X509_load_certificate_file(clientCert, WOLFSSL_FILETYPE_ASN1);
  23226. #endif /* USE_CERT_BUFFERS */
  23227. clikey = tmp;
  23228. if ((prvKey = wolfSSL_EVP_PKEY_new()) == NULL) {
  23229. ret = WC_TEST_RET_ENC_ERRNO;
  23230. goto openssl_pkey1_test_done;
  23231. }
  23232. wolfSSL_EVP_PKEY_free(prvKey);
  23233. prvKey = NULL;
  23234. if (x509 == NULL) {
  23235. ret = WC_TEST_RET_ENC_NC;
  23236. goto openssl_pkey1_test_done;
  23237. }
  23238. pubKey = wolfSSL_X509_get_pubkey(x509);
  23239. if (pubKey == NULL) {
  23240. ret = WC_TEST_RET_ENC_NC;
  23241. goto openssl_pkey1_test_done;
  23242. }
  23243. prvKey = wolfSSL_d2i_PrivateKey(WC_EVP_PKEY_RSA, NULL, &clikey, cliKeySz);
  23244. if (prvKey == NULL) {
  23245. ret = WC_TEST_RET_ENC_NC;
  23246. goto openssl_pkey1_test_done;
  23247. }
  23248. /* phase 2 API to create WOLFSSL_EVP_PKEY_CTX and encrypt/decrypt */
  23249. if (wolfSSL_EVP_PKEY_bits(prvKey) != keyLenBits) {
  23250. ret = WC_TEST_RET_ENC_NC;
  23251. goto openssl_pkey1_test_done;
  23252. }
  23253. if (wolfSSL_EVP_PKEY_size(prvKey) != keyLenBits/8) {
  23254. ret = WC_TEST_RET_ENC_NC;
  23255. goto openssl_pkey1_test_done;
  23256. }
  23257. dec = wolfSSL_EVP_PKEY_CTX_new(prvKey, NULL);
  23258. enc = wolfSSL_EVP_PKEY_CTX_new(pubKey, NULL);
  23259. if (dec == NULL || enc == NULL) {
  23260. ret = WC_TEST_RET_ENC_ERRNO;
  23261. goto openssl_pkey1_test_done;
  23262. }
  23263. if (wolfSSL_EVP_PKEY_decrypt_init(dec) != 1) {
  23264. ret = WC_TEST_RET_ENC_NC;
  23265. goto openssl_pkey1_test_done;
  23266. }
  23267. if (wolfSSL_EVP_PKEY_encrypt_init(enc) != 1) {
  23268. ret = WC_TEST_RET_ENC_NC;
  23269. goto openssl_pkey1_test_done;
  23270. }
  23271. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23272. ret = WC_TEST_RET_ENC_NC;
  23273. goto openssl_pkey1_test_done;
  23274. }
  23275. #ifndef HAVE_FIPS
  23276. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23277. ret = WC_TEST_RET_ENC_EC(ret);
  23278. goto openssl_pkey1_test_done;
  23279. }
  23280. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23281. ret = WC_TEST_RET_ENC_EC(ret);
  23282. goto openssl_pkey1_test_done;
  23283. }
  23284. #endif
  23285. XMEMSET(cipher, 0, RSA_TEST_BYTES);
  23286. outlen = (size_t)(keyLenBits/8);
  23287. if (wolfSSL_EVP_PKEY_encrypt(enc, cipher, &outlen, msg, sizeof(msg)) < 0) {
  23288. ret = WC_TEST_RET_ENC_EC(ret);
  23289. goto openssl_pkey1_test_done;
  23290. }
  23291. XMEMSET(plain, 0, RSA_TEST_BYTES);
  23292. if (wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, cipher, outlen) != 1) {
  23293. ret = WC_TEST_RET_ENC_NC;
  23294. goto openssl_pkey1_test_done;
  23295. }
  23296. openssl_pkey1_test_done:
  23297. if (pubKey != NULL) {
  23298. wolfSSL_EVP_PKEY_free(pubKey);
  23299. }
  23300. if (prvKey != NULL) {
  23301. wolfSSL_EVP_PKEY_free(prvKey);
  23302. }
  23303. if (dec != NULL) {
  23304. wolfSSL_EVP_PKEY_CTX_free(dec);
  23305. }
  23306. if (enc != NULL) {
  23307. wolfSSL_EVP_PKEY_CTX_free(enc);
  23308. }
  23309. if (x509 != NULL) {
  23310. wolfSSL_X509_free(x509);
  23311. }
  23312. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23313. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23314. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23315. XFREE(plain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23316. #endif
  23317. #endif
  23318. return ret;
  23319. }
  23320. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void)
  23321. {
  23322. #if !defined(NO_RSA) && !defined(NO_SHA)
  23323. byte* prvTmp;
  23324. byte* pubTmp;
  23325. int prvBytes;
  23326. int pubBytes;
  23327. WOLFSSL_RSA *prvRsa;
  23328. WOLFSSL_RSA *pubRsa;
  23329. WOLFSSL_EVP_PKEY *prvPkey;
  23330. WOLFSSL_EVP_PKEY *pubPkey;
  23331. WOLFSSL_EVP_MD_CTX* sign;
  23332. WOLFSSL_EVP_MD_CTX* verf;
  23333. char msg[] = "see spot run";
  23334. unsigned char sig[256];
  23335. unsigned int sigSz;
  23336. const void* pt;
  23337. unsigned int count;
  23338. wc_test_ret_t ret, ret1, ret2;
  23339. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  23340. XFILE keyFile;
  23341. XFILE keypubFile;
  23342. char cliKey[] = "./certs/client-key.der";
  23343. char cliKeypub[] = "./certs/client-keyPub.der";
  23344. #endif
  23345. WOLFSSL_ENTER("openssl_evpSig_test");
  23346. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23347. if (prvTmp == NULL)
  23348. return WC_TEST_RET_ENC_ERRNO;
  23349. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23350. if (pubTmp == NULL) {
  23351. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23352. return WC_TEST_RET_ENC_NC;
  23353. }
  23354. #ifdef USE_CERT_BUFFERS_1024
  23355. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  23356. prvBytes = sizeof_client_key_der_1024;
  23357. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  23358. pubBytes = sizeof_client_keypub_der_1024;
  23359. #elif defined(USE_CERT_BUFFERS_2048)
  23360. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  23361. prvBytes = sizeof_client_key_der_2048;
  23362. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  23363. pubBytes = sizeof_client_keypub_der_2048;
  23364. #else
  23365. keyFile = XFOPEN(cliKey, "rb");
  23366. if (!keyFile) {
  23367. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23368. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23369. err_sys("can't open ./certs/client-key.der, "
  23370. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23371. return WC_TEST_RET_ENC_ERRNO;
  23372. }
  23373. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23374. XFCLOSE(keyFile);
  23375. if (prvBytes == 0) {
  23376. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23377. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23378. return WC_TEST_RET_ENC_ERRNO;
  23379. }
  23380. keypubFile = XFOPEN(cliKeypub, "rb");
  23381. if (!keypubFile) {
  23382. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23383. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23384. err_sys("can't open ./certs/client-cert.der, "
  23385. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23386. return WC_TEST_RET_ENC_ERRNO;
  23387. }
  23388. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23389. XFCLOSE(keypubFile);
  23390. if (pubBytes == 0) {
  23391. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23392. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23393. return WC_TEST_RET_ENC_ERRNO;
  23394. }
  23395. #endif /* USE_CERT_BUFFERS */
  23396. prvRsa = wolfSSL_RSA_new();
  23397. pubRsa = wolfSSL_RSA_new();
  23398. if((prvRsa == NULL) || (pubRsa == NULL)){
  23399. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23400. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23401. err_sys("ERROR with RSA_new", WC_TEST_RET_ENC_NC);
  23402. return WC_TEST_RET_ENC_NC;
  23403. }
  23404. ret1 = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23405. ret2 = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23406. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23407. printf("error with RSA_LoadDer_ex\n");
  23408. return WC_TEST_RET_ENC_NC;
  23409. }
  23410. prvPkey = wolfSSL_EVP_PKEY_new();
  23411. pubPkey = wolfSSL_EVP_PKEY_new();
  23412. if((prvPkey == NULL) || (pubPkey == NULL)){
  23413. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23414. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23415. printf("error with KEY_new\n");
  23416. return WC_TEST_RET_ENC_NC;
  23417. }
  23418. ret1 = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23419. ret2 = wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23420. if((ret1 != 1) || (ret2 != 1)){
  23421. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23422. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23423. printf("error with WOLFSSL_EVP_PKEY_set1_RSA\n");
  23424. return WC_TEST_RET_ENC_NC;
  23425. }
  23426. /****************** sign and verify *******************/
  23427. sign = wolfSSL_EVP_MD_CTX_new();
  23428. verf = wolfSSL_EVP_MD_CTX_new();
  23429. if((sign == NULL)||(verf == NULL)){
  23430. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23431. wolfSSL_EVP_MD_CTX_free(sign);
  23432. wolfSSL_EVP_MD_CTX_free(verf);
  23433. return WC_TEST_RET_ENC_NC;
  23434. }
  23435. ret = wolfSSL_EVP_SignInit(sign, wolfSSL_EVP_sha1());
  23436. if (ret != WOLFSSL_SUCCESS){
  23437. printf("error with EVP_SignInit\n");
  23438. wolfSSL_EVP_MD_CTX_free(sign);
  23439. wolfSSL_EVP_MD_CTX_free(verf);
  23440. return WC_TEST_RET_ENC_NC;
  23441. }
  23442. count = sizeof(msg);
  23443. show("message = ", (char *)msg, count);
  23444. /* sign */
  23445. XMEMSET(sig, 0, sizeof(sig));
  23446. pt = (const void*)msg;
  23447. ret1 = wolfSSL_EVP_SignUpdate(sign, pt, count);
  23448. ret2 = wolfSSL_EVP_SignFinal(sign, sig, &sigSz, prvPkey);
  23449. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23450. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23451. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23452. wolfSSL_EVP_MD_CTX_free(sign);
  23453. wolfSSL_EVP_MD_CTX_free(verf);
  23454. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23455. return WC_TEST_RET_ENC_NC;
  23456. }
  23457. show("signature = ", (char *)sig, sigSz);
  23458. /* verify */
  23459. pt = (const void*)msg;
  23460. ret1 = wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23461. ret2 = wolfSSL_EVP_VerifyUpdate(verf, pt, count);
  23462. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23463. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23464. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23465. wolfSSL_EVP_MD_CTX_free(sign);
  23466. wolfSSL_EVP_MD_CTX_free(verf);
  23467. printf("error with EVP_Verify\n");
  23468. return WC_TEST_RET_ENC_NC;
  23469. }
  23470. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) != 1) {
  23471. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23472. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23473. wolfSSL_EVP_MD_CTX_free(sign);
  23474. wolfSSL_EVP_MD_CTX_free(verf);
  23475. printf("error with EVP_VerifyFinal\n");
  23476. return WC_TEST_RET_ENC_NC;
  23477. }
  23478. /* expect fail without update */
  23479. wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23480. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) == 1) {
  23481. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23482. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23483. wolfSSL_EVP_MD_CTX_free(sign);
  23484. wolfSSL_EVP_MD_CTX_free(verf);
  23485. printf("EVP_VerifyInit without update not detected\n");
  23486. return WC_TEST_RET_ENC_NC;
  23487. }
  23488. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23489. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23490. wolfSSL_EVP_MD_CTX_free(sign);
  23491. wolfSSL_EVP_MD_CTX_free(verf);
  23492. wolfSSL_RSA_free(prvRsa);
  23493. wolfSSL_RSA_free(pubRsa);
  23494. wolfSSL_EVP_PKEY_free(pubPkey);
  23495. wolfSSL_EVP_PKEY_free(prvPkey);
  23496. #endif /* NO_RSA */
  23497. return 0;
  23498. }
  23499. #endif /* OPENSSL_EXTRA */
  23500. #ifndef NO_PWDBASED
  23501. #ifdef HAVE_SCRYPT
  23502. /* Test vectors taken from RFC 7914: scrypt PBKDF - Section 12. */
  23503. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void)
  23504. {
  23505. #ifdef HAVE_FIPS
  23506. /* RFC 7914 test vector keys are too short for FIPS. */
  23507. #else
  23508. wc_test_ret_t ret;
  23509. byte derived[64];
  23510. WOLFSSL_SMALL_STACK_STATIC const byte verify1[] = {
  23511. 0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20,
  23512. 0x3b, 0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97,
  23513. 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8,
  23514. 0xdf, 0xdf, 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42,
  23515. 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, 0xf8,
  23516. 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17,
  23517. 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d, 0x36, 0x28,
  23518. 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06
  23519. };
  23520. #if !defined(BENCH_EMBEDDED)
  23521. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23522. 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00,
  23523. 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe,
  23524. 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30,
  23525. 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62,
  23526. 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88,
  23527. 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda,
  23528. 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d,
  23529. 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40
  23530. };
  23531. #endif
  23532. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23533. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  23534. 0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48,
  23535. 0x46, 0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb,
  23536. 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e,
  23537. 0xa9, 0xb5, 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2,
  23538. 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, 0xcf,
  23539. 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9,
  23540. 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65, 0x1e, 0x40,
  23541. 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87
  23542. };
  23543. #endif
  23544. #ifdef SCRYPT_TEST_ALL
  23545. /* Test case is very slow.
  23546. * Use for confirmation after code change or new platform.
  23547. */
  23548. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  23549. 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae,
  23550. 0xad, 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81,
  23551. 0xec, 0x56, 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d,
  23552. 0xab, 0xe5, 0xee, 0x98, 0x20, 0xad, 0xaa, 0x47,
  23553. 0x8e, 0x56, 0xfd, 0x8f, 0x4b, 0xa5, 0xd0, 0x9f,
  23554. 0xfa, 0x1c, 0x6d, 0x92, 0x7c, 0x40, 0xf4, 0xc3,
  23555. 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, 0x52, 0xfb,
  23556. 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, 0xa4
  23557. };
  23558. #endif
  23559. WOLFSSL_ENTER("scrypt_test");
  23560. ret = wc_scrypt(derived, NULL, 0, NULL, 0, 4, 1, 1, sizeof(verify1));
  23561. if (ret != 0)
  23562. return WC_TEST_RET_ENC_EC(ret);
  23563. if (XMEMCMP(derived, verify1, sizeof(verify1)) != 0)
  23564. return WC_TEST_RET_ENC_NC;
  23565. #if !defined(BENCH_EMBEDDED)
  23566. ret = wc_scrypt(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 10, 8, 16,
  23567. sizeof(verify2));
  23568. if (ret != 0)
  23569. return WC_TEST_RET_ENC_EC(ret);
  23570. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23571. return WC_TEST_RET_ENC_NC;
  23572. #endif
  23573. /* Test case with parallel overflowing */
  23574. ret = wc_scrypt(derived, (byte*)"password", 16, (byte*)"NaCl", 16, 2, 4, 8388608,
  23575. sizeof(verify1));
  23576. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  23577. return WC_TEST_RET_ENC_EC(ret);
  23578. /* Don't run these test on embedded, since they use large mallocs */
  23579. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23580. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23581. (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(verify3));
  23582. if (ret != 0)
  23583. return WC_TEST_RET_ENC_EC(ret);
  23584. if (XMEMCMP(derived, verify3, sizeof(verify3)) != 0)
  23585. return WC_TEST_RET_ENC_NC;
  23586. #ifdef SCRYPT_TEST_ALL
  23587. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23588. (byte*)"SodiumChloride", 14, 20, 8, 1, sizeof(verify4));
  23589. if (ret != 0)
  23590. return WC_TEST_RET_ENC_EC(ret);
  23591. if (XMEMCMP(derived, verify4, sizeof(verify4)) != 0)
  23592. return WC_TEST_RET_ENC_NC;
  23593. #endif
  23594. #else
  23595. #ifdef SCRYPT_TEST_ALL
  23596. (void)verify4;
  23597. #endif
  23598. #endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */
  23599. #if !defined(BENCH_EMBEDDED)
  23600. ret = wc_scrypt_ex(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 1<<10,
  23601. 8, 16, sizeof(verify2));
  23602. if (ret != 0)
  23603. return WC_TEST_RET_ENC_EC(ret);
  23604. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23605. return WC_TEST_RET_ENC_NC;
  23606. #endif
  23607. #endif /* !HAVE_FIPS */
  23608. return 0;
  23609. }
  23610. #endif
  23611. #ifdef HAVE_PKCS12
  23612. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void)
  23613. {
  23614. WOLFSSL_SMALL_STACK_STATIC const byte passwd[] = { 0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
  23615. 0x00, 0x00 };
  23616. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f };
  23617. WOLFSSL_SMALL_STACK_STATIC const byte passwd2[] = { 0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
  23618. 0x00, 0x67, 0x00, 0x00 };
  23619. WOLFSSL_SMALL_STACK_STATIC const byte salt2[] = { 0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5 };
  23620. byte derived[64];
  23621. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23622. 0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
  23623. 0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
  23624. 0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
  23625. };
  23626. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23627. 0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
  23628. 0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
  23629. 0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
  23630. };
  23631. int id = 1;
  23632. int kLen = 24;
  23633. int iterations = 1;
  23634. wc_test_ret_t ret;
  23635. WOLFSSL_ENTER("pkcs12_pbkdf_test");
  23636. ret = wc_PKCS12_PBKDF(derived, passwd, sizeof(passwd), salt, 8,
  23637. iterations, kLen, WC_SHA256, id);
  23638. if (ret < 0)
  23639. return WC_TEST_RET_ENC_EC(ret);
  23640. if (XMEMCMP(derived, verify, (unsigned long)kLen) != 0)
  23641. return WC_TEST_RET_ENC_NC;
  23642. iterations = 1000;
  23643. ret = wc_PKCS12_PBKDF(derived, passwd2, sizeof(passwd2), salt2, 8,
  23644. iterations, kLen, WC_SHA256, id);
  23645. if (ret < 0)
  23646. return WC_TEST_RET_ENC_EC(ret);
  23647. ret = wc_PKCS12_PBKDF_ex(derived, passwd2, sizeof(passwd2), salt2, 8,
  23648. iterations, kLen, WC_SHA256, id, HEAP_HINT);
  23649. if (ret < 0)
  23650. return WC_TEST_RET_ENC_EC(ret);
  23651. if (XMEMCMP(derived, verify2, 24) != 0)
  23652. return WC_TEST_RET_ENC_NC;
  23653. return 0;
  23654. }
  23655. #endif /* HAVE_PKCS12 */
  23656. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23657. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void)
  23658. {
  23659. char passwd[] = "passwordpassword";
  23660. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a,
  23661. 0x5d, 0x63, 0xcb, 0x06 };
  23662. int iterations = 2048;
  23663. int kLen = 24;
  23664. byte derived[64];
  23665. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23666. 0x43, 0x6d, 0xb5, 0xe8, 0xd0, 0xfb, 0x3f, 0x35, 0x42, 0x48, 0x39, 0xbc,
  23667. 0x2d, 0xd4, 0xf9, 0x37, 0xd4, 0x95, 0x16, 0xa7, 0x2a, 0x9a, 0x21, 0xd1
  23668. };
  23669. wc_test_ret_t ret;
  23670. WOLFSSL_ENTER("pbkdf2_test");
  23671. ret = wc_PBKDF2_ex(derived, (byte*)passwd, (int)XSTRLEN(passwd),
  23672. salt, (int)sizeof(salt), iterations,
  23673. kLen, WC_SHA256, HEAP_HINT, devId);
  23674. if (ret != 0)
  23675. return WC_TEST_RET_ENC_EC(ret);
  23676. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23677. return WC_TEST_RET_ENC_NC;
  23678. return 0;
  23679. }
  23680. #endif /* HAVE_PBKDF2 && !NO_SHA256 && !NO_HMAC */
  23681. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23682. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void)
  23683. {
  23684. char passwd[] = "password";
  23685. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  23686. int iterations = 1000;
  23687. int kLen = 16;
  23688. byte derived[16];
  23689. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23690. 0xDC, 0x19, 0x84, 0x7E, 0x05, 0xC6, 0x4D, 0x2F,
  23691. 0xAF, 0x10, 0xEB, 0xFB, 0x4A, 0x3D, 0x2A, 0x20
  23692. };
  23693. wc_test_ret_t ret;
  23694. WOLFSSL_ENTER("pbkdf1_test");
  23695. ret = wc_PBKDF1_ex(derived, kLen, NULL, 0, (byte*)passwd,
  23696. (int)XSTRLEN(passwd), salt, (int)sizeof(salt), iterations, WC_SHA,
  23697. HEAP_HINT);
  23698. if (ret != 0)
  23699. return ret;
  23700. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23701. return WC_TEST_RET_ENC_NC;
  23702. return 0;
  23703. }
  23704. #endif /* HAVE_PBKDF2 && !NO_SHA */
  23705. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void)
  23706. {
  23707. wc_test_ret_t ret = 0;
  23708. WOLFSSL_ENTER("pwdbased_test");
  23709. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23710. ret = pbkdf1_test();
  23711. if (ret != 0)
  23712. return ret;
  23713. #endif
  23714. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23715. ret = pbkdf2_test();
  23716. if (ret != 0)
  23717. return ret;
  23718. #endif
  23719. #ifdef HAVE_PKCS12
  23720. ret = pkcs12_pbkdf_test();
  23721. if (ret != 0)
  23722. return ret;
  23723. #endif
  23724. #ifdef HAVE_SCRYPT
  23725. ret = scrypt_test();
  23726. if (ret != 0)
  23727. return ret;
  23728. #endif
  23729. return ret;
  23730. }
  23731. #endif /* NO_PWDBASED */
  23732. #if defined(USE_CERT_BUFFERS_2048) && \
  23733. defined(HAVE_PKCS12) && \
  23734. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  23735. !defined(NO_CERTS) && !defined(NO_DES3)
  23736. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
  23737. {
  23738. wc_test_ret_t ret = 0;
  23739. WC_PKCS12* pkcs12 = NULL;
  23740. /* Gen vars */
  23741. byte* pkcs12der = NULL;
  23742. int pkcs12derSz = 0;
  23743. WC_DerCertList derCaList = {
  23744. (byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
  23745. };
  23746. char* pass = (char*)"wolfSSL test";
  23747. /* Parsing vars */
  23748. WC_DerCertList* derCaListOut = NULL;
  23749. byte* keyDer = NULL;
  23750. byte* certDer = NULL;
  23751. word32 keySz;
  23752. word32 certSz;
  23753. WOLFSSL_ENTER("pkcs12_test");
  23754. pkcs12 = wc_PKCS12_create(pass, (word32)XSTRLEN(pass),
  23755. (char*)"friendlyName" /* not used currently */,
  23756. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  23757. (byte*)server_cert_der_2048, sizeof_server_cert_der_2048,
  23758. &derCaList, PBE_SHA1_DES3, PBE_SHA1_DES3, 100, 100,
  23759. 0 /* not used currently */, HEAP_HINT);
  23760. if (pkcs12 == NULL) {
  23761. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23762. goto out;
  23763. }
  23764. ret = wc_i2d_PKCS12(pkcs12, NULL, &pkcs12derSz);
  23765. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  23766. if (ret == 0)
  23767. ret = WC_TEST_RET_ENC_NC;
  23768. else
  23769. ret = WC_TEST_RET_ENC_I(ret);
  23770. goto out;
  23771. }
  23772. pkcs12der = (byte*)XMALLOC(pkcs12derSz, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23773. if (pkcs12der == NULL) {
  23774. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23775. goto out;
  23776. }
  23777. {
  23778. /* Use tmp pointer to avoid advancing pkcs12der */
  23779. byte* tmp = pkcs12der;
  23780. ret = wc_i2d_PKCS12(pkcs12, &tmp, &pkcs12derSz);
  23781. if (ret <= 0) {
  23782. if (ret == 0)
  23783. ret = WC_TEST_RET_ENC_NC;
  23784. else
  23785. ret = WC_TEST_RET_ENC_I(ret);
  23786. goto out;
  23787. }
  23788. }
  23789. wc_PKCS12_free(pkcs12);
  23790. pkcs12 = wc_PKCS12_new_ex(HEAP_HINT);
  23791. if (pkcs12 == NULL) {
  23792. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23793. goto out;
  23794. }
  23795. /* convert the DER file into an internal structure */
  23796. ret = wc_d2i_PKCS12(pkcs12der, pkcs12derSz, pkcs12);
  23797. if (ret != 0) {
  23798. ret = WC_TEST_RET_ENC_EC(ret);
  23799. goto out;
  23800. }
  23801. /* parse the internal structure into its parts */
  23802. ret = wc_PKCS12_parse(pkcs12, "wolfSSL test", &keyDer, &keySz,
  23803. &certDer, &certSz, &derCaListOut);
  23804. if (ret != 0) {
  23805. ret = WC_TEST_RET_ENC_EC(ret);
  23806. goto out;
  23807. }
  23808. if (keyDer == NULL || certDer == NULL || derCaListOut == NULL) {
  23809. ret = WC_TEST_RET_ENC_NC;
  23810. goto out;
  23811. }
  23812. out:
  23813. if (derCaListOut)
  23814. wc_FreeCertList(derCaListOut, HEAP_HINT);
  23815. XFREE(keyDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23816. XFREE(certDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23817. if (pkcs12)
  23818. wc_PKCS12_free(pkcs12);
  23819. XFREE(pkcs12der, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23820. return ret;
  23821. }
  23822. #endif
  23823. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  23824. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  23825. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  23826. defined(WOLFSSL_AFALG_XILINX_RSA)
  23827. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  23828. static wc_test_ret_t hkdf_test(void)
  23829. #else
  23830. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void)
  23831. #endif
  23832. {
  23833. wc_test_ret_t ret = 0;
  23834. #if !defined(NO_SHA) || !defined(NO_SHA256)
  23835. int L;
  23836. byte okm1[42];
  23837. byte ikm1[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23838. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23839. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  23840. #ifndef HAVE_FIPS
  23841. byte salt1[13] ={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  23842. 0x08, 0x09, 0x0a, 0x0b, 0x0c };
  23843. byte info1[10] ={ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  23844. 0xf8, 0xf9 };
  23845. #endif
  23846. #ifndef NO_SHA
  23847. byte res1[42] = { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61,
  23848. 0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06,
  23849. 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06,
  23850. 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0,
  23851. 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
  23852. 0x49, 0x18 };
  23853. #ifndef HAVE_FIPS
  23854. byte res2[42] = { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69,
  23855. 0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81,
  23856. 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15,
  23857. 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2,
  23858. 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
  23859. 0xf8, 0x96 };
  23860. #endif
  23861. #endif /* !NO_SHA */
  23862. #ifndef NO_SHA256
  23863. byte res3[42] = { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
  23864. 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
  23865. 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
  23866. 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
  23867. 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
  23868. 0x96, 0xc8 };
  23869. #ifndef HAVE_FIPS
  23870. byte res4[42] = { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
  23871. 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
  23872. 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
  23873. 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
  23874. 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
  23875. 0x58, 0x65 };
  23876. #endif
  23877. #endif /* !NO_SHA256 */
  23878. WOLFSSL_ENTER("hkdf_test");
  23879. XMEMSET(okm1, 0, sizeof(okm1));
  23880. L = (int)sizeof(okm1);
  23881. #ifndef NO_SHA
  23882. ret = wc_HKDF(WC_SHA, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23883. okm1, (word32)L);
  23884. if (ret != 0)
  23885. return WC_TEST_RET_ENC_EC(ret);
  23886. if (XMEMCMP(okm1, res1, (unsigned long)L) != 0)
  23887. return WC_TEST_RET_ENC_NC;
  23888. #ifndef HAVE_FIPS
  23889. /* fips can't have key size under 14 bytes, salt is key too */
  23890. L = (int)sizeof(okm1);
  23891. ret = wc_HKDF(WC_SHA, ikm1, 11, salt1, (word32)sizeof(salt1),
  23892. info1, (word32)sizeof(info1), okm1, (word32)L);
  23893. if (ret != 0)
  23894. return WC_TEST_RET_ENC_EC(ret);
  23895. if (XMEMCMP(okm1, res2, (unsigned long)L) != 0)
  23896. return WC_TEST_RET_ENC_NC;
  23897. #endif /* HAVE_FIPS */
  23898. #endif /* !NO_SHA */
  23899. #ifndef NO_SHA256
  23900. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23901. okm1, (word32)L);
  23902. if (ret != 0)
  23903. return WC_TEST_RET_ENC_EC(ret);
  23904. if (XMEMCMP(okm1, res3, (unsigned long)L) != 0)
  23905. return WC_TEST_RET_ENC_NC;
  23906. #ifndef HAVE_FIPS
  23907. /* fips can't have key size under 14 bytes, salt is key too */
  23908. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1),
  23909. salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, (word32)L);
  23910. if (ret != 0)
  23911. return WC_TEST_RET_ENC_EC(ret);
  23912. if (XMEMCMP(okm1, res4, (unsigned long)L) != 0)
  23913. return WC_TEST_RET_ENC_NC;
  23914. #endif /* HAVE_FIPS */
  23915. #endif /* !NO_SHA256 */
  23916. #endif /* !NO_SHA || !NO_SHA256 */
  23917. return ret;
  23918. }
  23919. #endif /* HAVE_HKDF */
  23920. #ifdef WOLFSSL_WOLFSSH
  23921. typedef struct {
  23922. byte hashId;
  23923. byte keyId;
  23924. const byte* k;
  23925. word32 kSz;
  23926. const byte* h;
  23927. word32 hSz;
  23928. const byte* sessionId;
  23929. word32 sessionIdSz;
  23930. const byte* expectedKey;
  23931. word32 expectedKeySz;
  23932. } SshKdfTestVector;
  23933. /** Test Vector Set #3: SHA-256 **/
  23934. static const byte sshKdfTvSet3k[] = {
  23935. 0x6A, 0xC3, 0x82, 0xEA, 0xAC, 0xA0, 0x93, 0xE1,
  23936. 0x25, 0xE2, 0x5C, 0x24, 0xBE, 0xBC, 0x84, 0x64,
  23937. 0x0C, 0x11, 0x98, 0x75, 0x07, 0x34, 0x4B, 0x5C,
  23938. 0x73, 0x9C, 0xEB, 0x84, 0xA9, 0xE0, 0xB2, 0x22,
  23939. 0xB9, 0xA8, 0xB5, 0x1C, 0x83, 0x9E, 0x5E, 0xBE,
  23940. 0x49, 0xCF, 0xAD, 0xBF, 0xB3, 0x95, 0x99, 0x76,
  23941. 0x4E, 0xD5, 0x22, 0x09, 0x9D, 0xC9, 0x12, 0x75,
  23942. 0x19, 0x50, 0xDC, 0x7D, 0xC9, 0x7F, 0xBD, 0xC0,
  23943. 0x63, 0x28, 0xB6, 0x8F, 0x22, 0x78, 0x1F, 0xD3,
  23944. 0x15, 0xAF, 0x56, 0x80, 0x09, 0xA5, 0x50, 0x9E,
  23945. 0x5B, 0x87, 0xA1, 0x1B, 0xF5, 0x27, 0xC0, 0x56,
  23946. 0xDA, 0xFF, 0xD8, 0x2A, 0xB6, 0xCB, 0xC2, 0x5C,
  23947. 0xCA, 0x37, 0x14, 0x34, 0x59, 0xE7, 0xBC, 0x63,
  23948. 0xBC, 0xDE, 0x52, 0x75, 0x7A, 0xDE, 0xB7, 0xDF,
  23949. 0x01, 0xCF, 0x12, 0x17, 0x3F, 0x1F, 0xEF, 0x81,
  23950. 0x02, 0xEC, 0x5A, 0xB1, 0x42, 0xC2, 0x13, 0xDD,
  23951. 0x9D, 0x30, 0x69, 0x62, 0x78, 0xA8, 0xD8, 0xBC,
  23952. 0x32, 0xDD, 0xE9, 0x59, 0x2D, 0x28, 0xC0, 0x78,
  23953. 0xC6, 0xD9, 0x2B, 0x94, 0x7D, 0x82, 0x5A, 0xCA,
  23954. 0xAB, 0x64, 0x94, 0x84, 0x6A, 0x49, 0xDE, 0x24,
  23955. 0xB9, 0x62, 0x3F, 0x48, 0x89, 0xE8, 0xAD, 0xC3,
  23956. 0x8E, 0x8C, 0x66, 0x9E, 0xFF, 0xEF, 0x17, 0x60,
  23957. 0x40, 0xAD, 0x94, 0x5E, 0x90, 0xA7, 0xD3, 0xEE,
  23958. 0xC1, 0x5E, 0xFE, 0xEE, 0x78, 0xAE, 0x71, 0x04,
  23959. 0x3C, 0x96, 0x51, 0x11, 0x03, 0xA1, 0x6B, 0xA7,
  23960. 0xCA, 0xF0, 0xAC, 0xD0, 0x64, 0x2E, 0xFD, 0xBE,
  23961. 0x80, 0x99, 0x34, 0xFA, 0xA1, 0xA5, 0xF1, 0xBD,
  23962. 0x11, 0x04, 0x36, 0x49, 0xB2, 0x5C, 0xCD, 0x1F,
  23963. 0xEE, 0x2E, 0x38, 0x81, 0x5D, 0x4D, 0x5F, 0x5F,
  23964. 0xC6, 0xB4, 0x10, 0x29, 0x69, 0xF2, 0x1C, 0x22,
  23965. 0xAE, 0x1B, 0x0E, 0x7D, 0x36, 0x03, 0xA5, 0x56,
  23966. 0xA1, 0x32, 0x62, 0xFF, 0x62, 0x8D, 0xE2, 0x22
  23967. };
  23968. static const byte sshKdfTvSet3h[] = {
  23969. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23970. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23971. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23972. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23973. };
  23974. static const byte sshKdfTvSet3sid[] = {
  23975. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23976. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23977. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23978. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23979. };
  23980. static const byte sshKdfTvSet3a[] = {
  23981. 0x81, 0xF0, 0x33, 0x0E, 0xF6, 0xF0, 0x53, 0x61,
  23982. 0xB3, 0x82, 0x3B, 0xFD, 0xED, 0x6E, 0x1D, 0xE9
  23983. };
  23984. static const byte sshKdfTvSet3b[] = {
  23985. 0x3F, 0x6F, 0xD2, 0x06, 0x5E, 0xEB, 0x2B, 0x0B,
  23986. 0x1D, 0x93, 0x19, 0x5A, 0x1F, 0xED, 0x48, 0xA5
  23987. };
  23988. static const byte sshKdfTvSet3c[] = {
  23989. 0xC3, 0x54, 0x71, 0x03, 0x4E, 0x6F, 0xD6, 0x54,
  23990. 0x76, 0x13, 0x17, 0x8E, 0x23, 0x43, 0x5F, 0x21
  23991. };
  23992. static const byte sshKdfTvSet3d[] = {
  23993. 0x7E, 0x9D, 0x79, 0x03, 0x20, 0x90, 0xD9, 0x9F,
  23994. 0x98, 0xB0, 0x15, 0x63, 0x4D, 0xD9, 0xF4, 0x62
  23995. };
  23996. static const byte sshKdfTvSet3e[] = {
  23997. 0x24, 0xEE, 0x55, 0x9A, 0xD7, 0xCE, 0x71, 0x2B,
  23998. 0x68, 0x5D, 0x0B, 0x22, 0x71, 0xE4, 0x43, 0xC1,
  23999. 0x7A, 0xB1, 0xD1, 0xDC, 0xEB, 0x5A, 0x36, 0x05,
  24000. 0x69, 0xD2, 0x5D, 0x5D, 0xC2, 0x43, 0x00, 0x2F
  24001. };
  24002. static const byte sshKdfTvSet3f[] = {
  24003. 0xC3, 0x41, 0x9C, 0x2B, 0x96, 0x62, 0x35, 0x86,
  24004. 0x9D, 0x71, 0x4B, 0xA5, 0xAC, 0x48, 0xDD, 0xB7,
  24005. 0xD9, 0xE3, 0x5C, 0x8C, 0x19, 0xAA, 0xC7, 0x34,
  24006. 0x22, 0x33, 0x7A, 0x37, 0x34, 0x53, 0x60, 0x7E
  24007. };
  24008. static const SshKdfTestVector sshKdfTestVectors[] = {
  24009. {WC_HASH_TYPE_SHA256, 'A',
  24010. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24011. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24012. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24013. sshKdfTvSet3a, sizeof(sshKdfTvSet3a)},
  24014. {WC_HASH_TYPE_SHA256, 'B',
  24015. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24016. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24017. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24018. sshKdfTvSet3b, sizeof(sshKdfTvSet3b)},
  24019. {WC_HASH_TYPE_SHA256, 'C',
  24020. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24021. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24022. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24023. sshKdfTvSet3c, sizeof(sshKdfTvSet3c)},
  24024. {WC_HASH_TYPE_SHA256, 'D',
  24025. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24026. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24027. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24028. sshKdfTvSet3d, sizeof(sshKdfTvSet3d)},
  24029. {WC_HASH_TYPE_SHA256, 'E',
  24030. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24031. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24032. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24033. sshKdfTvSet3e, sizeof(sshKdfTvSet3e)},
  24034. {WC_HASH_TYPE_SHA256, 'F',
  24035. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24036. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24037. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24038. sshKdfTvSet3f, sizeof(sshKdfTvSet3f)},
  24039. };
  24040. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void)
  24041. {
  24042. byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and WC_AES_BLOCK_SIZE */
  24043. word32 i;
  24044. word32 tc = sizeof(sshKdfTestVectors)/sizeof(SshKdfTestVector);
  24045. const SshKdfTestVector* tv = NULL;
  24046. wc_test_ret_t result = 0;
  24047. WOLFSSL_ENTER("sshkdf_test");
  24048. /* sId - Session ID, eKey - Expected Key, cKey - Calculated Key */
  24049. for (i = 0, tv = sshKdfTestVectors; i < tc; i++, tv++) {
  24050. result = wc_SSH_KDF(tv->hashId, tv->keyId,
  24051. cKey, tv->expectedKeySz,
  24052. tv->k, tv->kSz, tv->h, tv->hSz,
  24053. tv->sessionId, tv->sessionIdSz);
  24054. if (result != 0) {
  24055. printf("KDF: Could not derive key.\n");
  24056. result = WC_TEST_RET_ENC_EC(result);
  24057. }
  24058. else {
  24059. if (XMEMCMP(cKey, tv->expectedKey, tv->expectedKeySz) != 0) {
  24060. printf("KDF: Calculated Key does not match Expected Key.\n");
  24061. result = WC_TEST_RET_ENC_EC(result);
  24062. }
  24063. }
  24064. if (result != 0) break;
  24065. }
  24066. return result;
  24067. }
  24068. #endif /* WOLFSSL_WOLFSSH */
  24069. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  24070. #define DIGL 12
  24071. #define SECL 48
  24072. #define LBSL 63
  24073. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void)
  24074. {
  24075. int ret;
  24076. byte dig[DIGL] = {0};
  24077. byte secret[SECL] = {
  24078. 0x10, 0xbc, 0xb4, 0xa2, 0xe8, 0xdc, 0xf1, 0x9b, 0x4c,
  24079. 0x51, 0x9c, 0xed, 0x31, 0x1b, 0x51, 0x57, 0x02, 0x3f,
  24080. 0xa1, 0x7d, 0xfb, 0x0e, 0xf3, 0x4e, 0x8f, 0x6f, 0x71,
  24081. 0xa3, 0x67, 0x76, 0x6b, 0xfa, 0x5d, 0x46, 0x4a, 0xe8,
  24082. 0x61, 0x18, 0x81, 0xc4, 0x66, 0xcc, 0x6f, 0x09, 0x99,
  24083. 0x9d, 0xfc, 0x47
  24084. };
  24085. byte lablSd[LBSL] = {
  24086. 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69,
  24087. 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x0b, 0x46, 0xba,
  24088. 0x56, 0xbf, 0x1f, 0x5d, 0x99, 0xff, 0xe9, 0xbb, 0x43,
  24089. 0x01, 0xe7, 0xca, 0x2c, 0x00, 0xdf, 0x9a, 0x39, 0x6e,
  24090. 0xcf, 0x6d, 0x15, 0x27, 0x4d, 0xf2, 0x93, 0x96, 0x4a,
  24091. 0x91, 0xde, 0x5c, 0xc0, 0x47, 0x7c, 0xa8, 0xae, 0xcf,
  24092. 0x5d, 0x93, 0x5f, 0x4c, 0x92, 0xcc, 0x98, 0x5b, 0x43
  24093. };
  24094. byte expected[DIGL] = {
  24095. 0xee, 0xcb, 0xb1, 0x30, 0xf2, 0xcd, 0xb3, 0x4a,
  24096. 0xbe, 0xda, 0xc1, 0xf6
  24097. };
  24098. int digL = DIGL;
  24099. int secL = SECL;
  24100. int lblsdL = LBSL;
  24101. int hash_type = sha384_mac;
  24102. ret = wc_PRF(dig, (word32)digL, secret, (word32)secL, lablSd,
  24103. (word32)lblsdL, hash_type,
  24104. HEAP_HINT, INVALID_DEVID);
  24105. if (ret != 0) {
  24106. printf("Failed w/ code: %d\n", ret);
  24107. return WC_TEST_RET_ENC_EC(ret);
  24108. }
  24109. if (XMEMCMP(expected, dig, DIGL) != 0) {
  24110. printf("Got unexpected digest\n");
  24111. return WC_TEST_RET_ENC_NC;
  24112. }
  24113. return 0;
  24114. }
  24115. #endif /* WOLFSSL_HAVE_PRF && !NO_HMAC */
  24116. #ifdef WOLFSSL_HAVE_PRF
  24117. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  24118. #ifdef WOLFSSL_BASE16
  24119. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
  24120. {
  24121. const char* preMasterSecret = "D06F9C19BFF49B1E91E4EFE97345D089"
  24122. "4E6C2E6C34A165B24540E2970875D641"
  24123. "2AA6515871B389B4C199BB8389C71CED";
  24124. const char* helloRandom = "162B81EDFBEAE4F25240320B87E7651C"
  24125. "865564191DD782DB0B9ECA275FBA1BB9"
  24126. "5A1DA3DF436D68DA86C5E7B4B4A36E46"
  24127. "B977C61767983A31BE270D74517BD0F6";
  24128. const char* masterSecret = "EB38B8D89B98B1C266DE44BB3CA14E83"
  24129. "C32F009F9955B1D994E61D3C51EE8760"
  24130. "90B4EF89CC7AF42F46E72201BFCC7977";
  24131. const char* label = "master secret";
  24132. byte pms[48] = {0};
  24133. byte seed[64] = {0};
  24134. byte ms[48] = {0};
  24135. byte result[48] = {0};
  24136. word32 pmsSz = (word32)sizeof(pms);
  24137. word32 seedSz = (word32)sizeof(seed);
  24138. word32 msSz = (word32)sizeof(ms);
  24139. int ret;
  24140. ret = Base16_Decode((const byte*)preMasterSecret,
  24141. (word32)XSTRLEN(preMasterSecret), pms, &pmsSz);
  24142. if (ret != 0)
  24143. return ret;
  24144. ret = Base16_Decode((const byte*)helloRandom,
  24145. (word32)XSTRLEN(helloRandom), seed, &seedSz);
  24146. if (ret != 0)
  24147. return ret;
  24148. ret = Base16_Decode((const byte*)masterSecret,
  24149. (word32)XSTRLEN(masterSecret), ms, &msSz);
  24150. if (ret != 0)
  24151. return ret;
  24152. ret = wc_PRF_TLS(result, msSz, pms, pmsSz,
  24153. (const byte*)label, (word32)XSTRLEN(label), seed, seedSz,
  24154. 1, sha256_mac, NULL, INVALID_DEVID);
  24155. if (ret != 0) {
  24156. if (ret == WC_NO_ERR_TRACE(FIPS_PRIVATE_KEY_LOCKED_E)) {
  24157. printf(" wc_PRF_TLSv12: Private key locked.\n");
  24158. }
  24159. return WC_TEST_RET_ENC_NC;
  24160. }
  24161. if (XMEMCMP(result, ms, msSz) != 0)
  24162. return WC_TEST_RET_ENC_NC;
  24163. return 0;
  24164. }
  24165. #endif /* WOLFSSL_BASE16 */
  24166. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  24167. #endif /* WOLFSSL_HAVE_PRF */
  24168. #ifdef WOLFSSL_TLS13
  24169. #define TLSV13_PSK_DHE_SZ 40
  24170. typedef struct {
  24171. enum wc_HashType hashAlg;
  24172. word32 pskSz;
  24173. word32 dheSz;
  24174. byte psk[TLSV13_PSK_DHE_SZ];
  24175. byte dhe[TLSV13_PSK_DHE_SZ];
  24176. byte hashHello1[WC_MAX_DIGEST_SIZE];
  24177. byte hashHello2[WC_MAX_DIGEST_SIZE];
  24178. byte hashFinished1[WC_MAX_DIGEST_SIZE];
  24179. byte hashFinished2[WC_MAX_DIGEST_SIZE];
  24180. /* Expected */
  24181. byte clientEarlyTrafficSecret[WC_MAX_DIGEST_SIZE];
  24182. byte earlyExporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24183. byte clientHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24184. byte serverHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24185. byte clientApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24186. byte serverApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24187. byte exporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24188. byte resumptionMasterSecret[WC_MAX_DIGEST_SIZE];
  24189. } Tls13KdfTestVector;
  24190. /* The following tests come from the CAVP test vectors we used for
  24191. * our FIPS validation. The hash values used are the components from
  24192. * the test hashed together. hashHello1 is the hash of the
  24193. * clientHelloRandom value of the test vector. hashHello2 is the hash
  24194. * of the clientHelloRandom and serverHelloRandom values from the test
  24195. * vector. hashFinished1 is clientHelloRandom, serverHelloRandom, and
  24196. * serverFinishedRandom. hashFinished2 is clientHelloRandom,
  24197. * serverHelloRandom, serverFinishedRandom, and clietnFinishedRandom
  24198. * hashed together. */
  24199. static const Tls13KdfTestVector tls13KdfTestVectors[] = {
  24200. { /* 1 */
  24201. WC_HASH_TYPE_SHA256, 35, 35,
  24202. { /* PSK */
  24203. 0x7b, 0xf1, 0x05, 0x31, 0x36, 0xfa, 0x03, 0xdc,
  24204. 0x31, 0x97, 0x88, 0x04, 0x9c, 0xbc, 0xee, 0xf7,
  24205. 0x8d, 0x84, 0x95, 0x26, 0xaf, 0x1d, 0x68, 0xb0,
  24206. 0x60, 0x7a, 0xcc, 0x4f, 0xc1, 0xd3, 0xa1, 0x68,
  24207. 0x7f, 0x6d, 0xbe
  24208. },
  24209. { /* DHE */
  24210. 0x6e, 0xa1, 0x77, 0xab, 0x2f, 0x43, 0xd2, 0x4b,
  24211. 0xe5, 0xa1, 0x09, 0xe0, 0x7a, 0xd0, 0x01, 0x35,
  24212. 0x8d, 0xf8, 0xf2, 0x5c, 0x91, 0x02, 0xb0, 0x6c,
  24213. 0x3f, 0xeb, 0xee, 0xa4, 0x42, 0x19, 0xce, 0xdc,
  24214. 0x81, 0x26, 0x40
  24215. },
  24216. { /* Hello 1 */
  24217. 0xd9, 0x4b, 0xe4, 0x17, 0xef, 0x58, 0x73, 0x7d,
  24218. 0x28, 0x3d, 0xf0, 0xcc, 0x05, 0x03, 0xaf, 0xac,
  24219. 0x3d, 0x92, 0x79, 0x48, 0xe8, 0x8c, 0xdb, 0xce,
  24220. 0x95, 0x82, 0x21, 0x31, 0x7b, 0x61, 0xd7, 0xc6
  24221. },
  24222. { /* Hello 2 */
  24223. 0xb7, 0x7f, 0x29, 0x91, 0xa4, 0x8b, 0x34, 0xdb,
  24224. 0xbd, 0xc7, 0x54, 0x1c, 0x3b, 0x86, 0xa3, 0x69,
  24225. 0xfe, 0x26, 0xe4, 0x7b, 0xac, 0x57, 0x71, 0xb3,
  24226. 0x32, 0x97, 0xed, 0xd2, 0x0e, 0x95, 0xb8, 0x63
  24227. },
  24228. { /* Finished 1 */
  24229. 0x65, 0xdb, 0x6d, 0x71, 0x71, 0xd0, 0xd8, 0x49,
  24230. 0xd0, 0x3c, 0x8e, 0x2b, 0x24, 0xdf, 0xc2, 0xe9,
  24231. 0xd6, 0xfd, 0xea, 0x04, 0x95, 0x7c, 0xf0, 0x7e,
  24232. 0x57, 0x74, 0x7c, 0xdd, 0xa3, 0x0b, 0x2b, 0x36
  24233. },
  24234. { /* Finished 2 */
  24235. 0x28, 0xf2, 0xf2, 0x79, 0xcf, 0x20, 0x52, 0x90,
  24236. 0x1d, 0x91, 0x05, 0xad, 0x44, 0x26, 0x23, 0x96,
  24237. 0x32, 0xce, 0xec, 0x61, 0xd1, 0xbf, 0x00, 0x48,
  24238. 0x4a, 0xa5, 0x60, 0xcc, 0x28, 0xb5, 0x8d, 0x98
  24239. },
  24240. { /* Client Early Traffic Secret */
  24241. 0x07, 0x14, 0x6a, 0x26, 0x5b, 0x6c, 0x7f, 0x4d, 0x6b, 0x47, 0x3f, 0xd5,
  24242. 0x03, 0x1d, 0xd2, 0x23, 0x3d, 0x89, 0x3e, 0xc6, 0x51, 0xd1, 0xac, 0xf8,
  24243. 0x28, 0xae, 0x4b, 0x76, 0xc8, 0x10, 0x7e, 0xdd
  24244. },
  24245. { /* Early Exporter Master Secret */
  24246. 0xb8, 0xd3, 0x25, 0x7e, 0x2d, 0x41, 0x7b, 0xcb, 0x5e, 0x82, 0x49, 0xf5,
  24247. 0x51, 0x3d, 0xb7, 0x59, 0x32, 0xb3, 0xdf, 0x99, 0x4e, 0x04, 0x69, 0xc6,
  24248. 0x96, 0x8e, 0xe6, 0x3d, 0x91, 0xe4, 0x81, 0x11
  24249. },
  24250. { /* Client Handshake Traffic Secret */
  24251. 0xd9, 0x3b, 0x54, 0xe2, 0xb0, 0xd1, 0x85, 0xf0, 0xfd, 0xf3, 0x48, 0x4a,
  24252. 0xf8, 0x0b, 0xa5, 0xdc, 0x4c, 0x37, 0xcb, 0xd4, 0x20, 0xaf, 0x60, 0xc7,
  24253. 0xd5, 0x50, 0x5d, 0x0c, 0x77, 0x3b, 0x6f, 0xd2
  24254. },
  24255. { /* Server Handshake Traffic Secret */
  24256. 0x4d, 0x40, 0x2b, 0xd2, 0x8c, 0x33, 0x90, 0x39, 0x67, 0x67, 0x05, 0xf7,
  24257. 0x5d, 0x37, 0x1e, 0xdc, 0x4a, 0x70, 0x6b, 0x9e, 0xf8, 0x06, 0x61, 0x89,
  24258. 0x70, 0xe1, 0x3d, 0x36, 0xad, 0x88, 0x7e, 0x5b
  24259. },
  24260. { /* Client Application Traffic Secret */
  24261. 0x74, 0x6e, 0xa0, 0x13, 0x18, 0x34, 0x48, 0x4d, 0x23, 0x31, 0xf1, 0xf9,
  24262. 0xee, 0x44, 0x6d, 0xad, 0xc1, 0xad, 0x92, 0x73, 0xca, 0x27, 0x16, 0x91,
  24263. 0xa2, 0x50, 0x9a, 0xfc, 0xec, 0xf0, 0x6b, 0x24
  24264. },
  24265. { /* Server Application Traffic Secret */
  24266. 0x89, 0x18, 0x7e, 0x34, 0x8d, 0xfc, 0x14, 0xb1, 0x4f, 0x21, 0xd8, 0x29,
  24267. 0xdb, 0x9b, 0xfb, 0x55, 0xcf, 0xa1, 0x4f, 0x95, 0xf8, 0xe0, 0xb0, 0x83,
  24268. 0xd5, 0x34, 0x9e, 0x0b, 0x83, 0x37, 0x42, 0x93
  24269. },
  24270. { /* Exporter Master Secret */
  24271. 0x7d, 0xc8, 0x88, 0x46, 0xd5, 0x57, 0x15, 0xb6, 0x24, 0x25, 0x92, 0x61,
  24272. 0xb1, 0x18, 0x86, 0x2a, 0x6d, 0xa5, 0x84, 0xeb, 0x59, 0xdf, 0x13, 0xbd,
  24273. 0x73, 0xaa, 0x5d, 0x65, 0xab, 0xd9, 0xb4, 0x56
  24274. },
  24275. { /* Resumption Master Secret */
  24276. 0x20, 0xb7, 0xd0, 0xe3, 0x82, 0x01, 0xa1, 0x04, 0xb8, 0x13, 0x29, 0xed,
  24277. 0x35, 0xe4, 0x2f, 0xbf, 0x58, 0x23, 0x7f, 0x21, 0xdb, 0x9f, 0xf8, 0xe0,
  24278. 0xe8, 0xe4, 0xab, 0xc4, 0xa1, 0x61, 0xb9, 0xbb
  24279. }
  24280. },
  24281. { /* 6 */
  24282. WC_HASH_TYPE_SHA256, 0, 33,
  24283. { 0 }, /* PSK */
  24284. { /* DHE */
  24285. 0x7a, 0x46, 0x8c, 0x5a, 0xd1, 0x8e, 0x95, 0xba,
  24286. 0x61, 0xe6, 0x6f, 0xe6, 0x76, 0x0c, 0x20, 0x43,
  24287. 0x16, 0x82, 0x15, 0xfe, 0x54, 0xa3, 0xc7, 0xfd,
  24288. 0x3b, 0x2c, 0x88, 0xb4, 0xd3, 0x42, 0x70, 0x12,
  24289. 0x18
  24290. },
  24291. { /* Hello 1 */
  24292. 0x63, 0x83, 0x58, 0xab, 0x36, 0xcd, 0x0c, 0xf3,
  24293. 0x26, 0x07, 0xb5, 0x5f, 0x0b, 0x8b, 0x45, 0xd6,
  24294. 0x7d, 0x5b, 0x42, 0xdc, 0xa8, 0xaa, 0x06, 0xfb,
  24295. 0x20, 0xa5, 0xbb, 0x85, 0xdb, 0x54, 0xd8, 0x8b
  24296. },
  24297. { /* Hello 2 */
  24298. 0xea, 0xfe, 0x9e, 0x8e, 0xff, 0x1f, 0x6f, 0x43,
  24299. 0xf9, 0x5d, 0xfd, 0xbf, 0xe2, 0x5f, 0x02, 0x2f,
  24300. 0x6d, 0x47, 0x60, 0x9a, 0x48, 0x9a, 0x75, 0xfb,
  24301. 0xb5, 0x4a, 0xbf, 0x9c, 0x4e, 0xff, 0xbf, 0x0b
  24302. },
  24303. { /* Finished 1 */
  24304. 0xca, 0x25, 0xb3, 0x53, 0x8e, 0x6d, 0xc3, 0x36,
  24305. 0x17, 0x30, 0x07, 0xdf, 0x0d, 0xd7, 0x79, 0xb0,
  24306. 0x7f, 0xcb, 0xbe, 0x7a, 0xbc, 0x2d, 0x9f, 0x2d,
  24307. 0x94, 0x44, 0x94, 0xe6, 0xa4, 0xf3, 0xe8, 0x53
  24308. },
  24309. { /* Finished 2 */
  24310. 0x2e, 0xa6, 0x5a, 0xaf, 0xb5, 0xba, 0x9f, 0x2f,
  24311. 0x74, 0x83, 0x5d, 0xbf, 0x86, 0xa4, 0xa6, 0xf6,
  24312. 0xb9, 0x89, 0xdf, 0x17, 0xe1, 0xa8, 0x14, 0xc0,
  24313. 0xe1, 0x50, 0xfa, 0xec, 0xfa, 0xae, 0x8b, 0x7b
  24314. },
  24315. {
  24316. 0x20, 0x18, 0x72, 0x7c, 0xde, 0x3a, 0x85, 0x17, 0x72, 0xdc, 0xd7, 0x72,
  24317. 0xb0, 0xfc, 0x45, 0xd0, 0x62, 0xb9, 0xbb, 0x38, 0x69, 0x05, 0x7b, 0xb4,
  24318. 0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
  24319. },
  24320. {
  24321. 0x68, 0x10, 0x20, 0xd1, 0x5e, 0xfc, 0x0c, 0x53, 0x85, 0xbb, 0xdb, 0x18,
  24322. 0xa8, 0x78, 0xf1, 0x2b, 0x13, 0xba, 0x64, 0x1d, 0xe7, 0x09, 0xbe, 0x13,
  24323. 0x49, 0x26, 0xf9, 0x98, 0x56, 0xf1, 0x43, 0xfb
  24324. },
  24325. {
  24326. 0x24, 0x35, 0x3e, 0x10, 0x6f, 0x39, 0x50, 0xd6, 0xa2, 0x12, 0x99, 0xf2,
  24327. 0xd5, 0xf5, 0x19, 0xf5, 0x84, 0xed, 0xee, 0x78, 0x2a, 0xa6, 0xfa, 0x3d,
  24328. 0x06, 0xa8, 0xa7, 0x5d, 0x97, 0x78, 0xd6, 0x58
  24329. },
  24330. {
  24331. 0xf4, 0x57, 0xac, 0x24, 0x7a, 0xfb, 0x7c, 0x3b, 0xb6, 0x39, 0x17, 0x14,
  24332. 0xd9, 0xd4, 0x58, 0x4d, 0x46, 0xd5, 0x1b, 0xde, 0xf7, 0x9d, 0x06, 0xee,
  24333. 0x8d, 0x1a, 0x2c, 0x25, 0x6d, 0x64, 0xde, 0x89
  24334. },
  24335. {
  24336. 0xb6, 0x00, 0xce, 0x63, 0xed, 0x65, 0x8b, 0x66, 0x66, 0x42, 0xc6, 0xbd,
  24337. 0x89, 0xc4, 0x71, 0x6f, 0xce, 0x28, 0xb2, 0xac, 0x97, 0x07, 0x5b, 0xea,
  24338. 0xb8, 0x1d, 0x4c, 0xeb, 0x9e, 0x71, 0x07, 0x8f
  24339. },
  24340. {
  24341. 0xf8, 0x92, 0xc8, 0xba, 0xe7, 0x83, 0xfe, 0x68, 0xe4, 0xd6, 0x5e, 0xcb,
  24342. 0xb3, 0xef, 0x49, 0xd0, 0xe7, 0xb1, 0xac, 0xcb, 0x39, 0x19, 0xfd, 0xa7,
  24343. 0xf7, 0xca, 0xab, 0x1e, 0x42, 0x14, 0xd8, 0xe7
  24344. },
  24345. {
  24346. 0x32, 0x4a, 0x1a, 0xad, 0xe2, 0xbb, 0x55, 0x8a, 0xdd, 0xe9, 0xa5, 0x2a,
  24347. 0x46, 0x5e, 0x6c, 0x83, 0x66, 0x27, 0x27, 0x94, 0xdd, 0x68, 0x59, 0xa0,
  24348. 0xbb, 0xe8, 0x31, 0x7c, 0x39, 0xd7, 0xfd, 0x6d
  24349. },
  24350. {
  24351. 0x58, 0xbc, 0x6c, 0x5b, 0x24, 0xad, 0x82, 0xb3, 0xcc, 0xc7, 0xd1, 0xa1,
  24352. 0xaa, 0x2b, 0x98, 0x9f, 0x2f, 0x7e, 0xa9, 0x63, 0xc2, 0x8e, 0xb6, 0x06,
  24353. 0xc2, 0x2b, 0x74, 0x4b, 0x79, 0x19, 0x7e, 0x2e
  24354. }
  24355. },
  24356. { /* 11 */
  24357. WC_HASH_TYPE_SHA256, 33, 0,
  24358. { /* PSK */
  24359. 0x3d, 0x39, 0x49, 0x36, 0x98, 0xc5, 0xfd, 0xcd,
  24360. 0xa0, 0x17, 0xbd, 0x65, 0x0a, 0xdb, 0xd4, 0x07,
  24361. 0x56, 0xa2, 0x7b, 0xb8, 0x2a, 0x7e, 0xfb, 0x26,
  24362. 0x74, 0xe1, 0xbc, 0x08, 0x4b, 0xf0, 0x30, 0x14,
  24363. 0x12
  24364. },
  24365. { 0 }, /* DHE */
  24366. { /* Hello 1 */
  24367. 0xb7, 0x44, 0x74, 0x6c, 0x57, 0x1f, 0xf3, 0x84,
  24368. 0x8f, 0x63, 0xfb, 0x8c, 0x94, 0x6c, 0x16, 0x68,
  24369. 0x4b, 0xe1, 0xb5, 0xb5, 0x2a, 0x4e, 0x5f, 0xdf,
  24370. 0x4b, 0x53, 0xb2, 0x35, 0xfc, 0x30, 0xf1, 0x36
  24371. },
  24372. { /* Hello 2 */
  24373. 0xe6, 0x4f, 0x3a, 0x4f, 0xd7, 0xe0, 0x64, 0xd4,
  24374. 0x69, 0x50, 0xe4, 0x8b, 0xba, 0xbc, 0x47, 0x74,
  24375. 0xa7, 0x9b, 0x40, 0x91, 0x8f, 0xa8, 0x72, 0x22,
  24376. 0x97, 0xad, 0x43, 0xa7, 0x11, 0x86, 0xb5, 0x72
  24377. },
  24378. { /* Finished 1 */
  24379. 0x5f, 0xa6, 0x10, 0xe2, 0xa3, 0x99, 0x0b, 0x5e,
  24380. 0x57, 0xee, 0xc3, 0x3a, 0x8e, 0x04, 0xf3, 0x0e,
  24381. 0x58, 0x02, 0x09, 0xb2, 0x7e, 0x2d, 0xc6, 0xd2,
  24382. 0x08, 0xae, 0x68, 0x0a, 0x55, 0xa5, 0xda, 0x51
  24383. },
  24384. { /* Finished 2 */
  24385. 0xfc, 0x5b, 0xc0, 0x7e, 0x1b, 0xaa, 0xc0, 0xb4,
  24386. 0x34, 0x85, 0x49, 0x8e, 0x16, 0x31, 0x98, 0xdf,
  24387. 0x10, 0x54, 0x22, 0xda, 0x1e, 0x6b, 0x51, 0xf6,
  24388. 0x97, 0x57, 0xa0, 0x7a, 0x92, 0xe7, 0x47, 0x52
  24389. },
  24390. {
  24391. 0x80, 0xfa, 0x36, 0x30, 0xb8, 0x65, 0xb3, 0x2a, 0x1d, 0x68, 0x91, 0x06,
  24392. 0x98, 0xa0, 0x17, 0x8f, 0xee, 0xb7, 0x9e, 0x3d, 0xd8, 0x84, 0x99, 0x30,
  24393. 0xb9, 0xd6, 0x09, 0x25, 0x5e, 0xfb, 0x8f, 0xd3 },
  24394. {
  24395. 0xa9, 0x89, 0x29, 0x70, 0xe4, 0x55, 0xec, 0x97, 0xfb, 0x24, 0x5b, 0xf9,
  24396. 0xf1, 0xa3, 0x19, 0x3d, 0xf1, 0x31, 0x14, 0xcd, 0x2a, 0xed, 0x21, 0xc8,
  24397. 0xb1, 0x53, 0xad, 0x11, 0x0b, 0x9e, 0x5a, 0xee },
  24398. {
  24399. 0x72, 0xad, 0x8d, 0x7f, 0xfc, 0xb7, 0x68, 0xda, 0x27, 0x60, 0x37, 0xa3,
  24400. 0x4a, 0x63, 0xe8, 0xa5, 0xc8, 0xcd, 0x36, 0x6a, 0x77, 0x99, 0x0d, 0xa9,
  24401. 0xb1, 0x5b, 0x2f, 0x47, 0x2e, 0x22, 0xa7, 0x5e },
  24402. {
  24403. 0x95, 0x6e, 0x85, 0x09, 0xe5, 0x04, 0x88, 0x14, 0x28, 0x8d, 0xdf, 0xe6,
  24404. 0x0d, 0x0f, 0x0d, 0x6b, 0x4e, 0x66, 0x1c, 0x03, 0xb9, 0xaa, 0x2d, 0x45,
  24405. 0x56, 0x67, 0x5c, 0x55, 0x29, 0xd6, 0x89, 0xd0 },
  24406. {
  24407. 0xe8, 0xf2, 0x14, 0xf9, 0x9b, 0x2b, 0x9f, 0x24, 0x2b, 0x37, 0xbe, 0x86,
  24408. 0xdb, 0x23, 0x4b, 0xbe, 0x39, 0x57, 0xe8, 0xa9, 0xa5, 0xee, 0x08, 0xf2,
  24409. 0x75, 0x58, 0xdb, 0xd9, 0x51, 0xc1, 0x46, 0x02 },
  24410. {
  24411. 0x3d, 0x19, 0xaf, 0xa3, 0x0b, 0x21, 0xf7, 0x3d, 0xe7, 0x37, 0x6e, 0x32,
  24412. 0x13, 0x48, 0x9d, 0xea, 0xe0, 0x90, 0xbf, 0x64, 0x48, 0xf7, 0x1e, 0xcc,
  24413. 0xf0, 0xbc, 0x92, 0xd7, 0x8a, 0x4a, 0xa8, 0xc1 },
  24414. {
  24415. 0x16, 0x35, 0xb1, 0x66, 0x28, 0xa3, 0x3e, 0x19, 0xf5, 0x2d, 0x92, 0x22,
  24416. 0x95, 0x48, 0xe8, 0x34, 0x7b, 0x30, 0x50, 0xa2, 0xa0, 0xd9, 0xc2, 0x59,
  24417. 0x39, 0xf9, 0x8c, 0x69, 0xf2, 0x2a, 0xb9, 0xff },
  24418. {
  24419. 0x32, 0x71, 0xa6, 0x87, 0x0c, 0x97, 0x42, 0x07, 0xdd, 0x5f, 0xc9, 0x44,
  24420. 0xa5, 0x7c, 0x50, 0x14, 0xfd, 0xe7, 0x5f, 0x8b, 0xd3, 0x2f, 0xdc, 0x9b,
  24421. 0xa9, 0x93, 0x22, 0x19, 0xe6, 0xf2, 0x0c, 0xd8 }
  24422. },
  24423. #ifdef WOLFSSL_SHA384
  24424. { /* 26 */
  24425. WC_HASH_TYPE_SHA384, 35, 35,
  24426. { /* PSK */
  24427. 0x62, 0x83, 0x25, 0xc7, 0xcc, 0x08, 0x5e, 0x63,
  24428. 0x64, 0x56, 0xf0, 0xc6, 0x88, 0x27, 0x5a, 0x5b,
  24429. 0x68, 0x59, 0x0b, 0x14, 0x55, 0x13, 0x2e, 0xfd,
  24430. 0x8f, 0x28, 0x5b, 0x3d, 0xe3, 0xad, 0x67, 0xe4,
  24431. 0x68, 0xba, 0xf9
  24432. },
  24433. { /* DHE */
  24434. 0xa8, 0xb1, 0xab, 0xd8, 0xc8, 0x5b, 0x52, 0xdf,
  24435. 0x7f, 0x49, 0x10, 0xf4, 0xa1, 0x31, 0xd1, 0x91,
  24436. 0x36, 0xc1, 0x87, 0x5d, 0x42, 0x2a, 0xe7, 0x1d,
  24437. 0x2c, 0x29, 0x3d, 0x40, 0x64, 0x61, 0x63, 0x76,
  24438. 0xd8, 0x66, 0xac
  24439. },
  24440. { /* Hello 1 */
  24441. 0x6f, 0xc6, 0x4c, 0xe1, 0xc6, 0x68, 0x34, 0x8c,
  24442. 0x0a, 0xe1, 0xf8, 0xb8, 0x3e, 0xd4, 0xf8, 0x0b,
  24443. 0x54, 0x50, 0xe4, 0xc5, 0x4a, 0x33, 0x7d, 0xbd,
  24444. 0x90, 0xd2, 0xa2, 0xb9, 0xb7, 0x92, 0xed, 0xab,
  24445. 0x14, 0xf1, 0xe4, 0x86, 0x22, 0x67, 0xd7, 0x44,
  24446. 0x03, 0x21, 0xdc, 0x51, 0x52, 0x7f, 0x35, 0x80
  24447. },
  24448. { /* Hello 2 */
  24449. 0x3e, 0xcf, 0x2f, 0xc3, 0x87, 0xba, 0xc5, 0xbd,
  24450. 0x7c, 0xe8, 0x35, 0x5b, 0x95, 0x51, 0x30, 0x3b,
  24451. 0x08, 0xcc, 0x2a, 0x7d, 0xb5, 0x74, 0x7c, 0x16,
  24452. 0xb3, 0x0b, 0xe7, 0x61, 0xa3, 0x7c, 0x6c, 0xbd,
  24453. 0x39, 0x74, 0xfd, 0x1e, 0x4c, 0xff, 0xc8, 0xcc,
  24454. 0xa0, 0xef, 0x29, 0x4d, 0x94, 0xaa, 0x55, 0x6f,
  24455. },
  24456. { /* Finished 1 */
  24457. 0x06, 0xc1, 0x47, 0x78, 0x66, 0x53, 0x6f, 0x24,
  24458. 0x94, 0x61, 0x69, 0xec, 0xd8, 0x60, 0x31, 0x2f,
  24459. 0xbf, 0xd6, 0x8a, 0x29, 0x17, 0xff, 0xa3, 0x88,
  24460. 0x13, 0x09, 0x8c, 0x9d, 0x6c, 0x64, 0x84, 0x48,
  24461. 0x44, 0xdd, 0x2d, 0x29, 0x4d, 0xe6, 0x98, 0x2b,
  24462. 0x45, 0x3b, 0x84, 0x33, 0x79, 0xb2, 0x75, 0x68
  24463. },
  24464. { /* Finished 2 */
  24465. 0x28, 0x1e, 0x18, 0xf7, 0x9c, 0x32, 0xa9, 0xbf,
  24466. 0x0c, 0x24, 0x58, 0x21, 0xce, 0xbc, 0xf2, 0x44,
  24467. 0xb1, 0x18, 0xaf, 0x9d, 0xd9, 0x20, 0xf9, 0xf4,
  24468. 0xed, 0xcc, 0x53, 0x82, 0x66, 0x5c, 0x46, 0x94,
  24469. 0x8c, 0x36, 0x5e, 0xca, 0x9f, 0xd8, 0x9a, 0xd3,
  24470. 0xf0, 0xe1, 0x53, 0x71, 0xdd, 0x19, 0x1e, 0x59
  24471. },
  24472. {
  24473. 0xd0, 0xef, 0xa8, 0xcb, 0x5b, 0x14, 0x0f, 0x0a, 0x62, 0xba, 0x5a, 0xb1,
  24474. 0xc5, 0xb5, 0x3f, 0x11, 0xda, 0xa1, 0x0c, 0x9c, 0xb4, 0x32, 0x48, 0x4e,
  24475. 0xfa, 0x84, 0x4f, 0xe4, 0xe7, 0x91, 0x8f, 0x42, 0x3f, 0xc7, 0x4e, 0xd3,
  24476. 0x83, 0x3d, 0x7f, 0x70, 0x12, 0xee, 0x9a, 0x37, 0x01, 0xbb, 0x14, 0xd3
  24477. },
  24478. {
  24479. 0x48, 0x6f, 0x77, 0x1d, 0x39, 0x1b, 0xa5, 0x9a, 0x76, 0xd9, 0x1d, 0x7d,
  24480. 0xb3, 0xd9, 0xb9, 0x78, 0x35, 0x0f, 0xd0, 0xe1, 0x07, 0x1f, 0x8d, 0xe5,
  24481. 0x75, 0x00, 0xda, 0xc0, 0x19, 0x01, 0xfb, 0x08, 0x35, 0xe7, 0x18, 0x8f,
  24482. 0xf0, 0x19, 0xfb, 0x46, 0xf6, 0xa5, 0x77, 0x0e, 0x90, 0x38, 0x8b, 0x15
  24483. },
  24484. {
  24485. 0x80, 0x8c, 0xa7, 0x24, 0x97, 0xf9, 0xd3, 0x52, 0xb0, 0x69, 0x9d, 0x4b,
  24486. 0xa4, 0x19, 0x4a, 0xb1, 0x46, 0x53, 0x3a, 0xc8, 0xe4, 0x02, 0x69, 0xf2,
  24487. 0xe7, 0xb6, 0x1d, 0x33, 0x51, 0xcc, 0x14, 0x40, 0x4a, 0xb0, 0xe7, 0x58,
  24488. 0x84, 0xba, 0xc2, 0x14, 0x58, 0x6b, 0xb9, 0xdc, 0x50, 0x98, 0x67, 0x01
  24489. },
  24490. {
  24491. 0xb1, 0xa8, 0xc0, 0x06, 0xb3, 0x2e, 0xa7, 0x8a, 0x6a, 0x12, 0x88, 0x00,
  24492. 0x65, 0x88, 0x9c, 0x5d, 0x35, 0xee, 0xe5, 0x51, 0x0b, 0x62, 0xf8, 0x67,
  24493. 0xe5, 0xef, 0x15, 0x1f, 0x23, 0x02, 0x74, 0x08, 0x9c, 0xc8, 0xba, 0x27,
  24494. 0x5d, 0x32, 0x19, 0x6f, 0x6d, 0x5d, 0x72, 0x5e, 0x15, 0xde, 0x30, 0xc3
  24495. },
  24496. {
  24497. 0xfd, 0xce, 0xf5, 0x65, 0x45, 0x84, 0xfb, 0x8c, 0x79, 0xa4, 0x6c, 0x1b,
  24498. 0x0e, 0x1b, 0xfd, 0x26, 0xa2, 0x53, 0xf4, 0x4e, 0x00, 0x4d, 0x4b, 0x0b,
  24499. 0x24, 0x6d, 0x35, 0x35, 0xd9, 0x97, 0x70, 0xc5, 0xf4, 0xee, 0xe3, 0xba,
  24500. 0x31, 0x1e, 0x2a, 0x42, 0xcb, 0xdf, 0x40, 0xb1, 0x14, 0xb8, 0x53, 0xce
  24501. },
  24502. {
  24503. 0xbb, 0xb3, 0x26, 0x7c, 0x22, 0x21, 0x9b, 0x72, 0x32, 0xa1, 0x97, 0xfb,
  24504. 0x78, 0x8c, 0xbe, 0x3d, 0x71, 0x45, 0xb8, 0xf5, 0x24, 0x8f, 0x0f, 0xac,
  24505. 0x42, 0x5b, 0x81, 0xe8, 0xd0, 0x71, 0x4a, 0xcb, 0x32, 0x3f, 0x03, 0xfb,
  24506. 0xec, 0x6a, 0x1f, 0x76, 0x80, 0x65, 0x01, 0x7a, 0x3d, 0xce, 0xc4, 0xdf
  24507. },
  24508. {
  24509. 0x3f, 0xcf, 0x2f, 0x63, 0x94, 0x94, 0x99, 0xfd, 0x04, 0x3a, 0x89, 0x83,
  24510. 0xcf, 0x06, 0x05, 0xec, 0x20, 0x3e, 0x5f, 0x51, 0x9d, 0x6e, 0x4a, 0xc6,
  24511. 0xf1, 0x2b, 0x37, 0x17, 0x34, 0x72, 0x6e, 0x1d, 0x2a, 0xfd, 0xc7, 0x73,
  24512. 0xb5, 0x07, 0x22, 0x81, 0x32, 0x2e, 0x21, 0x85, 0xaf, 0x10, 0xb2, 0x73
  24513. },
  24514. {
  24515. 0x52, 0x0c, 0x3d, 0x2e, 0x2d, 0x4a, 0x11, 0xae, 0x96, 0x78, 0xe9, 0x5b,
  24516. 0xd8, 0x0f, 0x6c, 0xf4, 0xbd, 0x96, 0x13, 0x55, 0x88, 0xdd, 0xa3, 0x67,
  24517. 0x36, 0x86, 0x1e, 0x0b, 0x36, 0x41, 0xec, 0xf6, 0x04, 0xb2, 0xc4, 0x16,
  24518. 0xbc, 0x2c, 0xdb, 0x30, 0x02, 0x94, 0xd4, 0x42, 0xbf, 0x38, 0xee, 0x9d
  24519. }
  24520. },
  24521. { /* 36 */
  24522. WC_HASH_TYPE_SHA384, 0, 33,
  24523. { 0 }, /* PSK */
  24524. { /* DHE */
  24525. 0xd3, 0x00, 0x72, 0x9a, 0xa8, 0xc5, 0xf3, 0xc4,
  24526. 0xf1, 0xa0, 0x26, 0x89, 0x65, 0x70, 0xc7, 0x0b,
  24527. 0x77, 0xbb, 0xe1, 0x4b, 0x2b, 0xa8, 0x4f, 0xa6,
  24528. 0x09, 0x4b, 0xba, 0x45, 0x36, 0x15, 0xee, 0x68,
  24529. 0xfd
  24530. },
  24531. { /* Hello 1 */
  24532. 0x10, 0x9d, 0x8b, 0xa2, 0x93, 0xe7, 0xd3, 0xb9,
  24533. 0xb4, 0x0f, 0xeb, 0x6a, 0xb9, 0x69, 0xcb, 0x39,
  24534. 0x16, 0x29, 0xcc, 0xd3, 0xcc, 0x1a, 0x4c, 0x1b,
  24535. 0x53, 0x7c, 0x33, 0x88, 0x06, 0xbc, 0x0a, 0x02,
  24536. 0xa0, 0xbe, 0x62, 0xc0, 0xe6, 0x5e, 0x97, 0x5b,
  24537. 0x6a, 0xa1, 0x98, 0xf3, 0xd2, 0x1e, 0xcd, 0xc5
  24538. },
  24539. { /* Hello 2 */
  24540. 0x74, 0xc0, 0x07, 0x2c, 0xc1, 0x63, 0xcc, 0x11,
  24541. 0xad, 0x1a, 0x55, 0x63, 0xbc, 0x20, 0x77, 0x96,
  24542. 0x30, 0x1c, 0x68, 0x45, 0x1e, 0x9b, 0xa7, 0xb4,
  24543. 0xf3, 0x04, 0x45, 0x16, 0x76, 0x55, 0xf9, 0xdf,
  24544. 0x4b, 0x2f, 0x1a, 0xdf, 0x5a, 0xb0, 0x93, 0xc9,
  24545. 0xab, 0xf5, 0x32, 0x47, 0x79, 0x9c, 0x01, 0xeb
  24546. },
  24547. { /* Finished 1 */
  24548. 0x27, 0x08, 0x8e, 0xa5, 0xf1, 0x30, 0xe1, 0xd6,
  24549. 0x4f, 0xa2, 0x9e, 0x3b, 0x03, 0x2d, 0x2e, 0xa3,
  24550. 0x84, 0x75, 0x51, 0x3a, 0xc3, 0xf6, 0xee, 0x2e,
  24551. 0x37, 0x0c, 0xe3, 0x28, 0x46, 0xa5, 0x2d, 0xc7,
  24552. 0xf0, 0x64, 0x78, 0x53, 0x66, 0x43, 0x02, 0xa4,
  24553. 0x7a, 0x43, 0x66, 0x4b, 0xa7, 0xcb, 0x97, 0x16
  24554. },
  24555. { /* Finished 2 */
  24556. 0x1d, 0x0d, 0xf8, 0xe1, 0x81, 0xa5, 0xbd, 0xa8,
  24557. 0x6f, 0x9d, 0x01, 0xa4, 0x9a, 0x92, 0xe2, 0xef,
  24558. 0x08, 0xab, 0xef, 0x3e, 0x2d, 0xd4, 0x82, 0xac,
  24559. 0x68, 0x9d, 0xe0, 0x54, 0x17, 0xde, 0x1a, 0xed,
  24560. 0x57, 0xcb, 0xd9, 0x2d, 0xc8, 0xbc, 0x93, 0xe6,
  24561. 0xa3, 0xec, 0xde, 0xee, 0xa1, 0x1c, 0x41, 0x85
  24562. },
  24563. {
  24564. 0x7f, 0x1f, 0xe6, 0x7b, 0xd8, 0xf5, 0x2b, 0x37, 0xbe, 0xb7, 0xd0, 0x37,
  24565. 0xce, 0x46, 0xad, 0x04, 0x2f, 0xc7, 0xdb, 0xc9, 0x9a, 0xb6, 0x00, 0x3f,
  24566. 0xc1, 0x97, 0xe9, 0x5c, 0x5e, 0x14, 0xd1, 0x38, 0x4d, 0x55, 0xe1, 0x07,
  24567. 0xb5, 0x85, 0x6d, 0xfa, 0xa7, 0x66, 0xad, 0xfa, 0xb6, 0xad, 0x29, 0x44
  24568. },
  24569. {
  24570. 0x4e, 0x6b, 0x20, 0x99, 0x55, 0x1b, 0x21, 0x89, 0xb6, 0x70, 0xdb, 0xe8,
  24571. 0xa7, 0x16, 0x55, 0xf2, 0x93, 0x13, 0x90, 0x7d, 0xfa, 0x62, 0x65, 0x53,
  24572. 0xa0, 0x97, 0xe9, 0xb4, 0xc0, 0xf1, 0xc9, 0x1a, 0x67, 0xdd, 0xca, 0x57,
  24573. 0xbc, 0xca, 0x39, 0xe6, 0x39, 0x6b, 0x63, 0x47, 0x25, 0x08, 0x3a, 0xd7
  24574. },
  24575. {
  24576. 0x35, 0x0d, 0xac, 0xd8, 0x10, 0x6a, 0x46, 0x50, 0x66, 0xae, 0x02, 0xc9,
  24577. 0xde, 0x13, 0x48, 0xce, 0x53, 0xd4, 0x92, 0x62, 0xc5, 0x65, 0x10, 0x08,
  24578. 0xc2, 0xc2, 0x82, 0xed, 0x9d, 0xc9, 0x6f, 0xa8, 0xc3, 0xc1, 0x0b, 0x7c,
  24579. 0xe1, 0x97, 0x85, 0xd6, 0x46, 0x29, 0x0e, 0x42, 0x51, 0xc1, 0x35, 0xcf
  24580. },
  24581. {
  24582. 0x3d, 0x5d, 0x84, 0xbd, 0x16, 0x46, 0x34, 0xb3, 0xf6, 0x31, 0x49, 0x3e,
  24583. 0x8d, 0xdc, 0xcb, 0x8c, 0x6a, 0x42, 0xf4, 0x88, 0xfc, 0x19, 0xfa, 0xa2,
  24584. 0x25, 0xc7, 0xa0, 0xa4, 0xca, 0xf0, 0xea, 0x2d, 0xe8, 0xc4, 0x02, 0x14,
  24585. 0x63, 0xfb, 0xd3, 0x7b, 0x51, 0x1c, 0xce, 0xca, 0xa3, 0xc3, 0xe4, 0xa5
  24586. },
  24587. {
  24588. 0x7c, 0x3a, 0x55, 0x92, 0x2e, 0xdd, 0x75, 0xdd, 0x76, 0x54, 0x4a, 0x9f,
  24589. 0xd0, 0xa2, 0x88, 0x83, 0xe9, 0x27, 0xda, 0x30, 0xe9, 0x96, 0x58, 0xc5,
  24590. 0xb7, 0x56, 0xfc, 0x4b, 0xb8, 0x5d, 0xee, 0x46, 0x70, 0x4e, 0x1b, 0x06,
  24591. 0x86, 0xaf, 0x48, 0x5c, 0x17, 0x35, 0xfa, 0x69, 0xc2, 0x4d, 0xfb, 0x09
  24592. },
  24593. {
  24594. 0x00, 0x0e, 0x28, 0x51, 0xc1, 0x7f, 0x41, 0x89, 0x6f, 0x9a, 0xca, 0x15,
  24595. 0xee, 0xed, 0x43, 0xca, 0x6d, 0x65, 0x6f, 0x51, 0x18, 0x6c, 0x08, 0x4b,
  24596. 0x77, 0xca, 0x75, 0xc4, 0xc3, 0xde, 0x29, 0x41, 0x8b, 0xaf, 0xa7, 0x1c,
  24597. 0x28, 0x37, 0xa0, 0xa0, 0x74, 0x8e, 0x09, 0x42, 0x7a, 0x1b, 0x68, 0xdb
  24598. },
  24599. {
  24600. 0x14, 0x8f, 0xab, 0x28, 0x64, 0xea, 0x45, 0x88, 0xdb, 0xc1, 0xc6, 0xa0,
  24601. 0x48, 0xdf, 0x15, 0xd0, 0x28, 0x07, 0x2d, 0x6c, 0xb8, 0x42, 0xbb, 0x60,
  24602. 0x02, 0x08, 0x9e, 0x29, 0x9b, 0x8d, 0xd6, 0x1c, 0xaf, 0xf2, 0x1a, 0xdc,
  24603. 0xf0, 0x78, 0x0b, 0x4d, 0x90, 0xa1, 0x0c, 0xb3, 0x13, 0xde, 0xca, 0x5a
  24604. },
  24605. {
  24606. 0x4d, 0x80, 0x7d, 0x0b, 0xb9, 0x00, 0x6f, 0x65, 0x51, 0x65, 0x23, 0xde,
  24607. 0x72, 0xdc, 0x4f, 0x04, 0xa5, 0xa2, 0x90, 0x45, 0x51, 0x9e, 0xd0, 0x3a,
  24608. 0xe4, 0xd7, 0x78, 0xa3, 0x0f, 0x2d, 0x65, 0x12, 0xad, 0xc8, 0x92, 0x30,
  24609. 0x79, 0x9d, 0x9d, 0x08, 0x7a, 0x9c, 0x9f, 0x83, 0xb1, 0xca, 0x59, 0x56
  24610. }
  24611. },
  24612. { /* 41 */
  24613. WC_HASH_TYPE_SHA384, 33, 0,
  24614. { /* PSK */
  24615. 0xa4, 0x8b, 0x1b, 0x5f, 0xd0, 0xea, 0x75, 0x62,
  24616. 0x06, 0x4d, 0x68, 0x40, 0x85, 0x20, 0x45, 0x95,
  24617. 0x4a, 0x00, 0xca, 0x05, 0xeb, 0xd4, 0x1d, 0x48,
  24618. 0x81, 0x89, 0xe8, 0x86, 0x43, 0xfa, 0x28, 0x17,
  24619. 0x12
  24620. },
  24621. { 0 }, /* DHE */
  24622. { /* Hello 1 */
  24623. 0x03, 0x7c, 0x33, 0x75, 0xdc, 0xc5, 0x46, 0x3a,
  24624. 0x0d, 0x56, 0xc6, 0xfb, 0xab, 0x1e, 0x1d, 0xda,
  24625. 0x59, 0xc2, 0xb2, 0xb1, 0x7c, 0x48, 0x9b, 0x06,
  24626. 0x0a, 0x5a, 0xbb, 0xf8, 0x98, 0x53, 0x78, 0x2d,
  24627. 0xd2, 0xcc, 0x87, 0x68, 0x25, 0xdd, 0x88, 0x22,
  24628. 0xcd, 0xb7, 0x74, 0x55, 0x21, 0xf9, 0x34, 0x98
  24629. },
  24630. { /* Hello 2 */
  24631. 0x03, 0xb4, 0xfb, 0xcc, 0x28, 0x2c, 0xc1, 0x70,
  24632. 0x42, 0x73, 0x57, 0xac, 0xdb, 0x47, 0x71, 0xf6,
  24633. 0x2e, 0x11, 0x8a, 0x5b, 0x47, 0x2f, 0x02, 0x54,
  24634. 0x95, 0x34, 0xed, 0x5f, 0x19, 0xc1, 0x75, 0xe0,
  24635. 0x76, 0xad, 0xb0, 0x90, 0x57, 0xcd, 0xfd, 0xd7,
  24636. 0x58, 0x1f, 0x0d, 0x6b, 0x9e, 0x51, 0x3c, 0x08
  24637. },
  24638. { /* Finished 1 */
  24639. 0x2b, 0x50, 0xd9, 0xa7, 0x43, 0x24, 0xda, 0x2c,
  24640. 0x7a, 0xaa, 0x0e, 0x37, 0xd7, 0x6b, 0x2c, 0xab,
  24641. 0x8e, 0xb2, 0xfe, 0x31, 0x1b, 0xa8, 0x12, 0x59,
  24642. 0x5b, 0x7b, 0xdc, 0x3e, 0xa7, 0x86, 0xa5, 0x48,
  24643. 0xe4, 0x46, 0x2b, 0x4c, 0xc1, 0x66, 0x4b, 0xf3,
  24644. 0x2a, 0x99, 0x93, 0x08, 0xbc, 0x3d, 0x08, 0x76
  24645. },
  24646. { /* Finished 2 */
  24647. 0x7c, 0x34, 0xc8, 0x56, 0x17, 0xf1, 0x62, 0x1c,
  24648. 0x9f, 0x0b, 0xeb, 0xfd, 0x69, 0x72, 0x51, 0xc5,
  24649. 0xfa, 0x74, 0x87, 0xc9, 0xbd, 0x50, 0xe9, 0x48,
  24650. 0xa7, 0x3c, 0x94, 0x3e, 0x06, 0x7d, 0xe8, 0x8e,
  24651. 0xc1, 0xd1, 0x08, 0x1f, 0x5d, 0x48, 0x8a, 0x25,
  24652. 0xfc, 0xea, 0xe7, 0xd9, 0xd4, 0xd0, 0xf9, 0xad
  24653. },
  24654. {
  24655. 0x4b, 0x0b, 0xed, 0xb9, 0xc8, 0xb8, 0xa8, 0x1e, 0xb0, 0x81, 0x76, 0xd5,
  24656. 0x33, 0x22, 0x71, 0x33, 0x3a, 0x85, 0x19, 0x67, 0x7e, 0x91, 0x37, 0xf2,
  24657. 0xa6, 0x11, 0x22, 0xdf, 0x41, 0x04, 0x3d, 0xa9, 0x13, 0xb9, 0xb2, 0xb1,
  24658. 0xbb, 0xd8, 0xef, 0x23, 0x7c, 0xc2, 0xab, 0x70, 0x1b, 0x51, 0x9f, 0xc9
  24659. },
  24660. {
  24661. 0xeb, 0x96, 0x10, 0x8c, 0x7d, 0x92, 0xea, 0x80, 0x86, 0xb2, 0xf8, 0x27,
  24662. 0xf2, 0x9a, 0x09, 0xc1, 0x7c, 0x09, 0x43, 0xbc, 0xfe, 0xc8, 0x75, 0xe0,
  24663. 0x97, 0xe7, 0x6d, 0xd5, 0xb2, 0x3c, 0xed, 0x12, 0xb7, 0x74, 0x0e, 0xe3,
  24664. 0xb6, 0xe0, 0xba, 0xe1, 0x8d, 0x89, 0xcf, 0x4f, 0x57, 0xf6, 0x6d, 0x90
  24665. },
  24666. {
  24667. 0x22, 0xb0, 0x39, 0x34, 0xb6, 0x6c, 0x2d, 0x7a, 0x97, 0x1c, 0x5d, 0xcc,
  24668. 0x78, 0x84, 0x71, 0xbb, 0xc6, 0x7b, 0xb6, 0xbc, 0xcc, 0x0b, 0xf8, 0xac,
  24669. 0x8e, 0xd7, 0x20, 0xbd, 0xbe, 0x32, 0xf0, 0xd6, 0xe9, 0x69, 0x13, 0xf2,
  24670. 0x9a, 0xce, 0xfe, 0x86, 0xd3, 0xee, 0xba, 0x69, 0x51, 0xb6, 0x77, 0x56
  24671. },
  24672. {
  24673. 0x16, 0xfd, 0xda, 0xf3, 0x5e, 0xb9, 0xa6, 0x17, 0x24, 0xb2, 0x16, 0x9f,
  24674. 0xb6, 0x59, 0x13, 0x0f, 0x25, 0x5a, 0xf1, 0x5b, 0x5f, 0xe4, 0x54, 0x2a,
  24675. 0xa7, 0xbf, 0x29, 0xaf, 0x5a, 0x77, 0xf4, 0x4f, 0x25, 0xba, 0x94, 0xad,
  24676. 0x6b, 0x91, 0x3b, 0xe7, 0xd5, 0x73, 0x0d, 0xff, 0xaa, 0xe3, 0x72, 0x2c
  24677. },
  24678. {
  24679. 0x22, 0xb4, 0x94, 0xc0, 0x53, 0xd7, 0x82, 0x06, 0x38, 0x9d, 0x4a, 0xa0,
  24680. 0x3f, 0xf1, 0x5f, 0x6e, 0x23, 0x8d, 0x09, 0x62, 0xbf, 0x6f, 0x7c, 0x84,
  24681. 0xc6, 0x3e, 0x15, 0xad, 0x18, 0x37, 0x76, 0x29, 0xc7, 0xd6, 0x68, 0x0c,
  24682. 0x1e, 0xc6, 0x93, 0x31, 0xef, 0x85, 0x69, 0x30, 0x68, 0xf0, 0x1e, 0x37
  24683. },
  24684. {
  24685. 0x6d, 0x4d, 0x20, 0xaf, 0x47, 0xe8, 0x1b, 0xfa, 0xd0, 0xb6, 0xc8, 0x97,
  24686. 0xd1, 0x03, 0xfc, 0x9d, 0x59, 0xa0, 0x68, 0x9d, 0xe9, 0x17, 0x8b, 0xce,
  24687. 0x48, 0x2c, 0x77, 0x8a, 0x22, 0x4b, 0x5c, 0x54, 0x22, 0xa1, 0x15, 0x12,
  24688. 0xe1, 0x07, 0x8e, 0x15, 0xd8, 0x7b, 0x16, 0x65, 0x99, 0x6b, 0xcb, 0x71
  24689. },
  24690. {
  24691. 0x79, 0x64, 0x79, 0xdd, 0x75, 0x5c, 0x6f, 0x98, 0xac, 0x03, 0xe0, 0xcd,
  24692. 0x92, 0xba, 0x0e, 0x2d, 0xb4, 0xd1, 0x8b, 0x97, 0xd0, 0x85, 0xbb, 0x2e,
  24693. 0x4f, 0x26, 0x93, 0xf5, 0x1d, 0xf3, 0xd2, 0x43, 0x4f, 0xd2, 0x47, 0xaa,
  24694. 0x91, 0x1e, 0xf3, 0x67, 0x10, 0x18, 0x2c, 0xb9, 0x01, 0xba, 0x10, 0x9f
  24695. },
  24696. {
  24697. 0x79, 0xb6, 0x9c, 0xbe, 0xf1, 0x6a, 0xb0, 0x92, 0xa0, 0x29, 0x52, 0x61,
  24698. 0xf1, 0xcd, 0x3a, 0x67, 0xe1, 0x6b, 0xb8, 0x9d, 0x0d, 0x95, 0xb6, 0x03,
  24699. 0x80, 0x1f, 0xd5, 0x75, 0xb6, 0x1d, 0x79, 0x02, 0x93, 0x43, 0x77, 0xa7,
  24700. 0x9d, 0x2f, 0xc3, 0x84, 0xc6, 0x83, 0x76, 0x16, 0x06, 0x98, 0x7b, 0x79
  24701. }
  24702. },
  24703. #endif /* WOLFSSL_SHA384 */
  24704. };
  24705. static const char protocolLabel[] = "tls13 ";
  24706. static const char ceTrafficLabel[] = "c e traffic";
  24707. static const char eExpMasterLabel[] = "e exp master";
  24708. static const char cHsTrafficLabel[] = "c hs traffic";
  24709. static const char sHsTrafficLabel[] = "s hs traffic";
  24710. static const char cAppTrafficLabel[] = "c ap traffic";
  24711. static const char sAppTrafficLabel[] = "s ap traffic";
  24712. static const char expMasterLabel[] = "exp master";
  24713. static const char resMasterLabel[] = "res master";
  24714. static const char derivedLabel[] = "derived";
  24715. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void)
  24716. {
  24717. wc_test_ret_t ret = 0;
  24718. word32 i;
  24719. word32 tc = sizeof(tls13KdfTestVectors)/sizeof(Tls13KdfTestVector);
  24720. const Tls13KdfTestVector* tv = NULL;
  24721. WOLFSSL_ENTER("tls13_kdf_test");
  24722. for (i = 0, tv = tls13KdfTestVectors; i < tc; i++, tv++) {
  24723. byte output[WC_MAX_DIGEST_SIZE];
  24724. byte secret[WC_MAX_DIGEST_SIZE];
  24725. byte salt[WC_MAX_DIGEST_SIZE];
  24726. byte zeroes[WC_MAX_DIGEST_SIZE];
  24727. byte hashZero[WC_MAX_DIGEST_SIZE];
  24728. int hashAlgSz;
  24729. XMEMSET(zeroes, 0, sizeof zeroes);
  24730. hashAlgSz = wc_HashGetDigestSize(tv->hashAlg);
  24731. if (hashAlgSz == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) break;
  24732. ret = wc_Hash(tv->hashAlg, NULL, 0, hashZero, (word32)hashAlgSz);
  24733. if (ret != 0) break;
  24734. ret = wc_Tls13_HKDF_Extract(secret, NULL, 0,
  24735. (tv->pskSz == 0) ? zeroes : (byte*)tv->psk,
  24736. tv->pskSz, (int)tv->hashAlg);
  24737. if (ret != 0) break;
  24738. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24739. secret, (word32)hashAlgSz,
  24740. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24741. (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel),
  24742. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24743. if (ret != 0) break;
  24744. ret = XMEMCMP(tv->clientEarlyTrafficSecret, output,
  24745. (unsigned long)hashAlgSz);
  24746. if (ret != 0) break;
  24747. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24748. secret, (word32)hashAlgSz,
  24749. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24750. (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel),
  24751. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24752. if (ret != 0) break;
  24753. ret = XMEMCMP(tv->earlyExporterMasterSecret, output,
  24754. (unsigned long)hashAlgSz);
  24755. if (ret != 0) break;
  24756. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24757. secret, (word32)hashAlgSz,
  24758. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24759. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24760. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24761. if (ret != 0) break;
  24762. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24763. (tv->dheSz == 0) ? zeroes : (byte*)tv->dhe,
  24764. tv->dheSz, (int)tv->hashAlg);
  24765. if (ret != 0) break;
  24766. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24767. secret, (word32)hashAlgSz,
  24768. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24769. (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel),
  24770. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24771. if (ret != 0) break;
  24772. ret = XMEMCMP(tv->clientHandshakeTrafficSecret,
  24773. output, (unsigned long)hashAlgSz);
  24774. if (ret != 0) break;
  24775. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24776. secret, (word32)hashAlgSz,
  24777. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24778. (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel),
  24779. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24780. if (ret != 0) break;
  24781. ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output,
  24782. (unsigned long)hashAlgSz);
  24783. if (ret != 0) break;
  24784. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24785. secret, (word32)hashAlgSz,
  24786. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24787. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24788. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24789. if (ret != 0) break;
  24790. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24791. zeroes, (word32)(word32)hashAlgSz, (int)tv->hashAlg);
  24792. if (ret != 0) break;
  24793. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24794. secret, (word32)hashAlgSz,
  24795. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24796. (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel),
  24797. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24798. if (ret != 0) break;
  24799. ret = XMEMCMP(tv->clientApplicationTrafficSecret, output,
  24800. (unsigned long)hashAlgSz);
  24801. if (ret != 0) break;
  24802. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24803. secret, (word32)hashAlgSz,
  24804. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24805. (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel),
  24806. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24807. if (ret != 0) break;
  24808. ret = XMEMCMP(tv->serverApplicationTrafficSecret, output,
  24809. (unsigned long)hashAlgSz);
  24810. if (ret != 0) break;
  24811. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24812. secret, (word32)hashAlgSz,
  24813. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24814. (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel),
  24815. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24816. if (ret != 0) break;
  24817. ret = XMEMCMP(tv->exporterMasterSecret, output, (unsigned long)hashAlgSz);
  24818. if (ret != 0) break;
  24819. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24820. secret, (word32)hashAlgSz,
  24821. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24822. (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel),
  24823. tv->hashFinished2, (word32)hashAlgSz, (int)tv->hashAlg);
  24824. if (ret != 0) break;
  24825. ret = XMEMCMP(tv->resumptionMasterSecret, output,
  24826. (unsigned long)hashAlgSz);
  24827. if (ret != 0) break;
  24828. }
  24829. return ret;
  24830. }
  24831. #endif /* WOLFSSL_TLS13 */
  24832. static const int fiducial2 = WC_TEST_RET_LN; /* source code reference point --
  24833. * see print_fiducials() below.
  24834. */
  24835. #if defined(HAVE_ECC) && defined(HAVE_X963_KDF)
  24836. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void)
  24837. {
  24838. wc_test_ret_t ret;
  24839. byte kek[128];
  24840. #ifndef NO_SHA
  24841. /* SHA-1, COUNT = 0
  24842. * shared secret length: 192
  24843. * SharedInfo length: 0
  24844. * key data length: 128
  24845. */
  24846. WOLFSSL_SMALL_STACK_STATIC const byte Z[] = {
  24847. 0x1c, 0x7d, 0x7b, 0x5f, 0x05, 0x97, 0xb0, 0x3d,
  24848. 0x06, 0xa0, 0x18, 0x46, 0x6e, 0xd1, 0xa9, 0x3e,
  24849. 0x30, 0xed, 0x4b, 0x04, 0xdc, 0x64, 0xcc, 0xdd
  24850. };
  24851. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  24852. 0xbf, 0x71, 0xdf, 0xfd, 0x8f, 0x4d, 0x99, 0x22,
  24853. 0x39, 0x36, 0xbe, 0xb4, 0x6f, 0xee, 0x8c, 0xcc
  24854. };
  24855. #endif
  24856. #ifndef NO_SHA256
  24857. /* SHA-256, COUNT = 3
  24858. * shared secret length: 192
  24859. * SharedInfo length: 0
  24860. * key data length: 128
  24861. */
  24862. WOLFSSL_SMALL_STACK_STATIC const byte Z2[] = {
  24863. 0xd3, 0x8b, 0xdb, 0xe5, 0xc4, 0xfc, 0x16, 0x4c,
  24864. 0xdd, 0x96, 0x7f, 0x63, 0xc0, 0x4f, 0xe0, 0x7b,
  24865. 0x60, 0xcd, 0xe8, 0x81, 0xc2, 0x46, 0x43, 0x8c
  24866. };
  24867. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  24868. 0x5e, 0x67, 0x4d, 0xb9, 0x71, 0xba, 0xc2, 0x0a,
  24869. 0x80, 0xba, 0xd0, 0xd4, 0x51, 0x4d, 0xc4, 0x84
  24870. };
  24871. #endif
  24872. #ifdef WOLFSSL_SHA512
  24873. /* SHA-512, COUNT = 0
  24874. * shared secret length: 192
  24875. * SharedInfo length: 0
  24876. * key data length: 128
  24877. */
  24878. WOLFSSL_SMALL_STACK_STATIC const byte Z3[] = {
  24879. 0x87, 0xfc, 0x0d, 0x8c, 0x44, 0x77, 0x48, 0x5b,
  24880. 0xb5, 0x74, 0xf5, 0xfc, 0xea, 0x26, 0x4b, 0x30,
  24881. 0x88, 0x5d, 0xc8, 0xd9, 0x0a, 0xd8, 0x27, 0x82
  24882. };
  24883. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  24884. 0x94, 0x76, 0x65, 0xfb, 0xb9, 0x15, 0x21, 0x53,
  24885. 0xef, 0x46, 0x02, 0x38, 0x50, 0x6a, 0x02, 0x45
  24886. };
  24887. /* SHA-512, COUNT = 0
  24888. * shared secret length: 521
  24889. * SharedInfo length: 128
  24890. * key data length: 1024
  24891. */
  24892. WOLFSSL_SMALL_STACK_STATIC const byte Z4[] = {
  24893. 0x00, 0xaa, 0x5b, 0xb7, 0x9b, 0x33, 0xe3, 0x89,
  24894. 0xfa, 0x58, 0xce, 0xad, 0xc0, 0x47, 0x19, 0x7f,
  24895. 0x14, 0xe7, 0x37, 0x12, 0xf4, 0x52, 0xca, 0xa9,
  24896. 0xfc, 0x4c, 0x9a, 0xdb, 0x36, 0x93, 0x48, 0xb8,
  24897. 0x15, 0x07, 0x39, 0x2f, 0x1a, 0x86, 0xdd, 0xfd,
  24898. 0xb7, 0xc4, 0xff, 0x82, 0x31, 0xc4, 0xbd, 0x0f,
  24899. 0x44, 0xe4, 0x4a, 0x1b, 0x55, 0xb1, 0x40, 0x47,
  24900. 0x47, 0xa9, 0xe2, 0xe7, 0x53, 0xf5, 0x5e, 0xf0,
  24901. 0x5a, 0x2d
  24902. };
  24903. WOLFSSL_SMALL_STACK_STATIC const byte info4[] = {
  24904. 0xe3, 0xb5, 0xb4, 0xc1, 0xb0, 0xd5, 0xcf, 0x1d,
  24905. 0x2b, 0x3a, 0x2f, 0x99, 0x37, 0x89, 0x5d, 0x31
  24906. };
  24907. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  24908. 0x44, 0x63, 0xf8, 0x69, 0xf3, 0xcc, 0x18, 0x76,
  24909. 0x9b, 0x52, 0x26, 0x4b, 0x01, 0x12, 0xb5, 0x85,
  24910. 0x8f, 0x7a, 0xd3, 0x2a, 0x5a, 0x2d, 0x96, 0xd8,
  24911. 0xcf, 0xfa, 0xbf, 0x7f, 0xa7, 0x33, 0x63, 0x3d,
  24912. 0x6e, 0x4d, 0xd2, 0xa5, 0x99, 0xac, 0xce, 0xb3,
  24913. 0xea, 0x54, 0xa6, 0x21, 0x7c, 0xe0, 0xb5, 0x0e,
  24914. 0xef, 0x4f, 0x6b, 0x40, 0xa5, 0xc3, 0x02, 0x50,
  24915. 0xa5, 0xa8, 0xee, 0xee, 0x20, 0x80, 0x02, 0x26,
  24916. 0x70, 0x89, 0xdb, 0xf3, 0x51, 0xf3, 0xf5, 0x02,
  24917. 0x2a, 0xa9, 0x63, 0x8b, 0xf1, 0xee, 0x41, 0x9d,
  24918. 0xea, 0x9c, 0x4f, 0xf7, 0x45, 0xa2, 0x5a, 0xc2,
  24919. 0x7b, 0xda, 0x33, 0xca, 0x08, 0xbd, 0x56, 0xdd,
  24920. 0x1a, 0x59, 0xb4, 0x10, 0x6c, 0xf2, 0xdb, 0xbc,
  24921. 0x0a, 0xb2, 0xaa, 0x8e, 0x2e, 0xfa, 0x7b, 0x17,
  24922. 0x90, 0x2d, 0x34, 0x27, 0x69, 0x51, 0xce, 0xcc,
  24923. 0xab, 0x87, 0xf9, 0x66, 0x1c, 0x3e, 0x88, 0x16
  24924. };
  24925. #endif
  24926. WOLFSSL_ENTER("x963kdf_test");
  24927. #ifndef NO_SHA
  24928. ret = wc_X963_KDF(WC_HASH_TYPE_SHA, Z, sizeof(Z), NULL, 0,
  24929. kek, sizeof(verify));
  24930. if (ret != 0)
  24931. return WC_TEST_RET_ENC_EC(ret);
  24932. if (XMEMCMP(verify, kek, sizeof(verify)) != 0)
  24933. return WC_TEST_RET_ENC_NC;
  24934. #endif
  24935. #ifndef NO_SHA256
  24936. ret = wc_X963_KDF(WC_HASH_TYPE_SHA256, Z2, sizeof(Z2), NULL, 0,
  24937. kek, sizeof(verify2));
  24938. if (ret != 0)
  24939. return WC_TEST_RET_ENC_EC(ret);
  24940. if (XMEMCMP(verify2, kek, sizeof(verify2)) != 0)
  24941. return WC_TEST_RET_ENC_NC;
  24942. #endif
  24943. #ifdef WOLFSSL_SHA512
  24944. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z3, sizeof(Z3), NULL, 0,
  24945. kek, sizeof(verify3));
  24946. if (ret != 0)
  24947. return WC_TEST_RET_ENC_EC(ret);
  24948. if (XMEMCMP(verify3, kek, sizeof(verify3)) != 0)
  24949. return WC_TEST_RET_ENC_NC;
  24950. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z4, sizeof(Z4), info4,
  24951. sizeof(info4), kek, sizeof(verify4));
  24952. if (ret != 0)
  24953. return WC_TEST_RET_ENC_EC(ret);
  24954. if (XMEMCMP(verify4, kek, sizeof(verify4)) != 0)
  24955. return WC_TEST_RET_ENC_NC;
  24956. #endif
  24957. return 0;
  24958. }
  24959. #endif /* HAVE_X963_KDF */
  24960. #if defined(HAVE_HPKE) && \
  24961. (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) && \
  24962. defined(HAVE_AESGCM)
  24963. static wc_test_ret_t hpke_test_single(Hpke* hpke)
  24964. {
  24965. wc_test_ret_t ret = 0;
  24966. int rngRet = 0;
  24967. WC_RNG rng[1];
  24968. const char* start_text = "this is a test";
  24969. const char* info_text = "info";
  24970. const char* aad_text = "aad";
  24971. byte ciphertext[MAX_HPKE_LABEL_SZ];
  24972. byte plaintext[MAX_HPKE_LABEL_SZ];
  24973. void* receiverKey = NULL;
  24974. void* ephemeralKey = NULL;
  24975. #ifdef WOLFSSL_SMALL_STACK
  24976. byte *pubKey = NULL; /* public key */
  24977. word16 pubKeySz = (word16)HPKE_Npk_MAX;
  24978. #else
  24979. byte pubKey[HPKE_Npk_MAX]; /* public key */
  24980. word16 pubKeySz = (word16)sizeof(pubKey);
  24981. #endif
  24982. rngRet = ret = wc_InitRng(rng);
  24983. if (ret != 0)
  24984. return WC_TEST_RET_ENC_EC(ret);
  24985. #ifdef WOLFSSL_SMALL_STACK
  24986. if (ret == 0) {
  24987. pubKey = (byte *)XMALLOC(pubKeySz, HEAP_HINT,
  24988. DYNAMIC_TYPE_TMP_BUFFER);
  24989. if (pubKey == NULL)
  24990. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  24991. }
  24992. #endif
  24993. /* generate the keys */
  24994. if (ret == 0) {
  24995. ret = wc_HpkeGenerateKeyPair(hpke, &ephemeralKey, rng);
  24996. if (ret != 0)
  24997. ret = WC_TEST_RET_ENC_EC(ret);
  24998. }
  24999. if (ret == 0) {
  25000. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, rng);
  25001. if (ret != 0)
  25002. ret = WC_TEST_RET_ENC_EC(ret);
  25003. }
  25004. /* seal */
  25005. if (ret == 0) {
  25006. ret = wc_HpkeSealBase(hpke, ephemeralKey, receiverKey,
  25007. (byte*)info_text, (word32)XSTRLEN(info_text),
  25008. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25009. (byte*)start_text, (word32)XSTRLEN(start_text),
  25010. ciphertext);
  25011. if (ret != 0)
  25012. ret = WC_TEST_RET_ENC_EC(ret);
  25013. }
  25014. /* export ephemeral key */
  25015. if (ret == 0) {
  25016. ret = wc_HpkeSerializePublicKey(hpke, ephemeralKey, pubKey, &pubKeySz);
  25017. if (ret != 0)
  25018. ret = WC_TEST_RET_ENC_EC(ret);
  25019. }
  25020. /* open with exported ephemeral key */
  25021. if (ret == 0) {
  25022. ret = wc_HpkeOpenBase(hpke, receiverKey, pubKey, pubKeySz,
  25023. (byte*)info_text, (word32)XSTRLEN(info_text),
  25024. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25025. ciphertext, (word32)XSTRLEN(start_text),
  25026. plaintext);
  25027. if (ret != 0)
  25028. ret = WC_TEST_RET_ENC_EC(ret);
  25029. }
  25030. if (ret == 0) {
  25031. ret = XMEMCMP(plaintext, start_text, XSTRLEN(start_text));
  25032. if (ret != 0)
  25033. ret = WC_TEST_RET_ENC_NC;
  25034. }
  25035. /* Negative test case with NULL argument */
  25036. if (ret == 0) {
  25037. ret = wc_HpkeGenerateKeyPair(NULL, &receiverKey, rng);
  25038. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25039. ret = WC_TEST_RET_ENC_EC(ret);
  25040. else
  25041. ret = 0;
  25042. }
  25043. if (ret == 0) {
  25044. ret = wc_HpkeGenerateKeyPair(hpke, NULL, rng);
  25045. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25046. ret = WC_TEST_RET_ENC_EC(ret);
  25047. else
  25048. ret = 0;
  25049. }
  25050. if (ret == 0) {
  25051. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, NULL);
  25052. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25053. ret = WC_TEST_RET_ENC_EC(ret);
  25054. else
  25055. ret = 0;
  25056. }
  25057. if (ephemeralKey != NULL)
  25058. wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap);
  25059. if (receiverKey != NULL)
  25060. wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap);
  25061. #ifdef WOLFSSL_SMALL_STACK
  25062. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25063. #endif
  25064. if (rngRet == 0)
  25065. wc_FreeRng(rng);
  25066. return ret;
  25067. }
  25068. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void)
  25069. {
  25070. wc_test_ret_t ret = 0;
  25071. Hpke hpke[1];
  25072. WOLFSSL_ENTER("hpke_test");
  25073. #if defined(HAVE_ECC)
  25074. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
  25075. /* p256 */
  25076. ret = wc_HpkeInit(hpke, DHKEM_P256_HKDF_SHA256, HKDF_SHA256,
  25077. HPKE_AES_128_GCM, NULL);
  25078. if (ret != 0)
  25079. return WC_TEST_RET_ENC_EC(ret);
  25080. ret = hpke_test_single(hpke);
  25081. if (ret != 0)
  25082. return ret;
  25083. #endif
  25084. #if defined(WOLFSSL_SHA384) && \
  25085. (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  25086. /* p384 */
  25087. ret = wc_HpkeInit(hpke, DHKEM_P384_HKDF_SHA384, HKDF_SHA384,
  25088. HPKE_AES_128_GCM, NULL);
  25089. if (ret != 0)
  25090. return WC_TEST_RET_ENC_EC(ret);
  25091. ret = hpke_test_single(hpke);
  25092. if (ret != 0)
  25093. return ret;
  25094. #endif
  25095. #if (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) && \
  25096. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25097. /* p521 */
  25098. ret = wc_HpkeInit(hpke, DHKEM_P521_HKDF_SHA512, HKDF_SHA512,
  25099. HPKE_AES_128_GCM, NULL);
  25100. if (ret != 0)
  25101. return WC_TEST_RET_ENC_EC(ret);
  25102. ret = hpke_test_single(hpke);
  25103. if (ret != 0)
  25104. return ret;
  25105. #endif
  25106. #endif
  25107. #if defined(HAVE_CURVE25519)
  25108. /* test with curve25519 and aes256 */
  25109. ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256,
  25110. HPKE_AES_256_GCM, NULL);
  25111. if (ret != 0)
  25112. return WC_TEST_RET_ENC_EC(ret);
  25113. ret = hpke_test_single(hpke);
  25114. if (ret != 0)
  25115. return ret;
  25116. #endif
  25117. #if defined(HAVE_CURVE448) && \
  25118. (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512))
  25119. /* test with curve448 and aes256 */
  25120. ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512,
  25121. HPKE_AES_256_GCM, NULL);
  25122. /* HPKE does not support X448 yet, so expect failure */
  25123. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25124. return WC_TEST_RET_ENC_EC(ret);
  25125. ret = hpke_test_single(hpke);
  25126. /* HPKE does not support X448 yet, so expect failure */
  25127. if (WC_TEST_RET_DEC_EC(ret) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25128. return ret;
  25129. ret = 0; /* reset error code */
  25130. #endif
  25131. /* TODO: HPKE chacha20 is not implemented */
  25132. return ret;
  25133. }
  25134. #endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */
  25135. #if defined(WC_SRTP_KDF)
  25136. typedef struct Srtp_Kdf_Tv {
  25137. const unsigned char* key;
  25138. word32 keySz;
  25139. const unsigned char* salt;
  25140. word32 saltSz;
  25141. int kdfIdx;
  25142. const unsigned char* index;
  25143. const unsigned char* ke;
  25144. const unsigned char* ka;
  25145. const unsigned char* ks;
  25146. const unsigned char* index_c;
  25147. const unsigned char* ke_c;
  25148. const unsigned char* ka_c;
  25149. const unsigned char* ks_c;
  25150. word32 keSz;
  25151. word32 kaSz;
  25152. word32 ksSz;
  25153. } Srtp_Kdf_Tv;
  25154. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
  25155. {
  25156. wc_test_ret_t ret = 0;
  25157. /* 128-bit key, kdrIdx = -1 */
  25158. WOLFSSL_SMALL_STACK_STATIC const byte key_0[] = {
  25159. 0xc4, 0x80, 0x9f, 0x6d, 0x36, 0x98, 0x88, 0x72,
  25160. 0x8e, 0x26, 0xad, 0xb5, 0x32, 0x12, 0x98, 0x90
  25161. };
  25162. WOLFSSL_SMALL_STACK_STATIC const byte salt_0[] = {
  25163. 0x0e, 0x23, 0x00, 0x6c, 0x6c, 0x04, 0x4f, 0x56,
  25164. 0x62, 0x40, 0x0e, 0x9d, 0x1b, 0xd6
  25165. };
  25166. WOLFSSL_SMALL_STACK_STATIC const byte index_0[] = {
  25167. 0x48, 0x71, 0x65, 0x64, 0x9c, 0xca
  25168. };
  25169. WOLFSSL_SMALL_STACK_STATIC const byte ke_0[] = {
  25170. 0xdc, 0x38, 0x21, 0x92, 0xab, 0x65, 0x10, 0x8a,
  25171. 0x86, 0xb2, 0x59, 0xb6, 0x1b, 0x3a, 0xf4, 0x6f
  25172. };
  25173. WOLFSSL_SMALL_STACK_STATIC const byte ka_0[] = {
  25174. 0xb8, 0x39, 0x37, 0xfb, 0x32, 0x17, 0x92, 0xee,
  25175. 0x87, 0xb7, 0x88, 0x19, 0x3b, 0xe5, 0xa4, 0xe3,
  25176. 0xbd, 0x32, 0x6e, 0xe4
  25177. };
  25178. WOLFSSL_SMALL_STACK_STATIC const byte ks_0[] = {
  25179. 0xf1, 0xc0, 0x35, 0xc0, 0x0b, 0x5a, 0x54, 0xa6,
  25180. 0x16, 0x92, 0xc0, 0x16, 0x27, 0x6c
  25181. };
  25182. WOLFSSL_SMALL_STACK_STATIC const byte index_c_0[] = {
  25183. 0x56, 0xf3, 0xf1, 0x97
  25184. };
  25185. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_0[] = {
  25186. 0xab, 0x5b, 0xe0, 0xb4, 0x56, 0x23, 0x5d, 0xcf,
  25187. 0x77, 0xd5, 0x08, 0x69, 0x29, 0xba, 0xfb, 0x38
  25188. };
  25189. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_0[] = {
  25190. 0xc5, 0x2f, 0xde, 0x0b, 0x80, 0xb0, 0xf0, 0xba,
  25191. 0xd8, 0xd1, 0x56, 0x45, 0xcb, 0x86, 0xe7, 0xc7,
  25192. 0xc3, 0xd8, 0x77, 0x0e
  25193. };
  25194. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_0[] = {
  25195. 0xde, 0xb5, 0xf8, 0x5f, 0x81, 0x33, 0x6a, 0x96,
  25196. 0x5e, 0xd3, 0x2b, 0xb7, 0xed, 0xe8
  25197. };
  25198. /* 192-bit key, kdrIdx = 0 */
  25199. WOLFSSL_SMALL_STACK_STATIC const byte key_1[] = {
  25200. 0xbb, 0x04, 0x5b, 0x1f, 0x53, 0xc6, 0x93, 0x2c,
  25201. 0x2b, 0xa6, 0x88, 0xf5, 0xe3, 0xf2, 0x24, 0x70,
  25202. 0xe1, 0x7d, 0x7d, 0xec, 0x8a, 0x93, 0x4d, 0xf2
  25203. };
  25204. WOLFSSL_SMALL_STACK_STATIC const byte salt_1[] = {
  25205. 0xe7, 0x22, 0xab, 0x92, 0xfc, 0x7c, 0x89, 0xb6,
  25206. 0x53, 0x8a, 0xf9, 0x3c, 0xb9, 0x52
  25207. };
  25208. WOLFSSL_SMALL_STACK_STATIC const byte index_1[] = {
  25209. 0xd7, 0x87, 0x8f, 0x33, 0xb1, 0x76
  25210. };
  25211. WOLFSSL_SMALL_STACK_STATIC const byte ke_1[] = {
  25212. 0x2c, 0xc8, 0x3e, 0x54, 0xb2, 0x33, 0x89, 0xb3,
  25213. 0x71, 0x65, 0x0f, 0x51, 0x61, 0x65, 0xe4, 0x93,
  25214. 0x07, 0x4e, 0xb3, 0x47, 0xba, 0x2d, 0x60, 0x60
  25215. };
  25216. WOLFSSL_SMALL_STACK_STATIC const byte ka_1[] = {
  25217. 0x2e, 0x80, 0xe4, 0x82, 0x55, 0xa2, 0xbe, 0x6d,
  25218. 0xe0, 0x46, 0xcc, 0xc1, 0x75, 0x78, 0x6e, 0x78,
  25219. 0xd1, 0xd1, 0x47, 0x08
  25220. };
  25221. WOLFSSL_SMALL_STACK_STATIC const byte ks_1[] = {
  25222. 0xe0, 0xc1, 0xe6, 0xaf, 0x1e, 0x8d, 0x8c, 0xfe,
  25223. 0xe5, 0x60, 0x70, 0xb5, 0xe6, 0xea
  25224. };
  25225. WOLFSSL_SMALL_STACK_STATIC const byte index_c_1[] = {
  25226. 0x40, 0xbf, 0xd4, 0xa9
  25227. };
  25228. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_1[] = {
  25229. 0x94, 0x0f, 0x55, 0xce, 0x58, 0xd8, 0x16, 0x65,
  25230. 0xf0, 0xfa, 0x46, 0x40, 0x0c, 0xda, 0xb1, 0x11,
  25231. 0x9e, 0x69, 0xa0, 0x93, 0x4e, 0xd7, 0xf2, 0x84
  25232. };
  25233. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_1[] = {
  25234. 0xf5, 0x41, 0x6f, 0xc2, 0x65, 0xc5, 0xb3, 0xef,
  25235. 0xbb, 0x22, 0xc8, 0xfc, 0x6b, 0x00, 0x14, 0xb2,
  25236. 0xf3, 0x3b, 0x8e, 0x29
  25237. };
  25238. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_1[] = {
  25239. 0x35, 0xb7, 0x42, 0x43, 0xf0, 0x01, 0x01, 0xb4,
  25240. 0x68, 0xa1, 0x28, 0x80, 0x37, 0xf0
  25241. };
  25242. /* 256-bit key, kdrIdx = 1 */
  25243. WOLFSSL_SMALL_STACK_STATIC const byte key_2[] = {
  25244. 0x10, 0x38, 0x0a, 0xcd, 0xd6, 0x47, 0xab, 0xee,
  25245. 0xc0, 0xd4, 0x44, 0xf4, 0x7e, 0x51, 0x36, 0x02,
  25246. 0x79, 0xa8, 0x94, 0x80, 0x35, 0x40, 0xed, 0x50,
  25247. 0xf4, 0x45, 0x30, 0x3d, 0xb5, 0xf0, 0x2b, 0xbb
  25248. };
  25249. WOLFSSL_SMALL_STACK_STATIC const byte salt_2[] = {
  25250. 0xc7, 0x31, 0xf2, 0xc8, 0x40, 0x43, 0xb8, 0x74,
  25251. 0x8a, 0x61, 0x84, 0x7a, 0x25, 0x8a
  25252. };
  25253. WOLFSSL_SMALL_STACK_STATIC const byte index_2[] = {
  25254. 0x82, 0xf1, 0x84, 0x8c, 0xac, 0x42
  25255. };
  25256. WOLFSSL_SMALL_STACK_STATIC const byte ke_2[] = {
  25257. 0xb2, 0x26, 0x60, 0xaf, 0x08, 0x23, 0x14, 0x98,
  25258. 0x91, 0xde, 0x5d, 0x87, 0x95, 0x61, 0xca, 0x8f,
  25259. 0x0e, 0xce, 0xfb, 0x68, 0x4d, 0xd6, 0x28, 0xcb,
  25260. 0x28, 0xe2, 0x27, 0x20, 0x2d, 0xff, 0x64, 0xbb
  25261. };
  25262. WOLFSSL_SMALL_STACK_STATIC const byte ka_2[] = {
  25263. 0x12, 0x6f, 0x52, 0xe8, 0x07, 0x7f, 0x07, 0x84,
  25264. 0xa0, 0x61, 0x96, 0xf8, 0xee, 0x4d, 0x05, 0x57,
  25265. 0x65, 0xc7, 0x50, 0xc1
  25266. };
  25267. WOLFSSL_SMALL_STACK_STATIC const byte ks_2[] = {
  25268. 0x18, 0x5a, 0x59, 0xe5, 0x91, 0x4d, 0xc9, 0x6c,
  25269. 0xfa, 0x5b, 0x36, 0x06, 0x8c, 0x9a
  25270. };
  25271. WOLFSSL_SMALL_STACK_STATIC const byte index_c_2[] = {
  25272. 0x31, 0x2d, 0x58, 0x15
  25273. };
  25274. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_2[] = {
  25275. 0x14, 0xf2, 0xc8, 0x25, 0x02, 0x79, 0x22, 0xa1,
  25276. 0x96, 0xb6, 0xf7, 0x07, 0x76, 0xa6, 0xa3, 0xc4,
  25277. 0x37, 0xdf, 0xa0, 0xf8, 0x78, 0x93, 0x2c, 0xfa,
  25278. 0xea, 0x35, 0xf0, 0xf3, 0x3f, 0x32, 0x6e, 0xfd
  25279. };
  25280. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_2[] = {
  25281. 0x6e, 0x3d, 0x4a, 0x99, 0xea, 0x2f, 0x9d, 0x13,
  25282. 0x4a, 0x1e, 0x71, 0x2e, 0x15, 0xc0, 0xca, 0xb6,
  25283. 0x35, 0x78, 0xdf, 0xa4
  25284. };
  25285. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_2[] = {
  25286. 0xae, 0xe4, 0xec, 0x18, 0x31, 0x70, 0x5d, 0x3f,
  25287. 0xdc, 0x97, 0x89, 0x88, 0xfd, 0xff
  25288. };
  25289. /* 128-bit key, kdrIdx = 8 */
  25290. WOLFSSL_SMALL_STACK_STATIC const byte key_3[] = {
  25291. 0x36, 0xb4, 0xde, 0xcb, 0x2e, 0x51, 0x23, 0x76,
  25292. 0xe0, 0x27, 0x7e, 0x3e, 0xc8, 0xf6, 0x54, 0x04
  25293. };
  25294. WOLFSSL_SMALL_STACK_STATIC const byte salt_3[] = {
  25295. 0x73, 0x26, 0xf4, 0x3f, 0xc0, 0xd9, 0xc6, 0xe3,
  25296. 0x2f, 0x92, 0x7d, 0x46, 0x12, 0x76
  25297. };
  25298. WOLFSSL_SMALL_STACK_STATIC const byte index_3[] = {
  25299. 0x44, 0x73, 0xb2, 0x2d, 0xb2, 0x60
  25300. };
  25301. WOLFSSL_SMALL_STACK_STATIC const byte ke_3[] = {
  25302. 0x79, 0x91, 0x3d, 0x7b, 0x20, 0x5d, 0xea, 0xe2,
  25303. 0xeb, 0x46, 0x89, 0x68, 0x5a, 0x06, 0x73, 0x74
  25304. };
  25305. WOLFSSL_SMALL_STACK_STATIC const byte ka_3[] = {
  25306. 0x2d, 0x2e, 0x97, 0x4e, 0x76, 0x8c, 0x62, 0xa6,
  25307. 0x57, 0x80, 0x13, 0x42, 0x0b, 0x51, 0xa7, 0x66,
  25308. 0xea, 0x31, 0x24, 0xe6
  25309. };
  25310. WOLFSSL_SMALL_STACK_STATIC const byte ks_3[] = {
  25311. 0xcc, 0xd7, 0x31, 0xf6, 0x3b, 0xf3, 0x89, 0x8a,
  25312. 0x5b, 0x7b, 0xb5, 0x8b, 0x4c, 0x3f
  25313. };
  25314. WOLFSSL_SMALL_STACK_STATIC const byte index_c_3[] = {
  25315. 0x4a, 0x7d, 0xaa, 0x85
  25316. };
  25317. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_3[] = {
  25318. 0x34, 0x99, 0x71, 0xfe, 0x12, 0x93, 0xae, 0x8c,
  25319. 0x4a, 0xe9, 0x84, 0xe4, 0x93, 0x53, 0x63, 0x88
  25320. };
  25321. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_3[] = {
  25322. 0xa4, 0x53, 0x5e, 0x0a, 0x9c, 0xf2, 0xce, 0x13,
  25323. 0xef, 0x7a, 0x13, 0xee, 0x0a, 0xef, 0xba, 0x17,
  25324. 0x05, 0x18, 0xe3, 0xed
  25325. };
  25326. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_3[] = {
  25327. 0xe1, 0x29, 0x4f, 0x61, 0x30, 0x3c, 0x4d, 0x46,
  25328. 0x5f, 0x5c, 0x81, 0x3c, 0x38, 0xb6
  25329. };
  25330. /* SRTCP w/ 48-bit idx - KDR 0 (-1) */
  25331. WOLFSSL_SMALL_STACK_STATIC const byte mk48_1[] = {
  25332. 0xFF, 0xB6, 0xCB, 0x09, 0x71, 0x3F, 0x63, 0x4D,
  25333. 0x7F, 0x42, 0xED, 0xA8, 0x12, 0x81, 0x50, 0xE6
  25334. };
  25335. WOLFSSL_SMALL_STACK_STATIC const byte ms48_1[] = {
  25336. 0x1F, 0x04, 0x76, 0xC8, 0x7F, 0x58, 0x23, 0xEF,
  25337. 0xD3, 0x57, 0xB2, 0xBD, 0xF1, 0x32
  25338. };
  25339. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_1[] = {
  25340. 0x00, 0x00, 0x08, 0x56, 0xBC, 0x39
  25341. };
  25342. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_1[] = {
  25343. 0xD2, 0xC3, 0xF3, 0x49, 0x00, 0x1A, 0x18, 0x0F,
  25344. 0xB6, 0x05, 0x5A, 0x5A, 0x67, 0x8E, 0xE5, 0xB2
  25345. };
  25346. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_1[] = {
  25347. 0x8D, 0x54, 0xBE, 0xB5, 0x7B, 0x7F, 0x7A, 0xAB,
  25348. 0xF5, 0x46, 0xCE, 0x5B, 0x45, 0x69, 0x4A, 0x75,
  25349. 0x81, 0x2A, 0xE2, 0xCB
  25350. };
  25351. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_1[] = {
  25352. 0x76, 0x3C, 0x97, 0x6A, 0x45, 0x31, 0xA7, 0x79,
  25353. 0x3C, 0x28, 0x4A, 0xA6, 0x82, 0x03
  25354. };
  25355. /* SRTCP w/ 48-bit idx - KDR 19 */
  25356. WOLFSSL_SMALL_STACK_STATIC const byte mk48_2[] = {
  25357. 0xBD, 0x1D, 0x71, 0x6B, 0xDA, 0x28, 0xE3, 0xFC,
  25358. 0xA5, 0xA0, 0x66, 0x3F, 0x2E, 0x34, 0xA8, 0x58
  25359. };
  25360. WOLFSSL_SMALL_STACK_STATIC const byte ms48_2[] = {
  25361. 0x79, 0x06, 0xE5, 0xAB, 0x5C, 0x2B, 0x1B, 0x69,
  25362. 0xFA, 0xEE, 0xD2, 0x29, 0x57, 0x3C
  25363. };
  25364. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_2[] = {
  25365. 0x00, 0x00, 0x59, 0xD0, 0xC2, 0xE8
  25366. };
  25367. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_2[] = {
  25368. 0xB9, 0xD7, 0xAD, 0xD8, 0x90, 0x94, 0xC2, 0x92,
  25369. 0xA5, 0x04, 0x87, 0xC4, 0x8C, 0xEF, 0xE2, 0xA3
  25370. };
  25371. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_2[] = {
  25372. 0x07, 0xD5, 0xC4, 0xD2, 0x06, 0xFB, 0x63, 0x15,
  25373. 0xC2, 0x9C, 0x7F, 0x55, 0xD1, 0x16, 0x5C, 0xB5,
  25374. 0xB7, 0x44, 0x54, 0xBD
  25375. };
  25376. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_2[] = {
  25377. 0x0C, 0x5E, 0x53, 0xC1, 0xD0, 0x75, 0xAD, 0x65,
  25378. 0xBF, 0x51, 0x74, 0x50, 0x89, 0xD7
  25379. };
  25380. int kdr_48_1 = -1;
  25381. int kdr_48_2 = 19;
  25382. #define SRTP_TV_CNT 4
  25383. Srtp_Kdf_Tv tv[SRTP_TV_CNT] = {
  25384. { key_0, (word32)sizeof(key_0), salt_0, (word32)sizeof(salt_0), -1,
  25385. index_0, ke_0, ka_0, ks_0, index_c_0, ke_c_0, ka_c_0, ks_c_0,
  25386. 16, 20, 14 },
  25387. { key_1, (word32)sizeof(key_1), salt_1, (word32)sizeof(salt_1), 0,
  25388. index_1, ke_1, ka_1, ks_1, index_c_1, ke_c_1, ka_c_1, ks_c_1,
  25389. 24, 20, 14 },
  25390. { key_2, (word32)sizeof(key_2), salt_2, (word32)sizeof(salt_2), 1,
  25391. index_2, ke_2, ka_2, ks_2, index_c_2, ke_c_2, ka_c_2, ks_c_2,
  25392. 32, 20, 14 },
  25393. { key_3, (word32)sizeof(key_3), salt_3, (word32)sizeof(salt_3), 8,
  25394. index_3, ke_3, ka_3, ks_3, index_c_3, ke_c_3, ka_c_3, ks_c_3,
  25395. 16, 20, 14 },
  25396. };
  25397. int i;
  25398. int idx;
  25399. unsigned char keyE[32];
  25400. unsigned char keyA[20];
  25401. unsigned char keyS[14];
  25402. WOLFSSL_ENTER("srtpkdf_test");
  25403. for (i = 0; (ret == 0) && (i < SRTP_TV_CNT); i++) {
  25404. #ifndef WOLFSSL_AES_128
  25405. if (tv[i].keySz == AES_128_KEY_SIZE) {
  25406. continue;
  25407. }
  25408. #endif
  25409. #ifndef WOLFSSL_AES_192
  25410. if (tv[i].keySz == AES_192_KEY_SIZE) {
  25411. continue;
  25412. }
  25413. #endif
  25414. #ifndef WOLFSSL_AES_256
  25415. if (tv[i].keySz == AES_256_KEY_SIZE) {
  25416. continue;
  25417. }
  25418. #endif
  25419. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25420. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25421. keyS, tv[i].ksSz);
  25422. if (ret != 0)
  25423. return WC_TEST_RET_ENC_EC(ret);
  25424. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25425. return WC_TEST_RET_ENC_NC;
  25426. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25427. return WC_TEST_RET_ENC_NC;
  25428. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25429. return WC_TEST_RET_ENC_NC;
  25430. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25431. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_ENCRYPTION,
  25432. keyE, tv[i].keSz);
  25433. if (ret != 0)
  25434. return WC_TEST_RET_ENC_EC(ret);
  25435. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25436. return WC_TEST_RET_ENC_NC;
  25437. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25438. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_MSG_AUTH,
  25439. keyA, tv[i].kaSz);
  25440. if (ret != 0)
  25441. return WC_TEST_RET_ENC_EC(ret);
  25442. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25443. return WC_TEST_RET_ENC_NC;
  25444. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25445. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_SALT, keyS,
  25446. tv[i].ksSz);
  25447. if (ret != 0)
  25448. return WC_TEST_RET_ENC_EC(ret);
  25449. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25450. return WC_TEST_RET_ENC_NC;
  25451. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25452. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25453. keyS, tv[i].ksSz);
  25454. if (ret != 0)
  25455. return WC_TEST_RET_ENC_EC(ret);
  25456. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25457. return WC_TEST_RET_ENC_NC;
  25458. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25459. return WC_TEST_RET_ENC_NC;
  25460. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25461. return WC_TEST_RET_ENC_NC;
  25462. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25463. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c,
  25464. WC_SRTCP_LABEL_ENCRYPTION, keyE, tv[i].keSz);
  25465. if (ret != 0)
  25466. return WC_TEST_RET_ENC_EC(ret);
  25467. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25468. return WC_TEST_RET_ENC_NC;
  25469. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25470. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_MSG_AUTH,
  25471. keyA, tv[i].kaSz);
  25472. if (ret != 0)
  25473. return WC_TEST_RET_ENC_EC(ret);
  25474. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25475. return WC_TEST_RET_ENC_NC;
  25476. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25477. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT,
  25478. keyS, tv[i].ksSz);
  25479. if (ret != 0)
  25480. return WC_TEST_RET_ENC_EC(ret);
  25481. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25482. return WC_TEST_RET_ENC_NC;
  25483. }
  25484. #ifdef WOLFSSL_AES_128
  25485. i = 0;
  25486. #elif defined(WOLFSSL_AES_192)
  25487. i = 1;
  25488. #else
  25489. i = 2;
  25490. #endif
  25491. ret = wc_SRTP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25492. tv[i].kdfIdx, tv[i].index, 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_SRTCP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25497. tv[i].kdfIdx, tv[i].index_c, 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_SRTP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25502. tv[i].kdfIdx, tv[i].index, 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_SRTCP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25507. tv[i].kdfIdx, tv[i].index_c, 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_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25512. tv[i].kdfIdx, tv[i].index, 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_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25517. tv[i].kdfIdx, tv[i].index_c, 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_SRTP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25522. tv[i].kdfIdx, tv[i].index, 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_SRTCP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25527. tv[i].kdfIdx, tv[i].index_c, 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_SRTP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25532. tv[i].kdfIdx, tv[i].index, 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_SRTCP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25537. tv[i].kdfIdx, tv[i].index_c, 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_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25542. 25, tv[i].index, 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_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25547. 25, tv[i].index_c, 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_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25552. -2, tv[i].index, 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_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25557. -2, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25558. keyS, tv[i].ksSz);
  25559. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25560. return WC_TEST_RET_ENC_EC(ret);
  25561. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25562. tv[i].kdfIdx, tv[i].index, 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_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25567. tv[i].kdfIdx, tv[i].index_c, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25568. keyS, tv[i].ksSz);
  25569. if (ret != 0)
  25570. return WC_TEST_RET_ENC_EC(ret);
  25571. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25572. tv[i].kdfIdx, tv[i].index, 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_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25577. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25578. keyS, tv[i].ksSz);
  25579. if (ret != 0)
  25580. return WC_TEST_RET_ENC_EC(ret);
  25581. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25582. tv[i].kdfIdx, tv[i].index, 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. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25587. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25588. NULL, tv[i].ksSz);
  25589. if (ret != 0)
  25590. return WC_TEST_RET_ENC_EC(ret);
  25591. idx = wc_SRTP_KDF_kdr_to_idx(0);
  25592. if (idx != -1)
  25593. return WC_TEST_RET_ENC_NC;
  25594. for (i = 0; i < 32; i++) {
  25595. word32 kdr = 1U << i;
  25596. /* SRTCP w/ 48-bit IDX, 128-bit key test */
  25597. if (i == 0) {
  25598. ret = wc_SRTCP_KDF_ex(mk48_1, (word32)sizeof(mk48_1),
  25599. ms48_1, (word32)sizeof(ms48_1),
  25600. kdr_48_1, srtcp48idx_1, keyE, tv[i].keSz,
  25601. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25602. WC_SRTCP_48BIT_IDX);
  25603. if (ret != 0)
  25604. return WC_TEST_RET_ENC_EC(ret);
  25605. if (XMEMCMP(keyE, srtcpKe_48_1, tv[i].keSz) != 0)
  25606. return WC_TEST_RET_ENC_NC;
  25607. if (XMEMCMP(keyA, srtcpKa_48_1, tv[i].kaSz) != 0)
  25608. return WC_TEST_RET_ENC_NC;
  25609. if (XMEMCMP(keyS, srtcpKs_48_1, tv[i].ksSz) != 0)
  25610. return WC_TEST_RET_ENC_NC;
  25611. ret = wc_SRTCP_KDF_ex(mk48_2, (word32)sizeof(mk48_2),
  25612. ms48_2, (word32)sizeof(ms48_2),
  25613. kdr_48_2, srtcp48idx_2, keyE, tv[i].keSz,
  25614. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25615. WC_SRTCP_48BIT_IDX);
  25616. if (ret != 0)
  25617. return WC_TEST_RET_ENC_EC(ret);
  25618. if (XMEMCMP(keyE, srtcpKe_48_2, tv[i].keSz) != 0)
  25619. return WC_TEST_RET_ENC_NC;
  25620. if (XMEMCMP(keyA, srtcpKa_48_2, tv[i].kaSz) != 0)
  25621. return WC_TEST_RET_ENC_NC;
  25622. if (XMEMCMP(keyS, srtcpKs_48_2, tv[i].ksSz) != 0)
  25623. return WC_TEST_RET_ENC_NC;
  25624. }
  25625. idx = wc_SRTP_KDF_kdr_to_idx(kdr);
  25626. if (idx != i)
  25627. return WC_TEST_RET_ENC_NC;
  25628. }
  25629. return 0;
  25630. }
  25631. #endif
  25632. #ifdef HAVE_ECC
  25633. /* size to use for ECC key gen tests */
  25634. #ifndef ECC_KEYGEN_SIZE
  25635. #if !defined(NO_ECC256) || defined(WOLFSSL_SM2)
  25636. #define ECC_KEYGEN_SIZE 32
  25637. #elif defined(HAVE_ECC384)
  25638. #define ECC_KEYGEN_SIZE 48
  25639. #elif defined(HAVE_ECC224)
  25640. #define ECC_KEYGEN_SIZE 28
  25641. #elif defined(HAVE_ECC521)
  25642. #define ECC_KEYGEN_SIZE 66
  25643. #else
  25644. #error No ECC keygen size defined for test
  25645. #endif
  25646. #endif
  25647. #ifdef BENCH_EMBEDDED
  25648. #define ECC_SHARED_SIZE 128
  25649. #else
  25650. #define ECC_SHARED_SIZE MAX_ECC_BYTES
  25651. #endif
  25652. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  25653. #define HAVE_ECC_DETERMINISTIC_K
  25654. #define ECC_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  25655. #else
  25656. #define ECC_DIGEST_SIZE MAX_ECC_BYTES
  25657. #endif
  25658. #define ECC_SIG_SIZE ECC_MAX_SIG_SIZE
  25659. #ifdef NO_ECC_SECP
  25660. #define NO_ECC_VECTOR_TEST
  25661. #endif
  25662. #ifndef NO_ECC_VECTOR_TEST
  25663. #if (defined(HAVE_ECC192) || defined(HAVE_ECC224) ||\
  25664. !defined(NO_ECC256) || defined(HAVE_ECC384) ||\
  25665. defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25666. #define HAVE_ECC_VECTOR_TEST
  25667. #endif
  25668. #endif
  25669. #ifdef HAVE_ECC_VECTOR_TEST
  25670. typedef struct eccVector {
  25671. const char* msg; /* SHA-1 Encoded Message */
  25672. const char* Qx;
  25673. const char* Qy;
  25674. const char* d; /* Private Key */
  25675. const char* R;
  25676. const char* S;
  25677. const char* curveName;
  25678. word32 msgLen;
  25679. word32 keySize;
  25680. const byte* r;
  25681. word32 rSz;
  25682. const byte* s;
  25683. word32 sSz;
  25684. } eccVector;
  25685. #if !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  25686. static wc_test_ret_t ecc_test_vector_item(const eccVector* vector)
  25687. {
  25688. wc_test_ret_t ret = 0;
  25689. int verify = 0;
  25690. word32 sigSz;
  25691. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25692. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25693. #else
  25694. ecc_key userA[1];
  25695. #endif
  25696. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25697. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25698. word32 sigRawSz, rSz = MAX_ECC_BYTES, sSz = MAX_ECC_BYTES;
  25699. WC_DECLARE_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25700. WC_DECLARE_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25701. WC_DECLARE_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25702. #endif
  25703. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25704. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25705. WC_ALLOC_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25706. WC_ALLOC_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25707. WC_ALLOC_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25708. #endif
  25709. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  25710. if (sig == NULL)
  25711. ERROR_OUT(MEMORY_E, done);
  25712. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25713. if (sigRaw == NULL || r == NULL || s == NULL)
  25714. ERROR_OUT(MEMORY_E, done);
  25715. #endif
  25716. #endif
  25717. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25718. if (userA == NULL)
  25719. ERROR_OUT(MEMORY_E, done);
  25720. #endif
  25721. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  25722. if (ret != 0)
  25723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25724. ret = wc_ecc_import_raw(userA, vector->Qx, vector->Qy,
  25725. vector->d, vector->curveName);
  25726. if (ret != 0)
  25727. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25728. #if !defined(NO_ASN)
  25729. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25730. sigSz = ECC_SIG_SIZE;
  25731. ret = wc_ecc_rs_to_sig(vector->R, vector->S, sig, &sigSz);
  25732. if (ret != 0)
  25733. goto done;
  25734. #if !defined(HAVE_SELFTEST)
  25735. XMEMSET(sigRaw, 0, ECC_SIG_SIZE);
  25736. sigRawSz = ECC_SIG_SIZE;
  25737. ret = wc_ecc_rs_raw_to_sig(vector->r, vector->rSz, vector->s, vector->sSz,
  25738. sigRaw, &sigRawSz);
  25739. if (ret != 0)
  25740. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25741. if (sigSz != sigRawSz || XMEMCMP(sig, sigRaw, sigSz) != 0) {
  25742. ret = WC_TEST_RET_ENC_NC;
  25743. goto done;
  25744. }
  25745. ret = wc_ecc_sig_to_rs(sig, sigSz, r, &rSz, s, &sSz);
  25746. if (ret != 0)
  25747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25748. if (rSz != vector->rSz || XMEMCMP(r, vector->r, rSz) != 0 ||
  25749. sSz != vector->sSz || XMEMCMP(s, vector->s, sSz) != 0) {
  25750. ret = WC_TEST_RET_ENC_NC;
  25751. goto done;
  25752. }
  25753. #endif /* !HAVE_SELFTEST */
  25754. #else
  25755. /* Signature will be R+S directly */
  25756. /* Make sure and zero pad if r or s is less than key size */
  25757. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25758. sigSz = vector->keySize * 2;
  25759. XMEMCPY(sig + (vector->keySize - vector->rSz),
  25760. vector->r, vector->rSz);
  25761. XMEMCPY(sig + vector->keySize + (vector->keySize - vector->sSz),
  25762. vector->s, vector->sSz);
  25763. #endif /* !NO_ASN */
  25764. #ifdef HAVE_ECC_VERIFY
  25765. do {
  25766. #if defined(WOLFSSL_ASYNC_CRYPT)
  25767. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25768. #endif
  25769. if (ret == 0)
  25770. ret = wc_ecc_verify_hash(sig, sigSz, (byte*)vector->msg,
  25771. vector->msgLen, &verify, userA);
  25772. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25773. if (ret != 0)
  25774. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25775. TEST_SLEEP();
  25776. if (verify != 1)
  25777. ret = WC_TEST_RET_ENC_NC;
  25778. #endif
  25779. done:
  25780. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25781. if (userA != NULL) {
  25782. wc_ecc_free(userA);
  25783. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25784. }
  25785. #else
  25786. wc_ecc_free(userA);
  25787. #endif
  25788. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25789. WC_FREE_VAR(sigRaw, HEAP_HINT);
  25790. WC_FREE_VAR(r, HEAP_HINT);
  25791. WC_FREE_VAR(s, HEAP_HINT);
  25792. #endif
  25793. WC_FREE_VAR(sig, HEAP_HINT);
  25794. return ret;
  25795. }
  25796. static wc_test_ret_t ecc_test_vector(int keySize)
  25797. {
  25798. wc_test_ret_t ret;
  25799. eccVector vec;
  25800. XMEMSET(&vec, 0, sizeof(vec));
  25801. vec.keySize = (word32)keySize;
  25802. switch(keySize) {
  25803. #if defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)
  25804. case 14:
  25805. return 0;
  25806. #endif /* HAVE_ECC112 */
  25807. #if defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)
  25808. case 16:
  25809. return 0;
  25810. #endif /* HAVE_ECC128 */
  25811. #if defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)
  25812. case 20:
  25813. return 0;
  25814. #endif /* HAVE_ECC160 */
  25815. #if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)
  25816. case 24:
  25817. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  25818. #if 1
  25819. vec.msg = "\x60\x80\x79\x42\x3f\x12\x42\x1d\xe6\x16\xb7\x49\x3e\xbe\x55\x1c\xf4\xd6\x5b\x92";
  25820. vec.msgLen = 20;
  25821. #else
  25822. /* This is the raw message prior to SHA-1 */
  25823. vec.msg =
  25824. "\xeb\xf7\x48\xd7\x48\xeb\xbc\xa7\xd2\x9f\xb4\x73\x69\x8a\x6e\x6b"
  25825. "\x4f\xb1\x0c\x86\x5d\x4a\xf0\x24\xcc\x39\xae\x3d\xf3\x46\x4b\xa4"
  25826. "\xf1\xd6\xd4\x0f\x32\xbf\x96\x18\xa9\x1b\xb5\x98\x6f\xa1\xa2\xaf"
  25827. "\x04\x8a\x0e\x14\xdc\x51\xe5\x26\x7e\xb0\x5e\x12\x7d\x68\x9d\x0a"
  25828. "\xc6\xf1\xa7\xf1\x56\xce\x06\x63\x16\xb9\x71\xcc\x7a\x11\xd0\xfd"
  25829. "\x7a\x20\x93\xe2\x7c\xf2\xd0\x87\x27\xa4\xe6\x74\x8c\xc3\x2f\xd5"
  25830. "\x9c\x78\x10\xc5\xb9\x01\x9d\xf2\x1c\xdc\xc0\xbc\xa4\x32\xc0\xa3"
  25831. "\xee\xd0\x78\x53\x87\x50\x88\x77\x11\x43\x59\xce\xe4\xa0\x71\xcf";
  25832. vec.msgLen = 128;
  25833. #endif
  25834. vec.Qx = "07008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6";
  25835. vec.Qy = "76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477";
  25836. vec.d = "e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3";
  25837. vec.R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  25838. vec.S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  25839. vec.curveName = "SECP192R1";
  25840. vec.r = (byte*)"\x69\x94\xd9\x62\xbd\xd0\xd7\x93\xff\xdd\xf8\x55"
  25841. "\xec\x5b\xf2\xf9\x1a\x96\x98\xb4\x62\x58\xa6\x3e";
  25842. vec.rSz = 24;
  25843. vec.s = (byte*)"\x02\xba\x64\x65\xa2\x34\x90\x37\x44\xab\x02\xbc"
  25844. "\x85\x21\x40\x5b\x73\xcf\x5f\xc0\x0e\x1a\x9f\x41";
  25845. vec.sSz = 24;
  25846. break;
  25847. #endif /* HAVE_ECC192 */
  25848. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  25849. case 28:
  25850. /* first [P-224,SHA-1] vector from FIPS 186-3 NIST vectors */
  25851. #if 1
  25852. vec.msg = "\xb9\xa3\xb8\x6d\xb0\xba\x99\xfd\xc6\xd2\x94\x6b\xfe\xbe\x9c\xe8\x3f\x10\x74\xfc";
  25853. vec.msgLen = 20;
  25854. #else
  25855. /* This is the raw message prior to SHA-1 */
  25856. vec.msg =
  25857. "\x36\xc8\xb2\x29\x86\x48\x7f\x67\x7c\x18\xd0\x97\x2a\x9e\x20\x47"
  25858. "\xb3\xaf\xa5\x9e\xc1\x62\x76\x4e\xc3\x0b\x5b\x69\xe0\x63\x0f\x99"
  25859. "\x0d\x4e\x05\xc2\x73\xb0\xe5\xa9\xd4\x28\x27\xb6\x95\xfc\x2d\x64"
  25860. "\xd9\x13\x8b\x1c\xf4\xc1\x21\x55\x89\x4c\x42\x13\x21\xa7\xbb\x97"
  25861. "\x0b\xdc\xe0\xfb\xf0\xd2\xae\x85\x61\xaa\xd8\x71\x7f\x2e\x46\xdf"
  25862. "\xe3\xff\x8d\xea\xb4\xd7\x93\x23\x56\x03\x2c\x15\x13\x0d\x59\x9e"
  25863. "\x26\xc1\x0f\x2f\xec\x96\x30\x31\xac\x69\x38\xa1\x8d\x66\x45\x38"
  25864. "\xb9\x4d\xac\x55\x34\xef\x7b\x59\x94\x24\xd6\x9b\xe1\xf7\x1c\x20";
  25865. vec.msgLen = 128;
  25866. #endif
  25867. vec.Qx = "8a4dca35136c4b70e588e23554637ae251077d1365a6ba5db9585de7";
  25868. vec.Qy = "ad3dee06de0be8279d4af435d7245f14f3b4f82eb578e519ee0057b1";
  25869. vec.d = "97c4b796e1639dd1035b708fc00dc7ba1682cec44a1002a1a820619f";
  25870. vec.R = "147b33758321e722a0360a4719738af848449e2c1d08defebc1671a7";
  25871. vec.S = "24fc7ed7f1352ca3872aa0916191289e2e04d454935d50fe6af3ad5b";
  25872. vec.curveName = "SECP224R1";
  25873. vec.r = (byte*)"\x14\x7b\x33\x75\x83\x21\xe7\x22\xa0\x36\x0a\x47"
  25874. "\x19\x73\x8a\xf8\x48\x44\x9e\x2c\x1d\x08\xde\xfe"
  25875. "\xbc\x16\x71\xa7";
  25876. vec.rSz = 28;
  25877. vec.s = (byte*)"\x24\xfc\x7e\xd7\xf1\x35\x2c\xa3\x87\x2a\xa0\x91"
  25878. "\x61\x91\x28\x9e\x2e\x04\xd4\x54\x93\x5d\x50\xfe"
  25879. "\x6a\xf3\xad\x5b";
  25880. vec.sSz = 28;
  25881. break;
  25882. #endif /* HAVE_ECC224 */
  25883. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  25884. case 30:
  25885. return 0;
  25886. #endif /* HAVE_ECC239 */
  25887. #if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES)
  25888. case 32:
  25889. /* first [P-256,SHA-1] vector from FIPS 186-3 NIST vectors */
  25890. #if 1
  25891. vec.msg = "\xa3\xf9\x1a\xe2\x1b\xa6\xb3\x03\x98\x64\x47\x2f\x18\x41\x44\xc6\xaf\x62\xcd\x0e";
  25892. vec.msgLen = 20;
  25893. #else
  25894. /* This is the raw message prior to SHA-1 */
  25895. vec.msg =
  25896. "\xa2\x4b\x21\x76\x2e\x6e\xdb\x15\x3c\xc1\x14\x38\xdb\x0e\x92\xcd"
  25897. "\xf5\x2b\x86\xb0\x6c\xa9\x70\x16\x06\x27\x59\xc7\x0d\x36\xd1\x56"
  25898. "\x2c\xc9\x63\x0d\x7f\xc7\xc7\x74\xb2\x8b\x54\xe3\x1e\xf5\x58\x72"
  25899. "\xb2\xa6\x5d\xf1\xd7\xec\x26\xde\xbb\x33\xe7\xd9\x27\xef\xcc\xf4"
  25900. "\x6b\x63\xde\x52\xa4\xf4\x31\xea\xca\x59\xb0\x5d\x2e\xde\xc4\x84"
  25901. "\x5f\xff\xc0\xee\x15\x03\x94\xd6\x1f\x3d\xfe\xcb\xcd\xbf\x6f\x5a"
  25902. "\x73\x38\xd0\xbe\x3f\x2a\x77\x34\x51\x98\x3e\xba\xeb\x48\xf6\x73"
  25903. "\x8f\xc8\x95\xdf\x35\x7e\x1a\x48\xa6\x53\xbb\x35\x5a\x31\xa1\xb4"
  25904. vec.msgLen = 128;
  25905. #endif
  25906. vec.Qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  25907. vec.Qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  25908. vec.d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  25909. vec.R = "2b826f5d44e2d0b6de531ad96b51e8f0c56fdfead3c236892e4d84eacfc3b75c";
  25910. vec.S = "a2248b62c03db35a7cd63e8a120a3521a89d3d2f61ff99035a2148ae32e3a248";
  25911. vec.r = (byte*)"\x2b\x82\x6f\x5d\x44\xe2\xd0\xb6\xde\x53\x1a\xd9"
  25912. "\x6b\x51\xe8\xf0\xc5\x6f\xdf\xea\xd3\xc2\x36\x89"
  25913. "\x2e\x4d\x84\xea\xcf\xc3\xb7\x5c";
  25914. vec.rSz = 32;
  25915. vec.s = (byte*)"\xa2\x24\x8b\x62\xc0\x3d\xb3\x5a\x7c\xd6\x3e\x8a"
  25916. "\x12\x0a\x35\x21\xa8\x9d\x3d\x2f\x61\xff\x99\x03"
  25917. "\x5a\x21\x48\xae\x32\xe3\xa2\x48";
  25918. vec.sSz = 32;
  25919. vec.curveName = "SECP256R1";
  25920. break;
  25921. #endif /* !NO_ECC256 */
  25922. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  25923. case 40:
  25924. return 0;
  25925. #endif /* HAVE_ECC320 */
  25926. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  25927. case 48:
  25928. /* first [P-384,SHA-1] vector from FIPS 186-3 NIST vectors */
  25929. #if 1
  25930. vec.msg = "\x9b\x9f\x8c\x95\x35\xa5\xca\x26\x60\x5d\xb7\xf2\xfa\x57\x3b\xdf\xc3\x2e\xab\x8b";
  25931. vec.msgLen = 20;
  25932. #else
  25933. /* This is the raw message prior to SHA-1 */
  25934. vec.msg =
  25935. "\xab\xe1\x0a\xce\x13\xe7\xe1\xd9\x18\x6c\x48\xf7\x88\x9d\x51\x47"
  25936. "\x3d\x3a\x09\x61\x98\x4b\xc8\x72\xdf\x70\x8e\xcc\x3e\xd3\xb8\x16"
  25937. "\x9d\x01\xe3\xd9\x6f\xc4\xf1\xd5\xea\x00\xa0\x36\x92\xbc\xc5\xcf"
  25938. "\xfd\x53\x78\x7c\x88\xb9\x34\xaf\x40\x4c\x03\x9d\x32\x89\xb5\xba"
  25939. "\xc5\xae\x7d\xb1\x49\x68\x75\xb5\xdc\x73\xc3\x09\xf9\x25\xc1\x3d"
  25940. "\x1c\x01\xab\xda\xaf\xeb\xcd\xac\x2c\xee\x43\x39\x39\xce\x8d\x4a"
  25941. "\x0a\x5d\x57\xbb\x70\x5f\x3b\xf6\xec\x08\x47\x95\x11\xd4\xb4\xa3"
  25942. "\x21\x1f\x61\x64\x9a\xd6\x27\x43\x14\xbf\x0d\x43\x8a\x81\xe0\x60"
  25943. vec.msgLen = 128;
  25944. #endif
  25945. vec.Qx = "e55fee6c49d8d523f5ce7bf9c0425ce4ff650708b7de5cfb095901523979a7f042602db30854735369813b5c3f5ef868";
  25946. vec.Qy = "28f59cc5dc509892a988d38a8e2519de3d0c4fd0fbdb0993e38f18506c17606c5e24249246f1ce94983a5361c5be983e";
  25947. vec.d = "a492ce8fa90084c227e1a32f7974d39e9ff67a7e8705ec3419b35fb607582bebd461e0b1520ac76ec2dd4e9b63ebae71";
  25948. vec.R = "6820b8585204648aed63bdff47f6d9acebdea62944774a7d14f0e14aa0b9a5b99545b2daee6b3c74ebf606667a3f39b7";
  25949. vec.S = "491af1d0cccd56ddd520b233775d0bc6b40a6255cc55207d8e9356741f23c96c14714221078dbd5c17f4fdd89b32a907";
  25950. vec.curveName = "SECP384R1";
  25951. vec.r = (byte*)"\x68\x20\xb8\x58\x52\x04\x64\x8a\xed\x63\xbd\xff"
  25952. "\x47\xf6\xd9\xac\xeb\xde\xa6\x29\x44\x77\x4a\x7d"
  25953. "\x14\xf0\xe1\x4a\xa0\xb9\xa5\xb9\x95\x45\xb2\xda"
  25954. "\xee\x6b\x3c\x74\xeb\xf6\x06\x66\x7a\x3f\x39\xb7";
  25955. vec.rSz = 48;
  25956. vec.s = (byte*)"\x49\x1a\xf1\xd0\xcc\xcd\x56\xdd\xd5\x20\xb2\x33"
  25957. "\x77\x5d\x0b\xc6\xb4\x0a\x62\x55\xcc\x55\x20\x7d"
  25958. "\x8e\x93\x56\x74\x1f\x23\xc9\x6c\x14\x71\x42\x21"
  25959. "\x07\x8d\xbd\x5c\x17\xf4\xfd\xd8\x9b\x32\xa9\x07";
  25960. vec.sSz = 48;
  25961. break;
  25962. #endif /* HAVE_ECC384 */
  25963. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  25964. case 64:
  25965. return 0;
  25966. #endif /* HAVE_ECC512 */
  25967. #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
  25968. case 66:
  25969. /* first [P-521,SHA-1] vector from FIPS 186-3 NIST vectors */
  25970. #if 1
  25971. vec.msg = "\x1b\xf7\x03\x9c\xca\x23\x94\x27\x3f\x11\xa1\xd4\x8d\xcc\xb4\x46\x6f\x31\x61\xdf";
  25972. vec.msgLen = 20;
  25973. #else
  25974. /* This is the raw message prior to SHA-1 */
  25975. vec.msg =
  25976. "\x50\x3f\x79\x39\x34\x0a\xc7\x23\xcd\x4a\x2f\x4e\x6c\xcc\x27\x33"
  25977. "\x38\x3a\xca\x2f\xba\x90\x02\x19\x9d\x9e\x1f\x94\x8b\xe0\x41\x21"
  25978. "\x07\xa3\xfd\xd5\x14\xd9\x0c\xd4\xf3\x7c\xc3\xac\x62\xef\x00\x3a"
  25979. "\x2d\xb1\xd9\x65\x7a\xb7\x7f\xe7\x55\xbf\x71\xfa\x59\xe4\xd9\x6e"
  25980. "\xa7\x2a\xe7\xbf\x9d\xe8\x7d\x79\x34\x3b\xc1\xa4\xbb\x14\x4d\x16"
  25981. "\x28\xd1\xe9\xe9\xc8\xed\x80\x8b\x96\x2c\x54\xe5\xf9\x6d\x53\xda"
  25982. "\x14\x7a\x96\x38\xf9\x4a\x91\x75\xd8\xed\x61\x05\x5f\x0b\xa5\x73"
  25983. "\xa8\x2b\xb7\xe0\x18\xee\xda\xc4\xea\x7b\x36\x2e\xc8\x9c\x38\x2b"
  25984. vec.msgLen = 128;
  25985. #endif
  25986. vec.Qx = "12fbcaeffa6a51f3ee4d3d2b51c5dec6d7c726ca353fc014ea2bf7cfbb9b910d32cbfa6a00fe39b6cdb8946f22775398b2e233c0cf144d78c8a7742b5c7a3bb5d23";
  25987. vec.Qy = "09cdef823dd7bf9a79e8cceacd2e4527c231d0ae5967af0958e931d7ddccf2805a3e618dc3039fec9febbd33052fe4c0fee98f033106064982d88f4e03549d4a64d";
  25988. vec.d = "1bd56bd106118eda246155bd43b42b8e13f0a6e25dd3bb376026fab4dc92b6157bc6dfec2d15dd3d0cf2a39aa68494042af48ba9601118da82c6f2108a3a203ad74";
  25989. vec.R = "0bd117b4807710898f9dd7778056485777668f0e78e6ddf5b000356121eb7a220e9493c7f9a57c077947f89ac45d5acb6661bbcd17abb3faea149ba0aa3bb1521be";
  25990. vec.S = "019cd2c5c3f9870ecdeb9b323abdf3a98cd5e231d85c6ddc5b71ab190739f7f226e6b134ba1d5889ddeb2751dabd97911dff90c34684cdbe7bb669b6c3d22f2480c";
  25991. vec.curveName = "SECP521R1";
  25992. vec.r = (byte*)"\xbd\x11\x7b\x48\x07\x71\x08\x98\xf9\xdd\x77\x78"
  25993. "\x05\x64\x85\x77\x76\x68\xf0\xe7\x8e\x6d\xdf\x5b"
  25994. "\x00\x03\x56\x12\x1e\xb7\xa2\x20\xe9\x49\x3c\x7f"
  25995. "\x9a\x57\xc0\x77\x94\x7f\x89\xac\x45\xd5\xac\xb6"
  25996. "\x66\x1b\xbc\xd1\x7a\xbb\x3f\xae\xa1\x49\xba\x0a"
  25997. "\xa3\xbb\x15\x21\xbe";
  25998. vec.rSz = 65;
  25999. vec.s = (byte*)"\x19\xcd\x2c\x5c\x3f\x98\x70\xec\xde\xb9\xb3\x23"
  26000. "\xab\xdf\x3a\x98\xcd\x5e\x23\x1d\x85\xc6\xdd\xc5"
  26001. "\xb7\x1a\xb1\x90\x73\x9f\x7f\x22\x6e\x6b\x13\x4b"
  26002. "\xa1\xd5\x88\x9d\xde\xb2\x75\x1d\xab\xd9\x79\x11"
  26003. "\xdf\xf9\x0c\x34\x68\x4c\xdb\xe7\xbb\x66\x9b\x6c"
  26004. "\x3d\x22\xf2\x48\x0c";
  26005. vec.sSz = 65;
  26006. break;
  26007. #endif /* HAVE_ECC521 */
  26008. default:
  26009. return WC_TEST_RET_ENC_EC(NOT_COMPILED_IN); /* Invalid key size /
  26010. * Not supported
  26011. */
  26012. }; /* Switch */
  26013. ret = ecc_test_vector_item(&vec);
  26014. if (ret < 0) {
  26015. return ret;
  26016. }
  26017. return 0;
  26018. }
  26019. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26020. #if defined(HAVE_ECC_SIGN) && \
  26021. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  26022. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  26023. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  26024. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  26025. static wc_test_ret_t ecdsa_test_deterministic_k_sig(ecc_key *key,
  26026. enum wc_HashType hashType, const char* msg, WC_RNG* rng, const byte* expSig,
  26027. size_t expSigSz)
  26028. {
  26029. wc_test_ret_t ret;
  26030. int verify;
  26031. byte sig[ECC_MAX_SIG_SIZE];
  26032. word32 sigSz;
  26033. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26034. ret = wc_Hash(hashType,
  26035. (byte*)msg, (word32)XSTRLEN(msg),
  26036. hash, sizeof(hash));
  26037. if (ret != 0)
  26038. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26039. /* Sign test */
  26040. sigSz = sizeof(sig);
  26041. do {
  26042. #if defined(WOLFSSL_ASYNC_CRYPT)
  26043. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26044. #endif
  26045. if (ret == 0)
  26046. ret = wc_ecc_sign_hash(hash, wc_HashGetDigestSize(hashType),
  26047. sig, &sigSz, rng, key);
  26048. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26049. if (ret != 0)
  26050. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26051. TEST_SLEEP();
  26052. /* Compare test vector */
  26053. if (sigSz != expSigSz) {
  26054. ret = WC_TEST_RET_ENC_NC;
  26055. goto done;
  26056. }
  26057. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26058. ret = WC_TEST_RET_ENC_NC;
  26059. goto done;
  26060. }
  26061. /* Verification */
  26062. verify = 0;
  26063. do {
  26064. #if defined(WOLFSSL_ASYNC_CRYPT)
  26065. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26066. #endif
  26067. if (ret == 0)
  26068. ret = wc_ecc_verify_hash(sig, sigSz,
  26069. hash, wc_HashGetDigestSize(hashType), &verify, key);
  26070. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26071. if (ret != 0)
  26072. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26073. if (verify != 1) {
  26074. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26075. }
  26076. done:
  26077. return ret;
  26078. }
  26079. static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
  26080. {
  26081. wc_test_ret_t ret;
  26082. #ifdef WOLFSSL_SMALL_STACK
  26083. ecc_key *key = NULL;
  26084. #else
  26085. ecc_key key[1];
  26086. #endif
  26087. int key_inited = 0;
  26088. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26089. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26090. "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721";
  26091. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26092. "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6";
  26093. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26094. "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299";
  26095. #ifndef NO_SHA256
  26096. WOLFSSL_SMALL_STACK_STATIC const byte expSig256[] = {
  26097. 0x30, 0x46, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26098. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26099. 0x00, 0xEF, 0xD4, 0x8B, 0x2A, 0xAC, 0xB6, 0xA8,
  26100. 0xFD, 0x11, 0x40, 0xDD, 0x9C, 0xD4, 0x5E, 0x81,
  26101. 0xD6, 0x9D, 0x2C, 0x87, 0x7B, 0x56, 0xAA, 0xF9,
  26102. 0x91, 0xC3, 0x4D, 0x0E, 0xA8, 0x4E, 0xAF, 0x37,
  26103. 0x16,
  26104. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26105. 0x00, 0xF7, 0xCB, 0x1C, 0x94, 0x2D, 0x65, 0x7C,
  26106. 0x41, 0xD4, 0x36, 0xC7, 0xA1, 0xB6, 0xE2, 0x9F,
  26107. 0x65, 0xF3, 0xE9, 0x00, 0xDB, 0xB9, 0xAF, 0xF4,
  26108. 0x06, 0x4D, 0xC4, 0xAB, 0x2F, 0x84, 0x3A, 0xCD,
  26109. 0xA8
  26110. };
  26111. #endif
  26112. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26113. WOLFSSL_SMALL_STACK_STATIC const byte expSig384[] = {
  26114. 0x30, 0x44, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26115. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26116. 0x0e, 0xaf, 0xea, 0x03, 0x9b, 0x20, 0xe9, 0xb4,
  26117. 0x23, 0x09, 0xfb, 0x1d, 0x89, 0xe2, 0x13, 0x05,
  26118. 0x7c, 0xbf, 0x97, 0x3d, 0xc0, 0xcf, 0xc8, 0xf1,
  26119. 0x29, 0xed, 0xdd, 0xc8, 0x00, 0xef, 0x77, 0x19,
  26120. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26121. 0x48, 0x61, 0xf0, 0x49, 0x1e, 0x69, 0x98, 0xb9,
  26122. 0x45, 0x51, 0x93, 0xe3, 0x4e, 0x7b, 0x0d, 0x28,
  26123. 0x4d, 0xdd, 0x71, 0x49, 0xa7, 0x4b, 0x95, 0xb9,
  26124. 0x26, 0x1f, 0x13, 0xab, 0xde, 0x94, 0x09, 0x54
  26125. };
  26126. #endif
  26127. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26128. WOLFSSL_SMALL_STACK_STATIC const byte expSig512[] = {
  26129. 0x30, 0x45, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26130. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26131. 0x00, 0x84, 0x96, 0xa6, 0x0b, 0x5e, 0x9b, 0x47,
  26132. 0xc8, 0x25, 0x48, 0x88, 0x27, 0xe0, 0x49, 0x5b,
  26133. 0x0e, 0x3f, 0xa1, 0x09, 0xec, 0x45, 0x68, 0xfd,
  26134. 0x3f, 0x8d, 0x10, 0x97, 0x67, 0x8e, 0xb9, 0x7f,
  26135. 0x00,
  26136. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26137. 0x23, 0x62, 0xab, 0x1a, 0xdb, 0xe2, 0xb8, 0xad,
  26138. 0xf9, 0xcb, 0x9e, 0xda, 0xb7, 0x40, 0xea, 0x60,
  26139. 0x49, 0xc0, 0x28, 0x11, 0x4f, 0x24, 0x60, 0xf9,
  26140. 0x65, 0x54, 0xf6, 0x1f, 0xae, 0x33, 0x02, 0xfe
  26141. };
  26142. #endif
  26143. #ifdef WOLFSSL_SMALL_STACK
  26144. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26145. if (key == NULL)
  26146. return MEMORY_E;
  26147. #endif
  26148. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26149. if (ret != 0)
  26150. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26151. key_inited = 1;
  26152. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26153. if (ret != 0)
  26154. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26155. ret = wc_ecc_set_deterministic(key, 1);
  26156. if (ret != 0)
  26157. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26158. #ifndef NO_SHA256
  26159. /* Test for SHA2-256 */
  26160. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA256, msg, rng,
  26161. expSig256, sizeof(expSig256));
  26162. if (ret != 0)
  26163. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26164. #endif /* !NO_SHA256 */
  26165. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26166. /* Test for SHA2-384 */
  26167. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA384, msg, rng,
  26168. expSig384, sizeof(expSig384));
  26169. if (ret != 0)
  26170. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26171. #endif /* WOLFSSL_SHA384 */
  26172. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26173. /* Test for SHA2-512 */
  26174. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA512, msg, rng,
  26175. expSig512, sizeof(expSig512));
  26176. if (ret != 0)
  26177. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26178. #endif /* WOLFSSL_SHA512 */
  26179. done:
  26180. if (key_inited)
  26181. wc_ecc_free(key);
  26182. #ifdef WOLFSSL_SMALL_STACK
  26183. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26184. #endif
  26185. return ret;
  26186. }
  26187. #endif /* NO_ECC256 || HAVE_ALL_CURVES */
  26188. #ifdef WOLFSSL_PUBLIC_MP
  26189. static wc_test_ret_t ecdsa_test_deterministic_k_rs(ecc_key *key,
  26190. enum wc_HashType hashType, const char* msg, WC_RNG* rng,
  26191. mp_int* r, mp_int* s,
  26192. mp_int* expR, mp_int* expS)
  26193. {
  26194. wc_test_ret_t ret;
  26195. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26196. int verify;
  26197. ret = wc_Hash(hashType,
  26198. (byte*)msg, (word32)XSTRLEN(msg),
  26199. hash, sizeof(hash));
  26200. if (ret != 0)
  26201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26202. ret = wc_ecc_sign_hash_ex(hash, wc_HashGetDigestSize(hashType), rng, key,
  26203. r, s);
  26204. #if defined(WOLFSSL_ASYNC_CRYPT)
  26205. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26206. #endif
  26207. if (ret != 0)
  26208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26209. TEST_SLEEP();
  26210. if (mp_cmp(r, expR) != MP_EQ && mp_cmp(s, expS) != MP_EQ) {
  26211. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26212. }
  26213. /* Verification */
  26214. verify = 0;
  26215. ret = wc_ecc_verify_hash_ex(r, s, hash, wc_HashGetDigestSize(hashType),
  26216. &verify, key);
  26217. #if defined(WOLFSSL_ASYNC_CRYPT)
  26218. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26219. #endif
  26220. if (ret != 0)
  26221. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26222. if (verify != 1) {
  26223. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26224. }
  26225. done:
  26226. return ret;
  26227. }
  26228. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  26229. /* KAT from RFC6979 */
  26230. static wc_test_ret_t ecc384_test_deterministic_k(WC_RNG* rng)
  26231. {
  26232. wc_test_ret_t ret;
  26233. #ifdef WOLFSSL_SMALL_STACK
  26234. ecc_key *key;
  26235. mp_int *r, *s, *expR, *expS;
  26236. #else
  26237. ecc_key key[1];
  26238. mp_int r[1], s[1], expR[1], expS[1];
  26239. #endif
  26240. int key_inited = 0,
  26241. tmp_mp_ints_inited = 0;
  26242. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26243. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26244. "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D8"
  26245. "96D5724E4C70A825F872C9EA60D2EDF5";
  26246. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26247. "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64"
  26248. "DEF8F0EA9055866064A254515480BC13";
  26249. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26250. "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1"
  26251. "288B231C3AE0D4FE7344FD2533264720";
  26252. #ifndef NO_SHA256
  26253. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26254. "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33"
  26255. "BDE1E888E63355D92FA2B3C36D8FB2CD";
  26256. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26257. "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEB"
  26258. "EFDC63ECCD1AC42EC0CB8668A4FA0AB0";
  26259. #endif
  26260. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26261. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26262. "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C"
  26263. "81A648152E44ACF96E36DD1E80FABE46";
  26264. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26265. "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94F"
  26266. "A329C145786E679E7B82C71A38628AC8";
  26267. #endif
  26268. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26269. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26270. "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799C"
  26271. "FE30F35CC900056D7C99CD7882433709";
  26272. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26273. "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112"
  26274. "DC7CC3EF3446DEFCEB01A45C2667FDD5";
  26275. #endif
  26276. #ifdef WOLFSSL_SMALL_STACK
  26277. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26278. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26279. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26280. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26281. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26282. if ((key == NULL) ||
  26283. (r == NULL) ||
  26284. (s == NULL) ||
  26285. (expR == NULL) ||
  26286. (expS == NULL))
  26287. {
  26288. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26289. }
  26290. #endif
  26291. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26292. if (ret != MP_OKAY)
  26293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26294. tmp_mp_ints_inited = 1;
  26295. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26296. if (ret != 0)
  26297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26298. key_inited = 1;
  26299. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP384R1");
  26300. if (ret != 0)
  26301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26302. ret = wc_ecc_set_deterministic(key, 1);
  26303. if (ret != 0)
  26304. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26305. #ifndef NO_SHA256
  26306. /* Test for SHA2-256 */
  26307. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26308. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26309. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26310. r, s, expR, expS);
  26311. if (ret != 0)
  26312. ERROR_OUT(ret, done);
  26313. #endif /* NO_SHA256 */
  26314. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26315. /* Test for SHA2-384 */
  26316. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26317. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26318. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26319. r, s, expR, expS);
  26320. if (ret != 0)
  26321. ERROR_OUT(ret, done);
  26322. #endif /* WOLFSSL_SHA384 */
  26323. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26324. /* Test for SHA2-512 */
  26325. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26326. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26327. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26328. r, s, expR, expS);
  26329. if (ret != 0)
  26330. ERROR_OUT(ret, done);
  26331. #endif /* WOLFSSL_SHA512 */
  26332. done:
  26333. if (key_inited)
  26334. wc_ecc_free(key);
  26335. if (tmp_mp_ints_inited) {
  26336. mp_free(r);
  26337. mp_free(s);
  26338. mp_free(expR);
  26339. mp_free(expS);
  26340. }
  26341. #ifdef WOLFSSL_SMALL_STACK
  26342. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26343. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26344. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26345. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26346. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26347. #endif
  26348. return ret;
  26349. }
  26350. #endif /* HAVE_ECC384 */
  26351. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  26352. /* KAT from RFC6979 */
  26353. static wc_test_ret_t ecc521_test_deterministic_k(WC_RNG* rng)
  26354. {
  26355. wc_test_ret_t ret;
  26356. #ifdef WOLFSSL_SMALL_STACK
  26357. ecc_key *key;
  26358. mp_int *r, *s, *expR, *expS;
  26359. #else
  26360. ecc_key key[1];
  26361. mp_int r[1], s[1], expR[1], expS[1];
  26362. #endif
  26363. int key_inited = 0,
  26364. tmp_mp_ints_inited = 0;
  26365. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26366. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26367. "0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75C"
  26368. "AA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83"
  26369. "538";
  26370. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26371. "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD3"
  26372. "71123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F502"
  26373. "3A4";
  26374. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26375. "0493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A2"
  26376. "8A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDF"
  26377. "CF5";
  26378. #ifndef NO_SHA256
  26379. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26380. "1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659"
  26381. "D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E"
  26382. "1A7";
  26383. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26384. "04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916"
  26385. "E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7E"
  26386. "CFC";
  26387. #endif
  26388. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26389. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26390. "1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4"
  26391. "B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67"
  26392. "451";
  26393. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26394. "1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5"
  26395. "FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65"
  26396. "D61";
  26397. #endif
  26398. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26399. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26400. "0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F1"
  26401. "74E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E37"
  26402. "7FA";
  26403. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26404. "0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF2"
  26405. "82623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A"
  26406. "67A";
  26407. #endif
  26408. #ifdef WOLFSSL_SMALL_STACK
  26409. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26410. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26411. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26412. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26413. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26414. if ((key == NULL) ||
  26415. (r == NULL) ||
  26416. (s == NULL) ||
  26417. (expR == NULL) ||
  26418. (expS == NULL))
  26419. {
  26420. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26421. goto done;
  26422. }
  26423. #endif
  26424. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26425. if (ret != MP_OKAY)
  26426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26427. tmp_mp_ints_inited = 1;
  26428. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26429. if (ret != 0)
  26430. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26431. key_inited = 1;
  26432. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP521R1");
  26433. if (ret != 0)
  26434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26435. ret = wc_ecc_set_deterministic(key, 1);
  26436. if (ret != 0)
  26437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26438. #ifndef NO_SHA256
  26439. /* Test for SHA2-256 */
  26440. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26441. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26442. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26443. r, s, expR, expS);
  26444. if (ret != 0)
  26445. ERROR_OUT(ret, done);
  26446. #endif /* NO_SHA256 */
  26447. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26448. /* Test for SHA2-384 */
  26449. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26450. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26451. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26452. r, s, expR, expS);
  26453. if (ret != 0)
  26454. ERROR_OUT(ret, done);
  26455. #endif /* WOLFSSL_SHA384 */
  26456. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26457. /* Test for SHA2-512 */
  26458. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26459. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26460. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26461. r, s, expR, expS);
  26462. if (ret != 0)
  26463. ERROR_OUT(ret, done);
  26464. #endif /* WOLFSSL_SHA512 */
  26465. done:
  26466. if (key_inited)
  26467. wc_ecc_free(key);
  26468. if (tmp_mp_ints_inited) {
  26469. mp_free(r);
  26470. mp_free(s);
  26471. mp_free(expR);
  26472. mp_free(expS);
  26473. }
  26474. #ifdef WOLFSSL_SMALL_STACK
  26475. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26476. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26477. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26478. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26479. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26480. #endif
  26481. return ret;
  26482. }
  26483. #endif /* HAVE_ECC521 */
  26484. #endif /* WOLFSSL_PUBLIC_MP */
  26485. #endif /* HAVE_ECC_SIGN && (WOLFSSL_ECDSA_DETERMINISTIC_K ||
  26486. WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  26487. && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  26488. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  26489. !defined(WOLFSSL_KCAPI_ECC)
  26490. static wc_test_ret_t ecc_test_sign_vectors(WC_RNG* rng)
  26491. {
  26492. wc_test_ret_t ret;
  26493. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26494. ecc_key *key = NULL;
  26495. #else
  26496. ecc_key key[1];
  26497. #endif
  26498. int key_inited = 0;
  26499. byte sig[72];
  26500. word32 sigSz;
  26501. WOLFSSL_SMALL_STACK_STATIC const unsigned char hash[32] = "test wolfSSL deterministic sign";
  26502. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26503. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26504. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26505. WOLFSSL_SMALL_STACK_STATIC const byte k[1] = { 0x02 };
  26506. WOLFSSL_SMALL_STACK_STATIC const byte expSig[71] = {
  26507. 0x30, 0x45, 0x02, 0x20, 0x7c, 0xf2, 0x7b, 0x18,
  26508. 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03,
  26509. 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2,
  26510. 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc,
  26511. 0x47, 0x66, 0x99, 0x78, 0x02, 0x21, 0x00, 0xa8,
  26512. 0x43, 0xa0, 0xce, 0x6c, 0x5e, 0x17, 0x8a, 0x53,
  26513. 0x4d, 0xaf, 0xd2, 0x95, 0x78, 0x9f, 0x84, 0x4f,
  26514. 0x94, 0xb8, 0x75, 0xa3, 0x19, 0xa5, 0xd4, 0xdf,
  26515. 0xe1, 0xd4, 0x5e, 0x9d, 0x97, 0xfe, 0x81
  26516. };
  26517. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26518. if ((key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  26519. return MEMORY_E;
  26520. #endif
  26521. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26522. if (ret != 0)
  26523. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26524. key_inited = 1;
  26525. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26526. if (ret != 0)
  26527. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26528. #if (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) \
  26529. && (HAVE_FIPS_VERSION > 2)))
  26530. wc_ecc_set_flags(key, WC_ECC_FLAG_DEC_SIGN);
  26531. #endif
  26532. ret = wc_ecc_sign_set_k(k, sizeof(k), key);
  26533. if (ret != 0)
  26534. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26535. sigSz = sizeof(sig);
  26536. do {
  26537. #if defined(WOLFSSL_ASYNC_CRYPT)
  26538. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26539. #endif
  26540. if (ret == 0)
  26541. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26542. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26543. if (ret != 0)
  26544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26545. TEST_SLEEP();
  26546. if (sigSz != sizeof(expSig)) {
  26547. ret = WC_TEST_RET_ENC_NC;
  26548. goto done;
  26549. }
  26550. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26551. ret = WC_TEST_RET_ENC_NC;
  26552. goto done;
  26553. }
  26554. sigSz = sizeof(sig);
  26555. do {
  26556. #if defined(WOLFSSL_ASYNC_CRYPT)
  26557. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26558. #endif
  26559. if (ret == 0)
  26560. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26561. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26562. if (ret != 0)
  26563. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26564. TEST_SLEEP();
  26565. done:
  26566. if (key_inited)
  26567. wc_ecc_free(key);
  26568. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26569. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26570. #endif
  26571. return ret;
  26572. }
  26573. #endif
  26574. #if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE)
  26575. static wc_test_ret_t ecc_test_cdh_vectors(WC_RNG* rng)
  26576. {
  26577. wc_test_ret_t ret;
  26578. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26579. ecc_key *pub_key = (ecc_key *)XMALLOC(sizeof *pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26580. ecc_key *priv_key = (ecc_key *)XMALLOC(sizeof *priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26581. #else
  26582. ecc_key pub_key[1], priv_key[1];
  26583. #endif
  26584. byte sharedA[32] = {0}, sharedB[32] = {0};
  26585. word32 x, z;
  26586. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287";
  26587. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac";
  26588. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26589. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26590. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26591. WOLFSSL_SMALL_STACK_STATIC const char* ZIUT = "46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b";
  26592. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26593. if ((pub_key == NULL) ||
  26594. (priv_key == NULL)) {
  26595. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26596. goto done;
  26597. }
  26598. #endif
  26599. XMEMSET(pub_key, 0, sizeof *pub_key);
  26600. XMEMSET(priv_key, 0, sizeof *priv_key);
  26601. /* setup private and public keys */
  26602. ret = wc_ecc_init_ex(pub_key, HEAP_HINT, devId);
  26603. if (ret != 0)
  26604. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26605. ret = wc_ecc_init_ex(priv_key, HEAP_HINT, devId);
  26606. if (ret != 0)
  26607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26608. wc_ecc_set_flags(pub_key, WC_ECC_FLAG_COFACTOR);
  26609. wc_ecc_set_flags(priv_key, WC_ECC_FLAG_COFACTOR);
  26610. ret = wc_ecc_import_raw(pub_key, QCAVSx, QCAVSy, NULL, "SECP256R1");
  26611. if (ret != 0)
  26612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26613. ret = wc_ecc_import_raw(priv_key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26614. if (ret != 0)
  26615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26616. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26617. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26618. !defined(HAVE_SELFTEST)
  26619. ret = wc_ecc_set_rng(priv_key, rng);
  26620. if (ret != 0)
  26621. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26622. #else
  26623. (void)rng;
  26624. #endif
  26625. /* compute ECC Cofactor shared secret */
  26626. x = sizeof(sharedA);
  26627. do {
  26628. #if defined(WOLFSSL_ASYNC_CRYPT)
  26629. ret = wc_AsyncWait(ret, &priv_key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26630. #endif
  26631. if (ret == 0)
  26632. ret = wc_ecc_shared_secret(priv_key, pub_key, sharedA, &x);
  26633. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26634. if (ret != 0)
  26635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26636. TEST_SLEEP();
  26637. /* read in expected Z */
  26638. z = sizeof(sharedB);
  26639. ret = Base16_Decode((const byte*)ZIUT, (word32)XSTRLEN(ZIUT), sharedB, &z);
  26640. if (ret != 0)
  26641. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26642. /* compare results */
  26643. if (x != z || XMEMCMP(sharedA, sharedB, x)) {
  26644. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26645. }
  26646. done:
  26647. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26648. if (priv_key) {
  26649. wc_ecc_free(priv_key);
  26650. XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26651. }
  26652. if (pub_key) {
  26653. wc_ecc_free(pub_key);
  26654. XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26655. }
  26656. #else
  26657. wc_ecc_free(priv_key);
  26658. wc_ecc_free(pub_key);
  26659. #endif
  26660. return ret;
  26661. }
  26662. #endif /* HAVE_ECC_CDH && HAVE_ECC_DHE */
  26663. #endif /* HAVE_ECC_VECTOR_TEST */
  26664. #ifdef HAVE_ECC_KEY_IMPORT
  26665. /* returns 0 on success */
  26666. static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
  26667. {
  26668. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26669. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26670. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26671. ecc_key *pub = (ecc_key *)XMALLOC(sizeof *pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26672. #endif
  26673. byte *exportBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26674. byte *tmp = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26675. #else
  26676. ecc_key key[1];
  26677. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  26678. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26679. ecc_key pub[1];
  26680. #endif
  26681. byte exportBuf[ECC_BUFSIZE];
  26682. byte tmp[ECC_BUFSIZE];
  26683. #endif
  26684. const byte* msg = (const byte*)"test wolfSSL ECC public gen";
  26685. word32 x;
  26686. word32 tmpSz;
  26687. wc_test_ret_t ret = 0;
  26688. ecc_point* pubPoint = NULL;
  26689. #ifdef HAVE_ECC_VERIFY
  26690. int verify = 0;
  26691. #endif
  26692. #ifdef NO_ASN
  26693. /* private d for eccKeyDerFile / ecc_key_der_256 */
  26694. const byte keyPriv[] = {
  26695. 0x45, 0xB6, 0x69, 0x02, 0x73, 0x9C, 0x6C, 0x85,
  26696. 0xA1, 0x38, 0x5B, 0x72, 0xE8, 0xE8, 0xC7, 0xAC,
  26697. 0xC4, 0x03, 0x8D, 0x53, 0x35, 0x04, 0xFA, 0x6C,
  26698. 0x28, 0xDC, 0x34, 0x8D, 0xE1, 0xA8, 0x09, 0x8C
  26699. };
  26700. #endif
  26701. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26702. if ((key == NULL) ||
  26703. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26704. (pub == NULL) ||
  26705. #endif
  26706. (exportBuf == NULL) ||
  26707. (tmp == NULL))
  26708. ERROR_OUT(MEMORY_E, done);
  26709. #endif
  26710. (void)msg;
  26711. (void)verify;
  26712. (void)exportBuf;
  26713. (void)rng;
  26714. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26715. #ifndef NO_ECC256
  26716. #if defined(USE_CERT_BUFFERS_256)
  26717. {
  26718. XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
  26719. tmpSz = (size_t)sizeof_ecc_key_der_256;
  26720. }
  26721. #elif !defined(NO_FILESYSTEM)
  26722. {
  26723. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  26724. if (!file) {
  26725. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26726. }
  26727. tmpSz = (word32)XFREAD(tmp, 1, ECC_BUFSIZE, file);
  26728. XFCLOSE(file);
  26729. if (tmpSz == 0)
  26730. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26731. }
  26732. #else
  26733. {
  26734. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
  26735. ERROR_OUT(ASN_PARSE_E, done);
  26736. }
  26737. #endif /* USE_CERT_BUFFERS_256 */
  26738. /* import private only then test with */
  26739. ret = wc_ecc_import_private_key(tmp, tmpSz, NULL, 0, NULL);
  26740. if (ret == 0) {
  26741. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26742. }
  26743. ret = wc_ecc_import_private_key(NULL, tmpSz, NULL, 0, key);
  26744. if (ret == 0) {
  26745. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26746. }
  26747. #ifndef NO_ASN
  26748. x = 0;
  26749. ret = wc_EccPrivateKeyDecode(tmp, &x, key, tmpSz);
  26750. if (ret != 0)
  26751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26752. #ifdef HAVE_ECC_KEY_EXPORT
  26753. x = ECC_BUFSIZE;
  26754. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26755. if (ret != 0)
  26756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26757. /* make private only key */
  26758. wc_ecc_free(key);
  26759. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26760. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26761. if (ret != 0)
  26762. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26763. x = ECC_BUFSIZE;
  26764. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26765. if (ret == 0) {
  26766. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26767. }
  26768. #endif /* HAVE_ECC_KEY_EXPORT */
  26769. #else
  26770. /* Load raw private d directly */
  26771. ret = wc_ecc_import_private_key(keyPriv, sizeof(keyPriv), NULL, 0, key);
  26772. #endif /* !NO_ASN */
  26773. ret = wc_ecc_make_pub(NULL, NULL);
  26774. if (ret == 0) {
  26775. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26776. }
  26777. TEST_SLEEP();
  26778. #ifndef WOLFSSL_NO_MALLOC
  26779. pubPoint = wc_ecc_new_point_h(HEAP_HINT);
  26780. if (pubPoint == NULL) {
  26781. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26782. }
  26783. #if !defined(WOLFSSL_CRYPTOCELL)
  26784. ret = wc_ecc_make_pub(key, pubPoint);
  26785. #if defined(WOLFSSL_ASYNC_CRYPT)
  26786. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26787. #endif
  26788. if (ret != 0)
  26789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26790. #endif /* !WOLFSSL_CRYPTOCELL */
  26791. TEST_SLEEP();
  26792. #ifdef HAVE_ECC_KEY_EXPORT
  26793. /* export should still fail, is private only key */
  26794. x = ECC_BUFSIZE;
  26795. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26796. if (ret == 0) {
  26797. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26798. }
  26799. #endif /* HAVE_ECC_KEY_EXPORT */
  26800. #endif /* !WOLFSSL_NO_MALLOC */
  26801. #endif /* !NO_ECC256 */
  26802. /* create a new key since above test for loading key is not supported */
  26803. #if defined(WOLFSSL_CRYPTOCELL) || defined(NO_ECC256) || \
  26804. defined(WOLFSSL_QNX_CAAM) || defined(WOLFSSL_SE050) || \
  26805. defined(WOLFSSL_SECO_CAAM) || defined(WOLFSSL_IMXRT1170_CAAM)
  26806. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  26807. if (ret != 0)
  26808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26809. #endif
  26810. #if defined(HAVE_ECC_SIGN) && (!defined(ECC_TIMING_RESISTANT) || \
  26811. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG))) && \
  26812. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(HAVE_ECC_DETERMINISTIC_K)
  26813. tmpSz = ECC_BUFSIZE;
  26814. ret = 0;
  26815. do {
  26816. #if defined(WOLFSSL_ASYNC_CRYPT)
  26817. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26818. #endif
  26819. if (ret == 0) {
  26820. ret = wc_ecc_sign_hash(msg, (word32)XSTRLEN((const char* )msg), tmp,
  26821. &tmpSz, rng, key);
  26822. }
  26823. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26824. if (ret != 0)
  26825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26826. TEST_SLEEP();
  26827. #ifdef HAVE_ECC_VERIFY
  26828. /* try verify with private only key */
  26829. ret = 0;
  26830. do {
  26831. #if defined(WOLFSSL_ASYNC_CRYPT)
  26832. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26833. #endif
  26834. if (ret == 0) {
  26835. ret = wc_ecc_verify_hash(tmp, tmpSz, msg,
  26836. (word32)XSTRLEN((const char*)msg), &verify, key);
  26837. }
  26838. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26839. if (ret != 0)
  26840. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26841. if (verify != 1) {
  26842. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26843. }
  26844. TEST_SLEEP();
  26845. #ifdef HAVE_ECC_KEY_EXPORT
  26846. /* exporting the public part should now work */
  26847. x = ECC_BUFSIZE;
  26848. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26849. if (ret != 0)
  26850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26851. #endif /* HAVE_ECC_KEY_EXPORT */
  26852. #endif /* HAVE_ECC_VERIFY */
  26853. #endif /* HAVE_ECC_SIGN */
  26854. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  26855. /* now test private only key with creating a shared secret */
  26856. x = ECC_BUFSIZE;
  26857. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26858. if (ret != 0)
  26859. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26860. #if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SE050)
  26861. /* make private only key */
  26862. wc_ecc_free(key);
  26863. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26864. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26865. if (ret != 0)
  26866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26867. /* check that public export fails with private only key */
  26868. x = ECC_BUFSIZE;
  26869. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26870. if (ret == 0) {
  26871. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26872. }
  26873. #endif /* WOLFSSL_QNX_CAAM */
  26874. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  26875. /* make public key for shared secret */
  26876. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  26877. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, pub);
  26878. #ifdef HAVE_ECC_CDH
  26879. wc_ecc_set_flags(key, WC_ECC_FLAG_COFACTOR);
  26880. #endif
  26881. #if defined(WOLFSSL_ASYNC_CRYPT)
  26882. ret = wc_AsyncWait(ret, &pub->asyncDev, WC_ASYNC_FLAG_NONE);
  26883. #endif
  26884. if (ret != 0)
  26885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26886. TEST_SLEEP();
  26887. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26888. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26889. !defined(HAVE_SELFTEST)
  26890. ret = wc_ecc_set_rng(key, rng);
  26891. if (ret != 0)
  26892. goto done;
  26893. #endif
  26894. x = ECC_BUFSIZE;
  26895. do {
  26896. #if defined(WOLFSSL_ASYNC_CRYPT)
  26897. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26898. #endif
  26899. if (ret == 0) {
  26900. ret = wc_ecc_shared_secret(key, pub, exportBuf, &x);
  26901. }
  26902. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26903. wc_ecc_free(pub);
  26904. if (ret != 0)
  26905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26906. TEST_SLEEP();
  26907. #endif /* HAVE_ECC_DHE && HAVE_ECC_KEY_EXPORT && !WC_NO_RNG */
  26908. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26909. ret = 0;
  26910. done:
  26911. wc_ecc_del_point_h(pubPoint, HEAP_HINT);
  26912. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26913. if (key != NULL) {
  26914. wc_ecc_free(key);
  26915. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26916. }
  26917. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26918. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26919. #endif
  26920. XFREE(exportBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26921. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26922. #else
  26923. wc_ecc_free(key);
  26924. #endif
  26925. return ret;
  26926. }
  26927. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26928. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26929. static wc_test_ret_t ecc_test_key_decode(WC_RNG* rng, int keySize)
  26930. {
  26931. wc_test_ret_t ret;
  26932. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26933. ecc_key *eccKey = (ecc_key *)XMALLOC(sizeof *eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26934. byte *tmpBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26935. #else
  26936. ecc_key eccKey[1];
  26937. byte tmpBuf[ECC_BUFSIZE];
  26938. #endif
  26939. word32 tmpSz;
  26940. word32 idx;
  26941. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26942. if ((eccKey == NULL) || (tmpBuf == NULL))
  26943. ERROR_OUT(MEMORY_E, done);
  26944. #endif
  26945. ret = wc_ecc_init(eccKey);
  26946. if (ret != 0) {
  26947. goto done;
  26948. }
  26949. ret = wc_ecc_make_key(rng, keySize, eccKey);
  26950. #if defined(WOLFSSL_ASYNC_CRYPT)
  26951. ret = wc_AsyncWait(ret, &eccKey->asyncDev, WC_ASYNC_FLAG_NONE);
  26952. #endif
  26953. if (ret != 0) {
  26954. goto done;
  26955. }
  26956. tmpSz = ECC_BUFSIZE;
  26957. ret = wc_EccKeyToDer(eccKey, tmpBuf, tmpSz);
  26958. wc_ecc_free(eccKey);
  26959. if (ret < 0) {
  26960. goto done;
  26961. }
  26962. tmpSz = (word32)ret;
  26963. ret = wc_ecc_init(eccKey);
  26964. if (ret != 0) {
  26965. goto done;
  26966. }
  26967. idx = 0;
  26968. ret = wc_EccPrivateKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26969. if (ret != 0) {
  26970. goto done;
  26971. }
  26972. wc_ecc_free(eccKey);
  26973. ret = wc_ecc_init(eccKey);
  26974. if (ret != 0) {
  26975. goto done;
  26976. }
  26977. idx = 0;
  26978. ret = wc_EccPublicKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26979. if (ret != 0) {
  26980. goto done;
  26981. }
  26982. ret = 0;
  26983. done:
  26984. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26985. if (eccKey != NULL) {
  26986. wc_ecc_free(eccKey);
  26987. XFREE(eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26988. }
  26989. XFREE(tmpBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26990. #else
  26991. wc_ecc_free(eccKey);
  26992. #endif
  26993. return ret;
  26994. }
  26995. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26996. #endif /* HAVE_ECC_KEY_IMPORT */
  26997. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26998. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26999. static wc_test_ret_t ecc_test_key_gen(WC_RNG* rng, int keySize)
  27000. {
  27001. wc_test_ret_t ret = 0;
  27002. int derSz;
  27003. #ifdef HAVE_PKCS8
  27004. word32 pkcs8Sz;
  27005. #endif
  27006. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27007. byte *der = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27008. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27009. #else
  27010. byte der[ECC_BUFSIZE];
  27011. ecc_key userA[1];
  27012. #endif
  27013. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27014. if ((der == NULL) || (userA == NULL))
  27015. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  27016. #endif
  27017. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27018. if (ret != 0)
  27019. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27020. ret = wc_ecc_make_key(rng, keySize, userA);
  27021. #if defined(WOLFSSL_ASYNC_CRYPT)
  27022. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27023. #endif
  27024. if (ret != 0)
  27025. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27026. TEST_SLEEP();
  27027. ret = wc_ecc_check_key(userA);
  27028. if (ret != 0)
  27029. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27030. TEST_SLEEP();
  27031. derSz = wc_EccKeyToDer(userA, der, ECC_BUFSIZE);
  27032. if (derSz < 0) {
  27033. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27034. }
  27035. ret = SaveDerAndPem(der, derSz, eccCaKeyTempFile, eccCaKeyPemFile,
  27036. ECC_PRIVATEKEY_TYPE);
  27037. if (ret != 0)
  27038. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27039. /* test export of public key */
  27040. derSz = wc_EccPublicKeyToDer(userA, der, ECC_BUFSIZE, 1);
  27041. if (derSz < 0) {
  27042. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27043. }
  27044. if (derSz == 0) {
  27045. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27046. }
  27047. #ifdef HAVE_COMP_KEY
  27048. /* test export of compressed public key */
  27049. derSz = wc_EccPublicKeyToDer_ex(userA, der, ECC_BUFSIZE, 1, 1);
  27050. if (derSz < 0) {
  27051. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27052. }
  27053. if (derSz == 0) {
  27054. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27055. }
  27056. #endif
  27057. ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0);
  27058. if (ret != 0)
  27059. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27060. #ifdef HAVE_PKCS8
  27061. /* test export of PKCS#8 unencrypted private key */
  27062. pkcs8Sz = FOURK_BUF;
  27063. derSz = wc_EccPrivateKeyToPKCS8(userA, der, &pkcs8Sz);
  27064. if (derSz < 0) {
  27065. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27066. }
  27067. if (derSz == 0) {
  27068. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27069. }
  27070. ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0);
  27071. if (ret != 0) {
  27072. goto done;
  27073. }
  27074. #endif /* HAVE_PKCS8 */
  27075. done:
  27076. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27077. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27078. if (userA != NULL) {
  27079. wc_ecc_free(userA);
  27080. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27081. }
  27082. #else
  27083. wc_ecc_free(userA);
  27084. #endif
  27085. return ret;
  27086. }
  27087. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  27088. static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
  27089. int curve_id, const ecc_set_type* dp)
  27090. {
  27091. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27092. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27093. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27094. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27095. word32 y;
  27096. #endif
  27097. #ifdef HAVE_ECC_KEY_EXPORT
  27098. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  27099. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27100. #endif
  27101. word32 x = 0;
  27102. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27103. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27104. defined(HAVE_ECC_SIGN)
  27105. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27106. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27107. int i;
  27108. #ifdef HAVE_ECC_VERIFY
  27109. int verify;
  27110. #endif /* HAVE_ECC_VERIFY */
  27111. #endif /* HAVE_ECC_SIGN */
  27112. wc_test_ret_t ret;
  27113. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27114. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27115. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27116. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27117. #else
  27118. ecc_key userA[1];
  27119. ecc_key userB[1];
  27120. ecc_key pubKey[1];
  27121. #endif
  27122. #ifndef WC_NO_RNG
  27123. int curveSize;
  27124. #endif
  27125. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27126. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27127. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27128. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27129. #endif
  27130. #ifdef HAVE_ECC_KEY_EXPORT
  27131. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27132. #endif
  27133. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27134. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27135. defined(HAVE_ECC_SIGN)
  27136. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27137. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27138. #endif
  27139. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  27140. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \
  27141. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27142. if (sharedA == NULL || sharedB == NULL)
  27143. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27144. #endif
  27145. #ifdef HAVE_ECC_KEY_EXPORT
  27146. if (exportBuf == NULL)
  27147. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27148. #endif
  27149. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27150. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27151. defined(HAVE_ECC_SIGN)
  27152. if (sig == NULL || digest == NULL)
  27153. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27154. #endif
  27155. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  27156. (void)testVerifyCount;
  27157. (void)dp;
  27158. (void)x;
  27159. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27160. if ((userA == NULL) ||
  27161. (userB == NULL) ||
  27162. (pubKey == NULL))
  27163. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27164. #endif
  27165. XMEMSET(userA, 0, sizeof *userA);
  27166. XMEMSET(userB, 0, sizeof *userB);
  27167. XMEMSET(pubKey, 0, sizeof *pubKey);
  27168. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27169. if (ret != 0)
  27170. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27171. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  27172. if (ret != 0)
  27173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27174. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27175. if (ret != 0)
  27176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27177. #ifdef WOLFSSL_CUSTOM_CURVES
  27178. if (dp != NULL) {
  27179. ret = wc_ecc_set_custom_curve(userA, dp);
  27180. if (ret != 0)
  27181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27182. ret = wc_ecc_set_custom_curve(userB, dp);
  27183. if (ret != 0)
  27184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27185. }
  27186. #endif
  27187. #ifndef WC_NO_RNG
  27188. ret = wc_ecc_make_key_ex(rng, keySize, userA, curve_id);
  27189. #if defined(WOLFSSL_ASYNC_CRYPT)
  27190. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27191. #endif
  27192. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  27193. if (ret == WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  27194. ret = 0;
  27195. goto done; /* no software case */
  27196. }
  27197. #endif
  27198. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  27199. goto done; /* catch case, where curve is not supported */
  27200. if (ret != 0)
  27201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27202. TEST_SLEEP();
  27203. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  27204. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  27205. if (curveSize != userA->dp->size)
  27206. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27207. }
  27208. ret = wc_ecc_check_key(userA);
  27209. if (ret != 0)
  27210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27211. TEST_SLEEP();
  27212. /* ATECC508/608 configuration may not support more than one ECDH key */
  27213. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27214. ret = wc_ecc_make_key_ex(rng, keySize, userB, curve_id);
  27215. #if defined(WOLFSSL_ASYNC_CRYPT)
  27216. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  27217. #endif
  27218. if (ret != 0)
  27219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27220. TEST_SLEEP();
  27221. /* only perform the below tests if the key size matches */
  27222. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  27223. /* Not an error, just not a key size match */
  27224. WARNING_OUT(ECC_CURVE_OID_E, done);
  27225. #ifdef HAVE_ECC_DHE
  27226. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27227. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27228. !defined(HAVE_SELFTEST)
  27229. ret = wc_ecc_set_rng(userA, rng);
  27230. if (ret != 0)
  27231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27232. ret = wc_ecc_set_rng(userB, rng);
  27233. if (ret != 0)
  27234. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27235. #endif
  27236. x = ECC_SHARED_SIZE;
  27237. do {
  27238. #if defined(WOLFSSL_ASYNC_CRYPT)
  27239. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27240. #endif
  27241. if (ret == 0)
  27242. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27243. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27244. if (ret != 0)
  27245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27246. TEST_SLEEP();
  27247. y = ECC_SHARED_SIZE;
  27248. do {
  27249. #if defined(WOLFSSL_ASYNC_CRYPT)
  27250. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27251. #endif
  27252. if (ret == 0)
  27253. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27254. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27255. if (ret != 0)
  27256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27257. if (y != x)
  27258. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27259. if (XMEMCMP(sharedA, sharedB, x))
  27260. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27261. TEST_SLEEP();
  27262. #ifdef HAVE_ECC_CDH
  27263. /* add cofactor flag */
  27264. wc_ecc_set_flags(userA, WC_ECC_FLAG_COFACTOR);
  27265. wc_ecc_set_flags(userB, WC_ECC_FLAG_COFACTOR);
  27266. x = ECC_SHARED_SIZE;
  27267. do {
  27268. #if defined(WOLFSSL_ASYNC_CRYPT)
  27269. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27270. #endif
  27271. if (ret == 0)
  27272. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27273. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27274. if (ret != 0)
  27275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27276. TEST_SLEEP();
  27277. y = ECC_SHARED_SIZE;
  27278. do {
  27279. #if defined(WOLFSSL_ASYNC_CRYPT)
  27280. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27281. #endif
  27282. if (ret == 0)
  27283. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27284. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27285. if (ret != 0)
  27286. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27287. if (y != x)
  27288. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27289. if (XMEMCMP(sharedA, sharedB, x))
  27290. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27291. TEST_SLEEP();
  27292. /* remove cofactor flag */
  27293. wc_ecc_set_flags(userA, 0);
  27294. wc_ecc_set_flags(userB, 0);
  27295. #endif /* HAVE_ECC_CDH */
  27296. #endif /* HAVE_ECC_DHE */
  27297. #endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */
  27298. #ifdef HAVE_ECC_KEY_EXPORT
  27299. x = ECC_KEY_EXPORT_BUF_SIZE;
  27300. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  27301. if (ret != 0)
  27302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27303. #ifdef HAVE_ECC_KEY_IMPORT
  27304. #ifdef WOLFSSL_CUSTOM_CURVES
  27305. if (dp != NULL) {
  27306. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27307. if (ret != 0)
  27308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27309. }
  27310. #endif
  27311. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27312. if (ret != 0)
  27313. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27314. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27315. #ifdef HAVE_ECC_DHE
  27316. y = ECC_SHARED_SIZE;
  27317. do {
  27318. #if defined(WOLFSSL_ASYNC_CRYPT)
  27319. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27320. #endif
  27321. if (ret == 0)
  27322. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27323. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27324. if (ret != 0)
  27325. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27326. if (XMEMCMP(sharedA, sharedB, y))
  27327. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27328. TEST_SLEEP();
  27329. #endif /* HAVE_ECC_DHE */
  27330. #ifdef HAVE_COMP_KEY
  27331. /* try compressed export / import too */
  27332. x = ECC_KEY_EXPORT_BUF_SIZE;
  27333. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  27334. if (ret != 0)
  27335. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27336. wc_ecc_free(pubKey);
  27337. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27338. if (ret != 0)
  27339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27340. #ifdef WOLFSSL_CUSTOM_CURVES
  27341. if (dp != NULL) {
  27342. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27343. if (ret != 0)
  27344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27345. }
  27346. #endif
  27347. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27348. if (ret != 0)
  27349. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27350. #ifdef HAVE_ECC_DHE
  27351. y = ECC_SHARED_SIZE;
  27352. do {
  27353. #if defined(WOLFSSL_ASYNC_CRYPT)
  27354. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27355. #endif
  27356. if (ret == 0)
  27357. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27358. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27359. if (ret != 0)
  27360. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27361. if (XMEMCMP(sharedA, sharedB, y))
  27362. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27363. TEST_SLEEP();
  27364. #endif /* HAVE_ECC_DHE */
  27365. #endif /* HAVE_COMP_KEY */
  27366. #endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A */
  27367. #endif /* !WC_NO_RNG */
  27368. #endif /* HAVE_ECC_KEY_IMPORT */
  27369. #endif /* HAVE_ECC_KEY_EXPORT */
  27370. /* For KCAPI cannot sign using generated ECDH key */
  27371. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27372. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC))
  27373. #ifdef HAVE_ECC_SIGN
  27374. /* some hardware doesn't support sign/verify of all zero digest */
  27375. #if !defined(WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST)
  27376. /* test DSA sign hash with zeros */
  27377. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27378. digest[i] = 0;
  27379. }
  27380. x = ECC_SIG_SIZE;
  27381. do {
  27382. #if defined(WOLFSSL_ASYNC_CRYPT)
  27383. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27384. #endif
  27385. if (ret == 0)
  27386. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng,
  27387. userA);
  27388. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27389. if (ret != 0)
  27390. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27391. TEST_SLEEP();
  27392. #ifdef HAVE_ECC_VERIFY
  27393. for (i=0; i<testVerifyCount; i++) {
  27394. verify = 0;
  27395. do {
  27396. #if defined(WOLFSSL_ASYNC_CRYPT)
  27397. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27398. #endif
  27399. if (ret == 0)
  27400. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE,
  27401. &verify, userA);
  27402. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27403. if (ret != 0)
  27404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27405. if (verify != 1)
  27406. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27407. TEST_SLEEP();
  27408. }
  27409. #endif /* HAVE_ECC_VERIFY */
  27410. #endif /* !WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST */
  27411. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  27412. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27413. digest[i] = (byte)i;
  27414. }
  27415. x = ECC_SIG_SIZE;
  27416. do {
  27417. #if defined(WOLFSSL_ASYNC_CRYPT)
  27418. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27419. #endif
  27420. if (ret == 0)
  27421. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  27422. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27423. if (ret != 0)
  27424. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27425. TEST_SLEEP();
  27426. #ifdef HAVE_ECC_VERIFY
  27427. for (i=0; i<testVerifyCount; i++) {
  27428. verify = 0;
  27429. do {
  27430. #if defined(WOLFSSL_ASYNC_CRYPT)
  27431. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27432. #endif
  27433. if (ret == 0)
  27434. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, userA);
  27435. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27436. if (ret != 0)
  27437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27438. if (verify != 1)
  27439. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27440. TEST_SLEEP();
  27441. }
  27442. #endif /* HAVE_ECC_VERIFY */
  27443. #endif /* HAVE_ECC_SIGN */
  27444. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT &&
  27445. * !WC_NO_RNG && !WOLFSSL_KCAPI_ECC) */
  27446. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  27447. !defined(WOLFSSL_ATECC508) && !defined(WOLFSSL_ATECC608A) && \
  27448. !defined(WOLFSSL_KCAPI_ECC)
  27449. x = ECC_KEY_EXPORT_BUF_SIZE;
  27450. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  27451. if (ret != 0)
  27452. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27453. #elif defined(HAVE_ECC_KEY_EXPORT)
  27454. (void)exportBuf;
  27455. #endif /* HAVE_ECC_KEY_EXPORT */
  27456. done:
  27457. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27458. if (userA != NULL) {
  27459. wc_ecc_free(userA);
  27460. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27461. }
  27462. if (userB != NULL) {
  27463. wc_ecc_free(userB);
  27464. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27465. }
  27466. if (pubKey != NULL) {
  27467. wc_ecc_free(pubKey);
  27468. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27469. }
  27470. #else
  27471. wc_ecc_free(pubKey);
  27472. wc_ecc_free(userB);
  27473. wc_ecc_free(userA);
  27474. #endif
  27475. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  27476. WC_FREE_VAR(sharedA, HEAP_HINT);
  27477. WC_FREE_VAR(sharedB, HEAP_HINT);
  27478. #endif
  27479. #ifdef HAVE_ECC_KEY_EXPORT
  27480. WC_FREE_VAR(exportBuf, HEAP_HINT);
  27481. #endif
  27482. #ifdef HAVE_ECC_SIGN
  27483. WC_FREE_VAR(sig, HEAP_HINT);
  27484. WC_FREE_VAR(digest, HEAP_HINT);
  27485. #endif
  27486. (void)keySize;
  27487. (void)curve_id;
  27488. (void)rng;
  27489. return ret;
  27490. }
  27491. #undef ECC_TEST_VERIFY_COUNT
  27492. #define ECC_TEST_VERIFY_COUNT 2
  27493. static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
  27494. {
  27495. wc_test_ret_t ret;
  27496. WOLFSSL_MSG_EX("ecc_test_curve keySize = %d", keySize);
  27497. #if FIPS_VERSION3_GE(6,0,0)
  27498. #ifdef DEBUG_WOLFSSL
  27499. printf("keySize is %d\n", keySize);
  27500. #endif
  27501. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27502. goto skip_A;
  27503. }
  27504. #endif
  27505. ret = ecc_test_curve_size(rng, keySize, ECC_TEST_VERIFY_COUNT, curve_id,
  27506. NULL);
  27507. if (ret < 0) {
  27508. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27509. /* ignore error for curves not found */
  27510. /* some curve sizes are only available with:
  27511. HAVE_ECC_SECPR2, HAVE_ECC_SECPR3, HAVE_ECC_BRAINPOOL
  27512. and HAVE_ECC_KOBLITZ */
  27513. }
  27514. else {
  27515. printf("ecc_test_curve_size %d failed!\n", keySize);
  27516. return ret;
  27517. }
  27518. }
  27519. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27520. #if FIPS_VERSION3_GE(6,0,0)
  27521. skip_A:
  27522. #endif
  27523. #ifdef HAVE_ECC_VECTOR_TEST
  27524. ret = ecc_test_vector(keySize);
  27525. if (ret < 0) {
  27526. printf("ecc_test_vector %d failed!\n", keySize);
  27527. return ret;
  27528. }
  27529. #endif
  27530. #if FIPS_VERSION3_GE(6,0,0)
  27531. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27532. goto skip_B;
  27533. }
  27534. #endif
  27535. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27536. !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27537. ret = ecc_test_key_decode(rng, keySize);
  27538. if (ret < 0) {
  27539. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27540. /* ignore error for curves not found */
  27541. }
  27542. else {
  27543. printf("ecc_test_key_decode %d failed!\n", keySize);
  27544. return ret;
  27545. }
  27546. }
  27547. #endif
  27548. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27549. ret = ecc_test_key_gen(rng, keySize);
  27550. if (ret < 0) {
  27551. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27552. /* ignore error for curves not found */
  27553. }
  27554. else {
  27555. printf("ecc_test_key_gen %d failed!\n", keySize);
  27556. return ret;
  27557. }
  27558. }
  27559. #endif
  27560. #if FIPS_VERSION3_GE(6,0,0)
  27561. skip_B:
  27562. #endif
  27563. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  27564. return 0;
  27565. }
  27566. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  27567. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  27568. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27569. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27570. static wc_test_ret_t ecc_point_test(void)
  27571. {
  27572. wc_test_ret_t ret;
  27573. ecc_point* point;
  27574. ecc_point* point2;
  27575. #ifdef HAVE_COMP_KEY
  27576. ecc_point* point3;
  27577. ecc_point* point4;
  27578. #endif
  27579. word32 outLen;
  27580. byte out[65];
  27581. byte der[] = { 0x04, /* = Uncompressed */
  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. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27586. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27587. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27588. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27589. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27590. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27591. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27592. byte derComp0[] = { 0x02, /* = Compressed, y even */
  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. byte derComp1[] = { 0x03, /* = Compressed, y odd */
  27598. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27599. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27600. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27601. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27602. #endif
  27603. byte altDer[] = { 0x04, /* = Uncompressed */
  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. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27608. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27609. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27610. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27611. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  27612. int curve_idx = wc_ecc_get_curve_idx(ECC_SECP256R1);
  27613. /* if curve P256 is not enabled then test should not fail */
  27614. if (curve_idx == ECC_CURVE_INVALID)
  27615. return 0;
  27616. outLen = sizeof(out);
  27617. point = wc_ecc_new_point();
  27618. if (point == NULL)
  27619. return WC_TEST_RET_ENC_ERRNO;
  27620. point2 = wc_ecc_new_point();
  27621. if (point2 == NULL) {
  27622. wc_ecc_del_point(point);
  27623. return WC_TEST_RET_ENC_NC;
  27624. }
  27625. #ifdef HAVE_COMP_KEY
  27626. point3 = wc_ecc_new_point();
  27627. if (point3 == NULL) {
  27628. wc_ecc_del_point(point2);
  27629. wc_ecc_del_point(point);
  27630. return WC_TEST_RET_ENC_NC;
  27631. }
  27632. point4 = wc_ecc_new_point();
  27633. if (point4 == NULL) {
  27634. wc_ecc_del_point(point3);
  27635. wc_ecc_del_point(point2);
  27636. wc_ecc_del_point(point);
  27637. return WC_TEST_RET_ENC_NC;
  27638. }
  27639. #endif
  27640. /* Parameter Validation testing. */
  27641. wc_ecc_del_point(NULL);
  27642. ret = wc_ecc_import_point_der(NULL, sizeof(der), curve_idx, 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), ECC_CURVE_INVALID, point);
  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_import_point_der(der, sizeof(der), curve_idx, NULL);
  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(-1, point, 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, NULL, out, &outLen);
  27663. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27664. ret = WC_TEST_RET_ENC_EC(ret);
  27665. goto done;
  27666. }
  27667. ret = wc_ecc_export_point_der(curve_idx, point, NULL, &outLen);
  27668. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || outLen != sizeof(out)) {
  27669. ret = WC_TEST_RET_ENC_EC(ret);
  27670. goto done;
  27671. }
  27672. ret = wc_ecc_export_point_der(curve_idx, point, out, NULL);
  27673. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27674. ret = WC_TEST_RET_ENC_EC(ret);
  27675. goto done;
  27676. }
  27677. outLen = 0;
  27678. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27679. if (ret != WC_NO_ERR_TRACE(BUFFER_E)) {
  27680. ret = WC_TEST_RET_ENC_EC(ret);
  27681. goto done;
  27682. }
  27683. ret = wc_ecc_copy_point(NULL, NULL);
  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(NULL, point2);
  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_copy_point(point, NULL);
  27694. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27695. ret = WC_TEST_RET_ENC_EC(ret);
  27696. goto done;
  27697. }
  27698. ret = wc_ecc_cmp_point(NULL, NULL);
  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(NULL, point2);
  27704. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27705. ret = WC_TEST_RET_ENC_EC(ret);
  27706. goto done;
  27707. }
  27708. ret = wc_ecc_cmp_point(point, NULL);
  27709. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27710. ret = WC_TEST_RET_ENC_EC(ret);
  27711. goto done;
  27712. }
  27713. /* Use API. */
  27714. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, point);
  27715. if (ret != 0)
  27716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27717. outLen = sizeof(out);
  27718. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27719. if (ret != 0)
  27720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27721. if (outLen != sizeof(der)) {
  27722. ret = WC_TEST_RET_ENC_NC;
  27723. goto done;
  27724. }
  27725. if (XMEMCMP(out, der, outLen) != 0) {
  27726. ret = WC_TEST_RET_ENC_NC;
  27727. goto done;
  27728. }
  27729. ret = wc_ecc_copy_point(point2, point);
  27730. if (ret != MP_OKAY) {
  27731. ret = WC_TEST_RET_ENC_EC(ret);
  27732. goto done;
  27733. }
  27734. ret = wc_ecc_cmp_point(point2, point);
  27735. if (ret != MP_EQ) {
  27736. ret = WC_TEST_RET_ENC_EC(ret);
  27737. goto done;
  27738. }
  27739. ret = wc_ecc_import_point_der(altDer, sizeof(altDer), curve_idx, point2);
  27740. if (ret != 0)
  27741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27742. ret = wc_ecc_cmp_point(point2, point);
  27743. if (ret != MP_GT) {
  27744. ret = WC_TEST_RET_ENC_EC(ret);
  27745. goto done;
  27746. }
  27747. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27748. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27749. ret = wc_ecc_import_point_der(derComp0, sizeof(derComp0)*2-1, curve_idx, point3);
  27750. if (ret != 0)
  27751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27752. ret = wc_ecc_import_point_der_ex(derComp0, sizeof(derComp0), curve_idx, point4, 0);
  27753. if (ret != 0)
  27754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27755. ret = wc_ecc_cmp_point(point3, point4);
  27756. if (ret != MP_EQ) {
  27757. ret = WC_TEST_RET_ENC_EC(ret);
  27758. goto done;
  27759. }
  27760. ret = wc_ecc_import_point_der(derComp1, sizeof(derComp1)*2-1, curve_idx, point3);
  27761. if (ret != 0)
  27762. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27763. ret = wc_ecc_import_point_der_ex(derComp1, sizeof(derComp1), curve_idx, point4, 0);
  27764. if (ret != 0)
  27765. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27766. ret = wc_ecc_cmp_point(point3, point4);
  27767. if (ret != MP_EQ) {
  27768. ret = WC_TEST_RET_ENC_EC(ret);
  27769. goto done;
  27770. }
  27771. #endif
  27772. done:
  27773. #ifdef HAVE_COMP_KEY
  27774. wc_ecc_del_point(point4);
  27775. wc_ecc_del_point(point3);
  27776. #endif
  27777. wc_ecc_del_point(point2);
  27778. wc_ecc_del_point(point);
  27779. return ret;
  27780. }
  27781. #endif /* !WOLFSSL_ATECC508A && HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27782. #if !defined(NO_SIG_WRAPPER) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27783. static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key)
  27784. {
  27785. wc_test_ret_t ret;
  27786. word32 sigSz;
  27787. int size;
  27788. byte out[ECC_MAX_SIG_SIZE];
  27789. byte in[] = TEST_STRING;
  27790. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  27791. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  27792. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  27793. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  27794. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  27795. };
  27796. word32 inLen = (word32)XSTRLEN((char*)in);
  27797. size = wc_ecc_sig_size(key);
  27798. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, sizeof(*key));
  27799. if (ret != size)
  27800. return WC_TEST_RET_ENC_NC;
  27801. sigSz = (word32)ret;
  27802. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27803. inLen, out, &sigSz, key, sizeof(*key), rng);
  27804. if (ret != 0)
  27805. return WC_TEST_RET_ENC_EC(ret);
  27806. TEST_SLEEP();
  27807. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27808. inLen, out, sigSz, key, sizeof(*key));
  27809. if (ret != 0)
  27810. return WC_TEST_RET_ENC_EC(ret);
  27811. TEST_SLEEP();
  27812. sigSz = (word32)sizeof(out);
  27813. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27814. hash, (int)sizeof(hash), out, &sigSz, key, sizeof(*key), rng);
  27815. if (ret != 0)
  27816. return WC_TEST_RET_ENC_EC(ret);
  27817. TEST_SLEEP();
  27818. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27819. hash, (int)sizeof(hash), out, sigSz, key, sizeof(*key));
  27820. if (ret != 0)
  27821. return WC_TEST_RET_ENC_EC(ret);
  27822. TEST_SLEEP();
  27823. return 0;
  27824. }
  27825. #endif
  27826. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27827. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27828. static wc_test_ret_t ecc_exp_imp_test(ecc_key* key)
  27829. {
  27830. wc_test_ret_t ret;
  27831. int curve_id;
  27832. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27833. ecc_key *keyImp = (ecc_key *)XMALLOC(sizeof *keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27834. #else
  27835. ecc_key keyImp[1];
  27836. #endif
  27837. byte priv[32];
  27838. word32 privLen;
  27839. byte pub[65*2];
  27840. word32 pubLen, pubLenX, pubLenY;
  27841. const char qx[] = "7a4e287890a1a47ad3457e52f2f76a83"
  27842. "ce46cbc947616d0cbaa82323818a793d";
  27843. const char qy[] = "eec4084f5b29ebf29c44cce3b3059610"
  27844. "922f8b30ea6e8811742ac7238fe87308";
  27845. const char d[] = "8c14b793cb19137e323a6d2e2a870bca"
  27846. "2e7a493ec1153b3a95feb8a4873f8d08";
  27847. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27848. if (keyImp == NULL)
  27849. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27850. #endif
  27851. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27852. privLen = sizeof(priv);
  27853. ret = wc_ecc_export_private_only(key, priv, &privLen);
  27854. if (ret != 0)
  27855. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27856. pubLen = sizeof(pub);
  27857. ret = wc_ecc_export_point_der(key->idx, &key->pubkey, pub, &pubLen);
  27858. if (ret != 0)
  27859. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27860. ret = wc_ecc_import_private_key(priv, privLen, pub, pubLen, keyImp);
  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. ret = wc_ecc_import_raw_ex(keyImp, qx, qy, d, ECC_SECP256R1);
  27866. if (ret != 0)
  27867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27868. wc_ecc_free(keyImp);
  27869. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27870. curve_id = wc_ecc_get_curve_id(key->idx);
  27871. if (curve_id < 0) {
  27872. ret = WC_TEST_RET_ENC_EC(curve_id);
  27873. goto done;
  27874. }
  27875. /* test import private only */
  27876. ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, keyImp,
  27877. curve_id);
  27878. if (ret != 0)
  27879. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27880. wc_ecc_free(keyImp);
  27881. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27882. /* test export public raw */
  27883. pubLenX = pubLenY = 32;
  27884. ret = wc_ecc_export_public_raw(key, pub, &pubLenX, &pub[32], &pubLenY);
  27885. if (ret != 0)
  27886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27887. #ifndef HAVE_SELFTEST
  27888. /* test import of public */
  27889. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], NULL, ECC_SECP256R1);
  27890. if (ret != 0)
  27891. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27892. #endif
  27893. wc_ecc_free(keyImp);
  27894. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27895. /* test export private and public raw */
  27896. pubLenX = pubLenY = privLen = 32;
  27897. ret = wc_ecc_export_private_raw(key, pub, &pubLenX, &pub[32], &pubLenY,
  27898. priv, &privLen);
  27899. if (ret != 0)
  27900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27901. #ifndef HAVE_SELFTEST
  27902. /* test import of private and public */
  27903. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], priv, ECC_SECP256R1);
  27904. if (ret != 0)
  27905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27906. #endif
  27907. done:
  27908. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27909. if (keyImp != NULL) {
  27910. wc_ecc_free(keyImp);
  27911. XFREE(keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27912. }
  27913. #else
  27914. wc_ecc_free(keyImp);
  27915. #endif
  27916. return ret;
  27917. }
  27918. #endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27919. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  27920. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27921. static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
  27922. {
  27923. wc_test_ret_t ret;
  27924. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27925. ecc_key *key2 = (ecc_key *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27926. ecc_key *key3 = (ecc_key *)XMALLOC(sizeof *key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27927. #else
  27928. ecc_key key2[1];
  27929. ecc_key key3[1];
  27930. #endif
  27931. #ifdef WOLFSSL_PUBLIC_MP
  27932. mp_int* priv;
  27933. #endif
  27934. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27935. if ((key2 == NULL) || (key3 == NULL))
  27936. ERROR_OUT(MEMORY_E, done);
  27937. #endif
  27938. wc_ecc_init_ex(key2, HEAP_HINT, devId);
  27939. wc_ecc_init_ex(key3, HEAP_HINT, devId);
  27940. /* TODO: Use test data, test with WOLFSSL_VALIDATE_ECC_IMPORT. */
  27941. /* Need base point (Gx,Gy) and parameter A - load them as the public and
  27942. * private key in key2.
  27943. */
  27944. ret = wc_ecc_import_raw_ex(key2, key1->dp->Gx, key1->dp->Gy, key1->dp->Af,
  27945. ECC_SECP256R1);
  27946. if (ret != 0)
  27947. goto done;
  27948. /* Need a point (Gx,Gy) and prime - load them as the public and private key
  27949. * in key3.
  27950. */
  27951. ret = wc_ecc_import_raw_ex(key3, key1->dp->Gx, key1->dp->Gy,
  27952. key1->dp->prime, ECC_SECP256R1);
  27953. if (ret != 0)
  27954. goto done;
  27955. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27956. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27957. 1);
  27958. if (ret != 0)
  27959. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27960. #ifdef WOLFSSL_PUBLIC_MP
  27961. priv = wc_ecc_key_get_priv(key1);
  27962. mp_zero(priv);
  27963. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27964. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27965. 1);
  27966. if (ret != 0)
  27967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27968. if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
  27969. ret = WC_TEST_RET_ENC_EC(ret);
  27970. goto done;
  27971. }
  27972. if (mp_cmp_d(key3->pubkey.z, 1) != MP_EQ) {
  27973. ret = WC_TEST_RET_ENC_EC(ret);
  27974. goto done;
  27975. }
  27976. #endif
  27977. done:
  27978. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27979. if (key2 != NULL) {
  27980. wc_ecc_free(key2);
  27981. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27982. }
  27983. if (key3 != NULL) {
  27984. wc_ecc_free(key3);
  27985. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27986. }
  27987. #else
  27988. wc_ecc_free(key3);
  27989. wc_ecc_free(key2);
  27990. #endif
  27991. return ret;
  27992. }
  27993. #endif
  27994. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27995. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_ATECC508A) && \
  27996. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  27997. !defined(WOLFSSL_CRYPTOCELL)
  27998. static wc_test_ret_t ecc_ssh_test(ecc_key* key, WC_RNG* rng)
  27999. {
  28000. wc_test_ret_t ret;
  28001. byte out[128];
  28002. word32 outLen = sizeof(out);
  28003. /* Parameter Validation testing. */
  28004. ret = wc_ecc_shared_secret_ssh(NULL, &key->pubkey, out, &outLen);
  28005. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28006. return WC_TEST_RET_ENC_EC(ret);
  28007. ret = wc_ecc_shared_secret_ssh(key, NULL, out, &outLen);
  28008. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28009. return WC_TEST_RET_ENC_EC(ret);
  28010. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, NULL, &outLen);
  28011. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28012. return WC_TEST_RET_ENC_EC(ret);
  28013. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, NULL);
  28014. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28015. return WC_TEST_RET_ENC_EC(ret);
  28016. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  28017. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  28018. !defined(HAVE_SELFTEST)
  28019. ret = wc_ecc_set_rng(key, rng);
  28020. if (ret != 0)
  28021. return WC_TEST_RET_ENC_EC(ret);
  28022. #else
  28023. (void)rng;
  28024. #endif
  28025. /* Use API. */
  28026. ret = 0;
  28027. do {
  28028. #if defined(WOLFSSL_ASYNC_CRYPT)
  28029. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  28030. #endif
  28031. if (ret == 0)
  28032. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen);
  28033. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  28034. if (ret != 0)
  28035. return WC_TEST_RET_ENC_EC(ret);
  28036. TEST_SLEEP();
  28037. return 0;
  28038. }
  28039. #endif /* HAVE_ECC_DHE && !WC_NO_RNG */
  28040. static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
  28041. {
  28042. wc_test_ret_t ret;
  28043. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28044. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28045. #else
  28046. ecc_key key[1];
  28047. #endif
  28048. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28049. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28050. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28051. word32 idx = 0;
  28052. #endif
  28053. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28054. if (key == NULL)
  28055. ERROR_OUT(MEMORY_E, done);
  28056. #endif
  28057. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28058. /* Use API */
  28059. ret = wc_ecc_set_flags(NULL, 0);
  28060. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28061. ret = WC_TEST_RET_ENC_EC(ret);
  28062. goto done;
  28063. }
  28064. ret = wc_ecc_set_flags(key, 0);
  28065. if (ret != 0)
  28066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28067. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  28068. #ifndef WC_NO_RNG
  28069. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  28070. #if defined(WOLFSSL_ASYNC_CRYPT)
  28071. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  28072. #endif
  28073. if (ret != 0) {
  28074. goto done;
  28075. }
  28076. #ifndef NO_SIG_WRAPPER
  28077. ret = ecc_sig_test(rng, key);
  28078. if (ret < 0)
  28079. goto done;
  28080. #endif
  28081. TEST_SLEEP();
  28082. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_CRYPTOCELL) && \
  28083. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  28084. ret = ecc_ssh_test(key, rng);
  28085. if (ret < 0)
  28086. goto done;
  28087. #endif
  28088. wc_ecc_free(key);
  28089. #else
  28090. (void)rng;
  28091. #endif /* !WC_NO_RNG */
  28092. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28093. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28094. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28095. /* Use test ECC key - ensure real private "d" exists */
  28096. #if defined(USE_CERT_BUFFERS_256)
  28097. {
  28098. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  28099. sizeof_ecc_key_der_256);
  28100. }
  28101. #elif !defined(NO_FILESYSTEM)
  28102. {
  28103. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  28104. byte der[128];
  28105. word32 derSz;
  28106. if (!file) {
  28107. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28108. }
  28109. derSz = (word32)XFREAD(der, 1, sizeof(der), file);
  28110. XFCLOSE(file);
  28111. if (derSz == 0)
  28112. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28113. ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
  28114. }
  28115. #else
  28116. {
  28117. (void)idx;
  28118. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
  28119. ERROR_OUT(ASN_PARSE_E, done);
  28120. }
  28121. #endif
  28122. if (ret != 0) {
  28123. goto done;
  28124. }
  28125. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)
  28126. ret = ecc_exp_imp_test(key);
  28127. if (ret < 0)
  28128. goto done;
  28129. #endif
  28130. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  28131. !defined(WOLFSSL_CRYPTOCELL)
  28132. ret = ecc_mulmod_test(key);
  28133. if (ret < 0)
  28134. goto done;
  28135. #endif
  28136. #endif
  28137. #else
  28138. (void)rng;
  28139. (void)idx;
  28140. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  28141. done:
  28142. wc_ecc_free(key);
  28143. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28144. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28145. #endif
  28146. return ret;
  28147. }
  28148. #endif /* !NO_ECC256 || HAVE_ALL_CURVES */
  28149. #if defined(WOLFSSL_CERT_EXT) && \
  28150. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  28151. static wc_test_ret_t ecc_decode_test(void)
  28152. {
  28153. wc_test_ret_t ret;
  28154. word32 inSz;
  28155. word32 inOutIdx;
  28156. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28157. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28158. #else
  28159. ecc_key key[1];
  28160. #endif
  28161. /* SECP256R1 OID: 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 */
  28162. /* This is ecc_clikeypub_der_256. */
  28163. WOLFSSL_SMALL_STACK_STATIC const byte good[] = {
  28164. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  28165. 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  28166. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xbf, 0xf4,
  28167. 0x0f, 0x44, 0x50, 0x9a, 0x3d, 0xce, 0x9b, 0xb7, 0xf0, 0xc5,
  28168. 0x4d, 0xf5, 0x70, 0x7b, 0xd4, 0xec, 0x24, 0x8e, 0x19, 0x80,
  28169. 0xec, 0x5a, 0x4c, 0xa2, 0x24, 0x03, 0x62, 0x2c, 0x9b, 0xda,
  28170. 0xef, 0xa2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xc6, 0x56,
  28171. 0x95, 0x06, 0xcc, 0x01, 0xa9, 0xbd, 0xf6, 0x75, 0x1a, 0x42,
  28172. 0xf7, 0xbd, 0xa9, 0xb2, 0x36, 0x22, 0x5f, 0xc7, 0x5d, 0x7f,
  28173. 0xb4 };
  28174. WOLFSSL_SMALL_STACK_STATIC const byte badNoObjId[] = { 0x30, 0x08, 0x30, 0x06, 0x03, 0x04,
  28175. 0x00, 0x04, 0x01, 0x01 };
  28176. WOLFSSL_SMALL_STACK_STATIC const byte badOneObjId[] = { 0x30, 0x0a, 0x30, 0x08, 0x06, 0x00,
  28177. 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28178. WOLFSSL_SMALL_STACK_STATIC const byte badObjId1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x09,
  28179. 0x06, 0x00, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28180. WOLFSSL_SMALL_STACK_STATIC const byte badObj2d1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
  28181. 0x06, 0x07, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28182. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitStr[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28183. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28184. 0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28185. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrLen[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28186. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28187. 0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
  28188. WOLFSSL_SMALL_STACK_STATIC const byte badNoBitStrZero[] = { 0x30, 0x13, 0x30, 0x0a, 0x06, 0x00,
  28189. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28190. 0x03, 0x03, 0x04, 0x01, 0x01 };
  28191. WOLFSSL_SMALL_STACK_STATIC const byte badPoint[] = { 0x30, 0x12, 0x30, 0x09, 0x06, 0x00,
  28192. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28193. 0x03, 0x03, 0x00, 0x04, 0x01 };
  28194. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28195. if (key == NULL)
  28196. ERROR_OUT(MEMORY_E, done);
  28197. #endif
  28198. XMEMSET(key, 0, sizeof *key);
  28199. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28200. inSz = sizeof(good);
  28201. ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, 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, NULL, key, 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, NULL, inSz);
  28212. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28213. ret = WC_TEST_RET_ENC_EC(ret);
  28214. goto done;
  28215. }
  28216. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, 0);
  28217. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28218. ret = WC_TEST_RET_ENC_EC(ret);
  28219. goto done;
  28220. }
  28221. /* Change offset to produce bad input data. */
  28222. inOutIdx = 2;
  28223. inSz = sizeof(good) - inOutIdx;
  28224. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28225. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28226. ret = WC_TEST_RET_ENC_EC(ret);
  28227. goto done;
  28228. }
  28229. inOutIdx = 4;
  28230. inSz = sizeof(good) - inOutIdx;
  28231. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28232. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28233. ret = WC_TEST_RET_ENC_EC(ret);
  28234. goto done;
  28235. }
  28236. /* Bad data. */
  28237. inSz = sizeof(badNoObjId);
  28238. inOutIdx = 0;
  28239. ret = wc_EccPublicKeyDecode(badNoObjId, &inOutIdx, key, inSz);
  28240. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28241. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28242. {
  28243. ret = WC_TEST_RET_ENC_EC(ret);
  28244. goto done;
  28245. }
  28246. inSz = sizeof(badOneObjId);
  28247. inOutIdx = 0;
  28248. ret = wc_EccPublicKeyDecode(badOneObjId, &inOutIdx, key, inSz);
  28249. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28250. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28251. {
  28252. ret = WC_TEST_RET_ENC_EC(ret);
  28253. goto done;
  28254. }
  28255. inSz = sizeof(badObjId1Len);
  28256. inOutIdx = 0;
  28257. ret = wc_EccPublicKeyDecode(badObjId1Len, &inOutIdx, key, inSz);
  28258. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28259. ret = WC_TEST_RET_ENC_EC(ret);
  28260. goto done;
  28261. }
  28262. inSz = sizeof(badObj2d1Len);
  28263. inOutIdx = 0;
  28264. ret = wc_EccPublicKeyDecode(badObj2d1Len, &inOutIdx, key, inSz);
  28265. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28266. ret = WC_TEST_RET_ENC_EC(ret);
  28267. goto done;
  28268. }
  28269. inSz = sizeof(badNotBitStr);
  28270. inOutIdx = 0;
  28271. ret = wc_EccPublicKeyDecode(badNotBitStr, &inOutIdx, key, inSz);
  28272. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E) &&
  28273. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28274. {
  28275. ret = WC_TEST_RET_ENC_EC(ret);
  28276. goto done;
  28277. }
  28278. inSz = sizeof(badBitStrLen);
  28279. inOutIdx = 0;
  28280. ret = wc_EccPublicKeyDecode(badBitStrLen, &inOutIdx, key, inSz);
  28281. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28282. ret = WC_TEST_RET_ENC_EC(ret);
  28283. goto done;
  28284. }
  28285. inSz = sizeof(badNoBitStrZero);
  28286. inOutIdx = 0;
  28287. ret = wc_EccPublicKeyDecode(badNoBitStrZero, &inOutIdx, key, inSz);
  28288. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  28289. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28290. {
  28291. ret = WC_TEST_RET_ENC_EC(ret);
  28292. goto done;
  28293. }
  28294. inSz = sizeof(badPoint);
  28295. inOutIdx = 0;
  28296. ret = wc_EccPublicKeyDecode(badPoint, &inOutIdx, key, inSz);
  28297. if (ret != WC_NO_ERR_TRACE(ASN_ECC_KEY_E) &&
  28298. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28299. {
  28300. ret = WC_TEST_RET_ENC_EC(ret);
  28301. goto done;
  28302. }
  28303. inSz = sizeof(good);
  28304. inOutIdx = 0;
  28305. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28306. if (ret != 0)
  28307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28308. done:
  28309. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28310. if (key != NULL) {
  28311. wc_ecc_free(key);
  28312. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28313. }
  28314. #else
  28315. wc_ecc_free(key);
  28316. #endif
  28317. return ret;
  28318. }
  28319. #endif /* WOLFSSL_CERT_EXT */
  28320. #ifdef WOLFSSL_CUSTOM_CURVES
  28321. static const byte eccKeyExplicitCurve[] = {
  28322. 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07,
  28323. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  28324. 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  28325. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  28326. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  28327. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28328. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28329. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  28330. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  28331. 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe,
  28332. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  28333. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  28334. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  28335. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
  28336. 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4,
  28337. 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17,
  28338. 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47,
  28339. 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21,
  28340. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28341. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28342. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  28343. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  28344. 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04,
  28345. 0x3c, 0x4c, 0xc9, 0x5e, 0x2e, 0xa2, 0x3d, 0x49,
  28346. 0xcc, 0x5b, 0xff, 0x4f, 0xc9, 0x2e, 0x1d, 0x4a,
  28347. 0xc6, 0x21, 0xf6, 0xf3, 0xe6, 0x0b, 0x4f, 0xa9,
  28348. 0x9d, 0x74, 0x99, 0xdd, 0x97, 0xc7, 0x6e, 0xbe,
  28349. 0x14, 0x2b, 0x39, 0x9d, 0x63, 0xc7, 0x97, 0x0d,
  28350. 0x45, 0x25, 0x40, 0x30, 0x77, 0x05, 0x76, 0x88,
  28351. 0x38, 0x96, 0x29, 0x7d, 0x9c, 0xe1, 0x50, 0xbe,
  28352. 0xac, 0xf0, 0x1d, 0x86, 0xf4, 0x2f, 0x65, 0x0b
  28353. };
  28354. static wc_test_ret_t ecc_test_custom_curves(WC_RNG* rng)
  28355. {
  28356. wc_test_ret_t ret;
  28357. word32 inOutIdx;
  28358. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28359. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28360. #else
  28361. ecc_key key[1];
  28362. #endif
  28363. /* test use of custom curve - using BRAINPOOLP256R1 for test */
  28364. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28365. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28366. WOLFSSL_SMALL_STACK_STATIC const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
  28367. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
  28368. };
  28369. #define ecc_oid_brainpoolp256r1_sz \
  28370. (sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t))
  28371. #else
  28372. #define ecc_oid_brainpoolp256r1 { \
  28373. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 \
  28374. }
  28375. #define ecc_oid_brainpoolp256r1_sz 9
  28376. #endif
  28377. #define ecc_oid_brainpoolp256r1_sum 104
  28378. WOLFSSL_SMALL_STACK_STATIC const ecc_set_type ecc_dp_brainpool256r1 = {
  28379. 32, /* size/bytes */
  28380. ECC_CURVE_CUSTOM, /* ID */
  28381. "BRAINPOOLP256R1", /* curve name */
  28382. "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
  28383. "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
  28384. "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", /* B */
  28385. "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", /* order */
  28386. "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", /* Gx */
  28387. "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
  28388. ecc_oid_brainpoolp256r1, /* oid/oidSz */
  28389. ecc_oid_brainpoolp256r1_sz,
  28390. ecc_oid_brainpoolp256r1_sum, /* oid sum */
  28391. 1, /* cofactor */
  28392. };
  28393. #endif /* HAVE_ECC_BRAINPOOL */
  28394. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28395. if (! key) {
  28396. ret = MEMORY_E;
  28397. goto done;
  28398. }
  28399. #endif
  28400. XMEMSET(key, 0, sizeof *key);
  28401. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28402. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, ECC_CURVE_DEF,
  28403. &ecc_dp_brainpool256r1);
  28404. if (ret != 0) {
  28405. printf("ECC test for custom curve failed!\n");
  28406. goto done;
  28407. }
  28408. #endif
  28409. #if defined(HAVE_ECC_BRAINPOOL) || defined(HAVE_ECC_KOBLITZ)
  28410. {
  28411. int curve_id;
  28412. #ifdef HAVE_ECC_BRAINPOOL
  28413. curve_id = ECC_BRAINPOOLP256R1;
  28414. #else
  28415. curve_id = ECC_SECP256K1;
  28416. #endif
  28417. /* Test and demonstrate use of non-SECP curve */
  28418. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, curve_id, NULL);
  28419. if (ret < 0) {
  28420. printf("ECC test for curve_id %d failed!\n", curve_id);
  28421. goto done;
  28422. }
  28423. }
  28424. #endif
  28425. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  28426. if (ret != 0)
  28427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28428. inOutIdx = 0;
  28429. ret = wc_EccPublicKeyDecode(eccKeyExplicitCurve, &inOutIdx, key,
  28430. sizeof(eccKeyExplicitCurve));
  28431. if (ret != 0)
  28432. ret = WC_TEST_RET_ENC_EC(ret);
  28433. done:
  28434. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28435. if (key) {
  28436. wc_ecc_free(key);
  28437. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28438. }
  28439. #else
  28440. wc_ecc_free(key);
  28441. #endif
  28442. (void)rng;
  28443. return ret;
  28444. }
  28445. #endif /* WOLFSSL_CUSTOM_CURVES */
  28446. #ifdef WOLFSSL_SM2
  28447. #ifdef HAVE_ECC_VERIFY
  28448. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28449. #ifdef HAVE_OID_ENCODING
  28450. #define CODED_SM2P256V1 {1,2,156,10197,1,301}
  28451. #define CODED_SM2P256V1_SZ 6
  28452. #else
  28453. #define CODED_SM2P256V1 {0x06,0x08,0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D}
  28454. #define CODED_SM2P256V1_SZ 10
  28455. #endif
  28456. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28457. static const ecc_oid_t ecc_oid_sm2p256v1[] = CODED_SM2P256V1;
  28458. #else
  28459. #define ecc_oid_sm2p256v1 CODED_SM2P256V1
  28460. #endif
  28461. #define ecc_oid_sm2p256v1_sz CODED_SM2P256V1_SZ
  28462. #define ECC_SM2P256V1_TEST 102
  28463. static int test_sm2_verify_caseA2(void)
  28464. {
  28465. ecc_key key;
  28466. int ret, res;
  28467. mp_int r,s;
  28468. /* test key values */
  28469. const char qx[] = "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A";
  28470. const char qy[] = "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857";
  28471. const char d[] = "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263";
  28472. const ecc_set_type ecc_sm2_A2 = {
  28473. 32, /* size/bytes */
  28474. ECC_SM2P256V1_TEST, /* ID */
  28475. "SM2P256V1_TEST", /* curve name */
  28476. /* from test case A.2 in draft-shen-sm2-ecdsa-02 */
  28477. "8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", /* prime */
  28478. "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", /* A */
  28479. "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", /* B */
  28480. "8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", /* order n */
  28481. "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", /* Gx */
  28482. "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", /* Gy */
  28483. ecc_oid_sm2p256v1, /* oid/oidSz */
  28484. ecc_oid_sm2p256v1_sz,
  28485. ECC_SM2P256V1_OID, /* oid sum */
  28486. 1, /* cofactor */
  28487. };
  28488. /* use canned hash value hash = H(ZA||M) */
  28489. const byte hash[] = {
  28490. 0xB5,0x24,0xF5,0x52,0xCD,0x82,0xB8,0xB0,
  28491. 0x28,0x47,0x6E,0x00,0x5C,0x37,0x7F,0xB1,
  28492. 0x9A,0x87,0xE6,0xFC,0x68,0x2D,0x48,0xBB,
  28493. 0x5D,0x42,0xE3,0xD9,0xB9,0xEF,0xFE,0x76
  28494. };
  28495. /* canned r and s */
  28496. const byte rCan[] = {
  28497. 0x40,0xF1,0xEC,0x59,0xF7,0x93,0xD9,0xF4,
  28498. 0x9E,0x09,0xDC,0xEF,0x49,0x13,0x0D,0x41,
  28499. 0x94,0xF7,0x9F,0xB1,0xEE,0xD2,0xCA,0xA5,
  28500. 0x5B,0xAC,0xDB,0x49,0xC4,0xE7,0x55,0xD1
  28501. };
  28502. const byte sCan[] = {
  28503. 0x6F,0xC6,0xDA,0xC3,0x2C,0x5D,0x5C,0xF1,
  28504. 0x0C,0x77,0xDF,0xB2,0x0F,0x7C,0x2E,0xB6,
  28505. 0x67,0xA4,0x57,0x87,0x2F,0xB0,0x9E,0xC5,
  28506. 0x63,0x27,0xA6,0x7E,0xC7,0xDE,0xEB,0xE7
  28507. };
  28508. mp_init(&r);
  28509. mp_init(&s);
  28510. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28511. if (ret != 0)
  28512. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28513. ret = wc_ecc_set_custom_curve(&key, &ecc_sm2_A2);
  28514. if (ret != 0)
  28515. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28516. ret = wc_ecc_import_raw_ex(&key, qx, qy, d, ECC_SM2P256V1_TEST);
  28517. if (ret != 0)
  28518. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28519. mp_read_unsigned_bin(&r, rCan, sizeof(rCan));
  28520. mp_read_unsigned_bin(&s, sCan, sizeof(sCan));
  28521. ret = wc_ecc_sm2_verify_hash_ex(&r, &s, hash, sizeof(hash), &res, &key);
  28522. if (ret != 0)
  28523. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28524. if (res != 1)
  28525. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28526. done:
  28527. mp_free(&r);
  28528. mp_free(&s);
  28529. wc_ecc_free(&key);
  28530. return ret;
  28531. }
  28532. #endif /* WOLFSSL_PUBLIC_MP && WOLFSSL_CUSTOM_CURVES */
  28533. static int test_sm2_verify_case(void)
  28534. {
  28535. ecc_key key;
  28536. int ret, res;
  28537. /* test key values */
  28538. const char qx[] = "637F1B135036C933DC3F7A8EBB1B7B2FD1DFBD268D4F894B5AD47DBDBECD558F";
  28539. const char qy[] = "E88101D08048E36CCBF61CA38DDF7ABA542B4486E99E49F3A7470A857A096433";
  28540. /* use canned hash value hash = H(ZA||M) */
  28541. const byte hash[] = {
  28542. 0x3B,0xFA,0x5F,0xFB,0xC4,0x27,0x8C,0x9D,
  28543. 0x02,0x3A,0x19,0xCB,0x1E,0xAA,0xD2,0xF1,
  28544. 0x50,0x69,0x5B,0x20
  28545. };
  28546. const byte sig[] = {
  28547. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28548. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28549. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28550. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28551. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28552. 0xB5,0xB5,0xD9,0xD8,0xF1,0x20,0xDD,0x97,
  28553. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28554. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28555. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28556. };
  28557. const byte badSig[] = {
  28558. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28559. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28560. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28561. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28562. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28563. 0xB5,0xB5,0xE9,0xD8,0xF1,0x20,0xDD,0x97,
  28564. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28565. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28566. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28567. };
  28568. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28569. if (ret != 0)
  28570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28571. ret = wc_ecc_import_raw(&key, qx, qy, NULL, "SM2P256V1");
  28572. if (ret != 0)
  28573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28574. ret = wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash), &res,
  28575. &key);
  28576. if (ret != 0)
  28577. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28578. if (res != 1)
  28579. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28580. /* now test a case that should fail */
  28581. ret = wc_ecc_sm2_verify_hash(badSig, sizeof(badSig), hash, sizeof(hash),
  28582. &res, &key);
  28583. if (ret != 0)
  28584. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28585. if (res == 1)
  28586. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28587. done:
  28588. wc_ecc_free(&key);
  28589. return ret;
  28590. }
  28591. static int ecc_sm2_test_curve(WC_RNG* rng, int testVerifyCount)
  28592. {
  28593. const ecc_set_type* dp = wc_ecc_get_curve_params(
  28594. wc_ecc_get_curve_idx(ECC_SM2P256V1));
  28595. int keySize = 32;
  28596. int curve_id = ECC_SM2P256V1;
  28597. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28598. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28599. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28600. #endif
  28601. #ifdef HAVE_ECC_KEY_EXPORT
  28602. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  28603. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28604. #endif
  28605. word32 x = 0;
  28606. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28607. word32 y;
  28608. #endif
  28609. #ifdef HAVE_ECC_SIGN
  28610. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28611. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28612. int i;
  28613. int verify;
  28614. #endif /* HAVE_ECC_SIGN */
  28615. int ret;
  28616. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28617. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28618. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28619. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28620. #else
  28621. ecc_key userA[1];
  28622. ecc_key userB[1];
  28623. ecc_key pubKey[1];
  28624. #endif
  28625. #ifndef WC_NO_RNG
  28626. int curveSize;
  28627. #endif
  28628. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28629. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28630. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28631. #endif
  28632. #ifdef HAVE_ECC_KEY_EXPORT
  28633. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28634. #endif
  28635. #ifdef HAVE_ECC_SIGN
  28636. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28637. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28638. #endif
  28639. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  28640. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28641. if (sharedA == NULL || sharedB == NULL)
  28642. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28643. #endif
  28644. #ifdef HAVE_ECC_KEY_EXPORT
  28645. if (exportBuf == NULL)
  28646. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28647. #endif
  28648. #ifdef HAVE_ECC_SIGN
  28649. if (sig == NULL || digest == NULL)
  28650. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28651. #endif
  28652. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  28653. (void)testVerifyCount;
  28654. (void)dp;
  28655. (void)x;
  28656. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28657. if ((userA == NULL) ||
  28658. (userB == NULL) ||
  28659. (pubKey == NULL))
  28660. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28661. #endif
  28662. XMEMSET(userA, 0, sizeof *userA);
  28663. XMEMSET(userB, 0, sizeof *userB);
  28664. XMEMSET(pubKey, 0, sizeof *pubKey);
  28665. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  28666. if (ret != 0)
  28667. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28668. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  28669. if (ret != 0)
  28670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28671. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28672. if (ret != 0)
  28673. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28674. #ifndef WC_NO_RNG
  28675. ret = wc_ecc_sm2_make_key(rng, userA, WC_ECC_FLAG_NONE);
  28676. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  28677. goto done; /* catch case, where curve is not supported */
  28678. if (ret != 0)
  28679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28680. TEST_SLEEP();
  28681. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  28682. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  28683. if (curveSize != userA->dp->size) {
  28684. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28685. }
  28686. }
  28687. ret = wc_ecc_check_key(userA);
  28688. if (ret != 0)
  28689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28690. TEST_SLEEP();
  28691. ret = wc_ecc_sm2_make_key(rng, userB, WC_ECC_FLAG_NONE);
  28692. if (ret != 0)
  28693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28694. /* only perform the below tests if the key size matches */
  28695. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  28696. if (ret != 0) {
  28697. ret = ECC_CURVE_OID_E;
  28698. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28699. }
  28700. #ifdef HAVE_ECC_DHE
  28701. #if defined(ECC_TIMING_RESISTANT)
  28702. ret = wc_ecc_set_rng(userA, rng);
  28703. if (ret != 0)
  28704. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28705. ret = wc_ecc_set_rng(userB, rng);
  28706. if (ret != 0)
  28707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28708. #endif
  28709. x = ECC_SHARED_SIZE;
  28710. ret = wc_ecc_sm2_shared_secret(userA, userB, sharedA, &x);
  28711. if (ret != 0)
  28712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28713. y = ECC_SHARED_SIZE;
  28714. ret = wc_ecc_sm2_shared_secret(userB, userA, sharedB, &y);
  28715. if (ret != 0)
  28716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28717. if (y != x)
  28718. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28719. if (XMEMCMP(sharedA, sharedB, x))
  28720. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28721. #endif /* HAVE_ECC_DHE */
  28722. #ifdef HAVE_ECC_KEY_EXPORT
  28723. x = ECC_KEY_EXPORT_BUF_SIZE;
  28724. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  28725. if (ret != 0)
  28726. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28727. #ifdef HAVE_ECC_KEY_IMPORT
  28728. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28729. if (ret != 0)
  28730. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28731. #ifdef HAVE_ECC_DHE
  28732. y = ECC_SHARED_SIZE;
  28733. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28734. if (ret != 0)
  28735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28736. if (XMEMCMP(sharedA, sharedB, y))
  28737. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28738. #endif /* HAVE_ECC_DHE */
  28739. #ifdef HAVE_COMP_KEY
  28740. /* try compressed export / import too */
  28741. x = ECC_KEY_EXPORT_BUF_SIZE;
  28742. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  28743. if (ret != 0)
  28744. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28745. wc_ecc_free(pubKey);
  28746. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28747. if (ret != 0)
  28748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28749. #endif
  28750. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28751. if (ret != 0)
  28752. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28753. #ifdef HAVE_ECC_DHE
  28754. y = ECC_SHARED_SIZE;
  28755. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28756. if (ret != 0)
  28757. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28758. if (XMEMCMP(sharedA, sharedB, y))
  28759. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28760. #endif /* HAVE_ECC_DHE */
  28761. #endif /* HAVE_ECC_KEY_IMPORT */
  28762. #endif /* HAVE_ECC_KEY_EXPORT */
  28763. #endif /* !WC_NO_RNG */
  28764. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  28765. !defined(WC_NO_RNG))
  28766. #ifdef HAVE_ECC_SIGN
  28767. /* ECC w/out Shamir has issue with all 0 digest */
  28768. /* WC_BIGINT doesn't have 0 len well on hardware */
  28769. /* Cryptocell has issues with all 0 digest */
  28770. #if defined(ECC_SHAMIR)
  28771. /* test DSA sign hash with zeros */
  28772. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28773. digest[i] = 0;
  28774. }
  28775. x = ECC_SIG_SIZE;
  28776. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28777. if (ret != 0)
  28778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28779. for (i = 0; i < testVerifyCount; i++) {
  28780. verify = 0;
  28781. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28782. userA);
  28783. if (ret != 0)
  28784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28785. if (verify != 1)
  28786. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28787. }
  28788. #endif /* ECC_SHAMIR */
  28789. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  28790. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28791. digest[i] = (byte)i;
  28792. }
  28793. x = ECC_SIG_SIZE;
  28794. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28795. if (ret != 0)
  28796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28797. for (i = 0; i < testVerifyCount; i++) {
  28798. verify = 0;
  28799. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28800. userA);
  28801. if (ret != 0)
  28802. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28803. if (verify != 1)
  28804. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28805. }
  28806. #endif /* HAVE_ECC_SIGN */
  28807. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT && !WC_NO_RNG) */
  28808. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  28809. x = ECC_KEY_EXPORT_BUF_SIZE;
  28810. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  28811. if (ret != 0)
  28812. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28813. #elif defined(HAVE_ECC_KEY_EXPORT)
  28814. (void)exportBuf;
  28815. #endif /* HAVE_ECC_KEY_EXPORT */
  28816. done:
  28817. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28818. if (userA != NULL) {
  28819. wc_ecc_free(userA);
  28820. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28821. }
  28822. if (userB != NULL) {
  28823. wc_ecc_free(userB);
  28824. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28825. }
  28826. if (pubKey != NULL) {
  28827. wc_ecc_free(pubKey);
  28828. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28829. }
  28830. #else
  28831. wc_ecc_free(pubKey);
  28832. wc_ecc_free(userB);
  28833. wc_ecc_free(userA);
  28834. #endif
  28835. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  28836. WC_FREE_VAR(sharedA, HEAP_HINT);
  28837. WC_FREE_VAR(sharedB, HEAP_HINT);
  28838. #endif
  28839. #ifdef HAVE_ECC_KEY_EXPORT
  28840. WC_FREE_VAR(exportBuf, HEAP_HINT);
  28841. #endif
  28842. #ifdef HAVE_ECC_SIGN
  28843. WC_FREE_VAR(sig, HEAP_HINT);
  28844. WC_FREE_VAR(digest, HEAP_HINT);
  28845. #endif
  28846. (void)keySize;
  28847. (void)curve_id;
  28848. (void)rng;
  28849. return ret;
  28850. }
  28851. #endif /* HAVE_ECC_VERIFY */
  28852. static int test_sm2_create_digest(void)
  28853. {
  28854. #ifndef WOLFSSL_SM3
  28855. const byte msg[] = "message to sign";
  28856. const byte id[] = "0123456789";
  28857. const byte badId[] = "0123556789";
  28858. byte expected[] = {
  28859. 0xdd, 0x4d, 0x65, 0x49, 0xa3, 0x64, 0x76, 0xc0,
  28860. 0x73, 0x05, 0xdc, 0x05, 0x16, 0xb5, 0xee, 0x9f,
  28861. 0x82, 0xf9, 0xe9, 0x7d, 0x01, 0x1a, 0xdc, 0x88,
  28862. 0x5a, 0x59, 0x9c, 0x44, 0xcc, 0x47, 0xa4, 0x78
  28863. };
  28864. ecc_key key;
  28865. int ret;
  28866. /* test key values */
  28867. const char qx[] =
  28868. "af178b7b8740cc9d5b493fbd22049c12621bc27dcc5802e75ff4d045a4158baf";
  28869. const char qy[] =
  28870. "89933faf7a4798f48c5b9b4cd3a7693d54c9e05449946eb489c0dd50a5294805";
  28871. const char d[] =
  28872. "b3e66c2dbfb50c6ff6830c1fac4b51293a2562f9e667052b03df2d4b43c1f34a";
  28873. int hash_type = WC_HASH_TYPE_SHA256;
  28874. byte digest[WC_SHA256_DIGEST_SIZE];
  28875. #else
  28876. ecc_key key;
  28877. int ret;
  28878. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20,
  28879. 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x00 };
  28880. const byte id[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28881. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28882. 0x00 };
  28883. const byte badId[] = "0123556789";
  28884. const char qx[] =
  28885. "09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020";
  28886. const char qy[] =
  28887. "CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13";
  28888. const char d[] =
  28889. "3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8";
  28890. byte expected[] = {
  28891. 0xf0, 0xb4, 0x3e, 0x94, 0xba, 0x45, 0xac, 0xca,
  28892. 0xac, 0xe6, 0x92, 0xed, 0x53, 0x43, 0x82, 0xeb,
  28893. 0x17, 0xe6, 0xab, 0x5a, 0x19, 0xce, 0x7b, 0x31,
  28894. 0xf4, 0x48, 0x6f, 0xdf, 0xc0, 0xd2, 0x86, 0x40
  28895. };
  28896. int hash_type = WC_HASH_TYPE_SM3;
  28897. byte digest[WC_SM3_DIGEST_SIZE];
  28898. #endif
  28899. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28900. if (ret != 0)
  28901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28902. ret = wc_ecc_import_raw(&key, qx, qy, d, "SM2P256V1");
  28903. if (ret != 0)
  28904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28905. ret = wc_ecc_sm2_create_digest(id, (int)XSTRLEN((const char*)id),
  28906. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28907. &key);
  28908. if (ret != 0)
  28909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28910. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) != 0)
  28911. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28912. ret = wc_ecc_sm2_create_digest(badId, (int)XSTRLEN((const char*)badId),
  28913. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28914. &key);
  28915. if (ret != 0)
  28916. goto done;
  28917. /* should be different than the previous ID used */
  28918. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) == 0)
  28919. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28920. done:
  28921. wc_ecc_free(&key);
  28922. return ret;
  28923. }
  28924. static int test_sm2_verify(void)
  28925. {
  28926. int ret = 0;
  28927. #ifdef HAVE_ECC_VERIFY
  28928. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28929. ret = test_sm2_verify_caseA2();
  28930. if (ret != 0)
  28931. return ret;
  28932. #endif
  28933. ret = test_sm2_verify_case();
  28934. if (ret != 0)
  28935. return ret;
  28936. #endif /* HAVE_ECC_VERIFY */
  28937. ret = test_sm2_create_digest();
  28938. return ret;
  28939. }
  28940. #endif /* WOLFSSL_SM2 */
  28941. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  28942. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  28943. /* Make Cert / Sign example for ECC cert and ECC CA */
  28944. static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
  28945. {
  28946. wc_test_ret_t ret;
  28947. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28948. Cert *myCert = (Cert *)XMALLOC(sizeof *myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28949. #ifdef WOLFSSL_TEST_CERT
  28950. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28951. #endif
  28952. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28953. ecc_key *certPubKey = (ecc_key *)XMALLOC(sizeof *certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28954. #else
  28955. Cert myCert[1];
  28956. #ifdef WOLFSSL_TEST_CERT
  28957. DecodedCert decode[1];
  28958. #endif
  28959. ecc_key caEccKey[1];
  28960. ecc_key certPubKey[1];
  28961. #endif
  28962. int certSz;
  28963. size_t bytes = 0;
  28964. word32 idx = 0;
  28965. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
  28966. XFILE file;
  28967. #endif
  28968. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28969. byte* der = NULL;
  28970. #else
  28971. byte der[FOURK_BUF];
  28972. #endif
  28973. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28974. if ((myCert == NULL)
  28975. #ifdef WOLFSSL_TEST_CERT
  28976. || (decode == NULL)
  28977. #endif
  28978. || (caEccKey == NULL) || (certPubKey == NULL))
  28979. ERROR_OUT(MEMORY_E, exit);
  28980. #endif
  28981. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  28982. XMEMSET(certPubKey, 0, sizeof *certPubKey);
  28983. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28984. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28985. if (der == NULL) {
  28986. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28987. }
  28988. #endif
  28989. /* Get cert private key */
  28990. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28991. /* Get Cert Key 384 */
  28992. #ifdef USE_CERT_BUFFERS_256
  28993. XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
  28994. bytes = sizeof_ca_ecc_key_der_384;
  28995. #elif !defined(NO_FILESYSTEM)
  28996. file = XFOPEN(eccCaKey384File, "rb");
  28997. if (!file) {
  28998. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28999. }
  29000. bytes = XFREAD(der, 1, FOURK_BUF, file);
  29001. XFCLOSE(file);
  29002. if (bytes == 0)
  29003. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29004. (void)eccCaKeyFile;
  29005. #else
  29006. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
  29007. ERROR_OUT(ASN_PARSE_E, exit);
  29008. #endif /* USE_CERT_BUFFERS_256 */
  29009. /* end if ENABLE_ECC384_CERT_GEN_TEST */
  29010. #else
  29011. /* !ENABLE_ECC384_CERT_GEN_TEST */
  29012. #ifdef USE_CERT_BUFFERS_256
  29013. XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
  29014. bytes = sizeof_ca_ecc_key_der_256;
  29015. #else
  29016. file = XFOPEN(eccCaKeyFile, "rb");
  29017. if (!file) {
  29018. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29019. }
  29020. bytes = XFREAD(der, 1, FOURK_BUF, file);
  29021. XFCLOSE(file);
  29022. if (bytes == 0)
  29023. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29024. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29025. (void)eccCaKey384File;
  29026. #endif
  29027. #endif /* USE_CERT_BUFFERS_256 */
  29028. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29029. /* Get CA Key */
  29030. ret = wc_ecc_init_ex(caEccKey, HEAP_HINT, devId);
  29031. if (ret != 0)
  29032. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29033. ret = wc_EccPrivateKeyDecode(der, &idx, caEccKey, (word32)bytes);
  29034. if (ret != 0)
  29035. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29036. /* Make a public key */
  29037. ret = wc_ecc_init_ex(certPubKey, HEAP_HINT, devId);
  29038. if (ret != 0)
  29039. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29040. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, certPubKey);
  29041. #if defined(WOLFSSL_ASYNC_CRYPT)
  29042. ret = wc_AsyncWait(ret, &certPubKey->asyncDev, WC_ASYNC_FLAG_NONE);
  29043. #endif
  29044. if (ret != 0)
  29045. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29046. TEST_SLEEP();
  29047. /* Setup Certificate */
  29048. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  29049. if (ret != 0)
  29050. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29051. #ifndef NO_SHA256
  29052. myCert->sigType = CTC_SHA256wECDSA;
  29053. #else
  29054. myCert->sigType = CTC_SHAwECDSA;
  29055. #endif
  29056. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  29057. #ifdef WOLFSSL_CERT_EXT
  29058. /* add Policies */
  29059. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  29060. CTC_MAX_CERTPOL_SZ);
  29061. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  29062. CTC_MAX_CERTPOL_SZ);
  29063. myCert->certPoliciesNb = 2;
  29064. /* add SKID from the Public Key */
  29065. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey);
  29066. if (ret != 0)
  29067. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29068. /* add AKID from the Public Key */
  29069. ret = wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey);
  29070. if (ret != 0)
  29071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29072. /* add Key Usage */
  29073. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  29074. if (ret != 0)
  29075. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29076. #endif /* WOLFSSL_CERT_EXT */
  29077. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29078. #if defined(USE_CERT_BUFFERS_256)
  29079. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
  29080. sizeof_ca_ecc_cert_der_384);
  29081. #elif !defined(NO_FILESYSTEM)
  29082. ret = wc_SetIssuer(myCert, eccCaCert384File);
  29083. (void)eccCaCertFile;
  29084. #else
  29085. /* not testing with embedded, no file system target */
  29086. ERROR_OUT(ASN_PARSE_E, exit);
  29087. #endif /* USE_CERT_BUFFERS_256 */
  29088. #else
  29089. /* not ENABLE_ECC384_CERT_GEN_TEST */
  29090. #if defined(USE_CERT_BUFFERS_256)
  29091. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
  29092. sizeof_ca_ecc_cert_der_256);
  29093. #else
  29094. ret = wc_SetIssuer(myCert, eccCaCertFile);
  29095. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29096. (void)eccCaCert384File;
  29097. #endif
  29098. #endif
  29099. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29100. if (ret < 0)
  29101. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29102. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, certPubKey, rng);
  29103. if (certSz < 0) {
  29104. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit);
  29105. }
  29106. ret = 0;
  29107. do {
  29108. #if defined(WOLFSSL_ASYNC_CRYPT)
  29109. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  29110. #endif
  29111. if (ret >= 0) {
  29112. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  29113. FOURK_BUF, NULL, caEccKey, rng);
  29114. }
  29115. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  29116. if (ret < 0)
  29117. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29118. certSz = (int)ret;
  29119. TEST_SLEEP();
  29120. #ifdef WOLFSSL_TEST_CERT
  29121. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  29122. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  29123. if (ret != 0) {
  29124. FreeDecodedCert(decode);
  29125. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29126. }
  29127. FreeDecodedCert(decode);
  29128. #endif
  29129. ret = SaveDerAndPem(der, certSz, certEccDerFile, certEccPemFile,
  29130. CERT_TYPE);
  29131. if (ret != 0) {
  29132. goto exit;
  29133. }
  29134. exit:
  29135. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29136. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29137. #endif
  29138. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29139. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29140. #ifdef WOLFSSL_TEST_CERT
  29141. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29142. #endif
  29143. if (caEccKey != NULL) {
  29144. wc_ecc_free(caEccKey);
  29145. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29146. }
  29147. if (certPubKey != NULL) {
  29148. wc_ecc_free(certPubKey);
  29149. XFREE(certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29150. }
  29151. #else
  29152. wc_ecc_free(certPubKey);
  29153. wc_ecc_free(caEccKey);
  29154. #endif
  29155. return ret;
  29156. }
  29157. #endif /* WOLFSSL_CERT_GEN */
  29158. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  29159. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
  29160. (!defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES))
  29161. /* Test for the wc_ecc_key_new() and wc_ecc_key_free() functions. */
  29162. static wc_test_ret_t ecc_test_allocator(WC_RNG* rng)
  29163. {
  29164. wc_test_ret_t ret = 0;
  29165. ecc_key* key;
  29166. #ifdef WC_NO_RNG
  29167. word32 idx = 0;
  29168. #endif
  29169. key = wc_ecc_key_new(HEAP_HINT);
  29170. if (key == NULL) {
  29171. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29172. }
  29173. #ifndef WC_NO_RNG
  29174. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  29175. #if defined(WOLFSSL_ASYNC_CRYPT)
  29176. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  29177. #endif
  29178. if (ret != 0)
  29179. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29180. #else
  29181. /* use test ECC key */
  29182. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  29183. (word32)sizeof_ecc_key_der_256);
  29184. (void)rng;
  29185. #endif
  29186. exit:
  29187. wc_ecc_key_free(key);
  29188. return ret;
  29189. }
  29190. #endif
  29191. /* ECC Non-blocking tests for Sign and Verify */
  29192. /* Requires SP math and supports P384 or P256 */
  29193. /* ./configure --enable-ecc=nonblock --enable-sp=yes,nonblock CFLAGS="-DWOLFSSL_PUBLIC_MP" */
  29194. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_HAVE_SP_ECC) && \
  29195. defined(WOLFSSL_PUBLIC_MP)
  29196. /* ECC Private Key "d" */
  29197. static const byte p256PrivKey[] = {
  29198. /* SECP256R1 */
  29199. /* d */
  29200. 0x1e, 0xe7, 0x70, 0x07, 0xd3, 0x30, 0x94, 0x39,
  29201. 0x28, 0x90, 0xdf, 0x23, 0x88, 0x2c, 0x4a, 0x34,
  29202. 0x15, 0xdb, 0x4c, 0x43, 0xcd, 0xfa, 0xe5, 0x1f,
  29203. 0x3d, 0x4c, 0x37, 0xfe, 0x59, 0x3b, 0x96, 0xd8
  29204. };
  29205. #ifdef HAVE_ECC384
  29206. static const byte p384PrivKey[] = {
  29207. /* SECP384R1 */
  29208. /* d */
  29209. 0xa4, 0xe5, 0x06, 0xe8, 0x06, 0x16, 0x3e, 0xab,
  29210. 0x89, 0xf8, 0x60, 0x43, 0xc0, 0x60, 0x25, 0xdb,
  29211. 0xba, 0x7b, 0xfe, 0x19, 0x35, 0x08, 0x55, 0x65,
  29212. 0x76, 0xe2, 0xdc, 0xe0, 0x01, 0x8b, 0x6b, 0x68,
  29213. 0xdf, 0xcf, 0x6f, 0x80, 0x12, 0xce, 0x79, 0x37,
  29214. 0xeb, 0x2b, 0x9c, 0x7b, 0xc4, 0x68, 0x1c, 0x74
  29215. };
  29216. #endif /* HAVE_ECC384 */
  29217. #ifdef HAVE_ECC521
  29218. static const byte p521PrivKey[] = {
  29219. /* SECP521R1 */
  29220. /* d */
  29221. 0x01, 0x68, 0x91, 0x33, 0x53, 0xe2, 0x90, 0x68,
  29222. 0x11, 0x8f, 0xaa, 0xa8, 0x76, 0x0c, 0xf7, 0x2a,
  29223. 0x07, 0x1b, 0x92, 0x2a, 0xa7, 0x82, 0x3d, 0xfa,
  29224. 0x83, 0xce, 0x70, 0xc8, 0xc2, 0x60, 0x82, 0xfe,
  29225. 0x18, 0x88, 0x68, 0xda, 0x6a, 0x83, 0x46, 0x78,
  29226. 0xe4, 0xe9, 0xe9, 0xcc, 0x51, 0x7f, 0xed, 0x81,
  29227. 0x02, 0x32, 0xee, 0x26, 0x87, 0xcc, 0xed, 0x63,
  29228. 0x3f, 0x39, 0x27, 0xf0, 0xd7, 0x17, 0x77, 0xa1,
  29229. 0xa4, 0x36
  29230. };
  29231. #endif /* HAVE_ECC521 */
  29232. /* ECC public key Qx/Qy */
  29233. static const byte p256PubKey[] = {
  29234. /* SECP256R1 */
  29235. /* Qx */
  29236. 0x96, 0x93, 0x1c, 0x53, 0x0b, 0x43, 0x6c, 0x42,
  29237. 0x0c, 0x52, 0x90, 0xe4, 0xa7, 0xec, 0x98, 0xb1,
  29238. 0xaf, 0xd4, 0x14, 0x49, 0xd8, 0xc1, 0x42, 0x82,
  29239. 0x04, 0x78, 0xd1, 0x90, 0xae, 0xa0, 0x6c, 0x07,
  29240. /* Qy */
  29241. 0xf2, 0x3a, 0xb5, 0x10, 0x32, 0x8d, 0xce, 0x9e,
  29242. 0x76, 0xa0, 0xd2, 0x8c, 0xf3, 0xfc, 0xa9, 0x94,
  29243. 0x43, 0x24, 0xe6, 0x82, 0x00, 0x40, 0xc6, 0xdb,
  29244. 0x1c, 0x2f, 0xcd, 0x38, 0x4b, 0x60, 0xdd, 0x61
  29245. };
  29246. #ifdef HAVE_ECC384
  29247. static const byte p384PubKey[] = {
  29248. /* SECP384R1 */
  29249. /* Qx */
  29250. 0xea, 0xcf, 0x93, 0x4f, 0x2c, 0x09, 0xbb, 0x39,
  29251. 0x14, 0x0f, 0x56, 0x64, 0xc3, 0x40, 0xb4, 0xdf,
  29252. 0x0e, 0x63, 0xae, 0xe5, 0x71, 0x4b, 0x00, 0xcc,
  29253. 0x04, 0x97, 0xff, 0xe1, 0xe9, 0x38, 0x96, 0xbb,
  29254. 0x5f, 0x91, 0xb2, 0x6a, 0xcc, 0xb5, 0x39, 0x5f,
  29255. 0x8f, 0x70, 0x59, 0xf1, 0x01, 0xf6, 0x5a, 0x2b,
  29256. /* Qy */
  29257. 0x01, 0x6c, 0x68, 0x0b, 0xcf, 0x55, 0x25, 0xaf,
  29258. 0x6d, 0x98, 0x48, 0x0a, 0xa8, 0x74, 0xc9, 0xa9,
  29259. 0x17, 0xa0, 0x0c, 0xc3, 0xfb, 0xd3, 0x23, 0x68,
  29260. 0xfe, 0x04, 0x3c, 0x63, 0x50, 0x88, 0x3b, 0xb9,
  29261. 0x4f, 0x7c, 0x67, 0x34, 0xf7, 0x3b, 0xa9, 0x73,
  29262. 0xe7, 0x1b, 0xc3, 0x51, 0x5e, 0x22, 0x18, 0xec
  29263. };
  29264. #endif
  29265. #ifdef HAVE_ECC521
  29266. static const byte p521PubKey[] = {
  29267. /* SECP521R1 */
  29268. /* Qx */
  29269. 0x01, 0x62, 0x6e, 0xf1, 0x00, 0xec, 0xd8, 0x99,
  29270. 0x58, 0x9b, 0x80, 0x6b, 0xfe, 0x2c, 0xf1, 0xb2,
  29271. 0xf0, 0xc8, 0x48, 0xdf, 0xac, 0xd2, 0x3b, 0x71,
  29272. 0x29, 0xab, 0xf0, 0x66, 0x63, 0xd8, 0x8e, 0xb5,
  29273. 0xc8, 0xc2, 0xfc, 0x99, 0x44, 0xe2, 0x45, 0xb1,
  29274. 0x5a, 0x7b, 0xb9, 0x73, 0x01, 0xda, 0x79, 0xec,
  29275. 0x9c, 0x26, 0x27, 0x34, 0x45, 0x26, 0xd5, 0x89,
  29276. 0x4b, 0x44, 0xfe, 0x69, 0x4e, 0x72, 0x14, 0xe3,
  29277. 0x8b, 0xbc,
  29278. /* Qy */
  29279. 0x00, 0x0f, 0x09, 0xa2, 0x03, 0xc3, 0x5a, 0xdc,
  29280. 0x95, 0x82, 0xf6, 0xf9, 0xf6, 0x9c, 0xff, 0xb5,
  29281. 0x6b, 0x75, 0x95, 0x4b, 0xa4, 0x28, 0x5d, 0x9e,
  29282. 0x90, 0x04, 0xd1, 0xc0, 0x1e, 0xd5, 0xfd, 0x43,
  29283. 0x9e, 0x1e, 0x83, 0xc0, 0x11, 0x2b, 0x2b, 0x07,
  29284. 0x6d, 0xa9, 0x7a, 0x10, 0xd7, 0x67, 0xe7, 0x51,
  29285. 0x37, 0x24, 0xd8, 0xbf, 0x03, 0x0d, 0x8b, 0xb5,
  29286. 0x40, 0x5c, 0x4f, 0xd6, 0x13, 0x73, 0x42, 0xbc,
  29287. 0x91, 0xd9
  29288. };
  29289. /* perform verify of signature and hash using public key */
  29290. /* key is public Qx + public Qy */
  29291. /* sig is r + s */
  29292. static wc_test_ret_t crypto_ecc_verify(const byte *key, uint32_t keySz,
  29293. const byte *hash, uint32_t hashSz, const byte *sig, uint32_t sigSz,
  29294. uint32_t curveSz, int curveId)
  29295. {
  29296. wc_test_ret_t ret;
  29297. int verify_res = 0, count = 0;
  29298. mp_int r, s;
  29299. ecc_key ecc;
  29300. ecc_nb_ctx_t nb_ctx;
  29301. /* validate arguments */
  29302. if (key == NULL || hash == NULL || sig == NULL || curveSz == 0 ||
  29303. hashSz == 0 || keySz < (curveSz*2) || sigSz < (curveSz*2))
  29304. {
  29305. return WC_TEST_RET_ENC_NC;
  29306. }
  29307. /* Setup the ECC key */
  29308. ret = wc_ecc_init(&ecc);
  29309. if (ret < 0) {
  29310. return WC_TEST_RET_ENC_EC(ret);
  29311. }
  29312. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29313. if (ret != MP_OKAY) {
  29314. wc_ecc_free(&ecc);
  29315. return WC_TEST_RET_ENC_EC(ret);
  29316. }
  29317. /* Setup the signature r/s variables */
  29318. ret = mp_init(&r);
  29319. if (ret != MP_OKAY) {
  29320. wc_ecc_free(&ecc);
  29321. return WC_TEST_RET_ENC_EC(ret);
  29322. }
  29323. ret = mp_init(&s);
  29324. if (ret != MP_OKAY) {
  29325. mp_clear(&r);
  29326. wc_ecc_free(&ecc);
  29327. return WC_TEST_RET_ENC_EC(ret);
  29328. }
  29329. /* Import public key x/y */
  29330. ret = wc_ecc_import_unsigned(
  29331. &ecc,
  29332. (byte*)key, /* Public "x" Coordinate */
  29333. (byte*)(key + curveSz), /* Public "y" Coordinate */
  29334. NULL, /* Private "d" (optional) */
  29335. curveId /* ECC Curve Id */
  29336. );
  29337. /* Make sure it was a public key imported */
  29338. if (ret == 0 && ecc.type != ECC_PUBLICKEY) {
  29339. ret = WC_TEST_RET_ENC_NC; /* ECC_BAD_ARG_E */
  29340. }
  29341. /* Import signature r/s */
  29342. if (ret == 0) {
  29343. ret = mp_read_unsigned_bin(&r, sig, curveSz);
  29344. if (ret < 0)
  29345. ret = WC_TEST_RET_ENC_EC(ret);
  29346. }
  29347. if (ret == 0) {
  29348. ret = mp_read_unsigned_bin(&s, sig + curveSz, curveSz);
  29349. if (ret < 0)
  29350. ret = WC_TEST_RET_ENC_EC(ret);
  29351. }
  29352. /* Verify ECC Signature */
  29353. if (ret == 0) {
  29354. do {
  29355. ret = wc_ecc_verify_hash_ex(
  29356. &r, &s, /* r/s as mp_int */
  29357. hash, hashSz, /* computed hash digest */
  29358. &verify_res, /* verification result 1=success */
  29359. &ecc
  29360. );
  29361. count++;
  29362. /* This is where real-time work could be called */
  29363. } while (ret == FP_WOULDBLOCK);
  29364. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29365. printf("ECC non-block verify: %d times\n", count);
  29366. #endif
  29367. if (ret < 0)
  29368. ret = WC_TEST_RET_ENC_EC(ret);
  29369. }
  29370. /* check verify result */
  29371. if (ret == 0 && verify_res == 0) {
  29372. ret = WC_TEST_RET_ENC_NC /* SIG_VERIFY_E */;
  29373. }
  29374. mp_clear(&r);
  29375. mp_clear(&s);
  29376. wc_ecc_free(&ecc);
  29377. (void)count;
  29378. return ret;
  29379. }
  29380. /* perform signature operation against hash using private key */
  29381. static wc_test_ret_t crypto_ecc_sign(const byte *key, uint32_t keySz,
  29382. const byte *hash, uint32_t hashSz, byte *sig, uint32_t* sigSz,
  29383. uint32_t curveSz, int curveId, WC_RNG* rng)
  29384. {
  29385. wc_test_ret_t ret;
  29386. int count = 0;
  29387. mp_int r, s;
  29388. ecc_key ecc;
  29389. ecc_nb_ctx_t nb_ctx;
  29390. /* validate arguments */
  29391. if (key == NULL || hash == NULL || sig == NULL || sigSz == NULL ||
  29392. curveSz == 0 || hashSz == 0 || keySz < curveSz || *sigSz < (curveSz*2))
  29393. {
  29394. return WC_TEST_RET_ENC_NC /* BAD_FUNC_ARG */;
  29395. }
  29396. /* Initialize signature result */
  29397. memset(sig, 0, curveSz*2);
  29398. /* Setup the ECC key */
  29399. ret = wc_ecc_init(&ecc);
  29400. if (ret < 0) {
  29401. return WC_TEST_RET_ENC_EC(ret);
  29402. }
  29403. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29404. if (ret != MP_OKAY) {
  29405. wc_ecc_free(&ecc);
  29406. return WC_TEST_RET_ENC_EC(ret);
  29407. }
  29408. /* Setup the signature r/s variables */
  29409. ret = mp_init(&r);
  29410. if (ret != MP_OKAY) {
  29411. wc_ecc_free(&ecc);
  29412. return WC_TEST_RET_ENC_EC(ret);
  29413. }
  29414. ret = mp_init(&s);
  29415. if (ret != MP_OKAY) {
  29416. mp_clear(&r);
  29417. wc_ecc_free(&ecc);
  29418. return WC_TEST_RET_ENC_EC(ret);
  29419. }
  29420. /* Import private key "k" */
  29421. ret = wc_ecc_import_private_key_ex(
  29422. key, keySz, /* private key "d" */
  29423. NULL, 0, /* public (optional) */
  29424. &ecc,
  29425. curveId /* ECC Curve Id */
  29426. );
  29427. if (ret < 0)
  29428. ret = WC_TEST_RET_ENC_EC(ret);
  29429. if (ret == 0) {
  29430. do {
  29431. /* Verify ECC Signature */
  29432. ret = wc_ecc_sign_hash_ex(
  29433. hash, hashSz, /* computed hash digest */
  29434. rng, &ecc, /* random and key context */
  29435. &r, &s /* r/s as mp_int */
  29436. );
  29437. count++;
  29438. /* This is where real-time work could be called */
  29439. } while (ret == FP_WOULDBLOCK);
  29440. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29441. printf("ECC non-block sign: %d times\n", count);
  29442. #endif
  29443. if (ret < 0)
  29444. ret = WC_TEST_RET_ENC_EC(ret);
  29445. }
  29446. if (ret == 0) {
  29447. /* export r/s */
  29448. mp_to_unsigned_bin_len(&r, sig, curveSz);
  29449. mp_to_unsigned_bin_len(&s, sig + curveSz, curveSz);
  29450. }
  29451. mp_clear(&r);
  29452. mp_clear(&s);
  29453. wc_ecc_free(&ecc);
  29454. (void)count;
  29455. return ret;
  29456. }
  29457. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29458. /*
  29459. * This test doesn't work with WOLFSSL_VALIDATE_ECC_KEYGEN defined because we
  29460. * don't have non-blocking versions of the key checking functions, yet.
  29461. */
  29462. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29463. static wc_test_ret_t ecc_test_nonblock_dhe(int curveId, word32 curveSz,
  29464. const byte* privKey, const byte* pubKey, WC_RNG* rng)
  29465. {
  29466. wc_test_ret_t ret;
  29467. ecc_key keyA;
  29468. ecc_key keyB;
  29469. ecc_nb_ctx_t nbCtxA;
  29470. ecc_nb_ctx_t nbCtxB;
  29471. byte secretA[ECC_SHARED_SIZE];
  29472. byte secretB[ECC_SHARED_SIZE];
  29473. word32 secretSzA = ECC_SHARED_SIZE;
  29474. word32 secretSzB = ECC_SHARED_SIZE;
  29475. int count = 0;
  29476. ret = wc_ecc_init(&keyA);
  29477. if (ret == 0) {
  29478. ret = wc_ecc_init(&keyB);
  29479. if (ret < 0)
  29480. ret = WC_TEST_RET_ENC_EC(ret);
  29481. }
  29482. if (ret == 0) {
  29483. ret = wc_ecc_set_nonblock(&keyA, &nbCtxA);
  29484. if (ret < 0)
  29485. ret = WC_TEST_RET_ENC_EC(ret);
  29486. }
  29487. if (ret == 0) {
  29488. ret = wc_ecc_set_nonblock(&keyB, &nbCtxB);
  29489. if (ret < 0)
  29490. ret = WC_TEST_RET_ENC_EC(ret);
  29491. }
  29492. if (ret == 0) {
  29493. do {
  29494. ret = wc_ecc_make_key_ex(rng, curveSz, &keyA, curveId);
  29495. count++;
  29496. } while (ret == FP_WOULDBLOCK);
  29497. if (ret < 0)
  29498. ret = WC_TEST_RET_ENC_EC(ret);
  29499. }
  29500. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29501. fprintf(stderr, "ECC non-block key gen: %d times\n", count);
  29502. #endif
  29503. if (ret == 0) {
  29504. ret = wc_ecc_check_key(&keyA);
  29505. if (ret < 0)
  29506. ret = WC_TEST_RET_ENC_EC(ret);
  29507. }
  29508. if (ret == 0) {
  29509. ret = wc_ecc_import_unsigned(&keyB, pubKey, pubKey + curveSz,
  29510. privKey, curveId);
  29511. if (ret < 0)
  29512. ret = WC_TEST_RET_ENC_EC(ret);
  29513. }
  29514. count = 0;
  29515. if (ret == 0) {
  29516. do {
  29517. ret = wc_ecc_shared_secret(&keyA, &keyB, secretA, &secretSzA);
  29518. count++;
  29519. } while (ret == FP_WOULDBLOCK);
  29520. if (ret < 0)
  29521. ret = WC_TEST_RET_ENC_EC(ret);
  29522. }
  29523. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29524. fprintf(stderr, "ECC non-block shared secret: %d times\n", count);
  29525. #endif
  29526. if (ret == 0) {
  29527. do {
  29528. ret = wc_ecc_shared_secret(&keyB, &keyA, secretB, &secretSzB);
  29529. } while (ret == FP_WOULDBLOCK);
  29530. if (ret < 0)
  29531. ret = WC_TEST_RET_ENC_EC(ret);
  29532. }
  29533. if (ret == 0) {
  29534. if (secretSzA != secretSzB ||
  29535. XMEMCMP(secretA, secretB, secretSzA) != 0) {
  29536. ret = WC_TEST_RET_ENC_NC;
  29537. }
  29538. }
  29539. wc_ecc_free(&keyA);
  29540. wc_ecc_free(&keyB);
  29541. return ret;
  29542. }
  29543. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29544. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29545. static wc_test_ret_t ecc_test_nonblock_ecdsa(int curveId, word32 curveSz,
  29546. const byte* privKey, word32 privKeySz, const byte* pubKey, word32 pubKeySz,
  29547. WC_RNG* rng)
  29548. {
  29549. wc_test_ret_t ret = 0;
  29550. byte* sig = NULL;
  29551. word32 sigSz = curveSz * 2;
  29552. static const byte hash[] = {
  29553. 0x8d, 0x28, 0xa3, 0x8b, 0x0b, 0xa9, 0xfe, 0xd4, 0x0e, 0x54, 0xc4, 0x17,
  29554. 0x3d, 0x54, 0x66, 0x34, 0xbf, 0x5d, 0x6f, 0x46, 0xc2, 0x20, 0xcb, 0xc3,
  29555. 0x22, 0xe9, 0xb0, 0xdf, 0xe7, 0x64, 0x3f, 0xd9
  29556. };
  29557. sig = (byte*)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29558. if (sig == NULL) {
  29559. ret = WC_TEST_RET_ENC_ERRNO;
  29560. }
  29561. if (ret == 0) {
  29562. /* Sign hash using private key */
  29563. /* Note: result of an ECC sign varies for each call even with same
  29564. private key and hash. This is because a new random public key is
  29565. used for each operation. */
  29566. ret = crypto_ecc_sign(privKey, privKeySz, hash, sizeof(hash), sig,
  29567. &sigSz, curveSz, curveId, rng);
  29568. }
  29569. if (ret == 0) {
  29570. /* Verify generated signature is valid */
  29571. ret = crypto_ecc_verify(pubKey, pubKeySz, hash, sizeof(hash), sig,
  29572. sigSz, curveSz, curveId);
  29573. }
  29574. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29575. return ret;
  29576. }
  29577. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29578. static wc_test_ret_t ecc_test_nonblock(WC_RNG* rng)
  29579. {
  29580. wc_test_ret_t ret = 0;
  29581. word32 i;
  29582. int curveIds[3] = {0, 0, 0};
  29583. word32 curveSzs[3] = {0, 0, 0};
  29584. const byte* privKeys[3] = {NULL, NULL, NULL};
  29585. word32 privKeySzs[3] = {0, 0, 0};
  29586. const byte* pubKeys[3] = {NULL, NULL, NULL};
  29587. word32 pubKeySzs[3] = {0, 0, 0};
  29588. curveIds[0] = ECC_SECP256R1;
  29589. curveSzs[0] = 32;
  29590. privKeys[0] = p256PrivKey;
  29591. privKeySzs[0] = sizeof(p256PrivKey);
  29592. pubKeys[0] = p256PubKey;
  29593. pubKeySzs[0] = sizeof(p256PubKey);
  29594. #ifdef HAVE_ECC384
  29595. curveIds[1] = ECC_SECP384R1;
  29596. curveSzs[1] = 48;
  29597. privKeys[1] = p384PrivKey;
  29598. privKeySzs[1] = sizeof(p384PrivKey);
  29599. pubKeys[1] = p384PubKey;
  29600. pubKeySzs[1] = sizeof(p384PubKey);
  29601. #endif
  29602. #ifdef HAVE_ECC521
  29603. curveIds[2] = ECC_SECP521R1;
  29604. curveSzs[2] = 66;
  29605. privKeys[2] = p521PrivKey;
  29606. privKeySzs[2] = sizeof(p521PrivKey);
  29607. pubKeys[2] = p521PubKey;
  29608. pubKeySzs[2] = sizeof(p521PubKey);
  29609. #endif
  29610. for (i = 0; ret == 0 && i < sizeof(curveIds) / sizeof(curveIds[0]); ++i) {
  29611. if (curveIds[i] == 0) {
  29612. continue;
  29613. }
  29614. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29615. ret = ecc_test_nonblock_ecdsa(curveIds[i], curveSzs[i], privKeys[i],
  29616. privKeySzs[i], pubKeys[i], pubKeySzs[i], rng);
  29617. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29618. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29619. if (ret == 0) {
  29620. ret = ecc_test_nonblock_dhe(curveIds[i], curveSzs[i], privKeys[i],
  29621. pubKeys[i], rng);
  29622. }
  29623. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29624. }
  29625. return ret;
  29626. }
  29627. #endif /* WC_ECC_NONBLOCK && WOLFSSL_HAVE_SP_ECC && WOLFSSL_PUBLIC_MP */
  29628. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29629. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29630. (HAVE_FIPS_VERSION > 2)))
  29631. static int ecc_test_raw_enc_dec(void)
  29632. {
  29633. int ret;
  29634. unsigned char r[1];
  29635. word32 rSz;
  29636. unsigned char s[1];
  29637. word32 sSz;
  29638. unsigned char rZero[] = { 0, 0, 0, 0 };
  29639. unsigned char sOne[] = { 0, 0, 1 };
  29640. unsigned char sigRaw[32];
  29641. word32 sigRawSz;
  29642. unsigned char expSig[] = { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01 };
  29643. sigRawSz = sizeof(sigRaw);
  29644. ret = wc_ecc_rs_raw_to_sig(rZero, sizeof(rZero), sOne, sizeof(sOne),
  29645. sigRaw, &sigRawSz);
  29646. if (ret != 0) {
  29647. return WC_TEST_RET_ENC_EC(ret);
  29648. }
  29649. if (sigRawSz != sizeof(expSig)) {
  29650. return WC_TEST_RET_ENC_EC((int)sigRawSz);
  29651. }
  29652. if (XMEMCMP(sigRaw, expSig, sizeof(expSig)) != 0) {
  29653. return WC_TEST_RET_ENC_NC;
  29654. }
  29655. rSz = sizeof(r);
  29656. sSz = sizeof(s);
  29657. ret = wc_ecc_sig_to_rs(sigRaw, sigRawSz, r, &rSz, s, &sSz);
  29658. if (ret != 0) {
  29659. return WC_TEST_RET_ENC_EC(ret);
  29660. }
  29661. if (rSz != 1) {
  29662. return WC_TEST_RET_ENC_EC((int)rSz);
  29663. }
  29664. if (sSz != 1) {
  29665. return WC_TEST_RET_ENC_EC((int)sSz);
  29666. }
  29667. if (r[0] != 0) {
  29668. return WC_TEST_RET_ENC_EC(r[0]);
  29669. }
  29670. if (s[0] != 1) {
  29671. return WC_TEST_RET_ENC_EC(s[0]);
  29672. }
  29673. return ret;
  29674. }
  29675. #endif
  29676. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void)
  29677. {
  29678. wc_test_ret_t ret;
  29679. WC_RNG rng;
  29680. WOLFSSL_ENTER("ecc_test");
  29681. #if defined(ECC_MIN_KEY_SZ)
  29682. WOLFSSL_MSG_EX("ecc_test ECC_MIN_KEY_SZ = %d\n", ECC_MIN_KEY_SZ);
  29683. #else
  29684. WOLFSSL_MSG("ecc_test ECC_MIN_KEY_SZ not defined.");
  29685. #endif
  29686. #if defined(WOLFSSL_CERT_EXT) && \
  29687. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29688. ret = ecc_decode_test();
  29689. if (ret < 0)
  29690. return ret;
  29691. #endif
  29692. #ifndef HAVE_FIPS
  29693. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  29694. #else
  29695. ret = wc_InitRng(&rng);
  29696. #endif
  29697. #ifndef WC_NO_RNG
  29698. if (ret != 0)
  29699. return WC_TEST_RET_ENC_EC(ret);
  29700. #else
  29701. (void)ret;
  29702. #endif
  29703. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  29704. ret = ecc_test_curve(&rng, 14, ECC_CURVE_DEF);
  29705. if (ret < 0) {
  29706. printf("keySize=14, Default\n");
  29707. goto done;
  29708. }
  29709. #endif /* HAVE_ECC112 */
  29710. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  29711. ret = ecc_test_curve(&rng, 16, ECC_CURVE_DEF);
  29712. if (ret < 0) {
  29713. printf("keySize=16, Default\n");
  29714. goto done;
  29715. }
  29716. #endif /* HAVE_ECC128 */
  29717. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  29718. ret = ecc_test_curve(&rng, 20, ECC_CURVE_DEF);
  29719. if (ret < 0) {
  29720. printf("keySize=20, Default\n");
  29721. goto done;
  29722. }
  29723. #endif /* HAVE_ECC160 */
  29724. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  29725. #if !FIPS_VERSION3_GE(6,0,0)
  29726. ret = ecc_test_curve(&rng, 24, ECC_CURVE_DEF);
  29727. if (ret < 0) {
  29728. printf("keySize=24, Default\n");
  29729. goto done;
  29730. }
  29731. #endif
  29732. #endif /* HAVE_ECC192 */
  29733. #if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224
  29734. ret = ecc_test_curve(&rng, 28, ECC_CURVE_DEF);
  29735. if (ret < 0) {
  29736. printf("keySize=28, Default\n");
  29737. goto done;
  29738. }
  29739. #endif /* HAVE_ECC224 */
  29740. #if (defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 239
  29741. ret = ecc_test_curve(&rng, 30, ECC_CURVE_DEF);
  29742. if (ret < 0) {
  29743. printf("keySize=30, Default\n");
  29744. goto done;
  29745. }
  29746. #endif /* HAVE_ECC239 */
  29747. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29748. ret = ecc_test_curve(&rng, 32, ECC_CURVE_DEF);
  29749. if (ret < 0) {
  29750. printf("keySize=32, Default\n");
  29751. goto done;
  29752. }
  29753. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29754. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  29755. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  29756. ret = ecc_point_test();
  29757. if (ret < 0) {
  29758. goto done;
  29759. }
  29760. #endif
  29761. #if !defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES)
  29762. ret = ecc_def_curve_test(&rng);
  29763. if (ret < 0) {
  29764. printf("Default\n");
  29765. goto done;
  29766. }
  29767. #endif
  29768. #endif /* !NO_ECC256 */
  29769. #if (defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 320
  29770. ret = ecc_test_curve(&rng, 40, ECC_CURVE_DEF);
  29771. if (ret < 0) {
  29772. printf("keySize=40, Default\n");
  29773. goto done;
  29774. }
  29775. #endif /* HAVE_ECC320 */
  29776. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  29777. ret = ecc_test_curve(&rng, 48, ECC_CURVE_DEF);
  29778. if (ret < 0) {
  29779. printf("keySize=48, Default\n");
  29780. goto done;
  29781. }
  29782. #endif /* HAVE_ECC384 */
  29783. #if (defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 512
  29784. ret = ecc_test_curve(&rng, 64, ECC_CURVE_DEF);
  29785. if (ret < 0) {
  29786. printf("keySize=64, Default\n");
  29787. goto done;
  29788. }
  29789. #endif /* HAVE_ECC512 */
  29790. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  29791. ret = ecc_test_curve(&rng, 66, ECC_CURVE_DEF);
  29792. if (ret < 0) {
  29793. printf("keySize=66, Default\n");
  29794. goto done;
  29795. }
  29796. #endif /* HAVE_ECC521 */
  29797. #ifdef WOLFSSL_SM2
  29798. ret = ecc_test_curve(&rng, 32, ECC_SM2P256V1);
  29799. if (ret < 0) {
  29800. printf("SM2\n");
  29801. goto done;
  29802. }
  29803. #endif
  29804. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29805. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29806. (HAVE_FIPS_VERSION > 2)))
  29807. ret = ecc_test_raw_enc_dec();
  29808. if (ret != 0) {
  29809. printf("raw sig encode/decode\n");
  29810. goto done;
  29811. }
  29812. #endif
  29813. #if defined(WOLFSSL_CUSTOM_CURVES)
  29814. ret = ecc_test_custom_curves(&rng);
  29815. if (ret != 0) {
  29816. printf("Custom\n");
  29817. goto done;
  29818. }
  29819. #endif
  29820. #if defined(WOLFSSL_SM2)
  29821. ret = test_sm2_verify();
  29822. if (ret != 0) {
  29823. printf("SM2 Verify\n");
  29824. goto done;
  29825. }
  29826. ret = ecc_sm2_test_curve(&rng, ECC_TEST_VERIFY_COUNT);
  29827. if (ret != 0) {
  29828. printf("SM2 test\n");
  29829. goto done;
  29830. }
  29831. #endif
  29832. #if defined(HAVE_ECC_SIGN) && \
  29833. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  29834. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  29835. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  29836. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29837. ret = ecc_test_deterministic_k(&rng);
  29838. if (ret != 0) {
  29839. printf("ecc_test_deterministic_k failed!\n");
  29840. goto done;
  29841. }
  29842. #endif
  29843. #ifdef WOLFSSL_PUBLIC_MP
  29844. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  29845. ECC_MIN_KEY_SZ <= 384
  29846. ret = ecc384_test_deterministic_k(&rng);
  29847. if (ret != 0) {
  29848. printf("ecc384_test_deterministic_k failed!\n");
  29849. goto done;
  29850. }
  29851. #endif
  29852. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && \
  29853. ECC_MIN_KEY_SZ <= 521
  29854. ret = ecc521_test_deterministic_k(&rng);
  29855. if (ret != 0) {
  29856. printf("ecc512_test_deterministic_k failed!\n");
  29857. goto done;
  29858. }
  29859. #endif
  29860. #endif
  29861. #endif
  29862. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  29863. !defined(WOLFSSL_KCAPI_ECC)
  29864. ret = ecc_test_sign_vectors(&rng);
  29865. if (ret != 0) {
  29866. printf("ecc_test_sign_vectors failed!\n");
  29867. goto done;
  29868. }
  29869. #endif
  29870. #if defined(HAVE_ECC_VECTOR_TEST) && defined(HAVE_ECC_CDH) && \
  29871. defined(HAVE_ECC_DHE)
  29872. ret = ecc_test_cdh_vectors(&rng);
  29873. if (ret != 0) {
  29874. printf("ecc_test_cdh_vectors failed!\n");
  29875. goto done;
  29876. }
  29877. #endif
  29878. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29879. !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
  29880. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  29881. ret = ecc_test_make_pub(&rng);
  29882. if (ret != 0) {
  29883. printf("ecc_test_make_pub failed!\n");
  29884. goto done;
  29885. }
  29886. #elif defined(HAVE_ECC_KEY_IMPORT)
  29887. (void)ecc_test_make_pub; /* for compiler warning */
  29888. #endif
  29889. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  29890. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  29891. ret = ecc_test_cert_gen(&rng);
  29892. if (ret != 0) {
  29893. printf("ecc_test_cert_gen failed!\n");
  29894. goto done;
  29895. }
  29896. #endif
  29897. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) && \
  29898. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && (!defined(NO_ECC_SECP) || \
  29899. defined(WOLFSSL_CUSTOM_CURVES))
  29900. ret = ecc_test_allocator(&rng);
  29901. if (ret != 0) {
  29902. printf("ecc_test_allocator failed!\n");
  29903. goto done;
  29904. }
  29905. #endif
  29906. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  29907. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29908. ret = ecc_test_nonblock(&rng);
  29909. if (ret != 0) {
  29910. printf("ecc_test_nonblock failed!\n");
  29911. goto done;
  29912. }
  29913. #endif
  29914. done:
  29915. wc_FreeRng(&rng);
  29916. return ret;
  29917. }
  29918. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  29919. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  29920. #if !defined(WOLFSSL_NO_MALLOC)
  29921. #if ((! defined(HAVE_FIPS)) || FIPS_VERSION_GE(5,3))
  29922. /* maximum encrypted message:
  29923. * msgSz (14) + pad (2) + pubKeySz(1+66*2) + ivSz(16) + digestSz(32) = 197 */
  29924. #define MAX_ECIES_TEST_SZ 200
  29925. static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
  29926. {
  29927. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29928. byte* plaintext;
  29929. byte* encrypted;
  29930. byte* decrypted;
  29931. #else
  29932. byte plaintext[MAX_ECIES_TEST_SZ];
  29933. byte encrypted[MAX_ECIES_TEST_SZ];
  29934. byte decrypted[MAX_ECIES_TEST_SZ];
  29935. #endif
  29936. ecEncCtx* aCtx = NULL;
  29937. ecEncCtx* bCtx = NULL;
  29938. static const byte salt[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  29939. 14, 15};
  29940. wc_test_ret_t ret = 0;
  29941. static const char message[] = "Hello wolfSSL!";
  29942. word32 plaintextLen;
  29943. word32 encryptLen = MAX_ECIES_TEST_SZ;
  29944. word32 decryptLen = MAX_ECIES_TEST_SZ;
  29945. int aInit = 0;
  29946. int bInit = 0;
  29947. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29948. plaintext = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29949. encrypted = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29950. decrypted = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29951. #endif
  29952. wc_ecc_free(a);
  29953. wc_ecc_free(b);
  29954. ret = wc_ecc_init(a);
  29955. if (ret != 0) {
  29956. ret = WC_TEST_RET_ENC_EC(ret);
  29957. }
  29958. else {
  29959. aInit = 1;
  29960. }
  29961. if (ret == 0) {
  29962. ret = wc_ecc_init(b);
  29963. if (ret != 0) {
  29964. ret = WC_TEST_RET_ENC_EC(ret);
  29965. }
  29966. else {
  29967. bInit = 1;
  29968. }
  29969. }
  29970. if (ret == 0)
  29971. ret = wc_ecc_make_key(rng, 32, a);
  29972. if (ret == 0)
  29973. ret = wc_ecc_make_key(rng, 32, b);
  29974. /* create context */
  29975. if (ret == 0) {
  29976. aCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  29977. if (aCtx == NULL)
  29978. ret = WC_TEST_RET_ENC_NC;
  29979. }
  29980. if (ret == 0) {
  29981. bCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  29982. if (bCtx == NULL)
  29983. ret = WC_TEST_RET_ENC_NC;
  29984. }
  29985. /* set salt */
  29986. if (ret == 0) {
  29987. ret = wc_ecc_ctx_set_kdf_salt(aCtx, salt, sizeof(salt));
  29988. if (ret != 0)
  29989. ret = 10472;
  29990. }
  29991. if (ret == 0) {
  29992. ret = wc_ecc_ctx_set_kdf_salt(bCtx, salt, sizeof(salt));
  29993. if (ret != 0)
  29994. ret = 10473;
  29995. }
  29996. XMEMSET(plaintext, 0, MAX_ECIES_TEST_SZ);
  29997. XSTRLCPY((char *)plaintext, message, sizeof plaintext);
  29998. plaintextLen = (((word32)XSTRLEN(message) + WC_AES_BLOCK_SIZE - 1) /
  29999. WC_AES_BLOCK_SIZE) * WC_AES_BLOCK_SIZE;
  30000. /* encrypt */
  30001. if (ret == 0) {
  30002. ret = wc_ecc_encrypt(a, b, plaintext, plaintextLen, encrypted,
  30003. &encryptLen, aCtx);
  30004. if (ret != 0)
  30005. ret = WC_TEST_RET_ENC_EC(ret);
  30006. }
  30007. /* decrypt */
  30008. if (ret == 0) {
  30009. ret = wc_ecc_decrypt(b, a, encrypted, encryptLen, decrypted,
  30010. &decryptLen, bCtx);
  30011. if (ret != 0)
  30012. ret = WC_TEST_RET_ENC_EC(ret);
  30013. }
  30014. /* compare */
  30015. if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
  30016. ret = WC_TEST_RET_ENC_NC;
  30017. if (aInit) {
  30018. wc_ecc_free(a);
  30019. }
  30020. if (bInit) {
  30021. wc_ecc_free(b);
  30022. }
  30023. wc_ecc_ctx_free(aCtx);
  30024. wc_ecc_ctx_free(bCtx);
  30025. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30026. XFREE(plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30027. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30028. XFREE(decrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30029. #endif
  30030. return ret;
  30031. }
  30032. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30033. #endif /* !WOLFSSL_NO_MALLOC */
  30034. /* ecc_encrypt_e2e_test() uses wc_ecc_ctx_set_algo(), which was added in
  30035. * wolfFIPS 5.3.
  30036. * ecc_encrypt_kat() is used only by ecc_encrypt_e2e_test().
  30037. */
  30038. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30039. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30040. ECC_MIN_KEY_SZ <= 256 && defined(WOLFSSL_AES_128)
  30041. static wc_test_ret_t ecc_encrypt_kat(WC_RNG *rng)
  30042. {
  30043. wc_test_ret_t ret = 0;
  30044. #ifdef WOLFSSL_ECIES_OLD
  30045. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30046. ecc_key* userA = NULL;
  30047. #else
  30048. ecc_key userA[1];
  30049. #endif
  30050. int userAInit = 0;
  30051. #endif
  30052. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30053. ecc_key* userB = NULL;
  30054. #else
  30055. ecc_key userB[1];
  30056. #endif
  30057. int userBInit = 0;
  30058. ecc_key* tmpKey;
  30059. byte plain[48];
  30060. word32 plainSz = sizeof(plain);
  30061. WOLFSSL_SMALL_STACK_STATIC const byte privKey[] = {
  30062. 0x04, 0x80, 0xef, 0x1d, 0xbe, 0x02, 0x0c, 0x20,
  30063. 0x5b, 0xab, 0x80, 0x35, 0x5b, 0x2a, 0x0f, 0x6d,
  30064. 0xd3, 0xb0, 0x7f, 0x7e, 0x7f, 0x86, 0x8a, 0x49,
  30065. 0xee, 0xb4, 0xaa, 0x09, 0x2d, 0x1e, 0x1d, 0x02
  30066. };
  30067. #if defined(WOLFSSL_ECIES_OLD) || defined(WOLFSSL_QNX_CAAM)
  30068. WOLFSSL_SMALL_STACK_STATIC const byte pubKey[] = {
  30069. 0x04,
  30070. /* X */
  30071. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30072. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30073. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30074. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30075. /* X */
  30076. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30077. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30078. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30079. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28
  30080. };
  30081. #endif
  30082. WOLFSSL_SMALL_STACK_STATIC const byte enc_msg[] = {
  30083. #ifdef WOLFSSL_ECIES_OLD
  30084. 0x42, 0x70, 0xbf, 0xf9, 0xf4, 0x7e, 0x4b, 0x9b,
  30085. 0xb5, 0x4c, 0xcc, 0xc5, 0x94, 0xa7, 0xef, 0xaa,
  30086. 0xc3, 0x7c, 0x85, 0xa6, 0x51, 0x6e, 0xd3, 0xfa,
  30087. 0x56, 0xc9, 0x10, 0x4d, 0x14, 0x32, 0x61, 0xb8,
  30088. 0xbb, 0x66, 0x7a, 0xb5, 0xbc, 0x95, 0xf8, 0xca,
  30089. 0xd1, 0x2a, 0x19, 0x51, 0x44, 0xd8, 0x0e, 0x57,
  30090. 0x34, 0xed, 0x45, 0x89, 0x2e, 0x57, 0xbe, 0xd5,
  30091. 0x06, 0x22, 0xd7, 0x13, 0x0a, 0x0e, 0x40, 0x36,
  30092. 0x0d, 0x05, 0x0d, 0xb6, 0xae, 0x61, 0x37, 0x18,
  30093. 0x83, 0x90, 0x0a, 0x27, 0x95, 0x41, 0x8c, 0x45
  30094. #elif defined(WOLFSSL_ECIES_ISO18033)
  30095. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30096. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30097. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30098. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30099. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30100. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30101. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30102. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30103. 0x28, 0xbb, 0x9f, 0xa8, 0x2d, 0xe1, 0xf1, 0x67,
  30104. 0x45, 0x02, 0x19, 0xdc, 0xc8, 0x24, 0x8b, 0x20,
  30105. 0x02, 0xa0, 0x8f, 0x95, 0x12, 0x55, 0x51, 0xf8,
  30106. 0x03, 0xc4, 0x54, 0x13, 0x98, 0x2d, 0xf0, 0x31,
  30107. 0x51, 0x80, 0x45, 0x24, 0xcb, 0x8b, 0x48, 0xa6,
  30108. 0x8b, 0x8e, 0x97, 0x9c, 0x56, 0x4d, 0x70, 0x00,
  30109. 0x53, 0xd3, 0x47, 0x00, 0x5a, 0x23, 0x8c, 0xf9,
  30110. 0xfd, 0xd2, 0x33, 0x2c, 0x43, 0x6e, 0x9e, 0xb2,
  30111. 0xf4, 0x95, 0xd4, 0xcf, 0x30, 0xd6, 0xa2, 0xc5,
  30112. 0x35, 0x96, 0x6a, 0xd4, 0x36, 0x15, 0xa9, 0xbd,
  30113. 0x7f
  30114. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30115. /* EC P-256 point */
  30116. 0x04,
  30117. /* X */
  30118. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30119. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30120. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30121. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30122. /* Y */
  30123. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30124. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30125. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30126. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28,
  30127. /* IV */
  30128. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30129. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30130. /* Encrypted Msg */
  30131. 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d, 0x50,
  30132. 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c, 0x1f,
  30133. 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc, 0x44,
  30134. 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca, 0x65,
  30135. 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61, 0xbd,
  30136. 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1, 0xde,
  30137. /* HMAC */
  30138. 0x5a, 0x22, 0xc1, 0x5d, 0x99, 0x66, 0x3f, 0x24,
  30139. 0x35, 0x96, 0xac, 0xf7, 0xf6, 0x28, 0x45, 0x16,
  30140. 0x52, 0x19, 0x0d, 0xe4, 0xb2, 0xca, 0x5b, 0x28,
  30141. 0x4e, 0xbb, 0xf3, 0x98, 0x57, 0xd7, 0x3b, 0xe2
  30142. #else
  30143. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30144. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30145. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30146. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30147. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30148. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30149. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30150. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30151. 0x28, 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d,
  30152. 0x50, 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c,
  30153. 0x1f, 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc,
  30154. 0x44, 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca,
  30155. 0x65, 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61,
  30156. 0xbd, 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1,
  30157. 0xde, 0xc7, 0x3f, 0x6f, 0xce, 0xbe, 0x49, 0x61,
  30158. 0x48, 0x01, 0x77, 0x41, 0xd0, 0xd8, 0x5b, 0x48,
  30159. 0xca, 0x4e, 0x47, 0x3e, 0x47, 0xbf, 0x1d, 0x28,
  30160. 0x4c, 0x18, 0x1a, 0xfb, 0x96, 0x95, 0xda, 0xde,
  30161. 0x55
  30162. #endif
  30163. };
  30164. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  30165. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  30166. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  30167. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  30168. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  30169. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  30170. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  30171. };
  30172. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30173. userB = (ecc_key *)XMALLOC(sizeof(*userB), HEAP_HINT,
  30174. DYNAMIC_TYPE_TMP_BUFFER);
  30175. if (userB == NULL) {
  30176. ret = WC_TEST_RET_ENC_ERRNO;
  30177. }
  30178. #ifdef WOLFSSL_ECIES_OLD
  30179. if (ret == 0) {
  30180. userA = (ecc_key *)XMALLOC(sizeof(*userA), HEAP_HINT,
  30181. DYNAMIC_TYPE_TMP_BUFFER);
  30182. if (userA == NULL) {
  30183. ret = WC_TEST_RET_ENC_ERRNO;
  30184. }
  30185. }
  30186. #endif
  30187. #endif
  30188. if (ret == 0) {
  30189. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30190. if (ret != 0)
  30191. ret = WC_TEST_RET_ENC_EC(ret);
  30192. }
  30193. if (ret == 0) {
  30194. userBInit = 1;
  30195. #ifdef WOLFSSL_ECIES_OLD
  30196. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30197. if (ret != 0)
  30198. ret = WC_TEST_RET_ENC_EC(ret);
  30199. }
  30200. if (ret == 0) {
  30201. userAInit = 1;
  30202. tmpKey = userA;
  30203. #else
  30204. tmpKey = NULL;
  30205. #endif
  30206. }
  30207. if (ret == 0) {
  30208. #ifdef WOLFSSL_QNX_CAAM
  30209. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), pubKey,
  30210. sizeof(pubKey), userB, ECC_SECP256R1);
  30211. #else
  30212. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), NULL, 0,
  30213. userB, ECC_SECP256R1);
  30214. #endif
  30215. if (ret != 0)
  30216. ret = WC_TEST_RET_ENC_EC(ret);
  30217. }
  30218. #ifdef WOLFSSL_ECIES_OLD
  30219. if (ret == 0) {
  30220. ret = wc_ecc_import_x963_ex(pubKey, sizeof(pubKey), userA,
  30221. ECC_SECP256R1);
  30222. if (ret != 0)
  30223. ret = WC_TEST_RET_ENC_EC(ret);
  30224. }
  30225. #endif
  30226. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30227. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30228. !defined(HAVE_SELFTEST)
  30229. if (ret == 0) {
  30230. ret = wc_ecc_set_rng(userB, rng);
  30231. if (ret != 0) {
  30232. ret = WC_TEST_RET_ENC_EC(ret);
  30233. }
  30234. }
  30235. #else
  30236. (void)rng;
  30237. #endif
  30238. if (ret == 0) {
  30239. ret = wc_ecc_decrypt(userB, tmpKey, enc_msg, sizeof(enc_msg), plain,
  30240. &plainSz, NULL);
  30241. if (ret != 0)
  30242. ret = WC_TEST_RET_ENC_EC(ret);
  30243. }
  30244. if (ret == 0) {
  30245. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30246. ret = WC_TEST_RET_ENC_NC;
  30247. }
  30248. }
  30249. if (userBInit)
  30250. wc_ecc_free(userB);
  30251. #ifdef WOLFSSL_ECIES_OLD
  30252. if (userAInit)
  30253. wc_ecc_free(userA);
  30254. #endif
  30255. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30256. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30257. #ifdef WOLFSSL_ECIES_OLD
  30258. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30259. #endif
  30260. #endif
  30261. return ret;
  30262. }
  30263. #endif
  30264. #ifndef WOLFSSL_NO_MALLOC
  30265. static wc_test_ret_t ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB,
  30266. byte encAlgo, byte kdfAlgo, byte macAlgo)
  30267. {
  30268. wc_test_ret_t ret = 0;
  30269. byte msg[48];
  30270. byte plain[48];
  30271. #ifdef WOLFSSL_ECIES_OLD
  30272. byte out[80];
  30273. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30274. byte out[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30275. #else
  30276. byte out[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30277. #endif
  30278. word32 outSz = sizeof(out);
  30279. word32 plainSz = sizeof(plain);
  30280. int i;
  30281. ecEncCtx* cliCtx = NULL;
  30282. ecEncCtx* srvCtx = NULL;
  30283. byte cliSalt[EXCHANGE_SALT_SZ];
  30284. byte srvSalt[EXCHANGE_SALT_SZ];
  30285. const byte* tmpSalt;
  30286. byte msg2[48];
  30287. byte plain2[48];
  30288. #ifdef WOLFSSL_ECIES_OLD
  30289. byte out2[80];
  30290. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30291. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30292. #else
  30293. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30294. #endif
  30295. word32 outSz2 = sizeof(out2);
  30296. word32 plainSz2 = sizeof(plain2);
  30297. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30298. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof(ecc_key), HEAP_HINT,
  30299. DYNAMIC_TYPE_TMP_BUFFER);
  30300. #else
  30301. ecc_key tmpKey[1];
  30302. #endif
  30303. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30304. if (tmpKey == NULL) {
  30305. ERROR_OUT(MEMORY_E, done);
  30306. }
  30307. #endif
  30308. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30309. if (ret != 0)
  30310. goto done;
  30311. /* set message to incrementing 0,1,2,etc... */
  30312. for (i = 0; i < (int)sizeof(msg); i++)
  30313. msg[i] = i;
  30314. /* encrypt msg to B */
  30315. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz, NULL);
  30316. if (ret != 0) {
  30317. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30318. }
  30319. #ifdef WOLFSSL_ECIES_OLD
  30320. tmpKey->dp = userA->dp;
  30321. ret = wc_ecc_copy_point(&userA->pubkey, &tmpKey->pubkey);
  30322. if (ret != 0) {
  30323. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30324. }
  30325. #endif
  30326. /* decrypt msg from A */
  30327. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, NULL);
  30328. if (ret != 0) {
  30329. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30330. }
  30331. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30332. ret = WC_TEST_RET_ENC_NC; goto done;
  30333. }
  30334. #ifndef WOLFSSL_ECIES_OLD
  30335. /* A decrypts msg (response) from B */
  30336. ret = wc_ecc_decrypt(userB, NULL, out, outSz, plain2, &plainSz2, NULL);
  30337. if (ret != 0)
  30338. goto done;
  30339. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30340. ret = WC_TEST_RET_ENC_NC; goto done;
  30341. }
  30342. #endif
  30343. /* let's verify message exchange works, A is client, B is server */
  30344. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30345. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30346. if (cliCtx == NULL || srvCtx == NULL) {
  30347. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30348. }
  30349. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30350. if (ret != 0)
  30351. goto done;
  30352. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30353. if (ret != 0)
  30354. goto done;
  30355. /* get salt to send to peer */
  30356. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30357. if (tmpSalt == NULL) {
  30358. ret = WC_TEST_RET_ENC_NC; goto done;
  30359. }
  30360. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30361. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30362. if (tmpSalt == NULL) {
  30363. ret = WC_TEST_RET_ENC_NC; goto done;
  30364. }
  30365. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30366. /* in actual use, we'd get the peer's salt over the transport */
  30367. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30368. if (ret != 0)
  30369. goto done;
  30370. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30371. if (ret != 0)
  30372. goto done;
  30373. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 11);
  30374. if (ret != 0)
  30375. goto done;
  30376. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 11);
  30377. if (ret != 0)
  30378. goto done;
  30379. /* get encrypted msg (request) to send to B */
  30380. outSz = sizeof(out);
  30381. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz,cliCtx);
  30382. if (ret != 0)
  30383. goto done;
  30384. #ifndef WOLFSSL_ECIES_OLD
  30385. wc_ecc_free(tmpKey);
  30386. #endif
  30387. /* B decrypts msg (request) from A */
  30388. plainSz = sizeof(plain);
  30389. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30390. if (ret != 0)
  30391. goto done;
  30392. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30393. ret = WC_TEST_RET_ENC_NC; goto done;
  30394. }
  30395. /* msg2 (response) from B to A */
  30396. for (i = 0; i < (int)sizeof(msg2); i++)
  30397. msg2[i] = i + sizeof(msg2);
  30398. /* get encrypted msg (response) to send to B */
  30399. ret = wc_ecc_encrypt(userB, userA, msg2, sizeof(msg2), out2,
  30400. &outSz2, srvCtx);
  30401. if (ret != 0)
  30402. goto done;
  30403. #ifdef WOLFSSL_ECIES_OLD
  30404. tmpKey->dp = userB->dp;
  30405. ret = wc_ecc_copy_point(&userB->pubkey, &tmpKey->pubkey);
  30406. if (ret != 0) {
  30407. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30408. }
  30409. #else
  30410. wc_ecc_free(tmpKey);
  30411. #endif
  30412. /* A decrypts msg (response) from B */
  30413. ret = wc_ecc_decrypt(userA, tmpKey, out2, outSz2, plain2, &plainSz2,
  30414. cliCtx);
  30415. if (ret != 0)
  30416. goto done;
  30417. if (XMEMCMP(plain2, msg2, sizeof(msg2)) != 0) {
  30418. ret = WC_TEST_RET_ENC_NC; goto done;
  30419. }
  30420. #if defined(HAVE_COMP_KEY) && \
  30421. (! defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  30422. /* Create new client and server contexts. */
  30423. wc_ecc_ctx_free(srvCtx);
  30424. wc_ecc_ctx_free(cliCtx);
  30425. /* let's verify message exchange works, A is client, B is server */
  30426. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30427. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30428. if (cliCtx == NULL || srvCtx == NULL) {
  30429. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30430. }
  30431. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30432. if (ret != 0)
  30433. goto done;
  30434. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30435. if (ret != 0)
  30436. goto done;
  30437. /* get salt to send to peer */
  30438. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30439. if (tmpSalt == NULL) {
  30440. ret = WC_TEST_RET_ENC_NC; goto done;
  30441. }
  30442. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30443. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30444. if (tmpSalt == NULL) {
  30445. ret = WC_TEST_RET_ENC_NC; goto done;
  30446. }
  30447. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30448. /* in actual use, we'd get the peer's salt over the transport */
  30449. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30450. if (ret != 0)
  30451. goto done;
  30452. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30453. if (ret != 0)
  30454. goto done;
  30455. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 12);
  30456. if (ret != 0)
  30457. goto done;
  30458. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 12);
  30459. if (ret != 0)
  30460. goto done;
  30461. /* get encrypted msg (request) to send to B - compressed public key */
  30462. outSz = sizeof(out);
  30463. ret = wc_ecc_encrypt_ex(userA, userB, msg, sizeof(msg), out, &outSz, cliCtx,
  30464. 1);
  30465. if (ret != 0)
  30466. goto done;
  30467. #ifndef WOLFSSL_ECIES_OLD
  30468. wc_ecc_free(tmpKey);
  30469. #endif
  30470. /* B decrypts msg (request) from A - out has a compressed public key */
  30471. plainSz = sizeof(plain);
  30472. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30473. if (ret != 0)
  30474. goto done;
  30475. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30476. ret = WC_TEST_RET_ENC_NC; goto done;
  30477. }
  30478. #endif /* HAVE_COMP_KEY && (!FIPS || FIPS>=5.3) */
  30479. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30480. (ECC_MIN_KEY_SZ <= 256) && defined(WOLFSSL_AES_128)
  30481. ret = ecc_encrypt_kat(rng);
  30482. #endif
  30483. done:
  30484. /* cleanup */
  30485. wc_ecc_ctx_free(srvCtx);
  30486. wc_ecc_ctx_free(cliCtx);
  30487. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30488. if (tmpKey != NULL) {
  30489. wc_ecc_free(tmpKey);
  30490. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30491. }
  30492. #else
  30493. wc_ecc_free(tmpKey);
  30494. #endif
  30495. return ret;
  30496. }
  30497. #endif
  30498. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30499. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void)
  30500. {
  30501. WC_RNG rng;
  30502. wc_test_ret_t ret;
  30503. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30504. ecc_key *userA;
  30505. ecc_key *userB;
  30506. #else
  30507. ecc_key userA[1];
  30508. ecc_key userB[1];
  30509. #endif
  30510. WOLFSSL_ENTER("ecc_encrypt_test");
  30511. #ifndef HAVE_FIPS
  30512. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30513. #else
  30514. ret = wc_InitRng(&rng);
  30515. #endif
  30516. if (ret != 0)
  30517. return WC_TEST_RET_ENC_EC(ret);
  30518. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30519. userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT,
  30520. DYNAMIC_TYPE_TMP_BUFFER);
  30521. userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT,
  30522. DYNAMIC_TYPE_TMP_BUFFER);
  30523. if ((userA == NULL) || (userB == NULL)) {
  30524. ERROR_OUT(MEMORY_E, done);
  30525. }
  30526. #endif
  30527. XMEMSET(userA, 0, sizeof *userA);
  30528. XMEMSET(userB, 0, sizeof *userB);
  30529. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30530. if (ret != 0)
  30531. goto done;
  30532. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30533. if (ret != 0)
  30534. goto done;
  30535. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userA);
  30536. #if defined(WOLFSSL_ASYNC_CRYPT)
  30537. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  30538. #endif
  30539. if (ret != 0){
  30540. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30541. }
  30542. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userB);
  30543. #if defined(WOLFSSL_ASYNC_CRYPT)
  30544. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  30545. #endif
  30546. if (ret != 0){
  30547. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30548. }
  30549. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30550. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30551. !defined(HAVE_SELFTEST)
  30552. ret = wc_ecc_set_rng(userA, &rng);
  30553. if (ret != 0) {
  30554. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30555. }
  30556. ret = wc_ecc_set_rng(userB, &rng);
  30557. if (ret != 0) {
  30558. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30559. }
  30560. #endif
  30561. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30562. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30563. #ifdef WOLFSSL_AES_128
  30564. if (ret == 0) {
  30565. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30566. ecHKDF_SHA256, ecHMAC_SHA256);
  30567. if (ret != 0) {
  30568. printf("ECIES: AES_128_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30569. }
  30570. }
  30571. #ifdef HAVE_X963_KDF
  30572. if (ret == 0) {
  30573. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30574. ecKDF_X963_SHA256, ecHMAC_SHA256);
  30575. if (ret != 0) {
  30576. printf("ECIES: AES_128_CBC, KDF_X963_SHA256, HMAC_SHA256\n");
  30577. }
  30578. }
  30579. if (ret == 0) {
  30580. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30581. ecKDF_SHA256, ecHMAC_SHA256);
  30582. if (ret != 0) {
  30583. printf("ECIES: AES_128_CBC, KDF_SHA256, HMAC_SHA256\n");
  30584. }
  30585. }
  30586. #endif
  30587. #endif
  30588. #ifdef WOLFSSL_AES_256
  30589. if (ret == 0) {
  30590. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CBC,
  30591. ecHKDF_SHA256, ecHMAC_SHA256);
  30592. if (ret != 0) {
  30593. printf("ECIES: AES_256_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30594. }
  30595. }
  30596. #endif
  30597. #endif
  30598. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && !defined(WOLFSSL_NO_MALLOC)
  30599. #ifdef WOLFSSL_AES_128
  30600. if (ret == 0) {
  30601. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CTR,
  30602. ecHKDF_SHA256, ecHMAC_SHA256);
  30603. if (ret != 0) {
  30604. printf("ECIES: AES_128_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30605. }
  30606. }
  30607. #endif
  30608. #ifdef WOLFSSL_AES_256
  30609. if (ret == 0) {
  30610. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CTR,
  30611. ecHKDF_SHA256, ecHMAC_SHA256);
  30612. if (ret != 0) {
  30613. printf("ECIES: AES_256_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30614. }
  30615. }
  30616. #endif
  30617. #endif /* !NO_AES && WOLFSSL_AES_COUNTER */
  30618. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30619. if (ret == 0) {
  30620. ret = ecc_ctx_kdf_salt_test(&rng, userA, userB);
  30621. }
  30622. #endif
  30623. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30624. done:
  30625. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30626. if (userA != NULL) {
  30627. wc_ecc_free(userA);
  30628. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30629. }
  30630. if (userB != NULL) {
  30631. wc_ecc_free(userB);
  30632. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30633. }
  30634. #else
  30635. wc_ecc_free(userB);
  30636. wc_ecc_free(userA);
  30637. #endif
  30638. wc_FreeRng(&rng);
  30639. return ret;
  30640. }
  30641. #endif /* HAVE_ECC_ENCRYPT && HAVE_AES_CBC && WOLFSSL_AES_128 */
  30642. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  30643. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  30644. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  30645. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  30646. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void)
  30647. {
  30648. size_t bytes;
  30649. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30650. ecc_key *cliKey = (ecc_key *)XMALLOC(sizeof *cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30651. ecc_key *servKey = (ecc_key *)XMALLOC(sizeof *servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30652. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof *tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30653. #else
  30654. ecc_key cliKey[1];
  30655. ecc_key servKey[1];
  30656. ecc_key tmpKey[1];
  30657. #endif
  30658. WC_RNG rng;
  30659. word32 idx = 0;
  30660. wc_test_ret_t ret;
  30661. /* pad our test message to 32 bytes so evenly divisible by AES_BLOCK_SZ */
  30662. byte in[] = "Everyone gets Friday off. ecc p";
  30663. word32 inLen = (word32)XSTRLEN((char*)in);
  30664. byte out[256];
  30665. byte plain[256];
  30666. int verify = 0;
  30667. word32 x;
  30668. WOLFSSL_ENTER("ecc_test_buffers");
  30669. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30670. if ((cliKey == NULL) || (servKey == NULL) || (tmpKey == NULL))
  30671. ERROR_OUT(MEMORY_E, done);
  30672. #endif
  30673. ret = wc_ecc_init_ex(cliKey, HEAP_HINT, devId);
  30674. if (ret != 0)
  30675. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30676. ret = wc_ecc_init_ex(servKey, HEAP_HINT, devId);
  30677. if (ret != 0)
  30678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30679. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30680. if (ret != 0)
  30681. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30682. bytes = (size_t)sizeof_ecc_clikey_der_256;
  30683. /* place client key into ecc_key struct cliKey */
  30684. ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, cliKey,
  30685. (word32)bytes);
  30686. if (ret != 0)
  30687. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30688. idx = 0;
  30689. bytes = (size_t)sizeof_ecc_key_der_256;
  30690. /* place server key into ecc_key struct servKey */
  30691. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, servKey,
  30692. (word32)bytes);
  30693. if (ret != 0)
  30694. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30695. #ifndef WC_NO_RNG
  30696. #ifndef HAVE_FIPS
  30697. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30698. #else
  30699. ret = wc_InitRng(&rng);
  30700. #endif
  30701. if (ret != 0)
  30702. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30703. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30704. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30705. !defined(HAVE_SELFTEST)
  30706. ret = wc_ecc_set_rng(cliKey, &rng);
  30707. if (ret != 0)
  30708. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30709. ret = wc_ecc_set_rng(servKey, &rng);
  30710. if (ret != 0)
  30711. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30712. #endif
  30713. #endif /* !WC_NO_RNG */
  30714. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_HKDF) && \
  30715. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  30716. {
  30717. word32 y;
  30718. /* test encrypt and decrypt if they're available */
  30719. x = sizeof(out);
  30720. ret = wc_ecc_encrypt(cliKey, servKey, in, sizeof(in), out, &x, NULL);
  30721. if (ret < 0)
  30722. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30723. #ifdef WOLFSSL_ECIES_OLD
  30724. tmpKey->dp = cliKey->dp;
  30725. ret = wc_ecc_copy_point(&cliKey->pubkey, &tmpKey->pubkey);
  30726. if (ret != 0) {
  30727. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30728. }
  30729. #endif
  30730. y = sizeof(plain);
  30731. ret = wc_ecc_decrypt(servKey, tmpKey, out, x, plain, &y, NULL);
  30732. if (ret < 0)
  30733. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30734. if (XMEMCMP(plain, in, inLen))
  30735. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30736. }
  30737. #endif
  30738. x = sizeof(out);
  30739. do {
  30740. #if defined(WOLFSSL_ASYNC_CRYPT)
  30741. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30742. #endif
  30743. if (ret == 0)
  30744. ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, cliKey);
  30745. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30746. if (ret < 0)
  30747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30748. TEST_SLEEP();
  30749. XMEMSET(plain, 0, sizeof(plain));
  30750. do {
  30751. #if defined(WOLFSSL_ASYNC_CRYPT)
  30752. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30753. #endif
  30754. if (ret == 0)
  30755. ret = wc_ecc_verify_hash(out, x, in, inLen, &verify,
  30756. cliKey);
  30757. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30758. if (ret < 0)
  30759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30760. if (verify != 1)
  30761. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30762. TEST_SLEEP();
  30763. #ifdef WOLFSSL_CERT_EXT
  30764. idx = 0;
  30765. bytes = sizeof_ecc_clikeypub_der_256;
  30766. ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &idx, cliKey,
  30767. (word32) bytes);
  30768. if (ret != 0)
  30769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30770. #endif
  30771. ret = 0;
  30772. done:
  30773. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30774. if (cliKey != NULL) {
  30775. wc_ecc_free(cliKey);
  30776. XFREE(cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30777. }
  30778. if (servKey != NULL) {
  30779. wc_ecc_free(servKey);
  30780. XFREE(servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30781. }
  30782. if (tmpKey != NULL) {
  30783. wc_ecc_free(tmpKey);
  30784. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30785. }
  30786. #else
  30787. wc_ecc_free(cliKey);
  30788. wc_ecc_free(servKey);
  30789. wc_ecc_free(tmpKey);
  30790. #endif
  30791. wc_FreeRng(&rng);
  30792. return ret;
  30793. }
  30794. #endif /* USE_CERT_BUFFERS_256 && !WOLFSSL_ATECCX08A && !NO_ECC256 */
  30795. #endif /* HAVE_ECC */
  30796. #ifdef HAVE_CURVE25519
  30797. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  30798. defined(HAVE_CURVE25519_KEY_IMPORT)
  30799. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30800. #define X25519_TEST_CNT 5
  30801. #else
  30802. #define X25519_TEST_CNT 1
  30803. #endif
  30804. static wc_test_ret_t curve25519_overflow_test(void)
  30805. {
  30806. /* secret key for party a */
  30807. byte sa[X25519_TEST_CNT][32] = {
  30808. {
  30809. 0x8d,0xaf,0x6e,0x7a,0xc1,0xeb,0x8d,0x30,
  30810. 0x99,0x86,0xd3,0x90,0x47,0x96,0x21,0x3c,
  30811. 0x3a,0x75,0xc0,0x7b,0x75,0x01,0x75,0xa3,
  30812. 0x81,0x4b,0xff,0x5a,0xbc,0x96,0x87,0x28
  30813. },
  30814. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30815. {
  30816. 0x9d,0x63,0x5f,0xce,0xe2,0xe8,0xd7,0xfb,
  30817. 0x68,0x77,0x0e,0x44,0xd1,0xad,0x87,0x2b,
  30818. 0xf4,0x65,0x06,0xb7,0xbb,0xdb,0xbe,0x6e,
  30819. 0x02,0x43,0x24,0xc7,0x3d,0x7b,0x88,0x60
  30820. },
  30821. {
  30822. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30823. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30824. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30825. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30826. },
  30827. {
  30828. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30829. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30830. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30831. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30832. },
  30833. {
  30834. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30835. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30836. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30837. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30838. }
  30839. #endif
  30840. };
  30841. /* public key for party b */
  30842. byte pb[X25519_TEST_CNT][32] = {
  30843. {
  30844. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30845. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30846. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30847. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30848. },
  30849. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30850. {
  30851. /* 0xff first byte in original - invalid! */
  30852. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30853. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30854. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30855. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30856. },
  30857. {
  30858. 0x36,0x1a,0x74,0x87,0x28,0x59,0xe0,0xb6,
  30859. 0xe4,0x2b,0x17,0x9b,0x16,0xb0,0x3b,0xf8,
  30860. 0xb8,0x9f,0x2a,0x8f,0xc5,0x33,0x68,0x4f,
  30861. 0xde,0x4d,0xd8,0x80,0x63,0xe7,0xb4,0x0a
  30862. },
  30863. {
  30864. 0x00,0x80,0x38,0x59,0x19,0x3a,0x66,0x12,
  30865. 0xfd,0xa1,0xec,0x1c,0x40,0x84,0x40,0xbd,
  30866. 0x64,0x10,0x8b,0x53,0x81,0x21,0x03,0x2d,
  30867. 0x7d,0x33,0xb4,0x01,0x57,0x0d,0xe1,0x89
  30868. },
  30869. {
  30870. 0x1d,0xf8,0xf8,0x33,0x89,0x6c,0xb7,0xba,
  30871. 0x94,0x73,0xfa,0xc2,0x36,0xac,0xbe,0x49,
  30872. 0xaf,0x85,0x3e,0x93,0x5f,0xae,0xb2,0xc0,
  30873. 0xc8,0x80,0x8f,0x4a,0xaa,0xd3,0x55,0x2b
  30874. }
  30875. #endif
  30876. };
  30877. /* expected shared key */
  30878. byte ss[X25519_TEST_CNT][32] = {
  30879. {
  30880. 0x5c,0x4c,0x85,0x5f,0xfb,0x20,0x38,0xcc,
  30881. 0x55,0x16,0x5b,0x8a,0xa7,0xed,0x57,0x6e,
  30882. 0x35,0xaa,0x71,0x67,0x85,0x1f,0xb6,0x28,
  30883. 0x17,0x07,0x7b,0xda,0x76,0xdd,0xe0,0xb4
  30884. },
  30885. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30886. {
  30887. 0x33,0xf6,0xc1,0x34,0x62,0x92,0x06,0x02,
  30888. 0x95,0xdb,0x91,0x4c,0x5d,0x52,0x54,0xc7,
  30889. 0xd2,0x5b,0x24,0xb5,0x4f,0x33,0x59,0x79,
  30890. 0x9f,0x6d,0x7e,0x4a,0x4c,0x30,0xd6,0x38
  30891. },
  30892. {
  30893. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  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,0x02
  30897. },
  30898. {
  30899. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  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,0x09
  30903. },
  30904. {
  30905. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30906. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30907. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30908. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10
  30909. }
  30910. #endif
  30911. };
  30912. wc_test_ret_t ret = 0;
  30913. int i;
  30914. word32 y;
  30915. byte shared[32];
  30916. curve25519_key userA;
  30917. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  30918. for (i = 0; i < X25519_TEST_CNT; i++) {
  30919. if (wc_curve25519_import_private_raw(sa[i], sizeof(sa[i]), pb[i],
  30920. sizeof(pb[i]), &userA) != 0) {
  30921. ret = WC_TEST_RET_ENC_I(i); break;
  30922. }
  30923. /* test against known test vector */
  30924. XMEMSET(shared, 0, sizeof(shared));
  30925. y = sizeof(shared);
  30926. if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) {
  30927. ret = WC_TEST_RET_ENC_I(i); break;
  30928. }
  30929. if (XMEMCMP(ss[i], shared, y)) {
  30930. ret = WC_TEST_RET_ENC_I(i); break;
  30931. }
  30932. }
  30933. wc_curve25519_free(&userA);
  30934. return ret;
  30935. }
  30936. /* Test the wc_curve25519_check_public API.
  30937. *
  30938. * returns 0 on success and -ve on failure.
  30939. */
  30940. static wc_test_ret_t curve25519_check_public_test(void)
  30941. {
  30942. wc_test_ret_t ret;
  30943. /* Little-endian values that will fail */
  30944. byte fail_le[][CURVE25519_KEYSIZE] = {
  30945. {
  30946. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30947. 0x00,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. },
  30951. {
  30952. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30953. 0x00,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. },
  30957. {
  30958. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30959. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30960. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30961. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81
  30962. },
  30963. };
  30964. /* Big-endian values that will fail */
  30965. byte fail_be[][CURVE25519_KEYSIZE] = {
  30966. {
  30967. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  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. },
  30972. {
  30973. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30974. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30975. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30976. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30977. },
  30978. {
  30979. 0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30980. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30981. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30982. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30983. },
  30984. };
  30985. /* Good or valid public value */
  30986. byte good[CURVE25519_KEYSIZE] = {
  30987. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30988. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30989. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30990. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30991. };
  30992. int i;
  30993. /* Parameter checks */
  30994. /* NULL pointer */
  30995. ret = wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN);
  30996. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30997. return WC_TEST_RET_ENC_EC(ret);
  30998. }
  30999. ret = wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN);
  31000. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  31001. return WC_TEST_RET_ENC_EC(ret);
  31002. }
  31003. /* Length of 0 treated differently to other invalid lengths for TLS */
  31004. ret = wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN);
  31005. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31006. return WC_TEST_RET_ENC_EC(ret);
  31007. ret = wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN);
  31008. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31009. return WC_TEST_RET_ENC_EC(ret);
  31010. /* Length not CURVE25519_KEYSIZE */
  31011. for (i = 1; i < CURVE25519_KEYSIZE + 2; i++) {
  31012. if (i == CURVE25519_KEYSIZE)
  31013. continue;
  31014. if (wc_curve25519_check_public(good, (word32)i, EC25519_LITTLE_ENDIAN) !=
  31015. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31016. return WC_TEST_RET_ENC_I(i);
  31017. }
  31018. if (wc_curve25519_check_public(good, (word32)i, EC25519_BIG_ENDIAN) !=
  31019. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31020. return WC_TEST_RET_ENC_I(i);
  31021. }
  31022. }
  31023. /* Little-endian fail cases */
  31024. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  31025. if (wc_curve25519_check_public(fail_le[i], CURVE25519_KEYSIZE,
  31026. EC25519_LITTLE_ENDIAN) == 0) {
  31027. return WC_TEST_RET_ENC_I(i);
  31028. }
  31029. }
  31030. /* Big-endian fail cases */
  31031. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  31032. if (wc_curve25519_check_public(fail_be[i], CURVE25519_KEYSIZE,
  31033. EC25519_BIG_ENDIAN) == 0) {
  31034. return WC_TEST_RET_ENC_I(i);
  31035. }
  31036. }
  31037. /* Check a valid public value works! */
  31038. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31039. EC25519_LITTLE_ENDIAN);
  31040. if (ret != 0) {
  31041. return WC_TEST_RET_ENC_EC(ret);
  31042. }
  31043. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31044. EC25519_BIG_ENDIAN);
  31045. if (ret != 0) {
  31046. return WC_TEST_RET_ENC_EC(ret);
  31047. }
  31048. return 0;
  31049. }
  31050. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31051. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31052. defined(HAVE_CURVE25519_KEY_IMPORT)
  31053. static wc_test_ret_t curve255519_der_test(void)
  31054. {
  31055. wc_test_ret_t ret = 0;
  31056. /* certs/statickeys/x25519.der */
  31057. const byte kCurve25519PrivDer[] = {
  31058. 0x30, 0x2E, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E,
  31059. 0x04, 0x22, 0x04, 0x20, 0x78, 0x8E, 0x31, 0x5C, 0x33, 0xA9, 0x19, 0xC0,
  31060. 0x5E, 0x36, 0x70, 0x1B, 0xA4, 0xE8, 0xEF, 0xC1, 0x89, 0x8C, 0xB3, 0x15,
  31061. 0xC6, 0x79, 0xD3, 0xAC, 0x22, 0x00, 0xAE, 0xFA, 0xB3, 0xB7, 0x0F, 0x78
  31062. };
  31063. /* certs/statickeys/x25519-pub.der */
  31064. const byte kCurve25519PubDer[] = {
  31065. 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00,
  31066. 0x09, 0xBC, 0x8C, 0xC7, 0x45, 0x0D, 0xC1, 0xC2, 0x02, 0x57, 0x9A, 0x68,
  31067. 0x3A, 0xFD, 0x7A, 0xA8, 0xA5, 0x2F, 0xF0, 0x99, 0x39, 0x98, 0xEA, 0x26,
  31068. 0xA2, 0x5B, 0x38, 0xFD, 0x96, 0xDB, 0x2A, 0x26
  31069. };
  31070. curve25519_key key;
  31071. byte output[128];
  31072. word32 outputSz = 128;
  31073. word32 idx;
  31074. ret = wc_curve25519_init_ex(&key, HEAP_HINT, devId);
  31075. if (ret != 0)
  31076. return WC_TEST_RET_ENC_EC(ret);
  31077. /* Test decode / encode of Curve25519 private key only */
  31078. if (ret == 0) {
  31079. idx = 0;
  31080. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx, &key,
  31081. (word32)sizeof(kCurve25519PrivDer));
  31082. if (ret < 0)
  31083. ret = WC_TEST_RET_ENC_EC(ret);
  31084. }
  31085. if (ret == 0) {
  31086. outputSz = (word32)sizeof(output);
  31087. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31088. if (ret >= 0) {
  31089. outputSz = (word32)ret;
  31090. ret = 0;
  31091. }
  31092. else {
  31093. ret = WC_TEST_RET_ENC_EC(ret);
  31094. }
  31095. }
  31096. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31097. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31098. ret = WC_TEST_RET_ENC_NC;
  31099. }
  31100. /* Test decode / encode of Curve25519 public key only */
  31101. if (ret == 0) {
  31102. idx = 0;
  31103. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx, &key,
  31104. (word32)sizeof(kCurve25519PubDer));
  31105. if (ret < 0)
  31106. ret = WC_TEST_RET_ENC_EC(ret);
  31107. }
  31108. if (ret == 0) {
  31109. outputSz = (word32)sizeof(output);
  31110. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31111. if (ret >= 0) {
  31112. outputSz = (word32)ret;
  31113. ret = 0;
  31114. }
  31115. else {
  31116. ret = WC_TEST_RET_ENC_EC(ret);
  31117. }
  31118. }
  31119. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31120. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31121. ret = WC_TEST_RET_ENC_NC;
  31122. }
  31123. /* Test decode/encode of Curve25519 private key (only) using generic API */
  31124. if (ret == 0) {
  31125. /* clear key, since generic API will try to decode all fields */
  31126. XMEMSET(&key, 0, sizeof(key));
  31127. idx = 0;
  31128. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31129. (word32)sizeof(kCurve25519PrivDer));
  31130. if (ret < 0) {
  31131. ret = WC_TEST_RET_ENC_EC(ret);
  31132. }
  31133. }
  31134. if (ret == 0) {
  31135. outputSz = (word32)sizeof(output);
  31136. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31137. if (ret >= 0) {
  31138. outputSz = (word32)ret;
  31139. ret = 0;
  31140. }
  31141. else {
  31142. ret = WC_TEST_RET_ENC_EC(ret);
  31143. }
  31144. }
  31145. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31146. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31147. ret = WC_TEST_RET_ENC_NC;
  31148. }
  31149. /* Test decode/encode of Curve25519 public key (only) using generic API */
  31150. if (ret == 0) {
  31151. /* clear key, since generic API will try to decode all fields */
  31152. XMEMSET(&key, 0, sizeof(key));
  31153. idx = 0;
  31154. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31155. (word32)sizeof(kCurve25519PubDer));
  31156. if (ret < 0) {
  31157. ret = WC_TEST_RET_ENC_EC(ret);
  31158. }
  31159. }
  31160. if (ret == 0) {
  31161. outputSz = (word32)sizeof(output);
  31162. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31163. if (ret >= 0) {
  31164. outputSz = (word32)ret;
  31165. ret = 0;
  31166. }
  31167. else {
  31168. ret = WC_TEST_RET_ENC_EC(ret);
  31169. }
  31170. }
  31171. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31172. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31173. ret = WC_TEST_RET_ENC_NC;
  31174. }
  31175. /* Test decode/encode key data containing both public and private fields */
  31176. if (ret == 0) {
  31177. XMEMSET(&key, 0 , sizeof(key));
  31178. /* Decode public key */
  31179. idx = 0;
  31180. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31181. (word32)sizeof(kCurve25519PubDer));
  31182. if (ret < 0) {
  31183. ret = WC_TEST_RET_ENC_EC(ret);
  31184. }
  31185. if (ret == 0) {
  31186. /* Decode private key */
  31187. idx = 0;
  31188. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31189. (word32)sizeof(kCurve25519PrivDer));
  31190. if (ret < 0) {
  31191. ret = WC_TEST_RET_ENC_EC(ret);
  31192. }
  31193. }
  31194. /* Both public and private flags should be set */
  31195. if ((ret == 0) && (!key.pubSet && !key.privSet)) {
  31196. ret = WC_TEST_RET_ENC_NC;
  31197. }
  31198. if (ret == 0) {
  31199. /* Export key to temporary DER */
  31200. outputSz = (word32)sizeof(output);
  31201. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31202. if (ret >= 0) {
  31203. outputSz = (word32)ret;
  31204. ret = 0;
  31205. }
  31206. else {
  31207. ret = WC_TEST_RET_ENC_EC(ret);
  31208. }
  31209. /* Re-import temporary DER */
  31210. if (ret == 0) {
  31211. idx = 0;
  31212. ret = wc_Curve25519KeyDecode(output, &idx, &key, sizeof(output));
  31213. if (ret < 0) {
  31214. ret = WC_TEST_RET_ENC_EC(ret);
  31215. }
  31216. }
  31217. /* Ensure public and private keys survived combined keypair
  31218. * export/import by re-exporting DER for private and public keys,
  31219. * individually, and re-checking output against known good vectors.
  31220. * This is slightly circuitous but does test the functionality
  31221. * without requiring the addition of new test keys */
  31222. if (ret == 0) {
  31223. idx = 0;
  31224. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx,
  31225. &key, (word32)sizeof(kCurve25519PrivDer));
  31226. if (ret < 0)
  31227. ret = WC_TEST_RET_ENC_EC(ret);
  31228. }
  31229. if (ret == 0) {
  31230. outputSz = (word32)sizeof(output);
  31231. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31232. if (ret >= 0) {
  31233. outputSz = (word32)ret;
  31234. ret = 0;
  31235. }
  31236. else {
  31237. ret = WC_TEST_RET_ENC_EC(ret);
  31238. }
  31239. }
  31240. if ((ret == 0) &&
  31241. (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31242. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31243. ret = WC_TEST_RET_ENC_NC;
  31244. }
  31245. if (ret == 0) {
  31246. idx = 0;
  31247. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx,
  31248. &key, (word32)sizeof(kCurve25519PubDer));
  31249. if (ret < 0)
  31250. ret = WC_TEST_RET_ENC_EC(ret);
  31251. }
  31252. if (ret == 0) {
  31253. outputSz = (word32)sizeof(output);
  31254. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31255. if (ret >= 0) {
  31256. outputSz = (word32)ret;
  31257. ret = 0;
  31258. }
  31259. else {
  31260. ret = WC_TEST_RET_ENC_EC(ret);
  31261. }
  31262. }
  31263. if ((ret == 0) &&
  31264. (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31265. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31266. ret = WC_TEST_RET_ENC_NC;
  31267. }
  31268. }
  31269. }
  31270. wc_curve25519_free(&key);
  31271. return ret;
  31272. }
  31273. #endif /* !NO_ASN && HAVE_CURVE25519_KEY_EXPORT && HAVE_CURVE25519_KEY_IMPORT */
  31274. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
  31275. {
  31276. WC_RNG rng;
  31277. wc_test_ret_t ret;
  31278. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31279. byte sharedA[32];
  31280. byte sharedB[32];
  31281. word32 y;
  31282. #endif
  31283. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31284. byte exportBuf[32];
  31285. #endif
  31286. word32 x = 0;
  31287. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31288. curve25519_key *userA = NULL, *userB = NULL, *pubKey = NULL;
  31289. #else
  31290. curve25519_key userA[1], userB[1], pubKey[1];
  31291. #endif
  31292. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31293. defined(HAVE_CURVE25519_KEY_IMPORT)
  31294. /* test vectors from
  31295. https://tools.ietf.org/html/draft-josefsson-tls-curve25519-03
  31296. */
  31297. /* secret key for party a */
  31298. byte sa[] = {
  31299. 0x5A,0xC9,0x9F,0x33,0x63,0x2E,0x5A,0x76,
  31300. 0x8D,0xE7,0xE8,0x1B,0xF8,0x54,0xC2,0x7C,
  31301. 0x46,0xE3,0xFB,0xF2,0xAB,0xBA,0xCD,0x29,
  31302. 0xEC,0x4A,0xFF,0x51,0x73,0x69,0xC6,0x60
  31303. };
  31304. /* public key for party a */
  31305. byte pa[] = {
  31306. 0x05,0x7E,0x23,0xEA,0x9F,0x1C,0xBE,0x8A,
  31307. 0x27,0x16,0x8F,0x6E,0x69,0x6A,0x79,0x1D,
  31308. 0xE6,0x1D,0xD3,0xAF,0x7A,0xCD,0x4E,0xEA,
  31309. 0xCC,0x6E,0x7B,0xA5,0x14,0xFD,0xA8,0x63
  31310. };
  31311. /* secret key for party b */
  31312. byte sb[] = {
  31313. 0x47,0xDC,0x3D,0x21,0x41,0x74,0x82,0x0E,
  31314. 0x11,0x54,0xB4,0x9B,0xC6,0xCD,0xB2,0xAB,
  31315. 0xD4,0x5E,0xE9,0x58,0x17,0x05,0x5D,0x25,
  31316. 0x5A,0xA3,0x58,0x31,0xB7,0x0D,0x32,0x60
  31317. };
  31318. /* public key for party b */
  31319. byte pb[] = {
  31320. 0x6E,0xB8,0x9D,0xA9,0x19,0x89,0xAE,0x37,
  31321. 0xC7,0xEA,0xC7,0x61,0x8D,0x9E,0x5C,0x49,
  31322. 0x51,0xDB,0xA1,0xD7,0x3C,0x28,0x5A,0xE1,
  31323. 0xCD,0x26,0xA8,0x55,0x02,0x0E,0xEF,0x04
  31324. };
  31325. /* expected shared key */
  31326. byte ss[] = {
  31327. 0x61,0x45,0x0C,0xD9,0x8E,0x36,0x01,0x6B,
  31328. 0x58,0x77,0x6A,0x89,0x7A,0x9F,0x0A,0xEF,
  31329. 0x73,0x8B,0x99,0xF0,0x94,0x68,0xB8,0xD6,
  31330. 0xB8,0x51,0x11,0x84,0xD5,0x34,0x94,0xAB
  31331. };
  31332. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  31333. (void)x;
  31334. WOLFSSL_ENTER("curve25519_test");
  31335. /* wc_FreeRng is always called on exit. Therefore wc_InitRng should be
  31336. * called before any exit goto's */
  31337. #ifndef HAVE_FIPS
  31338. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31339. #else
  31340. ret = wc_InitRng(&rng);
  31341. #endif
  31342. if (ret != 0)
  31343. return WC_TEST_RET_ENC_EC(ret);
  31344. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31345. userA = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31346. if (ret != 0)
  31347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31348. userB = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31349. if (ret != 0)
  31350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31351. pubKey = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31352. if (ret != 0)
  31353. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31354. #else
  31355. wc_curve25519_init_ex(userA, HEAP_HINT, devId);
  31356. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31357. wc_curve25519_init_ex(pubKey, HEAP_HINT, devId);
  31358. #endif
  31359. /* make curve25519 keys */
  31360. ret = wc_curve25519_make_key(&rng, 32, userA);
  31361. if (ret != 0)
  31362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31363. ret = wc_curve25519_make_key(&rng, 32, userB);
  31364. if (ret != 0)
  31365. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31366. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31367. /* find shared secret key */
  31368. x = sizeof(sharedA);
  31369. if ((ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x)) != 0) {
  31370. printf("wc_curve25519_shared_secret 1 failed\n");
  31371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31372. }
  31373. y = sizeof(sharedB);
  31374. if ((ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y)) != 0) {
  31375. printf("wc_curve25519_shared_secret 2 failed\n");
  31376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31377. }
  31378. /* compare shared secret keys to test they are the same */
  31379. if (y != x)
  31380. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31381. if (XMEMCMP(sharedA, sharedB, x))
  31382. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31383. #endif
  31384. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31385. /* export a public key and import it for another user */
  31386. x = sizeof(exportBuf);
  31387. ret = wc_curve25519_export_public(userA, exportBuf, &x);
  31388. if (ret != 0)
  31389. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31390. #ifdef HAVE_CURVE25519_KEY_IMPORT
  31391. ret = wc_curve25519_import_public(exportBuf, x, pubKey);
  31392. if (ret != 0)
  31393. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31394. #endif
  31395. #endif
  31396. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31397. defined(HAVE_CURVE25519_KEY_IMPORT)
  31398. /* test shared key after importing a public key */
  31399. XMEMSET(sharedB, 0, sizeof(sharedB));
  31400. y = sizeof(sharedB);
  31401. if (wc_curve25519_shared_secret(userB, pubKey, sharedB, &y) != 0) {
  31402. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31403. }
  31404. if (XMEMCMP(sharedA, sharedB, y))
  31405. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31406. /* import RFC test vectors and compare shared key */
  31407. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31408. userA);
  31409. if (ret != 0)
  31410. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31411. ret = wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb),
  31412. userB);
  31413. if (ret != 0)
  31414. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31415. /* test against known test vector */
  31416. XMEMSET(sharedB, 0, sizeof(sharedB));
  31417. y = sizeof(sharedB);
  31418. ret = wc_curve25519_shared_secret(userA, userB, sharedB, &y);
  31419. if (ret != 0)
  31420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31421. if (XMEMCMP(ss, sharedB, y))
  31422. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31423. /* test swapping roles of keys and generating same shared key */
  31424. XMEMSET(sharedB, 0, sizeof(sharedB));
  31425. y = sizeof(sharedB);
  31426. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31427. if (ret != 0)
  31428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31429. if (XMEMCMP(ss, sharedB, y))
  31430. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31431. /* test with 1 generated key and 1 from known test vector */
  31432. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31433. userA);
  31434. if (ret != 0)
  31435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31436. wc_curve25519_free(userB);
  31437. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31438. ret = wc_curve25519_make_key(&rng, 32, userB);
  31439. if (ret != 0)
  31440. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31441. x = sizeof(sharedA);
  31442. ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x);
  31443. if (ret != 0)
  31444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31445. y = sizeof(sharedB);
  31446. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31447. if (ret != 0)
  31448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31449. /* compare shared secret keys to test they are the same */
  31450. if (y != x)
  31451. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31452. if (XMEMCMP(sharedA, sharedB, x))
  31453. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31454. ret = curve25519_overflow_test();
  31455. if (ret != 0)
  31456. goto cleanup;
  31457. ret = curve25519_check_public_test();
  31458. if (ret != 0)
  31459. goto cleanup;
  31460. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31461. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31462. defined(HAVE_CURVE25519_KEY_IMPORT)
  31463. ret = curve255519_der_test();
  31464. if (ret != 0)
  31465. goto cleanup;
  31466. #endif
  31467. cleanup:
  31468. /* clean up keys when done */
  31469. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31470. wc_curve25519_delete(pubKey, &pubKey);
  31471. wc_curve25519_delete(userB, &userB);
  31472. wc_curve25519_delete(userA, &userA);
  31473. #else
  31474. wc_curve25519_free(pubKey);
  31475. wc_curve25519_free(userB);
  31476. wc_curve25519_free(userA);
  31477. #endif
  31478. wc_FreeRng(&rng);
  31479. return ret;
  31480. }
  31481. #endif /* HAVE_CURVE25519 */
  31482. #ifdef HAVE_ED25519
  31483. #ifdef WOLFSSL_TEST_CERT
  31484. static wc_test_ret_t ed25519_test_cert(void)
  31485. {
  31486. DecodedCert cert[2];
  31487. DecodedCert* serverCert = NULL;
  31488. DecodedCert* caCert = NULL;
  31489. #ifdef HAVE_ED25519_VERIFY
  31490. ed25519_key key;
  31491. ed25519_key* pubKey = NULL;
  31492. int verify;
  31493. #endif /* HAVE_ED25519_VERIFY */
  31494. wc_test_ret_t ret;
  31495. byte* tmp;
  31496. size_t bytes;
  31497. XFILE file;
  31498. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31499. if (tmp == NULL) {
  31500. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31501. }
  31502. #ifdef USE_CERT_BUFFERS_256
  31503. XMEMCPY(tmp, ca_ed25519_cert, sizeof_ca_ed25519_cert);
  31504. bytes = sizeof_ca_ed25519_cert;
  31505. #elif !defined(NO_FILESYSTEM)
  31506. file = XFOPEN(caEd25519Cert, "rb");
  31507. if (file == NULL) {
  31508. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31509. }
  31510. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31511. XFCLOSE(file);
  31512. if (bytes == 0)
  31513. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31514. #else
  31515. /* No certificate to use. */
  31516. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31517. #endif
  31518. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  31519. caCert = &cert[0];
  31520. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  31521. if (ret != 0)
  31522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31523. #ifdef USE_CERT_BUFFERS_256
  31524. XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert);
  31525. bytes = sizeof_server_ed25519_cert;
  31526. #elif !defined(NO_FILESYSTEM)
  31527. file = XFOPEN(serverEd25519Cert, "rb");
  31528. if (file == NULL) {
  31529. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31530. }
  31531. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31532. XFCLOSE(file);
  31533. if (bytes == 0)
  31534. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31535. #else
  31536. /* No certificate to use. */
  31537. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31538. #endif
  31539. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  31540. serverCert = &cert[1];
  31541. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  31542. if (ret != 0)
  31543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31544. #ifdef HAVE_ED25519_VERIFY
  31545. ret = wc_ed25519_init(&key);
  31546. if (ret < 0)
  31547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31548. pubKey = &key;
  31549. ret = wc_ed25519_import_public(caCert->publicKey, caCert->pubKeySize,
  31550. pubKey);
  31551. if (ret < 0)
  31552. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31553. ret = wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength,
  31554. serverCert->source + serverCert->certBegin,
  31555. serverCert->sigIndex - serverCert->certBegin,
  31556. &verify, pubKey);
  31557. if (ret < 0 || verify != 1)
  31558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31559. #endif /* HAVE_ED25519_VERIFY */
  31560. done:
  31561. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31562. #ifdef HAVE_ED25519_VERIFY
  31563. wc_ed25519_free(pubKey);
  31564. #endif /* HAVE_ED25519_VERIFY */
  31565. if (caCert != NULL)
  31566. FreeDecodedCert(caCert);
  31567. if (serverCert != NULL)
  31568. FreeDecodedCert(serverCert);
  31569. return ret;
  31570. }
  31571. static wc_test_ret_t ed25519_test_make_cert(void)
  31572. {
  31573. WC_RNG rng;
  31574. Cert cert;
  31575. DecodedCert decode;
  31576. ed25519_key key;
  31577. ed25519_key* privKey = NULL;
  31578. wc_test_ret_t ret = 0;
  31579. byte* tmp = NULL;
  31580. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  31581. #ifndef HAVE_FIPS
  31582. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31583. #else
  31584. ret = wc_InitRng(&rng);
  31585. #endif
  31586. if (ret != 0)
  31587. return WC_TEST_RET_ENC_EC(ret);
  31588. wc_ed25519_init(&key);
  31589. privKey = &key;
  31590. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, privKey);
  31591. cert.daysValid = 365 * 2;
  31592. cert.selfSigned = 1;
  31593. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  31594. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  31595. cert.isCA = 0;
  31596. #ifdef WOLFSSL_CERT_EXT
  31597. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  31598. if (ret < 0)
  31599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31600. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31601. if (ret < 0)
  31602. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31603. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31604. if (ret < 0)
  31605. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31606. #endif
  31607. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31608. if (tmp == NULL) {
  31609. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31610. }
  31611. cert.sigType = CTC_ED25519;
  31612. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng);
  31613. if (ret < 0)
  31614. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31615. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF,
  31616. ED25519_TYPE, privKey, &rng);
  31617. if (ret < 0)
  31618. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31619. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  31620. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  31621. FreeDecodedCert(&decode);
  31622. if (ret != 0)
  31623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31624. done:
  31625. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31626. wc_ed25519_free(privKey);
  31627. wc_FreeRng(&rng);
  31628. return ret;
  31629. }
  31630. #endif /* WOLFSSL_TEST_CERT */
  31631. #if defined(HAVE_ED25519_KEY_IMPORT)
  31632. static wc_test_ret_t ed25519_test_check_key(void)
  31633. {
  31634. /* Fails to find x-ordinate from this y-ordinate. */
  31635. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  31636. 0x40,
  31637. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31638. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31639. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31640. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31641. };
  31642. /* Y-ordinate value larger than prime. */
  31643. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  31644. 0x40,
  31645. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31646. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31647. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31648. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31649. };
  31650. /* Y-ordinate value equal to prime. */
  31651. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  31652. 0x40,
  31653. 0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31654. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31655. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31656. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31657. };
  31658. /* Y-ordinate value equal to prime - 1. */
  31659. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  31660. 0x40,
  31661. 0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31662. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31663. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31664. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31665. };
  31666. ed25519_key key;
  31667. int ret;
  31668. int res = 0;
  31669. /* Initialize key for use. */
  31670. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31671. if (ret != 0) {
  31672. return WC_TEST_RET_ENC_NC;
  31673. }
  31674. /* Load bad public key only and perform checks. */
  31675. ret = wc_ed25519_import_public(key_bad_y, ED25519_PUB_KEY_SIZE + 1, &key);
  31676. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31677. res = WC_TEST_RET_ENC_NC;
  31678. }
  31679. if (res == 0) {
  31680. /* Load bad public key only and perform checks. */
  31681. ret = wc_ed25519_import_public(key_bad_y_max, ED25519_PUB_KEY_SIZE + 1,
  31682. &key);
  31683. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31684. res = WC_TEST_RET_ENC_NC;
  31685. }
  31686. }
  31687. if (res == 0) {
  31688. /* Load bad public key only and perform checks. */
  31689. ret = wc_ed25519_import_public(key_bad_y_is_p, ED25519_PUB_KEY_SIZE + 1,
  31690. &key);
  31691. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31692. res = WC_TEST_RET_ENC_NC;
  31693. }
  31694. }
  31695. if (res == 0) {
  31696. /* Load good public key only and perform checks. */
  31697. ret = wc_ed25519_import_public(key_y_is_p_minus_1,
  31698. ED25519_PUB_KEY_SIZE + 1, &key);
  31699. if (ret != 0) {
  31700. res = WC_TEST_RET_ENC_NC;
  31701. }
  31702. }
  31703. /* Dispose of key. */
  31704. wc_ed25519_free(&key);
  31705. return res;
  31706. }
  31707. #endif
  31708. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31709. defined(HAVE_ED25519_KEY_IMPORT)
  31710. static wc_test_ret_t ed25519ctx_test(void)
  31711. {
  31712. wc_test_ret_t ret;
  31713. byte out[ED25519_SIG_SIZE];
  31714. word32 outlen;
  31715. #ifdef HAVE_ED25519_VERIFY
  31716. int verify = 0;
  31717. #endif /* HAVE_ED25519_VERIFY */
  31718. ed25519_key key;
  31719. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  31720. 0x03,0x05,0x33,0x4e,0x38,0x1a,0xf7,0x8f,
  31721. 0x14,0x1c,0xb6,0x66,0xf6,0x19,0x9f,0x57,
  31722. 0xbc,0x34,0x95,0x33,0x5a,0x25,0x6a,0x95,
  31723. 0xbd,0x2a,0x55,0xbf,0x54,0x66,0x63,0xf6
  31724. };
  31725. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  31726. 0xdf,0xc9,0x42,0x5e,0x4f,0x96,0x8f,0x7f,
  31727. 0x0c,0x29,0xf0,0x25,0x9c,0xf5,0xf9,0xae,
  31728. 0xd6,0x85,0x1c,0x2b,0xb4,0xad,0x8b,0xfb,
  31729. 0x86,0x0c,0xfe,0xe0,0xab,0x24,0x82,0x92
  31730. };
  31731. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx1[] = {
  31732. 0x55,0xa4,0xcc,0x2f,0x70,0xa5,0x4e,0x04,
  31733. 0x28,0x8c,0x5f,0x4c,0xd1,0xe4,0x5a,0x7b,
  31734. 0xb5,0x20,0xb3,0x62,0x92,0x91,0x18,0x76,
  31735. 0xca,0xda,0x73,0x23,0x19,0x8d,0xd8,0x7a,
  31736. 0x8b,0x36,0x95,0x0b,0x95,0x13,0x00,0x22,
  31737. 0x90,0x7a,0x7f,0xb7,0xc4,0xe9,0xb2,0xd5,
  31738. 0xf6,0xcc,0xa6,0x85,0xa5,0x87,0xb4,0xb2,
  31739. 0x1f,0x4b,0x88,0x8e,0x4e,0x7e,0xdb,0x0d
  31740. };
  31741. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx2[] = {
  31742. 0xcc,0x5e,0x63,0xa2,0x7e,0x94,0xaf,0xd3,
  31743. 0x41,0x83,0x38,0xd2,0x48,0x6f,0xa9,0x2a,
  31744. 0xf9,0x91,0x7c,0x2d,0x98,0x9e,0x06,0xe5,
  31745. 0x02,0x77,0x72,0x1c,0x34,0x38,0x18,0xb4,
  31746. 0x21,0x96,0xbc,0x29,0x2e,0x68,0xf3,0x4d,
  31747. 0x85,0x9b,0xbe,0xad,0x17,0x9f,0x54,0x54,
  31748. 0x2d,0x4b,0x04,0xdc,0xfb,0xfa,0x4a,0x68,
  31749. 0x4e,0x39,0x50,0xfb,0x1c,0xcd,0x8d,0x0d
  31750. };
  31751. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  31752. 0xf7,0x26,0x93,0x6d,0x19,0xc8,0x00,0x49,
  31753. 0x4e,0x3f,0xda,0xff,0x20,0xb2,0x76,0xa8
  31754. };
  31755. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  31756. 0x66,0x6f,0x6f
  31757. };
  31758. outlen = sizeof(out);
  31759. XMEMSET(out, 0, sizeof(out));
  31760. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31761. if (ret != 0)
  31762. return 10800;
  31763. ret = wc_ed25519_import_private_key(sKeyCtx, ED25519_KEY_SIZE, pKeyCtx,
  31764. sizeof(pKeyCtx), &key);
  31765. if (ret == 0)
  31766. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31767. contextCtx, sizeof(contextCtx));
  31768. if (ret == 0 && XMEMCMP(out, sigCtx1, 64) != 0)
  31769. ret = WC_TEST_RET_ENC_NC;
  31770. #if defined(HAVE_ED25519_VERIFY)
  31771. /* test verify on good msg */
  31772. if (ret == 0)
  31773. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31774. &verify, &key, contextCtx, sizeof(contextCtx));
  31775. if (ret == 0 && verify != 1)
  31776. ret = WC_TEST_RET_ENC_NC;
  31777. #endif
  31778. if (ret == 0)
  31779. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31780. NULL, 0);
  31781. if (ret == 0 && XMEMCMP(out, sigCtx2, 64) != 0)
  31782. ret = WC_TEST_RET_ENC_NC;
  31783. #if defined(HAVE_ED25519_VERIFY)
  31784. /* test verify on good msg */
  31785. if (ret == 0)
  31786. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31787. &verify, &key, NULL, 0);
  31788. if (ret == 0 && verify != 1)
  31789. ret = WC_TEST_RET_ENC_NC;
  31790. #endif
  31791. wc_ed25519_free(&key);
  31792. return ret;
  31793. }
  31794. static wc_test_ret_t ed25519ph_test(void)
  31795. {
  31796. wc_test_ret_t ret = 0;
  31797. byte out[ED25519_SIG_SIZE];
  31798. word32 outlen;
  31799. #ifdef HAVE_ED25519_VERIFY
  31800. int verify = 0;
  31801. #endif /* HAVE_ED25519_VERIFY */
  31802. ed25519_key key;
  31803. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  31804. 0x83,0x3f,0xe6,0x24,0x09,0x23,0x7b,0x9d,
  31805. 0x62,0xec,0x77,0x58,0x75,0x20,0x91,0x1e,
  31806. 0x9a,0x75,0x9c,0xec,0x1d,0x19,0x75,0x5b,
  31807. 0x7d,0xa9,0x01,0xb9,0x6d,0xca,0x3d,0x42
  31808. };
  31809. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  31810. 0xec,0x17,0x2b,0x93,0xad,0x5e,0x56,0x3b,
  31811. 0xf4,0x93,0x2c,0x70,0xe1,0x24,0x50,0x34,
  31812. 0xc3,0x54,0x67,0xef,0x2e,0xfd,0x4d,0x64,
  31813. 0xeb,0xf8,0x19,0x68,0x34,0x67,0xe2,0xbf
  31814. };
  31815. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  31816. 0x98,0xa7,0x02,0x22,0xf0,0xb8,0x12,0x1a,
  31817. 0xa9,0xd3,0x0f,0x81,0x3d,0x68,0x3f,0x80,
  31818. 0x9e,0x46,0x2b,0x46,0x9c,0x7f,0xf8,0x76,
  31819. 0x39,0x49,0x9b,0xb9,0x4e,0x6d,0xae,0x41,
  31820. 0x31,0xf8,0x50,0x42,0x46,0x3c,0x2a,0x35,
  31821. 0x5a,0x20,0x03,0xd0,0x62,0xad,0xf5,0xaa,
  31822. 0xa1,0x0b,0x8c,0x61,0xe6,0x36,0x06,0x2a,
  31823. 0xaa,0xd1,0x1c,0x2a,0x26,0x08,0x34,0x06
  31824. };
  31825. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  31826. 0xe0,0x39,0x70,0x2b,0x4c,0x25,0x95,0xa6,
  31827. 0xa5,0x41,0xac,0x85,0x09,0x23,0x6e,0x29,
  31828. 0x90,0x47,0x47,0x95,0x33,0x0c,0x9b,0x34,
  31829. 0xa7,0x5f,0x58,0xa6,0x60,0x12,0x9e,0x08,
  31830. 0xfd,0x73,0x69,0x43,0xfb,0x19,0x43,0xa5,
  31831. 0x57,0x20,0xb9,0xe0,0x95,0x7b,0x1e,0xd6,
  31832. 0x73,0x48,0x16,0x61,0x9f,0x13,0x88,0xf4,
  31833. 0x3f,0x73,0xe6,0xe3,0xba,0xa8,0x1c,0x0e
  31834. };
  31835. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  31836. 0x61,0x62,0x63
  31837. };
  31838. /* SHA-512 hash of msgPh */
  31839. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  31840. 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
  31841. 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
  31842. 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
  31843. 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
  31844. 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
  31845. 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
  31846. 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
  31847. 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f
  31848. };
  31849. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  31850. 0x66,0x6f,0x6f
  31851. };
  31852. outlen = sizeof(out);
  31853. XMEMSET(out, 0, sizeof(out));
  31854. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31855. if (ret != 0)
  31856. return WC_TEST_RET_ENC_EC(ret);
  31857. ret = wc_ed25519_import_private_key(sKeyPh, ED25519_KEY_SIZE, pKeyPh,
  31858. sizeof(pKeyPh), &key);
  31859. if (ret == 0)
  31860. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31861. NULL, 0);
  31862. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31863. ret = WC_TEST_RET_ENC_NC;
  31864. #if defined(HAVE_ED25519_VERIFY)
  31865. /* test verify on good msg */
  31866. if (ret == 0)
  31867. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh),
  31868. &verify, &key, NULL, 0);
  31869. if (ret == 0 && verify != 1)
  31870. ret = WC_TEST_RET_ENC_NC;
  31871. #endif
  31872. if (ret == 0)
  31873. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31874. contextPh2, sizeof(contextPh2));
  31875. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31876. ret = WC_TEST_RET_ENC_NC;
  31877. #if defined(HAVE_ED25519_VERIFY)
  31878. /* test verify on good msg */
  31879. if (ret == 0)
  31880. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify,
  31881. &key, contextPh2, sizeof(contextPh2));
  31882. if (ret == 0 && verify != 1)
  31883. ret = WC_TEST_RET_ENC_NC;
  31884. #endif
  31885. if (ret == 0)
  31886. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31887. NULL, 0);
  31888. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31889. ret = WC_TEST_RET_ENC_NC;
  31890. #if defined(HAVE_ED25519_VERIFY)
  31891. if (ret == 0)
  31892. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh),
  31893. &verify, &key, NULL, 0);
  31894. if (ret == 0 && verify != 1)
  31895. ret = WC_TEST_RET_ENC_NC;
  31896. #endif
  31897. if (ret == 0)
  31898. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31899. contextPh2, sizeof(contextPh2));
  31900. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31901. ret = WC_TEST_RET_ENC_NC;
  31902. #if defined(HAVE_ED25519_VERIFY)
  31903. if (ret == 0)
  31904. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  31905. &key, contextPh2, sizeof(contextPh2));
  31906. if (ret == 0 && verify != 1)
  31907. ret = WC_TEST_RET_ENC_NC;
  31908. #endif
  31909. wc_ed25519_free(&key);
  31910. return ret;
  31911. }
  31912. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31913. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
  31914. {
  31915. wc_test_ret_t ret;
  31916. WC_RNG rng;
  31917. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  31918. defined(HAVE_ED25519_KEY_IMPORT)
  31919. byte out[ED25519_SIG_SIZE];
  31920. byte exportPKey[ED25519_KEY_SIZE];
  31921. byte exportSKey[ED25519_KEY_SIZE];
  31922. word32 exportPSz;
  31923. word32 exportSSz;
  31924. int i;
  31925. word32 outlen;
  31926. #ifdef HAVE_ED25519_VERIFY
  31927. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  31928. int j;
  31929. #endif
  31930. int verify;
  31931. #endif /* HAVE_ED25519_VERIFY */
  31932. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31933. word32 keySz, sigSz;
  31934. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31935. ed25519_key* key = NULL;
  31936. ed25519_key* key2 = NULL;
  31937. #else
  31938. ed25519_key key[1];
  31939. ed25519_key key2[1];
  31940. #endif
  31941. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31942. defined(HAVE_ED25519_KEY_IMPORT)
  31943. /* test vectors from
  31944. https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02
  31945. */
  31946. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  31947. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31948. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31949. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31950. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31951. };
  31952. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  31953. 0x4c,0xcd,0x08,0x9b,0x28,0xff,0x96,0xda,
  31954. 0x9d,0xb6,0xc3,0x46,0xec,0x11,0x4e,0x0f,
  31955. 0x5b,0x8a,0x31,0x9f,0x35,0xab,0xa6,0x24,
  31956. 0xda,0x8c,0xf6,0xed,0x4f,0xb8,0xa6,0xfb
  31957. };
  31958. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  31959. 0xc5,0xaa,0x8d,0xf4,0x3f,0x9f,0x83,0x7b,
  31960. 0xed,0xb7,0x44,0x2f,0x31,0xdc,0xb7,0xb1,
  31961. 0x66,0xd3,0x85,0x35,0x07,0x6f,0x09,0x4b,
  31962. 0x85,0xce,0x3a,0x2e,0x0b,0x44,0x58,0xf7
  31963. };
  31964. /* uncompressed test */
  31965. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  31966. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31967. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31968. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31969. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31970. };
  31971. /* compressed prefix test */
  31972. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  31973. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31974. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31975. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31976. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31977. };
  31978. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  31979. 0xf5,0xe5,0x76,0x7c,0xf1,0x53,0x31,0x95,
  31980. 0x17,0x63,0x0f,0x22,0x68,0x76,0xb8,0x6c,
  31981. 0x81,0x60,0xcc,0x58,0x3b,0xc0,0x13,0x74,
  31982. 0x4c,0x6b,0xf2,0x55,0xf5,0xcc,0x0e,0xe5
  31983. };
  31984. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  31985. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  31986. 0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31987. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31988. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31989. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31990. };
  31991. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  31992. 0x3d,0x40,0x17,0xc3,0xe8,0x43,0x89,0x5a,
  31993. 0x92,0xb7,0x0a,0xa7,0x4d,0x1b,0x7e,0xbc,
  31994. 0x9c,0x98,0x2c,0xcf,0x2e,0xc4,0x96,0x8c,
  31995. 0xc0,0xcd,0x55,0xf1,0x2a,0xf4,0x66,0x0c
  31996. };
  31997. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  31998. 0xfc,0x51,0xcd,0x8e,0x62,0x18,0xa1,0xa3,
  31999. 0x8d,0xa4,0x7e,0xd0,0x02,0x30,0xf0,0x58,
  32000. 0x08,0x16,0xed,0x13,0xba,0x33,0x03,0xac,
  32001. 0x5d,0xeb,0x91,0x15,0x48,0x90,0x80,0x25
  32002. };
  32003. /* uncompressed test */
  32004. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  32005. 0x04,0x55,0xd0,0xe0,0x9a,0x2b,0x9d,0x34,
  32006. 0x29,0x22,0x97,0xe0,0x8d,0x60,0xd0,0xf6,
  32007. 0x20,0xc5,0x13,0xd4,0x72,0x53,0x18,0x7c,
  32008. 0x24,0xb1,0x27,0x86,0xbd,0x77,0x76,0x45,
  32009. 0xce,0x1a,0x51,0x07,0xf7,0x68,0x1a,0x02,
  32010. 0xaf,0x25,0x23,0xa6,0xda,0xf3,0x72,0xe1,
  32011. 0x0e,0x3a,0x07,0x64,0xc9,0xd3,0xfe,0x4b,
  32012. 0xd5,0xb7,0x0a,0xb1,0x82,0x01,0x98,0x5a,
  32013. 0xd7
  32014. };
  32015. /* compressed prefix */
  32016. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  32017. 0x40,0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  32018. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  32019. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  32020. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  32021. };
  32022. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  32023. 0x27,0x81,0x17,0xfc,0x14,0x4c,0x72,0x34,
  32024. 0x0f,0x67,0xd0,0xf2,0x31,0x6e,0x83,0x86,
  32025. 0xce,0xff,0xbf,0x2b,0x24,0x28,0xc9,0xc5,
  32026. 0x1f,0xef,0x7c,0x59,0x7f,0x1d,0x42,0x6e
  32027. };
  32028. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  32029. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  32030. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  32031. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  32032. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32033. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32034. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32035. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32036. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32037. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32038. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32039. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32040. };
  32041. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  32042. 0x92,0xa0,0x09,0xa9,0xf0,0xd4,0xca,0xb8,
  32043. 0x72,0x0e,0x82,0x0b,0x5f,0x64,0x25,0x40,
  32044. 0xa2,0xb2,0x7b,0x54,0x16,0x50,0x3f,0x8f,
  32045. 0xb3,0x76,0x22,0x23,0xeb,0xdb,0x69,0xda,
  32046. 0x08,0x5a,0xc1,0xe4,0x3e,0x15,0x99,0x6e,
  32047. 0x45,0x8f,0x36,0x13,0xd0,0xf1,0x1d,0x8c,
  32048. 0x38,0x7b,0x2e,0xae,0xb4,0x30,0x2a,0xee,
  32049. 0xb0,0x0d,0x29,0x16,0x12,0xbb,0x0c,0x00
  32050. };
  32051. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  32052. 0x62,0x91,0xd6,0x57,0xde,0xec,0x24,0x02,
  32053. 0x48,0x27,0xe6,0x9c,0x3a,0xbe,0x01,0xa3,
  32054. 0x0c,0xe5,0x48,0xa2,0x84,0x74,0x3a,0x44,
  32055. 0x5e,0x36,0x80,0xd7,0xdb,0x5a,0xc3,0xac,
  32056. 0x18,0xff,0x9b,0x53,0x8d,0x16,0xf2,0x90,
  32057. 0xae,0x67,0xf7,0x60,0x98,0x4d,0xc6,0x59,
  32058. 0x4a,0x7c,0x15,0xe9,0x71,0x6e,0xd2,0x8d,
  32059. 0xc0,0x27,0xbe,0xce,0xea,0x1e,0xc4,0x0a
  32060. };
  32061. /* uncompressed test */
  32062. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  32063. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32064. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32065. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32066. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32067. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32068. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32069. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32070. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32071. };
  32072. /* compressed prefix */
  32073. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  32074. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32075. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32076. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32077. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32078. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32079. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32080. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32081. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32082. };
  32083. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  32084. 0x0a,0xab,0x4c,0x90,0x05,0x01,0xb3,0xe2,
  32085. 0x4d,0x7c,0xdf,0x46,0x63,0x32,0x6a,0x3a,
  32086. 0x87,0xdf,0x5e,0x48,0x43,0xb2,0xcb,0xdb,
  32087. 0x67,0xcb,0xf6,0xe4,0x60,0xfe,0xc3,0x50,
  32088. 0xaa,0x53,0x71,0xb1,0x50,0x8f,0x9f,0x45,
  32089. 0x28,0xec,0xea,0x23,0xc4,0x36,0xd9,0x4b,
  32090. 0x5e,0x8f,0xcd,0x4f,0x68,0x1e,0x30,0xa6,
  32091. 0xac,0x00,0xa9,0x70,0x4a,0x18,0x8a,0x03
  32092. };
  32093. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  32094. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {0x0 };
  32095. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {0x72};
  32096. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {0xAF,0x82};
  32097. /* test of a 1024 byte long message */
  32098. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  32099. 0x08,0xb8,0xb2,0xb7,0x33,0x42,0x42,0x43,
  32100. 0x76,0x0f,0xe4,0x26,0xa4,0xb5,0x49,0x08,
  32101. 0x63,0x21,0x10,0xa6,0x6c,0x2f,0x65,0x91,
  32102. 0xea,0xbd,0x33,0x45,0xe3,0xe4,0xeb,0x98,
  32103. 0xfa,0x6e,0x26,0x4b,0xf0,0x9e,0xfe,0x12,
  32104. 0xee,0x50,0xf8,0xf5,0x4e,0x9f,0x77,0xb1,
  32105. 0xe3,0x55,0xf6,0xc5,0x05,0x44,0xe2,0x3f,
  32106. 0xb1,0x43,0x3d,0xdf,0x73,0xbe,0x84,0xd8,
  32107. 0x79,0xde,0x7c,0x00,0x46,0xdc,0x49,0x96,
  32108. 0xd9,0xe7,0x73,0xf4,0xbc,0x9e,0xfe,0x57,
  32109. 0x38,0x82,0x9a,0xdb,0x26,0xc8,0x1b,0x37,
  32110. 0xc9,0x3a,0x1b,0x27,0x0b,0x20,0x32,0x9d,
  32111. 0x65,0x86,0x75,0xfc,0x6e,0xa5,0x34,0xe0,
  32112. 0x81,0x0a,0x44,0x32,0x82,0x6b,0xf5,0x8c,
  32113. 0x94,0x1e,0xfb,0x65,0xd5,0x7a,0x33,0x8b,
  32114. 0xbd,0x2e,0x26,0x64,0x0f,0x89,0xff,0xbc,
  32115. 0x1a,0x85,0x8e,0xfc,0xb8,0x55,0x0e,0xe3,
  32116. 0xa5,0xe1,0x99,0x8b,0xd1,0x77,0xe9,0x3a,
  32117. 0x73,0x63,0xc3,0x44,0xfe,0x6b,0x19,0x9e,
  32118. 0xe5,0xd0,0x2e,0x82,0xd5,0x22,0xc4,0xfe,
  32119. 0xba,0x15,0x45,0x2f,0x80,0x28,0x8a,0x82,
  32120. 0x1a,0x57,0x91,0x16,0xec,0x6d,0xad,0x2b,
  32121. 0x3b,0x31,0x0d,0xa9,0x03,0x40,0x1a,0xa6,
  32122. 0x21,0x00,0xab,0x5d,0x1a,0x36,0x55,0x3e,
  32123. 0x06,0x20,0x3b,0x33,0x89,0x0c,0xc9,0xb8,
  32124. 0x32,0xf7,0x9e,0xf8,0x05,0x60,0xcc,0xb9,
  32125. 0xa3,0x9c,0xe7,0x67,0x96,0x7e,0xd6,0x28,
  32126. 0xc6,0xad,0x57,0x3c,0xb1,0x16,0xdb,0xef,
  32127. 0xef,0xd7,0x54,0x99,0xda,0x96,0xbd,0x68,
  32128. 0xa8,0xa9,0x7b,0x92,0x8a,0x8b,0xbc,0x10,
  32129. 0x3b,0x66,0x21,0xfc,0xde,0x2b,0xec,0xa1,
  32130. 0x23,0x1d,0x20,0x6b,0xe6,0xcd,0x9e,0xc7,
  32131. 0xaf,0xf6,0xf6,0xc9,0x4f,0xcd,0x72,0x04,
  32132. 0xed,0x34,0x55,0xc6,0x8c,0x83,0xf4,0xa4,
  32133. 0x1d,0xa4,0xaf,0x2b,0x74,0xef,0x5c,0x53,
  32134. 0xf1,0xd8,0xac,0x70,0xbd,0xcb,0x7e,0xd1,
  32135. 0x85,0xce,0x81,0xbd,0x84,0x35,0x9d,0x44,
  32136. 0x25,0x4d,0x95,0x62,0x9e,0x98,0x55,0xa9,
  32137. 0x4a,0x7c,0x19,0x58,0xd1,0xf8,0xad,0xa5,
  32138. 0xd0,0x53,0x2e,0xd8,0xa5,0xaa,0x3f,0xb2,
  32139. 0xd1,0x7b,0xa7,0x0e,0xb6,0x24,0x8e,0x59,
  32140. 0x4e,0x1a,0x22,0x97,0xac,0xbb,0xb3,0x9d,
  32141. 0x50,0x2f,0x1a,0x8c,0x6e,0xb6,0xf1,0xce,
  32142. 0x22,0xb3,0xde,0x1a,0x1f,0x40,0xcc,0x24,
  32143. 0x55,0x41,0x19,0xa8,0x31,0xa9,0xaa,0xd6,
  32144. 0x07,0x9c,0xad,0x88,0x42,0x5d,0xe6,0xbd,
  32145. 0xe1,0xa9,0x18,0x7e,0xbb,0x60,0x92,0xcf,
  32146. 0x67,0xbf,0x2b,0x13,0xfd,0x65,0xf2,0x70,
  32147. 0x88,0xd7,0x8b,0x7e,0x88,0x3c,0x87,0x59,
  32148. 0xd2,0xc4,0xf5,0xc6,0x5a,0xdb,0x75,0x53,
  32149. 0x87,0x8a,0xd5,0x75,0xf9,0xfa,0xd8,0x78,
  32150. 0xe8,0x0a,0x0c,0x9b,0xa6,0x3b,0xcb,0xcc,
  32151. 0x27,0x32,0xe6,0x94,0x85,0xbb,0xc9,0xc9,
  32152. 0x0b,0xfb,0xd6,0x24,0x81,0xd9,0x08,0x9b,
  32153. 0xec,0xcf,0x80,0xcf,0xe2,0xdf,0x16,0xa2,
  32154. 0xcf,0x65,0xbd,0x92,0xdd,0x59,0x7b,0x07,
  32155. 0x07,0xe0,0x91,0x7a,0xf4,0x8b,0xbb,0x75,
  32156. 0xfe,0xd4,0x13,0xd2,0x38,0xf5,0x55,0x5a,
  32157. 0x7a,0x56,0x9d,0x80,0xc3,0x41,0x4a,0x8d,
  32158. 0x08,0x59,0xdc,0x65,0xa4,0x61,0x28,0xba,
  32159. 0xb2,0x7a,0xf8,0x7a,0x71,0x31,0x4f,0x31,
  32160. 0x8c,0x78,0x2b,0x23,0xeb,0xfe,0x80,0x8b,
  32161. 0x82,0xb0,0xce,0x26,0x40,0x1d,0x2e,0x22,
  32162. 0xf0,0x4d,0x83,0xd1,0x25,0x5d,0xc5,0x1a,
  32163. 0xdd,0xd3,0xb7,0x5a,0x2b,0x1a,0xe0,0x78,
  32164. 0x45,0x04,0xdf,0x54,0x3a,0xf8,0x96,0x9b,
  32165. 0xe3,0xea,0x70,0x82,0xff,0x7f,0xc9,0x88,
  32166. 0x8c,0x14,0x4d,0xa2,0xaf,0x58,0x42,0x9e,
  32167. 0xc9,0x60,0x31,0xdb,0xca,0xd3,0xda,0xd9,
  32168. 0xaf,0x0d,0xcb,0xaa,0xaf,0x26,0x8c,0xb8,
  32169. 0xfc,0xff,0xea,0xd9,0x4f,0x3c,0x7c,0xa4,
  32170. 0x95,0xe0,0x56,0xa9,0xb4,0x7a,0xcd,0xb7,
  32171. 0x51,0xfb,0x73,0xe6,0x66,0xc6,0xc6,0x55,
  32172. 0xad,0xe8,0x29,0x72,0x97,0xd0,0x7a,0xd1,
  32173. 0xba,0x5e,0x43,0xf1,0xbc,0xa3,0x23,0x01,
  32174. 0x65,0x13,0x39,0xe2,0x29,0x04,0xcc,0x8c,
  32175. 0x42,0xf5,0x8c,0x30,0xc0,0x4a,0xaf,0xdb,
  32176. 0x03,0x8d,0xda,0x08,0x47,0xdd,0x98,0x8d,
  32177. 0xcd,0xa6,0xf3,0xbf,0xd1,0x5c,0x4b,0x4c,
  32178. 0x45,0x25,0x00,0x4a,0xa0,0x6e,0xef,0xf8,
  32179. 0xca,0x61,0x78,0x3a,0xac,0xec,0x57,0xfb,
  32180. 0x3d,0x1f,0x92,0xb0,0xfe,0x2f,0xd1,0xa8,
  32181. 0x5f,0x67,0x24,0x51,0x7b,0x65,0xe6,0x14,
  32182. 0xad,0x68,0x08,0xd6,0xf6,0xee,0x34,0xdf,
  32183. 0xf7,0x31,0x0f,0xdc,0x82,0xae,0xbf,0xd9,
  32184. 0x04,0xb0,0x1e,0x1d,0xc5,0x4b,0x29,0x27,
  32185. 0x09,0x4b,0x2d,0xb6,0x8d,0x6f,0x90,0x3b,
  32186. 0x68,0x40,0x1a,0xde,0xbf,0x5a,0x7e,0x08,
  32187. 0xd7,0x8f,0xf4,0xef,0x5d,0x63,0x65,0x3a,
  32188. 0x65,0x04,0x0c,0xf9,0xbf,0xd4,0xac,0xa7,
  32189. 0x98,0x4a,0x74,0xd3,0x71,0x45,0x98,0x67,
  32190. 0x80,0xfc,0x0b,0x16,0xac,0x45,0x16,0x49,
  32191. 0xde,0x61,0x88,0xa7,0xdb,0xdf,0x19,0x1f,
  32192. 0x64,0xb5,0xfc,0x5e,0x2a,0xb4,0x7b,0x57,
  32193. 0xf7,0xf7,0x27,0x6c,0xd4,0x19,0xc1,0x7a,
  32194. 0x3c,0xa8,0xe1,0xb9,0x39,0xae,0x49,0xe4,
  32195. 0x88,0xac,0xba,0x6b,0x96,0x56,0x10,0xb5,
  32196. 0x48,0x01,0x09,0xc8,0xb1,0x7b,0x80,0xe1,
  32197. 0xb7,0xb7,0x50,0xdf,0xc7,0x59,0x8d,0x5d,
  32198. 0x50,0x11,0xfd,0x2d,0xcc,0x56,0x00,0xa3,
  32199. 0x2e,0xf5,0xb5,0x2a,0x1e,0xcc,0x82,0x0e,
  32200. 0x30,0x8a,0xa3,0x42,0x72,0x1a,0xac,0x09,
  32201. 0x43,0xbf,0x66,0x86,0xb6,0x4b,0x25,0x79,
  32202. 0x37,0x65,0x04,0xcc,0xc4,0x93,0xd9,0x7e,
  32203. 0x6a,0xed,0x3f,0xb0,0xf9,0xcd,0x71,0xa4,
  32204. 0x3d,0xd4,0x97,0xf0,0x1f,0x17,0xc0,0xe2,
  32205. 0xcb,0x37,0x97,0xaa,0x2a,0x2f,0x25,0x66,
  32206. 0x56,0x16,0x8e,0x6c,0x49,0x6a,0xfc,0x5f,
  32207. 0xb9,0x32,0x46,0xf6,0xb1,0x11,0x63,0x98,
  32208. 0xa3,0x46,0xf1,0xa6,0x41,0xf3,0xb0,0x41,
  32209. 0xe9,0x89,0xf7,0x91,0x4f,0x90,0xcc,0x2c,
  32210. 0x7f,0xff,0x35,0x78,0x76,0xe5,0x06,0xb5,
  32211. 0x0d,0x33,0x4b,0xa7,0x7c,0x22,0x5b,0xc3,
  32212. 0x07,0xba,0x53,0x71,0x52,0xf3,0xf1,0x61,
  32213. 0x0e,0x4e,0xaf,0xe5,0x95,0xf6,0xd9,0xd9,
  32214. 0x0d,0x11,0xfa,0xa9,0x33,0xa1,0x5e,0xf1,
  32215. 0x36,0x95,0x46,0x86,0x8a,0x7f,0x3a,0x45,
  32216. 0xa9,0x67,0x68,0xd4,0x0f,0xd9,0xd0,0x34,
  32217. 0x12,0xc0,0x91,0xc6,0x31,0x5c,0xf4,0xfd,
  32218. 0xe7,0xcb,0x68,0x60,0x69,0x37,0x38,0x0d,
  32219. 0xb2,0xea,0xaa,0x70,0x7b,0x4c,0x41,0x85,
  32220. 0xc3,0x2e,0xdd,0xcd,0xd3,0x06,0x70,0x5e,
  32221. 0x4d,0xc1,0xff,0xc8,0x72,0xee,0xee,0x47,
  32222. 0x5a,0x64,0xdf,0xac,0x86,0xab,0xa4,0x1c,
  32223. 0x06,0x18,0x98,0x3f,0x87,0x41,0xc5,0xef,
  32224. 0x68,0xd3,0xa1,0x01,0xe8,0xa3,0xb8,0xca,
  32225. 0xc6,0x0c,0x90,0x5c,0x15,0xfc,0x91,0x08,
  32226. 0x40,0xb9,0x4c,0x00,0xa0,0xb9,0xd0
  32227. };
  32228. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  32229. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  32230. sizeof(msg2),
  32231. sizeof(msg3),
  32232. 0 /*sizeof(msg1)*/,
  32233. 0 /*sizeof(msg1)*/,
  32234. sizeof(msg4)
  32235. };
  32236. #ifndef NO_ASN
  32237. static const byte privateEd25519[] = {
  32238. 0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,
  32239. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32240. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32241. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32242. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32243. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  32244. };
  32245. static const byte badPrivateEd25519[] = {
  32246. 0x30,0x52,0x02,0x01,0x00,0x30,0x05,0x06,
  32247. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32248. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32249. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32250. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32251. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32252. 0xa1,0x22,0x04,0x21,0xd7,0x5a,0x98,0x01, /* octet len 0x20 -> 0x21 */
  32253. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32254. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32255. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32256. 0xf7,0x07,0x51,0x1a,
  32257. 0x00 /* add additional bytes to make the pubkey bigger */
  32258. };
  32259. static const byte publicEd25519[] = {
  32260. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32261. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32262. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32263. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32264. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32265. 0xf7,0x07,0x51,0x1a
  32266. };
  32267. /* size has been altered to catch if sanity check is done */
  32268. static const byte badPublicEd25519[] = {
  32269. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32270. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32271. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32272. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32273. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32274. 0xf7,0x07,0x51,0x1a,
  32275. 0x00 /* add an additional byte to make the pubkey appear bigger */
  32276. };
  32277. static const byte privPubEd25519[] = {
  32278. 0x30,0x50,0x02,0x01,0x00,0x30,0x05,0x06,
  32279. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32280. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32281. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32282. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32283. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32284. 0x81,0x20,0xd7,0x5a,0x98,0x01,0x82,0xb1,
  32285. 0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,
  32286. 0x07,0x3a,0x0e,0xe1,0x72,0xf3,0xda,0xa6,
  32287. 0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7,0x07,
  32288. 0x51,0x1a
  32289. };
  32290. word32 idx;
  32291. #endif /* NO_ASN */
  32292. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32293. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32294. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32295. ed25519_key* key3 = NULL;
  32296. #else
  32297. ed25519_key key3[1];
  32298. #endif
  32299. #endif
  32300. WOLFSSL_ENTER("ed25519_test");
  32301. /* create ed25519 keys */
  32302. #ifndef HAVE_FIPS
  32303. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32304. #else
  32305. ret = wc_InitRng(&rng);
  32306. #endif
  32307. if (ret != 0)
  32308. return WC_TEST_RET_ENC_EC(ret);
  32309. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32310. key = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32311. if (ret != 0)
  32312. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32313. key2 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32314. if (ret != 0)
  32315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32316. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32317. key3 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32318. if (ret != 0)
  32319. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32320. #endif
  32321. #else
  32322. wc_ed25519_init_ex(key, HEAP_HINT, devId);
  32323. wc_ed25519_init_ex(key2, HEAP_HINT, devId);
  32324. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32325. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32326. #endif
  32327. #endif
  32328. #ifdef HAVE_ED25519_MAKE_KEY
  32329. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
  32330. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key2);
  32331. #endif
  32332. /* helper functions for signature and key size */
  32333. keySz = (word32)wc_ed25519_size(key);
  32334. sigSz = (word32)wc_ed25519_sig_size(key);
  32335. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  32336. defined(HAVE_ED25519_KEY_IMPORT)
  32337. for (i = 0; i < 6; i++) {
  32338. outlen = sizeof(out);
  32339. XMEMSET(out, 0, sizeof(out));
  32340. if (wc_ed25519_import_private_key(sKeys[i], ED25519_KEY_SIZE, pKeys[i],
  32341. pKeySz[i], key) != 0)
  32342. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32343. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key) != 0)
  32344. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32345. if (XMEMCMP(out, sigs[i], 64))
  32346. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32347. #if defined(HAVE_ED25519_VERIFY)
  32348. /* test verify on good msg */
  32349. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32350. key) != 0 || verify != 1)
  32351. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32352. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  32353. /* test verify on good msg using streaming interface directly */
  32354. if (wc_ed25519_verify_msg_init(out, outlen,
  32355. key, (byte)Ed25519, NULL, 0) != 0)
  32356. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32357. for (j = 0; j < msgSz[i]; j += i) {
  32358. if (wc_ed25519_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  32359. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32360. }
  32361. if (wc_ed25519_verify_msg_final(out, outlen, &verify,
  32362. key) != 0 || verify != 1)
  32363. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32364. #endif /* WOLFSSL_ED25519_STREAMING_VERIFY */
  32365. /* test verify on bad msg */
  32366. out[outlen-1] = out[outlen-1] + 1;
  32367. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32368. key) == 0 || verify == 1)
  32369. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32370. #endif /* HAVE_ED25519_VERIFY */
  32371. /* test api for import/exporting keys */
  32372. exportPSz = sizeof(exportPKey);
  32373. exportSSz = sizeof(exportSKey);
  32374. if (wc_ed25519_export_public(key, exportPKey, &exportPSz) != 0)
  32375. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32376. if (wc_ed25519_import_public_ex(exportPKey, exportPSz, key2, 1) != 0)
  32377. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32378. if (wc_ed25519_export_private_only(key, exportSKey, &exportSSz) != 0)
  32379. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32380. if (wc_ed25519_import_private_key(exportSKey, exportSSz,
  32381. exportPKey, exportPSz, key2) != 0)
  32382. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32383. /* clear "out" buffer and test sign with imported keys */
  32384. outlen = sizeof(out);
  32385. XMEMSET(out, 0, sizeof(out));
  32386. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key2) != 0)
  32387. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32388. #if defined(HAVE_ED25519_VERIFY)
  32389. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32390. key2) != 0 || verify != 1)
  32391. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32392. if (XMEMCMP(out, sigs[i], 64))
  32393. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32394. #endif /* HAVE_ED25519_VERIFY */
  32395. }
  32396. {
  32397. /* Run tests for some rare code paths */
  32398. /* sig is exactly equal to the order */
  32399. static const byte rareEd1[] = {
  32400. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32401. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32402. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32403. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32404. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32405. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32406. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32407. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32408. };
  32409. /* sig is larger than the order before we get to the low part */
  32410. static const byte rareEd2[] = {
  32411. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32412. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32413. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32414. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32415. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32416. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32417. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32418. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10
  32419. };
  32420. /* sig is larger than the order in the low part */
  32421. static const byte rareEd3[] = {
  32422. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32423. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32424. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32425. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32426. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32427. 0xd6, 0x9c, 0xf9, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32428. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32429. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32430. };
  32431. /* sig is smaller than the order */
  32432. static const byte rareEd4[] = {
  32433. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32434. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32435. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32436. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32437. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32438. 0xd6, 0x9c, 0xf1, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32439. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32440. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32441. };
  32442. ret = wc_ed25519_import_private_key(sKeys[0], ED25519_KEY_SIZE,
  32443. pKeys[0], pKeySz[0], key);
  32444. if (ret != 0)
  32445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32446. ret = wc_ed25519_verify_msg(rareEd1, sizeof(rareEd1), msgs[0], msgSz[0],
  32447. &verify, key);
  32448. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32449. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32450. ret = wc_ed25519_verify_msg(rareEd2, sizeof(rareEd2), msgs[0], msgSz[0],
  32451. &verify, key);
  32452. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32453. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32454. ret = wc_ed25519_verify_msg(rareEd3, sizeof(rareEd3), msgs[0], msgSz[0],
  32455. &verify, key);
  32456. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32457. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32458. ret = wc_ed25519_verify_msg(rareEd4, sizeof(rareEd4), msgs[0], msgSz[0],
  32459. &verify, key);
  32460. if (ret != WC_NO_ERR_TRACE(SIG_VERIFY_E))
  32461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32462. }
  32463. ret = ed25519ctx_test();
  32464. if (ret != 0)
  32465. goto cleanup;
  32466. ret = ed25519ph_test();
  32467. if (ret != 0)
  32468. goto cleanup;
  32469. #ifndef NO_ASN
  32470. /* Try ASN.1 encoded private-only key and public key. */
  32471. idx = 0;
  32472. ret = wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, key3,
  32473. sizeof(privateEd25519));
  32474. if (ret != 0)
  32475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32476. idx = 0;
  32477. if (wc_Ed25519PrivateKeyDecode(badPrivateEd25519, &idx, key3,
  32478. sizeof(badPrivateEd25519)) == 0)
  32479. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32480. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32481. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32482. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32483. /* try with a buffer size that is too large */
  32484. idx = 0;
  32485. if (wc_Ed25519PublicKeyDecode(badPublicEd25519, &idx, key3,
  32486. sizeof(badPublicEd25519)) == 0)
  32487. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32488. idx = 0;
  32489. ret = wc_Ed25519PublicKeyDecode(publicEd25519, &idx, key3,
  32490. sizeof(publicEd25519));
  32491. if (ret != 0)
  32492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32493. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32494. if (ret != 0)
  32495. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32496. if (XMEMCMP(out, sigs[0], 64))
  32497. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32498. #if defined(HAVE_ED25519_VERIFY)
  32499. /* test verify on good msg */
  32500. ret = wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3);
  32501. if (ret != 0 || verify != 1)
  32502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32503. #endif /* HAVE_ED25519_VERIFY */
  32504. wc_ed25519_free(key3);
  32505. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32506. idx = 0;
  32507. ret = wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, key3,
  32508. sizeof(privPubEd25519));
  32509. if (ret != 0)
  32510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32511. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32512. if (ret != 0)
  32513. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32514. if (XMEMCMP(out, sigs[0], 64))
  32515. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32516. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32517. wc_ed25519_delete(key3, &key3);
  32518. #else
  32519. wc_ed25519_free(key3);
  32520. #endif
  32521. #endif /* NO_ASN */
  32522. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32523. ret = ed25519_test_check_key();
  32524. if (ret < 0)
  32525. goto cleanup;
  32526. #ifdef WOLFSSL_TEST_CERT
  32527. ret = ed25519_test_cert();
  32528. if (ret < 0)
  32529. goto cleanup;
  32530. #if defined(WOLFSSL_CERT_GEN) && defined(HAVE_ED25519_MAKE_KEY)
  32531. ret = ed25519_test_make_cert();
  32532. if (ret < 0)
  32533. goto cleanup;
  32534. #endif /* WOLFSSL_CERT_GEN */
  32535. #endif /* WOLFSSL_TEST_CERT */
  32536. cleanup:
  32537. /* clean up keys when done */
  32538. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32539. wc_ed25519_delete(key, &key);
  32540. wc_ed25519_delete(key2, &key2);
  32541. #else
  32542. wc_ed25519_free(key);
  32543. wc_ed25519_free(key2);
  32544. #endif
  32545. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  32546. wc_FreeRng(&rng);
  32547. #endif
  32548. /* hush warnings of unused keySz and sigSz */
  32549. (void)keySz;
  32550. (void)sigSz;
  32551. return ret;
  32552. }
  32553. #endif /* HAVE_ED25519 */
  32554. #ifdef HAVE_CURVE448
  32555. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32556. defined(HAVE_CURVE448_KEY_IMPORT)
  32557. /* Test the wc_curve448_check_public API.
  32558. *
  32559. * returns 0 on success and -ve on failure.
  32560. */
  32561. static wc_test_ret_t curve448_check_public_test(void)
  32562. {
  32563. /* Little-endian values that will fail */
  32564. byte fail_le[][CURVE448_KEY_SIZE] = {
  32565. {
  32566. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32567. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32568. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32569. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32570. 0x00,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. },
  32574. {
  32575. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32576. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32577. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32578. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32579. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32580. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32581. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32582. },
  32583. };
  32584. /* Big-endian values that will fail */
  32585. byte fail_be[][CURVE448_KEY_SIZE] = {
  32586. {
  32587. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32588. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32589. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32590. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  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. },
  32595. {
  32596. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32597. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32598. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32599. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32600. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32601. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32602. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32603. },
  32604. };
  32605. /* Good or valid public value */
  32606. byte good[CURVE448_KEY_SIZE] = {
  32607. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32608. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32609. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32610. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32611. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32612. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32613. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32614. };
  32615. int i;
  32616. wc_test_ret_t ret;
  32617. /* Parameter checks */
  32618. /* NULL pointer */
  32619. ret = wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN);
  32620. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32621. return WC_TEST_RET_ENC_EC(ret);
  32622. ret = wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN);
  32623. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32624. return WC_TEST_RET_ENC_EC(ret);
  32625. /* Length of 0 treated differently to other invalid lengths for TLS */
  32626. ret = wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN);
  32627. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32628. return WC_TEST_RET_ENC_EC(ret);
  32629. ret = wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN);
  32630. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32631. return WC_TEST_RET_ENC_EC(ret);
  32632. /* Length not CURVE448_KEY_SIZE */
  32633. for (i = 1; i < CURVE448_KEY_SIZE + 2; i++) {
  32634. if (i == CURVE448_KEY_SIZE)
  32635. continue;
  32636. if (wc_curve448_check_public(good, (word32)i, EC448_LITTLE_ENDIAN) !=
  32637. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32638. return WC_TEST_RET_ENC_I(i);
  32639. }
  32640. if (wc_curve448_check_public(good, (word32)i, EC448_BIG_ENDIAN) !=
  32641. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32642. return WC_TEST_RET_ENC_I(i);
  32643. }
  32644. }
  32645. /* Little-endian fail cases */
  32646. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  32647. if (wc_curve448_check_public(fail_le[i], CURVE448_KEY_SIZE,
  32648. EC448_LITTLE_ENDIAN) == 0) {
  32649. return WC_TEST_RET_ENC_I(i);
  32650. }
  32651. }
  32652. /* Big-endian fail cases */
  32653. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  32654. if (wc_curve448_check_public(fail_be[i], CURVE448_KEY_SIZE,
  32655. EC448_BIG_ENDIAN) == 0) {
  32656. return WC_TEST_RET_ENC_I(i);
  32657. }
  32658. }
  32659. /* Check a valid public value works! */
  32660. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE,
  32661. EC448_LITTLE_ENDIAN);
  32662. if (ret != 0)
  32663. return WC_TEST_RET_ENC_EC(ret);
  32664. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN);
  32665. if (ret != 0)
  32666. return WC_TEST_RET_ENC_EC(ret);
  32667. return 0;
  32668. }
  32669. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32670. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void)
  32671. {
  32672. WC_RNG rng;
  32673. wc_test_ret_t ret;
  32674. #ifdef HAVE_CURVE448_SHARED_SECRET
  32675. byte sharedA[CURVE448_KEY_SIZE];
  32676. byte sharedB[CURVE448_KEY_SIZE];
  32677. word32 y;
  32678. #endif
  32679. #ifdef HAVE_CURVE448_KEY_EXPORT
  32680. byte exportBuf[CURVE448_KEY_SIZE];
  32681. #endif
  32682. word32 x = 0;
  32683. curve448_key userA, userB, pubKey;
  32684. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32685. defined(HAVE_CURVE448_KEY_IMPORT)
  32686. /* test vectors from
  32687. https://www.rfc-editor.org/rfc/rfc7748.html
  32688. */
  32689. /* secret key for party a */
  32690. byte sa[] = {
  32691. 0x6b, 0x72, 0x98, 0xa5, 0xc0, 0xd8, 0xc2, 0x9a,
  32692. 0x1d, 0xab, 0x27, 0xf1, 0xa6, 0x82, 0x63, 0x00,
  32693. 0x91, 0x73, 0x89, 0x44, 0x97, 0x41, 0xa9, 0x74,
  32694. 0xf5, 0xba, 0xc9, 0xd9, 0x8d, 0xc2, 0x98, 0xd4,
  32695. 0x65, 0x55, 0xbc, 0xe8, 0xba, 0xe8, 0x9e, 0xee,
  32696. 0xd4, 0x00, 0x58, 0x4b, 0xb0, 0x46, 0xcf, 0x75,
  32697. 0x57, 0x9f, 0x51, 0xd1, 0x25, 0x49, 0x8f, 0x9a,
  32698. };
  32699. /* public key for party a */
  32700. byte pa[] = {
  32701. 0xa0, 0x1f, 0xc4, 0x32, 0xe5, 0x80, 0x7f, 0x17,
  32702. 0x53, 0x0d, 0x12, 0x88, 0xda, 0x12, 0x5b, 0x0c,
  32703. 0xd4, 0x53, 0xd9, 0x41, 0x72, 0x64, 0x36, 0xc8,
  32704. 0xbb, 0xd9, 0xc5, 0x22, 0x2c, 0x3d, 0xa7, 0xfa,
  32705. 0x63, 0x9c, 0xe0, 0x3d, 0xb8, 0xd2, 0x3b, 0x27,
  32706. 0x4a, 0x07, 0x21, 0xa1, 0xae, 0xd5, 0x22, 0x7d,
  32707. 0xe6, 0xe3, 0xb7, 0x31, 0xcc, 0xf7, 0x08, 0x9b,
  32708. };
  32709. /* secret key for party b */
  32710. byte sb[] = {
  32711. 0x2d, 0x99, 0x73, 0x51, 0xb6, 0x10, 0x6f, 0x36,
  32712. 0xb0, 0xd1, 0x09, 0x1b, 0x92, 0x9c, 0x4c, 0x37,
  32713. 0x21, 0x3e, 0x0d, 0x2b, 0x97, 0xe8, 0x5e, 0xbb,
  32714. 0x20, 0xc1, 0x27, 0x69, 0x1d, 0x0d, 0xad, 0x8f,
  32715. 0x1d, 0x81, 0x75, 0xb0, 0x72, 0x37, 0x45, 0xe6,
  32716. 0x39, 0xa3, 0xcb, 0x70, 0x44, 0x29, 0x0b, 0x99,
  32717. 0xe0, 0xe2, 0xa0, 0xc2, 0x7a, 0x6a, 0x30, 0x1c,
  32718. };
  32719. /* public key for party b */
  32720. byte pb[] = {
  32721. 0x09, 0x36, 0xf3, 0x7b, 0xc6, 0xc1, 0xbd, 0x07,
  32722. 0xae, 0x3d, 0xec, 0x7a, 0xb5, 0xdc, 0x06, 0xa7,
  32723. 0x3c, 0xa1, 0x32, 0x42, 0xfb, 0x34, 0x3e, 0xfc,
  32724. 0x72, 0xb9, 0xd8, 0x27, 0x30, 0xb4, 0x45, 0xf3,
  32725. 0xd4, 0xb0, 0xbd, 0x07, 0x71, 0x62, 0xa4, 0x6d,
  32726. 0xcf, 0xec, 0x6f, 0x9b, 0x59, 0x0b, 0xfc, 0xbc,
  32727. 0xf5, 0x20, 0xcd, 0xb0, 0x29, 0xa8, 0xb7, 0x3e,
  32728. };
  32729. /* expected shared key */
  32730. byte ss[] = {
  32731. 0x9d, 0x87, 0x4a, 0x51, 0x37, 0x50, 0x9a, 0x44,
  32732. 0x9a, 0xd5, 0x85, 0x30, 0x40, 0x24, 0x1c, 0x52,
  32733. 0x36, 0x39, 0x54, 0x35, 0xc3, 0x64, 0x24, 0xfd,
  32734. 0x56, 0x0b, 0x0c, 0xb6, 0x2b, 0x28, 0x1d, 0x28,
  32735. 0x52, 0x75, 0xa7, 0x40, 0xce, 0x32, 0xa2, 0x2d,
  32736. 0xd1, 0x74, 0x0f, 0x4a, 0xa9, 0x16, 0x1c, 0xec,
  32737. 0x95, 0xcc, 0xc6, 0x1a, 0x18, 0xf4, 0xff, 0x07,
  32738. };
  32739. #endif /* HAVE_CURVE448_SHARED_SECRET */
  32740. (void)x;
  32741. WOLFSSL_ENTER("curve448_test");
  32742. #ifndef HAVE_FIPS
  32743. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32744. #else
  32745. ret = wc_InitRng(&rng);
  32746. #endif
  32747. if (ret != 0)
  32748. return WC_TEST_RET_ENC_EC(ret);
  32749. wc_curve448_init(&userA);
  32750. wc_curve448_init(&userB);
  32751. wc_curve448_init(&pubKey);
  32752. /* make curve448 keys */
  32753. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA);
  32754. if (ret != 0)
  32755. return WC_TEST_RET_ENC_EC(ret);
  32756. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB);
  32757. if (ret != 0)
  32758. return WC_TEST_RET_ENC_EC(ret);
  32759. #ifdef HAVE_CURVE448_SHARED_SECRET
  32760. /* find shared secret key */
  32761. x = sizeof(sharedA);
  32762. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32763. if (ret != 0)
  32764. return WC_TEST_RET_ENC_EC(ret);
  32765. y = sizeof(sharedB);
  32766. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32767. if (ret != 0)
  32768. return WC_TEST_RET_ENC_EC(ret);
  32769. /* compare shared secret keys to test they are the same */
  32770. if (y != x)
  32771. return WC_TEST_RET_ENC_NC;
  32772. if (XMEMCMP(sharedA, sharedB, x))
  32773. return WC_TEST_RET_ENC_NC;
  32774. #endif
  32775. #ifdef HAVE_CURVE448_KEY_EXPORT
  32776. /* export a public key and import it for another user */
  32777. x = sizeof(exportBuf);
  32778. ret = wc_curve448_export_public(&userA, exportBuf, &x);
  32779. if (ret != 0)
  32780. return WC_TEST_RET_ENC_EC(ret);
  32781. #ifdef HAVE_CURVE448_KEY_IMPORT
  32782. ret = wc_curve448_import_public(exportBuf, x, &pubKey);
  32783. if (ret != 0)
  32784. return WC_TEST_RET_ENC_EC(ret);
  32785. #endif
  32786. #endif
  32787. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32788. defined(HAVE_CURVE448_KEY_IMPORT)
  32789. /* test shared key after importing a public key */
  32790. XMEMSET(sharedB, 0, sizeof(sharedB));
  32791. y = sizeof(sharedB);
  32792. ret = wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y);
  32793. if (ret != 0)
  32794. return WC_TEST_RET_ENC_EC(ret);
  32795. if (XMEMCMP(sharedA, sharedB, y))
  32796. return WC_TEST_RET_ENC_NC;
  32797. /* import RFC test vectors and compare shared key */
  32798. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32799. if (ret != 0)
  32800. return WC_TEST_RET_ENC_EC(ret);
  32801. ret = wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB);
  32802. if (ret != 0)
  32803. return WC_TEST_RET_ENC_EC(ret);
  32804. /* test against known test vector */
  32805. XMEMSET(sharedB, 0, sizeof(sharedB));
  32806. y = sizeof(sharedB);
  32807. ret = wc_curve448_shared_secret(&userA, &userB, sharedB, &y);
  32808. if (ret != 0)
  32809. return WC_TEST_RET_ENC_EC(ret);
  32810. if (XMEMCMP(ss, sharedB, y))
  32811. return WC_TEST_RET_ENC_NC;
  32812. /* test swapping roles of keys and generating same shared key */
  32813. XMEMSET(sharedB, 0, sizeof(sharedB));
  32814. y = sizeof(sharedB);
  32815. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32816. if (ret != 0)
  32817. return WC_TEST_RET_ENC_EC(ret);
  32818. if (XMEMCMP(ss, sharedB, y))
  32819. return WC_TEST_RET_ENC_NC;
  32820. /* test with 1 generated key and 1 from known test vector */
  32821. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32822. if (ret != 0)
  32823. return WC_TEST_RET_ENC_EC(ret);
  32824. ret = wc_curve448_make_key(&rng, 56, &userB);
  32825. if (ret != 0)
  32826. return WC_TEST_RET_ENC_EC(ret);
  32827. x = sizeof(sharedA);
  32828. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32829. if (ret != 0)
  32830. return WC_TEST_RET_ENC_EC(ret);
  32831. y = sizeof(sharedB);
  32832. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32833. if (ret != 0)
  32834. return WC_TEST_RET_ENC_EC(ret);
  32835. /* compare shared secret keys to test they are the same */
  32836. if (y != x)
  32837. return WC_TEST_RET_ENC_NC;
  32838. if (XMEMCMP(sharedA, sharedB, x))
  32839. return WC_TEST_RET_ENC_NC;
  32840. ret = curve448_check_public_test();
  32841. if (ret != 0)
  32842. return ret;
  32843. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32844. /* clean up keys when done */
  32845. wc_curve448_free(&pubKey);
  32846. wc_curve448_free(&userB);
  32847. wc_curve448_free(&userA);
  32848. wc_FreeRng(&rng);
  32849. return 0;
  32850. }
  32851. #endif /* HAVE_CURVE448 */
  32852. #ifdef HAVE_ED448
  32853. #ifdef WOLFSSL_TEST_CERT
  32854. static wc_test_ret_t ed448_test_cert(void)
  32855. {
  32856. DecodedCert cert[2];
  32857. DecodedCert* serverCert = NULL;
  32858. DecodedCert* caCert = NULL;
  32859. #ifdef HAVE_ED448_VERIFY
  32860. ed448_key key;
  32861. ed448_key* pubKey = NULL;
  32862. int verify;
  32863. #endif /* HAVE_ED448_VERIFY */
  32864. wc_test_ret_t ret;
  32865. byte* tmp;
  32866. size_t bytes;
  32867. XFILE file;
  32868. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32869. if (tmp == NULL) {
  32870. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32871. }
  32872. #ifdef USE_CERT_BUFFERS_256
  32873. XMEMCPY(tmp, ca_ed448_cert, sizeof_ca_ed448_cert);
  32874. bytes = sizeof_ca_ed448_cert;
  32875. #elif !defined(NO_FILESYSTEM)
  32876. file = XFOPEN(caEd448Cert, "rb");
  32877. if (file == NULL) {
  32878. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32879. }
  32880. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32881. XFCLOSE(file);
  32882. if (bytes == 0)
  32883. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32884. #else
  32885. /* No certificate to use. */
  32886. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32887. #endif
  32888. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  32889. caCert = &cert[0];
  32890. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  32891. if (ret != 0)
  32892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32893. #ifdef USE_CERT_BUFFERS_256
  32894. XMEMCPY(tmp, server_ed448_cert, sizeof_server_ed448_cert);
  32895. bytes = sizeof_server_ed448_cert;
  32896. #elif !defined(NO_FILESYSTEM)
  32897. file = XFOPEN(serverEd448Cert, "rb");
  32898. if (file == NULL) {
  32899. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32900. }
  32901. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32902. XFCLOSE(file);
  32903. if (bytes == 0)
  32904. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32905. #else
  32906. /* No certificate to use. */
  32907. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32908. #endif
  32909. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  32910. serverCert = &cert[1];
  32911. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  32912. if (ret != 0)
  32913. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32914. #ifdef HAVE_ED448_VERIFY
  32915. ret = wc_ed448_init(&key);
  32916. if (ret < 0)
  32917. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32918. pubKey = &key;
  32919. ret = wc_ed448_import_public(caCert->publicKey, caCert->pubKeySize, pubKey);
  32920. if (ret < 0)
  32921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32922. ret = wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength,
  32923. serverCert->source + serverCert->certBegin,
  32924. serverCert->sigIndex - serverCert->certBegin,
  32925. &verify, pubKey, NULL, 0);
  32926. if (ret < 0 || verify != 1) {
  32927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32928. }
  32929. #endif /* HAVE_ED448_VERIFY */
  32930. done:
  32931. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32932. #ifdef HAVE_ED448_VERIFY
  32933. wc_ed448_free(pubKey);
  32934. #endif /* HAVE_ED448_VERIFY */
  32935. if (caCert != NULL)
  32936. FreeDecodedCert(caCert);
  32937. if (serverCert != NULL)
  32938. FreeDecodedCert(serverCert);
  32939. return ret;
  32940. }
  32941. static wc_test_ret_t ed448_test_make_cert(void)
  32942. {
  32943. WC_RNG rng;
  32944. Cert cert;
  32945. DecodedCert decode;
  32946. ed448_key key;
  32947. ed448_key* privKey = NULL;
  32948. wc_test_ret_t ret = 0;
  32949. byte* tmp = NULL;
  32950. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  32951. #ifndef HAVE_FIPS
  32952. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32953. #else
  32954. ret = wc_InitRng(&rng);
  32955. #endif
  32956. if (ret != 0)
  32957. return WC_TEST_RET_ENC_EC(ret);
  32958. wc_ed448_init(&key);
  32959. privKey = &key;
  32960. wc_ed448_make_key(&rng, ED448_KEY_SIZE, privKey);
  32961. cert.daysValid = 365 * 2;
  32962. cert.selfSigned = 1;
  32963. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  32964. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  32965. cert.isCA = 0;
  32966. #ifdef WOLFSSL_CERT_EXT
  32967. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  32968. if (ret < 0)
  32969. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32970. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32971. if (ret < 0)
  32972. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32973. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32974. if (ret < 0)
  32975. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32976. #endif
  32977. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32978. if (tmp == NULL) {
  32979. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32980. }
  32981. cert.sigType = CTC_ED448;
  32982. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng);
  32983. if (ret < 0)
  32984. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32985. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED448_TYPE,
  32986. privKey, &rng);
  32987. if (ret < 0)
  32988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32989. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  32990. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  32991. FreeDecodedCert(&decode);
  32992. if (ret != 0)
  32993. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32994. done:
  32995. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32996. wc_ed448_free(privKey);
  32997. wc_FreeRng(&rng);
  32998. return ret;
  32999. }
  33000. #endif /* WOLFSSL_TEST_CERT */
  33001. #if defined(HAVE_ED448_KEY_IMPORT)
  33002. static wc_test_ret_t ed448_test_check_key(void)
  33003. {
  33004. /* Fails to find x-ordinate from this y-ordinate. */
  33005. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  33006. 0x40,
  33007. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33008. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33009. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33010. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33011. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33012. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33013. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33014. 0x00
  33015. };
  33016. /* Y-ordinate value larger than prime. */
  33017. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  33018. 0x40,
  33019. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33020. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33021. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33022. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33023. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33024. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33025. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33026. 0xff
  33027. };
  33028. /* Y-ordinate value equal to prime. */
  33029. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  33030. 0x40,
  33031. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33032. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33033. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33034. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  33035. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33036. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33037. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33038. 0xff
  33039. };
  33040. /* Y-ordinate value equal to prime - 1. */
  33041. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  33042. 0x40,
  33043. 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33044. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33045. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33046. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  33047. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33048. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33049. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33050. 0xff
  33051. };
  33052. ed448_key key;
  33053. int ret;
  33054. int res = 0;
  33055. /* Initialize key for use. */
  33056. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33057. if (ret != 0) {
  33058. return WC_TEST_RET_ENC_NC;
  33059. }
  33060. /* Load bad public key only and perform checks. */
  33061. ret = wc_ed448_import_public(key_bad_y, ED448_PUB_KEY_SIZE + 1, &key);
  33062. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33063. res = WC_TEST_RET_ENC_NC;
  33064. }
  33065. if (ret == 0) {
  33066. /* Load bad public key only and perform checks. */
  33067. ret = wc_ed448_import_public(key_bad_y_max, ED448_PUB_KEY_SIZE + 1,
  33068. &key);
  33069. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33070. res = WC_TEST_RET_ENC_NC;
  33071. }
  33072. }
  33073. if (res == 0) {
  33074. /* Load bad public key only and perform checks. */
  33075. ret = wc_ed448_import_public(key_bad_y_is_p, ED448_PUB_KEY_SIZE + 1,
  33076. &key);
  33077. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33078. res = WC_TEST_RET_ENC_NC;
  33079. }
  33080. }
  33081. if (res == 0) {
  33082. /* Load good public key only and perform checks. */
  33083. ret = wc_ed448_import_public(key_y_is_p_minus_1, ED448_PUB_KEY_SIZE + 1,
  33084. &key);
  33085. if (ret != 0) {
  33086. res = WC_TEST_RET_ENC_NC;
  33087. }
  33088. }
  33089. /* Dispose of key. */
  33090. wc_ed448_free(&key);
  33091. return res;
  33092. }
  33093. #endif
  33094. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33095. defined(HAVE_ED448_KEY_IMPORT)
  33096. static wc_test_ret_t ed448_ctx_test(void)
  33097. {
  33098. wc_test_ret_t ret;
  33099. byte out[ED448_SIG_SIZE];
  33100. word32 outlen;
  33101. #ifdef HAVE_ED448_VERIFY
  33102. int verify;
  33103. #endif /* HAVE_ED448_VERIFY */
  33104. ed448_key key;
  33105. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  33106. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33107. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33108. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33109. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33110. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33111. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33112. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33113. 0x4e
  33114. };
  33115. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  33116. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33117. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33118. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33119. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33120. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33121. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33122. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33123. 0x80
  33124. };
  33125. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx[] = {
  33126. 0xd4, 0xf8, 0xf6, 0x13, 0x17, 0x70, 0xdd, 0x46,
  33127. 0xf4, 0x08, 0x67, 0xd6, 0xfd, 0x5d, 0x50, 0x55,
  33128. 0xde, 0x43, 0x54, 0x1f, 0x8c, 0x5e, 0x35, 0xab,
  33129. 0xbc, 0xd0, 0x01, 0xb3, 0x2a, 0x89, 0xf7, 0xd2,
  33130. 0x15, 0x1f, 0x76, 0x47, 0xf1, 0x1d, 0x8c, 0xa2,
  33131. 0xae, 0x27, 0x9f, 0xb8, 0x42, 0xd6, 0x07, 0x21,
  33132. 0x7f, 0xce, 0x6e, 0x04, 0x2f, 0x68, 0x15, 0xea,
  33133. 0x00, 0x0c, 0x85, 0x74, 0x1d, 0xe5, 0xc8, 0xda,
  33134. 0x11, 0x44, 0xa6, 0xa1, 0xab, 0xa7, 0xf9, 0x6d,
  33135. 0xe4, 0x25, 0x05, 0xd7, 0xa7, 0x29, 0x85, 0x24,
  33136. 0xfd, 0xa5, 0x38, 0xfc, 0xcb, 0xbb, 0x75, 0x4f,
  33137. 0x57, 0x8c, 0x1c, 0xad, 0x10, 0xd5, 0x4d, 0x0d,
  33138. 0x54, 0x28, 0x40, 0x7e, 0x85, 0xdc, 0xbc, 0x98,
  33139. 0xa4, 0x91, 0x55, 0xc1, 0x37, 0x64, 0xe6, 0x6c,
  33140. 0x3c, 0x00
  33141. };
  33142. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  33143. 0x03
  33144. };
  33145. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  33146. 0x66,0x6f,0x6f
  33147. };
  33148. outlen = sizeof(out);
  33149. XMEMSET(out, 0, sizeof(out));
  33150. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33151. if (ret != 0)
  33152. return WC_TEST_RET_ENC_EC(ret);
  33153. ret = wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx,
  33154. sizeof(pKeyCtx), &key);
  33155. if (ret != 0)
  33156. return WC_TEST_RET_ENC_EC(ret);
  33157. ret = wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  33158. contextCtx, sizeof(contextCtx));
  33159. if (ret != 0)
  33160. return WC_TEST_RET_ENC_EC(ret);
  33161. if (XMEMCMP(out, sigCtx, sizeof(sigCtx)))
  33162. return WC_TEST_RET_ENC_NC;
  33163. #if defined(HAVE_ED448_VERIFY)
  33164. /* test verify on good msg */
  33165. ret = wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key,
  33166. contextCtx, sizeof(contextCtx));
  33167. if (ret != 0 || verify != 1)
  33168. return WC_TEST_RET_ENC_EC(ret);
  33169. #endif
  33170. wc_ed448_free(&key);
  33171. return 0;
  33172. }
  33173. static wc_test_ret_t ed448ph_test(void)
  33174. {
  33175. wc_test_ret_t ret;
  33176. byte out[ED448_SIG_SIZE];
  33177. word32 outlen;
  33178. #ifdef HAVE_ED448_VERIFY
  33179. int verify;
  33180. #endif /* HAVE_ED448_VERIFY */
  33181. ed448_key key;
  33182. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  33183. 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
  33184. 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
  33185. 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
  33186. 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42,
  33187. 0xef, 0x78, 0x22, 0xe0, 0xd5, 0x10, 0x41, 0x27,
  33188. 0xdc, 0x05, 0xd6, 0xdb, 0xef, 0xde, 0x69, 0xe3,
  33189. 0xab, 0x2c, 0xec, 0x7c, 0x86, 0x7c, 0x6e, 0x2c,
  33190. 0x49
  33191. };
  33192. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  33193. 0x25, 0x9b, 0x71, 0xc1, 0x9f, 0x83, 0xef, 0x77,
  33194. 0xa7, 0xab, 0xd2, 0x65, 0x24, 0xcb, 0xdb, 0x31,
  33195. 0x61, 0xb5, 0x90, 0xa4, 0x8f, 0x7d, 0x17, 0xde,
  33196. 0x3e, 0xe0, 0xba, 0x9c, 0x52, 0xbe, 0xb7, 0x43,
  33197. 0xc0, 0x94, 0x28, 0xa1, 0x31, 0xd6, 0xb1, 0xb5,
  33198. 0x73, 0x03, 0xd9, 0x0d, 0x81, 0x32, 0xc2, 0x76,
  33199. 0xd5, 0xed, 0x3d, 0x5d, 0x01, 0xc0, 0xf5, 0x38,
  33200. 0x80
  33201. };
  33202. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  33203. 0x82, 0x2f, 0x69, 0x01, 0xf7, 0x48, 0x0f, 0x3d,
  33204. 0x5f, 0x56, 0x2c, 0x59, 0x29, 0x94, 0xd9, 0x69,
  33205. 0x36, 0x02, 0x87, 0x56, 0x14, 0x48, 0x32, 0x56,
  33206. 0x50, 0x56, 0x00, 0xbb, 0xc2, 0x81, 0xae, 0x38,
  33207. 0x1f, 0x54, 0xd6, 0xbc, 0xe2, 0xea, 0x91, 0x15,
  33208. 0x74, 0x93, 0x2f, 0x52, 0xa4, 0xe6, 0xca, 0xdd,
  33209. 0x78, 0x76, 0x93, 0x75, 0xec, 0x3f, 0xfd, 0x1b,
  33210. 0x80, 0x1a, 0x0d, 0x9b, 0x3f, 0x40, 0x30, 0xcd,
  33211. 0x43, 0x39, 0x64, 0xb6, 0x45, 0x7e, 0xa3, 0x94,
  33212. 0x76, 0x51, 0x12, 0x14, 0xf9, 0x74, 0x69, 0xb5,
  33213. 0x7d, 0xd3, 0x2d, 0xbc, 0x56, 0x0a, 0x9a, 0x94,
  33214. 0xd0, 0x0b, 0xff, 0x07, 0x62, 0x04, 0x64, 0xa3,
  33215. 0xad, 0x20, 0x3d, 0xf7, 0xdc, 0x7c, 0xe3, 0x60,
  33216. 0xc3, 0xcd, 0x36, 0x96, 0xd9, 0xd9, 0xfa, 0xb9,
  33217. 0x0f, 0x00
  33218. };
  33219. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  33220. 0xc3, 0x22, 0x99, 0xd4, 0x6e, 0xc8, 0xff, 0x02,
  33221. 0xb5, 0x45, 0x40, 0x98, 0x28, 0x14, 0xdc, 0xe9,
  33222. 0xa0, 0x58, 0x12, 0xf8, 0x19, 0x62, 0xb6, 0x49,
  33223. 0xd5, 0x28, 0x09, 0x59, 0x16, 0xa2, 0xaa, 0x48,
  33224. 0x10, 0x65, 0xb1, 0x58, 0x04, 0x23, 0xef, 0x92,
  33225. 0x7e, 0xcf, 0x0a, 0xf5, 0x88, 0x8f, 0x90, 0xda,
  33226. 0x0f, 0x6a, 0x9a, 0x85, 0xad, 0x5d, 0xc3, 0xf2,
  33227. 0x80, 0xd9, 0x12, 0x24, 0xba, 0x99, 0x11, 0xa3,
  33228. 0x65, 0x3d, 0x00, 0xe4, 0x84, 0xe2, 0xce, 0x23,
  33229. 0x25, 0x21, 0x48, 0x1c, 0x86, 0x58, 0xdf, 0x30,
  33230. 0x4b, 0xb7, 0x74, 0x5a, 0x73, 0x51, 0x4c, 0xdb,
  33231. 0x9b, 0xf3, 0xe1, 0x57, 0x84, 0xab, 0x71, 0x28,
  33232. 0x4f, 0x8d, 0x07, 0x04, 0xa6, 0x08, 0xc5, 0x4a,
  33233. 0x6b, 0x62, 0xd9, 0x7b, 0xeb, 0x51, 0x1d, 0x13,
  33234. 0x21, 0x00
  33235. };
  33236. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  33237. 0x61,0x62,0x63
  33238. };
  33239. /* SHA-512 hash of msgPh */
  33240. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  33241. 0x48, 0x33, 0x66, 0x60, 0x13, 0x60, 0xa8, 0x77,
  33242. 0x1c, 0x68, 0x63, 0x08, 0x0c, 0xc4, 0x11, 0x4d,
  33243. 0x8d, 0xb4, 0x45, 0x30, 0xf8, 0xf1, 0xe1, 0xee,
  33244. 0x4f, 0x94, 0xea, 0x37, 0xe7, 0x8b, 0x57, 0x39,
  33245. 0xd5, 0xa1, 0x5b, 0xef, 0x18, 0x6a, 0x53, 0x86,
  33246. 0xc7, 0x57, 0x44, 0xc0, 0x52, 0x7e, 0x1f, 0xaa,
  33247. 0x9f, 0x87, 0x26, 0xe4, 0x62, 0xa1, 0x2a, 0x4f,
  33248. 0xeb, 0x06, 0xbd, 0x88, 0x01, 0xe7, 0x51, 0xe4
  33249. };
  33250. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  33251. 0x66,0x6f,0x6f
  33252. };
  33253. outlen = sizeof(out);
  33254. XMEMSET(out, 0, sizeof(out));
  33255. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33256. if (ret != 0)
  33257. return WC_TEST_RET_ENC_EC(ret);
  33258. ret = wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh,
  33259. sizeof(pKeyPh), &key);
  33260. if (ret != 0)
  33261. return WC_TEST_RET_ENC_EC(ret);
  33262. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL,
  33263. 0);
  33264. if (ret != 0)
  33265. return WC_TEST_RET_ENC_EC(ret);
  33266. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33267. return WC_TEST_RET_ENC_NC;
  33268. #if defined(HAVE_ED448_VERIFY)
  33269. /* test verify on good msg */
  33270. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33271. NULL, 0);
  33272. if (ret != 0 || verify != 1) {
  33273. return WC_TEST_RET_ENC_EC(ret);
  33274. }
  33275. #endif
  33276. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  33277. contextPh2, sizeof(contextPh2));
  33278. if (ret != 0)
  33279. return WC_TEST_RET_ENC_EC(ret);
  33280. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33281. return WC_TEST_RET_ENC_NC;
  33282. #if defined(HAVE_ED448_VERIFY)
  33283. /* test verify on good msg */
  33284. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33285. contextPh2, sizeof(contextPh2));
  33286. if (ret != 0 || verify != 1) {
  33287. return WC_TEST_RET_ENC_EC(ret);
  33288. }
  33289. #endif
  33290. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL,
  33291. 0);
  33292. if (ret != 0)
  33293. return WC_TEST_RET_ENC_EC(ret);
  33294. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33295. return WC_TEST_RET_ENC_NC;
  33296. #if defined(HAVE_ED448_VERIFY)
  33297. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33298. &key, NULL, 0);
  33299. if (ret != 0 || verify != 1) {
  33300. return WC_TEST_RET_ENC_EC(ret);
  33301. }
  33302. #endif
  33303. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  33304. contextPh2, sizeof(contextPh2));
  33305. if (ret != 0)
  33306. return WC_TEST_RET_ENC_EC(ret);
  33307. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33308. return WC_TEST_RET_ENC_NC;
  33309. #if defined(HAVE_ED448_VERIFY)
  33310. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33311. &key, contextPh2, sizeof(contextPh2));
  33312. if (ret != 0 || verify != 1) {
  33313. return WC_TEST_RET_ENC_EC(ret);
  33314. }
  33315. #endif
  33316. wc_ed448_free(&key);
  33317. return 0;
  33318. }
  33319. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33320. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
  33321. {
  33322. wc_test_ret_t ret;
  33323. WC_RNG rng;
  33324. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33325. defined(HAVE_ED448_KEY_IMPORT)
  33326. byte out[ED448_SIG_SIZE];
  33327. int i;
  33328. word32 outlen;
  33329. #ifdef HAVE_ED448_VERIFY
  33330. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33331. int j;
  33332. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33333. int verify;
  33334. #endif /* HAVE_ED448_VERIFY */
  33335. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33336. word32 keySz, sigSz;
  33337. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33338. ed448_key *key = NULL;
  33339. ed448_key *key2 = NULL;
  33340. #else
  33341. ed448_key key[1];
  33342. ed448_key key2[1];
  33343. #endif
  33344. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33345. defined(HAVE_ED448_KEY_IMPORT)
  33346. /* test vectors from
  33347. https://tools.ietf.org/html/rfc8032
  33348. */
  33349. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  33350. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33351. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33352. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33353. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33354. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33355. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33356. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33357. 0x5b
  33358. };
  33359. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  33360. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33361. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33362. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33363. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33364. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33365. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33366. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33367. 0x4e
  33368. };
  33369. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  33370. 0x25, 0x8c, 0xdd, 0x4a, 0xda, 0x32, 0xed, 0x9c,
  33371. 0x9f, 0xf5, 0x4e, 0x63, 0x75, 0x6a, 0xe5, 0x82,
  33372. 0xfb, 0x8f, 0xab, 0x2a, 0xc7, 0x21, 0xf2, 0xc8,
  33373. 0xe6, 0x76, 0xa7, 0x27, 0x68, 0x51, 0x3d, 0x93,
  33374. 0x9f, 0x63, 0xdd, 0xdb, 0x55, 0x60, 0x91, 0x33,
  33375. 0xf2, 0x9a, 0xdf, 0x86, 0xec, 0x99, 0x29, 0xdc,
  33376. 0xcb, 0x52, 0xc1, 0xc5, 0xfd, 0x2f, 0xf7, 0xe2,
  33377. 0x1b
  33378. };
  33379. /* uncompressed test */
  33380. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  33381. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33382. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33383. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33384. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33385. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33386. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33387. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33388. 0x5b
  33389. };
  33390. /* compressed prefix test */
  33391. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  33392. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33393. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33394. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33395. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33396. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33397. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33398. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33399. 0x5b
  33400. };
  33401. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  33402. 0x87, 0x2d, 0x09, 0x37, 0x80, 0xf5, 0xd3, 0x73,
  33403. 0x0d, 0xf7, 0xc2, 0x12, 0x66, 0x4b, 0x37, 0xb8,
  33404. 0xa0, 0xf2, 0x4f, 0x56, 0x81, 0x0d, 0xaa, 0x83,
  33405. 0x82, 0xcd, 0x4f, 0xa3, 0xf7, 0x76, 0x34, 0xec,
  33406. 0x44, 0xdc, 0x54, 0xf1, 0xc2, 0xed, 0x9b, 0xea,
  33407. 0x86, 0xfa, 0xfb, 0x76, 0x32, 0xd8, 0xbe, 0x19,
  33408. 0x9e, 0xa1, 0x65, 0xf5, 0xad, 0x55, 0xdd, 0x9c,
  33409. 0xe8
  33410. };
  33411. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  33412. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  33413. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33414. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33415. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33416. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33417. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33418. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33419. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33420. 0x80
  33421. };
  33422. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  33423. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33424. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33425. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33426. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33427. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33428. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33429. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33430. 0x80
  33431. };
  33432. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  33433. 0x3b, 0xa1, 0x6d, 0xa0, 0xc6, 0xf2, 0xcc, 0x1f,
  33434. 0x30, 0x18, 0x77, 0x40, 0x75, 0x6f, 0x5e, 0x79,
  33435. 0x8d, 0x6b, 0xc5, 0xfc, 0x01, 0x5d, 0x7c, 0x63,
  33436. 0xcc, 0x95, 0x10, 0xee, 0x3f, 0xd4, 0x4a, 0xdc,
  33437. 0x24, 0xd8, 0xe9, 0x68, 0xb6, 0xe4, 0x6e, 0x6f,
  33438. 0x94, 0xd1, 0x9b, 0x94, 0x53, 0x61, 0x72, 0x6b,
  33439. 0xd7, 0x5e, 0x14, 0x9e, 0xf0, 0x98, 0x17, 0xf5,
  33440. 0x80
  33441. };
  33442. /* uncompressed test */
  33443. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  33444. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33445. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33446. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33447. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33448. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33449. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33450. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33451. 0x80
  33452. };
  33453. /* compressed prefix */
  33454. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  33455. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33456. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33457. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33458. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33459. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33460. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33461. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33462. 0x80
  33463. };
  33464. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  33465. 0xa8, 0x1b, 0x2e, 0x8a, 0x70, 0xa5, 0xac, 0x94,
  33466. 0xff, 0xdb, 0xcc, 0x9b, 0xad, 0xfc, 0x3f, 0xeb,
  33467. 0x08, 0x01, 0xf2, 0x58, 0x57, 0x8b, 0xb1, 0x14,
  33468. 0xad, 0x44, 0xec, 0xe1, 0xec, 0x0e, 0x79, 0x9d,
  33469. 0xa0, 0x8e, 0xff, 0xb8, 0x1c, 0x5d, 0x68, 0x5c,
  33470. 0x0c, 0x56, 0xf6, 0x4e, 0xec, 0xae, 0xf8, 0xcd,
  33471. 0xf1, 0x1c, 0xc3, 0x87, 0x37, 0x83, 0x8c, 0xf4,
  33472. 0x00
  33473. };
  33474. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  33475. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  33476. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  33477. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  33478. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33479. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33480. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33481. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33482. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33483. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33484. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33485. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33486. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33487. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33488. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33489. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33490. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33491. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33492. 0x26, 0x00
  33493. };
  33494. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  33495. 0x26, 0xb8, 0xf9, 0x17, 0x27, 0xbd, 0x62, 0x89,
  33496. 0x7a, 0xf1, 0x5e, 0x41, 0xeb, 0x43, 0xc3, 0x77,
  33497. 0xef, 0xb9, 0xc6, 0x10, 0xd4, 0x8f, 0x23, 0x35,
  33498. 0xcb, 0x0b, 0xd0, 0x08, 0x78, 0x10, 0xf4, 0x35,
  33499. 0x25, 0x41, 0xb1, 0x43, 0xc4, 0xb9, 0x81, 0xb7,
  33500. 0xe1, 0x8f, 0x62, 0xde, 0x8c, 0xcd, 0xf6, 0x33,
  33501. 0xfc, 0x1b, 0xf0, 0x37, 0xab, 0x7c, 0xd7, 0x79,
  33502. 0x80, 0x5e, 0x0d, 0xbc, 0xc0, 0xaa, 0xe1, 0xcb,
  33503. 0xce, 0xe1, 0xaf, 0xb2, 0xe0, 0x27, 0xdf, 0x36,
  33504. 0xbc, 0x04, 0xdc, 0xec, 0xbf, 0x15, 0x43, 0x36,
  33505. 0xc1, 0x9f, 0x0a, 0xf7, 0xe0, 0xa6, 0x47, 0x29,
  33506. 0x05, 0xe7, 0x99, 0xf1, 0x95, 0x3d, 0x2a, 0x0f,
  33507. 0xf3, 0x34, 0x8a, 0xb2, 0x1a, 0xa4, 0xad, 0xaf,
  33508. 0xd1, 0xd2, 0x34, 0x44, 0x1c, 0xf8, 0x07, 0xc0,
  33509. 0x3a, 0x00
  33510. };
  33511. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  33512. 0x7e, 0xee, 0xab, 0x7c, 0x4e, 0x50, 0xfb, 0x79,
  33513. 0x9b, 0x41, 0x8e, 0xe5, 0xe3, 0x19, 0x7f, 0xf6,
  33514. 0xbf, 0x15, 0xd4, 0x3a, 0x14, 0xc3, 0x43, 0x89,
  33515. 0xb5, 0x9d, 0xd1, 0xa7, 0xb1, 0xb8, 0x5b, 0x4a,
  33516. 0xe9, 0x04, 0x38, 0xac, 0xa6, 0x34, 0xbe, 0xa4,
  33517. 0x5e, 0x3a, 0x26, 0x95, 0xf1, 0x27, 0x0f, 0x07,
  33518. 0xfd, 0xcd, 0xf7, 0xc6, 0x2b, 0x8e, 0xfe, 0xaf,
  33519. 0x00, 0xb4, 0x5c, 0x2c, 0x96, 0xba, 0x45, 0x7e,
  33520. 0xb1, 0xa8, 0xbf, 0x07, 0x5a, 0x3d, 0xb2, 0x8e,
  33521. 0x5c, 0x24, 0xf6, 0xb9, 0x23, 0xed, 0x4a, 0xd7,
  33522. 0x47, 0xc3, 0xc9, 0xe0, 0x3c, 0x70, 0x79, 0xef,
  33523. 0xb8, 0x7c, 0xb1, 0x10, 0xd3, 0xa9, 0x98, 0x61,
  33524. 0xe7, 0x20, 0x03, 0xcb, 0xae, 0x6d, 0x6b, 0x8b,
  33525. 0x82, 0x7e, 0x4e, 0x6c, 0x14, 0x30, 0x64, 0xff,
  33526. 0x3c, 0x00
  33527. };
  33528. /* uncompressed test */
  33529. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  33530. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33531. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33532. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33533. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33534. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33535. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33536. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33537. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33538. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33539. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33540. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33541. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33542. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33543. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33544. 0x26, 0x00
  33545. };
  33546. /* compressed prefix */
  33547. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  33548. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33549. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33550. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33551. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33552. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33553. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33554. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33555. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33556. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33557. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33558. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33559. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33560. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33561. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33562. 0x26, 0x00
  33563. };
  33564. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  33565. 0xe3, 0x01, 0x34, 0x5a, 0x41, 0xa3, 0x9a, 0x4d,
  33566. 0x72, 0xff, 0xf8, 0xdf, 0x69, 0xc9, 0x80, 0x75,
  33567. 0xa0, 0xcc, 0x08, 0x2b, 0x80, 0x2f, 0xc9, 0xb2,
  33568. 0xb6, 0xbc, 0x50, 0x3f, 0x92, 0x6b, 0x65, 0xbd,
  33569. 0xdf, 0x7f, 0x4c, 0x8f, 0x1c, 0xb4, 0x9f, 0x63,
  33570. 0x96, 0xaf, 0xc8, 0xa7, 0x0a, 0xbe, 0x6d, 0x8a,
  33571. 0xef, 0x0d, 0xb4, 0x78, 0xd4, 0xc6, 0xb2, 0x97,
  33572. 0x00, 0x76, 0xc6, 0xa0, 0x48, 0x4f, 0xe7, 0x6d,
  33573. 0x76, 0xb3, 0xa9, 0x76, 0x25, 0xd7, 0x9f, 0x1c,
  33574. 0xe2, 0x40, 0xe7, 0xc5, 0x76, 0x75, 0x0d, 0x29,
  33575. 0x55, 0x28, 0x28, 0x6f, 0x71, 0x9b, 0x41, 0x3d,
  33576. 0xe9, 0xad, 0xa3, 0xe8, 0xeb, 0x78, 0xed, 0x57,
  33577. 0x36, 0x03, 0xce, 0x30, 0xd8, 0xbb, 0x76, 0x17,
  33578. 0x85, 0xdc, 0x30, 0xdb, 0xc3, 0x20, 0x86, 0x9e,
  33579. 0x1a, 0x00
  33580. };
  33581. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  33582. #define SIGSZ sizeof(sig1)
  33583. PEDANTIC_EXTENSION WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = { 0 };
  33584. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = { 0x03 };
  33585. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = { 0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd,
  33586. 0x66, 0x81, 0x1e, 0x29, 0x15 };
  33587. /* test of a 1023 byte long message */
  33588. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  33589. 0x6d, 0xdf, 0x80, 0x2e, 0x1a, 0xae, 0x49, 0x86,
  33590. 0x93, 0x5f, 0x7f, 0x98, 0x1b, 0xa3, 0xf0, 0x35,
  33591. 0x1d, 0x62, 0x73, 0xc0, 0xa0, 0xc2, 0x2c, 0x9c,
  33592. 0x0e, 0x83, 0x39, 0x16, 0x8e, 0x67, 0x54, 0x12,
  33593. 0xa3, 0xde, 0xbf, 0xaf, 0x43, 0x5e, 0xd6, 0x51,
  33594. 0x55, 0x80, 0x07, 0xdb, 0x43, 0x84, 0xb6, 0x50,
  33595. 0xfc, 0xc0, 0x7e, 0x3b, 0x58, 0x6a, 0x27, 0xa4,
  33596. 0xf7, 0xa0, 0x0a, 0xc8, 0xa6, 0xfe, 0xc2, 0xcd,
  33597. 0x86, 0xae, 0x4b, 0xf1, 0x57, 0x0c, 0x41, 0xe6,
  33598. 0xa4, 0x0c, 0x93, 0x1d, 0xb2, 0x7b, 0x2f, 0xaa,
  33599. 0x15, 0xa8, 0xce, 0xdd, 0x52, 0xcf, 0xf7, 0x36,
  33600. 0x2c, 0x4e, 0x6e, 0x23, 0xda, 0xec, 0x0f, 0xbc,
  33601. 0x3a, 0x79, 0xb6, 0x80, 0x6e, 0x31, 0x6e, 0xfc,
  33602. 0xc7, 0xb6, 0x81, 0x19, 0xbf, 0x46, 0xbc, 0x76,
  33603. 0xa2, 0x60, 0x67, 0xa5, 0x3f, 0x29, 0x6d, 0xaf,
  33604. 0xdb, 0xdc, 0x11, 0xc7, 0x7f, 0x77, 0x77, 0xe9,
  33605. 0x72, 0x66, 0x0c, 0xf4, 0xb6, 0xa9, 0xb3, 0x69,
  33606. 0xa6, 0x66, 0x5f, 0x02, 0xe0, 0xcc, 0x9b, 0x6e,
  33607. 0xdf, 0xad, 0x13, 0x6b, 0x4f, 0xab, 0xe7, 0x23,
  33608. 0xd2, 0x81, 0x3d, 0xb3, 0x13, 0x6c, 0xfd, 0xe9,
  33609. 0xb6, 0xd0, 0x44, 0x32, 0x2f, 0xee, 0x29, 0x47,
  33610. 0x95, 0x2e, 0x03, 0x1b, 0x73, 0xab, 0x5c, 0x60,
  33611. 0x33, 0x49, 0xb3, 0x07, 0xbd, 0xc2, 0x7b, 0xc6,
  33612. 0xcb, 0x8b, 0x8b, 0xbd, 0x7b, 0xd3, 0x23, 0x21,
  33613. 0x9b, 0x80, 0x33, 0xa5, 0x81, 0xb5, 0x9e, 0xad,
  33614. 0xeb, 0xb0, 0x9b, 0x3c, 0x4f, 0x3d, 0x22, 0x77,
  33615. 0xd4, 0xf0, 0x34, 0x36, 0x24, 0xac, 0xc8, 0x17,
  33616. 0x80, 0x47, 0x28, 0xb2, 0x5a, 0xb7, 0x97, 0x17,
  33617. 0x2b, 0x4c, 0x5c, 0x21, 0xa2, 0x2f, 0x9c, 0x78,
  33618. 0x39, 0xd6, 0x43, 0x00, 0x23, 0x2e, 0xb6, 0x6e,
  33619. 0x53, 0xf3, 0x1c, 0x72, 0x3f, 0xa3, 0x7f, 0xe3,
  33620. 0x87, 0xc7, 0xd3, 0xe5, 0x0b, 0xdf, 0x98, 0x13,
  33621. 0xa3, 0x0e, 0x5b, 0xb1, 0x2c, 0xf4, 0xcd, 0x93,
  33622. 0x0c, 0x40, 0xcf, 0xb4, 0xe1, 0xfc, 0x62, 0x25,
  33623. 0x92, 0xa4, 0x95, 0x88, 0x79, 0x44, 0x94, 0xd5,
  33624. 0x6d, 0x24, 0xea, 0x4b, 0x40, 0xc8, 0x9f, 0xc0,
  33625. 0x59, 0x6c, 0xc9, 0xeb, 0xb9, 0x61, 0xc8, 0xcb,
  33626. 0x10, 0xad, 0xde, 0x97, 0x6a, 0x5d, 0x60, 0x2b,
  33627. 0x1c, 0x3f, 0x85, 0xb9, 0xb9, 0xa0, 0x01, 0xed,
  33628. 0x3c, 0x6a, 0x4d, 0x3b, 0x14, 0x37, 0xf5, 0x20,
  33629. 0x96, 0xcd, 0x19, 0x56, 0xd0, 0x42, 0xa5, 0x97,
  33630. 0xd5, 0x61, 0xa5, 0x96, 0xec, 0xd3, 0xd1, 0x73,
  33631. 0x5a, 0x8d, 0x57, 0x0e, 0xa0, 0xec, 0x27, 0x22,
  33632. 0x5a, 0x2c, 0x4a, 0xaf, 0xf2, 0x63, 0x06, 0xd1,
  33633. 0x52, 0x6c, 0x1a, 0xf3, 0xca, 0x6d, 0x9c, 0xf5,
  33634. 0xa2, 0xc9, 0x8f, 0x47, 0xe1, 0xc4, 0x6d, 0xb9,
  33635. 0xa3, 0x32, 0x34, 0xcf, 0xd4, 0xd8, 0x1f, 0x2c,
  33636. 0x98, 0x53, 0x8a, 0x09, 0xeb, 0xe7, 0x69, 0x98,
  33637. 0xd0, 0xd8, 0xfd, 0x25, 0x99, 0x7c, 0x7d, 0x25,
  33638. 0x5c, 0x6d, 0x66, 0xec, 0xe6, 0xfa, 0x56, 0xf1,
  33639. 0x11, 0x44, 0x95, 0x0f, 0x02, 0x77, 0x95, 0xe6,
  33640. 0x53, 0x00, 0x8f, 0x4b, 0xd7, 0xca, 0x2d, 0xee,
  33641. 0x85, 0xd8, 0xe9, 0x0f, 0x3d, 0xc3, 0x15, 0x13,
  33642. 0x0c, 0xe2, 0xa0, 0x03, 0x75, 0xa3, 0x18, 0xc7,
  33643. 0xc3, 0xd9, 0x7b, 0xe2, 0xc8, 0xce, 0x5b, 0x6d,
  33644. 0xb4, 0x1a, 0x62, 0x54, 0xff, 0x26, 0x4f, 0xa6,
  33645. 0x15, 0x5b, 0xae, 0xe3, 0xb0, 0x77, 0x3c, 0x0f,
  33646. 0x49, 0x7c, 0x57, 0x3f, 0x19, 0xbb, 0x4f, 0x42,
  33647. 0x40, 0x28, 0x1f, 0x0b, 0x1f, 0x4f, 0x7b, 0xe8,
  33648. 0x57, 0xa4, 0xe5, 0x9d, 0x41, 0x6c, 0x06, 0xb4,
  33649. 0xc5, 0x0f, 0xa0, 0x9e, 0x18, 0x10, 0xdd, 0xc6,
  33650. 0xb1, 0x46, 0x7b, 0xae, 0xac, 0x5a, 0x36, 0x68,
  33651. 0xd1, 0x1b, 0x6e, 0xca, 0xa9, 0x01, 0x44, 0x00,
  33652. 0x16, 0xf3, 0x89, 0xf8, 0x0a, 0xcc, 0x4d, 0xb9,
  33653. 0x77, 0x02, 0x5e, 0x7f, 0x59, 0x24, 0x38, 0x8c,
  33654. 0x7e, 0x34, 0x0a, 0x73, 0x2e, 0x55, 0x44, 0x40,
  33655. 0xe7, 0x65, 0x70, 0xf8, 0xdd, 0x71, 0xb7, 0xd6,
  33656. 0x40, 0xb3, 0x45, 0x0d, 0x1f, 0xd5, 0xf0, 0x41,
  33657. 0x0a, 0x18, 0xf9, 0xa3, 0x49, 0x4f, 0x70, 0x7c,
  33658. 0x71, 0x7b, 0x79, 0xb4, 0xbf, 0x75, 0xc9, 0x84,
  33659. 0x00, 0xb0, 0x96, 0xb2, 0x16, 0x53, 0xb5, 0xd2,
  33660. 0x17, 0xcf, 0x35, 0x65, 0xc9, 0x59, 0x74, 0x56,
  33661. 0xf7, 0x07, 0x03, 0x49, 0x7a, 0x07, 0x87, 0x63,
  33662. 0x82, 0x9b, 0xc0, 0x1b, 0xb1, 0xcb, 0xc8, 0xfa,
  33663. 0x04, 0xea, 0xdc, 0x9a, 0x6e, 0x3f, 0x66, 0x99,
  33664. 0x58, 0x7a, 0x9e, 0x75, 0xc9, 0x4e, 0x5b, 0xab,
  33665. 0x00, 0x36, 0xe0, 0xb2, 0xe7, 0x11, 0x39, 0x2c,
  33666. 0xff, 0x00, 0x47, 0xd0, 0xd6, 0xb0, 0x5b, 0xd2,
  33667. 0xa5, 0x88, 0xbc, 0x10, 0x97, 0x18, 0x95, 0x42,
  33668. 0x59, 0xf1, 0xd8, 0x66, 0x78, 0xa5, 0x79, 0xa3,
  33669. 0x12, 0x0f, 0x19, 0xcf, 0xb2, 0x96, 0x3f, 0x17,
  33670. 0x7a, 0xeb, 0x70, 0xf2, 0xd4, 0x84, 0x48, 0x26,
  33671. 0x26, 0x2e, 0x51, 0xb8, 0x02, 0x71, 0x27, 0x20,
  33672. 0x68, 0xef, 0x5b, 0x38, 0x56, 0xfa, 0x85, 0x35,
  33673. 0xaa, 0x2a, 0x88, 0xb2, 0xd4, 0x1f, 0x2a, 0x0e,
  33674. 0x2f, 0xda, 0x76, 0x24, 0xc2, 0x85, 0x02, 0x72,
  33675. 0xac, 0x4a, 0x2f, 0x56, 0x1f, 0x8f, 0x2f, 0x7a,
  33676. 0x31, 0x8b, 0xfd, 0x5c, 0xaf, 0x96, 0x96, 0x14,
  33677. 0x9e, 0x4a, 0xc8, 0x24, 0xad, 0x34, 0x60, 0x53,
  33678. 0x8f, 0xdc, 0x25, 0x42, 0x1b, 0xee, 0xc2, 0xcc,
  33679. 0x68, 0x18, 0x16, 0x2d, 0x06, 0xbb, 0xed, 0x0c,
  33680. 0x40, 0xa3, 0x87, 0x19, 0x23, 0x49, 0xdb, 0x67,
  33681. 0xa1, 0x18, 0xba, 0xda, 0x6c, 0xd5, 0xab, 0x01,
  33682. 0x40, 0xee, 0x27, 0x32, 0x04, 0xf6, 0x28, 0xaa,
  33683. 0xd1, 0xc1, 0x35, 0xf7, 0x70, 0x27, 0x9a, 0x65,
  33684. 0x1e, 0x24, 0xd8, 0xc1, 0x4d, 0x75, 0xa6, 0x05,
  33685. 0x9d, 0x76, 0xb9, 0x6a, 0x6f, 0xd8, 0x57, 0xde,
  33686. 0xf5, 0xe0, 0xb3, 0x54, 0xb2, 0x7a, 0xb9, 0x37,
  33687. 0xa5, 0x81, 0x5d, 0x16, 0xb5, 0xfa, 0xe4, 0x07,
  33688. 0xff, 0x18, 0x22, 0x2c, 0x6d, 0x1e, 0xd2, 0x63,
  33689. 0xbe, 0x68, 0xc9, 0x5f, 0x32, 0xd9, 0x08, 0xbd,
  33690. 0x89, 0x5c, 0xd7, 0x62, 0x07, 0xae, 0x72, 0x64,
  33691. 0x87, 0x56, 0x7f, 0x9a, 0x67, 0xda, 0xd7, 0x9a,
  33692. 0xbe, 0xc3, 0x16, 0xf6, 0x83, 0xb1, 0x7f, 0x2d,
  33693. 0x02, 0xbf, 0x07, 0xe0, 0xac, 0x8b, 0x5b, 0xc6,
  33694. 0x16, 0x2c, 0xf9, 0x46, 0x97, 0xb3, 0xc2, 0x7c,
  33695. 0xd1, 0xfe, 0xa4, 0x9b, 0x27, 0xf2, 0x3b, 0xa2,
  33696. 0x90, 0x18, 0x71, 0x96, 0x25, 0x06, 0x52, 0x0c,
  33697. 0x39, 0x2d, 0xa8, 0xb6, 0xad, 0x0d, 0x99, 0xf7,
  33698. 0x01, 0x3f, 0xbc, 0x06, 0xc2, 0xc1, 0x7a, 0x56,
  33699. 0x95, 0x00, 0xc8, 0xa7, 0x69, 0x64, 0x81, 0xc1,
  33700. 0xcd, 0x33, 0xe9, 0xb1, 0x4e, 0x40, 0xb8, 0x2e,
  33701. 0x79, 0xa5, 0xf5, 0xdb, 0x82, 0x57, 0x1b, 0xa9,
  33702. 0x7b, 0xae, 0x3a, 0xd3, 0xe0, 0x47, 0x95, 0x15,
  33703. 0xbb, 0x0e, 0x2b, 0x0f, 0x3b, 0xfc, 0xd1, 0xfd,
  33704. 0x33, 0x03, 0x4e, 0xfc, 0x62, 0x45, 0xed, 0xdd,
  33705. 0x7e, 0xe2, 0x08, 0x6d, 0xda, 0xe2, 0x60, 0x0d,
  33706. 0x8c, 0xa7, 0x3e, 0x21, 0x4e, 0x8c, 0x2b, 0x0b,
  33707. 0xdb, 0x2b, 0x04, 0x7c, 0x6a, 0x46, 0x4a, 0x56,
  33708. 0x2e, 0xd7, 0x7b, 0x73, 0xd2, 0xd8, 0x41, 0xc4,
  33709. 0xb3, 0x49, 0x73, 0x55, 0x12, 0x57, 0x71, 0x3b,
  33710. 0x75, 0x36, 0x32, 0xef, 0xba, 0x34, 0x81, 0x69,
  33711. 0xab, 0xc9, 0x0a, 0x68, 0xf4, 0x26, 0x11, 0xa4,
  33712. 0x01, 0x26, 0xd7, 0xcb, 0x21, 0xb5, 0x86, 0x95,
  33713. 0x56, 0x81, 0x86, 0xf7, 0xe5, 0x69, 0xd2, 0xff,
  33714. 0x0f, 0x9e, 0x74, 0x5d, 0x04, 0x87, 0xdd, 0x2e,
  33715. 0xb9, 0x97, 0xca, 0xfc, 0x5a, 0xbf, 0x9d, 0xd1,
  33716. 0x02, 0xe6, 0x2f, 0xf6, 0x6c, 0xba, 0x87
  33717. };
  33718. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  33719. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  33720. sizeof(msg2),
  33721. sizeof(msg3),
  33722. 0 /*sizeof(msg1)*/,
  33723. 0 /*sizeof(msg1)*/,
  33724. sizeof(msg4)
  33725. };
  33726. #ifndef NO_ASN
  33727. static const byte privateEd448[] = {
  33728. 0x30, 0x47, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
  33729. 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04, 0x39,
  33730. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33731. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33732. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33733. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33734. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33735. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33736. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33737. 0x5b
  33738. };
  33739. static const byte publicEd448[] = {
  33740. 0x30, 0x43, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
  33741. 0x71, 0x03, 0x3a, 0x00, 0x5f, 0xd7, 0x44, 0x9b,
  33742. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33743. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33744. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33745. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33746. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33747. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33748. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33749. };
  33750. static const byte privPubEd448[] = {
  33751. 0x30, 0x81, 0x82, 0x02, 0x01, 0x00, 0x30, 0x05,
  33752. 0x06, 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04,
  33753. 0x39, 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d,
  33754. 0x10, 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e,
  33755. 0xbf, 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c,
  33756. 0x9f, 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48,
  33757. 0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04,
  33758. 0x4e, 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f,
  33759. 0x8f, 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98,
  33760. 0xf9, 0x5b, 0x81, 0x39, 0x5f, 0xd7, 0x44, 0x9b,
  33761. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33762. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33763. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33764. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33765. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33766. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33767. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33768. };
  33769. word32 idx;
  33770. #endif /* NO_ASN */
  33771. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33772. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33773. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33774. ed448_key *key3 = NULL;
  33775. #else
  33776. ed448_key key3[1];
  33777. #endif
  33778. #endif
  33779. WOLFSSL_ENTER("ed448_test");
  33780. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33781. key = (ed448_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33782. key2 = (ed448_key *)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33783. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33784. key3 = (ed448_key *)XMALLOC(sizeof(*key3), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33785. #endif
  33786. #endif
  33787. /* create ed448 keys */
  33788. #ifndef HAVE_FIPS
  33789. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  33790. #else
  33791. ret = wc_InitRng(&rng);
  33792. #endif
  33793. if (ret != 0) {
  33794. XMEMSET(&rng, 0, sizeof(rng));
  33795. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33796. }
  33797. ret = wc_ed448_init(key);
  33798. if (ret < 0)
  33799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33800. ret = wc_ed448_init(key2);
  33801. if (ret < 0)
  33802. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33803. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33804. ret = wc_ed448_init(key3);
  33805. if (ret < 0)
  33806. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33807. #endif
  33808. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key);
  33809. if (ret < 0)
  33810. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33811. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2);
  33812. if (ret < 0)
  33813. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33814. /* helper functions for signature and key size */
  33815. keySz = (word32)wc_ed448_size(key);
  33816. sigSz = (word32)wc_ed448_sig_size(key);
  33817. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33818. defined(HAVE_ED448_KEY_IMPORT)
  33819. for (i = 0; i < 6; i++) {
  33820. outlen = sizeof(out);
  33821. XMEMSET(out, 0, sizeof(out));
  33822. if (wc_ed448_import_private_key(sKeys[i], ED448_KEY_SIZE, pKeys[i],
  33823. pKeySz[i], key) != 0)
  33824. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33825. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key, NULL,
  33826. 0) != 0)
  33827. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33828. if (XMEMCMP(out, sigs[i], 114))
  33829. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33830. #if defined(HAVE_ED448_VERIFY)
  33831. /* test verify on good msg */
  33832. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33833. NULL, 0) != 0 || verify != 1)
  33834. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33835. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33836. /* test verify on good msg using streaming interface directly */
  33837. if (wc_ed448_verify_msg_init(out, outlen,
  33838. key, (byte)Ed448, NULL, 0) != 0)
  33839. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33840. for (j = 0; j < msgSz[i]; j += i) {
  33841. if (wc_ed448_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  33842. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33843. }
  33844. if (wc_ed448_verify_msg_final(out, outlen, &verify,
  33845. key) != 0 || verify != 1)
  33846. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33847. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33848. /* test verify on bad msg */
  33849. out[outlen-2] = out[outlen-2] + 1;
  33850. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33851. NULL, 0) == 0 || verify == 1)
  33852. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33853. #endif /* HAVE_ED448_VERIFY */
  33854. /* test api for import/exporting keys */
  33855. {
  33856. word32 exportPSz = ED448_KEY_SIZE;
  33857. word32 exportSSz = ED448_KEY_SIZE;
  33858. #ifdef WOLFSSL_NO_MALLOC
  33859. byte exportPKey[exportPSz];
  33860. byte exportSKey[exportSSz];
  33861. #else
  33862. byte *exportPKey = NULL;
  33863. byte *exportSKey = NULL;
  33864. exportPKey = (byte *)XMALLOC(exportPSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33865. exportSKey = (byte *)XMALLOC(exportSSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33866. if ((exportPKey == NULL) || (exportSKey == NULL))
  33867. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33868. #endif
  33869. ret = 0;
  33870. do {
  33871. if (wc_ed448_export_public(key, exportPKey, &exportPSz) != 0) {
  33872. ret = WC_TEST_RET_ENC_I(i);
  33873. break;
  33874. }
  33875. if (wc_ed448_import_public_ex(exportPKey, exportPSz, key2, 1) != 0) {
  33876. ret = WC_TEST_RET_ENC_I(i);
  33877. break;
  33878. }
  33879. if (wc_ed448_export_private_only(key, exportSKey, &exportSSz) != 0) {
  33880. ret = WC_TEST_RET_ENC_I(i);
  33881. break;
  33882. }
  33883. if (wc_ed448_import_private_key(exportSKey, exportSSz,
  33884. exportPKey, exportPSz, key2) != 0) {
  33885. ret = WC_TEST_RET_ENC_I(i);
  33886. break;
  33887. }
  33888. /* clear "out" buffer and test sign with imported keys */
  33889. outlen = sizeof(out);
  33890. XMEMSET(out, 0, sizeof(out));
  33891. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key2, NULL,
  33892. 0) != 0) {
  33893. ret = WC_TEST_RET_ENC_I(i);
  33894. break;
  33895. }
  33896. } while(0);
  33897. #ifndef WOLFSSL_NO_MALLOC
  33898. XFREE(exportPKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33899. XFREE(exportSKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33900. #endif
  33901. if (ret != 0)
  33902. goto out;
  33903. }
  33904. #if defined(HAVE_ED448_VERIFY)
  33905. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key2,
  33906. NULL, 0) != 0 || verify != 1)
  33907. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33908. if (XMEMCMP(out, sigs[i], SIGSZ))
  33909. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33910. #endif /* HAVE_ED448_VERIFY */
  33911. }
  33912. ret = ed448_ctx_test();
  33913. if (ret != 0)
  33914. goto out;
  33915. ret = ed448ph_test();
  33916. if (ret != 0)
  33917. goto out;
  33918. #ifndef NO_ASN
  33919. /* Try ASN.1 encoded private-only key and public key. */
  33920. idx = 0;
  33921. ret = wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3,
  33922. sizeof(privateEd448));
  33923. if (ret != 0)
  33924. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33925. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33926. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  33927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33928. idx = 0;
  33929. ret = wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, sizeof(publicEd448));
  33930. if (ret != 0)
  33931. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33932. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33933. if (ret != 0)
  33934. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33935. if (XMEMCMP(out, sigs[0], SIGSZ))
  33936. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33937. #if defined(HAVE_ED448_VERIFY)
  33938. /* test verify on good msg */
  33939. ret = wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3,
  33940. NULL, 0);
  33941. if (ret != 0 || verify != 1)
  33942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33943. #endif /* HAVE_ED448_VERIFY */
  33944. wc_ed448_free(key3);
  33945. ret = wc_ed448_init(key3);
  33946. if (ret < 0)
  33947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33948. idx = 0;
  33949. ret = wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3,
  33950. sizeof(privPubEd448));
  33951. if (ret != 0)
  33952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33953. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33954. if (ret != 0)
  33955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33956. if (XMEMCMP(out, sigs[0], SIGSZ))
  33957. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33958. #endif /* NO_ASN */
  33959. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33960. ret = 0;
  33961. out:
  33962. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33963. if (key) {
  33964. wc_ed448_free(key);
  33965. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33966. }
  33967. if (key2) {
  33968. wc_ed448_free(key2);
  33969. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33970. }
  33971. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33972. if (key3) {
  33973. wc_ed448_free(key3);
  33974. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33975. }
  33976. #endif
  33977. #else
  33978. wc_ed448_free(key);
  33979. wc_ed448_free(key2);
  33980. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33981. wc_ed448_free(key3);
  33982. #endif
  33983. #endif
  33984. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  33985. wc_FreeRng(&rng);
  33986. #endif
  33987. if (ret < 0)
  33988. return ret;
  33989. /* hush warnings of unused keySz and sigSz */
  33990. (void)keySz;
  33991. (void)sigSz;
  33992. ret = ed448_test_check_key();
  33993. if (ret < 0)
  33994. return ret;
  33995. #ifdef WOLFSSL_TEST_CERT
  33996. ret = ed448_test_cert();
  33997. if (ret < 0)
  33998. return ret;
  33999. #ifdef WOLFSSL_CERT_GEN
  34000. ret = ed448_test_make_cert();
  34001. if (ret < 0)
  34002. return ret;
  34003. #endif /* WOLFSSL_CERT_GEN */
  34004. #endif /* WOLFSSL_TEST_CERT */
  34005. return 0;
  34006. }
  34007. #endif /* HAVE_ED448 */
  34008. #ifdef WOLFSSL_HAVE_KYBER
  34009. #ifdef WOLFSSL_WC_KYBER /* OQS does not support KATs */
  34010. #if !defined(WOLFSSL_NO_KYBER512) && !defined(WOLFSSL_NO_ML_KEM_512)
  34011. static wc_test_ret_t kyber512_kat(void)
  34012. {
  34013. wc_test_ret_t ret;
  34014. #ifdef WOLFSSL_SMALL_STACK
  34015. KyberKey *key = NULL;
  34016. byte *priv = NULL;
  34017. byte *pub = NULL;
  34018. byte *ct = NULL;
  34019. byte *ss = NULL;
  34020. byte *ss_dec = NULL;
  34021. #else
  34022. KyberKey key[1];
  34023. byte priv[KYBER512_PRIVATE_KEY_SIZE];
  34024. byte pub[KYBER512_PUBLIC_KEY_SIZE];
  34025. byte ct[KYBER512_CIPHER_TEXT_SIZE];
  34026. byte ss[KYBER_SS_SZ];
  34027. byte ss_dec[KYBER_SS_SZ];
  34028. #endif
  34029. int key_inited = 0;
  34030. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_rand[] = {
  34031. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  34032. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  34033. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  34034. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  34035. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34036. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34037. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34038. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34039. };
  34040. WOLFSSL_SMALL_STACK_STATIC const byte kyber512enc_rand[] = {
  34041. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  34042. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  34043. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  34044. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  34045. };
  34046. #ifdef WOLFSSL_KYBER_ORIGINAL
  34047. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_pk[] = {
  34048. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34049. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34050. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34051. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34052. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34053. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34054. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34055. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34056. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34057. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34058. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34059. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34060. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34061. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34062. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34063. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34064. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34065. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34066. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34067. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34068. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34069. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34070. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34071. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34072. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34073. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34074. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34075. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34076. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34077. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34078. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34079. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34080. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34081. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34082. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34083. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34084. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34085. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34086. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34087. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34088. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34089. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34090. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34091. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34092. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34093. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34094. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34095. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34096. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34097. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34098. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34099. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34100. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34101. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34102. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34103. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34104. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34105. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34106. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34107. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34108. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34109. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34110. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34111. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34112. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34113. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34114. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34115. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34116. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34117. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34118. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34119. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34120. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34121. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34122. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34123. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34124. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34125. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34126. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34127. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34128. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34129. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34130. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34131. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34132. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34133. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34134. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34135. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34136. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34137. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34138. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34139. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34140. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34141. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34142. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34143. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34144. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34145. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34146. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34147. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  34148. };
  34149. #endif
  34150. #ifndef WOLFSSL_NO_ML_KEM
  34151. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_pk[] = {
  34152. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34153. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34154. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34155. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34156. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34157. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34158. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34159. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34160. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34161. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34162. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34163. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34164. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34165. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34166. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34167. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34168. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34169. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34170. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34171. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34172. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34173. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34174. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34175. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34176. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34177. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34178. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34179. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34180. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34181. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34182. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34183. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34184. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34185. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34186. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34187. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34188. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34189. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34190. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34191. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34192. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34193. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34194. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34195. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34196. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34197. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34198. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34199. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34200. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34201. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34202. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34203. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34204. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34205. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34206. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34207. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34208. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34209. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34210. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34211. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34212. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34213. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34214. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34215. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34216. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34217. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34218. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34219. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34220. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34221. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34222. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34223. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34224. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34225. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34226. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34227. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34228. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34229. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34230. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34231. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34232. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34233. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34234. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34235. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34236. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34237. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34238. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34239. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34240. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34241. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34242. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34243. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34244. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34245. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34246. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34247. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34248. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34249. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34250. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34251. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39
  34252. };
  34253. #endif
  34254. #ifdef WOLFSSL_KYBER_ORIGINAL
  34255. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_sk[] = {
  34256. 0x6C, 0x89, 0x2B, 0x02, 0x97, 0xA9, 0xC7, 0x64,
  34257. 0x14, 0x93, 0xF8, 0x7D, 0xAF, 0x35, 0x33, 0xEE,
  34258. 0xD6, 0x1F, 0x07, 0xF4, 0x65, 0x20, 0x66, 0x33,
  34259. 0x7E, 0xD7, 0x40, 0x46, 0xDC, 0xC7, 0x1B, 0xA0,
  34260. 0x3F, 0x30, 0x96, 0x01, 0x03, 0x16, 0x1F, 0x7D,
  34261. 0xEB, 0x53, 0xA7, 0x1B, 0x11, 0x61, 0x72, 0x63,
  34262. 0xFE, 0x2A, 0x80, 0x97, 0x69, 0xCE, 0x6D, 0x70,
  34263. 0xA8, 0x5F, 0xE6, 0x00, 0xEC, 0xE2, 0x9D, 0x7F,
  34264. 0x36, 0xA1, 0x6D, 0x33, 0x1B, 0x8B, 0x2A, 0x9E,
  34265. 0x1D, 0xB8, 0xC0, 0x90, 0x74, 0x2D, 0xF0, 0x73,
  34266. 0x9F, 0xF0, 0x60, 0xCE, 0xB4, 0xEC, 0xC5, 0xAB,
  34267. 0x1C, 0x5E, 0x55, 0xAC, 0x97, 0xBB, 0x66, 0xA7,
  34268. 0xF8, 0x95, 0x10, 0x5D, 0x57, 0x78, 0x2B, 0x22,
  34269. 0x95, 0x38, 0xE3, 0x42, 0x15, 0x44, 0xA3, 0x42,
  34270. 0x14, 0x08, 0xDB, 0xF4, 0x49, 0x10, 0x93, 0x4C,
  34271. 0xC4, 0x23, 0x77, 0x4F, 0x16, 0x76, 0xFF, 0x1C,
  34272. 0x30, 0x6F, 0x97, 0x55, 0x5F, 0x57, 0xB4, 0xAE,
  34273. 0xD7, 0xA6, 0xBA, 0xB9, 0x50, 0xA8, 0x16, 0x3C,
  34274. 0x8D, 0x31, 0x8D, 0xEA, 0x62, 0x75, 0x1B, 0xD6,
  34275. 0xAB, 0xC5, 0x06, 0x9C, 0x06, 0xC8, 0x8F, 0x33,
  34276. 0x00, 0x26, 0xA1, 0x98, 0x06, 0xA0, 0x3B, 0x97,
  34277. 0xA7, 0x69, 0x6B, 0x56, 0xDA, 0x21, 0x82, 0x7B,
  34278. 0xB4, 0xE8, 0xDC, 0x03, 0x11, 0x52, 0xB4, 0x1B,
  34279. 0x89, 0x2A, 0x9E, 0x99, 0xAD, 0xF6, 0xE1, 0x96,
  34280. 0x3E, 0x96, 0x57, 0x88, 0x28, 0x15, 0x4F, 0x46,
  34281. 0x70, 0x33, 0x84, 0x69, 0x20, 0xFB, 0xB4, 0xB8,
  34282. 0x05, 0x44, 0xE7, 0xE8, 0xA8, 0x1A, 0xE9, 0x63,
  34283. 0xCF, 0x36, 0x8C, 0x9B, 0xA0, 0x37, 0xA8, 0xC2,
  34284. 0xAD, 0x62, 0xE3, 0x2B, 0x6E, 0x61, 0xC9, 0x1D,
  34285. 0x75, 0xCE, 0x00, 0x5A, 0xB3, 0x0F, 0x80, 0x99,
  34286. 0xA1, 0xF2, 0x9D, 0x7B, 0x63, 0x05, 0xB4, 0xDC,
  34287. 0x06, 0xE2, 0x56, 0x80, 0xBB, 0x00, 0x99, 0x2F,
  34288. 0x71, 0x7F, 0xE6, 0xC1, 0x15, 0xA8, 0x08, 0x42,
  34289. 0x31, 0xCC, 0x79, 0xDD, 0x70, 0x0E, 0xA6, 0x91,
  34290. 0x2A, 0xC7, 0xFA, 0x0D, 0x93, 0x7B, 0xB6, 0xA7,
  34291. 0x56, 0x66, 0x22, 0x30, 0x47, 0x0C, 0x18, 0x9B,
  34292. 0x5A, 0xA1, 0x65, 0x3D, 0xEB, 0x93, 0x7D, 0x5A,
  34293. 0x9C, 0x25, 0xA2, 0x1D, 0x93, 0xB1, 0x90, 0x74,
  34294. 0xFC, 0x23, 0x9D, 0x81, 0x53, 0x53, 0x97, 0x97,
  34295. 0xC7, 0xD4, 0xAB, 0x62, 0x64, 0x9D, 0x76, 0xAA,
  34296. 0x55, 0x37, 0x36, 0xA9, 0x49, 0x02, 0x2C, 0x22,
  34297. 0xC5, 0x2B, 0xAE, 0xEC, 0x60, 0x5B, 0x32, 0xCE,
  34298. 0x9E, 0x5B, 0x93, 0x84, 0x90, 0x35, 0x58, 0xCA,
  34299. 0x9D, 0x6A, 0x3A, 0xBA, 0x90, 0x42, 0x3E, 0xED,
  34300. 0xA0, 0x1C, 0x94, 0x19, 0x8B, 0x19, 0x2A, 0x8B,
  34301. 0xA9, 0x06, 0x34, 0x97, 0xA0, 0xC5, 0x01, 0x33,
  34302. 0x07, 0xDD, 0xD8, 0x63, 0x52, 0x64, 0x71, 0xA4,
  34303. 0xD9, 0x95, 0x23, 0xEB, 0x41, 0x7F, 0x29, 0x1A,
  34304. 0xAC, 0x0C, 0x3A, 0x58, 0x1B, 0x6D, 0xA0, 0x07,
  34305. 0x32, 0xE5, 0xE8, 0x1B, 0x1F, 0x7C, 0x87, 0x9B,
  34306. 0x16, 0x93, 0xC1, 0x3B, 0x6F, 0x9F, 0x79, 0x31,
  34307. 0x62, 0x24, 0x29, 0xE5, 0x42, 0xAF, 0x40, 0x69,
  34308. 0x22, 0x2F, 0x04, 0x55, 0x44, 0xE0, 0xCC, 0x4F,
  34309. 0xB2, 0x4D, 0x44, 0x48, 0xCF, 0x2C, 0x65, 0x96,
  34310. 0xF5, 0xCB, 0x08, 0x62, 0x4B, 0x11, 0x85, 0x01,
  34311. 0x3B, 0x6B, 0x02, 0x08, 0x92, 0xF9, 0x6B, 0xDF,
  34312. 0xD4, 0xAD, 0xA9, 0x17, 0x9D, 0xE7, 0x27, 0xB8,
  34313. 0xD9, 0x42, 0x6E, 0x09, 0x96, 0xB5, 0xD3, 0x49,
  34314. 0x48, 0xCE, 0x02, 0xD0, 0xC3, 0x69, 0xB3, 0x7C,
  34315. 0xBB, 0x54, 0xD3, 0x47, 0x9E, 0xD8, 0xB5, 0x82,
  34316. 0xE9, 0xE7, 0x28, 0x92, 0x9B, 0x4C, 0x71, 0xC9,
  34317. 0xBE, 0x11, 0xD4, 0x5B, 0x20, 0xC4, 0xBD, 0xC3,
  34318. 0xC7, 0x43, 0x13, 0x22, 0x3F, 0x58, 0x27, 0x4E,
  34319. 0x8B, 0xA5, 0x24, 0x44, 0x47, 0xC4, 0x95, 0x95,
  34320. 0x0B, 0x84, 0xCB, 0x0C, 0x3C, 0x27, 0x36, 0x40,
  34321. 0x10, 0x8A, 0x33, 0x97, 0x94, 0x45, 0x73, 0x27,
  34322. 0x93, 0x28, 0x99, 0x6C, 0xDC, 0x0C, 0x91, 0x3C,
  34323. 0x95, 0x8A, 0xD6, 0x20, 0xBA, 0x8B, 0x5E, 0x5E,
  34324. 0xCB, 0xBB, 0x7E, 0x13, 0xCB, 0x9C, 0x70, 0xBD,
  34325. 0x5A, 0xB3, 0x0E, 0xB7, 0x48, 0x8C, 0x97, 0x00,
  34326. 0x1C, 0x20, 0x49, 0x8F, 0x1D, 0x7C, 0xC0, 0x6D,
  34327. 0xA7, 0x6B, 0xF5, 0x20, 0xC6, 0x58, 0xCC, 0xAD,
  34328. 0xFA, 0x29, 0x56, 0x42, 0x45, 0x57, 0xAB, 0xEA,
  34329. 0x8A, 0xB8, 0x92, 0x39, 0xC1, 0x78, 0x33, 0xDC,
  34330. 0x3A, 0x49, 0xB3, 0x6A, 0x9A, 0xE9, 0xA4, 0x86,
  34331. 0x94, 0x05, 0x40, 0xEB, 0x44, 0x4F, 0x97, 0x15,
  34332. 0x23, 0x57, 0xE0, 0x20, 0x35, 0x93, 0x9D, 0x75,
  34333. 0xA3, 0xC0, 0x25, 0xF4, 0x1A, 0x40, 0x08, 0x23,
  34334. 0x82, 0xA0, 0x73, 0x3C, 0x39, 0xB0, 0x62, 0x2B,
  34335. 0x74, 0x0E, 0x40, 0x75, 0x92, 0xC6, 0x2E, 0xCA,
  34336. 0xEB, 0x14, 0x32, 0xC4, 0x45, 0xB3, 0x70, 0x3A,
  34337. 0x86, 0xF6, 0x98, 0x1A, 0x27, 0x81, 0x57, 0xEA,
  34338. 0x95, 0xA6, 0xE9, 0x2D, 0x55, 0xE4, 0xB9, 0x72,
  34339. 0xF9, 0x36, 0xC2, 0xF0, 0xA6, 0x58, 0x28, 0x0E,
  34340. 0xA2, 0xB0, 0x7A, 0x48, 0x99, 0x2D, 0xF8, 0x93,
  34341. 0x7E, 0x0A, 0x2A, 0xC1, 0xDC, 0xC9, 0x74, 0xFE,
  34342. 0x00, 0xAA, 0xE1, 0xF5, 0x61, 0xFA, 0x25, 0x8E,
  34343. 0x2D, 0x25, 0x9C, 0x3E, 0x86, 0x1D, 0xCE, 0x23,
  34344. 0x60, 0x39, 0x12, 0x76, 0x06, 0xFC, 0x1C, 0xE0,
  34345. 0x09, 0x00, 0x3A, 0x7B, 0xAC, 0x94, 0x21, 0x01,
  34346. 0xDC, 0xB8, 0x22, 0xB1, 0xF3, 0xC1, 0x2B, 0xF7,
  34347. 0x32, 0x38, 0xF5, 0x46, 0xE0, 0x1C, 0x36, 0xB5,
  34348. 0xA6, 0x93, 0x61, 0x92, 0x99, 0x5C, 0xC6, 0x9C,
  34349. 0x63, 0x23, 0x74, 0x09, 0xCB, 0x53, 0xC2, 0xE3,
  34350. 0x5D, 0x74, 0x89, 0x0D, 0x18, 0x88, 0x53, 0x76,
  34351. 0xFA, 0x55, 0x03, 0xB1, 0x07, 0xA2, 0xA3, 0x92,
  34352. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34353. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34354. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34355. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34356. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34357. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34358. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34359. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34360. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34361. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34362. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34363. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34364. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34365. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34366. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34367. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34368. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34369. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34370. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34371. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34372. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34373. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34374. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34375. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34376. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34377. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34378. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34379. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34380. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34381. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34382. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34383. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34384. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34385. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34386. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34387. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34388. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34389. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34390. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34391. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34392. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34393. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34394. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34395. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34396. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34397. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34398. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34399. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34400. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34401. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34402. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34403. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34404. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34405. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34406. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34407. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34408. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34409. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34410. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34411. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34412. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34413. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34414. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34415. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34416. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34417. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34418. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34419. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34420. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34421. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34422. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34423. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34424. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34425. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34426. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34427. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34428. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34429. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34430. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34431. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34432. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34433. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34434. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34435. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34436. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34437. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34438. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34439. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34440. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34441. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34442. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34443. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34444. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34445. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34446. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34447. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34448. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34449. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34450. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34451. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  34452. 0x7F, 0xFA, 0xD1, 0xBC, 0x8A, 0xF7, 0x3B, 0x7E,
  34453. 0x87, 0x49, 0x56, 0xB8, 0x1C, 0x2A, 0x2E, 0xF0,
  34454. 0xBF, 0xAB, 0xE8, 0xDC, 0x93, 0xD7, 0x7B, 0x2F,
  34455. 0xBC, 0x9E, 0x0C, 0x64, 0xEF, 0xA0, 0x1E, 0x84,
  34456. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34457. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34458. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34459. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34460. };
  34461. #endif
  34462. #ifndef WOLFSSL_NO_ML_KEM
  34463. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_sk[] = {
  34464. 0x9c, 0xda, 0x16, 0x86, 0xa3, 0x39, 0x6a, 0x7c,
  34465. 0x10, 0x9b, 0x41, 0x52, 0x89, 0xf5, 0x6a, 0x9e,
  34466. 0xc4, 0x4c, 0xd5, 0xb9, 0xb6, 0x74, 0xc3, 0x8a,
  34467. 0x3b, 0xba, 0xb3, 0x0a, 0x2c, 0x90, 0xf0, 0x04,
  34468. 0x37, 0xa2, 0x64, 0xb0, 0xbe, 0x9a, 0x1e, 0x8b,
  34469. 0xa8, 0x87, 0xd3, 0xc3, 0xb1, 0x00, 0x89, 0x80,
  34470. 0x54, 0x27, 0x2f, 0x94, 0x1c, 0x88, 0xa1, 0xf2,
  34471. 0x08, 0xf1, 0xc9, 0x14, 0xf9, 0x64, 0xc1, 0xaa,
  34472. 0xd6, 0x13, 0xa6, 0xa8, 0x4f, 0x88, 0xe4, 0x2d,
  34473. 0x35, 0x56, 0x83, 0x5f, 0xb1, 0x61, 0xfd, 0xc5,
  34474. 0xcd, 0x15, 0xa3, 0xbc, 0x7e, 0x74, 0xb6, 0xf2,
  34475. 0x61, 0x2f, 0xa8, 0x27, 0x1c, 0x7e, 0xa1, 0x12,
  34476. 0xb0, 0x5c, 0x2a, 0x36, 0xcc, 0x70, 0x7c, 0xe3,
  34477. 0x8d, 0x5d, 0x1a, 0xcc, 0x51, 0x15, 0x46, 0x2a,
  34478. 0x8c, 0x1a, 0xab, 0xf0, 0x72, 0x76, 0xc7, 0x23,
  34479. 0x18, 0x33, 0x7f, 0x74, 0xb5, 0xcb, 0xef, 0xea,
  34480. 0x7a, 0x80, 0x37, 0x90, 0xbc, 0x03, 0x93, 0xf3,
  34481. 0xa5, 0x4c, 0x72, 0x4a, 0x57, 0x65, 0xa4, 0x8f,
  34482. 0x29, 0x6b, 0x03, 0xf4, 0x84, 0x37, 0x60, 0x23,
  34483. 0x62, 0x69, 0x30, 0x22, 0x27, 0x04, 0xc0, 0x8f,
  34484. 0xd3, 0xbc, 0x72, 0x93, 0x15, 0xd1, 0xfc, 0x70,
  34485. 0xeb, 0x79, 0x75, 0xa9, 0x7b, 0x9d, 0xee, 0xd1,
  34486. 0x62, 0xf4, 0x86, 0xbb, 0xc6, 0x4a, 0x09, 0x71,
  34487. 0x11, 0x95, 0x2d, 0x89, 0xb5, 0x7d, 0x76, 0x5e,
  34488. 0x8a, 0x99, 0x1a, 0x2e, 0x56, 0x42, 0x06, 0xea,
  34489. 0x7b, 0xf5, 0xe4, 0x00, 0x7a, 0x66, 0x35, 0x88,
  34490. 0x31, 0xca, 0x0e, 0x34, 0xb2, 0xf6, 0xa8, 0x4d,
  34491. 0x10, 0xf7, 0x9c, 0x47, 0x7c, 0xb6, 0x6a, 0x8a,
  34492. 0x95, 0x25, 0x69, 0x36, 0x73, 0x88, 0x13, 0x0d,
  34493. 0x7b, 0x97, 0x4a, 0x63, 0xaa, 0x51, 0x99, 0x6c,
  34494. 0x97, 0x70, 0x9b, 0xb8, 0xea, 0xbc, 0x94, 0xe6,
  34495. 0xa5, 0x35, 0xd7, 0x92, 0xd2, 0x90, 0x54, 0x74,
  34496. 0x95, 0x2d, 0x6b, 0x8c, 0x22, 0x22, 0xb2, 0xae,
  34497. 0x56, 0xdc, 0x66, 0xfb, 0x04, 0x61, 0x19, 0x20,
  34498. 0x66, 0xcd, 0xdb, 0x43, 0xec, 0x05, 0x98, 0x4f,
  34499. 0xb4, 0x98, 0x26, 0x49, 0x77, 0x13, 0x97, 0xc6,
  34500. 0xa8, 0x37, 0x9f, 0x3b, 0x56, 0x43, 0x06, 0x98,
  34501. 0x48, 0x87, 0x59, 0x19, 0xe8, 0x9c, 0xc4, 0x39,
  34502. 0xa3, 0xbe, 0x2f, 0x08, 0x14, 0x90, 0xf3, 0x41,
  34503. 0xbd, 0x12, 0x40, 0xad, 0xd8, 0x0d, 0xdb, 0x8c,
  34504. 0x99, 0x63, 0xb4, 0x7a, 0x2a, 0x09, 0x92, 0x29,
  34505. 0x03, 0x38, 0xda, 0x9c, 0x3b, 0x72, 0x5c, 0x6d,
  34506. 0xa4, 0x47, 0x18, 0xc0, 0x10, 0x46, 0x81, 0x25,
  34507. 0x62, 0xaf, 0xb0, 0x84, 0x83, 0x7a, 0xcb, 0x3c,
  34508. 0x57, 0x5e, 0x4f, 0x93, 0x93, 0x6c, 0x35, 0x2a,
  34509. 0xc0, 0xe7, 0x0a, 0xa3, 0x84, 0x5e, 0xe4, 0x85,
  34510. 0x29, 0x6e, 0x6b, 0x02, 0xde, 0x0b, 0x47, 0xb5,
  34511. 0xc4, 0xc9, 0x6b, 0x0b, 0x7c, 0xf9, 0x4c, 0x4a,
  34512. 0xbe, 0x95, 0x48, 0x61, 0x53, 0x11, 0x8e, 0x43,
  34513. 0xc2, 0xb9, 0xc8, 0x4d, 0x9d, 0xa9, 0x1c, 0x6c,
  34514. 0x5a, 0xcd, 0x5a, 0x57, 0x00, 0x2d, 0x05, 0x84,
  34515. 0x97, 0x99, 0x27, 0x99, 0xe5, 0xba, 0x1c, 0xe6,
  34516. 0xc2, 0x5e, 0xb2, 0x98, 0x44, 0xd8, 0x58, 0xba,
  34517. 0x1c, 0x37, 0x85, 0x0c, 0x0c, 0x2f, 0x57, 0xc6,
  34518. 0x0d, 0xe3, 0x7f, 0x77, 0xc0, 0x82, 0xec, 0x14,
  34519. 0x49, 0x4e, 0xba, 0x28, 0x8a, 0x65, 0x91, 0x51,
  34520. 0x16, 0xc2, 0x0a, 0x32, 0x5d, 0xe3, 0x1a, 0xaa,
  34521. 0xdd, 0x68, 0x0d, 0xb1, 0x9c, 0x0c, 0xfc, 0xc3,
  34522. 0x46, 0x0f, 0x0a, 0xa0, 0x1a, 0x87, 0xa6, 0xa5,
  34523. 0x80, 0xc6, 0xca, 0x29, 0x1f, 0xae, 0xf0, 0xcc,
  34524. 0xc4, 0x9b, 0x76, 0xa8, 0xda, 0xc4, 0xf9, 0xd4,
  34525. 0x16, 0x40, 0x50, 0x9d, 0xbd, 0x0b, 0x40, 0x45,
  34526. 0xc1, 0x53, 0x0e, 0xd3, 0x47, 0x55, 0xd4, 0x74,
  34527. 0x62, 0x70, 0x0f, 0x2a, 0x8c, 0xaf, 0x96, 0x80,
  34528. 0xa6, 0xd7, 0xe3, 0x8a, 0x7e, 0x2a, 0x63, 0xe9,
  34529. 0x37, 0x65, 0x0a, 0x23, 0x30, 0x6d, 0x85, 0x5d,
  34530. 0xa2, 0xa2, 0xb7, 0xef, 0x50, 0x5c, 0xa5, 0x96,
  34531. 0xab, 0x04, 0x85, 0x01, 0x3e, 0xa9, 0x27, 0xc7,
  34532. 0x34, 0x23, 0x43, 0x61, 0x36, 0x43, 0xba, 0x40,
  34533. 0x07, 0xd6, 0xc8, 0x74, 0xb9, 0x80, 0xc7, 0x9c,
  34534. 0x3a, 0xa1, 0xc7, 0x4f, 0x85, 0x81, 0xc3, 0x48,
  34535. 0x49, 0xb3, 0x6e, 0xa7, 0x98, 0x15, 0xfb, 0xb4,
  34536. 0xcc, 0xf9, 0x61, 0x05, 0x83, 0x08, 0x1d, 0x7c,
  34537. 0x5b, 0x44, 0x09, 0xb8, 0xd0, 0x53, 0x1c, 0x04,
  34538. 0xbc, 0xaf, 0x7c, 0xc7, 0x51, 0x10, 0x3a, 0x5f,
  34539. 0xd1, 0xba, 0x44, 0x70, 0x83, 0x3e, 0x89, 0x77,
  34540. 0x5a, 0xde, 0xd9, 0x70, 0xb5, 0x47, 0x18, 0x59,
  34541. 0x25, 0x0f, 0xe7, 0x26, 0x71, 0x05, 0x83, 0x5f,
  34542. 0x39, 0x00, 0x30, 0xc5, 0xe7, 0xcd, 0x3f, 0x96,
  34543. 0x10, 0x19, 0xea, 0xae, 0xa2, 0x37, 0x77, 0xd3,
  34544. 0x47, 0xbb, 0x2a, 0xdc, 0xb6, 0x73, 0xc0, 0x20,
  34545. 0x34, 0xf3, 0x94, 0x34, 0x22, 0x71, 0xbc, 0xea,
  34546. 0x64, 0x14, 0xe5, 0x46, 0xc3, 0xb2, 0x0b, 0xd5,
  34547. 0x74, 0x81, 0xc7, 0xea, 0x14, 0xc7, 0x7c, 0x38,
  34548. 0x8c, 0xc8, 0x62, 0x51, 0xc1, 0x25, 0x58, 0xb1,
  34549. 0x00, 0xf8, 0xc5, 0xb3, 0xd0, 0x3c, 0xa2, 0xc7,
  34550. 0x07, 0x13, 0x90, 0x96, 0x59, 0xc8, 0xba, 0x26,
  34551. 0xd0, 0xd1, 0x76, 0x5e, 0x0b, 0xc8, 0x23, 0xd6,
  34552. 0x8c, 0xa5, 0x57, 0x0d, 0xe6, 0x00, 0xcd, 0x09,
  34553. 0x41, 0x72, 0x5d, 0x38, 0x6e, 0x14, 0xc1, 0x01,
  34554. 0x2d, 0xf5, 0x95, 0x1b, 0xeb, 0x8d, 0x82, 0x81,
  34555. 0xa4, 0xf6, 0x81, 0x5d, 0x37, 0x60, 0xb7, 0x64,
  34556. 0x29, 0x5a, 0xd0, 0x40, 0x6c, 0x2b, 0xf7, 0x92,
  34557. 0x8a, 0xd6, 0x50, 0x32, 0xb6, 0x5f, 0x14, 0xb7,
  34558. 0x7c, 0xcb, 0x89, 0x17, 0xc9, 0x3a, 0x29, 0xd6,
  34559. 0x28, 0x7d, 0x8a, 0x60, 0x62, 0x39, 0x9c, 0xb6,
  34560. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34561. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34562. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34563. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34564. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34565. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34566. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34567. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34568. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34569. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34570. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34571. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34572. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34573. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34574. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34575. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34576. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34577. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34578. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34579. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34580. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34581. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34582. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34583. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34584. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34585. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34586. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34587. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34588. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34589. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34590. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34591. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34592. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34593. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34594. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34595. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34596. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34597. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34598. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34599. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34600. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34601. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34602. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34603. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34604. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34605. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34606. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34607. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34608. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34609. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34610. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34611. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34612. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34613. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34614. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34615. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34616. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34617. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34618. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34619. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34620. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34621. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34622. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34623. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34624. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34625. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34626. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34627. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34628. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34629. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34630. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34631. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34632. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34633. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34634. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34635. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34636. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34637. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34638. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34639. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34640. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34641. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34642. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34643. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34644. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34645. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34646. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34647. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34648. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34649. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34650. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34651. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34652. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34653. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34654. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34655. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34656. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34657. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34658. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34659. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39,
  34660. 0x50, 0xc8, 0xdd, 0x15, 0x2a, 0x45, 0x31, 0xaa,
  34661. 0xb5, 0x60, 0xd2, 0xfc, 0x7c, 0xa9, 0xa4, 0x0a,
  34662. 0xd8, 0xaf, 0x25, 0xad, 0x1d, 0xd0, 0x8c, 0x6d,
  34663. 0x79, 0xaf, 0xe4, 0xdd, 0x4d, 0x1e, 0xee, 0x5a,
  34664. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  34665. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  34666. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  34667. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  34668. };
  34669. #endif
  34670. #ifdef WOLFSSL_KYBER_ORIGINAL
  34671. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ct[] = {
  34672. 0xED, 0xF2, 0x41, 0x45, 0xE4, 0x3B, 0x4F, 0x6D,
  34673. 0xC6, 0xBF, 0x83, 0x32, 0xF5, 0x4E, 0x02, 0xCA,
  34674. 0xB0, 0x2D, 0xBF, 0x3B, 0x56, 0x05, 0xDD, 0xC9,
  34675. 0x0A, 0x15, 0xC8, 0x86, 0xAD, 0x3E, 0xD4, 0x89,
  34676. 0x46, 0x26, 0x99, 0xE4, 0xAB, 0xED, 0x44, 0x35,
  34677. 0x0B, 0xC3, 0x75, 0x7E, 0x26, 0x96, 0xFB, 0xFB,
  34678. 0x25, 0x34, 0x41, 0x2E, 0x8D, 0xD2, 0x01, 0xF1,
  34679. 0xE4, 0x54, 0x0A, 0x39, 0x70, 0xB0, 0x55, 0xFE,
  34680. 0x3B, 0x0B, 0xEC, 0x3A, 0x71, 0xF9, 0xE1, 0x15,
  34681. 0xB3, 0xF9, 0xF3, 0x91, 0x02, 0x06, 0x5B, 0x1C,
  34682. 0xCA, 0x83, 0x14, 0xDC, 0xC7, 0x95, 0xE3, 0xC0,
  34683. 0xE8, 0xFA, 0x98, 0xEE, 0x83, 0xCA, 0x66, 0x28,
  34684. 0x45, 0x70, 0x28, 0xA4, 0xD0, 0x9E, 0x83, 0x9E,
  34685. 0x55, 0x48, 0x62, 0xCF, 0x0B, 0x7B, 0xF5, 0x6C,
  34686. 0x5C, 0x0A, 0x82, 0x9E, 0x86, 0x57, 0x94, 0x79,
  34687. 0x45, 0xFE, 0x9C, 0x22, 0x56, 0x4F, 0xBA, 0xEB,
  34688. 0xC1, 0xB3, 0xAF, 0x35, 0x0D, 0x79, 0x55, 0x50,
  34689. 0x8A, 0x26, 0xD8, 0xA8, 0xEB, 0x54, 0x7B, 0x8B,
  34690. 0x1A, 0x2C, 0xF0, 0x3C, 0xCA, 0x1A, 0xAB, 0xCE,
  34691. 0x6C, 0x34, 0x97, 0x78, 0x3B, 0x64, 0x65, 0xBA,
  34692. 0x0B, 0x6E, 0x7A, 0xCB, 0xA8, 0x21, 0x19, 0x51,
  34693. 0x24, 0xAE, 0xF0, 0x9E, 0x62, 0x83, 0x82, 0xA1,
  34694. 0xF9, 0x14, 0x04, 0x3B, 0xE7, 0x09, 0x6E, 0x95,
  34695. 0x2C, 0xBC, 0x4F, 0xB4, 0xAF, 0xED, 0x13, 0x60,
  34696. 0x90, 0x46, 0x11, 0x7C, 0x01, 0x1F, 0xD7, 0x41,
  34697. 0xEE, 0x28, 0x6C, 0x83, 0x77, 0x16, 0x90, 0xF0,
  34698. 0xAE, 0xB5, 0x0D, 0xA0, 0xD7, 0x12, 0x85, 0xA1,
  34699. 0x79, 0xB2, 0x15, 0xC6, 0x03, 0x6D, 0xEB, 0x78,
  34700. 0x0F, 0x4D, 0x16, 0x76, 0x9F, 0x72, 0xDE, 0x16,
  34701. 0xFD, 0xAD, 0xAC, 0x73, 0xBE, 0xFA, 0x5B, 0xEF,
  34702. 0x89, 0x43, 0x19, 0x7F, 0x44, 0xC5, 0x95, 0x89,
  34703. 0xDC, 0x9F, 0x49, 0x73, 0xDE, 0x14, 0x50, 0xBA,
  34704. 0x1D, 0x0C, 0x32, 0x90, 0xD6, 0xB1, 0xD6, 0x83,
  34705. 0xF2, 0x94, 0xE7, 0x59, 0xC9, 0x54, 0xAB, 0xE8,
  34706. 0xA7, 0xDA, 0x5B, 0x10, 0x54, 0xFD, 0x6D, 0x21,
  34707. 0x32, 0x9B, 0x8E, 0x73, 0xD3, 0x75, 0x6A, 0xFD,
  34708. 0xA0, 0xDC, 0xB1, 0xFC, 0x8B, 0x15, 0x82, 0xD1,
  34709. 0xF9, 0x0C, 0xF2, 0x75, 0xA1, 0x02, 0xAB, 0xC6,
  34710. 0xAC, 0x69, 0x9D, 0xF0, 0xC5, 0x87, 0x0E, 0x50,
  34711. 0xA1, 0xF9, 0x89, 0xE4, 0xE6, 0x24, 0x1B, 0x60,
  34712. 0xAA, 0xA2, 0xEC, 0xF9, 0xE8, 0xE3, 0x3E, 0x0F,
  34713. 0xFC, 0xF4, 0x0F, 0xE8, 0x31, 0xE8, 0xFD, 0xC2,
  34714. 0xE8, 0x3B, 0x52, 0xCA, 0x7A, 0xB6, 0xD9, 0x3F,
  34715. 0x14, 0x6D, 0x29, 0xDC, 0xA5, 0x3C, 0x7D, 0xA1,
  34716. 0xDB, 0x4A, 0xC4, 0xF2, 0xDB, 0x39, 0xEA, 0x12,
  34717. 0x0D, 0x90, 0xFA, 0x60, 0xF4, 0xD4, 0x37, 0xC6,
  34718. 0xD0, 0x0E, 0xF4, 0x83, 0xBC, 0x94, 0xA3, 0x17,
  34719. 0x5C, 0xDA, 0x16, 0x3F, 0xC1, 0xC2, 0x82, 0x8B,
  34720. 0xE4, 0xDB, 0xD6, 0x43, 0x05, 0x07, 0xB5, 0x84,
  34721. 0xBB, 0x51, 0x77, 0xE1, 0x71, 0xB8, 0xDD, 0xA9,
  34722. 0xA4, 0x29, 0x3C, 0x32, 0x00, 0x29, 0x5C, 0x80,
  34723. 0x3A, 0x86, 0x5D, 0x6D, 0x21, 0x66, 0xF6, 0x6B,
  34724. 0xA5, 0x40, 0x1F, 0xB7, 0xA0, 0xE8, 0x53, 0x16,
  34725. 0x86, 0x00, 0xA2, 0x94, 0x84, 0x37, 0xE0, 0x36,
  34726. 0xE3, 0xBF, 0x19, 0xE1, 0x2F, 0xD3, 0xF2, 0xA2,
  34727. 0xB8, 0xB3, 0x43, 0xF7, 0x84, 0x24, 0x8E, 0x8D,
  34728. 0x68, 0x5E, 0xB0, 0xAF, 0xDE, 0x63, 0x15, 0x33,
  34729. 0x87, 0x30, 0xE7, 0xA1, 0x00, 0x1C, 0x27, 0xD8,
  34730. 0xD2, 0xA7, 0x6F, 0xA6, 0x9D, 0x15, 0x7B, 0xA1,
  34731. 0xAC, 0x7A, 0xD5, 0x6D, 0xA5, 0xA8, 0xC7, 0x0F,
  34732. 0xE4, 0xB5, 0xB8, 0xD7, 0x86, 0xDC, 0x6F, 0xC0,
  34733. 0x56, 0x6B, 0xA8, 0xE1, 0xB8, 0x81, 0x63, 0x34,
  34734. 0xD3, 0x2A, 0x3F, 0xB1, 0xCE, 0x7D, 0x4D, 0x5E,
  34735. 0x4C, 0x33, 0x2A, 0xF7, 0xB0, 0x03, 0xD0, 0x91,
  34736. 0x74, 0x1A, 0x3D, 0x5C, 0x96, 0x52, 0x92, 0x25,
  34737. 0x5D, 0xFF, 0x8E, 0xD2, 0xBB, 0xF1, 0xF9, 0x11,
  34738. 0x6B, 0xE5, 0x0C, 0x17, 0xB8, 0xE5, 0x48, 0x74,
  34739. 0x8A, 0xD4, 0xB2, 0xE9, 0x57, 0xBB, 0xD1, 0x95,
  34740. 0x34, 0x82, 0xA2, 0xE1, 0x71, 0x8C, 0xEC, 0x66,
  34741. 0xCD, 0x2C, 0x81, 0xF5, 0x72, 0xD5, 0x52, 0xB7,
  34742. 0x18, 0x78, 0x85, 0xE6, 0xB8, 0x94, 0x3D, 0x64,
  34743. 0x31, 0x41, 0x3C, 0x59, 0xEB, 0xB7, 0xE0, 0x36,
  34744. 0x04, 0x84, 0x90, 0xBE, 0x52, 0x89, 0xE9, 0x5B,
  34745. 0x20, 0xA8, 0x9E, 0x8B, 0x15, 0x9F, 0x61, 0xA9,
  34746. 0xA9, 0x88, 0x6E, 0x14, 0x75, 0x68, 0xF4, 0xC9,
  34747. 0x02, 0x1F, 0x36, 0x2F, 0x02, 0x68, 0x8A, 0x1C,
  34748. 0x8C, 0x3B, 0xB0, 0xD2, 0x40, 0x86, 0x88, 0x0E,
  34749. 0x55, 0xB6, 0xED, 0xB4, 0x3F, 0x37, 0x45, 0xD2,
  34750. 0xC1, 0x66, 0xDC, 0x1C, 0xB7, 0x43, 0xC7, 0x6F,
  34751. 0xE6, 0xBE, 0x52, 0x3A, 0x89, 0x3C, 0xC7, 0x64,
  34752. 0xD1, 0x64, 0x35, 0xC3, 0x78, 0x51, 0x25, 0x2A,
  34753. 0x81, 0xE2, 0xFF, 0xBA, 0x0F, 0x18, 0x97, 0x1A,
  34754. 0x3D, 0xEE, 0x37, 0xD4, 0x87, 0x7C, 0xB9, 0x28,
  34755. 0xE3, 0x6E, 0x52, 0x35, 0x03, 0x7A, 0x6B, 0x20,
  34756. 0x57, 0x89, 0x7D, 0x51, 0x8A, 0x5F, 0x0E, 0x34,
  34757. 0x8E, 0x3A, 0xB6, 0xD5, 0xB5, 0x2D, 0xFC, 0x60,
  34758. 0x75, 0x7F, 0x3B, 0x41, 0xA4, 0xFE, 0xC7, 0x82,
  34759. 0x8F, 0x1D, 0xEE, 0xAF, 0x45, 0x87, 0xCC, 0xC8,
  34760. 0xEA, 0xDF, 0x64, 0x7F, 0x4D, 0x20, 0x3B, 0x2F,
  34761. 0xAA, 0x05, 0xA6, 0x49, 0xB5, 0x82, 0x34, 0x0C,
  34762. 0xB4, 0xCA, 0xCE, 0x57, 0xA3, 0x07, 0x11, 0xBE,
  34763. 0x75, 0x2F, 0xAC, 0xF0, 0x22, 0x7D, 0x0A, 0x80,
  34764. 0xC4, 0x12, 0x84, 0x42, 0xDD, 0xC5, 0x44, 0xBE,
  34765. 0x80, 0x5B, 0x9C, 0xFE, 0x8F, 0xE9, 0xB1, 0x23,
  34766. 0x7C, 0x80, 0xF9, 0x67, 0x87, 0xCD, 0x92, 0x81,
  34767. 0xCC, 0xF2, 0x70, 0xC1, 0xAF, 0xC0, 0x67, 0x0D
  34768. };
  34769. #endif
  34770. #ifndef WOLFSSL_NO_ML_KEM
  34771. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_ct[] = {
  34772. 0x11, 0x3d, 0xb2, 0xdd, 0x06, 0x87, 0x12, 0x35,
  34773. 0xe7, 0xbc, 0x36, 0xc9, 0xdc, 0xaa, 0x52, 0x8f,
  34774. 0xc2, 0x6c, 0xe5, 0xdb, 0x9e, 0xcc, 0x1d, 0xc3,
  34775. 0x2e, 0x95, 0x7d, 0x7f, 0xfb, 0x3c, 0x74, 0x29,
  34776. 0xd5, 0x0c, 0x3c, 0x35, 0x77, 0xa5, 0x15, 0xd3,
  34777. 0x18, 0x3a, 0x1b, 0x9d, 0x26, 0x7b, 0x93, 0x6b,
  34778. 0x7e, 0xb8, 0xf5, 0x43, 0xa3, 0xaf, 0xb7, 0x77,
  34779. 0x65, 0xca, 0x79, 0x38, 0xf7, 0x8a, 0xa6, 0x43,
  34780. 0x8c, 0xe8, 0x0a, 0x06, 0xa6, 0x96, 0x6d, 0x0d,
  34781. 0x06, 0xaf, 0x75, 0xba, 0x3e, 0x0d, 0x4f, 0x37,
  34782. 0xba, 0xc7, 0x33, 0x69, 0xf5, 0xa7, 0x29, 0xf7,
  34783. 0x3e, 0x85, 0x72, 0x9e, 0xdd, 0x97, 0xc8, 0xc2,
  34784. 0xa8, 0xcc, 0x26, 0x19, 0xe4, 0xcf, 0x7b, 0x60,
  34785. 0x91, 0x86, 0x9e, 0x90, 0x9f, 0xd4, 0x7d, 0x97,
  34786. 0x09, 0x14, 0x92, 0x04, 0xb0, 0x83, 0x7d, 0x8d,
  34787. 0x6f, 0x25, 0xd2, 0x67, 0x97, 0x2b, 0xe6, 0x3b,
  34788. 0xad, 0x34, 0xb5, 0x44, 0x52, 0x3c, 0x01, 0xc0,
  34789. 0x9d, 0xe3, 0xb1, 0xfa, 0x1d, 0x6b, 0x7b, 0x05,
  34790. 0x9e, 0xee, 0x9e, 0x65, 0x20, 0x62, 0xfe, 0x87,
  34791. 0x0f, 0x68, 0xc6, 0x80, 0x05, 0x33, 0x9e, 0xa1,
  34792. 0x81, 0xe1, 0xd0, 0x76, 0x7c, 0x15, 0x2a, 0xeb,
  34793. 0x38, 0xfa, 0xf0, 0xf9, 0x24, 0x5a, 0xe5, 0x9d,
  34794. 0x5c, 0xb0, 0xd2, 0xb7, 0xf2, 0x01, 0x22, 0x9e,
  34795. 0xd9, 0x70, 0x20, 0xd0, 0x62, 0x3a, 0x46, 0x10,
  34796. 0x0d, 0x09, 0x7b, 0x0c, 0xe1, 0x15, 0x4e, 0x02,
  34797. 0x8a, 0xe6, 0x19, 0x4d, 0xe0, 0x5d, 0xe9, 0x7d,
  34798. 0xd9, 0xae, 0x2e, 0x85, 0xff, 0xd2, 0x5d, 0x95,
  34799. 0xeb, 0x22, 0xef, 0xfe, 0x5b, 0xa1, 0x9c, 0xd8,
  34800. 0x07, 0xc5, 0x30, 0xeb, 0xaa, 0x9f, 0xe9, 0xf6,
  34801. 0x42, 0xcc, 0xac, 0xff, 0x47, 0xed, 0x15, 0xc2,
  34802. 0x2b, 0xfe, 0x30, 0x36, 0xeb, 0xf8, 0xad, 0x9c,
  34803. 0x8e, 0xd2, 0x32, 0x40, 0xae, 0xeb, 0xaa, 0x24,
  34804. 0xd1, 0x35, 0x75, 0x51, 0x00, 0xb8, 0x5e, 0xce,
  34805. 0xe3, 0x17, 0x49, 0x06, 0xe4, 0x63, 0x12, 0x06,
  34806. 0x2c, 0xee, 0xca, 0xc7, 0x5d, 0xe5, 0x27, 0x52,
  34807. 0x56, 0xc2, 0xc1, 0xa6, 0x53, 0xfd, 0x69, 0x15,
  34808. 0xb1, 0xb3, 0x0c, 0x8e, 0xcb, 0xb6, 0xfd, 0x42,
  34809. 0x80, 0x43, 0x74, 0x53, 0x17, 0x3a, 0x96, 0x23,
  34810. 0x8b, 0xc7, 0xd1, 0x08, 0x89, 0x23, 0x43, 0xe0,
  34811. 0x33, 0xbc, 0xd9, 0x8e, 0x43, 0x7e, 0x78, 0x9f,
  34812. 0xc5, 0xbe, 0xba, 0xa1, 0x2b, 0x26, 0x34, 0xb5,
  34813. 0x1e, 0xd0, 0xd5, 0x89, 0xf1, 0x11, 0x43, 0xa0,
  34814. 0x21, 0xd8, 0xec, 0xce, 0x59, 0x4f, 0xdd, 0x48,
  34815. 0xda, 0xe8, 0x4c, 0x80, 0x63, 0xef, 0x35, 0x81,
  34816. 0xbc, 0x37, 0x8a, 0x48, 0xda, 0x4e, 0x51, 0xbb,
  34817. 0x17, 0x5b, 0x0d, 0xb4, 0x7f, 0x9d, 0xcf, 0x99,
  34818. 0x31, 0x8c, 0x30, 0x22, 0x5c, 0xa7, 0xfa, 0x79,
  34819. 0xc8, 0x79, 0xbf, 0x1c, 0x93, 0x97, 0xb5, 0xcc,
  34820. 0xc5, 0xef, 0xad, 0x94, 0xc5, 0x00, 0xed, 0x7f,
  34821. 0x9f, 0x38, 0x5d, 0x08, 0x8e, 0x34, 0x93, 0x22,
  34822. 0x21, 0xfc, 0x0f, 0xc9, 0xaf, 0xe5, 0x1f, 0x68,
  34823. 0x75, 0x54, 0x81, 0x31, 0x69, 0x76, 0x95, 0x47,
  34824. 0x8a, 0xbd, 0xc8, 0x73, 0x6f, 0x10, 0x09, 0x5a,
  34825. 0x6b, 0x92, 0xec, 0x67, 0x9f, 0xe0, 0xe2, 0xae,
  34826. 0x5d, 0x8b, 0x33, 0x53, 0x55, 0xd5, 0x8d, 0xae,
  34827. 0x4d, 0x4f, 0x0b, 0x17, 0xaa, 0x5d, 0x1e, 0x52,
  34828. 0xf1, 0xd4, 0x55, 0x84, 0xa8, 0x92, 0xc3, 0x4c,
  34829. 0xe4, 0xb0, 0x4f, 0xcd, 0x00, 0x98, 0x1d, 0x51,
  34830. 0xca, 0xa1, 0x60, 0x64, 0xba, 0xd9, 0x2d, 0x01,
  34831. 0x9d, 0xc3, 0xad, 0xed, 0x91, 0x96, 0x84, 0x11,
  34832. 0x2b, 0x29, 0xda, 0xa2, 0x8b, 0x9d, 0xae, 0x09,
  34833. 0xb8, 0x6b, 0x21, 0xa9, 0x33, 0x10, 0xd5, 0xfb,
  34834. 0xc6, 0x52, 0x7b, 0x22, 0x4b, 0x9c, 0xe8, 0x7d,
  34835. 0x27, 0x82, 0xbb, 0x29, 0x46, 0x73, 0xf0, 0xec,
  34836. 0x06, 0xf2, 0x6b, 0x08, 0x76, 0x52, 0xa1, 0x8d,
  34837. 0x6a, 0xd7, 0xb1, 0xc9, 0x33, 0x03, 0xef, 0x05,
  34838. 0x61, 0xc0, 0xfc, 0x9c, 0xd4, 0xf6, 0x78, 0xf6,
  34839. 0x06, 0xf1, 0x92, 0xcf, 0x5d, 0xf9, 0x2b, 0x15,
  34840. 0x48, 0xf5, 0xdd, 0x26, 0x87, 0xed, 0xbe, 0xcc,
  34841. 0xfc, 0x6d, 0x4e, 0x9d, 0xe4, 0xbd, 0x50, 0xd3,
  34842. 0xc7, 0x4f, 0xb2, 0x75, 0xab, 0xd9, 0xb3, 0xe9,
  34843. 0x02, 0x77, 0xdb, 0x4a, 0x00, 0x69, 0xc0, 0xa2,
  34844. 0xa7, 0x13, 0x6f, 0x50, 0xce, 0xad, 0x4b, 0x2f,
  34845. 0x19, 0x95, 0xfa, 0xaf, 0x16, 0x80, 0x40, 0xe9,
  34846. 0xe4, 0xbe, 0xb7, 0xc5, 0x72, 0x20, 0x49, 0xd6,
  34847. 0xda, 0x64, 0x02, 0x99, 0x2f, 0xce, 0xa4, 0x50,
  34848. 0x97, 0xdf, 0x7c, 0x1c, 0x20, 0xfb, 0x06, 0x82,
  34849. 0x22, 0x00, 0x05, 0x76, 0x93, 0x5a, 0x08, 0x06,
  34850. 0x77, 0x34, 0x51, 0x92, 0x1f, 0x54, 0xc5, 0x5f,
  34851. 0xbf, 0x59, 0x3a, 0x4f, 0x14, 0x7c, 0x1f, 0xef,
  34852. 0x3a, 0xca, 0xf0, 0xcf, 0xa9, 0x07, 0xae, 0x48,
  34853. 0xc8, 0xc0, 0x63, 0x12, 0xcf, 0xdf, 0x51, 0x86,
  34854. 0x90, 0x4b, 0xec, 0x7f, 0xed, 0x4e, 0xd9, 0x33,
  34855. 0xc9, 0x25, 0x6a, 0xb0, 0x4c, 0xbf, 0xa0, 0x3a,
  34856. 0x96, 0x7c, 0x1f, 0x7e, 0xad, 0x4a, 0xb4, 0x0d,
  34857. 0xf1, 0x16, 0xbe, 0x66, 0x0e, 0x27, 0xca, 0x2b,
  34858. 0x54, 0x35, 0x26, 0xd4, 0xb9, 0x68, 0x4c, 0x31,
  34859. 0xe1, 0xe4, 0x23, 0x83, 0xb9, 0x69, 0xf8, 0x96,
  34860. 0x29, 0x9d, 0x71, 0x39, 0x0c, 0xc8, 0x5b, 0x70,
  34861. 0x32, 0x02, 0xac, 0xad, 0xec, 0xfa, 0x8c, 0x40,
  34862. 0x96, 0x5c, 0x08, 0xc5, 0x3b, 0x56, 0x71, 0xe0,
  34863. 0xd5, 0x94, 0x55, 0xbc, 0x5a, 0x85, 0x86, 0xc6,
  34864. 0x55, 0xdb, 0x8c, 0x2a, 0xde, 0x4b, 0xa8, 0x87,
  34865. 0x7f, 0x19, 0xb6, 0x00, 0x0e, 0x18, 0xf8, 0xfe,
  34866. 0xad, 0xda, 0x7e, 0xde, 0x8f, 0xe8, 0x0a, 0xa6,
  34867. 0x62, 0xd6, 0x94, 0xc6, 0xd8, 0xc3, 0x3b, 0x52
  34868. };
  34869. #endif
  34870. #ifdef WOLFSSL_KYBER_ORIGINAL
  34871. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ss[] = {
  34872. 0x0A, 0x69, 0x25, 0x67, 0x6F, 0x24, 0xB2, 0x2C,
  34873. 0x28, 0x6F, 0x4C, 0x81, 0xA4, 0x22, 0x4C, 0xEC,
  34874. 0x50, 0x6C, 0x9B, 0x25, 0x7D, 0x48, 0x0E, 0x02,
  34875. 0xE3, 0xB4, 0x9F, 0x44, 0xCA, 0xA3, 0x23, 0x7F
  34876. };
  34877. #endif
  34878. #ifndef WOLFSSL_NO_ML_KEM
  34879. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_ss[] = {
  34880. 0x31, 0x98, 0x39, 0xe8, 0x2a, 0xb6, 0xb2, 0x22,
  34881. 0xde, 0x7b, 0x61, 0x9e, 0x80, 0xda, 0x83, 0x91,
  34882. 0x52, 0x2b, 0xbb, 0x37, 0x67, 0x70, 0x18, 0x49,
  34883. 0x4a, 0x47, 0x42, 0xc5, 0x3f, 0x9a, 0xbf, 0xdf
  34884. };
  34885. #endif
  34886. #ifdef WOLFSSL_SMALL_STACK
  34887. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  34888. DYNAMIC_TYPE_TMP_BUFFER);
  34889. priv = (byte *)XMALLOC(KYBER512_PRIVATE_KEY_SIZE, HEAP_HINT,
  34890. DYNAMIC_TYPE_TMP_BUFFER);
  34891. pub = (byte *)XMALLOC(KYBER512_PUBLIC_KEY_SIZE, HEAP_HINT,
  34892. DYNAMIC_TYPE_TMP_BUFFER);
  34893. ct = (byte *)XMALLOC(KYBER512_CIPHER_TEXT_SIZE, HEAP_HINT,
  34894. DYNAMIC_TYPE_TMP_BUFFER);
  34895. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34896. DYNAMIC_TYPE_TMP_BUFFER);
  34897. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34898. DYNAMIC_TYPE_TMP_BUFFER);
  34899. if (! (key && priv && pub && ct && ss && ss_dec))
  34900. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  34901. #endif
  34902. #ifdef WOLFSSL_KYBER_ORIGINAL
  34903. ret = wc_KyberKey_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
  34904. if (ret != 0)
  34905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34906. else
  34907. key_inited = 1;
  34908. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34909. sizeof(kyber512_rand));
  34910. if (ret != 0)
  34911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34912. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
  34913. if (ret != 0)
  34914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34915. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
  34916. if (ret != 0)
  34917. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34918. if (XMEMCMP(pub, kyber512_pk, sizeof(kyber512_pk)) != 0)
  34919. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34920. if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0)
  34921. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34922. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34923. sizeof(kyber512enc_rand));
  34924. if (ret != 0)
  34925. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34926. if (XMEMCMP(ct, kyber512_ct, sizeof(kyber512_ct)) != 0)
  34927. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34928. if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34929. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34930. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
  34931. if (ret != 0)
  34932. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34933. if (XMEMCMP(ss_dec, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34934. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34935. #endif
  34936. #ifndef WOLFSSL_NO_ML_KEM
  34937. ret = wc_KyberKey_Init(WC_ML_KEM_512, key, HEAP_HINT, INVALID_DEVID);
  34938. if (ret != 0)
  34939. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34940. else
  34941. key_inited = 1;
  34942. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34943. sizeof(kyber512_rand));
  34944. if (ret != 0)
  34945. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34946. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_512_PUBLIC_KEY_SIZE);
  34947. if (ret != 0)
  34948. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34949. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  34950. WC_ML_KEM_512_PRIVATE_KEY_SIZE);
  34951. if (ret != 0)
  34952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34953. if (XMEMCMP(pub, ml_kem_512_pk, sizeof(ml_kem_512_pk)) != 0)
  34954. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34955. if (XMEMCMP(priv, ml_kem_512_sk, sizeof(ml_kem_512_sk)) != 0)
  34956. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34957. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34958. sizeof(kyber512enc_rand));
  34959. if (ret != 0)
  34960. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34961. if (XMEMCMP(ct, ml_kem_512_ct, sizeof(ml_kem_512_ct)) != 0)
  34962. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34963. if (XMEMCMP(ss, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
  34964. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34965. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_512_ct));
  34966. if (ret != 0)
  34967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34968. if (XMEMCMP(ss_dec, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
  34969. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34970. #endif
  34971. out:
  34972. if (key_inited)
  34973. wc_KyberKey_Free(key);
  34974. #ifdef WOLFSSL_SMALL_STACK
  34975. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34976. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34977. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34978. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34979. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34980. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34981. #endif
  34982. return ret;
  34983. }
  34984. #endif /* WOLFSSL_KYBER512 */
  34985. #if !defined(WOLFSSL_NO_KYBER768) && !defined(WOLFSSL_NO_ML_KEM_768)
  34986. static wc_test_ret_t kyber768_kat(void)
  34987. {
  34988. wc_test_ret_t ret;
  34989. #ifdef WOLFSSL_SMALL_STACK
  34990. KyberKey *key = NULL;
  34991. byte *priv = NULL;
  34992. byte *pub = NULL;
  34993. byte *ct = NULL;
  34994. byte *ss = NULL;
  34995. byte *ss_dec = NULL;
  34996. #else
  34997. KyberKey key[1];
  34998. byte priv[KYBER768_PRIVATE_KEY_SIZE];
  34999. byte pub[KYBER768_PUBLIC_KEY_SIZE];
  35000. byte ct[KYBER768_CIPHER_TEXT_SIZE];
  35001. byte ss[KYBER_SS_SZ];
  35002. byte ss_dec[KYBER_SS_SZ];
  35003. #endif
  35004. int key_inited = 0;
  35005. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_rand[] = {
  35006. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  35007. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  35008. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  35009. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  35010. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35011. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35012. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35013. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35014. };
  35015. WOLFSSL_SMALL_STACK_STATIC const byte kyber768enc_rand[] = {
  35016. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  35017. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  35018. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  35019. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  35020. };
  35021. #ifdef WOLFSSL_KYBER_ORIGINAL
  35022. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_pk[] = {
  35023. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35024. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35025. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35026. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35027. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35028. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35029. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35030. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35031. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35032. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35033. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35034. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35035. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35036. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35037. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35038. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35039. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35040. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35041. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35042. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35043. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35044. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35045. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35046. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35047. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35048. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35049. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35050. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35051. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35052. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35053. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35054. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35055. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35056. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35057. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35058. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35059. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35060. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35061. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35062. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35063. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35064. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35065. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35066. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35067. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35068. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35069. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35070. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35071. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35072. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35073. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35074. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35075. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35076. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35077. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35078. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35079. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35080. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35081. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35082. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35083. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35084. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35085. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35086. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35087. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35088. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35089. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35090. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35091. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35092. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35093. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35094. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35095. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35096. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35097. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35098. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35099. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35100. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35101. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35102. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35103. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35104. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35105. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35106. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35107. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35108. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35109. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35110. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35111. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35112. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35113. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35114. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35115. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35116. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35117. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35118. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35119. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35120. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35121. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35122. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35123. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35124. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35125. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35126. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35127. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35128. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35129. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35130. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35131. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35132. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35133. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35134. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35135. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35136. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35137. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35138. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35139. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35140. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35141. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35142. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35143. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35144. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35145. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35146. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35147. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35148. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35149. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35150. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35151. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35152. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35153. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35154. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35155. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35156. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35157. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35158. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35159. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35160. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35161. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35162. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35163. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35164. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35165. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35166. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35167. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35168. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35169. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35170. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  35171. };
  35172. #endif
  35173. #ifndef WOLFSSL_NO_ML_KEM
  35174. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_pk[] = {
  35175. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35176. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35177. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35178. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35179. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35180. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35181. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35182. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35183. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35184. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35185. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35186. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35187. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35188. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35189. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35190. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35191. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35192. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35193. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35194. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35195. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35196. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35197. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35198. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35199. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35200. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35201. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35202. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35203. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35204. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35205. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35206. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35207. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35208. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35209. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35210. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35211. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35212. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35213. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35214. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35215. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35216. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35217. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35218. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35219. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35220. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35221. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35222. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35223. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35224. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35225. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35226. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35227. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35228. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35229. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35230. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35231. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35232. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35233. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35234. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35235. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35236. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35237. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35238. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35239. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35240. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35241. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35242. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35243. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35244. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35245. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35246. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35247. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35248. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35249. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35250. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35251. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35252. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35253. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35254. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35255. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35256. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35257. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35258. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35259. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35260. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35261. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35262. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35263. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35264. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35265. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35266. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35267. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35268. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35269. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35270. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35271. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35272. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35273. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35274. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35275. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35276. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35277. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35278. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35279. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35280. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35281. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35282. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35283. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35284. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35285. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35286. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35287. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35288. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35289. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35290. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35291. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35292. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35293. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35294. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35295. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35296. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35297. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35298. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35299. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35300. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35301. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35302. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35303. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35304. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35305. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35306. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35307. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35308. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35309. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35310. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35311. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35312. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35313. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35314. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35315. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35316. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35317. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35318. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35319. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35320. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35321. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35322. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28
  35323. };
  35324. #endif
  35325. #ifdef WOLFSSL_KYBER_ORIGINAL
  35326. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_sk[] = {
  35327. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  35328. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  35329. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  35330. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  35331. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  35332. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  35333. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  35334. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  35335. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  35336. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  35337. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  35338. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  35339. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  35340. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  35341. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  35342. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  35343. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  35344. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  35345. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  35346. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  35347. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  35348. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  35349. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  35350. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  35351. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  35352. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  35353. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  35354. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  35355. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  35356. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  35357. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  35358. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  35359. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  35360. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  35361. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  35362. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  35363. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  35364. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  35365. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  35366. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  35367. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  35368. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  35369. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  35370. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  35371. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  35372. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  35373. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  35374. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  35375. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  35376. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  35377. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  35378. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  35379. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  35380. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  35381. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  35382. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  35383. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  35384. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  35385. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  35386. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  35387. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  35388. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  35389. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  35390. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  35391. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  35392. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  35393. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  35394. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  35395. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  35396. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  35397. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  35398. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  35399. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  35400. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  35401. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  35402. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  35403. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  35404. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  35405. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  35406. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  35407. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  35408. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  35409. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  35410. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  35411. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  35412. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  35413. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  35414. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  35415. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  35416. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  35417. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  35418. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  35419. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  35420. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  35421. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  35422. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  35423. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  35424. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  35425. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  35426. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  35427. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  35428. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  35429. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  35430. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  35431. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  35432. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  35433. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  35434. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  35435. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  35436. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  35437. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  35438. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  35439. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  35440. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  35441. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  35442. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  35443. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  35444. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  35445. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  35446. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  35447. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  35448. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  35449. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  35450. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  35451. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  35452. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  35453. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  35454. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  35455. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  35456. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  35457. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  35458. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  35459. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  35460. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  35461. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  35462. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  35463. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  35464. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  35465. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  35466. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  35467. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  35468. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  35469. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  35470. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  35471. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35472. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35473. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35474. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35475. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35476. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35477. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35478. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35479. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35480. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35481. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35482. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35483. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35484. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35485. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35486. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35487. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35488. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35489. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35490. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35491. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35492. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35493. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35494. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35495. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35496. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35497. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35498. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35499. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35500. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35501. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35502. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35503. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35504. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35505. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35506. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35507. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35508. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35509. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35510. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35511. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35512. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35513. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35514. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35515. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35516. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35517. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35518. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35519. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35520. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35521. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35522. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35523. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35524. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35525. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35526. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35527. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35528. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35529. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35530. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35531. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35532. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35533. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35534. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35535. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35536. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35537. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35538. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35539. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35540. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35541. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35542. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35543. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35544. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35545. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35546. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35547. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35548. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35549. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35550. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35551. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35552. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35553. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35554. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35555. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35556. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35557. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35558. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35559. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35560. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35561. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35562. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35563. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35564. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35565. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35566. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35567. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35568. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35569. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35570. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35571. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35572. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35573. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35574. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35575. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35576. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35577. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35578. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35579. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35580. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35581. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35582. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35583. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35584. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35585. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35586. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35587. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35588. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35589. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35590. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35591. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35592. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35593. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35594. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35595. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35596. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35597. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35598. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35599. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35600. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35601. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35602. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35603. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35604. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35605. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35606. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35607. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35608. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35609. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35610. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35611. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35612. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35613. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35614. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35615. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35616. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35617. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35618. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  35619. 0xD4, 0xEC, 0x14, 0x3B, 0x50, 0xF0, 0x14, 0x23,
  35620. 0xB1, 0x77, 0x89, 0x5E, 0xDE, 0xE2, 0x2B, 0xB7,
  35621. 0x39, 0xF6, 0x47, 0xEC, 0xF8, 0x5F, 0x50, 0xBC,
  35622. 0x25, 0xEF, 0x7B, 0x5A, 0x72, 0x5D, 0xEE, 0x86,
  35623. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35624. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35625. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35626. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35627. };
  35628. #endif
  35629. #ifndef WOLFSSL_NO_ML_KEM
  35630. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_sk[] = {
  35631. 0xda, 0x0a, 0xc7, 0xb6, 0x60, 0x40, 0x4e, 0x61,
  35632. 0x3a, 0xa1, 0xf9, 0x80, 0x38, 0x0c, 0xb3, 0x6d,
  35633. 0xba, 0x18, 0xd2, 0x32, 0x56, 0xc7, 0x26, 0x7a,
  35634. 0x00, 0xa6, 0x7b, 0xa6, 0xc2, 0xa2, 0xb1, 0x4c,
  35635. 0x41, 0x42, 0x39, 0x66, 0x2f, 0x68, 0xbd, 0x44,
  35636. 0x6c, 0x8e, 0xfd, 0xf3, 0x66, 0x56, 0xa0, 0x89,
  35637. 0x1a, 0x3c, 0xc6, 0x23, 0xfc, 0x68, 0xb6, 0x57,
  35638. 0x2f, 0x7b, 0x29, 0xa6, 0xde, 0x12, 0x80, 0x14,
  35639. 0x41, 0x1e, 0xe4, 0x19, 0x06, 0xd0, 0x80, 0x71,
  35640. 0xf9, 0x48, 0x56, 0xe3, 0x6a, 0x83, 0x2b, 0x40,
  35641. 0x33, 0x8d, 0x74, 0x35, 0x16, 0x65, 0x9b, 0xd2,
  35642. 0x58, 0x79, 0xc0, 0x07, 0xa5, 0x2b, 0xc9, 0x58,
  35643. 0x6f, 0x79, 0x87, 0x6a, 0xfa, 0xc6, 0xc9, 0xa3,
  35644. 0x0d, 0x8f, 0xac, 0x24, 0x3b, 0xd2, 0x24, 0x25,
  35645. 0xd6, 0xad, 0xce, 0x42, 0xab, 0x7e, 0xd3, 0x90,
  35646. 0x14, 0x75, 0x7a, 0x95, 0x8b, 0xc8, 0xa7, 0x45,
  35647. 0x65, 0xf0, 0x19, 0x23, 0x4f, 0xf0, 0x4b, 0x34,
  35648. 0x89, 0x3e, 0xd6, 0xd0, 0x55, 0x01, 0xc3, 0x72,
  35649. 0x55, 0x23, 0x9a, 0xae, 0x2a, 0xc1, 0x9f, 0x8c,
  35650. 0x75, 0xac, 0x59, 0x00, 0xda, 0xe8, 0x30, 0x0d,
  35651. 0xbb, 0xa7, 0x10, 0xdc, 0x2c, 0xaa, 0xe1, 0xbc,
  35652. 0xa3, 0xa3, 0x8c, 0x58, 0x34, 0x2b, 0x28, 0x6b,
  35653. 0x85, 0x18, 0xf1, 0x36, 0xad, 0x15, 0xb9, 0xf7,
  35654. 0xbc, 0xbb, 0x06, 0xa5, 0x60, 0x7d, 0xb3, 0x75,
  35655. 0xdb, 0xe9, 0x76, 0x45, 0x7c, 0x26, 0xc6, 0x59,
  35656. 0x82, 0x57, 0x53, 0x1b, 0x2c, 0xfb, 0x6e, 0xe7,
  35657. 0xf5, 0x15, 0x91, 0x84, 0x08, 0x04, 0xc3, 0x83,
  35658. 0x88, 0x37, 0x6c, 0x27, 0x14, 0x84, 0x13, 0xda,
  35659. 0x9e, 0x92, 0x92, 0x0b, 0xfd, 0x9a, 0x06, 0x9e,
  35660. 0x01, 0x8b, 0xd2, 0x72, 0x05, 0x3d, 0xa8, 0x77,
  35661. 0x5c, 0x0b, 0x73, 0x9f, 0x76, 0x1d, 0xb2, 0x10,
  35662. 0x7c, 0xf3, 0x5a, 0x43, 0x4d, 0x69, 0xb0, 0x7e,
  35663. 0x5b, 0xcd, 0xb8, 0x74, 0x34, 0x13, 0x8b, 0x0c,
  35664. 0xb5, 0x56, 0x76, 0x1b, 0xa5, 0x22, 0xa5, 0x74,
  35665. 0x7b, 0x28, 0x74, 0x7d, 0x80, 0xeb, 0x9d, 0x6c,
  35666. 0xc6, 0x73, 0xbe, 0xe5, 0x76, 0x93, 0x77, 0xb9,
  35667. 0x96, 0xd3, 0x6c, 0xeb, 0x0c, 0x0c, 0x7e, 0xd9,
  35668. 0xa6, 0x58, 0x53, 0x33, 0x24, 0x86, 0x9c, 0x18,
  35669. 0xa1, 0xa3, 0x6f, 0x31, 0x47, 0x0f, 0x14, 0xc5,
  35670. 0xae, 0x49, 0xab, 0x07, 0x05, 0x07, 0xf8, 0x24,
  35671. 0x9c, 0xe4, 0x04, 0xb4, 0x9c, 0x0a, 0x8c, 0x3e,
  35672. 0xe4, 0x2f, 0xea, 0x96, 0x31, 0xfa, 0x1a, 0x0d,
  35673. 0x10, 0xd8, 0x6b, 0x93, 0xf9, 0x86, 0xe0, 0xe3,
  35674. 0xa8, 0x2e, 0x70, 0x3b, 0x74, 0xe5, 0xae, 0x61,
  35675. 0x01, 0x24, 0x24, 0x21, 0xa8, 0x9a, 0xa0, 0x7f,
  35676. 0xe6, 0x85, 0x88, 0x46, 0x0b, 0xaa, 0x36, 0x87,
  35677. 0x86, 0x48, 0x6a, 0x72, 0xe4, 0xf2, 0x4d, 0x2d,
  35678. 0xd7, 0x6c, 0xfc, 0x03, 0xb6, 0x94, 0xa5, 0xba,
  35679. 0x91, 0xa7, 0x55, 0xa0, 0xb9, 0x8f, 0x3b, 0xf9,
  35680. 0x33, 0x07, 0xc0, 0xab, 0x64, 0x63, 0x9a, 0xea,
  35681. 0x7a, 0x64, 0x98, 0xa3, 0xc3, 0xdd, 0xc5, 0x71,
  35682. 0x14, 0x1a, 0xbc, 0xa4, 0x67, 0x8c, 0xd2, 0xe2,
  35683. 0xb8, 0x57, 0xfb, 0x88, 0xf6, 0x00, 0xca, 0xa5,
  35684. 0x96, 0xb4, 0x4b, 0xc4, 0x22, 0x25, 0x0b, 0x28,
  35685. 0x19, 0xe0, 0x51, 0x5f, 0x04, 0x72, 0x39, 0x18,
  35686. 0x53, 0x70, 0x0b, 0x01, 0xef, 0xf9, 0x45, 0x3f,
  35687. 0xd1, 0x18, 0x76, 0xb7, 0xc7, 0x59, 0xa0, 0x7d,
  35688. 0xd8, 0x45, 0xca, 0xba, 0x45, 0x55, 0x26, 0x4a,
  35689. 0x82, 0x76, 0x51, 0x93, 0xfd, 0xf8, 0x1b, 0x62,
  35690. 0x0a, 0x1e, 0x1f, 0x92, 0x3f, 0xb2, 0x44, 0x42,
  35691. 0xcd, 0x1c, 0xbe, 0x94, 0x17, 0x50, 0x03, 0xec,
  35692. 0x06, 0xce, 0x77, 0xa3, 0xc6, 0x44, 0x93, 0xc1,
  35693. 0x99, 0x98, 0x7a, 0x30, 0x0c, 0x95, 0xc5, 0x3c,
  35694. 0x00, 0x89, 0xb5, 0xd6, 0x5c, 0x92, 0xea, 0x97,
  35695. 0x1b, 0x2f, 0xfa, 0x93, 0xb5, 0x2a, 0x46, 0x1e,
  35696. 0xa2, 0xac, 0x8c, 0x19, 0x9c, 0x2f, 0x4c, 0x2b,
  35697. 0x70, 0x42, 0x97, 0xce, 0x3c, 0x39, 0x49, 0xe0,
  35698. 0x73, 0x5e, 0xa8, 0xa1, 0x4a, 0xa5, 0x9e, 0x8d,
  35699. 0xec, 0x0c, 0x87, 0x83, 0x99, 0xff, 0x70, 0x74,
  35700. 0x7a, 0xb2, 0x44, 0xce, 0x46, 0xb5, 0xf2, 0x23,
  35701. 0x04, 0x73, 0x32, 0x3d, 0x25, 0xc6, 0x6f, 0xe6,
  35702. 0xb4, 0x19, 0xb1, 0xf4, 0xa1, 0x12, 0xe5, 0x21,
  35703. 0x40, 0x35, 0x25, 0x6b, 0xc4, 0x3f, 0xfd, 0x2b,
  35704. 0x6b, 0x7b, 0x37, 0x87, 0x69, 0xa6, 0xb4, 0x70,
  35705. 0x00, 0xbf, 0xb6, 0x35, 0x7d, 0x45, 0x81, 0x4b,
  35706. 0xae, 0xf3, 0x85, 0x7d, 0x37, 0x9e, 0x2f, 0xb8,
  35707. 0xb5, 0xe5, 0x20, 0x1a, 0xb2, 0x62, 0x74, 0xbb,
  35708. 0x1b, 0x70, 0xad, 0x32, 0x2c, 0xd0, 0x43, 0x9b,
  35709. 0x2d, 0xb1, 0x09, 0xcf, 0xf0, 0xa2, 0xf8, 0xe6,
  35710. 0x00, 0x99, 0x55, 0x71, 0xff, 0xc3, 0x8c, 0x59,
  35711. 0x0b, 0xc4, 0xc7, 0x61, 0x5c, 0x69, 0xd0, 0xc9,
  35712. 0x8e, 0xf4, 0x30, 0xf3, 0x08, 0x61, 0xa7, 0x72,
  35713. 0x38, 0xff, 0xc0, 0x70, 0x61, 0xe4, 0x75, 0xd6,
  35714. 0xa3, 0x0a, 0xd1, 0xb4, 0x7f, 0xd0, 0x39, 0xc3,
  35715. 0xa4, 0x47, 0x76, 0x2d, 0xb2, 0x21, 0x1d, 0xc3,
  35716. 0x1d, 0x0a, 0xca, 0xcf, 0xd5, 0x58, 0x90, 0xa5,
  35717. 0x82, 0x47, 0x98, 0xf9, 0xae, 0xad, 0x74, 0x13,
  35718. 0xdf, 0xe0, 0x28, 0xb1, 0x01, 0x2b, 0xe8, 0xb6,
  35719. 0xca, 0x10, 0x26, 0x66, 0x6a, 0xc6, 0xbc, 0x94,
  35720. 0x40, 0xa4, 0x49, 0xb5, 0x1a, 0xd8, 0xbb, 0xa7,
  35721. 0xb0, 0x92, 0x1d, 0xd4, 0xd8, 0xb4, 0xa5, 0x78,
  35722. 0x13, 0x6d, 0x1a, 0x05, 0xdb, 0x38, 0xcc, 0x85,
  35723. 0x84, 0x37, 0xb2, 0x51, 0x61, 0xd1, 0xc3, 0xc2,
  35724. 0x8e, 0xe0, 0x7b, 0xbc, 0xf2, 0xb2, 0x49, 0x11,
  35725. 0x0d, 0x22, 0x78, 0x1d, 0xc3, 0x05, 0x0d, 0x8c,
  35726. 0xc0, 0x09, 0x00, 0x96, 0xb3, 0x8a, 0x85, 0x06,
  35727. 0x96, 0xf8, 0x6e, 0x9e, 0x6b, 0xab, 0x32, 0x52,
  35728. 0x71, 0xb2, 0x24, 0x86, 0x75, 0x01, 0x19, 0x68,
  35729. 0x50, 0x28, 0x81, 0x09, 0x04, 0x97, 0xfa, 0xc0,
  35730. 0xaf, 0x84, 0x3c, 0x1a, 0xea, 0x76, 0xdd, 0x81,
  35731. 0xcf, 0x29, 0xc0, 0x12, 0xc6, 0x62, 0x27, 0xb7,
  35732. 0xf0, 0x6d, 0x99, 0x61, 0x30, 0x9b, 0x02, 0x62,
  35733. 0xf7, 0x32, 0xc9, 0xa4, 0xd0, 0xbb, 0xd0, 0x67,
  35734. 0x27, 0xab, 0xb8, 0x37, 0x1f, 0xf2, 0xc1, 0x18,
  35735. 0x99, 0xa0, 0x98, 0x37, 0x5c, 0x46, 0x05, 0x16,
  35736. 0xb2, 0xcc, 0x88, 0xbc, 0xf6, 0x28, 0xed, 0xe3,
  35737. 0x7d, 0x8f, 0x3b, 0x33, 0x42, 0xe4, 0x49, 0x0a,
  35738. 0x85, 0x60, 0x6e, 0xc0, 0x3d, 0xa2, 0x9b, 0x02,
  35739. 0x56, 0x27, 0x53, 0x82, 0xa3, 0x31, 0x3d, 0xc0,
  35740. 0x41, 0x11, 0x48, 0x01, 0x03, 0x2c, 0x51, 0x9f,
  35741. 0x35, 0x0c, 0x3e, 0x6a, 0xba, 0xc3, 0xe3, 0x3b,
  35742. 0x93, 0xb4, 0xa1, 0x9f, 0x7c, 0x54, 0x66, 0xe5,
  35743. 0x8c, 0xb1, 0xdc, 0x14, 0xb4, 0xa9, 0x6c, 0x47,
  35744. 0x57, 0x29, 0xf9, 0x71, 0xbd, 0xf1, 0x73, 0xcd,
  35745. 0xf3, 0x54, 0x82, 0x4d, 0x01, 0x94, 0x27, 0xf9,
  35746. 0x5b, 0x3b, 0x4a, 0x4a, 0x4a, 0x95, 0x8e, 0x47,
  35747. 0x6a, 0x6e, 0x69, 0x91, 0xce, 0x6f, 0x06, 0xcb,
  35748. 0x5d, 0xfc, 0xa7, 0xd4, 0x38, 0x0c, 0x3d, 0x92,
  35749. 0x0b, 0x57, 0x11, 0xac, 0x1f, 0xcb, 0xaf, 0x4b,
  35750. 0x9a, 0xc8, 0x00, 0xb9, 0x76, 0xd1, 0xec, 0x76,
  35751. 0x6a, 0x62, 0x6c, 0xc1, 0x90, 0x0b, 0x66, 0xb3,
  35752. 0xa9, 0xdc, 0x62, 0xc5, 0xc1, 0x44, 0x52, 0x7a,
  35753. 0x29, 0x6b, 0xaf, 0x70, 0x43, 0x3b, 0xf6, 0x57,
  35754. 0xc0, 0x43, 0x7f, 0x87, 0x59, 0x7b, 0xd7, 0xc8,
  35755. 0xbb, 0xbe, 0x9a, 0xbc, 0x37, 0x05, 0x09, 0x31,
  35756. 0xa4, 0xa8, 0x69, 0x82, 0xa2, 0x02, 0x8a, 0x74,
  35757. 0x45, 0x4c, 0x9b, 0x81, 0x0c, 0x88, 0xd1, 0x70,
  35758. 0x1c, 0x8c, 0xc9, 0x8a, 0x1d, 0x4c, 0xa1, 0x07,
  35759. 0xa6, 0xb2, 0x5e, 0x96, 0x2f, 0xe4, 0xb6, 0xb0,
  35760. 0x3c, 0x95, 0x45, 0x32, 0x60, 0xb8, 0x07, 0x22,
  35761. 0x86, 0x37, 0xcc, 0x9e, 0xb1, 0x2a, 0xcc, 0x09,
  35762. 0x54, 0x95, 0x9a, 0x52, 0xae, 0x54, 0xd1, 0x97,
  35763. 0x73, 0x00, 0xab, 0xa0, 0xba, 0x2c, 0x14, 0x60,
  35764. 0x9b, 0xb2, 0x8c, 0x11, 0xd5, 0xfa, 0xc5, 0xca,
  35765. 0xc8, 0x82, 0x97, 0x60, 0x32, 0x83, 0xe8, 0x67,
  35766. 0xa3, 0x64, 0x83, 0x66, 0xc7, 0x24, 0xd9, 0x35,
  35767. 0x4c, 0xd7, 0xa1, 0x96, 0xdb, 0xd9, 0x80, 0x2f,
  35768. 0x7b, 0x88, 0xd3, 0xfa, 0x00, 0x1f, 0x9c, 0x97,
  35769. 0x73, 0x22, 0x54, 0x62, 0x23, 0x5e, 0x91, 0x35,
  35770. 0x2a, 0x20, 0x79, 0x1f, 0xd8, 0xb8, 0x7f, 0xe3,
  35771. 0x37, 0x7e, 0xc6, 0xa3, 0x94, 0x0b, 0x11, 0x30,
  35772. 0xa0, 0xbb, 0x04, 0xe7, 0x41, 0x0a, 0x34, 0xe2,
  35773. 0x58, 0x0d, 0x07, 0x1d, 0x6c, 0x56, 0x20, 0x20,
  35774. 0x86, 0x78, 0x7a, 0x65, 0x90, 0xf8, 0x43, 0x93,
  35775. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35776. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35777. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35778. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35779. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35780. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35781. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35782. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35783. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35784. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35785. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35786. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35787. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35788. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35789. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35790. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35791. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35792. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35793. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35794. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35795. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35796. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35797. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35798. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35799. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35800. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35801. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35802. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35803. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35804. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35805. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35806. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35807. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35808. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35809. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35810. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35811. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35812. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35813. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35814. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35815. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35816. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35817. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35818. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35819. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35820. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35821. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35822. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35823. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35824. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35825. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35826. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35827. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35828. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35829. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35830. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35831. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35832. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35833. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35834. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35835. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35836. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35837. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35838. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35839. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35840. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35841. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35842. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35843. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35844. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35845. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35846. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35847. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35848. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35849. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35850. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35851. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35852. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35853. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35854. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35855. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35856. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35857. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35858. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35859. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35860. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35861. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35862. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35863. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35864. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35865. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35866. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35867. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35868. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35869. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35870. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35871. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35872. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35873. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35874. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35875. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35876. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35877. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35878. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35879. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35880. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35881. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35882. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35883. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35884. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35885. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35886. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35887. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35888. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35889. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35890. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35891. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35892. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35893. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35894. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35895. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35896. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35897. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35898. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35899. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35900. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35901. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35902. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35903. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35904. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35905. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35906. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35907. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35908. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35909. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35910. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35911. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35912. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35913. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35914. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35915. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35916. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35917. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35918. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35919. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35920. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35921. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35922. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28,
  35923. 0xf5, 0x72, 0x62, 0x66, 0x13, 0x58, 0xcd, 0xe8,
  35924. 0xd3, 0xeb, 0xf9, 0x90, 0xe5, 0xfd, 0x1d, 0x5b,
  35925. 0x89, 0x6c, 0x99, 0x2c, 0xcf, 0xaa, 0xdb, 0x52,
  35926. 0x56, 0xb6, 0x8b, 0xbf, 0x59, 0x43, 0xb1, 0x32,
  35927. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  35928. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  35929. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  35930. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  35931. };
  35932. #endif
  35933. #ifdef WOLFSSL_KYBER_ORIGINAL
  35934. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ct[] = {
  35935. 0xB5, 0x2C, 0x56, 0xB9, 0x2A, 0x4B, 0x7C, 0xE9,
  35936. 0xE4, 0xCB, 0x7C, 0x5B, 0x1B, 0x16, 0x31, 0x67,
  35937. 0xA8, 0xA1, 0x67, 0x5B, 0x2F, 0xDE, 0xF8, 0x4A,
  35938. 0x5B, 0x67, 0xCA, 0x15, 0xDB, 0x69, 0x4C, 0x9F,
  35939. 0x11, 0xBD, 0x02, 0x7C, 0x30, 0xAE, 0x22, 0xEC,
  35940. 0x92, 0x1A, 0x1D, 0x91, 0x15, 0x99, 0xAF, 0x05,
  35941. 0x85, 0xE4, 0x8D, 0x20, 0xDA, 0x70, 0xDF, 0x9F,
  35942. 0x39, 0xE3, 0x2E, 0xF9, 0x5D, 0x4C, 0x8F, 0x44,
  35943. 0xBF, 0xEF, 0xDA, 0xA5, 0xDA, 0x64, 0xF1, 0x05,
  35944. 0x46, 0x31, 0xD0, 0x4D, 0x6D, 0x3C, 0xFD, 0x0A,
  35945. 0x54, 0x0D, 0xD7, 0xBA, 0x38, 0x86, 0xE4, 0xB5,
  35946. 0xF1, 0x3E, 0x87, 0x87, 0x88, 0x60, 0x4C, 0x95,
  35947. 0xC0, 0x96, 0xEA, 0xB3, 0x91, 0x9F, 0x42, 0x75,
  35948. 0x21, 0x41, 0x9A, 0x94, 0x6C, 0x26, 0xCC, 0x04,
  35949. 0x14, 0x75, 0xD7, 0x12, 0x4C, 0xDC, 0x01, 0xD0,
  35950. 0x37, 0x3E, 0x5B, 0x09, 0xC7, 0xA7, 0x06, 0x03,
  35951. 0xCF, 0xDB, 0x4F, 0xB3, 0x40, 0x50, 0x23, 0xF2,
  35952. 0x26, 0x4D, 0xC3, 0xF9, 0x83, 0xC4, 0xFC, 0x02,
  35953. 0xA2, 0xD1, 0xB2, 0x68, 0xF2, 0x20, 0x8A, 0x1F,
  35954. 0x6E, 0x2A, 0x62, 0x09, 0xBF, 0xF1, 0x2F, 0x6F,
  35955. 0x46, 0x5F, 0x0B, 0x06, 0x9C, 0x3A, 0x7F, 0x84,
  35956. 0xF6, 0x06, 0xD8, 0xA9, 0x40, 0x64, 0x00, 0x3D,
  35957. 0x6E, 0xC1, 0x14, 0xC8, 0xE8, 0x08, 0xD3, 0x05,
  35958. 0x38, 0x84, 0xC1, 0xD5, 0xA1, 0x42, 0xFB, 0xF2,
  35959. 0x01, 0x12, 0xEB, 0x36, 0x0F, 0xDA, 0x3F, 0x0F,
  35960. 0x28, 0xB1, 0x72, 0xAE, 0x50, 0xF5, 0xE7, 0xD8,
  35961. 0x38, 0x01, 0xFB, 0x3F, 0x00, 0x64, 0xB6, 0x87,
  35962. 0x18, 0x70, 0x74, 0xBD, 0x7F, 0xE3, 0x0E, 0xDD,
  35963. 0xAA, 0x33, 0x4C, 0xF8, 0xFC, 0x04, 0xFA, 0x8C,
  35964. 0xED, 0x89, 0x9C, 0xEA, 0xDE, 0x4B, 0x4F, 0x28,
  35965. 0xB6, 0x83, 0x72, 0xBA, 0xF9, 0x8F, 0xF4, 0x82,
  35966. 0xA4, 0x15, 0xB7, 0x31, 0x15, 0x5B, 0x75, 0xCE,
  35967. 0xB9, 0x76, 0xBE, 0x0E, 0xA0, 0x28, 0x5B, 0xA0,
  35968. 0x1A, 0x27, 0xF1, 0x85, 0x7A, 0x8F, 0xB3, 0x77,
  35969. 0xA3, 0xAE, 0x0C, 0x23, 0xB2, 0xAA, 0x9A, 0x07,
  35970. 0x9B, 0xFA, 0xBF, 0xF0, 0xD5, 0xB2, 0xF1, 0xCD,
  35971. 0x9B, 0x71, 0x8B, 0xEA, 0x03, 0xC4, 0x2F, 0x34,
  35972. 0x3A, 0x39, 0xB4, 0xF1, 0x42, 0xD0, 0x1A, 0xD8,
  35973. 0xAC, 0xBB, 0x50, 0xE3, 0x88, 0x53, 0xCF, 0x9A,
  35974. 0x50, 0xC8, 0xB4, 0x4C, 0x3C, 0xF6, 0x71, 0xA4,
  35975. 0xA9, 0x04, 0x3B, 0x26, 0xDD, 0xBB, 0x24, 0x95,
  35976. 0x9A, 0xD6, 0x71, 0x5C, 0x08, 0x52, 0x18, 0x55,
  35977. 0xC7, 0x9A, 0x23, 0xB9, 0xC3, 0xD6, 0x47, 0x17,
  35978. 0x49, 0xC4, 0x07, 0x25, 0xBD, 0xD5, 0xC2, 0x77,
  35979. 0x6D, 0x43, 0xAE, 0xD2, 0x02, 0x04, 0xBA, 0xA1,
  35980. 0x41, 0xEF, 0xB3, 0x30, 0x49, 0x17, 0x47, 0x4B,
  35981. 0x7F, 0x9F, 0x7A, 0x4B, 0x08, 0xB1, 0xA9, 0x3D,
  35982. 0xAE, 0xD9, 0x8C, 0x67, 0x49, 0x53, 0x59, 0xD3,
  35983. 0x7D, 0x67, 0xF7, 0x43, 0x8B, 0xEE, 0x5E, 0x43,
  35984. 0x58, 0x56, 0x34, 0xB2, 0x6C, 0x6B, 0x38, 0x10,
  35985. 0xD7, 0xCD, 0xCB, 0xC0, 0xF6, 0xEB, 0x87, 0x7A,
  35986. 0x60, 0x87, 0xE6, 0x8A, 0xCB, 0x84, 0x80, 0xD3,
  35987. 0xA8, 0xCF, 0x69, 0x00, 0x44, 0x7E, 0x49, 0xB4,
  35988. 0x17, 0xF1, 0x5A, 0x53, 0xB6, 0x07, 0xA0, 0xE2,
  35989. 0x16, 0xB8, 0x55, 0x97, 0x0D, 0x37, 0x40, 0x68,
  35990. 0x70, 0xB4, 0x56, 0x87, 0x22, 0xDA, 0x77, 0xA4,
  35991. 0x08, 0x47, 0x03, 0x81, 0x67, 0x84, 0xE2, 0xF1,
  35992. 0x6B, 0xED, 0x18, 0x99, 0x65, 0x32, 0xC5, 0xD8,
  35993. 0xB7, 0xF5, 0xD2, 0x14, 0x46, 0x4E, 0x5F, 0x3F,
  35994. 0x6E, 0x90, 0x58, 0x67, 0xB0, 0xCE, 0x11, 0x9E,
  35995. 0x25, 0x2A, 0x66, 0x71, 0x32, 0x53, 0x54, 0x46,
  35996. 0x85, 0xD2, 0x08, 0xE1, 0x72, 0x39, 0x08, 0xA0,
  35997. 0xCE, 0x97, 0x83, 0x46, 0x52, 0xE0, 0x8A, 0xE7,
  35998. 0xBD, 0xC8, 0x81, 0xA1, 0x31, 0xB7, 0x3C, 0x71,
  35999. 0xE8, 0x4D, 0x20, 0xD6, 0x8F, 0xDE, 0xFF, 0x4F,
  36000. 0x5D, 0x70, 0xCD, 0x1A, 0xF5, 0x7B, 0x78, 0xE3,
  36001. 0x49, 0x1A, 0x98, 0x65, 0x94, 0x23, 0x21, 0x80,
  36002. 0x0A, 0x20, 0x3C, 0x05, 0xED, 0x1F, 0xEE, 0xB5,
  36003. 0xA2, 0x8E, 0x58, 0x4E, 0x19, 0xF6, 0x53, 0x5E,
  36004. 0x7F, 0x84, 0xE4, 0xA2, 0x4F, 0x84, 0xA7, 0x2D,
  36005. 0xCA, 0xF5, 0x64, 0x8B, 0x4A, 0x42, 0x35, 0xDD,
  36006. 0x66, 0x44, 0x64, 0x48, 0x2F, 0x03, 0x17, 0x6E,
  36007. 0x88, 0x8C, 0x28, 0xBF, 0xC6, 0xC1, 0xCB, 0x23,
  36008. 0x8C, 0xFF, 0xA3, 0x5A, 0x32, 0x1E, 0x71, 0x79,
  36009. 0x1D, 0x9E, 0xA8, 0xED, 0x08, 0x78, 0xC6, 0x11,
  36010. 0x21, 0xBF, 0x8D, 0x2A, 0x4A, 0xB2, 0xC1, 0xA5,
  36011. 0xE1, 0x20, 0xBC, 0x40, 0xAB, 0xB1, 0x89, 0x2D,
  36012. 0x17, 0x15, 0x09, 0x0A, 0x0E, 0xE4, 0x82, 0x52,
  36013. 0xCA, 0x29, 0x7A, 0x99, 0xAA, 0x0E, 0x51, 0x0C,
  36014. 0xF2, 0x6B, 0x1A, 0xDD, 0x06, 0xCA, 0x54, 0x3E,
  36015. 0x1C, 0x5D, 0x6B, 0xDC, 0xD3, 0xB9, 0xC5, 0x85,
  36016. 0xC8, 0x53, 0x80, 0x45, 0xDB, 0x5C, 0x25, 0x2E,
  36017. 0xC3, 0xC8, 0xC3, 0xC9, 0x54, 0xD9, 0xBE, 0x59,
  36018. 0x07, 0x09, 0x4A, 0x89, 0x4E, 0x60, 0xEA, 0xB4,
  36019. 0x35, 0x38, 0xCF, 0xEE, 0x82, 0xE8, 0xFF, 0xC0,
  36020. 0x79, 0x1B, 0x0D, 0x0F, 0x43, 0xAC, 0x16, 0x27,
  36021. 0x83, 0x0A, 0x61, 0xD5, 0x6D, 0xAD, 0x96, 0xC6,
  36022. 0x29, 0x58, 0xB0, 0xDE, 0x78, 0x0B, 0x78, 0xBD,
  36023. 0x47, 0xA6, 0x04, 0x55, 0x0D, 0xAB, 0x83, 0xFF,
  36024. 0xF2, 0x27, 0xC3, 0x24, 0x04, 0x94, 0x71, 0xF3,
  36025. 0x52, 0x48, 0xCF, 0xB8, 0x49, 0xB2, 0x57, 0x24,
  36026. 0xFF, 0x70, 0x4D, 0x52, 0x77, 0xAA, 0x35, 0x2D,
  36027. 0x55, 0x09, 0x58, 0xBE, 0x3B, 0x23, 0x7D, 0xFF,
  36028. 0x47, 0x3E, 0xC2, 0xAD, 0xBA, 0xEA, 0x48, 0xCA,
  36029. 0x26, 0x58, 0xAE, 0xFC, 0xC7, 0x7B, 0xBD, 0x42,
  36030. 0x64, 0xAB, 0x37, 0x4D, 0x70, 0xEA, 0xE5, 0xB9,
  36031. 0x64, 0x41, 0x6C, 0xE8, 0x22, 0x6A, 0x7E, 0x32,
  36032. 0x55, 0xA0, 0xF8, 0xD7, 0xE2, 0xAD, 0xCA, 0x06,
  36033. 0x2B, 0xCD, 0x6D, 0x78, 0xD6, 0x0D, 0x1B, 0x32,
  36034. 0xE1, 0x14, 0x05, 0xBE, 0x54, 0xB6, 0x6E, 0xF0,
  36035. 0xFD, 0xDD, 0x56, 0x77, 0x02, 0xA3, 0xBC, 0xCF,
  36036. 0xED, 0xE3, 0xC5, 0x84, 0x70, 0x12, 0x69, 0xED,
  36037. 0x14, 0x80, 0x9F, 0x06, 0xF8, 0x96, 0x83, 0x56,
  36038. 0xBB, 0x92, 0x67, 0xFE, 0x86, 0xE5, 0x14, 0x25,
  36039. 0x2E, 0x88, 0xBB, 0x5C, 0x30, 0xA7, 0xEC, 0xB3,
  36040. 0xD0, 0xE6, 0x21, 0x02, 0x1E, 0xE0, 0xFB, 0xF7,
  36041. 0x87, 0x1B, 0x09, 0x34, 0x2B, 0xF8, 0x4F, 0x55,
  36042. 0xC9, 0x7E, 0xAF, 0x86, 0xC4, 0x81, 0x89, 0xC7,
  36043. 0xFF, 0x4D, 0xF3, 0x89, 0xF0, 0x77, 0xE2, 0x80,
  36044. 0x6E, 0x5F, 0xA7, 0x3B, 0x3E, 0x94, 0x58, 0xA1,
  36045. 0x6C, 0x7E, 0x27, 0x5F, 0x4F, 0x60, 0x22, 0x75,
  36046. 0x58, 0x0E, 0xB7, 0xB7, 0x13, 0x5F, 0xB5, 0x37,
  36047. 0xFA, 0x0C, 0xD9, 0x5D, 0x6E, 0xA5, 0x8C, 0x10,
  36048. 0x8C, 0xD8, 0x94, 0x3D, 0x70, 0xC1, 0x64, 0x31,
  36049. 0x11, 0xF4, 0xF0, 0x1C, 0xA8, 0xA8, 0x27, 0x6A,
  36050. 0x90, 0x26, 0x66, 0xED, 0x81, 0xB7, 0x8D, 0x16,
  36051. 0x8B, 0x00, 0x6F, 0x16, 0xAA, 0xA3, 0xD8, 0xE4,
  36052. 0xCE, 0x4F, 0x4D, 0x0F, 0xB0, 0x99, 0x7E, 0x41,
  36053. 0xAE, 0xFF, 0xB5, 0xB3, 0xDA, 0xA8, 0x38, 0x73,
  36054. 0x2F, 0x35, 0x73, 0x49, 0x44, 0x7F, 0x38, 0x77,
  36055. 0x76, 0xC7, 0x93, 0xC0, 0x47, 0x9D, 0xE9, 0xE9,
  36056. 0x94, 0x98, 0xCC, 0x35, 0x6F, 0xDB, 0x00, 0x75,
  36057. 0xA7, 0x03, 0xF2, 0x3C, 0x55, 0xD4, 0x7B, 0x55,
  36058. 0x0E, 0xC8, 0x9B, 0x02, 0xAD, 0xE8, 0x93, 0x29,
  36059. 0x08, 0x6A, 0x50, 0x84, 0x34, 0x56, 0xFE, 0xDC,
  36060. 0x37, 0x88, 0xAC, 0x8D, 0x97, 0x23, 0x3C, 0x54,
  36061. 0x56, 0x04, 0x67, 0xEE, 0x1D, 0x0F, 0x02, 0x4B,
  36062. 0x18, 0x42, 0x8F, 0x0D, 0x73, 0xB3, 0x0E, 0x19,
  36063. 0xF5, 0xC6, 0x3B, 0x9A, 0xBF, 0x11, 0x41, 0x5B,
  36064. 0xEA, 0x4D, 0x01, 0x70, 0x13, 0x0B, 0xAA, 0xBD,
  36065. 0x33, 0xC0, 0x5E, 0x65, 0x24, 0xE5, 0xFB, 0x55,
  36066. 0x81, 0xB2, 0x2B, 0x04, 0x33, 0x34, 0x22, 0x48,
  36067. 0x26, 0x6D, 0x0F, 0x10, 0x53, 0xB2, 0x45, 0xCC,
  36068. 0x24, 0x62, 0xDC, 0x44, 0xD3, 0x49, 0x65, 0x10,
  36069. 0x24, 0x82, 0xA8, 0xED, 0x9E, 0x4E, 0x96, 0x4D,
  36070. 0x56, 0x83, 0xE5, 0xD4, 0x5D, 0x0C, 0x82, 0x69
  36071. };
  36072. #endif
  36073. #ifndef WOLFSSL_NO_ML_KEM
  36074. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_ct[] = {
  36075. 0xc8, 0x39, 0x10, 0x85, 0xb8, 0xd3, 0xea, 0x97,
  36076. 0x94, 0x21, 0x25, 0x41, 0xb2, 0x91, 0x4f, 0x08,
  36077. 0x96, 0x4d, 0x33, 0x52, 0x1d, 0x3f, 0x67, 0xad,
  36078. 0x66, 0x09, 0x6e, 0xbf, 0xb1, 0xf7, 0x06, 0x42,
  36079. 0x4b, 0x49, 0x55, 0x8f, 0x75, 0x5b, 0x56, 0x25,
  36080. 0xba, 0xe2, 0x36, 0xf2, 0xe0, 0x07, 0x96, 0x01,
  36081. 0xc7, 0x66, 0xf7, 0xd9, 0x60, 0x80, 0x8f, 0x7e,
  36082. 0x2b, 0xb0, 0xc7, 0xa5, 0xe0, 0x66, 0xed, 0x34,
  36083. 0x6d, 0xe6, 0x28, 0xf8, 0xc5, 0x7e, 0xeb, 0xab,
  36084. 0xbb, 0x0c, 0x22, 0xd9, 0x11, 0x54, 0x84, 0x63,
  36085. 0x69, 0x3e, 0xf3, 0xce, 0x52, 0xa5, 0x3f, 0x7f,
  36086. 0xf4, 0x15, 0xf0, 0x0e, 0x65, 0x7a, 0xe1, 0xc5,
  36087. 0xa4, 0x8f, 0xa5, 0xec, 0x6e, 0x4b, 0xe5, 0xcf,
  36088. 0x46, 0x2d, 0xaf, 0xfc, 0x84, 0xd2, 0xf6, 0xd5,
  36089. 0xff, 0x55, 0xdc, 0x9b, 0xbe, 0x8b, 0xb0, 0xd7,
  36090. 0x25, 0xec, 0x64, 0xfd, 0x4c, 0xd4, 0xbd, 0x8d,
  36091. 0xba, 0x0a, 0x84, 0x4e, 0x8b, 0x5c, 0xe4, 0xb6,
  36092. 0xa2, 0x89, 0x34, 0xd7, 0xf7, 0xa0, 0x50, 0x99,
  36093. 0x1f, 0xe1, 0x85, 0xb5, 0x06, 0xb4, 0x51, 0xda,
  36094. 0xbf, 0xad, 0x52, 0xd5, 0x2c, 0xb2, 0x11, 0x4c,
  36095. 0xa7, 0xd9, 0xa5, 0xcf, 0x98, 0x6c, 0x8f, 0xdc,
  36096. 0x1b, 0xc1, 0x0e, 0xc0, 0xc1, 0x86, 0x9e, 0x50,
  36097. 0xc0, 0x3c, 0x55, 0xa7, 0x61, 0x92, 0xa1, 0x04,
  36098. 0x9a, 0xca, 0x63, 0x6b, 0xa9, 0x02, 0x0b, 0xda,
  36099. 0xa8, 0xd0, 0xf5, 0x8c, 0x76, 0x3b, 0x0b, 0x89,
  36100. 0x84, 0x5c, 0xa0, 0x6d, 0x4c, 0x4d, 0xdc, 0x21,
  36101. 0x43, 0x3e, 0x16, 0xb9, 0xc6, 0x2e, 0x44, 0x87,
  36102. 0x1f, 0xdb, 0xc0, 0x5b, 0xa2, 0x18, 0xaf, 0x87,
  36103. 0x1f, 0xdd, 0x7d, 0xcf, 0xa4, 0x64, 0xe6, 0x0f,
  36104. 0xaa, 0x52, 0x65, 0x26, 0x4c, 0xe1, 0x39, 0x1b,
  36105. 0xd9, 0xa8, 0xc5, 0xfa, 0xa7, 0x62, 0x6d, 0x5f,
  36106. 0x15, 0x9b, 0x98, 0x05, 0xb9, 0x75, 0x71, 0x0a,
  36107. 0x35, 0x03, 0xa0, 0xb8, 0x58, 0xa1, 0x1c, 0x6a,
  36108. 0x64, 0x7c, 0xc0, 0xe1, 0x9a, 0xc8, 0x8b, 0x1b,
  36109. 0xe9, 0x05, 0x6c, 0x95, 0xb4, 0xd2, 0x08, 0x7d,
  36110. 0x09, 0x51, 0xd1, 0xd2, 0xf4, 0x99, 0x24, 0x91,
  36111. 0x11, 0x7e, 0x63, 0x47, 0x79, 0x4b, 0xa5, 0x45,
  36112. 0x71, 0xec, 0x49, 0xbb, 0xa7, 0x1a, 0xf3, 0x41,
  36113. 0x3d, 0x38, 0xa3, 0x0b, 0xf5, 0x87, 0x22, 0x48,
  36114. 0xd1, 0xf6, 0xd0, 0x7c, 0x86, 0xba, 0xf7, 0x82,
  36115. 0xe7, 0x3d, 0x26, 0x37, 0xf0, 0x43, 0xd3, 0x41,
  36116. 0xa0, 0x09, 0x21, 0x85, 0x7d, 0x8b, 0x21, 0xdd,
  36117. 0xf3, 0xe1, 0xd6, 0x31, 0x00, 0x36, 0xed, 0x27,
  36118. 0xaf, 0x49, 0xe5, 0xde, 0x1b, 0x90, 0x0f, 0xe4,
  36119. 0xde, 0x79, 0x80, 0x8f, 0xf2, 0x9f, 0x95, 0x70,
  36120. 0x85, 0x96, 0x12, 0xb1, 0x5a, 0xdc, 0x01, 0xfb,
  36121. 0xb2, 0x65, 0xb3, 0x05, 0xb1, 0xe3, 0xa1, 0x2a,
  36122. 0xe4, 0x19, 0xda, 0x5b, 0x74, 0x26, 0x1f, 0xa2,
  36123. 0x84, 0xc1, 0x01, 0xda, 0x3d, 0x8d, 0xca, 0x8b,
  36124. 0x2e, 0x45, 0x21, 0xac, 0xa5, 0x71, 0xef, 0x44,
  36125. 0xa0, 0x58, 0xe8, 0x44, 0xff, 0x32, 0xb1, 0x6d,
  36126. 0x5a, 0xae, 0xa0, 0x5f, 0x7f, 0x3a, 0xf8, 0xe2,
  36127. 0xab, 0x16, 0x22, 0x2e, 0x34, 0x76, 0x62, 0xed,
  36128. 0xdf, 0xb8, 0x91, 0xd0, 0xec, 0xc2, 0xa5, 0x5c,
  36129. 0x56, 0x38, 0xf9, 0xdd, 0xe9, 0x2d, 0x9a, 0x3d,
  36130. 0x54, 0x4a, 0x5f, 0x90, 0x1a, 0xc5, 0x01, 0xac,
  36131. 0xd1, 0xea, 0x6a, 0x01, 0x02, 0x01, 0xfc, 0xb1,
  36132. 0x0a, 0xd7, 0x02, 0xc4, 0x25, 0xa9, 0x4b, 0xdf,
  36133. 0x58, 0x90, 0xd5, 0x00, 0xa2, 0xa1, 0x47, 0xee,
  36134. 0xe1, 0xd1, 0xfc, 0xba, 0x8c, 0x3a, 0xbe, 0x7c,
  36135. 0x2d, 0xfe, 0x70, 0xf3, 0x46, 0xf0, 0x33, 0xd8,
  36136. 0x16, 0xa0, 0xb2, 0x79, 0x1b, 0x4f, 0x0b, 0x2d,
  36137. 0x95, 0x6d, 0x9e, 0xe5, 0x97, 0x17, 0x15, 0x39,
  36138. 0x9a, 0x56, 0x88, 0x30, 0x24, 0x95, 0xe2, 0xe0,
  36139. 0x7c, 0x1c, 0x8c, 0x01, 0x52, 0x71, 0x84, 0xbc,
  36140. 0xd0, 0xc2, 0x08, 0xbc, 0x15, 0x9f, 0x2e, 0x13,
  36141. 0x31, 0x8c, 0x0b, 0xb3, 0xdd, 0x24, 0xa6, 0xa7,
  36142. 0xfc, 0x84, 0x9f, 0x83, 0x38, 0x5e, 0xd4, 0xdb,
  36143. 0xa0, 0x7f, 0xe1, 0xd7, 0xbd, 0x56, 0x40, 0xcc,
  36144. 0x9e, 0xd5, 0xcc, 0xfd, 0xd6, 0x87, 0x63, 0xcb,
  36145. 0x0d, 0x0e, 0xdf, 0x61, 0xb2, 0x92, 0x17, 0x7f,
  36146. 0xc1, 0xd2, 0xd3, 0xc1, 0x1d, 0xd0, 0x49, 0x50,
  36147. 0x56, 0xbc, 0xb1, 0x25, 0x58, 0xae, 0xbc, 0xfd,
  36148. 0xde, 0xf9, 0xfe, 0xb4, 0xae, 0xbc, 0x57, 0xaf,
  36149. 0xd9, 0x02, 0x3c, 0x65, 0xcf, 0xe6, 0x5a, 0x24,
  36150. 0xe3, 0x3f, 0x1b, 0x00, 0x11, 0x1e, 0x92, 0xe6,
  36151. 0x3e, 0x01, 0x1e, 0xaf, 0x0b, 0x21, 0x2c, 0xf9,
  36152. 0x57, 0x43, 0xcd, 0x07, 0xf5, 0x18, 0x9e, 0xce,
  36153. 0x1f, 0x20, 0x5b, 0x7f, 0x6f, 0xcb, 0x2e, 0x6b,
  36154. 0x19, 0x61, 0xb5, 0x40, 0x4c, 0xeb, 0xe4, 0x7c,
  36155. 0x8c, 0xd1, 0x3b, 0x85, 0x99, 0xd5, 0xb4, 0x9e,
  36156. 0x6d, 0x87, 0xee, 0xda, 0x36, 0xe9, 0xb8, 0xfc,
  36157. 0x4c, 0x00, 0x63, 0x58, 0x96, 0xaa, 0x2b, 0x75,
  36158. 0x89, 0x6e, 0x33, 0x6d, 0x1b, 0x61, 0x2e, 0xe1,
  36159. 0x3d, 0xb8, 0x11, 0xe1, 0xf0, 0x7e, 0x61, 0x74,
  36160. 0x8d, 0x92, 0x0f, 0x48, 0x65, 0xf3, 0xf1, 0x17,
  36161. 0x41, 0x39, 0x9d, 0xc6, 0x16, 0x2c, 0x91, 0xca,
  36162. 0x16, 0x8a, 0x02, 0x32, 0x9d, 0xff, 0x82, 0x1d,
  36163. 0x58, 0x19, 0x87, 0x12, 0xdd, 0x55, 0x8a, 0xbb,
  36164. 0x09, 0x9b, 0x3a, 0x0b, 0xaf, 0x9d, 0xa1, 0xb7,
  36165. 0x30, 0xb2, 0xaa, 0x73, 0xbc, 0xf5, 0x8d, 0x74,
  36166. 0xf3, 0x57, 0xb0, 0x6f, 0x72, 0x11, 0xc8, 0x04,
  36167. 0xb6, 0xc8, 0xaf, 0x16, 0xff, 0x35, 0x09, 0xfa,
  36168. 0xd1, 0xd3, 0x5b, 0x14, 0xbf, 0xdc, 0xed, 0x7d,
  36169. 0xb8, 0xa6, 0xa2, 0x5c, 0x48, 0xe5, 0x95, 0x64,
  36170. 0x80, 0x72, 0x4d, 0xaa, 0x05, 0x7c, 0xd6, 0x60,
  36171. 0xb6, 0x7e, 0xe3, 0xe4, 0x72, 0x57, 0x41, 0x82,
  36172. 0x67, 0x9d, 0x48, 0x58, 0x38, 0xa6, 0x47, 0x6e,
  36173. 0xac, 0x02, 0x14, 0x10, 0x75, 0xc8, 0x12, 0xaf,
  36174. 0x79, 0x67, 0xba, 0x7c, 0x91, 0x85, 0xcc, 0x2a,
  36175. 0xbd, 0x2a, 0x45, 0x45, 0xb8, 0x0f, 0x3d, 0x31,
  36176. 0x04, 0xd5, 0x8d, 0x65, 0x4a, 0x57, 0x79, 0x2d,
  36177. 0xcf, 0xab, 0xbe, 0x9c, 0x07, 0x15, 0xe8, 0xde,
  36178. 0x2e, 0xf8, 0x1e, 0xf4, 0x04, 0xc8, 0x16, 0x8f,
  36179. 0xd7, 0xa4, 0x3e, 0xfa, 0xb3, 0xd4, 0x48, 0xe6,
  36180. 0x86, 0xa0, 0x88, 0xef, 0xd2, 0x6a, 0x26, 0x15,
  36181. 0x99, 0x48, 0x92, 0x67, 0x23, 0xd7, 0xec, 0xcc,
  36182. 0x39, 0xe3, 0xc1, 0xb7, 0x19, 0xcf, 0x8b, 0xec,
  36183. 0xb7, 0xbe, 0x7e, 0x96, 0x4f, 0x22, 0xcd, 0x8c,
  36184. 0xb1, 0xb7, 0xe2, 0x5e, 0x80, 0x0e, 0xa9, 0x7d,
  36185. 0x60, 0xa6, 0x4c, 0xc0, 0xbb, 0xd9, 0xcb, 0x40,
  36186. 0x7a, 0x3a, 0xb9, 0xf8, 0x8f, 0x5e, 0x29, 0x16,
  36187. 0x9e, 0xea, 0xfd, 0x4e, 0x03, 0x22, 0xfd, 0xe6,
  36188. 0x59, 0x0a, 0xe0, 0x93, 0xce, 0x8f, 0xee, 0xae,
  36189. 0x98, 0xb6, 0x22, 0xca, 0xa7, 0x55, 0x6f, 0xf4,
  36190. 0x26, 0xc9, 0xe7, 0xa4, 0x04, 0xce, 0x69, 0x35,
  36191. 0x58, 0x30, 0xa7, 0xa6, 0x77, 0x67, 0xa7, 0x6c,
  36192. 0x7d, 0x9a, 0x97, 0xb8, 0x4b, 0xfc, 0xf5, 0x0a,
  36193. 0x02, 0xf7, 0x5c, 0x23, 0x5d, 0x2f, 0x9c, 0x67,
  36194. 0x11, 0x38, 0x04, 0x9f, 0xfc, 0x7c, 0x80, 0x55,
  36195. 0x92, 0x6c, 0x03, 0xeb, 0x3f, 0xb8, 0x7f, 0x96,
  36196. 0x95, 0x18, 0x5a, 0x42, 0xec, 0xa9, 0xa4, 0x16,
  36197. 0x55, 0x87, 0x3d, 0x30, 0xa6, 0xb3, 0xbf, 0x42,
  36198. 0x8b, 0x24, 0x62, 0x23, 0x48, 0x4a, 0x8f, 0xf6,
  36199. 0x1e, 0xe3, 0xee, 0xaf, 0xff, 0x10, 0xe9, 0x9c,
  36200. 0x2c, 0x13, 0xa7, 0x62, 0x84, 0xd0, 0x63, 0xe5,
  36201. 0x6a, 0xb7, 0x11, 0xa3, 0x5a, 0x85, 0xb5, 0x38,
  36202. 0x3d, 0xf8, 0x1d, 0xa2, 0x34, 0x90, 0xf6, 0x6e,
  36203. 0x8e, 0xa3, 0xfc, 0xba, 0x06, 0x7f, 0x55, 0x30,
  36204. 0xc6, 0x54, 0x1c, 0x2b, 0x8f, 0x74, 0x71, 0x7c,
  36205. 0x35, 0x02, 0x3e, 0x7b, 0x9b, 0x39, 0x56, 0xc3,
  36206. 0xee, 0x2f, 0xf8, 0x4b, 0xa0, 0x3c, 0xcf, 0x4b,
  36207. 0x4b, 0x53, 0x21, 0xb9, 0x24, 0x08, 0x95, 0x48,
  36208. 0x1b, 0xc6, 0xd6, 0x3c, 0x16, 0x93, 0xc1, 0x84,
  36209. 0x78, 0x52, 0xf8, 0xe9, 0x7f, 0x50, 0xa1, 0x33,
  36210. 0x53, 0x2a, 0xc3, 0xee, 0x1e, 0x52, 0xd4, 0x64
  36211. };
  36212. #endif
  36213. #ifdef WOLFSSL_KYBER_ORIGINAL
  36214. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ss[] = {
  36215. 0x91, 0x4C, 0xB6, 0x7F, 0xE5, 0xC3, 0x8E, 0x73,
  36216. 0xBF, 0x74, 0x18, 0x1C, 0x0A, 0xC5, 0x04, 0x28,
  36217. 0xDE, 0xDF, 0x77, 0x50, 0xA9, 0x80, 0x58, 0xF7,
  36218. 0xD5, 0x36, 0x70, 0x87, 0x74, 0x53, 0x5B, 0x29
  36219. };
  36220. #endif
  36221. #ifndef WOLFSSL_NO_ML_KEM
  36222. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_ss[] = {
  36223. 0xe7, 0x18, 0x4a, 0x09, 0x75, 0xee, 0x34, 0x70,
  36224. 0x87, 0x8d, 0x2d, 0x15, 0x9e, 0xc8, 0x31, 0x29,
  36225. 0xc8, 0xae, 0xc2, 0x53, 0xd4, 0xee, 0x17, 0xb4,
  36226. 0x81, 0x03, 0x11, 0xd1, 0x98, 0xcd, 0x03, 0x68
  36227. };
  36228. #endif
  36229. #ifdef WOLFSSL_SMALL_STACK
  36230. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  36231. DYNAMIC_TYPE_TMP_BUFFER);
  36232. priv = (byte *)XMALLOC(KYBER768_PRIVATE_KEY_SIZE, HEAP_HINT,
  36233. DYNAMIC_TYPE_TMP_BUFFER);
  36234. pub = (byte *)XMALLOC(KYBER768_PUBLIC_KEY_SIZE, HEAP_HINT,
  36235. DYNAMIC_TYPE_TMP_BUFFER);
  36236. ct = (byte *)XMALLOC(KYBER768_CIPHER_TEXT_SIZE, HEAP_HINT,
  36237. DYNAMIC_TYPE_TMP_BUFFER);
  36238. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36239. DYNAMIC_TYPE_TMP_BUFFER);
  36240. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36241. DYNAMIC_TYPE_TMP_BUFFER);
  36242. if (! (key && priv && pub && ct && ss && ss_dec))
  36243. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  36244. #endif
  36245. #ifdef WOLFSSL_KYBER_ORIGINAL
  36246. ret = wc_KyberKey_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
  36247. if (ret != 0)
  36248. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36249. else
  36250. key_inited = 1;
  36251. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36252. sizeof(kyber768_rand));
  36253. if (ret != 0)
  36254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36255. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
  36256. if (ret != 0)
  36257. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36258. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
  36259. if (ret != 0)
  36260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36261. if (XMEMCMP(pub, kyber768_pk, sizeof(kyber768_pk)) != 0)
  36262. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36263. if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0)
  36264. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36265. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36266. sizeof(kyber768enc_rand));
  36267. if (ret != 0)
  36268. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36269. if (XMEMCMP(ct, kyber768_ct, sizeof(kyber768_ct)) != 0)
  36270. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36271. if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36272. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36273. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
  36274. if (ret != 0)
  36275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36276. if (XMEMCMP(ss_dec, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36277. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36278. #endif
  36279. #ifndef WOLFSSL_NO_ML_KEM
  36280. ret = wc_KyberKey_Init(WC_ML_KEM_768, key, HEAP_HINT, INVALID_DEVID);
  36281. if (ret != 0)
  36282. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36283. else
  36284. key_inited = 1;
  36285. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36286. sizeof(kyber768_rand));
  36287. if (ret != 0)
  36288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36289. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_768_PUBLIC_KEY_SIZE);
  36290. if (ret != 0)
  36291. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36292. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  36293. WC_ML_KEM_768_PRIVATE_KEY_SIZE);
  36294. if (ret != 0)
  36295. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36296. if (XMEMCMP(pub, ml_kem_768_pk, sizeof(ml_kem_768_pk)) != 0)
  36297. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36298. if (XMEMCMP(priv, ml_kem_768_sk, sizeof(ml_kem_768_sk)) != 0)
  36299. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36300. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36301. sizeof(kyber768enc_rand));
  36302. if (ret != 0)
  36303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36304. if (XMEMCMP(ct, ml_kem_768_ct, sizeof(ml_kem_768_ct)) != 0)
  36305. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36306. if (XMEMCMP(ss, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
  36307. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36308. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_768_ct));
  36309. if (ret != 0)
  36310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36311. if (XMEMCMP(ss_dec, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
  36312. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36313. #endif
  36314. out:
  36315. if (key_inited)
  36316. wc_KyberKey_Free(key);
  36317. #ifdef WOLFSSL_SMALL_STACK
  36318. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36319. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36320. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36321. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36322. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36323. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36324. #endif
  36325. return ret;
  36326. }
  36327. #endif /* WOLFSSL_KYBER768 */
  36328. #if !defined(WOLFSSL_NO_KYBER1024) && !defined(WOLFSSL_NO_ML_KEM_1024)
  36329. static wc_test_ret_t kyber1024_kat(void)
  36330. {
  36331. wc_test_ret_t ret;
  36332. #ifdef WOLFSSL_SMALL_STACK
  36333. KyberKey *key = NULL;
  36334. byte *priv = NULL;
  36335. byte *pub = NULL;
  36336. byte *ct = NULL;
  36337. byte *ss = NULL;
  36338. byte *ss_dec = NULL;
  36339. #else
  36340. KyberKey key[1];
  36341. byte priv[KYBER1024_PRIVATE_KEY_SIZE];
  36342. byte pub[KYBER1024_PUBLIC_KEY_SIZE];
  36343. byte ct[KYBER1024_CIPHER_TEXT_SIZE];
  36344. byte ss[KYBER_SS_SZ];
  36345. byte ss_dec[KYBER_SS_SZ];
  36346. #endif
  36347. int key_inited = 0;
  36348. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_rand[] = {
  36349. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  36350. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  36351. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  36352. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  36353. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  36354. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  36355. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  36356. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  36357. };
  36358. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024enc_rand[] = {
  36359. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  36360. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  36361. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  36362. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  36363. };
  36364. #ifdef WOLFSSL_KYBER_ORIGINAL
  36365. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_pk[] = {
  36366. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36367. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36368. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36369. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36370. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36371. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36372. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36373. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36374. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36375. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36376. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36377. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36378. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36379. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36380. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36381. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36382. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36383. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36384. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36385. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36386. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36387. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36388. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36389. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36390. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36391. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36392. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36393. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36394. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36395. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36396. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36397. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36398. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36399. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36400. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36401. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36402. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36403. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36404. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36405. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36406. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36407. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36408. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36409. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36410. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36411. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36412. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  36413. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  36414. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  36415. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  36416. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  36417. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  36418. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36419. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36420. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36421. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36422. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36423. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36424. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36425. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36426. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36427. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36428. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36429. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36430. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36431. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36432. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36433. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36434. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36435. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36436. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36437. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36438. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36439. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36440. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36441. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36442. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36443. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36444. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36445. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36446. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36447. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36448. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36449. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36450. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36451. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36452. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36453. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36454. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36455. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36456. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36457. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36458. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36459. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36460. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36461. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36462. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36463. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36464. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36465. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36466. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36467. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36468. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36469. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36470. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36471. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36472. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36473. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36474. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36475. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36476. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36477. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36478. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36479. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36480. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36481. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36482. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36483. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36484. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36485. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36486. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36487. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36488. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36489. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36490. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36491. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36492. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36493. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36494. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36495. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36496. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36497. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36498. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36499. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36500. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36501. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36502. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36503. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36504. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36505. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36506. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36507. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36508. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36509. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36510. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36511. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36512. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36513. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36514. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36515. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36516. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36517. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36518. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36519. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36520. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36521. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36522. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36523. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36524. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36525. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36526. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36527. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36528. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36529. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36530. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36531. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36532. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36533. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36534. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36535. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36536. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36537. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36538. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36539. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36540. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36541. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36542. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36543. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36544. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36545. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36546. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36547. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36548. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36549. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36550. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36551. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36552. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36553. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36554. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36555. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36556. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36557. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36558. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36559. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36560. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36561. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  36562. };
  36563. #endif
  36564. #ifndef WOLFSSL_NO_ML_KEM
  36565. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_pk[] = {
  36566. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36567. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36568. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36569. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36570. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36571. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36572. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36573. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36574. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36575. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36576. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36577. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36578. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36579. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36580. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36581. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36582. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36583. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36584. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36585. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36586. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36587. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36588. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36589. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36590. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36591. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36592. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36593. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36594. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36595. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36596. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36597. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36598. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36599. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36600. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36601. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36602. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36603. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36604. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36605. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36606. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36607. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36608. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36609. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36610. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36611. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36612. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36613. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36614. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36615. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36616. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36617. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36618. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36619. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36620. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36621. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36622. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36623. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36624. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36625. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36626. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36627. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36628. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36629. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36630. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36631. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36632. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  36633. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  36634. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  36635. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  36636. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  36637. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  36638. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  36639. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  36640. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  36641. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  36642. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  36643. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  36644. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  36645. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  36646. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  36647. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  36648. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  36649. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  36650. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  36651. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  36652. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  36653. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  36654. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  36655. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  36656. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  36657. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  36658. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  36659. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  36660. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  36661. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  36662. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  36663. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  36664. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  36665. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  36666. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  36667. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  36668. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  36669. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  36670. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  36671. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  36672. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  36673. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  36674. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  36675. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  36676. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  36677. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  36678. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  36679. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  36680. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  36681. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  36682. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  36683. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  36684. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  36685. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  36686. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  36687. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  36688. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  36689. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  36690. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  36691. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  36692. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  36693. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  36694. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  36695. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  36696. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  36697. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  36698. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  36699. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  36700. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  36701. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  36702. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  36703. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  36704. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  36705. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  36706. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  36707. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  36708. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  36709. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  36710. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  36711. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  36712. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  36713. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  36714. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  36715. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  36716. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  36717. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  36718. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  36719. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  36720. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  36721. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  36722. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  36723. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  36724. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  36725. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  36726. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  36727. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  36728. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  36729. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  36730. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  36731. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  36732. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  36733. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  36734. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  36735. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  36736. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  36737. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  36738. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  36739. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  36740. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  36741. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  36742. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  36743. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  36744. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  36745. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  36746. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  36747. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  36748. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  36749. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  36750. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  36751. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  36752. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  36753. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  36754. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  36755. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  36756. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  36757. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  36758. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  36759. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  36760. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  36761. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb
  36762. };
  36763. #endif
  36764. #ifdef WOLFSSL_KYBER_ORIGINAL
  36765. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_sk[] = {
  36766. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  36767. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  36768. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  36769. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  36770. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  36771. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  36772. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  36773. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  36774. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  36775. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  36776. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  36777. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  36778. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  36779. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  36780. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  36781. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  36782. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  36783. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  36784. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  36785. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  36786. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  36787. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  36788. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  36789. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  36790. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  36791. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  36792. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  36793. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  36794. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  36795. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  36796. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  36797. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  36798. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  36799. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  36800. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  36801. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  36802. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  36803. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  36804. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  36805. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  36806. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  36807. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  36808. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  36809. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  36810. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  36811. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  36812. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  36813. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  36814. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  36815. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  36816. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  36817. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  36818. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  36819. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  36820. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  36821. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  36822. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  36823. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  36824. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  36825. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  36826. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  36827. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  36828. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  36829. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  36830. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  36831. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  36832. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  36833. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  36834. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  36835. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  36836. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  36837. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  36838. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  36839. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  36840. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  36841. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  36842. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  36843. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  36844. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  36845. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  36846. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  36847. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  36848. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  36849. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  36850. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  36851. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  36852. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  36853. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  36854. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  36855. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  36856. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  36857. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  36858. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  36859. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  36860. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  36861. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  36862. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  36863. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  36864. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  36865. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  36866. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  36867. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  36868. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  36869. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  36870. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  36871. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  36872. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  36873. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  36874. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  36875. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  36876. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  36877. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  36878. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  36879. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  36880. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  36881. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  36882. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  36883. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  36884. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  36885. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  36886. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  36887. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  36888. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  36889. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  36890. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  36891. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  36892. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  36893. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  36894. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  36895. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  36896. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  36897. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  36898. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  36899. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  36900. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  36901. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  36902. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  36903. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  36904. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  36905. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  36906. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  36907. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  36908. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  36909. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  36910. 0x85, 0xA4, 0xC1, 0xA1, 0xAB, 0x9B, 0x6A, 0xEB,
  36911. 0x49, 0xCC, 0xE1, 0xC2, 0xF8, 0xA9, 0x7C, 0x35,
  36912. 0x16, 0xC7, 0x2A, 0x00, 0xA4, 0x62, 0x63, 0xBA,
  36913. 0xA6, 0x96, 0xBF, 0x25, 0x72, 0x77, 0x19, 0xC3,
  36914. 0x21, 0x64, 0x23, 0x61, 0x8F, 0xF3, 0x33, 0x80,
  36915. 0x93, 0x4A, 0x6C, 0x10, 0x54, 0x5C, 0x4C, 0x5C,
  36916. 0x51, 0x55, 0xB1, 0x24, 0x86, 0x18, 0x1F, 0xC7,
  36917. 0xA2, 0x31, 0x98, 0x73, 0x97, 0x8B, 0x6A, 0x2A,
  36918. 0x67, 0x49, 0x0F, 0x82, 0x56, 0xBD, 0x21, 0x96,
  36919. 0xFE, 0x17, 0x92, 0xA4, 0xC0, 0x00, 0x77, 0xB8,
  36920. 0x12, 0xEA, 0xE8, 0xBE, 0xD3, 0x57, 0x24, 0x99,
  36921. 0x68, 0x4A, 0xB3, 0x37, 0x18, 0x76, 0x76, 0x1E,
  36922. 0x45, 0x0C, 0x9F, 0x9D, 0x27, 0x68, 0xA3, 0x68,
  36923. 0x06, 0xD7, 0xAB, 0x20, 0x46, 0xC9, 0x1F, 0x17,
  36924. 0x59, 0x9E, 0x9A, 0xC5, 0x92, 0x99, 0x08, 0x08,
  36925. 0xDC, 0xD7, 0xB4, 0xD0, 0x91, 0x90, 0x72, 0xF1,
  36926. 0x4E, 0xC3, 0x61, 0x77, 0x3B, 0x72, 0x52, 0x44,
  36927. 0x4C, 0x32, 0x3C, 0x30, 0x83, 0x26, 0xF4, 0xA3,
  36928. 0x0F, 0x86, 0x80, 0xD2, 0xF7, 0x48, 0xF5, 0x6A,
  36929. 0x13, 0x2B, 0x82, 0x67, 0x4E, 0xD0, 0x18, 0x46,
  36930. 0x20, 0xB8, 0x2A, 0xD2, 0xCB, 0x18, 0x2C, 0x97,
  36931. 0xB4, 0x81, 0x62, 0x66, 0x47, 0x49, 0x12, 0x90,
  36932. 0xA0, 0x11, 0xCC, 0x73, 0x82, 0x86, 0x85, 0xA8,
  36933. 0xC3, 0x67, 0xA5, 0xB9, 0xCF, 0x8D, 0x62, 0x1B,
  36934. 0x0D, 0x5C, 0x1E, 0xFF, 0x03, 0x17, 0x27, 0x58,
  36935. 0xBD, 0x00, 0x49, 0x78, 0xC2, 0x51, 0xCD, 0x51,
  36936. 0x34, 0x22, 0x28, 0x98, 0x9C, 0xAE, 0x63, 0x32,
  36937. 0xAC, 0x48, 0x64, 0x37, 0xCB, 0x5C, 0x57, 0xD4,
  36938. 0x30, 0x74, 0x62, 0x86, 0x52, 0x53, 0xBE, 0x21,
  36939. 0x7B, 0x35, 0x15, 0xC7, 0x3D, 0xF4, 0x05, 0xB7,
  36940. 0xF2, 0x82, 0x17, 0xAD, 0x0B, 0x8C, 0xF6, 0x0C,
  36941. 0x2F, 0xFF, 0xAA, 0x0A, 0x00, 0x48, 0xB1, 0xFB,
  36942. 0x4A, 0xCD, 0xCD, 0xC3, 0x8B, 0x52, 0x50, 0xCF,
  36943. 0xEC, 0x35, 0x6A, 0x6D, 0xE2, 0x6C, 0xFA, 0x7A,
  36944. 0x58, 0x8F, 0xDC, 0x86, 0xF9, 0x8C, 0x85, 0x4A,
  36945. 0xC6, 0x4C, 0x7B, 0xFA, 0xA9, 0x6F, 0x5A, 0x32,
  36946. 0xCC, 0x06, 0x10, 0x93, 0x4B, 0xAA, 0x6A, 0x58,
  36947. 0x6B, 0x9A, 0x20, 0x54, 0xF1, 0x3B, 0xA2, 0x74,
  36948. 0x17, 0x4A, 0xA0, 0xD2, 0xB3, 0xA8, 0x1B, 0x96,
  36949. 0xA9, 0x40, 0x66, 0x6F, 0x78, 0x9B, 0x5A, 0x6B,
  36950. 0xCD, 0xC0, 0xA6, 0xA0, 0x17, 0x8A, 0x0C, 0x9A,
  36951. 0x02, 0x57, 0x8A, 0x49, 0x3F, 0x6E, 0xEA, 0x0D,
  36952. 0x2E, 0x6C, 0x13, 0x95, 0x1C, 0x9F, 0x24, 0x9A,
  36953. 0x5E, 0x8D, 0xD7, 0x1D, 0xD4, 0x9A, 0x74, 0x2D,
  36954. 0x45, 0x1F, 0x1A, 0xBB, 0xA1, 0x9A, 0xF8, 0xC5,
  36955. 0x47, 0x85, 0x5E, 0x0A, 0xFC, 0x72, 0x8E, 0x90,
  36956. 0xAB, 0xB4, 0x99, 0xC9, 0xBE, 0xEB, 0x76, 0x6F,
  36957. 0x47, 0x29, 0xCD, 0xA2, 0x22, 0x63, 0xE3, 0x24,
  36958. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36959. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36960. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36961. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36962. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36963. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36964. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36965. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36966. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36967. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36968. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36969. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36970. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36971. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36972. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36973. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36974. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36975. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36976. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36977. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36978. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36979. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36980. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36981. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36982. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36983. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36984. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36985. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36986. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36987. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36988. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36989. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36990. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36991. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36992. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36993. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36994. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36995. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36996. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36997. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36998. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36999. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  37000. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  37001. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  37002. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  37003. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  37004. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  37005. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  37006. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  37007. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  37008. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  37009. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  37010. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  37011. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  37012. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  37013. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  37014. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  37015. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  37016. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  37017. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  37018. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  37019. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  37020. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  37021. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  37022. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  37023. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  37024. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  37025. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  37026. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  37027. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  37028. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  37029. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  37030. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  37031. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  37032. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  37033. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  37034. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  37035. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  37036. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  37037. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  37038. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  37039. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  37040. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  37041. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  37042. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  37043. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  37044. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  37045. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  37046. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  37047. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  37048. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  37049. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  37050. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  37051. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  37052. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  37053. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  37054. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  37055. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  37056. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  37057. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  37058. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  37059. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  37060. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  37061. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  37062. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  37063. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  37064. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  37065. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  37066. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  37067. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  37068. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  37069. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  37070. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  37071. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  37072. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  37073. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  37074. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  37075. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  37076. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  37077. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  37078. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  37079. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  37080. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  37081. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  37082. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  37083. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  37084. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  37085. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  37086. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  37087. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  37088. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  37089. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  37090. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  37091. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  37092. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  37093. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  37094. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  37095. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  37096. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  37097. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  37098. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  37099. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  37100. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  37101. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  37102. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  37103. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  37104. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  37105. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  37106. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  37107. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  37108. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  37109. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  37110. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  37111. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  37112. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  37113. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  37114. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  37115. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  37116. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  37117. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  37118. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  37119. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  37120. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  37121. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  37122. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  37123. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  37124. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  37125. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  37126. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  37127. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  37128. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  37129. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  37130. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  37131. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  37132. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  37133. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  37134. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  37135. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  37136. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  37137. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  37138. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  37139. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  37140. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  37141. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  37142. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  37143. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  37144. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  37145. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  37146. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  37147. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  37148. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  37149. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  37150. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  37151. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  37152. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  37153. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  37154. 0x8A, 0x39, 0xE8, 0x7D, 0x53, 0x1F, 0x35, 0x27,
  37155. 0xC2, 0x07, 0xED, 0xCC, 0x1D, 0xB7, 0xFA, 0xDD,
  37156. 0xCF, 0x96, 0x28, 0x39, 0x18, 0x79, 0xB3, 0x35,
  37157. 0xC7, 0x07, 0x83, 0x9A, 0x0D, 0xB0, 0x51, 0xA8,
  37158. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  37159. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  37160. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  37161. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  37162. };
  37163. #endif
  37164. #ifndef WOLFSSL_NO_ML_KEM
  37165. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_sk[] = {
  37166. 0x43, 0x3a, 0x70, 0xee, 0x69, 0x50, 0xf9, 0x88,
  37167. 0x2a, 0xcd, 0xd5, 0xa4, 0x78, 0x20, 0xa6, 0xa8,
  37168. 0x16, 0x37, 0x08, 0xf0, 0x4d, 0x45, 0x7c, 0x77,
  37169. 0x99, 0x79, 0xb8, 0x3f, 0xe1, 0x17, 0x22, 0x47,
  37170. 0x01, 0x49, 0x08, 0x30, 0x38, 0x66, 0x37, 0xda,
  37171. 0x33, 0x2e, 0x74, 0xb1, 0xae, 0xda, 0x0b, 0x2f,
  37172. 0x81, 0xca, 0x4f, 0x9b, 0xb2, 0xc2, 0xb0, 0x2b,
  37173. 0x0c, 0xfd, 0x68, 0x0c, 0x11, 0x48, 0x2f, 0x33,
  37174. 0x5a, 0xcf, 0x7b, 0x91, 0x39, 0xb5, 0xb8, 0x8a,
  37175. 0x34, 0xe3, 0x54, 0x2c, 0x68, 0x61, 0x37, 0x75,
  37176. 0x45, 0x98, 0x33, 0x43, 0xcd, 0x82, 0x94, 0x14,
  37177. 0xe4, 0x78, 0x64, 0x21, 0x2e, 0x78, 0xf8, 0x55,
  37178. 0xf5, 0x23, 0x90, 0x37, 0x9a, 0xcc, 0x3a, 0x62,
  37179. 0x95, 0x31, 0x31, 0xb6, 0x3e, 0xe8, 0x32, 0xad,
  37180. 0xb3, 0xbf, 0x4b, 0xf5, 0x8e, 0x24, 0x73, 0x49,
  37181. 0xb5, 0xe0, 0x97, 0xe5, 0x5a, 0xbe, 0x49, 0x7b,
  37182. 0x15, 0x98, 0x23, 0x73, 0xae, 0x73, 0x2e, 0x04,
  37183. 0x39, 0xac, 0x67, 0xd0, 0x5c, 0x7f, 0x03, 0x7c,
  37184. 0x8a, 0x73, 0x9b, 0x18, 0x14, 0x0e, 0x14, 0x4c,
  37185. 0x85, 0x1d, 0xc9, 0x61, 0x1f, 0x4b, 0xcf, 0x04,
  37186. 0xf3, 0xa2, 0x09, 0x3c, 0x19, 0x7b, 0xd6, 0x3b,
  37187. 0xb5, 0xe6, 0x19, 0x01, 0x00, 0x54, 0x5f, 0xf8,
  37188. 0x1d, 0xb7, 0xfc, 0xcd, 0xdd, 0x9a, 0x32, 0x4b,
  37189. 0x0b, 0xac, 0x3c, 0x2c, 0x23, 0x82, 0x28, 0x40,
  37190. 0x58, 0xf0, 0x8b, 0x96, 0x19, 0x52, 0xc0, 0x94,
  37191. 0x01, 0x9c, 0x10, 0xbe, 0x37, 0xa5, 0x3d, 0x5a,
  37192. 0xc7, 0x94, 0xc0, 0x10, 0xa9, 0xd0, 0x82, 0x1f,
  37193. 0x15, 0x02, 0x7a, 0x1c, 0x41, 0x9c, 0x3c, 0x71,
  37194. 0xc9, 0xa1, 0xd2, 0x8a, 0xed, 0x02, 0x59, 0x7a,
  37195. 0xb7, 0x9b, 0x87, 0x53, 0x94, 0x62, 0x6b, 0xa3,
  37196. 0x9a, 0xdc, 0x09, 0x0c, 0x3a, 0x90, 0xcf, 0x75,
  37197. 0x87, 0x1a, 0x65, 0x27, 0x5e, 0xb1, 0xc5, 0xb0,
  37198. 0x33, 0x72, 0xe1, 0x3a, 0x1a, 0x23, 0xd0, 0xcf,
  37199. 0x93, 0x74, 0x11, 0x1f, 0x80, 0xcc, 0x83, 0xa9,
  37200. 0x05, 0x62, 0x2b, 0x83, 0xfc, 0x51, 0x39, 0x71,
  37201. 0xec, 0x84, 0x19, 0xf0, 0x88, 0x0c, 0x30, 0x67,
  37202. 0x63, 0x36, 0x71, 0xb0, 0x9b, 0x54, 0x56, 0xab,
  37203. 0x60, 0x57, 0x93, 0x6d, 0x19, 0xa4, 0xa2, 0xa2,
  37204. 0x67, 0x91, 0x1b, 0x00, 0x0a, 0x13, 0x95, 0x6f,
  37205. 0xbd, 0x49, 0x38, 0x21, 0xda, 0x07, 0x2c, 0x04,
  37206. 0x64, 0x2b, 0x0c, 0x20, 0xda, 0x6c, 0xc0, 0xd9,
  37207. 0xd8, 0x64, 0xa3, 0x93, 0x65, 0xdf, 0xd6, 0x4f,
  37208. 0x10, 0x18, 0x78, 0x25, 0xfa, 0x33, 0x25, 0x07,
  37209. 0x49, 0xcb, 0xc0, 0xc9, 0x05, 0xd7, 0xb1, 0xff,
  37210. 0x3c, 0xae, 0x24, 0x12, 0xbf, 0x86, 0xb8, 0x1a,
  37211. 0x81, 0x7b, 0x86, 0xba, 0xa3, 0x0e, 0xdf, 0x78,
  37212. 0x62, 0xe5, 0xf6, 0xba, 0xc9, 0x87, 0x26, 0xe5,
  37213. 0x6b, 0x3c, 0xec, 0x60, 0x66, 0x4c, 0xaa, 0x2a,
  37214. 0x7d, 0xf6, 0x70, 0xc5, 0xe2, 0x07, 0xdf, 0xac,
  37215. 0x03, 0x82, 0x4c, 0x89, 0x89, 0x7c, 0xb4, 0x90,
  37216. 0xea, 0xa7, 0x65, 0x21, 0x22, 0x2c, 0x86, 0x20,
  37217. 0x51, 0x69, 0xc9, 0x1c, 0x32, 0x9c, 0x4a, 0x18,
  37218. 0x4d, 0x78, 0x72, 0x1a, 0xf8, 0x36, 0xad, 0x4d,
  37219. 0xb0, 0xca, 0x78, 0x46, 0x4d, 0x41, 0x71, 0x47,
  37220. 0x30, 0x12, 0xb7, 0xd1, 0x83, 0xba, 0xfa, 0x62,
  37221. 0x75, 0x85, 0xc6, 0x4b, 0xe3, 0x80, 0x9d, 0x7e,
  37222. 0x60, 0x04, 0xcb, 0xdc, 0x79, 0xa5, 0x46, 0x0f,
  37223. 0x0a, 0xd6, 0x77, 0xcb, 0x71, 0x65, 0x12, 0x40,
  37224. 0x7d, 0x3a, 0x61, 0x9a, 0xd0, 0x95, 0x43, 0xb7,
  37225. 0x39, 0x54, 0x74, 0x72, 0xa7, 0x06, 0xb3, 0x17,
  37226. 0xa5, 0x09, 0xbe, 0x5d, 0x86, 0x1f, 0xd6, 0x6c,
  37227. 0x7d, 0x0e, 0xd9, 0x4c, 0xd5, 0x00, 0x47, 0x95,
  37228. 0xc1, 0x81, 0x59, 0xe3, 0xa3, 0x3d, 0x79, 0x87,
  37229. 0x11, 0x52, 0x5f, 0x16, 0x35, 0xa6, 0x84, 0x28,
  37230. 0x17, 0x29, 0x23, 0x24, 0x96, 0x35, 0xaa, 0xd0,
  37231. 0x32, 0xb9, 0xe5, 0x66, 0x64, 0xbd, 0xd4, 0x8e,
  37232. 0xd2, 0x4a, 0xc7, 0x5c, 0x64, 0x68, 0xd1, 0x90,
  37233. 0x3e, 0x47, 0x10, 0x86, 0xc5, 0xf1, 0x56, 0x7e,
  37234. 0x83, 0x1a, 0x05, 0x08, 0xc5, 0x39, 0x63, 0x25,
  37235. 0x91, 0xab, 0x57, 0x7d, 0x32, 0x4a, 0x82, 0x42,
  37236. 0x97, 0x25, 0x80, 0x99, 0x50, 0x76, 0x1d, 0x84,
  37237. 0x34, 0x28, 0x8c, 0x14, 0x03, 0x4f, 0x1c, 0x06,
  37238. 0xc1, 0xd0, 0xaa, 0xe0, 0x9a, 0x71, 0xc7, 0x40,
  37239. 0xa5, 0x57, 0x01, 0xc2, 0x8f, 0xf8, 0x44, 0x99,
  37240. 0xf2, 0xbb, 0x18, 0xb6, 0x62, 0x8c, 0xaa, 0xa3,
  37241. 0xfe, 0x75, 0xac, 0x4d, 0xe0, 0x4c, 0x6f, 0x91,
  37242. 0x39, 0x00, 0xd8, 0x6c, 0x88, 0x12, 0x62, 0x52,
  37243. 0xa1, 0x7c, 0x4d, 0x30, 0x39, 0x91, 0xdb, 0x02,
  37244. 0x87, 0x12, 0x08, 0x81, 0xbb, 0x88, 0x47, 0x8a,
  37245. 0xaa, 0x9a, 0xf9, 0xbc, 0x53, 0xd3, 0x72, 0x98,
  37246. 0x43, 0x85, 0x8f, 0xdb, 0x46, 0x48, 0x05, 0x9c,
  37247. 0xac, 0x82, 0xc1, 0xa1, 0x08, 0x78, 0xba, 0x39,
  37248. 0x82, 0x3b, 0x04, 0x1b, 0xd0, 0xe2, 0x58, 0x48,
  37249. 0x7b, 0x56, 0xcc, 0x8a, 0x32, 0x20, 0xc1, 0xa5,
  37250. 0x8b, 0xf6, 0x6a, 0x17, 0x2b, 0x5b, 0x9a, 0x0c,
  37251. 0x63, 0x2d, 0x67, 0x4e, 0xae, 0x88, 0x5a, 0x01,
  37252. 0x5c, 0x4e, 0x37, 0xba, 0x07, 0x36, 0x80, 0xbe,
  37253. 0xde, 0x75, 0x34, 0xf3, 0xe3, 0x4b, 0x60, 0x50,
  37254. 0xc8, 0x6b, 0x21, 0xc3, 0xc0, 0x90, 0x94, 0x1f,
  37255. 0x23, 0xb7, 0xf6, 0x73, 0x1e, 0x2b, 0xda, 0x0e,
  37256. 0x6e, 0xa4, 0x64, 0x67, 0x71, 0xce, 0xc5, 0x72,
  37257. 0xb9, 0x8c, 0xa0, 0xa1, 0x58, 0x91, 0x9a, 0xdb,
  37258. 0xeb, 0x84, 0xce, 0x58, 0x5f, 0xf9, 0xf2, 0x5e,
  37259. 0xbd, 0xda, 0x6c, 0xb6, 0xf0, 0x7a, 0x8f, 0x81,
  37260. 0x12, 0x32, 0x60, 0x7e, 0x72, 0x17, 0xbb, 0x03,
  37261. 0x9b, 0xab, 0xd0, 0xd9, 0x19, 0x34, 0xa8, 0x59,
  37262. 0x40, 0x59, 0xc9, 0x68, 0x77, 0x23, 0xc0, 0x43,
  37263. 0x81, 0xbf, 0xd6, 0x27, 0xa1, 0x05, 0x17, 0xf5,
  37264. 0xf4, 0xbf, 0xc7, 0x77, 0x77, 0xaa, 0x26, 0x71,
  37265. 0xae, 0x12, 0x4f, 0x2b, 0x7a, 0x5f, 0x4d, 0x56,
  37266. 0x14, 0x02, 0x91, 0x97, 0xe6, 0x58, 0x6f, 0xa8,
  37267. 0xc1, 0x7e, 0x0a, 0xd9, 0x07, 0x81, 0xbc, 0x7b,
  37268. 0xb1, 0x9a, 0x77, 0x2d, 0x5a, 0x4e, 0xfe, 0x32,
  37269. 0xca, 0xc8, 0x9b, 0x76, 0xc4, 0x2a, 0x5e, 0xde,
  37270. 0x9b, 0xcc, 0x20, 0xc1, 0x89, 0x8c, 0x08, 0xa5,
  37271. 0xb0, 0xc0, 0x7e, 0x47, 0x8b, 0x1b, 0xbc, 0x22,
  37272. 0x6e, 0xfa, 0xd1, 0x5f, 0x2a, 0xc7, 0x37, 0x51,
  37273. 0x4b, 0x8c, 0x61, 0x49, 0x81, 0x07, 0x79, 0x22,
  37274. 0x24, 0x16, 0x53, 0x7e, 0xd0, 0x0d, 0xae, 0xab,
  37275. 0x17, 0x7e, 0x90, 0x3e, 0xad, 0x6b, 0x4a, 0xc4,
  37276. 0x23, 0x70, 0xaf, 0x1b, 0x1f, 0x50, 0xeb, 0xaf,
  37277. 0xaa, 0x1c, 0x6e, 0x64, 0x7b, 0xba, 0xcc, 0xe7,
  37278. 0x2c, 0x7d, 0x0b, 0x88, 0xae, 0xb0, 0xb0, 0x6f,
  37279. 0xc1, 0xa4, 0x54, 0x57, 0xa9, 0xc1, 0x87, 0x57,
  37280. 0x9b, 0xf1, 0x84, 0x57, 0x9c, 0xc3, 0x51, 0xc4,
  37281. 0x3d, 0xff, 0x94, 0x26, 0x05, 0xaa, 0x56, 0x04,
  37282. 0xfc, 0x85, 0xfc, 0x55, 0x83, 0xf6, 0xf1, 0x49,
  37283. 0x6f, 0xe6, 0x1d, 0x70, 0xd6, 0xcd, 0xe2, 0x32,
  37284. 0x7f, 0xee, 0x71, 0x3d, 0x86, 0xf2, 0x9b, 0x3a,
  37285. 0xfc, 0xbb, 0x54, 0xe9, 0xa9, 0x2a, 0x33, 0xa6,
  37286. 0xc1, 0xea, 0x6f, 0xfa, 0x30, 0x95, 0x66, 0xb0,
  37287. 0x68, 0x62, 0x33, 0xc0, 0xf3, 0xb1, 0xc3, 0x14,
  37288. 0x48, 0x90, 0xe4, 0xf0, 0x82, 0x9a, 0x60, 0x99,
  37289. 0xc5, 0x74, 0x9c, 0xde, 0xc8, 0x43, 0x28, 0xec,
  37290. 0x2c, 0xb6, 0x4a, 0x73, 0x85, 0xa7, 0x61, 0xd6,
  37291. 0x4b, 0x3a, 0x23, 0xc4, 0x89, 0x34, 0x33, 0x43,
  37292. 0xb9, 0x77, 0x23, 0xae, 0x78, 0xc7, 0xd8, 0x05,
  37293. 0x45, 0x8e, 0x16, 0x20, 0xf0, 0x29, 0x28, 0x97,
  37294. 0x69, 0x17, 0x04, 0xcb, 0x76, 0xe3, 0xb0, 0xb2,
  37295. 0x81, 0xa8, 0x3c, 0xf6, 0x44, 0x90, 0x49, 0x8c,
  37296. 0xbc, 0xaf, 0x04, 0x80, 0x24, 0x16, 0xb3, 0x3c,
  37297. 0x56, 0x51, 0x71, 0xd7, 0x72, 0xd3, 0xb9, 0x35,
  37298. 0x40, 0x37, 0x58, 0x76, 0x29, 0xae, 0x14, 0xa5,
  37299. 0xc5, 0x03, 0x1a, 0xc3, 0x66, 0x71, 0xa0, 0xd0,
  37300. 0xc9, 0x1c, 0xc0, 0xb4, 0xcd, 0x69, 0xd8, 0x40,
  37301. 0x2e, 0x33, 0xb9, 0xbc, 0xc2, 0xbb, 0xaf, 0x6b,
  37302. 0x97, 0x1e, 0x30, 0x3f, 0xa1, 0x37, 0xbe, 0x23,
  37303. 0x25, 0x98, 0xa4, 0x99, 0x9b, 0xc0, 0x12, 0x57,
  37304. 0x4c, 0x81, 0x65, 0x1b, 0x38, 0xb3, 0x83, 0x96,
  37305. 0xc1, 0xc3, 0x65, 0x30, 0x3a, 0xd2, 0x5d, 0x49,
  37306. 0xfc, 0x6b, 0x68, 0x99, 0x51, 0xa1, 0xcc, 0x4c,
  37307. 0x60, 0x07, 0x61, 0x30, 0x65, 0x49, 0x5f, 0x97,
  37308. 0x91, 0x0f, 0x97, 0x35, 0xd4, 0xea, 0x4e, 0x44,
  37309. 0x2a, 0xcb, 0x2f, 0xab, 0xae, 0xcf, 0xe1, 0xad,
  37310. 0xef, 0x06, 0x67, 0xba, 0x42, 0x2c, 0x95, 0x4a,
  37311. 0x05, 0xd1, 0xb6, 0x16, 0x7a, 0x26, 0x3e, 0x12,
  37312. 0x75, 0xc6, 0xad, 0xa8, 0x38, 0x59, 0x65, 0x30,
  37313. 0x4b, 0x30, 0x32, 0x40, 0x40, 0x54, 0x2c, 0xf5,
  37314. 0xa4, 0x51, 0xbc, 0xaf, 0xc7, 0x47, 0x88, 0xbe,
  37315. 0x3b, 0x9b, 0x9f, 0xcc, 0x45, 0xd4, 0x79, 0x0e,
  37316. 0x2d, 0x73, 0x35, 0xc6, 0x0a, 0x14, 0xf0, 0xa4,
  37317. 0x9d, 0x13, 0x05, 0x3f, 0x26, 0x26, 0xa6, 0x27,
  37318. 0xca, 0x19, 0x55, 0x3c, 0xb3, 0x36, 0xa2, 0xcb,
  37319. 0x4a, 0x45, 0x5d, 0x8e, 0xf3, 0x98, 0x94, 0x91,
  37320. 0x47, 0x2b, 0xa0, 0x05, 0x1e, 0xf7, 0x41, 0x6e,
  37321. 0x0b, 0xbf, 0x1a, 0x61, 0x08, 0xfa, 0x07, 0xc1,
  37322. 0x61, 0x54, 0x8e, 0x7c, 0x62, 0x33, 0x1a, 0xe5,
  37323. 0xa2, 0xb4, 0xe4, 0xa1, 0x08, 0xa5, 0x10, 0x93,
  37324. 0xd3, 0x15, 0x08, 0x21, 0xa2, 0xfb, 0x54, 0x71,
  37325. 0x70, 0xa1, 0xb7, 0x3c, 0x43, 0xc5, 0x50, 0xc6,
  37326. 0x55, 0x7a, 0x40, 0x48, 0xa5, 0x8a, 0x2c, 0xd7,
  37327. 0x7a, 0x24, 0x42, 0x34, 0xb2, 0x23, 0x51, 0x75,
  37328. 0xa0, 0x89, 0x7d, 0x50, 0x61, 0xb4, 0x61, 0x34,
  37329. 0x82, 0xdc, 0x13, 0x64, 0x14, 0x04, 0x8c, 0x11,
  37330. 0xdb, 0x37, 0xea, 0xe0, 0xa5, 0xdf, 0x87, 0xc1,
  37331. 0x93, 0x14, 0xb0, 0xe8, 0x23, 0x97, 0xa0, 0xd3,
  37332. 0x38, 0xdc, 0x21, 0x53, 0x8a, 0xf3, 0x61, 0x49,
  37333. 0xd9, 0x3f, 0x8b, 0x1a, 0x11, 0xc5, 0x3b, 0xb5,
  37334. 0xde, 0xf8, 0xb7, 0xa2, 0xcc, 0xa3, 0x36, 0x2b,
  37335. 0x7f, 0xe3, 0xa1, 0x40, 0x8a, 0x25, 0x47, 0xe2,
  37336. 0x09, 0x05, 0x8c, 0x67, 0x3a, 0x75, 0x66, 0xc2,
  37337. 0x61, 0x23, 0xa6, 0xd8, 0xb6, 0x92, 0xa5, 0xf3,
  37338. 0x3e, 0xbd, 0xcb, 0x26, 0x24, 0xb7, 0x9d, 0x87,
  37339. 0x7b, 0xce, 0x5f, 0xa1, 0x4e, 0x42, 0xe8, 0x3f,
  37340. 0xaa, 0xd8, 0x2e, 0x99, 0x00, 0x55, 0x3a, 0x3c,
  37341. 0x60, 0x45, 0xca, 0x32, 0x9f, 0xea, 0x4a, 0x50,
  37342. 0x65, 0x58, 0xc4, 0x91, 0xb6, 0xa6, 0x16, 0xc6,
  37343. 0xfd, 0x40, 0x0b, 0x42, 0x13, 0x6f, 0x44, 0xcb,
  37344. 0x0d, 0x02, 0x57, 0x65, 0x08, 0x19, 0x01, 0x8d,
  37345. 0x3c, 0x56, 0x8e, 0xf6, 0xc6, 0x0c, 0x6c, 0x40,
  37346. 0x9e, 0x70, 0xa8, 0x29, 0x28, 0x71, 0x08, 0xc1,
  37347. 0xb6, 0xa4, 0xd3, 0x2f, 0x76, 0xe5, 0xcc, 0x4d,
  37348. 0x10, 0x4b, 0x02, 0x43, 0x8e, 0xf7, 0xa4, 0x67,
  37349. 0x91, 0x23, 0x98, 0xea, 0x9c, 0x7c, 0xbd, 0x99,
  37350. 0x81, 0x58, 0x9a, 0x34, 0x18, 0x97, 0x68, 0x7b,
  37351. 0x51, 0x6a, 0x13, 0x30, 0x7d, 0x66, 0xc0, 0x68,
  37352. 0xc4, 0x44, 0xb4, 0xb9, 0x49, 0xa1, 0x74, 0x12,
  37353. 0x41, 0x33, 0x15, 0xcc, 0xf4, 0x9b, 0x99, 0x98,
  37354. 0x00, 0x34, 0xb5, 0xb8, 0xcf, 0xde, 0xc4, 0xa6,
  37355. 0x0b, 0x9c, 0x1e, 0x74, 0x55, 0xaa, 0xfb, 0xf3,
  37356. 0xa7, 0x57, 0x34, 0x69, 0x90, 0xcc, 0x32, 0xb0,
  37357. 0x59, 0x9b, 0xa2, 0x17, 0xa6, 0xc5, 0xfc, 0x39,
  37358. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  37359. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  37360. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  37361. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  37362. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  37363. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  37364. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  37365. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  37366. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  37367. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  37368. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  37369. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  37370. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  37371. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  37372. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  37373. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  37374. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  37375. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  37376. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  37377. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  37378. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  37379. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  37380. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  37381. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  37382. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  37383. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  37384. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  37385. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  37386. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  37387. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  37388. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  37389. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  37390. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  37391. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  37392. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  37393. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  37394. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  37395. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  37396. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  37397. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  37398. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  37399. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  37400. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  37401. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  37402. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  37403. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  37404. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  37405. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  37406. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  37407. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  37408. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  37409. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  37410. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  37411. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  37412. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  37413. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  37414. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  37415. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  37416. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  37417. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  37418. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  37419. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  37420. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  37421. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  37422. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  37423. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  37424. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  37425. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  37426. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  37427. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  37428. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  37429. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  37430. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  37431. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  37432. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  37433. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  37434. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  37435. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  37436. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  37437. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  37438. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  37439. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  37440. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  37441. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  37442. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  37443. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  37444. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  37445. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  37446. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  37447. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  37448. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  37449. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  37450. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  37451. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  37452. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  37453. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  37454. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  37455. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  37456. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  37457. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  37458. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  37459. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  37460. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  37461. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  37462. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  37463. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  37464. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  37465. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  37466. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  37467. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  37468. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  37469. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  37470. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  37471. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  37472. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  37473. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  37474. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  37475. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  37476. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  37477. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  37478. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  37479. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  37480. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  37481. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  37482. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  37483. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  37484. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  37485. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  37486. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  37487. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  37488. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  37489. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  37490. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  37491. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  37492. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  37493. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  37494. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  37495. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  37496. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  37497. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  37498. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  37499. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  37500. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  37501. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  37502. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  37503. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  37504. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  37505. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  37506. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  37507. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  37508. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  37509. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  37510. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  37511. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  37512. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  37513. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  37514. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  37515. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  37516. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  37517. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  37518. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  37519. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  37520. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  37521. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  37522. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  37523. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  37524. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  37525. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  37526. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  37527. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  37528. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  37529. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  37530. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  37531. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  37532. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  37533. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  37534. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  37535. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  37536. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  37537. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  37538. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  37539. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  37540. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  37541. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  37542. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  37543. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  37544. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  37545. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  37546. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  37547. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  37548. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  37549. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  37550. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  37551. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  37552. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  37553. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb,
  37554. 0xeb, 0xbe, 0x41, 0xcd, 0x4d, 0xea, 0x48, 0x9d,
  37555. 0xed, 0xd0, 0x0e, 0x76, 0xae, 0x0b, 0xcf, 0x54,
  37556. 0xaa, 0x85, 0x50, 0x20, 0x29, 0x20, 0xeb, 0x64,
  37557. 0xd5, 0x89, 0x2a, 0xd0, 0x2b, 0x13, 0xf2, 0xe5,
  37558. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  37559. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  37560. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  37561. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  37562. };
  37563. #endif
  37564. #ifdef WOLFSSL_KYBER_ORIGINAL
  37565. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ct[] = {
  37566. 0xA6, 0xAF, 0x29, 0xD5, 0xF5, 0xB8, 0x0B, 0xD1,
  37567. 0x30, 0xF5, 0x18, 0xBA, 0xDD, 0xD6, 0xC8, 0xF1,
  37568. 0x75, 0x45, 0x41, 0x3D, 0x86, 0x0F, 0xB3, 0xDE,
  37569. 0x45, 0x19, 0x79, 0xEB, 0xFA, 0x5E, 0x4E, 0x31,
  37570. 0x12, 0xC7, 0xC0, 0xAD, 0xF9, 0x98, 0x24, 0xBB,
  37571. 0x52, 0x6F, 0x2C, 0x35, 0x50, 0x74, 0x8E, 0xD0,
  37572. 0xE1, 0x34, 0xF0, 0x45, 0x7A, 0x7C, 0x61, 0xF9,
  37573. 0xF5, 0x26, 0xF0, 0x02, 0xBA, 0xAD, 0xC0, 0x3F,
  37574. 0xC1, 0x3E, 0x38, 0x13, 0x12, 0x19, 0x51, 0x3C,
  37575. 0x3E, 0xDE, 0x06, 0x16, 0x61, 0xE7, 0x4F, 0x60,
  37576. 0x3C, 0x4F, 0xCF, 0x79, 0x51, 0xC8, 0xE5, 0x2C,
  37577. 0x9C, 0x21, 0x3B, 0x0D, 0x22, 0xD9, 0x29, 0x36,
  37578. 0x63, 0xD6, 0x69, 0xA6, 0xB5, 0x8E, 0xD8, 0xFC,
  37579. 0xEF, 0xCF, 0x82, 0x49, 0xD7, 0xBB, 0x52, 0x98,
  37580. 0xF5, 0x57, 0x61, 0x44, 0x5B, 0x2B, 0x83, 0xCE,
  37581. 0x7F, 0x00, 0x5C, 0xB0, 0x42, 0x48, 0xAE, 0xC8,
  37582. 0xBD, 0xA2, 0x2F, 0xD2, 0xD4, 0x2A, 0xA7, 0x66,
  37583. 0x32, 0x20, 0x14, 0xEA, 0x03, 0x8C, 0xC3, 0x2C,
  37584. 0x55, 0xC8, 0xE4, 0xB9, 0xE2, 0x8E, 0xC9, 0x11,
  37585. 0x9F, 0x52, 0x73, 0x41, 0xE4, 0xF6, 0x6A, 0x03,
  37586. 0x51, 0x21, 0x07, 0x3B, 0x85, 0xDE, 0x67, 0x06,
  37587. 0xDA, 0x19, 0xE0, 0x83, 0x8A, 0x9F, 0x33, 0xB7,
  37588. 0x19, 0xA6, 0x8F, 0x03, 0x9B, 0x66, 0x4D, 0xC0,
  37589. 0x02, 0x65, 0x9E, 0xAB, 0xFC, 0x39, 0x86, 0x79,
  37590. 0xAA, 0x70, 0x09, 0xCE, 0x0C, 0xD0, 0x1C, 0xDA,
  37591. 0xFB, 0x6C, 0xD2, 0xA2, 0x6F, 0xE4, 0x10, 0x16,
  37592. 0x72, 0xC9, 0x8F, 0xF5, 0x8F, 0x7C, 0x47, 0xD5,
  37593. 0xBD, 0xA2, 0x90, 0x66, 0x53, 0xB3, 0xA6, 0xF9,
  37594. 0x65, 0x1F, 0x7A, 0x12, 0x1E, 0xA7, 0x7E, 0xA7,
  37595. 0x47, 0x23, 0xFA, 0xE5, 0xB8, 0x73, 0xF9, 0xBB,
  37596. 0x7B, 0x66, 0x4F, 0x0C, 0x8A, 0x93, 0x83, 0x1E,
  37597. 0xF9, 0xD5, 0x1C, 0x7C, 0xC1, 0xEF, 0x44, 0xAC,
  37598. 0x0E, 0x55, 0xA5, 0x5C, 0xA7, 0x6D, 0x13, 0x7F,
  37599. 0xE9, 0xB7, 0x5F, 0x40, 0x50, 0x9C, 0xEF, 0x15,
  37600. 0x6E, 0x5A, 0xD1, 0x8F, 0x9F, 0xB9, 0x99, 0x68,
  37601. 0x00, 0x08, 0xE5, 0x47, 0xD5, 0x5E, 0xEC, 0xD5,
  37602. 0xB4, 0xD1, 0xCB, 0x1D, 0x9F, 0x07, 0x6C, 0xEC,
  37603. 0x21, 0x50, 0x1C, 0x74, 0x02, 0x50, 0x9E, 0xCB,
  37604. 0x77, 0xAF, 0xB2, 0xCB, 0x9A, 0x61, 0x34, 0x0A,
  37605. 0x8B, 0xD1, 0x51, 0x4C, 0x6E, 0x71, 0xB4, 0xAA,
  37606. 0x45, 0xE4, 0x7E, 0xC3, 0x75, 0x12, 0x27, 0x1B,
  37607. 0x91, 0x1F, 0x8F, 0xB4, 0x6C, 0x90, 0x82, 0xC9,
  37608. 0xDF, 0x07, 0x20, 0x4A, 0xBB, 0x5A, 0x50, 0xE6,
  37609. 0xE3, 0x64, 0x7A, 0x8A, 0xD4, 0xD8, 0xD5, 0xD7,
  37610. 0xBF, 0xF1, 0x9C, 0x8A, 0x50, 0x93, 0x08, 0xBC,
  37611. 0xFB, 0x89, 0x55, 0x36, 0xD0, 0x45, 0xCA, 0x2B,
  37612. 0x97, 0xCB, 0x16, 0xA2, 0x9B, 0xB7, 0x18, 0x1C,
  37613. 0xAD, 0x05, 0x09, 0xDD, 0xB9, 0x17, 0x35, 0x02,
  37614. 0x8E, 0xBA, 0x8C, 0x31, 0xD7, 0x4B, 0xD2, 0x75,
  37615. 0xEA, 0xA6, 0x5B, 0x53, 0x40, 0xB3, 0xA4, 0x3F,
  37616. 0xBF, 0xE0, 0xB3, 0x06, 0x1D, 0x6B, 0xAE, 0x7E,
  37617. 0x75, 0xB7, 0x09, 0x8C, 0xDA, 0xBE, 0x91, 0xD4,
  37618. 0xB3, 0x1E, 0x36, 0xC9, 0xAA, 0x7A, 0x82, 0x98,
  37619. 0x86, 0x2A, 0xD6, 0x3C, 0x8F, 0xD2, 0x82, 0xE0,
  37620. 0x3B, 0x46, 0x0B, 0x3A, 0xB4, 0x64, 0xCE, 0x0F,
  37621. 0x27, 0xB1, 0xC3, 0xD1, 0x11, 0x55, 0xAC, 0xAA,
  37622. 0x01, 0x1E, 0xB9, 0xE2, 0xAE, 0x3E, 0x6D, 0xDA,
  37623. 0x07, 0xD6, 0xF4, 0x91, 0x73, 0x7C, 0xBC, 0xE9,
  37624. 0xB0, 0x5F, 0x9B, 0xC5, 0x6B, 0xE2, 0x0E, 0x8D,
  37625. 0x32, 0x6B, 0xA1, 0x32, 0xC5, 0x7F, 0xB2, 0x35,
  37626. 0x16, 0x11, 0x44, 0x51, 0x9C, 0xDF, 0x40, 0x56,
  37627. 0x0F, 0xBE, 0x27, 0x9B, 0xDE, 0x41, 0x1E, 0x11,
  37628. 0x25, 0x31, 0xF8, 0x26, 0xD6, 0xAB, 0x10, 0xD4,
  37629. 0x54, 0x73, 0x50, 0xAD, 0xD2, 0xA9, 0xDE, 0x8D,
  37630. 0x62, 0xC2, 0xAC, 0x82, 0xCA, 0xBE, 0x68, 0x15,
  37631. 0x64, 0x6F, 0x4D, 0xC9, 0x74, 0x2B, 0xB0, 0xC2,
  37632. 0xA3, 0xF7, 0x7E, 0xC7, 0xB4, 0x6C, 0x6B, 0x53,
  37633. 0x76, 0x05, 0xFA, 0x31, 0x79, 0x8C, 0xD8, 0x92,
  37634. 0x81, 0x22, 0x1A, 0x33, 0xDF, 0xB9, 0x79, 0x6E,
  37635. 0x64, 0x43, 0x05, 0x63, 0x03, 0x32, 0xC2, 0xCB,
  37636. 0x93, 0x14, 0x08, 0xAB, 0x48, 0x1A, 0x16, 0xD9,
  37637. 0x53, 0xF6, 0xBE, 0xAE, 0x38, 0x91, 0xD6, 0xD9,
  37638. 0xAC, 0x1F, 0xAB, 0x38, 0x22, 0x2D, 0x92, 0x71,
  37639. 0x87, 0x2D, 0x9D, 0x0C, 0xAD, 0xB9, 0x1A, 0xBE,
  37640. 0x9B, 0x4E, 0x26, 0x5F, 0x75, 0xC6, 0xE5, 0xE8,
  37641. 0x29, 0xE1, 0x46, 0xC3, 0xD8, 0xCE, 0x1E, 0x9D,
  37642. 0x12, 0xE0, 0xD1, 0x29, 0x80, 0x19, 0x57, 0xF4,
  37643. 0x6B, 0x0D, 0x2D, 0xBE, 0x1F, 0x74, 0x9B, 0x1D,
  37644. 0x08, 0xE2, 0x34, 0x5F, 0x62, 0x39, 0xA7, 0x31,
  37645. 0x34, 0x2E, 0xB7, 0x5B, 0x0C, 0xF1, 0xBF, 0x41,
  37646. 0x17, 0x49, 0xBC, 0x2C, 0xAF, 0x28, 0x10, 0xB7,
  37647. 0x88, 0xC6, 0xB7, 0x23, 0x8B, 0x4D, 0x3D, 0xA2,
  37648. 0xD6, 0x31, 0x5C, 0xE9, 0x54, 0x2E, 0x24, 0x40,
  37649. 0x4F, 0x14, 0x57, 0x55, 0xA3, 0x0A, 0xB8, 0x51,
  37650. 0xE4, 0x44, 0x58, 0x41, 0xBD, 0x33, 0xF7, 0x16,
  37651. 0xA5, 0x86, 0x88, 0x48, 0x88, 0xEC, 0xC6, 0xBC,
  37652. 0x64, 0x98, 0xAA, 0x32, 0x91, 0x9A, 0xE8, 0x1D,
  37653. 0x20, 0xC2, 0x69, 0x73, 0xC2, 0xBD, 0x54, 0x58,
  37654. 0x2A, 0x0F, 0x6A, 0xD9, 0x8A, 0xBF, 0xD2, 0x62,
  37655. 0x7E, 0x15, 0x69, 0x0A, 0x72, 0x7E, 0x69, 0xF5,
  37656. 0x81, 0xDD, 0x2A, 0x71, 0x27, 0x98, 0x2A, 0x90,
  37657. 0xE3, 0x3E, 0x2D, 0x4A, 0x03, 0xFE, 0x33, 0x91,
  37658. 0x42, 0xC7, 0xE4, 0x4C, 0x32, 0x6A, 0xC4, 0x6E,
  37659. 0xD3, 0x95, 0xA2, 0x25, 0xD3, 0x03, 0x33, 0x89,
  37660. 0x91, 0x73, 0x28, 0xB4, 0x53, 0x16, 0xB1, 0x58,
  37661. 0x5A, 0x01, 0xB2, 0xC3, 0x04, 0xB2, 0x94, 0x4E,
  37662. 0x90, 0x3A, 0xBB, 0xB3, 0xEC, 0x56, 0x19, 0x44,
  37663. 0x1C, 0xFC, 0x89, 0x65, 0xA4, 0x46, 0xDF, 0x75,
  37664. 0xDE, 0xFA, 0x80, 0xC6, 0xE1, 0x5A, 0xDB, 0xD5,
  37665. 0x06, 0xB7, 0xAB, 0x2D, 0xE1, 0x2D, 0xDA, 0x9B,
  37666. 0xC8, 0x14, 0x41, 0xCF, 0xC8, 0x90, 0x52, 0xE2,
  37667. 0xE5, 0x80, 0x8F, 0x71, 0x26, 0xC6, 0xFD, 0x3A,
  37668. 0xC6, 0xAC, 0x80, 0x81, 0x25, 0x8A, 0x84, 0xA0,
  37669. 0x9A, 0xE5, 0x0F, 0x6C, 0xD7, 0xCC, 0x0F, 0x4A,
  37670. 0xF3, 0x36, 0xFD, 0x1D, 0x64, 0x3E, 0x99, 0x07,
  37671. 0x99, 0x96, 0x26, 0x8C, 0x2D, 0x32, 0xD9, 0x09,
  37672. 0xF2, 0x2E, 0x35, 0x04, 0xF0, 0x7F, 0xBB, 0x56,
  37673. 0x31, 0x96, 0xD4, 0x31, 0x2F, 0xDD, 0xB9, 0x33,
  37674. 0x5D, 0x5C, 0x1D, 0x36, 0xE8, 0xC5, 0xEE, 0xA2,
  37675. 0x27, 0x8D, 0xBA, 0x23, 0xB9, 0x4D, 0x19, 0x3C,
  37676. 0x94, 0x7C, 0xC4, 0x1C, 0xA9, 0x93, 0xDC, 0x7D,
  37677. 0xB1, 0x39, 0x63, 0x40, 0xAD, 0x9C, 0x4F, 0xE6,
  37678. 0x87, 0xDD, 0x7B, 0x8D, 0x0C, 0x7A, 0x51, 0x20,
  37679. 0xAE, 0x02, 0x04, 0xF2, 0xC6, 0x65, 0xBD, 0x5F,
  37680. 0x47, 0x3D, 0x64, 0x4C, 0x7F, 0xF2, 0x6B, 0xFF,
  37681. 0xBA, 0x7A, 0x36, 0x98, 0x08, 0x30, 0x70, 0x21,
  37682. 0x28, 0xA7, 0xE6, 0x61, 0xD6, 0x77, 0xA0, 0x92,
  37683. 0xA3, 0x6E, 0x74, 0x28, 0xA4, 0x13, 0x9F, 0xB2,
  37684. 0x9B, 0x00, 0x95, 0xCC, 0x11, 0x08, 0x6F, 0x44,
  37685. 0x7D, 0x2A, 0x9E, 0xF6, 0xC9, 0xB1, 0x61, 0xF1,
  37686. 0x89, 0xC6, 0x29, 0x9E, 0x08, 0x4C, 0xB7, 0xAA,
  37687. 0x00, 0xFA, 0xF7, 0x87, 0x79, 0x7B, 0xFB, 0x06,
  37688. 0x9F, 0xBC, 0x08, 0x7F, 0xDE, 0x26, 0x25, 0x2A,
  37689. 0x16, 0x64, 0xF1, 0x9C, 0x5A, 0x8A, 0x22, 0xEC,
  37690. 0x5E, 0xE1, 0xAE, 0xB0, 0x76, 0x35, 0x7B, 0x7D,
  37691. 0xC3, 0x7E, 0x6B, 0x0F, 0x15, 0x20, 0xF9, 0x58,
  37692. 0xF7, 0x85, 0x1B, 0xAC, 0xB9, 0x2C, 0x89, 0xFD,
  37693. 0x11, 0x4A, 0x72, 0xFE, 0xAC, 0x54, 0x65, 0x2D,
  37694. 0x45, 0xB0, 0x9E, 0x1A, 0xE7, 0x65, 0x1A, 0xBD,
  37695. 0x16, 0x4B, 0xCD, 0x53, 0x7D, 0x58, 0xFA, 0x39,
  37696. 0xD3, 0xEC, 0x8A, 0xCD, 0xCD, 0xF9, 0x84, 0x25,
  37697. 0x00, 0x58, 0x62, 0xFA, 0x59, 0x69, 0x2D, 0xE1,
  37698. 0x62, 0xB7, 0x7E, 0x62, 0x97, 0xC6, 0x62, 0x33,
  37699. 0x34, 0x84, 0x08, 0xA8, 0xAB, 0x69, 0x5C, 0xE2,
  37700. 0xF2, 0x72, 0x8D, 0xB9, 0xFB, 0xE2, 0x7E, 0x95,
  37701. 0x89, 0x67, 0xEC, 0x59, 0x74, 0x76, 0x7C, 0x5A,
  37702. 0x66, 0x02, 0x30, 0x74, 0xB4, 0xA7, 0x1A, 0xFD,
  37703. 0x26, 0x4A, 0xD2, 0x89, 0x0E, 0x97, 0x0A, 0x1F,
  37704. 0x31, 0xD6, 0xE3, 0x31, 0x1B, 0x73, 0x6F, 0x9F,
  37705. 0x94, 0x88, 0x79, 0x3D, 0xDC, 0x88, 0xF2, 0x34,
  37706. 0x58, 0x06, 0x42, 0x54, 0xC8, 0x2A, 0x1D, 0x9E,
  37707. 0x59, 0xEA, 0xD2, 0xFC, 0xEC, 0x40, 0xB4, 0x30,
  37708. 0x68, 0x7C, 0x4B, 0x7E, 0x28, 0x96, 0x09, 0x26,
  37709. 0xAF, 0xCA, 0xCC, 0x9B, 0xD7, 0x56, 0xA7, 0x10,
  37710. 0x88, 0xC7, 0x84, 0x50, 0xE2, 0x0A, 0x2E, 0x98,
  37711. 0x0A, 0xED, 0xE9, 0xEB, 0xED, 0xFE, 0x7F, 0xAB,
  37712. 0xD6, 0xAB, 0xFE, 0x96, 0xF9, 0x34, 0xC4, 0xB0,
  37713. 0x2C, 0x01, 0xCA, 0x19, 0x4D, 0x01, 0xB7, 0x3C,
  37714. 0x25, 0xD5, 0x99, 0x70, 0x39, 0xD3, 0xFC, 0xD0,
  37715. 0xF0, 0x99, 0x52, 0x1F, 0x70, 0xCA, 0xEE, 0x69,
  37716. 0x11, 0x0A, 0xC1, 0xFC, 0x5A, 0x99, 0x91, 0x7A,
  37717. 0xD7, 0x52, 0xFC, 0x96, 0xAD, 0xFA, 0xD7, 0x18,
  37718. 0x6D, 0x0A, 0x7C, 0x9C, 0xFE, 0x56, 0x01, 0xC0,
  37719. 0x75, 0x14, 0xEA, 0x64, 0x48, 0xD6, 0x61, 0xC5,
  37720. 0x7A, 0xA2, 0x02, 0x42, 0x10, 0x3C, 0x42, 0x76,
  37721. 0xA0, 0x70, 0xA4, 0x89, 0xA4, 0xCB, 0x6B, 0xCA,
  37722. 0x0F, 0x9E, 0xCC, 0x43, 0x79, 0xFB, 0x22, 0x02,
  37723. 0x15, 0xFD, 0x91, 0xF8, 0x10, 0x19, 0xD5, 0xB0,
  37724. 0xAE, 0x61, 0x93, 0x58, 0xB5, 0x24, 0x68, 0xF2,
  37725. 0x72, 0xC1, 0x78, 0xE3, 0xA7, 0x4C, 0xF6, 0x77,
  37726. 0x5A, 0xA9, 0x24, 0xFE, 0x32, 0x9C, 0x31, 0x75,
  37727. 0xD9, 0xE4, 0xC3, 0xE2, 0x1A, 0xB9, 0xEC, 0x83,
  37728. 0x6E, 0xDC, 0x3A, 0xCA, 0xB2, 0xE3, 0x89, 0x1E,
  37729. 0xE8, 0xDE, 0xDA, 0x51, 0x5D, 0x39, 0xAF, 0x9B,
  37730. 0x8D, 0xDD, 0x0E, 0xE7, 0xB0, 0x16, 0x4F, 0x80,
  37731. 0x5C, 0x38, 0x35, 0xF6, 0xD2, 0xBA, 0xBD, 0xB3,
  37732. 0x0E, 0xAB, 0x47, 0x56, 0xE7, 0xEC, 0x7F, 0x82,
  37733. 0x9E, 0xCE, 0x01, 0xE8, 0xEA, 0xDF, 0xBB, 0xED,
  37734. 0x12, 0xFC, 0x28, 0x3B, 0x3D, 0x4C, 0x69, 0xF5,
  37735. 0x75, 0xE7, 0xF8, 0x04, 0x17, 0x68, 0x9F, 0xDF,
  37736. 0xCF, 0xC7, 0xBE, 0x27, 0xEE, 0x3B, 0x8C, 0xDF,
  37737. 0x57, 0xAA, 0xEB, 0xEC, 0x4A, 0x95, 0xB7, 0xE5,
  37738. 0xBB, 0x58, 0x5B, 0x85, 0x22, 0x7F, 0x7C, 0x32,
  37739. 0xBE, 0x30, 0xDB, 0x3E, 0x65, 0xE4, 0x2E, 0x30,
  37740. 0xDC, 0xF5, 0xA5, 0xFA, 0x07, 0x3D, 0xBA, 0x39,
  37741. 0x9D, 0x94, 0x2F, 0x22, 0x22, 0xAD, 0xB9, 0xB9,
  37742. 0x89, 0x81, 0x02, 0xAF, 0xE5, 0x43, 0x2E, 0xDC,
  37743. 0x7F, 0x04, 0xAE, 0x34, 0xA8, 0xFE, 0xC2, 0xD8,
  37744. 0x1C, 0xB4, 0x9A, 0x9A, 0x9B, 0x43, 0x81, 0x4C,
  37745. 0xE7, 0x1D, 0x97, 0xF7, 0x26, 0xE2, 0xB1, 0xE8,
  37746. 0xF6, 0x4B, 0x50, 0xE6, 0x5D, 0xFB, 0x48, 0x16,
  37747. 0xE1, 0x2E, 0x82, 0xA3, 0x19, 0x74, 0x84, 0xA4,
  37748. 0xE9, 0xBB, 0xA4, 0xD2, 0xD6, 0x9E, 0x3F, 0x19,
  37749. 0xD0, 0xB7, 0x5C, 0x21, 0xE2, 0xBF, 0xFE, 0x9F,
  37750. 0xC0, 0xC9, 0x8C, 0xF4, 0x8A, 0x3A, 0xAF, 0x08,
  37751. 0xD4, 0x67, 0xF7, 0x26, 0x87, 0xDF, 0x01, 0x78,
  37752. 0x17, 0x4B, 0x78, 0x97, 0xF7, 0x34, 0x34, 0x9B,
  37753. 0x18, 0x1E, 0xCA, 0x86, 0xA5, 0x98, 0xA0, 0xC5,
  37754. 0xE8, 0xC2, 0x59, 0x46, 0xF2, 0x4D, 0xC5, 0x57,
  37755. 0x2B, 0xD3, 0x24, 0xA4, 0x04, 0x58, 0xA7, 0x88,
  37756. 0xE5, 0x13, 0x7F, 0x3C, 0x7A, 0x7C, 0x97, 0xFC,
  37757. 0x9F, 0x12, 0xA3, 0xC4, 0x63, 0xA8, 0xFE, 0x94,
  37758. 0x49, 0x10, 0x1C, 0xCE, 0x96, 0x6D, 0x7C, 0x00,
  37759. 0x93, 0x23, 0x93, 0x29, 0x98, 0xD5, 0x6E, 0xF4,
  37760. 0x30, 0xC7, 0x3B, 0xC2, 0x4F, 0x5D, 0x95, 0xF7,
  37761. 0x37, 0x85, 0x8D, 0xDC, 0x4F, 0x32, 0xC0, 0x13
  37762. };
  37763. #endif
  37764. #ifndef WOLFSSL_NO_ML_KEM
  37765. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_ct[] = {
  37766. 0xc9, 0xbe, 0xad, 0x6b, 0x0c, 0x11, 0x14, 0x38,
  37767. 0x9b, 0xd4, 0x76, 0x1c, 0x73, 0xab, 0x90, 0x95,
  37768. 0xb5, 0x80, 0x9d, 0xaa, 0xc9, 0xf6, 0x59, 0xbb,
  37769. 0x56, 0x4a, 0xf2, 0x26, 0x17, 0x30, 0x52, 0xa4,
  37770. 0xa3, 0xe7, 0xf2, 0xe5, 0xfd, 0x47, 0xd2, 0xb0,
  37771. 0x2a, 0xae, 0xb5, 0x18, 0x9e, 0x06, 0xb9, 0xf4,
  37772. 0xae, 0x98, 0xb6, 0x19, 0xcb, 0x63, 0xef, 0xbd,
  37773. 0xf3, 0x98, 0x9a, 0x94, 0xb3, 0x6e, 0x8e, 0xa0,
  37774. 0xd7, 0x00, 0x63, 0x3b, 0x95, 0x0a, 0x0a, 0xe2,
  37775. 0xa7, 0x8e, 0xd9, 0x2e, 0x85, 0xc8, 0x5c, 0x70,
  37776. 0xe1, 0x3e, 0x62, 0x6f, 0xb2, 0x63, 0xfa, 0xc9,
  37777. 0x68, 0x15, 0x21, 0xc3, 0xab, 0x22, 0xfd, 0xab,
  37778. 0x29, 0x17, 0x3c, 0x96, 0x16, 0xa2, 0xb0, 0x37,
  37779. 0x08, 0x3f, 0xf7, 0xb2, 0xe0, 0x19, 0xb5, 0xbc,
  37780. 0xde, 0x06, 0x8f, 0xac, 0x25, 0x7e, 0xf8, 0xf1,
  37781. 0x27, 0x98, 0x41, 0x16, 0x93, 0xc1, 0xbd, 0xcc,
  37782. 0x65, 0x42, 0x09, 0x97, 0xa5, 0x13, 0xa8, 0xa6,
  37783. 0x95, 0x02, 0x62, 0x0b, 0xe8, 0xe4, 0xce, 0x73,
  37784. 0x62, 0xe4, 0x12, 0xa7, 0x6c, 0xf5, 0x1c, 0x1f,
  37785. 0x24, 0x33, 0xf1, 0xab, 0x64, 0xce, 0x0e, 0x5d,
  37786. 0x2f, 0x56, 0xd7, 0xc9, 0xad, 0xe9, 0x94, 0xd0,
  37787. 0xe3, 0x5d, 0x0a, 0xee, 0xf3, 0xac, 0x51, 0x5b,
  37788. 0x48, 0x24, 0x37, 0x66, 0x4d, 0x8c, 0x1d, 0x25,
  37789. 0xe5, 0xa5, 0x50, 0x7c, 0xf8, 0x0f, 0x97, 0x0d,
  37790. 0x3e, 0xa7, 0x22, 0x6a, 0xac, 0xdc, 0x45, 0x7c,
  37791. 0xbf, 0x88, 0xa0, 0x56, 0x0a, 0xa3, 0x5b, 0xb2,
  37792. 0xc5, 0xc4, 0x55, 0x86, 0x7e, 0x21, 0x59, 0x91,
  37793. 0x0a, 0x35, 0x81, 0x0b, 0xef, 0xe3, 0xaa, 0x10,
  37794. 0xeb, 0x04, 0xd8, 0xd5, 0x71, 0x47, 0xcb, 0x8f,
  37795. 0x66, 0xd2, 0xb0, 0x70, 0xba, 0xc4, 0x3d, 0x1f,
  37796. 0x1f, 0xfd, 0xd5, 0x7a, 0x93, 0x99, 0x95, 0x1f,
  37797. 0x64, 0x96, 0x57, 0x27, 0xbc, 0xb9, 0xf6, 0x6a,
  37798. 0xd4, 0x23, 0x09, 0xda, 0xfc, 0x79, 0x9c, 0x1c,
  37799. 0x54, 0x0a, 0xf1, 0xaf, 0x93, 0xef, 0xf6, 0x8a,
  37800. 0x86, 0xd6, 0x1f, 0x51, 0x15, 0xdb, 0x66, 0x2d,
  37801. 0xee, 0x7a, 0xc9, 0xa3, 0x62, 0x67, 0x77, 0x62,
  37802. 0xb6, 0xa1, 0x64, 0xa0, 0xfa, 0x0a, 0x4d, 0x85,
  37803. 0x9e, 0x4b, 0x8c, 0x8d, 0xbd, 0xb4, 0xe1, 0x83,
  37804. 0xf5, 0xe6, 0x80, 0x8f, 0xc5, 0x22, 0x29, 0x65,
  37805. 0x0c, 0xaf, 0x7c, 0xf3, 0xe1, 0x6d, 0xe3, 0xd8,
  37806. 0x95, 0xd1, 0x48, 0xc3, 0x54, 0x48, 0xab, 0x8c,
  37807. 0x27, 0x53, 0xc9, 0x83, 0x1b, 0x24, 0xbd, 0x49,
  37808. 0x21, 0x49, 0x7e, 0xaa, 0x19, 0x25, 0x65, 0xca,
  37809. 0xbf, 0xd8, 0x3c, 0x0c, 0x68, 0xdf, 0xe7, 0xd3,
  37810. 0x92, 0xab, 0xf5, 0xe5, 0xe6, 0xf8, 0x4b, 0xb9,
  37811. 0xf5, 0xaf, 0x4b, 0x71, 0x18, 0xc0, 0xb5, 0x58,
  37812. 0x10, 0x5f, 0x9c, 0x10, 0xc9, 0xb6, 0xd7, 0x06,
  37813. 0x82, 0xe1, 0xde, 0x6e, 0x06, 0x89, 0xd7, 0x10,
  37814. 0x6a, 0x63, 0x74, 0xbd, 0x34, 0xae, 0xd7, 0x22,
  37815. 0x9e, 0x6c, 0xb3, 0x56, 0xf2, 0xea, 0x65, 0xe6,
  37816. 0x80, 0xce, 0x7b, 0x1e, 0x2c, 0x37, 0x04, 0xe1,
  37817. 0x16, 0xa3, 0x85, 0x42, 0x82, 0x6e, 0x8a, 0x00,
  37818. 0x11, 0x41, 0xba, 0xf2, 0xe3, 0x4d, 0xe3, 0x7a,
  37819. 0x03, 0x04, 0x09, 0x86, 0xd4, 0xc0, 0xcd, 0x5d,
  37820. 0x57, 0xf0, 0x70, 0x1c, 0xe9, 0x30, 0x98, 0x6f,
  37821. 0xd9, 0x52, 0x5b, 0x58, 0xe2, 0xe5, 0x9f, 0x45,
  37822. 0xb8, 0xdd, 0x04, 0xc0, 0xf3, 0x5b, 0x0f, 0x47,
  37823. 0x97, 0x0c, 0xc6, 0x70, 0x79, 0x61, 0x8e, 0xb9,
  37824. 0xe6, 0xd9, 0x1e, 0x9b, 0x0f, 0x8c, 0x6d, 0x2e,
  37825. 0x16, 0x5c, 0xf4, 0x48, 0xa2, 0xc1, 0xeb, 0xf7,
  37826. 0x1b, 0x65, 0x37, 0xe0, 0xf3, 0x75, 0x18, 0x5d,
  37827. 0xfa, 0xfe, 0xf6, 0x98, 0xb6, 0x23, 0x9b, 0xb3,
  37828. 0x55, 0x80, 0xb3, 0x15, 0xbc, 0xb5, 0xed, 0x40,
  37829. 0x8c, 0x35, 0x7f, 0x19, 0x2d, 0xef, 0x89, 0xbc,
  37830. 0x1b, 0x75, 0xcd, 0xd6, 0xaa, 0xe8, 0xb5, 0xfa,
  37831. 0xf0, 0xc3, 0xe1, 0x38, 0x03, 0xf6, 0xbd, 0xfa,
  37832. 0x76, 0xfb, 0x40, 0x7f, 0xcb, 0xda, 0x79, 0x0c,
  37833. 0x32, 0x9b, 0x3e, 0xe4, 0x2f, 0xd3, 0xd3, 0xb0,
  37834. 0x3b, 0xd5, 0x00, 0x3f, 0x0b, 0xc4, 0x32, 0xf7,
  37835. 0xba, 0x39, 0x63, 0x11, 0x12, 0x45, 0x2d, 0xfd,
  37836. 0x12, 0x14, 0x04, 0x33, 0xff, 0x89, 0x80, 0xeb,
  37837. 0x6a, 0x52, 0x6b, 0xa8, 0x5e, 0xf9, 0x94, 0x77,
  37838. 0x37, 0x8b, 0x4d, 0xc7, 0x66, 0x35, 0xa5, 0xcd,
  37839. 0x50, 0x40, 0xe4, 0x3b, 0x8c, 0x1f, 0xe4, 0xee,
  37840. 0x5e, 0x15, 0x8e, 0x42, 0x3b, 0xfc, 0x0c, 0x89,
  37841. 0x3c, 0x1d, 0x56, 0x13, 0xbe, 0xd0, 0x8d, 0xa7,
  37842. 0x19, 0xc9, 0x07, 0x31, 0x84, 0xee, 0xb3, 0x6f,
  37843. 0xd3, 0x57, 0x38, 0x0f, 0xb1, 0x87, 0x3d, 0x8c,
  37844. 0xbd, 0x36, 0xe2, 0x25, 0x5e, 0x98, 0x5b, 0x1b,
  37845. 0x76, 0x81, 0x97, 0x43, 0xa6, 0x58, 0x4a, 0x9b,
  37846. 0x3a, 0x58, 0x09, 0x96, 0xc9, 0xc2, 0xee, 0xd9,
  37847. 0xbb, 0xbf, 0xff, 0x78, 0xa6, 0x20, 0x4b, 0x5e,
  37848. 0x5e, 0xea, 0xe5, 0xf4, 0xef, 0xd2, 0x66, 0x00,
  37849. 0x78, 0xb3, 0x7f, 0x07, 0x54, 0xab, 0x5d, 0xa8,
  37850. 0x62, 0xe6, 0x66, 0xb1, 0x45, 0xb5, 0xf2, 0x3f,
  37851. 0x3d, 0x09, 0x77, 0x79, 0x99, 0x29, 0xdf, 0xa2,
  37852. 0xae, 0xdd, 0xa5, 0x3d, 0x15, 0x2e, 0xda, 0x1d,
  37853. 0x0d, 0x0e, 0x4e, 0xa4, 0x3f, 0x6e, 0xd8, 0x89,
  37854. 0xbb, 0x96, 0x5e, 0xef, 0xe0, 0xa7, 0xc6, 0x85,
  37855. 0xbb, 0x36, 0x77, 0x0e, 0xaa, 0x87, 0x42, 0x42,
  37856. 0xc0, 0xe2, 0x29, 0xcf, 0x6c, 0xe5, 0x6d, 0xef,
  37857. 0xa5, 0xae, 0xae, 0x64, 0xd0, 0xc4, 0x0d, 0xda,
  37858. 0x8a, 0xa2, 0x6e, 0xae, 0xb3, 0x14, 0x58, 0xf0,
  37859. 0x70, 0xa3, 0xbc, 0x72, 0xe1, 0x61, 0x9e, 0xe9,
  37860. 0xb5, 0xf6, 0x42, 0x29, 0x1c, 0x56, 0xdf, 0x5b,
  37861. 0x7e, 0x43, 0xdb, 0x6c, 0x80, 0x2f, 0xc7, 0x4f,
  37862. 0x4f, 0x3f, 0x9b, 0x5c, 0x0d, 0x35, 0x5c, 0x3a,
  37863. 0xae, 0x52, 0x0a, 0xa3, 0x12, 0x29, 0xd1, 0x2f,
  37864. 0x3e, 0x7c, 0xc5, 0xd4, 0x8e, 0x69, 0x11, 0x91,
  37865. 0xa3, 0x6b, 0x28, 0x37, 0x65, 0xf4, 0x13, 0x3f,
  37866. 0x0f, 0xf1, 0xfe, 0x2f, 0x01, 0xc6, 0x64, 0x8b,
  37867. 0x27, 0x98, 0xa7, 0x4e, 0xb5, 0xd8, 0x42, 0xa2,
  37868. 0x48, 0xf5, 0x24, 0xa7, 0xe7, 0xf8, 0x97, 0x42,
  37869. 0x11, 0x29, 0x7b, 0x44, 0xf0, 0xdd, 0x19, 0xf3,
  37870. 0x86, 0xe8, 0x6b, 0xe6, 0xba, 0x78, 0x2d, 0xe7,
  37871. 0x7f, 0xde, 0x88, 0x72, 0x26, 0xf3, 0x7a, 0x1c,
  37872. 0x77, 0xbc, 0x5e, 0xdd, 0xee, 0xe5, 0xbf, 0x46,
  37873. 0xb6, 0x7f, 0xb7, 0x47, 0x8d, 0x55, 0x98, 0x65,
  37874. 0xf2, 0x62, 0xca, 0xa8, 0x4d, 0x64, 0xa8, 0xce,
  37875. 0x59, 0xe4, 0xdf, 0x08, 0x18, 0xe1, 0x48, 0x61,
  37876. 0x52, 0x6a, 0xcd, 0x34, 0x83, 0x60, 0x0f, 0x3d,
  37877. 0xae, 0x79, 0x59, 0xd3, 0x5d, 0x81, 0x81, 0xca,
  37878. 0x6a, 0x81, 0xce, 0x79, 0x1b, 0xe0, 0x07, 0x52,
  37879. 0xda, 0x77, 0x59, 0x44, 0x6a, 0x2c, 0xfb, 0xe0,
  37880. 0x0b, 0x82, 0x48, 0xb9, 0x34, 0x91, 0xde, 0xbd,
  37881. 0x52, 0x02, 0x20, 0xb7, 0x55, 0x41, 0x6d, 0x2f,
  37882. 0xc6, 0xb7, 0xc8, 0xaf, 0x2f, 0xf7, 0x5e, 0x5b,
  37883. 0xcb, 0xb8, 0xe7, 0x53, 0x73, 0x80, 0xa5, 0x72,
  37884. 0x1c, 0x77, 0x48, 0x49, 0x57, 0xa6, 0x92, 0x71,
  37885. 0xd8, 0xba, 0xfc, 0xe0, 0xf1, 0x66, 0x73, 0x5f,
  37886. 0xf8, 0x69, 0x23, 0x2d, 0xe5, 0xd3, 0x81, 0xaf,
  37887. 0xbf, 0x0e, 0x44, 0xd6, 0x91, 0x72, 0xb7, 0x9a,
  37888. 0x35, 0x19, 0x19, 0x49, 0xde, 0x09, 0x70, 0x3b,
  37889. 0x94, 0x22, 0x2b, 0x13, 0xc3, 0x85, 0xc6, 0x08,
  37890. 0x1e, 0x6d, 0x2e, 0xde, 0x1e, 0x57, 0xfe, 0x18,
  37891. 0x4e, 0xf8, 0xf6, 0x01, 0x96, 0xb9, 0xa3, 0xa7,
  37892. 0xb7, 0xef, 0xf7, 0x49, 0x71, 0x91, 0xca, 0x87,
  37893. 0x41, 0xb5, 0xa0, 0x1e, 0x79, 0xcb, 0x69, 0xa6,
  37894. 0x11, 0x42, 0xe6, 0xf5, 0xd0, 0x80, 0xfb, 0xb3,
  37895. 0xe5, 0x66, 0xf7, 0x9e, 0x14, 0x6f, 0x75, 0xc8,
  37896. 0xa1, 0x09, 0x78, 0x60, 0x84, 0x1b, 0x47, 0x47,
  37897. 0xdf, 0x60, 0x4d, 0xba, 0x95, 0x4e, 0x4a, 0x8d,
  37898. 0x9e, 0x0d, 0xcc, 0xc1, 0xf6, 0x09, 0xd0, 0x5c,
  37899. 0xf8, 0xd3, 0x12, 0x19, 0xec, 0xd6, 0x0c, 0x31,
  37900. 0x2d, 0xe6, 0x84, 0x55, 0x2f, 0x09, 0x22, 0x7c,
  37901. 0xb8, 0x29, 0x29, 0x1c, 0x64, 0x57, 0x32, 0xc5,
  37902. 0xf5, 0xd4, 0xd7, 0x11, 0x63, 0x9f, 0x42, 0xa2,
  37903. 0x30, 0x80, 0xaa, 0x34, 0xfe, 0x14, 0x20, 0xf2,
  37904. 0x19, 0xbd, 0x6b, 0xcf, 0x4e, 0x3b, 0x29, 0xb9,
  37905. 0xd0, 0x22, 0x93, 0xb2, 0xda, 0x81, 0x38, 0x3e,
  37906. 0x0a, 0x51, 0xd2, 0xbb, 0x18, 0x6c, 0x7b, 0x0a,
  37907. 0x21, 0x1a, 0x0c, 0xd6, 0x3a, 0xcb, 0xfc, 0x02,
  37908. 0x10, 0x40, 0x1e, 0x98, 0x5d, 0x43, 0x6b, 0x38,
  37909. 0x03, 0xd5, 0x60, 0x1c, 0x24, 0x13, 0x6a, 0xfd,
  37910. 0x15, 0x62, 0x52, 0x2e, 0x45, 0xb4, 0x57, 0xcb,
  37911. 0x43, 0x91, 0x78, 0xbe, 0x4a, 0x87, 0xcc, 0xe4,
  37912. 0x03, 0x46, 0xd3, 0x4a, 0xe0, 0xf3, 0xc3, 0x91,
  37913. 0x03, 0xc8, 0xa3, 0xeb, 0xc9, 0xc8, 0x6c, 0x8d,
  37914. 0xb8, 0xfc, 0x55, 0x61, 0xeb, 0x0f, 0x3a, 0x14,
  37915. 0x3d, 0x4e, 0x9f, 0xe9, 0x3a, 0x5c, 0xba, 0x6f,
  37916. 0x6f, 0xca, 0xe5, 0x65, 0x0d, 0x3f, 0x43, 0xd2,
  37917. 0x66, 0x8a, 0x59, 0x56, 0xc9, 0x22, 0x89, 0x3b,
  37918. 0x81, 0x66, 0x47, 0xde, 0xd0, 0xaf, 0xc0, 0x52,
  37919. 0xa6, 0xc3, 0xd9, 0xd0, 0x1a, 0x3d, 0x3a, 0xf0,
  37920. 0xf1, 0xba, 0x80, 0x7f, 0xf1, 0x04, 0x91, 0xe1,
  37921. 0x31, 0xdc, 0x15, 0xe1, 0x65, 0xcf, 0xd0, 0x65,
  37922. 0x0a, 0x1f, 0x2c, 0x31, 0x3d, 0x79, 0x56, 0x14,
  37923. 0x1e, 0xdc, 0xc6, 0x1c, 0xb9, 0x0e, 0x9e, 0x7a,
  37924. 0xbf, 0x2f, 0xe3, 0x5f, 0xc9, 0xdc, 0x1b, 0xde,
  37925. 0x88, 0x93, 0x9f, 0xa1, 0x1f, 0x7b, 0xbe, 0x3e,
  37926. 0xb4, 0xd8, 0xff, 0xa6, 0x43, 0xb0, 0x74, 0xd7,
  37927. 0x4f, 0x45, 0x11, 0x35, 0x86, 0xe9, 0xbb, 0x12,
  37928. 0x06, 0x00, 0x03, 0xd7, 0x19, 0x41, 0xf2, 0xda,
  37929. 0x09, 0x8d, 0xc0, 0xe9, 0x6c, 0xad, 0x32, 0x55,
  37930. 0xcf, 0x32, 0x8e, 0xa2, 0xd3, 0x30, 0x8c, 0x1f,
  37931. 0x45, 0x85, 0xe8, 0x9c, 0x61, 0x3c, 0x42, 0x6b,
  37932. 0x7e, 0x79, 0x8e, 0x1e, 0xc4, 0xe9, 0x8f, 0xe6,
  37933. 0xc7, 0x1e, 0x74, 0x91, 0xf5, 0xec, 0xa0, 0xcd,
  37934. 0x05, 0x11, 0x58, 0x61, 0xbd, 0x16, 0x0e, 0x3f,
  37935. 0xe7, 0x3a, 0x58, 0xa0, 0x26, 0xba, 0x53, 0x8e,
  37936. 0x0e, 0x25, 0x6b, 0x92, 0xf1, 0xd7, 0xa2, 0x49,
  37937. 0x75, 0x70, 0x59, 0x48, 0x56, 0x86, 0x0f, 0xfd,
  37938. 0x06, 0xb6, 0x01, 0xac, 0x57, 0x55, 0x92, 0xf4,
  37939. 0xac, 0x61, 0x2b, 0x5d, 0xe7, 0x86, 0x60, 0x42,
  37940. 0x12, 0x3e, 0xbc, 0x60, 0xc5, 0x57, 0x68, 0xe3,
  37941. 0xa7, 0x60, 0x0a, 0x32, 0x60, 0x55, 0x1f, 0x2b,
  37942. 0xea, 0x22, 0xbb, 0xf6, 0xb6, 0xc8, 0x24, 0x6e,
  37943. 0x80, 0xf9, 0x12, 0x5c, 0x4b, 0xb9, 0xdb, 0x35,
  37944. 0x4d, 0xd6, 0x4a, 0xe6, 0x95, 0xc1, 0x5f, 0x50,
  37945. 0x71, 0xf4, 0xab, 0xb9, 0x63, 0x92, 0x07, 0xca,
  37946. 0xc7, 0x33, 0x1b, 0x31, 0x0f, 0x69, 0xa0, 0x5f,
  37947. 0x54, 0xb9, 0x95, 0xde, 0x52, 0x9a, 0x02, 0x3f,
  37948. 0x03, 0x3b, 0x05, 0x5d, 0xb9, 0x52, 0x87, 0xa1,
  37949. 0x4b, 0xa3, 0x0a, 0x7c, 0xc5, 0x26, 0xbb, 0x72,
  37950. 0x4c, 0x41, 0x7f, 0xba, 0x29, 0x06, 0x36, 0xa9,
  37951. 0x96, 0xf2, 0x86, 0xe3, 0xe9, 0xe9, 0x39, 0xe4,
  37952. 0xfe, 0x1c, 0x39, 0x8b, 0x5c, 0x65, 0x99, 0x95,
  37953. 0x9d, 0x0b, 0x44, 0x45, 0xa3, 0x27, 0xec, 0x46,
  37954. 0x9a, 0x16, 0x53, 0xcf, 0xae, 0xa7, 0x55, 0x2c,
  37955. 0xec, 0xec, 0x08, 0x5c, 0xca, 0xa6, 0x89, 0x38,
  37956. 0xae, 0x4a, 0xc3, 0xc4, 0x24, 0xf7, 0xe4, 0x80,
  37957. 0x43, 0x9e, 0xbd, 0x2c, 0x99, 0x2b, 0x5f, 0x6f,
  37958. 0x95, 0xec, 0x24, 0x4b, 0x65, 0x7d, 0xbd, 0xea,
  37959. 0xa9, 0xae, 0x11, 0x0a, 0xaf, 0x4d, 0x68, 0xbf,
  37960. 0x4e, 0x27, 0x41, 0x0d, 0x43, 0xce, 0xef, 0x3e,
  37961. 0x88, 0xe9, 0xc7, 0x17, 0xdd, 0x44, 0xc9, 0xee
  37962. };
  37963. #endif
  37964. #ifdef WOLFSSL_KYBER_ORIGINAL
  37965. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ss[] = {
  37966. 0xB1, 0x0F, 0x73, 0x94, 0x92, 0x6A, 0xD3, 0xB4,
  37967. 0x9C, 0x5D, 0x62, 0xD5, 0xAE, 0xB5, 0x31, 0xD5,
  37968. 0x75, 0x75, 0x38, 0xBC, 0xC0, 0xDA, 0x9E, 0x55,
  37969. 0x0D, 0x43, 0x8F, 0x1B, 0x61, 0xBD, 0x74, 0x19
  37970. };
  37971. #endif
  37972. #ifndef WOLFSSL_NO_ML_KEM
  37973. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_ss[] = {
  37974. 0x48, 0x9d, 0xd1, 0xe9, 0xc2, 0xbe, 0x4a, 0xf3,
  37975. 0x48, 0x2b, 0xdb, 0x35, 0xbb, 0x26, 0xce, 0x76,
  37976. 0x0e, 0x6e, 0x41, 0x4d, 0xa6, 0xec, 0xbe, 0x48,
  37977. 0x99, 0x85, 0x74, 0x8a, 0x82, 0x5f, 0x1c, 0xd6
  37978. };
  37979. #endif
  37980. #ifdef WOLFSSL_SMALL_STACK
  37981. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37982. DYNAMIC_TYPE_TMP_BUFFER);
  37983. priv = (byte *)XMALLOC(KYBER1024_PRIVATE_KEY_SIZE, HEAP_HINT,
  37984. DYNAMIC_TYPE_TMP_BUFFER);
  37985. pub = (byte *)XMALLOC(KYBER1024_PUBLIC_KEY_SIZE, HEAP_HINT,
  37986. DYNAMIC_TYPE_TMP_BUFFER);
  37987. ct = (byte *)XMALLOC(KYBER1024_CIPHER_TEXT_SIZE, HEAP_HINT,
  37988. DYNAMIC_TYPE_TMP_BUFFER);
  37989. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37990. DYNAMIC_TYPE_TMP_BUFFER);
  37991. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37992. DYNAMIC_TYPE_TMP_BUFFER);
  37993. if (! (key && priv && pub && ct && ss && ss_dec))
  37994. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37995. #endif
  37996. #ifdef WOLFSSL_KYBER_ORIGINAL
  37997. ret = wc_KyberKey_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
  37998. if (ret != 0)
  37999. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38000. else
  38001. key_inited = 1;
  38002. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  38003. sizeof(kyber1024_rand));
  38004. if (ret != 0)
  38005. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38006. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
  38007. if (ret != 0)
  38008. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38009. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
  38010. if (ret != 0)
  38011. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38012. if (XMEMCMP(pub, kyber1024_pk, sizeof(kyber1024_pk)) != 0)
  38013. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38014. if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0)
  38015. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38016. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  38017. sizeof(kyber1024enc_rand));
  38018. if (ret != 0)
  38019. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38020. if (XMEMCMP(ct, kyber1024_ct, sizeof(kyber1024_ct)) != 0)
  38021. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38022. if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  38023. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38024. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
  38025. if (ret != 0)
  38026. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38027. if (XMEMCMP(ss_dec, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  38028. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38029. #endif
  38030. #ifndef WOLFSSL_NO_ML_KEM
  38031. ret = wc_KyberKey_Init(WC_ML_KEM_1024, key, HEAP_HINT, INVALID_DEVID);
  38032. if (ret != 0)
  38033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38034. else
  38035. key_inited = 1;
  38036. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  38037. sizeof(kyber1024_rand));
  38038. if (ret != 0)
  38039. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38040. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE);
  38041. if (ret != 0)
  38042. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38043. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  38044. WC_ML_KEM_MAX_PRIVATE_KEY_SIZE);
  38045. if (ret != 0)
  38046. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38047. if (XMEMCMP(pub, ml_kem_1024_pk, sizeof(ml_kem_1024_pk)) != 0)
  38048. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38049. if (XMEMCMP(priv, ml_kem_1024_sk, sizeof(ml_kem_1024_sk)) != 0)
  38050. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38051. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  38052. sizeof(kyber1024enc_rand));
  38053. if (ret != 0)
  38054. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38055. if (XMEMCMP(ct, ml_kem_1024_ct, sizeof(ml_kem_1024_ct)) != 0)
  38056. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38057. if (XMEMCMP(ss, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
  38058. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38059. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_1024_ct));
  38060. if (ret != 0)
  38061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38062. if (XMEMCMP(ss_dec, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
  38063. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38064. #endif
  38065. out:
  38066. if (key_inited)
  38067. wc_KyberKey_Free(key);
  38068. #ifdef WOLFSSL_SMALL_STACK
  38069. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38070. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38071. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38072. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38073. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38074. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38075. #endif
  38076. return ret;
  38077. }
  38078. #endif /* WOLFSSL_KYBER1024 */
  38079. #endif /* WOLFSSL_WC_KYBER */
  38080. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
  38081. {
  38082. wc_test_ret_t ret;
  38083. WC_RNG rng;
  38084. int i;
  38085. #ifdef WOLFSSL_SMALL_STACK
  38086. KyberKey *key = NULL;
  38087. byte *priv = NULL;
  38088. byte *pub = NULL;
  38089. byte *priv2 = NULL;
  38090. byte *pub2 = NULL;
  38091. byte *ct = NULL;
  38092. byte *ss = NULL;
  38093. byte *ss_dec = NULL;
  38094. #else
  38095. KyberKey key[1];
  38096. byte priv[KYBER_MAX_PRIVATE_KEY_SIZE];
  38097. byte pub[KYBER_MAX_PUBLIC_KEY_SIZE];
  38098. byte priv2[KYBER_MAX_PRIVATE_KEY_SIZE];
  38099. byte pub2[KYBER_MAX_PUBLIC_KEY_SIZE];
  38100. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  38101. byte ss[KYBER_SS_SZ];
  38102. byte ss_dec[KYBER_SS_SZ];
  38103. #endif
  38104. int key_inited = 0;
  38105. static const int testData[][4] = {
  38106. #ifndef WOLFSSL_NO_ML_KEM
  38107. #ifdef WOLFSSL_WC_ML_KEM_512
  38108. { WC_ML_KEM_512, WC_ML_KEM_512_PRIVATE_KEY_SIZE,
  38109. WC_ML_KEM_512_PUBLIC_KEY_SIZE, WC_ML_KEM_512_CIPHER_TEXT_SIZE },
  38110. #endif
  38111. #ifdef WOLFSSL_WC_ML_KEM_768
  38112. { WC_ML_KEM_768, WC_ML_KEM_768_PRIVATE_KEY_SIZE,
  38113. WC_ML_KEM_768_PUBLIC_KEY_SIZE, WC_ML_KEM_768_CIPHER_TEXT_SIZE },
  38114. #endif
  38115. #ifdef WOLFSSL_WC_ML_KEM_1024
  38116. { WC_ML_KEM_1024, WC_ML_KEM_1024_PRIVATE_KEY_SIZE,
  38117. WC_ML_KEM_1024_PUBLIC_KEY_SIZE, WC_ML_KEM_1024_CIPHER_TEXT_SIZE },
  38118. #endif
  38119. #endif
  38120. #ifdef WOLFSSL_KYBER_ORIGINAL
  38121. #ifdef WOLFSSL_KYBER512
  38122. { KYBER512, KYBER512_PRIVATE_KEY_SIZE, KYBER512_PUBLIC_KEY_SIZE,
  38123. KYBER512_CIPHER_TEXT_SIZE },
  38124. #endif
  38125. #ifdef WOLFSSL_KYBER768
  38126. { KYBER768, KYBER768_PRIVATE_KEY_SIZE, KYBER768_PUBLIC_KEY_SIZE,
  38127. KYBER768_CIPHER_TEXT_SIZE },
  38128. #endif
  38129. #ifdef WOLFSSL_KYBER1024
  38130. { KYBER1024, KYBER1024_PRIVATE_KEY_SIZE, KYBER1024_PUBLIC_KEY_SIZE,
  38131. KYBER1024_CIPHER_TEXT_SIZE },
  38132. #endif
  38133. #endif
  38134. };
  38135. WOLFSSL_ENTER("kyber_test");
  38136. #ifdef WOLFSSL_SMALL_STACK
  38137. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  38138. DYNAMIC_TYPE_TMP_BUFFER);
  38139. priv = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  38140. DYNAMIC_TYPE_TMP_BUFFER);
  38141. pub = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  38142. DYNAMIC_TYPE_TMP_BUFFER);
  38143. priv2 = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  38144. DYNAMIC_TYPE_TMP_BUFFER);
  38145. pub2 = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  38146. DYNAMIC_TYPE_TMP_BUFFER);
  38147. ct = (byte *)XMALLOC(KYBER_MAX_CIPHER_TEXT_SIZE, HEAP_HINT,
  38148. DYNAMIC_TYPE_TMP_BUFFER);
  38149. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  38150. DYNAMIC_TYPE_TMP_BUFFER);
  38151. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  38152. DYNAMIC_TYPE_TMP_BUFFER);
  38153. if (! (key && priv && pub && priv2 && pub2 && ct && ss && ss_dec))
  38154. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38155. #endif
  38156. #ifndef HAVE_FIPS
  38157. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  38158. #else
  38159. ret = wc_InitRng(&rng);
  38160. #endif
  38161. if (ret != 0)
  38162. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38163. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  38164. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38165. if (ret != 0)
  38166. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38167. else
  38168. key_inited = 1;
  38169. ret = wc_KyberKey_MakeKey(key, &rng);
  38170. if (ret != 0)
  38171. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38172. ret = wc_KyberKey_EncodePublicKey(key, pub, testData[i][2]);
  38173. if (ret != 0)
  38174. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38175. ret = wc_KyberKey_EncodePrivateKey(key, priv, testData[i][1]);
  38176. if (ret != 0)
  38177. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38178. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38179. if (ret != 0)
  38180. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38181. ret = wc_KyberKey_DecodePublicKey(key, pub, testData[i][2]);
  38182. if (ret != 0)
  38183. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38184. ret = wc_KyberKey_Encapsulate(key, ct, ss, &rng);
  38185. if (ret != 0)
  38186. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38187. ret = wc_KyberKey_EncodePublicKey(key, pub2, testData[i][2]);
  38188. if (ret != 0)
  38189. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38190. if (XMEMCMP(pub, pub2, testData[i][2]) != 0)
  38191. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38192. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38193. if (ret != 0)
  38194. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38195. ret = wc_KyberKey_DecodePrivateKey(key, priv, testData[i][1]);
  38196. if (ret != 0)
  38197. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38198. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, testData[i][3]);
  38199. if (ret != 0)
  38200. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38201. if (XMEMCMP(ss, ss_dec, KYBER_SS_SZ) != 0)
  38202. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38203. ret = wc_KyberKey_EncodePrivateKey(key, priv2, testData[i][1]);
  38204. if (ret != 0)
  38205. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38206. if (XMEMCMP(priv, priv2, testData[i][2]) != 0)
  38207. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38208. }
  38209. wc_FreeRng(&rng);
  38210. #ifdef WOLFSSL_WC_KYBER
  38211. #if !defined(WOLFSSL_NO_KYBER512) && !defined(WOLFSSL_NO_ML_KEM_512)
  38212. ret = kyber512_kat();
  38213. if (ret != 0)
  38214. goto out;
  38215. #endif
  38216. #if !defined(WOLFSSL_NO_KYBER768) && !defined(WOLFSSL_NO_ML_KEM_768)
  38217. ret = kyber768_kat();
  38218. if (ret != 0)
  38219. goto out;
  38220. #endif
  38221. #if !defined(WOLFSSL_NO_KYBER1024) && !defined(WOLFSSL_NO_ML_KEM_1024)
  38222. ret = kyber1024_kat();
  38223. if (ret != 0)
  38224. goto out;
  38225. #endif
  38226. #endif /* WOLFSSL_WC_KYBER */
  38227. out:
  38228. if (key_inited)
  38229. wc_KyberKey_Free(key);
  38230. #ifdef WOLFSSL_SMALL_STACK
  38231. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38232. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38233. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38234. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38235. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38236. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38237. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38238. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38239. #endif
  38240. return ret;
  38241. }
  38242. #endif /* WOLFSSL_HAVE_KYBER */
  38243. #ifdef HAVE_DILITHIUM
  38244. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  38245. static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
  38246. word32 pubKeyLen, const byte* sig, word32 sigLen)
  38247. {
  38248. byte msg[512];
  38249. dilithium_key* key;
  38250. byte * pubExported = NULL;
  38251. wc_test_ret_t ret;
  38252. int i;
  38253. int res = 0;
  38254. word32 lenExported = pubKeyLen;
  38255. int n_diff = 0;
  38256. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  38257. DYNAMIC_TYPE_TMP_BUFFER);
  38258. if (key == NULL) {
  38259. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38260. }
  38261. pubExported = (byte*)XMALLOC(pubKeyLen, HEAP_HINT,
  38262. DYNAMIC_TYPE_TMP_BUFFER);
  38263. if (pubExported == NULL) {
  38264. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38265. }
  38266. /* make dummy msg */
  38267. for (i = 0; i < (int)sizeof(msg); i++) {
  38268. msg[i] = (byte)i;
  38269. }
  38270. ret = wc_dilithium_init(key);
  38271. if (ret != 0) {
  38272. ret = WC_TEST_RET_ENC_EC(ret);
  38273. return ret;
  38274. }
  38275. ret = wc_dilithium_set_level(key, param);
  38276. if (ret != 0)
  38277. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38278. ret = wc_dilithium_import_public(pubKey, pubKeyLen, key);
  38279. if (ret != 0)
  38280. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38281. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38282. if (param >= WC_ML_DSA_DRAFT) {
  38283. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg),
  38284. &res, key);
  38285. }
  38286. else
  38287. #endif
  38288. {
  38289. ret = wc_dilithium_verify_ctx_msg(sig, sigLen, NULL, 0, msg,
  38290. (word32)sizeof(msg), &res, key);
  38291. }
  38292. if (ret != 0)
  38293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38294. if (res != 1)
  38295. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  38296. /* Now test the export pub raw API, verify we recover the original pub. */
  38297. ret = wc_dilithium_export_public(key, pubExported, &lenExported);
  38298. if (ret != 0) {
  38299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38300. }
  38301. if (lenExported <= 0 || lenExported != pubKeyLen) {
  38302. ERROR_OUT(WC_TEST_RET_ENC_EC(lenExported), out);
  38303. }
  38304. n_diff = XMEMCMP(pubExported, pubKey, pubKeyLen);
  38305. if (n_diff) {
  38306. ERROR_OUT(WC_TEST_RET_ENC_EC(n_diff), out);
  38307. }
  38308. out:
  38309. wc_dilithium_free(key);
  38310. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38311. XFREE(pubExported, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38312. return ret;
  38313. }
  38314. #ifndef WOLFSSL_NO_ML_DSA_44
  38315. static wc_test_ret_t dilithium_param_44_vfy_test(void)
  38316. {
  38317. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_pub_key[] = {
  38318. 0xd8, 0xac, 0xaf, 0xd8, 0x2e, 0x14, 0x23, 0x78, 0xf7, 0x0d, 0x9a, 0x04,
  38319. 0x2b, 0x92, 0x48, 0x67, 0x60, 0x55, 0x34, 0xd9, 0xac, 0x0b, 0xc4, 0x1f,
  38320. 0x46, 0xe8, 0x85, 0xb9, 0x2e, 0x1b, 0x10, 0x3a, 0x75, 0x7a, 0xc2, 0xbc,
  38321. 0x76, 0xf0, 0x6d, 0x05, 0xa4, 0x78, 0x48, 0x84, 0x26, 0x69, 0xbd, 0x26,
  38322. 0x1d, 0x73, 0x60, 0xaa, 0x57, 0x9d, 0x8c, 0x66, 0xb1, 0x19, 0xea, 0x11,
  38323. 0xff, 0xbb, 0xf6, 0xeb, 0x26, 0x26, 0xac, 0x78, 0x74, 0x46, 0x6d, 0x51,
  38324. 0x6e, 0x92, 0xdf, 0x6a, 0x98, 0x41, 0xe9, 0x10, 0xf2, 0xcc, 0xa8, 0x7a,
  38325. 0x50, 0xdb, 0x1f, 0x4c, 0x42, 0x19, 0xd5, 0xbc, 0x76, 0x20, 0x6f, 0x2f,
  38326. 0xbf, 0xc2, 0xc9, 0x1b, 0x02, 0xb5, 0xb1, 0x09, 0x46, 0x06, 0x87, 0x02,
  38327. 0xac, 0x3d, 0xcf, 0xc3, 0xa5, 0x1b, 0xf0, 0xce, 0xd4, 0x9e, 0x84, 0x34,
  38328. 0x3c, 0x24, 0x7d, 0x89, 0xf3, 0xbf, 0x9c, 0x18, 0x9d, 0x1b, 0x1d, 0xd4,
  38329. 0xf6, 0xda, 0xc9, 0xa4, 0x14, 0xc4, 0x6b, 0xd7, 0x05, 0x6d, 0xed, 0x54,
  38330. 0x42, 0x6b, 0x5f, 0x6d, 0x1e, 0xda, 0x6b, 0x47, 0x70, 0xe5, 0x4e, 0xe7,
  38331. 0x25, 0x06, 0xf8, 0x28, 0x24, 0x34, 0xd6, 0xe5, 0xbe, 0xc5, 0x4f, 0x9e,
  38332. 0x5d, 0x33, 0xfc, 0xef, 0xe4, 0xe9, 0x55, 0x67, 0x93, 0x1f, 0x2e, 0x11,
  38333. 0x3a, 0x2e, 0xf2, 0xbb, 0x82, 0x09, 0x8d, 0xb2, 0x09, 0xf3, 0x2f, 0xef,
  38334. 0x6f, 0x38, 0xc6, 0x56, 0xf2, 0x23, 0x08, 0x63, 0x99, 0x7f, 0x4e, 0xc0,
  38335. 0x9d, 0x08, 0x9d, 0xa1, 0x59, 0x6e, 0xe1, 0x00, 0x2c, 0x99, 0xec, 0x83,
  38336. 0x2f, 0x12, 0x97, 0x2f, 0x75, 0x04, 0x67, 0x44, 0xb5, 0x95, 0xce, 0xc6,
  38337. 0x3e, 0x7a, 0x10, 0x77, 0x5e, 0xbe, 0x9c, 0x0f, 0xb3, 0xc7, 0x38, 0xbf,
  38338. 0x9e, 0x35, 0x8f, 0xe4, 0x8d, 0x19, 0xc3, 0x41, 0xb1, 0x0b, 0x8c, 0x10,
  38339. 0x9a, 0x58, 0xec, 0x4f, 0xb3, 0xe9, 0x5b, 0x72, 0x4b, 0xb8, 0x99, 0x34,
  38340. 0x9a, 0xcd, 0xb0, 0x69, 0xd0, 0x67, 0xef, 0x96, 0xb9, 0xe5, 0x54, 0x92,
  38341. 0xb7, 0x1a, 0x52, 0xf6, 0x0a, 0xc2, 0x23, 0x8d, 0x4f, 0xad, 0x00, 0xae,
  38342. 0x0f, 0x97, 0xfa, 0xce, 0x96, 0xba, 0xe7, 0x74, 0x55, 0xd4, 0xaf, 0xbf,
  38343. 0xa1, 0x32, 0x91, 0x2d, 0x03, 0x9f, 0xe3, 0x10, 0x8c, 0x77, 0x5d, 0x26,
  38344. 0x76, 0xf1, 0x87, 0x90, 0xf0, 0x20, 0xd1, 0xea, 0xf7, 0xa4, 0xe8, 0x2c,
  38345. 0x32, 0x1c, 0x55, 0xc0, 0x5d, 0xc9, 0xcd, 0x4e, 0x8f, 0x0d, 0xef, 0x0a,
  38346. 0x27, 0xb6, 0x4f, 0xa4, 0xd3, 0xa4, 0xed, 0x33, 0x22, 0xa1, 0xd3, 0x15,
  38347. 0xac, 0x1a, 0x20, 0x4e, 0x28, 0x8c, 0x8c, 0xd0, 0x71, 0xd1, 0xf2, 0xdb,
  38348. 0x33, 0x63, 0xb6, 0xa4, 0xf2, 0x17, 0x3c, 0x12, 0xb0, 0xad, 0xef, 0x31,
  38349. 0x91, 0xfe, 0xe5, 0x53, 0x99, 0xb6, 0x85, 0x63, 0xfa, 0xe6, 0xcd, 0xf6,
  38350. 0xb9, 0xce, 0x4a, 0x7d, 0x4a, 0x49, 0x29, 0xd2, 0xd9, 0xc9, 0x47, 0x4a,
  38351. 0x8a, 0x5c, 0x14, 0x5e, 0x0f, 0x7c, 0xc3, 0x91, 0xb0, 0xab, 0x37, 0xf5,
  38352. 0x26, 0x8d, 0x46, 0x74, 0x49, 0xad, 0x51, 0xc3, 0x11, 0xfa, 0x85, 0x15,
  38353. 0xa5, 0x84, 0xc1, 0xe0, 0x3c, 0x13, 0x6d, 0x13, 0xa3, 0xe6, 0xa8, 0x3c,
  38354. 0x22, 0xac, 0x17, 0x48, 0x57, 0x7c, 0x81, 0xe2, 0x4e, 0xd8, 0x33, 0x5d,
  38355. 0x4d, 0x65, 0xf7, 0xe1, 0xb8, 0x00, 0x78, 0x09, 0x16, 0xb0, 0x0b, 0xca,
  38356. 0x15, 0x0d, 0xcd, 0x9a, 0xd8, 0x47, 0x4c, 0x9b, 0x69, 0xb2, 0xa0, 0x9d,
  38357. 0x96, 0x96, 0x52, 0x6d, 0x89, 0xad, 0xff, 0x55, 0xde, 0x7b, 0xd6, 0x3d,
  38358. 0x1d, 0x5e, 0x8d, 0xf1, 0xfc, 0x48, 0x1c, 0x50, 0x59, 0x55, 0xb9, 0x07,
  38359. 0xfd, 0x6b, 0xcb, 0x95, 0xa6, 0x14, 0x73, 0xdb, 0x40, 0x40, 0x1c, 0x44,
  38360. 0xe6, 0x79, 0x30, 0x88, 0xbd, 0xa0, 0xde, 0x9b, 0xb8, 0x76, 0xf8, 0x98,
  38361. 0x56, 0x4b, 0xb9, 0x7a, 0xf6, 0xd4, 0x73, 0x89, 0x6b, 0xf7, 0x7d, 0x05,
  38362. 0x33, 0xbe, 0xb6, 0x1c, 0x4d, 0xa7, 0x12, 0x3b, 0x3f, 0xed, 0x4a, 0x0f,
  38363. 0xae, 0xa7, 0x6a, 0x26, 0x0d, 0x01, 0x84, 0x84, 0xa8, 0x0e, 0xc1, 0xc1,
  38364. 0xfd, 0xe4, 0xa9, 0xe2, 0x3f, 0xab, 0xce, 0x20, 0x90, 0x86, 0x79, 0xa2,
  38365. 0x40, 0xd0, 0xef, 0x79, 0x34, 0x2b, 0xe8, 0xc9, 0x54, 0xa7, 0x19, 0x62,
  38366. 0xcc, 0x20, 0x79, 0x3f, 0x5b, 0x9c, 0x61, 0xc2, 0xc1, 0xd2, 0x36, 0x7c,
  38367. 0x8e, 0xe3, 0x01, 0xbe, 0xc4, 0xb2, 0xb8, 0x07, 0x51, 0x23, 0x5b, 0x5d,
  38368. 0x00, 0xe6, 0x7f, 0xd6, 0xbb, 0x32, 0xa9, 0x7e, 0xb4, 0x30, 0xeb, 0x5e,
  38369. 0x6d, 0xed, 0xb2, 0xc3, 0x88, 0x81, 0xa3, 0x3b, 0x1f, 0x1e, 0xf9, 0x48,
  38370. 0x10, 0xd6, 0x01, 0x65, 0x5f, 0x6d, 0xc5, 0xeb, 0x76, 0x5f, 0x10, 0x79,
  38371. 0xaa, 0xc0, 0x86, 0xe7, 0x44, 0x95, 0x44, 0x4b, 0x54, 0x0c, 0x46, 0x2a,
  38372. 0x98, 0x01, 0x6e, 0xc0, 0xb9, 0x59, 0x2a, 0xff, 0x8f, 0xb3, 0x80, 0x15,
  38373. 0xec, 0xcd, 0x39, 0x36, 0xd7, 0x2f, 0x20, 0x9e, 0x3a, 0xc1, 0x90, 0xe5,
  38374. 0x99, 0x27, 0x16, 0xd7, 0x6c, 0x30, 0x10, 0x12, 0x03, 0x3e, 0xdc, 0xb9,
  38375. 0x03, 0x25, 0xb0, 0x8a, 0x27, 0x4d, 0x1a, 0x32, 0x36, 0x54, 0xc0, 0xba,
  38376. 0x22, 0xb2, 0xe2, 0xf6, 0x39, 0x23, 0x03, 0xc4, 0xc9, 0xe4, 0x0d, 0x99,
  38377. 0xfb, 0x98, 0xa5, 0x9b, 0x12, 0x9b, 0x58, 0x44, 0x74, 0x9f, 0x65, 0x61,
  38378. 0x51, 0xba, 0x31, 0x60, 0x9c, 0xec, 0xf8, 0x4d, 0x36, 0x61, 0xd1, 0x33,
  38379. 0x6d, 0xa6, 0x28, 0x75, 0xba, 0x7c, 0x82, 0xcb, 0x7e, 0xbe, 0x8f, 0x2d,
  38380. 0x21, 0x84, 0xb9, 0xf2, 0x4e, 0x7b, 0x95, 0x99, 0x11, 0xf3, 0xe1, 0xc0,
  38381. 0x6a, 0x44, 0xae, 0x11, 0xcb, 0x04, 0xa0, 0xf2, 0x3e, 0x17, 0xdf, 0xb2,
  38382. 0x6a, 0xdf, 0x5c, 0xf3, 0x8a, 0xf8, 0x90, 0x86, 0x64, 0xea, 0x0a, 0x32,
  38383. 0x7f, 0x9f, 0x90, 0xa8, 0x9d, 0x33, 0x12, 0xa6, 0xa4, 0xe7, 0x74, 0xa0,
  38384. 0x75, 0xa9, 0x65, 0xf8, 0x39, 0xae, 0x14, 0x32, 0x79, 0xcc, 0xaa, 0x34,
  38385. 0x86, 0x55, 0xcc, 0x99, 0xb7, 0x00, 0x05, 0x8b, 0xe3, 0x76, 0x28, 0x12,
  38386. 0xb6, 0x2a, 0x3e, 0x44, 0x8d, 0xf4, 0xba, 0xef, 0xf6, 0xdc, 0x29, 0x08,
  38387. 0x29, 0x7d, 0xd1, 0x1d, 0x17, 0x15, 0xb6, 0xb6, 0x58, 0x67, 0xd5, 0xd3,
  38388. 0x12, 0x05, 0x4e, 0xb0, 0xc3, 0x83, 0xe0, 0x35, 0x30, 0x60, 0x59, 0xa0,
  38389. 0xc5, 0x97, 0x5b, 0x81, 0xd3, 0x68, 0x6c, 0x8c, 0x17, 0x28, 0xa9, 0x24,
  38390. 0x4f, 0x80, 0x20, 0xa5, 0x21, 0x9f, 0x8f, 0x15, 0x89, 0x2d, 0x87, 0xae,
  38391. 0x2e, 0xcc, 0x73, 0x3e, 0x06, 0x43, 0xbc, 0xb3, 0x1b, 0xa6, 0x72, 0xaa,
  38392. 0xa3, 0xaa, 0xbb, 0x6f, 0x2d, 0x68, 0x60, 0xcf, 0x05, 0x94, 0x25, 0x3e,
  38393. 0x59, 0xf3, 0x64, 0x61, 0x5e, 0x78, 0x9a, 0x7e, 0x0d, 0x50, 0x45, 0x78,
  38394. 0x51, 0xab, 0x11, 0xb1, 0xc6, 0x95, 0xfc, 0x29, 0x28, 0x10, 0x9c, 0x1a,
  38395. 0x8c, 0x37, 0xb5, 0x4f, 0x0e, 0xed, 0x4a, 0x28, 0x6c, 0xaa, 0xb7, 0x0d,
  38396. 0x12, 0xfa, 0x87, 0x5d, 0xd4, 0x9a, 0xb7, 0x2b, 0x46, 0x90, 0x58, 0x4e,
  38397. 0xd7, 0x8b, 0x41, 0x1b, 0xf8, 0xc4, 0xc2, 0xde, 0xda, 0xec, 0x61, 0xe7,
  38398. 0xbf, 0x11, 0xdd, 0x6e, 0x4e, 0x6a, 0xd4, 0x87, 0x01, 0xe4, 0xac, 0xe8,
  38399. 0xaf, 0x2b, 0x01, 0xe1, 0x09, 0x20, 0xe0, 0xbd, 0x7d, 0x03, 0x73, 0x23,
  38400. 0xdf, 0x77, 0x71, 0xa4, 0x25, 0x8b, 0x0a, 0x93, 0x49, 0x32, 0x45, 0x1a,
  38401. 0xa4, 0x94, 0x31, 0x61, 0x2e, 0x17, 0x39, 0x8a, 0x66, 0xc9, 0xf9, 0x20,
  38402. 0x2d, 0x6a, 0x97, 0x2f, 0xe7, 0x26, 0xd8, 0x01, 0x42, 0x65, 0xcf, 0xce,
  38403. 0xd4, 0x24, 0x41, 0xfb, 0x9b, 0x6f, 0xf1, 0xc2, 0x9e, 0xd5, 0x08, 0x0c,
  38404. 0xdc, 0x4d, 0x8e, 0xae, 0xcb, 0x5f, 0xd4, 0xcd, 0x7c, 0xf6, 0x82, 0xc6,
  38405. 0xee, 0xf9, 0x88, 0x3a, 0x34, 0x07, 0x04, 0xb4, 0x84, 0x69, 0xb3, 0xa4,
  38406. 0x67, 0xab, 0x09, 0xc0, 0x83, 0xfe, 0x59, 0xaf, 0x18, 0x2c, 0xc8, 0x09,
  38407. 0xc1, 0xbb, 0x13, 0x7c, 0xce, 0x01, 0x5d, 0x85, 0xaa, 0x10, 0x28, 0xa2,
  38408. 0x96, 0x98, 0x69, 0x23, 0xa3, 0xe7, 0x67, 0xbc, 0x7c, 0x7e, 0xde, 0x4b,
  38409. 0x36, 0xab, 0x94, 0xd2, 0xb8, 0xf9, 0xdf, 0xee, 0xa1, 0x69, 0xa1, 0xc8,
  38410. 0xe9, 0x83, 0x21, 0xac, 0x1b, 0x39, 0xf7, 0x6d, 0xbf, 0x8c, 0xdb, 0xd6,
  38411. 0x2f, 0xc9, 0x3c, 0x3d, 0x50, 0xcf, 0x7f, 0xbe, 0x4a, 0x8d, 0xd8, 0x14,
  38412. 0xad, 0x69, 0xb0, 0x3e, 0x8a, 0xaf, 0xeb, 0xd9, 0x1a, 0x15, 0x4a, 0xe4,
  38413. 0xdd, 0xd9, 0xb2, 0xf8, 0x6b, 0xe2, 0x42, 0x9e, 0x29, 0x16, 0xfc, 0x85,
  38414. 0x9c, 0x47, 0x4b, 0x1f, 0x3d, 0x7b, 0x8c, 0xe1, 0x6d, 0xa3, 0xb8, 0x0a,
  38415. 0xe6, 0xfa, 0x27, 0xfe, 0x52, 0x72, 0xab, 0x3a, 0xa6, 0x58, 0xd7, 0x53,
  38416. 0xaf, 0x9f, 0xee, 0x03, 0x85, 0xfc, 0xa4, 0x7a, 0x72, 0x29, 0x7e, 0x62,
  38417. 0x28, 0x08, 0x79, 0xa8, 0xb8, 0xc7, 0x51, 0x8d, 0xaa, 0x40, 0x2d, 0x4a,
  38418. 0xd9, 0x47, 0xb4, 0xa8, 0xa2, 0x0a, 0x43, 0xd0, 0xe0, 0x4a, 0x39, 0xa3,
  38419. 0x06, 0x08, 0x9a, 0xe2, 0xf3, 0xf2, 0xf8, 0xb9, 0x9f, 0x63, 0x32, 0xa0,
  38420. 0x65, 0x0b, 0xb0, 0x50, 0x96, 0xa6, 0xa8, 0x7a, 0x18, 0xdd, 0x6c, 0xd1,
  38421. 0x9b, 0xd9, 0x4e, 0x76, 0x8f, 0xfb, 0x22, 0xa6, 0x1d, 0x29, 0xfc, 0xb8,
  38422. 0x47, 0x29, 0xb6, 0xd1, 0xb1, 0x63, 0x4a, 0x36, 0x1b, 0x10, 0xe6, 0x4c,
  38423. 0x65, 0x68, 0x1f, 0xad, 0x4f, 0x7d, 0x6b, 0x01, 0x41, 0x18, 0x5f, 0xba,
  38424. 0x3d, 0xa6, 0x54, 0x28, 0x58, 0xd5, 0x81, 0x60, 0xdf, 0x84, 0x76, 0x00,
  38425. 0x21, 0x53, 0xeb, 0xd3, 0xa6, 0xec, 0x7d, 0x3c, 0xb8, 0xcd, 0x91, 0x4c,
  38426. 0x2f, 0x4b, 0x2e, 0x23, 0x4c, 0x0f, 0x0f, 0xe0, 0x14, 0xa5, 0xe7, 0xe5,
  38427. 0x70, 0x8d, 0x8b, 0x9c
  38428. };
  38429. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38430. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_pub_key[] = {
  38431. 0xea, 0x05, 0x24, 0x0d, 0x80, 0x72, 0x25, 0x55, 0xf4, 0x5b,
  38432. 0xc2, 0x13, 0x8b, 0x87, 0x5d, 0x31, 0x99, 0x2f, 0x1d, 0xa9,
  38433. 0x41, 0x09, 0x05, 0x76, 0xa7, 0xb7, 0x5e, 0x8c, 0x44, 0xe2,
  38434. 0x64, 0x79, 0xa0, 0xec, 0x1f, 0x24, 0xb6, 0xc8, 0x05, 0x5b,
  38435. 0xc1, 0x18, 0xb0, 0xb7, 0xcf, 0x8c, 0x60, 0x67, 0x6b, 0x81,
  38436. 0x44, 0x27, 0xb6, 0x0e, 0xfd, 0x9b, 0xc3, 0xcb, 0x52, 0x31,
  38437. 0xfa, 0xc9, 0x34, 0x8d, 0x22, 0x1e, 0x07, 0x9d, 0x96, 0x6a,
  38438. 0x63, 0x83, 0x5c, 0xd7, 0x83, 0x2d, 0x7f, 0x48, 0x64, 0x79,
  38439. 0xca, 0xb4, 0x9f, 0xa2, 0x02, 0xb7, 0x86, 0x1d, 0x0e, 0xc7,
  38440. 0xf9, 0x6c, 0x07, 0xc0, 0x35, 0x6a, 0x34, 0x79, 0x7c, 0xb8,
  38441. 0x0f, 0xed, 0x98, 0x50, 0xfb, 0x51, 0xe0, 0x36, 0x44, 0x4c,
  38442. 0xc6, 0x35, 0xa2, 0xbb, 0x55, 0xb0, 0x5c, 0x39, 0x08, 0x02,
  38443. 0x20, 0x35, 0x5c, 0x56, 0x6d, 0x2e, 0xb9, 0xef, 0x21, 0x26,
  38444. 0x87, 0x87, 0x85, 0x8a, 0x32, 0xb5, 0xa7, 0x68, 0x70, 0x3a,
  38445. 0xfd, 0x0d, 0x21, 0x48, 0x91, 0xa3, 0x29, 0xc1, 0x2a, 0x38,
  38446. 0xe5, 0x26, 0x31, 0x1f, 0x42, 0xde, 0x0b, 0x25, 0xff, 0x1d,
  38447. 0x6b, 0xb4, 0xe0, 0x5d, 0x2d, 0xcf, 0x44, 0xd5, 0x7d, 0xc4,
  38448. 0xf6, 0x95, 0xf2, 0x06, 0x4f, 0x83, 0x88, 0x9d, 0x1e, 0xeb,
  38449. 0x1c, 0x09, 0x45, 0x62, 0x67, 0x3d, 0xff, 0x51, 0x47, 0xe8,
  38450. 0xbc, 0x9b, 0x03, 0x1f, 0xc7, 0x72, 0x65, 0xce, 0xa8, 0x8c,
  38451. 0xc2, 0xa0, 0xc2, 0xbd, 0x5b, 0x7c, 0x17, 0x16, 0x8b, 0x72,
  38452. 0xfa, 0xb1, 0xbd, 0xdf, 0x49, 0xd6, 0xa1, 0x00, 0x65, 0xbe,
  38453. 0x82, 0xe7, 0x68, 0xc7, 0xe7, 0xbc, 0xc2, 0xa4, 0xdb, 0xaa,
  38454. 0xcc, 0xea, 0x41, 0x52, 0x7f, 0x56, 0xb4, 0x68, 0x1f, 0x92,
  38455. 0x96, 0x0f, 0xce, 0xd4, 0xd0, 0x87, 0x4c, 0x4a, 0x73, 0xb5,
  38456. 0x6c, 0xd4, 0x69, 0x55, 0x15, 0x47, 0xdc, 0x94, 0x7f, 0xd2,
  38457. 0x54, 0x5e, 0xb2, 0x90, 0xc2, 0x47, 0xe4, 0xf5, 0xde, 0x8b,
  38458. 0x9b, 0xc6, 0x5d, 0x50, 0x95, 0x60, 0xe0, 0xf0, 0xa7, 0x4e,
  38459. 0xe0, 0xcd, 0x41, 0x09, 0xef, 0xb3, 0x3d, 0x90, 0x5c, 0x77,
  38460. 0x54, 0xec, 0x9e, 0x5d, 0x8a, 0xe7, 0x09, 0x5c, 0xc9, 0x58,
  38461. 0x0c, 0xd0, 0x42, 0x35, 0xd2, 0x14, 0x59, 0x38, 0x69, 0xad,
  38462. 0xf9, 0xb5, 0xbf, 0x8a, 0x8e, 0x33, 0xd8, 0x5e, 0x7a, 0x55,
  38463. 0xd0, 0x53, 0x15, 0x40, 0x4e, 0xc5, 0x86, 0xd7, 0x8f, 0x5f,
  38464. 0x2f, 0x55, 0x82, 0xc2, 0x4f, 0x16, 0xe5, 0xea, 0x1c, 0xbc,
  38465. 0xff, 0x5e, 0x1f, 0x39, 0x46, 0x70, 0x54, 0x7a, 0x3a, 0x27,
  38466. 0x16, 0x1a, 0x2b, 0x6c, 0xd2, 0xb7, 0x80, 0xd3, 0xd1, 0x9d,
  38467. 0x25, 0x59, 0xed, 0xe6, 0x51, 0xb1, 0xf2, 0xad, 0x7e, 0x51,
  38468. 0x78, 0x14, 0x2b, 0x19, 0xae, 0x64, 0x72, 0x0f, 0xd8, 0x18,
  38469. 0x79, 0x8e, 0x66, 0x88, 0xd3, 0xa4, 0xa3, 0xc3, 0x76, 0x21,
  38470. 0xcb, 0xe4, 0x79, 0x5e, 0x95, 0x74, 0xe3, 0x31, 0x18, 0x79,
  38471. 0xed, 0xc7, 0xe7, 0xfb, 0x86, 0x48, 0x1b, 0x7b, 0x75, 0x5b,
  38472. 0x7f, 0x7c, 0x82, 0xc5, 0xab, 0x11, 0xb4, 0x5d, 0x59, 0x6f,
  38473. 0x78, 0xb2, 0xa5, 0x39, 0xc6, 0x63, 0x38, 0x6c, 0xeb, 0x50,
  38474. 0x06, 0x14, 0x76, 0xf0, 0xe8, 0xfb, 0x11, 0x95, 0x1f, 0x9d,
  38475. 0x9c, 0xa6, 0xe1, 0xe2, 0x0d, 0xa3, 0x66, 0xfc, 0x20, 0x83,
  38476. 0x50, 0x0e, 0x53, 0x75, 0xb5, 0x12, 0xf4, 0xdf, 0x31, 0x46,
  38477. 0x83, 0xac, 0x5b, 0xf3, 0x99, 0xa6, 0xd1, 0x7b, 0x2b, 0xc5,
  38478. 0xdc, 0x71, 0x07, 0x27, 0x33, 0x35, 0x34, 0xf5, 0x30, 0x19,
  38479. 0xc1, 0x3b, 0xba, 0x8a, 0xaf, 0x7e, 0x49, 0x93, 0x48, 0x5b,
  38480. 0x38, 0xc0, 0xbc, 0x2e, 0xc7, 0x59, 0x1b, 0xd9, 0xf5, 0xcc,
  38481. 0x86, 0xf5, 0x7b, 0x4d, 0xd7, 0x39, 0xa7, 0xa2, 0x56, 0x20,
  38482. 0x48, 0x98, 0x7d, 0x4f, 0x75, 0x56, 0x9b, 0xb8, 0x95, 0x45,
  38483. 0x17, 0xf3, 0x86, 0x3d, 0x97, 0x0a, 0x49, 0x1b, 0xca, 0xff,
  38484. 0x20, 0xc0, 0x24, 0x2c, 0x51, 0xc2, 0x0a, 0x3c, 0xbf, 0x07,
  38485. 0x60, 0x1c, 0x88, 0x85, 0x9b, 0x85, 0x2d, 0x4a, 0xfe, 0x5a,
  38486. 0x1c, 0x90, 0xf5, 0x90, 0x12, 0xd3, 0x03, 0x3c, 0x8c, 0x2e,
  38487. 0x95, 0x4a, 0x47, 0x76, 0x0f, 0x1f, 0x5d, 0x9e, 0xed, 0xc5,
  38488. 0x64, 0xc4, 0x9b, 0xbf, 0x86, 0xc5, 0x63, 0x84, 0x33, 0x00,
  38489. 0xf1, 0x26, 0x18, 0x21, 0xf3, 0x88, 0x1a, 0x08, 0x18, 0x6d,
  38490. 0x2f, 0xef, 0xd5, 0xeb, 0x2f, 0x69, 0xc8, 0x6e, 0x92, 0x34,
  38491. 0xfc, 0x72, 0x3d, 0x9a, 0xa7, 0x9e, 0x51, 0xfb, 0x56, 0xe3,
  38492. 0xdc, 0xf4, 0x8f, 0x9b, 0x6d, 0x0d, 0x2a, 0xec, 0x66, 0x12,
  38493. 0x26, 0x35, 0xbd, 0x61, 0xc2, 0x67, 0x19, 0xf5, 0x7e, 0xa1,
  38494. 0x67, 0xa2, 0x9c, 0x3b, 0x67, 0xb0, 0xc2, 0x51, 0x6a, 0x37,
  38495. 0x7c, 0x48, 0xe9, 0x4b, 0xb9, 0xa3, 0x38, 0x2f, 0xfc, 0xde,
  38496. 0xb4, 0x7c, 0xda, 0x52, 0x84, 0x0b, 0xb0, 0xd9, 0x08, 0xe9,
  38497. 0x7a, 0x4a, 0x6f, 0x79, 0x29, 0x3d, 0xc4, 0x5c, 0x78, 0xee,
  38498. 0x63, 0xb6, 0x96, 0x68, 0xd9, 0x82, 0x4e, 0xc1, 0x1b, 0x6f,
  38499. 0x52, 0xf5, 0xb3, 0xfb, 0xe8, 0xc4, 0x2a, 0x07, 0xc6, 0x3b,
  38500. 0x85, 0x0d, 0xf4, 0xbf, 0xb0, 0x6b, 0xfb, 0xce, 0x1d, 0xb4,
  38501. 0xbf, 0x63, 0x0b, 0x91, 0x67, 0xc4, 0xa3, 0x06, 0xa4, 0xaf,
  38502. 0x6c, 0xd3, 0xe5, 0x8b, 0x87, 0x4e, 0x64, 0x9c, 0xb1, 0xf3,
  38503. 0x70, 0x7c, 0x68, 0x43, 0x46, 0x13, 0x46, 0xee, 0x27, 0x75,
  38504. 0x12, 0x45, 0x42, 0xde, 0xa5, 0x8d, 0xcf, 0xf7, 0x09, 0x87,
  38505. 0xa8, 0x80, 0x3d, 0xb6, 0x45, 0xee, 0x41, 0x2d, 0x7c, 0x45,
  38506. 0x01, 0x9d, 0xaa, 0x78, 0xa8, 0x10, 0xa4, 0xfd, 0xb5, 0x5f,
  38507. 0xee, 0x0f, 0x77, 0xba, 0x73, 0xff, 0x49, 0xdc, 0xfa, 0x39,
  38508. 0xd6, 0xa3, 0x6f, 0x25, 0xb9, 0x63, 0x2c, 0x92, 0xc5, 0xdf,
  38509. 0xfb, 0xba, 0x89, 0xf9, 0xfa, 0x94, 0x5b, 0x6f, 0x5a, 0x4d,
  38510. 0x1c, 0xe4, 0xc9, 0x10, 0xf9, 0xa0, 0xe8, 0xc4, 0xcb, 0x55,
  38511. 0x1a, 0xdb, 0x56, 0x5f, 0x8e, 0x91, 0x03, 0x23, 0xca, 0xb0,
  38512. 0x1f, 0xef, 0xb8, 0x6c, 0x13, 0x5a, 0x99, 0x25, 0xf0, 0x49,
  38513. 0xa9, 0x5a, 0x45, 0xf7, 0xfd, 0x1a, 0xc2, 0x71, 0x06, 0xe3,
  38514. 0x2d, 0x25, 0x64, 0xb0, 0x52, 0x12, 0x03, 0x62, 0xc7, 0xb6,
  38515. 0xf9, 0xdc, 0x1f, 0x78, 0xff, 0x8b, 0xfa, 0xde, 0x7f, 0x71,
  38516. 0xa6, 0x35, 0x3e, 0xac, 0x20, 0x54, 0x94, 0xa7, 0x2e, 0x9d,
  38517. 0x47, 0x17, 0x4b, 0xad, 0x92, 0xb3, 0x14, 0x26, 0x8c, 0x5a,
  38518. 0xd0, 0x16, 0x4b, 0x22, 0xe9, 0x0c, 0x79, 0x6b, 0x8e, 0xac,
  38519. 0x0d, 0x12, 0xf5, 0x66, 0x8e, 0x82, 0x1a, 0x44, 0xf3, 0xe9,
  38520. 0x56, 0x5a, 0xcd, 0x1c, 0x1b, 0x81, 0x7b, 0x63, 0x59, 0xfe,
  38521. 0xc8, 0xc0, 0xe3, 0xda, 0x16, 0x6b, 0x6f, 0x0d, 0xba, 0x0e,
  38522. 0x47, 0x12, 0x86, 0x9e, 0xf0, 0x3b, 0x4d, 0x87, 0x3b, 0xf2,
  38523. 0x75, 0x73, 0x2d, 0xdf, 0xca, 0x76, 0x0b, 0xbd, 0xe7, 0xb7,
  38524. 0x74, 0x24, 0xf3, 0xc6, 0xe6, 0x75, 0x3f, 0x8b, 0x6a, 0xd9,
  38525. 0xad, 0xed, 0xc0, 0x70, 0x04, 0x1e, 0x0b, 0x8e, 0x8b, 0x7f,
  38526. 0xea, 0xbc, 0x39, 0x6b, 0x8a, 0x44, 0xa6, 0x9a, 0x2d, 0x0d,
  38527. 0x8c, 0x21, 0x60, 0x09, 0xd2, 0x4a, 0xe0, 0x62, 0xcf, 0xfa,
  38528. 0xe8, 0x9b, 0x35, 0x6f, 0x23, 0x2f, 0xb5, 0x65, 0x08, 0x60,
  38529. 0x92, 0x15, 0xd0, 0x5b, 0x63, 0xcc, 0x65, 0x05, 0xd1, 0xef,
  38530. 0x0f, 0x7e, 0x1b, 0xb3, 0x8e, 0xc6, 0x12, 0x85, 0xc9, 0x82,
  38531. 0x53, 0x79, 0x2e, 0x80, 0x5f, 0x0c, 0x7b, 0xc7, 0x1c, 0x83,
  38532. 0x41, 0x06, 0xd8, 0x41, 0xc9, 0xe7, 0xb9, 0x4b, 0xa1, 0x61,
  38533. 0xc6, 0x86, 0x67, 0xf5, 0x10, 0xf7, 0x34, 0x0d, 0x39, 0x9e,
  38534. 0x2b, 0x5f, 0x19, 0x06, 0x02, 0xa5, 0x02, 0x23, 0x71, 0xc2,
  38535. 0x12, 0x65, 0xcc, 0x81, 0x06, 0xfd, 0x8d, 0x09, 0x68, 0x37,
  38536. 0x06, 0x3b, 0xff, 0xc4, 0x24, 0xb3, 0x1f, 0xd6, 0xe6, 0x8f,
  38537. 0x9c, 0x74, 0x2c, 0x5e, 0xc5, 0xf4, 0xe9, 0xeb, 0xca, 0xd3,
  38538. 0x04, 0x5b, 0x92, 0x9e, 0x5c, 0x1a, 0x1d, 0xa1, 0xa7, 0x34,
  38539. 0xd2, 0x05, 0xae, 0xdb, 0x3d, 0x71, 0x10, 0x6e, 0x30, 0xd9,
  38540. 0xa3, 0x44, 0xa0, 0xbd, 0x9e, 0x7b, 0xb5, 0x12, 0x8a, 0x12,
  38541. 0x07, 0x60, 0xd7, 0x1f, 0x92, 0xe6, 0xfe, 0x04, 0xa9, 0x3e,
  38542. 0x62, 0x64, 0x00, 0x5f, 0x7c, 0x7b, 0x34, 0x09, 0xeb, 0x4a,
  38543. 0x18, 0x9e, 0x77, 0x72, 0x3a, 0x31, 0x1a, 0x62, 0x2a, 0xb5,
  38544. 0xcb, 0x4e, 0x53, 0xce, 0xad, 0x8b, 0x5a, 0x20, 0x4f, 0xd7,
  38545. 0x3e, 0x16, 0xf8, 0x10, 0xe2, 0xae, 0xbd, 0x3f, 0x02, 0xa9,
  38546. 0x18, 0xa0, 0x01, 0x18, 0x84, 0x95, 0x22, 0x2e, 0x93, 0x76,
  38547. 0x44, 0x4e, 0x11, 0x7b, 0x03, 0x51, 0x50, 0x19, 0x79, 0xe7,
  38548. 0xbb, 0x5c, 0x7b, 0xca, 0x74, 0xb4, 0x25, 0x26, 0xdb, 0x66,
  38549. 0xaa, 0x0b, 0x21, 0x07, 0xfb, 0x7a, 0x96, 0x10, 0x7d, 0x99,
  38550. 0xa9, 0x16, 0xcb, 0x0e, 0xba, 0x63, 0xab, 0x95, 0xfc, 0x5a,
  38551. 0xbe, 0xa6, 0x7f, 0xd8, 0xb4, 0xcd, 0x7c, 0xc5, 0xd0, 0xb1,
  38552. 0x1b, 0x48, 0x40, 0xfb, 0xe6, 0x2f, 0x2b, 0x94, 0xfe, 0x68,
  38553. 0xa2, 0xc4, 0x36, 0xd9, 0xcd, 0xc1, 0x93, 0x6d, 0xef, 0x39,
  38554. 0x5e, 0x43, 0x30, 0x5a, 0x2e, 0x66, 0xb6, 0xf2, 0xed, 0x9a,
  38555. 0x8d, 0x12, 0xdf, 0x5c, 0xae, 0xad, 0x16, 0x12, 0x7e, 0x81,
  38556. 0x82, 0x91, 0x7d, 0x2b, 0x12, 0xe9, 0x96, 0xb8, 0xb7, 0x42,
  38557. 0xcb, 0x1f, 0xf8, 0xd1, 0xfd, 0x83, 0x7a, 0xe4, 0x36, 0x1d,
  38558. 0x04, 0x27, 0x4c, 0xe5, 0xbd, 0x75, 0x24, 0xf7, 0xbd, 0xb6,
  38559. 0x6a, 0x68, 0x4e, 0x2c, 0x1b, 0x56, 0x3e, 0x60, 0xa4, 0x42,
  38560. 0xca, 0x7a, 0x54, 0xe5, 0x06, 0xe3, 0xda, 0x05, 0xf7, 0x77,
  38561. 0x36, 0x8b, 0x81, 0x26, 0x99, 0x92, 0x42, 0xda, 0x45, 0xb1,
  38562. 0xfe, 0x4b
  38563. };
  38564. #endif
  38565. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_sig[] = {
  38566. 0x27, 0x3b, 0x58, 0xa0, 0xcf, 0x00, 0x29, 0x5e, 0x1a, 0x63, 0xbf, 0xb4,
  38567. 0x97, 0x16, 0xa1, 0x9c, 0x78, 0xd1, 0x33, 0xdc, 0x72, 0xde, 0xa3, 0xfc,
  38568. 0xf4, 0x09, 0xb1, 0x09, 0x16, 0x3f, 0x80, 0x72, 0x22, 0x68, 0x65, 0x68,
  38569. 0xb9, 0x80, 0x5a, 0x4a, 0x0d, 0x73, 0x49, 0xe1, 0xc6, 0xde, 0xca, 0x08,
  38570. 0x4f, 0xca, 0xf8, 0xb2, 0xf8, 0x45, 0x3b, 0x6b, 0x8c, 0x6c, 0xfd, 0x3a,
  38571. 0xf4, 0xde, 0xde, 0x82, 0xd8, 0x04, 0xbe, 0x4f, 0x4a, 0xdb, 0x92, 0x47,
  38572. 0x83, 0x2d, 0xc4, 0x55, 0xed, 0x20, 0x4f, 0x71, 0xb1, 0x58, 0xd9, 0x70,
  38573. 0x73, 0xbd, 0xb0, 0x3a, 0xb4, 0x8f, 0xd6, 0x9e, 0x32, 0x98, 0x2b, 0x9e,
  38574. 0xff, 0x2a, 0x7c, 0xcb, 0x05, 0x1b, 0x8e, 0xe6, 0x3a, 0x45, 0xc6, 0x7a,
  38575. 0xc8, 0xaf, 0x62, 0xd3, 0x04, 0xfa, 0x69, 0x4f, 0xda, 0x1b, 0x74, 0x16,
  38576. 0x0d, 0xb3, 0x1a, 0xee, 0x71, 0xd7, 0xb0, 0xef, 0x69, 0xf5, 0xe2, 0xe9,
  38577. 0xc2, 0xcc, 0x15, 0x66, 0x28, 0x0a, 0xac, 0xe2, 0x63, 0x06, 0xb7, 0x21,
  38578. 0x0d, 0xd8, 0x5c, 0x94, 0x63, 0xfd, 0x51, 0x18, 0x9f, 0x07, 0x19, 0x3d,
  38579. 0xa2, 0x50, 0x40, 0xd3, 0xe9, 0x05, 0xd4, 0x11, 0x13, 0x15, 0xaa, 0x46,
  38580. 0xda, 0x3e, 0x5f, 0xcd, 0x3c, 0xfa, 0x42, 0xba, 0x79, 0x4a, 0xb7, 0x43,
  38581. 0x91, 0xa5, 0xcb, 0xbc, 0xeb, 0x37, 0x94, 0xf1, 0x9c, 0xb9, 0xdb, 0x41,
  38582. 0x06, 0xd8, 0x7b, 0x5e, 0x90, 0xe3, 0x3c, 0x8a, 0x10, 0x62, 0x9a, 0x15,
  38583. 0x27, 0x78, 0xed, 0x69, 0x11, 0x2c, 0xb5, 0xb4, 0xdb, 0xc8, 0x70, 0x50,
  38584. 0x62, 0x47, 0x96, 0xcb, 0xd9, 0xb2, 0x3e, 0x59, 0x2f, 0x1c, 0xac, 0xcb,
  38585. 0xcf, 0x22, 0xc2, 0x9b, 0xc7, 0x92, 0xe9, 0x4d, 0x8d, 0x5d, 0xcf, 0x06,
  38586. 0x53, 0x7e, 0xf4, 0x4e, 0xfe, 0x9e, 0x41, 0x5d, 0x00, 0x8c, 0x08, 0xf4,
  38587. 0x02, 0x79, 0x33, 0x1c, 0x27, 0x1d, 0xe3, 0x94, 0xac, 0xe6, 0x87, 0xa0,
  38588. 0x08, 0xb4, 0x60, 0x0c, 0xff, 0x47, 0xdc, 0x16, 0x3a, 0x1d, 0x89, 0xc0,
  38589. 0x6a, 0xa4, 0x3d, 0x71, 0x33, 0xdd, 0x1e, 0x70, 0xfe, 0xd4, 0x8b, 0xed,
  38590. 0x7c, 0x91, 0xe4, 0xe2, 0x15, 0x06, 0xc1, 0x83, 0x24, 0x55, 0xa7, 0x2a,
  38591. 0x9f, 0x4e, 0xd9, 0x56, 0x7a, 0x95, 0xa8, 0xdd, 0xc4, 0xf0, 0x71, 0x3a,
  38592. 0x99, 0x65, 0x31, 0x4b, 0xb7, 0x96, 0x2c, 0x53, 0x54, 0x83, 0xec, 0xc9,
  38593. 0x97, 0x2f, 0x0c, 0xa4, 0x8f, 0xbb, 0x93, 0x9d, 0xea, 0xae, 0xf9, 0xcb,
  38594. 0xb2, 0xb9, 0xa3, 0x61, 0x5f, 0x77, 0x8c, 0xb6, 0x5a, 0x56, 0xbe, 0x5f,
  38595. 0x85, 0xd1, 0xb5, 0x0a, 0x53, 0xe2, 0xc7, 0xbf, 0x76, 0x8b, 0x97, 0x6f,
  38596. 0x10, 0xdd, 0x1f, 0x44, 0x69, 0x66, 0x03, 0xc4, 0x6b, 0x59, 0xf7, 0xb4,
  38597. 0xc1, 0x12, 0xcc, 0x00, 0x70, 0xe8, 0xbd, 0x44, 0x28, 0xf5, 0xfa, 0x96,
  38598. 0xf3, 0x59, 0xed, 0x81, 0x67, 0xe0, 0xbe, 0x47, 0x75, 0xb3, 0xa8, 0x9f,
  38599. 0x21, 0x70, 0x2e, 0x6f, 0xef, 0x54, 0x11, 0x3f, 0x34, 0xaf, 0x0d, 0x73,
  38600. 0x5b, 0x9e, 0x6d, 0x86, 0x58, 0xb7, 0x34, 0xc2, 0xc2, 0xb3, 0x64, 0xd5,
  38601. 0x9b, 0x6e, 0xb9, 0x99, 0x6a, 0xe4, 0xfd, 0xc3, 0x17, 0xf3, 0x10, 0xfc,
  38602. 0x6e, 0xf5, 0x65, 0xe1, 0x9c, 0x59, 0x15, 0x11, 0x00, 0xea, 0x96, 0x81,
  38603. 0x69, 0x9b, 0x05, 0x4d, 0xf3, 0xce, 0xf3, 0xf0, 0xa9, 0x01, 0x3f, 0x13,
  38604. 0xbb, 0xb0, 0xac, 0xc3, 0x92, 0x1c, 0x2b, 0x61, 0xe3, 0x01, 0x22, 0x45,
  38605. 0x4a, 0x23, 0x19, 0x80, 0xca, 0xb9, 0xef, 0x4e, 0x76, 0x52, 0xc5, 0x9d,
  38606. 0x91, 0x33, 0x17, 0xc4, 0x28, 0x83, 0x55, 0x61, 0x49, 0x72, 0x04, 0xaa,
  38607. 0xf8, 0xe3, 0x4b, 0x20, 0xf7, 0x6a, 0x74, 0x56, 0x64, 0xf9, 0xb3, 0xc9,
  38608. 0x67, 0x5b, 0x55, 0x29, 0x9a, 0x89, 0xa5, 0x14, 0x67, 0xea, 0x6d, 0x6a,
  38609. 0xde, 0x98, 0x58, 0x73, 0x25, 0xa3, 0xdb, 0xed, 0x3d, 0x62, 0xaa, 0xe0,
  38610. 0x79, 0x7f, 0xa3, 0xd9, 0xb5, 0x4c, 0xe9, 0xa8, 0xdf, 0xfd, 0x59, 0x31,
  38611. 0x42, 0x81, 0x9e, 0xb7, 0x81, 0x3f, 0x0e, 0xfb, 0xef, 0x80, 0x71, 0x9d,
  38612. 0xb7, 0xa5, 0xfc, 0xb1, 0x80, 0xc9, 0x7e, 0x31, 0xd9, 0x47, 0xe2, 0xca,
  38613. 0x10, 0x7b, 0xd1, 0xa1, 0x1c, 0x28, 0xc7, 0x7f, 0x51, 0x26, 0xb1, 0x4e,
  38614. 0x57, 0xdd, 0x7d, 0x76, 0x5c, 0x5a, 0x85, 0xa7, 0x7b, 0x8c, 0xc5, 0x6e,
  38615. 0xac, 0x20, 0xf8, 0x49, 0x16, 0xd6, 0x64, 0xf5, 0xf4, 0x2c, 0x32, 0xa1,
  38616. 0x5d, 0xfb, 0x87, 0xb6, 0x14, 0xfe, 0x68, 0x7c, 0x4d, 0xce, 0xd7, 0x94,
  38617. 0xf9, 0x8b, 0xf0, 0x61, 0xfd, 0xe0, 0x83, 0x7f, 0x13, 0xec, 0x7a, 0xb7,
  38618. 0x41, 0x04, 0x51, 0x6e, 0x30, 0xa2, 0x01, 0xf7, 0x30, 0x12, 0xec, 0xd2,
  38619. 0x8f, 0x73, 0xe7, 0x8e, 0x12, 0xb4, 0xe5, 0xc1, 0xff, 0xdf, 0x67, 0x14,
  38620. 0xb1, 0xe9, 0xba, 0x36, 0x19, 0x18, 0xf4, 0xaa, 0xe0, 0xe4, 0x9d, 0xcd,
  38621. 0xe8, 0xe7, 0x2b, 0x33, 0xb3, 0xdc, 0xb9, 0x19, 0xd7, 0xad, 0xa4, 0x68,
  38622. 0xcd, 0x83, 0x77, 0x98, 0x36, 0x49, 0xd9, 0x32, 0x20, 0xfd, 0xfc, 0x34,
  38623. 0xe7, 0x54, 0xd9, 0xb5, 0x05, 0xab, 0x0e, 0x08, 0x0e, 0x16, 0x8a, 0x7d,
  38624. 0x91, 0x4c, 0xaa, 0x19, 0x04, 0x37, 0x35, 0xa5, 0xab, 0x6c, 0xee, 0xc4,
  38625. 0x90, 0xf0, 0x5f, 0xc7, 0xae, 0x82, 0xfd, 0x59, 0x53, 0xe5, 0x36, 0x5a,
  38626. 0x56, 0x37, 0x61, 0x69, 0xda, 0xe5, 0x8f, 0xfd, 0x2e, 0xd4, 0x9c, 0x7f,
  38627. 0xb6, 0x39, 0xa4, 0x8d, 0x0a, 0xab, 0x82, 0x0f, 0xfe, 0x84, 0x69, 0x44,
  38628. 0x8a, 0xa6, 0xd0, 0x39, 0xf9, 0x72, 0x68, 0xe7, 0x97, 0xd8, 0x6c, 0x7b,
  38629. 0xec, 0x85, 0x8c, 0x52, 0xc9, 0x97, 0xbb, 0xc4, 0x7a, 0x67, 0x22, 0x60,
  38630. 0x46, 0x9f, 0x16, 0xf1, 0x67, 0x0e, 0x1b, 0x50, 0x7c, 0xc4, 0x29, 0x15,
  38631. 0xbc, 0x55, 0x6a, 0x67, 0xf6, 0xa8, 0x85, 0x66, 0x89, 0x9f, 0xff, 0x38,
  38632. 0x28, 0xaa, 0x87, 0x91, 0xce, 0xde, 0x8d, 0x45, 0x5c, 0xa1, 0x25, 0x95,
  38633. 0xe2, 0x86, 0xdd, 0xa1, 0x87, 0x6a, 0x0a, 0xa8, 0x3e, 0x63, 0x0e, 0x21,
  38634. 0xa5, 0x6e, 0x08, 0x4d, 0x07, 0xb6, 0x26, 0xa8, 0x92, 0xdb, 0xed, 0x13,
  38635. 0x01, 0xc3, 0xba, 0xcf, 0xad, 0x01, 0xbc, 0xe5, 0xc0, 0xba, 0xbe, 0x7c,
  38636. 0x75, 0xf1, 0xb9, 0xfe, 0xd3, 0xf0, 0xa5, 0x2c, 0x8e, 0x10, 0xff, 0x99,
  38637. 0xcb, 0xe2, 0x2d, 0xdc, 0x2f, 0x76, 0x00, 0xf8, 0x51, 0x7c, 0xcc, 0x52,
  38638. 0x16, 0x0f, 0x18, 0x98, 0xea, 0x34, 0x06, 0x7f, 0xb7, 0x2e, 0xe9, 0x40,
  38639. 0xf0, 0x2d, 0x30, 0x3d, 0xc0, 0x67, 0x4c, 0xe6, 0x63, 0x40, 0x41, 0x42,
  38640. 0x96, 0xbb, 0x0b, 0xd6, 0xc9, 0x1c, 0x22, 0x7a, 0xa9, 0x4d, 0xcc, 0x5b,
  38641. 0xaa, 0x03, 0xc6, 0x3b, 0x1e, 0x2f, 0x11, 0xae, 0x34, 0x6f, 0x0c, 0xe9,
  38642. 0x16, 0x9c, 0x82, 0x3b, 0x90, 0x4c, 0x0e, 0xf0, 0xf9, 0x7f, 0x02, 0xca,
  38643. 0xb9, 0xa9, 0x49, 0x6d, 0x27, 0x73, 0xd0, 0xbf, 0x15, 0x61, 0x52, 0xbc,
  38644. 0xd6, 0x31, 0x59, 0x2b, 0x52, 0x5b, 0xaf, 0x3c, 0xc0, 0x8f, 0xdc, 0xd5,
  38645. 0x2c, 0x1d, 0xe4, 0xe9, 0x41, 0xe8, 0xd3, 0x35, 0xd6, 0xb1, 0xf3, 0x32,
  38646. 0xe0, 0x52, 0x08, 0x73, 0x99, 0xb6, 0x6b, 0xbc, 0x26, 0xfb, 0x2e, 0xa7,
  38647. 0xb7, 0xcd, 0x14, 0xf0, 0xf9, 0xe5, 0x3a, 0xd0, 0x05, 0x5b, 0x2b, 0x38,
  38648. 0xbd, 0x7c, 0xda, 0xd4, 0x15, 0x45, 0xfa, 0x3b, 0x6f, 0x94, 0x8e, 0x22,
  38649. 0xce, 0xfa, 0x53, 0xe0, 0x5f, 0xa6, 0x9d, 0x1c, 0x26, 0x91, 0x8a, 0xab,
  38650. 0x72, 0x5b, 0x18, 0x78, 0x69, 0x98, 0x3f, 0x8d, 0x33, 0x7c, 0x21, 0x93,
  38651. 0x9e, 0xf0, 0xaf, 0xb7, 0x30, 0xc8, 0xac, 0xbc, 0xdb, 0x9c, 0x29, 0x17,
  38652. 0x6b, 0x9d, 0x0f, 0x16, 0xd6, 0xc0, 0xcc, 0x3b, 0xce, 0x11, 0xe9, 0x64,
  38653. 0xc8, 0xd4, 0x4c, 0x98, 0x7c, 0x8f, 0xf1, 0x5e, 0x84, 0xe4, 0x72, 0xf9,
  38654. 0x69, 0xf5, 0x9d, 0xad, 0x95, 0x3b, 0xfb, 0x6d, 0x30, 0x7e, 0x0a, 0x47,
  38655. 0x5b, 0x26, 0xb2, 0x4e, 0xeb, 0x1a, 0xc3, 0x37, 0x16, 0x28, 0x79, 0x62,
  38656. 0xb4, 0x36, 0x85, 0x4a, 0x15, 0x5a, 0xc3, 0x6e, 0xbe, 0x7e, 0x00, 0xe9,
  38657. 0x4a, 0xa5, 0xd7, 0x90, 0xcf, 0x59, 0x63, 0x2d, 0x2b, 0xc2, 0xc6, 0x47,
  38658. 0xe6, 0x77, 0xb7, 0x6e, 0x9b, 0xc8, 0x0d, 0x18, 0x2b, 0x45, 0x2b, 0xc9,
  38659. 0x5a, 0x6e, 0xb4, 0x50, 0xa5, 0x23, 0x7d, 0x17, 0xcc, 0x49, 0xe2, 0xb3,
  38660. 0xf4, 0x6d, 0xb4, 0xb7, 0xbb, 0x9e, 0xdd, 0x20, 0x99, 0x19, 0xf5, 0x53,
  38661. 0x1f, 0xd0, 0xff, 0x67, 0xf3, 0x8e, 0x6a, 0xcd, 0x2a, 0x6e, 0x2b, 0x0a,
  38662. 0x90, 0xd7, 0xdb, 0xe1, 0xff, 0x1c, 0x40, 0xa1, 0xb0, 0x5d, 0x94, 0x4d,
  38663. 0x20, 0x14, 0x01, 0xa1, 0xa8, 0xd1, 0x15, 0xd2, 0xd9, 0x1b, 0xbf, 0xc2,
  38664. 0x8a, 0xd0, 0x02, 0xf6, 0x16, 0xa1, 0xb7, 0x40, 0xe0, 0x36, 0x88, 0xc8,
  38665. 0x17, 0x0a, 0xf0, 0xb6, 0x0d, 0x3c, 0x53, 0xb9, 0x51, 0xed, 0xef, 0x20,
  38666. 0x6f, 0xf3, 0x0c, 0xb5, 0xce, 0x0e, 0x9e, 0xfd, 0x0f, 0x5e, 0x3f, 0x8f,
  38667. 0x3c, 0xb7, 0x2a, 0xdb, 0xc6, 0xa7, 0xf2, 0x11, 0x6e, 0xdc, 0x05, 0x33,
  38668. 0xd4, 0xd8, 0xb0, 0x2d, 0x8a, 0xe5, 0x39, 0x82, 0x00, 0x49, 0x7d, 0xfd,
  38669. 0x32, 0x29, 0xbb, 0x79, 0x5d, 0xcb, 0x21, 0x7b, 0x2d, 0x36, 0x58, 0x73,
  38670. 0x52, 0x57, 0x52, 0x96, 0x4d, 0x89, 0x61, 0xf4, 0xad, 0x1f, 0x48, 0xd5,
  38671. 0x7a, 0x4a, 0xaa, 0x1c, 0xa1, 0xf4, 0xb4, 0x9c, 0x43, 0x3b, 0x95, 0x72,
  38672. 0xd0, 0x0e, 0x35, 0x82, 0x26, 0xd4, 0x2e, 0xe3, 0x83, 0x96, 0x97, 0x5a,
  38673. 0x7b, 0xfc, 0x48, 0x17, 0x3c, 0xba, 0x9e, 0x5f, 0x46, 0x1a, 0x53, 0xe3,
  38674. 0x2e, 0x78, 0x79, 0x80, 0xf6, 0x2d, 0x24, 0xcf, 0x62, 0xb6, 0x86, 0xeb,
  38675. 0xee, 0xec, 0xf2, 0x1d, 0x00, 0xc8, 0x28, 0x9d, 0x93, 0x16, 0xa7, 0xd9,
  38676. 0x11, 0x47, 0xe3, 0xc4, 0xb6, 0xc4, 0xa0, 0x99, 0x83, 0xc1, 0x17, 0xd8,
  38677. 0x8e, 0xde, 0x69, 0x1d, 0xcb, 0xdd, 0xe7, 0x86, 0x6f, 0xf2, 0x36, 0x07,
  38678. 0x23, 0x86, 0x0d, 0xe9, 0xad, 0x87, 0xae, 0x76, 0x98, 0x95, 0x51, 0xf2,
  38679. 0xb3, 0x11, 0xc5, 0x34, 0xf0, 0x0c, 0xf8, 0x29, 0x9c, 0x84, 0x4f, 0x81,
  38680. 0x49, 0x85, 0x63, 0x25, 0x16, 0xb0, 0xc3, 0xaa, 0xd7, 0x8a, 0x2e, 0x4b,
  38681. 0x97, 0x60, 0x74, 0xf8, 0xa7, 0x39, 0xec, 0x6c, 0x2c, 0x9b, 0x33, 0x3a,
  38682. 0x11, 0xbd, 0xa6, 0x90, 0x48, 0x65, 0xb1, 0xe7, 0x38, 0x53, 0x47, 0x1b,
  38683. 0x62, 0xd5, 0xb7, 0xa8, 0xd4, 0xae, 0xf5, 0x12, 0x06, 0x12, 0x54, 0xa2,
  38684. 0xce, 0xf1, 0x6b, 0x3a, 0xda, 0x63, 0x2e, 0x37, 0x2a, 0x25, 0x89, 0x30,
  38685. 0x98, 0x77, 0x1d, 0x4b, 0x5a, 0x1e, 0xb7, 0x3d, 0xed, 0x19, 0xec, 0x9f,
  38686. 0x64, 0x46, 0xa8, 0x2a, 0x79, 0xf3, 0x70, 0x39, 0x9f, 0x8c, 0xc3, 0x28,
  38687. 0xcc, 0x2a, 0xc0, 0xd0, 0xe6, 0x80, 0xf5, 0x01, 0x78, 0x72, 0x7f, 0xe7,
  38688. 0x2e, 0x7b, 0x5f, 0x05, 0xc3, 0x41, 0x33, 0x07, 0xdb, 0x9c, 0xa8, 0x96,
  38689. 0xa7, 0x21, 0x20, 0x23, 0xd0, 0x59, 0x39, 0x06, 0x19, 0xa4, 0x29, 0xe5,
  38690. 0x72, 0x39, 0x69, 0x23, 0xe3, 0xfa, 0x28, 0x63, 0xf5, 0x42, 0x3b, 0xca,
  38691. 0x88, 0x5d, 0x7e, 0x47, 0x93, 0xa8, 0x8c, 0x75, 0xf2, 0x19, 0x44, 0x43,
  38692. 0x15, 0x39, 0x03, 0x42, 0xd8, 0x1d, 0x81, 0x30, 0x8e, 0x84, 0x31, 0x24,
  38693. 0x75, 0x67, 0x4e, 0xbe, 0xfe, 0x0a, 0xd8, 0xc3, 0xe7, 0x5b, 0xe1, 0xd5,
  38694. 0x12, 0x6a, 0x69, 0x99, 0xcd, 0x35, 0xca, 0x22, 0x02, 0x65, 0xb3, 0x0f,
  38695. 0x50, 0xb6, 0xaa, 0xc6, 0x91, 0x5c, 0x4d, 0xd4, 0x07, 0x93, 0x46, 0xf0,
  38696. 0xcc, 0xe1, 0x92, 0x14, 0x91, 0x21, 0x43, 0xc4, 0xba, 0x45, 0x1c, 0x47,
  38697. 0x29, 0xdf, 0xff, 0x89, 0x60, 0xee, 0x89, 0x1e, 0xc3, 0xb4, 0xb9, 0x0b,
  38698. 0xc9, 0x7e, 0xd9, 0x15, 0xb0, 0x80, 0x91, 0xbe, 0xb9, 0x43, 0x48, 0x12,
  38699. 0x86, 0x8e, 0x79, 0x38, 0x4d, 0xce, 0x36, 0x7f, 0xc3, 0xe8, 0xb7, 0xb9,
  38700. 0x92, 0xbf, 0x27, 0x20, 0x54, 0xc8, 0x05, 0x63, 0x3b, 0xf5, 0x48, 0x1a,
  38701. 0xa9, 0x04, 0x6c, 0xb6, 0x0e, 0x11, 0xea, 0xf3, 0x59, 0xb9, 0xa6, 0xf6,
  38702. 0xf8, 0x0b, 0x15, 0xed, 0x30, 0xf9, 0xe4, 0xe5, 0x26, 0x2d, 0xbb, 0xc6,
  38703. 0x5b, 0x36, 0xbb, 0x73, 0xa6, 0x4f, 0xf5, 0x43, 0x9f, 0xd7, 0xb9, 0x0f,
  38704. 0xbc, 0x4f, 0x8d, 0xb8, 0xec, 0x1d, 0x42, 0x19, 0x56, 0x37, 0xc4, 0xcb,
  38705. 0xd0, 0x16, 0x85, 0xff, 0xd3, 0x9b, 0xef, 0xc8, 0x75, 0x37, 0xd1, 0x92,
  38706. 0xad, 0x21, 0x94, 0x1e, 0x9a, 0xf6, 0x2f, 0x6d, 0x30, 0xba, 0x37, 0xc3,
  38707. 0xdc, 0x11, 0xe0, 0x79, 0xa4, 0x92, 0x1f, 0xe4, 0xaa, 0x7a, 0x6b, 0x2a,
  38708. 0xe4, 0x04, 0xb7, 0xf9, 0x86, 0x95, 0xdb, 0xa8, 0xfc, 0x8a, 0x53, 0x21,
  38709. 0x31, 0x14, 0xf7, 0x40, 0x01, 0x78, 0x4e, 0x73, 0x18, 0xb3, 0x54, 0xd7,
  38710. 0xa6, 0x93, 0xf0, 0x70, 0x04, 0x1c, 0xe0, 0x2b, 0xef, 0xee, 0xd4, 0x64,
  38711. 0xa7, 0xd9, 0x9f, 0x81, 0x4f, 0xe5, 0x1e, 0xbe, 0x6e, 0xd2, 0xf6, 0x3a,
  38712. 0xba, 0xcf, 0x8c, 0x96, 0x2a, 0x3d, 0xf7, 0xe5, 0x5c, 0x59, 0x40, 0x9c,
  38713. 0xe3, 0xf9, 0x2b, 0x6d, 0x3d, 0xf2, 0x6f, 0x81, 0xd6, 0xab, 0x9c, 0xab,
  38714. 0xc6, 0xf7, 0x8f, 0xaa, 0xe5, 0x71, 0xe3, 0xc9, 0x8c, 0x1a, 0xeb, 0xc5,
  38715. 0x87, 0xe7, 0xb0, 0xde, 0x18, 0xba, 0xaa, 0x1e, 0xda, 0x12, 0x32, 0x16,
  38716. 0x94, 0x3a, 0x6e, 0x4f, 0x84, 0x06, 0x8e, 0x33, 0xf7, 0xfa, 0x35, 0xb8,
  38717. 0x45, 0xe4, 0x5e, 0x9e, 0x46, 0x05, 0x7a, 0xf7, 0xf4, 0x99, 0xad, 0xb9,
  38718. 0xdd, 0x55, 0xd9, 0x52, 0x3b, 0x93, 0xe3, 0x9b, 0x54, 0x1b, 0xe6, 0xa9,
  38719. 0x70, 0xd3, 0x48, 0xf9, 0x3d, 0xdb, 0x88, 0x63, 0x66, 0xa0, 0xab, 0x72,
  38720. 0x83, 0x6e, 0x8f, 0x78, 0x9d, 0x55, 0x46, 0x21, 0xca, 0x7c, 0xb7, 0x5d,
  38721. 0x16, 0xe8, 0x66, 0x3b, 0x7b, 0xaa, 0xfe, 0x9c, 0x9c, 0x33, 0xc9, 0xc2,
  38722. 0xa4, 0x3c, 0x78, 0x97, 0xf3, 0x5b, 0xc2, 0x29, 0x36, 0x98, 0x68, 0x28,
  38723. 0xfe, 0x0a, 0xae, 0x6f, 0xe5, 0xf7, 0xfb, 0x9d, 0xf8, 0x8c, 0xd9, 0xd0,
  38724. 0x4d, 0xfe, 0xc7, 0xd0, 0xb0, 0xe3, 0x9c, 0xdb, 0xac, 0x9e, 0x1b, 0x55,
  38725. 0x7e, 0x24, 0xfe, 0xc4, 0x12, 0xcb, 0xc2, 0xdd, 0x0a, 0xda, 0x31, 0x40,
  38726. 0x41, 0xb7, 0xfc, 0x3f, 0x6d, 0xe2, 0xd3, 0x8a, 0x0f, 0x21, 0x33, 0x3a,
  38727. 0xbc, 0xa7, 0x62, 0x18, 0xb3, 0xaf, 0x48, 0xc6, 0xe2, 0xa3, 0xdd, 0x1d,
  38728. 0x20, 0x62, 0xe4, 0x4b, 0x81, 0x6b, 0x3a, 0xc5, 0xb1, 0x07, 0xe1, 0xf1,
  38729. 0xe1, 0xba, 0xf6, 0x01, 0xc6, 0xf2, 0xea, 0xc0, 0x97, 0x73, 0x79, 0x19,
  38730. 0x06, 0xaa, 0x62, 0x42, 0xcb, 0x21, 0x5f, 0x08, 0x97, 0x7d, 0x72, 0xb5,
  38731. 0x39, 0x4d, 0x99, 0xe3, 0xa2, 0x3f, 0xb9, 0xb4, 0xed, 0xf4, 0x61, 0x35,
  38732. 0xe1, 0x50, 0xfb, 0x56, 0x7c, 0x35, 0xfd, 0x44, 0x8a, 0x57, 0x22, 0xed,
  38733. 0x30, 0x33, 0xc3, 0x0b, 0xf1, 0x88, 0xe4, 0x44, 0x46, 0xf5, 0x73, 0x6d,
  38734. 0x9b, 0x98, 0x88, 0x92, 0xf5, 0x34, 0x85, 0x18, 0x66, 0xef, 0x70, 0xbe,
  38735. 0x7b, 0xc1, 0x0f, 0x1c, 0x78, 0x2d, 0x42, 0x13, 0x2d, 0x2f, 0x4d, 0x40,
  38736. 0x8e, 0xe2, 0x6f, 0xe0, 0x04, 0xdb, 0x58, 0xbc, 0x65, 0x80, 0xba, 0xfc,
  38737. 0x89, 0xee, 0xf3, 0x78, 0xb2, 0xd9, 0x78, 0x93, 0x6d, 0xbf, 0xd4, 0x74,
  38738. 0x24, 0xf4, 0x5c, 0x37, 0x89, 0x0c, 0x14, 0xd5, 0xbd, 0xc5, 0xfc, 0x37,
  38739. 0xe8, 0x8b, 0xe0, 0xc5, 0x89, 0xc9, 0x70, 0xb3, 0x76, 0x46, 0xce, 0x0d,
  38740. 0x7c, 0x3d, 0xa4, 0x5d, 0x02, 0x95, 0x03, 0xba, 0x24, 0xaa, 0xf7, 0xd0,
  38741. 0x75, 0x35, 0x78, 0x27, 0x9c, 0x6d, 0x2a, 0xef, 0xaa, 0xac, 0x85, 0xef,
  38742. 0x8d, 0xfc, 0xc0, 0xfc, 0x72, 0x02, 0xf4, 0xa3, 0xd3, 0x87, 0xfc, 0x4d,
  38743. 0xce, 0x3d, 0xcb, 0xc2, 0x74, 0x5b, 0xb0, 0x83, 0xc5, 0x72, 0x72, 0xd6,
  38744. 0xa1, 0x67, 0x4d, 0xa1, 0xd6, 0xaa, 0xe7, 0x9b, 0xe7, 0xc0, 0xfd, 0x86,
  38745. 0x91, 0x08, 0xfa, 0x48, 0x2f, 0x50, 0xce, 0x17, 0xea, 0x1c, 0xe3, 0x90,
  38746. 0x35, 0xe6, 0x6c, 0xc9, 0x66, 0x7d, 0x51, 0x32, 0x20, 0x0c, 0x2d, 0x4b,
  38747. 0xa1, 0xbf, 0x78, 0x87, 0xe1, 0x5a, 0x28, 0x0e, 0x9a, 0x85, 0xf6, 0x7e,
  38748. 0x39, 0x60, 0xbc, 0x64, 0x42, 0x5d, 0xf0, 0x0a, 0xd7, 0x3e, 0xbb, 0xa0,
  38749. 0x6d, 0x7c, 0xfa, 0x75, 0xee, 0x34, 0x39, 0x23, 0x0e, 0xbd, 0x50, 0x19,
  38750. 0x7a, 0x2a, 0xb7, 0x17, 0x3a, 0x8b, 0xb7, 0xb6, 0xf4, 0xd8, 0x47, 0x71,
  38751. 0x6b, 0x21, 0x1b, 0x56, 0xcc, 0xfb, 0x7b, 0x81, 0x99, 0x46, 0x88, 0x23,
  38752. 0x40, 0x49, 0x66, 0x8b, 0xac, 0x84, 0x16, 0x8a, 0x86, 0xae, 0x38, 0xc4,
  38753. 0x5b, 0x1f, 0x2b, 0xfa, 0xf2, 0x8b, 0x81, 0xc1, 0x22, 0x61, 0x61, 0x6c,
  38754. 0x43, 0x16, 0x8c, 0x1d, 0x37, 0xb2, 0xaf, 0x3c, 0x3a, 0x90, 0x33, 0xed,
  38755. 0xf5, 0x08, 0x78, 0xfd, 0x5a, 0xde, 0xd3, 0x38, 0x6d, 0xd7, 0x1c, 0x23,
  38756. 0xeb, 0xb4, 0x9b, 0x8e, 0xc2, 0x48, 0x47, 0x8e, 0x84, 0xbb, 0xc4, 0xd0,
  38757. 0xcc, 0xf9, 0x55, 0x5a, 0x57, 0xb9, 0x99, 0x52, 0x82, 0x21, 0x3b, 0x83,
  38758. 0xda, 0x8f, 0xa3, 0x88, 0x9c, 0x57, 0xe0, 0x4b, 0xc1, 0xce, 0xbe, 0xd3,
  38759. 0xea, 0xdd, 0xf2, 0x07, 0xc1, 0x73, 0x6f, 0xc0, 0x5e, 0x8e, 0x85, 0x72,
  38760. 0xab, 0x2f, 0xa9, 0xac, 0x39, 0xee, 0x05, 0x34, 0x13, 0x16, 0x1b, 0x1c,
  38761. 0x21, 0x24, 0x41, 0x49, 0x78, 0x87, 0x8b, 0x97, 0x9c, 0x9f, 0xa3, 0xa8,
  38762. 0xb9, 0xbc, 0xc6, 0xcc, 0xf2, 0xfd, 0x18, 0x2a, 0x46, 0x58, 0x5a, 0x88,
  38763. 0xa2, 0xb5, 0xcc, 0xd2, 0xda, 0xe1, 0xe3, 0x0d, 0x20, 0x23, 0x2b, 0x2f,
  38764. 0x47, 0x57, 0x5e, 0x64, 0x87, 0x97, 0x9c, 0xa7, 0xaa, 0xbc, 0xc1, 0xe4,
  38765. 0xe5, 0xea, 0x0b, 0x16, 0x3b, 0x3c, 0x3e, 0x45, 0x58, 0x63, 0x6a, 0x6f,
  38766. 0x7c, 0x8c, 0x8d, 0x92, 0x99, 0x9c, 0xad, 0xb5, 0xb7, 0xce, 0x00, 0x00,
  38767. 0x00, 0x00, 0x00, 0x00, 0x16, 0x23, 0x36, 0x4a
  38768. };
  38769. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38770. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_sig[] = {
  38771. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  38772. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  38773. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  38774. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  38775. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  38776. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  38777. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  38778. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  38779. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  38780. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  38781. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  38782. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  38783. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  38784. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  38785. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  38786. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  38787. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  38788. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  38789. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  38790. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  38791. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  38792. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  38793. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  38794. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  38795. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  38796. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  38797. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  38798. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  38799. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  38800. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  38801. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  38802. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  38803. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  38804. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  38805. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  38806. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  38807. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  38808. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  38809. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  38810. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  38811. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  38812. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  38813. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  38814. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  38815. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  38816. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  38817. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  38818. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  38819. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  38820. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  38821. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  38822. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  38823. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  38824. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  38825. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  38826. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  38827. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  38828. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  38829. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  38830. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  38831. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  38832. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  38833. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  38834. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  38835. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  38836. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  38837. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  38838. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  38839. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  38840. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  38841. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  38842. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  38843. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  38844. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  38845. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  38846. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  38847. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  38848. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  38849. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  38850. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  38851. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  38852. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  38853. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  38854. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  38855. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  38856. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  38857. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  38858. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  38859. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  38860. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  38861. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  38862. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  38863. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  38864. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  38865. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  38866. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  38867. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  38868. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  38869. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  38870. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  38871. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  38872. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  38873. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  38874. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  38875. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  38876. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  38877. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  38878. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  38879. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  38880. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  38881. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  38882. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  38883. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  38884. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  38885. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  38886. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  38887. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  38888. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  38889. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  38890. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  38891. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  38892. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  38893. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  38894. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  38895. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  38896. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  38897. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  38898. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  38899. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  38900. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  38901. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  38902. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  38903. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  38904. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  38905. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  38906. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  38907. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  38908. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  38909. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  38910. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  38911. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  38912. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  38913. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  38914. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  38915. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  38916. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  38917. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  38918. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  38919. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  38920. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  38921. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  38922. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  38923. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  38924. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  38925. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  38926. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  38927. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  38928. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  38929. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  38930. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  38931. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  38932. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  38933. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  38934. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  38935. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  38936. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  38937. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  38938. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  38939. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  38940. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  38941. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  38942. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  38943. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  38944. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  38945. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  38946. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  38947. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  38948. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  38949. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  38950. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  38951. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  38952. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  38953. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  38954. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  38955. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  38956. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  38957. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  38958. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  38959. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  38960. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  38961. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  38962. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  38963. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  38964. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  38965. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  38966. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  38967. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  38968. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  38969. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  38970. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  38971. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  38972. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  38973. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  38974. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  38975. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  38976. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  38977. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  38978. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  38979. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  38980. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  38981. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  38982. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  38983. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  38984. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  38985. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  38986. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  38987. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  38988. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  38989. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  38990. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  38991. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  38992. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  38993. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  38994. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  38995. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  38996. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  38997. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  38998. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  38999. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  39000. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  39001. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  39002. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  39003. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  39004. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  39005. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  39006. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  39007. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  39008. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  39009. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  39010. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  39011. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  39012. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46
  39013. };
  39014. #endif
  39015. wc_test_ret_t ret;
  39016. ret = dilithium_param_vfy_test(WC_ML_DSA_44, ml_dsa_44_pub_key,
  39017. (word32)sizeof(ml_dsa_44_pub_key), ml_dsa_44_sig,
  39018. (word32)sizeof(ml_dsa_44_sig));
  39019. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39020. if (ret == 0) {
  39021. ret = dilithium_param_vfy_test(WC_ML_DSA_44_DRAFT,
  39022. ml_dsa_44_draft_pub_key, (word32)sizeof(ml_dsa_44_draft_pub_key),
  39023. ml_dsa_44_draft_sig, (word32)sizeof(ml_dsa_44_draft_sig));
  39024. }
  39025. #endif
  39026. return ret;
  39027. }
  39028. #endif
  39029. #ifndef WOLFSSL_NO_ML_DSA_65
  39030. static wc_test_ret_t dilithium_param_65_vfy_test(void)
  39031. {
  39032. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_pub_key[] = {
  39033. 0x2c, 0x32, 0xfa, 0x59, 0x71, 0x16, 0x4a, 0x0e, 0x45, 0x0f, 0x21, 0xfd,
  39034. 0x65, 0xee, 0x50, 0xb0, 0xbf, 0xea, 0x8e, 0x4e, 0xa2, 0x55, 0x71, 0xa6,
  39035. 0x65, 0x48, 0x56, 0x20, 0x8a, 0x48, 0x9d, 0xd7, 0xc9, 0x2c, 0x80, 0x62,
  39036. 0x88, 0x68, 0x4d, 0x5f, 0xbe, 0x5f, 0xe5, 0xf5, 0xa4, 0x75, 0xb6, 0x88,
  39037. 0x26, 0xae, 0x7d, 0x11, 0x43, 0x89, 0xcd, 0xe9, 0x67, 0x0c, 0x91, 0x0b,
  39038. 0xd1, 0xd8, 0x8b, 0x7b, 0x73, 0x75, 0x94, 0xc1, 0xc9, 0x61, 0xc7, 0x35,
  39039. 0x21, 0x99, 0x2e, 0xab, 0xe0, 0xdf, 0x4d, 0xac, 0x0d, 0xd0, 0xa2, 0x61,
  39040. 0x5f, 0x04, 0x08, 0x83, 0x66, 0x5c, 0x67, 0x47, 0x0c, 0xab, 0x2c, 0xb7,
  39041. 0x6d, 0x0e, 0x32, 0x4c, 0x8c, 0x25, 0x80, 0xf5, 0xe5, 0x7e, 0x3b, 0xa1,
  39042. 0xc6, 0xc5, 0x87, 0xd8, 0x68, 0xb2, 0xd5, 0x67, 0xf9, 0x5a, 0x8b, 0x88,
  39043. 0xf8, 0xcd, 0x0c, 0xda, 0x4f, 0xfc, 0xd2, 0xaf, 0xb2, 0xa2, 0x38, 0x21,
  39044. 0xf9, 0xd8, 0xf1, 0x1c, 0x8d, 0xb4, 0xe8, 0xfb, 0x76, 0x36, 0x87, 0xf4,
  39045. 0x7d, 0x03, 0xc4, 0x06, 0xab, 0x87, 0xac, 0x52, 0xe8, 0xd5, 0xf7, 0x63,
  39046. 0xf0, 0xa8, 0x0b, 0x95, 0xbd, 0x07, 0xf1, 0x1d, 0x33, 0x7b, 0x8a, 0x2c,
  39047. 0xef, 0x85, 0xbe, 0xf8, 0xc1, 0x4b, 0xa2, 0xb0, 0xe0, 0x7a, 0x85, 0xfa,
  39048. 0x52, 0x36, 0x05, 0xa7, 0x65, 0x4a, 0x0c, 0x21, 0x5c, 0xc0, 0x4f, 0x18,
  39049. 0xb8, 0x66, 0x02, 0xe6, 0xd0, 0x45, 0x60, 0x56, 0xfc, 0x40, 0x94, 0xb5,
  39050. 0xa5, 0x2b, 0xc7, 0x57, 0xc3, 0xc5, 0x30, 0x72, 0x1c, 0x4c, 0x2a, 0xd5,
  39051. 0x75, 0xae, 0x43, 0x9f, 0x01, 0x71, 0xac, 0x5c, 0xdf, 0x9c, 0x0a, 0x3c,
  39052. 0xb5, 0x89, 0x07, 0x9b, 0x28, 0x25, 0x31, 0x31, 0xc5, 0xb7, 0x24, 0x53,
  39053. 0x2c, 0x3c, 0x2a, 0x96, 0xe5, 0x0d, 0xa2, 0x97, 0xa7, 0x08, 0x9d, 0x31,
  39054. 0xc0, 0xcd, 0x53, 0xd5, 0xa8, 0x58, 0xa6, 0xac, 0x43, 0x2d, 0xac, 0x39,
  39055. 0x01, 0x2c, 0x60, 0xf6, 0x82, 0x86, 0xd0, 0xaf, 0xad, 0x61, 0x3f, 0x82,
  39056. 0x80, 0xa1, 0xe1, 0x12, 0x83, 0x6e, 0x1d, 0x5e, 0xfe, 0xc6, 0x1e, 0x2a,
  39057. 0x7a, 0x44, 0xcd, 0xc2, 0x0a, 0xf5, 0xc8, 0x72, 0x3e, 0x29, 0xc7, 0x0a,
  39058. 0xd1, 0x4c, 0x17, 0xdd, 0x1f, 0xb6, 0x95, 0x34, 0xc2, 0x6c, 0xdc, 0x63,
  39059. 0xd1, 0x7e, 0xb0, 0x52, 0x06, 0x18, 0x6c, 0xb1, 0x99, 0x6a, 0xbe, 0x42,
  39060. 0xa9, 0xc0, 0x22, 0xcc, 0x09, 0x11, 0x84, 0x1f, 0x16, 0x9a, 0x0e, 0xdd,
  39061. 0x18, 0x7a, 0x39, 0x34, 0xb0, 0x49, 0x44, 0xcb, 0x88, 0x1f, 0x91, 0x93,
  39062. 0x49, 0x3f, 0xcc, 0x62, 0x56, 0x33, 0x15, 0xcb, 0x02, 0x9b, 0x33, 0xe8,
  39063. 0xd7, 0xab, 0x51, 0xc0, 0x91, 0xe0, 0x9c, 0xd2, 0xf9, 0x52, 0x05, 0x0c,
  39064. 0xbf, 0xf1, 0x97, 0x42, 0xfe, 0xd0, 0x32, 0x27, 0x34, 0xf8, 0x82, 0x2d,
  39065. 0x65, 0x3a, 0x36, 0xce, 0xd1, 0x07, 0x82, 0x3a, 0x6a, 0xaa, 0x56, 0xf1,
  39066. 0x9b, 0x98, 0xca, 0x8e, 0x55, 0xff, 0xa0, 0x74, 0xd6, 0x6a, 0x42, 0xaa,
  39067. 0x0a, 0xd4, 0x59, 0x74, 0xfb, 0xd4, 0xdb, 0x14, 0x10, 0xee, 0xca, 0x78,
  39068. 0x83, 0x83, 0x95, 0x9b, 0x77, 0xf1, 0x9a, 0x48, 0xe0, 0x8f, 0xa4, 0x5a,
  39069. 0x4d, 0xa9, 0x3f, 0x32, 0x78, 0x4a, 0x25, 0x96, 0x9c, 0x20, 0x0a, 0xcc,
  39070. 0x5b, 0xd8, 0xca, 0x19, 0x47, 0x77, 0xb8, 0x7c, 0x51, 0x3e, 0xd6, 0x30,
  39071. 0xdb, 0x45, 0xb0, 0xe6, 0x9d, 0x6f, 0xc5, 0x0a, 0x5d, 0x5f, 0x55, 0xcd,
  39072. 0x0f, 0x20, 0x22, 0x7e, 0x09, 0x99, 0xac, 0xb8, 0x9c, 0x9d, 0xf7, 0x3e,
  39073. 0x7e, 0x07, 0xd7, 0xbc, 0x21, 0x76, 0x8c, 0x27, 0x81, 0x94, 0xab, 0x57,
  39074. 0x4a, 0xe2, 0x91, 0x1c, 0xa4, 0x77, 0x4a, 0xd2, 0x96, 0x52, 0x9d, 0x33,
  39075. 0xb5, 0x58, 0x70, 0xd7, 0xff, 0x22, 0xe8, 0x14, 0xea, 0xd0, 0x8c, 0xd4,
  39076. 0x06, 0x08, 0xd8, 0x73, 0x66, 0x4b, 0x93, 0x41, 0xc9, 0x73, 0x5b, 0x07,
  39077. 0x5f, 0x31, 0xc5, 0x25, 0x98, 0x7b, 0x7b, 0xa5, 0x26, 0x83, 0x94, 0x22,
  39078. 0x42, 0x1c, 0x51, 0xe6, 0x80, 0x48, 0xca, 0xd4, 0x53, 0x40, 0x3a, 0xee,
  39079. 0x2c, 0x29, 0x07, 0xed, 0xdf, 0x97, 0x44, 0x19, 0xe5, 0xe5, 0x35, 0x66,
  39080. 0x1f, 0xbd, 0x29, 0x77, 0x0c, 0x15, 0x6c, 0x95, 0x08, 0x81, 0xe0, 0x76,
  39081. 0x86, 0x5e, 0x6d, 0x77, 0x78, 0x76, 0x07, 0xdd, 0x21, 0x97, 0x59, 0xdb,
  39082. 0xd4, 0xbd, 0xb6, 0x4c, 0x3f, 0x07, 0x93, 0xb6, 0x4a, 0xce, 0xf7, 0x08,
  39083. 0x86, 0xfd, 0x9c, 0x03, 0x08, 0x94, 0x00, 0xea, 0x4b, 0xd6, 0x1e, 0x17,
  39084. 0xfb, 0xb5, 0xba, 0xde, 0x25, 0x95, 0xe7, 0xf8, 0x97, 0x9e, 0x99, 0xae,
  39085. 0x5d, 0xdd, 0xf6, 0x32, 0x1a, 0xf2, 0x4f, 0xcf, 0x0c, 0x17, 0x55, 0xb8,
  39086. 0xfb, 0xae, 0xc8, 0x46, 0xb0, 0x3e, 0x86, 0x2b, 0x5e, 0xef, 0x36, 0xca,
  39087. 0x24, 0xed, 0x32, 0x5b, 0xc8, 0xfb, 0x88, 0x35, 0x6a, 0x26, 0xfe, 0x06,
  39088. 0x54, 0x0c, 0x3e, 0x2c, 0x71, 0xdf, 0x98, 0xf0, 0xbb, 0xb2, 0xe0, 0x9d,
  39089. 0xf7, 0xeb, 0xce, 0x07, 0xfa, 0xc4, 0xab, 0x88, 0xc3, 0x14, 0x33, 0x60,
  39090. 0x48, 0xcf, 0x39, 0x26, 0x90, 0xac, 0xfa, 0x39, 0x6f, 0x2d, 0x9d, 0x6d,
  39091. 0x15, 0x7f, 0x84, 0x6b, 0x0a, 0x1c, 0xf4, 0x6c, 0x78, 0x62, 0x52, 0x93,
  39092. 0x2c, 0x7e, 0x9f, 0x4a, 0x51, 0x7a, 0x2e, 0xad, 0xea, 0xe4, 0xe5, 0x9c,
  39093. 0x15, 0x15, 0x28, 0x4d, 0x3e, 0x5e, 0xb4, 0x3b, 0xff, 0x81, 0xe0, 0x56,
  39094. 0x44, 0x33, 0x33, 0xd9, 0x4b, 0xb2, 0x23, 0x60, 0xed, 0x0d, 0xa5, 0x4e,
  39095. 0x9f, 0x7d, 0xbc, 0x6e, 0x3a, 0xf9, 0x7e, 0x16, 0x47, 0x66, 0xb1, 0x6c,
  39096. 0xc7, 0x26, 0x62, 0x9b, 0x3c, 0x53, 0xb3, 0xa1, 0x16, 0x62, 0x31, 0x64,
  39097. 0xd2, 0xbb, 0x28, 0x5c, 0xe8, 0x21, 0xc3, 0xfc, 0xc3, 0x6d, 0xa7, 0x35,
  39098. 0x4d, 0x57, 0xe0, 0xbd, 0x54, 0x1a, 0x84, 0xf7, 0x9c, 0x8a, 0x54, 0x3d,
  39099. 0x59, 0xb3, 0xa2, 0x46, 0x3b, 0x16, 0x48, 0x3b, 0x3a, 0x3c, 0x5e, 0x88,
  39100. 0xc3, 0x60, 0x63, 0x7e, 0xca, 0x68, 0xb7, 0x2f, 0x2b, 0xb5, 0x62, 0x2e,
  39101. 0x51, 0x89, 0xbe, 0x78, 0xf7, 0xfa, 0x19, 0xcc, 0xca, 0x87, 0x9a, 0xf5,
  39102. 0xef, 0x0d, 0x21, 0x08, 0x3b, 0xd6, 0x9a, 0x94, 0xc5, 0xd1, 0x1b, 0xa9,
  39103. 0x7c, 0xc8, 0x9f, 0x9a, 0xb0, 0xb8, 0xf7, 0x02, 0x12, 0x31, 0x70, 0x52,
  39104. 0x52, 0xda, 0xb5, 0x9a, 0x08, 0x20, 0xc3, 0xc4, 0x0c, 0x6a, 0x34, 0x58,
  39105. 0x75, 0x9b, 0xdc, 0x1a, 0x6a, 0x37, 0x42, 0x9f, 0x16, 0x70, 0xbb, 0x39,
  39106. 0x86, 0xbd, 0x09, 0x9c, 0x04, 0x44, 0xbe, 0x1a, 0xe5, 0xe9, 0x50, 0x9b,
  39107. 0x14, 0x50, 0x4f, 0x00, 0xba, 0xb0, 0xf6, 0x36, 0x4d, 0x69, 0x16, 0x11,
  39108. 0x40, 0x5a, 0x4e, 0x8b, 0x39, 0xb4, 0xf1, 0xb2, 0x11, 0x36, 0x2f, 0x02,
  39109. 0x15, 0xca, 0x78, 0xde, 0x75, 0x07, 0x64, 0x72, 0xfd, 0xd4, 0x48, 0xdd,
  39110. 0xfb, 0xf5, 0x8a, 0x3d, 0xa8, 0x8e, 0x14, 0xd1, 0x69, 0xe3, 0x21, 0x50,
  39111. 0x39, 0xfd, 0xd0, 0x3b, 0xa0, 0x22, 0x61, 0x5c, 0x7e, 0x88, 0x91, 0xe1,
  39112. 0xf0, 0xf6, 0x16, 0x23, 0xdb, 0xdb, 0x50, 0x0e, 0x39, 0xcc, 0x86, 0xf1,
  39113. 0xab, 0x89, 0x60, 0xb0, 0xac, 0x28, 0xc6, 0x57, 0xe4, 0xee, 0xa9, 0x1b,
  39114. 0xae, 0x78, 0xc5, 0x67, 0x1a, 0xeb, 0xb3, 0x43, 0xbc, 0xea, 0x11, 0x0c,
  39115. 0x64, 0xf6, 0xd2, 0x52, 0xa0, 0x7e, 0xcd, 0x6d, 0x84, 0x8c, 0xf8, 0x80,
  39116. 0xb7, 0xdb, 0x26, 0x91, 0x4a, 0xa0, 0x61, 0x69, 0x2f, 0x6f, 0x1c, 0x9d,
  39117. 0x2a, 0x20, 0x44, 0xdc, 0x58, 0xaf, 0x7d, 0xfe, 0x4d, 0xa2, 0x10, 0x21,
  39118. 0x88, 0xef, 0x42, 0x2e, 0x8e, 0xfb, 0x63, 0xbc, 0xc8, 0x26, 0xe7, 0x80,
  39119. 0xa5, 0xbf, 0xe0, 0x7a, 0xcb, 0xf3, 0x31, 0x1c, 0xd9, 0xa3, 0x12, 0x00,
  39120. 0x2f, 0x20, 0xc6, 0xc1, 0x15, 0xfd, 0x5b, 0x0d, 0x8a, 0x4d, 0xfb, 0x84,
  39121. 0x4d, 0xb4, 0x64, 0xeb, 0x12, 0xf3, 0x78, 0x6b, 0x4d, 0xc6, 0x98, 0x46,
  39122. 0x4c, 0xb3, 0xb4, 0x59, 0xdc, 0xb7, 0xdc, 0xbb, 0x56, 0x0f, 0x09, 0x14,
  39123. 0x28, 0x43, 0x9f, 0xb8, 0x75, 0xed, 0xcb, 0x97, 0x25, 0xaf, 0xa5, 0xeb,
  39124. 0x46, 0x14, 0xa6, 0x38, 0x68, 0x06, 0xe0, 0x6e, 0x55, 0x68, 0x6b, 0xf3,
  39125. 0xd8, 0x6d, 0x59, 0x65, 0x65, 0xff, 0x48, 0xfd, 0xdb, 0x3d, 0xe2, 0x21,
  39126. 0xb4, 0x7b, 0x78, 0x6a, 0x2e, 0x28, 0xb8, 0x21, 0xc4, 0x72, 0xf4, 0xef,
  39127. 0xfb, 0x74, 0x43, 0x29, 0xf2, 0x30, 0xc9, 0xca, 0x78, 0x93, 0x72, 0xfd,
  39128. 0x84, 0xa4, 0x95, 0xe0, 0xcd, 0xb1, 0x48, 0x29, 0xe7, 0xd1, 0x27, 0xf7,
  39129. 0xdc, 0x31, 0x6e, 0x00, 0x04, 0xd7, 0x7c, 0xfd, 0x2d, 0x25, 0xe9, 0xdb,
  39130. 0xc2, 0xb8, 0x14, 0x26, 0xed, 0x63, 0xb1, 0x50, 0x0a, 0x3c, 0xb2, 0x79,
  39131. 0x98, 0x79, 0x81, 0x2d, 0xdb, 0x60, 0x97, 0x99, 0xc0, 0x0a, 0x89, 0x9f,
  39132. 0x90, 0x19, 0x0b, 0xb3, 0x97, 0xd2, 0xf7, 0x50, 0xa5, 0x1d, 0x7d, 0x71,
  39133. 0x75, 0xe6, 0x58, 0x62, 0x53, 0x95, 0x40, 0x9e, 0xc7, 0xd3, 0x72, 0xa1,
  39134. 0xae, 0x07, 0xb3, 0x8a, 0x56, 0x61, 0x99, 0x81, 0x3e, 0xe4, 0x5e, 0x78,
  39135. 0x57, 0xd1, 0x8a, 0xc4, 0x04, 0x38, 0x13, 0xa0, 0x5d, 0x68, 0x6d, 0x22,
  39136. 0xae, 0xda, 0xfc, 0x67, 0xbb, 0xfb, 0x8e, 0x1a, 0xdc, 0x24, 0xf7, 0xc8,
  39137. 0xf9, 0x92, 0x6f, 0x4e, 0xb5, 0xe7, 0x6d, 0x13, 0x88, 0x05, 0x5c, 0xbb,
  39138. 0xe0, 0x24, 0x2a, 0x96, 0xc6, 0x70, 0x52, 0x14, 0xd0, 0xd9, 0xd8, 0xb2,
  39139. 0x5b, 0xdc, 0x85, 0xcf, 0x62, 0xb4, 0xcf, 0x77, 0xf1, 0xe5, 0x51, 0xeb,
  39140. 0xef, 0xe9, 0x3e, 0xf0, 0x16, 0xd2, 0xcc, 0x38, 0x0a, 0x47, 0x91, 0xc0,
  39141. 0xe0, 0x14, 0x1a, 0xf9, 0x74, 0xd1, 0x32, 0x8b, 0x02, 0x36, 0x05, 0x55,
  39142. 0x62, 0xa7, 0xae, 0x77, 0xb0, 0x01, 0x3d, 0x2c, 0x91, 0xbe, 0xfa, 0xdd,
  39143. 0x9c, 0x17, 0x42, 0xc1, 0x01, 0x4d, 0xd8, 0x27, 0x3c, 0x10, 0x82, 0x66,
  39144. 0x11, 0x91, 0x8b, 0xc8, 0x52, 0xd5, 0xc1, 0x1d, 0xee, 0xb2, 0x90, 0x17,
  39145. 0xed, 0xf3, 0xad, 0xa5, 0xd5, 0xeb, 0xf2, 0x9b, 0x78, 0xbf, 0x2d, 0x5a,
  39146. 0xad, 0xe5, 0x53, 0xe6, 0xc1, 0x3b, 0xd8, 0xf3, 0x6b, 0xc5, 0x4c, 0x87,
  39147. 0x0a, 0xe3, 0xc8, 0xc7, 0xe5, 0x42, 0x2c, 0xe2, 0x13, 0x1a, 0xe7, 0x27,
  39148. 0x20, 0x3e, 0x95, 0x13, 0x1e, 0xbb, 0x03, 0xae, 0xc0, 0x84, 0x14, 0x6d,
  39149. 0x7b, 0xf7, 0x98, 0x08, 0x18, 0x12, 0xb4, 0x4f, 0x99, 0x4a, 0xcf, 0xd0,
  39150. 0x4a, 0x5d, 0x21, 0x16, 0xf6, 0xdf, 0x10, 0xc7, 0xbe, 0xe6, 0x79, 0x3b,
  39151. 0x35, 0x2a, 0xa6, 0xd6, 0x19, 0x9c, 0xde, 0xbd, 0xaf, 0x72, 0xd2, 0x25,
  39152. 0xe0, 0xa4, 0xde, 0x99, 0x44, 0x18, 0x66, 0x41, 0xc7, 0x56, 0xf7, 0xdc,
  39153. 0x32, 0x56, 0x57, 0x39, 0x18, 0x31, 0xc8, 0x75, 0x01, 0xc3, 0xf3, 0x46,
  39154. 0xcf, 0xbf, 0xc6, 0x10, 0xb5, 0x1c, 0x38, 0xf9, 0xa4, 0xa5, 0x44, 0xa1,
  39155. 0x0b, 0x25, 0x48, 0x9c, 0xd3, 0x1c, 0x55, 0x54, 0x15, 0x9f, 0xe3, 0x74,
  39156. 0x5b, 0xb1, 0x92, 0xb6, 0x52, 0x61, 0xba, 0x2f, 0x53, 0x91, 0x17, 0x44,
  39157. 0x94, 0x00, 0xe4, 0x43, 0xa0, 0xe7, 0x0d, 0xaa, 0x8a, 0x5b, 0x81, 0x43,
  39158. 0xad, 0xfb, 0x50, 0xfe, 0xcf, 0x85, 0x2d, 0xfa, 0xc8, 0x1d, 0xad, 0xc8,
  39159. 0x7a, 0x7c, 0x5e, 0xf3, 0x90, 0x35, 0x5e, 0x67, 0xce, 0x57, 0x4d, 0xa0,
  39160. 0x22, 0x9e, 0x07, 0x4a, 0xf5, 0x9e, 0x5f, 0x91, 0x45, 0xd8, 0x62, 0xe0,
  39161. 0xf3, 0x87, 0x3b, 0xb7, 0x89, 0x2f, 0xdf, 0x8b, 0x82, 0xb1, 0x86, 0xc3,
  39162. 0xa4, 0xa3, 0x68, 0xc7, 0x73, 0x9e, 0x68, 0x8d, 0x24, 0x6a, 0x29, 0x94,
  39163. 0x58, 0x57, 0x4b, 0x81, 0x00, 0xe2, 0x2b, 0x94, 0x0a, 0xf5, 0x96, 0xa3,
  39164. 0x23, 0x9a, 0x7b, 0xd0, 0x2d, 0xcb, 0x6a, 0x8e, 0xae, 0x1b, 0x1c, 0x34,
  39165. 0xed, 0x30, 0x4e, 0xca, 0x29, 0x21, 0xfc, 0x3d, 0x70, 0x11, 0xc1, 0x5f,
  39166. 0x3e, 0xc2, 0x9e, 0x88, 0x71, 0x29, 0xa3, 0x8f, 0x92, 0xf5, 0x46, 0x77,
  39167. 0xd5, 0x47, 0x2d, 0x2b, 0x66, 0x1c, 0x07, 0xf0, 0xfc, 0x7b, 0xa0, 0x13,
  39168. 0x00, 0xae, 0xa5, 0x61, 0x92, 0x36, 0xeb, 0x7e, 0x43, 0x91, 0x20, 0x72,
  39169. 0xe5, 0xba, 0x7f, 0x79, 0x23, 0x12, 0x3e, 0xb2, 0x4b, 0x13, 0xa1, 0x8c,
  39170. 0x84, 0x72, 0x3b, 0x45, 0x62, 0xcf, 0x2e, 0x78, 0xc4, 0x9c, 0x22, 0x09,
  39171. 0xfa, 0x59, 0x9d, 0xdf, 0x13, 0x54, 0x66, 0xe2, 0x6f, 0xfa, 0xb5, 0x2a,
  39172. 0x27, 0x3e, 0x17, 0x82, 0xf3, 0x2a, 0x4d, 0x36, 0xd3, 0xf0, 0x8d, 0x43,
  39173. 0x40, 0x2c, 0x84, 0x68, 0xbe, 0x40, 0x50, 0x7d, 0xa3, 0x27, 0x5e, 0xde,
  39174. 0x4d, 0x04, 0x6f, 0xe8, 0x96, 0x9c, 0x7a, 0x1d, 0xb8, 0x2b, 0x8a, 0xb1,
  39175. 0x6e, 0xe2, 0x36, 0x07, 0x22, 0x50, 0xd9, 0x71, 0x93, 0x48, 0xb5, 0x51,
  39176. 0xce, 0x2a, 0x64, 0x6b, 0x11, 0xa6, 0xb9, 0x40, 0x2d, 0x6c, 0xd2, 0x76,
  39177. 0x52, 0xc6, 0xe3, 0xa6, 0x6b, 0xd2, 0x3f, 0x39, 0xd2, 0x13, 0x28, 0xa4,
  39178. 0xa9, 0x58, 0x99, 0xe8, 0x3d, 0x08, 0xfa, 0x3c, 0x34, 0x39, 0x4d, 0x7d,
  39179. 0x5e, 0x10, 0x72, 0x51, 0x96, 0x1d, 0x4b, 0xd9, 0x3e, 0xc9, 0x22, 0x4c,
  39180. 0x72, 0x63, 0xf8, 0x87, 0x4b, 0xe7, 0x41, 0xac, 0xcd, 0xd6, 0x34, 0xa2,
  39181. 0xe1, 0xe8, 0x66, 0x81, 0x04, 0x7d, 0x70, 0x95, 0xba, 0x37, 0x86, 0x9e,
  39182. 0x1f, 0x9a, 0x1b, 0xe4, 0x35, 0xac, 0xe6, 0xcf, 0x48, 0x55, 0x6e, 0xbb,
  39183. 0x9d, 0x40, 0x79, 0x96, 0xdd, 0xac, 0xf8, 0xf5, 0x99, 0xad, 0x43, 0x0d,
  39184. 0xad, 0xa9, 0x62, 0xc0, 0x70, 0x8b, 0x50, 0x9b, 0xca, 0x0d, 0x3e, 0x54,
  39185. 0x9c, 0x27, 0xd5, 0x9e, 0x20, 0xe2, 0xe0, 0xb0, 0xb0, 0xbe, 0x8e, 0x56,
  39186. 0x43, 0x95, 0x9b, 0x34, 0xd1, 0x05, 0x28, 0xa0, 0xee, 0xd9, 0xab, 0x6a,
  39187. 0xa7, 0xbb, 0xb7, 0x1b, 0x3a, 0x5d, 0x33, 0x97, 0x25, 0x54, 0xe4, 0x0e,
  39188. 0x64, 0x79, 0xed, 0x16, 0x62, 0x89, 0x70, 0x4a, 0xa6, 0x47, 0x40, 0xd7,
  39189. 0xa3, 0xd2, 0x6f, 0x28, 0xdd, 0xc5, 0x04, 0xab, 0x7e, 0x7e, 0x1e, 0xb0,
  39190. 0x19, 0x02, 0x48, 0xb5, 0x88, 0x82, 0x75, 0xaf, 0x66, 0x74, 0xca, 0xf6,
  39191. 0xd7, 0xe8, 0x6d, 0xfa, 0x5e, 0xfa, 0xaf, 0xa8, 0x04, 0xaa, 0x2c, 0x09,
  39192. 0xf1, 0x4c, 0x36, 0x75, 0xb5, 0xdc, 0xe8, 0x04, 0x80, 0xd3, 0x14, 0x78,
  39193. 0x09, 0x5b, 0xfd, 0x52, 0x6f, 0xd9, 0x3c, 0x1c, 0x02, 0x3b, 0x77, 0xb8,
  39194. 0xa1, 0xe9, 0xa4, 0xb7, 0x42, 0x62, 0xee, 0xea, 0x43, 0xf3, 0xd8, 0xd0,
  39195. 0x7a, 0x53, 0x91, 0x34, 0x7f, 0xe7, 0x9a, 0xc6
  39196. };
  39197. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39198. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_pub_key[] = {
  39199. 0x15, 0xc9, 0xe5, 0x53, 0x2f, 0xd8, 0x1f, 0xb4, 0xa3, 0x9f,
  39200. 0xae, 0xad, 0xb3, 0x10, 0xd0, 0x72, 0x69, 0xd3, 0x02, 0xf3,
  39201. 0xdf, 0x67, 0x5a, 0x31, 0x52, 0x19, 0xca, 0x39, 0x27, 0x77,
  39202. 0x61, 0x6d, 0x0f, 0xc1, 0x33, 0x26, 0x09, 0xf0, 0xf9, 0x4d,
  39203. 0x12, 0x7a, 0xef, 0xf7, 0x21, 0x26, 0x2c, 0xe0, 0xe2, 0x92,
  39204. 0x1f, 0x9d, 0xd1, 0xaa, 0xaf, 0x08, 0x14, 0xf2, 0xaa, 0x24,
  39205. 0x99, 0x0f, 0x20, 0x57, 0x35, 0x04, 0x32, 0x96, 0x8e, 0x6e,
  39206. 0x10, 0x64, 0xe3, 0xe3, 0x57, 0x26, 0x33, 0x32, 0x7b, 0xe4,
  39207. 0x18, 0x41, 0x77, 0xd3, 0x24, 0x63, 0x3d, 0x11, 0xea, 0xdc,
  39208. 0xbe, 0x59, 0xff, 0x8d, 0xc2, 0xe4, 0xc7, 0x04, 0xf3, 0xd4,
  39209. 0xe0, 0x1d, 0x5e, 0x09, 0x46, 0xbf, 0x02, 0x05, 0xc7, 0xa6,
  39210. 0xb7, 0x82, 0x40, 0x1f, 0x55, 0xe9, 0x77, 0x82, 0xc0, 0xcc,
  39211. 0x86, 0x99, 0x19, 0x99, 0xa2, 0xc9, 0x1b, 0x4f, 0xdd, 0x49,
  39212. 0x4c, 0x78, 0x0a, 0x58, 0xb8, 0xf0, 0x23, 0xac, 0x1a, 0x71,
  39213. 0x57, 0x6d, 0xd6, 0x3a, 0x3a, 0x6f, 0x93, 0xb3, 0x2b, 0x09,
  39214. 0xbe, 0xec, 0x7b, 0x5b, 0xf7, 0x3a, 0xed, 0xf9, 0xd0, 0xb1,
  39215. 0xfe, 0x9f, 0x9b, 0xec, 0x11, 0xb6, 0x6b, 0xd1, 0xb6, 0x00,
  39216. 0x72, 0x7f, 0x68, 0x9a, 0x61, 0xa5, 0xf5, 0x6e, 0xe9, 0x46,
  39217. 0xa4, 0x82, 0x08, 0x9f, 0x50, 0x4c, 0x75, 0xc3, 0x48, 0x85,
  39218. 0x76, 0x39, 0xea, 0x0c, 0xf2, 0xe8, 0x7e, 0x48, 0x69, 0xd9,
  39219. 0x6f, 0x9a, 0x89, 0x7d, 0x98, 0xc1, 0x16, 0xdc, 0x2f, 0xc7,
  39220. 0x0a, 0x11, 0xa8, 0xbb, 0xe7, 0x91, 0xb1, 0x0f, 0x0e, 0xf0,
  39221. 0xb4, 0xc8, 0x41, 0x7e, 0x62, 0x9e, 0x3c, 0x30, 0x4c, 0xbc,
  39222. 0x4c, 0xeb, 0x37, 0xaf, 0x48, 0x72, 0x59, 0x64, 0x8e, 0xfb,
  39223. 0x77, 0x11, 0x28, 0xdd, 0x30, 0x52, 0x8e, 0x69, 0x8c, 0x9f,
  39224. 0x3d, 0xec, 0xdf, 0xa7, 0x5f, 0x42, 0x18, 0xda, 0xba, 0x1a,
  39225. 0x96, 0x91, 0x7d, 0x62, 0xd5, 0x52, 0xff, 0x44, 0xc9, 0x1d,
  39226. 0x29, 0xa6, 0xb9, 0x03, 0x9a, 0x26, 0x26, 0xcf, 0x57, 0x40,
  39227. 0x70, 0x7e, 0x2b, 0xbd, 0xf0, 0x81, 0x71, 0x0f, 0x0b, 0x2e,
  39228. 0x9b, 0x03, 0xba, 0x31, 0x41, 0x68, 0x37, 0xc8, 0xff, 0xea,
  39229. 0xc4, 0x73, 0xa5, 0xf9, 0xc2, 0x92, 0x78, 0x0c, 0xe7, 0xfd,
  39230. 0x5d, 0xb2, 0x01, 0xb5, 0x8d, 0xeb, 0x64, 0xd4, 0x14, 0xea,
  39231. 0x7a, 0xd1, 0x42, 0xc8, 0x99, 0xe4, 0x7d, 0x5b, 0x7e, 0x3b,
  39232. 0x8f, 0xab, 0x82, 0x12, 0xdf, 0xbb, 0xa1, 0x45, 0x30, 0xc9,
  39233. 0x0f, 0xb9, 0xe5, 0xba, 0xe6, 0x8a, 0xf3, 0x78, 0x61, 0xcc,
  39234. 0x9f, 0xe1, 0x46, 0x2a, 0x9a, 0x18, 0x0e, 0x2a, 0x57, 0xf3,
  39235. 0xe5, 0x56, 0xd1, 0x42, 0x48, 0xe1, 0x5a, 0x8e, 0x33, 0xce,
  39236. 0x19, 0xe5, 0x3e, 0x7f, 0x00, 0x70, 0x9c, 0x4c, 0xd3, 0xe1,
  39237. 0x0c, 0xa1, 0x7e, 0xd4, 0xa9, 0x9e, 0x8b, 0xe2, 0xf0, 0xac,
  39238. 0xdb, 0xa6, 0x72, 0x75, 0x67, 0xa6, 0x57, 0xed, 0x79, 0x2e,
  39239. 0xca, 0x8d, 0xeb, 0x9b, 0x9e, 0xb7, 0xbf, 0x30, 0x02, 0x2b,
  39240. 0xb3, 0x43, 0x89, 0x9b, 0xa8, 0x88, 0xa5, 0xbb, 0x33, 0xd9,
  39241. 0x99, 0x30, 0x7c, 0xc7, 0xd4, 0x28, 0x5e, 0x5e, 0x3f, 0x9d,
  39242. 0x6d, 0x35, 0x75, 0x33, 0x8e, 0xff, 0x84, 0x2e, 0x2d, 0xda,
  39243. 0xf0, 0xff, 0x70, 0xe5, 0xb5, 0x62, 0x96, 0x33, 0x3a, 0xd9,
  39244. 0xb5, 0x82, 0x25, 0x81, 0x81, 0x40, 0x5d, 0x4f, 0x11, 0x86,
  39245. 0x63, 0x1a, 0x06, 0xc1, 0x67, 0xc7, 0x49, 0x03, 0xc7, 0xe4,
  39246. 0x6f, 0xb4, 0x13, 0x3e, 0x57, 0x62, 0xfd, 0x8a, 0xc6, 0x2b,
  39247. 0x65, 0x5b, 0xa4, 0x29, 0x57, 0x8d, 0xde, 0xa5, 0xee, 0x32,
  39248. 0xc2, 0x76, 0x03, 0xca, 0xce, 0xc1, 0x48, 0xec, 0x45, 0xcf,
  39249. 0x30, 0x21, 0x28, 0x7f, 0x10, 0x47, 0xd2, 0xdb, 0xee, 0xca,
  39250. 0x5b, 0x0f, 0xd5, 0x39, 0x3a, 0xc3, 0xa6, 0x78, 0xb2, 0x15,
  39251. 0xaf, 0x82, 0x3c, 0x2f, 0xc4, 0x51, 0x5c, 0x52, 0xad, 0xf2,
  39252. 0x89, 0x92, 0x8e, 0xf3, 0x50, 0x38, 0xed, 0xf8, 0xc9, 0x14,
  39253. 0x4c, 0xe4, 0xa3, 0x9a, 0xaf, 0xc4, 0x5c, 0xf3, 0x9f, 0xc3,
  39254. 0xa3, 0xc0, 0xbe, 0x45, 0x1b, 0x21, 0x63, 0xfa, 0xe0, 0xe0,
  39255. 0x91, 0x2b, 0x42, 0xca, 0x91, 0xfb, 0x5e, 0x97, 0x9a, 0x0a,
  39256. 0xd4, 0x88, 0xba, 0xb8, 0x22, 0xc6, 0xbf, 0x56, 0x58, 0x1e,
  39257. 0x92, 0xa9, 0x9d, 0xa7, 0xed, 0xc9, 0xab, 0x54, 0x4f, 0x75,
  39258. 0x8d, 0x42, 0xc1, 0xe1, 0x61, 0xd0, 0x91, 0x9a, 0x3a, 0x40,
  39259. 0x9a, 0xa3, 0xfb, 0x7b, 0x4e, 0xf0, 0x85, 0xf0, 0xdc, 0x40,
  39260. 0x72, 0x9f, 0x05, 0xa8, 0xbe, 0x95, 0x5a, 0x7f, 0xba, 0x75,
  39261. 0x00, 0x6e, 0x95, 0x76, 0xbd, 0xb2, 0x40, 0xf5, 0xb0, 0x64,
  39262. 0x0a, 0x2f, 0x06, 0x3d, 0x9f, 0xac, 0x6a, 0xa5, 0x46, 0x5a,
  39263. 0x85, 0xa4, 0x6f, 0xee, 0x27, 0xa0, 0xeb, 0x5f, 0x1f, 0x91,
  39264. 0xbd, 0x2b, 0x02, 0x16, 0xdf, 0x74, 0x97, 0x2c, 0xd0, 0xa8,
  39265. 0x9f, 0x3a, 0x7b, 0xdf, 0x3e, 0x98, 0x4a, 0x91, 0xdc, 0x19,
  39266. 0x96, 0x88, 0x75, 0x21, 0x1a, 0x6a, 0xa8, 0x4b, 0x1f, 0x35,
  39267. 0xd1, 0x92, 0xf5, 0x76, 0xf4, 0x72, 0x55, 0x13, 0xdb, 0x5d,
  39268. 0x07, 0x8d, 0xd9, 0x72, 0xe4, 0x75, 0xde, 0x80, 0xbc, 0xe9,
  39269. 0x9c, 0xf0, 0x5c, 0x6a, 0x8a, 0x0e, 0x34, 0xf6, 0x3f, 0x5c,
  39270. 0xef, 0x0e, 0xcc, 0x52, 0x38, 0x2d, 0x7b, 0xc2, 0x1b, 0x69,
  39271. 0x9f, 0xe5, 0xed, 0x14, 0xb0, 0x91, 0x0b, 0xe9, 0x4d, 0x34,
  39272. 0xd5, 0xaa, 0xd4, 0xd2, 0x46, 0x39, 0x45, 0x7e, 0x85, 0x2f,
  39273. 0xdb, 0x89, 0xf4, 0xff, 0x05, 0x74, 0x51, 0xba, 0xdd, 0xee,
  39274. 0xf6, 0xc2, 0xc1, 0x0a, 0x8f, 0xd9, 0xeb, 0xc7, 0x61, 0x30,
  39275. 0x8f, 0x86, 0x8b, 0x1f, 0x82, 0xc1, 0x22, 0xfd, 0x83, 0xf4,
  39276. 0x5d, 0xc5, 0x94, 0xf5, 0xd7, 0x17, 0xc7, 0x7b, 0x71, 0xf5,
  39277. 0x5e, 0x15, 0x49, 0x70, 0xb2, 0x57, 0xa0, 0xc0, 0x57, 0x63,
  39278. 0x53, 0x35, 0xb6, 0x52, 0x20, 0x7b, 0x83, 0xd4, 0x57, 0x63,
  39279. 0x25, 0x8e, 0x83, 0xb3, 0x8e, 0x26, 0x1f, 0x09, 0xde, 0x14,
  39280. 0xd6, 0xa6, 0xfc, 0xe5, 0x93, 0x3c, 0x88, 0x8e, 0xf5, 0x10,
  39281. 0x57, 0xb9, 0xc9, 0x9b, 0xff, 0x72, 0x9d, 0x3d, 0x3f, 0x97,
  39282. 0xd9, 0x3c, 0x20, 0xe2, 0x57, 0xfd, 0x2a, 0x5c, 0x17, 0x12,
  39283. 0xe6, 0x08, 0xaf, 0xe4, 0x26, 0x96, 0xb9, 0x6d, 0xc3, 0xac,
  39284. 0x22, 0xf3, 0x8b, 0x89, 0xde, 0xc7, 0x8a, 0x93, 0x06, 0xf7,
  39285. 0x1d, 0x08, 0x21, 0x36, 0x16, 0x74, 0x2b, 0x97, 0x23, 0xe4,
  39286. 0x79, 0x31, 0x08, 0x23, 0x62, 0x30, 0x67, 0xe2, 0xed, 0x30,
  39287. 0x9b, 0x0c, 0xf9, 0x08, 0x7a, 0x29, 0x73, 0xc6, 0x77, 0x8a,
  39288. 0xbb, 0x2a, 0x1c, 0x66, 0xd0, 0xdd, 0x9e, 0xa3, 0xe9, 0x62,
  39289. 0xcc, 0xb7, 0x88, 0x25, 0x4a, 0x5f, 0xbc, 0xaa, 0xe3, 0xe4,
  39290. 0x4f, 0xec, 0xa6, 0x8e, 0xa6, 0xa4, 0x1b, 0x22, 0x2b, 0x2c,
  39291. 0x8f, 0x57, 0x7f, 0xb7, 0x33, 0xfe, 0x16, 0x43, 0x85, 0xc5,
  39292. 0xd2, 0x95, 0xe6, 0xb9, 0x21, 0x68, 0x88, 0x98, 0x33, 0x8c,
  39293. 0x1d, 0x15, 0x9c, 0x4d, 0x62, 0x1f, 0x6b, 0xe8, 0x7a, 0x2d,
  39294. 0x6b, 0x0e, 0xc3, 0xde, 0x1a, 0xa8, 0xed, 0x67, 0xb3, 0xb3,
  39295. 0x36, 0x5b, 0x4b, 0xcb, 0xe8, 0xa8, 0x5c, 0x0b, 0x2f, 0xca,
  39296. 0xd7, 0x71, 0xe8, 0x85, 0xe7, 0x4d, 0xe5, 0x7b, 0x45, 0xed,
  39297. 0xb2, 0x4c, 0x69, 0x04, 0x7e, 0x4f, 0xc0, 0xef, 0x1a, 0xca,
  39298. 0x0d, 0xa6, 0xc4, 0x79, 0x15, 0x78, 0x9c, 0xd2, 0x91, 0x3c,
  39299. 0x32, 0x55, 0x40, 0xe7, 0xcb, 0x7e, 0xde, 0x07, 0xa6, 0x97,
  39300. 0x00, 0x2d, 0x70, 0xf6, 0x3d, 0x15, 0xdf, 0x29, 0x8e, 0xa3,
  39301. 0x96, 0x6d, 0xf2, 0xbb, 0xa5, 0x1b, 0x7b, 0x58, 0x30, 0xf6,
  39302. 0x17, 0xbd, 0xda, 0x13, 0xf7, 0x33, 0xc2, 0x62, 0x32, 0xd4,
  39303. 0x1c, 0x2e, 0x31, 0x74, 0x92, 0xad, 0x99, 0x8c, 0x0e, 0x7c,
  39304. 0x50, 0x21, 0xcd, 0xff, 0x41, 0xeb, 0xd1, 0xca, 0x14, 0xb7,
  39305. 0xb2, 0x31, 0x2f, 0xbe, 0x16, 0xce, 0x4f, 0x26, 0x16, 0x04,
  39306. 0xc2, 0xaf, 0xbe, 0x0d, 0x24, 0xab, 0x9a, 0x21, 0x37, 0x06,
  39307. 0xac, 0x50, 0x23, 0xf1, 0xbe, 0x5c, 0xbb, 0x64, 0xf3, 0xd3,
  39308. 0x66, 0xa3, 0xb8, 0xbe, 0x8b, 0x49, 0x8d, 0xf6, 0xc7, 0xb9,
  39309. 0x8f, 0x4e, 0x31, 0x06, 0x51, 0xe5, 0xf3, 0x0e, 0x56, 0xc4,
  39310. 0x24, 0x30, 0xf5, 0xe9, 0x36, 0x71, 0xbc, 0xc9, 0x70, 0x2c,
  39311. 0x6c, 0x4c, 0x15, 0x43, 0x44, 0xa4, 0xfc, 0xf1, 0xd2, 0x71,
  39312. 0x6c, 0x4c, 0xce, 0x30, 0x6c, 0x05, 0x7d, 0x2e, 0xb7, 0xbc,
  39313. 0xe4, 0x65, 0x76, 0x24, 0x75, 0x36, 0xdf, 0x28, 0xfc, 0xcd,
  39314. 0x9a, 0xba, 0xc2, 0xcd, 0xb0, 0x30, 0xdb, 0xe7, 0x2e, 0x3c,
  39315. 0x92, 0x63, 0x1d, 0x30, 0x23, 0x74, 0xb1, 0xb8, 0xcc, 0xd7,
  39316. 0xb6, 0x90, 0x65, 0x73, 0xa2, 0x2a, 0x6e, 0x49, 0x95, 0x0d,
  39317. 0xab, 0x24, 0xdf, 0x2d, 0xbf, 0x76, 0x46, 0x01, 0x44, 0xe4,
  39318. 0x18, 0x8e, 0xd5, 0x9a, 0x76, 0xc9, 0xc6, 0xbc, 0xdb, 0x7f,
  39319. 0x80, 0x52, 0xc6, 0x40, 0x41, 0x12, 0x36, 0x7c, 0x80, 0x69,
  39320. 0xce, 0x7b, 0xe1, 0xa0, 0x53, 0xa2, 0xd6, 0x8f, 0x3f, 0xf7,
  39321. 0xd7, 0x61, 0x09, 0x70, 0xa2, 0xa0, 0xc6, 0xaf, 0xa0, 0xd0,
  39322. 0xfa, 0x13, 0xbf, 0xc0, 0x69, 0x15, 0xce, 0x15, 0xec, 0x24,
  39323. 0x4b, 0x6b, 0xdc, 0x93, 0x51, 0xc6, 0x82, 0x19, 0x92, 0x84,
  39324. 0x5d, 0x99, 0xb0, 0x90, 0x2c, 0xcc, 0x2a, 0x81, 0x6b, 0x22,
  39325. 0x64, 0x0a, 0xcb, 0x51, 0x25, 0x82, 0x50, 0x02, 0x2d, 0x3e,
  39326. 0xd4, 0x72, 0xb3, 0x0c, 0x15, 0x77, 0xd2, 0xca, 0x98, 0x2f,
  39327. 0x41, 0x93, 0x14, 0xb2, 0x7f, 0xa1, 0x97, 0xa3, 0xb8, 0x8a,
  39328. 0x56, 0x24, 0x38, 0xa7, 0x36, 0xc5, 0x01, 0xc0, 0x9f, 0x3f,
  39329. 0x3e, 0x9a, 0xf6, 0xe9, 0x16, 0x82, 0x01, 0x58, 0x70, 0x0e,
  39330. 0x0d, 0xbc, 0xfa, 0x03, 0x57, 0x65, 0xa8, 0x5a, 0x3d, 0x57,
  39331. 0x81, 0x23, 0xbe, 0x6e, 0xa9, 0xe8, 0x22, 0xdf, 0x2f, 0x70,
  39332. 0xeb, 0x0a, 0x03, 0x96, 0x6b, 0xef, 0x20, 0x9f, 0xf2, 0x62,
  39333. 0xe7, 0xb2, 0x6e, 0x3a, 0x1e, 0x40, 0x1f, 0xd2, 0x97, 0x48,
  39334. 0xd1, 0x18, 0xf0, 0xeb, 0x52, 0x58, 0x02, 0x26, 0xce, 0x75,
  39335. 0xb1, 0x3a, 0x9d, 0x5b, 0x52, 0x94, 0xb2, 0x6e, 0x0e, 0x3f,
  39336. 0x39, 0xb6, 0xd9, 0x8a, 0x9d, 0xe8, 0x7c, 0x83, 0x32, 0xcc,
  39337. 0x43, 0x35, 0x9b, 0x7a, 0xed, 0xb2, 0x1e, 0x51, 0x37, 0x6c,
  39338. 0x14, 0xd8, 0xb8, 0x55, 0xb3, 0x91, 0xef, 0x0c, 0x3a, 0xe5,
  39339. 0x77, 0xd0, 0xbd, 0xb0, 0x7d, 0x38, 0x84, 0x2a, 0x47, 0xb2,
  39340. 0xb6, 0xda, 0xd7, 0x75, 0xd6, 0x2e, 0x60, 0xc7, 0x10, 0x52,
  39341. 0xf7, 0xdd, 0x09, 0x15, 0x6f, 0x04, 0x31, 0xc3, 0x5a, 0x6b,
  39342. 0x0c, 0x60, 0x10, 0xa8, 0x6e, 0x20, 0xa9, 0xdd, 0xb7, 0x72,
  39343. 0xc3, 0x9e, 0x85, 0xd2, 0x8f, 0x16, 0x7e, 0x3d, 0xe0, 0x63,
  39344. 0x81, 0x32, 0xfd, 0xca, 0xbc, 0x0f, 0xef, 0x3e, 0x74, 0x6a,
  39345. 0xb1, 0x60, 0xc1, 0x10, 0x50, 0x7c, 0x67, 0xa4, 0x19, 0xa7,
  39346. 0xb8, 0xed, 0xe6, 0xf5, 0x4e, 0x41, 0x53, 0xa6, 0x72, 0x1b,
  39347. 0x2c, 0x33, 0x6a, 0x37, 0xf1, 0xb5, 0x1c, 0x01, 0x7d, 0xa2,
  39348. 0x1f, 0x2c, 0x4e, 0x0a, 0xbf, 0xd4, 0x2c, 0x24, 0x91, 0x58,
  39349. 0x62, 0xfb, 0xf8, 0x63, 0xd9, 0xf8, 0x78, 0xf5, 0xc7, 0x78,
  39350. 0x32, 0xda, 0x99, 0xeb, 0x58, 0x20, 0x25, 0x19, 0xb1, 0x06,
  39351. 0x7f, 0x6a, 0x29, 0x20, 0xdb, 0xc8, 0x22, 0x48, 0xa9, 0x7f,
  39352. 0x24, 0x54, 0x8d, 0x7d, 0x8d, 0xb1, 0x69, 0xb2, 0xa3, 0x98,
  39353. 0x14, 0x0f, 0xba, 0xfa, 0xb6, 0x15, 0xe8, 0x28, 0x99, 0x3f,
  39354. 0x30, 0x04, 0x50, 0xab, 0x5a, 0x3c, 0xf1, 0x97, 0xe1, 0xc8,
  39355. 0x0f, 0x0e, 0xb4, 0x11, 0x63, 0x5a, 0x79, 0x08, 0x48, 0x75,
  39356. 0xaf, 0x9b, 0xca, 0xd9, 0x13, 0x18, 0xcc, 0xb1, 0xb3, 0xee,
  39357. 0xdd, 0x63, 0xdd, 0xf4, 0x21, 0x98, 0x76, 0xe2, 0x3e, 0xd5,
  39358. 0x86, 0x23, 0x33, 0x7e, 0xc7, 0xb4, 0x35, 0x4b, 0xc2, 0x2d,
  39359. 0xe1, 0xe2, 0xb0, 0x6c, 0x8b, 0x9b, 0x20, 0x3d, 0x48, 0x24,
  39360. 0x7c, 0xea, 0xa1, 0x75, 0x27, 0xe5, 0xf4, 0x70, 0xeb, 0x3b,
  39361. 0xc7, 0x26, 0x37, 0x04, 0xff, 0x8a, 0x7a, 0xd0, 0xc2, 0xb7,
  39362. 0x84, 0xb7, 0x29, 0xfb, 0x0e, 0xa3, 0xa8, 0x71, 0xcd, 0x58,
  39363. 0x06, 0x36, 0xe2, 0xf2, 0x77, 0xcc, 0x0f, 0x78, 0x08, 0x2b,
  39364. 0xbb, 0xe3, 0x53, 0x05, 0x71, 0xdc, 0x6c, 0x37, 0x32, 0x91,
  39365. 0x46, 0x42, 0x4f, 0x21, 0xe0, 0x34, 0xad, 0x3f, 0x30, 0x5a,
  39366. 0xc7, 0x0d, 0x17, 0x19, 0x39, 0x31, 0x58, 0x69, 0x3c, 0x8c,
  39367. 0xbe, 0xe7, 0xa6, 0x3b, 0xad, 0xfb, 0x46, 0x89, 0x06, 0xc1,
  39368. 0x8c, 0x16, 0x9a, 0x06, 0x3a, 0xd0, 0x7e, 0xd6, 0xb0, 0x7b,
  39369. 0x7d, 0xf8, 0x91, 0x7c, 0xfa, 0xd9, 0x66, 0x39, 0xfa, 0xbc,
  39370. 0x57, 0xa7, 0x78, 0x8b, 0x36, 0x78, 0xc0, 0x1c, 0x0e, 0x23,
  39371. 0x05, 0x0e, 0x04, 0x61, 0x16, 0x34, 0xf9, 0xc6, 0x63, 0x58,
  39372. 0xdf, 0xf4, 0x52, 0xce, 0xd0, 0x0f, 0x0c, 0xec, 0xb1, 0x82,
  39373. 0xf4, 0x72, 0x73, 0x72, 0x3f, 0x02, 0xbe, 0xe3, 0x9c, 0x63,
  39374. 0x73, 0xc8, 0x21, 0x65, 0xba, 0x57, 0x52, 0xa9, 0x19, 0xac,
  39375. 0x68, 0x50, 0xbd, 0x2d, 0x72, 0x5b, 0x93, 0x0f, 0x1c, 0x81,
  39376. 0x77, 0xd7, 0x2e, 0xc3, 0x93, 0x52, 0x6e, 0xdc, 0x79, 0x52,
  39377. 0x9f, 0xe3, 0xde, 0xe1, 0xba, 0x58, 0x55, 0xab, 0x8a, 0xf2,
  39378. 0x35, 0x6a, 0xcf, 0x94, 0x1f, 0x17, 0xa4, 0x23, 0x2e, 0x8e,
  39379. 0x18, 0x21, 0xbe, 0x14, 0xfa, 0xe7, 0x59, 0xc5, 0x44, 0x34,
  39380. 0xce, 0x03, 0xf4, 0xb7, 0x75, 0xd3, 0x51, 0x55, 0xdf, 0xff,
  39381. 0xcf, 0x4f, 0x44, 0xee, 0x13, 0x9b, 0xcb, 0x12, 0xae, 0xe5,
  39382. 0x5b, 0x44, 0x65, 0x28, 0xcb, 0x6a, 0x9c, 0x24, 0x1d, 0xea,
  39383. 0x2d, 0x5e, 0xa5, 0xc3, 0x78, 0xad, 0xed, 0x0c, 0x05, 0xa6,
  39384. 0xaf, 0x95, 0x04, 0xd2, 0xb5, 0x91, 0x0e, 0xa0, 0x06, 0x77,
  39385. 0xc5, 0x82, 0xf6, 0xdd, 0x72, 0x83, 0x04, 0xcc, 0xb0, 0xab,
  39386. 0x7a, 0xf0, 0xb4, 0x4d, 0x36, 0x71, 0x72, 0x1a, 0x9a, 0x0d,
  39387. 0xcd, 0xa3, 0x11, 0xa8, 0x0d, 0x7d, 0x49, 0xce, 0x9c, 0x09,
  39388. 0x1d, 0x08, 0xa4, 0x39, 0x2e, 0x03, 0xdf, 0x3a, 0xc8, 0xfe,
  39389. 0x6a, 0x2b, 0x0b, 0x07, 0x80, 0x55, 0x8a, 0xa8, 0xe6, 0x0e,
  39390. 0xc9, 0x7e, 0x83, 0xce, 0x3a, 0x98, 0x98, 0x4e, 0x3e, 0x08,
  39391. 0x20, 0x8f, 0x10, 0xfc, 0xc1, 0xc4, 0xcf, 0x37, 0x8d, 0x69,
  39392. 0xd8, 0x57, 0x9d, 0x48, 0x80, 0x6a, 0xef, 0x0c, 0xdd, 0x27,
  39393. 0x99, 0xf9, 0xe7, 0xd0, 0xd2, 0x36, 0xd8, 0xed, 0x41, 0x14,
  39394. 0x1b, 0x10
  39395. };
  39396. #endif
  39397. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_sig[] = {
  39398. 0xb1, 0xd1, 0x8e, 0x83, 0x0b, 0x0d, 0xd2, 0x71, 0xb2, 0xaa, 0x31, 0x38,
  39399. 0x16, 0xf0, 0xb4, 0xbc, 0x64, 0x2b, 0x97, 0xa1, 0x08, 0x19, 0x4f, 0x52,
  39400. 0xfe, 0x99, 0x1a, 0xa9, 0xd4, 0x08, 0x93, 0x99, 0x88, 0xfd, 0x6a, 0xd6,
  39401. 0xd8, 0xdb, 0xf0, 0x71, 0x2a, 0xc9, 0x04, 0x83, 0xc9, 0x45, 0x59, 0x5d,
  39402. 0xe0, 0x36, 0x59, 0x53, 0x1b, 0xb8, 0x5a, 0xa6, 0x1f, 0xb4, 0x1b, 0x0a,
  39403. 0xfb, 0x3a, 0xba, 0xe3, 0xb7, 0x5e, 0x04, 0x14, 0x59, 0x09, 0x9a, 0x8e,
  39404. 0xc2, 0x77, 0x5a, 0x3d, 0xf1, 0x43, 0x67, 0x74, 0x78, 0xfc, 0xcd, 0x34,
  39405. 0xed, 0x35, 0x16, 0x38, 0x04, 0xe6, 0xe7, 0xd6, 0xd2, 0x90, 0x1b, 0x28,
  39406. 0xb6, 0x66, 0x1b, 0x57, 0x85, 0x5e, 0xa7, 0x9f, 0x86, 0x1a, 0x0d, 0xc3,
  39407. 0x7e, 0xed, 0xbd, 0x32, 0x8a, 0x35, 0xe1, 0xb3, 0x01, 0xdc, 0x9b, 0x44,
  39408. 0x88, 0xa1, 0x0b, 0x87, 0x6e, 0x55, 0x31, 0xb1, 0x27, 0xcb, 0x85, 0xa4,
  39409. 0x27, 0x56, 0x33, 0xb0, 0x39, 0x0d, 0xd3, 0x4b, 0xd1, 0xa2, 0x47, 0x07,
  39410. 0xc6, 0xf4, 0xe6, 0x1f, 0x88, 0x70, 0x70, 0x13, 0x7e, 0x2e, 0x17, 0x32,
  39411. 0x0a, 0x6b, 0x38, 0x34, 0xcf, 0x2f, 0x00, 0x36, 0x58, 0x8d, 0xe1, 0xdd,
  39412. 0xa7, 0x94, 0x2a, 0x8f, 0x87, 0x99, 0x67, 0x02, 0x4d, 0x5b, 0x56, 0xaf,
  39413. 0xef, 0xc4, 0x3c, 0xff, 0x72, 0x53, 0x95, 0x27, 0x03, 0x49, 0x94, 0x4f,
  39414. 0x94, 0x87, 0x1f, 0x52, 0x33, 0xed, 0xb9, 0x14, 0x7b, 0xe5, 0x6c, 0xef,
  39415. 0x7a, 0x17, 0x5a, 0xa4, 0x89, 0x2a, 0xfe, 0x68, 0xda, 0xdd, 0x48, 0xc2,
  39416. 0xf0, 0x92, 0xf4, 0xe4, 0xd6, 0xa6, 0x48, 0x08, 0x2c, 0xe8, 0xcd, 0x72,
  39417. 0xf6, 0x94, 0x3e, 0xc1, 0x82, 0xb8, 0x01, 0x58, 0xb2, 0xef, 0xef, 0xf4,
  39418. 0xcb, 0x93, 0x63, 0x2e, 0x33, 0x5b, 0xc9, 0xd6, 0x6a, 0xde, 0xad, 0xe8,
  39419. 0x1e, 0x3f, 0xa3, 0xf2, 0x35, 0x87, 0xc1, 0xc9, 0x48, 0x2f, 0x1b, 0x00,
  39420. 0xea, 0x3d, 0x04, 0x29, 0xd5, 0xc0, 0xe9, 0x1a, 0xc5, 0xce, 0x5e, 0xdb,
  39421. 0xd1, 0xee, 0x16, 0x9c, 0x05, 0x40, 0xf9, 0x21, 0x13, 0x72, 0x08, 0x39,
  39422. 0x6b, 0x63, 0x19, 0xcd, 0x6f, 0x64, 0xa0, 0xc3, 0x77, 0xb7, 0x50, 0xed,
  39423. 0xe9, 0x2d, 0xd5, 0x72, 0xea, 0xa6, 0xc1, 0x97, 0xb9, 0x6b, 0xe5, 0x81,
  39424. 0x91, 0x8e, 0xd1, 0x36, 0x11, 0xee, 0xfb, 0x2b, 0x66, 0xba, 0xe4, 0x3e,
  39425. 0xd0, 0xdd, 0x17, 0xc5, 0x24, 0x3b, 0xc3, 0x5b, 0x75, 0xfc, 0xd5, 0xb6,
  39426. 0x8c, 0xba, 0x8c, 0x66, 0xb2, 0xee, 0x40, 0x45, 0x8c, 0x23, 0xbb, 0xe0,
  39427. 0xc8, 0xd6, 0x05, 0xfd, 0x71, 0x5b, 0x24, 0xbb, 0x37, 0x65, 0x5f, 0x57,
  39428. 0x92, 0x22, 0x13, 0xb2, 0x9a, 0x70, 0x22, 0x4b, 0xbe, 0x03, 0xd1, 0x54,
  39429. 0xb0, 0x3a, 0x30, 0x50, 0x71, 0x24, 0xf7, 0x81, 0x8c, 0x20, 0x67, 0x74,
  39430. 0x5a, 0xef, 0xa1, 0x6a, 0xe3, 0xd0, 0x04, 0xd6, 0xa5, 0x6e, 0xad, 0xa7,
  39431. 0x15, 0x41, 0xf3, 0x21, 0xe8, 0xd9, 0xe6, 0xe5, 0x97, 0xbd, 0xc2, 0x1b,
  39432. 0xbb, 0xd1, 0x4e, 0x7e, 0x5a, 0xd6, 0xe4, 0x19, 0xa5, 0xe4, 0x76, 0xf4,
  39433. 0xce, 0x00, 0x94, 0x76, 0xef, 0x1b, 0xb3, 0x47, 0xb9, 0xa3, 0x32, 0xf7,
  39434. 0x45, 0x6d, 0x32, 0x73, 0x06, 0xc0, 0xb9, 0xaf, 0x9c, 0x46, 0x99, 0xbe,
  39435. 0x14, 0x06, 0xcd, 0x35, 0x7c, 0x90, 0x7c, 0xe7, 0x97, 0x0a, 0x9f, 0xb4,
  39436. 0x21, 0xff, 0xf0, 0xea, 0x83, 0xc0, 0x86, 0x68, 0x9f, 0x36, 0xb0, 0xad,
  39437. 0xe1, 0x8d, 0xc5, 0x76, 0x55, 0xb5, 0xb6, 0x7e, 0x1f, 0xa7, 0x5b, 0x26,
  39438. 0x6c, 0xb5, 0xf9, 0x54, 0x1f, 0x76, 0xc1, 0x9c, 0xfc, 0x57, 0xc8, 0x86,
  39439. 0xc1, 0x7d, 0x59, 0x55, 0x92, 0xa5, 0xb8, 0x03, 0xfa, 0xa5, 0x72, 0xd1,
  39440. 0x5c, 0x8d, 0x9b, 0x2e, 0x84, 0x07, 0x18, 0xee, 0x49, 0xc5, 0x99, 0x8e,
  39441. 0x15, 0x7c, 0xbf, 0xad, 0x8b, 0x13, 0xcd, 0x97, 0xf9, 0x3c, 0xa2, 0x89,
  39442. 0x9c, 0x9c, 0x89, 0xc9, 0x7a, 0x46, 0xb3, 0x42, 0x7b, 0xd4, 0x28, 0x0d,
  39443. 0x55, 0x63, 0x28, 0xd6, 0xc1, 0x65, 0xf5, 0x34, 0x6e, 0x38, 0x2a, 0xb4,
  39444. 0x35, 0x40, 0xed, 0x7e, 0x80, 0x61, 0x9d, 0x8f, 0x68, 0x4f, 0x74, 0x0c,
  39445. 0x30, 0x35, 0x0e, 0xb3, 0x07, 0xf4, 0x92, 0xed, 0x9c, 0x7f, 0xf5, 0xed,
  39446. 0x3e, 0x17, 0x5b, 0x6e, 0x91, 0x46, 0xa1, 0x25, 0x1d, 0x83, 0x50, 0x93,
  39447. 0x35, 0x06, 0x6c, 0x2f, 0x99, 0x8b, 0x21, 0x4c, 0x5c, 0x34, 0xb1, 0xa7,
  39448. 0x82, 0xbc, 0x70, 0x28, 0x56, 0x61, 0x29, 0x35, 0x89, 0x0b, 0x41, 0x21,
  39449. 0xf0, 0xf7, 0xff, 0x69, 0x3d, 0xa4, 0x28, 0x1e, 0x0d, 0x5d, 0xa7, 0x0e,
  39450. 0xaa, 0xd3, 0x4a, 0x95, 0x49, 0xfe, 0x35, 0x5f, 0xa9, 0xc0, 0xe4, 0xe1,
  39451. 0x9a, 0x03, 0xd4, 0xac, 0x96, 0xe3, 0xea, 0x7e, 0xa6, 0x85, 0x7e, 0xb0,
  39452. 0xb8, 0xc2, 0xe8, 0x07, 0xd6, 0xd3, 0x1a, 0x84, 0x90, 0x24, 0x04, 0xef,
  39453. 0x7c, 0x93, 0x15, 0x83, 0xea, 0xe2, 0x42, 0xc6, 0xe7, 0x13, 0x45, 0xbf,
  39454. 0x35, 0xae, 0x5d, 0x50, 0x79, 0x16, 0xbb, 0x11, 0x17, 0x1b, 0xf4, 0x08,
  39455. 0x88, 0x9d, 0x66, 0x14, 0x6a, 0xa0, 0x71, 0x76, 0x80, 0x51, 0x73, 0x7c,
  39456. 0x1d, 0xb0, 0xc1, 0xad, 0x58, 0xfb, 0xbe, 0xcf, 0x73, 0xe0, 0xd9, 0xf8,
  39457. 0xd5, 0xac, 0xd7, 0x49, 0xd9, 0xc9, 0x59, 0xbf, 0xfa, 0xf5, 0xb1, 0xd2,
  39458. 0x5a, 0x01, 0xcd, 0x8b, 0x07, 0x8b, 0x59, 0x37, 0xc0, 0x8c, 0x7d, 0xa9,
  39459. 0x71, 0x83, 0xf9, 0x7c, 0x58, 0xa9, 0x77, 0x01, 0x3d, 0x39, 0x56, 0x5c,
  39460. 0x93, 0xfe, 0x40, 0x87, 0x5a, 0x31, 0x81, 0x53, 0x8e, 0x0d, 0x99, 0x7e,
  39461. 0xdf, 0x37, 0xd9, 0xe3, 0x91, 0xb8, 0x60, 0x3a, 0x5b, 0xca, 0xe8, 0x91,
  39462. 0x56, 0x89, 0x59, 0x61, 0xc6, 0x31, 0xe2, 0x6c, 0x81, 0xda, 0xc7, 0x5c,
  39463. 0x04, 0x9d, 0xe4, 0x23, 0x12, 0x73, 0xfc, 0x48, 0xfb, 0xa5, 0xce, 0x87,
  39464. 0x37, 0x47, 0x71, 0x5c, 0xd1, 0x2a, 0x63, 0x89, 0xdc, 0x07, 0xe7, 0x7f,
  39465. 0x5d, 0x48, 0xe6, 0xd2, 0x96, 0xc6, 0x6f, 0xed, 0xee, 0x8c, 0xed, 0x5e,
  39466. 0x41, 0x38, 0xbd, 0xdf, 0x21, 0xaa, 0x9e, 0x51, 0x16, 0x22, 0x4a, 0xdc,
  39467. 0xd8, 0x12, 0xdf, 0x5a, 0x83, 0xd6, 0xd0, 0x07, 0xa4, 0x42, 0x41, 0x13,
  39468. 0xe1, 0x08, 0xc9, 0x00, 0x0f, 0x37, 0xc0, 0x7d, 0xda, 0xb2, 0x25, 0xfc,
  39469. 0xc9, 0xbc, 0xa8, 0x86, 0xcc, 0x38, 0x0e, 0x06, 0x51, 0x1b, 0x37, 0xc1,
  39470. 0x0e, 0x2a, 0x58, 0x49, 0xbc, 0x7c, 0xa7, 0xf0, 0xda, 0xd7, 0x74, 0x34,
  39471. 0xf5, 0xd8, 0x99, 0x8c, 0x94, 0x86, 0xe3, 0x1e, 0x6b, 0xf5, 0x68, 0xfa,
  39472. 0xa6, 0x69, 0x63, 0x22, 0x5a, 0x3c, 0x6f, 0x29, 0xc9, 0x40, 0xc0, 0xbe,
  39473. 0x8d, 0xb5, 0xcc, 0x82, 0x6e, 0x9d, 0xd1, 0x1f, 0x13, 0x63, 0xd8, 0x24,
  39474. 0x63, 0x38, 0x59, 0xf0, 0x4a, 0x8c, 0x0f, 0x28, 0x8a, 0x77, 0x81, 0xa2,
  39475. 0xa0, 0x23, 0x11, 0x59, 0xa9, 0x5a, 0x2d, 0x71, 0x8f, 0x82, 0xa7, 0xbd,
  39476. 0x85, 0x26, 0x4d, 0xc2, 0x2f, 0x11, 0xe8, 0xff, 0x96, 0xa1, 0x2d, 0xf2,
  39477. 0xd5, 0xf3, 0x1d, 0x54, 0xd0, 0x5f, 0x71, 0x07, 0xaf, 0x22, 0xa0, 0xcd,
  39478. 0x78, 0xb3, 0x47, 0xb1, 0x40, 0x3d, 0x6b, 0xfd, 0x10, 0x1b, 0xc6, 0x60,
  39479. 0xef, 0x5c, 0x24, 0xa3, 0x1f, 0xee, 0xc0, 0x0b, 0xed, 0x1d, 0x38, 0xc8,
  39480. 0xf2, 0x8c, 0xec, 0x5e, 0xd9, 0x70, 0x1a, 0x2b, 0x25, 0xe6, 0xed, 0xa9,
  39481. 0x0c, 0xb3, 0x78, 0xe1, 0x91, 0x01, 0x41, 0x2e, 0xfe, 0x7d, 0xbd, 0xfe,
  39482. 0xcf, 0x48, 0x6d, 0x2e, 0x05, 0x31, 0x89, 0x24, 0xc4, 0xd7, 0xc4, 0x26,
  39483. 0x2f, 0x64, 0x43, 0xa3, 0xdd, 0x56, 0x11, 0x5c, 0x65, 0x76, 0x96, 0xcc,
  39484. 0x3c, 0x12, 0x42, 0xf2, 0x6b, 0x20, 0xc2, 0xe6, 0xc3, 0x5c, 0xfa, 0x91,
  39485. 0xb1, 0xbd, 0x3b, 0xd3, 0x99, 0xde, 0x59, 0x7a, 0x34, 0x40, 0x56, 0xb0,
  39486. 0x88, 0x02, 0x19, 0xc8, 0xf9, 0xf9, 0x8f, 0xe7, 0x60, 0xfb, 0x42, 0x87,
  39487. 0x57, 0xb4, 0x42, 0xb4, 0x65, 0x94, 0x0a, 0x5f, 0xdb, 0xf5, 0x32, 0xe9,
  39488. 0x49, 0x28, 0xbe, 0xa6, 0x64, 0x0d, 0x6d, 0x08, 0x43, 0x91, 0x16, 0x7a,
  39489. 0x6c, 0xa9, 0x02, 0xe4, 0x84, 0x03, 0x39, 0x48, 0x08, 0xcc, 0xcb, 0x56,
  39490. 0xad, 0x52, 0x95, 0x9e, 0x9a, 0x2b, 0xf1, 0x6d, 0x3f, 0x4b, 0x02, 0xc6,
  39491. 0x52, 0xc7, 0x09, 0x6b, 0x3f, 0xa9, 0x60, 0xe2, 0x19, 0x5d, 0x0a, 0x61,
  39492. 0xcd, 0xc8, 0x36, 0xdb, 0x8e, 0x57, 0xd2, 0x11, 0x49, 0x1c, 0x26, 0x58,
  39493. 0x04, 0x07, 0x32, 0x2a, 0x34, 0xf0, 0x6a, 0x88, 0xcf, 0x63, 0xb7, 0xef,
  39494. 0x7e, 0x93, 0xcc, 0x64, 0x07, 0x14, 0xfa, 0x63, 0x38, 0xdd, 0xc0, 0xf0,
  39495. 0xaa, 0x56, 0xa1, 0xed, 0x16, 0xaa, 0x53, 0x8c, 0x99, 0xc0, 0xd4, 0xda,
  39496. 0x94, 0x58, 0x13, 0xd9, 0x5f, 0x98, 0x9a, 0xa1, 0x57, 0xbd, 0x89, 0xca,
  39497. 0x9d, 0x3e, 0xdf, 0x75, 0x26, 0x29, 0x0f, 0xb2, 0x33, 0x4b, 0x83, 0xb3,
  39498. 0x99, 0x1f, 0x06, 0x5d, 0x10, 0xf5, 0x1c, 0x75, 0x97, 0xec, 0x5b, 0x87,
  39499. 0xc7, 0xf1, 0xd8, 0xbd, 0x0e, 0x4c, 0x1a, 0xb0, 0x59, 0x3b, 0x27, 0x73,
  39500. 0xdc, 0xde, 0xca, 0x0c, 0x2e, 0x1f, 0x42, 0x7f, 0xd8, 0x0f, 0x9b, 0x3f,
  39501. 0x49, 0x3f, 0x63, 0x7d, 0x71, 0xe3, 0x77, 0x79, 0xcc, 0x9c, 0xbf, 0xff,
  39502. 0x23, 0xa9, 0x74, 0xa2, 0xda, 0xb7, 0xca, 0x86, 0x7f, 0x12, 0xc1, 0x1b,
  39503. 0x41, 0x35, 0xb5, 0xc7, 0x10, 0x09, 0xc0, 0xa2, 0x1b, 0x41, 0x31, 0x5e,
  39504. 0x6c, 0x35, 0xb5, 0x63, 0x13, 0x19, 0x61, 0x8e, 0xbd, 0x89, 0xf6, 0x0a,
  39505. 0xbd, 0x16, 0x15, 0xd8, 0xfa, 0xcc, 0x9f, 0x97, 0x02, 0x8f, 0x1b, 0x34,
  39506. 0x40, 0xbc, 0x4a, 0xb1, 0x39, 0x12, 0xf8, 0x66, 0xda, 0x34, 0x03, 0xf2,
  39507. 0x5c, 0x33, 0x9c, 0x63, 0x0b, 0xb6, 0x8f, 0xca, 0x81, 0xa2, 0x4a, 0x43,
  39508. 0xe7, 0xe7, 0x66, 0x41, 0x45, 0x6b, 0x7c, 0xd1, 0x1d, 0xbc, 0x4f, 0x91,
  39509. 0xab, 0x24, 0x0b, 0x9f, 0x60, 0x47, 0x36, 0x04, 0x8b, 0x72, 0xb6, 0x65,
  39510. 0x35, 0xfc, 0xbf, 0xc9, 0x26, 0xaf, 0x84, 0x04, 0x30, 0x32, 0x02, 0xc0,
  39511. 0x94, 0x98, 0xbc, 0x17, 0x33, 0x99, 0xac, 0xb1, 0x4e, 0xdd, 0xf0, 0x46,
  39512. 0x68, 0x6a, 0xac, 0x6d, 0xdb, 0x85, 0xfd, 0xc6, 0x3b, 0xc8, 0x93, 0x89,
  39513. 0xbf, 0xd7, 0xd9, 0x94, 0xe4, 0xa4, 0x37, 0xb9, 0x67, 0x52, 0x84, 0xcf,
  39514. 0x88, 0xba, 0x01, 0x8b, 0xe4, 0xd4, 0x3e, 0xde, 0x94, 0xa1, 0xa9, 0xd8,
  39515. 0x15, 0xb5, 0x6e, 0xa0, 0x62, 0x92, 0x5c, 0xb1, 0x1b, 0xbf, 0x4f, 0xaf,
  39516. 0xf5, 0x99, 0x35, 0xce, 0x7d, 0xa9, 0x4b, 0xa8, 0x60, 0x31, 0xf5, 0x0a,
  39517. 0x83, 0x58, 0xf5, 0x83, 0xde, 0xb2, 0xfe, 0xf3, 0x12, 0x08, 0x3d, 0xe3,
  39518. 0x14, 0x89, 0x17, 0x93, 0x5c, 0x87, 0xe4, 0x89, 0xcb, 0xb7, 0x67, 0x3e,
  39519. 0xea, 0x0e, 0x08, 0x57, 0xf1, 0xca, 0xe0, 0x18, 0xd7, 0xae, 0x5f, 0x9e,
  39520. 0x62, 0x5c, 0xd7, 0x6a, 0x2f, 0xd6, 0x30, 0x67, 0xfb, 0x5e, 0xed, 0xcf,
  39521. 0xa9, 0x88, 0x04, 0x0a, 0xf2, 0x62, 0x50, 0xc5, 0x39, 0xc6, 0xa1, 0x3c,
  39522. 0xe4, 0x9a, 0x81, 0x55, 0x96, 0xca, 0x60, 0xb2, 0x53, 0x62, 0xee, 0xa1,
  39523. 0x1d, 0xfc, 0xd9, 0x5c, 0x51, 0xbf, 0x55, 0x65, 0x1d, 0x13, 0x2a, 0x13,
  39524. 0x58, 0xa3, 0x18, 0x52, 0x6b, 0xb4, 0xae, 0x60, 0x1c, 0x26, 0x3e, 0xb1,
  39525. 0x4c, 0xb1, 0x72, 0x1b, 0x8a, 0x4c, 0xaa, 0xb5, 0x5b, 0x8a, 0x3b, 0x2f,
  39526. 0x1f, 0xc3, 0x29, 0x41, 0xe6, 0x6d, 0xd7, 0x96, 0x26, 0xdd, 0x37, 0x67,
  39527. 0x4f, 0x9d, 0x31, 0xc6, 0x54, 0x51, 0xaa, 0xba, 0x73, 0xae, 0xd2, 0x00,
  39528. 0x0b, 0x05, 0x98, 0x73, 0xd6, 0x9c, 0xb4, 0x2e, 0x23, 0xd0, 0xc3, 0xac,
  39529. 0x46, 0x6f, 0x3e, 0x05, 0x43, 0xf8, 0x96, 0xa0, 0xe0, 0xfe, 0x17, 0x3f,
  39530. 0xfa, 0xc2, 0xc3, 0xf6, 0x1a, 0x46, 0xd0, 0x05, 0x53, 0x0e, 0xea, 0xd8,
  39531. 0xba, 0xa3, 0xab, 0xb6, 0x58, 0xd1, 0x40, 0x1c, 0x97, 0x38, 0xd4, 0x77,
  39532. 0x58, 0x03, 0xf5, 0x8a, 0xc7, 0x48, 0x19, 0x71, 0x71, 0xb5, 0x4b, 0x08,
  39533. 0x85, 0x35, 0x1c, 0xdf, 0xbd, 0xa9, 0xc9, 0xd1, 0x40, 0x62, 0xa3, 0xd6,
  39534. 0x3b, 0xa1, 0xf7, 0x4e, 0xc6, 0xfe, 0xc4, 0x07, 0x2f, 0xf5, 0xc9, 0x0c,
  39535. 0xb6, 0xa0, 0xb3, 0x25, 0x3e, 0x2a, 0x07, 0xe3, 0x63, 0xe3, 0x9e, 0x8d,
  39536. 0x0d, 0x7a, 0x70, 0x1e, 0x65, 0x95, 0x47, 0x37, 0xa8, 0xd2, 0x35, 0x09,
  39537. 0x09, 0x70, 0xf5, 0xc9, 0xc9, 0x30, 0x95, 0xd9, 0xf2, 0x5d, 0x10, 0x3c,
  39538. 0xc3, 0x66, 0x66, 0xb6, 0xdc, 0x14, 0xf6, 0x91, 0xc2, 0x7b, 0x4b, 0x71,
  39539. 0x42, 0xf9, 0x35, 0xe7, 0x08, 0x1e, 0xb6, 0x9a, 0x5c, 0x0e, 0x8b, 0x41,
  39540. 0x44, 0x7f, 0xad, 0xca, 0x8a, 0x4b, 0x6a, 0x02, 0x81, 0x96, 0xe7, 0xe1,
  39541. 0xb0, 0x5b, 0xaf, 0xf2, 0x17, 0x44, 0x7f, 0xd1, 0x49, 0x77, 0xfd, 0x07,
  39542. 0x59, 0x53, 0x8e, 0x51, 0xac, 0x0f, 0x0c, 0xb4, 0xa3, 0xf6, 0x24, 0x16,
  39543. 0x47, 0xf3, 0xa4, 0x36, 0x17, 0x3e, 0x01, 0x1e, 0xf1, 0xec, 0x78, 0x4a,
  39544. 0xcb, 0xbd, 0x2a, 0xfd, 0x01, 0xdd, 0xa5, 0xad, 0x7b, 0xef, 0x5e, 0x56,
  39545. 0xb2, 0x60, 0xb4, 0xf2, 0x27, 0xc8, 0x9b, 0x5b, 0x31, 0x49, 0x54, 0xbc,
  39546. 0x69, 0x9b, 0xc6, 0x1a, 0x79, 0xe7, 0xd4, 0x46, 0xc8, 0x50, 0xc3, 0xaa,
  39547. 0xfc, 0xb5, 0x28, 0x87, 0x1e, 0xa0, 0x0c, 0xc6, 0x1a, 0xa7, 0x34, 0xd6,
  39548. 0xbb, 0x9d, 0x9c, 0x0d, 0x90, 0x6f, 0x1a, 0x3c, 0xdc, 0x3b, 0x95, 0xc4,
  39549. 0x38, 0x25, 0x7a, 0xc6, 0x46, 0x82, 0x9f, 0x68, 0xca, 0x6a, 0x63, 0xa7,
  39550. 0x99, 0xfe, 0x64, 0xe6, 0x6f, 0x11, 0xcd, 0x2c, 0x76, 0x1e, 0xe6, 0x08,
  39551. 0xb8, 0x33, 0x64, 0x43, 0x51, 0xbd, 0x52, 0xf7, 0x05, 0x06, 0xd5, 0xcc,
  39552. 0x6a, 0xde, 0x1a, 0xa2, 0xbe, 0xf8, 0x8c, 0x44, 0x5e, 0x2d, 0xc2, 0x28,
  39553. 0xcd, 0x9a, 0x53, 0x04, 0x96, 0xcc, 0x1e, 0xbb, 0x96, 0x07, 0xc9, 0x17,
  39554. 0x04, 0xf8, 0xd8, 0xd9, 0xdd, 0x35, 0x35, 0x3d, 0x53, 0x30, 0x60, 0xb3,
  39555. 0x87, 0x5d, 0xf3, 0xe5, 0xa7, 0x20, 0x30, 0x9d, 0xb0, 0x5b, 0xc4, 0x36,
  39556. 0xf7, 0xd7, 0xb6, 0x3e, 0x44, 0x98, 0x99, 0xe7, 0xc3, 0x29, 0xcb, 0x70,
  39557. 0xc4, 0x91, 0x8b, 0xfc, 0x63, 0x60, 0x29, 0x95, 0xeb, 0x61, 0x7f, 0xdf,
  39558. 0xf7, 0x3a, 0x69, 0x3a, 0xeb, 0xa1, 0x73, 0x1d, 0x13, 0x18, 0x29, 0x2c,
  39559. 0x89, 0x82, 0x56, 0x42, 0xe7, 0xa3, 0xba, 0xe9, 0x59, 0x2e, 0xfd, 0xff,
  39560. 0xb6, 0xf7, 0xbd, 0x2a, 0xc9, 0xff, 0x4c, 0x63, 0xef, 0x54, 0x63, 0x82,
  39561. 0x7c, 0xa5, 0x11, 0x44, 0xc7, 0x68, 0xf5, 0x7b, 0x44, 0x2c, 0xee, 0xab,
  39562. 0xa3, 0x84, 0x5a, 0x99, 0x28, 0x98, 0x97, 0x2e, 0x8b, 0x07, 0x09, 0x6c,
  39563. 0xea, 0xc1, 0x81, 0x0b, 0xe0, 0xc4, 0xb7, 0xc2, 0x73, 0xbe, 0x8b, 0x72,
  39564. 0xf8, 0xc9, 0x8d, 0x50, 0x28, 0xf2, 0x95, 0x54, 0x8a, 0x3b, 0x23, 0x86,
  39565. 0xc4, 0xe8, 0xe8, 0xe5, 0x45, 0x0d, 0xdf, 0xa3, 0xe6, 0x00, 0x71, 0xe8,
  39566. 0x20, 0xd2, 0x6d, 0x22, 0x23, 0xaf, 0x37, 0x04, 0x55, 0x05, 0x8d, 0xc9,
  39567. 0x38, 0x38, 0x12, 0x4c, 0x9f, 0x28, 0x56, 0x14, 0x76, 0xe5, 0x10, 0x54,
  39568. 0xd9, 0x68, 0xca, 0xc3, 0x97, 0x9f, 0xd2, 0x25, 0x2c, 0x0d, 0xa0, 0xff,
  39569. 0xea, 0xab, 0x61, 0xd2, 0xb2, 0x06, 0xc2, 0x93, 0xfd, 0x5a, 0xfe, 0xe3,
  39570. 0x98, 0xbf, 0x37, 0x2e, 0xa5, 0x74, 0x56, 0xd0, 0x7a, 0x5a, 0x23, 0x3b,
  39571. 0xd2, 0xa0, 0x1f, 0x4b, 0xeb, 0x7f, 0x5a, 0xc5, 0x51, 0x79, 0xf6, 0x95,
  39572. 0x19, 0x50, 0xb1, 0x6a, 0x80, 0xcb, 0xcf, 0x19, 0xa4, 0x67, 0xf4, 0x08,
  39573. 0x0f, 0x6a, 0xd9, 0x3f, 0x15, 0x96, 0x2c, 0x6d, 0xd5, 0x69, 0x7a, 0x56,
  39574. 0x4d, 0x17, 0xc8, 0xcb, 0xba, 0x9b, 0x6e, 0x65, 0xa2, 0x3d, 0x66, 0xed,
  39575. 0xea, 0xe2, 0x54, 0x88, 0x6c, 0xc1, 0x1a, 0x11, 0xde, 0x4e, 0x0c, 0x8a,
  39576. 0x42, 0x04, 0xe1, 0x77, 0xc3, 0x0c, 0xff, 0x10, 0x7d, 0x4a, 0x45, 0x3f,
  39577. 0xb8, 0x40, 0xf9, 0x75, 0x76, 0x9f, 0x65, 0x42, 0x2f, 0x78, 0x5b, 0x0b,
  39578. 0x32, 0xbc, 0x45, 0xfc, 0xd4, 0x29, 0x49, 0x34, 0x76, 0xda, 0x5f, 0xe8,
  39579. 0x39, 0x35, 0x9e, 0xba, 0x7f, 0x19, 0x7e, 0x14, 0xe6, 0x71, 0x9c, 0x72,
  39580. 0x6a, 0xce, 0xcc, 0xa6, 0x72, 0x73, 0x3f, 0x4e, 0x9b, 0x9e, 0x94, 0x0c,
  39581. 0xce, 0x00, 0x15, 0xb4, 0x50, 0xff, 0xcf, 0xcd, 0x78, 0xd3, 0x08, 0x0e,
  39582. 0x95, 0x48, 0x24, 0x13, 0x16, 0x54, 0xb4, 0xe0, 0xa9, 0x29, 0xa3, 0x05,
  39583. 0x77, 0x2f, 0x5d, 0x47, 0x6a, 0xa5, 0xb0, 0x4e, 0xf3, 0xa9, 0x4a, 0x82,
  39584. 0xb9, 0x2c, 0x26, 0x07, 0x9c, 0x33, 0xc6, 0x68, 0xc2, 0xe0, 0xc0, 0x7d,
  39585. 0x70, 0x48, 0x74, 0xb9, 0xf5, 0x1e, 0x6c, 0x15, 0x7f, 0xba, 0xe5, 0xa1,
  39586. 0xb4, 0x36, 0x41, 0x20, 0xf4, 0x2d, 0x97, 0x27, 0x0b, 0x10, 0x30, 0x57,
  39587. 0x7f, 0x38, 0x66, 0xe1, 0xc4, 0xf6, 0xa4, 0xc9, 0x8d, 0xbc, 0x2b, 0x4f,
  39588. 0x14, 0xb3, 0xf0, 0x1e, 0x80, 0x70, 0xc0, 0x0f, 0x69, 0x06, 0xe7, 0x95,
  39589. 0xd1, 0x53, 0x65, 0x49, 0x1c, 0xa8, 0xfa, 0x9e, 0x2b, 0xcc, 0x33, 0x71,
  39590. 0x76, 0xa4, 0x0b, 0x4a, 0xc7, 0xea, 0xa0, 0xfa, 0x1b, 0x2b, 0xfb, 0xa5,
  39591. 0x59, 0x06, 0x2a, 0xef, 0x4b, 0xbf, 0x05, 0x4b, 0x87, 0x70, 0x3c, 0xde,
  39592. 0xc7, 0xb2, 0x4f, 0xf2, 0x5b, 0x1a, 0xbe, 0xda, 0x04, 0x31, 0x57, 0xff,
  39593. 0xf2, 0xa5, 0x43, 0x12, 0xff, 0x8d, 0xf4, 0x99, 0x05, 0xe1, 0x34, 0xa9,
  39594. 0xb9, 0x0a, 0xb3, 0x1f, 0x3d, 0x6d, 0x0d, 0xb7, 0xd3, 0x35, 0x0b, 0x04,
  39595. 0x44, 0x77, 0x60, 0xc0, 0x96, 0x99, 0x7b, 0xa8, 0x8e, 0x79, 0x4a, 0x96,
  39596. 0x24, 0xef, 0xb1, 0xf4, 0x8a, 0x2f, 0x3e, 0x08, 0xf3, 0x3d, 0xf2, 0xfe,
  39597. 0x5f, 0x0a, 0xf7, 0x0a, 0xf5, 0xd8, 0xf2, 0xa0, 0x1b, 0xe7, 0x9e, 0xc9,
  39598. 0x0b, 0xcf, 0x58, 0x97, 0x92, 0x90, 0xad, 0x3d, 0xfc, 0x42, 0xc1, 0x7f,
  39599. 0x39, 0xe8, 0xd1, 0x35, 0x14, 0x8a, 0xb3, 0x77, 0xb1, 0xa9, 0xdb, 0xb4,
  39600. 0x3a, 0x3d, 0xeb, 0x59, 0x0b, 0x5b, 0x3a, 0x63, 0x54, 0x70, 0xda, 0xf0,
  39601. 0xf0, 0xb9, 0xe6, 0x07, 0x69, 0x27, 0x9d, 0xc6, 0xb6, 0x00, 0x2d, 0xd6,
  39602. 0xc7, 0xd7, 0x2e, 0xf8, 0x9c, 0xfe, 0x4c, 0xfb, 0xc0, 0x7b, 0xbf, 0xa2,
  39603. 0x25, 0xb8, 0x2a, 0x5c, 0x06, 0xca, 0x12, 0x2c, 0x96, 0xa4, 0x27, 0xa6,
  39604. 0x73, 0x0b, 0xb8, 0x42, 0x93, 0x51, 0x87, 0xfe, 0xe6, 0x8f, 0xca, 0x00,
  39605. 0x53, 0xdc, 0xc0, 0x38, 0x03, 0x9e, 0x66, 0x13, 0x84, 0x68, 0xe7, 0x04,
  39606. 0x93, 0x79, 0x0c, 0x3e, 0x4c, 0x90, 0xe2, 0xf7, 0x81, 0x15, 0x49, 0x05,
  39607. 0xe1, 0x8f, 0xe6, 0xfc, 0xc8, 0x40, 0xae, 0x3d, 0x7a, 0x16, 0xec, 0xc6,
  39608. 0x39, 0xa5, 0x04, 0x95, 0x35, 0xac, 0xdd, 0x0d, 0x19, 0xd6, 0xa9, 0xd9,
  39609. 0xd2, 0x53, 0x71, 0x31, 0x38, 0xa2, 0xf1, 0x9c, 0x13, 0x2c, 0x8c, 0x21,
  39610. 0x9c, 0x3a, 0x1b, 0xf2, 0xd8, 0x4c, 0xeb, 0xe9, 0x8b, 0x27, 0x52, 0xd3,
  39611. 0x6c, 0x01, 0xc0, 0x60, 0x32, 0x8c, 0x6e, 0xfb, 0xd6, 0xd6, 0x1b, 0xc6,
  39612. 0x93, 0xff, 0xdc, 0xdb, 0x38, 0xf5, 0x0e, 0xd5, 0x15, 0xcd, 0x65, 0x76,
  39613. 0x78, 0x42, 0x13, 0x37, 0x6b, 0x2e, 0xe8, 0xe2, 0x54, 0x4d, 0x45, 0x34,
  39614. 0x73, 0x1b, 0x61, 0x35, 0x2c, 0xf7, 0x20, 0x3e, 0xe9, 0x7c, 0xf0, 0xf3,
  39615. 0xba, 0x41, 0xfc, 0x49, 0xe4, 0x5d, 0xd4, 0xb8, 0x07, 0x15, 0x7b, 0x16,
  39616. 0xc7, 0x7f, 0x78, 0xef, 0xd6, 0x53, 0x3f, 0xe4, 0xa6, 0x33, 0xcf, 0xcc,
  39617. 0x78, 0x53, 0x0c, 0x59, 0xf7, 0x28, 0xa5, 0x83, 0x2b, 0x5a, 0xd3, 0xd6,
  39618. 0xb7, 0xb2, 0xd1, 0x73, 0x63, 0xa9, 0xad, 0x16, 0xf2, 0xed, 0x48, 0x6e,
  39619. 0x88, 0x22, 0xbd, 0x16, 0x9d, 0x6a, 0xc2, 0x48, 0x83, 0xdf, 0x40, 0xb7,
  39620. 0x0a, 0x50, 0x23, 0x3d, 0x58, 0x50, 0x00, 0x02, 0x04, 0xd2, 0x31, 0x72,
  39621. 0x28, 0x7b, 0x10, 0x96, 0xe0, 0xe7, 0x3f, 0xe0, 0xd0, 0x61, 0x70, 0x5c,
  39622. 0x0a, 0xdb, 0xc0, 0x7b, 0xea, 0xef, 0xba, 0xc0, 0x90, 0xe0, 0xf9, 0x0e,
  39623. 0x83, 0x8c, 0x3b, 0x05, 0x2b, 0xb6, 0xcb, 0xbb, 0x37, 0xa1, 0xd3, 0x28,
  39624. 0x02, 0x40, 0xe3, 0x76, 0xbf, 0x27, 0x0b, 0x4f, 0x82, 0xb9, 0x22, 0xee,
  39625. 0x0b, 0x3a, 0xcb, 0xcc, 0x56, 0x13, 0x51, 0xb8, 0xb6, 0x2d, 0xd3, 0x6c,
  39626. 0x96, 0x10, 0xd9, 0x51, 0x24, 0x7b, 0x2b, 0xb8, 0x7b, 0xbd, 0x8d, 0xd9,
  39627. 0xf2, 0x50, 0x61, 0xbb, 0x0c, 0xb7, 0x71, 0x65, 0x3a, 0x25, 0x18, 0x09,
  39628. 0x1a, 0x9d, 0x41, 0xf4, 0xdb, 0x5a, 0x1c, 0x61, 0x0a, 0xbb, 0x43, 0x27,
  39629. 0x8a, 0xa8, 0x83, 0x60, 0x8c, 0x5d, 0x4c, 0x9b, 0xa9, 0xe5, 0xa7, 0x67,
  39630. 0x99, 0x98, 0xdc, 0x7a, 0x3a, 0x55, 0x0d, 0x25, 0x69, 0x47, 0x21, 0xb1,
  39631. 0xd7, 0x0c, 0x0c, 0x43, 0x58, 0xc9, 0xbf, 0x74, 0x91, 0x1b, 0x2b, 0xf3,
  39632. 0x29, 0x8d, 0x10, 0x41, 0xaf, 0xdd, 0x42, 0x0a, 0x71, 0xe3, 0xb8, 0x4d,
  39633. 0x3a, 0xf3, 0x9c, 0x5a, 0x46, 0x4e, 0x70, 0xbe, 0xdb, 0x0d, 0x03, 0xee,
  39634. 0xcb, 0xfb, 0x61, 0x45, 0xbd, 0x25, 0xb4, 0x72, 0xd1, 0x51, 0x03, 0x19,
  39635. 0x82, 0x53, 0x83, 0x18, 0xab, 0xa3, 0x6c, 0x9e, 0xa2, 0xe9, 0x15, 0xb1,
  39636. 0x74, 0x61, 0xa1, 0xaf, 0x09, 0x4b, 0x4a, 0x34, 0x9b, 0xd0, 0xd2, 0x80,
  39637. 0x43, 0xd9, 0x90, 0x53, 0x71, 0x38, 0xb9, 0x80, 0x58, 0x1b, 0x9f, 0x9e,
  39638. 0xfe, 0x07, 0x1b, 0x33, 0x24, 0xb2, 0x58, 0x7f, 0x01, 0xbe, 0xe8, 0x25,
  39639. 0x53, 0x08, 0x06, 0x77, 0x7d, 0x5a, 0x16, 0x83, 0x67, 0x91, 0x0b, 0xa2,
  39640. 0xd2, 0x1e, 0x5f, 0x9c, 0x39, 0xda, 0x57, 0xbc, 0x67, 0xc5, 0x39, 0xbe,
  39641. 0xb9, 0x73, 0x03, 0x19, 0x97, 0x34, 0x4f, 0x1e, 0x6b, 0x4d, 0x87, 0xef,
  39642. 0x79, 0x4f, 0xd1, 0xdd, 0x80, 0x13, 0xbe, 0x3b, 0x0f, 0xea, 0x77, 0x9a,
  39643. 0x1a, 0x46, 0x63, 0xc5, 0x2f, 0x93, 0xfe, 0x18, 0x71, 0xfb, 0x70, 0xbf,
  39644. 0x85, 0x3b, 0x3e, 0x54, 0xe6, 0xf8, 0xe0, 0xb9, 0xd0, 0x9d, 0xf5, 0x2b,
  39645. 0x12, 0x22, 0x39, 0x6a, 0x8d, 0x13, 0xa1, 0x3a, 0x95, 0xd0, 0xe7, 0x07,
  39646. 0xa4, 0x2c, 0x33, 0xba, 0x43, 0x1d, 0xd8, 0xb5, 0xd0, 0x8e, 0x6c, 0x85,
  39647. 0x6f, 0xf8, 0x8f, 0xd3, 0x72, 0x65, 0xc1, 0xff, 0x8f, 0xf6, 0xb5, 0x19,
  39648. 0x59, 0x34, 0xf9, 0xe8, 0xdb, 0xf3, 0x10, 0x68, 0xbd, 0xd5, 0x59, 0xf7,
  39649. 0xe5, 0xf2, 0x84, 0x98, 0x8d, 0xd6, 0x6f, 0xcc, 0xde, 0xc5, 0xee, 0xf7,
  39650. 0x16, 0xca, 0xec, 0xc4, 0x00, 0x89, 0x2e, 0x0d, 0x0d, 0xb6, 0xa8, 0xe0,
  39651. 0x9a, 0xb0, 0xe5, 0x8e, 0xb6, 0x64, 0x47, 0x7d, 0x01, 0x59, 0x8a, 0x90,
  39652. 0xa6, 0x9b, 0x2b, 0x63, 0xad, 0x70, 0xc8, 0x07, 0x36, 0x3e, 0xa9, 0x8f,
  39653. 0xd9, 0xc2, 0xf7, 0x4b, 0xec, 0x95, 0x53, 0xec, 0x6b, 0x2d, 0x1f, 0xb5,
  39654. 0x91, 0xbf, 0x9f, 0xc5, 0x85, 0x61, 0x3a, 0xc7, 0x5c, 0x15, 0x2a, 0x0b,
  39655. 0x4b, 0x3c, 0x38, 0x6d, 0xc9, 0x2c, 0x91, 0x11, 0xc6, 0x6b, 0x44, 0x71,
  39656. 0x9f, 0x89, 0xd5, 0xde, 0x27, 0x99, 0x81, 0xa2, 0x59, 0x8b, 0x57, 0x97,
  39657. 0x83, 0x46, 0x33, 0xe1, 0x8c, 0xdf, 0xcf, 0x5b, 0x6b, 0xb3, 0x0e, 0x17,
  39658. 0x1a, 0xb8, 0x7d, 0x6e, 0x71, 0xe5, 0xc8, 0x4c, 0xa9, 0xe2, 0x52, 0x81,
  39659. 0xf6, 0x2f, 0x3a, 0xef, 0x5a, 0x1b, 0x6b, 0x7b, 0x61, 0x51, 0xcb, 0xd5,
  39660. 0x7b, 0x5f, 0xf0, 0x1c, 0xb8, 0xeb, 0x9a, 0xe4, 0x0a, 0x6e, 0x53, 0x59,
  39661. 0x2e, 0x2d, 0x78, 0x27, 0xb7, 0x47, 0x35, 0x1a, 0x01, 0x25, 0x0a, 0xcc,
  39662. 0x67, 0xae, 0xda, 0xaf, 0xfe, 0x22, 0x63, 0xe8, 0xa2, 0x1c, 0x34, 0xe6,
  39663. 0x6b, 0x73, 0xcf, 0x6f, 0x3e, 0x0a, 0x4a, 0x36, 0xbc, 0xda, 0x43, 0xbc,
  39664. 0x5e, 0x9c, 0x91, 0xe4, 0x8b, 0x34, 0x2e, 0x09, 0x87, 0x69, 0x96, 0x93,
  39665. 0xb4, 0xff, 0x97, 0xbc, 0x4e, 0xd6, 0xa2, 0xb4, 0x16, 0x78, 0x7c, 0x62,
  39666. 0xd0, 0x78, 0x3f, 0x37, 0xdb, 0xf2, 0x92, 0xad, 0x9b, 0x51, 0x77, 0x08,
  39667. 0x19, 0xd2, 0x09, 0x12, 0xf7, 0x52, 0xe8, 0xc8, 0xb2, 0xfb, 0x6f, 0xcd,
  39668. 0x05, 0x5b, 0xd2, 0x8e, 0x0d, 0x6e, 0x0c, 0x16, 0x5b, 0x8a, 0xc2, 0x09,
  39669. 0x13, 0x3b, 0x69, 0x85, 0xbd, 0xc0, 0xcc, 0x2b, 0x48, 0x65, 0xa7, 0xc1,
  39670. 0xc3, 0xe0, 0xea, 0x14, 0x67, 0x6f, 0xa4, 0xb8, 0xc6, 0xf0, 0x12, 0x3e,
  39671. 0x96, 0x0d, 0x23, 0x2b, 0x37, 0x87, 0x8d, 0xc8, 0xf7, 0x00, 0x00, 0x00,
  39672. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39673. 0x00, 0x00, 0x00, 0x03, 0x0b, 0x13, 0x1a, 0x1d, 0x25
  39674. };
  39675. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39676. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_sig[] = {
  39677. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  39678. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  39679. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  39680. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  39681. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  39682. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  39683. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  39684. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  39685. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  39686. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  39687. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  39688. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  39689. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  39690. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  39691. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  39692. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  39693. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  39694. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  39695. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  39696. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  39697. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  39698. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  39699. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  39700. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  39701. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  39702. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  39703. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  39704. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  39705. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  39706. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  39707. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  39708. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  39709. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  39710. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  39711. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  39712. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  39713. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  39714. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  39715. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  39716. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  39717. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  39718. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  39719. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  39720. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  39721. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  39722. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  39723. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  39724. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  39725. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  39726. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  39727. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  39728. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  39729. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  39730. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  39731. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  39732. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  39733. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  39734. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  39735. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  39736. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  39737. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  39738. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  39739. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  39740. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  39741. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  39742. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  39743. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  39744. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  39745. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  39746. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  39747. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  39748. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  39749. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  39750. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  39751. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  39752. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  39753. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  39754. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  39755. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  39756. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  39757. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  39758. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  39759. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  39760. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  39761. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  39762. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  39763. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  39764. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  39765. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  39766. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  39767. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  39768. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  39769. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  39770. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  39771. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  39772. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  39773. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  39774. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  39775. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  39776. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  39777. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  39778. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  39779. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  39780. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  39781. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  39782. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  39783. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  39784. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  39785. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  39786. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  39787. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  39788. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  39789. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  39790. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  39791. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  39792. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  39793. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  39794. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  39795. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  39796. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  39797. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  39798. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  39799. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  39800. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  39801. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  39802. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  39803. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  39804. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  39805. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  39806. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  39807. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  39808. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  39809. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  39810. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  39811. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  39812. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  39813. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  39814. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  39815. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  39816. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  39817. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  39818. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  39819. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  39820. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  39821. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  39822. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  39823. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  39824. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  39825. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  39826. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  39827. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  39828. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  39829. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  39830. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  39831. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  39832. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  39833. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  39834. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  39835. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  39836. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  39837. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  39838. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  39839. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  39840. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  39841. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  39842. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  39843. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  39844. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  39845. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  39846. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  39847. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  39848. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  39849. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  39850. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  39851. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  39852. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  39853. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  39854. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  39855. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  39856. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  39857. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  39858. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  39859. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  39860. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  39861. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  39862. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  39863. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  39864. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  39865. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  39866. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  39867. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  39868. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  39869. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  39870. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  39871. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  39872. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  39873. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  39874. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  39875. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  39876. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  39877. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  39878. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  39879. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  39880. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  39881. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  39882. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  39883. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  39884. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  39885. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  39886. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  39887. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  39888. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  39889. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  39890. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  39891. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  39892. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  39893. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  39894. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  39895. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  39896. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  39897. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  39898. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  39899. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  39900. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  39901. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  39902. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  39903. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  39904. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  39905. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  39906. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  39907. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  39908. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  39909. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  39910. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  39911. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  39912. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  39913. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  39914. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  39915. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  39916. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  39917. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  39918. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  39919. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  39920. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  39921. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  39922. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  39923. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  39924. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  39925. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  39926. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  39927. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  39928. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  39929. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  39930. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  39931. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  39932. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  39933. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  39934. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  39935. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  39936. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  39937. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  39938. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  39939. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  39940. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  39941. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  39942. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  39943. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  39944. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  39945. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  39946. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  39947. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  39948. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  39949. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  39950. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  39951. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  39952. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  39953. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  39954. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  39955. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  39956. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  39957. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  39958. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  39959. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  39960. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  39961. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  39962. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  39963. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  39964. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  39965. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  39966. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  39967. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  39968. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  39969. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  39970. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  39971. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  39972. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  39973. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  39974. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  39975. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  39976. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  39977. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  39978. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  39979. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  39980. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  39981. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  39982. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  39983. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  39984. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  39985. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  39986. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  39987. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  39988. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  39989. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  39990. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  39991. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  39992. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  39993. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  39994. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  39995. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  39996. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  39997. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  39998. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  39999. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  40000. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  40001. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  40002. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  40003. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  40004. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  40005. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  40006. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40007. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28
  40008. };
  40009. #endif
  40010. wc_test_ret_t ret;
  40011. ret = dilithium_param_vfy_test(WC_ML_DSA_65, ml_dsa_65_pub_key,
  40012. (word32)sizeof(ml_dsa_65_pub_key), ml_dsa_65_sig,
  40013. (word32)sizeof(ml_dsa_65_sig));
  40014. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40015. if (ret == 0) {
  40016. ret = dilithium_param_vfy_test(WC_ML_DSA_65_DRAFT,
  40017. ml_dsa_65_draft_pub_key, (word32)sizeof(ml_dsa_65_draft_pub_key),
  40018. ml_dsa_65_draft_sig, (word32)sizeof(ml_dsa_65_draft_sig));
  40019. }
  40020. #endif
  40021. return ret;
  40022. }
  40023. #endif
  40024. #ifndef WOLFSSL_NO_ML_DSA_87
  40025. static wc_test_ret_t dilithium_param_87_vfy_test(void)
  40026. {
  40027. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_pub_key[] = {
  40028. 0x8a, 0x66, 0xe3, 0x6e, 0x3c, 0x11, 0x70, 0x9f, 0x82, 0xdd, 0xeb, 0x9e,
  40029. 0xc0, 0xd7, 0x25, 0x87, 0x0c, 0x65, 0x07, 0x9d, 0x47, 0x39, 0x5d, 0x04,
  40030. 0x42, 0x5c, 0xd6, 0x0a, 0xdc, 0x39, 0x44, 0x04, 0xd9, 0x79, 0x43, 0x87,
  40031. 0x98, 0x64, 0x88, 0x82, 0x3a, 0x31, 0xbd, 0xec, 0x66, 0xcb, 0x01, 0x90,
  40032. 0xf9, 0x85, 0xcc, 0xde, 0x54, 0x69, 0x7d, 0x84, 0xb3, 0x84, 0x3c, 0x42,
  40033. 0x0d, 0x09, 0x63, 0xdb, 0xe6, 0x5d, 0xc2, 0x8a, 0xcf, 0xe1, 0xf4, 0x86,
  40034. 0x13, 0x05, 0x09, 0x9a, 0x4d, 0x05, 0xd4, 0x31, 0xe7, 0x27, 0x39, 0xfd,
  40035. 0x3a, 0xdb, 0x63, 0x9f, 0x1c, 0x67, 0x0b, 0x01, 0xec, 0xf9, 0xff, 0xf3,
  40036. 0xda, 0xa9, 0xf4, 0x9a, 0x59, 0x52, 0x76, 0xc2, 0xd2, 0xd5, 0xdd, 0x8d,
  40037. 0xb1, 0xa2, 0xef, 0xb3, 0x73, 0x99, 0xe3, 0xcd, 0x1c, 0xf5, 0xca, 0x6e,
  40038. 0x39, 0xfa, 0x26, 0x83, 0x45, 0xe7, 0xd0, 0x9c, 0x1b, 0xf7, 0xb2, 0x64,
  40039. 0xf1, 0x70, 0x00, 0x10, 0xc0, 0x7c, 0x7f, 0xb2, 0x32, 0xce, 0x6d, 0x71,
  40040. 0xa5, 0x43, 0x7c, 0x40, 0x71, 0x09, 0x54, 0x74, 0xac, 0xb5, 0xeb, 0xe0,
  40041. 0x04, 0x02, 0xe5, 0x82, 0x4d, 0x5a, 0x85, 0x1e, 0x19, 0x86, 0x39, 0x33,
  40042. 0x92, 0x2f, 0xa9, 0xa8, 0x10, 0xd2, 0x31, 0x60, 0x16, 0x08, 0x99, 0xe3,
  40043. 0x2c, 0x93, 0x13, 0xc4, 0x4b, 0x10, 0xe0, 0x42, 0xca, 0x3f, 0x32, 0xa7,
  40044. 0xa4, 0xd2, 0xfc, 0x9c, 0x93, 0xb6, 0x5f, 0xe2, 0x5b, 0x6e, 0x40, 0x0c,
  40045. 0x63, 0xf8, 0xf8, 0xe1, 0x2d, 0xcd, 0x86, 0x07, 0x79, 0xdb, 0x61, 0xad,
  40046. 0x24, 0xfd, 0x1e, 0x66, 0x3e, 0x8d, 0x76, 0xba, 0x98, 0x8e, 0x94, 0xc7,
  40047. 0x57, 0xb1, 0x65, 0xce, 0x4f, 0x97, 0xfa, 0x34, 0x7c, 0x97, 0x6b, 0xcd,
  40048. 0x3c, 0x42, 0x81, 0xa4, 0xd1, 0x75, 0xeb, 0x6d, 0x0c, 0x31, 0x0e, 0x6f,
  40049. 0xd5, 0x75, 0xe7, 0xff, 0x83, 0xdd, 0x7a, 0x4d, 0x83, 0x67, 0xa7, 0x4b,
  40050. 0xc1, 0x74, 0xad, 0x37, 0x38, 0x99, 0xe0, 0xf5, 0x5a, 0x44, 0x36, 0xa2,
  40051. 0x20, 0x2b, 0xfc, 0xc9, 0xfa, 0x68, 0xcb, 0xf0, 0x6f, 0x0a, 0x46, 0x1d,
  40052. 0xb5, 0xca, 0x5b, 0x96, 0x1b, 0x3a, 0xaf, 0x7d, 0x01, 0x7a, 0xd2, 0x09,
  40053. 0xcc, 0xd4, 0xe4, 0xb1, 0x49, 0x34, 0x56, 0x68, 0x9c, 0x0f, 0x23, 0xe9,
  40054. 0xb3, 0x4b, 0xed, 0x3d, 0xe7, 0x8d, 0x19, 0x6e, 0xe6, 0xfa, 0x06, 0x55,
  40055. 0xb8, 0x06, 0x4d, 0xa8, 0x45, 0x20, 0x91, 0xf7, 0xfa, 0x0b, 0x6b, 0xce,
  40056. 0x55, 0xa7, 0x14, 0x1b, 0xf9, 0xea, 0xc5, 0x79, 0x78, 0xf7, 0x3a, 0xd9,
  40057. 0xfc, 0x07, 0x43, 0x06, 0x90, 0x94, 0x5e, 0xc9, 0x48, 0x51, 0xe5, 0x96,
  40058. 0x68, 0x78, 0xc8, 0xcb, 0xd1, 0xf3, 0x65, 0xef, 0x14, 0x91, 0xa3, 0xca,
  40059. 0x8b, 0x77, 0x40, 0x84, 0xf4, 0x2e, 0xe7, 0x56, 0xe3, 0xab, 0xa0, 0xa8,
  40060. 0x61, 0x93, 0x17, 0x95, 0x9e, 0xff, 0x3a, 0xd4, 0x12, 0xea, 0x13, 0xe6,
  40061. 0x82, 0x16, 0xed, 0x14, 0x70, 0x91, 0xcc, 0x72, 0x58, 0x99, 0xa1, 0x7f,
  40062. 0xf3, 0x84, 0x10, 0xf4, 0x01, 0x0d, 0x05, 0x45, 0x4d, 0xca, 0x05, 0x03,
  40063. 0x75, 0x7e, 0xbb, 0x44, 0x2e, 0xf5, 0xee, 0xed, 0x64, 0x9b, 0xd3, 0xde,
  40064. 0x3e, 0xfc, 0x31, 0x8c, 0xca, 0x23, 0x66, 0x25, 0xac, 0x5f, 0x0f, 0x33,
  40065. 0x0f, 0xd2, 0xe9, 0xc9, 0x96, 0x2a, 0xe2, 0xb8, 0xed, 0x93, 0xd3, 0x78,
  40066. 0xd8, 0x81, 0xe4, 0x52, 0x9a, 0xc6, 0x64, 0x1d, 0x2d, 0x5f, 0x93, 0x9a,
  40067. 0x2e, 0x73, 0xc4, 0x17, 0xae, 0xc6, 0x08, 0x0d, 0x2d, 0xe9, 0x4b, 0x10,
  40068. 0x29, 0xa8, 0x4e, 0x8c, 0x08, 0x59, 0x87, 0x10, 0x0d, 0x5d, 0xfa, 0xec,
  40069. 0xd6, 0x42, 0xf6, 0x5c, 0xa4, 0x0d, 0xaa, 0x64, 0x8e, 0x20, 0xa5, 0x50,
  40070. 0x9f, 0x0b, 0x85, 0x37, 0x57, 0x15, 0x7c, 0xb1, 0xe4, 0xdd, 0xd5, 0x19,
  40071. 0x3b, 0x10, 0x7d, 0x22, 0xdb, 0x53, 0x8b, 0x7b, 0x32, 0xf7, 0xf2, 0x24,
  40072. 0x92, 0xb2, 0x05, 0xd1, 0xfd, 0xfc, 0x11, 0xd6, 0xfd, 0x3c, 0x8d, 0xd7,
  40073. 0xb0, 0x58, 0x50, 0x06, 0x84, 0x61, 0xa6, 0x78, 0x04, 0x1d, 0x7f, 0x92,
  40074. 0x0e, 0x8b, 0xb3, 0x63, 0x43, 0xc5, 0x30, 0x4c, 0xce, 0x2b, 0x44, 0x70,
  40075. 0x53, 0x7c, 0xb5, 0xbd, 0x30, 0xcb, 0x41, 0x19, 0x27, 0x69, 0xfe, 0x41,
  40076. 0x92, 0xae, 0xf0, 0x37, 0x33, 0xf0, 0x95, 0xe4, 0xe8, 0x4f, 0x75, 0x41,
  40077. 0x64, 0x87, 0xc5, 0x68, 0xd3, 0xce, 0xfa, 0xaa, 0xe8, 0x59, 0x88, 0xfe,
  40078. 0x24, 0x46, 0x27, 0x60, 0x71, 0x36, 0x78, 0x66, 0x3c, 0x36, 0x8e, 0xdb,
  40079. 0x90, 0x67, 0xa5, 0x6a, 0xfe, 0xd3, 0x23, 0x28, 0x91, 0x34, 0x24, 0x67,
  40080. 0x4b, 0x01, 0x6a, 0x0e, 0x02, 0xb7, 0xf0, 0xa8, 0xd4, 0x76, 0xd5, 0xa8,
  40081. 0x1c, 0xd3, 0xb3, 0x7d, 0x74, 0xc6, 0x17, 0x96, 0xa7, 0xf9, 0xad, 0x24,
  40082. 0x36, 0xd2, 0xeb, 0x34, 0x5a, 0xcc, 0x9c, 0x01, 0x99, 0xbe, 0x21, 0x4f,
  40083. 0x27, 0x9d, 0x6b, 0xca, 0x27, 0x1b, 0x60, 0x51, 0x41, 0x23, 0xe1, 0xcb,
  40084. 0xfc, 0x17, 0x2e, 0x1a, 0x4d, 0x3d, 0x51, 0xb3, 0x91, 0x8c, 0x53, 0x4d,
  40085. 0xd7, 0xbc, 0xa4, 0x07, 0xd7, 0x17, 0x19, 0x18, 0x61, 0x38, 0x4e, 0x05,
  40086. 0x81, 0x3f, 0x43, 0x8a, 0x00, 0x60, 0xdc, 0x30, 0xf4, 0x38, 0x3f, 0x93,
  40087. 0x82, 0x10, 0x29, 0x73, 0xa9, 0xbd, 0x63, 0x15, 0x7d, 0xac, 0x2e, 0xc9,
  40088. 0x05, 0xc1, 0x01, 0x41, 0x18, 0x5a, 0xc0, 0xc8, 0xc7, 0x81, 0x69, 0xe7,
  40089. 0x24, 0x21, 0x57, 0xaf, 0x88, 0x73, 0x7c, 0x53, 0x29, 0xae, 0x5a, 0xdf,
  40090. 0x76, 0x37, 0x56, 0x4f, 0x1f, 0x6b, 0xfd, 0x71, 0xbb, 0x80, 0x4a, 0xd7,
  40091. 0x53, 0x50, 0x10, 0x2d, 0xfc, 0x1a, 0xaf, 0x7c, 0x1f, 0xe8, 0xd0, 0x6c,
  40092. 0xa6, 0x45, 0x3d, 0xb5, 0x3d, 0xb2, 0xfc, 0x97, 0xa9, 0xbf, 0x7c, 0x0f,
  40093. 0x32, 0x7a, 0xcc, 0xa9, 0x2f, 0xd0, 0xc6, 0xe6, 0xcd, 0x04, 0x1d, 0x71,
  40094. 0x91, 0xb9, 0x59, 0x4b, 0xad, 0xa0, 0xde, 0x9e, 0xdc, 0x9c, 0x10, 0xeb,
  40095. 0x8d, 0xd6, 0x65, 0x57, 0xbc, 0x96, 0xfd, 0x0f, 0xcc, 0x73, 0xbe, 0x39,
  40096. 0x27, 0x99, 0x94, 0xf5, 0xe1, 0xbb, 0x32, 0xcd, 0x27, 0x7e, 0x08, 0xa0,
  40097. 0xd2, 0x92, 0x39, 0xeb, 0x71, 0xc8, 0xe8, 0x34, 0x57, 0x34, 0x4b, 0x20,
  40098. 0x3f, 0xe2, 0x68, 0xec, 0xc0, 0x8a, 0x71, 0xa3, 0x16, 0xa2, 0x91, 0x77,
  40099. 0xde, 0x41, 0x12, 0xa5, 0xf5, 0x2a, 0x63, 0x60, 0x55, 0xd0, 0x33, 0xa4,
  40100. 0xa7, 0x2e, 0xcb, 0x80, 0x08, 0xe5, 0x76, 0x16, 0x75, 0x04, 0x57, 0xe3,
  40101. 0x14, 0x71, 0x4e, 0x57, 0x29, 0x23, 0x0e, 0xc0, 0xcc, 0xad, 0xba, 0xdc,
  40102. 0x96, 0x5d, 0x23, 0x49, 0x42, 0xd8, 0x91, 0x08, 0x0d, 0x52, 0xf4, 0x5f,
  40103. 0xcd, 0xb7, 0x03, 0xaa, 0x73, 0x26, 0xa8, 0xd5, 0x5b, 0x0c, 0x85, 0xc8,
  40104. 0x84, 0x50, 0x9e, 0x70, 0x18, 0x45, 0x27, 0x82, 0x20, 0x75, 0xad, 0x52,
  40105. 0x5c, 0x80, 0x4b, 0xb1, 0x0b, 0x3b, 0x30, 0x39, 0x02, 0x54, 0x18, 0x5d,
  40106. 0x02, 0x9e, 0x85, 0x31, 0x4a, 0x07, 0x9c, 0x59, 0x5d, 0xab, 0x13, 0x4f,
  40107. 0x8f, 0x6e, 0x39, 0x20, 0xb2, 0xc5, 0x31, 0x93, 0xc6, 0xcc, 0xfb, 0xdc,
  40108. 0x15, 0xba, 0x3d, 0xcc, 0xbb, 0xd2, 0x6f, 0x04, 0x21, 0xdf, 0x0b, 0x27,
  40109. 0x5c, 0xd2, 0x6e, 0xfa, 0xda, 0x86, 0x5d, 0xe4, 0xca, 0xa4, 0x90, 0x22,
  40110. 0xa2, 0x80, 0xb5, 0x33, 0x17, 0xdb, 0x9b, 0x7b, 0x0a, 0xcc, 0x0f, 0x9b,
  40111. 0x38, 0x06, 0xdf, 0x10, 0x11, 0xa1, 0xd7, 0x2c, 0x24, 0xf0, 0xa8, 0x34,
  40112. 0x24, 0xfb, 0x99, 0xba, 0x0a, 0xb5, 0xa1, 0x94, 0x6c, 0x2d, 0xf8, 0xda,
  40113. 0x74, 0xaf, 0x19, 0x59, 0x84, 0xb2, 0x68, 0x1c, 0xef, 0xa1, 0xf5, 0x18,
  40114. 0x8f, 0x10, 0xf6, 0xb3, 0x6d, 0x33, 0x87, 0xe0, 0x25, 0xc8, 0x65, 0x5c,
  40115. 0x2f, 0x51, 0x07, 0x83, 0x69, 0x1b, 0xce, 0xa8, 0xe6, 0xe4, 0x27, 0x62,
  40116. 0x5d, 0x9b, 0x7f, 0xa7, 0x07, 0xc8, 0x54, 0x86, 0x90, 0xa5, 0x06, 0x6a,
  40117. 0x94, 0x80, 0x84, 0x97, 0xaa, 0x2a, 0xb9, 0x79, 0xe5, 0x19, 0x7a, 0x91,
  40118. 0xef, 0x8b, 0x58, 0xdc, 0xf9, 0x90, 0x94, 0xa2, 0x25, 0x4c, 0x69, 0xd8,
  40119. 0x6e, 0x9e, 0xad, 0xf8, 0x82, 0x17, 0x37, 0xc9, 0x20, 0x15, 0x24, 0x40,
  40120. 0xe5, 0xc6, 0xc1, 0xc7, 0xbd, 0xd4, 0x62, 0xff, 0x16, 0x6d, 0xa5, 0xec,
  40121. 0xe9, 0x67, 0x41, 0x9d, 0x3e, 0xfb, 0x22, 0x81, 0x80, 0x61, 0x37, 0x45,
  40122. 0xa5, 0x9f, 0x70, 0xff, 0xd4, 0x99, 0x3d, 0x79, 0x45, 0xd0, 0x27, 0xc2,
  40123. 0x32, 0xbe, 0xd4, 0xe2, 0x53, 0xa8, 0x8c, 0x94, 0x8b, 0xbe, 0x8a, 0x43,
  40124. 0xf7, 0x2a, 0x28, 0x49, 0xf4, 0xce, 0x2e, 0x0b, 0x98, 0xc7, 0xaf, 0x7d,
  40125. 0x51, 0x2e, 0xda, 0xd0, 0x7a, 0xfa, 0x91, 0x3a, 0xe6, 0xe7, 0x64, 0xd6,
  40126. 0x09, 0xd8, 0x5d, 0x6a, 0x97, 0xcf, 0x89, 0x96, 0x72, 0x21, 0x97, 0x61,
  40127. 0xc5, 0x1b, 0xd8, 0xa1, 0xf0, 0xcd, 0x9d, 0xe4, 0xe9, 0x13, 0xd0, 0x16,
  40128. 0x41, 0x20, 0xa4, 0x2c, 0x33, 0xf5, 0x3d, 0xfe, 0x80, 0xe8, 0xb2, 0x52,
  40129. 0x0e, 0x18, 0x31, 0x19, 0x50, 0xeb, 0xc6, 0x99, 0x43, 0xab, 0x9a, 0x59,
  40130. 0x5d, 0x6c, 0x84, 0x00, 0x88, 0x45, 0x7c, 0x73, 0xdf, 0x56, 0x61, 0x3a,
  40131. 0xe1, 0x55, 0xb8, 0x59, 0x13, 0xcc, 0x0e, 0x53, 0xe9, 0xf4, 0x74, 0xa0,
  40132. 0xf2, 0x15, 0xd2, 0xa8, 0xf9, 0xd4, 0x0d, 0x3d, 0xe7, 0x3d, 0x7d, 0x5b,
  40133. 0x19, 0x89, 0x8b, 0x2c, 0x4d, 0x8a, 0xeb, 0xc3, 0x43, 0x31, 0x9a, 0x45,
  40134. 0x72, 0x5b, 0x25, 0xb6, 0xa2, 0xc1, 0x98, 0xe3, 0x8a, 0xd4, 0x90, 0xd0,
  40135. 0x3e, 0x13, 0xf0, 0xd7, 0x90, 0x34, 0x94, 0xcc, 0xf1, 0x0a, 0xa9, 0x30,
  40136. 0xd1, 0x95, 0x43, 0x07, 0xcd, 0xd2, 0xca, 0xb0, 0xe5, 0xd4, 0xf1, 0xa1,
  40137. 0xc5, 0x9b, 0xf4, 0x98, 0x28, 0xba, 0xde, 0x40, 0xd6, 0x98, 0x98, 0x20,
  40138. 0x9c, 0x84, 0x9e, 0xc6, 0x57, 0xd8, 0x84, 0xc4, 0xa2, 0x9b, 0x53, 0x50,
  40139. 0xa5, 0xa6, 0x0b, 0x47, 0xe8, 0x08, 0x7d, 0xd7, 0x09, 0xa4, 0x0c, 0x2b,
  40140. 0x27, 0xde, 0xf9, 0x78, 0xbc, 0xa4, 0xb6, 0xc6, 0x1b, 0xda, 0xce, 0x6a,
  40141. 0xf8, 0x1a, 0xf5, 0xfe, 0x7b, 0xab, 0x58, 0x7c, 0xdc, 0x72, 0x02, 0x94,
  40142. 0x99, 0xf0, 0x3c, 0x37, 0x87, 0x5b, 0xd2, 0x4b, 0x5a, 0x80, 0x83, 0xd7,
  40143. 0xfc, 0x9d, 0xa7, 0x51, 0x81, 0xb8, 0x62, 0xff, 0x4b, 0xb3, 0x9f, 0x07,
  40144. 0xc3, 0x54, 0xfb, 0x41, 0x85, 0x42, 0x9d, 0xac, 0x27, 0x81, 0x2e, 0xaf,
  40145. 0x98, 0x67, 0x8c, 0x23, 0xad, 0x45, 0xfe, 0x6a, 0x57, 0x9f, 0x18, 0xc5,
  40146. 0x71, 0x8c, 0xad, 0x3f, 0x30, 0x3c, 0xaa, 0x47, 0x8d, 0xba, 0xc8, 0x7f,
  40147. 0x03, 0x1c, 0x86, 0xee, 0xba, 0x3f, 0x59, 0x45, 0xd4, 0xd0, 0xf5, 0x54,
  40148. 0x9e, 0xcb, 0x08, 0xcf, 0xca, 0x40, 0x0a, 0x06, 0xc0, 0x1e, 0x60, 0x1f,
  40149. 0x33, 0xbf, 0x2c, 0xa8, 0x5f, 0xce, 0x23, 0xa0, 0xe2, 0x1c, 0x2d, 0x56,
  40150. 0x2a, 0x44, 0x61, 0x58, 0xf1, 0x84, 0x63, 0x4f, 0x0d, 0x5e, 0xfb, 0x83,
  40151. 0x0f, 0x36, 0x1b, 0xf4, 0x8f, 0x17, 0x82, 0x2e, 0x04, 0x2c, 0x77, 0x9d,
  40152. 0x32, 0x58, 0xb8, 0xb0, 0xf9, 0x44, 0xd2, 0xf6, 0x84, 0xa4, 0x8b, 0x28,
  40153. 0x53, 0xd6, 0x99, 0x81, 0x84, 0x43, 0xf0, 0xc1, 0x15, 0xc6, 0x74, 0x4f,
  40154. 0xab, 0x05, 0xcc, 0x80, 0xdf, 0xef, 0xcf, 0xaf, 0x14, 0x82, 0xdf, 0x51,
  40155. 0x7c, 0x28, 0x5e, 0x5b, 0x27, 0x5e, 0x91, 0x8b, 0x54, 0x3d, 0x54, 0x26,
  40156. 0xb0, 0x3f, 0xd7, 0xc5, 0xce, 0xf3, 0x6d, 0x2c, 0x12, 0xc6, 0xb4, 0x48,
  40157. 0x60, 0x11, 0x9c, 0xef, 0x29, 0x98, 0x9c, 0x76, 0x4e, 0x73, 0x2b, 0xd2,
  40158. 0x23, 0x53, 0x7d, 0x03, 0xc2, 0x2f, 0x8a, 0xa1, 0xe2, 0x84, 0x54, 0x2d,
  40159. 0xd8, 0xc6, 0x55, 0x77, 0x9d, 0x07, 0x67, 0x1f, 0x1a, 0xd3, 0x57, 0x4c,
  40160. 0x25, 0x79, 0x8f, 0xd8, 0x82, 0xc2, 0x4d, 0x87, 0x84, 0x33, 0xdc, 0x47,
  40161. 0xed, 0x9e, 0xfb, 0xd2, 0x62, 0xc8, 0x50, 0x76, 0xda, 0x3c, 0x3c, 0x05,
  40162. 0x0e, 0x2d, 0x30, 0x56, 0xca, 0x4d, 0x6a, 0xe2, 0x17, 0x24, 0x26, 0x9c,
  40163. 0xff, 0x09, 0xec, 0xb3, 0x94, 0xec, 0xab, 0x69, 0xb2, 0xf0, 0xa5, 0x66,
  40164. 0x18, 0x92, 0x49, 0x6b, 0x90, 0xf5, 0x77, 0x5a, 0x18, 0xe5, 0x51, 0x36,
  40165. 0x4a, 0x35, 0x54, 0x98, 0x48, 0x04, 0xa9, 0x0f, 0xcb, 0x55, 0xf1, 0x71,
  40166. 0xad, 0x1a, 0x4a, 0x2c, 0x0e, 0x5d, 0x5e, 0x77, 0x47, 0xf5, 0x46, 0x17,
  40167. 0x6b, 0x94, 0x2a, 0xbc, 0x40, 0xe5, 0xa7, 0xa6, 0x88, 0x41, 0x76, 0x22,
  40168. 0x47, 0xd1, 0xe8, 0x2b, 0x18, 0x48, 0x21, 0xc0, 0xe8, 0x4f, 0xe2, 0xb2,
  40169. 0x7e, 0x03, 0xbb, 0x25, 0x9c, 0xc8, 0x68, 0x66, 0x48, 0x25, 0x6a, 0xf2,
  40170. 0x64, 0x29, 0xec, 0x79, 0xba, 0xdb, 0x34, 0xe1, 0xd4, 0xf9, 0x52, 0x0e,
  40171. 0xfd, 0x8d, 0x86, 0x94, 0x71, 0xd8, 0xe0, 0x86, 0x02, 0x9b, 0xd4, 0x65,
  40172. 0x69, 0x5e, 0x01, 0x32, 0x87, 0x59, 0xd8, 0x6c, 0xbc, 0x8a, 0x9f, 0x58,
  40173. 0x28, 0x8c, 0x97, 0xef, 0x33, 0xb2, 0xda, 0x45, 0xa0, 0xec, 0xe5, 0x5b,
  40174. 0xac, 0xc6, 0x65, 0xc1, 0xb6, 0xcb, 0xf7, 0x85, 0x0e, 0xfa, 0x78, 0x36,
  40175. 0x30, 0x84, 0x90, 0xa8, 0xf8, 0x42, 0x25, 0xa5, 0xdd, 0xdc, 0xdc, 0x89,
  40176. 0xd3, 0xf0, 0x73, 0x9a, 0xd8, 0x95, 0x8f, 0x04, 0xbf, 0xc1, 0xfd, 0x94,
  40177. 0xff, 0xe6, 0xf8, 0x4e, 0xc6, 0x43, 0xc9, 0x60, 0x30, 0xe9, 0x68, 0xa8,
  40178. 0x76, 0xfb, 0xfa, 0xdf, 0xc0, 0x9b, 0xbc, 0xbc, 0x34, 0xe4, 0x38, 0xfd,
  40179. 0x93, 0xb0, 0x47, 0xb2, 0x3e, 0x83, 0x6c, 0xef, 0xe1, 0xaf, 0x35, 0xb4,
  40180. 0x90, 0x2a, 0x32, 0xaf, 0x25, 0x3f, 0x3e, 0x72, 0x61, 0xc0, 0x0f, 0x29,
  40181. 0xbb, 0x46, 0x6e, 0x2e, 0x94, 0x7d, 0xdd, 0xb7, 0x67, 0x1f, 0x7b, 0x64,
  40182. 0xcb, 0xa5, 0x9a, 0x58, 0x63, 0x20, 0xa7, 0xc0, 0x94, 0xa9, 0xad, 0x90,
  40183. 0x7d, 0xf3, 0x2b, 0x61, 0x2b, 0x64, 0x3d, 0x8a, 0xc3, 0xd1, 0xcb, 0xad,
  40184. 0x36, 0x44, 0xe6, 0x29, 0x8b, 0x3d, 0x95, 0x7c, 0xa7, 0xa2, 0xfa, 0x1b,
  40185. 0x16, 0x8d, 0x9e, 0xc4, 0xf8, 0x4c, 0x76, 0x20, 0x00, 0x68, 0x07, 0x99,
  40186. 0x9c, 0x60, 0xe6, 0x16, 0x6a, 0x6f, 0x8a, 0xbe, 0x71, 0x95, 0xa1, 0xcb,
  40187. 0xfe, 0x7c, 0x41, 0x59, 0x61, 0x20, 0xf9, 0x54, 0x3c, 0xb1, 0x19, 0x5c,
  40188. 0x42, 0x67, 0x3f, 0xff, 0xf3, 0x32, 0x21, 0x9c, 0x9e, 0x88, 0xf9, 0x97,
  40189. 0x00, 0x43, 0x73, 0x4a, 0xfc, 0x54, 0xeb, 0x27, 0x79, 0x14, 0x85, 0xd3,
  40190. 0xdc, 0x47, 0xb3, 0x6d, 0x24, 0xd3, 0xf7, 0x7a, 0xfb, 0x90, 0x7c, 0x6e,
  40191. 0xcd, 0x4e, 0xbf, 0x26, 0x76, 0xd2, 0xe8, 0xcc, 0x67, 0xd1, 0x23, 0x3c,
  40192. 0x94, 0x16, 0x1e, 0x07, 0x36, 0x7c, 0x96, 0xf6, 0xe8, 0x50, 0x72, 0x26,
  40193. 0x56, 0x67, 0x89, 0xa9, 0x11, 0xfb, 0x1d, 0xb8, 0xb9, 0x2a, 0x55, 0xb7,
  40194. 0x85, 0xf7, 0x40, 0xa2, 0xfc, 0x9f, 0x30, 0xec, 0x8f, 0x9a, 0x1c, 0xc8,
  40195. 0xe4, 0xc5, 0x1f, 0xcb, 0x0a, 0x60, 0x80, 0x41, 0xec, 0x88, 0x8a, 0xda,
  40196. 0x7c, 0x7a, 0xa1, 0x96, 0x51, 0x62, 0x16, 0x63, 0x75, 0x36, 0x28, 0x7c,
  40197. 0xc9, 0xd0, 0x27, 0x0c, 0x9e, 0x18, 0x4a, 0x82, 0xf7, 0x02, 0xb9, 0x40,
  40198. 0x8f, 0xd5, 0x97, 0x7a, 0x35, 0xa9, 0x3a, 0xb3, 0x8b, 0x6b, 0xf1, 0x9a,
  40199. 0xd1, 0xe7, 0x14, 0x38, 0x5e, 0xba, 0x8c, 0xbf, 0x32, 0xaa, 0x34, 0x30,
  40200. 0x7c, 0x1e, 0x11, 0xcd, 0x1f, 0x9f, 0xcf, 0x4d, 0x14, 0xce, 0x67, 0xf9,
  40201. 0x9c, 0x89, 0x07, 0x92, 0x44, 0x6e, 0x9a, 0x16, 0xe4, 0xfb, 0x67, 0x01,
  40202. 0x3f, 0x4c, 0x14, 0x89, 0x33, 0x87, 0x46, 0xc6, 0xe4, 0x66, 0x94, 0xd4,
  40203. 0x87, 0x4f, 0x2c, 0x92, 0x1b, 0xae, 0x82, 0xe7, 0x99, 0xaa, 0xb4, 0x99,
  40204. 0x81, 0x26, 0xa6, 0x6f, 0x1d, 0xc1, 0x95, 0x80, 0xe9, 0xea, 0xe3, 0x44,
  40205. 0x6a, 0x2b, 0xd2, 0xe0, 0x0d, 0x69, 0x42, 0xf7, 0x27, 0x6b, 0x4f, 0x02,
  40206. 0x7a, 0x33, 0x7b, 0x43, 0x3d, 0xef, 0x10, 0xaa, 0xab, 0xc5, 0xa2, 0xf0,
  40207. 0xbb, 0x07, 0x4b, 0x26, 0x0c, 0x58, 0xcd, 0x3b, 0xd2, 0x6d, 0xa5, 0x32,
  40208. 0x37, 0x88, 0x4e, 0x8b, 0xe3, 0x75, 0xb0, 0xbb, 0x87, 0xea, 0xa4, 0x53,
  40209. 0xf3, 0xff, 0x39, 0x92, 0x44, 0xab, 0x7b, 0x71, 0x62, 0x31, 0x6b, 0x31,
  40210. 0xca, 0x97, 0xba, 0xd7, 0x41, 0xe0, 0x47, 0x47, 0x4f, 0x77, 0xa2, 0x35,
  40211. 0x62, 0x7a, 0xc1, 0xb6, 0x69, 0x10, 0x09, 0xce, 0xfc, 0x92, 0xcc, 0xc5,
  40212. 0x7a, 0x11, 0xf1, 0xc1, 0xa0, 0x80, 0xe5, 0x42, 0x17, 0xb6, 0x3f, 0xab,
  40213. 0xc1, 0xa2, 0x41, 0xfb, 0xe3, 0x98, 0x2d, 0x7a, 0xe4, 0x1b, 0x1f, 0x7e,
  40214. 0x71, 0x3c, 0x3e, 0x90, 0x8c, 0x60, 0x30, 0xb7, 0x73, 0x06, 0x1f, 0x8a,
  40215. 0xce, 0x50, 0x20, 0x7c, 0xfa, 0x8c, 0xf2, 0x14, 0xd9, 0x00, 0xa2, 0x21,
  40216. 0xea, 0x10, 0x36, 0x21, 0x6f, 0x7f, 0x13, 0xe3, 0x6c, 0xb2, 0xd6, 0xa5,
  40217. 0xa6, 0x6e, 0xa9, 0xe7, 0x1d, 0xdf, 0xc9, 0x97, 0x60, 0x75, 0xa3, 0x55,
  40218. 0xa1, 0x2c, 0x94, 0xd7, 0x85, 0x4b, 0x44, 0xc6, 0x9c, 0x17, 0xc2, 0xad,
  40219. 0xe6, 0x56, 0x72, 0x1d, 0xb9, 0x13, 0x54, 0xfe, 0x8c, 0xec, 0xf4, 0xa3,
  40220. 0x54, 0x6b, 0x31, 0xbc, 0x55, 0x9e, 0x01, 0xd4, 0x9b, 0x24, 0x9e, 0x51,
  40221. 0xaf, 0x67, 0x76, 0x02, 0xf7, 0x34, 0x6a, 0xaa, 0xb0, 0x3c, 0x70, 0x2e,
  40222. 0xc8, 0x86, 0xfa, 0x40, 0x89, 0x12, 0xb7, 0x49, 0x38, 0x0b, 0xf7, 0x66,
  40223. 0xd2, 0x2e, 0x58, 0xf1, 0x22, 0x3b, 0xb3, 0x40, 0x6b, 0x7a, 0x68, 0x4d,
  40224. 0x42, 0xfd, 0xbf, 0xa0, 0xf7, 0x2f, 0x63, 0x4a, 0x87, 0xe7, 0x99, 0x52,
  40225. 0x6e, 0xe7, 0xdd, 0xca, 0x19, 0x71, 0xee, 0x92, 0xe2, 0x68, 0x0e, 0xe1,
  40226. 0xb7, 0x90, 0x1f, 0xc4, 0xef, 0xf8, 0xf6, 0x85, 0x53, 0x18, 0x33, 0x86,
  40227. 0x15, 0xc8, 0x29, 0x58, 0x6f, 0xf0, 0x1c, 0x14, 0x73, 0xa9, 0x8e, 0x88,
  40228. 0x74, 0xd4, 0x21, 0xf5, 0xc6, 0x7c, 0xd8, 0x96, 0x0f, 0xb0, 0xa6, 0x7b,
  40229. 0xf7, 0x72, 0x15, 0xd7, 0x30, 0x6b, 0x15, 0x1d, 0x3f, 0xb7, 0x4e, 0xaa,
  40230. 0xc0, 0x52, 0x1d, 0x84, 0xbf, 0x98, 0xbd, 0x33, 0x02, 0xab, 0x8b, 0xd0,
  40231. 0x9c, 0x85, 0x2f, 0xa3, 0xfb, 0x46, 0x8d, 0x4d, 0x97, 0x1a, 0x8a, 0x3c,
  40232. 0x73, 0x5b, 0x3b, 0x58, 0x26, 0xba, 0x6b, 0x45, 0x2e, 0x24, 0x66, 0x79,
  40233. 0x7d, 0xc4, 0xf8, 0x8c, 0x05, 0x7d, 0x5c, 0x23, 0xb9, 0xe8, 0x5d, 0xfe,
  40234. 0xc9, 0x84, 0xe5, 0x58, 0x40, 0xa4, 0xb7, 0x55, 0x74, 0x69, 0x92, 0x9c,
  40235. 0x3e, 0x19, 0xb1, 0xb6, 0x51, 0xe9, 0x71, 0xcc, 0x96, 0x2b, 0x01, 0x71,
  40236. 0xf5, 0xb9, 0xde, 0x77, 0xfe, 0x2e, 0x74, 0x9c, 0x6a, 0x52, 0x17, 0x1e,
  40237. 0xea, 0xd9, 0xc8, 0x14, 0xbe, 0x61, 0xdf, 0xe9, 0x96, 0x24, 0x5a, 0x9a,
  40238. 0xd8, 0xd7, 0xad, 0x71, 0xe0, 0xf4, 0xbb, 0x9e, 0xae, 0x95, 0xcd, 0x58,
  40239. 0x94, 0x81, 0xee, 0x46, 0x84, 0x65, 0x39, 0xb1, 0x1b, 0x1e, 0xf5, 0x50,
  40240. 0xad, 0x56, 0x58, 0xb7, 0x53, 0x9b, 0x2a, 0x2f, 0x09, 0x61, 0x57, 0xda,
  40241. 0xf5, 0xdc, 0x9f, 0x3c, 0x6c, 0x69, 0x0d, 0x61, 0x49, 0xb2, 0xe0, 0xb2,
  40242. 0xe5, 0xef, 0x19, 0xbe, 0x04, 0xf6, 0x6b, 0xad, 0x41, 0x4c, 0x5a, 0x50,
  40243. 0xf6, 0xac, 0x1b, 0x25, 0x8a, 0xdd, 0xe3, 0x57, 0xab, 0x7c, 0x92, 0xe4
  40244. };
  40245. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40246. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_pub_key[] = {
  40247. 0xef, 0x49, 0x79, 0x47, 0x15, 0xc4, 0x8a, 0xa9, 0x74, 0x2a,
  40248. 0xf0, 0x36, 0x94, 0x5c, 0x91, 0x1c, 0x5d, 0xff, 0x2c, 0x83,
  40249. 0xf2, 0x8b, 0x04, 0xfc, 0x5d, 0x64, 0xbd, 0x49, 0x73, 0xcd,
  40250. 0xcc, 0x99, 0x50, 0x5f, 0x2b, 0x16, 0x3a, 0xbb, 0x98, 0xc0,
  40251. 0xa7, 0x69, 0x0e, 0x95, 0x99, 0x0b, 0xa2, 0x6c, 0xfe, 0x6c,
  40252. 0xdb, 0xc8, 0xa7, 0x09, 0x46, 0x6c, 0x90, 0x50, 0xa4, 0x75,
  40253. 0x30, 0xf7, 0x90, 0xac, 0x31, 0xb6, 0xdd, 0x21, 0xaf, 0xc6,
  40254. 0xf9, 0xfe, 0xee, 0xc6, 0x5b, 0xa8, 0x8f, 0x0a, 0x2e, 0xd0,
  40255. 0x42, 0xab, 0xa8, 0x3c, 0x8d, 0xbf, 0xf7, 0x44, 0xbd, 0x0d,
  40256. 0xcf, 0xf4, 0x68, 0xfc, 0x16, 0x67, 0xf7, 0x39, 0x48, 0x5f,
  40257. 0x56, 0xd1, 0xe7, 0x1f, 0x49, 0x80, 0x50, 0xbe, 0x54, 0xd1,
  40258. 0xb7, 0xc9, 0xd2, 0x32, 0xc7, 0x08, 0x8c, 0xde, 0x2c, 0x31,
  40259. 0xf6, 0x1d, 0xc7, 0xac, 0xb3, 0x79, 0xd7, 0x4b, 0x1b, 0x23,
  40260. 0x89, 0x0a, 0xdc, 0x8e, 0x44, 0x41, 0x14, 0x28, 0x99, 0x13,
  40261. 0xb3, 0x26, 0xa6, 0x0e, 0x83, 0x60, 0xaa, 0x8d, 0x7c, 0x23,
  40262. 0x13, 0xba, 0x6c, 0x28, 0x90, 0x56, 0x84, 0xa1, 0x23, 0x8b,
  40263. 0x81, 0x20, 0x97, 0x7c, 0x66, 0x3f, 0xed, 0x5d, 0xd0, 0xe4,
  40264. 0x5d, 0xee, 0x46, 0xbc, 0x4b, 0x3c, 0x03, 0xb5, 0xbc, 0x4d,
  40265. 0x8d, 0x37, 0xa3, 0x56, 0x4b, 0x33, 0xad, 0xef, 0xd4, 0xb6,
  40266. 0xec, 0xdb, 0x04, 0x9a, 0x19, 0x58, 0x57, 0xd8, 0x00, 0x3a,
  40267. 0x92, 0x61, 0x0c, 0x0b, 0xc8, 0x52, 0xe5, 0x04, 0x02, 0x9a,
  40268. 0x00, 0x7e, 0xec, 0x7e, 0x94, 0xaa, 0xef, 0x2d, 0x7f, 0xb6,
  40269. 0x2e, 0x7c, 0xb0, 0x73, 0xa2, 0x20, 0xc0, 0x07, 0x30, 0x41,
  40270. 0x50, 0x20, 0x14, 0x18, 0x21, 0x5e, 0x2a, 0x6f, 0x70, 0x21,
  40271. 0xd6, 0x97, 0x13, 0xb9, 0xc1, 0x9e, 0x90, 0x67, 0xcc, 0x55,
  40272. 0x8a, 0xec, 0xec, 0x0a, 0x1e, 0x90, 0xdc, 0x3f, 0xb0, 0x4d,
  40273. 0xd1, 0x18, 0xea, 0x4f, 0xcb, 0x5d, 0x15, 0x4c, 0xb8, 0x35,
  40274. 0x9b, 0x34, 0x24, 0x30, 0x06, 0x53, 0x17, 0xf0, 0xbe, 0x27,
  40275. 0x36, 0xb3, 0x04, 0x6a, 0xbd, 0xbf, 0xa7, 0x39, 0xee, 0xa9,
  40276. 0x8f, 0x0e, 0x98, 0xc5, 0xf5, 0x9f, 0x46, 0x25, 0x93, 0xc9,
  40277. 0xf2, 0xf6, 0x2b, 0x8e, 0x92, 0x06, 0x01, 0x3d, 0x81, 0x18,
  40278. 0xf2, 0xec, 0xf1, 0x05, 0x4c, 0xad, 0x4b, 0xcb, 0x98, 0xa4,
  40279. 0xb5, 0x61, 0x20, 0xda, 0x81, 0xa1, 0xfb, 0x92, 0x4c, 0xaf,
  40280. 0x87, 0x6f, 0x6e, 0xd2, 0x57, 0xec, 0xcd, 0x94, 0xb3, 0x79,
  40281. 0xbf, 0x59, 0x88, 0x17, 0x81, 0xce, 0x8a, 0x57, 0xce, 0x57,
  40282. 0xae, 0x3e, 0x82, 0x81, 0x2f, 0x83, 0x61, 0xd8, 0xf9, 0x68,
  40283. 0x21, 0xe7, 0x72, 0x5b, 0xd6, 0x80, 0x55, 0x68, 0x5d, 0x67,
  40284. 0x15, 0x0c, 0x8b, 0xdc, 0x4f, 0xc3, 0x89, 0x36, 0x3c, 0xac,
  40285. 0xaf, 0x16, 0x5e, 0x1c, 0xfa, 0x68, 0x74, 0x6a, 0xab, 0x68,
  40286. 0xd8, 0x59, 0x96, 0x2d, 0x33, 0x62, 0xe4, 0xbd, 0xb3, 0xb7,
  40287. 0x4d, 0x88, 0x35, 0xb8, 0xed, 0xb2, 0x16, 0x85, 0x97, 0x08,
  40288. 0x71, 0x71, 0x39, 0x7e, 0x0c, 0x53, 0x16, 0xda, 0x38, 0xe5,
  40289. 0x28, 0x09, 0x9c, 0xd9, 0x46, 0xec, 0x68, 0xda, 0x8d, 0xd0,
  40290. 0xad, 0xb2, 0x79, 0x28, 0x3b, 0x1e, 0x12, 0xc9, 0xdf, 0xa9,
  40291. 0x6d, 0x3d, 0x29, 0x99, 0x2f, 0x53, 0xc2, 0xd0, 0xf9, 0x88,
  40292. 0x26, 0x94, 0x47, 0xaf, 0xf6, 0x96, 0xf3, 0xe1, 0x11, 0xa6,
  40293. 0x82, 0x3d, 0x43, 0x3f, 0x1f, 0xbc, 0xf6, 0x98, 0xbe, 0xff,
  40294. 0x06, 0x86, 0x61, 0x27, 0xdc, 0x91, 0x54, 0xd4, 0xfc, 0x68,
  40295. 0x83, 0xe8, 0x35, 0x3e, 0xee, 0x94, 0x59, 0x28, 0x2f, 0xde,
  40296. 0xdd, 0x03, 0x60, 0x66, 0xc1, 0x49, 0x57, 0xdd, 0xbc, 0xd5,
  40297. 0x0a, 0x67, 0x34, 0xf1, 0xa6, 0x0a, 0x57, 0x94, 0x65, 0x02,
  40298. 0x2c, 0x52, 0x43, 0x70, 0x3b, 0xc1, 0x9a, 0xff, 0xda, 0x6f,
  40299. 0xb9, 0x54, 0x47, 0x01, 0xda, 0x27, 0xe4, 0x48, 0x4a, 0x90,
  40300. 0x9f, 0xb5, 0xc3, 0xee, 0x0e, 0x09, 0x57, 0xfe, 0x48, 0x51,
  40301. 0x08, 0x34, 0x5e, 0x8f, 0x16, 0xc9, 0x0b, 0x74, 0xd9, 0x7d,
  40302. 0x22, 0x3f, 0xd6, 0xb7, 0x5d, 0xd6, 0x76, 0x00, 0x8d, 0x4e,
  40303. 0x78, 0x73, 0x86, 0xd6, 0xdb, 0x2a, 0x65, 0xab, 0xdf, 0xb0,
  40304. 0xea, 0x11, 0xad, 0xdf, 0xba, 0x43, 0xdb, 0xa8, 0x0a, 0xfb,
  40305. 0x04, 0x38, 0x81, 0x2b, 0xa3, 0x29, 0xfc, 0x95, 0x73, 0x9a,
  40306. 0x0c, 0x6c, 0x9e, 0xcd, 0xdc, 0xcf, 0x0a, 0x0c, 0x18, 0x41,
  40307. 0x6f, 0x1d, 0xa3, 0xf6, 0x12, 0x4c, 0x13, 0xf2, 0x02, 0xc6,
  40308. 0x50, 0x99, 0x86, 0x73, 0xa7, 0xf9, 0x7e, 0x84, 0x7f, 0x4c,
  40309. 0x00, 0xce, 0x2e, 0x21, 0x76, 0x8e, 0x17, 0x7a, 0x87, 0x6f,
  40310. 0x81, 0xe6, 0xc0, 0x52, 0xa5, 0xa0, 0x3c, 0x54, 0x3c, 0xec,
  40311. 0xb0, 0x9d, 0x1c, 0x3b, 0xec, 0xe5, 0x4e, 0x4a, 0x37, 0xe7,
  40312. 0xd5, 0xa9, 0x07, 0x87, 0x23, 0x28, 0x5d, 0x3d, 0x22, 0x02,
  40313. 0x79, 0x40, 0x3f, 0x2d, 0x40, 0xc9, 0xe5, 0xa6, 0x9b, 0xa8,
  40314. 0xb8, 0x76, 0xf6, 0x77, 0x5b, 0x8d, 0x72, 0x96, 0x3e, 0x13,
  40315. 0xbf, 0x76, 0xfa, 0x7b, 0xb7, 0x82, 0x5f, 0xe7, 0x9d, 0x54,
  40316. 0x0e, 0x05, 0x1a, 0x9f, 0xa4, 0x42, 0xa5, 0xb4, 0x93, 0x23,
  40317. 0x06, 0x59, 0x43, 0xa8, 0xe8, 0x5c, 0xfc, 0x18, 0x97, 0xdb,
  40318. 0xad, 0x9a, 0x80, 0x0a, 0xf2, 0x20, 0x50, 0xac, 0xc1, 0x13,
  40319. 0x3e, 0x98, 0x09, 0xde, 0xf2, 0x70, 0x9e, 0x14, 0xc2, 0x5c,
  40320. 0xec, 0x65, 0x07, 0x0b, 0xfa, 0x02, 0x5c, 0xf8, 0x71, 0xaa,
  40321. 0x9b, 0x45, 0x62, 0xe2, 0x27, 0xaf, 0x77, 0xf8, 0xe3, 0xeb,
  40322. 0x7b, 0x24, 0x7b, 0x3c, 0x67, 0xc2, 0x6d, 0x6e, 0x17, 0xae,
  40323. 0x6e, 0x86, 0x6f, 0x98, 0xc9, 0xac, 0x13, 0x9f, 0x87, 0x64,
  40324. 0x3d, 0x4d, 0x6f, 0xa0, 0xb3, 0x39, 0xc6, 0x68, 0x1b, 0xa7,
  40325. 0xeb, 0x3e, 0x0f, 0x6b, 0xc7, 0xa4, 0xe2, 0x20, 0x27, 0x75,
  40326. 0x3f, 0x09, 0x16, 0xff, 0x1a, 0xcc, 0xa7, 0xc4, 0x6d, 0xc2,
  40327. 0xfc, 0xc3, 0x0b, 0x37, 0x63, 0xff, 0x9b, 0x10, 0xe6, 0x00,
  40328. 0xf7, 0x18, 0x43, 0x9f, 0x07, 0x50, 0x31, 0x51, 0xd4, 0xfd,
  40329. 0xad, 0xa2, 0x0f, 0x77, 0xda, 0x41, 0xc1, 0x0a, 0x6f, 0x86,
  40330. 0xd7, 0xdc, 0x8a, 0x52, 0xd6, 0xa1, 0x27, 0xdb, 0x14, 0x67,
  40331. 0x26, 0x91, 0xb3, 0xcd, 0x01, 0x5f, 0x60, 0xa1, 0x7f, 0x43,
  40332. 0x15, 0x1a, 0x82, 0x0f, 0xd3, 0x66, 0x5f, 0x60, 0x57, 0x2f,
  40333. 0xb2, 0x8c, 0x27, 0x2a, 0x9d, 0x1b, 0xf9, 0xf2, 0x59, 0x20,
  40334. 0x39, 0xd9, 0xc5, 0xaf, 0xf2, 0x36, 0x8c, 0x58, 0x00, 0x1b,
  40335. 0xd0, 0xc5, 0x8e, 0x1a, 0x49, 0xa8, 0x60, 0xbe, 0xd1, 0xd7,
  40336. 0x2a, 0xb0, 0xc2, 0xab, 0x58, 0x8a, 0x7a, 0xa9, 0x41, 0x68,
  40337. 0x70, 0xbd, 0xea, 0x73, 0xa5, 0x03, 0x11, 0xb2, 0x27, 0xd9,
  40338. 0xcd, 0xf5, 0x09, 0xe8, 0x1c, 0xe2, 0x4f, 0x50, 0x6a, 0x84,
  40339. 0x34, 0x62, 0x2e, 0x36, 0xaa, 0x4c, 0xc1, 0x83, 0x78, 0x98,
  40340. 0x35, 0x7a, 0x27, 0x7e, 0xfe, 0xf1, 0x6f, 0x59, 0x27, 0x35,
  40341. 0x73, 0xce, 0x74, 0xaa, 0xb4, 0x72, 0x82, 0xa8, 0xe2, 0x81,
  40342. 0x7a, 0x6b, 0xca, 0x33, 0xa5, 0xda, 0xa2, 0x63, 0xca, 0x2e,
  40343. 0x90, 0x03, 0x32, 0xec, 0x63, 0xdb, 0x52, 0x7b, 0x16, 0xfc,
  40344. 0x01, 0x2d, 0x30, 0x12, 0x1e, 0xf9, 0xa3, 0x72, 0x21, 0x3c,
  40345. 0x75, 0x0c, 0x61, 0x9c, 0x7e, 0x73, 0x04, 0x71, 0x41, 0x45,
  40346. 0x5d, 0x7f, 0x49, 0x1c, 0x09, 0x08, 0xa4, 0xec, 0x2f, 0xfd,
  40347. 0xc4, 0xfb, 0x59, 0x6a, 0x27, 0x7a, 0xd4, 0xfc, 0x5f, 0x20,
  40348. 0x04, 0x34, 0x7d, 0x08, 0xed, 0x82, 0x5a, 0x90, 0xe1, 0xab,
  40349. 0xfd, 0x35, 0x3a, 0x8d, 0xbb, 0x0a, 0x9d, 0x73, 0xff, 0x69,
  40350. 0xe5, 0xe9, 0x09, 0x55, 0x14, 0xd9, 0x7b, 0x6f, 0x0d, 0x99,
  40351. 0xd2, 0x7e, 0x71, 0xf8, 0x4f, 0x72, 0x2f, 0xbb, 0xc6, 0xc4,
  40352. 0x36, 0xc9, 0x01, 0xd3, 0x9b, 0x94, 0xab, 0x41, 0x0f, 0x4a,
  40353. 0x61, 0x5c, 0x68, 0xe5, 0xd7, 0x0d, 0x94, 0xaa, 0xee, 0xba,
  40354. 0x95, 0xcb, 0x8c, 0x0e, 0x85, 0x3a, 0x02, 0x6b, 0x95, 0x50,
  40355. 0xfd, 0x02, 0xfd, 0xa4, 0x58, 0x29, 0x78, 0x4f, 0xd0, 0xae,
  40356. 0x66, 0xd6, 0x5c, 0xe7, 0x45, 0xfe, 0x98, 0xb0, 0xa3, 0xe2,
  40357. 0x87, 0xc0, 0xd2, 0x81, 0x08, 0xf1, 0xf1, 0xe7, 0xda, 0x62,
  40358. 0x9e, 0xa0, 0x34, 0x86, 0xeb, 0xa1, 0x6e, 0x4a, 0x26, 0x8e,
  40359. 0x39, 0x0c, 0x51, 0x10, 0x33, 0x11, 0x87, 0xf8, 0x79, 0x3c,
  40360. 0x49, 0x7a, 0x8b, 0xce, 0xc1, 0x0a, 0x0e, 0xe1, 0xd5, 0x2a,
  40361. 0xac, 0xf0, 0x3a, 0x1d, 0x6a, 0x6a, 0xe5, 0xe1, 0x81, 0x70,
  40362. 0xad, 0xaf, 0x15, 0x4c, 0x2a, 0x70, 0x2a, 0x6b, 0x22, 0x0d,
  40363. 0x30, 0xe7, 0x56, 0xed, 0x2d, 0x4b, 0x85, 0x17, 0x49, 0x72,
  40364. 0x3a, 0x1b, 0x6f, 0x57, 0x1c, 0xf7, 0x72, 0x9e, 0x20, 0xdb,
  40365. 0x57, 0x1c, 0xfb, 0x36, 0x50, 0x52, 0xec, 0x5b, 0xd6, 0x6a,
  40366. 0x1b, 0xf8, 0x74, 0xad, 0xe6, 0x00, 0x74, 0x04, 0xc5, 0x99,
  40367. 0x83, 0xe4, 0x5a, 0x0c, 0xc3, 0xe8, 0x6d, 0x3a, 0xd7, 0x3c,
  40368. 0x3c, 0xc0, 0x1a, 0x28, 0xb3, 0x29, 0x7a, 0x10, 0x9e, 0x39,
  40369. 0x66, 0x5b, 0xc1, 0x38, 0xac, 0x21, 0x4e, 0xcd, 0x01, 0xf2,
  40370. 0xf6, 0x30, 0x2c, 0x2b, 0xb6, 0xbf, 0xf5, 0xea, 0x61, 0xaf,
  40371. 0x0c, 0xa6, 0x01, 0x11, 0x15, 0x19, 0x09, 0x8c, 0x7e, 0x69,
  40372. 0xdf, 0x3b, 0xea, 0xd3, 0x0a, 0x3a, 0xd7, 0xbd, 0xe1, 0x17,
  40373. 0xaf, 0x92, 0x3c, 0xf5, 0xfe, 0x35, 0xd6, 0xcf, 0x07, 0xa6,
  40374. 0xf7, 0xe9, 0xc1, 0x99, 0xed, 0x80, 0xe3, 0x12, 0xd5, 0x4b,
  40375. 0xb9, 0xdf, 0xaf, 0x4e, 0x52, 0xad, 0x8e, 0x66, 0x87, 0xe5,
  40376. 0x2c, 0xd0, 0x45, 0x70, 0xd9, 0x78, 0x8f, 0x4b, 0xf4, 0xe1,
  40377. 0xf1, 0x22, 0xf2, 0xe3, 0xed, 0x1f, 0xeb, 0xe9, 0x70, 0x31,
  40378. 0x4c, 0x65, 0x5f, 0x55, 0xee, 0x5d, 0xaa, 0x83, 0x87, 0x76,
  40379. 0xbe, 0x11, 0xae, 0xd7, 0xf2, 0xfb, 0x43, 0xe7, 0x17, 0x81,
  40380. 0x33, 0x15, 0x47, 0xa0, 0xf3, 0x8e, 0x84, 0x57, 0xff, 0x35,
  40381. 0x9e, 0x4a, 0x8a, 0xab, 0x50, 0x3a, 0x45, 0xe0, 0xc3, 0x73,
  40382. 0xca, 0x77, 0x61, 0x68, 0x38, 0xd0, 0xa3, 0x5f, 0x03, 0x8d,
  40383. 0x41, 0xc2, 0xd3, 0x4a, 0x17, 0xe0, 0xa8, 0xaa, 0x00, 0xf3,
  40384. 0xf2, 0x5b, 0xa8, 0xe1, 0x06, 0xa6, 0x2b, 0xdb, 0xe1, 0x74,
  40385. 0xbd, 0xc4, 0xd2, 0x2b, 0x55, 0x9a, 0xb0, 0xf8, 0x35, 0xd8,
  40386. 0x6b, 0xec, 0xdb, 0xc5, 0xf4, 0x6c, 0x40, 0x90, 0x6a, 0x68,
  40387. 0xc9, 0xb5, 0xcb, 0xbb, 0xd0, 0xb0, 0xbc, 0x9f, 0xb9, 0xaa,
  40388. 0x50, 0x14, 0x93, 0x3b, 0x9f, 0x25, 0xcb, 0x40, 0xb8, 0x08,
  40389. 0xcc, 0x13, 0xe5, 0xdc, 0x3f, 0x84, 0x96, 0xe0, 0x73, 0x7b,
  40390. 0x7d, 0x9e, 0x41, 0x92, 0x5d, 0xcc, 0xa4, 0xea, 0x4f, 0x93,
  40391. 0x0c, 0x40, 0x2e, 0x42, 0x8a, 0xe9, 0xb9, 0x12, 0x74, 0xbb,
  40392. 0x79, 0x7c, 0xb0, 0x37, 0x20, 0xb6, 0xaf, 0x43, 0x3a, 0x88,
  40393. 0x59, 0x7c, 0x68, 0x28, 0x5f, 0x98, 0xc2, 0xf0, 0x2a, 0xbc,
  40394. 0xa1, 0x61, 0x88, 0x1f, 0x43, 0xbc, 0x42, 0x8f, 0x43, 0xf3,
  40395. 0x7e, 0x16, 0x96, 0xfa, 0x92, 0x70, 0xaf, 0x3c, 0x9f, 0x4b,
  40396. 0xd9, 0x60, 0xe9, 0xf6, 0x2e, 0x84, 0xda, 0x88, 0x31, 0x34,
  40397. 0xa6, 0x85, 0x10, 0x05, 0xef, 0x40, 0xa8, 0xa5, 0x4f, 0x92,
  40398. 0x59, 0xf7, 0xe0, 0xc4, 0x2b, 0x12, 0x17, 0x71, 0xbe, 0x8c,
  40399. 0x4a, 0x02, 0xfe, 0x12, 0xb6, 0x3b, 0x85, 0x75, 0x37, 0xf3,
  40400. 0x73, 0x2d, 0x9c, 0x00, 0x5d, 0x80, 0xad, 0x20, 0x2f, 0x5a,
  40401. 0x0b, 0x17, 0x7e, 0x67, 0x72, 0x24, 0x5a, 0xb9, 0xf3, 0xb1,
  40402. 0x33, 0xa4, 0x57, 0x1d, 0x49, 0x72, 0x2c, 0x7f, 0x47, 0x15,
  40403. 0x07, 0xe0, 0x45, 0x14, 0xdd, 0x77, 0x86, 0x6d, 0x03, 0xbe,
  40404. 0x57, 0xd0, 0xaa, 0x18, 0xa6, 0xdd, 0x94, 0x18, 0x3f, 0x8a,
  40405. 0xf3, 0xb5, 0xd7, 0x5a, 0xec, 0xc8, 0x79, 0x7f, 0x51, 0x61,
  40406. 0x3c, 0x9b, 0xb2, 0x9b, 0xf3, 0xb4, 0x35, 0xd1, 0x38, 0xbf,
  40407. 0x37, 0xce, 0x54, 0xd1, 0xf8, 0xb6, 0x45, 0xeb, 0x52, 0x0d,
  40408. 0x9a, 0x09, 0x58, 0x0d, 0x2c, 0x0b, 0xb1, 0xf2, 0x30, 0x3a,
  40409. 0x95, 0xc1, 0x13, 0x91, 0xd2, 0x9f, 0x8d, 0x8d, 0xd0, 0x38,
  40410. 0x3e, 0x4c, 0xae, 0x4a, 0x55, 0xa7, 0x42, 0x11, 0x83, 0xc4,
  40411. 0x70, 0xf0, 0x2b, 0x68, 0x9e, 0x07, 0xad, 0xb7, 0x83, 0xc6,
  40412. 0x53, 0x3c, 0xfb, 0x0a, 0x5d, 0x24, 0xdc, 0xe1, 0x55, 0x72,
  40413. 0xcf, 0xce, 0x3e, 0xc8, 0xd0, 0x57, 0x8a, 0x82, 0x5e, 0x78,
  40414. 0x2b, 0x80, 0xc5, 0xb9, 0x09, 0x46, 0xf8, 0x90, 0x39, 0x52,
  40415. 0xa9, 0xce, 0x3f, 0x3d, 0x41, 0x3b, 0x28, 0x45, 0xa3, 0xb3,
  40416. 0x21, 0xc2, 0xcd, 0x14, 0x49, 0x41, 0x6c, 0x38, 0xda, 0x1b,
  40417. 0x5f, 0x16, 0x49, 0xf9, 0x65, 0x00, 0x4e, 0xb4, 0x20, 0x55,
  40418. 0x70, 0xe8, 0x58, 0x1a, 0x18, 0xbf, 0x41, 0xef, 0x31, 0xb1,
  40419. 0xe7, 0x8d, 0x89, 0xc1, 0x48, 0xe8, 0xf5, 0x57, 0x35, 0xfa,
  40420. 0xc1, 0x79, 0xee, 0x2c, 0xe8, 0x7d, 0xb6, 0x03, 0xcc, 0x66,
  40421. 0x09, 0x6f, 0x52, 0x84, 0x0a, 0x34, 0x18, 0x2c, 0x01, 0x45,
  40422. 0x81, 0x00, 0xe5, 0x5e, 0x8d, 0xae, 0x1c, 0x96, 0x8b, 0x45,
  40423. 0x73, 0x00, 0x0a, 0xb5, 0xcf, 0x8d, 0x0e, 0x35, 0x5d, 0x1a,
  40424. 0x0e, 0xbf, 0x64, 0x9a, 0x52, 0x20, 0x48, 0xc6, 0xb9, 0x40,
  40425. 0xd3, 0x2c, 0x52, 0xca, 0x93, 0xcf, 0xbb, 0x94, 0x06, 0xf3,
  40426. 0x97, 0xee, 0xcc, 0x5d, 0xa3, 0xea, 0xf8, 0x5a, 0x39, 0x77,
  40427. 0x34, 0xd7, 0xf6, 0x4e, 0xbe, 0x8a, 0x07, 0x5f, 0x51, 0x53,
  40428. 0xc5, 0x1b, 0x8c, 0x47, 0x8f, 0x34, 0x0e, 0x60, 0x0a, 0x90,
  40429. 0xe2, 0xda, 0x7b, 0xef, 0xd6, 0xf5, 0x5d, 0xe5, 0x32, 0x37,
  40430. 0x75, 0x99, 0x81, 0x4a, 0x2a, 0x78, 0x71, 0xdc, 0xf4, 0xe5,
  40431. 0xca, 0xd8, 0x6b, 0x3b, 0x90, 0x68, 0x2e, 0x93, 0xc5, 0x10,
  40432. 0x42, 0x5d, 0x38, 0x90, 0x32, 0x46, 0xea, 0x87, 0xe0, 0xbc,
  40433. 0xb8, 0x9a, 0x18, 0x20, 0x68, 0x85, 0x6d, 0x9b, 0xc9, 0x8f,
  40434. 0x9b, 0xd2, 0xbe, 0x15, 0x12, 0x68, 0xd0, 0xb0, 0x16, 0x5f,
  40435. 0xe2, 0x69, 0x1d, 0x04, 0x00, 0xfc, 0x63, 0x33, 0xcd, 0x1f,
  40436. 0x89, 0xcd, 0x52, 0xff, 0xec, 0x19, 0x69, 0x74, 0xa3, 0xce,
  40437. 0x4d, 0xab, 0x93, 0xe4, 0xc6, 0x13, 0x56, 0x27, 0xc9, 0x25,
  40438. 0x5a, 0x01, 0xb2, 0x36, 0x8b, 0x61, 0xe5, 0x8b, 0x98, 0xac,
  40439. 0xe4, 0x2a, 0xb6, 0x40, 0x9f, 0x42, 0xe4, 0x1b, 0x52, 0xf7,
  40440. 0xfd, 0xd8, 0x30, 0x07, 0x33, 0xf9, 0x47, 0xcb, 0x3c, 0xad,
  40441. 0x12, 0xc1, 0xcc, 0x29, 0x62, 0x49, 0x04, 0x0c, 0x23, 0x97,
  40442. 0x5a, 0xa4, 0x84, 0x67, 0xde, 0x5a, 0xe5, 0x36, 0xd2, 0x88,
  40443. 0xf1, 0xd4, 0xeb, 0x13, 0x81, 0x54, 0x51, 0x11, 0xe3, 0xba,
  40444. 0xbc, 0xee, 0xdd, 0x6c, 0xcd, 0xe6, 0xb4, 0xa1, 0x8b, 0x0b,
  40445. 0x66, 0xfb, 0x8e, 0x50, 0xa0, 0xda, 0x69, 0x8d, 0xcc, 0x2d,
  40446. 0xe4, 0x2c, 0xc4, 0x37, 0xdf, 0x61, 0xc0, 0x03, 0xbd, 0x8b,
  40447. 0x28, 0xca, 0xd2, 0x8c, 0x1c, 0xf1, 0xa4, 0x26, 0x69, 0xe5,
  40448. 0xcf, 0x45, 0xdb, 0x5a, 0x47, 0x79, 0xed, 0x9f, 0xf7, 0xd2,
  40449. 0xdb, 0xba, 0x46, 0x53, 0x4f, 0xce, 0xa8, 0xbe, 0x8f, 0x4a,
  40450. 0xd6, 0xdf, 0x2e, 0x06, 0xe6, 0x4c, 0x9a, 0xc1, 0xb6, 0x49,
  40451. 0xed, 0xc4, 0xeb, 0xaa, 0xa4, 0x29, 0x6d, 0xd4, 0xcc, 0x8c,
  40452. 0xb6, 0x40, 0x11, 0x39, 0x69, 0xf7, 0x75, 0xcd, 0xb1, 0x99,
  40453. 0x46, 0x4e, 0xde, 0xcb, 0xf6, 0x9d, 0x32, 0xf3, 0xc9, 0x47,
  40454. 0x47, 0x7a, 0xcb, 0xfb, 0xa3, 0x0c, 0x3b, 0xdf, 0xb7, 0xde,
  40455. 0xec, 0x99, 0xde, 0xb0, 0x26, 0x04, 0x34, 0xae, 0x6b, 0xfc,
  40456. 0x99, 0xbc, 0xde, 0xd5, 0xbe, 0xe7, 0xeb, 0xf9, 0xe7, 0xa6,
  40457. 0x01, 0x9a, 0x0c, 0x5e, 0x66, 0xe6, 0x53, 0xe4, 0xd1, 0x58,
  40458. 0xac, 0xda, 0x69, 0x77, 0x7b, 0x68, 0xd6, 0x30, 0x2a, 0x9c,
  40459. 0x6b, 0xbe, 0x9f, 0x3d, 0x71, 0xd6, 0x54, 0xcd, 0x59, 0x4e,
  40460. 0x1f, 0xe3, 0x83, 0x4e, 0xd1, 0x8e, 0xaf, 0x97, 0xa8, 0xe5,
  40461. 0xb6, 0x59, 0x77, 0xa8, 0x02, 0x20, 0xe4, 0xeb, 0x44, 0x71,
  40462. 0xbc, 0x07, 0x14, 0x79, 0x4f, 0x0c, 0x27, 0x06, 0x39, 0xcf,
  40463. 0x7c, 0xef, 0x2b, 0x9b, 0x5e, 0xc4, 0x6d, 0x79, 0x13, 0x00,
  40464. 0x43, 0x6f, 0x51, 0x77, 0xb5, 0xc3, 0x72, 0xad, 0x13, 0xa9,
  40465. 0xe5, 0x9a, 0x5b, 0x1a, 0x99, 0x74, 0xc0, 0x7a, 0xf9, 0xc5,
  40466. 0xb0, 0x58, 0x35, 0x1c, 0xa5, 0x51, 0xdb, 0xa1, 0x14, 0xcd,
  40467. 0x26, 0x71, 0xb1, 0xe7, 0xaa, 0x14, 0xa7, 0x46, 0x93, 0xd3,
  40468. 0x5c, 0x8c, 0x1a, 0x91, 0x77, 0x46, 0x2e, 0x15, 0xaa, 0x9e,
  40469. 0xf7, 0x2b, 0x79, 0x41, 0x76, 0xf7, 0x22, 0x53, 0x7d, 0x51,
  40470. 0xdb, 0x98, 0x3d, 0x5b, 0x78, 0x5f, 0xc3, 0xc9, 0x29, 0xa3,
  40471. 0xff, 0x75, 0x82, 0x06, 0x9a, 0x16, 0x5e, 0xa4, 0x79, 0x0d,
  40472. 0xd1, 0x6d, 0x08, 0xff, 0x43, 0xef, 0x9c, 0xf3, 0x1b, 0x7a,
  40473. 0x3f, 0x34, 0xbe, 0x19, 0x15, 0x06, 0x33, 0xdb, 0xa5, 0x71,
  40474. 0xcb, 0x5f, 0x6b, 0x8d, 0xbd, 0x5b, 0x32, 0x91, 0xb2, 0x37,
  40475. 0x3d, 0xb4, 0x40, 0x9e, 0x02, 0x9b, 0xb7, 0x68, 0x20, 0x58,
  40476. 0x5c, 0xab, 0xcb, 0xc8, 0x23, 0x2d, 0x77, 0xcc, 0x0b, 0xf6,
  40477. 0x78, 0x6b, 0x80, 0x06, 0x91, 0xa9, 0xfd, 0x7e, 0xfa, 0x25,
  40478. 0x98, 0x9f, 0xcc, 0x79, 0x0a, 0x1a, 0x54, 0x83, 0xac, 0x64,
  40479. 0x16, 0x90, 0xe5, 0xd9, 0xa7, 0xd7, 0x1b, 0x86, 0x0d, 0xe6,
  40480. 0xe6, 0x22, 0x2b, 0x1f, 0x44, 0x49, 0x98, 0x9c, 0x51, 0x6f,
  40481. 0xcf, 0x58, 0x4a, 0xfa, 0xfa, 0x84, 0x12, 0xa5, 0x10, 0xf4,
  40482. 0xca, 0xf0, 0x98, 0x2b, 0xc9, 0x03, 0x71, 0x37, 0xe7, 0xdc,
  40483. 0xc2, 0xb1, 0x4e, 0x64, 0xde, 0x4f, 0x46, 0x0d, 0x6b, 0x25,
  40484. 0x88, 0x5d, 0xd6, 0xff, 0x23, 0x46, 0x57, 0x36, 0x14, 0x18,
  40485. 0xa7, 0xcb, 0xb8, 0xbd, 0xf0, 0xc5, 0x37, 0x36, 0xee, 0xe1,
  40486. 0xed, 0x9f, 0x4d, 0xd4, 0x39, 0xe5, 0x92, 0xcf, 0x95, 0x4d,
  40487. 0x66, 0x36, 0x5d, 0xd0, 0xcc, 0x07, 0xcf, 0x15, 0x5a, 0xce,
  40488. 0x14, 0xb8, 0xda, 0x0d, 0x3d, 0x1b, 0x45, 0xc5, 0x2e, 0x34,
  40489. 0x43, 0x25, 0x02, 0x3a, 0xcd, 0x14, 0x45, 0xfb, 0x3e, 0xf9,
  40490. 0x88, 0x5d, 0x0d, 0x29, 0x31, 0xb9, 0xa1, 0xe6, 0x31, 0x18,
  40491. 0x52, 0x46, 0x3f, 0x22, 0x4f, 0x9f, 0x7a, 0x65, 0x36, 0x88,
  40492. 0xa3, 0x1c, 0x3e, 0x6f, 0x50, 0x7a, 0x36, 0xbe, 0x56, 0x7e,
  40493. 0x50, 0xcb, 0x7a, 0x10, 0xa0, 0xec, 0xf6, 0x82, 0xd6, 0x30,
  40494. 0x1c, 0xe8, 0x4c, 0x50, 0xf9, 0x3e, 0xdb, 0xac, 0xbe, 0x4f,
  40495. 0x90, 0xb1, 0xd5, 0x1b, 0x12, 0x95, 0xfb, 0xe8, 0x08, 0x64,
  40496. 0x56, 0x7c, 0x96, 0xcc, 0x90, 0xb1, 0xbc, 0xa0, 0xf5, 0x32,
  40497. 0x69, 0xb3, 0x5f, 0x27, 0x0f, 0xbe, 0xc9, 0xbd, 0xeb, 0xfa,
  40498. 0x4b, 0x5c, 0xc5, 0x99, 0x9e, 0x5a, 0x04, 0xcc, 0xd0, 0x4d,
  40499. 0x29, 0xe8, 0x84, 0x55, 0x8c, 0xd7, 0xc4, 0x06, 0x13, 0x4d,
  40500. 0x92, 0xe5, 0x98, 0x9c, 0x4c, 0xc1, 0xf7, 0xaf, 0x7b, 0xd5,
  40501. 0x2b, 0x92, 0x68, 0x68, 0x19, 0x70, 0x4c, 0x9e, 0x46, 0xb8,
  40502. 0x34, 0xeb, 0x01, 0x47, 0xbe, 0x59, 0xab, 0x0b, 0x22, 0x25,
  40503. 0xe7, 0x56, 0xa8, 0xb4, 0x93, 0x3c, 0xd5, 0x98, 0x9f, 0x61,
  40504. 0x2e, 0xfa, 0xcb, 0x5f, 0x5b, 0xd8, 0x09, 0x83, 0xe9, 0x40,
  40505. 0xe9, 0x0e, 0x42, 0xdd, 0x17, 0xd7, 0x6e, 0x19, 0x8d, 0x95,
  40506. 0x0a, 0x93
  40507. };
  40508. #endif
  40509. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_sig[] = {
  40510. 0x20, 0xff, 0x12, 0xe1, 0x87, 0xf6, 0x11, 0x38, 0xff, 0x41, 0xd0, 0x8f,
  40511. 0xcd, 0x7e, 0xd1, 0xf6, 0x21, 0x17, 0xd0, 0x46, 0xe9, 0x86, 0x83, 0x1b,
  40512. 0xaf, 0xe5, 0x2b, 0x59, 0x21, 0xd1, 0x6b, 0xc9, 0xdb, 0x34, 0xdc, 0xba,
  40513. 0xfd, 0xd3, 0xf8, 0x71, 0x49, 0xd8, 0x31, 0xbc, 0x48, 0x83, 0x22, 0x7b,
  40514. 0xfd, 0x6a, 0x93, 0xa6, 0x39, 0x4c, 0xda, 0xdb, 0x15, 0xe7, 0x41, 0x14,
  40515. 0xb4, 0xb8, 0xfe, 0xb0, 0x1f, 0xf9, 0x0a, 0x2c, 0x0b, 0xc0, 0xac, 0x09,
  40516. 0x84, 0x69, 0x5e, 0x64, 0x8c, 0xa8, 0xee, 0xa1, 0x52, 0x22, 0xde, 0x0d,
  40517. 0xc7, 0x25, 0xef, 0xa8, 0xfd, 0x8c, 0xb9, 0x45, 0x4f, 0xa4, 0x9c, 0xbc,
  40518. 0x70, 0xf2, 0x88, 0xea, 0x79, 0x13, 0xb0, 0xfc, 0xe6, 0x41, 0x48, 0x1c,
  40519. 0x33, 0x48, 0xa2, 0x77, 0x75, 0x37, 0x9f, 0xc1, 0x86, 0x94, 0xcd, 0x69,
  40520. 0x98, 0x87, 0x47, 0x49, 0x75, 0x93, 0xf1, 0xa4, 0x2d, 0x8e, 0xa8, 0x7e,
  40521. 0x0f, 0x95, 0xf5, 0x3e, 0x5d, 0x31, 0x2d, 0xc9, 0x58, 0x1c, 0x42, 0xfd,
  40522. 0x79, 0x6a, 0x49, 0xa3, 0x84, 0xc5, 0x2e, 0x8d, 0x96, 0x9c, 0xc8, 0x05,
  40523. 0x93, 0xdb, 0x6d, 0xbf, 0x83, 0x34, 0xc2, 0x81, 0x47, 0x90, 0xc9, 0xa9,
  40524. 0x82, 0xbd, 0xe1, 0xc8, 0x89, 0xa2, 0x36, 0x47, 0xed, 0xfb, 0x47, 0x57,
  40525. 0x01, 0x1a, 0x75, 0x8c, 0x6b, 0x83, 0xcf, 0x56, 0xae, 0x52, 0x66, 0x8b,
  40526. 0xab, 0x7f, 0x0c, 0xec, 0xde, 0x5c, 0x13, 0xbe, 0xbd, 0x5b, 0x74, 0x28,
  40527. 0xb5, 0xd7, 0x68, 0xd5, 0xd2, 0xe9, 0x96, 0x3b, 0x55, 0xda, 0x3a, 0x93,
  40528. 0x3c, 0xd9, 0x9f, 0x53, 0x2a, 0x31, 0x84, 0x45, 0x3f, 0xee, 0x2b, 0xfc,
  40529. 0x92, 0xb0, 0x9c, 0xc6, 0x16, 0x16, 0x4f, 0x33, 0x41, 0x17, 0x58, 0xbe,
  40530. 0x5d, 0x57, 0x4b, 0x04, 0x82, 0xe3, 0xb3, 0x68, 0xdf, 0x7c, 0x93, 0xce,
  40531. 0x9d, 0xf6, 0x7e, 0x21, 0x3d, 0x28, 0x1c, 0xf0, 0x37, 0x46, 0xf2, 0xc2,
  40532. 0x73, 0x7c, 0xbe, 0x98, 0x0e, 0x09, 0x75, 0xa7, 0x21, 0x11, 0xa9, 0xd6,
  40533. 0xd1, 0x47, 0xac, 0xd0, 0x19, 0x48, 0x3b, 0x74, 0xc1, 0x3c, 0x37, 0x43,
  40534. 0x49, 0x12, 0x62, 0xee, 0xaf, 0x5c, 0x38, 0xf7, 0x8a, 0xce, 0xb3, 0x7a,
  40535. 0x05, 0x16, 0xd4, 0x71, 0x8b, 0xbe, 0x1a, 0xe0, 0x1e, 0xbc, 0x4b, 0x54,
  40536. 0x0f, 0xb5, 0x73, 0x2b, 0xb8, 0x3a, 0x75, 0xf0, 0x26, 0xcd, 0xf9, 0xca,
  40537. 0x32, 0xf9, 0x7e, 0x15, 0x38, 0x75, 0x9c, 0x4d, 0xbc, 0x11, 0xf8, 0xea,
  40538. 0x8e, 0xe8, 0x38, 0x17, 0xc5, 0x62, 0xf4, 0x34, 0xfb, 0xd6, 0xf5, 0x76,
  40539. 0xfc, 0xa3, 0xf3, 0x44, 0xf9, 0xab, 0x2e, 0x9a, 0x68, 0xcd, 0xa1, 0x29,
  40540. 0xff, 0xda, 0xe8, 0xb5, 0xb0, 0x20, 0x5d, 0x02, 0x01, 0x62, 0x26, 0x44,
  40541. 0x32, 0xc8, 0x94, 0xf8, 0xf1, 0xaa, 0xf9, 0xc2, 0x86, 0xcb, 0x55, 0x7f,
  40542. 0x8d, 0xb3, 0xf6, 0x63, 0xb1, 0xa4, 0x95, 0x57, 0xb8, 0x1d, 0xc3, 0x42,
  40543. 0xd2, 0x4b, 0x69, 0xcd, 0x7a, 0x10, 0x5b, 0x6a, 0x13, 0xd1, 0x02, 0x98,
  40544. 0x38, 0x87, 0x9b, 0x9a, 0x5a, 0x66, 0x73, 0xcb, 0x75, 0xd0, 0x7a, 0x4b,
  40545. 0xad, 0x23, 0x06, 0x1c, 0xc8, 0x6b, 0x0c, 0xa8, 0xfe, 0x7b, 0x8f, 0x65,
  40546. 0x50, 0xd7, 0xf7, 0x76, 0x88, 0x42, 0xe0, 0x5e, 0x18, 0x91, 0x8b, 0x99,
  40547. 0x37, 0x56, 0x08, 0x91, 0xe7, 0x01, 0xe7, 0x05, 0xd5, 0xed, 0x43, 0x25,
  40548. 0x71, 0x7e, 0x3e, 0xfc, 0xc4, 0xfd, 0xed, 0x8b, 0x85, 0x16, 0x8c, 0xe3,
  40549. 0x05, 0xee, 0x51, 0x02, 0xa4, 0x4b, 0xd8, 0x3c, 0xcf, 0x4d, 0x2f, 0x2d,
  40550. 0x68, 0x6e, 0xc1, 0xd5, 0xfa, 0x91, 0xfd, 0x6a, 0xe0, 0x64, 0x85, 0x35,
  40551. 0x9c, 0x75, 0xe6, 0x0d, 0xb8, 0xec, 0x97, 0x88, 0x62, 0x98, 0x78, 0x75,
  40552. 0xc7, 0x1e, 0x68, 0xa7, 0xb9, 0x7b, 0xab, 0x75, 0x7a, 0x72, 0x3c, 0x7b,
  40553. 0xab, 0x60, 0x03, 0xb7, 0x38, 0x13, 0xe4, 0x96, 0x6e, 0xcb, 0x95, 0xcc,
  40554. 0xdc, 0x6a, 0x47, 0x67, 0x77, 0xd7, 0x95, 0xc4, 0x87, 0x66, 0xc2, 0x7e,
  40555. 0x42, 0x90, 0x59, 0x4f, 0xd6, 0xf3, 0xf4, 0xa7, 0xd0, 0x29, 0xf9, 0x5d,
  40556. 0x4b, 0x06, 0x06, 0xf7, 0x6e, 0xb2, 0xab, 0xb0, 0x8e, 0x21, 0xa6, 0xff,
  40557. 0x5e, 0x7b, 0x47, 0xb6, 0x3a, 0xa6, 0x9e, 0x19, 0xf6, 0xdf, 0x9b, 0x3b,
  40558. 0x3d, 0x07, 0x37, 0xd1, 0x0b, 0xa8, 0xf3, 0x9c, 0x43, 0x89, 0xee, 0xba,
  40559. 0x03, 0xee, 0x38, 0x74, 0x13, 0x09, 0x8e, 0x47, 0x4e, 0xa9, 0x14, 0xf5,
  40560. 0xb0, 0x55, 0xe0, 0x03, 0xe5, 0xb9, 0x53, 0xef, 0x03, 0x15, 0x60, 0xb3,
  40561. 0x4a, 0x71, 0x31, 0x4b, 0xf1, 0xc8, 0xe4, 0x63, 0x9b, 0x8b, 0x78, 0x3c,
  40562. 0x1f, 0xac, 0x27, 0x20, 0xa8, 0x53, 0x7d, 0xdd, 0x72, 0xd3, 0x90, 0x8f,
  40563. 0x71, 0xa6, 0xa7, 0xeb, 0xb0, 0xeb, 0x42, 0x96, 0xa4, 0xc3, 0xba, 0xc6,
  40564. 0x3c, 0xe7, 0x7b, 0x15, 0x1e, 0xfa, 0x15, 0x23, 0x37, 0xf3, 0xc8, 0xb2,
  40565. 0xf9, 0x46, 0x04, 0xd1, 0x5e, 0x44, 0xd7, 0x8f, 0x70, 0xb1, 0x0a, 0xde,
  40566. 0x6a, 0xe3, 0xaf, 0x9e, 0x49, 0x55, 0x78, 0x79, 0x11, 0x22, 0x87, 0xa9,
  40567. 0x54, 0x7c, 0xb4, 0x83, 0xe1, 0x25, 0xcd, 0x89, 0xa6, 0x91, 0x21, 0x7b,
  40568. 0xbe, 0x3d, 0x2f, 0x46, 0xb5, 0x5b, 0x50, 0x1a, 0xc8, 0x8d, 0x32, 0xf3,
  40569. 0x62, 0x1f, 0x24, 0x64, 0xe8, 0xb6, 0x02, 0x4f, 0x1f, 0x52, 0x3c, 0x40,
  40570. 0xfc, 0x72, 0x38, 0xd4, 0xba, 0x40, 0x8e, 0xb7, 0xc0, 0x97, 0x06, 0x16,
  40571. 0xd5, 0xe3, 0x39, 0x45, 0xd7, 0x7c, 0x0e, 0xed, 0x6b, 0x19, 0x19, 0x0a,
  40572. 0x8e, 0xcb, 0x2b, 0xee, 0x4d, 0xa1, 0x5e, 0x84, 0x22, 0x66, 0xcd, 0x4f,
  40573. 0xb9, 0x1a, 0x25, 0x85, 0x02, 0xc0, 0x67, 0xc4, 0xd5, 0x1a, 0xcb, 0xbb,
  40574. 0xde, 0x4d, 0x3c, 0x3c, 0x62, 0x9f, 0x76, 0x8f, 0x15, 0x29, 0xa5, 0xbb,
  40575. 0x5a, 0x48, 0x38, 0x66, 0xfa, 0x56, 0x0a, 0x09, 0xbd, 0xdf, 0xdf, 0x4a,
  40576. 0xe7, 0x0e, 0xa6, 0xb1, 0xb5, 0x7c, 0xe1, 0xed, 0x8d, 0x63, 0x07, 0x42,
  40577. 0xf3, 0xf8, 0x15, 0x28, 0x7c, 0x09, 0xf5, 0x02, 0x69, 0x1b, 0x88, 0x1e,
  40578. 0x3d, 0xad, 0x5f, 0x46, 0xed, 0xab, 0x2b, 0x11, 0x96, 0x73, 0xa8, 0xe8,
  40579. 0xe6, 0x64, 0x7d, 0xae, 0x13, 0xa1, 0x7d, 0x54, 0xae, 0xc0, 0x82, 0xeb,
  40580. 0x2a, 0xd1, 0x76, 0xb7, 0x9f, 0xbd, 0x33, 0x8f, 0xe7, 0xe6, 0x79, 0x92,
  40581. 0xa6, 0xaf, 0x61, 0x91, 0x49, 0xbc, 0xd2, 0x3c, 0x6f, 0x8b, 0xbe, 0x8f,
  40582. 0x5f, 0x1f, 0x00, 0x2c, 0x2e, 0x2c, 0xa0, 0x14, 0xcf, 0x34, 0x42, 0x44,
  40583. 0x41, 0x11, 0xd7, 0x37, 0xd3, 0x99, 0x44, 0x36, 0x43, 0x03, 0xb9, 0x50,
  40584. 0x4f, 0xab, 0xfe, 0x48, 0xe2, 0x4b, 0xed, 0x51, 0x8b, 0xe0, 0x04, 0x3c,
  40585. 0x93, 0x28, 0x55, 0xc8, 0x5a, 0xb3, 0x52, 0x2c, 0x56, 0xbd, 0x43, 0xb9,
  40586. 0x4a, 0x6c, 0x4c, 0xcc, 0xda, 0xba, 0x9c, 0xe6, 0x3e, 0x50, 0x8b, 0x1a,
  40587. 0xe5, 0x83, 0xc1, 0x60, 0x55, 0xb2, 0x02, 0x16, 0x54, 0x33, 0x62, 0x69,
  40588. 0x7c, 0x7d, 0x94, 0xf2, 0xb0, 0x3a, 0x22, 0xf0, 0x21, 0x46, 0xd7, 0x94,
  40589. 0x53, 0xec, 0x63, 0x4c, 0x3e, 0xc3, 0x71, 0xd1, 0xb9, 0x2e, 0x16, 0xe8,
  40590. 0x17, 0x63, 0x7e, 0x0c, 0x83, 0x05, 0x72, 0xe6, 0x20, 0x60, 0x34, 0xae,
  40591. 0x0e, 0x54, 0xa0, 0x57, 0x75, 0x93, 0x2e, 0xb8, 0x6c, 0xec, 0xda, 0x44,
  40592. 0x1b, 0xac, 0xd6, 0x75, 0xc5, 0x79, 0x3c, 0xc2, 0xa6, 0xa2, 0x7f, 0x3a,
  40593. 0xb0, 0xec, 0xeb, 0xc1, 0xe6, 0xd6, 0xae, 0xac, 0x2e, 0x55, 0x30, 0x1c,
  40594. 0x81, 0xa4, 0x4c, 0x35, 0x0e, 0xd8, 0xa6, 0x4e, 0xea, 0x0e, 0xbf, 0x79,
  40595. 0xf7, 0xdf, 0x55, 0xfc, 0xf9, 0x24, 0xb0, 0xa6, 0xba, 0xc3, 0x72, 0x42,
  40596. 0x60, 0x06, 0x44, 0x03, 0xe3, 0x40, 0x3c, 0x2a, 0x13, 0xf7, 0xdf, 0x3d,
  40597. 0xb7, 0x0d, 0x86, 0x6c, 0xb0, 0x0f, 0x2e, 0x72, 0x91, 0x16, 0x4f, 0x5f,
  40598. 0xd0, 0x3e, 0x8c, 0x36, 0xed, 0xa8, 0x6f, 0xbc, 0x65, 0xb0, 0x65, 0x99,
  40599. 0x47, 0x50, 0xa5, 0x9c, 0xea, 0xee, 0x8a, 0x44, 0x70, 0xf5, 0x31, 0x1a,
  40600. 0xe9, 0x11, 0xc1, 0xce, 0xe0, 0x21, 0x52, 0x70, 0x89, 0xf7, 0xc3, 0x35,
  40601. 0xfa, 0x55, 0x5a, 0xc5, 0x10, 0x02, 0xc4, 0xc7, 0xf7, 0xe1, 0xaf, 0x49,
  40602. 0x48, 0x61, 0xe7, 0x0d, 0xa1, 0x2d, 0x7d, 0x03, 0x00, 0x38, 0xa7, 0xd5,
  40603. 0xd3, 0xbf, 0x95, 0x29, 0xed, 0xcc, 0x70, 0x3e, 0xbe, 0x95, 0x8a, 0xdf,
  40604. 0xaf, 0xbf, 0xec, 0xf8, 0x6a, 0x4f, 0x9e, 0x69, 0xee, 0x4e, 0x3d, 0x8b,
  40605. 0x58, 0xa0, 0x2e, 0xb5, 0x83, 0x6a, 0x0e, 0x04, 0xa4, 0xa9, 0x74, 0xcb,
  40606. 0x4f, 0xb0, 0x39, 0x37, 0x8f, 0xcf, 0xbf, 0x77, 0xe4, 0x1a, 0x74, 0xcf,
  40607. 0x0e, 0x0d, 0x2d, 0x6e, 0x1d, 0xba, 0xc1, 0xf5, 0x7c, 0x54, 0x6e, 0x92,
  40608. 0xec, 0x4b, 0x03, 0xc3, 0xa4, 0x44, 0xad, 0x3e, 0x4f, 0xa4, 0xd9, 0xe9,
  40609. 0x71, 0x3c, 0xe6, 0xb6, 0xbe, 0xe7, 0xfc, 0x72, 0x76, 0x86, 0x9a, 0x73,
  40610. 0xb1, 0xb3, 0xf3, 0x84, 0xb6, 0x2a, 0x40, 0x0b, 0x8c, 0xae, 0xb3, 0xc4,
  40611. 0xdc, 0xb5, 0x21, 0x85, 0x87, 0xdc, 0x19, 0x18, 0xd5, 0xba, 0xa4, 0x5e,
  40612. 0x88, 0x89, 0xa4, 0xf4, 0x88, 0x75, 0xc2, 0x7a, 0xb4, 0xee, 0x9d, 0x54,
  40613. 0x66, 0x97, 0x70, 0x08, 0x8f, 0x99, 0x84, 0x5d, 0x5e, 0xa7, 0x6f, 0x92,
  40614. 0xe8, 0xa3, 0x65, 0xfa, 0x0e, 0x87, 0xfb, 0x3c, 0xe9, 0x17, 0x2d, 0xc7,
  40615. 0x2d, 0x30, 0x8f, 0x41, 0x82, 0x68, 0x2b, 0xf1, 0x67, 0x8e, 0xf7, 0x05,
  40616. 0x78, 0xfa, 0xc3, 0x61, 0xba, 0x35, 0xe7, 0x2f, 0x19, 0xef, 0x71, 0x36,
  40617. 0xac, 0x5b, 0xf0, 0x45, 0x30, 0x70, 0xdc, 0xc7, 0xab, 0x7b, 0x62, 0x17,
  40618. 0x9d, 0xc4, 0x43, 0x6f, 0xfc, 0x02, 0x56, 0x5f, 0x65, 0xaa, 0x68, 0x3b,
  40619. 0x5c, 0xfa, 0x71, 0x28, 0x89, 0xe9, 0x28, 0x2f, 0x95, 0x4b, 0xfc, 0xe6,
  40620. 0xe7, 0xc8, 0x44, 0x28, 0x5c, 0x3c, 0x08, 0x5f, 0x9c, 0xbc, 0x41, 0x68,
  40621. 0x91, 0x98, 0x7a, 0x00, 0x63, 0xc9, 0x5c, 0x75, 0x8f, 0xcc, 0x33, 0x77,
  40622. 0x7b, 0xd0, 0x2d, 0xe8, 0xa2, 0x98, 0xa4, 0x1b, 0xfa, 0x09, 0x67, 0x7b,
  40623. 0x25, 0x96, 0x19, 0xf4, 0x77, 0x33, 0x20, 0x4f, 0x19, 0xf6, 0x9c, 0x6c,
  40624. 0x2e, 0xd9, 0x68, 0x95, 0xb0, 0xe2, 0x18, 0x06, 0xe5, 0x84, 0x8e, 0xf7,
  40625. 0xbf, 0x6c, 0x96, 0xa8, 0x9d, 0x37, 0xc7, 0x28, 0xa1, 0x3d, 0x90, 0x8c,
  40626. 0x40, 0x3d, 0xe2, 0x51, 0xfd, 0x55, 0x09, 0xf8, 0x83, 0x43, 0x44, 0x4d,
  40627. 0x1c, 0x8a, 0x8d, 0x36, 0x84, 0x64, 0xc4, 0xfa, 0x1d, 0x72, 0x04, 0x0b,
  40628. 0x1d, 0x49, 0x13, 0x88, 0x78, 0x5f, 0x07, 0x9b, 0xc8, 0x01, 0x9c, 0x3c,
  40629. 0xfc, 0xff, 0x0f, 0xd5, 0x13, 0xcd, 0x15, 0x98, 0xcc, 0xe6, 0x59, 0x1e,
  40630. 0x83, 0x38, 0x8f, 0x6c, 0x75, 0xbe, 0xdf, 0xe9, 0x1b, 0xc5, 0xb9, 0x6b,
  40631. 0xa4, 0x5a, 0x0c, 0xae, 0x98, 0x8d, 0x93, 0xfa, 0x76, 0x7f, 0x0d, 0x0b,
  40632. 0xe8, 0xa0, 0x3b, 0x9e, 0x5e, 0xc8, 0xa8, 0xcc, 0x02, 0xc9, 0x86, 0x9c,
  40633. 0x78, 0xaf, 0x6e, 0x6a, 0xf4, 0xfe, 0x49, 0xad, 0xc5, 0x93, 0xae, 0x62,
  40634. 0xbd, 0xe3, 0x3a, 0xa8, 0xf2, 0x60, 0xb5, 0x29, 0xde, 0x5f, 0x12, 0x02,
  40635. 0x2d, 0x43, 0x90, 0xf5, 0x9d, 0x9d, 0x97, 0x29, 0xfa, 0xdd, 0x60, 0x41,
  40636. 0x64, 0xb7, 0xa5, 0x03, 0x72, 0x10, 0x2b, 0xdd, 0x5b, 0x60, 0xe6, 0xf0,
  40637. 0xe1, 0xd7, 0xa5, 0x97, 0xec, 0xb4, 0x9a, 0x4c, 0x3e, 0x16, 0xa2, 0x82,
  40638. 0xb3, 0xc3, 0x3f, 0x3e, 0x5d, 0x32, 0xac, 0x5a, 0x40, 0xb4, 0x00, 0xfa,
  40639. 0xd9, 0x47, 0xe8, 0x77, 0xa8, 0x96, 0x5c, 0x60, 0x04, 0x9c, 0x5c, 0xdf,
  40640. 0x24, 0x3b, 0xa7, 0x4a, 0x58, 0x25, 0x12, 0x9a, 0xa8, 0x7b, 0x3e, 0x14,
  40641. 0xc8, 0x06, 0x79, 0x23, 0xea, 0x91, 0x7f, 0xe1, 0x78, 0x41, 0x6c, 0xdb,
  40642. 0x8c, 0xeb, 0x66, 0x35, 0x87, 0x87, 0x81, 0x65, 0x2c, 0xef, 0x3a, 0x6e,
  40643. 0xae, 0xb3, 0x6c, 0xe9, 0x86, 0x50, 0x6d, 0x89, 0xd6, 0x27, 0x0a, 0xdb,
  40644. 0xf8, 0xd4, 0xb8, 0x85, 0x8e, 0x37, 0xa6, 0x56, 0xf7, 0x58, 0x18, 0x4c,
  40645. 0x44, 0xcf, 0xeb, 0xc4, 0x79, 0x19, 0xfc, 0x2e, 0x53, 0x18, 0x0e, 0x7b,
  40646. 0x51, 0x86, 0xf3, 0x59, 0x13, 0xb2, 0xaf, 0xd3, 0xee, 0xf4, 0xd5, 0xbf,
  40647. 0x2c, 0xb8, 0x6d, 0x71, 0x74, 0x7c, 0x67, 0x54, 0xa7, 0x4b, 0x03, 0xa9,
  40648. 0x1b, 0x62, 0x95, 0x9f, 0xc3, 0xf0, 0x71, 0x39, 0x2d, 0x26, 0xaf, 0xaf,
  40649. 0xa7, 0xa5, 0x58, 0xf8, 0xf8, 0x8a, 0xe0, 0x62, 0x90, 0x3f, 0x72, 0x9d,
  40650. 0x21, 0x82, 0x76, 0x3e, 0x4c, 0x5d, 0xe0, 0xb5, 0x67, 0x23, 0xe3, 0x13,
  40651. 0x1a, 0x29, 0xa3, 0xda, 0xa4, 0xb4, 0x5c, 0x1d, 0x47, 0xdf, 0xdf, 0xc9,
  40652. 0x93, 0x6c, 0xb2, 0xb5, 0x22, 0xb3, 0x47, 0x2b, 0xcf, 0xf0, 0x36, 0x87,
  40653. 0x51, 0x3c, 0x79, 0x41, 0x70, 0xbd, 0xea, 0x70, 0xa2, 0x29, 0x90, 0x55,
  40654. 0x30, 0x6f, 0x3e, 0x50, 0xc8, 0x38, 0xd6, 0xfa, 0x6f, 0xe3, 0x39, 0x67,
  40655. 0x88, 0x52, 0x1f, 0xd3, 0x52, 0xbf, 0x3e, 0x7b, 0x2a, 0xe5, 0x1e, 0xcd,
  40656. 0xf9, 0xf1, 0x91, 0x1d, 0x04, 0x61, 0x25, 0xbb, 0xe1, 0x33, 0xe3, 0x66,
  40657. 0x46, 0xed, 0x06, 0x8d, 0xc3, 0x4f, 0x20, 0xc6, 0x24, 0xa7, 0xb5, 0x49,
  40658. 0x3b, 0xc7, 0xe6, 0xa0, 0x77, 0x58, 0xd9, 0x70, 0xb1, 0xf5, 0xec, 0x94,
  40659. 0x19, 0xf3, 0x5b, 0x0f, 0x9a, 0xe4, 0xad, 0x37, 0x81, 0xaf, 0x68, 0x7b,
  40660. 0xe5, 0x67, 0xb5, 0xae, 0x7f, 0x2d, 0x64, 0x78, 0x68, 0x5a, 0xd1, 0x8f,
  40661. 0x1c, 0xc0, 0xc3, 0x5b, 0x21, 0x77, 0xe4, 0xa8, 0x5d, 0x05, 0x50, 0xc1,
  40662. 0x92, 0xee, 0x36, 0x2d, 0xd2, 0xff, 0xee, 0xc2, 0x11, 0x99, 0xee, 0xd7,
  40663. 0x48, 0xfb, 0x6a, 0xa3, 0xc9, 0xb7, 0x0c, 0xc1, 0xe5, 0x12, 0xbf, 0x6f,
  40664. 0x58, 0x66, 0x35, 0x34, 0x26, 0xaa, 0xbe, 0xc3, 0x33, 0x86, 0xfd, 0xc0,
  40665. 0x1c, 0xa5, 0xe4, 0x1e, 0x91, 0xc4, 0x55, 0x4e, 0xf1, 0xcb, 0xd2, 0x0b,
  40666. 0xe8, 0x0d, 0x89, 0x6a, 0x00, 0xbd, 0x7b, 0xf5, 0x3d, 0x1a, 0x4a, 0x48,
  40667. 0xfc, 0xf0, 0x5b, 0xcd, 0xdb, 0xb2, 0xa0, 0x27, 0x4b, 0x8f, 0xf7, 0x87,
  40668. 0x78, 0x13, 0xdb, 0x3f, 0xfb, 0x0b, 0xda, 0x22, 0xb3, 0x2b, 0x3a, 0x38,
  40669. 0xd2, 0x29, 0x73, 0x77, 0xb8, 0xd6, 0xec, 0xab, 0xb4, 0xfe, 0xbe, 0xbb,
  40670. 0x6e, 0xe2, 0xc8, 0x45, 0x7b, 0x0d, 0x36, 0x28, 0x0f, 0x45, 0x72, 0xea,
  40671. 0x6d, 0x38, 0x02, 0x5e, 0x48, 0x89, 0x12, 0x24, 0x1b, 0x33, 0x0f, 0xe9,
  40672. 0xf4, 0xce, 0xf8, 0x27, 0x16, 0x37, 0x29, 0xae, 0xe8, 0x22, 0x03, 0x31,
  40673. 0xa9, 0xa0, 0x73, 0x0c, 0x40, 0xe4, 0xfc, 0x6b, 0xe2, 0x1c, 0x8d, 0x7c,
  40674. 0x40, 0x82, 0x72, 0x28, 0xd0, 0x7d, 0xe5, 0xef, 0x05, 0x14, 0x80, 0x28,
  40675. 0x11, 0x32, 0x0d, 0x63, 0x8a, 0xc3, 0x7c, 0xfe, 0xf5, 0x06, 0x0e, 0xb0,
  40676. 0x78, 0x5c, 0x3a, 0xb6, 0x54, 0x37, 0x46, 0xa7, 0x43, 0x4f, 0x05, 0xec,
  40677. 0xe4, 0x9f, 0xd8, 0x55, 0x1f, 0x70, 0xb3, 0xe6, 0xbc, 0x46, 0x34, 0x9e,
  40678. 0xfc, 0xa4, 0x57, 0x8f, 0x0f, 0x25, 0x6f, 0x9f, 0xb3, 0x80, 0x21, 0x0b,
  40679. 0xa1, 0xca, 0x59, 0xcd, 0x37, 0xf7, 0xc9, 0xcb, 0xbe, 0x91, 0xad, 0x07,
  40680. 0x4f, 0xc7, 0x4e, 0x04, 0xbd, 0x38, 0x8b, 0x63, 0xb5, 0x51, 0xac, 0xc8,
  40681. 0x83, 0x3a, 0xa7, 0xe1, 0x77, 0xbc, 0xa4, 0x0c, 0x6c, 0x50, 0xeb, 0x46,
  40682. 0xe1, 0x45, 0x9a, 0x7b, 0x01, 0xca, 0x54, 0xf0, 0x0f, 0xa0, 0x1f, 0x43,
  40683. 0x9a, 0x19, 0x70, 0x2e, 0x70, 0x5a, 0xcf, 0x3b, 0x1b, 0x41, 0xfd, 0xd3,
  40684. 0x9a, 0xa2, 0x36, 0x14, 0xf0, 0xdd, 0xb0, 0x12, 0x6d, 0xcf, 0x55, 0x3f,
  40685. 0xef, 0x0a, 0xc1, 0x80, 0xa9, 0x68, 0xc3, 0x98, 0x03, 0x46, 0x34, 0xce,
  40686. 0x91, 0xb2, 0x7a, 0x94, 0xd2, 0xe7, 0xb9, 0x9c, 0x56, 0xb8, 0xf8, 0xd6,
  40687. 0xff, 0xbf, 0x8b, 0x39, 0x45, 0x04, 0x45, 0xc9, 0xa2, 0xe2, 0xbb, 0x50,
  40688. 0x68, 0x13, 0x32, 0x1e, 0x09, 0x51, 0xb7, 0xb9, 0xcf, 0x5f, 0xcc, 0x54,
  40689. 0xd2, 0xf3, 0xc1, 0x9d, 0xa0, 0x8d, 0x22, 0xc8, 0x7e, 0x1b, 0xc6, 0x14,
  40690. 0xde, 0x5f, 0x52, 0xb4, 0x69, 0x71, 0xca, 0x58, 0x1d, 0x1e, 0x89, 0xcb,
  40691. 0x56, 0x78, 0x7a, 0x85, 0xee, 0xfd, 0xf6, 0x7e, 0xbe, 0x49, 0x9b, 0xb1,
  40692. 0x05, 0x95, 0x12, 0xe9, 0x63, 0xbd, 0x61, 0x9a, 0x26, 0xf9, 0x0b, 0x9f,
  40693. 0x23, 0x0a, 0x59, 0x55, 0x93, 0xd3, 0x2d, 0xca, 0x66, 0x45, 0x03, 0xb7,
  40694. 0xf0, 0x88, 0x9e, 0xc1, 0x11, 0xbb, 0x62, 0x2c, 0x6f, 0xac, 0x3e, 0x87,
  40695. 0xd7, 0xe6, 0x4a, 0x44, 0x83, 0x04, 0x5d, 0x5d, 0xbc, 0x3c, 0xce, 0x83,
  40696. 0x2b, 0x11, 0x42, 0x02, 0x73, 0x1c, 0x24, 0x90, 0xd9, 0x1a, 0x7d, 0x96,
  40697. 0x82, 0x33, 0x75, 0x1e, 0x59, 0xea, 0xa7, 0x99, 0xe1, 0x5b, 0xdc, 0xe4,
  40698. 0x07, 0xc5, 0x48, 0x07, 0xb4, 0xbc, 0x80, 0x0e, 0xbd, 0x63, 0x6e, 0x66,
  40699. 0xf1, 0x12, 0xb6, 0x67, 0xe0, 0x14, 0x74, 0x9f, 0xbb, 0xb3, 0xb8, 0x16,
  40700. 0xd0, 0x25, 0xe9, 0x21, 0x80, 0x1a, 0x32, 0xb0, 0x58, 0x9a, 0x62, 0x17,
  40701. 0x18, 0x9d, 0x64, 0x2d, 0x47, 0x89, 0x82, 0x3b, 0x8c, 0x5d, 0x60, 0xc4,
  40702. 0x54, 0x69, 0xaa, 0xb4, 0x6a, 0x1d, 0x16, 0xb0, 0xe2, 0x5d, 0x7d, 0xeb,
  40703. 0xb9, 0x80, 0x37, 0xcd, 0x5b, 0xf0, 0xa1, 0xa8, 0x39, 0xb2, 0xd6, 0x3a,
  40704. 0xc8, 0xcd, 0xca, 0xaf, 0xcb, 0x3b, 0x54, 0xc2, 0x67, 0x49, 0xf3, 0xf1,
  40705. 0x11, 0x4d, 0x53, 0x7c, 0x46, 0x8d, 0x22, 0xf6, 0x9a, 0x0d, 0x9e, 0xda,
  40706. 0x37, 0xc6, 0x06, 0x00, 0xca, 0xb6, 0xb6, 0x99, 0xc5, 0xb6, 0x81, 0x7e,
  40707. 0x87, 0x62, 0xcf, 0x07, 0x76, 0xc1, 0x5f, 0xfe, 0x86, 0xfc, 0x5b, 0xa0,
  40708. 0xac, 0xca, 0xcb, 0x7d, 0xf5, 0x5a, 0xc2, 0x5e, 0x41, 0x48, 0x35, 0xc4,
  40709. 0x71, 0x9d, 0xc4, 0x0a, 0x79, 0x6f, 0xe3, 0x6d, 0x47, 0xd4, 0xaa, 0xfd,
  40710. 0x97, 0xe7, 0xb0, 0x7e, 0x61, 0xf1, 0x7d, 0x7e, 0xf8, 0x78, 0x4c, 0x2e,
  40711. 0x65, 0x51, 0xeb, 0x99, 0xd0, 0x3e, 0x24, 0x4c, 0xe0, 0x40, 0x7e, 0x2d,
  40712. 0xf7, 0x00, 0x9d, 0x50, 0x87, 0xce, 0x1f, 0x9a, 0xd2, 0x76, 0x00, 0x09,
  40713. 0xeb, 0x10, 0x1b, 0x4c, 0xf1, 0x43, 0x0e, 0x35, 0xbb, 0x23, 0x2e, 0x26,
  40714. 0x3d, 0x66, 0xa3, 0x0f, 0xf6, 0x10, 0x8b, 0x67, 0xce, 0x66, 0xfd, 0xb5,
  40715. 0x07, 0xdc, 0x04, 0x69, 0xad, 0xe0, 0x4d, 0xdf, 0xdb, 0x2f, 0x87, 0xf7,
  40716. 0xde, 0xc3, 0x77, 0x89, 0x71, 0xfd, 0x70, 0x38, 0xed, 0xe6, 0x27, 0xb1,
  40717. 0xbd, 0x94, 0x5f, 0x39, 0x20, 0x72, 0x59, 0xc4, 0x39, 0xd0, 0x20, 0x5d,
  40718. 0xe2, 0xe7, 0xe0, 0x00, 0x61, 0xc7, 0x65, 0xbd, 0xef, 0x05, 0xb3, 0xc7,
  40719. 0x7e, 0xae, 0xc5, 0x83, 0x7f, 0xc1, 0x32, 0x4e, 0x2a, 0x17, 0x64, 0x4e,
  40720. 0x2a, 0x9a, 0x2d, 0x26, 0x99, 0xa2, 0xd7, 0x37, 0x3a, 0x10, 0x6a, 0x89,
  40721. 0x72, 0x43, 0x0e, 0x3a, 0x03, 0x4c, 0xf9, 0xfe, 0xe8, 0xfc, 0x87, 0x71,
  40722. 0x37, 0x71, 0x5a, 0x05, 0xbc, 0x4e, 0x20, 0x4c, 0xd7, 0xf9, 0x8d, 0x4e,
  40723. 0xb8, 0xb8, 0x56, 0x07, 0xc8, 0x6e, 0x34, 0x6d, 0x45, 0x83, 0x34, 0xf0,
  40724. 0x77, 0xfb, 0x18, 0xec, 0x72, 0xf6, 0x4c, 0xfb, 0xba, 0x84, 0xe9, 0x89,
  40725. 0x3d, 0xfd, 0xb7, 0x0d, 0x70, 0xae, 0xa4, 0x48, 0x6b, 0x39, 0xf8, 0x62,
  40726. 0xc0, 0x7f, 0x0c, 0xf2, 0xa3, 0xfa, 0x7a, 0x64, 0x83, 0x57, 0x7d, 0x4c,
  40727. 0x04, 0x96, 0xd7, 0x9d, 0x10, 0x8b, 0x34, 0x48, 0x17, 0xff, 0x74, 0x5c,
  40728. 0x9c, 0xbe, 0xeb, 0xe5, 0x52, 0x94, 0x6a, 0x34, 0x6f, 0xf7, 0x95, 0x32,
  40729. 0x38, 0x5a, 0x9b, 0x08, 0xf6, 0xda, 0x8c, 0x0f, 0x9c, 0x5d, 0x04, 0x45,
  40730. 0xd4, 0xe9, 0xa4, 0x7a, 0xc4, 0xfd, 0x70, 0xfe, 0xa1, 0x3d, 0x21, 0xa0,
  40731. 0x01, 0xe5, 0x21, 0xca, 0xa7, 0xd9, 0xf1, 0x9f, 0x45, 0xe1, 0xe8, 0x2d,
  40732. 0x27, 0xe6, 0x87, 0xc8, 0x0d, 0xad, 0x13, 0xdb, 0xfe, 0x2f, 0xaa, 0x2b,
  40733. 0xdc, 0xa6, 0x1a, 0xc9, 0x19, 0x78, 0x1a, 0x1f, 0x10, 0xcf, 0x31, 0xe1,
  40734. 0x06, 0x28, 0x66, 0xb3, 0xa7, 0xa2, 0xa6, 0xf1, 0x3b, 0x2d, 0xd3, 0x81,
  40735. 0xaf, 0x6f, 0xc9, 0x88, 0x76, 0xe9, 0x83, 0x6c, 0x52, 0xb9, 0x70, 0x51,
  40736. 0x87, 0x6b, 0x8b, 0xbd, 0x5b, 0x9c, 0xa9, 0xf3, 0xcb, 0x55, 0xd1, 0x76,
  40737. 0x40, 0xe1, 0x90, 0xb9, 0x4c, 0xbd, 0xab, 0x1d, 0xa0, 0x5b, 0x5b, 0x34,
  40738. 0x14, 0x2f, 0x87, 0x8f, 0x63, 0xa0, 0x2d, 0x29, 0x4e, 0x50, 0x4b, 0x18,
  40739. 0x5f, 0x86, 0xac, 0x1b, 0x93, 0xe9, 0x59, 0x38, 0xa1, 0x2a, 0x36, 0x21,
  40740. 0xb2, 0xa4, 0xc0, 0x79, 0xc1, 0x60, 0xfc, 0x0f, 0xbf, 0x99, 0x04, 0x9d,
  40741. 0x4b, 0x17, 0x60, 0x5b, 0xcd, 0x78, 0x03, 0xd7, 0x7c, 0x4b, 0x9b, 0x17,
  40742. 0x58, 0x24, 0x60, 0xb8, 0x08, 0x92, 0x48, 0x4f, 0x66, 0x42, 0x9a, 0x98,
  40743. 0x2a, 0x99, 0x9a, 0x8f, 0xdd, 0xd7, 0x09, 0xf3, 0x22, 0x66, 0x62, 0xef,
  40744. 0xe5, 0x64, 0xd3, 0xdf, 0x31, 0xaa, 0x84, 0x4c, 0xa5, 0x3f, 0x4e, 0x27,
  40745. 0x48, 0x37, 0x96, 0x63, 0xbf, 0x8d, 0xe1, 0xf0, 0xd1, 0xef, 0x95, 0x1a,
  40746. 0xe6, 0xf4, 0x02, 0x61, 0xbf, 0xe3, 0xbc, 0x8b, 0x3d, 0x0b, 0x77, 0x91,
  40747. 0xc0, 0x5d, 0xfb, 0xe6, 0x7e, 0xab, 0x5e, 0xc5, 0x1c, 0x5b, 0x16, 0xfd,
  40748. 0x88, 0xa4, 0x78, 0x4c, 0x06, 0x77, 0xc3, 0x6e, 0x84, 0x0c, 0xda, 0xbf,
  40749. 0xf3, 0x8e, 0xd3, 0x61, 0x65, 0xac, 0xf2, 0x18, 0x70, 0x68, 0x84, 0x6f,
  40750. 0x9f, 0x3a, 0x94, 0x81, 0xa6, 0xc7, 0xc3, 0x92, 0xee, 0x4b, 0x20, 0x15,
  40751. 0x4e, 0x03, 0x76, 0x51, 0x5b, 0x4e, 0xe1, 0x5c, 0x51, 0x5e, 0x1b, 0x9c,
  40752. 0x30, 0x25, 0x79, 0xdd, 0x70, 0x12, 0xec, 0xdc, 0x45, 0x95, 0x45, 0x43,
  40753. 0xcd, 0xbb, 0xae, 0xa0, 0x0d, 0x43, 0xb4, 0xc9, 0x8c, 0x62, 0xfd, 0x7b,
  40754. 0xed, 0x50, 0x78, 0xb7, 0xa6, 0x94, 0xcb, 0x98, 0xb0, 0xbe, 0x09, 0xd9,
  40755. 0x0c, 0xb2, 0xc4, 0x8b, 0x96, 0x93, 0xd9, 0x26, 0xc6, 0x6d, 0x26, 0x93,
  40756. 0x32, 0x4e, 0x86, 0x72, 0x74, 0x92, 0x00, 0x72, 0x0b, 0x20, 0xa3, 0x2b,
  40757. 0x94, 0xe6, 0x10, 0x56, 0x5a, 0x41, 0x71, 0x92, 0x08, 0xce, 0x6c, 0xc4,
  40758. 0x1d, 0x9e, 0x71, 0x82, 0x64, 0x23, 0xe5, 0x15, 0xef, 0x4a, 0x7c, 0x4d,
  40759. 0xe3, 0x92, 0xbc, 0xa3, 0xa2, 0x29, 0xb7, 0x46, 0xfa, 0x8f, 0x9f, 0xc2,
  40760. 0x5d, 0xe4, 0xc0, 0x9c, 0x3f, 0x40, 0x17, 0xae, 0x44, 0xf3, 0x28, 0x10,
  40761. 0x29, 0x24, 0xa9, 0x1c, 0x9e, 0xd2, 0x55, 0x4c, 0xee, 0x45, 0xfe, 0x4a,
  40762. 0x45, 0x12, 0xf5, 0xde, 0xc7, 0x64, 0x15, 0xc3, 0x4a, 0x77, 0x63, 0x05,
  40763. 0x8d, 0xa6, 0x31, 0xa0, 0xad, 0x64, 0xaf, 0x3c, 0x69, 0x2c, 0x25, 0x78,
  40764. 0xae, 0xa0, 0x88, 0x96, 0x8a, 0xc2, 0x9b, 0x8d, 0xee, 0x6f, 0x2e, 0x79,
  40765. 0x1f, 0xec, 0x32, 0x35, 0x75, 0x83, 0x19, 0x8b, 0xda, 0xca, 0xd0, 0xaf,
  40766. 0x6a, 0x6c, 0x42, 0xe8, 0x81, 0xb5, 0x69, 0x31, 0x0b, 0x7d, 0xbc, 0xd8,
  40767. 0xd2, 0xb7, 0x7a, 0x8f, 0xfa, 0xcf, 0x91, 0x07, 0x1f, 0xda, 0xa9, 0x1f,
  40768. 0xb7, 0x2d, 0xff, 0x50, 0x15, 0x2a, 0xef, 0x8c, 0xa1, 0xe3, 0x7f, 0x08,
  40769. 0x95, 0xf2, 0x99, 0x83, 0x1f, 0x97, 0x71, 0x3e, 0x35, 0x3c, 0x8c, 0xe7,
  40770. 0x08, 0xd8, 0xa6, 0x1f, 0x0c, 0xa6, 0x52, 0xdc, 0x73, 0xa0, 0xfc, 0xd2,
  40771. 0x73, 0xe9, 0x27, 0x9d, 0xfd, 0x7a, 0x4a, 0x29, 0xd3, 0x12, 0x26, 0x13,
  40772. 0x0f, 0xce, 0xea, 0x56, 0x99, 0x61, 0x78, 0x47, 0x2c, 0xa0, 0x16, 0xa0,
  40773. 0xe2, 0x64, 0x97, 0x57, 0x31, 0xf0, 0x32, 0x5b, 0x44, 0x93, 0x76, 0x8b,
  40774. 0x59, 0x63, 0x5c, 0x5b, 0x0f, 0xe1, 0xe7, 0x74, 0x98, 0x11, 0x2d, 0x90,
  40775. 0xe4, 0xde, 0xd4, 0x3a, 0xc2, 0xfd, 0x24, 0xe3, 0x1f, 0x7a, 0xf4, 0x40,
  40776. 0xbb, 0x51, 0x92, 0x8f, 0x68, 0x9c, 0x51, 0xab, 0xdc, 0xf6, 0x1e, 0x96,
  40777. 0xca, 0x56, 0x5c, 0x92, 0xca, 0xb2, 0x1b, 0x2e, 0x6d, 0x20, 0x28, 0xb3,
  40778. 0x0a, 0x8e, 0xfd, 0xa9, 0xa2, 0x38, 0x74, 0x60, 0x37, 0xa6, 0x96, 0x02,
  40779. 0x20, 0x8a, 0x9a, 0x2b, 0x8c, 0xb9, 0x6d, 0xec, 0xff, 0xbf, 0x88, 0xbd,
  40780. 0x6c, 0xb4, 0x10, 0xbd, 0xfa, 0x5a, 0xeb, 0xb2, 0x6b, 0x74, 0x13, 0x2d,
  40781. 0xa5, 0xdb, 0x60, 0x93, 0xc6, 0xed, 0x39, 0x4f, 0xc5, 0x63, 0xe1, 0x9e,
  40782. 0x57, 0x1f, 0xe7, 0x47, 0xa4, 0xfb, 0x7f, 0xfa, 0x3a, 0x46, 0x50, 0x3a,
  40783. 0xd8, 0xd3, 0x83, 0xf5, 0xe6, 0x5e, 0xf8, 0x09, 0x0d, 0xfa, 0x33, 0xe1,
  40784. 0x50, 0xe4, 0x36, 0x3e, 0x0a, 0x5d, 0xe6, 0xf8, 0x2e, 0x17, 0x87, 0x8f,
  40785. 0xe1, 0x8c, 0x82, 0x73, 0xbd, 0xdd, 0x3b, 0x77, 0x47, 0x9f, 0x42, 0xd7,
  40786. 0xf4, 0x2d, 0x6c, 0xef, 0xcc, 0x22, 0x15, 0x3c, 0xe9, 0x26, 0xea, 0xbc,
  40787. 0xee, 0x09, 0xd3, 0xea, 0x84, 0x0f, 0x46, 0xa8, 0xe0, 0xda, 0xc5, 0x57,
  40788. 0x02, 0x54, 0xb6, 0x88, 0x2b, 0x37, 0xe5, 0x96, 0xc5, 0x33, 0xb7, 0x45,
  40789. 0x5d, 0xb7, 0xc7, 0xfd, 0xa0, 0xfa, 0x85, 0x1b, 0x2f, 0xe1, 0xec, 0x89,
  40790. 0xc6, 0xb2, 0x51, 0x71, 0xcb, 0x08, 0x82, 0x3e, 0xc9, 0xed, 0x80, 0x9d,
  40791. 0x37, 0x31, 0x9d, 0x15, 0xde, 0x24, 0x6f, 0xbd, 0x0e, 0x73, 0xa2, 0xb8,
  40792. 0x7e, 0x29, 0x7e, 0x96, 0xe4, 0xbb, 0xd6, 0x23, 0x17, 0xff, 0x33, 0x97,
  40793. 0x9c, 0x87, 0xe0, 0xe5, 0x0f, 0xb9, 0xb6, 0x31, 0x33, 0xad, 0xf8, 0xd8,
  40794. 0xdb, 0xa0, 0x71, 0x13, 0xe4, 0x1c, 0xce, 0xd0, 0x7e, 0x65, 0x7b, 0xa0,
  40795. 0x38, 0x17, 0x53, 0x4f, 0x71, 0x75, 0x6d, 0x02, 0x61, 0xc4, 0x52, 0xf8,
  40796. 0xe4, 0x2e, 0xbc, 0x52, 0xc1, 0xb1, 0x7e, 0x83, 0x0a, 0xa1, 0xd1, 0xcd,
  40797. 0x2f, 0xa0, 0x30, 0xfd, 0x41, 0x86, 0x7f, 0x26, 0xd1, 0xe7, 0xfc, 0xd7,
  40798. 0xc7, 0x37, 0xe5, 0x11, 0xa6, 0xc0, 0x9a, 0x75, 0x18, 0x04, 0x36, 0xca,
  40799. 0x8e, 0x26, 0x7d, 0xcf, 0xa2, 0x6a, 0x94, 0x9b, 0xc4, 0xf7, 0xc7, 0xeb,
  40800. 0x51, 0x13, 0xa3, 0x6f, 0x8c, 0x80, 0x5f, 0xae, 0xf0, 0x18, 0xa0, 0x88,
  40801. 0xe0, 0x8d, 0xb7, 0x80, 0x4e, 0x8c, 0xec, 0xc8, 0x7b, 0xeb, 0xac, 0x29,
  40802. 0xb7, 0x4a, 0x0f, 0x33, 0xdd, 0x9d, 0x89, 0x0a, 0x10, 0xb0, 0xce, 0x74,
  40803. 0x59, 0xa2, 0x62, 0x91, 0xc9, 0xac, 0x56, 0xcd, 0x69, 0xd3, 0x01, 0x6d,
  40804. 0x51, 0xe7, 0x04, 0xc3, 0xfb, 0xe9, 0x79, 0x1b, 0x72, 0x72, 0x1a, 0x90,
  40805. 0x0a, 0x20, 0x55, 0x85, 0xc1, 0x8b, 0xeb, 0x1e, 0x9f, 0x9f, 0x4a, 0x81,
  40806. 0x47, 0x97, 0x96, 0xbc, 0xc2, 0xe4, 0xc2, 0xfe, 0xa0, 0x20, 0xda, 0x70,
  40807. 0x0c, 0x2b, 0xe2, 0xd4, 0xc8, 0xcb, 0x46, 0x00, 0xb6, 0x7c, 0xfb, 0xbd,
  40808. 0x56, 0x94, 0x3d, 0x7f, 0x64, 0xf7, 0x88, 0xb5, 0xa7, 0xfe, 0xbe, 0x64,
  40809. 0x8a, 0xe4, 0x00, 0x08, 0x82, 0x5b, 0x8f, 0x98, 0x77, 0x87, 0xda, 0xaf,
  40810. 0x16, 0x25, 0x4a, 0x9a, 0xed, 0xfb, 0x50, 0x18, 0x45, 0x46, 0x2b, 0x73,
  40811. 0xff, 0xb9, 0xb9, 0xab, 0xa2, 0x8f, 0x3a, 0xaf, 0xc5, 0x0a, 0x14, 0x91,
  40812. 0xb2, 0x3f, 0xa6, 0x93, 0xf4, 0x81, 0x20, 0x77, 0xfa, 0x51, 0x79, 0x62,
  40813. 0xe8, 0xe6, 0x89, 0x52, 0x39, 0xd5, 0x01, 0xa2, 0x87, 0xa3, 0x53, 0x74,
  40814. 0x3c, 0x36, 0x8a, 0xc3, 0xb4, 0x44, 0x3b, 0x15, 0x21, 0xf6, 0xdc, 0x18,
  40815. 0x02, 0xd2, 0x57, 0xe5, 0x10, 0xf0, 0x3d, 0x61, 0xa7, 0x16, 0x85, 0x6f,
  40816. 0x71, 0x07, 0x75, 0x50, 0x4b, 0x21, 0x53, 0x47, 0x38, 0x35, 0x9e, 0xa7,
  40817. 0xd8, 0xfd, 0x74, 0x59, 0x15, 0x32, 0x7b, 0x89, 0xd0, 0x2c, 0xd9, 0xf6,
  40818. 0x40, 0x49, 0x79, 0xdc, 0xfb, 0x0a, 0x64, 0x59, 0x9b, 0x17, 0x47, 0x36,
  40819. 0xcb, 0xf0, 0xc3, 0xcc, 0x14, 0x8e, 0x1f, 0xa8, 0x12, 0xaa, 0xb7, 0x6a,
  40820. 0xba, 0x45, 0xf9, 0xc4, 0x44, 0xe7, 0xb5, 0x7c, 0xdd, 0xbe, 0x16, 0x76,
  40821. 0x52, 0x92, 0x3d, 0x78, 0xb7, 0xec, 0x81, 0x96, 0xd8, 0x7f, 0x34, 0x2a,
  40822. 0xa2, 0x64, 0x5f, 0xfd, 0xb1, 0x42, 0x4c, 0x79, 0x98, 0xc9, 0x17, 0x48,
  40823. 0x74, 0x12, 0x72, 0x2c, 0xde, 0x91, 0x7e, 0xa9, 0x49, 0x2a, 0xcc, 0x5c,
  40824. 0x60, 0x05, 0x25, 0x09, 0x72, 0x20, 0x80, 0x42, 0x7b, 0x18, 0xc2, 0xfc,
  40825. 0x2a, 0x5e, 0x3e, 0x2d, 0x61, 0xa6, 0xf6, 0x82, 0x42, 0x83, 0x81, 0x66,
  40826. 0x4d, 0xa6, 0xe1, 0xf9, 0xf6, 0x48, 0xd4, 0xc8, 0x69, 0xed, 0xee, 0xb5,
  40827. 0x7a, 0xcb, 0xf6, 0x0a, 0x76, 0x0e, 0x61, 0x8b, 0xf2, 0x1a, 0x8a, 0xa7,
  40828. 0x88, 0xb0, 0x90, 0xd5, 0x23, 0xaa, 0xe0, 0x2b, 0xd6, 0xd0, 0xef, 0x49,
  40829. 0x13, 0x88, 0xc7, 0x50, 0xf0, 0x9e, 0xd5, 0x28, 0xe1, 0xaa, 0x1d, 0xaf,
  40830. 0xd9, 0x73, 0xb3, 0x9e, 0xa7, 0xd8, 0xfc, 0xb9, 0x22, 0x97, 0x0e, 0x21,
  40831. 0xa0, 0xb9, 0xf9, 0xea, 0x1e, 0x95, 0x88, 0xda, 0x85, 0x7c, 0x32, 0x7c,
  40832. 0xbd, 0xef, 0xf8, 0x44, 0x25, 0x5f, 0x23, 0xfd, 0x14, 0x78, 0xc6, 0xdb,
  40833. 0x86, 0xee, 0xf8, 0xda, 0xc0, 0xae, 0x92, 0x6a, 0x03, 0xa9, 0x0a, 0xee,
  40834. 0x4a, 0x22, 0x5a, 0x6c, 0x39, 0xd3, 0x91, 0x7d, 0x91, 0x43, 0xac, 0x79,
  40835. 0xad, 0xab, 0xb7, 0x91, 0xb1, 0x20, 0x84, 0x7f, 0x0a, 0xd7, 0xa8, 0x62,
  40836. 0x95, 0xab, 0x04, 0xb6, 0xb2, 0xf1, 0xd4, 0xb0, 0xac, 0x52, 0x89, 0xb0,
  40837. 0x93, 0xdf, 0xdf, 0x80, 0x26, 0x0c, 0x32, 0x31, 0xb3, 0xba, 0xa1, 0xba,
  40838. 0x6f, 0xa3, 0x14, 0x5c, 0xfa, 0x37, 0x3b, 0x6a, 0xf2, 0xc4, 0x34, 0x27,
  40839. 0x08, 0x1a, 0xe4, 0xfc, 0x89, 0x58, 0x79, 0x34, 0x36, 0xe4, 0xad, 0x4b,
  40840. 0x3f, 0x57, 0x7b, 0xc1, 0x59, 0x2d, 0xb6, 0x54, 0x44, 0xbe, 0x4e, 0x5d,
  40841. 0x0d, 0x6a, 0xf3, 0xcd, 0xbf, 0xcd, 0x4d, 0x9f, 0x9a, 0x50, 0x09, 0xa4,
  40842. 0x6b, 0x8b, 0xb3, 0x01, 0x69, 0x6c, 0x69, 0x5d, 0x28, 0x73, 0x9e, 0xb5,
  40843. 0xc2, 0xc7, 0x6e, 0xff, 0x4c, 0x5c, 0x6b, 0x93, 0x22, 0xc1, 0x9f, 0xa6,
  40844. 0x71, 0xbf, 0x4d, 0x2d, 0x4e, 0x4e, 0x98, 0xa3, 0x6d, 0xab, 0x05, 0xa0,
  40845. 0xde, 0x34, 0x41, 0x28, 0xa4, 0x38, 0x75, 0x4e, 0xdf, 0x7f, 0xc9, 0xdd,
  40846. 0xbf, 0x5a, 0xd4, 0xcd, 0x38, 0x0c, 0x89, 0xe7, 0x0e, 0xfc, 0x0f, 0x27,
  40847. 0x39, 0x21, 0xa4, 0xa6, 0x07, 0x7b, 0x2a, 0x13, 0x56, 0xe7, 0x4e, 0x55,
  40848. 0x57, 0x71, 0x98, 0xb9, 0x3d, 0x59, 0xb5, 0xa8, 0x24, 0x18, 0x08, 0xa2,
  40849. 0x6e, 0x9a, 0xe5, 0x97, 0xa7, 0x38, 0xd9, 0x43, 0x9b, 0x19, 0x17, 0x34,
  40850. 0x03, 0xd6, 0xba, 0xe9, 0x71, 0x38, 0x26, 0x90, 0x78, 0x9e, 0x1c, 0x41,
  40851. 0x8d, 0x60, 0xdd, 0x0e, 0x12, 0x46, 0x37, 0xb4, 0x79, 0x87, 0x33, 0x12,
  40852. 0x24, 0xc4, 0x5a, 0x6c, 0x70, 0xa2, 0xb2, 0x58, 0xbb, 0xe7, 0xd6, 0x88,
  40853. 0x42, 0x2d, 0x49, 0xc8, 0x67, 0x1e, 0xc5, 0xed, 0x16, 0xa8, 0x1f, 0x36,
  40854. 0x2b, 0xfb, 0x0d, 0x51, 0x96, 0xc8, 0x78, 0xf2, 0xab, 0x82, 0xa1, 0xe2,
  40855. 0xaf, 0x8c, 0xa4, 0x13, 0x54, 0x90, 0xf1, 0xe7, 0xbb, 0xd1, 0x09, 0x23,
  40856. 0x76, 0x0e, 0x50, 0x32, 0xc5, 0x54, 0xbb, 0x1e, 0x12, 0x5d, 0x59, 0xf3,
  40857. 0xe9, 0xc9, 0xa4, 0xaa, 0xbc, 0x13, 0x1d, 0xf0, 0x79, 0x54, 0xae, 0x70,
  40858. 0xc0, 0xea, 0xcb, 0x21, 0x32, 0xe6, 0xe6, 0x8e, 0xaa, 0x51, 0x46, 0x25,
  40859. 0x1e, 0xf1, 0x3f, 0x9f, 0xf6, 0xff, 0x19, 0x53, 0x97, 0xbc, 0xa2, 0xb6,
  40860. 0x91, 0x59, 0x27, 0x1e, 0x39, 0x76, 0x76, 0x02, 0x0b, 0x03, 0x25, 0x6b,
  40861. 0x00, 0x02, 0xfa, 0x7d, 0x69, 0x5e, 0xde, 0x64, 0x33, 0xbf, 0xab, 0x3e,
  40862. 0x3f, 0x24, 0x32, 0x68, 0xbf, 0x90, 0x8f, 0x0f, 0xc5, 0x36, 0x58, 0x9e,
  40863. 0x9b, 0x11, 0xd1, 0x2a, 0x8a, 0x0d, 0xac, 0x3a, 0x23, 0xe2, 0x8e, 0xd6,
  40864. 0x0d, 0x4a, 0x8b, 0x45, 0x04, 0x47, 0xd9, 0x5a, 0x46, 0x6c, 0x70, 0x82,
  40865. 0xc7, 0x81, 0x67, 0xdc, 0xa6, 0xfa, 0x6a, 0x86, 0xfd, 0x01, 0xed, 0x90,
  40866. 0xf6, 0xe6, 0x26, 0x6d, 0xac, 0x52, 0x03, 0x4a, 0x91, 0x08, 0x7b, 0xa5,
  40867. 0x9c, 0xca, 0xd3, 0x2d, 0x79, 0xf1, 0xed, 0xcb, 0xaa, 0x8f, 0x77, 0xc8,
  40868. 0x17, 0xa8, 0xfb, 0x6c, 0x15, 0x62, 0xab, 0x34, 0xd1, 0xdd, 0x94, 0x3e,
  40869. 0xd4, 0x0c, 0x47, 0xed, 0x04, 0x91, 0xd2, 0xd7, 0x98, 0xb4, 0x43, 0x57,
  40870. 0xd1, 0x54, 0xef, 0x63, 0xba, 0xe3, 0x8a, 0x72, 0xc5, 0xb9, 0xf4, 0x30,
  40871. 0xfa, 0x16, 0x3c, 0xe1, 0xbb, 0xbe, 0x57, 0x90, 0xb9, 0xa1, 0xa0, 0x23,
  40872. 0xfa, 0xdd, 0xbe, 0x2f, 0xb3, 0xec, 0x41, 0x8b, 0x64, 0xeb, 0xc5, 0x41,
  40873. 0xea, 0xa8, 0x16, 0x76, 0x6f, 0x28, 0xda, 0x2b, 0x5f, 0x03, 0x0b, 0xe8,
  40874. 0x1c, 0x29, 0x71, 0xd8, 0x4e, 0x41, 0xdf, 0x39, 0x8e, 0x6a, 0x95, 0x79,
  40875. 0x85, 0x9c, 0xa9, 0x79, 0xd9, 0x8f, 0x33, 0xaf, 0x15, 0x3b, 0x5a, 0x82,
  40876. 0x56, 0x32, 0x98, 0x0c, 0xf6, 0xf6, 0x64, 0x42, 0xd4, 0x6a, 0x15, 0x0f,
  40877. 0xb9, 0x75, 0x22, 0xbd, 0x9a, 0x58, 0xa6, 0x01, 0x3a, 0x63, 0xf0, 0x80,
  40878. 0x78, 0x22, 0x80, 0xa0, 0x14, 0xe1, 0x37, 0x6b, 0xd4, 0x99, 0x3f, 0xc2,
  40879. 0xba, 0x2b, 0x8f, 0xf3, 0x56, 0xc8, 0x1b, 0xe4, 0x7a, 0x5e, 0x96, 0x60,
  40880. 0xee, 0x74, 0x54, 0xb6, 0x6d, 0x5c, 0x3d, 0x3e, 0x05, 0xf0, 0x9a, 0xf6,
  40881. 0xcd, 0xdd, 0x06, 0xdb, 0x8c, 0x21, 0xb9, 0xf5, 0x28, 0x57, 0x9c, 0x4f,
  40882. 0xb4, 0x08, 0xcf, 0xac, 0x6c, 0xfe, 0x30, 0xaf, 0xa2, 0xef, 0xcf, 0x93,
  40883. 0x15, 0xdd, 0x12, 0x16, 0x19, 0x7d, 0xbc, 0x57, 0xd9, 0xce, 0xbe, 0x0e,
  40884. 0xfc, 0xe1, 0xf0, 0x4a, 0x7c, 0xaa, 0xbf, 0x20, 0x64, 0x00, 0x34, 0x59,
  40885. 0xed, 0xea, 0x12, 0x58, 0x46, 0x4c, 0xc6, 0x2f, 0x77, 0x62, 0x1d, 0x82,
  40886. 0x5c, 0xe8, 0x98, 0x0d, 0xef, 0x5c, 0x0e, 0xec, 0x5d, 0x2e, 0x5f, 0xd2,
  40887. 0x22, 0x43, 0x2d, 0xe1, 0x02, 0xd5, 0x4a, 0x0a, 0x79, 0x6f, 0xa5, 0xec,
  40888. 0x48, 0xaa, 0xee, 0xf8, 0xe3, 0x5f, 0xdd, 0xe7, 0x26, 0x87, 0xb5, 0xc4,
  40889. 0xcf, 0xd9, 0x7f, 0xa8, 0xaa, 0xb6, 0xbe, 0xe9, 0x02, 0x49, 0x5d, 0x5f,
  40890. 0x81, 0x8b, 0xb9, 0xbd, 0xc0, 0xc9, 0xd5, 0xfe, 0x36, 0x3e, 0x49, 0x56,
  40891. 0x63, 0x8b, 0xce, 0xef, 0x48, 0x6e, 0xc0, 0xd4, 0x04, 0x0c, 0x33, 0x45,
  40892. 0x6e, 0x97, 0x9e, 0xa3, 0xae, 0xbc, 0xc2, 0xce, 0xdc, 0xe3, 0xff, 0x48,
  40893. 0x51, 0x68, 0x89, 0xad, 0xae, 0xc7, 0xd1, 0xde, 0xe2, 0xf9, 0xfe, 0x00,
  40894. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40895. 0x0c, 0x18, 0x20, 0x24, 0x2f, 0x33, 0x3f
  40896. };
  40897. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40898. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_sig[] = {
  40899. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  40900. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  40901. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  40902. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  40903. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  40904. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  40905. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  40906. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  40907. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  40908. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  40909. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  40910. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  40911. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  40912. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  40913. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  40914. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  40915. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  40916. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  40917. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  40918. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  40919. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  40920. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  40921. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  40922. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  40923. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  40924. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  40925. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  40926. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  40927. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  40928. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  40929. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  40930. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  40931. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  40932. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  40933. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  40934. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  40935. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  40936. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  40937. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  40938. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  40939. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  40940. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  40941. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  40942. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  40943. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  40944. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  40945. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  40946. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  40947. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  40948. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  40949. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  40950. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  40951. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  40952. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  40953. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  40954. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  40955. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  40956. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  40957. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  40958. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  40959. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  40960. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  40961. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  40962. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  40963. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  40964. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  40965. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  40966. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  40967. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  40968. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  40969. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  40970. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  40971. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  40972. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  40973. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  40974. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  40975. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  40976. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  40977. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  40978. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  40979. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  40980. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  40981. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  40982. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  40983. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  40984. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  40985. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  40986. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  40987. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  40988. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  40989. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  40990. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  40991. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  40992. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  40993. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  40994. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  40995. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  40996. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  40997. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  40998. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  40999. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  41000. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  41001. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  41002. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  41003. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  41004. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  41005. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  41006. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  41007. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  41008. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  41009. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  41010. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  41011. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  41012. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  41013. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  41014. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  41015. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  41016. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  41017. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  41018. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  41019. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  41020. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  41021. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  41022. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  41023. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  41024. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  41025. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  41026. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  41027. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  41028. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  41029. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  41030. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  41031. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  41032. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  41033. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  41034. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  41035. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  41036. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  41037. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  41038. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  41039. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  41040. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  41041. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  41042. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  41043. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  41044. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  41045. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  41046. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  41047. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  41048. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  41049. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  41050. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  41051. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  41052. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  41053. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  41054. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  41055. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  41056. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  41057. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  41058. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  41059. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  41060. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  41061. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  41062. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  41063. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  41064. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  41065. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  41066. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  41067. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  41068. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  41069. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  41070. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  41071. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  41072. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  41073. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  41074. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  41075. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  41076. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  41077. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  41078. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  41079. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  41080. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  41081. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  41082. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  41083. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  41084. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  41085. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  41086. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  41087. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  41088. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  41089. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  41090. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  41091. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  41092. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  41093. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  41094. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  41095. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  41096. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  41097. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  41098. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  41099. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  41100. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  41101. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  41102. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  41103. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  41104. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  41105. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  41106. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  41107. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  41108. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  41109. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  41110. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  41111. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  41112. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  41113. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  41114. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  41115. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  41116. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  41117. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  41118. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  41119. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  41120. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  41121. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  41122. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  41123. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  41124. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  41125. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  41126. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  41127. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  41128. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  41129. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  41130. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  41131. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  41132. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  41133. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  41134. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  41135. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  41136. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  41137. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  41138. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  41139. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  41140. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  41141. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  41142. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  41143. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  41144. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  41145. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  41146. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  41147. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  41148. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  41149. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  41150. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  41151. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  41152. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  41153. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  41154. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  41155. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  41156. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  41157. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  41158. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  41159. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  41160. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  41161. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  41162. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  41163. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  41164. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  41165. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  41166. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  41167. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  41168. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  41169. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  41170. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  41171. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  41172. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  41173. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  41174. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  41175. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  41176. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  41177. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  41178. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  41179. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  41180. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  41181. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  41182. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  41183. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  41184. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  41185. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  41186. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  41187. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  41188. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  41189. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  41190. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  41191. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  41192. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  41193. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  41194. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  41195. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  41196. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  41197. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  41198. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  41199. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  41200. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  41201. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  41202. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  41203. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  41204. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  41205. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  41206. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  41207. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  41208. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  41209. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  41210. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  41211. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  41212. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  41213. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  41214. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  41215. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  41216. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  41217. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  41218. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  41219. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  41220. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  41221. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  41222. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  41223. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  41224. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  41225. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  41226. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  41227. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  41228. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  41229. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  41230. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  41231. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  41232. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  41233. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  41234. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  41235. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  41236. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  41237. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  41238. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  41239. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  41240. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  41241. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  41242. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  41243. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  41244. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  41245. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  41246. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  41247. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  41248. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  41249. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  41250. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  41251. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  41252. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  41253. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  41254. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  41255. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  41256. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  41257. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  41258. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  41259. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  41260. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  41261. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  41262. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  41263. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  41264. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  41265. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  41266. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  41267. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  41268. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  41269. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  41270. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  41271. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  41272. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  41273. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  41274. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  41275. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  41276. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  41277. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  41278. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  41279. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  41280. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  41281. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  41282. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  41283. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  41284. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  41285. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  41286. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  41287. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  41288. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  41289. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  41290. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  41291. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  41292. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  41293. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  41294. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  41295. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  41296. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  41297. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  41298. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  41299. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  41300. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  41301. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  41302. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  41303. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  41304. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  41305. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  41306. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  41307. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  41308. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  41309. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  41310. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  41311. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  41312. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  41313. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  41314. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  41315. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  41316. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  41317. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  41318. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  41319. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  41320. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  41321. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  41322. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  41323. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  41324. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  41325. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  41326. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  41327. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  41328. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  41329. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  41330. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  41331. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  41332. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  41333. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  41334. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  41335. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  41336. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  41337. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  41338. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  41339. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  41340. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  41341. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  41342. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  41343. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  41344. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  41345. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  41346. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  41347. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  41348. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  41349. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  41350. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  41351. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  41352. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  41353. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  41354. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  41355. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  41356. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  41357. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  41358. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  41359. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  41360. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  41361. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f
  41362. };
  41363. #endif
  41364. wc_test_ret_t ret;
  41365. ret = dilithium_param_vfy_test(WC_ML_DSA_87, ml_dsa_87_pub_key,
  41366. (word32)sizeof(ml_dsa_87_pub_key), ml_dsa_87_sig,
  41367. (word32)sizeof(ml_dsa_87_sig));
  41368. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  41369. if (ret == 0) {
  41370. ret = dilithium_param_vfy_test(WC_ML_DSA_87_DRAFT,
  41371. ml_dsa_87_draft_pub_key, (word32)sizeof(ml_dsa_87_draft_pub_key),
  41372. ml_dsa_87_draft_sig, (word32)sizeof(ml_dsa_87_draft_sig));
  41373. }
  41374. #endif
  41375. return ret;
  41376. }
  41377. #endif
  41378. #endif
  41379. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41380. static wc_test_ret_t dilithium_param_test(int param, WC_RNG* rng)
  41381. {
  41382. wc_test_ret_t ret;
  41383. dilithium_key* key;
  41384. byte* sig = NULL;
  41385. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41386. word32 sigLen;
  41387. byte msg[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  41388. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41389. int res = 0;
  41390. #endif
  41391. #endif
  41392. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  41393. DYNAMIC_TYPE_TMP_BUFFER);
  41394. if (key == NULL) {
  41395. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41396. }
  41397. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT,
  41398. DYNAMIC_TYPE_TMP_BUFFER);
  41399. if (sig == NULL) {
  41400. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41401. }
  41402. ret = wc_dilithium_init(key);
  41403. if (ret != 0) {
  41404. ret = WC_TEST_RET_ENC_EC(ret);
  41405. return ret;
  41406. }
  41407. ret = wc_dilithium_set_level(key, param);
  41408. if (ret != 0)
  41409. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41410. ret = wc_dilithium_make_key(key, rng);
  41411. if (ret != 0)
  41412. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41413. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41414. sigLen = wc_dilithium_sig_size(key);
  41415. if (sigLen <= 0)
  41416. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41417. ret = wc_dilithium_sign_msg(msg, (word32)sizeof(msg), sig, &sigLen, key,
  41418. rng);
  41419. if (ret != 0)
  41420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41421. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41422. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg), &res,
  41423. key);
  41424. if (ret != 0)
  41425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41426. if (res != 1)
  41427. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  41428. #endif
  41429. #endif
  41430. out:
  41431. wc_dilithium_free(key);
  41432. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41433. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41434. return ret;
  41435. }
  41436. #endif
  41437. #if defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41438. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41439. /* Tests decoding a key from DER without the security level specified */
  41440. static wc_test_ret_t test_dilithium_decode_level(const byte* rawKey,
  41441. word32 rawKeySz,
  41442. int expectedLevel,
  41443. int isPublicOnlyKey)
  41444. {
  41445. int ret = 0;
  41446. #ifdef WOLFSSL_SMALL_STACK
  41447. dilithium_key *key = NULL;
  41448. #else
  41449. dilithium_key key[1];
  41450. #endif
  41451. word32 idx;
  41452. byte* der;
  41453. word32 derSz;
  41454. /* Size the buffer to accommodate the largest encoded key size */
  41455. const word32 maxDerSz = DILITHIUM_MAX_PRV_KEY_DER_SIZE;
  41456. /* Allocate DER buffer */
  41457. der = (byte*)XMALLOC(maxDerSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41458. if (der == NULL) {
  41459. return MEMORY_E;
  41460. }
  41461. #ifdef WOLFSSL_SMALL_STACK
  41462. key = (dilithium_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41463. if (key == NULL)
  41464. ret = MEMORY_E;
  41465. #endif
  41466. /* Initialize key */
  41467. if (ret == 0) {
  41468. ret = wc_dilithium_init(key);
  41469. }
  41470. /* Import raw key, setting the security level */
  41471. if (ret == 0) {
  41472. ret = wc_dilithium_set_level(key, expectedLevel);
  41473. }
  41474. if (ret == 0) {
  41475. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41476. if (isPublicOnlyKey) {
  41477. ret = wc_dilithium_import_public(rawKey, rawKeySz, key);
  41478. }
  41479. #endif
  41480. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41481. if (!isPublicOnlyKey) {
  41482. ret = wc_dilithium_import_private(rawKey, rawKeySz, key);
  41483. }
  41484. #endif
  41485. }
  41486. /* Export raw key as DER */
  41487. if (ret == 0) {
  41488. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41489. if (isPublicOnlyKey) {
  41490. ret = wc_Dilithium_PublicKeyToDer(key, der, maxDerSz, 1);
  41491. }
  41492. #endif
  41493. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41494. if (!isPublicOnlyKey) {
  41495. ret = wc_Dilithium_PrivateKeyToDer(key, der, maxDerSz);
  41496. }
  41497. #endif
  41498. if (ret >= 0) {
  41499. derSz = ret;
  41500. ret = 0;
  41501. }
  41502. }
  41503. /* Free and reinit key to test fresh decode */
  41504. if (ret == 0) {
  41505. wc_dilithium_free(key);
  41506. ret = wc_dilithium_init(key);
  41507. }
  41508. /* First test decoding when security level is set externally */
  41509. if (ret == 0) {
  41510. ret = wc_dilithium_set_level(key, expectedLevel);
  41511. }
  41512. if (ret == 0) {
  41513. idx = 0;
  41514. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41515. if (isPublicOnlyKey) {
  41516. ret = wc_Dilithium_PublicKeyDecode(der, &idx, key, derSz);
  41517. }
  41518. #endif
  41519. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41520. if (!isPublicOnlyKey) {
  41521. ret = wc_Dilithium_PrivateKeyDecode(der, &idx, key, derSz);
  41522. }
  41523. #endif
  41524. }
  41525. /* Free and reinit key to test fresh decode */
  41526. if (ret == 0) {
  41527. wc_dilithium_free(key);
  41528. ret = wc_dilithium_init(key);
  41529. }
  41530. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  41531. /* Test decoding without setting security level - should auto-detect */
  41532. if (ret == 0) {
  41533. idx = 0;
  41534. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41535. if (isPublicOnlyKey) {
  41536. ret = wc_Dilithium_PublicKeyDecode(der, &idx, key, derSz);
  41537. }
  41538. #endif
  41539. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41540. if (!isPublicOnlyKey) {
  41541. ret = wc_Dilithium_PrivateKeyDecode(der, &idx, key, derSz);
  41542. }
  41543. #endif
  41544. }
  41545. /* Verify auto-detected security level */
  41546. if (ret == 0 && key->level != expectedLevel) {
  41547. printf("Dilithium key decode failed to detect level.\n"
  41548. "\tExpected level=%d\n\tGot level=%d\n",
  41549. expectedLevel, key->level);
  41550. ret = WC_TEST_RET_ENC_NC;
  41551. }
  41552. #endif /* !WOLFSSL_DILITHIUM_FIPS204_DRAFT */
  41553. /* Cleanup */
  41554. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41555. wc_dilithium_free(key);
  41556. #ifdef WOLFSSL_SMALL_STACK
  41557. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41558. #endif
  41559. return ret;
  41560. }
  41561. /* Test Dilithium key decoding and security level detection */
  41562. static wc_test_ret_t dilithium_decode_test(void)
  41563. {
  41564. wc_test_ret_t ret;
  41565. const byte* key;
  41566. word32 keySz;
  41567. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41568. const int isPrvKey = 0;
  41569. #endif
  41570. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41571. const int isPubKey = 1;
  41572. #endif
  41573. #ifndef WOLFSSL_NO_ML_DSA_44
  41574. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41575. /* Test ML-DSA-44 */
  41576. key = bench_dilithium_level2_key;
  41577. keySz = sizeof_bench_dilithium_level2_key;
  41578. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_44, isPrvKey);
  41579. if (ret != 0) {
  41580. return ret;
  41581. }
  41582. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41583. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41584. key = bench_dilithium_level2_pubkey;
  41585. keySz = sizeof_bench_dilithium_level2_pubkey;
  41586. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_44, isPubKey);
  41587. if (ret != 0) {
  41588. return ret;
  41589. }
  41590. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41591. #endif /* WOLFSSL_NO_ML_DSA_44 */
  41592. #ifndef WOLFSSL_NO_ML_DSA_65
  41593. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41594. /* Test ML-DSA-65 */
  41595. key = bench_dilithium_level3_key;
  41596. keySz = sizeof_bench_dilithium_level3_key;
  41597. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_65, isPrvKey);
  41598. if (ret != 0) {
  41599. return ret;
  41600. }
  41601. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41602. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41603. key = bench_dilithium_level3_pubkey;
  41604. keySz = sizeof_bench_dilithium_level3_pubkey;
  41605. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_65, isPubKey);
  41606. if (ret != 0) {
  41607. return ret;
  41608. }
  41609. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41610. #endif /* WOLFSSL_NO_ML_DSA_65 */
  41611. #ifndef WOLFSSL_NO_ML_DSA_87
  41612. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41613. /* Test ML-DSA-87 */
  41614. key = bench_dilithium_level5_key;
  41615. keySz = sizeof_bench_dilithium_level5_key;
  41616. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_87, isPrvKey);
  41617. if (ret != 0) {
  41618. return ret;
  41619. }
  41620. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41621. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41622. key = bench_dilithium_level5_pubkey;
  41623. keySz = sizeof_bench_dilithium_level5_pubkey;
  41624. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_87, isPubKey);
  41625. if (ret != 0) {
  41626. return ret;
  41627. }
  41628. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41629. #endif /* WOLFSSL_NO_ML_DSA_87 */
  41630. return ret;
  41631. }
  41632. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY || WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41633. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
  41634. {
  41635. wc_test_ret_t ret;
  41636. WC_RNG rng;
  41637. #ifndef HAVE_FIPS
  41638. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41639. #else
  41640. ret = wc_InitRng(&rng);
  41641. #endif
  41642. if (ret != 0) {
  41643. ret = WC_TEST_RET_ENC_EC(ret);
  41644. return ret;
  41645. }
  41646. #ifndef WOLFSSL_NO_ML_DSA_44
  41647. #ifdef WOLFSSL_WC_DILITHIUM
  41648. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41649. ret = dilithium_param_44_vfy_test();
  41650. if (ret != 0)
  41651. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41652. #endif
  41653. #endif
  41654. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41655. ret = dilithium_param_test(WC_ML_DSA_44, &rng);
  41656. if (ret != 0)
  41657. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41658. #endif
  41659. #endif
  41660. #ifndef WOLFSSL_NO_ML_DSA_65
  41661. #ifdef WOLFSSL_WC_DILITHIUM
  41662. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41663. ret = dilithium_param_65_vfy_test();
  41664. if (ret != 0)
  41665. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41666. #endif
  41667. #endif
  41668. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41669. ret = dilithium_param_test(WC_ML_DSA_65, &rng);
  41670. if (ret != 0)
  41671. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41672. #endif
  41673. #endif
  41674. #ifndef WOLFSSL_NO_ML_DSA_87
  41675. #ifdef WOLFSSL_WC_DILITHIUM
  41676. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41677. ret = dilithium_param_87_vfy_test();
  41678. if (ret != 0)
  41679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41680. #endif
  41681. #endif
  41682. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41683. ret = dilithium_param_test(WC_ML_DSA_87, &rng);
  41684. if (ret != 0)
  41685. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41686. #endif
  41687. #endif
  41688. #if defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41689. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41690. ret = dilithium_decode_test();
  41691. if (ret != 0) {
  41692. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41693. }
  41694. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY || WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41695. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  41696. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) || \
  41697. defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41698. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41699. out:
  41700. #endif
  41701. wc_FreeRng(&rng);
  41702. return ret;
  41703. }
  41704. #endif /* HAVE_DILITHIUM */
  41705. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  41706. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  41707. void *context)
  41708. {
  41709. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41710. * BE USED FOR TESTING PURPOSES! Production applications should
  41711. * write only to non-volatile storage. */
  41712. XMEMCPY(context, priv, privSz);
  41713. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  41714. }
  41715. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  41716. void *context)
  41717. {
  41718. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41719. * BE USED FOR TESTING PURPOSES! */
  41720. XMEMCPY(priv, context, privSz);
  41721. return WC_XMSS_RC_READ_TO_MEMORY;
  41722. }
  41723. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
  41724. {
  41725. int i = 0;
  41726. int j = 0;
  41727. XmssKey signingKey;
  41728. XmssKey verifyKey;
  41729. WC_RNG rng;
  41730. word32 pkSz = 0;
  41731. word32 skSz = 0;
  41732. word32 sigSz = 0;
  41733. word32 bufSz = 0;
  41734. unsigned char * sk = NULL;
  41735. unsigned char * old_sk = NULL;
  41736. const char * msg = "XMSS post quantum signature test";
  41737. word32 msgSz = (word32) XSTRLEN(msg);
  41738. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41739. const char * param = "XMSS-SHA2_10_256";
  41740. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 20
  41741. const char * param = "XMSSMT-SHA2_20/4_256";
  41742. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 40
  41743. const char * param = "XMSSMT-SHA2_40/8_256";
  41744. #else
  41745. const char * param = "XMSSMT-SHA2_60/12_256";
  41746. #endif
  41747. byte * sig = NULL;
  41748. int ret2 = -1;
  41749. int ret = WC_TEST_RET_ENC_NC;
  41750. WOLFSSL_ENTER("xmss_test");
  41751. #ifndef HAVE_FIPS
  41752. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41753. #else
  41754. ret = wc_InitRng(&rng);
  41755. #endif
  41756. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41757. ret = wc_XmssKey_Init(&signingKey, NULL, INVALID_DEVID);
  41758. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41759. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41760. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41761. /* Set the parameter string to the signing key, and
  41762. * get sizes for secret key, pub key, and signature. */
  41763. ret = wc_XmssKey_SetParamStr(&signingKey, param);
  41764. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41765. ret = wc_XmssKey_GetPubLen(&signingKey, &pkSz);
  41766. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41767. if (pkSz != XMSS_SHA256_PUBLEN) {
  41768. return WC_TEST_RET_ENC_EC(pkSz);
  41769. }
  41770. ret = wc_XmssKey_GetPrivLen(&signingKey, &skSz);
  41771. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41772. ret = wc_XmssKey_GetSigLen(&signingKey, &sigSz);
  41773. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41774. /* Allocate signature array. */
  41775. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41776. if (sig == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41777. bufSz = sigSz;
  41778. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41779. fprintf(stderr, "param: %s\n", param);
  41780. fprintf(stderr, "pkSz: %d\n", pkSz);
  41781. fprintf(stderr, "skSz: %d\n", skSz);
  41782. fprintf(stderr, "sigSz: %d\n", sigSz);
  41783. #endif
  41784. /* Allocate current and old secret keys.*/
  41785. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41786. if (sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41787. old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41788. if (old_sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41789. XMEMSET(sk, 0, skSz);
  41790. XMEMSET(old_sk, 0, skSz);
  41791. XMEMSET(sig, 0, sigSz);
  41792. ret = wc_XmssKey_SetWriteCb(&signingKey, xmss_write_key_mem);
  41793. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41794. ret = wc_XmssKey_SetReadCb(&signingKey, xmss_read_key_mem);
  41795. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41796. ret = wc_XmssKey_SetContext(&signingKey, (void *) sk);
  41797. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41798. ret = wc_XmssKey_MakeKey(&signingKey, &rng);
  41799. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41800. /* Export the pub to a verify key. */
  41801. ret = wc_XmssKey_ExportPub(&verifyKey, &signingKey);
  41802. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41803. /* Repeat a few times to check that:
  41804. * 1. The secret key is mutated on each sign.
  41805. * 2. We can verify each new signature.
  41806. * Only do a few times, because the full signature space
  41807. * for this parameter set is huge. */
  41808. for (i = 0; i < 10; ++i) {
  41809. XMEMCPY(old_sk, sk, skSz);
  41810. ret = wc_XmssKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41811. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41812. if (sigSz != bufSz) { return WC_TEST_RET_ENC_I(i); }
  41813. /* Old secret key and current secret key should not match. */
  41814. ret = XMEMCMP(old_sk, sk, skSz);
  41815. if (ret == 0) { return WC_TEST_RET_ENC_I(i); }
  41816. ret = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41817. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41818. /* Flip bits in a few places throughout the signature, stepping in multiple
  41819. * of hash size. These should all fail with -1. */
  41820. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41821. sig[j] ^= 1;
  41822. ret2 = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41823. msgSz);
  41824. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41825. /* Verify passed when it should have failed. */
  41826. return WC_TEST_RET_ENC_I(j);
  41827. }
  41828. /* Flip this spot back. */
  41829. sig[j] ^= 1;
  41830. }
  41831. }
  41832. /* Cleanup everything. */
  41833. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41834. sig = NULL;
  41835. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41836. sk = NULL;
  41837. XFREE(old_sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41838. old_sk = NULL;
  41839. wc_XmssKey_Free(&signingKey);
  41840. wc_FreeRng(&rng);
  41841. return ret;
  41842. }
  41843. #endif /*if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)*/
  41844. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_SMALL_STACK) && \
  41845. WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41846. /* A simple xmss verify only test using:
  41847. * XMSS-SHA2_10_256
  41848. * pub len: 68
  41849. * msg len: 32
  41850. * sig len: 2500
  41851. *
  41852. * These were generated with the test xmss_fast, from the unpatched
  41853. * xmss-reference repository:
  41854. * https://github.com/XMSS/xmss-reference
  41855. * */
  41856. static const byte xmss_pub[XMSS_SHA256_PUBLEN] =
  41857. {
  41858. 0x00,0x00,0x00,0x01,0xA5,0x41,0x31,0x96,
  41859. 0x0A,0xF9,0xF3,0xB2,0x4B,0x2E,0x5B,0x3E,
  41860. 0xCA,0x74,0xAD,0x6C,0xA5,0x89,0xAD,0x2C,
  41861. 0x0E,0x96,0xB3,0x54,0xFB,0x5B,0x63,0x50,
  41862. 0x96,0x81,0xE2,0x59,0x72,0x10,0x09,0x54,
  41863. 0xBB,0x39,0xAC,0xEE,0x78,0xEF,0x95,0xEC,
  41864. 0x01,0x1D,0xF0,0x36,0x68,0xE2,0xC4,0xA5,
  41865. 0x2F,0x60,0x42,0x7E,0xD3,0x8E,0xAA,0x27,
  41866. 0xC9,0xB7,0x39,0x4E
  41867. };
  41868. static /* not const */ byte xmss_msg[32] =
  41869. {
  41870. 0x07,0x9F,0x80,0x86,0xDB,0x76,0x27,0xDF,
  41871. 0xED,0x5B,0x2A,0x81,0x60,0x60,0x7D,0xB4,
  41872. 0xE8,0x7A,0x69,0x45,0x20,0x6B,0xA2,0x96,
  41873. 0xC0,0x21,0xA5,0x46,0x29,0x63,0x9B,0x37
  41874. };
  41875. /* This was actually the 5th signature produced from
  41876. * xmss_fast test in xmss-reference. */
  41877. static /* not const */ byte xmss_sig[2500] =
  41878. {
  41879. 0x00,0x00,0x00,0x05,0xF0,0x15,0x34,0xBA,
  41880. 0x92,0x03,0x6A,0xB9,0xA5,0x23,0x86,0x11,
  41881. 0xAE,0x65,0x0A,0x5C,0x78,0x2C,0xC9,0xBE,
  41882. 0x7E,0xA6,0xDC,0xA2,0x8B,0xA9,0x9C,0x50,
  41883. 0xF6,0x61,0x8D,0x9D,0xD7,0xE9,0xC0,0xF8,
  41884. 0x67,0xCD,0x8A,0xC4,0x9B,0x74,0x96,0x07,
  41885. 0x5D,0xF2,0xC9,0xCC,0x28,0x05,0xB1,0xBE,
  41886. 0x5E,0xA4,0xBA,0xBE,0xAB,0xD8,0x21,0x6B,
  41887. 0x21,0x5F,0xAB,0xB7,0x6C,0xEC,0x2F,0xC8,
  41888. 0xC6,0x74,0x3E,0x97,0x1B,0xC3,0x45,0x57,
  41889. 0xAF,0xAA,0x1E,0xA8,0xF2,0x86,0xA8,0xAA,
  41890. 0x43,0x6D,0x66,0xE9,0x81,0x14,0xDE,0x09,
  41891. 0x39,0xD2,0xAF,0xD1,0x4C,0xE7,0x75,0x18,
  41892. 0x0D,0xAA,0x29,0xA1,0x92,0x53,0xCC,0xE9,
  41893. 0xF3,0x0B,0x1E,0x3B,0xE2,0xAE,0x80,0x0C,
  41894. 0xE7,0x7A,0x7C,0x13,0x8A,0x28,0xC6,0x5F,
  41895. 0x0A,0xA4,0xA3,0x73,0x0A,0x3A,0xC2,0xA6,
  41896. 0x3B,0xB4,0x30,0x67,0xC0,0x36,0x18,0xA1,
  41897. 0x58,0xCD,0xAD,0x54,0x36,0x64,0xCE,0xFD,
  41898. 0x52,0xFF,0x70,0x7E,0x09,0xFB,0x13,0xA2,
  41899. 0xEA,0xDF,0x67,0x8D,0x6C,0x42,0xB2,0x78,
  41900. 0xF5,0x7D,0x5C,0x4B,0xF7,0x8E,0xCF,0x3E,
  41901. 0xB7,0xC6,0xC1,0x23,0xFA,0x65,0xDE,0xD2,
  41902. 0xFA,0x40,0x51,0x97,0x0D,0x52,0x32,0x76,
  41903. 0x7E,0x82,0x8D,0xD0,0xB9,0x1E,0x62,0xD9,
  41904. 0x1E,0xC1,0xDB,0x40,0x43,0x37,0x4A,0x23,
  41905. 0x8A,0x1D,0x35,0xFA,0xF4,0x53,0x11,0x5A,
  41906. 0xB5,0x6D,0x1E,0x8B,0x22,0xC8,0x7D,0x2A,
  41907. 0xE4,0x94,0xAA,0x25,0x20,0x40,0x96,0xDB,
  41908. 0x82,0x62,0xBA,0x8F,0x8B,0x45,0xCB,0x4F,
  41909. 0x35,0x88,0x33,0xEB,0xEF,0xB3,0xBA,0xA7,
  41910. 0x09,0x72,0xB3,0x4C,0xEC,0xF2,0xC3,0xC7,
  41911. 0x5E,0x02,0x6C,0x41,0x93,0xCB,0x3C,0x89,
  41912. 0x12,0x09,0x68,0x54,0x8E,0xEC,0x6A,0x7E,
  41913. 0x20,0xE1,0x70,0x3D,0x8C,0xEB,0xB4,0x36,
  41914. 0xBE,0x91,0xBE,0x97,0xB5,0xA6,0x34,0x16,
  41915. 0x95,0x0F,0x10,0x26,0xA9,0x13,0x80,0x88,
  41916. 0x9C,0xAA,0x68,0xEC,0x34,0x70,0x4A,0x15,
  41917. 0x9B,0x5E,0x57,0x05,0x87,0x1C,0xF8,0x35,
  41918. 0x45,0x29,0xE9,0x6E,0xF2,0x70,0x13,0x42,
  41919. 0x89,0x4E,0x77,0xC0,0x18,0xC7,0x55,0x6D,
  41920. 0xE7,0xFA,0x0D,0x63,0x83,0x16,0x19,0x01,
  41921. 0x2D,0xFD,0x31,0x14,0x94,0xCA,0x3E,0x0E,
  41922. 0xD6,0x11,0x34,0x81,0x57,0x58,0xEC,0x24,
  41923. 0xA4,0x17,0x63,0xD3,0x25,0x00,0xBF,0x7D,
  41924. 0x78,0x5D,0xC5,0xD8,0xC6,0xC1,0xBD,0x8C,
  41925. 0xD0,0x94,0x0A,0xB1,0x33,0xA5,0x4B,0x31,
  41926. 0x25,0xF5,0xAF,0xE7,0x84,0x26,0xAA,0x05,
  41927. 0xBB,0xF3,0x9A,0xAF,0x58,0x36,0x40,0xEF,
  41928. 0x3D,0xA2,0xBD,0xCA,0xA1,0x8D,0x2F,0x6D,
  41929. 0x54,0xD2,0x62,0x33,0x09,0xAE,0xE6,0x73,
  41930. 0xD6,0x44,0xE8,0x7C,0x5C,0x39,0x2B,0x78,
  41931. 0x94,0x14,0xC7,0xC9,0xAF,0xEC,0x77,0x36,
  41932. 0xA1,0x61,0x61,0xF1,0xD0,0x09,0xA2,0xEE,
  41933. 0xE7,0x55,0xD7,0x35,0x89,0x89,0x9B,0xCF,
  41934. 0xFA,0xA6,0x09,0x1E,0x3B,0xBD,0x5D,0xD9,
  41935. 0x25,0xE7,0xED,0xDD,0x7C,0xF0,0x1C,0x57,
  41936. 0xE0,0x06,0xBB,0x08,0x39,0x59,0xDF,0xD7,
  41937. 0xAF,0x4B,0x88,0x0D,0x87,0x8F,0x4A,0xF3,
  41938. 0x1C,0xD4,0x4B,0xB3,0xE2,0xF3,0x1B,0x86,
  41939. 0x4F,0xCD,0x35,0x75,0xE2,0x03,0xF9,0x1D,
  41940. 0xBF,0x3E,0xD1,0x7B,0xC7,0x23,0x11,0x75,
  41941. 0x5F,0x92,0x0D,0x98,0xEE,0x14,0xE1,0xDA,
  41942. 0x7A,0x02,0x17,0x47,0x6B,0x41,0xEA,0x47,
  41943. 0xA1,0xAF,0x06,0x79,0x1A,0x52,0x6F,0x19,
  41944. 0x31,0x70,0x71,0xBD,0xC2,0x61,0x8D,0xB7,
  41945. 0xEE,0x6B,0x69,0x2A,0xE8,0x21,0x7A,0x95,
  41946. 0xBE,0x86,0x2A,0xA1,0xF4,0xE2,0x2F,0x17,
  41947. 0x02,0xFD,0xAD,0x17,0x9F,0x0A,0x0A,0x78,
  41948. 0xA9,0x92,0x30,0x21,0x72,0x2B,0x28,0xF8,
  41949. 0xF2,0x3E,0x05,0xD5,0xAC,0xC0,0x82,0xF8,
  41950. 0xD2,0xDA,0xD0,0xA3,0xBC,0x93,0xDB,0xA5,
  41951. 0x46,0xDE,0x14,0x1E,0xD4,0x3A,0x5D,0x79,
  41952. 0x3D,0x31,0x4B,0x06,0xCE,0x22,0x29,0x3C,
  41953. 0x98,0xB6,0x18,0x8A,0xAE,0xF7,0xBA,0x22,
  41954. 0x88,0xA1,0xEE,0xC0,0x14,0x4C,0x4A,0xA0,
  41955. 0x57,0x0A,0xD3,0x18,0xA2,0x3D,0xDD,0xC7,
  41956. 0x83,0x73,0xFC,0x38,0x9B,0x31,0xA3,0xE1,
  41957. 0x17,0x76,0xA1,0xA2,0x69,0xFC,0xAB,0x08,
  41958. 0x80,0x72,0x8D,0xF5,0xE4,0x14,0xB7,0x6B,
  41959. 0x03,0xFF,0xE8,0x11,0x4B,0x06,0x55,0x7E,
  41960. 0x36,0x21,0x2F,0xD7,0x54,0x82,0xC9,0x31,
  41961. 0xB4,0x85,0x68,0x41,0xEF,0x75,0xB0,0x3A,
  41962. 0xEA,0x4F,0xE0,0xEC,0x72,0xCC,0x33,0x96,
  41963. 0xCE,0x7D,0xAD,0xDD,0x0D,0x27,0x05,0x6E,
  41964. 0xA2,0xD4,0x11,0x07,0xD8,0x7D,0x27,0xD4,
  41965. 0x80,0x8F,0x00,0x22,0xE4,0xFC,0x2C,0x9D,
  41966. 0xD5,0xD8,0x18,0x7F,0x4E,0xF4,0xB9,0x7F,
  41967. 0xEF,0xD6,0x00,0x08,0x5C,0x05,0x04,0x1E,
  41968. 0x9A,0xC6,0x8D,0xCC,0x19,0xD9,0x0B,0x06,
  41969. 0xCC,0x6A,0x17,0xE2,0x03,0x23,0xDB,0x1C,
  41970. 0xBC,0xA2,0xB9,0xA2,0x95,0x3C,0x73,0xD8,
  41971. 0xFF,0xE6,0x0E,0xAE,0x04,0xB2,0xFC,0x91,
  41972. 0x4F,0xEF,0x8A,0x58,0xB7,0x31,0x68,0x4C,
  41973. 0x1E,0xD0,0x5B,0x85,0xCC,0x03,0xDC,0xF4,
  41974. 0xAC,0xDB,0x03,0x9B,0x35,0x33,0x08,0x71,
  41975. 0xD0,0x50,0x8D,0xDC,0xE3,0x3A,0x98,0x40,
  41976. 0x41,0x80,0xDD,0x35,0xE1,0xA2,0xAF,0x14,
  41977. 0x9A,0xDB,0xD3,0x68,0x14,0xE2,0x50,0x7A,
  41978. 0x76,0x3F,0xE4,0xA4,0x1B,0xAA,0xC1,0x06,
  41979. 0x87,0x9A,0x92,0xF9,0xBE,0x9E,0x86,0x8C,
  41980. 0x92,0x1D,0x74,0xB1,0x7F,0x27,0x43,0xC0,
  41981. 0xEE,0x2E,0xC2,0x6C,0x6D,0xAA,0x0C,0x0E,
  41982. 0x71,0xC9,0x56,0xD6,0x3A,0x56,0xCB,0x90,
  41983. 0xD1,0x7E,0x6E,0x1C,0x6A,0x00,0x2D,0x02,
  41984. 0x2C,0x96,0xF0,0x2A,0x37,0x37,0x18,0x07,
  41985. 0x0B,0xF4,0xB4,0x8C,0x30,0xF2,0xA4,0xAB,
  41986. 0x66,0xFB,0x8B,0x22,0xC0,0x00,0x7E,0x05,
  41987. 0xB6,0xF9,0x95,0x49,0x33,0xA1,0xDC,0x97,
  41988. 0x0C,0x5C,0x61,0x46,0xE2,0xD7,0x87,0x4B,
  41989. 0xC4,0xC7,0x5F,0x26,0x06,0x84,0xD7,0x47,
  41990. 0x05,0xF1,0x33,0xFF,0x85,0x85,0xB2,0xBD,
  41991. 0x1F,0x44,0xC6,0xC2,0x7D,0x51,0xBE,0x0E,
  41992. 0xB5,0xC4,0x44,0x2F,0xFE,0x73,0x5F,0xF4,
  41993. 0xA4,0xEF,0xE2,0xF1,0x73,0x0B,0xEF,0x3E,
  41994. 0x2B,0xD7,0xCC,0x9F,0xDA,0x1A,0x7E,0x92,
  41995. 0x39,0xA1,0x55,0xBF,0x60,0x0A,0xDB,0x23,
  41996. 0x74,0xFE,0xE7,0x05,0x63,0xA9,0x85,0x52,
  41997. 0x9F,0xCC,0xC3,0xFF,0xF6,0x6C,0x1B,0x4E,
  41998. 0x4F,0x01,0xBD,0xC3,0xEB,0x37,0xEC,0x29,
  41999. 0x21,0x3B,0x2C,0xC9,0x2E,0x93,0x20,0x3E,
  42000. 0x19,0xC0,0x8B,0xE8,0x33,0xCD,0xC6,0x6A,
  42001. 0x6E,0x72,0x13,0x15,0xA1,0x90,0x20,0x0C,
  42002. 0x14,0x66,0xED,0xCC,0xA4,0xDD,0x7F,0x58,
  42003. 0x53,0xBC,0x4A,0x68,0xFC,0x86,0x3E,0xAA,
  42004. 0xF1,0x17,0x0F,0x3E,0x20,0x54,0x93,0xF4,
  42005. 0x98,0xBF,0xB4,0x07,0x05,0xBD,0x70,0xE7,
  42006. 0xD7,0x34,0xFD,0xE3,0x69,0xDF,0xCD,0xF5,
  42007. 0x1A,0x73,0x6E,0xC9,0x2B,0x21,0xFB,0xB8,
  42008. 0x7E,0x44,0x10,0x83,0x56,0xCE,0xD5,0x15,
  42009. 0x9A,0x75,0xFC,0x91,0x8E,0x6B,0x9E,0x1A,
  42010. 0x3A,0x33,0x39,0x35,0xB4,0x0D,0x74,0xF4,
  42011. 0xFB,0x4C,0x0E,0x37,0xFE,0x82,0x95,0x46,
  42012. 0x6B,0xD2,0x6E,0xEE,0xCD,0x4D,0x38,0xAF,
  42013. 0x0A,0xAA,0xF1,0xD5,0xA4,0x7C,0x04,0xD8,
  42014. 0xB9,0xDB,0x11,0x68,0x88,0x35,0x41,0xDE,
  42015. 0x31,0x33,0x0C,0xDC,0x2D,0x4C,0xA8,0x20,
  42016. 0xCC,0x2C,0x4C,0x63,0xAB,0xBA,0xDF,0x48,
  42017. 0x84,0xD5,0x25,0xBC,0x70,0xE3,0x49,0xAA,
  42018. 0x43,0xCA,0x8B,0xE7,0x9F,0xDD,0x20,0x76,
  42019. 0x9B,0x38,0xF4,0xBA,0x4D,0x4E,0x34,0x4A,
  42020. 0xAF,0x81,0xE7,0x0B,0xEC,0xE9,0x59,0xC1,
  42021. 0x35,0x22,0x7F,0x69,0x46,0x62,0xD2,0x18,
  42022. 0x6E,0x1F,0x79,0xD1,0xAD,0xC3,0x84,0x95,
  42023. 0x96,0xB2,0x18,0x58,0x5E,0x7E,0x0C,0x25,
  42024. 0x0A,0x0F,0x69,0xA3,0x1D,0xEC,0x29,0xCB,
  42025. 0xDA,0xA2,0xD1,0x1A,0x10,0xA5,0x52,0xC3,
  42026. 0x62,0x1E,0xC5,0x83,0xFF,0xA3,0x56,0xC2,
  42027. 0xFD,0x87,0x3B,0x57,0x52,0x98,0x36,0x95,
  42028. 0x77,0x6B,0xE5,0x49,0x10,0x8E,0x39,0xDD,
  42029. 0xCA,0x4B,0xB3,0x9F,0x4C,0x0C,0x11,0x62,
  42030. 0xF3,0x22,0x78,0xDB,0x48,0xEB,0x68,0xFE,
  42031. 0xE4,0x2A,0xE9,0xAA,0x8F,0x7A,0x2F,0x69,
  42032. 0xA5,0xC5,0x03,0x2D,0xEF,0x62,0xA8,0x71,
  42033. 0x65,0x06,0x40,0x84,0x10,0x0F,0xF2,0xED,
  42034. 0xBC,0x70,0x71,0x69,0x24,0xA2,0xBF,0x83,
  42035. 0x39,0xDD,0xFA,0xA2,0x7B,0xE5,0xEC,0x3D,
  42036. 0xFE,0x3B,0x52,0x6E,0x3D,0x82,0xA6,0x2A,
  42037. 0x86,0x01,0x61,0x51,0x63,0xBF,0xF9,0x0A,
  42038. 0x06,0x72,0xF1,0xD5,0x39,0x0C,0xBA,0xC9,
  42039. 0x78,0xC6,0x77,0x22,0xE4,0x96,0x6E,0xB1,
  42040. 0x48,0x62,0x84,0x62,0x2D,0xEA,0x49,0x56,
  42041. 0x50,0x86,0x3F,0x90,0xC3,0x01,0x42,0x45,
  42042. 0xED,0xE6,0x9A,0x65,0x19,0x93,0x7F,0x48,
  42043. 0x16,0xF2,0x50,0xA7,0x70,0xB3,0xF5,0xDB,
  42044. 0x0E,0x5E,0x22,0x9E,0x64,0x04,0x26,0x69,
  42045. 0xC1,0x16,0xEE,0x65,0x08,0x82,0x27,0x65,
  42046. 0xEC,0x3D,0xDF,0x51,0x5E,0x2D,0xE8,0x76,
  42047. 0xF2,0xE3,0xE4,0x24,0x04,0x88,0x06,0x0F,
  42048. 0xB2,0x7B,0x9B,0x72,0x3D,0x4C,0x7D,0x6A,
  42049. 0x1F,0xB2,0xA2,0xD2,0x35,0xD6,0x40,0x25,
  42050. 0xC2,0x0B,0x25,0xF9,0xDF,0x26,0xE4,0xDC,
  42051. 0xFB,0xB1,0x84,0x84,0x77,0x1B,0x45,0x51,
  42052. 0x60,0xD5,0xF0,0xB6,0x09,0xE6,0xBC,0xE3,
  42053. 0x1C,0x70,0x96,0x2C,0xD3,0x9D,0x7D,0x7F,
  42054. 0xB1,0x70,0xDA,0x79,0xB8,0x74,0x99,0xBF,
  42055. 0x84,0x95,0xCC,0x93,0xD7,0x51,0xDD,0x66,
  42056. 0xD3,0x70,0x0C,0x75,0x86,0x09,0x06,0xFD,
  42057. 0x66,0x14,0x80,0xCD,0xF3,0x59,0xB4,0x92,
  42058. 0x5F,0xE4,0xEE,0x00,0xA8,0xB0,0x8B,0x5C,
  42059. 0x3E,0xDB,0x8A,0x9C,0x0B,0xB5,0x99,0xC2,
  42060. 0x0D,0x81,0x09,0x06,0x6C,0x28,0xC0,0x7E,
  42061. 0xA5,0x07,0x70,0x64,0xD7,0x41,0xF4,0xC3,
  42062. 0x66,0x61,0x1C,0xA8,0x51,0xF6,0x3C,0xBA,
  42063. 0xE0,0x94,0xA3,0x11,0x8C,0x2E,0xBA,0x13,
  42064. 0xB2,0x47,0x48,0x93,0xB4,0x1A,0x2C,0x9A,
  42065. 0x6E,0x8E,0x30,0x66,0x7B,0xD3,0xBB,0x3B,
  42066. 0x5D,0x97,0x0D,0xE4,0xEA,0x24,0x28,0x9E,
  42067. 0xB4,0x88,0xCE,0x1D,0x7D,0x6F,0x39,0xB3,
  42068. 0x87,0x21,0xE5,0x08,0x93,0xF0,0xD4,0x9D,
  42069. 0x2D,0x91,0xC9,0xFD,0x0C,0x74,0x34,0xB4,
  42070. 0x1F,0xFE,0xDA,0xDC,0x10,0x5B,0x8D,0x2B,
  42071. 0x87,0xD3,0x42,0xB4,0xAE,0x32,0x9C,0xAE,
  42072. 0x4C,0x99,0xD8,0xED,0x44,0x41,0x07,0xE0,
  42073. 0x8F,0xBD,0xA5,0x7C,0x5A,0xDF,0x91,0x29,
  42074. 0x00,0xB5,0x4B,0xC3,0x3A,0x40,0x6C,0x48,
  42075. 0xAB,0x2A,0xF3,0x02,0xCB,0xB3,0x69,0xDA,
  42076. 0x06,0x0C,0x4D,0x5C,0x45,0xC3,0x28,0xAC,
  42077. 0x7A,0x01,0xD4,0xF8,0xCB,0x07,0x63,0x89,
  42078. 0x09,0x34,0x78,0xA7,0x14,0x39,0xCF,0x2D,
  42079. 0x94,0x8D,0x7A,0x4E,0x4E,0xBD,0xC4,0x32,
  42080. 0xAB,0x21,0xC9,0xDA,0x3F,0x5F,0x04,0x6B,
  42081. 0x14,0x40,0x18,0x18,0x2F,0xF9,0x46,0x17,
  42082. 0x57,0x54,0x9B,0x28,0x7B,0xBD,0xF9,0xA2,
  42083. 0x13,0xAC,0x69,0x24,0xB1,0x31,0x39,0xBF,
  42084. 0x8D,0x75,0xC3,0xFD,0x03,0x54,0x5A,0xFD,
  42085. 0xD4,0x7A,0xB7,0x56,0x4F,0x66,0x43,0x57,
  42086. 0x1B,0xFB,0xF9,0x92,0x7A,0x83,0xE6,0xFF,
  42087. 0xB4,0xBA,0x83,0xD2,0x61,0x8E,0x4A,0x82,
  42088. 0x82,0xA8,0xF5,0x0C,0xD2,0x43,0x53,0xA8,
  42089. 0x85,0x0A,0xD4,0x69,0x7B,0x04,0x71,0x3B,
  42090. 0x80,0x49,0x27,0x47,0x12,0xB6,0xB0,0xEA,
  42091. 0x90,0x0A,0xFA,0xA8,0xC8,0x78,0x61,0xDE,
  42092. 0x30,0x12,0xBB,0xDC,0xA6,0x57,0x56,0x30,
  42093. 0x6E,0xF1,0xA8,0x3B,0xF6,0x09,0x07,0xEA,
  42094. 0x31,0xE2,0x08,0x23,0x31,0x0F,0xD4,0x34,
  42095. 0xE3,0x60,0xC2,0x2B,0xDB,0x5A,0x99,0xCF,
  42096. 0xD4,0x6B,0x4E,0x75,0x65,0x35,0xE8,0x8B,
  42097. 0x93,0x7D,0xCA,0x11,0x47,0xF0,0x3E,0x11,
  42098. 0x5C,0xD1,0xEE,0x4B,0x11,0xB4,0x65,0x2B,
  42099. 0x6B,0x79,0xC0,0x86,0x60,0xA4,0x4B,0x24,
  42100. 0xA0,0x5C,0x70,0x34,0xC3,0x7C,0xE7,0x4F,
  42101. 0x97,0x89,0x4D,0xFE,0x22,0x89,0x3A,0xE9,
  42102. 0x07,0xB9,0x1A,0x86,0xB8,0x7A,0x12,0x38,
  42103. 0xE1,0x24,0x46,0xBC,0x9B,0x21,0xCD,0xAC,
  42104. 0x30,0xAB,0x98,0x21,0x31,0xC5,0x17,0x3F,
  42105. 0x1E,0x56,0xC3,0x18,0xCE,0xF0,0xA1,0xCC,
  42106. 0xFF,0x9D,0xA8,0x53,0xAF,0x74,0x77,0x54,
  42107. 0x02,0x9A,0x8F,0xA4,0xD4,0xBD,0xB2,0x1A,
  42108. 0xBA,0x52,0x2E,0x19,0xBE,0x49,0x11,0x45,
  42109. 0x02,0x01,0x7A,0xBF,0x28,0xD6,0x18,0xED,
  42110. 0xBD,0xCE,0xE4,0xDE,0xB5,0xF1,0x53,0x5D,
  42111. 0x65,0xF9,0x5F,0x83,0x8F,0x2D,0xF2,0x82,
  42112. 0xA0,0x2D,0x28,0xD3,0x0A,0x9E,0x0F,0x7F,
  42113. 0xC7,0xC4,0x43,0x7F,0xC3,0x0E,0x06,0xEB,
  42114. 0x4E,0xB4,0x2D,0xFA,0xDD,0x48,0xAB,0xF4,
  42115. 0x7D,0x41,0x48,0x33,0x5A,0xE6,0x70,0x02,
  42116. 0xE7,0x71,0x8D,0xD9,0x6B,0x0C,0x5A,0x8F,
  42117. 0xA4,0xC1,0xB7,0x4E,0x96,0x83,0xD6,0xA7,
  42118. 0x1D,0xF1,0x88,0xB3,0x6E,0xF4,0x12,0xA9,
  42119. 0xF6,0x31,0x69,0x66,0xFE,0xFE,0x02,0xF2,
  42120. 0x86,0x6D,0xBB,0x57,0x51,0x8C,0x4C,0xE9,
  42121. 0x7C,0x92,0x3E,0x3A,0xD3,0x2D,0xA8,0x82,
  42122. 0x53,0x84,0x26,0x89,0xBB,0xCC,0x13,0x12,
  42123. 0x3D,0x94,0xBB,0xDF,0x3D,0x4C,0xDF,0x27,
  42124. 0x9B,0x1F,0xB8,0xB6,0xE4,0xEA,0xA2,0x07,
  42125. 0xF8,0x4D,0x42,0x8F,0x29,0x90,0xFE,0x21,
  42126. 0x20,0xE9,0x55,0x02,0xAD,0x90,0xA7,0x77,
  42127. 0x4E,0x29,0xB6,0xD9,0x14,0x94,0xB2,0x25,
  42128. 0xA4,0xB2,0x0E,0x96,0x31,0xAB,0x9E,0x93,
  42129. 0x49,0xAC,0xA9,0xCB,0x68,0x22,0xBA,0xB8,
  42130. 0x57,0x5C,0x9D,0x65,0xC1,0xF1,0xFC,0x99,
  42131. 0x7C,0x3C,0xE9,0xEA,0x4B,0x29,0x22,0x2F,
  42132. 0xDB,0x17,0x21,0x8D,0xB0,0x13,0xBF,0xEE,
  42133. 0x7D,0xE4,0x8B,0x6D,0x17,0xE0,0x53,0x92,
  42134. 0x0B,0x32,0x6B,0xB1,0x65,0x2E,0xA7,0x83,
  42135. 0xFD,0x62,0x62,0xE3,0xAA,0x81,0xE8,0xD6,
  42136. 0xF7,0xB1,0x30,0x65,0x80,0x9F,0x77,0x1E,
  42137. 0x4A,0xEA,0xE8,0x45,0x32,0x12,0x3A,0xFB,
  42138. 0x22,0xE9,0xA9,0xF6,0xCB,0xAB,0xA8,0x0C,
  42139. 0x20,0xA8,0x7C,0xF9,0xF7,0x53,0xC1,0xB4,
  42140. 0xC0,0x5D,0x06,0x45,0xDD,0x7E,0xA7,0x34,
  42141. 0xA1,0x21,0xC2,0x62,0xAB,0x22,0x45,0x3D,
  42142. 0x73,0x4C,0x26,0xD1,0x1A,0xB2,0xF0,0xB2,
  42143. 0x6D,0x11,0x70,0x58,0xAA,0xF5,0xA4,0xF5,
  42144. 0xF8,0x0B,0x3D,0xC1,0xF6,0x17,0x70,0x15,
  42145. 0xCD,0x72,0x02,0x7E,0x4E,0x94,0x96,0x0A,
  42146. 0x56,0xCC,0xA5,0xA3,0xB3,0x7E,0xDD,0x5A,
  42147. 0x72,0xD2,0xFB,0xAC,0x3D,0x0E,0x66,0x65,
  42148. 0xE9,0x08,0x6C,0xB0,0x1C,0xE2,0x1A,0x82,
  42149. 0xF6,0xF3,0x34,0x89,0x73,0x02,0x5B,0x42,
  42150. 0x6D,0x40,0x61,0xB6,0xE0,0xE6,0x53,0x32,
  42151. 0xA5,0x72,0x17,0x4F,0x3B,0x51,0x4F,0xBC,
  42152. 0x00,0xE0,0x69,0x26,0xA9,0xAE,0x83,0xE3,
  42153. 0x73,0x7F,0x71,0x97,0xE0,0xDC,0x7C,0x63,
  42154. 0x9C,0x85,0x5F,0xDF,0x7D,0xE4,0x6C,0xD8,
  42155. 0xA9,0x3A,0x6F,0x5E,0x4A,0x2E,0xB0,0xE7,
  42156. 0x8B,0x45,0xE2,0x90,0x05,0x37,0xE8,0xAB,
  42157. 0x49,0x48,0x4C,0xC0,0x59,0x1D,0x8C,0x46,
  42158. 0x5B,0x84,0xE0,0x83,0xCE,0xEA,0x4B,0xF9,
  42159. 0xD4,0xDC,0x63,0xDF,0x79,0xB7,0x5C,0x11,
  42160. 0x25,0x7F,0x90,0x2E,0x0A,0x38,0x03,0xEA,
  42161. 0xEA,0xA1,0x26,0x52,0x20,0x19,0xA3,0xBE,
  42162. 0xFC,0x9D,0xB7,0x6E,0xA6,0x58,0x8E,0x6D,
  42163. 0xC5,0x58,0xE9,0xED,0x2F,0x55,0x43,0x8B,
  42164. 0x03,0x8B,0xE6,0xA4,0xC2,0x25,0x4B,0x36,
  42165. 0xBA,0xD3,0x27,0x48,0x40,0x2E,0x87,0xA2,
  42166. 0xD4,0x12,0xC6,0x05,0x36,0x03,0x11,0x51,
  42167. 0xD1,0xF2,0xAC,0x71,0x2C,0xB6,0xC3,0xA5,
  42168. 0x57,0x0F,0xAF,0x4B,0xBD,0xCD,0x47,0x4C,
  42169. 0x3A,0x52,0x6F,0x47,0xE7,0x0B,0xB7,0xD5,
  42170. 0xF7,0xA6,0x39,0x63,0x82,0x08,0x4C,0x41,
  42171. 0x0E,0x2A,0x52,0x42,0x5A,0xEA,0x59,0xC7,
  42172. 0x94,0xFB,0xD0,0x88,0x47,0x27,0xF6,0x97,
  42173. 0x03,0x9E,0x29,0xB8,0x3A,0x67,0xE6,0xF3,
  42174. 0x95,0xA7,0x42,0xC1,0x96,0xD1,0x9A,0xA6,
  42175. 0xF0,0x09,0x0C,0xEA,0xE0,0xAB,0x0F,0x15,
  42176. 0xE9,0xC3,0xEB,0xA5,0x89,0x86,0x98,0x32,
  42177. 0x83,0xAB,0x30,0x33,0xAE,0x90,0x8D,0x2E,
  42178. 0xB3,0xAA,0x91,0xA6,0xD9,0xA4,0x4A,0x54,
  42179. 0xE0,0xD3,0x08,0xCC,0x79,0xCE,0xE4,0x15,
  42180. 0x31,0xA6,0xCE,0x61,0xCF,0x03,0x06,0xEE,
  42181. 0x8E,0xE2,0x64,0x29,0xD1,0x54,0x9B,0xD0,
  42182. 0x5F,0x09,0x2B,0x8B,0xD5,0xF8,0xD4,0x7D,
  42183. 0xF1,0x97,0x32,0xD9,0xEA,0x5A,0x0E,0x10,
  42184. 0x8C,0x4D,0xFB,0x55,0xE6,0x27,0x0C,0xBA,
  42185. 0xC1,0x73,0xC1,0x73,0xE3,0x1C,0x09,0xB3,
  42186. 0x6F,0xB4,0x12,0xFA,0xF3,0x29,0xDC,0x23,
  42187. 0x32,0xED,0x80,0x87,0x83,0xC2,0xF6,0x07,
  42188. 0xB5,0xA9,0x22,0xDE,0x66,0x1A,0xA7,0x4A,
  42189. 0x86,0xF1,0x39,0x9B,0xF4,0xE7,0x50,0x15,
  42190. 0x4A,0x55,0x3C,0x93,0xB9,0xF9,0xFD,0xDC,
  42191. 0xB3,0x5D,0x73,0x52
  42192. };
  42193. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void)
  42194. {
  42195. XmssKey verifyKey;
  42196. unsigned char pub_raw[XMSS_SHA256_PUBLEN];
  42197. word32 pub_len = sizeof(pub_raw);
  42198. word32 pkSz = 0;
  42199. word32 sigSz = 0;
  42200. const char * param = "XMSS-SHA2_10_256";
  42201. int j = 0;
  42202. int ret2 = WC_TEST_RET_ENC_NC;
  42203. int ret = WC_TEST_RET_ENC_NC;
  42204. int n_diff = 0;
  42205. WOLFSSL_ENTER("xmss_test_verify_only");
  42206. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42207. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42208. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42209. ret = wc_XmssKey_SetParamStr(&verifyKey, param);
  42210. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42211. ret = wc_XmssKey_GetPubLen(&verifyKey, &pkSz);
  42212. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42213. if (pkSz != XMSS_SHA256_PUBLEN) {
  42214. return WC_TEST_RET_ENC_EC(pkSz);
  42215. }
  42216. ret = wc_XmssKey_GetSigLen(&verifyKey, &sigSz);
  42217. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42218. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  42219. fprintf(stderr, "param: %s\n", param);
  42220. fprintf(stderr, "pkSz: %d\n", pkSz);
  42221. fprintf(stderr, "sigSz: %d\n", sigSz);
  42222. #endif
  42223. if (sigSz != sizeof(xmss_sig)) {
  42224. return WC_TEST_RET_ENC_EC(sigSz);
  42225. }
  42226. ret = wc_XmssKey_ImportPubRaw(&verifyKey, xmss_pub, XMSS_SHA256_PUBLEN);
  42227. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42228. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42229. (byte *) xmss_msg, sizeof(xmss_msg));
  42230. if (ret != 0) {
  42231. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  42232. return WC_TEST_RET_ENC_EC(ret);
  42233. }
  42234. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42235. ret = wc_XmssKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42236. if (ret != 0) {
  42237. printf("error: wc_XmssKey_ExportPubRaw returned %d, expected 0\n", ret);
  42238. return WC_TEST_RET_ENC_EC(ret);
  42239. }
  42240. if (pub_len != XMSS_SHA256_PUBLEN) {
  42241. printf("error: xmss pub len %u, expected %d\n", pub_len,
  42242. XMSS_SHA256_PUBLEN);
  42243. return WC_TEST_RET_ENC_EC(pub_len);
  42244. }
  42245. n_diff = XMEMCMP(pub_raw, xmss_pub, sizeof(xmss_pub));
  42246. if (n_diff != 0) {
  42247. printf("error: exported and imported pub raw do not match: %d\n",
  42248. n_diff);
  42249. return WC_TEST_RET_ENC_EC(n_diff);
  42250. }
  42251. /* Flip bits in message. This should fail. */
  42252. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  42253. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42254. (byte *) xmss_msg, sizeof(xmss_msg));
  42255. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42256. printf("error: wc_XmssKey_Verify returned %d, expected -1\n", ret2);
  42257. return WC_TEST_RET_ENC_EC(ret2);
  42258. }
  42259. /* Flip it back. This should pass again. */
  42260. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  42261. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42262. (byte *) xmss_msg, sizeof(xmss_msg));
  42263. if (ret != 0) {
  42264. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  42265. return WC_TEST_RET_ENC_EC(ret);
  42266. }
  42267. /* Flip bits in a few places throughout the signature, stepping in multiple
  42268. * of hash size. These should all fail with -1. */
  42269. for (j = 0; j < (int) sizeof(xmss_sig); j+= 4 * 32) {
  42270. xmss_sig[j] ^= 1;
  42271. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42272. (byte *) xmss_msg, sizeof(xmss_msg));
  42273. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42274. /* Verify passed when it should have failed. */
  42275. return WC_TEST_RET_ENC_I(j);
  42276. }
  42277. /* Flip this spot back. */
  42278. xmss_sig[j] ^= 1;
  42279. }
  42280. /* Cleanup everything. */
  42281. wc_XmssKey_Free(&verifyKey);
  42282. return ret;
  42283. }
  42284. #endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_SMALL_STACK &&
  42285. * WOLFSSL_XMSS_MIN_HEIGHT <= 10 */
  42286. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  42287. static int lms_write_key_mem(const byte * priv, word32 privSz, void *context)
  42288. {
  42289. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  42290. * BE USED FOR TESTING PURPOSES! Production applications should
  42291. * write only to non-volatile storage. */
  42292. XMEMCPY(context, priv, privSz);
  42293. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  42294. }
  42295. static int lms_read_key_mem(byte * priv, word32 privSz, void *context)
  42296. {
  42297. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  42298. * BE USED FOR TESTING PURPOSES! */
  42299. XMEMCPY(priv, context, privSz);
  42300. return WC_LMS_RC_READ_TO_MEMORY;
  42301. }
  42302. /* LMS signature sizes are a function of their parameters. This
  42303. * test has a signature of 8688 bytes. */
  42304. #ifndef WOLFSSL_NO_LMS_SHA256_256
  42305. #define WC_TEST_LMS_SIG_LEN (8688)
  42306. #else
  42307. #define WC_TEST_LMS_SIG_LEN (4984)
  42308. #endif
  42309. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
  42310. {
  42311. int i = 0;
  42312. int j = 0;
  42313. int ret = WC_TEST_RET_ENC_NC;
  42314. int ret2 = WC_TEST_RET_ENC_NC;
  42315. int sigsLeft = 0;
  42316. LmsKey signingKey;
  42317. LmsKey verifyKey;
  42318. WC_RNG rng;
  42319. word32 sigSz = 0;
  42320. const char * msg = "LMS HSS post quantum signature test";
  42321. word32 msgSz = (word32) XSTRLEN(msg);
  42322. unsigned char priv[HSS_MAX_PRIVATE_KEY_LEN];
  42323. unsigned char old_priv[HSS_MAX_PRIVATE_KEY_LEN];
  42324. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42325. byte * sig = (byte*)XMALLOC(WC_TEST_LMS_SIG_LEN, HEAP_HINT,
  42326. DYNAMIC_TYPE_TMP_BUFFER);
  42327. if (sig == NULL) {
  42328. return WC_TEST_RET_ENC_ERRNO;
  42329. }
  42330. #else
  42331. byte sig[WC_TEST_LMS_SIG_LEN];
  42332. #endif
  42333. WOLFSSL_ENTER("lms_test");
  42334. XMEMSET(priv, 0, sizeof(priv));
  42335. XMEMSET(old_priv, 0, sizeof(old_priv));
  42336. XMEMSET(sig, 0, WC_TEST_LMS_SIG_LEN);
  42337. #ifndef HAVE_FIPS
  42338. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  42339. #else
  42340. ret = wc_InitRng(&rng);
  42341. #endif
  42342. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42343. /* This test:
  42344. * levels: 1
  42345. * height: 5
  42346. * winternitz: 1
  42347. *
  42348. * max sigs: 2 ** (1 * 5) = 32
  42349. * signature length: 8688
  42350. */
  42351. ret = wc_LmsKey_Init(&signingKey, NULL, INVALID_DEVID);
  42352. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42353. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42354. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42355. ret = wc_LmsKey_SetParameters(&signingKey, 1, 5, 1);
  42356. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42357. ret = wc_LmsKey_SetWriteCb(&signingKey, lms_write_key_mem);
  42358. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42359. ret = wc_LmsKey_SetReadCb(&signingKey, lms_read_key_mem);
  42360. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42361. ret = wc_LmsKey_SetContext(&signingKey, (void *) priv);
  42362. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42363. ret = wc_LmsKey_MakeKey(&signingKey, &rng);
  42364. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42365. XMEMCPY(old_priv, priv, sizeof(priv));
  42366. ret = wc_LmsKey_ExportPub(&verifyKey, &signingKey);
  42367. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42368. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42369. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42370. if (sigSz != WC_TEST_LMS_SIG_LEN) {
  42371. printf("error: got %u, expected %d\n", sigSz, WC_TEST_LMS_SIG_LEN);
  42372. return WC_TEST_RET_ENC_EC(sigSz);
  42373. }
  42374. /* 2 ** 5 should be the max number of signatures */
  42375. for (i = 0; i < 32; ++i) {
  42376. /* We should have remaining signstures. */
  42377. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42378. if (sigsLeft == 0) {
  42379. return WC_TEST_RET_ENC_EC(sigsLeft);
  42380. }
  42381. /* Sign with key. The private key will be updated on every signature. */
  42382. ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  42383. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42384. /* The updated private key should not match the old one. */
  42385. if (XMEMCMP(old_priv, priv, sizeof(priv)) == 0) {
  42386. printf("error: current priv key should not match old: %d\n", i);
  42387. return WC_TEST_RET_ENC_I(i);
  42388. }
  42389. XMEMCPY(old_priv, priv, sizeof(priv));
  42390. ret = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  42391. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42392. /* Flip bits in a few places throughout the signature, stepping in multiple
  42393. * of hash size. These should all fail with -1. */
  42394. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42395. sig[j] ^= 1;
  42396. ret2 = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  42397. msgSz);
  42398. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42399. /* Verify passed when it should have failed. */
  42400. return WC_TEST_RET_ENC_I(j);
  42401. }
  42402. /* Flip this spot back. */
  42403. sig[j] ^= 1;
  42404. }
  42405. }
  42406. /* This should be the last signature. */
  42407. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42408. if (sigsLeft != 0) {
  42409. return WC_TEST_RET_ENC_EC(sigsLeft);
  42410. }
  42411. wc_LmsKey_Free(&signingKey);
  42412. wc_LmsKey_Free(&verifyKey);
  42413. wc_FreeRng(&rng);
  42414. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42415. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42416. #endif
  42417. return ret;
  42418. }
  42419. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  42420. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK)
  42421. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  42422. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  42423. /* A simple LMS verify only test.
  42424. *
  42425. * Note: LMS signature sizes are a function of their parameters. This
  42426. * test has a signature of 1456 bytes:
  42427. * levels: 1
  42428. * height: 10
  42429. * winternitz: 8
  42430. * max sigs: 2 ** (1 * 10) = 1024
  42431. * signature length: 1456
  42432. * */
  42433. /* "wolfSSL LMS example message!" without null terminator. */
  42434. static byte lms_msg[28] =
  42435. {
  42436. 0x77,0x6F,0x6C,0x66,0x53,0x53,0x4C,0x20,
  42437. 0x4C,0x4D,0x53,0x20,0x65,0x78,0x61,0x6D,
  42438. 0x70,0x6C,0x65,0x20,0x6D,0x65,0x73,0x73,
  42439. 0x61,0x67,0x65,0x21
  42440. };
  42441. static const byte lms_L1H10W8_pub[HSS_MAX_PUBLIC_KEY_LEN] =
  42442. {
  42443. 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,
  42444. 0x00,0x00,0x00,0x04,0xA1,0x26,0x76,0xF8,
  42445. 0xBB,0x0B,0xC0,0x82,0x21,0x71,0x0B,0x2E,
  42446. 0x8C,0xA6,0xEF,0x12,0xED,0x41,0x0E,0x8C,
  42447. 0xAF,0x11,0x93,0x34,0x7B,0x49,0x79,0xB7,
  42448. 0xDE,0x63,0x1C,0xFE,0x1F,0xD1,0x17,0x49,
  42449. 0xCD,0x5C,0xD4,0x26,0xA0,0x53,0x26,0x1A,
  42450. 0xC5,0xB4,0x8F,0x23
  42451. };
  42452. #define LMS_L1H10W8_SIGLEN (1456)
  42453. static byte lms_L1H10W8_sig[LMS_L1H10W8_SIGLEN] =
  42454. {
  42455. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  42456. 0x00,0x00,0x00,0x04,0x18,0x70,0x09,0x2E,
  42457. 0x21,0xC9,0x6A,0xC9,0x5C,0xB6,0xB0,0xAA,
  42458. 0xC3,0xED,0x6E,0x66,0x2F,0xCC,0x45,0x81,
  42459. 0xBC,0xBA,0x44,0x96,0x1C,0xBF,0x4E,0xFB,
  42460. 0x7A,0x46,0xFB,0xBE,0x9A,0x0C,0xE4,0x50,
  42461. 0x90,0xC7,0x92,0xAC,0x53,0xAE,0x53,0x76,
  42462. 0x29,0xA6,0x65,0xF1,0x09,0xED,0x1A,0x8E,
  42463. 0x03,0x2E,0x5A,0x06,0x51,0xE3,0x1E,0xE6,
  42464. 0xF6,0xFE,0x3A,0x6E,0xD1,0x92,0x31,0x1D,
  42465. 0xA1,0x6A,0x5C,0x30,0x3A,0xC7,0xFD,0x5B,
  42466. 0xFE,0x71,0x2C,0x5C,0x2F,0x5B,0x5B,0xCF,
  42467. 0xBC,0x7F,0xBF,0x6C,0xAF,0x44,0x8A,0xAE,
  42468. 0x14,0x60,0xAB,0x88,0xED,0x0E,0x4F,0xF8,
  42469. 0xC7,0x1B,0x74,0x28,0x72,0xB3,0x96,0xA6,
  42470. 0xE6,0x46,0x22,0x82,0xCF,0x1F,0x4D,0xA6,
  42471. 0xEA,0x22,0x06,0x07,0x52,0xF5,0x26,0x16,
  42472. 0x0B,0x90,0xE3,0xFF,0x64,0xA9,0xE4,0x61,
  42473. 0x1E,0x9C,0x12,0x9C,0xF6,0xD4,0x63,0x29,
  42474. 0xEA,0x02,0xF7,0x18,0x52,0x79,0x6C,0x43,
  42475. 0xDC,0xCF,0x43,0x23,0xB9,0xCC,0x4A,0x25,
  42476. 0x9D,0x10,0xAF,0xA3,0xE6,0x47,0x5A,0x1C,
  42477. 0xFE,0x68,0x89,0xAF,0x1B,0x2D,0x88,0x3E,
  42478. 0xCA,0xDC,0x70,0xEA,0xAC,0x11,0x00,0x8A,
  42479. 0x6E,0xE0,0xC7,0xD0,0xD2,0x1A,0x36,0x18,
  42480. 0x97,0xB3,0x5F,0x0E,0x75,0x48,0x28,0xF8,
  42481. 0xA8,0xF5,0x90,0xD1,0xA1,0x84,0xFB,0xA4,
  42482. 0xAD,0x50,0xBE,0xE9,0x39,0x8C,0xC5,0xA1,
  42483. 0x67,0x51,0xA1,0x8C,0xD6,0x6B,0x97,0x1F,
  42484. 0x47,0x99,0xEE,0xE0,0x70,0x01,0xC7,0x07,
  42485. 0x50,0xF3,0x5E,0x3F,0xE7,0x06,0xD6,0x8D,
  42486. 0x26,0xD6,0x5A,0x59,0x18,0x72,0x6B,0x12,
  42487. 0xD2,0xAF,0x9B,0xB4,0x2B,0xD0,0xB2,0xF2,
  42488. 0x96,0x2F,0x40,0xEA,0xBE,0xE6,0xAC,0x1F,
  42489. 0xB8,0x33,0xC2,0x76,0xDC,0x8C,0xAC,0xC1,
  42490. 0x46,0x5E,0x04,0x84,0x1B,0xC8,0xB9,0x65,
  42491. 0x8D,0xAD,0x96,0xB5,0xB1,0xF6,0x17,0x4A,
  42492. 0x19,0x87,0xE7,0xBF,0x29,0xC7,0x9B,0xB9,
  42493. 0xD6,0x11,0x2C,0x92,0x2F,0xB7,0x24,0xD5,
  42494. 0x01,0x1D,0x80,0x37,0x54,0xED,0x33,0x32,
  42495. 0xAB,0x7A,0x12,0xD4,0x02,0x1D,0x27,0x52,
  42496. 0x89,0xDB,0x32,0xBF,0x61,0xD4,0xBB,0xB4,
  42497. 0x46,0x78,0x1B,0x64,0x17,0x84,0x4B,0x8A,
  42498. 0xBA,0xC6,0xC1,0xCF,0xC7,0x5D,0x8F,0x93,
  42499. 0xC5,0x9A,0x27,0x90,0xAC,0x17,0x98,0xFF,
  42500. 0xC8,0x22,0x59,0x55,0x90,0xB2,0x29,0x39,
  42501. 0xA0,0xBE,0x00,0x23,0x55,0x6B,0xDA,0x83,
  42502. 0xD8,0x5B,0x57,0x7C,0x67,0x1B,0xC3,0x6B,
  42503. 0x6D,0xC7,0x9B,0x2B,0x9E,0xB7,0x95,0xB3,
  42504. 0xF0,0x1B,0x89,0x5A,0xD7,0x4B,0x67,0xAF,
  42505. 0xDC,0x9E,0xCF,0x7E,0x1A,0xBA,0x1B,0xB9,
  42506. 0x3B,0x7A,0xDD,0x3F,0x0D,0xEE,0x4C,0x0B,
  42507. 0xD1,0x4F,0x34,0xF2,0x93,0xF7,0x21,0x64,
  42508. 0x2C,0x07,0x00,0x15,0x4F,0xE3,0x6A,0x9F,
  42509. 0x08,0x52,0xC2,0x65,0x47,0x1F,0x34,0x64,
  42510. 0x66,0x07,0xBC,0xEA,0xAF,0x9B,0xAA,0x39,
  42511. 0x15,0x8B,0x08,0x8C,0x24,0x41,0x9B,0x46,
  42512. 0x1B,0x5B,0x91,0x11,0xC4,0xFD,0xA9,0x88,
  42513. 0x35,0x0E,0x7D,0xAF,0xFD,0xB7,0x90,0x7E,
  42514. 0xD7,0x29,0x02,0x0A,0xDC,0xC8,0x3F,0xC0,
  42515. 0xFD,0x97,0xAF,0x50,0x49,0xA6,0x5E,0x12,
  42516. 0xC1,0xCD,0xEC,0x52,0xC5,0x51,0xF2,0x80,
  42517. 0x17,0x61,0xC7,0x7E,0xBE,0xD1,0x1B,0x65,
  42518. 0xA4,0xAB,0x92,0x8D,0x89,0xB2,0xC5,0x8F,
  42519. 0xFF,0xA5,0x6F,0xFA,0x62,0x75,0xE4,0xA1,
  42520. 0xD4,0x22,0xA8,0x9E,0x40,0x04,0x27,0x1F,
  42521. 0xCC,0x81,0xBA,0x28,0x67,0xA0,0x1C,0x80,
  42522. 0xEB,0xCA,0xB0,0x61,0xA5,0x48,0xD0,0x8A,
  42523. 0x25,0xEB,0x9E,0x67,0x8C,0x8E,0x9B,0xD1,
  42524. 0xAD,0xBB,0xC3,0xEA,0xD3,0xD4,0xC5,0x12,
  42525. 0x7B,0xDD,0x00,0x57,0x7F,0xF6,0xF7,0xF6,
  42526. 0x3C,0x05,0xCF,0xFC,0x12,0xE1,0x93,0x05,
  42527. 0xE5,0x9B,0x79,0x87,0x69,0xD8,0x82,0xD9,
  42528. 0xD7,0x1D,0x41,0x73,0xE4,0x52,0x1D,0x3E,
  42529. 0xE5,0x8C,0x8D,0x34,0xE1,0x75,0xA9,0xF1,
  42530. 0x9D,0x09,0xA2,0x5B,0xEF,0xDA,0x96,0x6E,
  42531. 0x76,0x3D,0xEA,0x50,0xD9,0xCF,0x4F,0xAC,
  42532. 0xAD,0x1D,0x35,0x72,0x1B,0x88,0x8B,0xCD,
  42533. 0x8C,0x8A,0x8A,0xE0,0x96,0x04,0xD8,0xBB,
  42534. 0x28,0x43,0x16,0x77,0x60,0x98,0x63,0xF9,
  42535. 0xB9,0x71,0x46,0xB7,0xE1,0xA7,0xA9,0x84,
  42536. 0xC3,0x65,0x82,0xE1,0x1B,0x67,0x04,0x2D,
  42537. 0x55,0x6B,0xF9,0xC0,0x79,0x09,0x09,0xE7,
  42538. 0xFD,0x06,0x4D,0x09,0x9B,0x1A,0xCE,0x35,
  42539. 0xFA,0x27,0x6F,0x2F,0x01,0x65,0x0D,0xA0,
  42540. 0x97,0x59,0x11,0xF0,0x48,0xD2,0xE7,0x46,
  42541. 0xBE,0xB4,0x0A,0xA3,0xE2,0x75,0x0E,0x09,
  42542. 0x94,0xD9,0x69,0x28,0xD4,0xDA,0x64,0xBA,
  42543. 0xFE,0xA4,0xB9,0xF0,0xBA,0xEB,0xBA,0xAC,
  42544. 0xA8,0xF9,0xD3,0x82,0x4C,0x36,0x80,0xFA,
  42545. 0xE5,0xF6,0x76,0xC3,0x80,0xFA,0x90,0x29,
  42546. 0xF4,0x85,0xA4,0xC6,0x25,0x22,0x79,0x7E,
  42547. 0x39,0x1E,0x30,0xB8,0x65,0x72,0xCF,0xE1,
  42548. 0x99,0xF0,0x75,0xE8,0x09,0xB4,0x92,0x96,
  42549. 0x1B,0x68,0x50,0x88,0xF1,0x2C,0x97,0xE3,
  42550. 0x2D,0x26,0x8F,0xC5,0x30,0xCF,0x24,0xCB,
  42551. 0xB2,0x60,0x77,0xDC,0x02,0x72,0x0D,0xD9,
  42552. 0x2E,0xF2,0x52,0xEA,0x00,0xF6,0x32,0x65,
  42553. 0xA5,0xC6,0x43,0x29,0x29,0x69,0xAB,0x27,
  42554. 0x0C,0x39,0xDF,0x76,0x3E,0x93,0x95,0xB1,
  42555. 0x2C,0xA2,0x0D,0x18,0xCE,0xA0,0x97,0x10,
  42556. 0x3C,0x90,0xC0,0xEF,0x0E,0x04,0xA6,0xC8,
  42557. 0xA0,0x21,0x3C,0x0B,0x22,0x77,0x7A,0x66,
  42558. 0xA5,0x90,0x25,0xA4,0x09,0x3E,0xD5,0x27,
  42559. 0x1F,0x6C,0x99,0x85,0x5C,0xA2,0x99,0x7A,
  42560. 0x25,0xEE,0x8D,0x32,0x3D,0xD3,0xDC,0xF5,
  42561. 0x00,0x5A,0x34,0x61,0xB6,0xCD,0x4E,0xBC,
  42562. 0x26,0x36,0xFB,0x44,0x97,0x35,0xBD,0x06,
  42563. 0x7D,0x2E,0x4A,0xA2,0xDC,0x24,0xFE,0x70,
  42564. 0x0A,0xF9,0x57,0xE3,0xEE,0xAB,0xD1,0x17,
  42565. 0xF3,0x7C,0xD6,0x37,0x26,0xFA,0x83,0x9F,
  42566. 0xDD,0xB2,0xE1,0xD7,0xF9,0xC7,0x0E,0x15,
  42567. 0x01,0xA6,0x58,0x32,0x98,0x04,0x32,0xD4,
  42568. 0xDE,0xB9,0xEF,0x09,0xFA,0xE4,0x5A,0xD7,
  42569. 0xDD,0x09,0x1C,0xC9,0xAC,0xB8,0x6A,0xF5,
  42570. 0x00,0x5D,0x6B,0x95,0x12,0x8C,0x2F,0xCC,
  42571. 0xD8,0xB9,0x50,0x3A,0xEB,0x74,0x86,0xD2,
  42572. 0x3F,0xA1,0x05,0x8F,0x6E,0xEF,0xF5,0xA4,
  42573. 0xD6,0x6E,0x53,0xFA,0x9E,0xFA,0xCE,0xDB,
  42574. 0x99,0x46,0xE7,0xC5,0xDA,0x92,0x51,0x4F,
  42575. 0x22,0x07,0xF3,0xA5,0x38,0x26,0xD3,0xEC,
  42576. 0xD6,0x01,0xDD,0x31,0x3A,0x48,0x93,0xF6,
  42577. 0x69,0x4F,0xD8,0xF6,0xC2,0x91,0xA5,0x7C,
  42578. 0xDF,0x51,0x64,0xF1,0x3B,0x79,0xBC,0x0A,
  42579. 0x2C,0xDC,0x33,0x5A,0x29,0xF6,0xB2,0x09,
  42580. 0x66,0xCA,0x24,0x9F,0x1A,0x18,0xF3,0x76,
  42581. 0x4C,0x5E,0x0B,0x81,0x7F,0x29,0x84,0xD8,
  42582. 0x7A,0xA8,0xD6,0x11,0xAC,0xEC,0xD9,0x07,
  42583. 0x91,0xEC,0xB6,0x6D,0xEC,0xDB,0xBE,0x6F,
  42584. 0x9F,0xC5,0x19,0x5E,0x56,0x87,0x20,0x80,
  42585. 0x75,0xD5,0x64,0xE9,0x80,0xBF,0x2D,0xD5,
  42586. 0x94,0x9F,0x8C,0xA4,0x54,0x41,0xAB,0xB1,
  42587. 0x8E,0xAD,0x51,0xE4,0x3C,0x24,0xF7,0x1D,
  42588. 0xFE,0x02,0x48,0x7C,0x6D,0xED,0xF1,0xAC,
  42589. 0xD9,0x79,0x42,0xE5,0x3A,0xCF,0x6A,0x4C,
  42590. 0x6D,0xE2,0x13,0xD2,0x2B,0x9D,0xAB,0x1F,
  42591. 0x70,0xD3,0xC0,0x6F,0x81,0xE9,0x9A,0x86,
  42592. 0x33,0x39,0x60,0xE7,0x6A,0x00,0x1F,0x97,
  42593. 0xEB,0xE5,0x1D,0x0D,0x66,0x15,0xC9,0xA2,
  42594. 0xB1,0xC0,0xF0,0x2E,0xF4,0x07,0xA2,0x2E,
  42595. 0x49,0x92,0x95,0x13,0xA3,0x18,0x46,0x25,
  42596. 0xB9,0x3C,0xA1,0x4B,0x00,0x00,0x00,0x06,
  42597. 0xAB,0xAA,0xF9,0x3F,0x7E,0x21,0xF4,0x0E,
  42598. 0xCE,0xFD,0xE0,0x44,0xAC,0xC7,0x1A,0x30,
  42599. 0x22,0x9D,0x0A,0xD7,0x96,0x2D,0x8F,0x9A,
  42600. 0x99,0x1F,0x40,0x75,0x7F,0x62,0xF9,0xC1,
  42601. 0x81,0x7B,0x4A,0x1B,0xFA,0xD6,0x87,0xB9,
  42602. 0xEF,0x58,0x48,0xE4,0x5C,0x79,0xE5,0xB1,
  42603. 0x2C,0x59,0xA4,0x42,0xDB,0xA6,0x53,0x70,
  42604. 0x80,0x61,0x17,0xD4,0xD3,0x77,0xBD,0x53,
  42605. 0x26,0x7C,0x0E,0x0E,0xFF,0x30,0x4B,0xD0,
  42606. 0x86,0xFC,0x02,0x20,0x24,0x46,0x5B,0xF5,
  42607. 0xE3,0x99,0x73,0x85,0x60,0x00,0x36,0x47,
  42608. 0x17,0xEE,0x0C,0xD2,0x80,0x71,0x46,0x0E,
  42609. 0x2B,0xB0,0xEF,0x7F,0xFE,0x3B,0xE5,0xE1,
  42610. 0x87,0xC2,0xAF,0x1A,0x6F,0x63,0xF4,0x5A,
  42611. 0xC4,0x16,0xF7,0xAD,0x07,0x70,0x71,0x85,
  42612. 0x7D,0x3D,0x67,0x08,0xB8,0xD8,0xE2,0xF0,
  42613. 0xA1,0xAC,0xD2,0x94,0x7D,0x93,0x03,0xDD,
  42614. 0x54,0xF9,0x64,0x19,0xB3,0xED,0x24,0x22,
  42615. 0x01,0xD7,0x12,0x5E,0xC1,0x2B,0x39,0x10,
  42616. 0x13,0xE2,0x56,0x1C,0xEE,0xF4,0x2A,0x49,
  42617. 0x7B,0xFB,0x36,0x8D,0xF8,0xAF,0x60,0xDF,
  42618. 0x10,0xF0,0x72,0xA2,0xED,0xB6,0x53,0x88,
  42619. 0xA9,0x0C,0xED,0x9C,0x18,0x33,0x7D,0x65,
  42620. 0x9B,0xB2,0x9C,0x3E,0xE9,0x1E,0x43,0x51,
  42621. 0x7E,0xBE,0x01,0x95,0xF6,0x60,0x65,0xBE,
  42622. 0xD1,0xF4,0xE2,0x83,0x6B,0xCA,0x7A,0x70,
  42623. 0x41,0x83,0x72,0xC0,0x23,0x51,0x13,0x11,
  42624. 0x2D,0xF9,0xC0,0x0D,0x7D,0x73,0x76,0xA5,
  42625. 0x30,0x83,0x68,0x10,0x35,0xA2,0x18,0x22,
  42626. 0x4E,0x21,0x93,0x27,0x6A,0x19,0x28,0x83,
  42627. 0x7F,0xDD,0xDD,0xFF,0xC3,0x8A,0x64,0x00,
  42628. 0x5F,0x1C,0x0D,0xF8,0xBB,0xD7,0x15,0xB9,
  42629. 0xEF,0xE0,0x07,0x62,0x05,0x9E,0xCF,0xFC,
  42630. 0x08,0x52,0x1E,0x65,0x41,0x56,0x6A,0xEB,
  42631. 0x81,0x53,0x30,0x7B,0xF2,0xFD,0x65,0xFF,
  42632. 0xA2,0x14,0xF5,0x62,0x1E,0x24,0x48,0x47,
  42633. 0xA5,0x41,0x80,0xB4,0xC5,0xDC,0xB2,0xB4,
  42634. 0x2D,0x17,0xE7,0xBE,0x49,0x53,0x7A,0x25,
  42635. 0xC5,0x0D,0x19,0x59,0xF4,0x88,0x59,0xED,
  42636. 0x92,0x13,0xEE,0x7A,0x4F,0x12,0x98,0x4C
  42637. };
  42638. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
  42639. {
  42640. LmsKey verifyKey;
  42641. unsigned char pub_raw[HSS_MAX_PUBLIC_KEY_LEN];
  42642. word32 pub_len = sizeof(pub_raw);
  42643. word32 sigSz = 0;
  42644. word32 msgSz = sizeof(lms_msg);
  42645. word32 pubSz = 0;
  42646. int levels = 0;
  42647. int height = 0;
  42648. int winternitz = 0;
  42649. int ret = WC_TEST_RET_ENC_NC;
  42650. int ret2 = WC_TEST_RET_ENC_NC;
  42651. int j = 0;
  42652. int n_diff = 0;
  42653. WOLFSSL_ENTER("lms_test_verify_only");
  42654. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42655. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42656. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42657. ret = wc_LmsKey_SetParameters(&verifyKey, 1, 10, 8);
  42658. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42659. ret = wc_LmsKey_ImportPubRaw(&verifyKey, lms_L1H10W8_pub,
  42660. HSS_MAX_PUBLIC_KEY_LEN);
  42661. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42662. /* Verify parameters, pub length, and sig length are correct. */
  42663. ret = wc_LmsKey_GetParameters(&verifyKey, &levels, &height, &winternitz);
  42664. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42665. if (levels != 1 || height != 10 || winternitz != 8) {
  42666. printf("error: invalid LMS parameters: L%d-H%d-W%d\n", levels, height,
  42667. winternitz);
  42668. return WC_TEST_RET_ENC_NC;
  42669. }
  42670. ret = wc_LmsKey_GetPubLen(&verifyKey, &pubSz);
  42671. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42672. if (pubSz != HSS_MAX_PUBLIC_KEY_LEN) {
  42673. printf("error: got %u, expected %d\n", pubSz, HSS_MAX_PUBLIC_KEY_LEN);
  42674. return WC_TEST_RET_ENC_EC(pubSz);
  42675. }
  42676. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42677. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42678. if (sigSz != LMS_L1H10W8_SIGLEN) {
  42679. printf("error: got %u, expected %d\n", sigSz, LMS_L1H10W8_SIGLEN);
  42680. return WC_TEST_RET_ENC_EC(sigSz);
  42681. }
  42682. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42683. (byte *) lms_msg, msgSz);
  42684. if (ret != 0) {
  42685. printf("error: wc_LmsKey_Verify returned %d\n", ret);
  42686. return WC_TEST_RET_ENC_EC(ret);
  42687. }
  42688. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42689. ret = wc_LmsKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42690. if (ret != 0) {
  42691. printf("error: wc_LmsKey_ExportPubRaw returned %d, expected 0\n", ret);
  42692. return WC_TEST_RET_ENC_EC(ret);
  42693. }
  42694. if (pub_len != HSS_MAX_PUBLIC_KEY_LEN) {
  42695. printf("error: LMS pub len %u, expected %d\n", pub_len,
  42696. HSS_MAX_PUBLIC_KEY_LEN);
  42697. return WC_TEST_RET_ENC_EC(pub_len);
  42698. }
  42699. n_diff = XMEMCMP(pub_raw, lms_L1H10W8_pub, sizeof(lms_L1H10W8_pub));
  42700. if (n_diff != 0) {
  42701. printf("error: exported and imported pub raw do not match: %d\n",
  42702. n_diff);
  42703. return WC_TEST_RET_ENC_EC(n_diff);
  42704. }
  42705. /* Flip bits in message. This should fail. */
  42706. lms_msg[msgSz / 2] ^= 1;
  42707. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42708. (byte *) lms_msg, msgSz);
  42709. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42710. printf("error: wc_LmsKey_Verify returned %d, expected -1\n", ret2);
  42711. return WC_TEST_RET_ENC_EC(ret);
  42712. }
  42713. /* Flip it back. This should pass again. */
  42714. lms_msg[msgSz / 2] ^= 1;
  42715. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42716. (byte *) lms_msg, msgSz);
  42717. if (ret != 0) {
  42718. printf("error: wc_LmsKey_Verify returned %d, expected 0\n", ret);
  42719. return WC_TEST_RET_ENC_EC(ret);
  42720. }
  42721. /* Flip bits in a few places throughout the signature, stepping in multiple
  42722. * of hash size. These should all fail with -1. */
  42723. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42724. lms_L1H10W8_sig[j] ^= 1;
  42725. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig,
  42726. LMS_L1H10W8_SIGLEN,
  42727. (byte *) lms_msg, msgSz);
  42728. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42729. /* Verify passed when it should have failed. */
  42730. return WC_TEST_RET_ENC_I(j);
  42731. }
  42732. /* Flip this spot back. */
  42733. lms_L1H10W8_sig[j] ^= 1;
  42734. }
  42735. wc_LmsKey_Free(&verifyKey);
  42736. return ret;
  42737. }
  42738. #endif
  42739. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK) */
  42740. static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point --
  42741. * see print_fiducials() below.
  42742. */
  42743. #ifdef WOLFCRYPT_HAVE_ECCSI
  42744. static wc_test_ret_t eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk,
  42745. ecc_point* pvt)
  42746. {
  42747. wc_test_ret_t ret;
  42748. byte id[1] = { 0x00 };
  42749. int valid;
  42750. word32 sz;
  42751. byte data[256];
  42752. byte hash[WC_MAX_DIGEST_SIZE];
  42753. byte hashSz;
  42754. byte sig[257];
  42755. word32 sigSz;
  42756. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42757. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42758. return WC_TEST_RET_ENC_EC(ret);
  42759. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42760. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42761. return WC_TEST_RET_ENC_EC(ret);
  42762. ret = wc_InitEccsiKey(NULL, NULL, INVALID_DEVID);
  42763. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42764. return WC_TEST_RET_ENC_EC(ret);
  42765. ret = wc_InitEccsiKey(NULL, HEAP_HINT, INVALID_DEVID);
  42766. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42767. return WC_TEST_RET_ENC_EC(ret);
  42768. wc_FreeEccsiKey(NULL);
  42769. /* Create a valid key. */
  42770. ret = wc_InitEccsiKey(key, NULL, INVALID_DEVID);
  42771. if (ret != 0)
  42772. return WC_TEST_RET_ENC_EC(ret);
  42773. ret = wc_MakeEccsiKey(NULL, NULL);
  42774. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42775. return WC_TEST_RET_ENC_EC(ret);
  42776. ret = wc_MakeEccsiKey(key, NULL);
  42777. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42778. return WC_TEST_RET_ENC_EC(ret);
  42779. ret = wc_MakeEccsiKey(NULL, rng);
  42780. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42781. return WC_TEST_RET_ENC_EC(ret);
  42782. ret = wc_MakeEccsiPair(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL,
  42783. NULL);
  42784. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42785. return WC_TEST_RET_ENC_EC(ret);
  42786. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL);
  42787. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42788. return WC_TEST_RET_ENC_EC(ret);
  42789. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt);
  42790. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42791. return WC_TEST_RET_ENC_EC(ret);
  42792. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt);
  42793. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42794. return WC_TEST_RET_ENC_EC(ret);
  42795. ret = wc_MakeEccsiPair(key, NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42796. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42797. return WC_TEST_RET_ENC_EC(ret);
  42798. ret = wc_MakeEccsiPair(NULL, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42799. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42800. return WC_TEST_RET_ENC_EC(ret);
  42801. /* No key set */
  42802. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42803. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42804. return WC_TEST_RET_ENC_EC(ret);
  42805. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL,
  42806. NULL);
  42807. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42808. return WC_TEST_RET_ENC_EC(ret);
  42809. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42810. NULL);
  42811. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42812. return WC_TEST_RET_ENC_EC(ret);
  42813. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL,
  42814. &valid);
  42815. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42816. return WC_TEST_RET_ENC_EC(ret);
  42817. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt,
  42818. &valid);
  42819. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42820. return WC_TEST_RET_ENC_EC(ret);
  42821. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt,
  42822. &valid);
  42823. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42824. return WC_TEST_RET_ENC_EC(ret);
  42825. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42826. &valid);
  42827. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42828. return WC_TEST_RET_ENC_EC(ret);
  42829. /* No key set */
  42830. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42831. &valid);
  42832. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42833. return WC_TEST_RET_ENC_EC(ret);
  42834. ret = wc_ValidateEccsiPvt(NULL, NULL, NULL);
  42835. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42836. return WC_TEST_RET_ENC_EC(ret);
  42837. ret = wc_ValidateEccsiPvt(key, NULL, NULL);
  42838. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42839. return WC_TEST_RET_ENC_EC(ret);
  42840. ret = wc_ValidateEccsiPvt(NULL, pvt, NULL);
  42841. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42842. return WC_TEST_RET_ENC_EC(ret);
  42843. ret = wc_ValidateEccsiPvt(NULL, NULL, &valid);
  42844. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42845. return WC_TEST_RET_ENC_EC(ret);
  42846. ret = wc_ValidateEccsiPvt(key, pvt, NULL);
  42847. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42848. return WC_TEST_RET_ENC_EC(ret);
  42849. ret = wc_ValidateEccsiPvt(key, NULL, &valid);
  42850. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42851. return WC_TEST_RET_ENC_EC(ret);
  42852. ret = wc_ValidateEccsiPvt(NULL, pvt, &valid);
  42853. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42854. return WC_TEST_RET_ENC_EC(ret);
  42855. ret = wc_EncodeEccsiPair(NULL, NULL, NULL, data, NULL);
  42856. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42857. return WC_TEST_RET_ENC_EC(ret);
  42858. ret = wc_EncodeEccsiPair(key, ssk, pvt, data, NULL);
  42859. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42860. return WC_TEST_RET_ENC_EC(ret);
  42861. ret = wc_EncodeEccsiPair(key, ssk, NULL, data, &sz);
  42862. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42863. return WC_TEST_RET_ENC_EC(ret);
  42864. ret = wc_EncodeEccsiPair(key, NULL, pvt, data, &sz);
  42865. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42866. return WC_TEST_RET_ENC_EC(ret);
  42867. ret = wc_EncodeEccsiPair(NULL, ssk, pvt, data, &sz);
  42868. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42869. return WC_TEST_RET_ENC_EC(ret);
  42870. /* No key created so no curve information. */
  42871. ret = wc_EncodeEccsiPair(key, ssk, pvt, NULL, &sz);
  42872. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42873. return WC_TEST_RET_ENC_EC(ret);
  42874. ret = wc_EncodeEccsiSsk(NULL, NULL, data, NULL);
  42875. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42876. return WC_TEST_RET_ENC_EC(ret);
  42877. ret = wc_EncodeEccsiSsk(key, ssk, data, NULL);
  42878. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42879. return WC_TEST_RET_ENC_EC(ret);
  42880. ret = wc_EncodeEccsiSsk(key, NULL, data, &sz);
  42881. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42882. return WC_TEST_RET_ENC_EC(ret);
  42883. ret = wc_EncodeEccsiSsk(NULL, ssk, data, &sz);
  42884. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42885. return WC_TEST_RET_ENC_EC(ret);
  42886. ret = wc_EncodeEccsiPvt(NULL, NULL, data, NULL, 1);
  42887. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42888. return WC_TEST_RET_ENC_EC(ret);
  42889. ret = wc_EncodeEccsiPvt(key, pvt, data, NULL, 1);
  42890. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42891. return WC_TEST_RET_ENC_EC(ret);
  42892. ret = wc_EncodeEccsiPvt(key, NULL, data, &sz, 1);
  42893. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42894. return WC_TEST_RET_ENC_EC(ret);
  42895. ret = wc_EncodeEccsiPvt(NULL, pvt, data, &sz, 1);
  42896. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42897. return WC_TEST_RET_ENC_EC(ret);
  42898. ret = wc_DecodeEccsiPair(NULL, NULL, 0, NULL, NULL);
  42899. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42900. return WC_TEST_RET_ENC_EC(ret);
  42901. ret = wc_DecodeEccsiPair(key, data, 0, ssk, NULL);
  42902. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42903. return WC_TEST_RET_ENC_EC(ret);
  42904. ret = wc_DecodeEccsiPair(key, data, 0, NULL, pvt);
  42905. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42906. return WC_TEST_RET_ENC_EC(ret);
  42907. ret = wc_DecodeEccsiPair(key, NULL, 0, ssk, pvt);
  42908. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42909. return WC_TEST_RET_ENC_EC(ret);
  42910. ret = wc_DecodeEccsiPair(NULL, data, 0, ssk, pvt);
  42911. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42912. return WC_TEST_RET_ENC_EC(ret);
  42913. ret = wc_DecodeEccsiSsk(NULL, NULL, 0, NULL);
  42914. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42915. return WC_TEST_RET_ENC_EC(ret);
  42916. ret = wc_DecodeEccsiSsk(key, data, 0, NULL);
  42917. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42918. return WC_TEST_RET_ENC_EC(ret);
  42919. ret = wc_DecodeEccsiSsk(key, NULL, 0, ssk);
  42920. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42921. return WC_TEST_RET_ENC_EC(ret);
  42922. ret = wc_DecodeEccsiSsk(NULL, data, 0, ssk);
  42923. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42924. return WC_TEST_RET_ENC_EC(ret);
  42925. ret = wc_DecodeEccsiPvt(NULL, NULL, 0, NULL);
  42926. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42927. return WC_TEST_RET_ENC_EC(ret);
  42928. ret = wc_DecodeEccsiPvt(key, data, 0, NULL);
  42929. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42930. return WC_TEST_RET_ENC_EC(ret);
  42931. ret = wc_DecodeEccsiPvt(key, NULL, 0, pvt);
  42932. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42933. return WC_TEST_RET_ENC_EC(ret);
  42934. ret = wc_DecodeEccsiPvt(NULL, data, 0, pvt);
  42935. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42936. return WC_TEST_RET_ENC_EC(ret);
  42937. ret = wc_DecodeEccsiPvtFromSig(NULL, NULL, 0, NULL);
  42938. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42939. return WC_TEST_RET_ENC_EC(ret);
  42940. ret = wc_DecodeEccsiPvtFromSig(key, data, 0, NULL);
  42941. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42942. return WC_TEST_RET_ENC_EC(ret);
  42943. ret = wc_DecodeEccsiPvtFromSig(key, NULL, 0, pvt);
  42944. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42945. return WC_TEST_RET_ENC_EC(ret);
  42946. ret = wc_DecodeEccsiPvtFromSig(NULL, data, 0, pvt);
  42947. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42948. return WC_TEST_RET_ENC_EC(ret);
  42949. ret = wc_ExportEccsiKey(NULL, data, NULL);
  42950. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42951. return WC_TEST_RET_ENC_EC(ret);
  42952. ret = wc_ExportEccsiKey(key, data, NULL);
  42953. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42954. return WC_TEST_RET_ENC_EC(ret);
  42955. ret = wc_ExportEccsiKey(NULL, data, &sz);
  42956. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42957. return WC_TEST_RET_ENC_EC(ret);
  42958. /* No key to export */
  42959. ret = wc_ExportEccsiKey(key, NULL, &sz);
  42960. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42961. return WC_TEST_RET_ENC_EC(ret);
  42962. ret = wc_ImportEccsiKey(NULL, NULL, 0);
  42963. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42964. return WC_TEST_RET_ENC_EC(ret);
  42965. ret = wc_ImportEccsiKey(key, NULL, 0);
  42966. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42967. return WC_TEST_RET_ENC_EC(ret);
  42968. ret = wc_ImportEccsiKey(NULL, data, 0);
  42969. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42970. return WC_TEST_RET_ENC_EC(ret);
  42971. ret = wc_ExportEccsiPrivateKey(NULL, data, NULL);
  42972. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42973. return WC_TEST_RET_ENC_EC(ret);
  42974. ret = wc_ExportEccsiPrivateKey(key, data, NULL);
  42975. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42976. return WC_TEST_RET_ENC_EC(ret);
  42977. ret = wc_ExportEccsiPrivateKey(NULL, data, &sz);
  42978. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42979. return WC_TEST_RET_ENC_EC(ret);
  42980. /* No key to export */
  42981. ret = wc_ExportEccsiPrivateKey(key, NULL, &sz);
  42982. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42983. return WC_TEST_RET_ENC_EC(ret);
  42984. ret = wc_ImportEccsiPrivateKey(NULL, NULL, 0);
  42985. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42986. return WC_TEST_RET_ENC_EC(ret);
  42987. ret = wc_ImportEccsiPrivateKey(key, NULL, 0);
  42988. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42989. return WC_TEST_RET_ENC_EC(ret);
  42990. ret = wc_ImportEccsiPrivateKey(NULL, data, 0);
  42991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42992. return WC_TEST_RET_ENC_EC(ret);
  42993. ret = wc_ExportEccsiPublicKey(NULL, data, NULL, 1);
  42994. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42995. return WC_TEST_RET_ENC_EC(ret);
  42996. ret = wc_ExportEccsiPublicKey(key, data, NULL, 1);
  42997. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42998. return WC_TEST_RET_ENC_EC(ret);
  42999. ret = wc_ExportEccsiPublicKey(NULL, data, &sz, 1);
  43000. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43001. return WC_TEST_RET_ENC_EC(ret);
  43002. /* No key to export */
  43003. ret = wc_ExportEccsiPublicKey(key, data, &sz, 1);
  43004. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43005. return WC_TEST_RET_ENC_EC(ret);
  43006. ret = wc_ImportEccsiPublicKey(NULL, NULL, 0, 1);
  43007. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43008. return WC_TEST_RET_ENC_EC(ret);
  43009. ret = wc_ImportEccsiPublicKey(key, NULL, 0, 1);
  43010. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43011. return WC_TEST_RET_ENC_EC(ret);
  43012. ret = wc_ImportEccsiPublicKey(NULL, data, 0, 1);
  43013. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43014. return WC_TEST_RET_ENC_EC(ret);
  43015. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL);
  43016. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43017. return WC_TEST_RET_ENC_EC(ret);
  43018. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, NULL);
  43019. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43020. return WC_TEST_RET_ENC_EC(ret);
  43021. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, NULL, &hashSz);
  43022. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43023. return WC_TEST_RET_ENC_EC(ret);
  43024. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, NULL, hash, &hashSz);
  43025. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43026. return WC_TEST_RET_ENC_EC(ret);
  43027. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, NULL, 1, pvt, hash,
  43028. &hashSz);
  43029. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43030. return WC_TEST_RET_ENC_EC(ret);
  43031. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  43032. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43033. return WC_TEST_RET_ENC_EC(ret);
  43034. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  43035. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43036. return WC_TEST_RET_ENC_EC(ret);
  43037. ret = wc_SetEccsiHash(NULL, NULL, 1);
  43038. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43039. return WC_TEST_RET_ENC_EC(ret);
  43040. ret = wc_SetEccsiHash(key, NULL, 1);
  43041. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43042. return WC_TEST_RET_ENC_EC(ret);
  43043. ret = wc_SetEccsiHash(NULL, hash, 1);
  43044. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43045. return WC_TEST_RET_ENC_EC(ret);
  43046. ret = wc_SetEccsiPair(NULL, NULL, NULL);
  43047. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43048. return WC_TEST_RET_ENC_EC(ret);
  43049. ret = wc_SetEccsiPair(key, NULL, NULL);
  43050. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43051. return WC_TEST_RET_ENC_EC(ret);
  43052. ret = wc_SetEccsiPair(NULL, ssk, NULL);
  43053. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43054. return WC_TEST_RET_ENC_EC(ret);
  43055. ret = wc_SetEccsiPair(NULL, NULL, pvt);
  43056. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43057. return WC_TEST_RET_ENC_EC(ret);
  43058. ret = wc_SetEccsiPair(key, ssk, NULL);
  43059. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43060. return WC_TEST_RET_ENC_EC(ret);
  43061. ret = wc_SetEccsiPair(key, NULL, pvt);
  43062. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43063. return WC_TEST_RET_ENC_EC(ret);
  43064. ret = wc_SetEccsiPair(NULL, ssk, pvt);
  43065. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43066. return WC_TEST_RET_ENC_EC(ret);
  43067. ret = wc_SignEccsiHash(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, NULL);
  43068. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43069. return WC_TEST_RET_ENC_EC(ret);
  43070. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, sig, NULL);
  43071. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43072. return WC_TEST_RET_ENC_EC(ret);
  43073. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, NULL, 0, sig,
  43074. &sigSz);
  43075. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43076. return WC_TEST_RET_ENC_EC(ret);
  43077. ret = wc_SignEccsiHash(key, NULL, WC_HASH_TYPE_SHA256, data, 0, sig,
  43078. &sigSz);
  43079. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43080. return WC_TEST_RET_ENC_EC(ret);
  43081. ret = wc_SignEccsiHash(NULL, rng, WC_HASH_TYPE_SHA256, data, 0, sig,
  43082. &sigSz);
  43083. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43084. return WC_TEST_RET_ENC_EC(ret);
  43085. /* Key not set. */
  43086. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  43087. &sigSz);
  43088. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43089. return WC_TEST_RET_ENC_EC(ret);
  43090. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  43091. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43092. return WC_TEST_RET_ENC_EC(ret);
  43093. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  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, NULL, 0, NULL);
  43097. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43098. return WC_TEST_RET_ENC_EC(ret);
  43099. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0, NULL);
  43100. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43101. return WC_TEST_RET_ENC_EC(ret);
  43102. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0,
  43103. &valid);
  43104. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43105. return WC_TEST_RET_ENC_EC(ret);
  43106. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, NULL);
  43107. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43108. return WC_TEST_RET_ENC_EC(ret);
  43109. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, NULL, 0,
  43110. &valid);
  43111. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43112. return WC_TEST_RET_ENC_EC(ret);
  43113. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0,
  43114. &valid);
  43115. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43116. return WC_TEST_RET_ENC_EC(ret);
  43117. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  43118. &valid);
  43119. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43120. return WC_TEST_RET_ENC_EC(ret);
  43121. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  43122. &valid);
  43123. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43124. return WC_TEST_RET_ENC_EC(ret);
  43125. ret = wc_SetEccsiPair(key, ssk, pvt);
  43126. if (ret != 0)
  43127. return WC_TEST_RET_ENC_EC(ret);
  43128. /* Identity hash not set. */
  43129. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  43130. &sigSz);
  43131. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43132. return WC_TEST_RET_ENC_EC(ret);
  43133. wc_FreeEccsiKey(key);
  43134. return 0;
  43135. }
  43136. /* RFC 6507: Appendix A */
  43137. static wc_test_ret_t eccsi_kat_verify_test(EccsiKey* key, ecc_point* pvt)
  43138. {
  43139. wc_test_ret_t ret;
  43140. int verified;
  43141. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00 };
  43142. word32 msgSz = sizeof(msg);
  43143. byte hash[WC_SHA256_DIGEST_SIZE];
  43144. byte hashSz = WC_SHA256_DIGEST_SIZE;
  43145. static const byte id[] = {
  43146. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43147. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43148. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43149. 0x33, 0x00
  43150. };
  43151. word32 idSz = sizeof(id);
  43152. static const byte sig[] = {
  43153. 0x26, 0x9D, 0x4C, 0x8F, 0xDE, 0xB6, 0x6A, 0x74,
  43154. 0xE4, 0xEF, 0x8C, 0x0D, 0x5D, 0xCC, 0x59, 0x7D,
  43155. 0xDF, 0xE6, 0x02, 0x9C, 0x2A, 0xFF, 0xC4, 0x93,
  43156. 0x60, 0x08, 0xCD, 0x2C, 0xC1, 0x04, 0x5D, 0x81,
  43157. 0xE0, 0x9B, 0x52, 0x8D, 0x0E, 0xF8, 0xD6, 0xDF,
  43158. 0x1A, 0xA3, 0xEC, 0xBF, 0x80, 0x11, 0x0C, 0xFC,
  43159. 0xEC, 0x9F, 0xC6, 0x82, 0x52, 0xCE, 0xBB, 0x67,
  43160. 0x9F, 0x41, 0x34, 0x84, 0x69, 0x40, 0xCC, 0xFD,
  43161. 0x04,
  43162. 0x75, 0x8A, 0x14, 0x27, 0x79, 0xBE, 0x89, 0xE8,
  43163. 0x29, 0xE7, 0x19, 0x84, 0xCB, 0x40, 0xEF, 0x75,
  43164. 0x8C, 0xC4, 0xAD, 0x77, 0x5F, 0xC5, 0xB9, 0xA3,
  43165. 0xE1, 0xC8, 0xED, 0x52, 0xF6, 0xFA, 0x36, 0xD9,
  43166. 0xA7, 0x9D, 0x24, 0x76, 0x92, 0xF4, 0xED, 0xA3,
  43167. 0xA6, 0xBD, 0xAB, 0x77, 0xD6, 0xAA, 0x64, 0x74,
  43168. 0xA4, 0x64, 0xAE, 0x49, 0x34, 0x66, 0x3C, 0x52,
  43169. 0x65, 0xBA, 0x70, 0x18, 0xBA, 0x09, 0x1F, 0x79
  43170. };
  43171. word32 sigSz = sizeof(sig);
  43172. static const byte pubData[] = {
  43173. 0x50, 0xD4, 0x67, 0x0B, 0xDE, 0x75, 0x24, 0x4F,
  43174. 0x28, 0xD2, 0x83, 0x8A, 0x0D, 0x25, 0x55, 0x8A,
  43175. 0x7A, 0x72, 0x68, 0x6D, 0x45, 0x22, 0xD4, 0xC8,
  43176. 0x27, 0x3F, 0xB6, 0x44, 0x2A, 0xEB, 0xFA, 0x93,
  43177. 0xDB, 0xDD, 0x37, 0x55, 0x1A, 0xFD, 0x26, 0x3B,
  43178. 0x5D, 0xFD, 0x61, 0x7F, 0x39, 0x60, 0xC6, 0x5A,
  43179. 0x8C, 0x29, 0x88, 0x50, 0xFF, 0x99, 0xF2, 0x03,
  43180. 0x66, 0xDC, 0xE7, 0xD4, 0x36, 0x72, 0x17, 0xF4
  43181. };
  43182. static const byte expHash[] = {
  43183. 0x49, 0x0f, 0x3f, 0xeb, 0xbc, 0x1c, 0x90, 0x2f,
  43184. 0x62, 0x89, 0x72, 0x3d, 0x7f, 0x8c, 0xbf, 0x79,
  43185. 0xdb, 0x88, 0x93, 0x08, 0x49, 0xd1, 0x9f, 0x38,
  43186. 0xf0, 0x29, 0x5b, 0x5c, 0x27, 0x6c, 0x14, 0xd1
  43187. };
  43188. ret = wc_ImportEccsiPublicKey(key, pubData, sizeof(pubData), 0);
  43189. if (ret != 0)
  43190. return WC_TEST_RET_ENC_EC(ret);
  43191. ret = wc_DecodeEccsiPvtFromSig(key, sig, sigSz, pvt);
  43192. if (ret != 0)
  43193. return WC_TEST_RET_ENC_EC(ret);
  43194. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, idSz, pvt, hash,
  43195. &hashSz);
  43196. if (ret != 0)
  43197. return WC_TEST_RET_ENC_EC(ret);
  43198. if (hashSz != sizeof(expHash))
  43199. return WC_TEST_RET_ENC_NC;
  43200. if (XMEMCMP(hash, expHash, hashSz) != 0)
  43201. return WC_TEST_RET_ENC_NC;
  43202. ret = wc_SetEccsiHash(key, hash, hashSz);
  43203. if (ret != 0)
  43204. return WC_TEST_RET_ENC_EC(ret);
  43205. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43206. &verified);
  43207. if (ret != 0)
  43208. return WC_TEST_RET_ENC_EC(ret);
  43209. if (!verified)
  43210. return WC_TEST_RET_ENC_NC;
  43211. return 0;
  43212. }
  43213. static wc_test_ret_t eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt)
  43214. {
  43215. wc_test_ret_t ret;
  43216. byte data[32 * 3];
  43217. word32 sz;
  43218. ecc_point* decPvt = NULL;
  43219. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  43220. mp_int *decSsk = (mp_int *)XMALLOC(sizeof(*decSsk), HEAP_HINT,
  43221. DYNAMIC_TYPE_TMP_BUFFER);
  43222. if (decSsk == NULL)
  43223. return WC_TEST_RET_ENC_ERRNO;
  43224. #else
  43225. mp_int decSsk[1];
  43226. #endif
  43227. ret = mp_init(decSsk);
  43228. if (ret != 0)
  43229. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43230. decPvt = wc_ecc_new_point();
  43231. if (decPvt == NULL)
  43232. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  43233. ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz);
  43234. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43235. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43236. if (sz != 32 * 3)
  43237. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43238. ret = wc_EncodeEccsiPair(priv, ssk, pvt, data, &sz);
  43239. if (ret != 0)
  43240. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43241. if (sz != 32* 3)
  43242. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43243. ret = wc_DecodeEccsiPair(priv, data, sz, decSsk, decPvt);
  43244. if (ret != 0)
  43245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43246. ret = mp_cmp(ssk, decSsk);
  43247. if (ret != MP_EQ)
  43248. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43249. ret = wc_ecc_cmp_point(pvt, decPvt);
  43250. if (ret != MP_EQ)
  43251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43252. ret = wc_EncodeEccsiSsk(priv, ssk, NULL, &sz);
  43253. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43255. if (sz != 32)
  43256. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43257. ret = wc_EncodeEccsiSsk(priv, ssk, data, &sz);
  43258. if (ret != 0)
  43259. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43260. if (sz != 32)
  43261. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43262. ret = wc_DecodeEccsiSsk(priv, data, sz, decSsk);
  43263. if (ret != 0)
  43264. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43265. ret = mp_cmp(ssk, decSsk);
  43266. if (ret != MP_EQ)
  43267. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43268. ret = wc_EncodeEccsiPvt(priv, pvt, NULL, &sz, 1);
  43269. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43271. if (sz != 32 * 2)
  43272. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43273. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 1);
  43274. if (ret != 0)
  43275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43276. if (sz != 32 * 2)
  43277. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43278. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  43279. if (ret != 0)
  43280. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43281. ret = wc_ecc_cmp_point(pvt, decPvt);
  43282. if (ret != MP_EQ)
  43283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43284. sz = sizeof(data);
  43285. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 0);
  43286. if (ret != 0)
  43287. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43288. if (sz != 32 * 2 + 1)
  43289. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43290. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  43291. if (ret != 0)
  43292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43293. ret = wc_ecc_cmp_point(pvt, decPvt);
  43294. if (ret != MP_EQ)
  43295. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43296. wc_ecc_del_point(decPvt);
  43297. out:
  43298. mp_free(decSsk);
  43299. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  43300. XFREE(decSsk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43301. #endif
  43302. return ret;
  43303. }
  43304. static wc_test_ret_t eccsi_imp_exp_key_test(EccsiKey* priv)
  43305. {
  43306. wc_test_ret_t ret;
  43307. byte data[32 * 3];
  43308. byte out[32 * 3];
  43309. word32 sz;
  43310. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  43311. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43312. return WC_TEST_RET_ENC_EC(ret);
  43313. if (sz != 32 * 3)
  43314. return WC_TEST_RET_ENC_NC;
  43315. ret = wc_ExportEccsiKey(priv, data, &sz);
  43316. if (ret != 0)
  43317. return WC_TEST_RET_ENC_EC(ret);
  43318. ret = wc_ImportEccsiKey(priv, data, sz);
  43319. if (ret != 0)
  43320. return WC_TEST_RET_ENC_EC(ret);
  43321. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  43322. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43323. return WC_TEST_RET_ENC_EC(ret);
  43324. if (sz != 32 * 3)
  43325. return WC_TEST_RET_ENC_NC;
  43326. ret = wc_ExportEccsiKey(priv, out, &sz);
  43327. if (ret != 0)
  43328. return WC_TEST_RET_ENC_EC(ret);
  43329. if (sz != 32 * 3)
  43330. return WC_TEST_RET_ENC_NC;
  43331. if (XMEMCMP(data, out, sz) != 0)
  43332. return WC_TEST_RET_ENC_NC;
  43333. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  43334. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43335. return WC_TEST_RET_ENC_EC(ret);
  43336. if (sz != 32)
  43337. return WC_TEST_RET_ENC_NC;
  43338. ret = wc_ExportEccsiPrivateKey(priv, data, &sz);
  43339. if (ret != 0)
  43340. return WC_TEST_RET_ENC_EC(ret);
  43341. ret = wc_ImportEccsiPrivateKey(priv, data, sz);
  43342. if (ret != 0)
  43343. return WC_TEST_RET_ENC_EC(ret);
  43344. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  43345. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43346. return WC_TEST_RET_ENC_EC(ret);
  43347. if (sz != 32)
  43348. return WC_TEST_RET_ENC_NC;
  43349. ret = wc_ExportEccsiPrivateKey(priv, out, &sz);
  43350. if (ret != 0)
  43351. return WC_TEST_RET_ENC_EC(ret);
  43352. if (sz != 32)
  43353. return WC_TEST_RET_ENC_NC;
  43354. if (XMEMCMP(data, out, sz) != 0)
  43355. return WC_TEST_RET_ENC_NC;
  43356. return 0;
  43357. }
  43358. static wc_test_ret_t eccsi_imp_exp_pubkey_test(EccsiKey* key1, EccsiKey* key2)
  43359. {
  43360. wc_test_ret_t ret;
  43361. byte data[32 * 2 + 1];
  43362. byte pubData[32 * 2 + 1];
  43363. word32 sz;
  43364. ret = wc_ExportEccsiPublicKey(key1, NULL, &sz, 1);
  43365. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43366. return WC_TEST_RET_ENC_EC(ret);
  43367. if (sz != 32 * 2)
  43368. return WC_TEST_RET_ENC_NC;
  43369. ret = wc_ExportEccsiPublicKey(key1, data, &sz, 1);
  43370. if (ret != 0)
  43371. return WC_TEST_RET_ENC_EC(ret);
  43372. ret = wc_ImportEccsiPublicKey(key2, data, sz, 1);
  43373. if (ret != 0)
  43374. return WC_TEST_RET_ENC_EC(ret);
  43375. sz = sizeof(pubData);
  43376. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 1);
  43377. if (ret != 0)
  43378. return WC_TEST_RET_ENC_EC(ret);
  43379. if (sz != 32 * 2)
  43380. return WC_TEST_RET_ENC_NC;
  43381. if (XMEMCMP(data, pubData, sz) != 0)
  43382. return WC_TEST_RET_ENC_NC;
  43383. sz = sizeof(pubData);
  43384. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 0);
  43385. if (ret != 0)
  43386. return WC_TEST_RET_ENC_EC(ret);
  43387. if (sz != 32 * 2 + 1)
  43388. return WC_TEST_RET_ENC_NC;
  43389. if (pubData[0] != 0x04)
  43390. return WC_TEST_RET_ENC_NC;
  43391. if (XMEMCMP(pubData + 1, data, sz - 1) != 0)
  43392. return WC_TEST_RET_ENC_NC;
  43393. ret = wc_ImportEccsiPublicKey(key2, pubData, sz, 0);
  43394. if (ret != 0)
  43395. return WC_TEST_RET_ENC_EC(ret);
  43396. return 0;
  43397. }
  43398. static wc_test_ret_t eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43399. mp_int* ssk, ecc_point* pvt)
  43400. {
  43401. wc_test_ret_t ret;
  43402. char mail[] = "test@wolfssl.com";
  43403. byte* id = (byte*)mail;
  43404. word32 idSz = (word32) XSTRLEN(mail);
  43405. int valid;
  43406. ret = wc_MakeEccsiKey(priv, rng);
  43407. if (ret != 0)
  43408. return WC_TEST_RET_ENC_EC(ret);
  43409. ret = eccsi_imp_exp_key_test(priv);
  43410. if (ret < 0)
  43411. return ret;
  43412. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43413. if (ret < 0)
  43414. return ret;
  43415. ret = wc_MakeEccsiPair(priv, rng, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt);
  43416. if (ret != 0)
  43417. return WC_TEST_RET_ENC_EC(ret);
  43418. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43419. &valid);
  43420. if (ret != 0)
  43421. return WC_TEST_RET_ENC_EC(ret);
  43422. if (!valid)
  43423. return WC_TEST_RET_ENC_NC;
  43424. ret = eccsi_enc_dec_pair_test(priv, ssk, pvt);
  43425. if (ret != 0)
  43426. return ret;
  43427. return 0;
  43428. }
  43429. static wc_test_ret_t eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43430. mp_int* ssk, ecc_point* pvt)
  43431. {
  43432. wc_test_ret_t ret;
  43433. byte hashPriv[WC_MAX_DIGEST_SIZE];
  43434. byte hashPub[WC_MAX_DIGEST_SIZE];
  43435. byte hashSz;
  43436. byte sig[144];
  43437. word32 sigSz;
  43438. int verified, valid;
  43439. char mail[] = "test@wolfssl.com";
  43440. byte* id = (byte*)mail;
  43441. word32 idSz = (word32) XSTRLEN(mail);
  43442. byte msg[] = { 0x00 };
  43443. word32 msgSz = sizeof(msg);
  43444. #ifdef WOLFSSL_SHA384
  43445. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA384, id, idSz, pvt, hashPriv,
  43446. &hashSz);
  43447. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43448. return WC_TEST_RET_ENC_EC(ret);
  43449. #endif
  43450. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPriv,
  43451. &hashSz);
  43452. if (ret != 0)
  43453. return WC_TEST_RET_ENC_EC(ret);
  43454. if (hashSz != 32)
  43455. return WC_TEST_RET_ENC_NC;
  43456. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPub,
  43457. &hashSz);
  43458. if (ret != 0)
  43459. return WC_TEST_RET_ENC_EC(ret);
  43460. if (hashSz != 32)
  43461. return WC_TEST_RET_ENC_NC;
  43462. if (XMEMCMP(hashPriv, hashPub, hashSz) != 0)
  43463. return WC_TEST_RET_ENC_NC;
  43464. ret = wc_SetEccsiHash(priv, hashPriv, hashSz);
  43465. if (ret != 0)
  43466. return WC_TEST_RET_ENC_EC(ret);
  43467. ret = wc_SetEccsiPair(priv, ssk, pvt);
  43468. if (ret != 0)
  43469. return WC_TEST_RET_ENC_EC(ret);
  43470. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, NULL,
  43471. &sigSz);
  43472. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43473. return WC_TEST_RET_ENC_EC(ret);
  43474. if (sigSz != 129)
  43475. return WC_TEST_RET_ENC_NC;
  43476. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, sig,
  43477. &sigSz);
  43478. if (ret != 0)
  43479. return WC_TEST_RET_ENC_EC(ret);
  43480. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43481. if (ret != 0)
  43482. return WC_TEST_RET_ENC_EC(ret);
  43483. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43484. &verified);
  43485. if (ret != 0)
  43486. return WC_TEST_RET_ENC_EC(ret);
  43487. if (!verified)
  43488. return WC_TEST_RET_ENC_NC;
  43489. /* Check that changing HS results in verification failure. */
  43490. hashPub[0] ^= 0x80;
  43491. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43492. if (ret != 0)
  43493. return WC_TEST_RET_ENC_EC(ret);
  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. hashPub[0] ^= 0x80;
  43501. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43502. if (ret != 0)
  43503. return WC_TEST_RET_ENC_EC(ret);
  43504. /* Check that changing msg results in verification failure. */
  43505. msg[0] ^= 0x80;
  43506. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43507. &verified);
  43508. if (ret != 0)
  43509. return WC_TEST_RET_ENC_EC(ret);
  43510. if (verified)
  43511. return WC_TEST_RET_ENC_NC;
  43512. msg[0] ^= 0x80;
  43513. /* Check that changing signature results in verification failure. */
  43514. sig[0] ^= 0x80;
  43515. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43516. &verified);
  43517. if (ret != 0)
  43518. return WC_TEST_RET_ENC_EC(ret);
  43519. if (verified)
  43520. return WC_TEST_RET_ENC_NC;
  43521. sig[0] ^= 0x80;
  43522. /* Check that key state hasn't been invalidated. */
  43523. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43524. &verified);
  43525. if (ret != 0)
  43526. return WC_TEST_RET_ENC_EC(ret);
  43527. if (!verified)
  43528. return WC_TEST_RET_ENC_NC;
  43529. /* Check that verifying with the private key works. */
  43530. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43531. &verified);
  43532. if (ret != 0)
  43533. return WC_TEST_RET_ENC_EC(ret);
  43534. if (!verified)
  43535. return WC_TEST_RET_ENC_NC;
  43536. /* Check that the KPAK is converted from montgomery form. */
  43537. ret = eccsi_imp_exp_key_test(priv);
  43538. if (ret != 0)
  43539. return ret;
  43540. /* Check that KPAK can converted to Montgomery form again. */
  43541. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43542. &verified);
  43543. if (ret != 0)
  43544. return WC_TEST_RET_ENC_EC(ret);
  43545. if (!verified)
  43546. return WC_TEST_RET_ENC_NC;
  43547. /* Check that the KPAK is converted from montgomery form. */
  43548. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43549. &valid);
  43550. if (ret != 0)
  43551. return WC_TEST_RET_ENC_EC(ret);
  43552. if (!valid)
  43553. return WC_TEST_RET_ENC_NC;
  43554. /* Check that KPAK can converted to Montgomery form again. */
  43555. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43556. &verified);
  43557. if (ret != 0)
  43558. return WC_TEST_RET_ENC_EC(ret);
  43559. if (!verified)
  43560. return WC_TEST_RET_ENC_NC;
  43561. /* Check that the KPAK is converted from montgomery form. */
  43562. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43563. if (ret != 0)
  43564. return ret;
  43565. return 0;
  43566. }
  43567. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void)
  43568. {
  43569. wc_test_ret_t ret = 0;
  43570. WC_RNG rng;
  43571. int rng_inited = 0;
  43572. EccsiKey* priv = NULL;
  43573. EccsiKey* pub = NULL;
  43574. mp_int* ssk = NULL;
  43575. ecc_point* pvt = NULL;
  43576. WOLFSSL_ENTER("eccsi_test");
  43577. priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43578. DYNAMIC_TYPE_TMP_BUFFER);
  43579. if (priv == NULL)
  43580. ret = WC_TEST_RET_ENC_NC;
  43581. else
  43582. XMEMSET(priv, 0, sizeof(*priv));
  43583. if (ret == 0) {
  43584. pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43585. DYNAMIC_TYPE_TMP_BUFFER);
  43586. if (pub == NULL)
  43587. ret = WC_TEST_RET_ENC_NC;
  43588. else
  43589. XMEMSET(pub, 0, sizeof(*pub));
  43590. }
  43591. if (ret == 0) {
  43592. ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT,
  43593. DYNAMIC_TYPE_TMP_BUFFER);
  43594. if (ssk == NULL)
  43595. ret = WC_TEST_RET_ENC_NC;
  43596. else
  43597. XMEMSET(ssk, 0, sizeof(*ssk));
  43598. }
  43599. if (ret == 0) {
  43600. #ifndef HAVE_FIPS
  43601. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  43602. #else
  43603. ret = wc_InitRng(&rng);
  43604. #endif
  43605. if (ret != 0)
  43606. ret = WC_TEST_RET_ENC_EC(ret);
  43607. else
  43608. rng_inited = 1;
  43609. }
  43610. if (ret == 0) {
  43611. pvt = wc_ecc_new_point();
  43612. if (pvt == NULL)
  43613. ret = WC_TEST_RET_ENC_NC;
  43614. }
  43615. if (ret == 0) {
  43616. ret = mp_init(ssk);
  43617. if (ret != 0)
  43618. ret = WC_TEST_RET_ENC_EC(ret);
  43619. }
  43620. if (ret == 0) {
  43621. ret = eccsi_api_test(&rng, priv, ssk, pvt);
  43622. }
  43623. if (ret == 0) {
  43624. ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID);
  43625. if (ret != 0)
  43626. ret = WC_TEST_RET_ENC_EC(ret);
  43627. }
  43628. if (ret == 0) {
  43629. ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID);
  43630. if (ret != 0)
  43631. ret = WC_TEST_RET_ENC_EC(ret);
  43632. }
  43633. if (ret == 0) {
  43634. ret = eccsi_kat_verify_test(pub, pvt);
  43635. }
  43636. if (ret == 0) {
  43637. ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt);
  43638. }
  43639. if (ret == 0) {
  43640. ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt);
  43641. }
  43642. if (pvt != NULL)
  43643. wc_ecc_del_point(pvt);
  43644. if (rng_inited)
  43645. wc_FreeRng(&rng);
  43646. if (ssk != NULL) {
  43647. mp_free(ssk);
  43648. XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43649. }
  43650. if (pub != NULL) {
  43651. wc_FreeEccsiKey(pub);
  43652. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43653. }
  43654. if (priv != NULL) {
  43655. wc_FreeEccsiKey(priv);
  43656. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43657. }
  43658. return ret;
  43659. }
  43660. #endif /* WOLFCRYPT_HAVE_ECCSI */
  43661. #ifdef WOLFCRYPT_HAVE_SAKKE
  43662. static wc_test_ret_t sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk)
  43663. {
  43664. wc_test_ret_t ret;
  43665. byte id[1] = { 0x00 };
  43666. int valid;
  43667. byte data[256];
  43668. word32 sz;
  43669. byte auth[257];
  43670. word16 authSz;
  43671. byte ssv[256];
  43672. word16 ssvSz;
  43673. word32 len;
  43674. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43675. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43676. return WC_TEST_RET_ENC_EC(ret);
  43677. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43678. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43679. return WC_TEST_RET_ENC_EC(ret);
  43680. wc_FreeSakkeKey(NULL);
  43681. XMEMSET(key, 0, sizeof(*key));
  43682. wc_FreeSakkeKey(key);
  43683. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43684. if (ret != 0)
  43685. return WC_TEST_RET_ENC_EC(ret);
  43686. ret = wc_MakeSakkeKey(NULL, NULL);
  43687. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43688. return WC_TEST_RET_ENC_EC(ret);
  43689. ret = wc_MakeSakkeKey(key, NULL);
  43690. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43691. return WC_TEST_RET_ENC_EC(ret);
  43692. ret = wc_MakeSakkeKey(NULL, rng);
  43693. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43694. return WC_TEST_RET_ENC_EC(ret);
  43695. ret = wc_MakeSakkePublicKey(NULL, NULL);
  43696. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43697. return WC_TEST_RET_ENC_EC(ret);
  43698. ret = wc_MakeSakkePublicKey(key, NULL);
  43699. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43700. return WC_TEST_RET_ENC_EC(ret);
  43701. ret = wc_MakeSakkePublicKey(NULL, rsk);
  43702. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43703. return WC_TEST_RET_ENC_EC(ret);
  43704. ret = wc_MakeSakkeRsk(NULL, NULL, 1, NULL);
  43705. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43706. return WC_TEST_RET_ENC_EC(ret);
  43707. ret = wc_MakeSakkeRsk(key, id, 1, NULL);
  43708. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43709. return WC_TEST_RET_ENC_EC(ret);
  43710. ret = wc_MakeSakkeRsk(key, NULL, 1, rsk);
  43711. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43712. return WC_TEST_RET_ENC_EC(ret);
  43713. ret = wc_MakeSakkeRsk(NULL, id, 1, rsk);
  43714. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43715. return WC_TEST_RET_ENC_EC(ret);
  43716. ret = wc_ValidateSakkeRsk(NULL, NULL, 1, NULL, NULL);
  43717. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43718. return WC_TEST_RET_ENC_EC(ret);
  43719. ret = wc_ValidateSakkeRsk(key, id, 1, rsk, NULL);
  43720. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43721. return WC_TEST_RET_ENC_EC(ret);
  43722. ret = wc_ValidateSakkeRsk(NULL, id, 1, rsk, &valid);
  43723. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43724. return WC_TEST_RET_ENC_EC(ret);
  43725. ret = wc_ExportSakkeKey(NULL, NULL, NULL);
  43726. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43727. return WC_TEST_RET_ENC_EC(ret);
  43728. ret = wc_ExportSakkeKey(key, data, NULL);
  43729. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43730. return WC_TEST_RET_ENC_EC(ret);
  43731. ret = wc_ExportSakkeKey(NULL, data, &sz);
  43732. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43733. return WC_TEST_RET_ENC_EC(ret);
  43734. ret = wc_ImportSakkeKey(NULL, NULL, 1);
  43735. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43736. return WC_TEST_RET_ENC_EC(ret);
  43737. ret = wc_ImportSakkeKey(key, NULL, 1);
  43738. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43739. return WC_TEST_RET_ENC_EC(ret);
  43740. ret = wc_ImportSakkeKey(NULL, data, 1);
  43741. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43742. return WC_TEST_RET_ENC_EC(ret);
  43743. ret = wc_ExportSakkePrivateKey(NULL, NULL, NULL);
  43744. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43745. return WC_TEST_RET_ENC_EC(ret);
  43746. ret = wc_ExportSakkePrivateKey(key, data, NULL);
  43747. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43748. return WC_TEST_RET_ENC_EC(ret);
  43749. ret = wc_ExportSakkePrivateKey(NULL, data, &sz);
  43750. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43751. return WC_TEST_RET_ENC_EC(ret);
  43752. ret = wc_ImportSakkePrivateKey(NULL, NULL, 1);
  43753. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43754. return WC_TEST_RET_ENC_EC(ret);
  43755. ret = wc_ImportSakkePrivateKey(key, NULL, 1);
  43756. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43757. return WC_TEST_RET_ENC_EC(ret);
  43758. ret = wc_ImportSakkePrivateKey(NULL, data, 1);
  43759. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43760. return WC_TEST_RET_ENC_EC(ret);
  43761. sz = sizeof(data);
  43762. ret = wc_EncodeSakkeRsk(NULL, NULL, data, NULL, 1);
  43763. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43764. return WC_TEST_RET_ENC_EC(ret);
  43765. ret = wc_EncodeSakkeRsk(key, rsk, data, NULL, 1);
  43766. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43767. return WC_TEST_RET_ENC_EC(ret);
  43768. ret = wc_EncodeSakkeRsk(key, NULL, data, &sz, 1);
  43769. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43770. return WC_TEST_RET_ENC_EC(ret);
  43771. ret = wc_EncodeSakkeRsk(NULL, rsk, data, &sz, 1);
  43772. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43773. return WC_TEST_RET_ENC_EC(ret);
  43774. ret = wc_DecodeSakkeRsk(NULL, NULL, sz, NULL);
  43775. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43776. return WC_TEST_RET_ENC_EC(ret);
  43777. ret = wc_DecodeSakkeRsk(key, data, sz, NULL);
  43778. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43779. return WC_TEST_RET_ENC_EC(ret);
  43780. ret = wc_DecodeSakkeRsk(key, NULL, sz, rsk);
  43781. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43782. return WC_TEST_RET_ENC_EC(ret);
  43783. ret = wc_DecodeSakkeRsk(NULL, data, sz, rsk);
  43784. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43785. return WC_TEST_RET_ENC_EC(ret);
  43786. ret = wc_ImportSakkeRsk(NULL, NULL, sz);
  43787. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43788. return WC_TEST_RET_ENC_EC(ret);
  43789. ret = wc_ImportSakkeRsk(key, NULL, sz);
  43790. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43791. return WC_TEST_RET_ENC_EC(ret);
  43792. ret = wc_ImportSakkeRsk(NULL, data, sz);
  43793. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43794. return WC_TEST_RET_ENC_EC(ret);
  43795. ret = wc_ImportSakkeRsk(key, data, 1);
  43796. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43797. return WC_TEST_RET_ENC_EC(ret);
  43798. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, NULL);
  43799. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43800. return WC_TEST_RET_ENC_EC(ret);
  43801. ret = wc_GenerateSakkeRskTable(key, NULL, data, NULL);
  43802. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43803. return WC_TEST_RET_ENC_EC(ret);
  43804. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, NULL);
  43805. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43806. return WC_TEST_RET_ENC_EC(ret);
  43807. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, &len);
  43808. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43809. return WC_TEST_RET_ENC_EC(ret);
  43810. ret = wc_GenerateSakkeRskTable(key, rsk, data, NULL);
  43811. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43812. return WC_TEST_RET_ENC_EC(ret);
  43813. ret = wc_GenerateSakkeRskTable(key, NULL, data, &len);
  43814. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43815. return WC_TEST_RET_ENC_EC(ret);
  43816. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, &len);
  43817. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43818. return WC_TEST_RET_ENC_EC(ret);
  43819. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43820. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43821. return WC_TEST_RET_ENC_EC(ret);
  43822. len--;
  43823. ret = wc_GenerateSakkeRskTable(key, rsk, data, &len);
  43824. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43825. return WC_TEST_RET_ENC_EC(ret);
  43826. ret = wc_ExportSakkePublicKey(NULL, data, NULL, 1);
  43827. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43828. return WC_TEST_RET_ENC_EC(ret);
  43829. ret = wc_ExportSakkePublicKey(key, data, NULL, 1);
  43830. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43831. return WC_TEST_RET_ENC_EC(ret);
  43832. ret = wc_ExportSakkePublicKey(NULL, data, &sz, 1);
  43833. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43834. return WC_TEST_RET_ENC_EC(ret);
  43835. ret = wc_ImportSakkePublicKey(NULL, NULL, sz, 1);
  43836. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43837. return WC_TEST_RET_ENC_EC(ret);
  43838. ret = wc_ImportSakkePublicKey(key, NULL, sz, 1);
  43839. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43840. return WC_TEST_RET_ENC_EC(ret);
  43841. ret = wc_ImportSakkePublicKey(NULL, data, sz, 1);
  43842. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43843. return WC_TEST_RET_ENC_EC(ret);
  43844. ret = wc_GetSakkeAuthSize(NULL, NULL);
  43845. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43846. return WC_TEST_RET_ENC_EC(ret);
  43847. ret = wc_GetSakkeAuthSize(key, NULL);
  43848. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43849. return WC_TEST_RET_ENC_EC(ret);
  43850. ret = wc_GetSakkeAuthSize(NULL, &authSz);
  43851. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43852. return WC_TEST_RET_ENC_EC(ret);
  43853. ret = wc_MakeSakkePointI(NULL, NULL, SAKKE_ID_MAX_SIZE + 1);
  43854. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43855. return WC_TEST_RET_ENC_EC(ret);
  43856. ret = wc_MakeSakkePointI(key, NULL, SAKKE_ID_MAX_SIZE + 1);
  43857. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43858. return WC_TEST_RET_ENC_EC(ret);
  43859. ret = wc_MakeSakkePointI(NULL, id, 1);
  43860. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43861. return WC_TEST_RET_ENC_EC(ret);
  43862. ret = wc_MakeSakkePointI(NULL, NULL, 1);
  43863. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43864. return WC_TEST_RET_ENC_EC(ret);
  43865. ret = wc_MakeSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1);
  43866. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43867. return WC_TEST_RET_ENC_EC(ret);
  43868. ret = wc_MakeSakkePointI(key, NULL, 1);
  43869. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43870. return WC_TEST_RET_ENC_EC(ret);
  43871. ret = wc_MakeSakkePointI(NULL, id, 1);
  43872. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43873. return WC_TEST_RET_ENC_EC(ret);
  43874. ret = wc_GenerateSakkePointITable(NULL, data, NULL);
  43875. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43876. return WC_TEST_RET_ENC_EC(ret);
  43877. ret = wc_GenerateSakkePointITable(key, data, NULL);
  43878. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43879. return WC_TEST_RET_ENC_EC(ret);
  43880. ret = wc_GenerateSakkePointITable(NULL, data, &len);
  43881. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43882. return WC_TEST_RET_ENC_EC(ret);
  43883. ret = wc_GenerateSakkePointITable(key, NULL, &len);
  43884. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43885. return WC_TEST_RET_ENC_EC(ret);
  43886. len--;
  43887. ret = wc_GenerateSakkePointITable(key, data, &len);
  43888. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43889. return WC_TEST_RET_ENC_EC(ret);
  43890. ret = wc_SetSakkePointITable(NULL, NULL, 1);
  43891. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43892. return WC_TEST_RET_ENC_EC(ret);
  43893. ret = wc_SetSakkePointITable(key, NULL, 1);
  43894. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43895. return WC_TEST_RET_ENC_EC(ret);
  43896. ret = wc_SetSakkePointITable(NULL, data, 1);
  43897. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43898. return WC_TEST_RET_ENC_EC(ret);
  43899. ret = wc_SetSakkePointITable(key, data, 1);
  43900. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43901. return WC_TEST_RET_ENC_EC(ret);
  43902. ret = wc_ClearSakkePointITable(NULL);
  43903. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43904. return WC_TEST_RET_ENC_EC(ret);
  43905. ret = wc_GetSakkePointI(NULL, data, NULL);
  43906. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43907. return WC_TEST_RET_ENC_EC(ret);
  43908. ret = wc_GetSakkePointI(key, data, NULL);
  43909. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43910. return WC_TEST_RET_ENC_EC(ret);
  43911. ret = wc_GetSakkePointI(NULL, data, &sz);
  43912. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43913. return WC_TEST_RET_ENC_EC(ret);
  43914. sz = 1;
  43915. ret = wc_GetSakkePointI(key, data, &sz);
  43916. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43917. return WC_TEST_RET_ENC_EC(ret);
  43918. sz = 256;
  43919. ret = wc_SetSakkePointI(NULL, NULL, 1, NULL, sz);
  43920. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43921. return WC_TEST_RET_ENC_EC(ret);
  43922. ret = wc_SetSakkePointI(key, NULL, 1, NULL, sz);
  43923. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43924. return WC_TEST_RET_ENC_EC(ret);
  43925. ret = wc_SetSakkePointI(NULL, id, 1, NULL, sz);
  43926. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43927. return WC_TEST_RET_ENC_EC(ret);
  43928. ret = wc_SetSakkePointI(NULL, NULL, 1, data, sz);
  43929. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43930. return WC_TEST_RET_ENC_EC(ret);
  43931. ret = wc_SetSakkePointI(key, id, 1, NULL, sz);
  43932. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43933. return WC_TEST_RET_ENC_EC(ret);
  43934. ret = wc_SetSakkePointI(key, NULL, 1, data, sz);
  43935. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43936. return WC_TEST_RET_ENC_EC(ret);
  43937. ret = wc_SetSakkePointI(NULL, id, 1, data, sz);
  43938. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43939. return WC_TEST_RET_ENC_EC(ret);
  43940. ret = wc_SetSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1, data, sz);
  43941. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43942. return WC_TEST_RET_ENC_EC(ret);
  43943. ret = wc_SetSakkePointI(key, id, 1, data, sz - 1);
  43944. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43945. return WC_TEST_RET_ENC_EC(ret);
  43946. ret = wc_SetSakkeIdentity(NULL, NULL, 1);
  43947. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43948. return WC_TEST_RET_ENC_EC(ret);
  43949. ret = wc_SetSakkeIdentity(key, NULL, 1);
  43950. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43951. return WC_TEST_RET_ENC_EC(ret);
  43952. ret = wc_SetSakkeIdentity(NULL, id, 1);
  43953. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43954. return WC_TEST_RET_ENC_EC(ret);
  43955. ssvSz = sizeof(ssv);
  43956. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43957. auth, NULL);
  43958. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43959. return WC_TEST_RET_ENC_EC(ret);
  43960. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43961. auth, NULL);
  43962. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43963. return WC_TEST_RET_ENC_EC(ret);
  43964. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43965. auth, NULL);
  43966. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43967. return WC_TEST_RET_ENC_EC(ret);
  43968. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43969. auth, &authSz);
  43970. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43971. return WC_TEST_RET_ENC_EC(ret);
  43972. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43973. auth, NULL);
  43974. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43975. return WC_TEST_RET_ENC_EC(ret);
  43976. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43977. auth, &authSz);
  43978. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43979. return WC_TEST_RET_ENC_EC(ret);
  43980. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43981. auth, &authSz);
  43982. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43983. return WC_TEST_RET_ENC_EC(ret);
  43984. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43985. auth, &authSz);
  43986. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43987. return WC_TEST_RET_ENC_EC(ret);
  43988. ret = wc_GenerateSakkeSSV(NULL, NULL, data, NULL);
  43989. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43990. return WC_TEST_RET_ENC_EC(ret);
  43991. ret = wc_GenerateSakkeSSV(key, rng, data, NULL);
  43992. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43993. return WC_TEST_RET_ENC_EC(ret);
  43994. ret = wc_GenerateSakkeSSV(key, NULL, data, &ssvSz);
  43995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43996. return WC_TEST_RET_ENC_EC(ret);
  43997. ret = wc_GenerateSakkeSSV(NULL, rng, data, &ssvSz);
  43998. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43999. return WC_TEST_RET_ENC_EC(ret);
  44000. ret = wc_SetSakkeRsk(NULL, NULL, data, 1);
  44001. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44002. return WC_TEST_RET_ENC_EC(ret);
  44003. ret = wc_SetSakkeRsk(key, NULL, data, 1);
  44004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44005. return WC_TEST_RET_ENC_EC(ret);
  44006. ret = wc_SetSakkeRsk(NULL, rsk, data, 1);
  44007. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44008. return WC_TEST_RET_ENC_EC(ret);
  44009. ssvSz = sizeof(ssv);
  44010. authSz = sizeof(auth);
  44011. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  44012. authSz);
  44013. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44014. return WC_TEST_RET_ENC_EC(ret);
  44015. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  44016. authSz);
  44017. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44018. return WC_TEST_RET_ENC_EC(ret);
  44019. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  44020. authSz);
  44021. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44022. return WC_TEST_RET_ENC_EC(ret);
  44023. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  44024. authSz);
  44025. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44026. return WC_TEST_RET_ENC_EC(ret);
  44027. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  44028. authSz);
  44029. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44030. return WC_TEST_RET_ENC_EC(ret);
  44031. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  44032. authSz);
  44033. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44034. return WC_TEST_RET_ENC_EC(ret);
  44035. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44036. authSz);
  44037. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44038. return WC_TEST_RET_ENC_EC(ret);
  44039. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44040. authSz);
  44041. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44042. return WC_TEST_RET_ENC_EC(ret);
  44043. ret = wc_SetSakkeIdentity(key, id, 1);
  44044. if (ret != 0)
  44045. return WC_TEST_RET_ENC_EC(ret);
  44046. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44047. authSz);
  44048. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44049. return WC_TEST_RET_ENC_EC(ret);
  44050. ret = wc_SetSakkeIdentity(key, id, 0);
  44051. if (ret != 0)
  44052. return WC_TEST_RET_ENC_EC(ret);
  44053. ret = wc_SetSakkeRsk(key, rsk, data, 1);
  44054. if (ret != 0)
  44055. return WC_TEST_RET_ENC_EC(ret);
  44056. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44057. authSz);
  44058. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44059. return WC_TEST_RET_ENC_EC(ret);
  44060. wc_FreeSakkeKey(key);
  44061. return 0;
  44062. }
  44063. static wc_test_ret_t sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk)
  44064. {
  44065. WOLFSSL_SMALL_STACK_STATIC const byte pubData[] = {
  44066. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  44067. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  44068. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  44069. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  44070. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  44071. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  44072. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  44073. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  44074. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  44075. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  44076. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  44077. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  44078. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  44079. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  44080. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  44081. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  44082. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  44083. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  44084. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  44085. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  44086. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  44087. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  44088. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  44089. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  44090. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  44091. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  44092. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  44093. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  44094. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  44095. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  44096. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  44097. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  44098. };
  44099. WOLFSSL_SMALL_STACK_STATIC const byte rskData[] = {
  44100. 0x93, 0xAF, 0x67, 0xE5, 0x00, 0x7B, 0xA6, 0xE6,
  44101. 0xA8, 0x0D, 0xA7, 0x93, 0xDA, 0x30, 0x0F, 0xA4,
  44102. 0xB5, 0x2D, 0x0A, 0x74, 0xE2, 0x5E, 0x6E, 0x7B,
  44103. 0x2B, 0x3D, 0x6E, 0xE9, 0xD1, 0x8A, 0x9B, 0x5C,
  44104. 0x50, 0x23, 0x59, 0x7B, 0xD8, 0x2D, 0x80, 0x62,
  44105. 0xD3, 0x40, 0x19, 0x56, 0x3B, 0xA1, 0xD2, 0x5C,
  44106. 0x0D, 0xC5, 0x6B, 0x7B, 0x97, 0x9D, 0x74, 0xAA,
  44107. 0x50, 0xF2, 0x9F, 0xBF, 0x11, 0xCC, 0x2C, 0x93,
  44108. 0xF5, 0xDF, 0xCA, 0x61, 0x5E, 0x60, 0x92, 0x79,
  44109. 0xF6, 0x17, 0x5C, 0xEA, 0xDB, 0x00, 0xB5, 0x8C,
  44110. 0x6B, 0xEE, 0x1E, 0x7A, 0x2A, 0x47, 0xC4, 0xF0,
  44111. 0xC4, 0x56, 0xF0, 0x52, 0x59, 0xA6, 0xFA, 0x94,
  44112. 0xA6, 0x34, 0xA4, 0x0D, 0xAE, 0x1D, 0xF5, 0x93,
  44113. 0xD4, 0xFE, 0xCF, 0x68, 0x8D, 0x5F, 0xC6, 0x78,
  44114. 0xBE, 0x7E, 0xFC, 0x6D, 0xF3, 0xD6, 0x83, 0x53,
  44115. 0x25, 0xB8, 0x3B, 0x2C, 0x6E, 0x69, 0x03, 0x6B,
  44116. 0x15, 0x5F, 0x0A, 0x27, 0x24, 0x10, 0x94, 0xB0,
  44117. 0x4B, 0xFB, 0x0B, 0xDF, 0xAC, 0x6C, 0x67, 0x0A,
  44118. 0x65, 0xC3, 0x25, 0xD3, 0x9A, 0x06, 0x9F, 0x03,
  44119. 0x65, 0x9D, 0x44, 0xCA, 0x27, 0xD3, 0xBE, 0x8D,
  44120. 0xF3, 0x11, 0x17, 0x2B, 0x55, 0x41, 0x60, 0x18,
  44121. 0x1C, 0xBE, 0x94, 0xA2, 0xA7, 0x83, 0x32, 0x0C,
  44122. 0xED, 0x59, 0x0B, 0xC4, 0x26, 0x44, 0x70, 0x2C,
  44123. 0xF3, 0x71, 0x27, 0x1E, 0x49, 0x6B, 0xF2, 0x0F,
  44124. 0x58, 0x8B, 0x78, 0xA1, 0xBC, 0x01, 0xEC, 0xBB,
  44125. 0x65, 0x59, 0x93, 0x4B, 0xDD, 0x2F, 0xB6, 0x5D,
  44126. 0x28, 0x84, 0x31, 0x8A, 0x33, 0xD1, 0xA4, 0x2A,
  44127. 0xDF, 0x5E, 0x33, 0xCC, 0x58, 0x00, 0x28, 0x0B,
  44128. 0x28, 0x35, 0x64, 0x97, 0xF8, 0x71, 0x35, 0xBA,
  44129. 0xB9, 0x61, 0x2A, 0x17, 0x26, 0x04, 0x24, 0x40,
  44130. 0x9A, 0xC1, 0x5F, 0xEE, 0x99, 0x6B, 0x74, 0x4C,
  44131. 0x33, 0x21, 0x51, 0x23, 0x5D, 0xEC, 0xB0, 0xF5
  44132. };
  44133. WOLFSSL_SMALL_STACK_STATIC const byte id[] = {
  44134. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  44135. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  44136. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  44137. 0x33, 0x00
  44138. };
  44139. WOLFSSL_SMALL_STACK_STATIC const byte ssv[] = {
  44140. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  44141. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  44142. };
  44143. WOLFSSL_SMALL_STACK_STATIC const byte auth[] = {
  44144. 0x04,
  44145. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  44146. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  44147. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  44148. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  44149. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  44150. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  44151. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  44152. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  44153. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  44154. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  44155. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  44156. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  44157. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  44158. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  44159. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  44160. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  44161. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  44162. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  44163. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  44164. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  44165. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  44166. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  44167. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  44168. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  44169. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  44170. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  44171. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  44172. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  44173. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  44174. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  44175. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  44176. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  44177. };
  44178. WOLFSSL_SMALL_STACK_STATIC const byte encSsv[] = {
  44179. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  44180. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  44181. };
  44182. wc_test_ret_t ret;
  44183. int valid;
  44184. byte pubKey[sizeof(pubData) + 1];
  44185. word32 sz = sizeof(pubKey);
  44186. byte tmpSsv[sizeof(encSsv)];
  44187. byte* iTable = NULL;
  44188. word32 iTableLen;
  44189. byte* table = NULL;
  44190. word32 len;
  44191. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44192. if (ret != 0)
  44193. return WC_TEST_RET_ENC_EC(ret);
  44194. ret = wc_DecodeSakkeRsk(key, rskData, sizeof(rskData), rsk);
  44195. if (ret != 0)
  44196. return WC_TEST_RET_ENC_EC(ret);
  44197. ret = wc_ValidateSakkeRsk(key, id, sizeof(id), rsk, &valid);
  44198. if (ret != 0)
  44199. return WC_TEST_RET_ENC_EC(ret);
  44200. if (valid != 1)
  44201. return WC_TEST_RET_ENC_NC;
  44202. ret = wc_SetSakkeRsk(key, rsk, NULL, 0);
  44203. if (ret != 0)
  44204. return WC_TEST_RET_ENC_EC(ret);
  44205. ret = wc_SetSakkeIdentity(key, id, sizeof(id));
  44206. if (ret != 0)
  44207. return WC_TEST_RET_ENC_EC(ret);
  44208. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  44209. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  44210. auth, sizeof(auth));
  44211. if (ret != 0)
  44212. return WC_TEST_RET_ENC_EC(ret);
  44213. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  44214. return WC_TEST_RET_ENC_NC;
  44215. ret = wc_MakeSakkePointI(key, id, sizeof(id));
  44216. if (ret != 0)
  44217. return WC_TEST_RET_ENC_EC(ret);
  44218. iTableLen = 0;
  44219. ret = wc_GenerateSakkePointITable(key, NULL, &iTableLen);
  44220. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44221. return WC_TEST_RET_ENC_EC(ret);
  44222. if (iTableLen != 0) {
  44223. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44224. if (iTable == NULL)
  44225. return WC_TEST_RET_ENC_ERRNO;
  44226. ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen);
  44227. if (ret != 0)
  44228. return WC_TEST_RET_ENC_EC(ret);
  44229. }
  44230. len = 0;
  44231. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  44232. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44233. return WC_TEST_RET_ENC_EC(ret);
  44234. if (len > 0) {
  44235. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44236. if (table == NULL)
  44237. return WC_TEST_RET_ENC_ERRNO;
  44238. ret = wc_GenerateSakkeRskTable(key, rsk, table, &len);
  44239. if (ret != 0)
  44240. return WC_TEST_RET_ENC_EC(ret);
  44241. }
  44242. ret = wc_SetSakkeRsk(key, rsk, table, len);
  44243. if (ret != 0)
  44244. return WC_TEST_RET_ENC_EC(ret);
  44245. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  44246. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  44247. auth, sizeof(auth));
  44248. if (ret != 0)
  44249. return WC_TEST_RET_ENC_EC(ret);
  44250. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  44251. return WC_TEST_RET_ENC_NC;
  44252. /* Don't reference table that is about to be freed. */
  44253. ret = wc_ClearSakkePointITable(key);
  44254. if (ret != 0)
  44255. return WC_TEST_RET_ENC_EC(ret);
  44256. /* Dispose of tables */
  44257. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44258. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44259. /* Make sure the key public key is exportable - convert to Montgomery form
  44260. * in Validation.
  44261. */
  44262. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 1);
  44263. if (ret != 0)
  44264. return WC_TEST_RET_ENC_EC(ret);
  44265. if (sz != sizeof(pubData))
  44266. return WC_TEST_RET_ENC_NC;
  44267. if (XMEMCMP(pubKey, pubData, sizeof(pubData)) != 0)
  44268. return WC_TEST_RET_ENC_NC;
  44269. sz = sizeof(pubData) + 1;
  44270. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 0);
  44271. if (ret != 0)
  44272. return WC_TEST_RET_ENC_EC(ret);
  44273. if (sz != sizeof(pubData) + 1)
  44274. return WC_TEST_RET_ENC_NC;
  44275. if (pubKey[0] != 0x04)
  44276. return WC_TEST_RET_ENC_NC;
  44277. if (XMEMCMP(pubKey + 1, pubData, sizeof(pubData)) != 0)
  44278. return WC_TEST_RET_ENC_NC;
  44279. return 0;
  44280. }
  44281. static wc_test_ret_t sakke_kat_encapsulate_test(SakkeKey* key)
  44282. {
  44283. static const byte pubData[] = {
  44284. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  44285. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  44286. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  44287. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  44288. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  44289. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  44290. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  44291. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  44292. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  44293. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  44294. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  44295. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  44296. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  44297. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  44298. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  44299. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  44300. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  44301. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  44302. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  44303. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  44304. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  44305. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  44306. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  44307. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  44308. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  44309. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  44310. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  44311. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  44312. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  44313. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  44314. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  44315. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  44316. };
  44317. static const byte id[] = {
  44318. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  44319. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  44320. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  44321. 0x33, 0x00
  44322. };
  44323. static const word32 idSz = sizeof(id);
  44324. byte ssv[] = {
  44325. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  44326. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  44327. };
  44328. static const word16 ssvSz = sizeof(ssv);
  44329. static const byte expAuth[] = {
  44330. 0x04,
  44331. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  44332. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  44333. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  44334. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  44335. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  44336. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  44337. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  44338. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  44339. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  44340. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  44341. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  44342. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  44343. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  44344. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  44345. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  44346. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  44347. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  44348. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  44349. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  44350. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  44351. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  44352. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  44353. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  44354. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  44355. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  44356. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  44357. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  44358. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  44359. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  44360. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  44361. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  44362. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  44363. };
  44364. static const byte encSsv[] = {
  44365. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  44366. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  44367. };
  44368. wc_test_ret_t ret;
  44369. byte auth[257];
  44370. word16 authSz = sizeof(auth);
  44371. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44372. if (ret != 0)
  44373. return WC_TEST_RET_ENC_EC(ret);
  44374. ret = wc_SetSakkeIdentity(key, id, idSz);
  44375. if (ret != 0)
  44376. return WC_TEST_RET_ENC_EC(ret);
  44377. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44378. auth, &authSz);
  44379. if (ret != 0)
  44380. return WC_TEST_RET_ENC_EC(ret);
  44381. if (authSz != 257)
  44382. return WC_TEST_RET_ENC_NC;
  44383. if (XMEMCMP(ssv, encSsv, ssvSz) != 0)
  44384. return WC_TEST_RET_ENC_NC;
  44385. if (XMEMCMP(auth, expAuth, authSz) != 0)
  44386. return WC_TEST_RET_ENC_NC;
  44387. return 0;
  44388. }
  44389. static wc_test_ret_t sakke_make_key_test(SakkeKey* priv, SakkeKey* pub, SakkeKey* key,
  44390. WC_RNG* rng, ecc_point* rsk)
  44391. {
  44392. wc_test_ret_t ret;
  44393. byte data[440];
  44394. byte pubData[257];
  44395. word32 sz;
  44396. char mail[] = "test@wolfssl.com";
  44397. byte* id = (byte*)mail;
  44398. word32 idSz = (word32)XSTRLEN(mail);
  44399. int valid;
  44400. ecc_point* pubKey = rsk;
  44401. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44402. if (ret != 0)
  44403. return WC_TEST_RET_ENC_EC(ret);
  44404. ret = wc_MakeSakkeKey(priv, rng);
  44405. if (ret != 0)
  44406. return WC_TEST_RET_ENC_EC(ret);
  44407. ret = wc_ExportSakkeKey(priv, NULL, &sz);
  44408. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44409. return WC_TEST_RET_ENC_EC(ret);
  44410. if (sz != 384)
  44411. return WC_TEST_RET_ENC_NC;
  44412. sz--;
  44413. ret = wc_ExportSakkeKey(priv, data, &sz);
  44414. if (ret == 0)
  44415. return WC_TEST_RET_ENC_NC;
  44416. sz++;
  44417. ret = wc_ExportSakkeKey(priv, data, &sz);
  44418. if (ret != 0)
  44419. return WC_TEST_RET_ENC_EC(ret);
  44420. if (sz != 384)
  44421. return WC_TEST_RET_ENC_NC;
  44422. ret = wc_ImportSakkeKey(key, data, sz - 1);
  44423. if (ret == 0)
  44424. return WC_TEST_RET_ENC_NC;
  44425. ret = wc_ImportSakkeKey(key, data, sz);
  44426. if (ret != 0)
  44427. return WC_TEST_RET_ENC_EC(ret);
  44428. wc_FreeSakkeKey(key);
  44429. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44430. if (ret != 0)
  44431. return WC_TEST_RET_ENC_EC(ret);
  44432. ret = wc_ExportSakkePrivateKey(priv, NULL, &sz);
  44433. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44434. return WC_TEST_RET_ENC_EC(ret);
  44435. if (sz != 128)
  44436. return WC_TEST_RET_ENC_NC;
  44437. sz--;
  44438. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44439. if (ret == 0)
  44440. return WC_TEST_RET_ENC_NC;
  44441. sz++;
  44442. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44443. if (ret != 0)
  44444. return WC_TEST_RET_ENC_EC(ret);
  44445. if (sz != 128)
  44446. return WC_TEST_RET_ENC_NC;
  44447. ret = wc_ImportSakkePrivateKey(key, data, sz - 1);
  44448. if (ret == 0)
  44449. return WC_TEST_RET_ENC_NC;
  44450. ret = wc_ImportSakkePrivateKey(key, data, sz);
  44451. if (ret != 0)
  44452. return WC_TEST_RET_ENC_EC(ret);
  44453. ret = wc_MakeSakkePublicKey(key, pubKey);
  44454. if (ret != 0)
  44455. return WC_TEST_RET_ENC_EC(ret);
  44456. ret = wc_ExportSakkePublicKey(priv, NULL, &sz, 1);
  44457. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44458. return WC_TEST_RET_ENC_EC(ret);
  44459. if (sz != 256)
  44460. return WC_TEST_RET_ENC_NC;
  44461. sz--;
  44462. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44463. if (ret == 0)
  44464. return WC_TEST_RET_ENC_NC;
  44465. sz++;
  44466. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44467. if (ret != 0)
  44468. return WC_TEST_RET_ENC_EC(ret);
  44469. if (sz != 256)
  44470. return WC_TEST_RET_ENC_NC;
  44471. ret = wc_ImportSakkePublicKey(pub, data, sz - 1, 1);
  44472. if (ret == 0)
  44473. return WC_TEST_RET_ENC_NC;
  44474. ret = wc_ImportSakkePublicKey(pub, data, sz, 1);
  44475. if (ret != 0)
  44476. return WC_TEST_RET_ENC_EC(ret);
  44477. ret = wc_ExportSakkePublicKey(pub, pubData, &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. if (XMEMCMP(data, pubData, sz) != 0)
  44483. return WC_TEST_RET_ENC_NC;
  44484. ret = wc_MakeSakkeRsk(priv, id, idSz, rsk);
  44485. if (ret != 0)
  44486. return WC_TEST_RET_ENC_EC(ret);
  44487. ret = wc_ValidateSakkeRsk(priv, id, idSz, rsk, &valid);
  44488. if (ret != 0)
  44489. return WC_TEST_RET_ENC_EC(ret);
  44490. if (valid != 1)
  44491. return WC_TEST_RET_ENC_NC;
  44492. ret = wc_ValidateSakkeRsk(pub, id, idSz, rsk, &valid);
  44493. if (ret != 0)
  44494. return WC_TEST_RET_ENC_EC(ret);
  44495. if (valid != 1)
  44496. return WC_TEST_RET_ENC_NC;
  44497. sz = sizeof(data);
  44498. ret = wc_EncodeSakkeRsk(priv, rsk, data, &sz, 1);
  44499. if (ret != 0)
  44500. return WC_TEST_RET_ENC_EC(ret);
  44501. if (sz != 256)
  44502. return WC_TEST_RET_ENC_NC;
  44503. ret = wc_DecodeSakkeRsk(priv, data, sz, rsk);
  44504. if (ret != 0)
  44505. return WC_TEST_RET_ENC_EC(ret);
  44506. sz = sizeof(pubData);
  44507. ret = wc_EncodeSakkeRsk(priv, rsk, pubData, &sz, 0);
  44508. if (ret != 0)
  44509. return WC_TEST_RET_ENC_EC(ret);
  44510. if (sz != sizeof(pubData))
  44511. return WC_TEST_RET_ENC_NC;
  44512. ret = wc_DecodeSakkeRsk(priv, pubData, sz, rsk);
  44513. if (ret != 0)
  44514. return WC_TEST_RET_ENC_EC(ret);
  44515. wc_FreeSakkeKey(key);
  44516. return 0;
  44517. }
  44518. static wc_test_ret_t sakke_op_test(SakkeKey* priv, SakkeKey* pub, WC_RNG* rng,
  44519. ecc_point* rsk)
  44520. {
  44521. wc_test_ret_t ret;
  44522. byte ssv[16];
  44523. word16 ssvSz;
  44524. byte auth[257];
  44525. word16 authSz;
  44526. char mail[] = "test@wolfssl.com";
  44527. byte* id = (byte*)mail;
  44528. word32 idSz = (word32)XSTRLEN(mail);
  44529. byte pointI[256];
  44530. word32 sz;
  44531. ret = wc_GenerateSakkeSSV(pub, rng, NULL, &ssvSz);
  44532. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44533. return WC_TEST_RET_ENC_EC(ret);
  44534. if (ssvSz != 16)
  44535. return WC_TEST_RET_ENC_NC;
  44536. ssvSz += 128;
  44537. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44538. if (ret == 0)
  44539. return WC_TEST_RET_ENC_NC;
  44540. ssvSz -= 128;
  44541. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44542. if (ret != 0)
  44543. return WC_TEST_RET_ENC_EC(ret);
  44544. if (ssvSz != 16)
  44545. return WC_TEST_RET_ENC_NC;
  44546. ret = wc_GetSakkeAuthSize(pub, &authSz);
  44547. if (ret != 0)
  44548. return WC_TEST_RET_ENC_EC(ret);
  44549. ret = wc_SetSakkeIdentity(pub, id, idSz);
  44550. if (ret != 0)
  44551. return WC_TEST_RET_ENC_EC(ret);
  44552. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44553. NULL, &authSz);
  44554. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44555. return WC_TEST_RET_ENC_EC(ret);
  44556. if (authSz != 257)
  44557. return WC_TEST_RET_ENC_NC;
  44558. authSz--;
  44559. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44560. auth, &authSz);
  44561. if (ret == 0)
  44562. return WC_TEST_RET_ENC_NC;
  44563. authSz++;
  44564. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44565. auth, &authSz);
  44566. if (ret != 0)
  44567. return WC_TEST_RET_ENC_EC(ret);
  44568. if (authSz != 257)
  44569. return WC_TEST_RET_ENC_NC;
  44570. ret = wc_GetSakkePointI(pub, NULL, &sz);
  44571. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44572. return WC_TEST_RET_ENC_EC(ret);
  44573. if (sz != 256)
  44574. return WC_TEST_RET_ENC_NC;
  44575. ret = wc_GetSakkePointI(pub, pointI, &sz);
  44576. if (ret != 0)
  44577. return WC_TEST_RET_ENC_EC(ret);
  44578. if (sz != 256)
  44579. return WC_TEST_RET_ENC_NC;
  44580. /* Bogus identity - make it check and regenerate I. */
  44581. ret = wc_MakeSakkePointI(pub, ssv, ssvSz);
  44582. if (ret != 0)
  44583. return WC_TEST_RET_ENC_EC(ret);
  44584. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44585. auth, &authSz);
  44586. if (ret != 0)
  44587. return WC_TEST_RET_ENC_EC(ret);
  44588. if (authSz != 257)
  44589. return WC_TEST_RET_ENC_NC;
  44590. ret = wc_SetSakkeRsk(priv, rsk, NULL, 0);
  44591. if (ret != 0)
  44592. return WC_TEST_RET_ENC_EC(ret);
  44593. ret = wc_SetSakkeIdentity(priv, id, idSz);
  44594. if (ret != 0)
  44595. return WC_TEST_RET_ENC_EC(ret);
  44596. authSz--;
  44597. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44598. authSz);
  44599. if (ret == 0)
  44600. return WC_TEST_RET_ENC_NC;
  44601. authSz++;
  44602. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44603. authSz);
  44604. if (ret != 0)
  44605. return WC_TEST_RET_ENC_EC(ret);
  44606. ssv[0] ^= 0x80;
  44607. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44608. authSz);
  44609. if (ret != WC_NO_ERR_TRACE(SAKKE_VERIFY_FAIL_E))
  44610. return WC_TEST_RET_ENC_EC(ret);
  44611. ssv[0] ^= 0x80;
  44612. /* Bogus identity - make it check and regenerate I. */
  44613. ret = wc_MakeSakkePointI(pub, ssv, idSz);
  44614. if (ret != 0)
  44615. return WC_TEST_RET_ENC_EC(ret);
  44616. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44617. authSz);
  44618. if (ret != 0)
  44619. return WC_TEST_RET_ENC_EC(ret);
  44620. return 0;
  44621. }
  44622. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void)
  44623. {
  44624. wc_test_ret_t ret = 0;
  44625. WC_RNG rng;
  44626. int rng_inited = 0;
  44627. SakkeKey* priv = NULL;
  44628. SakkeKey* pub = NULL;
  44629. SakkeKey* key = NULL;
  44630. ecc_point* rsk = NULL;
  44631. WOLFSSL_ENTER("sakke_test");
  44632. priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44633. DYNAMIC_TYPE_TMP_BUFFER);
  44634. if (priv == NULL)
  44635. ret = WC_TEST_RET_ENC_NC;
  44636. else
  44637. XMEMSET(priv, 0, sizeof(*priv));
  44638. if (ret == 0) {
  44639. pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44640. DYNAMIC_TYPE_TMP_BUFFER);
  44641. if (pub == NULL)
  44642. ret = WC_TEST_RET_ENC_NC;
  44643. else
  44644. XMEMSET(pub, 0, sizeof(*pub));
  44645. }
  44646. if (ret == 0) {
  44647. key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44648. DYNAMIC_TYPE_TMP_BUFFER);
  44649. if (key == NULL)
  44650. ret = WC_TEST_RET_ENC_NC;
  44651. else
  44652. XMEMSET(key, 0, sizeof(*key));
  44653. }
  44654. if (ret == 0) {
  44655. #ifndef HAVE_FIPS
  44656. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  44657. #else
  44658. ret = wc_InitRng(&rng);
  44659. #endif
  44660. if (ret == 0)
  44661. rng_inited = 1;
  44662. else
  44663. ret = WC_TEST_RET_ENC_EC(ret);
  44664. }
  44665. if (ret == 0) {
  44666. rsk = wc_ecc_new_point();
  44667. if (rsk == NULL)
  44668. ret = WC_TEST_RET_ENC_NC;
  44669. }
  44670. if (ret == 0) {
  44671. ret = wc_InitSakkeKey(pub, HEAP_HINT, INVALID_DEVID);
  44672. if (ret != 0)
  44673. ret = WC_TEST_RET_ENC_EC(ret);
  44674. }
  44675. if (ret == 0) {
  44676. ret = wc_InitSakkeKey(priv, HEAP_HINT, INVALID_DEVID);
  44677. if (ret != 0)
  44678. ret = WC_TEST_RET_ENC_EC(ret);
  44679. }
  44680. if (ret == 0) {
  44681. ret = sakke_api_test(&rng, key, rsk);
  44682. }
  44683. if (ret == 0) {
  44684. ret = sakke_kat_derive_test(pub, rsk);
  44685. }
  44686. if (ret == 0) {
  44687. ret = sakke_kat_encapsulate_test(pub);
  44688. }
  44689. if (ret == 0) {
  44690. ret = sakke_make_key_test(priv, pub, key, &rng, rsk);
  44691. }
  44692. if (ret == 0) {
  44693. ret = sakke_op_test(priv, pub, &rng, rsk);
  44694. }
  44695. if (rsk != NULL) {
  44696. wc_ecc_forcezero_point(rsk);
  44697. wc_ecc_del_point(rsk);
  44698. }
  44699. if (rng_inited)
  44700. wc_FreeRng(&rng);
  44701. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44702. if (pub != NULL) {
  44703. wc_FreeSakkeKey(pub);
  44704. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44705. }
  44706. if (priv != NULL) {
  44707. wc_FreeSakkeKey(priv);
  44708. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44709. }
  44710. return ret;
  44711. }
  44712. #endif /* WOLFCRYPT_HAVE_SAKKE */
  44713. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  44714. typedef struct CMAC_Test_Case {
  44715. int type;
  44716. int partial;
  44717. const byte* m;
  44718. word32 mSz;
  44719. const byte* k;
  44720. word32 kSz;
  44721. const byte* t;
  44722. word32 tSz;
  44723. } CMAC_Test_Case;
  44724. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void)
  44725. {
  44726. #ifdef WOLFSSL_AES_128
  44727. WOLFSSL_SMALL_STACK_STATIC const byte k128[] =
  44728. {
  44729. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  44730. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  44731. };
  44732. #define KLEN_128 (sizeof(k128))
  44733. #endif
  44734. #ifdef WOLFSSL_AES_192
  44735. WOLFSSL_SMALL_STACK_STATIC const byte k192[] =
  44736. {
  44737. 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
  44738. 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
  44739. 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
  44740. };
  44741. #define KLEN_192 (sizeof(k192))
  44742. #endif
  44743. #ifdef WOLFSSL_AES_256
  44744. WOLFSSL_SMALL_STACK_STATIC const byte k256[] =
  44745. {
  44746. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  44747. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  44748. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  44749. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  44750. };
  44751. #define KLEN_256 (sizeof(k256))
  44752. #endif
  44753. WOLFSSL_SMALL_STACK_STATIC const byte m[] =
  44754. {
  44755. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  44756. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  44757. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  44758. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  44759. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  44760. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  44761. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  44762. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  44763. };
  44764. #define MLEN_0 (0)
  44765. #define MLEN_128 (128/8)
  44766. #define MLEN_320 (320/8)
  44767. #define MLEN_319 (MLEN_320 - 1)
  44768. #define MLEN_512 (512/8)
  44769. #ifdef WOLFSSL_AES_128
  44770. WOLFSSL_SMALL_STACK_STATIC const byte t128_0[] =
  44771. {
  44772. 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
  44773. 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
  44774. };
  44775. WOLFSSL_SMALL_STACK_STATIC const byte t128_128[] =
  44776. {
  44777. 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
  44778. 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
  44779. };
  44780. WOLFSSL_SMALL_STACK_STATIC const byte t128_319[] =
  44781. {
  44782. 0x2c, 0x17, 0x84, 0x4c, 0x93, 0x1c, 0x07, 0x95,
  44783. 0x15, 0x92, 0x73, 0x0a, 0x34, 0xd0, 0xd9, 0xd2
  44784. };
  44785. WOLFSSL_SMALL_STACK_STATIC const byte t128_320[] =
  44786. {
  44787. 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
  44788. 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
  44789. };
  44790. WOLFSSL_SMALL_STACK_STATIC const byte t128_512[] =
  44791. {
  44792. 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
  44793. 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
  44794. };
  44795. #endif
  44796. #ifdef WOLFSSL_AES_192
  44797. WOLFSSL_SMALL_STACK_STATIC const byte t192_0[] =
  44798. {
  44799. 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
  44800. 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
  44801. };
  44802. WOLFSSL_SMALL_STACK_STATIC const byte t192_128[] =
  44803. {
  44804. 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
  44805. 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
  44806. };
  44807. WOLFSSL_SMALL_STACK_STATIC const byte t192_320[] =
  44808. {
  44809. 0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
  44810. 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e
  44811. };
  44812. WOLFSSL_SMALL_STACK_STATIC const byte t192_512[] =
  44813. {
  44814. 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
  44815. 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
  44816. };
  44817. #endif
  44818. #ifdef WOLFSSL_AES_256
  44819. WOLFSSL_SMALL_STACK_STATIC const byte t256_0[] =
  44820. {
  44821. 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
  44822. 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
  44823. };
  44824. WOLFSSL_SMALL_STACK_STATIC const byte t256_128[] =
  44825. {
  44826. 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
  44827. 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
  44828. };
  44829. WOLFSSL_SMALL_STACK_STATIC const byte t256_320[] =
  44830. {
  44831. 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
  44832. 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6
  44833. };
  44834. WOLFSSL_SMALL_STACK_STATIC const byte t256_512[] =
  44835. {
  44836. 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
  44837. 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
  44838. };
  44839. #endif
  44840. const CMAC_Test_Case testCases[] =
  44841. {
  44842. #ifdef WOLFSSL_AES_128
  44843. {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, WC_AES_BLOCK_SIZE},
  44844. {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, WC_AES_BLOCK_SIZE},
  44845. {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, WC_AES_BLOCK_SIZE},
  44846. {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, WC_AES_BLOCK_SIZE},
  44847. {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, WC_AES_BLOCK_SIZE},
  44848. #endif
  44849. #ifdef WOLFSSL_AES_192
  44850. {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, WC_AES_BLOCK_SIZE},
  44851. {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, WC_AES_BLOCK_SIZE},
  44852. {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, WC_AES_BLOCK_SIZE},
  44853. {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, WC_AES_BLOCK_SIZE},
  44854. #endif
  44855. #ifdef WOLFSSL_AES_256
  44856. {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, WC_AES_BLOCK_SIZE},
  44857. {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, WC_AES_BLOCK_SIZE},
  44858. {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, WC_AES_BLOCK_SIZE},
  44859. {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, WC_AES_BLOCK_SIZE},
  44860. #endif
  44861. #ifdef WOLFSSL_AES_128
  44862. {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, WC_AES_BLOCK_SIZE}
  44863. #endif
  44864. };
  44865. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44866. Cmac *cmac;
  44867. #else
  44868. Cmac cmac[1];
  44869. #endif
  44870. byte tag[WC_AES_BLOCK_SIZE];
  44871. const CMAC_Test_Case* tc;
  44872. word32 i, tagSz;
  44873. wc_test_ret_t ret;
  44874. WOLFSSL_ENTER("cmac_test");
  44875. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44876. if ((cmac = (Cmac *)XMALLOC(sizeof *cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC)) == NULL)
  44877. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  44878. #endif
  44879. for (i = 0, tc = testCases;
  44880. i < sizeof(testCases)/sizeof(CMAC_Test_Case);
  44881. i++, tc++) {
  44882. XMEMSET(tag, 0, sizeof(tag));
  44883. tagSz = WC_AES_BLOCK_SIZE;
  44884. #if !defined(HAVE_FIPS) || \
  44885. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)
  44886. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44887. #else
  44888. ret = wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL);
  44889. #endif
  44890. if (ret != 0)
  44891. {
  44892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44893. }
  44894. if (tc->partial) {
  44895. ret = wc_CmacUpdate(cmac, tc->m,
  44896. tc->mSz/2 - tc->partial);
  44897. if (ret != 0)
  44898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44899. ret = wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial,
  44900. tc->mSz/2 + tc->partial);
  44901. if (ret != 0)
  44902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44903. }
  44904. else {
  44905. ret = wc_CmacUpdate(cmac, tc->m, tc->mSz);
  44906. if (ret != 0)
  44907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44908. }
  44909. ret = wc_CmacFinal(cmac, tag, &tagSz);
  44910. if (ret != 0)
  44911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44912. if (XMEMCMP(tag, tc->t, WC_AES_BLOCK_SIZE) != 0)
  44913. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44914. XMEMSET(tag, 0, sizeof(tag));
  44915. tagSz = sizeof(tag);
  44916. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44917. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44918. tc->k, tc->kSz, NULL, devId);
  44919. #else
  44920. ret = wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz,
  44921. tc->k, tc->kSz);
  44922. #endif
  44923. if (ret != 0)
  44924. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44925. if (XMEMCMP(tag, tc->t, WC_AES_BLOCK_SIZE) != 0)
  44926. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44927. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44928. ret = wc_AesCmacVerify_ex(cmac, tc->t, tc->tSz, tc->m, tc->mSz,
  44929. tc->k, tc->kSz, HEAP_HINT, devId);
  44930. #else
  44931. ret = wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz,
  44932. tc->k, tc->kSz);
  44933. #endif
  44934. if (ret != 0)
  44935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44936. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44937. /* Test that keyless generate with init is the same */
  44938. XMEMSET(tag, 0, sizeof(tag));
  44939. tagSz = sizeof(tag);
  44940. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44941. if (ret != 0) {
  44942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44943. }
  44944. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44945. NULL, 0, HEAP_HINT, devId);
  44946. if (ret != 0) {
  44947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44948. }
  44949. #endif
  44950. }
  44951. ret = 0;
  44952. out:
  44953. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44954. XFREE(cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC);
  44955. #endif
  44956. return ret;
  44957. }
  44958. #endif /* !NO_AES && WOLFSSL_CMAC */
  44959. #if defined(WOLFSSL_SIPHASH)
  44960. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44961. /* Test vectors from:
  44962. * https://github.com/veorq/SipHash/blob/master/vectors.h
  44963. */
  44964. static const unsigned char siphash_key[SIPHASH_KEY_SIZE] = {
  44965. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44966. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  44967. };
  44968. static const unsigned char siphash_msg[64] = {
  44969. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44970. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  44971. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  44972. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  44973. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  44974. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  44975. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  44976. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
  44977. };
  44978. static const unsigned char siphash_r8[64][SIPHASH_MAC_SIZE_8] = {
  44979. { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, },
  44980. { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, },
  44981. { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, },
  44982. { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, },
  44983. { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, },
  44984. { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, },
  44985. { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, },
  44986. { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, },
  44987. { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, },
  44988. { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, },
  44989. { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, },
  44990. { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, },
  44991. { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, },
  44992. { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, },
  44993. { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, },
  44994. { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, },
  44995. { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, },
  44996. { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, },
  44997. { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, },
  44998. { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, },
  44999. { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, },
  45000. { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, },
  45001. { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, },
  45002. { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, },
  45003. { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, },
  45004. { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, },
  45005. { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, },
  45006. { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, },
  45007. { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, },
  45008. { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, },
  45009. { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, },
  45010. { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, },
  45011. { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, },
  45012. { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, },
  45013. { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, },
  45014. { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, },
  45015. { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, },
  45016. { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, },
  45017. { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, },
  45018. { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, },
  45019. { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, },
  45020. { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, },
  45021. { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, },
  45022. { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, },
  45023. { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, },
  45024. { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, },
  45025. { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, },
  45026. { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, },
  45027. { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, },
  45028. { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, },
  45029. { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, },
  45030. { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, },
  45031. { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, },
  45032. { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, },
  45033. { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, },
  45034. { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, },
  45035. { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, },
  45036. { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, },
  45037. { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, },
  45038. { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, },
  45039. { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, },
  45040. { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, },
  45041. { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, },
  45042. { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, },
  45043. };
  45044. static const unsigned char siphash_r16[64][SIPHASH_MAC_SIZE_16] = {
  45045. { 0xa3, 0x81, 0x7f, 0x04, 0xba, 0x25, 0xa8, 0xe6,
  45046. 0x6d, 0xf6, 0x72, 0x14, 0xc7, 0x55, 0x02, 0x93, },
  45047. { 0xda, 0x87, 0xc1, 0xd8, 0x6b, 0x99, 0xaf, 0x44,
  45048. 0x34, 0x76, 0x59, 0x11, 0x9b, 0x22, 0xfc, 0x45, },
  45049. { 0x81, 0x77, 0x22, 0x8d, 0xa4, 0xa4, 0x5d, 0xc7,
  45050. 0xfc, 0xa3, 0x8b, 0xde, 0xf6, 0x0a, 0xff, 0xe4, },
  45051. { 0x9c, 0x70, 0xb6, 0x0c, 0x52, 0x67, 0xa9, 0x4e,
  45052. 0x5f, 0x33, 0xb6, 0xb0, 0x29, 0x85, 0xed, 0x51, },
  45053. { 0xf8, 0x81, 0x64, 0xc1, 0x2d, 0x9c, 0x8f, 0xaf,
  45054. 0x7d, 0x0f, 0x6e, 0x7c, 0x7b, 0xcd, 0x55, 0x79, },
  45055. { 0x13, 0x68, 0x87, 0x59, 0x80, 0x77, 0x6f, 0x88,
  45056. 0x54, 0x52, 0x7a, 0x07, 0x69, 0x0e, 0x96, 0x27, },
  45057. { 0x14, 0xee, 0xca, 0x33, 0x8b, 0x20, 0x86, 0x13,
  45058. 0x48, 0x5e, 0xa0, 0x30, 0x8f, 0xd7, 0xa1, 0x5e, },
  45059. { 0xa1, 0xf1, 0xeb, 0xbe, 0xd8, 0xdb, 0xc1, 0x53,
  45060. 0xc0, 0xb8, 0x4a, 0xa6, 0x1f, 0xf0, 0x82, 0x39, },
  45061. { 0x3b, 0x62, 0xa9, 0xba, 0x62, 0x58, 0xf5, 0x61,
  45062. 0x0f, 0x83, 0xe2, 0x64, 0xf3, 0x14, 0x97, 0xb4, },
  45063. { 0x26, 0x44, 0x99, 0x06, 0x0a, 0xd9, 0xba, 0xab,
  45064. 0xc4, 0x7f, 0x8b, 0x02, 0xbb, 0x6d, 0x71, 0xed, },
  45065. { 0x00, 0x11, 0x0d, 0xc3, 0x78, 0x14, 0x69, 0x56,
  45066. 0xc9, 0x54, 0x47, 0xd3, 0xf3, 0xd0, 0xfb, 0xba, },
  45067. { 0x01, 0x51, 0xc5, 0x68, 0x38, 0x6b, 0x66, 0x77,
  45068. 0xa2, 0xb4, 0xdc, 0x6f, 0x81, 0xe5, 0xdc, 0x18, },
  45069. { 0xd6, 0x26, 0xb2, 0x66, 0x90, 0x5e, 0xf3, 0x58,
  45070. 0x82, 0x63, 0x4d, 0xf6, 0x85, 0x32, 0xc1, 0x25, },
  45071. { 0x98, 0x69, 0xe2, 0x47, 0xe9, 0xc0, 0x8b, 0x10,
  45072. 0xd0, 0x29, 0x93, 0x4f, 0xc4, 0xb9, 0x52, 0xf7, },
  45073. { 0x31, 0xfc, 0xef, 0xac, 0x66, 0xd7, 0xde, 0x9c,
  45074. 0x7e, 0xc7, 0x48, 0x5f, 0xe4, 0x49, 0x49, 0x02, },
  45075. { 0x54, 0x93, 0xe9, 0x99, 0x33, 0xb0, 0xa8, 0x11,
  45076. 0x7e, 0x08, 0xec, 0x0f, 0x97, 0xcf, 0xc3, 0xd9, },
  45077. { 0x6e, 0xe2, 0xa4, 0xca, 0x67, 0xb0, 0x54, 0xbb,
  45078. 0xfd, 0x33, 0x15, 0xbf, 0x85, 0x23, 0x05, 0x77, },
  45079. { 0x47, 0x3d, 0x06, 0xe8, 0x73, 0x8d, 0xb8, 0x98,
  45080. 0x54, 0xc0, 0x66, 0xc4, 0x7a, 0xe4, 0x77, 0x40, },
  45081. { 0xa4, 0x26, 0xe5, 0xe4, 0x23, 0xbf, 0x48, 0x85,
  45082. 0x29, 0x4d, 0xa4, 0x81, 0xfe, 0xae, 0xf7, 0x23, },
  45083. { 0x78, 0x01, 0x77, 0x31, 0xcf, 0x65, 0xfa, 0xb0,
  45084. 0x74, 0xd5, 0x20, 0x89, 0x52, 0x51, 0x2e, 0xb1, },
  45085. { 0x9e, 0x25, 0xfc, 0x83, 0x3f, 0x22, 0x90, 0x73,
  45086. 0x3e, 0x93, 0x44, 0xa5, 0xe8, 0x38, 0x39, 0xeb, },
  45087. { 0x56, 0x8e, 0x49, 0x5a, 0xbe, 0x52, 0x5a, 0x21,
  45088. 0x8a, 0x22, 0x14, 0xcd, 0x3e, 0x07, 0x1d, 0x12, },
  45089. { 0x4a, 0x29, 0xb5, 0x45, 0x52, 0xd1, 0x6b, 0x9a,
  45090. 0x46, 0x9c, 0x10, 0x52, 0x8e, 0xff, 0x0a, 0xae, },
  45091. { 0xc9, 0xd1, 0x84, 0xdd, 0xd5, 0xa9, 0xf5, 0xe0,
  45092. 0xcf, 0x8c, 0xe2, 0x9a, 0x9a, 0xbf, 0x69, 0x1c, },
  45093. { 0x2d, 0xb4, 0x79, 0xae, 0x78, 0xbd, 0x50, 0xd8,
  45094. 0x88, 0x2a, 0x8a, 0x17, 0x8a, 0x61, 0x32, 0xad, },
  45095. { 0x8e, 0xce, 0x5f, 0x04, 0x2d, 0x5e, 0x44, 0x7b,
  45096. 0x50, 0x51, 0xb9, 0xea, 0xcb, 0x8d, 0x8f, 0x6f, },
  45097. { 0x9c, 0x0b, 0x53, 0xb4, 0xb3, 0xc3, 0x07, 0xe8,
  45098. 0x7e, 0xae, 0xe0, 0x86, 0x78, 0x14, 0x1f, 0x66, },
  45099. { 0xab, 0xf2, 0x48, 0xaf, 0x69, 0xa6, 0xea, 0xe4,
  45100. 0xbf, 0xd3, 0xeb, 0x2f, 0x12, 0x9e, 0xeb, 0x94, },
  45101. { 0x06, 0x64, 0xda, 0x16, 0x68, 0x57, 0x4b, 0x88,
  45102. 0xb9, 0x35, 0xf3, 0x02, 0x73, 0x58, 0xae, 0xf4, },
  45103. { 0xaa, 0x4b, 0x9d, 0xc4, 0xbf, 0x33, 0x7d, 0xe9,
  45104. 0x0c, 0xd4, 0xfd, 0x3c, 0x46, 0x7c, 0x6a, 0xb7, },
  45105. { 0xea, 0x5c, 0x7f, 0x47, 0x1f, 0xaf, 0x6b, 0xde,
  45106. 0x2b, 0x1a, 0xd7, 0xd4, 0x68, 0x6d, 0x22, 0x87, },
  45107. { 0x29, 0x39, 0xb0, 0x18, 0x32, 0x23, 0xfa, 0xfc,
  45108. 0x17, 0x23, 0xde, 0x4f, 0x52, 0xc4, 0x3d, 0x35, },
  45109. { 0x7c, 0x39, 0x56, 0xca, 0x5e, 0xea, 0xfc, 0x3e,
  45110. 0x36, 0x3e, 0x9d, 0x55, 0x65, 0x46, 0xeb, 0x68, },
  45111. { 0x77, 0xc6, 0x07, 0x71, 0x46, 0xf0, 0x1c, 0x32,
  45112. 0xb6, 0xb6, 0x9d, 0x5f, 0x4e, 0xa9, 0xff, 0xcf, },
  45113. { 0x37, 0xa6, 0x98, 0x6c, 0xb8, 0x84, 0x7e, 0xdf,
  45114. 0x09, 0x25, 0xf0, 0xf1, 0x30, 0x9b, 0x54, 0xde, },
  45115. { 0xa7, 0x05, 0xf0, 0xe6, 0x9d, 0xa9, 0xa8, 0xf9,
  45116. 0x07, 0x24, 0x1a, 0x2e, 0x92, 0x3c, 0x8c, 0xc8, },
  45117. { 0x3d, 0xc4, 0x7d, 0x1f, 0x29, 0xc4, 0x48, 0x46,
  45118. 0x1e, 0x9e, 0x76, 0xed, 0x90, 0x4f, 0x67, 0x11, },
  45119. { 0x0d, 0x62, 0xbf, 0x01, 0xe6, 0xfc, 0x0e, 0x1a,
  45120. 0x0d, 0x3c, 0x47, 0x51, 0xc5, 0xd3, 0x69, 0x2b, },
  45121. { 0x8c, 0x03, 0x46, 0x8b, 0xca, 0x7c, 0x66, 0x9e,
  45122. 0xe4, 0xfd, 0x5e, 0x08, 0x4b, 0xbe, 0xe7, 0xb5, },
  45123. { 0x52, 0x8a, 0x5b, 0xb9, 0x3b, 0xaf, 0x2c, 0x9c,
  45124. 0x44, 0x73, 0xcc, 0xe5, 0xd0, 0xd2, 0x2b, 0xd9, },
  45125. { 0xdf, 0x6a, 0x30, 0x1e, 0x95, 0xc9, 0x5d, 0xad,
  45126. 0x97, 0xae, 0x0c, 0xc8, 0xc6, 0x91, 0x3b, 0xd8, },
  45127. { 0x80, 0x11, 0x89, 0x90, 0x2c, 0x85, 0x7f, 0x39,
  45128. 0xe7, 0x35, 0x91, 0x28, 0x5e, 0x70, 0xb6, 0xdb, },
  45129. { 0xe6, 0x17, 0x34, 0x6a, 0xc9, 0xc2, 0x31, 0xbb,
  45130. 0x36, 0x50, 0xae, 0x34, 0xcc, 0xca, 0x0c, 0x5b, },
  45131. { 0x27, 0xd9, 0x34, 0x37, 0xef, 0xb7, 0x21, 0xaa,
  45132. 0x40, 0x18, 0x21, 0xdc, 0xec, 0x5a, 0xdf, 0x89, },
  45133. { 0x89, 0x23, 0x7d, 0x9d, 0xed, 0x9c, 0x5e, 0x78,
  45134. 0xd8, 0xb1, 0xc9, 0xb1, 0x66, 0xcc, 0x73, 0x42, },
  45135. { 0x4a, 0x6d, 0x80, 0x91, 0xbf, 0x5e, 0x7d, 0x65,
  45136. 0x11, 0x89, 0xfa, 0x94, 0xa2, 0x50, 0xb1, 0x4c, },
  45137. { 0x0e, 0x33, 0xf9, 0x60, 0x55, 0xe7, 0xae, 0x89,
  45138. 0x3f, 0xfc, 0x0e, 0x3d, 0xcf, 0x49, 0x29, 0x02, },
  45139. { 0xe6, 0x1c, 0x43, 0x2b, 0x72, 0x0b, 0x19, 0xd1,
  45140. 0x8e, 0xc8, 0xd8, 0x4b, 0xdc, 0x63, 0x15, 0x1b, },
  45141. { 0xf7, 0xe5, 0xae, 0xf5, 0x49, 0xf7, 0x82, 0xcf,
  45142. 0x37, 0x90, 0x55, 0xa6, 0x08, 0x26, 0x9b, 0x16, },
  45143. { 0x43, 0x8d, 0x03, 0x0f, 0xd0, 0xb7, 0xa5, 0x4f,
  45144. 0xa8, 0x37, 0xf2, 0xad, 0x20, 0x1a, 0x64, 0x03, },
  45145. { 0xa5, 0x90, 0xd3, 0xee, 0x4f, 0xbf, 0x04, 0xe3,
  45146. 0x24, 0x7e, 0x0d, 0x27, 0xf2, 0x86, 0x42, 0x3f, },
  45147. { 0x5f, 0xe2, 0xc1, 0xa1, 0x72, 0xfe, 0x93, 0xc4,
  45148. 0xb1, 0x5c, 0xd3, 0x7c, 0xae, 0xf9, 0xf5, 0x38, },
  45149. { 0x2c, 0x97, 0x32, 0x5c, 0xbd, 0x06, 0xb3, 0x6e,
  45150. 0xb2, 0x13, 0x3d, 0xd0, 0x8b, 0x3a, 0x01, 0x7c, },
  45151. { 0x92, 0xc8, 0x14, 0x22, 0x7a, 0x6b, 0xca, 0x94,
  45152. 0x9f, 0xf0, 0x65, 0x9f, 0x00, 0x2a, 0xd3, 0x9e, },
  45153. { 0xdc, 0xe8, 0x50, 0x11, 0x0b, 0xd8, 0x32, 0x8c,
  45154. 0xfb, 0xd5, 0x08, 0x41, 0xd6, 0x91, 0x1d, 0x87, },
  45155. { 0x67, 0xf1, 0x49, 0x84, 0xc7, 0xda, 0x79, 0x12,
  45156. 0x48, 0xe3, 0x2b, 0xb5, 0x92, 0x25, 0x83, 0xda, },
  45157. { 0x19, 0x38, 0xf2, 0xcf, 0x72, 0xd5, 0x4e, 0xe9,
  45158. 0x7e, 0x94, 0x16, 0x6f, 0xa9, 0x1d, 0x2a, 0x36, },
  45159. { 0x74, 0x48, 0x1e, 0x96, 0x46, 0xed, 0x49, 0xfe,
  45160. 0x0f, 0x62, 0x24, 0x30, 0x16, 0x04, 0x69, 0x8e, },
  45161. { 0x57, 0xfc, 0xa5, 0xde, 0x98, 0xa9, 0xd6, 0xd8,
  45162. 0x00, 0x64, 0x38, 0xd0, 0x58, 0x3d, 0x8a, 0x1d, },
  45163. { 0x9f, 0xec, 0xde, 0x1c, 0xef, 0xdc, 0x1c, 0xbe,
  45164. 0xd4, 0x76, 0x36, 0x74, 0xd9, 0x57, 0x53, 0x59, },
  45165. { 0xe3, 0x04, 0x0c, 0x00, 0xeb, 0x28, 0xf1, 0x53,
  45166. 0x66, 0xca, 0x73, 0xcb, 0xd8, 0x72, 0xe7, 0x40, },
  45167. { 0x76, 0x97, 0x00, 0x9a, 0x6a, 0x83, 0x1d, 0xfe,
  45168. 0xcc, 0xa9, 0x1c, 0x59, 0x93, 0x67, 0x0f, 0x7a, },
  45169. { 0x58, 0x53, 0x54, 0x23, 0x21, 0xf5, 0x67, 0xa0,
  45170. 0x05, 0xd5, 0x47, 0xa4, 0xf0, 0x47, 0x59, 0xbd, },
  45171. { 0x51, 0x50, 0xd1, 0x77, 0x2f, 0x50, 0x83, 0x4a,
  45172. 0x50, 0x3e, 0x06, 0x9a, 0x97, 0x3f, 0xbd, 0x7c, },
  45173. };
  45174. #endif
  45175. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void)
  45176. {
  45177. wc_test_ret_t ret = 0;
  45178. int i;
  45179. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  45180. unsigned char res[SIPHASH_MAC_SIZE_16];
  45181. unsigned char tmp[SIPHASH_MAC_SIZE_8];
  45182. SipHash siphash;
  45183. WOLFSSL_ENTER("siphash_test (1)");
  45184. for (i = 0; i < 64; i++) {
  45185. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45186. if (ret != 0)
  45187. return WC_TEST_RET_ENC_I(i);
  45188. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  45189. if (ret != 0)
  45190. return WC_TEST_RET_ENC_I(i);
  45191. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  45192. if (ret != 0)
  45193. return WC_TEST_RET_ENC_I(i);
  45194. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  45195. return WC_TEST_RET_ENC_I(i);
  45196. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_8);
  45197. if (ret != 0)
  45198. return WC_TEST_RET_ENC_I(i);
  45199. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  45200. return WC_TEST_RET_ENC_I(i);
  45201. }
  45202. for (i = 0; i < 64; i++) {
  45203. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_16);
  45204. if (ret != 0)
  45205. return WC_TEST_RET_ENC_I(i);
  45206. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  45207. if (ret != 0)
  45208. return WC_TEST_RET_ENC_I(i);
  45209. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  45210. if (ret != 0)
  45211. return WC_TEST_RET_ENC_I(i);
  45212. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  45213. return WC_TEST_RET_ENC_I(i);
  45214. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_16);
  45215. if (ret != 0)
  45216. return WC_TEST_RET_ENC_I(i);
  45217. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  45218. return WC_TEST_RET_ENC_I(i);
  45219. }
  45220. #else
  45221. WOLFSSL_ENTER("siphash_test (1)");
  45222. #endif
  45223. /* Testing bad parameters. */
  45224. ret = wc_InitSipHash(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_InitSipHash(NULL, siphash_key, 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_InitSipHash(&siphash, NULL, 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_InitSipHash(&siphash, siphash_key, 7);
  45234. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45235. return WC_TEST_RET_ENC_EC(ret);
  45236. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45237. if (ret != 0)
  45238. return WC_TEST_RET_ENC_EC(ret);
  45239. ret = wc_SipHashUpdate(NULL, NULL, 0);
  45240. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45241. return WC_TEST_RET_ENC_EC(ret);
  45242. ret = wc_SipHashUpdate(&siphash, NULL, 1);
  45243. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45244. return WC_TEST_RET_ENC_EC(ret);
  45245. ret = wc_SipHashFinal(NULL, NULL, SIPHASH_MAC_SIZE_8);
  45246. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45247. return WC_TEST_RET_ENC_EC(ret);
  45248. ret = wc_SipHashFinal(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  45249. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45250. return WC_TEST_RET_ENC_EC(ret);
  45251. ret = wc_SipHashFinal(NULL, res, SIPHASH_MAC_SIZE_8);
  45252. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45253. return WC_TEST_RET_ENC_EC(ret);
  45254. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  45255. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45256. return WC_TEST_RET_ENC_EC(ret);
  45257. ret = wc_SipHash(NULL, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  45258. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45259. return WC_TEST_RET_ENC_EC(ret);
  45260. ret = wc_SipHash(siphash_key, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  45261. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45262. return WC_TEST_RET_ENC_EC(ret);
  45263. ret = wc_SipHash(NULL, NULL, 0, res, SIPHASH_MAC_SIZE_16);
  45264. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45265. return WC_TEST_RET_ENC_EC(ret);
  45266. ret = wc_SipHash(siphash_key, NULL, 0, res, 15);
  45267. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45268. return WC_TEST_RET_ENC_EC(ret);
  45269. ret = wc_SipHash(siphash_key, NULL, 1, res, SIPHASH_MAC_SIZE_16);
  45270. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45271. return WC_TEST_RET_ENC_EC(ret);
  45272. /* Test cache with multiple non blocksize bytes */
  45273. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45274. if (ret != 0)
  45275. return WC_TEST_RET_ENC_EC(ret);
  45276. ret = wc_SipHashUpdate(&siphash, siphash_msg, 5);
  45277. if (ret != 0)
  45278. return WC_TEST_RET_ENC_EC(ret);
  45279. ret = wc_SipHashUpdate(&siphash, siphash_msg + 5, 4);
  45280. if (ret != 0)
  45281. return WC_TEST_RET_ENC_EC(ret);
  45282. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  45283. if (ret != 0)
  45284. return WC_TEST_RET_ENC_EC(ret);
  45285. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45286. if (ret != 0)
  45287. return WC_TEST_RET_ENC_EC(ret);
  45288. ret = wc_SipHashUpdate(&siphash, siphash_msg, 9);
  45289. if (ret != 0)
  45290. return WC_TEST_RET_ENC_EC(ret);
  45291. ret = wc_SipHashFinal(&siphash, tmp, SIPHASH_MAC_SIZE_8);
  45292. if (ret != 0)
  45293. return WC_TEST_RET_ENC_EC(ret);
  45294. if (XMEMCMP(res, tmp, SIPHASH_MAC_SIZE_8) != 0)
  45295. return WC_TEST_RET_ENC_NC;
  45296. return 0;
  45297. }
  45298. #endif /* WOLFSSL_SIPHASH */
  45299. #ifdef HAVE_LIBZ
  45300. static const byte sample_text[] =
  45301. "Biodiesel cupidatat marfa, cliche aute put a bird on it incididunt elit\n"
  45302. "polaroid. Sunt tattooed bespoke reprehenderit. Sint twee organic id\n"
  45303. "marfa. Commodo veniam ad esse gastropub. 3 wolf moon sartorial vero,\n"
  45304. "plaid delectus biodiesel squid +1 vice. Post-ironic keffiyeh leggings\n"
  45305. "selfies cray fap hoodie, forage anim. Carles cupidatat shoreditch, VHS\n"
  45306. "small batch meggings kogi dolore food truck bespoke gastropub.\n"
  45307. "\n"
  45308. "Terry richardson adipisicing actually typewriter tumblr, twee whatever\n"
  45309. "four loko you probably haven't heard of them high life. Messenger bag\n"
  45310. "whatever tattooed deep v mlkshk. Brooklyn pinterest assumenda chillwave\n"
  45311. "et, banksy ullamco messenger bag umami pariatur direct trade forage.\n"
  45312. "Typewriter culpa try-hard, pariatur sint brooklyn meggings. Gentrify\n"
  45313. "food truck next level, tousled irony non semiotics PBR ethical anim cred\n"
  45314. "readymade. Mumblecore brunch lomo odd future, portland organic terry\n"
  45315. "richardson elit leggings adipisicing ennui raw denim banjo hella. Godard\n"
  45316. "mixtape polaroid, pork belly readymade organic cray typewriter helvetica\n"
  45317. "four loko whatever street art yr farm-to-table.\n"
  45318. "\n"
  45319. "Vinyl keytar vice tofu. Locavore you probably haven't heard of them pug\n"
  45320. "pickled, hella tonx labore truffaut DIY mlkshk elit cosby sweater sint\n"
  45321. "et mumblecore. Elit swag semiotics, reprehenderit DIY sartorial nisi ugh\n"
  45322. "nesciunt pug pork belly wayfarers selfies delectus. Ethical hoodie\n"
  45323. "seitan fingerstache kale chips. Terry richardson artisan williamsburg,\n"
  45324. "eiusmod fanny pack irony tonx ennui lo-fi incididunt tofu YOLO\n"
  45325. "readymade. 8-bit sed ethnic beard officia. Pour-over iphone DIY butcher,\n"
  45326. "ethnic art party qui letterpress nisi proident jean shorts mlkshk\n"
  45327. "locavore.\n"
  45328. "\n"
  45329. "Narwhal flexitarian letterpress, do gluten-free voluptate next level\n"
  45330. "banh mi tonx incididunt carles DIY. Odd future nulla 8-bit beard ut\n"
  45331. "cillum pickled velit, YOLO officia you probably haven't heard of them\n"
  45332. "trust fund gastropub. Nisi adipisicing tattooed, Austin mlkshk 90's\n"
  45333. "small batch american apparel. Put a bird on it cosby sweater before they\n"
  45334. "sold out pork belly kogi hella. Street art mollit sustainable polaroid,\n"
  45335. "DIY ethnic ea pug beard dreamcatcher cosby sweater magna scenester nisi.\n"
  45336. "Sed pork belly skateboard mollit, labore proident eiusmod. Sriracha\n"
  45337. "excepteur cosby sweater, anim deserunt laborum eu aliquip ethical et\n"
  45338. "neutra PBR selvage.\n"
  45339. "\n"
  45340. "Raw denim pork belly truffaut, irony plaid sustainable put a bird on it\n"
  45341. "next level jean shorts exercitation. Hashtag keytar whatever, nihil\n"
  45342. "authentic aliquip disrupt laborum. Tattooed selfies deserunt trust fund\n"
  45343. "wayfarers. 3 wolf moon synth church-key sartorial, gastropub leggings\n"
  45344. "tattooed. Labore high life commodo, meggings raw denim fingerstache pug\n"
  45345. "trust fund leggings seitan forage. Nostrud ullamco duis, reprehenderit\n"
  45346. "incididunt flannel sustainable helvetica pork belly pug banksy you\n"
  45347. "probably haven't heard of them nesciunt farm-to-table. Disrupt nostrud\n"
  45348. "mollit magna, sriracha sartorial helvetica.\n"
  45349. "\n"
  45350. "Nulla kogi reprehenderit, skateboard sustainable duis adipisicing viral\n"
  45351. "ad fanny pack salvia. Fanny pack trust fund you probably haven't heard\n"
  45352. "of them YOLO vice nihil. Keffiyeh cray lo-fi pinterest cardigan aliqua,\n"
  45353. "reprehenderit aute. Culpa tousled williamsburg, marfa lomo actually anim\n"
  45354. "skateboard. Iphone aliqua ugh, semiotics pariatur vero readymade\n"
  45355. "organic. Marfa squid nulla, in laborum disrupt laboris irure gastropub.\n"
  45356. "Veniam sunt food truck leggings, sint vinyl fap.\n"
  45357. "\n"
  45358. "Hella dolore pork belly, truffaut carles you probably haven't heard of\n"
  45359. "them PBR helvetica in sapiente. Fashion axe ugh bushwick american\n"
  45360. "apparel. Fingerstache sed iphone, jean shorts blue bottle nisi bushwick\n"
  45361. "flexitarian officia veniam plaid bespoke fap YOLO lo-fi. Blog\n"
  45362. "letterpress mumblecore, food truck id cray brooklyn cillum ad sed.\n"
  45363. "Assumenda chambray wayfarers vinyl mixtape sustainable. VHS vinyl\n"
  45364. "delectus, culpa williamsburg polaroid cliche swag church-key synth kogi\n"
  45365. "magna pop-up literally. Swag thundercats ennui shoreditch vegan\n"
  45366. "pitchfork neutra truffaut etsy, sed single-origin coffee craft beer.\n"
  45367. "\n"
  45368. "Odio letterpress brooklyn elit. Nulla single-origin coffee in occaecat\n"
  45369. "meggings. Irony meggings 8-bit, chillwave lo-fi adipisicing cred\n"
  45370. "dreamcatcher veniam. Put a bird on it irony umami, trust fund bushwick\n"
  45371. "locavore kale chips. Sriracha swag thundercats, chillwave disrupt\n"
  45372. "tousled beard mollit mustache leggings portland next level. Nihil esse\n"
  45373. "est, skateboard art party etsy thundercats sed dreamcatcher ut iphone\n"
  45374. "swag consectetur et. Irure skateboard banjo, nulla deserunt messenger\n"
  45375. "bag dolor terry richardson sapiente.\n";
  45376. static const byte sample_text_gz[] = {
  45377. 0x1F, 0x8B, 0x08, 0x08, 0xC5, 0x49, 0xB5, 0x5B, 0x00, 0x03, 0x63, 0x69, 0x70,
  45378. 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x8D,
  45379. 0x58, 0xCB, 0x92, 0xE4, 0xB6, 0x11, 0xBC, 0xE3, 0x2B, 0xEA, 0xA6, 0x83, 0xD9,
  45380. 0x1D, 0x72, 0xF8, 0x22, 0x1F, 0xB5, 0x96, 0xA5, 0xDD, 0x90, 0xBC, 0xAB, 0xD0,
  45381. 0x28, 0x36, 0x42, 0x47, 0x90, 0x2C, 0x36, 0xA1, 0x06, 0x09, 0x0A, 0x8F, 0xEE,
  45382. 0xE1, 0xDF, 0x3B, 0x0B, 0xE0, 0x73, 0x2C, 0x4B, 0xBA, 0xCD, 0xCE, 0x80, 0x78,
  45383. 0x64, 0x65, 0x65, 0x66, 0xED, 0x3B, 0xE3, 0x5A, 0xC3, 0x81, 0x2D, 0x35, 0x69,
  45384. 0x32, 0xAD, 0x8E, 0x3A, 0xD2, 0xA0, 0x7D, 0xA7, 0x2B, 0x6A, 0xAC, 0x69, 0x7A,
  45385. 0x26, 0x9D, 0x22, 0xD3, 0x94, 0x22, 0x69, 0xAA, 0x8D, 0x6F, 0xC9, 0x8D, 0x64,
  45386. 0x22, 0x99, 0xB1, 0x31, 0xAD, 0x69, 0xD3, 0x18, 0x89, 0xAD, 0x89, 0x6A, 0x72,
  45387. 0x56, 0x7B, 0x67, 0xDA, 0x2B, 0xBD, 0xC8, 0xEF, 0xB0, 0x4D, 0x74, 0x8E, 0x5B,
  45388. 0xAA, 0x39, 0x4C, 0xEE, 0xCE, 0xE4, 0x79, 0xF2, 0xDC, 0xF3, 0xD8, 0xB2, 0x37,
  45389. 0x11, 0x8B, 0x8C, 0x2C, 0x7A, 0x32, 0x93, 0xF3, 0x37, 0x3D, 0x9A, 0x86, 0x4C,
  45390. 0xAB, 0xF2, 0xB9, 0x57, 0xFA, 0x97, 0x1B, 0x06, 0xD7, 0x3A, 0x7A, 0xF0, 0x68,
  45391. 0xF4, 0x40, 0xBA, 0x25, 0x0E, 0x81, 0xE9, 0xA6, 0x43, 0xF4, 0x6E, 0x4A, 0xF5,
  45392. 0x95, 0xFE, 0x41, 0x4F, 0x67, 0x3B, 0x1A, 0x1C, 0xEE, 0x12, 0xB4, 0x8F, 0xCE,
  45393. 0x1B, 0x6D, 0xB1, 0xDE, 0xBB, 0x4A, 0x4D, 0x56, 0x9B, 0x96, 0x5A, 0xB6, 0xDC,
  45394. 0xC4, 0x14, 0x70, 0xE5, 0xF5, 0x7D, 0xE1, 0xB7, 0x84, 0x3F, 0xFC, 0xED, 0xEF,
  45395. 0xF4, 0x30, 0x0D, 0x5F, 0xE9, 0x47, 0x17, 0xE2, 0xC5, 0x78, 0x27, 0x67, 0xDF,
  45396. 0xB9, 0xEB, 0xCC, 0xCC, 0x3D, 0x59, 0xBE, 0xDD, 0xCC, 0x78, 0x0B, 0x0A, 0x1F,
  45397. 0x74, 0xF8, 0x8C, 0x1A, 0xAF, 0x67, 0xEA, 0xF4, 0x44, 0xBD, 0x93, 0x7D, 0x2A,
  45398. 0xEA, 0x9C, 0xD7, 0x37, 0x80, 0x32, 0x9A, 0x01, 0x37, 0xD5, 0xDE, 0xCA, 0xA2,
  45399. 0x0D, 0xB9, 0xD0, 0x3B, 0xCF, 0xAD, 0x89, 0x4D, 0x5F, 0xD1, 0xE7, 0xF7, 0x2F,
  45400. 0x2A, 0x0C, 0xDA, 0x5A, 0xAA, 0x35, 0x7E, 0x41, 0xC3, 0xB2, 0x37, 0xDD, 0xDD,
  45401. 0xCD, 0x50, 0xEB, 0x2C, 0x96, 0x62, 0x3B, 0xD7, 0x52, 0xF4, 0xA9, 0xB9, 0x6F,
  45402. 0x48, 0xED, 0xEF, 0x54, 0xEA, 0x67, 0xF6, 0x7E, 0x26, 0x8F, 0x3A, 0x68, 0xDF,
  45403. 0x06, 0xBC, 0x56, 0xB7, 0x66, 0x32, 0xC1, 0x34, 0xD8, 0x88, 0x34, 0x1E, 0x88,
  45404. 0xED, 0x67, 0x8A, 0xF3, 0xC4, 0x4F, 0xC0, 0xCA, 0x9E, 0x62, 0x1A, 0x6A, 0xEB,
  45405. 0xAB, 0x02, 0xED, 0xB3, 0xD7, 0x91, 0x81, 0x8A, 0xEA, 0x5C, 0xF2, 0x64, 0xDD,
  45406. 0xDD, 0xD1, 0xEC, 0x12, 0x4D, 0xDE, 0xD5, 0xBA, 0xC6, 0x77, 0xBD, 0x06, 0xC4,
  45407. 0x5F, 0x44, 0xEA, 0x59, 0x4B, 0x5D, 0x3B, 0x8A, 0x3D, 0x0F, 0xD4, 0x9B, 0x1B,
  45408. 0x80, 0x30, 0x1D, 0x30, 0xFA, 0x8F, 0x00, 0x3F, 0xDE, 0xB0, 0x6F, 0xAD, 0x6F,
  45409. 0x6A, 0xDD, 0x6E, 0x2F, 0x6E, 0xCB, 0x3C, 0xD1, 0x83, 0x06, 0x7B, 0x0F, 0xFD,
  45410. 0xFD, 0x4A, 0xEF, 0xBC, 0x73, 0x77, 0x3B, 0x8F, 0x34, 0xA1, 0xBA, 0xEC, 0x39,
  45411. 0x80, 0x33, 0x21, 0xA4, 0x01, 0x55, 0xD7, 0xD4, 0xF4, 0xC6, 0xDA, 0x27, 0x4E,
  45412. 0x54, 0x1C, 0x2B, 0xEC, 0x37, 0xDE, 0xC3, 0x4C, 0xC9, 0x5A, 0x3D, 0x34, 0x0E,
  45413. 0xD8, 0x1C, 0x0E, 0xA2, 0x34, 0xE8, 0xC1, 0xD0, 0xA4, 0x51, 0xD5, 0x88, 0x8B,
  45414. 0xB7, 0xC6, 0xA3, 0x96, 0x40, 0x49, 0xB7, 0xBC, 0xE0, 0x7F, 0x55, 0x3F, 0xEF,
  45415. 0x6F, 0x6E, 0x92, 0x9D, 0x34, 0xFE, 0x3C, 0x5F, 0x04, 0xA5, 0x6A, 0xFF, 0x30,
  45416. 0x08, 0xC9, 0xEA, 0xF5, 0x52, 0x2B, 0xFE, 0x57, 0xFA, 0x8E, 0xC7, 0xE8, 0x4D,
  45417. 0x37, 0xAB, 0x03, 0xFA, 0x23, 0xBF, 0x46, 0x94, 0xFF, 0xC1, 0x16, 0xE0, 0xB9,
  45418. 0x14, 0x2C, 0x9E, 0x27, 0xEC, 0x98, 0x69, 0x14, 0x92, 0xF1, 0x60, 0x5C, 0x34,
  45419. 0x4D, 0xA0, 0x1F, 0xDF, 0xFD, 0x44, 0x1C, 0x7B, 0xD3, 0x80, 0x70, 0x42, 0x02,
  45420. 0x30, 0x84, 0x5B, 0xE5, 0x59, 0xB7, 0xF3, 0x80, 0xFB, 0x01, 0x33, 0xA9, 0x00,
  45421. 0x37, 0x52, 0xDC, 0xDA, 0xA7, 0x11, 0x85, 0xB7, 0x6E, 0x70, 0xE4, 0xDA, 0x96,
  45422. 0xBA, 0x84, 0x5B, 0x81, 0x43, 0x93, 0xF3, 0xD1, 0xEA, 0xB1, 0xDD, 0xB8, 0x1F,
  45423. 0xA5, 0xCC, 0xEA, 0x50, 0x66, 0x69, 0xA9, 0x8D, 0x8C, 0xA7, 0xA2, 0xF3, 0x38,
  45424. 0x26, 0x43, 0x5E, 0x3F, 0x01, 0xBE, 0x1C, 0x0F, 0x20, 0x7F, 0x75, 0xA8, 0x20,
  45425. 0x80, 0xC4, 0xC3, 0x5C, 0x8B, 0x0D, 0xD4, 0x60, 0x5E, 0xA3, 0x9E, 0xD0, 0xB4,
  45426. 0x4B, 0x4F, 0xE6, 0x13, 0x85, 0x60, 0x42, 0x96, 0xED, 0xAA, 0xDB, 0xE9, 0x99,
  45427. 0xE3, 0x07, 0x0E, 0x61, 0xB3, 0x07, 0xE3, 0xB1, 0xFA, 0xC0, 0x9B, 0xAD, 0xF6,
  45428. 0xE0, 0x26, 0x33, 0xEA, 0xEA, 0x23, 0xCD, 0x1E, 0x9D, 0xE1, 0x87, 0x4B, 0x74,
  45429. 0x97, 0x08, 0x3E, 0xA1, 0x28, 0xEA, 0xB3, 0x19, 0x67, 0x8B, 0x76, 0x9A, 0xA3,
  45430. 0xF6, 0xB9, 0xCF, 0x80, 0x65, 0x97, 0xAE, 0xF4, 0x83, 0x6B, 0xF4, 0x43, 0x20,
  45431. 0xF9, 0x0B, 0xFC, 0x9B, 0xD2, 0x4D, 0x4D, 0xA6, 0xB9, 0xA3, 0x02, 0x55, 0x79,
  45432. 0x18, 0x36, 0x19, 0x5F, 0xC9, 0xEA, 0x5A, 0x76, 0x40, 0xB9, 0xBA, 0x0E, 0x9A,
  45433. 0x44, 0xDF, 0x7C, 0xF8, 0x65, 0x61, 0x5E, 0x81, 0xAB, 0x71, 0xA1, 0x9E, 0x29,
  45434. 0x3C, 0x59, 0xCB, 0x23, 0xA4, 0xF6, 0x60, 0x1A, 0x0D, 0x5B, 0x39, 0xAE, 0xF4,
  45435. 0x6F, 0x59, 0x16, 0x9E, 0x60, 0xD8, 0x56, 0xCF, 0xEA, 0x2C, 0x4C, 0x79, 0xD3,
  45436. 0x5D, 0x51, 0x46, 0xA0, 0x4E, 0xE9, 0xD6, 0xAB, 0x91, 0x43, 0x63, 0x44, 0xD7,
  45437. 0x70, 0xB9, 0x23, 0x98, 0x4F, 0x3D, 0x03, 0x02, 0xF6, 0x81, 0x56, 0xC1, 0x58,
  45438. 0x85, 0x07, 0xA7, 0x2D, 0x2C, 0x29, 0xCA, 0x01, 0x45, 0x31, 0x51, 0x8F, 0xD4,
  45439. 0x19, 0xA1, 0x79, 0x88, 0x5A, 0xA4, 0xF5, 0xAE, 0x2D, 0x4B, 0x63, 0x4C, 0x58,
  45440. 0xFE, 0xBF, 0xAD, 0xEE, 0xA3, 0x09, 0xF8, 0xE2, 0x89, 0xBE, 0x81, 0x0E, 0x86,
  45441. 0x3A, 0xF9, 0x5B, 0xA5, 0xD8, 0xA4, 0x00, 0x75, 0x04, 0xF2, 0x23, 0xB8, 0x39,
  45442. 0x69, 0x50, 0xB7, 0xD0, 0x34, 0x63, 0x54, 0xD8, 0x61, 0xDD, 0xA5, 0x33, 0x47,
  45443. 0x85, 0x96, 0x22, 0xD0, 0x2F, 0x9F, 0x7E, 0xF8, 0x74, 0x24, 0xEA, 0x57, 0x97,
  45444. 0x5A, 0xE0, 0x00, 0xCF, 0xC1, 0x67, 0xE1, 0x41, 0xBD, 0x94, 0xA1, 0x03, 0xD3,
  45445. 0xB4, 0x08, 0x64, 0xF2, 0x17, 0x27, 0x35, 0x37, 0x53, 0xEF, 0x46, 0xCE, 0xD8,
  45446. 0xD4, 0x09, 0x52, 0xC6, 0x1E, 0xF7, 0x28, 0xDF, 0x08, 0x0F, 0xD0, 0x6F, 0x71,
  45447. 0xA6, 0xDF, 0xE4, 0x60, 0x8E, 0xC0, 0x1E, 0x78, 0x86, 0x50, 0xB0, 0x9B, 0x84,
  45448. 0x7E, 0xE8, 0x36, 0xFA, 0x95, 0xF1, 0x12, 0x51, 0xC7, 0x18, 0x96, 0xA2, 0x29,
  45449. 0xBB, 0x70, 0x02, 0xB4, 0xF9, 0xA8, 0x3D, 0x08, 0x66, 0xA9, 0xB3, 0xFC, 0x0A,
  45450. 0x94, 0x80, 0xFD, 0x78, 0xDC, 0xAB, 0x82, 0x5A, 0xD2, 0xCD, 0xC2, 0x87, 0xC6,
  45451. 0x4B, 0x07, 0xFA, 0xD1, 0xC3, 0xD9, 0x34, 0x41, 0x85, 0xF8, 0xD0, 0xB6, 0x0A,
  45452. 0x9D, 0x00, 0x91, 0x35, 0x05, 0x88, 0xC3, 0xE3, 0x9B, 0x22, 0xD2, 0xB8, 0xFD,
  45453. 0x95, 0x3E, 0x6D, 0x5D, 0x48, 0xA3, 0x68, 0xCF, 0x02, 0x42, 0x79, 0x79, 0x8A,
  45454. 0xAA, 0x01, 0xD6, 0x09, 0x14, 0x2C, 0xF4, 0x83, 0xA3, 0x80, 0x31, 0x55, 0x46,
  45455. 0x6E, 0xC5, 0xE5, 0x2F, 0x30, 0x58, 0x81, 0xA2, 0x90, 0xBE, 0x2E, 0xA1, 0xC3,
  45456. 0x0F, 0xA6, 0xF5, 0x51, 0x00, 0x39, 0xB6, 0xF2, 0x2A, 0xA3, 0x15, 0x7D, 0x8D,
  45457. 0xF5, 0x66, 0x5C, 0xD9, 0xFC, 0xCF, 0x2F, 0xBF, 0x08, 0x27, 0xE7, 0xD0, 0x03,
  45458. 0xB8, 0xD9, 0x00, 0x13, 0x3D, 0x01, 0x6B, 0xB6, 0xA8, 0xCD, 0x5B, 0x3B, 0x3E,
  45459. 0x93, 0xBF, 0xE6, 0x2E, 0xB7, 0x4A, 0xCF, 0xB3, 0x0A, 0xCE, 0x62, 0x11, 0xD6,
  45460. 0x1F, 0x68, 0x9B, 0x1D, 0x68, 0xD1, 0x8C, 0x97, 0xBD, 0xA1, 0x07, 0x67, 0x73,
  45461. 0x87, 0xE0, 0x36, 0xDA, 0x8C, 0xD2, 0xD2, 0xBB, 0x84, 0x28, 0xA9, 0xFE, 0x52,
  45462. 0x74, 0xD6, 0xB9, 0x0F, 0x0A, 0x6A, 0x2D, 0x28, 0x35, 0x34, 0x3A, 0xD3, 0xE2,
  45463. 0xCD, 0x35, 0x06, 0x7D, 0x1B, 0x35, 0x85, 0x86, 0xD1, 0x3E, 0xF2, 0x6F, 0xA1,
  45464. 0xC4, 0x55, 0xBD, 0x00, 0xD8, 0xC3, 0x5D, 0xC2, 0x1D, 0x6B, 0x6B, 0x27, 0x5B,
  45465. 0x95, 0xF3, 0xAB, 0xB5, 0xD3, 0x37, 0xF2, 0x2C, 0x9C, 0xC7, 0x5D, 0xBD, 0xF1,
  45466. 0x68, 0x1C, 0xAD, 0xF8, 0xB5, 0xE1, 0x29, 0x72, 0x7A, 0x73, 0x62, 0x55, 0x24,
  45467. 0xB9, 0x85, 0xDF, 0x7B, 0x29, 0x7D, 0xDE, 0x08, 0xF5, 0xE4, 0x44, 0xDA, 0x1A,
  45468. 0x30, 0x74, 0xDA, 0xB4, 0x9B, 0x23, 0x9A, 0x3A, 0xC1, 0x53, 0xB2, 0xA2, 0xA3,
  45469. 0x7B, 0x1F, 0xD9, 0x56, 0xD4, 0x4F, 0x9B, 0xB2, 0x1E, 0xEE, 0xB8, 0x6A, 0x4E,
  45470. 0xB5, 0xF4, 0x5A, 0xC9, 0x18, 0x27, 0x9C, 0xDE, 0x14, 0x44, 0xED, 0xC4, 0x3C,
  45471. 0x71, 0x9F, 0x5F, 0xD9, 0x37, 0xA0, 0x78, 0x34, 0x6E, 0xBC, 0xD2, 0x7B, 0x1D,
  45472. 0xFA, 0x08, 0x39, 0x5A, 0x04, 0x73, 0x15, 0xD9, 0x0A, 0x48, 0xC1, 0x2D, 0x15,
  45473. 0x4E, 0x84, 0x30, 0x45, 0x69, 0xB3, 0xE5, 0xF6, 0xAD, 0x09, 0x1E, 0xCC, 0x5F,
  45474. 0x1F, 0x06, 0xD5, 0x58, 0xAD, 0x78, 0xD7, 0x9F, 0xE5, 0xED, 0x3B, 0x09, 0xD5,
  45475. 0xA6, 0x52, 0x6F, 0x92, 0xD3, 0x3C, 0xC6, 0x1E, 0xF2, 0x93, 0x7C, 0xD3, 0x5F,
  45476. 0x70, 0x85, 0x5D, 0xF8, 0xAA, 0x9D, 0xB7, 0x7B, 0x24, 0x5A, 0xE9, 0x0A, 0x35,
  45477. 0x2F, 0xF5, 0xD9, 0x82, 0x02, 0x8A, 0x90, 0x13, 0x5B, 0xB5, 0x67, 0x9C, 0xDD,
  45478. 0xA0, 0x4E, 0x82, 0x27, 0xDA, 0x7E, 0xE8, 0x8E, 0xCD, 0xE1, 0x56, 0x71, 0x2C,
  45479. 0xE6, 0x4E, 0x1F, 0x91, 0xCD, 0x7C, 0x6A, 0xB7, 0x78, 0xD0, 0x26, 0xF3, 0x56,
  45480. 0xA9, 0xD5, 0xA1, 0xC3, 0x3B, 0x98, 0xE9, 0x28, 0x09, 0xEF, 0x50, 0x90, 0xCD,
  45481. 0xC4, 0x8E, 0x75, 0xCC, 0xAC, 0x2D, 0xC9, 0x03, 0x6D, 0xAC, 0xFE, 0xC4, 0x88,
  45482. 0x36, 0xD1, 0x3F, 0xBB, 0x1C, 0x7D, 0xB3, 0x14, 0x61, 0x2C, 0xB7, 0x54, 0x4B,
  45483. 0xDB, 0x64, 0xB6, 0x57, 0x14, 0x16, 0x8E, 0x1E, 0x6C, 0x64, 0xBB, 0x8B, 0x48,
  45484. 0x5D, 0x96, 0x9D, 0xDC, 0x80, 0xA7, 0xF7, 0x54, 0xC7, 0x46, 0x38, 0x3E, 0x44,
  45485. 0xDE, 0x7E, 0x92, 0x8D, 0x07, 0xF6, 0x07, 0x37, 0x4E, 0x16, 0x10, 0xB4, 0x7D,
  45486. 0x88, 0x66, 0x7F, 0xBB, 0xFF, 0xEA, 0x00, 0xF3, 0xFF, 0x97, 0x2C, 0xB5, 0xBE,
  45487. 0x35, 0x4B, 0x5C, 0x36, 0xEC, 0x4C, 0xBD, 0x2B, 0x7D, 0xBF, 0x46, 0xE2, 0x9C,
  45488. 0x0E, 0x8A, 0xA3, 0xEC, 0xB1, 0x0E, 0x9A, 0xDA, 0x9A, 0x9B, 0x28, 0x92, 0x10,
  45489. 0x53, 0x57, 0xEA, 0xEC, 0xA2, 0x32, 0x32, 0x20, 0x1D, 0x97, 0x5C, 0xB6, 0x84,
  45490. 0xA9, 0x93, 0x8D, 0x95, 0x11, 0xA3, 0x24, 0xA3, 0x2D, 0xC6, 0x4A, 0xEF, 0xAA,
  45491. 0x1D, 0x85, 0x2B, 0x7D, 0x28, 0xBE, 0x53, 0xCE, 0x10, 0x1F, 0xAE, 0x0E, 0x41,
  45492. 0x6C, 0x4B, 0x79, 0x12, 0xFB, 0xF7, 0x54, 0xA3, 0x96, 0x54, 0x83, 0x20, 0x96,
  45493. 0x8F, 0x28, 0xA9, 0x3F, 0x8B, 0x3D, 0xBA, 0x77, 0xDC, 0x24, 0xE1, 0xD4, 0x49,
  45494. 0x40, 0xD8, 0x78, 0x31, 0x85, 0x43, 0xF6, 0xFE, 0x5C, 0xA6, 0x8F, 0x90, 0x09,
  45495. 0xB0, 0xE7, 0xC4, 0x95, 0xB2, 0x55, 0x49, 0x97, 0x8F, 0x1C, 0x78, 0x30, 0x20,
  45496. 0xA0, 0xB4, 0xEF, 0x73, 0x56, 0x59, 0x82, 0xFD, 0xCE, 0xBA, 0x6A, 0x8F, 0x2C,
  45497. 0x8B, 0x15, 0xFD, 0xA1, 0x85, 0xA8, 0x5C, 0x0F, 0x11, 0xA5, 0x9D, 0xC2, 0x46,
  45498. 0xC6, 0x9C, 0xC9, 0x40, 0x0B, 0x58, 0x6A, 0x1C, 0x7A, 0x23, 0xF9, 0xE0, 0x95,
  45499. 0x05, 0x13, 0x58, 0x72, 0xE8, 0x9F, 0x30, 0xAC, 0xCD, 0x26, 0xD4, 0x66, 0x13,
  45500. 0xDF, 0x1E, 0x7B, 0x4F, 0x9C, 0xBE, 0x38, 0x79, 0x75, 0x92, 0xA4, 0xDA, 0x26,
  45501. 0x44, 0x55, 0x17, 0xA3, 0xE5, 0x62, 0xDA, 0xEB, 0x86, 0xEA, 0x68, 0xC7, 0xAB,
  45502. 0xFD, 0x2D, 0x43, 0x59, 0x51, 0xC0, 0x75, 0x64, 0x91, 0x01, 0x29, 0x33, 0x28,
  45503. 0xF3, 0x04, 0x83, 0x80, 0x75, 0x37, 0x75, 0x0C, 0x03, 0x7B, 0x0A, 0xAB, 0x8E,
  45504. 0x60, 0x62, 0x8B, 0x4C, 0xAF, 0x2D, 0xA3, 0x2F, 0xFE, 0xAB, 0x45, 0xCF, 0xDA,
  45505. 0xAB, 0xFA, 0xFA, 0x30, 0x3D, 0xE8, 0xA1, 0x96, 0xA5, 0x7B, 0xE2, 0x2A, 0xD0,
  45506. 0xAF, 0x59, 0xF7, 0xD0, 0x32, 0x57, 0x19, 0xBD, 0xCA, 0x9F, 0xD5, 0x1A, 0xC7,
  45507. 0xAA, 0x65, 0x4A, 0x38, 0xB2, 0x70, 0x33, 0xB7, 0x75, 0xD2, 0xCD, 0xD1, 0xF0,
  45508. 0xA8, 0x87, 0x59, 0x20, 0xA5, 0x57, 0x55, 0xB1, 0xB2, 0xC9, 0x4D, 0x97, 0x34,
  45509. 0x41, 0xF3, 0xF0, 0x30, 0xA1, 0x2C, 0x1C, 0x49, 0x3E, 0x89, 0x7D, 0x12, 0xE2,
  45510. 0xC3, 0x04, 0xC3, 0x92, 0xC0, 0xF6, 0x39, 0x10, 0x80, 0x81, 0x8F, 0x08, 0xB4,
  45511. 0xF8, 0xB9, 0x13, 0x4E, 0x2C, 0xAE, 0xB3, 0x71, 0x82, 0x63, 0x98, 0xAB, 0x5C,
  45512. 0x1C, 0x10, 0xEA, 0x66, 0xF9, 0x02, 0x3A, 0x82, 0x61, 0xD0, 0xD4, 0xAE, 0x43,
  45513. 0xD4, 0x01, 0x3E, 0x9D, 0x04, 0x14, 0xF6, 0x60, 0xD8, 0xA7, 0xD6, 0xB8, 0x53,
  45514. 0xC8, 0xDA, 0x80, 0x93, 0xA0, 0x02, 0xDD, 0xCC, 0xE2, 0xF2, 0xBB, 0xFB, 0xE0,
  45515. 0x27, 0xD7, 0x34, 0x9A, 0x71, 0x49, 0xB5, 0x4F, 0x42, 0x1F, 0xB2, 0x9D, 0x6D,
  45516. 0xAA, 0x9D, 0xD3, 0x50, 0xB5, 0x8F, 0x6A, 0x4B, 0xDF, 0x1F, 0xD5, 0x27, 0x8F,
  45517. 0x3B, 0x27, 0xCF, 0x2F, 0x8C, 0xF8, 0x9D, 0x4C, 0x52, 0xBC, 0x32, 0x0F, 0x73,
  45518. 0xD5, 0x51, 0x8E, 0x36, 0x7E, 0xAD, 0x09, 0xF0, 0x94, 0x83, 0x5F, 0x36, 0xFD,
  45519. 0x7C, 0x03, 0xED, 0xF1, 0x5E, 0x4B, 0xF7, 0xAA, 0x55, 0x5C, 0x4A, 0x14, 0x59,
  45520. 0x85, 0x38, 0x2D, 0x8C, 0xDF, 0xEC, 0x65, 0x1B, 0xB8, 0x76, 0x57, 0x96, 0x3C,
  45521. 0x86, 0xED, 0xF2, 0x7F, 0x2D, 0x28, 0x48, 0xDA, 0x49, 0x7F, 0xF7, 0x54, 0x2B,
  45522. 0xD5, 0x39, 0xD5, 0x57, 0x0A, 0x75, 0x7A, 0x3E, 0x5E, 0x5D, 0xBA, 0x4A, 0x15,
  45523. 0xFA, 0xB8, 0x31, 0x80, 0x71, 0x2C, 0xCA, 0xC4, 0x51, 0x10, 0x16, 0x5D, 0x39,
  45524. 0xEC, 0x9D, 0x07, 0xB6, 0x6A, 0x89, 0x9F, 0x9B, 0x5B, 0x6F, 0x03, 0xB0, 0x92,
  45525. 0x01, 0x38, 0x6B, 0x48, 0x99, 0x0A, 0x8F, 0x13, 0xC1, 0xA6, 0x01, 0xEA, 0xBF,
  45526. 0x6F, 0x86, 0x43, 0x51, 0xB6, 0x11, 0x00, 0x00
  45527. };
  45528. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void)
  45529. {
  45530. wc_test_ret_t ret = 0;
  45531. word32 dSz = sizeof(sample_text);
  45532. word32 cSz = (dSz + (word32)(dSz * 0.001) + 12);
  45533. byte *c;
  45534. byte *d;
  45535. WOLFSSL_ENTER("compress_test");
  45536. c = (byte *)XMALLOC(cSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45537. d = (byte *)XMALLOC(dSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45538. if (c == NULL || d == NULL) {
  45539. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  45540. }
  45541. /* follow calloc and initialize to 0 */
  45542. XMEMSET(c, 0, cSz);
  45543. XMEMSET(d, 0, dSz);
  45544. if ((ret = wc_Compress(c, cSz, sample_text, dSz, 0)) < 0) {
  45545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45546. }
  45547. cSz = (word32)ret;
  45548. if ((ret = wc_DeCompress(d, dSz, c, cSz)) != (int)dSz) {
  45549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45550. }
  45551. dSz = (word32)ret;
  45552. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45553. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45554. }
  45555. /* GZIP tests */
  45556. cSz = (dSz + (word32)(dSz * 0.001) + 12); /* reset cSz */
  45557. XMEMSET(c, 0, cSz);
  45558. XMEMSET(d, 0, dSz);
  45559. ret = wc_Compress_ex(c, cSz, sample_text, dSz, 0, LIBZ_WINBITS_GZIP);
  45560. if (ret < 0)
  45561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45562. cSz = (word32)ret;
  45563. ret = wc_DeCompress_ex(d, dSz, c, cSz, LIBZ_WINBITS_GZIP);
  45564. if (ret < 0)
  45565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45566. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45567. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45568. }
  45569. /* Try with gzip generated output */
  45570. XMEMSET(d, 0, dSz);
  45571. ret = wc_DeCompress_ex(d, dSz, sample_text_gz, sizeof(sample_text_gz),
  45572. LIBZ_WINBITS_GZIP);
  45573. if (ret < 0)
  45574. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45575. dSz = (word32)ret;
  45576. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45577. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45578. }
  45579. ret = 0; /* success */
  45580. exit:
  45581. XFREE(c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45582. XFREE(d, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45583. return ret;
  45584. }
  45585. #endif /* HAVE_LIBZ */
  45586. #ifdef HAVE_PKCS7
  45587. /* External Debugging/Testing Note:
  45588. *
  45589. * PKCS#7 test functions can output generated PKCS#7/CMS bundles for
  45590. * additional testing. To dump bundles to files DER encoded files, please
  45591. * define:
  45592. *
  45593. * #define PKCS7_OUTPUT_TEST_BUNDLES
  45594. */
  45595. /* Loads certs and keys for use with PKCS7 tests, from either files
  45596. * or buffers.
  45597. *
  45598. * rsaClientCertBuf - output buffer for RSA client cert
  45599. * rsaClientCertBufSz - IN/OUT size of output buffer, size of RSA client cert
  45600. * rsaClientPrivKeyBuf - output buffer for RSA client private key
  45601. * rsaClientPrivKeyBufSz - IN/OUT size of output buffer, size of RSA client key
  45602. *
  45603. * rsaServerCertBuf - output buffer for RSA server cert
  45604. * rsaServerCertBufSz - IN/OUT size of output buffer, size of RSA server cert
  45605. * rsaServerPrivKeyBuf - output buffer for RSA server private key
  45606. * rsaServerPrivKeyBufSz - IN/OUT size of output buffer, size of RSA server key
  45607. *
  45608. * rsaCaCertBuf - output buffer for RSA CA cert
  45609. * rsaCaCertBufSz - IN/OUT size of output buffer, size of RSA ca cert
  45610. * rsaCaPrivKeyBuf - output buffer for RSA CA private key
  45611. * rsaCaPrivKeyBufSz - IN/OUT size of output buffer, size of RSA CA key
  45612. *
  45613. * eccClientCertBuf - output buffer for ECC cert
  45614. * eccClientCertBufSz - IN/OUT size of output buffer, size of ECC cert
  45615. * eccClientPrivKeyBuf - output buffer for ECC private key
  45616. * eccClientPrivKeyBufSz - IN/OUT size of output buffer, size of ECC private key
  45617. *
  45618. * Returns 0 on success, negative on error
  45619. */
  45620. static wc_test_ret_t pkcs7_load_certs_keys(
  45621. byte* rsaClientCertBuf, word32* rsaClientCertBufSz,
  45622. byte* rsaClientPrivKeyBuf, word32* rsaClientPrivKeyBufSz,
  45623. byte* rsaServerCertBuf, word32* rsaServerCertBufSz,
  45624. byte* rsaServerPrivKeyBuf, word32* rsaServerPrivKeyBufSz,
  45625. byte* rsaCaCertBuf, word32* rsaCaCertBufSz,
  45626. byte* rsaCaPrivKeyBuf, word32* rsaCaPrivKeyBufSz,
  45627. byte* eccClientCertBuf, word32* eccClientCertBufSz,
  45628. byte* eccClientPrivKeyBuf, word32* eccClientPrivKeyBufSz)
  45629. {
  45630. #ifndef NO_FILESYSTEM
  45631. XFILE certFile;
  45632. XFILE keyFile;
  45633. (void)certFile;
  45634. (void)keyFile;
  45635. #endif
  45636. #ifndef NO_RSA
  45637. if (rsaClientCertBuf == NULL || rsaClientCertBufSz == NULL ||
  45638. rsaClientPrivKeyBuf == NULL || rsaClientPrivKeyBufSz == NULL)
  45639. return BAD_FUNC_ARG;
  45640. #endif
  45641. #ifdef HAVE_ECC
  45642. if (eccClientCertBuf == NULL || eccClientCertBufSz == NULL ||
  45643. eccClientPrivKeyBuf == NULL || eccClientPrivKeyBufSz == NULL)
  45644. return BAD_FUNC_ARG;
  45645. #endif
  45646. /* RSA */
  45647. #ifndef NO_RSA
  45648. #ifdef USE_CERT_BUFFERS_1024
  45649. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_1024)
  45650. return WC_TEST_RET_ENC_NC;
  45651. XMEMCPY(rsaClientCertBuf, client_cert_der_1024,
  45652. sizeof_client_cert_der_1024);
  45653. *rsaClientCertBufSz = sizeof_client_cert_der_1024;
  45654. if (rsaServerCertBuf != NULL) {
  45655. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_1024)
  45656. return WC_TEST_RET_ENC_NC;
  45657. XMEMCPY(rsaServerCertBuf, server_cert_der_1024,
  45658. sizeof_server_cert_der_1024);
  45659. *rsaServerCertBufSz = sizeof_server_cert_der_1024;
  45660. }
  45661. if (rsaCaCertBuf != NULL) {
  45662. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_1024)
  45663. return WC_TEST_RET_ENC_NC;
  45664. XMEMCPY(rsaCaCertBuf, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  45665. *rsaCaCertBufSz = sizeof_ca_cert_der_1024;
  45666. }
  45667. #elif defined(USE_CERT_BUFFERS_2048)
  45668. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_2048)
  45669. return WC_TEST_RET_ENC_NC;
  45670. XMEMCPY(rsaClientCertBuf, client_cert_der_2048,
  45671. sizeof_client_cert_der_2048);
  45672. *rsaClientCertBufSz = sizeof_client_cert_der_2048;
  45673. if (rsaServerCertBuf != NULL) {
  45674. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_2048)
  45675. return WC_TEST_RET_ENC_NC;
  45676. XMEMCPY(rsaServerCertBuf, server_cert_der_2048,
  45677. sizeof_server_cert_der_2048);
  45678. *rsaServerCertBufSz = sizeof_server_cert_der_2048;
  45679. }
  45680. if (rsaCaCertBuf != NULL) {
  45681. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_2048)
  45682. return WC_TEST_RET_ENC_NC;
  45683. XMEMCPY(rsaCaCertBuf, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  45684. *rsaCaCertBufSz = sizeof_ca_cert_der_2048;
  45685. }
  45686. #else
  45687. certFile = XFOPEN(clientCert, "rb");
  45688. if (!certFile)
  45689. return WC_TEST_RET_ENC_ERRNO;
  45690. *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1,
  45691. *rsaClientCertBufSz, certFile);
  45692. XFCLOSE(certFile);
  45693. if (*rsaClientCertBufSz == 0)
  45694. return WC_TEST_RET_ENC_ERRNO;
  45695. if (rsaServerCertBuf != NULL) {
  45696. certFile = XFOPEN(rsaServerCertDerFile, "rb");
  45697. if (!certFile)
  45698. return WC_TEST_RET_ENC_ERRNO;
  45699. *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1,
  45700. *rsaServerCertBufSz, certFile);
  45701. XFCLOSE(certFile);
  45702. if (*rsaServerCertBufSz == 0)
  45703. return WC_TEST_RET_ENC_ERRNO;
  45704. }
  45705. if (rsaCaCertBuf != NULL) {
  45706. certFile = XFOPEN(rsaCaCertDerFile, "rb");
  45707. if (!certFile)
  45708. return WC_TEST_RET_ENC_ERRNO;
  45709. *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz,
  45710. certFile);
  45711. XFCLOSE(certFile);
  45712. if (*rsaCaCertBufSz == 0)
  45713. return WC_TEST_RET_ENC_ERRNO;
  45714. }
  45715. #endif
  45716. #ifdef USE_CERT_BUFFERS_1024
  45717. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_1024)
  45718. return WC_TEST_RET_ENC_NC;
  45719. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_1024,
  45720. sizeof_client_key_der_1024);
  45721. *rsaClientPrivKeyBufSz = sizeof_client_key_der_1024;
  45722. if (rsaServerPrivKeyBuf != NULL) {
  45723. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_1024)
  45724. return WC_TEST_RET_ENC_NC;
  45725. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_1024,
  45726. sizeof_server_key_der_1024);
  45727. *rsaServerPrivKeyBufSz = sizeof_server_key_der_1024;
  45728. }
  45729. if (rsaCaPrivKeyBuf != NULL) {
  45730. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_1024)
  45731. return WC_TEST_RET_ENC_NC;
  45732. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_1024, sizeof_ca_key_der_1024);
  45733. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_1024;
  45734. }
  45735. #elif defined(USE_CERT_BUFFERS_2048)
  45736. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_2048)
  45737. return WC_TEST_RET_ENC_NC;
  45738. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_2048,
  45739. sizeof_client_key_der_2048);
  45740. *rsaClientPrivKeyBufSz = sizeof_client_key_der_2048;
  45741. if (rsaServerPrivKeyBuf != NULL) {
  45742. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_2048)
  45743. return WC_TEST_RET_ENC_NC;
  45744. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_2048,
  45745. sizeof_server_key_der_2048);
  45746. *rsaServerPrivKeyBufSz = sizeof_server_key_der_2048;
  45747. }
  45748. if (rsaCaPrivKeyBuf != NULL) {
  45749. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_2048)
  45750. return WC_TEST_RET_ENC_NC;
  45751. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_2048, sizeof_ca_key_der_2048);
  45752. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048;
  45753. }
  45754. #else
  45755. keyFile = XFOPEN(clientKey, "rb");
  45756. if (!keyFile)
  45757. return WC_TEST_RET_ENC_ERRNO;
  45758. *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1,
  45759. *rsaClientPrivKeyBufSz, keyFile);
  45760. XFCLOSE(keyFile);
  45761. if (*rsaClientPrivKeyBufSz == 0)
  45762. return WC_TEST_RET_ENC_ERRNO;
  45763. if (rsaServerPrivKeyBuf != NULL) {
  45764. keyFile = XFOPEN(rsaServerKeyDerFile, "rb");
  45765. if (!keyFile)
  45766. return WC_TEST_RET_ENC_ERRNO;
  45767. *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1,
  45768. *rsaServerPrivKeyBufSz, keyFile);
  45769. XFCLOSE(keyFile);
  45770. if (*rsaServerPrivKeyBufSz == 0)
  45771. return WC_TEST_RET_ENC_ERRNO;
  45772. }
  45773. if (rsaCaPrivKeyBuf != NULL) {
  45774. keyFile = XFOPEN(rsaCaKeyFile, "rb");
  45775. if (!keyFile)
  45776. return WC_TEST_RET_ENC_ERRNO;
  45777. *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1,
  45778. *rsaCaPrivKeyBufSz, keyFile);
  45779. XFCLOSE(keyFile);
  45780. if (*rsaCaPrivKeyBufSz == 0)
  45781. return WC_TEST_RET_ENC_ERRNO;
  45782. }
  45783. #endif /* USE_CERT_BUFFERS */
  45784. #endif /* NO_RSA */
  45785. /* ECC */
  45786. #ifdef HAVE_ECC
  45787. #ifdef USE_CERT_BUFFERS_256
  45788. if (*eccClientCertBufSz < (word32)sizeof_cliecc_cert_der_256)
  45789. return WC_TEST_RET_ENC_NC;
  45790. XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45791. *eccClientCertBufSz = sizeof_cliecc_cert_der_256;
  45792. #else
  45793. certFile = XFOPEN(eccClientCert, "rb");
  45794. if (!certFile)
  45795. return WC_TEST_RET_ENC_ERRNO;
  45796. *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1,
  45797. *eccClientCertBufSz, certFile);
  45798. XFCLOSE(certFile);
  45799. if (*eccClientCertBufSz == 0)
  45800. return WC_TEST_RET_ENC_ERRNO;
  45801. #endif /* USE_CERT_BUFFERS_256 */
  45802. #ifdef USE_CERT_BUFFERS_256
  45803. if (*eccClientPrivKeyBufSz < (word32)sizeof_ecc_clikey_der_256)
  45804. return WC_TEST_RET_ENC_NC;
  45805. XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45806. *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256;
  45807. #else
  45808. keyFile = XFOPEN(eccClientKey, "rb");
  45809. if (!keyFile)
  45810. return WC_TEST_RET_ENC_ERRNO;
  45811. *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1,
  45812. *eccClientPrivKeyBufSz, keyFile);
  45813. XFCLOSE(keyFile);
  45814. if (*eccClientPrivKeyBufSz == 0)
  45815. return WC_TEST_RET_ENC_ERRNO;
  45816. #endif /* USE_CERT_BUFFERS_256 */
  45817. #endif /* HAVE_ECC */
  45818. #ifdef NO_RSA
  45819. (void)rsaClientCertBuf;
  45820. (void)rsaClientCertBufSz;
  45821. (void)rsaClientPrivKeyBuf;
  45822. (void)rsaClientPrivKeyBufSz;
  45823. (void)rsaServerCertBuf;
  45824. (void)rsaServerCertBufSz;
  45825. (void)rsaServerPrivKeyBuf;
  45826. (void)rsaServerPrivKeyBufSz;
  45827. (void)rsaCaCertBuf;
  45828. (void)rsaCaCertBufSz;
  45829. (void)rsaCaPrivKeyBuf;
  45830. (void)rsaCaPrivKeyBufSz;
  45831. #endif
  45832. #ifndef HAVE_ECC
  45833. (void)eccClientCertBuf;
  45834. (void)eccClientCertBufSz;
  45835. (void)eccClientPrivKeyBuf;
  45836. (void)eccClientPrivKeyBufSz;
  45837. #endif
  45838. #ifndef NO_FILESYSTEM
  45839. (void)certFile;
  45840. (void)keyFile;
  45841. #endif
  45842. return 0;
  45843. }
  45844. typedef struct {
  45845. const byte* content;
  45846. word32 contentSz;
  45847. int contentOID;
  45848. int encryptOID;
  45849. int keyWrapOID;
  45850. int keyAgreeOID;
  45851. byte* cert;
  45852. size_t certSz;
  45853. byte* privateKey;
  45854. word32 privateKeySz;
  45855. byte* optionalUkm;
  45856. word32 optionalUkmSz;
  45857. int ktriOptions; /* KTRI options flags */
  45858. int kariOptions; /* KARI options flags */
  45859. /* KEKRI specific */
  45860. const byte* secretKey; /* key, only for kekri RecipientInfo types */
  45861. word32 secretKeySz; /* size of secretKey, bytes */
  45862. const byte* secretKeyId; /* key identifier */
  45863. word32 secretKeyIdSz; /* size of key identifier, bytes */
  45864. void* timePtr; /* time_t pointer */
  45865. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  45866. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  45867. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  45868. word32 otherAttrSz; /* size of otherAttr, bytes */
  45869. int kekriOptions; /* KEKRI options flags */
  45870. /* PWRI specific */
  45871. const char* password;
  45872. word32 passwordSz;
  45873. const byte* salt;
  45874. word32 saltSz;
  45875. int kdfOID;
  45876. int hashOID;
  45877. int kdfIterations;
  45878. int pwriOptions; /* PWRI options flags */
  45879. /* ORI specific */
  45880. int isOri;
  45881. int oriOptions; /* ORI options flags */
  45882. const char* outFileName;
  45883. } pkcs7EnvelopedVector;
  45884. static const byte asnDataOid[] = {
  45885. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01
  45886. };
  45887. /* ORI encrypt callback, responsible for encrypting content-encryption key (CEK)
  45888. * and giving wolfCrypt the value for oriOID and oriValue to place in
  45889. * OtherRecipientInfo.
  45890. *
  45891. * Returns 0 on success, negative upon error. */
  45892. static int myOriEncryptCb(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* oriType,
  45893. word32* oriTypeSz, byte* oriValue, word32* oriValueSz,
  45894. void* ctx)
  45895. {
  45896. int i;
  45897. /* make sure buffers are large enough */
  45898. if (*oriValueSz < (2 + cekSz))
  45899. return WC_TEST_RET_ENC_NC;
  45900. if (*oriTypeSz < sizeof(asnDataOid))
  45901. return WC_TEST_RET_ENC_NC;
  45902. /* our simple encryption algorithm will be take the bitwise complement */
  45903. oriValue[0] = 0x04; /*ASN OCTET STRING */
  45904. oriValue[1] = (byte)cekSz; /* length */
  45905. for (i = 0; i < (int)cekSz; i++) {
  45906. oriValue[2 + i] = ~cek[i];
  45907. }
  45908. *oriValueSz = 2 + cekSz;
  45909. /* set oriType to ASN.1 encoded data OID */
  45910. XMEMCPY(oriType, asnDataOid, sizeof(asnDataOid));
  45911. *oriTypeSz = sizeof(asnDataOid);
  45912. (void)pkcs7;
  45913. (void)ctx;
  45914. return 0;
  45915. }
  45916. /* ORI decrypt callback, responsible for providing a decrypted content
  45917. * encryption key (CEK) placed into decryptedKey and size placed into
  45918. * decryptedKeySz. oriOID and oriValue are given to the callback to help
  45919. * in decrypting the encrypted CEK.
  45920. *
  45921. * Returns 0 on success, negative upon error. */
  45922. static int myOriDecryptCb(wc_PKCS7* pkcs7, byte* oriType, word32 oriTypeSz,
  45923. byte* oriValue, word32 oriValueSz, byte* decryptedKey,
  45924. word32* decryptedKeySz, void* ctx)
  45925. {
  45926. int i;
  45927. /* make sure oriType matches what we expect */
  45928. if (oriTypeSz != sizeof(asnDataOid))
  45929. return WC_TEST_RET_ENC_NC;
  45930. if (XMEMCMP(oriType, asnDataOid, sizeof(asnDataOid)) != 0)
  45931. return WC_TEST_RET_ENC_NC;
  45932. /* make sure decrypted buffer is large enough */
  45933. if (*decryptedKeySz < oriValueSz)
  45934. return WC_TEST_RET_ENC_NC;
  45935. /* decrypt encrypted CEK using simple bitwise complement,
  45936. only for example */
  45937. for (i = 0; i < (int)oriValueSz - 2; i++) {
  45938. decryptedKey[i] = ~oriValue[2 + i];
  45939. }
  45940. *decryptedKeySz = oriValueSz - 2;
  45941. (void)pkcs7;
  45942. (void)ctx;
  45943. return 0;
  45944. }
  45945. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45946. /* returns 0 on success */
  45947. static int myDecryptionFunc(wc_PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45948. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45949. byte* in, int inSz, byte* out, void* usrCtx)
  45950. {
  45951. wc_test_ret_t ret;
  45952. int keyId = -1, keySz;
  45953. word32 keyIdSz = 8;
  45954. const byte* key;
  45955. byte keyIdRaw[8];
  45956. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45957. Aes *aes;
  45958. #else
  45959. Aes aes[1];
  45960. #endif
  45961. /* looking for KEY ID
  45962. * fwDecryptKeyID OID "1.2.840.113549.1.9.16.2.37
  45963. */
  45964. WOLFSSL_SMALL_STACK_STATIC const unsigned char OID[] = {
  45965. /* 0x06, 0x0B do not pass in tag and length */
  45966. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  45967. 0x01, 0x09, 0x10, 0x02, 0x25
  45968. };
  45969. WOLFSSL_SMALL_STACK_STATIC const byte defKey[] = {
  45970. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45971. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45972. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45973. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45974. };
  45975. WOLFSSL_SMALL_STACK_STATIC const byte altKey[] = {
  45976. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45977. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45978. };
  45979. /* test user context passed in */
  45980. if (usrCtx == NULL || *(int*)usrCtx != 1) {
  45981. return WC_TEST_RET_ENC_NC;
  45982. }
  45983. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45984. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  45985. return WC_TEST_RET_ENC_ERRNO;
  45986. #endif
  45987. /* if needing to find keyIdSz can call with NULL */
  45988. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), NULL,
  45989. &keyIdSz);
  45990. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  45991. printf("Unexpected error %d when getting keyIdSz\n", ret);
  45992. printf("Possibly no KEY ID attribute set\n");
  45993. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45994. }
  45995. else {
  45996. XMEMSET(keyIdRaw, 0, sizeof(keyIdRaw));
  45997. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), keyIdRaw,
  45998. &keyIdSz);
  45999. if (ret < 0) {
  46000. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46001. }
  46002. if (keyIdSz < 3) {
  46003. printf("keyIdSz is smaller than expected\n");
  46004. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46005. }
  46006. if (keyIdSz > 2 + sizeof(int)) {
  46007. printf("example case was only expecting a keyId of int size\n");
  46008. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46009. }
  46010. /* keyIdRaw[0] OCTET TAG */
  46011. /* keyIdRaw[1] Length */
  46012. #ifdef BIG_ENDIAN_ORDER
  46013. if (keyIdRaw[1] == 0x01) {
  46014. keyId = 1;
  46015. }
  46016. #else
  46017. XMEMCPY(&keyId, keyIdRaw + 2, sizeof(keyId));
  46018. #endif
  46019. }
  46020. /* Use keyID here if found to select key and decrypt in HSM or in this
  46021. * example just select key and do software decryption */
  46022. if (keyId == 1) {
  46023. key = altKey;
  46024. keySz = sizeof(altKey);
  46025. }
  46026. else {
  46027. key = defKey;
  46028. keySz = sizeof(defKey);
  46029. }
  46030. switch (encryptOID) {
  46031. #ifdef WOLFSSL_AES_256
  46032. case AES256CBCb:
  46033. if ((keySz != 32 ) || (ivSz != WC_AES_BLOCK_SIZE))
  46034. WARNING_OUT(BAD_FUNC_ARG, out);
  46035. break;
  46036. #endif
  46037. #ifdef WOLFSSL_AES_128
  46038. case AES128CBCb:
  46039. if ((keySz != 16 ) || (ivSz != WC_AES_BLOCK_SIZE))
  46040. ERROR_OUT(BAD_FUNC_ARG, out);
  46041. break;
  46042. #endif
  46043. default:
  46044. printf("Unsupported content cipher type for example");
  46045. ERROR_OUT(ALGO_ID_E, out);
  46046. };
  46047. ret = wc_AesInit(aes, HEAP_HINT, INVALID_DEVID);
  46048. if (ret == 0) {
  46049. ret = wc_AesSetKey(aes, key, (word32)keySz, iv, AES_DECRYPTION);
  46050. if (ret == 0)
  46051. ret = wc_AesCbcDecrypt(aes, out, in, (word32)inSz);
  46052. wc_AesFree(aes);
  46053. }
  46054. out:
  46055. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  46056. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46057. #endif
  46058. (void)aad;
  46059. (void)aadSz;
  46060. (void)authTag;
  46061. (void)authTagSz;
  46062. return (int)ret;
  46063. }
  46064. #endif /* !NO_AES && HAVE_AES_CBC */
  46065. #define PKCS7_BUF_SIZE 2048
  46066. static wc_test_ret_t pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46067. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46068. byte* eccCert, word32 eccCertSz,
  46069. byte* eccPrivKey, word32 eccPrivKeySz)
  46070. {
  46071. wc_test_ret_t ret = 0;
  46072. int testSz = 0, i;
  46073. int envelopedSz, decodedSz;
  46074. byte *enveloped = NULL;
  46075. byte *decoded = NULL;
  46076. wc_PKCS7* pkcs7 = NULL;
  46077. #ifdef ECC_TIMING_RESISTANT
  46078. WC_RNG rng;
  46079. #endif
  46080. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46081. XFILE pkcs7File;
  46082. #endif
  46083. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46084. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46085. 0x72,0x6c,0x64
  46086. };
  46087. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256) && \
  46088. defined(HAVE_ECC) && defined(WOLFSSL_SHA512)
  46089. byte optionalUkm[] = {
  46090. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46091. };
  46092. #endif /* !NO_AES */
  46093. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  46094. !defined(NO_SHA)
  46095. /* encryption key for kekri recipient types */
  46096. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46097. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46098. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46099. };
  46100. /* encryption key identifier */
  46101. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46102. 0x02,0x02,0x03,0x04
  46103. };
  46104. #endif
  46105. #if !defined(NO_PWDBASED) && !defined(NO_SHA) && \
  46106. !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46107. #ifndef HAVE_FIPS
  46108. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password"; /* NOTE: Password is too short for FIPS */
  46109. #else
  46110. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46111. #endif
  46112. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46113. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46114. };
  46115. #endif
  46116. #define MAX_TESTVECTORS_LEN 13
  46117. #define ADD_PKCS7ENVELOPEDVECTOR(...) { \
  46118. pkcs7EnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46119. if (testSz == MAX_TESTVECTORS_LEN) { \
  46120. ret = WC_TEST_RET_ENC_NC; \
  46121. goto out; \
  46122. } \
  46123. XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\
  46124. }
  46125. pkcs7EnvelopedVector *testVectors = NULL;
  46126. #ifdef ECC_TIMING_RESISTANT
  46127. XMEMSET(&rng, 0, sizeof(rng));
  46128. #endif
  46129. testVectors = (pkcs7EnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46130. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46131. if (testVectors == NULL) {
  46132. ret = WC_TEST_RET_ENC_ERRNO;
  46133. goto out;
  46134. }
  46135. {
  46136. /* key transport key encryption technique */
  46137. #ifndef NO_RSA
  46138. #ifndef NO_DES3
  46139. ADD_PKCS7ENVELOPEDVECTOR(
  46140. data, (word32)sizeof(data), DATA, DES3b, 0, 0, rsaCert, rsaCertSz,
  46141. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46142. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46143. "pkcs7envelopedDataDES3.der");
  46144. #endif
  46145. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46146. #ifdef WOLFSSL_AES_128
  46147. ADD_PKCS7ENVELOPEDVECTOR(
  46148. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, rsaCert, rsaCertSz,
  46149. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46150. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46151. "pkcs7envelopedDataAES128CBC.der");
  46152. #endif
  46153. #ifdef WOLFSSL_AES_192
  46154. ADD_PKCS7ENVELOPEDVECTOR(
  46155. data, (word32)sizeof(data), DATA, AES192CBCb, 0, 0, rsaCert, rsaCertSz,
  46156. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46157. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46158. "pkcs7envelopedDataAES192CBC.der");
  46159. #endif
  46160. #ifdef WOLFSSL_AES_256
  46161. ADD_PKCS7ENVELOPEDVECTOR(
  46162. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46163. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46164. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46165. "pkcs7envelopedDataAES256CBC.der");
  46166. /* explicitly using SKID for SubjectKeyIdentifier */
  46167. ADD_PKCS7ENVELOPEDVECTOR(
  46168. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46169. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_SKID, 0, NULL, 0, NULL, 0, NULL,
  46170. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46171. "pkcs7envelopedDataAES256CBC_SKID.der");
  46172. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46173. ADD_PKCS7ENVELOPEDVECTOR(
  46174. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46175. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_ISSUER_AND_SERIAL_NUMBER, 0,
  46176. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46177. 0, 0, 0, 0, "pkcs7envelopedDataAES256CBC_IANDS.der");
  46178. #endif
  46179. #endif /* !NO_AES && HAVE_AES_CBC */
  46180. #endif
  46181. /* key agreement key encryption technique*/
  46182. #ifdef HAVE_ECC
  46183. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46184. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46185. ADD_PKCS7ENVELOPEDVECTOR(
  46186. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP,
  46187. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46188. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46189. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46190. "pkcs7envelopedDataAES128CBC_ECDH_SHA1KDF.der");
  46191. #endif
  46192. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46193. ADD_PKCS7ENVELOPEDVECTOR(
  46194. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46195. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46196. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46197. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46198. "pkcs7envelopedDataAES256CBC_ECDH_SHA256KDF.der");
  46199. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46200. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46201. ADD_PKCS7ENVELOPEDVECTOR(
  46202. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46203. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46204. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46205. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46206. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF.der");
  46207. /* with optional user keying material (ukm) */
  46208. ADD_PKCS7ENVELOPEDVECTOR(
  46209. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46210. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46211. eccPrivKeySz, optionalUkm, sizeof(optionalUkm), 0, 0, NULL, 0,
  46212. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46213. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF_ukm.der");
  46214. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46215. #endif /* !NO_AES && HAVE_AES_CBC */
  46216. #endif
  46217. /* kekri (KEKRecipientInfo) recipient types */
  46218. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46219. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46220. ADD_PKCS7ENVELOPEDVECTOR(
  46221. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP, 0,
  46222. NULL, 0, NULL, 0, NULL, 0, 0, 0, secretKey, sizeof(secretKey),
  46223. secretKeyId, sizeof(secretKeyId), NULL, NULL, 0, NULL, 0,
  46224. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46225. "pkcs7envelopedDataAES128CBC_KEKRI.der");
  46226. #endif
  46227. #endif /* !NO_AES && HAVE_AES_CBC */
  46228. /* pwri (PasswordRecipientInfo) recipient types */
  46229. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  46230. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46231. ADD_PKCS7ENVELOPEDVECTOR(
  46232. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0,
  46233. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46234. NULL, 0, NULL, NULL, 0, NULL, 0, 0, password,
  46235. (word32)XSTRLEN(password), salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46236. 0, 0, 0, "pkcs7envelopedDataAES128CBC_PWRI.der");
  46237. #endif
  46238. #endif
  46239. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_128)
  46240. /* ori (OtherRecipientInfo) recipient types */
  46241. ADD_PKCS7ENVELOPEDVECTOR(
  46242. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, NULL, 0, NULL, 0,
  46243. NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0,
  46244. NULL, 0, 0, 0, 0, 0, 1, 0, "pkcs7envelopedDataAES128CBC_ORI.der");
  46245. #endif
  46246. };
  46247. #undef MAX_TESTVECTORS_LEN
  46248. #undef ADD_PKCS7ENVELOPEDVECTOR
  46249. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46250. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46251. if ((! enveloped) || (! decoded)) {
  46252. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46253. }
  46254. #ifdef ECC_TIMING_RESISTANT
  46255. #ifndef HAVE_FIPS
  46256. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46257. #else
  46258. ret = wc_InitRng(&rng);
  46259. #endif
  46260. if (ret != 0)
  46261. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46262. #endif
  46263. for (i = 0; i < testSz; i++) {
  46264. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46265. #ifdef WOLFSSL_ASYNC_CRYPT
  46266. INVALID_DEVID /* async PKCS7 is not supported */
  46267. #else
  46268. devId
  46269. #endif
  46270. );
  46271. if (pkcs7 == NULL) {
  46272. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46273. }
  46274. if (testVectors[i].secretKey != NULL) {
  46275. /* KEKRI recipient type */
  46276. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46277. if (ret != 0)
  46278. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46279. pkcs7->content = (byte*)testVectors[i].content;
  46280. pkcs7->contentSz = testVectors[i].contentSz;
  46281. pkcs7->contentOID = testVectors[i].contentOID;
  46282. pkcs7->encryptOID = testVectors[i].encryptOID;
  46283. pkcs7->ukm = testVectors[i].optionalUkm;
  46284. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46285. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46286. (byte *)testVectors[i].secretKey, testVectors[i].secretKeySz,
  46287. (byte *)testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46288. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46289. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46290. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46291. if (ret < 0) {
  46292. wc_PKCS7_Free(pkcs7);
  46293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46294. }
  46295. /* set key, for decryption */
  46296. ret = wc_PKCS7_SetKey(pkcs7, (byte *)testVectors[i].secretKey,
  46297. testVectors[i].secretKeySz);
  46298. if (ret != 0) {
  46299. wc_PKCS7_Free(pkcs7);
  46300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46301. }
  46302. } else if (testVectors[i].password != NULL) {
  46303. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46304. /* PWRI recipient type */
  46305. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46306. if (ret != 0)
  46307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46308. pkcs7->content = (byte*)testVectors[i].content;
  46309. pkcs7->contentSz = testVectors[i].contentSz;
  46310. pkcs7->contentOID = testVectors[i].contentOID;
  46311. pkcs7->encryptOID = testVectors[i].encryptOID;
  46312. pkcs7->ukm = testVectors[i].optionalUkm;
  46313. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46314. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46315. (byte *)testVectors[i].password, testVectors[i].passwordSz,
  46316. (byte *)testVectors[i].salt, testVectors[i].saltSz,
  46317. testVectors[i].kdfOID,
  46318. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46319. testVectors[i].encryptOID, testVectors[i].pwriOptions);
  46320. if (ret < 0) {
  46321. wc_PKCS7_Free(pkcs7);
  46322. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46323. }
  46324. /* set password, for decryption */
  46325. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46326. testVectors[i].passwordSz);
  46327. if (ret < 0) {
  46328. wc_PKCS7_Free(pkcs7);
  46329. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46330. }
  46331. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46332. } else if (testVectors[i].isOri == 1) {
  46333. /* ORI recipient type */
  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. pkcs7->content = (byte*)testVectors[i].content;
  46338. pkcs7->contentSz = testVectors[i].contentSz;
  46339. pkcs7->contentOID = testVectors[i].contentOID;
  46340. pkcs7->encryptOID = testVectors[i].encryptOID;
  46341. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46342. testVectors[i].oriOptions);
  46343. if (ret < 0) {
  46344. wc_PKCS7_Free(pkcs7);
  46345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46346. }
  46347. /* set decrypt callback for decryption */
  46348. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46349. if (ret < 0) {
  46350. wc_PKCS7_Free(pkcs7);
  46351. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46352. }
  46353. } else {
  46354. /* KTRI or KARI recipient types */
  46355. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46356. if (ret != 0)
  46357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46358. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46359. (word32)testVectors[i].certSz);
  46360. if (ret != 0) {
  46361. wc_PKCS7_Free(pkcs7);
  46362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46363. }
  46364. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46365. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46366. pkcs7->privateKey = testVectors[i].privateKey;
  46367. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46368. pkcs7->content = (byte*)testVectors[i].content;
  46369. pkcs7->contentSz = testVectors[i].contentSz;
  46370. pkcs7->contentOID = testVectors[i].contentOID;
  46371. pkcs7->encryptOID = testVectors[i].encryptOID;
  46372. pkcs7->ukm = testVectors[i].optionalUkm;
  46373. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46374. /* set SubjectIdentifier type for KTRI types */
  46375. if (testVectors[i].ktriOptions & CMS_SKID) {
  46376. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46377. if (ret != 0) {
  46378. wc_PKCS7_Free(pkcs7);
  46379. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46380. }
  46381. } else if (testVectors[i].ktriOptions &
  46382. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46383. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46384. CMS_ISSUER_AND_SERIAL_NUMBER);
  46385. if (ret != 0) {
  46386. wc_PKCS7_Free(pkcs7);
  46387. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46388. }
  46389. }
  46390. }
  46391. #ifdef ECC_TIMING_RESISTANT
  46392. pkcs7->rng = &rng;
  46393. #endif
  46394. /* encode envelopedData */
  46395. envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, enveloped,
  46396. PKCS7_BUF_SIZE);
  46397. if (envelopedSz <= 0) {
  46398. wc_PKCS7_Free(pkcs7);
  46399. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46400. }
  46401. /* decode envelopedData */
  46402. pkcs7->contentOID = 0;
  46403. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, (word32)envelopedSz,
  46404. decoded, PKCS7_BUF_SIZE);
  46405. if (pkcs7->contentOID != testVectors[i].contentOID ||
  46406. decodedSz <= 0) {
  46407. wc_PKCS7_Free(pkcs7);
  46408. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46409. }
  46410. /* test decode result */
  46411. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  46412. wc_PKCS7_Free(pkcs7);
  46413. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46414. }
  46415. #ifndef NO_PKCS7_STREAM
  46416. { /* test reading byte by byte */
  46417. int z;
  46418. for (z = 0; z < envelopedSz; z++) {
  46419. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped + z, 1,
  46420. decoded, PKCS7_BUF_SIZE);
  46421. if (decodedSz <= 0 &&
  46422. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46423. {
  46424. printf("unexpected error %d\n", decodedSz);
  46425. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46426. }
  46427. }
  46428. /* test decode result */
  46429. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46430. printf("stream read compare failed\n");
  46431. wc_PKCS7_Free(pkcs7);
  46432. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46433. }
  46434. }
  46435. #endif
  46436. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46437. /* output pkcs7 envelopedData for external testing */
  46438. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46439. if (!pkcs7File) {
  46440. wc_PKCS7_Free(pkcs7);
  46441. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46442. }
  46443. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  46444. XFCLOSE(pkcs7File);
  46445. if (ret != envelopedSz) {
  46446. wc_PKCS7_Free(pkcs7);
  46447. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46448. } else {
  46449. /* reset ret to 0 for success */
  46450. ret = 0;
  46451. }
  46452. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  46453. wc_PKCS7_Free(pkcs7);
  46454. pkcs7 = NULL;
  46455. }
  46456. #ifdef ECC_TIMING_RESISTANT
  46457. wc_FreeRng(&rng);
  46458. #endif
  46459. (void)eccCert;
  46460. (void)eccCertSz;
  46461. (void)eccPrivKey;
  46462. (void)eccPrivKeySz;
  46463. (void)rsaCert;
  46464. (void)rsaCertSz;
  46465. (void)rsaPrivKey;
  46466. (void)rsaPrivKeySz;
  46467. out:
  46468. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46469. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46470. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46471. return ret;
  46472. }
  46473. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void)
  46474. {
  46475. wc_test_ret_t ret = 0;
  46476. byte* rsaCert = NULL;
  46477. byte* rsaPrivKey = NULL;
  46478. word32 rsaCertSz = 0;
  46479. word32 rsaPrivKeySz = 0;
  46480. byte* eccCert = NULL;
  46481. byte* eccPrivKey = NULL;
  46482. word32 eccCertSz = 0;
  46483. word32 eccPrivKeySz = 0;
  46484. WOLFSSL_ENTER("pkcs7enveloped_test");
  46485. #ifndef NO_RSA
  46486. /* read client RSA cert and key in DER format */
  46487. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46488. if (rsaCert == NULL)
  46489. return WC_TEST_RET_ENC_ERRNO;
  46490. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46491. if (rsaPrivKey == NULL) {
  46492. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46493. return WC_TEST_RET_ENC_NC;
  46494. }
  46495. rsaCertSz = FOURK_BUF;
  46496. rsaPrivKeySz = FOURK_BUF;
  46497. #endif /* NO_RSA */
  46498. #ifdef HAVE_ECC
  46499. /* read client ECC cert and key in DER format */
  46500. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46501. if (eccCert == NULL) {
  46502. #ifndef NO_RSA
  46503. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46504. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46505. #endif
  46506. return WC_TEST_RET_ENC_NC;
  46507. }
  46508. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46509. if (eccPrivKey == NULL) {
  46510. #ifndef NO_RSA
  46511. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46512. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46513. #endif
  46514. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46515. return WC_TEST_RET_ENC_NC;
  46516. }
  46517. eccCertSz = FOURK_BUF;
  46518. eccPrivKeySz = FOURK_BUF;
  46519. #endif /* HAVE_ECC */
  46520. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  46521. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  46522. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  46523. eccPrivKey, &eccPrivKeySz);
  46524. if (ret < 0) {
  46525. #ifndef NO_RSA
  46526. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46527. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46528. #endif
  46529. #ifdef HAVE_ECC
  46530. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46531. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46532. #endif
  46533. return WC_TEST_RET_ENC_EC(ret);
  46534. }
  46535. ret = pkcs7enveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  46536. rsaPrivKey, (word32)rsaPrivKeySz,
  46537. eccCert, (word32)eccCertSz,
  46538. eccPrivKey, (word32)eccPrivKeySz);
  46539. #ifndef NO_RSA
  46540. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46541. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46542. #endif
  46543. #ifdef HAVE_ECC
  46544. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46545. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46546. #endif
  46547. return ret;
  46548. }
  46549. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  46550. typedef struct {
  46551. const byte* content;
  46552. word32 contentSz;
  46553. int contentOID;
  46554. int encryptOID;
  46555. int keyWrapOID;
  46556. int keyAgreeOID;
  46557. byte* cert;
  46558. size_t certSz;
  46559. byte* privateKey;
  46560. word32 privateKeySz;
  46561. PKCS7Attrib* authAttribs;
  46562. word32 authAttribsSz;
  46563. PKCS7Attrib* unauthAttribs;
  46564. word32 unauthAttribsSz;
  46565. /* KARI / KTRI specific */
  46566. byte* optionalUkm;
  46567. word32 optionalUkmSz;
  46568. int ktriOptions; /* KTRI options flags */
  46569. int kariOptions; /* KARI options flags */
  46570. /* KEKRI specific */
  46571. byte* secretKey; /* key, only for kekri RecipientInfo types */
  46572. word32 secretKeySz; /* size of secretKey, bytes */
  46573. byte* secretKeyId; /* key identifier */
  46574. word32 secretKeyIdSz; /* size of key identifier, bytes */
  46575. void* timePtr; /* time_t pointer */
  46576. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  46577. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  46578. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  46579. word32 otherAttrSz; /* size of otherAttr, bytes */
  46580. int kekriOptions; /* KEKRI options flags */
  46581. /* PWRI specific */
  46582. char* password; /* password */
  46583. word32 passwordSz; /* password size, bytes */
  46584. byte* salt; /* KDF salt */
  46585. word32 saltSz; /* KDF salt size, bytes */
  46586. int kdfOID; /* KDF OID */
  46587. int hashOID; /* KDF hash algorithm OID */
  46588. int kdfIterations; /* KDF iterations */
  46589. int kekEncryptOID; /* KEK encryption algorithm OID */
  46590. int pwriOptions; /* PWRI options flags */
  46591. /* ORI specific */
  46592. int isOri;
  46593. int oriOptions; /* ORI options flags */
  46594. const char* outFileName;
  46595. } pkcs7AuthEnvelopedVector;
  46596. static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46597. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46598. byte* eccCert, word32 eccCertSz,
  46599. byte* eccPrivKey, word32 eccPrivKeySz)
  46600. {
  46601. wc_test_ret_t ret = 0;
  46602. int testSz = 0, i;
  46603. int envelopedSz, decodedSz;
  46604. byte *enveloped = NULL;
  46605. byte *decoded = NULL;
  46606. WC_RNG rng;
  46607. wc_PKCS7* pkcs7;
  46608. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46609. XFILE pkcs7File;
  46610. #endif
  46611. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46612. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46613. 0x72,0x6c,0x64
  46614. };
  46615. byte senderNonce[PKCS7_NONCE_SZ + 2];
  46616. #ifdef HAVE_ECC
  46617. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46618. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46619. WOLFSSL_SMALL_STACK_STATIC const byte senderNonceOid[] =
  46620. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  46621. 0x09, 0x05 };
  46622. PKCS7Attrib attribs[] =
  46623. {
  46624. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  46625. sizeof(senderNonce) }
  46626. };
  46627. #endif
  46628. #endif
  46629. #endif
  46630. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && defined(HAVE_ECC) && \
  46631. defined(WOLFSSL_SHA512) && defined(HAVE_AESGCM)
  46632. WOLFSSL_SMALL_STACK_STATIC const byte optionalUkm[] = {
  46633. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46634. };
  46635. #endif /* !NO_AES */
  46636. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46637. /* encryption key for kekri recipient types */
  46638. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46639. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46640. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46641. };
  46642. /* encryption key identifier */
  46643. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46644. 0x02,0x02,0x03,0x04
  46645. };
  46646. #endif
  46647. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  46648. !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46649. #ifndef HAVE_FIPS
  46650. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password";
  46651. #else
  46652. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46653. #endif
  46654. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46655. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46656. };
  46657. #endif
  46658. #define MAX_TESTVECTORS_LEN 20
  46659. #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \
  46660. pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46661. if (testSz == MAX_TESTVECTORS_LEN) { \
  46662. ret = WC_TEST_RET_ENC_NC; \
  46663. goto out; \
  46664. } \
  46665. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  46666. sizeof _this_vector); \
  46667. }
  46668. pkcs7AuthEnvelopedVector *testVectors = NULL;
  46669. XMEMSET(&rng, 0, sizeof(rng));
  46670. testVectors = (pkcs7AuthEnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46671. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46672. if (testVectors == NULL) {
  46673. ret = WC_TEST_RET_ENC_ERRNO;
  46674. goto out;
  46675. }
  46676. {
  46677. /* key transport key encryption technique */
  46678. #ifndef NO_RSA
  46679. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46680. #ifdef WOLFSSL_AES_128
  46681. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46682. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, rsaCert, rsaCertSz,
  46683. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46684. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46685. 0, 0, "pkcs7authEnvelopedDataAES128GCM.der");
  46686. #endif
  46687. #ifdef WOLFSSL_AES_192
  46688. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46689. data, (word32)sizeof(data), DATA, AES192GCMb, 0, 0, rsaCert, rsaCertSz,
  46690. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46691. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46692. 0, 0, "pkcs7authEnvelopedDataAES192GCM.der");
  46693. #endif
  46694. #ifdef WOLFSSL_AES_256
  46695. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46696. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46697. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46698. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46699. 0, 0, "pkcs7authEnvelopedDataAES256GCM.der");
  46700. /* test with contentType set to FirmwarePkgData */
  46701. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46702. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, 0, 0,
  46703. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL,
  46704. 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL,
  46705. 0, 0, 0, 0, 0, 0, 0, 0,
  46706. "pkcs7authEnvelopedDataAES256GCM_firmwarePkgData.der");
  46707. /* explicitly using SKID for SubjectKeyIdentifier */
  46708. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46709. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46710. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, CMS_SKID, 0,
  46711. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46712. 0, 0, 0, 0, 0, "pkcs7authEnvelopedDataAES256GCM_SKID.der");
  46713. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46714. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46715. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46716. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0,
  46717. CMS_ISSUER_AND_SERIAL_NUMBER, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46718. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46719. "pkcs7authEnvelopedDataAES256GCM_IANDS.der");
  46720. #endif
  46721. #else
  46722. (void)rsaCert;
  46723. (void)rsaCertSz;
  46724. (void)rsaPrivKey;
  46725. (void)rsaPrivKeySz;
  46726. #endif /* !NO_AES && !HAVE_AESGCM */
  46727. #endif
  46728. /* key agreement key encryption technique*/
  46729. #ifdef HAVE_ECC
  46730. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46731. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46732. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46733. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP,
  46734. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46735. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46736. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46737. "pkcs7authEnvelopedDataAES128GCM_ECDH_SHA1KDF.der");
  46738. #endif
  46739. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46740. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46741. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46742. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46743. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46744. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46745. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF.der");
  46746. /* with authenticated attributes */
  46747. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46748. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46749. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46750. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46751. NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46752. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46753. 0, 0, 0,
  46754. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_authAttribs.der");
  46755. /* with unauthenticated attributes */
  46756. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46757. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46758. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46759. eccPrivKeySz, NULL, 0, attribs,
  46760. (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0, NULL, 0,
  46761. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46762. 0, 0, 0,
  46763. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_unauthAttribs.der");
  46764. /* with authenticated AND unauthenticated attributes */
  46765. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46766. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46767. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46768. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46769. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46770. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46771. 0, 0, 0, 0, 0, 0,
  46772. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_bothAttribs.der");
  46773. /* with authenticated AND unauthenticated attributes AND
  46774. * contentType of FirmwarePkgData */
  46775. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46776. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, AES256_WRAP,
  46777. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46778. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46779. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46780. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46781. 0, 0, 0, 0, 0, 0,
  46782. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_fw_bothAttribs.der");
  46783. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46784. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46785. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46786. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46787. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46788. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL,
  46789. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46790. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF.der");
  46791. /* with optional user keying material (ukm) */
  46792. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46793. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46794. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46795. eccPrivKeySz, NULL, 0, NULL, 0, (byte *)optionalUkm, sizeof(optionalUkm), 0,
  46796. 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46797. 0, 0, 0, 0, 0, 0,
  46798. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF_ukm.der");
  46799. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46800. #endif /* !NO_AES && HAVE_AESGCM */
  46801. #endif
  46802. /* kekri (KEKRecipientInfo) recipient types */
  46803. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46804. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46805. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46806. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP, 0,
  46807. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0,
  46808. (byte *)secretKey, sizeof(secretKey), (byte *)secretKeyId, sizeof(secretKeyId),
  46809. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46810. "pkcs7authEnvelopedDataAES128GCM_KEKRI.der");
  46811. #endif
  46812. #endif
  46813. /* pwri (PasswordRecipientInfo) recipient types */
  46814. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM)
  46815. #if !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46816. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46817. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0,
  46818. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46819. NULL, 0, NULL, NULL, 0, NULL, 0, 0, (char *)password,
  46820. (word32)XSTRLEN(password), (byte *)salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46821. AES128CBCb, 0, 0, 0, "pkcs7authEnvelopedDataAES128GCM_PWRI.der");
  46822. #endif
  46823. #endif
  46824. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46825. #ifdef WOLFSSL_AES_128
  46826. /* ori (OtherRecipientInfo) recipient types */
  46827. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46828. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, NULL, 0, NULL, 0,
  46829. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46830. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 1, 0,
  46831. "pkcs7authEnvelopedDataAES128GCM_ORI.der");
  46832. #endif
  46833. #endif
  46834. }
  46835. #undef MAX_TESTVECTORS_LEN
  46836. #undef ADD_PKCS7AUTHENVELOPEDVECTOR
  46837. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46838. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46839. if ((! enveloped) || (! decoded)) {
  46840. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46841. }
  46842. /* generate senderNonce */
  46843. {
  46844. #ifndef HAVE_FIPS
  46845. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46846. #else
  46847. ret = wc_InitRng(&rng);
  46848. #endif
  46849. if (ret != 0)
  46850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46851. senderNonce[0] = 0x04;
  46852. senderNonce[1] = PKCS7_NONCE_SZ;
  46853. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  46854. if (ret != 0) {
  46855. wc_FreeRng(&rng);
  46856. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46857. }
  46858. }
  46859. for (i = 0; i < testSz; i++) {
  46860. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46861. #ifdef WOLFSSL_ASYNC_CRYPT
  46862. INVALID_DEVID /* async PKCS7 is not supported */
  46863. #else
  46864. devId
  46865. #endif
  46866. );
  46867. if (pkcs7 == NULL) {
  46868. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46869. }
  46870. if (testVectors[i].secretKey != NULL) {
  46871. /* KEKRI recipient type */
  46872. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46873. if (ret != 0)
  46874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46875. pkcs7->content = (byte*)testVectors[i].content;
  46876. pkcs7->contentSz = testVectors[i].contentSz;
  46877. pkcs7->contentOID = testVectors[i].contentOID;
  46878. pkcs7->encryptOID = testVectors[i].encryptOID;
  46879. pkcs7->ukm = testVectors[i].optionalUkm;
  46880. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46881. pkcs7->authAttribs = testVectors[i].authAttribs;
  46882. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46883. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46884. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46885. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46886. testVectors[i].secretKey, testVectors[i].secretKeySz,
  46887. testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46888. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46889. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46890. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46891. if (ret < 0) {
  46892. wc_PKCS7_Free(pkcs7);
  46893. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46894. }
  46895. /* set key, for decryption */
  46896. ret = wc_PKCS7_SetKey(pkcs7, testVectors[i].secretKey,
  46897. testVectors[i].secretKeySz);
  46898. if (ret != 0) {
  46899. wc_PKCS7_Free(pkcs7);
  46900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46901. }
  46902. } else if (testVectors[i].password != NULL) {
  46903. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46904. /* PWRI recipient type */
  46905. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46906. if (ret != 0)
  46907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46908. pkcs7->content = (byte*)testVectors[i].content;
  46909. pkcs7->contentSz = testVectors[i].contentSz;
  46910. pkcs7->contentOID = testVectors[i].contentOID;
  46911. pkcs7->encryptOID = testVectors[i].encryptOID;
  46912. pkcs7->ukm = testVectors[i].optionalUkm;
  46913. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46914. pkcs7->authAttribs = testVectors[i].authAttribs;
  46915. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46916. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46917. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46918. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46919. (byte*)testVectors[i].password,
  46920. testVectors[i].passwordSz, testVectors[i].salt,
  46921. testVectors[i].saltSz, testVectors[i].kdfOID,
  46922. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46923. testVectors[i].kekEncryptOID, testVectors[i].pwriOptions);
  46924. if (ret < 0) {
  46925. wc_PKCS7_Free(pkcs7);
  46926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46927. }
  46928. /* set password, for decryption */
  46929. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46930. testVectors[i].passwordSz);
  46931. if (ret < 0) {
  46932. wc_PKCS7_Free(pkcs7);
  46933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46934. }
  46935. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46936. } else if (testVectors[i].isOri == 1) {
  46937. /* ORI recipient type */
  46938. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46939. if (ret != 0)
  46940. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46941. pkcs7->content = (byte*)testVectors[i].content;
  46942. pkcs7->contentSz = testVectors[i].contentSz;
  46943. pkcs7->contentOID = testVectors[i].contentOID;
  46944. pkcs7->encryptOID = testVectors[i].encryptOID;
  46945. pkcs7->authAttribs = testVectors[i].authAttribs;
  46946. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46947. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46948. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46949. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46950. testVectors[i].oriOptions);
  46951. if (ret < 0) {
  46952. wc_PKCS7_Free(pkcs7);
  46953. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46954. }
  46955. /* set decrypt callback for decryption */
  46956. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46957. if (ret < 0) {
  46958. wc_PKCS7_Free(pkcs7);
  46959. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46960. }
  46961. } else {
  46962. /* KTRI or KARI recipient types */
  46963. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46964. (word32)testVectors[i].certSz);
  46965. if (ret != 0) {
  46966. wc_PKCS7_Free(pkcs7);
  46967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46968. }
  46969. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46970. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46971. pkcs7->privateKey = testVectors[i].privateKey;
  46972. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46973. pkcs7->content = (byte*)testVectors[i].content;
  46974. pkcs7->contentSz = testVectors[i].contentSz;
  46975. pkcs7->contentOID = testVectors[i].contentOID;
  46976. pkcs7->encryptOID = testVectors[i].encryptOID;
  46977. pkcs7->ukm = testVectors[i].optionalUkm;
  46978. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46979. pkcs7->authAttribs = testVectors[i].authAttribs;
  46980. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46981. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46982. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46983. /* set SubjectIdentifier type for KTRI types */
  46984. if (testVectors[i].ktriOptions & CMS_SKID) {
  46985. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46986. if (ret != 0) {
  46987. wc_PKCS7_Free(pkcs7);
  46988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46989. }
  46990. } else if (testVectors[i].ktriOptions &
  46991. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46992. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46993. CMS_ISSUER_AND_SERIAL_NUMBER);
  46994. if (ret != 0) {
  46995. wc_PKCS7_Free(pkcs7);
  46996. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46997. }
  46998. }
  46999. }
  47000. #ifdef ECC_TIMING_RESISTANT
  47001. pkcs7->rng = &rng;
  47002. #endif
  47003. /* encode envelopedData */
  47004. envelopedSz = wc_PKCS7_EncodeAuthEnvelopedData(pkcs7, enveloped,
  47005. PKCS7_BUF_SIZE);
  47006. if (envelopedSz <= 0) {
  47007. wc_PKCS7_Free(pkcs7);
  47008. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  47009. }
  47010. #ifndef NO_PKCS7_STREAM
  47011. { /* test reading byte by byte */
  47012. int z;
  47013. for (z = 0; z < envelopedSz; z++) {
  47014. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7,
  47015. enveloped + z, 1, decoded, PKCS7_BUF_SIZE);
  47016. if (decodedSz <= 0 &&
  47017. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  47018. {
  47019. printf("unexpected error %d\n", decodedSz);
  47020. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47021. }
  47022. }
  47023. /* test decode result */
  47024. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47025. printf("stream read compare failed\n");
  47026. wc_PKCS7_Free(pkcs7);
  47027. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47028. }
  47029. }
  47030. #endif
  47031. /* decode envelopedData */
  47032. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7, enveloped,
  47033. (word32)envelopedSz, decoded,
  47034. PKCS7_BUF_SIZE);
  47035. if (decodedSz <= 0) {
  47036. wc_PKCS7_Free(pkcs7);
  47037. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47038. }
  47039. /* test decode result */
  47040. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  47041. wc_PKCS7_Free(pkcs7);
  47042. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47043. }
  47044. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47045. /* output pkcs7 envelopedData for external testing */
  47046. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47047. if (!pkcs7File) {
  47048. wc_PKCS7_Free(pkcs7);
  47049. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47050. }
  47051. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  47052. XFCLOSE(pkcs7File);
  47053. if (ret != envelopedSz) {
  47054. wc_PKCS7_Free(pkcs7);
  47055. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47056. } else {
  47057. /* reset ret to 0 for success */
  47058. ret = 0;
  47059. }
  47060. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47061. wc_PKCS7_Free(pkcs7);
  47062. pkcs7 = NULL;
  47063. }
  47064. wc_FreeRng(&rng);
  47065. (void)eccCert;
  47066. (void)eccCertSz;
  47067. (void)eccPrivKey;
  47068. (void)eccPrivKeySz;
  47069. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  47070. (void)secretKey;
  47071. (void)secretKeyId;
  47072. #endif
  47073. #ifdef NO_RSA
  47074. (void)rsaCert;
  47075. (void)rsaCertSz;
  47076. (void)rsaPrivKey;
  47077. (void)rsaPrivKeySz;
  47078. #endif
  47079. out:
  47080. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47081. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47082. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47083. return ret;
  47084. }
  47085. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void)
  47086. {
  47087. wc_test_ret_t ret = 0;
  47088. byte* rsaCert = NULL;
  47089. byte* rsaPrivKey = NULL;
  47090. word32 rsaCertSz = 0;
  47091. word32 rsaPrivKeySz = 0;
  47092. byte* eccCert = NULL;
  47093. byte* eccPrivKey = NULL;
  47094. word32 eccCertSz = 0;
  47095. word32 eccPrivKeySz = 0;
  47096. WOLFSSL_ENTER("pkcs7authenveloped_test");
  47097. #ifndef NO_RSA
  47098. /* read client RSA cert and key in DER format */
  47099. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47100. if (rsaCert == NULL)
  47101. return WC_TEST_RET_ENC_ERRNO;
  47102. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47103. if (rsaPrivKey == NULL) {
  47104. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47105. return WC_TEST_RET_ENC_NC;
  47106. }
  47107. rsaCertSz = FOURK_BUF;
  47108. rsaPrivKeySz = FOURK_BUF;
  47109. #endif /* NO_RSA */
  47110. #ifdef HAVE_ECC
  47111. /* read client ECC cert and key in DER format */
  47112. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47113. if (eccCert == NULL) {
  47114. #ifndef NO_RSA
  47115. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47116. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47117. #endif
  47118. return WC_TEST_RET_ENC_NC;
  47119. }
  47120. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47121. if (eccPrivKey == NULL) {
  47122. #ifndef NO_RSA
  47123. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47124. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47125. #endif
  47126. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47127. return WC_TEST_RET_ENC_NC;
  47128. }
  47129. eccCertSz = FOURK_BUF;
  47130. eccPrivKeySz = FOURK_BUF;
  47131. #endif /* HAVE_ECC */
  47132. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  47133. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  47134. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  47135. eccPrivKey, &eccPrivKeySz);
  47136. if (ret < 0) {
  47137. #ifndef NO_RSA
  47138. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47139. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47140. #endif
  47141. #ifdef HAVE_ECC
  47142. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47143. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47144. #endif
  47145. return WC_TEST_RET_ENC_EC(ret);
  47146. }
  47147. ret = pkcs7authenveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  47148. rsaPrivKey, (word32)rsaPrivKeySz,
  47149. eccCert, (word32)eccCertSz,
  47150. eccPrivKey, (word32)eccPrivKeySz);
  47151. #ifndef NO_RSA
  47152. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47153. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47154. #endif
  47155. #ifdef HAVE_ECC
  47156. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47157. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47158. #endif
  47159. return ret;
  47160. }
  47161. #endif /* HAVE_AESGCM || HAVE_AESCCM */
  47162. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47163. static const byte p7DefKey[] = {
  47164. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47165. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47166. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47167. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47168. };
  47169. static const byte p7AltKey[] = {
  47170. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47171. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47172. };
  47173. static int myCEKwrapFunc(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  47174. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  47175. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  47176. {
  47177. wc_test_ret_t ret;
  47178. if (cek == NULL || out == NULL)
  47179. return BAD_FUNC_ARG;
  47180. /* test case sanity checks */
  47181. if (keyIdSz != 1) {
  47182. return WC_TEST_RET_ENC_NC;
  47183. }
  47184. if (keyId[0] != 0x00) {
  47185. return WC_TEST_RET_ENC_NC;
  47186. }
  47187. if (type != (int)PKCS7_KEKRI) {
  47188. return WC_TEST_RET_ENC_NC;
  47189. }
  47190. switch (keyWrapAlgo) {
  47191. case AES256_WRAP:
  47192. ret = wc_AesKeyUnWrap(p7DefKey, sizeof(p7DefKey), cek, cekSz,
  47193. out, outSz, NULL);
  47194. if (ret <= 0)
  47195. return (int)ret;
  47196. break;
  47197. default:
  47198. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  47199. return BAD_KEYWRAP_ALG_E;
  47200. };
  47201. (void)pkcs7;
  47202. (void)direction;
  47203. (void)orginKey; /* used with KAKRI */
  47204. (void)orginKeySz;
  47205. return (int)ret;
  47206. }
  47207. /* returns key size on success */
  47208. static wc_test_ret_t getFirmwareKey(wc_PKCS7* pkcs7, byte* key, word32 keySz)
  47209. {
  47210. wc_test_ret_t ret;
  47211. word32 atrSz;
  47212. byte atr[256];
  47213. /* Additionally can look for fwWrappedFirmwareKey
  47214. * 1.2.840.113529.1.9.16.1.16 */
  47215. const unsigned char fwWrappedFirmwareKey[] = {
  47216. /* 0x06, 0x0B */
  47217. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47218. 0x01, 0x09, 0x10, 0x02, 0x27
  47219. };
  47220. /* find keyID in fwWrappedFirmwareKey */
  47221. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  47222. sizeof(fwWrappedFirmwareKey), NULL, &atrSz);
  47223. if (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  47224. XMEMSET(atr, 0, sizeof(atr));
  47225. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  47226. sizeof(fwWrappedFirmwareKey), atr, &atrSz);
  47227. /* keyIdRaw[0] OCTET TAG */
  47228. /* keyIdRaw[1] Length */
  47229. if (ret > 0) {
  47230. wc_PKCS7* envPkcs7;
  47231. envPkcs7 = wc_PKCS7_New(NULL, 0);
  47232. if (envPkcs7 == NULL) {
  47233. return MEMORY_E;
  47234. }
  47235. wc_PKCS7_Init(envPkcs7, NULL, 0);
  47236. ret = wc_PKCS7_SetWrapCEKCb(envPkcs7, myCEKwrapFunc);
  47237. if (ret == 0) {
  47238. /* expecting FIRMWARE_PKG_DATA content */
  47239. envPkcs7->contentOID = FIRMWARE_PKG_DATA;
  47240. ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz,
  47241. key, keySz);
  47242. if (envPkcs7->contentOID != FIRMWARE_PKG_DATA) {
  47243. /* the contentOID should have been set to the inner
  47244. * FIRMWARE_PKG_DATA content */
  47245. ret = BAD_STATE_E;
  47246. }
  47247. }
  47248. wc_PKCS7_Free(envPkcs7);
  47249. }
  47250. }
  47251. return ret;
  47252. }
  47253. /* create a KEKRI enveloped data
  47254. * return size on success */
  47255. static wc_test_ret_t envelopedData_encrypt(byte* in, word32 inSz, byte* out,
  47256. word32 outSz)
  47257. {
  47258. wc_test_ret_t ret;
  47259. wc_PKCS7* pkcs7;
  47260. WOLFSSL_SMALL_STACK_STATIC const byte keyId[] = { 0x00 };
  47261. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  47262. if (pkcs7 == NULL)
  47263. return WC_TEST_RET_ENC_ERRNO;
  47264. pkcs7->content = in;
  47265. pkcs7->contentSz = inSz;
  47266. pkcs7->contentOID = FIRMWARE_PKG_DATA;
  47267. pkcs7->encryptOID = AES256CBCb;
  47268. pkcs7->ukm = NULL;
  47269. pkcs7->ukmSz = 0;
  47270. /* add recipient (KEKRI type) */
  47271. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP, (byte*)p7DefKey,
  47272. sizeof(p7DefKey), (byte*)keyId,
  47273. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0);
  47274. if (ret < 0) {
  47275. printf("wc_PKCS7_AddRecipient_KEKRI() failed\n");
  47276. wc_PKCS7_Free(pkcs7);
  47277. return WC_TEST_RET_ENC_EC(ret);
  47278. }
  47279. /* encode envelopedData, returns size */
  47280. ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
  47281. if (ret <= 0) {
  47282. printf("wc_PKCS7_EncodeEnvelopedData() failed\n");
  47283. wc_PKCS7_Free(pkcs7);
  47284. return WC_TEST_RET_ENC_EC(ret);
  47285. }
  47286. wc_PKCS7_Free(pkcs7);
  47287. return ret;
  47288. }
  47289. /*
  47290. * keyHint is the KeyID to be set in the fwDecryptKeyID attribute
  47291. * returns size of buffer output on success
  47292. */
  47293. static wc_test_ret_t generateBundle(byte* out, word32 *outSz, const byte* encryptKey,
  47294. word32 encryptKeySz, byte keyHint, byte* cert, word32 certSz,
  47295. byte* key, word32 keySz)
  47296. {
  47297. wc_test_ret_t ret;
  47298. int attribNum = 1;
  47299. wc_PKCS7* pkcs7;
  47300. /* KEY ID
  47301. * fwDecryptKeyID OID 1.2.840.113549.1.9.16.2.37
  47302. */
  47303. const unsigned char fwDecryptKeyID[] = {
  47304. 0x06, 0x0B,
  47305. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47306. 0x01, 0x09, 0x10, 0x02, 0x25
  47307. };
  47308. /* fwWrappedFirmwareKey 1.2.840.113529.1.9.16.1.16 */
  47309. const unsigned char fwWrappedFirmwareKey[] = {
  47310. 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47311. 0x01, 0x09, 0x10, 0x02, 0x27
  47312. };
  47313. byte keyID[] = { 0x04, 0x01, 0x00 };
  47314. byte env[256];
  47315. char data[] = "Test of wolfSSL PKCS7 decrypt callback";
  47316. PKCS7Attrib attribs[] =
  47317. {
  47318. { fwDecryptKeyID, sizeof(fwDecryptKeyID), keyID, sizeof(keyID) },
  47319. { fwWrappedFirmwareKey, sizeof(fwWrappedFirmwareKey), env, 0 }
  47320. };
  47321. keyID[2] = keyHint;
  47322. /* If using keyHint 0 then create a bundle with fwWrappedFirmwareKey */
  47323. if (keyHint == 0) {
  47324. ret = envelopedData_encrypt((byte*)p7DefKey, sizeof(p7DefKey), env,
  47325. sizeof(env));
  47326. if (ret <= 0) {
  47327. return ret;
  47328. }
  47329. attribs[1].valueSz = (word32)ret;
  47330. attribNum++;
  47331. }
  47332. /* init PKCS7 */
  47333. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  47334. if (pkcs7 == NULL)
  47335. return WC_TEST_RET_ENC_ERRNO;
  47336. ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz);
  47337. if (ret != 0) {
  47338. printf("ERROR: wc_PKCS7_InitWithCert() failed, ret = %d\n", ret);
  47339. wc_PKCS7_Free(pkcs7);
  47340. return WC_TEST_RET_ENC_EC(ret);
  47341. }
  47342. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47343. if (ret != 0) {
  47344. wc_PKCS7_Free(pkcs7);
  47345. return WC_TEST_RET_ENC_EC(ret);
  47346. }
  47347. /* encode Signed Encrypted FirmwarePkgData */
  47348. if (encryptKeySz == 16) {
  47349. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  47350. encryptKeySz, key, keySz, AES128CBCb, RSAk, SHA256h,
  47351. (byte*)data, sizeof(data), NULL, 0,
  47352. attribs, (word32)attribNum, out, *outSz);
  47353. }
  47354. else {
  47355. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  47356. encryptKeySz, key, keySz, AES256CBCb, RSAk, SHA256h,
  47357. (byte*)data, sizeof(data), NULL, 0,
  47358. attribs, (word32)attribNum, out, *outSz);
  47359. }
  47360. if (ret <= 0) {
  47361. printf("ERROR: wc_PKCS7_EncodeSignedEncryptedFPD() failed, "
  47362. "ret = %d\n", ret);
  47363. wc_PKCS7_Free(pkcs7);
  47364. return WC_TEST_RET_ENC_EC(ret);
  47365. } else {
  47366. *outSz = (word32)ret;
  47367. }
  47368. wc_PKCS7_Free(pkcs7);
  47369. return ret;
  47370. }
  47371. /* test verification and decryption of PKCS7 bundle
  47372. * return 0 on success
  47373. */
  47374. static wc_test_ret_t verifyBundle(byte* derBuf, word32 derSz, int keyHint)
  47375. {
  47376. wc_test_ret_t ret = 0;
  47377. int usrCtx = 1; /* test value to pass as user context to callback */
  47378. wc_PKCS7* pkcs7 = NULL;
  47379. byte* sid = NULL;
  47380. word32 sidSz;
  47381. byte key[256];
  47382. word32 keySz = sizeof(key);
  47383. byte *decoded = NULL;
  47384. int decodedSz = FOURK_BUF/2;
  47385. WOLFSSL_SMALL_STACK_STATIC const byte expectedSid[] = {
  47386. #ifdef NO_SHA
  47387. #ifdef USE_CERT_BUFFERS_1024
  47388. 0x70, 0xe7, 0x79, 0x60, 0x8f, 0x41, 0xdc, 0xe9,
  47389. 0xad, 0x8b, 0x3d, 0x0c, 0x20, 0xf4, 0xc3, 0xf2,
  47390. 0x8e, 0x05, 0xe8, 0xa1, 0xb6, 0x68, 0x74, 0x06,
  47391. 0xbc, 0xe7, 0xc5, 0x3c, 0x13, 0x99, 0x79, 0xb9
  47392. #else
  47393. 0xce, 0x06, 0x07, 0xbe, 0xf1, 0xa6, 0x1e, 0x36,
  47394. 0xef, 0xfa, 0xbc, 0x89, 0x71, 0xf3, 0x23, 0x9e,
  47395. 0x34, 0x6d, 0xae, 0x86, 0xae, 0x2b, 0xdc, 0xf4,
  47396. 0x4a, 0x27, 0xd5, 0x63, 0x59, 0x4f, 0x4a, 0x71
  47397. #endif
  47398. #else /* !NO_SHA */
  47399. #ifdef USE_CERT_BUFFERS_1024
  47400. 0x81, 0x69, 0x0f, 0xf8, 0xdf, 0xdd, 0xcf, 0x34,
  47401. 0x29, 0xd5, 0x67, 0x75, 0x71, 0x85, 0xc7, 0x75,
  47402. 0x10, 0x69, 0x59, 0xec,
  47403. #else
  47404. 0x33, 0xD8, 0x45, 0x66, 0xD7, 0x68, 0x87, 0x18,
  47405. 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26,
  47406. 0xD7, 0x85, 0x65, 0xC0
  47407. #endif
  47408. #endif /* !NO_SHA */
  47409. };
  47410. decoded = (byte *)XMALLOC(decodedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47411. if (decoded == NULL) {
  47412. ret = MEMORY_E;
  47413. goto out;
  47414. }
  47415. pkcs7 = wc_PKCS7_New(HEAP_HINT, INVALID_DEVID);
  47416. if (pkcs7 == NULL) {
  47417. ret = MEMORY_E;
  47418. goto out;
  47419. }
  47420. /* Test verify */
  47421. ret = wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID);
  47422. if (ret != 0)
  47423. goto out;
  47424. ret = wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47425. if (ret != 0)
  47426. goto out;
  47427. ret = wc_PKCS7_VerifySignedData(pkcs7, derBuf, derSz);
  47428. if (ret != 0)
  47429. goto out;
  47430. /* Get size of SID and print it out */
  47431. ret = wc_PKCS7_GetSignerSID(pkcs7, NULL, &sidSz);
  47432. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  47433. goto out;
  47434. sid = (byte*)XMALLOC(sidSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47435. if (sid == NULL) {
  47436. ret = MEMORY_E;
  47437. goto out;
  47438. }
  47439. ret = wc_PKCS7_GetSignerSID(pkcs7, sid, &sidSz);
  47440. if (ret != 0)
  47441. goto out;
  47442. ret = XMEMCMP(sid, expectedSid, sidSz);
  47443. if (ret != 0) {
  47444. ret = PKCS7_NO_SIGNER_E; /* close enough */
  47445. goto out;
  47446. }
  47447. /* get expected fwWrappedFirmwareKey */
  47448. if (keyHint == 0) {
  47449. ret = getFirmwareKey(pkcs7, key, keySz);
  47450. if (ret < 0)
  47451. goto out;
  47452. pkcs7->encryptionKey = key;
  47453. pkcs7->encryptionKeySz = (word32)ret;
  47454. }
  47455. else {
  47456. decodedSz = PKCS7_BUF_SIZE;
  47457. ret = wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc);
  47458. if (ret != 0)
  47459. goto out;
  47460. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)&usrCtx);
  47461. if (ret != 0)
  47462. goto out;
  47463. }
  47464. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  47465. pkcs7->contentSz, decoded, (word32)decodedSz);
  47466. if (decodedSz < 0) {
  47467. ret = decodedSz;
  47468. goto out;
  47469. }
  47470. ret = 0;
  47471. out:
  47472. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47473. if (pkcs7)
  47474. wc_PKCS7_Free(pkcs7);
  47475. XFREE(sid, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47476. return ret;
  47477. }
  47478. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key, word32 keySz)
  47479. {
  47480. wc_test_ret_t ret = 0;
  47481. word32 derSz;
  47482. byte *derBuf = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47483. WOLFSSL_ENTER("pkcs7callback_test");
  47484. if (! derBuf)
  47485. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47486. /* Doing default generation and verify */
  47487. derSz = FOURK_BUF;
  47488. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 0, cert,
  47489. certSz, key, keySz);
  47490. if (ret <= 0) {
  47491. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47492. }
  47493. ret = verifyBundle(derBuf, derSz, 0);
  47494. if (ret != 0)
  47495. ERROR_OUT(ret, out);
  47496. /* test choosing other key with keyID */
  47497. derSz = FOURK_BUF;
  47498. ret = generateBundle(derBuf, &derSz, p7AltKey, sizeof(p7AltKey), 1,
  47499. cert, certSz, key, keySz);
  47500. if (ret <= 0) {
  47501. ERROR_OUT(ret, out);
  47502. }
  47503. ret = verifyBundle(derBuf, derSz, 1);
  47504. if (ret != 0)
  47505. ERROR_OUT(ret, out);
  47506. /* test fail case with wrong keyID */
  47507. derSz = FOURK_BUF;
  47508. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 1,
  47509. cert, certSz, key, keySz);
  47510. if (ret <= 0) {
  47511. ERROR_OUT(ret, out);
  47512. }
  47513. ret = verifyBundle(derBuf, derSz, 1);
  47514. if (ret == 0) {
  47515. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47516. }
  47517. ret = 0;
  47518. out:
  47519. XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47520. return ret;
  47521. }
  47522. #endif /* !NO_AES && HAVE_AES_CBC */
  47523. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47524. typedef struct {
  47525. const byte* content;
  47526. word32 contentSz;
  47527. int contentOID;
  47528. int encryptOID;
  47529. byte* encryptionKey;
  47530. word32 encryptionKeySz;
  47531. PKCS7Attrib* attribs;
  47532. word32 attribsSz;
  47533. const char* outFileName;
  47534. } pkcs7EncryptedVector;
  47535. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void)
  47536. {
  47537. wc_test_ret_t ret = 0;
  47538. int i, testSz;
  47539. int encryptedSz, decodedSz, attribIdx;
  47540. wc_PKCS7* pkcs7;
  47541. byte *encrypted;
  47542. byte *decoded;
  47543. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47544. XFILE pkcs7File;
  47545. #endif
  47546. PKCS7Attrib* expectedAttrib;
  47547. PKCS7DecodedAttrib* decodedAttrib;
  47548. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47549. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47550. 0x72,0x6c,0x64
  47551. };
  47552. #ifndef NO_DES3
  47553. byte desKey[] = {
  47554. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  47555. };
  47556. byte des3Key[] = {
  47557. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  47558. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  47559. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  47560. };
  47561. #endif
  47562. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47563. #ifdef WOLFSSL_AES_128
  47564. byte aes128Key[] = {
  47565. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47566. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47567. };
  47568. #endif
  47569. #ifdef WOLFSSL_AES_192
  47570. byte aes192Key[] = {
  47571. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47572. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47573. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47574. };
  47575. #endif
  47576. #ifdef WOLFSSL_AES_256
  47577. byte aes256Key[] = {
  47578. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47579. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47580. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47581. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47582. };
  47583. #endif
  47584. #ifdef WOLFSSL_AES_256
  47585. /* Attribute example from RFC 4134, Section 7.2
  47586. * OID = 1.2.5555
  47587. * OCTET STRING = 'This is a test General ASN Attribute, number 1.' */
  47588. static const byte genAttrOid[] = { 0x06, 0x03, 0x2a, 0xab, 0x33 };
  47589. static const byte genAttr[] = { 0x04, 47,
  47590. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47591. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47592. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47593. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47594. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47595. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x31, 0x2e };
  47596. static const byte genAttrOid2[] = { 0x06, 0x03, 0x2a, 0xab, 0x34 };
  47597. static const byte genAttr2[] = { 0x04, 47,
  47598. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47599. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47600. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47601. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47602. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47603. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x32, 0x2e };
  47604. PKCS7Attrib attribs[] =
  47605. {
  47606. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) }
  47607. };
  47608. PKCS7Attrib multiAttribs[] =
  47609. {
  47610. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) },
  47611. { genAttrOid2, sizeof(genAttrOid2), genAttr2, sizeof(genAttr2) }
  47612. };
  47613. #endif
  47614. #endif /* NO_AES */
  47615. const pkcs7EncryptedVector testVectors[] =
  47616. {
  47617. #ifndef NO_DES3
  47618. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key),
  47619. NULL, 0, "pkcs7encryptedDataDES3.der"},
  47620. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey),
  47621. NULL, 0, "pkcs7encryptedDataDES.der"},
  47622. #endif /* NO_DES3 */
  47623. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47624. #ifdef WOLFSSL_AES_128
  47625. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  47626. sizeof(aes128Key), NULL, 0, "pkcs7encryptedDataAES128CBC.der"},
  47627. #endif
  47628. #ifdef WOLFSSL_AES_192
  47629. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  47630. sizeof(aes192Key), NULL, 0, "pkcs7encryptedDataAES192CBC.der"},
  47631. #endif
  47632. #ifdef WOLFSSL_AES_256
  47633. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47634. sizeof(aes256Key), NULL, 0, "pkcs7encryptedDataAES256CBC.der"},
  47635. /* test with optional unprotected attributes */
  47636. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47637. sizeof(aes256Key), attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47638. "pkcs7encryptedDataAES256CBC_attribs.der"},
  47639. /* test with multiple optional unprotected attributes */
  47640. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47641. sizeof(aes256Key), multiAttribs,
  47642. (sizeof(multiAttribs)/sizeof(PKCS7Attrib)),
  47643. "pkcs7encryptedDataAES256CBC_multi_attribs.der"},
  47644. /* test with contentType set to FirmwarePkgData */
  47645. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256CBCb, aes256Key,
  47646. sizeof(aes256Key), NULL, 0,
  47647. "pkcs7encryptedDataAES256CBC_firmwarePkgData.der"},
  47648. #endif
  47649. #endif /* !NO_AES && HAVE_AES_CBC */
  47650. };
  47651. WOLFSSL_ENTER("pkcs7encrypted_test");
  47652. encrypted = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47653. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47654. if ((! encrypted) || (! decoded)) {
  47655. ERROR_OUT(MEMORY_E, out);
  47656. }
  47657. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  47658. for (i = 0; i < testSz; i++) {
  47659. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47660. if (pkcs7 == NULL) {
  47661. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47662. }
  47663. pkcs7->content = (byte*)testVectors[i].content;
  47664. pkcs7->contentSz = testVectors[i].contentSz;
  47665. pkcs7->contentOID = testVectors[i].contentOID;
  47666. pkcs7->encryptOID = testVectors[i].encryptOID;
  47667. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  47668. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  47669. pkcs7->unprotectedAttribs = testVectors[i].attribs;
  47670. pkcs7->unprotectedAttribsSz = testVectors[i].attribsSz;
  47671. /* encode encryptedData */
  47672. encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47673. PKCS7_BUF_SIZE);
  47674. if (encryptedSz <= 0) {
  47675. wc_PKCS7_Free(pkcs7);
  47676. ERROR_OUT(WC_TEST_RET_ENC_EC(encryptedSz), out);
  47677. }
  47678. /* decode encryptedData */
  47679. #ifndef NO_PKCS7_STREAM
  47680. { /* test reading byte by byte */
  47681. int z;
  47682. for (z = 0; z < encryptedSz; z++) {
  47683. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted + z, 1,
  47684. decoded, PKCS7_BUF_SIZE);
  47685. if (decodedSz <= 0 &&
  47686. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  47687. {
  47688. printf("unexpected error %d\n", decodedSz);
  47689. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47690. }
  47691. }
  47692. /* test decode result */
  47693. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47694. printf("stream read failed\n");
  47695. wc_PKCS7_Free(pkcs7);
  47696. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47697. }
  47698. }
  47699. #endif
  47700. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47701. decoded, PKCS7_BUF_SIZE);
  47702. if (decodedSz <= 0){
  47703. wc_PKCS7_Free(pkcs7);
  47704. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47705. }
  47706. /* test decode result */
  47707. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47708. wc_PKCS7_Free(pkcs7);
  47709. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47710. }
  47711. /* verify decoded unprotected attributes */
  47712. if (pkcs7->decodedAttrib != NULL) {
  47713. decodedAttrib = pkcs7->decodedAttrib;
  47714. attribIdx = 1;
  47715. while (decodedAttrib != NULL) {
  47716. /* expected attribute, stored list is reversed */
  47717. expectedAttrib = &(pkcs7->unprotectedAttribs
  47718. [pkcs7->unprotectedAttribsSz - attribIdx]);
  47719. /* verify oid */
  47720. if (XMEMCMP(decodedAttrib->oid, expectedAttrib->oid,
  47721. decodedAttrib->oidSz) != 0) {
  47722. wc_PKCS7_Free(pkcs7);
  47723. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47724. }
  47725. /* verify value */
  47726. if (XMEMCMP(decodedAttrib->value, expectedAttrib->value,
  47727. decodedAttrib->valueSz) != 0) {
  47728. wc_PKCS7_Free(pkcs7);
  47729. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47730. }
  47731. decodedAttrib = decodedAttrib->next;
  47732. attribIdx++;
  47733. }
  47734. }
  47735. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47736. /* output pkcs7 envelopedData for external testing */
  47737. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47738. if (!pkcs7File) {
  47739. wc_PKCS7_Free(pkcs7);
  47740. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47741. }
  47742. ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File);
  47743. if (ret < 0)
  47744. ret = WC_TEST_RET_ENC_ERRNO;
  47745. else
  47746. ret = 0;
  47747. XFCLOSE(pkcs7File);
  47748. #endif
  47749. wc_PKCS7_Free(pkcs7);
  47750. }
  47751. out:
  47752. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47753. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47754. return ret;
  47755. }
  47756. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47757. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47758. typedef struct {
  47759. const byte* content;
  47760. word32 contentSz;
  47761. int contentOID;
  47762. const char* outFileName;
  47763. } pkcs7CompressedVector;
  47764. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void)
  47765. {
  47766. wc_test_ret_t ret = 0;
  47767. int i, testSz;
  47768. int compressedSz, decodedSz;
  47769. wc_PKCS7* pkcs7;
  47770. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47771. byte *compressed;
  47772. byte *decoded;
  47773. #else
  47774. byte compressed[PKCS7_BUF_SIZE];
  47775. byte decoded[PKCS7_BUF_SIZE];
  47776. #endif
  47777. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47778. XFILE pkcs7File;
  47779. #endif
  47780. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47781. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47782. 0x72,0x6c,0x64
  47783. };
  47784. const pkcs7CompressedVector testVectors[] =
  47785. {
  47786. {data, (word32)sizeof(data), DATA,
  47787. "pkcs7compressedData_data_zlib.der"},
  47788. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA,
  47789. "pkcs7compressedData_firmwarePkgData_zlib.der"},
  47790. };
  47791. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47792. compressed = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47793. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47794. if ((! compressed) || (! decoded)) {
  47795. ERROR_OUT(MEMORY_E, out);
  47796. }
  47797. #endif
  47798. WOLFSSL_ENTER("pkcs7compressed_test");
  47799. testSz = sizeof(testVectors) / sizeof(pkcs7CompressedVector);
  47800. for (i = 0; i < testSz; i++) {
  47801. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47802. if (pkcs7 == NULL) {
  47803. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47804. }
  47805. pkcs7->content = (byte*)testVectors[i].content;
  47806. pkcs7->contentSz = testVectors[i].contentSz;
  47807. pkcs7->contentOID = testVectors[i].contentOID;
  47808. /* encode compressedData */
  47809. compressedSz = wc_PKCS7_EncodeCompressedData(pkcs7, compressed,
  47810. PKCS7_BUF_SIZE);
  47811. if (compressedSz <= 0) {
  47812. wc_PKCS7_Free(pkcs7);
  47813. ERROR_OUT(WC_TEST_RET_ENC_EC(compressedSz), out);
  47814. }
  47815. /* decode compressedData */
  47816. decodedSz = wc_PKCS7_DecodeCompressedData(pkcs7, compressed,
  47817. compressedSz, decoded,
  47818. PKCS7_BUF_SIZE);
  47819. if (decodedSz <= 0){
  47820. wc_PKCS7_Free(pkcs7);
  47821. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47822. }
  47823. /* test decode result */
  47824. if (XMEMCMP(decoded, testVectors[i].content,
  47825. testVectors[i].contentSz) != 0) {
  47826. wc_PKCS7_Free(pkcs7);
  47827. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47828. }
  47829. /* make sure content type is the same */
  47830. if (testVectors[i].contentOID != pkcs7->contentOID) {
  47831. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47832. }
  47833. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47834. /* output pkcs7 compressedData for external testing */
  47835. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47836. if (!pkcs7File) {
  47837. wc_PKCS7_Free(pkcs7);
  47838. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47839. }
  47840. ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File);
  47841. if (ret < 0)
  47842. ret = WC_TEST_RET_ENC_ERRNO;
  47843. else
  47844. ret = 0;
  47845. XFCLOSE(pkcs7File);
  47846. #endif
  47847. wc_PKCS7_Free(pkcs7);
  47848. }
  47849. out:
  47850. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47851. XFREE(compressed, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47852. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47853. #endif
  47854. return ret;
  47855. } /* pkcs7compressed_test() */
  47856. #undef PKCS7_BUF_SIZE
  47857. #endif /* HAVE_LIBZ */
  47858. typedef struct {
  47859. const byte* content;
  47860. word32 contentSz;
  47861. int hashOID;
  47862. int signOID;
  47863. byte* privateKey;
  47864. word32 privateKeySz;
  47865. byte* cert;
  47866. size_t certSz;
  47867. byte* caCert;
  47868. size_t caCertSz;
  47869. PKCS7Attrib* signedAttribs;
  47870. word32 signedAttribsSz;
  47871. const char* outFileName;
  47872. int contentOID;
  47873. const byte* contentType;
  47874. word32 contentTypeSz;
  47875. int sidType;
  47876. int encryptOID; /* for single-shot encrypt alg OID */
  47877. int encCompFlag; /* for single-shot. 1 = enc, 2 = comp, 3 = both*/
  47878. const byte* encryptKey; /* for single-shot, encryptedData */
  47879. word32 encryptKeySz; /* for single-shot, encryptedData */
  47880. PKCS7Attrib* unprotectedAttribs; /* for single-shot, encryptedData */
  47881. word32 unprotectedAttribsSz; /* for single-shot, encryptedData */
  47882. word16 detachedSignature; /* generate detached signature (0:1) */
  47883. } pkcs7SignedVector;
  47884. static wc_test_ret_t pkcs7signed_run_vectors(
  47885. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47886. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47887. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47888. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47889. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47890. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47891. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47892. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47893. {
  47894. wc_test_ret_t ret;
  47895. int testSz = 0, i;
  47896. int encodedSz;
  47897. byte* out = NULL;
  47898. word32 outSz;
  47899. WC_RNG rng;
  47900. wc_PKCS7* pkcs7 = NULL;
  47901. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47902. XFILE file;
  47903. #endif
  47904. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47905. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47906. 0x72,0x6c,0x64
  47907. };
  47908. static const byte transIdOid[] =
  47909. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47910. 0x09, 0x07 };
  47911. static const byte messageTypeOid[] =
  47912. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47913. 0x09, 0x02 };
  47914. static const byte senderNonceOid[] =
  47915. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47916. 0x09, 0x05 };
  47917. #ifndef NO_SHA
  47918. byte transId[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47919. #else
  47920. byte transId[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47921. #endif
  47922. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47923. byte senderNonce[PKCS7_NONCE_SZ + 2];
  47924. PKCS7Attrib attribs[] =
  47925. {
  47926. { transIdOid, sizeof(transIdOid), transId,
  47927. sizeof(transId) - 1 }, /* take off the null */
  47928. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47929. sizeof(messageType) },
  47930. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  47931. sizeof(senderNonce) }
  47932. };
  47933. /* for testing custom contentType, FirmwarePkgData */
  47934. static const byte customContentType[] = { 0x06, 0x0B, 0x2A, 0x86,
  47935. 0x48, 0x86, 0xF7, 0x0D,
  47936. 0x01, 0x09, 0x10, 0x01, 0x10 };
  47937. #define MAX_TESTVECTORS_LEN 20
  47938. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47939. const pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47940. if (testSz == MAX_TESTVECTORS_LEN) { \
  47941. ret = WC_TEST_RET_ENC_NC; \
  47942. goto out; \
  47943. } \
  47944. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47945. sizeof _this_vector); \
  47946. }
  47947. pkcs7SignedVector *testVectors = NULL;
  47948. XMEMSET(&rng, 0, sizeof(rng));
  47949. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47950. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47951. if (testVectors == NULL) {
  47952. ret = WC_TEST_RET_ENC_ERRNO;
  47953. goto out;
  47954. }
  47955. {
  47956. #ifndef NO_RSA
  47957. #ifndef NO_SHA
  47958. /* RSA with SHA */
  47959. ADD_PKCS7SIGNEDVECTOR(
  47960. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47961. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47962. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47963. "pkcs7signedData_RSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0, NULL,
  47964. 0, 0);
  47965. /* RSA with SHA, no signed attributes */
  47966. ADD_PKCS7SIGNEDVECTOR(
  47967. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47968. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz,
  47969. NULL, 0, NULL, 0,
  47970. "pkcs7signedData_RSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47971. NULL, 0, 0);
  47972. #endif
  47973. #ifdef WOLFSSL_SHA224
  47974. /* RSA with SHA224 */
  47975. ADD_PKCS7SIGNEDVECTOR(
  47976. data, (word32)sizeof(data), SHA224h, RSAk, rsaClientPrivKeyBuf,
  47977. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47978. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47979. "pkcs7signedData_RSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47980. NULL, 0, 0);
  47981. #endif
  47982. #ifndef NO_SHA256
  47983. /* RSA with SHA256 */
  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.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47989. NULL, 0, 0);
  47990. /* RSA with SHA256, detached signature */
  47991. ADD_PKCS7SIGNEDVECTOR(
  47992. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47993. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47994. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47995. "pkcs7signedData_RSA_SHA256_detachedSig.der", 0, NULL, 0, 0, 0, 0,
  47996. NULL, 0, NULL, 0, 1);
  47997. /* RSA with SHA256 and SubjectKeyIdentifier in SignerIdentifier */
  47998. ADD_PKCS7SIGNEDVECTOR(
  47999. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48000. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48001. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48002. "pkcs7signedData_RSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  48003. NULL, 0, NULL, 0, 0);
  48004. /* RSA with SHA256 and custom contentType */
  48005. ADD_PKCS7SIGNEDVECTOR(
  48006. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48007. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48008. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48009. "pkcs7signedData_RSA_SHA256_custom_contentType.der", 0,
  48010. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  48011. NULL, 0, 0);
  48012. /* RSA with SHA256 and FirmwarePkgData contentType */
  48013. ADD_PKCS7SIGNEDVECTOR(
  48014. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48015. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48016. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48017. "pkcs7signedData_RSA_SHA256_firmwarePkgData.der",
  48018. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48019. /* RSA with SHA256 using server cert and ca cert */
  48020. ADD_PKCS7SIGNEDVECTOR(
  48021. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48022. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48023. rsaCaCertBuf, rsaCaCertBufSz,
  48024. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48025. "pkcs7signedData_RSA_SHA256_with_ca_cert.der", 0, NULL, 0, 0, 0, 0,
  48026. NULL, 0, NULL, 0, 0);
  48027. #endif
  48028. #if defined(WOLFSSL_SHA384)
  48029. /* RSA with SHA384 */
  48030. ADD_PKCS7SIGNEDVECTOR(
  48031. data, (word32)sizeof(data), SHA384h, RSAk, rsaClientPrivKeyBuf,
  48032. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48033. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48034. "pkcs7signedData_RSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48035. NULL, 0, 0);
  48036. #endif
  48037. #if defined(WOLFSSL_SHA512)
  48038. /* RSA with SHA512 */
  48039. ADD_PKCS7SIGNEDVECTOR(
  48040. data, (word32)sizeof(data), SHA512h, RSAk, rsaClientPrivKeyBuf,
  48041. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48042. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48043. "pkcs7signedData_RSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48044. NULL, 0, 0);
  48045. #endif
  48046. #endif /* NO_RSA */
  48047. #ifdef HAVE_ECC
  48048. #ifndef NO_SHA
  48049. /* ECDSA with SHA */
  48050. ADD_PKCS7SIGNEDVECTOR(
  48051. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  48052. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48053. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48054. "pkcs7signedData_ECDSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48055. NULL, 0, 0);
  48056. /* ECDSA with SHA, no signed attributes */
  48057. ADD_PKCS7SIGNEDVECTOR(
  48058. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  48059. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz,
  48060. NULL, 0, NULL, 0,
  48061. "pkcs7signedData_ECDSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48062. NULL, 0, 0);
  48063. #endif
  48064. #ifdef WOLFSSL_SHA224
  48065. /* ECDSA with SHA224 */
  48066. ADD_PKCS7SIGNEDVECTOR(
  48067. data, (word32)sizeof(data), SHA224h, ECDSAk, eccClientPrivKeyBuf,
  48068. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48069. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48070. "pkcs7signedData_ECDSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48071. NULL, 0, 0);
  48072. #endif
  48073. #ifndef NO_SHA256
  48074. /* ECDSA with SHA256 */
  48075. ADD_PKCS7SIGNEDVECTOR(
  48076. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48077. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48078. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48079. "pkcs7signedData_ECDSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48080. NULL, 0, 0);
  48081. /* ECDSA with SHA256 and SubjectKeyIdentifier in SigherIdentifier */
  48082. ADD_PKCS7SIGNEDVECTOR(
  48083. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48084. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48085. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48086. "pkcs7signedData_ECDSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  48087. NULL, 0, NULL, 0, 0);
  48088. /* ECDSA with SHA256 and custom contentType */
  48089. ADD_PKCS7SIGNEDVECTOR(
  48090. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48091. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48092. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48093. "pkcs7signedData_ECDSA_SHA256_custom_contentType.der", 0,
  48094. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  48095. NULL, 0, 0);
  48096. /* ECDSA with SHA256 and FirmwarePkgData contentType */
  48097. ADD_PKCS7SIGNEDVECTOR(
  48098. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48099. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48100. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48101. "pkcs7signedData_ECDSA_SHA256_firmwarePkgData.der",
  48102. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48103. #endif
  48104. #ifdef WOLFSSL_SHA384
  48105. /* ECDSA with SHA384 */
  48106. ADD_PKCS7SIGNEDVECTOR(
  48107. data, (word32)sizeof(data), SHA384h, ECDSAk, eccClientPrivKeyBuf,
  48108. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48109. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48110. "pkcs7signedData_ECDSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48111. NULL, 0, 0);
  48112. #endif
  48113. #ifdef WOLFSSL_SHA512
  48114. /* ECDSA with SHA512 */
  48115. ADD_PKCS7SIGNEDVECTOR(
  48116. data, (word32)sizeof(data), SHA512h, ECDSAk, eccClientPrivKeyBuf,
  48117. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48118. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48119. "pkcs7signedData_ECDSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48120. NULL, 0, 0);
  48121. #endif
  48122. #endif /* HAVE_ECC */
  48123. };
  48124. #undef MAX_TESTVECTORS_LEN
  48125. #undef ADD_PKCS7SIGNEDVECTOR
  48126. outSz = FOURK_BUF;
  48127. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48128. if (out == NULL)
  48129. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48130. XMEMSET(out, 0, outSz);
  48131. /* test inner pad size error with block size being 0 */
  48132. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 0);
  48133. if (ret > 0)
  48134. ERROR_OUT(-1, out);
  48135. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48136. if (ret < 0)
  48137. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48138. #ifndef HAVE_FIPS
  48139. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48140. #else
  48141. ret = wc_InitRng(&rng);
  48142. #endif
  48143. if (ret != 0)
  48144. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48145. for (i = 0; i < testSz; i++) {
  48146. if (pkcs7)
  48147. wc_PKCS7_Free(pkcs7);
  48148. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48149. if (pkcs7 == NULL)
  48150. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48151. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48152. (word32)testVectors[i].certSz);
  48153. if (ret != 0)
  48154. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48155. /* load CA certificate, if present */
  48156. if (testVectors[i].caCert != NULL) {
  48157. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48158. (word32)testVectors[i].caCertSz);
  48159. if (ret != 0)
  48160. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48161. }
  48162. pkcs7->rng = &rng;
  48163. pkcs7->content = (byte*)testVectors[i].content;
  48164. pkcs7->contentSz = testVectors[i].contentSz;
  48165. pkcs7->contentOID = testVectors[i].contentOID;
  48166. pkcs7->hashOID = testVectors[i].hashOID;
  48167. pkcs7->encryptOID = testVectors[i].signOID;
  48168. pkcs7->privateKey = testVectors[i].privateKey;
  48169. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  48170. pkcs7->signedAttribs = testVectors[i].signedAttribs;
  48171. pkcs7->signedAttribsSz = testVectors[i].signedAttribsSz;
  48172. /* optional custom contentType, default is DATA,
  48173. overrides contentOID if set */
  48174. if (testVectors[i].contentType != NULL) {
  48175. ret = wc_PKCS7_SetContentType(pkcs7,
  48176. (byte *)testVectors[i].contentType,
  48177. testVectors[i].contentTypeSz);
  48178. if (ret != 0)
  48179. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48180. }
  48181. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48182. default is IssuerAndSerialNumber */
  48183. if (testVectors[i].sidType == CMS_SKID) {
  48184. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48185. if (ret != 0)
  48186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48187. }
  48188. /* generate senderNonce */
  48189. {
  48190. senderNonce[0] = 0x04;
  48191. senderNonce[1] = PKCS7_NONCE_SZ;
  48192. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  48193. if (ret != 0)
  48194. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48195. }
  48196. /* generate transactionID (used with SCEP) */
  48197. {
  48198. #ifndef NO_SHA
  48199. wc_Sha sha;
  48200. byte digest[WC_SHA_DIGEST_SIZE];
  48201. #else
  48202. wc_Sha256 sha;
  48203. byte digest[WC_SHA256_DIGEST_SIZE];
  48204. #endif
  48205. int j,k;
  48206. transId[0] = 0x13;
  48207. transId[1] = sizeof(digest) * 2;
  48208. #ifndef NO_SHA
  48209. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  48210. if (ret != 0)
  48211. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48212. wc_ShaUpdate(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  48213. wc_ShaFinal(&sha, digest);
  48214. wc_ShaFree(&sha);
  48215. #else
  48216. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  48217. if (ret != 0)
  48218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48219. wc_Sha256Update(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  48220. wc_Sha256Final(&sha, digest);
  48221. wc_Sha256Free(&sha);
  48222. #endif
  48223. for (j = 0, k = 2; j < (int)sizeof(digest); j++, k += 2) {
  48224. (void)XSNPRINTF((char*)&transId[k], 3, "%02x", digest[j]);
  48225. }
  48226. }
  48227. /* enable detached signature generation, if set */
  48228. if (testVectors[i].detachedSignature == 1) {
  48229. ret = wc_PKCS7_SetDetached(pkcs7, 1);
  48230. if (ret != 0)
  48231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48232. }
  48233. encodedSz = wc_PKCS7_EncodeSignedData(pkcs7, out, outSz);
  48234. if (encodedSz < 0)
  48235. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48236. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48237. /* write PKCS#7 to output file for more testing */
  48238. file = XFOPEN(testVectors[i].outFileName, "wb");
  48239. if (!file) {
  48240. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48241. }
  48242. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48243. XFCLOSE(file);
  48244. if (ret != (int)encodedSz)
  48245. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48246. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48247. wc_PKCS7_Free(pkcs7);
  48248. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48249. if (pkcs7 == NULL)
  48250. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48251. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48252. if (testVectors[i].detachedSignature == 1) {
  48253. /* set content for verifying detached signatures */
  48254. pkcs7->content = (byte*)testVectors[i].content;
  48255. pkcs7->contentSz = testVectors[i].contentSz;
  48256. }
  48257. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48258. if (ret < 0)
  48259. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48260. /* verify contentType extracted successfully for custom content types */
  48261. if (testVectors[i].contentTypeSz > 0) {
  48262. if (pkcs7->contentTypeSz != testVectors[i].contentTypeSz) {
  48263. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48264. } else if (XMEMCMP(pkcs7->contentType, testVectors[i].contentType,
  48265. pkcs7->contentTypeSz) != 0) {
  48266. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48267. }
  48268. }
  48269. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48270. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48271. {
  48272. /* check getting signed attributes */
  48273. #ifndef NO_SHA
  48274. byte buf[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  48275. #else
  48276. byte buf[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  48277. #endif
  48278. const byte* oidPt = transIdOid + 2; /* skip object id tag and size */
  48279. int oidSz = (int)sizeof(transIdOid) - 2;
  48280. int bufSz = 0;
  48281. if (testVectors[i].signedAttribs != NULL) {
  48282. ret = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  48283. NULL, (word32*)&bufSz);
  48284. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  48285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48286. ret = 0;
  48287. }
  48288. if (bufSz > (int)sizeof(buf))
  48289. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48290. bufSz = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  48291. buf, (word32*)&bufSz);
  48292. if ((testVectors[i].signedAttribs != NULL && bufSz < 0) ||
  48293. (testVectors[i].signedAttribs == NULL && bufSz > 0))
  48294. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48295. }
  48296. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48297. file = XFOPEN("./pkcs7cert.der", "wb");
  48298. if (!file)
  48299. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48300. ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file);
  48301. if (ret < 0)
  48302. ret = WC_TEST_RET_ENC_ERRNO;
  48303. else
  48304. ret = 0;
  48305. XFCLOSE(file);
  48306. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48307. }
  48308. out:
  48309. if (pkcs7 != NULL)
  48310. wc_PKCS7_Free(pkcs7);
  48311. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48312. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48313. wc_FreeRng(&rng);
  48314. if (ret > 0)
  48315. return 0;
  48316. (void)rsaClientCertBuf;
  48317. (void)rsaClientCertBufSz;
  48318. (void)rsaClientPrivKeyBuf;
  48319. (void)rsaClientPrivKeyBufSz;
  48320. (void)rsaServerCertBuf;
  48321. (void)rsaServerCertBufSz;
  48322. (void)rsaServerPrivKeyBuf;
  48323. (void)rsaServerPrivKeyBufSz;
  48324. (void)rsaCaCertBuf;
  48325. (void)rsaCaCertBufSz;
  48326. (void)rsaCaPrivKeyBuf;
  48327. (void)rsaCaPrivKeyBufSz;
  48328. (void)eccClientCertBuf;
  48329. (void)eccClientCertBufSz;
  48330. (void)eccClientPrivKeyBuf;
  48331. (void)eccClientPrivKeyBufSz;
  48332. return ret;
  48333. }
  48334. static wc_test_ret_t pkcs7signed_run_SingleShotVectors(
  48335. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  48336. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  48337. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  48338. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  48339. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  48340. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  48341. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  48342. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  48343. {
  48344. wc_test_ret_t ret;
  48345. int testSz = 0, i;
  48346. int encodedSz;
  48347. byte* out = NULL;
  48348. word32 outSz;
  48349. WC_RNG rng;
  48350. wc_PKCS7* pkcs7 = NULL;
  48351. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48352. XFILE file;
  48353. #endif
  48354. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48355. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48356. byte* encryptedTmp = NULL;
  48357. int encryptedTmpSz;
  48358. #endif
  48359. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  48360. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  48361. 0x72,0x6c,0x64
  48362. };
  48363. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48364. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48365. static const byte aes256Key[] = {
  48366. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48367. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48368. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48369. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  48370. };
  48371. #endif
  48372. static const byte messageTypeOid[] =
  48373. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  48374. 0x09, 0x02 };
  48375. static const byte messageType[] = { 0x13, 2, '1', '9' };
  48376. PKCS7Attrib attribs[] =
  48377. {
  48378. { messageTypeOid, sizeof(messageTypeOid), messageType,
  48379. sizeof(messageType) },
  48380. };
  48381. #define MAX_TESTVECTORS_LEN 19
  48382. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  48383. pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  48384. if (testSz == MAX_TESTVECTORS_LEN) { \
  48385. ret = WC_TEST_RET_ENC_NC; \
  48386. goto out; \
  48387. } \
  48388. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  48389. sizeof _this_vector); \
  48390. }
  48391. pkcs7SignedVector *testVectors = NULL;
  48392. XMEMSET(&rng, 0, sizeof(rng));
  48393. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  48394. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48395. if (testVectors == NULL) {
  48396. ret = WC_TEST_RET_ENC_ERRNO;
  48397. goto out;
  48398. }
  48399. {
  48400. #ifndef NO_RSA
  48401. #ifndef NO_SHA256
  48402. /* Signed FirmwarePkgData, RSA, SHA256, no attribs */
  48403. ADD_PKCS7SIGNEDVECTOR(
  48404. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48405. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48406. NULL, 0,
  48407. "pkcs7signedFirmwarePkgData_RSA_SHA256_noattr.der", 0, NULL, 0, 0,
  48408. 0, 0, NULL, 0, NULL, 0, 0);
  48409. /* Signed FirmwarePkgData, RSA, SHA256, attrs */
  48410. ADD_PKCS7SIGNEDVECTOR(
  48411. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48412. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48413. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48414. "pkcs7signedFirmwarePkgData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0,
  48415. NULL, 0, NULL, 0, 0);
  48416. /* Signed FirmwarePkgData, RSA, SHA256, SubjectKeyIdentifier, attrs */
  48417. ADD_PKCS7SIGNEDVECTOR(
  48418. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48419. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48420. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48421. "pkcs7signedFirmwarePkgData_RSA_SHA256_SKID.der", 0, NULL,
  48422. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48423. /* Signed FirmwraePkgData, RSA, SHA256, server cert and ca cert, attr */
  48424. ADD_PKCS7SIGNEDVECTOR(
  48425. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48426. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48427. rsaCaCertBuf, rsaCaCertBufSz,
  48428. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48429. "pkcs7signedFirmwarePkgData_RSA_SHA256_with_ca_cert.der", 0, NULL,
  48430. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48431. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48432. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48433. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, no attribs */
  48434. ADD_PKCS7SIGNEDVECTOR(
  48435. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48436. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48437. NULL, 0,
  48438. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48439. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48440. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, attribs */
  48441. ADD_PKCS7SIGNEDVECTOR(
  48442. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48443. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48444. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48445. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256.der", 0,
  48446. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48447. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48448. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48449. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48450. /* Signed Compressed FirmwarePkgData, RSA, SHA256, no attribs */
  48451. ADD_PKCS7SIGNEDVECTOR(
  48452. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48453. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48454. NULL, 0,
  48455. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48456. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48457. /* Signed Compressed FirmwarePkgData, RSA, SHA256, attribs */
  48458. ADD_PKCS7SIGNEDVECTOR(
  48459. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48460. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48461. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48462. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256.der", 0,
  48463. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48464. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48465. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48466. no attribs */
  48467. ADD_PKCS7SIGNEDVECTOR(
  48468. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48469. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48470. NULL, 0,
  48471. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der",
  48472. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48473. 0, 0);
  48474. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48475. attribs */
  48476. ADD_PKCS7SIGNEDVECTOR(
  48477. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48478. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48479. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48480. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256.der",
  48481. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48482. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48483. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48484. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48485. #endif /* NO_SHA256 */
  48486. #endif /* NO_RSA */
  48487. #ifdef HAVE_ECC
  48488. #ifndef NO_SHA256
  48489. /* Signed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48490. ADD_PKCS7SIGNEDVECTOR(
  48491. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48492. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48493. NULL, 0,
  48494. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48495. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48496. /* Signed FirmwarePkgData, ECDSA, SHA256, attribs */
  48497. ADD_PKCS7SIGNEDVECTOR(
  48498. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48499. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48500. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48501. "pkcs7signedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48502. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48503. /* Signed FirmwarePkgData, ECDSA, SHA256, SubjectKeyIdentifier, attr */
  48504. ADD_PKCS7SIGNEDVECTOR(
  48505. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48506. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48507. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48508. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_SKID.der", 0, NULL,
  48509. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48510. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48511. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48512. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, no attribs */
  48513. ADD_PKCS7SIGNEDVECTOR(
  48514. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48515. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48516. NULL, 0,
  48517. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48518. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48519. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, attribs */
  48520. ADD_PKCS7SIGNEDVECTOR(
  48521. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48522. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48523. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48524. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48525. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48526. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48527. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48528. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48529. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48530. ADD_PKCS7SIGNEDVECTOR(
  48531. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48532. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48533. NULL, 0,
  48534. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48535. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48536. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, attrib */
  48537. ADD_PKCS7SIGNEDVECTOR(
  48538. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48539. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48540. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48541. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48542. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48543. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48544. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48545. no attribs */
  48546. ADD_PKCS7SIGNEDVECTOR(
  48547. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48548. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48549. NULL, 0,
  48550. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der",
  48551. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48552. 0, 0);
  48553. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48554. attribs */
  48555. ADD_PKCS7SIGNEDVECTOR(
  48556. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48557. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48558. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48559. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256.der",
  48560. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48561. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48562. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48563. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48564. #endif /* NO_SHA256 */
  48565. #endif /* HAVE_ECC */
  48566. };
  48567. #undef MAX_TESTVECTORS_LEN
  48568. #undef ADD_PKCS7SIGNEDVECTOR
  48569. outSz = FOURK_BUF;
  48570. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48571. if (out == NULL)
  48572. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48573. XMEMSET(out, 0, outSz);
  48574. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48575. if (ret < 0)
  48576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48577. #ifndef HAVE_FIPS
  48578. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48579. #else
  48580. ret = wc_InitRng(&rng);
  48581. #endif
  48582. if (ret != 0)
  48583. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48584. for (i = 0; i < testSz; i++) {
  48585. if (pkcs7)
  48586. wc_PKCS7_Free(pkcs7);
  48587. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48588. if (pkcs7 == NULL)
  48589. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48590. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48591. (word32)testVectors[i].certSz);
  48592. if (ret != 0)
  48593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48594. /* load CA certificate, if present */
  48595. if (testVectors[i].caCert != NULL) {
  48596. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48597. (word32)testVectors[i].caCertSz);
  48598. if (ret != 0)
  48599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48600. }
  48601. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48602. default is IssuerAndSerialNumber */
  48603. if (testVectors[i].sidType == CMS_SKID) {
  48604. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48605. if (ret != 0)
  48606. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48607. }
  48608. if (testVectors[i].encCompFlag == 0) {
  48609. /* encode Signed FirmwarePkgData */
  48610. encodedSz = wc_PKCS7_EncodeSignedFPD(pkcs7,
  48611. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48612. testVectors[i].signOID, testVectors[i].hashOID,
  48613. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48614. testVectors[i].signedAttribs,
  48615. testVectors[i].signedAttribsSz, out, outSz);
  48616. if (encodedSz < 0)
  48617. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48618. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48619. } else if (testVectors[i].encCompFlag == 1) {
  48620. /* encode Signed Encrypted FirmwarePkgData */
  48621. encodedSz = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7,
  48622. (byte *)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48623. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48624. testVectors[i].encryptOID, testVectors[i].signOID,
  48625. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48626. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48627. testVectors[i].unprotectedAttribsSz,
  48628. testVectors[i].signedAttribs,
  48629. testVectors[i].signedAttribsSz, out, outSz);
  48630. if (encodedSz <= 0)
  48631. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48632. #endif
  48633. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48634. } else if (testVectors[i].encCompFlag == 2) {
  48635. /* encode Signed Compressed FirmwarePkgData */
  48636. encodedSz = wc_PKCS7_EncodeSignedCompressedFPD(pkcs7,
  48637. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48638. testVectors[i].signOID, testVectors[i].hashOID,
  48639. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48640. testVectors[i].signedAttribs,
  48641. testVectors[i].signedAttribsSz, out, outSz);
  48642. if (encodedSz <= 0)
  48643. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48644. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48645. } else if (testVectors[i].encCompFlag == 3) {
  48646. /* encode Signed Encrypted Compressed FirmwarePkgData */
  48647. encodedSz = wc_PKCS7_EncodeSignedEncryptedCompressedFPD(pkcs7,
  48648. (byte*)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48649. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48650. testVectors[i].encryptOID, testVectors[i].signOID,
  48651. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48652. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48653. testVectors[i].unprotectedAttribsSz,
  48654. testVectors[i].signedAttribs,
  48655. testVectors[i].signedAttribsSz, out, outSz);
  48656. if (encodedSz <= 0)
  48657. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48658. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48659. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48660. } else {
  48661. /* unsupported SignedData single-shot combination */
  48662. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48663. }
  48664. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48665. /* write PKCS#7 to output file for more testing */
  48666. file = XFOPEN(testVectors[i].outFileName, "wb");
  48667. if (!file)
  48668. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48669. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48670. XFCLOSE(file);
  48671. file = NULL;
  48672. if (ret != (int)encodedSz)
  48673. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48674. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48675. wc_PKCS7_Free(pkcs7);
  48676. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48677. if (pkcs7 == NULL)
  48678. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48679. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48680. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48681. if (ret < 0)
  48682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48683. #ifndef NO_PKCS7_STREAM
  48684. {
  48685. word32 z;
  48686. for (z = 0; z < outSz && ret != 0; z++) {
  48687. ret = wc_PKCS7_VerifySignedData(pkcs7, out + z, 1);
  48688. if (ret < 0 && ret != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  48689. printf("unexpected error %d\n", ret);
  48690. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48691. }
  48692. }
  48693. }
  48694. #endif
  48695. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48696. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48697. if (testVectors[i].encCompFlag == 0) {
  48698. /* verify decoded content matches expected */
  48699. if ((pkcs7->contentSz != testVectors[i].contentSz) ||
  48700. XMEMCMP(pkcs7->content, testVectors[i].content,
  48701. pkcs7->contentSz)) {
  48702. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48703. }
  48704. }
  48705. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48706. else if (testVectors[i].encCompFlag == 1) {
  48707. /* decrypt inner encryptedData */
  48708. pkcs7->encryptionKey = (byte *)testVectors[i].encryptKey;
  48709. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48710. ret = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48711. pkcs7->contentSz, out, outSz);
  48712. if (ret < 0)
  48713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48714. /* compare decrypted to expected */
  48715. if (((word32)ret != testVectors[i].contentSz) ||
  48716. XMEMCMP(out, testVectors[i].content, ret))
  48717. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48718. }
  48719. #endif
  48720. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48721. else if (testVectors[i].encCompFlag == 2) {
  48722. /* decompress inner compressedData */
  48723. ret = wc_PKCS7_DecodeCompressedData(pkcs7, pkcs7->content,
  48724. pkcs7->contentSz, out, outSz);
  48725. if (ret < 0)
  48726. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48727. /* compare decompressed to expected */
  48728. if (((word32)ret != testVectors[i].contentSz) ||
  48729. XMEMCMP(out, testVectors[i].content, ret))
  48730. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48731. }
  48732. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48733. else if (testVectors[i].encCompFlag == 3) {
  48734. encryptedTmpSz = FOURK_BUF;
  48735. encryptedTmp = (byte*)XMALLOC(encryptedTmpSz, HEAP_HINT,
  48736. DYNAMIC_TYPE_TMP_BUFFER);
  48737. if (encryptedTmp == NULL)
  48738. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48739. XMEMSET(encryptedTmp, 0, encryptedTmpSz);
  48740. /* decrypt inner encryptedData */
  48741. pkcs7->encryptionKey = (byte*)testVectors[i].encryptKey;
  48742. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48743. encryptedTmpSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48744. pkcs7->contentSz, encryptedTmp,
  48745. encryptedTmpSz);
  48746. if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA)
  48747. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48748. /* decompress inner compressedData */
  48749. ret = wc_PKCS7_DecodeCompressedData(pkcs7, encryptedTmp,
  48750. encryptedTmpSz, out, outSz);
  48751. if (ret < 0)
  48752. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48753. /* compare decompressed to expected */
  48754. if (((word32)ret != testVectors[i].contentSz) ||
  48755. XMEMCMP(out, testVectors[i].content, ret))
  48756. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48757. }
  48758. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48759. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48760. }
  48761. out:
  48762. if (pkcs7 != NULL)
  48763. wc_PKCS7_Free(pkcs7);
  48764. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48765. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48766. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48767. XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48768. #endif
  48769. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48770. wc_FreeRng(&rng);
  48771. if (ret > 0)
  48772. return 0;
  48773. (void)eccClientCertBuf;
  48774. (void)eccClientCertBufSz;
  48775. (void)eccClientPrivKeyBuf;
  48776. (void)eccClientPrivKeyBufSz;
  48777. (void)rsaClientCertBuf;
  48778. (void)rsaClientCertBufSz;
  48779. (void)rsaClientPrivKeyBuf;
  48780. (void)rsaClientPrivKeyBufSz;
  48781. (void)rsaServerCertBuf;
  48782. (void)rsaServerCertBufSz;
  48783. (void)rsaServerPrivKeyBuf;
  48784. (void)rsaServerPrivKeyBufSz;
  48785. (void)rsaCaCertBuf;
  48786. (void)rsaCaCertBufSz;
  48787. (void)rsaCaPrivKeyBuf;
  48788. (void)rsaCaPrivKeyBufSz;
  48789. return ret;
  48790. }
  48791. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void)
  48792. {
  48793. wc_test_ret_t ret = 0;
  48794. byte* rsaClientCertBuf = NULL;
  48795. byte* rsaServerCertBuf = NULL;
  48796. byte* rsaCaCertBuf = NULL;
  48797. byte* eccClientCertBuf = NULL;
  48798. byte* rsaClientPrivKeyBuf = NULL;
  48799. byte* rsaServerPrivKeyBuf = NULL;
  48800. byte* rsaCaPrivKeyBuf = NULL;
  48801. byte* eccClientPrivKeyBuf = NULL;
  48802. word32 rsaClientCertBufSz = 0;
  48803. word32 rsaServerCertBufSz = 0;
  48804. word32 rsaCaCertBufSz = 0;
  48805. word32 eccClientCertBufSz = 0;
  48806. word32 rsaClientPrivKeyBufSz = 0;
  48807. word32 rsaServerPrivKeyBufSz = 0;
  48808. word32 rsaCaPrivKeyBufSz = 0;
  48809. word32 eccClientPrivKeyBufSz = 0;
  48810. WOLFSSL_ENTER("pkcs7signed_test");
  48811. #ifndef NO_RSA
  48812. /* read client RSA cert and key in DER format */
  48813. rsaClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48814. DYNAMIC_TYPE_TMP_BUFFER);
  48815. if (rsaClientCertBuf == NULL)
  48816. ret = WC_TEST_RET_ENC_NC;
  48817. rsaClientPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48818. DYNAMIC_TYPE_TMP_BUFFER);
  48819. if (ret == 0 && rsaClientPrivKeyBuf == NULL) {
  48820. ret = WC_TEST_RET_ENC_ERRNO;
  48821. }
  48822. rsaClientCertBufSz = FOURK_BUF;
  48823. rsaClientPrivKeyBufSz = FOURK_BUF;
  48824. /* read server RSA cert and key in DER format */
  48825. rsaServerCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48826. DYNAMIC_TYPE_TMP_BUFFER);
  48827. if (ret == 0 && rsaServerCertBuf == NULL)
  48828. ret = WC_TEST_RET_ENC_NC;
  48829. rsaServerPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48830. DYNAMIC_TYPE_TMP_BUFFER);
  48831. if (ret == 0 && rsaServerPrivKeyBuf == NULL) {
  48832. ret = WC_TEST_RET_ENC_ERRNO;
  48833. }
  48834. rsaServerCertBufSz = FOURK_BUF;
  48835. rsaServerPrivKeyBufSz = FOURK_BUF;
  48836. /* read CA RSA cert and key in DER format, for use with server cert */
  48837. rsaCaCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48838. DYNAMIC_TYPE_TMP_BUFFER);
  48839. if (ret == 0 && rsaCaCertBuf == NULL)
  48840. ret = WC_TEST_RET_ENC_NC;
  48841. rsaCaPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48842. DYNAMIC_TYPE_TMP_BUFFER);
  48843. if (ret == 0 && rsaCaPrivKeyBuf == NULL) {
  48844. ret = WC_TEST_RET_ENC_ERRNO;
  48845. }
  48846. rsaCaCertBufSz = FOURK_BUF;
  48847. rsaCaPrivKeyBufSz = FOURK_BUF;
  48848. #endif /* NO_RSA */
  48849. #ifdef HAVE_ECC
  48850. /* read client ECC cert and key in DER format */
  48851. eccClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48852. DYNAMIC_TYPE_TMP_BUFFER);
  48853. if (ret == 0 && eccClientCertBuf == NULL) {
  48854. ret = WC_TEST_RET_ENC_ERRNO;
  48855. }
  48856. eccClientPrivKeyBuf =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48857. DYNAMIC_TYPE_TMP_BUFFER);
  48858. if (ret == 0 && eccClientPrivKeyBuf == NULL) {
  48859. ret = WC_TEST_RET_ENC_ERRNO;
  48860. }
  48861. eccClientCertBufSz = FOURK_BUF;
  48862. eccClientPrivKeyBufSz = FOURK_BUF;
  48863. #endif /* HAVE_ECC */
  48864. if (ret >= 0)
  48865. ret = pkcs7_load_certs_keys(rsaClientCertBuf, &rsaClientCertBufSz,
  48866. rsaClientPrivKeyBuf, &rsaClientPrivKeyBufSz,
  48867. rsaServerCertBuf, &rsaServerCertBufSz,
  48868. rsaServerPrivKeyBuf, &rsaServerPrivKeyBufSz,
  48869. rsaCaCertBuf, &rsaCaCertBufSz,
  48870. rsaCaPrivKeyBuf, &rsaCaPrivKeyBufSz,
  48871. eccClientCertBuf, &eccClientCertBufSz,
  48872. eccClientPrivKeyBuf, &eccClientPrivKeyBufSz);
  48873. if (ret < 0) {
  48874. ret = WC_TEST_RET_ENC_EC(ret);
  48875. }
  48876. if (ret >= 0)
  48877. ret = pkcs7signed_run_vectors(rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48878. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48879. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48880. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48881. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48882. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48883. eccClientCertBuf, (word32)eccClientCertBufSz,
  48884. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48885. if (ret >= 0)
  48886. ret = pkcs7signed_run_SingleShotVectors(
  48887. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48888. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48889. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48890. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48891. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48892. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48893. eccClientCertBuf, (word32)eccClientCertBufSz,
  48894. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48895. #if !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  48896. if (ret >= 0)
  48897. ret = pkcs7callback_test(
  48898. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48899. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz);
  48900. #endif
  48901. XFREE(rsaClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48902. XFREE(rsaClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48903. XFREE(rsaServerCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48904. XFREE(rsaServerPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48905. XFREE(rsaCaCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48906. XFREE(rsaCaPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48907. XFREE(eccClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48908. XFREE(eccClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48909. return ret;
  48910. }
  48911. #endif /* HAVE_PKCS7 */
  48912. #if defined(WOLFSSL_PUBLIC_MP) && \
  48913. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48914. defined(USE_FAST_MATH))
  48915. /* Maximum number of bytes in a number to test. */
  48916. #define MP_MAX_TEST_BYTE_LEN 32
  48917. static wc_test_ret_t randNum(mp_int* n, int len, WC_RNG* rng, void* heap)
  48918. {
  48919. byte d[MP_MAX_TEST_BYTE_LEN];
  48920. wc_test_ret_t ret;
  48921. (void)heap;
  48922. do {
  48923. ret = wc_RNG_GenerateBlock(rng, d, (word32)len);
  48924. if (ret != 0)
  48925. return ret;
  48926. ret = mp_read_unsigned_bin(n, d, (word32)len);
  48927. if (ret != 0)
  48928. return ret;
  48929. } while (mp_iszero(n));
  48930. return 0;
  48931. }
  48932. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  48933. static wc_test_ret_t mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng)
  48934. {
  48935. int i, j;
  48936. mp_digit rem;
  48937. mp_digit rem2;
  48938. wc_test_ret_t ret;
  48939. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48940. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  48941. for (i = 0; i < 10; i++) {
  48942. for (j = 1; j < 10; j++) {
  48943. ret = randNum(a, j, rng, NULL);
  48944. if (ret != 0)
  48945. return WC_TEST_RET_ENC_EC(ret);
  48946. ret = mp_div_3(a, r, &rem);
  48947. if (ret != 0)
  48948. return WC_TEST_RET_ENC_EC(ret);
  48949. ret = mp_mul_d(r, 3, r);
  48950. if (ret != 0)
  48951. return WC_TEST_RET_ENC_EC(ret);
  48952. ret = mp_add_d(r, rem, r);
  48953. if (ret != 0)
  48954. return WC_TEST_RET_ENC_EC(ret);
  48955. ret = mp_cmp(r, a);
  48956. if (ret != MP_EQ)
  48957. return WC_TEST_RET_ENC_NC;
  48958. }
  48959. }
  48960. ret = mp_div_3(a, r, &rem);
  48961. if (ret != 0)
  48962. return WC_TEST_RET_ENC_NC;
  48963. ret = mp_div_3(a, a, NULL);
  48964. if (ret != 0)
  48965. return WC_TEST_RET_ENC_NC;
  48966. ret = mp_cmp(r, a);
  48967. if (ret != MP_EQ)
  48968. return WC_TEST_RET_ENC_NC;
  48969. #endif
  48970. #if defined(WOLFSSL_SP_MATH_ALL)
  48971. ret = mp_div_d(a, 10, r, &rem);
  48972. if (ret != 0)
  48973. return WC_TEST_RET_ENC_EC(ret);
  48974. ret = mp_div_d(a, 10, 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. ret = mp_div_d(a, 12, r, &rem);
  48981. if (ret != 0)
  48982. return WC_TEST_RET_ENC_EC(ret);
  48983. ret = mp_div_d(a, 12, a, NULL);
  48984. if (ret != 0)
  48985. return WC_TEST_RET_ENC_EC(ret);
  48986. ret = mp_cmp(r, a);
  48987. if (ret != MP_EQ)
  48988. return WC_TEST_RET_ENC_NC;
  48989. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem);
  48990. if (ret != 0)
  48991. return WC_TEST_RET_ENC_EC(ret);
  48992. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2);
  48993. if (ret != 0)
  48994. return WC_TEST_RET_ENC_EC(ret);
  48995. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL);
  48996. if (ret != 0)
  48997. return WC_TEST_RET_ENC_EC(ret);
  48998. ret = mp_cmp(r, a);
  48999. if (ret != MP_EQ)
  49000. return WC_TEST_RET_ENC_NC;
  49001. if (rem != rem2)
  49002. return WC_TEST_RET_ENC_NC;
  49003. #endif
  49004. (void)a;
  49005. (void)r;
  49006. (void)rng;
  49007. (void)i;
  49008. (void)j;
  49009. (void)rem;
  49010. (void)rem2;
  49011. (void)ret;
  49012. return 0;
  49013. }
  49014. #endif /* WOLFSSL_SP_MATH || !USE_FAST_MATH */
  49015. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  49016. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49017. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  49018. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  49019. static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
  49020. {
  49021. wc_test_ret_t ret;
  49022. int i, j;
  49023. int size;
  49024. char str[30];
  49025. WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = "A";
  49026. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "a";
  49027. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  49028. WOLFSSL_SMALL_STACK_STATIC const char* zeros = "000";
  49029. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  49030. for (i = 0; i < 10; i++) {
  49031. for (j = 2; j < 12; j++) {
  49032. ret = randNum(a, j, rng, NULL);
  49033. if (ret != 0)
  49034. return WC_TEST_RET_ENC_EC(ret);
  49035. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  49036. if (ret != MP_OKAY)
  49037. return WC_TEST_RET_ENC_EC(ret);
  49038. ret = mp_toradix(a, str, MP_RADIX_DEC);
  49039. if (ret != MP_OKAY)
  49040. return WC_TEST_RET_ENC_EC(ret);
  49041. if ((int)XSTRLEN(str) != size - 1)
  49042. return WC_TEST_RET_ENC_NC;
  49043. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  49044. if (ret != MP_OKAY)
  49045. return WC_TEST_RET_ENC_EC(ret);
  49046. ret = mp_cmp(a, r);
  49047. if (ret != MP_EQ)
  49048. return WC_TEST_RET_ENC_NC;
  49049. }
  49050. }
  49051. ret = mp_read_radix(r, badStr1, MP_RADIX_DEC);
  49052. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49053. return WC_TEST_RET_ENC_EC(ret);
  49054. ret = mp_read_radix(r, badStr2, MP_RADIX_DEC);
  49055. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49056. return WC_TEST_RET_ENC_EC(ret);
  49057. ret = mp_read_radix(r, empty2, MP_RADIX_DEC);
  49058. if (ret != MP_OKAY)
  49059. return WC_TEST_RET_ENC_EC(ret);
  49060. ret = mp_read_radix(r, zeros, MP_RADIX_DEC);
  49061. if (ret != MP_OKAY)
  49062. return WC_TEST_RET_ENC_EC(ret);
  49063. if (!mp_iszero(r))
  49064. return WC_TEST_RET_ENC_NC;
  49065. mp_set(r, 1);
  49066. ret = mp_read_radix(r, empty, MP_RADIX_DEC);
  49067. if (ret != MP_OKAY)
  49068. return WC_TEST_RET_ENC_EC(ret);
  49069. if (!mp_iszero(r))
  49070. return WC_TEST_RET_ENC_NC;
  49071. mp_zero(a);
  49072. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  49073. if (ret != 0)
  49074. return WC_TEST_RET_ENC_EC(ret);
  49075. if (size != 2)
  49076. return WC_TEST_RET_ENC_NC;
  49077. ret = mp_toradix(a, str, MP_RADIX_DEC);
  49078. if (ret != 0)
  49079. return WC_TEST_RET_ENC_EC(ret);
  49080. if ((int)XSTRLEN(str) != size - 1)
  49081. return WC_TEST_RET_ENC_NC;
  49082. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  49083. if (ret != 0)
  49084. return WC_TEST_RET_ENC_EC(ret);
  49085. if (!mp_iszero(r))
  49086. return WC_TEST_RET_ENC_NC;
  49087. return 0;
  49088. }
  49089. #endif
  49090. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  49091. defined(HAVE_ECC))
  49092. static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
  49093. {
  49094. wc_test_ret_t ret;
  49095. int i, j;
  49096. int size;
  49097. char str[30];
  49098. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  49099. static char longStr[2 * sizeof(a->dp) + 2];
  49100. #endif
  49101. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  49102. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "}";
  49103. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  49104. for (i = 0; i < 10; i++) {
  49105. for (j = 2; j < 12; j++) {
  49106. ret = randNum(a, j, rng, NULL);
  49107. if (ret != 0)
  49108. return WC_TEST_RET_ENC_EC(ret);
  49109. mp_radix_size(a, MP_RADIX_HEX, &size);
  49110. mp_toradix(a, str, MP_RADIX_HEX);
  49111. if ((int)XSTRLEN(str) != size - 1)
  49112. return WC_TEST_RET_ENC_NC;
  49113. mp_read_radix(r, str, MP_RADIX_HEX);
  49114. ret = mp_cmp(a, r);
  49115. if (ret != MP_EQ)
  49116. return WC_TEST_RET_ENC_NC;
  49117. }
  49118. }
  49119. ret = mp_read_radix(r, empty2, MP_RADIX_HEX);
  49120. if (ret != MP_OKAY)
  49121. return WC_TEST_RET_ENC_EC(ret);
  49122. ret = mp_read_radix(r, badStr2, MP_RADIX_HEX);
  49123. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49124. return WC_TEST_RET_ENC_EC(ret);
  49125. mp_set(r, 1);
  49126. ret = mp_read_radix(r, empty, MP_RADIX_HEX);
  49127. if (ret != MP_OKAY)
  49128. return WC_TEST_RET_ENC_EC(ret);
  49129. if (!mp_iszero(r))
  49130. return WC_TEST_RET_ENC_NC;
  49131. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  49132. /* Fixed MP data size - string can be too long. */
  49133. longStr[0] = '8';
  49134. XMEMSET(longStr+1, '0', sizeof(longStr) - 2);
  49135. longStr[sizeof(longStr)-1] = '\0';
  49136. ret = mp_read_radix(r, longStr, MP_RADIX_HEX);
  49137. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49138. return WC_TEST_RET_ENC_EC(ret);
  49139. #endif
  49140. mp_zero(a);
  49141. ret = mp_radix_size(a, MP_RADIX_HEX, &size);
  49142. if (ret != 0)
  49143. return WC_TEST_RET_ENC_EC(ret);
  49144. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  49145. if (size != 3)
  49146. #else
  49147. if (size != 2)
  49148. #endif
  49149. return WC_TEST_RET_ENC_NC;
  49150. ret = mp_toradix(a, str, MP_RADIX_HEX);
  49151. if (ret != 0)
  49152. return WC_TEST_RET_ENC_EC(ret);
  49153. if ((int)XSTRLEN(str) != size - 1)
  49154. return WC_TEST_RET_ENC_NC;
  49155. ret = mp_read_radix(r, str, MP_RADIX_HEX);
  49156. if (ret != 0)
  49157. return WC_TEST_RET_ENC_EC(ret);
  49158. if (!mp_iszero(r))
  49159. return WC_TEST_RET_ENC_NC;
  49160. #ifdef WOLFSSL_SP_MATH
  49161. ret = mp_toradix(a, str, 8);
  49162. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49163. return WC_TEST_RET_ENC_EC(ret);
  49164. ret = mp_radix_size(a, 8, &size);
  49165. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49166. return WC_TEST_RET_ENC_EC(ret);
  49167. #endif
  49168. return 0;
  49169. }
  49170. #endif
  49171. static wc_test_ret_t mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng)
  49172. {
  49173. int i;
  49174. wc_test_ret_t ret;
  49175. ret = randNum(a, 4, rng, NULL);
  49176. if (ret != 0)
  49177. return WC_TEST_RET_ENC_EC(ret);
  49178. for (i = 0; i < 4; i++) {
  49179. mp_copy(r1, a);
  49180. #if !defined(NO_DH) || defined(HAVE_ECC) || (!defined(NO_RSA) && \
  49181. defined(WC_RSA_BLINDING) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49182. ret = mp_lshd(r1, i);
  49183. if (ret != MP_OKAY)
  49184. return WC_TEST_RET_ENC_EC(ret);
  49185. #ifndef WOLFSSL_SP_MATH
  49186. mp_rshd(r1, i);
  49187. #else
  49188. mp_rshb(r1, i * SP_WORD_SIZE);
  49189. #endif
  49190. ret = mp_cmp(a, r1);
  49191. if (ret != MP_EQ)
  49192. return WC_TEST_RET_ENC_NC;
  49193. #endif
  49194. }
  49195. #ifndef WOLFSSL_SP_MATH
  49196. for (i = 0; i < DIGIT_BIT+1; i++) {
  49197. ret = mp_mul_2d(a, i, r1);
  49198. if (ret != MP_OKAY)
  49199. return WC_TEST_RET_ENC_EC(ret);
  49200. mp_rshb(r1, i);
  49201. ret = mp_cmp(a, r1);
  49202. if (ret != MP_EQ)
  49203. return WC_TEST_RET_ENC_NC;
  49204. }
  49205. #endif
  49206. return 0;
  49207. }
  49208. static wc_test_ret_t mp_test_add_sub_d(mp_int* a, mp_int* r1)
  49209. {
  49210. int i, j;
  49211. wc_test_ret_t ret;
  49212. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49213. mp_zero(a);
  49214. mp_set_bit(a, i);
  49215. if ((int)a->used != (i + DIGIT_BIT) / DIGIT_BIT)
  49216. return WC_TEST_RET_ENC_NC;
  49217. for (j = 0; j < i && j < DIGIT_BIT; j++) {
  49218. mp_zero(r1);
  49219. mp_set_bit(r1, i);
  49220. ret = mp_sub_d(r1, (mp_digit)1 << j, r1);
  49221. if (ret != MP_OKAY)
  49222. return WC_TEST_RET_ENC_EC(ret);
  49223. ret = mp_add_d(r1, (mp_digit)1 << j, r1);
  49224. if (ret != MP_OKAY)
  49225. return WC_TEST_RET_ENC_EC(ret);
  49226. ret = mp_cmp(a, r1);
  49227. if (ret != MP_EQ)
  49228. return WC_TEST_RET_ENC_NC;
  49229. }
  49230. }
  49231. mp_zero(r1);
  49232. ret = mp_add_d(r1, 1, r1);
  49233. if (ret != MP_OKAY)
  49234. return WC_TEST_RET_ENC_EC(ret);
  49235. if (r1->used != 1)
  49236. return WC_TEST_RET_ENC_NC;
  49237. ret = mp_sub_d(r1, 1, r1);
  49238. if (ret != MP_OKAY)
  49239. return WC_TEST_RET_ENC_EC(ret);
  49240. if (r1->used != 0)
  49241. return WC_TEST_RET_ENC_NC;
  49242. return 0;
  49243. }
  49244. static wc_test_ret_t mp_test_read_to_bin(mp_int* a)
  49245. {
  49246. WOLFSSL_SMALL_STACK_STATIC const byte in[16] = {
  49247. 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7, 0x08,
  49248. 0x93, 0xa4, 0xb4, 0xc5, 0xd6, 0xe7, 0xf8, 0x09
  49249. };
  49250. byte out[24];
  49251. int i, j, k;
  49252. const byte* p;
  49253. wc_test_ret_t ret;
  49254. for (i = 0; i < (int)sizeof(in); i++) {
  49255. p = in + sizeof(in) - i;
  49256. ret = mp_read_unsigned_bin(a, p, (word32)i);
  49257. if (ret != 0)
  49258. return WC_TEST_RET_ENC_EC(ret);
  49259. for (j = i; j < (int)sizeof(out); j++) {
  49260. XMEMSET(out, 0xff, sizeof(out));
  49261. ret = mp_to_unsigned_bin_len(a, out, j);
  49262. if (ret != 0)
  49263. return WC_TEST_RET_ENC_EC(ret);
  49264. for (k = 0; k < j - i; k++) {
  49265. if (out[k] != 0)
  49266. return WC_TEST_RET_ENC_NC;
  49267. }
  49268. for (; k < j; k++) {
  49269. if (out[k] != p[k - (j - i)])
  49270. return WC_TEST_RET_ENC_NC;
  49271. }
  49272. }
  49273. }
  49274. /* Length too small. */
  49275. ret = mp_to_unsigned_bin_len(a, out, 1);
  49276. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49277. return WC_TEST_RET_ENC_EC(ret);
  49278. ret = mp_read_unsigned_bin(a, NULL, 0);
  49279. if (ret != 0)
  49280. return WC_TEST_RET_ENC_EC(ret);
  49281. if (!mp_iszero(a))
  49282. return WC_TEST_RET_ENC_NC;
  49283. return 0;
  49284. }
  49285. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49286. static wc_test_ret_t mp_test_set_int(mp_int* a)
  49287. {
  49288. #if SP_ULONG_BITS == 64
  49289. unsigned long n = 0xfedcba9876543210UL;
  49290. byte exp[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
  49291. byte out[8] = { 0 };
  49292. #elif SP_ULONG_BITS == 32
  49293. unsigned long n = 0xfedcba98UL;
  49294. byte exp[4] = { 0xfe, 0xdc, 0xba, 0x98 };
  49295. byte out[4] = { 0 };
  49296. #elif SP_ULONG_BITS == 16
  49297. unsigned long n = 0xfedc;
  49298. byte exp[2] = { 0xfe, 0xdc };
  49299. byte out[2] = { 0 };
  49300. #elif SP_ULONG_BITS == 8
  49301. unsigned long n = 0xfe;
  49302. byte exp[1] = { 0xfe };
  49303. byte out[1] = { 0 };
  49304. #endif
  49305. wc_test_ret_t ret;
  49306. ret = mp_set_int(a, n);
  49307. if (ret != 0)
  49308. return WC_TEST_RET_ENC_EC(ret);
  49309. ret = mp_unsigned_bin_size(a);
  49310. if (ret != sizeof(exp))
  49311. return WC_TEST_RET_ENC_NC;
  49312. ret = mp_to_unsigned_bin(a, out);
  49313. if (ret != 0)
  49314. return WC_TEST_RET_ENC_EC(ret);
  49315. if (XMEMCMP(exp, out, sizeof(exp)) != 0)
  49316. return WC_TEST_RET_ENC_NC;
  49317. return 0;
  49318. }
  49319. #endif
  49320. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49321. static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
  49322. {
  49323. byte buffer[16];
  49324. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49325. char hexStr[] = "abcdef0123456789";
  49326. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49327. char negStr[] = "-1234";
  49328. #endif
  49329. #endif
  49330. #if !defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
  49331. defined(HAVE_COMP_KEY)
  49332. char decStr[] = "0987654321";
  49333. #endif
  49334. wc_test_ret_t ret;
  49335. #ifdef WOLFSSL_SP_MATH_ALL
  49336. mp_digit rho;
  49337. int size;
  49338. #endif
  49339. #ifdef WOLFSSL_SP_PRIME_GEN
  49340. int result;
  49341. #endif
  49342. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49343. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49344. mp_digit rd;
  49345. #endif
  49346. (void)rng;
  49347. (void)r;
  49348. ret = mp_init(NULL);
  49349. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49350. return WC_TEST_RET_ENC_EC(ret);
  49351. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49352. ret = mp_init_multi(NULL, NULL, NULL, NULL, NULL, NULL);
  49353. if (ret != MP_OKAY)
  49354. return WC_TEST_RET_ENC_EC(ret);
  49355. #endif
  49356. mp_free(NULL);
  49357. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
  49358. ret = mp_grow(NULL, 1);
  49359. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49360. return WC_TEST_RET_ENC_EC(ret);
  49361. #ifdef WOLFSSL_SP_MATH
  49362. ret = mp_grow(a, SP_INT_DIGITS + 1);
  49363. if (ret != WC_NO_ERR_TRACE(MP_MEM))
  49364. return WC_TEST_RET_ENC_EC(ret);
  49365. #endif
  49366. #endif
  49367. mp_clear(NULL);
  49368. ret = mp_abs(NULL, NULL);
  49369. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49370. return WC_TEST_RET_ENC_EC(ret);
  49371. ret = mp_abs(a, NULL);
  49372. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49373. return WC_TEST_RET_ENC_EC(ret);
  49374. ret = mp_abs(NULL, b);
  49375. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49376. return WC_TEST_RET_ENC_EC(ret);
  49377. ret = mp_unsigned_bin_size(NULL);
  49378. if (ret != 0)
  49379. return WC_TEST_RET_ENC_EC(ret);
  49380. /* clear buffer to avoid provoking uninitvar errors. */
  49381. XMEMSET(buffer, 0, sizeof(buffer));
  49382. ret = mp_read_unsigned_bin(NULL, NULL, sizeof(buffer));
  49383. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49384. return WC_TEST_RET_ENC_EC(ret);
  49385. ret = mp_read_unsigned_bin(NULL, buffer, sizeof(buffer));
  49386. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49387. return WC_TEST_RET_ENC_EC(ret);
  49388. ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer));
  49389. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49390. return WC_TEST_RET_ENC_EC(ret);
  49391. ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
  49392. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49393. return WC_TEST_RET_ENC_EC(ret);
  49394. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49395. ret = mp_read_radix(NULL, NULL, 16);
  49396. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49397. return WC_TEST_RET_ENC_EC(ret);
  49398. ret = mp_read_radix(a, NULL, 16);
  49399. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49400. return WC_TEST_RET_ENC_EC(ret);
  49401. ret = mp_read_radix(NULL, hexStr, 16);
  49402. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49403. return WC_TEST_RET_ENC_EC(ret);
  49404. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49405. ret = mp_read_radix(a, negStr, 16);
  49406. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49407. return WC_TEST_RET_ENC_EC(ret);
  49408. #ifdef WOLFSSL_SP_MATH_ALL
  49409. ret = mp_read_radix(a, negStr, 10);
  49410. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49411. return WC_TEST_RET_ENC_EC(ret);
  49412. #endif /* WOLFSSL_SP_MATH_ALL */
  49413. #endif /* WOLFSSL_SP_INT_NEGATIVE */
  49414. #endif
  49415. #ifndef WOLFSSL_SP_MATH_ALL
  49416. /* Radix 10 only supported with ALL. */
  49417. ret = mp_read_radix(a, decStr, 10);
  49418. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49419. return WC_TEST_RET_ENC_EC(ret);
  49420. #endif
  49421. /* Radix 8 not supported SP_INT. */
  49422. ret = mp_read_radix(a, "0123", 8);
  49423. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49424. return WC_TEST_RET_ENC_EC(ret);
  49425. ret = mp_count_bits(NULL);
  49426. if (ret != 0)
  49427. return WC_TEST_RET_ENC_EC(ret);
  49428. ret = mp_is_bit_set(NULL, 0);
  49429. if (ret != 0)
  49430. return WC_TEST_RET_ENC_EC(ret);
  49431. ret = mp_leading_bit(NULL);
  49432. if (ret != 0)
  49433. return WC_TEST_RET_ENC_EC(ret);
  49434. mp_zero(a);
  49435. ret = mp_leading_bit(a);
  49436. if (ret != 0)
  49437. return WC_TEST_RET_ENC_EC(ret);
  49438. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49439. defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || \
  49440. !defined(NO_RSA)
  49441. ret = mp_set_bit(NULL, 1);
  49442. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49443. return WC_TEST_RET_ENC_EC(ret);
  49444. #endif
  49445. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49446. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49447. ret = mp_to_unsigned_bin(NULL, NULL);
  49448. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49449. return WC_TEST_RET_ENC_EC(ret);
  49450. ret = mp_to_unsigned_bin(a, NULL);
  49451. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49452. return WC_TEST_RET_ENC_EC(ret);
  49453. ret = mp_to_unsigned_bin(NULL, buffer);
  49454. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49455. return WC_TEST_RET_ENC_EC(ret);
  49456. #endif
  49457. ret = mp_to_unsigned_bin_len(NULL, NULL, 1);
  49458. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49459. return WC_TEST_RET_ENC_EC(ret);
  49460. ret = mp_to_unsigned_bin_len(a, NULL, 1);
  49461. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49462. return WC_TEST_RET_ENC_EC(ret);
  49463. ret = mp_to_unsigned_bin_len(NULL, buffer, 1);
  49464. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49465. return WC_TEST_RET_ENC_EC(ret);
  49466. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  49467. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49468. ret = mp_to_unsigned_bin_at_pos(0, NULL, NULL);
  49469. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49470. return WC_TEST_RET_ENC_EC(ret);
  49471. ret = mp_to_unsigned_bin_at_pos(0, a, NULL);
  49472. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49473. return WC_TEST_RET_ENC_EC(ret);
  49474. ret = mp_to_unsigned_bin_at_pos(0, NULL, buffer);
  49475. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49476. return WC_TEST_RET_ENC_EC(ret);
  49477. ret = mp_to_unsigned_bin_at_pos(0, a, buffer);
  49478. if (ret != MP_OKAY)
  49479. return WC_TEST_RET_ENC_EC(ret);
  49480. #endif
  49481. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49482. ret = mp_copy(NULL, NULL);
  49483. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49484. return WC_TEST_RET_ENC_EC(ret);
  49485. ret = mp_copy(a, NULL);
  49486. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49487. return WC_TEST_RET_ENC_EC(ret);
  49488. ret = mp_copy(NULL, b);
  49489. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49490. return WC_TEST_RET_ENC_EC(ret);
  49491. #endif
  49492. #if defined(WOLFSSL_KEY_GEN) || !defined(NO_DH)
  49493. ret = sp_2expt(NULL, 1);
  49494. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49495. return WC_TEST_RET_ENC_EC(ret);
  49496. #endif
  49497. ret = mp_set(NULL, 0);
  49498. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49499. return WC_TEST_RET_ENC_EC(ret);
  49500. ret = mp_cmp_d(NULL, 0);
  49501. if (ret != MP_LT)
  49502. return WC_TEST_RET_ENC_EC(ret);
  49503. ret = mp_cmp(NULL, NULL);
  49504. if (ret != MP_EQ)
  49505. return WC_TEST_RET_ENC_NC;
  49506. ret = mp_cmp(a, NULL);
  49507. if (ret != MP_GT)
  49508. return WC_TEST_RET_ENC_NC;
  49509. ret = mp_cmp(NULL, b);
  49510. if (ret != MP_LT)
  49511. return WC_TEST_RET_ENC_NC;
  49512. #ifdef WOLFSSL_SP_MATH_ALL
  49513. mp_rshd(NULL, 1);
  49514. #endif
  49515. mp_zero(NULL);
  49516. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49517. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  49518. ret = mp_lshd(NULL, 0);
  49519. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49520. return WC_TEST_RET_ENC_EC(ret);
  49521. ret = mp_lshd(a, SP_INT_DIGITS + 1);
  49522. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49523. return WC_TEST_RET_ENC_EC(ret);
  49524. #endif
  49525. #if defined(WOLFSSL_SP_MATH_ALL)
  49526. ret = mp_div(NULL, NULL, a, b);
  49527. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49528. return WC_TEST_RET_ENC_EC(ret);
  49529. ret = mp_div(a, NULL, a, b);
  49530. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49531. return WC_TEST_RET_ENC_EC(ret);
  49532. ret = mp_div(NULL, b, a, b);
  49533. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49534. return WC_TEST_RET_ENC_EC(ret);
  49535. ret = mp_div(a, b, NULL, NULL);
  49536. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49537. return WC_TEST_RET_ENC_EC(ret);
  49538. #endif
  49539. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49540. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49541. ret = mp_mod(NULL, NULL, NULL);
  49542. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49543. return WC_TEST_RET_ENC_EC(ret);
  49544. ret = mp_mod(a, NULL, NULL);
  49545. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49546. return WC_TEST_RET_ENC_EC(ret);
  49547. ret = mp_mod(NULL, b, NULL);
  49548. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49549. return WC_TEST_RET_ENC_EC(ret);
  49550. ret = mp_mod(NULL, NULL, r);
  49551. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49552. return WC_TEST_RET_ENC_EC(ret);
  49553. ret = mp_mod(a, b, NULL);
  49554. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49555. return WC_TEST_RET_ENC_EC(ret);
  49556. ret = mp_mod(a, NULL, r);
  49557. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49558. return WC_TEST_RET_ENC_EC(ret);
  49559. ret = mp_mod(NULL, b, r);
  49560. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49561. return WC_TEST_RET_ENC_EC(ret);
  49562. #endif
  49563. #if !defined(NO_RSA) || defined(WOLFSSL_SP_MATH_ALL)
  49564. ret = mp_set_int(NULL, 0);
  49565. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49566. return WC_TEST_RET_ENC_EC(ret);
  49567. #endif
  49568. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  49569. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  49570. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49571. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49572. return WC_TEST_RET_ENC_EC(ret);
  49573. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49574. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49575. return WC_TEST_RET_ENC_EC(ret);
  49576. ret = mp_exptmod_ex(NULL, a, 1, NULL, NULL);
  49577. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49578. return WC_TEST_RET_ENC_EC(ret);
  49579. ret = mp_exptmod_ex(NULL, NULL, 1, a, NULL);
  49580. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49581. return WC_TEST_RET_ENC_EC(ret);
  49582. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49583. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49584. return WC_TEST_RET_ENC_EC(ret);
  49585. ret = mp_exptmod_ex(a, a, 1, a, NULL);
  49586. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49587. return WC_TEST_RET_ENC_EC(ret);
  49588. ret = mp_exptmod_ex(a, a, 1, NULL, a);
  49589. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49590. return WC_TEST_RET_ENC_EC(ret);
  49591. ret = mp_exptmod_ex(a, NULL, 1, a, a);
  49592. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49593. return WC_TEST_RET_ENC_EC(ret);
  49594. ret = mp_exptmod_ex(NULL, a, 1, 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, NULL, NULL, NULL);
  49598. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49599. return WC_TEST_RET_ENC_EC(ret);
  49600. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49601. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49602. return WC_TEST_RET_ENC_EC(ret);
  49603. ret = mp_exptmod_nct(NULL, a, NULL, NULL);
  49604. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49605. return WC_TEST_RET_ENC_EC(ret);
  49606. ret = mp_exptmod_nct(NULL, NULL, a, NULL);
  49607. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49608. return WC_TEST_RET_ENC_EC(ret);
  49609. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49610. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49611. return WC_TEST_RET_ENC_EC(ret);
  49612. ret = mp_exptmod_nct(a, a, a, NULL);
  49613. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49614. return WC_TEST_RET_ENC_EC(ret);
  49615. ret = mp_exptmod_nct(a, a, NULL, a);
  49616. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49617. return WC_TEST_RET_ENC_EC(ret);
  49618. ret = mp_exptmod_nct(a, NULL, a, a);
  49619. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49620. return WC_TEST_RET_ENC_EC(ret);
  49621. ret = mp_exptmod_nct(NULL, a, a, a);
  49622. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49623. return WC_TEST_RET_ENC_EC(ret);
  49624. #endif
  49625. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  49626. !defined(WC_NO_RNG)
  49627. ret = mp_rand_prime(NULL, 32, NULL, NULL);
  49628. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49629. return WC_TEST_RET_ENC_EC(ret);
  49630. ret = mp_rand_prime(a, 32, NULL, NULL);
  49631. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49632. return WC_TEST_RET_ENC_EC(ret);
  49633. ret = mp_rand_prime(NULL, 32, rng, NULL);
  49634. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49635. return WC_TEST_RET_ENC_EC(ret);
  49636. ret = mp_rand_prime(a, 0, rng, NULL);
  49637. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49638. return WC_TEST_RET_ENC_EC(ret);
  49639. #endif
  49640. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49641. ret = mp_mul(NULL, NULL, NULL);
  49642. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49643. return WC_TEST_RET_ENC_EC(ret);
  49644. ret = mp_mul(a, NULL, NULL);
  49645. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49646. return WC_TEST_RET_ENC_EC(ret);
  49647. ret = mp_mul(NULL, b, NULL);
  49648. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49649. return WC_TEST_RET_ENC_EC(ret);
  49650. ret = mp_mul(NULL, NULL, r);
  49651. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49652. return WC_TEST_RET_ENC_EC(ret);
  49653. ret = mp_mul(a, b, NULL);
  49654. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49655. return WC_TEST_RET_ENC_EC(ret);
  49656. ret = mp_mul(a, NULL, r);
  49657. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49658. return WC_TEST_RET_ENC_EC(ret);
  49659. ret = mp_mul(NULL, b, r);
  49660. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49661. return WC_TEST_RET_ENC_EC(ret);
  49662. #endif
  49663. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49664. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49665. ret = mp_sqr(NULL, NULL);
  49666. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49667. return WC_TEST_RET_ENC_EC(ret);
  49668. ret = mp_sqr(a, NULL);
  49669. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49670. return WC_TEST_RET_ENC_EC(ret);
  49671. ret = mp_sqr(NULL, r);
  49672. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49673. return WC_TEST_RET_ENC_EC(ret);
  49674. #endif
  49675. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49676. ret = mp_sqrmod(NULL, NULL, NULL);
  49677. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49678. return WC_TEST_RET_ENC_EC(ret);
  49679. ret = mp_sqrmod(a, NULL, NULL);
  49680. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49681. return WC_TEST_RET_ENC_EC(ret);
  49682. ret = mp_sqrmod(NULL, a, NULL);
  49683. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49684. return WC_TEST_RET_ENC_EC(ret);
  49685. ret = mp_sqrmod(NULL, NULL, a);
  49686. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49687. return WC_TEST_RET_ENC_EC(ret);
  49688. ret = mp_sqrmod(a, b, NULL);
  49689. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49690. return WC_TEST_RET_ENC_EC(ret);
  49691. ret = mp_sqrmod(a, NULL, b);
  49692. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49693. return WC_TEST_RET_ENC_EC(ret);
  49694. ret = mp_sqrmod(NULL, a, b);
  49695. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49696. return WC_TEST_RET_ENC_EC(ret);
  49697. ret = mp_mulmod(NULL, NULL, NULL, NULL);
  49698. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49699. return WC_TEST_RET_ENC_EC(ret);
  49700. ret = mp_mulmod(a, NULL, NULL, NULL);
  49701. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49702. return WC_TEST_RET_ENC_EC(ret);
  49703. ret = mp_mulmod(NULL, a, NULL, NULL);
  49704. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49705. return WC_TEST_RET_ENC_EC(ret);
  49706. ret = mp_mulmod(NULL, NULL, a, NULL);
  49707. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49708. return WC_TEST_RET_ENC_EC(ret);
  49709. ret = mp_mulmod(NULL, NULL, NULL, a);
  49710. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49711. return WC_TEST_RET_ENC_EC(ret);
  49712. ret = mp_mulmod(a, b, b, NULL);
  49713. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49714. return WC_TEST_RET_ENC_EC(ret);
  49715. ret = mp_mulmod(a, b, NULL, a);
  49716. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49717. return WC_TEST_RET_ENC_EC(ret);
  49718. ret = mp_mulmod(a, NULL, b, a);
  49719. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49720. return WC_TEST_RET_ENC_EC(ret);
  49721. ret = mp_mulmod(NULL, b, b, a);
  49722. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49723. return WC_TEST_RET_ENC_EC(ret);
  49724. #endif
  49725. #if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \
  49726. !defined(NO_RSA) || !defined(NO_DSA)
  49727. ret = mp_add_d(NULL, 1, NULL);
  49728. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49729. return WC_TEST_RET_ENC_EC(ret);
  49730. ret = mp_add_d(a, 1, NULL);
  49731. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49732. return WC_TEST_RET_ENC_EC(ret);
  49733. ret = mp_add_d(NULL, 1, b);
  49734. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49735. return WC_TEST_RET_ENC_EC(ret);
  49736. #endif
  49737. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49738. !defined(NO_DH) || defined(HAVE_ECC) || !defined(NO_DSA)
  49739. ret = mp_sub_d(NULL, 1, NULL);
  49740. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49741. return WC_TEST_RET_ENC_EC(ret);
  49742. ret = mp_sub_d(a, 1, NULL);
  49743. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49744. return WC_TEST_RET_ENC_EC(ret);
  49745. ret = mp_sub_d(NULL, 1, b);
  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(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49750. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49751. ret = mp_div_d(NULL, 0, NULL, NULL);
  49752. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49753. return WC_TEST_RET_ENC_EC(ret);
  49754. ret = mp_div_d(a, 0, NULL, NULL);
  49755. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49756. return WC_TEST_RET_ENC_EC(ret);
  49757. ret = mp_div_d(NULL, 1, NULL, NULL);
  49758. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49759. return WC_TEST_RET_ENC_EC(ret);
  49760. #endif
  49761. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49762. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49763. ret = mp_mod_d(NULL, 0, NULL);
  49764. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49765. return WC_TEST_RET_ENC_EC(ret);
  49766. ret = mp_mod_d(a, 0, NULL);
  49767. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49768. return WC_TEST_RET_ENC_EC(ret);
  49769. ret = mp_mod_d(NULL, 0, &rd);
  49770. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49771. return WC_TEST_RET_ENC_EC(ret);
  49772. #endif
  49773. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  49774. ret = mp_gcd(NULL, NULL, NULL);
  49775. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49776. return WC_TEST_RET_ENC_EC(ret);
  49777. ret = mp_gcd(a, NULL, NULL);
  49778. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49779. return WC_TEST_RET_ENC_EC(ret);
  49780. ret = mp_gcd(NULL, a, NULL);
  49781. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49782. return WC_TEST_RET_ENC_EC(ret);
  49783. ret = mp_gcd(NULL, NULL, a);
  49784. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49785. return WC_TEST_RET_ENC_EC(ret);
  49786. ret = mp_gcd(a, b, NULL);
  49787. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49788. return WC_TEST_RET_ENC_EC(ret);
  49789. ret = mp_gcd(a, NULL, b);
  49790. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49791. return WC_TEST_RET_ENC_EC(ret);
  49792. ret = mp_gcd(NULL, a, b);
  49793. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49794. return WC_TEST_RET_ENC_EC(ret);
  49795. #endif
  49796. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49797. ret = mp_div_2_mod_ct(NULL, NULL, NULL);
  49798. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49799. return WC_TEST_RET_ENC_EC(ret);
  49800. ret = mp_div_2_mod_ct(a, NULL, NULL);
  49801. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49802. return WC_TEST_RET_ENC_EC(ret);
  49803. ret = mp_div_2_mod_ct(NULL, b, NULL);
  49804. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49805. return WC_TEST_RET_ENC_EC(ret);
  49806. ret = mp_div_2_mod_ct(NULL, NULL, a);
  49807. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49808. return WC_TEST_RET_ENC_EC(ret);
  49809. ret = mp_div_2_mod_ct(a, b, NULL);
  49810. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49811. return WC_TEST_RET_ENC_EC(ret);
  49812. ret = mp_div_2_mod_ct(a, b, NULL);
  49813. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49814. return WC_TEST_RET_ENC_EC(ret);
  49815. ret = mp_div_2_mod_ct(NULL, b, a);
  49816. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49817. return WC_TEST_RET_ENC_EC(ret);
  49818. ret = mp_div_2(NULL, NULL);
  49819. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49820. return WC_TEST_RET_ENC_EC(ret);
  49821. ret = mp_div_2(a, NULL);
  49822. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49823. return WC_TEST_RET_ENC_EC(ret);
  49824. ret = mp_div_2(NULL, a);
  49825. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49826. return WC_TEST_RET_ENC_EC(ret);
  49827. #endif
  49828. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  49829. !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  49830. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  49831. ret = mp_invmod(NULL, NULL, NULL);
  49832. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49833. return WC_TEST_RET_ENC_EC(ret);
  49834. ret = mp_invmod(a, NULL, NULL);
  49835. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49836. return WC_TEST_RET_ENC_EC(ret);
  49837. ret = mp_invmod(NULL, b, NULL);
  49838. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49839. return WC_TEST_RET_ENC_EC(ret);
  49840. ret = mp_invmod(NULL, NULL, a);
  49841. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49842. return WC_TEST_RET_ENC_EC(ret);
  49843. ret = mp_invmod(a, b, NULL);
  49844. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49845. return WC_TEST_RET_ENC_EC(ret);
  49846. ret = mp_invmod(a, NULL, a);
  49847. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49848. return WC_TEST_RET_ENC_EC(ret);
  49849. ret = mp_invmod(NULL, b, a);
  49850. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49851. return WC_TEST_RET_ENC_EC(ret);
  49852. #endif
  49853. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49854. ret = mp_invmod_mont_ct(NULL, NULL, NULL, 1);
  49855. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49856. return WC_TEST_RET_ENC_EC(ret);
  49857. ret = mp_invmod_mont_ct(a, NULL, NULL, 1);
  49858. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49859. return WC_TEST_RET_ENC_EC(ret);
  49860. ret = mp_invmod_mont_ct(NULL, b, NULL, 1);
  49861. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49862. return WC_TEST_RET_ENC_EC(ret);
  49863. ret = mp_invmod_mont_ct(NULL, NULL, a, 1);
  49864. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49865. return WC_TEST_RET_ENC_EC(ret);
  49866. ret = mp_invmod_mont_ct(a, b, NULL, 1);
  49867. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49868. return WC_TEST_RET_ENC_EC(ret);
  49869. ret = mp_invmod_mont_ct(a, NULL, a, 1);
  49870. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49871. return WC_TEST_RET_ENC_EC(ret);
  49872. ret = mp_invmod_mont_ct(NULL, b, a, 1);
  49873. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49874. return WC_TEST_RET_ENC_EC(ret);
  49875. #endif
  49876. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  49877. ret = mp_lcm(NULL, NULL, NULL);
  49878. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49879. return WC_TEST_RET_ENC_EC(ret);
  49880. ret = mp_lcm(a, NULL, NULL);
  49881. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49882. return WC_TEST_RET_ENC_EC(ret);
  49883. ret = mp_lcm(NULL, b, NULL);
  49884. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49885. return WC_TEST_RET_ENC_EC(ret);
  49886. ret = mp_lcm(NULL, NULL, a);
  49887. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49888. return WC_TEST_RET_ENC_EC(ret);
  49889. ret = mp_lcm(a, b, NULL);
  49890. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49891. return WC_TEST_RET_ENC_EC(ret);
  49892. ret = mp_lcm(a, NULL, a);
  49893. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49894. return WC_TEST_RET_ENC_EC(ret);
  49895. ret = mp_lcm(NULL, b, a);
  49896. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49897. return WC_TEST_RET_ENC_EC(ret);
  49898. #endif
  49899. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49900. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49901. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49902. return WC_TEST_RET_ENC_EC(ret);
  49903. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49904. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49905. return WC_TEST_RET_ENC_EC(ret);
  49906. ret = mp_exptmod_ex(NULL, b, 1, NULL, NULL);
  49907. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49908. return WC_TEST_RET_ENC_EC(ret);
  49909. ret = mp_exptmod_ex(NULL, NULL, 1, b, NULL);
  49910. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49911. return WC_TEST_RET_ENC_EC(ret);
  49912. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49913. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49914. return WC_TEST_RET_ENC_EC(ret);
  49915. ret = mp_exptmod_ex(a, b, 1, b, NULL);
  49916. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49917. return WC_TEST_RET_ENC_EC(ret);
  49918. ret = mp_exptmod_ex(a, b, 1, NULL, a);
  49919. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49920. return WC_TEST_RET_ENC_EC(ret);
  49921. ret = mp_exptmod_ex(a, NULL, 1, b, a);
  49922. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49923. return WC_TEST_RET_ENC_EC(ret);
  49924. ret = mp_exptmod_ex(NULL, b, 1, b, a);
  49925. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49926. return WC_TEST_RET_ENC_EC(ret);
  49927. ret = mp_exptmod(NULL, NULL, NULL, NULL);
  49928. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49929. return WC_TEST_RET_ENC_EC(ret);
  49930. ret = mp_exptmod(a, NULL, NULL, NULL);
  49931. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49932. return WC_TEST_RET_ENC_EC(ret);
  49933. ret = mp_exptmod(NULL, b, NULL, NULL);
  49934. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49935. return WC_TEST_RET_ENC_EC(ret);
  49936. ret = mp_exptmod(NULL, NULL, b, NULL);
  49937. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49938. return WC_TEST_RET_ENC_EC(ret);
  49939. ret = mp_exptmod(NULL, NULL, NULL, a);
  49940. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49941. return WC_TEST_RET_ENC_EC(ret);
  49942. ret = mp_exptmod(a, b, b, NULL);
  49943. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49944. return WC_TEST_RET_ENC_EC(ret);
  49945. ret = mp_exptmod(a, b, NULL, a);
  49946. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49947. return WC_TEST_RET_ENC_EC(ret);
  49948. ret = mp_exptmod(a, NULL, b, a);
  49949. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49950. return WC_TEST_RET_ENC_EC(ret);
  49951. ret = mp_exptmod(NULL, b, b, a);
  49952. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49953. return WC_TEST_RET_ENC_EC(ret);
  49954. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49955. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49956. return WC_TEST_RET_ENC_EC(ret);
  49957. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49958. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49959. return WC_TEST_RET_ENC_EC(ret);
  49960. ret = mp_exptmod_nct(NULL, b, NULL, NULL);
  49961. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49962. return WC_TEST_RET_ENC_EC(ret);
  49963. ret = mp_exptmod_nct(NULL, NULL, b, NULL);
  49964. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49965. return WC_TEST_RET_ENC_EC(ret);
  49966. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49967. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49968. return WC_TEST_RET_ENC_EC(ret);
  49969. ret = mp_exptmod_nct(a, b, b, NULL);
  49970. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49971. return WC_TEST_RET_ENC_EC(ret);
  49972. ret = mp_exptmod_nct(a, b, NULL, a);
  49973. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49974. return WC_TEST_RET_ENC_EC(ret);
  49975. ret = mp_exptmod_nct(a, NULL, b, a);
  49976. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49977. return WC_TEST_RET_ENC_EC(ret);
  49978. ret = mp_exptmod_nct(NULL, b, b, a);
  49979. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49980. return WC_TEST_RET_ENC_EC(ret);
  49981. #endif
  49982. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  49983. ret = mp_cnt_lsb(NULL);
  49984. if (ret != 0)
  49985. return WC_TEST_RET_ENC_EC(ret);
  49986. #endif
  49987. #ifdef WOLFSSL_SP_PRIME_GEN
  49988. ret = mp_prime_is_prime(NULL, 1, NULL);
  49989. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49990. return WC_TEST_RET_ENC_EC(ret);
  49991. ret = mp_prime_is_prime(a, 1, NULL);
  49992. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49993. return WC_TEST_RET_ENC_EC(ret);
  49994. ret = mp_prime_is_prime(NULL, 1, &result);
  49995. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49996. return WC_TEST_RET_ENC_EC(ret);
  49997. ret = mp_prime_is_prime(a, 0, &result);
  49998. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49999. return WC_TEST_RET_ENC_EC(ret);
  50000. ret = mp_prime_is_prime(a, 1024, &result);
  50001. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50002. return WC_TEST_RET_ENC_EC(ret);
  50003. ret = mp_prime_is_prime_ex(NULL, 1, NULL, NULL);
  50004. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50005. return WC_TEST_RET_ENC_EC(ret);
  50006. ret = mp_prime_is_prime_ex(a, 1, NULL, NULL);
  50007. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50008. return WC_TEST_RET_ENC_EC(ret);
  50009. ret = mp_prime_is_prime_ex(NULL, 1, &result, NULL);
  50010. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50011. return WC_TEST_RET_ENC_EC(ret);
  50012. ret = mp_prime_is_prime_ex(NULL, 1, NULL, rng);
  50013. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50014. return WC_TEST_RET_ENC_EC(ret);
  50015. ret = mp_prime_is_prime_ex(a, 1, &result, NULL);
  50016. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50017. return WC_TEST_RET_ENC_EC(ret);
  50018. ret = mp_prime_is_prime_ex(a, 1, NULL, rng);
  50019. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50020. return WC_TEST_RET_ENC_EC(ret);
  50021. ret = mp_prime_is_prime_ex(NULL, 1, &result, rng);
  50022. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50023. return WC_TEST_RET_ENC_EC(ret);
  50024. #endif
  50025. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA)
  50026. ret = mp_exch(NULL, NULL);
  50027. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50028. return WC_TEST_RET_ENC_EC(ret);
  50029. ret = mp_exch(a, NULL);
  50030. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50031. return WC_TEST_RET_ENC_EC(ret);
  50032. ret = mp_exch(NULL, b);
  50033. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50034. return WC_TEST_RET_ENC_EC(ret);
  50035. #endif
  50036. #if (defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)) || \
  50037. defined(WOLFSSL_SP_MATH_ALL)
  50038. ret = mp_mul_d(NULL, 1, NULL);
  50039. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50040. return WC_TEST_RET_ENC_EC(ret);
  50041. ret = mp_mul_d(a, 1, NULL);
  50042. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50043. return WC_TEST_RET_ENC_EC(ret);
  50044. ret = mp_mul_d(NULL, 1, b);
  50045. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50046. return WC_TEST_RET_ENC_EC(ret);
  50047. #endif
  50048. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50049. ret = mp_add(NULL, NULL, NULL);
  50050. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50051. return WC_TEST_RET_ENC_EC(ret);
  50052. ret = mp_add(a, NULL, NULL);
  50053. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50054. return WC_TEST_RET_ENC_EC(ret);
  50055. ret = mp_add(NULL, b, NULL);
  50056. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50057. return WC_TEST_RET_ENC_EC(ret);
  50058. ret = mp_add(NULL, NULL, r);
  50059. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50060. return WC_TEST_RET_ENC_EC(ret);
  50061. ret = mp_add(a, b, NULL);
  50062. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50063. return WC_TEST_RET_ENC_EC(ret);
  50064. ret = mp_add(a, NULL, r);
  50065. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50066. return WC_TEST_RET_ENC_EC(ret);
  50067. ret = mp_add(NULL, b, r);
  50068. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50069. return WC_TEST_RET_ENC_EC(ret);
  50070. #endif
  50071. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50072. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50073. ret = mp_sub(NULL, NULL, NULL);
  50074. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50075. return WC_TEST_RET_ENC_EC(ret);
  50076. ret = mp_sub(a, NULL, NULL);
  50077. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50078. return WC_TEST_RET_ENC_EC(ret);
  50079. ret = mp_sub(NULL, b, NULL);
  50080. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50081. return WC_TEST_RET_ENC_EC(ret);
  50082. ret = mp_sub(NULL, NULL, r);
  50083. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50084. return WC_TEST_RET_ENC_EC(ret);
  50085. ret = mp_sub(a, b, NULL);
  50086. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50087. return WC_TEST_RET_ENC_EC(ret);
  50088. ret = mp_sub(a, NULL, r);
  50089. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50090. return WC_TEST_RET_ENC_EC(ret);
  50091. ret = mp_sub(NULL, b, r);
  50092. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50093. return WC_TEST_RET_ENC_EC(ret);
  50094. #endif
  50095. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined(WOLFSSL_SP_MATH) && \
  50096. defined(WOLFSSL_CUSTOM_CURVES))
  50097. ret = mp_addmod(NULL, NULL, NULL, NULL);
  50098. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50099. return WC_TEST_RET_ENC_EC(ret);
  50100. ret = mp_addmod(a, NULL, NULL, NULL);
  50101. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50102. return WC_TEST_RET_ENC_EC(ret);
  50103. ret = mp_addmod(NULL, b, NULL, NULL);
  50104. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50105. return WC_TEST_RET_ENC_EC(ret);
  50106. ret = mp_addmod(NULL, NULL, b, NULL);
  50107. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50108. return WC_TEST_RET_ENC_EC(ret);
  50109. ret = mp_addmod(NULL, NULL, NULL, a);
  50110. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50111. return WC_TEST_RET_ENC_EC(ret);
  50112. ret = mp_addmod(a, b, b, NULL);
  50113. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50114. return WC_TEST_RET_ENC_EC(ret);
  50115. ret = mp_addmod(a, b, NULL, a);
  50116. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50117. return WC_TEST_RET_ENC_EC(ret);
  50118. ret = mp_addmod(a, NULL, b, a);
  50119. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50120. return WC_TEST_RET_ENC_EC(ret);
  50121. ret = mp_addmod(NULL, b, b, a);
  50122. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50123. return WC_TEST_RET_ENC_EC(ret);
  50124. #endif
  50125. #ifdef WOLFSSL_SP_MATH_ALL
  50126. ret = mp_submod(NULL, NULL, NULL, NULL);
  50127. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50128. return WC_TEST_RET_ENC_EC(ret);
  50129. ret = mp_submod(a, NULL, NULL, NULL);
  50130. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50131. return WC_TEST_RET_ENC_EC(ret);
  50132. ret = mp_submod(NULL, b, NULL, NULL);
  50133. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50134. return WC_TEST_RET_ENC_EC(ret);
  50135. ret = mp_submod(NULL, NULL, b, NULL);
  50136. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50137. return WC_TEST_RET_ENC_EC(ret);
  50138. ret = mp_submod(NULL, NULL, NULL, a);
  50139. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50140. return WC_TEST_RET_ENC_EC(ret);
  50141. ret = mp_submod(a, b, b, NULL);
  50142. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50143. return WC_TEST_RET_ENC_EC(ret);
  50144. ret = mp_submod(a, b, NULL, a);
  50145. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50146. return WC_TEST_RET_ENC_EC(ret);
  50147. ret = mp_submod(a, NULL, b, a);
  50148. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50149. return WC_TEST_RET_ENC_EC(ret);
  50150. ret = mp_submod(NULL, b, b, a);
  50151. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50152. return WC_TEST_RET_ENC_EC(ret);
  50153. #endif
  50154. #ifdef WOLFSSL_SP_MATH_ALL
  50155. ret = mp_div_2d(NULL, 1, a, b);
  50156. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50157. return WC_TEST_RET_ENC_EC(ret);
  50158. ret = mp_mod_2d(NULL, 1, NULL);
  50159. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50160. return WC_TEST_RET_ENC_EC(ret);
  50161. ret = mp_mod_2d(a, 1, NULL);
  50162. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50163. return WC_TEST_RET_ENC_EC(ret);
  50164. ret = mp_mod_2d(NULL, 1, b);
  50165. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50166. return WC_TEST_RET_ENC_EC(ret);
  50167. ret = mp_mul_2d(NULL, 1, NULL);
  50168. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50169. return WC_TEST_RET_ENC_EC(ret);
  50170. ret = mp_mul_2d(a, 1, NULL);
  50171. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50172. return WC_TEST_RET_ENC_EC(ret);
  50173. ret = mp_mul_2d(NULL, 1, b);
  50174. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50175. return WC_TEST_RET_ENC_EC(ret);
  50176. #endif
  50177. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50178. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50179. ret = mp_montgomery_reduce(NULL, NULL, 1);
  50180. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50181. return WC_TEST_RET_ENC_EC(ret);
  50182. ret = mp_montgomery_reduce(a, NULL, 1);
  50183. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50184. return WC_TEST_RET_ENC_EC(ret);
  50185. ret = mp_montgomery_reduce(NULL, b, 1);
  50186. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50187. return WC_TEST_RET_ENC_EC(ret);
  50188. mp_zero(b);
  50189. ret = mp_montgomery_reduce(a, b, 1);
  50190. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50191. return WC_TEST_RET_ENC_EC(ret);
  50192. #endif
  50193. #ifdef WOLFSSL_SP_MATH_ALL
  50194. ret = mp_montgomery_setup(NULL, NULL);
  50195. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50196. return WC_TEST_RET_ENC_EC(ret);
  50197. ret = mp_montgomery_setup(a, NULL);
  50198. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50199. return WC_TEST_RET_ENC_EC(ret);
  50200. ret = mp_montgomery_setup(NULL, &rho);
  50201. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50202. return WC_TEST_RET_ENC_EC(ret);
  50203. ret = mp_montgomery_calc_normalization(NULL, NULL);
  50204. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50205. return WC_TEST_RET_ENC_EC(ret);
  50206. ret = mp_montgomery_calc_normalization(a, NULL);
  50207. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50208. return WC_TEST_RET_ENC_EC(ret);
  50209. ret = mp_montgomery_calc_normalization(NULL, b);
  50210. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50211. return WC_TEST_RET_ENC_EC(ret);
  50212. #endif
  50213. ret = mp_unsigned_bin_size(NULL);
  50214. if (ret != 0)
  50215. return WC_TEST_RET_ENC_EC(ret);
  50216. #if defined(WC_MP_TO_RADIX) || defined(WOLFSSL_SP_MATH_ALL)
  50217. ret = mp_tohex(NULL, NULL);
  50218. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50219. return WC_TEST_RET_ENC_EC(ret);
  50220. ret = mp_tohex(a, NULL);
  50221. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50222. return WC_TEST_RET_ENC_EC(ret);
  50223. ret = mp_tohex(NULL, hexStr);
  50224. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50225. return WC_TEST_RET_ENC_EC(ret);
  50226. #endif
  50227. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  50228. ret = mp_todecimal(NULL, NULL);
  50229. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50230. return WC_TEST_RET_ENC_EC(ret);
  50231. ret = mp_todecimal(a, NULL);
  50232. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50233. return WC_TEST_RET_ENC_EC(ret);
  50234. ret = mp_todecimal(NULL, decStr);
  50235. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50236. return WC_TEST_RET_ENC_EC(ret);
  50237. #endif
  50238. #ifdef WOLFSSL_SP_MATH_ALL
  50239. ret = mp_toradix(NULL, NULL, MP_RADIX_HEX);
  50240. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50241. return WC_TEST_RET_ENC_EC(ret);
  50242. ret = mp_toradix(a, NULL, MP_RADIX_HEX);
  50243. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50244. return WC_TEST_RET_ENC_EC(ret);
  50245. ret = mp_toradix(NULL, hexStr, MP_RADIX_HEX);
  50246. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50247. return WC_TEST_RET_ENC_EC(ret);
  50248. ret = mp_toradix(a, hexStr, 3);
  50249. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50250. return WC_TEST_RET_ENC_EC(ret);
  50251. ret = mp_radix_size(NULL, MP_RADIX_HEX, NULL);
  50252. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50253. return WC_TEST_RET_ENC_EC(ret);
  50254. ret = mp_radix_size(a, MP_RADIX_HEX, NULL);
  50255. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50256. return WC_TEST_RET_ENC_EC(ret);
  50257. ret = mp_radix_size(NULL, MP_RADIX_HEX, &size);
  50258. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50259. return WC_TEST_RET_ENC_EC(ret);
  50260. ret = mp_radix_size(a, 3, &size);
  50261. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50262. return WC_TEST_RET_ENC_EC(ret);
  50263. #endif
  50264. return 0;
  50265. }
  50266. #endif
  50267. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50268. static wc_test_ret_t mp_test_set_is_bit(mp_int* a)
  50269. {
  50270. int i, j;
  50271. wc_test_ret_t ret;
  50272. mp_zero(a);
  50273. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50274. if (mp_is_bit_set(a, i))
  50275. return WC_TEST_RET_ENC_NC;
  50276. for (j = 0; j < i; j++) {
  50277. if (!mp_is_bit_set(a, j))
  50278. return WC_TEST_RET_ENC_NC;
  50279. }
  50280. if (mp_set_bit(a, i) != 0)
  50281. return WC_TEST_RET_ENC_NC;
  50282. if (!mp_is_bit_set(a, i))
  50283. return WC_TEST_RET_ENC_NC;
  50284. }
  50285. mp_zero(a);
  50286. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50287. if (mp_is_bit_set(a, i))
  50288. return WC_TEST_RET_ENC_NC;
  50289. }
  50290. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50291. mp_zero(a);
  50292. if (mp_set_bit(a, i) != 0)
  50293. return WC_TEST_RET_ENC_NC;
  50294. for (j = 0; j < i; j++) {
  50295. if (mp_is_bit_set(a, j))
  50296. return WC_TEST_RET_ENC_NC;
  50297. }
  50298. if (!mp_is_bit_set(a, i))
  50299. return WC_TEST_RET_ENC_NC;
  50300. }
  50301. #ifdef WOLFSSL_KEY_GEN
  50302. for (i = 0; i < DIGIT_BIT * 2; i++) {
  50303. mp_set(a, 1);
  50304. ret = mp_2expt(a, i);
  50305. if (ret != 0)
  50306. return WC_TEST_RET_ENC_EC(ret);
  50307. for (j = 0; j < i; j++) {
  50308. if (mp_is_bit_set(a, j))
  50309. return WC_TEST_RET_ENC_NC;
  50310. }
  50311. if (!mp_is_bit_set(a, i))
  50312. return WC_TEST_RET_ENC_NC;
  50313. }
  50314. #endif
  50315. #ifdef WOLFSSL_SP_MATH
  50316. mp_zero(a);
  50317. for (j = 1; j <= 3; j++) {
  50318. i = SP_INT_MAX_BITS - j;
  50319. if (mp_is_bit_set(a, i))
  50320. return WC_TEST_RET_ENC_NC;
  50321. if (mp_set_bit(a, i) != 0)
  50322. return WC_TEST_RET_ENC_NC;
  50323. if (!mp_is_bit_set(a, i))
  50324. return WC_TEST_RET_ENC_NC;
  50325. #ifdef WOLFSSL_KEY_GEN
  50326. ret = mp_2expt(a, i);
  50327. if (ret != 0)
  50328. return WC_TEST_RET_ENC_EC(ret);
  50329. if (!mp_is_bit_set(a, i))
  50330. return WC_TEST_RET_ENC_NC;
  50331. #endif
  50332. }
  50333. mp_zero(a);
  50334. for (j = 0; j <= 3; j++) {
  50335. i = SP_INT_MAX_BITS + j;
  50336. if (mp_is_bit_set(a, i))
  50337. return WC_TEST_RET_ENC_NC;
  50338. if (mp_set_bit(a, i) != WC_NO_ERR_TRACE(MP_VAL))
  50339. return WC_TEST_RET_ENC_NC;
  50340. #ifdef WOLFSSL_KEY_GEN
  50341. ret = mp_2expt(a, i);
  50342. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50343. return WC_TEST_RET_ENC_EC(ret);
  50344. #endif
  50345. }
  50346. #endif
  50347. (void)ret;
  50348. return 0;
  50349. }
  50350. #endif /* !WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */
  50351. static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b)
  50352. {
  50353. wc_test_ret_t ret;
  50354. mp_zero(a);
  50355. mp_zero(b);
  50356. ret = mp_cmp_d(a, 0);
  50357. if (ret != MP_EQ)
  50358. return WC_TEST_RET_ENC_EC(ret);
  50359. ret = mp_cmp_d(a, 1);
  50360. if (ret != MP_LT)
  50361. return WC_TEST_RET_ENC_EC(ret);
  50362. ret = mp_cmp(a, b);
  50363. if (ret != MP_EQ)
  50364. return WC_TEST_RET_ENC_NC;
  50365. mp_set(a, 1);
  50366. ret = mp_cmp_d(a, 0);
  50367. if (ret != MP_GT)
  50368. return WC_TEST_RET_ENC_EC(ret);
  50369. ret = mp_cmp_d(a, 1);
  50370. if (ret != MP_EQ)
  50371. return WC_TEST_RET_ENC_EC(ret);
  50372. ret = mp_cmp_d(a, 2);
  50373. if (ret != MP_LT)
  50374. return WC_TEST_RET_ENC_EC(ret);
  50375. ret = mp_cmp(a, b);
  50376. if (ret != MP_GT)
  50377. return WC_TEST_RET_ENC_NC;
  50378. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50379. mp_read_radix(b, "1234567890123456789", MP_RADIX_HEX);
  50380. ret = mp_cmp_d(b, -1);
  50381. if (ret != MP_GT)
  50382. return WC_TEST_RET_ENC_EC(ret);
  50383. ret = mp_cmp(a, b);
  50384. if (ret != MP_LT)
  50385. return WC_TEST_RET_ENC_NC;
  50386. ret = mp_cmp(b, a);
  50387. if (ret != MP_GT)
  50388. return WC_TEST_RET_ENC_NC;
  50389. ret = mp_cmp(b, b);
  50390. if (ret != MP_EQ)
  50391. return WC_TEST_RET_ENC_NC;
  50392. #endif
  50393. #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
  50394. defined(WOLFSSL_SP_INT_NEGATIVE)
  50395. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50396. mp_read_radix(a, "-1", MP_RADIX_HEX);
  50397. mp_read_radix(a, "1", MP_RADIX_HEX);
  50398. ret = mp_cmp(a, b);
  50399. if (ret != MP_LT)
  50400. return WC_TEST_RET_ENC_NC;
  50401. ret = mp_cmp(b, a);
  50402. if (ret != MP_GT)
  50403. return WC_TEST_RET_ENC_NC;
  50404. mp_read_radix(b, "-2", MP_RADIX_HEX);
  50405. ret = mp_cmp(a, b);
  50406. if (ret != MP_GT)
  50407. return WC_TEST_RET_ENC_NC;
  50408. ret = mp_cmp(b, a);
  50409. if (ret != MP_LT)
  50410. return WC_TEST_RET_ENC_NC;
  50411. #endif
  50412. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50413. mp_read_radix(a, "-2", MP_RADIX_HEX);
  50414. ret = mp_cmp(a, b);
  50415. if (ret != MP_EQ)
  50416. return WC_TEST_RET_ENC_NC;
  50417. #endif
  50418. #endif
  50419. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  50420. defined(WOLFSSL_ECC_GEN_REJECT_SAMPLING)
  50421. mp_zero(a);
  50422. mp_zero(b);
  50423. ret = mp_cmp_ct(a, b, 1);
  50424. if (ret != MP_EQ)
  50425. return WC_TEST_RET_ENC_EC(ret);
  50426. ret = mp_cmp_ct(a, a, a->used);
  50427. if (ret != MP_EQ)
  50428. return WC_TEST_RET_ENC_EC(ret);
  50429. #ifdef WOLFSSL_SP_MATH_ALL
  50430. ret = mp_cmp_ct(a, NULL, a->used);
  50431. if (ret != MP_GT)
  50432. return WC_TEST_RET_ENC_EC(ret);
  50433. ret = mp_cmp_ct(NULL, a, a->used);
  50434. if (ret != MP_LT)
  50435. return WC_TEST_RET_ENC_EC(ret);
  50436. #endif
  50437. mp_read_radix(a, "1", MP_RADIX_HEX);
  50438. ret = mp_cmp_ct(a, b, 1);
  50439. if (ret != MP_GT)
  50440. return WC_TEST_RET_ENC_EC(ret);
  50441. ret = mp_cmp_ct(b, a, 1);
  50442. if (ret != MP_LT)
  50443. return WC_TEST_RET_ENC_EC(ret);
  50444. mp_read_radix(a, "0123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50445. ret = mp_cmp_ct(a, b, a->used);
  50446. if (ret != MP_GT)
  50447. return WC_TEST_RET_ENC_EC(ret);
  50448. ret = mp_cmp_ct(b, a, a->used);
  50449. if (ret != MP_LT)
  50450. return WC_TEST_RET_ENC_EC(ret);
  50451. mp_read_radix(b, "1123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50452. ret = mp_cmp_ct(b, a, a->used);
  50453. if (ret != MP_GT)
  50454. return WC_TEST_RET_ENC_EC(ret);
  50455. ret = mp_cmp_ct(a, b, a->used);
  50456. if (ret != MP_LT)
  50457. return WC_TEST_RET_ENC_EC(ret);
  50458. mp_read_radix(b, "0123456789abcdef0123456789abcdf0", MP_RADIX_HEX);
  50459. ret = mp_cmp_ct(b, a, a->used);
  50460. if (ret != MP_GT)
  50461. return WC_TEST_RET_ENC_EC(ret);
  50462. ret = mp_cmp_ct(a, b, a->used);
  50463. if (ret != MP_LT)
  50464. return WC_TEST_RET_ENC_EC(ret);
  50465. mp_read_radix(b, "0123456789abcdf0", MP_RADIX_HEX);
  50466. ret = mp_cmp_ct(a, b, a->used);
  50467. if (ret != MP_GT)
  50468. return WC_TEST_RET_ENC_EC(ret);
  50469. ret = mp_cmp_ct(b, a, a->used);
  50470. if (ret != MP_LT)
  50471. return WC_TEST_RET_ENC_EC(ret);
  50472. #endif
  50473. return 0;
  50474. }
  50475. #if !defined(NO_DH) || defined(HAVE_ECC) || (!defined(NO_RSA) && \
  50476. !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  50477. static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
  50478. {
  50479. wc_test_ret_t ret;
  50480. int i, j, k;
  50481. #ifndef WOLFSSL_SP_MATH
  50482. for (i = 0; i < 10; i++) {
  50483. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50484. ret = randNum(a, j, rng, NULL);
  50485. if (ret != MP_OKAY)
  50486. return WC_TEST_RET_ENC_EC(ret);
  50487. mp_copy(a, b);
  50488. for (k = 0; k <= DIGIT_BIT * 2; k++) {
  50489. ret = mp_mul_2d(a, k, a);
  50490. if (ret != MP_OKAY)
  50491. return WC_TEST_RET_ENC_EC(ret);
  50492. mp_rshb(a, k);
  50493. ret = mp_cmp(a, b);
  50494. if (ret != MP_EQ)
  50495. return WC_TEST_RET_ENC_NC;
  50496. }
  50497. }
  50498. }
  50499. #endif
  50500. for (i = 0; i < 10; i++) {
  50501. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50502. ret = randNum(a, j, rng, NULL);
  50503. if (ret != MP_OKAY)
  50504. return WC_TEST_RET_ENC_EC(ret);
  50505. mp_copy(a, b);
  50506. for (k = 0; k < 10; k++) {
  50507. ret = mp_lshd(a, k);
  50508. if (ret != MP_OKAY)
  50509. return WC_TEST_RET_ENC_EC(ret);
  50510. #ifndef WOLFSSL_SP_MATH
  50511. mp_rshd(a, k);
  50512. #else
  50513. mp_rshb(a, k * SP_WORD_SIZE);
  50514. #endif
  50515. ret = mp_cmp(a, b);
  50516. if (ret != MP_EQ)
  50517. return WC_TEST_RET_ENC_NC;
  50518. }
  50519. }
  50520. }
  50521. #ifndef WOLFSSL_SP_MATH
  50522. mp_zero(a);
  50523. mp_rshd(a, 1);
  50524. if (!mp_iszero(a))
  50525. return WC_TEST_RET_ENC_NC;
  50526. mp_set(a, 1);
  50527. mp_rshd(a, 1);
  50528. if (!mp_iszero(a))
  50529. return WC_TEST_RET_ENC_NC;
  50530. mp_set(a, 1);
  50531. mp_rshd(a, 2);
  50532. if (!mp_iszero(a))
  50533. return WC_TEST_RET_ENC_NC;
  50534. #endif
  50535. return 0;
  50536. }
  50537. #endif
  50538. #if !defined(NO_DH) || defined(HAVE_ECC) || \
  50539. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  50540. static wc_test_ret_t mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem,
  50541. WC_RNG* rng)
  50542. {
  50543. wc_test_ret_t ret;
  50544. int i, j, k;
  50545. mp_zero(a);
  50546. mp_zero(d);
  50547. ret = mp_div(a, d, r, rem);
  50548. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50549. return WC_TEST_RET_ENC_EC(ret);
  50550. mp_set(d, 1);
  50551. ret = mp_div(a, d, r, rem);
  50552. if (ret != MP_OKAY)
  50553. return WC_TEST_RET_ENC_EC(ret);
  50554. if (!mp_iszero(r))
  50555. return WC_TEST_RET_ENC_EC(ret);
  50556. if (!mp_iszero(rem))
  50557. return WC_TEST_RET_ENC_EC(ret);
  50558. mp_set(a, 1);
  50559. ret = mp_div(a, d, r, rem);
  50560. if (ret != MP_OKAY)
  50561. return WC_TEST_RET_ENC_EC(ret);
  50562. if (!mp_isone(r))
  50563. return WC_TEST_RET_ENC_EC(ret);
  50564. if (!mp_iszero(rem))
  50565. return WC_TEST_RET_ENC_EC(ret);
  50566. for (i = 0; i < 100; i++) {
  50567. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 2; j++) {
  50568. ret = randNum(d, j, rng, NULL);
  50569. if (ret != MP_OKAY)
  50570. return WC_TEST_RET_ENC_EC(ret);
  50571. for (k = 1; k < (DIGIT_BIT + 7) / 8 * 2 + 1; k++) {
  50572. ret = randNum(a, k, rng, NULL);
  50573. if (ret != MP_OKAY)
  50574. return WC_TEST_RET_ENC_EC(ret);
  50575. ret = mp_div(a, d, NULL, rem);
  50576. if (ret != MP_OKAY)
  50577. return WC_TEST_RET_ENC_EC(ret);
  50578. ret = mp_div(a, d, r, NULL);
  50579. if (ret != MP_OKAY)
  50580. return WC_TEST_RET_ENC_EC(ret);
  50581. ret = mp_div(a, d, r, rem);
  50582. if (ret != MP_OKAY)
  50583. return WC_TEST_RET_ENC_EC(ret);
  50584. mp_mul(r, d, r);
  50585. mp_add(r, rem, r);
  50586. if (mp_cmp(r, a) != MP_EQ)
  50587. return WC_TEST_RET_ENC_NC;
  50588. }
  50589. }
  50590. }
  50591. ret = randNum(d, (DIGIT_BIT + 7) / 8 * 2, rng, NULL);
  50592. if (ret != MP_OKAY)
  50593. return WC_TEST_RET_ENC_EC(ret);
  50594. mp_add(d, d, a);
  50595. mp_set(rem, 1);
  50596. mp_div(a, d, NULL, rem);
  50597. if (ret != MP_OKAY)
  50598. return WC_TEST_RET_ENC_EC(ret);
  50599. if (!mp_iszero(rem))
  50600. return WC_TEST_RET_ENC_EC(ret);
  50601. mp_set(r, 1);
  50602. mp_div(a, d, r, NULL);
  50603. if (ret != MP_OKAY)
  50604. return WC_TEST_RET_ENC_EC(ret);
  50605. if (mp_cmp_d(r, 2) != MP_EQ)
  50606. return WC_TEST_RET_ENC_EC(ret);
  50607. mp_set(r, 1);
  50608. mp_set(rem, 1);
  50609. mp_div(a, d, r, rem);
  50610. if (ret != MP_OKAY)
  50611. return WC_TEST_RET_ENC_EC(ret);
  50612. if (mp_cmp_d(r, 2) != MP_EQ)
  50613. return WC_TEST_RET_ENC_EC(ret);
  50614. if (!mp_iszero(rem))
  50615. return WC_TEST_RET_ENC_EC(ret);
  50616. mp_set(a, 0xfe);
  50617. mp_lshd(a, 3);
  50618. mp_add_d(a, 0xff, a);
  50619. mp_set(d, 0xfe);
  50620. mp_lshd(d, 2);
  50621. ret = mp_div(a, d, r, rem);
  50622. if (ret != MP_OKAY)
  50623. return WC_TEST_RET_ENC_EC(ret);
  50624. mp_mul(r, d, d);
  50625. mp_add(rem, d, d);
  50626. if (mp_cmp(a, d) != MP_EQ)
  50627. return WC_TEST_RET_ENC_NC;
  50628. /* Force (hi | lo) / d to be (d | 0) / d which will would not fit in
  50629. * a digit. So mp_div must detect and handle.
  50630. * For example: 0x800000 / 0x8001, DIGIT_BIT = 8
  50631. */
  50632. mp_zero(a);
  50633. mp_set_bit(a, DIGIT_BIT * 3 - 1);
  50634. mp_zero(d);
  50635. mp_set_bit(d, DIGIT_BIT * 2 - 1);
  50636. mp_add_d(d, 1, d);
  50637. ret = mp_div(a, d, r, rem);
  50638. if (ret != MP_OKAY)
  50639. return WC_TEST_RET_ENC_EC(ret);
  50640. /* Make sure [d | d] / d is handled. */
  50641. mp_zero(a);
  50642. mp_set_bit(a, DIGIT_BIT * 2 - 1);
  50643. mp_set_bit(a, DIGIT_BIT * 1 - 1);
  50644. mp_zero(d);
  50645. mp_set_bit(d, DIGIT_BIT - 1);
  50646. ret = mp_div(a, d, r, rem);
  50647. if (ret != MP_OKAY)
  50648. return WC_TEST_RET_ENC_EC(ret);
  50649. mp_zero(a);
  50650. mp_set_bit(a, DIGIT_BIT);
  50651. mp_set_bit(a, 0);
  50652. mp_zero(d);
  50653. if (mp_cmp(r, a) != MP_EQ)
  50654. return WC_TEST_RET_ENC_NC;
  50655. if (mp_cmp(rem, d) != MP_EQ)
  50656. return WC_TEST_RET_ENC_NC;
  50657. return 0;
  50658. }
  50659. #endif
  50660. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50661. !defined(WC_NO_RNG)
  50662. static wc_test_ret_t mp_test_prime(mp_int* a, WC_RNG* rng)
  50663. {
  50664. wc_test_ret_t ret;
  50665. int res;
  50666. ret = mp_rand_prime(a, 1, rng, NULL);
  50667. #if defined(WOLFSSL_SP_MATH_ALL)
  50668. if (ret != 0)
  50669. return WC_TEST_RET_ENC_EC(ret);
  50670. #else
  50671. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50672. return WC_TEST_RET_ENC_NC;
  50673. #endif
  50674. #ifndef WOLFSSL_SP_MATH
  50675. ret = mp_rand_prime(a, -5, rng, NULL);
  50676. if (ret != 0 || (a->dp[0] & 3) != 3)
  50677. return WC_TEST_RET_ENC_NC;
  50678. #endif
  50679. ret = mp_prime_is_prime(a, 1, &res);
  50680. if (ret != MP_OKAY)
  50681. return WC_TEST_RET_ENC_EC(ret);
  50682. #ifndef WOLFSSL_SP_MATH
  50683. if (res != MP_YES)
  50684. return WC_TEST_RET_ENC_EC(res);
  50685. #else
  50686. if (res != MP_NO)
  50687. return WC_TEST_RET_ENC_EC(res);
  50688. #endif
  50689. ret = mp_prime_is_prime(a, 0, &res);
  50690. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50691. return WC_TEST_RET_ENC_EC(ret);
  50692. ret = mp_prime_is_prime(a, -1, &res);
  50693. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50694. return WC_TEST_RET_ENC_EC(ret);
  50695. ret = mp_prime_is_prime(a, 257, &res);
  50696. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50697. return WC_TEST_RET_ENC_EC(ret);
  50698. mp_set(a, 1);
  50699. ret = mp_prime_is_prime(a, 1, &res);
  50700. if (ret != MP_OKAY)
  50701. return WC_TEST_RET_ENC_EC(ret);
  50702. if (res != MP_NO)
  50703. return WC_TEST_RET_ENC_EC(res);
  50704. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50705. if (ret != MP_OKAY)
  50706. return WC_TEST_RET_ENC_EC(ret);
  50707. if (res != MP_NO)
  50708. return WC_TEST_RET_ENC_EC(res);
  50709. mp_set(a, 2);
  50710. ret = mp_prime_is_prime(a, 1, &res);
  50711. if (ret != MP_OKAY)
  50712. return WC_TEST_RET_ENC_EC(ret);
  50713. if (res != MP_YES)
  50714. return WC_TEST_RET_ENC_EC(res);
  50715. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50716. if (ret != MP_OKAY)
  50717. return WC_TEST_RET_ENC_EC(ret);
  50718. if (res != MP_YES)
  50719. return WC_TEST_RET_ENC_EC(res);
  50720. mp_set(a, 0xfb);
  50721. ret = mp_prime_is_prime(a, 1, &res);
  50722. if (ret != MP_OKAY)
  50723. return WC_TEST_RET_ENC_EC(ret);
  50724. if (res != MP_YES)
  50725. return WC_TEST_RET_ENC_EC(res);
  50726. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50727. if (ret != MP_OKAY)
  50728. return WC_TEST_RET_ENC_EC(ret);
  50729. if (res != MP_YES)
  50730. return WC_TEST_RET_ENC_EC(res);
  50731. mp_set(a, 0x6);
  50732. ret = mp_prime_is_prime(a, 1, &res);
  50733. if (ret != MP_OKAY)
  50734. return WC_TEST_RET_ENC_EC(ret);
  50735. if (res != MP_NO)
  50736. return WC_TEST_RET_ENC_EC(res);
  50737. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50738. if (ret != MP_OKAY)
  50739. return WC_TEST_RET_ENC_EC(ret);
  50740. if (res != MP_NO)
  50741. return WC_TEST_RET_ENC_EC(res);
  50742. mp_set_int(a, 0x655 * 0x65b);
  50743. ret = mp_prime_is_prime(a, 10, &res);
  50744. if (ret != MP_OKAY)
  50745. return WC_TEST_RET_ENC_EC(ret);
  50746. if (res != MP_NO)
  50747. return WC_TEST_RET_ENC_EC(res);
  50748. ret = mp_prime_is_prime_ex(a, 10, &res, rng);
  50749. if (ret != MP_OKAY)
  50750. return WC_TEST_RET_ENC_EC(ret);
  50751. if (res != MP_NO)
  50752. return WC_TEST_RET_ENC_EC(res);
  50753. return 0;
  50754. }
  50755. #endif
  50756. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  50757. static wc_test_ret_t mp_test_lcm_gcd(mp_int* a, mp_int* b, mp_int* r, mp_int* exp,
  50758. WC_RNG* rng)
  50759. {
  50760. wc_test_ret_t ret;
  50761. int i;
  50762. WOLFSSL_SMALL_STACK_STATIC const int kat[][3] = {
  50763. { 1, 1, 1 }, { 2, 1, 2 }, { 1, 2, 2 }, { 2, 4, 4 }, { 4, 2, 4 },
  50764. { 12, 56, 168 }, { 56, 12, 168 }
  50765. };
  50766. (void)exp;
  50767. mp_set(a, 0);
  50768. mp_set(b, 1);
  50769. ret = mp_lcm(a, a, r);
  50770. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50771. return WC_TEST_RET_ENC_EC(ret);
  50772. ret = mp_lcm(a, b, r);
  50773. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50774. return WC_TEST_RET_ENC_EC(ret);
  50775. ret = mp_lcm(b, a, r);
  50776. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50777. return WC_TEST_RET_ENC_EC(ret);
  50778. for (i = 0; i < (int)(sizeof(kat) / sizeof(*kat)); i++) {
  50779. mp_set(a, kat[i][0]);
  50780. mp_set(b, kat[i][1]);
  50781. ret = mp_lcm(a, b, r);
  50782. if (ret != MP_OKAY)
  50783. return WC_TEST_RET_ENC_EC(ret);
  50784. mp_set(exp, kat[i][2]);
  50785. ret = mp_cmp(r, exp);
  50786. if (ret != MP_EQ)
  50787. return WC_TEST_RET_ENC_NC;
  50788. }
  50789. (void)rng;
  50790. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50791. !defined(WC_NO_RNG)
  50792. ret = mp_rand_prime(a, 20, rng, NULL);
  50793. if (ret != MP_OKAY)
  50794. return WC_TEST_RET_ENC_EC(ret);
  50795. ret = mp_rand_prime(b, 20, rng, NULL);
  50796. if (ret != MP_OKAY)
  50797. return WC_TEST_RET_ENC_EC(ret);
  50798. ret = mp_mul(a, b, exp);
  50799. if (ret != MP_OKAY)
  50800. return WC_TEST_RET_ENC_EC(ret);
  50801. ret = mp_lcm(a, b, r);
  50802. if (ret != MP_OKAY)
  50803. return WC_TEST_RET_ENC_EC(ret);
  50804. ret = mp_cmp(r, exp);
  50805. if (ret != MP_EQ)
  50806. return WC_TEST_RET_ENC_NC;
  50807. ret = mp_lcm(b, a, r);
  50808. if (ret != MP_OKAY)
  50809. return WC_TEST_RET_ENC_EC(ret);
  50810. ret = mp_cmp(r, exp);
  50811. if (ret != MP_EQ)
  50812. return WC_TEST_RET_ENC_NC;
  50813. #endif
  50814. mp_set(a, 11);
  50815. mp_zero(b);
  50816. ret = mp_gcd(a, b, r);
  50817. if (ret != MP_OKAY)
  50818. return WC_TEST_RET_ENC_EC(ret);
  50819. ret = mp_cmp_d(r, 11);
  50820. if (ret != MP_EQ)
  50821. return WC_TEST_RET_ENC_EC(ret);
  50822. ret = mp_gcd(b, a, r);
  50823. if (ret != MP_OKAY)
  50824. return WC_TEST_RET_ENC_EC(ret);
  50825. ret = mp_cmp_d(r, 11);
  50826. if (ret != MP_EQ)
  50827. return WC_TEST_RET_ENC_EC(ret);
  50828. ret = mp_gcd(b, b, r);
  50829. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50830. return WC_TEST_RET_ENC_EC(ret);
  50831. return 0;
  50832. }
  50833. #endif
  50834. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50835. defined(WOLFSSL_SP_MATH_ALL)
  50836. static wc_test_ret_t mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng)
  50837. {
  50838. wc_test_ret_t ret;
  50839. int i;
  50840. int j;
  50841. mp_set(a, 10);
  50842. ret = mp_mod_2d(a, 0, r);
  50843. if (ret != MP_OKAY)
  50844. return WC_TEST_RET_ENC_EC(ret);
  50845. if (!mp_iszero(r))
  50846. return WC_TEST_RET_ENC_NC;
  50847. ret = mp_mod_2d(a, 1, r);
  50848. if (ret != MP_OKAY)
  50849. return WC_TEST_RET_ENC_EC(ret);
  50850. if (!mp_iszero(r))
  50851. return WC_TEST_RET_ENC_NC;
  50852. ret = mp_mod_2d(a, 2, r);
  50853. if (ret != MP_OKAY)
  50854. return WC_TEST_RET_ENC_EC(ret);
  50855. ret = mp_cmp_d(r, 2);
  50856. if (ret != 0)
  50857. return WC_TEST_RET_ENC_EC(ret);
  50858. for (i = 2; i < 20; i++) {
  50859. ret = randNum(a, i, rng, NULL);
  50860. if (ret != 0)
  50861. return WC_TEST_RET_ENC_EC(ret);
  50862. for (j = 1; j <= mp_count_bits(a); j++) {
  50863. /* Get top part */
  50864. ret = mp_div_2d(a, j, t, NULL);
  50865. if (ret != 0)
  50866. return WC_TEST_RET_ENC_EC(ret);
  50867. ret = mp_mul_2d(t, j, t);
  50868. if (ret != 0)
  50869. return WC_TEST_RET_ENC_EC(ret);
  50870. /* Get bottom part */
  50871. ret = mp_mod_2d(a, j, r);
  50872. if (ret != 0)
  50873. return WC_TEST_RET_ENC_EC(ret);
  50874. /* Reassemble */
  50875. ret = mp_add(t, r, r);
  50876. if (ret != 0)
  50877. return WC_TEST_RET_ENC_EC(ret);
  50878. ret = mp_cmp(a, r);
  50879. if (ret != MP_EQ)
  50880. return WC_TEST_RET_ENC_NC;
  50881. }
  50882. }
  50883. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_SP_INT_NEGATIVE)
  50884. /* Test negative value being moded. */
  50885. for (j = 0; j < 20; j++) {
  50886. ret = randNum(a, 2, rng, NULL);
  50887. if (ret != 0)
  50888. return WC_TEST_RET_ENC_EC(ret);
  50889. a->sign = MP_NEG;
  50890. for (i = 1; i < DIGIT_BIT * 3 + 1; i++) {
  50891. ret = mp_mod_2d(a, i, r);
  50892. if (ret != 0)
  50893. return WC_TEST_RET_ENC_EC(ret);
  50894. mp_zero(t);
  50895. ret = mp_set_bit(t, i);
  50896. if (ret != 0)
  50897. return WC_TEST_RET_ENC_EC(ret);
  50898. ret = mp_mod(a, t, t);
  50899. if (ret != 0)
  50900. return WC_TEST_RET_ENC_EC(ret);
  50901. ret = mp_cmp(r, t);
  50902. if (ret != MP_EQ)
  50903. return WC_TEST_RET_ENC_NC;
  50904. }
  50905. }
  50906. #endif
  50907. return 0;
  50908. }
  50909. #endif
  50910. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50911. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50912. static wc_test_ret_t mp_test_mod_d(mp_int* a, WC_RNG* rng)
  50913. {
  50914. wc_test_ret_t ret;
  50915. mp_digit r;
  50916. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50917. mp_digit rem;
  50918. int i;
  50919. #endif
  50920. (void)rng;
  50921. ret = mp_set(a, 1);
  50922. if (ret != MP_OKAY)
  50923. return WC_TEST_RET_ENC_EC(ret);
  50924. ret = mp_mod_d(a, 0, &r);
  50925. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50926. return WC_TEST_RET_ENC_EC(ret);
  50927. mp_zero(a);
  50928. ret = mp_mod_d(a, 1, &r);
  50929. if (ret != MP_OKAY)
  50930. return WC_TEST_RET_ENC_EC(ret);
  50931. ret = mp_mod_d(a, 3, &r);
  50932. if (ret != MP_OKAY)
  50933. return WC_TEST_RET_ENC_EC(ret);
  50934. ret = mp_mod_d(a, 5, &r);
  50935. if (ret != MP_OKAY)
  50936. return WC_TEST_RET_ENC_EC(ret);
  50937. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50938. for (i = MP_MAX_TEST_BYTE_LEN - 16; i <= MP_MAX_TEST_BYTE_LEN; i++) {
  50939. ret = randNum(a, i, rng, NULL);
  50940. if (ret != MP_OKAY)
  50941. return WC_TEST_RET_ENC_EC(ret);
  50942. ret = mp_mod_d(a, 3, &r);
  50943. if (ret != MP_OKAY)
  50944. return WC_TEST_RET_ENC_EC(ret);
  50945. ret = mp_div_d(a, 3, a, &rem);
  50946. if (ret != MP_OKAY)
  50947. return WC_TEST_RET_ENC_EC(ret);
  50948. if (r != rem)
  50949. return WC_TEST_RET_ENC_NC;
  50950. }
  50951. #endif
  50952. return 0;
  50953. }
  50954. #endif
  50955. static wc_test_ret_t mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r2,
  50956. WC_RNG* rng)
  50957. {
  50958. wc_test_ret_t ret;
  50959. int i;
  50960. for (i = 1; i < 16; i++) {
  50961. ret = randNum(a, i, rng, NULL);
  50962. if (ret != 0)
  50963. return WC_TEST_RET_ENC_EC(ret);
  50964. ret = mp_mul(a, a, r1);
  50965. if (ret != 0)
  50966. return WC_TEST_RET_ENC_EC(ret);
  50967. ret = mp_sqr(a, r2);
  50968. if (ret != 0)
  50969. return WC_TEST_RET_ENC_EC(ret);
  50970. ret = mp_cmp(r1, r2);
  50971. if (ret != MP_EQ)
  50972. return WC_TEST_RET_ENC_NC;
  50973. }
  50974. ret = mp_set(b, 0);
  50975. if (ret != MP_OKAY)
  50976. return WC_TEST_RET_ENC_EC(ret);
  50977. ret = mp_mul(a, b, r1);
  50978. if (ret != MP_OKAY)
  50979. return WC_TEST_RET_ENC_EC(ret);
  50980. if (!mp_iszero(r1))
  50981. return WC_TEST_RET_ENC_EC(ret);
  50982. ret = mp_sqr(b, r1);
  50983. if (ret != MP_OKAY)
  50984. return WC_TEST_RET_ENC_EC(ret);
  50985. if (!mp_iszero(r1))
  50986. return WC_TEST_RET_ENC_NC;
  50987. #ifdef WOLFSSL_SP_MATH_ALL
  50988. ret = mp_set(a, 1);
  50989. if (ret != MP_OKAY)
  50990. return WC_TEST_RET_ENC_EC(ret);
  50991. i = (SP_INT_DIGITS / 2) + 1;
  50992. ret = mp_mul_2d(a, i * SP_WORD_SIZE - 1, a);
  50993. if (ret != MP_OKAY)
  50994. return WC_TEST_RET_ENC_EC(ret);
  50995. ret = mp_set(b, 1);
  50996. if (ret != MP_OKAY)
  50997. return WC_TEST_RET_ENC_EC(ret);
  50998. ret = mp_mul_2d(b, (SP_INT_DIGITS - 1 - i) * SP_WORD_SIZE - 1, b);
  50999. if (ret != MP_OKAY)
  51000. return WC_TEST_RET_ENC_EC(ret);
  51001. ret = mp_mul(a, b, r1);
  51002. if (ret != MP_OKAY)
  51003. return WC_TEST_RET_ENC_EC(ret);
  51004. ret = mp_mul(a, a, r1);
  51005. if (ret == MP_OKAY)
  51006. return WC_TEST_RET_ENC_NC;
  51007. ret = mp_sqr(a, r1);
  51008. if (ret == MP_OKAY)
  51009. return WC_TEST_RET_ENC_NC;
  51010. ret = mp_sqr(b, r1);
  51011. if (ret != MP_OKAY)
  51012. return WC_TEST_RET_ENC_EC(ret);
  51013. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51014. (defined(HAVE_ECC) && defined(FP_ECC))
  51015. ret = mp_mulmod(a, b, b, r1);
  51016. if (ret != MP_OKAY)
  51017. return WC_TEST_RET_ENC_EC(ret);
  51018. ret = mp_mulmod(a, a, b, r1);
  51019. if (ret == MP_OKAY)
  51020. return WC_TEST_RET_ENC_NC;
  51021. #if defined(HAVE_ECC) && (defined(ECC_SHAMIR) || defined(FP_ECC))
  51022. ret = mp_sqrmod(a, b, r1);
  51023. if (ret == MP_OKAY)
  51024. return WC_TEST_RET_ENC_NC;
  51025. ret = mp_sqrmod(b, a, r1);
  51026. if (ret != MP_OKAY)
  51027. return WC_TEST_RET_ENC_EC(ret);
  51028. #endif /* HAVE_ECC && (ECC_SHAMIR || FP_ECC) */
  51029. #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
  51030. #endif /* WOLFSSL_SP_MATH_ALL */
  51031. return 0;
  51032. }
  51033. #if (!defined(NO_RSA) && \
  51034. !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  51035. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  51036. static wc_test_ret_t mp_test_invmod(mp_int* a, mp_int* m, mp_int* r)
  51037. {
  51038. wc_test_ret_t ret;
  51039. mp_set(a, 0);
  51040. mp_set(m, 1);
  51041. ret = mp_invmod(a, m, r);
  51042. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51043. return WC_TEST_RET_ENC_EC(ret);
  51044. ret = mp_invmod(m, a, r);
  51045. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51046. return WC_TEST_RET_ENC_EC(ret);
  51047. mp_set(a, 2);
  51048. mp_set(m, 4);
  51049. ret = mp_invmod(a, m, r);
  51050. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51051. return WC_TEST_RET_ENC_EC(ret);
  51052. mp_set(a, 3);
  51053. mp_set(m, 6);
  51054. ret = mp_invmod(a, m, r);
  51055. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51056. return WC_TEST_RET_ENC_EC(ret);
  51057. mp_set(a, 5*9);
  51058. mp_set(m, 6*9);
  51059. ret = mp_invmod(a, m, r);
  51060. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51061. return WC_TEST_RET_ENC_EC(ret);
  51062. mp_set(a, 1);
  51063. mp_set(m, 4);
  51064. ret = mp_invmod(a, m, r);
  51065. if (ret != MP_OKAY)
  51066. return WC_TEST_RET_ENC_EC(ret);
  51067. if (!mp_isone(r))
  51068. return WC_TEST_RET_ENC_NC;
  51069. mp_set(a, 3);
  51070. mp_set(m, 4);
  51071. ret = mp_invmod(a, m, r);
  51072. if (ret != MP_OKAY)
  51073. return WC_TEST_RET_ENC_EC(ret);
  51074. ret = mp_cmp_d(r, 3);
  51075. if (ret != 0)
  51076. return WC_TEST_RET_ENC_EC(ret);
  51077. mp_set(a, 3);
  51078. mp_set(m, 5);
  51079. ret = mp_invmod(a, m, r);
  51080. if (ret != MP_OKAY)
  51081. return WC_TEST_RET_ENC_EC(ret);
  51082. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51083. /* Maximum 'a' */
  51084. mp_set(a, 0);
  51085. mp_set_bit(a, (r->size / 2)* SP_WORD_SIZE - 1);
  51086. mp_sub_d(a, 1, a);
  51087. /* Modulus too big. */
  51088. mp_set(m, 0);
  51089. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE);
  51090. ret = mp_invmod(a, m, r);
  51091. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51092. return WC_TEST_RET_ENC_EC(ret);
  51093. /* Maximum modulus - even. */
  51094. mp_set(m, 0);
  51095. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE - 1);
  51096. ret = mp_invmod(a, m, r);
  51097. if (ret != MP_OKAY)
  51098. return WC_TEST_RET_ENC_EC(ret);
  51099. #endif
  51100. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_INT_NEGATIVE)
  51101. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  51102. mp_read_radix(a, "-3", 16);
  51103. ret = mp_invmod(a, m, r);
  51104. if (ret != MP_OKAY)
  51105. return WC_TEST_RET_ENC_EC(ret);
  51106. #endif
  51107. #endif
  51108. #if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC)
  51109. mp_set(a, 0);
  51110. mp_set(m, 3);
  51111. ret = mp_invmod_mont_ct(a, m, r, 1);
  51112. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51113. return WC_TEST_RET_ENC_EC(ret);
  51114. mp_set(a, 1);
  51115. mp_set(m, 0);
  51116. ret = mp_invmod_mont_ct(a, m, r, 1);
  51117. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51118. return WC_TEST_RET_ENC_EC(ret);
  51119. mp_set(a, 1);
  51120. mp_set(m, 1);
  51121. ret = mp_invmod_mont_ct(a, m, r, 1);
  51122. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51123. return WC_TEST_RET_ENC_EC(ret);
  51124. mp_set(a, 1);
  51125. mp_set(m, 2);
  51126. ret = mp_invmod_mont_ct(a, m, r, 1);
  51127. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51128. return WC_TEST_RET_ENC_EC(ret);
  51129. mp_set(a, 1);
  51130. mp_set(m, 3);
  51131. ret = mp_invmod_mont_ct(a, m, r, 1);
  51132. if (ret != MP_OKAY)
  51133. return WC_TEST_RET_ENC_EC(ret);
  51134. #endif
  51135. return 0;
  51136. }
  51137. #endif /* !NO_RSA || HAVE_ECC || !NO_DSA || OPENSSL_EXTRA */
  51138. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51139. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51140. static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r)
  51141. {
  51142. wc_test_ret_t ret;
  51143. mp_set(b, 0x2);
  51144. mp_set(e, 0x3);
  51145. mp_set(m, 0x0);
  51146. ret = mp_exptmod_ex(b, e, 1, m, r);
  51147. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51148. return WC_TEST_RET_ENC_EC(ret);
  51149. ret = mp_exptmod_nct(b, e, m, r);
  51150. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51151. return WC_TEST_RET_ENC_EC(ret);
  51152. mp_set(b, 0x2);
  51153. mp_set(e, 0x3);
  51154. mp_set(m, 0x1);
  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, 0x2);
  51166. mp_set(e, 0x0);
  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. if (!mp_isone(r))
  51172. return WC_TEST_RET_ENC_NC;
  51173. ret = mp_exptmod_nct(b, e, m, r);
  51174. if (ret != MP_OKAY)
  51175. return WC_TEST_RET_ENC_EC(ret);
  51176. if (!mp_isone(r))
  51177. return WC_TEST_RET_ENC_NC;
  51178. mp_set(b, 0x0);
  51179. mp_set(e, 0x3);
  51180. mp_set(m, 0x7);
  51181. ret = mp_exptmod_ex(b, e, 1, m, r);
  51182. if (ret != MP_OKAY)
  51183. return WC_TEST_RET_ENC_EC(ret);
  51184. if (!mp_iszero(r))
  51185. return WC_TEST_RET_ENC_NC;
  51186. ret = mp_exptmod_nct(b, e, m, r);
  51187. if (ret != MP_OKAY)
  51188. return WC_TEST_RET_ENC_EC(ret);
  51189. if (!mp_iszero(r))
  51190. return WC_TEST_RET_ENC_NC;
  51191. mp_set(b, 0x10);
  51192. mp_set(e, 0x3);
  51193. mp_set(m, 0x7);
  51194. ret = mp_exptmod_ex(b, e, 1, m, r);
  51195. if (ret != MP_OKAY)
  51196. return WC_TEST_RET_ENC_EC(ret);
  51197. ret = mp_exptmod_nct(b, e, m, r);
  51198. if (ret != MP_OKAY)
  51199. return WC_TEST_RET_ENC_EC(ret);
  51200. mp_set(b, 0x7);
  51201. mp_set(e, 0x3);
  51202. mp_set(m, 0x7);
  51203. ret = mp_exptmod_ex(b, e, 1, m, r);
  51204. if (ret != MP_OKAY)
  51205. return WC_TEST_RET_ENC_EC(ret);
  51206. if (!mp_iszero(r))
  51207. return WC_TEST_RET_ENC_NC;
  51208. ret = mp_exptmod_nct(b, e, m, r);
  51209. if (ret != MP_OKAY)
  51210. return WC_TEST_RET_ENC_EC(ret);
  51211. if (!mp_iszero(r))
  51212. return WC_TEST_RET_ENC_NC;
  51213. #ifndef WOLFSSL_SP_MATH
  51214. mp_set(b, 0x01);
  51215. mp_mul_2d(b, DIGIT_BIT, b);
  51216. mp_add_d(b, 1, b);
  51217. mp_set(e, 0x3);
  51218. mp_copy(b, m);
  51219. ret = mp_exptmod_ex(b, e, 1, m, r);
  51220. if (ret != MP_OKAY)
  51221. return WC_TEST_RET_ENC_EC(ret);
  51222. if (!mp_iszero(r))
  51223. return WC_TEST_RET_ENC_NC;
  51224. ret = mp_exptmod_nct(b, e, m, r);
  51225. if (ret != MP_OKAY)
  51226. return WC_TEST_RET_ENC_EC(ret);
  51227. if (!mp_iszero(r))
  51228. return WC_TEST_RET_ENC_NC;
  51229. #endif
  51230. mp_set(b, 0x2);
  51231. mp_set(e, 0x3);
  51232. mp_set(m, 0x7);
  51233. ret = mp_exptmod_ex(b, e, 1, m, r);
  51234. if (ret != MP_OKAY)
  51235. return WC_TEST_RET_ENC_EC(ret);
  51236. ret = mp_exptmod_nct(b, e, m, r);
  51237. if (ret != MP_OKAY)
  51238. return WC_TEST_RET_ENC_EC(ret);
  51239. #ifdef WOLFSSL_SP_MATH_ALL
  51240. mp_set(b, 0x2);
  51241. mp_set(e, 0x3);
  51242. mp_set(m, 0x01);
  51243. mp_mul_2d(m, SP_WORD_SIZE * SP_INT_DIGITS / 2, m);
  51244. mp_add_d(m, 0x01, m);
  51245. ret = mp_exptmod_ex(b, e, 1, m, r);
  51246. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51247. return WC_TEST_RET_ENC_EC(ret);
  51248. ret = mp_exptmod_nct(b, e, m, r);
  51249. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51250. return WC_TEST_RET_ENC_EC(ret);
  51251. #endif
  51252. return 0;
  51253. }
  51254. #endif /* !NO_RSA || !NO_DSA || !NO_DH || (HAVE_ECC && HAVE_COMP_KEY) ||
  51255. * OPENSSL_EXTRA */
  51256. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51257. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51258. static wc_test_ret_t mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng)
  51259. {
  51260. wc_test_ret_t ret;
  51261. mp_digit mp;
  51262. static int exp[] = { 7, 8, 16, 27, 32, 64,
  51263. 127, 128, 255, 256,
  51264. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  51265. 383, 384, 2033, 2048
  51266. #endif
  51267. };
  51268. static mp_digit sub[] = { 0x01, 0x05, 0x0f, 0x27, 0x05, 0x3b,
  51269. 0x01, 0x9f, 0x13, 0xbd,
  51270. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  51271. 0x1f, 0x13d, 0x45, 0x615
  51272. #endif
  51273. };
  51274. int bits[] = { 256, 384,
  51275. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 4096
  51276. 2048,
  51277. #endif
  51278. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 6144
  51279. 3072
  51280. #endif
  51281. };
  51282. int i;
  51283. int j;
  51284. for (i = 0; i < (int)(sizeof(exp) / sizeof(*exp)); i++) {
  51285. if (exp[i] >= DIGIT_BIT)
  51286. continue;
  51287. mp_zero(m);
  51288. ret = mp_set_bit(m, exp[i]);
  51289. if (ret != MP_OKAY)
  51290. return WC_TEST_RET_ENC_EC(ret);
  51291. ret = mp_sub_d(m, sub[i], m);
  51292. if (ret != MP_OKAY)
  51293. return WC_TEST_RET_ENC_EC(ret);
  51294. ret = mp_montgomery_setup(m, &mp);
  51295. if (ret != MP_OKAY)
  51296. return WC_TEST_RET_ENC_EC(ret);
  51297. ret = mp_montgomery_calc_normalization(n, m);
  51298. if (ret != MP_OKAY)
  51299. return WC_TEST_RET_ENC_EC(ret);
  51300. for (j = 0; j < 10; j++) {
  51301. ret = randNum(a, (exp[i] + DIGIT_BIT - 1) / DIGIT_BIT, rng, NULL);
  51302. if (ret != 0)
  51303. return WC_TEST_RET_ENC_EC(ret);
  51304. ret = mp_mod(a, m, a);
  51305. if (ret != 0)
  51306. return WC_TEST_RET_ENC_EC(ret);
  51307. /* r = a * a */
  51308. ret = mp_sqrmod(a, m, r);
  51309. if (ret != MP_OKAY)
  51310. return WC_TEST_RET_ENC_EC(ret);
  51311. /* Convert to Montgomery form = a*n */
  51312. ret = mp_mulmod(a, n, m, a);
  51313. if (ret != MP_OKAY)
  51314. return WC_TEST_RET_ENC_EC(ret);
  51315. /* a*a mod m == ((a*n) * (a*n)) / n / n */
  51316. ret = mp_sqr(a, a);
  51317. if (ret != MP_OKAY)
  51318. return WC_TEST_RET_ENC_EC(ret);
  51319. ret = mp_montgomery_reduce(a, m, mp);
  51320. if (ret != MP_OKAY)
  51321. return WC_TEST_RET_ENC_EC(ret);
  51322. ret = mp_montgomery_reduce(a, m, mp);
  51323. if (ret != MP_OKAY)
  51324. return WC_TEST_RET_ENC_EC(ret);
  51325. if (mp_cmp(a, r) != MP_EQ)
  51326. return WC_TEST_RET_ENC_NC;
  51327. }
  51328. }
  51329. /* Force carries. */
  51330. for (i = 0; i < (int)(sizeof(bits) / sizeof(*bits)); i++) {
  51331. /* a = 2^(bits*2) - 1 */
  51332. mp_zero(a);
  51333. mp_set_bit(a, bits[i] * 2);
  51334. ret = mp_sub_d(a, 1, a);
  51335. if (ret != MP_OKAY)
  51336. return WC_TEST_RET_ENC_EC(ret);
  51337. /* m = 2^(bits) - 1 */
  51338. mp_zero(m);
  51339. mp_set_bit(m, bits[i]);
  51340. ret = mp_sub_d(m, 1, m);
  51341. if (ret != MP_OKAY)
  51342. return WC_TEST_RET_ENC_EC(ret);
  51343. mp = 1;
  51344. /* result = r = 2^(bits) - 1 */
  51345. mp_zero(r);
  51346. mp_set_bit(r, bits[i]);
  51347. ret = mp_sub_d(r, 1, r);
  51348. if (ret != MP_OKAY)
  51349. return WC_TEST_RET_ENC_EC(ret);
  51350. ret = mp_montgomery_reduce(a, m, mp);
  51351. if (ret != MP_OKAY)
  51352. return WC_TEST_RET_ENC_EC(ret);
  51353. /* Result is m or 0 if reduced to range of modulus. */
  51354. if (mp_cmp(a, r) != MP_EQ && mp_iszero(a) != MP_YES)
  51355. return WC_TEST_RET_ENC_NC;
  51356. }
  51357. return 0;
  51358. }
  51359. #endif
  51360. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
  51361. {
  51362. WC_RNG rng;
  51363. int rng_inited = 0;
  51364. wc_test_ret_t ret;
  51365. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51366. int i, j;
  51367. #ifndef WOLFSSL_SP_MATH
  51368. int k;
  51369. #endif
  51370. mp_digit d = 0;
  51371. #endif
  51372. #ifdef WOLFSSL_SMALL_STACK
  51373. mp_int *a = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51374. DYNAMIC_TYPE_TMP_BUFFER),
  51375. *b = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51376. DYNAMIC_TYPE_TMP_BUFFER),
  51377. *r1 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51378. DYNAMIC_TYPE_TMP_BUFFER),
  51379. *r2 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51380. DYNAMIC_TYPE_TMP_BUFFER),
  51381. *p = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51382. DYNAMIC_TYPE_TMP_BUFFER);
  51383. if ((a == NULL) ||
  51384. (b == NULL) ||
  51385. (r1 == NULL) ||
  51386. (r2 == NULL) ||
  51387. (p == NULL))
  51388. {
  51389. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  51390. }
  51391. #else
  51392. mp_int a[1], b[1], r1[1], r2[1], p[1];
  51393. #endif
  51394. WOLFSSL_ENTER("mp_test");
  51395. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
  51396. ret = mp_init_multi(a, b, r1, r2, NULL, NULL);
  51397. #else
  51398. ret = mp_init(a);
  51399. ret |= mp_init(b);
  51400. ret |= mp_init(r1);
  51401. ret |= mp_init(r2);
  51402. #endif
  51403. if (ret != 0)
  51404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51405. #ifdef WOLFSSL_SP_MATH_ALL
  51406. mp_init_copy(p, a);
  51407. #else
  51408. ret = mp_init(p);
  51409. if (ret != 0)
  51410. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51411. #endif
  51412. #ifndef HAVE_FIPS
  51413. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  51414. #else
  51415. ret = wc_InitRng(&rng);
  51416. #endif
  51417. if (ret != 0)
  51418. goto done;
  51419. rng_inited = 1;
  51420. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51421. mp_set_int(a, 0);
  51422. if (a->used != 0 || a->dp[0] != 0)
  51423. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51424. for (j = 1; j <= MP_MAX_TEST_BYTE_LEN; j++) {
  51425. for (i = 0; i < 4 * j; i++) {
  51426. /* New values to use. */
  51427. ret = randNum(p, j, &rng, NULL);
  51428. if (ret != 0)
  51429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51430. ret = randNum(a, j, &rng, NULL);
  51431. if (ret != 0)
  51432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51433. ret = randNum(b, j, &rng, NULL);
  51434. if (ret != 0)
  51435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51436. ret = wc_RNG_GenerateBlock(&rng, (byte*)&d, sizeof(d));
  51437. if (ret != 0)
  51438. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51439. d &= MP_MASK;
  51440. #if !defined(WOLFSSL_SP_MATH) || (defined(HAVE_ECC) && \
  51441. (defined(ECC_SHAMIR) || defined(FP_ECC)))
  51442. /* Ensure sqrmod produce same result as mulmod. */
  51443. ret = mp_sqrmod(a, p, r1);
  51444. if (ret != 0)
  51445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51446. ret = mp_mulmod(a, a, p, r2);
  51447. if (ret != 0)
  51448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51449. if (mp_cmp(r1, r2) != 0) {
  51450. WOLFSSL_MSG("Fail: mp_mulmod result does not match mp_sqrmod!");
  51451. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51452. }
  51453. #endif
  51454. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51455. #if defined(WOLFSSL_SP_MATH) || (defined(WOLFSSL_SP_MATH_ALL) && \
  51456. !defined(WOLFSSL_SP_INT_NEGATIVE))
  51457. ret = mp_addmod(a, b, p, r1);
  51458. if (ret != 0)
  51459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51460. ret = mp_submod(r1, b, p, r2);
  51461. if (ret != 0)
  51462. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51463. ret = mp_mod(a, p, r1);
  51464. if (ret != 0)
  51465. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51466. if (mp_cmp(r1, r2) != MP_EQ)
  51467. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51468. #else
  51469. /* Ensure add with mod produce same result as sub with mod. */
  51470. ret = mp_addmod(a, b, p, r1);
  51471. if (ret != 0)
  51472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51473. b->sign ^= 1;
  51474. ret = mp_submod(a, b, p, r2);
  51475. if (ret != 0)
  51476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51477. if (mp_cmp(r1, r2) != 0)
  51478. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51479. #endif
  51480. #endif
  51481. /* Ensure add digit produce same result as sub digit. */
  51482. ret = mp_add_d(a, d, r1);
  51483. if (ret != 0)
  51484. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51485. ret = mp_sub_d(r1, d, r2);
  51486. if (ret != 0)
  51487. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51488. if (mp_cmp(a, r2) != 0)
  51489. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51490. /* Invert - if p is even it will use the slow impl.
  51491. * - if p and a are even it will fail.
  51492. */
  51493. ret = mp_invmod(a, p, r1);
  51494. if (ret != 0 && ret != WC_NO_ERR_TRACE(MP_VAL))
  51495. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51496. #ifndef WOLFSSL_SP_MATH
  51497. /* Shift up and down number all bits in a digit. */
  51498. for (k = 0; k < DIGIT_BIT; k++) {
  51499. mp_mul_2d(a, k, r1);
  51500. mp_div_2d(r1, k, r2, p);
  51501. if (mp_cmp(a, r2) != 0)
  51502. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51503. if (!mp_iszero(p))
  51504. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51505. mp_rshb(r1, k);
  51506. if (mp_cmp(a, r1) != 0)
  51507. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51508. }
  51509. #endif
  51510. }
  51511. }
  51512. /* Test adding and subtracting zero from zero. */
  51513. mp_zero(a);
  51514. ret = mp_add_d(a, 0, r1);
  51515. if (ret != 0)
  51516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51517. if (!mp_iszero(r1)) {
  51518. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51519. }
  51520. ret = mp_sub_d(a, 0, r2);
  51521. if (ret != 0)
  51522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51523. if (!mp_iszero(r2)) {
  51524. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51525. }
  51526. #if DIGIT_BIT >= 32
  51527. /* Check that setting a 32-bit digit works. */
  51528. d &= 0xffffffffU;
  51529. mp_set_int(a, d);
  51530. if (a->used != 1 || a->dp[0] != d)
  51531. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51532. #endif
  51533. /* Check setting a bit and testing a bit works. */
  51534. for (i = 0; i < MP_MAX_TEST_BYTE_LEN * 8; i++) {
  51535. mp_zero(a);
  51536. mp_set_bit(a, i);
  51537. if (!mp_is_bit_set(a, i))
  51538. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51539. }
  51540. #endif
  51541. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  51542. mp_zero(a);
  51543. i = mp_cnt_lsb(a);
  51544. if (i != 0)
  51545. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51546. mp_set(a, 1);
  51547. i = mp_cnt_lsb(a);
  51548. if (i != 0)
  51549. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51550. mp_set(a, 32);
  51551. i = mp_cnt_lsb(a);
  51552. if (i != 5)
  51553. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51554. mp_zero(a);
  51555. mp_set_bit(a, 129);
  51556. i = mp_cnt_lsb(a);
  51557. if (i != 129)
  51558. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51559. #endif
  51560. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51561. if ((ret = mp_test_param(a, b, r1, &rng)) != 0)
  51562. goto done;
  51563. #endif
  51564. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  51565. if ((ret = mp_test_div_3(a, r1, &rng)) != 0)
  51566. goto done;
  51567. #endif
  51568. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  51569. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  51570. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  51571. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  51572. if ((ret = mp_test_radix_10(a, r1, &rng)) != 0)
  51573. goto done;
  51574. #endif
  51575. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  51576. defined(HAVE_ECC))
  51577. if ((ret = mp_test_radix_16(a, r1, &rng)) != 0)
  51578. goto done;
  51579. #endif
  51580. if ((ret = mp_test_shift(a, r1, &rng)) != 0)
  51581. goto done;
  51582. if ((ret = mp_test_add_sub_d(a, r1)) != 0)
  51583. goto done;
  51584. if ((ret = mp_test_read_to_bin(a)) != 0)
  51585. goto done;
  51586. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51587. if ((ret = mp_test_set_int(a)) != 0)
  51588. goto done;
  51589. #endif
  51590. if ((ret = mp_test_cmp(a, r1)) != 0)
  51591. goto done;
  51592. #if !defined(NO_DH) || defined(HAVE_ECC) || (!defined(NO_RSA) && \
  51593. !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  51594. if ((ret = mp_test_shbd(a, b, &rng)) != 0)
  51595. goto done;
  51596. #endif
  51597. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51598. if ((ret = mp_test_set_is_bit(a)) != 0)
  51599. goto done;
  51600. #endif
  51601. #if !defined(NO_DH) || defined(HAVE_ECC) || \
  51602. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  51603. if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0)
  51604. goto done;
  51605. #endif
  51606. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  51607. !defined(WC_NO_RNG)
  51608. if ((ret = mp_test_prime(a, &rng)) != 0)
  51609. goto done;
  51610. #endif
  51611. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  51612. if ((ret = mp_test_lcm_gcd(a, b, r1, r2, &rng)) != 0)
  51613. goto done;
  51614. #endif
  51615. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  51616. defined(WOLFSSL_SP_MATH_ALL)
  51617. if ((ret = mp_test_mod_2d(a, r1, p, &rng)) != 0)
  51618. goto done;
  51619. #endif
  51620. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  51621. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  51622. if ((ret = mp_test_mod_d(a, &rng)) != 0)
  51623. goto done;
  51624. #endif
  51625. if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0)
  51626. goto done;
  51627. #if (!defined(NO_RSA) && \
  51628. !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  51629. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  51630. if ((ret = mp_test_invmod(a, b, r1)) != 0)
  51631. goto done;
  51632. #endif
  51633. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51634. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51635. if ((ret = mp_test_exptmod(a, b, r1, r2)) != 0)
  51636. goto done;
  51637. #endif
  51638. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51639. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51640. if ((ret = mp_test_mont(a, b, r1, r2, &rng)) != 0)
  51641. goto done;
  51642. #endif
  51643. done:
  51644. #ifdef WOLFSSL_SMALL_STACK
  51645. if (p) {
  51646. mp_clear(p);
  51647. XFREE(p, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51648. }
  51649. if (r2) {
  51650. mp_clear(r2);
  51651. XFREE(r2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51652. }
  51653. if (r1) {
  51654. mp_clear(r1);
  51655. XFREE(r1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51656. }
  51657. if (b) {
  51658. mp_clear(b);
  51659. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51660. }
  51661. if (a) {
  51662. mp_clear(a);
  51663. XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51664. }
  51665. #else
  51666. mp_clear(p);
  51667. mp_clear(r2);
  51668. mp_clear(r1);
  51669. mp_clear(b);
  51670. mp_clear(a);
  51671. #endif
  51672. if (rng_inited)
  51673. wc_FreeRng(&rng);
  51674. return ret;
  51675. }
  51676. #endif /* WOLFSSL_PUBLIC_MP && ((WOLFSSL_SP_MATH_ALL &&
  51677. * !WOLFSSL_RSA_VERIFY_ONLY) || USE_FAST_MATH) */
  51678. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  51679. typedef struct pairs_t {
  51680. const unsigned char* coeff;
  51681. int coeffSz;
  51682. int exp;
  51683. } pairs_t;
  51684. /*
  51685. n =p1p2p3, where pi = ki(p1-1)+1 with (k2,k3) = (173,293)
  51686. p1 = 2^192 * 0x000000000000e24fd4f6d6363200bf2323ec46285cac1d3a
  51687. + 2^0 * 0x0b2488b0c29d96c5e67f8bec15b54b189ae5636efe89b45b
  51688. */
  51689. static const unsigned char c192a[] =
  51690. {
  51691. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x4f,
  51692. 0xd4, 0xf6, 0xd6, 0x36, 0x32, 0x00, 0xbf, 0x23,
  51693. 0x23, 0xec, 0x46, 0x28, 0x5c, 0xac, 0x1d, 0x3a
  51694. };
  51695. static const unsigned char c0a[] =
  51696. {
  51697. 0x0b, 0x24, 0x88, 0xb0, 0xc2, 0x9d, 0x96, 0xc5,
  51698. 0xe6, 0x7f, 0x8b, 0xec, 0x15, 0xb5, 0x4b, 0x18,
  51699. 0x9a, 0xe5, 0x63, 0x6e, 0xfe, 0x89, 0xb4, 0x5b
  51700. };
  51701. static const pairs_t ecPairsA[] =
  51702. {
  51703. {c192a, sizeof(c192a), 192},
  51704. {c0a, sizeof(c0a), 0}
  51705. };
  51706. static const int kA[] = {173, 293};
  51707. static const unsigned char controlPrime[] = {
  51708. 0xe1, 0x76, 0x45, 0x80, 0x59, 0xb6, 0xd3, 0x49,
  51709. 0xdf, 0x0a, 0xef, 0x12, 0xd6, 0x0f, 0xf0, 0xb7,
  51710. 0xcb, 0x2a, 0x37, 0xbf, 0xa7, 0xf8, 0xb5, 0x4d,
  51711. 0xf5, 0x31, 0x35, 0xad, 0xe4, 0xa3, 0x94, 0xa1,
  51712. 0xdb, 0xf1, 0x96, 0xad, 0xb5, 0x05, 0x64, 0x85,
  51713. 0x83, 0xfc, 0x1b, 0x5b, 0x29, 0xaa, 0xbe, 0xf8,
  51714. 0x26, 0x3f, 0x76, 0x7e, 0xad, 0x1c, 0xf0, 0xcb,
  51715. 0xd7, 0x26, 0xb4, 0x1b, 0x05, 0x8e, 0x56, 0x86,
  51716. 0x7e, 0x08, 0x62, 0x21, 0xc1, 0x86, 0xd6, 0x47,
  51717. 0x79, 0x3e, 0xb7, 0x5d, 0xa4, 0xc6, 0x3a, 0xd7,
  51718. 0xb1, 0x74, 0x20, 0xf6, 0x50, 0x97, 0x41, 0x04,
  51719. 0x53, 0xed, 0x3f, 0x26, 0xd6, 0x6f, 0x91, 0xfa,
  51720. 0x68, 0x26, 0xec, 0x2a, 0xdc, 0x9a, 0xf1, 0xe7,
  51721. 0xdc, 0xfb, 0x73, 0xf0, 0x79, 0x43, 0x1b, 0x21,
  51722. 0xa3, 0x59, 0x04, 0x63, 0x52, 0x07, 0xc9, 0xd7,
  51723. 0xe6, 0xd1, 0x1b, 0x5d, 0x5e, 0x96, 0xfa, 0x53
  51724. };
  51725. static const unsigned char testOne[] = { 1 };
  51726. static wc_test_ret_t GenerateNextP(mp_int* p1, mp_int* p2, int k)
  51727. {
  51728. wc_test_ret_t ret;
  51729. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51730. mp_int *ki = (mp_int *)XMALLOC(sizeof(*ki), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51731. if (ki == NULL)
  51732. return MEMORY_E;
  51733. #else
  51734. mp_int ki[1];
  51735. #endif
  51736. ret = mp_init(ki);
  51737. if (ret != 0)
  51738. ret = WC_TEST_RET_ENC_EC(ret);
  51739. if (ret == 0) {
  51740. ret = mp_set(ki, (mp_digit)k);
  51741. if (ret != 0)
  51742. ret = WC_TEST_RET_ENC_EC(ret);
  51743. }
  51744. if (ret == 0) {
  51745. ret = mp_sub_d(p1, 1, p2);
  51746. if (ret != 0)
  51747. ret = WC_TEST_RET_ENC_EC(ret);
  51748. }
  51749. if (ret == 0) {
  51750. ret = mp_mul(p2, ki, p2);
  51751. if (ret != 0)
  51752. ret = WC_TEST_RET_ENC_EC(ret);
  51753. }
  51754. if (ret == 0) {
  51755. ret = mp_add_d(p2, 1, p2);
  51756. if (ret != 0)
  51757. ret = WC_TEST_RET_ENC_EC(ret);
  51758. }
  51759. mp_clear(ki);
  51760. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51761. XFREE(ki, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51762. #endif
  51763. return ret;
  51764. }
  51765. static wc_test_ret_t GenerateP(mp_int* p1, mp_int* p2, mp_int* p3,
  51766. const pairs_t* ecPairs, int ecPairsSz,
  51767. const int* k)
  51768. {
  51769. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51770. mp_int *x = NULL, *y = NULL;
  51771. #else
  51772. mp_int x[1], y[1];
  51773. #endif
  51774. wc_test_ret_t ret;
  51775. int i;
  51776. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51777. if (((x = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) ||
  51778. ((y = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)) {
  51779. ret = MEMORY_E;
  51780. goto out;
  51781. }
  51782. #endif
  51783. ret = mp_init_multi(x, y, NULL, NULL, NULL, NULL);
  51784. if (ret != 0) {
  51785. ret = WC_TEST_RET_ENC_EC(ret);
  51786. goto out;
  51787. }
  51788. for (i = 0; ret == 0 && i < ecPairsSz; i++) {
  51789. ret = mp_read_unsigned_bin(x, ecPairs[i].coeff, (word32)ecPairs[i].coeffSz);
  51790. if (ret != 0) {
  51791. ret = WC_TEST_RET_ENC_EC(ret);
  51792. break;
  51793. }
  51794. /* p1 = 2^exp */
  51795. ret = mp_2expt(y, ecPairs[i].exp);
  51796. if (ret != 0) {
  51797. ret = WC_TEST_RET_ENC_EC(ret);
  51798. break;
  51799. }
  51800. /* p1 = p1 * m */
  51801. ret = mp_mul(x, y, x);
  51802. if (ret != 0) {
  51803. ret = WC_TEST_RET_ENC_EC(ret);
  51804. break;
  51805. }
  51806. /* p1 += */
  51807. ret = mp_add(p1, x, p1);
  51808. if (ret != 0) {
  51809. ret = WC_TEST_RET_ENC_EC(ret);
  51810. break;
  51811. }
  51812. mp_zero(x);
  51813. mp_zero(y);
  51814. }
  51815. if (ret == 0)
  51816. ret = GenerateNextP(p1, p2, k[0]);
  51817. if (ret == 0)
  51818. ret = GenerateNextP(p1, p3, k[1]);
  51819. out:
  51820. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51821. if (x != NULL) {
  51822. mp_clear(x);
  51823. XFREE(x, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51824. }
  51825. if (y != NULL) {
  51826. mp_clear(y);
  51827. XFREE(y, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51828. }
  51829. #else
  51830. mp_clear(x);
  51831. mp_clear(y);
  51832. #endif
  51833. return ret;
  51834. }
  51835. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void)
  51836. {
  51837. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51838. mp_int *n = (mp_int *)XMALLOC(sizeof *n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51839. *p1 = (mp_int *)XMALLOC(sizeof *p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51840. *p2 = (mp_int *)XMALLOC(sizeof *p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51841. *p3 = (mp_int *)XMALLOC(sizeof *p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51842. #else
  51843. mp_int n[1],
  51844. p1[1],
  51845. p2[1],
  51846. p3[1];
  51847. #endif
  51848. wc_test_ret_t ret;
  51849. int isPrime = 0;
  51850. WC_RNG rng;
  51851. WOLFSSL_ENTER("prime_test");
  51852. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51853. if ((n == NULL) ||
  51854. (p1 == NULL) ||
  51855. (p2 == NULL) ||
  51856. (p3 == NULL))
  51857. ERROR_OUT(MEMORY_E, out);
  51858. #endif
  51859. ret = wc_InitRng(&rng);
  51860. if (ret != 0)
  51861. ret = WC_TEST_RET_ENC_EC(ret);
  51862. if (ret == 0) {
  51863. ret = mp_init_multi(n, p1, p2, p3, NULL, NULL);
  51864. if (ret != 0)
  51865. ret = WC_TEST_RET_ENC_EC(ret);
  51866. }
  51867. if (ret == 0)
  51868. ret = GenerateP(p1, p2, p3,
  51869. ecPairsA, sizeof(ecPairsA) / sizeof(ecPairsA[0]), kA);
  51870. if (ret == 0) {
  51871. ret = mp_mul(p1, p2, n);
  51872. if (ret != 0)
  51873. ret = WC_TEST_RET_ENC_EC(ret);
  51874. }
  51875. if (ret == 0) {
  51876. ret = mp_mul(n, p3, n);
  51877. if (ret != 0)
  51878. ret = WC_TEST_RET_ENC_EC(ret);
  51879. }
  51880. if (ret != 0)
  51881. ERROR_OUT(ret, out);
  51882. /* Check the old prime test using the number that false positives.
  51883. * This test result should indicate as not prime. */
  51884. ret = mp_prime_is_prime(n, 40, &isPrime);
  51885. if (ret != 0)
  51886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51887. if (isPrime)
  51888. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51889. /* This test result should fail. It should indicate the value as prime. */
  51890. ret = mp_prime_is_prime(n, 8, &isPrime);
  51891. if (ret != 0)
  51892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51893. if (!isPrime)
  51894. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51895. /* This test result should indicate the value as not prime. */
  51896. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51897. if (ret != 0)
  51898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51899. if (isPrime)
  51900. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51901. ret = mp_read_unsigned_bin(n, controlPrime, sizeof(controlPrime));
  51902. if (ret != 0)
  51903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51904. /* This test result should indicate the value as prime. */
  51905. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51906. if (ret != 0)
  51907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51908. if (!isPrime)
  51909. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51910. /* This test result should indicate the value as prime. */
  51911. isPrime = -1;
  51912. ret = mp_prime_is_prime(n, 8, &isPrime);
  51913. if (ret != 0)
  51914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51915. if (!isPrime)
  51916. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51917. ret = mp_read_unsigned_bin(n, testOne, sizeof(testOne));
  51918. if (ret != 0)
  51919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51920. /* This test result should indicate the value as not prime. */
  51921. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51922. if (ret != 0)
  51923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51924. if (isPrime)
  51925. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51926. ret = mp_prime_is_prime(n, 8, &isPrime);
  51927. if (ret != 0)
  51928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51929. if (isPrime)
  51930. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51931. ret = 0;
  51932. out:
  51933. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51934. if (n != NULL) {
  51935. mp_clear(n);
  51936. XFREE(n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51937. }
  51938. if (p1 != NULL) {
  51939. mp_clear(p1);
  51940. XFREE(p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51941. }
  51942. if (p2 != NULL) {
  51943. mp_clear(p2);
  51944. XFREE(p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51945. }
  51946. if (p3 != NULL) {
  51947. mp_clear(p3);
  51948. XFREE(p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51949. }
  51950. #else
  51951. mp_clear(p3);
  51952. mp_clear(p2);
  51953. mp_clear(p1);
  51954. mp_clear(n);
  51955. #endif
  51956. wc_FreeRng(&rng);
  51957. return ret;
  51958. }
  51959. #endif /* WOLFSSL_PUBLIC_MP */
  51960. #if defined(ASN_BER_TO_DER) && \
  51961. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  51962. defined(OPENSSL_EXTRA_X509_SMALL))
  51963. /* wc_BerToDer is only public facing in the case of test cert or opensslextra */
  51964. typedef struct berDerTestData {
  51965. const byte *in;
  51966. word32 inSz;
  51967. const byte *out;
  51968. word32 outSz;
  51969. } berDerTestData;
  51970. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void)
  51971. {
  51972. wc_test_ret_t ret;
  51973. int i;
  51974. word32 len = 0, l;
  51975. byte out[32];
  51976. WOLFSSL_SMALL_STACK_STATIC const byte good1_in[] = { 0x30, 0x80, 0x00, 0x00 };
  51977. WOLFSSL_SMALL_STACK_STATIC const byte good1_out[] = { 0x30, 0x00 };
  51978. WOLFSSL_SMALL_STACK_STATIC const byte good2_in[] = { 0x30, 0x80, 0x02, 0x01, 0x01, 0x00, 0x00 };
  51979. WOLFSSL_SMALL_STACK_STATIC const byte good2_out[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51980. WOLFSSL_SMALL_STACK_STATIC const byte good3_in[] = {
  51981. 0x24, 0x80, 0x04, 0x01, 0x01, 0x00, 0x00
  51982. };
  51983. WOLFSSL_SMALL_STACK_STATIC const byte good3_out[] = { 0x04, 0x1, 0x01 };
  51984. WOLFSSL_SMALL_STACK_STATIC const byte good4_in[] = {
  51985. 0x30, 0x80,
  51986. 0x02, 0x01, 0x01,
  51987. 0x30, 0x80,
  51988. 0x24, 0x80,
  51989. 0x04, 0x01, 0x01,
  51990. 0x04, 0x02, 0x02, 0x03,
  51991. 0x00, 0x00,
  51992. 0x06, 0x01, 0x01,
  51993. 0x00, 0x00,
  51994. 0x31, 0x80,
  51995. 0x06, 0x01, 0x01,
  51996. 0x00, 0x00,
  51997. 0x00, 0x00,
  51998. };
  51999. WOLFSSL_SMALL_STACK_STATIC const byte good4_out[] = {
  52000. 0x30, 0x12,
  52001. 0x02, 0x01, 0x01,
  52002. 0x30, 0x08,
  52003. 0x04, 0x03, 0x01, 0x02, 0x03,
  52004. 0x06, 0x01, 0x01,
  52005. 0x31, 0x03,
  52006. 0x06, 0x01, 0x01
  52007. };
  52008. WOLFSSL_SMALL_STACK_STATIC const byte good5_in[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  52009. berDerTestData testData[] = {
  52010. { good1_in, sizeof(good1_in), good1_out, sizeof(good1_out) },
  52011. { good2_in, sizeof(good2_in), good2_out, sizeof(good2_out) },
  52012. { good3_in, sizeof(good3_in), good3_out, sizeof(good3_out) },
  52013. { good4_in, sizeof(good4_in), good4_out, sizeof(good4_out) },
  52014. { good5_in, sizeof(good5_in), good5_in , sizeof(good5_in ) },
  52015. };
  52016. WOLFSSL_ENTER("berder_test");
  52017. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  52018. ret = wc_BerToDer(testData[i].in, testData[i].inSz, NULL, &len);
  52019. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  52020. return WC_TEST_RET_ENC_I(i);
  52021. if (len != testData[i].outSz)
  52022. return WC_TEST_RET_ENC_I(i);
  52023. len = testData[i].outSz;
  52024. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &len);
  52025. if (ret != 0)
  52026. return WC_TEST_RET_ENC_I(i);
  52027. if (XMEMCMP(out, testData[i].out, len) != 0)
  52028. return WC_TEST_RET_ENC_I(i);
  52029. for (l = 1; l < testData[i].inSz; l++) {
  52030. ret = wc_BerToDer(testData[i].in, l, NULL, &len);
  52031. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  52032. return WC_TEST_RET_ENC_EC(ret);
  52033. len = testData[i].outSz;
  52034. ret = wc_BerToDer(testData[i].in, l, out, &len);
  52035. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  52036. return WC_TEST_RET_ENC_EC(ret);
  52037. }
  52038. for (l = 0; l < testData[i].outSz-1; l++) {
  52039. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &l);
  52040. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  52041. return WC_TEST_RET_ENC_EC(ret);
  52042. }
  52043. }
  52044. ret = wc_BerToDer(NULL, 4, NULL, NULL);
  52045. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52046. return WC_TEST_RET_ENC_EC(ret);
  52047. ret = wc_BerToDer(out, 4, NULL, NULL);
  52048. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52049. return WC_TEST_RET_ENC_EC(ret);
  52050. ret = wc_BerToDer(NULL, 4, NULL, &len);
  52051. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52052. return WC_TEST_RET_ENC_EC(ret);
  52053. ret = wc_BerToDer(NULL, 4, out, NULL);
  52054. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52055. return WC_TEST_RET_ENC_EC(ret);
  52056. ret = wc_BerToDer(out, 4, out, NULL);
  52057. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52058. return WC_TEST_RET_ENC_EC(ret);
  52059. ret = wc_BerToDer(NULL, 4, out, &len);
  52060. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52061. return WC_TEST_RET_ENC_EC(ret);
  52062. for (l = 1; l < sizeof(good4_out); l++) {
  52063. len = l;
  52064. ret = wc_BerToDer(good4_in, sizeof(good4_in), out, &len);
  52065. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  52066. return WC_TEST_RET_ENC_EC(ret);
  52067. }
  52068. return 0;
  52069. }
  52070. #endif /* ASN_BER_TO_DER && (WOLFSSL_TEST_CERT || OPENSSL_EXTRA ||
  52071. OPENSSL_EXTRA_X509_SMALL */
  52072. #ifdef DEBUG_WOLFSSL
  52073. static THREAD_LS_T int log_cnt = 0;
  52074. static void my_Logging_cb(const int logLevel, const char *const logMessage)
  52075. {
  52076. (void)logLevel;
  52077. (void)logMessage;
  52078. log_cnt++;
  52079. }
  52080. #endif /* DEBUG_WOLFSSL */
  52081. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void)
  52082. {
  52083. wc_test_ret_t ret;
  52084. #ifdef DEBUG_WOLFSSL
  52085. const char* msg = "Testing, testing. 1, 2, 3, 4 ...";
  52086. byte a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  52087. byte b[256];
  52088. int i;
  52089. WOLFSSL_ENTER("logging_test (debug)");
  52090. for (i = 0; i < (int)sizeof(b); i++)
  52091. b[i] = i;
  52092. ret = wolfSSL_Debugging_ON();
  52093. if (ret != 0)
  52094. return WC_TEST_RET_ENC_EC(ret);
  52095. ret = wolfSSL_SetLoggingCb(my_Logging_cb);
  52096. if (ret != 0)
  52097. return WC_TEST_RET_ENC_EC(ret);
  52098. WOLFSSL_MSG(msg);
  52099. WOLFSSL_BUFFER(a, sizeof(a));
  52100. WOLFSSL_BUFFER(b, sizeof(b));
  52101. WOLFSSL_BUFFER(NULL, 0);
  52102. WOLFSSL_ERROR(MEMORY_E);
  52103. WOLFSSL_ERROR_MSG(msg);
  52104. /* turn off logs */
  52105. wolfSSL_Debugging_OFF();
  52106. /* capture log count */
  52107. i = log_cnt;
  52108. /* validate no logs are output when disabled */
  52109. WOLFSSL_MSG(msg);
  52110. WOLFSSL_BUFFER(a, sizeof(a));
  52111. WOLFSSL_BUFFER(b, sizeof(b));
  52112. WOLFSSL_BUFFER(NULL, 0);
  52113. WOLFSSL_ERROR(MEMORY_E);
  52114. WOLFSSL_ERROR_MSG(msg);
  52115. /* check the logs were disabled */
  52116. if (i != log_cnt)
  52117. return WC_TEST_RET_ENC_NC;
  52118. /* restore callback and leave logging enabled */
  52119. wolfSSL_SetLoggingCb(NULL);
  52120. wolfSSL_Debugging_ON();
  52121. /* suppress unused args */
  52122. (void)a;
  52123. (void)b;
  52124. #else
  52125. WOLFSSL_ENTER("logging_test");
  52126. ret = wolfSSL_Debugging_ON();
  52127. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  52128. return WC_TEST_RET_ENC_EC(ret);
  52129. wolfSSL_Debugging_OFF();
  52130. ret = wolfSSL_SetLoggingCb(NULL);
  52131. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  52132. return WC_TEST_RET_ENC_EC(ret);
  52133. #endif /* DEBUG_WOLFSSL */
  52134. return 0;
  52135. }
  52136. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  52137. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void)
  52138. #else
  52139. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void)
  52140. #endif
  52141. {
  52142. #ifdef WOLFSSL_PTHREADS
  52143. wolfSSL_Mutex m;
  52144. #endif
  52145. #if defined(WOLFSSL_PTHREADS) || (!defined(WOLFSSL_NO_MALLOC) && \
  52146. !defined(WOLFSSL_USER_MUTEX) && defined(WOLFSSL_STATIC_MEMORY))
  52147. wc_test_ret_t ret;
  52148. #endif
  52149. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_USER_MUTEX)
  52150. #ifndef WOLFSSL_STATIC_MEMORY
  52151. wolfSSL_Mutex *mm = wc_InitAndAllocMutex();
  52152. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (1)");
  52153. #else
  52154. wolfSSL_Mutex *mm = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex),
  52155. HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52156. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (2)");
  52157. if (mm != NULL) {
  52158. ret = wc_InitMutex(mm);
  52159. if (ret != 0) {
  52160. WOLFSSL_MSG("Init Mutex failed");
  52161. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52162. return WC_TEST_RET_ENC_EC(ret);
  52163. }
  52164. }
  52165. #endif
  52166. if (mm == NULL)
  52167. return WC_TEST_RET_ENC_ERRNO;
  52168. wc_FreeMutex(mm);
  52169. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52170. #endif
  52171. /* Can optionally enable advanced pthread tests using "ENABLE_PTHREAD_LOCKFREE_TESTS" */
  52172. #ifdef WOLFSSL_PTHREADS
  52173. ret = wc_InitMutex(&m);
  52174. if (ret != 0)
  52175. return WC_TEST_RET_ENC_EC(ret);
  52176. ret = wc_LockMutex(&m);
  52177. if (ret != 0)
  52178. return WC_TEST_RET_ENC_EC(ret);
  52179. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  52180. /* trying to free a locked mutex is not portable behavior with pthread */
  52181. /* Attempting to destroy a locked mutex results in undefined behavior */
  52182. ret = wc_FreeMutex(&m);
  52183. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52184. return WC_TEST_RET_ENC_EC(ret);
  52185. #endif
  52186. ret = wc_UnLockMutex(&m);
  52187. if (ret != 0)
  52188. return WC_TEST_RET_ENC_EC(ret);
  52189. ret = wc_FreeMutex(&m);
  52190. if (ret != 0)
  52191. return WC_TEST_RET_ENC_EC(ret);
  52192. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  52193. /* Trying to use a pthread after free'ing is not portable behavior */
  52194. ret = wc_LockMutex(&m);
  52195. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52196. return WC_TEST_RET_ENC_EC(ret);
  52197. ret = wc_UnLockMutex(&m);
  52198. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52199. return WC_TEST_RET_ENC_EC(ret);
  52200. #endif
  52201. #endif
  52202. return 0;
  52203. }
  52204. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  52205. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \
  52206. !defined(WOLFSSL_STATIC_MEMORY)
  52207. static wc_test_ret_t malloc_cnt = 0;
  52208. static wc_test_ret_t realloc_cnt = 0;
  52209. static wc_test_ret_t free_cnt = 0;
  52210. #ifdef WOLFSSL_DEBUG_MEMORY
  52211. static void *my_Malloc_cb(size_t size, const char* func, unsigned int line)
  52212. {
  52213. (void) func;
  52214. (void) line;
  52215. #else
  52216. static void *my_Malloc_cb(size_t size)
  52217. {
  52218. #endif
  52219. malloc_cnt++;
  52220. #ifndef WOLFSSL_NO_MALLOC
  52221. return malloc(size); /* native heap */
  52222. #else
  52223. WOLFSSL_MSG("No malloc available");
  52224. (void)size;
  52225. return NULL;
  52226. #endif
  52227. }
  52228. #ifdef WOLFSSL_DEBUG_MEMORY
  52229. static void my_Free_cb(void *ptr, const char* func, unsigned int line)
  52230. {
  52231. (void) func;
  52232. (void) line;
  52233. #else
  52234. static void my_Free_cb(void *ptr)
  52235. {
  52236. #endif
  52237. free_cnt++;
  52238. #ifndef WOLFSSL_NO_MALLOC
  52239. free(ptr); /* native heap */
  52240. #else
  52241. WOLFSSL_MSG("No free available");
  52242. (void)ptr;
  52243. #endif
  52244. }
  52245. #ifdef WOLFSSL_DEBUG_MEMORY
  52246. static void *my_Realloc_cb(void *ptr, size_t size, const char* func, unsigned int line)
  52247. {
  52248. (void) func;
  52249. (void) line;
  52250. #else
  52251. static void *my_Realloc_cb(void *ptr, size_t size)
  52252. {
  52253. #endif
  52254. realloc_cnt++;
  52255. #ifndef WOLFSSL_NO_MALLOC
  52256. return realloc(ptr, size); /* native heap */
  52257. #else
  52258. WOLFSSL_MSG("No realloc available");
  52259. (void)ptr;
  52260. (void)size;
  52261. return NULL;
  52262. #endif
  52263. }
  52264. #endif /* !WOLFSSL_NO_MALLOC */
  52265. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void)
  52266. {
  52267. wc_test_ret_t ret = 0;
  52268. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52269. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52270. byte* b = NULL;
  52271. #endif
  52272. wolfSSL_Malloc_cb mc;
  52273. wolfSSL_Free_cb fc;
  52274. wolfSSL_Realloc_cb rc;
  52275. WOLFSSL_ENTER("memcb_test");
  52276. /* Save existing memory callbacks */
  52277. ret = wolfSSL_GetAllocators(&mc, &fc, &rc);
  52278. if (ret != 0)
  52279. return WC_TEST_RET_ENC_EC(ret);
  52280. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52281. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52282. /* test realloc */
  52283. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52284. if (b == NULL) {
  52285. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_memcb);
  52286. }
  52287. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52288. b = NULL;
  52289. /* Use API. */
  52290. ret = wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb,
  52291. (wolfSSL_Free_cb)my_Free_cb,
  52292. (wolfSSL_Realloc_cb)my_Realloc_cb);
  52293. if (ret != 0) {
  52294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_memcb);
  52295. }
  52296. b = (byte*)XMALLOC(1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52297. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52298. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52299. #ifndef WOLFSSL_STATIC_MEMORY
  52300. #ifndef WOLFSSL_CHECK_MEM_ZERO
  52301. if (malloc_cnt != 1 || free_cnt != 1 || realloc_cnt != 1)
  52302. #else
  52303. /* Checking zeroized memory means realloc is a malloc and free. */
  52304. if (malloc_cnt != 2 || free_cnt != 2 || realloc_cnt != 0)
  52305. #endif
  52306. #else
  52307. if (malloc_cnt != 0 || free_cnt != 0 || realloc_cnt != 0)
  52308. #endif
  52309. ret = WC_TEST_RET_ENC_NC;
  52310. #endif /* !WOLFSSL_NO_MALLOC */
  52311. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52312. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52313. exit_memcb:
  52314. /* reset malloc/free/realloc counts */
  52315. malloc_cnt = 0;
  52316. free_cnt = 0;
  52317. realloc_cnt = 0;
  52318. #endif
  52319. /* restore memory callbacks */
  52320. wolfSSL_SetAllocators(mc, fc, rc);
  52321. return ret;
  52322. }
  52323. #endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_NO_MALLOC */
  52324. #if defined(WOLFSSL_CAAM_BLOB)
  52325. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void)
  52326. {
  52327. wc_test_ret_t ret = 0;
  52328. byte out[112];
  52329. byte blob[112];
  52330. word32 outSz;
  52331. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  52332. {
  52333. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  52334. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  52335. };
  52336. WOLFSSL_SMALL_STACK_STATIC const byte text[] =
  52337. {
  52338. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  52339. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  52340. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  52341. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  52342. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  52343. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  52344. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  52345. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  52346. };
  52347. WOLFSSL_ENTER("blob_test");
  52348. XMEMSET(blob, 0, sizeof(blob));
  52349. XMEMSET(out, 0, sizeof(out));
  52350. outSz = sizeof(blob);
  52351. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  52352. if (ret != 0)
  52353. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52354. blob[outSz - 2] += 1;
  52355. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52356. if (ret == 0) { /* should fail with altered blob */
  52357. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52358. }
  52359. XMEMSET(blob, 0, sizeof(blob));
  52360. outSz = sizeof(blob);
  52361. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  52362. if (ret != 0)
  52363. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52364. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52365. if (ret != 0)
  52366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52367. if (XMEMCMP(out, iv, sizeof(iv))) {
  52368. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52369. }
  52370. XMEMSET(blob, 0, sizeof(blob));
  52371. outSz = sizeof(blob);
  52372. ret = wc_caamCreateBlob((byte*)text, sizeof(text), blob, &outSz);
  52373. if (ret != 0)
  52374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52375. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52376. if (ret != 0)
  52377. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52378. if (XMEMCMP(out, text, sizeof(text))) {
  52379. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52380. }
  52381. exit_blob:
  52382. return ret;
  52383. }
  52384. #endif /* WOLFSSL_CAAM_BLOB */
  52385. #ifdef WOLF_CRYPTO_CB
  52386. /* Example custom context for crypto callback */
  52387. typedef struct {
  52388. int exampleVar; /* flag for testing if only crypt is enabled. */
  52389. } myCryptoDevCtx;
  52390. #ifdef WOLF_CRYPTO_CB_ONLY_RSA
  52391. /* Testing rsa cb when CB_ONLY_RSA is enabled
  52392. * When CB_ONLY_RSA is enabled, software imple. is not available.
  52393. *
  52394. * ctx callback ctx
  52395. * returen 0 on success, otherwise return negative
  52396. */
  52397. static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
  52398. {
  52399. wc_test_ret_t ret = 0;
  52400. #if !defined(NO_RSA)
  52401. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52402. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key,
  52403. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52404. byte* tmp = NULL;
  52405. #else
  52406. RsaKey key[1];
  52407. byte tmp[FOURK_BUF];
  52408. #endif
  52409. size_t bytes;
  52410. const word32 inLen = (word32)TEST_STRING_SZ;
  52411. word32 idx = 0;
  52412. word32 sigSz;
  52413. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  52414. byte out[RSA_TEST_BYTES];
  52415. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  52416. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  52417. !defined(NO_FILESYSTEM)
  52418. XFILE file;
  52419. #endif
  52420. #ifdef WOLFSSL_KEY_GEN
  52421. WC_RNG rng;
  52422. #endif
  52423. #ifdef USE_CERT_BUFFERS_1024
  52424. bytes = (size_t)sizeof_client_key_der_1024;
  52425. if (bytes < (size_t)sizeof_client_cert_der_1024)
  52426. bytes = (size_t)sizeof_client_cert_der_1024;
  52427. #elif defined(USE_CERT_BUFFERS_2048)
  52428. bytes = (size_t)sizeof_client_key_der_2048;
  52429. if (bytes < (size_t)sizeof_client_cert_der_2048)
  52430. bytes = (size_t)sizeof_client_cert_der_2048;
  52431. #elif defined(USE_CERT_BUFFERS_3072)
  52432. bytes = (size_t)sizeof_client_key_der_3072;
  52433. if (bytes < (size_t)sizeof_client_cert_der_3072)
  52434. bytes = (size_t)sizeof_client_cert_der_3072;
  52435. #elif defined(USE_CERT_BUFFERS_4096)
  52436. bytes = (size_t)sizeof_client_key_der_4096;
  52437. if (bytes < (size_t)sizeof_client_cert_der_4096)
  52438. bytes = (size_t)sizeof_client_cert_der_4096;
  52439. #else
  52440. bytes = FOURK_BUF;
  52441. #endif
  52442. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52443. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52444. if (tmp == NULL)
  52445. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52446. #endif
  52447. #ifdef USE_CERT_BUFFERS_1024
  52448. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  52449. #elif defined(USE_CERT_BUFFERS_2048)
  52450. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  52451. #elif defined(USE_CERT_BUFFERS_3072)
  52452. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  52453. #elif defined(USE_CERT_BUFFERS_4096)
  52454. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  52455. #elif !defined(NO_FILESYSTEM)
  52456. file = XFOPEN(clientKey, "rb");
  52457. if (!file) {
  52458. ret = WC_TEST_RET_ENC_ERRNO;
  52459. err_sys("can't open ./certs/client-key.der, "
  52460. "Please run from wolfSSL home dir", ret);
  52461. ERROR_OUT(ret, exit_onlycb);
  52462. }
  52463. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  52464. XFCLOSE(file);
  52465. if (bytes == 0)
  52466. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52467. #endif
  52468. #ifdef WOLFSSL_KEY_GEN
  52469. /* wc_CryptoCb_MakeRsaKey cb test, no actual making key
  52470. * wc_MakeRsaKey() -> rsa cb ->
  52471. * myCryptoDevCb -> wc_MakeRsaKey(CBONLY_TEST_DEVID)
  52472. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
  52473. */
  52474. ctx->exampleVar = 99;
  52475. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52476. if (ret != 0)
  52477. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52478. /* wc_MakeRsaKey() -> rsa cb ->
  52479. * myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
  52480. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
  52481. */
  52482. ctx->exampleVar = 1;
  52483. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  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. #endif
  52490. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  52491. if (ret != 0)
  52492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52493. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  52494. if (ret != 0)
  52495. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52496. sigSz = (word32)wc_RsaEncryptSize(key);
  52497. /* wc_CryptoCb_Rsa cb test, no actual rsa operation */
  52498. if (ret == 0) {
  52499. /* wc_SignatureGenerate() -> rsa cb ->
  52500. * myCryptoDevCb -> wc_RsaFunction(CBONLY_TEST_DEVID)
  52501. * wc_RsaFunction(CBONLY_TEST_DEVID) expects to return 0(success)
  52502. */
  52503. ctx->exampleVar = 99;
  52504. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52505. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52506. if (ret != 0)
  52507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52508. }
  52509. if (ret == 0) {
  52510. /* wc_SignatureGenerate() -> rsa cb ->
  52511. * myCryptoDevCb -> wc_RsaFunction(INVALID_DEVID)
  52512. * wc_SignatureGenerate(INVALID_DEVID) expects to
  52513. * return NO_VALID_DEVID(failure)
  52514. */
  52515. ctx->exampleVar = 1;
  52516. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52517. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52518. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52520. } else
  52521. /* reset return code */
  52522. ret = 0;
  52523. }
  52524. exit_onlycb:
  52525. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52526. if (key != NULL) {
  52527. wc_FreeRsaKey(key);
  52528. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52529. }
  52530. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52531. #else
  52532. wc_FreeRsaKey(key);
  52533. #endif
  52534. #endif
  52535. return ret;
  52536. }
  52537. #endif
  52538. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  52539. /* Testing rsa cb when CB_ONLY_ECC is enabled
  52540. * When CB_ONLY_ECC is enabled, software imple. is not available.
  52541. *
  52542. * ctx callback ctx
  52543. * returen 0 on success, otherwise return negative
  52544. */
  52545. static wc_test_ret_t ecc_onlycb_test(myCryptoDevCtx *ctx)
  52546. {
  52547. wc_test_ret_t ret = 0;
  52548. #if defined(HAVE_ECC)
  52549. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52550. ecc_key* key = (ecc_key *)XMALLOC(sizeof *key,
  52551. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52552. ecc_key* pub = (ecc_key *)XMALLOC(sizeof *pub,
  52553. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52554. byte* out = (byte*)XMALLOC(sizeof(byte),
  52555. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52556. #ifdef OPENSSL_EXTRA
  52557. byte* check = (byte*)XMALLOC(sizeof(byte)*(256), HEAP_HINT,
  52558. DYNAMIC_TYPE_TMP_BUFFER);
  52559. #endif
  52560. #else
  52561. ecc_key key[1];
  52562. ecc_key pub[1];
  52563. byte out[256];
  52564. #ifdef OPENSSL_EXTRA
  52565. unsigned char check[256];
  52566. #endif
  52567. #endif
  52568. #ifdef OPENSSL_EXTRA
  52569. WOLFSSL_EVP_PKEY* privKey = NULL;
  52570. WOLFSSL_EVP_PKEY* pubKey = NULL;
  52571. #ifdef USE_CERT_BUFFERS_256
  52572. ecc_key* pkey;
  52573. const unsigned char* cp;
  52574. #endif
  52575. WOLFSSL_EVP_MD_CTX mdCtx;
  52576. const char testData[] = "Hi There";
  52577. size_t checkSz = -1;
  52578. const unsigned char* p;
  52579. const unsigned char check_v[256] = {
  52580. 0x30,0x45,0x02,0x20,0x1b,0x5c,0x2a,0xf0,0x18,0x09,
  52581. 0x74,0x65,0xa1,0x04,0x76,0x3a,0xce,0xcc,0xe5,0x34,
  52582. 0x5e,0x89,0xed,0x40,0x1e,0x5a,0xb1,0x53,0xb4,0xff,
  52583. 0xc7,0x18,0xfe,0x0f,0xc7,0xa6,0x02,0x21,0x00,0xe5,
  52584. 0x70,0x21,0xfc,0xf9,0x63,0x36,0xfd,0x16,0x18,0x08,
  52585. 0x9a,0x63,0x61,0x0f,0xe7,0x7c,0xa3,0xc9,0x14,0xa3,
  52586. 0x30,0x87,0xf7,0xf5,0x70,0x19,0xaf,0x56,0x96,0x9b,
  52587. 0xd8,0x64,0xcd,0xd9,0xff,0x7b,0x2a,0x55,0x52,0xca,
  52588. 0x41,0xb2,0xa6,0xa4,0x8a,0x3b,0x02,0x20,0x8c,0xc5,
  52589. 0xf9,0xc1,0x7d,0x2a,0x65,0x6c,0xe6,0x5a,0xe3,0x76,
  52590. 0x9b,0xab,0x0b,0x9f,0xaf,0x62,0x5d,0xb2,0x60,0xd7,
  52591. 0xeb,0xb4,0x1b,0x73,0xdc,0x01,0x7d,0x7b,0xab,0xc1,
  52592. 0x0c,0x74,0x96,0x41,0xe6,0x3f,0xc5,0x86,0xe6,0x7d,
  52593. 0x2b,0x9d,0x54,0x6b,0xcd,0x31,0x35,0x1f,0xdb,0x49,
  52594. 0x1f,0x32,0x34,0xf8,0x57,0x12,0x86,0x5c,0x0e,0x80,
  52595. 0x55,0x8d,0xff,0xd8,0xbd,0xdf,0x32,0x26,0x62,0x42,
  52596. 0x09,0xda,0xf7,0x74,0xf2,0x3f,0xe6,0xf1,0x77,0x82,
  52597. 0xce,0xe4,0xbb,0x61,0xa6,0xc0,0x17,0x0c,0x6c,0x47,
  52598. 0x2a,0x40,0x1c,0x2b,0xe0,0x98,0x3b,0xbf,0xc6,0xf8,
  52599. 0x6d,0xfd,0xd0,0xfa,0xc1,0x02,0xfb,0x5f,0xfb,0xb0,
  52600. 0xcb,0xd9,0xa3,0x59,0x94,0xe9,0x0f,0x74,0xbb,0x3f,
  52601. 0x64,0xa3,0x83,0xc4,0x2b,0xf7,0xd2,0x97,0xbf,0x3b,
  52602. 0xcf,0xbb,0x60,0x81,0x33,0x94,0xfa,0x0d,0x35,0xd2,
  52603. 0x3d,0xb9,0x99,0xe3,0x12,0xf8,0xf4,0xa3,0x74,0xf4,
  52604. 0x94,0x1d,0x7a,0x66,0xf8,0xd1,0x1d,0xcf,0xb0,0x48,
  52605. 0xef,0x8c,0x94,0x6f,0xdd,0x62,
  52606. };
  52607. #endif
  52608. WC_RNG rng;
  52609. EncryptedInfo encInfo;
  52610. int keyFormat = 0;
  52611. word32 keyIdx = 0;
  52612. byte in[] = "Everyone gets Friday off. ecc p";
  52613. word32 inLen = (word32)XSTRLEN((char*)in);
  52614. word32 outLen;
  52615. int verify;
  52616. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52617. if (key == NULL || pub == NULL) {
  52618. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52619. }
  52620. #endif
  52621. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  52622. if (ret != 0)
  52623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52624. /* wc_CryptoCb_MakeEccKey cb test, , no actual testing */
  52625. ctx->exampleVar = 99;
  52626. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52627. if (ret != 0)
  52628. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52629. ctx->exampleVar = 1;
  52630. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52631. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52633. } else
  52634. /* reset return code */
  52635. ret = 0;
  52636. #ifdef USE_CERT_BUFFERS_256
  52637. if (ret == 0) {
  52638. /* load ECC private key and perform private transform */
  52639. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &keyIdx,
  52640. key, sizeof_ecc_key_der_256);
  52641. }
  52642. if (ret != 0)
  52643. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52644. /* wc_CryptoCb_EccSign cb test, no actual testing */
  52645. ctx->exampleVar = 99;
  52646. if (ret == 0) {
  52647. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  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_sign_hash(in, inLen, out, &outLen, &rng, key);
  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. /* wc_CryptoCb_EccVerify cb test, no actual testing */
  52661. ctx->exampleVar = 99;
  52662. if (ret == 0) {
  52663. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  52664. }
  52665. if (ret != 0)
  52666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52667. ctx->exampleVar = 1;
  52668. if (ret == 0) {
  52669. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  52670. }
  52671. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52672. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52673. }
  52674. else
  52675. ret = 0;
  52676. /* wc_CryptoCb_Ecdh cb test, no actual testing */
  52677. /* make public key for shared secret */
  52678. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  52679. ctx->exampleVar = 99;
  52680. if (ret == 0) {
  52681. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52682. }
  52683. if (ret != 0)
  52684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52685. ctx->exampleVar = 1;
  52686. if (ret == 0) {
  52687. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52688. }
  52689. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52690. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52691. }
  52692. else
  52693. ret = 0;
  52694. #ifdef OPENSSL_EXTRA
  52695. (void)pkey;
  52696. cp = ecc_clikey_der_256;
  52697. privKey = d2i_PrivateKey(WC_EVP_PKEY_EC, NULL, &cp,
  52698. sizeof_ecc_clikey_der_256);
  52699. if (privKey == NULL) {
  52700. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52701. }
  52702. pkey = (ecc_key*)privKey->ecc->internal;
  52703. pkey->devId = devId;
  52704. p = ecc_clikeypub_der_256;
  52705. pubKey = d2i_PUBKEY(NULL, &p, sizeof_ecc_clikeypub_der_256);
  52706. if (pubKey == NULL) {
  52707. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52708. }
  52709. pkey = (ecc_key*)pubKey->ecc->internal;
  52710. pkey->devId = devId;
  52711. /* sign */
  52712. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52713. ret = EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, privKey);
  52714. if (ret != WOLFSSL_SUCCESS) {
  52715. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52716. }
  52717. ret = EVP_DigestSignUpdate(&mdCtx, testData,
  52718. (unsigned int)XSTRLEN(testData));
  52719. if (ret != WOLFSSL_SUCCESS) {
  52720. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52721. }
  52722. ret = EVP_DigestSignFinal(&mdCtx, NULL, &checkSz);
  52723. if (ret != WOLFSSL_SUCCESS) {
  52724. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52725. }
  52726. ctx->exampleVar = 99;
  52727. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52728. /* just called crypt callback as dummy
  52729. * EVP_DigestSignFinal returns 0 internally.
  52730. */
  52731. if (ret != 0)
  52732. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52733. ctx->exampleVar = 1;
  52734. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52735. /* just called crypt callback as dummy
  52736. * EVP_DigestSignFinal returns 0 internally.
  52737. */
  52738. if (ret != 0)
  52739. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52740. /* restore checkSz for verify */
  52741. checkSz = 71;
  52742. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52743. if (ret != WOLFSSL_SUCCESS) {
  52744. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52745. }
  52746. /* verify */
  52747. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52748. if (ret == WOLFSSL_SUCCESS) {
  52749. ret = EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, pubKey);
  52750. }
  52751. if (ret != WOLFSSL_SUCCESS) {
  52752. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52753. }
  52754. if (ret == WOLFSSL_SUCCESS) {
  52755. ret = EVP_DigestVerifyUpdate(&mdCtx, testData,
  52756. (unsigned int)XSTRLEN(testData));
  52757. }
  52758. if (ret != WOLFSSL_SUCCESS) {
  52759. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52760. }
  52761. ctx->exampleVar = 99;
  52762. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52763. /* just called crypt callback as dummy
  52764. * EVP_DigestSignFinal returns 0 internally.
  52765. */
  52766. if (ret != 0)
  52767. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52768. ctx->exampleVar = 1;
  52769. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52770. /* just called crypt callback as dummy
  52771. * EVP_DigestVerifyFinal returns -1 internally rather than NO_VALID_DEVID.
  52772. */
  52773. if (ret != -1) {
  52774. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52775. }
  52776. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52777. if (ret != WOLFSSL_SUCCESS) {
  52778. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52779. } else
  52780. ret = 0;
  52781. #endif
  52782. #else
  52783. (void)verify;
  52784. (void)outLen;
  52785. (void)inLen;
  52786. (void)out;
  52787. (void)pub;
  52788. #ifdef OPENSSL_EXTRA
  52789. (void)privKey;
  52790. (void)pubKey;
  52791. (void)mdCtx;
  52792. (void)check;
  52793. (void)checkSz;
  52794. (void)p;
  52795. #endif
  52796. #endif
  52797. (void)keyFormat;
  52798. (void)encInfo;
  52799. exit_onlycb:
  52800. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52801. if (key != NULL) {
  52802. wc_ecc_free(key);
  52803. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52804. }
  52805. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52806. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52807. #ifdef OPENSSL_EXTRA
  52808. if (check) {
  52809. FREE(check, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52810. }
  52811. #endif
  52812. #else
  52813. wc_ecc_free(key);
  52814. #ifdef OPENSSL_EXTRA
  52815. if (privKey)
  52816. wolfSSL_EVP_PKEY_free(privKey);
  52817. if (pubKey)
  52818. wolfSSL_EVP_PKEY_free(pubKey);
  52819. #endif
  52820. #endif
  52821. #endif /* HAVE_ECC */
  52822. return ret;
  52823. }
  52824. #endif
  52825. /* Example crypto dev callback function that calls software version */
  52826. static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
  52827. {
  52828. int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN); /* return this to bypass HW and
  52829. use SW */
  52830. myCryptoDevCtx* myCtx = (myCryptoDevCtx*)ctx;
  52831. if (info == NULL)
  52832. return BAD_FUNC_ARG;
  52833. #ifdef DEBUG_WOLFSSL
  52834. WOLFSSL_MSG_EX("CryptoDevCb: Algo Type %d\n", info->algo_type);
  52835. #endif
  52836. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  52837. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  52838. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  52839. /* if RNG only supports crypto callback, just use seed */
  52840. ret = wc_GenerateSeed(&info->rng.rng->seed,
  52841. info->rng.out, info->rng.sz);
  52842. #elif !defined(WC_NO_RNG)
  52843. /* set devId to invalid, so software is used */
  52844. info->rng.rng->devId = INVALID_DEVID;
  52845. ret = wc_RNG_GenerateBlock(info->rng.rng,
  52846. info->rng.out, info->rng.sz);
  52847. /* reset devId */
  52848. info->rng.rng->devId = devIdArg;
  52849. #endif
  52850. }
  52851. else if (info->algo_type == WC_ALGO_TYPE_SEED) {
  52852. #ifndef WC_NO_RNG
  52853. ALIGN32 static byte seed[sizeof(word32)] = { 0x00, 0x00, 0x00, 0x01 };
  52854. word32* seedWord32 = (word32*)seed;
  52855. word32 len;
  52856. /* wc_GenerateSeed is a local symbol so we need to fake the entropy. */
  52857. while (info->seed.sz > 0) {
  52858. len = (word32)sizeof(seed);
  52859. if (info->seed.sz < len)
  52860. len = info->seed.sz;
  52861. XMEMCPY(info->seed.seed, seed, sizeof(seed));
  52862. info->seed.seed += len;
  52863. info->seed.sz -= len;
  52864. (*seedWord32)++;
  52865. }
  52866. ret = 0;
  52867. #endif
  52868. }
  52869. else if (info->algo_type == WC_ALGO_TYPE_PK) {
  52870. #ifdef DEBUG_WOLFSSL
  52871. WOLFSSL_MSG_EX("CryptoDevCb: Pk Type %d\n", info->pk.type);
  52872. #endif
  52873. #ifndef NO_RSA
  52874. if (info->pk.type == WC_PK_TYPE_RSA) {
  52875. /* set devId to invalid, so software is used */
  52876. info->pk.rsa.key->devId = INVALID_DEVID;
  52877. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52878. #ifdef DEBUG_WOLFSSL
  52879. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52880. #endif
  52881. if (myCtx->exampleVar == 99) {
  52882. info->pk.rsa.key->devId = devIdArg;
  52883. return 0;
  52884. }
  52885. #endif
  52886. switch (info->pk.rsa.type) {
  52887. case RSA_PUBLIC_ENCRYPT:
  52888. case RSA_PUBLIC_DECRYPT:
  52889. /* perform software based RSA public op */
  52890. ret = wc_RsaFunction(
  52891. info->pk.rsa.in, info->pk.rsa.inLen,
  52892. info->pk.rsa.out, info->pk.rsa.outLen,
  52893. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52894. break;
  52895. case RSA_PRIVATE_ENCRYPT:
  52896. case RSA_PRIVATE_DECRYPT:
  52897. /* perform software based RSA private op */
  52898. ret = wc_RsaFunction(
  52899. info->pk.rsa.in, info->pk.rsa.inLen,
  52900. info->pk.rsa.out, info->pk.rsa.outLen,
  52901. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52902. break;
  52903. }
  52904. /* reset devId */
  52905. info->pk.rsa.key->devId = devIdArg;
  52906. }
  52907. #ifdef WOLFSSL_KEY_GEN
  52908. else if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN) {
  52909. info->pk.rsakg.key->devId = INVALID_DEVID;
  52910. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52911. #ifdef DEBUG_WOLFSSL
  52912. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52913. #endif
  52914. if (myCtx->exampleVar == 99) {
  52915. info->pk.rsakg.key->devId = devIdArg;
  52916. return 0;
  52917. }
  52918. #endif
  52919. #ifdef HAVE_FIPS
  52920. for (;;) {
  52921. #endif
  52922. ret = wc_MakeRsaKey(info->pk.rsakg.key, info->pk.rsakg.size,
  52923. info->pk.rsakg.e, info->pk.rsakg.rng);
  52924. #ifdef HAVE_FIPS
  52925. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  52926. continue;
  52927. break;
  52928. }
  52929. #endif
  52930. /* reset devId */
  52931. info->pk.rsakg.key->devId = devIdArg;
  52932. }
  52933. #endif
  52934. #endif /* !NO_RSA */
  52935. #ifdef HAVE_ECC
  52936. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  52937. /* set devId to invalid, so software is used */
  52938. info->pk.eckg.key->devId = INVALID_DEVID;
  52939. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52940. #ifdef DEBUG_WOLFSSL
  52941. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52942. #endif
  52943. if (myCtx->exampleVar == 99) {
  52944. info->pk.eckg.key->devId = devIdArg;
  52945. return 0;
  52946. }
  52947. #endif
  52948. ret = wc_ecc_make_key_ex(info->pk.eckg.rng, info->pk.eckg.size,
  52949. info->pk.eckg.key, info->pk.eckg.curveId);
  52950. /* reset devId */
  52951. info->pk.eckg.key->devId = devIdArg;
  52952. }
  52953. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  52954. /* set devId to invalid, so software is used */
  52955. info->pk.eccsign.key->devId = INVALID_DEVID;
  52956. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52957. #ifdef DEBUG_WOLFSSL
  52958. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52959. #endif
  52960. if (myCtx->exampleVar == 99) {
  52961. info->pk.eccsign.key->devId = devIdArg;
  52962. return 0;
  52963. }
  52964. #endif
  52965. ret = wc_ecc_sign_hash(
  52966. info->pk.eccsign.in, info->pk.eccsign.inlen,
  52967. info->pk.eccsign.out, info->pk.eccsign.outlen,
  52968. info->pk.eccsign.rng, info->pk.eccsign.key);
  52969. /* reset devId */
  52970. info->pk.eccsign.key->devId = devIdArg;
  52971. }
  52972. else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
  52973. /* set devId to invalid, so software is used */
  52974. info->pk.eccverify.key->devId = INVALID_DEVID;
  52975. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52976. #ifdef DEBUG_WOLFSSL
  52977. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52978. #endif
  52979. if (myCtx->exampleVar == 99) {
  52980. info->pk.eccverify.key->devId = devIdArg;
  52981. return 0;
  52982. }
  52983. #endif
  52984. ret = wc_ecc_verify_hash(
  52985. info->pk.eccverify.sig, info->pk.eccverify.siglen,
  52986. info->pk.eccverify.hash, info->pk.eccverify.hashlen,
  52987. info->pk.eccverify.res, info->pk.eccverify.key);
  52988. /* reset devId */
  52989. info->pk.eccverify.key->devId = devIdArg;
  52990. }
  52991. else if (info->pk.type == WC_PK_TYPE_ECDH) {
  52992. /* set devId to invalid, so software is used */
  52993. info->pk.ecdh.private_key->devId = INVALID_DEVID;
  52994. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52995. #ifdef DEBUG_WOLFSSL
  52996. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52997. #endif
  52998. if (myCtx->exampleVar == 99) {
  52999. info->pk.ecdh.private_key->devId = devIdArg;
  53000. return 0;
  53001. }
  53002. #endif
  53003. ret = wc_ecc_shared_secret(
  53004. info->pk.ecdh.private_key, info->pk.ecdh.public_key,
  53005. info->pk.ecdh.out, info->pk.ecdh.outlen);
  53006. /* reset devId */
  53007. info->pk.ecdh.private_key->devId = devIdArg;
  53008. }
  53009. #endif /* HAVE_ECC */
  53010. #ifdef HAVE_CURVE25519
  53011. if (info->pk.type == WC_PK_TYPE_CURVE25519_KEYGEN) {
  53012. /* set devId to invalid, so software is used */
  53013. info->pk.curve25519kg.key->devId = INVALID_DEVID;
  53014. ret = wc_curve25519_make_key(info->pk.curve25519kg.rng,
  53015. info->pk.curve25519kg.size, info->pk.curve25519kg.key);
  53016. /* reset devId */
  53017. info->pk.curve25519kg.key->devId = devIdArg;
  53018. }
  53019. else if (info->pk.type == WC_PK_TYPE_CURVE25519) {
  53020. /* set devId to invalid, so software is used */
  53021. info->pk.curve25519.private_key->devId = INVALID_DEVID;
  53022. ret = wc_curve25519_shared_secret_ex(
  53023. info->pk.curve25519.private_key, info->pk.curve25519.public_key,
  53024. info->pk.curve25519.out, info->pk.curve25519.outlen,
  53025. info->pk.curve25519.endian);
  53026. /* reset devId */
  53027. info->pk.curve25519.private_key->devId = devIdArg;
  53028. }
  53029. #endif /* HAVE_CURVE25519 */
  53030. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  53031. if (info->pk.type == WC_PK_TYPE_ED25519_KEYGEN) {
  53032. /* set devId to invalid, so software is used */
  53033. info->pk.ed25519kg.key->devId = INVALID_DEVID;
  53034. ret = wc_ed25519_make_key(info->pk.ed25519kg.rng,
  53035. info->pk.ed25519kg.size, info->pk.ed25519kg.key);
  53036. /* reset devId */
  53037. info->pk.ed25519kg.key->devId = devIdArg;
  53038. }
  53039. #ifdef HAVE_ED25519_SIGN
  53040. else if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  53041. /* set devId to invalid, so software is used */
  53042. info->pk.ed25519sign.key->devId = INVALID_DEVID;
  53043. ret = wc_ed25519_sign_msg_ex(
  53044. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  53045. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  53046. info->pk.ed25519sign.key, info->pk.ed25519sign.type,
  53047. info->pk.ed25519sign.context, info->pk.ed25519sign.contextLen);
  53048. /* reset devId */
  53049. info->pk.ed25519sign.key->devId = devIdArg;
  53050. }
  53051. #endif
  53052. #ifdef HAVE_ED25519_VERIFY
  53053. else if (info->pk.type == WC_PK_TYPE_ED25519_VERIFY) {
  53054. /* set devId to invalid, so software is used */
  53055. info->pk.ed25519verify.key->devId = INVALID_DEVID;
  53056. ret = wc_ed25519_verify_msg_ex(
  53057. info->pk.ed25519verify.sig, info->pk.ed25519verify.sigLen,
  53058. info->pk.ed25519verify.msg, info->pk.ed25519verify.msgLen,
  53059. info->pk.ed25519verify.res, info->pk.ed25519verify.key,
  53060. info->pk.ed25519verify.type, info->pk.ed25519verify.context,
  53061. info->pk.ed25519verify.contextLen);
  53062. /* reset devId */
  53063. info->pk.ed25519verify.key->devId = devIdArg;
  53064. }
  53065. #endif
  53066. #endif /* HAVE_ED25519 */
  53067. }
  53068. else if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
  53069. #if !defined(NO_AES) || !defined(NO_DES3)
  53070. #ifdef HAVE_AESGCM
  53071. if (info->cipher.type == WC_CIPHER_AES_GCM) {
  53072. if (info->cipher.enc) {
  53073. /* set devId to invalid, so software is used */
  53074. info->cipher.aesgcm_enc.aes->devId = INVALID_DEVID;
  53075. ret = wc_AesGcmEncrypt(
  53076. info->cipher.aesgcm_enc.aes,
  53077. info->cipher.aesgcm_enc.out,
  53078. info->cipher.aesgcm_enc.in,
  53079. info->cipher.aesgcm_enc.sz,
  53080. info->cipher.aesgcm_enc.iv,
  53081. info->cipher.aesgcm_enc.ivSz,
  53082. info->cipher.aesgcm_enc.authTag,
  53083. info->cipher.aesgcm_enc.authTagSz,
  53084. info->cipher.aesgcm_enc.authIn,
  53085. info->cipher.aesgcm_enc.authInSz);
  53086. /* reset devId */
  53087. info->cipher.aesgcm_enc.aes->devId = devIdArg;
  53088. }
  53089. else {
  53090. /* set devId to invalid, so software is used */
  53091. info->cipher.aesgcm_dec.aes->devId = INVALID_DEVID;
  53092. ret = wc_AesGcmDecrypt(
  53093. info->cipher.aesgcm_dec.aes,
  53094. info->cipher.aesgcm_dec.out,
  53095. info->cipher.aesgcm_dec.in,
  53096. info->cipher.aesgcm_dec.sz,
  53097. info->cipher.aesgcm_dec.iv,
  53098. info->cipher.aesgcm_dec.ivSz,
  53099. info->cipher.aesgcm_dec.authTag,
  53100. info->cipher.aesgcm_dec.authTagSz,
  53101. info->cipher.aesgcm_dec.authIn,
  53102. info->cipher.aesgcm_dec.authInSz);
  53103. /* reset devId */
  53104. info->cipher.aesgcm_dec.aes->devId = devIdArg;
  53105. }
  53106. }
  53107. #endif /* HAVE_AESGCM */
  53108. #ifdef HAVE_AES_CBC
  53109. if (info->cipher.type == WC_CIPHER_AES_CBC) {
  53110. if (info->cipher.enc) {
  53111. /* set devId to invalid, so software is used */
  53112. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  53113. ret = wc_AesCbcEncrypt(
  53114. info->cipher.aescbc.aes,
  53115. info->cipher.aescbc.out,
  53116. info->cipher.aescbc.in,
  53117. info->cipher.aescbc.sz);
  53118. /* reset devId */
  53119. info->cipher.aescbc.aes->devId = devIdArg;
  53120. }
  53121. else {
  53122. /* set devId to invalid, so software is used */
  53123. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  53124. ret = wc_AesCbcDecrypt(
  53125. info->cipher.aescbc.aes,
  53126. info->cipher.aescbc.out,
  53127. info->cipher.aescbc.in,
  53128. info->cipher.aescbc.sz);
  53129. /* reset devId */
  53130. info->cipher.aescbc.aes->devId = devIdArg;
  53131. }
  53132. }
  53133. #endif /* HAVE_AES_CBC */
  53134. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  53135. if (info->cipher.type == WC_CIPHER_AES_ECB) {
  53136. if (info->cipher.enc) {
  53137. /* set devId to invalid, so software is used */
  53138. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  53139. ret = wc_AesEcbEncrypt(
  53140. info->cipher.aesecb.aes,
  53141. info->cipher.aesecb.out,
  53142. info->cipher.aesecb.in,
  53143. info->cipher.aesecb.sz);
  53144. /* reset devId */
  53145. info->cipher.aesecb.aes->devId = devIdArg;
  53146. }
  53147. else {
  53148. /* set devId to invalid, so software is used */
  53149. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  53150. ret = wc_AesEcbDecrypt(
  53151. info->cipher.aesecb.aes,
  53152. info->cipher.aesecb.out,
  53153. info->cipher.aesecb.in,
  53154. info->cipher.aesecb.sz);
  53155. /* reset devId */
  53156. info->cipher.aesecb.aes->devId = devIdArg;
  53157. }
  53158. }
  53159. #endif /* HAVE_AES_ECB */
  53160. #if defined(WOLFSSL_AES_COUNTER) && !defined(HAVE_FIPS) && \
  53161. !defined(HAVE_SELFTEST)
  53162. if (info->cipher.type == WC_CIPHER_AES_CTR) {
  53163. /* set devId to invalid, so software is used */
  53164. info->cipher.aesctr.aes->devId = INVALID_DEVID;
  53165. ret = wc_AesCtrEncrypt(
  53166. info->cipher.aesctr.aes,
  53167. info->cipher.aesctr.out,
  53168. info->cipher.aesctr.in,
  53169. info->cipher.aesctr.sz);
  53170. /* reset devId */
  53171. info->cipher.aesctr.aes->devId = devIdArg;
  53172. }
  53173. #endif /* WOLFSSL_AES_COUNTER */
  53174. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53175. if (info->cipher.type == WC_CIPHER_AES_CCM) {
  53176. if (info->cipher.enc) {
  53177. /* set devId to invalid, so software is used */
  53178. info->cipher.aesccm_enc.aes->devId = INVALID_DEVID;
  53179. ret = wc_AesCcmEncrypt(
  53180. info->cipher.aesccm_enc.aes,
  53181. info->cipher.aesccm_enc.out,
  53182. info->cipher.aesccm_enc.in,
  53183. info->cipher.aesccm_enc.sz,
  53184. info->cipher.aesccm_enc.nonce,
  53185. info->cipher.aesccm_enc.nonceSz,
  53186. info->cipher.aesccm_enc.authTag,
  53187. info->cipher.aesccm_enc.authTagSz,
  53188. info->cipher.aesccm_enc.authIn,
  53189. info->cipher.aesccm_enc.authInSz);
  53190. /* reset devId */
  53191. info->cipher.aesccm_enc.aes->devId = devIdArg;
  53192. }
  53193. else {
  53194. /* set devId to invalid, so software is used */
  53195. info->cipher.aesccm_dec.aes->devId = INVALID_DEVID;
  53196. ret = wc_AesCcmDecrypt(
  53197. info->cipher.aesccm_dec.aes,
  53198. info->cipher.aesccm_dec.out,
  53199. info->cipher.aesccm_dec.in,
  53200. info->cipher.aesccm_dec.sz,
  53201. info->cipher.aesccm_dec.nonce,
  53202. info->cipher.aesccm_dec.nonceSz,
  53203. info->cipher.aesccm_dec.authTag,
  53204. info->cipher.aesccm_dec.authTagSz,
  53205. info->cipher.aesccm_dec.authIn,
  53206. info->cipher.aesccm_dec.authInSz);
  53207. /* reset devId */
  53208. info->cipher.aesccm_dec.aes->devId = devIdArg;
  53209. }
  53210. }
  53211. #endif
  53212. #ifndef NO_DES3
  53213. if (info->cipher.type == WC_CIPHER_DES3) {
  53214. if (info->cipher.enc) {
  53215. /* set devId to invalid, so software is used */
  53216. info->cipher.des3.des->devId = INVALID_DEVID;
  53217. ret = wc_Des3_CbcEncrypt(
  53218. info->cipher.des3.des,
  53219. info->cipher.des3.out,
  53220. info->cipher.des3.in,
  53221. info->cipher.des3.sz);
  53222. /* reset devId */
  53223. info->cipher.des3.des->devId = devIdArg;
  53224. }
  53225. else {
  53226. /* set devId to invalid, so software is used */
  53227. info->cipher.des3.des->devId = INVALID_DEVID;
  53228. ret = wc_Des3_CbcDecrypt(
  53229. info->cipher.des3.des,
  53230. info->cipher.des3.out,
  53231. info->cipher.des3.in,
  53232. info->cipher.des3.sz);
  53233. /* reset devId */
  53234. info->cipher.des3.des->devId = devIdArg;
  53235. }
  53236. }
  53237. #endif /* !NO_DES3 */
  53238. #endif /* !NO_AES || !NO_DES3 */
  53239. }
  53240. #if !defined(NO_SHA) || !defined(NO_SHA256) || \
  53241. defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
  53242. else if (info->algo_type == WC_ALGO_TYPE_HASH) {
  53243. #if !defined(NO_SHA)
  53244. if (info->hash.type == WC_HASH_TYPE_SHA) {
  53245. if (info->hash.sha1 == NULL)
  53246. return NOT_COMPILED_IN;
  53247. /* set devId to invalid, so software is used */
  53248. info->hash.sha1->devId = INVALID_DEVID;
  53249. if (info->hash.in != NULL) {
  53250. ret = wc_ShaUpdate(
  53251. info->hash.sha1,
  53252. info->hash.in,
  53253. info->hash.inSz);
  53254. }
  53255. if (info->hash.digest != NULL) {
  53256. ret = wc_ShaFinal(
  53257. info->hash.sha1,
  53258. info->hash.digest);
  53259. }
  53260. /* reset devId */
  53261. info->hash.sha1->devId = devIdArg;
  53262. }
  53263. else
  53264. #endif
  53265. #if !defined(NO_SHA256)
  53266. if (info->hash.type == WC_HASH_TYPE_SHA256) {
  53267. if (info->hash.sha256 == NULL)
  53268. return NOT_COMPILED_IN;
  53269. /* set devId to invalid, so software is used */
  53270. info->hash.sha256->devId = INVALID_DEVID;
  53271. if (info->hash.in != NULL) {
  53272. ret = wc_Sha256Update(
  53273. info->hash.sha256,
  53274. info->hash.in,
  53275. info->hash.inSz);
  53276. }
  53277. if (info->hash.digest != NULL) {
  53278. ret = wc_Sha256Final(
  53279. info->hash.sha256,
  53280. info->hash.digest);
  53281. }
  53282. /* reset devId */
  53283. info->hash.sha256->devId = devIdArg;
  53284. }
  53285. else
  53286. #endif
  53287. #ifdef WOLFSSL_SHA384
  53288. if (info->hash.type == WC_HASH_TYPE_SHA384) {
  53289. if (info->hash.sha384 == NULL)
  53290. return NOT_COMPILED_IN;
  53291. #ifndef NO_SHA2_CRYPTO_CB
  53292. /* set devId to invalid, so software is used */
  53293. info->hash.sha384->devId = INVALID_DEVID;
  53294. #endif
  53295. if (info->hash.in != NULL) {
  53296. ret = wc_Sha384Update(
  53297. info->hash.sha384,
  53298. info->hash.in,
  53299. info->hash.inSz);
  53300. }
  53301. if (info->hash.digest != NULL) {
  53302. ret = wc_Sha384Final(
  53303. info->hash.sha384,
  53304. info->hash.digest);
  53305. }
  53306. #ifndef NO_SHA2_CRYPTO_CB
  53307. /* reset devId */
  53308. info->hash.sha384->devId = devIdArg;
  53309. #endif
  53310. }
  53311. else
  53312. #endif
  53313. #ifdef WOLFSSL_SHA512
  53314. if (info->hash.type == WC_HASH_TYPE_SHA512) {
  53315. if (info->hash.sha512 == NULL)
  53316. return NOT_COMPILED_IN;
  53317. #ifndef NO_SHA2_CRYPTO_CB
  53318. /* set devId to invalid, so software is used */
  53319. info->hash.sha512->devId = INVALID_DEVID;
  53320. #endif
  53321. if (info->hash.in != NULL) {
  53322. ret = wc_Sha512Update(
  53323. info->hash.sha512,
  53324. info->hash.in,
  53325. info->hash.inSz);
  53326. }
  53327. if (info->hash.digest != NULL) {
  53328. ret = wc_Sha512Final(
  53329. info->hash.sha512,
  53330. info->hash.digest);
  53331. }
  53332. #ifndef NO_SHA2_CRYPTO_CB
  53333. /* reset devId */
  53334. info->hash.sha512->devId = devIdArg;
  53335. #endif
  53336. }
  53337. else
  53338. #endif
  53339. #if defined(WOLFSSL_SHA3) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0))
  53340. if (info->hash.type == WC_HASH_TYPE_SHA3_224) {
  53341. if (info->hash.sha3 == NULL)
  53342. return NOT_COMPILED_IN;
  53343. /* set devId to invalid, so software is used */
  53344. info->hash.sha3->devId = INVALID_DEVID;
  53345. if (info->hash.in != NULL) {
  53346. ret = wc_Sha3_224_Update(
  53347. info->hash.sha3,
  53348. info->hash.in,
  53349. info->hash.inSz);
  53350. }
  53351. if (info->hash.digest != NULL) {
  53352. ret = wc_Sha3_224_Final(
  53353. info->hash.sha3,
  53354. info->hash.digest);
  53355. }
  53356. /* reset devId */
  53357. info->hash.sha3->devId = devIdArg;
  53358. }
  53359. else if (info->hash.type == WC_HASH_TYPE_SHA3_256) {
  53360. if (info->hash.sha3 == NULL)
  53361. return NOT_COMPILED_IN;
  53362. /* set devId to invalid, so software is used */
  53363. info->hash.sha3->devId = INVALID_DEVID;
  53364. if (info->hash.in != NULL) {
  53365. ret = wc_Sha3_256_Update(
  53366. info->hash.sha3,
  53367. info->hash.in,
  53368. info->hash.inSz);
  53369. }
  53370. if (info->hash.digest != NULL) {
  53371. ret = wc_Sha3_256_Final(
  53372. info->hash.sha3,
  53373. info->hash.digest);
  53374. }
  53375. /* reset devId */
  53376. info->hash.sha3->devId = devIdArg;
  53377. }
  53378. else if (info->hash.type == WC_HASH_TYPE_SHA3_384) {
  53379. if (info->hash.sha3 == NULL)
  53380. return NOT_COMPILED_IN;
  53381. /* set devId to invalid, so software is used */
  53382. info->hash.sha3->devId = INVALID_DEVID;
  53383. if (info->hash.in != NULL) {
  53384. ret = wc_Sha3_384_Update(
  53385. info->hash.sha3,
  53386. info->hash.in,
  53387. info->hash.inSz);
  53388. }
  53389. if (info->hash.digest != NULL) {
  53390. ret = wc_Sha3_384_Final(
  53391. info->hash.sha3,
  53392. info->hash.digest);
  53393. }
  53394. /* reset devId */
  53395. info->hash.sha3->devId = devIdArg;
  53396. }
  53397. else if (info->hash.type == WC_HASH_TYPE_SHA3_512) {
  53398. if (info->hash.sha3 == NULL)
  53399. return NOT_COMPILED_IN;
  53400. /* set devId to invalid, so software is used */
  53401. info->hash.sha3->devId = INVALID_DEVID;
  53402. if (info->hash.in != NULL) {
  53403. ret = wc_Sha3_512_Update(
  53404. info->hash.sha3,
  53405. info->hash.in,
  53406. info->hash.inSz);
  53407. }
  53408. if (info->hash.digest != NULL) {
  53409. ret = wc_Sha3_512_Final(
  53410. info->hash.sha3,
  53411. info->hash.digest);
  53412. }
  53413. /* reset devId */
  53414. info->hash.sha3->devId = devIdArg;
  53415. }
  53416. else
  53417. #endif
  53418. {
  53419. }
  53420. }
  53421. #endif /* !NO_SHA || !NO_SHA256 */
  53422. #ifndef NO_HMAC
  53423. else if (info->algo_type == WC_ALGO_TYPE_HMAC) {
  53424. if (info->hmac.hmac == NULL)
  53425. return NOT_COMPILED_IN;
  53426. /* set devId to invalid, so software is used */
  53427. info->hmac.hmac->devId = INVALID_DEVID;
  53428. if (info->hmac.in != NULL) {
  53429. ret = wc_HmacUpdate(
  53430. info->hmac.hmac,
  53431. info->hmac.in,
  53432. info->hmac.inSz);
  53433. }
  53434. else if (info->hmac.digest != NULL) {
  53435. ret = wc_HmacFinal(
  53436. info->hmac.hmac,
  53437. info->hmac.digest);
  53438. }
  53439. /* reset devId */
  53440. info->hmac.hmac->devId = devIdArg;
  53441. }
  53442. #endif
  53443. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53444. else if (info->algo_type == WC_ALGO_TYPE_CMAC) {
  53445. if (info->cmac.cmac == NULL) {
  53446. return NOT_COMPILED_IN;
  53447. }
  53448. /* set devId to invalid so software is used */
  53449. info->cmac.cmac->devId = INVALID_DEVID;
  53450. /* Handle one-shot cases */
  53451. if (info->cmac.key != NULL && info->cmac.in != NULL
  53452. && info->cmac.out != NULL) {
  53453. ret = wc_AesCmacGenerate(info->cmac.out,
  53454. info->cmac.outSz,
  53455. info->cmac.in,
  53456. info->cmac.inSz,
  53457. info->cmac.key,
  53458. info->cmac.keySz);
  53459. /* Sequentially handle incremental cases */
  53460. } else {
  53461. if (info->cmac.key != NULL) {
  53462. ret = wc_InitCmac(info->cmac.cmac,
  53463. info->cmac.key,
  53464. info->cmac.keySz,
  53465. info->cmac.type,
  53466. NULL);
  53467. }
  53468. if ((ret == 0) && (info->cmac.in != NULL)) {
  53469. ret = wc_CmacUpdate(info->cmac.cmac,
  53470. info->cmac.in,
  53471. info->cmac.inSz);
  53472. }
  53473. if ((ret ==0) && (info->cmac.out != NULL)) {
  53474. ret = wc_CmacFinal(info->cmac.cmac,
  53475. info->cmac.out,
  53476. info->cmac.outSz);
  53477. }
  53478. }
  53479. /* reset devId */
  53480. info->cmac.cmac->devId = devIdArg;
  53481. }
  53482. #endif /* WOLFSSL_CMAC && !(NO_AES) && WOLFSSL_AES_DIRECT */
  53483. (void)devIdArg;
  53484. (void)myCtx;
  53485. return ret;
  53486. }
  53487. #ifdef WOLF_CRYPTO_CB_FIND
  53488. static int myCryptoCbFind(int currentId, int algoType)
  53489. {
  53490. /* can have algo specific overrides here
  53491. switch (algoType) {
  53492. i.e.
  53493. WC_ALGO_TYPE_CMAC
  53494. WC_ALGO_TYPE_SEED
  53495. WC_ALGO_TYPE_HMAC
  53496. WC_ALGO_TYPE_HASH
  53497. WC_ALGO_TYPE_CIPHER
  53498. WC_ALGO_TYPE_PK
  53499. }
  53500. */
  53501. (void)algoType;
  53502. if (currentId == INVALID_DEVID) {
  53503. /* can override invalid devid found with 1 */
  53504. }
  53505. return currentId;
  53506. }
  53507. #endif /* WOLF_CRYPTO_CB_FIND */
  53508. #if !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  53509. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void)
  53510. {
  53511. wc_test_ret_t ret = 0;
  53512. int origDevId = devId;
  53513. myCryptoDevCtx myCtx;
  53514. WOLFSSL_ENTER("cryptocb_test");
  53515. /* example data for callback */
  53516. myCtx.exampleVar = 1;
  53517. /* set devId to something other than INVALID_DEVID */
  53518. devId = 1;
  53519. ret = wc_CryptoCb_RegisterDevice(devId, myCryptoDevCb, &myCtx);
  53520. #ifdef WOLF_CRYPTO_CB_FIND
  53521. wc_CryptoCb_SetDeviceFindCb(myCryptoCbFind);
  53522. #endif /* WOLF_CRYPTO_CB_FIND */
  53523. #ifndef WC_NO_RNG
  53524. if (ret == 0)
  53525. ret = random_test();
  53526. #endif /* WC_NO_RNG */
  53527. #if !defined(NO_RSA)
  53528. PRIVATE_KEY_UNLOCK();
  53529. if (ret == 0)
  53530. ret = rsa_test();
  53531. PRIVATE_KEY_LOCK();
  53532. #endif
  53533. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  53534. PRIVATE_KEY_UNLOCK();
  53535. if (ret == 0)
  53536. ret = rsa_onlycb_test(&myCtx);
  53537. PRIVATE_KEY_LOCK();
  53538. #endif
  53539. #if defined(HAVE_ECC)
  53540. PRIVATE_KEY_UNLOCK();
  53541. if (ret == 0)
  53542. ret = ecc_test();
  53543. PRIVATE_KEY_LOCK();
  53544. #endif
  53545. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  53546. PRIVATE_KEY_UNLOCK();
  53547. if (ret == 0)
  53548. ret = ecc_onlycb_test(&myCtx);
  53549. PRIVATE_KEY_LOCK();
  53550. #endif
  53551. #ifdef HAVE_ED25519
  53552. PRIVATE_KEY_UNLOCK();
  53553. if (ret == 0)
  53554. ret = ed25519_test();
  53555. PRIVATE_KEY_LOCK();
  53556. #endif
  53557. #ifdef HAVE_CURVE25519
  53558. if (ret == 0)
  53559. ret = curve25519_test();
  53560. #endif
  53561. #ifndef NO_AES
  53562. #ifdef HAVE_AESGCM
  53563. if (ret == 0)
  53564. ret = aesgcm_test();
  53565. #endif
  53566. #ifdef HAVE_AES_CBC
  53567. if (ret == 0)
  53568. ret = aes_test();
  53569. #endif
  53570. #ifdef WOLFSSL_AES_XTS
  53571. if (ret == 0)
  53572. ret = aes_xts_test();
  53573. #endif
  53574. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53575. if (ret == 0)
  53576. ret = aesccm_test();
  53577. #endif
  53578. #endif /* !NO_AES */
  53579. #ifndef NO_DES3
  53580. if (ret == 0)
  53581. ret = des3_test();
  53582. #endif /* !NO_DES3 */
  53583. #ifndef NO_SHA
  53584. if (ret == 0)
  53585. ret = sha_test();
  53586. #endif
  53587. #ifndef NO_SHA256
  53588. if (ret == 0)
  53589. ret = sha256_test();
  53590. #endif
  53591. #ifdef WOLFSSL_SHA384
  53592. if (ret == 0)
  53593. ret = sha384_test();
  53594. #endif
  53595. #ifdef WOLFSSL_SHA512
  53596. if (ret == 0)
  53597. ret = sha512_test();
  53598. #ifdef WOLFSSL_SHA3
  53599. if (ret == 0)
  53600. ret = sha3_test();
  53601. #endif
  53602. #endif
  53603. #ifndef NO_HMAC
  53604. #ifndef NO_SHA
  53605. if (ret == 0)
  53606. ret = hmac_sha_test();
  53607. #endif
  53608. #ifndef NO_SHA256
  53609. if (ret == 0)
  53610. ret = hmac_sha256_test();
  53611. #endif
  53612. #ifdef WOLFSSL_SHA3
  53613. if (ret == 0)
  53614. ret = hmac_sha3_test();
  53615. #endif
  53616. #endif
  53617. #ifndef NO_PWDBASED
  53618. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  53619. PRIVATE_KEY_UNLOCK();
  53620. if (ret == 0)
  53621. ret = pbkdf2_test();
  53622. PRIVATE_KEY_LOCK();
  53623. #endif
  53624. #endif
  53625. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53626. if (ret == 0)
  53627. ret = cmac_test();
  53628. #endif
  53629. /* restore devId */
  53630. devId = origDevId;
  53631. return ret;
  53632. }
  53633. #endif /* ! WC_TEST_NO_CRYPTOCB_SW_TEST */
  53634. #endif /* WOLF_CRYPTO_CB */
  53635. #ifdef WOLFSSL_CERT_PIV
  53636. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void)
  53637. {
  53638. wc_test_ret_t ret;
  53639. wc_CertPIV piv;
  53640. /* Template for Identiv PIV cert, nonce and signature */
  53641. WOLFSSL_SMALL_STACK_STATIC const byte pivCertIdentiv[] = {
  53642. 0x0A, 0x0B,
  53643. 0x53, 0x09, /* NIST PIV Cert */
  53644. 0x70, 0x02, /* Certificate */
  53645. 0x30, 0x00,
  53646. 0x71, 0x01, 0x05, /* Cert Info */
  53647. 0xFE, 0x00, /* Error Detection */
  53648. 0x0B, 0x01, 0x00, /* Nonce */
  53649. 0x0C, 0x01, 0x00, /* Signed Nonce */
  53650. };
  53651. /* PIV certificate data including certificate, info and error detection. */
  53652. WOLFSSL_SMALL_STACK_STATIC const byte pivCert[] = {
  53653. 0x53, 0x09, /* NIST PIV Cert */
  53654. 0x70, 0x02, /* Certificate */
  53655. 0x30, 0x00,
  53656. 0x71, 0x01, 0x04, /* Cert Info */
  53657. 0xFE, 0x00, /* Error Detection */
  53658. };
  53659. WOLFSSL_ENTER("certpiv_test");
  53660. XMEMSET(&piv, 0, sizeof(piv));
  53661. /* Test with Identiv 0x0A, 0x0B and 0x0C markers */
  53662. ret = wc_ParseCertPIV(&piv, pivCertIdentiv, sizeof(pivCertIdentiv));
  53663. if (ret != 0) {
  53664. return WC_TEST_RET_ENC_EC(ret);
  53665. }
  53666. if (!piv.isIdentiv) {
  53667. return WC_TEST_RET_ENC_NC;
  53668. }
  53669. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53670. return WC_TEST_RET_ENC_NC;
  53671. }
  53672. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53673. return WC_TEST_RET_ENC_NC;
  53674. }
  53675. if ((piv.compression != ASN_PIV_CERT_INFO_GZIP)) {
  53676. return WC_TEST_RET_ENC_NC;
  53677. }
  53678. if (!piv.isX509) {
  53679. return WC_TEST_RET_ENC_NC;
  53680. }
  53681. if ((piv.nonce == NULL) || (piv.nonceSz != 1)) {
  53682. return WC_TEST_RET_ENC_NC;
  53683. }
  53684. if ((piv.signedNonce == NULL) || (piv.signedNonceSz != 1)) {
  53685. return WC_TEST_RET_ENC_NC;
  53686. }
  53687. XMEMSET(&piv, 0, sizeof(piv));
  53688. /* Test with NIST PIV format */
  53689. ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert));
  53690. if (ret != 0) {
  53691. return WC_TEST_RET_ENC_EC(ret);
  53692. }
  53693. if (piv.isIdentiv) {
  53694. return WC_TEST_RET_ENC_NC;
  53695. }
  53696. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53697. return WC_TEST_RET_ENC_NC;
  53698. }
  53699. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53700. return WC_TEST_RET_ENC_NC;
  53701. }
  53702. if ((piv.compression != 0)) {
  53703. return WC_TEST_RET_ENC_NC;
  53704. }
  53705. if (!piv.isX509) {
  53706. return WC_TEST_RET_ENC_NC;
  53707. }
  53708. return ret;
  53709. }
  53710. #endif /* WOLFSSL_CERT_PIV */
  53711. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  53712. static time_t time_cb(time_t* t)
  53713. {
  53714. if (t != NULL) {
  53715. *t = 99;
  53716. }
  53717. return 99;
  53718. }
  53719. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void)
  53720. {
  53721. time_t t;
  53722. wc_test_ret_t ret;
  53723. WOLFSSL_ENTER("time_test");
  53724. ret = wc_SetTimeCb(time_cb);
  53725. if (ret != 0)
  53726. return WC_TEST_RET_ENC_EC(ret);
  53727. t = wc_Time(NULL);
  53728. if (t != 99)
  53729. return WC_TEST_RET_ENC_NC;
  53730. ret = wc_GetTime(&t, sizeof(time_t));
  53731. if (ret != 0)
  53732. return WC_TEST_RET_ENC_EC(ret);
  53733. if (t != 99)
  53734. return WC_TEST_RET_ENC_NC;
  53735. ret = wc_SetTimeCb(NULL);
  53736. if (ret != 0)
  53737. return WC_TEST_RET_ENC_EC(ret);
  53738. return 0;
  53739. }
  53740. #endif
  53741. #ifdef WOLFSSL_AES_SIV
  53742. typedef struct {
  53743. const byte key[33];
  53744. word32 keySz;
  53745. const byte nonce[49];
  53746. word32 nonceSz;
  53747. byte numAssoc;
  53748. const byte assoc1[81];
  53749. word32 assoc1Sz;
  53750. const byte assoc2[11];
  53751. word32 assoc2Sz;
  53752. const byte plaintext[83];
  53753. word32 plaintextSz;
  53754. const byte siv[WC_AES_BLOCK_SIZE+1];
  53755. const byte ciphertext[82];
  53756. word32 ciphertextSz;
  53757. } AesSivTestVector;
  53758. #define AES_SIV_TEST_VECTORS 9
  53759. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
  53760. {
  53761. WOLFSSL_SMALL_STACK_STATIC const AesSivTestVector testVectors[AES_SIV_TEST_VECTORS] = {
  53762. /* These test vectors come from chrony 4.1's SIV unit tests. */
  53763. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53764. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53765. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53766. 1,
  53767. "", 0,
  53768. "", 0,
  53769. "", 0,
  53770. "\x22\x3e\xb5\x94\xe0\xe0\x25\x4b\x00\x25\x8e\x21\x9a\x1c\xa4\x21",
  53771. "", 0
  53772. },
  53773. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53774. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53775. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53776. 1,
  53777. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53778. "", 0,
  53779. "", 0,
  53780. "\xd7\x20\x19\x89\xc6\xdb\xc6\xd6\x61\xfc\x62\xbc\x86\x5e\xee\xef",
  53781. "", 0
  53782. },
  53783. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53784. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53785. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53786. 1,
  53787. "", 0,
  53788. "", 0,
  53789. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53790. "\xb6\xc1\x60\xe9\xc2\xfd\x2a\xe8\xde\xc5\x36\x8b\x2a\x33\xed\xe1",
  53791. "\x14\xff\xb3\x97\x34\x5c\xcb\xe4\x4a\xa4\xde\xac\xd9\x36\x90\x46", 16
  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. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e", 15,
  53796. 1,
  53797. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c", 15,
  53798. "", 0,
  53799. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4", 15,
  53800. "\x03\x8c\x41\x51\xba\x7a\x8f\x77\x6e\x56\x31\x99\x42\x0b\xc7\x03",
  53801. "\xe7\x6c\x67\xc9\xda\xb7\x0d\x5b\x44\x06\x26\x5a\xd0\xd2\x3b", 15
  53802. },
  53803. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53804. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53805. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53806. 1,
  53807. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53808. "", 0,
  53809. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7", 16,
  53810. "\x5c\x05\x23\x65\xf4\x57\x0a\xa0\xfb\x38\x3e\xce\x9b\x75\x85\xeb",
  53811. "\x68\x85\x19\x36\x0c\x7c\x48\x11\x40\xcb\x9b\x57\x9a\x0e\x65\x32", 16
  53812. },
  53813. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53814. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53815. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53816. "\xd5", 17,
  53817. 1,
  53818. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b"
  53819. "\xa0", 17,
  53820. "", 0,
  53821. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7"
  53822. "\x08", 17,
  53823. "\xaf\x58\x4b\xe7\x82\x1e\x96\x19\x29\x91\x25\xe0\xdd\x80\x3b\x49",
  53824. "\xa5\x11\xcd\xb6\x08\xf3\x76\xa0\xb6\xfa\x15\x82\xf3\x95\xe1\xeb"
  53825. "\xbd", 17
  53826. },
  53827. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53828. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53829. "\xb0\x5a\x1b\xc7\x56\xe7\xb6\x2c\xb4\x85\xe5\x56\xa5\x28\xc0\x6c"
  53830. "\x2f\x3b\x0b\x9d\x1a\x0c\xdf\x69\x47\xe0\xcc\xc0\x87\xaa\x5c\x09"
  53831. "\x98\x48\x8d\x6a\x8e\x1e\x05\xd7\x8b\x68\x74\x83\xb5\x1d\xf1\x2c", 48,
  53832. 1,
  53833. "\xe5\x8b\xd2\x6a\x30\xc5\xc5\x61\xcc\xbd\x7c\x27\xbf\xfe\xf9\x06"
  53834. "\x00\x5b\xd7\xfc\x11\x0b\xcf\x16\x61\xef\xac\x05\xa7\xaf\xec\x27"
  53835. "\x41\xc8\x5e\x9e\x0d\xf9\x2f\xaf\x20\x79\x17\xe5\x17\x91\x2a\x27"
  53836. "\x34\x1c\xbc\xaf\xeb\xef\x7f\x52\xe7\x1e\x4c\x2a\xca\xbd\x2b\xbe"
  53837. "\x34\xd6\xfb\x69\xd3\x3e\x49\x59\x60\xb4\x26\xc9\xb8\xce\xba", 79,
  53838. "", 0,
  53839. "\x6c\xe7\xcf\x7e\xab\x7b\xa0\xe1\xa7\x22\xcb\x88\xde\x5e\x42\xd2"
  53840. "\xec\x79\xe0\xa2\xcf\x5f\x0f\x6f\x6b\x89\x57\xcd\xae\x17\xd4\xc2"
  53841. "\xf3\x1b\xa2\xa8\x13\x78\x23\x2f\x83\xa8\xd4\x0c\xc0\xd2\xf3\x99"
  53842. "\xae\x81\xa1\xca\x5b\x5f\x45\xa6\x6f\x0c\x8a\xf3\xd4\x67\x40\x81"
  53843. "\x26\xe2\x01\x86\xe8\x5a\xd5\xf8\x58\x80\x9f\x56\xaa\x76\x96\xbf"
  53844. "\x31", 81,
  53845. "\x9a\x06\x33\xe0\xee\x00\x6a\x9b\xc8\x20\xd5\xe2\xc2\xed\xb5\x75",
  53846. "\xfa\x9e\x42\x2a\x31\x6b\xda\xca\xaa\x7d\x31\x8b\x84\x7a\xb8\xd7"
  53847. "\x8a\x81\x25\x64\xed\x41\x9b\xa9\x77\x10\xbd\x05\x0c\x4e\xc5\x31"
  53848. "\x0c\xa2\x86\xec\x8a\x94\xc8\x24\x23\x3c\x13\xee\xa5\x51\xc9\xdf"
  53849. "\x48\xc9\x55\xc5\x2f\x40\x73\x3f\x98\xbb\x8d\x69\x78\x46\x64\x17"
  53850. "\x8d\x49\x2f\x14\x62\xa4\x7c\x2a\x57\x38\x87\xce\xc6\x72\xd3\x5c"
  53851. "\xa1", 81
  53852. },
  53853. /* Example A.1 from RFC5297 */
  53854. {
  53855. "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0"
  53856. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 32,
  53857. "", 0,
  53858. 1,
  53859. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53860. "\x20\x21\x22\x23\x24\x25\x26\x27", 24,
  53861. "", 0,
  53862. "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee", 14,
  53863. "\x85\x63\x2d\x07\xc6\xe8\xf3\x7f\x95\x0a\xcd\x32\x0a\x2e\xcc\x93",
  53864. "\x40\xc0\x2b\x96\x90\xc4\xdc\x04\xda\xef\x7f\x6a\xfe\x5c", 14
  53865. },
  53866. /* Example A.2 from RFC5297 */
  53867. {
  53868. "\x7f\x7e\x7d\x7c\x7b\x7a\x79\x78\x77\x76\x75\x74\x73\x72\x71\x70"
  53869. "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", 32,
  53870. "\x09\xf9\x11\x02\x9d\x74\xe3\x5b\xd8\x41\x56\xc5\x63\x56\x88\xc0", 16,
  53871. 2,
  53872. "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
  53873. "\xde\xad\xda\xda\xde\xad\xda\xda\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
  53874. "\x77\x66\x55\x44\x33\x22\x11\x00", 40,
  53875. "\x10\x20\x30\x40\x50\x60\x70\x80\x90\xa0", 10,
  53876. "\x74\x68\x69\x73\x20\x69\x73\x20\x73\x6f\x6d\x65\x20\x70\x6c\x61"
  53877. "\x69\x6e\x74\x65\x78\x74\x20\x74\x6f\x20\x65\x6e\x63\x72\x79\x70"
  53878. "\x74\x20\x75\x73\x69\x6e\x67\x20\x53\x49\x56\x2d\x41\x45\x53", 47,
  53879. "\x7b\xdb\x6e\x3b\x43\x26\x67\xeb\x06\xf4\xd1\x4b\xff\x2f\xbd\x0f",
  53880. "\xcb\x90\x0f\x2f\xdd\xbe\x40\x43\x26\x60\x19\x65\xc8\x89\xbf\x17"
  53881. "\xdb\xa7\x7c\xeb\x09\x4f\xa6\x63\xb7\xa3\xf7\x48\xba\x8a\xf8\x29"
  53882. "\xea\x64\xad\x54\x4a\x27\x2e\x9c\x48\x5b\x62\xa3\xfd\x5c\x0d", 47
  53883. }
  53884. };
  53885. int i;
  53886. byte computedCiphertext[82];
  53887. byte computedPlaintext[82];
  53888. byte siv[WC_AES_BLOCK_SIZE];
  53889. wc_test_ret_t ret = 0;
  53890. WOLFSSL_ENTER("aes_siv_test");
  53891. /* First test legacy "exactly one Assoc" interface. */
  53892. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53893. if (testVectors[i].numAssoc != 1)
  53894. continue;
  53895. ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz,
  53896. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53897. testVectors[i].nonce, testVectors[i].nonceSz,
  53898. testVectors[i].plaintext,
  53899. testVectors[i].plaintextSz, siv,
  53900. computedCiphertext);
  53901. if (ret != 0) {
  53902. return WC_TEST_RET_ENC_EC(ret);
  53903. }
  53904. ret = XMEMCMP(siv, testVectors[i].siv, WC_AES_BLOCK_SIZE);
  53905. if (ret != 0) {
  53906. return WC_TEST_RET_ENC_NC;
  53907. }
  53908. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53909. testVectors[i].ciphertextSz);
  53910. if (ret != 0) {
  53911. return WC_TEST_RET_ENC_NC;
  53912. }
  53913. ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz,
  53914. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53915. testVectors[i].nonce, testVectors[i].nonceSz,
  53916. computedCiphertext, testVectors[i].plaintextSz,
  53917. siv, computedPlaintext);
  53918. if (ret != 0) {
  53919. return WC_TEST_RET_ENC_EC(ret);
  53920. }
  53921. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53922. testVectors[i].plaintextSz);
  53923. if (ret != 0) {
  53924. return WC_TEST_RET_ENC_NC;
  53925. }
  53926. }
  53927. /* Then test "multiple Assoc" interface. */
  53928. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53929. const struct AesSivAssoc assoc[2] = {
  53930. { testVectors[i].assoc1, testVectors[i].assoc1Sz },
  53931. { testVectors[i].assoc2, testVectors[i].assoc2Sz }
  53932. };
  53933. ret = wc_AesSivEncrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53934. assoc, testVectors[i].numAssoc,
  53935. testVectors[i].nonce, testVectors[i].nonceSz,
  53936. testVectors[i].plaintext,
  53937. testVectors[i].plaintextSz, siv,
  53938. computedCiphertext);
  53939. if (ret != 0) {
  53940. return WC_TEST_RET_ENC_EC(ret);
  53941. }
  53942. ret = XMEMCMP(siv, testVectors[i].siv, WC_AES_BLOCK_SIZE);
  53943. if (ret != 0) {
  53944. return WC_TEST_RET_ENC_NC;
  53945. }
  53946. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53947. testVectors[i].ciphertextSz);
  53948. if (ret != 0) {
  53949. return WC_TEST_RET_ENC_NC;
  53950. }
  53951. ret = wc_AesSivDecrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53952. assoc, testVectors[i].numAssoc,
  53953. testVectors[i].nonce, testVectors[i].nonceSz,
  53954. computedCiphertext,
  53955. testVectors[i].plaintextSz, siv,
  53956. computedPlaintext);
  53957. if (ret != 0) {
  53958. return WC_TEST_RET_ENC_EC(ret);
  53959. }
  53960. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53961. testVectors[i].plaintextSz);
  53962. if (ret != 0) {
  53963. return WC_TEST_RET_ENC_NC;
  53964. }
  53965. }
  53966. return 0;
  53967. }
  53968. #endif
  53969. #undef ERROR_OUT
  53970. static const int fiducial4 = WC_TEST_RET_LN;
  53971. /* print the fiducial line numbers assigned above, allowing confirmation of
  53972. * source code version match when in doubt.
  53973. */
  53974. static void print_fiducials(void) {
  53975. printf(" [fiducial line numbers: %d %d %d %d]\n",
  53976. fiducial1, fiducial2, fiducial3, fiducial4);
  53977. }
  53978. #else
  53979. #ifndef NO_MAIN_DRIVER
  53980. int main(void) { return 0; }
  53981. #endif
  53982. #endif /* NO_CRYPT_TEST */