test.c 2.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869598705987159872598735987459875598765987759878598795988059881598825988359884598855988659887
  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(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0))
  8781. static wc_test_ret_t aescfb1_test(void)
  8782. {
  8783. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8784. Aes *enc = NULL;
  8785. #else
  8786. Aes enc[1];
  8787. #endif
  8788. byte cipher[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. #ifndef WOLFCRYPT_ONLY
  8925. ret = EVP_test(wolfSSL_EVP_aes_128_cfb1(), key1, iv, msg1, sizeof(msg1),
  8926. cipher, sizeof(msg1));
  8927. if (ret != 0) {
  8928. goto out;
  8929. }
  8930. #endif
  8931. #endif
  8932. #endif /* WOLFSSL_AES_128 */
  8933. #ifdef WOLFSSL_AES_192
  8934. /* 192 key tests */
  8935. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8936. if (ret != 0)
  8937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8938. XMEMSET(cipher, 0, sizeof(cipher));
  8939. ret = wc_AesCfb1Encrypt(enc, cipher, msg2, 4);
  8940. if (ret != 0)
  8941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8942. if (XMEMCMP(cipher, cipher2, sizeof(cipher2)) != 0)
  8943. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8944. #ifdef OPENSSL_EXTRA
  8945. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8946. if (ret != 0)
  8947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8948. XMEMSET(cipher, 0, sizeof(cipher));
  8949. ret = wc_AesCfb1Encrypt(enc, cipher, msg2,
  8950. sizeof(msg2) * WOLFSSL_BIT_SIZE);
  8951. if (ret != 0)
  8952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8953. #ifndef WOLFCRYPT_ONLY
  8954. ret = EVP_test(wolfSSL_EVP_aes_192_cfb1(), key2, iv2, msg2, sizeof(msg2),
  8955. cipher, sizeof(msg2));
  8956. if (ret != 0) {
  8957. goto out;
  8958. }
  8959. #endif
  8960. #endif
  8961. #endif /* WOLFSSL_AES_192 */
  8962. #ifdef WOLFSSL_AES_256
  8963. /* 256 key tests */
  8964. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8965. if (ret != 0)
  8966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8967. XMEMSET(cipher, 0, sizeof(cipher));
  8968. ret = wc_AesCfb1Encrypt(enc, cipher, msg3, 10);
  8969. if (ret != 0)
  8970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8971. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  8972. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8973. #ifdef OPENSSL_EXTRA
  8974. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8975. if (ret != 0)
  8976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8977. XMEMSET(cipher, 0, sizeof(cipher));
  8978. ret = wc_AesCfb1Encrypt(enc, cipher, msg3,
  8979. sizeof(msg3) * WOLFSSL_BIT_SIZE);
  8980. if (ret != 0)
  8981. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8982. #ifndef WOLFCRYPT_ONLY
  8983. ret = EVP_test(wolfSSL_EVP_aes_256_cfb1(), key3, iv3, msg3, sizeof(msg3),
  8984. cipher, sizeof(msg3));
  8985. if (ret != 0) {
  8986. goto out;
  8987. }
  8988. #endif
  8989. #endif
  8990. #endif /* WOLFSSL_AES_256 */
  8991. out:
  8992. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8993. wc_AesDelete(enc, &enc);
  8994. #else
  8995. wc_AesFree(enc);
  8996. #endif
  8997. #ifdef HAVE_AES_DECRYPT
  8998. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8999. wc_AesDelete(dec, &dec);
  9000. #else
  9001. wc_AesFree(dec);
  9002. #endif
  9003. #endif
  9004. return ret;
  9005. }
  9006. static wc_test_ret_t aescfb8_test(void)
  9007. {
  9008. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9009. Aes *enc = NULL;
  9010. #else
  9011. Aes enc[1];
  9012. #endif
  9013. byte cipher[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. ret = EVP_test(wolfSSL_EVP_aes_128_cfb8(), key1, iv, msg1, sizeof(msg1),
  9112. cipher1, sizeof(cipher1));
  9113. if (ret != 0) {
  9114. return ret;
  9115. }
  9116. #endif
  9117. ret = wc_AesSetKey(enc, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9118. if (ret != 0)
  9119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9120. #ifdef HAVE_AES_DECRYPT
  9121. /* decrypt uses AES_ENCRYPTION */
  9122. ret = wc_AesSetKey(dec, key1, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9123. if (ret != 0)
  9124. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9125. #endif
  9126. XMEMSET(cipher, 0, sizeof(cipher));
  9127. ret = wc_AesCfb8Encrypt(enc, cipher, msg1, sizeof(msg1));
  9128. if (ret != 0)
  9129. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9130. if (XMEMCMP(cipher, cipher1, sizeof(cipher1)) != 0)
  9131. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9132. #ifdef HAVE_AES_DECRYPT
  9133. ret = wc_AesCfb8Decrypt(dec, plain, cipher, sizeof(msg1));
  9134. if (ret != 0)
  9135. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9136. if (XMEMCMP(plain, msg1, sizeof(msg1)) != 0)
  9137. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9138. #endif /* HAVE_AES_DECRYPT */
  9139. #endif /* WOLFSSL_AES_128 */
  9140. #ifdef WOLFSSL_AES_192
  9141. /* 192 key tests */
  9142. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  9143. if (ret != 0)
  9144. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9145. XMEMSET(cipher, 0, sizeof(cipher));
  9146. ret = wc_AesCfb8Encrypt(enc, cipher, msg2, sizeof(msg2));
  9147. if (ret != 0)
  9148. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9149. if (XMEMCMP(cipher, cipher2, sizeof(msg2)) != 0)
  9150. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9151. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9152. ret = EVP_test(wolfSSL_EVP_aes_192_cfb8(), key2, iv2, msg2, sizeof(msg2),
  9153. cipher2, sizeof(msg2));
  9154. if (ret != 0) {
  9155. return ret;
  9156. }
  9157. #endif
  9158. #endif /* WOLFSSL_AES_192 */
  9159. #ifdef WOLFSSL_AES_256
  9160. /* 256 key tests */
  9161. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  9162. if (ret != 0)
  9163. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9164. XMEMSET(cipher, 0, sizeof(cipher));
  9165. ret = wc_AesCfb8Encrypt(enc, cipher, msg3, sizeof(msg3));
  9166. if (ret != 0)
  9167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9168. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  9169. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9170. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9171. ret = EVP_test(wolfSSL_EVP_aes_256_cfb8(), key3, iv3, msg3, sizeof(msg3),
  9172. cipher3, sizeof(msg3));
  9173. if (ret != 0) {
  9174. goto out;
  9175. }
  9176. #endif
  9177. #endif /* WOLFSSL_AES_256 */
  9178. out:
  9179. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9180. wc_AesDelete(enc, &enc);
  9181. #else
  9182. wc_AesFree(enc);
  9183. #endif
  9184. #ifdef HAVE_AES_DECRYPT
  9185. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9186. wc_AesDelete(dec, &dec);
  9187. #else
  9188. wc_AesFree(dec);
  9189. #endif
  9190. #endif
  9191. return ret;
  9192. }
  9193. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  9194. #endif /* WOLFSSL_AES_CFB */
  9195. #ifndef HAVE_RENESAS_SYNC
  9196. static wc_test_ret_t aes_key_size_test(void)
  9197. {
  9198. wc_test_ret_t ret;
  9199. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9200. Aes *aes = NULL;
  9201. #else
  9202. Aes aes[1];
  9203. #endif
  9204. byte key16[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9205. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9206. #ifndef WOLFSSL_CRYPTOCELL
  9207. byte key24[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9208. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9209. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
  9210. #endif
  9211. byte key32[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9212. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9213. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9214. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9215. byte iv[] = "1234567890abcdef";
  9216. #ifndef HAVE_FIPS
  9217. word32 keySize;
  9218. #endif
  9219. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9220. aes = wc_AesNew(HEAP_HINT, devId, &ret);
  9221. if (aes == NULL)
  9222. return WC_TEST_RET_ENC_EC(ret);
  9223. #else
  9224. ret = wc_AesInit(aes, HEAP_HINT, devId);
  9225. /* 0 check OK for FIPSv1 */
  9226. if (ret != 0)
  9227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9228. #endif
  9229. #if !defined(HAVE_FIPS) || \
  9230. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  9231. /* w/ FIPS v1 (cert 2425) wc_AesInit just returns 0 always as it's not
  9232. * supported with that FIPS version */
  9233. ret = wc_AesInit(NULL, HEAP_HINT, devId);
  9234. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9235. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9236. #endif
  9237. #ifndef HAVE_FIPS
  9238. /* Parameter Validation testing. */
  9239. ret = wc_AesGetKeySize(NULL, NULL);
  9240. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9241. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9242. ret = wc_AesGetKeySize(aes, NULL);
  9243. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9244. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9245. ret = wc_AesGetKeySize(NULL, &keySize);
  9246. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9247. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9248. /* Crashes in FIPS */
  9249. ret = wc_AesSetKey(NULL, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9250. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9252. #endif
  9253. /* NULL IV indicates to use all zeros IV. */
  9254. ret = wc_AesSetKey(aes, key16, sizeof(key16), NULL, AES_ENCRYPTION);
  9255. #ifdef WOLFSSL_AES_128
  9256. if (ret != 0)
  9257. #else
  9258. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9259. #endif
  9260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9261. ret = wc_AesSetKey(aes, key32, sizeof(key32) - 1, iv, AES_ENCRYPTION);
  9262. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9264. /* CryptoCell handles rounds internally */
  9265. #if !defined(HAVE_FIPS) && !defined(WOLFSSL_CRYPTOCELL)
  9266. /* PSA don't use aes->rounds */
  9267. #if !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_AES)
  9268. /* Force invalid rounds */
  9269. aes->rounds = 16;
  9270. ret = wc_AesGetKeySize(aes, &keySize);
  9271. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9273. #endif
  9274. #endif
  9275. ret = wc_AesSetKey(aes, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9276. #ifdef WOLFSSL_AES_128
  9277. if (ret != 0)
  9278. #else
  9279. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9280. #endif
  9281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9282. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_128)
  9283. ret = wc_AesGetKeySize(aes, &keySize);
  9284. if (ret != 0 || keySize != sizeof(key16))
  9285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9286. #endif
  9287. #ifndef WOLFSSL_CRYPTOCELL
  9288. /* Cryptocell only supports AES-128 key size */
  9289. ret = wc_AesSetKey(aes, key24, sizeof(key24), iv, AES_ENCRYPTION);
  9290. #ifdef WOLFSSL_AES_192
  9291. if (ret != 0)
  9292. #else
  9293. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9294. #endif
  9295. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9296. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_192)
  9297. ret = wc_AesGetKeySize(aes, &keySize);
  9298. if (ret != 0 || keySize != sizeof(key24))
  9299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9300. #endif
  9301. ret = wc_AesSetKey(aes, key32, sizeof(key32), iv, AES_ENCRYPTION);
  9302. #ifdef WOLFSSL_AES_256
  9303. if (ret != 0)
  9304. #else
  9305. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9306. #endif
  9307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9308. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_256)
  9309. ret = wc_AesGetKeySize(aes, &keySize);
  9310. if (ret != 0 || keySize != sizeof(key32))
  9311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9312. #endif
  9313. #endif /* !WOLFSSL_CRYPTOCELL */
  9314. ret = 0; /* success */
  9315. out:
  9316. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9317. wc_AesDelete(aes, &aes);
  9318. #else
  9319. wc_AesFree(aes);
  9320. #endif
  9321. return ret;
  9322. }
  9323. #endif /* !HAVE_RENESAS_SYNC */
  9324. #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  9325. /* test vectors from http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html */
  9326. #ifdef WOLFSSL_AES_128
  9327. static wc_test_ret_t aes_xts_128_test(void)
  9328. {
  9329. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9330. XtsAes *aes = NULL;
  9331. #else
  9332. XtsAes aes[1];
  9333. #endif
  9334. int aes_inited = 0;
  9335. wc_test_ret_t ret = 0;
  9336. unsigned char buf[WC_AES_BLOCK_SIZE * 2 + 8];
  9337. unsigned char cipher[WC_AES_BLOCK_SIZE * 2 + 8];
  9338. #ifdef WOLFSSL_AESXTS_STREAM
  9339. struct XtsAesStreamData stream;
  9340. #endif
  9341. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9342. !defined(WOLFSSL_AFALG)
  9343. #define LARGE_XTS_SZ 1024
  9344. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9345. byte* large_input = NULL;
  9346. #else
  9347. byte large_input[LARGE_XTS_SZ];
  9348. #endif
  9349. #endif
  9350. /* 128 key tests */
  9351. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9352. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  9353. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  9354. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  9355. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  9356. };
  9357. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9358. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9359. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9360. };
  9361. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9362. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9363. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9364. };
  9365. /* plain text test of partial block is not from NIST test vector list */
  9366. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9367. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9368. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9369. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9370. };
  9371. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9372. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a,
  9373. 0x82, 0x50, 0x81, 0xd5, 0xbe, 0x47, 0x1c, 0x63
  9374. };
  9375. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9376. 0x39, 0x25, 0x79, 0x05, 0xdf, 0xcc, 0x77, 0x76,
  9377. 0x6c, 0x87, 0x0a, 0x80, 0x6a, 0x60, 0xe3, 0xc0,
  9378. 0x93, 0xd1, 0x2a, 0xcf, 0xcb, 0x51, 0x42, 0xfa,
  9379. 0x09, 0x69, 0x89, 0x62, 0x5b, 0x60, 0xdb, 0x16
  9380. };
  9381. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9382. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9383. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9384. };
  9385. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9386. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9387. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9388. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9389. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9390. };
  9391. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9392. 0xd6, 0xbe, 0x04, 0x6d, 0x41, 0xf2, 0x3b, 0x5e,
  9393. 0xd7, 0x0b, 0x6b, 0x3d, 0x5c, 0x8e, 0x66, 0x23,
  9394. 0x2b, 0xe6, 0xb8, 0x07, 0xd4, 0xdc, 0xc6, 0x0e,
  9395. 0xff, 0x8d, 0xbc, 0x1d, 0x9f, 0x7f, 0xc8, 0x22
  9396. };
  9397. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9398. 0x2b, 0xf7, 0x2c, 0xf3, 0xeb, 0x85, 0xef, 0x7b,
  9399. 0x0b, 0x76, 0xa0, 0xaa, 0xf3, 0x3f, 0x25, 0x8b,
  9400. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a
  9401. };
  9402. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9403. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9404. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9405. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9406. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9407. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9408. };
  9409. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9410. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9411. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9412. };
  9413. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9414. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9415. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9416. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9417. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9418. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9419. };
  9420. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9421. 0xA2, 0x07, 0x47, 0x76, 0x3F, 0xEC, 0x0C, 0x23,
  9422. 0x1B, 0xD0, 0xBD, 0x46, 0x9A, 0x27, 0x38, 0x12,
  9423. 0x95, 0x02, 0x3D, 0x5D, 0xC6, 0x94, 0x51, 0x36,
  9424. 0xA0, 0x85, 0xD2, 0x69, 0x6E, 0x87, 0x0A, 0xBF,
  9425. 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD
  9426. };
  9427. #endif /* HAVE_FIPS */
  9428. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9429. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9430. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9431. #endif
  9432. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  9433. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  9434. ret = EVP_test(wolfSSL_EVP_aes_128_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  9435. if (ret != 0) {
  9436. printf("EVP_aes_128_xts failed!\n");
  9437. goto out;
  9438. }
  9439. #endif
  9440. XMEMSET(buf, 0, sizeof(buf));
  9441. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9442. if (ret != 0)
  9443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9444. else
  9445. aes_inited = 1;
  9446. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9447. if (ret != 0)
  9448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9449. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9450. #if defined(WOLFSSL_ASYNC_CRYPT)
  9451. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9452. #endif
  9453. if (ret != 0)
  9454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9455. if (XMEMCMP(c2, buf, sizeof(c2)))
  9456. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9457. #ifdef WOLFSSL_AESXTS_STREAM
  9458. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9459. #if defined(WOLFSSL_ASYNC_CRYPT)
  9460. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9461. #endif
  9462. if (ret != 0)
  9463. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9464. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream);
  9465. #if defined(WOLFSSL_ASYNC_CRYPT)
  9466. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9467. #endif
  9468. if (ret != 0)
  9469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9470. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream);
  9471. #if defined(WOLFSSL_ASYNC_CRYPT)
  9472. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9473. #endif
  9474. if (ret != 0)
  9475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9476. if (XMEMCMP(c2, buf, sizeof(c2)))
  9477. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9478. #endif /* WOLFSSL_AESXTS_STREAM */
  9479. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9480. defined(WC_C_DYNAMIC_FALLBACK)
  9481. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9482. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9483. #if defined(WOLFSSL_ASYNC_CRYPT)
  9484. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9485. #endif
  9486. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9487. if (ret != 0)
  9488. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9489. if (XMEMCMP(c2, buf, sizeof(c2)))
  9490. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9491. #endif
  9492. XMEMSET(buf, 0, sizeof(buf));
  9493. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9494. if (ret != 0)
  9495. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9496. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9497. #if defined(WOLFSSL_ASYNC_CRYPT)
  9498. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9499. #endif
  9500. if (ret != 0)
  9501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9502. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  9503. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9504. #ifdef WOLFSSL_AESXTS_STREAM
  9505. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i2), &stream);
  9506. #if defined(WOLFSSL_ASYNC_CRYPT)
  9507. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9508. #endif
  9509. if (ret != 0)
  9510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9511. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  9512. #if defined(WOLFSSL_ASYNC_CRYPT)
  9513. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9514. #endif
  9515. if (ret != 0)
  9516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9517. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9518. #if defined(WOLFSSL_ASYNC_CRYPT)
  9519. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9520. #endif
  9521. if (ret != 0)
  9522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9523. if (XMEMCMP(c1, buf, sizeof(c1)))
  9524. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9525. #endif /* WOLFSSL_AESXTS_STREAM */
  9526. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9527. defined(WC_C_DYNAMIC_FALLBACK)
  9528. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9529. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9530. #if defined(WOLFSSL_ASYNC_CRYPT)
  9531. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9532. #endif
  9533. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9534. if (ret != 0)
  9535. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9536. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  9537. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9538. #endif
  9539. /* partial block encryption test */
  9540. XMEMSET(cipher, 0, sizeof(cipher));
  9541. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9542. #if defined(WOLFSSL_ASYNC_CRYPT)
  9543. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9544. #endif
  9545. if (ret != 0)
  9546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9547. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9548. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9549. #ifdef WOLFSSL_AESXTS_STREAM
  9550. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9551. #if defined(WOLFSSL_ASYNC_CRYPT)
  9552. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9553. #endif
  9554. if (ret != 0)
  9555. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9556. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  9557. #if defined(WOLFSSL_ASYNC_CRYPT)
  9558. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9559. #endif
  9560. if (ret != 0)
  9561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9562. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9563. #if defined(WOLFSSL_ASYNC_CRYPT)
  9564. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9565. #endif
  9566. if (ret != 0)
  9567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9568. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  9569. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9570. #endif /* WOLFSSL_AESXTS_STREAM */
  9571. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9572. defined(WC_C_DYNAMIC_FALLBACK)
  9573. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9574. XMEMSET(cipher, 0, sizeof(cipher));
  9575. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9576. #if defined(WOLFSSL_ASYNC_CRYPT)
  9577. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9578. #endif
  9579. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9580. if (ret != 0)
  9581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9582. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9583. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9584. #endif
  9585. /* partial block decrypt test */
  9586. XMEMSET(buf, 0, sizeof(buf));
  9587. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9588. if (ret != 0)
  9589. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9590. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9591. #if defined(WOLFSSL_ASYNC_CRYPT)
  9592. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9593. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9594. #else
  9595. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9596. #endif
  9597. #endif
  9598. if (ret != 0)
  9599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9600. if (XMEMCMP(pp, buf, sizeof(pp)))
  9601. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9602. #ifdef WOLFSSL_AESXTS_STREAM
  9603. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9604. #if defined(WOLFSSL_ASYNC_CRYPT)
  9605. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9606. #endif
  9607. if (ret != 0)
  9608. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9609. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  9610. #if defined(WOLFSSL_ASYNC_CRYPT)
  9611. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9612. #endif
  9613. if (ret != 0)
  9614. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9615. if (XMEMCMP(pp, buf, sizeof(pp)))
  9616. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9617. #endif /* WOLFSSL_AESXTS_STREAM */
  9618. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9619. defined(WC_C_DYNAMIC_FALLBACK)
  9620. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9621. XMEMSET(buf, 0, sizeof(buf));
  9622. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9623. #if defined(WOLFSSL_ASYNC_CRYPT)
  9624. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9625. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9626. #else
  9627. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9628. #endif
  9629. #endif
  9630. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9631. if (ret != 0)
  9632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9633. if (XMEMCMP(pp, buf, sizeof(pp)))
  9634. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9635. #endif
  9636. /* NIST decrypt test vector */
  9637. XMEMSET(buf, 0, sizeof(buf));
  9638. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9639. #if defined(WOLFSSL_ASYNC_CRYPT)
  9640. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9641. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9642. #else
  9643. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9644. #endif
  9645. #endif
  9646. if (ret != 0)
  9647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9648. if (XMEMCMP(p1, buf, sizeof(p1)))
  9649. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9650. #ifdef WOLFSSL_AESXTS_STREAM
  9651. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9652. #if defined(WOLFSSL_ASYNC_CRYPT)
  9653. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9654. #endif
  9655. if (ret != 0)
  9656. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9657. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  9658. #if defined(WOLFSSL_ASYNC_CRYPT)
  9659. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9660. #endif
  9661. if (ret != 0)
  9662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9663. if (XMEMCMP(p1, buf, sizeof(p1)))
  9664. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9665. #endif /* WOLFSSL_AESXTS_STREAM */
  9666. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9667. defined(WC_C_DYNAMIC_FALLBACK)
  9668. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9669. XMEMSET(buf, 0, sizeof(buf));
  9670. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9671. #if defined(WOLFSSL_ASYNC_CRYPT)
  9672. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9673. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9674. #else
  9675. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9676. #endif
  9677. #endif
  9678. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9679. if (ret != 0)
  9680. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9681. if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE))
  9682. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9683. #endif
  9684. /* fail case with decrypting using wrong key */
  9685. XMEMSET(buf, 0, sizeof(buf));
  9686. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9687. #if defined(WOLFSSL_ASYNC_CRYPT)
  9688. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9689. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9690. #else
  9691. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9692. #endif
  9693. #endif
  9694. if (ret != 0)
  9695. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9696. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  9697. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9698. /* set correct key and retest */
  9699. XMEMSET(buf, 0, sizeof(buf));
  9700. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  9701. if (ret != 0)
  9702. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9703. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9704. #if defined(WOLFSSL_ASYNC_CRYPT)
  9705. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9706. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9707. #else
  9708. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9709. #endif
  9710. #endif
  9711. if (ret != 0)
  9712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9713. if (XMEMCMP(p2, buf, sizeof(p2)))
  9714. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9715. #ifndef HAVE_FIPS
  9716. /* Test ciphertext stealing in-place. */
  9717. XMEMCPY(buf, p3, sizeof(p3));
  9718. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  9719. if (ret != 0)
  9720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9721. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  9722. #if defined(WOLFSSL_ASYNC_CRYPT)
  9723. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9724. #endif
  9725. if (ret != 0)
  9726. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9727. if (XMEMCMP(c3, buf, sizeof(c3)))
  9728. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9729. #ifdef WOLFSSL_AESXTS_STREAM
  9730. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  9731. #if defined(WOLFSSL_ASYNC_CRYPT)
  9732. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9733. #endif
  9734. if (ret != 0)
  9735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9736. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, WC_AES_BLOCK_SIZE, &stream);
  9737. #if defined(WOLFSSL_ASYNC_CRYPT)
  9738. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9739. #endif
  9740. if (ret != 0)
  9741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9742. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p3 + WC_AES_BLOCK_SIZE, sizeof(p3) - WC_AES_BLOCK_SIZE, &stream);
  9743. #if defined(WOLFSSL_ASYNC_CRYPT)
  9744. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9745. #endif
  9746. if (ret != 0)
  9747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9748. if (XMEMCMP(c3, buf, sizeof(c3)))
  9749. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9750. #endif /* WOLFSSL_AESXTS_STREAM */
  9751. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  9752. if (ret != 0)
  9753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9754. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  9755. #if defined(WOLFSSL_ASYNC_CRYPT)
  9756. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9757. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9758. #else
  9759. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9760. #endif
  9761. #endif
  9762. if (ret != 0)
  9763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9764. if (XMEMCMP(p3, buf, sizeof(p3)))
  9765. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9766. #ifdef WOLFSSL_AESXTS_STREAM
  9767. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  9768. #if defined(WOLFSSL_ASYNC_CRYPT)
  9769. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9770. #endif
  9771. if (ret != 0)
  9772. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9773. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, WC_AES_BLOCK_SIZE, &stream);
  9774. #if defined(WOLFSSL_ASYNC_CRYPT)
  9775. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9776. #endif
  9777. if (ret != 0)
  9778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9779. ret = wc_AesXtsDecryptFinal(aes, buf + WC_AES_BLOCK_SIZE, c3 + WC_AES_BLOCK_SIZE, sizeof(c3) - WC_AES_BLOCK_SIZE, &stream);
  9780. #if defined(WOLFSSL_ASYNC_CRYPT)
  9781. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9782. #endif
  9783. if (ret != 0)
  9784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9785. if (XMEMCMP(p3, buf, sizeof(p3)))
  9786. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9787. #endif /* WOLFSSL_AESXTS_STREAM */
  9788. #endif /* !HAVE_FIPS */
  9789. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9790. !defined(WOLFSSL_AFALG)
  9791. {
  9792. int i;
  9793. int j;
  9794. #ifdef WOLFSSL_AESXTS_STREAM
  9795. int k;
  9796. #endif
  9797. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9798. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  9799. DYNAMIC_TYPE_TMP_BUFFER);
  9800. if (large_input == NULL)
  9801. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  9802. #endif
  9803. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9804. large_input[i] = (byte)i;
  9805. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9806. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9807. if (ret != 0)
  9808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9809. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9810. sizeof(i1));
  9811. #if defined(WOLFSSL_ASYNC_CRYPT)
  9812. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9813. #endif
  9814. if (ret != 0)
  9815. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9816. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9817. if (ret != 0)
  9818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9819. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9820. sizeof(i1));
  9821. #if defined(WOLFSSL_ASYNC_CRYPT)
  9822. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9823. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9824. WC_ASYNC_FLAG_NONE);
  9825. #else
  9826. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9827. #endif
  9828. #endif
  9829. if (ret != 0)
  9830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9831. for (i = 0; i < j; i++) {
  9832. if (large_input[i] != (byte)i) {
  9833. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9834. }
  9835. }
  9836. }
  9837. #ifdef WOLFSSL_AESXTS_STREAM
  9838. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9839. large_input[i] = (byte)i;
  9840. /* first, encrypt block by block then decrypt with a one-shot call. */
  9841. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9842. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9843. if (ret != 0)
  9844. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9845. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9846. #if defined(WOLFSSL_ASYNC_CRYPT)
  9847. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9848. #endif
  9849. if (ret != 0)
  9850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9851. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  9852. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  9853. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9854. else
  9855. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  9856. #if defined(WOLFSSL_ASYNC_CRYPT)
  9857. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9858. #endif
  9859. if (ret != 0)
  9860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9861. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  9862. break;
  9863. }
  9864. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9865. if (ret != 0)
  9866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9867. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9868. sizeof(i1));
  9869. #if defined(WOLFSSL_ASYNC_CRYPT)
  9870. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9871. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9872. WC_ASYNC_FLAG_NONE);
  9873. #else
  9874. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9875. #endif
  9876. #endif
  9877. if (ret != 0)
  9878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9879. for (i = 0; i < j; i++) {
  9880. if (large_input[i] != (byte)i) {
  9881. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9882. }
  9883. }
  9884. }
  9885. /* second, encrypt with a one-shot call then decrypt block by block. */
  9886. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9887. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9888. if (ret != 0)
  9889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9890. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9891. sizeof(i1));
  9892. #if defined(WOLFSSL_ASYNC_CRYPT)
  9893. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9894. #endif
  9895. if (ret != 0)
  9896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9897. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9898. if (ret != 0)
  9899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9900. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9901. #if defined(WOLFSSL_ASYNC_CRYPT)
  9902. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9903. #endif
  9904. if (ret != 0)
  9905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9906. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  9907. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  9908. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9909. else
  9910. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  9911. #if defined(WOLFSSL_ASYNC_CRYPT)
  9912. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9913. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9914. WC_ASYNC_FLAG_NONE);
  9915. #else
  9916. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9917. #endif
  9918. #endif
  9919. if (ret != 0)
  9920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9921. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  9922. break;
  9923. }
  9924. for (i = 0; i < j; i++) {
  9925. if (large_input[i] != (byte)i) {
  9926. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9927. }
  9928. }
  9929. }
  9930. #endif /* WOLFSSL_AESXTS_STREAM */
  9931. }
  9932. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  9933. * !WOLFSSL_AFALG
  9934. */
  9935. out:
  9936. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9937. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  9938. !defined(WOLFSSL_NO_MALLOC)
  9939. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9940. #endif
  9941. if (aes_inited)
  9942. wc_AesXtsFree(aes);
  9943. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9944. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9945. #endif
  9946. return ret;
  9947. }
  9948. #endif /* WOLFSSL_AES_128 */
  9949. #ifdef WOLFSSL_AES_192
  9950. static wc_test_ret_t aes_xts_192_test(void)
  9951. {
  9952. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9953. XtsAes *aes = NULL;
  9954. #else
  9955. XtsAes aes[1];
  9956. #endif
  9957. int aes_inited = 0;
  9958. wc_test_ret_t ret = 0;
  9959. unsigned char buf[WC_AES_BLOCK_SIZE * 2 + 8];
  9960. unsigned char cipher[WC_AES_BLOCK_SIZE * 2 + 8];
  9961. #ifdef WOLFSSL_AESXTS_STREAM
  9962. struct XtsAesStreamData stream;
  9963. #endif
  9964. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9965. !defined(WOLFSSL_AFALG)
  9966. #define LARGE_XTS_SZ 1024
  9967. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9968. byte* large_input = NULL;
  9969. #else
  9970. byte large_input[LARGE_XTS_SZ];
  9971. #endif
  9972. #endif
  9973. /* 192 bit key tests */
  9974. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9975. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  9976. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  9977. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  9978. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  9979. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  9980. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3
  9981. };
  9982. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9983. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9984. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9985. };
  9986. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9987. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9988. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9989. };
  9990. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9991. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9992. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9993. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9994. };
  9995. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9996. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4,
  9997. 0xdb, 0x4e, 0xd3, 0x69, 0xdf, 0x8e, 0x3a, 0xe0
  9998. };
  9999. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10000. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10001. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10002. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10003. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10004. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10005. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a
  10006. };
  10007. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10008. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  10009. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  10010. };
  10011. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10012. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  10013. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  10014. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  10015. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  10016. };
  10017. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10018. 0x6c, 0xa6, 0xb5, 0x73, 0x48, 0xf1, 0x89, 0xfa,
  10019. 0xdd, 0x80, 0x72, 0x1f, 0xb8, 0x56, 0x0c, 0xa2,
  10020. 0x35, 0xd4, 0x08, 0xbf, 0x24, 0xcb, 0xec, 0xdb,
  10021. 0x81, 0xe0, 0xe6, 0x4f, 0x3d, 0x1c, 0x5c, 0x46
  10022. };
  10023. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  10024. 0xe9, 0x58, 0xfe, 0xab, 0x66, 0xb4, 0xf1, 0x79,
  10025. 0x91, 0x3f, 0x91, 0xdc, 0x6f, 0xdf, 0xd6, 0xac,
  10026. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4
  10027. };
  10028. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  10029. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  10030. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10031. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10032. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10033. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10034. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10035. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10036. };
  10037. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  10038. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10039. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10040. };
  10041. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  10042. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10043. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10044. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10045. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10046. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10047. };
  10048. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  10049. 0xa4, 0xf2, 0x71, 0x5d, 0x80, 0x60, 0x68, 0xa0,
  10050. 0x80, 0x61, 0xd7, 0xc1, 0x55, 0xc8, 0x3a, 0x2e,
  10051. 0xd7, 0xf4, 0x62, 0xaf, 0xbd, 0x2d, 0xf9, 0x5f,
  10052. 0xe8, 0xc5, 0x99, 0x3d, 0x58, 0x3c, 0xeb, 0xba,
  10053. 0x86, 0xea, 0x2c, 0x7e, 0x1f, 0xba, 0x81, 0xde
  10054. };
  10055. #endif /* HAVE_FIPS */
  10056. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10057. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10058. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10059. #endif
  10060. XMEMSET(buf, 0, sizeof(buf));
  10061. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10062. if (ret != 0)
  10063. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10064. else
  10065. aes_inited = 1;
  10066. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10067. if (ret != 0)
  10068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10069. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10070. #if defined(WOLFSSL_ASYNC_CRYPT)
  10071. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10072. #endif
  10073. if (ret != 0)
  10074. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10075. if (XMEMCMP(c2, buf, sizeof(c2)))
  10076. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10077. #ifdef WOLFSSL_AESXTS_STREAM
  10078. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10079. #if defined(WOLFSSL_ASYNC_CRYPT)
  10080. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10081. #endif
  10082. if (ret != 0)
  10083. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10084. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream);
  10085. #if defined(WOLFSSL_ASYNC_CRYPT)
  10086. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10087. #endif
  10088. if (ret != 0)
  10089. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10090. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream);
  10091. #if defined(WOLFSSL_ASYNC_CRYPT)
  10092. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10093. #endif
  10094. if (ret != 0)
  10095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10096. if (XMEMCMP(c2, buf, sizeof(c2)))
  10097. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10098. #endif /* WOLFSSL_AESXTS_STREAM */
  10099. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10100. defined(WC_C_DYNAMIC_FALLBACK)
  10101. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10102. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10103. #if defined(WOLFSSL_ASYNC_CRYPT)
  10104. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10105. #endif
  10106. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10107. if (ret != 0)
  10108. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10109. if (XMEMCMP(c2, buf, sizeof(c2)))
  10110. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10111. #endif
  10112. XMEMSET(buf, 0, sizeof(buf));
  10113. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10114. if (ret != 0)
  10115. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10116. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10117. #if defined(WOLFSSL_ASYNC_CRYPT)
  10118. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10119. #endif
  10120. if (ret != 0)
  10121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10122. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  10123. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10124. #ifdef WOLFSSL_AESXTS_STREAM
  10125. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10126. #if defined(WOLFSSL_ASYNC_CRYPT)
  10127. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10128. #endif
  10129. if (ret != 0)
  10130. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10131. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10132. #if defined(WOLFSSL_ASYNC_CRYPT)
  10133. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10134. #endif
  10135. if (ret != 0)
  10136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10137. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10138. #if defined(WOLFSSL_ASYNC_CRYPT)
  10139. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10140. #endif
  10141. if (ret != 0)
  10142. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10143. if (XMEMCMP(c1, buf, sizeof(c1)))
  10144. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10145. #endif /* WOLFSSL_AESXTS_STREAM */
  10146. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10147. defined(WC_C_DYNAMIC_FALLBACK)
  10148. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10149. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10150. #if defined(WOLFSSL_ASYNC_CRYPT)
  10151. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10152. #endif
  10153. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10154. if (ret != 0)
  10155. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10156. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  10157. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10158. #endif
  10159. /* partial block encryption test */
  10160. XMEMSET(cipher, 0, sizeof(cipher));
  10161. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10162. #if defined(WOLFSSL_ASYNC_CRYPT)
  10163. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10164. #endif
  10165. if (ret != 0)
  10166. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10167. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10168. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10169. #ifdef WOLFSSL_AESXTS_STREAM
  10170. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10171. #if defined(WOLFSSL_ASYNC_CRYPT)
  10172. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10173. #endif
  10174. if (ret != 0)
  10175. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10176. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  10177. #if defined(WOLFSSL_ASYNC_CRYPT)
  10178. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10179. #endif
  10180. if (ret != 0)
  10181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10182. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10183. #if defined(WOLFSSL_ASYNC_CRYPT)
  10184. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10185. #endif
  10186. if (ret != 0)
  10187. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10188. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  10189. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10190. #endif /* WOLFSSL_AESXTS_STREAM */
  10191. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10192. defined(WC_C_DYNAMIC_FALLBACK)
  10193. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10194. XMEMSET(cipher, 0, sizeof(cipher));
  10195. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10196. #if defined(WOLFSSL_ASYNC_CRYPT)
  10197. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10198. #endif
  10199. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10200. if (ret != 0)
  10201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10202. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10203. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10204. #endif
  10205. /* partial block decrypt test */
  10206. XMEMSET(buf, 0, sizeof(buf));
  10207. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10208. if (ret != 0)
  10209. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10210. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10211. #if defined(WOLFSSL_ASYNC_CRYPT)
  10212. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10213. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10214. #else
  10215. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10216. #endif
  10217. #endif
  10218. if (ret != 0)
  10219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10220. if (XMEMCMP(pp, buf, sizeof(pp)))
  10221. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10222. #ifdef WOLFSSL_AESXTS_STREAM
  10223. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10224. #if defined(WOLFSSL_ASYNC_CRYPT)
  10225. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10226. #endif
  10227. if (ret != 0)
  10228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10229. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  10230. #if defined(WOLFSSL_ASYNC_CRYPT)
  10231. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10232. #endif
  10233. if (ret != 0)
  10234. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10235. if (XMEMCMP(pp, buf, sizeof(pp)))
  10236. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10237. #endif /* WOLFSSL_AESXTS_STREAM */
  10238. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10239. defined(WC_C_DYNAMIC_FALLBACK)
  10240. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10241. XMEMSET(buf, 0, sizeof(buf));
  10242. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10243. #if defined(WOLFSSL_ASYNC_CRYPT)
  10244. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10245. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10246. #else
  10247. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10248. #endif
  10249. #endif
  10250. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10251. if (ret != 0)
  10252. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10253. if (XMEMCMP(pp, buf, sizeof(pp)))
  10254. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10255. #endif
  10256. /* NIST decrypt test vector */
  10257. XMEMSET(buf, 0, sizeof(buf));
  10258. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10259. #if defined(WOLFSSL_ASYNC_CRYPT)
  10260. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10261. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10262. #else
  10263. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10264. #endif
  10265. #endif
  10266. if (ret != 0)
  10267. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10268. if (XMEMCMP(p1, buf, sizeof(p1)))
  10269. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10270. #ifdef WOLFSSL_AESXTS_STREAM
  10271. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10272. #if defined(WOLFSSL_ASYNC_CRYPT)
  10273. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10274. #endif
  10275. if (ret != 0)
  10276. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10277. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10278. #if defined(WOLFSSL_ASYNC_CRYPT)
  10279. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10280. #endif
  10281. if (ret != 0)
  10282. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10283. if (XMEMCMP(p1, buf, sizeof(p1)))
  10284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10285. #endif /* WOLFSSL_AESXTS_STREAM */
  10286. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10287. defined(WC_C_DYNAMIC_FALLBACK)
  10288. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10289. XMEMSET(buf, 0, sizeof(buf));
  10290. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10291. #if defined(WOLFSSL_ASYNC_CRYPT)
  10292. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10293. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10294. #else
  10295. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10296. #endif
  10297. #endif
  10298. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10299. if (ret != 0)
  10300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10301. if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE))
  10302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10303. #endif
  10304. /* fail case with decrypting using wrong key */
  10305. XMEMSET(buf, 0, sizeof(buf));
  10306. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10307. #if defined(WOLFSSL_ASYNC_CRYPT)
  10308. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10309. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10310. #else
  10311. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10312. #endif
  10313. #endif
  10314. if (ret != 0)
  10315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10316. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  10317. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10318. /* set correct key and retest */
  10319. XMEMSET(buf, 0, sizeof(buf));
  10320. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10321. if (ret != 0)
  10322. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10323. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10324. #if defined(WOLFSSL_ASYNC_CRYPT)
  10325. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10326. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10327. #else
  10328. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10329. #endif
  10330. #endif
  10331. if (ret != 0)
  10332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10333. if (XMEMCMP(p2, buf, sizeof(p2)))
  10334. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10335. #ifndef HAVE_FIPS
  10336. /* Test ciphertext stealing in-place. */
  10337. XMEMCPY(buf, p3, sizeof(p3));
  10338. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  10339. if (ret != 0)
  10340. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10341. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  10342. #if defined(WOLFSSL_ASYNC_CRYPT)
  10343. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10344. #endif
  10345. if (ret != 0)
  10346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10347. if (XMEMCMP(c3, buf, sizeof(c3)))
  10348. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10349. #ifdef WOLFSSL_AESXTS_STREAM
  10350. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  10351. #if defined(WOLFSSL_ASYNC_CRYPT)
  10352. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10353. #endif
  10354. if (ret != 0)
  10355. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10356. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, WC_AES_BLOCK_SIZE, &stream);
  10357. #if defined(WOLFSSL_ASYNC_CRYPT)
  10358. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10359. #endif
  10360. if (ret != 0)
  10361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10362. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p3 + WC_AES_BLOCK_SIZE, sizeof(p3) - WC_AES_BLOCK_SIZE, &stream);
  10363. #if defined(WOLFSSL_ASYNC_CRYPT)
  10364. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10365. #endif
  10366. if (ret != 0)
  10367. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10368. if (XMEMCMP(c3, buf, sizeof(c3)))
  10369. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10370. #endif /* WOLFSSL_AESXTS_STREAM */
  10371. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  10372. if (ret != 0)
  10373. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10374. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  10375. #if defined(WOLFSSL_ASYNC_CRYPT)
  10376. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10377. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10378. #else
  10379. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10380. #endif
  10381. #endif
  10382. if (ret != 0)
  10383. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10384. if (XMEMCMP(p3, buf, sizeof(p3)))
  10385. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10386. #ifdef WOLFSSL_AESXTS_STREAM
  10387. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  10388. #if defined(WOLFSSL_ASYNC_CRYPT)
  10389. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10390. #endif
  10391. if (ret != 0)
  10392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10393. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, WC_AES_BLOCK_SIZE, &stream);
  10394. #if defined(WOLFSSL_ASYNC_CRYPT)
  10395. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10396. #endif
  10397. if (ret != 0)
  10398. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10399. ret = wc_AesXtsDecryptFinal(aes, buf + WC_AES_BLOCK_SIZE, c3 + WC_AES_BLOCK_SIZE, sizeof(c3) - WC_AES_BLOCK_SIZE, &stream);
  10400. #if defined(WOLFSSL_ASYNC_CRYPT)
  10401. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10402. #endif
  10403. if (ret != 0)
  10404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10405. if (XMEMCMP(p3, buf, sizeof(p3)))
  10406. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10407. #endif /* WOLFSSL_AESXTS_STREAM */
  10408. #endif /* !HAVE_FIPS */
  10409. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10410. !defined(WOLFSSL_AFALG)
  10411. {
  10412. int i;
  10413. int j;
  10414. #ifdef WOLFSSL_AESXTS_STREAM
  10415. int k;
  10416. #endif
  10417. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10418. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10419. DYNAMIC_TYPE_TMP_BUFFER);
  10420. if (large_input == NULL)
  10421. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10422. #endif
  10423. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10424. large_input[i] = (byte)i;
  10425. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10426. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10427. if (ret != 0)
  10428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10429. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10430. sizeof(i1));
  10431. #if defined(WOLFSSL_ASYNC_CRYPT)
  10432. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10433. #endif
  10434. if (ret != 0)
  10435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10436. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10437. if (ret != 0)
  10438. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10439. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10440. sizeof(i1));
  10441. #if defined(WOLFSSL_ASYNC_CRYPT)
  10442. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10443. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10444. WC_ASYNC_FLAG_NONE);
  10445. #else
  10446. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10447. #endif
  10448. #endif
  10449. if (ret != 0)
  10450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10451. for (i = 0; i < j; i++) {
  10452. if (large_input[i] != (byte)i) {
  10453. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10454. }
  10455. }
  10456. }
  10457. #ifdef WOLFSSL_AESXTS_STREAM
  10458. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10459. large_input[i] = (byte)i;
  10460. /* first, encrypt block by block then decrypt with a one-shot call. */
  10461. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10462. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10463. if (ret != 0)
  10464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10465. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10466. #if defined(WOLFSSL_ASYNC_CRYPT)
  10467. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10468. #endif
  10469. if (ret != 0)
  10470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10471. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  10472. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10473. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10474. else
  10475. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  10476. #if defined(WOLFSSL_ASYNC_CRYPT)
  10477. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10478. #endif
  10479. if (ret != 0)
  10480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10481. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10482. break;
  10483. }
  10484. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10485. if (ret != 0)
  10486. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10487. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10488. sizeof(i1));
  10489. #if defined(WOLFSSL_ASYNC_CRYPT)
  10490. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10491. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10492. WC_ASYNC_FLAG_NONE);
  10493. #else
  10494. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10495. #endif
  10496. #endif
  10497. if (ret != 0)
  10498. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10499. for (i = 0; i < j; i++) {
  10500. if (large_input[i] != (byte)i) {
  10501. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10502. }
  10503. }
  10504. }
  10505. /* second, encrypt with a one-shot call then decrypt block by block. */
  10506. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10507. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10508. if (ret != 0)
  10509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10510. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10511. sizeof(i1));
  10512. #if defined(WOLFSSL_ASYNC_CRYPT)
  10513. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10514. #endif
  10515. if (ret != 0)
  10516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10517. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10518. if (ret != 0)
  10519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10520. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10521. #if defined(WOLFSSL_ASYNC_CRYPT)
  10522. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10523. #endif
  10524. if (ret != 0)
  10525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10526. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  10527. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10528. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10529. else
  10530. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  10531. #if defined(WOLFSSL_ASYNC_CRYPT)
  10532. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10533. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10534. WC_ASYNC_FLAG_NONE);
  10535. #else
  10536. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10537. #endif
  10538. #endif
  10539. if (ret != 0)
  10540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10541. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10542. break;
  10543. }
  10544. for (i = 0; i < j; i++) {
  10545. if (large_input[i] != (byte)i) {
  10546. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10547. }
  10548. }
  10549. }
  10550. #endif /* WOLFSSL_AESXTS_STREAM */
  10551. }
  10552. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10553. * !WOLFSSL_AFALG
  10554. */
  10555. out:
  10556. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10557. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10558. !defined(WOLFSSL_NO_MALLOC)
  10559. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10560. #endif
  10561. if (aes_inited)
  10562. wc_AesXtsFree(aes);
  10563. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10564. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10565. #endif
  10566. return ret;
  10567. }
  10568. #endif /* WOLFSSL_AES_192 */
  10569. #ifdef WOLFSSL_AES_256
  10570. static wc_test_ret_t aes_xts_256_test(void)
  10571. {
  10572. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10573. XtsAes *aes = NULL;
  10574. #else
  10575. XtsAes aes[1];
  10576. #endif
  10577. int aes_inited = 0;
  10578. wc_test_ret_t ret = 0;
  10579. unsigned char buf[WC_AES_BLOCK_SIZE * 3];
  10580. unsigned char cipher[WC_AES_BLOCK_SIZE * 3];
  10581. #ifdef WOLFSSL_AESXTS_STREAM
  10582. struct XtsAesStreamData stream;
  10583. #endif
  10584. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10585. !defined(WOLFSSL_AFALG)
  10586. #define LARGE_XTS_SZ 1024
  10587. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10588. byte* large_input = NULL;
  10589. #else
  10590. byte large_input[LARGE_XTS_SZ];
  10591. #endif
  10592. #endif
  10593. /* 256 key tests */
  10594. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10595. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  10596. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  10597. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  10598. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  10599. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  10600. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3,
  10601. 0xd6, 0x19, 0xb7, 0xe2, 0xb9, 0x14, 0x1e, 0x58,
  10602. 0x31, 0x8e, 0xea, 0x39, 0x2c, 0xf4, 0x1b, 0x08
  10603. };
  10604. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  10605. 0xad, 0xf8, 0xd9, 0x26, 0x27, 0x46, 0x4a, 0xd2,
  10606. 0xf0, 0x42, 0x8e, 0x84, 0xa9, 0xf8, 0x75, 0x64
  10607. };
  10608. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10609. 0x2e, 0xed, 0xea, 0x52, 0xcd, 0x82, 0x15, 0xe1,
  10610. 0xac, 0xc6, 0x47, 0xe8, 0x10, 0xbb, 0xc3, 0x64,
  10611. 0x2e, 0x87, 0x28, 0x7f, 0x8d, 0x2e, 0x57, 0xe3,
  10612. 0x6c, 0x0a, 0x24, 0xfb, 0xc1, 0x2a, 0x20, 0x2e
  10613. };
  10614. /* plain text test of partial block is not from NIST test vector list */
  10615. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  10616. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  10617. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  10618. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  10619. };
  10620. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10621. 0xcb, 0xaa, 0xd0, 0xe2, 0xf6, 0xce, 0xa3, 0xf5,
  10622. 0x0b, 0x37, 0xf9, 0x34, 0xd4, 0x6a, 0x9b, 0x13,
  10623. 0x0b, 0x9d, 0x54, 0xf0, 0x7e, 0x34, 0xf3, 0x6a,
  10624. 0xf7, 0x93, 0xe8, 0x6f, 0x73, 0xc6, 0xd7, 0xdb
  10625. };
  10626. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10627. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10628. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10629. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10630. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10631. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10632. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a,
  10633. 0xb5, 0xb0, 0xc7, 0xe5, 0x2d, 0xb5, 0x06, 0x12,
  10634. 0xd2, 0xb5, 0x3a, 0xcb, 0x47, 0x8a, 0x53, 0xb4
  10635. };
  10636. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10637. 0xe6, 0x42, 0x19, 0xed, 0xe0, 0xe1, 0xc2, 0xa0,
  10638. 0x0e, 0xf5, 0x58, 0x6a, 0xc4, 0x9b, 0xeb, 0x6f
  10639. };
  10640. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10641. 0x24, 0xcb, 0x76, 0x22, 0x55, 0xb5, 0xa8, 0x00,
  10642. 0xf4, 0x6e, 0x80, 0x60, 0x56, 0x9e, 0x05, 0x53,
  10643. 0xbc, 0xfe, 0x86, 0x55, 0x3b, 0xca, 0xd5, 0x89,
  10644. 0xc7, 0x54, 0x1a, 0x73, 0xac, 0xc3, 0x9a, 0xbd,
  10645. 0x53, 0xc4, 0x07, 0x76, 0xd8, 0xe8, 0x22, 0x61,
  10646. 0x9e, 0xa9, 0xad, 0x77, 0xa0, 0x13, 0x4c, 0xfc
  10647. };
  10648. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10649. 0xa3, 0xc6, 0xf3, 0xf3, 0x82, 0x79, 0x5b, 0x10,
  10650. 0x87, 0xd7, 0x02, 0x50, 0xdb, 0x2c, 0xd3, 0xb1,
  10651. 0xa1, 0x62, 0xa8, 0xb6, 0xdc, 0x12, 0x60, 0x61,
  10652. 0xc1, 0x0a, 0x84, 0xa5, 0x85, 0x3f, 0x3a, 0x89,
  10653. 0xe6, 0x6c, 0xdb, 0xb7, 0x9a, 0xb4, 0x28, 0x9b,
  10654. 0xc3, 0xea, 0xd8, 0x10, 0xe9, 0xc0, 0xaf, 0x92
  10655. };
  10656. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10657. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10658. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10659. #endif
  10660. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  10661. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  10662. ret = EVP_test(wolfSSL_EVP_aes_256_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  10663. if (ret != 0) {
  10664. printf("EVP_aes_256_xts failed\n");
  10665. goto out;
  10666. }
  10667. #endif
  10668. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10669. if (ret != 0)
  10670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10671. else
  10672. aes_inited = 1;
  10673. XMEMSET(buf, 0, sizeof(buf));
  10674. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10675. if (ret != 0)
  10676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10677. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10678. #if defined(WOLFSSL_ASYNC_CRYPT)
  10679. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10680. #endif
  10681. if (ret != 0)
  10682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10683. if (XMEMCMP(c2, buf, sizeof(c2)))
  10684. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10685. #ifdef WOLFSSL_AESXTS_STREAM
  10686. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10687. #if defined(WOLFSSL_ASYNC_CRYPT)
  10688. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10689. #endif
  10690. if (ret != 0)
  10691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10692. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, WC_AES_BLOCK_SIZE, &stream);
  10693. #if defined(WOLFSSL_ASYNC_CRYPT)
  10694. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10695. #endif
  10696. if (ret != 0)
  10697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10698. ret = wc_AesXtsEncryptFinal(aes, buf + WC_AES_BLOCK_SIZE, p2 + WC_AES_BLOCK_SIZE, sizeof(p2) - WC_AES_BLOCK_SIZE, &stream);
  10699. #if defined(WOLFSSL_ASYNC_CRYPT)
  10700. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10701. #endif
  10702. if (ret != 0)
  10703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10704. if (XMEMCMP(c2, buf, sizeof(c2)))
  10705. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10706. #endif /* WOLFSSL_AESXTS_STREAM */
  10707. XMEMSET(buf, 0, sizeof(buf));
  10708. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10709. if (ret != 0)
  10710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10711. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10712. #if defined(WOLFSSL_ASYNC_CRYPT)
  10713. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10714. #endif
  10715. if (ret != 0)
  10716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10717. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  10718. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10719. #ifdef WOLFSSL_AESXTS_STREAM
  10720. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10721. #if defined(WOLFSSL_ASYNC_CRYPT)
  10722. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10723. #endif
  10724. if (ret != 0)
  10725. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10726. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10727. #if defined(WOLFSSL_ASYNC_CRYPT)
  10728. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10729. #endif
  10730. if (ret != 0)
  10731. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10732. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10733. #if defined(WOLFSSL_ASYNC_CRYPT)
  10734. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10735. #endif
  10736. if (ret != 0)
  10737. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10738. if (XMEMCMP(c1, buf, sizeof(c1)))
  10739. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10740. #endif /* WOLFSSL_AESXTS_STREAM */
  10741. /* partial block encryption test */
  10742. XMEMSET(cipher, 0, sizeof(cipher));
  10743. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10744. #if defined(WOLFSSL_ASYNC_CRYPT)
  10745. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10746. #endif
  10747. if (ret != 0)
  10748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10749. /* partial block decrypt test */
  10750. XMEMSET(buf, 0, sizeof(buf));
  10751. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10752. if (ret != 0)
  10753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10754. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10755. #if defined(WOLFSSL_ASYNC_CRYPT)
  10756. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10757. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10758. #else
  10759. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10760. #endif
  10761. #endif
  10762. if (ret != 0)
  10763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10764. if (XMEMCMP(pp, buf, sizeof(pp)))
  10765. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10766. /* NIST decrypt test vector */
  10767. XMEMSET(buf, 0, sizeof(buf));
  10768. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10769. #if defined(WOLFSSL_ASYNC_CRYPT)
  10770. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10771. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10772. #else
  10773. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10774. #endif
  10775. #endif
  10776. if (ret != 0)
  10777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10778. if (XMEMCMP(p1, buf, sizeof(p1)))
  10779. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10780. #ifdef WOLFSSL_AESXTS_STREAM
  10781. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10782. #if defined(WOLFSSL_ASYNC_CRYPT)
  10783. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10784. #endif
  10785. if (ret != 0)
  10786. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10787. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10788. #if defined(WOLFSSL_ASYNC_CRYPT)
  10789. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10790. #endif
  10791. if (ret != 0)
  10792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10793. if (XMEMCMP(p1, buf, sizeof(p1)))
  10794. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10795. #endif /* WOLFSSL_AESXTS_STREAM */
  10796. XMEMSET(buf, 0, sizeof(buf));
  10797. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10798. if (ret != 0)
  10799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10800. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10801. #if defined(WOLFSSL_ASYNC_CRYPT)
  10802. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10803. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10804. #else
  10805. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10806. #endif
  10807. #endif
  10808. if (ret != 0)
  10809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10810. if (XMEMCMP(p2, buf, sizeof(p2)))
  10811. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10812. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10813. !defined(WOLFSSL_AFALG)
  10814. {
  10815. int i;
  10816. int j;
  10817. #ifdef WOLFSSL_AESXTS_STREAM
  10818. int k;
  10819. #endif
  10820. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10821. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10822. DYNAMIC_TYPE_TMP_BUFFER);
  10823. if (large_input == NULL)
  10824. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10825. #endif
  10826. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10827. large_input[i] = (byte)i;
  10828. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10829. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10830. if (ret != 0)
  10831. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10832. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10833. sizeof(i1));
  10834. #if defined(WOLFSSL_ASYNC_CRYPT)
  10835. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10836. #endif
  10837. if (ret != 0)
  10838. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10839. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10840. if (ret != 0)
  10841. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10842. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10843. sizeof(i1));
  10844. #if defined(WOLFSSL_ASYNC_CRYPT)
  10845. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10846. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10847. WC_ASYNC_FLAG_NONE);
  10848. #else
  10849. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10850. #endif
  10851. #endif
  10852. if (ret != 0)
  10853. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10854. for (i = 0; i < j; i++) {
  10855. if (large_input[i] != (byte)i) {
  10856. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10857. }
  10858. }
  10859. }
  10860. #ifdef WOLFSSL_AESXTS_STREAM
  10861. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10862. large_input[i] = (byte)i;
  10863. /* first, encrypt block by block then decrypt with a one-shot call. */
  10864. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10865. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10866. if (ret != 0)
  10867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10868. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10869. #if defined(WOLFSSL_ASYNC_CRYPT)
  10870. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10871. #endif
  10872. if (ret != 0)
  10873. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10874. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  10875. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10876. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10877. else
  10878. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  10879. #if defined(WOLFSSL_ASYNC_CRYPT)
  10880. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10881. #endif
  10882. if (ret != 0)
  10883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10884. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10885. break;
  10886. }
  10887. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10888. if (ret != 0)
  10889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10890. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10891. sizeof(i1));
  10892. #if defined(WOLFSSL_ASYNC_CRYPT)
  10893. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10894. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10895. WC_ASYNC_FLAG_NONE);
  10896. #else
  10897. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10898. #endif
  10899. #endif
  10900. if (ret != 0)
  10901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10902. for (i = 0; i < j; i++) {
  10903. if (large_input[i] != (byte)i) {
  10904. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10905. }
  10906. }
  10907. }
  10908. /* second, encrypt with a one-shot call then decrypt block by block. */
  10909. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10910. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10911. if (ret != 0)
  10912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10913. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10914. sizeof(i1));
  10915. #if defined(WOLFSSL_ASYNC_CRYPT)
  10916. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10917. #endif
  10918. if (ret != 0)
  10919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10920. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10921. if (ret != 0)
  10922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10923. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10924. #if defined(WOLFSSL_ASYNC_CRYPT)
  10925. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10926. #endif
  10927. if (ret != 0)
  10928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10929. for (k = 0; k < j; k += WC_AES_BLOCK_SIZE) {
  10930. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10931. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10932. else
  10933. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, WC_AES_BLOCK_SIZE, &stream);
  10934. #if defined(WOLFSSL_ASYNC_CRYPT)
  10935. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10936. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10937. WC_ASYNC_FLAG_NONE);
  10938. #else
  10939. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10940. #endif
  10941. #endif
  10942. if (ret != 0)
  10943. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10944. if ((j - k) < WC_AES_BLOCK_SIZE*2)
  10945. break;
  10946. }
  10947. for (i = 0; i < j; i++) {
  10948. if (large_input[i] != (byte)i) {
  10949. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10950. }
  10951. }
  10952. }
  10953. #endif /* WOLFSSL_AESXTS_STREAM */
  10954. }
  10955. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10956. * !WOLFSSL_AFALG
  10957. */
  10958. out:
  10959. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10960. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10961. !defined(WOLFSSL_NO_MALLOC)
  10962. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10963. #endif
  10964. if (aes_inited)
  10965. wc_AesXtsFree(aes);
  10966. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10967. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10968. #endif
  10969. return ret;
  10970. }
  10971. #endif /* WOLFSSL_AES_256 */
  10972. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  10973. /* both 128 and 256 bit key test */
  10974. static wc_test_ret_t aes_xts_sector_test(void)
  10975. {
  10976. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10977. XtsAes *aes = NULL;
  10978. #else
  10979. XtsAes aes[1];
  10980. #endif
  10981. int aes_inited = 0;
  10982. wc_test_ret_t ret = 0;
  10983. unsigned char buf[WC_AES_BLOCK_SIZE * 2];
  10984. /* 128 key tests */
  10985. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10986. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  10987. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  10988. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  10989. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  10990. };
  10991. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10992. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  10993. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  10994. };
  10995. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10996. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  10997. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  10998. };
  10999. word64 s1 = 141;
  11000. /* 256 key tests */
  11001. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  11002. 0xef, 0x01, 0x0c, 0xa1, 0xa3, 0x66, 0x3e, 0x32,
  11003. 0x53, 0x43, 0x49, 0xbc, 0x0b, 0xae, 0x62, 0x23,
  11004. 0x2a, 0x15, 0x73, 0x34, 0x85, 0x68, 0xfb, 0x9e,
  11005. 0xf4, 0x17, 0x68, 0xa7, 0x67, 0x4f, 0x50, 0x7a,
  11006. 0x72, 0x7f, 0x98, 0x75, 0x53, 0x97, 0xd0, 0xe0,
  11007. 0xaa, 0x32, 0xf8, 0x30, 0x33, 0x8c, 0xc7, 0xa9,
  11008. 0x26, 0xc7, 0x73, 0xf0, 0x9e, 0x57, 0xb3, 0x57,
  11009. 0xcd, 0x15, 0x6a, 0xfb, 0xca, 0x46, 0xe1, 0xa0
  11010. };
  11011. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  11012. 0xed, 0x98, 0xe0, 0x17, 0x70, 0xa8, 0x53, 0xb4,
  11013. 0x9d, 0xb9, 0xe6, 0xaa, 0xf8, 0x8f, 0x0a, 0x41,
  11014. 0xb9, 0xb5, 0x6e, 0x91, 0xa5, 0xa2, 0xb1, 0x1d,
  11015. 0x40, 0x52, 0x92, 0x54, 0xf5, 0x52, 0x3e, 0x75
  11016. };
  11017. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  11018. 0xca, 0x20, 0xc5, 0x5e, 0x8d, 0xc1, 0x49, 0x68,
  11019. 0x7d, 0x25, 0x41, 0xde, 0x39, 0xc3, 0xdf, 0x63,
  11020. 0x00, 0xbb, 0x5a, 0x16, 0x3c, 0x10, 0xce, 0xd3,
  11021. 0x66, 0x6b, 0x13, 0x57, 0xdb, 0x8b, 0xd3, 0x9d
  11022. };
  11023. word64 s2 = 187;
  11024. #if !defined(BENCH_EMBEDDED) && \
  11025. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11026. /* Sector size for encrypt/decrypt consecutive sectors testcase */
  11027. word32 sectorSz = 512;
  11028. unsigned char data[550];
  11029. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  11030. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11031. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11032. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  11033. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
  11034. };
  11035. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  11036. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11037. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11038. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11039. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11040. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11041. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11042. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11043. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11044. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11045. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11046. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11047. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11048. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11049. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11050. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11051. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11052. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11053. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11054. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11055. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11056. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11057. 0xfc, 0xfd, 0xfe, 0xff,
  11058. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11059. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11060. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11061. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11062. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11063. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11064. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11065. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11066. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11067. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11068. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11069. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11070. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11071. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11072. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11073. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11074. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11075. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11076. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11077. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11078. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11079. 0xfc, 0xfd, 0xfe, 0xff,
  11080. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11081. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11082. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  11083. };
  11084. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  11085. 0xb9, 0x6b, 0x2b, 0xfd, 0x61, 0x87, 0x84, 0xd5, 0x26, 0xd2, 0x8c, 0x62,
  11086. 0x63, 0x01, 0xca, 0x46, 0xb1, 0x82, 0xfa, 0xdc, 0xbc, 0x32, 0x18, 0xe9,
  11087. 0xda, 0xe6, 0xda, 0xd1, 0x1a, 0x52, 0x77, 0xca, 0xdb, 0x0e, 0xbe, 0x37,
  11088. 0x88, 0x36, 0x1c, 0x87, 0x16, 0x60, 0xfe, 0xa8, 0x9e, 0xf6, 0x48, 0x64,
  11089. 0x94, 0x34, 0x64, 0xed, 0xf6, 0x9a, 0xc5, 0x28, 0xc9, 0xed, 0x64, 0x80,
  11090. 0x85, 0xd8, 0x93, 0xa7, 0x50, 0xb1, 0x9d, 0x2f, 0x1e, 0x34, 0xcc, 0xb4,
  11091. 0x03, 0xfb, 0x6b, 0x43, 0x21, 0xa8, 0x5b, 0xc6, 0x59, 0x13, 0xd2, 0xb5,
  11092. 0xf5, 0x7b, 0xf6, 0xb2, 0xa4, 0x7a, 0xd2, 0x50, 0x26, 0xcb, 0xa4, 0x83,
  11093. 0xc3, 0x56, 0xb0, 0xb1, 0x14, 0x34, 0x12, 0x1b, 0xea, 0x26, 0x97, 0x24,
  11094. 0x54, 0xcc, 0x32, 0x4c, 0xa4, 0xc2, 0xa3, 0x07, 0xfa, 0x30, 0xa9, 0xf0,
  11095. 0x91, 0x17, 0x60, 0x68, 0x88, 0x7f, 0x34, 0x7e, 0xbd, 0x20, 0x33, 0x95,
  11096. 0x6e, 0xc0, 0xb6, 0x2b, 0xff, 0x7e, 0x61, 0x35, 0x9a, 0x88, 0xff, 0xd9,
  11097. 0x69, 0x21, 0xe7, 0x8f, 0x45, 0x02, 0xf9, 0xd7, 0xeb, 0xa6, 0x53, 0xf1,
  11098. 0x73, 0x04, 0xf1, 0x0b, 0x85, 0xc6, 0x1f, 0x4a, 0x51, 0x2f, 0x95, 0x87,
  11099. 0x5a, 0x67, 0x37, 0xb2, 0x87, 0xf7, 0xbe, 0x2a, 0x17, 0x57, 0xca, 0xfc,
  11100. 0xdd, 0x5f, 0x37, 0x48, 0x78, 0xbd, 0xfa, 0x75, 0xc9, 0xfa, 0x86, 0x7e,
  11101. 0xc4, 0x0f, 0x60, 0x85, 0xce, 0x12, 0x44, 0x7c, 0xd9, 0xb2, 0x50, 0xd9,
  11102. 0x57, 0x85, 0xa5, 0xd7, 0x68, 0x59, 0x03, 0x09, 0x97, 0x2e, 0x8e, 0xa5,
  11103. 0xe3, 0x98, 0xac, 0x16, 0xfb, 0x6d, 0x54, 0xc5, 0x5d, 0x7a, 0x33, 0x44,
  11104. 0x0a, 0x39, 0x91, 0xcc, 0x9f, 0x67, 0xf9, 0x89, 0xbb, 0x62, 0x02, 0xc4,
  11105. 0x22, 0xec, 0xcf, 0x97, 0x69, 0x81, 0x3d, 0x00, 0xfd, 0xeb, 0x55, 0x08,
  11106. 0xa2, 0xff, 0x97, 0xaa, 0x79, 0xde, 0x3c, 0x8a, 0x78, 0x71, 0x73, 0xa2,
  11107. 0x98, 0x2f, 0xd8, 0x5c, 0x62, 0x1c, 0x5c, 0x23, 0x0a, 0xd1, 0xf1, 0x81,
  11108. 0x8a, 0x12, 0xe7, 0x4d, 0xdd, 0x4f, 0xd4, 0xf1, 0xe8, 0x0f, 0x25, 0x79,
  11109. 0x45, 0x4a, 0x49, 0x49, 0x7e, 0x56, 0x91, 0x4e, 0xaa, 0xba, 0x18, 0xe1,
  11110. 0xe4, 0xbe, 0x21, 0xdc, 0x58, 0x60, 0x6f, 0x6a, 0x7f, 0xdc, 0x5e, 0x74,
  11111. 0x47, 0xbf, 0xeb, 0x84, 0xc4, 0x1e, 0x5a, 0x61, 0x64, 0xc8, 0x63, 0x68,
  11112. 0xfa, 0x17, 0x9c, 0xac, 0x60, 0x1c, 0xa5, 0x6e, 0x00, 0x21, 0x93, 0x3c,
  11113. 0xd7, 0xbb, 0x73, 0x45, 0xf7, 0x34, 0x81, 0x6c, 0xfa, 0xf2, 0x33, 0xfd,
  11114. 0xb1, 0x40, 0x30, 0x6b, 0x30, 0xd1, 0x83, 0x5e, 0x2e, 0x7a, 0xce, 0xa6,
  11115. 0x12, 0x2a, 0x15, 0x03, 0x78, 0x29, 0xb9, 0x07, 0xae, 0xe7, 0xc2, 0x78,
  11116. 0x74, 0x72, 0xa5, 0x0e, 0x6b, 0x1f, 0x78, 0xf2, 0x5a, 0x69, 0xb6, 0x2b,
  11117. 0x99, 0x94, 0x1f, 0x89, 0xd1, 0x21, 0x14, 0x4a, 0x54, 0xab, 0x5a, 0x9f,
  11118. 0xaa, 0xa7, 0x96, 0x0a, 0x21, 0xce, 0x30, 0xb6, 0x70, 0x81, 0xe9, 0xd3,
  11119. 0x71, 0xc0, 0xf1, 0x15, 0xe2, 0xf6, 0xd3, 0xcc, 0x41, 0x15, 0x9d, 0xd5,
  11120. 0xa3, 0xa4, 0xe0, 0xf8, 0x62, 0xc4, 0x76, 0x65, 0x63, 0x89, 0xa7, 0xe2,
  11121. 0xfb, 0xf5, 0xc9, 0x80, 0x15, 0x5b, 0xc1, 0x59, 0xb2, 0xd0, 0x01, 0x3a,
  11122. 0xf9, 0xab, 0x5b, 0x79, 0x54, 0xed, 0x6b, 0xf9, 0x1d, 0x9d, 0x87, 0x63,
  11123. 0x80, 0x4f, 0xec, 0x9c, 0x4f, 0xad, 0x97, 0x04, 0xff, 0x62, 0x4a, 0x17,
  11124. 0xc0, 0x09, 0x2a, 0x2c, 0x23, 0x4b, 0xc3, 0xb6, 0x6d, 0xed, 0xdb, 0x1a,
  11125. 0x6f, 0x56, 0x2b, 0x78, 0x92, 0x3a, 0x5c, 0x7f, 0xb2, 0x63, 0xd3, 0xd5,
  11126. 0x1a, 0xbe, 0xc2, 0x34, 0xc8, 0xad, 0x36, 0xb7, 0x12, 0xb8, 0xe1, 0xb7,
  11127. 0x52, 0x7f, 0x16, 0x84, 0x2c, 0x47, 0x7e, 0xf2, 0xa5, 0x36, 0x2e, 0xad,
  11128. 0xe7, 0xbb, 0xc0, 0x6f, 0x27, 0x8e, 0x41, 0x08, 0x75, 0xe5, 0xff, 0xde,
  11129. 0x08, 0x9f, 0x8c, 0x91, 0xba, 0xc9, 0x9d, 0x9f, 0x27, 0x90, 0x50, 0x44,
  11130. 0x24, 0xe7, 0x3d, 0x6f
  11131. };
  11132. word64 s3 = 0x000000ffffffffff;
  11133. #endif
  11134. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11135. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11136. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11137. #endif
  11138. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11139. if (ret != 0)
  11140. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11141. else
  11142. aes_inited = 1;
  11143. XMEMSET(buf, 0, sizeof(buf));
  11144. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11145. if (ret != 0)
  11146. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11147. ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1);
  11148. #if defined(WOLFSSL_ASYNC_CRYPT)
  11149. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11150. #endif
  11151. if (ret != 0)
  11152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11153. if (XMEMCMP(c1, buf, WC_AES_BLOCK_SIZE))
  11154. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11155. /* decrypt test */
  11156. XMEMSET(buf, 0, sizeof(buf));
  11157. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11158. if (ret != 0)
  11159. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11160. ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1);
  11161. #if defined(WOLFSSL_ASYNC_CRYPT)
  11162. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11163. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11164. #else
  11165. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11166. #endif
  11167. #endif
  11168. if (ret != 0)
  11169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11170. if (XMEMCMP(p1, buf, WC_AES_BLOCK_SIZE))
  11171. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11172. /* 256 bit key tests */
  11173. XMEMSET(buf, 0, sizeof(buf));
  11174. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  11175. if (ret != 0)
  11176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11177. ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2);
  11178. #if defined(WOLFSSL_ASYNC_CRYPT)
  11179. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11180. #endif
  11181. if (ret != 0)
  11182. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11183. if (XMEMCMP(c2, buf, sizeof(c2)))
  11184. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11185. /* decrypt test */
  11186. XMEMSET(buf, 0, sizeof(buf));
  11187. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  11188. if (ret != 0)
  11189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11190. ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2);
  11191. #if defined(WOLFSSL_ASYNC_CRYPT)
  11192. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11193. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11194. #else
  11195. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11196. #endif
  11197. #endif
  11198. if (ret != 0)
  11199. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11200. if (XMEMCMP(p2, buf, sizeof(p2)))
  11201. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11202. #if !defined(BENCH_EMBEDDED) && \
  11203. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11204. /* encrypt consecutive sectors test */
  11205. XMEMSET(data, 0, sizeof(buf));
  11206. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  11207. if (ret != 0)
  11208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11209. ret = wc_AesXtsEncryptConsecutiveSectors(aes, data, p3,
  11210. sizeof(p3), s3, sectorSz);
  11211. #if defined(WOLFSSL_ASYNC_CRYPT)
  11212. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11213. #endif
  11214. if (ret != 0)
  11215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11216. if (XMEMCMP(c3, data, sizeof(c3)))
  11217. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11218. /* decrypt consecutive sectors test */
  11219. XMEMSET(data, 0, sizeof(buf));
  11220. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  11221. if (ret != 0)
  11222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11223. ret = wc_AesXtsDecryptConsecutiveSectors(aes, data, c3,
  11224. sizeof(c3), s3, sectorSz);
  11225. #if defined(WOLFSSL_ASYNC_CRYPT)
  11226. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11227. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11228. #else
  11229. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11230. #endif
  11231. #endif
  11232. if (ret != 0)
  11233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11234. if (XMEMCMP(p3, data, sizeof(p3)))
  11235. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11236. #endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */
  11237. out:
  11238. if (aes_inited)
  11239. wc_AesXtsFree(aes);
  11240. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11241. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11242. #endif
  11243. return ret;
  11244. }
  11245. #endif /* WOLFSSL_AES_128 && WOLFSSL_AES_256 */
  11246. #ifdef WOLFSSL_AES_128
  11247. /* testing of bad arguments */
  11248. static wc_test_ret_t aes_xts_args_test(void)
  11249. {
  11250. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11251. XtsAes *aes = NULL;
  11252. #else
  11253. XtsAes aes[1];
  11254. #endif
  11255. int aes_inited = 0;
  11256. wc_test_ret_t ret;
  11257. unsigned char buf[WC_AES_BLOCK_SIZE * 2];
  11258. /* 128 key tests */
  11259. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  11260. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  11261. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  11262. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  11263. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  11264. };
  11265. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  11266. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  11267. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  11268. };
  11269. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  11270. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  11271. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  11272. };
  11273. word64 s1 = 141;
  11274. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11275. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11276. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11277. #endif
  11278. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11279. if (ret != 0)
  11280. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11281. else
  11282. aes_inited = 1;
  11283. if (wc_AesXtsSetKeyNoInit(NULL, k1, sizeof(k1), AES_ENCRYPTION) == 0)
  11284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11285. if (wc_AesXtsSetKeyNoInit(aes, NULL, sizeof(k1), AES_ENCRYPTION) == 0)
  11286. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11287. /* encryption operations */
  11288. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11289. if (ret != 0)
  11290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11291. ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1);
  11292. #if defined(WOLFSSL_ASYNC_CRYPT)
  11293. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11294. #endif
  11295. if (ret == 0)
  11296. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11297. ret = wc_AesXtsEncryptSector(aes, NULL, p1, sizeof(p1), s1);
  11298. #if defined(WOLFSSL_ASYNC_CRYPT)
  11299. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11300. #endif
  11301. if (ret == 0)
  11302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11303. /* decryption operations */
  11304. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11305. if (ret != 0)
  11306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11307. ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1);
  11308. #if defined(WOLFSSL_ASYNC_CRYPT)
  11309. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11310. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11311. #else
  11312. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11313. #endif
  11314. #endif
  11315. if (ret == 0)
  11316. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11317. ret = wc_AesXtsDecryptSector(aes, NULL, c1, sizeof(c1), s1);
  11318. #if defined(WOLFSSL_ASYNC_CRYPT)
  11319. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11320. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11321. #else
  11322. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11323. #endif
  11324. #endif
  11325. if (ret == 0)
  11326. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11327. ret = 0;
  11328. out:
  11329. if (aes_inited)
  11330. wc_AesXtsFree(aes);
  11331. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11332. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11333. #endif
  11334. return ret;
  11335. }
  11336. #endif /* WOLFSSL_AES_128 */
  11337. #endif /* WOLFSSL_AES_XTS && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  11338. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  11339. !defined(HAVE_RENESAS_SYNC)
  11340. static wc_test_ret_t aes_cbc_oneshot_test(void)
  11341. {
  11342. byte cipher[WC_AES_BLOCK_SIZE];
  11343. byte plain[WC_AES_BLOCK_SIZE];
  11344. wc_test_ret_t ret;
  11345. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  11346. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  11347. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  11348. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  11349. };
  11350. byte key[] = "0123456789abcdef "; /* align */
  11351. byte iv[] = "1234567890abcdef "; /* align */
  11352. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  11353. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  11354. /* Parameter Validation testing. */
  11355. ret = wc_AesCbcEncryptWithKey(cipher, msg, WC_AES_BLOCK_SIZE, key, 17, NULL);
  11356. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11357. return WC_TEST_RET_ENC_EC(ret);
  11358. #ifdef HAVE_AES_DECRYPT
  11359. ret = wc_AesCbcDecryptWithKey(plain, cipher, WC_AES_BLOCK_SIZE, key, 17, NULL);
  11360. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11361. return WC_TEST_RET_ENC_EC(ret);
  11362. #endif
  11363. ret = wc_AesCbcEncryptWithKey(cipher, msg, WC_AES_BLOCK_SIZE, key,
  11364. WC_AES_BLOCK_SIZE, iv);
  11365. if (ret != 0)
  11366. return WC_TEST_RET_ENC_EC(ret);
  11367. #ifdef HAVE_AES_DECRYPT
  11368. ret = wc_AesCbcDecryptWithKey(plain, cipher, WC_AES_BLOCK_SIZE, key,
  11369. WC_AES_BLOCK_SIZE, iv);
  11370. if (ret != 0)
  11371. return WC_TEST_RET_ENC_EC(ret);
  11372. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE) != 0)
  11373. return WC_TEST_RET_ENC_NC;
  11374. #endif /* HAVE_AES_DECRYPT */
  11375. (void)plain;
  11376. return 0;
  11377. }
  11378. #endif
  11379. #if defined(WOLFSSL_AES_COUNTER) && defined(HAVE_AES_DECRYPT)
  11380. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void)
  11381. {
  11382. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11383. Aes *enc = NULL;
  11384. Aes *dec = NULL;
  11385. #else
  11386. Aes enc[1];
  11387. Aes dec[1];
  11388. #endif
  11389. byte cipher[WC_AES_BLOCK_SIZE * 4];
  11390. byte plain [WC_AES_BLOCK_SIZE * 4];
  11391. wc_test_ret_t ret = 0;
  11392. /* test vectors from "Recommendation for Block Cipher Modes of
  11393. * Operation" NIST Special Publication 800-38A */
  11394. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  11395. {
  11396. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  11397. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  11398. };
  11399. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  11400. {
  11401. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11402. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  11403. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  11404. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  11405. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  11406. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  11407. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  11408. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  11409. };
  11410. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11411. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32[] =
  11412. {
  11413. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,
  11414. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11415. };
  11416. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32_2[] =
  11417. {
  11418. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11419. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xfe
  11420. };
  11421. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64[] =
  11422. {
  11423. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11424. 0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11425. };
  11426. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64_2[] =
  11427. {
  11428. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
  11429. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11430. };
  11431. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96[] =
  11432. {
  11433. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11434. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff
  11435. };
  11436. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96_2[] =
  11437. {
  11438. 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,
  11439. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11440. };
  11441. #endif
  11442. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
  11443. {
  11444. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11445. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11446. };
  11447. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11448. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128_2[] =
  11449. {
  11450. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11451. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11452. };
  11453. #endif
  11454. #ifdef WOLFSSL_AES_128
  11455. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  11456. {
  11457. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  11458. 0xc2
  11459. };
  11460. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Key[] =
  11461. {
  11462. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  11463. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  11464. };
  11465. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Cipher[] =
  11466. {
  11467. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  11468. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  11469. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  11470. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  11471. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  11472. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  11473. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  11474. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  11475. };
  11476. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11477. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32Cipher[] =
  11478. {
  11479. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11480. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11481. 0x7e,0xad,0xea,0x5c,0xd1
  11482. };
  11483. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32CipherLong[] =
  11484. {
  11485. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11486. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11487. 0x7e,0xad,0xea,0x5c,0xd1,0xb7,0x98,0xf0,
  11488. 0x22,0x20,0xfe,0x67,0xb0,0x02,0x23,0x50
  11489. };
  11490. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32_2CipherLong[] =
  11491. {
  11492. 0x6e,0xa1,0x27,0x4d,0xea,0x20,0x5f,0x39,
  11493. 0x68,0xc8,0xb6,0x78,0xde,0xfc,0x53,0x5c,
  11494. 0x90,0xc8,0xf6,0xc6,0xfa,0xe0,0x7b,0x09,
  11495. 0x7c,0xf8,0x9c,0x6a,0x5a,0xa5,0x17,0x7f,
  11496. 0x03,0x92,0x5f,0x4e,0x85,0xea,0x26,0xc9,
  11497. 0x5a,0xc2,0x74,0xe2,0xbf,0xe4,0x1b,0xd4
  11498. };
  11499. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64Cipher[] =
  11500. {
  11501. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11502. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11503. 0xae,0x74,0x94,0x72,0x8e
  11504. };
  11505. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64CipherLong[] =
  11506. {
  11507. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11508. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11509. 0xae,0x74,0x94,0x72,0x8e,0xd0,0x71,0xc0,
  11510. 0x89,0x8a,0xa1,0xb0,0x29,0xa0,0x10,0x9e
  11511. };
  11512. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64_2CipherLong[] =
  11513. {
  11514. 0x3f,0xe7,0xd5,0xf3,0xfa,0x09,0xfe,0x40,
  11515. 0xa6,0xa1,0x32,0x8b,0x57,0x12,0xb9,0xfa,
  11516. 0xf2,0x2d,0xe4,0x3c,0x66,0x1d,0x0a,0x8e,
  11517. 0x46,0xf8,0x2e,0x33,0xce,0x8d,0x4e,0x3b,
  11518. 0x17,0x67,0x9e,0x9f,0x76,0x9e,0xc2,0x99,
  11519. 0xd5,0xd4,0x71,0xed,0xb4,0x33,0xb2,0xcd
  11520. };
  11521. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96Cipher[] =
  11522. {
  11523. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11524. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11525. 0x9d,0x77,0xc9,0x5f,0x38
  11526. };
  11527. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96CipherLong[] =
  11528. {
  11529. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11530. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11531. 0x9d,0x77,0xc9,0x5f,0x38,0xb5,0x6e,0x44,
  11532. 0x21,0x8e,0xda,0x57,0xe0,0x41,0xc7,0x6a
  11533. };
  11534. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96_2CipherLong[] =
  11535. {
  11536. 0xc8,0x81,0x1a,0xbe,0xc7,0x5b,0x93,0x6f,
  11537. 0xe6,0x52,0xe4,0xb1,0x2d,0x1c,0x39,0xbc,
  11538. 0xeb,0x82,0x27,0x0a,0x7e,0xa5,0x0e,0x2d,
  11539. 0x32,0xda,0xbe,0x10,0x7a,0x10,0xcc,0xd3,
  11540. 0x6f,0xc6,0x83,0x28,0x05,0x57,0x8a,0x24,
  11541. 0x44,0x76,0x17,0x81,0xb9,0x5c,0x94,0x81
  11542. };
  11543. #endif
  11544. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
  11545. {
  11546. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11547. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11548. 0xd3,0xda,0xe1,0x5b,0x04
  11549. };
  11550. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128CipherLong[] =
  11551. {
  11552. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11553. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11554. 0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
  11555. 0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
  11556. };
  11557. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11558. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128_2CipherLong[] =
  11559. {
  11560. 0xba,0x76,0xaa,0x54,0xd5,0xb5,0x60,0x67,
  11561. 0xc1,0xa7,0x90,0x3b,0x3f,0xdd,0xfa,0x89,
  11562. 0x24,0xdf,0x0c,0x56,0x5c,0xf4,0x2a,0x68,
  11563. 0x97,0x87,0x13,0xb6,0x7a,0xd1,0x24,0xfd,
  11564. 0x4d,0x3f,0x77,0x4a,0xb9,0xe4,0x7d,0xa2,
  11565. 0xdb,0xb9,0x31,0x5e,0xa3,0x11,0x06,0x80
  11566. };
  11567. #endif
  11568. #endif /* WOLFSSL_AES_128 */
  11569. #ifdef WOLFSSL_AES_192
  11570. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  11571. {
  11572. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  11573. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  11574. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  11575. };
  11576. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  11577. {
  11578. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  11579. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b,
  11580. 0x09,0x03,0x39,0xec,0x0a,0xa6,0xfa,0xef,
  11581. 0xd5,0xcc,0xc2,0xc6,0xf4,0xce,0x8e,0x94,
  11582. 0x1e,0x36,0xb2,0x6b,0xd1,0xeb,0xc6,0x70,
  11583. 0xd1,0xbd,0x1d,0x66,0x56,0x20,0xab,0xf7,
  11584. 0x4f,0x78,0xa7,0xf6,0xd2,0x98,0x09,0x58,
  11585. 0x5a,0x97,0xda,0xec,0x58,0xc6,0xb0,0x50
  11586. };
  11587. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11588. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32Cipher[] =
  11589. {
  11590. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11591. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11592. 0x0c,0x33,0x97,0x06,0xc0
  11593. };
  11594. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32CipherLong[] =
  11595. {
  11596. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11597. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11598. 0x0c,0x33,0x97,0x06,0xc0,0xbe,0x83,0x87,
  11599. 0xdd,0xd3,0xff,0xd8,0xe4,0x6a,0x5b,0x84
  11600. };
  11601. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32_2CipherLong[] =
  11602. {
  11603. 0xf5,0x00,0xa2,0x91,0x54,0xa3,0x76,0xa2,
  11604. 0xdd,0xad,0x16,0x89,0xe5,0xf0,0x1d,0x40,
  11605. 0x84,0xcd,0x74,0x84,0xcb,0x8b,0x9e,0x29,
  11606. 0xa9,0x8a,0x12,0x65,0xa0,0x79,0x5e,0xce,
  11607. 0xd9,0x50,0x65,0x21,0x86,0xb0,0x85,0x0d,
  11608. 0x98,0x2d,0x9a,0x5a,0x11,0xbe,0xa5,0x7f
  11609. };
  11610. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64Cipher[] =
  11611. {
  11612. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11613. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11614. 0x3d,0xf7,0xb4,0xfd,0x8c
  11615. };
  11616. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64CipherLong[] =
  11617. {
  11618. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11619. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11620. 0x3d,0xf7,0xb4,0xfd,0x8c,0x55,0x47,0x10,
  11621. 0xd5,0x91,0x35,0xbe,0xd8,0x0d,0xa5,0x9e
  11622. };
  11623. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64_2CipherLong[] =
  11624. {
  11625. 0x59,0xf1,0xed,0x70,0x62,0x42,0xa8,0x06,
  11626. 0x07,0x36,0xe1,0xc5,0x04,0x79,0xc3,0x9b,
  11627. 0xd1,0x14,0x5c,0xcc,0x6f,0x81,0x5f,0x2f,
  11628. 0xa0,0xde,0xcf,0x61,0x55,0x18,0x7a,0xac,
  11629. 0xb0,0x59,0x37,0x90,0x53,0xb3,0x00,0x88,
  11630. 0xb4,0x49,0x90,0x7b,0x96,0xcd,0xcc,0xc3
  11631. };
  11632. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96Cipher[] =
  11633. {
  11634. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11635. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11636. 0x47,0xb5,0xf3,0x30,0x3b
  11637. };
  11638. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96CipherLong[] =
  11639. {
  11640. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11641. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11642. 0x47,0xb5,0xf3,0x30,0x3b,0xef,0xcd,0x80,
  11643. 0xe3,0x61,0x34,0xef,0x4e,0x1b,0x79,0xc1
  11644. };
  11645. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96_2CipherLong[] =
  11646. {
  11647. 0x3c,0xb2,0xff,0xc0,0x24,0xe1,0xf5,0xc4,
  11648. 0x0f,0xd1,0x0a,0x1b,0xbe,0x1f,0x23,0xa1,
  11649. 0x8e,0xbf,0x2b,0x96,0xb6,0x37,0xc8,0x25,
  11650. 0x06,0x90,0xe2,0xca,0x71,0x24,0x52,0x95,
  11651. 0xaa,0x8c,0x80,0xdf,0xb7,0xd7,0x30,0xb0,
  11652. 0xcc,0x06,0x4f,0x28,0xa2,0x74,0x27,0xf8
  11653. };
  11654. #endif
  11655. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128Cipher[] =
  11656. {
  11657. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11658. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11659. 0x8c,0x68,0xa7,0xd9,0x57
  11660. };
  11661. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128CipherLong[] =
  11662. {
  11663. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11664. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11665. 0x8c,0x68,0xa7,0xd9,0x57,0xab,0x09,0x0f,
  11666. 0x01,0xc4,0x4e,0x62,0xaf,0xc2,0xdf,0x1a
  11667. };
  11668. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11669. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128_2CipherLong[] =
  11670. {
  11671. 0x88,0x0a,0x26,0x4e,0xa8,0x26,0x21,0xe0,
  11672. 0xfc,0xbc,0x63,0xdc,0xd9,0x60,0x52,0xb2,
  11673. 0x99,0x2f,0xbb,0x1e,0x00,0xf5,0x9f,0x6d,
  11674. 0xab,0x48,0x0f,0xc6,0x37,0x12,0x56,0xe3,
  11675. 0x12,0x8d,0x31,0xc8,0xea,0xf4,0x41,0x82,
  11676. 0x7a,0x88,0xe0,0xd7,0xf0,0x67,0x03,0xa4
  11677. };
  11678. #endif
  11679. #endif
  11680. #ifdef WOLFSSL_AES_256
  11681. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  11682. {
  11683. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11684. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11685. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11686. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11687. };
  11688. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  11689. {
  11690. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  11691. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
  11692. 0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,
  11693. 0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
  11694. 0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,
  11695. 0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
  11696. 0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,
  11697. 0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6
  11698. };
  11699. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11700. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32Cipher[] =
  11701. {
  11702. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11703. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11704. 0xa2,0x13,0x47,0x74,0xda
  11705. };
  11706. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32CipherLong[] =
  11707. {
  11708. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11709. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11710. 0xa2,0x13,0x47,0x74,0xda,0x89,0x77,0x40,
  11711. 0x28,0x9c,0xe8,0x19,0x26,0x32,0xd8,0x1f
  11712. };
  11713. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32_2CipherLong[] =
  11714. {
  11715. 0xf6,0xd9,0x22,0xc6,0x80,0x29,0xaf,0x14,
  11716. 0x54,0x6c,0x0a,0xce,0x42,0xea,0x3c,0xa1,
  11717. 0x7c,0xeb,0x36,0x0d,0x8e,0xd7,0x8c,0x59,
  11718. 0xa8,0x09,0x9f,0x9e,0xba,0x5b,0x95,0xfa,
  11719. 0x26,0x8c,0x37,0x59,0xf8,0xae,0x8e,0xaa,
  11720. 0x4d,0xe4,0x1c,0xfe,0x51,0xc7,0xb7,0xcc
  11721. };
  11722. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64Cipher[] =
  11723. {
  11724. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11725. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11726. 0xd4,0x94,0x4c,0xcd,0x4d
  11727. };
  11728. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64CipherLong[] =
  11729. {
  11730. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11731. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11732. 0xd4,0x94,0x4c,0xcd,0x4d,0x47,0x5a,0x92,
  11733. 0x26,0x49,0x81,0x7a,0xda,0x36,0x27,0x01
  11734. };
  11735. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64_2CipherLong[] =
  11736. {
  11737. 0xf7,0x9c,0xbf,0xf6,0xa2,0xaa,0x8a,0x0a,
  11738. 0x63,0x8a,0x20,0x2f,0x12,0xf1,0x8e,0x49,
  11739. 0x30,0xc0,0x8d,0x5c,0x5f,0x8b,0xbc,0x16,
  11740. 0xdd,0x71,0xee,0x13,0x14,0x7b,0xe1,0x25,
  11741. 0xcb,0x87,0x8a,0xc6,0xdc,0x1d,0x54,0x7a,
  11742. 0xe1,0xe4,0x6f,0x0d,0x95,0x1b,0xd1,0x8b
  11743. };
  11744. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96Cipher[] =
  11745. {
  11746. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11747. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11748. 0xb8,0x69,0xa1,0x48,0x45
  11749. };
  11750. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96CipherLong[] =
  11751. {
  11752. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11753. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11754. 0xb8,0x69,0xa1,0x48,0x45,0xf1,0xc6,0x27,
  11755. 0x36,0xa8,0xb2,0x4b,0x0e,0x62,0x6b,0x72
  11756. };
  11757. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96_2CipherLong[] =
  11758. {
  11759. 0xd5,0x56,0x73,0xaa,0xb8,0xe4,0x06,0xf6,
  11760. 0x83,0x45,0x3a,0xb4,0xb9,0x63,0xec,0xad,
  11761. 0x73,0xc5,0xab,0x78,0xb1,0x21,0xab,0xef,
  11762. 0x69,0x15,0xb7,0x0c,0xe9,0xb4,0x3a,0xe7,
  11763. 0xbc,0xc4,0x22,0xbd,0x93,0xba,0x52,0xe0,
  11764. 0x91,0x2f,0x5e,0x8d,0x6d,0x59,0xf7,0xc2
  11765. };
  11766. #endif
  11767. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
  11768. {
  11769. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11770. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11771. 0x4b,0x45,0x7c,0xd6,0x8a
  11772. };
  11773. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128CipherLong[] =
  11774. {
  11775. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11776. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11777. 0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
  11778. 0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
  11779. };
  11780. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11781. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128_2CipherLong[] =
  11782. {
  11783. 0x24,0x5c,0x09,0xa0,0x3b,0x1a,0x5a,0x94,
  11784. 0x2b,0x93,0x56,0x13,0x48,0xa0,0x21,0xce,
  11785. 0x95,0x11,0xa3,0x76,0xd6,0x59,0x88,0x42,
  11786. 0x04,0x71,0x69,0x62,0x28,0xb2,0xee,0x9d,
  11787. 0xd5,0xa0,0xea,0xc7,0x37,0x93,0x92,0xc7,
  11788. 0xf2,0xb6,0x8d,0xd9,0x59,0x1a,0xfa,0xbb
  11789. };
  11790. #endif
  11791. #endif
  11792. int i;
  11793. struct {
  11794. const byte* key;
  11795. int keySz;
  11796. const byte* iv;
  11797. const byte* plain;
  11798. int len;
  11799. const byte* cipher;
  11800. } testVec[] = {
  11801. #ifdef WOLFSSL_AES_128
  11802. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11803. ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
  11804. /* let's try with just 9 bytes, non block size test */
  11805. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11806. ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
  11807. /* and an additional 9 bytes to reuse tmp left buffer */
  11808. { NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
  11809. /* Counter wrapping */
  11810. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11811. ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
  11812. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11813. ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
  11814. ctr128Wrap128CipherLong },
  11815. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11816. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128_2,
  11817. ctrPlain, (int)sizeof(ctr128Wrap128_2CipherLong),
  11818. ctr128Wrap128_2CipherLong },
  11819. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11820. ctrPlain, (int)sizeof(ctr128Wrap96Cipher), ctr128Wrap96Cipher },
  11821. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11822. ctrPlain, (int)sizeof(ctr128Wrap96CipherLong),
  11823. ctr128Wrap96CipherLong },
  11824. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96_2,
  11825. ctrPlain, (int)sizeof(ctr128Wrap96_2CipherLong),
  11826. ctr128Wrap96_2CipherLong },
  11827. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11828. ctrPlain, (int)sizeof(ctr128Wrap64Cipher), ctr128Wrap64Cipher },
  11829. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11830. ctrPlain, (int)sizeof(ctr128Wrap64CipherLong),
  11831. ctr128Wrap64CipherLong },
  11832. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64_2,
  11833. ctrPlain, (int)sizeof(ctr128Wrap64_2CipherLong),
  11834. ctr128Wrap64_2CipherLong },
  11835. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11836. ctrPlain, (int)sizeof(ctr128Wrap32Cipher), ctr128Wrap32Cipher },
  11837. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11838. ctrPlain, (int)sizeof(ctr128Wrap32CipherLong),
  11839. ctr128Wrap32CipherLong },
  11840. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32_2,
  11841. ctrPlain, (int)sizeof(ctr128Wrap32_2CipherLong),
  11842. ctr128Wrap32_2CipherLong },
  11843. #endif
  11844. #endif
  11845. #ifdef WOLFSSL_AES_192
  11846. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11847. ctrPlain, (int)sizeof(ctrPlain), ctr192Cipher },
  11848. /* let's try with just 9 bytes, non block size test */
  11849. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11850. ctrPlain, (int)sizeof(oddCipher), ctr192Cipher },
  11851. /* Counter wrapping */
  11852. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11853. ctrPlain, (int)sizeof(ctr192Wrap128Cipher), ctr192Wrap128Cipher },
  11854. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11855. ctrPlain, (int)sizeof(ctr192Wrap128CipherLong),
  11856. ctr192Wrap128CipherLong },
  11857. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11858. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128_2,
  11859. ctrPlain, (int)sizeof(ctr192Wrap128_2CipherLong),
  11860. ctr192Wrap128_2CipherLong },
  11861. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11862. ctrPlain, (int)sizeof(ctr192Wrap96Cipher), ctr192Wrap96Cipher },
  11863. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11864. ctrPlain, (int)sizeof(ctr192Wrap96CipherLong),
  11865. ctr192Wrap96CipherLong },
  11866. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96_2,
  11867. ctrPlain, (int)sizeof(ctr192Wrap96_2CipherLong),
  11868. ctr192Wrap96_2CipherLong },
  11869. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11870. ctrPlain, (int)sizeof(ctr192Wrap64Cipher), ctr192Wrap64Cipher },
  11871. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11872. ctrPlain, (int)sizeof(ctr192Wrap64CipherLong),
  11873. ctr192Wrap64CipherLong },
  11874. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64_2,
  11875. ctrPlain, (int)sizeof(ctr192Wrap64_2CipherLong),
  11876. ctr192Wrap64_2CipherLong },
  11877. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11878. ctrPlain, (int)sizeof(ctr192Wrap32Cipher), ctr192Wrap32Cipher },
  11879. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11880. ctrPlain, (int)sizeof(ctr192Wrap32CipherLong),
  11881. ctr192Wrap32CipherLong },
  11882. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32_2,
  11883. ctrPlain, (int)sizeof(ctr192Wrap32_2CipherLong),
  11884. ctr192Wrap32_2CipherLong },
  11885. #endif
  11886. #endif
  11887. #ifdef WOLFSSL_AES_256
  11888. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11889. ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
  11890. /* let's try with just 9 bytes, non block size test */
  11891. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11892. ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
  11893. /* Counter wrapping */
  11894. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11895. ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
  11896. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11897. ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
  11898. ctr256Wrap128CipherLong },
  11899. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11900. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128_2,
  11901. ctrPlain, (int)sizeof(ctr256Wrap128_2CipherLong),
  11902. ctr256Wrap128_2CipherLong },
  11903. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11904. ctrPlain, (int)sizeof(ctr256Wrap96Cipher), ctr256Wrap96Cipher },
  11905. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11906. ctrPlain, (int)sizeof(ctr256Wrap96CipherLong),
  11907. ctr256Wrap96CipherLong },
  11908. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96_2,
  11909. ctrPlain, (int)sizeof(ctr256Wrap96_2CipherLong),
  11910. ctr256Wrap96_2CipherLong },
  11911. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11912. ctrPlain, (int)sizeof(ctr256Wrap64Cipher), ctr256Wrap64Cipher },
  11913. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11914. ctrPlain, (int)sizeof(ctr256Wrap64CipherLong),
  11915. ctr256Wrap64CipherLong },
  11916. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64_2,
  11917. ctrPlain, (int)sizeof(ctr256Wrap64_2CipherLong),
  11918. ctr256Wrap64_2CipherLong },
  11919. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11920. ctrPlain, (int)sizeof(ctr256Wrap32Cipher), ctr256Wrap32Cipher },
  11921. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11922. ctrPlain, (int)sizeof(ctr256Wrap32CipherLong),
  11923. ctr256Wrap32CipherLong },
  11924. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32_2,
  11925. ctrPlain, (int)sizeof(ctr256Wrap32_2CipherLong),
  11926. ctr256Wrap32_2CipherLong },
  11927. #endif
  11928. #endif
  11929. };
  11930. #define AES_CTR_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  11931. WOLFSSL_ENTER("aes_ctr_test");
  11932. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11933. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  11934. if (enc == NULL)
  11935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11936. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  11937. if (dec == NULL)
  11938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11939. #else
  11940. XMEMSET(enc, 0, sizeof(Aes));
  11941. XMEMSET(dec, 0, sizeof(Aes));
  11942. ret = wc_AesInit(enc, HEAP_HINT, devId);
  11943. if (ret != 0)
  11944. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11945. ret = wc_AesInit(dec, HEAP_HINT, devId);
  11946. if (ret != 0)
  11947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11948. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  11949. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11950. if (testVec[i].key != NULL) {
  11951. ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
  11952. testVec[i].iv, AES_ENCRYPTION);
  11953. if (ret != 0) {
  11954. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11955. }
  11956. /* Ctr only uses encrypt, even on key setup */
  11957. ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
  11958. testVec[i].iv, AES_ENCRYPTION);
  11959. if (ret != 0) {
  11960. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11961. }
  11962. }
  11963. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
  11964. if (ret != 0) {
  11965. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11966. }
  11967. ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
  11968. if (ret != 0) {
  11969. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11970. }
  11971. if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
  11972. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11973. }
  11974. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  11975. if (XMEMCMP(cipher, testVec[i].cipher, (size_t)testVec[i].len)) {
  11976. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11977. }
  11978. #endif
  11979. }
  11980. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11981. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11982. if (testVec[i].key != NULL) {
  11983. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  11984. testVec[i].iv, AES_ENCRYPTION);
  11985. if (ret != 0) {
  11986. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11987. }
  11988. /* Ctr only uses encrypt, even on key setup */
  11989. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  11990. testVec[i].iv, AES_ENCRYPTION);
  11991. if (ret != 0) {
  11992. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11993. }
  11994. }
  11995. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11996. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  11997. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11998. if (ret != 0) {
  11999. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12000. }
  12001. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12002. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12003. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12004. if (ret != 0) {
  12005. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12006. }
  12007. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12008. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12009. }
  12010. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12011. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12012. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12013. }
  12014. #endif
  12015. }
  12016. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  12017. if (testVec[i].key != NULL) {
  12018. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12019. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  12020. testVec[i].iv, AES_ENCRYPTION);
  12021. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12022. if (ret != 0) {
  12023. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12024. }
  12025. /* Ctr only uses encrypt, even on key setup */
  12026. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12027. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  12028. testVec[i].iv, AES_ENCRYPTION);
  12029. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12030. if (ret != 0) {
  12031. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12032. }
  12033. }
  12034. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  12035. if (ret != 0) {
  12036. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12037. }
  12038. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12039. if (ret != 0) {
  12040. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12041. }
  12042. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12043. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12044. }
  12045. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12046. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12047. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12048. }
  12049. #endif
  12050. }
  12051. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12052. out:
  12053. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12054. wc_AesDelete(enc, &enc);
  12055. #else
  12056. wc_AesFree(enc);
  12057. #endif
  12058. #ifdef HAVE_AES_DECRYPT
  12059. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12060. wc_AesDelete(dec, &dec);
  12061. #else
  12062. wc_AesFree(dec);
  12063. #endif
  12064. #endif
  12065. return ret;
  12066. }
  12067. #endif /* WOLFSSL_AES_COUNTER */
  12068. #ifdef HAVE_AES_ECB
  12069. static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12070. {
  12071. wc_test_ret_t ret = 0;
  12072. /* keys padded to block size (16 bytes) */
  12073. WOLFSSL_SMALL_STACK_STATIC const byte key_128[] =
  12074. "0123456789abcdef ";
  12075. WOLFSSL_SMALL_STACK_STATIC const byte key_192[] =
  12076. "0123456789abcdef01234567 ";
  12077. WOLFSSL_SMALL_STACK_STATIC const byte key_256[] =
  12078. "0123456789abcdef0123456789abcdef ";
  12079. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12080. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12081. 0x6e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  12082. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20
  12083. };
  12084. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[WC_AES_BLOCK_SIZE] = {
  12085. 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6,
  12086. 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1
  12087. };
  12088. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[WC_AES_BLOCK_SIZE] = {
  12089. 0x06, 0x57, 0xee, 0x78, 0x3f, 0x96, 0x00, 0xb1,
  12090. 0xec, 0x76, 0x94, 0x30, 0x29, 0xbe, 0x15, 0xab
  12091. };
  12092. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[WC_AES_BLOCK_SIZE] = {
  12093. 0xcd, 0xf2, 0x81, 0x3e, 0x73, 0x3e, 0xf7, 0x33,
  12094. 0x3d, 0x18, 0xfd, 0x41, 0x85, 0x37, 0x04, 0x82
  12095. };
  12096. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] = {
  12097. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12098. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12099. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12100. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12101. };
  12102. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] = {
  12103. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12104. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12105. };
  12106. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] = {
  12107. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12108. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12109. };
  12110. int i;
  12111. struct {
  12112. const byte* key;
  12113. int keySz;
  12114. const byte* iv; /* null uses 0's */
  12115. const byte* plain;
  12116. const byte* verify;
  12117. } testVec[] = {
  12118. { key_128, 16, iv, msg, verify_ecb_128 },
  12119. { key_192, 24, iv, msg, verify_ecb_192 },
  12120. { key_256, 32, iv, msg, verify_ecb_256 },
  12121. { niKey, 32, NULL, niPlain, niCipher }
  12122. };
  12123. #define AES_ECB_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  12124. for (i = 0; i < AES_ECB_TEST_LEN; i++) {
  12125. ret = wc_AesSetKey(enc, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12126. AES_ENCRYPTION);
  12127. if (ret != 0)
  12128. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12129. #ifdef HAVE_AES_DECRYPT
  12130. ret = wc_AesSetKey(dec, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12131. AES_DECRYPTION);
  12132. if (ret != 0)
  12133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12134. #endif
  12135. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12136. ret = wc_AesEcbEncrypt(enc, cipher, testVec[i].plain, WC_AES_BLOCK_SIZE);
  12137. #if defined(WOLFSSL_ASYNC_CRYPT)
  12138. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12139. #endif
  12140. if (ret != 0)
  12141. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12142. if (XMEMCMP(cipher, testVec[i].verify, WC_AES_BLOCK_SIZE)) {
  12143. WOLFSSL_MSG("aes_test cipher vs verify_ecb mismatch!");
  12144. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12145. }
  12146. #ifdef HAVE_AES_DECRYPT
  12147. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12148. ret = wc_AesEcbDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE);
  12149. #if defined(WOLFSSL_ASYNC_CRYPT)
  12150. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12151. #endif
  12152. if (ret != 0)
  12153. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12154. if (XMEMCMP(plain, testVec[i].plain, WC_AES_BLOCK_SIZE))
  12155. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12156. #endif /* HAVE_AES_DECRYPT */
  12157. (void)dec;
  12158. (void)plain;
  12159. }
  12160. out:
  12161. return ret;
  12162. }
  12163. #endif /* HAVE_AES_ECB */
  12164. #ifdef WOLFSSL_AES_DIRECT
  12165. static wc_test_ret_t aes_direct_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12166. {
  12167. wc_test_ret_t ret = 0;
  12168. WOLFSSL_ENTER("aes_direct_test");
  12169. #if defined(WOLFSSL_AES_256)
  12170. {
  12171. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  12172. {
  12173. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12174. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12175. };
  12176. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  12177. {
  12178. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12179. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12180. };
  12181. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  12182. {
  12183. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12184. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12185. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12186. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12187. };
  12188. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12189. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  12190. if (ret != 0)
  12191. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12192. #if !defined(HAVE_SELFTEST) && \
  12193. (defined(WOLFSSL_LINUXKM) || \
  12194. !defined(HAVE_FIPS) || \
  12195. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12196. ret = wc_AesEncryptDirect(enc, cipher, niPlain);
  12197. if (ret != 0)
  12198. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12199. #else
  12200. wc_AesEncryptDirect(enc, cipher, niPlain);
  12201. #endif
  12202. if (XMEMCMP(cipher, niCipher, WC_AES_BLOCK_SIZE) != 0)
  12203. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12204. #ifdef HAVE_AES_DECRYPT
  12205. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12206. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  12207. if (ret != 0)
  12208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12209. #if !defined(HAVE_SELFTEST) && \
  12210. (defined(WOLFSSL_LINUXKM) || \
  12211. !defined(HAVE_FIPS) || \
  12212. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12213. ret = wc_AesDecryptDirect(dec, plain, niCipher);
  12214. if (ret != 0)
  12215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12216. #else
  12217. wc_AesDecryptDirect(dec, plain, niCipher);
  12218. #endif
  12219. if (XMEMCMP(plain, niPlain, WC_AES_BLOCK_SIZE) != 0)
  12220. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12221. #endif /* HAVE_AES_DECRYPT */
  12222. }
  12223. out:
  12224. #endif /* WOLFSSL_AES_256 */
  12225. (void)enc;
  12226. (void)dec;
  12227. (void)cipher;
  12228. (void)plain;
  12229. return ret;
  12230. }
  12231. #endif /* WOLFSSL_AES_DIRECT */
  12232. #ifdef HAVE_AES_CBC
  12233. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void)
  12234. {
  12235. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12236. Aes *enc = NULL;
  12237. #else
  12238. Aes enc[1];
  12239. #endif
  12240. #ifdef HAVE_AES_DECRYPT
  12241. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12242. Aes *dec = NULL;
  12243. #else
  12244. Aes dec[1];
  12245. #endif
  12246. #endif
  12247. byte cipher[WC_AES_BLOCK_SIZE * 4];
  12248. #ifdef HAVE_AES_DECRYPT
  12249. byte plain [WC_AES_BLOCK_SIZE * 4];
  12250. #endif
  12251. wc_test_ret_t ret = 0;
  12252. WOLFSSL_ENTER("aes_cbc_test");
  12253. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12254. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12255. if (enc == NULL)
  12256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12257. #ifdef HAVE_AES_DECRYPT
  12258. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12259. if (dec == NULL)
  12260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12261. #endif
  12262. #else
  12263. XMEMSET(enc, 0, sizeof(Aes));
  12264. #ifdef HAVE_AES_DECRYPT
  12265. XMEMSET(dec, 0, sizeof(Aes));
  12266. #endif
  12267. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12268. if (ret != 0)
  12269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12270. #ifdef HAVE_AES_DECRYPT
  12271. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12272. if (ret != 0)
  12273. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12274. #endif
  12275. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12276. #ifdef WOLFSSL_AES_128
  12277. {
  12278. /* "Now is the time for all " w/o trailing 0 */
  12279. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12280. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  12281. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  12282. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  12283. };
  12284. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12285. {
  12286. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  12287. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  12288. };
  12289. #ifdef HAVE_RENESAS_SYNC
  12290. const byte *key = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  12291. #else
  12292. /* padded to 16-byye */
  12293. WOLFSSL_SMALL_STACK_STATIC const byte key[] = "0123456789abcdef ";
  12294. #endif
  12295. /* padded to 16-bytes */
  12296. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12297. ret = wc_AesSetKey(enc, key, WC_AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  12298. if (ret != 0)
  12299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12300. #ifdef HAVE_AES_DECRYPT
  12301. ret = wc_AesSetKey(dec, key, WC_AES_BLOCK_SIZE, iv, AES_DECRYPTION);
  12302. if (ret != 0)
  12303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12304. #endif
  12305. XMEMSET(cipher, 0, sizeof(cipher));
  12306. ret = wc_AesCbcEncrypt(enc, cipher, msg, WC_AES_BLOCK_SIZE);
  12307. #if defined(WOLFSSL_ASYNC_CRYPT)
  12308. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12309. #endif
  12310. if (ret != 0)
  12311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12312. #ifdef HAVE_AES_DECRYPT
  12313. XMEMSET(plain, 0, sizeof(plain));
  12314. ret = wc_AesCbcDecrypt(dec, plain, cipher, WC_AES_BLOCK_SIZE);
  12315. #if defined(WOLFSSL_ASYNC_CRYPT)
  12316. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12317. #endif
  12318. if (ret != 0) {
  12319. WOLFSSL_MSG("failed wc_AesCbcDecrypt");
  12320. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12321. }
  12322. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE)) {
  12323. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain compare");
  12324. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12325. }
  12326. #endif /* HAVE_AES_DECRYPT */
  12327. /* skipped because wrapped key use in case of renesas sm */
  12328. #ifndef HAVE_RENESAS_SYNC
  12329. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE)) {
  12330. WOLFSSL_MSG("wc_AesCbcDecrypt failed cipher-verify compare");
  12331. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12332. }
  12333. #endif
  12334. }
  12335. #endif /* WOLFSSL_AES_128 */
  12336. #if defined(WOLFSSL_AESNI) && defined(HAVE_AES_DECRYPT)
  12337. {
  12338. WOLFSSL_SMALL_STACK_STATIC const byte bigMsg[] = {
  12339. /* "All work and no play makes Jack a dull boy. " */
  12340. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12341. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12342. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12343. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12344. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12345. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12346. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12347. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12348. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12349. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12350. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12351. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12352. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12353. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12354. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12355. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12356. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12357. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12358. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12359. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12360. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12361. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12362. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12363. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12364. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12365. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12366. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12367. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12368. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12369. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12370. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12371. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12372. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12373. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12374. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12375. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12376. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12377. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12378. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12379. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12380. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12381. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12382. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12383. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12384. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12385. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12386. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12387. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20
  12388. };
  12389. WOLFSSL_SMALL_STACK_STATIC const byte bigKey[] =
  12390. "0123456789abcdeffedcba9876543210";
  12391. /* padded to 16-bytes */
  12392. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12393. word32 keySz, msgSz;
  12394. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12395. byte *bigCipher = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12396. DYNAMIC_TYPE_TMP_BUFFER);
  12397. byte *bigPlain = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12398. DYNAMIC_TYPE_TMP_BUFFER);
  12399. if ((bigCipher == NULL) ||
  12400. (bigPlain == NULL)) {
  12401. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12402. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12403. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12404. }
  12405. #else
  12406. byte bigCipher[sizeof(bigMsg)];
  12407. byte bigPlain[sizeof(bigMsg)];
  12408. #endif
  12409. /* Iterate from one WC_AES_BLOCK_SIZE of bigMsg through the whole
  12410. * message by WC_AES_BLOCK_SIZE for each size of AES key. */
  12411. for (keySz = 16; keySz <= 32; keySz += 8) {
  12412. for (msgSz = WC_AES_BLOCK_SIZE;
  12413. msgSz <= sizeof(bigMsg);
  12414. msgSz += WC_AES_BLOCK_SIZE) {
  12415. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12416. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12417. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12418. if (ret != 0) {
  12419. ret = WC_TEST_RET_ENC_EC(ret);
  12420. break;
  12421. }
  12422. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12423. if (ret != 0) {
  12424. ret = WC_TEST_RET_ENC_EC(ret);
  12425. break;
  12426. }
  12427. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12428. #if defined(WOLFSSL_ASYNC_CRYPT)
  12429. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12430. #endif
  12431. if (ret != 0) {
  12432. ret = WC_TEST_RET_ENC_EC(ret);
  12433. break;
  12434. }
  12435. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12436. #if defined(WOLFSSL_ASYNC_CRYPT)
  12437. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12438. #endif
  12439. if (ret != 0) {
  12440. ret = WC_TEST_RET_ENC_EC(ret);
  12441. break;
  12442. }
  12443. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12444. ret = WC_TEST_RET_ENC_NC;
  12445. break;
  12446. }
  12447. }
  12448. if (ret != 0)
  12449. break;
  12450. }
  12451. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12452. /* Iterate from one WC_AES_BLOCK_SIZE of bigMsg through the whole
  12453. * message by WC_AES_BLOCK_SIZE for each size of AES key. */
  12454. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12455. for (keySz = 16; keySz <= 32; keySz += 8) {
  12456. for (msgSz = WC_AES_BLOCK_SIZE;
  12457. msgSz <= sizeof(bigMsg);
  12458. msgSz += WC_AES_BLOCK_SIZE) {
  12459. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12460. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12461. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12462. if (ret != 0) {
  12463. ret = WC_TEST_RET_ENC_EC(ret);
  12464. break;
  12465. }
  12466. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12467. if (ret != 0) {
  12468. ret = WC_TEST_RET_ENC_EC(ret);
  12469. break;
  12470. }
  12471. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12472. #if defined(WOLFSSL_ASYNC_CRYPT)
  12473. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12474. #endif
  12475. if (ret != 0) {
  12476. ret = WC_TEST_RET_ENC_EC(ret);
  12477. break;
  12478. }
  12479. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12480. #if defined(WOLFSSL_ASYNC_CRYPT)
  12481. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12482. #endif
  12483. if (ret != 0) {
  12484. ret = WC_TEST_RET_ENC_EC(ret);
  12485. break;
  12486. }
  12487. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12488. ret = WC_TEST_RET_ENC_NC;
  12489. break;
  12490. }
  12491. }
  12492. if (ret != 0)
  12493. break;
  12494. }
  12495. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12496. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12497. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12498. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12499. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12500. #endif
  12501. if (ret != 0)
  12502. goto out;
  12503. }
  12504. #endif /* WOLFSSL_AESNI && HAVE_AES_DECRYPT */
  12505. /* Test of AES IV state with encrypt/decrypt */
  12506. #if defined(WOLFSSL_AES_128) && !defined(HAVE_RENESAS_SYNC)
  12507. {
  12508. /* Test Vector from "NIST Special Publication 800-38A, 2001 Edition"
  12509. * https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38a.pdf
  12510. */
  12511. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  12512. {
  12513. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  12514. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  12515. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  12516. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51
  12517. };
  12518. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] =
  12519. {
  12520. 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
  12521. 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
  12522. 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
  12523. 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2
  12524. };
  12525. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  12526. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  12527. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  12528. };
  12529. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  12530. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  12531. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  12532. };
  12533. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  12534. if (ret != 0)
  12535. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12536. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE * 2);
  12537. ret = wc_AesCbcEncrypt(enc, cipher, msg2, WC_AES_BLOCK_SIZE);
  12538. #if defined(WOLFSSL_ASYNC_CRYPT)
  12539. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12540. #endif
  12541. if (ret != 0)
  12542. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12543. #ifndef HAVE_RENESAS_SYNC
  12544. if (XMEMCMP(cipher, verify2, WC_AES_BLOCK_SIZE))
  12545. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12546. #endif
  12547. ret = wc_AesCbcEncrypt(enc, cipher + WC_AES_BLOCK_SIZE,
  12548. msg2 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
  12549. #if defined(WOLFSSL_ASYNC_CRYPT)
  12550. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12551. #endif
  12552. if (ret != 0)
  12553. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12554. if (XMEMCMP(cipher + WC_AES_BLOCK_SIZE, verify2 + WC_AES_BLOCK_SIZE,
  12555. WC_AES_BLOCK_SIZE))
  12556. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12557. #if defined(HAVE_AES_DECRYPT)
  12558. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION);
  12559. if (ret != 0)
  12560. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12561. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE * 2);
  12562. ret = wc_AesCbcDecrypt(dec, plain, verify2, WC_AES_BLOCK_SIZE);
  12563. #if defined(WOLFSSL_ASYNC_CRYPT)
  12564. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12565. #endif
  12566. if (ret != 0)
  12567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12568. if (XMEMCMP(plain, msg2, WC_AES_BLOCK_SIZE))
  12569. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12570. ret = wc_AesCbcDecrypt(dec, plain + WC_AES_BLOCK_SIZE,
  12571. verify2 + WC_AES_BLOCK_SIZE, WC_AES_BLOCK_SIZE);
  12572. #if defined(WOLFSSL_ASYNC_CRYPT)
  12573. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12574. #endif
  12575. if (ret != 0)
  12576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12577. if (XMEMCMP(plain + WC_AES_BLOCK_SIZE, msg2 + WC_AES_BLOCK_SIZE,
  12578. WC_AES_BLOCK_SIZE)) {
  12579. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain-msg2 compare");
  12580. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12581. }
  12582. #endif /* HAVE_AES_DECRYPT */
  12583. aes_cbc_oneshot_test();
  12584. }
  12585. #endif /* WOLFSSL_AES_128 && !HAVE_RENESAS_SYNC */
  12586. out:
  12587. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12588. wc_AesDelete(enc, &enc);
  12589. #else
  12590. wc_AesFree(enc);
  12591. #endif
  12592. #ifdef HAVE_AES_DECRYPT
  12593. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12594. wc_AesDelete(dec, &dec);
  12595. #else
  12596. wc_AesFree(dec);
  12597. #endif
  12598. #endif
  12599. return ret;
  12600. }
  12601. #endif /* HAVE_AES_CBC */
  12602. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12603. static wc_test_ret_t aes_ecb_direct_test(void)
  12604. {
  12605. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12606. Aes *enc = NULL;
  12607. #else
  12608. Aes enc[1];
  12609. #endif
  12610. #if !defined(HAVE_AES_DECRYPT) || \
  12611. (defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC))
  12612. Aes *dec = NULL;
  12613. #else
  12614. Aes dec[1];
  12615. #endif
  12616. byte cipher[WC_AES_BLOCK_SIZE];
  12617. byte plain [WC_AES_BLOCK_SIZE];
  12618. wc_test_ret_t ret = 0;
  12619. WOLFSSL_ENTER("aes_ecb/direct_test");
  12620. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  12621. XMEMSET(enc, 0, sizeof(Aes));
  12622. #ifdef HAVE_AES_DECRYPT
  12623. XMEMSET(dec, 0, sizeof(Aes));
  12624. #endif
  12625. #endif
  12626. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12627. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12628. if (enc == NULL)
  12629. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12630. #ifdef HAVE_AES_DECRYPT
  12631. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12632. if (dec == NULL)
  12633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12634. #endif
  12635. #else
  12636. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12637. if (ret != 0)
  12638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12639. #ifdef HAVE_AES_DECRYPT
  12640. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12641. if (ret != 0)
  12642. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12643. #endif
  12644. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12645. #ifdef HAVE_AES_ECB
  12646. ret = aes_ecb_test(enc, dec, cipher, plain);
  12647. if (ret != 0)
  12648. return ret;
  12649. #endif
  12650. #ifdef WOLFSSL_AES_DIRECT
  12651. ret = aes_direct_test(enc, dec, cipher, plain);
  12652. if (ret != 0)
  12653. return ret;
  12654. #endif
  12655. out:
  12656. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12657. wc_AesDelete(enc, &enc);
  12658. wc_AesDelete(dec, &dec);
  12659. #else
  12660. wc_AesFree(enc);
  12661. wc_AesFree(dec);
  12662. #endif
  12663. return ret;
  12664. }
  12665. #endif /* HAVE_AES_ECB || WOLFSSL_AES_DIRECT */
  12666. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void)
  12667. {
  12668. wc_test_ret_t ret = 0;
  12669. WOLFSSL_ENTER("aes_test");
  12670. #ifndef HAVE_RENESAS_SYNC
  12671. ret = aes_key_size_test();
  12672. if (ret != 0)
  12673. goto out;
  12674. #endif
  12675. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12676. ret = aes_ecb_direct_test();
  12677. if (ret != 0)
  12678. return ret;
  12679. #endif
  12680. out:
  12681. return ret;
  12682. }
  12683. #if defined(WOLFSSL_AES_CFB)
  12684. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void)
  12685. {
  12686. int ret;
  12687. WOLFSSL_ENTER("aes_cfb_test");
  12688. ret = aescfb_test_0();
  12689. if (ret != 0)
  12690. return ret;
  12691. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  12692. ret = aescfb1_test();
  12693. if (ret != 0)
  12694. return ret;
  12695. ret = aescfb8_test();
  12696. if (ret != 0)
  12697. return ret;
  12698. #endif
  12699. return 0;
  12700. }
  12701. #endif
  12702. #if defined(WOLFSSL_AES_XTS)
  12703. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void)
  12704. {
  12705. int ret = 0;
  12706. WOLFSSL_ENTER("aes_xts_test");
  12707. #ifdef WOLFSSL_AES_128
  12708. ret = aes_xts_128_test();
  12709. if (ret != 0)
  12710. return ret;
  12711. #endif
  12712. #ifdef WOLFSSL_AES_192
  12713. ret = aes_xts_192_test();
  12714. if (ret != 0)
  12715. return ret;
  12716. #endif
  12717. #ifdef WOLFSSL_AES_256
  12718. ret = aes_xts_256_test();
  12719. if (ret != 0)
  12720. return ret;
  12721. #endif
  12722. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  12723. ret = aes_xts_sector_test();
  12724. if (ret != 0)
  12725. return ret;
  12726. #endif
  12727. #ifdef WOLFSSL_AES_128
  12728. ret = aes_xts_args_test();
  12729. if (ret != 0)
  12730. return ret;
  12731. #endif
  12732. return 0;
  12733. }
  12734. #endif
  12735. #ifdef WOLFSSL_AES_192
  12736. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
  12737. {
  12738. wc_test_ret_t ret = 0;
  12739. #ifdef HAVE_AES_CBC
  12740. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12741. Aes *enc = NULL;
  12742. #else
  12743. Aes enc[1];
  12744. #endif
  12745. byte cipher[WC_AES_BLOCK_SIZE];
  12746. #ifdef HAVE_AES_DECRYPT
  12747. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12748. Aes *dec = NULL;
  12749. #else
  12750. Aes dec[1];
  12751. #endif
  12752. byte plain[WC_AES_BLOCK_SIZE];
  12753. #endif
  12754. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  12755. * Appendix F.2.3 */
  12756. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12757. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12758. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12759. };
  12760. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12761. {
  12762. 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  12763. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8
  12764. };
  12765. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12766. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  12767. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  12768. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  12769. };
  12770. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12771. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12772. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12773. };
  12774. WOLFSSL_ENTER("aes192_test");
  12775. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12776. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12777. if (enc == NULL)
  12778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12779. #ifdef HAVE_AES_DECRYPT
  12780. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12781. if (dec == NULL)
  12782. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12783. #endif
  12784. #else
  12785. XMEMSET(enc, 0, sizeof(Aes));
  12786. #ifdef HAVE_AES_DECRYPT
  12787. XMEMSET(dec, 0, sizeof(Aes));
  12788. #endif
  12789. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12790. if (ret != 0)
  12791. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12792. #ifdef HAVE_AES_DECRYPT
  12793. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12794. if (ret != 0)
  12795. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12796. #endif
  12797. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12798. ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
  12799. if (ret != 0)
  12800. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12801. #ifdef HAVE_AES_DECRYPT
  12802. ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION);
  12803. if (ret != 0)
  12804. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12805. #endif
  12806. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12807. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12808. #if defined(WOLFSSL_ASYNC_CRYPT)
  12809. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12810. #endif
  12811. if (ret != 0)
  12812. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12813. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12814. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12815. #ifdef HAVE_AES_DECRYPT
  12816. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12817. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12818. #if defined(WOLFSSL_ASYNC_CRYPT)
  12819. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12820. #endif
  12821. if (ret != 0)
  12822. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12823. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12824. WOLFSSL_MSG("failed wc_AesCbcDecrypt plain-msg compare");
  12825. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12826. }
  12827. #endif
  12828. out:
  12829. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12830. wc_AesDelete(enc, &enc);
  12831. #else
  12832. wc_AesFree(enc);
  12833. #endif
  12834. #ifdef HAVE_AES_DECRYPT
  12835. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12836. wc_AesDelete(dec, &dec);
  12837. #else
  12838. wc_AesFree(dec);
  12839. #endif
  12840. #endif
  12841. #endif /* HAVE_AES_CBC */
  12842. return ret;
  12843. }
  12844. #endif /* WOLFSSL_AES_192 */
  12845. #ifdef WOLFSSL_AES_256
  12846. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
  12847. {
  12848. #ifdef HAVE_AES_CBC
  12849. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12850. Aes *enc = NULL;
  12851. #else
  12852. Aes enc[1];
  12853. #endif
  12854. byte cipher[WC_AES_BLOCK_SIZE];
  12855. #ifdef HAVE_AES_DECRYPT
  12856. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12857. Aes *dec = NULL;
  12858. #else
  12859. Aes dec[1];
  12860. #endif
  12861. byte plain[WC_AES_BLOCK_SIZE];
  12862. #endif
  12863. #endif /* HAVE_AES_CBC */
  12864. wc_test_ret_t ret = 0;
  12865. #ifdef HAVE_AES_CBC
  12866. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  12867. * Appendix F.2.5 */
  12868. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12869. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12870. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12871. };
  12872. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12873. {
  12874. 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  12875. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6
  12876. };
  12877. #ifdef HAVE_RENESAS_SYNC
  12878. byte *key =
  12879. (byte*)guser_PKCbInfo.wrapped_key_aes256;
  12880. int keySz = (256/8);
  12881. #else
  12882. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12883. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12884. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12885. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12886. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12887. };
  12888. int keySz = (int)sizeof(key);
  12889. #endif
  12890. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12891. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12892. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12893. };
  12894. WOLFSSL_ENTER("aes256_test");
  12895. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12896. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12897. if (enc == NULL)
  12898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12899. #ifdef HAVE_AES_DECRYPT
  12900. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12901. if (dec == NULL)
  12902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12903. #endif
  12904. #else
  12905. XMEMSET(enc, 0, sizeof(Aes));
  12906. #ifdef HAVE_AES_DECRYPT
  12907. XMEMSET(dec, 0, sizeof(Aes));
  12908. #endif
  12909. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12910. if (ret != 0)
  12911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12912. #ifdef HAVE_AES_DECRYPT
  12913. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12914. if (ret != 0)
  12915. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12916. #endif
  12917. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12918. ret = wc_AesSetKey(enc, key, (word32)keySz, iv, AES_ENCRYPTION);
  12919. if (ret != 0)
  12920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12921. #ifdef HAVE_AES_DECRYPT
  12922. ret = wc_AesSetKey(dec, key, (word32)keySz, iv, AES_DECRYPTION);
  12923. if (ret != 0)
  12924. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12925. #endif
  12926. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12927. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12928. #if defined(WOLFSSL_ASYNC_CRYPT)
  12929. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12930. #endif
  12931. if (ret != 0)
  12932. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12933. #ifdef HAVE_AES_DECRYPT
  12934. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12935. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12936. #if defined(WOLFSSL_ASYNC_CRYPT)
  12937. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12938. #endif
  12939. if (ret != 0)
  12940. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12941. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12942. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12943. }
  12944. #endif
  12945. #ifndef HAVE_RENESAS_SYNC
  12946. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12947. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12948. #endif
  12949. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12950. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12951. if (ret != 0)
  12952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12953. #ifdef HAVE_AES_DECRYPT
  12954. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12955. if (ret != 0)
  12956. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12957. #endif
  12958. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12959. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12960. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12961. #if defined(WOLFSSL_ASYNC_CRYPT)
  12962. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12963. #endif
  12964. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12965. if (ret != 0)
  12966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12967. #ifdef HAVE_AES_DECRYPT
  12968. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  12969. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12970. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12971. #if defined(WOLFSSL_ASYNC_CRYPT)
  12972. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12973. #endif
  12974. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12975. if (ret != 0)
  12976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12977. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12978. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12979. }
  12980. #endif
  12981. #ifndef HAVE_RENESAS_SYNC
  12982. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12983. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12984. #endif
  12985. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12986. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12987. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12988. if (ret != 0)
  12989. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12990. #ifdef HAVE_AES_DECRYPT
  12991. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12992. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12993. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12994. if (ret != 0)
  12995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12996. #endif
  12997. XMEMSET(cipher, 0, WC_AES_BLOCK_SIZE);
  12998. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12999. #if defined(WOLFSSL_ASYNC_CRYPT)
  13000. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13001. #endif
  13002. if (ret != 0)
  13003. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13004. #ifdef HAVE_AES_DECRYPT
  13005. XMEMSET(plain, 0, WC_AES_BLOCK_SIZE);
  13006. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  13007. #if defined(WOLFSSL_ASYNC_CRYPT)
  13008. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13009. #endif
  13010. if (ret != 0)
  13011. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13012. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  13013. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13014. }
  13015. #endif
  13016. #ifndef HAVE_RENESAS_SYNC
  13017. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  13018. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13019. #endif
  13020. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  13021. out:
  13022. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13023. wc_AesDelete(enc, &enc);
  13024. #else
  13025. wc_AesFree(enc);
  13026. #endif
  13027. #ifdef HAVE_AES_DECRYPT
  13028. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13029. wc_AesDelete(dec, &dec);
  13030. #else
  13031. wc_AesFree(dec);
  13032. #endif
  13033. #endif
  13034. #endif /* HAVE_AES_CBC */
  13035. return ret;
  13036. }
  13037. #endif /* WOLFSSL_AES_256 */
  13038. #ifdef HAVE_AESGCM
  13039. #ifdef WOLFSSL_AES_128
  13040. static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz,
  13041. byte* plain, int plainSz, byte* cipher, int cipherSz,
  13042. byte* aad, int aadSz, byte* tag, int tagSz)
  13043. {
  13044. wc_test_ret_t ret;
  13045. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13046. Aes *enc = NULL;
  13047. Aes *dec = NULL;
  13048. #else
  13049. Aes enc[1];
  13050. Aes dec[1];
  13051. #endif
  13052. byte resultT[WC_AES_BLOCK_SIZE];
  13053. byte resultP[WC_AES_BLOCK_SIZE * 3];
  13054. byte resultC[WC_AES_BLOCK_SIZE * 3];
  13055. XMEMSET(resultT, 0, sizeof(resultT));
  13056. XMEMSET(resultC, 0, sizeof(resultC));
  13057. XMEMSET(resultP, 0, sizeof(resultP));
  13058. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13059. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13060. if (enc == NULL)
  13061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13062. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13063. if (dec == NULL)
  13064. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13065. #else
  13066. XMEMSET(enc, 0, sizeof(Aes));
  13067. XMEMSET(dec, 0, sizeof(Aes));
  13068. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13069. if (ret != 0)
  13070. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13071. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13072. if (ret != 0)
  13073. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13074. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  13075. ret = wc_AesGcmSetKey(enc, key, (word32)keySz);
  13076. if (ret != 0)
  13077. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13078. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13079. ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, (word32)ivSz,
  13080. resultT, (word32)tagSz, aad, (word32)aadSz);
  13081. #if defined(WOLFSSL_ASYNC_CRYPT)
  13082. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13083. #endif
  13084. if (ret != 0)
  13085. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13086. if (cipher != NULL) {
  13087. if (XMEMCMP(cipher, resultC, (word32)cipherSz))
  13088. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13089. }
  13090. if (XMEMCMP(tag, resultT, (unsigned long)tagSz))
  13091. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13092. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13093. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13094. ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz,
  13095. resultT, tagSz, aad, aadSz);
  13096. #if defined(WOLFSSL_ASYNC_CRYPT)
  13097. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13098. #endif
  13099. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13100. if (ret != 0)
  13101. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13102. if (cipher != NULL) {
  13103. if (XMEMCMP(cipher, resultC, (unsigned long)cipherSz))
  13104. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13105. }
  13106. if (XMEMCMP(tag, resultT, tagSz))
  13107. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13108. #endif
  13109. #ifdef HAVE_AES_DECRYPT
  13110. ret = wc_AesGcmSetKey(dec, key, (word32)keySz);
  13111. if (ret != 0)
  13112. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13113. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)cipherSz,
  13114. iv, (word32)ivSz, resultT, (word32)tagSz, aad, (word32)aadSz);
  13115. #if defined(WOLFSSL_ASYNC_CRYPT)
  13116. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13117. #endif
  13118. if (ret != 0)
  13119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13120. if (plain != NULL) {
  13121. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13122. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13123. }
  13124. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13125. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13126. ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz,
  13127. iv, ivSz, resultT, tagSz, aad, aadSz);
  13128. #if defined(WOLFSSL_ASYNC_CRYPT)
  13129. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13130. #endif
  13131. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13132. if (ret != 0)
  13133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13134. if (plain != NULL) {
  13135. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13136. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13137. }
  13138. #endif
  13139. #endif /* HAVE_AES_DECRYPT */
  13140. ret = 0;
  13141. out:
  13142. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13143. wc_AesDelete(enc, &enc);
  13144. wc_AesDelete(dec, &dec);
  13145. #else
  13146. wc_AesFree(enc);
  13147. wc_AesFree(dec);
  13148. #endif
  13149. return ret;
  13150. }
  13151. #endif
  13152. /* tests that only use 12 byte IV and 16 or less byte AAD
  13153. * test vectors are from NIST SP 800-38D
  13154. * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES*/
  13155. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void)
  13156. {
  13157. #ifdef WOLFSSL_AES_128
  13158. byte key1[] = {
  13159. 0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62,
  13160. 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc
  13161. };
  13162. byte iv1[] = {
  13163. 0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa,
  13164. 0xe4, 0xed, 0x2f, 0x6d
  13165. };
  13166. ALIGN64 byte plain1[] = {
  13167. 0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad,
  13168. 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01,
  13169. 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac,
  13170. 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01
  13171. };
  13172. byte aad1[] = {
  13173. 0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73,
  13174. 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1
  13175. };
  13176. ALIGN64 byte cipher1[] = {
  13177. 0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d,
  13178. 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d,
  13179. 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46,
  13180. 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb
  13181. };
  13182. byte tag1[] = {
  13183. 0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7,
  13184. 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2
  13185. };
  13186. byte key2[] = {
  13187. 0x01, 0x6d, 0xbb, 0x38, 0xda, 0xa7, 0x6d, 0xfe,
  13188. 0x7d, 0xa3, 0x84, 0xeb, 0xf1, 0x24, 0x03, 0x64
  13189. };
  13190. byte iv2[] = {
  13191. 0x07, 0x93, 0xef, 0x3a, 0xda, 0x78, 0x2f, 0x78,
  13192. 0xc9, 0x8a, 0xff, 0xe3
  13193. };
  13194. ALIGN64 byte plain2[] = {
  13195. 0x4b, 0x34, 0xa9, 0xec, 0x57, 0x63, 0x52, 0x4b,
  13196. 0x19, 0x1d, 0x56, 0x16, 0xc5, 0x47, 0xf6, 0xb7
  13197. };
  13198. ALIGN64 byte cipher2[] = {
  13199. 0x60, 0x9a, 0xa3, 0xf4, 0x54, 0x1b, 0xc0, 0xfe,
  13200. 0x99, 0x31, 0xda, 0xad, 0x2e, 0xe1, 0x5d, 0x0c
  13201. };
  13202. byte tag2[] = {
  13203. 0x33, 0xaf, 0xec, 0x59, 0xc4, 0x5b, 0xaf, 0x68,
  13204. 0x9a, 0x5e, 0x1b, 0x13, 0xae, 0x42, 0x36, 0x19
  13205. };
  13206. byte key3[] = {
  13207. 0xb0, 0x1e, 0x45, 0xcc, 0x30, 0x88, 0xaa, 0xba,
  13208. 0x9f, 0xa4, 0x3d, 0x81, 0xd4, 0x81, 0x82, 0x3f
  13209. };
  13210. byte iv3[] = {
  13211. 0x5a, 0x2c, 0x4a, 0x66, 0x46, 0x87, 0x13, 0x45,
  13212. 0x6a, 0x4b, 0xd5, 0xe1
  13213. };
  13214. byte tag3[] = {
  13215. 0x01, 0x42, 0x80, 0xf9, 0x44, 0xf5, 0x3c, 0x68,
  13216. 0x11, 0x64, 0xb2, 0xff
  13217. };
  13218. wc_test_ret_t ret;
  13219. WOLFSSL_ENTER("aesgcm_default_test");
  13220. ret = aesgcm_default_test_helper(key1, sizeof(key1), iv1, sizeof(iv1),
  13221. plain1, sizeof(plain1), cipher1, sizeof(cipher1),
  13222. aad1, sizeof(aad1), tag1, sizeof(tag1));
  13223. if (ret != 0) {
  13224. return ret;
  13225. }
  13226. ret = aesgcm_default_test_helper(key2, sizeof(key2), iv2, sizeof(iv2),
  13227. plain2, sizeof(plain2), cipher2, sizeof(cipher2),
  13228. NULL, 0, tag2, sizeof(tag2));
  13229. if (ret != 0) {
  13230. return ret;
  13231. }
  13232. ret = aesgcm_default_test_helper(key3, sizeof(key3), iv3, sizeof(iv3),
  13233. NULL, 0, NULL, 0,
  13234. NULL, 0, tag3, sizeof(tag3));
  13235. if (ret != 0) {
  13236. return ret;
  13237. }
  13238. #endif
  13239. return 0;
  13240. }
  13241. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
  13242. {
  13243. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13244. Aes *enc = NULL;
  13245. Aes *dec = NULL;
  13246. #else
  13247. Aes enc[1];
  13248. Aes dec[1];
  13249. #endif
  13250. /*
  13251. * This is Test Case 16 from the document Galois/
  13252. * Counter Mode of Operation (GCM) by McGrew and
  13253. * Viega.
  13254. */
  13255. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  13256. {
  13257. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  13258. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  13259. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  13260. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  13261. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  13262. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  13263. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  13264. 0xba, 0x63, 0x7b, 0x39
  13265. };
  13266. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  13267. {
  13268. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13269. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13270. 0xab, 0xad, 0xda, 0xd2
  13271. };
  13272. #ifdef WOLFSSL_AES_256
  13273. #ifdef HAVE_RENESAS_SYNC
  13274. const byte *k1 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  13275. int k1Sz = (int)(256/8);
  13276. #else
  13277. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13278. {
  13279. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13280. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13281. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13282. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  13283. };
  13284. int k1Sz = (int)sizeof(k1);
  13285. #endif
  13286. #endif /* WOLFSSL_AES_256 */
  13287. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13288. {
  13289. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  13290. 0xde, 0xca, 0xf8, 0x88
  13291. };
  13292. #if defined(WOLFSSL_AES_256) || defined(WOLFSSL_AES_192)
  13293. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  13294. {
  13295. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  13296. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  13297. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  13298. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  13299. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  13300. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  13301. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  13302. 0xbc, 0xc9, 0xf6, 0x62
  13303. };
  13304. #endif /* WOLFSSL_AES_256 || WOLFSSL_AES_192 */
  13305. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13306. {
  13307. 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
  13308. 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b
  13309. };
  13310. /* FIPS, QAT and PIC32MZ HW Crypto only support 12-byte IV */
  13311. #if !defined(HAVE_FIPS) && \
  13312. !defined(WOLFSSL_PIC32MZ_CRYPT) && \
  13313. !defined(FREESCALE_LTC) && !defined(FREESCALE_MMCAU) && \
  13314. !defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13315. !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(WOLFSSL_KCAPI_AES) && \
  13316. !(defined(WOLF_CRYPTO_CB) && \
  13317. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  13318. #define ENABLE_NON_12BYTE_IV_TEST
  13319. #ifdef WOLFSSL_AES_192
  13320. /* Test Case 12, uses same plaintext and AAD data. */
  13321. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13322. {
  13323. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13324. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13325. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c
  13326. };
  13327. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13328. {
  13329. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  13330. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  13331. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  13332. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  13333. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  13334. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  13335. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  13336. 0xa6, 0x37, 0xb3, 0x9b
  13337. };
  13338. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  13339. {
  13340. 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
  13341. 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
  13342. 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
  13343. 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
  13344. 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
  13345. 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
  13346. 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
  13347. 0xe9, 0xb7, 0x37, 0x3b
  13348. };
  13349. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13350. {
  13351. 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
  13352. 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9
  13353. };
  13354. #endif /* WOLFSSL_AES_192 */
  13355. #ifdef WOLFSSL_AES_128
  13356. /* The following is an interesting test case from the example
  13357. * FIPS test vectors for AES-GCM. IVlen = 1 byte */
  13358. WOLFSSL_SMALL_STACK_STATIC const byte p3[] =
  13359. {
  13360. 0x57, 0xce, 0x45, 0x1f, 0xa5, 0xe2, 0x35, 0xa5,
  13361. 0x8e, 0x1a, 0xa2, 0x3b, 0x77, 0xcb, 0xaf, 0xe2
  13362. };
  13363. #ifdef HAVE_RENESAS_SYNC
  13364. const byte *k3 =
  13365. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  13366. int k3Sz = (int)(128/8);
  13367. #else
  13368. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  13369. {
  13370. 0xbb, 0x01, 0xd7, 0x03, 0x81, 0x1c, 0x10, 0x1a,
  13371. 0x35, 0xe0, 0xff, 0xd2, 0x91, 0xba, 0xf2, 0x4b
  13372. };
  13373. int k3Sz = (int)sizeof(k3);
  13374. #endif
  13375. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  13376. {
  13377. 0xca
  13378. };
  13379. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  13380. {
  13381. 0x6b, 0x5f, 0xb3, 0x9d, 0xc1, 0xc5, 0x7a, 0x4f,
  13382. 0xf3, 0x51, 0x4d, 0xc2, 0xd5, 0xf0, 0xd0, 0x07
  13383. };
  13384. WOLFSSL_SMALL_STACK_STATIC const byte a3[] =
  13385. {
  13386. 0x40, 0xfc, 0xdc, 0xd7, 0x4a, 0xd7, 0x8b, 0xf1,
  13387. 0x3e, 0x7c, 0x60, 0x55, 0x50, 0x51, 0xdd, 0x54
  13388. };
  13389. WOLFSSL_SMALL_STACK_STATIC const byte t3[] =
  13390. {
  13391. 0x06, 0x90, 0xed, 0x01, 0x34, 0xdd, 0xc6, 0x95,
  13392. 0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
  13393. };
  13394. #endif /* WOLFSSL_AES_128 */
  13395. #ifdef WOLFSSL_AES_256
  13396. int ivlen;
  13397. #endif
  13398. #endif
  13399. byte resultT[sizeof(t1) + WC_AES_BLOCK_SIZE];
  13400. byte resultP[sizeof(p) + WC_AES_BLOCK_SIZE];
  13401. byte resultC[sizeof(p) + WC_AES_BLOCK_SIZE];
  13402. wc_test_ret_t ret = 0;
  13403. int alen = 0;
  13404. int plen = 0;
  13405. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13406. byte buf[sizeof(p) + WC_AES_BLOCK_SIZE];
  13407. byte bufA[sizeof(a) + 1];
  13408. byte *large_aad = (byte*)XMALLOC((size_t)1024 + 16, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13409. #endif
  13410. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM)
  13411. #if !defined(BENCH_AESGCM_LARGE)
  13412. #define BENCH_AESGCM_LARGE 1024
  13413. #endif
  13414. #ifndef WOLFSSL_NO_MALLOC
  13415. byte *large_input = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13416. byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13417. byte *large_outdec = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13418. (void)alen;
  13419. (void)plen;
  13420. if ((! large_input) || (! large_output) || (! large_outdec))
  13421. ERROR_OUT(MEMORY_E, out);
  13422. #else
  13423. byte large_input[BENCH_AESGCM_LARGE];
  13424. byte large_output[BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE];
  13425. byte large_outdec[BENCH_AESGCM_LARGE];
  13426. #endif
  13427. XMEMSET(large_input, 0, BENCH_AESGCM_LARGE);
  13428. XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + WC_AES_BLOCK_SIZE);
  13429. XMEMSET(large_outdec, 0, BENCH_AESGCM_LARGE);
  13430. #endif
  13431. WOLFSSL_ENTER("aesgcm_test");
  13432. XMEMSET(resultT, 0, sizeof(resultT));
  13433. XMEMSET(resultC, 0, sizeof(resultC));
  13434. XMEMSET(resultP, 0, sizeof(resultP));
  13435. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13436. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13437. if (enc == NULL)
  13438. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13439. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13440. if (dec == NULL)
  13441. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13442. #else
  13443. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13444. if (ret != 0)
  13445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13446. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13447. if (ret != 0)
  13448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13449. #endif
  13450. #ifdef WOLFSSL_AES_256
  13451. ret = wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13452. if (ret != 0)
  13453. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13454. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13455. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13456. resultT, sizeof(t1), a, sizeof(a));
  13457. #if defined(WOLFSSL_ASYNC_CRYPT)
  13458. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13459. #endif
  13460. if (ret != 0)
  13461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13462. #ifndef HAVE_RENESAS_SYNC
  13463. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13464. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13465. if (XMEMCMP(t1, resultT, sizeof(t1)))
  13466. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13467. #endif
  13468. #ifdef HAVE_AES_DECRYPT
  13469. ret = wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13470. if (ret != 0)
  13471. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13472. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1),
  13473. iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13474. #if defined(WOLFSSL_ASYNC_CRYPT)
  13475. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13476. #endif
  13477. if (ret != 0)
  13478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13479. if (XMEMCMP(p, resultP, sizeof(p)))
  13480. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13481. #endif /* HAVE_AES_DECRYPT */
  13482. /* Large buffer test */
  13483. #ifdef BENCH_AESGCM_LARGE
  13484. /* setup test buffer */
  13485. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13486. large_input[alen] = (byte)alen;
  13487. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13488. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13489. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13490. resultT, sizeof(t1), a, sizeof(a));
  13491. #if defined(WOLFSSL_ASYNC_CRYPT)
  13492. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13493. #endif
  13494. if (ret != 0)
  13495. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13496. #ifdef HAVE_AES_DECRYPT
  13497. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13498. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13499. sizeof(t1), a, sizeof(a));
  13500. #if defined(WOLFSSL_ASYNC_CRYPT)
  13501. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13502. #endif
  13503. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13504. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13505. if (ret != 0)
  13506. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13507. #endif /* HAVE_AES_DECRYPT */
  13508. #endif /* BENCH_AESGCM_LARGE */
  13509. #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256)
  13510. /* Variable IV length test */
  13511. for (ivlen=1; ivlen<k1Sz; ivlen++) {
  13512. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13513. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1,
  13514. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13515. #if defined(WOLFSSL_ASYNC_CRYPT)
  13516. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13517. #endif
  13518. if (ret != 0)
  13519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13520. #ifdef HAVE_AES_DECRYPT
  13521. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1,
  13522. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13523. #if defined(WOLFSSL_ASYNC_CRYPT)
  13524. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13525. #endif
  13526. if (ret != 0)
  13527. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13528. #endif /* HAVE_AES_DECRYPT */
  13529. }
  13530. #endif
  13531. #if !(defined(WOLF_CRYPTO_CB) && defined(HAVE_INTEL_QA_SYNC))
  13532. /* Variable authenticated data length test */
  13533. for (alen=0; alen<(int)sizeof(p); alen++) {
  13534. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13535. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13536. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13537. #if defined(WOLFSSL_ASYNC_CRYPT)
  13538. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13539. #endif
  13540. if (ret != 0)
  13541. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13542. #ifdef HAVE_AES_DECRYPT
  13543. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13544. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13545. #if defined(WOLFSSL_ASYNC_CRYPT)
  13546. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13547. #endif
  13548. if (ret != 0)
  13549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13550. #endif /* HAVE_AES_DECRYPT */
  13551. }
  13552. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13553. if (! large_aad)
  13554. ERROR_OUT(MEMORY_E, out);
  13555. XMEMSET(large_aad, 0, 1024+16);
  13556. /* Variable authenticated data length test */
  13557. for (alen=0; alen<=1024; alen+=16) {
  13558. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13559. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13560. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13561. if (ret != 0)
  13562. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13563. #ifdef HAVE_AES_DECRYPT
  13564. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13565. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13566. if (ret != 0)
  13567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13568. #endif /* HAVE_AES_DECRYPT */
  13569. }
  13570. /* Test unaligned memory of all potential arguments */
  13571. ret = wc_AesGcmSetKey(enc, k1, k1Sz);
  13572. if (ret != 0)
  13573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13574. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13575. XMEMCPY(&buf[1], p, sizeof(p));
  13576. XMEMCPY(&bufA[1], a, sizeof(a));
  13577. ret = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1),
  13578. &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13579. if (ret != 0)
  13580. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13581. if (XMEMCMP(c1, &resultC[1], sizeof(c1)))
  13582. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13583. if (XMEMCMP(t1, &resultT[1], sizeof(t1)))
  13584. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13585. #ifdef HAVE_AES_DECRYPT
  13586. ret = wc_AesGcmSetKey(dec, k1, k1Sz);
  13587. if (ret != 0)
  13588. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13589. ret = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1),
  13590. iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13591. if (ret != 0)
  13592. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13593. if (XMEMCMP(p, &resultP[1], sizeof(p)))
  13594. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13595. #endif /* HAVE_AES_DECRYPT */
  13596. #endif /* Xilinx Versal */
  13597. #endif
  13598. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13599. #ifdef BENCH_AESGCM_LARGE
  13600. /* Variable plain text length test */
  13601. for (plen=1; plen<BENCH_AESGCM_LARGE; plen++) {
  13602. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13603. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13604. (word32)plen, iv1, sizeof(iv1), resultT,
  13605. sizeof(t1), a, sizeof(a));
  13606. #if defined(WOLFSSL_ASYNC_CRYPT)
  13607. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13608. #endif
  13609. if (ret != 0)
  13610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13611. #ifdef HAVE_AES_DECRYPT
  13612. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13613. (word32)plen, iv1, sizeof(iv1), resultT,
  13614. sizeof(t1), a, sizeof(a));
  13615. #if defined(WOLFSSL_ASYNC_CRYPT)
  13616. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13617. #endif
  13618. if (ret != 0)
  13619. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13620. #endif /* HAVE_AES_DECRYPT */
  13621. }
  13622. #else /* BENCH_AESGCM_LARGE */
  13623. /* Variable plain text length test */
  13624. for (plen=1; plen<(int)sizeof(p); plen++) {
  13625. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13626. ret = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1,
  13627. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13628. #if defined(WOLFSSL_ASYNC_CRYPT)
  13629. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13630. #endif
  13631. if (ret != 0)
  13632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13633. #ifdef HAVE_AES_DECRYPT
  13634. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1,
  13635. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13636. #if defined(WOLFSSL_ASYNC_CRYPT)
  13637. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13638. #endif
  13639. if (ret != 0)
  13640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13641. #endif /* HAVE_AES_DECRYPT */
  13642. }
  13643. #endif /* BENCH_AESGCM_LARGE */
  13644. #endif
  13645. #endif /* WOLFSSL_AES_256 */
  13646. /* test with IV != 12 bytes */
  13647. #ifdef ENABLE_NON_12BYTE_IV_TEST
  13648. XMEMSET(resultT, 0, sizeof(resultT));
  13649. XMEMSET(resultC, 0, sizeof(resultC));
  13650. XMEMSET(resultP, 0, sizeof(resultP));
  13651. #ifdef WOLFSSL_AES_192
  13652. wc_AesGcmSetKey(enc, k2, sizeof(k2));
  13653. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13654. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2),
  13655. resultT, sizeof(t1), a, sizeof(a));
  13656. #if defined(WOLFSSL_ASYNC_CRYPT)
  13657. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13658. #endif
  13659. if (ret != 0)
  13660. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13661. if (XMEMCMP(c2, resultC, sizeof(c2)))
  13662. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13663. if (XMEMCMP(t2, resultT, sizeof(t1)))
  13664. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13665. #ifdef HAVE_AES_DECRYPT
  13666. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1),
  13667. iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a));
  13668. #if defined(WOLFSSL_ASYNC_CRYPT)
  13669. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13670. #endif
  13671. if (ret != 0)
  13672. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13673. if (XMEMCMP(p, resultP, sizeof(p)))
  13674. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13675. #endif /* HAVE_AES_DECRYPT */
  13676. /* Large buffer test */
  13677. #ifdef BENCH_AESGCM_LARGE
  13678. wc_AesGcmSetKey(enc, k2, (word32)sizeof(k2));
  13679. wc_AesGcmSetKey(dec, k2, (word32)sizeof(k2));
  13680. /* setup test buffer */
  13681. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13682. large_input[alen] = (byte)alen;
  13683. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13684. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13685. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13686. resultT, sizeof(t1), a, sizeof(a));
  13687. #if defined(WOLFSSL_ASYNC_CRYPT)
  13688. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13689. #endif
  13690. if (ret != 0)
  13691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13692. #ifdef HAVE_AES_DECRYPT
  13693. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13694. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13695. sizeof(t1), a, sizeof(a));
  13696. #if defined(WOLFSSL_ASYNC_CRYPT)
  13697. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13698. #endif
  13699. if (ret != 0)
  13700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13701. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13702. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13703. #endif /* HAVE_AES_DECRYPT */
  13704. #endif /* BENCH_AESGCM_LARGE */
  13705. XMEMSET(resultT, 0, sizeof(resultT));
  13706. XMEMSET(resultC, 0, sizeof(resultC));
  13707. XMEMSET(resultP, 0, sizeof(resultP));
  13708. #endif /* WOLFSSL_AES_192 */
  13709. #ifdef WOLFSSL_AES_128
  13710. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13711. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13712. ret = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3),
  13713. resultT, sizeof(t3), a3, sizeof(a3));
  13714. #if defined(WOLFSSL_ASYNC_CRYPT)
  13715. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13716. #endif
  13717. if (ret != 0)
  13718. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13719. #ifndef HAVE_RENESAS_SYNC
  13720. if (XMEMCMP(c3, resultC, sizeof(c3)))
  13721. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13722. if (XMEMCMP(t3, resultT, sizeof(t3)))
  13723. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13724. #endif
  13725. #ifdef HAVE_AES_DECRYPT
  13726. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
  13727. iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3));
  13728. #if defined(WOLFSSL_ASYNC_CRYPT)
  13729. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13730. #endif
  13731. if (ret != 0)
  13732. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13733. if (XMEMCMP(p3, resultP, sizeof(p3)))
  13734. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13735. #endif /* HAVE_AES_DECRYPT */
  13736. /* Large buffer test */
  13737. #ifdef BENCH_AESGCM_LARGE
  13738. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13739. wc_AesGcmSetKey(dec, k3, (word32)k3Sz);
  13740. /* setup test buffer */
  13741. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13742. large_input[alen] = (byte)alen;
  13743. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13744. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13745. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13746. resultT, sizeof(t1), a, sizeof(a));
  13747. #if defined(WOLFSSL_ASYNC_CRYPT)
  13748. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13749. #endif
  13750. if (ret != 0)
  13751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13752. #ifdef HAVE_AES_DECRYPT
  13753. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13754. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13755. sizeof(t1), a, sizeof(a));
  13756. #if defined(WOLFSSL_ASYNC_CRYPT)
  13757. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13758. #endif
  13759. if (ret != 0)
  13760. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13761. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13762. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13763. #endif /* HAVE_AES_DECRYPT */
  13764. #endif /* BENCH_AESGCM_LARGE */
  13765. #endif /* WOLFSSL_AES_128 */
  13766. #endif /* ENABLE_NON_12BYTE_IV_TEST */
  13767. #if defined(WOLFSSL_AES_256) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13768. !defined(WOLFSSL_XILINX_CRYPT) && \
  13769. !(defined(WOLF_CRYPTO_CB) && \
  13770. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC))
  13771. XMEMSET(resultT, 0, sizeof(resultT));
  13772. XMEMSET(resultC, 0, sizeof(resultC));
  13773. XMEMSET(resultP, 0, sizeof(resultP));
  13774. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13775. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13776. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13777. resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13778. #if defined(WOLFSSL_ASYNC_CRYPT)
  13779. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13780. #endif
  13781. if (ret != 0)
  13782. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13783. #ifndef HAVE_RENESAS_SYNC
  13784. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13785. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13786. if (XMEMCMP(t1, resultT + 1, sizeof(t1) - 1))
  13787. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13788. #endif
  13789. #ifdef HAVE_AES_DECRYPT
  13790. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p),
  13791. iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13792. #if defined(WOLFSSL_ASYNC_CRYPT)
  13793. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13794. #endif
  13795. if (ret != 0)
  13796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13797. if (XMEMCMP(p, resultP, sizeof(p)))
  13798. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13799. #endif /* HAVE_AES_DECRYPT */
  13800. #endif /* WOLFSSL_AES_256 */
  13801. #if !defined(HAVE_FIPS) || \
  13802. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  13803. /* Test encrypt with internally generated IV */
  13804. #if defined(WOLFSSL_AES_256) && !(defined(WC_NO_RNG) || defined(HAVE_SELFTEST)) \
  13805. && !(defined(WOLF_CRYPTO_CB) && defined(HAVE_CAVIUM_OCTEON_SYNC))
  13806. {
  13807. WC_RNG rng;
  13808. byte randIV[12];
  13809. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  13810. if (ret != 0)
  13811. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13812. XMEMSET(randIV, 0, sizeof(randIV));
  13813. XMEMSET(resultT, 0, sizeof(resultT));
  13814. XMEMSET(resultC, 0, sizeof(resultC));
  13815. XMEMSET(resultP, 0, sizeof(resultP));
  13816. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13817. ret = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng);
  13818. if (ret != 0)
  13819. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13820. ret = wc_AesGcmEncrypt_ex(enc,
  13821. resultC, p, sizeof(p),
  13822. randIV, sizeof(randIV),
  13823. resultT, sizeof(t1),
  13824. a, sizeof(a));
  13825. #if defined(WOLFSSL_ASYNC_CRYPT)
  13826. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13827. #endif
  13828. if (ret != 0)
  13829. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13830. /* Check the IV has been set. */
  13831. {
  13832. word32 i, ivSum = 0;
  13833. for (i = 0; i < sizeof(randIV); i++)
  13834. ivSum += randIV[i];
  13835. if (ivSum == 0)
  13836. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13837. }
  13838. #ifdef HAVE_AES_DECRYPT
  13839. wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13840. ret = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng);
  13841. if (ret != 0)
  13842. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13843. ret = wc_AesGcmDecrypt(dec,
  13844. resultP, resultC, sizeof(c1),
  13845. randIV, sizeof(randIV),
  13846. resultT, sizeof(t1),
  13847. a, sizeof(a));
  13848. #if defined(WOLFSSL_ASYNC_CRYPT)
  13849. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13850. #endif
  13851. if (ret != 0)
  13852. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13853. if (XMEMCMP(p, resultP, sizeof(p)))
  13854. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13855. #endif /* HAVE_AES_DECRYPT */
  13856. wc_FreeRng(&rng);
  13857. }
  13858. #endif /* WOLFSSL_AES_256 && !(WC_NO_RNG || HAVE_SELFTEST) */
  13859. #endif /* HAVE_FIPS_VERSION >= 2 */
  13860. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13861. #ifdef WOLFSSL_AES_256
  13862. #ifdef WOLFSSL_AESGCM_STREAM
  13863. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13864. if (ret != 0)
  13865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13866. ret = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a));
  13867. if (ret != 0)
  13868. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13869. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13870. if (ret != 0)
  13871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13872. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13873. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13874. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13875. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13876. #ifdef HAVE_AES_DECRYPT
  13877. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13878. if (ret != 0)
  13879. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13880. ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a));
  13881. if (ret != 0)
  13882. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13883. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13884. if (ret != 0)
  13885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13886. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13887. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13888. #endif
  13889. /* alen is the size to pass in with each update. */
  13890. for (alen = 1; alen < WC_AES_BLOCK_SIZE + 1; alen++) {
  13891. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13892. if (ret != 0)
  13893. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13894. /* plen is the offset into AAD to update with. */
  13895. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13896. int len = sizeof(a) - plen;
  13897. if (len > alen) len = alen;
  13898. ret = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13899. if (ret != 0)
  13900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13901. }
  13902. /* plen is the offset into plaintext to update with. */
  13903. for (plen = 0; plen < (int)sizeof(p); plen += alen) {
  13904. int len = sizeof(p) - plen;
  13905. if (len > alen) len = alen;
  13906. ret = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, (word32)len,
  13907. NULL, 0);
  13908. if (ret != 0)
  13909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13910. }
  13911. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13912. if (ret != 0)
  13913. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13914. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13915. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13916. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13917. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13918. }
  13919. #ifdef HAVE_AES_DECRYPT
  13920. for (alen = 1; alen < WC_AES_BLOCK_SIZE + 1; alen++) {
  13921. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13922. if (ret != 0)
  13923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13924. /* plen is the offset into AAD to update with. */
  13925. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13926. int len = sizeof(a) - plen;
  13927. if (len > alen) len = alen;
  13928. ret = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13929. if (ret != 0)
  13930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13931. }
  13932. /* plen is the offset into cipher text to update with. */
  13933. for (plen = 0; plen < (int)sizeof(c1); plen += alen) {
  13934. int len = sizeof(c1) - plen;
  13935. if (len > alen) len = alen;
  13936. ret = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, (word32)len,
  13937. NULL, 0);
  13938. if (ret != 0)
  13939. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13940. }
  13941. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13942. if (ret != 0)
  13943. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13944. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13945. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13946. }
  13947. #endif /* HAVE_AES_DECRYPT */
  13948. #ifdef BENCH_AESGCM_LARGE
  13949. /* setup test buffer */
  13950. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13951. if (ret != 0)
  13952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13953. ret = wc_AesGcmEncryptUpdate(enc, large_output, large_input,
  13954. BENCH_AESGCM_LARGE, a, sizeof(a));
  13955. if (ret != 0)
  13956. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13957. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13958. if (ret != 0)
  13959. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13960. #ifdef HAVE_AES_DECRYPT
  13961. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13962. if (ret != 0)
  13963. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13964. ret = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output,
  13965. BENCH_AESGCM_LARGE, a, sizeof(a));
  13966. if (ret != 0)
  13967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13968. ret = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1));
  13969. if (ret != 0)
  13970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13971. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13972. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13973. #endif /* HAVE_AES_DECRYPT */
  13974. #endif /* BENCH_AESGCM_LARGE */
  13975. #endif /* WOLFSSL_AESGCM_STREAM */
  13976. #endif /* WOLFSSL_AES_256 */
  13977. #endif /* !WOLFSSL_AFALG_XILINX_AES && !WOLFSSL_XILINX_CRYPT */
  13978. ret = 0;
  13979. out:
  13980. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  13981. !defined(WOLFSSL_NO_MALLOC)
  13982. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13983. XFREE(large_output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13984. XFREE(large_outdec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13985. #endif
  13986. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13987. wc_AesDelete(enc, &enc);
  13988. wc_AesDelete(dec, &dec);
  13989. #else
  13990. wc_AesFree(enc);
  13991. wc_AesFree(dec);
  13992. #endif
  13993. return ret;
  13994. }
  13995. #ifdef WOLFSSL_AES_128
  13996. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void)
  13997. {
  13998. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13999. Gmac *gmac;
  14000. #else
  14001. Gmac gmac[1];
  14002. #endif
  14003. wc_test_ret_t ret;
  14004. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14005. {
  14006. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  14007. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  14008. };
  14009. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  14010. {
  14011. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  14012. 0xe2, 0x8c, 0x8f, 0x16
  14013. };
  14014. WOLFSSL_SMALL_STACK_STATIC const byte a1[] =
  14015. {
  14016. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  14017. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  14018. };
  14019. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  14020. {
  14021. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  14022. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14023. };
  14024. #if (!defined(HAVE_FIPS) || \
  14025. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
  14026. /* FIPS builds only allow 16-byte auth tags. */
  14027. /* This sample uses a 15-byte auth tag. */
  14028. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14029. {
  14030. 0x40, 0xf7, 0xec, 0xb2, 0x52, 0x6d, 0xaa, 0xd4,
  14031. 0x74, 0x25, 0x1d, 0xf4, 0x88, 0x9e, 0xf6, 0x5b
  14032. };
  14033. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  14034. {
  14035. 0xee, 0x9c, 0x6e, 0x06, 0x15, 0x45, 0x45, 0x03,
  14036. 0x1a, 0x60, 0x24, 0xa7
  14037. };
  14038. WOLFSSL_SMALL_STACK_STATIC const byte a2[] =
  14039. {
  14040. 0x94, 0x81, 0x2c, 0x87, 0x07, 0x4e, 0x15, 0x18,
  14041. 0x34, 0xb8, 0x35, 0xaf, 0x1c, 0xa5, 0x7e, 0x56
  14042. };
  14043. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  14044. {
  14045. 0xc6, 0x81, 0x79, 0x8e, 0x3d, 0xda, 0xb0, 0x9f,
  14046. 0x8d, 0x83, 0xb0, 0xbb, 0x14, 0xb6, 0x91
  14047. };
  14048. #endif
  14049. byte tag[16];
  14050. WOLFSSL_ENTER("gmac_test");
  14051. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14052. if ((gmac = (Gmac *)XMALLOC(sizeof *gmac, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  14053. return WC_TEST_RET_ENC_ERRNO;
  14054. #endif
  14055. XMEMSET(gmac, 0, sizeof *gmac); /* clear context */
  14056. (void)wc_AesInit(&gmac->aes, HEAP_HINT, INVALID_DEVID); /* Make sure devId updated */
  14057. XMEMSET(tag, 0, sizeof(tag));
  14058. wc_GmacSetKey(gmac, k1, sizeof(k1));
  14059. wc_GmacUpdate(gmac, iv1, sizeof(iv1), a1, sizeof(a1), tag, sizeof(t1));
  14060. if (XMEMCMP(t1, tag, sizeof(t1)) != 0)
  14061. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14062. #if (!defined(HAVE_FIPS) || \
  14063. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) )
  14064. XMEMSET(tag, 0, sizeof(tag));
  14065. wc_GmacSetKey(gmac, k2, sizeof(k2));
  14066. wc_GmacUpdate(gmac, iv2, sizeof(iv2), a2, sizeof(a2), tag, sizeof(t2));
  14067. if (XMEMCMP(t2, tag, sizeof(t2)) != 0)
  14068. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14069. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT)
  14070. {
  14071. WOLFSSL_SMALL_STACK_STATIC const byte badT[] =
  14072. {
  14073. 0xde, 0xad, 0xbe, 0xef, 0x17, 0x2e, 0xd0, 0x43,
  14074. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14075. };
  14076. WC_RNG rng;
  14077. byte iv[12];
  14078. #ifndef HAVE_FIPS
  14079. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14080. if (ret != 0)
  14081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14082. #else
  14083. ret = wc_InitRng(&rng);
  14084. if (ret != 0)
  14085. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14086. #endif
  14087. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14088. t1, sizeof(t1));
  14089. if (ret != 0)
  14090. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14091. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14092. badT, sizeof(badT));
  14093. if (ret != WC_NO_ERR_TRACE(AES_GCM_AUTH_E))
  14094. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14095. ret = wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2),
  14096. t2, sizeof(t2));
  14097. if (ret != 0)
  14098. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14099. XMEMSET(tag, 0, sizeof(tag));
  14100. XMEMSET(iv, 0, sizeof(iv));
  14101. ret = wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14102. tag, sizeof(tag), &rng);
  14103. if (ret != 0)
  14104. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14105. ret = wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14106. tag, sizeof(tag));
  14107. if (ret != 0)
  14108. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14109. wc_FreeRng(&rng);
  14110. }
  14111. #endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */
  14112. #endif /* HAVE_FIPS */
  14113. ret = 0;
  14114. out:
  14115. wc_AesFree(&gmac->aes);
  14116. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14117. XFREE(gmac, HEAP_HINT, DYNAMIC_TYPE_AES);
  14118. #endif
  14119. return ret;
  14120. }
  14121. #endif /* WOLFSSL_AES_128 */
  14122. #endif /* HAVE_AESGCM */
  14123. #if defined(HAVE_AESCCM)
  14124. #if defined(WOLFSSL_AES_256)
  14125. static wc_test_ret_t aesccm_256_test(void)
  14126. {
  14127. wc_test_ret_t ret = 0;
  14128. /* Test vectors from NIST AES CCM 256-bit CAST Example #1 */
  14129. WOLFSSL_SMALL_STACK_STATIC const byte in_key[32] = {
  14130. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14131. 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
  14132. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14133. 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
  14134. };
  14135. WOLFSSL_SMALL_STACK_STATIC const byte in_nonce[7] = {
  14136. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
  14137. WOLFSSL_SMALL_STACK_STATIC const byte in_auth[8] = {
  14138. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  14139. WOLFSSL_SMALL_STACK_STATIC const byte in_plaintext[4] = {
  14140. 0x20, 0x21, 0x22, 0x23};
  14141. WOLFSSL_SMALL_STACK_STATIC const byte exp_ciphertext[4] = {
  14142. 0x8A, 0xB1, 0xA8, 0x74};
  14143. WOLFSSL_SMALL_STACK_STATIC const byte exp_tag[4] = {
  14144. 0x95, 0xFC, 0x08, 0x20};
  14145. byte output[sizeof(in_plaintext)];
  14146. byte atag[sizeof(exp_tag)];
  14147. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14148. Aes* aes = wc_AesNew(HEAP_HINT, devId, &ret);
  14149. if (aes == NULL) {
  14150. ret = WC_TEST_RET_ENC_EC(ret);
  14151. }
  14152. #else
  14153. Aes aes[1];
  14154. ret = wc_AesInit(aes, HEAP_HINT, devId);
  14155. #endif
  14156. if (ret == 0) {
  14157. ret = wc_AesCcmSetKey(aes, in_key, sizeof(in_key));
  14158. }
  14159. if (ret == 0) {
  14160. ret = wc_AesCcmEncrypt(aes, output, in_plaintext, sizeof(in_plaintext),
  14161. in_nonce, sizeof(in_nonce),
  14162. atag, sizeof(atag),
  14163. in_auth, sizeof(in_auth));
  14164. }
  14165. /* Verify we produce the proper ciphertext and tag */
  14166. if (ret == 0 &&
  14167. (XMEMCMP(output, exp_ciphertext, sizeof(output)) ||
  14168. XMEMCMP(atag, exp_tag, sizeof(atag)))) {
  14169. ret = WC_TEST_RET_ENC_NC;
  14170. }
  14171. #ifdef HAVE_AES_DECRYPT
  14172. if (ret == 0) {
  14173. /* decrypt inline */
  14174. ret = wc_AesCcmDecrypt(aes, output, output, sizeof(output),
  14175. in_nonce, sizeof(in_nonce),
  14176. atag, sizeof(atag),
  14177. in_auth, sizeof(in_auth));
  14178. }
  14179. /* Verify decryption was successful */
  14180. if (ret == 0 &&
  14181. XMEMCMP(output, in_plaintext, sizeof(output))) {
  14182. ret = WC_TEST_RET_ENC_NC;
  14183. }
  14184. #endif
  14185. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14186. wc_AesDelete(aes, &aes);
  14187. #else
  14188. wc_AesFree(aes);
  14189. #endif
  14190. return ret;
  14191. }
  14192. #endif /* WOLFSSL_AES_256 */
  14193. #if defined(WOLFSSL_AES_128)
  14194. static wc_test_ret_t aesccm_128_test(void)
  14195. {
  14196. wc_test_ret_t ret;
  14197. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14198. Aes *enc = NULL;
  14199. #else
  14200. Aes enc[1];
  14201. #endif
  14202. /* key */
  14203. WOLFSSL_SMALL_STACK_STATIC const byte k[] =
  14204. {
  14205. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  14206. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  14207. };
  14208. /* nonce */
  14209. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  14210. {
  14211. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  14212. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  14213. };
  14214. /* plaintext */
  14215. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  14216. {
  14217. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14218. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14219. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  14220. };
  14221. /* plaintext - long */
  14222. WOLFSSL_SMALL_STACK_STATIC const byte pl[] =
  14223. {
  14224. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14225. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14226. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  14227. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14228. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  14229. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  14230. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  14231. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14232. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  14233. 0x50
  14234. };
  14235. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  14236. {
  14237. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14238. };
  14239. /* ciphertext */
  14240. WOLFSSL_SMALL_STACK_STATIC const byte c[] =
  14241. {
  14242. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14243. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14244. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  14245. };
  14246. /* tag - authentication */
  14247. WOLFSSL_SMALL_STACK_STATIC const byte t[] =
  14248. {
  14249. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  14250. };
  14251. /* ciphertext - long */
  14252. WOLFSSL_SMALL_STACK_STATIC const byte cl[] =
  14253. {
  14254. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14255. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14256. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0xe0,
  14257. 0x44, 0x2d, 0xbe, 0x25, 0xfa, 0x48, 0x2b, 0xa8,
  14258. 0x36, 0x0b, 0xbf, 0x01, 0xc0, 0x12, 0x45, 0xa4,
  14259. 0x82, 0x9f, 0x20, 0x6c, 0xc3, 0xd6, 0xae, 0x5b,
  14260. 0x54, 0x8d, 0xd0, 0xb1, 0x69, 0x2c, 0xec, 0x5e,
  14261. 0x95, 0xa5, 0x6b, 0x48, 0xc3, 0xc6, 0xc8, 0x9e,
  14262. 0xc7, 0x92, 0x98, 0x9d, 0x26, 0x7d, 0x2a, 0x10,
  14263. 0x0b
  14264. };
  14265. /* tag - authentication - long */
  14266. WOLFSSL_SMALL_STACK_STATIC const byte tl[] =
  14267. {
  14268. 0x89, 0xd8, 0xd2, 0x02, 0xc5, 0xcf, 0xae, 0xf4
  14269. };
  14270. /* tag - authentication - empty plaintext */
  14271. WOLFSSL_SMALL_STACK_STATIC const byte t_empty[] =
  14272. {
  14273. 0xe4, 0x28, 0x8a, 0xc3, 0x78, 0x00, 0x0f, 0xf5
  14274. };
  14275. byte t2[sizeof(t)];
  14276. byte p2[sizeof(p)];
  14277. byte c2[sizeof(c)];
  14278. byte iv2[sizeof(iv)];
  14279. byte pl2[sizeof(pl)];
  14280. byte cl2[sizeof(cl)];
  14281. byte tl2[sizeof(tl)];
  14282. byte t_empty2[sizeof(t_empty)];
  14283. XMEMSET(t2, 0, sizeof(t2));
  14284. XMEMSET(c2, 0, sizeof(c2));
  14285. XMEMSET(p2, 0, sizeof(p2));
  14286. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14287. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  14288. if (enc == NULL)
  14289. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14290. #else
  14291. XMEMSET(enc, 0, sizeof(Aes));
  14292. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14293. if (ret != 0)
  14294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14295. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  14296. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14297. if (ret != 0)
  14298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14299. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14300. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14301. t2, sizeof(t2), a, sizeof(a));
  14302. if (ret != 0)
  14303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14304. if (XMEMCMP(c, c2, sizeof(c2)))
  14305. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14306. if (XMEMCMP(t, t2, sizeof(t2)))
  14307. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14308. #ifdef HAVE_AES_DECRYPT
  14309. ret = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv),
  14310. t2, sizeof(t2), a, sizeof(a));
  14311. if (ret != 0)
  14312. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14313. if (XMEMCMP(p, p2, sizeof(p2)))
  14314. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14315. /* Test the authentication failure */
  14316. t2[0]++; /* Corrupt the authentication tag. */
  14317. ret = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv),
  14318. t2, sizeof(t2), a, sizeof(a));
  14319. if (ret == 0)
  14320. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14321. /* Clear c2 to compare against p2. p2 should be set to zero in case of
  14322. * authentication fail. */
  14323. XMEMSET(c2, 0, sizeof(c2));
  14324. if (XMEMCMP(p2, c2, sizeof(p2)))
  14325. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14326. #endif
  14327. XMEMSET(t2, 0, sizeof(t2));
  14328. XMEMSET(c2, 0, sizeof(c2));
  14329. XMEMSET(p2, 0, sizeof(p2));
  14330. XMEMSET(iv2, 0, sizeof(iv2));
  14331. wc_AesFree(enc);
  14332. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14333. if (ret != 0)
  14334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14335. #ifndef HAVE_SELFTEST
  14336. /* selftest build does not have wc_AesCcmSetNonce() or
  14337. * wc_AesCcmEncrypt_ex() */
  14338. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14339. if (ret != 0)
  14340. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14341. ret = wc_AesCcmSetNonce(enc, iv, sizeof(iv));
  14342. if (ret != 0)
  14343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14344. ret = wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2),
  14345. t2, sizeof(t2), a, sizeof(a));
  14346. if (ret != 0)
  14347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14348. if (XMEMCMP(iv, iv2, sizeof(iv2)))
  14349. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14350. if (XMEMCMP(c, c2, sizeof(c2)))
  14351. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14352. if (XMEMCMP(t, t2, sizeof(t2)))
  14353. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14354. #endif
  14355. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  14356. /* test fail on invalid IV sizes */
  14357. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14358. if (ret != 0)
  14359. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14360. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14361. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14362. t2, 1, a, sizeof(a));
  14363. if (ret == 0) {
  14364. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14365. }
  14366. #endif
  14367. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14368. ret = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv),
  14369. tl2, sizeof(tl2), a, sizeof(a));
  14370. if (ret != 0)
  14371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14372. if (XMEMCMP(cl, cl2, sizeof(cl2)))
  14373. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14374. if (XMEMCMP(tl, tl2, sizeof(tl2)))
  14375. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14376. #ifdef HAVE_AES_DECRYPT
  14377. ret = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv),
  14378. tl2, sizeof(tl2), a, sizeof(a));
  14379. if (ret != 0)
  14380. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14381. if (XMEMCMP(pl, pl2, sizeof(pl2)))
  14382. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14383. #endif
  14384. /* test empty message as null input or output with nonzero inSz. */
  14385. ret = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* in */, 1 /* inSz */,
  14386. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14387. a, sizeof(a));
  14388. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14389. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14390. ret = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14391. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14392. a, sizeof(a));
  14393. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14394. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14395. #ifdef HAVE_AES_DECRYPT
  14396. ret = wc_AesCcmDecrypt(enc, pl2, NULL /* in */, 1 /* inSz */,
  14397. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14398. sizeof(a));
  14399. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14400. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14401. ret = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14402. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14403. sizeof(a));
  14404. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14405. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14406. #endif
  14407. /* test empty message as null input and output with zero inSz --
  14408. * must either succeed, or fail early with BAD_FUNC_ARG.
  14409. */
  14410. ret = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */,
  14411. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14412. a, sizeof(a));
  14413. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  14414. if (ret != 0)
  14415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14416. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14417. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14418. #ifdef HAVE_AES_DECRYPT
  14419. ret = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */,
  14420. 0 /* inSz */, iv, sizeof(iv), t_empty2,
  14421. sizeof(t_empty2), a, sizeof(a));
  14422. if (ret != 0)
  14423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14424. #endif
  14425. }
  14426. /* test empty message as zero-length string -- must work. */
  14427. ret = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv,
  14428. sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14429. sizeof(a));
  14430. if (ret != 0)
  14431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14432. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14433. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14434. #ifdef HAVE_AES_DECRYPT
  14435. ret = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */,
  14436. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14437. sizeof(a));
  14438. if (ret != 0)
  14439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14440. #endif
  14441. ret = 0;
  14442. out:
  14443. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14444. wc_AesDelete(enc, &enc);
  14445. #else
  14446. wc_AesFree(enc);
  14447. #endif
  14448. return ret;
  14449. }
  14450. #endif /* WOLFSSL_AES_128 */
  14451. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void)
  14452. {
  14453. wc_test_ret_t ret = 0;
  14454. WOLFSSL_ENTER("aesccm_test");
  14455. #ifdef WOLFSSL_AES_128
  14456. if (ret == 0)
  14457. ret = aesccm_128_test();
  14458. #endif
  14459. #ifdef WOLFSSL_AES_256
  14460. if (ret == 0)
  14461. ret = aesccm_256_test();
  14462. #endif
  14463. return ret;
  14464. }
  14465. #endif /* HAVE_AESCCM */
  14466. #if defined(WOLFSSL_AES_EAX) && \
  14467. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  14468. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void)
  14469. {
  14470. typedef struct {
  14471. byte key[AES_256_KEY_SIZE];
  14472. int key_length;
  14473. byte iv[WC_AES_BLOCK_SIZE];
  14474. int iv_length;
  14475. byte aad[WC_AES_BLOCK_SIZE * 2];
  14476. int aad_length;
  14477. byte msg[WC_AES_BLOCK_SIZE * 2];
  14478. int msg_length;
  14479. byte ct[WC_AES_BLOCK_SIZE * 2];
  14480. int ct_length;
  14481. byte tag[WC_AES_BLOCK_SIZE];
  14482. int tag_length;
  14483. int valid;
  14484. } AadVector;
  14485. /* A small selection of Google wycheproof vectors that use vectors
  14486. * from the original paper: eprint.iacr.org/2003/069
  14487. * https://github.com/google/wycheproof/blob/master/testvectors/aes_eax_test.json
  14488. */
  14489. WOLFSSL_SMALL_STACK_STATIC const AadVector vectors[] = {
  14490. /* Vector from paper - empty message with auth data */
  14491. {
  14492. /* key, key length */
  14493. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  14494. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  14495. /* iv, iv length */
  14496. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  14497. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  14498. /* aad, aad length */
  14499. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  14500. /* msg, msg length */
  14501. {0}, 0,
  14502. /* ct, ct length */
  14503. {0}, 0,
  14504. /* tag, tag length */
  14505. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2,
  14506. 0x7b, 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  14507. /* valid */
  14508. 1,
  14509. },
  14510. /* Vector from paper - no auth data, valid auth tag */
  14511. {
  14512. /* key, key length */
  14513. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14514. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14515. /* iv , iv length */
  14516. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  14517. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  14518. /* aad, aad length */
  14519. {0}, 0,
  14520. /* msg, msg length */
  14521. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14522. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14523. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  14524. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  14525. /* ct, ct length */
  14526. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  14527. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  14528. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  14529. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  14530. /* tag, tag length */
  14531. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  14532. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  14533. /* valid */
  14534. 1,
  14535. },
  14536. /* Vector from paper - no auth data with invalid auth tag */
  14537. {
  14538. /* key, key length */
  14539. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14540. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14541. /* iv, iv length */
  14542. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14543. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  14544. /* aad, aad length */
  14545. {0}, 0,
  14546. /* msg, msg length */
  14547. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14548. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  14549. /* ct , ct length */
  14550. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  14551. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  14552. /* tag, tag length */
  14553. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  14554. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  14555. /* valid */
  14556. 0,
  14557. },
  14558. };
  14559. WOLFSSL_SMALL_STACK_STATIC byte ciphertext[sizeof(vectors[0].ct)];
  14560. WOLFSSL_SMALL_STACK_STATIC byte authtag[sizeof(vectors[0].tag)];
  14561. int i;
  14562. int len;
  14563. wc_test_ret_t ret;
  14564. WOLFSSL_ENTER("aes_eax_test");
  14565. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  14566. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14567. len = sizeof(authtag);
  14568. ret = wc_AesEaxEncryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14569. ciphertext,
  14570. vectors[i].msg, (word32)vectors[i].msg_length,
  14571. vectors[i].iv, (word32)vectors[i].iv_length,
  14572. authtag, (word32)len,
  14573. vectors[i].aad, (word32)vectors[i].aad_length);
  14574. if (ret != 0) {
  14575. return WC_TEST_RET_ENC_EC(ret);
  14576. }
  14577. /* check ciphertext matches vector */
  14578. if (XMEMCMP(ciphertext, vectors[i].ct, (size_t)vectors[i].ct_length)) {
  14579. return WC_TEST_RET_ENC_NC;
  14580. }
  14581. /* check that tag matches vector only for vectors marked as valid */
  14582. ret = XMEMCMP(authtag, vectors[i].tag, len);
  14583. if (vectors[i].valid == 1 && ret != 0 ) {
  14584. return WC_TEST_RET_ENC_NC;
  14585. }
  14586. else if (vectors[i].valid == 0 && ret == 0) {
  14587. return WC_TEST_RET_ENC_NC;
  14588. }
  14589. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14590. ret = wc_AesEaxDecryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14591. ciphertext,
  14592. vectors[i].ct, (word32)vectors[i].ct_length,
  14593. vectors[i].iv, (word32)vectors[i].iv_length,
  14594. authtag, (word32)len,
  14595. vectors[i].aad, (word32)vectors[i].aad_length);
  14596. if (ret != 0) {
  14597. return WC_TEST_RET_ENC_EC(ret);
  14598. }
  14599. /* check decrypted ciphertext matches vector plaintext */
  14600. if (XMEMCMP(ciphertext, vectors[i].msg, (size_t)vectors[i].msg_length)) {
  14601. return WC_TEST_RET_ENC_NC;
  14602. }
  14603. }
  14604. return 0;
  14605. }
  14606. #endif /* WOLFSSL_AES_EAX */
  14607. #ifdef HAVE_AES_KEYWRAP
  14608. #define MAX_KEYWRAP_TEST_OUTLEN 40
  14609. #define MAX_KEYWRAP_TEST_PLAINLEN 32
  14610. typedef struct keywrapVector {
  14611. const byte* kek;
  14612. const byte* data;
  14613. const byte* verify;
  14614. word32 kekLen;
  14615. word32 dataLen;
  14616. word32 verifyLen;
  14617. } keywrapVector;
  14618. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void)
  14619. {
  14620. int wrapSz, plainSz, testSz, i;
  14621. /* test vectors from RFC 3394 (kek, data, verify) */
  14622. #ifdef WOLFSSL_AES_128
  14623. /* Wrap 128 bits of Key Data with a 128-bit KEK */
  14624. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14625. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14626. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14627. };
  14628. WOLFSSL_SMALL_STACK_STATIC const byte d1[] = {
  14629. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14630. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14631. };
  14632. WOLFSSL_SMALL_STACK_STATIC const byte v1[] = {
  14633. 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
  14634. 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
  14635. 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
  14636. };
  14637. #endif /* WOLFSSL_AES_128 */
  14638. #ifdef WOLFSSL_AES_192
  14639. /* Wrap 128 bits of Key Data with a 192-bit KEK */
  14640. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  14641. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14642. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14643. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14644. };
  14645. WOLFSSL_SMALL_STACK_STATIC const byte d2[] = {
  14646. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14647. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14648. };
  14649. WOLFSSL_SMALL_STACK_STATIC const byte v2[] = {
  14650. 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35,
  14651. 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2,
  14652. 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D
  14653. };
  14654. #endif
  14655. #ifdef WOLFSSL_AES_256
  14656. /* Wrap 128 bits of Key Data with a 256-bit KEK */
  14657. WOLFSSL_SMALL_STACK_STATIC const byte k3[] = {
  14658. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14659. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14660. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14661. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14662. };
  14663. WOLFSSL_SMALL_STACK_STATIC const byte d3[] = {
  14664. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14665. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14666. };
  14667. WOLFSSL_SMALL_STACK_STATIC const byte v3[] = {
  14668. 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2,
  14669. 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A,
  14670. 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7
  14671. };
  14672. #endif
  14673. #ifdef WOLFSSL_AES_192
  14674. /* Wrap 192 bits of Key Data with a 192-bit KEK */
  14675. WOLFSSL_SMALL_STACK_STATIC const byte k4[] = {
  14676. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14677. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14678. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14679. };
  14680. WOLFSSL_SMALL_STACK_STATIC const byte d4[] = {
  14681. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14682. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14683. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14684. };
  14685. WOLFSSL_SMALL_STACK_STATIC const byte v4[] = {
  14686. 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32,
  14687. 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC,
  14688. 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93,
  14689. 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2
  14690. };
  14691. #endif
  14692. #ifdef WOLFSSL_AES_256
  14693. /* Wrap 192 bits of Key Data with a 256-bit KEK */
  14694. WOLFSSL_SMALL_STACK_STATIC const byte k5[] = {
  14695. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14696. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14697. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14698. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14699. };
  14700. WOLFSSL_SMALL_STACK_STATIC const byte d5[] = {
  14701. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14702. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14703. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14704. };
  14705. WOLFSSL_SMALL_STACK_STATIC const byte v5[] = {
  14706. 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F,
  14707. 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4,
  14708. 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95,
  14709. 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1
  14710. };
  14711. /* Wrap 256 bits of Key Data with a 256-bit KEK */
  14712. WOLFSSL_SMALL_STACK_STATIC const byte k6[] = {
  14713. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14714. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14715. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14716. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14717. };
  14718. WOLFSSL_SMALL_STACK_STATIC const byte d6[] = {
  14719. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14720. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14721. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14722. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14723. };
  14724. WOLFSSL_SMALL_STACK_STATIC const byte v6[] = {
  14725. 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4,
  14726. 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26,
  14727. 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26,
  14728. 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B,
  14729. 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21
  14730. };
  14731. #endif /* WOLFSSL_AES_256 */
  14732. byte output[MAX_KEYWRAP_TEST_OUTLEN];
  14733. byte plain [MAX_KEYWRAP_TEST_PLAINLEN];
  14734. const keywrapVector test_wrap[] =
  14735. {
  14736. #ifdef WOLFSSL_AES_128
  14737. {k1, d1, v1, sizeof(k1), sizeof(d1), sizeof(v1)},
  14738. #endif
  14739. #ifdef WOLFSSL_AES_192
  14740. {k2, d2, v2, sizeof(k2), sizeof(d2), sizeof(v2)},
  14741. #endif
  14742. #ifdef WOLFSSL_AES_256
  14743. {k3, d3, v3, sizeof(k3), sizeof(d3), sizeof(v3)},
  14744. #endif
  14745. #ifdef WOLFSSL_AES_192
  14746. {k4, d4, v4, sizeof(k4), sizeof(d4), sizeof(v4)},
  14747. #endif
  14748. #ifdef WOLFSSL_AES_256
  14749. {k5, d5, v5, sizeof(k5), sizeof(d5), sizeof(v5)},
  14750. {k6, d6, v6, sizeof(k6), sizeof(d6), sizeof(v6)}
  14751. #endif
  14752. };
  14753. WOLFSSL_ENTER("aeskeywrap_test");
  14754. testSz = sizeof(test_wrap) / sizeof(keywrapVector);
  14755. XMEMSET(output, 0, sizeof(output));
  14756. XMEMSET(plain, 0, sizeof(plain));
  14757. for (i = 0; i < testSz; i++) {
  14758. wrapSz = wc_AesKeyWrap(test_wrap[i].kek, test_wrap[i].kekLen,
  14759. test_wrap[i].data, test_wrap[i].dataLen,
  14760. output, sizeof(output), NULL);
  14761. if ( (wrapSz < 0) || (wrapSz != (int)test_wrap[i].verifyLen) )
  14762. return WC_TEST_RET_ENC_NC;
  14763. if (XMEMCMP(output, test_wrap[i].verify, test_wrap[i].verifyLen) != 0)
  14764. return WC_TEST_RET_ENC_NC;
  14765. plainSz = wc_AesKeyUnWrap((byte*)test_wrap[i].kek, test_wrap[i].kekLen,
  14766. output, (word32)wrapSz,
  14767. plain, sizeof(plain), NULL);
  14768. if ( (plainSz < 0) || (plainSz != (int)test_wrap[i].dataLen) )
  14769. return WC_TEST_RET_ENC_NC;
  14770. if (XMEMCMP(plain, test_wrap[i].data, test_wrap[i].dataLen) != 0)
  14771. return WC_TEST_RET_ENC_I(i);
  14772. }
  14773. return 0;
  14774. }
  14775. #endif /* HAVE_AES_KEYWRAP */
  14776. #endif /* !NO_AES */
  14777. #ifdef HAVE_ARIA
  14778. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz)
  14779. {
  14780. #ifndef DEBUG_WOLFSSL
  14781. (void)strName;
  14782. (void)data;
  14783. (void)dataSz;
  14784. #else
  14785. WOLFSSL_MSG_EX("%s (%d):", strName,dataSz);
  14786. WOLFSSL_BUFFER(data,dataSz);
  14787. #endif
  14788. }
  14789. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID algo)
  14790. {
  14791. byte data[] = TEST_STRING;
  14792. word32 dataSz = TEST_STRING_SZ;
  14793. /* Arbitrarily random long key that we will truncate to the right size */
  14794. byte key[] = { 0x1E, 0xCC, 0x95, 0xCB, 0xD3, 0x74, 0x58, 0x4F,
  14795. 0x6F, 0x8A, 0x70, 0x26, 0xF7, 0x3C, 0x8D, 0xB6,
  14796. 0xDC, 0x32, 0x76, 0x20, 0xCF, 0x05, 0x4A, 0xCF,
  14797. 0x11, 0x86, 0xCD, 0x23, 0x5E, 0xC1, 0x6E, 0x2B };
  14798. byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[WC_AES_BLOCK_SIZE];
  14799. word32 keySz, adSz = 256, authTagSz = sizeof(authTag);
  14800. wc_Aria aria;
  14801. int ret = 0;
  14802. WOLFSSL_ENTER("ariagcm_test");
  14803. XMEMSET((void *)&aria, 0, sizeof(aria));
  14804. ret = wc_AriaInitCrypt(&aria, algo);
  14805. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14806. ret = wc_AriaSetKey(&aria, key);
  14807. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14808. MC_GetObjectValue(aria.hSession, aria.hKey, key, &keySz);
  14809. printOutput("Key", key, keySz);
  14810. WC_RNG rng;
  14811. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14812. if (ret != 0)
  14813. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14814. ret = wc_AriaGcmSetIV(&aria, GCM_NONCE_MID_SZ, NULL, 0, &rng);
  14815. if (ret != 0)
  14816. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14817. wc_FreeRng(&rng);
  14818. printOutput("Plaintext", data, sizeof(data));
  14819. XMEMSET(cipher, 0, sizeof(cipher));
  14820. ret = wc_AriaEncrypt(&aria, cipher, data, dataSz,
  14821. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14822. authTag, authTagSz);
  14823. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14824. printOutput("Ciphertext", cipher, sizeof(cipher));
  14825. printOutput("AuthTag", authTag, sizeof(authTag));
  14826. XMEMSET(plain, 0, sizeof(plain));
  14827. ret = wc_AriaDecrypt(&aria, plain, cipher, dataSz,
  14828. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14829. authTag, authTagSz);
  14830. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14831. printOutput("Plaintext", plain, sizeof(plain));
  14832. if (XMEMCMP(plain, data, dataSz) != 0)
  14833. ERROR_OUT(WC_TEST_RET_ENC_NC,out);
  14834. out:
  14835. if (ret != 0) { wc_AriaFreeCrypt(&aria); }
  14836. else { ret = wc_AriaFreeCrypt(&aria); }
  14837. return ret;
  14838. }
  14839. #endif /* HAVE_ARIA */
  14840. #ifdef HAVE_CAMELLIA
  14841. enum {
  14842. CAM_ECB_ENC, CAM_ECB_DEC, CAM_CBC_ENC, CAM_CBC_DEC
  14843. };
  14844. typedef struct {
  14845. int type;
  14846. const byte* plaintext;
  14847. const byte* iv;
  14848. const byte* ciphertext;
  14849. const byte* key;
  14850. word32 keySz;
  14851. int errorCode;
  14852. } test_vector_t;
  14853. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void)
  14854. {
  14855. /* Camellia ECB Test Plaintext */
  14856. WOLFSSL_SMALL_STACK_STATIC const byte pte[] =
  14857. {
  14858. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14859. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14860. };
  14861. /* Camellia ECB Test Initialization Vector */
  14862. WOLFSSL_SMALL_STACK_STATIC const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  14863. /* Test 1: Camellia ECB 128-bit key */
  14864. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14865. {
  14866. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14867. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14868. };
  14869. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  14870. {
  14871. 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
  14872. 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
  14873. };
  14874. /* Test 2: Camellia ECB 192-bit key */
  14875. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14876. {
  14877. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14878. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14879. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  14880. };
  14881. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  14882. {
  14883. 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
  14884. 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9
  14885. };
  14886. /* Test 3: Camellia ECB 256-bit key */
  14887. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  14888. {
  14889. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14890. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14891. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14892. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  14893. };
  14894. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  14895. {
  14896. 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
  14897. 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09
  14898. };
  14899. /* Camellia CBC Test Plaintext */
  14900. WOLFSSL_SMALL_STACK_STATIC const byte ptc[] =
  14901. {
  14902. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  14903. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  14904. };
  14905. /* Camellia CBC Test Initialization Vector */
  14906. WOLFSSL_SMALL_STACK_STATIC const byte ivc[] =
  14907. {
  14908. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14909. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14910. };
  14911. /* Test 4: Camellia-CBC 128-bit key */
  14912. WOLFSSL_SMALL_STACK_STATIC const byte k4[] =
  14913. {
  14914. 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
  14915. 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
  14916. };
  14917. WOLFSSL_SMALL_STACK_STATIC const byte c4[] =
  14918. {
  14919. 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
  14920. 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB
  14921. };
  14922. /* Test 5: Camellia-CBC 192-bit key */
  14923. WOLFSSL_SMALL_STACK_STATIC const byte k5[] =
  14924. {
  14925. 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
  14926. 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
  14927. 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B
  14928. };
  14929. WOLFSSL_SMALL_STACK_STATIC const byte c5[] =
  14930. {
  14931. 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
  14932. 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93
  14933. };
  14934. /* Test 6: CBC 256-bit key */
  14935. WOLFSSL_SMALL_STACK_STATIC const byte k6[] =
  14936. {
  14937. 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
  14938. 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
  14939. 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
  14940. 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4
  14941. };
  14942. WOLFSSL_SMALL_STACK_STATIC const byte c6[] =
  14943. {
  14944. 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
  14945. 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
  14946. };
  14947. byte out[WC_CAMELLIA_BLOCK_SIZE];
  14948. wc_Camellia cam;
  14949. WOLFSSL_SMALL_STACK_STATIC const test_vector_t testVectors[] =
  14950. {
  14951. {CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114},
  14952. {CAM_ECB_ENC, pte, ive, c2, k2, sizeof(k2), -115},
  14953. {CAM_ECB_ENC, pte, ive, c3, k3, sizeof(k3), -116},
  14954. {CAM_ECB_DEC, pte, ive, c1, k1, sizeof(k1), -117},
  14955. {CAM_ECB_DEC, pte, ive, c2, k2, sizeof(k2), -118},
  14956. {CAM_ECB_DEC, pte, ive, c3, k3, sizeof(k3), -119},
  14957. {CAM_CBC_ENC, ptc, ivc, c4, k4, sizeof(k4), -120},
  14958. {CAM_CBC_ENC, ptc, ivc, c5, k5, sizeof(k5), -121},
  14959. {CAM_CBC_ENC, ptc, ivc, c6, k6, sizeof(k6), -122},
  14960. {CAM_CBC_DEC, ptc, ivc, c4, k4, sizeof(k4), -123},
  14961. {CAM_CBC_DEC, ptc, ivc, c5, k5, sizeof(k5), -124},
  14962. {CAM_CBC_DEC, ptc, ivc, c6, k6, sizeof(k6), -125}
  14963. };
  14964. int i, testsSz;
  14965. int ret;
  14966. WOLFSSL_ENTER("camellia_test");
  14967. testsSz = sizeof(testVectors)/sizeof(test_vector_t);
  14968. for (i = 0; i < testsSz; i++) {
  14969. if (wc_CamelliaSetKey(&cam, testVectors[i].key, testVectors[i].keySz,
  14970. testVectors[i].iv) != 0)
  14971. return testVectors[i].errorCode;
  14972. switch (testVectors[i].type) {
  14973. case CAM_ECB_ENC:
  14974. ret = wc_CamelliaEncryptDirect(&cam, out,
  14975. testVectors[i].plaintext);
  14976. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14977. WC_CAMELLIA_BLOCK_SIZE))
  14978. return testVectors[i].errorCode;
  14979. break;
  14980. case CAM_ECB_DEC:
  14981. ret = wc_CamelliaDecryptDirect(&cam, out,
  14982. testVectors[i].ciphertext);
  14983. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14984. WC_CAMELLIA_BLOCK_SIZE))
  14985. return testVectors[i].errorCode;
  14986. break;
  14987. case CAM_CBC_ENC:
  14988. ret = wc_CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext,
  14989. WC_CAMELLIA_BLOCK_SIZE);
  14990. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14991. WC_CAMELLIA_BLOCK_SIZE))
  14992. return testVectors[i].errorCode;
  14993. break;
  14994. case CAM_CBC_DEC:
  14995. ret = wc_CamelliaCbcDecrypt(&cam, out,
  14996. testVectors[i].ciphertext, WC_CAMELLIA_BLOCK_SIZE);
  14997. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14998. WC_CAMELLIA_BLOCK_SIZE))
  14999. return testVectors[i].errorCode;
  15000. break;
  15001. default:
  15002. break;
  15003. }
  15004. }
  15005. /* Setting the IV and checking it was actually set. */
  15006. ret = wc_CamelliaSetIV(&cam, ivc);
  15007. if (ret != 0)
  15008. return WC_TEST_RET_ENC_EC(ret);
  15009. if (XMEMCMP(cam.reg, ivc, WC_CAMELLIA_BLOCK_SIZE) != 0)
  15010. return WC_TEST_RET_ENC_NC;
  15011. /* Setting the IV to NULL should be same as all zeros IV */
  15012. ret = wc_CamelliaSetIV(&cam, NULL);
  15013. if (ret != 0)
  15014. return WC_TEST_RET_ENC_EC(ret);
  15015. if (XMEMCMP(cam.reg, ive, WC_CAMELLIA_BLOCK_SIZE) != 0)
  15016. return WC_TEST_RET_ENC_NC;
  15017. /* First parameter should never be null */
  15018. if (wc_CamelliaSetIV(NULL, NULL) == 0)
  15019. return WC_TEST_RET_ENC_NC;
  15020. /* First parameter should never be null, check it fails */
  15021. if (wc_CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0)
  15022. return WC_TEST_RET_ENC_NC;
  15023. /* Key should have a size of 16, 24, or 32 */
  15024. if (wc_CamelliaSetKey(&cam, k1, 0, NULL) == 0)
  15025. return WC_TEST_RET_ENC_NC;
  15026. return 0;
  15027. }
  15028. #endif /* HAVE_CAMELLIA */
  15029. #ifdef WOLFSSL_SM4
  15030. #ifdef WOLFSSL_SM4_ECB
  15031. static int sm4_ecb_test(void)
  15032. {
  15033. /* draft-ribose-cfrg-sm4-10 A.2.1.1 */
  15034. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15035. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15036. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15037. };
  15038. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15039. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15040. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15041. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15042. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15043. };
  15044. WOLFSSL_SMALL_STACK_STATIC const byte c1_ecb[] = {
  15045. 0x5E, 0xC8, 0x14, 0x3D, 0xE5, 0x09, 0xCF, 0xF7,
  15046. 0xB5, 0x17, 0x9F, 0x8F, 0x47, 0x4B, 0x86, 0x19,
  15047. 0x2F, 0x1D, 0x30, 0x5A, 0x7F, 0xB1, 0x7D, 0xF9,
  15048. 0x85, 0xF8, 0x1C, 0x84, 0x82, 0x19, 0x23, 0x04
  15049. };
  15050. wc_Sm4 sm4;
  15051. byte enc[SM4_BLOCK_SIZE * 4];
  15052. byte dec[SM4_BLOCK_SIZE * 4];
  15053. int ret;
  15054. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15055. if (ret != 0)
  15056. return WC_TEST_RET_ENC_EC(ret);
  15057. /* Encrypt and decrypt with ECB. */
  15058. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15059. if (ret != 0)
  15060. return WC_TEST_RET_ENC_EC(ret);
  15061. ret = wc_Sm4EcbEncrypt(&sm4, enc, p1, sizeof(p1));
  15062. if (ret != 0)
  15063. return WC_TEST_RET_ENC_EC(ret);
  15064. if (XMEMCMP(enc, c1_ecb, sizeof(c1_ecb)) != 0)
  15065. return WC_TEST_RET_ENC_NC;
  15066. ret = wc_Sm4EcbDecrypt(&sm4, dec, enc, sizeof(c1_ecb));
  15067. if (ret != 0)
  15068. return WC_TEST_RET_ENC_EC(ret);
  15069. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15070. return WC_TEST_RET_ENC_NC;
  15071. wc_Sm4Free(&sm4);
  15072. return 0;
  15073. }
  15074. #endif
  15075. #ifdef WOLFSSL_SM4_CBC
  15076. static int sm4_cbc_test(void)
  15077. {
  15078. /* draft-ribose-cfrg-sm4-10 A.2.2.1 */
  15079. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15080. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15081. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15082. };
  15083. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15084. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15085. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15086. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15087. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15088. };
  15089. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15090. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15091. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15092. };
  15093. WOLFSSL_SMALL_STACK_STATIC const byte c1_cbc[] = {
  15094. 0x78, 0xEB, 0xB1, 0x1C, 0xC4, 0x0B, 0x0A, 0x48,
  15095. 0x31, 0x2A, 0xAE, 0xB2, 0x04, 0x02, 0x44, 0xCB,
  15096. 0x4C, 0xB7, 0x01, 0x69, 0x51, 0x90, 0x92, 0x26,
  15097. 0x97, 0x9B, 0x0D, 0x15, 0xDC, 0x6A, 0x8F, 0x6D
  15098. };
  15099. wc_Sm4 sm4;
  15100. byte enc[SM4_BLOCK_SIZE * 4];
  15101. byte dec[SM4_BLOCK_SIZE * 4];
  15102. int ret;
  15103. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15104. if (ret != 0)
  15105. return WC_TEST_RET_ENC_EC(ret);
  15106. /* Encrypt and decrypt with CBC. */
  15107. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15108. if (ret != 0)
  15109. return WC_TEST_RET_ENC_EC(ret);
  15110. ret = wc_Sm4SetIV(&sm4, i1);
  15111. if (ret != 0)
  15112. return WC_TEST_RET_ENC_EC(ret);
  15113. ret = wc_Sm4CbcEncrypt(&sm4, enc, p1, sizeof(p1));
  15114. if (ret != 0)
  15115. return WC_TEST_RET_ENC_EC(ret);
  15116. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15117. return WC_TEST_RET_ENC_NC;
  15118. ret = wc_Sm4SetIV(&sm4, i1);
  15119. if (ret != 0)
  15120. return WC_TEST_RET_ENC_EC(ret);
  15121. ret = wc_Sm4CbcDecrypt(&sm4, dec, enc, sizeof(c1_cbc));
  15122. if (ret != 0)
  15123. return WC_TEST_RET_ENC_EC(ret);
  15124. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15125. return WC_TEST_RET_ENC_NC;
  15126. /* Encrypt and decrypt in-place with CBC. */
  15127. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15128. if (ret != 0)
  15129. return WC_TEST_RET_ENC_EC(ret);
  15130. ret = wc_Sm4SetIV(&sm4, i1);
  15131. if (ret != 0)
  15132. return WC_TEST_RET_ENC_EC(ret);
  15133. XMEMCPY(enc, p1, sizeof(p1));
  15134. ret = wc_Sm4CbcEncrypt(&sm4, enc, enc, sizeof(p1));
  15135. if (ret != 0)
  15136. return WC_TEST_RET_ENC_EC(ret);
  15137. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15138. return WC_TEST_RET_ENC_NC;
  15139. ret = wc_Sm4SetIV(&sm4, i1);
  15140. if (ret != 0)
  15141. return WC_TEST_RET_ENC_EC(ret);
  15142. ret = wc_Sm4CbcDecrypt(&sm4, enc, enc, sizeof(c1_cbc));
  15143. if (ret != 0)
  15144. return WC_TEST_RET_ENC_EC(ret);
  15145. if (XMEMCMP(enc, p1, sizeof(p1)) != 0)
  15146. return WC_TEST_RET_ENC_NC;
  15147. wc_Sm4Free(&sm4);
  15148. return 0;
  15149. }
  15150. #endif
  15151. #ifdef WOLFSSL_SM4_CTR
  15152. static int sm4_ctr_test(void)
  15153. {
  15154. /* draft-ribose-cfrg-sm4-10 A.2.5.1 */
  15155. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15156. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15157. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15158. };
  15159. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15160. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15161. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15162. };
  15163. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15164. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15165. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15166. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15167. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15168. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15169. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15170. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15171. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB
  15172. };
  15173. WOLFSSL_SMALL_STACK_STATIC const byte c2_ctr[] = {
  15174. 0xAC, 0x32, 0x36, 0xCB, 0x97, 0x0C, 0xC2, 0x07,
  15175. 0x91, 0x36, 0x4C, 0x39, 0x5A, 0x13, 0x42, 0xD1,
  15176. 0xA3, 0xCB, 0xC1, 0x87, 0x8C, 0x6F, 0x30, 0xCD,
  15177. 0x07, 0x4C, 0xCE, 0x38, 0x5C, 0xDD, 0x70, 0xC7,
  15178. 0xF2, 0x34, 0xBC, 0x0E, 0x24, 0xC1, 0x19, 0x80,
  15179. 0xFD, 0x12, 0x86, 0x31, 0x0C, 0xE3, 0x7B, 0x92,
  15180. 0x6E, 0x02, 0xFC, 0xD0, 0xFA, 0xA0, 0xBA, 0xF3,
  15181. 0x8B, 0x29, 0x33, 0x85, 0x1D, 0x82, 0x45, 0x14
  15182. };
  15183. wc_Sm4 sm4;
  15184. byte enc[SM4_BLOCK_SIZE * 4];
  15185. byte dec[SM4_BLOCK_SIZE * 4];
  15186. int chunk;
  15187. int i;
  15188. int ret;
  15189. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15190. if (ret != 0)
  15191. return WC_TEST_RET_ENC_EC(ret);
  15192. /* Encrypt and decrypt using encrypt with CTR. */
  15193. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15194. if (ret != 0)
  15195. return WC_TEST_RET_ENC_EC(ret);
  15196. ret = wc_Sm4SetIV(&sm4, i1);
  15197. if (ret != 0)
  15198. return WC_TEST_RET_ENC_EC(ret);
  15199. ret = wc_Sm4CtrEncrypt(&sm4, enc, p2, sizeof(p2));
  15200. if (ret != 0)
  15201. return WC_TEST_RET_ENC_EC(ret);
  15202. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15203. return WC_TEST_RET_ENC_NC;
  15204. ret = wc_Sm4SetIV(&sm4, i1);
  15205. if (ret != 0)
  15206. return WC_TEST_RET_ENC_EC(ret);
  15207. ret = wc_Sm4CtrEncrypt(&sm4, dec, enc, sizeof(c2_ctr));
  15208. if (ret != 0)
  15209. return WC_TEST_RET_ENC_EC(ret);
  15210. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15211. return WC_TEST_RET_ENC_NC;
  15212. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15213. ret = wc_Sm4SetIV(&sm4, i1);
  15214. if (ret != 0)
  15215. return WC_TEST_RET_ENC_I(chunk);
  15216. XMEMSET(enc, 0, sizeof(enc));
  15217. for (i = 0; i + chunk <= (int)sizeof(p2); i += chunk) {
  15218. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, chunk);
  15219. if (ret != 0)
  15220. return WC_TEST_RET_ENC_I(i);
  15221. }
  15222. if (i < (int)sizeof(p2)) {
  15223. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, sizeof(p2) - i);
  15224. if (ret != 0)
  15225. return WC_TEST_RET_ENC_I(chunk);
  15226. }
  15227. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15228. return WC_TEST_RET_ENC_I(chunk);
  15229. }
  15230. wc_Sm4Free(&sm4);
  15231. return 0;
  15232. }
  15233. #endif
  15234. #ifdef WOLFSSL_SM4_GCM
  15235. static int sm4_gcm_test(void)
  15236. {
  15237. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15238. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15239. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15240. };
  15241. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15242. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15243. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15244. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15245. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15246. };
  15247. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15248. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15249. 0x08, 0x09, 0x0A, 0x0B
  15250. };
  15251. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15252. 0xFF, 0xEE, 0xDD
  15253. };
  15254. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15255. 0x83, 0xb2, 0x91, 0xcf, 0x22, 0xc9, 0x5f, 0x89,
  15256. 0xde, 0x3d, 0x52, 0x8d, 0xd7, 0x13, 0x50, 0x89
  15257. };
  15258. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15259. 0xff, 0x8b, 0xb2, 0x3b, 0x0a, 0x0a, 0x12, 0xa4,
  15260. 0xa8, 0x4c, 0x4f, 0x67, 0x06, 0x81, 0xbb, 0x88,
  15261. 0x66, 0x17, 0xc7, 0x43, 0xbf, 0xae, 0x41, 0x40,
  15262. 0xec, 0x1e, 0x03, 0x85, 0x2b, 0x56, 0xa8, 0xc0
  15263. };
  15264. /* RFC8998 A.1. */
  15265. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15266. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15267. 0x00, 0x00, 0xAB, 0xCD
  15268. };
  15269. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15270. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15271. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15272. };
  15273. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15274. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15275. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15276. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15277. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15278. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15279. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15280. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15281. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15282. };
  15283. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15284. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15285. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15286. 0xAB, 0xAD, 0xDA, 0xD2
  15287. };
  15288. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15289. 0x17, 0xF3, 0x99, 0xF0, 0x8C, 0x67, 0xD5, 0xEE,
  15290. 0x19, 0xD0, 0xDC, 0x99, 0x69, 0xC4, 0xBB, 0x7D,
  15291. 0x5F, 0xD4, 0x6F, 0xD3, 0x75, 0x64, 0x89, 0x06,
  15292. 0x91, 0x57, 0xB2, 0x82, 0xBB, 0x20, 0x07, 0x35,
  15293. 0xD8, 0x27, 0x10, 0xCA, 0x5C, 0x22, 0xF0, 0xCC,
  15294. 0xFA, 0x7C, 0xBF, 0x93, 0xD4, 0x96, 0xAC, 0x15,
  15295. 0xA5, 0x68, 0x34, 0xCB, 0xCF, 0x98, 0xC3, 0x97,
  15296. 0xB4, 0x02, 0x4A, 0x26, 0x91, 0x23, 0x3B, 0x8D
  15297. };
  15298. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15299. 0x83, 0xDE, 0x35, 0x41, 0xE4, 0xC2, 0xB5, 0x81,
  15300. 0x77, 0xE0, 0x65, 0xA9, 0xBF, 0x7B, 0x62, 0xEC
  15301. };
  15302. wc_Sm4 sm4;
  15303. byte enc[SM4_BLOCK_SIZE * 4];
  15304. byte dec[SM4_BLOCK_SIZE * 4];
  15305. byte tag[SM4_BLOCK_SIZE];
  15306. int ret;
  15307. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15308. if (ret != 0)
  15309. return WC_TEST_RET_ENC_EC(ret);
  15310. /* Encrypt and decrypt using encrypt with GCM. */
  15311. ret = wc_Sm4GcmSetKey(&sm4, k1, sizeof(k1));
  15312. if (ret != 0)
  15313. return WC_TEST_RET_ENC_EC(ret);
  15314. ret = wc_Sm4GcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15315. sizeof(tag), a1, sizeof(a1));
  15316. if (ret != 0)
  15317. return WC_TEST_RET_ENC_EC(ret);
  15318. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15319. return WC_TEST_RET_ENC_NC;
  15320. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15321. return WC_TEST_RET_ENC_NC;
  15322. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15323. sizeof(tag), a1, sizeof(a1));
  15324. if (ret != 0)
  15325. return WC_TEST_RET_ENC_EC(ret);
  15326. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15327. return WC_TEST_RET_ENC_NC;
  15328. /* RFC8998 test vector. */
  15329. ret = wc_Sm4GcmSetKey(&sm4, k2, sizeof(k2));
  15330. if (ret != 0)
  15331. return WC_TEST_RET_ENC_EC(ret);
  15332. ret = wc_Sm4GcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15333. sizeof(tag), a2, sizeof(a2));
  15334. if (ret != 0)
  15335. return WC_TEST_RET_ENC_EC(ret);
  15336. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15337. return WC_TEST_RET_ENC_NC;
  15338. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15339. return WC_TEST_RET_ENC_NC;
  15340. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15341. sizeof(tag), a2, sizeof(a2));
  15342. if (ret != 0)
  15343. return WC_TEST_RET_ENC_EC(ret);
  15344. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15345. return WC_TEST_RET_ENC_NC;
  15346. wc_Sm4Free(&sm4);
  15347. return 0;
  15348. }
  15349. #endif
  15350. #ifdef WOLFSSL_SM4_CCM
  15351. static int sm4_ccm_test(void)
  15352. {
  15353. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15354. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15355. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15356. };
  15357. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15358. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15359. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15360. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15361. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15362. };
  15363. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15364. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15365. 0x08, 0x09, 0x0A, 0x0B
  15366. };
  15367. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15368. 0xFF, 0xEE, 0xDD
  15369. };
  15370. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15371. 0x9a, 0x98, 0x04, 0xb6, 0x0f, 0x19, 0x4a, 0x46,
  15372. 0xba, 0xed, 0xe6, 0x89, 0x69, 0x34, 0xad, 0x61
  15373. };
  15374. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15375. 0xbd, 0xc0, 0x72, 0x60, 0xda, 0x2d, 0x11, 0xdc,
  15376. 0x66, 0x33, 0xcc, 0xec, 0xb2, 0xf4, 0x53, 0x59,
  15377. 0x9e, 0xb1, 0xb3, 0x6b, 0x1f, 0x1c, 0xfb, 0x29,
  15378. 0xf5, 0x37, 0xfc, 0x00, 0xf2, 0x4e, 0x70, 0x6f
  15379. };
  15380. /* RFC8998 A.1. */
  15381. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15382. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15383. 0x00, 0x00, 0xAB, 0xCD
  15384. };
  15385. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15386. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15387. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15388. };
  15389. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15390. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15391. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15392. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15393. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15394. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15395. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15396. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15397. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15398. };
  15399. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15400. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15401. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15402. 0xAB, 0xAD, 0xDA, 0xD2
  15403. };
  15404. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15405. 0x48, 0xAF, 0x93, 0x50, 0x1F, 0xA6, 0x2A, 0xDB,
  15406. 0xCD, 0x41, 0x4C, 0xCE, 0x60, 0x34, 0xD8, 0x95,
  15407. 0xDD, 0xA1, 0xBF, 0x8F, 0x13, 0x2F, 0x04, 0x20,
  15408. 0x98, 0x66, 0x15, 0x72, 0xE7, 0x48, 0x30, 0x94,
  15409. 0xFD, 0x12, 0xE5, 0x18, 0xCE, 0x06, 0x2C, 0x98,
  15410. 0xAC, 0xEE, 0x28, 0xD9, 0x5D, 0xF4, 0x41, 0x6B,
  15411. 0xED, 0x31, 0xA2, 0xF0, 0x44, 0x76, 0xC1, 0x8B,
  15412. 0xB4, 0x0C, 0x84, 0xA7, 0x4B, 0x97, 0xDC, 0x5B
  15413. };
  15414. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15415. 0x16, 0x84, 0x2D, 0x4F, 0xA1, 0x86, 0xF5, 0x6A,
  15416. 0xB3, 0x32, 0x56, 0x97, 0x1F, 0xA1, 0x10, 0xF4
  15417. };
  15418. wc_Sm4 sm4;
  15419. byte enc[SM4_BLOCK_SIZE * 4];
  15420. byte dec[SM4_BLOCK_SIZE * 4];
  15421. byte tag[SM4_BLOCK_SIZE];
  15422. int ret;
  15423. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15424. if (ret != 0)
  15425. return WC_TEST_RET_ENC_EC(ret);
  15426. /* Encrypt and decrypt using encrypt with CCM. */
  15427. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15428. if (ret != 0)
  15429. return WC_TEST_RET_ENC_EC(ret);
  15430. ret = wc_Sm4CcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15431. sizeof(tag), a1, sizeof(a1));
  15432. if (ret != 0)
  15433. return WC_TEST_RET_ENC_EC(ret);
  15434. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15435. return WC_TEST_RET_ENC_NC;
  15436. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15437. return WC_TEST_RET_ENC_NC;
  15438. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15439. sizeof(tag), a1, sizeof(a1));
  15440. if (ret != 0)
  15441. return WC_TEST_RET_ENC_EC(ret);
  15442. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15443. return WC_TEST_RET_ENC_NC;
  15444. /* RFC8998 test vector. */
  15445. ret = wc_Sm4SetKey(&sm4, k2, sizeof(k2));
  15446. if (ret != 0)
  15447. return WC_TEST_RET_ENC_EC(ret);
  15448. ret = wc_Sm4CcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15449. sizeof(tag), a2, sizeof(a2));
  15450. if (ret != 0)
  15451. return WC_TEST_RET_ENC_EC(ret);
  15452. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15453. return WC_TEST_RET_ENC_NC;
  15454. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15455. return WC_TEST_RET_ENC_NC;
  15456. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15457. sizeof(tag), a2, sizeof(a2));
  15458. if (ret != 0)
  15459. return WC_TEST_RET_ENC_EC(ret);
  15460. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15461. return WC_TEST_RET_ENC_NC;
  15462. wc_Sm4Free(&sm4);
  15463. return 0;
  15464. }
  15465. #endif
  15466. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void)
  15467. {
  15468. wc_test_ret_t ret;
  15469. WOLFSSL_ENTER("sm4_test");
  15470. #ifdef WOLFSSL_SM4_ECB
  15471. ret = sm4_ecb_test();
  15472. if (ret != 0)
  15473. return ret;
  15474. #endif
  15475. #ifdef WOLFSSL_SM4_CBC
  15476. ret = sm4_cbc_test();
  15477. if (ret != 0)
  15478. return ret;
  15479. #endif
  15480. #ifdef WOLFSSL_SM4_CTR
  15481. ret = sm4_ctr_test();
  15482. if (ret != 0)
  15483. return ret;
  15484. #endif
  15485. #ifdef WOLFSSL_SM4_GCM
  15486. ret = sm4_gcm_test();
  15487. if (ret != 0)
  15488. return ret;
  15489. #endif
  15490. #ifdef WOLFSSL_SM4_CCM
  15491. ret = sm4_ccm_test();
  15492. if (ret != 0)
  15493. return ret;
  15494. #endif
  15495. return 0;
  15496. }
  15497. #endif
  15498. #ifdef HAVE_XCHACHA
  15499. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void) {
  15500. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15501. 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, /* The dhole (prono */
  15502. 0x75, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x22, 0x64, 0x6f, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x69, 0x73, /* unced "dole") is */
  15503. 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x74, /* also known as t */
  15504. 0x68, 0x65, 0x20, 0x41, 0x73, 0x69, 0x61, 0x74, 0x69, 0x63, 0x20, 0x77, 0x69, 0x6c, 0x64, 0x20, /* he Asiatic wild */
  15505. 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x72, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x61, 0x6e, /* dog, red dog, an */
  15506. 0x64, 0x20, 0x77, 0x68, 0x69, 0x73, 0x74, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x64, 0x6f, 0x67, 0x2e, /* d whistling dog. */
  15507. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, /* It is about the */
  15508. 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x47, 0x65, 0x72, 0x6d, 0x61, /* size of a Germa */
  15509. 0x6e, 0x20, 0x73, 0x68, 0x65, 0x70, 0x68, 0x65, 0x72, 0x64, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6c, /* n shepherd but l */
  15510. 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x61, /* ooks more like a */
  15511. 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x6c, 0x65, 0x67, 0x67, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x78, /* long-legged fox */
  15512. 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x79, 0x20, 0x65, 0x6c, /* . This highly el */
  15513. 0x75, 0x73, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x65, /* usive and skille */
  15514. 0x64, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6c, 0x61, 0x73, /* d jumper is clas */
  15515. 0x73, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x77, 0x6f, 0x6c, 0x76, /* sified with wolv */
  15516. 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6f, 0x79, 0x6f, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x6a, 0x61, 0x63, /* es, coyotes, jac */
  15517. 0x6b, 0x61, 0x6c, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x78, 0x65, 0x73, 0x20, /* kals, and foxes */
  15518. 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x61, 0x78, 0x6f, 0x6e, 0x6f, 0x6d, 0x69, 0x63, /* in the taxonomic */
  15519. 0x20, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x20, 0x43, 0x61, 0x6e, 0x69, 0x64, 0x61, 0x65, 0x2e /* family Canidae. */
  15520. };
  15521. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15522. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15523. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15524. };
  15525. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15526. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15527. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58 }; /* PQRSTUVW */
  15528. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15529. 0x45, 0x59, 0xab, 0xba, 0x4e, 0x48, 0xc1, 0x61, 0x02, 0xe8, 0xbb, 0x2c, 0x05, 0xe6, 0x94, 0x7f,
  15530. 0x50, 0xa7, 0x86, 0xde, 0x16, 0x2f, 0x9b, 0x0b, 0x7e, 0x59, 0x2a, 0x9b, 0x53, 0xd0, 0xd4, 0xe9,
  15531. 0x8d, 0x8d, 0x64, 0x10, 0xd5, 0x40, 0xa1, 0xa6, 0x37, 0x5b, 0x26, 0xd8, 0x0d, 0xac, 0xe4, 0xfa,
  15532. 0xb5, 0x23, 0x84, 0xc7, 0x31, 0xac, 0xbf, 0x16, 0xa5, 0x92, 0x3c, 0x0c, 0x48, 0xd3, 0x57, 0x5d,
  15533. 0x4d, 0x0d, 0x2c, 0x67, 0x3b, 0x66, 0x6f, 0xaa, 0x73, 0x10, 0x61, 0x27, 0x77, 0x01, 0x09, 0x3a,
  15534. 0x6b, 0xf7, 0xa1, 0x58, 0xa8, 0x86, 0x42, 0x92, 0xa4, 0x1c, 0x48, 0xe3, 0xa9, 0xb4, 0xc0, 0xda,
  15535. 0xec, 0xe0, 0xf8, 0xd9, 0x8d, 0x0d, 0x7e, 0x05, 0xb3, 0x7a, 0x30, 0x7b, 0xbb, 0x66, 0x33, 0x31,
  15536. 0x64, 0xec, 0x9e, 0x1b, 0x24, 0xea, 0x0d, 0x6c, 0x3f, 0xfd, 0xdc, 0xec, 0x4f, 0x68, 0xe7, 0x44,
  15537. 0x30, 0x56, 0x19, 0x3a, 0x03, 0xc8, 0x10, 0xe1, 0x13, 0x44, 0xca, 0x06, 0xd8, 0xed, 0x8a, 0x2b,
  15538. 0xfb, 0x1e, 0x8d, 0x48, 0xcf, 0xa6, 0xbc, 0x0e, 0xb4, 0xe2, 0x46, 0x4b, 0x74, 0x81, 0x42, 0x40,
  15539. 0x7c, 0x9f, 0x43, 0x1a, 0xee, 0x76, 0x99, 0x60, 0xe1, 0x5b, 0xa8, 0xb9, 0x68, 0x90, 0x46, 0x6e,
  15540. 0xf2, 0x45, 0x75, 0x99, 0x85, 0x23, 0x85, 0xc6, 0x61, 0xf7, 0x52, 0xce, 0x20, 0xf9, 0xda, 0x0c,
  15541. 0x09, 0xab, 0x6b, 0x19, 0xdf, 0x74, 0xe7, 0x6a, 0x95, 0x96, 0x74, 0x46, 0xf8, 0xd0, 0xfd, 0x41,
  15542. 0x5e, 0x7b, 0xee, 0x2a, 0x12, 0xa1, 0x14, 0xc2, 0x0e, 0xb5, 0x29, 0x2a, 0xe7, 0xa3, 0x49, 0xae,
  15543. 0x57, 0x78, 0x20, 0xd5, 0x52, 0x0a, 0x1f, 0x3f, 0xb6, 0x2a, 0x17, 0xce, 0x6a, 0x7e, 0x68, 0xfa,
  15544. 0x7c, 0x79, 0x11, 0x1d, 0x88, 0x60, 0x92, 0x0b, 0xc0, 0x48, 0xef, 0x43, 0xfe, 0x84, 0x48, 0x6c,
  15545. 0xcb, 0x87, 0xc2, 0x5f, 0x0a, 0xe0, 0x45, 0xf0, 0xcc, 0xe1, 0xe7, 0x98, 0x9a, 0x9a, 0xa2, 0x20,
  15546. 0xa2, 0x8b, 0xdd, 0x48, 0x27, 0xe7, 0x51, 0xa2, 0x4a, 0x6d, 0x5c, 0x62, 0xd7, 0x90, 0xa6, 0x63,
  15547. 0x93, 0xb9, 0x31, 0x11, 0xc1, 0xa5, 0x5d, 0xd7, 0x42, 0x1a, 0x10, 0x18, 0x49, 0x74, 0xc7, 0xc5
  15548. };
  15549. wc_test_ret_t ret;
  15550. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15551. struct ChaCha *chacha = (struct ChaCha *)XMALLOC(sizeof *chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15552. byte *buf1 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15553. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15554. WOLFSSL_ENTER("XChaCha_test");
  15555. if ((chacha == NULL) || (buf1 == NULL) || (buf2 == NULL))
  15556. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15557. #else
  15558. struct ChaCha chacha[1];
  15559. byte buf1[sizeof Plaintext];
  15560. byte buf2[sizeof Plaintext];
  15561. WOLFSSL_ENTER("XChaCha_test");
  15562. #endif
  15563. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15564. if (ret < 0)
  15565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15566. ret = wc_Chacha_Process(chacha, buf1, Plaintext, sizeof Plaintext);
  15567. if (ret < 0)
  15568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15569. if (XMEMCMP(buf1, Ciphertext, sizeof Plaintext))
  15570. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15571. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15572. if (ret < 0)
  15573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15574. ret = wc_Chacha_Process(chacha, buf2, buf1, sizeof Plaintext);
  15575. if (ret < 0)
  15576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15577. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15578. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15579. out:
  15580. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15581. XFREE(chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15582. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15583. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15584. #endif
  15585. return ret;
  15586. }
  15587. #endif /* HAVE_XCHACHA */
  15588. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  15589. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void) {
  15590. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15591. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, /* Ladies and Gentl */
  15592. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, /* emen of the clas */
  15593. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, /* s of '99: If I c */
  15594. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, /* ould offer you o */
  15595. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, /* nly one tip for */
  15596. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, /* the future, suns */
  15597. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, /* creen would be i */
  15598. 0x74, 0x2e }; /* t. */
  15599. WOLFSSL_SMALL_STACK_STATIC const byte AAD[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; /* PQRS........ */
  15600. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15601. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15602. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15603. };
  15604. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15605. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15606. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }; /* PQRSTUVW */
  15607. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15608. 0xbd, 0x6d, 0x17, 0x9d, 0x3e, 0x83, 0xd4, 0x3b, 0x95, 0x76, 0x57, 0x94, 0x93, 0xc0, 0xe9, 0x39,
  15609. 0x57, 0x2a, 0x17, 0x00, 0x25, 0x2b, 0xfa, 0xcc, 0xbe, 0xd2, 0x90, 0x2c, 0x21, 0x39, 0x6c, 0xbb,
  15610. 0x73, 0x1c, 0x7f, 0x1b, 0x0b, 0x4a, 0xa6, 0x44, 0x0b, 0xf3, 0xa8, 0x2f, 0x4e, 0xda, 0x7e, 0x39,
  15611. 0xae, 0x64, 0xc6, 0x70, 0x8c, 0x54, 0xc2, 0x16, 0xcb, 0x96, 0xb7, 0x2e, 0x12, 0x13, 0xb4, 0x52,
  15612. 0x2f, 0x8c, 0x9b, 0xa4, 0x0d, 0xb5, 0xd9, 0x45, 0xb1, 0x1b, 0x69, 0xb9, 0x82, 0xc1, 0xbb, 0x9e,
  15613. 0x3f, 0x3f, 0xac, 0x2b, 0xc3, 0x69, 0x48, 0x8f, 0x76, 0xb2, 0x38, 0x35, 0x65, 0xd3, 0xff, 0xf9,
  15614. 0x21, 0xf9, 0x66, 0x4c, 0x97, 0x63, 0x7d, 0xa9, 0x76, 0x88, 0x12, 0xf6, 0x15, 0xc6, 0x8b, 0x13,
  15615. 0xb5, 0x2e };
  15616. WOLFSSL_SMALL_STACK_STATIC const byte Tag[] = {
  15617. 0xc0, 0x87, 0x59, 0x24, 0xc1, 0xc7, 0x98, 0x79, 0x47, 0xde, 0xaf, 0xd8, 0x78, 0x0a, 0xcf, 0x49
  15618. };
  15619. wc_test_ret_t ret;
  15620. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15621. byte *buf1 = (byte *)XMALLOC(sizeof Ciphertext + sizeof Tag, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15622. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15623. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15624. if ((buf1 == NULL) || (buf2 == NULL))
  15625. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15626. #else
  15627. byte buf1[sizeof Ciphertext + sizeof Tag];
  15628. byte buf2[sizeof Plaintext];
  15629. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15630. #endif
  15631. ret = wc_XChaCha20Poly1305_Encrypt(buf1, sizeof Ciphertext + sizeof Tag,
  15632. Plaintext, sizeof Plaintext,
  15633. AAD, sizeof AAD,
  15634. IV, sizeof IV,
  15635. Key, sizeof Key);
  15636. if (ret < 0)
  15637. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15638. if (XMEMCMP(buf1, Ciphertext, sizeof Ciphertext))
  15639. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15640. if (XMEMCMP(buf1 + sizeof Ciphertext, Tag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE))
  15641. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15642. ret = wc_XChaCha20Poly1305_Decrypt(buf2, sizeof Plaintext,
  15643. buf1, sizeof Ciphertext + sizeof Tag,
  15644. AAD, sizeof AAD,
  15645. IV, sizeof IV,
  15646. Key, sizeof Key);
  15647. if (ret < 0)
  15648. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15649. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15650. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15651. out:
  15652. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15653. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15654. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15655. #endif
  15656. return ret;
  15657. }
  15658. #endif /* defined(HAVE_XCHACHA) && defined(HAVE_POLY1305) */
  15659. #ifndef WC_NO_RNG
  15660. static wc_test_ret_t _rng_test(WC_RNG* rng)
  15661. {
  15662. byte block[32];
  15663. wc_test_ret_t ret;
  15664. int i;
  15665. XMEMSET(block, 0, sizeof(block));
  15666. ret = wc_RNG_GenerateBlock(rng, block, sizeof(block));
  15667. if (ret != 0) {
  15668. return WC_TEST_RET_ENC_EC(ret);
  15669. }
  15670. /* Check for 0's */
  15671. for (i=0; i<(int)sizeof(block); i++) {
  15672. if (block[i] == 0) {
  15673. ret++;
  15674. }
  15675. }
  15676. /* All zeros count check */
  15677. if (ret >= (int)sizeof(block)) {
  15678. return WC_TEST_RET_ENC_NC;
  15679. }
  15680. ret = wc_RNG_GenerateByte(rng, block);
  15681. if (ret != 0) {
  15682. return WC_TEST_RET_ENC_EC(ret);
  15683. }
  15684. /* Parameter validation testing. */
  15685. ret = wc_RNG_GenerateBlock(NULL, block, sizeof(block));
  15686. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15687. return WC_TEST_RET_ENC_EC(ret);
  15688. }
  15689. ret = wc_RNG_GenerateBlock(rng, NULL, sizeof(block));
  15690. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15691. return WC_TEST_RET_ENC_EC(ret);
  15692. }
  15693. ret = wc_RNG_GenerateByte(NULL, block);
  15694. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15695. return WC_TEST_RET_ENC_EC(ret);
  15696. }
  15697. ret = wc_RNG_GenerateByte(rng, NULL);
  15698. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15699. return WC_TEST_RET_ENC_EC(ret);
  15700. }
  15701. return 0;
  15702. }
  15703. static wc_test_ret_t random_rng_test(void)
  15704. {
  15705. WC_RNG localRng;
  15706. WC_RNG* rng;
  15707. wc_test_ret_t ret;
  15708. rng = &localRng;
  15709. /* Test stack based RNG. */
  15710. #ifndef HAVE_FIPS
  15711. ret = wc_InitRng_ex(rng, HEAP_HINT, devId);
  15712. #else
  15713. ret = wc_InitRng(rng);
  15714. #endif
  15715. if (ret != 0)
  15716. return WC_TEST_RET_ENC_EC(ret);
  15717. ret = _rng_test(rng);
  15718. /* Make sure and free RNG */
  15719. wc_FreeRng(rng);
  15720. if (ret != 0)
  15721. return ret;
  15722. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
  15723. {
  15724. byte nonce[8] = { 0 };
  15725. /* Test dynamic RNG */
  15726. rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
  15727. if (rng == NULL)
  15728. return WC_TEST_RET_ENC_ERRNO;
  15729. ret = _rng_test(rng);
  15730. wc_rng_free(rng);
  15731. rng = NULL;
  15732. if (ret != 0)
  15733. return ret;
  15734. /* Test dynamic RNG using extended API */
  15735. ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
  15736. HEAP_HINT, devId);
  15737. if (ret != 0)
  15738. return WC_TEST_RET_ENC_EC(ret);
  15739. ret = _rng_test(rng);
  15740. wc_rng_free(rng);
  15741. if (ret != 0)
  15742. return ret;
  15743. }
  15744. #endif
  15745. return ret;
  15746. }
  15747. #if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  15748. #ifdef WC_RNG_SEED_CB
  15749. static int seed_cb(OS_Seed* os, byte* output, word32 sz)
  15750. {
  15751. word32 i;
  15752. (void)os;
  15753. /* Known answer test. Set the seed to the same value every time. */
  15754. for (i = 0; i < sz; i++)
  15755. output[i] = (byte)i;
  15756. return 0;
  15757. }
  15758. static wc_test_ret_t rng_seed_test(void)
  15759. {
  15760. #ifndef HAVE_FIPS
  15761. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15762. {
  15763. 0x83, 0x46, 0x65, 0x2f, 0x5c, 0x44, 0x16, 0x5f,
  15764. 0xb3, 0x89, 0x26, 0xde, 0x0b, 0x6b, 0xa2, 0x06,
  15765. 0x7e, 0xa7, 0x9a, 0x55, 0x22, 0x01, 0xb0, 0x22,
  15766. 0xf4, 0x7e, 0xa2, 0x66, 0xc4, 0x08, 0x6f, 0xba
  15767. };
  15768. #else
  15769. /* FIPS uses a longer seed, so different check value. */
  15770. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15771. {
  15772. 0xaf, 0x31, 0xcc, 0xef, 0xa9, 0x29, 0x4c, 0x24,
  15773. 0xbd, 0xa5, 0xa3, 0x52, 0x69, 0xf3, 0xb9, 0xb2,
  15774. 0x1e, 0xd4, 0x52, 0x3b, 0x9a, 0x96, 0x06, 0x20,
  15775. 0xc0, 0x5f, 0x44, 0x06, 0x1f, 0x80, 0xdf, 0xe0
  15776. };
  15777. #endif
  15778. byte output[WC_SHA256_DIGEST_SIZE];
  15779. WC_RNG rng;
  15780. wc_test_ret_t ret;
  15781. ret = wc_SetSeed_Cb(seed_cb);
  15782. if (ret != 0) {
  15783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15784. }
  15785. ret = wc_InitRng(&rng);
  15786. if (ret != 0) {
  15787. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15788. }
  15789. ret = wc_RNG_GenerateBlock(&rng, output, sizeof(output));
  15790. if (ret != 0) {
  15791. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15792. }
  15793. ret = XMEMCMP(output, check, sizeof(output));
  15794. if (ret != 0) {
  15795. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15796. }
  15797. ret = wc_FreeRng(&rng);
  15798. if (ret != 0) {
  15799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15800. }
  15801. ret = wc_SetSeed_Cb(wc_GenerateSeed);
  15802. if (ret != 0) {
  15803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15804. }
  15805. out:
  15806. return ret;
  15807. }
  15808. #endif
  15809. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15810. {
  15811. WOLFSSL_SMALL_STACK_STATIC const byte test1Entropy[] =
  15812. {
  15813. 0xa6, 0x5a, 0xd0, 0xf3, 0x45, 0xdb, 0x4e, 0x0e, 0xff, 0xe8, 0x75, 0xc3,
  15814. 0xa2, 0xe7, 0x1f, 0x42, 0xc7, 0x12, 0x9d, 0x62, 0x0f, 0xf5, 0xc1, 0x19,
  15815. 0xa9, 0xef, 0x55, 0xf0, 0x51, 0x85, 0xe0, 0xfb, 0x85, 0x81, 0xf9, 0x31,
  15816. 0x75, 0x17, 0x27, 0x6e, 0x06, 0xe9, 0x60, 0x7d, 0xdb, 0xcb, 0xcc, 0x2e
  15817. };
  15818. WOLFSSL_SMALL_STACK_STATIC const byte test1Output[] =
  15819. {
  15820. 0xd3, 0xe1, 0x60, 0xc3, 0x5b, 0x99, 0xf3, 0x40, 0xb2, 0x62, 0x82, 0x64,
  15821. 0xd1, 0x75, 0x10, 0x60, 0xe0, 0x04, 0x5d, 0xa3, 0x83, 0xff, 0x57, 0xa5,
  15822. 0x7d, 0x73, 0xa6, 0x73, 0xd2, 0xb8, 0xd8, 0x0d, 0xaa, 0xf6, 0xa6, 0xc3,
  15823. 0x5a, 0x91, 0xbb, 0x45, 0x79, 0xd7, 0x3f, 0xd0, 0xc8, 0xfe, 0xd1, 0x11,
  15824. 0xb0, 0x39, 0x13, 0x06, 0x82, 0x8a, 0xdf, 0xed, 0x52, 0x8f, 0x01, 0x81,
  15825. 0x21, 0xb3, 0xfe, 0xbd, 0xc3, 0x43, 0xe7, 0x97, 0xb8, 0x7d, 0xbb, 0x63,
  15826. 0xdb, 0x13, 0x33, 0xde, 0xd9, 0xd1, 0xec, 0xe1, 0x77, 0xcf, 0xa6, 0xb7,
  15827. 0x1f, 0xe8, 0xab, 0x1d, 0xa4, 0x66, 0x24, 0xed, 0x64, 0x15, 0xe5, 0x1c,
  15828. 0xcd, 0xe2, 0xc7, 0xca, 0x86, 0xe2, 0x83, 0x99, 0x0e, 0xea, 0xeb, 0x91,
  15829. 0x12, 0x04, 0x15, 0x52, 0x8b, 0x22, 0x95, 0x91, 0x02, 0x81, 0xb0, 0x2d,
  15830. 0xd4, 0x31, 0xf4, 0xc9, 0xf7, 0x04, 0x27, 0xdf
  15831. };
  15832. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyA[] =
  15833. {
  15834. 0x63, 0x36, 0x33, 0x77, 0xe4, 0x1e, 0x86, 0x46, 0x8d, 0xeb, 0x0a, 0xb4,
  15835. 0xa8, 0xed, 0x68, 0x3f, 0x6a, 0x13, 0x4e, 0x47, 0xe0, 0x14, 0xc7, 0x00,
  15836. 0x45, 0x4e, 0x81, 0xe9, 0x53, 0x58, 0xa5, 0x69, 0x80, 0x8a, 0xa3, 0x8f,
  15837. 0x2a, 0x72, 0xa6, 0x23, 0x59, 0x91, 0x5a, 0x9f, 0x8a, 0x04, 0xca, 0x68
  15838. };
  15839. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyB[] =
  15840. {
  15841. 0xe6, 0x2b, 0x8a, 0x8e, 0xe8, 0xf1, 0x41, 0xb6, 0x98, 0x05, 0x66, 0xe3,
  15842. 0xbf, 0xe3, 0xc0, 0x49, 0x03, 0xda, 0xd4, 0xac, 0x2c, 0xdf, 0x9f, 0x22,
  15843. 0x80, 0x01, 0x0a, 0x67, 0x39, 0xbc, 0x83, 0xd3
  15844. };
  15845. WOLFSSL_SMALL_STACK_STATIC const byte test2Output[] =
  15846. {
  15847. 0x04, 0xee, 0xc6, 0x3b, 0xb2, 0x31, 0xdf, 0x2c, 0x63, 0x0a, 0x1a, 0xfb,
  15848. 0xe7, 0x24, 0x94, 0x9d, 0x00, 0x5a, 0x58, 0x78, 0x51, 0xe1, 0xaa, 0x79,
  15849. 0x5e, 0x47, 0x73, 0x47, 0xc8, 0xb0, 0x56, 0x62, 0x1c, 0x18, 0xbd, 0xdc,
  15850. 0xdd, 0x8d, 0x99, 0xfc, 0x5f, 0xc2, 0xb9, 0x20, 0x53, 0xd8, 0xcf, 0xac,
  15851. 0xfb, 0x0b, 0xb8, 0x83, 0x12, 0x05, 0xfa, 0xd1, 0xdd, 0xd6, 0xc0, 0x71,
  15852. 0x31, 0x8a, 0x60, 0x18, 0xf0, 0x3b, 0x73, 0xf5, 0xed, 0xe4, 0xd4, 0xd0,
  15853. 0x71, 0xf9, 0xde, 0x03, 0xfd, 0x7a, 0xea, 0x10, 0x5d, 0x92, 0x99, 0xb8,
  15854. 0xaf, 0x99, 0xaa, 0x07, 0x5b, 0xdb, 0x4d, 0xb9, 0xaa, 0x28, 0xc1, 0x8d,
  15855. 0x17, 0x4b, 0x56, 0xee, 0x2a, 0x01, 0x4d, 0x09, 0x88, 0x96, 0xff, 0x22,
  15856. 0x82, 0xc9, 0x55, 0xa8, 0x19, 0x69, 0xe0, 0x69, 0xfa, 0x8c, 0xe0, 0x07,
  15857. 0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17
  15858. };
  15859. byte output[WC_SHA256_DIGEST_SIZE * 4];
  15860. wc_test_ret_t ret;
  15861. WOLFSSL_ENTER("random_test");
  15862. ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
  15863. output, sizeof(output));
  15864. if (ret != 0)
  15865. return WC_TEST_RET_ENC_EC(ret);
  15866. if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
  15867. return WC_TEST_RET_ENC_NC;
  15868. ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
  15869. test2EntropyB, sizeof(test2EntropyB),
  15870. output, sizeof(output));
  15871. if (ret != 0)
  15872. return WC_TEST_RET_ENC_EC(ret);
  15873. if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
  15874. return WC_TEST_RET_ENC_NC;
  15875. /* Basic RNG generate block test */
  15876. if ((ret = random_rng_test()) != 0)
  15877. return ret;
  15878. /* Test the seed check function. */
  15879. #if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
  15880. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  15881. {
  15882. word32 i, outputSz;
  15883. /* Repeat the same byte over and over. Should fail. */
  15884. outputSz = sizeof(output);
  15885. XMEMSET(output, 1, outputSz);
  15886. ret = wc_RNG_TestSeed(output, outputSz);
  15887. if (ret == 0)
  15888. return WC_TEST_RET_ENC_NC;
  15889. /* Every byte of the entropy scratch is different,
  15890. * entropy is a single byte that shouldn't match. */
  15891. outputSz = (sizeof(output) / 2) + 1;
  15892. for (i = 0; i < outputSz; i++)
  15893. output[i] = (byte)i;
  15894. ret = wc_RNG_TestSeed(output, outputSz);
  15895. if (ret != 0)
  15896. return WC_TEST_RET_ENC_EC(ret);
  15897. outputSz = sizeof(output);
  15898. for (i = 0; i < outputSz; i++)
  15899. output[i] = (byte)i;
  15900. ret = wc_RNG_TestSeed(output, outputSz);
  15901. if (ret != 0)
  15902. return WC_TEST_RET_ENC_EC(ret);
  15903. }
  15904. #endif
  15905. /* Test the seed callback. */
  15906. #ifdef WC_RNG_SEED_CB
  15907. if ((ret = rng_seed_test()) != 0)
  15908. return ret;
  15909. #endif
  15910. return 0;
  15911. }
  15912. #else
  15913. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15914. {
  15915. WOLFSSL_ENTER("random_test");
  15916. /* Basic RNG generate block test */
  15917. return random_rng_test();
  15918. }
  15919. #endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
  15920. #endif /* WC_NO_RNG */
  15921. #ifndef MEM_TEST_SZ
  15922. #define MEM_TEST_SZ 1024
  15923. #endif
  15924. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15925. static int simple_mem_test(size_t sz)
  15926. {
  15927. int ret = 0;
  15928. byte* b;
  15929. int i;
  15930. b = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15931. if (b == NULL) {
  15932. return WC_TEST_RET_ENC_NC;
  15933. }
  15934. /* utilize memory */
  15935. for (i = 0; i < (int)sz; i++) {
  15936. b[i] = (byte)i;
  15937. }
  15938. /* read back and verify */
  15939. for (i = 0; i < (int)sz; i++) {
  15940. if (b[i] != (byte)i) {
  15941. ret = WC_TEST_RET_ENC_NC;
  15942. break;
  15943. }
  15944. }
  15945. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15946. return ret;
  15947. }
  15948. #endif
  15949. /* If successful, returns the first letter of the byte array `in`.
  15950. **
  15951. ** This is a deceptively simple test of a read-only embedded Linux file system.
  15952. ** (e.g CFLAGS `-mfdpic` and `-mforce-l32`) for Xtensa Linux ESP32. When the
  15953. ** `-mforce-l32` is missing, access to `in` will fail with Illegal Instruction.
  15954. ** Const is on read-only memory-mapped file system, *not* loaded in app memory.
  15955. **
  15956. ** Edit with caution. See PR #6523. */
  15957. static wc_test_ret_t const_byte_ptr_test(const byte* in, word32 *outJ)
  15958. {
  15959. wc_test_ret_t ret = 0;
  15960. volatile word32 j = (word32)-1; /* must be volatile to properly detect error */
  15961. ret = (wc_test_ret_t)*in; /* accessed *in value. */
  15962. (void)ret;
  15963. j = *outJ; /* Found index to use in const array. */
  15964. if (j == 0) {
  15965. #ifdef WOLFSSL_DEBUG
  15966. printf("Testing const byte ptr reference...\n");
  15967. #endif
  15968. /* although j is zero, in[0] does not detect the Illegal instruction */
  15969. ret = in[j]; /* The big test: can we actually access the `in` data? */
  15970. }
  15971. else {
  15972. ret = WC_TEST_RET_ENC_I(j);
  15973. }
  15974. return ret;
  15975. }
  15976. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
  15977. {
  15978. wc_test_ret_t ret = 0;
  15979. word32 j = 0; /* used in embedded const pointer test */
  15980. WOLFSSL_ENTER("memory_test");
  15981. #if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY)
  15982. int i;
  15983. #endif
  15984. #ifdef WOLFSSL_STATIC_MEMORY
  15985. word32 size[] = { WOLFMEM_BUCKETS };
  15986. word32 dist[] = { WOLFMEM_DIST };
  15987. byte buffer[30000]; /* make large enough to involve many bucket sizes */
  15988. int pad = -(int)((wc_ptr_t)buffer) & (WOLFSSL_STATIC_ALIGN - 1);
  15989. /* pad to account for if head of buffer is not at set memory
  15990. * alignment when tests are ran */
  15991. #endif
  15992. #ifdef WOLFSSL_STATIC_MEMORY
  15993. /* check macro settings */
  15994. if (sizeof(size)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15995. return WC_TEST_RET_ENC_NC;
  15996. }
  15997. if (sizeof(dist)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15998. return WC_TEST_RET_ENC_NC;
  15999. }
  16000. if (WOLFMEM_DEF_BUCKETS > WOLFMEM_MAX_BUCKETS) {
  16001. return WC_TEST_RET_ENC_NC;
  16002. }
  16003. for (i = 0; i < WOLFMEM_DEF_BUCKETS; i++) {
  16004. if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) {
  16005. /* each element in array should be divisible by alignment size */
  16006. return WC_TEST_RET_ENC_NC;
  16007. }
  16008. }
  16009. for (i = 1; i < WOLFMEM_DEF_BUCKETS; i++) {
  16010. if (size[i - 1] >= size[i]) {
  16011. return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */
  16012. }
  16013. }
  16014. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  16015. /* check that padding size returned is possible */
  16016. if (wolfSSL_MemoryPaddingSz() < WOLFSSL_STATIC_ALIGN) {
  16017. return WC_TEST_RET_ENC_NC; /* no room for wc_Memory struct */
  16018. }
  16019. ret = wolfSSL_MemoryPaddingSz();
  16020. if (ret < 0) {
  16021. return WC_TEST_RET_ENC_EC(ret);
  16022. }
  16023. if (wolfSSL_MemoryPaddingSz() % WOLFSSL_STATIC_ALIGN != 0) {
  16024. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16025. }
  16026. /* check function to return optimum buffer size (rounded down) */
  16027. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_GENERAL);
  16028. if (ret < 0) {
  16029. return WC_TEST_RET_ENC_EC(ret);
  16030. }
  16031. if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) {
  16032. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16033. }
  16034. if ((unsigned int)ret > sizeof(buffer)) {
  16035. return WC_TEST_RET_ENC_NC; /* did not round down as expected */
  16036. }
  16037. if (ret != wolfSSL_StaticBufferSz(buffer, ret, WOLFMEM_GENERAL)) {
  16038. return WC_TEST_RET_ENC_NC; /* return value changed when using suggested
  16039. * value
  16040. */
  16041. }
  16042. ret = wolfSSL_MemoryPaddingSz();
  16043. ret += pad; /* add space that is going to be needed if buffer not aligned */
  16044. if (wolfSSL_StaticBufferSz(buffer, size[0] + ret + 1, WOLFMEM_GENERAL) !=
  16045. (ret + (int)size[0])) {
  16046. return WC_TEST_RET_ENC_NC; /* did not round down to nearest bucket
  16047. * value
  16048. */
  16049. }
  16050. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_IO_POOL);
  16051. if ((ret - pad) < 0) {
  16052. return WC_TEST_RET_ENC_NC;
  16053. }
  16054. if (((ret - pad) % (WOLFMEM_IO_SZ + wolfSSL_MemoryPaddingSz())) != 0) {
  16055. return WC_TEST_RET_ENC_NC; /* not even chunks of memory for IO size */
  16056. }
  16057. if (((ret - pad) % WOLFSSL_STATIC_ALIGN) != 0) {
  16058. return WC_TEST_RET_ENC_NC; /* memory not aligned */
  16059. }
  16060. /* check for passing bad or unknown arguments to functions */
  16061. if (wolfSSL_StaticBufferSz(NULL, 1, WOLFMEM_GENERAL) > 0) {
  16062. return WC_TEST_RET_ENC_NC;
  16063. }
  16064. if (wolfSSL_StaticBufferSz(buffer, 1, WOLFMEM_GENERAL) != 0) {
  16065. return WC_TEST_RET_ENC_NC; /* should round to 0
  16066. since struct + bucket will not fit */
  16067. }
  16068. #endif
  16069. (void)pad;
  16070. (void)dist; /* avoid static analysis warning of variable not used */
  16071. #endif
  16072. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  16073. /* simple test */
  16074. ret = simple_mem_test((size_t)MEM_TEST_SZ);
  16075. if (ret != 0)
  16076. return ret;
  16077. #endif
  16078. #ifdef COMPLEX_MEM_TEST
  16079. /* test various size blocks */
  16080. for (i = 1; i < MEM_TEST_SZ; i*=2) {
  16081. ret = simple_mem_test((size_t)i);
  16082. if (ret != 0)
  16083. return ret;
  16084. }
  16085. #endif
  16086. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) && defined(XREALLOC)
  16087. /* realloc test */
  16088. {
  16089. byte *b = (byte*)XMALLOC(MEM_TEST_SZ, HEAP_HINT,
  16090. DYNAMIC_TYPE_TMP_BUFFER);
  16091. #ifndef WOLFSSL_NO_REALLOC
  16092. byte *c = NULL;
  16093. if (b) {
  16094. c = (byte*)XREALLOC(b, MEM_TEST_SZ+sizeof(word32), HEAP_HINT,
  16095. DYNAMIC_TYPE_TMP_BUFFER);
  16096. if (c)
  16097. b = c;
  16098. }
  16099. #endif
  16100. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16101. if (b == NULL
  16102. #ifndef WOLFSSL_NO_REALLOC
  16103. || c == NULL
  16104. #endif
  16105. ) {
  16106. return WC_TEST_RET_ENC_ERRNO;
  16107. }
  16108. }
  16109. #endif
  16110. if (ret == 0) {
  16111. /* This test is only interesting on embedded R/O Flash systems */
  16112. if (const_byte_ptr_test(const_byte_array, &j) != CBPTR_EXPECTED) {
  16113. ret = 1;
  16114. }
  16115. }
  16116. return ret;
  16117. }
  16118. #ifndef NO_FILESYSTEM
  16119. /* Cert Paths */
  16120. #ifdef FREESCALE_MQX
  16121. #define CERT_PREFIX "a:\\"
  16122. #define CERT_PATH_SEP "\\"
  16123. #elif defined(WOLFSSL_uTKERNEL2)
  16124. #define CERT_PREFIX "/uda/"
  16125. #define CERT_PATH_SEP "/"
  16126. #elif defined(_WIN32_WCE)
  16127. #define CERT_PREFIX "\\windows\\"
  16128. #define CERT_PATH_SEP "\\"
  16129. #elif defined(WOLFSSL_NDS)
  16130. #undef CERT_PREFIX
  16131. #ifndef WOLFSSL_MELONDS
  16132. #define CERT_PREFIX "fat:/_nds/"
  16133. #else
  16134. #define CERT_PREFIX "_nds/"
  16135. #endif
  16136. #define CERT_PATH_SEP "/"
  16137. #endif
  16138. #ifndef CERT_PREFIX
  16139. #define CERT_PREFIX "./"
  16140. #endif
  16141. #ifndef CERT_PATH_SEP
  16142. #define CERT_PATH_SEP "/"
  16143. #endif
  16144. #ifndef CERT_WRITE_TEMP_DIR
  16145. #define CERT_WRITE_TEMP_DIR CERT_PREFIX
  16146. #endif
  16147. #define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
  16148. /* Generated Test Certs */
  16149. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16150. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16151. #if !defined(NO_RSA) && !defined(NO_ASN)
  16152. static const char* clientKey = CERT_ROOT "client-key.der";
  16153. static const char* clientCert = CERT_ROOT "client-cert.der";
  16154. #ifdef WOLFSSL_CERT_EXT
  16155. static const char* clientKeyPub = CERT_ROOT "client-keyPub.der";
  16156. #endif
  16157. #endif /* !NO_RSA && !NO_ASN */
  16158. #endif
  16159. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16160. #if !defined(NO_RSA) && !defined(NO_ASN)
  16161. #if defined(WOLFSSL_CERT_GEN) || defined(HAVE_PKCS7)
  16162. static const char* rsaCaKeyFile = CERT_ROOT "ca-key.der";
  16163. #ifdef WOLFSSL_CERT_GEN
  16164. static const char* rsaCaCertFile = CERT_ROOT "ca-cert.pem";
  16165. #endif
  16166. #if (defined(WOLFSSL_ALT_NAMES) && !defined(WOLFSSL_NO_MALLOC)) || \
  16167. defined(HAVE_PKCS7)
  16168. static const char* rsaCaCertDerFile = CERT_ROOT "ca-cert.der";
  16169. #endif
  16170. #ifdef HAVE_PKCS7
  16171. static const char* rsaServerCertDerFile =
  16172. CERT_ROOT "server-cert.der";
  16173. static const char* rsaServerKeyDerFile =
  16174. CERT_ROOT "server-key.der";
  16175. #endif
  16176. #endif
  16177. #endif /* !NO_RSA && !NO_ASN */
  16178. #endif /* !USE_CERT_BUFFER_* */
  16179. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16180. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16181. #if !defined(NO_ASN) && !defined(NO_DH)
  16182. static const char* dhParamsFile = CERT_ROOT "dh2048.der";
  16183. #endif
  16184. #endif
  16185. #if !defined(NO_ASN) && !defined(NO_DH)
  16186. #if defined(WOLFSSL_DH_EXTRA) && (!defined(HAVE_FIPS) || \
  16187. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  16188. #if !defined(USE_CERT_BUFFERS_2048)
  16189. static const char* dhKeyFile = CERT_ROOT "statickeys/dh-ffdhe2048.der";
  16190. static const char* dhKeyPubFile = CERT_ROOT "statickeys/dh-ffdhe2048-pub.der";
  16191. #endif
  16192. #endif
  16193. #endif
  16194. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16195. #ifndef NO_DSA
  16196. static const char* dsaKey = CERT_ROOT "dsa2048.der";
  16197. #endif
  16198. #endif /* !USE_CERT_BUFFER_* */
  16199. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ECC256)
  16200. #ifdef HAVE_ECC
  16201. /* cert files to be used in rsa cert gen test, check if RSA enabled */
  16202. #ifdef HAVE_ECC_KEY_IMPORT
  16203. static const char* eccKeyDerFile = CERT_ROOT "ecc-key.der";
  16204. #endif
  16205. #endif
  16206. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN)
  16207. #if defined(HAVE_ECC) && defined(WOLFSSL_CERT_GEN) && \
  16208. !defined(NO_ECC_SECP)
  16209. #ifndef NO_RSA
  16210. static const char* eccKeyPubFileDer = CERT_ROOT "ecc-keyPub.der";
  16211. #endif
  16212. #if !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  16213. static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der";
  16214. static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem";
  16215. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16216. static const char* eccCaKey384File =
  16217. CERT_ROOT "ca-ecc384-key.der";
  16218. static const char* eccCaCert384File =
  16219. CERT_ROOT "ca-ecc384-cert.pem";
  16220. #endif
  16221. #endif
  16222. #endif
  16223. #if defined(HAVE_PKCS7) && defined(HAVE_ECC)
  16224. static const char* eccClientKey = CERT_ROOT "ecc-client-key.der";
  16225. static const char* eccClientCert = CERT_ROOT "client-ecc-cert.der";
  16226. #endif
  16227. #endif /* HAVE_ECC */
  16228. #ifdef HAVE_ED25519
  16229. #ifdef WOLFSSL_TEST_CERT
  16230. static const char* serverEd25519Cert =
  16231. CERT_ROOT "ed25519/server-ed25519.der";
  16232. static const char* caEd25519Cert =
  16233. CERT_ROOT "ed25519/ca-ed25519.der";
  16234. #endif
  16235. #endif
  16236. #ifdef HAVE_ED448
  16237. #ifdef WOLFSSL_TEST_CERT
  16238. static const char* serverEd448Cert =
  16239. CERT_ROOT "ed448/server-ed448.der";
  16240. static const char* caEd448Cert = CERT_ROOT "ed448/ca-ed448.der";
  16241. #endif
  16242. #endif
  16243. #endif /* !USE_CERT_BUFFER_* */
  16244. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16245. !defined(NO_FILESYSTEM)
  16246. static const char* certExtNc =
  16247. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nc.der";
  16248. static const char* certExtIa =
  16249. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-ia.der";
  16250. static const char* certExtNct =
  16251. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nct.der";
  16252. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16253. static const char* certBadNegInt =
  16254. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-neg-int.der";
  16255. #endif
  16256. static const char* certBadOid =
  16257. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-oid.der";
  16258. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16259. static const char* certBadUtf8 =
  16260. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-utf8.der";
  16261. #endif
  16262. #endif
  16263. #ifndef NO_WRITE_TEMP_FILES
  16264. #ifdef HAVE_ECC
  16265. #ifndef NO_ECC_SECP
  16266. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16267. !defined(WOLFSSL_NO_MALLOC)
  16268. static const char* certEccPemFile = CERT_WRITE_TEMP_DIR "certecc.pem";
  16269. static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der";
  16270. #endif
  16271. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  16272. static const char* certEccRsaPemFile = CERT_WRITE_TEMP_DIR "certeccrsa.pem";
  16273. static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der";
  16274. #endif
  16275. #endif
  16276. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  16277. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ASN_CRYPT)
  16278. static const char* eccCaKeyPemFile = CERT_WRITE_TEMP_DIR "ecc-key.pem";
  16279. static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der";
  16280. static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der";
  16281. #if defined(HAVE_PKCS8) && !defined(WC_NO_RNG) && \
  16282. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  16283. static const char* eccPkcs8KeyDerFile = CERT_WRITE_TEMP_DIR "ecc-key-pkcs8.der";
  16284. #endif
  16285. #endif /* HAVE_ECC_KEY_EXPORT */
  16286. #endif /* HAVE_ECC */
  16287. #ifndef NO_RSA
  16288. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16289. !defined(WOLFSSL_NO_MALLOC)
  16290. static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der";
  16291. static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der";
  16292. static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem";
  16293. static const char* certPemFile = CERT_WRITE_TEMP_DIR "cert.pem";
  16294. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  16295. static const char* certReqDerFile = CERT_WRITE_TEMP_DIR "certreq.der";
  16296. static const char* certReqPemFile = CERT_WRITE_TEMP_DIR "certreq.pem";
  16297. #endif
  16298. #endif
  16299. #endif /* !NO_RSA */
  16300. #if !defined(NO_RSA) || !defined(NO_DSA)
  16301. #ifdef WOLFSSL_KEY_GEN
  16302. static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
  16303. static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
  16304. #endif
  16305. #endif
  16306. #endif /* !NO_WRITE_TEMP_FILES */
  16307. #endif /* !NO_FILESYSTEM */
  16308. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  16309. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  16310. static CertName certDefaultName;
  16311. static void initDefaultName(void)
  16312. {
  16313. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16314. NameAttrib* n;
  16315. #endif
  16316. XMEMCPY(certDefaultName.country, "US", sizeof("US"));
  16317. certDefaultName.countryEnc = CTC_PRINTABLE;
  16318. XMEMCPY(certDefaultName.state, "Oregon", sizeof("Oregon"));
  16319. certDefaultName.stateEnc = CTC_UTF8;
  16320. XMEMCPY(certDefaultName.street, "Main St", sizeof("Main St"));
  16321. certDefaultName.streetEnc = CTC_UTF8;
  16322. XMEMCPY(certDefaultName.locality, "Portland", sizeof("Portland"));
  16323. certDefaultName.localityEnc = CTC_UTF8;
  16324. XMEMCPY(certDefaultName.sur, "Test", sizeof("Test"));
  16325. certDefaultName.surEnc = CTC_UTF8;
  16326. XMEMCPY(certDefaultName.org, "wolfSSL", sizeof("wolfSSL"));
  16327. certDefaultName.orgEnc = CTC_UTF8;
  16328. XMEMCPY(certDefaultName.unit, "Development", sizeof("Development"));
  16329. certDefaultName.unitEnc = CTC_UTF8;
  16330. XMEMCPY(certDefaultName.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  16331. certDefaultName.commonNameEnc = CTC_UTF8;
  16332. XMEMCPY(certDefaultName.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  16333. certDefaultName.serialDevEnc = CTC_PRINTABLE;
  16334. XMEMCPY(certDefaultName.postalCode, "12-456", sizeof("12-456"));
  16335. certDefaultName.postalCodeEnc = CTC_PRINTABLE;
  16336. #ifdef WOLFSSL_CERT_EXT
  16337. XMEMCPY(certDefaultName.busCat, "Private Organization", sizeof("Private Organization"));
  16338. certDefaultName.busCatEnc = CTC_UTF8;
  16339. XMEMCPY(certDefaultName.joiSt, "US", sizeof("US"));
  16340. certDefaultName.joiStEnc = CTC_PRINTABLE;
  16341. XMEMCPY(certDefaultName.joiC, "Oregon", sizeof("Oregon"));
  16342. certDefaultName.joiCEnc = CTC_PRINTABLE;
  16343. #endif
  16344. XMEMCPY(certDefaultName.email, "info@wolfssl.com", sizeof("info@wolfssl.com"));
  16345. XMEMCPY(certDefaultName.userId, "TestUserID", sizeof("TestUserID"));
  16346. certDefaultName.userIdEnc = CTC_PRINTABLE;
  16347. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16348. /* test having additional OUs and setting DC */
  16349. n = &certDefaultName.name[0];
  16350. n->id = ASN_ORGUNIT_NAME;
  16351. n->type = CTC_UTF8;
  16352. n->sz = XSTRLEN("Development-2");
  16353. XMEMCPY(n->value, "Development-2", sizeof("Development-2"));
  16354. #if CTC_MAX_ATTRIB > 3
  16355. n = &certDefaultName.name[1];
  16356. n->id = ASN_DOMAIN_COMPONENT;
  16357. n->type = CTC_UTF8;
  16358. n->sz = XSTRLEN("com");
  16359. XMEMCPY(n->value, "com", sizeof("com"));
  16360. n = &certDefaultName.name[2];
  16361. n->id = ASN_DOMAIN_COMPONENT;
  16362. n->type = CTC_UTF8;
  16363. n->sz = XSTRLEN("wolfssl");
  16364. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  16365. #endif
  16366. #endif /* WOLFSSL_MULTI_ATTRIB && WOLFSSL_TEST_CERT */
  16367. #ifdef WOLFSSL_CUSTOM_OID
  16368. /* TODO: Add test case for custom OID's */
  16369. #endif
  16370. }
  16371. #ifdef WOLFSSL_CERT_EXT
  16372. #if ((defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  16373. defined(WOLFSSL_TEST_CERT)) || defined(HAVE_ECC)
  16374. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage[] =
  16375. "digitalSignature,nonRepudiation";
  16376. #endif
  16377. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_ASN_TIME)
  16378. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage2[] =
  16379. "digitalSignature,nonRepudiation,keyEncipherment,keyAgreement";
  16380. #endif
  16381. #endif /* WOLFSSL_CERT_EXT */
  16382. #endif /* WOLFSSL_CERT_GEN */
  16383. #ifndef NO_RSA
  16384. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16385. !defined(NO_FILESYSTEM)
  16386. static const byte minSerial[] = { 0x02, 0x01, 0x01 };
  16387. static const byte minName[] = { 0x30, 0x00 };
  16388. static const byte nameBad[] = {
  16389. 0x30, 0x08,
  16390. 0x31, 0x06,
  16391. 0x30, 0x04,
  16392. 0x06, 0x02,
  16393. 0x55, 0x04,
  16394. };
  16395. static const byte minDates[] = {
  16396. 0x30, 0x1e,
  16397. 0x17, 0x0d,
  16398. 0x31, 0x38, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35,
  16399. 0x32, 0x33, 0x31, 0x30, 0x5a,
  16400. 0x17, 0x0d,
  16401. 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x31, 0x35,
  16402. 0x32, 0x33, 0x31, 0x30, 0x5a
  16403. };
  16404. static const byte minPubKey[] = {
  16405. 0x30, 0x1c,
  16406. 0x30, 0x0d,
  16407. 0x06, 0x09,
  16408. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16409. 0x01,
  16410. 0x05, 0x00,
  16411. 0x03, 0x0b,
  16412. 0x00, 0x30, 0x08,
  16413. 0x02, 0x01,
  16414. 0x03,
  16415. 0x02, 0x03,
  16416. 0x01, 0x00, 0x01
  16417. };
  16418. static const byte minSigAlg[] = {
  16419. 0x30, 0x0d,
  16420. 0x06, 0x09,
  16421. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16422. 0x0b,
  16423. 0x05, 0x00
  16424. };
  16425. static const byte minSig[] = {
  16426. 0x03, 0x01,
  16427. 0x00
  16428. };
  16429. static int add_seq(byte* certData, int offset, byte* data, byte length)
  16430. {
  16431. XMEMMOVE(certData + offset + 2, data, length);
  16432. certData[offset++] = 0x30;
  16433. certData[offset++] = length;
  16434. return offset + length;
  16435. }
  16436. static int add_data(byte* certData, int offset, const byte* data, byte length)
  16437. {
  16438. XMEMCPY(certData + offset, data, length);
  16439. return offset + length;
  16440. }
  16441. static wc_test_ret_t cert_asn1_test(void)
  16442. {
  16443. wc_test_ret_t ret;
  16444. int len[3];
  16445. DecodedCert cert;
  16446. byte certData[114];
  16447. byte* badCert = NULL;
  16448. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16449. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16450. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16451. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16452. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16453. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16454. len[1] = add_seq(certData, 0, certData, len[2]);
  16455. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16456. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16457. len[0] = add_seq(certData, 0, certData, len[1]);
  16458. /* Minimal good certificate */
  16459. InitDecodedCert(&cert, certData, len[0], 0);
  16460. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16461. FreeDecodedCert(&cert);
  16462. if (ret != 0)
  16463. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16464. /* Bad issuer name */
  16465. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16466. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16467. len[2] = add_data(certData, len[2], nameBad, (byte)sizeof(nameBad));
  16468. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16469. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16470. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16471. len[1] = add_seq(certData, 0, certData, len[2]);
  16472. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16473. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16474. len[0] = add_seq(certData, 0, certData, len[1]);
  16475. /* Put data into allocated buffer to allow access error checking. */
  16476. badCert = (byte*)XMALLOC(len[0], HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16477. XMEMCPY(badCert, certData, len[0]);
  16478. InitDecodedCert(&cert, badCert, len[0], 0);
  16479. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16480. FreeDecodedCert(&cert);
  16481. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  16482. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16483. }
  16484. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16485. badCert = NULL;
  16486. ret = 0;
  16487. done:
  16488. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16489. return ret;
  16490. }
  16491. static wc_test_ret_t cert_load_bad(const char* fname, byte* tmp, int err)
  16492. {
  16493. wc_test_ret_t ret;
  16494. DecodedCert cert;
  16495. XFILE file;
  16496. size_t bytes;
  16497. if ((fname == NULL) || (tmp == NULL)) {
  16498. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  16499. }
  16500. file = XFOPEN(fname, "rb");
  16501. if (!file) {
  16502. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16503. }
  16504. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16505. XFCLOSE(file);
  16506. if (bytes == 0) {
  16507. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16508. }
  16509. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16510. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16511. FreeDecodedCert(&cert);
  16512. if (ret != err) {
  16513. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16514. }
  16515. ret = 0;
  16516. done:
  16517. return ret;
  16518. }
  16519. static wc_test_ret_t cert_bad_asn1_test(void)
  16520. {
  16521. wc_test_ret_t ret = 0;
  16522. byte* tmp;
  16523. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16524. if (tmp == NULL) {
  16525. ret = WC_TEST_RET_ENC_ERRNO;
  16526. }
  16527. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16528. if (ret == 0) {
  16529. /* Serial number: 0xff 0xa8. 0xff and top bit set on next byte invalid.
  16530. */
  16531. ret = cert_load_bad(certBadNegInt, tmp, ASN_EXPECT_0_E);
  16532. }
  16533. #endif
  16534. if (ret == 0) {
  16535. /* Subject name OID: 55 04 f4. Last byte with top bit set invalid. */
  16536. ret = cert_load_bad(certBadOid, tmp, ASN_PARSE_E);
  16537. }
  16538. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16539. if (ret == 0) {
  16540. /* Issuer name UTF8STRING: df 52 4e 44. Top bit of second byte not set.
  16541. */
  16542. ret = cert_load_bad(certBadUtf8, tmp, ASN_PARSE_E);
  16543. }
  16544. #endif
  16545. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16546. return ret;
  16547. }
  16548. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void)
  16549. {
  16550. #if !defined(NO_FILESYSTEM)
  16551. DecodedCert cert;
  16552. byte* tmp;
  16553. size_t bytes;
  16554. XFILE file;
  16555. wc_test_ret_t ret;
  16556. WOLFSSL_ENTER("cert_test");
  16557. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16558. if (tmp == NULL)
  16559. return WC_TEST_RET_ENC_ERRNO;
  16560. /* Certificate with Name Constraints extension. */
  16561. file = XFOPEN(certExtNc, "rb");
  16562. if (!file) {
  16563. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16564. }
  16565. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16566. XFCLOSE(file);
  16567. if (bytes == 0)
  16568. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16569. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16570. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16571. if (ret != 0)
  16572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16573. FreeDecodedCert(&cert);
  16574. /* Certificate with Inhibit Any Policy extension. */
  16575. file = XFOPEN(certExtIa, "rb");
  16576. if (!file) {
  16577. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16578. }
  16579. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16580. XFCLOSE(file);
  16581. if (bytes == 0)
  16582. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16583. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16584. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16585. if (ret != 0)
  16586. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16587. FreeDecodedCert(&cert);
  16588. /* Certificate with Netscape Certificate Type extension. */
  16589. file = XFOPEN(certExtNct, "rb");
  16590. if (!file) {
  16591. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16592. }
  16593. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16594. XFCLOSE(file);
  16595. if (bytes == 0)
  16596. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16597. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16598. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16599. #ifndef IGNORE_NETSCAPE_CERT_TYPE
  16600. if (ret != 0)
  16601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16602. #else
  16603. if (ret != WC_NO_ERR_TRACE(ASN_CRIT_EXT_E)) {
  16604. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16605. }
  16606. ret = 0;
  16607. #endif
  16608. done:
  16609. FreeDecodedCert(&cert);
  16610. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16611. #endif /* !NO_FILESYSTEM */
  16612. if (ret == 0)
  16613. ret = cert_asn1_test();
  16614. if (ret == 0)
  16615. ret = cert_bad_asn1_test();
  16616. return ret;
  16617. }
  16618. #endif /* WOLFSSL_TEST_CERT */
  16619. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  16620. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  16621. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void)
  16622. {
  16623. DecodedCert cert;
  16624. byte* tmp;
  16625. size_t bytes;
  16626. XFILE file;
  16627. wc_test_ret_t ret;
  16628. /* created from rsa_test : othercert.der */
  16629. byte skid_rsa[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16630. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16631. /* created from rsa_test : othercert.der */
  16632. byte akid_rsa[] = "\x27\x8E\x67\x11\x74\xC3\x26\x1D\x3F\xED"
  16633. "\x33\x63\xB3\xA4\xD8\x1D\x30\xE5\xE8\xD5";
  16634. #ifdef HAVE_ECC
  16635. /* created from ecc_test_cert_gen : certecc.der */
  16636. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16637. /* Authority key id from ./certs/ca-ecc384-cert.pem */
  16638. byte akid_ecc[] = "\xAB\xE0\xC3\x26\x4C\x18\xD4\x72\xBB\xD2"
  16639. "\x84\x8C\x9C\x0A\x05\x92\x80\x12\x53\x52";
  16640. #else
  16641. /* Authority key id from ./certs/ca-ecc-cert.pem */
  16642. byte akid_ecc[] = "\x56\x8E\x9A\xC3\xF0\x42\xDE\x18\xB9\x45"
  16643. "\x55\x6E\xF9\x93\xCF\xEA\xC3\xF3\xA5\x21";
  16644. #endif
  16645. #endif /* HAVE_ECC */
  16646. /* created from rsa_test : cert.der */
  16647. byte kid_ca[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16648. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16649. WOLFSSL_ENTER("certext_test");
  16650. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16651. if (tmp == NULL)
  16652. return WC_TEST_RET_ENC_ERRNO;
  16653. /* load othercert.der (Cert signed by an authority) */
  16654. file = XFOPEN(otherCertDerFile, "rb");
  16655. if (!file) {
  16656. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16657. return WC_TEST_RET_ENC_ERRNO;
  16658. }
  16659. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16660. XFCLOSE(file);
  16661. if (bytes == 0)
  16662. return WC_TEST_RET_ENC_ERRNO;
  16663. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16664. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16665. if (ret != 0)
  16666. return WC_TEST_RET_ENC_EC(ret);
  16667. /* check the SKID from a RSA certificate */
  16668. if ((sizeof(skid_rsa) - 1 != cert.extSubjKeyIdSz) ||
  16669. (XMEMCMP(skid_rsa, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16670. return WC_TEST_RET_ENC_NC;
  16671. /* check the AKID from an RSA certificate */
  16672. if ((sizeof(akid_rsa) - 1 != cert.extAuthKeyIdSz) ||
  16673. (XMEMCMP(akid_rsa, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16674. return WC_TEST_RET_ENC_NC;
  16675. /* check the Key Usage from an RSA certificate */
  16676. if (!cert.extKeyUsageSet)
  16677. return WC_TEST_RET_ENC_NC;
  16678. if (cert.extKeyUsage != (KEYUSE_KEY_ENCIPHER|KEYUSE_KEY_AGREE))
  16679. return WC_TEST_RET_ENC_NC;
  16680. /* check the CA Basic Constraints from an RSA certificate */
  16681. if (cert.isCA)
  16682. return WC_TEST_RET_ENC_NC;
  16683. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16684. /* check the Certificate Policies Id */
  16685. if (cert.extCertPoliciesNb != 1)
  16686. return WC_TEST_RET_ENC_NC;
  16687. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16688. return WC_TEST_RET_ENC_NC;
  16689. #endif
  16690. FreeDecodedCert(&cert);
  16691. #ifdef HAVE_ECC
  16692. /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */
  16693. file = XFOPEN(certEccDerFile, "rb");
  16694. if (!file) {
  16695. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16696. return WC_TEST_RET_ENC_ERRNO;
  16697. }
  16698. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16699. XFCLOSE(file);
  16700. if (bytes == 0)
  16701. return WC_TEST_RET_ENC_ERRNO;
  16702. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16703. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16704. if (ret != 0)
  16705. return WC_TEST_RET_ENC_EC(ret);
  16706. /* check the SKID from a ECC certificate - generated dynamically */
  16707. /* check the AKID from an ECC certificate */
  16708. if ((sizeof(akid_ecc) - 1 != cert.extAuthKeyIdSz) ||
  16709. (XMEMCMP(akid_ecc, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16710. return WC_TEST_RET_ENC_NC;
  16711. /* check the Key Usage from an ECC certificate */
  16712. if (!cert.extKeyUsageSet)
  16713. return WC_TEST_RET_ENC_NC;
  16714. if (cert.extKeyUsage != (KEYUSE_DIGITAL_SIG|KEYUSE_CONTENT_COMMIT))
  16715. return WC_TEST_RET_ENC_NC;
  16716. /* check the CA Basic Constraints from an ECC certificate */
  16717. if (cert.isCA)
  16718. return WC_TEST_RET_ENC_NC;
  16719. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16720. /* check the Certificate Policies Id */
  16721. if (cert.extCertPoliciesNb != 2)
  16722. return WC_TEST_RET_ENC_NC;
  16723. if (strncmp(cert.extCertPolicies[0], "2.4.589440.587.101.2.1.9632587.1", 32))
  16724. return WC_TEST_RET_ENC_NC;
  16725. if (strncmp(cert.extCertPolicies[1], "1.2.13025.489.1.113549", 22))
  16726. return WC_TEST_RET_ENC_NC;
  16727. #endif
  16728. FreeDecodedCert(&cert);
  16729. #endif /* HAVE_ECC */
  16730. /* load cert.der (self signed certificate) */
  16731. file = XFOPEN(certDerFile, "rb");
  16732. if (!file) {
  16733. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16734. return WC_TEST_RET_ENC_ERRNO;
  16735. }
  16736. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16737. XFCLOSE(file);
  16738. if (bytes == 0)
  16739. return WC_TEST_RET_ENC_ERRNO;
  16740. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16741. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16742. if (ret != 0)
  16743. return WC_TEST_RET_ENC_EC(ret);
  16744. /* check the SKID from a CA certificate */
  16745. if ((sizeof(kid_ca) - 1 != cert.extSubjKeyIdSz) ||
  16746. (XMEMCMP(kid_ca, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16747. return WC_TEST_RET_ENC_NC;
  16748. /* check the AKID from an CA certificate */
  16749. if ((sizeof(kid_ca) - 1 != cert.extAuthKeyIdSz) ||
  16750. (XMEMCMP(kid_ca, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16751. return WC_TEST_RET_ENC_NC;
  16752. /* check the Key Usage from CA certificate */
  16753. if (!cert.extKeyUsageSet)
  16754. return WC_TEST_RET_ENC_NC;
  16755. if (cert.extKeyUsage != (KEYUSE_KEY_CERT_SIGN|KEYUSE_CRL_SIGN))
  16756. return WC_TEST_RET_ENC_NC;
  16757. /* check the CA Basic Constraints CA certificate */
  16758. if (!cert.isCA)
  16759. return WC_TEST_RET_ENC_NC;
  16760. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16761. /* check the Certificate Policies Id */
  16762. if (cert.extCertPoliciesNb != 2)
  16763. return WC_TEST_RET_ENC_NC;
  16764. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16765. return WC_TEST_RET_ENC_NC;
  16766. if (strncmp(cert.extCertPolicies[1], "1.2.840.113549.1.9.16.6.5", 25))
  16767. return WC_TEST_RET_ENC_NC;
  16768. #endif
  16769. FreeDecodedCert(&cert);
  16770. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16771. return 0;
  16772. }
  16773. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_TEST_CERT &&
  16774. !NO_FILESYSTEM && !NO_RSA && WOLFSSL_CERT_GEN */
  16775. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  16776. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  16777. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void)
  16778. {
  16779. wc_test_ret_t ret = 0;
  16780. Cert cert;
  16781. FILE* file;
  16782. byte* der;
  16783. word32 derSz;
  16784. WOLFSSL_ENTER("decodedCertCache_test");
  16785. derSz = FOURK_BUF;
  16786. der = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16787. if (der == NULL)
  16788. ret = WC_TEST_RET_ENC_NC;
  16789. if (ret == 0) {
  16790. /* load cert.der */
  16791. file = XFOPEN(certDerFile, "rb");
  16792. if (file != NULL) {
  16793. derSz = (word32)XFREAD(der, 1, FOURK_BUF, file);
  16794. XFCLOSE(file);
  16795. if (derSz == 0)
  16796. ret = WC_TEST_RET_ENC_ERRNO;
  16797. }
  16798. else
  16799. ret = WC_TEST_RET_ENC_ERRNO;
  16800. }
  16801. if (ret == 0) {
  16802. ret = wc_InitCert_ex(&cert, HEAP_HINT, devId);
  16803. if (ret != 0)
  16804. ret = WC_TEST_RET_ENC_EC(ret);
  16805. }
  16806. if (ret == 0) {
  16807. ret = wc_SetSubjectBuffer(&cert, der, derSz);
  16808. if (ret != 0)
  16809. ret = WC_TEST_RET_ENC_EC(ret);
  16810. }
  16811. if (ret == 0) {
  16812. ret = wc_SetSubjectBuffer(NULL, der, derSz);
  16813. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16814. ret = 0;
  16815. else
  16816. ret = WC_TEST_RET_ENC_EC(ret);
  16817. }
  16818. if (ret == 0) {
  16819. ret = wc_SetSubjectRaw(&cert, der, derSz);
  16820. if (ret != 0)
  16821. ret = WC_TEST_RET_ENC_EC(ret);
  16822. }
  16823. if (ret == 0) {
  16824. ret = wc_SetSubjectRaw(NULL, der, derSz);
  16825. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16826. ret = 0;
  16827. else
  16828. ret = WC_TEST_RET_ENC_EC(ret);
  16829. }
  16830. if (ret == 0) {
  16831. ret = wc_SetIssuerBuffer(&cert, der, derSz);
  16832. if (ret != 0)
  16833. ret = WC_TEST_RET_ENC_EC(ret);
  16834. }
  16835. if (ret == 0) {
  16836. ret = wc_SetIssuerBuffer(NULL, der, derSz);
  16837. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16838. ret = 0;
  16839. else
  16840. ret = WC_TEST_RET_ENC_EC(ret);
  16841. }
  16842. if (ret == 0) {
  16843. ret = wc_SetIssuerRaw(&cert, der, derSz);
  16844. if (ret != 0)
  16845. ret = WC_TEST_RET_ENC_EC(ret);
  16846. }
  16847. if (ret == 0) {
  16848. ret = wc_SetIssuerRaw(NULL, der, derSz);
  16849. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16850. ret = 0;
  16851. else
  16852. ret = WC_TEST_RET_ENC_EC(ret);
  16853. }
  16854. #ifdef WOLFSSL_ALT_NAMES
  16855. if (ret == 0) {
  16856. ret = wc_SetAltNamesBuffer(&cert, der, derSz);
  16857. if (ret != 0)
  16858. ret = WC_TEST_RET_ENC_EC(ret);
  16859. }
  16860. if (ret == 0) {
  16861. ret = wc_SetAltNamesBuffer(NULL, der, derSz);
  16862. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16863. ret = 0;
  16864. else
  16865. ret = WC_TEST_RET_ENC_EC(ret);
  16866. }
  16867. if (ret == 0) {
  16868. ret = wc_SetDatesBuffer(&cert, der, derSz);
  16869. if (ret != 0)
  16870. ret = WC_TEST_RET_ENC_EC(ret);
  16871. }
  16872. if (ret == 0) {
  16873. ret = wc_SetDatesBuffer(NULL, der, derSz);
  16874. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16875. ret = 0;
  16876. else
  16877. ret = WC_TEST_RET_ENC_EC(ret);
  16878. }
  16879. #endif
  16880. if (ret == 0) {
  16881. ret = wc_SetAuthKeyIdFromCert(&cert, der, derSz);
  16882. if (ret != 0)
  16883. ret = WC_TEST_RET_ENC_EC(ret);
  16884. }
  16885. if (ret == 0) {
  16886. ret = wc_SetAuthKeyIdFromCert(NULL, der, derSz);
  16887. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16888. ret = 0;
  16889. else
  16890. ret = WC_TEST_RET_ENC_NC;
  16891. }
  16892. wc_SetCert_Free(&cert);
  16893. if (ret == 0) {
  16894. if(cert.decodedCert != NULL)
  16895. ret = WC_TEST_RET_ENC_NC;
  16896. }
  16897. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16898. return ret;
  16899. }
  16900. #endif /* defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) &&
  16901. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) */
  16902. #define RSA_TEST_BYTES 512 /* up to 4096-bit key */
  16903. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  16904. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16905. static wc_test_ret_t rsa_flatten_test(RsaKey* key)
  16906. {
  16907. wc_test_ret_t ret;
  16908. byte e[RSA_TEST_BYTES];
  16909. byte n[RSA_TEST_BYTES];
  16910. word32 eSz = sizeof(e);
  16911. word32 nSz = sizeof(n);
  16912. /* Parameter Validation testing. */
  16913. ret = wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz);
  16914. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16915. return WC_TEST_RET_ENC_EC(ret);
  16916. ret = wc_RsaFlattenPublicKey(key, NULL, &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, e, NULL, 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, &eSz, NULL, &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, n, NULL);
  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, &nSz);
  16929. if (ret != 0)
  16930. return WC_TEST_RET_ENC_EC(ret);
  16931. eSz = 0;
  16932. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16933. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16934. return WC_TEST_RET_ENC_EC(ret);
  16935. eSz = sizeof(e);
  16936. nSz = 0;
  16937. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16938. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16939. return WC_TEST_RET_ENC_EC(ret);
  16940. return 0;
  16941. }
  16942. #endif /* NO_ASN */
  16943. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  16944. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16945. static wc_test_ret_t rsa_export_key_test(RsaKey* key)
  16946. {
  16947. wc_test_ret_t ret;
  16948. byte e[3];
  16949. word32 eSz = sizeof(e);
  16950. byte n[RSA_TEST_BYTES];
  16951. word32 nSz = sizeof(n);
  16952. byte d[RSA_TEST_BYTES];
  16953. word32 dSz = sizeof(d);
  16954. byte p[RSA_TEST_BYTES/2];
  16955. word32 pSz = sizeof(p);
  16956. byte q[RSA_TEST_BYTES/2];
  16957. word32 qSz = sizeof(q);
  16958. word32 zero = 0;
  16959. ret = wc_RsaExportKey(NULL, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16960. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16961. return WC_TEST_RET_ENC_EC(ret);
  16962. ret = wc_RsaExportKey(key, NULL, &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, e, NULL, 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, &eSz, NULL, &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, n, NULL, 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, &nSz, NULL, &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, d, NULL, 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, &dSz, NULL, &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, p, NULL, 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, &pSz, NULL, &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, q, NULL);
  16990. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16991. return WC_TEST_RET_ENC_EC(ret);
  16992. ret = wc_RsaExportKey(key, e, &zero, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16993. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16994. return WC_TEST_RET_ENC_EC(ret);
  16995. ret = wc_RsaExportKey(key, e, &eSz, n, &zero, 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. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  16999. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &zero, p, &pSz, q, &qSz);
  17000. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17001. return WC_TEST_RET_ENC_EC(ret);
  17002. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &zero, 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, &pSz, q, &zero);
  17006. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17007. return WC_TEST_RET_ENC_EC(ret);
  17008. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  17009. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  17010. if (ret != 0)
  17011. return WC_TEST_RET_ENC_EC(ret);
  17012. return 0;
  17013. }
  17014. #endif /* !HAVE_FIPS && !NO_ASN && !WOLFSSL_RSA_VERIFY_ONLY */
  17015. #ifndef NO_SIG_WRAPPER
  17016. static wc_test_ret_t rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng)
  17017. {
  17018. wc_test_ret_t ret;
  17019. word32 sigSz;
  17020. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  17021. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  17022. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17023. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17024. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17025. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17026. };
  17027. WOLFSSL_SMALL_STACK_STATIC const byte hashEnc[] = {
  17028. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  17029. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  17030. 0x00, 0x04, 0x20,
  17031. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17032. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17033. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17034. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17035. };
  17036. word32 inLen = (word32)XSTRLEN((char*)in);
  17037. byte out[RSA_TEST_BYTES];
  17038. /* Parameter Validation testing. */
  17039. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_NONE, key, keyLen);
  17040. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17041. return WC_TEST_RET_ENC_EC(ret);
  17042. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, 0);
  17043. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17044. return WC_TEST_RET_ENC_EC(ret);
  17045. sigSz = (word32)modLen;
  17046. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17047. inLen, out, &sigSz, key, keyLen, rng);
  17048. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17049. return WC_TEST_RET_ENC_EC(ret);
  17050. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17051. 0, out, &sigSz, key, keyLen, rng);
  17052. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17053. return WC_TEST_RET_ENC_EC(ret);
  17054. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17055. inLen, NULL, &sigSz, key, keyLen, rng);
  17056. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17057. return WC_TEST_RET_ENC_EC(ret);
  17058. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17059. inLen, out, NULL, key, keyLen, rng);
  17060. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17061. return WC_TEST_RET_ENC_EC(ret);
  17062. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17063. inLen, out, &sigSz, NULL, keyLen, rng);
  17064. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17065. return WC_TEST_RET_ENC_EC(ret);
  17066. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17067. inLen, out, &sigSz, key, 0, rng);
  17068. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17069. return WC_TEST_RET_ENC_EC(ret);
  17070. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17071. inLen, out, &sigSz, key, keyLen, NULL);
  17072. #if defined(WOLFSSL_AFALG_XILINX_RSA) || defined(WOLFSSL_XILINX_CRYPT)
  17073. /* blinding / rng handled with hardware acceleration */
  17074. if (ret != 0)
  17075. #elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
  17076. /* async may not require RNG */
  17077. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17078. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID))
  17079. #else
  17080. if (ret != 0 && ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17081. #endif
  17082. #elif defined(HAVE_FIPS) || !defined(WC_RSA_BLINDING)
  17083. /* FIPS140 implementation does not do blinding */
  17084. if (ret != 0)
  17085. #elif defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY)
  17086. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17087. #elif defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SE050)
  17088. /* RNG is handled by hardware */
  17089. if (ret != 0)
  17090. #else
  17091. if (ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17092. #endif
  17093. return WC_TEST_RET_ENC_EC(ret);
  17094. sigSz = 0;
  17095. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17096. inLen, out, &sigSz, key, keyLen, rng);
  17097. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17098. return WC_TEST_RET_ENC_EC(ret);
  17099. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17100. inLen, out, (word32)modLen, key, keyLen);
  17101. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17102. return WC_TEST_RET_ENC_EC(ret);
  17103. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17104. 0, out, (word32)modLen, key, keyLen);
  17105. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17106. return WC_TEST_RET_ENC_EC(ret);
  17107. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17108. inLen, NULL, (word32)modLen, key, keyLen);
  17109. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17110. return WC_TEST_RET_ENC_EC(ret);
  17111. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17112. inLen, out, 0, key, keyLen);
  17113. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17114. return WC_TEST_RET_ENC_EC(ret);
  17115. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17116. inLen, out, (word32)modLen, NULL, keyLen);
  17117. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17118. return WC_TEST_RET_ENC_EC(ret);
  17119. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17120. inLen, out, (word32)modLen, key, 0);
  17121. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17122. return WC_TEST_RET_ENC_EC(ret);
  17123. #ifndef HAVE_ECC
  17124. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, keyLen);
  17125. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17126. return WC_TEST_RET_ENC_EC(ret);
  17127. #endif
  17128. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17129. return 0;
  17130. #endif
  17131. /* Use APIs. */
  17132. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, keyLen);
  17133. if (ret != modLen)
  17134. return WC_TEST_RET_ENC_EC(ret);
  17135. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA_W_ENC, key, keyLen);
  17136. if (ret != modLen)
  17137. return WC_TEST_RET_ENC_EC(ret);
  17138. sigSz = (word32)ret;
  17139. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  17140. XMEMSET(out, 0, sizeof(out));
  17141. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17142. inLen, out, &sigSz, key, keyLen, rng);
  17143. if (ret != 0)
  17144. return WC_TEST_RET_ENC_EC(ret);
  17145. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17146. inLen, out, (word32)modLen, key, keyLen);
  17147. if (ret != 0)
  17148. return WC_TEST_RET_ENC_EC(ret);
  17149. sigSz = (word32)sizeof(out);
  17150. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17151. in, inLen, out, &sigSz, key, keyLen, rng);
  17152. if (ret != 0)
  17153. return WC_TEST_RET_ENC_EC(ret);
  17154. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17155. in, inLen, out, (word32)modLen, key, keyLen);
  17156. if (ret != 0)
  17157. return WC_TEST_RET_ENC_EC(ret);
  17158. /* Wrong signature type. */
  17159. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17160. inLen, out, (word32)modLen, key, keyLen);
  17161. if (ret == 0)
  17162. return WC_TEST_RET_ENC_EC(ret);
  17163. /* check hash functions */
  17164. sigSz = (word32)sizeof(out);
  17165. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17166. hash, (int)sizeof(hash), out, &sigSz, key, keyLen, rng);
  17167. if (ret != 0)
  17168. return WC_TEST_RET_ENC_EC(ret);
  17169. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17170. hash, (int)sizeof(hash), out, (word32)modLen, key, keyLen);
  17171. if (ret != 0)
  17172. return WC_TEST_RET_ENC_EC(ret);
  17173. sigSz = (word32)sizeof(out);
  17174. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17175. hashEnc, (int)sizeof(hashEnc), out, &sigSz, key, keyLen, rng);
  17176. if (ret != 0)
  17177. return WC_TEST_RET_ENC_EC(ret);
  17178. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17179. hashEnc, (int)sizeof(hashEnc), out, (word32)modLen, key, keyLen);
  17180. if (ret != 0)
  17181. return WC_TEST_RET_ENC_EC(ret);
  17182. #else
  17183. (void)hash;
  17184. (void)hashEnc;
  17185. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  17186. return 0;
  17187. }
  17188. #endif /* !NO_SIG_WRAPPER */
  17189. #ifdef WC_RSA_NONBLOCK
  17190. static wc_test_ret_t rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out,
  17191. word32 outSz, byte* plain, word32 plainSz, WC_RNG* rng)
  17192. {
  17193. wc_test_ret_t ret = 0;
  17194. int count;
  17195. int signSz = 0;
  17196. RsaNb nb;
  17197. byte* inlinePlain = NULL;
  17198. /* Enable non-blocking RSA mode - provide context */
  17199. ret = wc_RsaSetNonBlock(key, &nb);
  17200. if (ret != 0)
  17201. return ret;
  17202. #ifdef WC_RSA_NONBLOCK_TIME
  17203. /* Enable time based RSA blocking. 8 microseconds max (3.1GHz) */
  17204. ret = wc_RsaSetNonBlockTime(key, 8, 3100);
  17205. if (ret != 0)
  17206. return ret;
  17207. #endif
  17208. count = 0;
  17209. do {
  17210. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, rng);
  17211. count++; /* track number of would blocks */
  17212. if (ret == FP_WOULDBLOCK) {
  17213. /* do "other" work here */
  17214. }
  17215. } while (ret == FP_WOULDBLOCK);
  17216. if (ret < 0) {
  17217. return ret;
  17218. }
  17219. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17220. printf("RSA non-block sign: %d times\n", count);
  17221. #endif
  17222. signSz = ret;
  17223. /* Test non-blocking verify */
  17224. XMEMSET(plain, 0, plainSz);
  17225. count = 0;
  17226. do {
  17227. ret = wc_RsaSSL_Verify(out, (word32)signSz, plain, plainSz, key);
  17228. count++; /* track number of would blocks */
  17229. if (ret == FP_WOULDBLOCK) {
  17230. /* do "other" work here */
  17231. }
  17232. } while (ret == FP_WOULDBLOCK);
  17233. if (ret < 0) {
  17234. return ret;
  17235. }
  17236. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17237. printf("RSA non-block verify: %d times\n", count);
  17238. #endif
  17239. if (signSz == ret && XMEMCMP(plain, in, (size_t)ret)) {
  17240. return SIG_VERIFY_E;
  17241. }
  17242. /* Test inline non-blocking verify */
  17243. count = 0;
  17244. do {
  17245. ret = wc_RsaSSL_VerifyInline(out, (word32)signSz, &inlinePlain, key);
  17246. count++; /* track number of would blocks */
  17247. if (ret == FP_WOULDBLOCK) {
  17248. /* do "other" work here */
  17249. }
  17250. } while (ret == FP_WOULDBLOCK);
  17251. if (ret < 0) {
  17252. return ret;
  17253. }
  17254. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17255. printf("RSA non-block inline verify: %d times\n", count);
  17256. #endif
  17257. if (signSz == ret && XMEMCMP(inlinePlain, in, (size_t)ret)) {
  17258. return SIG_VERIFY_E;
  17259. }
  17260. /* Disabling non-block RSA mode */
  17261. ret = wc_RsaSetNonBlock(key, NULL);
  17262. (void)count;
  17263. return 0;
  17264. }
  17265. #endif
  17266. #if !defined(NO_ASN)
  17267. static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
  17268. {
  17269. wc_test_ret_t ret;
  17270. word32 inSz;
  17271. word32 inOutIdx;
  17272. WOLFSSL_SMALL_STACK_STATIC const byte n[2] = { 0x00, 0x23 };
  17273. WOLFSSL_SMALL_STACK_STATIC const byte e[2] = { 0x00, 0x03 };
  17274. WOLFSSL_SMALL_STACK_STATIC const byte good[] = { 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1,
  17275. 0x03 };
  17276. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgId[] = {
  17277. 0x30, 0x18, 0x30, 0x16,
  17278. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17279. 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17280. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgIdNull[] = {
  17281. 0x30, 0x1a, 0x30, 0x18,
  17282. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17283. 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17284. 0x02, 0x1, 0x03 };
  17285. WOLFSSL_SMALL_STACK_STATIC const byte badAlgIdNull[] = {
  17286. 0x30, 0x1b, 0x30, 0x19,
  17287. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17288. 0x05, 0x01, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17289. 0x02, 0x1, 0x03 };
  17290. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitString[] = {
  17291. 0x30, 0x18, 0x30, 0x16,
  17292. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17293. 0x04, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17294. WOLFSSL_SMALL_STACK_STATIC const byte badBitStringLen[] = {
  17295. 0x30, 0x18, 0x30, 0x16,
  17296. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17297. 0x03, 0x0a, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17298. WOLFSSL_SMALL_STACK_STATIC const byte badNoSeq[] = {
  17299. 0x30, 0x16, 0x30, 0x14,
  17300. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17301. 0x07, 0x00, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17302. WOLFSSL_SMALL_STACK_STATIC const byte badNoObj[] = {
  17303. 0x30, 0x0f, 0x30, 0x0d, 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06,
  17304. 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17305. WOLFSSL_SMALL_STACK_STATIC const byte badIntN[] = {
  17306. 0x30, 0x06, 0x02, 0x05, 0x23, 0x02, 0x1, 0x03 };
  17307. WOLFSSL_SMALL_STACK_STATIC const byte badNotIntE[] = {
  17308. 0x30, 0x06, 0x02, 0x01, 0x23, 0x04, 0x1, 0x03 };
  17309. WOLFSSL_SMALL_STACK_STATIC const byte badLength[] = {
  17310. 0x30, 0x04, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17311. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrNoZero[] = {
  17312. 0x30, 0x17, 0x30, 0x15,
  17313. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17314. 0x03, 0x08, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17315. ret = wc_InitRsaKey(keyPub, NULL);
  17316. if (ret != 0)
  17317. return WC_TEST_RET_ENC_EC(ret);
  17318. /* Parameter Validation testing. */
  17319. ret = wc_RsaPublicKeyDecodeRaw(NULL, sizeof(n), e, sizeof(e), keyPub);
  17320. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17321. ret = WC_TEST_RET_ENC_EC(ret);
  17322. goto done;
  17323. }
  17324. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), NULL, sizeof(e), keyPub);
  17325. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17326. ret = WC_TEST_RET_ENC_EC(ret);
  17327. goto done;
  17328. }
  17329. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), NULL);
  17330. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17331. ret = WC_TEST_RET_ENC_EC(ret);
  17332. goto done;
  17333. }
  17334. ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub);
  17335. #if defined(USE_INTEGER_HEAP_MATH)
  17336. if (ret != 0)
  17337. #else
  17338. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17339. #endif
  17340. {
  17341. ret = WC_TEST_RET_ENC_EC(ret);
  17342. goto done;
  17343. }
  17344. wc_FreeRsaKey(keyPub);
  17345. ret = wc_InitRsaKey(keyPub, NULL);
  17346. if (ret != 0)
  17347. return WC_TEST_RET_ENC_EC(ret);
  17348. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub);
  17349. #if defined(USE_INTEGER_HEAP_MATH)
  17350. if (ret != 0)
  17351. #else
  17352. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17353. #endif
  17354. {
  17355. ret = WC_TEST_RET_ENC_EC(ret);
  17356. goto done;
  17357. }
  17358. wc_FreeRsaKey(keyPub);
  17359. ret = wc_InitRsaKey(keyPub, NULL);
  17360. if (ret != 0)
  17361. return WC_TEST_RET_ENC_EC(ret);
  17362. /* Use API. */
  17363. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), keyPub);
  17364. if (ret != 0) {
  17365. ret = WC_TEST_RET_ENC_EC(ret);
  17366. goto done;
  17367. }
  17368. wc_FreeRsaKey(keyPub);
  17369. ret = wc_InitRsaKey(keyPub, NULL);
  17370. if (ret != 0)
  17371. return WC_TEST_RET_ENC_EC(ret);
  17372. /* Parameter Validation testing. */
  17373. inSz = sizeof(good);
  17374. ret = wc_RsaPublicKeyDecode(NULL, &inOutIdx, keyPub, inSz);
  17375. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17376. ret = WC_TEST_RET_ENC_EC(ret);
  17377. goto done;
  17378. }
  17379. ret = wc_RsaPublicKeyDecode(good, NULL, keyPub, inSz);
  17380. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17381. ret = WC_TEST_RET_ENC_EC(ret);
  17382. goto done;
  17383. }
  17384. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  17385. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17386. ret = WC_TEST_RET_ENC_EC(ret);
  17387. goto done;
  17388. }
  17389. /* Use good data and offset to bad data. */
  17390. inOutIdx = 2;
  17391. inSz = sizeof(good) - inOutIdx;
  17392. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17393. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17394. ret = WC_TEST_RET_ENC_EC(ret);
  17395. goto done;
  17396. }
  17397. inOutIdx = 2;
  17398. inSz = sizeof(goodAlgId) - inOutIdx;
  17399. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17400. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17401. ret = WC_TEST_RET_ENC_EC(ret);
  17402. goto done;
  17403. }
  17404. inOutIdx = 2;
  17405. inSz = sizeof(goodAlgId);
  17406. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17407. #ifndef WOLFSSL_NO_DECODE_EXTRA
  17408. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17409. #else
  17410. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E))
  17411. #endif
  17412. {
  17413. ret = WC_TEST_RET_ENC_EC(ret);
  17414. goto done;
  17415. }
  17416. /* Try different bad data. */
  17417. inSz = sizeof(badAlgIdNull);
  17418. inOutIdx = 0;
  17419. ret = wc_RsaPublicKeyDecode(badAlgIdNull, &inOutIdx, keyPub, inSz);
  17420. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E)) {
  17421. ret = WC_TEST_RET_ENC_EC(ret);
  17422. goto done;
  17423. }
  17424. inSz = sizeof(badNotBitString);
  17425. inOutIdx = 0;
  17426. ret = wc_RsaPublicKeyDecode(badNotBitString, &inOutIdx, keyPub, inSz);
  17427. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E)) {
  17428. ret = WC_TEST_RET_ENC_EC(ret);
  17429. goto done;
  17430. }
  17431. inSz = sizeof(badBitStringLen);
  17432. inOutIdx = 0;
  17433. ret = wc_RsaPublicKeyDecode(badBitStringLen, &inOutIdx, keyPub, inSz);
  17434. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17435. ret = WC_TEST_RET_ENC_EC(ret);
  17436. goto done;
  17437. }
  17438. inSz = sizeof(badNoSeq);
  17439. inOutIdx = 0;
  17440. ret = wc_RsaPublicKeyDecode(badNoSeq, &inOutIdx, keyPub, inSz);
  17441. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17442. ret = WC_TEST_RET_ENC_EC(ret);
  17443. goto done;
  17444. }
  17445. inSz = sizeof(badNoObj);
  17446. inOutIdx = 0;
  17447. ret = wc_RsaPublicKeyDecode(badNoObj, &inOutIdx, keyPub, inSz);
  17448. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E) &&
  17449. ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E))
  17450. {
  17451. ret = WC_TEST_RET_ENC_EC(ret);
  17452. goto done;
  17453. }
  17454. inSz = sizeof(badIntN);
  17455. inOutIdx = 0;
  17456. ret = wc_RsaPublicKeyDecode(badIntN, &inOutIdx, keyPub, inSz);
  17457. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17458. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17459. {
  17460. ret = WC_TEST_RET_ENC_EC(ret);
  17461. goto done;
  17462. }
  17463. inSz = sizeof(badNotIntE);
  17464. inOutIdx = 0;
  17465. ret = wc_RsaPublicKeyDecode(badNotIntE, &inOutIdx, keyPub, inSz);
  17466. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17467. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17468. {
  17469. ret = WC_TEST_RET_ENC_EC(ret);
  17470. goto done;
  17471. }
  17472. /* TODO: Shouldn't pass as the sequence length is too small. */
  17473. inSz = sizeof(badLength);
  17474. inOutIdx = 0;
  17475. ret = wc_RsaPublicKeyDecode(badLength, &inOutIdx, keyPub, inSz);
  17476. #ifndef WOLFSSL_ASN_TEMPLATE
  17477. if (ret != 0)
  17478. #else
  17479. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17480. #endif
  17481. {
  17482. ret = WC_TEST_RET_ENC_EC(ret);
  17483. goto done;
  17484. }
  17485. /* TODO: Shouldn't ignore object id's data. */
  17486. wc_FreeRsaKey(keyPub);
  17487. ret = wc_InitRsaKey(keyPub, NULL);
  17488. if (ret != 0)
  17489. return WC_TEST_RET_ENC_EC(ret);
  17490. inSz = sizeof(badBitStrNoZero);
  17491. inOutIdx = 0;
  17492. ret = wc_RsaPublicKeyDecode(badBitStrNoZero, &inOutIdx, keyPub, inSz);
  17493. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  17494. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17495. {
  17496. ret = WC_TEST_RET_ENC_EC(ret);
  17497. goto done;
  17498. }
  17499. wc_FreeRsaKey(keyPub);
  17500. ret = wc_InitRsaKey(keyPub, NULL);
  17501. if (ret != 0)
  17502. return WC_TEST_RET_ENC_EC(ret);
  17503. /* Valid data cases. */
  17504. inSz = sizeof(good);
  17505. inOutIdx = 0;
  17506. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17507. if (ret != 0) {
  17508. ret = WC_TEST_RET_ENC_EC(ret);
  17509. goto done;
  17510. }
  17511. if (inOutIdx != inSz) {
  17512. ret = WC_TEST_RET_ENC_NC;
  17513. goto done;
  17514. }
  17515. wc_FreeRsaKey(keyPub);
  17516. ret = wc_InitRsaKey(keyPub, NULL);
  17517. if (ret != 0)
  17518. return WC_TEST_RET_ENC_EC(ret);
  17519. inSz = sizeof(goodAlgId);
  17520. inOutIdx = 0;
  17521. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17522. if (ret != 0) {
  17523. ret = WC_TEST_RET_ENC_EC(ret);
  17524. goto done;
  17525. }
  17526. if (inOutIdx != inSz) {
  17527. ret = WC_TEST_RET_ENC_NC;
  17528. goto done;
  17529. }
  17530. wc_FreeRsaKey(keyPub);
  17531. ret = wc_InitRsaKey(keyPub, NULL);
  17532. if (ret != 0)
  17533. return WC_TEST_RET_ENC_EC(ret);
  17534. inSz = sizeof(goodAlgIdNull);
  17535. inOutIdx = 0;
  17536. ret = wc_RsaPublicKeyDecode(goodAlgIdNull, &inOutIdx, keyPub, inSz);
  17537. if (ret != 0) {
  17538. ret = WC_TEST_RET_ENC_EC(ret);
  17539. goto done;
  17540. }
  17541. if (inOutIdx != inSz) {
  17542. ret = WC_TEST_RET_ENC_NC;
  17543. goto done;
  17544. }
  17545. done:
  17546. wc_FreeRsaKey(keyPub);
  17547. return ret;
  17548. }
  17549. #endif
  17550. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  17551. /* Need to create known good signatures to test with this. */
  17552. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  17553. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17554. static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key)
  17555. {
  17556. byte digest[WC_MAX_DIGEST_SIZE];
  17557. wc_test_ret_t ret = 0;
  17558. const char inStr[] = TEST_STRING;
  17559. word32 inLen = (word32)TEST_STRING_SZ;
  17560. word32 outSz;
  17561. word32 plainSz;
  17562. word32 digestSz;
  17563. int i, j;
  17564. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17565. int k, l;
  17566. #endif
  17567. #ifndef WOLFSSL_SE050
  17568. int len;
  17569. #endif
  17570. byte* plain;
  17571. int mgf[] = {
  17572. #ifndef NO_SHA
  17573. WC_MGF1SHA1,
  17574. #endif
  17575. #ifdef WOLFSSL_SHA224
  17576. WC_MGF1SHA224,
  17577. #endif
  17578. WC_MGF1SHA256,
  17579. #ifdef WOLFSSL_SHA384
  17580. WC_MGF1SHA384,
  17581. #endif
  17582. #ifdef WOLFSSL_SHA512
  17583. WC_MGF1SHA512
  17584. #endif
  17585. };
  17586. enum wc_HashType hash[] = {
  17587. #ifndef NO_SHA
  17588. WC_HASH_TYPE_SHA,
  17589. #endif
  17590. #ifdef WOLFSSL_SHA224
  17591. WC_HASH_TYPE_SHA224,
  17592. #endif
  17593. WC_HASH_TYPE_SHA256,
  17594. #ifdef WOLFSSL_SHA384
  17595. WC_HASH_TYPE_SHA384,
  17596. #endif
  17597. #ifdef WOLFSSL_SHA512
  17598. WC_HASH_TYPE_SHA512,
  17599. #endif
  17600. };
  17601. WC_DECLARE_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17602. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17603. WC_DECLARE_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17604. WC_ALLOC_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17605. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17606. WC_ALLOC_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17607. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17608. if (in == NULL || out == NULL || sig == NULL)
  17609. ERROR_OUT(MEMORY_E, exit_rsa_pss);
  17610. #endif
  17611. XMEMCPY(in, inStr, inLen);
  17612. /* Test all combinations of hash and MGF. */
  17613. for (j = 0; j < (int)(sizeof(hash)/sizeof(*hash)); j++) {
  17614. /* Calculate hash of message. */
  17615. ret = wc_Hash(hash[j], in, inLen, digest, sizeof(digest));
  17616. if (ret != 0)
  17617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17618. digestSz = (word32)wc_HashGetDigestSize(hash[j]);
  17619. #ifdef WOLFSSL_SE050
  17620. /* SE050 only supports MGF matched to same hash type */
  17621. i = j;
  17622. #else
  17623. for (i = 0; i < (int)(sizeof(mgf)/sizeof(*mgf)); i++) {
  17624. #endif
  17625. outSz = RSA_TEST_BYTES;
  17626. do {
  17627. #if defined(WOLFSSL_ASYNC_CRYPT)
  17628. ret = wc_AsyncWait(ret, &key->asyncDev,
  17629. WC_ASYNC_FLAG_CALL_AGAIN);
  17630. #endif
  17631. if (ret >= 0) {
  17632. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz,
  17633. hash[j], mgf[i], -1, key, rng);
  17634. }
  17635. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17636. if (ret <= 0)
  17637. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17638. outSz = (word32)ret;
  17639. XMEMCPY(sig, out, outSz);
  17640. plain = NULL;
  17641. TEST_SLEEP();
  17642. do {
  17643. #if defined(WOLFSSL_ASYNC_CRYPT)
  17644. ret = wc_AsyncWait(ret, &key->asyncDev,
  17645. WC_ASYNC_FLAG_CALL_AGAIN);
  17646. #endif
  17647. if (ret >= 0) {
  17648. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[j],
  17649. mgf[i], -1, key);
  17650. }
  17651. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17652. if (ret <= 0)
  17653. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17654. plainSz = (word32)ret;
  17655. TEST_SLEEP();
  17656. #if defined(HAVE_SELFTEST) && \
  17657. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17658. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17659. hash[j], -1);
  17660. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17661. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17662. hash[j], -1, 0);
  17663. #else
  17664. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz,
  17665. hash[j], -1, wc_RsaEncryptSize(key)*8, HEAP_HINT);
  17666. #endif
  17667. if (ret != 0)
  17668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17669. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17670. for (k = 0; k < (int)(sizeof(mgf)/sizeof(*mgf)); k++) {
  17671. for (l = 0; l < (int)(sizeof(hash)/sizeof(*hash)); l++) {
  17672. if (i == k && j == l)
  17673. continue;
  17674. XMEMCPY(sig, out, outSz);
  17675. do {
  17676. #if defined(WOLFSSL_ASYNC_CRYPT)
  17677. ret = wc_AsyncWait(ret, &key->asyncDev,
  17678. WC_ASYNC_FLAG_CALL_AGAIN);
  17679. #endif
  17680. if (ret >= 0) {
  17681. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz,
  17682. (byte**)&plain, hash[l], mgf[k], -1, key);
  17683. }
  17684. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17685. if (ret >= 0)
  17686. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17687. }
  17688. }
  17689. #endif
  17690. #ifndef WOLFSSL_SE050
  17691. } /* end mgf for loop */
  17692. #endif
  17693. }
  17694. /* SE050 generates salts internally only of hash length */
  17695. #ifndef WOLFSSL_SE050
  17696. /* Test that a salt length of zero works. */
  17697. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17698. outSz = RSA_TEST_BYTES;
  17699. do {
  17700. #if defined(WOLFSSL_ASYNC_CRYPT)
  17701. ret = wc_AsyncWait(ret, &key->asyncDev,
  17702. WC_ASYNC_FLAG_CALL_AGAIN);
  17703. #endif
  17704. if (ret >= 0) {
  17705. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17706. mgf[0], 0, key, rng);
  17707. }
  17708. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17709. if (ret <= 0)
  17710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17711. outSz = (word32)ret;
  17712. TEST_SLEEP();
  17713. do {
  17714. #if defined(WOLFSSL_ASYNC_CRYPT)
  17715. ret = wc_AsyncWait(ret, &key->asyncDev,
  17716. WC_ASYNC_FLAG_CALL_AGAIN);
  17717. #endif
  17718. if (ret >= 0) {
  17719. ret = wc_RsaPSS_Verify_ex(out, outSz, sig, outSz, hash[0], mgf[0],
  17720. 0, key);
  17721. }
  17722. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17723. if (ret <= 0)
  17724. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17725. plainSz = (word32)ret;
  17726. TEST_SLEEP();
  17727. do {
  17728. #if defined(WOLFSSL_ASYNC_CRYPT)
  17729. ret = wc_AsyncWait(ret, &key->asyncDev,
  17730. WC_ASYNC_FLAG_CALL_AGAIN);
  17731. #endif
  17732. if (ret >= 0) {
  17733. #if defined(HAVE_SELFTEST) && \
  17734. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17735. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17736. hash[0], 0);
  17737. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17738. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17739. hash[0], 0, 0);
  17740. #else
  17741. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, sig, plainSz,
  17742. hash[0], 0, 0, HEAP_HINT);
  17743. #endif
  17744. }
  17745. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17746. if (ret != 0)
  17747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17748. XMEMCPY(sig, out, outSz);
  17749. plain = NULL;
  17750. do {
  17751. #if defined(WOLFSSL_ASYNC_CRYPT)
  17752. ret = wc_AsyncWait(ret, &key->asyncDev,
  17753. WC_ASYNC_FLAG_CALL_AGAIN);
  17754. #endif
  17755. if (ret >= 0) {
  17756. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17757. 0, key);
  17758. }
  17759. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17760. if (ret <= 0)
  17761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17762. plainSz = (word32)ret;
  17763. TEST_SLEEP();
  17764. #if defined(HAVE_SELFTEST) && \
  17765. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17766. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17767. hash[0], 0);
  17768. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17769. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17770. hash[0], 0, 0);
  17771. #else
  17772. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17773. 0, 0, HEAP_HINT);
  17774. #endif
  17775. if (ret != 0)
  17776. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17777. /* Test bad salt lengths in various APIs. */
  17778. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17779. outSz = RSA_TEST_BYTES;
  17780. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17781. len = -2;
  17782. #else
  17783. len = -3;
  17784. #endif
  17785. do {
  17786. #if defined(WOLFSSL_ASYNC_CRYPT)
  17787. ret = wc_AsyncWait(ret, &key->asyncDev,
  17788. WC_ASYNC_FLAG_CALL_AGAIN);
  17789. #endif
  17790. if (ret >= 0) {
  17791. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17792. mgf[0], len, key, rng);
  17793. }
  17794. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17795. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17797. do {
  17798. #if defined(WOLFSSL_ASYNC_CRYPT)
  17799. ret = wc_AsyncWait(ret, &key->asyncDev,
  17800. WC_ASYNC_FLAG_CALL_AGAIN);
  17801. #endif
  17802. if (ret >= 0) {
  17803. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17804. mgf[0], (int)digestSz + 1, key, rng);
  17805. }
  17806. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17807. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17809. TEST_SLEEP();
  17810. do {
  17811. #if defined(WOLFSSL_ASYNC_CRYPT)
  17812. ret = wc_AsyncWait(ret, &key->asyncDev,
  17813. WC_ASYNC_FLAG_CALL_AGAIN);
  17814. #endif
  17815. if (ret >= 0) {
  17816. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0],
  17817. mgf[0], -2, key);
  17818. }
  17819. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17820. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17821. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17822. TEST_SLEEP();
  17823. do {
  17824. #if defined(WOLFSSL_ASYNC_CRYPT)
  17825. ret = wc_AsyncWait(ret, &key->asyncDev,
  17826. WC_ASYNC_FLAG_CALL_AGAIN);
  17827. #endif
  17828. if (ret >= 0) {
  17829. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17830. (int)digestSz + 1, key);
  17831. }
  17832. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17833. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17834. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17835. TEST_SLEEP();
  17836. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17837. len = -2;
  17838. #else
  17839. len = -3;
  17840. #endif
  17841. #if defined(HAVE_SELFTEST) && \
  17842. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17843. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17844. hash[0], len);
  17845. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17846. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17847. hash[0], len, 0);
  17848. #else
  17849. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17850. len, 0, HEAP_HINT);
  17851. #endif
  17852. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17853. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17854. #ifndef WOLFSSL_PSS_LONG_SALT
  17855. len = (int)(digestSz + 1);
  17856. #else
  17857. len = (int)(plainSz - digestSz - 1);
  17858. #endif
  17859. #if defined(HAVE_SELFTEST) && \
  17860. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17861. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17862. hash[0], len);
  17863. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17864. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17865. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17866. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17867. hash[0], len, 0);
  17868. if (ret != WC_NO_ERR_TRACE(BAD_PADDING_E))
  17869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17870. #else
  17871. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17872. len, 0, HEAP_HINT);
  17873. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17875. #endif
  17876. ret = 0;
  17877. #endif /* WOLFSSL_SE050 */
  17878. exit_rsa_pss:
  17879. WC_FREE_VAR(sig, HEAP_HINT);
  17880. WC_FREE_VAR(in, HEAP_HINT);
  17881. WC_FREE_VAR(out, HEAP_HINT);
  17882. return ret;
  17883. }
  17884. #endif /* !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY */
  17885. #endif
  17886. #ifdef WC_RSA_NO_PADDING
  17887. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void)
  17888. {
  17889. WC_RNG rng;
  17890. byte* tmp = NULL;
  17891. size_t bytes;
  17892. wc_test_ret_t ret;
  17893. word32 inLen = 0;
  17894. word32 idx = 0;
  17895. word32 outSz = RSA_TEST_BYTES;
  17896. word32 plainSz = RSA_TEST_BYTES;
  17897. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  17898. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  17899. !defined(NO_FILESYSTEM)
  17900. XFILE file;
  17901. #endif
  17902. WC_DECLARE_VAR(key, RsaKey, 1, HEAP_HINT);
  17903. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17904. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17905. WC_ALLOC_VAR(key, RsaKey, 1, HEAP_HINT);
  17906. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17907. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17908. WOLFSSL_ENTER("rsa_no_pad_test");
  17909. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17910. if (key == NULL || out == NULL || plain == NULL)
  17911. ERROR_OUT(MEMORY_E, exit_rsa_nopadding);
  17912. #endif
  17913. /* initialize stack structures */
  17914. XMEMSET(&rng, 0, sizeof(rng));
  17915. XMEMSET(key, 0, sizeof(RsaKey));
  17916. #ifdef USE_CERT_BUFFERS_1024
  17917. bytes = (size_t)sizeof_client_key_der_1024;
  17918. if (bytes < (size_t)sizeof_client_cert_der_1024)
  17919. bytes = (size_t)sizeof_client_cert_der_1024;
  17920. #elif defined(USE_CERT_BUFFERS_2048)
  17921. bytes = (size_t)sizeof_client_key_der_2048;
  17922. if (bytes < (size_t)sizeof_client_cert_der_2048)
  17923. bytes = (size_t)sizeof_client_cert_der_2048;
  17924. #else
  17925. bytes = FOURK_BUF;
  17926. #endif
  17927. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  17928. if (tmp == NULL
  17929. #ifdef WOLFSSL_ASYNC_CRYPT
  17930. || out == NULL || plain == NULL
  17931. #endif
  17932. ) {
  17933. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17934. }
  17935. #ifdef USE_CERT_BUFFERS_1024
  17936. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  17937. #elif defined(USE_CERT_BUFFERS_2048)
  17938. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  17939. #elif defined(USE_CERT_BUFFERS_3072)
  17940. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  17941. #elif defined(USE_CERT_BUFFERS_4096)
  17942. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  17943. #elif !defined(NO_FILESYSTEM)
  17944. file = XFOPEN(clientKey, "rb");
  17945. if (!file) {
  17946. err_sys("can't open clientKey, Please run from wolfSSL home dir",
  17947. WC_TEST_RET_ENC_ERRNO);
  17948. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17949. }
  17950. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  17951. XFCLOSE(file);
  17952. if (bytes == 0)
  17953. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17954. #else
  17955. /* No key to use. */
  17956. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17957. #endif /* USE_CERT_BUFFERS */
  17958. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  17959. if (ret != 0) {
  17960. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17961. }
  17962. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  17963. if (ret != 0) {
  17964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17965. }
  17966. /* after loading in key use tmp as the test buffer */
  17967. #ifndef HAVE_FIPS
  17968. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  17969. #else
  17970. ret = wc_InitRng(&rng);
  17971. #endif
  17972. if (ret != 0) {
  17973. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17974. }
  17975. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17976. inLen = (word32)wc_RsaEncryptSize(key);
  17977. outSz = inLen;
  17978. plainSz = inLen;
  17979. XMEMSET(tmp, 7, inLen);
  17980. do {
  17981. #if defined(WOLFSSL_ASYNC_CRYPT)
  17982. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17983. #endif
  17984. if (ret >= 0) {
  17985. ret = wc_RsaDirect(tmp, inLen, out, &outSz, key,
  17986. RSA_PRIVATE_ENCRYPT, &rng);
  17987. }
  17988. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17989. if (ret <= 0) {
  17990. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17991. }
  17992. /* encrypted result should not be the same as input */
  17993. if (XMEMCMP(out, tmp, inLen) == 0) {
  17994. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17995. }
  17996. TEST_SLEEP();
  17997. /* decrypt with public key and compare result */
  17998. do {
  17999. #if defined(WOLFSSL_ASYNC_CRYPT)
  18000. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18001. #endif
  18002. if (ret >= 0) {
  18003. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key,
  18004. RSA_PUBLIC_DECRYPT, &rng);
  18005. }
  18006. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18007. if (ret <= 0) {
  18008. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18009. }
  18010. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18011. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18012. }
  18013. TEST_SLEEP();
  18014. #endif
  18015. #ifdef WC_RSA_BLINDING
  18016. ret = wc_RsaSetRNG(NULL, &rng);
  18017. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18018. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18019. }
  18020. ret = wc_RsaSetRNG(key, &rng);
  18021. if (ret < 0) {
  18022. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18023. }
  18024. #endif
  18025. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18026. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18027. do {
  18028. #if defined(WOLFSSL_ASYNC_CRYPT)
  18029. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18030. #endif
  18031. if (ret >= 0) {
  18032. ret = wc_RsaPublicEncrypt_ex(tmp, inLen, out, outSz, key, &rng,
  18033. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18034. }
  18035. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18036. if (ret < 0) {
  18037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18038. }
  18039. TEST_SLEEP();
  18040. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18041. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18042. do {
  18043. #if defined(WOLFSSL_ASYNC_CRYPT)
  18044. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18045. #endif
  18046. if (ret >= 0) {
  18047. ret = wc_RsaPrivateDecrypt_ex(out, outSz, plain, plainSz, key,
  18048. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18049. }
  18050. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18051. if (ret < 0) {
  18052. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18053. }
  18054. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18055. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18056. }
  18057. TEST_SLEEP();
  18058. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18059. /* test some bad arguments */
  18060. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key, -1,
  18061. &rng);
  18062. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18063. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18064. }
  18065. ret = wc_RsaDirect(out, outSz, plain, &plainSz, NULL, RSA_PUBLIC_DECRYPT,
  18066. &rng);
  18067. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18069. }
  18070. ret = wc_RsaDirect(out, outSz, NULL, &plainSz, key, RSA_PUBLIC_DECRYPT,
  18071. &rng);
  18072. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || plainSz != inLen) {
  18073. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18074. }
  18075. ret = wc_RsaDirect(out, outSz - 10, plain, &plainSz, key,
  18076. RSA_PUBLIC_DECRYPT, &rng);
  18077. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18078. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18079. }
  18080. /* if making it to this point of code without hitting an ERROR_OUT then
  18081. * all tests have passed */
  18082. ret = 0;
  18083. exit_rsa_nopadding:
  18084. wc_FreeRsaKey(key);
  18085. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18086. WC_FREE_VAR(key, HEAP_HINT);
  18087. WC_FREE_VAR(out, HEAP_HINT);
  18088. WC_FREE_VAR(plain, HEAP_HINT);
  18089. wc_FreeRng(&rng);
  18090. return ret;
  18091. }
  18092. #endif /* WC_RSA_NO_PADDING */
  18093. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  18094. static wc_test_ret_t rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
  18095. {
  18096. byte* tmp = NULL;
  18097. size_t bytes;
  18098. wc_test_ret_t ret;
  18099. word32 inLen = 0;
  18100. #ifndef NO_ASN
  18101. word32 idx = 0;
  18102. #endif
  18103. word32 outSz = RSA_TEST_BYTES;
  18104. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18105. word32 plainSz = RSA_TEST_BYTES;
  18106. #endif
  18107. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_3072) && \
  18108. !defined(USE_CERT_BUFFERS_4096) && !defined(NO_FILESYSTEM)
  18109. XFILE file;
  18110. #endif
  18111. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18112. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18113. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18114. #endif
  18115. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18116. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18117. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18118. #endif
  18119. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18120. if (out == NULL
  18121. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18122. || plain == NULL
  18123. #endif
  18124. ) {
  18125. ERROR_OUT(MEMORY_E, exit_rsa_even_mod);
  18126. }
  18127. #endif
  18128. #if defined(USE_CERT_BUFFERS_2048)
  18129. bytes = (size_t)sizeof_client_key_der_2048;
  18130. if (bytes < (size_t)sizeof_client_cert_der_2048)
  18131. bytes = (size_t)sizeof_client_cert_der_2048;
  18132. #else
  18133. bytes = FOURK_BUF;
  18134. #endif
  18135. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18136. if (tmp == NULL
  18137. #ifdef WOLFSSL_ASYNC_CRYPT
  18138. || out == NULL || plain == NULL
  18139. #endif
  18140. ) {
  18141. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18142. }
  18143. #if defined(USE_CERT_BUFFERS_2048)
  18144. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  18145. #elif defined(USE_CERT_BUFFERS_3072)
  18146. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  18147. #elif defined(USE_CERT_BUFFERS_4096)
  18148. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  18149. #elif !defined(NO_FILESYSTEM)
  18150. file = XFOPEN(clientKey, "rb");
  18151. if (!file) {
  18152. err_sys("can't open ./certs/client-key.der, "
  18153. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  18154. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18155. }
  18156. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  18157. XFCLOSE(file);
  18158. if (bytes == 0)
  18159. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18160. #else
  18161. /* No key to use. */
  18162. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18163. #endif /* USE_CERT_BUFFERS */
  18164. #ifndef NO_ASN
  18165. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  18166. if (ret != 0) {
  18167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18168. }
  18169. #else
  18170. #ifdef USE_CERT_BUFFERS_2048
  18171. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  18172. if (ret != 0) {
  18173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18174. }
  18175. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  18176. if (ret != 0) {
  18177. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18178. }
  18179. #ifndef NO_SIG_WRAPPER
  18180. modLen = 2048;
  18181. #endif
  18182. #else
  18183. #error Not supported yet!
  18184. #endif
  18185. #endif
  18186. key->n.dp[0] &= (mp_digit)-2;
  18187. if (ret != 0) {
  18188. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18189. }
  18190. /* after loading in key use tmp as the test buffer */
  18191. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  18192. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM))) && \
  18193. !defined(WOLFSSL_XILINX_CRYPT)
  18194. /* The ARM64_ASM code that was FIPS validated did not return these expected
  18195. * failure codes. These tests cases were added after the assembly was
  18196. * in-lined in the module and validated, these tests will be available in
  18197. * the 140-3 module */
  18198. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18199. inLen = 32;
  18200. outSz = wc_RsaEncryptSize(key);
  18201. XMEMSET(tmp, 7, plainSz);
  18202. ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng);
  18203. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18204. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18205. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18206. {
  18207. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18208. }
  18209. ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key);
  18210. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18211. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18212. {
  18213. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18214. }
  18215. #endif
  18216. #ifdef WC_RSA_BLINDING
  18217. ret = wc_RsaSetRNG(key, rng);
  18218. if (ret < 0) {
  18219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18220. }
  18221. #endif
  18222. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18223. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18224. ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
  18225. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18226. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18227. {
  18228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18229. }
  18230. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18231. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18232. ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key);
  18233. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18234. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18235. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18236. {
  18237. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18238. }
  18239. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18240. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  18241. /* if making it to this point of code without hitting an ERROR_OUT then
  18242. * all tests have passed */
  18243. ret = 0;
  18244. exit_rsa_even_mod:
  18245. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18246. WC_FREE_VAR(out, HEAP_HINT);
  18247. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18248. WC_FREE_VAR(plain, HEAP_HINT);
  18249. #endif
  18250. (void)out;
  18251. (void)outSz;
  18252. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18253. (void)plain;
  18254. (void)plainSz;
  18255. #endif
  18256. (void)inLen;
  18257. (void)rng;
  18258. return ret;
  18259. }
  18260. #endif /* WOLFSSL_HAVE_SP_RSA */
  18261. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  18262. static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp)
  18263. {
  18264. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18265. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18266. #ifdef WOLFSSL_TEST_CERT
  18267. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18268. #endif
  18269. #else
  18270. RsaKey caKey[1];
  18271. #ifdef WOLFSSL_TEST_CERT
  18272. DecodedCert decode[1];
  18273. #endif
  18274. #endif
  18275. byte* der = NULL;
  18276. wc_test_ret_t ret;
  18277. Cert* myCert = NULL;
  18278. int certSz;
  18279. size_t bytes3;
  18280. word32 idx3 = 0;
  18281. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  18282. XFILE file3;
  18283. #endif
  18284. #if defined(WOLFSSL_ALT_NAMES) && !defined(NO_ASN_TIME)
  18285. struct tm beforeTime;
  18286. struct tm afterTime;
  18287. #endif
  18288. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  18289. (void)keypub;
  18290. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18291. if (caKey == NULL)
  18292. ERROR_OUT(MEMORY_E, exit_rsa);
  18293. #ifdef WOLFSSL_TEST_CERT
  18294. if (decode == NULL)
  18295. ERROR_OUT(MEMORY_E, exit_rsa);
  18296. #endif
  18297. #endif
  18298. XMEMSET(caKey, 0, sizeof *caKey);
  18299. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18300. if (der == NULL) {
  18301. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18302. }
  18303. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18304. if (myCert == NULL) {
  18305. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18306. }
  18307. /* self signed */
  18308. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18309. if (ret != 0) {
  18310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18311. }
  18312. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18313. XMEMCPY(myCert->serial, mySerial, sizeof(mySerial));
  18314. myCert->serialSz = (int)sizeof(mySerial);
  18315. myCert->isCA = 1;
  18316. #ifndef NO_SHA256
  18317. myCert->sigType = CTC_SHA256wRSA;
  18318. #else
  18319. myCert->sigType = CTC_SHAwRSA;
  18320. #endif
  18321. #ifdef WOLFSSL_CERT_EXT
  18322. /* add Policies */
  18323. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18324. CTC_MAX_CERTPOL_SZ);
  18325. XSTRNCPY(myCert->certPolicies[1], "1.2.840.113549.1.9.16.6.5",
  18326. CTC_MAX_CERTPOL_SZ);
  18327. myCert->certPoliciesNb = 2;
  18328. /* add SKID from the Public Key */
  18329. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL);
  18330. if (ret != 0) {
  18331. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18332. }
  18333. /* add AKID from the Public Key */
  18334. ret = wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL);
  18335. if (ret != 0) {
  18336. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18337. }
  18338. /* add Key Usage */
  18339. ret = wc_SetKeyUsage(myCert,"cRLSign,keyCertSign");
  18340. if (ret != 0) {
  18341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18342. }
  18343. #ifdef WOLFSSL_EKU_OID
  18344. {
  18345. const char unique[] = "2.16.840.1.111111.100.1.10.1";
  18346. ret = wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0,
  18347. HEAP_HINT);
  18348. if (ret != 0) {
  18349. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18350. }
  18351. }
  18352. #endif /* WOLFSSL_EKU_OID */
  18353. #endif /* WOLFSSL_CERT_EXT */
  18354. do {
  18355. #if defined(WOLFSSL_ASYNC_CRYPT)
  18356. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18357. #endif
  18358. if (ret >= 0) {
  18359. ret = wc_MakeSelfCert(myCert, der, FOURK_BUF, key, rng);
  18360. }
  18361. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18362. if (ret < 0) {
  18363. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18364. }
  18365. certSz = (int)ret;
  18366. #ifdef WOLFSSL_TEST_CERT
  18367. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18368. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18369. if (ret != 0) {
  18370. FreeDecodedCert(decode);
  18371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18372. }
  18373. FreeDecodedCert(decode);
  18374. #endif
  18375. ret = SaveDerAndPem(der, certSz, certDerFile, certPemFile,
  18376. CERT_TYPE);
  18377. if (ret != 0) {
  18378. goto exit_rsa;
  18379. }
  18380. /* Setup Certificate */
  18381. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18382. if (ret < 0) {
  18383. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18384. }
  18385. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  18386. /* Get CA Cert for testing */
  18387. #ifdef USE_CERT_BUFFERS_1024
  18388. XMEMCPY(tmp, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  18389. bytes3 = sizeof_ca_cert_der_1024;
  18390. #elif defined(USE_CERT_BUFFERS_2048)
  18391. XMEMCPY(tmp, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  18392. bytes3 = sizeof_ca_cert_der_2048;
  18393. #else
  18394. file3 = XFOPEN(rsaCaCertDerFile, "rb");
  18395. if (!file3) {
  18396. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18397. }
  18398. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18399. XFCLOSE(file3);
  18400. if (bytes3 == 0)
  18401. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18402. #endif /* USE_CERT_BUFFERS */
  18403. #if defined(WOLFSSL_ALT_NAMES)
  18404. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \
  18405. !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  18406. ret = wc_SetAltNames(myCert, rsaCaCertFile);
  18407. if (ret != 0)
  18408. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18409. #endif
  18410. /* get alt names from der */
  18411. ret = wc_SetAltNamesBuffer(myCert, tmp, (int)bytes3);
  18412. if (ret != 0)
  18413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18414. /* get dates from der */
  18415. ret = wc_SetDatesBuffer(myCert, tmp, (int)bytes3);
  18416. if (ret != 0)
  18417. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18418. #ifndef NO_ASN_TIME
  18419. ret = wc_GetCertDates(myCert, &beforeTime, &afterTime);
  18420. if (ret < 0)
  18421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18422. #endif
  18423. #endif /* WOLFSSL_ALT_NAMES */
  18424. #endif /* WOLFSSL_ALT_NAMES || HAVE_PKCS7 */
  18425. /* Get CA Key */
  18426. #ifdef USE_CERT_BUFFERS_1024
  18427. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18428. bytes3 = sizeof_ca_key_der_1024;
  18429. #elif defined(USE_CERT_BUFFERS_2048)
  18430. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18431. bytes3 = sizeof_ca_key_der_2048;
  18432. #else
  18433. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18434. if (!file3) {
  18435. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18436. }
  18437. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18438. XFCLOSE(file3);
  18439. if (bytes3 == 0)
  18440. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18441. #endif /* USE_CERT_BUFFERS */
  18442. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18443. if (ret != 0)
  18444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18445. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18446. if (ret != 0)
  18447. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18448. #ifndef NO_SHA256
  18449. myCert->sigType = CTC_SHA256wRSA;
  18450. #else
  18451. myCert->sigType = CTC_SHAwRSA;
  18452. #endif
  18453. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18454. #ifdef WOLFSSL_CERT_EXT
  18455. /* add Policies */
  18456. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18457. CTC_MAX_CERTPOL_SZ);
  18458. myCert->certPoliciesNb =1;
  18459. /* add SKID from the Public Key */
  18460. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL);
  18461. if (ret != 0)
  18462. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18463. /* add AKID from the CA certificate */
  18464. #if defined(USE_CERT_BUFFERS_2048)
  18465. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18466. sizeof_ca_cert_der_2048);
  18467. #elif defined(USE_CERT_BUFFERS_1024)
  18468. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18469. sizeof_ca_cert_der_1024);
  18470. #else
  18471. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18472. #endif
  18473. if (ret != 0)
  18474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18475. /* add Key Usage */
  18476. ret = wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement");
  18477. if (ret != 0)
  18478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18479. #endif /* WOLFSSL_CERT_EXT */
  18480. #if defined(USE_CERT_BUFFERS_2048)
  18481. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18482. sizeof_ca_cert_der_2048);
  18483. #elif defined(USE_CERT_BUFFERS_1024)
  18484. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18485. sizeof_ca_cert_der_1024);
  18486. #else
  18487. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18488. #endif
  18489. if (ret < 0)
  18490. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18491. certSz = wc_MakeCert(myCert, der, FOURK_BUF, key, NULL, rng);
  18492. if (certSz < 0) {
  18493. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18494. }
  18495. ret = 0;
  18496. do {
  18497. #if defined(WOLFSSL_ASYNC_CRYPT)
  18498. ret = wc_AsyncWait(ret, &caKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18499. #endif
  18500. if (ret >= 0) {
  18501. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der, FOURK_BUF,
  18502. caKey, NULL, rng);
  18503. }
  18504. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18505. if (ret < 0)
  18506. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18507. certSz = (int)ret;
  18508. #ifdef WOLFSSL_TEST_CERT
  18509. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18510. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18511. if (ret != 0) {
  18512. FreeDecodedCert(decode);
  18513. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18514. }
  18515. FreeDecodedCert(decode);
  18516. #endif
  18517. ret = SaveDerAndPem(der, certSz, otherCertDerFile, otherCertPemFile,
  18518. CERT_TYPE);
  18519. if (ret != 0) {
  18520. goto exit_rsa;
  18521. }
  18522. exit_rsa:
  18523. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18524. if (caKey != NULL) {
  18525. wc_FreeRsaKey(caKey);
  18526. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18527. }
  18528. #ifdef WOLFSSL_TEST_CERT
  18529. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18530. #endif
  18531. #else
  18532. wc_FreeRsaKey(caKey);
  18533. #endif
  18534. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18535. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18536. return ret;
  18537. }
  18538. #endif
  18539. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP) && \
  18540. defined(WOLFSSL_CERT_GEN)
  18541. /* Make Cert / Sign example for ECC cert and RSA CA */
  18542. static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
  18543. {
  18544. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18545. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18546. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18547. ecc_key *caEccKeyPub = (ecc_key *)XMALLOC(sizeof *caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18548. #ifdef WOLFSSL_TEST_CERT
  18549. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18550. #endif
  18551. #else
  18552. RsaKey caKey[1];
  18553. ecc_key caEccKey[1];
  18554. ecc_key caEccKeyPub[1];
  18555. #ifdef WOLFSSL_TEST_CERT
  18556. DecodedCert decode[1];
  18557. #endif
  18558. #endif
  18559. byte* der = NULL;
  18560. Cert* myCert = NULL;
  18561. int certSz;
  18562. size_t bytes3;
  18563. word32 idx3 = 0;
  18564. #if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
  18565. || !defined(USE_CERT_BUFFERS_256)
  18566. #ifndef NO_FILESYSTEM
  18567. XFILE file3;
  18568. #endif
  18569. #endif
  18570. wc_test_ret_t ret;
  18571. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18572. if ((caKey == NULL) || (caEccKey == NULL) || (caEccKeyPub == NULL)
  18573. #ifdef WOLFSSL_TEST_CERT
  18574. || (decode == NULL)
  18575. #endif
  18576. )
  18577. ERROR_OUT(MEMORY_E, exit_rsa);
  18578. #endif
  18579. XMEMSET(caKey, 0, sizeof *caKey);
  18580. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  18581. XMEMSET(caEccKeyPub, 0, sizeof *caEccKeyPub);
  18582. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18583. if (der == NULL) {
  18584. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18585. }
  18586. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18587. if (myCert == NULL) {
  18588. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18589. }
  18590. /* Get CA Key */
  18591. #ifdef USE_CERT_BUFFERS_1024
  18592. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18593. bytes3 = sizeof_ca_key_der_1024;
  18594. #elif defined(USE_CERT_BUFFERS_2048)
  18595. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18596. bytes3 = sizeof_ca_key_der_2048;
  18597. #else
  18598. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18599. if (!file3) {
  18600. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18601. }
  18602. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18603. XFCLOSE(file3);
  18604. if (bytes3 == 0)
  18605. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18606. #endif /* USE_CERT_BUFFERS */
  18607. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18608. if (ret != 0)
  18609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18610. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18611. if (ret != 0)
  18612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18613. /* Get Cert Key */
  18614. #if defined(USE_CERT_BUFFERS_256)
  18615. {
  18616. XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
  18617. bytes3 = sizeof_ecc_key_pub_der_256;
  18618. }
  18619. #elif !defined(NO_FILESYSTEM)
  18620. {
  18621. file3 = XFOPEN(eccKeyPubFileDer, "rb");
  18622. if (!file3) {
  18623. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18624. }
  18625. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18626. XFCLOSE(file3);
  18627. if (bytes3 == 0)
  18628. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18629. }
  18630. #else
  18631. {
  18632. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
  18633. ERROR_OUT(ASN_PARSE_E, exit_rsa);
  18634. }
  18635. #endif
  18636. ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
  18637. if (ret != 0)
  18638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18639. idx3 = 0;
  18640. ret = wc_EccPublicKeyDecode(tmp, &idx3, caEccKeyPub, (word32)bytes3);
  18641. if (ret != 0)
  18642. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18643. /* Setup Certificate */
  18644. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18645. if (ret != 0)
  18646. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18647. #ifndef NO_SHA256
  18648. myCert->sigType = CTC_SHA256wRSA;
  18649. #else
  18650. myCert->sigType = CTC_SHAwRSA;
  18651. #endif
  18652. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18653. #ifdef WOLFSSL_CERT_EXT
  18654. /* add Policies */
  18655. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  18656. CTC_MAX_CERTPOL_SZ);
  18657. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  18658. CTC_MAX_CERTPOL_SZ);
  18659. myCert->certPoliciesNb = 2;
  18660. /* add SKID from the Public Key */
  18661. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub);
  18662. if (ret != 0)
  18663. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18664. /* add AKID from the CA certificate */
  18665. #if defined(USE_CERT_BUFFERS_2048)
  18666. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18667. sizeof_ca_cert_der_2048);
  18668. #elif defined(USE_CERT_BUFFERS_1024)
  18669. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18670. sizeof_ca_cert_der_1024);
  18671. #else
  18672. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18673. #endif
  18674. if (ret != 0)
  18675. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18676. /* add Key Usage */
  18677. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  18678. if (ret != 0)
  18679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18680. #endif /* WOLFSSL_CERT_EXT */
  18681. #if defined(USE_CERT_BUFFERS_2048)
  18682. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18683. sizeof_ca_cert_der_2048);
  18684. #elif defined(USE_CERT_BUFFERS_1024)
  18685. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18686. sizeof_ca_cert_der_1024);
  18687. #else
  18688. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18689. #endif
  18690. if (ret < 0)
  18691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18692. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, caEccKeyPub, rng);
  18693. if (certSz < 0) {
  18694. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18695. }
  18696. ret = 0;
  18697. do {
  18698. #if defined(WOLFSSL_ASYNC_CRYPT)
  18699. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18700. #endif
  18701. if (ret >= 0) {
  18702. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  18703. FOURK_BUF, caKey, NULL, rng);
  18704. }
  18705. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18706. if (ret < 0)
  18707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18708. certSz = (int)ret;
  18709. #ifdef WOLFSSL_TEST_CERT
  18710. InitDecodedCert(decode, der, certSz, 0);
  18711. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18712. if (ret != 0) {
  18713. FreeDecodedCert(decode);
  18714. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18715. }
  18716. FreeDecodedCert(decode);
  18717. #endif
  18718. ret = SaveDerAndPem(der, certSz, certEccRsaDerFile, certEccRsaPemFile,
  18719. CERT_TYPE);
  18720. if (ret != 0) {
  18721. goto exit_rsa;
  18722. }
  18723. exit_rsa:
  18724. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18725. if (caKey != NULL) {
  18726. wc_FreeRsaKey(caKey);
  18727. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18728. }
  18729. if (caEccKey != NULL) {
  18730. wc_ecc_free(caEccKey);
  18731. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18732. }
  18733. if (caEccKeyPub != NULL) {
  18734. wc_ecc_free(caEccKeyPub);
  18735. XFREE(caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18736. }
  18737. #ifdef WOLFSSL_TEST_CERT
  18738. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18739. #endif
  18740. #else
  18741. wc_FreeRsaKey(caKey);
  18742. wc_ecc_free(caEccKey);
  18743. wc_ecc_free(caEccKeyPub);
  18744. #endif
  18745. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18746. myCert = NULL;
  18747. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18748. der = NULL;
  18749. if (ret >= 0)
  18750. ret = 0;
  18751. return ret;
  18752. }
  18753. #endif /* !NO_RSA && HAVE_ECC && WOLFSSL_CERT_GEN */
  18754. #ifdef WOLFSSL_KEY_GEN
  18755. static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
  18756. {
  18757. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18758. RsaKey *genKey = (RsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18759. #else
  18760. RsaKey genKey[1];
  18761. #endif
  18762. wc_test_ret_t ret;
  18763. #ifndef WOLFSSL_NO_MALLOC
  18764. byte* der = NULL;
  18765. #else
  18766. byte der[1280];
  18767. #endif
  18768. #ifndef WOLFSSL_CRYPTOCELL
  18769. word32 idx = 0;
  18770. #endif
  18771. int derSz = 0;
  18772. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FIPS) && \
  18773. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18774. int keySz = 1024;
  18775. #else
  18776. int keySz = 2048;
  18777. #endif
  18778. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18779. if (! genKey)
  18780. ERROR_OUT(MEMORY_E, exit_rsa);
  18781. #endif
  18782. XMEMSET(genKey, 0, sizeof *genKey);
  18783. ret = wc_InitRsaKey_ex(genKey, HEAP_HINT, devId);
  18784. if (ret != 0)
  18785. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18786. #ifdef HAVE_FIPS
  18787. for (;;) {
  18788. #endif
  18789. ret = wc_MakeRsaKey(genKey, keySz, WC_RSA_EXPONENT, rng);
  18790. #if defined(WOLFSSL_ASYNC_CRYPT)
  18791. ret = wc_AsyncWait(ret, &genKey->asyncDev, WC_ASYNC_FLAG_NONE);
  18792. #endif
  18793. #ifdef HAVE_FIPS
  18794. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  18795. continue;
  18796. break;
  18797. }
  18798. #endif
  18799. if (ret != 0)
  18800. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18801. TEST_SLEEP();
  18802. #ifdef WOLFSSL_RSA_KEY_CHECK
  18803. ret = wc_CheckRsaKey(genKey);
  18804. if (ret != 0)
  18805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18806. #endif
  18807. #ifndef WOLFSSL_NO_MALLOC
  18808. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18809. if (der == NULL) {
  18810. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18811. }
  18812. derSz = FOURK_BUF;
  18813. #else
  18814. derSz = sizeof(der);
  18815. #endif
  18816. derSz = wc_RsaKeyToDer(genKey, der, derSz);
  18817. if (derSz < 0) {
  18818. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  18819. }
  18820. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  18821. PRIVATEKEY_TYPE);
  18822. if (ret != 0) {
  18823. goto exit_rsa;
  18824. }
  18825. wc_FreeRsaKey(genKey);
  18826. ret = wc_InitRsaKey(genKey, HEAP_HINT);
  18827. if (ret != 0)
  18828. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18829. #ifndef WOLFSSL_CRYPTOCELL
  18830. idx = 0;
  18831. /* The private key part of the key gen pairs from cryptocell can't be exported */
  18832. ret = wc_RsaPrivateKeyDecode(der, &idx, genKey, (word32)derSz);
  18833. if (ret != 0)
  18834. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18835. #endif /* WOLFSSL_CRYPTOCELL */
  18836. exit_rsa:
  18837. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18838. if (genKey) {
  18839. wc_FreeRsaKey(genKey);
  18840. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18841. }
  18842. #else
  18843. wc_FreeRsaKey(genKey);
  18844. #endif
  18845. #ifndef WOLFSSL_NO_MALLOC
  18846. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18847. der = NULL;
  18848. #endif
  18849. return ret;
  18850. }
  18851. #endif
  18852. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18853. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) && \
  18854. (!defined(HAVE_FIPS) || \
  18855. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  18856. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  18857. static wc_test_ret_t rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng)
  18858. {
  18859. wc_test_ret_t ret = 0;
  18860. word32 idx = 0;
  18861. const char inStr[] = TEST_STRING;
  18862. const word32 inLen = (word32)TEST_STRING_SZ;
  18863. const word32 outSz = RSA_TEST_BYTES;
  18864. const word32 plainSz = RSA_TEST_BYTES;
  18865. byte* res = NULL;
  18866. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18867. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18868. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18869. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18870. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18871. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18872. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18873. if (in == NULL || out == NULL || plain == NULL)
  18874. ERROR_OUT(MEMORY_E, exit_rsa);
  18875. #endif
  18876. XMEMCPY(in, inStr, inLen);
  18877. #ifndef NO_SHA
  18878. do {
  18879. #if defined(WOLFSSL_ASYNC_CRYPT)
  18880. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18881. #endif
  18882. if (ret >= 0) {
  18883. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18884. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18885. }
  18886. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18887. if (ret < 0)
  18888. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18889. TEST_SLEEP();
  18890. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18891. idx = (word32)ret;
  18892. do {
  18893. #if defined(WOLFSSL_ASYNC_CRYPT)
  18894. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18895. #endif
  18896. if (ret >= 0) {
  18897. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18898. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18899. }
  18900. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18901. if (ret < 0)
  18902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18903. if (XMEMCMP(plain, in, inLen)) {
  18904. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18905. }
  18906. TEST_SLEEP();
  18907. #endif /* NO_SHA */
  18908. #endif
  18909. #ifndef NO_SHA256
  18910. XMEMSET(plain, 0, plainSz);
  18911. do {
  18912. #if defined(WOLFSSL_ASYNC_CRYPT)
  18913. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18914. #endif
  18915. if (ret >= 0) {
  18916. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18917. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18918. }
  18919. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18920. if (ret < 0)
  18921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18922. TEST_SLEEP();
  18923. idx = (word32)ret;
  18924. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18925. do {
  18926. #if defined(WOLFSSL_ASYNC_CRYPT)
  18927. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18928. #endif
  18929. if (ret >= 0) {
  18930. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18931. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18932. }
  18933. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18934. if (ret < 0)
  18935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18936. if (XMEMCMP(plain, in, inLen)) {
  18937. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18938. }
  18939. TEST_SLEEP();
  18940. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18941. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18942. do {
  18943. #if defined(WOLFSSL_ASYNC_CRYPT)
  18944. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18945. #endif
  18946. if (ret >= 0) {
  18947. ret = wc_RsaPrivateDecryptInline_ex(out, idx, &res, key,
  18948. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18949. }
  18950. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18951. if (ret < 0)
  18952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18953. if (ret != (int)inLen) {
  18954. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18955. }
  18956. if (XMEMCMP(res, in, inLen)) {
  18957. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18958. }
  18959. TEST_SLEEP();
  18960. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18961. /* check fails if not using the same optional label */
  18962. XMEMSET(plain, 0, plainSz);
  18963. do {
  18964. #if defined(WOLFSSL_ASYNC_CRYPT)
  18965. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18966. #endif
  18967. if (ret >= 0) {
  18968. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18969. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18970. }
  18971. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18972. if (ret < 0)
  18973. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18974. TEST_SLEEP();
  18975. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18976. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18977. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18978. /* label is unused in cryptocell and SE050 so it won't detect decrypt error
  18979. * due to label */
  18980. idx = (word32)ret;
  18981. do {
  18982. #if defined(WOLFSSL_ASYNC_CRYPT)
  18983. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18984. #endif
  18985. if (ret >= 0) {
  18986. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18987. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18988. }
  18989. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18990. if (ret > 0) { /* in this case decrypt should fail */
  18991. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18992. }
  18993. ret = 0;
  18994. TEST_SLEEP();
  18995. #endif /* !HAVE_CAVIUM */
  18996. /* check using optional label with encrypt/decrypt */
  18997. XMEMSET(plain, 0, plainSz);
  18998. do {
  18999. #if defined(WOLFSSL_ASYNC_CRYPT)
  19000. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19001. #endif
  19002. if (ret >= 0) {
  19003. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19004. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19005. }
  19006. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19007. if (ret < 0)
  19008. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19009. TEST_SLEEP();
  19010. idx = (word32)ret;
  19011. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19012. do {
  19013. #if defined(WOLFSSL_ASYNC_CRYPT)
  19014. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19015. #endif
  19016. if (ret >= 0) {
  19017. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19018. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19019. }
  19020. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19021. if (ret < 0)
  19022. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19023. if (XMEMCMP(plain, in, inLen)) {
  19024. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19025. }
  19026. TEST_SLEEP();
  19027. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19028. #ifndef NO_SHA
  19029. /* check fail using mismatch hash algorithms */
  19030. XMEMSET(plain, 0, plainSz);
  19031. do {
  19032. #if defined(WOLFSSL_ASYNC_CRYPT)
  19033. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19034. #endif
  19035. if (ret >= 0) {
  19036. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19037. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, in, inLen);
  19038. }
  19039. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19040. if (ret < 0)
  19041. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19042. TEST_SLEEP();
  19043. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  19044. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19045. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  19046. idx = (word32)ret;
  19047. do {
  19048. #if defined(WOLFSSL_ASYNC_CRYPT)
  19049. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19050. #endif
  19051. if (ret >= 0) {
  19052. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19053. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256,
  19054. in, inLen);
  19055. }
  19056. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19057. if (ret > 0) { /* should fail */
  19058. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19059. }
  19060. ret = 0;
  19061. TEST_SLEEP();
  19062. #endif /* !HAVE_CAVIUM */
  19063. #endif /* NO_SHA */
  19064. #endif /* NO_SHA256 */
  19065. #ifdef WOLFSSL_SHA512
  19066. /* Check valid RSA key size is used while using hash length of SHA512
  19067. If key size is less than (hash length * 2) + 2 then is invalid use
  19068. and test, since OAEP padding requires this.
  19069. BAD_FUNC_ARG is returned when this case is not met */
  19070. if (wc_RsaEncryptSize(key) > ((int)WC_SHA512_DIGEST_SIZE * 2) + 2) {
  19071. XMEMSET(plain, 0, plainSz);
  19072. do {
  19073. #if defined(WOLFSSL_ASYNC_CRYPT)
  19074. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19075. #endif
  19076. if (ret >= 0) {
  19077. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19078. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19079. }
  19080. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19081. if (ret < 0)
  19082. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19083. TEST_SLEEP();
  19084. idx = (word32)ret;
  19085. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19086. do {
  19087. #if defined(WOLFSSL_ASYNC_CRYPT)
  19088. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19089. #endif
  19090. if (ret >= 0) {
  19091. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19092. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19093. }
  19094. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19095. if (ret < 0)
  19096. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19097. if (XMEMCMP(plain, in, inLen)) {
  19098. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19099. }
  19100. TEST_SLEEP();
  19101. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19102. }
  19103. #endif /* WOLFSSL_SHA512 */
  19104. /* check using pkcsv15 padding with _ex API */
  19105. XMEMSET(plain, 0, plainSz);
  19106. do {
  19107. #if defined(WOLFSSL_ASYNC_CRYPT)
  19108. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19109. #endif
  19110. if (ret >= 0) {
  19111. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19112. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19113. }
  19114. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19115. if (ret < 0)
  19116. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19117. TEST_SLEEP();
  19118. idx = (word32)ret;
  19119. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19120. do {
  19121. #if defined(WOLFSSL_ASYNC_CRYPT)
  19122. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19123. #endif
  19124. if (ret >= 0) {
  19125. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19126. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19127. }
  19128. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19129. if (ret < 0)
  19130. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19131. if (XMEMCMP(plain, in, inLen)) {
  19132. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19133. }
  19134. TEST_SLEEP();
  19135. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19136. exit_rsa:
  19137. WC_FREE_VAR(in, HEAP_HINT);
  19138. WC_FREE_VAR(out, HEAP_HINT);
  19139. WC_FREE_VAR(plain, HEAP_HINT);
  19140. (void)idx;
  19141. (void)inStr;
  19142. (void)res;
  19143. if (ret >= 0)
  19144. ret = 0;
  19145. return ret;
  19146. }
  19147. #endif
  19148. #endif
  19149. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
  19150. {
  19151. wc_test_ret_t ret;
  19152. size_t bytes = 0;
  19153. WC_RNG rng;
  19154. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19155. byte* tmp = NULL;
  19156. byte* der = NULL;
  19157. RsaKey *key = NULL;
  19158. #else
  19159. RsaKey key[1];
  19160. byte tmp[FOURK_BUF];
  19161. #endif
  19162. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19163. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19164. RsaKey *keypub = NULL;
  19165. #else
  19166. RsaKey keypub[1];
  19167. #endif
  19168. #endif
  19169. word32 idx = 0;
  19170. const char inStr[] = TEST_STRING;
  19171. const word32 inLen = (word32)TEST_STRING_SZ;
  19172. const word32 outSz = RSA_TEST_BYTES;
  19173. const word32 plainSz = RSA_TEST_BYTES;
  19174. byte* res = NULL;
  19175. #ifndef NO_SIG_WRAPPER
  19176. int modLen;
  19177. #endif
  19178. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19179. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  19180. !defined(NO_FILESYSTEM)
  19181. XFILE file;
  19182. #ifdef WOLFSSL_TEST_CERT
  19183. XFILE file2;
  19184. #endif
  19185. #endif
  19186. #ifdef WOLFSSL_TEST_CERT
  19187. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19188. DecodedCert *cert = (DecodedCert *)XMALLOC(sizeof *cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19189. #else
  19190. DecodedCert cert[1];
  19191. #endif
  19192. #ifndef NO_ASN_TIME
  19193. struct tm timearg;
  19194. const byte* date;
  19195. byte dateFormat;
  19196. int dateLength;
  19197. #endif
  19198. #endif
  19199. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19200. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19201. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19202. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19203. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19204. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19205. WOLFSSL_ENTER("rsa_test");
  19206. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  19207. if (in == NULL || out == NULL || plain == NULL)
  19208. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19209. #endif
  19210. XMEMCPY(in, inStr, inLen);
  19211. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19212. key = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19213. if (key == NULL)
  19214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19215. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19216. keypub = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19217. if (keypub == NULL)
  19218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19219. #endif
  19220. #ifdef WOLFSSL_TEST_CERT
  19221. if (cert == NULL)
  19222. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19223. #endif
  19224. #else /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19225. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19226. if (ret != 0)
  19227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19228. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19229. ret = wc_InitRsaKey_ex(keypub, HEAP_HINT, devId);
  19230. if (ret != 0)
  19231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19232. #endif
  19233. #endif /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19234. /* initialize stack structures */
  19235. XMEMSET(&rng, 0, sizeof(rng));
  19236. #if !defined(NO_ASN)
  19237. ret = rsa_decode_test(key);
  19238. if (ret != 0)
  19239. ERROR_OUT(ret, exit_rsa);
  19240. #endif
  19241. #ifdef USE_CERT_BUFFERS_1024
  19242. bytes = (size_t)sizeof_client_key_der_1024;
  19243. if (bytes < (size_t)sizeof_client_cert_der_1024)
  19244. bytes = (size_t)sizeof_client_cert_der_1024;
  19245. #elif defined(USE_CERT_BUFFERS_2048)
  19246. bytes = (size_t)sizeof_client_key_der_2048;
  19247. if (bytes < (size_t)sizeof_client_cert_der_2048)
  19248. bytes = (size_t)sizeof_client_cert_der_2048;
  19249. #elif defined(USE_CERT_BUFFERS_3072)
  19250. bytes = (size_t)sizeof_client_key_der_3072;
  19251. if (bytes < (size_t)sizeof_client_cert_der_3072)
  19252. bytes = (size_t)sizeof_client_cert_der_3072;
  19253. #elif defined(USE_CERT_BUFFERS_4096)
  19254. bytes = (size_t)sizeof_client_key_der_4096;
  19255. if (bytes < (size_t)sizeof_client_cert_der_4096)
  19256. bytes = (size_t)sizeof_client_cert_der_4096;
  19257. #else
  19258. bytes = FOURK_BUF;
  19259. #endif
  19260. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19261. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19262. if (tmp == NULL)
  19263. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19264. #endif
  19265. #ifdef USE_CERT_BUFFERS_1024
  19266. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  19267. #elif defined(USE_CERT_BUFFERS_2048)
  19268. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  19269. #elif defined(USE_CERT_BUFFERS_3072)
  19270. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  19271. #elif defined(USE_CERT_BUFFERS_4096)
  19272. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  19273. #elif !defined(NO_FILESYSTEM)
  19274. file = XFOPEN(clientKey, "rb");
  19275. if (!file) {
  19276. err_sys("can't open ./certs/client-key.der, "
  19277. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19278. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19279. }
  19280. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19281. XFCLOSE(file);
  19282. if (bytes == 0)
  19283. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19284. #else
  19285. /* No key to use. */
  19286. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19287. #endif /* USE_CERT_BUFFERS */
  19288. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19289. if (ret != 0)
  19290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19291. #ifndef NO_ASN
  19292. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  19293. if (ret != 0)
  19294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19295. #ifndef NO_SIG_WRAPPER
  19296. modLen = wc_RsaEncryptSize(key);
  19297. #endif
  19298. #else
  19299. #ifdef USE_CERT_BUFFERS_2048
  19300. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  19301. if (ret != 0)
  19302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19303. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  19304. if (ret != 0)
  19305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19306. #ifndef NO_SIG_WRAPPER
  19307. modLen = 2048;
  19308. #endif
  19309. #else
  19310. #error Not supported yet!
  19311. #endif
  19312. #endif
  19313. #ifndef WC_NO_RNG
  19314. #ifndef HAVE_FIPS
  19315. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  19316. #else
  19317. ret = wc_InitRng(&rng);
  19318. #endif
  19319. if (ret != 0)
  19320. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19321. #endif
  19322. #ifndef NO_SIG_WRAPPER
  19323. ret = rsa_sig_test(key, sizeof *key, modLen, &rng);
  19324. if (ret != 0)
  19325. goto exit_rsa;
  19326. #endif
  19327. #ifdef WC_RSA_NONBLOCK
  19328. ret = rsa_nb_test(key, in, inLen, out, outSz, plain, plainSz, &rng);
  19329. if (ret != 0)
  19330. goto exit_rsa;
  19331. #endif
  19332. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19333. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19334. do {
  19335. #if defined(WOLFSSL_ASYNC_CRYPT)
  19336. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19337. #endif
  19338. if (ret >= 0) {
  19339. ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, key, &rng);
  19340. }
  19341. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19342. if (ret < 0)
  19343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19344. TEST_SLEEP();
  19345. #ifdef WC_RSA_BLINDING
  19346. {
  19347. wc_test_ret_t tmpret = ret;
  19348. ret = wc_RsaSetRNG(key, &rng);
  19349. if (ret < 0)
  19350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19351. ret = tmpret;
  19352. }
  19353. #endif
  19354. idx = (word32)ret; /* save off encrypted length */
  19355. do {
  19356. #if defined(WOLFSSL_ASYNC_CRYPT)
  19357. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19358. #endif
  19359. if (ret >= 0) {
  19360. ret = wc_RsaPrivateDecrypt(out, idx, plain, plainSz, key);
  19361. }
  19362. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19363. if (ret < 0)
  19364. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19365. if (XMEMCMP(plain, in, inLen)) {
  19366. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19367. }
  19368. TEST_SLEEP();
  19369. do {
  19370. #if defined(WOLFSSL_ASYNC_CRYPT)
  19371. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19372. #endif
  19373. if (ret >= 0) {
  19374. ret = wc_RsaPrivateDecryptInline(out, idx, &res, key);
  19375. }
  19376. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19377. if (ret < 0)
  19378. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19379. if (ret != (int)inLen) {
  19380. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19381. }
  19382. if (XMEMCMP(res, in, inLen)) {
  19383. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19384. }
  19385. TEST_SLEEP();
  19386. do {
  19387. #if defined(WOLFSSL_ASYNC_CRYPT)
  19388. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19389. #endif
  19390. if (ret >= 0) {
  19391. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng);
  19392. }
  19393. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19394. if (ret < 0)
  19395. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19396. TEST_SLEEP();
  19397. #elif defined(WOLFSSL_PUBLIC_MP)
  19398. {
  19399. static const byte signature_2048[] = {
  19400. 0x07, 0x6f, 0xc9, 0x85, 0x73, 0x9e, 0x21, 0x79,
  19401. 0x47, 0xf1, 0xa3, 0xd7, 0xf4, 0x27, 0x29, 0xbe,
  19402. 0x99, 0x5d, 0xac, 0xb2, 0x10, 0x3f, 0x95, 0xda,
  19403. 0x89, 0x23, 0xb8, 0x96, 0x13, 0x57, 0x72, 0x30,
  19404. 0xa1, 0xfe, 0x5a, 0x68, 0x9c, 0x99, 0x9d, 0x1e,
  19405. 0x05, 0xa4, 0x80, 0xb0, 0xbb, 0xd9, 0xd9, 0xa1,
  19406. 0x69, 0x97, 0x74, 0xb3, 0x41, 0x21, 0x3b, 0x47,
  19407. 0xf5, 0x51, 0xb1, 0xfb, 0xc7, 0xaa, 0xcc, 0xdc,
  19408. 0xcd, 0x76, 0xa0, 0x28, 0x4d, 0x27, 0x14, 0xa4,
  19409. 0xb9, 0x41, 0x68, 0x7c, 0xb3, 0x66, 0xe6, 0x6f,
  19410. 0x40, 0x76, 0xe4, 0x12, 0xfd, 0xae, 0x29, 0xb5,
  19411. 0x63, 0x60, 0x87, 0xce, 0x49, 0x6b, 0xf3, 0x05,
  19412. 0x9a, 0x14, 0xb5, 0xcc, 0xcd, 0xf7, 0x30, 0x95,
  19413. 0xd2, 0x72, 0x52, 0x1d, 0x5b, 0x7e, 0xef, 0x4a,
  19414. 0x02, 0x96, 0x21, 0x6c, 0x55, 0xa5, 0x15, 0xb1,
  19415. 0x57, 0x63, 0x2c, 0xa3, 0x8e, 0x9d, 0x3d, 0x45,
  19416. 0xcc, 0xb8, 0xe6, 0xa1, 0xc8, 0x59, 0xcd, 0xf5,
  19417. 0xdc, 0x0a, 0x51, 0xb6, 0x9d, 0xfb, 0xf4, 0x6b,
  19418. 0xfd, 0x32, 0x71, 0x6e, 0xcf, 0xcb, 0xb3, 0xd9,
  19419. 0xe0, 0x4a, 0x77, 0x34, 0xd6, 0x61, 0xf5, 0x7c,
  19420. 0xf9, 0xa9, 0xa4, 0xb0, 0x8e, 0x3b, 0xd6, 0x04,
  19421. 0xe0, 0xde, 0x2b, 0x5b, 0x5a, 0xbf, 0xd9, 0xef,
  19422. 0x8d, 0xa3, 0xf5, 0xb1, 0x67, 0xf3, 0xb9, 0x72,
  19423. 0x0a, 0x37, 0x12, 0x35, 0x6c, 0x8e, 0x10, 0x8b,
  19424. 0x38, 0x06, 0x16, 0x4b, 0x20, 0x20, 0x13, 0x00,
  19425. 0x2e, 0x6d, 0xc2, 0x59, 0x23, 0x67, 0x4a, 0x6d,
  19426. 0xa1, 0x46, 0x8b, 0xee, 0xcf, 0x44, 0xb4, 0x3e,
  19427. 0x56, 0x75, 0x00, 0x68, 0xb5, 0x7d, 0x0f, 0x20,
  19428. 0x79, 0x5d, 0x7f, 0x12, 0x15, 0x32, 0x89, 0x61,
  19429. 0x6b, 0x29, 0xb7, 0x52, 0xf5, 0x25, 0xd8, 0x98,
  19430. 0xe8, 0x6f, 0xf9, 0x22, 0xb4, 0xbb, 0xe5, 0xff,
  19431. 0xd0, 0x92, 0x86, 0x9a, 0x88, 0xa2, 0xaf, 0x6b
  19432. };
  19433. ret = sizeof(signature_2048);
  19434. XMEMCPY(out, signature_2048, ret);
  19435. }
  19436. #endif
  19437. #if !defined(WC_NO_RNG) && !defined(WC_NO_RSA_OAEP) && \
  19438. ((!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  19439. defined(WOLFSSL_PUBLIC_MP)) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19440. idx = (word32)ret;
  19441. XMEMSET(plain, 0, plainSz);
  19442. do {
  19443. #if defined(WOLFSSL_ASYNC_CRYPT)
  19444. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19445. #endif
  19446. if (ret >= 0) {
  19447. #ifndef WOLFSSL_RSA_VERIFY_INLINE
  19448. #if defined(WOLFSSL_CRYPTOCELL)
  19449. /*
  19450. Cryptocell requires the input data and signature byte array to verify.
  19451. first argument must be the input data
  19452. second argument must be the length of input data
  19453. third argument must be the signature byte array or the output from
  19454. wc_RsaSSL_Sign()
  19455. fourth argument must be the length of the signature byte array
  19456. */
  19457. ret = wc_RsaSSL_Verify(in, inLen, out, outSz, key);
  19458. #else
  19459. ret = wc_RsaSSL_Verify(out, idx, plain, plainSz, key);
  19460. #endif /* WOLFSSL_CRYPTOCELL */
  19461. #else
  19462. byte* dec = NULL;
  19463. ret = wc_RsaSSL_VerifyInline(out, idx, &dec, key);
  19464. if (ret > 0) {
  19465. XMEMCPY(plain, dec, ret);
  19466. }
  19467. #endif
  19468. }
  19469. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19470. if (ret < 0)
  19471. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19472. if (XMEMCMP(plain, in, (size_t)ret)) {
  19473. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19474. }
  19475. TEST_SLEEP();
  19476. #endif
  19477. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  19478. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG)
  19479. #if (!defined(HAVE_FIPS) || \
  19480. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  19481. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19482. ret = rsa_oaep_padding_test(key, &rng);
  19483. if (ret != 0)
  19484. goto exit_rsa;
  19485. #endif /* !HAVE_FIPS */
  19486. #endif /* WC_NO_RSA_OAEP && !WC_NO_RNG */
  19487. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  19488. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  19489. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19490. ret = rsa_export_key_test(key);
  19491. if (ret != 0)
  19492. goto exit_rsa;
  19493. #endif
  19494. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19495. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19496. ret = rsa_flatten_test(key);
  19497. if (ret != 0)
  19498. goto exit_rsa;
  19499. #endif
  19500. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_ASN) && \
  19501. !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19502. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  19503. (void)clientCert;
  19504. #endif
  19505. #ifdef WOLFSSL_TEST_CERT
  19506. #ifdef USE_CERT_BUFFERS_1024
  19507. XMEMCPY(tmp, client_cert_der_1024, (size_t)sizeof_client_cert_der_1024);
  19508. bytes = (size_t)sizeof_client_cert_der_1024;
  19509. #elif defined(USE_CERT_BUFFERS_2048)
  19510. XMEMCPY(tmp, client_cert_der_2048, (size_t)sizeof_client_cert_der_2048);
  19511. bytes = (size_t)sizeof_client_cert_der_2048;
  19512. #elif defined(USE_CERT_BUFFERS_3072)
  19513. XMEMCPY(tmp, client_cert_der_3072, (size_t)sizeof_client_cert_der_3072);
  19514. bytes = (size_t)sizeof_client_cert_der_3072;
  19515. #elif defined(USE_CERT_BUFFERS_4096)
  19516. XMEMCPY(tmp, client_cert_der_4096, (size_t)sizeof_client_cert_der_4096);
  19517. bytes = (size_t)sizeof_client_cert_der_4096;
  19518. #elif !defined(NO_FILESYSTEM)
  19519. file2 = XFOPEN(clientCert, "rb");
  19520. if (!file2) {
  19521. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19522. }
  19523. bytes = XFREAD(tmp, 1, FOURK_BUF, file2);
  19524. XFCLOSE(file2);
  19525. if (bytes == 0)
  19526. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19527. #else
  19528. /* No certificate to use. */
  19529. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19530. #endif
  19531. InitDecodedCert(cert, tmp, (word32)bytes, NULL);
  19532. ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL);
  19533. if (ret != 0) {
  19534. FreeDecodedCert(cert);
  19535. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19536. }
  19537. #ifndef NO_ASN_TIME
  19538. ret = wc_GetDateInfo(cert->afterDate, cert->afterDateLen, &date,
  19539. &dateFormat, &dateLength);
  19540. if (ret != 0) {
  19541. FreeDecodedCert(cert);
  19542. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19543. }
  19544. ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg);
  19545. if (ret != 0) {
  19546. FreeDecodedCert(cert);
  19547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19548. }
  19549. #endif
  19550. FreeDecodedCert(cert);
  19551. #endif /* WOLFSSL_TEST_CERT */
  19552. #ifdef WOLFSSL_CERT_EXT
  19553. #ifdef USE_CERT_BUFFERS_1024
  19554. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  19555. bytes = sizeof_client_keypub_der_1024;
  19556. #elif defined(USE_CERT_BUFFERS_2048)
  19557. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  19558. bytes = sizeof_client_keypub_der_2048;
  19559. #elif defined(USE_CERT_BUFFERS_3072)
  19560. XMEMCPY(tmp, client_keypub_der_3072, sizeof_client_keypub_der_3072);
  19561. bytes = sizeof_client_keypub_der_3072;
  19562. #elif defined(USE_CERT_BUFFERS_4096)
  19563. XMEMCPY(tmp, client_keypub_der_4096, sizeof_client_keypub_der_4096);
  19564. bytes = sizeof_client_keypub_der_4096;
  19565. #else
  19566. file = XFOPEN(clientKeyPub, "rb");
  19567. if (!file) {
  19568. err_sys("can't open ./certs/client-keyPub.der, "
  19569. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19570. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19571. }
  19572. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19573. XFCLOSE(file);
  19574. if (bytes == 0)
  19575. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19576. #endif /* USE_CERT_BUFFERS */
  19577. ret = wc_InitRsaKey(keypub, HEAP_HINT);
  19578. if (ret != 0)
  19579. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19580. idx = 0;
  19581. ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
  19582. if (ret != 0)
  19583. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19584. #endif /* WOLFSSL_CERT_EXT */
  19585. #ifdef WOLFSSL_KEY_GEN
  19586. ret = rsa_keygen_test(&rng);
  19587. if (ret != 0)
  19588. goto exit_rsa;
  19589. #endif
  19590. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  19591. !defined(WOLFSSL_NO_MALLOC)
  19592. /* Make Cert / Sign example for RSA cert and RSA CA */
  19593. ret = rsa_certgen_test(key, keypub, &rng, tmp);
  19594. if (ret != 0)
  19595. goto exit_rsa;
  19596. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP)
  19597. ret = rsa_ecc_certgen_test(&rng, tmp);
  19598. if (ret != 0)
  19599. goto exit_rsa;
  19600. #endif
  19601. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  19602. {
  19603. Cert *req;
  19604. int derSz;
  19605. #ifndef WOLFSSL_SMALL_STACK
  19606. byte* der = NULL;
  19607. #endif
  19608. req = (Cert *)XMALLOC(sizeof *req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19609. if (! req)
  19610. ERROR_OUT(MEMORY_E, exit_rsa);
  19611. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,DYNAMIC_TYPE_TMP_BUFFER);
  19612. if (der == NULL) {
  19613. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19614. }
  19615. ret = wc_InitCert_ex(req, HEAP_HINT, devId);
  19616. if (ret != 0)
  19617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19618. req->version = 0;
  19619. req->isCA = 1;
  19620. XSTRNCPY(req->challengePw, "wolf123", CTC_NAME_SIZE);
  19621. XMEMCPY(&req->subject, &certDefaultName, sizeof(CertName));
  19622. #ifndef NO_SHA256
  19623. req->sigType = CTC_SHA256wRSA;
  19624. #else
  19625. req->sigType = CTC_SHAwRSA;
  19626. #endif
  19627. #ifdef WOLFSSL_CERT_EXT
  19628. /* add SKID from the Public Key */
  19629. ret = wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL);
  19630. if (ret != 0)
  19631. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19632. /* add Key Usage */
  19633. ret = wc_SetKeyUsage(req, certKeyUsage2);
  19634. if (ret != 0)
  19635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19636. /* add Extended Key Usage */
  19637. ret = wc_SetExtKeyUsage(req,
  19638. "serverAuth,clientAuth,codeSigning,"
  19639. "emailProtection,timeStamping,OCSPSigning");
  19640. if (ret != 0)
  19641. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19642. #ifdef WOLFSSL_EKU_OID
  19643. {
  19644. WOLFSSL_SMALL_STACK_STATIC const char unique[] =
  19645. "2.16.840.1.111111.100.1.10.1";
  19646. ret = wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0,
  19647. HEAP_HINT);
  19648. if (ret != 0)
  19649. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19650. }
  19651. #endif /* WOLFSSL_EKU_OID */
  19652. #endif /* WOLFSSL_CERT_EXT */
  19653. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19654. if (derSz < 0) {
  19655. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19656. }
  19657. #ifdef WOLFSSL_CERT_EXT
  19658. /* Try again with "any" flag set, will override all others */
  19659. ret = wc_SetExtKeyUsage(req, "any");
  19660. if (ret != 0)
  19661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19662. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19663. if (derSz < 0) {
  19664. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19665. }
  19666. #endif /* WOLFSSL_CERT_EXT */
  19667. ret = 0;
  19668. do {
  19669. #if defined(WOLFSSL_ASYNC_CRYPT)
  19670. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19671. #endif
  19672. if (ret >= 0) {
  19673. ret = wc_SignCert(req->bodySz, req->sigType, der, FOURK_BUF,
  19674. key, NULL, &rng);
  19675. }
  19676. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19677. if (ret < 0)
  19678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19679. derSz = (int)ret;
  19680. ret = SaveDerAndPem(der, derSz, certReqDerFile, certReqPemFile,
  19681. CERTREQ_TYPE);
  19682. if (ret != 0) {
  19683. goto exit_rsa;
  19684. }
  19685. derSz = wc_MakeCertReq_ex(req, der, FOURK_BUF, RSA_TYPE, key);
  19686. if (derSz < 0) {
  19687. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19688. }
  19689. /* Test getting the size of the buffer without providing the buffer.
  19690. * derSz is set to the "largest buffer" we are willing to allocate. */
  19691. derSz = wc_MakeCertReq(req, NULL, 10000, key, NULL);
  19692. if (derSz < 0) {
  19693. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19694. }
  19695. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19696. XFREE(req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19697. der = NULL;
  19698. }
  19699. #endif /* WOLFSSL_CERT_REQ */
  19700. #endif /* WOLFSSL_CERT_GEN */
  19701. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  19702. /* Need to create known good signatures to test with this. */
  19703. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19704. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19705. ret = rsa_pss_test(&rng, key);
  19706. if (ret != 0)
  19707. goto exit_rsa;
  19708. #endif
  19709. #endif
  19710. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  19711. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19712. /* New key to be loaded in rsa_even_mod_test(). */
  19713. if (key != NULL)
  19714. #endif
  19715. wc_FreeRsaKey(key);
  19716. /* New key to be loaded in rsa_even_mod_test(). */
  19717. ret = rsa_even_mod_test(&rng, key);
  19718. #endif
  19719. exit_rsa:
  19720. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19721. wc_DeleteRsaKey(key, &key);
  19722. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19723. wc_DeleteRsaKey(keypub, &keypub);
  19724. #endif
  19725. #ifdef WOLFSSL_TEST_CERT
  19726. XFREE(cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19727. #endif
  19728. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19729. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19730. #else
  19731. wc_FreeRsaKey(key);
  19732. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19733. wc_FreeRsaKey(keypub);
  19734. #endif
  19735. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19736. wc_FreeRng(&rng);
  19737. WC_FREE_VAR(in, HEAP_HINT);
  19738. WC_FREE_VAR(out, HEAP_HINT);
  19739. WC_FREE_VAR(plain, HEAP_HINT);
  19740. (void)res;
  19741. (void)bytes;
  19742. (void)idx;
  19743. (void)in;
  19744. (void)out;
  19745. (void)plain;
  19746. (void)idx;
  19747. (void)inStr;
  19748. (void)inLen;
  19749. (void)outSz;
  19750. (void)plainSz;
  19751. /* ret can be greater then 0 with certgen but all negative values should
  19752. * be returned and treated as an error */
  19753. if (ret >= 0) {
  19754. return 0;
  19755. }
  19756. else {
  19757. return ret;
  19758. }
  19759. }
  19760. #endif /* !NO_RSA */
  19761. #ifndef NO_DH
  19762. static wc_test_ret_t dh_fips_generate_test(WC_RNG *rng)
  19763. {
  19764. wc_test_ret_t ret = 0;
  19765. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19766. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19767. #else
  19768. DhKey key[1];
  19769. #endif
  19770. WOLFSSL_SMALL_STACK_STATIC const byte p[] = {
  19771. 0xc5, 0x7c, 0xa2, 0x4f, 0x4b, 0xd6, 0x8c, 0x3c,
  19772. 0xda, 0xc7, 0xba, 0xaa, 0xea, 0x2e, 0x5c, 0x1e,
  19773. 0x18, 0xb2, 0x7b, 0x8c, 0x55, 0x65, 0x9f, 0xea,
  19774. 0xe0, 0xa1, 0x36, 0x53, 0x2b, 0x36, 0xe0, 0x4e,
  19775. 0x3e, 0x64, 0xa9, 0xe4, 0xfc, 0x8f, 0x32, 0x62,
  19776. 0x97, 0xe4, 0xbe, 0xf7, 0xc1, 0xde, 0x07, 0x5a,
  19777. 0x89, 0x28, 0xf3, 0xfe, 0x4f, 0xfe, 0x68, 0xbc,
  19778. 0xfb, 0x0a, 0x7c, 0xa4, 0xb3, 0x14, 0x48, 0x89,
  19779. 0x9f, 0xaf, 0xb8, 0x43, 0xe2, 0xa0, 0x62, 0x5c,
  19780. 0xb4, 0x88, 0x3f, 0x06, 0x50, 0x11, 0xfe, 0x65,
  19781. 0x8d, 0x49, 0xd2, 0xf5, 0x4b, 0x74, 0x79, 0xdb,
  19782. 0x06, 0x62, 0x92, 0x89, 0xed, 0xda, 0xcb, 0x87,
  19783. 0x37, 0x16, 0xd2, 0xa1, 0x7a, 0xe8, 0xde, 0x92,
  19784. 0xee, 0x3e, 0x41, 0x4a, 0x91, 0x5e, 0xed, 0xf3,
  19785. 0x6c, 0x6b, 0x7e, 0xfd, 0x15, 0x92, 0x18, 0xfc,
  19786. 0xa7, 0xac, 0x42, 0x85, 0x57, 0xe9, 0xdc, 0xda,
  19787. 0x55, 0xc9, 0x8b, 0x28, 0x9e, 0xc1, 0xc4, 0x46,
  19788. 0x4d, 0x88, 0xed, 0x62, 0x8e, 0xdb, 0x3f, 0xb9,
  19789. 0xd7, 0xc8, 0xe3, 0xcf, 0xb8, 0x34, 0x2c, 0xd2,
  19790. 0x6f, 0x28, 0x06, 0x41, 0xe3, 0x66, 0x8c, 0xfc,
  19791. 0x72, 0xff, 0x26, 0x3b, 0x6b, 0x6c, 0x6f, 0x73,
  19792. 0xde, 0xf2, 0x90, 0x29, 0xe0, 0x61, 0x32, 0xc4,
  19793. 0x12, 0x74, 0x09, 0x52, 0xec, 0xf3, 0x1b, 0xa6,
  19794. 0x45, 0x98, 0xac, 0xf9, 0x1c, 0x65, 0x8e, 0x3a,
  19795. 0x91, 0x84, 0x4b, 0x23, 0x8a, 0xb2, 0x3c, 0xc9,
  19796. 0xfa, 0xea, 0xf1, 0x38, 0xce, 0xd8, 0x05, 0xe0,
  19797. 0xfa, 0x44, 0x68, 0x1f, 0xeb, 0xd9, 0x57, 0xb8,
  19798. 0x4a, 0x97, 0x5b, 0x88, 0xc5, 0xf1, 0xbb, 0xb0,
  19799. 0x49, 0xc3, 0x91, 0x7c, 0xd3, 0x13, 0xb9, 0x47,
  19800. 0xbb, 0x91, 0x8f, 0xe5, 0x26, 0x07, 0xab, 0xa9,
  19801. 0xc5, 0xd0, 0x3d, 0x95, 0x41, 0x26, 0x92, 0x9d,
  19802. 0x13, 0x67, 0xf2, 0x7e, 0x11, 0x88, 0xdc, 0x2d
  19803. };
  19804. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  19805. 0x4a, 0x1a, 0xf3, 0xa4, 0x92, 0xe9, 0xee, 0x74,
  19806. 0x6e, 0x57, 0xd5, 0x8c, 0x2c, 0x5b, 0x41, 0x41,
  19807. 0x5e, 0xd4, 0x55, 0x19, 0xdc, 0xd9, 0x32, 0x91,
  19808. 0xf7, 0xfd, 0xc2, 0x57, 0xff, 0x03, 0x14, 0xdb,
  19809. 0xf1, 0xb7, 0x60, 0x0c, 0x43, 0x59, 0x3f, 0xff,
  19810. 0xac, 0xf1, 0x80, 0x9a, 0x15, 0x6f, 0xd8, 0x6e,
  19811. 0xb7, 0x85, 0x18, 0xc8, 0xec, 0x4e, 0x59, 0x4a,
  19812. 0xe2, 0x91, 0x43, 0x4c, 0xeb, 0x95, 0xb6, 0x2e,
  19813. 0x9a, 0xea, 0x53, 0x68, 0x80, 0x64, 0x69, 0x40,
  19814. 0xf9, 0xec, 0xbd, 0x85, 0x89, 0x26, 0x97, 0x67,
  19815. 0xaf, 0xb0, 0xad, 0x00, 0x1b, 0xd4, 0xfd, 0x94,
  19816. 0xd3, 0xe9, 0x92, 0xb1, 0xb4, 0xbc, 0x5a, 0xaa,
  19817. 0x92, 0x80, 0x89, 0x3b, 0x39, 0x05, 0x6c, 0x22,
  19818. 0x26, 0xfe, 0x5a, 0x28, 0x6c, 0x37, 0x50, 0x5a,
  19819. 0x38, 0x99, 0xcf, 0xf3, 0xc1, 0x96, 0x45, 0xdc,
  19820. 0x01, 0xcb, 0x20, 0x87, 0xa5, 0x00, 0x8c, 0xf5,
  19821. 0x4d, 0xc2, 0xef, 0xb8, 0x9b, 0xd1, 0x87, 0xbe,
  19822. 0xed, 0xd5, 0x0a, 0x29, 0x15, 0x34, 0x59, 0x4c,
  19823. 0x3a, 0x05, 0x22, 0x05, 0x44, 0x4f, 0x9f, 0xc8,
  19824. 0x47, 0x12, 0x24, 0x8e, 0xa8, 0x79, 0xe4, 0x67,
  19825. 0xba, 0x4d, 0x5b, 0x75, 0x56, 0x95, 0xeb, 0xe8,
  19826. 0x8a, 0xfa, 0x8e, 0x01, 0x8c, 0x1b, 0x74, 0x63,
  19827. 0xd9, 0x2f, 0xf7, 0xd3, 0x44, 0x8f, 0xa8, 0xf5,
  19828. 0xaf, 0x6c, 0x4f, 0xdb, 0xe7, 0xc9, 0x6c, 0x71,
  19829. 0x22, 0xa3, 0x1d, 0xf1, 0x40, 0xb2, 0xe0, 0x9a,
  19830. 0xb6, 0x72, 0xc9, 0xc0, 0x13, 0x16, 0xa2, 0x4a,
  19831. 0xe1, 0x92, 0xc7, 0x54, 0x23, 0xab, 0x9d, 0xa1,
  19832. 0xa1, 0xe5, 0x0b, 0xed, 0xba, 0xe8, 0x84, 0x37,
  19833. 0xb2, 0xe7, 0xfe, 0x32, 0x8d, 0xfa, 0x1c, 0x53,
  19834. 0x77, 0x97, 0xc7, 0xf3, 0x48, 0xc9, 0xdb, 0x2d,
  19835. 0x75, 0x52, 0x9d, 0x42, 0x51, 0x78, 0x62, 0x68,
  19836. 0x05, 0x45, 0x15, 0xf8, 0xa2, 0x4e, 0xf3, 0x0b
  19837. };
  19838. WOLFSSL_SMALL_STACK_STATIC const byte q[] = {
  19839. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19840. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19841. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19842. 0x40, 0x52, 0xed, 0x41
  19843. };
  19844. WOLFSSL_SMALL_STACK_STATIC const byte q0[] = {
  19845. 0x00,
  19846. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19847. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19848. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19849. 0x40, 0x52, 0xed, 0x41
  19850. };
  19851. byte priv[256];
  19852. byte pub[256];
  19853. word32 privSz = sizeof(priv);
  19854. word32 pubSz = sizeof(pub);
  19855. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19856. if (key == NULL)
  19857. ERROR_OUT(MEMORY_E, exit_gen_test);
  19858. #endif
  19859. /* Parameter Validation testing. */
  19860. ret = wc_DhGenerateKeyPair(NULL, rng, priv, &privSz, pub, &pubSz);
  19861. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19862. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19863. ret = wc_DhGenerateKeyPair(key, NULL, 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, rng, NULL, &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, priv, NULL, 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, &privSz, NULL, &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, pub, NULL);
  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_InitDhKey_ex(key, HEAP_HINT, devId);
  19879. if (ret != 0)
  19880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19881. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q0, sizeof(q0));
  19882. if (ret != 0)
  19883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19884. wc_FreeDhKey(key);
  19885. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19886. if (ret != 0)
  19887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19888. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q, sizeof(q));
  19889. if (ret != 0)
  19890. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19891. /* Use API. */
  19892. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19893. #if defined(WOLFSSL_ASYNC_CRYPT)
  19894. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19895. #endif
  19896. if (ret != 0)
  19897. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19898. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q0, sizeof(q0));
  19899. if (ret != 0)
  19900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19901. wc_FreeDhKey(key);
  19902. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19903. if (ret != 0)
  19904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19905. ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
  19906. if (ret != 0)
  19907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19908. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q, sizeof(q));
  19909. if (ret != 0)
  19910. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19911. #ifndef HAVE_SELFTEST
  19912. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19913. if (ret != 0)
  19914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19915. /* Taint the public key so the check fails. */
  19916. pub[0]++;
  19917. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19918. if (ret != WC_NO_ERR_TRACE(MP_CMP_E)) {
  19919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19920. }
  19921. #ifdef WOLFSSL_KEY_GEN
  19922. wc_FreeDhKey(key);
  19923. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19924. if (ret != 0)
  19925. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19926. ret = wc_DhGenerateParams(rng, 2048, key);
  19927. if (ret != 0)
  19928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19929. privSz = sizeof(priv);
  19930. pubSz = sizeof(pub);
  19931. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19932. #if defined(WOLFSSL_ASYNC_CRYPT)
  19933. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19934. #endif
  19935. if (ret != 0)
  19936. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19937. #endif /* WOLFSSL_KEY_GEN */
  19938. #endif /* HAVE_SELFTEST */
  19939. ret = 0;
  19940. exit_gen_test:
  19941. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19942. if (key) {
  19943. wc_FreeDhKey(key);
  19944. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19945. }
  19946. #else
  19947. wc_FreeDhKey(key);
  19948. #endif
  19949. return ret;
  19950. }
  19951. static wc_test_ret_t dh_generate_test(WC_RNG *rng)
  19952. {
  19953. wc_test_ret_t ret = 0;
  19954. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19955. DhKey *smallKey = NULL;
  19956. #else
  19957. DhKey smallKey[1];
  19958. #endif
  19959. byte p[2] = { 1, 7 }; /* 263 in decimal */
  19960. byte g[2] = { 0, 2 };
  19961. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19962. #ifdef WOLFSSL_DH_CONST
  19963. /* the table for constant DH lookup will round to the lowest byte size 21 */
  19964. byte priv[21];
  19965. byte pub[21];
  19966. #else
  19967. byte priv[2];
  19968. byte pub[2];
  19969. #endif
  19970. word32 privSz = sizeof(priv);
  19971. word32 pubSz = sizeof(pub);
  19972. #endif
  19973. int smallKey_inited = 0;
  19974. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19975. if ((smallKey = (DhKey *)XMALLOC(sizeof(*smallKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  19976. return WC_TEST_RET_ENC_ERRNO;
  19977. #endif
  19978. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19979. if (ret != 0)
  19980. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19981. smallKey_inited = 1;
  19982. /* Parameter Validation testing. */
  19983. ret = wc_InitDhKey_ex(NULL, HEAP_HINT, devId);
  19984. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19985. return WC_TEST_RET_ENC_EC(ret);
  19986. wc_FreeDhKey(NULL);
  19987. ret = wc_DhSetKey(NULL, p, sizeof(p), g, sizeof(g));
  19988. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19989. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19990. }
  19991. ret = wc_DhSetKey(smallKey, NULL, sizeof(p), g, sizeof(g));
  19992. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19993. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19994. }
  19995. ret = wc_DhSetKey(smallKey, p, 0, g, sizeof(g));
  19996. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19997. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19998. }
  19999. ret = wc_DhSetKey(smallKey, p, sizeof(p), NULL, sizeof(g));
  20000. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  20001. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20002. }
  20003. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, 0);
  20004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  20005. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20006. }
  20007. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, sizeof(g));
  20008. if (ret != 0)
  20009. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20010. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  20011. /* Use API. */
  20012. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20013. #if defined(WOLFSSL_ASYNC_CRYPT)
  20014. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20015. #endif
  20016. if (ret != 0) {
  20017. ret = WC_TEST_RET_ENC_EC(ret);
  20018. }
  20019. #else
  20020. (void)rng;
  20021. #if defined(HAVE_FIPS) || !defined(WOLFSSL_NO_DH186)
  20022. ret = 0;
  20023. #endif
  20024. #endif
  20025. #if !defined(HAVE_FIPS) && defined(WOLFSSL_NO_DH186)
  20026. {
  20027. byte priv[260];
  20028. byte pub[260];
  20029. word32 privSz = sizeof(priv);
  20030. word32 pubSz = sizeof(pub);
  20031. /* test odd ball param generation with DH */
  20032. wc_FreeDhKey(smallKey);
  20033. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  20034. if (ret != 0)
  20035. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20036. /* should fail since modSz is 16 and group size is 20 */
  20037. ret = wc_DhGenerateParams(rng, 128, smallKey);
  20038. if (ret == 0)
  20039. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20040. ret = wc_DhGenerateParams(rng, 2056, smallKey);
  20041. if (ret != 0)
  20042. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20043. privSz = sizeof(priv);
  20044. pubSz = sizeof(pub);
  20045. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20046. #if defined(WOLFSSL_ASYNC_CRYPT)
  20047. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20048. #endif
  20049. if (ret != 0)
  20050. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20051. }
  20052. #endif /* !HAVE_FIPS and WOLFSSL_NO_DH186 */
  20053. exit_gen_test:
  20054. if (smallKey_inited)
  20055. wc_FreeDhKey(smallKey);
  20056. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20057. XFREE(smallKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20058. #endif
  20059. return ret;
  20060. }
  20061. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20062. typedef struct dh_pubvalue_test {
  20063. const byte* data;
  20064. word32 len;
  20065. } dh_pubvalue_test;
  20066. static wc_test_ret_t dh_test_check_pubvalue(void)
  20067. {
  20068. wc_test_ret_t ret;
  20069. word32 i;
  20070. WOLFSSL_SMALL_STACK_STATIC const byte prime[] = {0x01, 0x00, 0x01};
  20071. WOLFSSL_SMALL_STACK_STATIC const byte pubValZero[] = { 0x00 };
  20072. WOLFSSL_SMALL_STACK_STATIC const byte pubValZeroLong[] = { 0x00, 0x00, 0x00 };
  20073. WOLFSSL_SMALL_STACK_STATIC const byte pubValOne[] = { 0x01 };
  20074. WOLFSSL_SMALL_STACK_STATIC const byte pubValOneLong[] = { 0x00, 0x00, 0x01 };
  20075. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeMinusOne[] = { 0x01, 0x00, 0x00 };
  20076. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeLong[] = {0x00, 0x01, 0x00, 0x01};
  20077. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimePlusOne[] = { 0x01, 0x00, 0x02 };
  20078. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig0[] = { 0x02, 0x00, 0x01 };
  20079. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig1[] = { 0x01, 0x01, 0x01 };
  20080. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooLong[] = { 0x01, 0x00, 0x00, 0x01 };
  20081. const dh_pubvalue_test dh_pubval_fail[] = {
  20082. { prime, sizeof(prime) },
  20083. { pubValZero, sizeof(pubValZero) },
  20084. { pubValZeroLong, sizeof(pubValZeroLong) },
  20085. { pubValOne, sizeof(pubValOne) },
  20086. { pubValOneLong, sizeof(pubValOneLong) },
  20087. { pubValPrimeMinusOne, sizeof(pubValPrimeMinusOne) },
  20088. { pubValPrimeLong, sizeof(pubValPrimeLong) },
  20089. { pubValPrimePlusOne, sizeof(pubValPrimePlusOne) },
  20090. { pubValTooBig0, sizeof(pubValTooBig0) },
  20091. { pubValTooBig1, sizeof(pubValTooBig1) },
  20092. { pubValTooLong, sizeof(pubValTooLong) },
  20093. };
  20094. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwo[] = { 0x02 };
  20095. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwoLong[] = { 0x00, 0x00, 0x02 };
  20096. WOLFSSL_SMALL_STACK_STATIC const byte pubValGood[] = { 0x12, 0x34 };
  20097. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLen[] = { 0x00, 0x12, 0x34 };
  20098. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLong[] = { 0x00, 0x00, 0x12, 0x34 };
  20099. const dh_pubvalue_test dh_pubval_pass[] = {
  20100. { pubValTwo, sizeof(pubValTwo) },
  20101. { pubValTwoLong, sizeof(pubValTwoLong) },
  20102. { pubValGood, sizeof(pubValGood) },
  20103. { pubValGoodLen, sizeof(pubValGoodLen) },
  20104. { pubValGoodLong, sizeof(pubValGoodLong) },
  20105. };
  20106. for (i = 0; i < sizeof(dh_pubval_fail) / sizeof(*dh_pubval_fail); i++) {
  20107. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_fail[i].data,
  20108. dh_pubval_fail[i].len);
  20109. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  20110. return WC_TEST_RET_ENC_I(i);
  20111. }
  20112. for (i = 0; i < sizeof(dh_pubval_pass) / sizeof(*dh_pubval_pass); i++) {
  20113. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_pass[i].data,
  20114. dh_pubval_pass[i].len);
  20115. if (ret != 0)
  20116. return WC_TEST_RET_ENC_I(i);
  20117. }
  20118. return 0;
  20119. }
  20120. #endif
  20121. #if defined(HAVE_FFDHE)
  20122. #if defined(HAVE_FFDHE_4096)
  20123. #define MAX_DH_PRIV_SZ 39
  20124. #define MAX_DH_KEY_SZ 512
  20125. #elif defined(HAVE_FFDHE_3072)
  20126. #define MAX_DH_PRIV_SZ 34
  20127. #define MAX_DH_KEY_SZ 384
  20128. #else
  20129. #define MAX_DH_PRIV_SZ 29
  20130. #define MAX_DH_KEY_SZ 256
  20131. #endif
  20132. #ifndef WC_NO_RNG
  20133. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20134. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20135. #ifdef HAVE_PUBLIC_FFDHE
  20136. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, const DhParams* params)
  20137. #else
  20138. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, int name)
  20139. #endif
  20140. {
  20141. wc_test_ret_t ret;
  20142. word32 privSz, pubSz, privSz2, pubSz2;
  20143. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20144. byte *priv = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20145. byte *pub = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20146. byte *priv2 = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20147. byte *pub2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20148. byte *agree = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20149. byte *agree2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20150. DhKey *key = (DhKey*)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20151. DhKey *key2 = (DhKey*)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20152. #else
  20153. byte priv[MAX_DH_PRIV_SZ];
  20154. byte pub[MAX_DH_KEY_SZ];
  20155. byte priv2[MAX_DH_PRIV_SZ];
  20156. byte pub2[MAX_DH_KEY_SZ];
  20157. byte agree[MAX_DH_KEY_SZ];
  20158. byte agree2[MAX_DH_KEY_SZ];
  20159. DhKey key[1];
  20160. DhKey key2[1];
  20161. #endif
  20162. word32 agreeSz = MAX_DH_KEY_SZ;
  20163. word32 agreeSz2 = MAX_DH_KEY_SZ;
  20164. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20165. if ((priv == NULL) ||
  20166. (pub == NULL) ||
  20167. (priv2 == NULL) ||
  20168. (pub2 == NULL) ||
  20169. (agree == NULL) ||
  20170. (agree2 == NULL) ||
  20171. (key == NULL) ||
  20172. (key2 == NULL))
  20173. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20174. #endif
  20175. pubSz = MAX_DH_KEY_SZ;
  20176. pubSz2 = MAX_DH_KEY_SZ;
  20177. #ifdef HAVE_PUBLIC_FFDHE
  20178. privSz = MAX_DH_PRIV_SZ;
  20179. privSz2 = MAX_DH_PRIV_SZ;
  20180. #else
  20181. privSz = wc_DhGetNamedKeyMinSize(name);
  20182. privSz2 = privSz;
  20183. #endif
  20184. XMEMSET(key, 0, sizeof(*key));
  20185. XMEMSET(key2, 0, sizeof(*key2));
  20186. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20187. if (ret != 0)
  20188. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20189. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20190. if (ret != 0)
  20191. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20192. #ifdef HAVE_PUBLIC_FFDHE
  20193. ret = wc_DhSetKey(key, params->p, params->p_len, params->g, params->g_len);
  20194. #else
  20195. ret = wc_DhSetNamedKey(key, name);
  20196. #endif
  20197. if (ret != 0)
  20198. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20199. #ifdef HAVE_PUBLIC_FFDHE
  20200. ret = wc_DhSetKey(key2, params->p, params->p_len, params->g,
  20201. params->g_len);
  20202. #else
  20203. ret = wc_DhSetNamedKey(key2, name);
  20204. #endif
  20205. if (ret != 0)
  20206. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20207. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20208. #if defined(WOLFSSL_ASYNC_CRYPT)
  20209. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20210. #endif
  20211. if (ret != 0)
  20212. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20213. ret = wc_DhGenerateKeyPair(key2, rng, priv2, &privSz2, pub2, &pubSz2);
  20214. #if defined(WOLFSSL_ASYNC_CRYPT)
  20215. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20216. #endif
  20217. if (ret != 0)
  20218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20219. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20220. #if defined(WOLFSSL_ASYNC_CRYPT)
  20221. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20222. #endif
  20223. if (ret != 0)
  20224. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20225. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20226. #if defined(WOLFSSL_ASYNC_CRYPT)
  20227. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20228. #endif
  20229. if (ret != 0)
  20230. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20231. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20232. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20233. }
  20234. #if (defined(WOLFSSL_HAVE_SP_DH) || defined(USE_FAST_MATH)) && \
  20235. !defined(HAVE_INTEL_QA)
  20236. /* Make p even */
  20237. key->p.dp[0] &= (mp_digit)-2;
  20238. if (ret != 0)
  20239. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20240. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20241. #if defined(WOLFSSL_ASYNC_CRYPT)
  20242. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20243. #endif
  20244. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20245. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  20246. {
  20247. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20248. }
  20249. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20250. #if defined(WOLFSSL_ASYNC_CRYPT)
  20251. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20252. #endif
  20253. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20254. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20255. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20256. {
  20257. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20258. }
  20259. #ifndef HAVE_SELFTEST
  20260. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  20261. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20262. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20263. ret != WC_NO_ERR_TRACE(MP_CMP_E) &&
  20264. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20265. {
  20266. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20267. }
  20268. #endif
  20269. /* Getting here means success - set ret to 0. */
  20270. ret = 0;
  20271. #endif /* (SP DH or Fast Math) and not Intel QuickAssist */
  20272. done:
  20273. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) && \
  20274. !defined(WC_NO_RNG)
  20275. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20276. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20277. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20278. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20279. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20280. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20281. if (key) {
  20282. wc_FreeDhKey(key);
  20283. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20284. }
  20285. if (key2) {
  20286. wc_FreeDhKey(key2);
  20287. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20288. }
  20289. #else
  20290. wc_FreeDhKey(key);
  20291. wc_FreeDhKey(key2);
  20292. #endif
  20293. return ret;
  20294. }
  20295. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  20296. #endif /* !WC_NO_RNG */
  20297. #endif /* HAVE_FFDHE */
  20298. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void)
  20299. {
  20300. wc_test_ret_t ret;
  20301. word32 bytes;
  20302. word32 idx = 0;
  20303. word32 privSz = 0;
  20304. word32 pubSz = 0;
  20305. word32 privSz2 = 0;
  20306. word32 pubSz2 = 0;
  20307. #ifndef WC_NO_RNG
  20308. WC_RNG rng;
  20309. int rngInit = 0;
  20310. #endif
  20311. int keyInit = 0, key2Init = 0;
  20312. #define DH_TEST_TMP_SIZE 1024
  20313. #if !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  20314. #define DH_TEST_BUF_SIZE 256
  20315. #else
  20316. #define DH_TEST_BUF_SIZE 512
  20317. #endif
  20318. #ifndef WC_NO_RNG
  20319. word32 agreeSz = DH_TEST_BUF_SIZE;
  20320. word32 agreeSz2 = DH_TEST_BUF_SIZE;
  20321. #endif
  20322. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20323. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20324. DhKey *key2 = (DhKey *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20325. byte *tmp = (byte *)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20326. #else
  20327. DhKey key[1];
  20328. DhKey key2[1];
  20329. byte tmp[DH_TEST_TMP_SIZE];
  20330. #endif
  20331. #ifndef WC_NO_RNG
  20332. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20333. byte *priv = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20334. byte *pub = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20335. byte *priv2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20336. byte *pub2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20337. byte *agree = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20338. byte *agree2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20339. if (priv == NULL || pub == NULL || priv2 == NULL || pub2 == NULL ||
  20340. agree == NULL || agree2 == NULL) {
  20341. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20342. }
  20343. #else
  20344. byte priv[DH_TEST_BUF_SIZE];
  20345. byte pub[DH_TEST_BUF_SIZE];
  20346. byte priv2[DH_TEST_BUF_SIZE];
  20347. byte pub2[DH_TEST_BUF_SIZE];
  20348. byte agree[DH_TEST_BUF_SIZE];
  20349. byte agree2[DH_TEST_BUF_SIZE];
  20350. #endif
  20351. #endif /* !WC_NO_RNG */
  20352. WOLFSSL_ENTER("dh_test");
  20353. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20354. if (key == NULL || key2 == NULL || tmp == NULL) {
  20355. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20356. }
  20357. #endif
  20358. #ifdef USE_CERT_BUFFERS_1024
  20359. XMEMCPY(tmp, dh_key_der_1024, (size_t)sizeof_dh_key_der_1024);
  20360. bytes = (size_t)sizeof_dh_key_der_1024;
  20361. #elif defined(USE_CERT_BUFFERS_2048)
  20362. XMEMCPY(tmp, dh_key_der_2048, (size_t)sizeof_dh_key_der_2048);
  20363. bytes = (size_t)sizeof_dh_key_der_2048;
  20364. #elif defined(USE_CERT_BUFFERS_3072)
  20365. XMEMCPY(tmp, dh_key_der_3072, (size_t)sizeof_dh_key_der_3072);
  20366. bytes = (size_t)sizeof_dh_key_der_3072;
  20367. #elif defined(USE_CERT_BUFFERS_4096)
  20368. XMEMCPY(tmp, dh_key_der_4096, (size_t)sizeof_dh_key_der_4096);
  20369. bytes = (size_t)sizeof_dh_key_der_4096;
  20370. #elif defined(NO_ASN)
  20371. /* don't use file, no DER parsing */
  20372. #elif !defined(NO_FILESYSTEM)
  20373. {
  20374. XFILE file = XFOPEN(dhParamsFile, "rb");
  20375. if (! file)
  20376. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20377. bytes = (word32) XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20378. XFCLOSE(file);
  20379. if (bytes == 0)
  20380. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20381. }
  20382. #else
  20383. /* No DH key to use. */
  20384. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20385. #endif /* USE_CERT_BUFFERS */
  20386. (void)idx;
  20387. (void)tmp;
  20388. (void)bytes;
  20389. pubSz = DH_TEST_BUF_SIZE;
  20390. pubSz2 = DH_TEST_BUF_SIZE;
  20391. privSz = DH_TEST_BUF_SIZE;
  20392. privSz2 = DH_TEST_BUF_SIZE;
  20393. #ifndef WC_NO_RNG
  20394. XMEMSET(&rng, 0, sizeof(rng));
  20395. #endif
  20396. /* Use API for coverage. */
  20397. ret = wc_InitDhKey(key);
  20398. if (ret != 0)
  20399. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20400. wc_FreeDhKey(key);
  20401. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20402. if (ret != 0)
  20403. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20404. keyInit = 1;
  20405. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20406. if (ret != 0)
  20407. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20408. key2Init = 1;
  20409. #ifdef NO_ASN
  20410. #ifndef WOLFSSL_SP_MATH
  20411. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20412. if (ret != 0)
  20413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20414. ret = wc_DhSetKey(key2, 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. #else
  20418. ret = wc_DhSetKey(key, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20419. sizeof(dh2048_g));
  20420. if (ret != 0)
  20421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20422. ret = wc_DhSetKey(key2, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20423. sizeof(dh2048_g));
  20424. if (ret != 0)
  20425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20426. #endif
  20427. #else
  20428. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20429. if (ret != 0)
  20430. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20431. idx = 0;
  20432. ret = wc_DhKeyDecode(tmp, &idx, key2, bytes);
  20433. if (ret != 0)
  20434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20435. #endif
  20436. #ifndef WC_NO_RNG
  20437. #ifndef HAVE_FIPS
  20438. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20439. #else
  20440. ret = wc_InitRng(&rng);
  20441. #endif
  20442. if (ret != 0)
  20443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20444. rngInit = 1;
  20445. ret = wc_DhGenerateKeyPair(key, &rng, priv, &privSz, pub, &pubSz);
  20446. #if defined(WOLFSSL_ASYNC_CRYPT)
  20447. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20448. #endif
  20449. if (ret != 0)
  20450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20451. ret = wc_DhGenerateKeyPair(key2, &rng, priv2, &privSz2, pub2, &pubSz2);
  20452. #if defined(WOLFSSL_ASYNC_CRYPT)
  20453. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20454. #endif
  20455. if (ret != 0)
  20456. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20457. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20458. #if defined(WOLFSSL_ASYNC_CRYPT)
  20459. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20460. #endif
  20461. if (ret != 0)
  20462. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20463. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20464. #if defined(WOLFSSL_ASYNC_CRYPT)
  20465. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20466. #endif
  20467. if (ret != 0)
  20468. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20469. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20470. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20471. }
  20472. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) && \
  20473. !defined(HAVE_SELFTEST)
  20474. agreeSz = DH_TEST_BUF_SIZE;
  20475. agreeSz2 = DH_TEST_BUF_SIZE;
  20476. ret = wc_DhAgree_ct(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20477. if (ret != 0)
  20478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20479. ret = wc_DhAgree_ct(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20480. if (ret != 0)
  20481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20482. #ifdef WOLFSSL_PUBLIC_MP
  20483. if (agreeSz != (word32)mp_unsigned_bin_size(&key->p))
  20484. {
  20485. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20486. }
  20487. #endif
  20488. if (agreeSz != agreeSz2)
  20489. {
  20490. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20491. }
  20492. if (XMEMCMP(agree, agree2, agreeSz) != 0)
  20493. {
  20494. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20495. }
  20496. #endif /* (!HAVE_FIPS || FIPS_VERSION_GE(7,0)) && !HAVE_SELFTEST */
  20497. #endif /* !WC_NO_RNG */
  20498. #if defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20499. ret = wc_DhCheckPrivKey(NULL, NULL, 0);
  20500. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20502. ret = wc_DhCheckPrivKey(key, priv, privSz);
  20503. if (ret != 0)
  20504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20505. ret = wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  20506. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20508. {
  20509. word32 pSz, qSz, gSz;
  20510. ret = wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz);
  20511. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  20512. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20513. }
  20514. #endif
  20515. /* Test DH key import / export */
  20516. #if defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM) && \
  20517. (!defined(HAVE_FIPS) || \
  20518. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  20519. wc_FreeDhKey(key);
  20520. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20521. if (ret != 0)
  20522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20523. #ifndef NO_ASN
  20524. {
  20525. /* DH Private - Key Export / Import */
  20526. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20527. byte *tmp2;
  20528. #else
  20529. byte tmp2[DH_TEST_TMP_SIZE];
  20530. #endif
  20531. #if defined(USE_CERT_BUFFERS_2048)
  20532. XMEMCPY(tmp, dh_ffdhe_statickey_der_2048, sizeof_dh_ffdhe_statickey_der_2048);
  20533. bytes = sizeof_dh_ffdhe_statickey_der_2048;
  20534. #else
  20535. XFILE file = XFOPEN(dhKeyFile, "rb");
  20536. if (!file)
  20537. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20538. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20539. XFCLOSE(file);
  20540. if (bytes == 0)
  20541. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20542. #endif
  20543. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20544. tmp2 = (byte*)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20545. if (tmp2 == NULL)
  20546. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20547. #endif
  20548. idx = 0;
  20549. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20550. /* Import DH Private key as DER */
  20551. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20552. if (ret == 0) {
  20553. /* Export as DER */
  20554. idx = DH_TEST_TMP_SIZE;
  20555. ret = wc_DhPrivKeyToDer(key, tmp2, &idx);
  20556. }
  20557. /* Verify export matches original */
  20558. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20559. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20560. }
  20561. /* DH Public Key - Export / Import */
  20562. #if defined(USE_CERT_BUFFERS_2048)
  20563. XMEMCPY(tmp, dh_ffdhe_pub_statickey_der_2048, sizeof_dh_ffdhe_pub_statickey_der_2048);
  20564. bytes = sizeof_dh_ffdhe_pub_statickey_der_2048;
  20565. #else
  20566. file = XFOPEN(dhKeyPubFile, "rb");
  20567. if (!file)
  20568. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20569. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20570. XFCLOSE(file);
  20571. if (bytes == 0)
  20572. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20573. #endif
  20574. /* for HAVE_WOLF_BIGINT prevent leak */
  20575. wc_FreeDhKey(key);
  20576. (void)wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20577. idx = 0;
  20578. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20579. /* Import DH Public key as DER */
  20580. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20581. if (ret == 0) {
  20582. /* Export as DER */
  20583. idx = DH_TEST_TMP_SIZE;
  20584. ret = wc_DhPubKeyToDer(key, tmp2, &idx);
  20585. }
  20586. /* Verify export matches original */
  20587. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20588. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20589. }
  20590. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20591. XFREE(tmp2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20592. #endif
  20593. }
  20594. #else
  20595. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20596. if (ret != 0)
  20597. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20598. #endif /* !NO_ASN */
  20599. privSz = DH_TEST_BUF_SIZE;
  20600. pubSz = DH_TEST_BUF_SIZE;
  20601. ret = wc_DhExportKeyPair(key, priv, &privSz, pub, &pubSz);
  20602. if (ret != 0)
  20603. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20604. ret = wc_DhImportKeyPair(key2, priv, privSz, pub, pubSz);
  20605. if (ret != 0)
  20606. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20607. #endif /* WOLFSSL_DH_EXTRA && !NO_FILESYSTEM && !FIPS <= 2 */
  20608. #ifndef WC_NO_RNG
  20609. ret = dh_generate_test(&rng);
  20610. if (ret != 0)
  20611. ERROR_OUT(ret, done);
  20612. ret = dh_fips_generate_test(&rng);
  20613. if (ret != 0)
  20614. ERROR_OUT(ret, done);
  20615. #endif /* !WC_NO_RNG */
  20616. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20617. ret = dh_test_check_pubvalue();
  20618. if (ret != 0)
  20619. ERROR_OUT(ret, done);
  20620. #endif
  20621. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20622. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20623. /* RNG with DH and SP_ASM code not supported in the in-lined FIPS ASM code,
  20624. * this will be available for testing in the 140-3 module */
  20625. #ifndef WC_NO_RNG
  20626. /* Specialized code for key gen when using FFDHE-2048, FFDHE-3072 and FFDHE-4096 */
  20627. #ifdef HAVE_FFDHE_2048
  20628. #ifdef HAVE_PUBLIC_FFDHE
  20629. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe2048_Get());
  20630. #else
  20631. ret = dh_ffdhe_test(&rng, WC_FFDHE_2048);
  20632. #endif
  20633. if (ret != 0)
  20634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20635. #endif
  20636. #ifdef HAVE_FFDHE_3072
  20637. #ifdef HAVE_PUBLIC_FFDHE
  20638. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe3072_Get());
  20639. #else
  20640. ret = dh_ffdhe_test(&rng, WC_FFDHE_3072);
  20641. #endif
  20642. if (ret != 0)
  20643. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20644. #endif
  20645. #ifdef HAVE_FFDHE_4096
  20646. #ifdef HAVE_PUBLIC_FFDHE
  20647. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe4096_Get());
  20648. #else
  20649. ret = dh_ffdhe_test(&rng, WC_FFDHE_4096);
  20650. #endif
  20651. if (ret != 0)
  20652. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20653. #endif
  20654. #endif /* !WC_NO_RNG */
  20655. #endif /* HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM64_ASM */
  20656. wc_FreeDhKey(key);
  20657. keyInit = 0;
  20658. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  20659. !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(WC_NO_RNG)
  20660. /* Test Check Key */
  20661. ret = wc_DhSetCheckKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g),
  20662. NULL, 0, 0, &rng);
  20663. if (ret != 0)
  20664. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20665. keyInit = 1; /* DhSetCheckKey also initializes the key, free it */
  20666. #endif
  20667. done:
  20668. #ifndef WC_NO_RNG
  20669. if (rngInit)
  20670. wc_FreeRng(&rng);
  20671. #endif
  20672. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20673. if (key) {
  20674. if (keyInit)
  20675. wc_FreeDhKey(key);
  20676. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20677. }
  20678. if (key2) {
  20679. if (key2Init)
  20680. wc_FreeDhKey(key2);
  20681. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20682. }
  20683. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20684. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20685. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20686. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20687. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20688. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20689. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20690. #else
  20691. if (keyInit)
  20692. wc_FreeDhKey(key);
  20693. if (key2Init)
  20694. wc_FreeDhKey(key2);
  20695. #endif
  20696. (void)privSz;
  20697. (void)pubSz;
  20698. (void)pubSz2;
  20699. (void)privSz2;
  20700. return ret;
  20701. #undef DH_TEST_BUF_SIZE
  20702. #undef DH_TEST_TMP_SIZE
  20703. }
  20704. #endif /* NO_DH */
  20705. #ifndef NO_DSA
  20706. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void)
  20707. {
  20708. wc_test_ret_t ret = 0;
  20709. int answer;
  20710. word32 bytes;
  20711. word32 idx = 0;
  20712. WC_RNG rng;
  20713. int rng_inited = 0;
  20714. wc_Sha sha;
  20715. byte hash[WC_SHA_DIGEST_SIZE];
  20716. byte signature[40];
  20717. int key_inited = 0;
  20718. #ifdef WOLFSSL_KEY_GEN
  20719. byte* der = 0;
  20720. int derIn_inited = 0;
  20721. int genKey_inited = 0;
  20722. #endif
  20723. #define DSA_TEST_TMP_SIZE 1024
  20724. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20725. byte *tmp = (byte *)XMALLOC(DSA_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20726. DsaKey *key = (DsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20727. #ifdef WOLFSSL_KEY_GEN
  20728. DsaKey *derIn = (DsaKey *)XMALLOC(sizeof *derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20729. DsaKey *genKey = (DsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20730. #endif
  20731. WOLFSSL_ENTER("dsa_test");
  20732. if ((tmp == NULL) ||
  20733. (key == NULL)
  20734. #ifdef WOLFSSL_KEY_GEN
  20735. || (derIn == NULL)
  20736. || (genKey == NULL)
  20737. #endif
  20738. ) {
  20739. ret = WC_TEST_RET_ENC_NC;
  20740. goto out;
  20741. }
  20742. #else
  20743. byte tmp[1024];
  20744. DsaKey key[1];
  20745. #ifdef WOLFSSL_KEY_GEN
  20746. DsaKey derIn[1];
  20747. DsaKey genKey[1];
  20748. #endif
  20749. #endif
  20750. #ifdef USE_CERT_BUFFERS_1024
  20751. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20752. bytes = sizeof_dsa_key_der_1024;
  20753. #elif defined(USE_CERT_BUFFERS_2048)
  20754. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20755. bytes = sizeof_dsa_key_der_2048;
  20756. #else
  20757. {
  20758. XFILE file = XFOPEN(dsaKey, "rb");
  20759. if (!file)
  20760. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20761. bytes = (word32) XFREAD(tmp, 1, DSA_TEST_TMP_SIZE, file);
  20762. XFCLOSE(file);
  20763. if (bytes == 0)
  20764. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20765. }
  20766. #endif /* USE_CERT_BUFFERS */
  20767. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  20768. if (ret != 0)
  20769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20770. wc_ShaUpdate(&sha, tmp, bytes);
  20771. wc_ShaFinal(&sha, hash);
  20772. wc_ShaFree(&sha);
  20773. ret = wc_InitDsaKey(key);
  20774. if (ret != 0)
  20775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20776. key_inited = 1;
  20777. ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes);
  20778. if (ret != 0)
  20779. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20780. #ifndef HAVE_FIPS
  20781. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20782. #else
  20783. ret = wc_InitRng(&rng);
  20784. #endif
  20785. if (ret != 0)
  20786. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20787. rng_inited = 1;
  20788. ret = wc_DsaSign(hash, signature, key, &rng);
  20789. if (ret != 0)
  20790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20791. ret = wc_DsaVerify(hash, signature, key, &answer);
  20792. if (ret != 0)
  20793. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20794. if (answer != 1)
  20795. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20796. wc_FreeDsaKey(key);
  20797. key_inited = 0;
  20798. ret = wc_InitDsaKey_h(key, NULL);
  20799. if (ret != 0)
  20800. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20801. key_inited = 1;
  20802. #ifdef WOLFSSL_KEY_GEN
  20803. {
  20804. int derSz = 0;
  20805. ret = wc_InitDsaKey(genKey);
  20806. if (ret != 0)
  20807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20808. genKey_inited = 1;
  20809. ret = wc_MakeDsaParameters(&rng, 1024, genKey);
  20810. if (ret != 0)
  20811. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20812. ret = wc_MakeDsaKey(&rng, genKey);
  20813. if (ret != 0)
  20814. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20815. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20816. if (der == NULL)
  20817. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20818. derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF);
  20819. if (derSz < 0)
  20820. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out);
  20821. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  20822. DSA_PRIVATEKEY_TYPE);
  20823. if (ret != 0)
  20824. goto out;
  20825. ret = wc_InitDsaKey(derIn);
  20826. if (ret != 0)
  20827. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20828. derIn_inited = 1;
  20829. idx = 0;
  20830. ret = wc_DsaPrivateKeyDecode(der, &idx, derIn, (word32)derSz);
  20831. if (ret != 0)
  20832. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20833. }
  20834. #endif /* WOLFSSL_KEY_GEN */
  20835. out:
  20836. #ifdef WOLFSSL_KEY_GEN
  20837. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20838. #endif
  20839. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20840. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20841. if (key) {
  20842. if (key_inited)
  20843. wc_FreeDsaKey(key);
  20844. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20845. }
  20846. #ifdef WOLFSSL_KEY_GEN
  20847. if (derIn) {
  20848. if (derIn_inited)
  20849. wc_FreeDsaKey(derIn);
  20850. XFREE(derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20851. }
  20852. if (genKey) {
  20853. if (genKey_inited)
  20854. wc_FreeDsaKey(genKey);
  20855. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20856. }
  20857. #endif
  20858. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  20859. if (key_inited)
  20860. wc_FreeDsaKey(key);
  20861. #ifdef WOLFSSL_KEY_GEN
  20862. if (derIn_inited)
  20863. wc_FreeDsaKey(derIn);
  20864. if (genKey_inited)
  20865. wc_FreeDsaKey(genKey);
  20866. #endif
  20867. #endif
  20868. if (rng_inited)
  20869. wc_FreeRng(&rng);
  20870. return ret;
  20871. }
  20872. #endif /* NO_DSA */
  20873. #ifdef WOLFCRYPT_HAVE_SRP
  20874. static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
  20875. {
  20876. wc_test_ret_t ret = WC_TEST_RET_ENC_NC;
  20877. WC_RNG rng;
  20878. if(NULL == buf || !size)
  20879. return WC_TEST_RET_ENC_NC;
  20880. if (buf && size && wc_InitRng_ex(&rng, HEAP_HINT, devId) == 0) {
  20881. ret = wc_RNG_GenerateBlock(&rng, (byte *)buf, size);
  20882. wc_FreeRng(&rng);
  20883. }
  20884. return ret;
  20885. }
  20886. static wc_test_ret_t srp_test_digest(SrpType dgstType)
  20887. {
  20888. wc_test_ret_t r;
  20889. byte clientPubKey[192]; /* A */
  20890. byte serverPubKey[192]; /* B */
  20891. word32 clientPubKeySz = 192;
  20892. word32 serverPubKeySz = 192;
  20893. byte username[] = "user";
  20894. word32 usernameSz = 4;
  20895. byte password[] = "password";
  20896. word32 passwordSz = 8;
  20897. WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
  20898. 0xfc, 0x58, 0x7a, 0x8a, 0x70, 0xfb, 0x5a, 0x9a,
  20899. 0x5d, 0x39, 0x48, 0xbf, 0x1c, 0x46, 0xd8, 0x3b,
  20900. 0x7a, 0xe9, 0x1f, 0x85, 0x36, 0x18, 0xc4, 0x35,
  20901. 0x3f, 0xf8, 0x8a, 0x8f, 0x8c, 0x10, 0x2e, 0x01,
  20902. 0x58, 0x1d, 0x41, 0xcb, 0xc4, 0x47, 0xa8, 0xaf,
  20903. 0x9a, 0x6f, 0x58, 0x14, 0xa4, 0x68, 0xf0, 0x9c,
  20904. 0xa6, 0xe7, 0xbf, 0x0d, 0xe9, 0x62, 0x0b, 0xd7,
  20905. 0x26, 0x46, 0x5b, 0x27, 0xcb, 0x4c, 0xf9, 0x7e,
  20906. 0x1e, 0x8b, 0xe6, 0xdd, 0x29, 0xb7, 0xb7, 0x15,
  20907. 0x2e, 0xcf, 0x23, 0xa6, 0x4b, 0x97, 0x9f, 0x89,
  20908. 0xd4, 0x86, 0xc4, 0x90, 0x63, 0x92, 0xf4, 0x30,
  20909. 0x26, 0x69, 0x48, 0x9d, 0x7a, 0x4f, 0xad, 0xb5,
  20910. 0x6a, 0x51, 0xad, 0xeb, 0xf9, 0x90, 0x31, 0x77,
  20911. 0x53, 0x30, 0x2a, 0x85, 0xf7, 0x11, 0x21, 0x0c,
  20912. 0xb8, 0x4b, 0x56, 0x03, 0x5e, 0xbb, 0x25, 0x33,
  20913. 0x7c, 0xd9, 0x5a, 0xd1, 0x5c, 0xb2, 0xd4, 0x53,
  20914. 0xc5, 0x16, 0x68, 0xf0, 0xdf, 0x48, 0x55, 0x3e,
  20915. 0xd4, 0x59, 0x87, 0x64, 0x59, 0xaa, 0x39, 0x01,
  20916. 0x45, 0x89, 0x9c, 0x72, 0xff, 0xdd, 0x8f, 0x6d,
  20917. 0xa0, 0x42, 0xbc, 0x6f, 0x6e, 0x62, 0x18, 0x2d,
  20918. 0x50, 0xe8, 0x18, 0x97, 0x87, 0xfc, 0xef, 0x1f,
  20919. 0xf5, 0x53, 0x68, 0xe8, 0x49, 0xd1, 0xa2, 0xe8,
  20920. 0xb9, 0x26, 0x03, 0xba, 0xb5, 0x58, 0x6f, 0x6c,
  20921. 0x8b, 0x08, 0xa1, 0x7b, 0x6f, 0x42, 0xc9, 0x53
  20922. };
  20923. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  20924. 0x02
  20925. };
  20926. byte salt[10];
  20927. byte verifier[192];
  20928. word32 v_size = sizeof(verifier);
  20929. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  20930. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  20931. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20932. Srp *cli = (Srp *)XMALLOC(sizeof *cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20933. Srp *srv = (Srp *)XMALLOC(sizeof *srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20934. byte *clientProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20935. DYNAMIC_TYPE_TMP_BUFFER); /* M1 */
  20936. byte *serverProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20937. DYNAMIC_TYPE_TMP_BUFFER); /* M2 */
  20938. if ((cli == NULL) ||
  20939. (srv == NULL) ||
  20940. (clientProof == NULL) ||
  20941. (serverProof == NULL)) {
  20942. r = WC_TEST_RET_ENC_NC;
  20943. goto out;
  20944. }
  20945. #else
  20946. Srp cli[1], srv[1];
  20947. byte clientProof[SRP_MAX_DIGEST_SIZE]; /* M1 */
  20948. byte serverProof[SRP_MAX_DIGEST_SIZE]; /* M2 */
  20949. #endif
  20950. /* set as 0's so if second init on srv not called SrpTerm is not on
  20951. * garbage values */
  20952. XMEMSET(srv, 0, sizeof *srv);
  20953. XMEMSET(cli, 0, sizeof *cli);
  20954. /* generating random salt */
  20955. r = generate_random_salt(salt, sizeof(salt));
  20956. /* client knows username and password. */
  20957. /* server knows N, g, salt and verifier. */
  20958. if (!r) r = wc_SrpInit_ex(cli, dgstType, SRP_CLIENT_SIDE, HEAP_HINT, devId);
  20959. if (!r) r = wc_SrpSetUsername(cli, username, usernameSz);
  20960. /* loading N, g and salt in advance to generate the verifier. */
  20961. if (!r) r = wc_SrpSetParams(cli, N, sizeof(N),
  20962. g, sizeof(g),
  20963. salt, sizeof(salt));
  20964. if (!r) r = wc_SrpSetPassword(cli, password, passwordSz);
  20965. if (!r) r = wc_SrpGetVerifier(cli, verifier, &v_size);
  20966. /* client sends username to server */
  20967. if (!r) r = wc_SrpInit_ex(srv, dgstType, SRP_SERVER_SIDE, HEAP_HINT, devId);
  20968. if (!r) r = wc_SrpSetUsername(srv, username, usernameSz);
  20969. if (!r) r = wc_SrpSetParams(srv, N, sizeof(N),
  20970. g, sizeof(g),
  20971. salt, sizeof(salt));
  20972. if (!r) r = wc_SrpSetVerifier(srv, verifier, v_size);
  20973. if (!r) r = wc_SrpGetPublic(srv, serverPubKey, &serverPubKeySz);
  20974. /* server sends N, g, salt and B to client */
  20975. if (!r) r = wc_SrpGetPublic(cli, clientPubKey, &clientPubKeySz);
  20976. if (!r) r = wc_SrpComputeKey(cli, clientPubKey, clientPubKeySz,
  20977. serverPubKey, serverPubKeySz);
  20978. if (!r) r = wc_SrpGetProof(cli, clientProof, &clientProofSz);
  20979. /* client sends A and M1 to server */
  20980. if (!r) r = wc_SrpComputeKey(srv, clientPubKey, clientPubKeySz,
  20981. serverPubKey, serverPubKeySz);
  20982. if (!r) r = wc_SrpVerifyPeersProof(srv, clientProof, clientProofSz);
  20983. if (!r) r = wc_SrpGetProof(srv, serverProof, &serverProofSz);
  20984. /* server sends M2 to client */
  20985. if (!r) r = wc_SrpVerifyPeersProof(cli, serverProof, serverProofSz);
  20986. wc_SrpTerm(cli);
  20987. wc_SrpTerm(srv);
  20988. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20989. out:
  20990. XFREE(cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20991. XFREE(srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20992. XFREE(clientProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20993. XFREE(serverProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20994. #endif
  20995. return r;
  20996. }
  20997. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void)
  20998. {
  20999. wc_test_ret_t ret;
  21000. WOLFSSL_ENTER("srp_test");
  21001. #ifndef NO_SHA
  21002. ret = srp_test_digest(SRP_TYPE_SHA);
  21003. if (ret != 0)
  21004. return ret;
  21005. #endif
  21006. #ifndef NO_SHA256
  21007. ret = srp_test_digest(SRP_TYPE_SHA256);
  21008. if (ret != 0)
  21009. return ret;
  21010. #endif
  21011. #ifdef WOLFSSL_SHA384
  21012. ret = srp_test_digest(SRP_TYPE_SHA384);
  21013. if (ret != 0)
  21014. return ret;
  21015. #endif
  21016. #ifdef WOLFSSL_SHA512
  21017. ret = srp_test_digest(SRP_TYPE_SHA512);
  21018. if (ret != 0)
  21019. return ret;
  21020. #endif
  21021. return ret;
  21022. }
  21023. #endif /* WOLFCRYPT_HAVE_SRP */
  21024. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  21025. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  21026. static wc_test_ret_t openssl_aes_test(void)
  21027. {
  21028. #ifdef HAVE_AES_CBC
  21029. #ifdef WOLFSSL_AES_128
  21030. {
  21031. /* EVP_CipherUpdate test */
  21032. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21033. {
  21034. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21035. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21036. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21037. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21038. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21039. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21040. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21041. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21042. };
  21043. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21044. "0123456789abcdef "; /* align */
  21045. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21046. "1234567890abcdef "; /* align */
  21047. byte cipher[WC_AES_BLOCK_SIZE * 4];
  21048. byte plain [WC_AES_BLOCK_SIZE * 4];
  21049. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21050. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21051. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21052. #else
  21053. WOLFSSL_EVP_CIPHER_CTX en[1];
  21054. WOLFSSL_EVP_CIPHER_CTX de[1];
  21055. #endif
  21056. int outlen ;
  21057. int total = 0;
  21058. int i;
  21059. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21060. if ((en == NULL) || (de == NULL))
  21061. return MEMORY_E;
  21062. #endif
  21063. wolfSSL_EVP_CIPHER_CTX_init(en);
  21064. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21065. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21066. return WC_TEST_RET_ENC_NC;
  21067. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21068. (byte*)cbcPlain, 9) == 0)
  21069. return WC_TEST_RET_ENC_NC;
  21070. if (outlen != 0)
  21071. return WC_TEST_RET_ENC_NC;
  21072. total += outlen;
  21073. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21074. (byte*)&cbcPlain[9] , 9) == 0)
  21075. return WC_TEST_RET_ENC_NC;
  21076. if (outlen != 16)
  21077. return WC_TEST_RET_ENC_NC;
  21078. total += outlen;
  21079. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21080. return WC_TEST_RET_ENC_NC;
  21081. if (outlen != 16)
  21082. return WC_TEST_RET_ENC_NC;
  21083. total += outlen;
  21084. if (total != 32)
  21085. return 3408;
  21086. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21087. total = 0;
  21088. wolfSSL_EVP_CIPHER_CTX_init(de);
  21089. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21090. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21091. return WC_TEST_RET_ENC_NC;
  21092. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  21093. return WC_TEST_RET_ENC_NC;
  21094. if (outlen != 0)
  21095. return WC_TEST_RET_ENC_NC;
  21096. total += outlen;
  21097. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21098. (byte*)&cipher[6], 12) == 0)
  21099. return WC_TEST_RET_ENC_NC;
  21100. if (outlen != 0)
  21101. total += outlen;
  21102. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21103. (byte*)&cipher[6+12], 14) == 0)
  21104. return WC_TEST_RET_ENC_NC;
  21105. if (outlen != 16)
  21106. return WC_TEST_RET_ENC_NC;
  21107. total += outlen;
  21108. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21109. return WC_TEST_RET_ENC_NC;
  21110. if (outlen != 2)
  21111. return WC_TEST_RET_ENC_NC;
  21112. total += outlen;
  21113. if (total != 18)
  21114. return 3427;
  21115. if (XMEMCMP(plain, cbcPlain, 18))
  21116. return WC_TEST_RET_ENC_NC;
  21117. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21118. /* test with encrypting/decrypting more than 16 bytes at once */
  21119. total = 0;
  21120. wolfSSL_EVP_CIPHER_CTX_init(en);
  21121. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21122. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21123. return WC_TEST_RET_ENC_NC;
  21124. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21125. (byte*)cbcPlain, 17) == 0)
  21126. return WC_TEST_RET_ENC_NC;
  21127. if (outlen != 16)
  21128. return WC_TEST_RET_ENC_NC;
  21129. total += outlen;
  21130. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21131. (byte*)&cbcPlain[17] , 1) == 0)
  21132. return WC_TEST_RET_ENC_NC;
  21133. if (outlen != 0)
  21134. return WC_TEST_RET_ENC_NC;
  21135. total += outlen;
  21136. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21137. return WC_TEST_RET_ENC_NC;
  21138. if (outlen != 16)
  21139. return WC_TEST_RET_ENC_NC;
  21140. total += outlen;
  21141. if (total != 32)
  21142. return WC_TEST_RET_ENC_NC;
  21143. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21144. total = 0;
  21145. wolfSSL_EVP_CIPHER_CTX_init(de);
  21146. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21147. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21148. return WC_TEST_RET_ENC_NC;
  21149. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 17) == 0)
  21150. return WC_TEST_RET_ENC_NC;
  21151. if (outlen != 16)
  21152. return WC_TEST_RET_ENC_NC;
  21153. total += outlen;
  21154. /* final call on non block size should fail */
  21155. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21156. return WC_TEST_RET_ENC_NC;
  21157. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21158. (byte*)&cipher[17], 1) == 0)
  21159. return WC_TEST_RET_ENC_NC;
  21160. if (outlen != 0)
  21161. total += outlen;
  21162. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21163. (byte*)&cipher[17+1], 14) == 0)
  21164. return WC_TEST_RET_ENC_NC;
  21165. if (outlen != 0)
  21166. return WC_TEST_RET_ENC_NC;
  21167. total += outlen;
  21168. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21169. return WC_TEST_RET_ENC_NC;
  21170. if (outlen != 2)
  21171. return WC_TEST_RET_ENC_NC;
  21172. total += outlen;
  21173. if (total != 18)
  21174. return WC_TEST_RET_ENC_NC;
  21175. if (XMEMCMP(plain, cbcPlain, 18))
  21176. return WC_TEST_RET_ENC_NC;
  21177. /* test byte by byte decrypt */
  21178. for (i = 0; i < WC_AES_BLOCK_SIZE * 3; i++) {
  21179. plain[i] = i;
  21180. }
  21181. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21182. total = 0;
  21183. wolfSSL_EVP_CIPHER_CTX_init(en);
  21184. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21185. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21186. return WC_TEST_RET_ENC_NC;
  21187. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21188. (byte*)plain, WC_AES_BLOCK_SIZE * 3) == 0)
  21189. return WC_TEST_RET_ENC_NC;
  21190. if (outlen != WC_AES_BLOCK_SIZE * 3)
  21191. return WC_TEST_RET_ENC_NC;
  21192. total += outlen;
  21193. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21194. return WC_TEST_RET_ENC_NC;
  21195. if (outlen != WC_AES_BLOCK_SIZE)
  21196. return WC_TEST_RET_ENC_NC;
  21197. total += outlen;
  21198. if (total != sizeof(plain))
  21199. return WC_TEST_RET_ENC_NC;
  21200. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21201. total = 0;
  21202. wolfSSL_EVP_CIPHER_CTX_init(de);
  21203. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21204. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21205. return WC_TEST_RET_ENC_NC;
  21206. for (i = 0; i < WC_AES_BLOCK_SIZE * 4; i++) {
  21207. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain + total, &outlen,
  21208. (byte*)cipher + i, 1) == 0)
  21209. return WC_TEST_RET_ENC_NC;
  21210. if (outlen > 0) {
  21211. int j;
  21212. total += outlen;
  21213. for (j = 0; j < total; j++) {
  21214. if (plain[j] != j) {
  21215. return WC_TEST_RET_ENC_NC;
  21216. }
  21217. }
  21218. }
  21219. }
  21220. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21221. return WC_TEST_RET_ENC_NC;
  21222. total += outlen;
  21223. if (total != WC_AES_BLOCK_SIZE * 3) {
  21224. return WC_TEST_RET_ENC_NC;
  21225. }
  21226. for (i = 0; i < WC_AES_BLOCK_SIZE * 3; i++) {
  21227. if (plain[i] != i) {
  21228. return WC_TEST_RET_ENC_NC;
  21229. }
  21230. }
  21231. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21232. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21233. wolfSSL_EVP_CIPHER_CTX_free(en);
  21234. wolfSSL_EVP_CIPHER_CTX_free(de);
  21235. #endif
  21236. }
  21237. /* set buffers to be exact size to catch potential over read/write */
  21238. {
  21239. /* EVP_CipherUpdate test */
  21240. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21241. {
  21242. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21243. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21244. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21245. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21246. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21247. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21248. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21249. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21250. };
  21251. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21252. "0123456789abcdef "; /* align */
  21253. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21254. "1234567890abcdef "; /* align */
  21255. #define EVP_TEST_BUF_SZ 18
  21256. #define EVP_TEST_BUF_PAD 32
  21257. byte cipher[EVP_TEST_BUF_SZ];
  21258. byte plain [EVP_TEST_BUF_SZ];
  21259. byte padded[EVP_TEST_BUF_PAD];
  21260. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21261. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21262. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21263. #else
  21264. WOLFSSL_EVP_CIPHER_CTX en[1];
  21265. WOLFSSL_EVP_CIPHER_CTX de[1];
  21266. #endif
  21267. int outlen ;
  21268. int total = 0;
  21269. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21270. if ((en == NULL) || (de == NULL))
  21271. return MEMORY_E;
  21272. #endif
  21273. wolfSSL_EVP_CIPHER_CTX_init(en);
  21274. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21275. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21276. return WC_TEST_RET_ENC_NC;
  21277. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != 1)
  21278. return WC_TEST_RET_ENC_NC;
  21279. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21280. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21281. return WC_TEST_RET_ENC_NC;
  21282. if (outlen != 16)
  21283. return WC_TEST_RET_ENC_NC;
  21284. total += outlen;
  21285. /* should fail here */
  21286. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0)
  21287. return WC_TEST_RET_ENC_NC;
  21288. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21289. /* turn padding back on and do successful encrypt */
  21290. total = 0;
  21291. wolfSSL_EVP_CIPHER_CTX_init(en);
  21292. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21293. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21294. return WC_TEST_RET_ENC_NC;
  21295. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != 1)
  21296. return WC_TEST_RET_ENC_NC;
  21297. if (wolfSSL_EVP_CipherUpdate(en, (byte*)padded, &outlen,
  21298. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21299. return WC_TEST_RET_ENC_NC;
  21300. if (outlen != 16)
  21301. return WC_TEST_RET_ENC_NC;
  21302. total += outlen;
  21303. if (wolfSSL_EVP_CipherFinal(en, (byte*)&padded[total], &outlen) == 0)
  21304. return WC_TEST_RET_ENC_NC;
  21305. total += outlen;
  21306. if (total != 32)
  21307. return WC_TEST_RET_ENC_NC;
  21308. XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ);
  21309. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21310. /* test out of bounds read on buffers w/o padding during decryption */
  21311. total = 0;
  21312. wolfSSL_EVP_CIPHER_CTX_init(de);
  21313. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21314. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21315. return WC_TEST_RET_ENC_NC;
  21316. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 0) != 1)
  21317. return WC_TEST_RET_ENC_NC;
  21318. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher,
  21319. EVP_TEST_BUF_SZ) == 0)
  21320. return WC_TEST_RET_ENC_NC;
  21321. if (outlen != 16)
  21322. return WC_TEST_RET_ENC_NC;
  21323. total += outlen;
  21324. /* should fail since not using padding */
  21325. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21326. return WC_TEST_RET_ENC_NC;
  21327. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21328. total = 0;
  21329. wolfSSL_EVP_CIPHER_CTX_init(de);
  21330. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21331. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21332. return WC_TEST_RET_ENC_NC;
  21333. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 1) != 1)
  21334. return WC_TEST_RET_ENC_NC;
  21335. if (wolfSSL_EVP_CipherUpdate(de, (byte*)padded, &outlen, (byte*)padded,
  21336. EVP_TEST_BUF_PAD) == 0)
  21337. return WC_TEST_RET_ENC_NC;
  21338. if (outlen != 16)
  21339. return WC_TEST_RET_ENC_NC;
  21340. total += outlen;
  21341. if (wolfSSL_EVP_CipherFinal(de, (byte*)&padded[total], &outlen) == 0)
  21342. return WC_TEST_RET_ENC_NC;
  21343. if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ))
  21344. return WC_TEST_RET_ENC_NC;
  21345. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21346. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21347. wolfSSL_EVP_CIPHER_CTX_free(en);
  21348. wolfSSL_EVP_CIPHER_CTX_free(de);
  21349. #endif
  21350. }
  21351. { /* evp_cipher test: EVP_aes_128_cbc */
  21352. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21353. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21354. #else
  21355. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21356. #endif
  21357. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  21358. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  21359. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  21360. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  21361. };
  21362. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21363. {
  21364. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  21365. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  21366. };
  21367. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21368. "0123456789abcdef "; /* align */
  21369. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21370. "1234567890abcdef "; /* align */
  21371. byte cipher[WC_AES_BLOCK_SIZE * 4];
  21372. byte plain [WC_AES_BLOCK_SIZE * 4];
  21373. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21374. if (ctx == NULL)
  21375. return MEMORY_E;
  21376. #endif
  21377. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21378. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1) == 0)
  21379. return WC_TEST_RET_ENC_NC;
  21380. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21381. return WC_TEST_RET_ENC_NC;
  21382. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  21383. return WC_TEST_RET_ENC_NC;
  21384. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21385. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21386. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0) == 0)
  21387. return WC_TEST_RET_ENC_NC;
  21388. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21389. return WC_TEST_RET_ENC_NC;
  21390. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  21391. return WC_TEST_RET_ENC_NC;
  21392. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21393. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21394. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21395. #endif
  21396. } /* end evp_cipher test: EVP_aes_128_cbc*/
  21397. #endif /* WOLFSSL_AES_128 */
  21398. #endif /* HAVE_AES_CBC */
  21399. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21400. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  21401. { /* evp_cipher test: EVP_aes_256_ecb*/
  21402. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21403. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21404. #else
  21405. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21406. #endif
  21407. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21408. {
  21409. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21410. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21411. };
  21412. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21413. {
  21414. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21415. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21416. };
  21417. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21418. {
  21419. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21420. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21421. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21422. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21423. };
  21424. byte cipher[WC_AES_BLOCK_SIZE * 4];
  21425. byte plain [WC_AES_BLOCK_SIZE * 4];
  21426. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21427. if (ctx == NULL)
  21428. return MEMORY_E;
  21429. #endif
  21430. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21431. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1) == 0)
  21432. return WC_TEST_RET_ENC_NC;
  21433. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21434. return WC_TEST_RET_ENC_NC;
  21435. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  21436. return WC_TEST_RET_ENC_NC;
  21437. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21438. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0) == 0)
  21439. return WC_TEST_RET_ENC_NC;
  21440. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21441. return WC_TEST_RET_ENC_NC;
  21442. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  21443. return WC_TEST_RET_ENC_NC;
  21444. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21445. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21446. #endif
  21447. } /* end evp_cipher test */
  21448. #endif /* HAVE_AES_ECB && WOLFSSL_AES_256 */
  21449. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  21450. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  21451. {
  21452. /* Test: AES_encrypt/decrypt/set Key */
  21453. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21454. WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21455. #ifdef HAVE_AES_DECRYPT
  21456. WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21457. #endif
  21458. #else
  21459. WOLFSSL_AES_KEY enc[1];
  21460. #ifdef HAVE_AES_DECRYPT
  21461. WOLFSSL_AES_KEY dec[1];
  21462. #endif
  21463. #endif
  21464. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21465. {
  21466. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21467. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21468. };
  21469. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21470. {
  21471. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21472. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21473. };
  21474. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21475. {
  21476. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21477. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21478. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21479. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21480. };
  21481. byte plain[sizeof(msg)];
  21482. byte cipher[sizeof(msg)];
  21483. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21484. if (enc == NULL)
  21485. return MEMORY_E;
  21486. #ifdef HAVE_AES_DECRYPT
  21487. if (dec == NULL)
  21488. return MEMORY_E;
  21489. #endif
  21490. #endif
  21491. wolfSSL_AES_set_encrypt_key(key, sizeof(key)*8, enc);
  21492. wolfSSL_AES_set_decrypt_key(key, sizeof(key)*8, dec);
  21493. wolfSSL_AES_encrypt(msg, cipher, enc);
  21494. #ifdef HAVE_AES_DECRYPT
  21495. wolfSSL_AES_decrypt(cipher, plain, dec);
  21496. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  21497. return WC_TEST_RET_ENC_NC;
  21498. #endif /* HAVE_AES_DECRYPT */
  21499. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  21500. return WC_TEST_RET_ENC_NC;
  21501. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21502. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21503. #ifdef HAVE_AES_DECRYPT
  21504. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21505. #endif
  21506. #endif
  21507. }
  21508. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  21509. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21510. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  21511. #ifdef WOLFSSL_AES_COUNTER
  21512. {
  21513. byte plainBuff [64];
  21514. byte cipherBuff[64];
  21515. #ifdef WOLFSSL_AES_128
  21516. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  21517. {
  21518. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21519. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21520. };
  21521. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  21522. {
  21523. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21524. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21525. };
  21526. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  21527. {
  21528. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21529. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21530. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21531. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21532. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21533. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21534. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21535. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21536. };
  21537. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  21538. {
  21539. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  21540. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  21541. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  21542. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  21543. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  21544. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  21545. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  21546. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  21547. };
  21548. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  21549. {
  21550. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  21551. 0xc2
  21552. };
  21553. #endif
  21554. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21555. * NIST Special Publication 800-38A */
  21556. #ifdef WOLFSSL_AES_192
  21557. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  21558. {
  21559. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  21560. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  21561. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  21562. };
  21563. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  21564. {
  21565. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21566. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21567. };
  21568. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  21569. {
  21570. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21571. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21572. };
  21573. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  21574. {
  21575. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  21576. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  21577. };
  21578. #endif /* WOLFSSL_AES_192 */
  21579. #ifdef WOLFSSL_AES_256
  21580. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21581. * NIST Special Publication 800-38A */
  21582. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  21583. {
  21584. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21585. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21586. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21587. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21588. };
  21589. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  21590. {
  21591. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21592. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21593. };
  21594. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  21595. {
  21596. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21597. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21598. };
  21599. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  21600. {
  21601. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  21602. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  21603. };
  21604. #endif /* WOLFSSL_AES_256 */
  21605. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21606. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21607. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21608. #else
  21609. WOLFSSL_EVP_CIPHER_CTX en[1];
  21610. WOLFSSL_EVP_CIPHER_CTX de[1];
  21611. #endif
  21612. #ifdef WOLFSSL_AES_128
  21613. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21614. WOLFSSL_EVP_CIPHER_CTX *p_en;
  21615. WOLFSSL_EVP_CIPHER_CTX *p_de;
  21616. #endif
  21617. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21618. if ((en == NULL) || (de == NULL))
  21619. return MEMORY_E;
  21620. #endif
  21621. wolfSSL_EVP_CIPHER_CTX_init(en);
  21622. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21623. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21624. return WC_TEST_RET_ENC_NC;
  21625. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  21626. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  21627. return WC_TEST_RET_ENC_NC;
  21628. wolfSSL_EVP_CIPHER_CTX_init(de);
  21629. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21630. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21631. return WC_TEST_RET_ENC_NC;
  21632. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21633. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  21634. return WC_TEST_RET_ENC_NC;
  21635. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21636. return WC_TEST_RET_ENC_NC;
  21637. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21638. return WC_TEST_RET_ENC_NC;
  21639. if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4))
  21640. return WC_TEST_RET_ENC_NC;
  21641. if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4))
  21642. return WC_TEST_RET_ENC_NC;
  21643. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21644. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  21645. if (p_en == NULL)
  21646. return WC_TEST_RET_ENC_ERRNO;
  21647. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  21648. if (p_de == NULL)
  21649. return WC_TEST_RET_ENC_ERRNO;
  21650. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  21651. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21652. return WC_TEST_RET_ENC_NC;
  21653. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  21654. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  21655. return WC_TEST_RET_ENC_NC;
  21656. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  21657. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21658. return WC_TEST_RET_ENC_NC;
  21659. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  21660. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  21661. return WC_TEST_RET_ENC_NC;
  21662. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21663. return WC_TEST_RET_ENC_NC;
  21664. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21665. return WC_TEST_RET_ENC_NC;
  21666. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  21667. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  21668. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  21669. if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4))
  21670. return WC_TEST_RET_ENC_NC;
  21671. if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4))
  21672. return WC_TEST_RET_ENC_NC;
  21673. wolfSSL_EVP_CIPHER_CTX_init(en);
  21674. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21675. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21676. return WC_TEST_RET_ENC_NC;
  21677. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21678. return WC_TEST_RET_ENC_NC;
  21679. wolfSSL_EVP_CIPHER_CTX_init(de);
  21680. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21681. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21682. return WC_TEST_RET_ENC_NC;
  21683. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21684. return WC_TEST_RET_ENC_NC;
  21685. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21686. return WC_TEST_RET_ENC_NC;
  21687. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  21688. return WC_TEST_RET_ENC_NC;
  21689. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21690. return WC_TEST_RET_ENC_NC;
  21691. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21692. return WC_TEST_RET_ENC_NC;
  21693. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21694. return WC_TEST_RET_ENC_NC;
  21695. if (XMEMCMP(cipherBuff, oddCipher, 9))
  21696. return WC_TEST_RET_ENC_NC;
  21697. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21698. return WC_TEST_RET_ENC_NC;
  21699. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21700. return WC_TEST_RET_ENC_NC;
  21701. #endif /* WOLFSSL_AES_128 */
  21702. #ifdef WOLFSSL_AES_192
  21703. wolfSSL_EVP_CIPHER_CTX_init(en);
  21704. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  21705. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21706. return WC_TEST_RET_ENC_NC;
  21707. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  21708. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  21709. return WC_TEST_RET_ENC_NC;
  21710. wolfSSL_EVP_CIPHER_CTX_init(de);
  21711. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  21712. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21713. return WC_TEST_RET_ENC_NC;
  21714. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21715. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21716. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  21717. return WC_TEST_RET_ENC_NC;
  21718. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  21719. return WC_TEST_RET_ENC_NC;
  21720. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  21721. return WC_TEST_RET_ENC_NC;
  21722. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21723. return WC_TEST_RET_ENC_NC;
  21724. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21725. return WC_TEST_RET_ENC_NC;
  21726. #endif /* WOLFSSL_AES_192 */
  21727. #ifdef WOLFSSL_AES_256
  21728. wolfSSL_EVP_CIPHER_CTX_init(en);
  21729. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  21730. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21731. return WC_TEST_RET_ENC_NC;
  21732. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  21733. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  21734. return WC_TEST_RET_ENC_NC;
  21735. wolfSSL_EVP_CIPHER_CTX_init(de);
  21736. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  21737. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21738. return WC_TEST_RET_ENC_NC;
  21739. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21740. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21741. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  21742. return WC_TEST_RET_ENC_NC;
  21743. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  21744. return WC_TEST_RET_ENC_NC;
  21745. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  21746. return WC_TEST_RET_ENC_NC;
  21747. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21748. return WC_TEST_RET_ENC_NC;
  21749. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21750. return WC_TEST_RET_ENC_NC;
  21751. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21752. wolfSSL_EVP_CIPHER_CTX_free(en);
  21753. wolfSSL_EVP_CIPHER_CTX_free(de);
  21754. #endif
  21755. #endif /* WOLFSSL_AES_256 */
  21756. }
  21757. #endif /* HAVE_AES_COUNTER */
  21758. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21759. #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128)
  21760. {
  21761. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21762. WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21763. WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21764. #else
  21765. WOLFSSL_AES_KEY enc[1];
  21766. WOLFSSL_AES_KEY dec[1];
  21767. #endif
  21768. WOLFSSL_SMALL_STACK_STATIC const byte setIv[] = {
  21769. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  21770. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  21771. };
  21772. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21773. {
  21774. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21775. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21776. };
  21777. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  21778. {
  21779. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  21780. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  21781. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  21782. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b
  21783. };
  21784. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21785. {
  21786. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21787. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21788. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21789. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51
  21790. };
  21791. byte cipher[WC_AES_BLOCK_SIZE * 2];
  21792. byte iv[WC_AES_BLOCK_SIZE]; /* iv buffer is updeated by API */
  21793. int num = 0;
  21794. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21795. if ((enc == NULL) || (dec == NULL))
  21796. return MEMORY_E;
  21797. #endif
  21798. XMEMCPY(iv, setIv, sizeof(setIv));
  21799. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, enc);
  21800. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, dec);
  21801. wolfSSL_AES_cfb128_encrypt(msg, cipher, WC_AES_BLOCK_SIZE - 1, enc, iv,
  21802. &num, AES_ENCRYPTION);
  21803. if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE - 1))
  21804. return WC_TEST_RET_ENC_NC;
  21805. if (num != 15) /* should have used 15 of the 16 bytes */
  21806. return WC_TEST_RET_ENC_NC;
  21807. wolfSSL_AES_cfb128_encrypt(msg + WC_AES_BLOCK_SIZE - 1,
  21808. cipher + WC_AES_BLOCK_SIZE - 1, WC_AES_BLOCK_SIZE + 1, enc, iv,
  21809. &num, AES_ENCRYPTION);
  21810. if (XMEMCMP(cipher, cipher1, WC_AES_BLOCK_SIZE * 2))
  21811. return WC_TEST_RET_ENC_NC;
  21812. if (num != 0)
  21813. return WC_TEST_RET_ENC_NC;
  21814. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21815. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21816. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21817. #endif
  21818. }
  21819. #endif /* WOLFSSL_AES_CFB && WOLFSSL_AES_128 */
  21820. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21821. return 0;
  21822. }
  21823. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  21824. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void)
  21825. {
  21826. wc_test_ret_t ret;
  21827. #ifdef WOLFSSL_SMALL_STACK
  21828. WOLFSSL_EVP_MD_CTX *md_ctx = (WOLFSSL_EVP_MD_CTX *)XMALLOC(sizeof(WOLFSSL_EVP_MD_CTX), NULL, DYNAMIC_TYPE_OPENSSL);
  21829. #else
  21830. WOLFSSL_EVP_MD_CTX md_ctx[1];
  21831. #endif
  21832. testVector a, b, c, d, e, f;
  21833. byte hash[WC_SHA256_DIGEST_SIZE*2]; /* max size */
  21834. #ifdef WOLFSSL_SMALL_STACK
  21835. if (md_ctx == NULL)
  21836. return WC_TEST_RET_ENC_EC(MEMORY_E);
  21837. #endif
  21838. WOLFSSL_ENTER("openssl_test");
  21839. a.inLen = 0;
  21840. b.inLen = c.inLen = d.inLen = e.inLen = f.inLen = a.inLen;
  21841. (void)a;
  21842. (void)b;
  21843. (void)c;
  21844. (void)d;
  21845. (void)e;
  21846. (void)f;
  21847. /* test malloc / free , 10 is an arbitrary amount of memory chosen */
  21848. {
  21849. byte* p;
  21850. p = (byte*)wolfSSL_CRYPTO_malloc(10, "", 0);
  21851. if (p == NULL) {
  21852. return WC_TEST_RET_ENC_NC;
  21853. }
  21854. XMEMSET(p, 0, 10);
  21855. wolfSSL_CRYPTO_free(p, "", 0);
  21856. }
  21857. #ifndef NO_MD5
  21858. a.input = "1234567890123456789012345678901234567890123456789012345678"
  21859. "9012345678901234567890";
  21860. a.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  21861. "\x7a";
  21862. a.inLen = XSTRLEN(a.input);
  21863. a.outLen = WC_MD5_DIGEST_SIZE;
  21864. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21865. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_md5());
  21866. if (ret == WOLFSSL_SUCCESS) {
  21867. ret = wolfSSL_EVP_DigestUpdate(md_ctx, a.input, (unsigned long)a.inLen);
  21868. }
  21869. if (ret == WOLFSSL_SUCCESS) {
  21870. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21871. }
  21872. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21873. if (ret != WOLFSSL_SUCCESS)
  21874. return WC_TEST_RET_ENC_NC;
  21875. if (XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE) != 0)
  21876. return WC_TEST_RET_ENC_NC;
  21877. #endif /* NO_MD5 */
  21878. #ifndef NO_SHA
  21879. b.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21880. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21881. "aaaaaaaaaa";
  21882. b.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  21883. "\x53\x99\x5E\x26\xA0";
  21884. b.inLen = XSTRLEN(b.input);
  21885. b.outLen = WC_SHA_DIGEST_SIZE;
  21886. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21887. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha1());
  21888. if (ret == WOLFSSL_SUCCESS) {
  21889. ret = wolfSSL_EVP_DigestUpdate(md_ctx, b.input, (unsigned long)b.inLen);
  21890. if (ret == WOLFSSL_SUCCESS)
  21891. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21892. }
  21893. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21894. if (ret != WOLFSSL_SUCCESS)
  21895. return WC_TEST_RET_ENC_NC;
  21896. if (XMEMCMP(hash, b.output, b.outLen) != 0)
  21897. return WC_TEST_RET_ENC_NC;
  21898. #endif /* NO_SHA */
  21899. #ifdef WOLFSSL_SHA224
  21900. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21901. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21902. e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99"
  21903. "\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3";
  21904. e.inLen = XSTRLEN(e.input);
  21905. e.outLen = WC_SHA224_DIGEST_SIZE;
  21906. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21907. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha224());
  21908. if (ret == WOLFSSL_SUCCESS) {
  21909. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21910. if (ret == WOLFSSL_SUCCESS)
  21911. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21912. }
  21913. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21914. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21915. return WC_TEST_RET_ENC_NC;
  21916. }
  21917. #endif /* WOLFSSL_SHA224 */
  21918. #ifndef NO_SHA256
  21919. d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  21920. d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  21921. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  21922. "\x06\xC1";
  21923. d.inLen = XSTRLEN(d.input);
  21924. d.outLen = WC_SHA256_DIGEST_SIZE;
  21925. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21926. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha256());
  21927. if (ret == WOLFSSL_SUCCESS) {
  21928. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21929. if (ret == WOLFSSL_SUCCESS)
  21930. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21931. }
  21932. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21933. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21934. return WC_TEST_RET_ENC_NC;
  21935. }
  21936. #endif /* !NO_SHA256 */
  21937. #ifdef WOLFSSL_SHA384
  21938. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21939. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21940. e.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  21941. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  21942. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  21943. "\x74\x60\x39";
  21944. e.inLen = XSTRLEN(e.input);
  21945. e.outLen = WC_SHA384_DIGEST_SIZE;
  21946. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21947. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha384());
  21948. if (ret == WOLFSSL_SUCCESS) {
  21949. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21950. if (ret == WOLFSSL_SUCCESS)
  21951. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21952. }
  21953. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21954. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21955. return WC_TEST_RET_ENC_NC;
  21956. }
  21957. #endif /* WOLFSSL_SHA384 */
  21958. #ifdef WOLFSSL_SHA512
  21959. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21960. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21961. f.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  21962. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  21963. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  21964. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  21965. "\x87\x4b\xe9\x09";
  21966. f.inLen = XSTRLEN(f.input);
  21967. f.outLen = WC_SHA512_DIGEST_SIZE;
  21968. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21969. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512());
  21970. if (ret == WOLFSSL_SUCCESS) {
  21971. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21972. if (ret == WOLFSSL_SUCCESS)
  21973. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21974. }
  21975. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21976. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21977. return WC_TEST_RET_ENC_NC;
  21978. }
  21979. #if !defined(WOLFSSL_NOSHA512_224) && \
  21980. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21981. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21982. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21983. f.output = "\x23\xfe\xc5\xbb\x94\xd6\x0b\x23\x30\x81\x92\x64\x0b\x0c\x45"
  21984. "\x33\x35\xd6\x64\x73\x4f\xe4\x0e\x72\x68\x67\x4a\xf9";
  21985. f.inLen = XSTRLEN(f.input);
  21986. f.outLen = WC_SHA512_224_DIGEST_SIZE;
  21987. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21988. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_224());
  21989. if (ret == WOLFSSL_SUCCESS) {
  21990. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21991. if (ret == WOLFSSL_SUCCESS)
  21992. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21993. }
  21994. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21995. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21996. return WC_TEST_RET_ENC_NC;
  21997. }
  21998. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  21999. #if !defined(WOLFSSL_NOSHA512_256) && \
  22000. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  22001. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22002. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22003. f.output = "\x39\x28\xe1\x84\xfb\x86\x90\xf8\x40\xda\x39\x88\x12\x1d\x31"
  22004. "\xbe\x65\xcb\x9d\x3e\xf8\x3e\xe6\x14\x6f\xea\xc8\x61\xe1\x9b"
  22005. "\x56\x3a";
  22006. f.inLen = XSTRLEN(f.input);
  22007. f.outLen = WC_SHA512_256_DIGEST_SIZE;
  22008. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22009. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_256());
  22010. if (ret == WOLFSSL_SUCCESS) {
  22011. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22012. if (ret == WOLFSSL_SUCCESS)
  22013. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22014. }
  22015. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22016. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  22017. return WC_TEST_RET_ENC_NC;
  22018. }
  22019. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  22020. #endif /* WOLFSSL_SHA512 */
  22021. #ifdef WOLFSSL_SHA3
  22022. #ifndef WOLFSSL_NOSHA3_224
  22023. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22024. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22025. e.output = "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a"
  22026. "\xe5\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc";
  22027. e.inLen = XSTRLEN(e.input);
  22028. e.outLen = WC_SHA3_224_DIGEST_SIZE;
  22029. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22030. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_224());
  22031. if (ret == WOLFSSL_SUCCESS) {
  22032. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22033. if (ret == WOLFSSL_SUCCESS)
  22034. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22035. }
  22036. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22037. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22038. return WC_TEST_RET_ENC_NC;
  22039. }
  22040. #endif /* WOLFSSL_NOSHA3_224 */
  22041. #ifndef WOLFSSL_NOSHA3_256
  22042. d.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22043. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22044. d.output = "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf"
  22045. "\xdb\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad"
  22046. "\x1d\x18";
  22047. d.inLen = XSTRLEN(d.input);
  22048. d.outLen = WC_SHA3_256_DIGEST_SIZE;
  22049. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22050. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_256());
  22051. if (ret == WOLFSSL_SUCCESS) {
  22052. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  22053. if (ret == WOLFSSL_SUCCESS)
  22054. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22055. }
  22056. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22057. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  22058. return WC_TEST_RET_ENC_NC;
  22059. }
  22060. #endif /* WOLFSSL_NOSHA3_256 */
  22061. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22062. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22063. e.output = "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47"
  22064. "\x91\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6"
  22065. "\x25\xdc\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79"
  22066. "\xaa\x7f\xc7";
  22067. e.inLen = XSTRLEN(e.input);
  22068. e.outLen = WC_SHA3_384_DIGEST_SIZE;
  22069. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22070. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_384());
  22071. if (ret == WOLFSSL_SUCCESS) {
  22072. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22073. if (ret == WOLFSSL_SUCCESS)
  22074. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22075. }
  22076. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22077. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22078. return WC_TEST_RET_ENC_NC;
  22079. }
  22080. #ifndef WOLFSSL_NOSHA3_512
  22081. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22082. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22083. f.output = "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78"
  22084. "\xf9\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18"
  22085. "\xa4\xfa\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8"
  22086. "\x2e\x21\x89\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55"
  22087. "\xf2\x1d\xd1\x85";
  22088. f.inLen = XSTRLEN(f.input);
  22089. f.outLen = WC_SHA3_512_DIGEST_SIZE;
  22090. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22091. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_512());
  22092. if (ret == WOLFSSL_SUCCESS) {
  22093. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22094. if (ret == WOLFSSL_SUCCESS)
  22095. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22096. }
  22097. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22098. if (ret != WOLFSSL_SUCCESS ||
  22099. XMEMCMP(hash, f.output, f.outLen) != 0) {
  22100. return WC_TEST_RET_ENC_NC;
  22101. }
  22102. #endif /* WOLFSSL_NOSHA3_512 */
  22103. #endif /* WOLFSSL_SHA3 */
  22104. #ifdef WOLFSSL_SMALL_STACK
  22105. XFREE(md_ctx, NULL, DYNAMIC_TYPE_OPENSSL);
  22106. md_ctx = NULL;
  22107. #endif
  22108. #ifndef WC_NO_RNG
  22109. if (wolfSSL_RAND_bytes(hash, sizeof(hash)) != WOLFSSL_SUCCESS)
  22110. return WC_TEST_RET_ENC_NC;
  22111. #endif
  22112. #ifndef NO_MD5
  22113. c.input = "what do ya want for nothing?";
  22114. c.output = "\x55\x78\xe8\x48\x4b\xcc\x93\x80\x93\xec\x53\xaf\x22\xd6\x14"
  22115. "\x76";
  22116. c.inLen = XSTRLEN(c.input);
  22117. c.outLen = WC_MD5_DIGEST_SIZE;
  22118. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)
  22119. /* Expect failure with MD5 + HMAC when using FIPS 140-3. */
  22120. if (wolfSSL_HMAC(wolfSSL_EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22121. hash, 0) != NULL)
  22122. #else
  22123. if (wolfSSL_HMAC(wolfSSL_EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22124. hash, 0) == NULL ||
  22125. XMEMCMP(hash, c.output, c.outLen) != 0)
  22126. #endif
  22127. {
  22128. return WC_TEST_RET_ENC_NC;
  22129. }
  22130. #endif /* NO_MD5 */
  22131. #ifndef NO_DES3
  22132. { /* des test */
  22133. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  22134. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22135. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22136. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22137. };
  22138. byte plain[24];
  22139. byte cipher[24];
  22140. WOLFSSL_const_DES_cblock key = {
  22141. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  22142. };
  22143. WOLFSSL_DES_cblock iv = {
  22144. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  22145. };
  22146. WOLFSSL_DES_key_schedule sched;
  22147. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22148. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  22149. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  22150. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  22151. };
  22152. wolfSSL_DES_key_sched(&key, &sched);
  22153. wolfSSL_DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, WC_DES_ENCRYPT);
  22154. wolfSSL_DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, WC_DES_DECRYPT);
  22155. if (XMEMCMP(plain, vector, sizeof(vector)) != 0)
  22156. return WC_TEST_RET_ENC_NC;
  22157. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22158. return WC_TEST_RET_ENC_NC;
  22159. /* test changing iv */
  22160. wolfSSL_DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, WC_DES_ENCRYPT);
  22161. wolfSSL_DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, WC_DES_ENCRYPT);
  22162. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22163. return WC_TEST_RET_ENC_NC;
  22164. } /* end des test */
  22165. #endif /* NO_DES3 */
  22166. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  22167. if ((ret = openssl_aes_test()) != 0) {
  22168. return ret;
  22169. }
  22170. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  22171. { /* evp_cipher test: EVP_aes_128_cbc */
  22172. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22173. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22174. #else
  22175. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22176. #endif
  22177. int idx, cipherSz, plainSz;
  22178. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  22179. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22180. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22181. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22182. };
  22183. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22184. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22185. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22186. 0x3b,0x5d,0x41,0x97,0x94,0x25,0xa4,0xb4,
  22187. 0xae,0x7b,0x34,0xd0,0x3f,0x0c,0xbc,0x06
  22188. };
  22189. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  22190. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22191. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22192. 0x7d,0x37,0x7b,0x0b,0x44,0xaa,0xb5,0xf0,
  22193. 0x5f,0x34,0xb4,0xde,0xb5,0xbd,0x2a,0xbb
  22194. };
  22195. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22196. "0123456789abcdef "; /* align */
  22197. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  22198. "1234567890abcdef "; /* align */
  22199. byte cipher[WC_AES_BLOCK_SIZE * 4];
  22200. byte plain [WC_AES_BLOCK_SIZE * 4];
  22201. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22202. if (ctx == NULL)
  22203. return MEMORY_E;
  22204. #endif
  22205. cipherSz = 0;
  22206. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22207. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22208. if (ret == WOLFSSL_SUCCESS) {
  22209. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, (byte*)msg, sizeof(msg));
  22210. if (ret == WOLFSSL_SUCCESS)
  22211. cipherSz += idx;
  22212. }
  22213. if (ret == WOLFSSL_SUCCESS) {
  22214. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22215. if (ret == WOLFSSL_SUCCESS)
  22216. cipherSz += idx;
  22217. }
  22218. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22219. if (ret != WOLFSSL_SUCCESS)
  22220. return WC_TEST_RET_ENC_NC;
  22221. if (cipherSz != (int)sizeof(verify) || XMEMCMP(cipher, verify, cipherSz))
  22222. return WC_TEST_RET_ENC_NC;
  22223. /* check partial decrypt (not enough padding for full block) */
  22224. plainSz = 0;
  22225. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22226. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22227. if (ret == WOLFSSL_SUCCESS) {
  22228. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, 1);
  22229. if (ret == WOLFSSL_SUCCESS)
  22230. plainSz += idx;
  22231. }
  22232. if (ret == WOLFSSL_SUCCESS) {
  22233. /* this test should fail... not enough padding for full block */
  22234. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22235. if (plainSz == 0 && ret != WOLFSSL_SUCCESS)
  22236. ret = WOLFSSL_SUCCESS;
  22237. else
  22238. ret = WC_TEST_RET_ENC_NC;
  22239. }
  22240. else
  22241. ret = WC_TEST_RET_ENC_NC;
  22242. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22243. if (ret != WOLFSSL_SUCCESS)
  22244. return ret;
  22245. plainSz = 0;
  22246. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22247. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22248. if (ret == WOLFSSL_SUCCESS) {
  22249. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, cipherSz);
  22250. if (ret == WOLFSSL_SUCCESS)
  22251. plainSz += idx;
  22252. }
  22253. if (ret == WOLFSSL_SUCCESS) {
  22254. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22255. if (ret == WOLFSSL_SUCCESS)
  22256. plainSz += idx;
  22257. }
  22258. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22259. if (ret != WOLFSSL_SUCCESS)
  22260. return WC_TEST_RET_ENC_NC;
  22261. if (plainSz != (int)sizeof(msg) || XMEMCMP(plain, msg, sizeof(msg)))
  22262. return WC_TEST_RET_ENC_NC;
  22263. cipherSz = 0;
  22264. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22265. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22266. if (ret == WOLFSSL_SUCCESS) {
  22267. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, msg, WC_AES_BLOCK_SIZE);
  22268. if (ret == WOLFSSL_SUCCESS)
  22269. cipherSz += idx;
  22270. }
  22271. if (ret == WOLFSSL_SUCCESS) {
  22272. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22273. if (ret == WOLFSSL_SUCCESS)
  22274. cipherSz += idx;
  22275. }
  22276. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22277. if (ret != WOLFSSL_SUCCESS)
  22278. return WC_TEST_RET_ENC_NC;
  22279. if (cipherSz != (int)sizeof(verify2) || XMEMCMP(cipher, verify2, cipherSz))
  22280. return WC_TEST_RET_ENC_NC;
  22281. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22282. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22283. #endif
  22284. } /* end evp_cipher test: EVP_aes_128_cbc*/
  22285. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22286. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  22287. { /* evp_cipher test: EVP_aes_256_ecb*/
  22288. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22289. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22290. #else
  22291. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22292. #endif
  22293. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  22294. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22295. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22296. };
  22297. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22298. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22299. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22300. };
  22301. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  22302. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22303. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22304. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22305. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22306. };
  22307. byte cipher[WC_AES_BLOCK_SIZE * 4];
  22308. byte plain [WC_AES_BLOCK_SIZE * 4];
  22309. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22310. if (ctx == NULL)
  22311. return MEMORY_E;
  22312. #endif
  22313. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22314. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1);
  22315. if (ret == WOLFSSL_SUCCESS)
  22316. ret = wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16);
  22317. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22318. if (ret != 16)
  22319. return WC_TEST_RET_ENC_NC;
  22320. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  22321. return WC_TEST_RET_ENC_NC;
  22322. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22323. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0);
  22324. if (ret == WOLFSSL_SUCCESS)
  22325. ret = wolfSSL_EVP_Cipher(ctx, plain, cipher, 16);
  22326. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22327. if (ret != 16)
  22328. return WC_TEST_RET_ENC_NC;
  22329. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  22330. return WC_TEST_RET_ENC_NC;
  22331. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22332. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22333. #endif
  22334. } /* end evp_cipher test */
  22335. #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */
  22336. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  22337. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  22338. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  22339. {
  22340. /* Test: AES_encrypt/decrypt/set Key */
  22341. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22342. WOLFSSL_AES_KEY *enc = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22343. #ifdef HAVE_AES_DECRYPT
  22344. WOLFSSL_AES_KEY *dec = (WOLFSSL_AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22345. #endif
  22346. #else
  22347. WOLFSSL_AES_KEY enc[1];
  22348. #ifdef HAVE_AES_DECRYPT
  22349. WOLFSSL_AES_KEY dec[1];
  22350. #endif
  22351. #endif
  22352. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  22353. {
  22354. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22355. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22356. };
  22357. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  22358. {
  22359. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22360. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22361. };
  22362. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22363. {
  22364. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22365. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22366. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22367. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22368. };
  22369. byte plain[sizeof(msg)];
  22370. byte cipher[sizeof(msg)];
  22371. printf("openSSL extra test\n") ;
  22372. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22373. if (enc == NULL)
  22374. return MEMORY_E;
  22375. #ifdef HAVE_AES_DECRYPT
  22376. if (dec == NULL)
  22377. return MEMORY_E;
  22378. #endif
  22379. #endif
  22380. wolfSSL_AES_set_encrypt_key(key, sizeof(key)*8, enc);
  22381. wolfSSL_AES_set_decrypt_key(key, sizeof(key)*8, dec);
  22382. wolfSSL_AES_encrypt(msg, cipher, enc);
  22383. #ifdef HAVE_AES_DECRYPT
  22384. wolfSSL_AES_decrypt(cipher, plain, dec);
  22385. if (XMEMCMP(plain, msg, WC_AES_BLOCK_SIZE))
  22386. return WC_TEST_RET_ENC_NC;
  22387. #endif /* HAVE_AES_DECRYPT */
  22388. if (XMEMCMP(cipher, verify, WC_AES_BLOCK_SIZE))
  22389. return WC_TEST_RET_ENC_NC;
  22390. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22391. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22392. #ifdef HAVE_AES_DECRYPT
  22393. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22394. #endif
  22395. #endif
  22396. }
  22397. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  22398. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  22399. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  22400. #ifdef WOLFSSL_AES_COUNTER
  22401. {
  22402. byte plainBuff [64];
  22403. byte cipherBuff[64];
  22404. #ifdef WOLFSSL_AES_128
  22405. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  22406. {
  22407. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  22408. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  22409. };
  22410. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  22411. {
  22412. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22413. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22414. };
  22415. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  22416. {
  22417. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22418. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22419. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22420. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22421. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22422. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22423. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22424. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22425. };
  22426. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  22427. {
  22428. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  22429. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  22430. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  22431. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  22432. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  22433. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  22434. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  22435. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  22436. };
  22437. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  22438. {
  22439. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  22440. 0xc2
  22441. };
  22442. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22443. WOLFSSL_EVP_CIPHER_CTX *p_en;
  22444. WOLFSSL_EVP_CIPHER_CTX *p_de;
  22445. #endif
  22446. #endif /* WOLFSSL_AES_128 */
  22447. #ifdef WOLFSSL_AES_192
  22448. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22449. * NIST Special Publication 800-38A */
  22450. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  22451. {
  22452. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  22453. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  22454. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  22455. };
  22456. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  22457. {
  22458. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22459. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22460. };
  22461. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  22462. {
  22463. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22464. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22465. };
  22466. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  22467. {
  22468. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  22469. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  22470. };
  22471. #endif /* WOLFSSL_AES_192 */
  22472. #ifdef WOLFSSL_AES_256
  22473. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22474. * NIST Special Publication 800-38A */
  22475. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  22476. {
  22477. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22478. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22479. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22480. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22481. };
  22482. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  22483. {
  22484. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22485. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22486. };
  22487. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  22488. {
  22489. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22490. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22491. };
  22492. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  22493. {
  22494. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  22495. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  22496. };
  22497. #endif /* WOLFSSL_AES_256 */
  22498. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22499. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22500. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22501. if ((en == NULL) || (de == NULL))
  22502. return MEMORY_E;
  22503. #else
  22504. WOLFSSL_EVP_CIPHER_CTX en[1];
  22505. WOLFSSL_EVP_CIPHER_CTX de[1];
  22506. #endif
  22507. #ifdef WOLFSSL_AES_128
  22508. wolfSSL_EVP_CIPHER_CTX_init(en);
  22509. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22510. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22511. return WC_TEST_RET_ENC_NC;
  22512. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  22513. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  22514. return WC_TEST_RET_ENC_NC;
  22515. wolfSSL_EVP_CIPHER_CTX_init(de);
  22516. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22517. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22518. return WC_TEST_RET_ENC_NC;
  22519. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22520. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  22521. return WC_TEST_RET_ENC_NC;
  22522. if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4))
  22523. return WC_TEST_RET_ENC_NC;
  22524. if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4))
  22525. return WC_TEST_RET_ENC_NC;
  22526. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22527. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22528. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22529. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  22530. if (p_en == NULL)
  22531. return WC_TEST_RET_ENC_ERRNO;
  22532. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  22533. if (p_de == NULL)
  22534. return WC_TEST_RET_ENC_ERRNO;
  22535. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  22536. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22537. return WC_TEST_RET_ENC_NC;
  22538. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  22539. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  22540. return WC_TEST_RET_ENC_NC;
  22541. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  22542. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22543. return WC_TEST_RET_ENC_NC;
  22544. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  22545. WC_AES_BLOCK_SIZE*4) != WC_AES_BLOCK_SIZE*4)
  22546. return WC_TEST_RET_ENC_NC;
  22547. wolfSSL_EVP_CIPHER_CTX_cleanup(p_en);
  22548. wolfSSL_EVP_CIPHER_CTX_cleanup(p_de);
  22549. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  22550. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  22551. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  22552. if (XMEMCMP(cipherBuff, ctrCipher, WC_AES_BLOCK_SIZE*4))
  22553. return WC_TEST_RET_ENC_NC;
  22554. if (XMEMCMP(plainBuff, ctrPlain, WC_AES_BLOCK_SIZE*4))
  22555. return WC_TEST_RET_ENC_NC;
  22556. wolfSSL_EVP_CIPHER_CTX_init(en);
  22557. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22558. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22559. return WC_TEST_RET_ENC_NC;
  22560. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22561. return WC_TEST_RET_ENC_NC;
  22562. wolfSSL_EVP_CIPHER_CTX_init(de);
  22563. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22564. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22565. return WC_TEST_RET_ENC_NC;
  22566. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22567. return WC_TEST_RET_ENC_NC;
  22568. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22569. return WC_TEST_RET_ENC_NC;
  22570. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  22571. return WC_TEST_RET_ENC_NC;
  22572. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22573. return WC_TEST_RET_ENC_NC;
  22574. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22575. return WC_TEST_RET_ENC_NC;
  22576. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22577. return WC_TEST_RET_ENC_NC;
  22578. if (XMEMCMP(cipherBuff, oddCipher, 9))
  22579. return WC_TEST_RET_ENC_NC;
  22580. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22581. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22582. #endif /* WOLFSSL_AES_128 */
  22583. #ifdef WOLFSSL_AES_192
  22584. wolfSSL_EVP_CIPHER_CTX_init(en);
  22585. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  22586. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22587. return WC_TEST_RET_ENC_NC;
  22588. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  22589. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  22590. return WC_TEST_RET_ENC_NC;
  22591. wolfSSL_EVP_CIPHER_CTX_init(de);
  22592. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  22593. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22594. return WC_TEST_RET_ENC_NC;
  22595. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22596. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22597. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  22598. return WC_TEST_RET_ENC_NC;
  22599. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  22600. return WC_TEST_RET_ENC_NC;
  22601. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  22602. return WC_TEST_RET_ENC_NC;
  22603. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22604. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22605. #endif /* WOLFSSL_AES_192 */
  22606. #ifdef WOLFSSL_AES_256
  22607. wolfSSL_EVP_CIPHER_CTX_init(en);
  22608. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  22609. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22610. return WC_TEST_RET_ENC_NC;
  22611. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  22612. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  22613. return WC_TEST_RET_ENC_NC;
  22614. wolfSSL_EVP_CIPHER_CTX_init(de);
  22615. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  22616. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22617. return WC_TEST_RET_ENC_NC;
  22618. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22619. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22620. WC_AES_BLOCK_SIZE) != WC_AES_BLOCK_SIZE)
  22621. return WC_TEST_RET_ENC_NC;
  22622. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  22623. return WC_TEST_RET_ENC_NC;
  22624. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  22625. return WC_TEST_RET_ENC_NC;
  22626. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22627. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22628. #endif /* WOLFSSL_AES_256 */
  22629. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22630. wolfSSL_EVP_CIPHER_CTX_free(en);
  22631. wolfSSL_EVP_CIPHER_CTX_free(de);
  22632. #endif
  22633. }
  22634. #endif /* HAVE_AES_COUNTER */
  22635. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22636. {
  22637. /* EVP_CipherUpdate test */
  22638. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  22639. {
  22640. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22641. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22642. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22643. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22644. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22645. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22646. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22647. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22648. };
  22649. byte key[] = "0123456789abcdef "; /* align */
  22650. byte iv[] = "1234567890abcdef "; /* align */
  22651. byte cipher[WC_AES_BLOCK_SIZE * 4];
  22652. byte plain [WC_AES_BLOCK_SIZE * 4];
  22653. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22654. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22655. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22656. #else
  22657. WOLFSSL_EVP_CIPHER_CTX en[1];
  22658. WOLFSSL_EVP_CIPHER_CTX de[1];
  22659. #endif
  22660. int outlen ;
  22661. int total = 0;
  22662. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22663. if ((en == NULL) || (de == NULL))
  22664. return MEMORY_E;
  22665. #endif
  22666. wolfSSL_EVP_CIPHER_CTX_init(en);
  22667. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22668. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22669. return WC_TEST_RET_ENC_NC;
  22670. /* openSSL compatibility, if(inlen == 0)return 1; */
  22671. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22672. (byte*)cbcPlain, 0) != 1)
  22673. return WC_TEST_RET_ENC_NC;
  22674. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22675. return WC_TEST_RET_ENC_NC;
  22676. wolfSSL_EVP_CIPHER_CTX_init(en);
  22677. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22678. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22679. return WC_TEST_RET_ENC_NC;
  22680. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22681. (byte*)cbcPlain, 9) == 0)
  22682. return WC_TEST_RET_ENC_NC;
  22683. if(outlen != 0)
  22684. return WC_TEST_RET_ENC_NC;
  22685. total += outlen;
  22686. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  22687. (byte*)&cbcPlain[9] , 9) == 0)
  22688. return WC_TEST_RET_ENC_NC;
  22689. if(outlen != 16)
  22690. return WC_TEST_RET_ENC_NC;
  22691. total += outlen;
  22692. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22693. return WC_TEST_RET_ENC_NC;
  22694. if(outlen != 16)
  22695. return WC_TEST_RET_ENC_NC;
  22696. total += outlen;
  22697. if(total != 32)
  22698. return WC_TEST_RET_ENC_NC;
  22699. total = 0;
  22700. wolfSSL_EVP_CIPHER_CTX_init(de);
  22701. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  22702. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22703. return WC_TEST_RET_ENC_NC;
  22704. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22705. return WC_TEST_RET_ENC_NC;
  22706. if(outlen != 0)
  22707. return WC_TEST_RET_ENC_NC;
  22708. total += outlen;
  22709. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22710. (byte*)&cipher[6], 12) == 0)
  22711. return WC_TEST_RET_ENC_NC;
  22712. if(outlen != 0)
  22713. total += outlen;
  22714. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22715. (byte*)&cipher[6+12], 14) == 0)
  22716. return WC_TEST_RET_ENC_NC;
  22717. if(outlen != 16)
  22718. return WC_TEST_RET_ENC_NC;
  22719. total += outlen;
  22720. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  22721. return WC_TEST_RET_ENC_NC;
  22722. if(outlen != 2)
  22723. return WC_TEST_RET_ENC_NC;
  22724. total += outlen;
  22725. if(total != 18)
  22726. return WC_TEST_RET_ENC_NC;
  22727. if (XMEMCMP(plain, cbcPlain, 18))
  22728. return WC_TEST_RET_ENC_NC;
  22729. total = 0;
  22730. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22731. return WC_TEST_RET_ENC_NC;
  22732. wolfSSL_EVP_CIPHER_CTX_init(en);
  22733. if (wolfSSL_EVP_EncryptInit(en, wolfSSL_EVP_aes_128_cbc(),
  22734. (unsigned char*)key, (unsigned char*)iv) == 0)
  22735. return WC_TEST_RET_ENC_NC;
  22736. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0)
  22737. return WC_TEST_RET_ENC_NC;
  22738. if(outlen != 0)
  22739. return WC_TEST_RET_ENC_NC;
  22740. total += outlen;
  22741. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0)
  22742. return WC_TEST_RET_ENC_NC;
  22743. if(outlen != 16)
  22744. return WC_TEST_RET_ENC_NC;
  22745. total += outlen;
  22746. if (wolfSSL_EVP_EncryptFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22747. return WC_TEST_RET_ENC_NC;
  22748. if(outlen != 16)
  22749. return WC_TEST_RET_ENC_NC;
  22750. total += outlen;
  22751. if(total != 32)
  22752. return 3438;
  22753. total = 0;
  22754. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22755. return WC_TEST_RET_ENC_NC;
  22756. wolfSSL_EVP_CIPHER_CTX_init(de);
  22757. if (wolfSSL_EVP_DecryptInit(de, wolfSSL_EVP_aes_128_cbc(),
  22758. (unsigned char*)key, (unsigned char*)iv) == 0)
  22759. return WC_TEST_RET_ENC_NC;
  22760. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22761. return WC_TEST_RET_ENC_NC;
  22762. if(outlen != 0)
  22763. return WC_TEST_RET_ENC_NC;
  22764. total += outlen;
  22765. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0)
  22766. return WC_TEST_RET_ENC_NC;
  22767. if(outlen != 0)
  22768. total += outlen;
  22769. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0)
  22770. return WC_TEST_RET_ENC_NC;
  22771. if(outlen != 16)
  22772. return WC_TEST_RET_ENC_NC;
  22773. total += outlen;
  22774. if (wolfSSL_EVP_DecryptFinal(de, (byte*)&plain[total], &outlen) == 0)
  22775. return WC_TEST_RET_ENC_NC;
  22776. if(outlen != 2)
  22777. return WC_TEST_RET_ENC_NC;
  22778. total += outlen;
  22779. if(total != 18)
  22780. return 3447;
  22781. if (XMEMCMP(plain, cbcPlain, 18))
  22782. return WC_TEST_RET_ENC_NC;
  22783. if (wolfSSL_EVP_Cipher_key_length(NULL) != 0)
  22784. return WC_TEST_RET_ENC_NC;
  22785. if (wolfSSL_EVP_Cipher_key_length(wolfSSL_EVP_aes_128_cbc()) != 16)
  22786. return WC_TEST_RET_ENC_NC;
  22787. if (wolfSSL_EVP_CIPHER_CTX_mode(NULL) != 0)
  22788. return WC_TEST_RET_ENC_NC;
  22789. if (wolfSSL_EVP_CIPHER_CTX_mode(en) != (en->flags & WOLFSSL_EVP_CIPH_MODE))
  22790. return WC_TEST_RET_ENC_NC;
  22791. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22792. return WC_TEST_RET_ENC_NC;
  22793. wolfSSL_EVP_CIPHER_CTX_init(en);
  22794. if (wolfSSL_EVP_CipherInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22795. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22796. return WC_TEST_RET_ENC_NC;
  22797. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22798. return WC_TEST_RET_ENC_NC;
  22799. wolfSSL_EVP_CIPHER_CTX_init(en);
  22800. if (wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22801. (unsigned char*)key, (unsigned char*)iv) == 0)
  22802. return WC_TEST_RET_ENC_NC;
  22803. if (wolfSSL_EVP_EncryptFinal_ex(NULL, NULL, NULL)
  22804. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22805. {
  22806. return WC_TEST_RET_ENC_NC;
  22807. }
  22808. if (wolfSSL_EVP_EncryptFinal(NULL, NULL, NULL)
  22809. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22810. {
  22811. return WC_TEST_RET_ENC_NC;
  22812. }
  22813. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22814. return WC_TEST_RET_ENC_NC;
  22815. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22816. return WC_TEST_RET_ENC_NC;
  22817. wolfSSL_EVP_CIPHER_CTX_init(de);
  22818. if (wolfSSL_EVP_DecryptInit_ex(de, wolfSSL_EVP_aes_128_cbc(), NULL,
  22819. (unsigned char*)key, (unsigned char*)iv) == 0)
  22820. return WC_TEST_RET_ENC_NC;
  22821. if (wolfSSL_EVP_DecryptFinal(NULL, NULL, NULL)
  22822. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22823. {
  22824. return WC_TEST_RET_ENC_NC;
  22825. }
  22826. if (wolfSSL_EVP_DecryptFinal_ex(NULL, NULL, NULL)
  22827. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22828. {
  22829. return WC_TEST_RET_ENC_NC;
  22830. }
  22831. if (wolfSSL_EVP_CIPHER_CTX_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22832. return WC_TEST_RET_ENC_NC;
  22833. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22834. return WC_TEST_RET_ENC_NC;
  22835. wolfSSL_EVP_CIPHER_CTX_init(en);
  22836. wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22837. (unsigned char*)key, (unsigned char*)iv);
  22838. if (wolfSSL_EVP_CIPHER_CTX_block_size(en) != en->block_size)
  22839. return WC_TEST_RET_ENC_NC;
  22840. if (wolfSSL_EVP_CIPHER_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22841. return WC_TEST_RET_ENC_NC;
  22842. if (wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_128_cbc()) != WC_AES_BLOCK_SIZE)
  22843. return WC_TEST_RET_ENC_NC;
  22844. if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0)
  22845. return WC_TEST_RET_ENC_NC;
  22846. if (wolfSSL_EVP_CIPHER_flags(wolfSSL_EVP_aes_128_cbc()) != WOLFSSL_EVP_CIPH_CBC_MODE)
  22847. return WC_TEST_RET_ENC_NC;
  22848. wolfSSL_EVP_CIPHER_CTX_clear_flags(en, 0xFFFFFFFF);
  22849. wolfSSL_EVP_CIPHER_CTX_set_flags(en, 42);
  22850. if (en->flags != 42)
  22851. return WC_TEST_RET_ENC_NC;
  22852. if (wolfSSL_EVP_CIPHER_CTX_set_padding(NULL, 0) !=
  22853. WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22854. return WC_TEST_RET_ENC_NC;
  22855. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != WOLFSSL_SUCCESS)
  22856. return WC_TEST_RET_ENC_NC;
  22857. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != WOLFSSL_SUCCESS)
  22858. return WC_TEST_RET_ENC_NC;
  22859. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22860. return WC_TEST_RET_ENC_NC;
  22861. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22862. return WC_TEST_RET_ENC_NC;
  22863. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22864. wolfSSL_EVP_CIPHER_CTX_free(en);
  22865. wolfSSL_EVP_CIPHER_CTX_free(de);
  22866. #endif
  22867. }
  22868. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22869. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  22870. return 0;
  22871. }
  22872. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void)
  22873. {
  22874. wc_test_ret_t ret = 0;
  22875. #if !defined(NO_SHA256) && !defined(NO_SHA)
  22876. WOLFSSL_EVP_MD_CTX* ctx;
  22877. WOLFSSL_EVP_MD_CTX* ctx2;
  22878. WOLFSSL_ENTER("openSSL_evpMD_test");
  22879. ctx = wolfSSL_EVP_MD_CTX_new();
  22880. ctx2 = wolfSSL_EVP_MD_CTX_new();
  22881. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha256());
  22882. if (ret != WOLFSSL_SUCCESS) {
  22883. ret = WC_TEST_RET_ENC_NC;
  22884. goto openSSL_evpMD_test_done;
  22885. }
  22886. ret = wolfSSL_EVP_MD_CTX_copy(ctx2, ctx);
  22887. if (ret != WOLFSSL_SUCCESS) {
  22888. ret = WC_TEST_RET_ENC_NC;
  22889. goto openSSL_evpMD_test_done;
  22890. }
  22891. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22892. ret = WC_TEST_RET_ENC_NC;
  22893. goto openSSL_evpMD_test_done;
  22894. }
  22895. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha1());
  22896. if (ret != WOLFSSL_SUCCESS) {
  22897. ret = WC_TEST_RET_ENC_NC;
  22898. goto openSSL_evpMD_test_done;
  22899. }
  22900. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22901. ret = WC_TEST_RET_ENC_NC;
  22902. goto openSSL_evpMD_test_done;
  22903. }
  22904. ret = wolfSSL_EVP_MD_CTX_copy_ex(ctx2, ctx);
  22905. if (ret != WOLFSSL_SUCCESS) {
  22906. ret = WC_TEST_RET_ENC_NC;
  22907. goto openSSL_evpMD_test_done;
  22908. }
  22909. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) == wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22910. ret = WC_TEST_RET_ENC_NC;
  22911. goto openSSL_evpMD_test_done;
  22912. }
  22913. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha1()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22914. ret = WC_TEST_RET_ENC_NC;
  22915. goto openSSL_evpMD_test_done;
  22916. }
  22917. if (wolfSSL_EVP_DigestInit_ex(ctx, wolfSSL_EVP_sha1(), NULL) != WOLFSSL_SUCCESS) {
  22918. ret = WC_TEST_RET_ENC_NC;
  22919. goto openSSL_evpMD_test_done;
  22920. }
  22921. if (wolfSSL_EVP_add_digest(NULL) != 0) {
  22922. ret = WC_TEST_RET_ENC_NC;
  22923. goto openSSL_evpMD_test_done;
  22924. }
  22925. if (wolfSSL_EVP_add_cipher(NULL) != 0) {
  22926. ret = WC_TEST_RET_ENC_NC;
  22927. goto openSSL_evpMD_test_done;
  22928. }
  22929. ret = 0; /* got to success state without jumping to end with a fail */
  22930. openSSL_evpMD_test_done:
  22931. wolfSSL_EVP_MD_CTX_free(ctx);
  22932. wolfSSL_EVP_MD_CTX_free(ctx2);
  22933. #endif /* NO_SHA256 */
  22934. return ret;
  22935. }
  22936. #ifdef DEBUG_SIGN
  22937. static void show(const char *title, const char *p, unsigned int s) {
  22938. char* i;
  22939. printf("%s: ", title);
  22940. for (i = p;
  22941. i < p + s;
  22942. printf("%c", *i), i++);
  22943. printf("\n");
  22944. }
  22945. #else
  22946. #define show(a,b,c) WC_DO_NOTHING
  22947. #endif
  22948. #define FOURK_BUFF 4096
  22949. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void)
  22950. {
  22951. wc_test_ret_t ret = 0;
  22952. #if !defined(NO_RSA) && !defined(NO_SHA)
  22953. byte* prvTmp;
  22954. byte* pubTmp;
  22955. int prvBytes;
  22956. int pubBytes;
  22957. WOLFSSL_RSA *prvRsa = NULL;
  22958. WOLFSSL_RSA *pubRsa = NULL;
  22959. WOLFSSL_EVP_PKEY *prvPkey = NULL;
  22960. WOLFSSL_EVP_PKEY *pubPkey = NULL;
  22961. WOLFSSL_EVP_PKEY_CTX *enc = NULL;
  22962. WOLFSSL_EVP_PKEY_CTX *dec = NULL;
  22963. byte in[] = TEST_STRING;
  22964. byte out[256];
  22965. size_t outlen;
  22966. size_t keySz;
  22967. byte plain[256];
  22968. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  22969. XFILE keyFile;
  22970. XFILE keypubFile;
  22971. char cliKey[] = "./certs/client-key.der";
  22972. char cliKeypub[] = "./certs/client-keyPub.der";
  22973. #endif
  22974. WOLFSSL_ENTER("openssl_pkey0_test");
  22975. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22976. if (prvTmp == NULL)
  22977. return WC_TEST_RET_ENC_ERRNO;
  22978. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22979. if (pubTmp == NULL) {
  22980. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22981. return WC_TEST_RET_ENC_NC;
  22982. }
  22983. #ifdef USE_CERT_BUFFERS_1024
  22984. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  22985. prvBytes = sizeof_client_key_der_1024;
  22986. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  22987. pubBytes = sizeof_client_keypub_der_1024;
  22988. #elif defined(USE_CERT_BUFFERS_2048)
  22989. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  22990. prvBytes = sizeof_client_key_der_2048;
  22991. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  22992. pubBytes = sizeof_client_keypub_der_2048;
  22993. #else
  22994. keyFile = XFOPEN(cliKey, "rb");
  22995. if (!keyFile) {
  22996. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22997. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22998. err_sys("can't open ./certs/client-key.der, "
  22999. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23000. return WC_TEST_RET_ENC_ERRNO;
  23001. }
  23002. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23003. XFCLOSE(keyFile);
  23004. if (prvBytes == 0) {
  23005. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23006. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23007. return WC_TEST_RET_ENC_ERRNO;
  23008. }
  23009. keypubFile = XFOPEN(cliKeypub, "rb");
  23010. if (!keypubFile) {
  23011. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23012. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23013. err_sys("can't open ./certs/client-cert.der, "
  23014. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23015. return WC_TEST_RET_ENC_ERRNO;
  23016. }
  23017. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23018. XFCLOSE(keypubFile);
  23019. if (pubBytes == 0) {
  23020. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23021. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23022. return WC_TEST_RET_ENC_ERRNO;
  23023. }
  23024. #endif /* USE_CERT_BUFFERS */
  23025. prvRsa = wolfSSL_RSA_new();
  23026. pubRsa = wolfSSL_RSA_new();
  23027. if((prvRsa == NULL) || (pubRsa == NULL)){
  23028. printf("error with RSA_new\n");
  23029. ret = WC_TEST_RET_ENC_ERRNO;
  23030. goto openssl_pkey0_test_done;
  23031. }
  23032. ret = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23033. if(ret != WOLFSSL_SUCCESS){
  23034. printf("error with RSA_LoadDer_ex\n");
  23035. ret = WC_TEST_RET_ENC_EC(ret);
  23036. goto openssl_pkey0_test_done;
  23037. }
  23038. ret = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23039. if(ret != WOLFSSL_SUCCESS){
  23040. printf("error with RSA_LoadDer_ex\n");
  23041. ret = WC_TEST_RET_ENC_EC(ret);
  23042. goto openssl_pkey0_test_done;
  23043. }
  23044. keySz = (size_t)wolfSSL_RSA_size(pubRsa);
  23045. prvPkey = wolfSSL_EVP_PKEY_new();
  23046. pubPkey = wolfSSL_EVP_PKEY_new();
  23047. if((prvPkey == NULL) || (pubPkey == NULL)){
  23048. printf("error with PKEY_new\n");
  23049. ret = WC_TEST_RET_ENC_NC;
  23050. goto openssl_pkey0_test_done;
  23051. }
  23052. ret = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23053. ret += wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23054. if(ret != 2){
  23055. printf("error with PKEY_set1_RSA\n");
  23056. ret = WC_TEST_RET_ENC_I(ret);
  23057. goto openssl_pkey0_test_done;
  23058. }
  23059. dec = wolfSSL_EVP_PKEY_CTX_new(prvPkey, NULL);
  23060. enc = wolfSSL_EVP_PKEY_CTX_new(pubPkey, NULL);
  23061. if((dec == NULL)||(enc==NULL)){
  23062. printf("error with EVP_PKEY_CTX_new\n");
  23063. ret = WC_TEST_RET_ENC_NC;
  23064. goto openssl_pkey0_test_done;
  23065. }
  23066. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23067. if (ret != 1) {
  23068. printf("error with decrypt init\n");
  23069. ret = WC_TEST_RET_ENC_NC;
  23070. goto openssl_pkey0_test_done;
  23071. }
  23072. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23073. if (ret != 1) {
  23074. printf("error with encrypt init\n");
  23075. ret = WC_TEST_RET_ENC_NC;
  23076. goto openssl_pkey0_test_done;
  23077. }
  23078. XMEMSET(out, 0, sizeof(out));
  23079. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23080. if (ret != 1) {
  23081. printf("error encrypting msg\n");
  23082. ret = WC_TEST_RET_ENC_NC;
  23083. goto openssl_pkey0_test_done;
  23084. }
  23085. show("encrypted msg", out, outlen);
  23086. XMEMSET(plain, 0, sizeof(plain));
  23087. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23088. if (ret != 1) {
  23089. printf("error decrypting msg\n");
  23090. ret = WC_TEST_RET_ENC_NC;
  23091. goto openssl_pkey0_test_done;
  23092. }
  23093. show("decrypted msg", plain, outlen);
  23094. /* RSA_PKCS1_OAEP_PADDING test */
  23095. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23096. if (ret != 1) {
  23097. printf("error with decrypt init\n");
  23098. ret = WC_TEST_RET_ENC_NC;
  23099. goto openssl_pkey0_test_done;
  23100. }
  23101. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23102. if (ret != 1) {
  23103. printf("error with encrypt init\n");
  23104. ret = WC_TEST_RET_ENC_NC;
  23105. goto openssl_pkey0_test_done;
  23106. }
  23107. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23108. printf("first set rsa padding error\n");
  23109. ret = WC_TEST_RET_ENC_EC(ret);
  23110. goto openssl_pkey0_test_done;
  23111. }
  23112. #ifndef HAVE_FIPS
  23113. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23114. printf("second set rsa padding error\n");
  23115. ret = WC_TEST_RET_ENC_EC(ret);
  23116. goto openssl_pkey0_test_done;
  23117. }
  23118. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23119. printf("third set rsa padding error\n");
  23120. ret = WC_TEST_RET_ENC_EC(ret);
  23121. goto openssl_pkey0_test_done;
  23122. }
  23123. #endif
  23124. XMEMSET(out, 0, sizeof(out));
  23125. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23126. if (ret != 1) {
  23127. printf("error encrypting msg\n");
  23128. ret = WC_TEST_RET_ENC_NC;
  23129. goto openssl_pkey0_test_done;
  23130. }
  23131. show("encrypted msg", out, outlen);
  23132. XMEMSET(plain, 0, sizeof(plain));
  23133. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23134. if (ret != 1) {
  23135. printf("error decrypting msg\n");
  23136. ret = WC_TEST_RET_ENC_NC;
  23137. goto openssl_pkey0_test_done;
  23138. }
  23139. show("decrypted msg", plain, outlen);
  23140. ret = 0; /* made it to this point without error then set success */
  23141. openssl_pkey0_test_done:
  23142. wolfSSL_RSA_free(prvRsa);
  23143. wolfSSL_RSA_free(pubRsa);
  23144. wolfSSL_EVP_PKEY_free(pubPkey);
  23145. wolfSSL_EVP_PKEY_free(prvPkey);
  23146. wolfSSL_EVP_PKEY_CTX_free(dec);
  23147. wolfSSL_EVP_PKEY_CTX_free(enc);
  23148. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23149. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23150. #endif /* NO_RSA */
  23151. return ret;
  23152. }
  23153. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void)
  23154. {
  23155. wc_test_ret_t ret = 0;
  23156. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_SHA)
  23157. WOLFSSL_EVP_PKEY_CTX* dec = NULL;
  23158. WOLFSSL_EVP_PKEY_CTX* enc = NULL;
  23159. WOLFSSL_EVP_PKEY* pubKey = NULL;
  23160. WOLFSSL_EVP_PKEY* prvKey = NULL;
  23161. WOLFSSL_X509* x509 = NULL;
  23162. WOLFSSL_SMALL_STACK_STATIC const unsigned char msg[] = "sugar slapped";
  23163. const unsigned char* clikey;
  23164. long cliKeySz;
  23165. size_t outlen;
  23166. int keyLenBits = 2048;
  23167. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23168. unsigned char *tmp = (unsigned char *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23169. unsigned char *cipher = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23170. unsigned char *plain = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23171. if ((tmp == NULL) ||
  23172. (cipher == NULL) ||
  23173. (plain == NULL)) {
  23174. ret = WC_TEST_RET_ENC_NC;
  23175. goto openssl_pkey1_test_done;
  23176. }
  23177. #else
  23178. unsigned char tmp[FOURK_BUF];
  23179. unsigned char cipher[RSA_TEST_BYTES];
  23180. unsigned char plain[RSA_TEST_BYTES];
  23181. #endif
  23182. WOLFSSL_ENTER("openssl_pkey1_test");
  23183. #if defined(USE_CERT_BUFFERS_1024)
  23184. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  23185. cliKeySz = (long)sizeof_client_key_der_1024;
  23186. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_1024,
  23187. sizeof_client_cert_der_1024, SSL_FILETYPE_ASN1);
  23188. keyLenBits = 1024;
  23189. #elif defined(USE_CERT_BUFFERS_2048)
  23190. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  23191. cliKeySz = (long)sizeof_client_key_der_2048;
  23192. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_2048,
  23193. sizeof_client_cert_der_2048, SSL_FILETYPE_ASN1);
  23194. #elif defined(USE_CERT_BUFFERS_3072)
  23195. XMEMCPY(tmp, client_key_der_3072, sizeof_client_key_der_3072);
  23196. cliKeySz = (long)sizeof_client_key_der_3072;
  23197. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_3072,
  23198. sizeof_client_cert_der_3072, SSL_FILETYPE_ASN1);
  23199. keyLenBits = 3072;
  23200. #elif defined(USE_CERT_BUFFERS_4096)
  23201. XMEMCPY(tmp, client_key_der_4096, sizeof_client_key_der_4096);
  23202. cliKeySz = (long)sizeof_client_key_der_4096;
  23203. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_4096,
  23204. sizeof_client_cert_der_4096, SSL_FILETYPE_ASN1);
  23205. keyLenBits = 4096;
  23206. #else
  23207. {
  23208. XFILE f;
  23209. f = XFOPEN(clientKey, "rb");
  23210. if (!f) {
  23211. err_sys("can't open ./certs/client-key.der, "
  23212. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23213. ret = WC_TEST_RET_ENC_ERRNO;
  23214. goto openssl_pkey1_test_done;
  23215. }
  23216. cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f);
  23217. XFCLOSE(f);
  23218. if (cliKeySz == 0)
  23219. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, openssl_pkey1_test_done);
  23220. }
  23221. /* using existing wolfSSL api to get public and private key */
  23222. x509 = wolfSSL_X509_load_certificate_file(clientCert, WOLFSSL_FILETYPE_ASN1);
  23223. #endif /* USE_CERT_BUFFERS */
  23224. clikey = tmp;
  23225. if ((prvKey = wolfSSL_EVP_PKEY_new()) == NULL) {
  23226. ret = WC_TEST_RET_ENC_ERRNO;
  23227. goto openssl_pkey1_test_done;
  23228. }
  23229. wolfSSL_EVP_PKEY_free(prvKey);
  23230. prvKey = NULL;
  23231. if (x509 == NULL) {
  23232. ret = WC_TEST_RET_ENC_NC;
  23233. goto openssl_pkey1_test_done;
  23234. }
  23235. pubKey = wolfSSL_X509_get_pubkey(x509);
  23236. if (pubKey == NULL) {
  23237. ret = WC_TEST_RET_ENC_NC;
  23238. goto openssl_pkey1_test_done;
  23239. }
  23240. prvKey = wolfSSL_d2i_PrivateKey(WC_EVP_PKEY_RSA, NULL, &clikey, cliKeySz);
  23241. if (prvKey == NULL) {
  23242. ret = WC_TEST_RET_ENC_NC;
  23243. goto openssl_pkey1_test_done;
  23244. }
  23245. /* phase 2 API to create WOLFSSL_EVP_PKEY_CTX and encrypt/decrypt */
  23246. if (wolfSSL_EVP_PKEY_bits(prvKey) != keyLenBits) {
  23247. ret = WC_TEST_RET_ENC_NC;
  23248. goto openssl_pkey1_test_done;
  23249. }
  23250. if (wolfSSL_EVP_PKEY_size(prvKey) != keyLenBits/8) {
  23251. ret = WC_TEST_RET_ENC_NC;
  23252. goto openssl_pkey1_test_done;
  23253. }
  23254. dec = wolfSSL_EVP_PKEY_CTX_new(prvKey, NULL);
  23255. enc = wolfSSL_EVP_PKEY_CTX_new(pubKey, NULL);
  23256. if (dec == NULL || enc == NULL) {
  23257. ret = WC_TEST_RET_ENC_ERRNO;
  23258. goto openssl_pkey1_test_done;
  23259. }
  23260. if (wolfSSL_EVP_PKEY_decrypt_init(dec) != 1) {
  23261. ret = WC_TEST_RET_ENC_NC;
  23262. goto openssl_pkey1_test_done;
  23263. }
  23264. if (wolfSSL_EVP_PKEY_encrypt_init(enc) != 1) {
  23265. ret = WC_TEST_RET_ENC_NC;
  23266. goto openssl_pkey1_test_done;
  23267. }
  23268. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23269. ret = WC_TEST_RET_ENC_NC;
  23270. goto openssl_pkey1_test_done;
  23271. }
  23272. #ifndef HAVE_FIPS
  23273. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23274. ret = WC_TEST_RET_ENC_EC(ret);
  23275. goto openssl_pkey1_test_done;
  23276. }
  23277. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23278. ret = WC_TEST_RET_ENC_EC(ret);
  23279. goto openssl_pkey1_test_done;
  23280. }
  23281. #endif
  23282. XMEMSET(cipher, 0, RSA_TEST_BYTES);
  23283. outlen = (size_t)(keyLenBits/8);
  23284. if (wolfSSL_EVP_PKEY_encrypt(enc, cipher, &outlen, msg, sizeof(msg)) < 0) {
  23285. ret = WC_TEST_RET_ENC_EC(ret);
  23286. goto openssl_pkey1_test_done;
  23287. }
  23288. XMEMSET(plain, 0, RSA_TEST_BYTES);
  23289. if (wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, cipher, outlen) != 1) {
  23290. ret = WC_TEST_RET_ENC_NC;
  23291. goto openssl_pkey1_test_done;
  23292. }
  23293. openssl_pkey1_test_done:
  23294. if (pubKey != NULL) {
  23295. wolfSSL_EVP_PKEY_free(pubKey);
  23296. }
  23297. if (prvKey != NULL) {
  23298. wolfSSL_EVP_PKEY_free(prvKey);
  23299. }
  23300. if (dec != NULL) {
  23301. wolfSSL_EVP_PKEY_CTX_free(dec);
  23302. }
  23303. if (enc != NULL) {
  23304. wolfSSL_EVP_PKEY_CTX_free(enc);
  23305. }
  23306. if (x509 != NULL) {
  23307. wolfSSL_X509_free(x509);
  23308. }
  23309. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23310. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23311. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23312. XFREE(plain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23313. #endif
  23314. #endif
  23315. return ret;
  23316. }
  23317. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void)
  23318. {
  23319. #if !defined(NO_RSA) && !defined(NO_SHA)
  23320. byte* prvTmp;
  23321. byte* pubTmp;
  23322. int prvBytes;
  23323. int pubBytes;
  23324. WOLFSSL_RSA *prvRsa;
  23325. WOLFSSL_RSA *pubRsa;
  23326. WOLFSSL_EVP_PKEY *prvPkey;
  23327. WOLFSSL_EVP_PKEY *pubPkey;
  23328. WOLFSSL_EVP_MD_CTX* sign;
  23329. WOLFSSL_EVP_MD_CTX* verf;
  23330. char msg[] = "see spot run";
  23331. unsigned char sig[256];
  23332. unsigned int sigSz;
  23333. const void* pt;
  23334. unsigned int count;
  23335. wc_test_ret_t ret, ret1, ret2;
  23336. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  23337. XFILE keyFile;
  23338. XFILE keypubFile;
  23339. char cliKey[] = "./certs/client-key.der";
  23340. char cliKeypub[] = "./certs/client-keyPub.der";
  23341. #endif
  23342. WOLFSSL_ENTER("openssl_evpSig_test");
  23343. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23344. if (prvTmp == NULL)
  23345. return WC_TEST_RET_ENC_ERRNO;
  23346. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23347. if (pubTmp == NULL) {
  23348. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23349. return WC_TEST_RET_ENC_NC;
  23350. }
  23351. #ifdef USE_CERT_BUFFERS_1024
  23352. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  23353. prvBytes = sizeof_client_key_der_1024;
  23354. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  23355. pubBytes = sizeof_client_keypub_der_1024;
  23356. #elif defined(USE_CERT_BUFFERS_2048)
  23357. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  23358. prvBytes = sizeof_client_key_der_2048;
  23359. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  23360. pubBytes = sizeof_client_keypub_der_2048;
  23361. #else
  23362. keyFile = XFOPEN(cliKey, "rb");
  23363. if (!keyFile) {
  23364. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23365. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23366. err_sys("can't open ./certs/client-key.der, "
  23367. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23368. return WC_TEST_RET_ENC_ERRNO;
  23369. }
  23370. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23371. XFCLOSE(keyFile);
  23372. if (prvBytes == 0) {
  23373. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23374. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23375. return WC_TEST_RET_ENC_ERRNO;
  23376. }
  23377. keypubFile = XFOPEN(cliKeypub, "rb");
  23378. if (!keypubFile) {
  23379. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23380. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23381. err_sys("can't open ./certs/client-cert.der, "
  23382. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23383. return WC_TEST_RET_ENC_ERRNO;
  23384. }
  23385. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23386. XFCLOSE(keypubFile);
  23387. if (pubBytes == 0) {
  23388. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23389. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23390. return WC_TEST_RET_ENC_ERRNO;
  23391. }
  23392. #endif /* USE_CERT_BUFFERS */
  23393. prvRsa = wolfSSL_RSA_new();
  23394. pubRsa = wolfSSL_RSA_new();
  23395. if((prvRsa == NULL) || (pubRsa == NULL)){
  23396. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23397. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23398. err_sys("ERROR with RSA_new", WC_TEST_RET_ENC_NC);
  23399. return WC_TEST_RET_ENC_NC;
  23400. }
  23401. ret1 = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23402. ret2 = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23403. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23404. printf("error with RSA_LoadDer_ex\n");
  23405. return WC_TEST_RET_ENC_NC;
  23406. }
  23407. prvPkey = wolfSSL_EVP_PKEY_new();
  23408. pubPkey = wolfSSL_EVP_PKEY_new();
  23409. if((prvPkey == NULL) || (pubPkey == NULL)){
  23410. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23411. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23412. printf("error with KEY_new\n");
  23413. return WC_TEST_RET_ENC_NC;
  23414. }
  23415. ret1 = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23416. ret2 = wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23417. if((ret1 != 1) || (ret2 != 1)){
  23418. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23419. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23420. printf("error with WOLFSSL_EVP_PKEY_set1_RSA\n");
  23421. return WC_TEST_RET_ENC_NC;
  23422. }
  23423. /****************** sign and verify *******************/
  23424. sign = wolfSSL_EVP_MD_CTX_new();
  23425. verf = wolfSSL_EVP_MD_CTX_new();
  23426. if((sign == NULL)||(verf == NULL)){
  23427. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23428. wolfSSL_EVP_MD_CTX_free(sign);
  23429. wolfSSL_EVP_MD_CTX_free(verf);
  23430. return WC_TEST_RET_ENC_NC;
  23431. }
  23432. ret = wolfSSL_EVP_SignInit(sign, wolfSSL_EVP_sha1());
  23433. if (ret != WOLFSSL_SUCCESS){
  23434. printf("error with EVP_SignInit\n");
  23435. wolfSSL_EVP_MD_CTX_free(sign);
  23436. wolfSSL_EVP_MD_CTX_free(verf);
  23437. return WC_TEST_RET_ENC_NC;
  23438. }
  23439. count = sizeof(msg);
  23440. show("message = ", (char *)msg, count);
  23441. /* sign */
  23442. XMEMSET(sig, 0, sizeof(sig));
  23443. pt = (const void*)msg;
  23444. ret1 = wolfSSL_EVP_SignUpdate(sign, pt, count);
  23445. ret2 = wolfSSL_EVP_SignFinal(sign, sig, &sigSz, prvPkey);
  23446. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23447. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23448. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23449. wolfSSL_EVP_MD_CTX_free(sign);
  23450. wolfSSL_EVP_MD_CTX_free(verf);
  23451. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23452. return WC_TEST_RET_ENC_NC;
  23453. }
  23454. show("signature = ", (char *)sig, sigSz);
  23455. /* verify */
  23456. pt = (const void*)msg;
  23457. ret1 = wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23458. ret2 = wolfSSL_EVP_VerifyUpdate(verf, pt, count);
  23459. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23460. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23461. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23462. wolfSSL_EVP_MD_CTX_free(sign);
  23463. wolfSSL_EVP_MD_CTX_free(verf);
  23464. printf("error with EVP_Verify\n");
  23465. return WC_TEST_RET_ENC_NC;
  23466. }
  23467. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) != 1) {
  23468. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23469. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23470. wolfSSL_EVP_MD_CTX_free(sign);
  23471. wolfSSL_EVP_MD_CTX_free(verf);
  23472. printf("error with EVP_VerifyFinal\n");
  23473. return WC_TEST_RET_ENC_NC;
  23474. }
  23475. /* expect fail without update */
  23476. wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23477. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) == 1) {
  23478. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23479. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23480. wolfSSL_EVP_MD_CTX_free(sign);
  23481. wolfSSL_EVP_MD_CTX_free(verf);
  23482. printf("EVP_VerifyInit without update not detected\n");
  23483. return WC_TEST_RET_ENC_NC;
  23484. }
  23485. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23486. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23487. wolfSSL_EVP_MD_CTX_free(sign);
  23488. wolfSSL_EVP_MD_CTX_free(verf);
  23489. wolfSSL_RSA_free(prvRsa);
  23490. wolfSSL_RSA_free(pubRsa);
  23491. wolfSSL_EVP_PKEY_free(pubPkey);
  23492. wolfSSL_EVP_PKEY_free(prvPkey);
  23493. #endif /* NO_RSA */
  23494. return 0;
  23495. }
  23496. #endif /* OPENSSL_EXTRA */
  23497. #ifndef NO_PWDBASED
  23498. #ifdef HAVE_SCRYPT
  23499. /* Test vectors taken from RFC 7914: scrypt PBKDF - Section 12. */
  23500. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void)
  23501. {
  23502. #ifdef HAVE_FIPS
  23503. /* RFC 7914 test vector keys are too short for FIPS. */
  23504. #else
  23505. wc_test_ret_t ret;
  23506. byte derived[64];
  23507. WOLFSSL_SMALL_STACK_STATIC const byte verify1[] = {
  23508. 0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20,
  23509. 0x3b, 0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97,
  23510. 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8,
  23511. 0xdf, 0xdf, 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42,
  23512. 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, 0xf8,
  23513. 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17,
  23514. 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d, 0x36, 0x28,
  23515. 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06
  23516. };
  23517. #if !defined(BENCH_EMBEDDED)
  23518. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23519. 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00,
  23520. 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe,
  23521. 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30,
  23522. 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62,
  23523. 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88,
  23524. 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda,
  23525. 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d,
  23526. 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40
  23527. };
  23528. #endif
  23529. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23530. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  23531. 0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48,
  23532. 0x46, 0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb,
  23533. 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e,
  23534. 0xa9, 0xb5, 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2,
  23535. 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, 0xcf,
  23536. 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9,
  23537. 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65, 0x1e, 0x40,
  23538. 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87
  23539. };
  23540. #endif
  23541. #ifdef SCRYPT_TEST_ALL
  23542. /* Test case is very slow.
  23543. * Use for confirmation after code change or new platform.
  23544. */
  23545. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  23546. 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae,
  23547. 0xad, 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81,
  23548. 0xec, 0x56, 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d,
  23549. 0xab, 0xe5, 0xee, 0x98, 0x20, 0xad, 0xaa, 0x47,
  23550. 0x8e, 0x56, 0xfd, 0x8f, 0x4b, 0xa5, 0xd0, 0x9f,
  23551. 0xfa, 0x1c, 0x6d, 0x92, 0x7c, 0x40, 0xf4, 0xc3,
  23552. 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, 0x52, 0xfb,
  23553. 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, 0xa4
  23554. };
  23555. #endif
  23556. WOLFSSL_ENTER("scrypt_test");
  23557. ret = wc_scrypt(derived, NULL, 0, NULL, 0, 4, 1, 1, sizeof(verify1));
  23558. if (ret != 0)
  23559. return WC_TEST_RET_ENC_EC(ret);
  23560. if (XMEMCMP(derived, verify1, sizeof(verify1)) != 0)
  23561. return WC_TEST_RET_ENC_NC;
  23562. #if !defined(BENCH_EMBEDDED)
  23563. ret = wc_scrypt(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 10, 8, 16,
  23564. sizeof(verify2));
  23565. if (ret != 0)
  23566. return WC_TEST_RET_ENC_EC(ret);
  23567. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23568. return WC_TEST_RET_ENC_NC;
  23569. #endif
  23570. /* Test case with parallel overflowing */
  23571. ret = wc_scrypt(derived, (byte*)"password", 16, (byte*)"NaCl", 16, 2, 4, 8388608,
  23572. sizeof(verify1));
  23573. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  23574. return WC_TEST_RET_ENC_EC(ret);
  23575. /* Don't run these test on embedded, since they use large mallocs */
  23576. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23577. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23578. (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(verify3));
  23579. if (ret != 0)
  23580. return WC_TEST_RET_ENC_EC(ret);
  23581. if (XMEMCMP(derived, verify3, sizeof(verify3)) != 0)
  23582. return WC_TEST_RET_ENC_NC;
  23583. #ifdef SCRYPT_TEST_ALL
  23584. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23585. (byte*)"SodiumChloride", 14, 20, 8, 1, sizeof(verify4));
  23586. if (ret != 0)
  23587. return WC_TEST_RET_ENC_EC(ret);
  23588. if (XMEMCMP(derived, verify4, sizeof(verify4)) != 0)
  23589. return WC_TEST_RET_ENC_NC;
  23590. #endif
  23591. #else
  23592. #ifdef SCRYPT_TEST_ALL
  23593. (void)verify4;
  23594. #endif
  23595. #endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */
  23596. #if !defined(BENCH_EMBEDDED)
  23597. ret = wc_scrypt_ex(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 1<<10,
  23598. 8, 16, sizeof(verify2));
  23599. if (ret != 0)
  23600. return WC_TEST_RET_ENC_EC(ret);
  23601. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23602. return WC_TEST_RET_ENC_NC;
  23603. #endif
  23604. #endif /* !HAVE_FIPS */
  23605. return 0;
  23606. }
  23607. #endif
  23608. #ifdef HAVE_PKCS12
  23609. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void)
  23610. {
  23611. WOLFSSL_SMALL_STACK_STATIC const byte passwd[] = { 0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
  23612. 0x00, 0x00 };
  23613. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f };
  23614. WOLFSSL_SMALL_STACK_STATIC const byte passwd2[] = { 0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
  23615. 0x00, 0x67, 0x00, 0x00 };
  23616. WOLFSSL_SMALL_STACK_STATIC const byte salt2[] = { 0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5 };
  23617. byte derived[64];
  23618. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23619. 0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
  23620. 0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
  23621. 0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
  23622. };
  23623. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23624. 0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
  23625. 0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
  23626. 0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
  23627. };
  23628. int id = 1;
  23629. int kLen = 24;
  23630. int iterations = 1;
  23631. wc_test_ret_t ret;
  23632. WOLFSSL_ENTER("pkcs12_pbkdf_test");
  23633. ret = wc_PKCS12_PBKDF(derived, passwd, sizeof(passwd), salt, 8,
  23634. iterations, kLen, WC_SHA256, id);
  23635. if (ret < 0)
  23636. return WC_TEST_RET_ENC_EC(ret);
  23637. if (XMEMCMP(derived, verify, (unsigned long)kLen) != 0)
  23638. return WC_TEST_RET_ENC_NC;
  23639. iterations = 1000;
  23640. ret = wc_PKCS12_PBKDF(derived, passwd2, sizeof(passwd2), salt2, 8,
  23641. iterations, kLen, WC_SHA256, id);
  23642. if (ret < 0)
  23643. return WC_TEST_RET_ENC_EC(ret);
  23644. ret = wc_PKCS12_PBKDF_ex(derived, passwd2, sizeof(passwd2), salt2, 8,
  23645. iterations, kLen, WC_SHA256, id, HEAP_HINT);
  23646. if (ret < 0)
  23647. return WC_TEST_RET_ENC_EC(ret);
  23648. if (XMEMCMP(derived, verify2, 24) != 0)
  23649. return WC_TEST_RET_ENC_NC;
  23650. return 0;
  23651. }
  23652. #endif /* HAVE_PKCS12 */
  23653. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23654. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void)
  23655. {
  23656. char passwd[] = "passwordpassword";
  23657. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a,
  23658. 0x5d, 0x63, 0xcb, 0x06 };
  23659. int iterations = 2048;
  23660. int kLen = 24;
  23661. byte derived[64];
  23662. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23663. 0x43, 0x6d, 0xb5, 0xe8, 0xd0, 0xfb, 0x3f, 0x35, 0x42, 0x48, 0x39, 0xbc,
  23664. 0x2d, 0xd4, 0xf9, 0x37, 0xd4, 0x95, 0x16, 0xa7, 0x2a, 0x9a, 0x21, 0xd1
  23665. };
  23666. wc_test_ret_t ret;
  23667. WOLFSSL_ENTER("pbkdf2_test");
  23668. ret = wc_PBKDF2_ex(derived, (byte*)passwd, (int)XSTRLEN(passwd),
  23669. salt, (int)sizeof(salt), iterations,
  23670. kLen, WC_SHA256, HEAP_HINT, devId);
  23671. if (ret != 0)
  23672. return WC_TEST_RET_ENC_EC(ret);
  23673. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23674. return WC_TEST_RET_ENC_NC;
  23675. return 0;
  23676. }
  23677. #endif /* HAVE_PBKDF2 && !NO_SHA256 && !NO_HMAC */
  23678. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23679. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void)
  23680. {
  23681. char passwd[] = "password";
  23682. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  23683. int iterations = 1000;
  23684. int kLen = 16;
  23685. byte derived[16];
  23686. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23687. 0xDC, 0x19, 0x84, 0x7E, 0x05, 0xC6, 0x4D, 0x2F,
  23688. 0xAF, 0x10, 0xEB, 0xFB, 0x4A, 0x3D, 0x2A, 0x20
  23689. };
  23690. wc_test_ret_t ret;
  23691. WOLFSSL_ENTER("pbkdf1_test");
  23692. ret = wc_PBKDF1_ex(derived, kLen, NULL, 0, (byte*)passwd,
  23693. (int)XSTRLEN(passwd), salt, (int)sizeof(salt), iterations, WC_SHA,
  23694. HEAP_HINT);
  23695. if (ret != 0)
  23696. return ret;
  23697. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23698. return WC_TEST_RET_ENC_NC;
  23699. return 0;
  23700. }
  23701. #endif /* HAVE_PBKDF2 && !NO_SHA */
  23702. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void)
  23703. {
  23704. wc_test_ret_t ret = 0;
  23705. WOLFSSL_ENTER("pwdbased_test");
  23706. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23707. ret = pbkdf1_test();
  23708. if (ret != 0)
  23709. return ret;
  23710. #endif
  23711. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23712. ret = pbkdf2_test();
  23713. if (ret != 0)
  23714. return ret;
  23715. #endif
  23716. #ifdef HAVE_PKCS12
  23717. ret = pkcs12_pbkdf_test();
  23718. if (ret != 0)
  23719. return ret;
  23720. #endif
  23721. #ifdef HAVE_SCRYPT
  23722. ret = scrypt_test();
  23723. if (ret != 0)
  23724. return ret;
  23725. #endif
  23726. return ret;
  23727. }
  23728. #endif /* NO_PWDBASED */
  23729. #if defined(USE_CERT_BUFFERS_2048) && \
  23730. defined(HAVE_PKCS12) && \
  23731. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  23732. !defined(NO_CERTS) && !defined(NO_DES3)
  23733. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
  23734. {
  23735. wc_test_ret_t ret = 0;
  23736. WC_PKCS12* pkcs12 = NULL;
  23737. /* Gen vars */
  23738. byte* pkcs12der = NULL;
  23739. int pkcs12derSz = 0;
  23740. WC_DerCertList derCaList = {
  23741. (byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
  23742. };
  23743. char* pass = (char*)"wolfSSL test";
  23744. /* Parsing vars */
  23745. WC_DerCertList* derCaListOut = NULL;
  23746. byte* keyDer = NULL;
  23747. byte* certDer = NULL;
  23748. word32 keySz;
  23749. word32 certSz;
  23750. WOLFSSL_ENTER("pkcs12_test");
  23751. pkcs12 = wc_PKCS12_create(pass, (word32)XSTRLEN(pass),
  23752. (char*)"friendlyName" /* not used currently */,
  23753. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  23754. (byte*)server_cert_der_2048, sizeof_server_cert_der_2048,
  23755. &derCaList, PBE_SHA1_DES3, PBE_SHA1_DES3, 100, 100,
  23756. 0 /* not used currently */, HEAP_HINT);
  23757. if (pkcs12 == NULL) {
  23758. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23759. goto out;
  23760. }
  23761. ret = wc_i2d_PKCS12(pkcs12, NULL, &pkcs12derSz);
  23762. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  23763. if (ret == 0)
  23764. ret = WC_TEST_RET_ENC_NC;
  23765. else
  23766. ret = WC_TEST_RET_ENC_I(ret);
  23767. goto out;
  23768. }
  23769. pkcs12der = (byte*)XMALLOC(pkcs12derSz, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23770. if (pkcs12der == NULL) {
  23771. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23772. goto out;
  23773. }
  23774. {
  23775. /* Use tmp pointer to avoid advancing pkcs12der */
  23776. byte* tmp = pkcs12der;
  23777. ret = wc_i2d_PKCS12(pkcs12, &tmp, &pkcs12derSz);
  23778. if (ret <= 0) {
  23779. if (ret == 0)
  23780. ret = WC_TEST_RET_ENC_NC;
  23781. else
  23782. ret = WC_TEST_RET_ENC_I(ret);
  23783. goto out;
  23784. }
  23785. }
  23786. wc_PKCS12_free(pkcs12);
  23787. pkcs12 = wc_PKCS12_new_ex(HEAP_HINT);
  23788. if (pkcs12 == NULL) {
  23789. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23790. goto out;
  23791. }
  23792. /* convert the DER file into an internal structure */
  23793. ret = wc_d2i_PKCS12(pkcs12der, pkcs12derSz, pkcs12);
  23794. if (ret != 0) {
  23795. ret = WC_TEST_RET_ENC_EC(ret);
  23796. goto out;
  23797. }
  23798. /* parse the internal structure into its parts */
  23799. ret = wc_PKCS12_parse(pkcs12, "wolfSSL test", &keyDer, &keySz,
  23800. &certDer, &certSz, &derCaListOut);
  23801. if (ret != 0) {
  23802. ret = WC_TEST_RET_ENC_EC(ret);
  23803. goto out;
  23804. }
  23805. if (keyDer == NULL || certDer == NULL || derCaListOut == NULL) {
  23806. ret = WC_TEST_RET_ENC_NC;
  23807. goto out;
  23808. }
  23809. out:
  23810. if (derCaListOut)
  23811. wc_FreeCertList(derCaListOut, HEAP_HINT);
  23812. XFREE(keyDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23813. XFREE(certDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23814. if (pkcs12)
  23815. wc_PKCS12_free(pkcs12);
  23816. XFREE(pkcs12der, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23817. return ret;
  23818. }
  23819. #endif
  23820. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  23821. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  23822. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  23823. defined(WOLFSSL_AFALG_XILINX_RSA)
  23824. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  23825. static wc_test_ret_t hkdf_test(void)
  23826. #else
  23827. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void)
  23828. #endif
  23829. {
  23830. wc_test_ret_t ret = 0;
  23831. #if !defined(NO_SHA) || !defined(NO_SHA256)
  23832. int L;
  23833. byte okm1[42];
  23834. byte ikm1[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23835. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23836. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  23837. #ifndef HAVE_FIPS
  23838. byte salt1[13] ={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  23839. 0x08, 0x09, 0x0a, 0x0b, 0x0c };
  23840. byte info1[10] ={ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  23841. 0xf8, 0xf9 };
  23842. #endif
  23843. #ifndef NO_SHA
  23844. byte res1[42] = { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61,
  23845. 0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06,
  23846. 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06,
  23847. 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0,
  23848. 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
  23849. 0x49, 0x18 };
  23850. #ifndef HAVE_FIPS
  23851. byte res2[42] = { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69,
  23852. 0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81,
  23853. 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15,
  23854. 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2,
  23855. 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
  23856. 0xf8, 0x96 };
  23857. #endif
  23858. #endif /* !NO_SHA */
  23859. #ifndef NO_SHA256
  23860. byte res3[42] = { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
  23861. 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
  23862. 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
  23863. 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
  23864. 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
  23865. 0x96, 0xc8 };
  23866. #ifndef HAVE_FIPS
  23867. byte res4[42] = { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
  23868. 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
  23869. 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
  23870. 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
  23871. 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
  23872. 0x58, 0x65 };
  23873. #endif
  23874. #endif /* !NO_SHA256 */
  23875. WOLFSSL_ENTER("hkdf_test");
  23876. XMEMSET(okm1, 0, sizeof(okm1));
  23877. L = (int)sizeof(okm1);
  23878. #ifndef NO_SHA
  23879. ret = wc_HKDF(WC_SHA, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23880. okm1, (word32)L);
  23881. if (ret != 0)
  23882. return WC_TEST_RET_ENC_EC(ret);
  23883. if (XMEMCMP(okm1, res1, (unsigned long)L) != 0)
  23884. return WC_TEST_RET_ENC_NC;
  23885. #ifndef HAVE_FIPS
  23886. /* fips can't have key size under 14 bytes, salt is key too */
  23887. L = (int)sizeof(okm1);
  23888. ret = wc_HKDF(WC_SHA, ikm1, 11, salt1, (word32)sizeof(salt1),
  23889. info1, (word32)sizeof(info1), okm1, (word32)L);
  23890. if (ret != 0)
  23891. return WC_TEST_RET_ENC_EC(ret);
  23892. if (XMEMCMP(okm1, res2, (unsigned long)L) != 0)
  23893. return WC_TEST_RET_ENC_NC;
  23894. #endif /* HAVE_FIPS */
  23895. #endif /* !NO_SHA */
  23896. #ifndef NO_SHA256
  23897. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23898. okm1, (word32)L);
  23899. if (ret != 0)
  23900. return WC_TEST_RET_ENC_EC(ret);
  23901. if (XMEMCMP(okm1, res3, (unsigned long)L) != 0)
  23902. return WC_TEST_RET_ENC_NC;
  23903. #ifndef HAVE_FIPS
  23904. /* fips can't have key size under 14 bytes, salt is key too */
  23905. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1),
  23906. salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, (word32)L);
  23907. if (ret != 0)
  23908. return WC_TEST_RET_ENC_EC(ret);
  23909. if (XMEMCMP(okm1, res4, (unsigned long)L) != 0)
  23910. return WC_TEST_RET_ENC_NC;
  23911. #endif /* HAVE_FIPS */
  23912. #endif /* !NO_SHA256 */
  23913. #endif /* !NO_SHA || !NO_SHA256 */
  23914. return ret;
  23915. }
  23916. #endif /* HAVE_HKDF */
  23917. #ifdef WOLFSSL_WOLFSSH
  23918. typedef struct {
  23919. byte hashId;
  23920. byte keyId;
  23921. const byte* k;
  23922. word32 kSz;
  23923. const byte* h;
  23924. word32 hSz;
  23925. const byte* sessionId;
  23926. word32 sessionIdSz;
  23927. const byte* expectedKey;
  23928. word32 expectedKeySz;
  23929. } SshKdfTestVector;
  23930. /** Test Vector Set #3: SHA-256 **/
  23931. static const byte sshKdfTvSet3k[] = {
  23932. 0x6A, 0xC3, 0x82, 0xEA, 0xAC, 0xA0, 0x93, 0xE1,
  23933. 0x25, 0xE2, 0x5C, 0x24, 0xBE, 0xBC, 0x84, 0x64,
  23934. 0x0C, 0x11, 0x98, 0x75, 0x07, 0x34, 0x4B, 0x5C,
  23935. 0x73, 0x9C, 0xEB, 0x84, 0xA9, 0xE0, 0xB2, 0x22,
  23936. 0xB9, 0xA8, 0xB5, 0x1C, 0x83, 0x9E, 0x5E, 0xBE,
  23937. 0x49, 0xCF, 0xAD, 0xBF, 0xB3, 0x95, 0x99, 0x76,
  23938. 0x4E, 0xD5, 0x22, 0x09, 0x9D, 0xC9, 0x12, 0x75,
  23939. 0x19, 0x50, 0xDC, 0x7D, 0xC9, 0x7F, 0xBD, 0xC0,
  23940. 0x63, 0x28, 0xB6, 0x8F, 0x22, 0x78, 0x1F, 0xD3,
  23941. 0x15, 0xAF, 0x56, 0x80, 0x09, 0xA5, 0x50, 0x9E,
  23942. 0x5B, 0x87, 0xA1, 0x1B, 0xF5, 0x27, 0xC0, 0x56,
  23943. 0xDA, 0xFF, 0xD8, 0x2A, 0xB6, 0xCB, 0xC2, 0x5C,
  23944. 0xCA, 0x37, 0x14, 0x34, 0x59, 0xE7, 0xBC, 0x63,
  23945. 0xBC, 0xDE, 0x52, 0x75, 0x7A, 0xDE, 0xB7, 0xDF,
  23946. 0x01, 0xCF, 0x12, 0x17, 0x3F, 0x1F, 0xEF, 0x81,
  23947. 0x02, 0xEC, 0x5A, 0xB1, 0x42, 0xC2, 0x13, 0xDD,
  23948. 0x9D, 0x30, 0x69, 0x62, 0x78, 0xA8, 0xD8, 0xBC,
  23949. 0x32, 0xDD, 0xE9, 0x59, 0x2D, 0x28, 0xC0, 0x78,
  23950. 0xC6, 0xD9, 0x2B, 0x94, 0x7D, 0x82, 0x5A, 0xCA,
  23951. 0xAB, 0x64, 0x94, 0x84, 0x6A, 0x49, 0xDE, 0x24,
  23952. 0xB9, 0x62, 0x3F, 0x48, 0x89, 0xE8, 0xAD, 0xC3,
  23953. 0x8E, 0x8C, 0x66, 0x9E, 0xFF, 0xEF, 0x17, 0x60,
  23954. 0x40, 0xAD, 0x94, 0x5E, 0x90, 0xA7, 0xD3, 0xEE,
  23955. 0xC1, 0x5E, 0xFE, 0xEE, 0x78, 0xAE, 0x71, 0x04,
  23956. 0x3C, 0x96, 0x51, 0x11, 0x03, 0xA1, 0x6B, 0xA7,
  23957. 0xCA, 0xF0, 0xAC, 0xD0, 0x64, 0x2E, 0xFD, 0xBE,
  23958. 0x80, 0x99, 0x34, 0xFA, 0xA1, 0xA5, 0xF1, 0xBD,
  23959. 0x11, 0x04, 0x36, 0x49, 0xB2, 0x5C, 0xCD, 0x1F,
  23960. 0xEE, 0x2E, 0x38, 0x81, 0x5D, 0x4D, 0x5F, 0x5F,
  23961. 0xC6, 0xB4, 0x10, 0x29, 0x69, 0xF2, 0x1C, 0x22,
  23962. 0xAE, 0x1B, 0x0E, 0x7D, 0x36, 0x03, 0xA5, 0x56,
  23963. 0xA1, 0x32, 0x62, 0xFF, 0x62, 0x8D, 0xE2, 0x22
  23964. };
  23965. static const byte sshKdfTvSet3h[] = {
  23966. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23967. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23968. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23969. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23970. };
  23971. static const byte sshKdfTvSet3sid[] = {
  23972. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23973. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23974. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23975. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23976. };
  23977. static const byte sshKdfTvSet3a[] = {
  23978. 0x81, 0xF0, 0x33, 0x0E, 0xF6, 0xF0, 0x53, 0x61,
  23979. 0xB3, 0x82, 0x3B, 0xFD, 0xED, 0x6E, 0x1D, 0xE9
  23980. };
  23981. static const byte sshKdfTvSet3b[] = {
  23982. 0x3F, 0x6F, 0xD2, 0x06, 0x5E, 0xEB, 0x2B, 0x0B,
  23983. 0x1D, 0x93, 0x19, 0x5A, 0x1F, 0xED, 0x48, 0xA5
  23984. };
  23985. static const byte sshKdfTvSet3c[] = {
  23986. 0xC3, 0x54, 0x71, 0x03, 0x4E, 0x6F, 0xD6, 0x54,
  23987. 0x76, 0x13, 0x17, 0x8E, 0x23, 0x43, 0x5F, 0x21
  23988. };
  23989. static const byte sshKdfTvSet3d[] = {
  23990. 0x7E, 0x9D, 0x79, 0x03, 0x20, 0x90, 0xD9, 0x9F,
  23991. 0x98, 0xB0, 0x15, 0x63, 0x4D, 0xD9, 0xF4, 0x62
  23992. };
  23993. static const byte sshKdfTvSet3e[] = {
  23994. 0x24, 0xEE, 0x55, 0x9A, 0xD7, 0xCE, 0x71, 0x2B,
  23995. 0x68, 0x5D, 0x0B, 0x22, 0x71, 0xE4, 0x43, 0xC1,
  23996. 0x7A, 0xB1, 0xD1, 0xDC, 0xEB, 0x5A, 0x36, 0x05,
  23997. 0x69, 0xD2, 0x5D, 0x5D, 0xC2, 0x43, 0x00, 0x2F
  23998. };
  23999. static const byte sshKdfTvSet3f[] = {
  24000. 0xC3, 0x41, 0x9C, 0x2B, 0x96, 0x62, 0x35, 0x86,
  24001. 0x9D, 0x71, 0x4B, 0xA5, 0xAC, 0x48, 0xDD, 0xB7,
  24002. 0xD9, 0xE3, 0x5C, 0x8C, 0x19, 0xAA, 0xC7, 0x34,
  24003. 0x22, 0x33, 0x7A, 0x37, 0x34, 0x53, 0x60, 0x7E
  24004. };
  24005. static const SshKdfTestVector sshKdfTestVectors[] = {
  24006. {WC_HASH_TYPE_SHA256, 'A',
  24007. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24008. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24009. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24010. sshKdfTvSet3a, sizeof(sshKdfTvSet3a)},
  24011. {WC_HASH_TYPE_SHA256, 'B',
  24012. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24013. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24014. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24015. sshKdfTvSet3b, sizeof(sshKdfTvSet3b)},
  24016. {WC_HASH_TYPE_SHA256, 'C',
  24017. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24018. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24019. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24020. sshKdfTvSet3c, sizeof(sshKdfTvSet3c)},
  24021. {WC_HASH_TYPE_SHA256, 'D',
  24022. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24023. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24024. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24025. sshKdfTvSet3d, sizeof(sshKdfTvSet3d)},
  24026. {WC_HASH_TYPE_SHA256, 'E',
  24027. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24028. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24029. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24030. sshKdfTvSet3e, sizeof(sshKdfTvSet3e)},
  24031. {WC_HASH_TYPE_SHA256, 'F',
  24032. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24033. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24034. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24035. sshKdfTvSet3f, sizeof(sshKdfTvSet3f)},
  24036. };
  24037. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void)
  24038. {
  24039. byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and WC_AES_BLOCK_SIZE */
  24040. word32 i;
  24041. word32 tc = sizeof(sshKdfTestVectors)/sizeof(SshKdfTestVector);
  24042. const SshKdfTestVector* tv = NULL;
  24043. wc_test_ret_t result = 0;
  24044. WOLFSSL_ENTER("sshkdf_test");
  24045. /* sId - Session ID, eKey - Expected Key, cKey - Calculated Key */
  24046. for (i = 0, tv = sshKdfTestVectors; i < tc; i++, tv++) {
  24047. result = wc_SSH_KDF(tv->hashId, tv->keyId,
  24048. cKey, tv->expectedKeySz,
  24049. tv->k, tv->kSz, tv->h, tv->hSz,
  24050. tv->sessionId, tv->sessionIdSz);
  24051. if (result != 0) {
  24052. printf("KDF: Could not derive key.\n");
  24053. result = WC_TEST_RET_ENC_EC(result);
  24054. }
  24055. else {
  24056. if (XMEMCMP(cKey, tv->expectedKey, tv->expectedKeySz) != 0) {
  24057. printf("KDF: Calculated Key does not match Expected Key.\n");
  24058. result = WC_TEST_RET_ENC_EC(result);
  24059. }
  24060. }
  24061. if (result != 0) break;
  24062. }
  24063. return result;
  24064. }
  24065. #endif /* WOLFSSL_WOLFSSH */
  24066. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  24067. #define DIGL 12
  24068. #define SECL 48
  24069. #define LBSL 63
  24070. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void)
  24071. {
  24072. int ret;
  24073. byte dig[DIGL] = {0};
  24074. byte secret[SECL] = {
  24075. 0x10, 0xbc, 0xb4, 0xa2, 0xe8, 0xdc, 0xf1, 0x9b, 0x4c,
  24076. 0x51, 0x9c, 0xed, 0x31, 0x1b, 0x51, 0x57, 0x02, 0x3f,
  24077. 0xa1, 0x7d, 0xfb, 0x0e, 0xf3, 0x4e, 0x8f, 0x6f, 0x71,
  24078. 0xa3, 0x67, 0x76, 0x6b, 0xfa, 0x5d, 0x46, 0x4a, 0xe8,
  24079. 0x61, 0x18, 0x81, 0xc4, 0x66, 0xcc, 0x6f, 0x09, 0x99,
  24080. 0x9d, 0xfc, 0x47
  24081. };
  24082. byte lablSd[LBSL] = {
  24083. 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69,
  24084. 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x0b, 0x46, 0xba,
  24085. 0x56, 0xbf, 0x1f, 0x5d, 0x99, 0xff, 0xe9, 0xbb, 0x43,
  24086. 0x01, 0xe7, 0xca, 0x2c, 0x00, 0xdf, 0x9a, 0x39, 0x6e,
  24087. 0xcf, 0x6d, 0x15, 0x27, 0x4d, 0xf2, 0x93, 0x96, 0x4a,
  24088. 0x91, 0xde, 0x5c, 0xc0, 0x47, 0x7c, 0xa8, 0xae, 0xcf,
  24089. 0x5d, 0x93, 0x5f, 0x4c, 0x92, 0xcc, 0x98, 0x5b, 0x43
  24090. };
  24091. byte expected[DIGL] = {
  24092. 0xee, 0xcb, 0xb1, 0x30, 0xf2, 0xcd, 0xb3, 0x4a,
  24093. 0xbe, 0xda, 0xc1, 0xf6
  24094. };
  24095. int digL = DIGL;
  24096. int secL = SECL;
  24097. int lblsdL = LBSL;
  24098. int hash_type = sha384_mac;
  24099. ret = wc_PRF(dig, (word32)digL, secret, (word32)secL, lablSd,
  24100. (word32)lblsdL, hash_type,
  24101. HEAP_HINT, INVALID_DEVID);
  24102. if (ret != 0) {
  24103. printf("Failed w/ code: %d\n", ret);
  24104. return WC_TEST_RET_ENC_EC(ret);
  24105. }
  24106. if (XMEMCMP(expected, dig, DIGL) != 0) {
  24107. printf("Got unexpected digest\n");
  24108. return WC_TEST_RET_ENC_NC;
  24109. }
  24110. return 0;
  24111. }
  24112. #endif /* WOLFSSL_HAVE_PRF && !NO_HMAC */
  24113. #ifdef WOLFSSL_HAVE_PRF
  24114. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  24115. #ifdef WOLFSSL_BASE16
  24116. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
  24117. {
  24118. const char* preMasterSecret = "D06F9C19BFF49B1E91E4EFE97345D089"
  24119. "4E6C2E6C34A165B24540E2970875D641"
  24120. "2AA6515871B389B4C199BB8389C71CED";
  24121. const char* helloRandom = "162B81EDFBEAE4F25240320B87E7651C"
  24122. "865564191DD782DB0B9ECA275FBA1BB9"
  24123. "5A1DA3DF436D68DA86C5E7B4B4A36E46"
  24124. "B977C61767983A31BE270D74517BD0F6";
  24125. const char* masterSecret = "EB38B8D89B98B1C266DE44BB3CA14E83"
  24126. "C32F009F9955B1D994E61D3C51EE8760"
  24127. "90B4EF89CC7AF42F46E72201BFCC7977";
  24128. const char* label = "master secret";
  24129. byte pms[48] = {0};
  24130. byte seed[64] = {0};
  24131. byte ms[48] = {0};
  24132. byte result[48] = {0};
  24133. word32 pmsSz = (word32)sizeof(pms);
  24134. word32 seedSz = (word32)sizeof(seed);
  24135. word32 msSz = (word32)sizeof(ms);
  24136. int ret;
  24137. ret = Base16_Decode((const byte*)preMasterSecret,
  24138. (word32)XSTRLEN(preMasterSecret), pms, &pmsSz);
  24139. if (ret != 0)
  24140. return ret;
  24141. ret = Base16_Decode((const byte*)helloRandom,
  24142. (word32)XSTRLEN(helloRandom), seed, &seedSz);
  24143. if (ret != 0)
  24144. return ret;
  24145. ret = Base16_Decode((const byte*)masterSecret,
  24146. (word32)XSTRLEN(masterSecret), ms, &msSz);
  24147. if (ret != 0)
  24148. return ret;
  24149. ret = wc_PRF_TLS(result, msSz, pms, pmsSz,
  24150. (const byte*)label, (word32)XSTRLEN(label), seed, seedSz,
  24151. 1, sha256_mac, NULL, INVALID_DEVID);
  24152. if (ret != 0) {
  24153. if (ret == WC_NO_ERR_TRACE(FIPS_PRIVATE_KEY_LOCKED_E)) {
  24154. printf(" wc_PRF_TLSv12: Private key locked.\n");
  24155. }
  24156. return WC_TEST_RET_ENC_NC;
  24157. }
  24158. if (XMEMCMP(result, ms, msSz) != 0)
  24159. return WC_TEST_RET_ENC_NC;
  24160. return 0;
  24161. }
  24162. #endif /* WOLFSSL_BASE16 */
  24163. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  24164. #endif /* WOLFSSL_HAVE_PRF */
  24165. #ifdef WOLFSSL_TLS13
  24166. #define TLSV13_PSK_DHE_SZ 40
  24167. typedef struct {
  24168. enum wc_HashType hashAlg;
  24169. word32 pskSz;
  24170. word32 dheSz;
  24171. byte psk[TLSV13_PSK_DHE_SZ];
  24172. byte dhe[TLSV13_PSK_DHE_SZ];
  24173. byte hashHello1[WC_MAX_DIGEST_SIZE];
  24174. byte hashHello2[WC_MAX_DIGEST_SIZE];
  24175. byte hashFinished1[WC_MAX_DIGEST_SIZE];
  24176. byte hashFinished2[WC_MAX_DIGEST_SIZE];
  24177. /* Expected */
  24178. byte clientEarlyTrafficSecret[WC_MAX_DIGEST_SIZE];
  24179. byte earlyExporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24180. byte clientHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24181. byte serverHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24182. byte clientApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24183. byte serverApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24184. byte exporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24185. byte resumptionMasterSecret[WC_MAX_DIGEST_SIZE];
  24186. } Tls13KdfTestVector;
  24187. /* The following tests come from the CAVP test vectors we used for
  24188. * our FIPS validation. The hash values used are the components from
  24189. * the test hashed together. hashHello1 is the hash of the
  24190. * clientHelloRandom value of the test vector. hashHello2 is the hash
  24191. * of the clientHelloRandom and serverHelloRandom values from the test
  24192. * vector. hashFinished1 is clientHelloRandom, serverHelloRandom, and
  24193. * serverFinishedRandom. hashFinished2 is clientHelloRandom,
  24194. * serverHelloRandom, serverFinishedRandom, and clietnFinishedRandom
  24195. * hashed together. */
  24196. static const Tls13KdfTestVector tls13KdfTestVectors[] = {
  24197. { /* 1 */
  24198. WC_HASH_TYPE_SHA256, 35, 35,
  24199. { /* PSK */
  24200. 0x7b, 0xf1, 0x05, 0x31, 0x36, 0xfa, 0x03, 0xdc,
  24201. 0x31, 0x97, 0x88, 0x04, 0x9c, 0xbc, 0xee, 0xf7,
  24202. 0x8d, 0x84, 0x95, 0x26, 0xaf, 0x1d, 0x68, 0xb0,
  24203. 0x60, 0x7a, 0xcc, 0x4f, 0xc1, 0xd3, 0xa1, 0x68,
  24204. 0x7f, 0x6d, 0xbe
  24205. },
  24206. { /* DHE */
  24207. 0x6e, 0xa1, 0x77, 0xab, 0x2f, 0x43, 0xd2, 0x4b,
  24208. 0xe5, 0xa1, 0x09, 0xe0, 0x7a, 0xd0, 0x01, 0x35,
  24209. 0x8d, 0xf8, 0xf2, 0x5c, 0x91, 0x02, 0xb0, 0x6c,
  24210. 0x3f, 0xeb, 0xee, 0xa4, 0x42, 0x19, 0xce, 0xdc,
  24211. 0x81, 0x26, 0x40
  24212. },
  24213. { /* Hello 1 */
  24214. 0xd9, 0x4b, 0xe4, 0x17, 0xef, 0x58, 0x73, 0x7d,
  24215. 0x28, 0x3d, 0xf0, 0xcc, 0x05, 0x03, 0xaf, 0xac,
  24216. 0x3d, 0x92, 0x79, 0x48, 0xe8, 0x8c, 0xdb, 0xce,
  24217. 0x95, 0x82, 0x21, 0x31, 0x7b, 0x61, 0xd7, 0xc6
  24218. },
  24219. { /* Hello 2 */
  24220. 0xb7, 0x7f, 0x29, 0x91, 0xa4, 0x8b, 0x34, 0xdb,
  24221. 0xbd, 0xc7, 0x54, 0x1c, 0x3b, 0x86, 0xa3, 0x69,
  24222. 0xfe, 0x26, 0xe4, 0x7b, 0xac, 0x57, 0x71, 0xb3,
  24223. 0x32, 0x97, 0xed, 0xd2, 0x0e, 0x95, 0xb8, 0x63
  24224. },
  24225. { /* Finished 1 */
  24226. 0x65, 0xdb, 0x6d, 0x71, 0x71, 0xd0, 0xd8, 0x49,
  24227. 0xd0, 0x3c, 0x8e, 0x2b, 0x24, 0xdf, 0xc2, 0xe9,
  24228. 0xd6, 0xfd, 0xea, 0x04, 0x95, 0x7c, 0xf0, 0x7e,
  24229. 0x57, 0x74, 0x7c, 0xdd, 0xa3, 0x0b, 0x2b, 0x36
  24230. },
  24231. { /* Finished 2 */
  24232. 0x28, 0xf2, 0xf2, 0x79, 0xcf, 0x20, 0x52, 0x90,
  24233. 0x1d, 0x91, 0x05, 0xad, 0x44, 0x26, 0x23, 0x96,
  24234. 0x32, 0xce, 0xec, 0x61, 0xd1, 0xbf, 0x00, 0x48,
  24235. 0x4a, 0xa5, 0x60, 0xcc, 0x28, 0xb5, 0x8d, 0x98
  24236. },
  24237. { /* Client Early Traffic Secret */
  24238. 0x07, 0x14, 0x6a, 0x26, 0x5b, 0x6c, 0x7f, 0x4d, 0x6b, 0x47, 0x3f, 0xd5,
  24239. 0x03, 0x1d, 0xd2, 0x23, 0x3d, 0x89, 0x3e, 0xc6, 0x51, 0xd1, 0xac, 0xf8,
  24240. 0x28, 0xae, 0x4b, 0x76, 0xc8, 0x10, 0x7e, 0xdd
  24241. },
  24242. { /* Early Exporter Master Secret */
  24243. 0xb8, 0xd3, 0x25, 0x7e, 0x2d, 0x41, 0x7b, 0xcb, 0x5e, 0x82, 0x49, 0xf5,
  24244. 0x51, 0x3d, 0xb7, 0x59, 0x32, 0xb3, 0xdf, 0x99, 0x4e, 0x04, 0x69, 0xc6,
  24245. 0x96, 0x8e, 0xe6, 0x3d, 0x91, 0xe4, 0x81, 0x11
  24246. },
  24247. { /* Client Handshake Traffic Secret */
  24248. 0xd9, 0x3b, 0x54, 0xe2, 0xb0, 0xd1, 0x85, 0xf0, 0xfd, 0xf3, 0x48, 0x4a,
  24249. 0xf8, 0x0b, 0xa5, 0xdc, 0x4c, 0x37, 0xcb, 0xd4, 0x20, 0xaf, 0x60, 0xc7,
  24250. 0xd5, 0x50, 0x5d, 0x0c, 0x77, 0x3b, 0x6f, 0xd2
  24251. },
  24252. { /* Server Handshake Traffic Secret */
  24253. 0x4d, 0x40, 0x2b, 0xd2, 0x8c, 0x33, 0x90, 0x39, 0x67, 0x67, 0x05, 0xf7,
  24254. 0x5d, 0x37, 0x1e, 0xdc, 0x4a, 0x70, 0x6b, 0x9e, 0xf8, 0x06, 0x61, 0x89,
  24255. 0x70, 0xe1, 0x3d, 0x36, 0xad, 0x88, 0x7e, 0x5b
  24256. },
  24257. { /* Client Application Traffic Secret */
  24258. 0x74, 0x6e, 0xa0, 0x13, 0x18, 0x34, 0x48, 0x4d, 0x23, 0x31, 0xf1, 0xf9,
  24259. 0xee, 0x44, 0x6d, 0xad, 0xc1, 0xad, 0x92, 0x73, 0xca, 0x27, 0x16, 0x91,
  24260. 0xa2, 0x50, 0x9a, 0xfc, 0xec, 0xf0, 0x6b, 0x24
  24261. },
  24262. { /* Server Application Traffic Secret */
  24263. 0x89, 0x18, 0x7e, 0x34, 0x8d, 0xfc, 0x14, 0xb1, 0x4f, 0x21, 0xd8, 0x29,
  24264. 0xdb, 0x9b, 0xfb, 0x55, 0xcf, 0xa1, 0x4f, 0x95, 0xf8, 0xe0, 0xb0, 0x83,
  24265. 0xd5, 0x34, 0x9e, 0x0b, 0x83, 0x37, 0x42, 0x93
  24266. },
  24267. { /* Exporter Master Secret */
  24268. 0x7d, 0xc8, 0x88, 0x46, 0xd5, 0x57, 0x15, 0xb6, 0x24, 0x25, 0x92, 0x61,
  24269. 0xb1, 0x18, 0x86, 0x2a, 0x6d, 0xa5, 0x84, 0xeb, 0x59, 0xdf, 0x13, 0xbd,
  24270. 0x73, 0xaa, 0x5d, 0x65, 0xab, 0xd9, 0xb4, 0x56
  24271. },
  24272. { /* Resumption Master Secret */
  24273. 0x20, 0xb7, 0xd0, 0xe3, 0x82, 0x01, 0xa1, 0x04, 0xb8, 0x13, 0x29, 0xed,
  24274. 0x35, 0xe4, 0x2f, 0xbf, 0x58, 0x23, 0x7f, 0x21, 0xdb, 0x9f, 0xf8, 0xe0,
  24275. 0xe8, 0xe4, 0xab, 0xc4, 0xa1, 0x61, 0xb9, 0xbb
  24276. }
  24277. },
  24278. { /* 6 */
  24279. WC_HASH_TYPE_SHA256, 0, 33,
  24280. { 0 }, /* PSK */
  24281. { /* DHE */
  24282. 0x7a, 0x46, 0x8c, 0x5a, 0xd1, 0x8e, 0x95, 0xba,
  24283. 0x61, 0xe6, 0x6f, 0xe6, 0x76, 0x0c, 0x20, 0x43,
  24284. 0x16, 0x82, 0x15, 0xfe, 0x54, 0xa3, 0xc7, 0xfd,
  24285. 0x3b, 0x2c, 0x88, 0xb4, 0xd3, 0x42, 0x70, 0x12,
  24286. 0x18
  24287. },
  24288. { /* Hello 1 */
  24289. 0x63, 0x83, 0x58, 0xab, 0x36, 0xcd, 0x0c, 0xf3,
  24290. 0x26, 0x07, 0xb5, 0x5f, 0x0b, 0x8b, 0x45, 0xd6,
  24291. 0x7d, 0x5b, 0x42, 0xdc, 0xa8, 0xaa, 0x06, 0xfb,
  24292. 0x20, 0xa5, 0xbb, 0x85, 0xdb, 0x54, 0xd8, 0x8b
  24293. },
  24294. { /* Hello 2 */
  24295. 0xea, 0xfe, 0x9e, 0x8e, 0xff, 0x1f, 0x6f, 0x43,
  24296. 0xf9, 0x5d, 0xfd, 0xbf, 0xe2, 0x5f, 0x02, 0x2f,
  24297. 0x6d, 0x47, 0x60, 0x9a, 0x48, 0x9a, 0x75, 0xfb,
  24298. 0xb5, 0x4a, 0xbf, 0x9c, 0x4e, 0xff, 0xbf, 0x0b
  24299. },
  24300. { /* Finished 1 */
  24301. 0xca, 0x25, 0xb3, 0x53, 0x8e, 0x6d, 0xc3, 0x36,
  24302. 0x17, 0x30, 0x07, 0xdf, 0x0d, 0xd7, 0x79, 0xb0,
  24303. 0x7f, 0xcb, 0xbe, 0x7a, 0xbc, 0x2d, 0x9f, 0x2d,
  24304. 0x94, 0x44, 0x94, 0xe6, 0xa4, 0xf3, 0xe8, 0x53
  24305. },
  24306. { /* Finished 2 */
  24307. 0x2e, 0xa6, 0x5a, 0xaf, 0xb5, 0xba, 0x9f, 0x2f,
  24308. 0x74, 0x83, 0x5d, 0xbf, 0x86, 0xa4, 0xa6, 0xf6,
  24309. 0xb9, 0x89, 0xdf, 0x17, 0xe1, 0xa8, 0x14, 0xc0,
  24310. 0xe1, 0x50, 0xfa, 0xec, 0xfa, 0xae, 0x8b, 0x7b
  24311. },
  24312. {
  24313. 0x20, 0x18, 0x72, 0x7c, 0xde, 0x3a, 0x85, 0x17, 0x72, 0xdc, 0xd7, 0x72,
  24314. 0xb0, 0xfc, 0x45, 0xd0, 0x62, 0xb9, 0xbb, 0x38, 0x69, 0x05, 0x7b, 0xb4,
  24315. 0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
  24316. },
  24317. {
  24318. 0x68, 0x10, 0x20, 0xd1, 0x5e, 0xfc, 0x0c, 0x53, 0x85, 0xbb, 0xdb, 0x18,
  24319. 0xa8, 0x78, 0xf1, 0x2b, 0x13, 0xba, 0x64, 0x1d, 0xe7, 0x09, 0xbe, 0x13,
  24320. 0x49, 0x26, 0xf9, 0x98, 0x56, 0xf1, 0x43, 0xfb
  24321. },
  24322. {
  24323. 0x24, 0x35, 0x3e, 0x10, 0x6f, 0x39, 0x50, 0xd6, 0xa2, 0x12, 0x99, 0xf2,
  24324. 0xd5, 0xf5, 0x19, 0xf5, 0x84, 0xed, 0xee, 0x78, 0x2a, 0xa6, 0xfa, 0x3d,
  24325. 0x06, 0xa8, 0xa7, 0x5d, 0x97, 0x78, 0xd6, 0x58
  24326. },
  24327. {
  24328. 0xf4, 0x57, 0xac, 0x24, 0x7a, 0xfb, 0x7c, 0x3b, 0xb6, 0x39, 0x17, 0x14,
  24329. 0xd9, 0xd4, 0x58, 0x4d, 0x46, 0xd5, 0x1b, 0xde, 0xf7, 0x9d, 0x06, 0xee,
  24330. 0x8d, 0x1a, 0x2c, 0x25, 0x6d, 0x64, 0xde, 0x89
  24331. },
  24332. {
  24333. 0xb6, 0x00, 0xce, 0x63, 0xed, 0x65, 0x8b, 0x66, 0x66, 0x42, 0xc6, 0xbd,
  24334. 0x89, 0xc4, 0x71, 0x6f, 0xce, 0x28, 0xb2, 0xac, 0x97, 0x07, 0x5b, 0xea,
  24335. 0xb8, 0x1d, 0x4c, 0xeb, 0x9e, 0x71, 0x07, 0x8f
  24336. },
  24337. {
  24338. 0xf8, 0x92, 0xc8, 0xba, 0xe7, 0x83, 0xfe, 0x68, 0xe4, 0xd6, 0x5e, 0xcb,
  24339. 0xb3, 0xef, 0x49, 0xd0, 0xe7, 0xb1, 0xac, 0xcb, 0x39, 0x19, 0xfd, 0xa7,
  24340. 0xf7, 0xca, 0xab, 0x1e, 0x42, 0x14, 0xd8, 0xe7
  24341. },
  24342. {
  24343. 0x32, 0x4a, 0x1a, 0xad, 0xe2, 0xbb, 0x55, 0x8a, 0xdd, 0xe9, 0xa5, 0x2a,
  24344. 0x46, 0x5e, 0x6c, 0x83, 0x66, 0x27, 0x27, 0x94, 0xdd, 0x68, 0x59, 0xa0,
  24345. 0xbb, 0xe8, 0x31, 0x7c, 0x39, 0xd7, 0xfd, 0x6d
  24346. },
  24347. {
  24348. 0x58, 0xbc, 0x6c, 0x5b, 0x24, 0xad, 0x82, 0xb3, 0xcc, 0xc7, 0xd1, 0xa1,
  24349. 0xaa, 0x2b, 0x98, 0x9f, 0x2f, 0x7e, 0xa9, 0x63, 0xc2, 0x8e, 0xb6, 0x06,
  24350. 0xc2, 0x2b, 0x74, 0x4b, 0x79, 0x19, 0x7e, 0x2e
  24351. }
  24352. },
  24353. { /* 11 */
  24354. WC_HASH_TYPE_SHA256, 33, 0,
  24355. { /* PSK */
  24356. 0x3d, 0x39, 0x49, 0x36, 0x98, 0xc5, 0xfd, 0xcd,
  24357. 0xa0, 0x17, 0xbd, 0x65, 0x0a, 0xdb, 0xd4, 0x07,
  24358. 0x56, 0xa2, 0x7b, 0xb8, 0x2a, 0x7e, 0xfb, 0x26,
  24359. 0x74, 0xe1, 0xbc, 0x08, 0x4b, 0xf0, 0x30, 0x14,
  24360. 0x12
  24361. },
  24362. { 0 }, /* DHE */
  24363. { /* Hello 1 */
  24364. 0xb7, 0x44, 0x74, 0x6c, 0x57, 0x1f, 0xf3, 0x84,
  24365. 0x8f, 0x63, 0xfb, 0x8c, 0x94, 0x6c, 0x16, 0x68,
  24366. 0x4b, 0xe1, 0xb5, 0xb5, 0x2a, 0x4e, 0x5f, 0xdf,
  24367. 0x4b, 0x53, 0xb2, 0x35, 0xfc, 0x30, 0xf1, 0x36
  24368. },
  24369. { /* Hello 2 */
  24370. 0xe6, 0x4f, 0x3a, 0x4f, 0xd7, 0xe0, 0x64, 0xd4,
  24371. 0x69, 0x50, 0xe4, 0x8b, 0xba, 0xbc, 0x47, 0x74,
  24372. 0xa7, 0x9b, 0x40, 0x91, 0x8f, 0xa8, 0x72, 0x22,
  24373. 0x97, 0xad, 0x43, 0xa7, 0x11, 0x86, 0xb5, 0x72
  24374. },
  24375. { /* Finished 1 */
  24376. 0x5f, 0xa6, 0x10, 0xe2, 0xa3, 0x99, 0x0b, 0x5e,
  24377. 0x57, 0xee, 0xc3, 0x3a, 0x8e, 0x04, 0xf3, 0x0e,
  24378. 0x58, 0x02, 0x09, 0xb2, 0x7e, 0x2d, 0xc6, 0xd2,
  24379. 0x08, 0xae, 0x68, 0x0a, 0x55, 0xa5, 0xda, 0x51
  24380. },
  24381. { /* Finished 2 */
  24382. 0xfc, 0x5b, 0xc0, 0x7e, 0x1b, 0xaa, 0xc0, 0xb4,
  24383. 0x34, 0x85, 0x49, 0x8e, 0x16, 0x31, 0x98, 0xdf,
  24384. 0x10, 0x54, 0x22, 0xda, 0x1e, 0x6b, 0x51, 0xf6,
  24385. 0x97, 0x57, 0xa0, 0x7a, 0x92, 0xe7, 0x47, 0x52
  24386. },
  24387. {
  24388. 0x80, 0xfa, 0x36, 0x30, 0xb8, 0x65, 0xb3, 0x2a, 0x1d, 0x68, 0x91, 0x06,
  24389. 0x98, 0xa0, 0x17, 0x8f, 0xee, 0xb7, 0x9e, 0x3d, 0xd8, 0x84, 0x99, 0x30,
  24390. 0xb9, 0xd6, 0x09, 0x25, 0x5e, 0xfb, 0x8f, 0xd3 },
  24391. {
  24392. 0xa9, 0x89, 0x29, 0x70, 0xe4, 0x55, 0xec, 0x97, 0xfb, 0x24, 0x5b, 0xf9,
  24393. 0xf1, 0xa3, 0x19, 0x3d, 0xf1, 0x31, 0x14, 0xcd, 0x2a, 0xed, 0x21, 0xc8,
  24394. 0xb1, 0x53, 0xad, 0x11, 0x0b, 0x9e, 0x5a, 0xee },
  24395. {
  24396. 0x72, 0xad, 0x8d, 0x7f, 0xfc, 0xb7, 0x68, 0xda, 0x27, 0x60, 0x37, 0xa3,
  24397. 0x4a, 0x63, 0xe8, 0xa5, 0xc8, 0xcd, 0x36, 0x6a, 0x77, 0x99, 0x0d, 0xa9,
  24398. 0xb1, 0x5b, 0x2f, 0x47, 0x2e, 0x22, 0xa7, 0x5e },
  24399. {
  24400. 0x95, 0x6e, 0x85, 0x09, 0xe5, 0x04, 0x88, 0x14, 0x28, 0x8d, 0xdf, 0xe6,
  24401. 0x0d, 0x0f, 0x0d, 0x6b, 0x4e, 0x66, 0x1c, 0x03, 0xb9, 0xaa, 0x2d, 0x45,
  24402. 0x56, 0x67, 0x5c, 0x55, 0x29, 0xd6, 0x89, 0xd0 },
  24403. {
  24404. 0xe8, 0xf2, 0x14, 0xf9, 0x9b, 0x2b, 0x9f, 0x24, 0x2b, 0x37, 0xbe, 0x86,
  24405. 0xdb, 0x23, 0x4b, 0xbe, 0x39, 0x57, 0xe8, 0xa9, 0xa5, 0xee, 0x08, 0xf2,
  24406. 0x75, 0x58, 0xdb, 0xd9, 0x51, 0xc1, 0x46, 0x02 },
  24407. {
  24408. 0x3d, 0x19, 0xaf, 0xa3, 0x0b, 0x21, 0xf7, 0x3d, 0xe7, 0x37, 0x6e, 0x32,
  24409. 0x13, 0x48, 0x9d, 0xea, 0xe0, 0x90, 0xbf, 0x64, 0x48, 0xf7, 0x1e, 0xcc,
  24410. 0xf0, 0xbc, 0x92, 0xd7, 0x8a, 0x4a, 0xa8, 0xc1 },
  24411. {
  24412. 0x16, 0x35, 0xb1, 0x66, 0x28, 0xa3, 0x3e, 0x19, 0xf5, 0x2d, 0x92, 0x22,
  24413. 0x95, 0x48, 0xe8, 0x34, 0x7b, 0x30, 0x50, 0xa2, 0xa0, 0xd9, 0xc2, 0x59,
  24414. 0x39, 0xf9, 0x8c, 0x69, 0xf2, 0x2a, 0xb9, 0xff },
  24415. {
  24416. 0x32, 0x71, 0xa6, 0x87, 0x0c, 0x97, 0x42, 0x07, 0xdd, 0x5f, 0xc9, 0x44,
  24417. 0xa5, 0x7c, 0x50, 0x14, 0xfd, 0xe7, 0x5f, 0x8b, 0xd3, 0x2f, 0xdc, 0x9b,
  24418. 0xa9, 0x93, 0x22, 0x19, 0xe6, 0xf2, 0x0c, 0xd8 }
  24419. },
  24420. #ifdef WOLFSSL_SHA384
  24421. { /* 26 */
  24422. WC_HASH_TYPE_SHA384, 35, 35,
  24423. { /* PSK */
  24424. 0x62, 0x83, 0x25, 0xc7, 0xcc, 0x08, 0x5e, 0x63,
  24425. 0x64, 0x56, 0xf0, 0xc6, 0x88, 0x27, 0x5a, 0x5b,
  24426. 0x68, 0x59, 0x0b, 0x14, 0x55, 0x13, 0x2e, 0xfd,
  24427. 0x8f, 0x28, 0x5b, 0x3d, 0xe3, 0xad, 0x67, 0xe4,
  24428. 0x68, 0xba, 0xf9
  24429. },
  24430. { /* DHE */
  24431. 0xa8, 0xb1, 0xab, 0xd8, 0xc8, 0x5b, 0x52, 0xdf,
  24432. 0x7f, 0x49, 0x10, 0xf4, 0xa1, 0x31, 0xd1, 0x91,
  24433. 0x36, 0xc1, 0x87, 0x5d, 0x42, 0x2a, 0xe7, 0x1d,
  24434. 0x2c, 0x29, 0x3d, 0x40, 0x64, 0x61, 0x63, 0x76,
  24435. 0xd8, 0x66, 0xac
  24436. },
  24437. { /* Hello 1 */
  24438. 0x6f, 0xc6, 0x4c, 0xe1, 0xc6, 0x68, 0x34, 0x8c,
  24439. 0x0a, 0xe1, 0xf8, 0xb8, 0x3e, 0xd4, 0xf8, 0x0b,
  24440. 0x54, 0x50, 0xe4, 0xc5, 0x4a, 0x33, 0x7d, 0xbd,
  24441. 0x90, 0xd2, 0xa2, 0xb9, 0xb7, 0x92, 0xed, 0xab,
  24442. 0x14, 0xf1, 0xe4, 0x86, 0x22, 0x67, 0xd7, 0x44,
  24443. 0x03, 0x21, 0xdc, 0x51, 0x52, 0x7f, 0x35, 0x80
  24444. },
  24445. { /* Hello 2 */
  24446. 0x3e, 0xcf, 0x2f, 0xc3, 0x87, 0xba, 0xc5, 0xbd,
  24447. 0x7c, 0xe8, 0x35, 0x5b, 0x95, 0x51, 0x30, 0x3b,
  24448. 0x08, 0xcc, 0x2a, 0x7d, 0xb5, 0x74, 0x7c, 0x16,
  24449. 0xb3, 0x0b, 0xe7, 0x61, 0xa3, 0x7c, 0x6c, 0xbd,
  24450. 0x39, 0x74, 0xfd, 0x1e, 0x4c, 0xff, 0xc8, 0xcc,
  24451. 0xa0, 0xef, 0x29, 0x4d, 0x94, 0xaa, 0x55, 0x6f,
  24452. },
  24453. { /* Finished 1 */
  24454. 0x06, 0xc1, 0x47, 0x78, 0x66, 0x53, 0x6f, 0x24,
  24455. 0x94, 0x61, 0x69, 0xec, 0xd8, 0x60, 0x31, 0x2f,
  24456. 0xbf, 0xd6, 0x8a, 0x29, 0x17, 0xff, 0xa3, 0x88,
  24457. 0x13, 0x09, 0x8c, 0x9d, 0x6c, 0x64, 0x84, 0x48,
  24458. 0x44, 0xdd, 0x2d, 0x29, 0x4d, 0xe6, 0x98, 0x2b,
  24459. 0x45, 0x3b, 0x84, 0x33, 0x79, 0xb2, 0x75, 0x68
  24460. },
  24461. { /* Finished 2 */
  24462. 0x28, 0x1e, 0x18, 0xf7, 0x9c, 0x32, 0xa9, 0xbf,
  24463. 0x0c, 0x24, 0x58, 0x21, 0xce, 0xbc, 0xf2, 0x44,
  24464. 0xb1, 0x18, 0xaf, 0x9d, 0xd9, 0x20, 0xf9, 0xf4,
  24465. 0xed, 0xcc, 0x53, 0x82, 0x66, 0x5c, 0x46, 0x94,
  24466. 0x8c, 0x36, 0x5e, 0xca, 0x9f, 0xd8, 0x9a, 0xd3,
  24467. 0xf0, 0xe1, 0x53, 0x71, 0xdd, 0x19, 0x1e, 0x59
  24468. },
  24469. {
  24470. 0xd0, 0xef, 0xa8, 0xcb, 0x5b, 0x14, 0x0f, 0x0a, 0x62, 0xba, 0x5a, 0xb1,
  24471. 0xc5, 0xb5, 0x3f, 0x11, 0xda, 0xa1, 0x0c, 0x9c, 0xb4, 0x32, 0x48, 0x4e,
  24472. 0xfa, 0x84, 0x4f, 0xe4, 0xe7, 0x91, 0x8f, 0x42, 0x3f, 0xc7, 0x4e, 0xd3,
  24473. 0x83, 0x3d, 0x7f, 0x70, 0x12, 0xee, 0x9a, 0x37, 0x01, 0xbb, 0x14, 0xd3
  24474. },
  24475. {
  24476. 0x48, 0x6f, 0x77, 0x1d, 0x39, 0x1b, 0xa5, 0x9a, 0x76, 0xd9, 0x1d, 0x7d,
  24477. 0xb3, 0xd9, 0xb9, 0x78, 0x35, 0x0f, 0xd0, 0xe1, 0x07, 0x1f, 0x8d, 0xe5,
  24478. 0x75, 0x00, 0xda, 0xc0, 0x19, 0x01, 0xfb, 0x08, 0x35, 0xe7, 0x18, 0x8f,
  24479. 0xf0, 0x19, 0xfb, 0x46, 0xf6, 0xa5, 0x77, 0x0e, 0x90, 0x38, 0x8b, 0x15
  24480. },
  24481. {
  24482. 0x80, 0x8c, 0xa7, 0x24, 0x97, 0xf9, 0xd3, 0x52, 0xb0, 0x69, 0x9d, 0x4b,
  24483. 0xa4, 0x19, 0x4a, 0xb1, 0x46, 0x53, 0x3a, 0xc8, 0xe4, 0x02, 0x69, 0xf2,
  24484. 0xe7, 0xb6, 0x1d, 0x33, 0x51, 0xcc, 0x14, 0x40, 0x4a, 0xb0, 0xe7, 0x58,
  24485. 0x84, 0xba, 0xc2, 0x14, 0x58, 0x6b, 0xb9, 0xdc, 0x50, 0x98, 0x67, 0x01
  24486. },
  24487. {
  24488. 0xb1, 0xa8, 0xc0, 0x06, 0xb3, 0x2e, 0xa7, 0x8a, 0x6a, 0x12, 0x88, 0x00,
  24489. 0x65, 0x88, 0x9c, 0x5d, 0x35, 0xee, 0xe5, 0x51, 0x0b, 0x62, 0xf8, 0x67,
  24490. 0xe5, 0xef, 0x15, 0x1f, 0x23, 0x02, 0x74, 0x08, 0x9c, 0xc8, 0xba, 0x27,
  24491. 0x5d, 0x32, 0x19, 0x6f, 0x6d, 0x5d, 0x72, 0x5e, 0x15, 0xde, 0x30, 0xc3
  24492. },
  24493. {
  24494. 0xfd, 0xce, 0xf5, 0x65, 0x45, 0x84, 0xfb, 0x8c, 0x79, 0xa4, 0x6c, 0x1b,
  24495. 0x0e, 0x1b, 0xfd, 0x26, 0xa2, 0x53, 0xf4, 0x4e, 0x00, 0x4d, 0x4b, 0x0b,
  24496. 0x24, 0x6d, 0x35, 0x35, 0xd9, 0x97, 0x70, 0xc5, 0xf4, 0xee, 0xe3, 0xba,
  24497. 0x31, 0x1e, 0x2a, 0x42, 0xcb, 0xdf, 0x40, 0xb1, 0x14, 0xb8, 0x53, 0xce
  24498. },
  24499. {
  24500. 0xbb, 0xb3, 0x26, 0x7c, 0x22, 0x21, 0x9b, 0x72, 0x32, 0xa1, 0x97, 0xfb,
  24501. 0x78, 0x8c, 0xbe, 0x3d, 0x71, 0x45, 0xb8, 0xf5, 0x24, 0x8f, 0x0f, 0xac,
  24502. 0x42, 0x5b, 0x81, 0xe8, 0xd0, 0x71, 0x4a, 0xcb, 0x32, 0x3f, 0x03, 0xfb,
  24503. 0xec, 0x6a, 0x1f, 0x76, 0x80, 0x65, 0x01, 0x7a, 0x3d, 0xce, 0xc4, 0xdf
  24504. },
  24505. {
  24506. 0x3f, 0xcf, 0x2f, 0x63, 0x94, 0x94, 0x99, 0xfd, 0x04, 0x3a, 0x89, 0x83,
  24507. 0xcf, 0x06, 0x05, 0xec, 0x20, 0x3e, 0x5f, 0x51, 0x9d, 0x6e, 0x4a, 0xc6,
  24508. 0xf1, 0x2b, 0x37, 0x17, 0x34, 0x72, 0x6e, 0x1d, 0x2a, 0xfd, 0xc7, 0x73,
  24509. 0xb5, 0x07, 0x22, 0x81, 0x32, 0x2e, 0x21, 0x85, 0xaf, 0x10, 0xb2, 0x73
  24510. },
  24511. {
  24512. 0x52, 0x0c, 0x3d, 0x2e, 0x2d, 0x4a, 0x11, 0xae, 0x96, 0x78, 0xe9, 0x5b,
  24513. 0xd8, 0x0f, 0x6c, 0xf4, 0xbd, 0x96, 0x13, 0x55, 0x88, 0xdd, 0xa3, 0x67,
  24514. 0x36, 0x86, 0x1e, 0x0b, 0x36, 0x41, 0xec, 0xf6, 0x04, 0xb2, 0xc4, 0x16,
  24515. 0xbc, 0x2c, 0xdb, 0x30, 0x02, 0x94, 0xd4, 0x42, 0xbf, 0x38, 0xee, 0x9d
  24516. }
  24517. },
  24518. { /* 36 */
  24519. WC_HASH_TYPE_SHA384, 0, 33,
  24520. { 0 }, /* PSK */
  24521. { /* DHE */
  24522. 0xd3, 0x00, 0x72, 0x9a, 0xa8, 0xc5, 0xf3, 0xc4,
  24523. 0xf1, 0xa0, 0x26, 0x89, 0x65, 0x70, 0xc7, 0x0b,
  24524. 0x77, 0xbb, 0xe1, 0x4b, 0x2b, 0xa8, 0x4f, 0xa6,
  24525. 0x09, 0x4b, 0xba, 0x45, 0x36, 0x15, 0xee, 0x68,
  24526. 0xfd
  24527. },
  24528. { /* Hello 1 */
  24529. 0x10, 0x9d, 0x8b, 0xa2, 0x93, 0xe7, 0xd3, 0xb9,
  24530. 0xb4, 0x0f, 0xeb, 0x6a, 0xb9, 0x69, 0xcb, 0x39,
  24531. 0x16, 0x29, 0xcc, 0xd3, 0xcc, 0x1a, 0x4c, 0x1b,
  24532. 0x53, 0x7c, 0x33, 0x88, 0x06, 0xbc, 0x0a, 0x02,
  24533. 0xa0, 0xbe, 0x62, 0xc0, 0xe6, 0x5e, 0x97, 0x5b,
  24534. 0x6a, 0xa1, 0x98, 0xf3, 0xd2, 0x1e, 0xcd, 0xc5
  24535. },
  24536. { /* Hello 2 */
  24537. 0x74, 0xc0, 0x07, 0x2c, 0xc1, 0x63, 0xcc, 0x11,
  24538. 0xad, 0x1a, 0x55, 0x63, 0xbc, 0x20, 0x77, 0x96,
  24539. 0x30, 0x1c, 0x68, 0x45, 0x1e, 0x9b, 0xa7, 0xb4,
  24540. 0xf3, 0x04, 0x45, 0x16, 0x76, 0x55, 0xf9, 0xdf,
  24541. 0x4b, 0x2f, 0x1a, 0xdf, 0x5a, 0xb0, 0x93, 0xc9,
  24542. 0xab, 0xf5, 0x32, 0x47, 0x79, 0x9c, 0x01, 0xeb
  24543. },
  24544. { /* Finished 1 */
  24545. 0x27, 0x08, 0x8e, 0xa5, 0xf1, 0x30, 0xe1, 0xd6,
  24546. 0x4f, 0xa2, 0x9e, 0x3b, 0x03, 0x2d, 0x2e, 0xa3,
  24547. 0x84, 0x75, 0x51, 0x3a, 0xc3, 0xf6, 0xee, 0x2e,
  24548. 0x37, 0x0c, 0xe3, 0x28, 0x46, 0xa5, 0x2d, 0xc7,
  24549. 0xf0, 0x64, 0x78, 0x53, 0x66, 0x43, 0x02, 0xa4,
  24550. 0x7a, 0x43, 0x66, 0x4b, 0xa7, 0xcb, 0x97, 0x16
  24551. },
  24552. { /* Finished 2 */
  24553. 0x1d, 0x0d, 0xf8, 0xe1, 0x81, 0xa5, 0xbd, 0xa8,
  24554. 0x6f, 0x9d, 0x01, 0xa4, 0x9a, 0x92, 0xe2, 0xef,
  24555. 0x08, 0xab, 0xef, 0x3e, 0x2d, 0xd4, 0x82, 0xac,
  24556. 0x68, 0x9d, 0xe0, 0x54, 0x17, 0xde, 0x1a, 0xed,
  24557. 0x57, 0xcb, 0xd9, 0x2d, 0xc8, 0xbc, 0x93, 0xe6,
  24558. 0xa3, 0xec, 0xde, 0xee, 0xa1, 0x1c, 0x41, 0x85
  24559. },
  24560. {
  24561. 0x7f, 0x1f, 0xe6, 0x7b, 0xd8, 0xf5, 0x2b, 0x37, 0xbe, 0xb7, 0xd0, 0x37,
  24562. 0xce, 0x46, 0xad, 0x04, 0x2f, 0xc7, 0xdb, 0xc9, 0x9a, 0xb6, 0x00, 0x3f,
  24563. 0xc1, 0x97, 0xe9, 0x5c, 0x5e, 0x14, 0xd1, 0x38, 0x4d, 0x55, 0xe1, 0x07,
  24564. 0xb5, 0x85, 0x6d, 0xfa, 0xa7, 0x66, 0xad, 0xfa, 0xb6, 0xad, 0x29, 0x44
  24565. },
  24566. {
  24567. 0x4e, 0x6b, 0x20, 0x99, 0x55, 0x1b, 0x21, 0x89, 0xb6, 0x70, 0xdb, 0xe8,
  24568. 0xa7, 0x16, 0x55, 0xf2, 0x93, 0x13, 0x90, 0x7d, 0xfa, 0x62, 0x65, 0x53,
  24569. 0xa0, 0x97, 0xe9, 0xb4, 0xc0, 0xf1, 0xc9, 0x1a, 0x67, 0xdd, 0xca, 0x57,
  24570. 0xbc, 0xca, 0x39, 0xe6, 0x39, 0x6b, 0x63, 0x47, 0x25, 0x08, 0x3a, 0xd7
  24571. },
  24572. {
  24573. 0x35, 0x0d, 0xac, 0xd8, 0x10, 0x6a, 0x46, 0x50, 0x66, 0xae, 0x02, 0xc9,
  24574. 0xde, 0x13, 0x48, 0xce, 0x53, 0xd4, 0x92, 0x62, 0xc5, 0x65, 0x10, 0x08,
  24575. 0xc2, 0xc2, 0x82, 0xed, 0x9d, 0xc9, 0x6f, 0xa8, 0xc3, 0xc1, 0x0b, 0x7c,
  24576. 0xe1, 0x97, 0x85, 0xd6, 0x46, 0x29, 0x0e, 0x42, 0x51, 0xc1, 0x35, 0xcf
  24577. },
  24578. {
  24579. 0x3d, 0x5d, 0x84, 0xbd, 0x16, 0x46, 0x34, 0xb3, 0xf6, 0x31, 0x49, 0x3e,
  24580. 0x8d, 0xdc, 0xcb, 0x8c, 0x6a, 0x42, 0xf4, 0x88, 0xfc, 0x19, 0xfa, 0xa2,
  24581. 0x25, 0xc7, 0xa0, 0xa4, 0xca, 0xf0, 0xea, 0x2d, 0xe8, 0xc4, 0x02, 0x14,
  24582. 0x63, 0xfb, 0xd3, 0x7b, 0x51, 0x1c, 0xce, 0xca, 0xa3, 0xc3, 0xe4, 0xa5
  24583. },
  24584. {
  24585. 0x7c, 0x3a, 0x55, 0x92, 0x2e, 0xdd, 0x75, 0xdd, 0x76, 0x54, 0x4a, 0x9f,
  24586. 0xd0, 0xa2, 0x88, 0x83, 0xe9, 0x27, 0xda, 0x30, 0xe9, 0x96, 0x58, 0xc5,
  24587. 0xb7, 0x56, 0xfc, 0x4b, 0xb8, 0x5d, 0xee, 0x46, 0x70, 0x4e, 0x1b, 0x06,
  24588. 0x86, 0xaf, 0x48, 0x5c, 0x17, 0x35, 0xfa, 0x69, 0xc2, 0x4d, 0xfb, 0x09
  24589. },
  24590. {
  24591. 0x00, 0x0e, 0x28, 0x51, 0xc1, 0x7f, 0x41, 0x89, 0x6f, 0x9a, 0xca, 0x15,
  24592. 0xee, 0xed, 0x43, 0xca, 0x6d, 0x65, 0x6f, 0x51, 0x18, 0x6c, 0x08, 0x4b,
  24593. 0x77, 0xca, 0x75, 0xc4, 0xc3, 0xde, 0x29, 0x41, 0x8b, 0xaf, 0xa7, 0x1c,
  24594. 0x28, 0x37, 0xa0, 0xa0, 0x74, 0x8e, 0x09, 0x42, 0x7a, 0x1b, 0x68, 0xdb
  24595. },
  24596. {
  24597. 0x14, 0x8f, 0xab, 0x28, 0x64, 0xea, 0x45, 0x88, 0xdb, 0xc1, 0xc6, 0xa0,
  24598. 0x48, 0xdf, 0x15, 0xd0, 0x28, 0x07, 0x2d, 0x6c, 0xb8, 0x42, 0xbb, 0x60,
  24599. 0x02, 0x08, 0x9e, 0x29, 0x9b, 0x8d, 0xd6, 0x1c, 0xaf, 0xf2, 0x1a, 0xdc,
  24600. 0xf0, 0x78, 0x0b, 0x4d, 0x90, 0xa1, 0x0c, 0xb3, 0x13, 0xde, 0xca, 0x5a
  24601. },
  24602. {
  24603. 0x4d, 0x80, 0x7d, 0x0b, 0xb9, 0x00, 0x6f, 0x65, 0x51, 0x65, 0x23, 0xde,
  24604. 0x72, 0xdc, 0x4f, 0x04, 0xa5, 0xa2, 0x90, 0x45, 0x51, 0x9e, 0xd0, 0x3a,
  24605. 0xe4, 0xd7, 0x78, 0xa3, 0x0f, 0x2d, 0x65, 0x12, 0xad, 0xc8, 0x92, 0x30,
  24606. 0x79, 0x9d, 0x9d, 0x08, 0x7a, 0x9c, 0x9f, 0x83, 0xb1, 0xca, 0x59, 0x56
  24607. }
  24608. },
  24609. { /* 41 */
  24610. WC_HASH_TYPE_SHA384, 33, 0,
  24611. { /* PSK */
  24612. 0xa4, 0x8b, 0x1b, 0x5f, 0xd0, 0xea, 0x75, 0x62,
  24613. 0x06, 0x4d, 0x68, 0x40, 0x85, 0x20, 0x45, 0x95,
  24614. 0x4a, 0x00, 0xca, 0x05, 0xeb, 0xd4, 0x1d, 0x48,
  24615. 0x81, 0x89, 0xe8, 0x86, 0x43, 0xfa, 0x28, 0x17,
  24616. 0x12
  24617. },
  24618. { 0 }, /* DHE */
  24619. { /* Hello 1 */
  24620. 0x03, 0x7c, 0x33, 0x75, 0xdc, 0xc5, 0x46, 0x3a,
  24621. 0x0d, 0x56, 0xc6, 0xfb, 0xab, 0x1e, 0x1d, 0xda,
  24622. 0x59, 0xc2, 0xb2, 0xb1, 0x7c, 0x48, 0x9b, 0x06,
  24623. 0x0a, 0x5a, 0xbb, 0xf8, 0x98, 0x53, 0x78, 0x2d,
  24624. 0xd2, 0xcc, 0x87, 0x68, 0x25, 0xdd, 0x88, 0x22,
  24625. 0xcd, 0xb7, 0x74, 0x55, 0x21, 0xf9, 0x34, 0x98
  24626. },
  24627. { /* Hello 2 */
  24628. 0x03, 0xb4, 0xfb, 0xcc, 0x28, 0x2c, 0xc1, 0x70,
  24629. 0x42, 0x73, 0x57, 0xac, 0xdb, 0x47, 0x71, 0xf6,
  24630. 0x2e, 0x11, 0x8a, 0x5b, 0x47, 0x2f, 0x02, 0x54,
  24631. 0x95, 0x34, 0xed, 0x5f, 0x19, 0xc1, 0x75, 0xe0,
  24632. 0x76, 0xad, 0xb0, 0x90, 0x57, 0xcd, 0xfd, 0xd7,
  24633. 0x58, 0x1f, 0x0d, 0x6b, 0x9e, 0x51, 0x3c, 0x08
  24634. },
  24635. { /* Finished 1 */
  24636. 0x2b, 0x50, 0xd9, 0xa7, 0x43, 0x24, 0xda, 0x2c,
  24637. 0x7a, 0xaa, 0x0e, 0x37, 0xd7, 0x6b, 0x2c, 0xab,
  24638. 0x8e, 0xb2, 0xfe, 0x31, 0x1b, 0xa8, 0x12, 0x59,
  24639. 0x5b, 0x7b, 0xdc, 0x3e, 0xa7, 0x86, 0xa5, 0x48,
  24640. 0xe4, 0x46, 0x2b, 0x4c, 0xc1, 0x66, 0x4b, 0xf3,
  24641. 0x2a, 0x99, 0x93, 0x08, 0xbc, 0x3d, 0x08, 0x76
  24642. },
  24643. { /* Finished 2 */
  24644. 0x7c, 0x34, 0xc8, 0x56, 0x17, 0xf1, 0x62, 0x1c,
  24645. 0x9f, 0x0b, 0xeb, 0xfd, 0x69, 0x72, 0x51, 0xc5,
  24646. 0xfa, 0x74, 0x87, 0xc9, 0xbd, 0x50, 0xe9, 0x48,
  24647. 0xa7, 0x3c, 0x94, 0x3e, 0x06, 0x7d, 0xe8, 0x8e,
  24648. 0xc1, 0xd1, 0x08, 0x1f, 0x5d, 0x48, 0x8a, 0x25,
  24649. 0xfc, 0xea, 0xe7, 0xd9, 0xd4, 0xd0, 0xf9, 0xad
  24650. },
  24651. {
  24652. 0x4b, 0x0b, 0xed, 0xb9, 0xc8, 0xb8, 0xa8, 0x1e, 0xb0, 0x81, 0x76, 0xd5,
  24653. 0x33, 0x22, 0x71, 0x33, 0x3a, 0x85, 0x19, 0x67, 0x7e, 0x91, 0x37, 0xf2,
  24654. 0xa6, 0x11, 0x22, 0xdf, 0x41, 0x04, 0x3d, 0xa9, 0x13, 0xb9, 0xb2, 0xb1,
  24655. 0xbb, 0xd8, 0xef, 0x23, 0x7c, 0xc2, 0xab, 0x70, 0x1b, 0x51, 0x9f, 0xc9
  24656. },
  24657. {
  24658. 0xeb, 0x96, 0x10, 0x8c, 0x7d, 0x92, 0xea, 0x80, 0x86, 0xb2, 0xf8, 0x27,
  24659. 0xf2, 0x9a, 0x09, 0xc1, 0x7c, 0x09, 0x43, 0xbc, 0xfe, 0xc8, 0x75, 0xe0,
  24660. 0x97, 0xe7, 0x6d, 0xd5, 0xb2, 0x3c, 0xed, 0x12, 0xb7, 0x74, 0x0e, 0xe3,
  24661. 0xb6, 0xe0, 0xba, 0xe1, 0x8d, 0x89, 0xcf, 0x4f, 0x57, 0xf6, 0x6d, 0x90
  24662. },
  24663. {
  24664. 0x22, 0xb0, 0x39, 0x34, 0xb6, 0x6c, 0x2d, 0x7a, 0x97, 0x1c, 0x5d, 0xcc,
  24665. 0x78, 0x84, 0x71, 0xbb, 0xc6, 0x7b, 0xb6, 0xbc, 0xcc, 0x0b, 0xf8, 0xac,
  24666. 0x8e, 0xd7, 0x20, 0xbd, 0xbe, 0x32, 0xf0, 0xd6, 0xe9, 0x69, 0x13, 0xf2,
  24667. 0x9a, 0xce, 0xfe, 0x86, 0xd3, 0xee, 0xba, 0x69, 0x51, 0xb6, 0x77, 0x56
  24668. },
  24669. {
  24670. 0x16, 0xfd, 0xda, 0xf3, 0x5e, 0xb9, 0xa6, 0x17, 0x24, 0xb2, 0x16, 0x9f,
  24671. 0xb6, 0x59, 0x13, 0x0f, 0x25, 0x5a, 0xf1, 0x5b, 0x5f, 0xe4, 0x54, 0x2a,
  24672. 0xa7, 0xbf, 0x29, 0xaf, 0x5a, 0x77, 0xf4, 0x4f, 0x25, 0xba, 0x94, 0xad,
  24673. 0x6b, 0x91, 0x3b, 0xe7, 0xd5, 0x73, 0x0d, 0xff, 0xaa, 0xe3, 0x72, 0x2c
  24674. },
  24675. {
  24676. 0x22, 0xb4, 0x94, 0xc0, 0x53, 0xd7, 0x82, 0x06, 0x38, 0x9d, 0x4a, 0xa0,
  24677. 0x3f, 0xf1, 0x5f, 0x6e, 0x23, 0x8d, 0x09, 0x62, 0xbf, 0x6f, 0x7c, 0x84,
  24678. 0xc6, 0x3e, 0x15, 0xad, 0x18, 0x37, 0x76, 0x29, 0xc7, 0xd6, 0x68, 0x0c,
  24679. 0x1e, 0xc6, 0x93, 0x31, 0xef, 0x85, 0x69, 0x30, 0x68, 0xf0, 0x1e, 0x37
  24680. },
  24681. {
  24682. 0x6d, 0x4d, 0x20, 0xaf, 0x47, 0xe8, 0x1b, 0xfa, 0xd0, 0xb6, 0xc8, 0x97,
  24683. 0xd1, 0x03, 0xfc, 0x9d, 0x59, 0xa0, 0x68, 0x9d, 0xe9, 0x17, 0x8b, 0xce,
  24684. 0x48, 0x2c, 0x77, 0x8a, 0x22, 0x4b, 0x5c, 0x54, 0x22, 0xa1, 0x15, 0x12,
  24685. 0xe1, 0x07, 0x8e, 0x15, 0xd8, 0x7b, 0x16, 0x65, 0x99, 0x6b, 0xcb, 0x71
  24686. },
  24687. {
  24688. 0x79, 0x64, 0x79, 0xdd, 0x75, 0x5c, 0x6f, 0x98, 0xac, 0x03, 0xe0, 0xcd,
  24689. 0x92, 0xba, 0x0e, 0x2d, 0xb4, 0xd1, 0x8b, 0x97, 0xd0, 0x85, 0xbb, 0x2e,
  24690. 0x4f, 0x26, 0x93, 0xf5, 0x1d, 0xf3, 0xd2, 0x43, 0x4f, 0xd2, 0x47, 0xaa,
  24691. 0x91, 0x1e, 0xf3, 0x67, 0x10, 0x18, 0x2c, 0xb9, 0x01, 0xba, 0x10, 0x9f
  24692. },
  24693. {
  24694. 0x79, 0xb6, 0x9c, 0xbe, 0xf1, 0x6a, 0xb0, 0x92, 0xa0, 0x29, 0x52, 0x61,
  24695. 0xf1, 0xcd, 0x3a, 0x67, 0xe1, 0x6b, 0xb8, 0x9d, 0x0d, 0x95, 0xb6, 0x03,
  24696. 0x80, 0x1f, 0xd5, 0x75, 0xb6, 0x1d, 0x79, 0x02, 0x93, 0x43, 0x77, 0xa7,
  24697. 0x9d, 0x2f, 0xc3, 0x84, 0xc6, 0x83, 0x76, 0x16, 0x06, 0x98, 0x7b, 0x79
  24698. }
  24699. },
  24700. #endif /* WOLFSSL_SHA384 */
  24701. };
  24702. static const char protocolLabel[] = "tls13 ";
  24703. static const char ceTrafficLabel[] = "c e traffic";
  24704. static const char eExpMasterLabel[] = "e exp master";
  24705. static const char cHsTrafficLabel[] = "c hs traffic";
  24706. static const char sHsTrafficLabel[] = "s hs traffic";
  24707. static const char cAppTrafficLabel[] = "c ap traffic";
  24708. static const char sAppTrafficLabel[] = "s ap traffic";
  24709. static const char expMasterLabel[] = "exp master";
  24710. static const char resMasterLabel[] = "res master";
  24711. static const char derivedLabel[] = "derived";
  24712. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void)
  24713. {
  24714. wc_test_ret_t ret = 0;
  24715. word32 i;
  24716. word32 tc = sizeof(tls13KdfTestVectors)/sizeof(Tls13KdfTestVector);
  24717. const Tls13KdfTestVector* tv = NULL;
  24718. WOLFSSL_ENTER("tls13_kdf_test");
  24719. for (i = 0, tv = tls13KdfTestVectors; i < tc; i++, tv++) {
  24720. byte output[WC_MAX_DIGEST_SIZE];
  24721. byte secret[WC_MAX_DIGEST_SIZE];
  24722. byte salt[WC_MAX_DIGEST_SIZE];
  24723. byte zeroes[WC_MAX_DIGEST_SIZE];
  24724. byte hashZero[WC_MAX_DIGEST_SIZE];
  24725. int hashAlgSz;
  24726. XMEMSET(zeroes, 0, sizeof zeroes);
  24727. hashAlgSz = wc_HashGetDigestSize(tv->hashAlg);
  24728. if (hashAlgSz == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) break;
  24729. ret = wc_Hash(tv->hashAlg, NULL, 0, hashZero, (word32)hashAlgSz);
  24730. if (ret != 0) break;
  24731. ret = wc_Tls13_HKDF_Extract(secret, NULL, 0,
  24732. (tv->pskSz == 0) ? zeroes : (byte*)tv->psk,
  24733. tv->pskSz, (int)tv->hashAlg);
  24734. if (ret != 0) break;
  24735. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24736. secret, (word32)hashAlgSz,
  24737. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24738. (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel),
  24739. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24740. if (ret != 0) break;
  24741. ret = XMEMCMP(tv->clientEarlyTrafficSecret, output,
  24742. (unsigned long)hashAlgSz);
  24743. if (ret != 0) break;
  24744. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24745. secret, (word32)hashAlgSz,
  24746. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24747. (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel),
  24748. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24749. if (ret != 0) break;
  24750. ret = XMEMCMP(tv->earlyExporterMasterSecret, output,
  24751. (unsigned long)hashAlgSz);
  24752. if (ret != 0) break;
  24753. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24754. secret, (word32)hashAlgSz,
  24755. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24756. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24757. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24758. if (ret != 0) break;
  24759. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24760. (tv->dheSz == 0) ? zeroes : (byte*)tv->dhe,
  24761. tv->dheSz, (int)tv->hashAlg);
  24762. if (ret != 0) break;
  24763. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24764. secret, (word32)hashAlgSz,
  24765. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24766. (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel),
  24767. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24768. if (ret != 0) break;
  24769. ret = XMEMCMP(tv->clientHandshakeTrafficSecret,
  24770. output, (unsigned long)hashAlgSz);
  24771. if (ret != 0) break;
  24772. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24773. secret, (word32)hashAlgSz,
  24774. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24775. (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel),
  24776. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24777. if (ret != 0) break;
  24778. ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output,
  24779. (unsigned long)hashAlgSz);
  24780. if (ret != 0) break;
  24781. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24782. secret, (word32)hashAlgSz,
  24783. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24784. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24785. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24786. if (ret != 0) break;
  24787. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24788. zeroes, (word32)(word32)hashAlgSz, (int)tv->hashAlg);
  24789. if (ret != 0) break;
  24790. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24791. secret, (word32)hashAlgSz,
  24792. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24793. (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel),
  24794. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24795. if (ret != 0) break;
  24796. ret = XMEMCMP(tv->clientApplicationTrafficSecret, output,
  24797. (unsigned long)hashAlgSz);
  24798. if (ret != 0) break;
  24799. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24800. secret, (word32)hashAlgSz,
  24801. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24802. (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel),
  24803. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24804. if (ret != 0) break;
  24805. ret = XMEMCMP(tv->serverApplicationTrafficSecret, output,
  24806. (unsigned long)hashAlgSz);
  24807. if (ret != 0) break;
  24808. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24809. secret, (word32)hashAlgSz,
  24810. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24811. (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel),
  24812. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24813. if (ret != 0) break;
  24814. ret = XMEMCMP(tv->exporterMasterSecret, output, (unsigned long)hashAlgSz);
  24815. if (ret != 0) break;
  24816. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24817. secret, (word32)hashAlgSz,
  24818. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24819. (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel),
  24820. tv->hashFinished2, (word32)hashAlgSz, (int)tv->hashAlg);
  24821. if (ret != 0) break;
  24822. ret = XMEMCMP(tv->resumptionMasterSecret, output,
  24823. (unsigned long)hashAlgSz);
  24824. if (ret != 0) break;
  24825. }
  24826. return ret;
  24827. }
  24828. #endif /* WOLFSSL_TLS13 */
  24829. static const int fiducial2 = WC_TEST_RET_LN; /* source code reference point --
  24830. * see print_fiducials() below.
  24831. */
  24832. #if defined(HAVE_ECC) && defined(HAVE_X963_KDF)
  24833. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void)
  24834. {
  24835. wc_test_ret_t ret;
  24836. byte kek[128];
  24837. #ifndef NO_SHA
  24838. /* SHA-1, COUNT = 0
  24839. * shared secret length: 192
  24840. * SharedInfo length: 0
  24841. * key data length: 128
  24842. */
  24843. WOLFSSL_SMALL_STACK_STATIC const byte Z[] = {
  24844. 0x1c, 0x7d, 0x7b, 0x5f, 0x05, 0x97, 0xb0, 0x3d,
  24845. 0x06, 0xa0, 0x18, 0x46, 0x6e, 0xd1, 0xa9, 0x3e,
  24846. 0x30, 0xed, 0x4b, 0x04, 0xdc, 0x64, 0xcc, 0xdd
  24847. };
  24848. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  24849. 0xbf, 0x71, 0xdf, 0xfd, 0x8f, 0x4d, 0x99, 0x22,
  24850. 0x39, 0x36, 0xbe, 0xb4, 0x6f, 0xee, 0x8c, 0xcc
  24851. };
  24852. #endif
  24853. #ifndef NO_SHA256
  24854. /* SHA-256, COUNT = 3
  24855. * shared secret length: 192
  24856. * SharedInfo length: 0
  24857. * key data length: 128
  24858. */
  24859. WOLFSSL_SMALL_STACK_STATIC const byte Z2[] = {
  24860. 0xd3, 0x8b, 0xdb, 0xe5, 0xc4, 0xfc, 0x16, 0x4c,
  24861. 0xdd, 0x96, 0x7f, 0x63, 0xc0, 0x4f, 0xe0, 0x7b,
  24862. 0x60, 0xcd, 0xe8, 0x81, 0xc2, 0x46, 0x43, 0x8c
  24863. };
  24864. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  24865. 0x5e, 0x67, 0x4d, 0xb9, 0x71, 0xba, 0xc2, 0x0a,
  24866. 0x80, 0xba, 0xd0, 0xd4, 0x51, 0x4d, 0xc4, 0x84
  24867. };
  24868. #endif
  24869. #ifdef WOLFSSL_SHA512
  24870. /* SHA-512, COUNT = 0
  24871. * shared secret length: 192
  24872. * SharedInfo length: 0
  24873. * key data length: 128
  24874. */
  24875. WOLFSSL_SMALL_STACK_STATIC const byte Z3[] = {
  24876. 0x87, 0xfc, 0x0d, 0x8c, 0x44, 0x77, 0x48, 0x5b,
  24877. 0xb5, 0x74, 0xf5, 0xfc, 0xea, 0x26, 0x4b, 0x30,
  24878. 0x88, 0x5d, 0xc8, 0xd9, 0x0a, 0xd8, 0x27, 0x82
  24879. };
  24880. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  24881. 0x94, 0x76, 0x65, 0xfb, 0xb9, 0x15, 0x21, 0x53,
  24882. 0xef, 0x46, 0x02, 0x38, 0x50, 0x6a, 0x02, 0x45
  24883. };
  24884. /* SHA-512, COUNT = 0
  24885. * shared secret length: 521
  24886. * SharedInfo length: 128
  24887. * key data length: 1024
  24888. */
  24889. WOLFSSL_SMALL_STACK_STATIC const byte Z4[] = {
  24890. 0x00, 0xaa, 0x5b, 0xb7, 0x9b, 0x33, 0xe3, 0x89,
  24891. 0xfa, 0x58, 0xce, 0xad, 0xc0, 0x47, 0x19, 0x7f,
  24892. 0x14, 0xe7, 0x37, 0x12, 0xf4, 0x52, 0xca, 0xa9,
  24893. 0xfc, 0x4c, 0x9a, 0xdb, 0x36, 0x93, 0x48, 0xb8,
  24894. 0x15, 0x07, 0x39, 0x2f, 0x1a, 0x86, 0xdd, 0xfd,
  24895. 0xb7, 0xc4, 0xff, 0x82, 0x31, 0xc4, 0xbd, 0x0f,
  24896. 0x44, 0xe4, 0x4a, 0x1b, 0x55, 0xb1, 0x40, 0x47,
  24897. 0x47, 0xa9, 0xe2, 0xe7, 0x53, 0xf5, 0x5e, 0xf0,
  24898. 0x5a, 0x2d
  24899. };
  24900. WOLFSSL_SMALL_STACK_STATIC const byte info4[] = {
  24901. 0xe3, 0xb5, 0xb4, 0xc1, 0xb0, 0xd5, 0xcf, 0x1d,
  24902. 0x2b, 0x3a, 0x2f, 0x99, 0x37, 0x89, 0x5d, 0x31
  24903. };
  24904. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  24905. 0x44, 0x63, 0xf8, 0x69, 0xf3, 0xcc, 0x18, 0x76,
  24906. 0x9b, 0x52, 0x26, 0x4b, 0x01, 0x12, 0xb5, 0x85,
  24907. 0x8f, 0x7a, 0xd3, 0x2a, 0x5a, 0x2d, 0x96, 0xd8,
  24908. 0xcf, 0xfa, 0xbf, 0x7f, 0xa7, 0x33, 0x63, 0x3d,
  24909. 0x6e, 0x4d, 0xd2, 0xa5, 0x99, 0xac, 0xce, 0xb3,
  24910. 0xea, 0x54, 0xa6, 0x21, 0x7c, 0xe0, 0xb5, 0x0e,
  24911. 0xef, 0x4f, 0x6b, 0x40, 0xa5, 0xc3, 0x02, 0x50,
  24912. 0xa5, 0xa8, 0xee, 0xee, 0x20, 0x80, 0x02, 0x26,
  24913. 0x70, 0x89, 0xdb, 0xf3, 0x51, 0xf3, 0xf5, 0x02,
  24914. 0x2a, 0xa9, 0x63, 0x8b, 0xf1, 0xee, 0x41, 0x9d,
  24915. 0xea, 0x9c, 0x4f, 0xf7, 0x45, 0xa2, 0x5a, 0xc2,
  24916. 0x7b, 0xda, 0x33, 0xca, 0x08, 0xbd, 0x56, 0xdd,
  24917. 0x1a, 0x59, 0xb4, 0x10, 0x6c, 0xf2, 0xdb, 0xbc,
  24918. 0x0a, 0xb2, 0xaa, 0x8e, 0x2e, 0xfa, 0x7b, 0x17,
  24919. 0x90, 0x2d, 0x34, 0x27, 0x69, 0x51, 0xce, 0xcc,
  24920. 0xab, 0x87, 0xf9, 0x66, 0x1c, 0x3e, 0x88, 0x16
  24921. };
  24922. #endif
  24923. WOLFSSL_ENTER("x963kdf_test");
  24924. #ifndef NO_SHA
  24925. ret = wc_X963_KDF(WC_HASH_TYPE_SHA, Z, sizeof(Z), NULL, 0,
  24926. kek, sizeof(verify));
  24927. if (ret != 0)
  24928. return WC_TEST_RET_ENC_EC(ret);
  24929. if (XMEMCMP(verify, kek, sizeof(verify)) != 0)
  24930. return WC_TEST_RET_ENC_NC;
  24931. #endif
  24932. #ifndef NO_SHA256
  24933. ret = wc_X963_KDF(WC_HASH_TYPE_SHA256, Z2, sizeof(Z2), NULL, 0,
  24934. kek, sizeof(verify2));
  24935. if (ret != 0)
  24936. return WC_TEST_RET_ENC_EC(ret);
  24937. if (XMEMCMP(verify2, kek, sizeof(verify2)) != 0)
  24938. return WC_TEST_RET_ENC_NC;
  24939. #endif
  24940. #ifdef WOLFSSL_SHA512
  24941. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z3, sizeof(Z3), NULL, 0,
  24942. kek, sizeof(verify3));
  24943. if (ret != 0)
  24944. return WC_TEST_RET_ENC_EC(ret);
  24945. if (XMEMCMP(verify3, kek, sizeof(verify3)) != 0)
  24946. return WC_TEST_RET_ENC_NC;
  24947. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z4, sizeof(Z4), info4,
  24948. sizeof(info4), kek, sizeof(verify4));
  24949. if (ret != 0)
  24950. return WC_TEST_RET_ENC_EC(ret);
  24951. if (XMEMCMP(verify4, kek, sizeof(verify4)) != 0)
  24952. return WC_TEST_RET_ENC_NC;
  24953. #endif
  24954. return 0;
  24955. }
  24956. #endif /* HAVE_X963_KDF */
  24957. #if defined(HAVE_HPKE) && \
  24958. (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) && \
  24959. defined(HAVE_AESGCM)
  24960. static wc_test_ret_t hpke_test_single(Hpke* hpke)
  24961. {
  24962. wc_test_ret_t ret = 0;
  24963. int rngRet = 0;
  24964. WC_RNG rng[1];
  24965. const char* start_text = "this is a test";
  24966. const char* info_text = "info";
  24967. const char* aad_text = "aad";
  24968. byte ciphertext[MAX_HPKE_LABEL_SZ];
  24969. byte plaintext[MAX_HPKE_LABEL_SZ];
  24970. void* receiverKey = NULL;
  24971. void* ephemeralKey = NULL;
  24972. #ifdef WOLFSSL_SMALL_STACK
  24973. byte *pubKey = NULL; /* public key */
  24974. word16 pubKeySz = (word16)HPKE_Npk_MAX;
  24975. #else
  24976. byte pubKey[HPKE_Npk_MAX]; /* public key */
  24977. word16 pubKeySz = (word16)sizeof(pubKey);
  24978. #endif
  24979. rngRet = ret = wc_InitRng(rng);
  24980. if (ret != 0)
  24981. return WC_TEST_RET_ENC_EC(ret);
  24982. #ifdef WOLFSSL_SMALL_STACK
  24983. if (ret == 0) {
  24984. pubKey = (byte *)XMALLOC(pubKeySz, HEAP_HINT,
  24985. DYNAMIC_TYPE_TMP_BUFFER);
  24986. if (pubKey == NULL)
  24987. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  24988. }
  24989. #endif
  24990. /* generate the keys */
  24991. if (ret == 0) {
  24992. ret = wc_HpkeGenerateKeyPair(hpke, &ephemeralKey, rng);
  24993. if (ret != 0)
  24994. ret = WC_TEST_RET_ENC_EC(ret);
  24995. }
  24996. if (ret == 0) {
  24997. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, rng);
  24998. if (ret != 0)
  24999. ret = WC_TEST_RET_ENC_EC(ret);
  25000. }
  25001. /* seal */
  25002. if (ret == 0) {
  25003. ret = wc_HpkeSealBase(hpke, ephemeralKey, receiverKey,
  25004. (byte*)info_text, (word32)XSTRLEN(info_text),
  25005. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25006. (byte*)start_text, (word32)XSTRLEN(start_text),
  25007. ciphertext);
  25008. if (ret != 0)
  25009. ret = WC_TEST_RET_ENC_EC(ret);
  25010. }
  25011. /* export ephemeral key */
  25012. if (ret == 0) {
  25013. ret = wc_HpkeSerializePublicKey(hpke, ephemeralKey, pubKey, &pubKeySz);
  25014. if (ret != 0)
  25015. ret = WC_TEST_RET_ENC_EC(ret);
  25016. }
  25017. /* open with exported ephemeral key */
  25018. if (ret == 0) {
  25019. ret = wc_HpkeOpenBase(hpke, receiverKey, pubKey, pubKeySz,
  25020. (byte*)info_text, (word32)XSTRLEN(info_text),
  25021. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25022. ciphertext, (word32)XSTRLEN(start_text),
  25023. plaintext);
  25024. if (ret != 0)
  25025. ret = WC_TEST_RET_ENC_EC(ret);
  25026. }
  25027. if (ret == 0) {
  25028. ret = XMEMCMP(plaintext, start_text, XSTRLEN(start_text));
  25029. if (ret != 0)
  25030. ret = WC_TEST_RET_ENC_NC;
  25031. }
  25032. /* Negative test case with NULL argument */
  25033. if (ret == 0) {
  25034. ret = wc_HpkeGenerateKeyPair(NULL, &receiverKey, rng);
  25035. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25036. ret = WC_TEST_RET_ENC_EC(ret);
  25037. else
  25038. ret = 0;
  25039. }
  25040. if (ret == 0) {
  25041. ret = wc_HpkeGenerateKeyPair(hpke, NULL, rng);
  25042. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25043. ret = WC_TEST_RET_ENC_EC(ret);
  25044. else
  25045. ret = 0;
  25046. }
  25047. if (ret == 0) {
  25048. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, NULL);
  25049. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25050. ret = WC_TEST_RET_ENC_EC(ret);
  25051. else
  25052. ret = 0;
  25053. }
  25054. if (ephemeralKey != NULL)
  25055. wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap);
  25056. if (receiverKey != NULL)
  25057. wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap);
  25058. #ifdef WOLFSSL_SMALL_STACK
  25059. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25060. #endif
  25061. if (rngRet == 0)
  25062. wc_FreeRng(rng);
  25063. return ret;
  25064. }
  25065. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void)
  25066. {
  25067. wc_test_ret_t ret = 0;
  25068. Hpke hpke[1];
  25069. WOLFSSL_ENTER("hpke_test");
  25070. #if defined(HAVE_ECC)
  25071. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
  25072. /* p256 */
  25073. ret = wc_HpkeInit(hpke, DHKEM_P256_HKDF_SHA256, HKDF_SHA256,
  25074. HPKE_AES_128_GCM, NULL);
  25075. if (ret != 0)
  25076. return WC_TEST_RET_ENC_EC(ret);
  25077. ret = hpke_test_single(hpke);
  25078. if (ret != 0)
  25079. return ret;
  25080. #endif
  25081. #if defined(WOLFSSL_SHA384) && \
  25082. (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  25083. /* p384 */
  25084. ret = wc_HpkeInit(hpke, DHKEM_P384_HKDF_SHA384, HKDF_SHA384,
  25085. HPKE_AES_128_GCM, NULL);
  25086. if (ret != 0)
  25087. return WC_TEST_RET_ENC_EC(ret);
  25088. ret = hpke_test_single(hpke);
  25089. if (ret != 0)
  25090. return ret;
  25091. #endif
  25092. #if (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) && \
  25093. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25094. /* p521 */
  25095. ret = wc_HpkeInit(hpke, DHKEM_P521_HKDF_SHA512, HKDF_SHA512,
  25096. HPKE_AES_128_GCM, NULL);
  25097. if (ret != 0)
  25098. return WC_TEST_RET_ENC_EC(ret);
  25099. ret = hpke_test_single(hpke);
  25100. if (ret != 0)
  25101. return ret;
  25102. #endif
  25103. #endif
  25104. #if defined(HAVE_CURVE25519)
  25105. /* test with curve25519 and aes256 */
  25106. ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256,
  25107. HPKE_AES_256_GCM, NULL);
  25108. if (ret != 0)
  25109. return WC_TEST_RET_ENC_EC(ret);
  25110. ret = hpke_test_single(hpke);
  25111. if (ret != 0)
  25112. return ret;
  25113. #endif
  25114. #if defined(HAVE_CURVE448) && \
  25115. (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512))
  25116. /* test with curve448 and aes256 */
  25117. ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512,
  25118. HPKE_AES_256_GCM, NULL);
  25119. /* HPKE does not support X448 yet, so expect failure */
  25120. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25121. return WC_TEST_RET_ENC_EC(ret);
  25122. ret = hpke_test_single(hpke);
  25123. /* HPKE does not support X448 yet, so expect failure */
  25124. if (WC_TEST_RET_DEC_EC(ret) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25125. return ret;
  25126. ret = 0; /* reset error code */
  25127. #endif
  25128. /* TODO: HPKE chacha20 is not implemented */
  25129. return ret;
  25130. }
  25131. #endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */
  25132. #if defined(WC_SRTP_KDF)
  25133. typedef struct Srtp_Kdf_Tv {
  25134. const unsigned char* key;
  25135. word32 keySz;
  25136. const unsigned char* salt;
  25137. word32 saltSz;
  25138. int kdfIdx;
  25139. const unsigned char* index;
  25140. const unsigned char* ke;
  25141. const unsigned char* ka;
  25142. const unsigned char* ks;
  25143. const unsigned char* index_c;
  25144. const unsigned char* ke_c;
  25145. const unsigned char* ka_c;
  25146. const unsigned char* ks_c;
  25147. word32 keSz;
  25148. word32 kaSz;
  25149. word32 ksSz;
  25150. } Srtp_Kdf_Tv;
  25151. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
  25152. {
  25153. wc_test_ret_t ret = 0;
  25154. /* 128-bit key, kdrIdx = -1 */
  25155. WOLFSSL_SMALL_STACK_STATIC const byte key_0[] = {
  25156. 0xc4, 0x80, 0x9f, 0x6d, 0x36, 0x98, 0x88, 0x72,
  25157. 0x8e, 0x26, 0xad, 0xb5, 0x32, 0x12, 0x98, 0x90
  25158. };
  25159. WOLFSSL_SMALL_STACK_STATIC const byte salt_0[] = {
  25160. 0x0e, 0x23, 0x00, 0x6c, 0x6c, 0x04, 0x4f, 0x56,
  25161. 0x62, 0x40, 0x0e, 0x9d, 0x1b, 0xd6
  25162. };
  25163. WOLFSSL_SMALL_STACK_STATIC const byte index_0[] = {
  25164. 0x48, 0x71, 0x65, 0x64, 0x9c, 0xca
  25165. };
  25166. WOLFSSL_SMALL_STACK_STATIC const byte ke_0[] = {
  25167. 0xdc, 0x38, 0x21, 0x92, 0xab, 0x65, 0x10, 0x8a,
  25168. 0x86, 0xb2, 0x59, 0xb6, 0x1b, 0x3a, 0xf4, 0x6f
  25169. };
  25170. WOLFSSL_SMALL_STACK_STATIC const byte ka_0[] = {
  25171. 0xb8, 0x39, 0x37, 0xfb, 0x32, 0x17, 0x92, 0xee,
  25172. 0x87, 0xb7, 0x88, 0x19, 0x3b, 0xe5, 0xa4, 0xe3,
  25173. 0xbd, 0x32, 0x6e, 0xe4
  25174. };
  25175. WOLFSSL_SMALL_STACK_STATIC const byte ks_0[] = {
  25176. 0xf1, 0xc0, 0x35, 0xc0, 0x0b, 0x5a, 0x54, 0xa6,
  25177. 0x16, 0x92, 0xc0, 0x16, 0x27, 0x6c
  25178. };
  25179. WOLFSSL_SMALL_STACK_STATIC const byte index_c_0[] = {
  25180. 0x56, 0xf3, 0xf1, 0x97
  25181. };
  25182. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_0[] = {
  25183. 0xab, 0x5b, 0xe0, 0xb4, 0x56, 0x23, 0x5d, 0xcf,
  25184. 0x77, 0xd5, 0x08, 0x69, 0x29, 0xba, 0xfb, 0x38
  25185. };
  25186. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_0[] = {
  25187. 0xc5, 0x2f, 0xde, 0x0b, 0x80, 0xb0, 0xf0, 0xba,
  25188. 0xd8, 0xd1, 0x56, 0x45, 0xcb, 0x86, 0xe7, 0xc7,
  25189. 0xc3, 0xd8, 0x77, 0x0e
  25190. };
  25191. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_0[] = {
  25192. 0xde, 0xb5, 0xf8, 0x5f, 0x81, 0x33, 0x6a, 0x96,
  25193. 0x5e, 0xd3, 0x2b, 0xb7, 0xed, 0xe8
  25194. };
  25195. /* 192-bit key, kdrIdx = 0 */
  25196. WOLFSSL_SMALL_STACK_STATIC const byte key_1[] = {
  25197. 0xbb, 0x04, 0x5b, 0x1f, 0x53, 0xc6, 0x93, 0x2c,
  25198. 0x2b, 0xa6, 0x88, 0xf5, 0xe3, 0xf2, 0x24, 0x70,
  25199. 0xe1, 0x7d, 0x7d, 0xec, 0x8a, 0x93, 0x4d, 0xf2
  25200. };
  25201. WOLFSSL_SMALL_STACK_STATIC const byte salt_1[] = {
  25202. 0xe7, 0x22, 0xab, 0x92, 0xfc, 0x7c, 0x89, 0xb6,
  25203. 0x53, 0x8a, 0xf9, 0x3c, 0xb9, 0x52
  25204. };
  25205. WOLFSSL_SMALL_STACK_STATIC const byte index_1[] = {
  25206. 0xd7, 0x87, 0x8f, 0x33, 0xb1, 0x76
  25207. };
  25208. WOLFSSL_SMALL_STACK_STATIC const byte ke_1[] = {
  25209. 0x2c, 0xc8, 0x3e, 0x54, 0xb2, 0x33, 0x89, 0xb3,
  25210. 0x71, 0x65, 0x0f, 0x51, 0x61, 0x65, 0xe4, 0x93,
  25211. 0x07, 0x4e, 0xb3, 0x47, 0xba, 0x2d, 0x60, 0x60
  25212. };
  25213. WOLFSSL_SMALL_STACK_STATIC const byte ka_1[] = {
  25214. 0x2e, 0x80, 0xe4, 0x82, 0x55, 0xa2, 0xbe, 0x6d,
  25215. 0xe0, 0x46, 0xcc, 0xc1, 0x75, 0x78, 0x6e, 0x78,
  25216. 0xd1, 0xd1, 0x47, 0x08
  25217. };
  25218. WOLFSSL_SMALL_STACK_STATIC const byte ks_1[] = {
  25219. 0xe0, 0xc1, 0xe6, 0xaf, 0x1e, 0x8d, 0x8c, 0xfe,
  25220. 0xe5, 0x60, 0x70, 0xb5, 0xe6, 0xea
  25221. };
  25222. WOLFSSL_SMALL_STACK_STATIC const byte index_c_1[] = {
  25223. 0x40, 0xbf, 0xd4, 0xa9
  25224. };
  25225. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_1[] = {
  25226. 0x94, 0x0f, 0x55, 0xce, 0x58, 0xd8, 0x16, 0x65,
  25227. 0xf0, 0xfa, 0x46, 0x40, 0x0c, 0xda, 0xb1, 0x11,
  25228. 0x9e, 0x69, 0xa0, 0x93, 0x4e, 0xd7, 0xf2, 0x84
  25229. };
  25230. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_1[] = {
  25231. 0xf5, 0x41, 0x6f, 0xc2, 0x65, 0xc5, 0xb3, 0xef,
  25232. 0xbb, 0x22, 0xc8, 0xfc, 0x6b, 0x00, 0x14, 0xb2,
  25233. 0xf3, 0x3b, 0x8e, 0x29
  25234. };
  25235. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_1[] = {
  25236. 0x35, 0xb7, 0x42, 0x43, 0xf0, 0x01, 0x01, 0xb4,
  25237. 0x68, 0xa1, 0x28, 0x80, 0x37, 0xf0
  25238. };
  25239. /* 256-bit key, kdrIdx = 1 */
  25240. WOLFSSL_SMALL_STACK_STATIC const byte key_2[] = {
  25241. 0x10, 0x38, 0x0a, 0xcd, 0xd6, 0x47, 0xab, 0xee,
  25242. 0xc0, 0xd4, 0x44, 0xf4, 0x7e, 0x51, 0x36, 0x02,
  25243. 0x79, 0xa8, 0x94, 0x80, 0x35, 0x40, 0xed, 0x50,
  25244. 0xf4, 0x45, 0x30, 0x3d, 0xb5, 0xf0, 0x2b, 0xbb
  25245. };
  25246. WOLFSSL_SMALL_STACK_STATIC const byte salt_2[] = {
  25247. 0xc7, 0x31, 0xf2, 0xc8, 0x40, 0x43, 0xb8, 0x74,
  25248. 0x8a, 0x61, 0x84, 0x7a, 0x25, 0x8a
  25249. };
  25250. WOLFSSL_SMALL_STACK_STATIC const byte index_2[] = {
  25251. 0x82, 0xf1, 0x84, 0x8c, 0xac, 0x42
  25252. };
  25253. WOLFSSL_SMALL_STACK_STATIC const byte ke_2[] = {
  25254. 0xb2, 0x26, 0x60, 0xaf, 0x08, 0x23, 0x14, 0x98,
  25255. 0x91, 0xde, 0x5d, 0x87, 0x95, 0x61, 0xca, 0x8f,
  25256. 0x0e, 0xce, 0xfb, 0x68, 0x4d, 0xd6, 0x28, 0xcb,
  25257. 0x28, 0xe2, 0x27, 0x20, 0x2d, 0xff, 0x64, 0xbb
  25258. };
  25259. WOLFSSL_SMALL_STACK_STATIC const byte ka_2[] = {
  25260. 0x12, 0x6f, 0x52, 0xe8, 0x07, 0x7f, 0x07, 0x84,
  25261. 0xa0, 0x61, 0x96, 0xf8, 0xee, 0x4d, 0x05, 0x57,
  25262. 0x65, 0xc7, 0x50, 0xc1
  25263. };
  25264. WOLFSSL_SMALL_STACK_STATIC const byte ks_2[] = {
  25265. 0x18, 0x5a, 0x59, 0xe5, 0x91, 0x4d, 0xc9, 0x6c,
  25266. 0xfa, 0x5b, 0x36, 0x06, 0x8c, 0x9a
  25267. };
  25268. WOLFSSL_SMALL_STACK_STATIC const byte index_c_2[] = {
  25269. 0x31, 0x2d, 0x58, 0x15
  25270. };
  25271. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_2[] = {
  25272. 0x14, 0xf2, 0xc8, 0x25, 0x02, 0x79, 0x22, 0xa1,
  25273. 0x96, 0xb6, 0xf7, 0x07, 0x76, 0xa6, 0xa3, 0xc4,
  25274. 0x37, 0xdf, 0xa0, 0xf8, 0x78, 0x93, 0x2c, 0xfa,
  25275. 0xea, 0x35, 0xf0, 0xf3, 0x3f, 0x32, 0x6e, 0xfd
  25276. };
  25277. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_2[] = {
  25278. 0x6e, 0x3d, 0x4a, 0x99, 0xea, 0x2f, 0x9d, 0x13,
  25279. 0x4a, 0x1e, 0x71, 0x2e, 0x15, 0xc0, 0xca, 0xb6,
  25280. 0x35, 0x78, 0xdf, 0xa4
  25281. };
  25282. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_2[] = {
  25283. 0xae, 0xe4, 0xec, 0x18, 0x31, 0x70, 0x5d, 0x3f,
  25284. 0xdc, 0x97, 0x89, 0x88, 0xfd, 0xff
  25285. };
  25286. /* 128-bit key, kdrIdx = 8 */
  25287. WOLFSSL_SMALL_STACK_STATIC const byte key_3[] = {
  25288. 0x36, 0xb4, 0xde, 0xcb, 0x2e, 0x51, 0x23, 0x76,
  25289. 0xe0, 0x27, 0x7e, 0x3e, 0xc8, 0xf6, 0x54, 0x04
  25290. };
  25291. WOLFSSL_SMALL_STACK_STATIC const byte salt_3[] = {
  25292. 0x73, 0x26, 0xf4, 0x3f, 0xc0, 0xd9, 0xc6, 0xe3,
  25293. 0x2f, 0x92, 0x7d, 0x46, 0x12, 0x76
  25294. };
  25295. WOLFSSL_SMALL_STACK_STATIC const byte index_3[] = {
  25296. 0x44, 0x73, 0xb2, 0x2d, 0xb2, 0x60
  25297. };
  25298. WOLFSSL_SMALL_STACK_STATIC const byte ke_3[] = {
  25299. 0x79, 0x91, 0x3d, 0x7b, 0x20, 0x5d, 0xea, 0xe2,
  25300. 0xeb, 0x46, 0x89, 0x68, 0x5a, 0x06, 0x73, 0x74
  25301. };
  25302. WOLFSSL_SMALL_STACK_STATIC const byte ka_3[] = {
  25303. 0x2d, 0x2e, 0x97, 0x4e, 0x76, 0x8c, 0x62, 0xa6,
  25304. 0x57, 0x80, 0x13, 0x42, 0x0b, 0x51, 0xa7, 0x66,
  25305. 0xea, 0x31, 0x24, 0xe6
  25306. };
  25307. WOLFSSL_SMALL_STACK_STATIC const byte ks_3[] = {
  25308. 0xcc, 0xd7, 0x31, 0xf6, 0x3b, 0xf3, 0x89, 0x8a,
  25309. 0x5b, 0x7b, 0xb5, 0x8b, 0x4c, 0x3f
  25310. };
  25311. WOLFSSL_SMALL_STACK_STATIC const byte index_c_3[] = {
  25312. 0x4a, 0x7d, 0xaa, 0x85
  25313. };
  25314. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_3[] = {
  25315. 0x34, 0x99, 0x71, 0xfe, 0x12, 0x93, 0xae, 0x8c,
  25316. 0x4a, 0xe9, 0x84, 0xe4, 0x93, 0x53, 0x63, 0x88
  25317. };
  25318. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_3[] = {
  25319. 0xa4, 0x53, 0x5e, 0x0a, 0x9c, 0xf2, 0xce, 0x13,
  25320. 0xef, 0x7a, 0x13, 0xee, 0x0a, 0xef, 0xba, 0x17,
  25321. 0x05, 0x18, 0xe3, 0xed
  25322. };
  25323. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_3[] = {
  25324. 0xe1, 0x29, 0x4f, 0x61, 0x30, 0x3c, 0x4d, 0x46,
  25325. 0x5f, 0x5c, 0x81, 0x3c, 0x38, 0xb6
  25326. };
  25327. /* SRTCP w/ 48-bit idx - KDR 0 (-1) */
  25328. WOLFSSL_SMALL_STACK_STATIC const byte mk48_1[] = {
  25329. 0xFF, 0xB6, 0xCB, 0x09, 0x71, 0x3F, 0x63, 0x4D,
  25330. 0x7F, 0x42, 0xED, 0xA8, 0x12, 0x81, 0x50, 0xE6
  25331. };
  25332. WOLFSSL_SMALL_STACK_STATIC const byte ms48_1[] = {
  25333. 0x1F, 0x04, 0x76, 0xC8, 0x7F, 0x58, 0x23, 0xEF,
  25334. 0xD3, 0x57, 0xB2, 0xBD, 0xF1, 0x32
  25335. };
  25336. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_1[] = {
  25337. 0x00, 0x00, 0x08, 0x56, 0xBC, 0x39
  25338. };
  25339. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_1[] = {
  25340. 0xD2, 0xC3, 0xF3, 0x49, 0x00, 0x1A, 0x18, 0x0F,
  25341. 0xB6, 0x05, 0x5A, 0x5A, 0x67, 0x8E, 0xE5, 0xB2
  25342. };
  25343. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_1[] = {
  25344. 0x8D, 0x54, 0xBE, 0xB5, 0x7B, 0x7F, 0x7A, 0xAB,
  25345. 0xF5, 0x46, 0xCE, 0x5B, 0x45, 0x69, 0x4A, 0x75,
  25346. 0x81, 0x2A, 0xE2, 0xCB
  25347. };
  25348. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_1[] = {
  25349. 0x76, 0x3C, 0x97, 0x6A, 0x45, 0x31, 0xA7, 0x79,
  25350. 0x3C, 0x28, 0x4A, 0xA6, 0x82, 0x03
  25351. };
  25352. /* SRTCP w/ 48-bit idx - KDR 19 */
  25353. WOLFSSL_SMALL_STACK_STATIC const byte mk48_2[] = {
  25354. 0xBD, 0x1D, 0x71, 0x6B, 0xDA, 0x28, 0xE3, 0xFC,
  25355. 0xA5, 0xA0, 0x66, 0x3F, 0x2E, 0x34, 0xA8, 0x58
  25356. };
  25357. WOLFSSL_SMALL_STACK_STATIC const byte ms48_2[] = {
  25358. 0x79, 0x06, 0xE5, 0xAB, 0x5C, 0x2B, 0x1B, 0x69,
  25359. 0xFA, 0xEE, 0xD2, 0x29, 0x57, 0x3C
  25360. };
  25361. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_2[] = {
  25362. 0x00, 0x00, 0x59, 0xD0, 0xC2, 0xE8
  25363. };
  25364. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_2[] = {
  25365. 0xB9, 0xD7, 0xAD, 0xD8, 0x90, 0x94, 0xC2, 0x92,
  25366. 0xA5, 0x04, 0x87, 0xC4, 0x8C, 0xEF, 0xE2, 0xA3
  25367. };
  25368. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_2[] = {
  25369. 0x07, 0xD5, 0xC4, 0xD2, 0x06, 0xFB, 0x63, 0x15,
  25370. 0xC2, 0x9C, 0x7F, 0x55, 0xD1, 0x16, 0x5C, 0xB5,
  25371. 0xB7, 0x44, 0x54, 0xBD
  25372. };
  25373. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_2[] = {
  25374. 0x0C, 0x5E, 0x53, 0xC1, 0xD0, 0x75, 0xAD, 0x65,
  25375. 0xBF, 0x51, 0x74, 0x50, 0x89, 0xD7
  25376. };
  25377. int kdr_48_1 = -1;
  25378. int kdr_48_2 = 19;
  25379. #define SRTP_TV_CNT 4
  25380. Srtp_Kdf_Tv tv[SRTP_TV_CNT] = {
  25381. { key_0, (word32)sizeof(key_0), salt_0, (word32)sizeof(salt_0), -1,
  25382. index_0, ke_0, ka_0, ks_0, index_c_0, ke_c_0, ka_c_0, ks_c_0,
  25383. 16, 20, 14 },
  25384. { key_1, (word32)sizeof(key_1), salt_1, (word32)sizeof(salt_1), 0,
  25385. index_1, ke_1, ka_1, ks_1, index_c_1, ke_c_1, ka_c_1, ks_c_1,
  25386. 24, 20, 14 },
  25387. { key_2, (word32)sizeof(key_2), salt_2, (word32)sizeof(salt_2), 1,
  25388. index_2, ke_2, ka_2, ks_2, index_c_2, ke_c_2, ka_c_2, ks_c_2,
  25389. 32, 20, 14 },
  25390. { key_3, (word32)sizeof(key_3), salt_3, (word32)sizeof(salt_3), 8,
  25391. index_3, ke_3, ka_3, ks_3, index_c_3, ke_c_3, ka_c_3, ks_c_3,
  25392. 16, 20, 14 },
  25393. };
  25394. int i;
  25395. int idx;
  25396. unsigned char keyE[32];
  25397. unsigned char keyA[20];
  25398. unsigned char keyS[14];
  25399. WOLFSSL_ENTER("srtpkdf_test");
  25400. for (i = 0; (ret == 0) && (i < SRTP_TV_CNT); i++) {
  25401. #ifndef WOLFSSL_AES_128
  25402. if (tv[i].keySz == AES_128_KEY_SIZE) {
  25403. continue;
  25404. }
  25405. #endif
  25406. #ifndef WOLFSSL_AES_192
  25407. if (tv[i].keySz == AES_192_KEY_SIZE) {
  25408. continue;
  25409. }
  25410. #endif
  25411. #ifndef WOLFSSL_AES_256
  25412. if (tv[i].keySz == AES_256_KEY_SIZE) {
  25413. continue;
  25414. }
  25415. #endif
  25416. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25417. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25418. keyS, tv[i].ksSz);
  25419. if (ret != 0)
  25420. return WC_TEST_RET_ENC_EC(ret);
  25421. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25422. return WC_TEST_RET_ENC_NC;
  25423. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25424. return WC_TEST_RET_ENC_NC;
  25425. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25426. return WC_TEST_RET_ENC_NC;
  25427. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25428. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_ENCRYPTION,
  25429. keyE, tv[i].keSz);
  25430. if (ret != 0)
  25431. return WC_TEST_RET_ENC_EC(ret);
  25432. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25433. return WC_TEST_RET_ENC_NC;
  25434. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25435. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_MSG_AUTH,
  25436. keyA, tv[i].kaSz);
  25437. if (ret != 0)
  25438. return WC_TEST_RET_ENC_EC(ret);
  25439. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25440. return WC_TEST_RET_ENC_NC;
  25441. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25442. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_SALT, keyS,
  25443. tv[i].ksSz);
  25444. if (ret != 0)
  25445. return WC_TEST_RET_ENC_EC(ret);
  25446. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25447. return WC_TEST_RET_ENC_NC;
  25448. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25449. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25450. keyS, tv[i].ksSz);
  25451. if (ret != 0)
  25452. return WC_TEST_RET_ENC_EC(ret);
  25453. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25454. return WC_TEST_RET_ENC_NC;
  25455. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25456. return WC_TEST_RET_ENC_NC;
  25457. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25458. return WC_TEST_RET_ENC_NC;
  25459. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25460. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c,
  25461. WC_SRTCP_LABEL_ENCRYPTION, keyE, tv[i].keSz);
  25462. if (ret != 0)
  25463. return WC_TEST_RET_ENC_EC(ret);
  25464. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25465. return WC_TEST_RET_ENC_NC;
  25466. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25467. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_MSG_AUTH,
  25468. keyA, tv[i].kaSz);
  25469. if (ret != 0)
  25470. return WC_TEST_RET_ENC_EC(ret);
  25471. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25472. return WC_TEST_RET_ENC_NC;
  25473. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25474. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT,
  25475. keyS, tv[i].ksSz);
  25476. if (ret != 0)
  25477. return WC_TEST_RET_ENC_EC(ret);
  25478. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25479. return WC_TEST_RET_ENC_NC;
  25480. }
  25481. #ifdef WOLFSSL_AES_128
  25482. i = 0;
  25483. #elif defined(WOLFSSL_AES_192)
  25484. i = 1;
  25485. #else
  25486. i = 2;
  25487. #endif
  25488. ret = wc_SRTP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25489. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25490. keyS, tv[i].ksSz);
  25491. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25492. return WC_TEST_RET_ENC_EC(ret);
  25493. ret = wc_SRTCP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25494. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25495. keyS, tv[i].ksSz);
  25496. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25497. return WC_TEST_RET_ENC_EC(ret);
  25498. ret = wc_SRTP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25499. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25500. keyS, tv[i].ksSz);
  25501. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25502. return WC_TEST_RET_ENC_EC(ret);
  25503. ret = wc_SRTCP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25504. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25505. keyS, tv[i].ksSz);
  25506. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25507. return WC_TEST_RET_ENC_EC(ret);
  25508. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25509. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25510. keyS, tv[i].ksSz);
  25511. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25512. return WC_TEST_RET_ENC_EC(ret);
  25513. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25514. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25515. keyS, tv[i].ksSz);
  25516. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25517. return WC_TEST_RET_ENC_EC(ret);
  25518. ret = wc_SRTP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25519. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25520. keyS, tv[i].ksSz);
  25521. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25522. return WC_TEST_RET_ENC_EC(ret);
  25523. ret = wc_SRTCP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25524. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25525. keyS, tv[i].ksSz);
  25526. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25527. return WC_TEST_RET_ENC_EC(ret);
  25528. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25529. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25530. keyS, tv[i].ksSz);
  25531. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25532. return WC_TEST_RET_ENC_EC(ret);
  25533. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25534. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25535. keyS, tv[i].ksSz);
  25536. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25537. return WC_TEST_RET_ENC_EC(ret);
  25538. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25539. 25, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25540. keyS, tv[i].ksSz);
  25541. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25542. return WC_TEST_RET_ENC_EC(ret);
  25543. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25544. 25, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25545. keyS, tv[i].ksSz);
  25546. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25547. return WC_TEST_RET_ENC_EC(ret);
  25548. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25549. -2, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25550. keyS, tv[i].ksSz);
  25551. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25552. return WC_TEST_RET_ENC_EC(ret);
  25553. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25554. -2, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25555. keyS, tv[i].ksSz);
  25556. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25557. return WC_TEST_RET_ENC_EC(ret);
  25558. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25559. tv[i].kdfIdx, tv[i].index, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25560. keyS, tv[i].ksSz);
  25561. if (ret != 0)
  25562. return WC_TEST_RET_ENC_EC(ret);
  25563. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25564. tv[i].kdfIdx, tv[i].index_c, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25565. keyS, tv[i].ksSz);
  25566. if (ret != 0)
  25567. return WC_TEST_RET_ENC_EC(ret);
  25568. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25569. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25570. keyS, tv[i].ksSz);
  25571. if (ret != 0)
  25572. return WC_TEST_RET_ENC_EC(ret);
  25573. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25574. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25575. keyS, tv[i].ksSz);
  25576. if (ret != 0)
  25577. return WC_TEST_RET_ENC_EC(ret);
  25578. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25579. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25580. NULL, tv[i].ksSz);
  25581. if (ret != 0)
  25582. return WC_TEST_RET_ENC_EC(ret);
  25583. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25584. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25585. NULL, tv[i].ksSz);
  25586. if (ret != 0)
  25587. return WC_TEST_RET_ENC_EC(ret);
  25588. idx = wc_SRTP_KDF_kdr_to_idx(0);
  25589. if (idx != -1)
  25590. return WC_TEST_RET_ENC_NC;
  25591. for (i = 0; i < 32; i++) {
  25592. word32 kdr = 1U << i;
  25593. /* SRTCP w/ 48-bit IDX, 128-bit key test */
  25594. if (i == 0) {
  25595. ret = wc_SRTCP_KDF_ex(mk48_1, (word32)sizeof(mk48_1),
  25596. ms48_1, (word32)sizeof(ms48_1),
  25597. kdr_48_1, srtcp48idx_1, keyE, tv[i].keSz,
  25598. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25599. WC_SRTCP_48BIT_IDX);
  25600. if (ret != 0)
  25601. return WC_TEST_RET_ENC_EC(ret);
  25602. if (XMEMCMP(keyE, srtcpKe_48_1, tv[i].keSz) != 0)
  25603. return WC_TEST_RET_ENC_NC;
  25604. if (XMEMCMP(keyA, srtcpKa_48_1, tv[i].kaSz) != 0)
  25605. return WC_TEST_RET_ENC_NC;
  25606. if (XMEMCMP(keyS, srtcpKs_48_1, tv[i].ksSz) != 0)
  25607. return WC_TEST_RET_ENC_NC;
  25608. ret = wc_SRTCP_KDF_ex(mk48_2, (word32)sizeof(mk48_2),
  25609. ms48_2, (word32)sizeof(ms48_2),
  25610. kdr_48_2, srtcp48idx_2, keyE, tv[i].keSz,
  25611. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25612. WC_SRTCP_48BIT_IDX);
  25613. if (ret != 0)
  25614. return WC_TEST_RET_ENC_EC(ret);
  25615. if (XMEMCMP(keyE, srtcpKe_48_2, tv[i].keSz) != 0)
  25616. return WC_TEST_RET_ENC_NC;
  25617. if (XMEMCMP(keyA, srtcpKa_48_2, tv[i].kaSz) != 0)
  25618. return WC_TEST_RET_ENC_NC;
  25619. if (XMEMCMP(keyS, srtcpKs_48_2, tv[i].ksSz) != 0)
  25620. return WC_TEST_RET_ENC_NC;
  25621. }
  25622. idx = wc_SRTP_KDF_kdr_to_idx(kdr);
  25623. if (idx != i)
  25624. return WC_TEST_RET_ENC_NC;
  25625. }
  25626. return 0;
  25627. }
  25628. #endif
  25629. #ifdef HAVE_ECC
  25630. /* size to use for ECC key gen tests */
  25631. #ifndef ECC_KEYGEN_SIZE
  25632. #if !defined(NO_ECC256) || defined(WOLFSSL_SM2)
  25633. #define ECC_KEYGEN_SIZE 32
  25634. #elif defined(HAVE_ECC384)
  25635. #define ECC_KEYGEN_SIZE 48
  25636. #elif defined(HAVE_ECC224)
  25637. #define ECC_KEYGEN_SIZE 28
  25638. #elif defined(HAVE_ECC521)
  25639. #define ECC_KEYGEN_SIZE 66
  25640. #else
  25641. #error No ECC keygen size defined for test
  25642. #endif
  25643. #endif
  25644. #ifdef BENCH_EMBEDDED
  25645. #define ECC_SHARED_SIZE 128
  25646. #else
  25647. #define ECC_SHARED_SIZE MAX_ECC_BYTES
  25648. #endif
  25649. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  25650. #define HAVE_ECC_DETERMINISTIC_K
  25651. #define ECC_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  25652. #else
  25653. #define ECC_DIGEST_SIZE MAX_ECC_BYTES
  25654. #endif
  25655. #define ECC_SIG_SIZE ECC_MAX_SIG_SIZE
  25656. #ifdef NO_ECC_SECP
  25657. #define NO_ECC_VECTOR_TEST
  25658. #endif
  25659. #ifndef NO_ECC_VECTOR_TEST
  25660. #if (defined(HAVE_ECC192) || defined(HAVE_ECC224) ||\
  25661. !defined(NO_ECC256) || defined(HAVE_ECC384) ||\
  25662. defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25663. #define HAVE_ECC_VECTOR_TEST
  25664. #endif
  25665. #endif
  25666. #ifdef HAVE_ECC_VECTOR_TEST
  25667. typedef struct eccVector {
  25668. const char* msg; /* SHA-1 Encoded Message */
  25669. const char* Qx;
  25670. const char* Qy;
  25671. const char* d; /* Private Key */
  25672. const char* R;
  25673. const char* S;
  25674. const char* curveName;
  25675. word32 msgLen;
  25676. word32 keySize;
  25677. const byte* r;
  25678. word32 rSz;
  25679. const byte* s;
  25680. word32 sSz;
  25681. } eccVector;
  25682. #if !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  25683. static wc_test_ret_t ecc_test_vector_item(const eccVector* vector)
  25684. {
  25685. wc_test_ret_t ret = 0;
  25686. int verify = 0;
  25687. word32 sigSz;
  25688. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25689. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25690. #else
  25691. ecc_key userA[1];
  25692. #endif
  25693. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25694. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25695. word32 sigRawSz, rSz = MAX_ECC_BYTES, sSz = MAX_ECC_BYTES;
  25696. WC_DECLARE_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25697. WC_DECLARE_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25698. WC_DECLARE_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25699. #endif
  25700. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25701. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25702. WC_ALLOC_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25703. WC_ALLOC_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25704. WC_ALLOC_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25705. #endif
  25706. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  25707. if (sig == NULL)
  25708. ERROR_OUT(MEMORY_E, done);
  25709. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25710. if (sigRaw == NULL || r == NULL || s == NULL)
  25711. ERROR_OUT(MEMORY_E, done);
  25712. #endif
  25713. #endif
  25714. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25715. if (userA == NULL)
  25716. ERROR_OUT(MEMORY_E, done);
  25717. #endif
  25718. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  25719. if (ret != 0)
  25720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25721. ret = wc_ecc_import_raw(userA, vector->Qx, vector->Qy,
  25722. vector->d, vector->curveName);
  25723. if (ret != 0)
  25724. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25725. #if !defined(NO_ASN)
  25726. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25727. sigSz = ECC_SIG_SIZE;
  25728. ret = wc_ecc_rs_to_sig(vector->R, vector->S, sig, &sigSz);
  25729. if (ret != 0)
  25730. goto done;
  25731. #if !defined(HAVE_SELFTEST)
  25732. XMEMSET(sigRaw, 0, ECC_SIG_SIZE);
  25733. sigRawSz = ECC_SIG_SIZE;
  25734. ret = wc_ecc_rs_raw_to_sig(vector->r, vector->rSz, vector->s, vector->sSz,
  25735. sigRaw, &sigRawSz);
  25736. if (ret != 0)
  25737. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25738. if (sigSz != sigRawSz || XMEMCMP(sig, sigRaw, sigSz) != 0) {
  25739. ret = WC_TEST_RET_ENC_NC;
  25740. goto done;
  25741. }
  25742. ret = wc_ecc_sig_to_rs(sig, sigSz, r, &rSz, s, &sSz);
  25743. if (ret != 0)
  25744. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25745. if (rSz != vector->rSz || XMEMCMP(r, vector->r, rSz) != 0 ||
  25746. sSz != vector->sSz || XMEMCMP(s, vector->s, sSz) != 0) {
  25747. ret = WC_TEST_RET_ENC_NC;
  25748. goto done;
  25749. }
  25750. #endif /* !HAVE_SELFTEST */
  25751. #else
  25752. /* Signature will be R+S directly */
  25753. /* Make sure and zero pad if r or s is less than key size */
  25754. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25755. sigSz = vector->keySize * 2;
  25756. XMEMCPY(sig + (vector->keySize - vector->rSz),
  25757. vector->r, vector->rSz);
  25758. XMEMCPY(sig + vector->keySize + (vector->keySize - vector->sSz),
  25759. vector->s, vector->sSz);
  25760. #endif /* !NO_ASN */
  25761. #ifdef HAVE_ECC_VERIFY
  25762. do {
  25763. #if defined(WOLFSSL_ASYNC_CRYPT)
  25764. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25765. #endif
  25766. if (ret == 0)
  25767. ret = wc_ecc_verify_hash(sig, sigSz, (byte*)vector->msg,
  25768. vector->msgLen, &verify, userA);
  25769. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25770. if (ret != 0)
  25771. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25772. TEST_SLEEP();
  25773. if (verify != 1)
  25774. ret = WC_TEST_RET_ENC_NC;
  25775. #endif
  25776. done:
  25777. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25778. if (userA != NULL) {
  25779. wc_ecc_free(userA);
  25780. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25781. }
  25782. #else
  25783. wc_ecc_free(userA);
  25784. #endif
  25785. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25786. WC_FREE_VAR(sigRaw, HEAP_HINT);
  25787. WC_FREE_VAR(r, HEAP_HINT);
  25788. WC_FREE_VAR(s, HEAP_HINT);
  25789. #endif
  25790. WC_FREE_VAR(sig, HEAP_HINT);
  25791. return ret;
  25792. }
  25793. static wc_test_ret_t ecc_test_vector(int keySize)
  25794. {
  25795. wc_test_ret_t ret;
  25796. eccVector vec;
  25797. XMEMSET(&vec, 0, sizeof(vec));
  25798. vec.keySize = (word32)keySize;
  25799. switch(keySize) {
  25800. #if defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)
  25801. case 14:
  25802. return 0;
  25803. #endif /* HAVE_ECC112 */
  25804. #if defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)
  25805. case 16:
  25806. return 0;
  25807. #endif /* HAVE_ECC128 */
  25808. #if defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)
  25809. case 20:
  25810. return 0;
  25811. #endif /* HAVE_ECC160 */
  25812. #if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)
  25813. case 24:
  25814. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  25815. #if 1
  25816. vec.msg = "\x60\x80\x79\x42\x3f\x12\x42\x1d\xe6\x16\xb7\x49\x3e\xbe\x55\x1c\xf4\xd6\x5b\x92";
  25817. vec.msgLen = 20;
  25818. #else
  25819. /* This is the raw message prior to SHA-1 */
  25820. vec.msg =
  25821. "\xeb\xf7\x48\xd7\x48\xeb\xbc\xa7\xd2\x9f\xb4\x73\x69\x8a\x6e\x6b"
  25822. "\x4f\xb1\x0c\x86\x5d\x4a\xf0\x24\xcc\x39\xae\x3d\xf3\x46\x4b\xa4"
  25823. "\xf1\xd6\xd4\x0f\x32\xbf\x96\x18\xa9\x1b\xb5\x98\x6f\xa1\xa2\xaf"
  25824. "\x04\x8a\x0e\x14\xdc\x51\xe5\x26\x7e\xb0\x5e\x12\x7d\x68\x9d\x0a"
  25825. "\xc6\xf1\xa7\xf1\x56\xce\x06\x63\x16\xb9\x71\xcc\x7a\x11\xd0\xfd"
  25826. "\x7a\x20\x93\xe2\x7c\xf2\xd0\x87\x27\xa4\xe6\x74\x8c\xc3\x2f\xd5"
  25827. "\x9c\x78\x10\xc5\xb9\x01\x9d\xf2\x1c\xdc\xc0\xbc\xa4\x32\xc0\xa3"
  25828. "\xee\xd0\x78\x53\x87\x50\x88\x77\x11\x43\x59\xce\xe4\xa0\x71\xcf";
  25829. vec.msgLen = 128;
  25830. #endif
  25831. vec.Qx = "07008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6";
  25832. vec.Qy = "76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477";
  25833. vec.d = "e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3";
  25834. vec.R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  25835. vec.S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  25836. vec.curveName = "SECP192R1";
  25837. vec.r = (byte*)"\x69\x94\xd9\x62\xbd\xd0\xd7\x93\xff\xdd\xf8\x55"
  25838. "\xec\x5b\xf2\xf9\x1a\x96\x98\xb4\x62\x58\xa6\x3e";
  25839. vec.rSz = 24;
  25840. vec.s = (byte*)"\x02\xba\x64\x65\xa2\x34\x90\x37\x44\xab\x02\xbc"
  25841. "\x85\x21\x40\x5b\x73\xcf\x5f\xc0\x0e\x1a\x9f\x41";
  25842. vec.sSz = 24;
  25843. break;
  25844. #endif /* HAVE_ECC192 */
  25845. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  25846. case 28:
  25847. /* first [P-224,SHA-1] vector from FIPS 186-3 NIST vectors */
  25848. #if 1
  25849. vec.msg = "\xb9\xa3\xb8\x6d\xb0\xba\x99\xfd\xc6\xd2\x94\x6b\xfe\xbe\x9c\xe8\x3f\x10\x74\xfc";
  25850. vec.msgLen = 20;
  25851. #else
  25852. /* This is the raw message prior to SHA-1 */
  25853. vec.msg =
  25854. "\x36\xc8\xb2\x29\x86\x48\x7f\x67\x7c\x18\xd0\x97\x2a\x9e\x20\x47"
  25855. "\xb3\xaf\xa5\x9e\xc1\x62\x76\x4e\xc3\x0b\x5b\x69\xe0\x63\x0f\x99"
  25856. "\x0d\x4e\x05\xc2\x73\xb0\xe5\xa9\xd4\x28\x27\xb6\x95\xfc\x2d\x64"
  25857. "\xd9\x13\x8b\x1c\xf4\xc1\x21\x55\x89\x4c\x42\x13\x21\xa7\xbb\x97"
  25858. "\x0b\xdc\xe0\xfb\xf0\xd2\xae\x85\x61\xaa\xd8\x71\x7f\x2e\x46\xdf"
  25859. "\xe3\xff\x8d\xea\xb4\xd7\x93\x23\x56\x03\x2c\x15\x13\x0d\x59\x9e"
  25860. "\x26\xc1\x0f\x2f\xec\x96\x30\x31\xac\x69\x38\xa1\x8d\x66\x45\x38"
  25861. "\xb9\x4d\xac\x55\x34\xef\x7b\x59\x94\x24\xd6\x9b\xe1\xf7\x1c\x20";
  25862. vec.msgLen = 128;
  25863. #endif
  25864. vec.Qx = "8a4dca35136c4b70e588e23554637ae251077d1365a6ba5db9585de7";
  25865. vec.Qy = "ad3dee06de0be8279d4af435d7245f14f3b4f82eb578e519ee0057b1";
  25866. vec.d = "97c4b796e1639dd1035b708fc00dc7ba1682cec44a1002a1a820619f";
  25867. vec.R = "147b33758321e722a0360a4719738af848449e2c1d08defebc1671a7";
  25868. vec.S = "24fc7ed7f1352ca3872aa0916191289e2e04d454935d50fe6af3ad5b";
  25869. vec.curveName = "SECP224R1";
  25870. vec.r = (byte*)"\x14\x7b\x33\x75\x83\x21\xe7\x22\xa0\x36\x0a\x47"
  25871. "\x19\x73\x8a\xf8\x48\x44\x9e\x2c\x1d\x08\xde\xfe"
  25872. "\xbc\x16\x71\xa7";
  25873. vec.rSz = 28;
  25874. vec.s = (byte*)"\x24\xfc\x7e\xd7\xf1\x35\x2c\xa3\x87\x2a\xa0\x91"
  25875. "\x61\x91\x28\x9e\x2e\x04\xd4\x54\x93\x5d\x50\xfe"
  25876. "\x6a\xf3\xad\x5b";
  25877. vec.sSz = 28;
  25878. break;
  25879. #endif /* HAVE_ECC224 */
  25880. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  25881. case 30:
  25882. return 0;
  25883. #endif /* HAVE_ECC239 */
  25884. #if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES)
  25885. case 32:
  25886. /* first [P-256,SHA-1] vector from FIPS 186-3 NIST vectors */
  25887. #if 1
  25888. vec.msg = "\xa3\xf9\x1a\xe2\x1b\xa6\xb3\x03\x98\x64\x47\x2f\x18\x41\x44\xc6\xaf\x62\xcd\x0e";
  25889. vec.msgLen = 20;
  25890. #else
  25891. /* This is the raw message prior to SHA-1 */
  25892. vec.msg =
  25893. "\xa2\x4b\x21\x76\x2e\x6e\xdb\x15\x3c\xc1\x14\x38\xdb\x0e\x92\xcd"
  25894. "\xf5\x2b\x86\xb0\x6c\xa9\x70\x16\x06\x27\x59\xc7\x0d\x36\xd1\x56"
  25895. "\x2c\xc9\x63\x0d\x7f\xc7\xc7\x74\xb2\x8b\x54\xe3\x1e\xf5\x58\x72"
  25896. "\xb2\xa6\x5d\xf1\xd7\xec\x26\xde\xbb\x33\xe7\xd9\x27\xef\xcc\xf4"
  25897. "\x6b\x63\xde\x52\xa4\xf4\x31\xea\xca\x59\xb0\x5d\x2e\xde\xc4\x84"
  25898. "\x5f\xff\xc0\xee\x15\x03\x94\xd6\x1f\x3d\xfe\xcb\xcd\xbf\x6f\x5a"
  25899. "\x73\x38\xd0\xbe\x3f\x2a\x77\x34\x51\x98\x3e\xba\xeb\x48\xf6\x73"
  25900. "\x8f\xc8\x95\xdf\x35\x7e\x1a\x48\xa6\x53\xbb\x35\x5a\x31\xa1\xb4"
  25901. vec.msgLen = 128;
  25902. #endif
  25903. vec.Qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  25904. vec.Qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  25905. vec.d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  25906. vec.R = "2b826f5d44e2d0b6de531ad96b51e8f0c56fdfead3c236892e4d84eacfc3b75c";
  25907. vec.S = "a2248b62c03db35a7cd63e8a120a3521a89d3d2f61ff99035a2148ae32e3a248";
  25908. vec.r = (byte*)"\x2b\x82\x6f\x5d\x44\xe2\xd0\xb6\xde\x53\x1a\xd9"
  25909. "\x6b\x51\xe8\xf0\xc5\x6f\xdf\xea\xd3\xc2\x36\x89"
  25910. "\x2e\x4d\x84\xea\xcf\xc3\xb7\x5c";
  25911. vec.rSz = 32;
  25912. vec.s = (byte*)"\xa2\x24\x8b\x62\xc0\x3d\xb3\x5a\x7c\xd6\x3e\x8a"
  25913. "\x12\x0a\x35\x21\xa8\x9d\x3d\x2f\x61\xff\x99\x03"
  25914. "\x5a\x21\x48\xae\x32\xe3\xa2\x48";
  25915. vec.sSz = 32;
  25916. vec.curveName = "SECP256R1";
  25917. break;
  25918. #endif /* !NO_ECC256 */
  25919. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  25920. case 40:
  25921. return 0;
  25922. #endif /* HAVE_ECC320 */
  25923. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  25924. case 48:
  25925. /* first [P-384,SHA-1] vector from FIPS 186-3 NIST vectors */
  25926. #if 1
  25927. vec.msg = "\x9b\x9f\x8c\x95\x35\xa5\xca\x26\x60\x5d\xb7\xf2\xfa\x57\x3b\xdf\xc3\x2e\xab\x8b";
  25928. vec.msgLen = 20;
  25929. #else
  25930. /* This is the raw message prior to SHA-1 */
  25931. vec.msg =
  25932. "\xab\xe1\x0a\xce\x13\xe7\xe1\xd9\x18\x6c\x48\xf7\x88\x9d\x51\x47"
  25933. "\x3d\x3a\x09\x61\x98\x4b\xc8\x72\xdf\x70\x8e\xcc\x3e\xd3\xb8\x16"
  25934. "\x9d\x01\xe3\xd9\x6f\xc4\xf1\xd5\xea\x00\xa0\x36\x92\xbc\xc5\xcf"
  25935. "\xfd\x53\x78\x7c\x88\xb9\x34\xaf\x40\x4c\x03\x9d\x32\x89\xb5\xba"
  25936. "\xc5\xae\x7d\xb1\x49\x68\x75\xb5\xdc\x73\xc3\x09\xf9\x25\xc1\x3d"
  25937. "\x1c\x01\xab\xda\xaf\xeb\xcd\xac\x2c\xee\x43\x39\x39\xce\x8d\x4a"
  25938. "\x0a\x5d\x57\xbb\x70\x5f\x3b\xf6\xec\x08\x47\x95\x11\xd4\xb4\xa3"
  25939. "\x21\x1f\x61\x64\x9a\xd6\x27\x43\x14\xbf\x0d\x43\x8a\x81\xe0\x60"
  25940. vec.msgLen = 128;
  25941. #endif
  25942. vec.Qx = "e55fee6c49d8d523f5ce7bf9c0425ce4ff650708b7de5cfb095901523979a7f042602db30854735369813b5c3f5ef868";
  25943. vec.Qy = "28f59cc5dc509892a988d38a8e2519de3d0c4fd0fbdb0993e38f18506c17606c5e24249246f1ce94983a5361c5be983e";
  25944. vec.d = "a492ce8fa90084c227e1a32f7974d39e9ff67a7e8705ec3419b35fb607582bebd461e0b1520ac76ec2dd4e9b63ebae71";
  25945. vec.R = "6820b8585204648aed63bdff47f6d9acebdea62944774a7d14f0e14aa0b9a5b99545b2daee6b3c74ebf606667a3f39b7";
  25946. vec.S = "491af1d0cccd56ddd520b233775d0bc6b40a6255cc55207d8e9356741f23c96c14714221078dbd5c17f4fdd89b32a907";
  25947. vec.curveName = "SECP384R1";
  25948. vec.r = (byte*)"\x68\x20\xb8\x58\x52\x04\x64\x8a\xed\x63\xbd\xff"
  25949. "\x47\xf6\xd9\xac\xeb\xde\xa6\x29\x44\x77\x4a\x7d"
  25950. "\x14\xf0\xe1\x4a\xa0\xb9\xa5\xb9\x95\x45\xb2\xda"
  25951. "\xee\x6b\x3c\x74\xeb\xf6\x06\x66\x7a\x3f\x39\xb7";
  25952. vec.rSz = 48;
  25953. vec.s = (byte*)"\x49\x1a\xf1\xd0\xcc\xcd\x56\xdd\xd5\x20\xb2\x33"
  25954. "\x77\x5d\x0b\xc6\xb4\x0a\x62\x55\xcc\x55\x20\x7d"
  25955. "\x8e\x93\x56\x74\x1f\x23\xc9\x6c\x14\x71\x42\x21"
  25956. "\x07\x8d\xbd\x5c\x17\xf4\xfd\xd8\x9b\x32\xa9\x07";
  25957. vec.sSz = 48;
  25958. break;
  25959. #endif /* HAVE_ECC384 */
  25960. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  25961. case 64:
  25962. return 0;
  25963. #endif /* HAVE_ECC512 */
  25964. #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
  25965. case 66:
  25966. /* first [P-521,SHA-1] vector from FIPS 186-3 NIST vectors */
  25967. #if 1
  25968. vec.msg = "\x1b\xf7\x03\x9c\xca\x23\x94\x27\x3f\x11\xa1\xd4\x8d\xcc\xb4\x46\x6f\x31\x61\xdf";
  25969. vec.msgLen = 20;
  25970. #else
  25971. /* This is the raw message prior to SHA-1 */
  25972. vec.msg =
  25973. "\x50\x3f\x79\x39\x34\x0a\xc7\x23\xcd\x4a\x2f\x4e\x6c\xcc\x27\x33"
  25974. "\x38\x3a\xca\x2f\xba\x90\x02\x19\x9d\x9e\x1f\x94\x8b\xe0\x41\x21"
  25975. "\x07\xa3\xfd\xd5\x14\xd9\x0c\xd4\xf3\x7c\xc3\xac\x62\xef\x00\x3a"
  25976. "\x2d\xb1\xd9\x65\x7a\xb7\x7f\xe7\x55\xbf\x71\xfa\x59\xe4\xd9\x6e"
  25977. "\xa7\x2a\xe7\xbf\x9d\xe8\x7d\x79\x34\x3b\xc1\xa4\xbb\x14\x4d\x16"
  25978. "\x28\xd1\xe9\xe9\xc8\xed\x80\x8b\x96\x2c\x54\xe5\xf9\x6d\x53\xda"
  25979. "\x14\x7a\x96\x38\xf9\x4a\x91\x75\xd8\xed\x61\x05\x5f\x0b\xa5\x73"
  25980. "\xa8\x2b\xb7\xe0\x18\xee\xda\xc4\xea\x7b\x36\x2e\xc8\x9c\x38\x2b"
  25981. vec.msgLen = 128;
  25982. #endif
  25983. vec.Qx = "12fbcaeffa6a51f3ee4d3d2b51c5dec6d7c726ca353fc014ea2bf7cfbb9b910d32cbfa6a00fe39b6cdb8946f22775398b2e233c0cf144d78c8a7742b5c7a3bb5d23";
  25984. vec.Qy = "09cdef823dd7bf9a79e8cceacd2e4527c231d0ae5967af0958e931d7ddccf2805a3e618dc3039fec9febbd33052fe4c0fee98f033106064982d88f4e03549d4a64d";
  25985. vec.d = "1bd56bd106118eda246155bd43b42b8e13f0a6e25dd3bb376026fab4dc92b6157bc6dfec2d15dd3d0cf2a39aa68494042af48ba9601118da82c6f2108a3a203ad74";
  25986. vec.R = "0bd117b4807710898f9dd7778056485777668f0e78e6ddf5b000356121eb7a220e9493c7f9a57c077947f89ac45d5acb6661bbcd17abb3faea149ba0aa3bb1521be";
  25987. vec.S = "019cd2c5c3f9870ecdeb9b323abdf3a98cd5e231d85c6ddc5b71ab190739f7f226e6b134ba1d5889ddeb2751dabd97911dff90c34684cdbe7bb669b6c3d22f2480c";
  25988. vec.curveName = "SECP521R1";
  25989. vec.r = (byte*)"\xbd\x11\x7b\x48\x07\x71\x08\x98\xf9\xdd\x77\x78"
  25990. "\x05\x64\x85\x77\x76\x68\xf0\xe7\x8e\x6d\xdf\x5b"
  25991. "\x00\x03\x56\x12\x1e\xb7\xa2\x20\xe9\x49\x3c\x7f"
  25992. "\x9a\x57\xc0\x77\x94\x7f\x89\xac\x45\xd5\xac\xb6"
  25993. "\x66\x1b\xbc\xd1\x7a\xbb\x3f\xae\xa1\x49\xba\x0a"
  25994. "\xa3\xbb\x15\x21\xbe";
  25995. vec.rSz = 65;
  25996. vec.s = (byte*)"\x19\xcd\x2c\x5c\x3f\x98\x70\xec\xde\xb9\xb3\x23"
  25997. "\xab\xdf\x3a\x98\xcd\x5e\x23\x1d\x85\xc6\xdd\xc5"
  25998. "\xb7\x1a\xb1\x90\x73\x9f\x7f\x22\x6e\x6b\x13\x4b"
  25999. "\xa1\xd5\x88\x9d\xde\xb2\x75\x1d\xab\xd9\x79\x11"
  26000. "\xdf\xf9\x0c\x34\x68\x4c\xdb\xe7\xbb\x66\x9b\x6c"
  26001. "\x3d\x22\xf2\x48\x0c";
  26002. vec.sSz = 65;
  26003. break;
  26004. #endif /* HAVE_ECC521 */
  26005. default:
  26006. return WC_TEST_RET_ENC_EC(NOT_COMPILED_IN); /* Invalid key size /
  26007. * Not supported
  26008. */
  26009. }; /* Switch */
  26010. ret = ecc_test_vector_item(&vec);
  26011. if (ret < 0) {
  26012. return ret;
  26013. }
  26014. return 0;
  26015. }
  26016. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26017. #if defined(HAVE_ECC_SIGN) && \
  26018. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  26019. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  26020. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  26021. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  26022. static wc_test_ret_t ecdsa_test_deterministic_k_sig(ecc_key *key,
  26023. enum wc_HashType hashType, const char* msg, WC_RNG* rng, const byte* expSig,
  26024. size_t expSigSz)
  26025. {
  26026. wc_test_ret_t ret;
  26027. int verify;
  26028. byte sig[ECC_MAX_SIG_SIZE];
  26029. word32 sigSz;
  26030. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26031. ret = wc_Hash(hashType,
  26032. (byte*)msg, (word32)XSTRLEN(msg),
  26033. hash, sizeof(hash));
  26034. if (ret != 0)
  26035. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26036. /* Sign test */
  26037. sigSz = sizeof(sig);
  26038. do {
  26039. #if defined(WOLFSSL_ASYNC_CRYPT)
  26040. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26041. #endif
  26042. if (ret == 0)
  26043. ret = wc_ecc_sign_hash(hash, wc_HashGetDigestSize(hashType),
  26044. sig, &sigSz, rng, key);
  26045. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26046. if (ret != 0)
  26047. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26048. TEST_SLEEP();
  26049. /* Compare test vector */
  26050. if (sigSz != expSigSz) {
  26051. ret = WC_TEST_RET_ENC_NC;
  26052. goto done;
  26053. }
  26054. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26055. ret = WC_TEST_RET_ENC_NC;
  26056. goto done;
  26057. }
  26058. /* Verification */
  26059. verify = 0;
  26060. do {
  26061. #if defined(WOLFSSL_ASYNC_CRYPT)
  26062. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26063. #endif
  26064. if (ret == 0)
  26065. ret = wc_ecc_verify_hash(sig, sigSz,
  26066. hash, wc_HashGetDigestSize(hashType), &verify, key);
  26067. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26068. if (ret != 0)
  26069. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26070. if (verify != 1) {
  26071. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26072. }
  26073. done:
  26074. return ret;
  26075. }
  26076. static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
  26077. {
  26078. wc_test_ret_t ret;
  26079. #ifdef WOLFSSL_SMALL_STACK
  26080. ecc_key *key = NULL;
  26081. #else
  26082. ecc_key key[1];
  26083. #endif
  26084. int key_inited = 0;
  26085. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26086. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26087. "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721";
  26088. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26089. "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6";
  26090. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26091. "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299";
  26092. #ifndef NO_SHA256
  26093. WOLFSSL_SMALL_STACK_STATIC const byte expSig256[] = {
  26094. 0x30, 0x46, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26095. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26096. 0x00, 0xEF, 0xD4, 0x8B, 0x2A, 0xAC, 0xB6, 0xA8,
  26097. 0xFD, 0x11, 0x40, 0xDD, 0x9C, 0xD4, 0x5E, 0x81,
  26098. 0xD6, 0x9D, 0x2C, 0x87, 0x7B, 0x56, 0xAA, 0xF9,
  26099. 0x91, 0xC3, 0x4D, 0x0E, 0xA8, 0x4E, 0xAF, 0x37,
  26100. 0x16,
  26101. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26102. 0x00, 0xF7, 0xCB, 0x1C, 0x94, 0x2D, 0x65, 0x7C,
  26103. 0x41, 0xD4, 0x36, 0xC7, 0xA1, 0xB6, 0xE2, 0x9F,
  26104. 0x65, 0xF3, 0xE9, 0x00, 0xDB, 0xB9, 0xAF, 0xF4,
  26105. 0x06, 0x4D, 0xC4, 0xAB, 0x2F, 0x84, 0x3A, 0xCD,
  26106. 0xA8
  26107. };
  26108. #endif
  26109. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26110. WOLFSSL_SMALL_STACK_STATIC const byte expSig384[] = {
  26111. 0x30, 0x44, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26112. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26113. 0x0e, 0xaf, 0xea, 0x03, 0x9b, 0x20, 0xe9, 0xb4,
  26114. 0x23, 0x09, 0xfb, 0x1d, 0x89, 0xe2, 0x13, 0x05,
  26115. 0x7c, 0xbf, 0x97, 0x3d, 0xc0, 0xcf, 0xc8, 0xf1,
  26116. 0x29, 0xed, 0xdd, 0xc8, 0x00, 0xef, 0x77, 0x19,
  26117. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26118. 0x48, 0x61, 0xf0, 0x49, 0x1e, 0x69, 0x98, 0xb9,
  26119. 0x45, 0x51, 0x93, 0xe3, 0x4e, 0x7b, 0x0d, 0x28,
  26120. 0x4d, 0xdd, 0x71, 0x49, 0xa7, 0x4b, 0x95, 0xb9,
  26121. 0x26, 0x1f, 0x13, 0xab, 0xde, 0x94, 0x09, 0x54
  26122. };
  26123. #endif
  26124. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26125. WOLFSSL_SMALL_STACK_STATIC const byte expSig512[] = {
  26126. 0x30, 0x45, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26127. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26128. 0x00, 0x84, 0x96, 0xa6, 0x0b, 0x5e, 0x9b, 0x47,
  26129. 0xc8, 0x25, 0x48, 0x88, 0x27, 0xe0, 0x49, 0x5b,
  26130. 0x0e, 0x3f, 0xa1, 0x09, 0xec, 0x45, 0x68, 0xfd,
  26131. 0x3f, 0x8d, 0x10, 0x97, 0x67, 0x8e, 0xb9, 0x7f,
  26132. 0x00,
  26133. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26134. 0x23, 0x62, 0xab, 0x1a, 0xdb, 0xe2, 0xb8, 0xad,
  26135. 0xf9, 0xcb, 0x9e, 0xda, 0xb7, 0x40, 0xea, 0x60,
  26136. 0x49, 0xc0, 0x28, 0x11, 0x4f, 0x24, 0x60, 0xf9,
  26137. 0x65, 0x54, 0xf6, 0x1f, 0xae, 0x33, 0x02, 0xfe
  26138. };
  26139. #endif
  26140. #ifdef WOLFSSL_SMALL_STACK
  26141. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26142. if (key == NULL)
  26143. return MEMORY_E;
  26144. #endif
  26145. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26146. if (ret != 0)
  26147. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26148. key_inited = 1;
  26149. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26150. if (ret != 0)
  26151. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26152. ret = wc_ecc_set_deterministic(key, 1);
  26153. if (ret != 0)
  26154. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26155. #ifndef NO_SHA256
  26156. /* Test for SHA2-256 */
  26157. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA256, msg, rng,
  26158. expSig256, sizeof(expSig256));
  26159. if (ret != 0)
  26160. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26161. #endif /* !NO_SHA256 */
  26162. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26163. /* Test for SHA2-384 */
  26164. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA384, msg, rng,
  26165. expSig384, sizeof(expSig384));
  26166. if (ret != 0)
  26167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26168. #endif /* WOLFSSL_SHA384 */
  26169. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26170. /* Test for SHA2-512 */
  26171. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA512, msg, rng,
  26172. expSig512, sizeof(expSig512));
  26173. if (ret != 0)
  26174. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26175. #endif /* WOLFSSL_SHA512 */
  26176. done:
  26177. if (key_inited)
  26178. wc_ecc_free(key);
  26179. #ifdef WOLFSSL_SMALL_STACK
  26180. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26181. #endif
  26182. return ret;
  26183. }
  26184. #endif /* NO_ECC256 || HAVE_ALL_CURVES */
  26185. #ifdef WOLFSSL_PUBLIC_MP
  26186. static wc_test_ret_t ecdsa_test_deterministic_k_rs(ecc_key *key,
  26187. enum wc_HashType hashType, const char* msg, WC_RNG* rng,
  26188. mp_int* r, mp_int* s,
  26189. mp_int* expR, mp_int* expS)
  26190. {
  26191. wc_test_ret_t ret;
  26192. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26193. int verify;
  26194. ret = wc_Hash(hashType,
  26195. (byte*)msg, (word32)XSTRLEN(msg),
  26196. hash, sizeof(hash));
  26197. if (ret != 0)
  26198. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26199. ret = wc_ecc_sign_hash_ex(hash, wc_HashGetDigestSize(hashType), rng, key,
  26200. r, s);
  26201. #if defined(WOLFSSL_ASYNC_CRYPT)
  26202. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26203. #endif
  26204. if (ret != 0)
  26205. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26206. TEST_SLEEP();
  26207. if (mp_cmp(r, expR) != MP_EQ && mp_cmp(s, expS) != MP_EQ) {
  26208. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26209. }
  26210. /* Verification */
  26211. verify = 0;
  26212. ret = wc_ecc_verify_hash_ex(r, s, hash, wc_HashGetDigestSize(hashType),
  26213. &verify, key);
  26214. #if defined(WOLFSSL_ASYNC_CRYPT)
  26215. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26216. #endif
  26217. if (ret != 0)
  26218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26219. if (verify != 1) {
  26220. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26221. }
  26222. done:
  26223. return ret;
  26224. }
  26225. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  26226. /* KAT from RFC6979 */
  26227. static wc_test_ret_t ecc384_test_deterministic_k(WC_RNG* rng)
  26228. {
  26229. wc_test_ret_t ret;
  26230. #ifdef WOLFSSL_SMALL_STACK
  26231. ecc_key *key;
  26232. mp_int *r, *s, *expR, *expS;
  26233. #else
  26234. ecc_key key[1];
  26235. mp_int r[1], s[1], expR[1], expS[1];
  26236. #endif
  26237. int key_inited = 0,
  26238. tmp_mp_ints_inited = 0;
  26239. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26240. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26241. "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D8"
  26242. "96D5724E4C70A825F872C9EA60D2EDF5";
  26243. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26244. "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64"
  26245. "DEF8F0EA9055866064A254515480BC13";
  26246. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26247. "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1"
  26248. "288B231C3AE0D4FE7344FD2533264720";
  26249. #ifndef NO_SHA256
  26250. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26251. "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33"
  26252. "BDE1E888E63355D92FA2B3C36D8FB2CD";
  26253. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26254. "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEB"
  26255. "EFDC63ECCD1AC42EC0CB8668A4FA0AB0";
  26256. #endif
  26257. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26258. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26259. "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C"
  26260. "81A648152E44ACF96E36DD1E80FABE46";
  26261. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26262. "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94F"
  26263. "A329C145786E679E7B82C71A38628AC8";
  26264. #endif
  26265. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26266. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26267. "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799C"
  26268. "FE30F35CC900056D7C99CD7882433709";
  26269. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26270. "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112"
  26271. "DC7CC3EF3446DEFCEB01A45C2667FDD5";
  26272. #endif
  26273. #ifdef WOLFSSL_SMALL_STACK
  26274. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26275. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26276. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26277. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26278. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26279. if ((key == NULL) ||
  26280. (r == NULL) ||
  26281. (s == NULL) ||
  26282. (expR == NULL) ||
  26283. (expS == NULL))
  26284. {
  26285. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26286. }
  26287. #endif
  26288. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26289. if (ret != MP_OKAY)
  26290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26291. tmp_mp_ints_inited = 1;
  26292. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26293. if (ret != 0)
  26294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26295. key_inited = 1;
  26296. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP384R1");
  26297. if (ret != 0)
  26298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26299. ret = wc_ecc_set_deterministic(key, 1);
  26300. if (ret != 0)
  26301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26302. #ifndef NO_SHA256
  26303. /* Test for SHA2-256 */
  26304. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26305. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26306. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26307. r, s, expR, expS);
  26308. if (ret != 0)
  26309. ERROR_OUT(ret, done);
  26310. #endif /* NO_SHA256 */
  26311. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26312. /* Test for SHA2-384 */
  26313. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26314. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26315. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26316. r, s, expR, expS);
  26317. if (ret != 0)
  26318. ERROR_OUT(ret, done);
  26319. #endif /* WOLFSSL_SHA384 */
  26320. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26321. /* Test for SHA2-512 */
  26322. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26323. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26324. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26325. r, s, expR, expS);
  26326. if (ret != 0)
  26327. ERROR_OUT(ret, done);
  26328. #endif /* WOLFSSL_SHA512 */
  26329. done:
  26330. if (key_inited)
  26331. wc_ecc_free(key);
  26332. if (tmp_mp_ints_inited) {
  26333. mp_free(r);
  26334. mp_free(s);
  26335. mp_free(expR);
  26336. mp_free(expS);
  26337. }
  26338. #ifdef WOLFSSL_SMALL_STACK
  26339. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26340. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26341. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26342. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26343. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26344. #endif
  26345. return ret;
  26346. }
  26347. #endif /* HAVE_ECC384 */
  26348. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  26349. /* KAT from RFC6979 */
  26350. static wc_test_ret_t ecc521_test_deterministic_k(WC_RNG* rng)
  26351. {
  26352. wc_test_ret_t ret;
  26353. #ifdef WOLFSSL_SMALL_STACK
  26354. ecc_key *key;
  26355. mp_int *r, *s, *expR, *expS;
  26356. #else
  26357. ecc_key key[1];
  26358. mp_int r[1], s[1], expR[1], expS[1];
  26359. #endif
  26360. int key_inited = 0,
  26361. tmp_mp_ints_inited = 0;
  26362. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26363. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26364. "0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75C"
  26365. "AA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83"
  26366. "538";
  26367. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26368. "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD3"
  26369. "71123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F502"
  26370. "3A4";
  26371. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26372. "0493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A2"
  26373. "8A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDF"
  26374. "CF5";
  26375. #ifndef NO_SHA256
  26376. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26377. "1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659"
  26378. "D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E"
  26379. "1A7";
  26380. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26381. "04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916"
  26382. "E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7E"
  26383. "CFC";
  26384. #endif
  26385. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26386. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26387. "1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4"
  26388. "B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67"
  26389. "451";
  26390. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26391. "1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5"
  26392. "FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65"
  26393. "D61";
  26394. #endif
  26395. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26396. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26397. "0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F1"
  26398. "74E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E37"
  26399. "7FA";
  26400. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26401. "0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF2"
  26402. "82623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A"
  26403. "67A";
  26404. #endif
  26405. #ifdef WOLFSSL_SMALL_STACK
  26406. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26407. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26408. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26409. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26410. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26411. if ((key == NULL) ||
  26412. (r == NULL) ||
  26413. (s == NULL) ||
  26414. (expR == NULL) ||
  26415. (expS == NULL))
  26416. {
  26417. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26418. goto done;
  26419. }
  26420. #endif
  26421. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26422. if (ret != MP_OKAY)
  26423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26424. tmp_mp_ints_inited = 1;
  26425. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26426. if (ret != 0)
  26427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26428. key_inited = 1;
  26429. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP521R1");
  26430. if (ret != 0)
  26431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26432. ret = wc_ecc_set_deterministic(key, 1);
  26433. if (ret != 0)
  26434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26435. #ifndef NO_SHA256
  26436. /* Test for SHA2-256 */
  26437. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26438. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26439. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26440. r, s, expR, expS);
  26441. if (ret != 0)
  26442. ERROR_OUT(ret, done);
  26443. #endif /* NO_SHA256 */
  26444. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26445. /* Test for SHA2-384 */
  26446. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26447. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26448. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26449. r, s, expR, expS);
  26450. if (ret != 0)
  26451. ERROR_OUT(ret, done);
  26452. #endif /* WOLFSSL_SHA384 */
  26453. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26454. /* Test for SHA2-512 */
  26455. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26456. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26457. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26458. r, s, expR, expS);
  26459. if (ret != 0)
  26460. ERROR_OUT(ret, done);
  26461. #endif /* WOLFSSL_SHA512 */
  26462. done:
  26463. if (key_inited)
  26464. wc_ecc_free(key);
  26465. if (tmp_mp_ints_inited) {
  26466. mp_free(r);
  26467. mp_free(s);
  26468. mp_free(expR);
  26469. mp_free(expS);
  26470. }
  26471. #ifdef WOLFSSL_SMALL_STACK
  26472. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26473. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26474. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26475. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26476. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26477. #endif
  26478. return ret;
  26479. }
  26480. #endif /* HAVE_ECC521 */
  26481. #endif /* WOLFSSL_PUBLIC_MP */
  26482. #endif /* HAVE_ECC_SIGN && (WOLFSSL_ECDSA_DETERMINISTIC_K ||
  26483. WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  26484. && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  26485. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  26486. !defined(WOLFSSL_KCAPI_ECC)
  26487. static wc_test_ret_t ecc_test_sign_vectors(WC_RNG* rng)
  26488. {
  26489. wc_test_ret_t ret;
  26490. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26491. ecc_key *key = NULL;
  26492. #else
  26493. ecc_key key[1];
  26494. #endif
  26495. int key_inited = 0;
  26496. byte sig[72];
  26497. word32 sigSz;
  26498. WOLFSSL_SMALL_STACK_STATIC const unsigned char hash[32] = "test wolfSSL deterministic sign";
  26499. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26500. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26501. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26502. WOLFSSL_SMALL_STACK_STATIC const byte k[1] = { 0x02 };
  26503. WOLFSSL_SMALL_STACK_STATIC const byte expSig[71] = {
  26504. 0x30, 0x45, 0x02, 0x20, 0x7c, 0xf2, 0x7b, 0x18,
  26505. 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03,
  26506. 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2,
  26507. 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc,
  26508. 0x47, 0x66, 0x99, 0x78, 0x02, 0x21, 0x00, 0xa8,
  26509. 0x43, 0xa0, 0xce, 0x6c, 0x5e, 0x17, 0x8a, 0x53,
  26510. 0x4d, 0xaf, 0xd2, 0x95, 0x78, 0x9f, 0x84, 0x4f,
  26511. 0x94, 0xb8, 0x75, 0xa3, 0x19, 0xa5, 0xd4, 0xdf,
  26512. 0xe1, 0xd4, 0x5e, 0x9d, 0x97, 0xfe, 0x81
  26513. };
  26514. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26515. if ((key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  26516. return MEMORY_E;
  26517. #endif
  26518. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26519. if (ret != 0)
  26520. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26521. key_inited = 1;
  26522. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26523. if (ret != 0)
  26524. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26525. #if (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) \
  26526. && (HAVE_FIPS_VERSION > 2)))
  26527. wc_ecc_set_flags(key, WC_ECC_FLAG_DEC_SIGN);
  26528. #endif
  26529. ret = wc_ecc_sign_set_k(k, sizeof(k), key);
  26530. if (ret != 0)
  26531. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26532. sigSz = sizeof(sig);
  26533. do {
  26534. #if defined(WOLFSSL_ASYNC_CRYPT)
  26535. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26536. #endif
  26537. if (ret == 0)
  26538. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26539. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26540. if (ret != 0)
  26541. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26542. TEST_SLEEP();
  26543. if (sigSz != sizeof(expSig)) {
  26544. ret = WC_TEST_RET_ENC_NC;
  26545. goto done;
  26546. }
  26547. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26548. ret = WC_TEST_RET_ENC_NC;
  26549. goto done;
  26550. }
  26551. sigSz = sizeof(sig);
  26552. do {
  26553. #if defined(WOLFSSL_ASYNC_CRYPT)
  26554. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26555. #endif
  26556. if (ret == 0)
  26557. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26558. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26559. if (ret != 0)
  26560. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26561. TEST_SLEEP();
  26562. done:
  26563. if (key_inited)
  26564. wc_ecc_free(key);
  26565. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26566. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26567. #endif
  26568. return ret;
  26569. }
  26570. #endif
  26571. #if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE)
  26572. static wc_test_ret_t ecc_test_cdh_vectors(WC_RNG* rng)
  26573. {
  26574. wc_test_ret_t ret;
  26575. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26576. ecc_key *pub_key = (ecc_key *)XMALLOC(sizeof *pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26577. ecc_key *priv_key = (ecc_key *)XMALLOC(sizeof *priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26578. #else
  26579. ecc_key pub_key[1], priv_key[1];
  26580. #endif
  26581. byte sharedA[32] = {0}, sharedB[32] = {0};
  26582. word32 x, z;
  26583. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287";
  26584. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac";
  26585. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26586. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26587. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26588. WOLFSSL_SMALL_STACK_STATIC const char* ZIUT = "46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b";
  26589. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26590. if ((pub_key == NULL) ||
  26591. (priv_key == NULL)) {
  26592. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26593. goto done;
  26594. }
  26595. #endif
  26596. XMEMSET(pub_key, 0, sizeof *pub_key);
  26597. XMEMSET(priv_key, 0, sizeof *priv_key);
  26598. /* setup private and public keys */
  26599. ret = wc_ecc_init_ex(pub_key, HEAP_HINT, devId);
  26600. if (ret != 0)
  26601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26602. ret = wc_ecc_init_ex(priv_key, HEAP_HINT, devId);
  26603. if (ret != 0)
  26604. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26605. wc_ecc_set_flags(pub_key, WC_ECC_FLAG_COFACTOR);
  26606. wc_ecc_set_flags(priv_key, WC_ECC_FLAG_COFACTOR);
  26607. ret = wc_ecc_import_raw(pub_key, QCAVSx, QCAVSy, NULL, "SECP256R1");
  26608. if (ret != 0)
  26609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26610. ret = wc_ecc_import_raw(priv_key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26611. if (ret != 0)
  26612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26613. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26614. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26615. !defined(HAVE_SELFTEST)
  26616. ret = wc_ecc_set_rng(priv_key, rng);
  26617. if (ret != 0)
  26618. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26619. #else
  26620. (void)rng;
  26621. #endif
  26622. /* compute ECC Cofactor shared secret */
  26623. x = sizeof(sharedA);
  26624. do {
  26625. #if defined(WOLFSSL_ASYNC_CRYPT)
  26626. ret = wc_AsyncWait(ret, &priv_key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26627. #endif
  26628. if (ret == 0)
  26629. ret = wc_ecc_shared_secret(priv_key, pub_key, sharedA, &x);
  26630. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26631. if (ret != 0)
  26632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26633. TEST_SLEEP();
  26634. /* read in expected Z */
  26635. z = sizeof(sharedB);
  26636. ret = Base16_Decode((const byte*)ZIUT, (word32)XSTRLEN(ZIUT), sharedB, &z);
  26637. if (ret != 0)
  26638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26639. /* compare results */
  26640. if (x != z || XMEMCMP(sharedA, sharedB, x)) {
  26641. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26642. }
  26643. done:
  26644. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26645. if (priv_key) {
  26646. wc_ecc_free(priv_key);
  26647. XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26648. }
  26649. if (pub_key) {
  26650. wc_ecc_free(pub_key);
  26651. XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26652. }
  26653. #else
  26654. wc_ecc_free(priv_key);
  26655. wc_ecc_free(pub_key);
  26656. #endif
  26657. return ret;
  26658. }
  26659. #endif /* HAVE_ECC_CDH && HAVE_ECC_DHE */
  26660. #endif /* HAVE_ECC_VECTOR_TEST */
  26661. #ifdef HAVE_ECC_KEY_IMPORT
  26662. /* returns 0 on success */
  26663. static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
  26664. {
  26665. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26666. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26667. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26668. ecc_key *pub = (ecc_key *)XMALLOC(sizeof *pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26669. #endif
  26670. byte *exportBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26671. byte *tmp = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26672. #else
  26673. ecc_key key[1];
  26674. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  26675. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26676. ecc_key pub[1];
  26677. #endif
  26678. byte exportBuf[ECC_BUFSIZE];
  26679. byte tmp[ECC_BUFSIZE];
  26680. #endif
  26681. const byte* msg = (const byte*)"test wolfSSL ECC public gen";
  26682. word32 x;
  26683. word32 tmpSz;
  26684. wc_test_ret_t ret = 0;
  26685. ecc_point* pubPoint = NULL;
  26686. #ifdef HAVE_ECC_VERIFY
  26687. int verify = 0;
  26688. #endif
  26689. #ifdef NO_ASN
  26690. /* private d for eccKeyDerFile / ecc_key_der_256 */
  26691. const byte keyPriv[] = {
  26692. 0x45, 0xB6, 0x69, 0x02, 0x73, 0x9C, 0x6C, 0x85,
  26693. 0xA1, 0x38, 0x5B, 0x72, 0xE8, 0xE8, 0xC7, 0xAC,
  26694. 0xC4, 0x03, 0x8D, 0x53, 0x35, 0x04, 0xFA, 0x6C,
  26695. 0x28, 0xDC, 0x34, 0x8D, 0xE1, 0xA8, 0x09, 0x8C
  26696. };
  26697. #endif
  26698. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26699. if ((key == NULL) ||
  26700. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26701. (pub == NULL) ||
  26702. #endif
  26703. (exportBuf == NULL) ||
  26704. (tmp == NULL))
  26705. ERROR_OUT(MEMORY_E, done);
  26706. #endif
  26707. (void)msg;
  26708. (void)verify;
  26709. (void)exportBuf;
  26710. (void)rng;
  26711. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26712. #ifndef NO_ECC256
  26713. #if defined(USE_CERT_BUFFERS_256)
  26714. {
  26715. XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
  26716. tmpSz = (size_t)sizeof_ecc_key_der_256;
  26717. }
  26718. #elif !defined(NO_FILESYSTEM)
  26719. {
  26720. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  26721. if (!file) {
  26722. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26723. }
  26724. tmpSz = (word32)XFREAD(tmp, 1, ECC_BUFSIZE, file);
  26725. XFCLOSE(file);
  26726. if (tmpSz == 0)
  26727. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26728. }
  26729. #else
  26730. {
  26731. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
  26732. ERROR_OUT(ASN_PARSE_E, done);
  26733. }
  26734. #endif /* USE_CERT_BUFFERS_256 */
  26735. /* import private only then test with */
  26736. ret = wc_ecc_import_private_key(tmp, tmpSz, NULL, 0, NULL);
  26737. if (ret == 0) {
  26738. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26739. }
  26740. ret = wc_ecc_import_private_key(NULL, tmpSz, NULL, 0, key);
  26741. if (ret == 0) {
  26742. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26743. }
  26744. #ifndef NO_ASN
  26745. x = 0;
  26746. ret = wc_EccPrivateKeyDecode(tmp, &x, key, tmpSz);
  26747. if (ret != 0)
  26748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26749. #ifdef HAVE_ECC_KEY_EXPORT
  26750. x = ECC_BUFSIZE;
  26751. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26752. if (ret != 0)
  26753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26754. /* make private only key */
  26755. wc_ecc_free(key);
  26756. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26757. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26758. if (ret != 0)
  26759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26760. x = ECC_BUFSIZE;
  26761. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26762. if (ret == 0) {
  26763. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26764. }
  26765. #endif /* HAVE_ECC_KEY_EXPORT */
  26766. #else
  26767. /* Load raw private d directly */
  26768. ret = wc_ecc_import_private_key(keyPriv, sizeof(keyPriv), NULL, 0, key);
  26769. #endif /* !NO_ASN */
  26770. ret = wc_ecc_make_pub(NULL, NULL);
  26771. if (ret == 0) {
  26772. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26773. }
  26774. TEST_SLEEP();
  26775. #ifndef WOLFSSL_NO_MALLOC
  26776. pubPoint = wc_ecc_new_point_h(HEAP_HINT);
  26777. if (pubPoint == NULL) {
  26778. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26779. }
  26780. #if !defined(WOLFSSL_CRYPTOCELL)
  26781. ret = wc_ecc_make_pub(key, pubPoint);
  26782. #if defined(WOLFSSL_ASYNC_CRYPT)
  26783. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26784. #endif
  26785. if (ret != 0)
  26786. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26787. #endif /* !WOLFSSL_CRYPTOCELL */
  26788. TEST_SLEEP();
  26789. #ifdef HAVE_ECC_KEY_EXPORT
  26790. /* export should still fail, is private only key */
  26791. x = ECC_BUFSIZE;
  26792. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26793. if (ret == 0) {
  26794. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26795. }
  26796. #endif /* HAVE_ECC_KEY_EXPORT */
  26797. #endif /* !WOLFSSL_NO_MALLOC */
  26798. #endif /* !NO_ECC256 */
  26799. /* create a new key since above test for loading key is not supported */
  26800. #if defined(WOLFSSL_CRYPTOCELL) || defined(NO_ECC256) || \
  26801. defined(WOLFSSL_QNX_CAAM) || defined(WOLFSSL_SE050) || \
  26802. defined(WOLFSSL_SECO_CAAM) || defined(WOLFSSL_IMXRT1170_CAAM)
  26803. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  26804. if (ret != 0)
  26805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26806. #endif
  26807. #if defined(HAVE_ECC_SIGN) && (!defined(ECC_TIMING_RESISTANT) || \
  26808. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG))) && \
  26809. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(HAVE_ECC_DETERMINISTIC_K)
  26810. tmpSz = ECC_BUFSIZE;
  26811. ret = 0;
  26812. do {
  26813. #if defined(WOLFSSL_ASYNC_CRYPT)
  26814. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26815. #endif
  26816. if (ret == 0) {
  26817. ret = wc_ecc_sign_hash(msg, (word32)XSTRLEN((const char* )msg), tmp,
  26818. &tmpSz, rng, key);
  26819. }
  26820. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26821. if (ret != 0)
  26822. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26823. TEST_SLEEP();
  26824. #ifdef HAVE_ECC_VERIFY
  26825. /* try verify with private only key */
  26826. ret = 0;
  26827. do {
  26828. #if defined(WOLFSSL_ASYNC_CRYPT)
  26829. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26830. #endif
  26831. if (ret == 0) {
  26832. ret = wc_ecc_verify_hash(tmp, tmpSz, msg,
  26833. (word32)XSTRLEN((const char*)msg), &verify, key);
  26834. }
  26835. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26836. if (ret != 0)
  26837. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26838. if (verify != 1) {
  26839. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26840. }
  26841. TEST_SLEEP();
  26842. #ifdef HAVE_ECC_KEY_EXPORT
  26843. /* exporting the public part should now work */
  26844. x = ECC_BUFSIZE;
  26845. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26846. if (ret != 0)
  26847. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26848. #endif /* HAVE_ECC_KEY_EXPORT */
  26849. #endif /* HAVE_ECC_VERIFY */
  26850. #endif /* HAVE_ECC_SIGN */
  26851. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  26852. /* now test private only key with creating a shared secret */
  26853. x = ECC_BUFSIZE;
  26854. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26855. if (ret != 0)
  26856. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26857. #if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SE050)
  26858. /* make private only key */
  26859. wc_ecc_free(key);
  26860. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26861. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26862. if (ret != 0)
  26863. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26864. /* check that public export fails with private only key */
  26865. x = ECC_BUFSIZE;
  26866. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26867. if (ret == 0) {
  26868. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26869. }
  26870. #endif /* WOLFSSL_QNX_CAAM */
  26871. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  26872. /* make public key for shared secret */
  26873. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  26874. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, pub);
  26875. #ifdef HAVE_ECC_CDH
  26876. wc_ecc_set_flags(key, WC_ECC_FLAG_COFACTOR);
  26877. #endif
  26878. #if defined(WOLFSSL_ASYNC_CRYPT)
  26879. ret = wc_AsyncWait(ret, &pub->asyncDev, WC_ASYNC_FLAG_NONE);
  26880. #endif
  26881. if (ret != 0)
  26882. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26883. TEST_SLEEP();
  26884. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26885. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26886. !defined(HAVE_SELFTEST)
  26887. ret = wc_ecc_set_rng(key, rng);
  26888. if (ret != 0)
  26889. goto done;
  26890. #endif
  26891. x = ECC_BUFSIZE;
  26892. do {
  26893. #if defined(WOLFSSL_ASYNC_CRYPT)
  26894. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26895. #endif
  26896. if (ret == 0) {
  26897. ret = wc_ecc_shared_secret(key, pub, exportBuf, &x);
  26898. }
  26899. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26900. wc_ecc_free(pub);
  26901. if (ret != 0)
  26902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26903. TEST_SLEEP();
  26904. #endif /* HAVE_ECC_DHE && HAVE_ECC_KEY_EXPORT && !WC_NO_RNG */
  26905. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26906. ret = 0;
  26907. done:
  26908. wc_ecc_del_point_h(pubPoint, HEAP_HINT);
  26909. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26910. if (key != NULL) {
  26911. wc_ecc_free(key);
  26912. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26913. }
  26914. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26915. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26916. #endif
  26917. XFREE(exportBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26918. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26919. #else
  26920. wc_ecc_free(key);
  26921. #endif
  26922. return ret;
  26923. }
  26924. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26925. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26926. static wc_test_ret_t ecc_test_key_decode(WC_RNG* rng, int keySize)
  26927. {
  26928. wc_test_ret_t ret;
  26929. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26930. ecc_key *eccKey = (ecc_key *)XMALLOC(sizeof *eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26931. byte *tmpBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26932. #else
  26933. ecc_key eccKey[1];
  26934. byte tmpBuf[ECC_BUFSIZE];
  26935. #endif
  26936. word32 tmpSz;
  26937. word32 idx;
  26938. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26939. if ((eccKey == NULL) || (tmpBuf == NULL))
  26940. ERROR_OUT(MEMORY_E, done);
  26941. #endif
  26942. ret = wc_ecc_init(eccKey);
  26943. if (ret != 0) {
  26944. goto done;
  26945. }
  26946. ret = wc_ecc_make_key(rng, keySize, eccKey);
  26947. #if defined(WOLFSSL_ASYNC_CRYPT)
  26948. ret = wc_AsyncWait(ret, &eccKey->asyncDev, WC_ASYNC_FLAG_NONE);
  26949. #endif
  26950. if (ret != 0) {
  26951. goto done;
  26952. }
  26953. tmpSz = ECC_BUFSIZE;
  26954. ret = wc_EccKeyToDer(eccKey, tmpBuf, tmpSz);
  26955. wc_ecc_free(eccKey);
  26956. if (ret < 0) {
  26957. goto done;
  26958. }
  26959. tmpSz = (word32)ret;
  26960. ret = wc_ecc_init(eccKey);
  26961. if (ret != 0) {
  26962. goto done;
  26963. }
  26964. idx = 0;
  26965. ret = wc_EccPrivateKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26966. if (ret != 0) {
  26967. goto done;
  26968. }
  26969. wc_ecc_free(eccKey);
  26970. ret = wc_ecc_init(eccKey);
  26971. if (ret != 0) {
  26972. goto done;
  26973. }
  26974. idx = 0;
  26975. ret = wc_EccPublicKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26976. if (ret != 0) {
  26977. goto done;
  26978. }
  26979. ret = 0;
  26980. done:
  26981. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26982. if (eccKey != NULL) {
  26983. wc_ecc_free(eccKey);
  26984. XFREE(eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26985. }
  26986. XFREE(tmpBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26987. #else
  26988. wc_ecc_free(eccKey);
  26989. #endif
  26990. return ret;
  26991. }
  26992. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26993. #endif /* HAVE_ECC_KEY_IMPORT */
  26994. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26995. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26996. static wc_test_ret_t ecc_test_key_gen(WC_RNG* rng, int keySize)
  26997. {
  26998. wc_test_ret_t ret = 0;
  26999. int derSz;
  27000. #ifdef HAVE_PKCS8
  27001. word32 pkcs8Sz;
  27002. #endif
  27003. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27004. byte *der = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27005. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27006. #else
  27007. byte der[ECC_BUFSIZE];
  27008. ecc_key userA[1];
  27009. #endif
  27010. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27011. if ((der == NULL) || (userA == NULL))
  27012. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  27013. #endif
  27014. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27015. if (ret != 0)
  27016. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27017. ret = wc_ecc_make_key(rng, keySize, userA);
  27018. #if defined(WOLFSSL_ASYNC_CRYPT)
  27019. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27020. #endif
  27021. if (ret != 0)
  27022. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27023. TEST_SLEEP();
  27024. ret = wc_ecc_check_key(userA);
  27025. if (ret != 0)
  27026. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27027. TEST_SLEEP();
  27028. derSz = wc_EccKeyToDer(userA, der, ECC_BUFSIZE);
  27029. if (derSz < 0) {
  27030. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27031. }
  27032. ret = SaveDerAndPem(der, derSz, eccCaKeyTempFile, eccCaKeyPemFile,
  27033. ECC_PRIVATEKEY_TYPE);
  27034. if (ret != 0)
  27035. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27036. /* test export of public key */
  27037. derSz = wc_EccPublicKeyToDer(userA, der, ECC_BUFSIZE, 1);
  27038. if (derSz < 0) {
  27039. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27040. }
  27041. if (derSz == 0) {
  27042. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27043. }
  27044. #ifdef HAVE_COMP_KEY
  27045. /* test export of compressed public key */
  27046. derSz = wc_EccPublicKeyToDer_ex(userA, der, ECC_BUFSIZE, 1, 1);
  27047. if (derSz < 0) {
  27048. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27049. }
  27050. if (derSz == 0) {
  27051. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27052. }
  27053. #endif
  27054. ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0);
  27055. if (ret != 0)
  27056. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27057. #ifdef HAVE_PKCS8
  27058. /* test export of PKCS#8 unencrypted private key */
  27059. pkcs8Sz = FOURK_BUF;
  27060. derSz = wc_EccPrivateKeyToPKCS8(userA, der, &pkcs8Sz);
  27061. if (derSz < 0) {
  27062. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27063. }
  27064. if (derSz == 0) {
  27065. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27066. }
  27067. ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0);
  27068. if (ret != 0) {
  27069. goto done;
  27070. }
  27071. #endif /* HAVE_PKCS8 */
  27072. done:
  27073. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27074. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27075. if (userA != NULL) {
  27076. wc_ecc_free(userA);
  27077. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27078. }
  27079. #else
  27080. wc_ecc_free(userA);
  27081. #endif
  27082. return ret;
  27083. }
  27084. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  27085. static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
  27086. int curve_id, const ecc_set_type* dp)
  27087. {
  27088. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27089. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27090. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27091. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27092. word32 y;
  27093. #endif
  27094. #ifdef HAVE_ECC_KEY_EXPORT
  27095. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  27096. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27097. #endif
  27098. word32 x = 0;
  27099. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27100. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27101. defined(HAVE_ECC_SIGN)
  27102. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27103. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27104. int i;
  27105. #ifdef HAVE_ECC_VERIFY
  27106. int verify;
  27107. #endif /* HAVE_ECC_VERIFY */
  27108. #endif /* HAVE_ECC_SIGN */
  27109. wc_test_ret_t ret;
  27110. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27111. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27112. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27113. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27114. #else
  27115. ecc_key userA[1];
  27116. ecc_key userB[1];
  27117. ecc_key pubKey[1];
  27118. #endif
  27119. #ifndef WC_NO_RNG
  27120. int curveSize;
  27121. #endif
  27122. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27123. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27124. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27125. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27126. #endif
  27127. #ifdef HAVE_ECC_KEY_EXPORT
  27128. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27129. #endif
  27130. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27131. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27132. defined(HAVE_ECC_SIGN)
  27133. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27134. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27135. #endif
  27136. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  27137. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \
  27138. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27139. if (sharedA == NULL || sharedB == NULL)
  27140. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27141. #endif
  27142. #ifdef HAVE_ECC_KEY_EXPORT
  27143. if (exportBuf == NULL)
  27144. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27145. #endif
  27146. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27147. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27148. defined(HAVE_ECC_SIGN)
  27149. if (sig == NULL || digest == NULL)
  27150. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27151. #endif
  27152. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  27153. (void)testVerifyCount;
  27154. (void)dp;
  27155. (void)x;
  27156. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27157. if ((userA == NULL) ||
  27158. (userB == NULL) ||
  27159. (pubKey == NULL))
  27160. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27161. #endif
  27162. XMEMSET(userA, 0, sizeof *userA);
  27163. XMEMSET(userB, 0, sizeof *userB);
  27164. XMEMSET(pubKey, 0, sizeof *pubKey);
  27165. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27166. if (ret != 0)
  27167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27168. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  27169. if (ret != 0)
  27170. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27171. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27172. if (ret != 0)
  27173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27174. #ifdef WOLFSSL_CUSTOM_CURVES
  27175. if (dp != NULL) {
  27176. ret = wc_ecc_set_custom_curve(userA, dp);
  27177. if (ret != 0)
  27178. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27179. ret = wc_ecc_set_custom_curve(userB, dp);
  27180. if (ret != 0)
  27181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27182. }
  27183. #endif
  27184. #ifndef WC_NO_RNG
  27185. ret = wc_ecc_make_key_ex(rng, keySize, userA, curve_id);
  27186. #if defined(WOLFSSL_ASYNC_CRYPT)
  27187. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27188. #endif
  27189. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  27190. if (ret == WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  27191. ret = 0;
  27192. goto done; /* no software case */
  27193. }
  27194. #endif
  27195. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  27196. goto done; /* catch case, where curve is not supported */
  27197. if (ret != 0)
  27198. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27199. TEST_SLEEP();
  27200. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  27201. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  27202. if (curveSize != userA->dp->size)
  27203. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27204. }
  27205. ret = wc_ecc_check_key(userA);
  27206. if (ret != 0)
  27207. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27208. TEST_SLEEP();
  27209. /* ATECC508/608 configuration may not support more than one ECDH key */
  27210. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27211. ret = wc_ecc_make_key_ex(rng, keySize, userB, curve_id);
  27212. #if defined(WOLFSSL_ASYNC_CRYPT)
  27213. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  27214. #endif
  27215. if (ret != 0)
  27216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27217. TEST_SLEEP();
  27218. /* only perform the below tests if the key size matches */
  27219. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  27220. /* Not an error, just not a key size match */
  27221. WARNING_OUT(ECC_CURVE_OID_E, done);
  27222. #ifdef HAVE_ECC_DHE
  27223. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27224. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27225. !defined(HAVE_SELFTEST)
  27226. ret = wc_ecc_set_rng(userA, rng);
  27227. if (ret != 0)
  27228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27229. ret = wc_ecc_set_rng(userB, rng);
  27230. if (ret != 0)
  27231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27232. #endif
  27233. x = ECC_SHARED_SIZE;
  27234. do {
  27235. #if defined(WOLFSSL_ASYNC_CRYPT)
  27236. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27237. #endif
  27238. if (ret == 0)
  27239. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27240. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27241. if (ret != 0)
  27242. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27243. TEST_SLEEP();
  27244. y = ECC_SHARED_SIZE;
  27245. do {
  27246. #if defined(WOLFSSL_ASYNC_CRYPT)
  27247. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27248. #endif
  27249. if (ret == 0)
  27250. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27251. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27252. if (ret != 0)
  27253. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27254. if (y != x)
  27255. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27256. if (XMEMCMP(sharedA, sharedB, x))
  27257. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27258. TEST_SLEEP();
  27259. #ifdef HAVE_ECC_CDH
  27260. /* add cofactor flag */
  27261. wc_ecc_set_flags(userA, WC_ECC_FLAG_COFACTOR);
  27262. wc_ecc_set_flags(userB, WC_ECC_FLAG_COFACTOR);
  27263. x = ECC_SHARED_SIZE;
  27264. do {
  27265. #if defined(WOLFSSL_ASYNC_CRYPT)
  27266. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27267. #endif
  27268. if (ret == 0)
  27269. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27270. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27271. if (ret != 0)
  27272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27273. TEST_SLEEP();
  27274. y = ECC_SHARED_SIZE;
  27275. do {
  27276. #if defined(WOLFSSL_ASYNC_CRYPT)
  27277. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27278. #endif
  27279. if (ret == 0)
  27280. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27281. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27282. if (ret != 0)
  27283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27284. if (y != x)
  27285. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27286. if (XMEMCMP(sharedA, sharedB, x))
  27287. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27288. TEST_SLEEP();
  27289. /* remove cofactor flag */
  27290. wc_ecc_set_flags(userA, 0);
  27291. wc_ecc_set_flags(userB, 0);
  27292. #endif /* HAVE_ECC_CDH */
  27293. #endif /* HAVE_ECC_DHE */
  27294. #endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */
  27295. #ifdef HAVE_ECC_KEY_EXPORT
  27296. x = ECC_KEY_EXPORT_BUF_SIZE;
  27297. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  27298. if (ret != 0)
  27299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27300. #ifdef HAVE_ECC_KEY_IMPORT
  27301. #ifdef WOLFSSL_CUSTOM_CURVES
  27302. if (dp != NULL) {
  27303. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27304. if (ret != 0)
  27305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27306. }
  27307. #endif
  27308. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27309. if (ret != 0)
  27310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27311. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27312. #ifdef HAVE_ECC_DHE
  27313. y = ECC_SHARED_SIZE;
  27314. do {
  27315. #if defined(WOLFSSL_ASYNC_CRYPT)
  27316. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27317. #endif
  27318. if (ret == 0)
  27319. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27320. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27321. if (ret != 0)
  27322. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27323. if (XMEMCMP(sharedA, sharedB, y))
  27324. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27325. TEST_SLEEP();
  27326. #endif /* HAVE_ECC_DHE */
  27327. #ifdef HAVE_COMP_KEY
  27328. /* try compressed export / import too */
  27329. x = ECC_KEY_EXPORT_BUF_SIZE;
  27330. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  27331. if (ret != 0)
  27332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27333. wc_ecc_free(pubKey);
  27334. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27335. if (ret != 0)
  27336. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27337. #ifdef WOLFSSL_CUSTOM_CURVES
  27338. if (dp != NULL) {
  27339. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27340. if (ret != 0)
  27341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27342. }
  27343. #endif
  27344. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27345. if (ret != 0)
  27346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27347. #ifdef HAVE_ECC_DHE
  27348. y = ECC_SHARED_SIZE;
  27349. do {
  27350. #if defined(WOLFSSL_ASYNC_CRYPT)
  27351. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27352. #endif
  27353. if (ret == 0)
  27354. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27355. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27356. if (ret != 0)
  27357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27358. if (XMEMCMP(sharedA, sharedB, y))
  27359. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27360. TEST_SLEEP();
  27361. #endif /* HAVE_ECC_DHE */
  27362. #endif /* HAVE_COMP_KEY */
  27363. #endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A */
  27364. #endif /* !WC_NO_RNG */
  27365. #endif /* HAVE_ECC_KEY_IMPORT */
  27366. #endif /* HAVE_ECC_KEY_EXPORT */
  27367. /* For KCAPI cannot sign using generated ECDH key */
  27368. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27369. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC))
  27370. #ifdef HAVE_ECC_SIGN
  27371. /* some hardware doesn't support sign/verify of all zero digest */
  27372. #if !defined(WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST)
  27373. /* test DSA sign hash with zeros */
  27374. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27375. digest[i] = 0;
  27376. }
  27377. x = ECC_SIG_SIZE;
  27378. do {
  27379. #if defined(WOLFSSL_ASYNC_CRYPT)
  27380. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27381. #endif
  27382. if (ret == 0)
  27383. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng,
  27384. userA);
  27385. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27386. if (ret != 0)
  27387. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27388. TEST_SLEEP();
  27389. #ifdef HAVE_ECC_VERIFY
  27390. for (i=0; i<testVerifyCount; i++) {
  27391. verify = 0;
  27392. do {
  27393. #if defined(WOLFSSL_ASYNC_CRYPT)
  27394. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27395. #endif
  27396. if (ret == 0)
  27397. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE,
  27398. &verify, userA);
  27399. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27400. if (ret != 0)
  27401. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27402. if (verify != 1)
  27403. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27404. TEST_SLEEP();
  27405. }
  27406. #endif /* HAVE_ECC_VERIFY */
  27407. #endif /* !WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST */
  27408. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  27409. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27410. digest[i] = (byte)i;
  27411. }
  27412. x = ECC_SIG_SIZE;
  27413. do {
  27414. #if defined(WOLFSSL_ASYNC_CRYPT)
  27415. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27416. #endif
  27417. if (ret == 0)
  27418. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  27419. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27420. if (ret != 0)
  27421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27422. TEST_SLEEP();
  27423. #ifdef HAVE_ECC_VERIFY
  27424. for (i=0; i<testVerifyCount; i++) {
  27425. verify = 0;
  27426. do {
  27427. #if defined(WOLFSSL_ASYNC_CRYPT)
  27428. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27429. #endif
  27430. if (ret == 0)
  27431. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, userA);
  27432. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27433. if (ret != 0)
  27434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27435. if (verify != 1)
  27436. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27437. TEST_SLEEP();
  27438. }
  27439. #endif /* HAVE_ECC_VERIFY */
  27440. #endif /* HAVE_ECC_SIGN */
  27441. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT &&
  27442. * !WC_NO_RNG && !WOLFSSL_KCAPI_ECC) */
  27443. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  27444. !defined(WOLFSSL_ATECC508) && !defined(WOLFSSL_ATECC608A) && \
  27445. !defined(WOLFSSL_KCAPI_ECC)
  27446. x = ECC_KEY_EXPORT_BUF_SIZE;
  27447. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  27448. if (ret != 0)
  27449. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27450. #elif defined(HAVE_ECC_KEY_EXPORT)
  27451. (void)exportBuf;
  27452. #endif /* HAVE_ECC_KEY_EXPORT */
  27453. done:
  27454. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27455. if (userA != NULL) {
  27456. wc_ecc_free(userA);
  27457. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27458. }
  27459. if (userB != NULL) {
  27460. wc_ecc_free(userB);
  27461. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27462. }
  27463. if (pubKey != NULL) {
  27464. wc_ecc_free(pubKey);
  27465. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27466. }
  27467. #else
  27468. wc_ecc_free(pubKey);
  27469. wc_ecc_free(userB);
  27470. wc_ecc_free(userA);
  27471. #endif
  27472. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  27473. WC_FREE_VAR(sharedA, HEAP_HINT);
  27474. WC_FREE_VAR(sharedB, HEAP_HINT);
  27475. #endif
  27476. #ifdef HAVE_ECC_KEY_EXPORT
  27477. WC_FREE_VAR(exportBuf, HEAP_HINT);
  27478. #endif
  27479. #ifdef HAVE_ECC_SIGN
  27480. WC_FREE_VAR(sig, HEAP_HINT);
  27481. WC_FREE_VAR(digest, HEAP_HINT);
  27482. #endif
  27483. (void)keySize;
  27484. (void)curve_id;
  27485. (void)rng;
  27486. return ret;
  27487. }
  27488. #undef ECC_TEST_VERIFY_COUNT
  27489. #define ECC_TEST_VERIFY_COUNT 2
  27490. static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
  27491. {
  27492. wc_test_ret_t ret;
  27493. WOLFSSL_MSG_EX("ecc_test_curve keySize = %d", keySize);
  27494. #if FIPS_VERSION3_GE(6,0,0)
  27495. #ifdef DEBUG_WOLFSSL
  27496. printf("keySize is %d\n", keySize);
  27497. #endif
  27498. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27499. goto skip_A;
  27500. }
  27501. #endif
  27502. ret = ecc_test_curve_size(rng, keySize, ECC_TEST_VERIFY_COUNT, curve_id,
  27503. NULL);
  27504. if (ret < 0) {
  27505. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27506. /* ignore error for curves not found */
  27507. /* some curve sizes are only available with:
  27508. HAVE_ECC_SECPR2, HAVE_ECC_SECPR3, HAVE_ECC_BRAINPOOL
  27509. and HAVE_ECC_KOBLITZ */
  27510. }
  27511. else {
  27512. printf("ecc_test_curve_size %d failed!\n", keySize);
  27513. return ret;
  27514. }
  27515. }
  27516. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27517. #if FIPS_VERSION3_GE(6,0,0)
  27518. skip_A:
  27519. #endif
  27520. #ifdef HAVE_ECC_VECTOR_TEST
  27521. ret = ecc_test_vector(keySize);
  27522. if (ret < 0) {
  27523. printf("ecc_test_vector %d failed!\n", keySize);
  27524. return ret;
  27525. }
  27526. #endif
  27527. #if FIPS_VERSION3_GE(6,0,0)
  27528. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27529. goto skip_B;
  27530. }
  27531. #endif
  27532. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27533. !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27534. ret = ecc_test_key_decode(rng, keySize);
  27535. if (ret < 0) {
  27536. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27537. /* ignore error for curves not found */
  27538. }
  27539. else {
  27540. printf("ecc_test_key_decode %d failed!\n", keySize);
  27541. return ret;
  27542. }
  27543. }
  27544. #endif
  27545. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27546. ret = ecc_test_key_gen(rng, keySize);
  27547. if (ret < 0) {
  27548. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27549. /* ignore error for curves not found */
  27550. }
  27551. else {
  27552. printf("ecc_test_key_gen %d failed!\n", keySize);
  27553. return ret;
  27554. }
  27555. }
  27556. #endif
  27557. #if FIPS_VERSION3_GE(6,0,0)
  27558. skip_B:
  27559. #endif
  27560. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  27561. return 0;
  27562. }
  27563. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  27564. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  27565. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27566. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27567. static wc_test_ret_t ecc_point_test(void)
  27568. {
  27569. wc_test_ret_t ret;
  27570. ecc_point* point;
  27571. ecc_point* point2;
  27572. #ifdef HAVE_COMP_KEY
  27573. ecc_point* point3;
  27574. ecc_point* point4;
  27575. #endif
  27576. word32 outLen;
  27577. byte out[65];
  27578. byte der[] = { 0x04, /* = Uncompressed */
  27579. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27580. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27581. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27582. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27583. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27584. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27585. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27586. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27587. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27588. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27589. byte derComp0[] = { 0x02, /* = Compressed, y even */
  27590. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27591. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27592. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27593. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27594. byte derComp1[] = { 0x03, /* = Compressed, y odd */
  27595. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27596. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27597. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27598. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27599. #endif
  27600. byte altDer[] = { 0x04, /* = Uncompressed */
  27601. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27602. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27603. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27604. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27605. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27606. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27607. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27608. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  27609. int curve_idx = wc_ecc_get_curve_idx(ECC_SECP256R1);
  27610. /* if curve P256 is not enabled then test should not fail */
  27611. if (curve_idx == ECC_CURVE_INVALID)
  27612. return 0;
  27613. outLen = sizeof(out);
  27614. point = wc_ecc_new_point();
  27615. if (point == NULL)
  27616. return WC_TEST_RET_ENC_ERRNO;
  27617. point2 = wc_ecc_new_point();
  27618. if (point2 == NULL) {
  27619. wc_ecc_del_point(point);
  27620. return WC_TEST_RET_ENC_NC;
  27621. }
  27622. #ifdef HAVE_COMP_KEY
  27623. point3 = wc_ecc_new_point();
  27624. if (point3 == NULL) {
  27625. wc_ecc_del_point(point2);
  27626. wc_ecc_del_point(point);
  27627. return WC_TEST_RET_ENC_NC;
  27628. }
  27629. point4 = wc_ecc_new_point();
  27630. if (point4 == NULL) {
  27631. wc_ecc_del_point(point3);
  27632. wc_ecc_del_point(point2);
  27633. wc_ecc_del_point(point);
  27634. return WC_TEST_RET_ENC_NC;
  27635. }
  27636. #endif
  27637. /* Parameter Validation testing. */
  27638. wc_ecc_del_point(NULL);
  27639. ret = wc_ecc_import_point_der(NULL, sizeof(der), curve_idx, point);
  27640. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27641. ret = WC_TEST_RET_ENC_EC(ret);
  27642. goto done;
  27643. }
  27644. ret = wc_ecc_import_point_der(der, sizeof(der), ECC_CURVE_INVALID, point);
  27645. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27646. ret = WC_TEST_RET_ENC_EC(ret);
  27647. goto done;
  27648. }
  27649. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, NULL);
  27650. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27651. ret = WC_TEST_RET_ENC_EC(ret);
  27652. goto done;
  27653. }
  27654. ret = wc_ecc_export_point_der(-1, point, out, &outLen);
  27655. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27656. ret = WC_TEST_RET_ENC_EC(ret);
  27657. goto done;
  27658. }
  27659. ret = wc_ecc_export_point_der(curve_idx, NULL, out, &outLen);
  27660. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27661. ret = WC_TEST_RET_ENC_EC(ret);
  27662. goto done;
  27663. }
  27664. ret = wc_ecc_export_point_der(curve_idx, point, NULL, &outLen);
  27665. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || outLen != sizeof(out)) {
  27666. ret = WC_TEST_RET_ENC_EC(ret);
  27667. goto done;
  27668. }
  27669. ret = wc_ecc_export_point_der(curve_idx, point, out, NULL);
  27670. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27671. ret = WC_TEST_RET_ENC_EC(ret);
  27672. goto done;
  27673. }
  27674. outLen = 0;
  27675. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27676. if (ret != WC_NO_ERR_TRACE(BUFFER_E)) {
  27677. ret = WC_TEST_RET_ENC_EC(ret);
  27678. goto done;
  27679. }
  27680. ret = wc_ecc_copy_point(NULL, NULL);
  27681. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27682. ret = WC_TEST_RET_ENC_EC(ret);
  27683. goto done;
  27684. }
  27685. ret = wc_ecc_copy_point(NULL, point2);
  27686. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27687. ret = WC_TEST_RET_ENC_EC(ret);
  27688. goto done;
  27689. }
  27690. ret = wc_ecc_copy_point(point, NULL);
  27691. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27692. ret = WC_TEST_RET_ENC_EC(ret);
  27693. goto done;
  27694. }
  27695. ret = wc_ecc_cmp_point(NULL, NULL);
  27696. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27697. ret = WC_TEST_RET_ENC_EC(ret);
  27698. goto done;
  27699. }
  27700. ret = wc_ecc_cmp_point(NULL, point2);
  27701. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27702. ret = WC_TEST_RET_ENC_EC(ret);
  27703. goto done;
  27704. }
  27705. ret = wc_ecc_cmp_point(point, NULL);
  27706. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27707. ret = WC_TEST_RET_ENC_EC(ret);
  27708. goto done;
  27709. }
  27710. /* Use API. */
  27711. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, point);
  27712. if (ret != 0)
  27713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27714. outLen = sizeof(out);
  27715. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27716. if (ret != 0)
  27717. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27718. if (outLen != sizeof(der)) {
  27719. ret = WC_TEST_RET_ENC_NC;
  27720. goto done;
  27721. }
  27722. if (XMEMCMP(out, der, outLen) != 0) {
  27723. ret = WC_TEST_RET_ENC_NC;
  27724. goto done;
  27725. }
  27726. ret = wc_ecc_copy_point(point2, point);
  27727. if (ret != MP_OKAY) {
  27728. ret = WC_TEST_RET_ENC_EC(ret);
  27729. goto done;
  27730. }
  27731. ret = wc_ecc_cmp_point(point2, point);
  27732. if (ret != MP_EQ) {
  27733. ret = WC_TEST_RET_ENC_EC(ret);
  27734. goto done;
  27735. }
  27736. ret = wc_ecc_import_point_der(altDer, sizeof(altDer), curve_idx, point2);
  27737. if (ret != 0)
  27738. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27739. ret = wc_ecc_cmp_point(point2, point);
  27740. if (ret != MP_GT) {
  27741. ret = WC_TEST_RET_ENC_EC(ret);
  27742. goto done;
  27743. }
  27744. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27745. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27746. ret = wc_ecc_import_point_der(derComp0, sizeof(derComp0)*2-1, curve_idx, point3);
  27747. if (ret != 0)
  27748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27749. ret = wc_ecc_import_point_der_ex(derComp0, sizeof(derComp0), curve_idx, point4, 0);
  27750. if (ret != 0)
  27751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27752. ret = wc_ecc_cmp_point(point3, point4);
  27753. if (ret != MP_EQ) {
  27754. ret = WC_TEST_RET_ENC_EC(ret);
  27755. goto done;
  27756. }
  27757. ret = wc_ecc_import_point_der(derComp1, sizeof(derComp1)*2-1, curve_idx, point3);
  27758. if (ret != 0)
  27759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27760. ret = wc_ecc_import_point_der_ex(derComp1, sizeof(derComp1), curve_idx, point4, 0);
  27761. if (ret != 0)
  27762. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27763. ret = wc_ecc_cmp_point(point3, point4);
  27764. if (ret != MP_EQ) {
  27765. ret = WC_TEST_RET_ENC_EC(ret);
  27766. goto done;
  27767. }
  27768. #endif
  27769. done:
  27770. #ifdef HAVE_COMP_KEY
  27771. wc_ecc_del_point(point4);
  27772. wc_ecc_del_point(point3);
  27773. #endif
  27774. wc_ecc_del_point(point2);
  27775. wc_ecc_del_point(point);
  27776. return ret;
  27777. }
  27778. #endif /* !WOLFSSL_ATECC508A && HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27779. #if !defined(NO_SIG_WRAPPER) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27780. static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key)
  27781. {
  27782. wc_test_ret_t ret;
  27783. word32 sigSz;
  27784. int size;
  27785. byte out[ECC_MAX_SIG_SIZE];
  27786. byte in[] = TEST_STRING;
  27787. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  27788. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  27789. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  27790. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  27791. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  27792. };
  27793. word32 inLen = (word32)XSTRLEN((char*)in);
  27794. size = wc_ecc_sig_size(key);
  27795. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, sizeof(*key));
  27796. if (ret != size)
  27797. return WC_TEST_RET_ENC_NC;
  27798. sigSz = (word32)ret;
  27799. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27800. inLen, out, &sigSz, key, sizeof(*key), rng);
  27801. if (ret != 0)
  27802. return WC_TEST_RET_ENC_EC(ret);
  27803. TEST_SLEEP();
  27804. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27805. inLen, out, sigSz, key, sizeof(*key));
  27806. if (ret != 0)
  27807. return WC_TEST_RET_ENC_EC(ret);
  27808. TEST_SLEEP();
  27809. sigSz = (word32)sizeof(out);
  27810. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27811. hash, (int)sizeof(hash), out, &sigSz, key, sizeof(*key), rng);
  27812. if (ret != 0)
  27813. return WC_TEST_RET_ENC_EC(ret);
  27814. TEST_SLEEP();
  27815. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27816. hash, (int)sizeof(hash), out, sigSz, key, sizeof(*key));
  27817. if (ret != 0)
  27818. return WC_TEST_RET_ENC_EC(ret);
  27819. TEST_SLEEP();
  27820. return 0;
  27821. }
  27822. #endif
  27823. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27824. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27825. static wc_test_ret_t ecc_exp_imp_test(ecc_key* key)
  27826. {
  27827. wc_test_ret_t ret;
  27828. int curve_id;
  27829. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27830. ecc_key *keyImp = (ecc_key *)XMALLOC(sizeof *keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27831. #else
  27832. ecc_key keyImp[1];
  27833. #endif
  27834. byte priv[32];
  27835. word32 privLen;
  27836. byte pub[65*2];
  27837. word32 pubLen, pubLenX, pubLenY;
  27838. const char qx[] = "7a4e287890a1a47ad3457e52f2f76a83"
  27839. "ce46cbc947616d0cbaa82323818a793d";
  27840. const char qy[] = "eec4084f5b29ebf29c44cce3b3059610"
  27841. "922f8b30ea6e8811742ac7238fe87308";
  27842. const char d[] = "8c14b793cb19137e323a6d2e2a870bca"
  27843. "2e7a493ec1153b3a95feb8a4873f8d08";
  27844. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27845. if (keyImp == NULL)
  27846. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27847. #endif
  27848. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27849. privLen = sizeof(priv);
  27850. ret = wc_ecc_export_private_only(key, priv, &privLen);
  27851. if (ret != 0)
  27852. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27853. pubLen = sizeof(pub);
  27854. ret = wc_ecc_export_point_der(key->idx, &key->pubkey, pub, &pubLen);
  27855. if (ret != 0)
  27856. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27857. ret = wc_ecc_import_private_key(priv, privLen, pub, pubLen, keyImp);
  27858. if (ret != 0)
  27859. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27860. wc_ecc_free(keyImp);
  27861. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27862. ret = wc_ecc_import_raw_ex(keyImp, qx, qy, d, ECC_SECP256R1);
  27863. if (ret != 0)
  27864. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27865. wc_ecc_free(keyImp);
  27866. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27867. curve_id = wc_ecc_get_curve_id(key->idx);
  27868. if (curve_id < 0) {
  27869. ret = WC_TEST_RET_ENC_EC(curve_id);
  27870. goto done;
  27871. }
  27872. /* test import private only */
  27873. ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, keyImp,
  27874. curve_id);
  27875. if (ret != 0)
  27876. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27877. wc_ecc_free(keyImp);
  27878. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27879. /* test export public raw */
  27880. pubLenX = pubLenY = 32;
  27881. ret = wc_ecc_export_public_raw(key, pub, &pubLenX, &pub[32], &pubLenY);
  27882. if (ret != 0)
  27883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27884. #ifndef HAVE_SELFTEST
  27885. /* test import of public */
  27886. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], NULL, ECC_SECP256R1);
  27887. if (ret != 0)
  27888. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27889. #endif
  27890. wc_ecc_free(keyImp);
  27891. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27892. /* test export private and public raw */
  27893. pubLenX = pubLenY = privLen = 32;
  27894. ret = wc_ecc_export_private_raw(key, pub, &pubLenX, &pub[32], &pubLenY,
  27895. priv, &privLen);
  27896. if (ret != 0)
  27897. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27898. #ifndef HAVE_SELFTEST
  27899. /* test import of private and public */
  27900. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], priv, ECC_SECP256R1);
  27901. if (ret != 0)
  27902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27903. #endif
  27904. done:
  27905. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27906. if (keyImp != NULL) {
  27907. wc_ecc_free(keyImp);
  27908. XFREE(keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27909. }
  27910. #else
  27911. wc_ecc_free(keyImp);
  27912. #endif
  27913. return ret;
  27914. }
  27915. #endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27916. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  27917. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27918. static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
  27919. {
  27920. wc_test_ret_t ret;
  27921. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27922. ecc_key *key2 = (ecc_key *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27923. ecc_key *key3 = (ecc_key *)XMALLOC(sizeof *key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27924. #else
  27925. ecc_key key2[1];
  27926. ecc_key key3[1];
  27927. #endif
  27928. #ifdef WOLFSSL_PUBLIC_MP
  27929. mp_int* priv;
  27930. #endif
  27931. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27932. if ((key2 == NULL) || (key3 == NULL))
  27933. ERROR_OUT(MEMORY_E, done);
  27934. #endif
  27935. wc_ecc_init_ex(key2, HEAP_HINT, devId);
  27936. wc_ecc_init_ex(key3, HEAP_HINT, devId);
  27937. /* TODO: Use test data, test with WOLFSSL_VALIDATE_ECC_IMPORT. */
  27938. /* Need base point (Gx,Gy) and parameter A - load them as the public and
  27939. * private key in key2.
  27940. */
  27941. ret = wc_ecc_import_raw_ex(key2, key1->dp->Gx, key1->dp->Gy, key1->dp->Af,
  27942. ECC_SECP256R1);
  27943. if (ret != 0)
  27944. goto done;
  27945. /* Need a point (Gx,Gy) and prime - load them as the public and private key
  27946. * in key3.
  27947. */
  27948. ret = wc_ecc_import_raw_ex(key3, key1->dp->Gx, key1->dp->Gy,
  27949. key1->dp->prime, ECC_SECP256R1);
  27950. if (ret != 0)
  27951. goto done;
  27952. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27953. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27954. 1);
  27955. if (ret != 0)
  27956. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27957. #ifdef WOLFSSL_PUBLIC_MP
  27958. priv = wc_ecc_key_get_priv(key1);
  27959. mp_zero(priv);
  27960. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27961. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27962. 1);
  27963. if (ret != 0)
  27964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27965. if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
  27966. ret = WC_TEST_RET_ENC_EC(ret);
  27967. goto done;
  27968. }
  27969. if (mp_cmp_d(key3->pubkey.z, 1) != MP_EQ) {
  27970. ret = WC_TEST_RET_ENC_EC(ret);
  27971. goto done;
  27972. }
  27973. #endif
  27974. done:
  27975. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27976. if (key2 != NULL) {
  27977. wc_ecc_free(key2);
  27978. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27979. }
  27980. if (key3 != NULL) {
  27981. wc_ecc_free(key3);
  27982. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27983. }
  27984. #else
  27985. wc_ecc_free(key3);
  27986. wc_ecc_free(key2);
  27987. #endif
  27988. return ret;
  27989. }
  27990. #endif
  27991. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27992. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_ATECC508A) && \
  27993. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  27994. !defined(WOLFSSL_CRYPTOCELL)
  27995. static wc_test_ret_t ecc_ssh_test(ecc_key* key, WC_RNG* rng)
  27996. {
  27997. wc_test_ret_t ret;
  27998. byte out[128];
  27999. word32 outLen = sizeof(out);
  28000. /* Parameter Validation testing. */
  28001. ret = wc_ecc_shared_secret_ssh(NULL, &key->pubkey, out, &outLen);
  28002. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28003. return WC_TEST_RET_ENC_EC(ret);
  28004. ret = wc_ecc_shared_secret_ssh(key, NULL, 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, &key->pubkey, NULL, &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, out, NULL);
  28011. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28012. return WC_TEST_RET_ENC_EC(ret);
  28013. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  28014. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  28015. !defined(HAVE_SELFTEST)
  28016. ret = wc_ecc_set_rng(key, rng);
  28017. if (ret != 0)
  28018. return WC_TEST_RET_ENC_EC(ret);
  28019. #else
  28020. (void)rng;
  28021. #endif
  28022. /* Use API. */
  28023. ret = 0;
  28024. do {
  28025. #if defined(WOLFSSL_ASYNC_CRYPT)
  28026. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  28027. #endif
  28028. if (ret == 0)
  28029. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen);
  28030. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  28031. if (ret != 0)
  28032. return WC_TEST_RET_ENC_EC(ret);
  28033. TEST_SLEEP();
  28034. return 0;
  28035. }
  28036. #endif /* HAVE_ECC_DHE && !WC_NO_RNG */
  28037. static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
  28038. {
  28039. wc_test_ret_t ret;
  28040. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28041. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28042. #else
  28043. ecc_key key[1];
  28044. #endif
  28045. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28046. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28047. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28048. word32 idx = 0;
  28049. #endif
  28050. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28051. if (key == NULL)
  28052. ERROR_OUT(MEMORY_E, done);
  28053. #endif
  28054. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28055. /* Use API */
  28056. ret = wc_ecc_set_flags(NULL, 0);
  28057. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28058. ret = WC_TEST_RET_ENC_EC(ret);
  28059. goto done;
  28060. }
  28061. ret = wc_ecc_set_flags(key, 0);
  28062. if (ret != 0)
  28063. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28064. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  28065. #ifndef WC_NO_RNG
  28066. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  28067. #if defined(WOLFSSL_ASYNC_CRYPT)
  28068. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  28069. #endif
  28070. if (ret != 0) {
  28071. goto done;
  28072. }
  28073. #ifndef NO_SIG_WRAPPER
  28074. ret = ecc_sig_test(rng, key);
  28075. if (ret < 0)
  28076. goto done;
  28077. #endif
  28078. TEST_SLEEP();
  28079. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_CRYPTOCELL) && \
  28080. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  28081. ret = ecc_ssh_test(key, rng);
  28082. if (ret < 0)
  28083. goto done;
  28084. #endif
  28085. wc_ecc_free(key);
  28086. #else
  28087. (void)rng;
  28088. #endif /* !WC_NO_RNG */
  28089. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28090. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28091. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28092. /* Use test ECC key - ensure real private "d" exists */
  28093. #if defined(USE_CERT_BUFFERS_256)
  28094. {
  28095. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  28096. sizeof_ecc_key_der_256);
  28097. }
  28098. #elif !defined(NO_FILESYSTEM)
  28099. {
  28100. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  28101. byte der[128];
  28102. word32 derSz;
  28103. if (!file) {
  28104. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28105. }
  28106. derSz = (word32)XFREAD(der, 1, sizeof(der), file);
  28107. XFCLOSE(file);
  28108. if (derSz == 0)
  28109. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28110. ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
  28111. }
  28112. #else
  28113. {
  28114. (void)idx;
  28115. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
  28116. ERROR_OUT(ASN_PARSE_E, done);
  28117. }
  28118. #endif
  28119. if (ret != 0) {
  28120. goto done;
  28121. }
  28122. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)
  28123. ret = ecc_exp_imp_test(key);
  28124. if (ret < 0)
  28125. goto done;
  28126. #endif
  28127. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  28128. !defined(WOLFSSL_CRYPTOCELL)
  28129. ret = ecc_mulmod_test(key);
  28130. if (ret < 0)
  28131. goto done;
  28132. #endif
  28133. #endif
  28134. #else
  28135. (void)rng;
  28136. (void)idx;
  28137. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  28138. done:
  28139. wc_ecc_free(key);
  28140. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28141. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28142. #endif
  28143. return ret;
  28144. }
  28145. #endif /* !NO_ECC256 || HAVE_ALL_CURVES */
  28146. #if defined(WOLFSSL_CERT_EXT) && \
  28147. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  28148. static wc_test_ret_t ecc_decode_test(void)
  28149. {
  28150. wc_test_ret_t ret;
  28151. word32 inSz;
  28152. word32 inOutIdx;
  28153. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28154. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28155. #else
  28156. ecc_key key[1];
  28157. #endif
  28158. /* SECP256R1 OID: 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 */
  28159. /* This is ecc_clikeypub_der_256. */
  28160. WOLFSSL_SMALL_STACK_STATIC const byte good[] = {
  28161. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  28162. 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  28163. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xbf, 0xf4,
  28164. 0x0f, 0x44, 0x50, 0x9a, 0x3d, 0xce, 0x9b, 0xb7, 0xf0, 0xc5,
  28165. 0x4d, 0xf5, 0x70, 0x7b, 0xd4, 0xec, 0x24, 0x8e, 0x19, 0x80,
  28166. 0xec, 0x5a, 0x4c, 0xa2, 0x24, 0x03, 0x62, 0x2c, 0x9b, 0xda,
  28167. 0xef, 0xa2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xc6, 0x56,
  28168. 0x95, 0x06, 0xcc, 0x01, 0xa9, 0xbd, 0xf6, 0x75, 0x1a, 0x42,
  28169. 0xf7, 0xbd, 0xa9, 0xb2, 0x36, 0x22, 0x5f, 0xc7, 0x5d, 0x7f,
  28170. 0xb4 };
  28171. WOLFSSL_SMALL_STACK_STATIC const byte badNoObjId[] = { 0x30, 0x08, 0x30, 0x06, 0x03, 0x04,
  28172. 0x00, 0x04, 0x01, 0x01 };
  28173. WOLFSSL_SMALL_STACK_STATIC const byte badOneObjId[] = { 0x30, 0x0a, 0x30, 0x08, 0x06, 0x00,
  28174. 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28175. WOLFSSL_SMALL_STACK_STATIC const byte badObjId1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x09,
  28176. 0x06, 0x00, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28177. WOLFSSL_SMALL_STACK_STATIC const byte badObj2d1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
  28178. 0x06, 0x07, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28179. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitStr[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28180. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28181. 0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28182. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrLen[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28183. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28184. 0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
  28185. WOLFSSL_SMALL_STACK_STATIC const byte badNoBitStrZero[] = { 0x30, 0x13, 0x30, 0x0a, 0x06, 0x00,
  28186. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28187. 0x03, 0x03, 0x04, 0x01, 0x01 };
  28188. WOLFSSL_SMALL_STACK_STATIC const byte badPoint[] = { 0x30, 0x12, 0x30, 0x09, 0x06, 0x00,
  28189. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28190. 0x03, 0x03, 0x00, 0x04, 0x01 };
  28191. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28192. if (key == NULL)
  28193. ERROR_OUT(MEMORY_E, done);
  28194. #endif
  28195. XMEMSET(key, 0, sizeof *key);
  28196. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28197. inSz = sizeof(good);
  28198. ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, key, inSz);
  28199. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28200. ret = WC_TEST_RET_ENC_EC(ret);
  28201. goto done;
  28202. }
  28203. ret = wc_EccPublicKeyDecode(good, NULL, key, inSz);
  28204. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28205. ret = WC_TEST_RET_ENC_EC(ret);
  28206. goto done;
  28207. }
  28208. ret = wc_EccPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  28209. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28210. ret = WC_TEST_RET_ENC_EC(ret);
  28211. goto done;
  28212. }
  28213. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, 0);
  28214. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28215. ret = WC_TEST_RET_ENC_EC(ret);
  28216. goto done;
  28217. }
  28218. /* Change offset to produce bad input data. */
  28219. inOutIdx = 2;
  28220. inSz = sizeof(good) - inOutIdx;
  28221. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28222. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28223. ret = WC_TEST_RET_ENC_EC(ret);
  28224. goto done;
  28225. }
  28226. inOutIdx = 4;
  28227. inSz = sizeof(good) - inOutIdx;
  28228. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28229. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28230. ret = WC_TEST_RET_ENC_EC(ret);
  28231. goto done;
  28232. }
  28233. /* Bad data. */
  28234. inSz = sizeof(badNoObjId);
  28235. inOutIdx = 0;
  28236. ret = wc_EccPublicKeyDecode(badNoObjId, &inOutIdx, key, inSz);
  28237. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28238. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28239. {
  28240. ret = WC_TEST_RET_ENC_EC(ret);
  28241. goto done;
  28242. }
  28243. inSz = sizeof(badOneObjId);
  28244. inOutIdx = 0;
  28245. ret = wc_EccPublicKeyDecode(badOneObjId, &inOutIdx, key, inSz);
  28246. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28247. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28248. {
  28249. ret = WC_TEST_RET_ENC_EC(ret);
  28250. goto done;
  28251. }
  28252. inSz = sizeof(badObjId1Len);
  28253. inOutIdx = 0;
  28254. ret = wc_EccPublicKeyDecode(badObjId1Len, &inOutIdx, key, inSz);
  28255. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28256. ret = WC_TEST_RET_ENC_EC(ret);
  28257. goto done;
  28258. }
  28259. inSz = sizeof(badObj2d1Len);
  28260. inOutIdx = 0;
  28261. ret = wc_EccPublicKeyDecode(badObj2d1Len, &inOutIdx, key, inSz);
  28262. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28263. ret = WC_TEST_RET_ENC_EC(ret);
  28264. goto done;
  28265. }
  28266. inSz = sizeof(badNotBitStr);
  28267. inOutIdx = 0;
  28268. ret = wc_EccPublicKeyDecode(badNotBitStr, &inOutIdx, key, inSz);
  28269. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E) &&
  28270. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28271. {
  28272. ret = WC_TEST_RET_ENC_EC(ret);
  28273. goto done;
  28274. }
  28275. inSz = sizeof(badBitStrLen);
  28276. inOutIdx = 0;
  28277. ret = wc_EccPublicKeyDecode(badBitStrLen, &inOutIdx, key, inSz);
  28278. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28279. ret = WC_TEST_RET_ENC_EC(ret);
  28280. goto done;
  28281. }
  28282. inSz = sizeof(badNoBitStrZero);
  28283. inOutIdx = 0;
  28284. ret = wc_EccPublicKeyDecode(badNoBitStrZero, &inOutIdx, key, inSz);
  28285. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  28286. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28287. {
  28288. ret = WC_TEST_RET_ENC_EC(ret);
  28289. goto done;
  28290. }
  28291. inSz = sizeof(badPoint);
  28292. inOutIdx = 0;
  28293. ret = wc_EccPublicKeyDecode(badPoint, &inOutIdx, key, inSz);
  28294. if (ret != WC_NO_ERR_TRACE(ASN_ECC_KEY_E) &&
  28295. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28296. {
  28297. ret = WC_TEST_RET_ENC_EC(ret);
  28298. goto done;
  28299. }
  28300. inSz = sizeof(good);
  28301. inOutIdx = 0;
  28302. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28303. if (ret != 0)
  28304. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28305. done:
  28306. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28307. if (key != NULL) {
  28308. wc_ecc_free(key);
  28309. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28310. }
  28311. #else
  28312. wc_ecc_free(key);
  28313. #endif
  28314. return ret;
  28315. }
  28316. #endif /* WOLFSSL_CERT_EXT */
  28317. #ifdef WOLFSSL_CUSTOM_CURVES
  28318. static const byte eccKeyExplicitCurve[] = {
  28319. 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07,
  28320. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  28321. 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  28322. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  28323. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  28324. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28325. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28326. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  28327. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  28328. 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe,
  28329. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  28330. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  28331. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  28332. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
  28333. 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4,
  28334. 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17,
  28335. 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47,
  28336. 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21,
  28337. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28338. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28339. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  28340. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  28341. 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04,
  28342. 0x3c, 0x4c, 0xc9, 0x5e, 0x2e, 0xa2, 0x3d, 0x49,
  28343. 0xcc, 0x5b, 0xff, 0x4f, 0xc9, 0x2e, 0x1d, 0x4a,
  28344. 0xc6, 0x21, 0xf6, 0xf3, 0xe6, 0x0b, 0x4f, 0xa9,
  28345. 0x9d, 0x74, 0x99, 0xdd, 0x97, 0xc7, 0x6e, 0xbe,
  28346. 0x14, 0x2b, 0x39, 0x9d, 0x63, 0xc7, 0x97, 0x0d,
  28347. 0x45, 0x25, 0x40, 0x30, 0x77, 0x05, 0x76, 0x88,
  28348. 0x38, 0x96, 0x29, 0x7d, 0x9c, 0xe1, 0x50, 0xbe,
  28349. 0xac, 0xf0, 0x1d, 0x86, 0xf4, 0x2f, 0x65, 0x0b
  28350. };
  28351. static wc_test_ret_t ecc_test_custom_curves(WC_RNG* rng)
  28352. {
  28353. wc_test_ret_t ret;
  28354. word32 inOutIdx;
  28355. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28356. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28357. #else
  28358. ecc_key key[1];
  28359. #endif
  28360. /* test use of custom curve - using BRAINPOOLP256R1 for test */
  28361. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28362. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28363. WOLFSSL_SMALL_STACK_STATIC const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
  28364. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
  28365. };
  28366. #define ecc_oid_brainpoolp256r1_sz \
  28367. (sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t))
  28368. #else
  28369. #define ecc_oid_brainpoolp256r1 { \
  28370. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 \
  28371. }
  28372. #define ecc_oid_brainpoolp256r1_sz 9
  28373. #endif
  28374. #define ecc_oid_brainpoolp256r1_sum 104
  28375. WOLFSSL_SMALL_STACK_STATIC const ecc_set_type ecc_dp_brainpool256r1 = {
  28376. 32, /* size/bytes */
  28377. ECC_CURVE_CUSTOM, /* ID */
  28378. "BRAINPOOLP256R1", /* curve name */
  28379. "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
  28380. "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
  28381. "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", /* B */
  28382. "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", /* order */
  28383. "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", /* Gx */
  28384. "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
  28385. ecc_oid_brainpoolp256r1, /* oid/oidSz */
  28386. ecc_oid_brainpoolp256r1_sz,
  28387. ecc_oid_brainpoolp256r1_sum, /* oid sum */
  28388. 1, /* cofactor */
  28389. };
  28390. #endif /* HAVE_ECC_BRAINPOOL */
  28391. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28392. if (! key) {
  28393. ret = MEMORY_E;
  28394. goto done;
  28395. }
  28396. #endif
  28397. XMEMSET(key, 0, sizeof *key);
  28398. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28399. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, ECC_CURVE_DEF,
  28400. &ecc_dp_brainpool256r1);
  28401. if (ret != 0) {
  28402. printf("ECC test for custom curve failed!\n");
  28403. goto done;
  28404. }
  28405. #endif
  28406. #if defined(HAVE_ECC_BRAINPOOL) || defined(HAVE_ECC_KOBLITZ)
  28407. {
  28408. int curve_id;
  28409. #ifdef HAVE_ECC_BRAINPOOL
  28410. curve_id = ECC_BRAINPOOLP256R1;
  28411. #else
  28412. curve_id = ECC_SECP256K1;
  28413. #endif
  28414. /* Test and demonstrate use of non-SECP curve */
  28415. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, curve_id, NULL);
  28416. if (ret < 0) {
  28417. printf("ECC test for curve_id %d failed!\n", curve_id);
  28418. goto done;
  28419. }
  28420. }
  28421. #endif
  28422. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  28423. if (ret != 0)
  28424. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28425. inOutIdx = 0;
  28426. ret = wc_EccPublicKeyDecode(eccKeyExplicitCurve, &inOutIdx, key,
  28427. sizeof(eccKeyExplicitCurve));
  28428. if (ret != 0)
  28429. ret = WC_TEST_RET_ENC_EC(ret);
  28430. done:
  28431. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28432. if (key) {
  28433. wc_ecc_free(key);
  28434. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28435. }
  28436. #else
  28437. wc_ecc_free(key);
  28438. #endif
  28439. (void)rng;
  28440. return ret;
  28441. }
  28442. #endif /* WOLFSSL_CUSTOM_CURVES */
  28443. #ifdef WOLFSSL_SM2
  28444. #ifdef HAVE_ECC_VERIFY
  28445. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28446. #ifdef HAVE_OID_ENCODING
  28447. #define CODED_SM2P256V1 {1,2,156,10197,1,301}
  28448. #define CODED_SM2P256V1_SZ 6
  28449. #else
  28450. #define CODED_SM2P256V1 {0x06,0x08,0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D}
  28451. #define CODED_SM2P256V1_SZ 10
  28452. #endif
  28453. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28454. static const ecc_oid_t ecc_oid_sm2p256v1[] = CODED_SM2P256V1;
  28455. #else
  28456. #define ecc_oid_sm2p256v1 CODED_SM2P256V1
  28457. #endif
  28458. #define ecc_oid_sm2p256v1_sz CODED_SM2P256V1_SZ
  28459. #define ECC_SM2P256V1_TEST 102
  28460. static int test_sm2_verify_caseA2(void)
  28461. {
  28462. ecc_key key;
  28463. int ret, res;
  28464. mp_int r,s;
  28465. /* test key values */
  28466. const char qx[] = "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A";
  28467. const char qy[] = "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857";
  28468. const char d[] = "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263";
  28469. const ecc_set_type ecc_sm2_A2 = {
  28470. 32, /* size/bytes */
  28471. ECC_SM2P256V1_TEST, /* ID */
  28472. "SM2P256V1_TEST", /* curve name */
  28473. /* from test case A.2 in draft-shen-sm2-ecdsa-02 */
  28474. "8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", /* prime */
  28475. "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", /* A */
  28476. "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", /* B */
  28477. "8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", /* order n */
  28478. "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", /* Gx */
  28479. "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", /* Gy */
  28480. ecc_oid_sm2p256v1, /* oid/oidSz */
  28481. ecc_oid_sm2p256v1_sz,
  28482. ECC_SM2P256V1_OID, /* oid sum */
  28483. 1, /* cofactor */
  28484. };
  28485. /* use canned hash value hash = H(ZA||M) */
  28486. const byte hash[] = {
  28487. 0xB5,0x24,0xF5,0x52,0xCD,0x82,0xB8,0xB0,
  28488. 0x28,0x47,0x6E,0x00,0x5C,0x37,0x7F,0xB1,
  28489. 0x9A,0x87,0xE6,0xFC,0x68,0x2D,0x48,0xBB,
  28490. 0x5D,0x42,0xE3,0xD9,0xB9,0xEF,0xFE,0x76
  28491. };
  28492. /* canned r and s */
  28493. const byte rCan[] = {
  28494. 0x40,0xF1,0xEC,0x59,0xF7,0x93,0xD9,0xF4,
  28495. 0x9E,0x09,0xDC,0xEF,0x49,0x13,0x0D,0x41,
  28496. 0x94,0xF7,0x9F,0xB1,0xEE,0xD2,0xCA,0xA5,
  28497. 0x5B,0xAC,0xDB,0x49,0xC4,0xE7,0x55,0xD1
  28498. };
  28499. const byte sCan[] = {
  28500. 0x6F,0xC6,0xDA,0xC3,0x2C,0x5D,0x5C,0xF1,
  28501. 0x0C,0x77,0xDF,0xB2,0x0F,0x7C,0x2E,0xB6,
  28502. 0x67,0xA4,0x57,0x87,0x2F,0xB0,0x9E,0xC5,
  28503. 0x63,0x27,0xA6,0x7E,0xC7,0xDE,0xEB,0xE7
  28504. };
  28505. mp_init(&r);
  28506. mp_init(&s);
  28507. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28508. if (ret != 0)
  28509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28510. ret = wc_ecc_set_custom_curve(&key, &ecc_sm2_A2);
  28511. if (ret != 0)
  28512. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28513. ret = wc_ecc_import_raw_ex(&key, qx, qy, d, ECC_SM2P256V1_TEST);
  28514. if (ret != 0)
  28515. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28516. mp_read_unsigned_bin(&r, rCan, sizeof(rCan));
  28517. mp_read_unsigned_bin(&s, sCan, sizeof(sCan));
  28518. ret = wc_ecc_sm2_verify_hash_ex(&r, &s, hash, sizeof(hash), &res, &key);
  28519. if (ret != 0)
  28520. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28521. if (res != 1)
  28522. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28523. done:
  28524. mp_free(&r);
  28525. mp_free(&s);
  28526. wc_ecc_free(&key);
  28527. return ret;
  28528. }
  28529. #endif /* WOLFSSL_PUBLIC_MP && WOLFSSL_CUSTOM_CURVES */
  28530. static int test_sm2_verify_case(void)
  28531. {
  28532. ecc_key key;
  28533. int ret, res;
  28534. /* test key values */
  28535. const char qx[] = "637F1B135036C933DC3F7A8EBB1B7B2FD1DFBD268D4F894B5AD47DBDBECD558F";
  28536. const char qy[] = "E88101D08048E36CCBF61CA38DDF7ABA542B4486E99E49F3A7470A857A096433";
  28537. /* use canned hash value hash = H(ZA||M) */
  28538. const byte hash[] = {
  28539. 0x3B,0xFA,0x5F,0xFB,0xC4,0x27,0x8C,0x9D,
  28540. 0x02,0x3A,0x19,0xCB,0x1E,0xAA,0xD2,0xF1,
  28541. 0x50,0x69,0x5B,0x20
  28542. };
  28543. const byte sig[] = {
  28544. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28545. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28546. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28547. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28548. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28549. 0xB5,0xB5,0xD9,0xD8,0xF1,0x20,0xDD,0x97,
  28550. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28551. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28552. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28553. };
  28554. const byte badSig[] = {
  28555. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28556. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28557. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28558. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28559. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28560. 0xB5,0xB5,0xE9,0xD8,0xF1,0x20,0xDD,0x97,
  28561. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28562. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28563. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28564. };
  28565. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28566. if (ret != 0)
  28567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28568. ret = wc_ecc_import_raw(&key, qx, qy, NULL, "SM2P256V1");
  28569. if (ret != 0)
  28570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28571. ret = wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash), &res,
  28572. &key);
  28573. if (ret != 0)
  28574. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28575. if (res != 1)
  28576. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28577. /* now test a case that should fail */
  28578. ret = wc_ecc_sm2_verify_hash(badSig, sizeof(badSig), hash, sizeof(hash),
  28579. &res, &key);
  28580. if (ret != 0)
  28581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28582. if (res == 1)
  28583. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28584. done:
  28585. wc_ecc_free(&key);
  28586. return ret;
  28587. }
  28588. static int ecc_sm2_test_curve(WC_RNG* rng, int testVerifyCount)
  28589. {
  28590. const ecc_set_type* dp = wc_ecc_get_curve_params(
  28591. wc_ecc_get_curve_idx(ECC_SM2P256V1));
  28592. int keySize = 32;
  28593. int curve_id = ECC_SM2P256V1;
  28594. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28595. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28596. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28597. #endif
  28598. #ifdef HAVE_ECC_KEY_EXPORT
  28599. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  28600. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28601. #endif
  28602. word32 x = 0;
  28603. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28604. word32 y;
  28605. #endif
  28606. #ifdef HAVE_ECC_SIGN
  28607. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28608. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28609. int i;
  28610. int verify;
  28611. #endif /* HAVE_ECC_SIGN */
  28612. int ret;
  28613. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28614. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28615. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28616. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28617. #else
  28618. ecc_key userA[1];
  28619. ecc_key userB[1];
  28620. ecc_key pubKey[1];
  28621. #endif
  28622. #ifndef WC_NO_RNG
  28623. int curveSize;
  28624. #endif
  28625. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28626. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28627. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28628. #endif
  28629. #ifdef HAVE_ECC_KEY_EXPORT
  28630. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28631. #endif
  28632. #ifdef HAVE_ECC_SIGN
  28633. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28634. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28635. #endif
  28636. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  28637. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28638. if (sharedA == NULL || sharedB == NULL)
  28639. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28640. #endif
  28641. #ifdef HAVE_ECC_KEY_EXPORT
  28642. if (exportBuf == NULL)
  28643. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28644. #endif
  28645. #ifdef HAVE_ECC_SIGN
  28646. if (sig == NULL || digest == NULL)
  28647. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28648. #endif
  28649. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  28650. (void)testVerifyCount;
  28651. (void)dp;
  28652. (void)x;
  28653. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28654. if ((userA == NULL) ||
  28655. (userB == NULL) ||
  28656. (pubKey == NULL))
  28657. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28658. #endif
  28659. XMEMSET(userA, 0, sizeof *userA);
  28660. XMEMSET(userB, 0, sizeof *userB);
  28661. XMEMSET(pubKey, 0, sizeof *pubKey);
  28662. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  28663. if (ret != 0)
  28664. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28665. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  28666. if (ret != 0)
  28667. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28668. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28669. if (ret != 0)
  28670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28671. #ifndef WC_NO_RNG
  28672. ret = wc_ecc_sm2_make_key(rng, userA, WC_ECC_FLAG_NONE);
  28673. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  28674. goto done; /* catch case, where curve is not supported */
  28675. if (ret != 0)
  28676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28677. TEST_SLEEP();
  28678. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  28679. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  28680. if (curveSize != userA->dp->size) {
  28681. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28682. }
  28683. }
  28684. ret = wc_ecc_check_key(userA);
  28685. if (ret != 0)
  28686. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28687. TEST_SLEEP();
  28688. ret = wc_ecc_sm2_make_key(rng, userB, WC_ECC_FLAG_NONE);
  28689. if (ret != 0)
  28690. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28691. /* only perform the below tests if the key size matches */
  28692. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  28693. if (ret != 0) {
  28694. ret = ECC_CURVE_OID_E;
  28695. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28696. }
  28697. #ifdef HAVE_ECC_DHE
  28698. #if defined(ECC_TIMING_RESISTANT)
  28699. ret = wc_ecc_set_rng(userA, rng);
  28700. if (ret != 0)
  28701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28702. ret = wc_ecc_set_rng(userB, rng);
  28703. if (ret != 0)
  28704. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28705. #endif
  28706. x = ECC_SHARED_SIZE;
  28707. ret = wc_ecc_sm2_shared_secret(userA, userB, sharedA, &x);
  28708. if (ret != 0)
  28709. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28710. y = ECC_SHARED_SIZE;
  28711. ret = wc_ecc_sm2_shared_secret(userB, userA, sharedB, &y);
  28712. if (ret != 0)
  28713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28714. if (y != x)
  28715. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28716. if (XMEMCMP(sharedA, sharedB, x))
  28717. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28718. #endif /* HAVE_ECC_DHE */
  28719. #ifdef HAVE_ECC_KEY_EXPORT
  28720. x = ECC_KEY_EXPORT_BUF_SIZE;
  28721. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  28722. if (ret != 0)
  28723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28724. #ifdef HAVE_ECC_KEY_IMPORT
  28725. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28726. if (ret != 0)
  28727. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28728. #ifdef HAVE_ECC_DHE
  28729. y = ECC_SHARED_SIZE;
  28730. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28731. if (ret != 0)
  28732. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28733. if (XMEMCMP(sharedA, sharedB, y))
  28734. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28735. #endif /* HAVE_ECC_DHE */
  28736. #ifdef HAVE_COMP_KEY
  28737. /* try compressed export / import too */
  28738. x = ECC_KEY_EXPORT_BUF_SIZE;
  28739. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  28740. if (ret != 0)
  28741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28742. wc_ecc_free(pubKey);
  28743. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28744. if (ret != 0)
  28745. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28746. #endif
  28747. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28748. if (ret != 0)
  28749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28750. #ifdef HAVE_ECC_DHE
  28751. y = ECC_SHARED_SIZE;
  28752. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28753. if (ret != 0)
  28754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28755. if (XMEMCMP(sharedA, sharedB, y))
  28756. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28757. #endif /* HAVE_ECC_DHE */
  28758. #endif /* HAVE_ECC_KEY_IMPORT */
  28759. #endif /* HAVE_ECC_KEY_EXPORT */
  28760. #endif /* !WC_NO_RNG */
  28761. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  28762. !defined(WC_NO_RNG))
  28763. #ifdef HAVE_ECC_SIGN
  28764. /* ECC w/out Shamir has issue with all 0 digest */
  28765. /* WC_BIGINT doesn't have 0 len well on hardware */
  28766. /* Cryptocell has issues with all 0 digest */
  28767. #if defined(ECC_SHAMIR)
  28768. /* test DSA sign hash with zeros */
  28769. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28770. digest[i] = 0;
  28771. }
  28772. x = ECC_SIG_SIZE;
  28773. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28774. if (ret != 0)
  28775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28776. for (i = 0; i < testVerifyCount; i++) {
  28777. verify = 0;
  28778. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28779. userA);
  28780. if (ret != 0)
  28781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28782. if (verify != 1)
  28783. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28784. }
  28785. #endif /* ECC_SHAMIR */
  28786. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  28787. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28788. digest[i] = (byte)i;
  28789. }
  28790. x = ECC_SIG_SIZE;
  28791. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28792. if (ret != 0)
  28793. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28794. for (i = 0; i < testVerifyCount; i++) {
  28795. verify = 0;
  28796. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28797. userA);
  28798. if (ret != 0)
  28799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28800. if (verify != 1)
  28801. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28802. }
  28803. #endif /* HAVE_ECC_SIGN */
  28804. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT && !WC_NO_RNG) */
  28805. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  28806. x = ECC_KEY_EXPORT_BUF_SIZE;
  28807. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  28808. if (ret != 0)
  28809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28810. #elif defined(HAVE_ECC_KEY_EXPORT)
  28811. (void)exportBuf;
  28812. #endif /* HAVE_ECC_KEY_EXPORT */
  28813. done:
  28814. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28815. if (userA != NULL) {
  28816. wc_ecc_free(userA);
  28817. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28818. }
  28819. if (userB != NULL) {
  28820. wc_ecc_free(userB);
  28821. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28822. }
  28823. if (pubKey != NULL) {
  28824. wc_ecc_free(pubKey);
  28825. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28826. }
  28827. #else
  28828. wc_ecc_free(pubKey);
  28829. wc_ecc_free(userB);
  28830. wc_ecc_free(userA);
  28831. #endif
  28832. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  28833. WC_FREE_VAR(sharedA, HEAP_HINT);
  28834. WC_FREE_VAR(sharedB, HEAP_HINT);
  28835. #endif
  28836. #ifdef HAVE_ECC_KEY_EXPORT
  28837. WC_FREE_VAR(exportBuf, HEAP_HINT);
  28838. #endif
  28839. #ifdef HAVE_ECC_SIGN
  28840. WC_FREE_VAR(sig, HEAP_HINT);
  28841. WC_FREE_VAR(digest, HEAP_HINT);
  28842. #endif
  28843. (void)keySize;
  28844. (void)curve_id;
  28845. (void)rng;
  28846. return ret;
  28847. }
  28848. #endif /* HAVE_ECC_VERIFY */
  28849. static int test_sm2_create_digest(void)
  28850. {
  28851. #ifndef WOLFSSL_SM3
  28852. const byte msg[] = "message to sign";
  28853. const byte id[] = "0123456789";
  28854. const byte badId[] = "0123556789";
  28855. byte expected[] = {
  28856. 0xdd, 0x4d, 0x65, 0x49, 0xa3, 0x64, 0x76, 0xc0,
  28857. 0x73, 0x05, 0xdc, 0x05, 0x16, 0xb5, 0xee, 0x9f,
  28858. 0x82, 0xf9, 0xe9, 0x7d, 0x01, 0x1a, 0xdc, 0x88,
  28859. 0x5a, 0x59, 0x9c, 0x44, 0xcc, 0x47, 0xa4, 0x78
  28860. };
  28861. ecc_key key;
  28862. int ret;
  28863. /* test key values */
  28864. const char qx[] =
  28865. "af178b7b8740cc9d5b493fbd22049c12621bc27dcc5802e75ff4d045a4158baf";
  28866. const char qy[] =
  28867. "89933faf7a4798f48c5b9b4cd3a7693d54c9e05449946eb489c0dd50a5294805";
  28868. const char d[] =
  28869. "b3e66c2dbfb50c6ff6830c1fac4b51293a2562f9e667052b03df2d4b43c1f34a";
  28870. int hash_type = WC_HASH_TYPE_SHA256;
  28871. byte digest[WC_SHA256_DIGEST_SIZE];
  28872. #else
  28873. ecc_key key;
  28874. int ret;
  28875. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20,
  28876. 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x00 };
  28877. const byte id[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28878. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28879. 0x00 };
  28880. const byte badId[] = "0123556789";
  28881. const char qx[] =
  28882. "09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020";
  28883. const char qy[] =
  28884. "CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13";
  28885. const char d[] =
  28886. "3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8";
  28887. byte expected[] = {
  28888. 0xf0, 0xb4, 0x3e, 0x94, 0xba, 0x45, 0xac, 0xca,
  28889. 0xac, 0xe6, 0x92, 0xed, 0x53, 0x43, 0x82, 0xeb,
  28890. 0x17, 0xe6, 0xab, 0x5a, 0x19, 0xce, 0x7b, 0x31,
  28891. 0xf4, 0x48, 0x6f, 0xdf, 0xc0, 0xd2, 0x86, 0x40
  28892. };
  28893. int hash_type = WC_HASH_TYPE_SM3;
  28894. byte digest[WC_SM3_DIGEST_SIZE];
  28895. #endif
  28896. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28897. if (ret != 0)
  28898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28899. ret = wc_ecc_import_raw(&key, qx, qy, d, "SM2P256V1");
  28900. if (ret != 0)
  28901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28902. ret = wc_ecc_sm2_create_digest(id, (int)XSTRLEN((const char*)id),
  28903. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28904. &key);
  28905. if (ret != 0)
  28906. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28907. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) != 0)
  28908. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28909. ret = wc_ecc_sm2_create_digest(badId, (int)XSTRLEN((const char*)badId),
  28910. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28911. &key);
  28912. if (ret != 0)
  28913. goto done;
  28914. /* should be different than the previous ID used */
  28915. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) == 0)
  28916. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28917. done:
  28918. wc_ecc_free(&key);
  28919. return ret;
  28920. }
  28921. static int test_sm2_verify(void)
  28922. {
  28923. int ret = 0;
  28924. #ifdef HAVE_ECC_VERIFY
  28925. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28926. ret = test_sm2_verify_caseA2();
  28927. if (ret != 0)
  28928. return ret;
  28929. #endif
  28930. ret = test_sm2_verify_case();
  28931. if (ret != 0)
  28932. return ret;
  28933. #endif /* HAVE_ECC_VERIFY */
  28934. ret = test_sm2_create_digest();
  28935. return ret;
  28936. }
  28937. #endif /* WOLFSSL_SM2 */
  28938. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  28939. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  28940. /* Make Cert / Sign example for ECC cert and ECC CA */
  28941. static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
  28942. {
  28943. wc_test_ret_t ret;
  28944. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28945. Cert *myCert = (Cert *)XMALLOC(sizeof *myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28946. #ifdef WOLFSSL_TEST_CERT
  28947. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28948. #endif
  28949. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28950. ecc_key *certPubKey = (ecc_key *)XMALLOC(sizeof *certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28951. #else
  28952. Cert myCert[1];
  28953. #ifdef WOLFSSL_TEST_CERT
  28954. DecodedCert decode[1];
  28955. #endif
  28956. ecc_key caEccKey[1];
  28957. ecc_key certPubKey[1];
  28958. #endif
  28959. int certSz;
  28960. size_t bytes = 0;
  28961. word32 idx = 0;
  28962. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
  28963. XFILE file;
  28964. #endif
  28965. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28966. byte* der = NULL;
  28967. #else
  28968. byte der[FOURK_BUF];
  28969. #endif
  28970. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28971. if ((myCert == NULL)
  28972. #ifdef WOLFSSL_TEST_CERT
  28973. || (decode == NULL)
  28974. #endif
  28975. || (caEccKey == NULL) || (certPubKey == NULL))
  28976. ERROR_OUT(MEMORY_E, exit);
  28977. #endif
  28978. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  28979. XMEMSET(certPubKey, 0, sizeof *certPubKey);
  28980. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28981. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28982. if (der == NULL) {
  28983. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28984. }
  28985. #endif
  28986. /* Get cert private key */
  28987. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28988. /* Get Cert Key 384 */
  28989. #ifdef USE_CERT_BUFFERS_256
  28990. XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
  28991. bytes = sizeof_ca_ecc_key_der_384;
  28992. #elif !defined(NO_FILESYSTEM)
  28993. file = XFOPEN(eccCaKey384File, "rb");
  28994. if (!file) {
  28995. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28996. }
  28997. bytes = XFREAD(der, 1, FOURK_BUF, file);
  28998. XFCLOSE(file);
  28999. if (bytes == 0)
  29000. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29001. (void)eccCaKeyFile;
  29002. #else
  29003. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
  29004. ERROR_OUT(ASN_PARSE_E, exit);
  29005. #endif /* USE_CERT_BUFFERS_256 */
  29006. /* end if ENABLE_ECC384_CERT_GEN_TEST */
  29007. #else
  29008. /* !ENABLE_ECC384_CERT_GEN_TEST */
  29009. #ifdef USE_CERT_BUFFERS_256
  29010. XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
  29011. bytes = sizeof_ca_ecc_key_der_256;
  29012. #else
  29013. file = XFOPEN(eccCaKeyFile, "rb");
  29014. if (!file) {
  29015. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29016. }
  29017. bytes = XFREAD(der, 1, FOURK_BUF, file);
  29018. XFCLOSE(file);
  29019. if (bytes == 0)
  29020. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29021. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29022. (void)eccCaKey384File;
  29023. #endif
  29024. #endif /* USE_CERT_BUFFERS_256 */
  29025. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29026. /* Get CA Key */
  29027. ret = wc_ecc_init_ex(caEccKey, HEAP_HINT, devId);
  29028. if (ret != 0)
  29029. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29030. ret = wc_EccPrivateKeyDecode(der, &idx, caEccKey, (word32)bytes);
  29031. if (ret != 0)
  29032. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29033. /* Make a public key */
  29034. ret = wc_ecc_init_ex(certPubKey, HEAP_HINT, devId);
  29035. if (ret != 0)
  29036. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29037. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, certPubKey);
  29038. #if defined(WOLFSSL_ASYNC_CRYPT)
  29039. ret = wc_AsyncWait(ret, &certPubKey->asyncDev, WC_ASYNC_FLAG_NONE);
  29040. #endif
  29041. if (ret != 0)
  29042. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29043. TEST_SLEEP();
  29044. /* Setup Certificate */
  29045. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  29046. if (ret != 0)
  29047. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29048. #ifndef NO_SHA256
  29049. myCert->sigType = CTC_SHA256wECDSA;
  29050. #else
  29051. myCert->sigType = CTC_SHAwECDSA;
  29052. #endif
  29053. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  29054. #ifdef WOLFSSL_CERT_EXT
  29055. /* add Policies */
  29056. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  29057. CTC_MAX_CERTPOL_SZ);
  29058. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  29059. CTC_MAX_CERTPOL_SZ);
  29060. myCert->certPoliciesNb = 2;
  29061. /* add SKID from the Public Key */
  29062. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey);
  29063. if (ret != 0)
  29064. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29065. /* add AKID from the Public Key */
  29066. ret = wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey);
  29067. if (ret != 0)
  29068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29069. /* add Key Usage */
  29070. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  29071. if (ret != 0)
  29072. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29073. #endif /* WOLFSSL_CERT_EXT */
  29074. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29075. #if defined(USE_CERT_BUFFERS_256)
  29076. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
  29077. sizeof_ca_ecc_cert_der_384);
  29078. #elif !defined(NO_FILESYSTEM)
  29079. ret = wc_SetIssuer(myCert, eccCaCert384File);
  29080. (void)eccCaCertFile;
  29081. #else
  29082. /* not testing with embedded, no file system target */
  29083. ERROR_OUT(ASN_PARSE_E, exit);
  29084. #endif /* USE_CERT_BUFFERS_256 */
  29085. #else
  29086. /* not ENABLE_ECC384_CERT_GEN_TEST */
  29087. #if defined(USE_CERT_BUFFERS_256)
  29088. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
  29089. sizeof_ca_ecc_cert_der_256);
  29090. #else
  29091. ret = wc_SetIssuer(myCert, eccCaCertFile);
  29092. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29093. (void)eccCaCert384File;
  29094. #endif
  29095. #endif
  29096. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29097. if (ret < 0)
  29098. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29099. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, certPubKey, rng);
  29100. if (certSz < 0) {
  29101. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit);
  29102. }
  29103. ret = 0;
  29104. do {
  29105. #if defined(WOLFSSL_ASYNC_CRYPT)
  29106. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  29107. #endif
  29108. if (ret >= 0) {
  29109. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  29110. FOURK_BUF, NULL, caEccKey, rng);
  29111. }
  29112. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  29113. if (ret < 0)
  29114. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29115. certSz = (int)ret;
  29116. TEST_SLEEP();
  29117. #ifdef WOLFSSL_TEST_CERT
  29118. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  29119. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  29120. if (ret != 0) {
  29121. FreeDecodedCert(decode);
  29122. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29123. }
  29124. FreeDecodedCert(decode);
  29125. #endif
  29126. ret = SaveDerAndPem(der, certSz, certEccDerFile, certEccPemFile,
  29127. CERT_TYPE);
  29128. if (ret != 0) {
  29129. goto exit;
  29130. }
  29131. exit:
  29132. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29133. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29134. #endif
  29135. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29136. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29137. #ifdef WOLFSSL_TEST_CERT
  29138. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29139. #endif
  29140. if (caEccKey != NULL) {
  29141. wc_ecc_free(caEccKey);
  29142. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29143. }
  29144. if (certPubKey != NULL) {
  29145. wc_ecc_free(certPubKey);
  29146. XFREE(certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29147. }
  29148. #else
  29149. wc_ecc_free(certPubKey);
  29150. wc_ecc_free(caEccKey);
  29151. #endif
  29152. return ret;
  29153. }
  29154. #endif /* WOLFSSL_CERT_GEN */
  29155. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  29156. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
  29157. (!defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES))
  29158. /* Test for the wc_ecc_key_new() and wc_ecc_key_free() functions. */
  29159. static wc_test_ret_t ecc_test_allocator(WC_RNG* rng)
  29160. {
  29161. wc_test_ret_t ret = 0;
  29162. ecc_key* key;
  29163. #ifdef WC_NO_RNG
  29164. word32 idx = 0;
  29165. #endif
  29166. key = wc_ecc_key_new(HEAP_HINT);
  29167. if (key == NULL) {
  29168. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29169. }
  29170. #ifndef WC_NO_RNG
  29171. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  29172. #if defined(WOLFSSL_ASYNC_CRYPT)
  29173. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  29174. #endif
  29175. if (ret != 0)
  29176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29177. #else
  29178. /* use test ECC key */
  29179. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  29180. (word32)sizeof_ecc_key_der_256);
  29181. (void)rng;
  29182. #endif
  29183. exit:
  29184. wc_ecc_key_free(key);
  29185. return ret;
  29186. }
  29187. #endif
  29188. /* ECC Non-blocking tests for Sign and Verify */
  29189. /* Requires SP math and supports P384 or P256 */
  29190. /* ./configure --enable-ecc=nonblock --enable-sp=yes,nonblock CFLAGS="-DWOLFSSL_PUBLIC_MP" */
  29191. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_HAVE_SP_ECC) && \
  29192. defined(WOLFSSL_PUBLIC_MP)
  29193. /* ECC Private Key "d" */
  29194. static const byte p256PrivKey[] = {
  29195. /* SECP256R1 */
  29196. /* d */
  29197. 0x1e, 0xe7, 0x70, 0x07, 0xd3, 0x30, 0x94, 0x39,
  29198. 0x28, 0x90, 0xdf, 0x23, 0x88, 0x2c, 0x4a, 0x34,
  29199. 0x15, 0xdb, 0x4c, 0x43, 0xcd, 0xfa, 0xe5, 0x1f,
  29200. 0x3d, 0x4c, 0x37, 0xfe, 0x59, 0x3b, 0x96, 0xd8
  29201. };
  29202. #ifdef HAVE_ECC384
  29203. static const byte p384PrivKey[] = {
  29204. /* SECP384R1 */
  29205. /* d */
  29206. 0xa4, 0xe5, 0x06, 0xe8, 0x06, 0x16, 0x3e, 0xab,
  29207. 0x89, 0xf8, 0x60, 0x43, 0xc0, 0x60, 0x25, 0xdb,
  29208. 0xba, 0x7b, 0xfe, 0x19, 0x35, 0x08, 0x55, 0x65,
  29209. 0x76, 0xe2, 0xdc, 0xe0, 0x01, 0x8b, 0x6b, 0x68,
  29210. 0xdf, 0xcf, 0x6f, 0x80, 0x12, 0xce, 0x79, 0x37,
  29211. 0xeb, 0x2b, 0x9c, 0x7b, 0xc4, 0x68, 0x1c, 0x74
  29212. };
  29213. #endif /* HAVE_ECC384 */
  29214. #ifdef HAVE_ECC521
  29215. static const byte p521PrivKey[] = {
  29216. /* SECP521R1 */
  29217. /* d */
  29218. 0x01, 0x68, 0x91, 0x33, 0x53, 0xe2, 0x90, 0x68,
  29219. 0x11, 0x8f, 0xaa, 0xa8, 0x76, 0x0c, 0xf7, 0x2a,
  29220. 0x07, 0x1b, 0x92, 0x2a, 0xa7, 0x82, 0x3d, 0xfa,
  29221. 0x83, 0xce, 0x70, 0xc8, 0xc2, 0x60, 0x82, 0xfe,
  29222. 0x18, 0x88, 0x68, 0xda, 0x6a, 0x83, 0x46, 0x78,
  29223. 0xe4, 0xe9, 0xe9, 0xcc, 0x51, 0x7f, 0xed, 0x81,
  29224. 0x02, 0x32, 0xee, 0x26, 0x87, 0xcc, 0xed, 0x63,
  29225. 0x3f, 0x39, 0x27, 0xf0, 0xd7, 0x17, 0x77, 0xa1,
  29226. 0xa4, 0x36
  29227. };
  29228. #endif /* HAVE_ECC521 */
  29229. /* ECC public key Qx/Qy */
  29230. static const byte p256PubKey[] = {
  29231. /* SECP256R1 */
  29232. /* Qx */
  29233. 0x96, 0x93, 0x1c, 0x53, 0x0b, 0x43, 0x6c, 0x42,
  29234. 0x0c, 0x52, 0x90, 0xe4, 0xa7, 0xec, 0x98, 0xb1,
  29235. 0xaf, 0xd4, 0x14, 0x49, 0xd8, 0xc1, 0x42, 0x82,
  29236. 0x04, 0x78, 0xd1, 0x90, 0xae, 0xa0, 0x6c, 0x07,
  29237. /* Qy */
  29238. 0xf2, 0x3a, 0xb5, 0x10, 0x32, 0x8d, 0xce, 0x9e,
  29239. 0x76, 0xa0, 0xd2, 0x8c, 0xf3, 0xfc, 0xa9, 0x94,
  29240. 0x43, 0x24, 0xe6, 0x82, 0x00, 0x40, 0xc6, 0xdb,
  29241. 0x1c, 0x2f, 0xcd, 0x38, 0x4b, 0x60, 0xdd, 0x61
  29242. };
  29243. #ifdef HAVE_ECC384
  29244. static const byte p384PubKey[] = {
  29245. /* SECP384R1 */
  29246. /* Qx */
  29247. 0xea, 0xcf, 0x93, 0x4f, 0x2c, 0x09, 0xbb, 0x39,
  29248. 0x14, 0x0f, 0x56, 0x64, 0xc3, 0x40, 0xb4, 0xdf,
  29249. 0x0e, 0x63, 0xae, 0xe5, 0x71, 0x4b, 0x00, 0xcc,
  29250. 0x04, 0x97, 0xff, 0xe1, 0xe9, 0x38, 0x96, 0xbb,
  29251. 0x5f, 0x91, 0xb2, 0x6a, 0xcc, 0xb5, 0x39, 0x5f,
  29252. 0x8f, 0x70, 0x59, 0xf1, 0x01, 0xf6, 0x5a, 0x2b,
  29253. /* Qy */
  29254. 0x01, 0x6c, 0x68, 0x0b, 0xcf, 0x55, 0x25, 0xaf,
  29255. 0x6d, 0x98, 0x48, 0x0a, 0xa8, 0x74, 0xc9, 0xa9,
  29256. 0x17, 0xa0, 0x0c, 0xc3, 0xfb, 0xd3, 0x23, 0x68,
  29257. 0xfe, 0x04, 0x3c, 0x63, 0x50, 0x88, 0x3b, 0xb9,
  29258. 0x4f, 0x7c, 0x67, 0x34, 0xf7, 0x3b, 0xa9, 0x73,
  29259. 0xe7, 0x1b, 0xc3, 0x51, 0x5e, 0x22, 0x18, 0xec
  29260. };
  29261. #endif
  29262. #ifdef HAVE_ECC521
  29263. static const byte p521PubKey[] = {
  29264. /* SECP521R1 */
  29265. /* Qx */
  29266. 0x01, 0x62, 0x6e, 0xf1, 0x00, 0xec, 0xd8, 0x99,
  29267. 0x58, 0x9b, 0x80, 0x6b, 0xfe, 0x2c, 0xf1, 0xb2,
  29268. 0xf0, 0xc8, 0x48, 0xdf, 0xac, 0xd2, 0x3b, 0x71,
  29269. 0x29, 0xab, 0xf0, 0x66, 0x63, 0xd8, 0x8e, 0xb5,
  29270. 0xc8, 0xc2, 0xfc, 0x99, 0x44, 0xe2, 0x45, 0xb1,
  29271. 0x5a, 0x7b, 0xb9, 0x73, 0x01, 0xda, 0x79, 0xec,
  29272. 0x9c, 0x26, 0x27, 0x34, 0x45, 0x26, 0xd5, 0x89,
  29273. 0x4b, 0x44, 0xfe, 0x69, 0x4e, 0x72, 0x14, 0xe3,
  29274. 0x8b, 0xbc,
  29275. /* Qy */
  29276. 0x00, 0x0f, 0x09, 0xa2, 0x03, 0xc3, 0x5a, 0xdc,
  29277. 0x95, 0x82, 0xf6, 0xf9, 0xf6, 0x9c, 0xff, 0xb5,
  29278. 0x6b, 0x75, 0x95, 0x4b, 0xa4, 0x28, 0x5d, 0x9e,
  29279. 0x90, 0x04, 0xd1, 0xc0, 0x1e, 0xd5, 0xfd, 0x43,
  29280. 0x9e, 0x1e, 0x83, 0xc0, 0x11, 0x2b, 0x2b, 0x07,
  29281. 0x6d, 0xa9, 0x7a, 0x10, 0xd7, 0x67, 0xe7, 0x51,
  29282. 0x37, 0x24, 0xd8, 0xbf, 0x03, 0x0d, 0x8b, 0xb5,
  29283. 0x40, 0x5c, 0x4f, 0xd6, 0x13, 0x73, 0x42, 0xbc,
  29284. 0x91, 0xd9
  29285. };
  29286. /* perform verify of signature and hash using public key */
  29287. /* key is public Qx + public Qy */
  29288. /* sig is r + s */
  29289. static wc_test_ret_t crypto_ecc_verify(const byte *key, uint32_t keySz,
  29290. const byte *hash, uint32_t hashSz, const byte *sig, uint32_t sigSz,
  29291. uint32_t curveSz, int curveId)
  29292. {
  29293. wc_test_ret_t ret;
  29294. int verify_res = 0, count = 0;
  29295. mp_int r, s;
  29296. ecc_key ecc;
  29297. ecc_nb_ctx_t nb_ctx;
  29298. /* validate arguments */
  29299. if (key == NULL || hash == NULL || sig == NULL || curveSz == 0 ||
  29300. hashSz == 0 || keySz < (curveSz*2) || sigSz < (curveSz*2))
  29301. {
  29302. return WC_TEST_RET_ENC_NC;
  29303. }
  29304. /* Setup the ECC key */
  29305. ret = wc_ecc_init(&ecc);
  29306. if (ret < 0) {
  29307. return WC_TEST_RET_ENC_EC(ret);
  29308. }
  29309. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29310. if (ret != MP_OKAY) {
  29311. wc_ecc_free(&ecc);
  29312. return WC_TEST_RET_ENC_EC(ret);
  29313. }
  29314. /* Setup the signature r/s variables */
  29315. ret = mp_init(&r);
  29316. if (ret != MP_OKAY) {
  29317. wc_ecc_free(&ecc);
  29318. return WC_TEST_RET_ENC_EC(ret);
  29319. }
  29320. ret = mp_init(&s);
  29321. if (ret != MP_OKAY) {
  29322. mp_clear(&r);
  29323. wc_ecc_free(&ecc);
  29324. return WC_TEST_RET_ENC_EC(ret);
  29325. }
  29326. /* Import public key x/y */
  29327. ret = wc_ecc_import_unsigned(
  29328. &ecc,
  29329. (byte*)key, /* Public "x" Coordinate */
  29330. (byte*)(key + curveSz), /* Public "y" Coordinate */
  29331. NULL, /* Private "d" (optional) */
  29332. curveId /* ECC Curve Id */
  29333. );
  29334. /* Make sure it was a public key imported */
  29335. if (ret == 0 && ecc.type != ECC_PUBLICKEY) {
  29336. ret = WC_TEST_RET_ENC_NC; /* ECC_BAD_ARG_E */
  29337. }
  29338. /* Import signature r/s */
  29339. if (ret == 0) {
  29340. ret = mp_read_unsigned_bin(&r, sig, curveSz);
  29341. if (ret < 0)
  29342. ret = WC_TEST_RET_ENC_EC(ret);
  29343. }
  29344. if (ret == 0) {
  29345. ret = mp_read_unsigned_bin(&s, sig + curveSz, curveSz);
  29346. if (ret < 0)
  29347. ret = WC_TEST_RET_ENC_EC(ret);
  29348. }
  29349. /* Verify ECC Signature */
  29350. if (ret == 0) {
  29351. do {
  29352. ret = wc_ecc_verify_hash_ex(
  29353. &r, &s, /* r/s as mp_int */
  29354. hash, hashSz, /* computed hash digest */
  29355. &verify_res, /* verification result 1=success */
  29356. &ecc
  29357. );
  29358. count++;
  29359. /* This is where real-time work could be called */
  29360. } while (ret == FP_WOULDBLOCK);
  29361. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29362. printf("ECC non-block verify: %d times\n", count);
  29363. #endif
  29364. if (ret < 0)
  29365. ret = WC_TEST_RET_ENC_EC(ret);
  29366. }
  29367. /* check verify result */
  29368. if (ret == 0 && verify_res == 0) {
  29369. ret = WC_TEST_RET_ENC_NC /* SIG_VERIFY_E */;
  29370. }
  29371. mp_clear(&r);
  29372. mp_clear(&s);
  29373. wc_ecc_free(&ecc);
  29374. (void)count;
  29375. return ret;
  29376. }
  29377. /* perform signature operation against hash using private key */
  29378. static wc_test_ret_t crypto_ecc_sign(const byte *key, uint32_t keySz,
  29379. const byte *hash, uint32_t hashSz, byte *sig, uint32_t* sigSz,
  29380. uint32_t curveSz, int curveId, WC_RNG* rng)
  29381. {
  29382. wc_test_ret_t ret;
  29383. int count = 0;
  29384. mp_int r, s;
  29385. ecc_key ecc;
  29386. ecc_nb_ctx_t nb_ctx;
  29387. /* validate arguments */
  29388. if (key == NULL || hash == NULL || sig == NULL || sigSz == NULL ||
  29389. curveSz == 0 || hashSz == 0 || keySz < curveSz || *sigSz < (curveSz*2))
  29390. {
  29391. return WC_TEST_RET_ENC_NC /* BAD_FUNC_ARG */;
  29392. }
  29393. /* Initialize signature result */
  29394. memset(sig, 0, curveSz*2);
  29395. /* Setup the ECC key */
  29396. ret = wc_ecc_init(&ecc);
  29397. if (ret < 0) {
  29398. return WC_TEST_RET_ENC_EC(ret);
  29399. }
  29400. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29401. if (ret != MP_OKAY) {
  29402. wc_ecc_free(&ecc);
  29403. return WC_TEST_RET_ENC_EC(ret);
  29404. }
  29405. /* Setup the signature r/s variables */
  29406. ret = mp_init(&r);
  29407. if (ret != MP_OKAY) {
  29408. wc_ecc_free(&ecc);
  29409. return WC_TEST_RET_ENC_EC(ret);
  29410. }
  29411. ret = mp_init(&s);
  29412. if (ret != MP_OKAY) {
  29413. mp_clear(&r);
  29414. wc_ecc_free(&ecc);
  29415. return WC_TEST_RET_ENC_EC(ret);
  29416. }
  29417. /* Import private key "k" */
  29418. ret = wc_ecc_import_private_key_ex(
  29419. key, keySz, /* private key "d" */
  29420. NULL, 0, /* public (optional) */
  29421. &ecc,
  29422. curveId /* ECC Curve Id */
  29423. );
  29424. if (ret < 0)
  29425. ret = WC_TEST_RET_ENC_EC(ret);
  29426. if (ret == 0) {
  29427. do {
  29428. /* Verify ECC Signature */
  29429. ret = wc_ecc_sign_hash_ex(
  29430. hash, hashSz, /* computed hash digest */
  29431. rng, &ecc, /* random and key context */
  29432. &r, &s /* r/s as mp_int */
  29433. );
  29434. count++;
  29435. /* This is where real-time work could be called */
  29436. } while (ret == FP_WOULDBLOCK);
  29437. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29438. printf("ECC non-block sign: %d times\n", count);
  29439. #endif
  29440. if (ret < 0)
  29441. ret = WC_TEST_RET_ENC_EC(ret);
  29442. }
  29443. if (ret == 0) {
  29444. /* export r/s */
  29445. mp_to_unsigned_bin_len(&r, sig, curveSz);
  29446. mp_to_unsigned_bin_len(&s, sig + curveSz, curveSz);
  29447. }
  29448. mp_clear(&r);
  29449. mp_clear(&s);
  29450. wc_ecc_free(&ecc);
  29451. (void)count;
  29452. return ret;
  29453. }
  29454. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29455. /*
  29456. * This test doesn't work with WOLFSSL_VALIDATE_ECC_KEYGEN defined because we
  29457. * don't have non-blocking versions of the key checking functions, yet.
  29458. */
  29459. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29460. static wc_test_ret_t ecc_test_nonblock_dhe(int curveId, word32 curveSz,
  29461. const byte* privKey, const byte* pubKey, WC_RNG* rng)
  29462. {
  29463. wc_test_ret_t ret;
  29464. ecc_key keyA;
  29465. ecc_key keyB;
  29466. ecc_nb_ctx_t nbCtxA;
  29467. ecc_nb_ctx_t nbCtxB;
  29468. byte secretA[ECC_SHARED_SIZE];
  29469. byte secretB[ECC_SHARED_SIZE];
  29470. word32 secretSzA = ECC_SHARED_SIZE;
  29471. word32 secretSzB = ECC_SHARED_SIZE;
  29472. int count = 0;
  29473. ret = wc_ecc_init(&keyA);
  29474. if (ret == 0) {
  29475. ret = wc_ecc_init(&keyB);
  29476. if (ret < 0)
  29477. ret = WC_TEST_RET_ENC_EC(ret);
  29478. }
  29479. if (ret == 0) {
  29480. ret = wc_ecc_set_nonblock(&keyA, &nbCtxA);
  29481. if (ret < 0)
  29482. ret = WC_TEST_RET_ENC_EC(ret);
  29483. }
  29484. if (ret == 0) {
  29485. ret = wc_ecc_set_nonblock(&keyB, &nbCtxB);
  29486. if (ret < 0)
  29487. ret = WC_TEST_RET_ENC_EC(ret);
  29488. }
  29489. if (ret == 0) {
  29490. do {
  29491. ret = wc_ecc_make_key_ex(rng, curveSz, &keyA, curveId);
  29492. count++;
  29493. } while (ret == FP_WOULDBLOCK);
  29494. if (ret < 0)
  29495. ret = WC_TEST_RET_ENC_EC(ret);
  29496. }
  29497. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29498. fprintf(stderr, "ECC non-block key gen: %d times\n", count);
  29499. #endif
  29500. if (ret == 0) {
  29501. ret = wc_ecc_check_key(&keyA);
  29502. if (ret < 0)
  29503. ret = WC_TEST_RET_ENC_EC(ret);
  29504. }
  29505. if (ret == 0) {
  29506. ret = wc_ecc_import_unsigned(&keyB, pubKey, pubKey + curveSz,
  29507. privKey, curveId);
  29508. if (ret < 0)
  29509. ret = WC_TEST_RET_ENC_EC(ret);
  29510. }
  29511. count = 0;
  29512. if (ret == 0) {
  29513. do {
  29514. ret = wc_ecc_shared_secret(&keyA, &keyB, secretA, &secretSzA);
  29515. count++;
  29516. } while (ret == FP_WOULDBLOCK);
  29517. if (ret < 0)
  29518. ret = WC_TEST_RET_ENC_EC(ret);
  29519. }
  29520. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29521. fprintf(stderr, "ECC non-block shared secret: %d times\n", count);
  29522. #endif
  29523. if (ret == 0) {
  29524. do {
  29525. ret = wc_ecc_shared_secret(&keyB, &keyA, secretB, &secretSzB);
  29526. } while (ret == FP_WOULDBLOCK);
  29527. if (ret < 0)
  29528. ret = WC_TEST_RET_ENC_EC(ret);
  29529. }
  29530. if (ret == 0) {
  29531. if (secretSzA != secretSzB ||
  29532. XMEMCMP(secretA, secretB, secretSzA) != 0) {
  29533. ret = WC_TEST_RET_ENC_NC;
  29534. }
  29535. }
  29536. wc_ecc_free(&keyA);
  29537. wc_ecc_free(&keyB);
  29538. return ret;
  29539. }
  29540. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29541. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29542. static wc_test_ret_t ecc_test_nonblock_ecdsa(int curveId, word32 curveSz,
  29543. const byte* privKey, word32 privKeySz, const byte* pubKey, word32 pubKeySz,
  29544. WC_RNG* rng)
  29545. {
  29546. wc_test_ret_t ret = 0;
  29547. byte* sig = NULL;
  29548. word32 sigSz = curveSz * 2;
  29549. static const byte hash[] = {
  29550. 0x8d, 0x28, 0xa3, 0x8b, 0x0b, 0xa9, 0xfe, 0xd4, 0x0e, 0x54, 0xc4, 0x17,
  29551. 0x3d, 0x54, 0x66, 0x34, 0xbf, 0x5d, 0x6f, 0x46, 0xc2, 0x20, 0xcb, 0xc3,
  29552. 0x22, 0xe9, 0xb0, 0xdf, 0xe7, 0x64, 0x3f, 0xd9
  29553. };
  29554. sig = (byte*)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29555. if (sig == NULL) {
  29556. ret = WC_TEST_RET_ENC_ERRNO;
  29557. }
  29558. if (ret == 0) {
  29559. /* Sign hash using private key */
  29560. /* Note: result of an ECC sign varies for each call even with same
  29561. private key and hash. This is because a new random public key is
  29562. used for each operation. */
  29563. ret = crypto_ecc_sign(privKey, privKeySz, hash, sizeof(hash), sig,
  29564. &sigSz, curveSz, curveId, rng);
  29565. }
  29566. if (ret == 0) {
  29567. /* Verify generated signature is valid */
  29568. ret = crypto_ecc_verify(pubKey, pubKeySz, hash, sizeof(hash), sig,
  29569. sigSz, curveSz, curveId);
  29570. }
  29571. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29572. return ret;
  29573. }
  29574. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29575. static wc_test_ret_t ecc_test_nonblock(WC_RNG* rng)
  29576. {
  29577. wc_test_ret_t ret = 0;
  29578. word32 i;
  29579. int curveIds[3] = {0, 0, 0};
  29580. word32 curveSzs[3] = {0, 0, 0};
  29581. const byte* privKeys[3] = {NULL, NULL, NULL};
  29582. word32 privKeySzs[3] = {0, 0, 0};
  29583. const byte* pubKeys[3] = {NULL, NULL, NULL};
  29584. word32 pubKeySzs[3] = {0, 0, 0};
  29585. curveIds[0] = ECC_SECP256R1;
  29586. curveSzs[0] = 32;
  29587. privKeys[0] = p256PrivKey;
  29588. privKeySzs[0] = sizeof(p256PrivKey);
  29589. pubKeys[0] = p256PubKey;
  29590. pubKeySzs[0] = sizeof(p256PubKey);
  29591. #ifdef HAVE_ECC384
  29592. curveIds[1] = ECC_SECP384R1;
  29593. curveSzs[1] = 48;
  29594. privKeys[1] = p384PrivKey;
  29595. privKeySzs[1] = sizeof(p384PrivKey);
  29596. pubKeys[1] = p384PubKey;
  29597. pubKeySzs[1] = sizeof(p384PubKey);
  29598. #endif
  29599. #ifdef HAVE_ECC521
  29600. curveIds[2] = ECC_SECP521R1;
  29601. curveSzs[2] = 66;
  29602. privKeys[2] = p521PrivKey;
  29603. privKeySzs[2] = sizeof(p521PrivKey);
  29604. pubKeys[2] = p521PubKey;
  29605. pubKeySzs[2] = sizeof(p521PubKey);
  29606. #endif
  29607. for (i = 0; ret == 0 && i < sizeof(curveIds) / sizeof(curveIds[0]); ++i) {
  29608. if (curveIds[i] == 0) {
  29609. continue;
  29610. }
  29611. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29612. ret = ecc_test_nonblock_ecdsa(curveIds[i], curveSzs[i], privKeys[i],
  29613. privKeySzs[i], pubKeys[i], pubKeySzs[i], rng);
  29614. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29615. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29616. if (ret == 0) {
  29617. ret = ecc_test_nonblock_dhe(curveIds[i], curveSzs[i], privKeys[i],
  29618. pubKeys[i], rng);
  29619. }
  29620. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29621. }
  29622. return ret;
  29623. }
  29624. #endif /* WC_ECC_NONBLOCK && WOLFSSL_HAVE_SP_ECC && WOLFSSL_PUBLIC_MP */
  29625. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29626. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29627. (HAVE_FIPS_VERSION > 2)))
  29628. static int ecc_test_raw_enc_dec(void)
  29629. {
  29630. int ret;
  29631. unsigned char r[1];
  29632. word32 rSz;
  29633. unsigned char s[1];
  29634. word32 sSz;
  29635. unsigned char rZero[] = { 0, 0, 0, 0 };
  29636. unsigned char sOne[] = { 0, 0, 1 };
  29637. unsigned char sigRaw[32];
  29638. word32 sigRawSz;
  29639. unsigned char expSig[] = { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01 };
  29640. sigRawSz = sizeof(sigRaw);
  29641. ret = wc_ecc_rs_raw_to_sig(rZero, sizeof(rZero), sOne, sizeof(sOne),
  29642. sigRaw, &sigRawSz);
  29643. if (ret != 0) {
  29644. return WC_TEST_RET_ENC_EC(ret);
  29645. }
  29646. if (sigRawSz != sizeof(expSig)) {
  29647. return WC_TEST_RET_ENC_EC((int)sigRawSz);
  29648. }
  29649. if (XMEMCMP(sigRaw, expSig, sizeof(expSig)) != 0) {
  29650. return WC_TEST_RET_ENC_NC;
  29651. }
  29652. rSz = sizeof(r);
  29653. sSz = sizeof(s);
  29654. ret = wc_ecc_sig_to_rs(sigRaw, sigRawSz, r, &rSz, s, &sSz);
  29655. if (ret != 0) {
  29656. return WC_TEST_RET_ENC_EC(ret);
  29657. }
  29658. if (rSz != 1) {
  29659. return WC_TEST_RET_ENC_EC((int)rSz);
  29660. }
  29661. if (sSz != 1) {
  29662. return WC_TEST_RET_ENC_EC((int)sSz);
  29663. }
  29664. if (r[0] != 0) {
  29665. return WC_TEST_RET_ENC_EC(r[0]);
  29666. }
  29667. if (s[0] != 1) {
  29668. return WC_TEST_RET_ENC_EC(s[0]);
  29669. }
  29670. return ret;
  29671. }
  29672. #endif
  29673. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void)
  29674. {
  29675. wc_test_ret_t ret;
  29676. WC_RNG rng;
  29677. WOLFSSL_ENTER("ecc_test");
  29678. #if defined(ECC_MIN_KEY_SZ)
  29679. WOLFSSL_MSG_EX("ecc_test ECC_MIN_KEY_SZ = %d\n", ECC_MIN_KEY_SZ);
  29680. #else
  29681. WOLFSSL_MSG("ecc_test ECC_MIN_KEY_SZ not defined.");
  29682. #endif
  29683. #if defined(WOLFSSL_CERT_EXT) && \
  29684. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29685. ret = ecc_decode_test();
  29686. if (ret < 0)
  29687. return ret;
  29688. #endif
  29689. #ifndef HAVE_FIPS
  29690. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  29691. #else
  29692. ret = wc_InitRng(&rng);
  29693. #endif
  29694. #ifndef WC_NO_RNG
  29695. if (ret != 0)
  29696. return WC_TEST_RET_ENC_EC(ret);
  29697. #else
  29698. (void)ret;
  29699. #endif
  29700. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  29701. ret = ecc_test_curve(&rng, 14, ECC_CURVE_DEF);
  29702. if (ret < 0) {
  29703. printf("keySize=14, Default\n");
  29704. goto done;
  29705. }
  29706. #endif /* HAVE_ECC112 */
  29707. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  29708. ret = ecc_test_curve(&rng, 16, ECC_CURVE_DEF);
  29709. if (ret < 0) {
  29710. printf("keySize=16, Default\n");
  29711. goto done;
  29712. }
  29713. #endif /* HAVE_ECC128 */
  29714. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  29715. ret = ecc_test_curve(&rng, 20, ECC_CURVE_DEF);
  29716. if (ret < 0) {
  29717. printf("keySize=20, Default\n");
  29718. goto done;
  29719. }
  29720. #endif /* HAVE_ECC160 */
  29721. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  29722. #if !FIPS_VERSION3_GE(6,0,0)
  29723. ret = ecc_test_curve(&rng, 24, ECC_CURVE_DEF);
  29724. if (ret < 0) {
  29725. printf("keySize=24, Default\n");
  29726. goto done;
  29727. }
  29728. #endif
  29729. #endif /* HAVE_ECC192 */
  29730. #if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224
  29731. ret = ecc_test_curve(&rng, 28, ECC_CURVE_DEF);
  29732. if (ret < 0) {
  29733. printf("keySize=28, Default\n");
  29734. goto done;
  29735. }
  29736. #endif /* HAVE_ECC224 */
  29737. #if (defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 239
  29738. ret = ecc_test_curve(&rng, 30, ECC_CURVE_DEF);
  29739. if (ret < 0) {
  29740. printf("keySize=30, Default\n");
  29741. goto done;
  29742. }
  29743. #endif /* HAVE_ECC239 */
  29744. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29745. ret = ecc_test_curve(&rng, 32, ECC_CURVE_DEF);
  29746. if (ret < 0) {
  29747. printf("keySize=32, Default\n");
  29748. goto done;
  29749. }
  29750. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29751. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  29752. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  29753. ret = ecc_point_test();
  29754. if (ret < 0) {
  29755. goto done;
  29756. }
  29757. #endif
  29758. #if !defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES)
  29759. ret = ecc_def_curve_test(&rng);
  29760. if (ret < 0) {
  29761. printf("Default\n");
  29762. goto done;
  29763. }
  29764. #endif
  29765. #endif /* !NO_ECC256 */
  29766. #if (defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 320
  29767. ret = ecc_test_curve(&rng, 40, ECC_CURVE_DEF);
  29768. if (ret < 0) {
  29769. printf("keySize=40, Default\n");
  29770. goto done;
  29771. }
  29772. #endif /* HAVE_ECC320 */
  29773. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  29774. ret = ecc_test_curve(&rng, 48, ECC_CURVE_DEF);
  29775. if (ret < 0) {
  29776. printf("keySize=48, Default\n");
  29777. goto done;
  29778. }
  29779. #endif /* HAVE_ECC384 */
  29780. #if (defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 512
  29781. ret = ecc_test_curve(&rng, 64, ECC_CURVE_DEF);
  29782. if (ret < 0) {
  29783. printf("keySize=64, Default\n");
  29784. goto done;
  29785. }
  29786. #endif /* HAVE_ECC512 */
  29787. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  29788. ret = ecc_test_curve(&rng, 66, ECC_CURVE_DEF);
  29789. if (ret < 0) {
  29790. printf("keySize=66, Default\n");
  29791. goto done;
  29792. }
  29793. #endif /* HAVE_ECC521 */
  29794. #ifdef WOLFSSL_SM2
  29795. ret = ecc_test_curve(&rng, 32, ECC_SM2P256V1);
  29796. if (ret < 0) {
  29797. printf("SM2\n");
  29798. goto done;
  29799. }
  29800. #endif
  29801. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29802. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29803. (HAVE_FIPS_VERSION > 2)))
  29804. ret = ecc_test_raw_enc_dec();
  29805. if (ret != 0) {
  29806. printf("raw sig encode/decode\n");
  29807. goto done;
  29808. }
  29809. #endif
  29810. #if defined(WOLFSSL_CUSTOM_CURVES)
  29811. ret = ecc_test_custom_curves(&rng);
  29812. if (ret != 0) {
  29813. printf("Custom\n");
  29814. goto done;
  29815. }
  29816. #endif
  29817. #if defined(WOLFSSL_SM2)
  29818. ret = test_sm2_verify();
  29819. if (ret != 0) {
  29820. printf("SM2 Verify\n");
  29821. goto done;
  29822. }
  29823. ret = ecc_sm2_test_curve(&rng, ECC_TEST_VERIFY_COUNT);
  29824. if (ret != 0) {
  29825. printf("SM2 test\n");
  29826. goto done;
  29827. }
  29828. #endif
  29829. #if defined(HAVE_ECC_SIGN) && \
  29830. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  29831. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  29832. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  29833. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29834. ret = ecc_test_deterministic_k(&rng);
  29835. if (ret != 0) {
  29836. printf("ecc_test_deterministic_k failed!\n");
  29837. goto done;
  29838. }
  29839. #endif
  29840. #ifdef WOLFSSL_PUBLIC_MP
  29841. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  29842. ECC_MIN_KEY_SZ <= 384
  29843. ret = ecc384_test_deterministic_k(&rng);
  29844. if (ret != 0) {
  29845. printf("ecc384_test_deterministic_k failed!\n");
  29846. goto done;
  29847. }
  29848. #endif
  29849. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && \
  29850. ECC_MIN_KEY_SZ <= 521
  29851. ret = ecc521_test_deterministic_k(&rng);
  29852. if (ret != 0) {
  29853. printf("ecc512_test_deterministic_k failed!\n");
  29854. goto done;
  29855. }
  29856. #endif
  29857. #endif
  29858. #endif
  29859. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  29860. !defined(WOLFSSL_KCAPI_ECC)
  29861. ret = ecc_test_sign_vectors(&rng);
  29862. if (ret != 0) {
  29863. printf("ecc_test_sign_vectors failed!\n");
  29864. goto done;
  29865. }
  29866. #endif
  29867. #if defined(HAVE_ECC_VECTOR_TEST) && defined(HAVE_ECC_CDH) && \
  29868. defined(HAVE_ECC_DHE)
  29869. ret = ecc_test_cdh_vectors(&rng);
  29870. if (ret != 0) {
  29871. printf("ecc_test_cdh_vectors failed!\n");
  29872. goto done;
  29873. }
  29874. #endif
  29875. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29876. !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
  29877. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  29878. ret = ecc_test_make_pub(&rng);
  29879. if (ret != 0) {
  29880. printf("ecc_test_make_pub failed!\n");
  29881. goto done;
  29882. }
  29883. #elif defined(HAVE_ECC_KEY_IMPORT)
  29884. (void)ecc_test_make_pub; /* for compiler warning */
  29885. #endif
  29886. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  29887. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  29888. ret = ecc_test_cert_gen(&rng);
  29889. if (ret != 0) {
  29890. printf("ecc_test_cert_gen failed!\n");
  29891. goto done;
  29892. }
  29893. #endif
  29894. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) && \
  29895. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && (!defined(NO_ECC_SECP) || \
  29896. defined(WOLFSSL_CUSTOM_CURVES))
  29897. ret = ecc_test_allocator(&rng);
  29898. if (ret != 0) {
  29899. printf("ecc_test_allocator failed!\n");
  29900. goto done;
  29901. }
  29902. #endif
  29903. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  29904. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29905. ret = ecc_test_nonblock(&rng);
  29906. if (ret != 0) {
  29907. printf("ecc_test_nonblock failed!\n");
  29908. goto done;
  29909. }
  29910. #endif
  29911. done:
  29912. wc_FreeRng(&rng);
  29913. return ret;
  29914. }
  29915. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  29916. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  29917. #if !defined(WOLFSSL_NO_MALLOC)
  29918. #if ((! defined(HAVE_FIPS)) || FIPS_VERSION_GE(5,3))
  29919. /* maximum encrypted message:
  29920. * msgSz (14) + pad (2) + pubKeySz(1+66*2) + ivSz(16) + digestSz(32) = 197 */
  29921. #define MAX_ECIES_TEST_SZ 200
  29922. static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
  29923. {
  29924. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29925. byte* plaintext;
  29926. byte* encrypted;
  29927. byte* decrypted;
  29928. #else
  29929. byte plaintext[MAX_ECIES_TEST_SZ];
  29930. byte encrypted[MAX_ECIES_TEST_SZ];
  29931. byte decrypted[MAX_ECIES_TEST_SZ];
  29932. #endif
  29933. ecEncCtx* aCtx = NULL;
  29934. ecEncCtx* bCtx = NULL;
  29935. static const byte salt[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  29936. 14, 15};
  29937. wc_test_ret_t ret = 0;
  29938. static const char message[] = "Hello wolfSSL!";
  29939. word32 plaintextLen;
  29940. word32 encryptLen = MAX_ECIES_TEST_SZ;
  29941. word32 decryptLen = MAX_ECIES_TEST_SZ;
  29942. int aInit = 0;
  29943. int bInit = 0;
  29944. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29945. plaintext = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29946. encrypted = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29947. decrypted = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29948. #endif
  29949. wc_ecc_free(a);
  29950. wc_ecc_free(b);
  29951. ret = wc_ecc_init(a);
  29952. if (ret != 0) {
  29953. ret = WC_TEST_RET_ENC_EC(ret);
  29954. }
  29955. else {
  29956. aInit = 1;
  29957. }
  29958. if (ret == 0) {
  29959. ret = wc_ecc_init(b);
  29960. if (ret != 0) {
  29961. ret = WC_TEST_RET_ENC_EC(ret);
  29962. }
  29963. else {
  29964. bInit = 1;
  29965. }
  29966. }
  29967. if (ret == 0)
  29968. ret = wc_ecc_make_key(rng, 32, a);
  29969. if (ret == 0)
  29970. ret = wc_ecc_make_key(rng, 32, b);
  29971. /* create context */
  29972. if (ret == 0) {
  29973. aCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  29974. if (aCtx == NULL)
  29975. ret = WC_TEST_RET_ENC_NC;
  29976. }
  29977. if (ret == 0) {
  29978. bCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  29979. if (bCtx == NULL)
  29980. ret = WC_TEST_RET_ENC_NC;
  29981. }
  29982. /* set salt */
  29983. if (ret == 0) {
  29984. ret = wc_ecc_ctx_set_kdf_salt(aCtx, salt, sizeof(salt));
  29985. if (ret != 0)
  29986. ret = 10472;
  29987. }
  29988. if (ret == 0) {
  29989. ret = wc_ecc_ctx_set_kdf_salt(bCtx, salt, sizeof(salt));
  29990. if (ret != 0)
  29991. ret = 10473;
  29992. }
  29993. XMEMSET(plaintext, 0, MAX_ECIES_TEST_SZ);
  29994. XSTRLCPY((char *)plaintext, message, sizeof plaintext);
  29995. plaintextLen = (((word32)XSTRLEN(message) + WC_AES_BLOCK_SIZE - 1) /
  29996. WC_AES_BLOCK_SIZE) * WC_AES_BLOCK_SIZE;
  29997. /* encrypt */
  29998. if (ret == 0) {
  29999. ret = wc_ecc_encrypt(a, b, plaintext, plaintextLen, encrypted,
  30000. &encryptLen, aCtx);
  30001. if (ret != 0)
  30002. ret = WC_TEST_RET_ENC_EC(ret);
  30003. }
  30004. /* decrypt */
  30005. if (ret == 0) {
  30006. ret = wc_ecc_decrypt(b, a, encrypted, encryptLen, decrypted,
  30007. &decryptLen, bCtx);
  30008. if (ret != 0)
  30009. ret = WC_TEST_RET_ENC_EC(ret);
  30010. }
  30011. /* compare */
  30012. if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
  30013. ret = WC_TEST_RET_ENC_NC;
  30014. if (aInit) {
  30015. wc_ecc_free(a);
  30016. }
  30017. if (bInit) {
  30018. wc_ecc_free(b);
  30019. }
  30020. wc_ecc_ctx_free(aCtx);
  30021. wc_ecc_ctx_free(bCtx);
  30022. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30023. XFREE(plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30024. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30025. XFREE(decrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30026. #endif
  30027. return ret;
  30028. }
  30029. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30030. #endif /* !WOLFSSL_NO_MALLOC */
  30031. /* ecc_encrypt_e2e_test() uses wc_ecc_ctx_set_algo(), which was added in
  30032. * wolfFIPS 5.3.
  30033. * ecc_encrypt_kat() is used only by ecc_encrypt_e2e_test().
  30034. */
  30035. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30036. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30037. ECC_MIN_KEY_SZ <= 256 && defined(WOLFSSL_AES_128)
  30038. static wc_test_ret_t ecc_encrypt_kat(WC_RNG *rng)
  30039. {
  30040. wc_test_ret_t ret = 0;
  30041. #ifdef WOLFSSL_ECIES_OLD
  30042. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30043. ecc_key* userA = NULL;
  30044. #else
  30045. ecc_key userA[1];
  30046. #endif
  30047. int userAInit = 0;
  30048. #endif
  30049. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30050. ecc_key* userB = NULL;
  30051. #else
  30052. ecc_key userB[1];
  30053. #endif
  30054. int userBInit = 0;
  30055. ecc_key* tmpKey;
  30056. byte plain[48];
  30057. word32 plainSz = sizeof(plain);
  30058. WOLFSSL_SMALL_STACK_STATIC const byte privKey[] = {
  30059. 0x04, 0x80, 0xef, 0x1d, 0xbe, 0x02, 0x0c, 0x20,
  30060. 0x5b, 0xab, 0x80, 0x35, 0x5b, 0x2a, 0x0f, 0x6d,
  30061. 0xd3, 0xb0, 0x7f, 0x7e, 0x7f, 0x86, 0x8a, 0x49,
  30062. 0xee, 0xb4, 0xaa, 0x09, 0x2d, 0x1e, 0x1d, 0x02
  30063. };
  30064. #if defined(WOLFSSL_ECIES_OLD) || defined(WOLFSSL_QNX_CAAM)
  30065. WOLFSSL_SMALL_STACK_STATIC const byte pubKey[] = {
  30066. 0x04,
  30067. /* X */
  30068. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30069. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30070. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30071. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30072. /* X */
  30073. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30074. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30075. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30076. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28
  30077. };
  30078. #endif
  30079. WOLFSSL_SMALL_STACK_STATIC const byte enc_msg[] = {
  30080. #ifdef WOLFSSL_ECIES_OLD
  30081. 0x42, 0x70, 0xbf, 0xf9, 0xf4, 0x7e, 0x4b, 0x9b,
  30082. 0xb5, 0x4c, 0xcc, 0xc5, 0x94, 0xa7, 0xef, 0xaa,
  30083. 0xc3, 0x7c, 0x85, 0xa6, 0x51, 0x6e, 0xd3, 0xfa,
  30084. 0x56, 0xc9, 0x10, 0x4d, 0x14, 0x32, 0x61, 0xb8,
  30085. 0xbb, 0x66, 0x7a, 0xb5, 0xbc, 0x95, 0xf8, 0xca,
  30086. 0xd1, 0x2a, 0x19, 0x51, 0x44, 0xd8, 0x0e, 0x57,
  30087. 0x34, 0xed, 0x45, 0x89, 0x2e, 0x57, 0xbe, 0xd5,
  30088. 0x06, 0x22, 0xd7, 0x13, 0x0a, 0x0e, 0x40, 0x36,
  30089. 0x0d, 0x05, 0x0d, 0xb6, 0xae, 0x61, 0x37, 0x18,
  30090. 0x83, 0x90, 0x0a, 0x27, 0x95, 0x41, 0x8c, 0x45
  30091. #elif defined(WOLFSSL_ECIES_ISO18033)
  30092. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30093. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30094. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30095. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30096. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30097. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30098. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30099. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30100. 0x28, 0xbb, 0x9f, 0xa8, 0x2d, 0xe1, 0xf1, 0x67,
  30101. 0x45, 0x02, 0x19, 0xdc, 0xc8, 0x24, 0x8b, 0x20,
  30102. 0x02, 0xa0, 0x8f, 0x95, 0x12, 0x55, 0x51, 0xf8,
  30103. 0x03, 0xc4, 0x54, 0x13, 0x98, 0x2d, 0xf0, 0x31,
  30104. 0x51, 0x80, 0x45, 0x24, 0xcb, 0x8b, 0x48, 0xa6,
  30105. 0x8b, 0x8e, 0x97, 0x9c, 0x56, 0x4d, 0x70, 0x00,
  30106. 0x53, 0xd3, 0x47, 0x00, 0x5a, 0x23, 0x8c, 0xf9,
  30107. 0xfd, 0xd2, 0x33, 0x2c, 0x43, 0x6e, 0x9e, 0xb2,
  30108. 0xf4, 0x95, 0xd4, 0xcf, 0x30, 0xd6, 0xa2, 0xc5,
  30109. 0x35, 0x96, 0x6a, 0xd4, 0x36, 0x15, 0xa9, 0xbd,
  30110. 0x7f
  30111. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30112. /* EC P-256 point */
  30113. 0x04,
  30114. /* X */
  30115. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30116. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30117. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30118. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30119. /* Y */
  30120. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30121. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30122. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30123. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28,
  30124. /* IV */
  30125. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30126. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30127. /* Encrypted Msg */
  30128. 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d, 0x50,
  30129. 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c, 0x1f,
  30130. 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc, 0x44,
  30131. 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca, 0x65,
  30132. 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61, 0xbd,
  30133. 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1, 0xde,
  30134. /* HMAC */
  30135. 0x5a, 0x22, 0xc1, 0x5d, 0x99, 0x66, 0x3f, 0x24,
  30136. 0x35, 0x96, 0xac, 0xf7, 0xf6, 0x28, 0x45, 0x16,
  30137. 0x52, 0x19, 0x0d, 0xe4, 0xb2, 0xca, 0x5b, 0x28,
  30138. 0x4e, 0xbb, 0xf3, 0x98, 0x57, 0xd7, 0x3b, 0xe2
  30139. #else
  30140. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30141. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30142. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30143. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30144. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30145. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30146. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30147. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30148. 0x28, 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d,
  30149. 0x50, 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c,
  30150. 0x1f, 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc,
  30151. 0x44, 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca,
  30152. 0x65, 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61,
  30153. 0xbd, 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1,
  30154. 0xde, 0xc7, 0x3f, 0x6f, 0xce, 0xbe, 0x49, 0x61,
  30155. 0x48, 0x01, 0x77, 0x41, 0xd0, 0xd8, 0x5b, 0x48,
  30156. 0xca, 0x4e, 0x47, 0x3e, 0x47, 0xbf, 0x1d, 0x28,
  30157. 0x4c, 0x18, 0x1a, 0xfb, 0x96, 0x95, 0xda, 0xde,
  30158. 0x55
  30159. #endif
  30160. };
  30161. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  30162. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  30163. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  30164. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  30165. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  30166. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  30167. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  30168. };
  30169. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30170. userB = (ecc_key *)XMALLOC(sizeof(*userB), HEAP_HINT,
  30171. DYNAMIC_TYPE_TMP_BUFFER);
  30172. if (userB == NULL) {
  30173. ret = WC_TEST_RET_ENC_ERRNO;
  30174. }
  30175. #ifdef WOLFSSL_ECIES_OLD
  30176. if (ret == 0) {
  30177. userA = (ecc_key *)XMALLOC(sizeof(*userA), HEAP_HINT,
  30178. DYNAMIC_TYPE_TMP_BUFFER);
  30179. if (userA == NULL) {
  30180. ret = WC_TEST_RET_ENC_ERRNO;
  30181. }
  30182. }
  30183. #endif
  30184. #endif
  30185. if (ret == 0) {
  30186. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30187. if (ret != 0)
  30188. ret = WC_TEST_RET_ENC_EC(ret);
  30189. }
  30190. if (ret == 0) {
  30191. userBInit = 1;
  30192. #ifdef WOLFSSL_ECIES_OLD
  30193. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30194. if (ret != 0)
  30195. ret = WC_TEST_RET_ENC_EC(ret);
  30196. }
  30197. if (ret == 0) {
  30198. userAInit = 1;
  30199. tmpKey = userA;
  30200. #else
  30201. tmpKey = NULL;
  30202. #endif
  30203. }
  30204. if (ret == 0) {
  30205. #ifdef WOLFSSL_QNX_CAAM
  30206. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), pubKey,
  30207. sizeof(pubKey), userB, ECC_SECP256R1);
  30208. #else
  30209. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), NULL, 0,
  30210. userB, ECC_SECP256R1);
  30211. #endif
  30212. if (ret != 0)
  30213. ret = WC_TEST_RET_ENC_EC(ret);
  30214. }
  30215. #ifdef WOLFSSL_ECIES_OLD
  30216. if (ret == 0) {
  30217. ret = wc_ecc_import_x963_ex(pubKey, sizeof(pubKey), userA,
  30218. ECC_SECP256R1);
  30219. if (ret != 0)
  30220. ret = WC_TEST_RET_ENC_EC(ret);
  30221. }
  30222. #endif
  30223. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30224. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30225. !defined(HAVE_SELFTEST)
  30226. if (ret == 0) {
  30227. ret = wc_ecc_set_rng(userB, rng);
  30228. if (ret != 0) {
  30229. ret = WC_TEST_RET_ENC_EC(ret);
  30230. }
  30231. }
  30232. #else
  30233. (void)rng;
  30234. #endif
  30235. if (ret == 0) {
  30236. ret = wc_ecc_decrypt(userB, tmpKey, enc_msg, sizeof(enc_msg), plain,
  30237. &plainSz, NULL);
  30238. if (ret != 0)
  30239. ret = WC_TEST_RET_ENC_EC(ret);
  30240. }
  30241. if (ret == 0) {
  30242. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30243. ret = WC_TEST_RET_ENC_NC;
  30244. }
  30245. }
  30246. if (userBInit)
  30247. wc_ecc_free(userB);
  30248. #ifdef WOLFSSL_ECIES_OLD
  30249. if (userAInit)
  30250. wc_ecc_free(userA);
  30251. #endif
  30252. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30253. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30254. #ifdef WOLFSSL_ECIES_OLD
  30255. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30256. #endif
  30257. #endif
  30258. return ret;
  30259. }
  30260. #endif
  30261. #ifndef WOLFSSL_NO_MALLOC
  30262. static wc_test_ret_t ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB,
  30263. byte encAlgo, byte kdfAlgo, byte macAlgo)
  30264. {
  30265. wc_test_ret_t ret = 0;
  30266. byte msg[48];
  30267. byte plain[48];
  30268. #ifdef WOLFSSL_ECIES_OLD
  30269. byte out[80];
  30270. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30271. byte out[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30272. #else
  30273. byte out[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30274. #endif
  30275. word32 outSz = sizeof(out);
  30276. word32 plainSz = sizeof(plain);
  30277. int i;
  30278. ecEncCtx* cliCtx = NULL;
  30279. ecEncCtx* srvCtx = NULL;
  30280. byte cliSalt[EXCHANGE_SALT_SZ];
  30281. byte srvSalt[EXCHANGE_SALT_SZ];
  30282. const byte* tmpSalt;
  30283. byte msg2[48];
  30284. byte plain2[48];
  30285. #ifdef WOLFSSL_ECIES_OLD
  30286. byte out2[80];
  30287. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30288. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30289. #else
  30290. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30291. #endif
  30292. word32 outSz2 = sizeof(out2);
  30293. word32 plainSz2 = sizeof(plain2);
  30294. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30295. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof(ecc_key), HEAP_HINT,
  30296. DYNAMIC_TYPE_TMP_BUFFER);
  30297. #else
  30298. ecc_key tmpKey[1];
  30299. #endif
  30300. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30301. if (tmpKey == NULL) {
  30302. ERROR_OUT(MEMORY_E, done);
  30303. }
  30304. #endif
  30305. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30306. if (ret != 0)
  30307. goto done;
  30308. /* set message to incrementing 0,1,2,etc... */
  30309. for (i = 0; i < (int)sizeof(msg); i++)
  30310. msg[i] = i;
  30311. /* encrypt msg to B */
  30312. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz, NULL);
  30313. if (ret != 0) {
  30314. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30315. }
  30316. #ifdef WOLFSSL_ECIES_OLD
  30317. tmpKey->dp = userA->dp;
  30318. ret = wc_ecc_copy_point(&userA->pubkey, &tmpKey->pubkey);
  30319. if (ret != 0) {
  30320. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30321. }
  30322. #endif
  30323. /* decrypt msg from A */
  30324. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, NULL);
  30325. if (ret != 0) {
  30326. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30327. }
  30328. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30329. ret = WC_TEST_RET_ENC_NC; goto done;
  30330. }
  30331. #ifndef WOLFSSL_ECIES_OLD
  30332. /* A decrypts msg (response) from B */
  30333. ret = wc_ecc_decrypt(userB, NULL, out, outSz, plain2, &plainSz2, NULL);
  30334. if (ret != 0)
  30335. goto done;
  30336. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30337. ret = WC_TEST_RET_ENC_NC; goto done;
  30338. }
  30339. #endif
  30340. /* let's verify message exchange works, A is client, B is server */
  30341. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30342. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30343. if (cliCtx == NULL || srvCtx == NULL) {
  30344. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30345. }
  30346. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30347. if (ret != 0)
  30348. goto done;
  30349. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30350. if (ret != 0)
  30351. goto done;
  30352. /* get salt to send to peer */
  30353. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30354. if (tmpSalt == NULL) {
  30355. ret = WC_TEST_RET_ENC_NC; goto done;
  30356. }
  30357. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30358. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30359. if (tmpSalt == NULL) {
  30360. ret = WC_TEST_RET_ENC_NC; goto done;
  30361. }
  30362. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30363. /* in actual use, we'd get the peer's salt over the transport */
  30364. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30365. if (ret != 0)
  30366. goto done;
  30367. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30368. if (ret != 0)
  30369. goto done;
  30370. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 11);
  30371. if (ret != 0)
  30372. goto done;
  30373. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 11);
  30374. if (ret != 0)
  30375. goto done;
  30376. /* get encrypted msg (request) to send to B */
  30377. outSz = sizeof(out);
  30378. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz,cliCtx);
  30379. if (ret != 0)
  30380. goto done;
  30381. #ifndef WOLFSSL_ECIES_OLD
  30382. wc_ecc_free(tmpKey);
  30383. #endif
  30384. /* B decrypts msg (request) from A */
  30385. plainSz = sizeof(plain);
  30386. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30387. if (ret != 0)
  30388. goto done;
  30389. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30390. ret = WC_TEST_RET_ENC_NC; goto done;
  30391. }
  30392. /* msg2 (response) from B to A */
  30393. for (i = 0; i < (int)sizeof(msg2); i++)
  30394. msg2[i] = i + sizeof(msg2);
  30395. /* get encrypted msg (response) to send to B */
  30396. ret = wc_ecc_encrypt(userB, userA, msg2, sizeof(msg2), out2,
  30397. &outSz2, srvCtx);
  30398. if (ret != 0)
  30399. goto done;
  30400. #ifdef WOLFSSL_ECIES_OLD
  30401. tmpKey->dp = userB->dp;
  30402. ret = wc_ecc_copy_point(&userB->pubkey, &tmpKey->pubkey);
  30403. if (ret != 0) {
  30404. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30405. }
  30406. #else
  30407. wc_ecc_free(tmpKey);
  30408. #endif
  30409. /* A decrypts msg (response) from B */
  30410. ret = wc_ecc_decrypt(userA, tmpKey, out2, outSz2, plain2, &plainSz2,
  30411. cliCtx);
  30412. if (ret != 0)
  30413. goto done;
  30414. if (XMEMCMP(plain2, msg2, sizeof(msg2)) != 0) {
  30415. ret = WC_TEST_RET_ENC_NC; goto done;
  30416. }
  30417. #if defined(HAVE_COMP_KEY) && \
  30418. (! defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  30419. /* Create new client and server contexts. */
  30420. wc_ecc_ctx_free(srvCtx);
  30421. wc_ecc_ctx_free(cliCtx);
  30422. /* let's verify message exchange works, A is client, B is server */
  30423. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30424. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30425. if (cliCtx == NULL || srvCtx == NULL) {
  30426. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30427. }
  30428. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30429. if (ret != 0)
  30430. goto done;
  30431. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30432. if (ret != 0)
  30433. goto done;
  30434. /* get salt to send to peer */
  30435. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30436. if (tmpSalt == NULL) {
  30437. ret = WC_TEST_RET_ENC_NC; goto done;
  30438. }
  30439. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30440. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30441. if (tmpSalt == NULL) {
  30442. ret = WC_TEST_RET_ENC_NC; goto done;
  30443. }
  30444. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30445. /* in actual use, we'd get the peer's salt over the transport */
  30446. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30447. if (ret != 0)
  30448. goto done;
  30449. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30450. if (ret != 0)
  30451. goto done;
  30452. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 12);
  30453. if (ret != 0)
  30454. goto done;
  30455. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 12);
  30456. if (ret != 0)
  30457. goto done;
  30458. /* get encrypted msg (request) to send to B - compressed public key */
  30459. outSz = sizeof(out);
  30460. ret = wc_ecc_encrypt_ex(userA, userB, msg, sizeof(msg), out, &outSz, cliCtx,
  30461. 1);
  30462. if (ret != 0)
  30463. goto done;
  30464. #ifndef WOLFSSL_ECIES_OLD
  30465. wc_ecc_free(tmpKey);
  30466. #endif
  30467. /* B decrypts msg (request) from A - out has a compressed public key */
  30468. plainSz = sizeof(plain);
  30469. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30470. if (ret != 0)
  30471. goto done;
  30472. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30473. ret = WC_TEST_RET_ENC_NC; goto done;
  30474. }
  30475. #endif /* HAVE_COMP_KEY && (!FIPS || FIPS>=5.3) */
  30476. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30477. (ECC_MIN_KEY_SZ <= 256) && defined(WOLFSSL_AES_128)
  30478. ret = ecc_encrypt_kat(rng);
  30479. #endif
  30480. done:
  30481. /* cleanup */
  30482. wc_ecc_ctx_free(srvCtx);
  30483. wc_ecc_ctx_free(cliCtx);
  30484. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30485. if (tmpKey != NULL) {
  30486. wc_ecc_free(tmpKey);
  30487. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30488. }
  30489. #else
  30490. wc_ecc_free(tmpKey);
  30491. #endif
  30492. return ret;
  30493. }
  30494. #endif
  30495. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30496. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void)
  30497. {
  30498. WC_RNG rng;
  30499. wc_test_ret_t ret;
  30500. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30501. ecc_key *userA;
  30502. ecc_key *userB;
  30503. #else
  30504. ecc_key userA[1];
  30505. ecc_key userB[1];
  30506. #endif
  30507. WOLFSSL_ENTER("ecc_encrypt_test");
  30508. #ifndef HAVE_FIPS
  30509. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30510. #else
  30511. ret = wc_InitRng(&rng);
  30512. #endif
  30513. if (ret != 0)
  30514. return WC_TEST_RET_ENC_EC(ret);
  30515. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30516. userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT,
  30517. DYNAMIC_TYPE_TMP_BUFFER);
  30518. userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT,
  30519. DYNAMIC_TYPE_TMP_BUFFER);
  30520. if ((userA == NULL) || (userB == NULL)) {
  30521. ERROR_OUT(MEMORY_E, done);
  30522. }
  30523. #endif
  30524. XMEMSET(userA, 0, sizeof *userA);
  30525. XMEMSET(userB, 0, sizeof *userB);
  30526. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30527. if (ret != 0)
  30528. goto done;
  30529. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30530. if (ret != 0)
  30531. goto done;
  30532. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userA);
  30533. #if defined(WOLFSSL_ASYNC_CRYPT)
  30534. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  30535. #endif
  30536. if (ret != 0){
  30537. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30538. }
  30539. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userB);
  30540. #if defined(WOLFSSL_ASYNC_CRYPT)
  30541. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  30542. #endif
  30543. if (ret != 0){
  30544. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30545. }
  30546. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30547. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30548. !defined(HAVE_SELFTEST)
  30549. ret = wc_ecc_set_rng(userA, &rng);
  30550. if (ret != 0) {
  30551. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30552. }
  30553. ret = wc_ecc_set_rng(userB, &rng);
  30554. if (ret != 0) {
  30555. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30556. }
  30557. #endif
  30558. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30559. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30560. #ifdef WOLFSSL_AES_128
  30561. if (ret == 0) {
  30562. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30563. ecHKDF_SHA256, ecHMAC_SHA256);
  30564. if (ret != 0) {
  30565. printf("ECIES: AES_128_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30566. }
  30567. }
  30568. #ifdef HAVE_X963_KDF
  30569. if (ret == 0) {
  30570. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30571. ecKDF_X963_SHA256, ecHMAC_SHA256);
  30572. if (ret != 0) {
  30573. printf("ECIES: AES_128_CBC, KDF_X963_SHA256, HMAC_SHA256\n");
  30574. }
  30575. }
  30576. if (ret == 0) {
  30577. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30578. ecKDF_SHA256, ecHMAC_SHA256);
  30579. if (ret != 0) {
  30580. printf("ECIES: AES_128_CBC, KDF_SHA256, HMAC_SHA256\n");
  30581. }
  30582. }
  30583. #endif
  30584. #endif
  30585. #ifdef WOLFSSL_AES_256
  30586. if (ret == 0) {
  30587. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CBC,
  30588. ecHKDF_SHA256, ecHMAC_SHA256);
  30589. if (ret != 0) {
  30590. printf("ECIES: AES_256_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30591. }
  30592. }
  30593. #endif
  30594. #endif
  30595. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && !defined(WOLFSSL_NO_MALLOC)
  30596. #ifdef WOLFSSL_AES_128
  30597. if (ret == 0) {
  30598. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CTR,
  30599. ecHKDF_SHA256, ecHMAC_SHA256);
  30600. if (ret != 0) {
  30601. printf("ECIES: AES_128_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30602. }
  30603. }
  30604. #endif
  30605. #ifdef WOLFSSL_AES_256
  30606. if (ret == 0) {
  30607. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CTR,
  30608. ecHKDF_SHA256, ecHMAC_SHA256);
  30609. if (ret != 0) {
  30610. printf("ECIES: AES_256_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30611. }
  30612. }
  30613. #endif
  30614. #endif /* !NO_AES && WOLFSSL_AES_COUNTER */
  30615. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30616. if (ret == 0) {
  30617. ret = ecc_ctx_kdf_salt_test(&rng, userA, userB);
  30618. }
  30619. #endif
  30620. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30621. done:
  30622. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30623. if (userA != NULL) {
  30624. wc_ecc_free(userA);
  30625. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30626. }
  30627. if (userB != NULL) {
  30628. wc_ecc_free(userB);
  30629. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30630. }
  30631. #else
  30632. wc_ecc_free(userB);
  30633. wc_ecc_free(userA);
  30634. #endif
  30635. wc_FreeRng(&rng);
  30636. return ret;
  30637. }
  30638. #endif /* HAVE_ECC_ENCRYPT && HAVE_AES_CBC && WOLFSSL_AES_128 */
  30639. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  30640. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  30641. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  30642. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  30643. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void)
  30644. {
  30645. size_t bytes;
  30646. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30647. ecc_key *cliKey = (ecc_key *)XMALLOC(sizeof *cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30648. ecc_key *servKey = (ecc_key *)XMALLOC(sizeof *servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30649. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof *tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30650. #else
  30651. ecc_key cliKey[1];
  30652. ecc_key servKey[1];
  30653. ecc_key tmpKey[1];
  30654. #endif
  30655. WC_RNG rng;
  30656. word32 idx = 0;
  30657. wc_test_ret_t ret;
  30658. /* pad our test message to 32 bytes so evenly divisible by AES_BLOCK_SZ */
  30659. byte in[] = "Everyone gets Friday off. ecc p";
  30660. word32 inLen = (word32)XSTRLEN((char*)in);
  30661. byte out[256];
  30662. byte plain[256];
  30663. int verify = 0;
  30664. word32 x;
  30665. WOLFSSL_ENTER("ecc_test_buffers");
  30666. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30667. if ((cliKey == NULL) || (servKey == NULL) || (tmpKey == NULL))
  30668. ERROR_OUT(MEMORY_E, done);
  30669. #endif
  30670. ret = wc_ecc_init_ex(cliKey, HEAP_HINT, devId);
  30671. if (ret != 0)
  30672. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30673. ret = wc_ecc_init_ex(servKey, HEAP_HINT, devId);
  30674. if (ret != 0)
  30675. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30676. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30677. if (ret != 0)
  30678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30679. bytes = (size_t)sizeof_ecc_clikey_der_256;
  30680. /* place client key into ecc_key struct cliKey */
  30681. ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, cliKey,
  30682. (word32)bytes);
  30683. if (ret != 0)
  30684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30685. idx = 0;
  30686. bytes = (size_t)sizeof_ecc_key_der_256;
  30687. /* place server key into ecc_key struct servKey */
  30688. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, servKey,
  30689. (word32)bytes);
  30690. if (ret != 0)
  30691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30692. #ifndef WC_NO_RNG
  30693. #ifndef HAVE_FIPS
  30694. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30695. #else
  30696. ret = wc_InitRng(&rng);
  30697. #endif
  30698. if (ret != 0)
  30699. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30700. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30701. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30702. !defined(HAVE_SELFTEST)
  30703. ret = wc_ecc_set_rng(cliKey, &rng);
  30704. if (ret != 0)
  30705. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30706. ret = wc_ecc_set_rng(servKey, &rng);
  30707. if (ret != 0)
  30708. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30709. #endif
  30710. #endif /* !WC_NO_RNG */
  30711. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_HKDF) && \
  30712. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  30713. {
  30714. word32 y;
  30715. /* test encrypt and decrypt if they're available */
  30716. x = sizeof(out);
  30717. ret = wc_ecc_encrypt(cliKey, servKey, in, sizeof(in), out, &x, NULL);
  30718. if (ret < 0)
  30719. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30720. #ifdef WOLFSSL_ECIES_OLD
  30721. tmpKey->dp = cliKey->dp;
  30722. ret = wc_ecc_copy_point(&cliKey->pubkey, &tmpKey->pubkey);
  30723. if (ret != 0) {
  30724. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30725. }
  30726. #endif
  30727. y = sizeof(plain);
  30728. ret = wc_ecc_decrypt(servKey, tmpKey, out, x, plain, &y, NULL);
  30729. if (ret < 0)
  30730. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30731. if (XMEMCMP(plain, in, inLen))
  30732. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30733. }
  30734. #endif
  30735. x = sizeof(out);
  30736. do {
  30737. #if defined(WOLFSSL_ASYNC_CRYPT)
  30738. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30739. #endif
  30740. if (ret == 0)
  30741. ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, cliKey);
  30742. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30743. if (ret < 0)
  30744. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30745. TEST_SLEEP();
  30746. XMEMSET(plain, 0, sizeof(plain));
  30747. do {
  30748. #if defined(WOLFSSL_ASYNC_CRYPT)
  30749. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30750. #endif
  30751. if (ret == 0)
  30752. ret = wc_ecc_verify_hash(out, x, in, inLen, &verify,
  30753. cliKey);
  30754. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30755. if (ret < 0)
  30756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30757. if (verify != 1)
  30758. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30759. TEST_SLEEP();
  30760. #ifdef WOLFSSL_CERT_EXT
  30761. idx = 0;
  30762. bytes = sizeof_ecc_clikeypub_der_256;
  30763. ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &idx, cliKey,
  30764. (word32) bytes);
  30765. if (ret != 0)
  30766. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30767. #endif
  30768. ret = 0;
  30769. done:
  30770. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30771. if (cliKey != NULL) {
  30772. wc_ecc_free(cliKey);
  30773. XFREE(cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30774. }
  30775. if (servKey != NULL) {
  30776. wc_ecc_free(servKey);
  30777. XFREE(servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30778. }
  30779. if (tmpKey != NULL) {
  30780. wc_ecc_free(tmpKey);
  30781. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30782. }
  30783. #else
  30784. wc_ecc_free(cliKey);
  30785. wc_ecc_free(servKey);
  30786. wc_ecc_free(tmpKey);
  30787. #endif
  30788. wc_FreeRng(&rng);
  30789. return ret;
  30790. }
  30791. #endif /* USE_CERT_BUFFERS_256 && !WOLFSSL_ATECCX08A && !NO_ECC256 */
  30792. #endif /* HAVE_ECC */
  30793. #ifdef HAVE_CURVE25519
  30794. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  30795. defined(HAVE_CURVE25519_KEY_IMPORT)
  30796. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30797. #define X25519_TEST_CNT 5
  30798. #else
  30799. #define X25519_TEST_CNT 1
  30800. #endif
  30801. static wc_test_ret_t curve25519_overflow_test(void)
  30802. {
  30803. /* secret key for party a */
  30804. byte sa[X25519_TEST_CNT][32] = {
  30805. {
  30806. 0x8d,0xaf,0x6e,0x7a,0xc1,0xeb,0x8d,0x30,
  30807. 0x99,0x86,0xd3,0x90,0x47,0x96,0x21,0x3c,
  30808. 0x3a,0x75,0xc0,0x7b,0x75,0x01,0x75,0xa3,
  30809. 0x81,0x4b,0xff,0x5a,0xbc,0x96,0x87,0x28
  30810. },
  30811. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30812. {
  30813. 0x9d,0x63,0x5f,0xce,0xe2,0xe8,0xd7,0xfb,
  30814. 0x68,0x77,0x0e,0x44,0xd1,0xad,0x87,0x2b,
  30815. 0xf4,0x65,0x06,0xb7,0xbb,0xdb,0xbe,0x6e,
  30816. 0x02,0x43,0x24,0xc7,0x3d,0x7b,0x88,0x60
  30817. },
  30818. {
  30819. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30820. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30821. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30822. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30823. },
  30824. {
  30825. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30826. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30827. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30828. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30829. },
  30830. {
  30831. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30832. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30833. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30834. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30835. }
  30836. #endif
  30837. };
  30838. /* public key for party b */
  30839. byte pb[X25519_TEST_CNT][32] = {
  30840. {
  30841. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30842. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30843. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30844. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30845. },
  30846. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30847. {
  30848. /* 0xff first byte in original - invalid! */
  30849. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30850. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30851. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30852. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30853. },
  30854. {
  30855. 0x36,0x1a,0x74,0x87,0x28,0x59,0xe0,0xb6,
  30856. 0xe4,0x2b,0x17,0x9b,0x16,0xb0,0x3b,0xf8,
  30857. 0xb8,0x9f,0x2a,0x8f,0xc5,0x33,0x68,0x4f,
  30858. 0xde,0x4d,0xd8,0x80,0x63,0xe7,0xb4,0x0a
  30859. },
  30860. {
  30861. 0x00,0x80,0x38,0x59,0x19,0x3a,0x66,0x12,
  30862. 0xfd,0xa1,0xec,0x1c,0x40,0x84,0x40,0xbd,
  30863. 0x64,0x10,0x8b,0x53,0x81,0x21,0x03,0x2d,
  30864. 0x7d,0x33,0xb4,0x01,0x57,0x0d,0xe1,0x89
  30865. },
  30866. {
  30867. 0x1d,0xf8,0xf8,0x33,0x89,0x6c,0xb7,0xba,
  30868. 0x94,0x73,0xfa,0xc2,0x36,0xac,0xbe,0x49,
  30869. 0xaf,0x85,0x3e,0x93,0x5f,0xae,0xb2,0xc0,
  30870. 0xc8,0x80,0x8f,0x4a,0xaa,0xd3,0x55,0x2b
  30871. }
  30872. #endif
  30873. };
  30874. /* expected shared key */
  30875. byte ss[X25519_TEST_CNT][32] = {
  30876. {
  30877. 0x5c,0x4c,0x85,0x5f,0xfb,0x20,0x38,0xcc,
  30878. 0x55,0x16,0x5b,0x8a,0xa7,0xed,0x57,0x6e,
  30879. 0x35,0xaa,0x71,0x67,0x85,0x1f,0xb6,0x28,
  30880. 0x17,0x07,0x7b,0xda,0x76,0xdd,0xe0,0xb4
  30881. },
  30882. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30883. {
  30884. 0x33,0xf6,0xc1,0x34,0x62,0x92,0x06,0x02,
  30885. 0x95,0xdb,0x91,0x4c,0x5d,0x52,0x54,0xc7,
  30886. 0xd2,0x5b,0x24,0xb5,0x4f,0x33,0x59,0x79,
  30887. 0x9f,0x6d,0x7e,0x4a,0x4c,0x30,0xd6,0x38
  30888. },
  30889. {
  30890. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30891. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30892. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30893. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02
  30894. },
  30895. {
  30896. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30897. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30898. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30899. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09
  30900. },
  30901. {
  30902. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30903. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30904. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30905. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10
  30906. }
  30907. #endif
  30908. };
  30909. wc_test_ret_t ret = 0;
  30910. int i;
  30911. word32 y;
  30912. byte shared[32];
  30913. curve25519_key userA;
  30914. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  30915. for (i = 0; i < X25519_TEST_CNT; i++) {
  30916. if (wc_curve25519_import_private_raw(sa[i], sizeof(sa[i]), pb[i],
  30917. sizeof(pb[i]), &userA) != 0) {
  30918. ret = WC_TEST_RET_ENC_I(i); break;
  30919. }
  30920. /* test against known test vector */
  30921. XMEMSET(shared, 0, sizeof(shared));
  30922. y = sizeof(shared);
  30923. if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) {
  30924. ret = WC_TEST_RET_ENC_I(i); break;
  30925. }
  30926. if (XMEMCMP(ss[i], shared, y)) {
  30927. ret = WC_TEST_RET_ENC_I(i); break;
  30928. }
  30929. }
  30930. wc_curve25519_free(&userA);
  30931. return ret;
  30932. }
  30933. /* Test the wc_curve25519_check_public API.
  30934. *
  30935. * returns 0 on success and -ve on failure.
  30936. */
  30937. static wc_test_ret_t curve25519_check_public_test(void)
  30938. {
  30939. wc_test_ret_t ret;
  30940. /* Little-endian values that will fail */
  30941. byte fail_le[][CURVE25519_KEYSIZE] = {
  30942. {
  30943. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30944. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30945. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30946. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30947. },
  30948. {
  30949. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30950. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30951. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30952. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30953. },
  30954. {
  30955. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30956. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30957. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30958. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81
  30959. },
  30960. };
  30961. /* Big-endian values that will fail */
  30962. byte fail_be[][CURVE25519_KEYSIZE] = {
  30963. {
  30964. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30965. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30966. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30967. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30968. },
  30969. {
  30970. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30971. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30972. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30973. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30974. },
  30975. {
  30976. 0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30977. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30978. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30979. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30980. },
  30981. };
  30982. /* Good or valid public value */
  30983. byte good[CURVE25519_KEYSIZE] = {
  30984. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30985. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30986. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30987. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30988. };
  30989. int i;
  30990. /* Parameter checks */
  30991. /* NULL pointer */
  30992. ret = wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN);
  30993. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30994. return WC_TEST_RET_ENC_EC(ret);
  30995. }
  30996. ret = wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN);
  30997. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30998. return WC_TEST_RET_ENC_EC(ret);
  30999. }
  31000. /* Length of 0 treated differently to other invalid lengths for TLS */
  31001. ret = wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN);
  31002. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31003. return WC_TEST_RET_ENC_EC(ret);
  31004. ret = wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN);
  31005. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31006. return WC_TEST_RET_ENC_EC(ret);
  31007. /* Length not CURVE25519_KEYSIZE */
  31008. for (i = 1; i < CURVE25519_KEYSIZE + 2; i++) {
  31009. if (i == CURVE25519_KEYSIZE)
  31010. continue;
  31011. if (wc_curve25519_check_public(good, (word32)i, EC25519_LITTLE_ENDIAN) !=
  31012. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31013. return WC_TEST_RET_ENC_I(i);
  31014. }
  31015. if (wc_curve25519_check_public(good, (word32)i, EC25519_BIG_ENDIAN) !=
  31016. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31017. return WC_TEST_RET_ENC_I(i);
  31018. }
  31019. }
  31020. /* Little-endian fail cases */
  31021. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  31022. if (wc_curve25519_check_public(fail_le[i], CURVE25519_KEYSIZE,
  31023. EC25519_LITTLE_ENDIAN) == 0) {
  31024. return WC_TEST_RET_ENC_I(i);
  31025. }
  31026. }
  31027. /* Big-endian fail cases */
  31028. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  31029. if (wc_curve25519_check_public(fail_be[i], CURVE25519_KEYSIZE,
  31030. EC25519_BIG_ENDIAN) == 0) {
  31031. return WC_TEST_RET_ENC_I(i);
  31032. }
  31033. }
  31034. /* Check a valid public value works! */
  31035. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31036. EC25519_LITTLE_ENDIAN);
  31037. if (ret != 0) {
  31038. return WC_TEST_RET_ENC_EC(ret);
  31039. }
  31040. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31041. EC25519_BIG_ENDIAN);
  31042. if (ret != 0) {
  31043. return WC_TEST_RET_ENC_EC(ret);
  31044. }
  31045. return 0;
  31046. }
  31047. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31048. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31049. defined(HAVE_CURVE25519_KEY_IMPORT)
  31050. static wc_test_ret_t curve255519_der_test(void)
  31051. {
  31052. wc_test_ret_t ret = 0;
  31053. /* certs/statickeys/x25519.der */
  31054. const byte kCurve25519PrivDer[] = {
  31055. 0x30, 0x2E, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E,
  31056. 0x04, 0x22, 0x04, 0x20, 0x78, 0x8E, 0x31, 0x5C, 0x33, 0xA9, 0x19, 0xC0,
  31057. 0x5E, 0x36, 0x70, 0x1B, 0xA4, 0xE8, 0xEF, 0xC1, 0x89, 0x8C, 0xB3, 0x15,
  31058. 0xC6, 0x79, 0xD3, 0xAC, 0x22, 0x00, 0xAE, 0xFA, 0xB3, 0xB7, 0x0F, 0x78
  31059. };
  31060. /* certs/statickeys/x25519-pub.der */
  31061. const byte kCurve25519PubDer[] = {
  31062. 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00,
  31063. 0x09, 0xBC, 0x8C, 0xC7, 0x45, 0x0D, 0xC1, 0xC2, 0x02, 0x57, 0x9A, 0x68,
  31064. 0x3A, 0xFD, 0x7A, 0xA8, 0xA5, 0x2F, 0xF0, 0x99, 0x39, 0x98, 0xEA, 0x26,
  31065. 0xA2, 0x5B, 0x38, 0xFD, 0x96, 0xDB, 0x2A, 0x26
  31066. };
  31067. curve25519_key key;
  31068. byte output[128];
  31069. word32 outputSz = 128;
  31070. word32 idx;
  31071. ret = wc_curve25519_init_ex(&key, HEAP_HINT, devId);
  31072. if (ret != 0)
  31073. return WC_TEST_RET_ENC_EC(ret);
  31074. /* Test decode / encode of Curve25519 private key only */
  31075. if (ret == 0) {
  31076. idx = 0;
  31077. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx, &key,
  31078. (word32)sizeof(kCurve25519PrivDer));
  31079. if (ret < 0)
  31080. ret = WC_TEST_RET_ENC_EC(ret);
  31081. }
  31082. if (ret == 0) {
  31083. outputSz = (word32)sizeof(output);
  31084. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31085. if (ret >= 0) {
  31086. outputSz = (word32)ret;
  31087. ret = 0;
  31088. }
  31089. else {
  31090. ret = WC_TEST_RET_ENC_EC(ret);
  31091. }
  31092. }
  31093. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31094. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31095. ret = WC_TEST_RET_ENC_NC;
  31096. }
  31097. /* Test decode / encode of Curve25519 public key only */
  31098. if (ret == 0) {
  31099. idx = 0;
  31100. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx, &key,
  31101. (word32)sizeof(kCurve25519PubDer));
  31102. if (ret < 0)
  31103. ret = WC_TEST_RET_ENC_EC(ret);
  31104. }
  31105. if (ret == 0) {
  31106. outputSz = (word32)sizeof(output);
  31107. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31108. if (ret >= 0) {
  31109. outputSz = (word32)ret;
  31110. ret = 0;
  31111. }
  31112. else {
  31113. ret = WC_TEST_RET_ENC_EC(ret);
  31114. }
  31115. }
  31116. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31117. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31118. ret = WC_TEST_RET_ENC_NC;
  31119. }
  31120. /* Test decode/encode of Curve25519 private key (only) using generic API */
  31121. if (ret == 0) {
  31122. /* clear key, since generic API will try to decode all fields */
  31123. XMEMSET(&key, 0, sizeof(key));
  31124. idx = 0;
  31125. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31126. (word32)sizeof(kCurve25519PrivDer));
  31127. if (ret < 0) {
  31128. ret = WC_TEST_RET_ENC_EC(ret);
  31129. }
  31130. }
  31131. if (ret == 0) {
  31132. outputSz = (word32)sizeof(output);
  31133. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31134. if (ret >= 0) {
  31135. outputSz = (word32)ret;
  31136. ret = 0;
  31137. }
  31138. else {
  31139. ret = WC_TEST_RET_ENC_EC(ret);
  31140. }
  31141. }
  31142. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31143. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31144. ret = WC_TEST_RET_ENC_NC;
  31145. }
  31146. /* Test decode/encode of Curve25519 public key (only) using generic API */
  31147. if (ret == 0) {
  31148. /* clear key, since generic API will try to decode all fields */
  31149. XMEMSET(&key, 0, sizeof(key));
  31150. idx = 0;
  31151. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31152. (word32)sizeof(kCurve25519PubDer));
  31153. if (ret < 0) {
  31154. ret = WC_TEST_RET_ENC_EC(ret);
  31155. }
  31156. }
  31157. if (ret == 0) {
  31158. outputSz = (word32)sizeof(output);
  31159. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31160. if (ret >= 0) {
  31161. outputSz = (word32)ret;
  31162. ret = 0;
  31163. }
  31164. else {
  31165. ret = WC_TEST_RET_ENC_EC(ret);
  31166. }
  31167. }
  31168. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31169. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31170. ret = WC_TEST_RET_ENC_NC;
  31171. }
  31172. /* Test decode/encode key data containing both public and private fields */
  31173. if (ret == 0) {
  31174. XMEMSET(&key, 0 , sizeof(key));
  31175. /* Decode public key */
  31176. idx = 0;
  31177. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31178. (word32)sizeof(kCurve25519PubDer));
  31179. if (ret < 0) {
  31180. ret = WC_TEST_RET_ENC_EC(ret);
  31181. }
  31182. if (ret == 0) {
  31183. /* Decode private key */
  31184. idx = 0;
  31185. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31186. (word32)sizeof(kCurve25519PrivDer));
  31187. if (ret < 0) {
  31188. ret = WC_TEST_RET_ENC_EC(ret);
  31189. }
  31190. }
  31191. /* Both public and private flags should be set */
  31192. if ((ret == 0) && (!key.pubSet && !key.privSet)) {
  31193. ret = WC_TEST_RET_ENC_NC;
  31194. }
  31195. if (ret == 0) {
  31196. /* Export key to temporary DER */
  31197. outputSz = (word32)sizeof(output);
  31198. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31199. if (ret >= 0) {
  31200. outputSz = (word32)ret;
  31201. ret = 0;
  31202. }
  31203. else {
  31204. ret = WC_TEST_RET_ENC_EC(ret);
  31205. }
  31206. /* Re-import temporary DER */
  31207. if (ret == 0) {
  31208. idx = 0;
  31209. ret = wc_Curve25519KeyDecode(output, &idx, &key, sizeof(output));
  31210. if (ret < 0) {
  31211. ret = WC_TEST_RET_ENC_EC(ret);
  31212. }
  31213. }
  31214. /* Ensure public and private keys survived combined keypair
  31215. * export/import by re-exporting DER for private and public keys,
  31216. * individually, and re-checking output against known good vectors.
  31217. * This is slightly circuitous but does test the functionality
  31218. * without requiring the addition of new test keys */
  31219. if (ret == 0) {
  31220. idx = 0;
  31221. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx,
  31222. &key, (word32)sizeof(kCurve25519PrivDer));
  31223. if (ret < 0)
  31224. ret = WC_TEST_RET_ENC_EC(ret);
  31225. }
  31226. if (ret == 0) {
  31227. outputSz = (word32)sizeof(output);
  31228. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31229. if (ret >= 0) {
  31230. outputSz = (word32)ret;
  31231. ret = 0;
  31232. }
  31233. else {
  31234. ret = WC_TEST_RET_ENC_EC(ret);
  31235. }
  31236. }
  31237. if ((ret == 0) &&
  31238. (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31239. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31240. ret = WC_TEST_RET_ENC_NC;
  31241. }
  31242. if (ret == 0) {
  31243. idx = 0;
  31244. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx,
  31245. &key, (word32)sizeof(kCurve25519PubDer));
  31246. if (ret < 0)
  31247. ret = WC_TEST_RET_ENC_EC(ret);
  31248. }
  31249. if (ret == 0) {
  31250. outputSz = (word32)sizeof(output);
  31251. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31252. if (ret >= 0) {
  31253. outputSz = (word32)ret;
  31254. ret = 0;
  31255. }
  31256. else {
  31257. ret = WC_TEST_RET_ENC_EC(ret);
  31258. }
  31259. }
  31260. if ((ret == 0) &&
  31261. (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31262. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31263. ret = WC_TEST_RET_ENC_NC;
  31264. }
  31265. }
  31266. }
  31267. wc_curve25519_free(&key);
  31268. return ret;
  31269. }
  31270. #endif /* !NO_ASN && HAVE_CURVE25519_KEY_EXPORT && HAVE_CURVE25519_KEY_IMPORT */
  31271. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
  31272. {
  31273. WC_RNG rng;
  31274. wc_test_ret_t ret;
  31275. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31276. byte sharedA[32];
  31277. byte sharedB[32];
  31278. word32 y;
  31279. #endif
  31280. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31281. byte exportBuf[32];
  31282. #endif
  31283. word32 x = 0;
  31284. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31285. curve25519_key *userA = NULL, *userB = NULL, *pubKey = NULL;
  31286. #else
  31287. curve25519_key userA[1], userB[1], pubKey[1];
  31288. #endif
  31289. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31290. defined(HAVE_CURVE25519_KEY_IMPORT)
  31291. /* test vectors from
  31292. https://tools.ietf.org/html/draft-josefsson-tls-curve25519-03
  31293. */
  31294. /* secret key for party a */
  31295. byte sa[] = {
  31296. 0x5A,0xC9,0x9F,0x33,0x63,0x2E,0x5A,0x76,
  31297. 0x8D,0xE7,0xE8,0x1B,0xF8,0x54,0xC2,0x7C,
  31298. 0x46,0xE3,0xFB,0xF2,0xAB,0xBA,0xCD,0x29,
  31299. 0xEC,0x4A,0xFF,0x51,0x73,0x69,0xC6,0x60
  31300. };
  31301. /* public key for party a */
  31302. byte pa[] = {
  31303. 0x05,0x7E,0x23,0xEA,0x9F,0x1C,0xBE,0x8A,
  31304. 0x27,0x16,0x8F,0x6E,0x69,0x6A,0x79,0x1D,
  31305. 0xE6,0x1D,0xD3,0xAF,0x7A,0xCD,0x4E,0xEA,
  31306. 0xCC,0x6E,0x7B,0xA5,0x14,0xFD,0xA8,0x63
  31307. };
  31308. /* secret key for party b */
  31309. byte sb[] = {
  31310. 0x47,0xDC,0x3D,0x21,0x41,0x74,0x82,0x0E,
  31311. 0x11,0x54,0xB4,0x9B,0xC6,0xCD,0xB2,0xAB,
  31312. 0xD4,0x5E,0xE9,0x58,0x17,0x05,0x5D,0x25,
  31313. 0x5A,0xA3,0x58,0x31,0xB7,0x0D,0x32,0x60
  31314. };
  31315. /* public key for party b */
  31316. byte pb[] = {
  31317. 0x6E,0xB8,0x9D,0xA9,0x19,0x89,0xAE,0x37,
  31318. 0xC7,0xEA,0xC7,0x61,0x8D,0x9E,0x5C,0x49,
  31319. 0x51,0xDB,0xA1,0xD7,0x3C,0x28,0x5A,0xE1,
  31320. 0xCD,0x26,0xA8,0x55,0x02,0x0E,0xEF,0x04
  31321. };
  31322. /* expected shared key */
  31323. byte ss[] = {
  31324. 0x61,0x45,0x0C,0xD9,0x8E,0x36,0x01,0x6B,
  31325. 0x58,0x77,0x6A,0x89,0x7A,0x9F,0x0A,0xEF,
  31326. 0x73,0x8B,0x99,0xF0,0x94,0x68,0xB8,0xD6,
  31327. 0xB8,0x51,0x11,0x84,0xD5,0x34,0x94,0xAB
  31328. };
  31329. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  31330. (void)x;
  31331. WOLFSSL_ENTER("curve25519_test");
  31332. /* wc_FreeRng is always called on exit. Therefore wc_InitRng should be
  31333. * called before any exit goto's */
  31334. #ifndef HAVE_FIPS
  31335. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31336. #else
  31337. ret = wc_InitRng(&rng);
  31338. #endif
  31339. if (ret != 0)
  31340. return WC_TEST_RET_ENC_EC(ret);
  31341. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31342. userA = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31343. if (ret != 0)
  31344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31345. userB = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31346. if (ret != 0)
  31347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31348. pubKey = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31349. if (ret != 0)
  31350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31351. #else
  31352. wc_curve25519_init_ex(userA, HEAP_HINT, devId);
  31353. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31354. wc_curve25519_init_ex(pubKey, HEAP_HINT, devId);
  31355. #endif
  31356. /* make curve25519 keys */
  31357. ret = wc_curve25519_make_key(&rng, 32, userA);
  31358. if (ret != 0)
  31359. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31360. ret = wc_curve25519_make_key(&rng, 32, userB);
  31361. if (ret != 0)
  31362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31363. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31364. /* find shared secret key */
  31365. x = sizeof(sharedA);
  31366. if ((ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x)) != 0) {
  31367. printf("wc_curve25519_shared_secret 1 failed\n");
  31368. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31369. }
  31370. y = sizeof(sharedB);
  31371. if ((ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y)) != 0) {
  31372. printf("wc_curve25519_shared_secret 2 failed\n");
  31373. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31374. }
  31375. /* compare shared secret keys to test they are the same */
  31376. if (y != x)
  31377. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31378. if (XMEMCMP(sharedA, sharedB, x))
  31379. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31380. #endif
  31381. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31382. /* export a public key and import it for another user */
  31383. x = sizeof(exportBuf);
  31384. ret = wc_curve25519_export_public(userA, exportBuf, &x);
  31385. if (ret != 0)
  31386. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31387. #ifdef HAVE_CURVE25519_KEY_IMPORT
  31388. ret = wc_curve25519_import_public(exportBuf, x, pubKey);
  31389. if (ret != 0)
  31390. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31391. #endif
  31392. #endif
  31393. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31394. defined(HAVE_CURVE25519_KEY_IMPORT)
  31395. /* test shared key after importing a public key */
  31396. XMEMSET(sharedB, 0, sizeof(sharedB));
  31397. y = sizeof(sharedB);
  31398. if (wc_curve25519_shared_secret(userB, pubKey, sharedB, &y) != 0) {
  31399. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31400. }
  31401. if (XMEMCMP(sharedA, sharedB, y))
  31402. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31403. /* import RFC test vectors and compare shared key */
  31404. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31405. userA);
  31406. if (ret != 0)
  31407. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31408. ret = wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb),
  31409. userB);
  31410. if (ret != 0)
  31411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31412. /* test against known test vector */
  31413. XMEMSET(sharedB, 0, sizeof(sharedB));
  31414. y = sizeof(sharedB);
  31415. ret = wc_curve25519_shared_secret(userA, userB, sharedB, &y);
  31416. if (ret != 0)
  31417. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31418. if (XMEMCMP(ss, sharedB, y))
  31419. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31420. /* test swapping roles of keys and generating same shared key */
  31421. XMEMSET(sharedB, 0, sizeof(sharedB));
  31422. y = sizeof(sharedB);
  31423. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31424. if (ret != 0)
  31425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31426. if (XMEMCMP(ss, sharedB, y))
  31427. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31428. /* test with 1 generated key and 1 from known test vector */
  31429. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31430. userA);
  31431. if (ret != 0)
  31432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31433. wc_curve25519_free(userB);
  31434. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31435. ret = wc_curve25519_make_key(&rng, 32, userB);
  31436. if (ret != 0)
  31437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31438. x = sizeof(sharedA);
  31439. ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x);
  31440. if (ret != 0)
  31441. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31442. y = sizeof(sharedB);
  31443. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31444. if (ret != 0)
  31445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31446. /* compare shared secret keys to test they are the same */
  31447. if (y != x)
  31448. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31449. if (XMEMCMP(sharedA, sharedB, x))
  31450. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31451. ret = curve25519_overflow_test();
  31452. if (ret != 0)
  31453. goto cleanup;
  31454. ret = curve25519_check_public_test();
  31455. if (ret != 0)
  31456. goto cleanup;
  31457. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31458. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31459. defined(HAVE_CURVE25519_KEY_IMPORT)
  31460. ret = curve255519_der_test();
  31461. if (ret != 0)
  31462. goto cleanup;
  31463. #endif
  31464. cleanup:
  31465. /* clean up keys when done */
  31466. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31467. wc_curve25519_delete(pubKey, &pubKey);
  31468. wc_curve25519_delete(userB, &userB);
  31469. wc_curve25519_delete(userA, &userA);
  31470. #else
  31471. wc_curve25519_free(pubKey);
  31472. wc_curve25519_free(userB);
  31473. wc_curve25519_free(userA);
  31474. #endif
  31475. wc_FreeRng(&rng);
  31476. return ret;
  31477. }
  31478. #endif /* HAVE_CURVE25519 */
  31479. #ifdef HAVE_ED25519
  31480. #ifdef WOLFSSL_TEST_CERT
  31481. static wc_test_ret_t ed25519_test_cert(void)
  31482. {
  31483. DecodedCert cert[2];
  31484. DecodedCert* serverCert = NULL;
  31485. DecodedCert* caCert = NULL;
  31486. #ifdef HAVE_ED25519_VERIFY
  31487. ed25519_key key;
  31488. ed25519_key* pubKey = NULL;
  31489. int verify;
  31490. #endif /* HAVE_ED25519_VERIFY */
  31491. wc_test_ret_t ret;
  31492. byte* tmp;
  31493. size_t bytes;
  31494. XFILE file;
  31495. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31496. if (tmp == NULL) {
  31497. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31498. }
  31499. #ifdef USE_CERT_BUFFERS_256
  31500. XMEMCPY(tmp, ca_ed25519_cert, sizeof_ca_ed25519_cert);
  31501. bytes = sizeof_ca_ed25519_cert;
  31502. #elif !defined(NO_FILESYSTEM)
  31503. file = XFOPEN(caEd25519Cert, "rb");
  31504. if (file == NULL) {
  31505. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31506. }
  31507. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31508. XFCLOSE(file);
  31509. if (bytes == 0)
  31510. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31511. #else
  31512. /* No certificate to use. */
  31513. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31514. #endif
  31515. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  31516. caCert = &cert[0];
  31517. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  31518. if (ret != 0)
  31519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31520. #ifdef USE_CERT_BUFFERS_256
  31521. XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert);
  31522. bytes = sizeof_server_ed25519_cert;
  31523. #elif !defined(NO_FILESYSTEM)
  31524. file = XFOPEN(serverEd25519Cert, "rb");
  31525. if (file == NULL) {
  31526. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31527. }
  31528. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31529. XFCLOSE(file);
  31530. if (bytes == 0)
  31531. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31532. #else
  31533. /* No certificate to use. */
  31534. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31535. #endif
  31536. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  31537. serverCert = &cert[1];
  31538. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  31539. if (ret != 0)
  31540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31541. #ifdef HAVE_ED25519_VERIFY
  31542. ret = wc_ed25519_init(&key);
  31543. if (ret < 0)
  31544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31545. pubKey = &key;
  31546. ret = wc_ed25519_import_public(caCert->publicKey, caCert->pubKeySize,
  31547. pubKey);
  31548. if (ret < 0)
  31549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31550. ret = wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength,
  31551. serverCert->source + serverCert->certBegin,
  31552. serverCert->sigIndex - serverCert->certBegin,
  31553. &verify, pubKey);
  31554. if (ret < 0 || verify != 1)
  31555. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31556. #endif /* HAVE_ED25519_VERIFY */
  31557. done:
  31558. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31559. #ifdef HAVE_ED25519_VERIFY
  31560. wc_ed25519_free(pubKey);
  31561. #endif /* HAVE_ED25519_VERIFY */
  31562. if (caCert != NULL)
  31563. FreeDecodedCert(caCert);
  31564. if (serverCert != NULL)
  31565. FreeDecodedCert(serverCert);
  31566. return ret;
  31567. }
  31568. static wc_test_ret_t ed25519_test_make_cert(void)
  31569. {
  31570. WC_RNG rng;
  31571. Cert cert;
  31572. DecodedCert decode;
  31573. ed25519_key key;
  31574. ed25519_key* privKey = NULL;
  31575. wc_test_ret_t ret = 0;
  31576. byte* tmp = NULL;
  31577. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  31578. #ifndef HAVE_FIPS
  31579. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31580. #else
  31581. ret = wc_InitRng(&rng);
  31582. #endif
  31583. if (ret != 0)
  31584. return WC_TEST_RET_ENC_EC(ret);
  31585. wc_ed25519_init(&key);
  31586. privKey = &key;
  31587. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, privKey);
  31588. cert.daysValid = 365 * 2;
  31589. cert.selfSigned = 1;
  31590. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  31591. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  31592. cert.isCA = 0;
  31593. #ifdef WOLFSSL_CERT_EXT
  31594. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  31595. if (ret < 0)
  31596. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31597. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31598. if (ret < 0)
  31599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31600. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31601. if (ret < 0)
  31602. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31603. #endif
  31604. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31605. if (tmp == NULL) {
  31606. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31607. }
  31608. cert.sigType = CTC_ED25519;
  31609. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng);
  31610. if (ret < 0)
  31611. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31612. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF,
  31613. ED25519_TYPE, privKey, &rng);
  31614. if (ret < 0)
  31615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31616. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  31617. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  31618. FreeDecodedCert(&decode);
  31619. if (ret != 0)
  31620. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31621. done:
  31622. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31623. wc_ed25519_free(privKey);
  31624. wc_FreeRng(&rng);
  31625. return ret;
  31626. }
  31627. #endif /* WOLFSSL_TEST_CERT */
  31628. #if defined(HAVE_ED25519_KEY_IMPORT)
  31629. static wc_test_ret_t ed25519_test_check_key(void)
  31630. {
  31631. /* Fails to find x-ordinate from this y-ordinate. */
  31632. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  31633. 0x40,
  31634. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31635. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31636. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31637. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31638. };
  31639. /* Y-ordinate value larger than prime. */
  31640. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  31641. 0x40,
  31642. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31643. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31644. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31645. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31646. };
  31647. /* Y-ordinate value equal to prime. */
  31648. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  31649. 0x40,
  31650. 0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31651. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31652. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31653. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31654. };
  31655. /* Y-ordinate value equal to prime - 1. */
  31656. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  31657. 0x40,
  31658. 0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31659. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31660. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31661. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31662. };
  31663. ed25519_key key;
  31664. int ret;
  31665. int res = 0;
  31666. /* Initialize key for use. */
  31667. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31668. if (ret != 0) {
  31669. return WC_TEST_RET_ENC_NC;
  31670. }
  31671. /* Load bad public key only and perform checks. */
  31672. ret = wc_ed25519_import_public(key_bad_y, ED25519_PUB_KEY_SIZE + 1, &key);
  31673. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31674. res = WC_TEST_RET_ENC_NC;
  31675. }
  31676. if (res == 0) {
  31677. /* Load bad public key only and perform checks. */
  31678. ret = wc_ed25519_import_public(key_bad_y_max, ED25519_PUB_KEY_SIZE + 1,
  31679. &key);
  31680. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31681. res = WC_TEST_RET_ENC_NC;
  31682. }
  31683. }
  31684. if (res == 0) {
  31685. /* Load bad public key only and perform checks. */
  31686. ret = wc_ed25519_import_public(key_bad_y_is_p, ED25519_PUB_KEY_SIZE + 1,
  31687. &key);
  31688. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31689. res = WC_TEST_RET_ENC_NC;
  31690. }
  31691. }
  31692. if (res == 0) {
  31693. /* Load good public key only and perform checks. */
  31694. ret = wc_ed25519_import_public(key_y_is_p_minus_1,
  31695. ED25519_PUB_KEY_SIZE + 1, &key);
  31696. if (ret != 0) {
  31697. res = WC_TEST_RET_ENC_NC;
  31698. }
  31699. }
  31700. /* Dispose of key. */
  31701. wc_ed25519_free(&key);
  31702. return res;
  31703. }
  31704. #endif
  31705. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31706. defined(HAVE_ED25519_KEY_IMPORT)
  31707. static wc_test_ret_t ed25519ctx_test(void)
  31708. {
  31709. wc_test_ret_t ret;
  31710. byte out[ED25519_SIG_SIZE];
  31711. word32 outlen;
  31712. #ifdef HAVE_ED25519_VERIFY
  31713. int verify = 0;
  31714. #endif /* HAVE_ED25519_VERIFY */
  31715. ed25519_key key;
  31716. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  31717. 0x03,0x05,0x33,0x4e,0x38,0x1a,0xf7,0x8f,
  31718. 0x14,0x1c,0xb6,0x66,0xf6,0x19,0x9f,0x57,
  31719. 0xbc,0x34,0x95,0x33,0x5a,0x25,0x6a,0x95,
  31720. 0xbd,0x2a,0x55,0xbf,0x54,0x66,0x63,0xf6
  31721. };
  31722. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  31723. 0xdf,0xc9,0x42,0x5e,0x4f,0x96,0x8f,0x7f,
  31724. 0x0c,0x29,0xf0,0x25,0x9c,0xf5,0xf9,0xae,
  31725. 0xd6,0x85,0x1c,0x2b,0xb4,0xad,0x8b,0xfb,
  31726. 0x86,0x0c,0xfe,0xe0,0xab,0x24,0x82,0x92
  31727. };
  31728. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx1[] = {
  31729. 0x55,0xa4,0xcc,0x2f,0x70,0xa5,0x4e,0x04,
  31730. 0x28,0x8c,0x5f,0x4c,0xd1,0xe4,0x5a,0x7b,
  31731. 0xb5,0x20,0xb3,0x62,0x92,0x91,0x18,0x76,
  31732. 0xca,0xda,0x73,0x23,0x19,0x8d,0xd8,0x7a,
  31733. 0x8b,0x36,0x95,0x0b,0x95,0x13,0x00,0x22,
  31734. 0x90,0x7a,0x7f,0xb7,0xc4,0xe9,0xb2,0xd5,
  31735. 0xf6,0xcc,0xa6,0x85,0xa5,0x87,0xb4,0xb2,
  31736. 0x1f,0x4b,0x88,0x8e,0x4e,0x7e,0xdb,0x0d
  31737. };
  31738. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx2[] = {
  31739. 0xcc,0x5e,0x63,0xa2,0x7e,0x94,0xaf,0xd3,
  31740. 0x41,0x83,0x38,0xd2,0x48,0x6f,0xa9,0x2a,
  31741. 0xf9,0x91,0x7c,0x2d,0x98,0x9e,0x06,0xe5,
  31742. 0x02,0x77,0x72,0x1c,0x34,0x38,0x18,0xb4,
  31743. 0x21,0x96,0xbc,0x29,0x2e,0x68,0xf3,0x4d,
  31744. 0x85,0x9b,0xbe,0xad,0x17,0x9f,0x54,0x54,
  31745. 0x2d,0x4b,0x04,0xdc,0xfb,0xfa,0x4a,0x68,
  31746. 0x4e,0x39,0x50,0xfb,0x1c,0xcd,0x8d,0x0d
  31747. };
  31748. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  31749. 0xf7,0x26,0x93,0x6d,0x19,0xc8,0x00,0x49,
  31750. 0x4e,0x3f,0xda,0xff,0x20,0xb2,0x76,0xa8
  31751. };
  31752. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  31753. 0x66,0x6f,0x6f
  31754. };
  31755. outlen = sizeof(out);
  31756. XMEMSET(out, 0, sizeof(out));
  31757. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31758. if (ret != 0)
  31759. return 10800;
  31760. ret = wc_ed25519_import_private_key(sKeyCtx, ED25519_KEY_SIZE, pKeyCtx,
  31761. sizeof(pKeyCtx), &key);
  31762. if (ret == 0)
  31763. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31764. contextCtx, sizeof(contextCtx));
  31765. if (ret == 0 && XMEMCMP(out, sigCtx1, 64) != 0)
  31766. ret = WC_TEST_RET_ENC_NC;
  31767. #if defined(HAVE_ED25519_VERIFY)
  31768. /* test verify on good msg */
  31769. if (ret == 0)
  31770. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31771. &verify, &key, contextCtx, sizeof(contextCtx));
  31772. if (ret == 0 && verify != 1)
  31773. ret = WC_TEST_RET_ENC_NC;
  31774. #endif
  31775. if (ret == 0)
  31776. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31777. NULL, 0);
  31778. if (ret == 0 && XMEMCMP(out, sigCtx2, 64) != 0)
  31779. ret = WC_TEST_RET_ENC_NC;
  31780. #if defined(HAVE_ED25519_VERIFY)
  31781. /* test verify on good msg */
  31782. if (ret == 0)
  31783. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31784. &verify, &key, NULL, 0);
  31785. if (ret == 0 && verify != 1)
  31786. ret = WC_TEST_RET_ENC_NC;
  31787. #endif
  31788. wc_ed25519_free(&key);
  31789. return ret;
  31790. }
  31791. static wc_test_ret_t ed25519ph_test(void)
  31792. {
  31793. wc_test_ret_t ret = 0;
  31794. byte out[ED25519_SIG_SIZE];
  31795. word32 outlen;
  31796. #ifdef HAVE_ED25519_VERIFY
  31797. int verify = 0;
  31798. #endif /* HAVE_ED25519_VERIFY */
  31799. ed25519_key key;
  31800. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  31801. 0x83,0x3f,0xe6,0x24,0x09,0x23,0x7b,0x9d,
  31802. 0x62,0xec,0x77,0x58,0x75,0x20,0x91,0x1e,
  31803. 0x9a,0x75,0x9c,0xec,0x1d,0x19,0x75,0x5b,
  31804. 0x7d,0xa9,0x01,0xb9,0x6d,0xca,0x3d,0x42
  31805. };
  31806. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  31807. 0xec,0x17,0x2b,0x93,0xad,0x5e,0x56,0x3b,
  31808. 0xf4,0x93,0x2c,0x70,0xe1,0x24,0x50,0x34,
  31809. 0xc3,0x54,0x67,0xef,0x2e,0xfd,0x4d,0x64,
  31810. 0xeb,0xf8,0x19,0x68,0x34,0x67,0xe2,0xbf
  31811. };
  31812. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  31813. 0x98,0xa7,0x02,0x22,0xf0,0xb8,0x12,0x1a,
  31814. 0xa9,0xd3,0x0f,0x81,0x3d,0x68,0x3f,0x80,
  31815. 0x9e,0x46,0x2b,0x46,0x9c,0x7f,0xf8,0x76,
  31816. 0x39,0x49,0x9b,0xb9,0x4e,0x6d,0xae,0x41,
  31817. 0x31,0xf8,0x50,0x42,0x46,0x3c,0x2a,0x35,
  31818. 0x5a,0x20,0x03,0xd0,0x62,0xad,0xf5,0xaa,
  31819. 0xa1,0x0b,0x8c,0x61,0xe6,0x36,0x06,0x2a,
  31820. 0xaa,0xd1,0x1c,0x2a,0x26,0x08,0x34,0x06
  31821. };
  31822. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  31823. 0xe0,0x39,0x70,0x2b,0x4c,0x25,0x95,0xa6,
  31824. 0xa5,0x41,0xac,0x85,0x09,0x23,0x6e,0x29,
  31825. 0x90,0x47,0x47,0x95,0x33,0x0c,0x9b,0x34,
  31826. 0xa7,0x5f,0x58,0xa6,0x60,0x12,0x9e,0x08,
  31827. 0xfd,0x73,0x69,0x43,0xfb,0x19,0x43,0xa5,
  31828. 0x57,0x20,0xb9,0xe0,0x95,0x7b,0x1e,0xd6,
  31829. 0x73,0x48,0x16,0x61,0x9f,0x13,0x88,0xf4,
  31830. 0x3f,0x73,0xe6,0xe3,0xba,0xa8,0x1c,0x0e
  31831. };
  31832. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  31833. 0x61,0x62,0x63
  31834. };
  31835. /* SHA-512 hash of msgPh */
  31836. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  31837. 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
  31838. 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
  31839. 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
  31840. 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
  31841. 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
  31842. 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
  31843. 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
  31844. 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f
  31845. };
  31846. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  31847. 0x66,0x6f,0x6f
  31848. };
  31849. outlen = sizeof(out);
  31850. XMEMSET(out, 0, sizeof(out));
  31851. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31852. if (ret != 0)
  31853. return WC_TEST_RET_ENC_EC(ret);
  31854. ret = wc_ed25519_import_private_key(sKeyPh, ED25519_KEY_SIZE, pKeyPh,
  31855. sizeof(pKeyPh), &key);
  31856. if (ret == 0)
  31857. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31858. NULL, 0);
  31859. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31860. ret = WC_TEST_RET_ENC_NC;
  31861. #if defined(HAVE_ED25519_VERIFY)
  31862. /* test verify on good msg */
  31863. if (ret == 0)
  31864. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh),
  31865. &verify, &key, NULL, 0);
  31866. if (ret == 0 && verify != 1)
  31867. ret = WC_TEST_RET_ENC_NC;
  31868. #endif
  31869. if (ret == 0)
  31870. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31871. contextPh2, sizeof(contextPh2));
  31872. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31873. ret = WC_TEST_RET_ENC_NC;
  31874. #if defined(HAVE_ED25519_VERIFY)
  31875. /* test verify on good msg */
  31876. if (ret == 0)
  31877. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify,
  31878. &key, contextPh2, sizeof(contextPh2));
  31879. if (ret == 0 && verify != 1)
  31880. ret = WC_TEST_RET_ENC_NC;
  31881. #endif
  31882. if (ret == 0)
  31883. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31884. NULL, 0);
  31885. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31886. ret = WC_TEST_RET_ENC_NC;
  31887. #if defined(HAVE_ED25519_VERIFY)
  31888. if (ret == 0)
  31889. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh),
  31890. &verify, &key, NULL, 0);
  31891. if (ret == 0 && verify != 1)
  31892. ret = WC_TEST_RET_ENC_NC;
  31893. #endif
  31894. if (ret == 0)
  31895. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31896. contextPh2, sizeof(contextPh2));
  31897. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31898. ret = WC_TEST_RET_ENC_NC;
  31899. #if defined(HAVE_ED25519_VERIFY)
  31900. if (ret == 0)
  31901. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  31902. &key, contextPh2, sizeof(contextPh2));
  31903. if (ret == 0 && verify != 1)
  31904. ret = WC_TEST_RET_ENC_NC;
  31905. #endif
  31906. wc_ed25519_free(&key);
  31907. return ret;
  31908. }
  31909. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31910. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
  31911. {
  31912. wc_test_ret_t ret;
  31913. WC_RNG rng;
  31914. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  31915. defined(HAVE_ED25519_KEY_IMPORT)
  31916. byte out[ED25519_SIG_SIZE];
  31917. byte exportPKey[ED25519_KEY_SIZE];
  31918. byte exportSKey[ED25519_KEY_SIZE];
  31919. word32 exportPSz;
  31920. word32 exportSSz;
  31921. int i;
  31922. word32 outlen;
  31923. #ifdef HAVE_ED25519_VERIFY
  31924. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  31925. int j;
  31926. #endif
  31927. int verify;
  31928. #endif /* HAVE_ED25519_VERIFY */
  31929. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31930. word32 keySz, sigSz;
  31931. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31932. ed25519_key* key = NULL;
  31933. ed25519_key* key2 = NULL;
  31934. #else
  31935. ed25519_key key[1];
  31936. ed25519_key key2[1];
  31937. #endif
  31938. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31939. defined(HAVE_ED25519_KEY_IMPORT)
  31940. /* test vectors from
  31941. https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02
  31942. */
  31943. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  31944. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31945. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31946. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31947. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31948. };
  31949. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  31950. 0x4c,0xcd,0x08,0x9b,0x28,0xff,0x96,0xda,
  31951. 0x9d,0xb6,0xc3,0x46,0xec,0x11,0x4e,0x0f,
  31952. 0x5b,0x8a,0x31,0x9f,0x35,0xab,0xa6,0x24,
  31953. 0xda,0x8c,0xf6,0xed,0x4f,0xb8,0xa6,0xfb
  31954. };
  31955. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  31956. 0xc5,0xaa,0x8d,0xf4,0x3f,0x9f,0x83,0x7b,
  31957. 0xed,0xb7,0x44,0x2f,0x31,0xdc,0xb7,0xb1,
  31958. 0x66,0xd3,0x85,0x35,0x07,0x6f,0x09,0x4b,
  31959. 0x85,0xce,0x3a,0x2e,0x0b,0x44,0x58,0xf7
  31960. };
  31961. /* uncompressed test */
  31962. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  31963. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31964. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31965. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31966. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31967. };
  31968. /* compressed prefix test */
  31969. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  31970. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31971. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31972. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31973. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31974. };
  31975. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  31976. 0xf5,0xe5,0x76,0x7c,0xf1,0x53,0x31,0x95,
  31977. 0x17,0x63,0x0f,0x22,0x68,0x76,0xb8,0x6c,
  31978. 0x81,0x60,0xcc,0x58,0x3b,0xc0,0x13,0x74,
  31979. 0x4c,0x6b,0xf2,0x55,0xf5,0xcc,0x0e,0xe5
  31980. };
  31981. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  31982. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  31983. 0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31984. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31985. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31986. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31987. };
  31988. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  31989. 0x3d,0x40,0x17,0xc3,0xe8,0x43,0x89,0x5a,
  31990. 0x92,0xb7,0x0a,0xa7,0x4d,0x1b,0x7e,0xbc,
  31991. 0x9c,0x98,0x2c,0xcf,0x2e,0xc4,0x96,0x8c,
  31992. 0xc0,0xcd,0x55,0xf1,0x2a,0xf4,0x66,0x0c
  31993. };
  31994. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  31995. 0xfc,0x51,0xcd,0x8e,0x62,0x18,0xa1,0xa3,
  31996. 0x8d,0xa4,0x7e,0xd0,0x02,0x30,0xf0,0x58,
  31997. 0x08,0x16,0xed,0x13,0xba,0x33,0x03,0xac,
  31998. 0x5d,0xeb,0x91,0x15,0x48,0x90,0x80,0x25
  31999. };
  32000. /* uncompressed test */
  32001. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  32002. 0x04,0x55,0xd0,0xe0,0x9a,0x2b,0x9d,0x34,
  32003. 0x29,0x22,0x97,0xe0,0x8d,0x60,0xd0,0xf6,
  32004. 0x20,0xc5,0x13,0xd4,0x72,0x53,0x18,0x7c,
  32005. 0x24,0xb1,0x27,0x86,0xbd,0x77,0x76,0x45,
  32006. 0xce,0x1a,0x51,0x07,0xf7,0x68,0x1a,0x02,
  32007. 0xaf,0x25,0x23,0xa6,0xda,0xf3,0x72,0xe1,
  32008. 0x0e,0x3a,0x07,0x64,0xc9,0xd3,0xfe,0x4b,
  32009. 0xd5,0xb7,0x0a,0xb1,0x82,0x01,0x98,0x5a,
  32010. 0xd7
  32011. };
  32012. /* compressed prefix */
  32013. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  32014. 0x40,0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  32015. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  32016. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  32017. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  32018. };
  32019. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  32020. 0x27,0x81,0x17,0xfc,0x14,0x4c,0x72,0x34,
  32021. 0x0f,0x67,0xd0,0xf2,0x31,0x6e,0x83,0x86,
  32022. 0xce,0xff,0xbf,0x2b,0x24,0x28,0xc9,0xc5,
  32023. 0x1f,0xef,0x7c,0x59,0x7f,0x1d,0x42,0x6e
  32024. };
  32025. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  32026. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  32027. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  32028. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  32029. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32030. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32031. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32032. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32033. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32034. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32035. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32036. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32037. };
  32038. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  32039. 0x92,0xa0,0x09,0xa9,0xf0,0xd4,0xca,0xb8,
  32040. 0x72,0x0e,0x82,0x0b,0x5f,0x64,0x25,0x40,
  32041. 0xa2,0xb2,0x7b,0x54,0x16,0x50,0x3f,0x8f,
  32042. 0xb3,0x76,0x22,0x23,0xeb,0xdb,0x69,0xda,
  32043. 0x08,0x5a,0xc1,0xe4,0x3e,0x15,0x99,0x6e,
  32044. 0x45,0x8f,0x36,0x13,0xd0,0xf1,0x1d,0x8c,
  32045. 0x38,0x7b,0x2e,0xae,0xb4,0x30,0x2a,0xee,
  32046. 0xb0,0x0d,0x29,0x16,0x12,0xbb,0x0c,0x00
  32047. };
  32048. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  32049. 0x62,0x91,0xd6,0x57,0xde,0xec,0x24,0x02,
  32050. 0x48,0x27,0xe6,0x9c,0x3a,0xbe,0x01,0xa3,
  32051. 0x0c,0xe5,0x48,0xa2,0x84,0x74,0x3a,0x44,
  32052. 0x5e,0x36,0x80,0xd7,0xdb,0x5a,0xc3,0xac,
  32053. 0x18,0xff,0x9b,0x53,0x8d,0x16,0xf2,0x90,
  32054. 0xae,0x67,0xf7,0x60,0x98,0x4d,0xc6,0x59,
  32055. 0x4a,0x7c,0x15,0xe9,0x71,0x6e,0xd2,0x8d,
  32056. 0xc0,0x27,0xbe,0xce,0xea,0x1e,0xc4,0x0a
  32057. };
  32058. /* uncompressed test */
  32059. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  32060. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32061. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32062. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32063. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32064. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32065. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32066. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32067. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32068. };
  32069. /* compressed prefix */
  32070. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  32071. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32072. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32073. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32074. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32075. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32076. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32077. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32078. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32079. };
  32080. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  32081. 0x0a,0xab,0x4c,0x90,0x05,0x01,0xb3,0xe2,
  32082. 0x4d,0x7c,0xdf,0x46,0x63,0x32,0x6a,0x3a,
  32083. 0x87,0xdf,0x5e,0x48,0x43,0xb2,0xcb,0xdb,
  32084. 0x67,0xcb,0xf6,0xe4,0x60,0xfe,0xc3,0x50,
  32085. 0xaa,0x53,0x71,0xb1,0x50,0x8f,0x9f,0x45,
  32086. 0x28,0xec,0xea,0x23,0xc4,0x36,0xd9,0x4b,
  32087. 0x5e,0x8f,0xcd,0x4f,0x68,0x1e,0x30,0xa6,
  32088. 0xac,0x00,0xa9,0x70,0x4a,0x18,0x8a,0x03
  32089. };
  32090. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  32091. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {0x0 };
  32092. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {0x72};
  32093. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {0xAF,0x82};
  32094. /* test of a 1024 byte long message */
  32095. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  32096. 0x08,0xb8,0xb2,0xb7,0x33,0x42,0x42,0x43,
  32097. 0x76,0x0f,0xe4,0x26,0xa4,0xb5,0x49,0x08,
  32098. 0x63,0x21,0x10,0xa6,0x6c,0x2f,0x65,0x91,
  32099. 0xea,0xbd,0x33,0x45,0xe3,0xe4,0xeb,0x98,
  32100. 0xfa,0x6e,0x26,0x4b,0xf0,0x9e,0xfe,0x12,
  32101. 0xee,0x50,0xf8,0xf5,0x4e,0x9f,0x77,0xb1,
  32102. 0xe3,0x55,0xf6,0xc5,0x05,0x44,0xe2,0x3f,
  32103. 0xb1,0x43,0x3d,0xdf,0x73,0xbe,0x84,0xd8,
  32104. 0x79,0xde,0x7c,0x00,0x46,0xdc,0x49,0x96,
  32105. 0xd9,0xe7,0x73,0xf4,0xbc,0x9e,0xfe,0x57,
  32106. 0x38,0x82,0x9a,0xdb,0x26,0xc8,0x1b,0x37,
  32107. 0xc9,0x3a,0x1b,0x27,0x0b,0x20,0x32,0x9d,
  32108. 0x65,0x86,0x75,0xfc,0x6e,0xa5,0x34,0xe0,
  32109. 0x81,0x0a,0x44,0x32,0x82,0x6b,0xf5,0x8c,
  32110. 0x94,0x1e,0xfb,0x65,0xd5,0x7a,0x33,0x8b,
  32111. 0xbd,0x2e,0x26,0x64,0x0f,0x89,0xff,0xbc,
  32112. 0x1a,0x85,0x8e,0xfc,0xb8,0x55,0x0e,0xe3,
  32113. 0xa5,0xe1,0x99,0x8b,0xd1,0x77,0xe9,0x3a,
  32114. 0x73,0x63,0xc3,0x44,0xfe,0x6b,0x19,0x9e,
  32115. 0xe5,0xd0,0x2e,0x82,0xd5,0x22,0xc4,0xfe,
  32116. 0xba,0x15,0x45,0x2f,0x80,0x28,0x8a,0x82,
  32117. 0x1a,0x57,0x91,0x16,0xec,0x6d,0xad,0x2b,
  32118. 0x3b,0x31,0x0d,0xa9,0x03,0x40,0x1a,0xa6,
  32119. 0x21,0x00,0xab,0x5d,0x1a,0x36,0x55,0x3e,
  32120. 0x06,0x20,0x3b,0x33,0x89,0x0c,0xc9,0xb8,
  32121. 0x32,0xf7,0x9e,0xf8,0x05,0x60,0xcc,0xb9,
  32122. 0xa3,0x9c,0xe7,0x67,0x96,0x7e,0xd6,0x28,
  32123. 0xc6,0xad,0x57,0x3c,0xb1,0x16,0xdb,0xef,
  32124. 0xef,0xd7,0x54,0x99,0xda,0x96,0xbd,0x68,
  32125. 0xa8,0xa9,0x7b,0x92,0x8a,0x8b,0xbc,0x10,
  32126. 0x3b,0x66,0x21,0xfc,0xde,0x2b,0xec,0xa1,
  32127. 0x23,0x1d,0x20,0x6b,0xe6,0xcd,0x9e,0xc7,
  32128. 0xaf,0xf6,0xf6,0xc9,0x4f,0xcd,0x72,0x04,
  32129. 0xed,0x34,0x55,0xc6,0x8c,0x83,0xf4,0xa4,
  32130. 0x1d,0xa4,0xaf,0x2b,0x74,0xef,0x5c,0x53,
  32131. 0xf1,0xd8,0xac,0x70,0xbd,0xcb,0x7e,0xd1,
  32132. 0x85,0xce,0x81,0xbd,0x84,0x35,0x9d,0x44,
  32133. 0x25,0x4d,0x95,0x62,0x9e,0x98,0x55,0xa9,
  32134. 0x4a,0x7c,0x19,0x58,0xd1,0xf8,0xad,0xa5,
  32135. 0xd0,0x53,0x2e,0xd8,0xa5,0xaa,0x3f,0xb2,
  32136. 0xd1,0x7b,0xa7,0x0e,0xb6,0x24,0x8e,0x59,
  32137. 0x4e,0x1a,0x22,0x97,0xac,0xbb,0xb3,0x9d,
  32138. 0x50,0x2f,0x1a,0x8c,0x6e,0xb6,0xf1,0xce,
  32139. 0x22,0xb3,0xde,0x1a,0x1f,0x40,0xcc,0x24,
  32140. 0x55,0x41,0x19,0xa8,0x31,0xa9,0xaa,0xd6,
  32141. 0x07,0x9c,0xad,0x88,0x42,0x5d,0xe6,0xbd,
  32142. 0xe1,0xa9,0x18,0x7e,0xbb,0x60,0x92,0xcf,
  32143. 0x67,0xbf,0x2b,0x13,0xfd,0x65,0xf2,0x70,
  32144. 0x88,0xd7,0x8b,0x7e,0x88,0x3c,0x87,0x59,
  32145. 0xd2,0xc4,0xf5,0xc6,0x5a,0xdb,0x75,0x53,
  32146. 0x87,0x8a,0xd5,0x75,0xf9,0xfa,0xd8,0x78,
  32147. 0xe8,0x0a,0x0c,0x9b,0xa6,0x3b,0xcb,0xcc,
  32148. 0x27,0x32,0xe6,0x94,0x85,0xbb,0xc9,0xc9,
  32149. 0x0b,0xfb,0xd6,0x24,0x81,0xd9,0x08,0x9b,
  32150. 0xec,0xcf,0x80,0xcf,0xe2,0xdf,0x16,0xa2,
  32151. 0xcf,0x65,0xbd,0x92,0xdd,0x59,0x7b,0x07,
  32152. 0x07,0xe0,0x91,0x7a,0xf4,0x8b,0xbb,0x75,
  32153. 0xfe,0xd4,0x13,0xd2,0x38,0xf5,0x55,0x5a,
  32154. 0x7a,0x56,0x9d,0x80,0xc3,0x41,0x4a,0x8d,
  32155. 0x08,0x59,0xdc,0x65,0xa4,0x61,0x28,0xba,
  32156. 0xb2,0x7a,0xf8,0x7a,0x71,0x31,0x4f,0x31,
  32157. 0x8c,0x78,0x2b,0x23,0xeb,0xfe,0x80,0x8b,
  32158. 0x82,0xb0,0xce,0x26,0x40,0x1d,0x2e,0x22,
  32159. 0xf0,0x4d,0x83,0xd1,0x25,0x5d,0xc5,0x1a,
  32160. 0xdd,0xd3,0xb7,0x5a,0x2b,0x1a,0xe0,0x78,
  32161. 0x45,0x04,0xdf,0x54,0x3a,0xf8,0x96,0x9b,
  32162. 0xe3,0xea,0x70,0x82,0xff,0x7f,0xc9,0x88,
  32163. 0x8c,0x14,0x4d,0xa2,0xaf,0x58,0x42,0x9e,
  32164. 0xc9,0x60,0x31,0xdb,0xca,0xd3,0xda,0xd9,
  32165. 0xaf,0x0d,0xcb,0xaa,0xaf,0x26,0x8c,0xb8,
  32166. 0xfc,0xff,0xea,0xd9,0x4f,0x3c,0x7c,0xa4,
  32167. 0x95,0xe0,0x56,0xa9,0xb4,0x7a,0xcd,0xb7,
  32168. 0x51,0xfb,0x73,0xe6,0x66,0xc6,0xc6,0x55,
  32169. 0xad,0xe8,0x29,0x72,0x97,0xd0,0x7a,0xd1,
  32170. 0xba,0x5e,0x43,0xf1,0xbc,0xa3,0x23,0x01,
  32171. 0x65,0x13,0x39,0xe2,0x29,0x04,0xcc,0x8c,
  32172. 0x42,0xf5,0x8c,0x30,0xc0,0x4a,0xaf,0xdb,
  32173. 0x03,0x8d,0xda,0x08,0x47,0xdd,0x98,0x8d,
  32174. 0xcd,0xa6,0xf3,0xbf,0xd1,0x5c,0x4b,0x4c,
  32175. 0x45,0x25,0x00,0x4a,0xa0,0x6e,0xef,0xf8,
  32176. 0xca,0x61,0x78,0x3a,0xac,0xec,0x57,0xfb,
  32177. 0x3d,0x1f,0x92,0xb0,0xfe,0x2f,0xd1,0xa8,
  32178. 0x5f,0x67,0x24,0x51,0x7b,0x65,0xe6,0x14,
  32179. 0xad,0x68,0x08,0xd6,0xf6,0xee,0x34,0xdf,
  32180. 0xf7,0x31,0x0f,0xdc,0x82,0xae,0xbf,0xd9,
  32181. 0x04,0xb0,0x1e,0x1d,0xc5,0x4b,0x29,0x27,
  32182. 0x09,0x4b,0x2d,0xb6,0x8d,0x6f,0x90,0x3b,
  32183. 0x68,0x40,0x1a,0xde,0xbf,0x5a,0x7e,0x08,
  32184. 0xd7,0x8f,0xf4,0xef,0x5d,0x63,0x65,0x3a,
  32185. 0x65,0x04,0x0c,0xf9,0xbf,0xd4,0xac,0xa7,
  32186. 0x98,0x4a,0x74,0xd3,0x71,0x45,0x98,0x67,
  32187. 0x80,0xfc,0x0b,0x16,0xac,0x45,0x16,0x49,
  32188. 0xde,0x61,0x88,0xa7,0xdb,0xdf,0x19,0x1f,
  32189. 0x64,0xb5,0xfc,0x5e,0x2a,0xb4,0x7b,0x57,
  32190. 0xf7,0xf7,0x27,0x6c,0xd4,0x19,0xc1,0x7a,
  32191. 0x3c,0xa8,0xe1,0xb9,0x39,0xae,0x49,0xe4,
  32192. 0x88,0xac,0xba,0x6b,0x96,0x56,0x10,0xb5,
  32193. 0x48,0x01,0x09,0xc8,0xb1,0x7b,0x80,0xe1,
  32194. 0xb7,0xb7,0x50,0xdf,0xc7,0x59,0x8d,0x5d,
  32195. 0x50,0x11,0xfd,0x2d,0xcc,0x56,0x00,0xa3,
  32196. 0x2e,0xf5,0xb5,0x2a,0x1e,0xcc,0x82,0x0e,
  32197. 0x30,0x8a,0xa3,0x42,0x72,0x1a,0xac,0x09,
  32198. 0x43,0xbf,0x66,0x86,0xb6,0x4b,0x25,0x79,
  32199. 0x37,0x65,0x04,0xcc,0xc4,0x93,0xd9,0x7e,
  32200. 0x6a,0xed,0x3f,0xb0,0xf9,0xcd,0x71,0xa4,
  32201. 0x3d,0xd4,0x97,0xf0,0x1f,0x17,0xc0,0xe2,
  32202. 0xcb,0x37,0x97,0xaa,0x2a,0x2f,0x25,0x66,
  32203. 0x56,0x16,0x8e,0x6c,0x49,0x6a,0xfc,0x5f,
  32204. 0xb9,0x32,0x46,0xf6,0xb1,0x11,0x63,0x98,
  32205. 0xa3,0x46,0xf1,0xa6,0x41,0xf3,0xb0,0x41,
  32206. 0xe9,0x89,0xf7,0x91,0x4f,0x90,0xcc,0x2c,
  32207. 0x7f,0xff,0x35,0x78,0x76,0xe5,0x06,0xb5,
  32208. 0x0d,0x33,0x4b,0xa7,0x7c,0x22,0x5b,0xc3,
  32209. 0x07,0xba,0x53,0x71,0x52,0xf3,0xf1,0x61,
  32210. 0x0e,0x4e,0xaf,0xe5,0x95,0xf6,0xd9,0xd9,
  32211. 0x0d,0x11,0xfa,0xa9,0x33,0xa1,0x5e,0xf1,
  32212. 0x36,0x95,0x46,0x86,0x8a,0x7f,0x3a,0x45,
  32213. 0xa9,0x67,0x68,0xd4,0x0f,0xd9,0xd0,0x34,
  32214. 0x12,0xc0,0x91,0xc6,0x31,0x5c,0xf4,0xfd,
  32215. 0xe7,0xcb,0x68,0x60,0x69,0x37,0x38,0x0d,
  32216. 0xb2,0xea,0xaa,0x70,0x7b,0x4c,0x41,0x85,
  32217. 0xc3,0x2e,0xdd,0xcd,0xd3,0x06,0x70,0x5e,
  32218. 0x4d,0xc1,0xff,0xc8,0x72,0xee,0xee,0x47,
  32219. 0x5a,0x64,0xdf,0xac,0x86,0xab,0xa4,0x1c,
  32220. 0x06,0x18,0x98,0x3f,0x87,0x41,0xc5,0xef,
  32221. 0x68,0xd3,0xa1,0x01,0xe8,0xa3,0xb8,0xca,
  32222. 0xc6,0x0c,0x90,0x5c,0x15,0xfc,0x91,0x08,
  32223. 0x40,0xb9,0x4c,0x00,0xa0,0xb9,0xd0
  32224. };
  32225. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  32226. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  32227. sizeof(msg2),
  32228. sizeof(msg3),
  32229. 0 /*sizeof(msg1)*/,
  32230. 0 /*sizeof(msg1)*/,
  32231. sizeof(msg4)
  32232. };
  32233. #ifndef NO_ASN
  32234. static const byte privateEd25519[] = {
  32235. 0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,
  32236. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32237. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32238. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32239. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32240. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  32241. };
  32242. static const byte badPrivateEd25519[] = {
  32243. 0x30,0x52,0x02,0x01,0x00,0x30,0x05,0x06,
  32244. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32245. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32246. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32247. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32248. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32249. 0xa1,0x22,0x04,0x21,0xd7,0x5a,0x98,0x01, /* octet len 0x20 -> 0x21 */
  32250. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32251. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32252. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32253. 0xf7,0x07,0x51,0x1a,
  32254. 0x00 /* add additional bytes to make the pubkey bigger */
  32255. };
  32256. static const byte publicEd25519[] = {
  32257. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32258. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32259. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32260. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32261. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32262. 0xf7,0x07,0x51,0x1a
  32263. };
  32264. /* size has been altered to catch if sanity check is done */
  32265. static const byte badPublicEd25519[] = {
  32266. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32267. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32268. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32269. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32270. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32271. 0xf7,0x07,0x51,0x1a,
  32272. 0x00 /* add an additional byte to make the pubkey appear bigger */
  32273. };
  32274. static const byte privPubEd25519[] = {
  32275. 0x30,0x50,0x02,0x01,0x00,0x30,0x05,0x06,
  32276. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32277. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32278. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32279. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32280. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32281. 0x81,0x20,0xd7,0x5a,0x98,0x01,0x82,0xb1,
  32282. 0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,
  32283. 0x07,0x3a,0x0e,0xe1,0x72,0xf3,0xda,0xa6,
  32284. 0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7,0x07,
  32285. 0x51,0x1a
  32286. };
  32287. word32 idx;
  32288. #endif /* NO_ASN */
  32289. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32290. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32291. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32292. ed25519_key* key3 = NULL;
  32293. #else
  32294. ed25519_key key3[1];
  32295. #endif
  32296. #endif
  32297. WOLFSSL_ENTER("ed25519_test");
  32298. /* create ed25519 keys */
  32299. #ifndef HAVE_FIPS
  32300. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32301. #else
  32302. ret = wc_InitRng(&rng);
  32303. #endif
  32304. if (ret != 0)
  32305. return WC_TEST_RET_ENC_EC(ret);
  32306. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32307. key = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32308. if (ret != 0)
  32309. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32310. key2 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32311. if (ret != 0)
  32312. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32313. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32314. key3 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32315. if (ret != 0)
  32316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32317. #endif
  32318. #else
  32319. wc_ed25519_init_ex(key, HEAP_HINT, devId);
  32320. wc_ed25519_init_ex(key2, HEAP_HINT, devId);
  32321. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32322. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32323. #endif
  32324. #endif
  32325. #ifdef HAVE_ED25519_MAKE_KEY
  32326. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
  32327. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key2);
  32328. #endif
  32329. /* helper functions for signature and key size */
  32330. keySz = (word32)wc_ed25519_size(key);
  32331. sigSz = (word32)wc_ed25519_sig_size(key);
  32332. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  32333. defined(HAVE_ED25519_KEY_IMPORT)
  32334. for (i = 0; i < 6; i++) {
  32335. outlen = sizeof(out);
  32336. XMEMSET(out, 0, sizeof(out));
  32337. if (wc_ed25519_import_private_key(sKeys[i], ED25519_KEY_SIZE, pKeys[i],
  32338. pKeySz[i], key) != 0)
  32339. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32340. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key) != 0)
  32341. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32342. if (XMEMCMP(out, sigs[i], 64))
  32343. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32344. #if defined(HAVE_ED25519_VERIFY)
  32345. /* test verify on good msg */
  32346. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32347. key) != 0 || verify != 1)
  32348. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32349. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  32350. /* test verify on good msg using streaming interface directly */
  32351. if (wc_ed25519_verify_msg_init(out, outlen,
  32352. key, (byte)Ed25519, NULL, 0) != 0)
  32353. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32354. for (j = 0; j < msgSz[i]; j += i) {
  32355. if (wc_ed25519_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  32356. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32357. }
  32358. if (wc_ed25519_verify_msg_final(out, outlen, &verify,
  32359. key) != 0 || verify != 1)
  32360. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32361. #endif /* WOLFSSL_ED25519_STREAMING_VERIFY */
  32362. /* test verify on bad msg */
  32363. out[outlen-1] = out[outlen-1] + 1;
  32364. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32365. key) == 0 || verify == 1)
  32366. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32367. #endif /* HAVE_ED25519_VERIFY */
  32368. /* test api for import/exporting keys */
  32369. exportPSz = sizeof(exportPKey);
  32370. exportSSz = sizeof(exportSKey);
  32371. if (wc_ed25519_export_public(key, exportPKey, &exportPSz) != 0)
  32372. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32373. if (wc_ed25519_import_public_ex(exportPKey, exportPSz, key2, 1) != 0)
  32374. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32375. if (wc_ed25519_export_private_only(key, exportSKey, &exportSSz) != 0)
  32376. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32377. if (wc_ed25519_import_private_key(exportSKey, exportSSz,
  32378. exportPKey, exportPSz, key2) != 0)
  32379. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32380. /* clear "out" buffer and test sign with imported keys */
  32381. outlen = sizeof(out);
  32382. XMEMSET(out, 0, sizeof(out));
  32383. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key2) != 0)
  32384. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32385. #if defined(HAVE_ED25519_VERIFY)
  32386. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32387. key2) != 0 || verify != 1)
  32388. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32389. if (XMEMCMP(out, sigs[i], 64))
  32390. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32391. #endif /* HAVE_ED25519_VERIFY */
  32392. }
  32393. {
  32394. /* Run tests for some rare code paths */
  32395. /* sig is exactly equal to the order */
  32396. static const byte rareEd1[] = {
  32397. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32398. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32399. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32400. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32401. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32402. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32403. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32404. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32405. };
  32406. /* sig is larger than the order before we get to the low part */
  32407. static const byte rareEd2[] = {
  32408. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32409. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32410. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32411. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32412. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32413. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32414. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32415. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10
  32416. };
  32417. /* sig is larger than the order in the low part */
  32418. static const byte rareEd3[] = {
  32419. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32420. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32421. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32422. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32423. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32424. 0xd6, 0x9c, 0xf9, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32425. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32426. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32427. };
  32428. /* sig is smaller than the order */
  32429. static const byte rareEd4[] = {
  32430. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32431. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32432. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32433. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32434. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32435. 0xd6, 0x9c, 0xf1, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32436. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32437. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32438. };
  32439. ret = wc_ed25519_import_private_key(sKeys[0], ED25519_KEY_SIZE,
  32440. pKeys[0], pKeySz[0], key);
  32441. if (ret != 0)
  32442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32443. ret = wc_ed25519_verify_msg(rareEd1, sizeof(rareEd1), msgs[0], msgSz[0],
  32444. &verify, key);
  32445. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32446. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32447. ret = wc_ed25519_verify_msg(rareEd2, sizeof(rareEd2), msgs[0], msgSz[0],
  32448. &verify, key);
  32449. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32451. ret = wc_ed25519_verify_msg(rareEd3, sizeof(rareEd3), msgs[0], msgSz[0],
  32452. &verify, key);
  32453. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32455. ret = wc_ed25519_verify_msg(rareEd4, sizeof(rareEd4), msgs[0], msgSz[0],
  32456. &verify, key);
  32457. if (ret != WC_NO_ERR_TRACE(SIG_VERIFY_E))
  32458. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32459. }
  32460. ret = ed25519ctx_test();
  32461. if (ret != 0)
  32462. goto cleanup;
  32463. ret = ed25519ph_test();
  32464. if (ret != 0)
  32465. goto cleanup;
  32466. #ifndef NO_ASN
  32467. /* Try ASN.1 encoded private-only key and public key. */
  32468. idx = 0;
  32469. ret = wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, key3,
  32470. sizeof(privateEd25519));
  32471. if (ret != 0)
  32472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32473. idx = 0;
  32474. if (wc_Ed25519PrivateKeyDecode(badPrivateEd25519, &idx, key3,
  32475. sizeof(badPrivateEd25519)) == 0)
  32476. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32477. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32478. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32479. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32480. /* try with a buffer size that is too large */
  32481. idx = 0;
  32482. if (wc_Ed25519PublicKeyDecode(badPublicEd25519, &idx, key3,
  32483. sizeof(badPublicEd25519)) == 0)
  32484. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32485. idx = 0;
  32486. ret = wc_Ed25519PublicKeyDecode(publicEd25519, &idx, key3,
  32487. sizeof(publicEd25519));
  32488. if (ret != 0)
  32489. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32490. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32491. if (ret != 0)
  32492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32493. if (XMEMCMP(out, sigs[0], 64))
  32494. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32495. #if defined(HAVE_ED25519_VERIFY)
  32496. /* test verify on good msg */
  32497. ret = wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3);
  32498. if (ret != 0 || verify != 1)
  32499. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32500. #endif /* HAVE_ED25519_VERIFY */
  32501. wc_ed25519_free(key3);
  32502. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32503. idx = 0;
  32504. ret = wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, key3,
  32505. sizeof(privPubEd25519));
  32506. if (ret != 0)
  32507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32508. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32509. if (ret != 0)
  32510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32511. if (XMEMCMP(out, sigs[0], 64))
  32512. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32513. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32514. wc_ed25519_delete(key3, &key3);
  32515. #else
  32516. wc_ed25519_free(key3);
  32517. #endif
  32518. #endif /* NO_ASN */
  32519. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32520. ret = ed25519_test_check_key();
  32521. if (ret < 0)
  32522. goto cleanup;
  32523. #ifdef WOLFSSL_TEST_CERT
  32524. ret = ed25519_test_cert();
  32525. if (ret < 0)
  32526. goto cleanup;
  32527. #if defined(WOLFSSL_CERT_GEN) && defined(HAVE_ED25519_MAKE_KEY)
  32528. ret = ed25519_test_make_cert();
  32529. if (ret < 0)
  32530. goto cleanup;
  32531. #endif /* WOLFSSL_CERT_GEN */
  32532. #endif /* WOLFSSL_TEST_CERT */
  32533. cleanup:
  32534. /* clean up keys when done */
  32535. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32536. wc_ed25519_delete(key, &key);
  32537. wc_ed25519_delete(key2, &key2);
  32538. #else
  32539. wc_ed25519_free(key);
  32540. wc_ed25519_free(key2);
  32541. #endif
  32542. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  32543. wc_FreeRng(&rng);
  32544. #endif
  32545. /* hush warnings of unused keySz and sigSz */
  32546. (void)keySz;
  32547. (void)sigSz;
  32548. return ret;
  32549. }
  32550. #endif /* HAVE_ED25519 */
  32551. #ifdef HAVE_CURVE448
  32552. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32553. defined(HAVE_CURVE448_KEY_IMPORT)
  32554. /* Test the wc_curve448_check_public API.
  32555. *
  32556. * returns 0 on success and -ve on failure.
  32557. */
  32558. static wc_test_ret_t curve448_check_public_test(void)
  32559. {
  32560. /* Little-endian values that will fail */
  32561. byte fail_le[][CURVE448_KEY_SIZE] = {
  32562. {
  32563. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32564. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32565. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32566. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32567. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32568. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32569. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32570. },
  32571. {
  32572. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32573. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32574. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32575. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32576. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32577. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32578. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32579. },
  32580. };
  32581. /* Big-endian values that will fail */
  32582. byte fail_be[][CURVE448_KEY_SIZE] = {
  32583. {
  32584. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32585. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32586. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32587. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32588. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32589. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32590. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32591. },
  32592. {
  32593. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32594. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32595. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32596. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32597. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32598. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32599. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32600. },
  32601. };
  32602. /* Good or valid public value */
  32603. byte good[CURVE448_KEY_SIZE] = {
  32604. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32605. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32606. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32607. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32608. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32609. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32610. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32611. };
  32612. int i;
  32613. wc_test_ret_t ret;
  32614. /* Parameter checks */
  32615. /* NULL pointer */
  32616. ret = wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN);
  32617. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32618. return WC_TEST_RET_ENC_EC(ret);
  32619. ret = wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN);
  32620. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32621. return WC_TEST_RET_ENC_EC(ret);
  32622. /* Length of 0 treated differently to other invalid lengths for TLS */
  32623. ret = wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN);
  32624. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32625. return WC_TEST_RET_ENC_EC(ret);
  32626. ret = wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN);
  32627. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32628. return WC_TEST_RET_ENC_EC(ret);
  32629. /* Length not CURVE448_KEY_SIZE */
  32630. for (i = 1; i < CURVE448_KEY_SIZE + 2; i++) {
  32631. if (i == CURVE448_KEY_SIZE)
  32632. continue;
  32633. if (wc_curve448_check_public(good, (word32)i, EC448_LITTLE_ENDIAN) !=
  32634. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32635. return WC_TEST_RET_ENC_I(i);
  32636. }
  32637. if (wc_curve448_check_public(good, (word32)i, EC448_BIG_ENDIAN) !=
  32638. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32639. return WC_TEST_RET_ENC_I(i);
  32640. }
  32641. }
  32642. /* Little-endian fail cases */
  32643. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  32644. if (wc_curve448_check_public(fail_le[i], CURVE448_KEY_SIZE,
  32645. EC448_LITTLE_ENDIAN) == 0) {
  32646. return WC_TEST_RET_ENC_I(i);
  32647. }
  32648. }
  32649. /* Big-endian fail cases */
  32650. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  32651. if (wc_curve448_check_public(fail_be[i], CURVE448_KEY_SIZE,
  32652. EC448_BIG_ENDIAN) == 0) {
  32653. return WC_TEST_RET_ENC_I(i);
  32654. }
  32655. }
  32656. /* Check a valid public value works! */
  32657. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE,
  32658. EC448_LITTLE_ENDIAN);
  32659. if (ret != 0)
  32660. return WC_TEST_RET_ENC_EC(ret);
  32661. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN);
  32662. if (ret != 0)
  32663. return WC_TEST_RET_ENC_EC(ret);
  32664. return 0;
  32665. }
  32666. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32667. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void)
  32668. {
  32669. WC_RNG rng;
  32670. wc_test_ret_t ret;
  32671. #ifdef HAVE_CURVE448_SHARED_SECRET
  32672. byte sharedA[CURVE448_KEY_SIZE];
  32673. byte sharedB[CURVE448_KEY_SIZE];
  32674. word32 y;
  32675. #endif
  32676. #ifdef HAVE_CURVE448_KEY_EXPORT
  32677. byte exportBuf[CURVE448_KEY_SIZE];
  32678. #endif
  32679. word32 x = 0;
  32680. curve448_key userA, userB, pubKey;
  32681. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32682. defined(HAVE_CURVE448_KEY_IMPORT)
  32683. /* test vectors from
  32684. https://www.rfc-editor.org/rfc/rfc7748.html
  32685. */
  32686. /* secret key for party a */
  32687. byte sa[] = {
  32688. 0x6b, 0x72, 0x98, 0xa5, 0xc0, 0xd8, 0xc2, 0x9a,
  32689. 0x1d, 0xab, 0x27, 0xf1, 0xa6, 0x82, 0x63, 0x00,
  32690. 0x91, 0x73, 0x89, 0x44, 0x97, 0x41, 0xa9, 0x74,
  32691. 0xf5, 0xba, 0xc9, 0xd9, 0x8d, 0xc2, 0x98, 0xd4,
  32692. 0x65, 0x55, 0xbc, 0xe8, 0xba, 0xe8, 0x9e, 0xee,
  32693. 0xd4, 0x00, 0x58, 0x4b, 0xb0, 0x46, 0xcf, 0x75,
  32694. 0x57, 0x9f, 0x51, 0xd1, 0x25, 0x49, 0x8f, 0x9a,
  32695. };
  32696. /* public key for party a */
  32697. byte pa[] = {
  32698. 0xa0, 0x1f, 0xc4, 0x32, 0xe5, 0x80, 0x7f, 0x17,
  32699. 0x53, 0x0d, 0x12, 0x88, 0xda, 0x12, 0x5b, 0x0c,
  32700. 0xd4, 0x53, 0xd9, 0x41, 0x72, 0x64, 0x36, 0xc8,
  32701. 0xbb, 0xd9, 0xc5, 0x22, 0x2c, 0x3d, 0xa7, 0xfa,
  32702. 0x63, 0x9c, 0xe0, 0x3d, 0xb8, 0xd2, 0x3b, 0x27,
  32703. 0x4a, 0x07, 0x21, 0xa1, 0xae, 0xd5, 0x22, 0x7d,
  32704. 0xe6, 0xe3, 0xb7, 0x31, 0xcc, 0xf7, 0x08, 0x9b,
  32705. };
  32706. /* secret key for party b */
  32707. byte sb[] = {
  32708. 0x2d, 0x99, 0x73, 0x51, 0xb6, 0x10, 0x6f, 0x36,
  32709. 0xb0, 0xd1, 0x09, 0x1b, 0x92, 0x9c, 0x4c, 0x37,
  32710. 0x21, 0x3e, 0x0d, 0x2b, 0x97, 0xe8, 0x5e, 0xbb,
  32711. 0x20, 0xc1, 0x27, 0x69, 0x1d, 0x0d, 0xad, 0x8f,
  32712. 0x1d, 0x81, 0x75, 0xb0, 0x72, 0x37, 0x45, 0xe6,
  32713. 0x39, 0xa3, 0xcb, 0x70, 0x44, 0x29, 0x0b, 0x99,
  32714. 0xe0, 0xe2, 0xa0, 0xc2, 0x7a, 0x6a, 0x30, 0x1c,
  32715. };
  32716. /* public key for party b */
  32717. byte pb[] = {
  32718. 0x09, 0x36, 0xf3, 0x7b, 0xc6, 0xc1, 0xbd, 0x07,
  32719. 0xae, 0x3d, 0xec, 0x7a, 0xb5, 0xdc, 0x06, 0xa7,
  32720. 0x3c, 0xa1, 0x32, 0x42, 0xfb, 0x34, 0x3e, 0xfc,
  32721. 0x72, 0xb9, 0xd8, 0x27, 0x30, 0xb4, 0x45, 0xf3,
  32722. 0xd4, 0xb0, 0xbd, 0x07, 0x71, 0x62, 0xa4, 0x6d,
  32723. 0xcf, 0xec, 0x6f, 0x9b, 0x59, 0x0b, 0xfc, 0xbc,
  32724. 0xf5, 0x20, 0xcd, 0xb0, 0x29, 0xa8, 0xb7, 0x3e,
  32725. };
  32726. /* expected shared key */
  32727. byte ss[] = {
  32728. 0x9d, 0x87, 0x4a, 0x51, 0x37, 0x50, 0x9a, 0x44,
  32729. 0x9a, 0xd5, 0x85, 0x30, 0x40, 0x24, 0x1c, 0x52,
  32730. 0x36, 0x39, 0x54, 0x35, 0xc3, 0x64, 0x24, 0xfd,
  32731. 0x56, 0x0b, 0x0c, 0xb6, 0x2b, 0x28, 0x1d, 0x28,
  32732. 0x52, 0x75, 0xa7, 0x40, 0xce, 0x32, 0xa2, 0x2d,
  32733. 0xd1, 0x74, 0x0f, 0x4a, 0xa9, 0x16, 0x1c, 0xec,
  32734. 0x95, 0xcc, 0xc6, 0x1a, 0x18, 0xf4, 0xff, 0x07,
  32735. };
  32736. #endif /* HAVE_CURVE448_SHARED_SECRET */
  32737. (void)x;
  32738. WOLFSSL_ENTER("curve448_test");
  32739. #ifndef HAVE_FIPS
  32740. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32741. #else
  32742. ret = wc_InitRng(&rng);
  32743. #endif
  32744. if (ret != 0)
  32745. return WC_TEST_RET_ENC_EC(ret);
  32746. wc_curve448_init(&userA);
  32747. wc_curve448_init(&userB);
  32748. wc_curve448_init(&pubKey);
  32749. /* make curve448 keys */
  32750. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA);
  32751. if (ret != 0)
  32752. return WC_TEST_RET_ENC_EC(ret);
  32753. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB);
  32754. if (ret != 0)
  32755. return WC_TEST_RET_ENC_EC(ret);
  32756. #ifdef HAVE_CURVE448_SHARED_SECRET
  32757. /* find shared secret key */
  32758. x = sizeof(sharedA);
  32759. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32760. if (ret != 0)
  32761. return WC_TEST_RET_ENC_EC(ret);
  32762. y = sizeof(sharedB);
  32763. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32764. if (ret != 0)
  32765. return WC_TEST_RET_ENC_EC(ret);
  32766. /* compare shared secret keys to test they are the same */
  32767. if (y != x)
  32768. return WC_TEST_RET_ENC_NC;
  32769. if (XMEMCMP(sharedA, sharedB, x))
  32770. return WC_TEST_RET_ENC_NC;
  32771. #endif
  32772. #ifdef HAVE_CURVE448_KEY_EXPORT
  32773. /* export a public key and import it for another user */
  32774. x = sizeof(exportBuf);
  32775. ret = wc_curve448_export_public(&userA, exportBuf, &x);
  32776. if (ret != 0)
  32777. return WC_TEST_RET_ENC_EC(ret);
  32778. #ifdef HAVE_CURVE448_KEY_IMPORT
  32779. ret = wc_curve448_import_public(exportBuf, x, &pubKey);
  32780. if (ret != 0)
  32781. return WC_TEST_RET_ENC_EC(ret);
  32782. #endif
  32783. #endif
  32784. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32785. defined(HAVE_CURVE448_KEY_IMPORT)
  32786. /* test shared key after importing a public key */
  32787. XMEMSET(sharedB, 0, sizeof(sharedB));
  32788. y = sizeof(sharedB);
  32789. ret = wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y);
  32790. if (ret != 0)
  32791. return WC_TEST_RET_ENC_EC(ret);
  32792. if (XMEMCMP(sharedA, sharedB, y))
  32793. return WC_TEST_RET_ENC_NC;
  32794. /* import RFC test vectors and compare shared key */
  32795. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32796. if (ret != 0)
  32797. return WC_TEST_RET_ENC_EC(ret);
  32798. ret = wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB);
  32799. if (ret != 0)
  32800. return WC_TEST_RET_ENC_EC(ret);
  32801. /* test against known test vector */
  32802. XMEMSET(sharedB, 0, sizeof(sharedB));
  32803. y = sizeof(sharedB);
  32804. ret = wc_curve448_shared_secret(&userA, &userB, sharedB, &y);
  32805. if (ret != 0)
  32806. return WC_TEST_RET_ENC_EC(ret);
  32807. if (XMEMCMP(ss, sharedB, y))
  32808. return WC_TEST_RET_ENC_NC;
  32809. /* test swapping roles of keys and generating same shared key */
  32810. XMEMSET(sharedB, 0, sizeof(sharedB));
  32811. y = sizeof(sharedB);
  32812. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32813. if (ret != 0)
  32814. return WC_TEST_RET_ENC_EC(ret);
  32815. if (XMEMCMP(ss, sharedB, y))
  32816. return WC_TEST_RET_ENC_NC;
  32817. /* test with 1 generated key and 1 from known test vector */
  32818. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32819. if (ret != 0)
  32820. return WC_TEST_RET_ENC_EC(ret);
  32821. ret = wc_curve448_make_key(&rng, 56, &userB);
  32822. if (ret != 0)
  32823. return WC_TEST_RET_ENC_EC(ret);
  32824. x = sizeof(sharedA);
  32825. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32826. if (ret != 0)
  32827. return WC_TEST_RET_ENC_EC(ret);
  32828. y = sizeof(sharedB);
  32829. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32830. if (ret != 0)
  32831. return WC_TEST_RET_ENC_EC(ret);
  32832. /* compare shared secret keys to test they are the same */
  32833. if (y != x)
  32834. return WC_TEST_RET_ENC_NC;
  32835. if (XMEMCMP(sharedA, sharedB, x))
  32836. return WC_TEST_RET_ENC_NC;
  32837. ret = curve448_check_public_test();
  32838. if (ret != 0)
  32839. return ret;
  32840. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32841. /* clean up keys when done */
  32842. wc_curve448_free(&pubKey);
  32843. wc_curve448_free(&userB);
  32844. wc_curve448_free(&userA);
  32845. wc_FreeRng(&rng);
  32846. return 0;
  32847. }
  32848. #endif /* HAVE_CURVE448 */
  32849. #ifdef HAVE_ED448
  32850. #ifdef WOLFSSL_TEST_CERT
  32851. static wc_test_ret_t ed448_test_cert(void)
  32852. {
  32853. DecodedCert cert[2];
  32854. DecodedCert* serverCert = NULL;
  32855. DecodedCert* caCert = NULL;
  32856. #ifdef HAVE_ED448_VERIFY
  32857. ed448_key key;
  32858. ed448_key* pubKey = NULL;
  32859. int verify;
  32860. #endif /* HAVE_ED448_VERIFY */
  32861. wc_test_ret_t ret;
  32862. byte* tmp;
  32863. size_t bytes;
  32864. XFILE file;
  32865. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32866. if (tmp == NULL) {
  32867. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32868. }
  32869. #ifdef USE_CERT_BUFFERS_256
  32870. XMEMCPY(tmp, ca_ed448_cert, sizeof_ca_ed448_cert);
  32871. bytes = sizeof_ca_ed448_cert;
  32872. #elif !defined(NO_FILESYSTEM)
  32873. file = XFOPEN(caEd448Cert, "rb");
  32874. if (file == NULL) {
  32875. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32876. }
  32877. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32878. XFCLOSE(file);
  32879. if (bytes == 0)
  32880. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32881. #else
  32882. /* No certificate to use. */
  32883. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32884. #endif
  32885. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  32886. caCert = &cert[0];
  32887. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  32888. if (ret != 0)
  32889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32890. #ifdef USE_CERT_BUFFERS_256
  32891. XMEMCPY(tmp, server_ed448_cert, sizeof_server_ed448_cert);
  32892. bytes = sizeof_server_ed448_cert;
  32893. #elif !defined(NO_FILESYSTEM)
  32894. file = XFOPEN(serverEd448Cert, "rb");
  32895. if (file == NULL) {
  32896. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32897. }
  32898. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32899. XFCLOSE(file);
  32900. if (bytes == 0)
  32901. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32902. #else
  32903. /* No certificate to use. */
  32904. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32905. #endif
  32906. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  32907. serverCert = &cert[1];
  32908. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  32909. if (ret != 0)
  32910. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32911. #ifdef HAVE_ED448_VERIFY
  32912. ret = wc_ed448_init(&key);
  32913. if (ret < 0)
  32914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32915. pubKey = &key;
  32916. ret = wc_ed448_import_public(caCert->publicKey, caCert->pubKeySize, pubKey);
  32917. if (ret < 0)
  32918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32919. ret = wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength,
  32920. serverCert->source + serverCert->certBegin,
  32921. serverCert->sigIndex - serverCert->certBegin,
  32922. &verify, pubKey, NULL, 0);
  32923. if (ret < 0 || verify != 1) {
  32924. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32925. }
  32926. #endif /* HAVE_ED448_VERIFY */
  32927. done:
  32928. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32929. #ifdef HAVE_ED448_VERIFY
  32930. wc_ed448_free(pubKey);
  32931. #endif /* HAVE_ED448_VERIFY */
  32932. if (caCert != NULL)
  32933. FreeDecodedCert(caCert);
  32934. if (serverCert != NULL)
  32935. FreeDecodedCert(serverCert);
  32936. return ret;
  32937. }
  32938. static wc_test_ret_t ed448_test_make_cert(void)
  32939. {
  32940. WC_RNG rng;
  32941. Cert cert;
  32942. DecodedCert decode;
  32943. ed448_key key;
  32944. ed448_key* privKey = NULL;
  32945. wc_test_ret_t ret = 0;
  32946. byte* tmp = NULL;
  32947. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  32948. #ifndef HAVE_FIPS
  32949. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32950. #else
  32951. ret = wc_InitRng(&rng);
  32952. #endif
  32953. if (ret != 0)
  32954. return WC_TEST_RET_ENC_EC(ret);
  32955. wc_ed448_init(&key);
  32956. privKey = &key;
  32957. wc_ed448_make_key(&rng, ED448_KEY_SIZE, privKey);
  32958. cert.daysValid = 365 * 2;
  32959. cert.selfSigned = 1;
  32960. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  32961. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  32962. cert.isCA = 0;
  32963. #ifdef WOLFSSL_CERT_EXT
  32964. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  32965. if (ret < 0)
  32966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32967. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32968. if (ret < 0)
  32969. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32970. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32971. if (ret < 0)
  32972. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32973. #endif
  32974. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32975. if (tmp == NULL) {
  32976. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32977. }
  32978. cert.sigType = CTC_ED448;
  32979. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng);
  32980. if (ret < 0)
  32981. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32982. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED448_TYPE,
  32983. privKey, &rng);
  32984. if (ret < 0)
  32985. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32986. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  32987. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  32988. FreeDecodedCert(&decode);
  32989. if (ret != 0)
  32990. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32991. done:
  32992. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32993. wc_ed448_free(privKey);
  32994. wc_FreeRng(&rng);
  32995. return ret;
  32996. }
  32997. #endif /* WOLFSSL_TEST_CERT */
  32998. #if defined(HAVE_ED448_KEY_IMPORT)
  32999. static wc_test_ret_t ed448_test_check_key(void)
  33000. {
  33001. /* Fails to find x-ordinate from this y-ordinate. */
  33002. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  33003. 0x40,
  33004. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33005. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33006. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33007. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33008. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33009. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33010. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33011. 0x00
  33012. };
  33013. /* Y-ordinate value larger than prime. */
  33014. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  33015. 0x40,
  33016. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33017. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33018. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33019. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33020. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33021. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33022. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33023. 0xff
  33024. };
  33025. /* Y-ordinate value equal to prime. */
  33026. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  33027. 0x40,
  33028. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33029. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33030. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33031. 0xff,0xff,0xff,0xff,0xfe,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,0xff,0xff,0xff,0xff,
  33035. 0xff
  33036. };
  33037. /* Y-ordinate value equal to prime - 1. */
  33038. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  33039. 0x40,
  33040. 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33041. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33042. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33043. 0xff,0xff,0xff,0xff,0xfe,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,0xff,0xff,0xff,0xff,
  33047. 0xff
  33048. };
  33049. ed448_key key;
  33050. int ret;
  33051. int res = 0;
  33052. /* Initialize key for use. */
  33053. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33054. if (ret != 0) {
  33055. return WC_TEST_RET_ENC_NC;
  33056. }
  33057. /* Load bad public key only and perform checks. */
  33058. ret = wc_ed448_import_public(key_bad_y, ED448_PUB_KEY_SIZE + 1, &key);
  33059. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33060. res = WC_TEST_RET_ENC_NC;
  33061. }
  33062. if (ret == 0) {
  33063. /* Load bad public key only and perform checks. */
  33064. ret = wc_ed448_import_public(key_bad_y_max, ED448_PUB_KEY_SIZE + 1,
  33065. &key);
  33066. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33067. res = WC_TEST_RET_ENC_NC;
  33068. }
  33069. }
  33070. if (res == 0) {
  33071. /* Load bad public key only and perform checks. */
  33072. ret = wc_ed448_import_public(key_bad_y_is_p, ED448_PUB_KEY_SIZE + 1,
  33073. &key);
  33074. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33075. res = WC_TEST_RET_ENC_NC;
  33076. }
  33077. }
  33078. if (res == 0) {
  33079. /* Load good public key only and perform checks. */
  33080. ret = wc_ed448_import_public(key_y_is_p_minus_1, ED448_PUB_KEY_SIZE + 1,
  33081. &key);
  33082. if (ret != 0) {
  33083. res = WC_TEST_RET_ENC_NC;
  33084. }
  33085. }
  33086. /* Dispose of key. */
  33087. wc_ed448_free(&key);
  33088. return res;
  33089. }
  33090. #endif
  33091. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33092. defined(HAVE_ED448_KEY_IMPORT)
  33093. static wc_test_ret_t ed448_ctx_test(void)
  33094. {
  33095. wc_test_ret_t ret;
  33096. byte out[ED448_SIG_SIZE];
  33097. word32 outlen;
  33098. #ifdef HAVE_ED448_VERIFY
  33099. int verify;
  33100. #endif /* HAVE_ED448_VERIFY */
  33101. ed448_key key;
  33102. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  33103. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33104. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33105. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33106. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33107. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33108. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33109. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33110. 0x4e
  33111. };
  33112. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  33113. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33114. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33115. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33116. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33117. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33118. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33119. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33120. 0x80
  33121. };
  33122. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx[] = {
  33123. 0xd4, 0xf8, 0xf6, 0x13, 0x17, 0x70, 0xdd, 0x46,
  33124. 0xf4, 0x08, 0x67, 0xd6, 0xfd, 0x5d, 0x50, 0x55,
  33125. 0xde, 0x43, 0x54, 0x1f, 0x8c, 0x5e, 0x35, 0xab,
  33126. 0xbc, 0xd0, 0x01, 0xb3, 0x2a, 0x89, 0xf7, 0xd2,
  33127. 0x15, 0x1f, 0x76, 0x47, 0xf1, 0x1d, 0x8c, 0xa2,
  33128. 0xae, 0x27, 0x9f, 0xb8, 0x42, 0xd6, 0x07, 0x21,
  33129. 0x7f, 0xce, 0x6e, 0x04, 0x2f, 0x68, 0x15, 0xea,
  33130. 0x00, 0x0c, 0x85, 0x74, 0x1d, 0xe5, 0xc8, 0xda,
  33131. 0x11, 0x44, 0xa6, 0xa1, 0xab, 0xa7, 0xf9, 0x6d,
  33132. 0xe4, 0x25, 0x05, 0xd7, 0xa7, 0x29, 0x85, 0x24,
  33133. 0xfd, 0xa5, 0x38, 0xfc, 0xcb, 0xbb, 0x75, 0x4f,
  33134. 0x57, 0x8c, 0x1c, 0xad, 0x10, 0xd5, 0x4d, 0x0d,
  33135. 0x54, 0x28, 0x40, 0x7e, 0x85, 0xdc, 0xbc, 0x98,
  33136. 0xa4, 0x91, 0x55, 0xc1, 0x37, 0x64, 0xe6, 0x6c,
  33137. 0x3c, 0x00
  33138. };
  33139. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  33140. 0x03
  33141. };
  33142. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  33143. 0x66,0x6f,0x6f
  33144. };
  33145. outlen = sizeof(out);
  33146. XMEMSET(out, 0, sizeof(out));
  33147. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33148. if (ret != 0)
  33149. return WC_TEST_RET_ENC_EC(ret);
  33150. ret = wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx,
  33151. sizeof(pKeyCtx), &key);
  33152. if (ret != 0)
  33153. return WC_TEST_RET_ENC_EC(ret);
  33154. ret = wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  33155. contextCtx, sizeof(contextCtx));
  33156. if (ret != 0)
  33157. return WC_TEST_RET_ENC_EC(ret);
  33158. if (XMEMCMP(out, sigCtx, sizeof(sigCtx)))
  33159. return WC_TEST_RET_ENC_NC;
  33160. #if defined(HAVE_ED448_VERIFY)
  33161. /* test verify on good msg */
  33162. ret = wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key,
  33163. contextCtx, sizeof(contextCtx));
  33164. if (ret != 0 || verify != 1)
  33165. return WC_TEST_RET_ENC_EC(ret);
  33166. #endif
  33167. wc_ed448_free(&key);
  33168. return 0;
  33169. }
  33170. static wc_test_ret_t ed448ph_test(void)
  33171. {
  33172. wc_test_ret_t ret;
  33173. byte out[ED448_SIG_SIZE];
  33174. word32 outlen;
  33175. #ifdef HAVE_ED448_VERIFY
  33176. int verify;
  33177. #endif /* HAVE_ED448_VERIFY */
  33178. ed448_key key;
  33179. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  33180. 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
  33181. 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
  33182. 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
  33183. 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42,
  33184. 0xef, 0x78, 0x22, 0xe0, 0xd5, 0x10, 0x41, 0x27,
  33185. 0xdc, 0x05, 0xd6, 0xdb, 0xef, 0xde, 0x69, 0xe3,
  33186. 0xab, 0x2c, 0xec, 0x7c, 0x86, 0x7c, 0x6e, 0x2c,
  33187. 0x49
  33188. };
  33189. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  33190. 0x25, 0x9b, 0x71, 0xc1, 0x9f, 0x83, 0xef, 0x77,
  33191. 0xa7, 0xab, 0xd2, 0x65, 0x24, 0xcb, 0xdb, 0x31,
  33192. 0x61, 0xb5, 0x90, 0xa4, 0x8f, 0x7d, 0x17, 0xde,
  33193. 0x3e, 0xe0, 0xba, 0x9c, 0x52, 0xbe, 0xb7, 0x43,
  33194. 0xc0, 0x94, 0x28, 0xa1, 0x31, 0xd6, 0xb1, 0xb5,
  33195. 0x73, 0x03, 0xd9, 0x0d, 0x81, 0x32, 0xc2, 0x76,
  33196. 0xd5, 0xed, 0x3d, 0x5d, 0x01, 0xc0, 0xf5, 0x38,
  33197. 0x80
  33198. };
  33199. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  33200. 0x82, 0x2f, 0x69, 0x01, 0xf7, 0x48, 0x0f, 0x3d,
  33201. 0x5f, 0x56, 0x2c, 0x59, 0x29, 0x94, 0xd9, 0x69,
  33202. 0x36, 0x02, 0x87, 0x56, 0x14, 0x48, 0x32, 0x56,
  33203. 0x50, 0x56, 0x00, 0xbb, 0xc2, 0x81, 0xae, 0x38,
  33204. 0x1f, 0x54, 0xd6, 0xbc, 0xe2, 0xea, 0x91, 0x15,
  33205. 0x74, 0x93, 0x2f, 0x52, 0xa4, 0xe6, 0xca, 0xdd,
  33206. 0x78, 0x76, 0x93, 0x75, 0xec, 0x3f, 0xfd, 0x1b,
  33207. 0x80, 0x1a, 0x0d, 0x9b, 0x3f, 0x40, 0x30, 0xcd,
  33208. 0x43, 0x39, 0x64, 0xb6, 0x45, 0x7e, 0xa3, 0x94,
  33209. 0x76, 0x51, 0x12, 0x14, 0xf9, 0x74, 0x69, 0xb5,
  33210. 0x7d, 0xd3, 0x2d, 0xbc, 0x56, 0x0a, 0x9a, 0x94,
  33211. 0xd0, 0x0b, 0xff, 0x07, 0x62, 0x04, 0x64, 0xa3,
  33212. 0xad, 0x20, 0x3d, 0xf7, 0xdc, 0x7c, 0xe3, 0x60,
  33213. 0xc3, 0xcd, 0x36, 0x96, 0xd9, 0xd9, 0xfa, 0xb9,
  33214. 0x0f, 0x00
  33215. };
  33216. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  33217. 0xc3, 0x22, 0x99, 0xd4, 0x6e, 0xc8, 0xff, 0x02,
  33218. 0xb5, 0x45, 0x40, 0x98, 0x28, 0x14, 0xdc, 0xe9,
  33219. 0xa0, 0x58, 0x12, 0xf8, 0x19, 0x62, 0xb6, 0x49,
  33220. 0xd5, 0x28, 0x09, 0x59, 0x16, 0xa2, 0xaa, 0x48,
  33221. 0x10, 0x65, 0xb1, 0x58, 0x04, 0x23, 0xef, 0x92,
  33222. 0x7e, 0xcf, 0x0a, 0xf5, 0x88, 0x8f, 0x90, 0xda,
  33223. 0x0f, 0x6a, 0x9a, 0x85, 0xad, 0x5d, 0xc3, 0xf2,
  33224. 0x80, 0xd9, 0x12, 0x24, 0xba, 0x99, 0x11, 0xa3,
  33225. 0x65, 0x3d, 0x00, 0xe4, 0x84, 0xe2, 0xce, 0x23,
  33226. 0x25, 0x21, 0x48, 0x1c, 0x86, 0x58, 0xdf, 0x30,
  33227. 0x4b, 0xb7, 0x74, 0x5a, 0x73, 0x51, 0x4c, 0xdb,
  33228. 0x9b, 0xf3, 0xe1, 0x57, 0x84, 0xab, 0x71, 0x28,
  33229. 0x4f, 0x8d, 0x07, 0x04, 0xa6, 0x08, 0xc5, 0x4a,
  33230. 0x6b, 0x62, 0xd9, 0x7b, 0xeb, 0x51, 0x1d, 0x13,
  33231. 0x21, 0x00
  33232. };
  33233. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  33234. 0x61,0x62,0x63
  33235. };
  33236. /* SHA-512 hash of msgPh */
  33237. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  33238. 0x48, 0x33, 0x66, 0x60, 0x13, 0x60, 0xa8, 0x77,
  33239. 0x1c, 0x68, 0x63, 0x08, 0x0c, 0xc4, 0x11, 0x4d,
  33240. 0x8d, 0xb4, 0x45, 0x30, 0xf8, 0xf1, 0xe1, 0xee,
  33241. 0x4f, 0x94, 0xea, 0x37, 0xe7, 0x8b, 0x57, 0x39,
  33242. 0xd5, 0xa1, 0x5b, 0xef, 0x18, 0x6a, 0x53, 0x86,
  33243. 0xc7, 0x57, 0x44, 0xc0, 0x52, 0x7e, 0x1f, 0xaa,
  33244. 0x9f, 0x87, 0x26, 0xe4, 0x62, 0xa1, 0x2a, 0x4f,
  33245. 0xeb, 0x06, 0xbd, 0x88, 0x01, 0xe7, 0x51, 0xe4
  33246. };
  33247. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  33248. 0x66,0x6f,0x6f
  33249. };
  33250. outlen = sizeof(out);
  33251. XMEMSET(out, 0, sizeof(out));
  33252. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33253. if (ret != 0)
  33254. return WC_TEST_RET_ENC_EC(ret);
  33255. ret = wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh,
  33256. sizeof(pKeyPh), &key);
  33257. if (ret != 0)
  33258. return WC_TEST_RET_ENC_EC(ret);
  33259. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL,
  33260. 0);
  33261. if (ret != 0)
  33262. return WC_TEST_RET_ENC_EC(ret);
  33263. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33264. return WC_TEST_RET_ENC_NC;
  33265. #if defined(HAVE_ED448_VERIFY)
  33266. /* test verify on good msg */
  33267. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33268. NULL, 0);
  33269. if (ret != 0 || verify != 1) {
  33270. return WC_TEST_RET_ENC_EC(ret);
  33271. }
  33272. #endif
  33273. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  33274. contextPh2, sizeof(contextPh2));
  33275. if (ret != 0)
  33276. return WC_TEST_RET_ENC_EC(ret);
  33277. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33278. return WC_TEST_RET_ENC_NC;
  33279. #if defined(HAVE_ED448_VERIFY)
  33280. /* test verify on good msg */
  33281. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33282. contextPh2, sizeof(contextPh2));
  33283. if (ret != 0 || verify != 1) {
  33284. return WC_TEST_RET_ENC_EC(ret);
  33285. }
  33286. #endif
  33287. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL,
  33288. 0);
  33289. if (ret != 0)
  33290. return WC_TEST_RET_ENC_EC(ret);
  33291. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33292. return WC_TEST_RET_ENC_NC;
  33293. #if defined(HAVE_ED448_VERIFY)
  33294. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33295. &key, NULL, 0);
  33296. if (ret != 0 || verify != 1) {
  33297. return WC_TEST_RET_ENC_EC(ret);
  33298. }
  33299. #endif
  33300. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  33301. contextPh2, sizeof(contextPh2));
  33302. if (ret != 0)
  33303. return WC_TEST_RET_ENC_EC(ret);
  33304. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33305. return WC_TEST_RET_ENC_NC;
  33306. #if defined(HAVE_ED448_VERIFY)
  33307. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33308. &key, contextPh2, sizeof(contextPh2));
  33309. if (ret != 0 || verify != 1) {
  33310. return WC_TEST_RET_ENC_EC(ret);
  33311. }
  33312. #endif
  33313. wc_ed448_free(&key);
  33314. return 0;
  33315. }
  33316. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33317. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
  33318. {
  33319. wc_test_ret_t ret;
  33320. WC_RNG rng;
  33321. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33322. defined(HAVE_ED448_KEY_IMPORT)
  33323. byte out[ED448_SIG_SIZE];
  33324. int i;
  33325. word32 outlen;
  33326. #ifdef HAVE_ED448_VERIFY
  33327. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33328. int j;
  33329. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33330. int verify;
  33331. #endif /* HAVE_ED448_VERIFY */
  33332. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33333. word32 keySz, sigSz;
  33334. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33335. ed448_key *key = NULL;
  33336. ed448_key *key2 = NULL;
  33337. #else
  33338. ed448_key key[1];
  33339. ed448_key key2[1];
  33340. #endif
  33341. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33342. defined(HAVE_ED448_KEY_IMPORT)
  33343. /* test vectors from
  33344. https://tools.ietf.org/html/rfc8032
  33345. */
  33346. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  33347. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33348. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33349. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33350. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33351. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33352. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33353. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33354. 0x5b
  33355. };
  33356. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  33357. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33358. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33359. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33360. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33361. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33362. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33363. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33364. 0x4e
  33365. };
  33366. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  33367. 0x25, 0x8c, 0xdd, 0x4a, 0xda, 0x32, 0xed, 0x9c,
  33368. 0x9f, 0xf5, 0x4e, 0x63, 0x75, 0x6a, 0xe5, 0x82,
  33369. 0xfb, 0x8f, 0xab, 0x2a, 0xc7, 0x21, 0xf2, 0xc8,
  33370. 0xe6, 0x76, 0xa7, 0x27, 0x68, 0x51, 0x3d, 0x93,
  33371. 0x9f, 0x63, 0xdd, 0xdb, 0x55, 0x60, 0x91, 0x33,
  33372. 0xf2, 0x9a, 0xdf, 0x86, 0xec, 0x99, 0x29, 0xdc,
  33373. 0xcb, 0x52, 0xc1, 0xc5, 0xfd, 0x2f, 0xf7, 0xe2,
  33374. 0x1b
  33375. };
  33376. /* uncompressed test */
  33377. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  33378. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33379. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33380. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33381. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33382. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33383. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33384. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33385. 0x5b
  33386. };
  33387. /* compressed prefix test */
  33388. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  33389. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33390. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33391. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33392. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33393. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33394. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33395. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33396. 0x5b
  33397. };
  33398. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  33399. 0x87, 0x2d, 0x09, 0x37, 0x80, 0xf5, 0xd3, 0x73,
  33400. 0x0d, 0xf7, 0xc2, 0x12, 0x66, 0x4b, 0x37, 0xb8,
  33401. 0xa0, 0xf2, 0x4f, 0x56, 0x81, 0x0d, 0xaa, 0x83,
  33402. 0x82, 0xcd, 0x4f, 0xa3, 0xf7, 0x76, 0x34, 0xec,
  33403. 0x44, 0xdc, 0x54, 0xf1, 0xc2, 0xed, 0x9b, 0xea,
  33404. 0x86, 0xfa, 0xfb, 0x76, 0x32, 0xd8, 0xbe, 0x19,
  33405. 0x9e, 0xa1, 0x65, 0xf5, 0xad, 0x55, 0xdd, 0x9c,
  33406. 0xe8
  33407. };
  33408. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  33409. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  33410. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33411. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33412. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33413. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33414. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33415. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33416. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33417. 0x80
  33418. };
  33419. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  33420. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33421. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33422. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33423. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33424. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33425. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33426. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33427. 0x80
  33428. };
  33429. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  33430. 0x3b, 0xa1, 0x6d, 0xa0, 0xc6, 0xf2, 0xcc, 0x1f,
  33431. 0x30, 0x18, 0x77, 0x40, 0x75, 0x6f, 0x5e, 0x79,
  33432. 0x8d, 0x6b, 0xc5, 0xfc, 0x01, 0x5d, 0x7c, 0x63,
  33433. 0xcc, 0x95, 0x10, 0xee, 0x3f, 0xd4, 0x4a, 0xdc,
  33434. 0x24, 0xd8, 0xe9, 0x68, 0xb6, 0xe4, 0x6e, 0x6f,
  33435. 0x94, 0xd1, 0x9b, 0x94, 0x53, 0x61, 0x72, 0x6b,
  33436. 0xd7, 0x5e, 0x14, 0x9e, 0xf0, 0x98, 0x17, 0xf5,
  33437. 0x80
  33438. };
  33439. /* uncompressed test */
  33440. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  33441. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33442. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33443. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33444. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33445. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33446. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33447. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33448. 0x80
  33449. };
  33450. /* compressed prefix */
  33451. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  33452. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33453. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33454. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33455. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33456. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33457. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33458. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33459. 0x80
  33460. };
  33461. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  33462. 0xa8, 0x1b, 0x2e, 0x8a, 0x70, 0xa5, 0xac, 0x94,
  33463. 0xff, 0xdb, 0xcc, 0x9b, 0xad, 0xfc, 0x3f, 0xeb,
  33464. 0x08, 0x01, 0xf2, 0x58, 0x57, 0x8b, 0xb1, 0x14,
  33465. 0xad, 0x44, 0xec, 0xe1, 0xec, 0x0e, 0x79, 0x9d,
  33466. 0xa0, 0x8e, 0xff, 0xb8, 0x1c, 0x5d, 0x68, 0x5c,
  33467. 0x0c, 0x56, 0xf6, 0x4e, 0xec, 0xae, 0xf8, 0xcd,
  33468. 0xf1, 0x1c, 0xc3, 0x87, 0x37, 0x83, 0x8c, 0xf4,
  33469. 0x00
  33470. };
  33471. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  33472. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  33473. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  33474. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  33475. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33476. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33477. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33478. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33479. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33480. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33481. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33482. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33483. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33484. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33485. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33486. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33487. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33488. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33489. 0x26, 0x00
  33490. };
  33491. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  33492. 0x26, 0xb8, 0xf9, 0x17, 0x27, 0xbd, 0x62, 0x89,
  33493. 0x7a, 0xf1, 0x5e, 0x41, 0xeb, 0x43, 0xc3, 0x77,
  33494. 0xef, 0xb9, 0xc6, 0x10, 0xd4, 0x8f, 0x23, 0x35,
  33495. 0xcb, 0x0b, 0xd0, 0x08, 0x78, 0x10, 0xf4, 0x35,
  33496. 0x25, 0x41, 0xb1, 0x43, 0xc4, 0xb9, 0x81, 0xb7,
  33497. 0xe1, 0x8f, 0x62, 0xde, 0x8c, 0xcd, 0xf6, 0x33,
  33498. 0xfc, 0x1b, 0xf0, 0x37, 0xab, 0x7c, 0xd7, 0x79,
  33499. 0x80, 0x5e, 0x0d, 0xbc, 0xc0, 0xaa, 0xe1, 0xcb,
  33500. 0xce, 0xe1, 0xaf, 0xb2, 0xe0, 0x27, 0xdf, 0x36,
  33501. 0xbc, 0x04, 0xdc, 0xec, 0xbf, 0x15, 0x43, 0x36,
  33502. 0xc1, 0x9f, 0x0a, 0xf7, 0xe0, 0xa6, 0x47, 0x29,
  33503. 0x05, 0xe7, 0x99, 0xf1, 0x95, 0x3d, 0x2a, 0x0f,
  33504. 0xf3, 0x34, 0x8a, 0xb2, 0x1a, 0xa4, 0xad, 0xaf,
  33505. 0xd1, 0xd2, 0x34, 0x44, 0x1c, 0xf8, 0x07, 0xc0,
  33506. 0x3a, 0x00
  33507. };
  33508. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  33509. 0x7e, 0xee, 0xab, 0x7c, 0x4e, 0x50, 0xfb, 0x79,
  33510. 0x9b, 0x41, 0x8e, 0xe5, 0xe3, 0x19, 0x7f, 0xf6,
  33511. 0xbf, 0x15, 0xd4, 0x3a, 0x14, 0xc3, 0x43, 0x89,
  33512. 0xb5, 0x9d, 0xd1, 0xa7, 0xb1, 0xb8, 0x5b, 0x4a,
  33513. 0xe9, 0x04, 0x38, 0xac, 0xa6, 0x34, 0xbe, 0xa4,
  33514. 0x5e, 0x3a, 0x26, 0x95, 0xf1, 0x27, 0x0f, 0x07,
  33515. 0xfd, 0xcd, 0xf7, 0xc6, 0x2b, 0x8e, 0xfe, 0xaf,
  33516. 0x00, 0xb4, 0x5c, 0x2c, 0x96, 0xba, 0x45, 0x7e,
  33517. 0xb1, 0xa8, 0xbf, 0x07, 0x5a, 0x3d, 0xb2, 0x8e,
  33518. 0x5c, 0x24, 0xf6, 0xb9, 0x23, 0xed, 0x4a, 0xd7,
  33519. 0x47, 0xc3, 0xc9, 0xe0, 0x3c, 0x70, 0x79, 0xef,
  33520. 0xb8, 0x7c, 0xb1, 0x10, 0xd3, 0xa9, 0x98, 0x61,
  33521. 0xe7, 0x20, 0x03, 0xcb, 0xae, 0x6d, 0x6b, 0x8b,
  33522. 0x82, 0x7e, 0x4e, 0x6c, 0x14, 0x30, 0x64, 0xff,
  33523. 0x3c, 0x00
  33524. };
  33525. /* uncompressed test */
  33526. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  33527. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33528. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33529. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33530. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33531. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33532. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33533. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33534. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33535. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33536. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33537. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33538. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33539. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33540. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33541. 0x26, 0x00
  33542. };
  33543. /* compressed prefix */
  33544. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  33545. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33546. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33547. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33548. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33549. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33550. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33551. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33552. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33553. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33554. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33555. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33556. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33557. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33558. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33559. 0x26, 0x00
  33560. };
  33561. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  33562. 0xe3, 0x01, 0x34, 0x5a, 0x41, 0xa3, 0x9a, 0x4d,
  33563. 0x72, 0xff, 0xf8, 0xdf, 0x69, 0xc9, 0x80, 0x75,
  33564. 0xa0, 0xcc, 0x08, 0x2b, 0x80, 0x2f, 0xc9, 0xb2,
  33565. 0xb6, 0xbc, 0x50, 0x3f, 0x92, 0x6b, 0x65, 0xbd,
  33566. 0xdf, 0x7f, 0x4c, 0x8f, 0x1c, 0xb4, 0x9f, 0x63,
  33567. 0x96, 0xaf, 0xc8, 0xa7, 0x0a, 0xbe, 0x6d, 0x8a,
  33568. 0xef, 0x0d, 0xb4, 0x78, 0xd4, 0xc6, 0xb2, 0x97,
  33569. 0x00, 0x76, 0xc6, 0xa0, 0x48, 0x4f, 0xe7, 0x6d,
  33570. 0x76, 0xb3, 0xa9, 0x76, 0x25, 0xd7, 0x9f, 0x1c,
  33571. 0xe2, 0x40, 0xe7, 0xc5, 0x76, 0x75, 0x0d, 0x29,
  33572. 0x55, 0x28, 0x28, 0x6f, 0x71, 0x9b, 0x41, 0x3d,
  33573. 0xe9, 0xad, 0xa3, 0xe8, 0xeb, 0x78, 0xed, 0x57,
  33574. 0x36, 0x03, 0xce, 0x30, 0xd8, 0xbb, 0x76, 0x17,
  33575. 0x85, 0xdc, 0x30, 0xdb, 0xc3, 0x20, 0x86, 0x9e,
  33576. 0x1a, 0x00
  33577. };
  33578. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  33579. #define SIGSZ sizeof(sig1)
  33580. PEDANTIC_EXTENSION WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = { 0 };
  33581. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = { 0x03 };
  33582. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = { 0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd,
  33583. 0x66, 0x81, 0x1e, 0x29, 0x15 };
  33584. /* test of a 1023 byte long message */
  33585. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  33586. 0x6d, 0xdf, 0x80, 0x2e, 0x1a, 0xae, 0x49, 0x86,
  33587. 0x93, 0x5f, 0x7f, 0x98, 0x1b, 0xa3, 0xf0, 0x35,
  33588. 0x1d, 0x62, 0x73, 0xc0, 0xa0, 0xc2, 0x2c, 0x9c,
  33589. 0x0e, 0x83, 0x39, 0x16, 0x8e, 0x67, 0x54, 0x12,
  33590. 0xa3, 0xde, 0xbf, 0xaf, 0x43, 0x5e, 0xd6, 0x51,
  33591. 0x55, 0x80, 0x07, 0xdb, 0x43, 0x84, 0xb6, 0x50,
  33592. 0xfc, 0xc0, 0x7e, 0x3b, 0x58, 0x6a, 0x27, 0xa4,
  33593. 0xf7, 0xa0, 0x0a, 0xc8, 0xa6, 0xfe, 0xc2, 0xcd,
  33594. 0x86, 0xae, 0x4b, 0xf1, 0x57, 0x0c, 0x41, 0xe6,
  33595. 0xa4, 0x0c, 0x93, 0x1d, 0xb2, 0x7b, 0x2f, 0xaa,
  33596. 0x15, 0xa8, 0xce, 0xdd, 0x52, 0xcf, 0xf7, 0x36,
  33597. 0x2c, 0x4e, 0x6e, 0x23, 0xda, 0xec, 0x0f, 0xbc,
  33598. 0x3a, 0x79, 0xb6, 0x80, 0x6e, 0x31, 0x6e, 0xfc,
  33599. 0xc7, 0xb6, 0x81, 0x19, 0xbf, 0x46, 0xbc, 0x76,
  33600. 0xa2, 0x60, 0x67, 0xa5, 0x3f, 0x29, 0x6d, 0xaf,
  33601. 0xdb, 0xdc, 0x11, 0xc7, 0x7f, 0x77, 0x77, 0xe9,
  33602. 0x72, 0x66, 0x0c, 0xf4, 0xb6, 0xa9, 0xb3, 0x69,
  33603. 0xa6, 0x66, 0x5f, 0x02, 0xe0, 0xcc, 0x9b, 0x6e,
  33604. 0xdf, 0xad, 0x13, 0x6b, 0x4f, 0xab, 0xe7, 0x23,
  33605. 0xd2, 0x81, 0x3d, 0xb3, 0x13, 0x6c, 0xfd, 0xe9,
  33606. 0xb6, 0xd0, 0x44, 0x32, 0x2f, 0xee, 0x29, 0x47,
  33607. 0x95, 0x2e, 0x03, 0x1b, 0x73, 0xab, 0x5c, 0x60,
  33608. 0x33, 0x49, 0xb3, 0x07, 0xbd, 0xc2, 0x7b, 0xc6,
  33609. 0xcb, 0x8b, 0x8b, 0xbd, 0x7b, 0xd3, 0x23, 0x21,
  33610. 0x9b, 0x80, 0x33, 0xa5, 0x81, 0xb5, 0x9e, 0xad,
  33611. 0xeb, 0xb0, 0x9b, 0x3c, 0x4f, 0x3d, 0x22, 0x77,
  33612. 0xd4, 0xf0, 0x34, 0x36, 0x24, 0xac, 0xc8, 0x17,
  33613. 0x80, 0x47, 0x28, 0xb2, 0x5a, 0xb7, 0x97, 0x17,
  33614. 0x2b, 0x4c, 0x5c, 0x21, 0xa2, 0x2f, 0x9c, 0x78,
  33615. 0x39, 0xd6, 0x43, 0x00, 0x23, 0x2e, 0xb6, 0x6e,
  33616. 0x53, 0xf3, 0x1c, 0x72, 0x3f, 0xa3, 0x7f, 0xe3,
  33617. 0x87, 0xc7, 0xd3, 0xe5, 0x0b, 0xdf, 0x98, 0x13,
  33618. 0xa3, 0x0e, 0x5b, 0xb1, 0x2c, 0xf4, 0xcd, 0x93,
  33619. 0x0c, 0x40, 0xcf, 0xb4, 0xe1, 0xfc, 0x62, 0x25,
  33620. 0x92, 0xa4, 0x95, 0x88, 0x79, 0x44, 0x94, 0xd5,
  33621. 0x6d, 0x24, 0xea, 0x4b, 0x40, 0xc8, 0x9f, 0xc0,
  33622. 0x59, 0x6c, 0xc9, 0xeb, 0xb9, 0x61, 0xc8, 0xcb,
  33623. 0x10, 0xad, 0xde, 0x97, 0x6a, 0x5d, 0x60, 0x2b,
  33624. 0x1c, 0x3f, 0x85, 0xb9, 0xb9, 0xa0, 0x01, 0xed,
  33625. 0x3c, 0x6a, 0x4d, 0x3b, 0x14, 0x37, 0xf5, 0x20,
  33626. 0x96, 0xcd, 0x19, 0x56, 0xd0, 0x42, 0xa5, 0x97,
  33627. 0xd5, 0x61, 0xa5, 0x96, 0xec, 0xd3, 0xd1, 0x73,
  33628. 0x5a, 0x8d, 0x57, 0x0e, 0xa0, 0xec, 0x27, 0x22,
  33629. 0x5a, 0x2c, 0x4a, 0xaf, 0xf2, 0x63, 0x06, 0xd1,
  33630. 0x52, 0x6c, 0x1a, 0xf3, 0xca, 0x6d, 0x9c, 0xf5,
  33631. 0xa2, 0xc9, 0x8f, 0x47, 0xe1, 0xc4, 0x6d, 0xb9,
  33632. 0xa3, 0x32, 0x34, 0xcf, 0xd4, 0xd8, 0x1f, 0x2c,
  33633. 0x98, 0x53, 0x8a, 0x09, 0xeb, 0xe7, 0x69, 0x98,
  33634. 0xd0, 0xd8, 0xfd, 0x25, 0x99, 0x7c, 0x7d, 0x25,
  33635. 0x5c, 0x6d, 0x66, 0xec, 0xe6, 0xfa, 0x56, 0xf1,
  33636. 0x11, 0x44, 0x95, 0x0f, 0x02, 0x77, 0x95, 0xe6,
  33637. 0x53, 0x00, 0x8f, 0x4b, 0xd7, 0xca, 0x2d, 0xee,
  33638. 0x85, 0xd8, 0xe9, 0x0f, 0x3d, 0xc3, 0x15, 0x13,
  33639. 0x0c, 0xe2, 0xa0, 0x03, 0x75, 0xa3, 0x18, 0xc7,
  33640. 0xc3, 0xd9, 0x7b, 0xe2, 0xc8, 0xce, 0x5b, 0x6d,
  33641. 0xb4, 0x1a, 0x62, 0x54, 0xff, 0x26, 0x4f, 0xa6,
  33642. 0x15, 0x5b, 0xae, 0xe3, 0xb0, 0x77, 0x3c, 0x0f,
  33643. 0x49, 0x7c, 0x57, 0x3f, 0x19, 0xbb, 0x4f, 0x42,
  33644. 0x40, 0x28, 0x1f, 0x0b, 0x1f, 0x4f, 0x7b, 0xe8,
  33645. 0x57, 0xa4, 0xe5, 0x9d, 0x41, 0x6c, 0x06, 0xb4,
  33646. 0xc5, 0x0f, 0xa0, 0x9e, 0x18, 0x10, 0xdd, 0xc6,
  33647. 0xb1, 0x46, 0x7b, 0xae, 0xac, 0x5a, 0x36, 0x68,
  33648. 0xd1, 0x1b, 0x6e, 0xca, 0xa9, 0x01, 0x44, 0x00,
  33649. 0x16, 0xf3, 0x89, 0xf8, 0x0a, 0xcc, 0x4d, 0xb9,
  33650. 0x77, 0x02, 0x5e, 0x7f, 0x59, 0x24, 0x38, 0x8c,
  33651. 0x7e, 0x34, 0x0a, 0x73, 0x2e, 0x55, 0x44, 0x40,
  33652. 0xe7, 0x65, 0x70, 0xf8, 0xdd, 0x71, 0xb7, 0xd6,
  33653. 0x40, 0xb3, 0x45, 0x0d, 0x1f, 0xd5, 0xf0, 0x41,
  33654. 0x0a, 0x18, 0xf9, 0xa3, 0x49, 0x4f, 0x70, 0x7c,
  33655. 0x71, 0x7b, 0x79, 0xb4, 0xbf, 0x75, 0xc9, 0x84,
  33656. 0x00, 0xb0, 0x96, 0xb2, 0x16, 0x53, 0xb5, 0xd2,
  33657. 0x17, 0xcf, 0x35, 0x65, 0xc9, 0x59, 0x74, 0x56,
  33658. 0xf7, 0x07, 0x03, 0x49, 0x7a, 0x07, 0x87, 0x63,
  33659. 0x82, 0x9b, 0xc0, 0x1b, 0xb1, 0xcb, 0xc8, 0xfa,
  33660. 0x04, 0xea, 0xdc, 0x9a, 0x6e, 0x3f, 0x66, 0x99,
  33661. 0x58, 0x7a, 0x9e, 0x75, 0xc9, 0x4e, 0x5b, 0xab,
  33662. 0x00, 0x36, 0xe0, 0xb2, 0xe7, 0x11, 0x39, 0x2c,
  33663. 0xff, 0x00, 0x47, 0xd0, 0xd6, 0xb0, 0x5b, 0xd2,
  33664. 0xa5, 0x88, 0xbc, 0x10, 0x97, 0x18, 0x95, 0x42,
  33665. 0x59, 0xf1, 0xd8, 0x66, 0x78, 0xa5, 0x79, 0xa3,
  33666. 0x12, 0x0f, 0x19, 0xcf, 0xb2, 0x96, 0x3f, 0x17,
  33667. 0x7a, 0xeb, 0x70, 0xf2, 0xd4, 0x84, 0x48, 0x26,
  33668. 0x26, 0x2e, 0x51, 0xb8, 0x02, 0x71, 0x27, 0x20,
  33669. 0x68, 0xef, 0x5b, 0x38, 0x56, 0xfa, 0x85, 0x35,
  33670. 0xaa, 0x2a, 0x88, 0xb2, 0xd4, 0x1f, 0x2a, 0x0e,
  33671. 0x2f, 0xda, 0x76, 0x24, 0xc2, 0x85, 0x02, 0x72,
  33672. 0xac, 0x4a, 0x2f, 0x56, 0x1f, 0x8f, 0x2f, 0x7a,
  33673. 0x31, 0x8b, 0xfd, 0x5c, 0xaf, 0x96, 0x96, 0x14,
  33674. 0x9e, 0x4a, 0xc8, 0x24, 0xad, 0x34, 0x60, 0x53,
  33675. 0x8f, 0xdc, 0x25, 0x42, 0x1b, 0xee, 0xc2, 0xcc,
  33676. 0x68, 0x18, 0x16, 0x2d, 0x06, 0xbb, 0xed, 0x0c,
  33677. 0x40, 0xa3, 0x87, 0x19, 0x23, 0x49, 0xdb, 0x67,
  33678. 0xa1, 0x18, 0xba, 0xda, 0x6c, 0xd5, 0xab, 0x01,
  33679. 0x40, 0xee, 0x27, 0x32, 0x04, 0xf6, 0x28, 0xaa,
  33680. 0xd1, 0xc1, 0x35, 0xf7, 0x70, 0x27, 0x9a, 0x65,
  33681. 0x1e, 0x24, 0xd8, 0xc1, 0x4d, 0x75, 0xa6, 0x05,
  33682. 0x9d, 0x76, 0xb9, 0x6a, 0x6f, 0xd8, 0x57, 0xde,
  33683. 0xf5, 0xe0, 0xb3, 0x54, 0xb2, 0x7a, 0xb9, 0x37,
  33684. 0xa5, 0x81, 0x5d, 0x16, 0xb5, 0xfa, 0xe4, 0x07,
  33685. 0xff, 0x18, 0x22, 0x2c, 0x6d, 0x1e, 0xd2, 0x63,
  33686. 0xbe, 0x68, 0xc9, 0x5f, 0x32, 0xd9, 0x08, 0xbd,
  33687. 0x89, 0x5c, 0xd7, 0x62, 0x07, 0xae, 0x72, 0x64,
  33688. 0x87, 0x56, 0x7f, 0x9a, 0x67, 0xda, 0xd7, 0x9a,
  33689. 0xbe, 0xc3, 0x16, 0xf6, 0x83, 0xb1, 0x7f, 0x2d,
  33690. 0x02, 0xbf, 0x07, 0xe0, 0xac, 0x8b, 0x5b, 0xc6,
  33691. 0x16, 0x2c, 0xf9, 0x46, 0x97, 0xb3, 0xc2, 0x7c,
  33692. 0xd1, 0xfe, 0xa4, 0x9b, 0x27, 0xf2, 0x3b, 0xa2,
  33693. 0x90, 0x18, 0x71, 0x96, 0x25, 0x06, 0x52, 0x0c,
  33694. 0x39, 0x2d, 0xa8, 0xb6, 0xad, 0x0d, 0x99, 0xf7,
  33695. 0x01, 0x3f, 0xbc, 0x06, 0xc2, 0xc1, 0x7a, 0x56,
  33696. 0x95, 0x00, 0xc8, 0xa7, 0x69, 0x64, 0x81, 0xc1,
  33697. 0xcd, 0x33, 0xe9, 0xb1, 0x4e, 0x40, 0xb8, 0x2e,
  33698. 0x79, 0xa5, 0xf5, 0xdb, 0x82, 0x57, 0x1b, 0xa9,
  33699. 0x7b, 0xae, 0x3a, 0xd3, 0xe0, 0x47, 0x95, 0x15,
  33700. 0xbb, 0x0e, 0x2b, 0x0f, 0x3b, 0xfc, 0xd1, 0xfd,
  33701. 0x33, 0x03, 0x4e, 0xfc, 0x62, 0x45, 0xed, 0xdd,
  33702. 0x7e, 0xe2, 0x08, 0x6d, 0xda, 0xe2, 0x60, 0x0d,
  33703. 0x8c, 0xa7, 0x3e, 0x21, 0x4e, 0x8c, 0x2b, 0x0b,
  33704. 0xdb, 0x2b, 0x04, 0x7c, 0x6a, 0x46, 0x4a, 0x56,
  33705. 0x2e, 0xd7, 0x7b, 0x73, 0xd2, 0xd8, 0x41, 0xc4,
  33706. 0xb3, 0x49, 0x73, 0x55, 0x12, 0x57, 0x71, 0x3b,
  33707. 0x75, 0x36, 0x32, 0xef, 0xba, 0x34, 0x81, 0x69,
  33708. 0xab, 0xc9, 0x0a, 0x68, 0xf4, 0x26, 0x11, 0xa4,
  33709. 0x01, 0x26, 0xd7, 0xcb, 0x21, 0xb5, 0x86, 0x95,
  33710. 0x56, 0x81, 0x86, 0xf7, 0xe5, 0x69, 0xd2, 0xff,
  33711. 0x0f, 0x9e, 0x74, 0x5d, 0x04, 0x87, 0xdd, 0x2e,
  33712. 0xb9, 0x97, 0xca, 0xfc, 0x5a, 0xbf, 0x9d, 0xd1,
  33713. 0x02, 0xe6, 0x2f, 0xf6, 0x6c, 0xba, 0x87
  33714. };
  33715. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  33716. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  33717. sizeof(msg2),
  33718. sizeof(msg3),
  33719. 0 /*sizeof(msg1)*/,
  33720. 0 /*sizeof(msg1)*/,
  33721. sizeof(msg4)
  33722. };
  33723. #ifndef NO_ASN
  33724. static const byte privateEd448[] = {
  33725. 0x30, 0x47, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
  33726. 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04, 0x39,
  33727. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33728. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33729. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33730. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33731. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33732. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33733. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33734. 0x5b
  33735. };
  33736. static const byte publicEd448[] = {
  33737. 0x30, 0x43, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
  33738. 0x71, 0x03, 0x3a, 0x00, 0x5f, 0xd7, 0x44, 0x9b,
  33739. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33740. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33741. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33742. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33743. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33744. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33745. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33746. };
  33747. static const byte privPubEd448[] = {
  33748. 0x30, 0x81, 0x82, 0x02, 0x01, 0x00, 0x30, 0x05,
  33749. 0x06, 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04,
  33750. 0x39, 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d,
  33751. 0x10, 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e,
  33752. 0xbf, 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c,
  33753. 0x9f, 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48,
  33754. 0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04,
  33755. 0x4e, 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f,
  33756. 0x8f, 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98,
  33757. 0xf9, 0x5b, 0x81, 0x39, 0x5f, 0xd7, 0x44, 0x9b,
  33758. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33759. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33760. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33761. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33762. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33763. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33764. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33765. };
  33766. word32 idx;
  33767. #endif /* NO_ASN */
  33768. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33769. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33770. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33771. ed448_key *key3 = NULL;
  33772. #else
  33773. ed448_key key3[1];
  33774. #endif
  33775. #endif
  33776. WOLFSSL_ENTER("ed448_test");
  33777. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33778. key = (ed448_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33779. key2 = (ed448_key *)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33780. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33781. key3 = (ed448_key *)XMALLOC(sizeof(*key3), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33782. #endif
  33783. #endif
  33784. /* create ed448 keys */
  33785. #ifndef HAVE_FIPS
  33786. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  33787. #else
  33788. ret = wc_InitRng(&rng);
  33789. #endif
  33790. if (ret != 0) {
  33791. XMEMSET(&rng, 0, sizeof(rng));
  33792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33793. }
  33794. ret = wc_ed448_init(key);
  33795. if (ret < 0)
  33796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33797. ret = wc_ed448_init(key2);
  33798. if (ret < 0)
  33799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33800. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33801. ret = wc_ed448_init(key3);
  33802. if (ret < 0)
  33803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33804. #endif
  33805. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key);
  33806. if (ret < 0)
  33807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33808. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2);
  33809. if (ret < 0)
  33810. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33811. /* helper functions for signature and key size */
  33812. keySz = (word32)wc_ed448_size(key);
  33813. sigSz = (word32)wc_ed448_sig_size(key);
  33814. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33815. defined(HAVE_ED448_KEY_IMPORT)
  33816. for (i = 0; i < 6; i++) {
  33817. outlen = sizeof(out);
  33818. XMEMSET(out, 0, sizeof(out));
  33819. if (wc_ed448_import_private_key(sKeys[i], ED448_KEY_SIZE, pKeys[i],
  33820. pKeySz[i], key) != 0)
  33821. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33822. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key, NULL,
  33823. 0) != 0)
  33824. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33825. if (XMEMCMP(out, sigs[i], 114))
  33826. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33827. #if defined(HAVE_ED448_VERIFY)
  33828. /* test verify on good msg */
  33829. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33830. NULL, 0) != 0 || verify != 1)
  33831. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33832. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33833. /* test verify on good msg using streaming interface directly */
  33834. if (wc_ed448_verify_msg_init(out, outlen,
  33835. key, (byte)Ed448, NULL, 0) != 0)
  33836. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33837. for (j = 0; j < msgSz[i]; j += i) {
  33838. if (wc_ed448_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  33839. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33840. }
  33841. if (wc_ed448_verify_msg_final(out, outlen, &verify,
  33842. key) != 0 || verify != 1)
  33843. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33844. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33845. /* test verify on bad msg */
  33846. out[outlen-2] = out[outlen-2] + 1;
  33847. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33848. NULL, 0) == 0 || verify == 1)
  33849. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33850. #endif /* HAVE_ED448_VERIFY */
  33851. /* test api for import/exporting keys */
  33852. {
  33853. word32 exportPSz = ED448_KEY_SIZE;
  33854. word32 exportSSz = ED448_KEY_SIZE;
  33855. #ifdef WOLFSSL_NO_MALLOC
  33856. byte exportPKey[exportPSz];
  33857. byte exportSKey[exportSSz];
  33858. #else
  33859. byte *exportPKey = NULL;
  33860. byte *exportSKey = NULL;
  33861. exportPKey = (byte *)XMALLOC(exportPSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33862. exportSKey = (byte *)XMALLOC(exportSSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33863. if ((exportPKey == NULL) || (exportSKey == NULL))
  33864. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33865. #endif
  33866. ret = 0;
  33867. do {
  33868. if (wc_ed448_export_public(key, exportPKey, &exportPSz) != 0) {
  33869. ret = WC_TEST_RET_ENC_I(i);
  33870. break;
  33871. }
  33872. if (wc_ed448_import_public_ex(exportPKey, exportPSz, key2, 1) != 0) {
  33873. ret = WC_TEST_RET_ENC_I(i);
  33874. break;
  33875. }
  33876. if (wc_ed448_export_private_only(key, exportSKey, &exportSSz) != 0) {
  33877. ret = WC_TEST_RET_ENC_I(i);
  33878. break;
  33879. }
  33880. if (wc_ed448_import_private_key(exportSKey, exportSSz,
  33881. exportPKey, exportPSz, key2) != 0) {
  33882. ret = WC_TEST_RET_ENC_I(i);
  33883. break;
  33884. }
  33885. /* clear "out" buffer and test sign with imported keys */
  33886. outlen = sizeof(out);
  33887. XMEMSET(out, 0, sizeof(out));
  33888. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key2, NULL,
  33889. 0) != 0) {
  33890. ret = WC_TEST_RET_ENC_I(i);
  33891. break;
  33892. }
  33893. } while(0);
  33894. #ifndef WOLFSSL_NO_MALLOC
  33895. XFREE(exportPKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33896. XFREE(exportSKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33897. #endif
  33898. if (ret != 0)
  33899. goto out;
  33900. }
  33901. #if defined(HAVE_ED448_VERIFY)
  33902. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key2,
  33903. NULL, 0) != 0 || verify != 1)
  33904. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33905. if (XMEMCMP(out, sigs[i], SIGSZ))
  33906. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33907. #endif /* HAVE_ED448_VERIFY */
  33908. }
  33909. ret = ed448_ctx_test();
  33910. if (ret != 0)
  33911. goto out;
  33912. ret = ed448ph_test();
  33913. if (ret != 0)
  33914. goto out;
  33915. #ifndef NO_ASN
  33916. /* Try ASN.1 encoded private-only key and public key. */
  33917. idx = 0;
  33918. ret = wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3,
  33919. sizeof(privateEd448));
  33920. if (ret != 0)
  33921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33922. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33923. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  33924. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33925. idx = 0;
  33926. ret = wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, sizeof(publicEd448));
  33927. if (ret != 0)
  33928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33929. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33930. if (ret != 0)
  33931. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33932. if (XMEMCMP(out, sigs[0], SIGSZ))
  33933. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33934. #if defined(HAVE_ED448_VERIFY)
  33935. /* test verify on good msg */
  33936. ret = wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3,
  33937. NULL, 0);
  33938. if (ret != 0 || verify != 1)
  33939. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33940. #endif /* HAVE_ED448_VERIFY */
  33941. wc_ed448_free(key3);
  33942. ret = wc_ed448_init(key3);
  33943. if (ret < 0)
  33944. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33945. idx = 0;
  33946. ret = wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3,
  33947. sizeof(privPubEd448));
  33948. if (ret != 0)
  33949. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33950. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33951. if (ret != 0)
  33952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33953. if (XMEMCMP(out, sigs[0], SIGSZ))
  33954. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33955. #endif /* NO_ASN */
  33956. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33957. ret = 0;
  33958. out:
  33959. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33960. if (key) {
  33961. wc_ed448_free(key);
  33962. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33963. }
  33964. if (key2) {
  33965. wc_ed448_free(key2);
  33966. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33967. }
  33968. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33969. if (key3) {
  33970. wc_ed448_free(key3);
  33971. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33972. }
  33973. #endif
  33974. #else
  33975. wc_ed448_free(key);
  33976. wc_ed448_free(key2);
  33977. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33978. wc_ed448_free(key3);
  33979. #endif
  33980. #endif
  33981. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  33982. wc_FreeRng(&rng);
  33983. #endif
  33984. if (ret < 0)
  33985. return ret;
  33986. /* hush warnings of unused keySz and sigSz */
  33987. (void)keySz;
  33988. (void)sigSz;
  33989. ret = ed448_test_check_key();
  33990. if (ret < 0)
  33991. return ret;
  33992. #ifdef WOLFSSL_TEST_CERT
  33993. ret = ed448_test_cert();
  33994. if (ret < 0)
  33995. return ret;
  33996. #ifdef WOLFSSL_CERT_GEN
  33997. ret = ed448_test_make_cert();
  33998. if (ret < 0)
  33999. return ret;
  34000. #endif /* WOLFSSL_CERT_GEN */
  34001. #endif /* WOLFSSL_TEST_CERT */
  34002. return 0;
  34003. }
  34004. #endif /* HAVE_ED448 */
  34005. #ifdef WOLFSSL_HAVE_KYBER
  34006. #ifdef WOLFSSL_WC_KYBER /* OQS does not support KATs */
  34007. #if !defined(WOLFSSL_NO_KYBER512) && !defined(WOLFSSL_NO_ML_KEM_512)
  34008. static wc_test_ret_t kyber512_kat(void)
  34009. {
  34010. wc_test_ret_t ret;
  34011. #ifdef WOLFSSL_SMALL_STACK
  34012. KyberKey *key = NULL;
  34013. byte *priv = NULL;
  34014. byte *pub = NULL;
  34015. byte *ct = NULL;
  34016. byte *ss = NULL;
  34017. byte *ss_dec = NULL;
  34018. #else
  34019. KyberKey key[1];
  34020. byte priv[KYBER512_PRIVATE_KEY_SIZE];
  34021. byte pub[KYBER512_PUBLIC_KEY_SIZE];
  34022. byte ct[KYBER512_CIPHER_TEXT_SIZE];
  34023. byte ss[KYBER_SS_SZ];
  34024. byte ss_dec[KYBER_SS_SZ];
  34025. #endif
  34026. int key_inited = 0;
  34027. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_rand[] = {
  34028. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  34029. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  34030. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  34031. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  34032. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34033. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34034. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34035. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34036. };
  34037. WOLFSSL_SMALL_STACK_STATIC const byte kyber512enc_rand[] = {
  34038. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  34039. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  34040. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  34041. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  34042. };
  34043. #ifdef WOLFSSL_KYBER_ORIGINAL
  34044. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_pk[] = {
  34045. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34046. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34047. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34048. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34049. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34050. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34051. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34052. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34053. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34054. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34055. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34056. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34057. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34058. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34059. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34060. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34061. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34062. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34063. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34064. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34065. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34066. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34067. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34068. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34069. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34070. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34071. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34072. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34073. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34074. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34075. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34076. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34077. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34078. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34079. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34080. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34081. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34082. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34083. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34084. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34085. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34086. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34087. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34088. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34089. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34090. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34091. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34092. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34093. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34094. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34095. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34096. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34097. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34098. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34099. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34100. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34101. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34102. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34103. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34104. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34105. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34106. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34107. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34108. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34109. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34110. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34111. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34112. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34113. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34114. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34115. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34116. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34117. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34118. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34119. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34120. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34121. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34122. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34123. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34124. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34125. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34126. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34127. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34128. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34129. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34130. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34131. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34132. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34133. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34134. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34135. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34136. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34137. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34138. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34139. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34140. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34141. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34142. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34143. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34144. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  34145. };
  34146. #endif
  34147. #ifndef WOLFSSL_NO_ML_KEM
  34148. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_pk[] = {
  34149. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34150. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34151. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34152. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34153. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34154. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34155. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34156. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34157. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34158. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34159. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34160. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34161. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34162. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34163. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34164. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34165. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34166. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34167. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34168. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34169. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34170. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34171. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34172. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34173. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34174. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34175. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34176. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34177. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34178. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34179. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34180. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34181. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34182. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34183. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34184. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34185. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34186. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34187. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34188. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34189. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34190. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34191. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34192. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34193. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34194. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34195. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34196. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34197. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34198. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34199. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34200. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34201. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34202. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34203. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34204. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34205. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34206. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34207. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34208. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34209. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34210. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34211. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34212. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34213. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34214. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34215. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34216. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34217. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34218. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34219. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34220. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34221. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34222. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34223. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34224. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34225. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34226. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34227. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34228. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34229. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34230. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34231. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34232. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34233. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34234. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34235. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34236. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34237. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34238. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34239. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34240. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34241. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34242. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34243. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34244. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34245. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34246. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34247. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34248. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39
  34249. };
  34250. #endif
  34251. #ifdef WOLFSSL_KYBER_ORIGINAL
  34252. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_sk[] = {
  34253. 0x6C, 0x89, 0x2B, 0x02, 0x97, 0xA9, 0xC7, 0x64,
  34254. 0x14, 0x93, 0xF8, 0x7D, 0xAF, 0x35, 0x33, 0xEE,
  34255. 0xD6, 0x1F, 0x07, 0xF4, 0x65, 0x20, 0x66, 0x33,
  34256. 0x7E, 0xD7, 0x40, 0x46, 0xDC, 0xC7, 0x1B, 0xA0,
  34257. 0x3F, 0x30, 0x96, 0x01, 0x03, 0x16, 0x1F, 0x7D,
  34258. 0xEB, 0x53, 0xA7, 0x1B, 0x11, 0x61, 0x72, 0x63,
  34259. 0xFE, 0x2A, 0x80, 0x97, 0x69, 0xCE, 0x6D, 0x70,
  34260. 0xA8, 0x5F, 0xE6, 0x00, 0xEC, 0xE2, 0x9D, 0x7F,
  34261. 0x36, 0xA1, 0x6D, 0x33, 0x1B, 0x8B, 0x2A, 0x9E,
  34262. 0x1D, 0xB8, 0xC0, 0x90, 0x74, 0x2D, 0xF0, 0x73,
  34263. 0x9F, 0xF0, 0x60, 0xCE, 0xB4, 0xEC, 0xC5, 0xAB,
  34264. 0x1C, 0x5E, 0x55, 0xAC, 0x97, 0xBB, 0x66, 0xA7,
  34265. 0xF8, 0x95, 0x10, 0x5D, 0x57, 0x78, 0x2B, 0x22,
  34266. 0x95, 0x38, 0xE3, 0x42, 0x15, 0x44, 0xA3, 0x42,
  34267. 0x14, 0x08, 0xDB, 0xF4, 0x49, 0x10, 0x93, 0x4C,
  34268. 0xC4, 0x23, 0x77, 0x4F, 0x16, 0x76, 0xFF, 0x1C,
  34269. 0x30, 0x6F, 0x97, 0x55, 0x5F, 0x57, 0xB4, 0xAE,
  34270. 0xD7, 0xA6, 0xBA, 0xB9, 0x50, 0xA8, 0x16, 0x3C,
  34271. 0x8D, 0x31, 0x8D, 0xEA, 0x62, 0x75, 0x1B, 0xD6,
  34272. 0xAB, 0xC5, 0x06, 0x9C, 0x06, 0xC8, 0x8F, 0x33,
  34273. 0x00, 0x26, 0xA1, 0x98, 0x06, 0xA0, 0x3B, 0x97,
  34274. 0xA7, 0x69, 0x6B, 0x56, 0xDA, 0x21, 0x82, 0x7B,
  34275. 0xB4, 0xE8, 0xDC, 0x03, 0x11, 0x52, 0xB4, 0x1B,
  34276. 0x89, 0x2A, 0x9E, 0x99, 0xAD, 0xF6, 0xE1, 0x96,
  34277. 0x3E, 0x96, 0x57, 0x88, 0x28, 0x15, 0x4F, 0x46,
  34278. 0x70, 0x33, 0x84, 0x69, 0x20, 0xFB, 0xB4, 0xB8,
  34279. 0x05, 0x44, 0xE7, 0xE8, 0xA8, 0x1A, 0xE9, 0x63,
  34280. 0xCF, 0x36, 0x8C, 0x9B, 0xA0, 0x37, 0xA8, 0xC2,
  34281. 0xAD, 0x62, 0xE3, 0x2B, 0x6E, 0x61, 0xC9, 0x1D,
  34282. 0x75, 0xCE, 0x00, 0x5A, 0xB3, 0x0F, 0x80, 0x99,
  34283. 0xA1, 0xF2, 0x9D, 0x7B, 0x63, 0x05, 0xB4, 0xDC,
  34284. 0x06, 0xE2, 0x56, 0x80, 0xBB, 0x00, 0x99, 0x2F,
  34285. 0x71, 0x7F, 0xE6, 0xC1, 0x15, 0xA8, 0x08, 0x42,
  34286. 0x31, 0xCC, 0x79, 0xDD, 0x70, 0x0E, 0xA6, 0x91,
  34287. 0x2A, 0xC7, 0xFA, 0x0D, 0x93, 0x7B, 0xB6, 0xA7,
  34288. 0x56, 0x66, 0x22, 0x30, 0x47, 0x0C, 0x18, 0x9B,
  34289. 0x5A, 0xA1, 0x65, 0x3D, 0xEB, 0x93, 0x7D, 0x5A,
  34290. 0x9C, 0x25, 0xA2, 0x1D, 0x93, 0xB1, 0x90, 0x74,
  34291. 0xFC, 0x23, 0x9D, 0x81, 0x53, 0x53, 0x97, 0x97,
  34292. 0xC7, 0xD4, 0xAB, 0x62, 0x64, 0x9D, 0x76, 0xAA,
  34293. 0x55, 0x37, 0x36, 0xA9, 0x49, 0x02, 0x2C, 0x22,
  34294. 0xC5, 0x2B, 0xAE, 0xEC, 0x60, 0x5B, 0x32, 0xCE,
  34295. 0x9E, 0x5B, 0x93, 0x84, 0x90, 0x35, 0x58, 0xCA,
  34296. 0x9D, 0x6A, 0x3A, 0xBA, 0x90, 0x42, 0x3E, 0xED,
  34297. 0xA0, 0x1C, 0x94, 0x19, 0x8B, 0x19, 0x2A, 0x8B,
  34298. 0xA9, 0x06, 0x34, 0x97, 0xA0, 0xC5, 0x01, 0x33,
  34299. 0x07, 0xDD, 0xD8, 0x63, 0x52, 0x64, 0x71, 0xA4,
  34300. 0xD9, 0x95, 0x23, 0xEB, 0x41, 0x7F, 0x29, 0x1A,
  34301. 0xAC, 0x0C, 0x3A, 0x58, 0x1B, 0x6D, 0xA0, 0x07,
  34302. 0x32, 0xE5, 0xE8, 0x1B, 0x1F, 0x7C, 0x87, 0x9B,
  34303. 0x16, 0x93, 0xC1, 0x3B, 0x6F, 0x9F, 0x79, 0x31,
  34304. 0x62, 0x24, 0x29, 0xE5, 0x42, 0xAF, 0x40, 0x69,
  34305. 0x22, 0x2F, 0x04, 0x55, 0x44, 0xE0, 0xCC, 0x4F,
  34306. 0xB2, 0x4D, 0x44, 0x48, 0xCF, 0x2C, 0x65, 0x96,
  34307. 0xF5, 0xCB, 0x08, 0x62, 0x4B, 0x11, 0x85, 0x01,
  34308. 0x3B, 0x6B, 0x02, 0x08, 0x92, 0xF9, 0x6B, 0xDF,
  34309. 0xD4, 0xAD, 0xA9, 0x17, 0x9D, 0xE7, 0x27, 0xB8,
  34310. 0xD9, 0x42, 0x6E, 0x09, 0x96, 0xB5, 0xD3, 0x49,
  34311. 0x48, 0xCE, 0x02, 0xD0, 0xC3, 0x69, 0xB3, 0x7C,
  34312. 0xBB, 0x54, 0xD3, 0x47, 0x9E, 0xD8, 0xB5, 0x82,
  34313. 0xE9, 0xE7, 0x28, 0x92, 0x9B, 0x4C, 0x71, 0xC9,
  34314. 0xBE, 0x11, 0xD4, 0x5B, 0x20, 0xC4, 0xBD, 0xC3,
  34315. 0xC7, 0x43, 0x13, 0x22, 0x3F, 0x58, 0x27, 0x4E,
  34316. 0x8B, 0xA5, 0x24, 0x44, 0x47, 0xC4, 0x95, 0x95,
  34317. 0x0B, 0x84, 0xCB, 0x0C, 0x3C, 0x27, 0x36, 0x40,
  34318. 0x10, 0x8A, 0x33, 0x97, 0x94, 0x45, 0x73, 0x27,
  34319. 0x93, 0x28, 0x99, 0x6C, 0xDC, 0x0C, 0x91, 0x3C,
  34320. 0x95, 0x8A, 0xD6, 0x20, 0xBA, 0x8B, 0x5E, 0x5E,
  34321. 0xCB, 0xBB, 0x7E, 0x13, 0xCB, 0x9C, 0x70, 0xBD,
  34322. 0x5A, 0xB3, 0x0E, 0xB7, 0x48, 0x8C, 0x97, 0x00,
  34323. 0x1C, 0x20, 0x49, 0x8F, 0x1D, 0x7C, 0xC0, 0x6D,
  34324. 0xA7, 0x6B, 0xF5, 0x20, 0xC6, 0x58, 0xCC, 0xAD,
  34325. 0xFA, 0x29, 0x56, 0x42, 0x45, 0x57, 0xAB, 0xEA,
  34326. 0x8A, 0xB8, 0x92, 0x39, 0xC1, 0x78, 0x33, 0xDC,
  34327. 0x3A, 0x49, 0xB3, 0x6A, 0x9A, 0xE9, 0xA4, 0x86,
  34328. 0x94, 0x05, 0x40, 0xEB, 0x44, 0x4F, 0x97, 0x15,
  34329. 0x23, 0x57, 0xE0, 0x20, 0x35, 0x93, 0x9D, 0x75,
  34330. 0xA3, 0xC0, 0x25, 0xF4, 0x1A, 0x40, 0x08, 0x23,
  34331. 0x82, 0xA0, 0x73, 0x3C, 0x39, 0xB0, 0x62, 0x2B,
  34332. 0x74, 0x0E, 0x40, 0x75, 0x92, 0xC6, 0x2E, 0xCA,
  34333. 0xEB, 0x14, 0x32, 0xC4, 0x45, 0xB3, 0x70, 0x3A,
  34334. 0x86, 0xF6, 0x98, 0x1A, 0x27, 0x81, 0x57, 0xEA,
  34335. 0x95, 0xA6, 0xE9, 0x2D, 0x55, 0xE4, 0xB9, 0x72,
  34336. 0xF9, 0x36, 0xC2, 0xF0, 0xA6, 0x58, 0x28, 0x0E,
  34337. 0xA2, 0xB0, 0x7A, 0x48, 0x99, 0x2D, 0xF8, 0x93,
  34338. 0x7E, 0x0A, 0x2A, 0xC1, 0xDC, 0xC9, 0x74, 0xFE,
  34339. 0x00, 0xAA, 0xE1, 0xF5, 0x61, 0xFA, 0x25, 0x8E,
  34340. 0x2D, 0x25, 0x9C, 0x3E, 0x86, 0x1D, 0xCE, 0x23,
  34341. 0x60, 0x39, 0x12, 0x76, 0x06, 0xFC, 0x1C, 0xE0,
  34342. 0x09, 0x00, 0x3A, 0x7B, 0xAC, 0x94, 0x21, 0x01,
  34343. 0xDC, 0xB8, 0x22, 0xB1, 0xF3, 0xC1, 0x2B, 0xF7,
  34344. 0x32, 0x38, 0xF5, 0x46, 0xE0, 0x1C, 0x36, 0xB5,
  34345. 0xA6, 0x93, 0x61, 0x92, 0x99, 0x5C, 0xC6, 0x9C,
  34346. 0x63, 0x23, 0x74, 0x09, 0xCB, 0x53, 0xC2, 0xE3,
  34347. 0x5D, 0x74, 0x89, 0x0D, 0x18, 0x88, 0x53, 0x76,
  34348. 0xFA, 0x55, 0x03, 0xB1, 0x07, 0xA2, 0xA3, 0x92,
  34349. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34350. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34351. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34352. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34353. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34354. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34355. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34356. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34357. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34358. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34359. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34360. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34361. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34362. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34363. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34364. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34365. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34366. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34367. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34368. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34369. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34370. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34371. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34372. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34373. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34374. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34375. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34376. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34377. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34378. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34379. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34380. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34381. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34382. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34383. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34384. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34385. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34386. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34387. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34388. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34389. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34390. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34391. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34392. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34393. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34394. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34395. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34396. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34397. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34398. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34399. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34400. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34401. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34402. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34403. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34404. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34405. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34406. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34407. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34408. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34409. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34410. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34411. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34412. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34413. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34414. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34415. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34416. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34417. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34418. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34419. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34420. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34421. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34422. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34423. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34424. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34425. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34426. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34427. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34428. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34429. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34430. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34431. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34432. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34433. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34434. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34435. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34436. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34437. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34438. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34439. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34440. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34441. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34442. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34443. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34444. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34445. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34446. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34447. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34448. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  34449. 0x7F, 0xFA, 0xD1, 0xBC, 0x8A, 0xF7, 0x3B, 0x7E,
  34450. 0x87, 0x49, 0x56, 0xB8, 0x1C, 0x2A, 0x2E, 0xF0,
  34451. 0xBF, 0xAB, 0xE8, 0xDC, 0x93, 0xD7, 0x7B, 0x2F,
  34452. 0xBC, 0x9E, 0x0C, 0x64, 0xEF, 0xA0, 0x1E, 0x84,
  34453. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34454. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34455. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34456. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34457. };
  34458. #endif
  34459. #ifndef WOLFSSL_NO_ML_KEM
  34460. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_sk[] = {
  34461. 0x9c, 0xda, 0x16, 0x86, 0xa3, 0x39, 0x6a, 0x7c,
  34462. 0x10, 0x9b, 0x41, 0x52, 0x89, 0xf5, 0x6a, 0x9e,
  34463. 0xc4, 0x4c, 0xd5, 0xb9, 0xb6, 0x74, 0xc3, 0x8a,
  34464. 0x3b, 0xba, 0xb3, 0x0a, 0x2c, 0x90, 0xf0, 0x04,
  34465. 0x37, 0xa2, 0x64, 0xb0, 0xbe, 0x9a, 0x1e, 0x8b,
  34466. 0xa8, 0x87, 0xd3, 0xc3, 0xb1, 0x00, 0x89, 0x80,
  34467. 0x54, 0x27, 0x2f, 0x94, 0x1c, 0x88, 0xa1, 0xf2,
  34468. 0x08, 0xf1, 0xc9, 0x14, 0xf9, 0x64, 0xc1, 0xaa,
  34469. 0xd6, 0x13, 0xa6, 0xa8, 0x4f, 0x88, 0xe4, 0x2d,
  34470. 0x35, 0x56, 0x83, 0x5f, 0xb1, 0x61, 0xfd, 0xc5,
  34471. 0xcd, 0x15, 0xa3, 0xbc, 0x7e, 0x74, 0xb6, 0xf2,
  34472. 0x61, 0x2f, 0xa8, 0x27, 0x1c, 0x7e, 0xa1, 0x12,
  34473. 0xb0, 0x5c, 0x2a, 0x36, 0xcc, 0x70, 0x7c, 0xe3,
  34474. 0x8d, 0x5d, 0x1a, 0xcc, 0x51, 0x15, 0x46, 0x2a,
  34475. 0x8c, 0x1a, 0xab, 0xf0, 0x72, 0x76, 0xc7, 0x23,
  34476. 0x18, 0x33, 0x7f, 0x74, 0xb5, 0xcb, 0xef, 0xea,
  34477. 0x7a, 0x80, 0x37, 0x90, 0xbc, 0x03, 0x93, 0xf3,
  34478. 0xa5, 0x4c, 0x72, 0x4a, 0x57, 0x65, 0xa4, 0x8f,
  34479. 0x29, 0x6b, 0x03, 0xf4, 0x84, 0x37, 0x60, 0x23,
  34480. 0x62, 0x69, 0x30, 0x22, 0x27, 0x04, 0xc0, 0x8f,
  34481. 0xd3, 0xbc, 0x72, 0x93, 0x15, 0xd1, 0xfc, 0x70,
  34482. 0xeb, 0x79, 0x75, 0xa9, 0x7b, 0x9d, 0xee, 0xd1,
  34483. 0x62, 0xf4, 0x86, 0xbb, 0xc6, 0x4a, 0x09, 0x71,
  34484. 0x11, 0x95, 0x2d, 0x89, 0xb5, 0x7d, 0x76, 0x5e,
  34485. 0x8a, 0x99, 0x1a, 0x2e, 0x56, 0x42, 0x06, 0xea,
  34486. 0x7b, 0xf5, 0xe4, 0x00, 0x7a, 0x66, 0x35, 0x88,
  34487. 0x31, 0xca, 0x0e, 0x34, 0xb2, 0xf6, 0xa8, 0x4d,
  34488. 0x10, 0xf7, 0x9c, 0x47, 0x7c, 0xb6, 0x6a, 0x8a,
  34489. 0x95, 0x25, 0x69, 0x36, 0x73, 0x88, 0x13, 0x0d,
  34490. 0x7b, 0x97, 0x4a, 0x63, 0xaa, 0x51, 0x99, 0x6c,
  34491. 0x97, 0x70, 0x9b, 0xb8, 0xea, 0xbc, 0x94, 0xe6,
  34492. 0xa5, 0x35, 0xd7, 0x92, 0xd2, 0x90, 0x54, 0x74,
  34493. 0x95, 0x2d, 0x6b, 0x8c, 0x22, 0x22, 0xb2, 0xae,
  34494. 0x56, 0xdc, 0x66, 0xfb, 0x04, 0x61, 0x19, 0x20,
  34495. 0x66, 0xcd, 0xdb, 0x43, 0xec, 0x05, 0x98, 0x4f,
  34496. 0xb4, 0x98, 0x26, 0x49, 0x77, 0x13, 0x97, 0xc6,
  34497. 0xa8, 0x37, 0x9f, 0x3b, 0x56, 0x43, 0x06, 0x98,
  34498. 0x48, 0x87, 0x59, 0x19, 0xe8, 0x9c, 0xc4, 0x39,
  34499. 0xa3, 0xbe, 0x2f, 0x08, 0x14, 0x90, 0xf3, 0x41,
  34500. 0xbd, 0x12, 0x40, 0xad, 0xd8, 0x0d, 0xdb, 0x8c,
  34501. 0x99, 0x63, 0xb4, 0x7a, 0x2a, 0x09, 0x92, 0x29,
  34502. 0x03, 0x38, 0xda, 0x9c, 0x3b, 0x72, 0x5c, 0x6d,
  34503. 0xa4, 0x47, 0x18, 0xc0, 0x10, 0x46, 0x81, 0x25,
  34504. 0x62, 0xaf, 0xb0, 0x84, 0x83, 0x7a, 0xcb, 0x3c,
  34505. 0x57, 0x5e, 0x4f, 0x93, 0x93, 0x6c, 0x35, 0x2a,
  34506. 0xc0, 0xe7, 0x0a, 0xa3, 0x84, 0x5e, 0xe4, 0x85,
  34507. 0x29, 0x6e, 0x6b, 0x02, 0xde, 0x0b, 0x47, 0xb5,
  34508. 0xc4, 0xc9, 0x6b, 0x0b, 0x7c, 0xf9, 0x4c, 0x4a,
  34509. 0xbe, 0x95, 0x48, 0x61, 0x53, 0x11, 0x8e, 0x43,
  34510. 0xc2, 0xb9, 0xc8, 0x4d, 0x9d, 0xa9, 0x1c, 0x6c,
  34511. 0x5a, 0xcd, 0x5a, 0x57, 0x00, 0x2d, 0x05, 0x84,
  34512. 0x97, 0x99, 0x27, 0x99, 0xe5, 0xba, 0x1c, 0xe6,
  34513. 0xc2, 0x5e, 0xb2, 0x98, 0x44, 0xd8, 0x58, 0xba,
  34514. 0x1c, 0x37, 0x85, 0x0c, 0x0c, 0x2f, 0x57, 0xc6,
  34515. 0x0d, 0xe3, 0x7f, 0x77, 0xc0, 0x82, 0xec, 0x14,
  34516. 0x49, 0x4e, 0xba, 0x28, 0x8a, 0x65, 0x91, 0x51,
  34517. 0x16, 0xc2, 0x0a, 0x32, 0x5d, 0xe3, 0x1a, 0xaa,
  34518. 0xdd, 0x68, 0x0d, 0xb1, 0x9c, 0x0c, 0xfc, 0xc3,
  34519. 0x46, 0x0f, 0x0a, 0xa0, 0x1a, 0x87, 0xa6, 0xa5,
  34520. 0x80, 0xc6, 0xca, 0x29, 0x1f, 0xae, 0xf0, 0xcc,
  34521. 0xc4, 0x9b, 0x76, 0xa8, 0xda, 0xc4, 0xf9, 0xd4,
  34522. 0x16, 0x40, 0x50, 0x9d, 0xbd, 0x0b, 0x40, 0x45,
  34523. 0xc1, 0x53, 0x0e, 0xd3, 0x47, 0x55, 0xd4, 0x74,
  34524. 0x62, 0x70, 0x0f, 0x2a, 0x8c, 0xaf, 0x96, 0x80,
  34525. 0xa6, 0xd7, 0xe3, 0x8a, 0x7e, 0x2a, 0x63, 0xe9,
  34526. 0x37, 0x65, 0x0a, 0x23, 0x30, 0x6d, 0x85, 0x5d,
  34527. 0xa2, 0xa2, 0xb7, 0xef, 0x50, 0x5c, 0xa5, 0x96,
  34528. 0xab, 0x04, 0x85, 0x01, 0x3e, 0xa9, 0x27, 0xc7,
  34529. 0x34, 0x23, 0x43, 0x61, 0x36, 0x43, 0xba, 0x40,
  34530. 0x07, 0xd6, 0xc8, 0x74, 0xb9, 0x80, 0xc7, 0x9c,
  34531. 0x3a, 0xa1, 0xc7, 0x4f, 0x85, 0x81, 0xc3, 0x48,
  34532. 0x49, 0xb3, 0x6e, 0xa7, 0x98, 0x15, 0xfb, 0xb4,
  34533. 0xcc, 0xf9, 0x61, 0x05, 0x83, 0x08, 0x1d, 0x7c,
  34534. 0x5b, 0x44, 0x09, 0xb8, 0xd0, 0x53, 0x1c, 0x04,
  34535. 0xbc, 0xaf, 0x7c, 0xc7, 0x51, 0x10, 0x3a, 0x5f,
  34536. 0xd1, 0xba, 0x44, 0x70, 0x83, 0x3e, 0x89, 0x77,
  34537. 0x5a, 0xde, 0xd9, 0x70, 0xb5, 0x47, 0x18, 0x59,
  34538. 0x25, 0x0f, 0xe7, 0x26, 0x71, 0x05, 0x83, 0x5f,
  34539. 0x39, 0x00, 0x30, 0xc5, 0xe7, 0xcd, 0x3f, 0x96,
  34540. 0x10, 0x19, 0xea, 0xae, 0xa2, 0x37, 0x77, 0xd3,
  34541. 0x47, 0xbb, 0x2a, 0xdc, 0xb6, 0x73, 0xc0, 0x20,
  34542. 0x34, 0xf3, 0x94, 0x34, 0x22, 0x71, 0xbc, 0xea,
  34543. 0x64, 0x14, 0xe5, 0x46, 0xc3, 0xb2, 0x0b, 0xd5,
  34544. 0x74, 0x81, 0xc7, 0xea, 0x14, 0xc7, 0x7c, 0x38,
  34545. 0x8c, 0xc8, 0x62, 0x51, 0xc1, 0x25, 0x58, 0xb1,
  34546. 0x00, 0xf8, 0xc5, 0xb3, 0xd0, 0x3c, 0xa2, 0xc7,
  34547. 0x07, 0x13, 0x90, 0x96, 0x59, 0xc8, 0xba, 0x26,
  34548. 0xd0, 0xd1, 0x76, 0x5e, 0x0b, 0xc8, 0x23, 0xd6,
  34549. 0x8c, 0xa5, 0x57, 0x0d, 0xe6, 0x00, 0xcd, 0x09,
  34550. 0x41, 0x72, 0x5d, 0x38, 0x6e, 0x14, 0xc1, 0x01,
  34551. 0x2d, 0xf5, 0x95, 0x1b, 0xeb, 0x8d, 0x82, 0x81,
  34552. 0xa4, 0xf6, 0x81, 0x5d, 0x37, 0x60, 0xb7, 0x64,
  34553. 0x29, 0x5a, 0xd0, 0x40, 0x6c, 0x2b, 0xf7, 0x92,
  34554. 0x8a, 0xd6, 0x50, 0x32, 0xb6, 0x5f, 0x14, 0xb7,
  34555. 0x7c, 0xcb, 0x89, 0x17, 0xc9, 0x3a, 0x29, 0xd6,
  34556. 0x28, 0x7d, 0x8a, 0x60, 0x62, 0x39, 0x9c, 0xb6,
  34557. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34558. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34559. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34560. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34561. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34562. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34563. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34564. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34565. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34566. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34567. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34568. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34569. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34570. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34571. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34572. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34573. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34574. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34575. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34576. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34577. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34578. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34579. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34580. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34581. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34582. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34583. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34584. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34585. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34586. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34587. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34588. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34589. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34590. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34591. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34592. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34593. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34594. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34595. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34596. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34597. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34598. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34599. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34600. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34601. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34602. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34603. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34604. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34605. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34606. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34607. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34608. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34609. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34610. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34611. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34612. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34613. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34614. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34615. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34616. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34617. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34618. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34619. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34620. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34621. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34622. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34623. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34624. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34625. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34626. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34627. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34628. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34629. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34630. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34631. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34632. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34633. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34634. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34635. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34636. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34637. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34638. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34639. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34640. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34641. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34642. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34643. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34644. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34645. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34646. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34647. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34648. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34649. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34650. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34651. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34652. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34653. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34654. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34655. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34656. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39,
  34657. 0x50, 0xc8, 0xdd, 0x15, 0x2a, 0x45, 0x31, 0xaa,
  34658. 0xb5, 0x60, 0xd2, 0xfc, 0x7c, 0xa9, 0xa4, 0x0a,
  34659. 0xd8, 0xaf, 0x25, 0xad, 0x1d, 0xd0, 0x8c, 0x6d,
  34660. 0x79, 0xaf, 0xe4, 0xdd, 0x4d, 0x1e, 0xee, 0x5a,
  34661. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  34662. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  34663. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  34664. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  34665. };
  34666. #endif
  34667. #ifdef WOLFSSL_KYBER_ORIGINAL
  34668. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ct[] = {
  34669. 0xED, 0xF2, 0x41, 0x45, 0xE4, 0x3B, 0x4F, 0x6D,
  34670. 0xC6, 0xBF, 0x83, 0x32, 0xF5, 0x4E, 0x02, 0xCA,
  34671. 0xB0, 0x2D, 0xBF, 0x3B, 0x56, 0x05, 0xDD, 0xC9,
  34672. 0x0A, 0x15, 0xC8, 0x86, 0xAD, 0x3E, 0xD4, 0x89,
  34673. 0x46, 0x26, 0x99, 0xE4, 0xAB, 0xED, 0x44, 0x35,
  34674. 0x0B, 0xC3, 0x75, 0x7E, 0x26, 0x96, 0xFB, 0xFB,
  34675. 0x25, 0x34, 0x41, 0x2E, 0x8D, 0xD2, 0x01, 0xF1,
  34676. 0xE4, 0x54, 0x0A, 0x39, 0x70, 0xB0, 0x55, 0xFE,
  34677. 0x3B, 0x0B, 0xEC, 0x3A, 0x71, 0xF9, 0xE1, 0x15,
  34678. 0xB3, 0xF9, 0xF3, 0x91, 0x02, 0x06, 0x5B, 0x1C,
  34679. 0xCA, 0x83, 0x14, 0xDC, 0xC7, 0x95, 0xE3, 0xC0,
  34680. 0xE8, 0xFA, 0x98, 0xEE, 0x83, 0xCA, 0x66, 0x28,
  34681. 0x45, 0x70, 0x28, 0xA4, 0xD0, 0x9E, 0x83, 0x9E,
  34682. 0x55, 0x48, 0x62, 0xCF, 0x0B, 0x7B, 0xF5, 0x6C,
  34683. 0x5C, 0x0A, 0x82, 0x9E, 0x86, 0x57, 0x94, 0x79,
  34684. 0x45, 0xFE, 0x9C, 0x22, 0x56, 0x4F, 0xBA, 0xEB,
  34685. 0xC1, 0xB3, 0xAF, 0x35, 0x0D, 0x79, 0x55, 0x50,
  34686. 0x8A, 0x26, 0xD8, 0xA8, 0xEB, 0x54, 0x7B, 0x8B,
  34687. 0x1A, 0x2C, 0xF0, 0x3C, 0xCA, 0x1A, 0xAB, 0xCE,
  34688. 0x6C, 0x34, 0x97, 0x78, 0x3B, 0x64, 0x65, 0xBA,
  34689. 0x0B, 0x6E, 0x7A, 0xCB, 0xA8, 0x21, 0x19, 0x51,
  34690. 0x24, 0xAE, 0xF0, 0x9E, 0x62, 0x83, 0x82, 0xA1,
  34691. 0xF9, 0x14, 0x04, 0x3B, 0xE7, 0x09, 0x6E, 0x95,
  34692. 0x2C, 0xBC, 0x4F, 0xB4, 0xAF, 0xED, 0x13, 0x60,
  34693. 0x90, 0x46, 0x11, 0x7C, 0x01, 0x1F, 0xD7, 0x41,
  34694. 0xEE, 0x28, 0x6C, 0x83, 0x77, 0x16, 0x90, 0xF0,
  34695. 0xAE, 0xB5, 0x0D, 0xA0, 0xD7, 0x12, 0x85, 0xA1,
  34696. 0x79, 0xB2, 0x15, 0xC6, 0x03, 0x6D, 0xEB, 0x78,
  34697. 0x0F, 0x4D, 0x16, 0x76, 0x9F, 0x72, 0xDE, 0x16,
  34698. 0xFD, 0xAD, 0xAC, 0x73, 0xBE, 0xFA, 0x5B, 0xEF,
  34699. 0x89, 0x43, 0x19, 0x7F, 0x44, 0xC5, 0x95, 0x89,
  34700. 0xDC, 0x9F, 0x49, 0x73, 0xDE, 0x14, 0x50, 0xBA,
  34701. 0x1D, 0x0C, 0x32, 0x90, 0xD6, 0xB1, 0xD6, 0x83,
  34702. 0xF2, 0x94, 0xE7, 0x59, 0xC9, 0x54, 0xAB, 0xE8,
  34703. 0xA7, 0xDA, 0x5B, 0x10, 0x54, 0xFD, 0x6D, 0x21,
  34704. 0x32, 0x9B, 0x8E, 0x73, 0xD3, 0x75, 0x6A, 0xFD,
  34705. 0xA0, 0xDC, 0xB1, 0xFC, 0x8B, 0x15, 0x82, 0xD1,
  34706. 0xF9, 0x0C, 0xF2, 0x75, 0xA1, 0x02, 0xAB, 0xC6,
  34707. 0xAC, 0x69, 0x9D, 0xF0, 0xC5, 0x87, 0x0E, 0x50,
  34708. 0xA1, 0xF9, 0x89, 0xE4, 0xE6, 0x24, 0x1B, 0x60,
  34709. 0xAA, 0xA2, 0xEC, 0xF9, 0xE8, 0xE3, 0x3E, 0x0F,
  34710. 0xFC, 0xF4, 0x0F, 0xE8, 0x31, 0xE8, 0xFD, 0xC2,
  34711. 0xE8, 0x3B, 0x52, 0xCA, 0x7A, 0xB6, 0xD9, 0x3F,
  34712. 0x14, 0x6D, 0x29, 0xDC, 0xA5, 0x3C, 0x7D, 0xA1,
  34713. 0xDB, 0x4A, 0xC4, 0xF2, 0xDB, 0x39, 0xEA, 0x12,
  34714. 0x0D, 0x90, 0xFA, 0x60, 0xF4, 0xD4, 0x37, 0xC6,
  34715. 0xD0, 0x0E, 0xF4, 0x83, 0xBC, 0x94, 0xA3, 0x17,
  34716. 0x5C, 0xDA, 0x16, 0x3F, 0xC1, 0xC2, 0x82, 0x8B,
  34717. 0xE4, 0xDB, 0xD6, 0x43, 0x05, 0x07, 0xB5, 0x84,
  34718. 0xBB, 0x51, 0x77, 0xE1, 0x71, 0xB8, 0xDD, 0xA9,
  34719. 0xA4, 0x29, 0x3C, 0x32, 0x00, 0x29, 0x5C, 0x80,
  34720. 0x3A, 0x86, 0x5D, 0x6D, 0x21, 0x66, 0xF6, 0x6B,
  34721. 0xA5, 0x40, 0x1F, 0xB7, 0xA0, 0xE8, 0x53, 0x16,
  34722. 0x86, 0x00, 0xA2, 0x94, 0x84, 0x37, 0xE0, 0x36,
  34723. 0xE3, 0xBF, 0x19, 0xE1, 0x2F, 0xD3, 0xF2, 0xA2,
  34724. 0xB8, 0xB3, 0x43, 0xF7, 0x84, 0x24, 0x8E, 0x8D,
  34725. 0x68, 0x5E, 0xB0, 0xAF, 0xDE, 0x63, 0x15, 0x33,
  34726. 0x87, 0x30, 0xE7, 0xA1, 0x00, 0x1C, 0x27, 0xD8,
  34727. 0xD2, 0xA7, 0x6F, 0xA6, 0x9D, 0x15, 0x7B, 0xA1,
  34728. 0xAC, 0x7A, 0xD5, 0x6D, 0xA5, 0xA8, 0xC7, 0x0F,
  34729. 0xE4, 0xB5, 0xB8, 0xD7, 0x86, 0xDC, 0x6F, 0xC0,
  34730. 0x56, 0x6B, 0xA8, 0xE1, 0xB8, 0x81, 0x63, 0x34,
  34731. 0xD3, 0x2A, 0x3F, 0xB1, 0xCE, 0x7D, 0x4D, 0x5E,
  34732. 0x4C, 0x33, 0x2A, 0xF7, 0xB0, 0x03, 0xD0, 0x91,
  34733. 0x74, 0x1A, 0x3D, 0x5C, 0x96, 0x52, 0x92, 0x25,
  34734. 0x5D, 0xFF, 0x8E, 0xD2, 0xBB, 0xF1, 0xF9, 0x11,
  34735. 0x6B, 0xE5, 0x0C, 0x17, 0xB8, 0xE5, 0x48, 0x74,
  34736. 0x8A, 0xD4, 0xB2, 0xE9, 0x57, 0xBB, 0xD1, 0x95,
  34737. 0x34, 0x82, 0xA2, 0xE1, 0x71, 0x8C, 0xEC, 0x66,
  34738. 0xCD, 0x2C, 0x81, 0xF5, 0x72, 0xD5, 0x52, 0xB7,
  34739. 0x18, 0x78, 0x85, 0xE6, 0xB8, 0x94, 0x3D, 0x64,
  34740. 0x31, 0x41, 0x3C, 0x59, 0xEB, 0xB7, 0xE0, 0x36,
  34741. 0x04, 0x84, 0x90, 0xBE, 0x52, 0x89, 0xE9, 0x5B,
  34742. 0x20, 0xA8, 0x9E, 0x8B, 0x15, 0x9F, 0x61, 0xA9,
  34743. 0xA9, 0x88, 0x6E, 0x14, 0x75, 0x68, 0xF4, 0xC9,
  34744. 0x02, 0x1F, 0x36, 0x2F, 0x02, 0x68, 0x8A, 0x1C,
  34745. 0x8C, 0x3B, 0xB0, 0xD2, 0x40, 0x86, 0x88, 0x0E,
  34746. 0x55, 0xB6, 0xED, 0xB4, 0x3F, 0x37, 0x45, 0xD2,
  34747. 0xC1, 0x66, 0xDC, 0x1C, 0xB7, 0x43, 0xC7, 0x6F,
  34748. 0xE6, 0xBE, 0x52, 0x3A, 0x89, 0x3C, 0xC7, 0x64,
  34749. 0xD1, 0x64, 0x35, 0xC3, 0x78, 0x51, 0x25, 0x2A,
  34750. 0x81, 0xE2, 0xFF, 0xBA, 0x0F, 0x18, 0x97, 0x1A,
  34751. 0x3D, 0xEE, 0x37, 0xD4, 0x87, 0x7C, 0xB9, 0x28,
  34752. 0xE3, 0x6E, 0x52, 0x35, 0x03, 0x7A, 0x6B, 0x20,
  34753. 0x57, 0x89, 0x7D, 0x51, 0x8A, 0x5F, 0x0E, 0x34,
  34754. 0x8E, 0x3A, 0xB6, 0xD5, 0xB5, 0x2D, 0xFC, 0x60,
  34755. 0x75, 0x7F, 0x3B, 0x41, 0xA4, 0xFE, 0xC7, 0x82,
  34756. 0x8F, 0x1D, 0xEE, 0xAF, 0x45, 0x87, 0xCC, 0xC8,
  34757. 0xEA, 0xDF, 0x64, 0x7F, 0x4D, 0x20, 0x3B, 0x2F,
  34758. 0xAA, 0x05, 0xA6, 0x49, 0xB5, 0x82, 0x34, 0x0C,
  34759. 0xB4, 0xCA, 0xCE, 0x57, 0xA3, 0x07, 0x11, 0xBE,
  34760. 0x75, 0x2F, 0xAC, 0xF0, 0x22, 0x7D, 0x0A, 0x80,
  34761. 0xC4, 0x12, 0x84, 0x42, 0xDD, 0xC5, 0x44, 0xBE,
  34762. 0x80, 0x5B, 0x9C, 0xFE, 0x8F, 0xE9, 0xB1, 0x23,
  34763. 0x7C, 0x80, 0xF9, 0x67, 0x87, 0xCD, 0x92, 0x81,
  34764. 0xCC, 0xF2, 0x70, 0xC1, 0xAF, 0xC0, 0x67, 0x0D
  34765. };
  34766. #endif
  34767. #ifndef WOLFSSL_NO_ML_KEM
  34768. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_ct[] = {
  34769. 0x11, 0x3d, 0xb2, 0xdd, 0x06, 0x87, 0x12, 0x35,
  34770. 0xe7, 0xbc, 0x36, 0xc9, 0xdc, 0xaa, 0x52, 0x8f,
  34771. 0xc2, 0x6c, 0xe5, 0xdb, 0x9e, 0xcc, 0x1d, 0xc3,
  34772. 0x2e, 0x95, 0x7d, 0x7f, 0xfb, 0x3c, 0x74, 0x29,
  34773. 0xd5, 0x0c, 0x3c, 0x35, 0x77, 0xa5, 0x15, 0xd3,
  34774. 0x18, 0x3a, 0x1b, 0x9d, 0x26, 0x7b, 0x93, 0x6b,
  34775. 0x7e, 0xb8, 0xf5, 0x43, 0xa3, 0xaf, 0xb7, 0x77,
  34776. 0x65, 0xca, 0x79, 0x38, 0xf7, 0x8a, 0xa6, 0x43,
  34777. 0x8c, 0xe8, 0x0a, 0x06, 0xa6, 0x96, 0x6d, 0x0d,
  34778. 0x06, 0xaf, 0x75, 0xba, 0x3e, 0x0d, 0x4f, 0x37,
  34779. 0xba, 0xc7, 0x33, 0x69, 0xf5, 0xa7, 0x29, 0xf7,
  34780. 0x3e, 0x85, 0x72, 0x9e, 0xdd, 0x97, 0xc8, 0xc2,
  34781. 0xa8, 0xcc, 0x26, 0x19, 0xe4, 0xcf, 0x7b, 0x60,
  34782. 0x91, 0x86, 0x9e, 0x90, 0x9f, 0xd4, 0x7d, 0x97,
  34783. 0x09, 0x14, 0x92, 0x04, 0xb0, 0x83, 0x7d, 0x8d,
  34784. 0x6f, 0x25, 0xd2, 0x67, 0x97, 0x2b, 0xe6, 0x3b,
  34785. 0xad, 0x34, 0xb5, 0x44, 0x52, 0x3c, 0x01, 0xc0,
  34786. 0x9d, 0xe3, 0xb1, 0xfa, 0x1d, 0x6b, 0x7b, 0x05,
  34787. 0x9e, 0xee, 0x9e, 0x65, 0x20, 0x62, 0xfe, 0x87,
  34788. 0x0f, 0x68, 0xc6, 0x80, 0x05, 0x33, 0x9e, 0xa1,
  34789. 0x81, 0xe1, 0xd0, 0x76, 0x7c, 0x15, 0x2a, 0xeb,
  34790. 0x38, 0xfa, 0xf0, 0xf9, 0x24, 0x5a, 0xe5, 0x9d,
  34791. 0x5c, 0xb0, 0xd2, 0xb7, 0xf2, 0x01, 0x22, 0x9e,
  34792. 0xd9, 0x70, 0x20, 0xd0, 0x62, 0x3a, 0x46, 0x10,
  34793. 0x0d, 0x09, 0x7b, 0x0c, 0xe1, 0x15, 0x4e, 0x02,
  34794. 0x8a, 0xe6, 0x19, 0x4d, 0xe0, 0x5d, 0xe9, 0x7d,
  34795. 0xd9, 0xae, 0x2e, 0x85, 0xff, 0xd2, 0x5d, 0x95,
  34796. 0xeb, 0x22, 0xef, 0xfe, 0x5b, 0xa1, 0x9c, 0xd8,
  34797. 0x07, 0xc5, 0x30, 0xeb, 0xaa, 0x9f, 0xe9, 0xf6,
  34798. 0x42, 0xcc, 0xac, 0xff, 0x47, 0xed, 0x15, 0xc2,
  34799. 0x2b, 0xfe, 0x30, 0x36, 0xeb, 0xf8, 0xad, 0x9c,
  34800. 0x8e, 0xd2, 0x32, 0x40, 0xae, 0xeb, 0xaa, 0x24,
  34801. 0xd1, 0x35, 0x75, 0x51, 0x00, 0xb8, 0x5e, 0xce,
  34802. 0xe3, 0x17, 0x49, 0x06, 0xe4, 0x63, 0x12, 0x06,
  34803. 0x2c, 0xee, 0xca, 0xc7, 0x5d, 0xe5, 0x27, 0x52,
  34804. 0x56, 0xc2, 0xc1, 0xa6, 0x53, 0xfd, 0x69, 0x15,
  34805. 0xb1, 0xb3, 0x0c, 0x8e, 0xcb, 0xb6, 0xfd, 0x42,
  34806. 0x80, 0x43, 0x74, 0x53, 0x17, 0x3a, 0x96, 0x23,
  34807. 0x8b, 0xc7, 0xd1, 0x08, 0x89, 0x23, 0x43, 0xe0,
  34808. 0x33, 0xbc, 0xd9, 0x8e, 0x43, 0x7e, 0x78, 0x9f,
  34809. 0xc5, 0xbe, 0xba, 0xa1, 0x2b, 0x26, 0x34, 0xb5,
  34810. 0x1e, 0xd0, 0xd5, 0x89, 0xf1, 0x11, 0x43, 0xa0,
  34811. 0x21, 0xd8, 0xec, 0xce, 0x59, 0x4f, 0xdd, 0x48,
  34812. 0xda, 0xe8, 0x4c, 0x80, 0x63, 0xef, 0x35, 0x81,
  34813. 0xbc, 0x37, 0x8a, 0x48, 0xda, 0x4e, 0x51, 0xbb,
  34814. 0x17, 0x5b, 0x0d, 0xb4, 0x7f, 0x9d, 0xcf, 0x99,
  34815. 0x31, 0x8c, 0x30, 0x22, 0x5c, 0xa7, 0xfa, 0x79,
  34816. 0xc8, 0x79, 0xbf, 0x1c, 0x93, 0x97, 0xb5, 0xcc,
  34817. 0xc5, 0xef, 0xad, 0x94, 0xc5, 0x00, 0xed, 0x7f,
  34818. 0x9f, 0x38, 0x5d, 0x08, 0x8e, 0x34, 0x93, 0x22,
  34819. 0x21, 0xfc, 0x0f, 0xc9, 0xaf, 0xe5, 0x1f, 0x68,
  34820. 0x75, 0x54, 0x81, 0x31, 0x69, 0x76, 0x95, 0x47,
  34821. 0x8a, 0xbd, 0xc8, 0x73, 0x6f, 0x10, 0x09, 0x5a,
  34822. 0x6b, 0x92, 0xec, 0x67, 0x9f, 0xe0, 0xe2, 0xae,
  34823. 0x5d, 0x8b, 0x33, 0x53, 0x55, 0xd5, 0x8d, 0xae,
  34824. 0x4d, 0x4f, 0x0b, 0x17, 0xaa, 0x5d, 0x1e, 0x52,
  34825. 0xf1, 0xd4, 0x55, 0x84, 0xa8, 0x92, 0xc3, 0x4c,
  34826. 0xe4, 0xb0, 0x4f, 0xcd, 0x00, 0x98, 0x1d, 0x51,
  34827. 0xca, 0xa1, 0x60, 0x64, 0xba, 0xd9, 0x2d, 0x01,
  34828. 0x9d, 0xc3, 0xad, 0xed, 0x91, 0x96, 0x84, 0x11,
  34829. 0x2b, 0x29, 0xda, 0xa2, 0x8b, 0x9d, 0xae, 0x09,
  34830. 0xb8, 0x6b, 0x21, 0xa9, 0x33, 0x10, 0xd5, 0xfb,
  34831. 0xc6, 0x52, 0x7b, 0x22, 0x4b, 0x9c, 0xe8, 0x7d,
  34832. 0x27, 0x82, 0xbb, 0x29, 0x46, 0x73, 0xf0, 0xec,
  34833. 0x06, 0xf2, 0x6b, 0x08, 0x76, 0x52, 0xa1, 0x8d,
  34834. 0x6a, 0xd7, 0xb1, 0xc9, 0x33, 0x03, 0xef, 0x05,
  34835. 0x61, 0xc0, 0xfc, 0x9c, 0xd4, 0xf6, 0x78, 0xf6,
  34836. 0x06, 0xf1, 0x92, 0xcf, 0x5d, 0xf9, 0x2b, 0x15,
  34837. 0x48, 0xf5, 0xdd, 0x26, 0x87, 0xed, 0xbe, 0xcc,
  34838. 0xfc, 0x6d, 0x4e, 0x9d, 0xe4, 0xbd, 0x50, 0xd3,
  34839. 0xc7, 0x4f, 0xb2, 0x75, 0xab, 0xd9, 0xb3, 0xe9,
  34840. 0x02, 0x77, 0xdb, 0x4a, 0x00, 0x69, 0xc0, 0xa2,
  34841. 0xa7, 0x13, 0x6f, 0x50, 0xce, 0xad, 0x4b, 0x2f,
  34842. 0x19, 0x95, 0xfa, 0xaf, 0x16, 0x80, 0x40, 0xe9,
  34843. 0xe4, 0xbe, 0xb7, 0xc5, 0x72, 0x20, 0x49, 0xd6,
  34844. 0xda, 0x64, 0x02, 0x99, 0x2f, 0xce, 0xa4, 0x50,
  34845. 0x97, 0xdf, 0x7c, 0x1c, 0x20, 0xfb, 0x06, 0x82,
  34846. 0x22, 0x00, 0x05, 0x76, 0x93, 0x5a, 0x08, 0x06,
  34847. 0x77, 0x34, 0x51, 0x92, 0x1f, 0x54, 0xc5, 0x5f,
  34848. 0xbf, 0x59, 0x3a, 0x4f, 0x14, 0x7c, 0x1f, 0xef,
  34849. 0x3a, 0xca, 0xf0, 0xcf, 0xa9, 0x07, 0xae, 0x48,
  34850. 0xc8, 0xc0, 0x63, 0x12, 0xcf, 0xdf, 0x51, 0x86,
  34851. 0x90, 0x4b, 0xec, 0x7f, 0xed, 0x4e, 0xd9, 0x33,
  34852. 0xc9, 0x25, 0x6a, 0xb0, 0x4c, 0xbf, 0xa0, 0x3a,
  34853. 0x96, 0x7c, 0x1f, 0x7e, 0xad, 0x4a, 0xb4, 0x0d,
  34854. 0xf1, 0x16, 0xbe, 0x66, 0x0e, 0x27, 0xca, 0x2b,
  34855. 0x54, 0x35, 0x26, 0xd4, 0xb9, 0x68, 0x4c, 0x31,
  34856. 0xe1, 0xe4, 0x23, 0x83, 0xb9, 0x69, 0xf8, 0x96,
  34857. 0x29, 0x9d, 0x71, 0x39, 0x0c, 0xc8, 0x5b, 0x70,
  34858. 0x32, 0x02, 0xac, 0xad, 0xec, 0xfa, 0x8c, 0x40,
  34859. 0x96, 0x5c, 0x08, 0xc5, 0x3b, 0x56, 0x71, 0xe0,
  34860. 0xd5, 0x94, 0x55, 0xbc, 0x5a, 0x85, 0x86, 0xc6,
  34861. 0x55, 0xdb, 0x8c, 0x2a, 0xde, 0x4b, 0xa8, 0x87,
  34862. 0x7f, 0x19, 0xb6, 0x00, 0x0e, 0x18, 0xf8, 0xfe,
  34863. 0xad, 0xda, 0x7e, 0xde, 0x8f, 0xe8, 0x0a, 0xa6,
  34864. 0x62, 0xd6, 0x94, 0xc6, 0xd8, 0xc3, 0x3b, 0x52
  34865. };
  34866. #endif
  34867. #ifdef WOLFSSL_KYBER_ORIGINAL
  34868. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ss[] = {
  34869. 0x0A, 0x69, 0x25, 0x67, 0x6F, 0x24, 0xB2, 0x2C,
  34870. 0x28, 0x6F, 0x4C, 0x81, 0xA4, 0x22, 0x4C, 0xEC,
  34871. 0x50, 0x6C, 0x9B, 0x25, 0x7D, 0x48, 0x0E, 0x02,
  34872. 0xE3, 0xB4, 0x9F, 0x44, 0xCA, 0xA3, 0x23, 0x7F
  34873. };
  34874. #endif
  34875. #ifndef WOLFSSL_NO_ML_KEM
  34876. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_ss[] = {
  34877. 0x31, 0x98, 0x39, 0xe8, 0x2a, 0xb6, 0xb2, 0x22,
  34878. 0xde, 0x7b, 0x61, 0x9e, 0x80, 0xda, 0x83, 0x91,
  34879. 0x52, 0x2b, 0xbb, 0x37, 0x67, 0x70, 0x18, 0x49,
  34880. 0x4a, 0x47, 0x42, 0xc5, 0x3f, 0x9a, 0xbf, 0xdf
  34881. };
  34882. #endif
  34883. #ifdef WOLFSSL_SMALL_STACK
  34884. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  34885. DYNAMIC_TYPE_TMP_BUFFER);
  34886. priv = (byte *)XMALLOC(KYBER512_PRIVATE_KEY_SIZE, HEAP_HINT,
  34887. DYNAMIC_TYPE_TMP_BUFFER);
  34888. pub = (byte *)XMALLOC(KYBER512_PUBLIC_KEY_SIZE, HEAP_HINT,
  34889. DYNAMIC_TYPE_TMP_BUFFER);
  34890. ct = (byte *)XMALLOC(KYBER512_CIPHER_TEXT_SIZE, HEAP_HINT,
  34891. DYNAMIC_TYPE_TMP_BUFFER);
  34892. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34893. DYNAMIC_TYPE_TMP_BUFFER);
  34894. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34895. DYNAMIC_TYPE_TMP_BUFFER);
  34896. if (! (key && priv && pub && ct && ss && ss_dec))
  34897. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  34898. #endif
  34899. #ifdef WOLFSSL_KYBER_ORIGINAL
  34900. ret = wc_KyberKey_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
  34901. if (ret != 0)
  34902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34903. else
  34904. key_inited = 1;
  34905. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34906. sizeof(kyber512_rand));
  34907. if (ret != 0)
  34908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34909. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
  34910. if (ret != 0)
  34911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34912. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
  34913. if (ret != 0)
  34914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34915. if (XMEMCMP(pub, kyber512_pk, sizeof(kyber512_pk)) != 0)
  34916. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34917. if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0)
  34918. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34919. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34920. sizeof(kyber512enc_rand));
  34921. if (ret != 0)
  34922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34923. if (XMEMCMP(ct, kyber512_ct, sizeof(kyber512_ct)) != 0)
  34924. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34925. if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34926. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34927. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
  34928. if (ret != 0)
  34929. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34930. if (XMEMCMP(ss_dec, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34931. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34932. #endif
  34933. #ifndef WOLFSSL_NO_ML_KEM
  34934. ret = wc_KyberKey_Init(WC_ML_KEM_512, key, HEAP_HINT, INVALID_DEVID);
  34935. if (ret != 0)
  34936. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34937. else
  34938. key_inited = 1;
  34939. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34940. sizeof(kyber512_rand));
  34941. if (ret != 0)
  34942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34943. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_512_PUBLIC_KEY_SIZE);
  34944. if (ret != 0)
  34945. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34946. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  34947. WC_ML_KEM_512_PRIVATE_KEY_SIZE);
  34948. if (ret != 0)
  34949. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34950. if (XMEMCMP(pub, ml_kem_512_pk, sizeof(ml_kem_512_pk)) != 0)
  34951. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34952. if (XMEMCMP(priv, ml_kem_512_sk, sizeof(ml_kem_512_sk)) != 0)
  34953. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34954. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34955. sizeof(kyber512enc_rand));
  34956. if (ret != 0)
  34957. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34958. if (XMEMCMP(ct, ml_kem_512_ct, sizeof(ml_kem_512_ct)) != 0)
  34959. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34960. if (XMEMCMP(ss, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
  34961. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34962. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_512_ct));
  34963. if (ret != 0)
  34964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34965. if (XMEMCMP(ss_dec, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
  34966. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34967. #endif
  34968. out:
  34969. if (key_inited)
  34970. wc_KyberKey_Free(key);
  34971. #ifdef WOLFSSL_SMALL_STACK
  34972. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34973. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34974. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34975. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34976. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34977. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34978. #endif
  34979. return ret;
  34980. }
  34981. #endif /* WOLFSSL_KYBER512 */
  34982. #if !defined(WOLFSSL_NO_KYBER768) && !defined(WOLFSSL_NO_ML_KEM_768)
  34983. static wc_test_ret_t kyber768_kat(void)
  34984. {
  34985. wc_test_ret_t ret;
  34986. #ifdef WOLFSSL_SMALL_STACK
  34987. KyberKey *key = NULL;
  34988. byte *priv = NULL;
  34989. byte *pub = NULL;
  34990. byte *ct = NULL;
  34991. byte *ss = NULL;
  34992. byte *ss_dec = NULL;
  34993. #else
  34994. KyberKey key[1];
  34995. byte priv[KYBER768_PRIVATE_KEY_SIZE];
  34996. byte pub[KYBER768_PUBLIC_KEY_SIZE];
  34997. byte ct[KYBER768_CIPHER_TEXT_SIZE];
  34998. byte ss[KYBER_SS_SZ];
  34999. byte ss_dec[KYBER_SS_SZ];
  35000. #endif
  35001. int key_inited = 0;
  35002. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_rand[] = {
  35003. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  35004. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  35005. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  35006. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  35007. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35008. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35009. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35010. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35011. };
  35012. WOLFSSL_SMALL_STACK_STATIC const byte kyber768enc_rand[] = {
  35013. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  35014. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  35015. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  35016. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  35017. };
  35018. #ifdef WOLFSSL_KYBER_ORIGINAL
  35019. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_pk[] = {
  35020. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35021. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35022. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35023. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35024. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35025. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35026. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35027. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35028. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35029. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35030. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35031. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35032. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35033. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35034. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35035. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35036. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35037. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35038. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35039. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35040. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35041. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35042. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35043. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35044. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35045. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35046. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35047. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35048. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35049. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35050. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35051. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35052. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35053. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35054. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35055. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35056. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35057. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35058. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35059. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35060. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35061. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35062. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35063. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35064. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35065. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35066. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35067. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35068. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35069. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35070. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35071. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35072. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35073. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35074. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35075. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35076. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35077. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35078. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35079. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35080. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35081. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35082. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35083. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35084. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35085. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35086. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35087. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35088. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35089. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35090. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35091. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35092. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35093. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35094. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35095. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35096. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35097. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35098. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35099. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35100. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35101. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35102. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35103. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35104. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35105. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35106. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35107. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35108. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35109. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35110. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35111. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35112. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35113. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35114. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35115. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35116. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35117. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35118. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35119. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35120. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35121. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35122. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35123. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35124. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35125. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35126. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35127. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35128. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35129. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35130. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35131. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35132. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35133. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35134. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35135. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35136. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35137. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35138. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35139. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35140. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35141. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35142. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35143. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35144. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35145. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35146. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35147. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35148. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35149. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35150. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35151. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35152. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35153. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35154. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35155. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35156. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35157. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35158. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35159. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35160. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35161. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35162. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35163. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35164. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35165. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35166. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35167. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  35168. };
  35169. #endif
  35170. #ifndef WOLFSSL_NO_ML_KEM
  35171. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_pk[] = {
  35172. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35173. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35174. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35175. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35176. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35177. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35178. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35179. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35180. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35181. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35182. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35183. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35184. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35185. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35186. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35187. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35188. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35189. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35190. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35191. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35192. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35193. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35194. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35195. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35196. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35197. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35198. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35199. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35200. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35201. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35202. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35203. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35204. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35205. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35206. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35207. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35208. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35209. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35210. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35211. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35212. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35213. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35214. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35215. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35216. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35217. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35218. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35219. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35220. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35221. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35222. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35223. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35224. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35225. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35226. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35227. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35228. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35229. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35230. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35231. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35232. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35233. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35234. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35235. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35236. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35237. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35238. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35239. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35240. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35241. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35242. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35243. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35244. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35245. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35246. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35247. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35248. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35249. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35250. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35251. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35252. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35253. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35254. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35255. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35256. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35257. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35258. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35259. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35260. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35261. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35262. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35263. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35264. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35265. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35266. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35267. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35268. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35269. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35270. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35271. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35272. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35273. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35274. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35275. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35276. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35277. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35278. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35279. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35280. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35281. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35282. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35283. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35284. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35285. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35286. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35287. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35288. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35289. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35290. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35291. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35292. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35293. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35294. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35295. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35296. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35297. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35298. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35299. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35300. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35301. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35302. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35303. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35304. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35305. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35306. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35307. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35308. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35309. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35310. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35311. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35312. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35313. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35314. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35315. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35316. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35317. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35318. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35319. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28
  35320. };
  35321. #endif
  35322. #ifdef WOLFSSL_KYBER_ORIGINAL
  35323. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_sk[] = {
  35324. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  35325. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  35326. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  35327. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  35328. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  35329. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  35330. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  35331. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  35332. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  35333. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  35334. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  35335. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  35336. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  35337. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  35338. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  35339. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  35340. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  35341. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  35342. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  35343. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  35344. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  35345. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  35346. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  35347. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  35348. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  35349. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  35350. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  35351. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  35352. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  35353. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  35354. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  35355. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  35356. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  35357. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  35358. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  35359. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  35360. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  35361. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  35362. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  35363. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  35364. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  35365. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  35366. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  35367. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  35368. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  35369. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  35370. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  35371. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  35372. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  35373. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  35374. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  35375. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  35376. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  35377. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  35378. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  35379. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  35380. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  35381. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  35382. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  35383. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  35384. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  35385. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  35386. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  35387. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  35388. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  35389. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  35390. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  35391. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  35392. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  35393. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  35394. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  35395. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  35396. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  35397. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  35398. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  35399. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  35400. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  35401. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  35402. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  35403. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  35404. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  35405. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  35406. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  35407. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  35408. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  35409. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  35410. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  35411. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  35412. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  35413. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  35414. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  35415. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  35416. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  35417. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  35418. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  35419. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  35420. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  35421. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  35422. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  35423. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  35424. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  35425. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  35426. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  35427. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  35428. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  35429. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  35430. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  35431. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  35432. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  35433. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  35434. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  35435. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  35436. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  35437. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  35438. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  35439. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  35440. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  35441. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  35442. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  35443. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  35444. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  35445. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  35446. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  35447. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  35448. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  35449. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  35450. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  35451. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  35452. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  35453. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  35454. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  35455. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  35456. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  35457. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  35458. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  35459. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  35460. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  35461. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  35462. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  35463. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  35464. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  35465. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  35466. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  35467. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  35468. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35469. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35470. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35471. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35472. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35473. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35474. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35475. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35476. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35477. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35478. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35479. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35480. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35481. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35482. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35483. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35484. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35485. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35486. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35487. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35488. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35489. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35490. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35491. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35492. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35493. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35494. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35495. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35496. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35497. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35498. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35499. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35500. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35501. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35502. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35503. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35504. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35505. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35506. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35507. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35508. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35509. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35510. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35511. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35512. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35513. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35514. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35515. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35516. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35517. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35518. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35519. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35520. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35521. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35522. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35523. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35524. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35525. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35526. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35527. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35528. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35529. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35530. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35531. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35532. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35533. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35534. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35535. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35536. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35537. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35538. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35539. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35540. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35541. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35542. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35543. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35544. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35545. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35546. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35547. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35548. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35549. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35550. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35551. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35552. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35553. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35554. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35555. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35556. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35557. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35558. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35559. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35560. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35561. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35562. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35563. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35564. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35565. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35566. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35567. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35568. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35569. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35570. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35571. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35572. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35573. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35574. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35575. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35576. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35577. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35578. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35579. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35580. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35581. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35582. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35583. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35584. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35585. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35586. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35587. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35588. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35589. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35590. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35591. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35592. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35593. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35594. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35595. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35596. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35597. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35598. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35599. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35600. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35601. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35602. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35603. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35604. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35605. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35606. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35607. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35608. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35609. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35610. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35611. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35612. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35613. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35614. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35615. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  35616. 0xD4, 0xEC, 0x14, 0x3B, 0x50, 0xF0, 0x14, 0x23,
  35617. 0xB1, 0x77, 0x89, 0x5E, 0xDE, 0xE2, 0x2B, 0xB7,
  35618. 0x39, 0xF6, 0x47, 0xEC, 0xF8, 0x5F, 0x50, 0xBC,
  35619. 0x25, 0xEF, 0x7B, 0x5A, 0x72, 0x5D, 0xEE, 0x86,
  35620. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35621. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35622. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35623. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35624. };
  35625. #endif
  35626. #ifndef WOLFSSL_NO_ML_KEM
  35627. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_sk[] = {
  35628. 0xda, 0x0a, 0xc7, 0xb6, 0x60, 0x40, 0x4e, 0x61,
  35629. 0x3a, 0xa1, 0xf9, 0x80, 0x38, 0x0c, 0xb3, 0x6d,
  35630. 0xba, 0x18, 0xd2, 0x32, 0x56, 0xc7, 0x26, 0x7a,
  35631. 0x00, 0xa6, 0x7b, 0xa6, 0xc2, 0xa2, 0xb1, 0x4c,
  35632. 0x41, 0x42, 0x39, 0x66, 0x2f, 0x68, 0xbd, 0x44,
  35633. 0x6c, 0x8e, 0xfd, 0xf3, 0x66, 0x56, 0xa0, 0x89,
  35634. 0x1a, 0x3c, 0xc6, 0x23, 0xfc, 0x68, 0xb6, 0x57,
  35635. 0x2f, 0x7b, 0x29, 0xa6, 0xde, 0x12, 0x80, 0x14,
  35636. 0x41, 0x1e, 0xe4, 0x19, 0x06, 0xd0, 0x80, 0x71,
  35637. 0xf9, 0x48, 0x56, 0xe3, 0x6a, 0x83, 0x2b, 0x40,
  35638. 0x33, 0x8d, 0x74, 0x35, 0x16, 0x65, 0x9b, 0xd2,
  35639. 0x58, 0x79, 0xc0, 0x07, 0xa5, 0x2b, 0xc9, 0x58,
  35640. 0x6f, 0x79, 0x87, 0x6a, 0xfa, 0xc6, 0xc9, 0xa3,
  35641. 0x0d, 0x8f, 0xac, 0x24, 0x3b, 0xd2, 0x24, 0x25,
  35642. 0xd6, 0xad, 0xce, 0x42, 0xab, 0x7e, 0xd3, 0x90,
  35643. 0x14, 0x75, 0x7a, 0x95, 0x8b, 0xc8, 0xa7, 0x45,
  35644. 0x65, 0xf0, 0x19, 0x23, 0x4f, 0xf0, 0x4b, 0x34,
  35645. 0x89, 0x3e, 0xd6, 0xd0, 0x55, 0x01, 0xc3, 0x72,
  35646. 0x55, 0x23, 0x9a, 0xae, 0x2a, 0xc1, 0x9f, 0x8c,
  35647. 0x75, 0xac, 0x59, 0x00, 0xda, 0xe8, 0x30, 0x0d,
  35648. 0xbb, 0xa7, 0x10, 0xdc, 0x2c, 0xaa, 0xe1, 0xbc,
  35649. 0xa3, 0xa3, 0x8c, 0x58, 0x34, 0x2b, 0x28, 0x6b,
  35650. 0x85, 0x18, 0xf1, 0x36, 0xad, 0x15, 0xb9, 0xf7,
  35651. 0xbc, 0xbb, 0x06, 0xa5, 0x60, 0x7d, 0xb3, 0x75,
  35652. 0xdb, 0xe9, 0x76, 0x45, 0x7c, 0x26, 0xc6, 0x59,
  35653. 0x82, 0x57, 0x53, 0x1b, 0x2c, 0xfb, 0x6e, 0xe7,
  35654. 0xf5, 0x15, 0x91, 0x84, 0x08, 0x04, 0xc3, 0x83,
  35655. 0x88, 0x37, 0x6c, 0x27, 0x14, 0x84, 0x13, 0xda,
  35656. 0x9e, 0x92, 0x92, 0x0b, 0xfd, 0x9a, 0x06, 0x9e,
  35657. 0x01, 0x8b, 0xd2, 0x72, 0x05, 0x3d, 0xa8, 0x77,
  35658. 0x5c, 0x0b, 0x73, 0x9f, 0x76, 0x1d, 0xb2, 0x10,
  35659. 0x7c, 0xf3, 0x5a, 0x43, 0x4d, 0x69, 0xb0, 0x7e,
  35660. 0x5b, 0xcd, 0xb8, 0x74, 0x34, 0x13, 0x8b, 0x0c,
  35661. 0xb5, 0x56, 0x76, 0x1b, 0xa5, 0x22, 0xa5, 0x74,
  35662. 0x7b, 0x28, 0x74, 0x7d, 0x80, 0xeb, 0x9d, 0x6c,
  35663. 0xc6, 0x73, 0xbe, 0xe5, 0x76, 0x93, 0x77, 0xb9,
  35664. 0x96, 0xd3, 0x6c, 0xeb, 0x0c, 0x0c, 0x7e, 0xd9,
  35665. 0xa6, 0x58, 0x53, 0x33, 0x24, 0x86, 0x9c, 0x18,
  35666. 0xa1, 0xa3, 0x6f, 0x31, 0x47, 0x0f, 0x14, 0xc5,
  35667. 0xae, 0x49, 0xab, 0x07, 0x05, 0x07, 0xf8, 0x24,
  35668. 0x9c, 0xe4, 0x04, 0xb4, 0x9c, 0x0a, 0x8c, 0x3e,
  35669. 0xe4, 0x2f, 0xea, 0x96, 0x31, 0xfa, 0x1a, 0x0d,
  35670. 0x10, 0xd8, 0x6b, 0x93, 0xf9, 0x86, 0xe0, 0xe3,
  35671. 0xa8, 0x2e, 0x70, 0x3b, 0x74, 0xe5, 0xae, 0x61,
  35672. 0x01, 0x24, 0x24, 0x21, 0xa8, 0x9a, 0xa0, 0x7f,
  35673. 0xe6, 0x85, 0x88, 0x46, 0x0b, 0xaa, 0x36, 0x87,
  35674. 0x86, 0x48, 0x6a, 0x72, 0xe4, 0xf2, 0x4d, 0x2d,
  35675. 0xd7, 0x6c, 0xfc, 0x03, 0xb6, 0x94, 0xa5, 0xba,
  35676. 0x91, 0xa7, 0x55, 0xa0, 0xb9, 0x8f, 0x3b, 0xf9,
  35677. 0x33, 0x07, 0xc0, 0xab, 0x64, 0x63, 0x9a, 0xea,
  35678. 0x7a, 0x64, 0x98, 0xa3, 0xc3, 0xdd, 0xc5, 0x71,
  35679. 0x14, 0x1a, 0xbc, 0xa4, 0x67, 0x8c, 0xd2, 0xe2,
  35680. 0xb8, 0x57, 0xfb, 0x88, 0xf6, 0x00, 0xca, 0xa5,
  35681. 0x96, 0xb4, 0x4b, 0xc4, 0x22, 0x25, 0x0b, 0x28,
  35682. 0x19, 0xe0, 0x51, 0x5f, 0x04, 0x72, 0x39, 0x18,
  35683. 0x53, 0x70, 0x0b, 0x01, 0xef, 0xf9, 0x45, 0x3f,
  35684. 0xd1, 0x18, 0x76, 0xb7, 0xc7, 0x59, 0xa0, 0x7d,
  35685. 0xd8, 0x45, 0xca, 0xba, 0x45, 0x55, 0x26, 0x4a,
  35686. 0x82, 0x76, 0x51, 0x93, 0xfd, 0xf8, 0x1b, 0x62,
  35687. 0x0a, 0x1e, 0x1f, 0x92, 0x3f, 0xb2, 0x44, 0x42,
  35688. 0xcd, 0x1c, 0xbe, 0x94, 0x17, 0x50, 0x03, 0xec,
  35689. 0x06, 0xce, 0x77, 0xa3, 0xc6, 0x44, 0x93, 0xc1,
  35690. 0x99, 0x98, 0x7a, 0x30, 0x0c, 0x95, 0xc5, 0x3c,
  35691. 0x00, 0x89, 0xb5, 0xd6, 0x5c, 0x92, 0xea, 0x97,
  35692. 0x1b, 0x2f, 0xfa, 0x93, 0xb5, 0x2a, 0x46, 0x1e,
  35693. 0xa2, 0xac, 0x8c, 0x19, 0x9c, 0x2f, 0x4c, 0x2b,
  35694. 0x70, 0x42, 0x97, 0xce, 0x3c, 0x39, 0x49, 0xe0,
  35695. 0x73, 0x5e, 0xa8, 0xa1, 0x4a, 0xa5, 0x9e, 0x8d,
  35696. 0xec, 0x0c, 0x87, 0x83, 0x99, 0xff, 0x70, 0x74,
  35697. 0x7a, 0xb2, 0x44, 0xce, 0x46, 0xb5, 0xf2, 0x23,
  35698. 0x04, 0x73, 0x32, 0x3d, 0x25, 0xc6, 0x6f, 0xe6,
  35699. 0xb4, 0x19, 0xb1, 0xf4, 0xa1, 0x12, 0xe5, 0x21,
  35700. 0x40, 0x35, 0x25, 0x6b, 0xc4, 0x3f, 0xfd, 0x2b,
  35701. 0x6b, 0x7b, 0x37, 0x87, 0x69, 0xa6, 0xb4, 0x70,
  35702. 0x00, 0xbf, 0xb6, 0x35, 0x7d, 0x45, 0x81, 0x4b,
  35703. 0xae, 0xf3, 0x85, 0x7d, 0x37, 0x9e, 0x2f, 0xb8,
  35704. 0xb5, 0xe5, 0x20, 0x1a, 0xb2, 0x62, 0x74, 0xbb,
  35705. 0x1b, 0x70, 0xad, 0x32, 0x2c, 0xd0, 0x43, 0x9b,
  35706. 0x2d, 0xb1, 0x09, 0xcf, 0xf0, 0xa2, 0xf8, 0xe6,
  35707. 0x00, 0x99, 0x55, 0x71, 0xff, 0xc3, 0x8c, 0x59,
  35708. 0x0b, 0xc4, 0xc7, 0x61, 0x5c, 0x69, 0xd0, 0xc9,
  35709. 0x8e, 0xf4, 0x30, 0xf3, 0x08, 0x61, 0xa7, 0x72,
  35710. 0x38, 0xff, 0xc0, 0x70, 0x61, 0xe4, 0x75, 0xd6,
  35711. 0xa3, 0x0a, 0xd1, 0xb4, 0x7f, 0xd0, 0x39, 0xc3,
  35712. 0xa4, 0x47, 0x76, 0x2d, 0xb2, 0x21, 0x1d, 0xc3,
  35713. 0x1d, 0x0a, 0xca, 0xcf, 0xd5, 0x58, 0x90, 0xa5,
  35714. 0x82, 0x47, 0x98, 0xf9, 0xae, 0xad, 0x74, 0x13,
  35715. 0xdf, 0xe0, 0x28, 0xb1, 0x01, 0x2b, 0xe8, 0xb6,
  35716. 0xca, 0x10, 0x26, 0x66, 0x6a, 0xc6, 0xbc, 0x94,
  35717. 0x40, 0xa4, 0x49, 0xb5, 0x1a, 0xd8, 0xbb, 0xa7,
  35718. 0xb0, 0x92, 0x1d, 0xd4, 0xd8, 0xb4, 0xa5, 0x78,
  35719. 0x13, 0x6d, 0x1a, 0x05, 0xdb, 0x38, 0xcc, 0x85,
  35720. 0x84, 0x37, 0xb2, 0x51, 0x61, 0xd1, 0xc3, 0xc2,
  35721. 0x8e, 0xe0, 0x7b, 0xbc, 0xf2, 0xb2, 0x49, 0x11,
  35722. 0x0d, 0x22, 0x78, 0x1d, 0xc3, 0x05, 0x0d, 0x8c,
  35723. 0xc0, 0x09, 0x00, 0x96, 0xb3, 0x8a, 0x85, 0x06,
  35724. 0x96, 0xf8, 0x6e, 0x9e, 0x6b, 0xab, 0x32, 0x52,
  35725. 0x71, 0xb2, 0x24, 0x86, 0x75, 0x01, 0x19, 0x68,
  35726. 0x50, 0x28, 0x81, 0x09, 0x04, 0x97, 0xfa, 0xc0,
  35727. 0xaf, 0x84, 0x3c, 0x1a, 0xea, 0x76, 0xdd, 0x81,
  35728. 0xcf, 0x29, 0xc0, 0x12, 0xc6, 0x62, 0x27, 0xb7,
  35729. 0xf0, 0x6d, 0x99, 0x61, 0x30, 0x9b, 0x02, 0x62,
  35730. 0xf7, 0x32, 0xc9, 0xa4, 0xd0, 0xbb, 0xd0, 0x67,
  35731. 0x27, 0xab, 0xb8, 0x37, 0x1f, 0xf2, 0xc1, 0x18,
  35732. 0x99, 0xa0, 0x98, 0x37, 0x5c, 0x46, 0x05, 0x16,
  35733. 0xb2, 0xcc, 0x88, 0xbc, 0xf6, 0x28, 0xed, 0xe3,
  35734. 0x7d, 0x8f, 0x3b, 0x33, 0x42, 0xe4, 0x49, 0x0a,
  35735. 0x85, 0x60, 0x6e, 0xc0, 0x3d, 0xa2, 0x9b, 0x02,
  35736. 0x56, 0x27, 0x53, 0x82, 0xa3, 0x31, 0x3d, 0xc0,
  35737. 0x41, 0x11, 0x48, 0x01, 0x03, 0x2c, 0x51, 0x9f,
  35738. 0x35, 0x0c, 0x3e, 0x6a, 0xba, 0xc3, 0xe3, 0x3b,
  35739. 0x93, 0xb4, 0xa1, 0x9f, 0x7c, 0x54, 0x66, 0xe5,
  35740. 0x8c, 0xb1, 0xdc, 0x14, 0xb4, 0xa9, 0x6c, 0x47,
  35741. 0x57, 0x29, 0xf9, 0x71, 0xbd, 0xf1, 0x73, 0xcd,
  35742. 0xf3, 0x54, 0x82, 0x4d, 0x01, 0x94, 0x27, 0xf9,
  35743. 0x5b, 0x3b, 0x4a, 0x4a, 0x4a, 0x95, 0x8e, 0x47,
  35744. 0x6a, 0x6e, 0x69, 0x91, 0xce, 0x6f, 0x06, 0xcb,
  35745. 0x5d, 0xfc, 0xa7, 0xd4, 0x38, 0x0c, 0x3d, 0x92,
  35746. 0x0b, 0x57, 0x11, 0xac, 0x1f, 0xcb, 0xaf, 0x4b,
  35747. 0x9a, 0xc8, 0x00, 0xb9, 0x76, 0xd1, 0xec, 0x76,
  35748. 0x6a, 0x62, 0x6c, 0xc1, 0x90, 0x0b, 0x66, 0xb3,
  35749. 0xa9, 0xdc, 0x62, 0xc5, 0xc1, 0x44, 0x52, 0x7a,
  35750. 0x29, 0x6b, 0xaf, 0x70, 0x43, 0x3b, 0xf6, 0x57,
  35751. 0xc0, 0x43, 0x7f, 0x87, 0x59, 0x7b, 0xd7, 0xc8,
  35752. 0xbb, 0xbe, 0x9a, 0xbc, 0x37, 0x05, 0x09, 0x31,
  35753. 0xa4, 0xa8, 0x69, 0x82, 0xa2, 0x02, 0x8a, 0x74,
  35754. 0x45, 0x4c, 0x9b, 0x81, 0x0c, 0x88, 0xd1, 0x70,
  35755. 0x1c, 0x8c, 0xc9, 0x8a, 0x1d, 0x4c, 0xa1, 0x07,
  35756. 0xa6, 0xb2, 0x5e, 0x96, 0x2f, 0xe4, 0xb6, 0xb0,
  35757. 0x3c, 0x95, 0x45, 0x32, 0x60, 0xb8, 0x07, 0x22,
  35758. 0x86, 0x37, 0xcc, 0x9e, 0xb1, 0x2a, 0xcc, 0x09,
  35759. 0x54, 0x95, 0x9a, 0x52, 0xae, 0x54, 0xd1, 0x97,
  35760. 0x73, 0x00, 0xab, 0xa0, 0xba, 0x2c, 0x14, 0x60,
  35761. 0x9b, 0xb2, 0x8c, 0x11, 0xd5, 0xfa, 0xc5, 0xca,
  35762. 0xc8, 0x82, 0x97, 0x60, 0x32, 0x83, 0xe8, 0x67,
  35763. 0xa3, 0x64, 0x83, 0x66, 0xc7, 0x24, 0xd9, 0x35,
  35764. 0x4c, 0xd7, 0xa1, 0x96, 0xdb, 0xd9, 0x80, 0x2f,
  35765. 0x7b, 0x88, 0xd3, 0xfa, 0x00, 0x1f, 0x9c, 0x97,
  35766. 0x73, 0x22, 0x54, 0x62, 0x23, 0x5e, 0x91, 0x35,
  35767. 0x2a, 0x20, 0x79, 0x1f, 0xd8, 0xb8, 0x7f, 0xe3,
  35768. 0x37, 0x7e, 0xc6, 0xa3, 0x94, 0x0b, 0x11, 0x30,
  35769. 0xa0, 0xbb, 0x04, 0xe7, 0x41, 0x0a, 0x34, 0xe2,
  35770. 0x58, 0x0d, 0x07, 0x1d, 0x6c, 0x56, 0x20, 0x20,
  35771. 0x86, 0x78, 0x7a, 0x65, 0x90, 0xf8, 0x43, 0x93,
  35772. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35773. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35774. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35775. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35776. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35777. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35778. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35779. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35780. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35781. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35782. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35783. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35784. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35785. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35786. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35787. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35788. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35789. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35790. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35791. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35792. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35793. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35794. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35795. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35796. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35797. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35798. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35799. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35800. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35801. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35802. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35803. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35804. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35805. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35806. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35807. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35808. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35809. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35810. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35811. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35812. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35813. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35814. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35815. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35816. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35817. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35818. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35819. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35820. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35821. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35822. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35823. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35824. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35825. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35826. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35827. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35828. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35829. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35830. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35831. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35832. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35833. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35834. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35835. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35836. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35837. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35838. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35839. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35840. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35841. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35842. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35843. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35844. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35845. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35846. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35847. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35848. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35849. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35850. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35851. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35852. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35853. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35854. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35855. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35856. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35857. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35858. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35859. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35860. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35861. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35862. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35863. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35864. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35865. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35866. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35867. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35868. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35869. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35870. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35871. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35872. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35873. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35874. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35875. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35876. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35877. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35878. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35879. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35880. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35881. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35882. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35883. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35884. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35885. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35886. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35887. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35888. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35889. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35890. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35891. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35892. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35893. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35894. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35895. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35896. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35897. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35898. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35899. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35900. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35901. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35902. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35903. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35904. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35905. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35906. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35907. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35908. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35909. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35910. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35911. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35912. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35913. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35914. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35915. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35916. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35917. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35918. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35919. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28,
  35920. 0xf5, 0x72, 0x62, 0x66, 0x13, 0x58, 0xcd, 0xe8,
  35921. 0xd3, 0xeb, 0xf9, 0x90, 0xe5, 0xfd, 0x1d, 0x5b,
  35922. 0x89, 0x6c, 0x99, 0x2c, 0xcf, 0xaa, 0xdb, 0x52,
  35923. 0x56, 0xb6, 0x8b, 0xbf, 0x59, 0x43, 0xb1, 0x32,
  35924. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  35925. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  35926. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  35927. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  35928. };
  35929. #endif
  35930. #ifdef WOLFSSL_KYBER_ORIGINAL
  35931. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ct[] = {
  35932. 0xB5, 0x2C, 0x56, 0xB9, 0x2A, 0x4B, 0x7C, 0xE9,
  35933. 0xE4, 0xCB, 0x7C, 0x5B, 0x1B, 0x16, 0x31, 0x67,
  35934. 0xA8, 0xA1, 0x67, 0x5B, 0x2F, 0xDE, 0xF8, 0x4A,
  35935. 0x5B, 0x67, 0xCA, 0x15, 0xDB, 0x69, 0x4C, 0x9F,
  35936. 0x11, 0xBD, 0x02, 0x7C, 0x30, 0xAE, 0x22, 0xEC,
  35937. 0x92, 0x1A, 0x1D, 0x91, 0x15, 0x99, 0xAF, 0x05,
  35938. 0x85, 0xE4, 0x8D, 0x20, 0xDA, 0x70, 0xDF, 0x9F,
  35939. 0x39, 0xE3, 0x2E, 0xF9, 0x5D, 0x4C, 0x8F, 0x44,
  35940. 0xBF, 0xEF, 0xDA, 0xA5, 0xDA, 0x64, 0xF1, 0x05,
  35941. 0x46, 0x31, 0xD0, 0x4D, 0x6D, 0x3C, 0xFD, 0x0A,
  35942. 0x54, 0x0D, 0xD7, 0xBA, 0x38, 0x86, 0xE4, 0xB5,
  35943. 0xF1, 0x3E, 0x87, 0x87, 0x88, 0x60, 0x4C, 0x95,
  35944. 0xC0, 0x96, 0xEA, 0xB3, 0x91, 0x9F, 0x42, 0x75,
  35945. 0x21, 0x41, 0x9A, 0x94, 0x6C, 0x26, 0xCC, 0x04,
  35946. 0x14, 0x75, 0xD7, 0x12, 0x4C, 0xDC, 0x01, 0xD0,
  35947. 0x37, 0x3E, 0x5B, 0x09, 0xC7, 0xA7, 0x06, 0x03,
  35948. 0xCF, 0xDB, 0x4F, 0xB3, 0x40, 0x50, 0x23, 0xF2,
  35949. 0x26, 0x4D, 0xC3, 0xF9, 0x83, 0xC4, 0xFC, 0x02,
  35950. 0xA2, 0xD1, 0xB2, 0x68, 0xF2, 0x20, 0x8A, 0x1F,
  35951. 0x6E, 0x2A, 0x62, 0x09, 0xBF, 0xF1, 0x2F, 0x6F,
  35952. 0x46, 0x5F, 0x0B, 0x06, 0x9C, 0x3A, 0x7F, 0x84,
  35953. 0xF6, 0x06, 0xD8, 0xA9, 0x40, 0x64, 0x00, 0x3D,
  35954. 0x6E, 0xC1, 0x14, 0xC8, 0xE8, 0x08, 0xD3, 0x05,
  35955. 0x38, 0x84, 0xC1, 0xD5, 0xA1, 0x42, 0xFB, 0xF2,
  35956. 0x01, 0x12, 0xEB, 0x36, 0x0F, 0xDA, 0x3F, 0x0F,
  35957. 0x28, 0xB1, 0x72, 0xAE, 0x50, 0xF5, 0xE7, 0xD8,
  35958. 0x38, 0x01, 0xFB, 0x3F, 0x00, 0x64, 0xB6, 0x87,
  35959. 0x18, 0x70, 0x74, 0xBD, 0x7F, 0xE3, 0x0E, 0xDD,
  35960. 0xAA, 0x33, 0x4C, 0xF8, 0xFC, 0x04, 0xFA, 0x8C,
  35961. 0xED, 0x89, 0x9C, 0xEA, 0xDE, 0x4B, 0x4F, 0x28,
  35962. 0xB6, 0x83, 0x72, 0xBA, 0xF9, 0x8F, 0xF4, 0x82,
  35963. 0xA4, 0x15, 0xB7, 0x31, 0x15, 0x5B, 0x75, 0xCE,
  35964. 0xB9, 0x76, 0xBE, 0x0E, 0xA0, 0x28, 0x5B, 0xA0,
  35965. 0x1A, 0x27, 0xF1, 0x85, 0x7A, 0x8F, 0xB3, 0x77,
  35966. 0xA3, 0xAE, 0x0C, 0x23, 0xB2, 0xAA, 0x9A, 0x07,
  35967. 0x9B, 0xFA, 0xBF, 0xF0, 0xD5, 0xB2, 0xF1, 0xCD,
  35968. 0x9B, 0x71, 0x8B, 0xEA, 0x03, 0xC4, 0x2F, 0x34,
  35969. 0x3A, 0x39, 0xB4, 0xF1, 0x42, 0xD0, 0x1A, 0xD8,
  35970. 0xAC, 0xBB, 0x50, 0xE3, 0x88, 0x53, 0xCF, 0x9A,
  35971. 0x50, 0xC8, 0xB4, 0x4C, 0x3C, 0xF6, 0x71, 0xA4,
  35972. 0xA9, 0x04, 0x3B, 0x26, 0xDD, 0xBB, 0x24, 0x95,
  35973. 0x9A, 0xD6, 0x71, 0x5C, 0x08, 0x52, 0x18, 0x55,
  35974. 0xC7, 0x9A, 0x23, 0xB9, 0xC3, 0xD6, 0x47, 0x17,
  35975. 0x49, 0xC4, 0x07, 0x25, 0xBD, 0xD5, 0xC2, 0x77,
  35976. 0x6D, 0x43, 0xAE, 0xD2, 0x02, 0x04, 0xBA, 0xA1,
  35977. 0x41, 0xEF, 0xB3, 0x30, 0x49, 0x17, 0x47, 0x4B,
  35978. 0x7F, 0x9F, 0x7A, 0x4B, 0x08, 0xB1, 0xA9, 0x3D,
  35979. 0xAE, 0xD9, 0x8C, 0x67, 0x49, 0x53, 0x59, 0xD3,
  35980. 0x7D, 0x67, 0xF7, 0x43, 0x8B, 0xEE, 0x5E, 0x43,
  35981. 0x58, 0x56, 0x34, 0xB2, 0x6C, 0x6B, 0x38, 0x10,
  35982. 0xD7, 0xCD, 0xCB, 0xC0, 0xF6, 0xEB, 0x87, 0x7A,
  35983. 0x60, 0x87, 0xE6, 0x8A, 0xCB, 0x84, 0x80, 0xD3,
  35984. 0xA8, 0xCF, 0x69, 0x00, 0x44, 0x7E, 0x49, 0xB4,
  35985. 0x17, 0xF1, 0x5A, 0x53, 0xB6, 0x07, 0xA0, 0xE2,
  35986. 0x16, 0xB8, 0x55, 0x97, 0x0D, 0x37, 0x40, 0x68,
  35987. 0x70, 0xB4, 0x56, 0x87, 0x22, 0xDA, 0x77, 0xA4,
  35988. 0x08, 0x47, 0x03, 0x81, 0x67, 0x84, 0xE2, 0xF1,
  35989. 0x6B, 0xED, 0x18, 0x99, 0x65, 0x32, 0xC5, 0xD8,
  35990. 0xB7, 0xF5, 0xD2, 0x14, 0x46, 0x4E, 0x5F, 0x3F,
  35991. 0x6E, 0x90, 0x58, 0x67, 0xB0, 0xCE, 0x11, 0x9E,
  35992. 0x25, 0x2A, 0x66, 0x71, 0x32, 0x53, 0x54, 0x46,
  35993. 0x85, 0xD2, 0x08, 0xE1, 0x72, 0x39, 0x08, 0xA0,
  35994. 0xCE, 0x97, 0x83, 0x46, 0x52, 0xE0, 0x8A, 0xE7,
  35995. 0xBD, 0xC8, 0x81, 0xA1, 0x31, 0xB7, 0x3C, 0x71,
  35996. 0xE8, 0x4D, 0x20, 0xD6, 0x8F, 0xDE, 0xFF, 0x4F,
  35997. 0x5D, 0x70, 0xCD, 0x1A, 0xF5, 0x7B, 0x78, 0xE3,
  35998. 0x49, 0x1A, 0x98, 0x65, 0x94, 0x23, 0x21, 0x80,
  35999. 0x0A, 0x20, 0x3C, 0x05, 0xED, 0x1F, 0xEE, 0xB5,
  36000. 0xA2, 0x8E, 0x58, 0x4E, 0x19, 0xF6, 0x53, 0x5E,
  36001. 0x7F, 0x84, 0xE4, 0xA2, 0x4F, 0x84, 0xA7, 0x2D,
  36002. 0xCA, 0xF5, 0x64, 0x8B, 0x4A, 0x42, 0x35, 0xDD,
  36003. 0x66, 0x44, 0x64, 0x48, 0x2F, 0x03, 0x17, 0x6E,
  36004. 0x88, 0x8C, 0x28, 0xBF, 0xC6, 0xC1, 0xCB, 0x23,
  36005. 0x8C, 0xFF, 0xA3, 0x5A, 0x32, 0x1E, 0x71, 0x79,
  36006. 0x1D, 0x9E, 0xA8, 0xED, 0x08, 0x78, 0xC6, 0x11,
  36007. 0x21, 0xBF, 0x8D, 0x2A, 0x4A, 0xB2, 0xC1, 0xA5,
  36008. 0xE1, 0x20, 0xBC, 0x40, 0xAB, 0xB1, 0x89, 0x2D,
  36009. 0x17, 0x15, 0x09, 0x0A, 0x0E, 0xE4, 0x82, 0x52,
  36010. 0xCA, 0x29, 0x7A, 0x99, 0xAA, 0x0E, 0x51, 0x0C,
  36011. 0xF2, 0x6B, 0x1A, 0xDD, 0x06, 0xCA, 0x54, 0x3E,
  36012. 0x1C, 0x5D, 0x6B, 0xDC, 0xD3, 0xB9, 0xC5, 0x85,
  36013. 0xC8, 0x53, 0x80, 0x45, 0xDB, 0x5C, 0x25, 0x2E,
  36014. 0xC3, 0xC8, 0xC3, 0xC9, 0x54, 0xD9, 0xBE, 0x59,
  36015. 0x07, 0x09, 0x4A, 0x89, 0x4E, 0x60, 0xEA, 0xB4,
  36016. 0x35, 0x38, 0xCF, 0xEE, 0x82, 0xE8, 0xFF, 0xC0,
  36017. 0x79, 0x1B, 0x0D, 0x0F, 0x43, 0xAC, 0x16, 0x27,
  36018. 0x83, 0x0A, 0x61, 0xD5, 0x6D, 0xAD, 0x96, 0xC6,
  36019. 0x29, 0x58, 0xB0, 0xDE, 0x78, 0x0B, 0x78, 0xBD,
  36020. 0x47, 0xA6, 0x04, 0x55, 0x0D, 0xAB, 0x83, 0xFF,
  36021. 0xF2, 0x27, 0xC3, 0x24, 0x04, 0x94, 0x71, 0xF3,
  36022. 0x52, 0x48, 0xCF, 0xB8, 0x49, 0xB2, 0x57, 0x24,
  36023. 0xFF, 0x70, 0x4D, 0x52, 0x77, 0xAA, 0x35, 0x2D,
  36024. 0x55, 0x09, 0x58, 0xBE, 0x3B, 0x23, 0x7D, 0xFF,
  36025. 0x47, 0x3E, 0xC2, 0xAD, 0xBA, 0xEA, 0x48, 0xCA,
  36026. 0x26, 0x58, 0xAE, 0xFC, 0xC7, 0x7B, 0xBD, 0x42,
  36027. 0x64, 0xAB, 0x37, 0x4D, 0x70, 0xEA, 0xE5, 0xB9,
  36028. 0x64, 0x41, 0x6C, 0xE8, 0x22, 0x6A, 0x7E, 0x32,
  36029. 0x55, 0xA0, 0xF8, 0xD7, 0xE2, 0xAD, 0xCA, 0x06,
  36030. 0x2B, 0xCD, 0x6D, 0x78, 0xD6, 0x0D, 0x1B, 0x32,
  36031. 0xE1, 0x14, 0x05, 0xBE, 0x54, 0xB6, 0x6E, 0xF0,
  36032. 0xFD, 0xDD, 0x56, 0x77, 0x02, 0xA3, 0xBC, 0xCF,
  36033. 0xED, 0xE3, 0xC5, 0x84, 0x70, 0x12, 0x69, 0xED,
  36034. 0x14, 0x80, 0x9F, 0x06, 0xF8, 0x96, 0x83, 0x56,
  36035. 0xBB, 0x92, 0x67, 0xFE, 0x86, 0xE5, 0x14, 0x25,
  36036. 0x2E, 0x88, 0xBB, 0x5C, 0x30, 0xA7, 0xEC, 0xB3,
  36037. 0xD0, 0xE6, 0x21, 0x02, 0x1E, 0xE0, 0xFB, 0xF7,
  36038. 0x87, 0x1B, 0x09, 0x34, 0x2B, 0xF8, 0x4F, 0x55,
  36039. 0xC9, 0x7E, 0xAF, 0x86, 0xC4, 0x81, 0x89, 0xC7,
  36040. 0xFF, 0x4D, 0xF3, 0x89, 0xF0, 0x77, 0xE2, 0x80,
  36041. 0x6E, 0x5F, 0xA7, 0x3B, 0x3E, 0x94, 0x58, 0xA1,
  36042. 0x6C, 0x7E, 0x27, 0x5F, 0x4F, 0x60, 0x22, 0x75,
  36043. 0x58, 0x0E, 0xB7, 0xB7, 0x13, 0x5F, 0xB5, 0x37,
  36044. 0xFA, 0x0C, 0xD9, 0x5D, 0x6E, 0xA5, 0x8C, 0x10,
  36045. 0x8C, 0xD8, 0x94, 0x3D, 0x70, 0xC1, 0x64, 0x31,
  36046. 0x11, 0xF4, 0xF0, 0x1C, 0xA8, 0xA8, 0x27, 0x6A,
  36047. 0x90, 0x26, 0x66, 0xED, 0x81, 0xB7, 0x8D, 0x16,
  36048. 0x8B, 0x00, 0x6F, 0x16, 0xAA, 0xA3, 0xD8, 0xE4,
  36049. 0xCE, 0x4F, 0x4D, 0x0F, 0xB0, 0x99, 0x7E, 0x41,
  36050. 0xAE, 0xFF, 0xB5, 0xB3, 0xDA, 0xA8, 0x38, 0x73,
  36051. 0x2F, 0x35, 0x73, 0x49, 0x44, 0x7F, 0x38, 0x77,
  36052. 0x76, 0xC7, 0x93, 0xC0, 0x47, 0x9D, 0xE9, 0xE9,
  36053. 0x94, 0x98, 0xCC, 0x35, 0x6F, 0xDB, 0x00, 0x75,
  36054. 0xA7, 0x03, 0xF2, 0x3C, 0x55, 0xD4, 0x7B, 0x55,
  36055. 0x0E, 0xC8, 0x9B, 0x02, 0xAD, 0xE8, 0x93, 0x29,
  36056. 0x08, 0x6A, 0x50, 0x84, 0x34, 0x56, 0xFE, 0xDC,
  36057. 0x37, 0x88, 0xAC, 0x8D, 0x97, 0x23, 0x3C, 0x54,
  36058. 0x56, 0x04, 0x67, 0xEE, 0x1D, 0x0F, 0x02, 0x4B,
  36059. 0x18, 0x42, 0x8F, 0x0D, 0x73, 0xB3, 0x0E, 0x19,
  36060. 0xF5, 0xC6, 0x3B, 0x9A, 0xBF, 0x11, 0x41, 0x5B,
  36061. 0xEA, 0x4D, 0x01, 0x70, 0x13, 0x0B, 0xAA, 0xBD,
  36062. 0x33, 0xC0, 0x5E, 0x65, 0x24, 0xE5, 0xFB, 0x55,
  36063. 0x81, 0xB2, 0x2B, 0x04, 0x33, 0x34, 0x22, 0x48,
  36064. 0x26, 0x6D, 0x0F, 0x10, 0x53, 0xB2, 0x45, 0xCC,
  36065. 0x24, 0x62, 0xDC, 0x44, 0xD3, 0x49, 0x65, 0x10,
  36066. 0x24, 0x82, 0xA8, 0xED, 0x9E, 0x4E, 0x96, 0x4D,
  36067. 0x56, 0x83, 0xE5, 0xD4, 0x5D, 0x0C, 0x82, 0x69
  36068. };
  36069. #endif
  36070. #ifndef WOLFSSL_NO_ML_KEM
  36071. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_ct[] = {
  36072. 0xc8, 0x39, 0x10, 0x85, 0xb8, 0xd3, 0xea, 0x97,
  36073. 0x94, 0x21, 0x25, 0x41, 0xb2, 0x91, 0x4f, 0x08,
  36074. 0x96, 0x4d, 0x33, 0x52, 0x1d, 0x3f, 0x67, 0xad,
  36075. 0x66, 0x09, 0x6e, 0xbf, 0xb1, 0xf7, 0x06, 0x42,
  36076. 0x4b, 0x49, 0x55, 0x8f, 0x75, 0x5b, 0x56, 0x25,
  36077. 0xba, 0xe2, 0x36, 0xf2, 0xe0, 0x07, 0x96, 0x01,
  36078. 0xc7, 0x66, 0xf7, 0xd9, 0x60, 0x80, 0x8f, 0x7e,
  36079. 0x2b, 0xb0, 0xc7, 0xa5, 0xe0, 0x66, 0xed, 0x34,
  36080. 0x6d, 0xe6, 0x28, 0xf8, 0xc5, 0x7e, 0xeb, 0xab,
  36081. 0xbb, 0x0c, 0x22, 0xd9, 0x11, 0x54, 0x84, 0x63,
  36082. 0x69, 0x3e, 0xf3, 0xce, 0x52, 0xa5, 0x3f, 0x7f,
  36083. 0xf4, 0x15, 0xf0, 0x0e, 0x65, 0x7a, 0xe1, 0xc5,
  36084. 0xa4, 0x8f, 0xa5, 0xec, 0x6e, 0x4b, 0xe5, 0xcf,
  36085. 0x46, 0x2d, 0xaf, 0xfc, 0x84, 0xd2, 0xf6, 0xd5,
  36086. 0xff, 0x55, 0xdc, 0x9b, 0xbe, 0x8b, 0xb0, 0xd7,
  36087. 0x25, 0xec, 0x64, 0xfd, 0x4c, 0xd4, 0xbd, 0x8d,
  36088. 0xba, 0x0a, 0x84, 0x4e, 0x8b, 0x5c, 0xe4, 0xb6,
  36089. 0xa2, 0x89, 0x34, 0xd7, 0xf7, 0xa0, 0x50, 0x99,
  36090. 0x1f, 0xe1, 0x85, 0xb5, 0x06, 0xb4, 0x51, 0xda,
  36091. 0xbf, 0xad, 0x52, 0xd5, 0x2c, 0xb2, 0x11, 0x4c,
  36092. 0xa7, 0xd9, 0xa5, 0xcf, 0x98, 0x6c, 0x8f, 0xdc,
  36093. 0x1b, 0xc1, 0x0e, 0xc0, 0xc1, 0x86, 0x9e, 0x50,
  36094. 0xc0, 0x3c, 0x55, 0xa7, 0x61, 0x92, 0xa1, 0x04,
  36095. 0x9a, 0xca, 0x63, 0x6b, 0xa9, 0x02, 0x0b, 0xda,
  36096. 0xa8, 0xd0, 0xf5, 0x8c, 0x76, 0x3b, 0x0b, 0x89,
  36097. 0x84, 0x5c, 0xa0, 0x6d, 0x4c, 0x4d, 0xdc, 0x21,
  36098. 0x43, 0x3e, 0x16, 0xb9, 0xc6, 0x2e, 0x44, 0x87,
  36099. 0x1f, 0xdb, 0xc0, 0x5b, 0xa2, 0x18, 0xaf, 0x87,
  36100. 0x1f, 0xdd, 0x7d, 0xcf, 0xa4, 0x64, 0xe6, 0x0f,
  36101. 0xaa, 0x52, 0x65, 0x26, 0x4c, 0xe1, 0x39, 0x1b,
  36102. 0xd9, 0xa8, 0xc5, 0xfa, 0xa7, 0x62, 0x6d, 0x5f,
  36103. 0x15, 0x9b, 0x98, 0x05, 0xb9, 0x75, 0x71, 0x0a,
  36104. 0x35, 0x03, 0xa0, 0xb8, 0x58, 0xa1, 0x1c, 0x6a,
  36105. 0x64, 0x7c, 0xc0, 0xe1, 0x9a, 0xc8, 0x8b, 0x1b,
  36106. 0xe9, 0x05, 0x6c, 0x95, 0xb4, 0xd2, 0x08, 0x7d,
  36107. 0x09, 0x51, 0xd1, 0xd2, 0xf4, 0x99, 0x24, 0x91,
  36108. 0x11, 0x7e, 0x63, 0x47, 0x79, 0x4b, 0xa5, 0x45,
  36109. 0x71, 0xec, 0x49, 0xbb, 0xa7, 0x1a, 0xf3, 0x41,
  36110. 0x3d, 0x38, 0xa3, 0x0b, 0xf5, 0x87, 0x22, 0x48,
  36111. 0xd1, 0xf6, 0xd0, 0x7c, 0x86, 0xba, 0xf7, 0x82,
  36112. 0xe7, 0x3d, 0x26, 0x37, 0xf0, 0x43, 0xd3, 0x41,
  36113. 0xa0, 0x09, 0x21, 0x85, 0x7d, 0x8b, 0x21, 0xdd,
  36114. 0xf3, 0xe1, 0xd6, 0x31, 0x00, 0x36, 0xed, 0x27,
  36115. 0xaf, 0x49, 0xe5, 0xde, 0x1b, 0x90, 0x0f, 0xe4,
  36116. 0xde, 0x79, 0x80, 0x8f, 0xf2, 0x9f, 0x95, 0x70,
  36117. 0x85, 0x96, 0x12, 0xb1, 0x5a, 0xdc, 0x01, 0xfb,
  36118. 0xb2, 0x65, 0xb3, 0x05, 0xb1, 0xe3, 0xa1, 0x2a,
  36119. 0xe4, 0x19, 0xda, 0x5b, 0x74, 0x26, 0x1f, 0xa2,
  36120. 0x84, 0xc1, 0x01, 0xda, 0x3d, 0x8d, 0xca, 0x8b,
  36121. 0x2e, 0x45, 0x21, 0xac, 0xa5, 0x71, 0xef, 0x44,
  36122. 0xa0, 0x58, 0xe8, 0x44, 0xff, 0x32, 0xb1, 0x6d,
  36123. 0x5a, 0xae, 0xa0, 0x5f, 0x7f, 0x3a, 0xf8, 0xe2,
  36124. 0xab, 0x16, 0x22, 0x2e, 0x34, 0x76, 0x62, 0xed,
  36125. 0xdf, 0xb8, 0x91, 0xd0, 0xec, 0xc2, 0xa5, 0x5c,
  36126. 0x56, 0x38, 0xf9, 0xdd, 0xe9, 0x2d, 0x9a, 0x3d,
  36127. 0x54, 0x4a, 0x5f, 0x90, 0x1a, 0xc5, 0x01, 0xac,
  36128. 0xd1, 0xea, 0x6a, 0x01, 0x02, 0x01, 0xfc, 0xb1,
  36129. 0x0a, 0xd7, 0x02, 0xc4, 0x25, 0xa9, 0x4b, 0xdf,
  36130. 0x58, 0x90, 0xd5, 0x00, 0xa2, 0xa1, 0x47, 0xee,
  36131. 0xe1, 0xd1, 0xfc, 0xba, 0x8c, 0x3a, 0xbe, 0x7c,
  36132. 0x2d, 0xfe, 0x70, 0xf3, 0x46, 0xf0, 0x33, 0xd8,
  36133. 0x16, 0xa0, 0xb2, 0x79, 0x1b, 0x4f, 0x0b, 0x2d,
  36134. 0x95, 0x6d, 0x9e, 0xe5, 0x97, 0x17, 0x15, 0x39,
  36135. 0x9a, 0x56, 0x88, 0x30, 0x24, 0x95, 0xe2, 0xe0,
  36136. 0x7c, 0x1c, 0x8c, 0x01, 0x52, 0x71, 0x84, 0xbc,
  36137. 0xd0, 0xc2, 0x08, 0xbc, 0x15, 0x9f, 0x2e, 0x13,
  36138. 0x31, 0x8c, 0x0b, 0xb3, 0xdd, 0x24, 0xa6, 0xa7,
  36139. 0xfc, 0x84, 0x9f, 0x83, 0x38, 0x5e, 0xd4, 0xdb,
  36140. 0xa0, 0x7f, 0xe1, 0xd7, 0xbd, 0x56, 0x40, 0xcc,
  36141. 0x9e, 0xd5, 0xcc, 0xfd, 0xd6, 0x87, 0x63, 0xcb,
  36142. 0x0d, 0x0e, 0xdf, 0x61, 0xb2, 0x92, 0x17, 0x7f,
  36143. 0xc1, 0xd2, 0xd3, 0xc1, 0x1d, 0xd0, 0x49, 0x50,
  36144. 0x56, 0xbc, 0xb1, 0x25, 0x58, 0xae, 0xbc, 0xfd,
  36145. 0xde, 0xf9, 0xfe, 0xb4, 0xae, 0xbc, 0x57, 0xaf,
  36146. 0xd9, 0x02, 0x3c, 0x65, 0xcf, 0xe6, 0x5a, 0x24,
  36147. 0xe3, 0x3f, 0x1b, 0x00, 0x11, 0x1e, 0x92, 0xe6,
  36148. 0x3e, 0x01, 0x1e, 0xaf, 0x0b, 0x21, 0x2c, 0xf9,
  36149. 0x57, 0x43, 0xcd, 0x07, 0xf5, 0x18, 0x9e, 0xce,
  36150. 0x1f, 0x20, 0x5b, 0x7f, 0x6f, 0xcb, 0x2e, 0x6b,
  36151. 0x19, 0x61, 0xb5, 0x40, 0x4c, 0xeb, 0xe4, 0x7c,
  36152. 0x8c, 0xd1, 0x3b, 0x85, 0x99, 0xd5, 0xb4, 0x9e,
  36153. 0x6d, 0x87, 0xee, 0xda, 0x36, 0xe9, 0xb8, 0xfc,
  36154. 0x4c, 0x00, 0x63, 0x58, 0x96, 0xaa, 0x2b, 0x75,
  36155. 0x89, 0x6e, 0x33, 0x6d, 0x1b, 0x61, 0x2e, 0xe1,
  36156. 0x3d, 0xb8, 0x11, 0xe1, 0xf0, 0x7e, 0x61, 0x74,
  36157. 0x8d, 0x92, 0x0f, 0x48, 0x65, 0xf3, 0xf1, 0x17,
  36158. 0x41, 0x39, 0x9d, 0xc6, 0x16, 0x2c, 0x91, 0xca,
  36159. 0x16, 0x8a, 0x02, 0x32, 0x9d, 0xff, 0x82, 0x1d,
  36160. 0x58, 0x19, 0x87, 0x12, 0xdd, 0x55, 0x8a, 0xbb,
  36161. 0x09, 0x9b, 0x3a, 0x0b, 0xaf, 0x9d, 0xa1, 0xb7,
  36162. 0x30, 0xb2, 0xaa, 0x73, 0xbc, 0xf5, 0x8d, 0x74,
  36163. 0xf3, 0x57, 0xb0, 0x6f, 0x72, 0x11, 0xc8, 0x04,
  36164. 0xb6, 0xc8, 0xaf, 0x16, 0xff, 0x35, 0x09, 0xfa,
  36165. 0xd1, 0xd3, 0x5b, 0x14, 0xbf, 0xdc, 0xed, 0x7d,
  36166. 0xb8, 0xa6, 0xa2, 0x5c, 0x48, 0xe5, 0x95, 0x64,
  36167. 0x80, 0x72, 0x4d, 0xaa, 0x05, 0x7c, 0xd6, 0x60,
  36168. 0xb6, 0x7e, 0xe3, 0xe4, 0x72, 0x57, 0x41, 0x82,
  36169. 0x67, 0x9d, 0x48, 0x58, 0x38, 0xa6, 0x47, 0x6e,
  36170. 0xac, 0x02, 0x14, 0x10, 0x75, 0xc8, 0x12, 0xaf,
  36171. 0x79, 0x67, 0xba, 0x7c, 0x91, 0x85, 0xcc, 0x2a,
  36172. 0xbd, 0x2a, 0x45, 0x45, 0xb8, 0x0f, 0x3d, 0x31,
  36173. 0x04, 0xd5, 0x8d, 0x65, 0x4a, 0x57, 0x79, 0x2d,
  36174. 0xcf, 0xab, 0xbe, 0x9c, 0x07, 0x15, 0xe8, 0xde,
  36175. 0x2e, 0xf8, 0x1e, 0xf4, 0x04, 0xc8, 0x16, 0x8f,
  36176. 0xd7, 0xa4, 0x3e, 0xfa, 0xb3, 0xd4, 0x48, 0xe6,
  36177. 0x86, 0xa0, 0x88, 0xef, 0xd2, 0x6a, 0x26, 0x15,
  36178. 0x99, 0x48, 0x92, 0x67, 0x23, 0xd7, 0xec, 0xcc,
  36179. 0x39, 0xe3, 0xc1, 0xb7, 0x19, 0xcf, 0x8b, 0xec,
  36180. 0xb7, 0xbe, 0x7e, 0x96, 0x4f, 0x22, 0xcd, 0x8c,
  36181. 0xb1, 0xb7, 0xe2, 0x5e, 0x80, 0x0e, 0xa9, 0x7d,
  36182. 0x60, 0xa6, 0x4c, 0xc0, 0xbb, 0xd9, 0xcb, 0x40,
  36183. 0x7a, 0x3a, 0xb9, 0xf8, 0x8f, 0x5e, 0x29, 0x16,
  36184. 0x9e, 0xea, 0xfd, 0x4e, 0x03, 0x22, 0xfd, 0xe6,
  36185. 0x59, 0x0a, 0xe0, 0x93, 0xce, 0x8f, 0xee, 0xae,
  36186. 0x98, 0xb6, 0x22, 0xca, 0xa7, 0x55, 0x6f, 0xf4,
  36187. 0x26, 0xc9, 0xe7, 0xa4, 0x04, 0xce, 0x69, 0x35,
  36188. 0x58, 0x30, 0xa7, 0xa6, 0x77, 0x67, 0xa7, 0x6c,
  36189. 0x7d, 0x9a, 0x97, 0xb8, 0x4b, 0xfc, 0xf5, 0x0a,
  36190. 0x02, 0xf7, 0x5c, 0x23, 0x5d, 0x2f, 0x9c, 0x67,
  36191. 0x11, 0x38, 0x04, 0x9f, 0xfc, 0x7c, 0x80, 0x55,
  36192. 0x92, 0x6c, 0x03, 0xeb, 0x3f, 0xb8, 0x7f, 0x96,
  36193. 0x95, 0x18, 0x5a, 0x42, 0xec, 0xa9, 0xa4, 0x16,
  36194. 0x55, 0x87, 0x3d, 0x30, 0xa6, 0xb3, 0xbf, 0x42,
  36195. 0x8b, 0x24, 0x62, 0x23, 0x48, 0x4a, 0x8f, 0xf6,
  36196. 0x1e, 0xe3, 0xee, 0xaf, 0xff, 0x10, 0xe9, 0x9c,
  36197. 0x2c, 0x13, 0xa7, 0x62, 0x84, 0xd0, 0x63, 0xe5,
  36198. 0x6a, 0xb7, 0x11, 0xa3, 0x5a, 0x85, 0xb5, 0x38,
  36199. 0x3d, 0xf8, 0x1d, 0xa2, 0x34, 0x90, 0xf6, 0x6e,
  36200. 0x8e, 0xa3, 0xfc, 0xba, 0x06, 0x7f, 0x55, 0x30,
  36201. 0xc6, 0x54, 0x1c, 0x2b, 0x8f, 0x74, 0x71, 0x7c,
  36202. 0x35, 0x02, 0x3e, 0x7b, 0x9b, 0x39, 0x56, 0xc3,
  36203. 0xee, 0x2f, 0xf8, 0x4b, 0xa0, 0x3c, 0xcf, 0x4b,
  36204. 0x4b, 0x53, 0x21, 0xb9, 0x24, 0x08, 0x95, 0x48,
  36205. 0x1b, 0xc6, 0xd6, 0x3c, 0x16, 0x93, 0xc1, 0x84,
  36206. 0x78, 0x52, 0xf8, 0xe9, 0x7f, 0x50, 0xa1, 0x33,
  36207. 0x53, 0x2a, 0xc3, 0xee, 0x1e, 0x52, 0xd4, 0x64
  36208. };
  36209. #endif
  36210. #ifdef WOLFSSL_KYBER_ORIGINAL
  36211. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ss[] = {
  36212. 0x91, 0x4C, 0xB6, 0x7F, 0xE5, 0xC3, 0x8E, 0x73,
  36213. 0xBF, 0x74, 0x18, 0x1C, 0x0A, 0xC5, 0x04, 0x28,
  36214. 0xDE, 0xDF, 0x77, 0x50, 0xA9, 0x80, 0x58, 0xF7,
  36215. 0xD5, 0x36, 0x70, 0x87, 0x74, 0x53, 0x5B, 0x29
  36216. };
  36217. #endif
  36218. #ifndef WOLFSSL_NO_ML_KEM
  36219. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_ss[] = {
  36220. 0xe7, 0x18, 0x4a, 0x09, 0x75, 0xee, 0x34, 0x70,
  36221. 0x87, 0x8d, 0x2d, 0x15, 0x9e, 0xc8, 0x31, 0x29,
  36222. 0xc8, 0xae, 0xc2, 0x53, 0xd4, 0xee, 0x17, 0xb4,
  36223. 0x81, 0x03, 0x11, 0xd1, 0x98, 0xcd, 0x03, 0x68
  36224. };
  36225. #endif
  36226. #ifdef WOLFSSL_SMALL_STACK
  36227. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  36228. DYNAMIC_TYPE_TMP_BUFFER);
  36229. priv = (byte *)XMALLOC(KYBER768_PRIVATE_KEY_SIZE, HEAP_HINT,
  36230. DYNAMIC_TYPE_TMP_BUFFER);
  36231. pub = (byte *)XMALLOC(KYBER768_PUBLIC_KEY_SIZE, HEAP_HINT,
  36232. DYNAMIC_TYPE_TMP_BUFFER);
  36233. ct = (byte *)XMALLOC(KYBER768_CIPHER_TEXT_SIZE, HEAP_HINT,
  36234. DYNAMIC_TYPE_TMP_BUFFER);
  36235. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36236. DYNAMIC_TYPE_TMP_BUFFER);
  36237. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36238. DYNAMIC_TYPE_TMP_BUFFER);
  36239. if (! (key && priv && pub && ct && ss && ss_dec))
  36240. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  36241. #endif
  36242. #ifdef WOLFSSL_KYBER_ORIGINAL
  36243. ret = wc_KyberKey_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
  36244. if (ret != 0)
  36245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36246. else
  36247. key_inited = 1;
  36248. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36249. sizeof(kyber768_rand));
  36250. if (ret != 0)
  36251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36252. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
  36253. if (ret != 0)
  36254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36255. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
  36256. if (ret != 0)
  36257. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36258. if (XMEMCMP(pub, kyber768_pk, sizeof(kyber768_pk)) != 0)
  36259. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36260. if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0)
  36261. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36262. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36263. sizeof(kyber768enc_rand));
  36264. if (ret != 0)
  36265. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36266. if (XMEMCMP(ct, kyber768_ct, sizeof(kyber768_ct)) != 0)
  36267. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36268. if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36269. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36270. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
  36271. if (ret != 0)
  36272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36273. if (XMEMCMP(ss_dec, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36274. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36275. #endif
  36276. #ifndef WOLFSSL_NO_ML_KEM
  36277. ret = wc_KyberKey_Init(WC_ML_KEM_768, key, HEAP_HINT, INVALID_DEVID);
  36278. if (ret != 0)
  36279. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36280. else
  36281. key_inited = 1;
  36282. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36283. sizeof(kyber768_rand));
  36284. if (ret != 0)
  36285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36286. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_768_PUBLIC_KEY_SIZE);
  36287. if (ret != 0)
  36288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36289. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  36290. WC_ML_KEM_768_PRIVATE_KEY_SIZE);
  36291. if (ret != 0)
  36292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36293. if (XMEMCMP(pub, ml_kem_768_pk, sizeof(ml_kem_768_pk)) != 0)
  36294. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36295. if (XMEMCMP(priv, ml_kem_768_sk, sizeof(ml_kem_768_sk)) != 0)
  36296. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36297. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36298. sizeof(kyber768enc_rand));
  36299. if (ret != 0)
  36300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36301. if (XMEMCMP(ct, ml_kem_768_ct, sizeof(ml_kem_768_ct)) != 0)
  36302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36303. if (XMEMCMP(ss, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
  36304. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36305. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_768_ct));
  36306. if (ret != 0)
  36307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36308. if (XMEMCMP(ss_dec, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
  36309. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36310. #endif
  36311. out:
  36312. if (key_inited)
  36313. wc_KyberKey_Free(key);
  36314. #ifdef WOLFSSL_SMALL_STACK
  36315. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36316. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36317. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36318. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36319. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36320. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36321. #endif
  36322. return ret;
  36323. }
  36324. #endif /* WOLFSSL_KYBER768 */
  36325. #if !defined(WOLFSSL_NO_KYBER1024) && !defined(WOLFSSL_NO_ML_KEM_1024)
  36326. static wc_test_ret_t kyber1024_kat(void)
  36327. {
  36328. wc_test_ret_t ret;
  36329. #ifdef WOLFSSL_SMALL_STACK
  36330. KyberKey *key = NULL;
  36331. byte *priv = NULL;
  36332. byte *pub = NULL;
  36333. byte *ct = NULL;
  36334. byte *ss = NULL;
  36335. byte *ss_dec = NULL;
  36336. #else
  36337. KyberKey key[1];
  36338. byte priv[KYBER1024_PRIVATE_KEY_SIZE];
  36339. byte pub[KYBER1024_PUBLIC_KEY_SIZE];
  36340. byte ct[KYBER1024_CIPHER_TEXT_SIZE];
  36341. byte ss[KYBER_SS_SZ];
  36342. byte ss_dec[KYBER_SS_SZ];
  36343. #endif
  36344. int key_inited = 0;
  36345. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_rand[] = {
  36346. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  36347. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  36348. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  36349. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  36350. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  36351. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  36352. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  36353. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  36354. };
  36355. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024enc_rand[] = {
  36356. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  36357. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  36358. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  36359. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  36360. };
  36361. #ifdef WOLFSSL_KYBER_ORIGINAL
  36362. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_pk[] = {
  36363. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36364. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36365. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36366. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36367. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36368. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36369. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36370. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36371. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36372. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36373. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36374. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36375. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36376. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36377. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36378. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36379. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36380. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36381. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36382. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36383. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36384. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36385. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36386. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36387. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36388. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36389. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36390. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36391. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36392. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36393. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36394. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36395. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36396. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36397. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36398. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36399. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36400. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36401. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36402. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36403. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36404. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36405. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36406. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36407. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36408. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36409. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  36410. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  36411. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  36412. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  36413. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  36414. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  36415. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36416. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36417. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36418. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36419. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36420. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36421. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36422. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36423. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36424. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36425. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36426. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36427. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36428. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36429. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36430. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36431. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36432. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36433. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36434. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36435. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36436. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36437. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36438. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36439. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36440. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36441. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36442. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36443. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36444. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36445. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36446. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36447. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36448. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36449. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36450. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36451. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36452. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36453. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36454. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36455. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36456. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36457. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36458. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36459. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36460. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36461. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36462. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36463. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36464. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36465. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36466. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36467. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36468. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36469. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36470. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36471. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36472. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36473. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36474. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36475. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36476. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36477. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36478. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36479. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36480. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36481. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36482. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36483. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36484. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36485. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36486. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36487. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36488. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36489. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36490. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36491. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36492. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36493. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36494. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36495. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36496. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36497. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36498. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36499. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36500. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36501. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36502. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36503. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36504. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36505. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36506. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36507. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36508. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36509. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36510. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36511. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36512. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36513. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36514. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36515. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36516. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36517. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36518. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36519. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36520. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36521. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36522. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36523. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36524. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36525. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36526. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36527. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36528. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36529. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36530. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36531. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36532. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36533. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36534. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36535. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36536. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36537. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36538. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36539. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36540. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36541. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36542. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36543. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36544. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36545. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36546. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36547. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36548. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36549. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36550. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36551. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36552. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36553. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36554. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36555. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36556. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36557. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36558. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  36559. };
  36560. #endif
  36561. #ifndef WOLFSSL_NO_ML_KEM
  36562. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_pk[] = {
  36563. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36564. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36565. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36566. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36567. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36568. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36569. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36570. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36571. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36572. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36573. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36574. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36575. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36576. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36577. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36578. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36579. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36580. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36581. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36582. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36583. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36584. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36585. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36586. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36587. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36588. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36589. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36590. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36591. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36592. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36593. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36594. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36595. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36596. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36597. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36598. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36599. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36600. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36601. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36602. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36603. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36604. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36605. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36606. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36607. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36608. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36609. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36610. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36611. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36612. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36613. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36614. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36615. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36616. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36617. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36618. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36619. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36620. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36621. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36622. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36623. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36624. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36625. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36626. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36627. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36628. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36629. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  36630. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  36631. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  36632. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  36633. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  36634. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  36635. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  36636. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  36637. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  36638. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  36639. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  36640. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  36641. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  36642. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  36643. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  36644. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  36645. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  36646. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  36647. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  36648. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  36649. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  36650. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  36651. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  36652. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  36653. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  36654. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  36655. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  36656. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  36657. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  36658. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  36659. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  36660. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  36661. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  36662. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  36663. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  36664. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  36665. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  36666. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  36667. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  36668. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  36669. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  36670. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  36671. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  36672. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  36673. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  36674. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  36675. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  36676. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  36677. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  36678. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  36679. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  36680. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  36681. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  36682. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  36683. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  36684. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  36685. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  36686. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  36687. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  36688. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  36689. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  36690. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  36691. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  36692. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  36693. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  36694. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  36695. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  36696. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  36697. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  36698. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  36699. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  36700. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  36701. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  36702. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  36703. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  36704. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  36705. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  36706. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  36707. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  36708. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  36709. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  36710. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  36711. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  36712. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  36713. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  36714. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  36715. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  36716. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  36717. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  36718. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  36719. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  36720. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  36721. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  36722. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  36723. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  36724. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  36725. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  36726. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  36727. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  36728. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  36729. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  36730. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  36731. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  36732. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  36733. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  36734. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  36735. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  36736. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  36737. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  36738. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  36739. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  36740. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  36741. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  36742. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  36743. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  36744. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  36745. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  36746. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  36747. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  36748. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  36749. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  36750. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  36751. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  36752. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  36753. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  36754. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  36755. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  36756. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  36757. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  36758. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb
  36759. };
  36760. #endif
  36761. #ifdef WOLFSSL_KYBER_ORIGINAL
  36762. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_sk[] = {
  36763. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  36764. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  36765. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  36766. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  36767. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  36768. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  36769. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  36770. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  36771. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  36772. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  36773. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  36774. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  36775. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  36776. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  36777. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  36778. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  36779. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  36780. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  36781. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  36782. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  36783. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  36784. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  36785. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  36786. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  36787. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  36788. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  36789. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  36790. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  36791. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  36792. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  36793. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  36794. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  36795. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  36796. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  36797. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  36798. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  36799. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  36800. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  36801. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  36802. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  36803. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  36804. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  36805. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  36806. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  36807. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  36808. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  36809. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  36810. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  36811. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  36812. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  36813. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  36814. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  36815. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  36816. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  36817. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  36818. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  36819. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  36820. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  36821. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  36822. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  36823. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  36824. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  36825. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  36826. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  36827. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  36828. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  36829. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  36830. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  36831. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  36832. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  36833. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  36834. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  36835. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  36836. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  36837. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  36838. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  36839. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  36840. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  36841. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  36842. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  36843. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  36844. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  36845. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  36846. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  36847. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  36848. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  36849. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  36850. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  36851. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  36852. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  36853. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  36854. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  36855. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  36856. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  36857. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  36858. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  36859. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  36860. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  36861. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  36862. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  36863. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  36864. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  36865. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  36866. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  36867. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  36868. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  36869. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  36870. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  36871. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  36872. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  36873. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  36874. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  36875. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  36876. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  36877. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  36878. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  36879. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  36880. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  36881. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  36882. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  36883. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  36884. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  36885. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  36886. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  36887. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  36888. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  36889. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  36890. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  36891. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  36892. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  36893. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  36894. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  36895. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  36896. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  36897. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  36898. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  36899. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  36900. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  36901. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  36902. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  36903. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  36904. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  36905. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  36906. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  36907. 0x85, 0xA4, 0xC1, 0xA1, 0xAB, 0x9B, 0x6A, 0xEB,
  36908. 0x49, 0xCC, 0xE1, 0xC2, 0xF8, 0xA9, 0x7C, 0x35,
  36909. 0x16, 0xC7, 0x2A, 0x00, 0xA4, 0x62, 0x63, 0xBA,
  36910. 0xA6, 0x96, 0xBF, 0x25, 0x72, 0x77, 0x19, 0xC3,
  36911. 0x21, 0x64, 0x23, 0x61, 0x8F, 0xF3, 0x33, 0x80,
  36912. 0x93, 0x4A, 0x6C, 0x10, 0x54, 0x5C, 0x4C, 0x5C,
  36913. 0x51, 0x55, 0xB1, 0x24, 0x86, 0x18, 0x1F, 0xC7,
  36914. 0xA2, 0x31, 0x98, 0x73, 0x97, 0x8B, 0x6A, 0x2A,
  36915. 0x67, 0x49, 0x0F, 0x82, 0x56, 0xBD, 0x21, 0x96,
  36916. 0xFE, 0x17, 0x92, 0xA4, 0xC0, 0x00, 0x77, 0xB8,
  36917. 0x12, 0xEA, 0xE8, 0xBE, 0xD3, 0x57, 0x24, 0x99,
  36918. 0x68, 0x4A, 0xB3, 0x37, 0x18, 0x76, 0x76, 0x1E,
  36919. 0x45, 0x0C, 0x9F, 0x9D, 0x27, 0x68, 0xA3, 0x68,
  36920. 0x06, 0xD7, 0xAB, 0x20, 0x46, 0xC9, 0x1F, 0x17,
  36921. 0x59, 0x9E, 0x9A, 0xC5, 0x92, 0x99, 0x08, 0x08,
  36922. 0xDC, 0xD7, 0xB4, 0xD0, 0x91, 0x90, 0x72, 0xF1,
  36923. 0x4E, 0xC3, 0x61, 0x77, 0x3B, 0x72, 0x52, 0x44,
  36924. 0x4C, 0x32, 0x3C, 0x30, 0x83, 0x26, 0xF4, 0xA3,
  36925. 0x0F, 0x86, 0x80, 0xD2, 0xF7, 0x48, 0xF5, 0x6A,
  36926. 0x13, 0x2B, 0x82, 0x67, 0x4E, 0xD0, 0x18, 0x46,
  36927. 0x20, 0xB8, 0x2A, 0xD2, 0xCB, 0x18, 0x2C, 0x97,
  36928. 0xB4, 0x81, 0x62, 0x66, 0x47, 0x49, 0x12, 0x90,
  36929. 0xA0, 0x11, 0xCC, 0x73, 0x82, 0x86, 0x85, 0xA8,
  36930. 0xC3, 0x67, 0xA5, 0xB9, 0xCF, 0x8D, 0x62, 0x1B,
  36931. 0x0D, 0x5C, 0x1E, 0xFF, 0x03, 0x17, 0x27, 0x58,
  36932. 0xBD, 0x00, 0x49, 0x78, 0xC2, 0x51, 0xCD, 0x51,
  36933. 0x34, 0x22, 0x28, 0x98, 0x9C, 0xAE, 0x63, 0x32,
  36934. 0xAC, 0x48, 0x64, 0x37, 0xCB, 0x5C, 0x57, 0xD4,
  36935. 0x30, 0x74, 0x62, 0x86, 0x52, 0x53, 0xBE, 0x21,
  36936. 0x7B, 0x35, 0x15, 0xC7, 0x3D, 0xF4, 0x05, 0xB7,
  36937. 0xF2, 0x82, 0x17, 0xAD, 0x0B, 0x8C, 0xF6, 0x0C,
  36938. 0x2F, 0xFF, 0xAA, 0x0A, 0x00, 0x48, 0xB1, 0xFB,
  36939. 0x4A, 0xCD, 0xCD, 0xC3, 0x8B, 0x52, 0x50, 0xCF,
  36940. 0xEC, 0x35, 0x6A, 0x6D, 0xE2, 0x6C, 0xFA, 0x7A,
  36941. 0x58, 0x8F, 0xDC, 0x86, 0xF9, 0x8C, 0x85, 0x4A,
  36942. 0xC6, 0x4C, 0x7B, 0xFA, 0xA9, 0x6F, 0x5A, 0x32,
  36943. 0xCC, 0x06, 0x10, 0x93, 0x4B, 0xAA, 0x6A, 0x58,
  36944. 0x6B, 0x9A, 0x20, 0x54, 0xF1, 0x3B, 0xA2, 0x74,
  36945. 0x17, 0x4A, 0xA0, 0xD2, 0xB3, 0xA8, 0x1B, 0x96,
  36946. 0xA9, 0x40, 0x66, 0x6F, 0x78, 0x9B, 0x5A, 0x6B,
  36947. 0xCD, 0xC0, 0xA6, 0xA0, 0x17, 0x8A, 0x0C, 0x9A,
  36948. 0x02, 0x57, 0x8A, 0x49, 0x3F, 0x6E, 0xEA, 0x0D,
  36949. 0x2E, 0x6C, 0x13, 0x95, 0x1C, 0x9F, 0x24, 0x9A,
  36950. 0x5E, 0x8D, 0xD7, 0x1D, 0xD4, 0x9A, 0x74, 0x2D,
  36951. 0x45, 0x1F, 0x1A, 0xBB, 0xA1, 0x9A, 0xF8, 0xC5,
  36952. 0x47, 0x85, 0x5E, 0x0A, 0xFC, 0x72, 0x8E, 0x90,
  36953. 0xAB, 0xB4, 0x99, 0xC9, 0xBE, 0xEB, 0x76, 0x6F,
  36954. 0x47, 0x29, 0xCD, 0xA2, 0x22, 0x63, 0xE3, 0x24,
  36955. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36956. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36957. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36958. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36959. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36960. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36961. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36962. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36963. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36964. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36965. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36966. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36967. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36968. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36969. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36970. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36971. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36972. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36973. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36974. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36975. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36976. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36977. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36978. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36979. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36980. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36981. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36982. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36983. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36984. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36985. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36986. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36987. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36988. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36989. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36990. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36991. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36992. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36993. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36994. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36995. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36996. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36997. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36998. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36999. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  37000. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  37001. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  37002. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  37003. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  37004. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  37005. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  37006. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  37007. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  37008. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  37009. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  37010. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  37011. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  37012. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  37013. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  37014. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  37015. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  37016. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  37017. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  37018. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  37019. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  37020. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  37021. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  37022. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  37023. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  37024. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  37025. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  37026. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  37027. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  37028. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  37029. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  37030. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  37031. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  37032. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  37033. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  37034. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  37035. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  37036. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  37037. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  37038. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  37039. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  37040. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  37041. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  37042. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  37043. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  37044. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  37045. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  37046. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  37047. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  37048. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  37049. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  37050. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  37051. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  37052. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  37053. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  37054. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  37055. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  37056. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  37057. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  37058. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  37059. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  37060. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  37061. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  37062. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  37063. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  37064. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  37065. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  37066. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  37067. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  37068. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  37069. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  37070. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  37071. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  37072. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  37073. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  37074. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  37075. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  37076. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  37077. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  37078. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  37079. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  37080. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  37081. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  37082. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  37083. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  37084. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  37085. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  37086. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  37087. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  37088. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  37089. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  37090. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  37091. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  37092. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  37093. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  37094. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  37095. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  37096. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  37097. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  37098. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  37099. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  37100. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  37101. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  37102. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  37103. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  37104. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  37105. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  37106. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  37107. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  37108. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  37109. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  37110. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  37111. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  37112. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  37113. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  37114. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  37115. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  37116. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  37117. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  37118. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  37119. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  37120. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  37121. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  37122. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  37123. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  37124. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  37125. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  37126. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  37127. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  37128. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  37129. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  37130. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  37131. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  37132. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  37133. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  37134. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  37135. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  37136. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  37137. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  37138. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  37139. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  37140. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  37141. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  37142. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  37143. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  37144. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  37145. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  37146. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  37147. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  37148. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  37149. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  37150. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  37151. 0x8A, 0x39, 0xE8, 0x7D, 0x53, 0x1F, 0x35, 0x27,
  37152. 0xC2, 0x07, 0xED, 0xCC, 0x1D, 0xB7, 0xFA, 0xDD,
  37153. 0xCF, 0x96, 0x28, 0x39, 0x18, 0x79, 0xB3, 0x35,
  37154. 0xC7, 0x07, 0x83, 0x9A, 0x0D, 0xB0, 0x51, 0xA8,
  37155. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  37156. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  37157. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  37158. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  37159. };
  37160. #endif
  37161. #ifndef WOLFSSL_NO_ML_KEM
  37162. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_sk[] = {
  37163. 0x43, 0x3a, 0x70, 0xee, 0x69, 0x50, 0xf9, 0x88,
  37164. 0x2a, 0xcd, 0xd5, 0xa4, 0x78, 0x20, 0xa6, 0xa8,
  37165. 0x16, 0x37, 0x08, 0xf0, 0x4d, 0x45, 0x7c, 0x77,
  37166. 0x99, 0x79, 0xb8, 0x3f, 0xe1, 0x17, 0x22, 0x47,
  37167. 0x01, 0x49, 0x08, 0x30, 0x38, 0x66, 0x37, 0xda,
  37168. 0x33, 0x2e, 0x74, 0xb1, 0xae, 0xda, 0x0b, 0x2f,
  37169. 0x81, 0xca, 0x4f, 0x9b, 0xb2, 0xc2, 0xb0, 0x2b,
  37170. 0x0c, 0xfd, 0x68, 0x0c, 0x11, 0x48, 0x2f, 0x33,
  37171. 0x5a, 0xcf, 0x7b, 0x91, 0x39, 0xb5, 0xb8, 0x8a,
  37172. 0x34, 0xe3, 0x54, 0x2c, 0x68, 0x61, 0x37, 0x75,
  37173. 0x45, 0x98, 0x33, 0x43, 0xcd, 0x82, 0x94, 0x14,
  37174. 0xe4, 0x78, 0x64, 0x21, 0x2e, 0x78, 0xf8, 0x55,
  37175. 0xf5, 0x23, 0x90, 0x37, 0x9a, 0xcc, 0x3a, 0x62,
  37176. 0x95, 0x31, 0x31, 0xb6, 0x3e, 0xe8, 0x32, 0xad,
  37177. 0xb3, 0xbf, 0x4b, 0xf5, 0x8e, 0x24, 0x73, 0x49,
  37178. 0xb5, 0xe0, 0x97, 0xe5, 0x5a, 0xbe, 0x49, 0x7b,
  37179. 0x15, 0x98, 0x23, 0x73, 0xae, 0x73, 0x2e, 0x04,
  37180. 0x39, 0xac, 0x67, 0xd0, 0x5c, 0x7f, 0x03, 0x7c,
  37181. 0x8a, 0x73, 0x9b, 0x18, 0x14, 0x0e, 0x14, 0x4c,
  37182. 0x85, 0x1d, 0xc9, 0x61, 0x1f, 0x4b, 0xcf, 0x04,
  37183. 0xf3, 0xa2, 0x09, 0x3c, 0x19, 0x7b, 0xd6, 0x3b,
  37184. 0xb5, 0xe6, 0x19, 0x01, 0x00, 0x54, 0x5f, 0xf8,
  37185. 0x1d, 0xb7, 0xfc, 0xcd, 0xdd, 0x9a, 0x32, 0x4b,
  37186. 0x0b, 0xac, 0x3c, 0x2c, 0x23, 0x82, 0x28, 0x40,
  37187. 0x58, 0xf0, 0x8b, 0x96, 0x19, 0x52, 0xc0, 0x94,
  37188. 0x01, 0x9c, 0x10, 0xbe, 0x37, 0xa5, 0x3d, 0x5a,
  37189. 0xc7, 0x94, 0xc0, 0x10, 0xa9, 0xd0, 0x82, 0x1f,
  37190. 0x15, 0x02, 0x7a, 0x1c, 0x41, 0x9c, 0x3c, 0x71,
  37191. 0xc9, 0xa1, 0xd2, 0x8a, 0xed, 0x02, 0x59, 0x7a,
  37192. 0xb7, 0x9b, 0x87, 0x53, 0x94, 0x62, 0x6b, 0xa3,
  37193. 0x9a, 0xdc, 0x09, 0x0c, 0x3a, 0x90, 0xcf, 0x75,
  37194. 0x87, 0x1a, 0x65, 0x27, 0x5e, 0xb1, 0xc5, 0xb0,
  37195. 0x33, 0x72, 0xe1, 0x3a, 0x1a, 0x23, 0xd0, 0xcf,
  37196. 0x93, 0x74, 0x11, 0x1f, 0x80, 0xcc, 0x83, 0xa9,
  37197. 0x05, 0x62, 0x2b, 0x83, 0xfc, 0x51, 0x39, 0x71,
  37198. 0xec, 0x84, 0x19, 0xf0, 0x88, 0x0c, 0x30, 0x67,
  37199. 0x63, 0x36, 0x71, 0xb0, 0x9b, 0x54, 0x56, 0xab,
  37200. 0x60, 0x57, 0x93, 0x6d, 0x19, 0xa4, 0xa2, 0xa2,
  37201. 0x67, 0x91, 0x1b, 0x00, 0x0a, 0x13, 0x95, 0x6f,
  37202. 0xbd, 0x49, 0x38, 0x21, 0xda, 0x07, 0x2c, 0x04,
  37203. 0x64, 0x2b, 0x0c, 0x20, 0xda, 0x6c, 0xc0, 0xd9,
  37204. 0xd8, 0x64, 0xa3, 0x93, 0x65, 0xdf, 0xd6, 0x4f,
  37205. 0x10, 0x18, 0x78, 0x25, 0xfa, 0x33, 0x25, 0x07,
  37206. 0x49, 0xcb, 0xc0, 0xc9, 0x05, 0xd7, 0xb1, 0xff,
  37207. 0x3c, 0xae, 0x24, 0x12, 0xbf, 0x86, 0xb8, 0x1a,
  37208. 0x81, 0x7b, 0x86, 0xba, 0xa3, 0x0e, 0xdf, 0x78,
  37209. 0x62, 0xe5, 0xf6, 0xba, 0xc9, 0x87, 0x26, 0xe5,
  37210. 0x6b, 0x3c, 0xec, 0x60, 0x66, 0x4c, 0xaa, 0x2a,
  37211. 0x7d, 0xf6, 0x70, 0xc5, 0xe2, 0x07, 0xdf, 0xac,
  37212. 0x03, 0x82, 0x4c, 0x89, 0x89, 0x7c, 0xb4, 0x90,
  37213. 0xea, 0xa7, 0x65, 0x21, 0x22, 0x2c, 0x86, 0x20,
  37214. 0x51, 0x69, 0xc9, 0x1c, 0x32, 0x9c, 0x4a, 0x18,
  37215. 0x4d, 0x78, 0x72, 0x1a, 0xf8, 0x36, 0xad, 0x4d,
  37216. 0xb0, 0xca, 0x78, 0x46, 0x4d, 0x41, 0x71, 0x47,
  37217. 0x30, 0x12, 0xb7, 0xd1, 0x83, 0xba, 0xfa, 0x62,
  37218. 0x75, 0x85, 0xc6, 0x4b, 0xe3, 0x80, 0x9d, 0x7e,
  37219. 0x60, 0x04, 0xcb, 0xdc, 0x79, 0xa5, 0x46, 0x0f,
  37220. 0x0a, 0xd6, 0x77, 0xcb, 0x71, 0x65, 0x12, 0x40,
  37221. 0x7d, 0x3a, 0x61, 0x9a, 0xd0, 0x95, 0x43, 0xb7,
  37222. 0x39, 0x54, 0x74, 0x72, 0xa7, 0x06, 0xb3, 0x17,
  37223. 0xa5, 0x09, 0xbe, 0x5d, 0x86, 0x1f, 0xd6, 0x6c,
  37224. 0x7d, 0x0e, 0xd9, 0x4c, 0xd5, 0x00, 0x47, 0x95,
  37225. 0xc1, 0x81, 0x59, 0xe3, 0xa3, 0x3d, 0x79, 0x87,
  37226. 0x11, 0x52, 0x5f, 0x16, 0x35, 0xa6, 0x84, 0x28,
  37227. 0x17, 0x29, 0x23, 0x24, 0x96, 0x35, 0xaa, 0xd0,
  37228. 0x32, 0xb9, 0xe5, 0x66, 0x64, 0xbd, 0xd4, 0x8e,
  37229. 0xd2, 0x4a, 0xc7, 0x5c, 0x64, 0x68, 0xd1, 0x90,
  37230. 0x3e, 0x47, 0x10, 0x86, 0xc5, 0xf1, 0x56, 0x7e,
  37231. 0x83, 0x1a, 0x05, 0x08, 0xc5, 0x39, 0x63, 0x25,
  37232. 0x91, 0xab, 0x57, 0x7d, 0x32, 0x4a, 0x82, 0x42,
  37233. 0x97, 0x25, 0x80, 0x99, 0x50, 0x76, 0x1d, 0x84,
  37234. 0x34, 0x28, 0x8c, 0x14, 0x03, 0x4f, 0x1c, 0x06,
  37235. 0xc1, 0xd0, 0xaa, 0xe0, 0x9a, 0x71, 0xc7, 0x40,
  37236. 0xa5, 0x57, 0x01, 0xc2, 0x8f, 0xf8, 0x44, 0x99,
  37237. 0xf2, 0xbb, 0x18, 0xb6, 0x62, 0x8c, 0xaa, 0xa3,
  37238. 0xfe, 0x75, 0xac, 0x4d, 0xe0, 0x4c, 0x6f, 0x91,
  37239. 0x39, 0x00, 0xd8, 0x6c, 0x88, 0x12, 0x62, 0x52,
  37240. 0xa1, 0x7c, 0x4d, 0x30, 0x39, 0x91, 0xdb, 0x02,
  37241. 0x87, 0x12, 0x08, 0x81, 0xbb, 0x88, 0x47, 0x8a,
  37242. 0xaa, 0x9a, 0xf9, 0xbc, 0x53, 0xd3, 0x72, 0x98,
  37243. 0x43, 0x85, 0x8f, 0xdb, 0x46, 0x48, 0x05, 0x9c,
  37244. 0xac, 0x82, 0xc1, 0xa1, 0x08, 0x78, 0xba, 0x39,
  37245. 0x82, 0x3b, 0x04, 0x1b, 0xd0, 0xe2, 0x58, 0x48,
  37246. 0x7b, 0x56, 0xcc, 0x8a, 0x32, 0x20, 0xc1, 0xa5,
  37247. 0x8b, 0xf6, 0x6a, 0x17, 0x2b, 0x5b, 0x9a, 0x0c,
  37248. 0x63, 0x2d, 0x67, 0x4e, 0xae, 0x88, 0x5a, 0x01,
  37249. 0x5c, 0x4e, 0x37, 0xba, 0x07, 0x36, 0x80, 0xbe,
  37250. 0xde, 0x75, 0x34, 0xf3, 0xe3, 0x4b, 0x60, 0x50,
  37251. 0xc8, 0x6b, 0x21, 0xc3, 0xc0, 0x90, 0x94, 0x1f,
  37252. 0x23, 0xb7, 0xf6, 0x73, 0x1e, 0x2b, 0xda, 0x0e,
  37253. 0x6e, 0xa4, 0x64, 0x67, 0x71, 0xce, 0xc5, 0x72,
  37254. 0xb9, 0x8c, 0xa0, 0xa1, 0x58, 0x91, 0x9a, 0xdb,
  37255. 0xeb, 0x84, 0xce, 0x58, 0x5f, 0xf9, 0xf2, 0x5e,
  37256. 0xbd, 0xda, 0x6c, 0xb6, 0xf0, 0x7a, 0x8f, 0x81,
  37257. 0x12, 0x32, 0x60, 0x7e, 0x72, 0x17, 0xbb, 0x03,
  37258. 0x9b, 0xab, 0xd0, 0xd9, 0x19, 0x34, 0xa8, 0x59,
  37259. 0x40, 0x59, 0xc9, 0x68, 0x77, 0x23, 0xc0, 0x43,
  37260. 0x81, 0xbf, 0xd6, 0x27, 0xa1, 0x05, 0x17, 0xf5,
  37261. 0xf4, 0xbf, 0xc7, 0x77, 0x77, 0xaa, 0x26, 0x71,
  37262. 0xae, 0x12, 0x4f, 0x2b, 0x7a, 0x5f, 0x4d, 0x56,
  37263. 0x14, 0x02, 0x91, 0x97, 0xe6, 0x58, 0x6f, 0xa8,
  37264. 0xc1, 0x7e, 0x0a, 0xd9, 0x07, 0x81, 0xbc, 0x7b,
  37265. 0xb1, 0x9a, 0x77, 0x2d, 0x5a, 0x4e, 0xfe, 0x32,
  37266. 0xca, 0xc8, 0x9b, 0x76, 0xc4, 0x2a, 0x5e, 0xde,
  37267. 0x9b, 0xcc, 0x20, 0xc1, 0x89, 0x8c, 0x08, 0xa5,
  37268. 0xb0, 0xc0, 0x7e, 0x47, 0x8b, 0x1b, 0xbc, 0x22,
  37269. 0x6e, 0xfa, 0xd1, 0x5f, 0x2a, 0xc7, 0x37, 0x51,
  37270. 0x4b, 0x8c, 0x61, 0x49, 0x81, 0x07, 0x79, 0x22,
  37271. 0x24, 0x16, 0x53, 0x7e, 0xd0, 0x0d, 0xae, 0xab,
  37272. 0x17, 0x7e, 0x90, 0x3e, 0xad, 0x6b, 0x4a, 0xc4,
  37273. 0x23, 0x70, 0xaf, 0x1b, 0x1f, 0x50, 0xeb, 0xaf,
  37274. 0xaa, 0x1c, 0x6e, 0x64, 0x7b, 0xba, 0xcc, 0xe7,
  37275. 0x2c, 0x7d, 0x0b, 0x88, 0xae, 0xb0, 0xb0, 0x6f,
  37276. 0xc1, 0xa4, 0x54, 0x57, 0xa9, 0xc1, 0x87, 0x57,
  37277. 0x9b, 0xf1, 0x84, 0x57, 0x9c, 0xc3, 0x51, 0xc4,
  37278. 0x3d, 0xff, 0x94, 0x26, 0x05, 0xaa, 0x56, 0x04,
  37279. 0xfc, 0x85, 0xfc, 0x55, 0x83, 0xf6, 0xf1, 0x49,
  37280. 0x6f, 0xe6, 0x1d, 0x70, 0xd6, 0xcd, 0xe2, 0x32,
  37281. 0x7f, 0xee, 0x71, 0x3d, 0x86, 0xf2, 0x9b, 0x3a,
  37282. 0xfc, 0xbb, 0x54, 0xe9, 0xa9, 0x2a, 0x33, 0xa6,
  37283. 0xc1, 0xea, 0x6f, 0xfa, 0x30, 0x95, 0x66, 0xb0,
  37284. 0x68, 0x62, 0x33, 0xc0, 0xf3, 0xb1, 0xc3, 0x14,
  37285. 0x48, 0x90, 0xe4, 0xf0, 0x82, 0x9a, 0x60, 0x99,
  37286. 0xc5, 0x74, 0x9c, 0xde, 0xc8, 0x43, 0x28, 0xec,
  37287. 0x2c, 0xb6, 0x4a, 0x73, 0x85, 0xa7, 0x61, 0xd6,
  37288. 0x4b, 0x3a, 0x23, 0xc4, 0x89, 0x34, 0x33, 0x43,
  37289. 0xb9, 0x77, 0x23, 0xae, 0x78, 0xc7, 0xd8, 0x05,
  37290. 0x45, 0x8e, 0x16, 0x20, 0xf0, 0x29, 0x28, 0x97,
  37291. 0x69, 0x17, 0x04, 0xcb, 0x76, 0xe3, 0xb0, 0xb2,
  37292. 0x81, 0xa8, 0x3c, 0xf6, 0x44, 0x90, 0x49, 0x8c,
  37293. 0xbc, 0xaf, 0x04, 0x80, 0x24, 0x16, 0xb3, 0x3c,
  37294. 0x56, 0x51, 0x71, 0xd7, 0x72, 0xd3, 0xb9, 0x35,
  37295. 0x40, 0x37, 0x58, 0x76, 0x29, 0xae, 0x14, 0xa5,
  37296. 0xc5, 0x03, 0x1a, 0xc3, 0x66, 0x71, 0xa0, 0xd0,
  37297. 0xc9, 0x1c, 0xc0, 0xb4, 0xcd, 0x69, 0xd8, 0x40,
  37298. 0x2e, 0x33, 0xb9, 0xbc, 0xc2, 0xbb, 0xaf, 0x6b,
  37299. 0x97, 0x1e, 0x30, 0x3f, 0xa1, 0x37, 0xbe, 0x23,
  37300. 0x25, 0x98, 0xa4, 0x99, 0x9b, 0xc0, 0x12, 0x57,
  37301. 0x4c, 0x81, 0x65, 0x1b, 0x38, 0xb3, 0x83, 0x96,
  37302. 0xc1, 0xc3, 0x65, 0x30, 0x3a, 0xd2, 0x5d, 0x49,
  37303. 0xfc, 0x6b, 0x68, 0x99, 0x51, 0xa1, 0xcc, 0x4c,
  37304. 0x60, 0x07, 0x61, 0x30, 0x65, 0x49, 0x5f, 0x97,
  37305. 0x91, 0x0f, 0x97, 0x35, 0xd4, 0xea, 0x4e, 0x44,
  37306. 0x2a, 0xcb, 0x2f, 0xab, 0xae, 0xcf, 0xe1, 0xad,
  37307. 0xef, 0x06, 0x67, 0xba, 0x42, 0x2c, 0x95, 0x4a,
  37308. 0x05, 0xd1, 0xb6, 0x16, 0x7a, 0x26, 0x3e, 0x12,
  37309. 0x75, 0xc6, 0xad, 0xa8, 0x38, 0x59, 0x65, 0x30,
  37310. 0x4b, 0x30, 0x32, 0x40, 0x40, 0x54, 0x2c, 0xf5,
  37311. 0xa4, 0x51, 0xbc, 0xaf, 0xc7, 0x47, 0x88, 0xbe,
  37312. 0x3b, 0x9b, 0x9f, 0xcc, 0x45, 0xd4, 0x79, 0x0e,
  37313. 0x2d, 0x73, 0x35, 0xc6, 0x0a, 0x14, 0xf0, 0xa4,
  37314. 0x9d, 0x13, 0x05, 0x3f, 0x26, 0x26, 0xa6, 0x27,
  37315. 0xca, 0x19, 0x55, 0x3c, 0xb3, 0x36, 0xa2, 0xcb,
  37316. 0x4a, 0x45, 0x5d, 0x8e, 0xf3, 0x98, 0x94, 0x91,
  37317. 0x47, 0x2b, 0xa0, 0x05, 0x1e, 0xf7, 0x41, 0x6e,
  37318. 0x0b, 0xbf, 0x1a, 0x61, 0x08, 0xfa, 0x07, 0xc1,
  37319. 0x61, 0x54, 0x8e, 0x7c, 0x62, 0x33, 0x1a, 0xe5,
  37320. 0xa2, 0xb4, 0xe4, 0xa1, 0x08, 0xa5, 0x10, 0x93,
  37321. 0xd3, 0x15, 0x08, 0x21, 0xa2, 0xfb, 0x54, 0x71,
  37322. 0x70, 0xa1, 0xb7, 0x3c, 0x43, 0xc5, 0x50, 0xc6,
  37323. 0x55, 0x7a, 0x40, 0x48, 0xa5, 0x8a, 0x2c, 0xd7,
  37324. 0x7a, 0x24, 0x42, 0x34, 0xb2, 0x23, 0x51, 0x75,
  37325. 0xa0, 0x89, 0x7d, 0x50, 0x61, 0xb4, 0x61, 0x34,
  37326. 0x82, 0xdc, 0x13, 0x64, 0x14, 0x04, 0x8c, 0x11,
  37327. 0xdb, 0x37, 0xea, 0xe0, 0xa5, 0xdf, 0x87, 0xc1,
  37328. 0x93, 0x14, 0xb0, 0xe8, 0x23, 0x97, 0xa0, 0xd3,
  37329. 0x38, 0xdc, 0x21, 0x53, 0x8a, 0xf3, 0x61, 0x49,
  37330. 0xd9, 0x3f, 0x8b, 0x1a, 0x11, 0xc5, 0x3b, 0xb5,
  37331. 0xde, 0xf8, 0xb7, 0xa2, 0xcc, 0xa3, 0x36, 0x2b,
  37332. 0x7f, 0xe3, 0xa1, 0x40, 0x8a, 0x25, 0x47, 0xe2,
  37333. 0x09, 0x05, 0x8c, 0x67, 0x3a, 0x75, 0x66, 0xc2,
  37334. 0x61, 0x23, 0xa6, 0xd8, 0xb6, 0x92, 0xa5, 0xf3,
  37335. 0x3e, 0xbd, 0xcb, 0x26, 0x24, 0xb7, 0x9d, 0x87,
  37336. 0x7b, 0xce, 0x5f, 0xa1, 0x4e, 0x42, 0xe8, 0x3f,
  37337. 0xaa, 0xd8, 0x2e, 0x99, 0x00, 0x55, 0x3a, 0x3c,
  37338. 0x60, 0x45, 0xca, 0x32, 0x9f, 0xea, 0x4a, 0x50,
  37339. 0x65, 0x58, 0xc4, 0x91, 0xb6, 0xa6, 0x16, 0xc6,
  37340. 0xfd, 0x40, 0x0b, 0x42, 0x13, 0x6f, 0x44, 0xcb,
  37341. 0x0d, 0x02, 0x57, 0x65, 0x08, 0x19, 0x01, 0x8d,
  37342. 0x3c, 0x56, 0x8e, 0xf6, 0xc6, 0x0c, 0x6c, 0x40,
  37343. 0x9e, 0x70, 0xa8, 0x29, 0x28, 0x71, 0x08, 0xc1,
  37344. 0xb6, 0xa4, 0xd3, 0x2f, 0x76, 0xe5, 0xcc, 0x4d,
  37345. 0x10, 0x4b, 0x02, 0x43, 0x8e, 0xf7, 0xa4, 0x67,
  37346. 0x91, 0x23, 0x98, 0xea, 0x9c, 0x7c, 0xbd, 0x99,
  37347. 0x81, 0x58, 0x9a, 0x34, 0x18, 0x97, 0x68, 0x7b,
  37348. 0x51, 0x6a, 0x13, 0x30, 0x7d, 0x66, 0xc0, 0x68,
  37349. 0xc4, 0x44, 0xb4, 0xb9, 0x49, 0xa1, 0x74, 0x12,
  37350. 0x41, 0x33, 0x15, 0xcc, 0xf4, 0x9b, 0x99, 0x98,
  37351. 0x00, 0x34, 0xb5, 0xb8, 0xcf, 0xde, 0xc4, 0xa6,
  37352. 0x0b, 0x9c, 0x1e, 0x74, 0x55, 0xaa, 0xfb, 0xf3,
  37353. 0xa7, 0x57, 0x34, 0x69, 0x90, 0xcc, 0x32, 0xb0,
  37354. 0x59, 0x9b, 0xa2, 0x17, 0xa6, 0xc5, 0xfc, 0x39,
  37355. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  37356. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  37357. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  37358. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  37359. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  37360. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  37361. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  37362. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  37363. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  37364. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  37365. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  37366. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  37367. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  37368. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  37369. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  37370. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  37371. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  37372. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  37373. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  37374. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  37375. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  37376. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  37377. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  37378. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  37379. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  37380. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  37381. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  37382. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  37383. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  37384. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  37385. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  37386. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  37387. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  37388. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  37389. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  37390. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  37391. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  37392. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  37393. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  37394. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  37395. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  37396. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  37397. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  37398. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  37399. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  37400. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  37401. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  37402. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  37403. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  37404. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  37405. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  37406. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  37407. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  37408. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  37409. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  37410. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  37411. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  37412. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  37413. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  37414. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  37415. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  37416. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  37417. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  37418. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  37419. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  37420. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  37421. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  37422. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  37423. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  37424. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  37425. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  37426. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  37427. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  37428. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  37429. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  37430. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  37431. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  37432. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  37433. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  37434. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  37435. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  37436. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  37437. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  37438. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  37439. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  37440. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  37441. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  37442. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  37443. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  37444. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  37445. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  37446. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  37447. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  37448. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  37449. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  37450. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  37451. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  37452. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  37453. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  37454. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  37455. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  37456. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  37457. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  37458. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  37459. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  37460. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  37461. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  37462. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  37463. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  37464. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  37465. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  37466. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  37467. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  37468. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  37469. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  37470. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  37471. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  37472. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  37473. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  37474. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  37475. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  37476. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  37477. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  37478. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  37479. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  37480. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  37481. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  37482. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  37483. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  37484. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  37485. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  37486. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  37487. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  37488. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  37489. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  37490. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  37491. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  37492. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  37493. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  37494. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  37495. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  37496. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  37497. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  37498. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  37499. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  37500. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  37501. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  37502. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  37503. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  37504. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  37505. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  37506. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  37507. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  37508. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  37509. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  37510. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  37511. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  37512. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  37513. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  37514. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  37515. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  37516. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  37517. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  37518. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  37519. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  37520. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  37521. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  37522. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  37523. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  37524. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  37525. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  37526. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  37527. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  37528. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  37529. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  37530. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  37531. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  37532. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  37533. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  37534. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  37535. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  37536. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  37537. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  37538. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  37539. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  37540. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  37541. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  37542. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  37543. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  37544. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  37545. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  37546. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  37547. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  37548. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  37549. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  37550. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb,
  37551. 0xeb, 0xbe, 0x41, 0xcd, 0x4d, 0xea, 0x48, 0x9d,
  37552. 0xed, 0xd0, 0x0e, 0x76, 0xae, 0x0b, 0xcf, 0x54,
  37553. 0xaa, 0x85, 0x50, 0x20, 0x29, 0x20, 0xeb, 0x64,
  37554. 0xd5, 0x89, 0x2a, 0xd0, 0x2b, 0x13, 0xf2, 0xe5,
  37555. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  37556. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  37557. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  37558. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  37559. };
  37560. #endif
  37561. #ifdef WOLFSSL_KYBER_ORIGINAL
  37562. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ct[] = {
  37563. 0xA6, 0xAF, 0x29, 0xD5, 0xF5, 0xB8, 0x0B, 0xD1,
  37564. 0x30, 0xF5, 0x18, 0xBA, 0xDD, 0xD6, 0xC8, 0xF1,
  37565. 0x75, 0x45, 0x41, 0x3D, 0x86, 0x0F, 0xB3, 0xDE,
  37566. 0x45, 0x19, 0x79, 0xEB, 0xFA, 0x5E, 0x4E, 0x31,
  37567. 0x12, 0xC7, 0xC0, 0xAD, 0xF9, 0x98, 0x24, 0xBB,
  37568. 0x52, 0x6F, 0x2C, 0x35, 0x50, 0x74, 0x8E, 0xD0,
  37569. 0xE1, 0x34, 0xF0, 0x45, 0x7A, 0x7C, 0x61, 0xF9,
  37570. 0xF5, 0x26, 0xF0, 0x02, 0xBA, 0xAD, 0xC0, 0x3F,
  37571. 0xC1, 0x3E, 0x38, 0x13, 0x12, 0x19, 0x51, 0x3C,
  37572. 0x3E, 0xDE, 0x06, 0x16, 0x61, 0xE7, 0x4F, 0x60,
  37573. 0x3C, 0x4F, 0xCF, 0x79, 0x51, 0xC8, 0xE5, 0x2C,
  37574. 0x9C, 0x21, 0x3B, 0x0D, 0x22, 0xD9, 0x29, 0x36,
  37575. 0x63, 0xD6, 0x69, 0xA6, 0xB5, 0x8E, 0xD8, 0xFC,
  37576. 0xEF, 0xCF, 0x82, 0x49, 0xD7, 0xBB, 0x52, 0x98,
  37577. 0xF5, 0x57, 0x61, 0x44, 0x5B, 0x2B, 0x83, 0xCE,
  37578. 0x7F, 0x00, 0x5C, 0xB0, 0x42, 0x48, 0xAE, 0xC8,
  37579. 0xBD, 0xA2, 0x2F, 0xD2, 0xD4, 0x2A, 0xA7, 0x66,
  37580. 0x32, 0x20, 0x14, 0xEA, 0x03, 0x8C, 0xC3, 0x2C,
  37581. 0x55, 0xC8, 0xE4, 0xB9, 0xE2, 0x8E, 0xC9, 0x11,
  37582. 0x9F, 0x52, 0x73, 0x41, 0xE4, 0xF6, 0x6A, 0x03,
  37583. 0x51, 0x21, 0x07, 0x3B, 0x85, 0xDE, 0x67, 0x06,
  37584. 0xDA, 0x19, 0xE0, 0x83, 0x8A, 0x9F, 0x33, 0xB7,
  37585. 0x19, 0xA6, 0x8F, 0x03, 0x9B, 0x66, 0x4D, 0xC0,
  37586. 0x02, 0x65, 0x9E, 0xAB, 0xFC, 0x39, 0x86, 0x79,
  37587. 0xAA, 0x70, 0x09, 0xCE, 0x0C, 0xD0, 0x1C, 0xDA,
  37588. 0xFB, 0x6C, 0xD2, 0xA2, 0x6F, 0xE4, 0x10, 0x16,
  37589. 0x72, 0xC9, 0x8F, 0xF5, 0x8F, 0x7C, 0x47, 0xD5,
  37590. 0xBD, 0xA2, 0x90, 0x66, 0x53, 0xB3, 0xA6, 0xF9,
  37591. 0x65, 0x1F, 0x7A, 0x12, 0x1E, 0xA7, 0x7E, 0xA7,
  37592. 0x47, 0x23, 0xFA, 0xE5, 0xB8, 0x73, 0xF9, 0xBB,
  37593. 0x7B, 0x66, 0x4F, 0x0C, 0x8A, 0x93, 0x83, 0x1E,
  37594. 0xF9, 0xD5, 0x1C, 0x7C, 0xC1, 0xEF, 0x44, 0xAC,
  37595. 0x0E, 0x55, 0xA5, 0x5C, 0xA7, 0x6D, 0x13, 0x7F,
  37596. 0xE9, 0xB7, 0x5F, 0x40, 0x50, 0x9C, 0xEF, 0x15,
  37597. 0x6E, 0x5A, 0xD1, 0x8F, 0x9F, 0xB9, 0x99, 0x68,
  37598. 0x00, 0x08, 0xE5, 0x47, 0xD5, 0x5E, 0xEC, 0xD5,
  37599. 0xB4, 0xD1, 0xCB, 0x1D, 0x9F, 0x07, 0x6C, 0xEC,
  37600. 0x21, 0x50, 0x1C, 0x74, 0x02, 0x50, 0x9E, 0xCB,
  37601. 0x77, 0xAF, 0xB2, 0xCB, 0x9A, 0x61, 0x34, 0x0A,
  37602. 0x8B, 0xD1, 0x51, 0x4C, 0x6E, 0x71, 0xB4, 0xAA,
  37603. 0x45, 0xE4, 0x7E, 0xC3, 0x75, 0x12, 0x27, 0x1B,
  37604. 0x91, 0x1F, 0x8F, 0xB4, 0x6C, 0x90, 0x82, 0xC9,
  37605. 0xDF, 0x07, 0x20, 0x4A, 0xBB, 0x5A, 0x50, 0xE6,
  37606. 0xE3, 0x64, 0x7A, 0x8A, 0xD4, 0xD8, 0xD5, 0xD7,
  37607. 0xBF, 0xF1, 0x9C, 0x8A, 0x50, 0x93, 0x08, 0xBC,
  37608. 0xFB, 0x89, 0x55, 0x36, 0xD0, 0x45, 0xCA, 0x2B,
  37609. 0x97, 0xCB, 0x16, 0xA2, 0x9B, 0xB7, 0x18, 0x1C,
  37610. 0xAD, 0x05, 0x09, 0xDD, 0xB9, 0x17, 0x35, 0x02,
  37611. 0x8E, 0xBA, 0x8C, 0x31, 0xD7, 0x4B, 0xD2, 0x75,
  37612. 0xEA, 0xA6, 0x5B, 0x53, 0x40, 0xB3, 0xA4, 0x3F,
  37613. 0xBF, 0xE0, 0xB3, 0x06, 0x1D, 0x6B, 0xAE, 0x7E,
  37614. 0x75, 0xB7, 0x09, 0x8C, 0xDA, 0xBE, 0x91, 0xD4,
  37615. 0xB3, 0x1E, 0x36, 0xC9, 0xAA, 0x7A, 0x82, 0x98,
  37616. 0x86, 0x2A, 0xD6, 0x3C, 0x8F, 0xD2, 0x82, 0xE0,
  37617. 0x3B, 0x46, 0x0B, 0x3A, 0xB4, 0x64, 0xCE, 0x0F,
  37618. 0x27, 0xB1, 0xC3, 0xD1, 0x11, 0x55, 0xAC, 0xAA,
  37619. 0x01, 0x1E, 0xB9, 0xE2, 0xAE, 0x3E, 0x6D, 0xDA,
  37620. 0x07, 0xD6, 0xF4, 0x91, 0x73, 0x7C, 0xBC, 0xE9,
  37621. 0xB0, 0x5F, 0x9B, 0xC5, 0x6B, 0xE2, 0x0E, 0x8D,
  37622. 0x32, 0x6B, 0xA1, 0x32, 0xC5, 0x7F, 0xB2, 0x35,
  37623. 0x16, 0x11, 0x44, 0x51, 0x9C, 0xDF, 0x40, 0x56,
  37624. 0x0F, 0xBE, 0x27, 0x9B, 0xDE, 0x41, 0x1E, 0x11,
  37625. 0x25, 0x31, 0xF8, 0x26, 0xD6, 0xAB, 0x10, 0xD4,
  37626. 0x54, 0x73, 0x50, 0xAD, 0xD2, 0xA9, 0xDE, 0x8D,
  37627. 0x62, 0xC2, 0xAC, 0x82, 0xCA, 0xBE, 0x68, 0x15,
  37628. 0x64, 0x6F, 0x4D, 0xC9, 0x74, 0x2B, 0xB0, 0xC2,
  37629. 0xA3, 0xF7, 0x7E, 0xC7, 0xB4, 0x6C, 0x6B, 0x53,
  37630. 0x76, 0x05, 0xFA, 0x31, 0x79, 0x8C, 0xD8, 0x92,
  37631. 0x81, 0x22, 0x1A, 0x33, 0xDF, 0xB9, 0x79, 0x6E,
  37632. 0x64, 0x43, 0x05, 0x63, 0x03, 0x32, 0xC2, 0xCB,
  37633. 0x93, 0x14, 0x08, 0xAB, 0x48, 0x1A, 0x16, 0xD9,
  37634. 0x53, 0xF6, 0xBE, 0xAE, 0x38, 0x91, 0xD6, 0xD9,
  37635. 0xAC, 0x1F, 0xAB, 0x38, 0x22, 0x2D, 0x92, 0x71,
  37636. 0x87, 0x2D, 0x9D, 0x0C, 0xAD, 0xB9, 0x1A, 0xBE,
  37637. 0x9B, 0x4E, 0x26, 0x5F, 0x75, 0xC6, 0xE5, 0xE8,
  37638. 0x29, 0xE1, 0x46, 0xC3, 0xD8, 0xCE, 0x1E, 0x9D,
  37639. 0x12, 0xE0, 0xD1, 0x29, 0x80, 0x19, 0x57, 0xF4,
  37640. 0x6B, 0x0D, 0x2D, 0xBE, 0x1F, 0x74, 0x9B, 0x1D,
  37641. 0x08, 0xE2, 0x34, 0x5F, 0x62, 0x39, 0xA7, 0x31,
  37642. 0x34, 0x2E, 0xB7, 0x5B, 0x0C, 0xF1, 0xBF, 0x41,
  37643. 0x17, 0x49, 0xBC, 0x2C, 0xAF, 0x28, 0x10, 0xB7,
  37644. 0x88, 0xC6, 0xB7, 0x23, 0x8B, 0x4D, 0x3D, 0xA2,
  37645. 0xD6, 0x31, 0x5C, 0xE9, 0x54, 0x2E, 0x24, 0x40,
  37646. 0x4F, 0x14, 0x57, 0x55, 0xA3, 0x0A, 0xB8, 0x51,
  37647. 0xE4, 0x44, 0x58, 0x41, 0xBD, 0x33, 0xF7, 0x16,
  37648. 0xA5, 0x86, 0x88, 0x48, 0x88, 0xEC, 0xC6, 0xBC,
  37649. 0x64, 0x98, 0xAA, 0x32, 0x91, 0x9A, 0xE8, 0x1D,
  37650. 0x20, 0xC2, 0x69, 0x73, 0xC2, 0xBD, 0x54, 0x58,
  37651. 0x2A, 0x0F, 0x6A, 0xD9, 0x8A, 0xBF, 0xD2, 0x62,
  37652. 0x7E, 0x15, 0x69, 0x0A, 0x72, 0x7E, 0x69, 0xF5,
  37653. 0x81, 0xDD, 0x2A, 0x71, 0x27, 0x98, 0x2A, 0x90,
  37654. 0xE3, 0x3E, 0x2D, 0x4A, 0x03, 0xFE, 0x33, 0x91,
  37655. 0x42, 0xC7, 0xE4, 0x4C, 0x32, 0x6A, 0xC4, 0x6E,
  37656. 0xD3, 0x95, 0xA2, 0x25, 0xD3, 0x03, 0x33, 0x89,
  37657. 0x91, 0x73, 0x28, 0xB4, 0x53, 0x16, 0xB1, 0x58,
  37658. 0x5A, 0x01, 0xB2, 0xC3, 0x04, 0xB2, 0x94, 0x4E,
  37659. 0x90, 0x3A, 0xBB, 0xB3, 0xEC, 0x56, 0x19, 0x44,
  37660. 0x1C, 0xFC, 0x89, 0x65, 0xA4, 0x46, 0xDF, 0x75,
  37661. 0xDE, 0xFA, 0x80, 0xC6, 0xE1, 0x5A, 0xDB, 0xD5,
  37662. 0x06, 0xB7, 0xAB, 0x2D, 0xE1, 0x2D, 0xDA, 0x9B,
  37663. 0xC8, 0x14, 0x41, 0xCF, 0xC8, 0x90, 0x52, 0xE2,
  37664. 0xE5, 0x80, 0x8F, 0x71, 0x26, 0xC6, 0xFD, 0x3A,
  37665. 0xC6, 0xAC, 0x80, 0x81, 0x25, 0x8A, 0x84, 0xA0,
  37666. 0x9A, 0xE5, 0x0F, 0x6C, 0xD7, 0xCC, 0x0F, 0x4A,
  37667. 0xF3, 0x36, 0xFD, 0x1D, 0x64, 0x3E, 0x99, 0x07,
  37668. 0x99, 0x96, 0x26, 0x8C, 0x2D, 0x32, 0xD9, 0x09,
  37669. 0xF2, 0x2E, 0x35, 0x04, 0xF0, 0x7F, 0xBB, 0x56,
  37670. 0x31, 0x96, 0xD4, 0x31, 0x2F, 0xDD, 0xB9, 0x33,
  37671. 0x5D, 0x5C, 0x1D, 0x36, 0xE8, 0xC5, 0xEE, 0xA2,
  37672. 0x27, 0x8D, 0xBA, 0x23, 0xB9, 0x4D, 0x19, 0x3C,
  37673. 0x94, 0x7C, 0xC4, 0x1C, 0xA9, 0x93, 0xDC, 0x7D,
  37674. 0xB1, 0x39, 0x63, 0x40, 0xAD, 0x9C, 0x4F, 0xE6,
  37675. 0x87, 0xDD, 0x7B, 0x8D, 0x0C, 0x7A, 0x51, 0x20,
  37676. 0xAE, 0x02, 0x04, 0xF2, 0xC6, 0x65, 0xBD, 0x5F,
  37677. 0x47, 0x3D, 0x64, 0x4C, 0x7F, 0xF2, 0x6B, 0xFF,
  37678. 0xBA, 0x7A, 0x36, 0x98, 0x08, 0x30, 0x70, 0x21,
  37679. 0x28, 0xA7, 0xE6, 0x61, 0xD6, 0x77, 0xA0, 0x92,
  37680. 0xA3, 0x6E, 0x74, 0x28, 0xA4, 0x13, 0x9F, 0xB2,
  37681. 0x9B, 0x00, 0x95, 0xCC, 0x11, 0x08, 0x6F, 0x44,
  37682. 0x7D, 0x2A, 0x9E, 0xF6, 0xC9, 0xB1, 0x61, 0xF1,
  37683. 0x89, 0xC6, 0x29, 0x9E, 0x08, 0x4C, 0xB7, 0xAA,
  37684. 0x00, 0xFA, 0xF7, 0x87, 0x79, 0x7B, 0xFB, 0x06,
  37685. 0x9F, 0xBC, 0x08, 0x7F, 0xDE, 0x26, 0x25, 0x2A,
  37686. 0x16, 0x64, 0xF1, 0x9C, 0x5A, 0x8A, 0x22, 0xEC,
  37687. 0x5E, 0xE1, 0xAE, 0xB0, 0x76, 0x35, 0x7B, 0x7D,
  37688. 0xC3, 0x7E, 0x6B, 0x0F, 0x15, 0x20, 0xF9, 0x58,
  37689. 0xF7, 0x85, 0x1B, 0xAC, 0xB9, 0x2C, 0x89, 0xFD,
  37690. 0x11, 0x4A, 0x72, 0xFE, 0xAC, 0x54, 0x65, 0x2D,
  37691. 0x45, 0xB0, 0x9E, 0x1A, 0xE7, 0x65, 0x1A, 0xBD,
  37692. 0x16, 0x4B, 0xCD, 0x53, 0x7D, 0x58, 0xFA, 0x39,
  37693. 0xD3, 0xEC, 0x8A, 0xCD, 0xCD, 0xF9, 0x84, 0x25,
  37694. 0x00, 0x58, 0x62, 0xFA, 0x59, 0x69, 0x2D, 0xE1,
  37695. 0x62, 0xB7, 0x7E, 0x62, 0x97, 0xC6, 0x62, 0x33,
  37696. 0x34, 0x84, 0x08, 0xA8, 0xAB, 0x69, 0x5C, 0xE2,
  37697. 0xF2, 0x72, 0x8D, 0xB9, 0xFB, 0xE2, 0x7E, 0x95,
  37698. 0x89, 0x67, 0xEC, 0x59, 0x74, 0x76, 0x7C, 0x5A,
  37699. 0x66, 0x02, 0x30, 0x74, 0xB4, 0xA7, 0x1A, 0xFD,
  37700. 0x26, 0x4A, 0xD2, 0x89, 0x0E, 0x97, 0x0A, 0x1F,
  37701. 0x31, 0xD6, 0xE3, 0x31, 0x1B, 0x73, 0x6F, 0x9F,
  37702. 0x94, 0x88, 0x79, 0x3D, 0xDC, 0x88, 0xF2, 0x34,
  37703. 0x58, 0x06, 0x42, 0x54, 0xC8, 0x2A, 0x1D, 0x9E,
  37704. 0x59, 0xEA, 0xD2, 0xFC, 0xEC, 0x40, 0xB4, 0x30,
  37705. 0x68, 0x7C, 0x4B, 0x7E, 0x28, 0x96, 0x09, 0x26,
  37706. 0xAF, 0xCA, 0xCC, 0x9B, 0xD7, 0x56, 0xA7, 0x10,
  37707. 0x88, 0xC7, 0x84, 0x50, 0xE2, 0x0A, 0x2E, 0x98,
  37708. 0x0A, 0xED, 0xE9, 0xEB, 0xED, 0xFE, 0x7F, 0xAB,
  37709. 0xD6, 0xAB, 0xFE, 0x96, 0xF9, 0x34, 0xC4, 0xB0,
  37710. 0x2C, 0x01, 0xCA, 0x19, 0x4D, 0x01, 0xB7, 0x3C,
  37711. 0x25, 0xD5, 0x99, 0x70, 0x39, 0xD3, 0xFC, 0xD0,
  37712. 0xF0, 0x99, 0x52, 0x1F, 0x70, 0xCA, 0xEE, 0x69,
  37713. 0x11, 0x0A, 0xC1, 0xFC, 0x5A, 0x99, 0x91, 0x7A,
  37714. 0xD7, 0x52, 0xFC, 0x96, 0xAD, 0xFA, 0xD7, 0x18,
  37715. 0x6D, 0x0A, 0x7C, 0x9C, 0xFE, 0x56, 0x01, 0xC0,
  37716. 0x75, 0x14, 0xEA, 0x64, 0x48, 0xD6, 0x61, 0xC5,
  37717. 0x7A, 0xA2, 0x02, 0x42, 0x10, 0x3C, 0x42, 0x76,
  37718. 0xA0, 0x70, 0xA4, 0x89, 0xA4, 0xCB, 0x6B, 0xCA,
  37719. 0x0F, 0x9E, 0xCC, 0x43, 0x79, 0xFB, 0x22, 0x02,
  37720. 0x15, 0xFD, 0x91, 0xF8, 0x10, 0x19, 0xD5, 0xB0,
  37721. 0xAE, 0x61, 0x93, 0x58, 0xB5, 0x24, 0x68, 0xF2,
  37722. 0x72, 0xC1, 0x78, 0xE3, 0xA7, 0x4C, 0xF6, 0x77,
  37723. 0x5A, 0xA9, 0x24, 0xFE, 0x32, 0x9C, 0x31, 0x75,
  37724. 0xD9, 0xE4, 0xC3, 0xE2, 0x1A, 0xB9, 0xEC, 0x83,
  37725. 0x6E, 0xDC, 0x3A, 0xCA, 0xB2, 0xE3, 0x89, 0x1E,
  37726. 0xE8, 0xDE, 0xDA, 0x51, 0x5D, 0x39, 0xAF, 0x9B,
  37727. 0x8D, 0xDD, 0x0E, 0xE7, 0xB0, 0x16, 0x4F, 0x80,
  37728. 0x5C, 0x38, 0x35, 0xF6, 0xD2, 0xBA, 0xBD, 0xB3,
  37729. 0x0E, 0xAB, 0x47, 0x56, 0xE7, 0xEC, 0x7F, 0x82,
  37730. 0x9E, 0xCE, 0x01, 0xE8, 0xEA, 0xDF, 0xBB, 0xED,
  37731. 0x12, 0xFC, 0x28, 0x3B, 0x3D, 0x4C, 0x69, 0xF5,
  37732. 0x75, 0xE7, 0xF8, 0x04, 0x17, 0x68, 0x9F, 0xDF,
  37733. 0xCF, 0xC7, 0xBE, 0x27, 0xEE, 0x3B, 0x8C, 0xDF,
  37734. 0x57, 0xAA, 0xEB, 0xEC, 0x4A, 0x95, 0xB7, 0xE5,
  37735. 0xBB, 0x58, 0x5B, 0x85, 0x22, 0x7F, 0x7C, 0x32,
  37736. 0xBE, 0x30, 0xDB, 0x3E, 0x65, 0xE4, 0x2E, 0x30,
  37737. 0xDC, 0xF5, 0xA5, 0xFA, 0x07, 0x3D, 0xBA, 0x39,
  37738. 0x9D, 0x94, 0x2F, 0x22, 0x22, 0xAD, 0xB9, 0xB9,
  37739. 0x89, 0x81, 0x02, 0xAF, 0xE5, 0x43, 0x2E, 0xDC,
  37740. 0x7F, 0x04, 0xAE, 0x34, 0xA8, 0xFE, 0xC2, 0xD8,
  37741. 0x1C, 0xB4, 0x9A, 0x9A, 0x9B, 0x43, 0x81, 0x4C,
  37742. 0xE7, 0x1D, 0x97, 0xF7, 0x26, 0xE2, 0xB1, 0xE8,
  37743. 0xF6, 0x4B, 0x50, 0xE6, 0x5D, 0xFB, 0x48, 0x16,
  37744. 0xE1, 0x2E, 0x82, 0xA3, 0x19, 0x74, 0x84, 0xA4,
  37745. 0xE9, 0xBB, 0xA4, 0xD2, 0xD6, 0x9E, 0x3F, 0x19,
  37746. 0xD0, 0xB7, 0x5C, 0x21, 0xE2, 0xBF, 0xFE, 0x9F,
  37747. 0xC0, 0xC9, 0x8C, 0xF4, 0x8A, 0x3A, 0xAF, 0x08,
  37748. 0xD4, 0x67, 0xF7, 0x26, 0x87, 0xDF, 0x01, 0x78,
  37749. 0x17, 0x4B, 0x78, 0x97, 0xF7, 0x34, 0x34, 0x9B,
  37750. 0x18, 0x1E, 0xCA, 0x86, 0xA5, 0x98, 0xA0, 0xC5,
  37751. 0xE8, 0xC2, 0x59, 0x46, 0xF2, 0x4D, 0xC5, 0x57,
  37752. 0x2B, 0xD3, 0x24, 0xA4, 0x04, 0x58, 0xA7, 0x88,
  37753. 0xE5, 0x13, 0x7F, 0x3C, 0x7A, 0x7C, 0x97, 0xFC,
  37754. 0x9F, 0x12, 0xA3, 0xC4, 0x63, 0xA8, 0xFE, 0x94,
  37755. 0x49, 0x10, 0x1C, 0xCE, 0x96, 0x6D, 0x7C, 0x00,
  37756. 0x93, 0x23, 0x93, 0x29, 0x98, 0xD5, 0x6E, 0xF4,
  37757. 0x30, 0xC7, 0x3B, 0xC2, 0x4F, 0x5D, 0x95, 0xF7,
  37758. 0x37, 0x85, 0x8D, 0xDC, 0x4F, 0x32, 0xC0, 0x13
  37759. };
  37760. #endif
  37761. #ifndef WOLFSSL_NO_ML_KEM
  37762. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_ct[] = {
  37763. 0xc9, 0xbe, 0xad, 0x6b, 0x0c, 0x11, 0x14, 0x38,
  37764. 0x9b, 0xd4, 0x76, 0x1c, 0x73, 0xab, 0x90, 0x95,
  37765. 0xb5, 0x80, 0x9d, 0xaa, 0xc9, 0xf6, 0x59, 0xbb,
  37766. 0x56, 0x4a, 0xf2, 0x26, 0x17, 0x30, 0x52, 0xa4,
  37767. 0xa3, 0xe7, 0xf2, 0xe5, 0xfd, 0x47, 0xd2, 0xb0,
  37768. 0x2a, 0xae, 0xb5, 0x18, 0x9e, 0x06, 0xb9, 0xf4,
  37769. 0xae, 0x98, 0xb6, 0x19, 0xcb, 0x63, 0xef, 0xbd,
  37770. 0xf3, 0x98, 0x9a, 0x94, 0xb3, 0x6e, 0x8e, 0xa0,
  37771. 0xd7, 0x00, 0x63, 0x3b, 0x95, 0x0a, 0x0a, 0xe2,
  37772. 0xa7, 0x8e, 0xd9, 0x2e, 0x85, 0xc8, 0x5c, 0x70,
  37773. 0xe1, 0x3e, 0x62, 0x6f, 0xb2, 0x63, 0xfa, 0xc9,
  37774. 0x68, 0x15, 0x21, 0xc3, 0xab, 0x22, 0xfd, 0xab,
  37775. 0x29, 0x17, 0x3c, 0x96, 0x16, 0xa2, 0xb0, 0x37,
  37776. 0x08, 0x3f, 0xf7, 0xb2, 0xe0, 0x19, 0xb5, 0xbc,
  37777. 0xde, 0x06, 0x8f, 0xac, 0x25, 0x7e, 0xf8, 0xf1,
  37778. 0x27, 0x98, 0x41, 0x16, 0x93, 0xc1, 0xbd, 0xcc,
  37779. 0x65, 0x42, 0x09, 0x97, 0xa5, 0x13, 0xa8, 0xa6,
  37780. 0x95, 0x02, 0x62, 0x0b, 0xe8, 0xe4, 0xce, 0x73,
  37781. 0x62, 0xe4, 0x12, 0xa7, 0x6c, 0xf5, 0x1c, 0x1f,
  37782. 0x24, 0x33, 0xf1, 0xab, 0x64, 0xce, 0x0e, 0x5d,
  37783. 0x2f, 0x56, 0xd7, 0xc9, 0xad, 0xe9, 0x94, 0xd0,
  37784. 0xe3, 0x5d, 0x0a, 0xee, 0xf3, 0xac, 0x51, 0x5b,
  37785. 0x48, 0x24, 0x37, 0x66, 0x4d, 0x8c, 0x1d, 0x25,
  37786. 0xe5, 0xa5, 0x50, 0x7c, 0xf8, 0x0f, 0x97, 0x0d,
  37787. 0x3e, 0xa7, 0x22, 0x6a, 0xac, 0xdc, 0x45, 0x7c,
  37788. 0xbf, 0x88, 0xa0, 0x56, 0x0a, 0xa3, 0x5b, 0xb2,
  37789. 0xc5, 0xc4, 0x55, 0x86, 0x7e, 0x21, 0x59, 0x91,
  37790. 0x0a, 0x35, 0x81, 0x0b, 0xef, 0xe3, 0xaa, 0x10,
  37791. 0xeb, 0x04, 0xd8, 0xd5, 0x71, 0x47, 0xcb, 0x8f,
  37792. 0x66, 0xd2, 0xb0, 0x70, 0xba, 0xc4, 0x3d, 0x1f,
  37793. 0x1f, 0xfd, 0xd5, 0x7a, 0x93, 0x99, 0x95, 0x1f,
  37794. 0x64, 0x96, 0x57, 0x27, 0xbc, 0xb9, 0xf6, 0x6a,
  37795. 0xd4, 0x23, 0x09, 0xda, 0xfc, 0x79, 0x9c, 0x1c,
  37796. 0x54, 0x0a, 0xf1, 0xaf, 0x93, 0xef, 0xf6, 0x8a,
  37797. 0x86, 0xd6, 0x1f, 0x51, 0x15, 0xdb, 0x66, 0x2d,
  37798. 0xee, 0x7a, 0xc9, 0xa3, 0x62, 0x67, 0x77, 0x62,
  37799. 0xb6, 0xa1, 0x64, 0xa0, 0xfa, 0x0a, 0x4d, 0x85,
  37800. 0x9e, 0x4b, 0x8c, 0x8d, 0xbd, 0xb4, 0xe1, 0x83,
  37801. 0xf5, 0xe6, 0x80, 0x8f, 0xc5, 0x22, 0x29, 0x65,
  37802. 0x0c, 0xaf, 0x7c, 0xf3, 0xe1, 0x6d, 0xe3, 0xd8,
  37803. 0x95, 0xd1, 0x48, 0xc3, 0x54, 0x48, 0xab, 0x8c,
  37804. 0x27, 0x53, 0xc9, 0x83, 0x1b, 0x24, 0xbd, 0x49,
  37805. 0x21, 0x49, 0x7e, 0xaa, 0x19, 0x25, 0x65, 0xca,
  37806. 0xbf, 0xd8, 0x3c, 0x0c, 0x68, 0xdf, 0xe7, 0xd3,
  37807. 0x92, 0xab, 0xf5, 0xe5, 0xe6, 0xf8, 0x4b, 0xb9,
  37808. 0xf5, 0xaf, 0x4b, 0x71, 0x18, 0xc0, 0xb5, 0x58,
  37809. 0x10, 0x5f, 0x9c, 0x10, 0xc9, 0xb6, 0xd7, 0x06,
  37810. 0x82, 0xe1, 0xde, 0x6e, 0x06, 0x89, 0xd7, 0x10,
  37811. 0x6a, 0x63, 0x74, 0xbd, 0x34, 0xae, 0xd7, 0x22,
  37812. 0x9e, 0x6c, 0xb3, 0x56, 0xf2, 0xea, 0x65, 0xe6,
  37813. 0x80, 0xce, 0x7b, 0x1e, 0x2c, 0x37, 0x04, 0xe1,
  37814. 0x16, 0xa3, 0x85, 0x42, 0x82, 0x6e, 0x8a, 0x00,
  37815. 0x11, 0x41, 0xba, 0xf2, 0xe3, 0x4d, 0xe3, 0x7a,
  37816. 0x03, 0x04, 0x09, 0x86, 0xd4, 0xc0, 0xcd, 0x5d,
  37817. 0x57, 0xf0, 0x70, 0x1c, 0xe9, 0x30, 0x98, 0x6f,
  37818. 0xd9, 0x52, 0x5b, 0x58, 0xe2, 0xe5, 0x9f, 0x45,
  37819. 0xb8, 0xdd, 0x04, 0xc0, 0xf3, 0x5b, 0x0f, 0x47,
  37820. 0x97, 0x0c, 0xc6, 0x70, 0x79, 0x61, 0x8e, 0xb9,
  37821. 0xe6, 0xd9, 0x1e, 0x9b, 0x0f, 0x8c, 0x6d, 0x2e,
  37822. 0x16, 0x5c, 0xf4, 0x48, 0xa2, 0xc1, 0xeb, 0xf7,
  37823. 0x1b, 0x65, 0x37, 0xe0, 0xf3, 0x75, 0x18, 0x5d,
  37824. 0xfa, 0xfe, 0xf6, 0x98, 0xb6, 0x23, 0x9b, 0xb3,
  37825. 0x55, 0x80, 0xb3, 0x15, 0xbc, 0xb5, 0xed, 0x40,
  37826. 0x8c, 0x35, 0x7f, 0x19, 0x2d, 0xef, 0x89, 0xbc,
  37827. 0x1b, 0x75, 0xcd, 0xd6, 0xaa, 0xe8, 0xb5, 0xfa,
  37828. 0xf0, 0xc3, 0xe1, 0x38, 0x03, 0xf6, 0xbd, 0xfa,
  37829. 0x76, 0xfb, 0x40, 0x7f, 0xcb, 0xda, 0x79, 0x0c,
  37830. 0x32, 0x9b, 0x3e, 0xe4, 0x2f, 0xd3, 0xd3, 0xb0,
  37831. 0x3b, 0xd5, 0x00, 0x3f, 0x0b, 0xc4, 0x32, 0xf7,
  37832. 0xba, 0x39, 0x63, 0x11, 0x12, 0x45, 0x2d, 0xfd,
  37833. 0x12, 0x14, 0x04, 0x33, 0xff, 0x89, 0x80, 0xeb,
  37834. 0x6a, 0x52, 0x6b, 0xa8, 0x5e, 0xf9, 0x94, 0x77,
  37835. 0x37, 0x8b, 0x4d, 0xc7, 0x66, 0x35, 0xa5, 0xcd,
  37836. 0x50, 0x40, 0xe4, 0x3b, 0x8c, 0x1f, 0xe4, 0xee,
  37837. 0x5e, 0x15, 0x8e, 0x42, 0x3b, 0xfc, 0x0c, 0x89,
  37838. 0x3c, 0x1d, 0x56, 0x13, 0xbe, 0xd0, 0x8d, 0xa7,
  37839. 0x19, 0xc9, 0x07, 0x31, 0x84, 0xee, 0xb3, 0x6f,
  37840. 0xd3, 0x57, 0x38, 0x0f, 0xb1, 0x87, 0x3d, 0x8c,
  37841. 0xbd, 0x36, 0xe2, 0x25, 0x5e, 0x98, 0x5b, 0x1b,
  37842. 0x76, 0x81, 0x97, 0x43, 0xa6, 0x58, 0x4a, 0x9b,
  37843. 0x3a, 0x58, 0x09, 0x96, 0xc9, 0xc2, 0xee, 0xd9,
  37844. 0xbb, 0xbf, 0xff, 0x78, 0xa6, 0x20, 0x4b, 0x5e,
  37845. 0x5e, 0xea, 0xe5, 0xf4, 0xef, 0xd2, 0x66, 0x00,
  37846. 0x78, 0xb3, 0x7f, 0x07, 0x54, 0xab, 0x5d, 0xa8,
  37847. 0x62, 0xe6, 0x66, 0xb1, 0x45, 0xb5, 0xf2, 0x3f,
  37848. 0x3d, 0x09, 0x77, 0x79, 0x99, 0x29, 0xdf, 0xa2,
  37849. 0xae, 0xdd, 0xa5, 0x3d, 0x15, 0x2e, 0xda, 0x1d,
  37850. 0x0d, 0x0e, 0x4e, 0xa4, 0x3f, 0x6e, 0xd8, 0x89,
  37851. 0xbb, 0x96, 0x5e, 0xef, 0xe0, 0xa7, 0xc6, 0x85,
  37852. 0xbb, 0x36, 0x77, 0x0e, 0xaa, 0x87, 0x42, 0x42,
  37853. 0xc0, 0xe2, 0x29, 0xcf, 0x6c, 0xe5, 0x6d, 0xef,
  37854. 0xa5, 0xae, 0xae, 0x64, 0xd0, 0xc4, 0x0d, 0xda,
  37855. 0x8a, 0xa2, 0x6e, 0xae, 0xb3, 0x14, 0x58, 0xf0,
  37856. 0x70, 0xa3, 0xbc, 0x72, 0xe1, 0x61, 0x9e, 0xe9,
  37857. 0xb5, 0xf6, 0x42, 0x29, 0x1c, 0x56, 0xdf, 0x5b,
  37858. 0x7e, 0x43, 0xdb, 0x6c, 0x80, 0x2f, 0xc7, 0x4f,
  37859. 0x4f, 0x3f, 0x9b, 0x5c, 0x0d, 0x35, 0x5c, 0x3a,
  37860. 0xae, 0x52, 0x0a, 0xa3, 0x12, 0x29, 0xd1, 0x2f,
  37861. 0x3e, 0x7c, 0xc5, 0xd4, 0x8e, 0x69, 0x11, 0x91,
  37862. 0xa3, 0x6b, 0x28, 0x37, 0x65, 0xf4, 0x13, 0x3f,
  37863. 0x0f, 0xf1, 0xfe, 0x2f, 0x01, 0xc6, 0x64, 0x8b,
  37864. 0x27, 0x98, 0xa7, 0x4e, 0xb5, 0xd8, 0x42, 0xa2,
  37865. 0x48, 0xf5, 0x24, 0xa7, 0xe7, 0xf8, 0x97, 0x42,
  37866. 0x11, 0x29, 0x7b, 0x44, 0xf0, 0xdd, 0x19, 0xf3,
  37867. 0x86, 0xe8, 0x6b, 0xe6, 0xba, 0x78, 0x2d, 0xe7,
  37868. 0x7f, 0xde, 0x88, 0x72, 0x26, 0xf3, 0x7a, 0x1c,
  37869. 0x77, 0xbc, 0x5e, 0xdd, 0xee, 0xe5, 0xbf, 0x46,
  37870. 0xb6, 0x7f, 0xb7, 0x47, 0x8d, 0x55, 0x98, 0x65,
  37871. 0xf2, 0x62, 0xca, 0xa8, 0x4d, 0x64, 0xa8, 0xce,
  37872. 0x59, 0xe4, 0xdf, 0x08, 0x18, 0xe1, 0x48, 0x61,
  37873. 0x52, 0x6a, 0xcd, 0x34, 0x83, 0x60, 0x0f, 0x3d,
  37874. 0xae, 0x79, 0x59, 0xd3, 0x5d, 0x81, 0x81, 0xca,
  37875. 0x6a, 0x81, 0xce, 0x79, 0x1b, 0xe0, 0x07, 0x52,
  37876. 0xda, 0x77, 0x59, 0x44, 0x6a, 0x2c, 0xfb, 0xe0,
  37877. 0x0b, 0x82, 0x48, 0xb9, 0x34, 0x91, 0xde, 0xbd,
  37878. 0x52, 0x02, 0x20, 0xb7, 0x55, 0x41, 0x6d, 0x2f,
  37879. 0xc6, 0xb7, 0xc8, 0xaf, 0x2f, 0xf7, 0x5e, 0x5b,
  37880. 0xcb, 0xb8, 0xe7, 0x53, 0x73, 0x80, 0xa5, 0x72,
  37881. 0x1c, 0x77, 0x48, 0x49, 0x57, 0xa6, 0x92, 0x71,
  37882. 0xd8, 0xba, 0xfc, 0xe0, 0xf1, 0x66, 0x73, 0x5f,
  37883. 0xf8, 0x69, 0x23, 0x2d, 0xe5, 0xd3, 0x81, 0xaf,
  37884. 0xbf, 0x0e, 0x44, 0xd6, 0x91, 0x72, 0xb7, 0x9a,
  37885. 0x35, 0x19, 0x19, 0x49, 0xde, 0x09, 0x70, 0x3b,
  37886. 0x94, 0x22, 0x2b, 0x13, 0xc3, 0x85, 0xc6, 0x08,
  37887. 0x1e, 0x6d, 0x2e, 0xde, 0x1e, 0x57, 0xfe, 0x18,
  37888. 0x4e, 0xf8, 0xf6, 0x01, 0x96, 0xb9, 0xa3, 0xa7,
  37889. 0xb7, 0xef, 0xf7, 0x49, 0x71, 0x91, 0xca, 0x87,
  37890. 0x41, 0xb5, 0xa0, 0x1e, 0x79, 0xcb, 0x69, 0xa6,
  37891. 0x11, 0x42, 0xe6, 0xf5, 0xd0, 0x80, 0xfb, 0xb3,
  37892. 0xe5, 0x66, 0xf7, 0x9e, 0x14, 0x6f, 0x75, 0xc8,
  37893. 0xa1, 0x09, 0x78, 0x60, 0x84, 0x1b, 0x47, 0x47,
  37894. 0xdf, 0x60, 0x4d, 0xba, 0x95, 0x4e, 0x4a, 0x8d,
  37895. 0x9e, 0x0d, 0xcc, 0xc1, 0xf6, 0x09, 0xd0, 0x5c,
  37896. 0xf8, 0xd3, 0x12, 0x19, 0xec, 0xd6, 0x0c, 0x31,
  37897. 0x2d, 0xe6, 0x84, 0x55, 0x2f, 0x09, 0x22, 0x7c,
  37898. 0xb8, 0x29, 0x29, 0x1c, 0x64, 0x57, 0x32, 0xc5,
  37899. 0xf5, 0xd4, 0xd7, 0x11, 0x63, 0x9f, 0x42, 0xa2,
  37900. 0x30, 0x80, 0xaa, 0x34, 0xfe, 0x14, 0x20, 0xf2,
  37901. 0x19, 0xbd, 0x6b, 0xcf, 0x4e, 0x3b, 0x29, 0xb9,
  37902. 0xd0, 0x22, 0x93, 0xb2, 0xda, 0x81, 0x38, 0x3e,
  37903. 0x0a, 0x51, 0xd2, 0xbb, 0x18, 0x6c, 0x7b, 0x0a,
  37904. 0x21, 0x1a, 0x0c, 0xd6, 0x3a, 0xcb, 0xfc, 0x02,
  37905. 0x10, 0x40, 0x1e, 0x98, 0x5d, 0x43, 0x6b, 0x38,
  37906. 0x03, 0xd5, 0x60, 0x1c, 0x24, 0x13, 0x6a, 0xfd,
  37907. 0x15, 0x62, 0x52, 0x2e, 0x45, 0xb4, 0x57, 0xcb,
  37908. 0x43, 0x91, 0x78, 0xbe, 0x4a, 0x87, 0xcc, 0xe4,
  37909. 0x03, 0x46, 0xd3, 0x4a, 0xe0, 0xf3, 0xc3, 0x91,
  37910. 0x03, 0xc8, 0xa3, 0xeb, 0xc9, 0xc8, 0x6c, 0x8d,
  37911. 0xb8, 0xfc, 0x55, 0x61, 0xeb, 0x0f, 0x3a, 0x14,
  37912. 0x3d, 0x4e, 0x9f, 0xe9, 0x3a, 0x5c, 0xba, 0x6f,
  37913. 0x6f, 0xca, 0xe5, 0x65, 0x0d, 0x3f, 0x43, 0xd2,
  37914. 0x66, 0x8a, 0x59, 0x56, 0xc9, 0x22, 0x89, 0x3b,
  37915. 0x81, 0x66, 0x47, 0xde, 0xd0, 0xaf, 0xc0, 0x52,
  37916. 0xa6, 0xc3, 0xd9, 0xd0, 0x1a, 0x3d, 0x3a, 0xf0,
  37917. 0xf1, 0xba, 0x80, 0x7f, 0xf1, 0x04, 0x91, 0xe1,
  37918. 0x31, 0xdc, 0x15, 0xe1, 0x65, 0xcf, 0xd0, 0x65,
  37919. 0x0a, 0x1f, 0x2c, 0x31, 0x3d, 0x79, 0x56, 0x14,
  37920. 0x1e, 0xdc, 0xc6, 0x1c, 0xb9, 0x0e, 0x9e, 0x7a,
  37921. 0xbf, 0x2f, 0xe3, 0x5f, 0xc9, 0xdc, 0x1b, 0xde,
  37922. 0x88, 0x93, 0x9f, 0xa1, 0x1f, 0x7b, 0xbe, 0x3e,
  37923. 0xb4, 0xd8, 0xff, 0xa6, 0x43, 0xb0, 0x74, 0xd7,
  37924. 0x4f, 0x45, 0x11, 0x35, 0x86, 0xe9, 0xbb, 0x12,
  37925. 0x06, 0x00, 0x03, 0xd7, 0x19, 0x41, 0xf2, 0xda,
  37926. 0x09, 0x8d, 0xc0, 0xe9, 0x6c, 0xad, 0x32, 0x55,
  37927. 0xcf, 0x32, 0x8e, 0xa2, 0xd3, 0x30, 0x8c, 0x1f,
  37928. 0x45, 0x85, 0xe8, 0x9c, 0x61, 0x3c, 0x42, 0x6b,
  37929. 0x7e, 0x79, 0x8e, 0x1e, 0xc4, 0xe9, 0x8f, 0xe6,
  37930. 0xc7, 0x1e, 0x74, 0x91, 0xf5, 0xec, 0xa0, 0xcd,
  37931. 0x05, 0x11, 0x58, 0x61, 0xbd, 0x16, 0x0e, 0x3f,
  37932. 0xe7, 0x3a, 0x58, 0xa0, 0x26, 0xba, 0x53, 0x8e,
  37933. 0x0e, 0x25, 0x6b, 0x92, 0xf1, 0xd7, 0xa2, 0x49,
  37934. 0x75, 0x70, 0x59, 0x48, 0x56, 0x86, 0x0f, 0xfd,
  37935. 0x06, 0xb6, 0x01, 0xac, 0x57, 0x55, 0x92, 0xf4,
  37936. 0xac, 0x61, 0x2b, 0x5d, 0xe7, 0x86, 0x60, 0x42,
  37937. 0x12, 0x3e, 0xbc, 0x60, 0xc5, 0x57, 0x68, 0xe3,
  37938. 0xa7, 0x60, 0x0a, 0x32, 0x60, 0x55, 0x1f, 0x2b,
  37939. 0xea, 0x22, 0xbb, 0xf6, 0xb6, 0xc8, 0x24, 0x6e,
  37940. 0x80, 0xf9, 0x12, 0x5c, 0x4b, 0xb9, 0xdb, 0x35,
  37941. 0x4d, 0xd6, 0x4a, 0xe6, 0x95, 0xc1, 0x5f, 0x50,
  37942. 0x71, 0xf4, 0xab, 0xb9, 0x63, 0x92, 0x07, 0xca,
  37943. 0xc7, 0x33, 0x1b, 0x31, 0x0f, 0x69, 0xa0, 0x5f,
  37944. 0x54, 0xb9, 0x95, 0xde, 0x52, 0x9a, 0x02, 0x3f,
  37945. 0x03, 0x3b, 0x05, 0x5d, 0xb9, 0x52, 0x87, 0xa1,
  37946. 0x4b, 0xa3, 0x0a, 0x7c, 0xc5, 0x26, 0xbb, 0x72,
  37947. 0x4c, 0x41, 0x7f, 0xba, 0x29, 0x06, 0x36, 0xa9,
  37948. 0x96, 0xf2, 0x86, 0xe3, 0xe9, 0xe9, 0x39, 0xe4,
  37949. 0xfe, 0x1c, 0x39, 0x8b, 0x5c, 0x65, 0x99, 0x95,
  37950. 0x9d, 0x0b, 0x44, 0x45, 0xa3, 0x27, 0xec, 0x46,
  37951. 0x9a, 0x16, 0x53, 0xcf, 0xae, 0xa7, 0x55, 0x2c,
  37952. 0xec, 0xec, 0x08, 0x5c, 0xca, 0xa6, 0x89, 0x38,
  37953. 0xae, 0x4a, 0xc3, 0xc4, 0x24, 0xf7, 0xe4, 0x80,
  37954. 0x43, 0x9e, 0xbd, 0x2c, 0x99, 0x2b, 0x5f, 0x6f,
  37955. 0x95, 0xec, 0x24, 0x4b, 0x65, 0x7d, 0xbd, 0xea,
  37956. 0xa9, 0xae, 0x11, 0x0a, 0xaf, 0x4d, 0x68, 0xbf,
  37957. 0x4e, 0x27, 0x41, 0x0d, 0x43, 0xce, 0xef, 0x3e,
  37958. 0x88, 0xe9, 0xc7, 0x17, 0xdd, 0x44, 0xc9, 0xee
  37959. };
  37960. #endif
  37961. #ifdef WOLFSSL_KYBER_ORIGINAL
  37962. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ss[] = {
  37963. 0xB1, 0x0F, 0x73, 0x94, 0x92, 0x6A, 0xD3, 0xB4,
  37964. 0x9C, 0x5D, 0x62, 0xD5, 0xAE, 0xB5, 0x31, 0xD5,
  37965. 0x75, 0x75, 0x38, 0xBC, 0xC0, 0xDA, 0x9E, 0x55,
  37966. 0x0D, 0x43, 0x8F, 0x1B, 0x61, 0xBD, 0x74, 0x19
  37967. };
  37968. #endif
  37969. #ifndef WOLFSSL_NO_ML_KEM
  37970. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_ss[] = {
  37971. 0x48, 0x9d, 0xd1, 0xe9, 0xc2, 0xbe, 0x4a, 0xf3,
  37972. 0x48, 0x2b, 0xdb, 0x35, 0xbb, 0x26, 0xce, 0x76,
  37973. 0x0e, 0x6e, 0x41, 0x4d, 0xa6, 0xec, 0xbe, 0x48,
  37974. 0x99, 0x85, 0x74, 0x8a, 0x82, 0x5f, 0x1c, 0xd6
  37975. };
  37976. #endif
  37977. #ifdef WOLFSSL_SMALL_STACK
  37978. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37979. DYNAMIC_TYPE_TMP_BUFFER);
  37980. priv = (byte *)XMALLOC(KYBER1024_PRIVATE_KEY_SIZE, HEAP_HINT,
  37981. DYNAMIC_TYPE_TMP_BUFFER);
  37982. pub = (byte *)XMALLOC(KYBER1024_PUBLIC_KEY_SIZE, HEAP_HINT,
  37983. DYNAMIC_TYPE_TMP_BUFFER);
  37984. ct = (byte *)XMALLOC(KYBER1024_CIPHER_TEXT_SIZE, HEAP_HINT,
  37985. DYNAMIC_TYPE_TMP_BUFFER);
  37986. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37987. DYNAMIC_TYPE_TMP_BUFFER);
  37988. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37989. DYNAMIC_TYPE_TMP_BUFFER);
  37990. if (! (key && priv && pub && ct && ss && ss_dec))
  37991. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37992. #endif
  37993. #ifdef WOLFSSL_KYBER_ORIGINAL
  37994. ret = wc_KyberKey_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
  37995. if (ret != 0)
  37996. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37997. else
  37998. key_inited = 1;
  37999. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  38000. sizeof(kyber1024_rand));
  38001. if (ret != 0)
  38002. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38003. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
  38004. if (ret != 0)
  38005. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38006. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
  38007. if (ret != 0)
  38008. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38009. if (XMEMCMP(pub, kyber1024_pk, sizeof(kyber1024_pk)) != 0)
  38010. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38011. if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0)
  38012. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38013. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  38014. sizeof(kyber1024enc_rand));
  38015. if (ret != 0)
  38016. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38017. if (XMEMCMP(ct, kyber1024_ct, sizeof(kyber1024_ct)) != 0)
  38018. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38019. if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  38020. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38021. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
  38022. if (ret != 0)
  38023. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38024. if (XMEMCMP(ss_dec, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  38025. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38026. #endif
  38027. #ifndef WOLFSSL_NO_ML_KEM
  38028. ret = wc_KyberKey_Init(WC_ML_KEM_1024, key, HEAP_HINT, INVALID_DEVID);
  38029. if (ret != 0)
  38030. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38031. else
  38032. key_inited = 1;
  38033. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  38034. sizeof(kyber1024_rand));
  38035. if (ret != 0)
  38036. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38037. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE);
  38038. if (ret != 0)
  38039. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38040. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  38041. WC_ML_KEM_MAX_PRIVATE_KEY_SIZE);
  38042. if (ret != 0)
  38043. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38044. if (XMEMCMP(pub, ml_kem_1024_pk, sizeof(ml_kem_1024_pk)) != 0)
  38045. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38046. if (XMEMCMP(priv, ml_kem_1024_sk, sizeof(ml_kem_1024_sk)) != 0)
  38047. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38048. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  38049. sizeof(kyber1024enc_rand));
  38050. if (ret != 0)
  38051. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38052. if (XMEMCMP(ct, ml_kem_1024_ct, sizeof(ml_kem_1024_ct)) != 0)
  38053. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38054. if (XMEMCMP(ss, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
  38055. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38056. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_1024_ct));
  38057. if (ret != 0)
  38058. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38059. if (XMEMCMP(ss_dec, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
  38060. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38061. #endif
  38062. out:
  38063. if (key_inited)
  38064. wc_KyberKey_Free(key);
  38065. #ifdef WOLFSSL_SMALL_STACK
  38066. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38067. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38068. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38069. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38070. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38071. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38072. #endif
  38073. return ret;
  38074. }
  38075. #endif /* WOLFSSL_KYBER1024 */
  38076. #endif /* WOLFSSL_WC_KYBER */
  38077. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
  38078. {
  38079. wc_test_ret_t ret;
  38080. WC_RNG rng;
  38081. int i;
  38082. #ifdef WOLFSSL_SMALL_STACK
  38083. KyberKey *key = NULL;
  38084. byte *priv = NULL;
  38085. byte *pub = NULL;
  38086. byte *priv2 = NULL;
  38087. byte *pub2 = NULL;
  38088. byte *ct = NULL;
  38089. byte *ss = NULL;
  38090. byte *ss_dec = NULL;
  38091. #else
  38092. KyberKey key[1];
  38093. byte priv[KYBER_MAX_PRIVATE_KEY_SIZE];
  38094. byte pub[KYBER_MAX_PUBLIC_KEY_SIZE];
  38095. byte priv2[KYBER_MAX_PRIVATE_KEY_SIZE];
  38096. byte pub2[KYBER_MAX_PUBLIC_KEY_SIZE];
  38097. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  38098. byte ss[KYBER_SS_SZ];
  38099. byte ss_dec[KYBER_SS_SZ];
  38100. #endif
  38101. int key_inited = 0;
  38102. static const int testData[][4] = {
  38103. #ifndef WOLFSSL_NO_ML_KEM
  38104. #ifdef WOLFSSL_WC_ML_KEM_512
  38105. { WC_ML_KEM_512, WC_ML_KEM_512_PRIVATE_KEY_SIZE,
  38106. WC_ML_KEM_512_PUBLIC_KEY_SIZE, WC_ML_KEM_512_CIPHER_TEXT_SIZE },
  38107. #endif
  38108. #ifdef WOLFSSL_WC_ML_KEM_768
  38109. { WC_ML_KEM_768, WC_ML_KEM_768_PRIVATE_KEY_SIZE,
  38110. WC_ML_KEM_768_PUBLIC_KEY_SIZE, WC_ML_KEM_768_CIPHER_TEXT_SIZE },
  38111. #endif
  38112. #ifdef WOLFSSL_WC_ML_KEM_1024
  38113. { WC_ML_KEM_1024, WC_ML_KEM_1024_PRIVATE_KEY_SIZE,
  38114. WC_ML_KEM_1024_PUBLIC_KEY_SIZE, WC_ML_KEM_1024_CIPHER_TEXT_SIZE },
  38115. #endif
  38116. #endif
  38117. #ifdef WOLFSSL_KYBER_ORIGINAL
  38118. #ifdef WOLFSSL_KYBER512
  38119. { KYBER512, KYBER512_PRIVATE_KEY_SIZE, KYBER512_PUBLIC_KEY_SIZE,
  38120. KYBER512_CIPHER_TEXT_SIZE },
  38121. #endif
  38122. #ifdef WOLFSSL_KYBER768
  38123. { KYBER768, KYBER768_PRIVATE_KEY_SIZE, KYBER768_PUBLIC_KEY_SIZE,
  38124. KYBER768_CIPHER_TEXT_SIZE },
  38125. #endif
  38126. #ifdef WOLFSSL_KYBER1024
  38127. { KYBER1024, KYBER1024_PRIVATE_KEY_SIZE, KYBER1024_PUBLIC_KEY_SIZE,
  38128. KYBER1024_CIPHER_TEXT_SIZE },
  38129. #endif
  38130. #endif
  38131. };
  38132. WOLFSSL_ENTER("kyber_test");
  38133. #ifdef WOLFSSL_SMALL_STACK
  38134. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  38135. DYNAMIC_TYPE_TMP_BUFFER);
  38136. priv = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  38137. DYNAMIC_TYPE_TMP_BUFFER);
  38138. pub = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  38139. DYNAMIC_TYPE_TMP_BUFFER);
  38140. priv2 = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  38141. DYNAMIC_TYPE_TMP_BUFFER);
  38142. pub2 = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  38143. DYNAMIC_TYPE_TMP_BUFFER);
  38144. ct = (byte *)XMALLOC(KYBER_MAX_CIPHER_TEXT_SIZE, HEAP_HINT,
  38145. DYNAMIC_TYPE_TMP_BUFFER);
  38146. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  38147. DYNAMIC_TYPE_TMP_BUFFER);
  38148. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  38149. DYNAMIC_TYPE_TMP_BUFFER);
  38150. if (! (key && priv && pub && priv2 && pub2 && ct && ss && ss_dec))
  38151. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38152. #endif
  38153. #ifndef HAVE_FIPS
  38154. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  38155. #else
  38156. ret = wc_InitRng(&rng);
  38157. #endif
  38158. if (ret != 0)
  38159. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38160. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  38161. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38162. if (ret != 0)
  38163. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38164. else
  38165. key_inited = 1;
  38166. ret = wc_KyberKey_MakeKey(key, &rng);
  38167. if (ret != 0)
  38168. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38169. ret = wc_KyberKey_EncodePublicKey(key, pub, testData[i][2]);
  38170. if (ret != 0)
  38171. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38172. ret = wc_KyberKey_EncodePrivateKey(key, priv, testData[i][1]);
  38173. if (ret != 0)
  38174. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38175. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38176. if (ret != 0)
  38177. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38178. ret = wc_KyberKey_DecodePublicKey(key, pub, testData[i][2]);
  38179. if (ret != 0)
  38180. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38181. ret = wc_KyberKey_Encapsulate(key, ct, ss, &rng);
  38182. if (ret != 0)
  38183. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38184. ret = wc_KyberKey_EncodePublicKey(key, pub2, testData[i][2]);
  38185. if (ret != 0)
  38186. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38187. if (XMEMCMP(pub, pub2, testData[i][2]) != 0)
  38188. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38189. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38190. if (ret != 0)
  38191. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38192. ret = wc_KyberKey_DecodePrivateKey(key, priv, testData[i][1]);
  38193. if (ret != 0)
  38194. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38195. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, testData[i][3]);
  38196. if (ret != 0)
  38197. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38198. if (XMEMCMP(ss, ss_dec, KYBER_SS_SZ) != 0)
  38199. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38200. ret = wc_KyberKey_EncodePrivateKey(key, priv2, testData[i][1]);
  38201. if (ret != 0)
  38202. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38203. if (XMEMCMP(priv, priv2, testData[i][2]) != 0)
  38204. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38205. }
  38206. wc_FreeRng(&rng);
  38207. #ifdef WOLFSSL_WC_KYBER
  38208. #if !defined(WOLFSSL_NO_KYBER512) && !defined(WOLFSSL_NO_ML_KEM_512)
  38209. ret = kyber512_kat();
  38210. if (ret != 0)
  38211. goto out;
  38212. #endif
  38213. #if !defined(WOLFSSL_NO_KYBER768) && !defined(WOLFSSL_NO_ML_KEM_768)
  38214. ret = kyber768_kat();
  38215. if (ret != 0)
  38216. goto out;
  38217. #endif
  38218. #if !defined(WOLFSSL_NO_KYBER1024) && !defined(WOLFSSL_NO_ML_KEM_1024)
  38219. ret = kyber1024_kat();
  38220. if (ret != 0)
  38221. goto out;
  38222. #endif
  38223. #endif /* WOLFSSL_WC_KYBER */
  38224. out:
  38225. if (key_inited)
  38226. wc_KyberKey_Free(key);
  38227. #ifdef WOLFSSL_SMALL_STACK
  38228. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38229. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38230. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38231. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38232. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38233. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38234. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38235. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38236. #endif
  38237. return ret;
  38238. }
  38239. #endif /* WOLFSSL_HAVE_KYBER */
  38240. #ifdef HAVE_DILITHIUM
  38241. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  38242. static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
  38243. word32 pubKeyLen, const byte* sig, word32 sigLen)
  38244. {
  38245. byte msg[512];
  38246. dilithium_key* key;
  38247. byte * pubExported = NULL;
  38248. wc_test_ret_t ret;
  38249. int i;
  38250. int res = 0;
  38251. word32 lenExported = pubKeyLen;
  38252. int n_diff = 0;
  38253. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  38254. DYNAMIC_TYPE_TMP_BUFFER);
  38255. if (key == NULL) {
  38256. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38257. }
  38258. pubExported = (byte*)XMALLOC(pubKeyLen, HEAP_HINT,
  38259. DYNAMIC_TYPE_TMP_BUFFER);
  38260. if (pubExported == NULL) {
  38261. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38262. }
  38263. /* make dummy msg */
  38264. for (i = 0; i < (int)sizeof(msg); i++) {
  38265. msg[i] = (byte)i;
  38266. }
  38267. ret = wc_dilithium_init(key);
  38268. if (ret != 0) {
  38269. ret = WC_TEST_RET_ENC_EC(ret);
  38270. return ret;
  38271. }
  38272. ret = wc_dilithium_set_level(key, param);
  38273. if (ret != 0)
  38274. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38275. ret = wc_dilithium_import_public(pubKey, pubKeyLen, key);
  38276. if (ret != 0)
  38277. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38278. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38279. if (param >= WC_ML_DSA_DRAFT) {
  38280. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg),
  38281. &res, key);
  38282. }
  38283. else
  38284. #endif
  38285. {
  38286. ret = wc_dilithium_verify_ctx_msg(sig, sigLen, NULL, 0, msg,
  38287. (word32)sizeof(msg), &res, key);
  38288. }
  38289. if (ret != 0)
  38290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38291. if (res != 1)
  38292. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  38293. /* Now test the export pub raw API, verify we recover the original pub. */
  38294. ret = wc_dilithium_export_public(key, pubExported, &lenExported);
  38295. if (ret != 0) {
  38296. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38297. }
  38298. if (lenExported <= 0 || lenExported != pubKeyLen) {
  38299. ERROR_OUT(WC_TEST_RET_ENC_EC(lenExported), out);
  38300. }
  38301. n_diff = XMEMCMP(pubExported, pubKey, pubKeyLen);
  38302. if (n_diff) {
  38303. ERROR_OUT(WC_TEST_RET_ENC_EC(n_diff), out);
  38304. }
  38305. out:
  38306. wc_dilithium_free(key);
  38307. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38308. XFREE(pubExported, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38309. return ret;
  38310. }
  38311. #ifndef WOLFSSL_NO_ML_DSA_44
  38312. static wc_test_ret_t dilithium_param_44_vfy_test(void)
  38313. {
  38314. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_pub_key[] = {
  38315. 0xd8, 0xac, 0xaf, 0xd8, 0x2e, 0x14, 0x23, 0x78, 0xf7, 0x0d, 0x9a, 0x04,
  38316. 0x2b, 0x92, 0x48, 0x67, 0x60, 0x55, 0x34, 0xd9, 0xac, 0x0b, 0xc4, 0x1f,
  38317. 0x46, 0xe8, 0x85, 0xb9, 0x2e, 0x1b, 0x10, 0x3a, 0x75, 0x7a, 0xc2, 0xbc,
  38318. 0x76, 0xf0, 0x6d, 0x05, 0xa4, 0x78, 0x48, 0x84, 0x26, 0x69, 0xbd, 0x26,
  38319. 0x1d, 0x73, 0x60, 0xaa, 0x57, 0x9d, 0x8c, 0x66, 0xb1, 0x19, 0xea, 0x11,
  38320. 0xff, 0xbb, 0xf6, 0xeb, 0x26, 0x26, 0xac, 0x78, 0x74, 0x46, 0x6d, 0x51,
  38321. 0x6e, 0x92, 0xdf, 0x6a, 0x98, 0x41, 0xe9, 0x10, 0xf2, 0xcc, 0xa8, 0x7a,
  38322. 0x50, 0xdb, 0x1f, 0x4c, 0x42, 0x19, 0xd5, 0xbc, 0x76, 0x20, 0x6f, 0x2f,
  38323. 0xbf, 0xc2, 0xc9, 0x1b, 0x02, 0xb5, 0xb1, 0x09, 0x46, 0x06, 0x87, 0x02,
  38324. 0xac, 0x3d, 0xcf, 0xc3, 0xa5, 0x1b, 0xf0, 0xce, 0xd4, 0x9e, 0x84, 0x34,
  38325. 0x3c, 0x24, 0x7d, 0x89, 0xf3, 0xbf, 0x9c, 0x18, 0x9d, 0x1b, 0x1d, 0xd4,
  38326. 0xf6, 0xda, 0xc9, 0xa4, 0x14, 0xc4, 0x6b, 0xd7, 0x05, 0x6d, 0xed, 0x54,
  38327. 0x42, 0x6b, 0x5f, 0x6d, 0x1e, 0xda, 0x6b, 0x47, 0x70, 0xe5, 0x4e, 0xe7,
  38328. 0x25, 0x06, 0xf8, 0x28, 0x24, 0x34, 0xd6, 0xe5, 0xbe, 0xc5, 0x4f, 0x9e,
  38329. 0x5d, 0x33, 0xfc, 0xef, 0xe4, 0xe9, 0x55, 0x67, 0x93, 0x1f, 0x2e, 0x11,
  38330. 0x3a, 0x2e, 0xf2, 0xbb, 0x82, 0x09, 0x8d, 0xb2, 0x09, 0xf3, 0x2f, 0xef,
  38331. 0x6f, 0x38, 0xc6, 0x56, 0xf2, 0x23, 0x08, 0x63, 0x99, 0x7f, 0x4e, 0xc0,
  38332. 0x9d, 0x08, 0x9d, 0xa1, 0x59, 0x6e, 0xe1, 0x00, 0x2c, 0x99, 0xec, 0x83,
  38333. 0x2f, 0x12, 0x97, 0x2f, 0x75, 0x04, 0x67, 0x44, 0xb5, 0x95, 0xce, 0xc6,
  38334. 0x3e, 0x7a, 0x10, 0x77, 0x5e, 0xbe, 0x9c, 0x0f, 0xb3, 0xc7, 0x38, 0xbf,
  38335. 0x9e, 0x35, 0x8f, 0xe4, 0x8d, 0x19, 0xc3, 0x41, 0xb1, 0x0b, 0x8c, 0x10,
  38336. 0x9a, 0x58, 0xec, 0x4f, 0xb3, 0xe9, 0x5b, 0x72, 0x4b, 0xb8, 0x99, 0x34,
  38337. 0x9a, 0xcd, 0xb0, 0x69, 0xd0, 0x67, 0xef, 0x96, 0xb9, 0xe5, 0x54, 0x92,
  38338. 0xb7, 0x1a, 0x52, 0xf6, 0x0a, 0xc2, 0x23, 0x8d, 0x4f, 0xad, 0x00, 0xae,
  38339. 0x0f, 0x97, 0xfa, 0xce, 0x96, 0xba, 0xe7, 0x74, 0x55, 0xd4, 0xaf, 0xbf,
  38340. 0xa1, 0x32, 0x91, 0x2d, 0x03, 0x9f, 0xe3, 0x10, 0x8c, 0x77, 0x5d, 0x26,
  38341. 0x76, 0xf1, 0x87, 0x90, 0xf0, 0x20, 0xd1, 0xea, 0xf7, 0xa4, 0xe8, 0x2c,
  38342. 0x32, 0x1c, 0x55, 0xc0, 0x5d, 0xc9, 0xcd, 0x4e, 0x8f, 0x0d, 0xef, 0x0a,
  38343. 0x27, 0xb6, 0x4f, 0xa4, 0xd3, 0xa4, 0xed, 0x33, 0x22, 0xa1, 0xd3, 0x15,
  38344. 0xac, 0x1a, 0x20, 0x4e, 0x28, 0x8c, 0x8c, 0xd0, 0x71, 0xd1, 0xf2, 0xdb,
  38345. 0x33, 0x63, 0xb6, 0xa4, 0xf2, 0x17, 0x3c, 0x12, 0xb0, 0xad, 0xef, 0x31,
  38346. 0x91, 0xfe, 0xe5, 0x53, 0x99, 0xb6, 0x85, 0x63, 0xfa, 0xe6, 0xcd, 0xf6,
  38347. 0xb9, 0xce, 0x4a, 0x7d, 0x4a, 0x49, 0x29, 0xd2, 0xd9, 0xc9, 0x47, 0x4a,
  38348. 0x8a, 0x5c, 0x14, 0x5e, 0x0f, 0x7c, 0xc3, 0x91, 0xb0, 0xab, 0x37, 0xf5,
  38349. 0x26, 0x8d, 0x46, 0x74, 0x49, 0xad, 0x51, 0xc3, 0x11, 0xfa, 0x85, 0x15,
  38350. 0xa5, 0x84, 0xc1, 0xe0, 0x3c, 0x13, 0x6d, 0x13, 0xa3, 0xe6, 0xa8, 0x3c,
  38351. 0x22, 0xac, 0x17, 0x48, 0x57, 0x7c, 0x81, 0xe2, 0x4e, 0xd8, 0x33, 0x5d,
  38352. 0x4d, 0x65, 0xf7, 0xe1, 0xb8, 0x00, 0x78, 0x09, 0x16, 0xb0, 0x0b, 0xca,
  38353. 0x15, 0x0d, 0xcd, 0x9a, 0xd8, 0x47, 0x4c, 0x9b, 0x69, 0xb2, 0xa0, 0x9d,
  38354. 0x96, 0x96, 0x52, 0x6d, 0x89, 0xad, 0xff, 0x55, 0xde, 0x7b, 0xd6, 0x3d,
  38355. 0x1d, 0x5e, 0x8d, 0xf1, 0xfc, 0x48, 0x1c, 0x50, 0x59, 0x55, 0xb9, 0x07,
  38356. 0xfd, 0x6b, 0xcb, 0x95, 0xa6, 0x14, 0x73, 0xdb, 0x40, 0x40, 0x1c, 0x44,
  38357. 0xe6, 0x79, 0x30, 0x88, 0xbd, 0xa0, 0xde, 0x9b, 0xb8, 0x76, 0xf8, 0x98,
  38358. 0x56, 0x4b, 0xb9, 0x7a, 0xf6, 0xd4, 0x73, 0x89, 0x6b, 0xf7, 0x7d, 0x05,
  38359. 0x33, 0xbe, 0xb6, 0x1c, 0x4d, 0xa7, 0x12, 0x3b, 0x3f, 0xed, 0x4a, 0x0f,
  38360. 0xae, 0xa7, 0x6a, 0x26, 0x0d, 0x01, 0x84, 0x84, 0xa8, 0x0e, 0xc1, 0xc1,
  38361. 0xfd, 0xe4, 0xa9, 0xe2, 0x3f, 0xab, 0xce, 0x20, 0x90, 0x86, 0x79, 0xa2,
  38362. 0x40, 0xd0, 0xef, 0x79, 0x34, 0x2b, 0xe8, 0xc9, 0x54, 0xa7, 0x19, 0x62,
  38363. 0xcc, 0x20, 0x79, 0x3f, 0x5b, 0x9c, 0x61, 0xc2, 0xc1, 0xd2, 0x36, 0x7c,
  38364. 0x8e, 0xe3, 0x01, 0xbe, 0xc4, 0xb2, 0xb8, 0x07, 0x51, 0x23, 0x5b, 0x5d,
  38365. 0x00, 0xe6, 0x7f, 0xd6, 0xbb, 0x32, 0xa9, 0x7e, 0xb4, 0x30, 0xeb, 0x5e,
  38366. 0x6d, 0xed, 0xb2, 0xc3, 0x88, 0x81, 0xa3, 0x3b, 0x1f, 0x1e, 0xf9, 0x48,
  38367. 0x10, 0xd6, 0x01, 0x65, 0x5f, 0x6d, 0xc5, 0xeb, 0x76, 0x5f, 0x10, 0x79,
  38368. 0xaa, 0xc0, 0x86, 0xe7, 0x44, 0x95, 0x44, 0x4b, 0x54, 0x0c, 0x46, 0x2a,
  38369. 0x98, 0x01, 0x6e, 0xc0, 0xb9, 0x59, 0x2a, 0xff, 0x8f, 0xb3, 0x80, 0x15,
  38370. 0xec, 0xcd, 0x39, 0x36, 0xd7, 0x2f, 0x20, 0x9e, 0x3a, 0xc1, 0x90, 0xe5,
  38371. 0x99, 0x27, 0x16, 0xd7, 0x6c, 0x30, 0x10, 0x12, 0x03, 0x3e, 0xdc, 0xb9,
  38372. 0x03, 0x25, 0xb0, 0x8a, 0x27, 0x4d, 0x1a, 0x32, 0x36, 0x54, 0xc0, 0xba,
  38373. 0x22, 0xb2, 0xe2, 0xf6, 0x39, 0x23, 0x03, 0xc4, 0xc9, 0xe4, 0x0d, 0x99,
  38374. 0xfb, 0x98, 0xa5, 0x9b, 0x12, 0x9b, 0x58, 0x44, 0x74, 0x9f, 0x65, 0x61,
  38375. 0x51, 0xba, 0x31, 0x60, 0x9c, 0xec, 0xf8, 0x4d, 0x36, 0x61, 0xd1, 0x33,
  38376. 0x6d, 0xa6, 0x28, 0x75, 0xba, 0x7c, 0x82, 0xcb, 0x7e, 0xbe, 0x8f, 0x2d,
  38377. 0x21, 0x84, 0xb9, 0xf2, 0x4e, 0x7b, 0x95, 0x99, 0x11, 0xf3, 0xe1, 0xc0,
  38378. 0x6a, 0x44, 0xae, 0x11, 0xcb, 0x04, 0xa0, 0xf2, 0x3e, 0x17, 0xdf, 0xb2,
  38379. 0x6a, 0xdf, 0x5c, 0xf3, 0x8a, 0xf8, 0x90, 0x86, 0x64, 0xea, 0x0a, 0x32,
  38380. 0x7f, 0x9f, 0x90, 0xa8, 0x9d, 0x33, 0x12, 0xa6, 0xa4, 0xe7, 0x74, 0xa0,
  38381. 0x75, 0xa9, 0x65, 0xf8, 0x39, 0xae, 0x14, 0x32, 0x79, 0xcc, 0xaa, 0x34,
  38382. 0x86, 0x55, 0xcc, 0x99, 0xb7, 0x00, 0x05, 0x8b, 0xe3, 0x76, 0x28, 0x12,
  38383. 0xb6, 0x2a, 0x3e, 0x44, 0x8d, 0xf4, 0xba, 0xef, 0xf6, 0xdc, 0x29, 0x08,
  38384. 0x29, 0x7d, 0xd1, 0x1d, 0x17, 0x15, 0xb6, 0xb6, 0x58, 0x67, 0xd5, 0xd3,
  38385. 0x12, 0x05, 0x4e, 0xb0, 0xc3, 0x83, 0xe0, 0x35, 0x30, 0x60, 0x59, 0xa0,
  38386. 0xc5, 0x97, 0x5b, 0x81, 0xd3, 0x68, 0x6c, 0x8c, 0x17, 0x28, 0xa9, 0x24,
  38387. 0x4f, 0x80, 0x20, 0xa5, 0x21, 0x9f, 0x8f, 0x15, 0x89, 0x2d, 0x87, 0xae,
  38388. 0x2e, 0xcc, 0x73, 0x3e, 0x06, 0x43, 0xbc, 0xb3, 0x1b, 0xa6, 0x72, 0xaa,
  38389. 0xa3, 0xaa, 0xbb, 0x6f, 0x2d, 0x68, 0x60, 0xcf, 0x05, 0x94, 0x25, 0x3e,
  38390. 0x59, 0xf3, 0x64, 0x61, 0x5e, 0x78, 0x9a, 0x7e, 0x0d, 0x50, 0x45, 0x78,
  38391. 0x51, 0xab, 0x11, 0xb1, 0xc6, 0x95, 0xfc, 0x29, 0x28, 0x10, 0x9c, 0x1a,
  38392. 0x8c, 0x37, 0xb5, 0x4f, 0x0e, 0xed, 0x4a, 0x28, 0x6c, 0xaa, 0xb7, 0x0d,
  38393. 0x12, 0xfa, 0x87, 0x5d, 0xd4, 0x9a, 0xb7, 0x2b, 0x46, 0x90, 0x58, 0x4e,
  38394. 0xd7, 0x8b, 0x41, 0x1b, 0xf8, 0xc4, 0xc2, 0xde, 0xda, 0xec, 0x61, 0xe7,
  38395. 0xbf, 0x11, 0xdd, 0x6e, 0x4e, 0x6a, 0xd4, 0x87, 0x01, 0xe4, 0xac, 0xe8,
  38396. 0xaf, 0x2b, 0x01, 0xe1, 0x09, 0x20, 0xe0, 0xbd, 0x7d, 0x03, 0x73, 0x23,
  38397. 0xdf, 0x77, 0x71, 0xa4, 0x25, 0x8b, 0x0a, 0x93, 0x49, 0x32, 0x45, 0x1a,
  38398. 0xa4, 0x94, 0x31, 0x61, 0x2e, 0x17, 0x39, 0x8a, 0x66, 0xc9, 0xf9, 0x20,
  38399. 0x2d, 0x6a, 0x97, 0x2f, 0xe7, 0x26, 0xd8, 0x01, 0x42, 0x65, 0xcf, 0xce,
  38400. 0xd4, 0x24, 0x41, 0xfb, 0x9b, 0x6f, 0xf1, 0xc2, 0x9e, 0xd5, 0x08, 0x0c,
  38401. 0xdc, 0x4d, 0x8e, 0xae, 0xcb, 0x5f, 0xd4, 0xcd, 0x7c, 0xf6, 0x82, 0xc6,
  38402. 0xee, 0xf9, 0x88, 0x3a, 0x34, 0x07, 0x04, 0xb4, 0x84, 0x69, 0xb3, 0xa4,
  38403. 0x67, 0xab, 0x09, 0xc0, 0x83, 0xfe, 0x59, 0xaf, 0x18, 0x2c, 0xc8, 0x09,
  38404. 0xc1, 0xbb, 0x13, 0x7c, 0xce, 0x01, 0x5d, 0x85, 0xaa, 0x10, 0x28, 0xa2,
  38405. 0x96, 0x98, 0x69, 0x23, 0xa3, 0xe7, 0x67, 0xbc, 0x7c, 0x7e, 0xde, 0x4b,
  38406. 0x36, 0xab, 0x94, 0xd2, 0xb8, 0xf9, 0xdf, 0xee, 0xa1, 0x69, 0xa1, 0xc8,
  38407. 0xe9, 0x83, 0x21, 0xac, 0x1b, 0x39, 0xf7, 0x6d, 0xbf, 0x8c, 0xdb, 0xd6,
  38408. 0x2f, 0xc9, 0x3c, 0x3d, 0x50, 0xcf, 0x7f, 0xbe, 0x4a, 0x8d, 0xd8, 0x14,
  38409. 0xad, 0x69, 0xb0, 0x3e, 0x8a, 0xaf, 0xeb, 0xd9, 0x1a, 0x15, 0x4a, 0xe4,
  38410. 0xdd, 0xd9, 0xb2, 0xf8, 0x6b, 0xe2, 0x42, 0x9e, 0x29, 0x16, 0xfc, 0x85,
  38411. 0x9c, 0x47, 0x4b, 0x1f, 0x3d, 0x7b, 0x8c, 0xe1, 0x6d, 0xa3, 0xb8, 0x0a,
  38412. 0xe6, 0xfa, 0x27, 0xfe, 0x52, 0x72, 0xab, 0x3a, 0xa6, 0x58, 0xd7, 0x53,
  38413. 0xaf, 0x9f, 0xee, 0x03, 0x85, 0xfc, 0xa4, 0x7a, 0x72, 0x29, 0x7e, 0x62,
  38414. 0x28, 0x08, 0x79, 0xa8, 0xb8, 0xc7, 0x51, 0x8d, 0xaa, 0x40, 0x2d, 0x4a,
  38415. 0xd9, 0x47, 0xb4, 0xa8, 0xa2, 0x0a, 0x43, 0xd0, 0xe0, 0x4a, 0x39, 0xa3,
  38416. 0x06, 0x08, 0x9a, 0xe2, 0xf3, 0xf2, 0xf8, 0xb9, 0x9f, 0x63, 0x32, 0xa0,
  38417. 0x65, 0x0b, 0xb0, 0x50, 0x96, 0xa6, 0xa8, 0x7a, 0x18, 0xdd, 0x6c, 0xd1,
  38418. 0x9b, 0xd9, 0x4e, 0x76, 0x8f, 0xfb, 0x22, 0xa6, 0x1d, 0x29, 0xfc, 0xb8,
  38419. 0x47, 0x29, 0xb6, 0xd1, 0xb1, 0x63, 0x4a, 0x36, 0x1b, 0x10, 0xe6, 0x4c,
  38420. 0x65, 0x68, 0x1f, 0xad, 0x4f, 0x7d, 0x6b, 0x01, 0x41, 0x18, 0x5f, 0xba,
  38421. 0x3d, 0xa6, 0x54, 0x28, 0x58, 0xd5, 0x81, 0x60, 0xdf, 0x84, 0x76, 0x00,
  38422. 0x21, 0x53, 0xeb, 0xd3, 0xa6, 0xec, 0x7d, 0x3c, 0xb8, 0xcd, 0x91, 0x4c,
  38423. 0x2f, 0x4b, 0x2e, 0x23, 0x4c, 0x0f, 0x0f, 0xe0, 0x14, 0xa5, 0xe7, 0xe5,
  38424. 0x70, 0x8d, 0x8b, 0x9c
  38425. };
  38426. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38427. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_pub_key[] = {
  38428. 0xea, 0x05, 0x24, 0x0d, 0x80, 0x72, 0x25, 0x55, 0xf4, 0x5b,
  38429. 0xc2, 0x13, 0x8b, 0x87, 0x5d, 0x31, 0x99, 0x2f, 0x1d, 0xa9,
  38430. 0x41, 0x09, 0x05, 0x76, 0xa7, 0xb7, 0x5e, 0x8c, 0x44, 0xe2,
  38431. 0x64, 0x79, 0xa0, 0xec, 0x1f, 0x24, 0xb6, 0xc8, 0x05, 0x5b,
  38432. 0xc1, 0x18, 0xb0, 0xb7, 0xcf, 0x8c, 0x60, 0x67, 0x6b, 0x81,
  38433. 0x44, 0x27, 0xb6, 0x0e, 0xfd, 0x9b, 0xc3, 0xcb, 0x52, 0x31,
  38434. 0xfa, 0xc9, 0x34, 0x8d, 0x22, 0x1e, 0x07, 0x9d, 0x96, 0x6a,
  38435. 0x63, 0x83, 0x5c, 0xd7, 0x83, 0x2d, 0x7f, 0x48, 0x64, 0x79,
  38436. 0xca, 0xb4, 0x9f, 0xa2, 0x02, 0xb7, 0x86, 0x1d, 0x0e, 0xc7,
  38437. 0xf9, 0x6c, 0x07, 0xc0, 0x35, 0x6a, 0x34, 0x79, 0x7c, 0xb8,
  38438. 0x0f, 0xed, 0x98, 0x50, 0xfb, 0x51, 0xe0, 0x36, 0x44, 0x4c,
  38439. 0xc6, 0x35, 0xa2, 0xbb, 0x55, 0xb0, 0x5c, 0x39, 0x08, 0x02,
  38440. 0x20, 0x35, 0x5c, 0x56, 0x6d, 0x2e, 0xb9, 0xef, 0x21, 0x26,
  38441. 0x87, 0x87, 0x85, 0x8a, 0x32, 0xb5, 0xa7, 0x68, 0x70, 0x3a,
  38442. 0xfd, 0x0d, 0x21, 0x48, 0x91, 0xa3, 0x29, 0xc1, 0x2a, 0x38,
  38443. 0xe5, 0x26, 0x31, 0x1f, 0x42, 0xde, 0x0b, 0x25, 0xff, 0x1d,
  38444. 0x6b, 0xb4, 0xe0, 0x5d, 0x2d, 0xcf, 0x44, 0xd5, 0x7d, 0xc4,
  38445. 0xf6, 0x95, 0xf2, 0x06, 0x4f, 0x83, 0x88, 0x9d, 0x1e, 0xeb,
  38446. 0x1c, 0x09, 0x45, 0x62, 0x67, 0x3d, 0xff, 0x51, 0x47, 0xe8,
  38447. 0xbc, 0x9b, 0x03, 0x1f, 0xc7, 0x72, 0x65, 0xce, 0xa8, 0x8c,
  38448. 0xc2, 0xa0, 0xc2, 0xbd, 0x5b, 0x7c, 0x17, 0x16, 0x8b, 0x72,
  38449. 0xfa, 0xb1, 0xbd, 0xdf, 0x49, 0xd6, 0xa1, 0x00, 0x65, 0xbe,
  38450. 0x82, 0xe7, 0x68, 0xc7, 0xe7, 0xbc, 0xc2, 0xa4, 0xdb, 0xaa,
  38451. 0xcc, 0xea, 0x41, 0x52, 0x7f, 0x56, 0xb4, 0x68, 0x1f, 0x92,
  38452. 0x96, 0x0f, 0xce, 0xd4, 0xd0, 0x87, 0x4c, 0x4a, 0x73, 0xb5,
  38453. 0x6c, 0xd4, 0x69, 0x55, 0x15, 0x47, 0xdc, 0x94, 0x7f, 0xd2,
  38454. 0x54, 0x5e, 0xb2, 0x90, 0xc2, 0x47, 0xe4, 0xf5, 0xde, 0x8b,
  38455. 0x9b, 0xc6, 0x5d, 0x50, 0x95, 0x60, 0xe0, 0xf0, 0xa7, 0x4e,
  38456. 0xe0, 0xcd, 0x41, 0x09, 0xef, 0xb3, 0x3d, 0x90, 0x5c, 0x77,
  38457. 0x54, 0xec, 0x9e, 0x5d, 0x8a, 0xe7, 0x09, 0x5c, 0xc9, 0x58,
  38458. 0x0c, 0xd0, 0x42, 0x35, 0xd2, 0x14, 0x59, 0x38, 0x69, 0xad,
  38459. 0xf9, 0xb5, 0xbf, 0x8a, 0x8e, 0x33, 0xd8, 0x5e, 0x7a, 0x55,
  38460. 0xd0, 0x53, 0x15, 0x40, 0x4e, 0xc5, 0x86, 0xd7, 0x8f, 0x5f,
  38461. 0x2f, 0x55, 0x82, 0xc2, 0x4f, 0x16, 0xe5, 0xea, 0x1c, 0xbc,
  38462. 0xff, 0x5e, 0x1f, 0x39, 0x46, 0x70, 0x54, 0x7a, 0x3a, 0x27,
  38463. 0x16, 0x1a, 0x2b, 0x6c, 0xd2, 0xb7, 0x80, 0xd3, 0xd1, 0x9d,
  38464. 0x25, 0x59, 0xed, 0xe6, 0x51, 0xb1, 0xf2, 0xad, 0x7e, 0x51,
  38465. 0x78, 0x14, 0x2b, 0x19, 0xae, 0x64, 0x72, 0x0f, 0xd8, 0x18,
  38466. 0x79, 0x8e, 0x66, 0x88, 0xd3, 0xa4, 0xa3, 0xc3, 0x76, 0x21,
  38467. 0xcb, 0xe4, 0x79, 0x5e, 0x95, 0x74, 0xe3, 0x31, 0x18, 0x79,
  38468. 0xed, 0xc7, 0xe7, 0xfb, 0x86, 0x48, 0x1b, 0x7b, 0x75, 0x5b,
  38469. 0x7f, 0x7c, 0x82, 0xc5, 0xab, 0x11, 0xb4, 0x5d, 0x59, 0x6f,
  38470. 0x78, 0xb2, 0xa5, 0x39, 0xc6, 0x63, 0x38, 0x6c, 0xeb, 0x50,
  38471. 0x06, 0x14, 0x76, 0xf0, 0xe8, 0xfb, 0x11, 0x95, 0x1f, 0x9d,
  38472. 0x9c, 0xa6, 0xe1, 0xe2, 0x0d, 0xa3, 0x66, 0xfc, 0x20, 0x83,
  38473. 0x50, 0x0e, 0x53, 0x75, 0xb5, 0x12, 0xf4, 0xdf, 0x31, 0x46,
  38474. 0x83, 0xac, 0x5b, 0xf3, 0x99, 0xa6, 0xd1, 0x7b, 0x2b, 0xc5,
  38475. 0xdc, 0x71, 0x07, 0x27, 0x33, 0x35, 0x34, 0xf5, 0x30, 0x19,
  38476. 0xc1, 0x3b, 0xba, 0x8a, 0xaf, 0x7e, 0x49, 0x93, 0x48, 0x5b,
  38477. 0x38, 0xc0, 0xbc, 0x2e, 0xc7, 0x59, 0x1b, 0xd9, 0xf5, 0xcc,
  38478. 0x86, 0xf5, 0x7b, 0x4d, 0xd7, 0x39, 0xa7, 0xa2, 0x56, 0x20,
  38479. 0x48, 0x98, 0x7d, 0x4f, 0x75, 0x56, 0x9b, 0xb8, 0x95, 0x45,
  38480. 0x17, 0xf3, 0x86, 0x3d, 0x97, 0x0a, 0x49, 0x1b, 0xca, 0xff,
  38481. 0x20, 0xc0, 0x24, 0x2c, 0x51, 0xc2, 0x0a, 0x3c, 0xbf, 0x07,
  38482. 0x60, 0x1c, 0x88, 0x85, 0x9b, 0x85, 0x2d, 0x4a, 0xfe, 0x5a,
  38483. 0x1c, 0x90, 0xf5, 0x90, 0x12, 0xd3, 0x03, 0x3c, 0x8c, 0x2e,
  38484. 0x95, 0x4a, 0x47, 0x76, 0x0f, 0x1f, 0x5d, 0x9e, 0xed, 0xc5,
  38485. 0x64, 0xc4, 0x9b, 0xbf, 0x86, 0xc5, 0x63, 0x84, 0x33, 0x00,
  38486. 0xf1, 0x26, 0x18, 0x21, 0xf3, 0x88, 0x1a, 0x08, 0x18, 0x6d,
  38487. 0x2f, 0xef, 0xd5, 0xeb, 0x2f, 0x69, 0xc8, 0x6e, 0x92, 0x34,
  38488. 0xfc, 0x72, 0x3d, 0x9a, 0xa7, 0x9e, 0x51, 0xfb, 0x56, 0xe3,
  38489. 0xdc, 0xf4, 0x8f, 0x9b, 0x6d, 0x0d, 0x2a, 0xec, 0x66, 0x12,
  38490. 0x26, 0x35, 0xbd, 0x61, 0xc2, 0x67, 0x19, 0xf5, 0x7e, 0xa1,
  38491. 0x67, 0xa2, 0x9c, 0x3b, 0x67, 0xb0, 0xc2, 0x51, 0x6a, 0x37,
  38492. 0x7c, 0x48, 0xe9, 0x4b, 0xb9, 0xa3, 0x38, 0x2f, 0xfc, 0xde,
  38493. 0xb4, 0x7c, 0xda, 0x52, 0x84, 0x0b, 0xb0, 0xd9, 0x08, 0xe9,
  38494. 0x7a, 0x4a, 0x6f, 0x79, 0x29, 0x3d, 0xc4, 0x5c, 0x78, 0xee,
  38495. 0x63, 0xb6, 0x96, 0x68, 0xd9, 0x82, 0x4e, 0xc1, 0x1b, 0x6f,
  38496. 0x52, 0xf5, 0xb3, 0xfb, 0xe8, 0xc4, 0x2a, 0x07, 0xc6, 0x3b,
  38497. 0x85, 0x0d, 0xf4, 0xbf, 0xb0, 0x6b, 0xfb, 0xce, 0x1d, 0xb4,
  38498. 0xbf, 0x63, 0x0b, 0x91, 0x67, 0xc4, 0xa3, 0x06, 0xa4, 0xaf,
  38499. 0x6c, 0xd3, 0xe5, 0x8b, 0x87, 0x4e, 0x64, 0x9c, 0xb1, 0xf3,
  38500. 0x70, 0x7c, 0x68, 0x43, 0x46, 0x13, 0x46, 0xee, 0x27, 0x75,
  38501. 0x12, 0x45, 0x42, 0xde, 0xa5, 0x8d, 0xcf, 0xf7, 0x09, 0x87,
  38502. 0xa8, 0x80, 0x3d, 0xb6, 0x45, 0xee, 0x41, 0x2d, 0x7c, 0x45,
  38503. 0x01, 0x9d, 0xaa, 0x78, 0xa8, 0x10, 0xa4, 0xfd, 0xb5, 0x5f,
  38504. 0xee, 0x0f, 0x77, 0xba, 0x73, 0xff, 0x49, 0xdc, 0xfa, 0x39,
  38505. 0xd6, 0xa3, 0x6f, 0x25, 0xb9, 0x63, 0x2c, 0x92, 0xc5, 0xdf,
  38506. 0xfb, 0xba, 0x89, 0xf9, 0xfa, 0x94, 0x5b, 0x6f, 0x5a, 0x4d,
  38507. 0x1c, 0xe4, 0xc9, 0x10, 0xf9, 0xa0, 0xe8, 0xc4, 0xcb, 0x55,
  38508. 0x1a, 0xdb, 0x56, 0x5f, 0x8e, 0x91, 0x03, 0x23, 0xca, 0xb0,
  38509. 0x1f, 0xef, 0xb8, 0x6c, 0x13, 0x5a, 0x99, 0x25, 0xf0, 0x49,
  38510. 0xa9, 0x5a, 0x45, 0xf7, 0xfd, 0x1a, 0xc2, 0x71, 0x06, 0xe3,
  38511. 0x2d, 0x25, 0x64, 0xb0, 0x52, 0x12, 0x03, 0x62, 0xc7, 0xb6,
  38512. 0xf9, 0xdc, 0x1f, 0x78, 0xff, 0x8b, 0xfa, 0xde, 0x7f, 0x71,
  38513. 0xa6, 0x35, 0x3e, 0xac, 0x20, 0x54, 0x94, 0xa7, 0x2e, 0x9d,
  38514. 0x47, 0x17, 0x4b, 0xad, 0x92, 0xb3, 0x14, 0x26, 0x8c, 0x5a,
  38515. 0xd0, 0x16, 0x4b, 0x22, 0xe9, 0x0c, 0x79, 0x6b, 0x8e, 0xac,
  38516. 0x0d, 0x12, 0xf5, 0x66, 0x8e, 0x82, 0x1a, 0x44, 0xf3, 0xe9,
  38517. 0x56, 0x5a, 0xcd, 0x1c, 0x1b, 0x81, 0x7b, 0x63, 0x59, 0xfe,
  38518. 0xc8, 0xc0, 0xe3, 0xda, 0x16, 0x6b, 0x6f, 0x0d, 0xba, 0x0e,
  38519. 0x47, 0x12, 0x86, 0x9e, 0xf0, 0x3b, 0x4d, 0x87, 0x3b, 0xf2,
  38520. 0x75, 0x73, 0x2d, 0xdf, 0xca, 0x76, 0x0b, 0xbd, 0xe7, 0xb7,
  38521. 0x74, 0x24, 0xf3, 0xc6, 0xe6, 0x75, 0x3f, 0x8b, 0x6a, 0xd9,
  38522. 0xad, 0xed, 0xc0, 0x70, 0x04, 0x1e, 0x0b, 0x8e, 0x8b, 0x7f,
  38523. 0xea, 0xbc, 0x39, 0x6b, 0x8a, 0x44, 0xa6, 0x9a, 0x2d, 0x0d,
  38524. 0x8c, 0x21, 0x60, 0x09, 0xd2, 0x4a, 0xe0, 0x62, 0xcf, 0xfa,
  38525. 0xe8, 0x9b, 0x35, 0x6f, 0x23, 0x2f, 0xb5, 0x65, 0x08, 0x60,
  38526. 0x92, 0x15, 0xd0, 0x5b, 0x63, 0xcc, 0x65, 0x05, 0xd1, 0xef,
  38527. 0x0f, 0x7e, 0x1b, 0xb3, 0x8e, 0xc6, 0x12, 0x85, 0xc9, 0x82,
  38528. 0x53, 0x79, 0x2e, 0x80, 0x5f, 0x0c, 0x7b, 0xc7, 0x1c, 0x83,
  38529. 0x41, 0x06, 0xd8, 0x41, 0xc9, 0xe7, 0xb9, 0x4b, 0xa1, 0x61,
  38530. 0xc6, 0x86, 0x67, 0xf5, 0x10, 0xf7, 0x34, 0x0d, 0x39, 0x9e,
  38531. 0x2b, 0x5f, 0x19, 0x06, 0x02, 0xa5, 0x02, 0x23, 0x71, 0xc2,
  38532. 0x12, 0x65, 0xcc, 0x81, 0x06, 0xfd, 0x8d, 0x09, 0x68, 0x37,
  38533. 0x06, 0x3b, 0xff, 0xc4, 0x24, 0xb3, 0x1f, 0xd6, 0xe6, 0x8f,
  38534. 0x9c, 0x74, 0x2c, 0x5e, 0xc5, 0xf4, 0xe9, 0xeb, 0xca, 0xd3,
  38535. 0x04, 0x5b, 0x92, 0x9e, 0x5c, 0x1a, 0x1d, 0xa1, 0xa7, 0x34,
  38536. 0xd2, 0x05, 0xae, 0xdb, 0x3d, 0x71, 0x10, 0x6e, 0x30, 0xd9,
  38537. 0xa3, 0x44, 0xa0, 0xbd, 0x9e, 0x7b, 0xb5, 0x12, 0x8a, 0x12,
  38538. 0x07, 0x60, 0xd7, 0x1f, 0x92, 0xe6, 0xfe, 0x04, 0xa9, 0x3e,
  38539. 0x62, 0x64, 0x00, 0x5f, 0x7c, 0x7b, 0x34, 0x09, 0xeb, 0x4a,
  38540. 0x18, 0x9e, 0x77, 0x72, 0x3a, 0x31, 0x1a, 0x62, 0x2a, 0xb5,
  38541. 0xcb, 0x4e, 0x53, 0xce, 0xad, 0x8b, 0x5a, 0x20, 0x4f, 0xd7,
  38542. 0x3e, 0x16, 0xf8, 0x10, 0xe2, 0xae, 0xbd, 0x3f, 0x02, 0xa9,
  38543. 0x18, 0xa0, 0x01, 0x18, 0x84, 0x95, 0x22, 0x2e, 0x93, 0x76,
  38544. 0x44, 0x4e, 0x11, 0x7b, 0x03, 0x51, 0x50, 0x19, 0x79, 0xe7,
  38545. 0xbb, 0x5c, 0x7b, 0xca, 0x74, 0xb4, 0x25, 0x26, 0xdb, 0x66,
  38546. 0xaa, 0x0b, 0x21, 0x07, 0xfb, 0x7a, 0x96, 0x10, 0x7d, 0x99,
  38547. 0xa9, 0x16, 0xcb, 0x0e, 0xba, 0x63, 0xab, 0x95, 0xfc, 0x5a,
  38548. 0xbe, 0xa6, 0x7f, 0xd8, 0xb4, 0xcd, 0x7c, 0xc5, 0xd0, 0xb1,
  38549. 0x1b, 0x48, 0x40, 0xfb, 0xe6, 0x2f, 0x2b, 0x94, 0xfe, 0x68,
  38550. 0xa2, 0xc4, 0x36, 0xd9, 0xcd, 0xc1, 0x93, 0x6d, 0xef, 0x39,
  38551. 0x5e, 0x43, 0x30, 0x5a, 0x2e, 0x66, 0xb6, 0xf2, 0xed, 0x9a,
  38552. 0x8d, 0x12, 0xdf, 0x5c, 0xae, 0xad, 0x16, 0x12, 0x7e, 0x81,
  38553. 0x82, 0x91, 0x7d, 0x2b, 0x12, 0xe9, 0x96, 0xb8, 0xb7, 0x42,
  38554. 0xcb, 0x1f, 0xf8, 0xd1, 0xfd, 0x83, 0x7a, 0xe4, 0x36, 0x1d,
  38555. 0x04, 0x27, 0x4c, 0xe5, 0xbd, 0x75, 0x24, 0xf7, 0xbd, 0xb6,
  38556. 0x6a, 0x68, 0x4e, 0x2c, 0x1b, 0x56, 0x3e, 0x60, 0xa4, 0x42,
  38557. 0xca, 0x7a, 0x54, 0xe5, 0x06, 0xe3, 0xda, 0x05, 0xf7, 0x77,
  38558. 0x36, 0x8b, 0x81, 0x26, 0x99, 0x92, 0x42, 0xda, 0x45, 0xb1,
  38559. 0xfe, 0x4b
  38560. };
  38561. #endif
  38562. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_sig[] = {
  38563. 0x27, 0x3b, 0x58, 0xa0, 0xcf, 0x00, 0x29, 0x5e, 0x1a, 0x63, 0xbf, 0xb4,
  38564. 0x97, 0x16, 0xa1, 0x9c, 0x78, 0xd1, 0x33, 0xdc, 0x72, 0xde, 0xa3, 0xfc,
  38565. 0xf4, 0x09, 0xb1, 0x09, 0x16, 0x3f, 0x80, 0x72, 0x22, 0x68, 0x65, 0x68,
  38566. 0xb9, 0x80, 0x5a, 0x4a, 0x0d, 0x73, 0x49, 0xe1, 0xc6, 0xde, 0xca, 0x08,
  38567. 0x4f, 0xca, 0xf8, 0xb2, 0xf8, 0x45, 0x3b, 0x6b, 0x8c, 0x6c, 0xfd, 0x3a,
  38568. 0xf4, 0xde, 0xde, 0x82, 0xd8, 0x04, 0xbe, 0x4f, 0x4a, 0xdb, 0x92, 0x47,
  38569. 0x83, 0x2d, 0xc4, 0x55, 0xed, 0x20, 0x4f, 0x71, 0xb1, 0x58, 0xd9, 0x70,
  38570. 0x73, 0xbd, 0xb0, 0x3a, 0xb4, 0x8f, 0xd6, 0x9e, 0x32, 0x98, 0x2b, 0x9e,
  38571. 0xff, 0x2a, 0x7c, 0xcb, 0x05, 0x1b, 0x8e, 0xe6, 0x3a, 0x45, 0xc6, 0x7a,
  38572. 0xc8, 0xaf, 0x62, 0xd3, 0x04, 0xfa, 0x69, 0x4f, 0xda, 0x1b, 0x74, 0x16,
  38573. 0x0d, 0xb3, 0x1a, 0xee, 0x71, 0xd7, 0xb0, 0xef, 0x69, 0xf5, 0xe2, 0xe9,
  38574. 0xc2, 0xcc, 0x15, 0x66, 0x28, 0x0a, 0xac, 0xe2, 0x63, 0x06, 0xb7, 0x21,
  38575. 0x0d, 0xd8, 0x5c, 0x94, 0x63, 0xfd, 0x51, 0x18, 0x9f, 0x07, 0x19, 0x3d,
  38576. 0xa2, 0x50, 0x40, 0xd3, 0xe9, 0x05, 0xd4, 0x11, 0x13, 0x15, 0xaa, 0x46,
  38577. 0xda, 0x3e, 0x5f, 0xcd, 0x3c, 0xfa, 0x42, 0xba, 0x79, 0x4a, 0xb7, 0x43,
  38578. 0x91, 0xa5, 0xcb, 0xbc, 0xeb, 0x37, 0x94, 0xf1, 0x9c, 0xb9, 0xdb, 0x41,
  38579. 0x06, 0xd8, 0x7b, 0x5e, 0x90, 0xe3, 0x3c, 0x8a, 0x10, 0x62, 0x9a, 0x15,
  38580. 0x27, 0x78, 0xed, 0x69, 0x11, 0x2c, 0xb5, 0xb4, 0xdb, 0xc8, 0x70, 0x50,
  38581. 0x62, 0x47, 0x96, 0xcb, 0xd9, 0xb2, 0x3e, 0x59, 0x2f, 0x1c, 0xac, 0xcb,
  38582. 0xcf, 0x22, 0xc2, 0x9b, 0xc7, 0x92, 0xe9, 0x4d, 0x8d, 0x5d, 0xcf, 0x06,
  38583. 0x53, 0x7e, 0xf4, 0x4e, 0xfe, 0x9e, 0x41, 0x5d, 0x00, 0x8c, 0x08, 0xf4,
  38584. 0x02, 0x79, 0x33, 0x1c, 0x27, 0x1d, 0xe3, 0x94, 0xac, 0xe6, 0x87, 0xa0,
  38585. 0x08, 0xb4, 0x60, 0x0c, 0xff, 0x47, 0xdc, 0x16, 0x3a, 0x1d, 0x89, 0xc0,
  38586. 0x6a, 0xa4, 0x3d, 0x71, 0x33, 0xdd, 0x1e, 0x70, 0xfe, 0xd4, 0x8b, 0xed,
  38587. 0x7c, 0x91, 0xe4, 0xe2, 0x15, 0x06, 0xc1, 0x83, 0x24, 0x55, 0xa7, 0x2a,
  38588. 0x9f, 0x4e, 0xd9, 0x56, 0x7a, 0x95, 0xa8, 0xdd, 0xc4, 0xf0, 0x71, 0x3a,
  38589. 0x99, 0x65, 0x31, 0x4b, 0xb7, 0x96, 0x2c, 0x53, 0x54, 0x83, 0xec, 0xc9,
  38590. 0x97, 0x2f, 0x0c, 0xa4, 0x8f, 0xbb, 0x93, 0x9d, 0xea, 0xae, 0xf9, 0xcb,
  38591. 0xb2, 0xb9, 0xa3, 0x61, 0x5f, 0x77, 0x8c, 0xb6, 0x5a, 0x56, 0xbe, 0x5f,
  38592. 0x85, 0xd1, 0xb5, 0x0a, 0x53, 0xe2, 0xc7, 0xbf, 0x76, 0x8b, 0x97, 0x6f,
  38593. 0x10, 0xdd, 0x1f, 0x44, 0x69, 0x66, 0x03, 0xc4, 0x6b, 0x59, 0xf7, 0xb4,
  38594. 0xc1, 0x12, 0xcc, 0x00, 0x70, 0xe8, 0xbd, 0x44, 0x28, 0xf5, 0xfa, 0x96,
  38595. 0xf3, 0x59, 0xed, 0x81, 0x67, 0xe0, 0xbe, 0x47, 0x75, 0xb3, 0xa8, 0x9f,
  38596. 0x21, 0x70, 0x2e, 0x6f, 0xef, 0x54, 0x11, 0x3f, 0x34, 0xaf, 0x0d, 0x73,
  38597. 0x5b, 0x9e, 0x6d, 0x86, 0x58, 0xb7, 0x34, 0xc2, 0xc2, 0xb3, 0x64, 0xd5,
  38598. 0x9b, 0x6e, 0xb9, 0x99, 0x6a, 0xe4, 0xfd, 0xc3, 0x17, 0xf3, 0x10, 0xfc,
  38599. 0x6e, 0xf5, 0x65, 0xe1, 0x9c, 0x59, 0x15, 0x11, 0x00, 0xea, 0x96, 0x81,
  38600. 0x69, 0x9b, 0x05, 0x4d, 0xf3, 0xce, 0xf3, 0xf0, 0xa9, 0x01, 0x3f, 0x13,
  38601. 0xbb, 0xb0, 0xac, 0xc3, 0x92, 0x1c, 0x2b, 0x61, 0xe3, 0x01, 0x22, 0x45,
  38602. 0x4a, 0x23, 0x19, 0x80, 0xca, 0xb9, 0xef, 0x4e, 0x76, 0x52, 0xc5, 0x9d,
  38603. 0x91, 0x33, 0x17, 0xc4, 0x28, 0x83, 0x55, 0x61, 0x49, 0x72, 0x04, 0xaa,
  38604. 0xf8, 0xe3, 0x4b, 0x20, 0xf7, 0x6a, 0x74, 0x56, 0x64, 0xf9, 0xb3, 0xc9,
  38605. 0x67, 0x5b, 0x55, 0x29, 0x9a, 0x89, 0xa5, 0x14, 0x67, 0xea, 0x6d, 0x6a,
  38606. 0xde, 0x98, 0x58, 0x73, 0x25, 0xa3, 0xdb, 0xed, 0x3d, 0x62, 0xaa, 0xe0,
  38607. 0x79, 0x7f, 0xa3, 0xd9, 0xb5, 0x4c, 0xe9, 0xa8, 0xdf, 0xfd, 0x59, 0x31,
  38608. 0x42, 0x81, 0x9e, 0xb7, 0x81, 0x3f, 0x0e, 0xfb, 0xef, 0x80, 0x71, 0x9d,
  38609. 0xb7, 0xa5, 0xfc, 0xb1, 0x80, 0xc9, 0x7e, 0x31, 0xd9, 0x47, 0xe2, 0xca,
  38610. 0x10, 0x7b, 0xd1, 0xa1, 0x1c, 0x28, 0xc7, 0x7f, 0x51, 0x26, 0xb1, 0x4e,
  38611. 0x57, 0xdd, 0x7d, 0x76, 0x5c, 0x5a, 0x85, 0xa7, 0x7b, 0x8c, 0xc5, 0x6e,
  38612. 0xac, 0x20, 0xf8, 0x49, 0x16, 0xd6, 0x64, 0xf5, 0xf4, 0x2c, 0x32, 0xa1,
  38613. 0x5d, 0xfb, 0x87, 0xb6, 0x14, 0xfe, 0x68, 0x7c, 0x4d, 0xce, 0xd7, 0x94,
  38614. 0xf9, 0x8b, 0xf0, 0x61, 0xfd, 0xe0, 0x83, 0x7f, 0x13, 0xec, 0x7a, 0xb7,
  38615. 0x41, 0x04, 0x51, 0x6e, 0x30, 0xa2, 0x01, 0xf7, 0x30, 0x12, 0xec, 0xd2,
  38616. 0x8f, 0x73, 0xe7, 0x8e, 0x12, 0xb4, 0xe5, 0xc1, 0xff, 0xdf, 0x67, 0x14,
  38617. 0xb1, 0xe9, 0xba, 0x36, 0x19, 0x18, 0xf4, 0xaa, 0xe0, 0xe4, 0x9d, 0xcd,
  38618. 0xe8, 0xe7, 0x2b, 0x33, 0xb3, 0xdc, 0xb9, 0x19, 0xd7, 0xad, 0xa4, 0x68,
  38619. 0xcd, 0x83, 0x77, 0x98, 0x36, 0x49, 0xd9, 0x32, 0x20, 0xfd, 0xfc, 0x34,
  38620. 0xe7, 0x54, 0xd9, 0xb5, 0x05, 0xab, 0x0e, 0x08, 0x0e, 0x16, 0x8a, 0x7d,
  38621. 0x91, 0x4c, 0xaa, 0x19, 0x04, 0x37, 0x35, 0xa5, 0xab, 0x6c, 0xee, 0xc4,
  38622. 0x90, 0xf0, 0x5f, 0xc7, 0xae, 0x82, 0xfd, 0x59, 0x53, 0xe5, 0x36, 0x5a,
  38623. 0x56, 0x37, 0x61, 0x69, 0xda, 0xe5, 0x8f, 0xfd, 0x2e, 0xd4, 0x9c, 0x7f,
  38624. 0xb6, 0x39, 0xa4, 0x8d, 0x0a, 0xab, 0x82, 0x0f, 0xfe, 0x84, 0x69, 0x44,
  38625. 0x8a, 0xa6, 0xd0, 0x39, 0xf9, 0x72, 0x68, 0xe7, 0x97, 0xd8, 0x6c, 0x7b,
  38626. 0xec, 0x85, 0x8c, 0x52, 0xc9, 0x97, 0xbb, 0xc4, 0x7a, 0x67, 0x22, 0x60,
  38627. 0x46, 0x9f, 0x16, 0xf1, 0x67, 0x0e, 0x1b, 0x50, 0x7c, 0xc4, 0x29, 0x15,
  38628. 0xbc, 0x55, 0x6a, 0x67, 0xf6, 0xa8, 0x85, 0x66, 0x89, 0x9f, 0xff, 0x38,
  38629. 0x28, 0xaa, 0x87, 0x91, 0xce, 0xde, 0x8d, 0x45, 0x5c, 0xa1, 0x25, 0x95,
  38630. 0xe2, 0x86, 0xdd, 0xa1, 0x87, 0x6a, 0x0a, 0xa8, 0x3e, 0x63, 0x0e, 0x21,
  38631. 0xa5, 0x6e, 0x08, 0x4d, 0x07, 0xb6, 0x26, 0xa8, 0x92, 0xdb, 0xed, 0x13,
  38632. 0x01, 0xc3, 0xba, 0xcf, 0xad, 0x01, 0xbc, 0xe5, 0xc0, 0xba, 0xbe, 0x7c,
  38633. 0x75, 0xf1, 0xb9, 0xfe, 0xd3, 0xf0, 0xa5, 0x2c, 0x8e, 0x10, 0xff, 0x99,
  38634. 0xcb, 0xe2, 0x2d, 0xdc, 0x2f, 0x76, 0x00, 0xf8, 0x51, 0x7c, 0xcc, 0x52,
  38635. 0x16, 0x0f, 0x18, 0x98, 0xea, 0x34, 0x06, 0x7f, 0xb7, 0x2e, 0xe9, 0x40,
  38636. 0xf0, 0x2d, 0x30, 0x3d, 0xc0, 0x67, 0x4c, 0xe6, 0x63, 0x40, 0x41, 0x42,
  38637. 0x96, 0xbb, 0x0b, 0xd6, 0xc9, 0x1c, 0x22, 0x7a, 0xa9, 0x4d, 0xcc, 0x5b,
  38638. 0xaa, 0x03, 0xc6, 0x3b, 0x1e, 0x2f, 0x11, 0xae, 0x34, 0x6f, 0x0c, 0xe9,
  38639. 0x16, 0x9c, 0x82, 0x3b, 0x90, 0x4c, 0x0e, 0xf0, 0xf9, 0x7f, 0x02, 0xca,
  38640. 0xb9, 0xa9, 0x49, 0x6d, 0x27, 0x73, 0xd0, 0xbf, 0x15, 0x61, 0x52, 0xbc,
  38641. 0xd6, 0x31, 0x59, 0x2b, 0x52, 0x5b, 0xaf, 0x3c, 0xc0, 0x8f, 0xdc, 0xd5,
  38642. 0x2c, 0x1d, 0xe4, 0xe9, 0x41, 0xe8, 0xd3, 0x35, 0xd6, 0xb1, 0xf3, 0x32,
  38643. 0xe0, 0x52, 0x08, 0x73, 0x99, 0xb6, 0x6b, 0xbc, 0x26, 0xfb, 0x2e, 0xa7,
  38644. 0xb7, 0xcd, 0x14, 0xf0, 0xf9, 0xe5, 0x3a, 0xd0, 0x05, 0x5b, 0x2b, 0x38,
  38645. 0xbd, 0x7c, 0xda, 0xd4, 0x15, 0x45, 0xfa, 0x3b, 0x6f, 0x94, 0x8e, 0x22,
  38646. 0xce, 0xfa, 0x53, 0xe0, 0x5f, 0xa6, 0x9d, 0x1c, 0x26, 0x91, 0x8a, 0xab,
  38647. 0x72, 0x5b, 0x18, 0x78, 0x69, 0x98, 0x3f, 0x8d, 0x33, 0x7c, 0x21, 0x93,
  38648. 0x9e, 0xf0, 0xaf, 0xb7, 0x30, 0xc8, 0xac, 0xbc, 0xdb, 0x9c, 0x29, 0x17,
  38649. 0x6b, 0x9d, 0x0f, 0x16, 0xd6, 0xc0, 0xcc, 0x3b, 0xce, 0x11, 0xe9, 0x64,
  38650. 0xc8, 0xd4, 0x4c, 0x98, 0x7c, 0x8f, 0xf1, 0x5e, 0x84, 0xe4, 0x72, 0xf9,
  38651. 0x69, 0xf5, 0x9d, 0xad, 0x95, 0x3b, 0xfb, 0x6d, 0x30, 0x7e, 0x0a, 0x47,
  38652. 0x5b, 0x26, 0xb2, 0x4e, 0xeb, 0x1a, 0xc3, 0x37, 0x16, 0x28, 0x79, 0x62,
  38653. 0xb4, 0x36, 0x85, 0x4a, 0x15, 0x5a, 0xc3, 0x6e, 0xbe, 0x7e, 0x00, 0xe9,
  38654. 0x4a, 0xa5, 0xd7, 0x90, 0xcf, 0x59, 0x63, 0x2d, 0x2b, 0xc2, 0xc6, 0x47,
  38655. 0xe6, 0x77, 0xb7, 0x6e, 0x9b, 0xc8, 0x0d, 0x18, 0x2b, 0x45, 0x2b, 0xc9,
  38656. 0x5a, 0x6e, 0xb4, 0x50, 0xa5, 0x23, 0x7d, 0x17, 0xcc, 0x49, 0xe2, 0xb3,
  38657. 0xf4, 0x6d, 0xb4, 0xb7, 0xbb, 0x9e, 0xdd, 0x20, 0x99, 0x19, 0xf5, 0x53,
  38658. 0x1f, 0xd0, 0xff, 0x67, 0xf3, 0x8e, 0x6a, 0xcd, 0x2a, 0x6e, 0x2b, 0x0a,
  38659. 0x90, 0xd7, 0xdb, 0xe1, 0xff, 0x1c, 0x40, 0xa1, 0xb0, 0x5d, 0x94, 0x4d,
  38660. 0x20, 0x14, 0x01, 0xa1, 0xa8, 0xd1, 0x15, 0xd2, 0xd9, 0x1b, 0xbf, 0xc2,
  38661. 0x8a, 0xd0, 0x02, 0xf6, 0x16, 0xa1, 0xb7, 0x40, 0xe0, 0x36, 0x88, 0xc8,
  38662. 0x17, 0x0a, 0xf0, 0xb6, 0x0d, 0x3c, 0x53, 0xb9, 0x51, 0xed, 0xef, 0x20,
  38663. 0x6f, 0xf3, 0x0c, 0xb5, 0xce, 0x0e, 0x9e, 0xfd, 0x0f, 0x5e, 0x3f, 0x8f,
  38664. 0x3c, 0xb7, 0x2a, 0xdb, 0xc6, 0xa7, 0xf2, 0x11, 0x6e, 0xdc, 0x05, 0x33,
  38665. 0xd4, 0xd8, 0xb0, 0x2d, 0x8a, 0xe5, 0x39, 0x82, 0x00, 0x49, 0x7d, 0xfd,
  38666. 0x32, 0x29, 0xbb, 0x79, 0x5d, 0xcb, 0x21, 0x7b, 0x2d, 0x36, 0x58, 0x73,
  38667. 0x52, 0x57, 0x52, 0x96, 0x4d, 0x89, 0x61, 0xf4, 0xad, 0x1f, 0x48, 0xd5,
  38668. 0x7a, 0x4a, 0xaa, 0x1c, 0xa1, 0xf4, 0xb4, 0x9c, 0x43, 0x3b, 0x95, 0x72,
  38669. 0xd0, 0x0e, 0x35, 0x82, 0x26, 0xd4, 0x2e, 0xe3, 0x83, 0x96, 0x97, 0x5a,
  38670. 0x7b, 0xfc, 0x48, 0x17, 0x3c, 0xba, 0x9e, 0x5f, 0x46, 0x1a, 0x53, 0xe3,
  38671. 0x2e, 0x78, 0x79, 0x80, 0xf6, 0x2d, 0x24, 0xcf, 0x62, 0xb6, 0x86, 0xeb,
  38672. 0xee, 0xec, 0xf2, 0x1d, 0x00, 0xc8, 0x28, 0x9d, 0x93, 0x16, 0xa7, 0xd9,
  38673. 0x11, 0x47, 0xe3, 0xc4, 0xb6, 0xc4, 0xa0, 0x99, 0x83, 0xc1, 0x17, 0xd8,
  38674. 0x8e, 0xde, 0x69, 0x1d, 0xcb, 0xdd, 0xe7, 0x86, 0x6f, 0xf2, 0x36, 0x07,
  38675. 0x23, 0x86, 0x0d, 0xe9, 0xad, 0x87, 0xae, 0x76, 0x98, 0x95, 0x51, 0xf2,
  38676. 0xb3, 0x11, 0xc5, 0x34, 0xf0, 0x0c, 0xf8, 0x29, 0x9c, 0x84, 0x4f, 0x81,
  38677. 0x49, 0x85, 0x63, 0x25, 0x16, 0xb0, 0xc3, 0xaa, 0xd7, 0x8a, 0x2e, 0x4b,
  38678. 0x97, 0x60, 0x74, 0xf8, 0xa7, 0x39, 0xec, 0x6c, 0x2c, 0x9b, 0x33, 0x3a,
  38679. 0x11, 0xbd, 0xa6, 0x90, 0x48, 0x65, 0xb1, 0xe7, 0x38, 0x53, 0x47, 0x1b,
  38680. 0x62, 0xd5, 0xb7, 0xa8, 0xd4, 0xae, 0xf5, 0x12, 0x06, 0x12, 0x54, 0xa2,
  38681. 0xce, 0xf1, 0x6b, 0x3a, 0xda, 0x63, 0x2e, 0x37, 0x2a, 0x25, 0x89, 0x30,
  38682. 0x98, 0x77, 0x1d, 0x4b, 0x5a, 0x1e, 0xb7, 0x3d, 0xed, 0x19, 0xec, 0x9f,
  38683. 0x64, 0x46, 0xa8, 0x2a, 0x79, 0xf3, 0x70, 0x39, 0x9f, 0x8c, 0xc3, 0x28,
  38684. 0xcc, 0x2a, 0xc0, 0xd0, 0xe6, 0x80, 0xf5, 0x01, 0x78, 0x72, 0x7f, 0xe7,
  38685. 0x2e, 0x7b, 0x5f, 0x05, 0xc3, 0x41, 0x33, 0x07, 0xdb, 0x9c, 0xa8, 0x96,
  38686. 0xa7, 0x21, 0x20, 0x23, 0xd0, 0x59, 0x39, 0x06, 0x19, 0xa4, 0x29, 0xe5,
  38687. 0x72, 0x39, 0x69, 0x23, 0xe3, 0xfa, 0x28, 0x63, 0xf5, 0x42, 0x3b, 0xca,
  38688. 0x88, 0x5d, 0x7e, 0x47, 0x93, 0xa8, 0x8c, 0x75, 0xf2, 0x19, 0x44, 0x43,
  38689. 0x15, 0x39, 0x03, 0x42, 0xd8, 0x1d, 0x81, 0x30, 0x8e, 0x84, 0x31, 0x24,
  38690. 0x75, 0x67, 0x4e, 0xbe, 0xfe, 0x0a, 0xd8, 0xc3, 0xe7, 0x5b, 0xe1, 0xd5,
  38691. 0x12, 0x6a, 0x69, 0x99, 0xcd, 0x35, 0xca, 0x22, 0x02, 0x65, 0xb3, 0x0f,
  38692. 0x50, 0xb6, 0xaa, 0xc6, 0x91, 0x5c, 0x4d, 0xd4, 0x07, 0x93, 0x46, 0xf0,
  38693. 0xcc, 0xe1, 0x92, 0x14, 0x91, 0x21, 0x43, 0xc4, 0xba, 0x45, 0x1c, 0x47,
  38694. 0x29, 0xdf, 0xff, 0x89, 0x60, 0xee, 0x89, 0x1e, 0xc3, 0xb4, 0xb9, 0x0b,
  38695. 0xc9, 0x7e, 0xd9, 0x15, 0xb0, 0x80, 0x91, 0xbe, 0xb9, 0x43, 0x48, 0x12,
  38696. 0x86, 0x8e, 0x79, 0x38, 0x4d, 0xce, 0x36, 0x7f, 0xc3, 0xe8, 0xb7, 0xb9,
  38697. 0x92, 0xbf, 0x27, 0x20, 0x54, 0xc8, 0x05, 0x63, 0x3b, 0xf5, 0x48, 0x1a,
  38698. 0xa9, 0x04, 0x6c, 0xb6, 0x0e, 0x11, 0xea, 0xf3, 0x59, 0xb9, 0xa6, 0xf6,
  38699. 0xf8, 0x0b, 0x15, 0xed, 0x30, 0xf9, 0xe4, 0xe5, 0x26, 0x2d, 0xbb, 0xc6,
  38700. 0x5b, 0x36, 0xbb, 0x73, 0xa6, 0x4f, 0xf5, 0x43, 0x9f, 0xd7, 0xb9, 0x0f,
  38701. 0xbc, 0x4f, 0x8d, 0xb8, 0xec, 0x1d, 0x42, 0x19, 0x56, 0x37, 0xc4, 0xcb,
  38702. 0xd0, 0x16, 0x85, 0xff, 0xd3, 0x9b, 0xef, 0xc8, 0x75, 0x37, 0xd1, 0x92,
  38703. 0xad, 0x21, 0x94, 0x1e, 0x9a, 0xf6, 0x2f, 0x6d, 0x30, 0xba, 0x37, 0xc3,
  38704. 0xdc, 0x11, 0xe0, 0x79, 0xa4, 0x92, 0x1f, 0xe4, 0xaa, 0x7a, 0x6b, 0x2a,
  38705. 0xe4, 0x04, 0xb7, 0xf9, 0x86, 0x95, 0xdb, 0xa8, 0xfc, 0x8a, 0x53, 0x21,
  38706. 0x31, 0x14, 0xf7, 0x40, 0x01, 0x78, 0x4e, 0x73, 0x18, 0xb3, 0x54, 0xd7,
  38707. 0xa6, 0x93, 0xf0, 0x70, 0x04, 0x1c, 0xe0, 0x2b, 0xef, 0xee, 0xd4, 0x64,
  38708. 0xa7, 0xd9, 0x9f, 0x81, 0x4f, 0xe5, 0x1e, 0xbe, 0x6e, 0xd2, 0xf6, 0x3a,
  38709. 0xba, 0xcf, 0x8c, 0x96, 0x2a, 0x3d, 0xf7, 0xe5, 0x5c, 0x59, 0x40, 0x9c,
  38710. 0xe3, 0xf9, 0x2b, 0x6d, 0x3d, 0xf2, 0x6f, 0x81, 0xd6, 0xab, 0x9c, 0xab,
  38711. 0xc6, 0xf7, 0x8f, 0xaa, 0xe5, 0x71, 0xe3, 0xc9, 0x8c, 0x1a, 0xeb, 0xc5,
  38712. 0x87, 0xe7, 0xb0, 0xde, 0x18, 0xba, 0xaa, 0x1e, 0xda, 0x12, 0x32, 0x16,
  38713. 0x94, 0x3a, 0x6e, 0x4f, 0x84, 0x06, 0x8e, 0x33, 0xf7, 0xfa, 0x35, 0xb8,
  38714. 0x45, 0xe4, 0x5e, 0x9e, 0x46, 0x05, 0x7a, 0xf7, 0xf4, 0x99, 0xad, 0xb9,
  38715. 0xdd, 0x55, 0xd9, 0x52, 0x3b, 0x93, 0xe3, 0x9b, 0x54, 0x1b, 0xe6, 0xa9,
  38716. 0x70, 0xd3, 0x48, 0xf9, 0x3d, 0xdb, 0x88, 0x63, 0x66, 0xa0, 0xab, 0x72,
  38717. 0x83, 0x6e, 0x8f, 0x78, 0x9d, 0x55, 0x46, 0x21, 0xca, 0x7c, 0xb7, 0x5d,
  38718. 0x16, 0xe8, 0x66, 0x3b, 0x7b, 0xaa, 0xfe, 0x9c, 0x9c, 0x33, 0xc9, 0xc2,
  38719. 0xa4, 0x3c, 0x78, 0x97, 0xf3, 0x5b, 0xc2, 0x29, 0x36, 0x98, 0x68, 0x28,
  38720. 0xfe, 0x0a, 0xae, 0x6f, 0xe5, 0xf7, 0xfb, 0x9d, 0xf8, 0x8c, 0xd9, 0xd0,
  38721. 0x4d, 0xfe, 0xc7, 0xd0, 0xb0, 0xe3, 0x9c, 0xdb, 0xac, 0x9e, 0x1b, 0x55,
  38722. 0x7e, 0x24, 0xfe, 0xc4, 0x12, 0xcb, 0xc2, 0xdd, 0x0a, 0xda, 0x31, 0x40,
  38723. 0x41, 0xb7, 0xfc, 0x3f, 0x6d, 0xe2, 0xd3, 0x8a, 0x0f, 0x21, 0x33, 0x3a,
  38724. 0xbc, 0xa7, 0x62, 0x18, 0xb3, 0xaf, 0x48, 0xc6, 0xe2, 0xa3, 0xdd, 0x1d,
  38725. 0x20, 0x62, 0xe4, 0x4b, 0x81, 0x6b, 0x3a, 0xc5, 0xb1, 0x07, 0xe1, 0xf1,
  38726. 0xe1, 0xba, 0xf6, 0x01, 0xc6, 0xf2, 0xea, 0xc0, 0x97, 0x73, 0x79, 0x19,
  38727. 0x06, 0xaa, 0x62, 0x42, 0xcb, 0x21, 0x5f, 0x08, 0x97, 0x7d, 0x72, 0xb5,
  38728. 0x39, 0x4d, 0x99, 0xe3, 0xa2, 0x3f, 0xb9, 0xb4, 0xed, 0xf4, 0x61, 0x35,
  38729. 0xe1, 0x50, 0xfb, 0x56, 0x7c, 0x35, 0xfd, 0x44, 0x8a, 0x57, 0x22, 0xed,
  38730. 0x30, 0x33, 0xc3, 0x0b, 0xf1, 0x88, 0xe4, 0x44, 0x46, 0xf5, 0x73, 0x6d,
  38731. 0x9b, 0x98, 0x88, 0x92, 0xf5, 0x34, 0x85, 0x18, 0x66, 0xef, 0x70, 0xbe,
  38732. 0x7b, 0xc1, 0x0f, 0x1c, 0x78, 0x2d, 0x42, 0x13, 0x2d, 0x2f, 0x4d, 0x40,
  38733. 0x8e, 0xe2, 0x6f, 0xe0, 0x04, 0xdb, 0x58, 0xbc, 0x65, 0x80, 0xba, 0xfc,
  38734. 0x89, 0xee, 0xf3, 0x78, 0xb2, 0xd9, 0x78, 0x93, 0x6d, 0xbf, 0xd4, 0x74,
  38735. 0x24, 0xf4, 0x5c, 0x37, 0x89, 0x0c, 0x14, 0xd5, 0xbd, 0xc5, 0xfc, 0x37,
  38736. 0xe8, 0x8b, 0xe0, 0xc5, 0x89, 0xc9, 0x70, 0xb3, 0x76, 0x46, 0xce, 0x0d,
  38737. 0x7c, 0x3d, 0xa4, 0x5d, 0x02, 0x95, 0x03, 0xba, 0x24, 0xaa, 0xf7, 0xd0,
  38738. 0x75, 0x35, 0x78, 0x27, 0x9c, 0x6d, 0x2a, 0xef, 0xaa, 0xac, 0x85, 0xef,
  38739. 0x8d, 0xfc, 0xc0, 0xfc, 0x72, 0x02, 0xf4, 0xa3, 0xd3, 0x87, 0xfc, 0x4d,
  38740. 0xce, 0x3d, 0xcb, 0xc2, 0x74, 0x5b, 0xb0, 0x83, 0xc5, 0x72, 0x72, 0xd6,
  38741. 0xa1, 0x67, 0x4d, 0xa1, 0xd6, 0xaa, 0xe7, 0x9b, 0xe7, 0xc0, 0xfd, 0x86,
  38742. 0x91, 0x08, 0xfa, 0x48, 0x2f, 0x50, 0xce, 0x17, 0xea, 0x1c, 0xe3, 0x90,
  38743. 0x35, 0xe6, 0x6c, 0xc9, 0x66, 0x7d, 0x51, 0x32, 0x20, 0x0c, 0x2d, 0x4b,
  38744. 0xa1, 0xbf, 0x78, 0x87, 0xe1, 0x5a, 0x28, 0x0e, 0x9a, 0x85, 0xf6, 0x7e,
  38745. 0x39, 0x60, 0xbc, 0x64, 0x42, 0x5d, 0xf0, 0x0a, 0xd7, 0x3e, 0xbb, 0xa0,
  38746. 0x6d, 0x7c, 0xfa, 0x75, 0xee, 0x34, 0x39, 0x23, 0x0e, 0xbd, 0x50, 0x19,
  38747. 0x7a, 0x2a, 0xb7, 0x17, 0x3a, 0x8b, 0xb7, 0xb6, 0xf4, 0xd8, 0x47, 0x71,
  38748. 0x6b, 0x21, 0x1b, 0x56, 0xcc, 0xfb, 0x7b, 0x81, 0x99, 0x46, 0x88, 0x23,
  38749. 0x40, 0x49, 0x66, 0x8b, 0xac, 0x84, 0x16, 0x8a, 0x86, 0xae, 0x38, 0xc4,
  38750. 0x5b, 0x1f, 0x2b, 0xfa, 0xf2, 0x8b, 0x81, 0xc1, 0x22, 0x61, 0x61, 0x6c,
  38751. 0x43, 0x16, 0x8c, 0x1d, 0x37, 0xb2, 0xaf, 0x3c, 0x3a, 0x90, 0x33, 0xed,
  38752. 0xf5, 0x08, 0x78, 0xfd, 0x5a, 0xde, 0xd3, 0x38, 0x6d, 0xd7, 0x1c, 0x23,
  38753. 0xeb, 0xb4, 0x9b, 0x8e, 0xc2, 0x48, 0x47, 0x8e, 0x84, 0xbb, 0xc4, 0xd0,
  38754. 0xcc, 0xf9, 0x55, 0x5a, 0x57, 0xb9, 0x99, 0x52, 0x82, 0x21, 0x3b, 0x83,
  38755. 0xda, 0x8f, 0xa3, 0x88, 0x9c, 0x57, 0xe0, 0x4b, 0xc1, 0xce, 0xbe, 0xd3,
  38756. 0xea, 0xdd, 0xf2, 0x07, 0xc1, 0x73, 0x6f, 0xc0, 0x5e, 0x8e, 0x85, 0x72,
  38757. 0xab, 0x2f, 0xa9, 0xac, 0x39, 0xee, 0x05, 0x34, 0x13, 0x16, 0x1b, 0x1c,
  38758. 0x21, 0x24, 0x41, 0x49, 0x78, 0x87, 0x8b, 0x97, 0x9c, 0x9f, 0xa3, 0xa8,
  38759. 0xb9, 0xbc, 0xc6, 0xcc, 0xf2, 0xfd, 0x18, 0x2a, 0x46, 0x58, 0x5a, 0x88,
  38760. 0xa2, 0xb5, 0xcc, 0xd2, 0xda, 0xe1, 0xe3, 0x0d, 0x20, 0x23, 0x2b, 0x2f,
  38761. 0x47, 0x57, 0x5e, 0x64, 0x87, 0x97, 0x9c, 0xa7, 0xaa, 0xbc, 0xc1, 0xe4,
  38762. 0xe5, 0xea, 0x0b, 0x16, 0x3b, 0x3c, 0x3e, 0x45, 0x58, 0x63, 0x6a, 0x6f,
  38763. 0x7c, 0x8c, 0x8d, 0x92, 0x99, 0x9c, 0xad, 0xb5, 0xb7, 0xce, 0x00, 0x00,
  38764. 0x00, 0x00, 0x00, 0x00, 0x16, 0x23, 0x36, 0x4a
  38765. };
  38766. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38767. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_sig[] = {
  38768. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  38769. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  38770. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  38771. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  38772. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  38773. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  38774. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  38775. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  38776. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  38777. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  38778. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  38779. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  38780. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  38781. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  38782. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  38783. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  38784. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  38785. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  38786. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  38787. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  38788. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  38789. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  38790. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  38791. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  38792. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  38793. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  38794. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  38795. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  38796. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  38797. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  38798. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  38799. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  38800. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  38801. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  38802. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  38803. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  38804. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  38805. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  38806. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  38807. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  38808. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  38809. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  38810. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  38811. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  38812. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  38813. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  38814. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  38815. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  38816. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  38817. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  38818. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  38819. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  38820. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  38821. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  38822. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  38823. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  38824. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  38825. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  38826. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  38827. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  38828. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  38829. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  38830. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  38831. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  38832. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  38833. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  38834. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  38835. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  38836. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  38837. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  38838. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  38839. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  38840. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  38841. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  38842. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  38843. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  38844. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  38845. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  38846. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  38847. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  38848. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  38849. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  38850. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  38851. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  38852. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  38853. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  38854. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  38855. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  38856. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  38857. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  38858. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  38859. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  38860. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  38861. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  38862. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  38863. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  38864. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  38865. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  38866. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  38867. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  38868. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  38869. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  38870. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  38871. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  38872. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  38873. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  38874. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  38875. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  38876. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  38877. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  38878. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  38879. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  38880. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  38881. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  38882. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  38883. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  38884. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  38885. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  38886. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  38887. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  38888. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  38889. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  38890. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  38891. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  38892. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  38893. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  38894. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  38895. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  38896. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  38897. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  38898. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  38899. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  38900. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  38901. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  38902. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  38903. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  38904. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  38905. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  38906. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  38907. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  38908. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  38909. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  38910. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  38911. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  38912. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  38913. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  38914. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  38915. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  38916. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  38917. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  38918. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  38919. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  38920. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  38921. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  38922. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  38923. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  38924. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  38925. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  38926. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  38927. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  38928. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  38929. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  38930. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  38931. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  38932. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  38933. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  38934. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  38935. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  38936. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  38937. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  38938. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  38939. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  38940. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  38941. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  38942. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  38943. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  38944. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  38945. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  38946. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  38947. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  38948. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  38949. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  38950. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  38951. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  38952. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  38953. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  38954. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  38955. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  38956. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  38957. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  38958. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  38959. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  38960. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  38961. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  38962. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  38963. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  38964. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  38965. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  38966. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  38967. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  38968. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  38969. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  38970. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  38971. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  38972. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  38973. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  38974. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  38975. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  38976. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  38977. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  38978. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  38979. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  38980. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  38981. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  38982. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  38983. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  38984. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  38985. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  38986. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  38987. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  38988. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  38989. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  38990. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  38991. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  38992. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  38993. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  38994. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  38995. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  38996. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  38997. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  38998. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  38999. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  39000. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  39001. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  39002. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  39003. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  39004. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  39005. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  39006. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  39007. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  39008. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  39009. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46
  39010. };
  39011. #endif
  39012. wc_test_ret_t ret;
  39013. ret = dilithium_param_vfy_test(WC_ML_DSA_44, ml_dsa_44_pub_key,
  39014. (word32)sizeof(ml_dsa_44_pub_key), ml_dsa_44_sig,
  39015. (word32)sizeof(ml_dsa_44_sig));
  39016. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39017. if (ret == 0) {
  39018. ret = dilithium_param_vfy_test(WC_ML_DSA_44_DRAFT,
  39019. ml_dsa_44_draft_pub_key, (word32)sizeof(ml_dsa_44_draft_pub_key),
  39020. ml_dsa_44_draft_sig, (word32)sizeof(ml_dsa_44_draft_sig));
  39021. }
  39022. #endif
  39023. return ret;
  39024. }
  39025. #endif
  39026. #ifndef WOLFSSL_NO_ML_DSA_65
  39027. static wc_test_ret_t dilithium_param_65_vfy_test(void)
  39028. {
  39029. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_pub_key[] = {
  39030. 0x2c, 0x32, 0xfa, 0x59, 0x71, 0x16, 0x4a, 0x0e, 0x45, 0x0f, 0x21, 0xfd,
  39031. 0x65, 0xee, 0x50, 0xb0, 0xbf, 0xea, 0x8e, 0x4e, 0xa2, 0x55, 0x71, 0xa6,
  39032. 0x65, 0x48, 0x56, 0x20, 0x8a, 0x48, 0x9d, 0xd7, 0xc9, 0x2c, 0x80, 0x62,
  39033. 0x88, 0x68, 0x4d, 0x5f, 0xbe, 0x5f, 0xe5, 0xf5, 0xa4, 0x75, 0xb6, 0x88,
  39034. 0x26, 0xae, 0x7d, 0x11, 0x43, 0x89, 0xcd, 0xe9, 0x67, 0x0c, 0x91, 0x0b,
  39035. 0xd1, 0xd8, 0x8b, 0x7b, 0x73, 0x75, 0x94, 0xc1, 0xc9, 0x61, 0xc7, 0x35,
  39036. 0x21, 0x99, 0x2e, 0xab, 0xe0, 0xdf, 0x4d, 0xac, 0x0d, 0xd0, 0xa2, 0x61,
  39037. 0x5f, 0x04, 0x08, 0x83, 0x66, 0x5c, 0x67, 0x47, 0x0c, 0xab, 0x2c, 0xb7,
  39038. 0x6d, 0x0e, 0x32, 0x4c, 0x8c, 0x25, 0x80, 0xf5, 0xe5, 0x7e, 0x3b, 0xa1,
  39039. 0xc6, 0xc5, 0x87, 0xd8, 0x68, 0xb2, 0xd5, 0x67, 0xf9, 0x5a, 0x8b, 0x88,
  39040. 0xf8, 0xcd, 0x0c, 0xda, 0x4f, 0xfc, 0xd2, 0xaf, 0xb2, 0xa2, 0x38, 0x21,
  39041. 0xf9, 0xd8, 0xf1, 0x1c, 0x8d, 0xb4, 0xe8, 0xfb, 0x76, 0x36, 0x87, 0xf4,
  39042. 0x7d, 0x03, 0xc4, 0x06, 0xab, 0x87, 0xac, 0x52, 0xe8, 0xd5, 0xf7, 0x63,
  39043. 0xf0, 0xa8, 0x0b, 0x95, 0xbd, 0x07, 0xf1, 0x1d, 0x33, 0x7b, 0x8a, 0x2c,
  39044. 0xef, 0x85, 0xbe, 0xf8, 0xc1, 0x4b, 0xa2, 0xb0, 0xe0, 0x7a, 0x85, 0xfa,
  39045. 0x52, 0x36, 0x05, 0xa7, 0x65, 0x4a, 0x0c, 0x21, 0x5c, 0xc0, 0x4f, 0x18,
  39046. 0xb8, 0x66, 0x02, 0xe6, 0xd0, 0x45, 0x60, 0x56, 0xfc, 0x40, 0x94, 0xb5,
  39047. 0xa5, 0x2b, 0xc7, 0x57, 0xc3, 0xc5, 0x30, 0x72, 0x1c, 0x4c, 0x2a, 0xd5,
  39048. 0x75, 0xae, 0x43, 0x9f, 0x01, 0x71, 0xac, 0x5c, 0xdf, 0x9c, 0x0a, 0x3c,
  39049. 0xb5, 0x89, 0x07, 0x9b, 0x28, 0x25, 0x31, 0x31, 0xc5, 0xb7, 0x24, 0x53,
  39050. 0x2c, 0x3c, 0x2a, 0x96, 0xe5, 0x0d, 0xa2, 0x97, 0xa7, 0x08, 0x9d, 0x31,
  39051. 0xc0, 0xcd, 0x53, 0xd5, 0xa8, 0x58, 0xa6, 0xac, 0x43, 0x2d, 0xac, 0x39,
  39052. 0x01, 0x2c, 0x60, 0xf6, 0x82, 0x86, 0xd0, 0xaf, 0xad, 0x61, 0x3f, 0x82,
  39053. 0x80, 0xa1, 0xe1, 0x12, 0x83, 0x6e, 0x1d, 0x5e, 0xfe, 0xc6, 0x1e, 0x2a,
  39054. 0x7a, 0x44, 0xcd, 0xc2, 0x0a, 0xf5, 0xc8, 0x72, 0x3e, 0x29, 0xc7, 0x0a,
  39055. 0xd1, 0x4c, 0x17, 0xdd, 0x1f, 0xb6, 0x95, 0x34, 0xc2, 0x6c, 0xdc, 0x63,
  39056. 0xd1, 0x7e, 0xb0, 0x52, 0x06, 0x18, 0x6c, 0xb1, 0x99, 0x6a, 0xbe, 0x42,
  39057. 0xa9, 0xc0, 0x22, 0xcc, 0x09, 0x11, 0x84, 0x1f, 0x16, 0x9a, 0x0e, 0xdd,
  39058. 0x18, 0x7a, 0x39, 0x34, 0xb0, 0x49, 0x44, 0xcb, 0x88, 0x1f, 0x91, 0x93,
  39059. 0x49, 0x3f, 0xcc, 0x62, 0x56, 0x33, 0x15, 0xcb, 0x02, 0x9b, 0x33, 0xe8,
  39060. 0xd7, 0xab, 0x51, 0xc0, 0x91, 0xe0, 0x9c, 0xd2, 0xf9, 0x52, 0x05, 0x0c,
  39061. 0xbf, 0xf1, 0x97, 0x42, 0xfe, 0xd0, 0x32, 0x27, 0x34, 0xf8, 0x82, 0x2d,
  39062. 0x65, 0x3a, 0x36, 0xce, 0xd1, 0x07, 0x82, 0x3a, 0x6a, 0xaa, 0x56, 0xf1,
  39063. 0x9b, 0x98, 0xca, 0x8e, 0x55, 0xff, 0xa0, 0x74, 0xd6, 0x6a, 0x42, 0xaa,
  39064. 0x0a, 0xd4, 0x59, 0x74, 0xfb, 0xd4, 0xdb, 0x14, 0x10, 0xee, 0xca, 0x78,
  39065. 0x83, 0x83, 0x95, 0x9b, 0x77, 0xf1, 0x9a, 0x48, 0xe0, 0x8f, 0xa4, 0x5a,
  39066. 0x4d, 0xa9, 0x3f, 0x32, 0x78, 0x4a, 0x25, 0x96, 0x9c, 0x20, 0x0a, 0xcc,
  39067. 0x5b, 0xd8, 0xca, 0x19, 0x47, 0x77, 0xb8, 0x7c, 0x51, 0x3e, 0xd6, 0x30,
  39068. 0xdb, 0x45, 0xb0, 0xe6, 0x9d, 0x6f, 0xc5, 0x0a, 0x5d, 0x5f, 0x55, 0xcd,
  39069. 0x0f, 0x20, 0x22, 0x7e, 0x09, 0x99, 0xac, 0xb8, 0x9c, 0x9d, 0xf7, 0x3e,
  39070. 0x7e, 0x07, 0xd7, 0xbc, 0x21, 0x76, 0x8c, 0x27, 0x81, 0x94, 0xab, 0x57,
  39071. 0x4a, 0xe2, 0x91, 0x1c, 0xa4, 0x77, 0x4a, 0xd2, 0x96, 0x52, 0x9d, 0x33,
  39072. 0xb5, 0x58, 0x70, 0xd7, 0xff, 0x22, 0xe8, 0x14, 0xea, 0xd0, 0x8c, 0xd4,
  39073. 0x06, 0x08, 0xd8, 0x73, 0x66, 0x4b, 0x93, 0x41, 0xc9, 0x73, 0x5b, 0x07,
  39074. 0x5f, 0x31, 0xc5, 0x25, 0x98, 0x7b, 0x7b, 0xa5, 0x26, 0x83, 0x94, 0x22,
  39075. 0x42, 0x1c, 0x51, 0xe6, 0x80, 0x48, 0xca, 0xd4, 0x53, 0x40, 0x3a, 0xee,
  39076. 0x2c, 0x29, 0x07, 0xed, 0xdf, 0x97, 0x44, 0x19, 0xe5, 0xe5, 0x35, 0x66,
  39077. 0x1f, 0xbd, 0x29, 0x77, 0x0c, 0x15, 0x6c, 0x95, 0x08, 0x81, 0xe0, 0x76,
  39078. 0x86, 0x5e, 0x6d, 0x77, 0x78, 0x76, 0x07, 0xdd, 0x21, 0x97, 0x59, 0xdb,
  39079. 0xd4, 0xbd, 0xb6, 0x4c, 0x3f, 0x07, 0x93, 0xb6, 0x4a, 0xce, 0xf7, 0x08,
  39080. 0x86, 0xfd, 0x9c, 0x03, 0x08, 0x94, 0x00, 0xea, 0x4b, 0xd6, 0x1e, 0x17,
  39081. 0xfb, 0xb5, 0xba, 0xde, 0x25, 0x95, 0xe7, 0xf8, 0x97, 0x9e, 0x99, 0xae,
  39082. 0x5d, 0xdd, 0xf6, 0x32, 0x1a, 0xf2, 0x4f, 0xcf, 0x0c, 0x17, 0x55, 0xb8,
  39083. 0xfb, 0xae, 0xc8, 0x46, 0xb0, 0x3e, 0x86, 0x2b, 0x5e, 0xef, 0x36, 0xca,
  39084. 0x24, 0xed, 0x32, 0x5b, 0xc8, 0xfb, 0x88, 0x35, 0x6a, 0x26, 0xfe, 0x06,
  39085. 0x54, 0x0c, 0x3e, 0x2c, 0x71, 0xdf, 0x98, 0xf0, 0xbb, 0xb2, 0xe0, 0x9d,
  39086. 0xf7, 0xeb, 0xce, 0x07, 0xfa, 0xc4, 0xab, 0x88, 0xc3, 0x14, 0x33, 0x60,
  39087. 0x48, 0xcf, 0x39, 0x26, 0x90, 0xac, 0xfa, 0x39, 0x6f, 0x2d, 0x9d, 0x6d,
  39088. 0x15, 0x7f, 0x84, 0x6b, 0x0a, 0x1c, 0xf4, 0x6c, 0x78, 0x62, 0x52, 0x93,
  39089. 0x2c, 0x7e, 0x9f, 0x4a, 0x51, 0x7a, 0x2e, 0xad, 0xea, 0xe4, 0xe5, 0x9c,
  39090. 0x15, 0x15, 0x28, 0x4d, 0x3e, 0x5e, 0xb4, 0x3b, 0xff, 0x81, 0xe0, 0x56,
  39091. 0x44, 0x33, 0x33, 0xd9, 0x4b, 0xb2, 0x23, 0x60, 0xed, 0x0d, 0xa5, 0x4e,
  39092. 0x9f, 0x7d, 0xbc, 0x6e, 0x3a, 0xf9, 0x7e, 0x16, 0x47, 0x66, 0xb1, 0x6c,
  39093. 0xc7, 0x26, 0x62, 0x9b, 0x3c, 0x53, 0xb3, 0xa1, 0x16, 0x62, 0x31, 0x64,
  39094. 0xd2, 0xbb, 0x28, 0x5c, 0xe8, 0x21, 0xc3, 0xfc, 0xc3, 0x6d, 0xa7, 0x35,
  39095. 0x4d, 0x57, 0xe0, 0xbd, 0x54, 0x1a, 0x84, 0xf7, 0x9c, 0x8a, 0x54, 0x3d,
  39096. 0x59, 0xb3, 0xa2, 0x46, 0x3b, 0x16, 0x48, 0x3b, 0x3a, 0x3c, 0x5e, 0x88,
  39097. 0xc3, 0x60, 0x63, 0x7e, 0xca, 0x68, 0xb7, 0x2f, 0x2b, 0xb5, 0x62, 0x2e,
  39098. 0x51, 0x89, 0xbe, 0x78, 0xf7, 0xfa, 0x19, 0xcc, 0xca, 0x87, 0x9a, 0xf5,
  39099. 0xef, 0x0d, 0x21, 0x08, 0x3b, 0xd6, 0x9a, 0x94, 0xc5, 0xd1, 0x1b, 0xa9,
  39100. 0x7c, 0xc8, 0x9f, 0x9a, 0xb0, 0xb8, 0xf7, 0x02, 0x12, 0x31, 0x70, 0x52,
  39101. 0x52, 0xda, 0xb5, 0x9a, 0x08, 0x20, 0xc3, 0xc4, 0x0c, 0x6a, 0x34, 0x58,
  39102. 0x75, 0x9b, 0xdc, 0x1a, 0x6a, 0x37, 0x42, 0x9f, 0x16, 0x70, 0xbb, 0x39,
  39103. 0x86, 0xbd, 0x09, 0x9c, 0x04, 0x44, 0xbe, 0x1a, 0xe5, 0xe9, 0x50, 0x9b,
  39104. 0x14, 0x50, 0x4f, 0x00, 0xba, 0xb0, 0xf6, 0x36, 0x4d, 0x69, 0x16, 0x11,
  39105. 0x40, 0x5a, 0x4e, 0x8b, 0x39, 0xb4, 0xf1, 0xb2, 0x11, 0x36, 0x2f, 0x02,
  39106. 0x15, 0xca, 0x78, 0xde, 0x75, 0x07, 0x64, 0x72, 0xfd, 0xd4, 0x48, 0xdd,
  39107. 0xfb, 0xf5, 0x8a, 0x3d, 0xa8, 0x8e, 0x14, 0xd1, 0x69, 0xe3, 0x21, 0x50,
  39108. 0x39, 0xfd, 0xd0, 0x3b, 0xa0, 0x22, 0x61, 0x5c, 0x7e, 0x88, 0x91, 0xe1,
  39109. 0xf0, 0xf6, 0x16, 0x23, 0xdb, 0xdb, 0x50, 0x0e, 0x39, 0xcc, 0x86, 0xf1,
  39110. 0xab, 0x89, 0x60, 0xb0, 0xac, 0x28, 0xc6, 0x57, 0xe4, 0xee, 0xa9, 0x1b,
  39111. 0xae, 0x78, 0xc5, 0x67, 0x1a, 0xeb, 0xb3, 0x43, 0xbc, 0xea, 0x11, 0x0c,
  39112. 0x64, 0xf6, 0xd2, 0x52, 0xa0, 0x7e, 0xcd, 0x6d, 0x84, 0x8c, 0xf8, 0x80,
  39113. 0xb7, 0xdb, 0x26, 0x91, 0x4a, 0xa0, 0x61, 0x69, 0x2f, 0x6f, 0x1c, 0x9d,
  39114. 0x2a, 0x20, 0x44, 0xdc, 0x58, 0xaf, 0x7d, 0xfe, 0x4d, 0xa2, 0x10, 0x21,
  39115. 0x88, 0xef, 0x42, 0x2e, 0x8e, 0xfb, 0x63, 0xbc, 0xc8, 0x26, 0xe7, 0x80,
  39116. 0xa5, 0xbf, 0xe0, 0x7a, 0xcb, 0xf3, 0x31, 0x1c, 0xd9, 0xa3, 0x12, 0x00,
  39117. 0x2f, 0x20, 0xc6, 0xc1, 0x15, 0xfd, 0x5b, 0x0d, 0x8a, 0x4d, 0xfb, 0x84,
  39118. 0x4d, 0xb4, 0x64, 0xeb, 0x12, 0xf3, 0x78, 0x6b, 0x4d, 0xc6, 0x98, 0x46,
  39119. 0x4c, 0xb3, 0xb4, 0x59, 0xdc, 0xb7, 0xdc, 0xbb, 0x56, 0x0f, 0x09, 0x14,
  39120. 0x28, 0x43, 0x9f, 0xb8, 0x75, 0xed, 0xcb, 0x97, 0x25, 0xaf, 0xa5, 0xeb,
  39121. 0x46, 0x14, 0xa6, 0x38, 0x68, 0x06, 0xe0, 0x6e, 0x55, 0x68, 0x6b, 0xf3,
  39122. 0xd8, 0x6d, 0x59, 0x65, 0x65, 0xff, 0x48, 0xfd, 0xdb, 0x3d, 0xe2, 0x21,
  39123. 0xb4, 0x7b, 0x78, 0x6a, 0x2e, 0x28, 0xb8, 0x21, 0xc4, 0x72, 0xf4, 0xef,
  39124. 0xfb, 0x74, 0x43, 0x29, 0xf2, 0x30, 0xc9, 0xca, 0x78, 0x93, 0x72, 0xfd,
  39125. 0x84, 0xa4, 0x95, 0xe0, 0xcd, 0xb1, 0x48, 0x29, 0xe7, 0xd1, 0x27, 0xf7,
  39126. 0xdc, 0x31, 0x6e, 0x00, 0x04, 0xd7, 0x7c, 0xfd, 0x2d, 0x25, 0xe9, 0xdb,
  39127. 0xc2, 0xb8, 0x14, 0x26, 0xed, 0x63, 0xb1, 0x50, 0x0a, 0x3c, 0xb2, 0x79,
  39128. 0x98, 0x79, 0x81, 0x2d, 0xdb, 0x60, 0x97, 0x99, 0xc0, 0x0a, 0x89, 0x9f,
  39129. 0x90, 0x19, 0x0b, 0xb3, 0x97, 0xd2, 0xf7, 0x50, 0xa5, 0x1d, 0x7d, 0x71,
  39130. 0x75, 0xe6, 0x58, 0x62, 0x53, 0x95, 0x40, 0x9e, 0xc7, 0xd3, 0x72, 0xa1,
  39131. 0xae, 0x07, 0xb3, 0x8a, 0x56, 0x61, 0x99, 0x81, 0x3e, 0xe4, 0x5e, 0x78,
  39132. 0x57, 0xd1, 0x8a, 0xc4, 0x04, 0x38, 0x13, 0xa0, 0x5d, 0x68, 0x6d, 0x22,
  39133. 0xae, 0xda, 0xfc, 0x67, 0xbb, 0xfb, 0x8e, 0x1a, 0xdc, 0x24, 0xf7, 0xc8,
  39134. 0xf9, 0x92, 0x6f, 0x4e, 0xb5, 0xe7, 0x6d, 0x13, 0x88, 0x05, 0x5c, 0xbb,
  39135. 0xe0, 0x24, 0x2a, 0x96, 0xc6, 0x70, 0x52, 0x14, 0xd0, 0xd9, 0xd8, 0xb2,
  39136. 0x5b, 0xdc, 0x85, 0xcf, 0x62, 0xb4, 0xcf, 0x77, 0xf1, 0xe5, 0x51, 0xeb,
  39137. 0xef, 0xe9, 0x3e, 0xf0, 0x16, 0xd2, 0xcc, 0x38, 0x0a, 0x47, 0x91, 0xc0,
  39138. 0xe0, 0x14, 0x1a, 0xf9, 0x74, 0xd1, 0x32, 0x8b, 0x02, 0x36, 0x05, 0x55,
  39139. 0x62, 0xa7, 0xae, 0x77, 0xb0, 0x01, 0x3d, 0x2c, 0x91, 0xbe, 0xfa, 0xdd,
  39140. 0x9c, 0x17, 0x42, 0xc1, 0x01, 0x4d, 0xd8, 0x27, 0x3c, 0x10, 0x82, 0x66,
  39141. 0x11, 0x91, 0x8b, 0xc8, 0x52, 0xd5, 0xc1, 0x1d, 0xee, 0xb2, 0x90, 0x17,
  39142. 0xed, 0xf3, 0xad, 0xa5, 0xd5, 0xeb, 0xf2, 0x9b, 0x78, 0xbf, 0x2d, 0x5a,
  39143. 0xad, 0xe5, 0x53, 0xe6, 0xc1, 0x3b, 0xd8, 0xf3, 0x6b, 0xc5, 0x4c, 0x87,
  39144. 0x0a, 0xe3, 0xc8, 0xc7, 0xe5, 0x42, 0x2c, 0xe2, 0x13, 0x1a, 0xe7, 0x27,
  39145. 0x20, 0x3e, 0x95, 0x13, 0x1e, 0xbb, 0x03, 0xae, 0xc0, 0x84, 0x14, 0x6d,
  39146. 0x7b, 0xf7, 0x98, 0x08, 0x18, 0x12, 0xb4, 0x4f, 0x99, 0x4a, 0xcf, 0xd0,
  39147. 0x4a, 0x5d, 0x21, 0x16, 0xf6, 0xdf, 0x10, 0xc7, 0xbe, 0xe6, 0x79, 0x3b,
  39148. 0x35, 0x2a, 0xa6, 0xd6, 0x19, 0x9c, 0xde, 0xbd, 0xaf, 0x72, 0xd2, 0x25,
  39149. 0xe0, 0xa4, 0xde, 0x99, 0x44, 0x18, 0x66, 0x41, 0xc7, 0x56, 0xf7, 0xdc,
  39150. 0x32, 0x56, 0x57, 0x39, 0x18, 0x31, 0xc8, 0x75, 0x01, 0xc3, 0xf3, 0x46,
  39151. 0xcf, 0xbf, 0xc6, 0x10, 0xb5, 0x1c, 0x38, 0xf9, 0xa4, 0xa5, 0x44, 0xa1,
  39152. 0x0b, 0x25, 0x48, 0x9c, 0xd3, 0x1c, 0x55, 0x54, 0x15, 0x9f, 0xe3, 0x74,
  39153. 0x5b, 0xb1, 0x92, 0xb6, 0x52, 0x61, 0xba, 0x2f, 0x53, 0x91, 0x17, 0x44,
  39154. 0x94, 0x00, 0xe4, 0x43, 0xa0, 0xe7, 0x0d, 0xaa, 0x8a, 0x5b, 0x81, 0x43,
  39155. 0xad, 0xfb, 0x50, 0xfe, 0xcf, 0x85, 0x2d, 0xfa, 0xc8, 0x1d, 0xad, 0xc8,
  39156. 0x7a, 0x7c, 0x5e, 0xf3, 0x90, 0x35, 0x5e, 0x67, 0xce, 0x57, 0x4d, 0xa0,
  39157. 0x22, 0x9e, 0x07, 0x4a, 0xf5, 0x9e, 0x5f, 0x91, 0x45, 0xd8, 0x62, 0xe0,
  39158. 0xf3, 0x87, 0x3b, 0xb7, 0x89, 0x2f, 0xdf, 0x8b, 0x82, 0xb1, 0x86, 0xc3,
  39159. 0xa4, 0xa3, 0x68, 0xc7, 0x73, 0x9e, 0x68, 0x8d, 0x24, 0x6a, 0x29, 0x94,
  39160. 0x58, 0x57, 0x4b, 0x81, 0x00, 0xe2, 0x2b, 0x94, 0x0a, 0xf5, 0x96, 0xa3,
  39161. 0x23, 0x9a, 0x7b, 0xd0, 0x2d, 0xcb, 0x6a, 0x8e, 0xae, 0x1b, 0x1c, 0x34,
  39162. 0xed, 0x30, 0x4e, 0xca, 0x29, 0x21, 0xfc, 0x3d, 0x70, 0x11, 0xc1, 0x5f,
  39163. 0x3e, 0xc2, 0x9e, 0x88, 0x71, 0x29, 0xa3, 0x8f, 0x92, 0xf5, 0x46, 0x77,
  39164. 0xd5, 0x47, 0x2d, 0x2b, 0x66, 0x1c, 0x07, 0xf0, 0xfc, 0x7b, 0xa0, 0x13,
  39165. 0x00, 0xae, 0xa5, 0x61, 0x92, 0x36, 0xeb, 0x7e, 0x43, 0x91, 0x20, 0x72,
  39166. 0xe5, 0xba, 0x7f, 0x79, 0x23, 0x12, 0x3e, 0xb2, 0x4b, 0x13, 0xa1, 0x8c,
  39167. 0x84, 0x72, 0x3b, 0x45, 0x62, 0xcf, 0x2e, 0x78, 0xc4, 0x9c, 0x22, 0x09,
  39168. 0xfa, 0x59, 0x9d, 0xdf, 0x13, 0x54, 0x66, 0xe2, 0x6f, 0xfa, 0xb5, 0x2a,
  39169. 0x27, 0x3e, 0x17, 0x82, 0xf3, 0x2a, 0x4d, 0x36, 0xd3, 0xf0, 0x8d, 0x43,
  39170. 0x40, 0x2c, 0x84, 0x68, 0xbe, 0x40, 0x50, 0x7d, 0xa3, 0x27, 0x5e, 0xde,
  39171. 0x4d, 0x04, 0x6f, 0xe8, 0x96, 0x9c, 0x7a, 0x1d, 0xb8, 0x2b, 0x8a, 0xb1,
  39172. 0x6e, 0xe2, 0x36, 0x07, 0x22, 0x50, 0xd9, 0x71, 0x93, 0x48, 0xb5, 0x51,
  39173. 0xce, 0x2a, 0x64, 0x6b, 0x11, 0xa6, 0xb9, 0x40, 0x2d, 0x6c, 0xd2, 0x76,
  39174. 0x52, 0xc6, 0xe3, 0xa6, 0x6b, 0xd2, 0x3f, 0x39, 0xd2, 0x13, 0x28, 0xa4,
  39175. 0xa9, 0x58, 0x99, 0xe8, 0x3d, 0x08, 0xfa, 0x3c, 0x34, 0x39, 0x4d, 0x7d,
  39176. 0x5e, 0x10, 0x72, 0x51, 0x96, 0x1d, 0x4b, 0xd9, 0x3e, 0xc9, 0x22, 0x4c,
  39177. 0x72, 0x63, 0xf8, 0x87, 0x4b, 0xe7, 0x41, 0xac, 0xcd, 0xd6, 0x34, 0xa2,
  39178. 0xe1, 0xe8, 0x66, 0x81, 0x04, 0x7d, 0x70, 0x95, 0xba, 0x37, 0x86, 0x9e,
  39179. 0x1f, 0x9a, 0x1b, 0xe4, 0x35, 0xac, 0xe6, 0xcf, 0x48, 0x55, 0x6e, 0xbb,
  39180. 0x9d, 0x40, 0x79, 0x96, 0xdd, 0xac, 0xf8, 0xf5, 0x99, 0xad, 0x43, 0x0d,
  39181. 0xad, 0xa9, 0x62, 0xc0, 0x70, 0x8b, 0x50, 0x9b, 0xca, 0x0d, 0x3e, 0x54,
  39182. 0x9c, 0x27, 0xd5, 0x9e, 0x20, 0xe2, 0xe0, 0xb0, 0xb0, 0xbe, 0x8e, 0x56,
  39183. 0x43, 0x95, 0x9b, 0x34, 0xd1, 0x05, 0x28, 0xa0, 0xee, 0xd9, 0xab, 0x6a,
  39184. 0xa7, 0xbb, 0xb7, 0x1b, 0x3a, 0x5d, 0x33, 0x97, 0x25, 0x54, 0xe4, 0x0e,
  39185. 0x64, 0x79, 0xed, 0x16, 0x62, 0x89, 0x70, 0x4a, 0xa6, 0x47, 0x40, 0xd7,
  39186. 0xa3, 0xd2, 0x6f, 0x28, 0xdd, 0xc5, 0x04, 0xab, 0x7e, 0x7e, 0x1e, 0xb0,
  39187. 0x19, 0x02, 0x48, 0xb5, 0x88, 0x82, 0x75, 0xaf, 0x66, 0x74, 0xca, 0xf6,
  39188. 0xd7, 0xe8, 0x6d, 0xfa, 0x5e, 0xfa, 0xaf, 0xa8, 0x04, 0xaa, 0x2c, 0x09,
  39189. 0xf1, 0x4c, 0x36, 0x75, 0xb5, 0xdc, 0xe8, 0x04, 0x80, 0xd3, 0x14, 0x78,
  39190. 0x09, 0x5b, 0xfd, 0x52, 0x6f, 0xd9, 0x3c, 0x1c, 0x02, 0x3b, 0x77, 0xb8,
  39191. 0xa1, 0xe9, 0xa4, 0xb7, 0x42, 0x62, 0xee, 0xea, 0x43, 0xf3, 0xd8, 0xd0,
  39192. 0x7a, 0x53, 0x91, 0x34, 0x7f, 0xe7, 0x9a, 0xc6
  39193. };
  39194. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39195. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_pub_key[] = {
  39196. 0x15, 0xc9, 0xe5, 0x53, 0x2f, 0xd8, 0x1f, 0xb4, 0xa3, 0x9f,
  39197. 0xae, 0xad, 0xb3, 0x10, 0xd0, 0x72, 0x69, 0xd3, 0x02, 0xf3,
  39198. 0xdf, 0x67, 0x5a, 0x31, 0x52, 0x19, 0xca, 0x39, 0x27, 0x77,
  39199. 0x61, 0x6d, 0x0f, 0xc1, 0x33, 0x26, 0x09, 0xf0, 0xf9, 0x4d,
  39200. 0x12, 0x7a, 0xef, 0xf7, 0x21, 0x26, 0x2c, 0xe0, 0xe2, 0x92,
  39201. 0x1f, 0x9d, 0xd1, 0xaa, 0xaf, 0x08, 0x14, 0xf2, 0xaa, 0x24,
  39202. 0x99, 0x0f, 0x20, 0x57, 0x35, 0x04, 0x32, 0x96, 0x8e, 0x6e,
  39203. 0x10, 0x64, 0xe3, 0xe3, 0x57, 0x26, 0x33, 0x32, 0x7b, 0xe4,
  39204. 0x18, 0x41, 0x77, 0xd3, 0x24, 0x63, 0x3d, 0x11, 0xea, 0xdc,
  39205. 0xbe, 0x59, 0xff, 0x8d, 0xc2, 0xe4, 0xc7, 0x04, 0xf3, 0xd4,
  39206. 0xe0, 0x1d, 0x5e, 0x09, 0x46, 0xbf, 0x02, 0x05, 0xc7, 0xa6,
  39207. 0xb7, 0x82, 0x40, 0x1f, 0x55, 0xe9, 0x77, 0x82, 0xc0, 0xcc,
  39208. 0x86, 0x99, 0x19, 0x99, 0xa2, 0xc9, 0x1b, 0x4f, 0xdd, 0x49,
  39209. 0x4c, 0x78, 0x0a, 0x58, 0xb8, 0xf0, 0x23, 0xac, 0x1a, 0x71,
  39210. 0x57, 0x6d, 0xd6, 0x3a, 0x3a, 0x6f, 0x93, 0xb3, 0x2b, 0x09,
  39211. 0xbe, 0xec, 0x7b, 0x5b, 0xf7, 0x3a, 0xed, 0xf9, 0xd0, 0xb1,
  39212. 0xfe, 0x9f, 0x9b, 0xec, 0x11, 0xb6, 0x6b, 0xd1, 0xb6, 0x00,
  39213. 0x72, 0x7f, 0x68, 0x9a, 0x61, 0xa5, 0xf5, 0x6e, 0xe9, 0x46,
  39214. 0xa4, 0x82, 0x08, 0x9f, 0x50, 0x4c, 0x75, 0xc3, 0x48, 0x85,
  39215. 0x76, 0x39, 0xea, 0x0c, 0xf2, 0xe8, 0x7e, 0x48, 0x69, 0xd9,
  39216. 0x6f, 0x9a, 0x89, 0x7d, 0x98, 0xc1, 0x16, 0xdc, 0x2f, 0xc7,
  39217. 0x0a, 0x11, 0xa8, 0xbb, 0xe7, 0x91, 0xb1, 0x0f, 0x0e, 0xf0,
  39218. 0xb4, 0xc8, 0x41, 0x7e, 0x62, 0x9e, 0x3c, 0x30, 0x4c, 0xbc,
  39219. 0x4c, 0xeb, 0x37, 0xaf, 0x48, 0x72, 0x59, 0x64, 0x8e, 0xfb,
  39220. 0x77, 0x11, 0x28, 0xdd, 0x30, 0x52, 0x8e, 0x69, 0x8c, 0x9f,
  39221. 0x3d, 0xec, 0xdf, 0xa7, 0x5f, 0x42, 0x18, 0xda, 0xba, 0x1a,
  39222. 0x96, 0x91, 0x7d, 0x62, 0xd5, 0x52, 0xff, 0x44, 0xc9, 0x1d,
  39223. 0x29, 0xa6, 0xb9, 0x03, 0x9a, 0x26, 0x26, 0xcf, 0x57, 0x40,
  39224. 0x70, 0x7e, 0x2b, 0xbd, 0xf0, 0x81, 0x71, 0x0f, 0x0b, 0x2e,
  39225. 0x9b, 0x03, 0xba, 0x31, 0x41, 0x68, 0x37, 0xc8, 0xff, 0xea,
  39226. 0xc4, 0x73, 0xa5, 0xf9, 0xc2, 0x92, 0x78, 0x0c, 0xe7, 0xfd,
  39227. 0x5d, 0xb2, 0x01, 0xb5, 0x8d, 0xeb, 0x64, 0xd4, 0x14, 0xea,
  39228. 0x7a, 0xd1, 0x42, 0xc8, 0x99, 0xe4, 0x7d, 0x5b, 0x7e, 0x3b,
  39229. 0x8f, 0xab, 0x82, 0x12, 0xdf, 0xbb, 0xa1, 0x45, 0x30, 0xc9,
  39230. 0x0f, 0xb9, 0xe5, 0xba, 0xe6, 0x8a, 0xf3, 0x78, 0x61, 0xcc,
  39231. 0x9f, 0xe1, 0x46, 0x2a, 0x9a, 0x18, 0x0e, 0x2a, 0x57, 0xf3,
  39232. 0xe5, 0x56, 0xd1, 0x42, 0x48, 0xe1, 0x5a, 0x8e, 0x33, 0xce,
  39233. 0x19, 0xe5, 0x3e, 0x7f, 0x00, 0x70, 0x9c, 0x4c, 0xd3, 0xe1,
  39234. 0x0c, 0xa1, 0x7e, 0xd4, 0xa9, 0x9e, 0x8b, 0xe2, 0xf0, 0xac,
  39235. 0xdb, 0xa6, 0x72, 0x75, 0x67, 0xa6, 0x57, 0xed, 0x79, 0x2e,
  39236. 0xca, 0x8d, 0xeb, 0x9b, 0x9e, 0xb7, 0xbf, 0x30, 0x02, 0x2b,
  39237. 0xb3, 0x43, 0x89, 0x9b, 0xa8, 0x88, 0xa5, 0xbb, 0x33, 0xd9,
  39238. 0x99, 0x30, 0x7c, 0xc7, 0xd4, 0x28, 0x5e, 0x5e, 0x3f, 0x9d,
  39239. 0x6d, 0x35, 0x75, 0x33, 0x8e, 0xff, 0x84, 0x2e, 0x2d, 0xda,
  39240. 0xf0, 0xff, 0x70, 0xe5, 0xb5, 0x62, 0x96, 0x33, 0x3a, 0xd9,
  39241. 0xb5, 0x82, 0x25, 0x81, 0x81, 0x40, 0x5d, 0x4f, 0x11, 0x86,
  39242. 0x63, 0x1a, 0x06, 0xc1, 0x67, 0xc7, 0x49, 0x03, 0xc7, 0xe4,
  39243. 0x6f, 0xb4, 0x13, 0x3e, 0x57, 0x62, 0xfd, 0x8a, 0xc6, 0x2b,
  39244. 0x65, 0x5b, 0xa4, 0x29, 0x57, 0x8d, 0xde, 0xa5, 0xee, 0x32,
  39245. 0xc2, 0x76, 0x03, 0xca, 0xce, 0xc1, 0x48, 0xec, 0x45, 0xcf,
  39246. 0x30, 0x21, 0x28, 0x7f, 0x10, 0x47, 0xd2, 0xdb, 0xee, 0xca,
  39247. 0x5b, 0x0f, 0xd5, 0x39, 0x3a, 0xc3, 0xa6, 0x78, 0xb2, 0x15,
  39248. 0xaf, 0x82, 0x3c, 0x2f, 0xc4, 0x51, 0x5c, 0x52, 0xad, 0xf2,
  39249. 0x89, 0x92, 0x8e, 0xf3, 0x50, 0x38, 0xed, 0xf8, 0xc9, 0x14,
  39250. 0x4c, 0xe4, 0xa3, 0x9a, 0xaf, 0xc4, 0x5c, 0xf3, 0x9f, 0xc3,
  39251. 0xa3, 0xc0, 0xbe, 0x45, 0x1b, 0x21, 0x63, 0xfa, 0xe0, 0xe0,
  39252. 0x91, 0x2b, 0x42, 0xca, 0x91, 0xfb, 0x5e, 0x97, 0x9a, 0x0a,
  39253. 0xd4, 0x88, 0xba, 0xb8, 0x22, 0xc6, 0xbf, 0x56, 0x58, 0x1e,
  39254. 0x92, 0xa9, 0x9d, 0xa7, 0xed, 0xc9, 0xab, 0x54, 0x4f, 0x75,
  39255. 0x8d, 0x42, 0xc1, 0xe1, 0x61, 0xd0, 0x91, 0x9a, 0x3a, 0x40,
  39256. 0x9a, 0xa3, 0xfb, 0x7b, 0x4e, 0xf0, 0x85, 0xf0, 0xdc, 0x40,
  39257. 0x72, 0x9f, 0x05, 0xa8, 0xbe, 0x95, 0x5a, 0x7f, 0xba, 0x75,
  39258. 0x00, 0x6e, 0x95, 0x76, 0xbd, 0xb2, 0x40, 0xf5, 0xb0, 0x64,
  39259. 0x0a, 0x2f, 0x06, 0x3d, 0x9f, 0xac, 0x6a, 0xa5, 0x46, 0x5a,
  39260. 0x85, 0xa4, 0x6f, 0xee, 0x27, 0xa0, 0xeb, 0x5f, 0x1f, 0x91,
  39261. 0xbd, 0x2b, 0x02, 0x16, 0xdf, 0x74, 0x97, 0x2c, 0xd0, 0xa8,
  39262. 0x9f, 0x3a, 0x7b, 0xdf, 0x3e, 0x98, 0x4a, 0x91, 0xdc, 0x19,
  39263. 0x96, 0x88, 0x75, 0x21, 0x1a, 0x6a, 0xa8, 0x4b, 0x1f, 0x35,
  39264. 0xd1, 0x92, 0xf5, 0x76, 0xf4, 0x72, 0x55, 0x13, 0xdb, 0x5d,
  39265. 0x07, 0x8d, 0xd9, 0x72, 0xe4, 0x75, 0xde, 0x80, 0xbc, 0xe9,
  39266. 0x9c, 0xf0, 0x5c, 0x6a, 0x8a, 0x0e, 0x34, 0xf6, 0x3f, 0x5c,
  39267. 0xef, 0x0e, 0xcc, 0x52, 0x38, 0x2d, 0x7b, 0xc2, 0x1b, 0x69,
  39268. 0x9f, 0xe5, 0xed, 0x14, 0xb0, 0x91, 0x0b, 0xe9, 0x4d, 0x34,
  39269. 0xd5, 0xaa, 0xd4, 0xd2, 0x46, 0x39, 0x45, 0x7e, 0x85, 0x2f,
  39270. 0xdb, 0x89, 0xf4, 0xff, 0x05, 0x74, 0x51, 0xba, 0xdd, 0xee,
  39271. 0xf6, 0xc2, 0xc1, 0x0a, 0x8f, 0xd9, 0xeb, 0xc7, 0x61, 0x30,
  39272. 0x8f, 0x86, 0x8b, 0x1f, 0x82, 0xc1, 0x22, 0xfd, 0x83, 0xf4,
  39273. 0x5d, 0xc5, 0x94, 0xf5, 0xd7, 0x17, 0xc7, 0x7b, 0x71, 0xf5,
  39274. 0x5e, 0x15, 0x49, 0x70, 0xb2, 0x57, 0xa0, 0xc0, 0x57, 0x63,
  39275. 0x53, 0x35, 0xb6, 0x52, 0x20, 0x7b, 0x83, 0xd4, 0x57, 0x63,
  39276. 0x25, 0x8e, 0x83, 0xb3, 0x8e, 0x26, 0x1f, 0x09, 0xde, 0x14,
  39277. 0xd6, 0xa6, 0xfc, 0xe5, 0x93, 0x3c, 0x88, 0x8e, 0xf5, 0x10,
  39278. 0x57, 0xb9, 0xc9, 0x9b, 0xff, 0x72, 0x9d, 0x3d, 0x3f, 0x97,
  39279. 0xd9, 0x3c, 0x20, 0xe2, 0x57, 0xfd, 0x2a, 0x5c, 0x17, 0x12,
  39280. 0xe6, 0x08, 0xaf, 0xe4, 0x26, 0x96, 0xb9, 0x6d, 0xc3, 0xac,
  39281. 0x22, 0xf3, 0x8b, 0x89, 0xde, 0xc7, 0x8a, 0x93, 0x06, 0xf7,
  39282. 0x1d, 0x08, 0x21, 0x36, 0x16, 0x74, 0x2b, 0x97, 0x23, 0xe4,
  39283. 0x79, 0x31, 0x08, 0x23, 0x62, 0x30, 0x67, 0xe2, 0xed, 0x30,
  39284. 0x9b, 0x0c, 0xf9, 0x08, 0x7a, 0x29, 0x73, 0xc6, 0x77, 0x8a,
  39285. 0xbb, 0x2a, 0x1c, 0x66, 0xd0, 0xdd, 0x9e, 0xa3, 0xe9, 0x62,
  39286. 0xcc, 0xb7, 0x88, 0x25, 0x4a, 0x5f, 0xbc, 0xaa, 0xe3, 0xe4,
  39287. 0x4f, 0xec, 0xa6, 0x8e, 0xa6, 0xa4, 0x1b, 0x22, 0x2b, 0x2c,
  39288. 0x8f, 0x57, 0x7f, 0xb7, 0x33, 0xfe, 0x16, 0x43, 0x85, 0xc5,
  39289. 0xd2, 0x95, 0xe6, 0xb9, 0x21, 0x68, 0x88, 0x98, 0x33, 0x8c,
  39290. 0x1d, 0x15, 0x9c, 0x4d, 0x62, 0x1f, 0x6b, 0xe8, 0x7a, 0x2d,
  39291. 0x6b, 0x0e, 0xc3, 0xde, 0x1a, 0xa8, 0xed, 0x67, 0xb3, 0xb3,
  39292. 0x36, 0x5b, 0x4b, 0xcb, 0xe8, 0xa8, 0x5c, 0x0b, 0x2f, 0xca,
  39293. 0xd7, 0x71, 0xe8, 0x85, 0xe7, 0x4d, 0xe5, 0x7b, 0x45, 0xed,
  39294. 0xb2, 0x4c, 0x69, 0x04, 0x7e, 0x4f, 0xc0, 0xef, 0x1a, 0xca,
  39295. 0x0d, 0xa6, 0xc4, 0x79, 0x15, 0x78, 0x9c, 0xd2, 0x91, 0x3c,
  39296. 0x32, 0x55, 0x40, 0xe7, 0xcb, 0x7e, 0xde, 0x07, 0xa6, 0x97,
  39297. 0x00, 0x2d, 0x70, 0xf6, 0x3d, 0x15, 0xdf, 0x29, 0x8e, 0xa3,
  39298. 0x96, 0x6d, 0xf2, 0xbb, 0xa5, 0x1b, 0x7b, 0x58, 0x30, 0xf6,
  39299. 0x17, 0xbd, 0xda, 0x13, 0xf7, 0x33, 0xc2, 0x62, 0x32, 0xd4,
  39300. 0x1c, 0x2e, 0x31, 0x74, 0x92, 0xad, 0x99, 0x8c, 0x0e, 0x7c,
  39301. 0x50, 0x21, 0xcd, 0xff, 0x41, 0xeb, 0xd1, 0xca, 0x14, 0xb7,
  39302. 0xb2, 0x31, 0x2f, 0xbe, 0x16, 0xce, 0x4f, 0x26, 0x16, 0x04,
  39303. 0xc2, 0xaf, 0xbe, 0x0d, 0x24, 0xab, 0x9a, 0x21, 0x37, 0x06,
  39304. 0xac, 0x50, 0x23, 0xf1, 0xbe, 0x5c, 0xbb, 0x64, 0xf3, 0xd3,
  39305. 0x66, 0xa3, 0xb8, 0xbe, 0x8b, 0x49, 0x8d, 0xf6, 0xc7, 0xb9,
  39306. 0x8f, 0x4e, 0x31, 0x06, 0x51, 0xe5, 0xf3, 0x0e, 0x56, 0xc4,
  39307. 0x24, 0x30, 0xf5, 0xe9, 0x36, 0x71, 0xbc, 0xc9, 0x70, 0x2c,
  39308. 0x6c, 0x4c, 0x15, 0x43, 0x44, 0xa4, 0xfc, 0xf1, 0xd2, 0x71,
  39309. 0x6c, 0x4c, 0xce, 0x30, 0x6c, 0x05, 0x7d, 0x2e, 0xb7, 0xbc,
  39310. 0xe4, 0x65, 0x76, 0x24, 0x75, 0x36, 0xdf, 0x28, 0xfc, 0xcd,
  39311. 0x9a, 0xba, 0xc2, 0xcd, 0xb0, 0x30, 0xdb, 0xe7, 0x2e, 0x3c,
  39312. 0x92, 0x63, 0x1d, 0x30, 0x23, 0x74, 0xb1, 0xb8, 0xcc, 0xd7,
  39313. 0xb6, 0x90, 0x65, 0x73, 0xa2, 0x2a, 0x6e, 0x49, 0x95, 0x0d,
  39314. 0xab, 0x24, 0xdf, 0x2d, 0xbf, 0x76, 0x46, 0x01, 0x44, 0xe4,
  39315. 0x18, 0x8e, 0xd5, 0x9a, 0x76, 0xc9, 0xc6, 0xbc, 0xdb, 0x7f,
  39316. 0x80, 0x52, 0xc6, 0x40, 0x41, 0x12, 0x36, 0x7c, 0x80, 0x69,
  39317. 0xce, 0x7b, 0xe1, 0xa0, 0x53, 0xa2, 0xd6, 0x8f, 0x3f, 0xf7,
  39318. 0xd7, 0x61, 0x09, 0x70, 0xa2, 0xa0, 0xc6, 0xaf, 0xa0, 0xd0,
  39319. 0xfa, 0x13, 0xbf, 0xc0, 0x69, 0x15, 0xce, 0x15, 0xec, 0x24,
  39320. 0x4b, 0x6b, 0xdc, 0x93, 0x51, 0xc6, 0x82, 0x19, 0x92, 0x84,
  39321. 0x5d, 0x99, 0xb0, 0x90, 0x2c, 0xcc, 0x2a, 0x81, 0x6b, 0x22,
  39322. 0x64, 0x0a, 0xcb, 0x51, 0x25, 0x82, 0x50, 0x02, 0x2d, 0x3e,
  39323. 0xd4, 0x72, 0xb3, 0x0c, 0x15, 0x77, 0xd2, 0xca, 0x98, 0x2f,
  39324. 0x41, 0x93, 0x14, 0xb2, 0x7f, 0xa1, 0x97, 0xa3, 0xb8, 0x8a,
  39325. 0x56, 0x24, 0x38, 0xa7, 0x36, 0xc5, 0x01, 0xc0, 0x9f, 0x3f,
  39326. 0x3e, 0x9a, 0xf6, 0xe9, 0x16, 0x82, 0x01, 0x58, 0x70, 0x0e,
  39327. 0x0d, 0xbc, 0xfa, 0x03, 0x57, 0x65, 0xa8, 0x5a, 0x3d, 0x57,
  39328. 0x81, 0x23, 0xbe, 0x6e, 0xa9, 0xe8, 0x22, 0xdf, 0x2f, 0x70,
  39329. 0xeb, 0x0a, 0x03, 0x96, 0x6b, 0xef, 0x20, 0x9f, 0xf2, 0x62,
  39330. 0xe7, 0xb2, 0x6e, 0x3a, 0x1e, 0x40, 0x1f, 0xd2, 0x97, 0x48,
  39331. 0xd1, 0x18, 0xf0, 0xeb, 0x52, 0x58, 0x02, 0x26, 0xce, 0x75,
  39332. 0xb1, 0x3a, 0x9d, 0x5b, 0x52, 0x94, 0xb2, 0x6e, 0x0e, 0x3f,
  39333. 0x39, 0xb6, 0xd9, 0x8a, 0x9d, 0xe8, 0x7c, 0x83, 0x32, 0xcc,
  39334. 0x43, 0x35, 0x9b, 0x7a, 0xed, 0xb2, 0x1e, 0x51, 0x37, 0x6c,
  39335. 0x14, 0xd8, 0xb8, 0x55, 0xb3, 0x91, 0xef, 0x0c, 0x3a, 0xe5,
  39336. 0x77, 0xd0, 0xbd, 0xb0, 0x7d, 0x38, 0x84, 0x2a, 0x47, 0xb2,
  39337. 0xb6, 0xda, 0xd7, 0x75, 0xd6, 0x2e, 0x60, 0xc7, 0x10, 0x52,
  39338. 0xf7, 0xdd, 0x09, 0x15, 0x6f, 0x04, 0x31, 0xc3, 0x5a, 0x6b,
  39339. 0x0c, 0x60, 0x10, 0xa8, 0x6e, 0x20, 0xa9, 0xdd, 0xb7, 0x72,
  39340. 0xc3, 0x9e, 0x85, 0xd2, 0x8f, 0x16, 0x7e, 0x3d, 0xe0, 0x63,
  39341. 0x81, 0x32, 0xfd, 0xca, 0xbc, 0x0f, 0xef, 0x3e, 0x74, 0x6a,
  39342. 0xb1, 0x60, 0xc1, 0x10, 0x50, 0x7c, 0x67, 0xa4, 0x19, 0xa7,
  39343. 0xb8, 0xed, 0xe6, 0xf5, 0x4e, 0x41, 0x53, 0xa6, 0x72, 0x1b,
  39344. 0x2c, 0x33, 0x6a, 0x37, 0xf1, 0xb5, 0x1c, 0x01, 0x7d, 0xa2,
  39345. 0x1f, 0x2c, 0x4e, 0x0a, 0xbf, 0xd4, 0x2c, 0x24, 0x91, 0x58,
  39346. 0x62, 0xfb, 0xf8, 0x63, 0xd9, 0xf8, 0x78, 0xf5, 0xc7, 0x78,
  39347. 0x32, 0xda, 0x99, 0xeb, 0x58, 0x20, 0x25, 0x19, 0xb1, 0x06,
  39348. 0x7f, 0x6a, 0x29, 0x20, 0xdb, 0xc8, 0x22, 0x48, 0xa9, 0x7f,
  39349. 0x24, 0x54, 0x8d, 0x7d, 0x8d, 0xb1, 0x69, 0xb2, 0xa3, 0x98,
  39350. 0x14, 0x0f, 0xba, 0xfa, 0xb6, 0x15, 0xe8, 0x28, 0x99, 0x3f,
  39351. 0x30, 0x04, 0x50, 0xab, 0x5a, 0x3c, 0xf1, 0x97, 0xe1, 0xc8,
  39352. 0x0f, 0x0e, 0xb4, 0x11, 0x63, 0x5a, 0x79, 0x08, 0x48, 0x75,
  39353. 0xaf, 0x9b, 0xca, 0xd9, 0x13, 0x18, 0xcc, 0xb1, 0xb3, 0xee,
  39354. 0xdd, 0x63, 0xdd, 0xf4, 0x21, 0x98, 0x76, 0xe2, 0x3e, 0xd5,
  39355. 0x86, 0x23, 0x33, 0x7e, 0xc7, 0xb4, 0x35, 0x4b, 0xc2, 0x2d,
  39356. 0xe1, 0xe2, 0xb0, 0x6c, 0x8b, 0x9b, 0x20, 0x3d, 0x48, 0x24,
  39357. 0x7c, 0xea, 0xa1, 0x75, 0x27, 0xe5, 0xf4, 0x70, 0xeb, 0x3b,
  39358. 0xc7, 0x26, 0x37, 0x04, 0xff, 0x8a, 0x7a, 0xd0, 0xc2, 0xb7,
  39359. 0x84, 0xb7, 0x29, 0xfb, 0x0e, 0xa3, 0xa8, 0x71, 0xcd, 0x58,
  39360. 0x06, 0x36, 0xe2, 0xf2, 0x77, 0xcc, 0x0f, 0x78, 0x08, 0x2b,
  39361. 0xbb, 0xe3, 0x53, 0x05, 0x71, 0xdc, 0x6c, 0x37, 0x32, 0x91,
  39362. 0x46, 0x42, 0x4f, 0x21, 0xe0, 0x34, 0xad, 0x3f, 0x30, 0x5a,
  39363. 0xc7, 0x0d, 0x17, 0x19, 0x39, 0x31, 0x58, 0x69, 0x3c, 0x8c,
  39364. 0xbe, 0xe7, 0xa6, 0x3b, 0xad, 0xfb, 0x46, 0x89, 0x06, 0xc1,
  39365. 0x8c, 0x16, 0x9a, 0x06, 0x3a, 0xd0, 0x7e, 0xd6, 0xb0, 0x7b,
  39366. 0x7d, 0xf8, 0x91, 0x7c, 0xfa, 0xd9, 0x66, 0x39, 0xfa, 0xbc,
  39367. 0x57, 0xa7, 0x78, 0x8b, 0x36, 0x78, 0xc0, 0x1c, 0x0e, 0x23,
  39368. 0x05, 0x0e, 0x04, 0x61, 0x16, 0x34, 0xf9, 0xc6, 0x63, 0x58,
  39369. 0xdf, 0xf4, 0x52, 0xce, 0xd0, 0x0f, 0x0c, 0xec, 0xb1, 0x82,
  39370. 0xf4, 0x72, 0x73, 0x72, 0x3f, 0x02, 0xbe, 0xe3, 0x9c, 0x63,
  39371. 0x73, 0xc8, 0x21, 0x65, 0xba, 0x57, 0x52, 0xa9, 0x19, 0xac,
  39372. 0x68, 0x50, 0xbd, 0x2d, 0x72, 0x5b, 0x93, 0x0f, 0x1c, 0x81,
  39373. 0x77, 0xd7, 0x2e, 0xc3, 0x93, 0x52, 0x6e, 0xdc, 0x79, 0x52,
  39374. 0x9f, 0xe3, 0xde, 0xe1, 0xba, 0x58, 0x55, 0xab, 0x8a, 0xf2,
  39375. 0x35, 0x6a, 0xcf, 0x94, 0x1f, 0x17, 0xa4, 0x23, 0x2e, 0x8e,
  39376. 0x18, 0x21, 0xbe, 0x14, 0xfa, 0xe7, 0x59, 0xc5, 0x44, 0x34,
  39377. 0xce, 0x03, 0xf4, 0xb7, 0x75, 0xd3, 0x51, 0x55, 0xdf, 0xff,
  39378. 0xcf, 0x4f, 0x44, 0xee, 0x13, 0x9b, 0xcb, 0x12, 0xae, 0xe5,
  39379. 0x5b, 0x44, 0x65, 0x28, 0xcb, 0x6a, 0x9c, 0x24, 0x1d, 0xea,
  39380. 0x2d, 0x5e, 0xa5, 0xc3, 0x78, 0xad, 0xed, 0x0c, 0x05, 0xa6,
  39381. 0xaf, 0x95, 0x04, 0xd2, 0xb5, 0x91, 0x0e, 0xa0, 0x06, 0x77,
  39382. 0xc5, 0x82, 0xf6, 0xdd, 0x72, 0x83, 0x04, 0xcc, 0xb0, 0xab,
  39383. 0x7a, 0xf0, 0xb4, 0x4d, 0x36, 0x71, 0x72, 0x1a, 0x9a, 0x0d,
  39384. 0xcd, 0xa3, 0x11, 0xa8, 0x0d, 0x7d, 0x49, 0xce, 0x9c, 0x09,
  39385. 0x1d, 0x08, 0xa4, 0x39, 0x2e, 0x03, 0xdf, 0x3a, 0xc8, 0xfe,
  39386. 0x6a, 0x2b, 0x0b, 0x07, 0x80, 0x55, 0x8a, 0xa8, 0xe6, 0x0e,
  39387. 0xc9, 0x7e, 0x83, 0xce, 0x3a, 0x98, 0x98, 0x4e, 0x3e, 0x08,
  39388. 0x20, 0x8f, 0x10, 0xfc, 0xc1, 0xc4, 0xcf, 0x37, 0x8d, 0x69,
  39389. 0xd8, 0x57, 0x9d, 0x48, 0x80, 0x6a, 0xef, 0x0c, 0xdd, 0x27,
  39390. 0x99, 0xf9, 0xe7, 0xd0, 0xd2, 0x36, 0xd8, 0xed, 0x41, 0x14,
  39391. 0x1b, 0x10
  39392. };
  39393. #endif
  39394. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_sig[] = {
  39395. 0xb1, 0xd1, 0x8e, 0x83, 0x0b, 0x0d, 0xd2, 0x71, 0xb2, 0xaa, 0x31, 0x38,
  39396. 0x16, 0xf0, 0xb4, 0xbc, 0x64, 0x2b, 0x97, 0xa1, 0x08, 0x19, 0x4f, 0x52,
  39397. 0xfe, 0x99, 0x1a, 0xa9, 0xd4, 0x08, 0x93, 0x99, 0x88, 0xfd, 0x6a, 0xd6,
  39398. 0xd8, 0xdb, 0xf0, 0x71, 0x2a, 0xc9, 0x04, 0x83, 0xc9, 0x45, 0x59, 0x5d,
  39399. 0xe0, 0x36, 0x59, 0x53, 0x1b, 0xb8, 0x5a, 0xa6, 0x1f, 0xb4, 0x1b, 0x0a,
  39400. 0xfb, 0x3a, 0xba, 0xe3, 0xb7, 0x5e, 0x04, 0x14, 0x59, 0x09, 0x9a, 0x8e,
  39401. 0xc2, 0x77, 0x5a, 0x3d, 0xf1, 0x43, 0x67, 0x74, 0x78, 0xfc, 0xcd, 0x34,
  39402. 0xed, 0x35, 0x16, 0x38, 0x04, 0xe6, 0xe7, 0xd6, 0xd2, 0x90, 0x1b, 0x28,
  39403. 0xb6, 0x66, 0x1b, 0x57, 0x85, 0x5e, 0xa7, 0x9f, 0x86, 0x1a, 0x0d, 0xc3,
  39404. 0x7e, 0xed, 0xbd, 0x32, 0x8a, 0x35, 0xe1, 0xb3, 0x01, 0xdc, 0x9b, 0x44,
  39405. 0x88, 0xa1, 0x0b, 0x87, 0x6e, 0x55, 0x31, 0xb1, 0x27, 0xcb, 0x85, 0xa4,
  39406. 0x27, 0x56, 0x33, 0xb0, 0x39, 0x0d, 0xd3, 0x4b, 0xd1, 0xa2, 0x47, 0x07,
  39407. 0xc6, 0xf4, 0xe6, 0x1f, 0x88, 0x70, 0x70, 0x13, 0x7e, 0x2e, 0x17, 0x32,
  39408. 0x0a, 0x6b, 0x38, 0x34, 0xcf, 0x2f, 0x00, 0x36, 0x58, 0x8d, 0xe1, 0xdd,
  39409. 0xa7, 0x94, 0x2a, 0x8f, 0x87, 0x99, 0x67, 0x02, 0x4d, 0x5b, 0x56, 0xaf,
  39410. 0xef, 0xc4, 0x3c, 0xff, 0x72, 0x53, 0x95, 0x27, 0x03, 0x49, 0x94, 0x4f,
  39411. 0x94, 0x87, 0x1f, 0x52, 0x33, 0xed, 0xb9, 0x14, 0x7b, 0xe5, 0x6c, 0xef,
  39412. 0x7a, 0x17, 0x5a, 0xa4, 0x89, 0x2a, 0xfe, 0x68, 0xda, 0xdd, 0x48, 0xc2,
  39413. 0xf0, 0x92, 0xf4, 0xe4, 0xd6, 0xa6, 0x48, 0x08, 0x2c, 0xe8, 0xcd, 0x72,
  39414. 0xf6, 0x94, 0x3e, 0xc1, 0x82, 0xb8, 0x01, 0x58, 0xb2, 0xef, 0xef, 0xf4,
  39415. 0xcb, 0x93, 0x63, 0x2e, 0x33, 0x5b, 0xc9, 0xd6, 0x6a, 0xde, 0xad, 0xe8,
  39416. 0x1e, 0x3f, 0xa3, 0xf2, 0x35, 0x87, 0xc1, 0xc9, 0x48, 0x2f, 0x1b, 0x00,
  39417. 0xea, 0x3d, 0x04, 0x29, 0xd5, 0xc0, 0xe9, 0x1a, 0xc5, 0xce, 0x5e, 0xdb,
  39418. 0xd1, 0xee, 0x16, 0x9c, 0x05, 0x40, 0xf9, 0x21, 0x13, 0x72, 0x08, 0x39,
  39419. 0x6b, 0x63, 0x19, 0xcd, 0x6f, 0x64, 0xa0, 0xc3, 0x77, 0xb7, 0x50, 0xed,
  39420. 0xe9, 0x2d, 0xd5, 0x72, 0xea, 0xa6, 0xc1, 0x97, 0xb9, 0x6b, 0xe5, 0x81,
  39421. 0x91, 0x8e, 0xd1, 0x36, 0x11, 0xee, 0xfb, 0x2b, 0x66, 0xba, 0xe4, 0x3e,
  39422. 0xd0, 0xdd, 0x17, 0xc5, 0x24, 0x3b, 0xc3, 0x5b, 0x75, 0xfc, 0xd5, 0xb6,
  39423. 0x8c, 0xba, 0x8c, 0x66, 0xb2, 0xee, 0x40, 0x45, 0x8c, 0x23, 0xbb, 0xe0,
  39424. 0xc8, 0xd6, 0x05, 0xfd, 0x71, 0x5b, 0x24, 0xbb, 0x37, 0x65, 0x5f, 0x57,
  39425. 0x92, 0x22, 0x13, 0xb2, 0x9a, 0x70, 0x22, 0x4b, 0xbe, 0x03, 0xd1, 0x54,
  39426. 0xb0, 0x3a, 0x30, 0x50, 0x71, 0x24, 0xf7, 0x81, 0x8c, 0x20, 0x67, 0x74,
  39427. 0x5a, 0xef, 0xa1, 0x6a, 0xe3, 0xd0, 0x04, 0xd6, 0xa5, 0x6e, 0xad, 0xa7,
  39428. 0x15, 0x41, 0xf3, 0x21, 0xe8, 0xd9, 0xe6, 0xe5, 0x97, 0xbd, 0xc2, 0x1b,
  39429. 0xbb, 0xd1, 0x4e, 0x7e, 0x5a, 0xd6, 0xe4, 0x19, 0xa5, 0xe4, 0x76, 0xf4,
  39430. 0xce, 0x00, 0x94, 0x76, 0xef, 0x1b, 0xb3, 0x47, 0xb9, 0xa3, 0x32, 0xf7,
  39431. 0x45, 0x6d, 0x32, 0x73, 0x06, 0xc0, 0xb9, 0xaf, 0x9c, 0x46, 0x99, 0xbe,
  39432. 0x14, 0x06, 0xcd, 0x35, 0x7c, 0x90, 0x7c, 0xe7, 0x97, 0x0a, 0x9f, 0xb4,
  39433. 0x21, 0xff, 0xf0, 0xea, 0x83, 0xc0, 0x86, 0x68, 0x9f, 0x36, 0xb0, 0xad,
  39434. 0xe1, 0x8d, 0xc5, 0x76, 0x55, 0xb5, 0xb6, 0x7e, 0x1f, 0xa7, 0x5b, 0x26,
  39435. 0x6c, 0xb5, 0xf9, 0x54, 0x1f, 0x76, 0xc1, 0x9c, 0xfc, 0x57, 0xc8, 0x86,
  39436. 0xc1, 0x7d, 0x59, 0x55, 0x92, 0xa5, 0xb8, 0x03, 0xfa, 0xa5, 0x72, 0xd1,
  39437. 0x5c, 0x8d, 0x9b, 0x2e, 0x84, 0x07, 0x18, 0xee, 0x49, 0xc5, 0x99, 0x8e,
  39438. 0x15, 0x7c, 0xbf, 0xad, 0x8b, 0x13, 0xcd, 0x97, 0xf9, 0x3c, 0xa2, 0x89,
  39439. 0x9c, 0x9c, 0x89, 0xc9, 0x7a, 0x46, 0xb3, 0x42, 0x7b, 0xd4, 0x28, 0x0d,
  39440. 0x55, 0x63, 0x28, 0xd6, 0xc1, 0x65, 0xf5, 0x34, 0x6e, 0x38, 0x2a, 0xb4,
  39441. 0x35, 0x40, 0xed, 0x7e, 0x80, 0x61, 0x9d, 0x8f, 0x68, 0x4f, 0x74, 0x0c,
  39442. 0x30, 0x35, 0x0e, 0xb3, 0x07, 0xf4, 0x92, 0xed, 0x9c, 0x7f, 0xf5, 0xed,
  39443. 0x3e, 0x17, 0x5b, 0x6e, 0x91, 0x46, 0xa1, 0x25, 0x1d, 0x83, 0x50, 0x93,
  39444. 0x35, 0x06, 0x6c, 0x2f, 0x99, 0x8b, 0x21, 0x4c, 0x5c, 0x34, 0xb1, 0xa7,
  39445. 0x82, 0xbc, 0x70, 0x28, 0x56, 0x61, 0x29, 0x35, 0x89, 0x0b, 0x41, 0x21,
  39446. 0xf0, 0xf7, 0xff, 0x69, 0x3d, 0xa4, 0x28, 0x1e, 0x0d, 0x5d, 0xa7, 0x0e,
  39447. 0xaa, 0xd3, 0x4a, 0x95, 0x49, 0xfe, 0x35, 0x5f, 0xa9, 0xc0, 0xe4, 0xe1,
  39448. 0x9a, 0x03, 0xd4, 0xac, 0x96, 0xe3, 0xea, 0x7e, 0xa6, 0x85, 0x7e, 0xb0,
  39449. 0xb8, 0xc2, 0xe8, 0x07, 0xd6, 0xd3, 0x1a, 0x84, 0x90, 0x24, 0x04, 0xef,
  39450. 0x7c, 0x93, 0x15, 0x83, 0xea, 0xe2, 0x42, 0xc6, 0xe7, 0x13, 0x45, 0xbf,
  39451. 0x35, 0xae, 0x5d, 0x50, 0x79, 0x16, 0xbb, 0x11, 0x17, 0x1b, 0xf4, 0x08,
  39452. 0x88, 0x9d, 0x66, 0x14, 0x6a, 0xa0, 0x71, 0x76, 0x80, 0x51, 0x73, 0x7c,
  39453. 0x1d, 0xb0, 0xc1, 0xad, 0x58, 0xfb, 0xbe, 0xcf, 0x73, 0xe0, 0xd9, 0xf8,
  39454. 0xd5, 0xac, 0xd7, 0x49, 0xd9, 0xc9, 0x59, 0xbf, 0xfa, 0xf5, 0xb1, 0xd2,
  39455. 0x5a, 0x01, 0xcd, 0x8b, 0x07, 0x8b, 0x59, 0x37, 0xc0, 0x8c, 0x7d, 0xa9,
  39456. 0x71, 0x83, 0xf9, 0x7c, 0x58, 0xa9, 0x77, 0x01, 0x3d, 0x39, 0x56, 0x5c,
  39457. 0x93, 0xfe, 0x40, 0x87, 0x5a, 0x31, 0x81, 0x53, 0x8e, 0x0d, 0x99, 0x7e,
  39458. 0xdf, 0x37, 0xd9, 0xe3, 0x91, 0xb8, 0x60, 0x3a, 0x5b, 0xca, 0xe8, 0x91,
  39459. 0x56, 0x89, 0x59, 0x61, 0xc6, 0x31, 0xe2, 0x6c, 0x81, 0xda, 0xc7, 0x5c,
  39460. 0x04, 0x9d, 0xe4, 0x23, 0x12, 0x73, 0xfc, 0x48, 0xfb, 0xa5, 0xce, 0x87,
  39461. 0x37, 0x47, 0x71, 0x5c, 0xd1, 0x2a, 0x63, 0x89, 0xdc, 0x07, 0xe7, 0x7f,
  39462. 0x5d, 0x48, 0xe6, 0xd2, 0x96, 0xc6, 0x6f, 0xed, 0xee, 0x8c, 0xed, 0x5e,
  39463. 0x41, 0x38, 0xbd, 0xdf, 0x21, 0xaa, 0x9e, 0x51, 0x16, 0x22, 0x4a, 0xdc,
  39464. 0xd8, 0x12, 0xdf, 0x5a, 0x83, 0xd6, 0xd0, 0x07, 0xa4, 0x42, 0x41, 0x13,
  39465. 0xe1, 0x08, 0xc9, 0x00, 0x0f, 0x37, 0xc0, 0x7d, 0xda, 0xb2, 0x25, 0xfc,
  39466. 0xc9, 0xbc, 0xa8, 0x86, 0xcc, 0x38, 0x0e, 0x06, 0x51, 0x1b, 0x37, 0xc1,
  39467. 0x0e, 0x2a, 0x58, 0x49, 0xbc, 0x7c, 0xa7, 0xf0, 0xda, 0xd7, 0x74, 0x34,
  39468. 0xf5, 0xd8, 0x99, 0x8c, 0x94, 0x86, 0xe3, 0x1e, 0x6b, 0xf5, 0x68, 0xfa,
  39469. 0xa6, 0x69, 0x63, 0x22, 0x5a, 0x3c, 0x6f, 0x29, 0xc9, 0x40, 0xc0, 0xbe,
  39470. 0x8d, 0xb5, 0xcc, 0x82, 0x6e, 0x9d, 0xd1, 0x1f, 0x13, 0x63, 0xd8, 0x24,
  39471. 0x63, 0x38, 0x59, 0xf0, 0x4a, 0x8c, 0x0f, 0x28, 0x8a, 0x77, 0x81, 0xa2,
  39472. 0xa0, 0x23, 0x11, 0x59, 0xa9, 0x5a, 0x2d, 0x71, 0x8f, 0x82, 0xa7, 0xbd,
  39473. 0x85, 0x26, 0x4d, 0xc2, 0x2f, 0x11, 0xe8, 0xff, 0x96, 0xa1, 0x2d, 0xf2,
  39474. 0xd5, 0xf3, 0x1d, 0x54, 0xd0, 0x5f, 0x71, 0x07, 0xaf, 0x22, 0xa0, 0xcd,
  39475. 0x78, 0xb3, 0x47, 0xb1, 0x40, 0x3d, 0x6b, 0xfd, 0x10, 0x1b, 0xc6, 0x60,
  39476. 0xef, 0x5c, 0x24, 0xa3, 0x1f, 0xee, 0xc0, 0x0b, 0xed, 0x1d, 0x38, 0xc8,
  39477. 0xf2, 0x8c, 0xec, 0x5e, 0xd9, 0x70, 0x1a, 0x2b, 0x25, 0xe6, 0xed, 0xa9,
  39478. 0x0c, 0xb3, 0x78, 0xe1, 0x91, 0x01, 0x41, 0x2e, 0xfe, 0x7d, 0xbd, 0xfe,
  39479. 0xcf, 0x48, 0x6d, 0x2e, 0x05, 0x31, 0x89, 0x24, 0xc4, 0xd7, 0xc4, 0x26,
  39480. 0x2f, 0x64, 0x43, 0xa3, 0xdd, 0x56, 0x11, 0x5c, 0x65, 0x76, 0x96, 0xcc,
  39481. 0x3c, 0x12, 0x42, 0xf2, 0x6b, 0x20, 0xc2, 0xe6, 0xc3, 0x5c, 0xfa, 0x91,
  39482. 0xb1, 0xbd, 0x3b, 0xd3, 0x99, 0xde, 0x59, 0x7a, 0x34, 0x40, 0x56, 0xb0,
  39483. 0x88, 0x02, 0x19, 0xc8, 0xf9, 0xf9, 0x8f, 0xe7, 0x60, 0xfb, 0x42, 0x87,
  39484. 0x57, 0xb4, 0x42, 0xb4, 0x65, 0x94, 0x0a, 0x5f, 0xdb, 0xf5, 0x32, 0xe9,
  39485. 0x49, 0x28, 0xbe, 0xa6, 0x64, 0x0d, 0x6d, 0x08, 0x43, 0x91, 0x16, 0x7a,
  39486. 0x6c, 0xa9, 0x02, 0xe4, 0x84, 0x03, 0x39, 0x48, 0x08, 0xcc, 0xcb, 0x56,
  39487. 0xad, 0x52, 0x95, 0x9e, 0x9a, 0x2b, 0xf1, 0x6d, 0x3f, 0x4b, 0x02, 0xc6,
  39488. 0x52, 0xc7, 0x09, 0x6b, 0x3f, 0xa9, 0x60, 0xe2, 0x19, 0x5d, 0x0a, 0x61,
  39489. 0xcd, 0xc8, 0x36, 0xdb, 0x8e, 0x57, 0xd2, 0x11, 0x49, 0x1c, 0x26, 0x58,
  39490. 0x04, 0x07, 0x32, 0x2a, 0x34, 0xf0, 0x6a, 0x88, 0xcf, 0x63, 0xb7, 0xef,
  39491. 0x7e, 0x93, 0xcc, 0x64, 0x07, 0x14, 0xfa, 0x63, 0x38, 0xdd, 0xc0, 0xf0,
  39492. 0xaa, 0x56, 0xa1, 0xed, 0x16, 0xaa, 0x53, 0x8c, 0x99, 0xc0, 0xd4, 0xda,
  39493. 0x94, 0x58, 0x13, 0xd9, 0x5f, 0x98, 0x9a, 0xa1, 0x57, 0xbd, 0x89, 0xca,
  39494. 0x9d, 0x3e, 0xdf, 0x75, 0x26, 0x29, 0x0f, 0xb2, 0x33, 0x4b, 0x83, 0xb3,
  39495. 0x99, 0x1f, 0x06, 0x5d, 0x10, 0xf5, 0x1c, 0x75, 0x97, 0xec, 0x5b, 0x87,
  39496. 0xc7, 0xf1, 0xd8, 0xbd, 0x0e, 0x4c, 0x1a, 0xb0, 0x59, 0x3b, 0x27, 0x73,
  39497. 0xdc, 0xde, 0xca, 0x0c, 0x2e, 0x1f, 0x42, 0x7f, 0xd8, 0x0f, 0x9b, 0x3f,
  39498. 0x49, 0x3f, 0x63, 0x7d, 0x71, 0xe3, 0x77, 0x79, 0xcc, 0x9c, 0xbf, 0xff,
  39499. 0x23, 0xa9, 0x74, 0xa2, 0xda, 0xb7, 0xca, 0x86, 0x7f, 0x12, 0xc1, 0x1b,
  39500. 0x41, 0x35, 0xb5, 0xc7, 0x10, 0x09, 0xc0, 0xa2, 0x1b, 0x41, 0x31, 0x5e,
  39501. 0x6c, 0x35, 0xb5, 0x63, 0x13, 0x19, 0x61, 0x8e, 0xbd, 0x89, 0xf6, 0x0a,
  39502. 0xbd, 0x16, 0x15, 0xd8, 0xfa, 0xcc, 0x9f, 0x97, 0x02, 0x8f, 0x1b, 0x34,
  39503. 0x40, 0xbc, 0x4a, 0xb1, 0x39, 0x12, 0xf8, 0x66, 0xda, 0x34, 0x03, 0xf2,
  39504. 0x5c, 0x33, 0x9c, 0x63, 0x0b, 0xb6, 0x8f, 0xca, 0x81, 0xa2, 0x4a, 0x43,
  39505. 0xe7, 0xe7, 0x66, 0x41, 0x45, 0x6b, 0x7c, 0xd1, 0x1d, 0xbc, 0x4f, 0x91,
  39506. 0xab, 0x24, 0x0b, 0x9f, 0x60, 0x47, 0x36, 0x04, 0x8b, 0x72, 0xb6, 0x65,
  39507. 0x35, 0xfc, 0xbf, 0xc9, 0x26, 0xaf, 0x84, 0x04, 0x30, 0x32, 0x02, 0xc0,
  39508. 0x94, 0x98, 0xbc, 0x17, 0x33, 0x99, 0xac, 0xb1, 0x4e, 0xdd, 0xf0, 0x46,
  39509. 0x68, 0x6a, 0xac, 0x6d, 0xdb, 0x85, 0xfd, 0xc6, 0x3b, 0xc8, 0x93, 0x89,
  39510. 0xbf, 0xd7, 0xd9, 0x94, 0xe4, 0xa4, 0x37, 0xb9, 0x67, 0x52, 0x84, 0xcf,
  39511. 0x88, 0xba, 0x01, 0x8b, 0xe4, 0xd4, 0x3e, 0xde, 0x94, 0xa1, 0xa9, 0xd8,
  39512. 0x15, 0xb5, 0x6e, 0xa0, 0x62, 0x92, 0x5c, 0xb1, 0x1b, 0xbf, 0x4f, 0xaf,
  39513. 0xf5, 0x99, 0x35, 0xce, 0x7d, 0xa9, 0x4b, 0xa8, 0x60, 0x31, 0xf5, 0x0a,
  39514. 0x83, 0x58, 0xf5, 0x83, 0xde, 0xb2, 0xfe, 0xf3, 0x12, 0x08, 0x3d, 0xe3,
  39515. 0x14, 0x89, 0x17, 0x93, 0x5c, 0x87, 0xe4, 0x89, 0xcb, 0xb7, 0x67, 0x3e,
  39516. 0xea, 0x0e, 0x08, 0x57, 0xf1, 0xca, 0xe0, 0x18, 0xd7, 0xae, 0x5f, 0x9e,
  39517. 0x62, 0x5c, 0xd7, 0x6a, 0x2f, 0xd6, 0x30, 0x67, 0xfb, 0x5e, 0xed, 0xcf,
  39518. 0xa9, 0x88, 0x04, 0x0a, 0xf2, 0x62, 0x50, 0xc5, 0x39, 0xc6, 0xa1, 0x3c,
  39519. 0xe4, 0x9a, 0x81, 0x55, 0x96, 0xca, 0x60, 0xb2, 0x53, 0x62, 0xee, 0xa1,
  39520. 0x1d, 0xfc, 0xd9, 0x5c, 0x51, 0xbf, 0x55, 0x65, 0x1d, 0x13, 0x2a, 0x13,
  39521. 0x58, 0xa3, 0x18, 0x52, 0x6b, 0xb4, 0xae, 0x60, 0x1c, 0x26, 0x3e, 0xb1,
  39522. 0x4c, 0xb1, 0x72, 0x1b, 0x8a, 0x4c, 0xaa, 0xb5, 0x5b, 0x8a, 0x3b, 0x2f,
  39523. 0x1f, 0xc3, 0x29, 0x41, 0xe6, 0x6d, 0xd7, 0x96, 0x26, 0xdd, 0x37, 0x67,
  39524. 0x4f, 0x9d, 0x31, 0xc6, 0x54, 0x51, 0xaa, 0xba, 0x73, 0xae, 0xd2, 0x00,
  39525. 0x0b, 0x05, 0x98, 0x73, 0xd6, 0x9c, 0xb4, 0x2e, 0x23, 0xd0, 0xc3, 0xac,
  39526. 0x46, 0x6f, 0x3e, 0x05, 0x43, 0xf8, 0x96, 0xa0, 0xe0, 0xfe, 0x17, 0x3f,
  39527. 0xfa, 0xc2, 0xc3, 0xf6, 0x1a, 0x46, 0xd0, 0x05, 0x53, 0x0e, 0xea, 0xd8,
  39528. 0xba, 0xa3, 0xab, 0xb6, 0x58, 0xd1, 0x40, 0x1c, 0x97, 0x38, 0xd4, 0x77,
  39529. 0x58, 0x03, 0xf5, 0x8a, 0xc7, 0x48, 0x19, 0x71, 0x71, 0xb5, 0x4b, 0x08,
  39530. 0x85, 0x35, 0x1c, 0xdf, 0xbd, 0xa9, 0xc9, 0xd1, 0x40, 0x62, 0xa3, 0xd6,
  39531. 0x3b, 0xa1, 0xf7, 0x4e, 0xc6, 0xfe, 0xc4, 0x07, 0x2f, 0xf5, 0xc9, 0x0c,
  39532. 0xb6, 0xa0, 0xb3, 0x25, 0x3e, 0x2a, 0x07, 0xe3, 0x63, 0xe3, 0x9e, 0x8d,
  39533. 0x0d, 0x7a, 0x70, 0x1e, 0x65, 0x95, 0x47, 0x37, 0xa8, 0xd2, 0x35, 0x09,
  39534. 0x09, 0x70, 0xf5, 0xc9, 0xc9, 0x30, 0x95, 0xd9, 0xf2, 0x5d, 0x10, 0x3c,
  39535. 0xc3, 0x66, 0x66, 0xb6, 0xdc, 0x14, 0xf6, 0x91, 0xc2, 0x7b, 0x4b, 0x71,
  39536. 0x42, 0xf9, 0x35, 0xe7, 0x08, 0x1e, 0xb6, 0x9a, 0x5c, 0x0e, 0x8b, 0x41,
  39537. 0x44, 0x7f, 0xad, 0xca, 0x8a, 0x4b, 0x6a, 0x02, 0x81, 0x96, 0xe7, 0xe1,
  39538. 0xb0, 0x5b, 0xaf, 0xf2, 0x17, 0x44, 0x7f, 0xd1, 0x49, 0x77, 0xfd, 0x07,
  39539. 0x59, 0x53, 0x8e, 0x51, 0xac, 0x0f, 0x0c, 0xb4, 0xa3, 0xf6, 0x24, 0x16,
  39540. 0x47, 0xf3, 0xa4, 0x36, 0x17, 0x3e, 0x01, 0x1e, 0xf1, 0xec, 0x78, 0x4a,
  39541. 0xcb, 0xbd, 0x2a, 0xfd, 0x01, 0xdd, 0xa5, 0xad, 0x7b, 0xef, 0x5e, 0x56,
  39542. 0xb2, 0x60, 0xb4, 0xf2, 0x27, 0xc8, 0x9b, 0x5b, 0x31, 0x49, 0x54, 0xbc,
  39543. 0x69, 0x9b, 0xc6, 0x1a, 0x79, 0xe7, 0xd4, 0x46, 0xc8, 0x50, 0xc3, 0xaa,
  39544. 0xfc, 0xb5, 0x28, 0x87, 0x1e, 0xa0, 0x0c, 0xc6, 0x1a, 0xa7, 0x34, 0xd6,
  39545. 0xbb, 0x9d, 0x9c, 0x0d, 0x90, 0x6f, 0x1a, 0x3c, 0xdc, 0x3b, 0x95, 0xc4,
  39546. 0x38, 0x25, 0x7a, 0xc6, 0x46, 0x82, 0x9f, 0x68, 0xca, 0x6a, 0x63, 0xa7,
  39547. 0x99, 0xfe, 0x64, 0xe6, 0x6f, 0x11, 0xcd, 0x2c, 0x76, 0x1e, 0xe6, 0x08,
  39548. 0xb8, 0x33, 0x64, 0x43, 0x51, 0xbd, 0x52, 0xf7, 0x05, 0x06, 0xd5, 0xcc,
  39549. 0x6a, 0xde, 0x1a, 0xa2, 0xbe, 0xf8, 0x8c, 0x44, 0x5e, 0x2d, 0xc2, 0x28,
  39550. 0xcd, 0x9a, 0x53, 0x04, 0x96, 0xcc, 0x1e, 0xbb, 0x96, 0x07, 0xc9, 0x17,
  39551. 0x04, 0xf8, 0xd8, 0xd9, 0xdd, 0x35, 0x35, 0x3d, 0x53, 0x30, 0x60, 0xb3,
  39552. 0x87, 0x5d, 0xf3, 0xe5, 0xa7, 0x20, 0x30, 0x9d, 0xb0, 0x5b, 0xc4, 0x36,
  39553. 0xf7, 0xd7, 0xb6, 0x3e, 0x44, 0x98, 0x99, 0xe7, 0xc3, 0x29, 0xcb, 0x70,
  39554. 0xc4, 0x91, 0x8b, 0xfc, 0x63, 0x60, 0x29, 0x95, 0xeb, 0x61, 0x7f, 0xdf,
  39555. 0xf7, 0x3a, 0x69, 0x3a, 0xeb, 0xa1, 0x73, 0x1d, 0x13, 0x18, 0x29, 0x2c,
  39556. 0x89, 0x82, 0x56, 0x42, 0xe7, 0xa3, 0xba, 0xe9, 0x59, 0x2e, 0xfd, 0xff,
  39557. 0xb6, 0xf7, 0xbd, 0x2a, 0xc9, 0xff, 0x4c, 0x63, 0xef, 0x54, 0x63, 0x82,
  39558. 0x7c, 0xa5, 0x11, 0x44, 0xc7, 0x68, 0xf5, 0x7b, 0x44, 0x2c, 0xee, 0xab,
  39559. 0xa3, 0x84, 0x5a, 0x99, 0x28, 0x98, 0x97, 0x2e, 0x8b, 0x07, 0x09, 0x6c,
  39560. 0xea, 0xc1, 0x81, 0x0b, 0xe0, 0xc4, 0xb7, 0xc2, 0x73, 0xbe, 0x8b, 0x72,
  39561. 0xf8, 0xc9, 0x8d, 0x50, 0x28, 0xf2, 0x95, 0x54, 0x8a, 0x3b, 0x23, 0x86,
  39562. 0xc4, 0xe8, 0xe8, 0xe5, 0x45, 0x0d, 0xdf, 0xa3, 0xe6, 0x00, 0x71, 0xe8,
  39563. 0x20, 0xd2, 0x6d, 0x22, 0x23, 0xaf, 0x37, 0x04, 0x55, 0x05, 0x8d, 0xc9,
  39564. 0x38, 0x38, 0x12, 0x4c, 0x9f, 0x28, 0x56, 0x14, 0x76, 0xe5, 0x10, 0x54,
  39565. 0xd9, 0x68, 0xca, 0xc3, 0x97, 0x9f, 0xd2, 0x25, 0x2c, 0x0d, 0xa0, 0xff,
  39566. 0xea, 0xab, 0x61, 0xd2, 0xb2, 0x06, 0xc2, 0x93, 0xfd, 0x5a, 0xfe, 0xe3,
  39567. 0x98, 0xbf, 0x37, 0x2e, 0xa5, 0x74, 0x56, 0xd0, 0x7a, 0x5a, 0x23, 0x3b,
  39568. 0xd2, 0xa0, 0x1f, 0x4b, 0xeb, 0x7f, 0x5a, 0xc5, 0x51, 0x79, 0xf6, 0x95,
  39569. 0x19, 0x50, 0xb1, 0x6a, 0x80, 0xcb, 0xcf, 0x19, 0xa4, 0x67, 0xf4, 0x08,
  39570. 0x0f, 0x6a, 0xd9, 0x3f, 0x15, 0x96, 0x2c, 0x6d, 0xd5, 0x69, 0x7a, 0x56,
  39571. 0x4d, 0x17, 0xc8, 0xcb, 0xba, 0x9b, 0x6e, 0x65, 0xa2, 0x3d, 0x66, 0xed,
  39572. 0xea, 0xe2, 0x54, 0x88, 0x6c, 0xc1, 0x1a, 0x11, 0xde, 0x4e, 0x0c, 0x8a,
  39573. 0x42, 0x04, 0xe1, 0x77, 0xc3, 0x0c, 0xff, 0x10, 0x7d, 0x4a, 0x45, 0x3f,
  39574. 0xb8, 0x40, 0xf9, 0x75, 0x76, 0x9f, 0x65, 0x42, 0x2f, 0x78, 0x5b, 0x0b,
  39575. 0x32, 0xbc, 0x45, 0xfc, 0xd4, 0x29, 0x49, 0x34, 0x76, 0xda, 0x5f, 0xe8,
  39576. 0x39, 0x35, 0x9e, 0xba, 0x7f, 0x19, 0x7e, 0x14, 0xe6, 0x71, 0x9c, 0x72,
  39577. 0x6a, 0xce, 0xcc, 0xa6, 0x72, 0x73, 0x3f, 0x4e, 0x9b, 0x9e, 0x94, 0x0c,
  39578. 0xce, 0x00, 0x15, 0xb4, 0x50, 0xff, 0xcf, 0xcd, 0x78, 0xd3, 0x08, 0x0e,
  39579. 0x95, 0x48, 0x24, 0x13, 0x16, 0x54, 0xb4, 0xe0, 0xa9, 0x29, 0xa3, 0x05,
  39580. 0x77, 0x2f, 0x5d, 0x47, 0x6a, 0xa5, 0xb0, 0x4e, 0xf3, 0xa9, 0x4a, 0x82,
  39581. 0xb9, 0x2c, 0x26, 0x07, 0x9c, 0x33, 0xc6, 0x68, 0xc2, 0xe0, 0xc0, 0x7d,
  39582. 0x70, 0x48, 0x74, 0xb9, 0xf5, 0x1e, 0x6c, 0x15, 0x7f, 0xba, 0xe5, 0xa1,
  39583. 0xb4, 0x36, 0x41, 0x20, 0xf4, 0x2d, 0x97, 0x27, 0x0b, 0x10, 0x30, 0x57,
  39584. 0x7f, 0x38, 0x66, 0xe1, 0xc4, 0xf6, 0xa4, 0xc9, 0x8d, 0xbc, 0x2b, 0x4f,
  39585. 0x14, 0xb3, 0xf0, 0x1e, 0x80, 0x70, 0xc0, 0x0f, 0x69, 0x06, 0xe7, 0x95,
  39586. 0xd1, 0x53, 0x65, 0x49, 0x1c, 0xa8, 0xfa, 0x9e, 0x2b, 0xcc, 0x33, 0x71,
  39587. 0x76, 0xa4, 0x0b, 0x4a, 0xc7, 0xea, 0xa0, 0xfa, 0x1b, 0x2b, 0xfb, 0xa5,
  39588. 0x59, 0x06, 0x2a, 0xef, 0x4b, 0xbf, 0x05, 0x4b, 0x87, 0x70, 0x3c, 0xde,
  39589. 0xc7, 0xb2, 0x4f, 0xf2, 0x5b, 0x1a, 0xbe, 0xda, 0x04, 0x31, 0x57, 0xff,
  39590. 0xf2, 0xa5, 0x43, 0x12, 0xff, 0x8d, 0xf4, 0x99, 0x05, 0xe1, 0x34, 0xa9,
  39591. 0xb9, 0x0a, 0xb3, 0x1f, 0x3d, 0x6d, 0x0d, 0xb7, 0xd3, 0x35, 0x0b, 0x04,
  39592. 0x44, 0x77, 0x60, 0xc0, 0x96, 0x99, 0x7b, 0xa8, 0x8e, 0x79, 0x4a, 0x96,
  39593. 0x24, 0xef, 0xb1, 0xf4, 0x8a, 0x2f, 0x3e, 0x08, 0xf3, 0x3d, 0xf2, 0xfe,
  39594. 0x5f, 0x0a, 0xf7, 0x0a, 0xf5, 0xd8, 0xf2, 0xa0, 0x1b, 0xe7, 0x9e, 0xc9,
  39595. 0x0b, 0xcf, 0x58, 0x97, 0x92, 0x90, 0xad, 0x3d, 0xfc, 0x42, 0xc1, 0x7f,
  39596. 0x39, 0xe8, 0xd1, 0x35, 0x14, 0x8a, 0xb3, 0x77, 0xb1, 0xa9, 0xdb, 0xb4,
  39597. 0x3a, 0x3d, 0xeb, 0x59, 0x0b, 0x5b, 0x3a, 0x63, 0x54, 0x70, 0xda, 0xf0,
  39598. 0xf0, 0xb9, 0xe6, 0x07, 0x69, 0x27, 0x9d, 0xc6, 0xb6, 0x00, 0x2d, 0xd6,
  39599. 0xc7, 0xd7, 0x2e, 0xf8, 0x9c, 0xfe, 0x4c, 0xfb, 0xc0, 0x7b, 0xbf, 0xa2,
  39600. 0x25, 0xb8, 0x2a, 0x5c, 0x06, 0xca, 0x12, 0x2c, 0x96, 0xa4, 0x27, 0xa6,
  39601. 0x73, 0x0b, 0xb8, 0x42, 0x93, 0x51, 0x87, 0xfe, 0xe6, 0x8f, 0xca, 0x00,
  39602. 0x53, 0xdc, 0xc0, 0x38, 0x03, 0x9e, 0x66, 0x13, 0x84, 0x68, 0xe7, 0x04,
  39603. 0x93, 0x79, 0x0c, 0x3e, 0x4c, 0x90, 0xe2, 0xf7, 0x81, 0x15, 0x49, 0x05,
  39604. 0xe1, 0x8f, 0xe6, 0xfc, 0xc8, 0x40, 0xae, 0x3d, 0x7a, 0x16, 0xec, 0xc6,
  39605. 0x39, 0xa5, 0x04, 0x95, 0x35, 0xac, 0xdd, 0x0d, 0x19, 0xd6, 0xa9, 0xd9,
  39606. 0xd2, 0x53, 0x71, 0x31, 0x38, 0xa2, 0xf1, 0x9c, 0x13, 0x2c, 0x8c, 0x21,
  39607. 0x9c, 0x3a, 0x1b, 0xf2, 0xd8, 0x4c, 0xeb, 0xe9, 0x8b, 0x27, 0x52, 0xd3,
  39608. 0x6c, 0x01, 0xc0, 0x60, 0x32, 0x8c, 0x6e, 0xfb, 0xd6, 0xd6, 0x1b, 0xc6,
  39609. 0x93, 0xff, 0xdc, 0xdb, 0x38, 0xf5, 0x0e, 0xd5, 0x15, 0xcd, 0x65, 0x76,
  39610. 0x78, 0x42, 0x13, 0x37, 0x6b, 0x2e, 0xe8, 0xe2, 0x54, 0x4d, 0x45, 0x34,
  39611. 0x73, 0x1b, 0x61, 0x35, 0x2c, 0xf7, 0x20, 0x3e, 0xe9, 0x7c, 0xf0, 0xf3,
  39612. 0xba, 0x41, 0xfc, 0x49, 0xe4, 0x5d, 0xd4, 0xb8, 0x07, 0x15, 0x7b, 0x16,
  39613. 0xc7, 0x7f, 0x78, 0xef, 0xd6, 0x53, 0x3f, 0xe4, 0xa6, 0x33, 0xcf, 0xcc,
  39614. 0x78, 0x53, 0x0c, 0x59, 0xf7, 0x28, 0xa5, 0x83, 0x2b, 0x5a, 0xd3, 0xd6,
  39615. 0xb7, 0xb2, 0xd1, 0x73, 0x63, 0xa9, 0xad, 0x16, 0xf2, 0xed, 0x48, 0x6e,
  39616. 0x88, 0x22, 0xbd, 0x16, 0x9d, 0x6a, 0xc2, 0x48, 0x83, 0xdf, 0x40, 0xb7,
  39617. 0x0a, 0x50, 0x23, 0x3d, 0x58, 0x50, 0x00, 0x02, 0x04, 0xd2, 0x31, 0x72,
  39618. 0x28, 0x7b, 0x10, 0x96, 0xe0, 0xe7, 0x3f, 0xe0, 0xd0, 0x61, 0x70, 0x5c,
  39619. 0x0a, 0xdb, 0xc0, 0x7b, 0xea, 0xef, 0xba, 0xc0, 0x90, 0xe0, 0xf9, 0x0e,
  39620. 0x83, 0x8c, 0x3b, 0x05, 0x2b, 0xb6, 0xcb, 0xbb, 0x37, 0xa1, 0xd3, 0x28,
  39621. 0x02, 0x40, 0xe3, 0x76, 0xbf, 0x27, 0x0b, 0x4f, 0x82, 0xb9, 0x22, 0xee,
  39622. 0x0b, 0x3a, 0xcb, 0xcc, 0x56, 0x13, 0x51, 0xb8, 0xb6, 0x2d, 0xd3, 0x6c,
  39623. 0x96, 0x10, 0xd9, 0x51, 0x24, 0x7b, 0x2b, 0xb8, 0x7b, 0xbd, 0x8d, 0xd9,
  39624. 0xf2, 0x50, 0x61, 0xbb, 0x0c, 0xb7, 0x71, 0x65, 0x3a, 0x25, 0x18, 0x09,
  39625. 0x1a, 0x9d, 0x41, 0xf4, 0xdb, 0x5a, 0x1c, 0x61, 0x0a, 0xbb, 0x43, 0x27,
  39626. 0x8a, 0xa8, 0x83, 0x60, 0x8c, 0x5d, 0x4c, 0x9b, 0xa9, 0xe5, 0xa7, 0x67,
  39627. 0x99, 0x98, 0xdc, 0x7a, 0x3a, 0x55, 0x0d, 0x25, 0x69, 0x47, 0x21, 0xb1,
  39628. 0xd7, 0x0c, 0x0c, 0x43, 0x58, 0xc9, 0xbf, 0x74, 0x91, 0x1b, 0x2b, 0xf3,
  39629. 0x29, 0x8d, 0x10, 0x41, 0xaf, 0xdd, 0x42, 0x0a, 0x71, 0xe3, 0xb8, 0x4d,
  39630. 0x3a, 0xf3, 0x9c, 0x5a, 0x46, 0x4e, 0x70, 0xbe, 0xdb, 0x0d, 0x03, 0xee,
  39631. 0xcb, 0xfb, 0x61, 0x45, 0xbd, 0x25, 0xb4, 0x72, 0xd1, 0x51, 0x03, 0x19,
  39632. 0x82, 0x53, 0x83, 0x18, 0xab, 0xa3, 0x6c, 0x9e, 0xa2, 0xe9, 0x15, 0xb1,
  39633. 0x74, 0x61, 0xa1, 0xaf, 0x09, 0x4b, 0x4a, 0x34, 0x9b, 0xd0, 0xd2, 0x80,
  39634. 0x43, 0xd9, 0x90, 0x53, 0x71, 0x38, 0xb9, 0x80, 0x58, 0x1b, 0x9f, 0x9e,
  39635. 0xfe, 0x07, 0x1b, 0x33, 0x24, 0xb2, 0x58, 0x7f, 0x01, 0xbe, 0xe8, 0x25,
  39636. 0x53, 0x08, 0x06, 0x77, 0x7d, 0x5a, 0x16, 0x83, 0x67, 0x91, 0x0b, 0xa2,
  39637. 0xd2, 0x1e, 0x5f, 0x9c, 0x39, 0xda, 0x57, 0xbc, 0x67, 0xc5, 0x39, 0xbe,
  39638. 0xb9, 0x73, 0x03, 0x19, 0x97, 0x34, 0x4f, 0x1e, 0x6b, 0x4d, 0x87, 0xef,
  39639. 0x79, 0x4f, 0xd1, 0xdd, 0x80, 0x13, 0xbe, 0x3b, 0x0f, 0xea, 0x77, 0x9a,
  39640. 0x1a, 0x46, 0x63, 0xc5, 0x2f, 0x93, 0xfe, 0x18, 0x71, 0xfb, 0x70, 0xbf,
  39641. 0x85, 0x3b, 0x3e, 0x54, 0xe6, 0xf8, 0xe0, 0xb9, 0xd0, 0x9d, 0xf5, 0x2b,
  39642. 0x12, 0x22, 0x39, 0x6a, 0x8d, 0x13, 0xa1, 0x3a, 0x95, 0xd0, 0xe7, 0x07,
  39643. 0xa4, 0x2c, 0x33, 0xba, 0x43, 0x1d, 0xd8, 0xb5, 0xd0, 0x8e, 0x6c, 0x85,
  39644. 0x6f, 0xf8, 0x8f, 0xd3, 0x72, 0x65, 0xc1, 0xff, 0x8f, 0xf6, 0xb5, 0x19,
  39645. 0x59, 0x34, 0xf9, 0xe8, 0xdb, 0xf3, 0x10, 0x68, 0xbd, 0xd5, 0x59, 0xf7,
  39646. 0xe5, 0xf2, 0x84, 0x98, 0x8d, 0xd6, 0x6f, 0xcc, 0xde, 0xc5, 0xee, 0xf7,
  39647. 0x16, 0xca, 0xec, 0xc4, 0x00, 0x89, 0x2e, 0x0d, 0x0d, 0xb6, 0xa8, 0xe0,
  39648. 0x9a, 0xb0, 0xe5, 0x8e, 0xb6, 0x64, 0x47, 0x7d, 0x01, 0x59, 0x8a, 0x90,
  39649. 0xa6, 0x9b, 0x2b, 0x63, 0xad, 0x70, 0xc8, 0x07, 0x36, 0x3e, 0xa9, 0x8f,
  39650. 0xd9, 0xc2, 0xf7, 0x4b, 0xec, 0x95, 0x53, 0xec, 0x6b, 0x2d, 0x1f, 0xb5,
  39651. 0x91, 0xbf, 0x9f, 0xc5, 0x85, 0x61, 0x3a, 0xc7, 0x5c, 0x15, 0x2a, 0x0b,
  39652. 0x4b, 0x3c, 0x38, 0x6d, 0xc9, 0x2c, 0x91, 0x11, 0xc6, 0x6b, 0x44, 0x71,
  39653. 0x9f, 0x89, 0xd5, 0xde, 0x27, 0x99, 0x81, 0xa2, 0x59, 0x8b, 0x57, 0x97,
  39654. 0x83, 0x46, 0x33, 0xe1, 0x8c, 0xdf, 0xcf, 0x5b, 0x6b, 0xb3, 0x0e, 0x17,
  39655. 0x1a, 0xb8, 0x7d, 0x6e, 0x71, 0xe5, 0xc8, 0x4c, 0xa9, 0xe2, 0x52, 0x81,
  39656. 0xf6, 0x2f, 0x3a, 0xef, 0x5a, 0x1b, 0x6b, 0x7b, 0x61, 0x51, 0xcb, 0xd5,
  39657. 0x7b, 0x5f, 0xf0, 0x1c, 0xb8, 0xeb, 0x9a, 0xe4, 0x0a, 0x6e, 0x53, 0x59,
  39658. 0x2e, 0x2d, 0x78, 0x27, 0xb7, 0x47, 0x35, 0x1a, 0x01, 0x25, 0x0a, 0xcc,
  39659. 0x67, 0xae, 0xda, 0xaf, 0xfe, 0x22, 0x63, 0xe8, 0xa2, 0x1c, 0x34, 0xe6,
  39660. 0x6b, 0x73, 0xcf, 0x6f, 0x3e, 0x0a, 0x4a, 0x36, 0xbc, 0xda, 0x43, 0xbc,
  39661. 0x5e, 0x9c, 0x91, 0xe4, 0x8b, 0x34, 0x2e, 0x09, 0x87, 0x69, 0x96, 0x93,
  39662. 0xb4, 0xff, 0x97, 0xbc, 0x4e, 0xd6, 0xa2, 0xb4, 0x16, 0x78, 0x7c, 0x62,
  39663. 0xd0, 0x78, 0x3f, 0x37, 0xdb, 0xf2, 0x92, 0xad, 0x9b, 0x51, 0x77, 0x08,
  39664. 0x19, 0xd2, 0x09, 0x12, 0xf7, 0x52, 0xe8, 0xc8, 0xb2, 0xfb, 0x6f, 0xcd,
  39665. 0x05, 0x5b, 0xd2, 0x8e, 0x0d, 0x6e, 0x0c, 0x16, 0x5b, 0x8a, 0xc2, 0x09,
  39666. 0x13, 0x3b, 0x69, 0x85, 0xbd, 0xc0, 0xcc, 0x2b, 0x48, 0x65, 0xa7, 0xc1,
  39667. 0xc3, 0xe0, 0xea, 0x14, 0x67, 0x6f, 0xa4, 0xb8, 0xc6, 0xf0, 0x12, 0x3e,
  39668. 0x96, 0x0d, 0x23, 0x2b, 0x37, 0x87, 0x8d, 0xc8, 0xf7, 0x00, 0x00, 0x00,
  39669. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39670. 0x00, 0x00, 0x00, 0x03, 0x0b, 0x13, 0x1a, 0x1d, 0x25
  39671. };
  39672. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39673. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_sig[] = {
  39674. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  39675. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  39676. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  39677. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  39678. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  39679. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  39680. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  39681. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  39682. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  39683. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  39684. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  39685. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  39686. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  39687. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  39688. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  39689. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  39690. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  39691. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  39692. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  39693. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  39694. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  39695. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  39696. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  39697. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  39698. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  39699. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  39700. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  39701. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  39702. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  39703. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  39704. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  39705. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  39706. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  39707. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  39708. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  39709. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  39710. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  39711. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  39712. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  39713. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  39714. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  39715. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  39716. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  39717. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  39718. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  39719. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  39720. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  39721. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  39722. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  39723. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  39724. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  39725. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  39726. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  39727. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  39728. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  39729. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  39730. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  39731. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  39732. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  39733. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  39734. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  39735. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  39736. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  39737. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  39738. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  39739. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  39740. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  39741. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  39742. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  39743. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  39744. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  39745. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  39746. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  39747. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  39748. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  39749. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  39750. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  39751. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  39752. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  39753. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  39754. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  39755. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  39756. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  39757. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  39758. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  39759. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  39760. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  39761. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  39762. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  39763. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  39764. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  39765. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  39766. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  39767. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  39768. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  39769. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  39770. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  39771. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  39772. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  39773. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  39774. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  39775. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  39776. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  39777. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  39778. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  39779. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  39780. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  39781. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  39782. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  39783. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  39784. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  39785. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  39786. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  39787. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  39788. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  39789. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  39790. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  39791. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  39792. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  39793. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  39794. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  39795. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  39796. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  39797. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  39798. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  39799. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  39800. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  39801. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  39802. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  39803. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  39804. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  39805. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  39806. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  39807. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  39808. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  39809. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  39810. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  39811. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  39812. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  39813. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  39814. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  39815. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  39816. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  39817. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  39818. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  39819. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  39820. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  39821. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  39822. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  39823. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  39824. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  39825. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  39826. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  39827. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  39828. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  39829. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  39830. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  39831. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  39832. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  39833. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  39834. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  39835. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  39836. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  39837. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  39838. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  39839. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  39840. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  39841. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  39842. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  39843. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  39844. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  39845. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  39846. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  39847. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  39848. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  39849. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  39850. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  39851. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  39852. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  39853. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  39854. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  39855. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  39856. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  39857. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  39858. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  39859. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  39860. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  39861. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  39862. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  39863. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  39864. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  39865. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  39866. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  39867. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  39868. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  39869. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  39870. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  39871. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  39872. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  39873. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  39874. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  39875. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  39876. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  39877. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  39878. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  39879. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  39880. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  39881. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  39882. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  39883. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  39884. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  39885. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  39886. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  39887. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  39888. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  39889. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  39890. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  39891. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  39892. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  39893. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  39894. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  39895. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  39896. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  39897. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  39898. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  39899. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  39900. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  39901. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  39902. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  39903. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  39904. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  39905. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  39906. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  39907. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  39908. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  39909. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  39910. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  39911. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  39912. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  39913. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  39914. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  39915. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  39916. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  39917. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  39918. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  39919. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  39920. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  39921. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  39922. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  39923. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  39924. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  39925. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  39926. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  39927. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  39928. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  39929. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  39930. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  39931. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  39932. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  39933. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  39934. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  39935. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  39936. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  39937. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  39938. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  39939. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  39940. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  39941. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  39942. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  39943. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  39944. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  39945. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  39946. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  39947. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  39948. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  39949. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  39950. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  39951. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  39952. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  39953. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  39954. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  39955. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  39956. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  39957. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  39958. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  39959. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  39960. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  39961. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  39962. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  39963. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  39964. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  39965. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  39966. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  39967. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  39968. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  39969. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  39970. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  39971. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  39972. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  39973. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  39974. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  39975. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  39976. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  39977. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  39978. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  39979. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  39980. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  39981. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  39982. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  39983. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  39984. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  39985. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  39986. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  39987. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  39988. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  39989. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  39990. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  39991. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  39992. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  39993. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  39994. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  39995. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  39996. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  39997. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  39998. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  39999. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  40000. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  40001. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  40002. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  40003. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40004. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28
  40005. };
  40006. #endif
  40007. wc_test_ret_t ret;
  40008. ret = dilithium_param_vfy_test(WC_ML_DSA_65, ml_dsa_65_pub_key,
  40009. (word32)sizeof(ml_dsa_65_pub_key), ml_dsa_65_sig,
  40010. (word32)sizeof(ml_dsa_65_sig));
  40011. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40012. if (ret == 0) {
  40013. ret = dilithium_param_vfy_test(WC_ML_DSA_65_DRAFT,
  40014. ml_dsa_65_draft_pub_key, (word32)sizeof(ml_dsa_65_draft_pub_key),
  40015. ml_dsa_65_draft_sig, (word32)sizeof(ml_dsa_65_draft_sig));
  40016. }
  40017. #endif
  40018. return ret;
  40019. }
  40020. #endif
  40021. #ifndef WOLFSSL_NO_ML_DSA_87
  40022. static wc_test_ret_t dilithium_param_87_vfy_test(void)
  40023. {
  40024. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_pub_key[] = {
  40025. 0x8a, 0x66, 0xe3, 0x6e, 0x3c, 0x11, 0x70, 0x9f, 0x82, 0xdd, 0xeb, 0x9e,
  40026. 0xc0, 0xd7, 0x25, 0x87, 0x0c, 0x65, 0x07, 0x9d, 0x47, 0x39, 0x5d, 0x04,
  40027. 0x42, 0x5c, 0xd6, 0x0a, 0xdc, 0x39, 0x44, 0x04, 0xd9, 0x79, 0x43, 0x87,
  40028. 0x98, 0x64, 0x88, 0x82, 0x3a, 0x31, 0xbd, 0xec, 0x66, 0xcb, 0x01, 0x90,
  40029. 0xf9, 0x85, 0xcc, 0xde, 0x54, 0x69, 0x7d, 0x84, 0xb3, 0x84, 0x3c, 0x42,
  40030. 0x0d, 0x09, 0x63, 0xdb, 0xe6, 0x5d, 0xc2, 0x8a, 0xcf, 0xe1, 0xf4, 0x86,
  40031. 0x13, 0x05, 0x09, 0x9a, 0x4d, 0x05, 0xd4, 0x31, 0xe7, 0x27, 0x39, 0xfd,
  40032. 0x3a, 0xdb, 0x63, 0x9f, 0x1c, 0x67, 0x0b, 0x01, 0xec, 0xf9, 0xff, 0xf3,
  40033. 0xda, 0xa9, 0xf4, 0x9a, 0x59, 0x52, 0x76, 0xc2, 0xd2, 0xd5, 0xdd, 0x8d,
  40034. 0xb1, 0xa2, 0xef, 0xb3, 0x73, 0x99, 0xe3, 0xcd, 0x1c, 0xf5, 0xca, 0x6e,
  40035. 0x39, 0xfa, 0x26, 0x83, 0x45, 0xe7, 0xd0, 0x9c, 0x1b, 0xf7, 0xb2, 0x64,
  40036. 0xf1, 0x70, 0x00, 0x10, 0xc0, 0x7c, 0x7f, 0xb2, 0x32, 0xce, 0x6d, 0x71,
  40037. 0xa5, 0x43, 0x7c, 0x40, 0x71, 0x09, 0x54, 0x74, 0xac, 0xb5, 0xeb, 0xe0,
  40038. 0x04, 0x02, 0xe5, 0x82, 0x4d, 0x5a, 0x85, 0x1e, 0x19, 0x86, 0x39, 0x33,
  40039. 0x92, 0x2f, 0xa9, 0xa8, 0x10, 0xd2, 0x31, 0x60, 0x16, 0x08, 0x99, 0xe3,
  40040. 0x2c, 0x93, 0x13, 0xc4, 0x4b, 0x10, 0xe0, 0x42, 0xca, 0x3f, 0x32, 0xa7,
  40041. 0xa4, 0xd2, 0xfc, 0x9c, 0x93, 0xb6, 0x5f, 0xe2, 0x5b, 0x6e, 0x40, 0x0c,
  40042. 0x63, 0xf8, 0xf8, 0xe1, 0x2d, 0xcd, 0x86, 0x07, 0x79, 0xdb, 0x61, 0xad,
  40043. 0x24, 0xfd, 0x1e, 0x66, 0x3e, 0x8d, 0x76, 0xba, 0x98, 0x8e, 0x94, 0xc7,
  40044. 0x57, 0xb1, 0x65, 0xce, 0x4f, 0x97, 0xfa, 0x34, 0x7c, 0x97, 0x6b, 0xcd,
  40045. 0x3c, 0x42, 0x81, 0xa4, 0xd1, 0x75, 0xeb, 0x6d, 0x0c, 0x31, 0x0e, 0x6f,
  40046. 0xd5, 0x75, 0xe7, 0xff, 0x83, 0xdd, 0x7a, 0x4d, 0x83, 0x67, 0xa7, 0x4b,
  40047. 0xc1, 0x74, 0xad, 0x37, 0x38, 0x99, 0xe0, 0xf5, 0x5a, 0x44, 0x36, 0xa2,
  40048. 0x20, 0x2b, 0xfc, 0xc9, 0xfa, 0x68, 0xcb, 0xf0, 0x6f, 0x0a, 0x46, 0x1d,
  40049. 0xb5, 0xca, 0x5b, 0x96, 0x1b, 0x3a, 0xaf, 0x7d, 0x01, 0x7a, 0xd2, 0x09,
  40050. 0xcc, 0xd4, 0xe4, 0xb1, 0x49, 0x34, 0x56, 0x68, 0x9c, 0x0f, 0x23, 0xe9,
  40051. 0xb3, 0x4b, 0xed, 0x3d, 0xe7, 0x8d, 0x19, 0x6e, 0xe6, 0xfa, 0x06, 0x55,
  40052. 0xb8, 0x06, 0x4d, 0xa8, 0x45, 0x20, 0x91, 0xf7, 0xfa, 0x0b, 0x6b, 0xce,
  40053. 0x55, 0xa7, 0x14, 0x1b, 0xf9, 0xea, 0xc5, 0x79, 0x78, 0xf7, 0x3a, 0xd9,
  40054. 0xfc, 0x07, 0x43, 0x06, 0x90, 0x94, 0x5e, 0xc9, 0x48, 0x51, 0xe5, 0x96,
  40055. 0x68, 0x78, 0xc8, 0xcb, 0xd1, 0xf3, 0x65, 0xef, 0x14, 0x91, 0xa3, 0xca,
  40056. 0x8b, 0x77, 0x40, 0x84, 0xf4, 0x2e, 0xe7, 0x56, 0xe3, 0xab, 0xa0, 0xa8,
  40057. 0x61, 0x93, 0x17, 0x95, 0x9e, 0xff, 0x3a, 0xd4, 0x12, 0xea, 0x13, 0xe6,
  40058. 0x82, 0x16, 0xed, 0x14, 0x70, 0x91, 0xcc, 0x72, 0x58, 0x99, 0xa1, 0x7f,
  40059. 0xf3, 0x84, 0x10, 0xf4, 0x01, 0x0d, 0x05, 0x45, 0x4d, 0xca, 0x05, 0x03,
  40060. 0x75, 0x7e, 0xbb, 0x44, 0x2e, 0xf5, 0xee, 0xed, 0x64, 0x9b, 0xd3, 0xde,
  40061. 0x3e, 0xfc, 0x31, 0x8c, 0xca, 0x23, 0x66, 0x25, 0xac, 0x5f, 0x0f, 0x33,
  40062. 0x0f, 0xd2, 0xe9, 0xc9, 0x96, 0x2a, 0xe2, 0xb8, 0xed, 0x93, 0xd3, 0x78,
  40063. 0xd8, 0x81, 0xe4, 0x52, 0x9a, 0xc6, 0x64, 0x1d, 0x2d, 0x5f, 0x93, 0x9a,
  40064. 0x2e, 0x73, 0xc4, 0x17, 0xae, 0xc6, 0x08, 0x0d, 0x2d, 0xe9, 0x4b, 0x10,
  40065. 0x29, 0xa8, 0x4e, 0x8c, 0x08, 0x59, 0x87, 0x10, 0x0d, 0x5d, 0xfa, 0xec,
  40066. 0xd6, 0x42, 0xf6, 0x5c, 0xa4, 0x0d, 0xaa, 0x64, 0x8e, 0x20, 0xa5, 0x50,
  40067. 0x9f, 0x0b, 0x85, 0x37, 0x57, 0x15, 0x7c, 0xb1, 0xe4, 0xdd, 0xd5, 0x19,
  40068. 0x3b, 0x10, 0x7d, 0x22, 0xdb, 0x53, 0x8b, 0x7b, 0x32, 0xf7, 0xf2, 0x24,
  40069. 0x92, 0xb2, 0x05, 0xd1, 0xfd, 0xfc, 0x11, 0xd6, 0xfd, 0x3c, 0x8d, 0xd7,
  40070. 0xb0, 0x58, 0x50, 0x06, 0x84, 0x61, 0xa6, 0x78, 0x04, 0x1d, 0x7f, 0x92,
  40071. 0x0e, 0x8b, 0xb3, 0x63, 0x43, 0xc5, 0x30, 0x4c, 0xce, 0x2b, 0x44, 0x70,
  40072. 0x53, 0x7c, 0xb5, 0xbd, 0x30, 0xcb, 0x41, 0x19, 0x27, 0x69, 0xfe, 0x41,
  40073. 0x92, 0xae, 0xf0, 0x37, 0x33, 0xf0, 0x95, 0xe4, 0xe8, 0x4f, 0x75, 0x41,
  40074. 0x64, 0x87, 0xc5, 0x68, 0xd3, 0xce, 0xfa, 0xaa, 0xe8, 0x59, 0x88, 0xfe,
  40075. 0x24, 0x46, 0x27, 0x60, 0x71, 0x36, 0x78, 0x66, 0x3c, 0x36, 0x8e, 0xdb,
  40076. 0x90, 0x67, 0xa5, 0x6a, 0xfe, 0xd3, 0x23, 0x28, 0x91, 0x34, 0x24, 0x67,
  40077. 0x4b, 0x01, 0x6a, 0x0e, 0x02, 0xb7, 0xf0, 0xa8, 0xd4, 0x76, 0xd5, 0xa8,
  40078. 0x1c, 0xd3, 0xb3, 0x7d, 0x74, 0xc6, 0x17, 0x96, 0xa7, 0xf9, 0xad, 0x24,
  40079. 0x36, 0xd2, 0xeb, 0x34, 0x5a, 0xcc, 0x9c, 0x01, 0x99, 0xbe, 0x21, 0x4f,
  40080. 0x27, 0x9d, 0x6b, 0xca, 0x27, 0x1b, 0x60, 0x51, 0x41, 0x23, 0xe1, 0xcb,
  40081. 0xfc, 0x17, 0x2e, 0x1a, 0x4d, 0x3d, 0x51, 0xb3, 0x91, 0x8c, 0x53, 0x4d,
  40082. 0xd7, 0xbc, 0xa4, 0x07, 0xd7, 0x17, 0x19, 0x18, 0x61, 0x38, 0x4e, 0x05,
  40083. 0x81, 0x3f, 0x43, 0x8a, 0x00, 0x60, 0xdc, 0x30, 0xf4, 0x38, 0x3f, 0x93,
  40084. 0x82, 0x10, 0x29, 0x73, 0xa9, 0xbd, 0x63, 0x15, 0x7d, 0xac, 0x2e, 0xc9,
  40085. 0x05, 0xc1, 0x01, 0x41, 0x18, 0x5a, 0xc0, 0xc8, 0xc7, 0x81, 0x69, 0xe7,
  40086. 0x24, 0x21, 0x57, 0xaf, 0x88, 0x73, 0x7c, 0x53, 0x29, 0xae, 0x5a, 0xdf,
  40087. 0x76, 0x37, 0x56, 0x4f, 0x1f, 0x6b, 0xfd, 0x71, 0xbb, 0x80, 0x4a, 0xd7,
  40088. 0x53, 0x50, 0x10, 0x2d, 0xfc, 0x1a, 0xaf, 0x7c, 0x1f, 0xe8, 0xd0, 0x6c,
  40089. 0xa6, 0x45, 0x3d, 0xb5, 0x3d, 0xb2, 0xfc, 0x97, 0xa9, 0xbf, 0x7c, 0x0f,
  40090. 0x32, 0x7a, 0xcc, 0xa9, 0x2f, 0xd0, 0xc6, 0xe6, 0xcd, 0x04, 0x1d, 0x71,
  40091. 0x91, 0xb9, 0x59, 0x4b, 0xad, 0xa0, 0xde, 0x9e, 0xdc, 0x9c, 0x10, 0xeb,
  40092. 0x8d, 0xd6, 0x65, 0x57, 0xbc, 0x96, 0xfd, 0x0f, 0xcc, 0x73, 0xbe, 0x39,
  40093. 0x27, 0x99, 0x94, 0xf5, 0xe1, 0xbb, 0x32, 0xcd, 0x27, 0x7e, 0x08, 0xa0,
  40094. 0xd2, 0x92, 0x39, 0xeb, 0x71, 0xc8, 0xe8, 0x34, 0x57, 0x34, 0x4b, 0x20,
  40095. 0x3f, 0xe2, 0x68, 0xec, 0xc0, 0x8a, 0x71, 0xa3, 0x16, 0xa2, 0x91, 0x77,
  40096. 0xde, 0x41, 0x12, 0xa5, 0xf5, 0x2a, 0x63, 0x60, 0x55, 0xd0, 0x33, 0xa4,
  40097. 0xa7, 0x2e, 0xcb, 0x80, 0x08, 0xe5, 0x76, 0x16, 0x75, 0x04, 0x57, 0xe3,
  40098. 0x14, 0x71, 0x4e, 0x57, 0x29, 0x23, 0x0e, 0xc0, 0xcc, 0xad, 0xba, 0xdc,
  40099. 0x96, 0x5d, 0x23, 0x49, 0x42, 0xd8, 0x91, 0x08, 0x0d, 0x52, 0xf4, 0x5f,
  40100. 0xcd, 0xb7, 0x03, 0xaa, 0x73, 0x26, 0xa8, 0xd5, 0x5b, 0x0c, 0x85, 0xc8,
  40101. 0x84, 0x50, 0x9e, 0x70, 0x18, 0x45, 0x27, 0x82, 0x20, 0x75, 0xad, 0x52,
  40102. 0x5c, 0x80, 0x4b, 0xb1, 0x0b, 0x3b, 0x30, 0x39, 0x02, 0x54, 0x18, 0x5d,
  40103. 0x02, 0x9e, 0x85, 0x31, 0x4a, 0x07, 0x9c, 0x59, 0x5d, 0xab, 0x13, 0x4f,
  40104. 0x8f, 0x6e, 0x39, 0x20, 0xb2, 0xc5, 0x31, 0x93, 0xc6, 0xcc, 0xfb, 0xdc,
  40105. 0x15, 0xba, 0x3d, 0xcc, 0xbb, 0xd2, 0x6f, 0x04, 0x21, 0xdf, 0x0b, 0x27,
  40106. 0x5c, 0xd2, 0x6e, 0xfa, 0xda, 0x86, 0x5d, 0xe4, 0xca, 0xa4, 0x90, 0x22,
  40107. 0xa2, 0x80, 0xb5, 0x33, 0x17, 0xdb, 0x9b, 0x7b, 0x0a, 0xcc, 0x0f, 0x9b,
  40108. 0x38, 0x06, 0xdf, 0x10, 0x11, 0xa1, 0xd7, 0x2c, 0x24, 0xf0, 0xa8, 0x34,
  40109. 0x24, 0xfb, 0x99, 0xba, 0x0a, 0xb5, 0xa1, 0x94, 0x6c, 0x2d, 0xf8, 0xda,
  40110. 0x74, 0xaf, 0x19, 0x59, 0x84, 0xb2, 0x68, 0x1c, 0xef, 0xa1, 0xf5, 0x18,
  40111. 0x8f, 0x10, 0xf6, 0xb3, 0x6d, 0x33, 0x87, 0xe0, 0x25, 0xc8, 0x65, 0x5c,
  40112. 0x2f, 0x51, 0x07, 0x83, 0x69, 0x1b, 0xce, 0xa8, 0xe6, 0xe4, 0x27, 0x62,
  40113. 0x5d, 0x9b, 0x7f, 0xa7, 0x07, 0xc8, 0x54, 0x86, 0x90, 0xa5, 0x06, 0x6a,
  40114. 0x94, 0x80, 0x84, 0x97, 0xaa, 0x2a, 0xb9, 0x79, 0xe5, 0x19, 0x7a, 0x91,
  40115. 0xef, 0x8b, 0x58, 0xdc, 0xf9, 0x90, 0x94, 0xa2, 0x25, 0x4c, 0x69, 0xd8,
  40116. 0x6e, 0x9e, 0xad, 0xf8, 0x82, 0x17, 0x37, 0xc9, 0x20, 0x15, 0x24, 0x40,
  40117. 0xe5, 0xc6, 0xc1, 0xc7, 0xbd, 0xd4, 0x62, 0xff, 0x16, 0x6d, 0xa5, 0xec,
  40118. 0xe9, 0x67, 0x41, 0x9d, 0x3e, 0xfb, 0x22, 0x81, 0x80, 0x61, 0x37, 0x45,
  40119. 0xa5, 0x9f, 0x70, 0xff, 0xd4, 0x99, 0x3d, 0x79, 0x45, 0xd0, 0x27, 0xc2,
  40120. 0x32, 0xbe, 0xd4, 0xe2, 0x53, 0xa8, 0x8c, 0x94, 0x8b, 0xbe, 0x8a, 0x43,
  40121. 0xf7, 0x2a, 0x28, 0x49, 0xf4, 0xce, 0x2e, 0x0b, 0x98, 0xc7, 0xaf, 0x7d,
  40122. 0x51, 0x2e, 0xda, 0xd0, 0x7a, 0xfa, 0x91, 0x3a, 0xe6, 0xe7, 0x64, 0xd6,
  40123. 0x09, 0xd8, 0x5d, 0x6a, 0x97, 0xcf, 0x89, 0x96, 0x72, 0x21, 0x97, 0x61,
  40124. 0xc5, 0x1b, 0xd8, 0xa1, 0xf0, 0xcd, 0x9d, 0xe4, 0xe9, 0x13, 0xd0, 0x16,
  40125. 0x41, 0x20, 0xa4, 0x2c, 0x33, 0xf5, 0x3d, 0xfe, 0x80, 0xe8, 0xb2, 0x52,
  40126. 0x0e, 0x18, 0x31, 0x19, 0x50, 0xeb, 0xc6, 0x99, 0x43, 0xab, 0x9a, 0x59,
  40127. 0x5d, 0x6c, 0x84, 0x00, 0x88, 0x45, 0x7c, 0x73, 0xdf, 0x56, 0x61, 0x3a,
  40128. 0xe1, 0x55, 0xb8, 0x59, 0x13, 0xcc, 0x0e, 0x53, 0xe9, 0xf4, 0x74, 0xa0,
  40129. 0xf2, 0x15, 0xd2, 0xa8, 0xf9, 0xd4, 0x0d, 0x3d, 0xe7, 0x3d, 0x7d, 0x5b,
  40130. 0x19, 0x89, 0x8b, 0x2c, 0x4d, 0x8a, 0xeb, 0xc3, 0x43, 0x31, 0x9a, 0x45,
  40131. 0x72, 0x5b, 0x25, 0xb6, 0xa2, 0xc1, 0x98, 0xe3, 0x8a, 0xd4, 0x90, 0xd0,
  40132. 0x3e, 0x13, 0xf0, 0xd7, 0x90, 0x34, 0x94, 0xcc, 0xf1, 0x0a, 0xa9, 0x30,
  40133. 0xd1, 0x95, 0x43, 0x07, 0xcd, 0xd2, 0xca, 0xb0, 0xe5, 0xd4, 0xf1, 0xa1,
  40134. 0xc5, 0x9b, 0xf4, 0x98, 0x28, 0xba, 0xde, 0x40, 0xd6, 0x98, 0x98, 0x20,
  40135. 0x9c, 0x84, 0x9e, 0xc6, 0x57, 0xd8, 0x84, 0xc4, 0xa2, 0x9b, 0x53, 0x50,
  40136. 0xa5, 0xa6, 0x0b, 0x47, 0xe8, 0x08, 0x7d, 0xd7, 0x09, 0xa4, 0x0c, 0x2b,
  40137. 0x27, 0xde, 0xf9, 0x78, 0xbc, 0xa4, 0xb6, 0xc6, 0x1b, 0xda, 0xce, 0x6a,
  40138. 0xf8, 0x1a, 0xf5, 0xfe, 0x7b, 0xab, 0x58, 0x7c, 0xdc, 0x72, 0x02, 0x94,
  40139. 0x99, 0xf0, 0x3c, 0x37, 0x87, 0x5b, 0xd2, 0x4b, 0x5a, 0x80, 0x83, 0xd7,
  40140. 0xfc, 0x9d, 0xa7, 0x51, 0x81, 0xb8, 0x62, 0xff, 0x4b, 0xb3, 0x9f, 0x07,
  40141. 0xc3, 0x54, 0xfb, 0x41, 0x85, 0x42, 0x9d, 0xac, 0x27, 0x81, 0x2e, 0xaf,
  40142. 0x98, 0x67, 0x8c, 0x23, 0xad, 0x45, 0xfe, 0x6a, 0x57, 0x9f, 0x18, 0xc5,
  40143. 0x71, 0x8c, 0xad, 0x3f, 0x30, 0x3c, 0xaa, 0x47, 0x8d, 0xba, 0xc8, 0x7f,
  40144. 0x03, 0x1c, 0x86, 0xee, 0xba, 0x3f, 0x59, 0x45, 0xd4, 0xd0, 0xf5, 0x54,
  40145. 0x9e, 0xcb, 0x08, 0xcf, 0xca, 0x40, 0x0a, 0x06, 0xc0, 0x1e, 0x60, 0x1f,
  40146. 0x33, 0xbf, 0x2c, 0xa8, 0x5f, 0xce, 0x23, 0xa0, 0xe2, 0x1c, 0x2d, 0x56,
  40147. 0x2a, 0x44, 0x61, 0x58, 0xf1, 0x84, 0x63, 0x4f, 0x0d, 0x5e, 0xfb, 0x83,
  40148. 0x0f, 0x36, 0x1b, 0xf4, 0x8f, 0x17, 0x82, 0x2e, 0x04, 0x2c, 0x77, 0x9d,
  40149. 0x32, 0x58, 0xb8, 0xb0, 0xf9, 0x44, 0xd2, 0xf6, 0x84, 0xa4, 0x8b, 0x28,
  40150. 0x53, 0xd6, 0x99, 0x81, 0x84, 0x43, 0xf0, 0xc1, 0x15, 0xc6, 0x74, 0x4f,
  40151. 0xab, 0x05, 0xcc, 0x80, 0xdf, 0xef, 0xcf, 0xaf, 0x14, 0x82, 0xdf, 0x51,
  40152. 0x7c, 0x28, 0x5e, 0x5b, 0x27, 0x5e, 0x91, 0x8b, 0x54, 0x3d, 0x54, 0x26,
  40153. 0xb0, 0x3f, 0xd7, 0xc5, 0xce, 0xf3, 0x6d, 0x2c, 0x12, 0xc6, 0xb4, 0x48,
  40154. 0x60, 0x11, 0x9c, 0xef, 0x29, 0x98, 0x9c, 0x76, 0x4e, 0x73, 0x2b, 0xd2,
  40155. 0x23, 0x53, 0x7d, 0x03, 0xc2, 0x2f, 0x8a, 0xa1, 0xe2, 0x84, 0x54, 0x2d,
  40156. 0xd8, 0xc6, 0x55, 0x77, 0x9d, 0x07, 0x67, 0x1f, 0x1a, 0xd3, 0x57, 0x4c,
  40157. 0x25, 0x79, 0x8f, 0xd8, 0x82, 0xc2, 0x4d, 0x87, 0x84, 0x33, 0xdc, 0x47,
  40158. 0xed, 0x9e, 0xfb, 0xd2, 0x62, 0xc8, 0x50, 0x76, 0xda, 0x3c, 0x3c, 0x05,
  40159. 0x0e, 0x2d, 0x30, 0x56, 0xca, 0x4d, 0x6a, 0xe2, 0x17, 0x24, 0x26, 0x9c,
  40160. 0xff, 0x09, 0xec, 0xb3, 0x94, 0xec, 0xab, 0x69, 0xb2, 0xf0, 0xa5, 0x66,
  40161. 0x18, 0x92, 0x49, 0x6b, 0x90, 0xf5, 0x77, 0x5a, 0x18, 0xe5, 0x51, 0x36,
  40162. 0x4a, 0x35, 0x54, 0x98, 0x48, 0x04, 0xa9, 0x0f, 0xcb, 0x55, 0xf1, 0x71,
  40163. 0xad, 0x1a, 0x4a, 0x2c, 0x0e, 0x5d, 0x5e, 0x77, 0x47, 0xf5, 0x46, 0x17,
  40164. 0x6b, 0x94, 0x2a, 0xbc, 0x40, 0xe5, 0xa7, 0xa6, 0x88, 0x41, 0x76, 0x22,
  40165. 0x47, 0xd1, 0xe8, 0x2b, 0x18, 0x48, 0x21, 0xc0, 0xe8, 0x4f, 0xe2, 0xb2,
  40166. 0x7e, 0x03, 0xbb, 0x25, 0x9c, 0xc8, 0x68, 0x66, 0x48, 0x25, 0x6a, 0xf2,
  40167. 0x64, 0x29, 0xec, 0x79, 0xba, 0xdb, 0x34, 0xe1, 0xd4, 0xf9, 0x52, 0x0e,
  40168. 0xfd, 0x8d, 0x86, 0x94, 0x71, 0xd8, 0xe0, 0x86, 0x02, 0x9b, 0xd4, 0x65,
  40169. 0x69, 0x5e, 0x01, 0x32, 0x87, 0x59, 0xd8, 0x6c, 0xbc, 0x8a, 0x9f, 0x58,
  40170. 0x28, 0x8c, 0x97, 0xef, 0x33, 0xb2, 0xda, 0x45, 0xa0, 0xec, 0xe5, 0x5b,
  40171. 0xac, 0xc6, 0x65, 0xc1, 0xb6, 0xcb, 0xf7, 0x85, 0x0e, 0xfa, 0x78, 0x36,
  40172. 0x30, 0x84, 0x90, 0xa8, 0xf8, 0x42, 0x25, 0xa5, 0xdd, 0xdc, 0xdc, 0x89,
  40173. 0xd3, 0xf0, 0x73, 0x9a, 0xd8, 0x95, 0x8f, 0x04, 0xbf, 0xc1, 0xfd, 0x94,
  40174. 0xff, 0xe6, 0xf8, 0x4e, 0xc6, 0x43, 0xc9, 0x60, 0x30, 0xe9, 0x68, 0xa8,
  40175. 0x76, 0xfb, 0xfa, 0xdf, 0xc0, 0x9b, 0xbc, 0xbc, 0x34, 0xe4, 0x38, 0xfd,
  40176. 0x93, 0xb0, 0x47, 0xb2, 0x3e, 0x83, 0x6c, 0xef, 0xe1, 0xaf, 0x35, 0xb4,
  40177. 0x90, 0x2a, 0x32, 0xaf, 0x25, 0x3f, 0x3e, 0x72, 0x61, 0xc0, 0x0f, 0x29,
  40178. 0xbb, 0x46, 0x6e, 0x2e, 0x94, 0x7d, 0xdd, 0xb7, 0x67, 0x1f, 0x7b, 0x64,
  40179. 0xcb, 0xa5, 0x9a, 0x58, 0x63, 0x20, 0xa7, 0xc0, 0x94, 0xa9, 0xad, 0x90,
  40180. 0x7d, 0xf3, 0x2b, 0x61, 0x2b, 0x64, 0x3d, 0x8a, 0xc3, 0xd1, 0xcb, 0xad,
  40181. 0x36, 0x44, 0xe6, 0x29, 0x8b, 0x3d, 0x95, 0x7c, 0xa7, 0xa2, 0xfa, 0x1b,
  40182. 0x16, 0x8d, 0x9e, 0xc4, 0xf8, 0x4c, 0x76, 0x20, 0x00, 0x68, 0x07, 0x99,
  40183. 0x9c, 0x60, 0xe6, 0x16, 0x6a, 0x6f, 0x8a, 0xbe, 0x71, 0x95, 0xa1, 0xcb,
  40184. 0xfe, 0x7c, 0x41, 0x59, 0x61, 0x20, 0xf9, 0x54, 0x3c, 0xb1, 0x19, 0x5c,
  40185. 0x42, 0x67, 0x3f, 0xff, 0xf3, 0x32, 0x21, 0x9c, 0x9e, 0x88, 0xf9, 0x97,
  40186. 0x00, 0x43, 0x73, 0x4a, 0xfc, 0x54, 0xeb, 0x27, 0x79, 0x14, 0x85, 0xd3,
  40187. 0xdc, 0x47, 0xb3, 0x6d, 0x24, 0xd3, 0xf7, 0x7a, 0xfb, 0x90, 0x7c, 0x6e,
  40188. 0xcd, 0x4e, 0xbf, 0x26, 0x76, 0xd2, 0xe8, 0xcc, 0x67, 0xd1, 0x23, 0x3c,
  40189. 0x94, 0x16, 0x1e, 0x07, 0x36, 0x7c, 0x96, 0xf6, 0xe8, 0x50, 0x72, 0x26,
  40190. 0x56, 0x67, 0x89, 0xa9, 0x11, 0xfb, 0x1d, 0xb8, 0xb9, 0x2a, 0x55, 0xb7,
  40191. 0x85, 0xf7, 0x40, 0xa2, 0xfc, 0x9f, 0x30, 0xec, 0x8f, 0x9a, 0x1c, 0xc8,
  40192. 0xe4, 0xc5, 0x1f, 0xcb, 0x0a, 0x60, 0x80, 0x41, 0xec, 0x88, 0x8a, 0xda,
  40193. 0x7c, 0x7a, 0xa1, 0x96, 0x51, 0x62, 0x16, 0x63, 0x75, 0x36, 0x28, 0x7c,
  40194. 0xc9, 0xd0, 0x27, 0x0c, 0x9e, 0x18, 0x4a, 0x82, 0xf7, 0x02, 0xb9, 0x40,
  40195. 0x8f, 0xd5, 0x97, 0x7a, 0x35, 0xa9, 0x3a, 0xb3, 0x8b, 0x6b, 0xf1, 0x9a,
  40196. 0xd1, 0xe7, 0x14, 0x38, 0x5e, 0xba, 0x8c, 0xbf, 0x32, 0xaa, 0x34, 0x30,
  40197. 0x7c, 0x1e, 0x11, 0xcd, 0x1f, 0x9f, 0xcf, 0x4d, 0x14, 0xce, 0x67, 0xf9,
  40198. 0x9c, 0x89, 0x07, 0x92, 0x44, 0x6e, 0x9a, 0x16, 0xe4, 0xfb, 0x67, 0x01,
  40199. 0x3f, 0x4c, 0x14, 0x89, 0x33, 0x87, 0x46, 0xc6, 0xe4, 0x66, 0x94, 0xd4,
  40200. 0x87, 0x4f, 0x2c, 0x92, 0x1b, 0xae, 0x82, 0xe7, 0x99, 0xaa, 0xb4, 0x99,
  40201. 0x81, 0x26, 0xa6, 0x6f, 0x1d, 0xc1, 0x95, 0x80, 0xe9, 0xea, 0xe3, 0x44,
  40202. 0x6a, 0x2b, 0xd2, 0xe0, 0x0d, 0x69, 0x42, 0xf7, 0x27, 0x6b, 0x4f, 0x02,
  40203. 0x7a, 0x33, 0x7b, 0x43, 0x3d, 0xef, 0x10, 0xaa, 0xab, 0xc5, 0xa2, 0xf0,
  40204. 0xbb, 0x07, 0x4b, 0x26, 0x0c, 0x58, 0xcd, 0x3b, 0xd2, 0x6d, 0xa5, 0x32,
  40205. 0x37, 0x88, 0x4e, 0x8b, 0xe3, 0x75, 0xb0, 0xbb, 0x87, 0xea, 0xa4, 0x53,
  40206. 0xf3, 0xff, 0x39, 0x92, 0x44, 0xab, 0x7b, 0x71, 0x62, 0x31, 0x6b, 0x31,
  40207. 0xca, 0x97, 0xba, 0xd7, 0x41, 0xe0, 0x47, 0x47, 0x4f, 0x77, 0xa2, 0x35,
  40208. 0x62, 0x7a, 0xc1, 0xb6, 0x69, 0x10, 0x09, 0xce, 0xfc, 0x92, 0xcc, 0xc5,
  40209. 0x7a, 0x11, 0xf1, 0xc1, 0xa0, 0x80, 0xe5, 0x42, 0x17, 0xb6, 0x3f, 0xab,
  40210. 0xc1, 0xa2, 0x41, 0xfb, 0xe3, 0x98, 0x2d, 0x7a, 0xe4, 0x1b, 0x1f, 0x7e,
  40211. 0x71, 0x3c, 0x3e, 0x90, 0x8c, 0x60, 0x30, 0xb7, 0x73, 0x06, 0x1f, 0x8a,
  40212. 0xce, 0x50, 0x20, 0x7c, 0xfa, 0x8c, 0xf2, 0x14, 0xd9, 0x00, 0xa2, 0x21,
  40213. 0xea, 0x10, 0x36, 0x21, 0x6f, 0x7f, 0x13, 0xe3, 0x6c, 0xb2, 0xd6, 0xa5,
  40214. 0xa6, 0x6e, 0xa9, 0xe7, 0x1d, 0xdf, 0xc9, 0x97, 0x60, 0x75, 0xa3, 0x55,
  40215. 0xa1, 0x2c, 0x94, 0xd7, 0x85, 0x4b, 0x44, 0xc6, 0x9c, 0x17, 0xc2, 0xad,
  40216. 0xe6, 0x56, 0x72, 0x1d, 0xb9, 0x13, 0x54, 0xfe, 0x8c, 0xec, 0xf4, 0xa3,
  40217. 0x54, 0x6b, 0x31, 0xbc, 0x55, 0x9e, 0x01, 0xd4, 0x9b, 0x24, 0x9e, 0x51,
  40218. 0xaf, 0x67, 0x76, 0x02, 0xf7, 0x34, 0x6a, 0xaa, 0xb0, 0x3c, 0x70, 0x2e,
  40219. 0xc8, 0x86, 0xfa, 0x40, 0x89, 0x12, 0xb7, 0x49, 0x38, 0x0b, 0xf7, 0x66,
  40220. 0xd2, 0x2e, 0x58, 0xf1, 0x22, 0x3b, 0xb3, 0x40, 0x6b, 0x7a, 0x68, 0x4d,
  40221. 0x42, 0xfd, 0xbf, 0xa0, 0xf7, 0x2f, 0x63, 0x4a, 0x87, 0xe7, 0x99, 0x52,
  40222. 0x6e, 0xe7, 0xdd, 0xca, 0x19, 0x71, 0xee, 0x92, 0xe2, 0x68, 0x0e, 0xe1,
  40223. 0xb7, 0x90, 0x1f, 0xc4, 0xef, 0xf8, 0xf6, 0x85, 0x53, 0x18, 0x33, 0x86,
  40224. 0x15, 0xc8, 0x29, 0x58, 0x6f, 0xf0, 0x1c, 0x14, 0x73, 0xa9, 0x8e, 0x88,
  40225. 0x74, 0xd4, 0x21, 0xf5, 0xc6, 0x7c, 0xd8, 0x96, 0x0f, 0xb0, 0xa6, 0x7b,
  40226. 0xf7, 0x72, 0x15, 0xd7, 0x30, 0x6b, 0x15, 0x1d, 0x3f, 0xb7, 0x4e, 0xaa,
  40227. 0xc0, 0x52, 0x1d, 0x84, 0xbf, 0x98, 0xbd, 0x33, 0x02, 0xab, 0x8b, 0xd0,
  40228. 0x9c, 0x85, 0x2f, 0xa3, 0xfb, 0x46, 0x8d, 0x4d, 0x97, 0x1a, 0x8a, 0x3c,
  40229. 0x73, 0x5b, 0x3b, 0x58, 0x26, 0xba, 0x6b, 0x45, 0x2e, 0x24, 0x66, 0x79,
  40230. 0x7d, 0xc4, 0xf8, 0x8c, 0x05, 0x7d, 0x5c, 0x23, 0xb9, 0xe8, 0x5d, 0xfe,
  40231. 0xc9, 0x84, 0xe5, 0x58, 0x40, 0xa4, 0xb7, 0x55, 0x74, 0x69, 0x92, 0x9c,
  40232. 0x3e, 0x19, 0xb1, 0xb6, 0x51, 0xe9, 0x71, 0xcc, 0x96, 0x2b, 0x01, 0x71,
  40233. 0xf5, 0xb9, 0xde, 0x77, 0xfe, 0x2e, 0x74, 0x9c, 0x6a, 0x52, 0x17, 0x1e,
  40234. 0xea, 0xd9, 0xc8, 0x14, 0xbe, 0x61, 0xdf, 0xe9, 0x96, 0x24, 0x5a, 0x9a,
  40235. 0xd8, 0xd7, 0xad, 0x71, 0xe0, 0xf4, 0xbb, 0x9e, 0xae, 0x95, 0xcd, 0x58,
  40236. 0x94, 0x81, 0xee, 0x46, 0x84, 0x65, 0x39, 0xb1, 0x1b, 0x1e, 0xf5, 0x50,
  40237. 0xad, 0x56, 0x58, 0xb7, 0x53, 0x9b, 0x2a, 0x2f, 0x09, 0x61, 0x57, 0xda,
  40238. 0xf5, 0xdc, 0x9f, 0x3c, 0x6c, 0x69, 0x0d, 0x61, 0x49, 0xb2, 0xe0, 0xb2,
  40239. 0xe5, 0xef, 0x19, 0xbe, 0x04, 0xf6, 0x6b, 0xad, 0x41, 0x4c, 0x5a, 0x50,
  40240. 0xf6, 0xac, 0x1b, 0x25, 0x8a, 0xdd, 0xe3, 0x57, 0xab, 0x7c, 0x92, 0xe4
  40241. };
  40242. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40243. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_pub_key[] = {
  40244. 0xef, 0x49, 0x79, 0x47, 0x15, 0xc4, 0x8a, 0xa9, 0x74, 0x2a,
  40245. 0xf0, 0x36, 0x94, 0x5c, 0x91, 0x1c, 0x5d, 0xff, 0x2c, 0x83,
  40246. 0xf2, 0x8b, 0x04, 0xfc, 0x5d, 0x64, 0xbd, 0x49, 0x73, 0xcd,
  40247. 0xcc, 0x99, 0x50, 0x5f, 0x2b, 0x16, 0x3a, 0xbb, 0x98, 0xc0,
  40248. 0xa7, 0x69, 0x0e, 0x95, 0x99, 0x0b, 0xa2, 0x6c, 0xfe, 0x6c,
  40249. 0xdb, 0xc8, 0xa7, 0x09, 0x46, 0x6c, 0x90, 0x50, 0xa4, 0x75,
  40250. 0x30, 0xf7, 0x90, 0xac, 0x31, 0xb6, 0xdd, 0x21, 0xaf, 0xc6,
  40251. 0xf9, 0xfe, 0xee, 0xc6, 0x5b, 0xa8, 0x8f, 0x0a, 0x2e, 0xd0,
  40252. 0x42, 0xab, 0xa8, 0x3c, 0x8d, 0xbf, 0xf7, 0x44, 0xbd, 0x0d,
  40253. 0xcf, 0xf4, 0x68, 0xfc, 0x16, 0x67, 0xf7, 0x39, 0x48, 0x5f,
  40254. 0x56, 0xd1, 0xe7, 0x1f, 0x49, 0x80, 0x50, 0xbe, 0x54, 0xd1,
  40255. 0xb7, 0xc9, 0xd2, 0x32, 0xc7, 0x08, 0x8c, 0xde, 0x2c, 0x31,
  40256. 0xf6, 0x1d, 0xc7, 0xac, 0xb3, 0x79, 0xd7, 0x4b, 0x1b, 0x23,
  40257. 0x89, 0x0a, 0xdc, 0x8e, 0x44, 0x41, 0x14, 0x28, 0x99, 0x13,
  40258. 0xb3, 0x26, 0xa6, 0x0e, 0x83, 0x60, 0xaa, 0x8d, 0x7c, 0x23,
  40259. 0x13, 0xba, 0x6c, 0x28, 0x90, 0x56, 0x84, 0xa1, 0x23, 0x8b,
  40260. 0x81, 0x20, 0x97, 0x7c, 0x66, 0x3f, 0xed, 0x5d, 0xd0, 0xe4,
  40261. 0x5d, 0xee, 0x46, 0xbc, 0x4b, 0x3c, 0x03, 0xb5, 0xbc, 0x4d,
  40262. 0x8d, 0x37, 0xa3, 0x56, 0x4b, 0x33, 0xad, 0xef, 0xd4, 0xb6,
  40263. 0xec, 0xdb, 0x04, 0x9a, 0x19, 0x58, 0x57, 0xd8, 0x00, 0x3a,
  40264. 0x92, 0x61, 0x0c, 0x0b, 0xc8, 0x52, 0xe5, 0x04, 0x02, 0x9a,
  40265. 0x00, 0x7e, 0xec, 0x7e, 0x94, 0xaa, 0xef, 0x2d, 0x7f, 0xb6,
  40266. 0x2e, 0x7c, 0xb0, 0x73, 0xa2, 0x20, 0xc0, 0x07, 0x30, 0x41,
  40267. 0x50, 0x20, 0x14, 0x18, 0x21, 0x5e, 0x2a, 0x6f, 0x70, 0x21,
  40268. 0xd6, 0x97, 0x13, 0xb9, 0xc1, 0x9e, 0x90, 0x67, 0xcc, 0x55,
  40269. 0x8a, 0xec, 0xec, 0x0a, 0x1e, 0x90, 0xdc, 0x3f, 0xb0, 0x4d,
  40270. 0xd1, 0x18, 0xea, 0x4f, 0xcb, 0x5d, 0x15, 0x4c, 0xb8, 0x35,
  40271. 0x9b, 0x34, 0x24, 0x30, 0x06, 0x53, 0x17, 0xf0, 0xbe, 0x27,
  40272. 0x36, 0xb3, 0x04, 0x6a, 0xbd, 0xbf, 0xa7, 0x39, 0xee, 0xa9,
  40273. 0x8f, 0x0e, 0x98, 0xc5, 0xf5, 0x9f, 0x46, 0x25, 0x93, 0xc9,
  40274. 0xf2, 0xf6, 0x2b, 0x8e, 0x92, 0x06, 0x01, 0x3d, 0x81, 0x18,
  40275. 0xf2, 0xec, 0xf1, 0x05, 0x4c, 0xad, 0x4b, 0xcb, 0x98, 0xa4,
  40276. 0xb5, 0x61, 0x20, 0xda, 0x81, 0xa1, 0xfb, 0x92, 0x4c, 0xaf,
  40277. 0x87, 0x6f, 0x6e, 0xd2, 0x57, 0xec, 0xcd, 0x94, 0xb3, 0x79,
  40278. 0xbf, 0x59, 0x88, 0x17, 0x81, 0xce, 0x8a, 0x57, 0xce, 0x57,
  40279. 0xae, 0x3e, 0x82, 0x81, 0x2f, 0x83, 0x61, 0xd8, 0xf9, 0x68,
  40280. 0x21, 0xe7, 0x72, 0x5b, 0xd6, 0x80, 0x55, 0x68, 0x5d, 0x67,
  40281. 0x15, 0x0c, 0x8b, 0xdc, 0x4f, 0xc3, 0x89, 0x36, 0x3c, 0xac,
  40282. 0xaf, 0x16, 0x5e, 0x1c, 0xfa, 0x68, 0x74, 0x6a, 0xab, 0x68,
  40283. 0xd8, 0x59, 0x96, 0x2d, 0x33, 0x62, 0xe4, 0xbd, 0xb3, 0xb7,
  40284. 0x4d, 0x88, 0x35, 0xb8, 0xed, 0xb2, 0x16, 0x85, 0x97, 0x08,
  40285. 0x71, 0x71, 0x39, 0x7e, 0x0c, 0x53, 0x16, 0xda, 0x38, 0xe5,
  40286. 0x28, 0x09, 0x9c, 0xd9, 0x46, 0xec, 0x68, 0xda, 0x8d, 0xd0,
  40287. 0xad, 0xb2, 0x79, 0x28, 0x3b, 0x1e, 0x12, 0xc9, 0xdf, 0xa9,
  40288. 0x6d, 0x3d, 0x29, 0x99, 0x2f, 0x53, 0xc2, 0xd0, 0xf9, 0x88,
  40289. 0x26, 0x94, 0x47, 0xaf, 0xf6, 0x96, 0xf3, 0xe1, 0x11, 0xa6,
  40290. 0x82, 0x3d, 0x43, 0x3f, 0x1f, 0xbc, 0xf6, 0x98, 0xbe, 0xff,
  40291. 0x06, 0x86, 0x61, 0x27, 0xdc, 0x91, 0x54, 0xd4, 0xfc, 0x68,
  40292. 0x83, 0xe8, 0x35, 0x3e, 0xee, 0x94, 0x59, 0x28, 0x2f, 0xde,
  40293. 0xdd, 0x03, 0x60, 0x66, 0xc1, 0x49, 0x57, 0xdd, 0xbc, 0xd5,
  40294. 0x0a, 0x67, 0x34, 0xf1, 0xa6, 0x0a, 0x57, 0x94, 0x65, 0x02,
  40295. 0x2c, 0x52, 0x43, 0x70, 0x3b, 0xc1, 0x9a, 0xff, 0xda, 0x6f,
  40296. 0xb9, 0x54, 0x47, 0x01, 0xda, 0x27, 0xe4, 0x48, 0x4a, 0x90,
  40297. 0x9f, 0xb5, 0xc3, 0xee, 0x0e, 0x09, 0x57, 0xfe, 0x48, 0x51,
  40298. 0x08, 0x34, 0x5e, 0x8f, 0x16, 0xc9, 0x0b, 0x74, 0xd9, 0x7d,
  40299. 0x22, 0x3f, 0xd6, 0xb7, 0x5d, 0xd6, 0x76, 0x00, 0x8d, 0x4e,
  40300. 0x78, 0x73, 0x86, 0xd6, 0xdb, 0x2a, 0x65, 0xab, 0xdf, 0xb0,
  40301. 0xea, 0x11, 0xad, 0xdf, 0xba, 0x43, 0xdb, 0xa8, 0x0a, 0xfb,
  40302. 0x04, 0x38, 0x81, 0x2b, 0xa3, 0x29, 0xfc, 0x95, 0x73, 0x9a,
  40303. 0x0c, 0x6c, 0x9e, 0xcd, 0xdc, 0xcf, 0x0a, 0x0c, 0x18, 0x41,
  40304. 0x6f, 0x1d, 0xa3, 0xf6, 0x12, 0x4c, 0x13, 0xf2, 0x02, 0xc6,
  40305. 0x50, 0x99, 0x86, 0x73, 0xa7, 0xf9, 0x7e, 0x84, 0x7f, 0x4c,
  40306. 0x00, 0xce, 0x2e, 0x21, 0x76, 0x8e, 0x17, 0x7a, 0x87, 0x6f,
  40307. 0x81, 0xe6, 0xc0, 0x52, 0xa5, 0xa0, 0x3c, 0x54, 0x3c, 0xec,
  40308. 0xb0, 0x9d, 0x1c, 0x3b, 0xec, 0xe5, 0x4e, 0x4a, 0x37, 0xe7,
  40309. 0xd5, 0xa9, 0x07, 0x87, 0x23, 0x28, 0x5d, 0x3d, 0x22, 0x02,
  40310. 0x79, 0x40, 0x3f, 0x2d, 0x40, 0xc9, 0xe5, 0xa6, 0x9b, 0xa8,
  40311. 0xb8, 0x76, 0xf6, 0x77, 0x5b, 0x8d, 0x72, 0x96, 0x3e, 0x13,
  40312. 0xbf, 0x76, 0xfa, 0x7b, 0xb7, 0x82, 0x5f, 0xe7, 0x9d, 0x54,
  40313. 0x0e, 0x05, 0x1a, 0x9f, 0xa4, 0x42, 0xa5, 0xb4, 0x93, 0x23,
  40314. 0x06, 0x59, 0x43, 0xa8, 0xe8, 0x5c, 0xfc, 0x18, 0x97, 0xdb,
  40315. 0xad, 0x9a, 0x80, 0x0a, 0xf2, 0x20, 0x50, 0xac, 0xc1, 0x13,
  40316. 0x3e, 0x98, 0x09, 0xde, 0xf2, 0x70, 0x9e, 0x14, 0xc2, 0x5c,
  40317. 0xec, 0x65, 0x07, 0x0b, 0xfa, 0x02, 0x5c, 0xf8, 0x71, 0xaa,
  40318. 0x9b, 0x45, 0x62, 0xe2, 0x27, 0xaf, 0x77, 0xf8, 0xe3, 0xeb,
  40319. 0x7b, 0x24, 0x7b, 0x3c, 0x67, 0xc2, 0x6d, 0x6e, 0x17, 0xae,
  40320. 0x6e, 0x86, 0x6f, 0x98, 0xc9, 0xac, 0x13, 0x9f, 0x87, 0x64,
  40321. 0x3d, 0x4d, 0x6f, 0xa0, 0xb3, 0x39, 0xc6, 0x68, 0x1b, 0xa7,
  40322. 0xeb, 0x3e, 0x0f, 0x6b, 0xc7, 0xa4, 0xe2, 0x20, 0x27, 0x75,
  40323. 0x3f, 0x09, 0x16, 0xff, 0x1a, 0xcc, 0xa7, 0xc4, 0x6d, 0xc2,
  40324. 0xfc, 0xc3, 0x0b, 0x37, 0x63, 0xff, 0x9b, 0x10, 0xe6, 0x00,
  40325. 0xf7, 0x18, 0x43, 0x9f, 0x07, 0x50, 0x31, 0x51, 0xd4, 0xfd,
  40326. 0xad, 0xa2, 0x0f, 0x77, 0xda, 0x41, 0xc1, 0x0a, 0x6f, 0x86,
  40327. 0xd7, 0xdc, 0x8a, 0x52, 0xd6, 0xa1, 0x27, 0xdb, 0x14, 0x67,
  40328. 0x26, 0x91, 0xb3, 0xcd, 0x01, 0x5f, 0x60, 0xa1, 0x7f, 0x43,
  40329. 0x15, 0x1a, 0x82, 0x0f, 0xd3, 0x66, 0x5f, 0x60, 0x57, 0x2f,
  40330. 0xb2, 0x8c, 0x27, 0x2a, 0x9d, 0x1b, 0xf9, 0xf2, 0x59, 0x20,
  40331. 0x39, 0xd9, 0xc5, 0xaf, 0xf2, 0x36, 0x8c, 0x58, 0x00, 0x1b,
  40332. 0xd0, 0xc5, 0x8e, 0x1a, 0x49, 0xa8, 0x60, 0xbe, 0xd1, 0xd7,
  40333. 0x2a, 0xb0, 0xc2, 0xab, 0x58, 0x8a, 0x7a, 0xa9, 0x41, 0x68,
  40334. 0x70, 0xbd, 0xea, 0x73, 0xa5, 0x03, 0x11, 0xb2, 0x27, 0xd9,
  40335. 0xcd, 0xf5, 0x09, 0xe8, 0x1c, 0xe2, 0x4f, 0x50, 0x6a, 0x84,
  40336. 0x34, 0x62, 0x2e, 0x36, 0xaa, 0x4c, 0xc1, 0x83, 0x78, 0x98,
  40337. 0x35, 0x7a, 0x27, 0x7e, 0xfe, 0xf1, 0x6f, 0x59, 0x27, 0x35,
  40338. 0x73, 0xce, 0x74, 0xaa, 0xb4, 0x72, 0x82, 0xa8, 0xe2, 0x81,
  40339. 0x7a, 0x6b, 0xca, 0x33, 0xa5, 0xda, 0xa2, 0x63, 0xca, 0x2e,
  40340. 0x90, 0x03, 0x32, 0xec, 0x63, 0xdb, 0x52, 0x7b, 0x16, 0xfc,
  40341. 0x01, 0x2d, 0x30, 0x12, 0x1e, 0xf9, 0xa3, 0x72, 0x21, 0x3c,
  40342. 0x75, 0x0c, 0x61, 0x9c, 0x7e, 0x73, 0x04, 0x71, 0x41, 0x45,
  40343. 0x5d, 0x7f, 0x49, 0x1c, 0x09, 0x08, 0xa4, 0xec, 0x2f, 0xfd,
  40344. 0xc4, 0xfb, 0x59, 0x6a, 0x27, 0x7a, 0xd4, 0xfc, 0x5f, 0x20,
  40345. 0x04, 0x34, 0x7d, 0x08, 0xed, 0x82, 0x5a, 0x90, 0xe1, 0xab,
  40346. 0xfd, 0x35, 0x3a, 0x8d, 0xbb, 0x0a, 0x9d, 0x73, 0xff, 0x69,
  40347. 0xe5, 0xe9, 0x09, 0x55, 0x14, 0xd9, 0x7b, 0x6f, 0x0d, 0x99,
  40348. 0xd2, 0x7e, 0x71, 0xf8, 0x4f, 0x72, 0x2f, 0xbb, 0xc6, 0xc4,
  40349. 0x36, 0xc9, 0x01, 0xd3, 0x9b, 0x94, 0xab, 0x41, 0x0f, 0x4a,
  40350. 0x61, 0x5c, 0x68, 0xe5, 0xd7, 0x0d, 0x94, 0xaa, 0xee, 0xba,
  40351. 0x95, 0xcb, 0x8c, 0x0e, 0x85, 0x3a, 0x02, 0x6b, 0x95, 0x50,
  40352. 0xfd, 0x02, 0xfd, 0xa4, 0x58, 0x29, 0x78, 0x4f, 0xd0, 0xae,
  40353. 0x66, 0xd6, 0x5c, 0xe7, 0x45, 0xfe, 0x98, 0xb0, 0xa3, 0xe2,
  40354. 0x87, 0xc0, 0xd2, 0x81, 0x08, 0xf1, 0xf1, 0xe7, 0xda, 0x62,
  40355. 0x9e, 0xa0, 0x34, 0x86, 0xeb, 0xa1, 0x6e, 0x4a, 0x26, 0x8e,
  40356. 0x39, 0x0c, 0x51, 0x10, 0x33, 0x11, 0x87, 0xf8, 0x79, 0x3c,
  40357. 0x49, 0x7a, 0x8b, 0xce, 0xc1, 0x0a, 0x0e, 0xe1, 0xd5, 0x2a,
  40358. 0xac, 0xf0, 0x3a, 0x1d, 0x6a, 0x6a, 0xe5, 0xe1, 0x81, 0x70,
  40359. 0xad, 0xaf, 0x15, 0x4c, 0x2a, 0x70, 0x2a, 0x6b, 0x22, 0x0d,
  40360. 0x30, 0xe7, 0x56, 0xed, 0x2d, 0x4b, 0x85, 0x17, 0x49, 0x72,
  40361. 0x3a, 0x1b, 0x6f, 0x57, 0x1c, 0xf7, 0x72, 0x9e, 0x20, 0xdb,
  40362. 0x57, 0x1c, 0xfb, 0x36, 0x50, 0x52, 0xec, 0x5b, 0xd6, 0x6a,
  40363. 0x1b, 0xf8, 0x74, 0xad, 0xe6, 0x00, 0x74, 0x04, 0xc5, 0x99,
  40364. 0x83, 0xe4, 0x5a, 0x0c, 0xc3, 0xe8, 0x6d, 0x3a, 0xd7, 0x3c,
  40365. 0x3c, 0xc0, 0x1a, 0x28, 0xb3, 0x29, 0x7a, 0x10, 0x9e, 0x39,
  40366. 0x66, 0x5b, 0xc1, 0x38, 0xac, 0x21, 0x4e, 0xcd, 0x01, 0xf2,
  40367. 0xf6, 0x30, 0x2c, 0x2b, 0xb6, 0xbf, 0xf5, 0xea, 0x61, 0xaf,
  40368. 0x0c, 0xa6, 0x01, 0x11, 0x15, 0x19, 0x09, 0x8c, 0x7e, 0x69,
  40369. 0xdf, 0x3b, 0xea, 0xd3, 0x0a, 0x3a, 0xd7, 0xbd, 0xe1, 0x17,
  40370. 0xaf, 0x92, 0x3c, 0xf5, 0xfe, 0x35, 0xd6, 0xcf, 0x07, 0xa6,
  40371. 0xf7, 0xe9, 0xc1, 0x99, 0xed, 0x80, 0xe3, 0x12, 0xd5, 0x4b,
  40372. 0xb9, 0xdf, 0xaf, 0x4e, 0x52, 0xad, 0x8e, 0x66, 0x87, 0xe5,
  40373. 0x2c, 0xd0, 0x45, 0x70, 0xd9, 0x78, 0x8f, 0x4b, 0xf4, 0xe1,
  40374. 0xf1, 0x22, 0xf2, 0xe3, 0xed, 0x1f, 0xeb, 0xe9, 0x70, 0x31,
  40375. 0x4c, 0x65, 0x5f, 0x55, 0xee, 0x5d, 0xaa, 0x83, 0x87, 0x76,
  40376. 0xbe, 0x11, 0xae, 0xd7, 0xf2, 0xfb, 0x43, 0xe7, 0x17, 0x81,
  40377. 0x33, 0x15, 0x47, 0xa0, 0xf3, 0x8e, 0x84, 0x57, 0xff, 0x35,
  40378. 0x9e, 0x4a, 0x8a, 0xab, 0x50, 0x3a, 0x45, 0xe0, 0xc3, 0x73,
  40379. 0xca, 0x77, 0x61, 0x68, 0x38, 0xd0, 0xa3, 0x5f, 0x03, 0x8d,
  40380. 0x41, 0xc2, 0xd3, 0x4a, 0x17, 0xe0, 0xa8, 0xaa, 0x00, 0xf3,
  40381. 0xf2, 0x5b, 0xa8, 0xe1, 0x06, 0xa6, 0x2b, 0xdb, 0xe1, 0x74,
  40382. 0xbd, 0xc4, 0xd2, 0x2b, 0x55, 0x9a, 0xb0, 0xf8, 0x35, 0xd8,
  40383. 0x6b, 0xec, 0xdb, 0xc5, 0xf4, 0x6c, 0x40, 0x90, 0x6a, 0x68,
  40384. 0xc9, 0xb5, 0xcb, 0xbb, 0xd0, 0xb0, 0xbc, 0x9f, 0xb9, 0xaa,
  40385. 0x50, 0x14, 0x93, 0x3b, 0x9f, 0x25, 0xcb, 0x40, 0xb8, 0x08,
  40386. 0xcc, 0x13, 0xe5, 0xdc, 0x3f, 0x84, 0x96, 0xe0, 0x73, 0x7b,
  40387. 0x7d, 0x9e, 0x41, 0x92, 0x5d, 0xcc, 0xa4, 0xea, 0x4f, 0x93,
  40388. 0x0c, 0x40, 0x2e, 0x42, 0x8a, 0xe9, 0xb9, 0x12, 0x74, 0xbb,
  40389. 0x79, 0x7c, 0xb0, 0x37, 0x20, 0xb6, 0xaf, 0x43, 0x3a, 0x88,
  40390. 0x59, 0x7c, 0x68, 0x28, 0x5f, 0x98, 0xc2, 0xf0, 0x2a, 0xbc,
  40391. 0xa1, 0x61, 0x88, 0x1f, 0x43, 0xbc, 0x42, 0x8f, 0x43, 0xf3,
  40392. 0x7e, 0x16, 0x96, 0xfa, 0x92, 0x70, 0xaf, 0x3c, 0x9f, 0x4b,
  40393. 0xd9, 0x60, 0xe9, 0xf6, 0x2e, 0x84, 0xda, 0x88, 0x31, 0x34,
  40394. 0xa6, 0x85, 0x10, 0x05, 0xef, 0x40, 0xa8, 0xa5, 0x4f, 0x92,
  40395. 0x59, 0xf7, 0xe0, 0xc4, 0x2b, 0x12, 0x17, 0x71, 0xbe, 0x8c,
  40396. 0x4a, 0x02, 0xfe, 0x12, 0xb6, 0x3b, 0x85, 0x75, 0x37, 0xf3,
  40397. 0x73, 0x2d, 0x9c, 0x00, 0x5d, 0x80, 0xad, 0x20, 0x2f, 0x5a,
  40398. 0x0b, 0x17, 0x7e, 0x67, 0x72, 0x24, 0x5a, 0xb9, 0xf3, 0xb1,
  40399. 0x33, 0xa4, 0x57, 0x1d, 0x49, 0x72, 0x2c, 0x7f, 0x47, 0x15,
  40400. 0x07, 0xe0, 0x45, 0x14, 0xdd, 0x77, 0x86, 0x6d, 0x03, 0xbe,
  40401. 0x57, 0xd0, 0xaa, 0x18, 0xa6, 0xdd, 0x94, 0x18, 0x3f, 0x8a,
  40402. 0xf3, 0xb5, 0xd7, 0x5a, 0xec, 0xc8, 0x79, 0x7f, 0x51, 0x61,
  40403. 0x3c, 0x9b, 0xb2, 0x9b, 0xf3, 0xb4, 0x35, 0xd1, 0x38, 0xbf,
  40404. 0x37, 0xce, 0x54, 0xd1, 0xf8, 0xb6, 0x45, 0xeb, 0x52, 0x0d,
  40405. 0x9a, 0x09, 0x58, 0x0d, 0x2c, 0x0b, 0xb1, 0xf2, 0x30, 0x3a,
  40406. 0x95, 0xc1, 0x13, 0x91, 0xd2, 0x9f, 0x8d, 0x8d, 0xd0, 0x38,
  40407. 0x3e, 0x4c, 0xae, 0x4a, 0x55, 0xa7, 0x42, 0x11, 0x83, 0xc4,
  40408. 0x70, 0xf0, 0x2b, 0x68, 0x9e, 0x07, 0xad, 0xb7, 0x83, 0xc6,
  40409. 0x53, 0x3c, 0xfb, 0x0a, 0x5d, 0x24, 0xdc, 0xe1, 0x55, 0x72,
  40410. 0xcf, 0xce, 0x3e, 0xc8, 0xd0, 0x57, 0x8a, 0x82, 0x5e, 0x78,
  40411. 0x2b, 0x80, 0xc5, 0xb9, 0x09, 0x46, 0xf8, 0x90, 0x39, 0x52,
  40412. 0xa9, 0xce, 0x3f, 0x3d, 0x41, 0x3b, 0x28, 0x45, 0xa3, 0xb3,
  40413. 0x21, 0xc2, 0xcd, 0x14, 0x49, 0x41, 0x6c, 0x38, 0xda, 0x1b,
  40414. 0x5f, 0x16, 0x49, 0xf9, 0x65, 0x00, 0x4e, 0xb4, 0x20, 0x55,
  40415. 0x70, 0xe8, 0x58, 0x1a, 0x18, 0xbf, 0x41, 0xef, 0x31, 0xb1,
  40416. 0xe7, 0x8d, 0x89, 0xc1, 0x48, 0xe8, 0xf5, 0x57, 0x35, 0xfa,
  40417. 0xc1, 0x79, 0xee, 0x2c, 0xe8, 0x7d, 0xb6, 0x03, 0xcc, 0x66,
  40418. 0x09, 0x6f, 0x52, 0x84, 0x0a, 0x34, 0x18, 0x2c, 0x01, 0x45,
  40419. 0x81, 0x00, 0xe5, 0x5e, 0x8d, 0xae, 0x1c, 0x96, 0x8b, 0x45,
  40420. 0x73, 0x00, 0x0a, 0xb5, 0xcf, 0x8d, 0x0e, 0x35, 0x5d, 0x1a,
  40421. 0x0e, 0xbf, 0x64, 0x9a, 0x52, 0x20, 0x48, 0xc6, 0xb9, 0x40,
  40422. 0xd3, 0x2c, 0x52, 0xca, 0x93, 0xcf, 0xbb, 0x94, 0x06, 0xf3,
  40423. 0x97, 0xee, 0xcc, 0x5d, 0xa3, 0xea, 0xf8, 0x5a, 0x39, 0x77,
  40424. 0x34, 0xd7, 0xf6, 0x4e, 0xbe, 0x8a, 0x07, 0x5f, 0x51, 0x53,
  40425. 0xc5, 0x1b, 0x8c, 0x47, 0x8f, 0x34, 0x0e, 0x60, 0x0a, 0x90,
  40426. 0xe2, 0xda, 0x7b, 0xef, 0xd6, 0xf5, 0x5d, 0xe5, 0x32, 0x37,
  40427. 0x75, 0x99, 0x81, 0x4a, 0x2a, 0x78, 0x71, 0xdc, 0xf4, 0xe5,
  40428. 0xca, 0xd8, 0x6b, 0x3b, 0x90, 0x68, 0x2e, 0x93, 0xc5, 0x10,
  40429. 0x42, 0x5d, 0x38, 0x90, 0x32, 0x46, 0xea, 0x87, 0xe0, 0xbc,
  40430. 0xb8, 0x9a, 0x18, 0x20, 0x68, 0x85, 0x6d, 0x9b, 0xc9, 0x8f,
  40431. 0x9b, 0xd2, 0xbe, 0x15, 0x12, 0x68, 0xd0, 0xb0, 0x16, 0x5f,
  40432. 0xe2, 0x69, 0x1d, 0x04, 0x00, 0xfc, 0x63, 0x33, 0xcd, 0x1f,
  40433. 0x89, 0xcd, 0x52, 0xff, 0xec, 0x19, 0x69, 0x74, 0xa3, 0xce,
  40434. 0x4d, 0xab, 0x93, 0xe4, 0xc6, 0x13, 0x56, 0x27, 0xc9, 0x25,
  40435. 0x5a, 0x01, 0xb2, 0x36, 0x8b, 0x61, 0xe5, 0x8b, 0x98, 0xac,
  40436. 0xe4, 0x2a, 0xb6, 0x40, 0x9f, 0x42, 0xe4, 0x1b, 0x52, 0xf7,
  40437. 0xfd, 0xd8, 0x30, 0x07, 0x33, 0xf9, 0x47, 0xcb, 0x3c, 0xad,
  40438. 0x12, 0xc1, 0xcc, 0x29, 0x62, 0x49, 0x04, 0x0c, 0x23, 0x97,
  40439. 0x5a, 0xa4, 0x84, 0x67, 0xde, 0x5a, 0xe5, 0x36, 0xd2, 0x88,
  40440. 0xf1, 0xd4, 0xeb, 0x13, 0x81, 0x54, 0x51, 0x11, 0xe3, 0xba,
  40441. 0xbc, 0xee, 0xdd, 0x6c, 0xcd, 0xe6, 0xb4, 0xa1, 0x8b, 0x0b,
  40442. 0x66, 0xfb, 0x8e, 0x50, 0xa0, 0xda, 0x69, 0x8d, 0xcc, 0x2d,
  40443. 0xe4, 0x2c, 0xc4, 0x37, 0xdf, 0x61, 0xc0, 0x03, 0xbd, 0x8b,
  40444. 0x28, 0xca, 0xd2, 0x8c, 0x1c, 0xf1, 0xa4, 0x26, 0x69, 0xe5,
  40445. 0xcf, 0x45, 0xdb, 0x5a, 0x47, 0x79, 0xed, 0x9f, 0xf7, 0xd2,
  40446. 0xdb, 0xba, 0x46, 0x53, 0x4f, 0xce, 0xa8, 0xbe, 0x8f, 0x4a,
  40447. 0xd6, 0xdf, 0x2e, 0x06, 0xe6, 0x4c, 0x9a, 0xc1, 0xb6, 0x49,
  40448. 0xed, 0xc4, 0xeb, 0xaa, 0xa4, 0x29, 0x6d, 0xd4, 0xcc, 0x8c,
  40449. 0xb6, 0x40, 0x11, 0x39, 0x69, 0xf7, 0x75, 0xcd, 0xb1, 0x99,
  40450. 0x46, 0x4e, 0xde, 0xcb, 0xf6, 0x9d, 0x32, 0xf3, 0xc9, 0x47,
  40451. 0x47, 0x7a, 0xcb, 0xfb, 0xa3, 0x0c, 0x3b, 0xdf, 0xb7, 0xde,
  40452. 0xec, 0x99, 0xde, 0xb0, 0x26, 0x04, 0x34, 0xae, 0x6b, 0xfc,
  40453. 0x99, 0xbc, 0xde, 0xd5, 0xbe, 0xe7, 0xeb, 0xf9, 0xe7, 0xa6,
  40454. 0x01, 0x9a, 0x0c, 0x5e, 0x66, 0xe6, 0x53, 0xe4, 0xd1, 0x58,
  40455. 0xac, 0xda, 0x69, 0x77, 0x7b, 0x68, 0xd6, 0x30, 0x2a, 0x9c,
  40456. 0x6b, 0xbe, 0x9f, 0x3d, 0x71, 0xd6, 0x54, 0xcd, 0x59, 0x4e,
  40457. 0x1f, 0xe3, 0x83, 0x4e, 0xd1, 0x8e, 0xaf, 0x97, 0xa8, 0xe5,
  40458. 0xb6, 0x59, 0x77, 0xa8, 0x02, 0x20, 0xe4, 0xeb, 0x44, 0x71,
  40459. 0xbc, 0x07, 0x14, 0x79, 0x4f, 0x0c, 0x27, 0x06, 0x39, 0xcf,
  40460. 0x7c, 0xef, 0x2b, 0x9b, 0x5e, 0xc4, 0x6d, 0x79, 0x13, 0x00,
  40461. 0x43, 0x6f, 0x51, 0x77, 0xb5, 0xc3, 0x72, 0xad, 0x13, 0xa9,
  40462. 0xe5, 0x9a, 0x5b, 0x1a, 0x99, 0x74, 0xc0, 0x7a, 0xf9, 0xc5,
  40463. 0xb0, 0x58, 0x35, 0x1c, 0xa5, 0x51, 0xdb, 0xa1, 0x14, 0xcd,
  40464. 0x26, 0x71, 0xb1, 0xe7, 0xaa, 0x14, 0xa7, 0x46, 0x93, 0xd3,
  40465. 0x5c, 0x8c, 0x1a, 0x91, 0x77, 0x46, 0x2e, 0x15, 0xaa, 0x9e,
  40466. 0xf7, 0x2b, 0x79, 0x41, 0x76, 0xf7, 0x22, 0x53, 0x7d, 0x51,
  40467. 0xdb, 0x98, 0x3d, 0x5b, 0x78, 0x5f, 0xc3, 0xc9, 0x29, 0xa3,
  40468. 0xff, 0x75, 0x82, 0x06, 0x9a, 0x16, 0x5e, 0xa4, 0x79, 0x0d,
  40469. 0xd1, 0x6d, 0x08, 0xff, 0x43, 0xef, 0x9c, 0xf3, 0x1b, 0x7a,
  40470. 0x3f, 0x34, 0xbe, 0x19, 0x15, 0x06, 0x33, 0xdb, 0xa5, 0x71,
  40471. 0xcb, 0x5f, 0x6b, 0x8d, 0xbd, 0x5b, 0x32, 0x91, 0xb2, 0x37,
  40472. 0x3d, 0xb4, 0x40, 0x9e, 0x02, 0x9b, 0xb7, 0x68, 0x20, 0x58,
  40473. 0x5c, 0xab, 0xcb, 0xc8, 0x23, 0x2d, 0x77, 0xcc, 0x0b, 0xf6,
  40474. 0x78, 0x6b, 0x80, 0x06, 0x91, 0xa9, 0xfd, 0x7e, 0xfa, 0x25,
  40475. 0x98, 0x9f, 0xcc, 0x79, 0x0a, 0x1a, 0x54, 0x83, 0xac, 0x64,
  40476. 0x16, 0x90, 0xe5, 0xd9, 0xa7, 0xd7, 0x1b, 0x86, 0x0d, 0xe6,
  40477. 0xe6, 0x22, 0x2b, 0x1f, 0x44, 0x49, 0x98, 0x9c, 0x51, 0x6f,
  40478. 0xcf, 0x58, 0x4a, 0xfa, 0xfa, 0x84, 0x12, 0xa5, 0x10, 0xf4,
  40479. 0xca, 0xf0, 0x98, 0x2b, 0xc9, 0x03, 0x71, 0x37, 0xe7, 0xdc,
  40480. 0xc2, 0xb1, 0x4e, 0x64, 0xde, 0x4f, 0x46, 0x0d, 0x6b, 0x25,
  40481. 0x88, 0x5d, 0xd6, 0xff, 0x23, 0x46, 0x57, 0x36, 0x14, 0x18,
  40482. 0xa7, 0xcb, 0xb8, 0xbd, 0xf0, 0xc5, 0x37, 0x36, 0xee, 0xe1,
  40483. 0xed, 0x9f, 0x4d, 0xd4, 0x39, 0xe5, 0x92, 0xcf, 0x95, 0x4d,
  40484. 0x66, 0x36, 0x5d, 0xd0, 0xcc, 0x07, 0xcf, 0x15, 0x5a, 0xce,
  40485. 0x14, 0xb8, 0xda, 0x0d, 0x3d, 0x1b, 0x45, 0xc5, 0x2e, 0x34,
  40486. 0x43, 0x25, 0x02, 0x3a, 0xcd, 0x14, 0x45, 0xfb, 0x3e, 0xf9,
  40487. 0x88, 0x5d, 0x0d, 0x29, 0x31, 0xb9, 0xa1, 0xe6, 0x31, 0x18,
  40488. 0x52, 0x46, 0x3f, 0x22, 0x4f, 0x9f, 0x7a, 0x65, 0x36, 0x88,
  40489. 0xa3, 0x1c, 0x3e, 0x6f, 0x50, 0x7a, 0x36, 0xbe, 0x56, 0x7e,
  40490. 0x50, 0xcb, 0x7a, 0x10, 0xa0, 0xec, 0xf6, 0x82, 0xd6, 0x30,
  40491. 0x1c, 0xe8, 0x4c, 0x50, 0xf9, 0x3e, 0xdb, 0xac, 0xbe, 0x4f,
  40492. 0x90, 0xb1, 0xd5, 0x1b, 0x12, 0x95, 0xfb, 0xe8, 0x08, 0x64,
  40493. 0x56, 0x7c, 0x96, 0xcc, 0x90, 0xb1, 0xbc, 0xa0, 0xf5, 0x32,
  40494. 0x69, 0xb3, 0x5f, 0x27, 0x0f, 0xbe, 0xc9, 0xbd, 0xeb, 0xfa,
  40495. 0x4b, 0x5c, 0xc5, 0x99, 0x9e, 0x5a, 0x04, 0xcc, 0xd0, 0x4d,
  40496. 0x29, 0xe8, 0x84, 0x55, 0x8c, 0xd7, 0xc4, 0x06, 0x13, 0x4d,
  40497. 0x92, 0xe5, 0x98, 0x9c, 0x4c, 0xc1, 0xf7, 0xaf, 0x7b, 0xd5,
  40498. 0x2b, 0x92, 0x68, 0x68, 0x19, 0x70, 0x4c, 0x9e, 0x46, 0xb8,
  40499. 0x34, 0xeb, 0x01, 0x47, 0xbe, 0x59, 0xab, 0x0b, 0x22, 0x25,
  40500. 0xe7, 0x56, 0xa8, 0xb4, 0x93, 0x3c, 0xd5, 0x98, 0x9f, 0x61,
  40501. 0x2e, 0xfa, 0xcb, 0x5f, 0x5b, 0xd8, 0x09, 0x83, 0xe9, 0x40,
  40502. 0xe9, 0x0e, 0x42, 0xdd, 0x17, 0xd7, 0x6e, 0x19, 0x8d, 0x95,
  40503. 0x0a, 0x93
  40504. };
  40505. #endif
  40506. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_sig[] = {
  40507. 0x20, 0xff, 0x12, 0xe1, 0x87, 0xf6, 0x11, 0x38, 0xff, 0x41, 0xd0, 0x8f,
  40508. 0xcd, 0x7e, 0xd1, 0xf6, 0x21, 0x17, 0xd0, 0x46, 0xe9, 0x86, 0x83, 0x1b,
  40509. 0xaf, 0xe5, 0x2b, 0x59, 0x21, 0xd1, 0x6b, 0xc9, 0xdb, 0x34, 0xdc, 0xba,
  40510. 0xfd, 0xd3, 0xf8, 0x71, 0x49, 0xd8, 0x31, 0xbc, 0x48, 0x83, 0x22, 0x7b,
  40511. 0xfd, 0x6a, 0x93, 0xa6, 0x39, 0x4c, 0xda, 0xdb, 0x15, 0xe7, 0x41, 0x14,
  40512. 0xb4, 0xb8, 0xfe, 0xb0, 0x1f, 0xf9, 0x0a, 0x2c, 0x0b, 0xc0, 0xac, 0x09,
  40513. 0x84, 0x69, 0x5e, 0x64, 0x8c, 0xa8, 0xee, 0xa1, 0x52, 0x22, 0xde, 0x0d,
  40514. 0xc7, 0x25, 0xef, 0xa8, 0xfd, 0x8c, 0xb9, 0x45, 0x4f, 0xa4, 0x9c, 0xbc,
  40515. 0x70, 0xf2, 0x88, 0xea, 0x79, 0x13, 0xb0, 0xfc, 0xe6, 0x41, 0x48, 0x1c,
  40516. 0x33, 0x48, 0xa2, 0x77, 0x75, 0x37, 0x9f, 0xc1, 0x86, 0x94, 0xcd, 0x69,
  40517. 0x98, 0x87, 0x47, 0x49, 0x75, 0x93, 0xf1, 0xa4, 0x2d, 0x8e, 0xa8, 0x7e,
  40518. 0x0f, 0x95, 0xf5, 0x3e, 0x5d, 0x31, 0x2d, 0xc9, 0x58, 0x1c, 0x42, 0xfd,
  40519. 0x79, 0x6a, 0x49, 0xa3, 0x84, 0xc5, 0x2e, 0x8d, 0x96, 0x9c, 0xc8, 0x05,
  40520. 0x93, 0xdb, 0x6d, 0xbf, 0x83, 0x34, 0xc2, 0x81, 0x47, 0x90, 0xc9, 0xa9,
  40521. 0x82, 0xbd, 0xe1, 0xc8, 0x89, 0xa2, 0x36, 0x47, 0xed, 0xfb, 0x47, 0x57,
  40522. 0x01, 0x1a, 0x75, 0x8c, 0x6b, 0x83, 0xcf, 0x56, 0xae, 0x52, 0x66, 0x8b,
  40523. 0xab, 0x7f, 0x0c, 0xec, 0xde, 0x5c, 0x13, 0xbe, 0xbd, 0x5b, 0x74, 0x28,
  40524. 0xb5, 0xd7, 0x68, 0xd5, 0xd2, 0xe9, 0x96, 0x3b, 0x55, 0xda, 0x3a, 0x93,
  40525. 0x3c, 0xd9, 0x9f, 0x53, 0x2a, 0x31, 0x84, 0x45, 0x3f, 0xee, 0x2b, 0xfc,
  40526. 0x92, 0xb0, 0x9c, 0xc6, 0x16, 0x16, 0x4f, 0x33, 0x41, 0x17, 0x58, 0xbe,
  40527. 0x5d, 0x57, 0x4b, 0x04, 0x82, 0xe3, 0xb3, 0x68, 0xdf, 0x7c, 0x93, 0xce,
  40528. 0x9d, 0xf6, 0x7e, 0x21, 0x3d, 0x28, 0x1c, 0xf0, 0x37, 0x46, 0xf2, 0xc2,
  40529. 0x73, 0x7c, 0xbe, 0x98, 0x0e, 0x09, 0x75, 0xa7, 0x21, 0x11, 0xa9, 0xd6,
  40530. 0xd1, 0x47, 0xac, 0xd0, 0x19, 0x48, 0x3b, 0x74, 0xc1, 0x3c, 0x37, 0x43,
  40531. 0x49, 0x12, 0x62, 0xee, 0xaf, 0x5c, 0x38, 0xf7, 0x8a, 0xce, 0xb3, 0x7a,
  40532. 0x05, 0x16, 0xd4, 0x71, 0x8b, 0xbe, 0x1a, 0xe0, 0x1e, 0xbc, 0x4b, 0x54,
  40533. 0x0f, 0xb5, 0x73, 0x2b, 0xb8, 0x3a, 0x75, 0xf0, 0x26, 0xcd, 0xf9, 0xca,
  40534. 0x32, 0xf9, 0x7e, 0x15, 0x38, 0x75, 0x9c, 0x4d, 0xbc, 0x11, 0xf8, 0xea,
  40535. 0x8e, 0xe8, 0x38, 0x17, 0xc5, 0x62, 0xf4, 0x34, 0xfb, 0xd6, 0xf5, 0x76,
  40536. 0xfc, 0xa3, 0xf3, 0x44, 0xf9, 0xab, 0x2e, 0x9a, 0x68, 0xcd, 0xa1, 0x29,
  40537. 0xff, 0xda, 0xe8, 0xb5, 0xb0, 0x20, 0x5d, 0x02, 0x01, 0x62, 0x26, 0x44,
  40538. 0x32, 0xc8, 0x94, 0xf8, 0xf1, 0xaa, 0xf9, 0xc2, 0x86, 0xcb, 0x55, 0x7f,
  40539. 0x8d, 0xb3, 0xf6, 0x63, 0xb1, 0xa4, 0x95, 0x57, 0xb8, 0x1d, 0xc3, 0x42,
  40540. 0xd2, 0x4b, 0x69, 0xcd, 0x7a, 0x10, 0x5b, 0x6a, 0x13, 0xd1, 0x02, 0x98,
  40541. 0x38, 0x87, 0x9b, 0x9a, 0x5a, 0x66, 0x73, 0xcb, 0x75, 0xd0, 0x7a, 0x4b,
  40542. 0xad, 0x23, 0x06, 0x1c, 0xc8, 0x6b, 0x0c, 0xa8, 0xfe, 0x7b, 0x8f, 0x65,
  40543. 0x50, 0xd7, 0xf7, 0x76, 0x88, 0x42, 0xe0, 0x5e, 0x18, 0x91, 0x8b, 0x99,
  40544. 0x37, 0x56, 0x08, 0x91, 0xe7, 0x01, 0xe7, 0x05, 0xd5, 0xed, 0x43, 0x25,
  40545. 0x71, 0x7e, 0x3e, 0xfc, 0xc4, 0xfd, 0xed, 0x8b, 0x85, 0x16, 0x8c, 0xe3,
  40546. 0x05, 0xee, 0x51, 0x02, 0xa4, 0x4b, 0xd8, 0x3c, 0xcf, 0x4d, 0x2f, 0x2d,
  40547. 0x68, 0x6e, 0xc1, 0xd5, 0xfa, 0x91, 0xfd, 0x6a, 0xe0, 0x64, 0x85, 0x35,
  40548. 0x9c, 0x75, 0xe6, 0x0d, 0xb8, 0xec, 0x97, 0x88, 0x62, 0x98, 0x78, 0x75,
  40549. 0xc7, 0x1e, 0x68, 0xa7, 0xb9, 0x7b, 0xab, 0x75, 0x7a, 0x72, 0x3c, 0x7b,
  40550. 0xab, 0x60, 0x03, 0xb7, 0x38, 0x13, 0xe4, 0x96, 0x6e, 0xcb, 0x95, 0xcc,
  40551. 0xdc, 0x6a, 0x47, 0x67, 0x77, 0xd7, 0x95, 0xc4, 0x87, 0x66, 0xc2, 0x7e,
  40552. 0x42, 0x90, 0x59, 0x4f, 0xd6, 0xf3, 0xf4, 0xa7, 0xd0, 0x29, 0xf9, 0x5d,
  40553. 0x4b, 0x06, 0x06, 0xf7, 0x6e, 0xb2, 0xab, 0xb0, 0x8e, 0x21, 0xa6, 0xff,
  40554. 0x5e, 0x7b, 0x47, 0xb6, 0x3a, 0xa6, 0x9e, 0x19, 0xf6, 0xdf, 0x9b, 0x3b,
  40555. 0x3d, 0x07, 0x37, 0xd1, 0x0b, 0xa8, 0xf3, 0x9c, 0x43, 0x89, 0xee, 0xba,
  40556. 0x03, 0xee, 0x38, 0x74, 0x13, 0x09, 0x8e, 0x47, 0x4e, 0xa9, 0x14, 0xf5,
  40557. 0xb0, 0x55, 0xe0, 0x03, 0xe5, 0xb9, 0x53, 0xef, 0x03, 0x15, 0x60, 0xb3,
  40558. 0x4a, 0x71, 0x31, 0x4b, 0xf1, 0xc8, 0xe4, 0x63, 0x9b, 0x8b, 0x78, 0x3c,
  40559. 0x1f, 0xac, 0x27, 0x20, 0xa8, 0x53, 0x7d, 0xdd, 0x72, 0xd3, 0x90, 0x8f,
  40560. 0x71, 0xa6, 0xa7, 0xeb, 0xb0, 0xeb, 0x42, 0x96, 0xa4, 0xc3, 0xba, 0xc6,
  40561. 0x3c, 0xe7, 0x7b, 0x15, 0x1e, 0xfa, 0x15, 0x23, 0x37, 0xf3, 0xc8, 0xb2,
  40562. 0xf9, 0x46, 0x04, 0xd1, 0x5e, 0x44, 0xd7, 0x8f, 0x70, 0xb1, 0x0a, 0xde,
  40563. 0x6a, 0xe3, 0xaf, 0x9e, 0x49, 0x55, 0x78, 0x79, 0x11, 0x22, 0x87, 0xa9,
  40564. 0x54, 0x7c, 0xb4, 0x83, 0xe1, 0x25, 0xcd, 0x89, 0xa6, 0x91, 0x21, 0x7b,
  40565. 0xbe, 0x3d, 0x2f, 0x46, 0xb5, 0x5b, 0x50, 0x1a, 0xc8, 0x8d, 0x32, 0xf3,
  40566. 0x62, 0x1f, 0x24, 0x64, 0xe8, 0xb6, 0x02, 0x4f, 0x1f, 0x52, 0x3c, 0x40,
  40567. 0xfc, 0x72, 0x38, 0xd4, 0xba, 0x40, 0x8e, 0xb7, 0xc0, 0x97, 0x06, 0x16,
  40568. 0xd5, 0xe3, 0x39, 0x45, 0xd7, 0x7c, 0x0e, 0xed, 0x6b, 0x19, 0x19, 0x0a,
  40569. 0x8e, 0xcb, 0x2b, 0xee, 0x4d, 0xa1, 0x5e, 0x84, 0x22, 0x66, 0xcd, 0x4f,
  40570. 0xb9, 0x1a, 0x25, 0x85, 0x02, 0xc0, 0x67, 0xc4, 0xd5, 0x1a, 0xcb, 0xbb,
  40571. 0xde, 0x4d, 0x3c, 0x3c, 0x62, 0x9f, 0x76, 0x8f, 0x15, 0x29, 0xa5, 0xbb,
  40572. 0x5a, 0x48, 0x38, 0x66, 0xfa, 0x56, 0x0a, 0x09, 0xbd, 0xdf, 0xdf, 0x4a,
  40573. 0xe7, 0x0e, 0xa6, 0xb1, 0xb5, 0x7c, 0xe1, 0xed, 0x8d, 0x63, 0x07, 0x42,
  40574. 0xf3, 0xf8, 0x15, 0x28, 0x7c, 0x09, 0xf5, 0x02, 0x69, 0x1b, 0x88, 0x1e,
  40575. 0x3d, 0xad, 0x5f, 0x46, 0xed, 0xab, 0x2b, 0x11, 0x96, 0x73, 0xa8, 0xe8,
  40576. 0xe6, 0x64, 0x7d, 0xae, 0x13, 0xa1, 0x7d, 0x54, 0xae, 0xc0, 0x82, 0xeb,
  40577. 0x2a, 0xd1, 0x76, 0xb7, 0x9f, 0xbd, 0x33, 0x8f, 0xe7, 0xe6, 0x79, 0x92,
  40578. 0xa6, 0xaf, 0x61, 0x91, 0x49, 0xbc, 0xd2, 0x3c, 0x6f, 0x8b, 0xbe, 0x8f,
  40579. 0x5f, 0x1f, 0x00, 0x2c, 0x2e, 0x2c, 0xa0, 0x14, 0xcf, 0x34, 0x42, 0x44,
  40580. 0x41, 0x11, 0xd7, 0x37, 0xd3, 0x99, 0x44, 0x36, 0x43, 0x03, 0xb9, 0x50,
  40581. 0x4f, 0xab, 0xfe, 0x48, 0xe2, 0x4b, 0xed, 0x51, 0x8b, 0xe0, 0x04, 0x3c,
  40582. 0x93, 0x28, 0x55, 0xc8, 0x5a, 0xb3, 0x52, 0x2c, 0x56, 0xbd, 0x43, 0xb9,
  40583. 0x4a, 0x6c, 0x4c, 0xcc, 0xda, 0xba, 0x9c, 0xe6, 0x3e, 0x50, 0x8b, 0x1a,
  40584. 0xe5, 0x83, 0xc1, 0x60, 0x55, 0xb2, 0x02, 0x16, 0x54, 0x33, 0x62, 0x69,
  40585. 0x7c, 0x7d, 0x94, 0xf2, 0xb0, 0x3a, 0x22, 0xf0, 0x21, 0x46, 0xd7, 0x94,
  40586. 0x53, 0xec, 0x63, 0x4c, 0x3e, 0xc3, 0x71, 0xd1, 0xb9, 0x2e, 0x16, 0xe8,
  40587. 0x17, 0x63, 0x7e, 0x0c, 0x83, 0x05, 0x72, 0xe6, 0x20, 0x60, 0x34, 0xae,
  40588. 0x0e, 0x54, 0xa0, 0x57, 0x75, 0x93, 0x2e, 0xb8, 0x6c, 0xec, 0xda, 0x44,
  40589. 0x1b, 0xac, 0xd6, 0x75, 0xc5, 0x79, 0x3c, 0xc2, 0xa6, 0xa2, 0x7f, 0x3a,
  40590. 0xb0, 0xec, 0xeb, 0xc1, 0xe6, 0xd6, 0xae, 0xac, 0x2e, 0x55, 0x30, 0x1c,
  40591. 0x81, 0xa4, 0x4c, 0x35, 0x0e, 0xd8, 0xa6, 0x4e, 0xea, 0x0e, 0xbf, 0x79,
  40592. 0xf7, 0xdf, 0x55, 0xfc, 0xf9, 0x24, 0xb0, 0xa6, 0xba, 0xc3, 0x72, 0x42,
  40593. 0x60, 0x06, 0x44, 0x03, 0xe3, 0x40, 0x3c, 0x2a, 0x13, 0xf7, 0xdf, 0x3d,
  40594. 0xb7, 0x0d, 0x86, 0x6c, 0xb0, 0x0f, 0x2e, 0x72, 0x91, 0x16, 0x4f, 0x5f,
  40595. 0xd0, 0x3e, 0x8c, 0x36, 0xed, 0xa8, 0x6f, 0xbc, 0x65, 0xb0, 0x65, 0x99,
  40596. 0x47, 0x50, 0xa5, 0x9c, 0xea, 0xee, 0x8a, 0x44, 0x70, 0xf5, 0x31, 0x1a,
  40597. 0xe9, 0x11, 0xc1, 0xce, 0xe0, 0x21, 0x52, 0x70, 0x89, 0xf7, 0xc3, 0x35,
  40598. 0xfa, 0x55, 0x5a, 0xc5, 0x10, 0x02, 0xc4, 0xc7, 0xf7, 0xe1, 0xaf, 0x49,
  40599. 0x48, 0x61, 0xe7, 0x0d, 0xa1, 0x2d, 0x7d, 0x03, 0x00, 0x38, 0xa7, 0xd5,
  40600. 0xd3, 0xbf, 0x95, 0x29, 0xed, 0xcc, 0x70, 0x3e, 0xbe, 0x95, 0x8a, 0xdf,
  40601. 0xaf, 0xbf, 0xec, 0xf8, 0x6a, 0x4f, 0x9e, 0x69, 0xee, 0x4e, 0x3d, 0x8b,
  40602. 0x58, 0xa0, 0x2e, 0xb5, 0x83, 0x6a, 0x0e, 0x04, 0xa4, 0xa9, 0x74, 0xcb,
  40603. 0x4f, 0xb0, 0x39, 0x37, 0x8f, 0xcf, 0xbf, 0x77, 0xe4, 0x1a, 0x74, 0xcf,
  40604. 0x0e, 0x0d, 0x2d, 0x6e, 0x1d, 0xba, 0xc1, 0xf5, 0x7c, 0x54, 0x6e, 0x92,
  40605. 0xec, 0x4b, 0x03, 0xc3, 0xa4, 0x44, 0xad, 0x3e, 0x4f, 0xa4, 0xd9, 0xe9,
  40606. 0x71, 0x3c, 0xe6, 0xb6, 0xbe, 0xe7, 0xfc, 0x72, 0x76, 0x86, 0x9a, 0x73,
  40607. 0xb1, 0xb3, 0xf3, 0x84, 0xb6, 0x2a, 0x40, 0x0b, 0x8c, 0xae, 0xb3, 0xc4,
  40608. 0xdc, 0xb5, 0x21, 0x85, 0x87, 0xdc, 0x19, 0x18, 0xd5, 0xba, 0xa4, 0x5e,
  40609. 0x88, 0x89, 0xa4, 0xf4, 0x88, 0x75, 0xc2, 0x7a, 0xb4, 0xee, 0x9d, 0x54,
  40610. 0x66, 0x97, 0x70, 0x08, 0x8f, 0x99, 0x84, 0x5d, 0x5e, 0xa7, 0x6f, 0x92,
  40611. 0xe8, 0xa3, 0x65, 0xfa, 0x0e, 0x87, 0xfb, 0x3c, 0xe9, 0x17, 0x2d, 0xc7,
  40612. 0x2d, 0x30, 0x8f, 0x41, 0x82, 0x68, 0x2b, 0xf1, 0x67, 0x8e, 0xf7, 0x05,
  40613. 0x78, 0xfa, 0xc3, 0x61, 0xba, 0x35, 0xe7, 0x2f, 0x19, 0xef, 0x71, 0x36,
  40614. 0xac, 0x5b, 0xf0, 0x45, 0x30, 0x70, 0xdc, 0xc7, 0xab, 0x7b, 0x62, 0x17,
  40615. 0x9d, 0xc4, 0x43, 0x6f, 0xfc, 0x02, 0x56, 0x5f, 0x65, 0xaa, 0x68, 0x3b,
  40616. 0x5c, 0xfa, 0x71, 0x28, 0x89, 0xe9, 0x28, 0x2f, 0x95, 0x4b, 0xfc, 0xe6,
  40617. 0xe7, 0xc8, 0x44, 0x28, 0x5c, 0x3c, 0x08, 0x5f, 0x9c, 0xbc, 0x41, 0x68,
  40618. 0x91, 0x98, 0x7a, 0x00, 0x63, 0xc9, 0x5c, 0x75, 0x8f, 0xcc, 0x33, 0x77,
  40619. 0x7b, 0xd0, 0x2d, 0xe8, 0xa2, 0x98, 0xa4, 0x1b, 0xfa, 0x09, 0x67, 0x7b,
  40620. 0x25, 0x96, 0x19, 0xf4, 0x77, 0x33, 0x20, 0x4f, 0x19, 0xf6, 0x9c, 0x6c,
  40621. 0x2e, 0xd9, 0x68, 0x95, 0xb0, 0xe2, 0x18, 0x06, 0xe5, 0x84, 0x8e, 0xf7,
  40622. 0xbf, 0x6c, 0x96, 0xa8, 0x9d, 0x37, 0xc7, 0x28, 0xa1, 0x3d, 0x90, 0x8c,
  40623. 0x40, 0x3d, 0xe2, 0x51, 0xfd, 0x55, 0x09, 0xf8, 0x83, 0x43, 0x44, 0x4d,
  40624. 0x1c, 0x8a, 0x8d, 0x36, 0x84, 0x64, 0xc4, 0xfa, 0x1d, 0x72, 0x04, 0x0b,
  40625. 0x1d, 0x49, 0x13, 0x88, 0x78, 0x5f, 0x07, 0x9b, 0xc8, 0x01, 0x9c, 0x3c,
  40626. 0xfc, 0xff, 0x0f, 0xd5, 0x13, 0xcd, 0x15, 0x98, 0xcc, 0xe6, 0x59, 0x1e,
  40627. 0x83, 0x38, 0x8f, 0x6c, 0x75, 0xbe, 0xdf, 0xe9, 0x1b, 0xc5, 0xb9, 0x6b,
  40628. 0xa4, 0x5a, 0x0c, 0xae, 0x98, 0x8d, 0x93, 0xfa, 0x76, 0x7f, 0x0d, 0x0b,
  40629. 0xe8, 0xa0, 0x3b, 0x9e, 0x5e, 0xc8, 0xa8, 0xcc, 0x02, 0xc9, 0x86, 0x9c,
  40630. 0x78, 0xaf, 0x6e, 0x6a, 0xf4, 0xfe, 0x49, 0xad, 0xc5, 0x93, 0xae, 0x62,
  40631. 0xbd, 0xe3, 0x3a, 0xa8, 0xf2, 0x60, 0xb5, 0x29, 0xde, 0x5f, 0x12, 0x02,
  40632. 0x2d, 0x43, 0x90, 0xf5, 0x9d, 0x9d, 0x97, 0x29, 0xfa, 0xdd, 0x60, 0x41,
  40633. 0x64, 0xb7, 0xa5, 0x03, 0x72, 0x10, 0x2b, 0xdd, 0x5b, 0x60, 0xe6, 0xf0,
  40634. 0xe1, 0xd7, 0xa5, 0x97, 0xec, 0xb4, 0x9a, 0x4c, 0x3e, 0x16, 0xa2, 0x82,
  40635. 0xb3, 0xc3, 0x3f, 0x3e, 0x5d, 0x32, 0xac, 0x5a, 0x40, 0xb4, 0x00, 0xfa,
  40636. 0xd9, 0x47, 0xe8, 0x77, 0xa8, 0x96, 0x5c, 0x60, 0x04, 0x9c, 0x5c, 0xdf,
  40637. 0x24, 0x3b, 0xa7, 0x4a, 0x58, 0x25, 0x12, 0x9a, 0xa8, 0x7b, 0x3e, 0x14,
  40638. 0xc8, 0x06, 0x79, 0x23, 0xea, 0x91, 0x7f, 0xe1, 0x78, 0x41, 0x6c, 0xdb,
  40639. 0x8c, 0xeb, 0x66, 0x35, 0x87, 0x87, 0x81, 0x65, 0x2c, 0xef, 0x3a, 0x6e,
  40640. 0xae, 0xb3, 0x6c, 0xe9, 0x86, 0x50, 0x6d, 0x89, 0xd6, 0x27, 0x0a, 0xdb,
  40641. 0xf8, 0xd4, 0xb8, 0x85, 0x8e, 0x37, 0xa6, 0x56, 0xf7, 0x58, 0x18, 0x4c,
  40642. 0x44, 0xcf, 0xeb, 0xc4, 0x79, 0x19, 0xfc, 0x2e, 0x53, 0x18, 0x0e, 0x7b,
  40643. 0x51, 0x86, 0xf3, 0x59, 0x13, 0xb2, 0xaf, 0xd3, 0xee, 0xf4, 0xd5, 0xbf,
  40644. 0x2c, 0xb8, 0x6d, 0x71, 0x74, 0x7c, 0x67, 0x54, 0xa7, 0x4b, 0x03, 0xa9,
  40645. 0x1b, 0x62, 0x95, 0x9f, 0xc3, 0xf0, 0x71, 0x39, 0x2d, 0x26, 0xaf, 0xaf,
  40646. 0xa7, 0xa5, 0x58, 0xf8, 0xf8, 0x8a, 0xe0, 0x62, 0x90, 0x3f, 0x72, 0x9d,
  40647. 0x21, 0x82, 0x76, 0x3e, 0x4c, 0x5d, 0xe0, 0xb5, 0x67, 0x23, 0xe3, 0x13,
  40648. 0x1a, 0x29, 0xa3, 0xda, 0xa4, 0xb4, 0x5c, 0x1d, 0x47, 0xdf, 0xdf, 0xc9,
  40649. 0x93, 0x6c, 0xb2, 0xb5, 0x22, 0xb3, 0x47, 0x2b, 0xcf, 0xf0, 0x36, 0x87,
  40650. 0x51, 0x3c, 0x79, 0x41, 0x70, 0xbd, 0xea, 0x70, 0xa2, 0x29, 0x90, 0x55,
  40651. 0x30, 0x6f, 0x3e, 0x50, 0xc8, 0x38, 0xd6, 0xfa, 0x6f, 0xe3, 0x39, 0x67,
  40652. 0x88, 0x52, 0x1f, 0xd3, 0x52, 0xbf, 0x3e, 0x7b, 0x2a, 0xe5, 0x1e, 0xcd,
  40653. 0xf9, 0xf1, 0x91, 0x1d, 0x04, 0x61, 0x25, 0xbb, 0xe1, 0x33, 0xe3, 0x66,
  40654. 0x46, 0xed, 0x06, 0x8d, 0xc3, 0x4f, 0x20, 0xc6, 0x24, 0xa7, 0xb5, 0x49,
  40655. 0x3b, 0xc7, 0xe6, 0xa0, 0x77, 0x58, 0xd9, 0x70, 0xb1, 0xf5, 0xec, 0x94,
  40656. 0x19, 0xf3, 0x5b, 0x0f, 0x9a, 0xe4, 0xad, 0x37, 0x81, 0xaf, 0x68, 0x7b,
  40657. 0xe5, 0x67, 0xb5, 0xae, 0x7f, 0x2d, 0x64, 0x78, 0x68, 0x5a, 0xd1, 0x8f,
  40658. 0x1c, 0xc0, 0xc3, 0x5b, 0x21, 0x77, 0xe4, 0xa8, 0x5d, 0x05, 0x50, 0xc1,
  40659. 0x92, 0xee, 0x36, 0x2d, 0xd2, 0xff, 0xee, 0xc2, 0x11, 0x99, 0xee, 0xd7,
  40660. 0x48, 0xfb, 0x6a, 0xa3, 0xc9, 0xb7, 0x0c, 0xc1, 0xe5, 0x12, 0xbf, 0x6f,
  40661. 0x58, 0x66, 0x35, 0x34, 0x26, 0xaa, 0xbe, 0xc3, 0x33, 0x86, 0xfd, 0xc0,
  40662. 0x1c, 0xa5, 0xe4, 0x1e, 0x91, 0xc4, 0x55, 0x4e, 0xf1, 0xcb, 0xd2, 0x0b,
  40663. 0xe8, 0x0d, 0x89, 0x6a, 0x00, 0xbd, 0x7b, 0xf5, 0x3d, 0x1a, 0x4a, 0x48,
  40664. 0xfc, 0xf0, 0x5b, 0xcd, 0xdb, 0xb2, 0xa0, 0x27, 0x4b, 0x8f, 0xf7, 0x87,
  40665. 0x78, 0x13, 0xdb, 0x3f, 0xfb, 0x0b, 0xda, 0x22, 0xb3, 0x2b, 0x3a, 0x38,
  40666. 0xd2, 0x29, 0x73, 0x77, 0xb8, 0xd6, 0xec, 0xab, 0xb4, 0xfe, 0xbe, 0xbb,
  40667. 0x6e, 0xe2, 0xc8, 0x45, 0x7b, 0x0d, 0x36, 0x28, 0x0f, 0x45, 0x72, 0xea,
  40668. 0x6d, 0x38, 0x02, 0x5e, 0x48, 0x89, 0x12, 0x24, 0x1b, 0x33, 0x0f, 0xe9,
  40669. 0xf4, 0xce, 0xf8, 0x27, 0x16, 0x37, 0x29, 0xae, 0xe8, 0x22, 0x03, 0x31,
  40670. 0xa9, 0xa0, 0x73, 0x0c, 0x40, 0xe4, 0xfc, 0x6b, 0xe2, 0x1c, 0x8d, 0x7c,
  40671. 0x40, 0x82, 0x72, 0x28, 0xd0, 0x7d, 0xe5, 0xef, 0x05, 0x14, 0x80, 0x28,
  40672. 0x11, 0x32, 0x0d, 0x63, 0x8a, 0xc3, 0x7c, 0xfe, 0xf5, 0x06, 0x0e, 0xb0,
  40673. 0x78, 0x5c, 0x3a, 0xb6, 0x54, 0x37, 0x46, 0xa7, 0x43, 0x4f, 0x05, 0xec,
  40674. 0xe4, 0x9f, 0xd8, 0x55, 0x1f, 0x70, 0xb3, 0xe6, 0xbc, 0x46, 0x34, 0x9e,
  40675. 0xfc, 0xa4, 0x57, 0x8f, 0x0f, 0x25, 0x6f, 0x9f, 0xb3, 0x80, 0x21, 0x0b,
  40676. 0xa1, 0xca, 0x59, 0xcd, 0x37, 0xf7, 0xc9, 0xcb, 0xbe, 0x91, 0xad, 0x07,
  40677. 0x4f, 0xc7, 0x4e, 0x04, 0xbd, 0x38, 0x8b, 0x63, 0xb5, 0x51, 0xac, 0xc8,
  40678. 0x83, 0x3a, 0xa7, 0xe1, 0x77, 0xbc, 0xa4, 0x0c, 0x6c, 0x50, 0xeb, 0x46,
  40679. 0xe1, 0x45, 0x9a, 0x7b, 0x01, 0xca, 0x54, 0xf0, 0x0f, 0xa0, 0x1f, 0x43,
  40680. 0x9a, 0x19, 0x70, 0x2e, 0x70, 0x5a, 0xcf, 0x3b, 0x1b, 0x41, 0xfd, 0xd3,
  40681. 0x9a, 0xa2, 0x36, 0x14, 0xf0, 0xdd, 0xb0, 0x12, 0x6d, 0xcf, 0x55, 0x3f,
  40682. 0xef, 0x0a, 0xc1, 0x80, 0xa9, 0x68, 0xc3, 0x98, 0x03, 0x46, 0x34, 0xce,
  40683. 0x91, 0xb2, 0x7a, 0x94, 0xd2, 0xe7, 0xb9, 0x9c, 0x56, 0xb8, 0xf8, 0xd6,
  40684. 0xff, 0xbf, 0x8b, 0x39, 0x45, 0x04, 0x45, 0xc9, 0xa2, 0xe2, 0xbb, 0x50,
  40685. 0x68, 0x13, 0x32, 0x1e, 0x09, 0x51, 0xb7, 0xb9, 0xcf, 0x5f, 0xcc, 0x54,
  40686. 0xd2, 0xf3, 0xc1, 0x9d, 0xa0, 0x8d, 0x22, 0xc8, 0x7e, 0x1b, 0xc6, 0x14,
  40687. 0xde, 0x5f, 0x52, 0xb4, 0x69, 0x71, 0xca, 0x58, 0x1d, 0x1e, 0x89, 0xcb,
  40688. 0x56, 0x78, 0x7a, 0x85, 0xee, 0xfd, 0xf6, 0x7e, 0xbe, 0x49, 0x9b, 0xb1,
  40689. 0x05, 0x95, 0x12, 0xe9, 0x63, 0xbd, 0x61, 0x9a, 0x26, 0xf9, 0x0b, 0x9f,
  40690. 0x23, 0x0a, 0x59, 0x55, 0x93, 0xd3, 0x2d, 0xca, 0x66, 0x45, 0x03, 0xb7,
  40691. 0xf0, 0x88, 0x9e, 0xc1, 0x11, 0xbb, 0x62, 0x2c, 0x6f, 0xac, 0x3e, 0x87,
  40692. 0xd7, 0xe6, 0x4a, 0x44, 0x83, 0x04, 0x5d, 0x5d, 0xbc, 0x3c, 0xce, 0x83,
  40693. 0x2b, 0x11, 0x42, 0x02, 0x73, 0x1c, 0x24, 0x90, 0xd9, 0x1a, 0x7d, 0x96,
  40694. 0x82, 0x33, 0x75, 0x1e, 0x59, 0xea, 0xa7, 0x99, 0xe1, 0x5b, 0xdc, 0xe4,
  40695. 0x07, 0xc5, 0x48, 0x07, 0xb4, 0xbc, 0x80, 0x0e, 0xbd, 0x63, 0x6e, 0x66,
  40696. 0xf1, 0x12, 0xb6, 0x67, 0xe0, 0x14, 0x74, 0x9f, 0xbb, 0xb3, 0xb8, 0x16,
  40697. 0xd0, 0x25, 0xe9, 0x21, 0x80, 0x1a, 0x32, 0xb0, 0x58, 0x9a, 0x62, 0x17,
  40698. 0x18, 0x9d, 0x64, 0x2d, 0x47, 0x89, 0x82, 0x3b, 0x8c, 0x5d, 0x60, 0xc4,
  40699. 0x54, 0x69, 0xaa, 0xb4, 0x6a, 0x1d, 0x16, 0xb0, 0xe2, 0x5d, 0x7d, 0xeb,
  40700. 0xb9, 0x80, 0x37, 0xcd, 0x5b, 0xf0, 0xa1, 0xa8, 0x39, 0xb2, 0xd6, 0x3a,
  40701. 0xc8, 0xcd, 0xca, 0xaf, 0xcb, 0x3b, 0x54, 0xc2, 0x67, 0x49, 0xf3, 0xf1,
  40702. 0x11, 0x4d, 0x53, 0x7c, 0x46, 0x8d, 0x22, 0xf6, 0x9a, 0x0d, 0x9e, 0xda,
  40703. 0x37, 0xc6, 0x06, 0x00, 0xca, 0xb6, 0xb6, 0x99, 0xc5, 0xb6, 0x81, 0x7e,
  40704. 0x87, 0x62, 0xcf, 0x07, 0x76, 0xc1, 0x5f, 0xfe, 0x86, 0xfc, 0x5b, 0xa0,
  40705. 0xac, 0xca, 0xcb, 0x7d, 0xf5, 0x5a, 0xc2, 0x5e, 0x41, 0x48, 0x35, 0xc4,
  40706. 0x71, 0x9d, 0xc4, 0x0a, 0x79, 0x6f, 0xe3, 0x6d, 0x47, 0xd4, 0xaa, 0xfd,
  40707. 0x97, 0xe7, 0xb0, 0x7e, 0x61, 0xf1, 0x7d, 0x7e, 0xf8, 0x78, 0x4c, 0x2e,
  40708. 0x65, 0x51, 0xeb, 0x99, 0xd0, 0x3e, 0x24, 0x4c, 0xe0, 0x40, 0x7e, 0x2d,
  40709. 0xf7, 0x00, 0x9d, 0x50, 0x87, 0xce, 0x1f, 0x9a, 0xd2, 0x76, 0x00, 0x09,
  40710. 0xeb, 0x10, 0x1b, 0x4c, 0xf1, 0x43, 0x0e, 0x35, 0xbb, 0x23, 0x2e, 0x26,
  40711. 0x3d, 0x66, 0xa3, 0x0f, 0xf6, 0x10, 0x8b, 0x67, 0xce, 0x66, 0xfd, 0xb5,
  40712. 0x07, 0xdc, 0x04, 0x69, 0xad, 0xe0, 0x4d, 0xdf, 0xdb, 0x2f, 0x87, 0xf7,
  40713. 0xde, 0xc3, 0x77, 0x89, 0x71, 0xfd, 0x70, 0x38, 0xed, 0xe6, 0x27, 0xb1,
  40714. 0xbd, 0x94, 0x5f, 0x39, 0x20, 0x72, 0x59, 0xc4, 0x39, 0xd0, 0x20, 0x5d,
  40715. 0xe2, 0xe7, 0xe0, 0x00, 0x61, 0xc7, 0x65, 0xbd, 0xef, 0x05, 0xb3, 0xc7,
  40716. 0x7e, 0xae, 0xc5, 0x83, 0x7f, 0xc1, 0x32, 0x4e, 0x2a, 0x17, 0x64, 0x4e,
  40717. 0x2a, 0x9a, 0x2d, 0x26, 0x99, 0xa2, 0xd7, 0x37, 0x3a, 0x10, 0x6a, 0x89,
  40718. 0x72, 0x43, 0x0e, 0x3a, 0x03, 0x4c, 0xf9, 0xfe, 0xe8, 0xfc, 0x87, 0x71,
  40719. 0x37, 0x71, 0x5a, 0x05, 0xbc, 0x4e, 0x20, 0x4c, 0xd7, 0xf9, 0x8d, 0x4e,
  40720. 0xb8, 0xb8, 0x56, 0x07, 0xc8, 0x6e, 0x34, 0x6d, 0x45, 0x83, 0x34, 0xf0,
  40721. 0x77, 0xfb, 0x18, 0xec, 0x72, 0xf6, 0x4c, 0xfb, 0xba, 0x84, 0xe9, 0x89,
  40722. 0x3d, 0xfd, 0xb7, 0x0d, 0x70, 0xae, 0xa4, 0x48, 0x6b, 0x39, 0xf8, 0x62,
  40723. 0xc0, 0x7f, 0x0c, 0xf2, 0xa3, 0xfa, 0x7a, 0x64, 0x83, 0x57, 0x7d, 0x4c,
  40724. 0x04, 0x96, 0xd7, 0x9d, 0x10, 0x8b, 0x34, 0x48, 0x17, 0xff, 0x74, 0x5c,
  40725. 0x9c, 0xbe, 0xeb, 0xe5, 0x52, 0x94, 0x6a, 0x34, 0x6f, 0xf7, 0x95, 0x32,
  40726. 0x38, 0x5a, 0x9b, 0x08, 0xf6, 0xda, 0x8c, 0x0f, 0x9c, 0x5d, 0x04, 0x45,
  40727. 0xd4, 0xe9, 0xa4, 0x7a, 0xc4, 0xfd, 0x70, 0xfe, 0xa1, 0x3d, 0x21, 0xa0,
  40728. 0x01, 0xe5, 0x21, 0xca, 0xa7, 0xd9, 0xf1, 0x9f, 0x45, 0xe1, 0xe8, 0x2d,
  40729. 0x27, 0xe6, 0x87, 0xc8, 0x0d, 0xad, 0x13, 0xdb, 0xfe, 0x2f, 0xaa, 0x2b,
  40730. 0xdc, 0xa6, 0x1a, 0xc9, 0x19, 0x78, 0x1a, 0x1f, 0x10, 0xcf, 0x31, 0xe1,
  40731. 0x06, 0x28, 0x66, 0xb3, 0xa7, 0xa2, 0xa6, 0xf1, 0x3b, 0x2d, 0xd3, 0x81,
  40732. 0xaf, 0x6f, 0xc9, 0x88, 0x76, 0xe9, 0x83, 0x6c, 0x52, 0xb9, 0x70, 0x51,
  40733. 0x87, 0x6b, 0x8b, 0xbd, 0x5b, 0x9c, 0xa9, 0xf3, 0xcb, 0x55, 0xd1, 0x76,
  40734. 0x40, 0xe1, 0x90, 0xb9, 0x4c, 0xbd, 0xab, 0x1d, 0xa0, 0x5b, 0x5b, 0x34,
  40735. 0x14, 0x2f, 0x87, 0x8f, 0x63, 0xa0, 0x2d, 0x29, 0x4e, 0x50, 0x4b, 0x18,
  40736. 0x5f, 0x86, 0xac, 0x1b, 0x93, 0xe9, 0x59, 0x38, 0xa1, 0x2a, 0x36, 0x21,
  40737. 0xb2, 0xa4, 0xc0, 0x79, 0xc1, 0x60, 0xfc, 0x0f, 0xbf, 0x99, 0x04, 0x9d,
  40738. 0x4b, 0x17, 0x60, 0x5b, 0xcd, 0x78, 0x03, 0xd7, 0x7c, 0x4b, 0x9b, 0x17,
  40739. 0x58, 0x24, 0x60, 0xb8, 0x08, 0x92, 0x48, 0x4f, 0x66, 0x42, 0x9a, 0x98,
  40740. 0x2a, 0x99, 0x9a, 0x8f, 0xdd, 0xd7, 0x09, 0xf3, 0x22, 0x66, 0x62, 0xef,
  40741. 0xe5, 0x64, 0xd3, 0xdf, 0x31, 0xaa, 0x84, 0x4c, 0xa5, 0x3f, 0x4e, 0x27,
  40742. 0x48, 0x37, 0x96, 0x63, 0xbf, 0x8d, 0xe1, 0xf0, 0xd1, 0xef, 0x95, 0x1a,
  40743. 0xe6, 0xf4, 0x02, 0x61, 0xbf, 0xe3, 0xbc, 0x8b, 0x3d, 0x0b, 0x77, 0x91,
  40744. 0xc0, 0x5d, 0xfb, 0xe6, 0x7e, 0xab, 0x5e, 0xc5, 0x1c, 0x5b, 0x16, 0xfd,
  40745. 0x88, 0xa4, 0x78, 0x4c, 0x06, 0x77, 0xc3, 0x6e, 0x84, 0x0c, 0xda, 0xbf,
  40746. 0xf3, 0x8e, 0xd3, 0x61, 0x65, 0xac, 0xf2, 0x18, 0x70, 0x68, 0x84, 0x6f,
  40747. 0x9f, 0x3a, 0x94, 0x81, 0xa6, 0xc7, 0xc3, 0x92, 0xee, 0x4b, 0x20, 0x15,
  40748. 0x4e, 0x03, 0x76, 0x51, 0x5b, 0x4e, 0xe1, 0x5c, 0x51, 0x5e, 0x1b, 0x9c,
  40749. 0x30, 0x25, 0x79, 0xdd, 0x70, 0x12, 0xec, 0xdc, 0x45, 0x95, 0x45, 0x43,
  40750. 0xcd, 0xbb, 0xae, 0xa0, 0x0d, 0x43, 0xb4, 0xc9, 0x8c, 0x62, 0xfd, 0x7b,
  40751. 0xed, 0x50, 0x78, 0xb7, 0xa6, 0x94, 0xcb, 0x98, 0xb0, 0xbe, 0x09, 0xd9,
  40752. 0x0c, 0xb2, 0xc4, 0x8b, 0x96, 0x93, 0xd9, 0x26, 0xc6, 0x6d, 0x26, 0x93,
  40753. 0x32, 0x4e, 0x86, 0x72, 0x74, 0x92, 0x00, 0x72, 0x0b, 0x20, 0xa3, 0x2b,
  40754. 0x94, 0xe6, 0x10, 0x56, 0x5a, 0x41, 0x71, 0x92, 0x08, 0xce, 0x6c, 0xc4,
  40755. 0x1d, 0x9e, 0x71, 0x82, 0x64, 0x23, 0xe5, 0x15, 0xef, 0x4a, 0x7c, 0x4d,
  40756. 0xe3, 0x92, 0xbc, 0xa3, 0xa2, 0x29, 0xb7, 0x46, 0xfa, 0x8f, 0x9f, 0xc2,
  40757. 0x5d, 0xe4, 0xc0, 0x9c, 0x3f, 0x40, 0x17, 0xae, 0x44, 0xf3, 0x28, 0x10,
  40758. 0x29, 0x24, 0xa9, 0x1c, 0x9e, 0xd2, 0x55, 0x4c, 0xee, 0x45, 0xfe, 0x4a,
  40759. 0x45, 0x12, 0xf5, 0xde, 0xc7, 0x64, 0x15, 0xc3, 0x4a, 0x77, 0x63, 0x05,
  40760. 0x8d, 0xa6, 0x31, 0xa0, 0xad, 0x64, 0xaf, 0x3c, 0x69, 0x2c, 0x25, 0x78,
  40761. 0xae, 0xa0, 0x88, 0x96, 0x8a, 0xc2, 0x9b, 0x8d, 0xee, 0x6f, 0x2e, 0x79,
  40762. 0x1f, 0xec, 0x32, 0x35, 0x75, 0x83, 0x19, 0x8b, 0xda, 0xca, 0xd0, 0xaf,
  40763. 0x6a, 0x6c, 0x42, 0xe8, 0x81, 0xb5, 0x69, 0x31, 0x0b, 0x7d, 0xbc, 0xd8,
  40764. 0xd2, 0xb7, 0x7a, 0x8f, 0xfa, 0xcf, 0x91, 0x07, 0x1f, 0xda, 0xa9, 0x1f,
  40765. 0xb7, 0x2d, 0xff, 0x50, 0x15, 0x2a, 0xef, 0x8c, 0xa1, 0xe3, 0x7f, 0x08,
  40766. 0x95, 0xf2, 0x99, 0x83, 0x1f, 0x97, 0x71, 0x3e, 0x35, 0x3c, 0x8c, 0xe7,
  40767. 0x08, 0xd8, 0xa6, 0x1f, 0x0c, 0xa6, 0x52, 0xdc, 0x73, 0xa0, 0xfc, 0xd2,
  40768. 0x73, 0xe9, 0x27, 0x9d, 0xfd, 0x7a, 0x4a, 0x29, 0xd3, 0x12, 0x26, 0x13,
  40769. 0x0f, 0xce, 0xea, 0x56, 0x99, 0x61, 0x78, 0x47, 0x2c, 0xa0, 0x16, 0xa0,
  40770. 0xe2, 0x64, 0x97, 0x57, 0x31, 0xf0, 0x32, 0x5b, 0x44, 0x93, 0x76, 0x8b,
  40771. 0x59, 0x63, 0x5c, 0x5b, 0x0f, 0xe1, 0xe7, 0x74, 0x98, 0x11, 0x2d, 0x90,
  40772. 0xe4, 0xde, 0xd4, 0x3a, 0xc2, 0xfd, 0x24, 0xe3, 0x1f, 0x7a, 0xf4, 0x40,
  40773. 0xbb, 0x51, 0x92, 0x8f, 0x68, 0x9c, 0x51, 0xab, 0xdc, 0xf6, 0x1e, 0x96,
  40774. 0xca, 0x56, 0x5c, 0x92, 0xca, 0xb2, 0x1b, 0x2e, 0x6d, 0x20, 0x28, 0xb3,
  40775. 0x0a, 0x8e, 0xfd, 0xa9, 0xa2, 0x38, 0x74, 0x60, 0x37, 0xa6, 0x96, 0x02,
  40776. 0x20, 0x8a, 0x9a, 0x2b, 0x8c, 0xb9, 0x6d, 0xec, 0xff, 0xbf, 0x88, 0xbd,
  40777. 0x6c, 0xb4, 0x10, 0xbd, 0xfa, 0x5a, 0xeb, 0xb2, 0x6b, 0x74, 0x13, 0x2d,
  40778. 0xa5, 0xdb, 0x60, 0x93, 0xc6, 0xed, 0x39, 0x4f, 0xc5, 0x63, 0xe1, 0x9e,
  40779. 0x57, 0x1f, 0xe7, 0x47, 0xa4, 0xfb, 0x7f, 0xfa, 0x3a, 0x46, 0x50, 0x3a,
  40780. 0xd8, 0xd3, 0x83, 0xf5, 0xe6, 0x5e, 0xf8, 0x09, 0x0d, 0xfa, 0x33, 0xe1,
  40781. 0x50, 0xe4, 0x36, 0x3e, 0x0a, 0x5d, 0xe6, 0xf8, 0x2e, 0x17, 0x87, 0x8f,
  40782. 0xe1, 0x8c, 0x82, 0x73, 0xbd, 0xdd, 0x3b, 0x77, 0x47, 0x9f, 0x42, 0xd7,
  40783. 0xf4, 0x2d, 0x6c, 0xef, 0xcc, 0x22, 0x15, 0x3c, 0xe9, 0x26, 0xea, 0xbc,
  40784. 0xee, 0x09, 0xd3, 0xea, 0x84, 0x0f, 0x46, 0xa8, 0xe0, 0xda, 0xc5, 0x57,
  40785. 0x02, 0x54, 0xb6, 0x88, 0x2b, 0x37, 0xe5, 0x96, 0xc5, 0x33, 0xb7, 0x45,
  40786. 0x5d, 0xb7, 0xc7, 0xfd, 0xa0, 0xfa, 0x85, 0x1b, 0x2f, 0xe1, 0xec, 0x89,
  40787. 0xc6, 0xb2, 0x51, 0x71, 0xcb, 0x08, 0x82, 0x3e, 0xc9, 0xed, 0x80, 0x9d,
  40788. 0x37, 0x31, 0x9d, 0x15, 0xde, 0x24, 0x6f, 0xbd, 0x0e, 0x73, 0xa2, 0xb8,
  40789. 0x7e, 0x29, 0x7e, 0x96, 0xe4, 0xbb, 0xd6, 0x23, 0x17, 0xff, 0x33, 0x97,
  40790. 0x9c, 0x87, 0xe0, 0xe5, 0x0f, 0xb9, 0xb6, 0x31, 0x33, 0xad, 0xf8, 0xd8,
  40791. 0xdb, 0xa0, 0x71, 0x13, 0xe4, 0x1c, 0xce, 0xd0, 0x7e, 0x65, 0x7b, 0xa0,
  40792. 0x38, 0x17, 0x53, 0x4f, 0x71, 0x75, 0x6d, 0x02, 0x61, 0xc4, 0x52, 0xf8,
  40793. 0xe4, 0x2e, 0xbc, 0x52, 0xc1, 0xb1, 0x7e, 0x83, 0x0a, 0xa1, 0xd1, 0xcd,
  40794. 0x2f, 0xa0, 0x30, 0xfd, 0x41, 0x86, 0x7f, 0x26, 0xd1, 0xe7, 0xfc, 0xd7,
  40795. 0xc7, 0x37, 0xe5, 0x11, 0xa6, 0xc0, 0x9a, 0x75, 0x18, 0x04, 0x36, 0xca,
  40796. 0x8e, 0x26, 0x7d, 0xcf, 0xa2, 0x6a, 0x94, 0x9b, 0xc4, 0xf7, 0xc7, 0xeb,
  40797. 0x51, 0x13, 0xa3, 0x6f, 0x8c, 0x80, 0x5f, 0xae, 0xf0, 0x18, 0xa0, 0x88,
  40798. 0xe0, 0x8d, 0xb7, 0x80, 0x4e, 0x8c, 0xec, 0xc8, 0x7b, 0xeb, 0xac, 0x29,
  40799. 0xb7, 0x4a, 0x0f, 0x33, 0xdd, 0x9d, 0x89, 0x0a, 0x10, 0xb0, 0xce, 0x74,
  40800. 0x59, 0xa2, 0x62, 0x91, 0xc9, 0xac, 0x56, 0xcd, 0x69, 0xd3, 0x01, 0x6d,
  40801. 0x51, 0xe7, 0x04, 0xc3, 0xfb, 0xe9, 0x79, 0x1b, 0x72, 0x72, 0x1a, 0x90,
  40802. 0x0a, 0x20, 0x55, 0x85, 0xc1, 0x8b, 0xeb, 0x1e, 0x9f, 0x9f, 0x4a, 0x81,
  40803. 0x47, 0x97, 0x96, 0xbc, 0xc2, 0xe4, 0xc2, 0xfe, 0xa0, 0x20, 0xda, 0x70,
  40804. 0x0c, 0x2b, 0xe2, 0xd4, 0xc8, 0xcb, 0x46, 0x00, 0xb6, 0x7c, 0xfb, 0xbd,
  40805. 0x56, 0x94, 0x3d, 0x7f, 0x64, 0xf7, 0x88, 0xb5, 0xa7, 0xfe, 0xbe, 0x64,
  40806. 0x8a, 0xe4, 0x00, 0x08, 0x82, 0x5b, 0x8f, 0x98, 0x77, 0x87, 0xda, 0xaf,
  40807. 0x16, 0x25, 0x4a, 0x9a, 0xed, 0xfb, 0x50, 0x18, 0x45, 0x46, 0x2b, 0x73,
  40808. 0xff, 0xb9, 0xb9, 0xab, 0xa2, 0x8f, 0x3a, 0xaf, 0xc5, 0x0a, 0x14, 0x91,
  40809. 0xb2, 0x3f, 0xa6, 0x93, 0xf4, 0x81, 0x20, 0x77, 0xfa, 0x51, 0x79, 0x62,
  40810. 0xe8, 0xe6, 0x89, 0x52, 0x39, 0xd5, 0x01, 0xa2, 0x87, 0xa3, 0x53, 0x74,
  40811. 0x3c, 0x36, 0x8a, 0xc3, 0xb4, 0x44, 0x3b, 0x15, 0x21, 0xf6, 0xdc, 0x18,
  40812. 0x02, 0xd2, 0x57, 0xe5, 0x10, 0xf0, 0x3d, 0x61, 0xa7, 0x16, 0x85, 0x6f,
  40813. 0x71, 0x07, 0x75, 0x50, 0x4b, 0x21, 0x53, 0x47, 0x38, 0x35, 0x9e, 0xa7,
  40814. 0xd8, 0xfd, 0x74, 0x59, 0x15, 0x32, 0x7b, 0x89, 0xd0, 0x2c, 0xd9, 0xf6,
  40815. 0x40, 0x49, 0x79, 0xdc, 0xfb, 0x0a, 0x64, 0x59, 0x9b, 0x17, 0x47, 0x36,
  40816. 0xcb, 0xf0, 0xc3, 0xcc, 0x14, 0x8e, 0x1f, 0xa8, 0x12, 0xaa, 0xb7, 0x6a,
  40817. 0xba, 0x45, 0xf9, 0xc4, 0x44, 0xe7, 0xb5, 0x7c, 0xdd, 0xbe, 0x16, 0x76,
  40818. 0x52, 0x92, 0x3d, 0x78, 0xb7, 0xec, 0x81, 0x96, 0xd8, 0x7f, 0x34, 0x2a,
  40819. 0xa2, 0x64, 0x5f, 0xfd, 0xb1, 0x42, 0x4c, 0x79, 0x98, 0xc9, 0x17, 0x48,
  40820. 0x74, 0x12, 0x72, 0x2c, 0xde, 0x91, 0x7e, 0xa9, 0x49, 0x2a, 0xcc, 0x5c,
  40821. 0x60, 0x05, 0x25, 0x09, 0x72, 0x20, 0x80, 0x42, 0x7b, 0x18, 0xc2, 0xfc,
  40822. 0x2a, 0x5e, 0x3e, 0x2d, 0x61, 0xa6, 0xf6, 0x82, 0x42, 0x83, 0x81, 0x66,
  40823. 0x4d, 0xa6, 0xe1, 0xf9, 0xf6, 0x48, 0xd4, 0xc8, 0x69, 0xed, 0xee, 0xb5,
  40824. 0x7a, 0xcb, 0xf6, 0x0a, 0x76, 0x0e, 0x61, 0x8b, 0xf2, 0x1a, 0x8a, 0xa7,
  40825. 0x88, 0xb0, 0x90, 0xd5, 0x23, 0xaa, 0xe0, 0x2b, 0xd6, 0xd0, 0xef, 0x49,
  40826. 0x13, 0x88, 0xc7, 0x50, 0xf0, 0x9e, 0xd5, 0x28, 0xe1, 0xaa, 0x1d, 0xaf,
  40827. 0xd9, 0x73, 0xb3, 0x9e, 0xa7, 0xd8, 0xfc, 0xb9, 0x22, 0x97, 0x0e, 0x21,
  40828. 0xa0, 0xb9, 0xf9, 0xea, 0x1e, 0x95, 0x88, 0xda, 0x85, 0x7c, 0x32, 0x7c,
  40829. 0xbd, 0xef, 0xf8, 0x44, 0x25, 0x5f, 0x23, 0xfd, 0x14, 0x78, 0xc6, 0xdb,
  40830. 0x86, 0xee, 0xf8, 0xda, 0xc0, 0xae, 0x92, 0x6a, 0x03, 0xa9, 0x0a, 0xee,
  40831. 0x4a, 0x22, 0x5a, 0x6c, 0x39, 0xd3, 0x91, 0x7d, 0x91, 0x43, 0xac, 0x79,
  40832. 0xad, 0xab, 0xb7, 0x91, 0xb1, 0x20, 0x84, 0x7f, 0x0a, 0xd7, 0xa8, 0x62,
  40833. 0x95, 0xab, 0x04, 0xb6, 0xb2, 0xf1, 0xd4, 0xb0, 0xac, 0x52, 0x89, 0xb0,
  40834. 0x93, 0xdf, 0xdf, 0x80, 0x26, 0x0c, 0x32, 0x31, 0xb3, 0xba, 0xa1, 0xba,
  40835. 0x6f, 0xa3, 0x14, 0x5c, 0xfa, 0x37, 0x3b, 0x6a, 0xf2, 0xc4, 0x34, 0x27,
  40836. 0x08, 0x1a, 0xe4, 0xfc, 0x89, 0x58, 0x79, 0x34, 0x36, 0xe4, 0xad, 0x4b,
  40837. 0x3f, 0x57, 0x7b, 0xc1, 0x59, 0x2d, 0xb6, 0x54, 0x44, 0xbe, 0x4e, 0x5d,
  40838. 0x0d, 0x6a, 0xf3, 0xcd, 0xbf, 0xcd, 0x4d, 0x9f, 0x9a, 0x50, 0x09, 0xa4,
  40839. 0x6b, 0x8b, 0xb3, 0x01, 0x69, 0x6c, 0x69, 0x5d, 0x28, 0x73, 0x9e, 0xb5,
  40840. 0xc2, 0xc7, 0x6e, 0xff, 0x4c, 0x5c, 0x6b, 0x93, 0x22, 0xc1, 0x9f, 0xa6,
  40841. 0x71, 0xbf, 0x4d, 0x2d, 0x4e, 0x4e, 0x98, 0xa3, 0x6d, 0xab, 0x05, 0xa0,
  40842. 0xde, 0x34, 0x41, 0x28, 0xa4, 0x38, 0x75, 0x4e, 0xdf, 0x7f, 0xc9, 0xdd,
  40843. 0xbf, 0x5a, 0xd4, 0xcd, 0x38, 0x0c, 0x89, 0xe7, 0x0e, 0xfc, 0x0f, 0x27,
  40844. 0x39, 0x21, 0xa4, 0xa6, 0x07, 0x7b, 0x2a, 0x13, 0x56, 0xe7, 0x4e, 0x55,
  40845. 0x57, 0x71, 0x98, 0xb9, 0x3d, 0x59, 0xb5, 0xa8, 0x24, 0x18, 0x08, 0xa2,
  40846. 0x6e, 0x9a, 0xe5, 0x97, 0xa7, 0x38, 0xd9, 0x43, 0x9b, 0x19, 0x17, 0x34,
  40847. 0x03, 0xd6, 0xba, 0xe9, 0x71, 0x38, 0x26, 0x90, 0x78, 0x9e, 0x1c, 0x41,
  40848. 0x8d, 0x60, 0xdd, 0x0e, 0x12, 0x46, 0x37, 0xb4, 0x79, 0x87, 0x33, 0x12,
  40849. 0x24, 0xc4, 0x5a, 0x6c, 0x70, 0xa2, 0xb2, 0x58, 0xbb, 0xe7, 0xd6, 0x88,
  40850. 0x42, 0x2d, 0x49, 0xc8, 0x67, 0x1e, 0xc5, 0xed, 0x16, 0xa8, 0x1f, 0x36,
  40851. 0x2b, 0xfb, 0x0d, 0x51, 0x96, 0xc8, 0x78, 0xf2, 0xab, 0x82, 0xa1, 0xe2,
  40852. 0xaf, 0x8c, 0xa4, 0x13, 0x54, 0x90, 0xf1, 0xe7, 0xbb, 0xd1, 0x09, 0x23,
  40853. 0x76, 0x0e, 0x50, 0x32, 0xc5, 0x54, 0xbb, 0x1e, 0x12, 0x5d, 0x59, 0xf3,
  40854. 0xe9, 0xc9, 0xa4, 0xaa, 0xbc, 0x13, 0x1d, 0xf0, 0x79, 0x54, 0xae, 0x70,
  40855. 0xc0, 0xea, 0xcb, 0x21, 0x32, 0xe6, 0xe6, 0x8e, 0xaa, 0x51, 0x46, 0x25,
  40856. 0x1e, 0xf1, 0x3f, 0x9f, 0xf6, 0xff, 0x19, 0x53, 0x97, 0xbc, 0xa2, 0xb6,
  40857. 0x91, 0x59, 0x27, 0x1e, 0x39, 0x76, 0x76, 0x02, 0x0b, 0x03, 0x25, 0x6b,
  40858. 0x00, 0x02, 0xfa, 0x7d, 0x69, 0x5e, 0xde, 0x64, 0x33, 0xbf, 0xab, 0x3e,
  40859. 0x3f, 0x24, 0x32, 0x68, 0xbf, 0x90, 0x8f, 0x0f, 0xc5, 0x36, 0x58, 0x9e,
  40860. 0x9b, 0x11, 0xd1, 0x2a, 0x8a, 0x0d, 0xac, 0x3a, 0x23, 0xe2, 0x8e, 0xd6,
  40861. 0x0d, 0x4a, 0x8b, 0x45, 0x04, 0x47, 0xd9, 0x5a, 0x46, 0x6c, 0x70, 0x82,
  40862. 0xc7, 0x81, 0x67, 0xdc, 0xa6, 0xfa, 0x6a, 0x86, 0xfd, 0x01, 0xed, 0x90,
  40863. 0xf6, 0xe6, 0x26, 0x6d, 0xac, 0x52, 0x03, 0x4a, 0x91, 0x08, 0x7b, 0xa5,
  40864. 0x9c, 0xca, 0xd3, 0x2d, 0x79, 0xf1, 0xed, 0xcb, 0xaa, 0x8f, 0x77, 0xc8,
  40865. 0x17, 0xa8, 0xfb, 0x6c, 0x15, 0x62, 0xab, 0x34, 0xd1, 0xdd, 0x94, 0x3e,
  40866. 0xd4, 0x0c, 0x47, 0xed, 0x04, 0x91, 0xd2, 0xd7, 0x98, 0xb4, 0x43, 0x57,
  40867. 0xd1, 0x54, 0xef, 0x63, 0xba, 0xe3, 0x8a, 0x72, 0xc5, 0xb9, 0xf4, 0x30,
  40868. 0xfa, 0x16, 0x3c, 0xe1, 0xbb, 0xbe, 0x57, 0x90, 0xb9, 0xa1, 0xa0, 0x23,
  40869. 0xfa, 0xdd, 0xbe, 0x2f, 0xb3, 0xec, 0x41, 0x8b, 0x64, 0xeb, 0xc5, 0x41,
  40870. 0xea, 0xa8, 0x16, 0x76, 0x6f, 0x28, 0xda, 0x2b, 0x5f, 0x03, 0x0b, 0xe8,
  40871. 0x1c, 0x29, 0x71, 0xd8, 0x4e, 0x41, 0xdf, 0x39, 0x8e, 0x6a, 0x95, 0x79,
  40872. 0x85, 0x9c, 0xa9, 0x79, 0xd9, 0x8f, 0x33, 0xaf, 0x15, 0x3b, 0x5a, 0x82,
  40873. 0x56, 0x32, 0x98, 0x0c, 0xf6, 0xf6, 0x64, 0x42, 0xd4, 0x6a, 0x15, 0x0f,
  40874. 0xb9, 0x75, 0x22, 0xbd, 0x9a, 0x58, 0xa6, 0x01, 0x3a, 0x63, 0xf0, 0x80,
  40875. 0x78, 0x22, 0x80, 0xa0, 0x14, 0xe1, 0x37, 0x6b, 0xd4, 0x99, 0x3f, 0xc2,
  40876. 0xba, 0x2b, 0x8f, 0xf3, 0x56, 0xc8, 0x1b, 0xe4, 0x7a, 0x5e, 0x96, 0x60,
  40877. 0xee, 0x74, 0x54, 0xb6, 0x6d, 0x5c, 0x3d, 0x3e, 0x05, 0xf0, 0x9a, 0xf6,
  40878. 0xcd, 0xdd, 0x06, 0xdb, 0x8c, 0x21, 0xb9, 0xf5, 0x28, 0x57, 0x9c, 0x4f,
  40879. 0xb4, 0x08, 0xcf, 0xac, 0x6c, 0xfe, 0x30, 0xaf, 0xa2, 0xef, 0xcf, 0x93,
  40880. 0x15, 0xdd, 0x12, 0x16, 0x19, 0x7d, 0xbc, 0x57, 0xd9, 0xce, 0xbe, 0x0e,
  40881. 0xfc, 0xe1, 0xf0, 0x4a, 0x7c, 0xaa, 0xbf, 0x20, 0x64, 0x00, 0x34, 0x59,
  40882. 0xed, 0xea, 0x12, 0x58, 0x46, 0x4c, 0xc6, 0x2f, 0x77, 0x62, 0x1d, 0x82,
  40883. 0x5c, 0xe8, 0x98, 0x0d, 0xef, 0x5c, 0x0e, 0xec, 0x5d, 0x2e, 0x5f, 0xd2,
  40884. 0x22, 0x43, 0x2d, 0xe1, 0x02, 0xd5, 0x4a, 0x0a, 0x79, 0x6f, 0xa5, 0xec,
  40885. 0x48, 0xaa, 0xee, 0xf8, 0xe3, 0x5f, 0xdd, 0xe7, 0x26, 0x87, 0xb5, 0xc4,
  40886. 0xcf, 0xd9, 0x7f, 0xa8, 0xaa, 0xb6, 0xbe, 0xe9, 0x02, 0x49, 0x5d, 0x5f,
  40887. 0x81, 0x8b, 0xb9, 0xbd, 0xc0, 0xc9, 0xd5, 0xfe, 0x36, 0x3e, 0x49, 0x56,
  40888. 0x63, 0x8b, 0xce, 0xef, 0x48, 0x6e, 0xc0, 0xd4, 0x04, 0x0c, 0x33, 0x45,
  40889. 0x6e, 0x97, 0x9e, 0xa3, 0xae, 0xbc, 0xc2, 0xce, 0xdc, 0xe3, 0xff, 0x48,
  40890. 0x51, 0x68, 0x89, 0xad, 0xae, 0xc7, 0xd1, 0xde, 0xe2, 0xf9, 0xfe, 0x00,
  40891. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40892. 0x0c, 0x18, 0x20, 0x24, 0x2f, 0x33, 0x3f
  40893. };
  40894. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40895. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_sig[] = {
  40896. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  40897. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  40898. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  40899. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  40900. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  40901. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  40902. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  40903. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  40904. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  40905. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  40906. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  40907. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  40908. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  40909. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  40910. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  40911. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  40912. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  40913. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  40914. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  40915. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  40916. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  40917. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  40918. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  40919. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  40920. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  40921. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  40922. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  40923. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  40924. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  40925. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  40926. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  40927. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  40928. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  40929. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  40930. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  40931. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  40932. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  40933. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  40934. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  40935. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  40936. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  40937. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  40938. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  40939. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  40940. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  40941. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  40942. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  40943. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  40944. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  40945. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  40946. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  40947. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  40948. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  40949. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  40950. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  40951. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  40952. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  40953. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  40954. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  40955. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  40956. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  40957. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  40958. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  40959. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  40960. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  40961. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  40962. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  40963. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  40964. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  40965. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  40966. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  40967. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  40968. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  40969. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  40970. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  40971. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  40972. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  40973. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  40974. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  40975. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  40976. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  40977. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  40978. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  40979. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  40980. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  40981. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  40982. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  40983. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  40984. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  40985. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  40986. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  40987. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  40988. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  40989. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  40990. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  40991. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  40992. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  40993. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  40994. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  40995. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  40996. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  40997. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  40998. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  40999. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  41000. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  41001. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  41002. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  41003. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  41004. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  41005. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  41006. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  41007. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  41008. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  41009. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  41010. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  41011. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  41012. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  41013. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  41014. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  41015. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  41016. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  41017. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  41018. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  41019. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  41020. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  41021. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  41022. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  41023. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  41024. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  41025. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  41026. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  41027. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  41028. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  41029. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  41030. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  41031. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  41032. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  41033. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  41034. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  41035. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  41036. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  41037. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  41038. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  41039. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  41040. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  41041. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  41042. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  41043. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  41044. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  41045. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  41046. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  41047. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  41048. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  41049. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  41050. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  41051. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  41052. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  41053. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  41054. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  41055. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  41056. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  41057. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  41058. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  41059. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  41060. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  41061. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  41062. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  41063. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  41064. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  41065. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  41066. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  41067. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  41068. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  41069. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  41070. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  41071. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  41072. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  41073. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  41074. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  41075. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  41076. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  41077. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  41078. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  41079. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  41080. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  41081. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  41082. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  41083. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  41084. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  41085. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  41086. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  41087. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  41088. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  41089. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  41090. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  41091. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  41092. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  41093. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  41094. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  41095. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  41096. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  41097. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  41098. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  41099. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  41100. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  41101. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  41102. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  41103. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  41104. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  41105. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  41106. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  41107. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  41108. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  41109. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  41110. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  41111. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  41112. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  41113. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  41114. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  41115. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  41116. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  41117. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  41118. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  41119. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  41120. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  41121. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  41122. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  41123. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  41124. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  41125. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  41126. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  41127. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  41128. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  41129. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  41130. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  41131. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  41132. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  41133. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  41134. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  41135. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  41136. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  41137. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  41138. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  41139. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  41140. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  41141. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  41142. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  41143. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  41144. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  41145. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  41146. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  41147. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  41148. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  41149. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  41150. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  41151. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  41152. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  41153. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  41154. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  41155. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  41156. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  41157. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  41158. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  41159. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  41160. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  41161. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  41162. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  41163. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  41164. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  41165. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  41166. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  41167. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  41168. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  41169. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  41170. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  41171. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  41172. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  41173. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  41174. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  41175. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  41176. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  41177. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  41178. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  41179. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  41180. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  41181. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  41182. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  41183. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  41184. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  41185. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  41186. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  41187. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  41188. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  41189. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  41190. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  41191. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  41192. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  41193. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  41194. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  41195. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  41196. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  41197. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  41198. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  41199. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  41200. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  41201. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  41202. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  41203. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  41204. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  41205. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  41206. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  41207. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  41208. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  41209. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  41210. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  41211. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  41212. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  41213. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  41214. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  41215. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  41216. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  41217. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  41218. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  41219. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  41220. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  41221. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  41222. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  41223. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  41224. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  41225. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  41226. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  41227. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  41228. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  41229. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  41230. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  41231. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  41232. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  41233. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  41234. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  41235. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  41236. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  41237. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  41238. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  41239. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  41240. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  41241. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  41242. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  41243. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  41244. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  41245. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  41246. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  41247. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  41248. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  41249. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  41250. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  41251. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  41252. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  41253. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  41254. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  41255. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  41256. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  41257. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  41258. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  41259. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  41260. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  41261. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  41262. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  41263. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  41264. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  41265. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  41266. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  41267. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  41268. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  41269. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  41270. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  41271. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  41272. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  41273. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  41274. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  41275. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  41276. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  41277. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  41278. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  41279. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  41280. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  41281. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  41282. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  41283. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  41284. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  41285. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  41286. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  41287. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  41288. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  41289. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  41290. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  41291. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  41292. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  41293. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  41294. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  41295. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  41296. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  41297. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  41298. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  41299. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  41300. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  41301. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  41302. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  41303. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  41304. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  41305. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  41306. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  41307. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  41308. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  41309. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  41310. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  41311. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  41312. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  41313. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  41314. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  41315. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  41316. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  41317. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  41318. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  41319. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  41320. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  41321. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  41322. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  41323. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  41324. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  41325. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  41326. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  41327. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  41328. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  41329. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  41330. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  41331. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  41332. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  41333. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  41334. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  41335. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  41336. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  41337. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  41338. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  41339. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  41340. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  41341. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  41342. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  41343. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  41344. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  41345. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  41346. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  41347. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  41348. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  41349. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  41350. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  41351. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  41352. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  41353. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  41354. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  41355. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  41356. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  41357. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  41358. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f
  41359. };
  41360. #endif
  41361. wc_test_ret_t ret;
  41362. ret = dilithium_param_vfy_test(WC_ML_DSA_87, ml_dsa_87_pub_key,
  41363. (word32)sizeof(ml_dsa_87_pub_key), ml_dsa_87_sig,
  41364. (word32)sizeof(ml_dsa_87_sig));
  41365. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  41366. if (ret == 0) {
  41367. ret = dilithium_param_vfy_test(WC_ML_DSA_87_DRAFT,
  41368. ml_dsa_87_draft_pub_key, (word32)sizeof(ml_dsa_87_draft_pub_key),
  41369. ml_dsa_87_draft_sig, (word32)sizeof(ml_dsa_87_draft_sig));
  41370. }
  41371. #endif
  41372. return ret;
  41373. }
  41374. #endif
  41375. #endif
  41376. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41377. static wc_test_ret_t dilithium_param_test(int param, WC_RNG* rng)
  41378. {
  41379. wc_test_ret_t ret;
  41380. dilithium_key* key;
  41381. byte* sig = NULL;
  41382. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41383. word32 sigLen;
  41384. byte msg[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  41385. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41386. int res = 0;
  41387. #endif
  41388. #endif
  41389. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  41390. DYNAMIC_TYPE_TMP_BUFFER);
  41391. if (key == NULL) {
  41392. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41393. }
  41394. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT,
  41395. DYNAMIC_TYPE_TMP_BUFFER);
  41396. if (sig == NULL) {
  41397. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41398. }
  41399. ret = wc_dilithium_init(key);
  41400. if (ret != 0) {
  41401. ret = WC_TEST_RET_ENC_EC(ret);
  41402. return ret;
  41403. }
  41404. ret = wc_dilithium_set_level(key, param);
  41405. if (ret != 0)
  41406. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41407. ret = wc_dilithium_make_key(key, rng);
  41408. if (ret != 0)
  41409. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41410. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41411. sigLen = wc_dilithium_sig_size(key);
  41412. if (sigLen <= 0)
  41413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41414. ret = wc_dilithium_sign_msg(msg, (word32)sizeof(msg), sig, &sigLen, key,
  41415. rng);
  41416. if (ret != 0)
  41417. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41418. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41419. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg), &res,
  41420. key);
  41421. if (ret != 0)
  41422. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41423. if (res != 1)
  41424. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  41425. #endif
  41426. #endif
  41427. out:
  41428. wc_dilithium_free(key);
  41429. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41430. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41431. return ret;
  41432. }
  41433. #endif
  41434. #if defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41435. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41436. /* Tests decoding a key from DER without the security level specified */
  41437. static wc_test_ret_t test_dilithium_decode_level(const byte* rawKey,
  41438. word32 rawKeySz,
  41439. int expectedLevel,
  41440. int isPublicOnlyKey)
  41441. {
  41442. int ret = 0;
  41443. #ifdef WOLFSSL_SMALL_STACK
  41444. dilithium_key *key = NULL;
  41445. #else
  41446. dilithium_key key[1];
  41447. #endif
  41448. word32 idx;
  41449. byte* der;
  41450. word32 derSz;
  41451. /* Size the buffer to accommodate the largest encoded key size */
  41452. const word32 maxDerSz = DILITHIUM_MAX_PRV_KEY_DER_SIZE;
  41453. /* Allocate DER buffer */
  41454. der = (byte*)XMALLOC(maxDerSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41455. if (der == NULL) {
  41456. return MEMORY_E;
  41457. }
  41458. #ifdef WOLFSSL_SMALL_STACK
  41459. key = (dilithium_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41460. if (key == NULL)
  41461. ret = MEMORY_E;
  41462. #endif
  41463. /* Initialize key */
  41464. if (ret == 0) {
  41465. ret = wc_dilithium_init(key);
  41466. }
  41467. /* Import raw key, setting the security level */
  41468. if (ret == 0) {
  41469. ret = wc_dilithium_set_level(key, expectedLevel);
  41470. }
  41471. if (ret == 0) {
  41472. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41473. if (isPublicOnlyKey) {
  41474. ret = wc_dilithium_import_public(rawKey, rawKeySz, key);
  41475. }
  41476. #endif
  41477. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41478. if (!isPublicOnlyKey) {
  41479. ret = wc_dilithium_import_private(rawKey, rawKeySz, key);
  41480. }
  41481. #endif
  41482. }
  41483. /* Export raw key as DER */
  41484. if (ret == 0) {
  41485. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41486. if (isPublicOnlyKey) {
  41487. ret = wc_Dilithium_PublicKeyToDer(key, der, maxDerSz, 1);
  41488. }
  41489. #endif
  41490. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41491. if (!isPublicOnlyKey) {
  41492. ret = wc_Dilithium_PrivateKeyToDer(key, der, maxDerSz);
  41493. }
  41494. #endif
  41495. if (ret >= 0) {
  41496. derSz = ret;
  41497. ret = 0;
  41498. }
  41499. }
  41500. /* Free and reinit key to test fresh decode */
  41501. if (ret == 0) {
  41502. wc_dilithium_free(key);
  41503. ret = wc_dilithium_init(key);
  41504. }
  41505. /* First test decoding when security level is set externally */
  41506. if (ret == 0) {
  41507. ret = wc_dilithium_set_level(key, expectedLevel);
  41508. }
  41509. if (ret == 0) {
  41510. idx = 0;
  41511. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41512. if (isPublicOnlyKey) {
  41513. ret = wc_Dilithium_PublicKeyDecode(der, &idx, key, derSz);
  41514. }
  41515. #endif
  41516. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41517. if (!isPublicOnlyKey) {
  41518. ret = wc_Dilithium_PrivateKeyDecode(der, &idx, key, derSz);
  41519. }
  41520. #endif
  41521. }
  41522. /* Free and reinit key to test fresh decode */
  41523. if (ret == 0) {
  41524. wc_dilithium_free(key);
  41525. ret = wc_dilithium_init(key);
  41526. }
  41527. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  41528. /* Test decoding without setting security level - should auto-detect */
  41529. if (ret == 0) {
  41530. idx = 0;
  41531. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41532. if (isPublicOnlyKey) {
  41533. ret = wc_Dilithium_PublicKeyDecode(der, &idx, key, derSz);
  41534. }
  41535. #endif
  41536. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41537. if (!isPublicOnlyKey) {
  41538. ret = wc_Dilithium_PrivateKeyDecode(der, &idx, key, derSz);
  41539. }
  41540. #endif
  41541. }
  41542. /* Verify auto-detected security level */
  41543. if (ret == 0 && key->level != expectedLevel) {
  41544. printf("Dilithium key decode failed to detect level.\n"
  41545. "\tExpected level=%d\n\tGot level=%d\n",
  41546. expectedLevel, key->level);
  41547. ret = WC_TEST_RET_ENC_NC;
  41548. }
  41549. #endif /* !WOLFSSL_DILITHIUM_FIPS204_DRAFT */
  41550. /* Cleanup */
  41551. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41552. wc_dilithium_free(key);
  41553. #ifdef WOLFSSL_SMALL_STACK
  41554. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41555. #endif
  41556. return ret;
  41557. }
  41558. /* Test Dilithium key decoding and security level detection */
  41559. static wc_test_ret_t dilithium_decode_test(void)
  41560. {
  41561. wc_test_ret_t ret;
  41562. const byte* key;
  41563. word32 keySz;
  41564. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41565. const int isPrvKey = 0;
  41566. #endif
  41567. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41568. const int isPubKey = 1;
  41569. #endif
  41570. #ifndef WOLFSSL_NO_ML_DSA_44
  41571. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41572. /* Test ML-DSA-44 */
  41573. key = bench_dilithium_level2_key;
  41574. keySz = sizeof_bench_dilithium_level2_key;
  41575. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_44, isPrvKey);
  41576. if (ret != 0) {
  41577. return ret;
  41578. }
  41579. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41580. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41581. key = bench_dilithium_level2_pubkey;
  41582. keySz = sizeof_bench_dilithium_level2_pubkey;
  41583. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_44, isPubKey);
  41584. if (ret != 0) {
  41585. return ret;
  41586. }
  41587. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41588. #endif /* WOLFSSL_NO_ML_DSA_44 */
  41589. #ifndef WOLFSSL_NO_ML_DSA_65
  41590. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41591. /* Test ML-DSA-65 */
  41592. key = bench_dilithium_level3_key;
  41593. keySz = sizeof_bench_dilithium_level3_key;
  41594. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_65, isPrvKey);
  41595. if (ret != 0) {
  41596. return ret;
  41597. }
  41598. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41599. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41600. key = bench_dilithium_level3_pubkey;
  41601. keySz = sizeof_bench_dilithium_level3_pubkey;
  41602. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_65, isPubKey);
  41603. if (ret != 0) {
  41604. return ret;
  41605. }
  41606. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41607. #endif /* WOLFSSL_NO_ML_DSA_65 */
  41608. #ifndef WOLFSSL_NO_ML_DSA_87
  41609. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41610. /* Test ML-DSA-87 */
  41611. key = bench_dilithium_level5_key;
  41612. keySz = sizeof_bench_dilithium_level5_key;
  41613. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_87, isPrvKey);
  41614. if (ret != 0) {
  41615. return ret;
  41616. }
  41617. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41618. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41619. key = bench_dilithium_level5_pubkey;
  41620. keySz = sizeof_bench_dilithium_level5_pubkey;
  41621. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_87, isPubKey);
  41622. if (ret != 0) {
  41623. return ret;
  41624. }
  41625. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41626. #endif /* WOLFSSL_NO_ML_DSA_87 */
  41627. return ret;
  41628. }
  41629. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY || WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41630. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
  41631. {
  41632. wc_test_ret_t ret;
  41633. WC_RNG rng;
  41634. #ifndef HAVE_FIPS
  41635. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41636. #else
  41637. ret = wc_InitRng(&rng);
  41638. #endif
  41639. if (ret != 0) {
  41640. ret = WC_TEST_RET_ENC_EC(ret);
  41641. return ret;
  41642. }
  41643. #ifndef WOLFSSL_NO_ML_DSA_44
  41644. #ifdef WOLFSSL_WC_DILITHIUM
  41645. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41646. ret = dilithium_param_44_vfy_test();
  41647. if (ret != 0)
  41648. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41649. #endif
  41650. #endif
  41651. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41652. ret = dilithium_param_test(WC_ML_DSA_44, &rng);
  41653. if (ret != 0)
  41654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41655. #endif
  41656. #endif
  41657. #ifndef WOLFSSL_NO_ML_DSA_65
  41658. #ifdef WOLFSSL_WC_DILITHIUM
  41659. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41660. ret = dilithium_param_65_vfy_test();
  41661. if (ret != 0)
  41662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41663. #endif
  41664. #endif
  41665. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41666. ret = dilithium_param_test(WC_ML_DSA_65, &rng);
  41667. if (ret != 0)
  41668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41669. #endif
  41670. #endif
  41671. #ifndef WOLFSSL_NO_ML_DSA_87
  41672. #ifdef WOLFSSL_WC_DILITHIUM
  41673. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41674. ret = dilithium_param_87_vfy_test();
  41675. if (ret != 0)
  41676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41677. #endif
  41678. #endif
  41679. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41680. ret = dilithium_param_test(WC_ML_DSA_87, &rng);
  41681. if (ret != 0)
  41682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41683. #endif
  41684. #endif
  41685. #if defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41686. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41687. ret = dilithium_decode_test();
  41688. if (ret != 0) {
  41689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41690. }
  41691. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY || WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41692. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  41693. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) || \
  41694. defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41695. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41696. out:
  41697. #endif
  41698. wc_FreeRng(&rng);
  41699. return ret;
  41700. }
  41701. #endif /* HAVE_DILITHIUM */
  41702. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  41703. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  41704. void *context)
  41705. {
  41706. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41707. * BE USED FOR TESTING PURPOSES! Production applications should
  41708. * write only to non-volatile storage. */
  41709. XMEMCPY(context, priv, privSz);
  41710. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  41711. }
  41712. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  41713. void *context)
  41714. {
  41715. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41716. * BE USED FOR TESTING PURPOSES! */
  41717. XMEMCPY(priv, context, privSz);
  41718. return WC_XMSS_RC_READ_TO_MEMORY;
  41719. }
  41720. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
  41721. {
  41722. int i = 0;
  41723. int j = 0;
  41724. XmssKey signingKey;
  41725. XmssKey verifyKey;
  41726. WC_RNG rng;
  41727. word32 pkSz = 0;
  41728. word32 skSz = 0;
  41729. word32 sigSz = 0;
  41730. word32 bufSz = 0;
  41731. unsigned char * sk = NULL;
  41732. unsigned char * old_sk = NULL;
  41733. const char * msg = "XMSS post quantum signature test";
  41734. word32 msgSz = (word32) XSTRLEN(msg);
  41735. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41736. const char * param = "XMSS-SHA2_10_256";
  41737. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 20
  41738. const char * param = "XMSSMT-SHA2_20/4_256";
  41739. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 40
  41740. const char * param = "XMSSMT-SHA2_40/8_256";
  41741. #else
  41742. const char * param = "XMSSMT-SHA2_60/12_256";
  41743. #endif
  41744. byte * sig = NULL;
  41745. int ret2 = -1;
  41746. int ret = WC_TEST_RET_ENC_NC;
  41747. WOLFSSL_ENTER("xmss_test");
  41748. #ifndef HAVE_FIPS
  41749. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41750. #else
  41751. ret = wc_InitRng(&rng);
  41752. #endif
  41753. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41754. ret = wc_XmssKey_Init(&signingKey, NULL, INVALID_DEVID);
  41755. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41756. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41757. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41758. /* Set the parameter string to the signing key, and
  41759. * get sizes for secret key, pub key, and signature. */
  41760. ret = wc_XmssKey_SetParamStr(&signingKey, param);
  41761. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41762. ret = wc_XmssKey_GetPubLen(&signingKey, &pkSz);
  41763. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41764. if (pkSz != XMSS_SHA256_PUBLEN) {
  41765. return WC_TEST_RET_ENC_EC(pkSz);
  41766. }
  41767. ret = wc_XmssKey_GetPrivLen(&signingKey, &skSz);
  41768. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41769. ret = wc_XmssKey_GetSigLen(&signingKey, &sigSz);
  41770. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41771. /* Allocate signature array. */
  41772. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41773. if (sig == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41774. bufSz = sigSz;
  41775. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41776. fprintf(stderr, "param: %s\n", param);
  41777. fprintf(stderr, "pkSz: %d\n", pkSz);
  41778. fprintf(stderr, "skSz: %d\n", skSz);
  41779. fprintf(stderr, "sigSz: %d\n", sigSz);
  41780. #endif
  41781. /* Allocate current and old secret keys.*/
  41782. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41783. if (sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41784. old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41785. if (old_sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41786. XMEMSET(sk, 0, skSz);
  41787. XMEMSET(old_sk, 0, skSz);
  41788. XMEMSET(sig, 0, sigSz);
  41789. ret = wc_XmssKey_SetWriteCb(&signingKey, xmss_write_key_mem);
  41790. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41791. ret = wc_XmssKey_SetReadCb(&signingKey, xmss_read_key_mem);
  41792. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41793. ret = wc_XmssKey_SetContext(&signingKey, (void *) sk);
  41794. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41795. ret = wc_XmssKey_MakeKey(&signingKey, &rng);
  41796. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41797. /* Export the pub to a verify key. */
  41798. ret = wc_XmssKey_ExportPub(&verifyKey, &signingKey);
  41799. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41800. /* Repeat a few times to check that:
  41801. * 1. The secret key is mutated on each sign.
  41802. * 2. We can verify each new signature.
  41803. * Only do a few times, because the full signature space
  41804. * for this parameter set is huge. */
  41805. for (i = 0; i < 10; ++i) {
  41806. XMEMCPY(old_sk, sk, skSz);
  41807. ret = wc_XmssKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41808. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41809. if (sigSz != bufSz) { return WC_TEST_RET_ENC_I(i); }
  41810. /* Old secret key and current secret key should not match. */
  41811. ret = XMEMCMP(old_sk, sk, skSz);
  41812. if (ret == 0) { return WC_TEST_RET_ENC_I(i); }
  41813. ret = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41814. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41815. /* Flip bits in a few places throughout the signature, stepping in multiple
  41816. * of hash size. These should all fail with -1. */
  41817. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41818. sig[j] ^= 1;
  41819. ret2 = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41820. msgSz);
  41821. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41822. /* Verify passed when it should have failed. */
  41823. return WC_TEST_RET_ENC_I(j);
  41824. }
  41825. /* Flip this spot back. */
  41826. sig[j] ^= 1;
  41827. }
  41828. }
  41829. /* Cleanup everything. */
  41830. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41831. sig = NULL;
  41832. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41833. sk = NULL;
  41834. XFREE(old_sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41835. old_sk = NULL;
  41836. wc_XmssKey_Free(&signingKey);
  41837. wc_FreeRng(&rng);
  41838. return ret;
  41839. }
  41840. #endif /*if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)*/
  41841. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_SMALL_STACK) && \
  41842. WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41843. /* A simple xmss verify only test using:
  41844. * XMSS-SHA2_10_256
  41845. * pub len: 68
  41846. * msg len: 32
  41847. * sig len: 2500
  41848. *
  41849. * These were generated with the test xmss_fast, from the unpatched
  41850. * xmss-reference repository:
  41851. * https://github.com/XMSS/xmss-reference
  41852. * */
  41853. static const byte xmss_pub[XMSS_SHA256_PUBLEN] =
  41854. {
  41855. 0x00,0x00,0x00,0x01,0xA5,0x41,0x31,0x96,
  41856. 0x0A,0xF9,0xF3,0xB2,0x4B,0x2E,0x5B,0x3E,
  41857. 0xCA,0x74,0xAD,0x6C,0xA5,0x89,0xAD,0x2C,
  41858. 0x0E,0x96,0xB3,0x54,0xFB,0x5B,0x63,0x50,
  41859. 0x96,0x81,0xE2,0x59,0x72,0x10,0x09,0x54,
  41860. 0xBB,0x39,0xAC,0xEE,0x78,0xEF,0x95,0xEC,
  41861. 0x01,0x1D,0xF0,0x36,0x68,0xE2,0xC4,0xA5,
  41862. 0x2F,0x60,0x42,0x7E,0xD3,0x8E,0xAA,0x27,
  41863. 0xC9,0xB7,0x39,0x4E
  41864. };
  41865. static /* not const */ byte xmss_msg[32] =
  41866. {
  41867. 0x07,0x9F,0x80,0x86,0xDB,0x76,0x27,0xDF,
  41868. 0xED,0x5B,0x2A,0x81,0x60,0x60,0x7D,0xB4,
  41869. 0xE8,0x7A,0x69,0x45,0x20,0x6B,0xA2,0x96,
  41870. 0xC0,0x21,0xA5,0x46,0x29,0x63,0x9B,0x37
  41871. };
  41872. /* This was actually the 5th signature produced from
  41873. * xmss_fast test in xmss-reference. */
  41874. static /* not const */ byte xmss_sig[2500] =
  41875. {
  41876. 0x00,0x00,0x00,0x05,0xF0,0x15,0x34,0xBA,
  41877. 0x92,0x03,0x6A,0xB9,0xA5,0x23,0x86,0x11,
  41878. 0xAE,0x65,0x0A,0x5C,0x78,0x2C,0xC9,0xBE,
  41879. 0x7E,0xA6,0xDC,0xA2,0x8B,0xA9,0x9C,0x50,
  41880. 0xF6,0x61,0x8D,0x9D,0xD7,0xE9,0xC0,0xF8,
  41881. 0x67,0xCD,0x8A,0xC4,0x9B,0x74,0x96,0x07,
  41882. 0x5D,0xF2,0xC9,0xCC,0x28,0x05,0xB1,0xBE,
  41883. 0x5E,0xA4,0xBA,0xBE,0xAB,0xD8,0x21,0x6B,
  41884. 0x21,0x5F,0xAB,0xB7,0x6C,0xEC,0x2F,0xC8,
  41885. 0xC6,0x74,0x3E,0x97,0x1B,0xC3,0x45,0x57,
  41886. 0xAF,0xAA,0x1E,0xA8,0xF2,0x86,0xA8,0xAA,
  41887. 0x43,0x6D,0x66,0xE9,0x81,0x14,0xDE,0x09,
  41888. 0x39,0xD2,0xAF,0xD1,0x4C,0xE7,0x75,0x18,
  41889. 0x0D,0xAA,0x29,0xA1,0x92,0x53,0xCC,0xE9,
  41890. 0xF3,0x0B,0x1E,0x3B,0xE2,0xAE,0x80,0x0C,
  41891. 0xE7,0x7A,0x7C,0x13,0x8A,0x28,0xC6,0x5F,
  41892. 0x0A,0xA4,0xA3,0x73,0x0A,0x3A,0xC2,0xA6,
  41893. 0x3B,0xB4,0x30,0x67,0xC0,0x36,0x18,0xA1,
  41894. 0x58,0xCD,0xAD,0x54,0x36,0x64,0xCE,0xFD,
  41895. 0x52,0xFF,0x70,0x7E,0x09,0xFB,0x13,0xA2,
  41896. 0xEA,0xDF,0x67,0x8D,0x6C,0x42,0xB2,0x78,
  41897. 0xF5,0x7D,0x5C,0x4B,0xF7,0x8E,0xCF,0x3E,
  41898. 0xB7,0xC6,0xC1,0x23,0xFA,0x65,0xDE,0xD2,
  41899. 0xFA,0x40,0x51,0x97,0x0D,0x52,0x32,0x76,
  41900. 0x7E,0x82,0x8D,0xD0,0xB9,0x1E,0x62,0xD9,
  41901. 0x1E,0xC1,0xDB,0x40,0x43,0x37,0x4A,0x23,
  41902. 0x8A,0x1D,0x35,0xFA,0xF4,0x53,0x11,0x5A,
  41903. 0xB5,0x6D,0x1E,0x8B,0x22,0xC8,0x7D,0x2A,
  41904. 0xE4,0x94,0xAA,0x25,0x20,0x40,0x96,0xDB,
  41905. 0x82,0x62,0xBA,0x8F,0x8B,0x45,0xCB,0x4F,
  41906. 0x35,0x88,0x33,0xEB,0xEF,0xB3,0xBA,0xA7,
  41907. 0x09,0x72,0xB3,0x4C,0xEC,0xF2,0xC3,0xC7,
  41908. 0x5E,0x02,0x6C,0x41,0x93,0xCB,0x3C,0x89,
  41909. 0x12,0x09,0x68,0x54,0x8E,0xEC,0x6A,0x7E,
  41910. 0x20,0xE1,0x70,0x3D,0x8C,0xEB,0xB4,0x36,
  41911. 0xBE,0x91,0xBE,0x97,0xB5,0xA6,0x34,0x16,
  41912. 0x95,0x0F,0x10,0x26,0xA9,0x13,0x80,0x88,
  41913. 0x9C,0xAA,0x68,0xEC,0x34,0x70,0x4A,0x15,
  41914. 0x9B,0x5E,0x57,0x05,0x87,0x1C,0xF8,0x35,
  41915. 0x45,0x29,0xE9,0x6E,0xF2,0x70,0x13,0x42,
  41916. 0x89,0x4E,0x77,0xC0,0x18,0xC7,0x55,0x6D,
  41917. 0xE7,0xFA,0x0D,0x63,0x83,0x16,0x19,0x01,
  41918. 0x2D,0xFD,0x31,0x14,0x94,0xCA,0x3E,0x0E,
  41919. 0xD6,0x11,0x34,0x81,0x57,0x58,0xEC,0x24,
  41920. 0xA4,0x17,0x63,0xD3,0x25,0x00,0xBF,0x7D,
  41921. 0x78,0x5D,0xC5,0xD8,0xC6,0xC1,0xBD,0x8C,
  41922. 0xD0,0x94,0x0A,0xB1,0x33,0xA5,0x4B,0x31,
  41923. 0x25,0xF5,0xAF,0xE7,0x84,0x26,0xAA,0x05,
  41924. 0xBB,0xF3,0x9A,0xAF,0x58,0x36,0x40,0xEF,
  41925. 0x3D,0xA2,0xBD,0xCA,0xA1,0x8D,0x2F,0x6D,
  41926. 0x54,0xD2,0x62,0x33,0x09,0xAE,0xE6,0x73,
  41927. 0xD6,0x44,0xE8,0x7C,0x5C,0x39,0x2B,0x78,
  41928. 0x94,0x14,0xC7,0xC9,0xAF,0xEC,0x77,0x36,
  41929. 0xA1,0x61,0x61,0xF1,0xD0,0x09,0xA2,0xEE,
  41930. 0xE7,0x55,0xD7,0x35,0x89,0x89,0x9B,0xCF,
  41931. 0xFA,0xA6,0x09,0x1E,0x3B,0xBD,0x5D,0xD9,
  41932. 0x25,0xE7,0xED,0xDD,0x7C,0xF0,0x1C,0x57,
  41933. 0xE0,0x06,0xBB,0x08,0x39,0x59,0xDF,0xD7,
  41934. 0xAF,0x4B,0x88,0x0D,0x87,0x8F,0x4A,0xF3,
  41935. 0x1C,0xD4,0x4B,0xB3,0xE2,0xF3,0x1B,0x86,
  41936. 0x4F,0xCD,0x35,0x75,0xE2,0x03,0xF9,0x1D,
  41937. 0xBF,0x3E,0xD1,0x7B,0xC7,0x23,0x11,0x75,
  41938. 0x5F,0x92,0x0D,0x98,0xEE,0x14,0xE1,0xDA,
  41939. 0x7A,0x02,0x17,0x47,0x6B,0x41,0xEA,0x47,
  41940. 0xA1,0xAF,0x06,0x79,0x1A,0x52,0x6F,0x19,
  41941. 0x31,0x70,0x71,0xBD,0xC2,0x61,0x8D,0xB7,
  41942. 0xEE,0x6B,0x69,0x2A,0xE8,0x21,0x7A,0x95,
  41943. 0xBE,0x86,0x2A,0xA1,0xF4,0xE2,0x2F,0x17,
  41944. 0x02,0xFD,0xAD,0x17,0x9F,0x0A,0x0A,0x78,
  41945. 0xA9,0x92,0x30,0x21,0x72,0x2B,0x28,0xF8,
  41946. 0xF2,0x3E,0x05,0xD5,0xAC,0xC0,0x82,0xF8,
  41947. 0xD2,0xDA,0xD0,0xA3,0xBC,0x93,0xDB,0xA5,
  41948. 0x46,0xDE,0x14,0x1E,0xD4,0x3A,0x5D,0x79,
  41949. 0x3D,0x31,0x4B,0x06,0xCE,0x22,0x29,0x3C,
  41950. 0x98,0xB6,0x18,0x8A,0xAE,0xF7,0xBA,0x22,
  41951. 0x88,0xA1,0xEE,0xC0,0x14,0x4C,0x4A,0xA0,
  41952. 0x57,0x0A,0xD3,0x18,0xA2,0x3D,0xDD,0xC7,
  41953. 0x83,0x73,0xFC,0x38,0x9B,0x31,0xA3,0xE1,
  41954. 0x17,0x76,0xA1,0xA2,0x69,0xFC,0xAB,0x08,
  41955. 0x80,0x72,0x8D,0xF5,0xE4,0x14,0xB7,0x6B,
  41956. 0x03,0xFF,0xE8,0x11,0x4B,0x06,0x55,0x7E,
  41957. 0x36,0x21,0x2F,0xD7,0x54,0x82,0xC9,0x31,
  41958. 0xB4,0x85,0x68,0x41,0xEF,0x75,0xB0,0x3A,
  41959. 0xEA,0x4F,0xE0,0xEC,0x72,0xCC,0x33,0x96,
  41960. 0xCE,0x7D,0xAD,0xDD,0x0D,0x27,0x05,0x6E,
  41961. 0xA2,0xD4,0x11,0x07,0xD8,0x7D,0x27,0xD4,
  41962. 0x80,0x8F,0x00,0x22,0xE4,0xFC,0x2C,0x9D,
  41963. 0xD5,0xD8,0x18,0x7F,0x4E,0xF4,0xB9,0x7F,
  41964. 0xEF,0xD6,0x00,0x08,0x5C,0x05,0x04,0x1E,
  41965. 0x9A,0xC6,0x8D,0xCC,0x19,0xD9,0x0B,0x06,
  41966. 0xCC,0x6A,0x17,0xE2,0x03,0x23,0xDB,0x1C,
  41967. 0xBC,0xA2,0xB9,0xA2,0x95,0x3C,0x73,0xD8,
  41968. 0xFF,0xE6,0x0E,0xAE,0x04,0xB2,0xFC,0x91,
  41969. 0x4F,0xEF,0x8A,0x58,0xB7,0x31,0x68,0x4C,
  41970. 0x1E,0xD0,0x5B,0x85,0xCC,0x03,0xDC,0xF4,
  41971. 0xAC,0xDB,0x03,0x9B,0x35,0x33,0x08,0x71,
  41972. 0xD0,0x50,0x8D,0xDC,0xE3,0x3A,0x98,0x40,
  41973. 0x41,0x80,0xDD,0x35,0xE1,0xA2,0xAF,0x14,
  41974. 0x9A,0xDB,0xD3,0x68,0x14,0xE2,0x50,0x7A,
  41975. 0x76,0x3F,0xE4,0xA4,0x1B,0xAA,0xC1,0x06,
  41976. 0x87,0x9A,0x92,0xF9,0xBE,0x9E,0x86,0x8C,
  41977. 0x92,0x1D,0x74,0xB1,0x7F,0x27,0x43,0xC0,
  41978. 0xEE,0x2E,0xC2,0x6C,0x6D,0xAA,0x0C,0x0E,
  41979. 0x71,0xC9,0x56,0xD6,0x3A,0x56,0xCB,0x90,
  41980. 0xD1,0x7E,0x6E,0x1C,0x6A,0x00,0x2D,0x02,
  41981. 0x2C,0x96,0xF0,0x2A,0x37,0x37,0x18,0x07,
  41982. 0x0B,0xF4,0xB4,0x8C,0x30,0xF2,0xA4,0xAB,
  41983. 0x66,0xFB,0x8B,0x22,0xC0,0x00,0x7E,0x05,
  41984. 0xB6,0xF9,0x95,0x49,0x33,0xA1,0xDC,0x97,
  41985. 0x0C,0x5C,0x61,0x46,0xE2,0xD7,0x87,0x4B,
  41986. 0xC4,0xC7,0x5F,0x26,0x06,0x84,0xD7,0x47,
  41987. 0x05,0xF1,0x33,0xFF,0x85,0x85,0xB2,0xBD,
  41988. 0x1F,0x44,0xC6,0xC2,0x7D,0x51,0xBE,0x0E,
  41989. 0xB5,0xC4,0x44,0x2F,0xFE,0x73,0x5F,0xF4,
  41990. 0xA4,0xEF,0xE2,0xF1,0x73,0x0B,0xEF,0x3E,
  41991. 0x2B,0xD7,0xCC,0x9F,0xDA,0x1A,0x7E,0x92,
  41992. 0x39,0xA1,0x55,0xBF,0x60,0x0A,0xDB,0x23,
  41993. 0x74,0xFE,0xE7,0x05,0x63,0xA9,0x85,0x52,
  41994. 0x9F,0xCC,0xC3,0xFF,0xF6,0x6C,0x1B,0x4E,
  41995. 0x4F,0x01,0xBD,0xC3,0xEB,0x37,0xEC,0x29,
  41996. 0x21,0x3B,0x2C,0xC9,0x2E,0x93,0x20,0x3E,
  41997. 0x19,0xC0,0x8B,0xE8,0x33,0xCD,0xC6,0x6A,
  41998. 0x6E,0x72,0x13,0x15,0xA1,0x90,0x20,0x0C,
  41999. 0x14,0x66,0xED,0xCC,0xA4,0xDD,0x7F,0x58,
  42000. 0x53,0xBC,0x4A,0x68,0xFC,0x86,0x3E,0xAA,
  42001. 0xF1,0x17,0x0F,0x3E,0x20,0x54,0x93,0xF4,
  42002. 0x98,0xBF,0xB4,0x07,0x05,0xBD,0x70,0xE7,
  42003. 0xD7,0x34,0xFD,0xE3,0x69,0xDF,0xCD,0xF5,
  42004. 0x1A,0x73,0x6E,0xC9,0x2B,0x21,0xFB,0xB8,
  42005. 0x7E,0x44,0x10,0x83,0x56,0xCE,0xD5,0x15,
  42006. 0x9A,0x75,0xFC,0x91,0x8E,0x6B,0x9E,0x1A,
  42007. 0x3A,0x33,0x39,0x35,0xB4,0x0D,0x74,0xF4,
  42008. 0xFB,0x4C,0x0E,0x37,0xFE,0x82,0x95,0x46,
  42009. 0x6B,0xD2,0x6E,0xEE,0xCD,0x4D,0x38,0xAF,
  42010. 0x0A,0xAA,0xF1,0xD5,0xA4,0x7C,0x04,0xD8,
  42011. 0xB9,0xDB,0x11,0x68,0x88,0x35,0x41,0xDE,
  42012. 0x31,0x33,0x0C,0xDC,0x2D,0x4C,0xA8,0x20,
  42013. 0xCC,0x2C,0x4C,0x63,0xAB,0xBA,0xDF,0x48,
  42014. 0x84,0xD5,0x25,0xBC,0x70,0xE3,0x49,0xAA,
  42015. 0x43,0xCA,0x8B,0xE7,0x9F,0xDD,0x20,0x76,
  42016. 0x9B,0x38,0xF4,0xBA,0x4D,0x4E,0x34,0x4A,
  42017. 0xAF,0x81,0xE7,0x0B,0xEC,0xE9,0x59,0xC1,
  42018. 0x35,0x22,0x7F,0x69,0x46,0x62,0xD2,0x18,
  42019. 0x6E,0x1F,0x79,0xD1,0xAD,0xC3,0x84,0x95,
  42020. 0x96,0xB2,0x18,0x58,0x5E,0x7E,0x0C,0x25,
  42021. 0x0A,0x0F,0x69,0xA3,0x1D,0xEC,0x29,0xCB,
  42022. 0xDA,0xA2,0xD1,0x1A,0x10,0xA5,0x52,0xC3,
  42023. 0x62,0x1E,0xC5,0x83,0xFF,0xA3,0x56,0xC2,
  42024. 0xFD,0x87,0x3B,0x57,0x52,0x98,0x36,0x95,
  42025. 0x77,0x6B,0xE5,0x49,0x10,0x8E,0x39,0xDD,
  42026. 0xCA,0x4B,0xB3,0x9F,0x4C,0x0C,0x11,0x62,
  42027. 0xF3,0x22,0x78,0xDB,0x48,0xEB,0x68,0xFE,
  42028. 0xE4,0x2A,0xE9,0xAA,0x8F,0x7A,0x2F,0x69,
  42029. 0xA5,0xC5,0x03,0x2D,0xEF,0x62,0xA8,0x71,
  42030. 0x65,0x06,0x40,0x84,0x10,0x0F,0xF2,0xED,
  42031. 0xBC,0x70,0x71,0x69,0x24,0xA2,0xBF,0x83,
  42032. 0x39,0xDD,0xFA,0xA2,0x7B,0xE5,0xEC,0x3D,
  42033. 0xFE,0x3B,0x52,0x6E,0x3D,0x82,0xA6,0x2A,
  42034. 0x86,0x01,0x61,0x51,0x63,0xBF,0xF9,0x0A,
  42035. 0x06,0x72,0xF1,0xD5,0x39,0x0C,0xBA,0xC9,
  42036. 0x78,0xC6,0x77,0x22,0xE4,0x96,0x6E,0xB1,
  42037. 0x48,0x62,0x84,0x62,0x2D,0xEA,0x49,0x56,
  42038. 0x50,0x86,0x3F,0x90,0xC3,0x01,0x42,0x45,
  42039. 0xED,0xE6,0x9A,0x65,0x19,0x93,0x7F,0x48,
  42040. 0x16,0xF2,0x50,0xA7,0x70,0xB3,0xF5,0xDB,
  42041. 0x0E,0x5E,0x22,0x9E,0x64,0x04,0x26,0x69,
  42042. 0xC1,0x16,0xEE,0x65,0x08,0x82,0x27,0x65,
  42043. 0xEC,0x3D,0xDF,0x51,0x5E,0x2D,0xE8,0x76,
  42044. 0xF2,0xE3,0xE4,0x24,0x04,0x88,0x06,0x0F,
  42045. 0xB2,0x7B,0x9B,0x72,0x3D,0x4C,0x7D,0x6A,
  42046. 0x1F,0xB2,0xA2,0xD2,0x35,0xD6,0x40,0x25,
  42047. 0xC2,0x0B,0x25,0xF9,0xDF,0x26,0xE4,0xDC,
  42048. 0xFB,0xB1,0x84,0x84,0x77,0x1B,0x45,0x51,
  42049. 0x60,0xD5,0xF0,0xB6,0x09,0xE6,0xBC,0xE3,
  42050. 0x1C,0x70,0x96,0x2C,0xD3,0x9D,0x7D,0x7F,
  42051. 0xB1,0x70,0xDA,0x79,0xB8,0x74,0x99,0xBF,
  42052. 0x84,0x95,0xCC,0x93,0xD7,0x51,0xDD,0x66,
  42053. 0xD3,0x70,0x0C,0x75,0x86,0x09,0x06,0xFD,
  42054. 0x66,0x14,0x80,0xCD,0xF3,0x59,0xB4,0x92,
  42055. 0x5F,0xE4,0xEE,0x00,0xA8,0xB0,0x8B,0x5C,
  42056. 0x3E,0xDB,0x8A,0x9C,0x0B,0xB5,0x99,0xC2,
  42057. 0x0D,0x81,0x09,0x06,0x6C,0x28,0xC0,0x7E,
  42058. 0xA5,0x07,0x70,0x64,0xD7,0x41,0xF4,0xC3,
  42059. 0x66,0x61,0x1C,0xA8,0x51,0xF6,0x3C,0xBA,
  42060. 0xE0,0x94,0xA3,0x11,0x8C,0x2E,0xBA,0x13,
  42061. 0xB2,0x47,0x48,0x93,0xB4,0x1A,0x2C,0x9A,
  42062. 0x6E,0x8E,0x30,0x66,0x7B,0xD3,0xBB,0x3B,
  42063. 0x5D,0x97,0x0D,0xE4,0xEA,0x24,0x28,0x9E,
  42064. 0xB4,0x88,0xCE,0x1D,0x7D,0x6F,0x39,0xB3,
  42065. 0x87,0x21,0xE5,0x08,0x93,0xF0,0xD4,0x9D,
  42066. 0x2D,0x91,0xC9,0xFD,0x0C,0x74,0x34,0xB4,
  42067. 0x1F,0xFE,0xDA,0xDC,0x10,0x5B,0x8D,0x2B,
  42068. 0x87,0xD3,0x42,0xB4,0xAE,0x32,0x9C,0xAE,
  42069. 0x4C,0x99,0xD8,0xED,0x44,0x41,0x07,0xE0,
  42070. 0x8F,0xBD,0xA5,0x7C,0x5A,0xDF,0x91,0x29,
  42071. 0x00,0xB5,0x4B,0xC3,0x3A,0x40,0x6C,0x48,
  42072. 0xAB,0x2A,0xF3,0x02,0xCB,0xB3,0x69,0xDA,
  42073. 0x06,0x0C,0x4D,0x5C,0x45,0xC3,0x28,0xAC,
  42074. 0x7A,0x01,0xD4,0xF8,0xCB,0x07,0x63,0x89,
  42075. 0x09,0x34,0x78,0xA7,0x14,0x39,0xCF,0x2D,
  42076. 0x94,0x8D,0x7A,0x4E,0x4E,0xBD,0xC4,0x32,
  42077. 0xAB,0x21,0xC9,0xDA,0x3F,0x5F,0x04,0x6B,
  42078. 0x14,0x40,0x18,0x18,0x2F,0xF9,0x46,0x17,
  42079. 0x57,0x54,0x9B,0x28,0x7B,0xBD,0xF9,0xA2,
  42080. 0x13,0xAC,0x69,0x24,0xB1,0x31,0x39,0xBF,
  42081. 0x8D,0x75,0xC3,0xFD,0x03,0x54,0x5A,0xFD,
  42082. 0xD4,0x7A,0xB7,0x56,0x4F,0x66,0x43,0x57,
  42083. 0x1B,0xFB,0xF9,0x92,0x7A,0x83,0xE6,0xFF,
  42084. 0xB4,0xBA,0x83,0xD2,0x61,0x8E,0x4A,0x82,
  42085. 0x82,0xA8,0xF5,0x0C,0xD2,0x43,0x53,0xA8,
  42086. 0x85,0x0A,0xD4,0x69,0x7B,0x04,0x71,0x3B,
  42087. 0x80,0x49,0x27,0x47,0x12,0xB6,0xB0,0xEA,
  42088. 0x90,0x0A,0xFA,0xA8,0xC8,0x78,0x61,0xDE,
  42089. 0x30,0x12,0xBB,0xDC,0xA6,0x57,0x56,0x30,
  42090. 0x6E,0xF1,0xA8,0x3B,0xF6,0x09,0x07,0xEA,
  42091. 0x31,0xE2,0x08,0x23,0x31,0x0F,0xD4,0x34,
  42092. 0xE3,0x60,0xC2,0x2B,0xDB,0x5A,0x99,0xCF,
  42093. 0xD4,0x6B,0x4E,0x75,0x65,0x35,0xE8,0x8B,
  42094. 0x93,0x7D,0xCA,0x11,0x47,0xF0,0x3E,0x11,
  42095. 0x5C,0xD1,0xEE,0x4B,0x11,0xB4,0x65,0x2B,
  42096. 0x6B,0x79,0xC0,0x86,0x60,0xA4,0x4B,0x24,
  42097. 0xA0,0x5C,0x70,0x34,0xC3,0x7C,0xE7,0x4F,
  42098. 0x97,0x89,0x4D,0xFE,0x22,0x89,0x3A,0xE9,
  42099. 0x07,0xB9,0x1A,0x86,0xB8,0x7A,0x12,0x38,
  42100. 0xE1,0x24,0x46,0xBC,0x9B,0x21,0xCD,0xAC,
  42101. 0x30,0xAB,0x98,0x21,0x31,0xC5,0x17,0x3F,
  42102. 0x1E,0x56,0xC3,0x18,0xCE,0xF0,0xA1,0xCC,
  42103. 0xFF,0x9D,0xA8,0x53,0xAF,0x74,0x77,0x54,
  42104. 0x02,0x9A,0x8F,0xA4,0xD4,0xBD,0xB2,0x1A,
  42105. 0xBA,0x52,0x2E,0x19,0xBE,0x49,0x11,0x45,
  42106. 0x02,0x01,0x7A,0xBF,0x28,0xD6,0x18,0xED,
  42107. 0xBD,0xCE,0xE4,0xDE,0xB5,0xF1,0x53,0x5D,
  42108. 0x65,0xF9,0x5F,0x83,0x8F,0x2D,0xF2,0x82,
  42109. 0xA0,0x2D,0x28,0xD3,0x0A,0x9E,0x0F,0x7F,
  42110. 0xC7,0xC4,0x43,0x7F,0xC3,0x0E,0x06,0xEB,
  42111. 0x4E,0xB4,0x2D,0xFA,0xDD,0x48,0xAB,0xF4,
  42112. 0x7D,0x41,0x48,0x33,0x5A,0xE6,0x70,0x02,
  42113. 0xE7,0x71,0x8D,0xD9,0x6B,0x0C,0x5A,0x8F,
  42114. 0xA4,0xC1,0xB7,0x4E,0x96,0x83,0xD6,0xA7,
  42115. 0x1D,0xF1,0x88,0xB3,0x6E,0xF4,0x12,0xA9,
  42116. 0xF6,0x31,0x69,0x66,0xFE,0xFE,0x02,0xF2,
  42117. 0x86,0x6D,0xBB,0x57,0x51,0x8C,0x4C,0xE9,
  42118. 0x7C,0x92,0x3E,0x3A,0xD3,0x2D,0xA8,0x82,
  42119. 0x53,0x84,0x26,0x89,0xBB,0xCC,0x13,0x12,
  42120. 0x3D,0x94,0xBB,0xDF,0x3D,0x4C,0xDF,0x27,
  42121. 0x9B,0x1F,0xB8,0xB6,0xE4,0xEA,0xA2,0x07,
  42122. 0xF8,0x4D,0x42,0x8F,0x29,0x90,0xFE,0x21,
  42123. 0x20,0xE9,0x55,0x02,0xAD,0x90,0xA7,0x77,
  42124. 0x4E,0x29,0xB6,0xD9,0x14,0x94,0xB2,0x25,
  42125. 0xA4,0xB2,0x0E,0x96,0x31,0xAB,0x9E,0x93,
  42126. 0x49,0xAC,0xA9,0xCB,0x68,0x22,0xBA,0xB8,
  42127. 0x57,0x5C,0x9D,0x65,0xC1,0xF1,0xFC,0x99,
  42128. 0x7C,0x3C,0xE9,0xEA,0x4B,0x29,0x22,0x2F,
  42129. 0xDB,0x17,0x21,0x8D,0xB0,0x13,0xBF,0xEE,
  42130. 0x7D,0xE4,0x8B,0x6D,0x17,0xE0,0x53,0x92,
  42131. 0x0B,0x32,0x6B,0xB1,0x65,0x2E,0xA7,0x83,
  42132. 0xFD,0x62,0x62,0xE3,0xAA,0x81,0xE8,0xD6,
  42133. 0xF7,0xB1,0x30,0x65,0x80,0x9F,0x77,0x1E,
  42134. 0x4A,0xEA,0xE8,0x45,0x32,0x12,0x3A,0xFB,
  42135. 0x22,0xE9,0xA9,0xF6,0xCB,0xAB,0xA8,0x0C,
  42136. 0x20,0xA8,0x7C,0xF9,0xF7,0x53,0xC1,0xB4,
  42137. 0xC0,0x5D,0x06,0x45,0xDD,0x7E,0xA7,0x34,
  42138. 0xA1,0x21,0xC2,0x62,0xAB,0x22,0x45,0x3D,
  42139. 0x73,0x4C,0x26,0xD1,0x1A,0xB2,0xF0,0xB2,
  42140. 0x6D,0x11,0x70,0x58,0xAA,0xF5,0xA4,0xF5,
  42141. 0xF8,0x0B,0x3D,0xC1,0xF6,0x17,0x70,0x15,
  42142. 0xCD,0x72,0x02,0x7E,0x4E,0x94,0x96,0x0A,
  42143. 0x56,0xCC,0xA5,0xA3,0xB3,0x7E,0xDD,0x5A,
  42144. 0x72,0xD2,0xFB,0xAC,0x3D,0x0E,0x66,0x65,
  42145. 0xE9,0x08,0x6C,0xB0,0x1C,0xE2,0x1A,0x82,
  42146. 0xF6,0xF3,0x34,0x89,0x73,0x02,0x5B,0x42,
  42147. 0x6D,0x40,0x61,0xB6,0xE0,0xE6,0x53,0x32,
  42148. 0xA5,0x72,0x17,0x4F,0x3B,0x51,0x4F,0xBC,
  42149. 0x00,0xE0,0x69,0x26,0xA9,0xAE,0x83,0xE3,
  42150. 0x73,0x7F,0x71,0x97,0xE0,0xDC,0x7C,0x63,
  42151. 0x9C,0x85,0x5F,0xDF,0x7D,0xE4,0x6C,0xD8,
  42152. 0xA9,0x3A,0x6F,0x5E,0x4A,0x2E,0xB0,0xE7,
  42153. 0x8B,0x45,0xE2,0x90,0x05,0x37,0xE8,0xAB,
  42154. 0x49,0x48,0x4C,0xC0,0x59,0x1D,0x8C,0x46,
  42155. 0x5B,0x84,0xE0,0x83,0xCE,0xEA,0x4B,0xF9,
  42156. 0xD4,0xDC,0x63,0xDF,0x79,0xB7,0x5C,0x11,
  42157. 0x25,0x7F,0x90,0x2E,0x0A,0x38,0x03,0xEA,
  42158. 0xEA,0xA1,0x26,0x52,0x20,0x19,0xA3,0xBE,
  42159. 0xFC,0x9D,0xB7,0x6E,0xA6,0x58,0x8E,0x6D,
  42160. 0xC5,0x58,0xE9,0xED,0x2F,0x55,0x43,0x8B,
  42161. 0x03,0x8B,0xE6,0xA4,0xC2,0x25,0x4B,0x36,
  42162. 0xBA,0xD3,0x27,0x48,0x40,0x2E,0x87,0xA2,
  42163. 0xD4,0x12,0xC6,0x05,0x36,0x03,0x11,0x51,
  42164. 0xD1,0xF2,0xAC,0x71,0x2C,0xB6,0xC3,0xA5,
  42165. 0x57,0x0F,0xAF,0x4B,0xBD,0xCD,0x47,0x4C,
  42166. 0x3A,0x52,0x6F,0x47,0xE7,0x0B,0xB7,0xD5,
  42167. 0xF7,0xA6,0x39,0x63,0x82,0x08,0x4C,0x41,
  42168. 0x0E,0x2A,0x52,0x42,0x5A,0xEA,0x59,0xC7,
  42169. 0x94,0xFB,0xD0,0x88,0x47,0x27,0xF6,0x97,
  42170. 0x03,0x9E,0x29,0xB8,0x3A,0x67,0xE6,0xF3,
  42171. 0x95,0xA7,0x42,0xC1,0x96,0xD1,0x9A,0xA6,
  42172. 0xF0,0x09,0x0C,0xEA,0xE0,0xAB,0x0F,0x15,
  42173. 0xE9,0xC3,0xEB,0xA5,0x89,0x86,0x98,0x32,
  42174. 0x83,0xAB,0x30,0x33,0xAE,0x90,0x8D,0x2E,
  42175. 0xB3,0xAA,0x91,0xA6,0xD9,0xA4,0x4A,0x54,
  42176. 0xE0,0xD3,0x08,0xCC,0x79,0xCE,0xE4,0x15,
  42177. 0x31,0xA6,0xCE,0x61,0xCF,0x03,0x06,0xEE,
  42178. 0x8E,0xE2,0x64,0x29,0xD1,0x54,0x9B,0xD0,
  42179. 0x5F,0x09,0x2B,0x8B,0xD5,0xF8,0xD4,0x7D,
  42180. 0xF1,0x97,0x32,0xD9,0xEA,0x5A,0x0E,0x10,
  42181. 0x8C,0x4D,0xFB,0x55,0xE6,0x27,0x0C,0xBA,
  42182. 0xC1,0x73,0xC1,0x73,0xE3,0x1C,0x09,0xB3,
  42183. 0x6F,0xB4,0x12,0xFA,0xF3,0x29,0xDC,0x23,
  42184. 0x32,0xED,0x80,0x87,0x83,0xC2,0xF6,0x07,
  42185. 0xB5,0xA9,0x22,0xDE,0x66,0x1A,0xA7,0x4A,
  42186. 0x86,0xF1,0x39,0x9B,0xF4,0xE7,0x50,0x15,
  42187. 0x4A,0x55,0x3C,0x93,0xB9,0xF9,0xFD,0xDC,
  42188. 0xB3,0x5D,0x73,0x52
  42189. };
  42190. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void)
  42191. {
  42192. XmssKey verifyKey;
  42193. unsigned char pub_raw[XMSS_SHA256_PUBLEN];
  42194. word32 pub_len = sizeof(pub_raw);
  42195. word32 pkSz = 0;
  42196. word32 sigSz = 0;
  42197. const char * param = "XMSS-SHA2_10_256";
  42198. int j = 0;
  42199. int ret2 = WC_TEST_RET_ENC_NC;
  42200. int ret = WC_TEST_RET_ENC_NC;
  42201. int n_diff = 0;
  42202. WOLFSSL_ENTER("xmss_test_verify_only");
  42203. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42204. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42205. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42206. ret = wc_XmssKey_SetParamStr(&verifyKey, param);
  42207. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42208. ret = wc_XmssKey_GetPubLen(&verifyKey, &pkSz);
  42209. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42210. if (pkSz != XMSS_SHA256_PUBLEN) {
  42211. return WC_TEST_RET_ENC_EC(pkSz);
  42212. }
  42213. ret = wc_XmssKey_GetSigLen(&verifyKey, &sigSz);
  42214. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42215. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  42216. fprintf(stderr, "param: %s\n", param);
  42217. fprintf(stderr, "pkSz: %d\n", pkSz);
  42218. fprintf(stderr, "sigSz: %d\n", sigSz);
  42219. #endif
  42220. if (sigSz != sizeof(xmss_sig)) {
  42221. return WC_TEST_RET_ENC_EC(sigSz);
  42222. }
  42223. ret = wc_XmssKey_ImportPubRaw(&verifyKey, xmss_pub, XMSS_SHA256_PUBLEN);
  42224. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42225. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42226. (byte *) xmss_msg, sizeof(xmss_msg));
  42227. if (ret != 0) {
  42228. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  42229. return WC_TEST_RET_ENC_EC(ret);
  42230. }
  42231. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42232. ret = wc_XmssKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42233. if (ret != 0) {
  42234. printf("error: wc_XmssKey_ExportPubRaw returned %d, expected 0\n", ret);
  42235. return WC_TEST_RET_ENC_EC(ret);
  42236. }
  42237. if (pub_len != XMSS_SHA256_PUBLEN) {
  42238. printf("error: xmss pub len %u, expected %d\n", pub_len,
  42239. XMSS_SHA256_PUBLEN);
  42240. return WC_TEST_RET_ENC_EC(pub_len);
  42241. }
  42242. n_diff = XMEMCMP(pub_raw, xmss_pub, sizeof(xmss_pub));
  42243. if (n_diff != 0) {
  42244. printf("error: exported and imported pub raw do not match: %d\n",
  42245. n_diff);
  42246. return WC_TEST_RET_ENC_EC(n_diff);
  42247. }
  42248. /* Flip bits in message. This should fail. */
  42249. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  42250. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42251. (byte *) xmss_msg, sizeof(xmss_msg));
  42252. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42253. printf("error: wc_XmssKey_Verify returned %d, expected -1\n", ret2);
  42254. return WC_TEST_RET_ENC_EC(ret2);
  42255. }
  42256. /* Flip it back. This should pass again. */
  42257. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  42258. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42259. (byte *) xmss_msg, sizeof(xmss_msg));
  42260. if (ret != 0) {
  42261. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  42262. return WC_TEST_RET_ENC_EC(ret);
  42263. }
  42264. /* Flip bits in a few places throughout the signature, stepping in multiple
  42265. * of hash size. These should all fail with -1. */
  42266. for (j = 0; j < (int) sizeof(xmss_sig); j+= 4 * 32) {
  42267. xmss_sig[j] ^= 1;
  42268. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42269. (byte *) xmss_msg, sizeof(xmss_msg));
  42270. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42271. /* Verify passed when it should have failed. */
  42272. return WC_TEST_RET_ENC_I(j);
  42273. }
  42274. /* Flip this spot back. */
  42275. xmss_sig[j] ^= 1;
  42276. }
  42277. /* Cleanup everything. */
  42278. wc_XmssKey_Free(&verifyKey);
  42279. return ret;
  42280. }
  42281. #endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_SMALL_STACK &&
  42282. * WOLFSSL_XMSS_MIN_HEIGHT <= 10 */
  42283. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  42284. static int lms_write_key_mem(const byte * priv, word32 privSz, void *context)
  42285. {
  42286. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  42287. * BE USED FOR TESTING PURPOSES! Production applications should
  42288. * write only to non-volatile storage. */
  42289. XMEMCPY(context, priv, privSz);
  42290. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  42291. }
  42292. static int lms_read_key_mem(byte * priv, word32 privSz, void *context)
  42293. {
  42294. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  42295. * BE USED FOR TESTING PURPOSES! */
  42296. XMEMCPY(priv, context, privSz);
  42297. return WC_LMS_RC_READ_TO_MEMORY;
  42298. }
  42299. /* LMS signature sizes are a function of their parameters. This
  42300. * test has a signature of 8688 bytes. */
  42301. #ifndef WOLFSSL_NO_LMS_SHA256_256
  42302. #define WC_TEST_LMS_SIG_LEN (8688)
  42303. #else
  42304. #define WC_TEST_LMS_SIG_LEN (4984)
  42305. #endif
  42306. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
  42307. {
  42308. int i = 0;
  42309. int j = 0;
  42310. int ret = WC_TEST_RET_ENC_NC;
  42311. int ret2 = WC_TEST_RET_ENC_NC;
  42312. int sigsLeft = 0;
  42313. LmsKey signingKey;
  42314. LmsKey verifyKey;
  42315. WC_RNG rng;
  42316. word32 sigSz = 0;
  42317. const char * msg = "LMS HSS post quantum signature test";
  42318. word32 msgSz = (word32) XSTRLEN(msg);
  42319. unsigned char priv[HSS_MAX_PRIVATE_KEY_LEN];
  42320. unsigned char old_priv[HSS_MAX_PRIVATE_KEY_LEN];
  42321. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42322. byte * sig = (byte*)XMALLOC(WC_TEST_LMS_SIG_LEN, HEAP_HINT,
  42323. DYNAMIC_TYPE_TMP_BUFFER);
  42324. if (sig == NULL) {
  42325. return WC_TEST_RET_ENC_ERRNO;
  42326. }
  42327. #else
  42328. byte sig[WC_TEST_LMS_SIG_LEN];
  42329. #endif
  42330. WOLFSSL_ENTER("lms_test");
  42331. XMEMSET(priv, 0, sizeof(priv));
  42332. XMEMSET(old_priv, 0, sizeof(old_priv));
  42333. XMEMSET(sig, 0, WC_TEST_LMS_SIG_LEN);
  42334. #ifndef HAVE_FIPS
  42335. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  42336. #else
  42337. ret = wc_InitRng(&rng);
  42338. #endif
  42339. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42340. /* This test:
  42341. * levels: 1
  42342. * height: 5
  42343. * winternitz: 1
  42344. *
  42345. * max sigs: 2 ** (1 * 5) = 32
  42346. * signature length: 8688
  42347. */
  42348. ret = wc_LmsKey_Init(&signingKey, NULL, INVALID_DEVID);
  42349. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42350. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42351. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42352. ret = wc_LmsKey_SetParameters(&signingKey, 1, 5, 1);
  42353. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42354. ret = wc_LmsKey_SetWriteCb(&signingKey, lms_write_key_mem);
  42355. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42356. ret = wc_LmsKey_SetReadCb(&signingKey, lms_read_key_mem);
  42357. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42358. ret = wc_LmsKey_SetContext(&signingKey, (void *) priv);
  42359. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42360. ret = wc_LmsKey_MakeKey(&signingKey, &rng);
  42361. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42362. XMEMCPY(old_priv, priv, sizeof(priv));
  42363. ret = wc_LmsKey_ExportPub(&verifyKey, &signingKey);
  42364. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42365. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42366. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42367. if (sigSz != WC_TEST_LMS_SIG_LEN) {
  42368. printf("error: got %u, expected %d\n", sigSz, WC_TEST_LMS_SIG_LEN);
  42369. return WC_TEST_RET_ENC_EC(sigSz);
  42370. }
  42371. /* 2 ** 5 should be the max number of signatures */
  42372. for (i = 0; i < 32; ++i) {
  42373. /* We should have remaining signstures. */
  42374. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42375. if (sigsLeft == 0) {
  42376. return WC_TEST_RET_ENC_EC(sigsLeft);
  42377. }
  42378. /* Sign with key. The private key will be updated on every signature. */
  42379. ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  42380. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42381. /* The updated private key should not match the old one. */
  42382. if (XMEMCMP(old_priv, priv, sizeof(priv)) == 0) {
  42383. printf("error: current priv key should not match old: %d\n", i);
  42384. return WC_TEST_RET_ENC_I(i);
  42385. }
  42386. XMEMCPY(old_priv, priv, sizeof(priv));
  42387. ret = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  42388. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42389. /* Flip bits in a few places throughout the signature, stepping in multiple
  42390. * of hash size. These should all fail with -1. */
  42391. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42392. sig[j] ^= 1;
  42393. ret2 = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  42394. msgSz);
  42395. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42396. /* Verify passed when it should have failed. */
  42397. return WC_TEST_RET_ENC_I(j);
  42398. }
  42399. /* Flip this spot back. */
  42400. sig[j] ^= 1;
  42401. }
  42402. }
  42403. /* This should be the last signature. */
  42404. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42405. if (sigsLeft != 0) {
  42406. return WC_TEST_RET_ENC_EC(sigsLeft);
  42407. }
  42408. wc_LmsKey_Free(&signingKey);
  42409. wc_LmsKey_Free(&verifyKey);
  42410. wc_FreeRng(&rng);
  42411. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42412. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42413. #endif
  42414. return ret;
  42415. }
  42416. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  42417. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK)
  42418. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  42419. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  42420. /* A simple LMS verify only test.
  42421. *
  42422. * Note: LMS signature sizes are a function of their parameters. This
  42423. * test has a signature of 1456 bytes:
  42424. * levels: 1
  42425. * height: 10
  42426. * winternitz: 8
  42427. * max sigs: 2 ** (1 * 10) = 1024
  42428. * signature length: 1456
  42429. * */
  42430. /* "wolfSSL LMS example message!" without null terminator. */
  42431. static byte lms_msg[28] =
  42432. {
  42433. 0x77,0x6F,0x6C,0x66,0x53,0x53,0x4C,0x20,
  42434. 0x4C,0x4D,0x53,0x20,0x65,0x78,0x61,0x6D,
  42435. 0x70,0x6C,0x65,0x20,0x6D,0x65,0x73,0x73,
  42436. 0x61,0x67,0x65,0x21
  42437. };
  42438. static const byte lms_L1H10W8_pub[HSS_MAX_PUBLIC_KEY_LEN] =
  42439. {
  42440. 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,
  42441. 0x00,0x00,0x00,0x04,0xA1,0x26,0x76,0xF8,
  42442. 0xBB,0x0B,0xC0,0x82,0x21,0x71,0x0B,0x2E,
  42443. 0x8C,0xA6,0xEF,0x12,0xED,0x41,0x0E,0x8C,
  42444. 0xAF,0x11,0x93,0x34,0x7B,0x49,0x79,0xB7,
  42445. 0xDE,0x63,0x1C,0xFE,0x1F,0xD1,0x17,0x49,
  42446. 0xCD,0x5C,0xD4,0x26,0xA0,0x53,0x26,0x1A,
  42447. 0xC5,0xB4,0x8F,0x23
  42448. };
  42449. #define LMS_L1H10W8_SIGLEN (1456)
  42450. static byte lms_L1H10W8_sig[LMS_L1H10W8_SIGLEN] =
  42451. {
  42452. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  42453. 0x00,0x00,0x00,0x04,0x18,0x70,0x09,0x2E,
  42454. 0x21,0xC9,0x6A,0xC9,0x5C,0xB6,0xB0,0xAA,
  42455. 0xC3,0xED,0x6E,0x66,0x2F,0xCC,0x45,0x81,
  42456. 0xBC,0xBA,0x44,0x96,0x1C,0xBF,0x4E,0xFB,
  42457. 0x7A,0x46,0xFB,0xBE,0x9A,0x0C,0xE4,0x50,
  42458. 0x90,0xC7,0x92,0xAC,0x53,0xAE,0x53,0x76,
  42459. 0x29,0xA6,0x65,0xF1,0x09,0xED,0x1A,0x8E,
  42460. 0x03,0x2E,0x5A,0x06,0x51,0xE3,0x1E,0xE6,
  42461. 0xF6,0xFE,0x3A,0x6E,0xD1,0x92,0x31,0x1D,
  42462. 0xA1,0x6A,0x5C,0x30,0x3A,0xC7,0xFD,0x5B,
  42463. 0xFE,0x71,0x2C,0x5C,0x2F,0x5B,0x5B,0xCF,
  42464. 0xBC,0x7F,0xBF,0x6C,0xAF,0x44,0x8A,0xAE,
  42465. 0x14,0x60,0xAB,0x88,0xED,0x0E,0x4F,0xF8,
  42466. 0xC7,0x1B,0x74,0x28,0x72,0xB3,0x96,0xA6,
  42467. 0xE6,0x46,0x22,0x82,0xCF,0x1F,0x4D,0xA6,
  42468. 0xEA,0x22,0x06,0x07,0x52,0xF5,0x26,0x16,
  42469. 0x0B,0x90,0xE3,0xFF,0x64,0xA9,0xE4,0x61,
  42470. 0x1E,0x9C,0x12,0x9C,0xF6,0xD4,0x63,0x29,
  42471. 0xEA,0x02,0xF7,0x18,0x52,0x79,0x6C,0x43,
  42472. 0xDC,0xCF,0x43,0x23,0xB9,0xCC,0x4A,0x25,
  42473. 0x9D,0x10,0xAF,0xA3,0xE6,0x47,0x5A,0x1C,
  42474. 0xFE,0x68,0x89,0xAF,0x1B,0x2D,0x88,0x3E,
  42475. 0xCA,0xDC,0x70,0xEA,0xAC,0x11,0x00,0x8A,
  42476. 0x6E,0xE0,0xC7,0xD0,0xD2,0x1A,0x36,0x18,
  42477. 0x97,0xB3,0x5F,0x0E,0x75,0x48,0x28,0xF8,
  42478. 0xA8,0xF5,0x90,0xD1,0xA1,0x84,0xFB,0xA4,
  42479. 0xAD,0x50,0xBE,0xE9,0x39,0x8C,0xC5,0xA1,
  42480. 0x67,0x51,0xA1,0x8C,0xD6,0x6B,0x97,0x1F,
  42481. 0x47,0x99,0xEE,0xE0,0x70,0x01,0xC7,0x07,
  42482. 0x50,0xF3,0x5E,0x3F,0xE7,0x06,0xD6,0x8D,
  42483. 0x26,0xD6,0x5A,0x59,0x18,0x72,0x6B,0x12,
  42484. 0xD2,0xAF,0x9B,0xB4,0x2B,0xD0,0xB2,0xF2,
  42485. 0x96,0x2F,0x40,0xEA,0xBE,0xE6,0xAC,0x1F,
  42486. 0xB8,0x33,0xC2,0x76,0xDC,0x8C,0xAC,0xC1,
  42487. 0x46,0x5E,0x04,0x84,0x1B,0xC8,0xB9,0x65,
  42488. 0x8D,0xAD,0x96,0xB5,0xB1,0xF6,0x17,0x4A,
  42489. 0x19,0x87,0xE7,0xBF,0x29,0xC7,0x9B,0xB9,
  42490. 0xD6,0x11,0x2C,0x92,0x2F,0xB7,0x24,0xD5,
  42491. 0x01,0x1D,0x80,0x37,0x54,0xED,0x33,0x32,
  42492. 0xAB,0x7A,0x12,0xD4,0x02,0x1D,0x27,0x52,
  42493. 0x89,0xDB,0x32,0xBF,0x61,0xD4,0xBB,0xB4,
  42494. 0x46,0x78,0x1B,0x64,0x17,0x84,0x4B,0x8A,
  42495. 0xBA,0xC6,0xC1,0xCF,0xC7,0x5D,0x8F,0x93,
  42496. 0xC5,0x9A,0x27,0x90,0xAC,0x17,0x98,0xFF,
  42497. 0xC8,0x22,0x59,0x55,0x90,0xB2,0x29,0x39,
  42498. 0xA0,0xBE,0x00,0x23,0x55,0x6B,0xDA,0x83,
  42499. 0xD8,0x5B,0x57,0x7C,0x67,0x1B,0xC3,0x6B,
  42500. 0x6D,0xC7,0x9B,0x2B,0x9E,0xB7,0x95,0xB3,
  42501. 0xF0,0x1B,0x89,0x5A,0xD7,0x4B,0x67,0xAF,
  42502. 0xDC,0x9E,0xCF,0x7E,0x1A,0xBA,0x1B,0xB9,
  42503. 0x3B,0x7A,0xDD,0x3F,0x0D,0xEE,0x4C,0x0B,
  42504. 0xD1,0x4F,0x34,0xF2,0x93,0xF7,0x21,0x64,
  42505. 0x2C,0x07,0x00,0x15,0x4F,0xE3,0x6A,0x9F,
  42506. 0x08,0x52,0xC2,0x65,0x47,0x1F,0x34,0x64,
  42507. 0x66,0x07,0xBC,0xEA,0xAF,0x9B,0xAA,0x39,
  42508. 0x15,0x8B,0x08,0x8C,0x24,0x41,0x9B,0x46,
  42509. 0x1B,0x5B,0x91,0x11,0xC4,0xFD,0xA9,0x88,
  42510. 0x35,0x0E,0x7D,0xAF,0xFD,0xB7,0x90,0x7E,
  42511. 0xD7,0x29,0x02,0x0A,0xDC,0xC8,0x3F,0xC0,
  42512. 0xFD,0x97,0xAF,0x50,0x49,0xA6,0x5E,0x12,
  42513. 0xC1,0xCD,0xEC,0x52,0xC5,0x51,0xF2,0x80,
  42514. 0x17,0x61,0xC7,0x7E,0xBE,0xD1,0x1B,0x65,
  42515. 0xA4,0xAB,0x92,0x8D,0x89,0xB2,0xC5,0x8F,
  42516. 0xFF,0xA5,0x6F,0xFA,0x62,0x75,0xE4,0xA1,
  42517. 0xD4,0x22,0xA8,0x9E,0x40,0x04,0x27,0x1F,
  42518. 0xCC,0x81,0xBA,0x28,0x67,0xA0,0x1C,0x80,
  42519. 0xEB,0xCA,0xB0,0x61,0xA5,0x48,0xD0,0x8A,
  42520. 0x25,0xEB,0x9E,0x67,0x8C,0x8E,0x9B,0xD1,
  42521. 0xAD,0xBB,0xC3,0xEA,0xD3,0xD4,0xC5,0x12,
  42522. 0x7B,0xDD,0x00,0x57,0x7F,0xF6,0xF7,0xF6,
  42523. 0x3C,0x05,0xCF,0xFC,0x12,0xE1,0x93,0x05,
  42524. 0xE5,0x9B,0x79,0x87,0x69,0xD8,0x82,0xD9,
  42525. 0xD7,0x1D,0x41,0x73,0xE4,0x52,0x1D,0x3E,
  42526. 0xE5,0x8C,0x8D,0x34,0xE1,0x75,0xA9,0xF1,
  42527. 0x9D,0x09,0xA2,0x5B,0xEF,0xDA,0x96,0x6E,
  42528. 0x76,0x3D,0xEA,0x50,0xD9,0xCF,0x4F,0xAC,
  42529. 0xAD,0x1D,0x35,0x72,0x1B,0x88,0x8B,0xCD,
  42530. 0x8C,0x8A,0x8A,0xE0,0x96,0x04,0xD8,0xBB,
  42531. 0x28,0x43,0x16,0x77,0x60,0x98,0x63,0xF9,
  42532. 0xB9,0x71,0x46,0xB7,0xE1,0xA7,0xA9,0x84,
  42533. 0xC3,0x65,0x82,0xE1,0x1B,0x67,0x04,0x2D,
  42534. 0x55,0x6B,0xF9,0xC0,0x79,0x09,0x09,0xE7,
  42535. 0xFD,0x06,0x4D,0x09,0x9B,0x1A,0xCE,0x35,
  42536. 0xFA,0x27,0x6F,0x2F,0x01,0x65,0x0D,0xA0,
  42537. 0x97,0x59,0x11,0xF0,0x48,0xD2,0xE7,0x46,
  42538. 0xBE,0xB4,0x0A,0xA3,0xE2,0x75,0x0E,0x09,
  42539. 0x94,0xD9,0x69,0x28,0xD4,0xDA,0x64,0xBA,
  42540. 0xFE,0xA4,0xB9,0xF0,0xBA,0xEB,0xBA,0xAC,
  42541. 0xA8,0xF9,0xD3,0x82,0x4C,0x36,0x80,0xFA,
  42542. 0xE5,0xF6,0x76,0xC3,0x80,0xFA,0x90,0x29,
  42543. 0xF4,0x85,0xA4,0xC6,0x25,0x22,0x79,0x7E,
  42544. 0x39,0x1E,0x30,0xB8,0x65,0x72,0xCF,0xE1,
  42545. 0x99,0xF0,0x75,0xE8,0x09,0xB4,0x92,0x96,
  42546. 0x1B,0x68,0x50,0x88,0xF1,0x2C,0x97,0xE3,
  42547. 0x2D,0x26,0x8F,0xC5,0x30,0xCF,0x24,0xCB,
  42548. 0xB2,0x60,0x77,0xDC,0x02,0x72,0x0D,0xD9,
  42549. 0x2E,0xF2,0x52,0xEA,0x00,0xF6,0x32,0x65,
  42550. 0xA5,0xC6,0x43,0x29,0x29,0x69,0xAB,0x27,
  42551. 0x0C,0x39,0xDF,0x76,0x3E,0x93,0x95,0xB1,
  42552. 0x2C,0xA2,0x0D,0x18,0xCE,0xA0,0x97,0x10,
  42553. 0x3C,0x90,0xC0,0xEF,0x0E,0x04,0xA6,0xC8,
  42554. 0xA0,0x21,0x3C,0x0B,0x22,0x77,0x7A,0x66,
  42555. 0xA5,0x90,0x25,0xA4,0x09,0x3E,0xD5,0x27,
  42556. 0x1F,0x6C,0x99,0x85,0x5C,0xA2,0x99,0x7A,
  42557. 0x25,0xEE,0x8D,0x32,0x3D,0xD3,0xDC,0xF5,
  42558. 0x00,0x5A,0x34,0x61,0xB6,0xCD,0x4E,0xBC,
  42559. 0x26,0x36,0xFB,0x44,0x97,0x35,0xBD,0x06,
  42560. 0x7D,0x2E,0x4A,0xA2,0xDC,0x24,0xFE,0x70,
  42561. 0x0A,0xF9,0x57,0xE3,0xEE,0xAB,0xD1,0x17,
  42562. 0xF3,0x7C,0xD6,0x37,0x26,0xFA,0x83,0x9F,
  42563. 0xDD,0xB2,0xE1,0xD7,0xF9,0xC7,0x0E,0x15,
  42564. 0x01,0xA6,0x58,0x32,0x98,0x04,0x32,0xD4,
  42565. 0xDE,0xB9,0xEF,0x09,0xFA,0xE4,0x5A,0xD7,
  42566. 0xDD,0x09,0x1C,0xC9,0xAC,0xB8,0x6A,0xF5,
  42567. 0x00,0x5D,0x6B,0x95,0x12,0x8C,0x2F,0xCC,
  42568. 0xD8,0xB9,0x50,0x3A,0xEB,0x74,0x86,0xD2,
  42569. 0x3F,0xA1,0x05,0x8F,0x6E,0xEF,0xF5,0xA4,
  42570. 0xD6,0x6E,0x53,0xFA,0x9E,0xFA,0xCE,0xDB,
  42571. 0x99,0x46,0xE7,0xC5,0xDA,0x92,0x51,0x4F,
  42572. 0x22,0x07,0xF3,0xA5,0x38,0x26,0xD3,0xEC,
  42573. 0xD6,0x01,0xDD,0x31,0x3A,0x48,0x93,0xF6,
  42574. 0x69,0x4F,0xD8,0xF6,0xC2,0x91,0xA5,0x7C,
  42575. 0xDF,0x51,0x64,0xF1,0x3B,0x79,0xBC,0x0A,
  42576. 0x2C,0xDC,0x33,0x5A,0x29,0xF6,0xB2,0x09,
  42577. 0x66,0xCA,0x24,0x9F,0x1A,0x18,0xF3,0x76,
  42578. 0x4C,0x5E,0x0B,0x81,0x7F,0x29,0x84,0xD8,
  42579. 0x7A,0xA8,0xD6,0x11,0xAC,0xEC,0xD9,0x07,
  42580. 0x91,0xEC,0xB6,0x6D,0xEC,0xDB,0xBE,0x6F,
  42581. 0x9F,0xC5,0x19,0x5E,0x56,0x87,0x20,0x80,
  42582. 0x75,0xD5,0x64,0xE9,0x80,0xBF,0x2D,0xD5,
  42583. 0x94,0x9F,0x8C,0xA4,0x54,0x41,0xAB,0xB1,
  42584. 0x8E,0xAD,0x51,0xE4,0x3C,0x24,0xF7,0x1D,
  42585. 0xFE,0x02,0x48,0x7C,0x6D,0xED,0xF1,0xAC,
  42586. 0xD9,0x79,0x42,0xE5,0x3A,0xCF,0x6A,0x4C,
  42587. 0x6D,0xE2,0x13,0xD2,0x2B,0x9D,0xAB,0x1F,
  42588. 0x70,0xD3,0xC0,0x6F,0x81,0xE9,0x9A,0x86,
  42589. 0x33,0x39,0x60,0xE7,0x6A,0x00,0x1F,0x97,
  42590. 0xEB,0xE5,0x1D,0x0D,0x66,0x15,0xC9,0xA2,
  42591. 0xB1,0xC0,0xF0,0x2E,0xF4,0x07,0xA2,0x2E,
  42592. 0x49,0x92,0x95,0x13,0xA3,0x18,0x46,0x25,
  42593. 0xB9,0x3C,0xA1,0x4B,0x00,0x00,0x00,0x06,
  42594. 0xAB,0xAA,0xF9,0x3F,0x7E,0x21,0xF4,0x0E,
  42595. 0xCE,0xFD,0xE0,0x44,0xAC,0xC7,0x1A,0x30,
  42596. 0x22,0x9D,0x0A,0xD7,0x96,0x2D,0x8F,0x9A,
  42597. 0x99,0x1F,0x40,0x75,0x7F,0x62,0xF9,0xC1,
  42598. 0x81,0x7B,0x4A,0x1B,0xFA,0xD6,0x87,0xB9,
  42599. 0xEF,0x58,0x48,0xE4,0x5C,0x79,0xE5,0xB1,
  42600. 0x2C,0x59,0xA4,0x42,0xDB,0xA6,0x53,0x70,
  42601. 0x80,0x61,0x17,0xD4,0xD3,0x77,0xBD,0x53,
  42602. 0x26,0x7C,0x0E,0x0E,0xFF,0x30,0x4B,0xD0,
  42603. 0x86,0xFC,0x02,0x20,0x24,0x46,0x5B,0xF5,
  42604. 0xE3,0x99,0x73,0x85,0x60,0x00,0x36,0x47,
  42605. 0x17,0xEE,0x0C,0xD2,0x80,0x71,0x46,0x0E,
  42606. 0x2B,0xB0,0xEF,0x7F,0xFE,0x3B,0xE5,0xE1,
  42607. 0x87,0xC2,0xAF,0x1A,0x6F,0x63,0xF4,0x5A,
  42608. 0xC4,0x16,0xF7,0xAD,0x07,0x70,0x71,0x85,
  42609. 0x7D,0x3D,0x67,0x08,0xB8,0xD8,0xE2,0xF0,
  42610. 0xA1,0xAC,0xD2,0x94,0x7D,0x93,0x03,0xDD,
  42611. 0x54,0xF9,0x64,0x19,0xB3,0xED,0x24,0x22,
  42612. 0x01,0xD7,0x12,0x5E,0xC1,0x2B,0x39,0x10,
  42613. 0x13,0xE2,0x56,0x1C,0xEE,0xF4,0x2A,0x49,
  42614. 0x7B,0xFB,0x36,0x8D,0xF8,0xAF,0x60,0xDF,
  42615. 0x10,0xF0,0x72,0xA2,0xED,0xB6,0x53,0x88,
  42616. 0xA9,0x0C,0xED,0x9C,0x18,0x33,0x7D,0x65,
  42617. 0x9B,0xB2,0x9C,0x3E,0xE9,0x1E,0x43,0x51,
  42618. 0x7E,0xBE,0x01,0x95,0xF6,0x60,0x65,0xBE,
  42619. 0xD1,0xF4,0xE2,0x83,0x6B,0xCA,0x7A,0x70,
  42620. 0x41,0x83,0x72,0xC0,0x23,0x51,0x13,0x11,
  42621. 0x2D,0xF9,0xC0,0x0D,0x7D,0x73,0x76,0xA5,
  42622. 0x30,0x83,0x68,0x10,0x35,0xA2,0x18,0x22,
  42623. 0x4E,0x21,0x93,0x27,0x6A,0x19,0x28,0x83,
  42624. 0x7F,0xDD,0xDD,0xFF,0xC3,0x8A,0x64,0x00,
  42625. 0x5F,0x1C,0x0D,0xF8,0xBB,0xD7,0x15,0xB9,
  42626. 0xEF,0xE0,0x07,0x62,0x05,0x9E,0xCF,0xFC,
  42627. 0x08,0x52,0x1E,0x65,0x41,0x56,0x6A,0xEB,
  42628. 0x81,0x53,0x30,0x7B,0xF2,0xFD,0x65,0xFF,
  42629. 0xA2,0x14,0xF5,0x62,0x1E,0x24,0x48,0x47,
  42630. 0xA5,0x41,0x80,0xB4,0xC5,0xDC,0xB2,0xB4,
  42631. 0x2D,0x17,0xE7,0xBE,0x49,0x53,0x7A,0x25,
  42632. 0xC5,0x0D,0x19,0x59,0xF4,0x88,0x59,0xED,
  42633. 0x92,0x13,0xEE,0x7A,0x4F,0x12,0x98,0x4C
  42634. };
  42635. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
  42636. {
  42637. LmsKey verifyKey;
  42638. unsigned char pub_raw[HSS_MAX_PUBLIC_KEY_LEN];
  42639. word32 pub_len = sizeof(pub_raw);
  42640. word32 sigSz = 0;
  42641. word32 msgSz = sizeof(lms_msg);
  42642. word32 pubSz = 0;
  42643. int levels = 0;
  42644. int height = 0;
  42645. int winternitz = 0;
  42646. int ret = WC_TEST_RET_ENC_NC;
  42647. int ret2 = WC_TEST_RET_ENC_NC;
  42648. int j = 0;
  42649. int n_diff = 0;
  42650. WOLFSSL_ENTER("lms_test_verify_only");
  42651. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42652. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42653. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42654. ret = wc_LmsKey_SetParameters(&verifyKey, 1, 10, 8);
  42655. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42656. ret = wc_LmsKey_ImportPubRaw(&verifyKey, lms_L1H10W8_pub,
  42657. HSS_MAX_PUBLIC_KEY_LEN);
  42658. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42659. /* Verify parameters, pub length, and sig length are correct. */
  42660. ret = wc_LmsKey_GetParameters(&verifyKey, &levels, &height, &winternitz);
  42661. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42662. if (levels != 1 || height != 10 || winternitz != 8) {
  42663. printf("error: invalid LMS parameters: L%d-H%d-W%d\n", levels, height,
  42664. winternitz);
  42665. return WC_TEST_RET_ENC_NC;
  42666. }
  42667. ret = wc_LmsKey_GetPubLen(&verifyKey, &pubSz);
  42668. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42669. if (pubSz != HSS_MAX_PUBLIC_KEY_LEN) {
  42670. printf("error: got %u, expected %d\n", pubSz, HSS_MAX_PUBLIC_KEY_LEN);
  42671. return WC_TEST_RET_ENC_EC(pubSz);
  42672. }
  42673. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42674. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42675. if (sigSz != LMS_L1H10W8_SIGLEN) {
  42676. printf("error: got %u, expected %d\n", sigSz, LMS_L1H10W8_SIGLEN);
  42677. return WC_TEST_RET_ENC_EC(sigSz);
  42678. }
  42679. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42680. (byte *) lms_msg, msgSz);
  42681. if (ret != 0) {
  42682. printf("error: wc_LmsKey_Verify returned %d\n", ret);
  42683. return WC_TEST_RET_ENC_EC(ret);
  42684. }
  42685. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42686. ret = wc_LmsKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42687. if (ret != 0) {
  42688. printf("error: wc_LmsKey_ExportPubRaw returned %d, expected 0\n", ret);
  42689. return WC_TEST_RET_ENC_EC(ret);
  42690. }
  42691. if (pub_len != HSS_MAX_PUBLIC_KEY_LEN) {
  42692. printf("error: LMS pub len %u, expected %d\n", pub_len,
  42693. HSS_MAX_PUBLIC_KEY_LEN);
  42694. return WC_TEST_RET_ENC_EC(pub_len);
  42695. }
  42696. n_diff = XMEMCMP(pub_raw, lms_L1H10W8_pub, sizeof(lms_L1H10W8_pub));
  42697. if (n_diff != 0) {
  42698. printf("error: exported and imported pub raw do not match: %d\n",
  42699. n_diff);
  42700. return WC_TEST_RET_ENC_EC(n_diff);
  42701. }
  42702. /* Flip bits in message. This should fail. */
  42703. lms_msg[msgSz / 2] ^= 1;
  42704. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42705. (byte *) lms_msg, msgSz);
  42706. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42707. printf("error: wc_LmsKey_Verify returned %d, expected -1\n", ret2);
  42708. return WC_TEST_RET_ENC_EC(ret);
  42709. }
  42710. /* Flip it back. This should pass again. */
  42711. lms_msg[msgSz / 2] ^= 1;
  42712. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42713. (byte *) lms_msg, msgSz);
  42714. if (ret != 0) {
  42715. printf("error: wc_LmsKey_Verify returned %d, expected 0\n", ret);
  42716. return WC_TEST_RET_ENC_EC(ret);
  42717. }
  42718. /* Flip bits in a few places throughout the signature, stepping in multiple
  42719. * of hash size. These should all fail with -1. */
  42720. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42721. lms_L1H10W8_sig[j] ^= 1;
  42722. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig,
  42723. LMS_L1H10W8_SIGLEN,
  42724. (byte *) lms_msg, msgSz);
  42725. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42726. /* Verify passed when it should have failed. */
  42727. return WC_TEST_RET_ENC_I(j);
  42728. }
  42729. /* Flip this spot back. */
  42730. lms_L1H10W8_sig[j] ^= 1;
  42731. }
  42732. wc_LmsKey_Free(&verifyKey);
  42733. return ret;
  42734. }
  42735. #endif
  42736. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK) */
  42737. static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point --
  42738. * see print_fiducials() below.
  42739. */
  42740. #ifdef WOLFCRYPT_HAVE_ECCSI
  42741. static wc_test_ret_t eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk,
  42742. ecc_point* pvt)
  42743. {
  42744. wc_test_ret_t ret;
  42745. byte id[1] = { 0x00 };
  42746. int valid;
  42747. word32 sz;
  42748. byte data[256];
  42749. byte hash[WC_MAX_DIGEST_SIZE];
  42750. byte hashSz;
  42751. byte sig[257];
  42752. word32 sigSz;
  42753. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42754. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42755. return WC_TEST_RET_ENC_EC(ret);
  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(NULL, NULL, 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, HEAP_HINT, INVALID_DEVID);
  42763. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42764. return WC_TEST_RET_ENC_EC(ret);
  42765. wc_FreeEccsiKey(NULL);
  42766. /* Create a valid key. */
  42767. ret = wc_InitEccsiKey(key, NULL, INVALID_DEVID);
  42768. if (ret != 0)
  42769. return WC_TEST_RET_ENC_EC(ret);
  42770. ret = wc_MakeEccsiKey(NULL, NULL);
  42771. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42772. return WC_TEST_RET_ENC_EC(ret);
  42773. ret = wc_MakeEccsiKey(key, NULL);
  42774. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42775. return WC_TEST_RET_ENC_EC(ret);
  42776. ret = wc_MakeEccsiKey(NULL, rng);
  42777. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42778. return WC_TEST_RET_ENC_EC(ret);
  42779. ret = wc_MakeEccsiPair(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL,
  42780. NULL);
  42781. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42782. return WC_TEST_RET_ENC_EC(ret);
  42783. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, 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, NULL, pvt);
  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, NULL, 1, ssk, pvt);
  42790. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42791. return WC_TEST_RET_ENC_EC(ret);
  42792. ret = wc_MakeEccsiPair(key, NULL, WC_HASH_TYPE_SHA256, id, 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(NULL, rng, 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. /* No key set */
  42799. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42800. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42801. return WC_TEST_RET_ENC_EC(ret);
  42802. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL,
  42803. NULL);
  42804. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42805. return WC_TEST_RET_ENC_EC(ret);
  42806. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42807. NULL);
  42808. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42809. return WC_TEST_RET_ENC_EC(ret);
  42810. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL,
  42811. &valid);
  42812. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42813. return WC_TEST_RET_ENC_EC(ret);
  42814. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt,
  42815. &valid);
  42816. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42817. return WC_TEST_RET_ENC_EC(ret);
  42818. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt,
  42819. &valid);
  42820. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42821. return WC_TEST_RET_ENC_EC(ret);
  42822. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42823. &valid);
  42824. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42825. return WC_TEST_RET_ENC_EC(ret);
  42826. /* No key set */
  42827. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42828. &valid);
  42829. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42830. return WC_TEST_RET_ENC_EC(ret);
  42831. ret = wc_ValidateEccsiPvt(NULL, NULL, NULL);
  42832. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42833. return WC_TEST_RET_ENC_EC(ret);
  42834. ret = wc_ValidateEccsiPvt(key, NULL, NULL);
  42835. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42836. return WC_TEST_RET_ENC_EC(ret);
  42837. ret = wc_ValidateEccsiPvt(NULL, pvt, NULL);
  42838. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42839. return WC_TEST_RET_ENC_EC(ret);
  42840. ret = wc_ValidateEccsiPvt(NULL, NULL, &valid);
  42841. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42842. return WC_TEST_RET_ENC_EC(ret);
  42843. ret = wc_ValidateEccsiPvt(key, pvt, NULL);
  42844. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42845. return WC_TEST_RET_ENC_EC(ret);
  42846. ret = wc_ValidateEccsiPvt(key, NULL, &valid);
  42847. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42848. return WC_TEST_RET_ENC_EC(ret);
  42849. ret = wc_ValidateEccsiPvt(NULL, pvt, &valid);
  42850. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42851. return WC_TEST_RET_ENC_EC(ret);
  42852. ret = wc_EncodeEccsiPair(NULL, NULL, NULL, data, NULL);
  42853. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42854. return WC_TEST_RET_ENC_EC(ret);
  42855. ret = wc_EncodeEccsiPair(key, ssk, pvt, 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, NULL, data, &sz);
  42859. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42860. return WC_TEST_RET_ENC_EC(ret);
  42861. ret = wc_EncodeEccsiPair(key, NULL, pvt, data, &sz);
  42862. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42863. return WC_TEST_RET_ENC_EC(ret);
  42864. ret = wc_EncodeEccsiPair(NULL, ssk, pvt, data, &sz);
  42865. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42866. return WC_TEST_RET_ENC_EC(ret);
  42867. /* No key created so no curve information. */
  42868. ret = wc_EncodeEccsiPair(key, ssk, pvt, NULL, &sz);
  42869. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42870. return WC_TEST_RET_ENC_EC(ret);
  42871. ret = wc_EncodeEccsiSsk(NULL, NULL, data, NULL);
  42872. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42873. return WC_TEST_RET_ENC_EC(ret);
  42874. ret = wc_EncodeEccsiSsk(key, ssk, 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, NULL, data, &sz);
  42878. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42879. return WC_TEST_RET_ENC_EC(ret);
  42880. ret = wc_EncodeEccsiSsk(NULL, ssk, data, &sz);
  42881. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42882. return WC_TEST_RET_ENC_EC(ret);
  42883. ret = wc_EncodeEccsiPvt(NULL, NULL, data, NULL, 1);
  42884. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42885. return WC_TEST_RET_ENC_EC(ret);
  42886. ret = wc_EncodeEccsiPvt(key, pvt, 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, NULL, data, &sz, 1);
  42890. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42891. return WC_TEST_RET_ENC_EC(ret);
  42892. ret = wc_EncodeEccsiPvt(NULL, pvt, data, &sz, 1);
  42893. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42894. return WC_TEST_RET_ENC_EC(ret);
  42895. ret = wc_DecodeEccsiPair(NULL, NULL, 0, NULL, NULL);
  42896. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42897. return WC_TEST_RET_ENC_EC(ret);
  42898. ret = wc_DecodeEccsiPair(key, data, 0, ssk, 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, NULL, pvt);
  42902. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42903. return WC_TEST_RET_ENC_EC(ret);
  42904. ret = wc_DecodeEccsiPair(key, NULL, 0, ssk, pvt);
  42905. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42906. return WC_TEST_RET_ENC_EC(ret);
  42907. ret = wc_DecodeEccsiPair(NULL, data, 0, ssk, pvt);
  42908. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42909. return WC_TEST_RET_ENC_EC(ret);
  42910. ret = wc_DecodeEccsiSsk(NULL, NULL, 0, NULL);
  42911. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42912. return WC_TEST_RET_ENC_EC(ret);
  42913. ret = wc_DecodeEccsiSsk(key, data, 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, NULL, 0, ssk);
  42917. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42918. return WC_TEST_RET_ENC_EC(ret);
  42919. ret = wc_DecodeEccsiSsk(NULL, data, 0, ssk);
  42920. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42921. return WC_TEST_RET_ENC_EC(ret);
  42922. ret = wc_DecodeEccsiPvt(NULL, NULL, 0, NULL);
  42923. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42924. return WC_TEST_RET_ENC_EC(ret);
  42925. ret = wc_DecodeEccsiPvt(key, data, 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, NULL, 0, pvt);
  42929. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42930. return WC_TEST_RET_ENC_EC(ret);
  42931. ret = wc_DecodeEccsiPvt(NULL, data, 0, pvt);
  42932. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42933. return WC_TEST_RET_ENC_EC(ret);
  42934. ret = wc_DecodeEccsiPvtFromSig(NULL, NULL, 0, NULL);
  42935. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42936. return WC_TEST_RET_ENC_EC(ret);
  42937. ret = wc_DecodeEccsiPvtFromSig(key, data, 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, NULL, 0, pvt);
  42941. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42942. return WC_TEST_RET_ENC_EC(ret);
  42943. ret = wc_DecodeEccsiPvtFromSig(NULL, data, 0, pvt);
  42944. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42945. return WC_TEST_RET_ENC_EC(ret);
  42946. ret = wc_ExportEccsiKey(NULL, data, NULL);
  42947. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42948. return WC_TEST_RET_ENC_EC(ret);
  42949. ret = wc_ExportEccsiKey(key, data, NULL);
  42950. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42951. return WC_TEST_RET_ENC_EC(ret);
  42952. ret = wc_ExportEccsiKey(NULL, data, &sz);
  42953. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42954. return WC_TEST_RET_ENC_EC(ret);
  42955. /* No key to export */
  42956. ret = wc_ExportEccsiKey(key, NULL, &sz);
  42957. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42958. return WC_TEST_RET_ENC_EC(ret);
  42959. ret = wc_ImportEccsiKey(NULL, NULL, 0);
  42960. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42961. return WC_TEST_RET_ENC_EC(ret);
  42962. ret = wc_ImportEccsiKey(key, NULL, 0);
  42963. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42964. return WC_TEST_RET_ENC_EC(ret);
  42965. ret = wc_ImportEccsiKey(NULL, data, 0);
  42966. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42967. return WC_TEST_RET_ENC_EC(ret);
  42968. ret = wc_ExportEccsiPrivateKey(NULL, data, NULL);
  42969. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42970. return WC_TEST_RET_ENC_EC(ret);
  42971. ret = wc_ExportEccsiPrivateKey(key, data, NULL);
  42972. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42973. return WC_TEST_RET_ENC_EC(ret);
  42974. ret = wc_ExportEccsiPrivateKey(NULL, data, &sz);
  42975. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42976. return WC_TEST_RET_ENC_EC(ret);
  42977. /* No key to export */
  42978. ret = wc_ExportEccsiPrivateKey(key, NULL, &sz);
  42979. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42980. return WC_TEST_RET_ENC_EC(ret);
  42981. ret = wc_ImportEccsiPrivateKey(NULL, NULL, 0);
  42982. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42983. return WC_TEST_RET_ENC_EC(ret);
  42984. ret = wc_ImportEccsiPrivateKey(key, NULL, 0);
  42985. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42986. return WC_TEST_RET_ENC_EC(ret);
  42987. ret = wc_ImportEccsiPrivateKey(NULL, data, 0);
  42988. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42989. return WC_TEST_RET_ENC_EC(ret);
  42990. ret = wc_ExportEccsiPublicKey(NULL, data, NULL, 1);
  42991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42992. return WC_TEST_RET_ENC_EC(ret);
  42993. ret = wc_ExportEccsiPublicKey(key, 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(NULL, data, &sz, 1);
  42997. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42998. return WC_TEST_RET_ENC_EC(ret);
  42999. /* No key to export */
  43000. ret = wc_ExportEccsiPublicKey(key, data, &sz, 1);
  43001. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43002. return WC_TEST_RET_ENC_EC(ret);
  43003. ret = wc_ImportEccsiPublicKey(NULL, NULL, 0, 1);
  43004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43005. return WC_TEST_RET_ENC_EC(ret);
  43006. ret = wc_ImportEccsiPublicKey(key, 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(NULL, data, 0, 1);
  43010. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43011. return WC_TEST_RET_ENC_EC(ret);
  43012. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL);
  43013. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43014. return WC_TEST_RET_ENC_EC(ret);
  43015. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, 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, NULL, &hashSz);
  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, NULL, hash, &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, NULL, 1, pvt, hash,
  43025. &hashSz);
  43026. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43027. return WC_TEST_RET_ENC_EC(ret);
  43028. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  43029. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43030. return WC_TEST_RET_ENC_EC(ret);
  43031. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  43032. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43033. return WC_TEST_RET_ENC_EC(ret);
  43034. ret = wc_SetEccsiHash(NULL, NULL, 1);
  43035. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43036. return WC_TEST_RET_ENC_EC(ret);
  43037. ret = wc_SetEccsiHash(key, NULL, 1);
  43038. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43039. return WC_TEST_RET_ENC_EC(ret);
  43040. ret = wc_SetEccsiHash(NULL, hash, 1);
  43041. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43042. return WC_TEST_RET_ENC_EC(ret);
  43043. ret = wc_SetEccsiPair(NULL, NULL, NULL);
  43044. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43045. return WC_TEST_RET_ENC_EC(ret);
  43046. ret = wc_SetEccsiPair(key, NULL, NULL);
  43047. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43048. return WC_TEST_RET_ENC_EC(ret);
  43049. ret = wc_SetEccsiPair(NULL, ssk, NULL);
  43050. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43051. return WC_TEST_RET_ENC_EC(ret);
  43052. ret = wc_SetEccsiPair(NULL, NULL, pvt);
  43053. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43054. return WC_TEST_RET_ENC_EC(ret);
  43055. ret = wc_SetEccsiPair(key, ssk, NULL);
  43056. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43057. return WC_TEST_RET_ENC_EC(ret);
  43058. ret = wc_SetEccsiPair(key, NULL, pvt);
  43059. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43060. return WC_TEST_RET_ENC_EC(ret);
  43061. ret = wc_SetEccsiPair(NULL, ssk, pvt);
  43062. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43063. return WC_TEST_RET_ENC_EC(ret);
  43064. ret = wc_SignEccsiHash(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, NULL);
  43065. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43066. return WC_TEST_RET_ENC_EC(ret);
  43067. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 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, NULL, 0, sig,
  43071. &sigSz);
  43072. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43073. return WC_TEST_RET_ENC_EC(ret);
  43074. ret = wc_SignEccsiHash(key, NULL, WC_HASH_TYPE_SHA256, data, 0, sig,
  43075. &sigSz);
  43076. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43077. return WC_TEST_RET_ENC_EC(ret);
  43078. ret = wc_SignEccsiHash(NULL, rng, WC_HASH_TYPE_SHA256, data, 0, sig,
  43079. &sigSz);
  43080. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43081. return WC_TEST_RET_ENC_EC(ret);
  43082. /* Key not set. */
  43083. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  43084. &sigSz);
  43085. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43086. return WC_TEST_RET_ENC_EC(ret);
  43087. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  43088. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43089. return WC_TEST_RET_ENC_EC(ret);
  43090. ret = wc_VerifyEccsiHash(key, 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(NULL, WC_HASH_TYPE_SHA256, data, 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, NULL, 0, sig, 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, NULL, 0,
  43100. &valid);
  43101. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43102. return WC_TEST_RET_ENC_EC(ret);
  43103. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, NULL);
  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, NULL, 0,
  43107. &valid);
  43108. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43109. return WC_TEST_RET_ENC_EC(ret);
  43110. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0,
  43111. &valid);
  43112. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43113. return WC_TEST_RET_ENC_EC(ret);
  43114. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  43115. &valid);
  43116. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43117. return WC_TEST_RET_ENC_EC(ret);
  43118. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  43119. &valid);
  43120. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43121. return WC_TEST_RET_ENC_EC(ret);
  43122. ret = wc_SetEccsiPair(key, ssk, pvt);
  43123. if (ret != 0)
  43124. return WC_TEST_RET_ENC_EC(ret);
  43125. /* Identity hash not set. */
  43126. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  43127. &sigSz);
  43128. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43129. return WC_TEST_RET_ENC_EC(ret);
  43130. wc_FreeEccsiKey(key);
  43131. return 0;
  43132. }
  43133. /* RFC 6507: Appendix A */
  43134. static wc_test_ret_t eccsi_kat_verify_test(EccsiKey* key, ecc_point* pvt)
  43135. {
  43136. wc_test_ret_t ret;
  43137. int verified;
  43138. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00 };
  43139. word32 msgSz = sizeof(msg);
  43140. byte hash[WC_SHA256_DIGEST_SIZE];
  43141. byte hashSz = WC_SHA256_DIGEST_SIZE;
  43142. static const byte id[] = {
  43143. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43144. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43145. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43146. 0x33, 0x00
  43147. };
  43148. word32 idSz = sizeof(id);
  43149. static const byte sig[] = {
  43150. 0x26, 0x9D, 0x4C, 0x8F, 0xDE, 0xB6, 0x6A, 0x74,
  43151. 0xE4, 0xEF, 0x8C, 0x0D, 0x5D, 0xCC, 0x59, 0x7D,
  43152. 0xDF, 0xE6, 0x02, 0x9C, 0x2A, 0xFF, 0xC4, 0x93,
  43153. 0x60, 0x08, 0xCD, 0x2C, 0xC1, 0x04, 0x5D, 0x81,
  43154. 0xE0, 0x9B, 0x52, 0x8D, 0x0E, 0xF8, 0xD6, 0xDF,
  43155. 0x1A, 0xA3, 0xEC, 0xBF, 0x80, 0x11, 0x0C, 0xFC,
  43156. 0xEC, 0x9F, 0xC6, 0x82, 0x52, 0xCE, 0xBB, 0x67,
  43157. 0x9F, 0x41, 0x34, 0x84, 0x69, 0x40, 0xCC, 0xFD,
  43158. 0x04,
  43159. 0x75, 0x8A, 0x14, 0x27, 0x79, 0xBE, 0x89, 0xE8,
  43160. 0x29, 0xE7, 0x19, 0x84, 0xCB, 0x40, 0xEF, 0x75,
  43161. 0x8C, 0xC4, 0xAD, 0x77, 0x5F, 0xC5, 0xB9, 0xA3,
  43162. 0xE1, 0xC8, 0xED, 0x52, 0xF6, 0xFA, 0x36, 0xD9,
  43163. 0xA7, 0x9D, 0x24, 0x76, 0x92, 0xF4, 0xED, 0xA3,
  43164. 0xA6, 0xBD, 0xAB, 0x77, 0xD6, 0xAA, 0x64, 0x74,
  43165. 0xA4, 0x64, 0xAE, 0x49, 0x34, 0x66, 0x3C, 0x52,
  43166. 0x65, 0xBA, 0x70, 0x18, 0xBA, 0x09, 0x1F, 0x79
  43167. };
  43168. word32 sigSz = sizeof(sig);
  43169. static const byte pubData[] = {
  43170. 0x50, 0xD4, 0x67, 0x0B, 0xDE, 0x75, 0x24, 0x4F,
  43171. 0x28, 0xD2, 0x83, 0x8A, 0x0D, 0x25, 0x55, 0x8A,
  43172. 0x7A, 0x72, 0x68, 0x6D, 0x45, 0x22, 0xD4, 0xC8,
  43173. 0x27, 0x3F, 0xB6, 0x44, 0x2A, 0xEB, 0xFA, 0x93,
  43174. 0xDB, 0xDD, 0x37, 0x55, 0x1A, 0xFD, 0x26, 0x3B,
  43175. 0x5D, 0xFD, 0x61, 0x7F, 0x39, 0x60, 0xC6, 0x5A,
  43176. 0x8C, 0x29, 0x88, 0x50, 0xFF, 0x99, 0xF2, 0x03,
  43177. 0x66, 0xDC, 0xE7, 0xD4, 0x36, 0x72, 0x17, 0xF4
  43178. };
  43179. static const byte expHash[] = {
  43180. 0x49, 0x0f, 0x3f, 0xeb, 0xbc, 0x1c, 0x90, 0x2f,
  43181. 0x62, 0x89, 0x72, 0x3d, 0x7f, 0x8c, 0xbf, 0x79,
  43182. 0xdb, 0x88, 0x93, 0x08, 0x49, 0xd1, 0x9f, 0x38,
  43183. 0xf0, 0x29, 0x5b, 0x5c, 0x27, 0x6c, 0x14, 0xd1
  43184. };
  43185. ret = wc_ImportEccsiPublicKey(key, pubData, sizeof(pubData), 0);
  43186. if (ret != 0)
  43187. return WC_TEST_RET_ENC_EC(ret);
  43188. ret = wc_DecodeEccsiPvtFromSig(key, sig, sigSz, pvt);
  43189. if (ret != 0)
  43190. return WC_TEST_RET_ENC_EC(ret);
  43191. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, idSz, pvt, hash,
  43192. &hashSz);
  43193. if (ret != 0)
  43194. return WC_TEST_RET_ENC_EC(ret);
  43195. if (hashSz != sizeof(expHash))
  43196. return WC_TEST_RET_ENC_NC;
  43197. if (XMEMCMP(hash, expHash, hashSz) != 0)
  43198. return WC_TEST_RET_ENC_NC;
  43199. ret = wc_SetEccsiHash(key, hash, hashSz);
  43200. if (ret != 0)
  43201. return WC_TEST_RET_ENC_EC(ret);
  43202. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43203. &verified);
  43204. if (ret != 0)
  43205. return WC_TEST_RET_ENC_EC(ret);
  43206. if (!verified)
  43207. return WC_TEST_RET_ENC_NC;
  43208. return 0;
  43209. }
  43210. static wc_test_ret_t eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt)
  43211. {
  43212. wc_test_ret_t ret;
  43213. byte data[32 * 3];
  43214. word32 sz;
  43215. ecc_point* decPvt = NULL;
  43216. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  43217. mp_int *decSsk = (mp_int *)XMALLOC(sizeof(*decSsk), HEAP_HINT,
  43218. DYNAMIC_TYPE_TMP_BUFFER);
  43219. if (decSsk == NULL)
  43220. return WC_TEST_RET_ENC_ERRNO;
  43221. #else
  43222. mp_int decSsk[1];
  43223. #endif
  43224. ret = mp_init(decSsk);
  43225. if (ret != 0)
  43226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43227. decPvt = wc_ecc_new_point();
  43228. if (decPvt == NULL)
  43229. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  43230. ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz);
  43231. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43232. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43233. if (sz != 32 * 3)
  43234. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43235. ret = wc_EncodeEccsiPair(priv, ssk, pvt, data, &sz);
  43236. if (ret != 0)
  43237. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43238. if (sz != 32* 3)
  43239. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43240. ret = wc_DecodeEccsiPair(priv, data, sz, decSsk, decPvt);
  43241. if (ret != 0)
  43242. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43243. ret = mp_cmp(ssk, decSsk);
  43244. if (ret != MP_EQ)
  43245. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43246. ret = wc_ecc_cmp_point(pvt, decPvt);
  43247. if (ret != MP_EQ)
  43248. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43249. ret = wc_EncodeEccsiSsk(priv, ssk, NULL, &sz);
  43250. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43252. if (sz != 32)
  43253. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43254. ret = wc_EncodeEccsiSsk(priv, ssk, data, &sz);
  43255. if (ret != 0)
  43256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43257. if (sz != 32)
  43258. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43259. ret = wc_DecodeEccsiSsk(priv, data, sz, decSsk);
  43260. if (ret != 0)
  43261. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43262. ret = mp_cmp(ssk, decSsk);
  43263. if (ret != MP_EQ)
  43264. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43265. ret = wc_EncodeEccsiPvt(priv, pvt, NULL, &sz, 1);
  43266. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43267. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43268. if (sz != 32 * 2)
  43269. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43270. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 1);
  43271. if (ret != 0)
  43272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43273. if (sz != 32 * 2)
  43274. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43275. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  43276. if (ret != 0)
  43277. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43278. ret = wc_ecc_cmp_point(pvt, decPvt);
  43279. if (ret != MP_EQ)
  43280. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43281. sz = sizeof(data);
  43282. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 0);
  43283. if (ret != 0)
  43284. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43285. if (sz != 32 * 2 + 1)
  43286. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43287. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  43288. if (ret != 0)
  43289. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43290. ret = wc_ecc_cmp_point(pvt, decPvt);
  43291. if (ret != MP_EQ)
  43292. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43293. wc_ecc_del_point(decPvt);
  43294. out:
  43295. mp_free(decSsk);
  43296. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  43297. XFREE(decSsk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43298. #endif
  43299. return ret;
  43300. }
  43301. static wc_test_ret_t eccsi_imp_exp_key_test(EccsiKey* priv)
  43302. {
  43303. wc_test_ret_t ret;
  43304. byte data[32 * 3];
  43305. byte out[32 * 3];
  43306. word32 sz;
  43307. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  43308. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43309. return WC_TEST_RET_ENC_EC(ret);
  43310. if (sz != 32 * 3)
  43311. return WC_TEST_RET_ENC_NC;
  43312. ret = wc_ExportEccsiKey(priv, data, &sz);
  43313. if (ret != 0)
  43314. return WC_TEST_RET_ENC_EC(ret);
  43315. ret = wc_ImportEccsiKey(priv, data, sz);
  43316. if (ret != 0)
  43317. return WC_TEST_RET_ENC_EC(ret);
  43318. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  43319. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43320. return WC_TEST_RET_ENC_EC(ret);
  43321. if (sz != 32 * 3)
  43322. return WC_TEST_RET_ENC_NC;
  43323. ret = wc_ExportEccsiKey(priv, out, &sz);
  43324. if (ret != 0)
  43325. return WC_TEST_RET_ENC_EC(ret);
  43326. if (sz != 32 * 3)
  43327. return WC_TEST_RET_ENC_NC;
  43328. if (XMEMCMP(data, out, sz) != 0)
  43329. return WC_TEST_RET_ENC_NC;
  43330. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  43331. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43332. return WC_TEST_RET_ENC_EC(ret);
  43333. if (sz != 32)
  43334. return WC_TEST_RET_ENC_NC;
  43335. ret = wc_ExportEccsiPrivateKey(priv, data, &sz);
  43336. if (ret != 0)
  43337. return WC_TEST_RET_ENC_EC(ret);
  43338. ret = wc_ImportEccsiPrivateKey(priv, data, sz);
  43339. if (ret != 0)
  43340. return WC_TEST_RET_ENC_EC(ret);
  43341. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  43342. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43343. return WC_TEST_RET_ENC_EC(ret);
  43344. if (sz != 32)
  43345. return WC_TEST_RET_ENC_NC;
  43346. ret = wc_ExportEccsiPrivateKey(priv, out, &sz);
  43347. if (ret != 0)
  43348. return WC_TEST_RET_ENC_EC(ret);
  43349. if (sz != 32)
  43350. return WC_TEST_RET_ENC_NC;
  43351. if (XMEMCMP(data, out, sz) != 0)
  43352. return WC_TEST_RET_ENC_NC;
  43353. return 0;
  43354. }
  43355. static wc_test_ret_t eccsi_imp_exp_pubkey_test(EccsiKey* key1, EccsiKey* key2)
  43356. {
  43357. wc_test_ret_t ret;
  43358. byte data[32 * 2 + 1];
  43359. byte pubData[32 * 2 + 1];
  43360. word32 sz;
  43361. ret = wc_ExportEccsiPublicKey(key1, NULL, &sz, 1);
  43362. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43363. return WC_TEST_RET_ENC_EC(ret);
  43364. if (sz != 32 * 2)
  43365. return WC_TEST_RET_ENC_NC;
  43366. ret = wc_ExportEccsiPublicKey(key1, data, &sz, 1);
  43367. if (ret != 0)
  43368. return WC_TEST_RET_ENC_EC(ret);
  43369. ret = wc_ImportEccsiPublicKey(key2, data, sz, 1);
  43370. if (ret != 0)
  43371. return WC_TEST_RET_ENC_EC(ret);
  43372. sz = sizeof(pubData);
  43373. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 1);
  43374. if (ret != 0)
  43375. return WC_TEST_RET_ENC_EC(ret);
  43376. if (sz != 32 * 2)
  43377. return WC_TEST_RET_ENC_NC;
  43378. if (XMEMCMP(data, pubData, sz) != 0)
  43379. return WC_TEST_RET_ENC_NC;
  43380. sz = sizeof(pubData);
  43381. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 0);
  43382. if (ret != 0)
  43383. return WC_TEST_RET_ENC_EC(ret);
  43384. if (sz != 32 * 2 + 1)
  43385. return WC_TEST_RET_ENC_NC;
  43386. if (pubData[0] != 0x04)
  43387. return WC_TEST_RET_ENC_NC;
  43388. if (XMEMCMP(pubData + 1, data, sz - 1) != 0)
  43389. return WC_TEST_RET_ENC_NC;
  43390. ret = wc_ImportEccsiPublicKey(key2, pubData, sz, 0);
  43391. if (ret != 0)
  43392. return WC_TEST_RET_ENC_EC(ret);
  43393. return 0;
  43394. }
  43395. static wc_test_ret_t eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43396. mp_int* ssk, ecc_point* pvt)
  43397. {
  43398. wc_test_ret_t ret;
  43399. char mail[] = "test@wolfssl.com";
  43400. byte* id = (byte*)mail;
  43401. word32 idSz = (word32) XSTRLEN(mail);
  43402. int valid;
  43403. ret = wc_MakeEccsiKey(priv, rng);
  43404. if (ret != 0)
  43405. return WC_TEST_RET_ENC_EC(ret);
  43406. ret = eccsi_imp_exp_key_test(priv);
  43407. if (ret < 0)
  43408. return ret;
  43409. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43410. if (ret < 0)
  43411. return ret;
  43412. ret = wc_MakeEccsiPair(priv, rng, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt);
  43413. if (ret != 0)
  43414. return WC_TEST_RET_ENC_EC(ret);
  43415. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43416. &valid);
  43417. if (ret != 0)
  43418. return WC_TEST_RET_ENC_EC(ret);
  43419. if (!valid)
  43420. return WC_TEST_RET_ENC_NC;
  43421. ret = eccsi_enc_dec_pair_test(priv, ssk, pvt);
  43422. if (ret != 0)
  43423. return ret;
  43424. return 0;
  43425. }
  43426. static wc_test_ret_t eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43427. mp_int* ssk, ecc_point* pvt)
  43428. {
  43429. wc_test_ret_t ret;
  43430. byte hashPriv[WC_MAX_DIGEST_SIZE];
  43431. byte hashPub[WC_MAX_DIGEST_SIZE];
  43432. byte hashSz;
  43433. byte sig[144];
  43434. word32 sigSz;
  43435. int verified, valid;
  43436. char mail[] = "test@wolfssl.com";
  43437. byte* id = (byte*)mail;
  43438. word32 idSz = (word32) XSTRLEN(mail);
  43439. byte msg[] = { 0x00 };
  43440. word32 msgSz = sizeof(msg);
  43441. #ifdef WOLFSSL_SHA384
  43442. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA384, id, idSz, pvt, hashPriv,
  43443. &hashSz);
  43444. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43445. return WC_TEST_RET_ENC_EC(ret);
  43446. #endif
  43447. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPriv,
  43448. &hashSz);
  43449. if (ret != 0)
  43450. return WC_TEST_RET_ENC_EC(ret);
  43451. if (hashSz != 32)
  43452. return WC_TEST_RET_ENC_NC;
  43453. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPub,
  43454. &hashSz);
  43455. if (ret != 0)
  43456. return WC_TEST_RET_ENC_EC(ret);
  43457. if (hashSz != 32)
  43458. return WC_TEST_RET_ENC_NC;
  43459. if (XMEMCMP(hashPriv, hashPub, hashSz) != 0)
  43460. return WC_TEST_RET_ENC_NC;
  43461. ret = wc_SetEccsiHash(priv, hashPriv, hashSz);
  43462. if (ret != 0)
  43463. return WC_TEST_RET_ENC_EC(ret);
  43464. ret = wc_SetEccsiPair(priv, ssk, pvt);
  43465. if (ret != 0)
  43466. return WC_TEST_RET_ENC_EC(ret);
  43467. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, NULL,
  43468. &sigSz);
  43469. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43470. return WC_TEST_RET_ENC_EC(ret);
  43471. if (sigSz != 129)
  43472. return WC_TEST_RET_ENC_NC;
  43473. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, sig,
  43474. &sigSz);
  43475. if (ret != 0)
  43476. return WC_TEST_RET_ENC_EC(ret);
  43477. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43478. if (ret != 0)
  43479. return WC_TEST_RET_ENC_EC(ret);
  43480. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43481. &verified);
  43482. if (ret != 0)
  43483. return WC_TEST_RET_ENC_EC(ret);
  43484. if (!verified)
  43485. return WC_TEST_RET_ENC_NC;
  43486. /* Check that changing HS results in verification failure. */
  43487. hashPub[0] ^= 0x80;
  43488. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43489. if (ret != 0)
  43490. return WC_TEST_RET_ENC_EC(ret);
  43491. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43492. &verified);
  43493. if (ret != 0)
  43494. return WC_TEST_RET_ENC_EC(ret);
  43495. if (verified)
  43496. return WC_TEST_RET_ENC_NC;
  43497. hashPub[0] ^= 0x80;
  43498. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43499. if (ret != 0)
  43500. return WC_TEST_RET_ENC_EC(ret);
  43501. /* Check that changing msg results in verification failure. */
  43502. msg[0] ^= 0x80;
  43503. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43504. &verified);
  43505. if (ret != 0)
  43506. return WC_TEST_RET_ENC_EC(ret);
  43507. if (verified)
  43508. return WC_TEST_RET_ENC_NC;
  43509. msg[0] ^= 0x80;
  43510. /* Check that changing signature results in verification failure. */
  43511. sig[0] ^= 0x80;
  43512. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43513. &verified);
  43514. if (ret != 0)
  43515. return WC_TEST_RET_ENC_EC(ret);
  43516. if (verified)
  43517. return WC_TEST_RET_ENC_NC;
  43518. sig[0] ^= 0x80;
  43519. /* Check that key state hasn't been invalidated. */
  43520. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43521. &verified);
  43522. if (ret != 0)
  43523. return WC_TEST_RET_ENC_EC(ret);
  43524. if (!verified)
  43525. return WC_TEST_RET_ENC_NC;
  43526. /* Check that verifying with the private key works. */
  43527. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43528. &verified);
  43529. if (ret != 0)
  43530. return WC_TEST_RET_ENC_EC(ret);
  43531. if (!verified)
  43532. return WC_TEST_RET_ENC_NC;
  43533. /* Check that the KPAK is converted from montgomery form. */
  43534. ret = eccsi_imp_exp_key_test(priv);
  43535. if (ret != 0)
  43536. return ret;
  43537. /* Check that KPAK can converted to Montgomery form again. */
  43538. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43539. &verified);
  43540. if (ret != 0)
  43541. return WC_TEST_RET_ENC_EC(ret);
  43542. if (!verified)
  43543. return WC_TEST_RET_ENC_NC;
  43544. /* Check that the KPAK is converted from montgomery form. */
  43545. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43546. &valid);
  43547. if (ret != 0)
  43548. return WC_TEST_RET_ENC_EC(ret);
  43549. if (!valid)
  43550. return WC_TEST_RET_ENC_NC;
  43551. /* Check that KPAK can converted to Montgomery form again. */
  43552. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43553. &verified);
  43554. if (ret != 0)
  43555. return WC_TEST_RET_ENC_EC(ret);
  43556. if (!verified)
  43557. return WC_TEST_RET_ENC_NC;
  43558. /* Check that the KPAK is converted from montgomery form. */
  43559. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43560. if (ret != 0)
  43561. return ret;
  43562. return 0;
  43563. }
  43564. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void)
  43565. {
  43566. wc_test_ret_t ret = 0;
  43567. WC_RNG rng;
  43568. int rng_inited = 0;
  43569. EccsiKey* priv = NULL;
  43570. EccsiKey* pub = NULL;
  43571. mp_int* ssk = NULL;
  43572. ecc_point* pvt = NULL;
  43573. WOLFSSL_ENTER("eccsi_test");
  43574. priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43575. DYNAMIC_TYPE_TMP_BUFFER);
  43576. if (priv == NULL)
  43577. ret = WC_TEST_RET_ENC_NC;
  43578. else
  43579. XMEMSET(priv, 0, sizeof(*priv));
  43580. if (ret == 0) {
  43581. pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43582. DYNAMIC_TYPE_TMP_BUFFER);
  43583. if (pub == NULL)
  43584. ret = WC_TEST_RET_ENC_NC;
  43585. else
  43586. XMEMSET(pub, 0, sizeof(*pub));
  43587. }
  43588. if (ret == 0) {
  43589. ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT,
  43590. DYNAMIC_TYPE_TMP_BUFFER);
  43591. if (ssk == NULL)
  43592. ret = WC_TEST_RET_ENC_NC;
  43593. else
  43594. XMEMSET(ssk, 0, sizeof(*ssk));
  43595. }
  43596. if (ret == 0) {
  43597. #ifndef HAVE_FIPS
  43598. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  43599. #else
  43600. ret = wc_InitRng(&rng);
  43601. #endif
  43602. if (ret != 0)
  43603. ret = WC_TEST_RET_ENC_EC(ret);
  43604. else
  43605. rng_inited = 1;
  43606. }
  43607. if (ret == 0) {
  43608. pvt = wc_ecc_new_point();
  43609. if (pvt == NULL)
  43610. ret = WC_TEST_RET_ENC_NC;
  43611. }
  43612. if (ret == 0) {
  43613. ret = mp_init(ssk);
  43614. if (ret != 0)
  43615. ret = WC_TEST_RET_ENC_EC(ret);
  43616. }
  43617. if (ret == 0) {
  43618. ret = eccsi_api_test(&rng, priv, ssk, pvt);
  43619. }
  43620. if (ret == 0) {
  43621. ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID);
  43622. if (ret != 0)
  43623. ret = WC_TEST_RET_ENC_EC(ret);
  43624. }
  43625. if (ret == 0) {
  43626. ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID);
  43627. if (ret != 0)
  43628. ret = WC_TEST_RET_ENC_EC(ret);
  43629. }
  43630. if (ret == 0) {
  43631. ret = eccsi_kat_verify_test(pub, pvt);
  43632. }
  43633. if (ret == 0) {
  43634. ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt);
  43635. }
  43636. if (ret == 0) {
  43637. ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt);
  43638. }
  43639. if (pvt != NULL)
  43640. wc_ecc_del_point(pvt);
  43641. if (rng_inited)
  43642. wc_FreeRng(&rng);
  43643. if (ssk != NULL) {
  43644. mp_free(ssk);
  43645. XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43646. }
  43647. if (pub != NULL) {
  43648. wc_FreeEccsiKey(pub);
  43649. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43650. }
  43651. if (priv != NULL) {
  43652. wc_FreeEccsiKey(priv);
  43653. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43654. }
  43655. return ret;
  43656. }
  43657. #endif /* WOLFCRYPT_HAVE_ECCSI */
  43658. #ifdef WOLFCRYPT_HAVE_SAKKE
  43659. static wc_test_ret_t sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk)
  43660. {
  43661. wc_test_ret_t ret;
  43662. byte id[1] = { 0x00 };
  43663. int valid;
  43664. byte data[256];
  43665. word32 sz;
  43666. byte auth[257];
  43667. word16 authSz;
  43668. byte ssv[256];
  43669. word16 ssvSz;
  43670. word32 len;
  43671. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43672. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43673. return WC_TEST_RET_ENC_EC(ret);
  43674. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43675. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43676. return WC_TEST_RET_ENC_EC(ret);
  43677. wc_FreeSakkeKey(NULL);
  43678. XMEMSET(key, 0, sizeof(*key));
  43679. wc_FreeSakkeKey(key);
  43680. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43681. if (ret != 0)
  43682. return WC_TEST_RET_ENC_EC(ret);
  43683. ret = wc_MakeSakkeKey(NULL, NULL);
  43684. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43685. return WC_TEST_RET_ENC_EC(ret);
  43686. ret = wc_MakeSakkeKey(key, NULL);
  43687. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43688. return WC_TEST_RET_ENC_EC(ret);
  43689. ret = wc_MakeSakkeKey(NULL, rng);
  43690. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43691. return WC_TEST_RET_ENC_EC(ret);
  43692. ret = wc_MakeSakkePublicKey(NULL, NULL);
  43693. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43694. return WC_TEST_RET_ENC_EC(ret);
  43695. ret = wc_MakeSakkePublicKey(key, NULL);
  43696. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43697. return WC_TEST_RET_ENC_EC(ret);
  43698. ret = wc_MakeSakkePublicKey(NULL, rsk);
  43699. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43700. return WC_TEST_RET_ENC_EC(ret);
  43701. ret = wc_MakeSakkeRsk(NULL, NULL, 1, NULL);
  43702. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43703. return WC_TEST_RET_ENC_EC(ret);
  43704. ret = wc_MakeSakkeRsk(key, id, 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, NULL, 1, rsk);
  43708. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43709. return WC_TEST_RET_ENC_EC(ret);
  43710. ret = wc_MakeSakkeRsk(NULL, id, 1, rsk);
  43711. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43712. return WC_TEST_RET_ENC_EC(ret);
  43713. ret = wc_ValidateSakkeRsk(NULL, NULL, 1, NULL, NULL);
  43714. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43715. return WC_TEST_RET_ENC_EC(ret);
  43716. ret = wc_ValidateSakkeRsk(key, id, 1, rsk, NULL);
  43717. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43718. return WC_TEST_RET_ENC_EC(ret);
  43719. ret = wc_ValidateSakkeRsk(NULL, id, 1, rsk, &valid);
  43720. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43721. return WC_TEST_RET_ENC_EC(ret);
  43722. ret = wc_ExportSakkeKey(NULL, NULL, NULL);
  43723. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43724. return WC_TEST_RET_ENC_EC(ret);
  43725. ret = wc_ExportSakkeKey(key, data, NULL);
  43726. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43727. return WC_TEST_RET_ENC_EC(ret);
  43728. ret = wc_ExportSakkeKey(NULL, data, &sz);
  43729. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43730. return WC_TEST_RET_ENC_EC(ret);
  43731. ret = wc_ImportSakkeKey(NULL, NULL, 1);
  43732. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43733. return WC_TEST_RET_ENC_EC(ret);
  43734. ret = wc_ImportSakkeKey(key, NULL, 1);
  43735. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43736. return WC_TEST_RET_ENC_EC(ret);
  43737. ret = wc_ImportSakkeKey(NULL, data, 1);
  43738. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43739. return WC_TEST_RET_ENC_EC(ret);
  43740. ret = wc_ExportSakkePrivateKey(NULL, NULL, NULL);
  43741. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43742. return WC_TEST_RET_ENC_EC(ret);
  43743. ret = wc_ExportSakkePrivateKey(key, data, NULL);
  43744. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43745. return WC_TEST_RET_ENC_EC(ret);
  43746. ret = wc_ExportSakkePrivateKey(NULL, data, &sz);
  43747. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43748. return WC_TEST_RET_ENC_EC(ret);
  43749. ret = wc_ImportSakkePrivateKey(NULL, NULL, 1);
  43750. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43751. return WC_TEST_RET_ENC_EC(ret);
  43752. ret = wc_ImportSakkePrivateKey(key, NULL, 1);
  43753. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43754. return WC_TEST_RET_ENC_EC(ret);
  43755. ret = wc_ImportSakkePrivateKey(NULL, data, 1);
  43756. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43757. return WC_TEST_RET_ENC_EC(ret);
  43758. sz = sizeof(data);
  43759. ret = wc_EncodeSakkeRsk(NULL, NULL, data, NULL, 1);
  43760. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43761. return WC_TEST_RET_ENC_EC(ret);
  43762. ret = wc_EncodeSakkeRsk(key, rsk, 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, NULL, data, &sz, 1);
  43766. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43767. return WC_TEST_RET_ENC_EC(ret);
  43768. ret = wc_EncodeSakkeRsk(NULL, rsk, data, &sz, 1);
  43769. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43770. return WC_TEST_RET_ENC_EC(ret);
  43771. ret = wc_DecodeSakkeRsk(NULL, NULL, sz, NULL);
  43772. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43773. return WC_TEST_RET_ENC_EC(ret);
  43774. ret = wc_DecodeSakkeRsk(key, data, 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, NULL, sz, rsk);
  43778. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43779. return WC_TEST_RET_ENC_EC(ret);
  43780. ret = wc_DecodeSakkeRsk(NULL, data, sz, rsk);
  43781. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43782. return WC_TEST_RET_ENC_EC(ret);
  43783. ret = wc_ImportSakkeRsk(NULL, NULL, sz);
  43784. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43785. return WC_TEST_RET_ENC_EC(ret);
  43786. ret = wc_ImportSakkeRsk(key, NULL, sz);
  43787. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43788. return WC_TEST_RET_ENC_EC(ret);
  43789. ret = wc_ImportSakkeRsk(NULL, data, sz);
  43790. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43791. return WC_TEST_RET_ENC_EC(ret);
  43792. ret = wc_ImportSakkeRsk(key, data, 1);
  43793. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43794. return WC_TEST_RET_ENC_EC(ret);
  43795. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, NULL);
  43796. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43797. return WC_TEST_RET_ENC_EC(ret);
  43798. ret = wc_GenerateSakkeRskTable(key, 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(NULL, rsk, 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, NULL, data, &len);
  43805. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43806. return WC_TEST_RET_ENC_EC(ret);
  43807. ret = wc_GenerateSakkeRskTable(key, rsk, data, NULL);
  43808. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43809. return WC_TEST_RET_ENC_EC(ret);
  43810. ret = wc_GenerateSakkeRskTable(key, NULL, data, &len);
  43811. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43812. return WC_TEST_RET_ENC_EC(ret);
  43813. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, &len);
  43814. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43815. return WC_TEST_RET_ENC_EC(ret);
  43816. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43817. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43818. return WC_TEST_RET_ENC_EC(ret);
  43819. len--;
  43820. ret = wc_GenerateSakkeRskTable(key, rsk, data, &len);
  43821. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43822. return WC_TEST_RET_ENC_EC(ret);
  43823. ret = wc_ExportSakkePublicKey(NULL, data, NULL, 1);
  43824. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43825. return WC_TEST_RET_ENC_EC(ret);
  43826. ret = wc_ExportSakkePublicKey(key, 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(NULL, data, &sz, 1);
  43830. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43831. return WC_TEST_RET_ENC_EC(ret);
  43832. ret = wc_ImportSakkePublicKey(NULL, NULL, sz, 1);
  43833. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43834. return WC_TEST_RET_ENC_EC(ret);
  43835. ret = wc_ImportSakkePublicKey(key, 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(NULL, data, sz, 1);
  43839. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43840. return WC_TEST_RET_ENC_EC(ret);
  43841. ret = wc_GetSakkeAuthSize(NULL, NULL);
  43842. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43843. return WC_TEST_RET_ENC_EC(ret);
  43844. ret = wc_GetSakkeAuthSize(key, NULL);
  43845. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43846. return WC_TEST_RET_ENC_EC(ret);
  43847. ret = wc_GetSakkeAuthSize(NULL, &authSz);
  43848. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43849. return WC_TEST_RET_ENC_EC(ret);
  43850. ret = wc_MakeSakkePointI(NULL, NULL, SAKKE_ID_MAX_SIZE + 1);
  43851. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43852. return WC_TEST_RET_ENC_EC(ret);
  43853. ret = wc_MakeSakkePointI(key, 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(NULL, id, 1);
  43857. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43858. return WC_TEST_RET_ENC_EC(ret);
  43859. ret = wc_MakeSakkePointI(NULL, NULL, 1);
  43860. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43861. return WC_TEST_RET_ENC_EC(ret);
  43862. ret = wc_MakeSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1);
  43863. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43864. return WC_TEST_RET_ENC_EC(ret);
  43865. ret = wc_MakeSakkePointI(key, NULL, 1);
  43866. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43867. return WC_TEST_RET_ENC_EC(ret);
  43868. ret = wc_MakeSakkePointI(NULL, id, 1);
  43869. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43870. return WC_TEST_RET_ENC_EC(ret);
  43871. ret = wc_GenerateSakkePointITable(NULL, data, NULL);
  43872. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43873. return WC_TEST_RET_ENC_EC(ret);
  43874. ret = wc_GenerateSakkePointITable(key, data, NULL);
  43875. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43876. return WC_TEST_RET_ENC_EC(ret);
  43877. ret = wc_GenerateSakkePointITable(NULL, data, &len);
  43878. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43879. return WC_TEST_RET_ENC_EC(ret);
  43880. ret = wc_GenerateSakkePointITable(key, NULL, &len);
  43881. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43882. return WC_TEST_RET_ENC_EC(ret);
  43883. len--;
  43884. ret = wc_GenerateSakkePointITable(key, data, &len);
  43885. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43886. return WC_TEST_RET_ENC_EC(ret);
  43887. ret = wc_SetSakkePointITable(NULL, NULL, 1);
  43888. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43889. return WC_TEST_RET_ENC_EC(ret);
  43890. ret = wc_SetSakkePointITable(key, NULL, 1);
  43891. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43892. return WC_TEST_RET_ENC_EC(ret);
  43893. ret = wc_SetSakkePointITable(NULL, data, 1);
  43894. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43895. return WC_TEST_RET_ENC_EC(ret);
  43896. ret = wc_SetSakkePointITable(key, data, 1);
  43897. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43898. return WC_TEST_RET_ENC_EC(ret);
  43899. ret = wc_ClearSakkePointITable(NULL);
  43900. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43901. return WC_TEST_RET_ENC_EC(ret);
  43902. ret = wc_GetSakkePointI(NULL, data, NULL);
  43903. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43904. return WC_TEST_RET_ENC_EC(ret);
  43905. ret = wc_GetSakkePointI(key, data, NULL);
  43906. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43907. return WC_TEST_RET_ENC_EC(ret);
  43908. ret = wc_GetSakkePointI(NULL, data, &sz);
  43909. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43910. return WC_TEST_RET_ENC_EC(ret);
  43911. sz = 1;
  43912. ret = wc_GetSakkePointI(key, data, &sz);
  43913. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43914. return WC_TEST_RET_ENC_EC(ret);
  43915. sz = 256;
  43916. ret = wc_SetSakkePointI(NULL, NULL, 1, NULL, sz);
  43917. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43918. return WC_TEST_RET_ENC_EC(ret);
  43919. ret = wc_SetSakkePointI(key, 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(NULL, id, 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, NULL, 1, data, sz);
  43926. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43927. return WC_TEST_RET_ENC_EC(ret);
  43928. ret = wc_SetSakkePointI(key, id, 1, NULL, sz);
  43929. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43930. return WC_TEST_RET_ENC_EC(ret);
  43931. ret = wc_SetSakkePointI(key, NULL, 1, data, sz);
  43932. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43933. return WC_TEST_RET_ENC_EC(ret);
  43934. ret = wc_SetSakkePointI(NULL, id, 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(key, id, SAKKE_ID_MAX_SIZE + 1, data, sz);
  43938. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43939. return WC_TEST_RET_ENC_EC(ret);
  43940. ret = wc_SetSakkePointI(key, id, 1, data, sz - 1);
  43941. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43942. return WC_TEST_RET_ENC_EC(ret);
  43943. ret = wc_SetSakkeIdentity(NULL, NULL, 1);
  43944. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43945. return WC_TEST_RET_ENC_EC(ret);
  43946. ret = wc_SetSakkeIdentity(key, NULL, 1);
  43947. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43948. return WC_TEST_RET_ENC_EC(ret);
  43949. ret = wc_SetSakkeIdentity(NULL, id, 1);
  43950. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43951. return WC_TEST_RET_ENC_EC(ret);
  43952. ssvSz = sizeof(ssv);
  43953. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43954. auth, NULL);
  43955. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43956. return WC_TEST_RET_ENC_EC(ret);
  43957. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43958. auth, NULL);
  43959. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43960. return WC_TEST_RET_ENC_EC(ret);
  43961. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43962. auth, NULL);
  43963. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43964. return WC_TEST_RET_ENC_EC(ret);
  43965. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43966. auth, &authSz);
  43967. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43968. return WC_TEST_RET_ENC_EC(ret);
  43969. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43970. auth, NULL);
  43971. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43972. return WC_TEST_RET_ENC_EC(ret);
  43973. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43974. auth, &authSz);
  43975. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43976. return WC_TEST_RET_ENC_EC(ret);
  43977. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43978. auth, &authSz);
  43979. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43980. return WC_TEST_RET_ENC_EC(ret);
  43981. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43982. auth, &authSz);
  43983. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43984. return WC_TEST_RET_ENC_EC(ret);
  43985. ret = wc_GenerateSakkeSSV(NULL, NULL, data, NULL);
  43986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43987. return WC_TEST_RET_ENC_EC(ret);
  43988. ret = wc_GenerateSakkeSSV(key, rng, 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, NULL, data, &ssvSz);
  43992. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43993. return WC_TEST_RET_ENC_EC(ret);
  43994. ret = wc_GenerateSakkeSSV(NULL, rng, data, &ssvSz);
  43995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43996. return WC_TEST_RET_ENC_EC(ret);
  43997. ret = wc_SetSakkeRsk(NULL, NULL, data, 1);
  43998. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43999. return WC_TEST_RET_ENC_EC(ret);
  44000. ret = wc_SetSakkeRsk(key, 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(NULL, rsk, data, 1);
  44004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44005. return WC_TEST_RET_ENC_EC(ret);
  44006. ssvSz = sizeof(ssv);
  44007. authSz = sizeof(auth);
  44008. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  44009. authSz);
  44010. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44011. return WC_TEST_RET_ENC_EC(ret);
  44012. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  44013. authSz);
  44014. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44015. return WC_TEST_RET_ENC_EC(ret);
  44016. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  44017. authSz);
  44018. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44019. return WC_TEST_RET_ENC_EC(ret);
  44020. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  44021. authSz);
  44022. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44023. return WC_TEST_RET_ENC_EC(ret);
  44024. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  44025. authSz);
  44026. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44027. return WC_TEST_RET_ENC_EC(ret);
  44028. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  44029. authSz);
  44030. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44031. return WC_TEST_RET_ENC_EC(ret);
  44032. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44033. authSz);
  44034. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44035. return WC_TEST_RET_ENC_EC(ret);
  44036. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44037. authSz);
  44038. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44039. return WC_TEST_RET_ENC_EC(ret);
  44040. ret = wc_SetSakkeIdentity(key, id, 1);
  44041. if (ret != 0)
  44042. return WC_TEST_RET_ENC_EC(ret);
  44043. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44044. authSz);
  44045. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44046. return WC_TEST_RET_ENC_EC(ret);
  44047. ret = wc_SetSakkeIdentity(key, id, 0);
  44048. if (ret != 0)
  44049. return WC_TEST_RET_ENC_EC(ret);
  44050. ret = wc_SetSakkeRsk(key, rsk, data, 1);
  44051. if (ret != 0)
  44052. return WC_TEST_RET_ENC_EC(ret);
  44053. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44054. authSz);
  44055. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44056. return WC_TEST_RET_ENC_EC(ret);
  44057. wc_FreeSakkeKey(key);
  44058. return 0;
  44059. }
  44060. static wc_test_ret_t sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk)
  44061. {
  44062. WOLFSSL_SMALL_STACK_STATIC const byte pubData[] = {
  44063. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  44064. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  44065. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  44066. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  44067. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  44068. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  44069. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  44070. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  44071. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  44072. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  44073. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  44074. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  44075. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  44076. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  44077. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  44078. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  44079. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  44080. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  44081. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  44082. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  44083. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  44084. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  44085. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  44086. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  44087. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  44088. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  44089. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  44090. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  44091. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  44092. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  44093. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  44094. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  44095. };
  44096. WOLFSSL_SMALL_STACK_STATIC const byte rskData[] = {
  44097. 0x93, 0xAF, 0x67, 0xE5, 0x00, 0x7B, 0xA6, 0xE6,
  44098. 0xA8, 0x0D, 0xA7, 0x93, 0xDA, 0x30, 0x0F, 0xA4,
  44099. 0xB5, 0x2D, 0x0A, 0x74, 0xE2, 0x5E, 0x6E, 0x7B,
  44100. 0x2B, 0x3D, 0x6E, 0xE9, 0xD1, 0x8A, 0x9B, 0x5C,
  44101. 0x50, 0x23, 0x59, 0x7B, 0xD8, 0x2D, 0x80, 0x62,
  44102. 0xD3, 0x40, 0x19, 0x56, 0x3B, 0xA1, 0xD2, 0x5C,
  44103. 0x0D, 0xC5, 0x6B, 0x7B, 0x97, 0x9D, 0x74, 0xAA,
  44104. 0x50, 0xF2, 0x9F, 0xBF, 0x11, 0xCC, 0x2C, 0x93,
  44105. 0xF5, 0xDF, 0xCA, 0x61, 0x5E, 0x60, 0x92, 0x79,
  44106. 0xF6, 0x17, 0x5C, 0xEA, 0xDB, 0x00, 0xB5, 0x8C,
  44107. 0x6B, 0xEE, 0x1E, 0x7A, 0x2A, 0x47, 0xC4, 0xF0,
  44108. 0xC4, 0x56, 0xF0, 0x52, 0x59, 0xA6, 0xFA, 0x94,
  44109. 0xA6, 0x34, 0xA4, 0x0D, 0xAE, 0x1D, 0xF5, 0x93,
  44110. 0xD4, 0xFE, 0xCF, 0x68, 0x8D, 0x5F, 0xC6, 0x78,
  44111. 0xBE, 0x7E, 0xFC, 0x6D, 0xF3, 0xD6, 0x83, 0x53,
  44112. 0x25, 0xB8, 0x3B, 0x2C, 0x6E, 0x69, 0x03, 0x6B,
  44113. 0x15, 0x5F, 0x0A, 0x27, 0x24, 0x10, 0x94, 0xB0,
  44114. 0x4B, 0xFB, 0x0B, 0xDF, 0xAC, 0x6C, 0x67, 0x0A,
  44115. 0x65, 0xC3, 0x25, 0xD3, 0x9A, 0x06, 0x9F, 0x03,
  44116. 0x65, 0x9D, 0x44, 0xCA, 0x27, 0xD3, 0xBE, 0x8D,
  44117. 0xF3, 0x11, 0x17, 0x2B, 0x55, 0x41, 0x60, 0x18,
  44118. 0x1C, 0xBE, 0x94, 0xA2, 0xA7, 0x83, 0x32, 0x0C,
  44119. 0xED, 0x59, 0x0B, 0xC4, 0x26, 0x44, 0x70, 0x2C,
  44120. 0xF3, 0x71, 0x27, 0x1E, 0x49, 0x6B, 0xF2, 0x0F,
  44121. 0x58, 0x8B, 0x78, 0xA1, 0xBC, 0x01, 0xEC, 0xBB,
  44122. 0x65, 0x59, 0x93, 0x4B, 0xDD, 0x2F, 0xB6, 0x5D,
  44123. 0x28, 0x84, 0x31, 0x8A, 0x33, 0xD1, 0xA4, 0x2A,
  44124. 0xDF, 0x5E, 0x33, 0xCC, 0x58, 0x00, 0x28, 0x0B,
  44125. 0x28, 0x35, 0x64, 0x97, 0xF8, 0x71, 0x35, 0xBA,
  44126. 0xB9, 0x61, 0x2A, 0x17, 0x26, 0x04, 0x24, 0x40,
  44127. 0x9A, 0xC1, 0x5F, 0xEE, 0x99, 0x6B, 0x74, 0x4C,
  44128. 0x33, 0x21, 0x51, 0x23, 0x5D, 0xEC, 0xB0, 0xF5
  44129. };
  44130. WOLFSSL_SMALL_STACK_STATIC const byte id[] = {
  44131. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  44132. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  44133. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  44134. 0x33, 0x00
  44135. };
  44136. WOLFSSL_SMALL_STACK_STATIC const byte ssv[] = {
  44137. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  44138. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  44139. };
  44140. WOLFSSL_SMALL_STACK_STATIC const byte auth[] = {
  44141. 0x04,
  44142. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  44143. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  44144. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  44145. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  44146. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  44147. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  44148. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  44149. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  44150. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  44151. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  44152. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  44153. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  44154. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  44155. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  44156. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  44157. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  44158. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  44159. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  44160. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  44161. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  44162. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  44163. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  44164. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  44165. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  44166. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  44167. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  44168. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  44169. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  44170. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  44171. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  44172. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  44173. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  44174. };
  44175. WOLFSSL_SMALL_STACK_STATIC const byte encSsv[] = {
  44176. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  44177. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  44178. };
  44179. wc_test_ret_t ret;
  44180. int valid;
  44181. byte pubKey[sizeof(pubData) + 1];
  44182. word32 sz = sizeof(pubKey);
  44183. byte tmpSsv[sizeof(encSsv)];
  44184. byte* iTable = NULL;
  44185. word32 iTableLen;
  44186. byte* table = NULL;
  44187. word32 len;
  44188. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44189. if (ret != 0)
  44190. return WC_TEST_RET_ENC_EC(ret);
  44191. ret = wc_DecodeSakkeRsk(key, rskData, sizeof(rskData), rsk);
  44192. if (ret != 0)
  44193. return WC_TEST_RET_ENC_EC(ret);
  44194. ret = wc_ValidateSakkeRsk(key, id, sizeof(id), rsk, &valid);
  44195. if (ret != 0)
  44196. return WC_TEST_RET_ENC_EC(ret);
  44197. if (valid != 1)
  44198. return WC_TEST_RET_ENC_NC;
  44199. ret = wc_SetSakkeRsk(key, rsk, NULL, 0);
  44200. if (ret != 0)
  44201. return WC_TEST_RET_ENC_EC(ret);
  44202. ret = wc_SetSakkeIdentity(key, id, sizeof(id));
  44203. if (ret != 0)
  44204. return WC_TEST_RET_ENC_EC(ret);
  44205. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  44206. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  44207. auth, sizeof(auth));
  44208. if (ret != 0)
  44209. return WC_TEST_RET_ENC_EC(ret);
  44210. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  44211. return WC_TEST_RET_ENC_NC;
  44212. ret = wc_MakeSakkePointI(key, id, sizeof(id));
  44213. if (ret != 0)
  44214. return WC_TEST_RET_ENC_EC(ret);
  44215. iTableLen = 0;
  44216. ret = wc_GenerateSakkePointITable(key, NULL, &iTableLen);
  44217. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44218. return WC_TEST_RET_ENC_EC(ret);
  44219. if (iTableLen != 0) {
  44220. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44221. if (iTable == NULL)
  44222. return WC_TEST_RET_ENC_ERRNO;
  44223. ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen);
  44224. if (ret != 0)
  44225. return WC_TEST_RET_ENC_EC(ret);
  44226. }
  44227. len = 0;
  44228. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  44229. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44230. return WC_TEST_RET_ENC_EC(ret);
  44231. if (len > 0) {
  44232. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44233. if (table == NULL)
  44234. return WC_TEST_RET_ENC_ERRNO;
  44235. ret = wc_GenerateSakkeRskTable(key, rsk, table, &len);
  44236. if (ret != 0)
  44237. return WC_TEST_RET_ENC_EC(ret);
  44238. }
  44239. ret = wc_SetSakkeRsk(key, rsk, table, len);
  44240. if (ret != 0)
  44241. return WC_TEST_RET_ENC_EC(ret);
  44242. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  44243. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  44244. auth, sizeof(auth));
  44245. if (ret != 0)
  44246. return WC_TEST_RET_ENC_EC(ret);
  44247. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  44248. return WC_TEST_RET_ENC_NC;
  44249. /* Don't reference table that is about to be freed. */
  44250. ret = wc_ClearSakkePointITable(key);
  44251. if (ret != 0)
  44252. return WC_TEST_RET_ENC_EC(ret);
  44253. /* Dispose of tables */
  44254. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44255. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44256. /* Make sure the key public key is exportable - convert to Montgomery form
  44257. * in Validation.
  44258. */
  44259. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 1);
  44260. if (ret != 0)
  44261. return WC_TEST_RET_ENC_EC(ret);
  44262. if (sz != sizeof(pubData))
  44263. return WC_TEST_RET_ENC_NC;
  44264. if (XMEMCMP(pubKey, pubData, sizeof(pubData)) != 0)
  44265. return WC_TEST_RET_ENC_NC;
  44266. sz = sizeof(pubData) + 1;
  44267. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 0);
  44268. if (ret != 0)
  44269. return WC_TEST_RET_ENC_EC(ret);
  44270. if (sz != sizeof(pubData) + 1)
  44271. return WC_TEST_RET_ENC_NC;
  44272. if (pubKey[0] != 0x04)
  44273. return WC_TEST_RET_ENC_NC;
  44274. if (XMEMCMP(pubKey + 1, pubData, sizeof(pubData)) != 0)
  44275. return WC_TEST_RET_ENC_NC;
  44276. return 0;
  44277. }
  44278. static wc_test_ret_t sakke_kat_encapsulate_test(SakkeKey* key)
  44279. {
  44280. static const byte pubData[] = {
  44281. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  44282. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  44283. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  44284. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  44285. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  44286. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  44287. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  44288. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  44289. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  44290. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  44291. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  44292. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  44293. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  44294. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  44295. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  44296. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  44297. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  44298. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  44299. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  44300. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  44301. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  44302. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  44303. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  44304. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  44305. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  44306. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  44307. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  44308. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  44309. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  44310. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  44311. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  44312. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  44313. };
  44314. static const byte id[] = {
  44315. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  44316. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  44317. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  44318. 0x33, 0x00
  44319. };
  44320. static const word32 idSz = sizeof(id);
  44321. byte ssv[] = {
  44322. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  44323. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  44324. };
  44325. static const word16 ssvSz = sizeof(ssv);
  44326. static const byte expAuth[] = {
  44327. 0x04,
  44328. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  44329. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  44330. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  44331. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  44332. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  44333. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  44334. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  44335. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  44336. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  44337. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  44338. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  44339. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  44340. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  44341. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  44342. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  44343. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  44344. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  44345. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  44346. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  44347. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  44348. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  44349. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  44350. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  44351. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  44352. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  44353. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  44354. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  44355. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  44356. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  44357. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  44358. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  44359. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  44360. };
  44361. static const byte encSsv[] = {
  44362. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  44363. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  44364. };
  44365. wc_test_ret_t ret;
  44366. byte auth[257];
  44367. word16 authSz = sizeof(auth);
  44368. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44369. if (ret != 0)
  44370. return WC_TEST_RET_ENC_EC(ret);
  44371. ret = wc_SetSakkeIdentity(key, id, idSz);
  44372. if (ret != 0)
  44373. return WC_TEST_RET_ENC_EC(ret);
  44374. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44375. auth, &authSz);
  44376. if (ret != 0)
  44377. return WC_TEST_RET_ENC_EC(ret);
  44378. if (authSz != 257)
  44379. return WC_TEST_RET_ENC_NC;
  44380. if (XMEMCMP(ssv, encSsv, ssvSz) != 0)
  44381. return WC_TEST_RET_ENC_NC;
  44382. if (XMEMCMP(auth, expAuth, authSz) != 0)
  44383. return WC_TEST_RET_ENC_NC;
  44384. return 0;
  44385. }
  44386. static wc_test_ret_t sakke_make_key_test(SakkeKey* priv, SakkeKey* pub, SakkeKey* key,
  44387. WC_RNG* rng, ecc_point* rsk)
  44388. {
  44389. wc_test_ret_t ret;
  44390. byte data[440];
  44391. byte pubData[257];
  44392. word32 sz;
  44393. char mail[] = "test@wolfssl.com";
  44394. byte* id = (byte*)mail;
  44395. word32 idSz = (word32)XSTRLEN(mail);
  44396. int valid;
  44397. ecc_point* pubKey = rsk;
  44398. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44399. if (ret != 0)
  44400. return WC_TEST_RET_ENC_EC(ret);
  44401. ret = wc_MakeSakkeKey(priv, rng);
  44402. if (ret != 0)
  44403. return WC_TEST_RET_ENC_EC(ret);
  44404. ret = wc_ExportSakkeKey(priv, NULL, &sz);
  44405. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44406. return WC_TEST_RET_ENC_EC(ret);
  44407. if (sz != 384)
  44408. return WC_TEST_RET_ENC_NC;
  44409. sz--;
  44410. ret = wc_ExportSakkeKey(priv, data, &sz);
  44411. if (ret == 0)
  44412. return WC_TEST_RET_ENC_NC;
  44413. sz++;
  44414. ret = wc_ExportSakkeKey(priv, data, &sz);
  44415. if (ret != 0)
  44416. return WC_TEST_RET_ENC_EC(ret);
  44417. if (sz != 384)
  44418. return WC_TEST_RET_ENC_NC;
  44419. ret = wc_ImportSakkeKey(key, data, sz - 1);
  44420. if (ret == 0)
  44421. return WC_TEST_RET_ENC_NC;
  44422. ret = wc_ImportSakkeKey(key, data, sz);
  44423. if (ret != 0)
  44424. return WC_TEST_RET_ENC_EC(ret);
  44425. wc_FreeSakkeKey(key);
  44426. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44427. if (ret != 0)
  44428. return WC_TEST_RET_ENC_EC(ret);
  44429. ret = wc_ExportSakkePrivateKey(priv, NULL, &sz);
  44430. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44431. return WC_TEST_RET_ENC_EC(ret);
  44432. if (sz != 128)
  44433. return WC_TEST_RET_ENC_NC;
  44434. sz--;
  44435. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44436. if (ret == 0)
  44437. return WC_TEST_RET_ENC_NC;
  44438. sz++;
  44439. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44440. if (ret != 0)
  44441. return WC_TEST_RET_ENC_EC(ret);
  44442. if (sz != 128)
  44443. return WC_TEST_RET_ENC_NC;
  44444. ret = wc_ImportSakkePrivateKey(key, data, sz - 1);
  44445. if (ret == 0)
  44446. return WC_TEST_RET_ENC_NC;
  44447. ret = wc_ImportSakkePrivateKey(key, data, sz);
  44448. if (ret != 0)
  44449. return WC_TEST_RET_ENC_EC(ret);
  44450. ret = wc_MakeSakkePublicKey(key, pubKey);
  44451. if (ret != 0)
  44452. return WC_TEST_RET_ENC_EC(ret);
  44453. ret = wc_ExportSakkePublicKey(priv, NULL, &sz, 1);
  44454. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44455. return WC_TEST_RET_ENC_EC(ret);
  44456. if (sz != 256)
  44457. return WC_TEST_RET_ENC_NC;
  44458. sz--;
  44459. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44460. if (ret == 0)
  44461. return WC_TEST_RET_ENC_NC;
  44462. sz++;
  44463. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44464. if (ret != 0)
  44465. return WC_TEST_RET_ENC_EC(ret);
  44466. if (sz != 256)
  44467. return WC_TEST_RET_ENC_NC;
  44468. ret = wc_ImportSakkePublicKey(pub, data, sz - 1, 1);
  44469. if (ret == 0)
  44470. return WC_TEST_RET_ENC_NC;
  44471. ret = wc_ImportSakkePublicKey(pub, data, sz, 1);
  44472. if (ret != 0)
  44473. return WC_TEST_RET_ENC_EC(ret);
  44474. ret = wc_ExportSakkePublicKey(pub, pubData, &sz, 1);
  44475. if (ret != 0)
  44476. return WC_TEST_RET_ENC_EC(ret);
  44477. if (sz != 256)
  44478. return WC_TEST_RET_ENC_NC;
  44479. if (XMEMCMP(data, pubData, sz) != 0)
  44480. return WC_TEST_RET_ENC_NC;
  44481. ret = wc_MakeSakkeRsk(priv, id, idSz, rsk);
  44482. if (ret != 0)
  44483. return WC_TEST_RET_ENC_EC(ret);
  44484. ret = wc_ValidateSakkeRsk(priv, id, idSz, rsk, &valid);
  44485. if (ret != 0)
  44486. return WC_TEST_RET_ENC_EC(ret);
  44487. if (valid != 1)
  44488. return WC_TEST_RET_ENC_NC;
  44489. ret = wc_ValidateSakkeRsk(pub, id, idSz, rsk, &valid);
  44490. if (ret != 0)
  44491. return WC_TEST_RET_ENC_EC(ret);
  44492. if (valid != 1)
  44493. return WC_TEST_RET_ENC_NC;
  44494. sz = sizeof(data);
  44495. ret = wc_EncodeSakkeRsk(priv, rsk, data, &sz, 1);
  44496. if (ret != 0)
  44497. return WC_TEST_RET_ENC_EC(ret);
  44498. if (sz != 256)
  44499. return WC_TEST_RET_ENC_NC;
  44500. ret = wc_DecodeSakkeRsk(priv, data, sz, rsk);
  44501. if (ret != 0)
  44502. return WC_TEST_RET_ENC_EC(ret);
  44503. sz = sizeof(pubData);
  44504. ret = wc_EncodeSakkeRsk(priv, rsk, pubData, &sz, 0);
  44505. if (ret != 0)
  44506. return WC_TEST_RET_ENC_EC(ret);
  44507. if (sz != sizeof(pubData))
  44508. return WC_TEST_RET_ENC_NC;
  44509. ret = wc_DecodeSakkeRsk(priv, pubData, sz, rsk);
  44510. if (ret != 0)
  44511. return WC_TEST_RET_ENC_EC(ret);
  44512. wc_FreeSakkeKey(key);
  44513. return 0;
  44514. }
  44515. static wc_test_ret_t sakke_op_test(SakkeKey* priv, SakkeKey* pub, WC_RNG* rng,
  44516. ecc_point* rsk)
  44517. {
  44518. wc_test_ret_t ret;
  44519. byte ssv[16];
  44520. word16 ssvSz;
  44521. byte auth[257];
  44522. word16 authSz;
  44523. char mail[] = "test@wolfssl.com";
  44524. byte* id = (byte*)mail;
  44525. word32 idSz = (word32)XSTRLEN(mail);
  44526. byte pointI[256];
  44527. word32 sz;
  44528. ret = wc_GenerateSakkeSSV(pub, rng, NULL, &ssvSz);
  44529. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44530. return WC_TEST_RET_ENC_EC(ret);
  44531. if (ssvSz != 16)
  44532. return WC_TEST_RET_ENC_NC;
  44533. ssvSz += 128;
  44534. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44535. if (ret == 0)
  44536. return WC_TEST_RET_ENC_NC;
  44537. ssvSz -= 128;
  44538. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44539. if (ret != 0)
  44540. return WC_TEST_RET_ENC_EC(ret);
  44541. if (ssvSz != 16)
  44542. return WC_TEST_RET_ENC_NC;
  44543. ret = wc_GetSakkeAuthSize(pub, &authSz);
  44544. if (ret != 0)
  44545. return WC_TEST_RET_ENC_EC(ret);
  44546. ret = wc_SetSakkeIdentity(pub, id, idSz);
  44547. if (ret != 0)
  44548. return WC_TEST_RET_ENC_EC(ret);
  44549. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44550. NULL, &authSz);
  44551. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44552. return WC_TEST_RET_ENC_EC(ret);
  44553. if (authSz != 257)
  44554. return WC_TEST_RET_ENC_NC;
  44555. authSz--;
  44556. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44557. auth, &authSz);
  44558. if (ret == 0)
  44559. return WC_TEST_RET_ENC_NC;
  44560. authSz++;
  44561. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44562. auth, &authSz);
  44563. if (ret != 0)
  44564. return WC_TEST_RET_ENC_EC(ret);
  44565. if (authSz != 257)
  44566. return WC_TEST_RET_ENC_NC;
  44567. ret = wc_GetSakkePointI(pub, NULL, &sz);
  44568. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44569. return WC_TEST_RET_ENC_EC(ret);
  44570. if (sz != 256)
  44571. return WC_TEST_RET_ENC_NC;
  44572. ret = wc_GetSakkePointI(pub, pointI, &sz);
  44573. if (ret != 0)
  44574. return WC_TEST_RET_ENC_EC(ret);
  44575. if (sz != 256)
  44576. return WC_TEST_RET_ENC_NC;
  44577. /* Bogus identity - make it check and regenerate I. */
  44578. ret = wc_MakeSakkePointI(pub, ssv, ssvSz);
  44579. if (ret != 0)
  44580. return WC_TEST_RET_ENC_EC(ret);
  44581. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44582. auth, &authSz);
  44583. if (ret != 0)
  44584. return WC_TEST_RET_ENC_EC(ret);
  44585. if (authSz != 257)
  44586. return WC_TEST_RET_ENC_NC;
  44587. ret = wc_SetSakkeRsk(priv, rsk, NULL, 0);
  44588. if (ret != 0)
  44589. return WC_TEST_RET_ENC_EC(ret);
  44590. ret = wc_SetSakkeIdentity(priv, id, idSz);
  44591. if (ret != 0)
  44592. return WC_TEST_RET_ENC_EC(ret);
  44593. authSz--;
  44594. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44595. authSz);
  44596. if (ret == 0)
  44597. return WC_TEST_RET_ENC_NC;
  44598. authSz++;
  44599. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44600. authSz);
  44601. if (ret != 0)
  44602. return WC_TEST_RET_ENC_EC(ret);
  44603. ssv[0] ^= 0x80;
  44604. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44605. authSz);
  44606. if (ret != WC_NO_ERR_TRACE(SAKKE_VERIFY_FAIL_E))
  44607. return WC_TEST_RET_ENC_EC(ret);
  44608. ssv[0] ^= 0x80;
  44609. /* Bogus identity - make it check and regenerate I. */
  44610. ret = wc_MakeSakkePointI(pub, ssv, idSz);
  44611. if (ret != 0)
  44612. return WC_TEST_RET_ENC_EC(ret);
  44613. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44614. authSz);
  44615. if (ret != 0)
  44616. return WC_TEST_RET_ENC_EC(ret);
  44617. return 0;
  44618. }
  44619. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void)
  44620. {
  44621. wc_test_ret_t ret = 0;
  44622. WC_RNG rng;
  44623. int rng_inited = 0;
  44624. SakkeKey* priv = NULL;
  44625. SakkeKey* pub = NULL;
  44626. SakkeKey* key = NULL;
  44627. ecc_point* rsk = NULL;
  44628. WOLFSSL_ENTER("sakke_test");
  44629. priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44630. DYNAMIC_TYPE_TMP_BUFFER);
  44631. if (priv == NULL)
  44632. ret = WC_TEST_RET_ENC_NC;
  44633. else
  44634. XMEMSET(priv, 0, sizeof(*priv));
  44635. if (ret == 0) {
  44636. pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44637. DYNAMIC_TYPE_TMP_BUFFER);
  44638. if (pub == NULL)
  44639. ret = WC_TEST_RET_ENC_NC;
  44640. else
  44641. XMEMSET(pub, 0, sizeof(*pub));
  44642. }
  44643. if (ret == 0) {
  44644. key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44645. DYNAMIC_TYPE_TMP_BUFFER);
  44646. if (key == NULL)
  44647. ret = WC_TEST_RET_ENC_NC;
  44648. else
  44649. XMEMSET(key, 0, sizeof(*key));
  44650. }
  44651. if (ret == 0) {
  44652. #ifndef HAVE_FIPS
  44653. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  44654. #else
  44655. ret = wc_InitRng(&rng);
  44656. #endif
  44657. if (ret == 0)
  44658. rng_inited = 1;
  44659. else
  44660. ret = WC_TEST_RET_ENC_EC(ret);
  44661. }
  44662. if (ret == 0) {
  44663. rsk = wc_ecc_new_point();
  44664. if (rsk == NULL)
  44665. ret = WC_TEST_RET_ENC_NC;
  44666. }
  44667. if (ret == 0) {
  44668. ret = wc_InitSakkeKey(pub, HEAP_HINT, INVALID_DEVID);
  44669. if (ret != 0)
  44670. ret = WC_TEST_RET_ENC_EC(ret);
  44671. }
  44672. if (ret == 0) {
  44673. ret = wc_InitSakkeKey(priv, HEAP_HINT, INVALID_DEVID);
  44674. if (ret != 0)
  44675. ret = WC_TEST_RET_ENC_EC(ret);
  44676. }
  44677. if (ret == 0) {
  44678. ret = sakke_api_test(&rng, key, rsk);
  44679. }
  44680. if (ret == 0) {
  44681. ret = sakke_kat_derive_test(pub, rsk);
  44682. }
  44683. if (ret == 0) {
  44684. ret = sakke_kat_encapsulate_test(pub);
  44685. }
  44686. if (ret == 0) {
  44687. ret = sakke_make_key_test(priv, pub, key, &rng, rsk);
  44688. }
  44689. if (ret == 0) {
  44690. ret = sakke_op_test(priv, pub, &rng, rsk);
  44691. }
  44692. if (rsk != NULL) {
  44693. wc_ecc_forcezero_point(rsk);
  44694. wc_ecc_del_point(rsk);
  44695. }
  44696. if (rng_inited)
  44697. wc_FreeRng(&rng);
  44698. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44699. if (pub != NULL) {
  44700. wc_FreeSakkeKey(pub);
  44701. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44702. }
  44703. if (priv != NULL) {
  44704. wc_FreeSakkeKey(priv);
  44705. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44706. }
  44707. return ret;
  44708. }
  44709. #endif /* WOLFCRYPT_HAVE_SAKKE */
  44710. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  44711. typedef struct CMAC_Test_Case {
  44712. int type;
  44713. int partial;
  44714. const byte* m;
  44715. word32 mSz;
  44716. const byte* k;
  44717. word32 kSz;
  44718. const byte* t;
  44719. word32 tSz;
  44720. } CMAC_Test_Case;
  44721. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void)
  44722. {
  44723. #ifdef WOLFSSL_AES_128
  44724. WOLFSSL_SMALL_STACK_STATIC const byte k128[] =
  44725. {
  44726. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  44727. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  44728. };
  44729. #define KLEN_128 (sizeof(k128))
  44730. #endif
  44731. #ifdef WOLFSSL_AES_192
  44732. WOLFSSL_SMALL_STACK_STATIC const byte k192[] =
  44733. {
  44734. 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
  44735. 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
  44736. 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
  44737. };
  44738. #define KLEN_192 (sizeof(k192))
  44739. #endif
  44740. #ifdef WOLFSSL_AES_256
  44741. WOLFSSL_SMALL_STACK_STATIC const byte k256[] =
  44742. {
  44743. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  44744. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  44745. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  44746. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  44747. };
  44748. #define KLEN_256 (sizeof(k256))
  44749. #endif
  44750. WOLFSSL_SMALL_STACK_STATIC const byte m[] =
  44751. {
  44752. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  44753. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  44754. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  44755. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  44756. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  44757. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  44758. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  44759. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  44760. };
  44761. #define MLEN_0 (0)
  44762. #define MLEN_128 (128/8)
  44763. #define MLEN_320 (320/8)
  44764. #define MLEN_319 (MLEN_320 - 1)
  44765. #define MLEN_512 (512/8)
  44766. #ifdef WOLFSSL_AES_128
  44767. WOLFSSL_SMALL_STACK_STATIC const byte t128_0[] =
  44768. {
  44769. 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
  44770. 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
  44771. };
  44772. WOLFSSL_SMALL_STACK_STATIC const byte t128_128[] =
  44773. {
  44774. 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
  44775. 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
  44776. };
  44777. WOLFSSL_SMALL_STACK_STATIC const byte t128_319[] =
  44778. {
  44779. 0x2c, 0x17, 0x84, 0x4c, 0x93, 0x1c, 0x07, 0x95,
  44780. 0x15, 0x92, 0x73, 0x0a, 0x34, 0xd0, 0xd9, 0xd2
  44781. };
  44782. WOLFSSL_SMALL_STACK_STATIC const byte t128_320[] =
  44783. {
  44784. 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
  44785. 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
  44786. };
  44787. WOLFSSL_SMALL_STACK_STATIC const byte t128_512[] =
  44788. {
  44789. 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
  44790. 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
  44791. };
  44792. #endif
  44793. #ifdef WOLFSSL_AES_192
  44794. WOLFSSL_SMALL_STACK_STATIC const byte t192_0[] =
  44795. {
  44796. 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
  44797. 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
  44798. };
  44799. WOLFSSL_SMALL_STACK_STATIC const byte t192_128[] =
  44800. {
  44801. 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
  44802. 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
  44803. };
  44804. WOLFSSL_SMALL_STACK_STATIC const byte t192_320[] =
  44805. {
  44806. 0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
  44807. 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e
  44808. };
  44809. WOLFSSL_SMALL_STACK_STATIC const byte t192_512[] =
  44810. {
  44811. 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
  44812. 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
  44813. };
  44814. #endif
  44815. #ifdef WOLFSSL_AES_256
  44816. WOLFSSL_SMALL_STACK_STATIC const byte t256_0[] =
  44817. {
  44818. 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
  44819. 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
  44820. };
  44821. WOLFSSL_SMALL_STACK_STATIC const byte t256_128[] =
  44822. {
  44823. 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
  44824. 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
  44825. };
  44826. WOLFSSL_SMALL_STACK_STATIC const byte t256_320[] =
  44827. {
  44828. 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
  44829. 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6
  44830. };
  44831. WOLFSSL_SMALL_STACK_STATIC const byte t256_512[] =
  44832. {
  44833. 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
  44834. 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
  44835. };
  44836. #endif
  44837. const CMAC_Test_Case testCases[] =
  44838. {
  44839. #ifdef WOLFSSL_AES_128
  44840. {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, WC_AES_BLOCK_SIZE},
  44841. {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, WC_AES_BLOCK_SIZE},
  44842. {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, WC_AES_BLOCK_SIZE},
  44843. {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, WC_AES_BLOCK_SIZE},
  44844. {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, WC_AES_BLOCK_SIZE},
  44845. #endif
  44846. #ifdef WOLFSSL_AES_192
  44847. {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, WC_AES_BLOCK_SIZE},
  44848. {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, WC_AES_BLOCK_SIZE},
  44849. {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, WC_AES_BLOCK_SIZE},
  44850. {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, WC_AES_BLOCK_SIZE},
  44851. #endif
  44852. #ifdef WOLFSSL_AES_256
  44853. {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, WC_AES_BLOCK_SIZE},
  44854. {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, WC_AES_BLOCK_SIZE},
  44855. {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, WC_AES_BLOCK_SIZE},
  44856. {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, WC_AES_BLOCK_SIZE},
  44857. #endif
  44858. #ifdef WOLFSSL_AES_128
  44859. {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, WC_AES_BLOCK_SIZE}
  44860. #endif
  44861. };
  44862. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44863. Cmac *cmac;
  44864. #else
  44865. Cmac cmac[1];
  44866. #endif
  44867. byte tag[WC_AES_BLOCK_SIZE];
  44868. const CMAC_Test_Case* tc;
  44869. word32 i, tagSz;
  44870. wc_test_ret_t ret;
  44871. WOLFSSL_ENTER("cmac_test");
  44872. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44873. if ((cmac = (Cmac *)XMALLOC(sizeof *cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC)) == NULL)
  44874. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  44875. #endif
  44876. for (i = 0, tc = testCases;
  44877. i < sizeof(testCases)/sizeof(CMAC_Test_Case);
  44878. i++, tc++) {
  44879. XMEMSET(tag, 0, sizeof(tag));
  44880. tagSz = WC_AES_BLOCK_SIZE;
  44881. #if !defined(HAVE_FIPS) || \
  44882. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)
  44883. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44884. #else
  44885. ret = wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL);
  44886. #endif
  44887. if (ret != 0)
  44888. {
  44889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44890. }
  44891. if (tc->partial) {
  44892. ret = wc_CmacUpdate(cmac, tc->m,
  44893. tc->mSz/2 - tc->partial);
  44894. if (ret != 0)
  44895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44896. ret = wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial,
  44897. tc->mSz/2 + tc->partial);
  44898. if (ret != 0)
  44899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44900. }
  44901. else {
  44902. ret = wc_CmacUpdate(cmac, tc->m, tc->mSz);
  44903. if (ret != 0)
  44904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44905. }
  44906. ret = wc_CmacFinal(cmac, tag, &tagSz);
  44907. if (ret != 0)
  44908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44909. if (XMEMCMP(tag, tc->t, WC_AES_BLOCK_SIZE) != 0)
  44910. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44911. XMEMSET(tag, 0, sizeof(tag));
  44912. tagSz = sizeof(tag);
  44913. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44914. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44915. tc->k, tc->kSz, NULL, devId);
  44916. #else
  44917. ret = wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz,
  44918. tc->k, tc->kSz);
  44919. #endif
  44920. if (ret != 0)
  44921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44922. if (XMEMCMP(tag, tc->t, WC_AES_BLOCK_SIZE) != 0)
  44923. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44924. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44925. ret = wc_AesCmacVerify_ex(cmac, tc->t, tc->tSz, tc->m, tc->mSz,
  44926. tc->k, tc->kSz, HEAP_HINT, devId);
  44927. #else
  44928. ret = wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz,
  44929. tc->k, tc->kSz);
  44930. #endif
  44931. if (ret != 0)
  44932. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44933. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44934. /* Test that keyless generate with init is the same */
  44935. XMEMSET(tag, 0, sizeof(tag));
  44936. tagSz = sizeof(tag);
  44937. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44938. if (ret != 0) {
  44939. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44940. }
  44941. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44942. NULL, 0, HEAP_HINT, devId);
  44943. if (ret != 0) {
  44944. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44945. }
  44946. #endif
  44947. }
  44948. ret = 0;
  44949. out:
  44950. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44951. XFREE(cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC);
  44952. #endif
  44953. return ret;
  44954. }
  44955. #endif /* !NO_AES && WOLFSSL_CMAC */
  44956. #if defined(WOLFSSL_SIPHASH)
  44957. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44958. /* Test vectors from:
  44959. * https://github.com/veorq/SipHash/blob/master/vectors.h
  44960. */
  44961. static const unsigned char siphash_key[SIPHASH_KEY_SIZE] = {
  44962. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44963. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  44964. };
  44965. static const unsigned char siphash_msg[64] = {
  44966. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44967. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  44968. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  44969. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  44970. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  44971. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  44972. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  44973. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
  44974. };
  44975. static const unsigned char siphash_r8[64][SIPHASH_MAC_SIZE_8] = {
  44976. { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, },
  44977. { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, },
  44978. { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, },
  44979. { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, },
  44980. { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, },
  44981. { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, },
  44982. { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, },
  44983. { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, },
  44984. { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, },
  44985. { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, },
  44986. { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, },
  44987. { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, },
  44988. { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, },
  44989. { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, },
  44990. { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, },
  44991. { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, },
  44992. { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, },
  44993. { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, },
  44994. { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, },
  44995. { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, },
  44996. { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, },
  44997. { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, },
  44998. { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, },
  44999. { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, },
  45000. { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, },
  45001. { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, },
  45002. { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, },
  45003. { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, },
  45004. { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, },
  45005. { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, },
  45006. { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, },
  45007. { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, },
  45008. { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, },
  45009. { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, },
  45010. { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, },
  45011. { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, },
  45012. { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, },
  45013. { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, },
  45014. { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, },
  45015. { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, },
  45016. { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, },
  45017. { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, },
  45018. { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, },
  45019. { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, },
  45020. { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, },
  45021. { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, },
  45022. { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, },
  45023. { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, },
  45024. { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, },
  45025. { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, },
  45026. { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, },
  45027. { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, },
  45028. { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, },
  45029. { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, },
  45030. { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, },
  45031. { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, },
  45032. { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, },
  45033. { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, },
  45034. { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, },
  45035. { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, },
  45036. { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, },
  45037. { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, },
  45038. { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, },
  45039. { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, },
  45040. };
  45041. static const unsigned char siphash_r16[64][SIPHASH_MAC_SIZE_16] = {
  45042. { 0xa3, 0x81, 0x7f, 0x04, 0xba, 0x25, 0xa8, 0xe6,
  45043. 0x6d, 0xf6, 0x72, 0x14, 0xc7, 0x55, 0x02, 0x93, },
  45044. { 0xda, 0x87, 0xc1, 0xd8, 0x6b, 0x99, 0xaf, 0x44,
  45045. 0x34, 0x76, 0x59, 0x11, 0x9b, 0x22, 0xfc, 0x45, },
  45046. { 0x81, 0x77, 0x22, 0x8d, 0xa4, 0xa4, 0x5d, 0xc7,
  45047. 0xfc, 0xa3, 0x8b, 0xde, 0xf6, 0x0a, 0xff, 0xe4, },
  45048. { 0x9c, 0x70, 0xb6, 0x0c, 0x52, 0x67, 0xa9, 0x4e,
  45049. 0x5f, 0x33, 0xb6, 0xb0, 0x29, 0x85, 0xed, 0x51, },
  45050. { 0xf8, 0x81, 0x64, 0xc1, 0x2d, 0x9c, 0x8f, 0xaf,
  45051. 0x7d, 0x0f, 0x6e, 0x7c, 0x7b, 0xcd, 0x55, 0x79, },
  45052. { 0x13, 0x68, 0x87, 0x59, 0x80, 0x77, 0x6f, 0x88,
  45053. 0x54, 0x52, 0x7a, 0x07, 0x69, 0x0e, 0x96, 0x27, },
  45054. { 0x14, 0xee, 0xca, 0x33, 0x8b, 0x20, 0x86, 0x13,
  45055. 0x48, 0x5e, 0xa0, 0x30, 0x8f, 0xd7, 0xa1, 0x5e, },
  45056. { 0xa1, 0xf1, 0xeb, 0xbe, 0xd8, 0xdb, 0xc1, 0x53,
  45057. 0xc0, 0xb8, 0x4a, 0xa6, 0x1f, 0xf0, 0x82, 0x39, },
  45058. { 0x3b, 0x62, 0xa9, 0xba, 0x62, 0x58, 0xf5, 0x61,
  45059. 0x0f, 0x83, 0xe2, 0x64, 0xf3, 0x14, 0x97, 0xb4, },
  45060. { 0x26, 0x44, 0x99, 0x06, 0x0a, 0xd9, 0xba, 0xab,
  45061. 0xc4, 0x7f, 0x8b, 0x02, 0xbb, 0x6d, 0x71, 0xed, },
  45062. { 0x00, 0x11, 0x0d, 0xc3, 0x78, 0x14, 0x69, 0x56,
  45063. 0xc9, 0x54, 0x47, 0xd3, 0xf3, 0xd0, 0xfb, 0xba, },
  45064. { 0x01, 0x51, 0xc5, 0x68, 0x38, 0x6b, 0x66, 0x77,
  45065. 0xa2, 0xb4, 0xdc, 0x6f, 0x81, 0xe5, 0xdc, 0x18, },
  45066. { 0xd6, 0x26, 0xb2, 0x66, 0x90, 0x5e, 0xf3, 0x58,
  45067. 0x82, 0x63, 0x4d, 0xf6, 0x85, 0x32, 0xc1, 0x25, },
  45068. { 0x98, 0x69, 0xe2, 0x47, 0xe9, 0xc0, 0x8b, 0x10,
  45069. 0xd0, 0x29, 0x93, 0x4f, 0xc4, 0xb9, 0x52, 0xf7, },
  45070. { 0x31, 0xfc, 0xef, 0xac, 0x66, 0xd7, 0xde, 0x9c,
  45071. 0x7e, 0xc7, 0x48, 0x5f, 0xe4, 0x49, 0x49, 0x02, },
  45072. { 0x54, 0x93, 0xe9, 0x99, 0x33, 0xb0, 0xa8, 0x11,
  45073. 0x7e, 0x08, 0xec, 0x0f, 0x97, 0xcf, 0xc3, 0xd9, },
  45074. { 0x6e, 0xe2, 0xa4, 0xca, 0x67, 0xb0, 0x54, 0xbb,
  45075. 0xfd, 0x33, 0x15, 0xbf, 0x85, 0x23, 0x05, 0x77, },
  45076. { 0x47, 0x3d, 0x06, 0xe8, 0x73, 0x8d, 0xb8, 0x98,
  45077. 0x54, 0xc0, 0x66, 0xc4, 0x7a, 0xe4, 0x77, 0x40, },
  45078. { 0xa4, 0x26, 0xe5, 0xe4, 0x23, 0xbf, 0x48, 0x85,
  45079. 0x29, 0x4d, 0xa4, 0x81, 0xfe, 0xae, 0xf7, 0x23, },
  45080. { 0x78, 0x01, 0x77, 0x31, 0xcf, 0x65, 0xfa, 0xb0,
  45081. 0x74, 0xd5, 0x20, 0x89, 0x52, 0x51, 0x2e, 0xb1, },
  45082. { 0x9e, 0x25, 0xfc, 0x83, 0x3f, 0x22, 0x90, 0x73,
  45083. 0x3e, 0x93, 0x44, 0xa5, 0xe8, 0x38, 0x39, 0xeb, },
  45084. { 0x56, 0x8e, 0x49, 0x5a, 0xbe, 0x52, 0x5a, 0x21,
  45085. 0x8a, 0x22, 0x14, 0xcd, 0x3e, 0x07, 0x1d, 0x12, },
  45086. { 0x4a, 0x29, 0xb5, 0x45, 0x52, 0xd1, 0x6b, 0x9a,
  45087. 0x46, 0x9c, 0x10, 0x52, 0x8e, 0xff, 0x0a, 0xae, },
  45088. { 0xc9, 0xd1, 0x84, 0xdd, 0xd5, 0xa9, 0xf5, 0xe0,
  45089. 0xcf, 0x8c, 0xe2, 0x9a, 0x9a, 0xbf, 0x69, 0x1c, },
  45090. { 0x2d, 0xb4, 0x79, 0xae, 0x78, 0xbd, 0x50, 0xd8,
  45091. 0x88, 0x2a, 0x8a, 0x17, 0x8a, 0x61, 0x32, 0xad, },
  45092. { 0x8e, 0xce, 0x5f, 0x04, 0x2d, 0x5e, 0x44, 0x7b,
  45093. 0x50, 0x51, 0xb9, 0xea, 0xcb, 0x8d, 0x8f, 0x6f, },
  45094. { 0x9c, 0x0b, 0x53, 0xb4, 0xb3, 0xc3, 0x07, 0xe8,
  45095. 0x7e, 0xae, 0xe0, 0x86, 0x78, 0x14, 0x1f, 0x66, },
  45096. { 0xab, 0xf2, 0x48, 0xaf, 0x69, 0xa6, 0xea, 0xe4,
  45097. 0xbf, 0xd3, 0xeb, 0x2f, 0x12, 0x9e, 0xeb, 0x94, },
  45098. { 0x06, 0x64, 0xda, 0x16, 0x68, 0x57, 0x4b, 0x88,
  45099. 0xb9, 0x35, 0xf3, 0x02, 0x73, 0x58, 0xae, 0xf4, },
  45100. { 0xaa, 0x4b, 0x9d, 0xc4, 0xbf, 0x33, 0x7d, 0xe9,
  45101. 0x0c, 0xd4, 0xfd, 0x3c, 0x46, 0x7c, 0x6a, 0xb7, },
  45102. { 0xea, 0x5c, 0x7f, 0x47, 0x1f, 0xaf, 0x6b, 0xde,
  45103. 0x2b, 0x1a, 0xd7, 0xd4, 0x68, 0x6d, 0x22, 0x87, },
  45104. { 0x29, 0x39, 0xb0, 0x18, 0x32, 0x23, 0xfa, 0xfc,
  45105. 0x17, 0x23, 0xde, 0x4f, 0x52, 0xc4, 0x3d, 0x35, },
  45106. { 0x7c, 0x39, 0x56, 0xca, 0x5e, 0xea, 0xfc, 0x3e,
  45107. 0x36, 0x3e, 0x9d, 0x55, 0x65, 0x46, 0xeb, 0x68, },
  45108. { 0x77, 0xc6, 0x07, 0x71, 0x46, 0xf0, 0x1c, 0x32,
  45109. 0xb6, 0xb6, 0x9d, 0x5f, 0x4e, 0xa9, 0xff, 0xcf, },
  45110. { 0x37, 0xa6, 0x98, 0x6c, 0xb8, 0x84, 0x7e, 0xdf,
  45111. 0x09, 0x25, 0xf0, 0xf1, 0x30, 0x9b, 0x54, 0xde, },
  45112. { 0xa7, 0x05, 0xf0, 0xe6, 0x9d, 0xa9, 0xa8, 0xf9,
  45113. 0x07, 0x24, 0x1a, 0x2e, 0x92, 0x3c, 0x8c, 0xc8, },
  45114. { 0x3d, 0xc4, 0x7d, 0x1f, 0x29, 0xc4, 0x48, 0x46,
  45115. 0x1e, 0x9e, 0x76, 0xed, 0x90, 0x4f, 0x67, 0x11, },
  45116. { 0x0d, 0x62, 0xbf, 0x01, 0xe6, 0xfc, 0x0e, 0x1a,
  45117. 0x0d, 0x3c, 0x47, 0x51, 0xc5, 0xd3, 0x69, 0x2b, },
  45118. { 0x8c, 0x03, 0x46, 0x8b, 0xca, 0x7c, 0x66, 0x9e,
  45119. 0xe4, 0xfd, 0x5e, 0x08, 0x4b, 0xbe, 0xe7, 0xb5, },
  45120. { 0x52, 0x8a, 0x5b, 0xb9, 0x3b, 0xaf, 0x2c, 0x9c,
  45121. 0x44, 0x73, 0xcc, 0xe5, 0xd0, 0xd2, 0x2b, 0xd9, },
  45122. { 0xdf, 0x6a, 0x30, 0x1e, 0x95, 0xc9, 0x5d, 0xad,
  45123. 0x97, 0xae, 0x0c, 0xc8, 0xc6, 0x91, 0x3b, 0xd8, },
  45124. { 0x80, 0x11, 0x89, 0x90, 0x2c, 0x85, 0x7f, 0x39,
  45125. 0xe7, 0x35, 0x91, 0x28, 0x5e, 0x70, 0xb6, 0xdb, },
  45126. { 0xe6, 0x17, 0x34, 0x6a, 0xc9, 0xc2, 0x31, 0xbb,
  45127. 0x36, 0x50, 0xae, 0x34, 0xcc, 0xca, 0x0c, 0x5b, },
  45128. { 0x27, 0xd9, 0x34, 0x37, 0xef, 0xb7, 0x21, 0xaa,
  45129. 0x40, 0x18, 0x21, 0xdc, 0xec, 0x5a, 0xdf, 0x89, },
  45130. { 0x89, 0x23, 0x7d, 0x9d, 0xed, 0x9c, 0x5e, 0x78,
  45131. 0xd8, 0xb1, 0xc9, 0xb1, 0x66, 0xcc, 0x73, 0x42, },
  45132. { 0x4a, 0x6d, 0x80, 0x91, 0xbf, 0x5e, 0x7d, 0x65,
  45133. 0x11, 0x89, 0xfa, 0x94, 0xa2, 0x50, 0xb1, 0x4c, },
  45134. { 0x0e, 0x33, 0xf9, 0x60, 0x55, 0xe7, 0xae, 0x89,
  45135. 0x3f, 0xfc, 0x0e, 0x3d, 0xcf, 0x49, 0x29, 0x02, },
  45136. { 0xe6, 0x1c, 0x43, 0x2b, 0x72, 0x0b, 0x19, 0xd1,
  45137. 0x8e, 0xc8, 0xd8, 0x4b, 0xdc, 0x63, 0x15, 0x1b, },
  45138. { 0xf7, 0xe5, 0xae, 0xf5, 0x49, 0xf7, 0x82, 0xcf,
  45139. 0x37, 0x90, 0x55, 0xa6, 0x08, 0x26, 0x9b, 0x16, },
  45140. { 0x43, 0x8d, 0x03, 0x0f, 0xd0, 0xb7, 0xa5, 0x4f,
  45141. 0xa8, 0x37, 0xf2, 0xad, 0x20, 0x1a, 0x64, 0x03, },
  45142. { 0xa5, 0x90, 0xd3, 0xee, 0x4f, 0xbf, 0x04, 0xe3,
  45143. 0x24, 0x7e, 0x0d, 0x27, 0xf2, 0x86, 0x42, 0x3f, },
  45144. { 0x5f, 0xe2, 0xc1, 0xa1, 0x72, 0xfe, 0x93, 0xc4,
  45145. 0xb1, 0x5c, 0xd3, 0x7c, 0xae, 0xf9, 0xf5, 0x38, },
  45146. { 0x2c, 0x97, 0x32, 0x5c, 0xbd, 0x06, 0xb3, 0x6e,
  45147. 0xb2, 0x13, 0x3d, 0xd0, 0x8b, 0x3a, 0x01, 0x7c, },
  45148. { 0x92, 0xc8, 0x14, 0x22, 0x7a, 0x6b, 0xca, 0x94,
  45149. 0x9f, 0xf0, 0x65, 0x9f, 0x00, 0x2a, 0xd3, 0x9e, },
  45150. { 0xdc, 0xe8, 0x50, 0x11, 0x0b, 0xd8, 0x32, 0x8c,
  45151. 0xfb, 0xd5, 0x08, 0x41, 0xd6, 0x91, 0x1d, 0x87, },
  45152. { 0x67, 0xf1, 0x49, 0x84, 0xc7, 0xda, 0x79, 0x12,
  45153. 0x48, 0xe3, 0x2b, 0xb5, 0x92, 0x25, 0x83, 0xda, },
  45154. { 0x19, 0x38, 0xf2, 0xcf, 0x72, 0xd5, 0x4e, 0xe9,
  45155. 0x7e, 0x94, 0x16, 0x6f, 0xa9, 0x1d, 0x2a, 0x36, },
  45156. { 0x74, 0x48, 0x1e, 0x96, 0x46, 0xed, 0x49, 0xfe,
  45157. 0x0f, 0x62, 0x24, 0x30, 0x16, 0x04, 0x69, 0x8e, },
  45158. { 0x57, 0xfc, 0xa5, 0xde, 0x98, 0xa9, 0xd6, 0xd8,
  45159. 0x00, 0x64, 0x38, 0xd0, 0x58, 0x3d, 0x8a, 0x1d, },
  45160. { 0x9f, 0xec, 0xde, 0x1c, 0xef, 0xdc, 0x1c, 0xbe,
  45161. 0xd4, 0x76, 0x36, 0x74, 0xd9, 0x57, 0x53, 0x59, },
  45162. { 0xe3, 0x04, 0x0c, 0x00, 0xeb, 0x28, 0xf1, 0x53,
  45163. 0x66, 0xca, 0x73, 0xcb, 0xd8, 0x72, 0xe7, 0x40, },
  45164. { 0x76, 0x97, 0x00, 0x9a, 0x6a, 0x83, 0x1d, 0xfe,
  45165. 0xcc, 0xa9, 0x1c, 0x59, 0x93, 0x67, 0x0f, 0x7a, },
  45166. { 0x58, 0x53, 0x54, 0x23, 0x21, 0xf5, 0x67, 0xa0,
  45167. 0x05, 0xd5, 0x47, 0xa4, 0xf0, 0x47, 0x59, 0xbd, },
  45168. { 0x51, 0x50, 0xd1, 0x77, 0x2f, 0x50, 0x83, 0x4a,
  45169. 0x50, 0x3e, 0x06, 0x9a, 0x97, 0x3f, 0xbd, 0x7c, },
  45170. };
  45171. #endif
  45172. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void)
  45173. {
  45174. wc_test_ret_t ret = 0;
  45175. int i;
  45176. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  45177. unsigned char res[SIPHASH_MAC_SIZE_16];
  45178. unsigned char tmp[SIPHASH_MAC_SIZE_8];
  45179. SipHash siphash;
  45180. WOLFSSL_ENTER("siphash_test (1)");
  45181. for (i = 0; i < 64; i++) {
  45182. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45183. if (ret != 0)
  45184. return WC_TEST_RET_ENC_I(i);
  45185. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  45186. if (ret != 0)
  45187. return WC_TEST_RET_ENC_I(i);
  45188. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  45189. if (ret != 0)
  45190. return WC_TEST_RET_ENC_I(i);
  45191. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  45192. return WC_TEST_RET_ENC_I(i);
  45193. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_8);
  45194. if (ret != 0)
  45195. return WC_TEST_RET_ENC_I(i);
  45196. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  45197. return WC_TEST_RET_ENC_I(i);
  45198. }
  45199. for (i = 0; i < 64; i++) {
  45200. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_16);
  45201. if (ret != 0)
  45202. return WC_TEST_RET_ENC_I(i);
  45203. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  45204. if (ret != 0)
  45205. return WC_TEST_RET_ENC_I(i);
  45206. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  45207. if (ret != 0)
  45208. return WC_TEST_RET_ENC_I(i);
  45209. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  45210. return WC_TEST_RET_ENC_I(i);
  45211. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_16);
  45212. if (ret != 0)
  45213. return WC_TEST_RET_ENC_I(i);
  45214. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  45215. return WC_TEST_RET_ENC_I(i);
  45216. }
  45217. #else
  45218. WOLFSSL_ENTER("siphash_test (1)");
  45219. #endif
  45220. /* Testing bad parameters. */
  45221. ret = wc_InitSipHash(NULL, NULL, SIPHASH_MAC_SIZE_8);
  45222. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45223. return WC_TEST_RET_ENC_EC(ret);
  45224. ret = wc_InitSipHash(NULL, siphash_key, 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(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  45228. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45229. return WC_TEST_RET_ENC_EC(ret);
  45230. ret = wc_InitSipHash(&siphash, siphash_key, 7);
  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, SIPHASH_MAC_SIZE_8);
  45234. if (ret != 0)
  45235. return WC_TEST_RET_ENC_EC(ret);
  45236. ret = wc_SipHashUpdate(NULL, NULL, 0);
  45237. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45238. return WC_TEST_RET_ENC_EC(ret);
  45239. ret = wc_SipHashUpdate(&siphash, NULL, 1);
  45240. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45241. return WC_TEST_RET_ENC_EC(ret);
  45242. ret = wc_SipHashFinal(NULL, NULL, SIPHASH_MAC_SIZE_8);
  45243. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45244. return WC_TEST_RET_ENC_EC(ret);
  45245. ret = wc_SipHashFinal(&siphash, 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(NULL, res, 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(&siphash, res, SIPHASH_MAC_SIZE_16);
  45252. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45253. return WC_TEST_RET_ENC_EC(ret);
  45254. ret = wc_SipHash(NULL, NULL, 0, NULL, 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(siphash_key, 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(NULL, NULL, 0, res, 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(siphash_key, NULL, 0, res, 15);
  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, 1, res, SIPHASH_MAC_SIZE_16);
  45267. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45268. return WC_TEST_RET_ENC_EC(ret);
  45269. /* Test cache with multiple non blocksize bytes */
  45270. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45271. if (ret != 0)
  45272. return WC_TEST_RET_ENC_EC(ret);
  45273. ret = wc_SipHashUpdate(&siphash, siphash_msg, 5);
  45274. if (ret != 0)
  45275. return WC_TEST_RET_ENC_EC(ret);
  45276. ret = wc_SipHashUpdate(&siphash, siphash_msg + 5, 4);
  45277. if (ret != 0)
  45278. return WC_TEST_RET_ENC_EC(ret);
  45279. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  45280. if (ret != 0)
  45281. return WC_TEST_RET_ENC_EC(ret);
  45282. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45283. if (ret != 0)
  45284. return WC_TEST_RET_ENC_EC(ret);
  45285. ret = wc_SipHashUpdate(&siphash, siphash_msg, 9);
  45286. if (ret != 0)
  45287. return WC_TEST_RET_ENC_EC(ret);
  45288. ret = wc_SipHashFinal(&siphash, tmp, SIPHASH_MAC_SIZE_8);
  45289. if (ret != 0)
  45290. return WC_TEST_RET_ENC_EC(ret);
  45291. if (XMEMCMP(res, tmp, SIPHASH_MAC_SIZE_8) != 0)
  45292. return WC_TEST_RET_ENC_NC;
  45293. return 0;
  45294. }
  45295. #endif /* WOLFSSL_SIPHASH */
  45296. #ifdef HAVE_LIBZ
  45297. static const byte sample_text[] =
  45298. "Biodiesel cupidatat marfa, cliche aute put a bird on it incididunt elit\n"
  45299. "polaroid. Sunt tattooed bespoke reprehenderit. Sint twee organic id\n"
  45300. "marfa. Commodo veniam ad esse gastropub. 3 wolf moon sartorial vero,\n"
  45301. "plaid delectus biodiesel squid +1 vice. Post-ironic keffiyeh leggings\n"
  45302. "selfies cray fap hoodie, forage anim. Carles cupidatat shoreditch, VHS\n"
  45303. "small batch meggings kogi dolore food truck bespoke gastropub.\n"
  45304. "\n"
  45305. "Terry richardson adipisicing actually typewriter tumblr, twee whatever\n"
  45306. "four loko you probably haven't heard of them high life. Messenger bag\n"
  45307. "whatever tattooed deep v mlkshk. Brooklyn pinterest assumenda chillwave\n"
  45308. "et, banksy ullamco messenger bag umami pariatur direct trade forage.\n"
  45309. "Typewriter culpa try-hard, pariatur sint brooklyn meggings. Gentrify\n"
  45310. "food truck next level, tousled irony non semiotics PBR ethical anim cred\n"
  45311. "readymade. Mumblecore brunch lomo odd future, portland organic terry\n"
  45312. "richardson elit leggings adipisicing ennui raw denim banjo hella. Godard\n"
  45313. "mixtape polaroid, pork belly readymade organic cray typewriter helvetica\n"
  45314. "four loko whatever street art yr farm-to-table.\n"
  45315. "\n"
  45316. "Vinyl keytar vice tofu. Locavore you probably haven't heard of them pug\n"
  45317. "pickled, hella tonx labore truffaut DIY mlkshk elit cosby sweater sint\n"
  45318. "et mumblecore. Elit swag semiotics, reprehenderit DIY sartorial nisi ugh\n"
  45319. "nesciunt pug pork belly wayfarers selfies delectus. Ethical hoodie\n"
  45320. "seitan fingerstache kale chips. Terry richardson artisan williamsburg,\n"
  45321. "eiusmod fanny pack irony tonx ennui lo-fi incididunt tofu YOLO\n"
  45322. "readymade. 8-bit sed ethnic beard officia. Pour-over iphone DIY butcher,\n"
  45323. "ethnic art party qui letterpress nisi proident jean shorts mlkshk\n"
  45324. "locavore.\n"
  45325. "\n"
  45326. "Narwhal flexitarian letterpress, do gluten-free voluptate next level\n"
  45327. "banh mi tonx incididunt carles DIY. Odd future nulla 8-bit beard ut\n"
  45328. "cillum pickled velit, YOLO officia you probably haven't heard of them\n"
  45329. "trust fund gastropub. Nisi adipisicing tattooed, Austin mlkshk 90's\n"
  45330. "small batch american apparel. Put a bird on it cosby sweater before they\n"
  45331. "sold out pork belly kogi hella. Street art mollit sustainable polaroid,\n"
  45332. "DIY ethnic ea pug beard dreamcatcher cosby sweater magna scenester nisi.\n"
  45333. "Sed pork belly skateboard mollit, labore proident eiusmod. Sriracha\n"
  45334. "excepteur cosby sweater, anim deserunt laborum eu aliquip ethical et\n"
  45335. "neutra PBR selvage.\n"
  45336. "\n"
  45337. "Raw denim pork belly truffaut, irony plaid sustainable put a bird on it\n"
  45338. "next level jean shorts exercitation. Hashtag keytar whatever, nihil\n"
  45339. "authentic aliquip disrupt laborum. Tattooed selfies deserunt trust fund\n"
  45340. "wayfarers. 3 wolf moon synth church-key sartorial, gastropub leggings\n"
  45341. "tattooed. Labore high life commodo, meggings raw denim fingerstache pug\n"
  45342. "trust fund leggings seitan forage. Nostrud ullamco duis, reprehenderit\n"
  45343. "incididunt flannel sustainable helvetica pork belly pug banksy you\n"
  45344. "probably haven't heard of them nesciunt farm-to-table. Disrupt nostrud\n"
  45345. "mollit magna, sriracha sartorial helvetica.\n"
  45346. "\n"
  45347. "Nulla kogi reprehenderit, skateboard sustainable duis adipisicing viral\n"
  45348. "ad fanny pack salvia. Fanny pack trust fund you probably haven't heard\n"
  45349. "of them YOLO vice nihil. Keffiyeh cray lo-fi pinterest cardigan aliqua,\n"
  45350. "reprehenderit aute. Culpa tousled williamsburg, marfa lomo actually anim\n"
  45351. "skateboard. Iphone aliqua ugh, semiotics pariatur vero readymade\n"
  45352. "organic. Marfa squid nulla, in laborum disrupt laboris irure gastropub.\n"
  45353. "Veniam sunt food truck leggings, sint vinyl fap.\n"
  45354. "\n"
  45355. "Hella dolore pork belly, truffaut carles you probably haven't heard of\n"
  45356. "them PBR helvetica in sapiente. Fashion axe ugh bushwick american\n"
  45357. "apparel. Fingerstache sed iphone, jean shorts blue bottle nisi bushwick\n"
  45358. "flexitarian officia veniam plaid bespoke fap YOLO lo-fi. Blog\n"
  45359. "letterpress mumblecore, food truck id cray brooklyn cillum ad sed.\n"
  45360. "Assumenda chambray wayfarers vinyl mixtape sustainable. VHS vinyl\n"
  45361. "delectus, culpa williamsburg polaroid cliche swag church-key synth kogi\n"
  45362. "magna pop-up literally. Swag thundercats ennui shoreditch vegan\n"
  45363. "pitchfork neutra truffaut etsy, sed single-origin coffee craft beer.\n"
  45364. "\n"
  45365. "Odio letterpress brooklyn elit. Nulla single-origin coffee in occaecat\n"
  45366. "meggings. Irony meggings 8-bit, chillwave lo-fi adipisicing cred\n"
  45367. "dreamcatcher veniam. Put a bird on it irony umami, trust fund bushwick\n"
  45368. "locavore kale chips. Sriracha swag thundercats, chillwave disrupt\n"
  45369. "tousled beard mollit mustache leggings portland next level. Nihil esse\n"
  45370. "est, skateboard art party etsy thundercats sed dreamcatcher ut iphone\n"
  45371. "swag consectetur et. Irure skateboard banjo, nulla deserunt messenger\n"
  45372. "bag dolor terry richardson sapiente.\n";
  45373. static const byte sample_text_gz[] = {
  45374. 0x1F, 0x8B, 0x08, 0x08, 0xC5, 0x49, 0xB5, 0x5B, 0x00, 0x03, 0x63, 0x69, 0x70,
  45375. 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x8D,
  45376. 0x58, 0xCB, 0x92, 0xE4, 0xB6, 0x11, 0xBC, 0xE3, 0x2B, 0xEA, 0xA6, 0x83, 0xD9,
  45377. 0x1D, 0x72, 0xF8, 0x22, 0x1F, 0xB5, 0x96, 0xA5, 0xDD, 0x90, 0xBC, 0xAB, 0xD0,
  45378. 0x28, 0x36, 0x42, 0x47, 0x90, 0x2C, 0x36, 0xA1, 0x06, 0x09, 0x0A, 0x8F, 0xEE,
  45379. 0xE1, 0xDF, 0x3B, 0x0B, 0xE0, 0x73, 0x2C, 0x4B, 0xBA, 0xCD, 0xCE, 0x80, 0x78,
  45380. 0x64, 0x65, 0x65, 0x66, 0xED, 0x3B, 0xE3, 0x5A, 0xC3, 0x81, 0x2D, 0x35, 0x69,
  45381. 0x32, 0xAD, 0x8E, 0x3A, 0xD2, 0xA0, 0x7D, 0xA7, 0x2B, 0x6A, 0xAC, 0x69, 0x7A,
  45382. 0x26, 0x9D, 0x22, 0xD3, 0x94, 0x22, 0x69, 0xAA, 0x8D, 0x6F, 0xC9, 0x8D, 0x64,
  45383. 0x22, 0x99, 0xB1, 0x31, 0xAD, 0x69, 0xD3, 0x18, 0x89, 0xAD, 0x89, 0x6A, 0x72,
  45384. 0x56, 0x7B, 0x67, 0xDA, 0x2B, 0xBD, 0xC8, 0xEF, 0xB0, 0x4D, 0x74, 0x8E, 0x5B,
  45385. 0xAA, 0x39, 0x4C, 0xEE, 0xCE, 0xE4, 0x79, 0xF2, 0xDC, 0xF3, 0xD8, 0xB2, 0x37,
  45386. 0x11, 0x8B, 0x8C, 0x2C, 0x7A, 0x32, 0x93, 0xF3, 0x37, 0x3D, 0x9A, 0x86, 0x4C,
  45387. 0xAB, 0xF2, 0xB9, 0x57, 0xFA, 0x97, 0x1B, 0x06, 0xD7, 0x3A, 0x7A, 0xF0, 0x68,
  45388. 0xF4, 0x40, 0xBA, 0x25, 0x0E, 0x81, 0xE9, 0xA6, 0x43, 0xF4, 0x6E, 0x4A, 0xF5,
  45389. 0x95, 0xFE, 0x41, 0x4F, 0x67, 0x3B, 0x1A, 0x1C, 0xEE, 0x12, 0xB4, 0x8F, 0xCE,
  45390. 0x1B, 0x6D, 0xB1, 0xDE, 0xBB, 0x4A, 0x4D, 0x56, 0x9B, 0x96, 0x5A, 0xB6, 0xDC,
  45391. 0xC4, 0x14, 0x70, 0xE5, 0xF5, 0x7D, 0xE1, 0xB7, 0x84, 0x3F, 0xFC, 0xED, 0xEF,
  45392. 0xF4, 0x30, 0x0D, 0x5F, 0xE9, 0x47, 0x17, 0xE2, 0xC5, 0x78, 0x27, 0x67, 0xDF,
  45393. 0xB9, 0xEB, 0xCC, 0xCC, 0x3D, 0x59, 0xBE, 0xDD, 0xCC, 0x78, 0x0B, 0x0A, 0x1F,
  45394. 0x74, 0xF8, 0x8C, 0x1A, 0xAF, 0x67, 0xEA, 0xF4, 0x44, 0xBD, 0x93, 0x7D, 0x2A,
  45395. 0xEA, 0x9C, 0xD7, 0x37, 0x80, 0x32, 0x9A, 0x01, 0x37, 0xD5, 0xDE, 0xCA, 0xA2,
  45396. 0x0D, 0xB9, 0xD0, 0x3B, 0xCF, 0xAD, 0x89, 0x4D, 0x5F, 0xD1, 0xE7, 0xF7, 0x2F,
  45397. 0x2A, 0x0C, 0xDA, 0x5A, 0xAA, 0x35, 0x7E, 0x41, 0xC3, 0xB2, 0x37, 0xDD, 0xDD,
  45398. 0xCD, 0x50, 0xEB, 0x2C, 0x96, 0x62, 0x3B, 0xD7, 0x52, 0xF4, 0xA9, 0xB9, 0x6F,
  45399. 0x48, 0xED, 0xEF, 0x54, 0xEA, 0x67, 0xF6, 0x7E, 0x26, 0x8F, 0x3A, 0x68, 0xDF,
  45400. 0x06, 0xBC, 0x56, 0xB7, 0x66, 0x32, 0xC1, 0x34, 0xD8, 0x88, 0x34, 0x1E, 0x88,
  45401. 0xED, 0x67, 0x8A, 0xF3, 0xC4, 0x4F, 0xC0, 0xCA, 0x9E, 0x62, 0x1A, 0x6A, 0xEB,
  45402. 0xAB, 0x02, 0xED, 0xB3, 0xD7, 0x91, 0x81, 0x8A, 0xEA, 0x5C, 0xF2, 0x64, 0xDD,
  45403. 0xDD, 0xD1, 0xEC, 0x12, 0x4D, 0xDE, 0xD5, 0xBA, 0xC6, 0x77, 0xBD, 0x06, 0xC4,
  45404. 0x5F, 0x44, 0xEA, 0x59, 0x4B, 0x5D, 0x3B, 0x8A, 0x3D, 0x0F, 0xD4, 0x9B, 0x1B,
  45405. 0x80, 0x30, 0x1D, 0x30, 0xFA, 0x8F, 0x00, 0x3F, 0xDE, 0xB0, 0x6F, 0xAD, 0x6F,
  45406. 0x6A, 0xDD, 0x6E, 0x2F, 0x6E, 0xCB, 0x3C, 0xD1, 0x83, 0x06, 0x7B, 0x0F, 0xFD,
  45407. 0xFD, 0x4A, 0xEF, 0xBC, 0x73, 0x77, 0x3B, 0x8F, 0x34, 0xA1, 0xBA, 0xEC, 0x39,
  45408. 0x80, 0x33, 0x21, 0xA4, 0x01, 0x55, 0xD7, 0xD4, 0xF4, 0xC6, 0xDA, 0x27, 0x4E,
  45409. 0x54, 0x1C, 0x2B, 0xEC, 0x37, 0xDE, 0xC3, 0x4C, 0xC9, 0x5A, 0x3D, 0x34, 0x0E,
  45410. 0xD8, 0x1C, 0x0E, 0xA2, 0x34, 0xE8, 0xC1, 0xD0, 0xA4, 0x51, 0xD5, 0x88, 0x8B,
  45411. 0xB7, 0xC6, 0xA3, 0x96, 0x40, 0x49, 0xB7, 0xBC, 0xE0, 0x7F, 0x55, 0x3F, 0xEF,
  45412. 0x6F, 0x6E, 0x92, 0x9D, 0x34, 0xFE, 0x3C, 0x5F, 0x04, 0xA5, 0x6A, 0xFF, 0x30,
  45413. 0x08, 0xC9, 0xEA, 0xF5, 0x52, 0x2B, 0xFE, 0x57, 0xFA, 0x8E, 0xC7, 0xE8, 0x4D,
  45414. 0x37, 0xAB, 0x03, 0xFA, 0x23, 0xBF, 0x46, 0x94, 0xFF, 0xC1, 0x16, 0xE0, 0xB9,
  45415. 0x14, 0x2C, 0x9E, 0x27, 0xEC, 0x98, 0x69, 0x14, 0x92, 0xF1, 0x60, 0x5C, 0x34,
  45416. 0x4D, 0xA0, 0x1F, 0xDF, 0xFD, 0x44, 0x1C, 0x7B, 0xD3, 0x80, 0x70, 0x42, 0x02,
  45417. 0x30, 0x84, 0x5B, 0xE5, 0x59, 0xB7, 0xF3, 0x80, 0xFB, 0x01, 0x33, 0xA9, 0x00,
  45418. 0x37, 0x52, 0xDC, 0xDA, 0xA7, 0x11, 0x85, 0xB7, 0x6E, 0x70, 0xE4, 0xDA, 0x96,
  45419. 0xBA, 0x84, 0x5B, 0x81, 0x43, 0x93, 0xF3, 0xD1, 0xEA, 0xB1, 0xDD, 0xB8, 0x1F,
  45420. 0xA5, 0xCC, 0xEA, 0x50, 0x66, 0x69, 0xA9, 0x8D, 0x8C, 0xA7, 0xA2, 0xF3, 0x38,
  45421. 0x26, 0x43, 0x5E, 0x3F, 0x01, 0xBE, 0x1C, 0x0F, 0x20, 0x7F, 0x75, 0xA8, 0x20,
  45422. 0x80, 0xC4, 0xC3, 0x5C, 0x8B, 0x0D, 0xD4, 0x60, 0x5E, 0xA3, 0x9E, 0xD0, 0xB4,
  45423. 0x4B, 0x4F, 0xE6, 0x13, 0x85, 0x60, 0x42, 0x96, 0xED, 0xAA, 0xDB, 0xE9, 0x99,
  45424. 0xE3, 0x07, 0x0E, 0x61, 0xB3, 0x07, 0xE3, 0xB1, 0xFA, 0xC0, 0x9B, 0xAD, 0xF6,
  45425. 0xE0, 0x26, 0x33, 0xEA, 0xEA, 0x23, 0xCD, 0x1E, 0x9D, 0xE1, 0x87, 0x4B, 0x74,
  45426. 0x97, 0x08, 0x3E, 0xA1, 0x28, 0xEA, 0xB3, 0x19, 0x67, 0x8B, 0x76, 0x9A, 0xA3,
  45427. 0xF6, 0xB9, 0xCF, 0x80, 0x65, 0x97, 0xAE, 0xF4, 0x83, 0x6B, 0xF4, 0x43, 0x20,
  45428. 0xF9, 0x0B, 0xFC, 0x9B, 0xD2, 0x4D, 0x4D, 0xA6, 0xB9, 0xA3, 0x02, 0x55, 0x79,
  45429. 0x18, 0x36, 0x19, 0x5F, 0xC9, 0xEA, 0x5A, 0x76, 0x40, 0xB9, 0xBA, 0x0E, 0x9A,
  45430. 0x44, 0xDF, 0x7C, 0xF8, 0x65, 0x61, 0x5E, 0x81, 0xAB, 0x71, 0xA1, 0x9E, 0x29,
  45431. 0x3C, 0x59, 0xCB, 0x23, 0xA4, 0xF6, 0x60, 0x1A, 0x0D, 0x5B, 0x39, 0xAE, 0xF4,
  45432. 0x6F, 0x59, 0x16, 0x9E, 0x60, 0xD8, 0x56, 0xCF, 0xEA, 0x2C, 0x4C, 0x79, 0xD3,
  45433. 0x5D, 0x51, 0x46, 0xA0, 0x4E, 0xE9, 0xD6, 0xAB, 0x91, 0x43, 0x63, 0x44, 0xD7,
  45434. 0x70, 0xB9, 0x23, 0x98, 0x4F, 0x3D, 0x03, 0x02, 0xF6, 0x81, 0x56, 0xC1, 0x58,
  45435. 0x85, 0x07, 0xA7, 0x2D, 0x2C, 0x29, 0xCA, 0x01, 0x45, 0x31, 0x51, 0x8F, 0xD4,
  45436. 0x19, 0xA1, 0x79, 0x88, 0x5A, 0xA4, 0xF5, 0xAE, 0x2D, 0x4B, 0x63, 0x4C, 0x58,
  45437. 0xFE, 0xBF, 0xAD, 0xEE, 0xA3, 0x09, 0xF8, 0xE2, 0x89, 0xBE, 0x81, 0x0E, 0x86,
  45438. 0x3A, 0xF9, 0x5B, 0xA5, 0xD8, 0xA4, 0x00, 0x75, 0x04, 0xF2, 0x23, 0xB8, 0x39,
  45439. 0x69, 0x50, 0xB7, 0xD0, 0x34, 0x63, 0x54, 0xD8, 0x61, 0xDD, 0xA5, 0x33, 0x47,
  45440. 0x85, 0x96, 0x22, 0xD0, 0x2F, 0x9F, 0x7E, 0xF8, 0x74, 0x24, 0xEA, 0x57, 0x97,
  45441. 0x5A, 0xE0, 0x00, 0xCF, 0xC1, 0x67, 0xE1, 0x41, 0xBD, 0x94, 0xA1, 0x03, 0xD3,
  45442. 0xB4, 0x08, 0x64, 0xF2, 0x17, 0x27, 0x35, 0x37, 0x53, 0xEF, 0x46, 0xCE, 0xD8,
  45443. 0xD4, 0x09, 0x52, 0xC6, 0x1E, 0xF7, 0x28, 0xDF, 0x08, 0x0F, 0xD0, 0x6F, 0x71,
  45444. 0xA6, 0xDF, 0xE4, 0x60, 0x8E, 0xC0, 0x1E, 0x78, 0x86, 0x50, 0xB0, 0x9B, 0x84,
  45445. 0x7E, 0xE8, 0x36, 0xFA, 0x95, 0xF1, 0x12, 0x51, 0xC7, 0x18, 0x96, 0xA2, 0x29,
  45446. 0xBB, 0x70, 0x02, 0xB4, 0xF9, 0xA8, 0x3D, 0x08, 0x66, 0xA9, 0xB3, 0xFC, 0x0A,
  45447. 0x94, 0x80, 0xFD, 0x78, 0xDC, 0xAB, 0x82, 0x5A, 0xD2, 0xCD, 0xC2, 0x87, 0xC6,
  45448. 0x4B, 0x07, 0xFA, 0xD1, 0xC3, 0xD9, 0x34, 0x41, 0x85, 0xF8, 0xD0, 0xB6, 0x0A,
  45449. 0x9D, 0x00, 0x91, 0x35, 0x05, 0x88, 0xC3, 0xE3, 0x9B, 0x22, 0xD2, 0xB8, 0xFD,
  45450. 0x95, 0x3E, 0x6D, 0x5D, 0x48, 0xA3, 0x68, 0xCF, 0x02, 0x42, 0x79, 0x79, 0x8A,
  45451. 0xAA, 0x01, 0xD6, 0x09, 0x14, 0x2C, 0xF4, 0x83, 0xA3, 0x80, 0x31, 0x55, 0x46,
  45452. 0x6E, 0xC5, 0xE5, 0x2F, 0x30, 0x58, 0x81, 0xA2, 0x90, 0xBE, 0x2E, 0xA1, 0xC3,
  45453. 0x0F, 0xA6, 0xF5, 0x51, 0x00, 0x39, 0xB6, 0xF2, 0x2A, 0xA3, 0x15, 0x7D, 0x8D,
  45454. 0xF5, 0x66, 0x5C, 0xD9, 0xFC, 0xCF, 0x2F, 0xBF, 0x08, 0x27, 0xE7, 0xD0, 0x03,
  45455. 0xB8, 0xD9, 0x00, 0x13, 0x3D, 0x01, 0x6B, 0xB6, 0xA8, 0xCD, 0x5B, 0x3B, 0x3E,
  45456. 0x93, 0xBF, 0xE6, 0x2E, 0xB7, 0x4A, 0xCF, 0xB3, 0x0A, 0xCE, 0x62, 0x11, 0xD6,
  45457. 0x1F, 0x68, 0x9B, 0x1D, 0x68, 0xD1, 0x8C, 0x97, 0xBD, 0xA1, 0x07, 0x67, 0x73,
  45458. 0x87, 0xE0, 0x36, 0xDA, 0x8C, 0xD2, 0xD2, 0xBB, 0x84, 0x28, 0xA9, 0xFE, 0x52,
  45459. 0x74, 0xD6, 0xB9, 0x0F, 0x0A, 0x6A, 0x2D, 0x28, 0x35, 0x34, 0x3A, 0xD3, 0xE2,
  45460. 0xCD, 0x35, 0x06, 0x7D, 0x1B, 0x35, 0x85, 0x86, 0xD1, 0x3E, 0xF2, 0x6F, 0xA1,
  45461. 0xC4, 0x55, 0xBD, 0x00, 0xD8, 0xC3, 0x5D, 0xC2, 0x1D, 0x6B, 0x6B, 0x27, 0x5B,
  45462. 0x95, 0xF3, 0xAB, 0xB5, 0xD3, 0x37, 0xF2, 0x2C, 0x9C, 0xC7, 0x5D, 0xBD, 0xF1,
  45463. 0x68, 0x1C, 0xAD, 0xF8, 0xB5, 0xE1, 0x29, 0x72, 0x7A, 0x73, 0x62, 0x55, 0x24,
  45464. 0xB9, 0x85, 0xDF, 0x7B, 0x29, 0x7D, 0xDE, 0x08, 0xF5, 0xE4, 0x44, 0xDA, 0x1A,
  45465. 0x30, 0x74, 0xDA, 0xB4, 0x9B, 0x23, 0x9A, 0x3A, 0xC1, 0x53, 0xB2, 0xA2, 0xA3,
  45466. 0x7B, 0x1F, 0xD9, 0x56, 0xD4, 0x4F, 0x9B, 0xB2, 0x1E, 0xEE, 0xB8, 0x6A, 0x4E,
  45467. 0xB5, 0xF4, 0x5A, 0xC9, 0x18, 0x27, 0x9C, 0xDE, 0x14, 0x44, 0xED, 0xC4, 0x3C,
  45468. 0x71, 0x9F, 0x5F, 0xD9, 0x37, 0xA0, 0x78, 0x34, 0x6E, 0xBC, 0xD2, 0x7B, 0x1D,
  45469. 0xFA, 0x08, 0x39, 0x5A, 0x04, 0x73, 0x15, 0xD9, 0x0A, 0x48, 0xC1, 0x2D, 0x15,
  45470. 0x4E, 0x84, 0x30, 0x45, 0x69, 0xB3, 0xE5, 0xF6, 0xAD, 0x09, 0x1E, 0xCC, 0x5F,
  45471. 0x1F, 0x06, 0xD5, 0x58, 0xAD, 0x78, 0xD7, 0x9F, 0xE5, 0xED, 0x3B, 0x09, 0xD5,
  45472. 0xA6, 0x52, 0x6F, 0x92, 0xD3, 0x3C, 0xC6, 0x1E, 0xF2, 0x93, 0x7C, 0xD3, 0x5F,
  45473. 0x70, 0x85, 0x5D, 0xF8, 0xAA, 0x9D, 0xB7, 0x7B, 0x24, 0x5A, 0xE9, 0x0A, 0x35,
  45474. 0x2F, 0xF5, 0xD9, 0x82, 0x02, 0x8A, 0x90, 0x13, 0x5B, 0xB5, 0x67, 0x9C, 0xDD,
  45475. 0xA0, 0x4E, 0x82, 0x27, 0xDA, 0x7E, 0xE8, 0x8E, 0xCD, 0xE1, 0x56, 0x71, 0x2C,
  45476. 0xE6, 0x4E, 0x1F, 0x91, 0xCD, 0x7C, 0x6A, 0xB7, 0x78, 0xD0, 0x26, 0xF3, 0x56,
  45477. 0xA9, 0xD5, 0xA1, 0xC3, 0x3B, 0x98, 0xE9, 0x28, 0x09, 0xEF, 0x50, 0x90, 0xCD,
  45478. 0xC4, 0x8E, 0x75, 0xCC, 0xAC, 0x2D, 0xC9, 0x03, 0x6D, 0xAC, 0xFE, 0xC4, 0x88,
  45479. 0x36, 0xD1, 0x3F, 0xBB, 0x1C, 0x7D, 0xB3, 0x14, 0x61, 0x2C, 0xB7, 0x54, 0x4B,
  45480. 0xDB, 0x64, 0xB6, 0x57, 0x14, 0x16, 0x8E, 0x1E, 0x6C, 0x64, 0xBB, 0x8B, 0x48,
  45481. 0x5D, 0x96, 0x9D, 0xDC, 0x80, 0xA7, 0xF7, 0x54, 0xC7, 0x46, 0x38, 0x3E, 0x44,
  45482. 0xDE, 0x7E, 0x92, 0x8D, 0x07, 0xF6, 0x07, 0x37, 0x4E, 0x16, 0x10, 0xB4, 0x7D,
  45483. 0x88, 0x66, 0x7F, 0xBB, 0xFF, 0xEA, 0x00, 0xF3, 0xFF, 0x97, 0x2C, 0xB5, 0xBE,
  45484. 0x35, 0x4B, 0x5C, 0x36, 0xEC, 0x4C, 0xBD, 0x2B, 0x7D, 0xBF, 0x46, 0xE2, 0x9C,
  45485. 0x0E, 0x8A, 0xA3, 0xEC, 0xB1, 0x0E, 0x9A, 0xDA, 0x9A, 0x9B, 0x28, 0x92, 0x10,
  45486. 0x53, 0x57, 0xEA, 0xEC, 0xA2, 0x32, 0x32, 0x20, 0x1D, 0x97, 0x5C, 0xB6, 0x84,
  45487. 0xA9, 0x93, 0x8D, 0x95, 0x11, 0xA3, 0x24, 0xA3, 0x2D, 0xC6, 0x4A, 0xEF, 0xAA,
  45488. 0x1D, 0x85, 0x2B, 0x7D, 0x28, 0xBE, 0x53, 0xCE, 0x10, 0x1F, 0xAE, 0x0E, 0x41,
  45489. 0x6C, 0x4B, 0x79, 0x12, 0xFB, 0xF7, 0x54, 0xA3, 0x96, 0x54, 0x83, 0x20, 0x96,
  45490. 0x8F, 0x28, 0xA9, 0x3F, 0x8B, 0x3D, 0xBA, 0x77, 0xDC, 0x24, 0xE1, 0xD4, 0x49,
  45491. 0x40, 0xD8, 0x78, 0x31, 0x85, 0x43, 0xF6, 0xFE, 0x5C, 0xA6, 0x8F, 0x90, 0x09,
  45492. 0xB0, 0xE7, 0xC4, 0x95, 0xB2, 0x55, 0x49, 0x97, 0x8F, 0x1C, 0x78, 0x30, 0x20,
  45493. 0xA0, 0xB4, 0xEF, 0x73, 0x56, 0x59, 0x82, 0xFD, 0xCE, 0xBA, 0x6A, 0x8F, 0x2C,
  45494. 0x8B, 0x15, 0xFD, 0xA1, 0x85, 0xA8, 0x5C, 0x0F, 0x11, 0xA5, 0x9D, 0xC2, 0x46,
  45495. 0xC6, 0x9C, 0xC9, 0x40, 0x0B, 0x58, 0x6A, 0x1C, 0x7A, 0x23, 0xF9, 0xE0, 0x95,
  45496. 0x05, 0x13, 0x58, 0x72, 0xE8, 0x9F, 0x30, 0xAC, 0xCD, 0x26, 0xD4, 0x66, 0x13,
  45497. 0xDF, 0x1E, 0x7B, 0x4F, 0x9C, 0xBE, 0x38, 0x79, 0x75, 0x92, 0xA4, 0xDA, 0x26,
  45498. 0x44, 0x55, 0x17, 0xA3, 0xE5, 0x62, 0xDA, 0xEB, 0x86, 0xEA, 0x68, 0xC7, 0xAB,
  45499. 0xFD, 0x2D, 0x43, 0x59, 0x51, 0xC0, 0x75, 0x64, 0x91, 0x01, 0x29, 0x33, 0x28,
  45500. 0xF3, 0x04, 0x83, 0x80, 0x75, 0x37, 0x75, 0x0C, 0x03, 0x7B, 0x0A, 0xAB, 0x8E,
  45501. 0x60, 0x62, 0x8B, 0x4C, 0xAF, 0x2D, 0xA3, 0x2F, 0xFE, 0xAB, 0x45, 0xCF, 0xDA,
  45502. 0xAB, 0xFA, 0xFA, 0x30, 0x3D, 0xE8, 0xA1, 0x96, 0xA5, 0x7B, 0xE2, 0x2A, 0xD0,
  45503. 0xAF, 0x59, 0xF7, 0xD0, 0x32, 0x57, 0x19, 0xBD, 0xCA, 0x9F, 0xD5, 0x1A, 0xC7,
  45504. 0xAA, 0x65, 0x4A, 0x38, 0xB2, 0x70, 0x33, 0xB7, 0x75, 0xD2, 0xCD, 0xD1, 0xF0,
  45505. 0xA8, 0x87, 0x59, 0x20, 0xA5, 0x57, 0x55, 0xB1, 0xB2, 0xC9, 0x4D, 0x97, 0x34,
  45506. 0x41, 0xF3, 0xF0, 0x30, 0xA1, 0x2C, 0x1C, 0x49, 0x3E, 0x89, 0x7D, 0x12, 0xE2,
  45507. 0xC3, 0x04, 0xC3, 0x92, 0xC0, 0xF6, 0x39, 0x10, 0x80, 0x81, 0x8F, 0x08, 0xB4,
  45508. 0xF8, 0xB9, 0x13, 0x4E, 0x2C, 0xAE, 0xB3, 0x71, 0x82, 0x63, 0x98, 0xAB, 0x5C,
  45509. 0x1C, 0x10, 0xEA, 0x66, 0xF9, 0x02, 0x3A, 0x82, 0x61, 0xD0, 0xD4, 0xAE, 0x43,
  45510. 0xD4, 0x01, 0x3E, 0x9D, 0x04, 0x14, 0xF6, 0x60, 0xD8, 0xA7, 0xD6, 0xB8, 0x53,
  45511. 0xC8, 0xDA, 0x80, 0x93, 0xA0, 0x02, 0xDD, 0xCC, 0xE2, 0xF2, 0xBB, 0xFB, 0xE0,
  45512. 0x27, 0xD7, 0x34, 0x9A, 0x71, 0x49, 0xB5, 0x4F, 0x42, 0x1F, 0xB2, 0x9D, 0x6D,
  45513. 0xAA, 0x9D, 0xD3, 0x50, 0xB5, 0x8F, 0x6A, 0x4B, 0xDF, 0x1F, 0xD5, 0x27, 0x8F,
  45514. 0x3B, 0x27, 0xCF, 0x2F, 0x8C, 0xF8, 0x9D, 0x4C, 0x52, 0xBC, 0x32, 0x0F, 0x73,
  45515. 0xD5, 0x51, 0x8E, 0x36, 0x7E, 0xAD, 0x09, 0xF0, 0x94, 0x83, 0x5F, 0x36, 0xFD,
  45516. 0x7C, 0x03, 0xED, 0xF1, 0x5E, 0x4B, 0xF7, 0xAA, 0x55, 0x5C, 0x4A, 0x14, 0x59,
  45517. 0x85, 0x38, 0x2D, 0x8C, 0xDF, 0xEC, 0x65, 0x1B, 0xB8, 0x76, 0x57, 0x96, 0x3C,
  45518. 0x86, 0xED, 0xF2, 0x7F, 0x2D, 0x28, 0x48, 0xDA, 0x49, 0x7F, 0xF7, 0x54, 0x2B,
  45519. 0xD5, 0x39, 0xD5, 0x57, 0x0A, 0x75, 0x7A, 0x3E, 0x5E, 0x5D, 0xBA, 0x4A, 0x15,
  45520. 0xFA, 0xB8, 0x31, 0x80, 0x71, 0x2C, 0xCA, 0xC4, 0x51, 0x10, 0x16, 0x5D, 0x39,
  45521. 0xEC, 0x9D, 0x07, 0xB6, 0x6A, 0x89, 0x9F, 0x9B, 0x5B, 0x6F, 0x03, 0xB0, 0x92,
  45522. 0x01, 0x38, 0x6B, 0x48, 0x99, 0x0A, 0x8F, 0x13, 0xC1, 0xA6, 0x01, 0xEA, 0xBF,
  45523. 0x6F, 0x86, 0x43, 0x51, 0xB6, 0x11, 0x00, 0x00
  45524. };
  45525. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void)
  45526. {
  45527. wc_test_ret_t ret = 0;
  45528. word32 dSz = sizeof(sample_text);
  45529. word32 cSz = (dSz + (word32)(dSz * 0.001) + 12);
  45530. byte *c;
  45531. byte *d;
  45532. WOLFSSL_ENTER("compress_test");
  45533. c = (byte *)XMALLOC(cSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45534. d = (byte *)XMALLOC(dSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45535. if (c == NULL || d == NULL) {
  45536. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  45537. }
  45538. /* follow calloc and initialize to 0 */
  45539. XMEMSET(c, 0, cSz);
  45540. XMEMSET(d, 0, dSz);
  45541. if ((ret = wc_Compress(c, cSz, sample_text, dSz, 0)) < 0) {
  45542. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45543. }
  45544. cSz = (word32)ret;
  45545. if ((ret = wc_DeCompress(d, dSz, c, cSz)) != (int)dSz) {
  45546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45547. }
  45548. dSz = (word32)ret;
  45549. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45550. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45551. }
  45552. /* GZIP tests */
  45553. cSz = (dSz + (word32)(dSz * 0.001) + 12); /* reset cSz */
  45554. XMEMSET(c, 0, cSz);
  45555. XMEMSET(d, 0, dSz);
  45556. ret = wc_Compress_ex(c, cSz, sample_text, dSz, 0, LIBZ_WINBITS_GZIP);
  45557. if (ret < 0)
  45558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45559. cSz = (word32)ret;
  45560. ret = wc_DeCompress_ex(d, dSz, c, cSz, LIBZ_WINBITS_GZIP);
  45561. if (ret < 0)
  45562. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45563. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45564. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45565. }
  45566. /* Try with gzip generated output */
  45567. XMEMSET(d, 0, dSz);
  45568. ret = wc_DeCompress_ex(d, dSz, sample_text_gz, sizeof(sample_text_gz),
  45569. LIBZ_WINBITS_GZIP);
  45570. if (ret < 0)
  45571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45572. dSz = (word32)ret;
  45573. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45574. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45575. }
  45576. ret = 0; /* success */
  45577. exit:
  45578. XFREE(c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45579. XFREE(d, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45580. return ret;
  45581. }
  45582. #endif /* HAVE_LIBZ */
  45583. #ifdef HAVE_PKCS7
  45584. /* External Debugging/Testing Note:
  45585. *
  45586. * PKCS#7 test functions can output generated PKCS#7/CMS bundles for
  45587. * additional testing. To dump bundles to files DER encoded files, please
  45588. * define:
  45589. *
  45590. * #define PKCS7_OUTPUT_TEST_BUNDLES
  45591. */
  45592. /* Loads certs and keys for use with PKCS7 tests, from either files
  45593. * or buffers.
  45594. *
  45595. * rsaClientCertBuf - output buffer for RSA client cert
  45596. * rsaClientCertBufSz - IN/OUT size of output buffer, size of RSA client cert
  45597. * rsaClientPrivKeyBuf - output buffer for RSA client private key
  45598. * rsaClientPrivKeyBufSz - IN/OUT size of output buffer, size of RSA client key
  45599. *
  45600. * rsaServerCertBuf - output buffer for RSA server cert
  45601. * rsaServerCertBufSz - IN/OUT size of output buffer, size of RSA server cert
  45602. * rsaServerPrivKeyBuf - output buffer for RSA server private key
  45603. * rsaServerPrivKeyBufSz - IN/OUT size of output buffer, size of RSA server key
  45604. *
  45605. * rsaCaCertBuf - output buffer for RSA CA cert
  45606. * rsaCaCertBufSz - IN/OUT size of output buffer, size of RSA ca cert
  45607. * rsaCaPrivKeyBuf - output buffer for RSA CA private key
  45608. * rsaCaPrivKeyBufSz - IN/OUT size of output buffer, size of RSA CA key
  45609. *
  45610. * eccClientCertBuf - output buffer for ECC cert
  45611. * eccClientCertBufSz - IN/OUT size of output buffer, size of ECC cert
  45612. * eccClientPrivKeyBuf - output buffer for ECC private key
  45613. * eccClientPrivKeyBufSz - IN/OUT size of output buffer, size of ECC private key
  45614. *
  45615. * Returns 0 on success, negative on error
  45616. */
  45617. static wc_test_ret_t pkcs7_load_certs_keys(
  45618. byte* rsaClientCertBuf, word32* rsaClientCertBufSz,
  45619. byte* rsaClientPrivKeyBuf, word32* rsaClientPrivKeyBufSz,
  45620. byte* rsaServerCertBuf, word32* rsaServerCertBufSz,
  45621. byte* rsaServerPrivKeyBuf, word32* rsaServerPrivKeyBufSz,
  45622. byte* rsaCaCertBuf, word32* rsaCaCertBufSz,
  45623. byte* rsaCaPrivKeyBuf, word32* rsaCaPrivKeyBufSz,
  45624. byte* eccClientCertBuf, word32* eccClientCertBufSz,
  45625. byte* eccClientPrivKeyBuf, word32* eccClientPrivKeyBufSz)
  45626. {
  45627. #ifndef NO_FILESYSTEM
  45628. XFILE certFile;
  45629. XFILE keyFile;
  45630. (void)certFile;
  45631. (void)keyFile;
  45632. #endif
  45633. #ifndef NO_RSA
  45634. if (rsaClientCertBuf == NULL || rsaClientCertBufSz == NULL ||
  45635. rsaClientPrivKeyBuf == NULL || rsaClientPrivKeyBufSz == NULL)
  45636. return BAD_FUNC_ARG;
  45637. #endif
  45638. #ifdef HAVE_ECC
  45639. if (eccClientCertBuf == NULL || eccClientCertBufSz == NULL ||
  45640. eccClientPrivKeyBuf == NULL || eccClientPrivKeyBufSz == NULL)
  45641. return BAD_FUNC_ARG;
  45642. #endif
  45643. /* RSA */
  45644. #ifndef NO_RSA
  45645. #ifdef USE_CERT_BUFFERS_1024
  45646. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_1024)
  45647. return WC_TEST_RET_ENC_NC;
  45648. XMEMCPY(rsaClientCertBuf, client_cert_der_1024,
  45649. sizeof_client_cert_der_1024);
  45650. *rsaClientCertBufSz = sizeof_client_cert_der_1024;
  45651. if (rsaServerCertBuf != NULL) {
  45652. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_1024)
  45653. return WC_TEST_RET_ENC_NC;
  45654. XMEMCPY(rsaServerCertBuf, server_cert_der_1024,
  45655. sizeof_server_cert_der_1024);
  45656. *rsaServerCertBufSz = sizeof_server_cert_der_1024;
  45657. }
  45658. if (rsaCaCertBuf != NULL) {
  45659. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_1024)
  45660. return WC_TEST_RET_ENC_NC;
  45661. XMEMCPY(rsaCaCertBuf, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  45662. *rsaCaCertBufSz = sizeof_ca_cert_der_1024;
  45663. }
  45664. #elif defined(USE_CERT_BUFFERS_2048)
  45665. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_2048)
  45666. return WC_TEST_RET_ENC_NC;
  45667. XMEMCPY(rsaClientCertBuf, client_cert_der_2048,
  45668. sizeof_client_cert_der_2048);
  45669. *rsaClientCertBufSz = sizeof_client_cert_der_2048;
  45670. if (rsaServerCertBuf != NULL) {
  45671. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_2048)
  45672. return WC_TEST_RET_ENC_NC;
  45673. XMEMCPY(rsaServerCertBuf, server_cert_der_2048,
  45674. sizeof_server_cert_der_2048);
  45675. *rsaServerCertBufSz = sizeof_server_cert_der_2048;
  45676. }
  45677. if (rsaCaCertBuf != NULL) {
  45678. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_2048)
  45679. return WC_TEST_RET_ENC_NC;
  45680. XMEMCPY(rsaCaCertBuf, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  45681. *rsaCaCertBufSz = sizeof_ca_cert_der_2048;
  45682. }
  45683. #else
  45684. certFile = XFOPEN(clientCert, "rb");
  45685. if (!certFile)
  45686. return WC_TEST_RET_ENC_ERRNO;
  45687. *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1,
  45688. *rsaClientCertBufSz, certFile);
  45689. XFCLOSE(certFile);
  45690. if (*rsaClientCertBufSz == 0)
  45691. return WC_TEST_RET_ENC_ERRNO;
  45692. if (rsaServerCertBuf != NULL) {
  45693. certFile = XFOPEN(rsaServerCertDerFile, "rb");
  45694. if (!certFile)
  45695. return WC_TEST_RET_ENC_ERRNO;
  45696. *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1,
  45697. *rsaServerCertBufSz, certFile);
  45698. XFCLOSE(certFile);
  45699. if (*rsaServerCertBufSz == 0)
  45700. return WC_TEST_RET_ENC_ERRNO;
  45701. }
  45702. if (rsaCaCertBuf != NULL) {
  45703. certFile = XFOPEN(rsaCaCertDerFile, "rb");
  45704. if (!certFile)
  45705. return WC_TEST_RET_ENC_ERRNO;
  45706. *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz,
  45707. certFile);
  45708. XFCLOSE(certFile);
  45709. if (*rsaCaCertBufSz == 0)
  45710. return WC_TEST_RET_ENC_ERRNO;
  45711. }
  45712. #endif
  45713. #ifdef USE_CERT_BUFFERS_1024
  45714. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_1024)
  45715. return WC_TEST_RET_ENC_NC;
  45716. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_1024,
  45717. sizeof_client_key_der_1024);
  45718. *rsaClientPrivKeyBufSz = sizeof_client_key_der_1024;
  45719. if (rsaServerPrivKeyBuf != NULL) {
  45720. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_1024)
  45721. return WC_TEST_RET_ENC_NC;
  45722. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_1024,
  45723. sizeof_server_key_der_1024);
  45724. *rsaServerPrivKeyBufSz = sizeof_server_key_der_1024;
  45725. }
  45726. if (rsaCaPrivKeyBuf != NULL) {
  45727. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_1024)
  45728. return WC_TEST_RET_ENC_NC;
  45729. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_1024, sizeof_ca_key_der_1024);
  45730. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_1024;
  45731. }
  45732. #elif defined(USE_CERT_BUFFERS_2048)
  45733. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_2048)
  45734. return WC_TEST_RET_ENC_NC;
  45735. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_2048,
  45736. sizeof_client_key_der_2048);
  45737. *rsaClientPrivKeyBufSz = sizeof_client_key_der_2048;
  45738. if (rsaServerPrivKeyBuf != NULL) {
  45739. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_2048)
  45740. return WC_TEST_RET_ENC_NC;
  45741. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_2048,
  45742. sizeof_server_key_der_2048);
  45743. *rsaServerPrivKeyBufSz = sizeof_server_key_der_2048;
  45744. }
  45745. if (rsaCaPrivKeyBuf != NULL) {
  45746. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_2048)
  45747. return WC_TEST_RET_ENC_NC;
  45748. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_2048, sizeof_ca_key_der_2048);
  45749. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048;
  45750. }
  45751. #else
  45752. keyFile = XFOPEN(clientKey, "rb");
  45753. if (!keyFile)
  45754. return WC_TEST_RET_ENC_ERRNO;
  45755. *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1,
  45756. *rsaClientPrivKeyBufSz, keyFile);
  45757. XFCLOSE(keyFile);
  45758. if (*rsaClientPrivKeyBufSz == 0)
  45759. return WC_TEST_RET_ENC_ERRNO;
  45760. if (rsaServerPrivKeyBuf != NULL) {
  45761. keyFile = XFOPEN(rsaServerKeyDerFile, "rb");
  45762. if (!keyFile)
  45763. return WC_TEST_RET_ENC_ERRNO;
  45764. *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1,
  45765. *rsaServerPrivKeyBufSz, keyFile);
  45766. XFCLOSE(keyFile);
  45767. if (*rsaServerPrivKeyBufSz == 0)
  45768. return WC_TEST_RET_ENC_ERRNO;
  45769. }
  45770. if (rsaCaPrivKeyBuf != NULL) {
  45771. keyFile = XFOPEN(rsaCaKeyFile, "rb");
  45772. if (!keyFile)
  45773. return WC_TEST_RET_ENC_ERRNO;
  45774. *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1,
  45775. *rsaCaPrivKeyBufSz, keyFile);
  45776. XFCLOSE(keyFile);
  45777. if (*rsaCaPrivKeyBufSz == 0)
  45778. return WC_TEST_RET_ENC_ERRNO;
  45779. }
  45780. #endif /* USE_CERT_BUFFERS */
  45781. #endif /* NO_RSA */
  45782. /* ECC */
  45783. #ifdef HAVE_ECC
  45784. #ifdef USE_CERT_BUFFERS_256
  45785. if (*eccClientCertBufSz < (word32)sizeof_cliecc_cert_der_256)
  45786. return WC_TEST_RET_ENC_NC;
  45787. XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45788. *eccClientCertBufSz = sizeof_cliecc_cert_der_256;
  45789. #else
  45790. certFile = XFOPEN(eccClientCert, "rb");
  45791. if (!certFile)
  45792. return WC_TEST_RET_ENC_ERRNO;
  45793. *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1,
  45794. *eccClientCertBufSz, certFile);
  45795. XFCLOSE(certFile);
  45796. if (*eccClientCertBufSz == 0)
  45797. return WC_TEST_RET_ENC_ERRNO;
  45798. #endif /* USE_CERT_BUFFERS_256 */
  45799. #ifdef USE_CERT_BUFFERS_256
  45800. if (*eccClientPrivKeyBufSz < (word32)sizeof_ecc_clikey_der_256)
  45801. return WC_TEST_RET_ENC_NC;
  45802. XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45803. *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256;
  45804. #else
  45805. keyFile = XFOPEN(eccClientKey, "rb");
  45806. if (!keyFile)
  45807. return WC_TEST_RET_ENC_ERRNO;
  45808. *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1,
  45809. *eccClientPrivKeyBufSz, keyFile);
  45810. XFCLOSE(keyFile);
  45811. if (*eccClientPrivKeyBufSz == 0)
  45812. return WC_TEST_RET_ENC_ERRNO;
  45813. #endif /* USE_CERT_BUFFERS_256 */
  45814. #endif /* HAVE_ECC */
  45815. #ifdef NO_RSA
  45816. (void)rsaClientCertBuf;
  45817. (void)rsaClientCertBufSz;
  45818. (void)rsaClientPrivKeyBuf;
  45819. (void)rsaClientPrivKeyBufSz;
  45820. (void)rsaServerCertBuf;
  45821. (void)rsaServerCertBufSz;
  45822. (void)rsaServerPrivKeyBuf;
  45823. (void)rsaServerPrivKeyBufSz;
  45824. (void)rsaCaCertBuf;
  45825. (void)rsaCaCertBufSz;
  45826. (void)rsaCaPrivKeyBuf;
  45827. (void)rsaCaPrivKeyBufSz;
  45828. #endif
  45829. #ifndef HAVE_ECC
  45830. (void)eccClientCertBuf;
  45831. (void)eccClientCertBufSz;
  45832. (void)eccClientPrivKeyBuf;
  45833. (void)eccClientPrivKeyBufSz;
  45834. #endif
  45835. #ifndef NO_FILESYSTEM
  45836. (void)certFile;
  45837. (void)keyFile;
  45838. #endif
  45839. return 0;
  45840. }
  45841. typedef struct {
  45842. const byte* content;
  45843. word32 contentSz;
  45844. int contentOID;
  45845. int encryptOID;
  45846. int keyWrapOID;
  45847. int keyAgreeOID;
  45848. byte* cert;
  45849. size_t certSz;
  45850. byte* privateKey;
  45851. word32 privateKeySz;
  45852. byte* optionalUkm;
  45853. word32 optionalUkmSz;
  45854. int ktriOptions; /* KTRI options flags */
  45855. int kariOptions; /* KARI options flags */
  45856. /* KEKRI specific */
  45857. const byte* secretKey; /* key, only for kekri RecipientInfo types */
  45858. word32 secretKeySz; /* size of secretKey, bytes */
  45859. const byte* secretKeyId; /* key identifier */
  45860. word32 secretKeyIdSz; /* size of key identifier, bytes */
  45861. void* timePtr; /* time_t pointer */
  45862. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  45863. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  45864. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  45865. word32 otherAttrSz; /* size of otherAttr, bytes */
  45866. int kekriOptions; /* KEKRI options flags */
  45867. /* PWRI specific */
  45868. const char* password;
  45869. word32 passwordSz;
  45870. const byte* salt;
  45871. word32 saltSz;
  45872. int kdfOID;
  45873. int hashOID;
  45874. int kdfIterations;
  45875. int pwriOptions; /* PWRI options flags */
  45876. /* ORI specific */
  45877. int isOri;
  45878. int oriOptions; /* ORI options flags */
  45879. const char* outFileName;
  45880. } pkcs7EnvelopedVector;
  45881. static const byte asnDataOid[] = {
  45882. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01
  45883. };
  45884. /* ORI encrypt callback, responsible for encrypting content-encryption key (CEK)
  45885. * and giving wolfCrypt the value for oriOID and oriValue to place in
  45886. * OtherRecipientInfo.
  45887. *
  45888. * Returns 0 on success, negative upon error. */
  45889. static int myOriEncryptCb(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* oriType,
  45890. word32* oriTypeSz, byte* oriValue, word32* oriValueSz,
  45891. void* ctx)
  45892. {
  45893. int i;
  45894. /* make sure buffers are large enough */
  45895. if (*oriValueSz < (2 + cekSz))
  45896. return WC_TEST_RET_ENC_NC;
  45897. if (*oriTypeSz < sizeof(asnDataOid))
  45898. return WC_TEST_RET_ENC_NC;
  45899. /* our simple encryption algorithm will be take the bitwise complement */
  45900. oriValue[0] = 0x04; /*ASN OCTET STRING */
  45901. oriValue[1] = (byte)cekSz; /* length */
  45902. for (i = 0; i < (int)cekSz; i++) {
  45903. oriValue[2 + i] = ~cek[i];
  45904. }
  45905. *oriValueSz = 2 + cekSz;
  45906. /* set oriType to ASN.1 encoded data OID */
  45907. XMEMCPY(oriType, asnDataOid, sizeof(asnDataOid));
  45908. *oriTypeSz = sizeof(asnDataOid);
  45909. (void)pkcs7;
  45910. (void)ctx;
  45911. return 0;
  45912. }
  45913. /* ORI decrypt callback, responsible for providing a decrypted content
  45914. * encryption key (CEK) placed into decryptedKey and size placed into
  45915. * decryptedKeySz. oriOID and oriValue are given to the callback to help
  45916. * in decrypting the encrypted CEK.
  45917. *
  45918. * Returns 0 on success, negative upon error. */
  45919. static int myOriDecryptCb(wc_PKCS7* pkcs7, byte* oriType, word32 oriTypeSz,
  45920. byte* oriValue, word32 oriValueSz, byte* decryptedKey,
  45921. word32* decryptedKeySz, void* ctx)
  45922. {
  45923. int i;
  45924. /* make sure oriType matches what we expect */
  45925. if (oriTypeSz != sizeof(asnDataOid))
  45926. return WC_TEST_RET_ENC_NC;
  45927. if (XMEMCMP(oriType, asnDataOid, sizeof(asnDataOid)) != 0)
  45928. return WC_TEST_RET_ENC_NC;
  45929. /* make sure decrypted buffer is large enough */
  45930. if (*decryptedKeySz < oriValueSz)
  45931. return WC_TEST_RET_ENC_NC;
  45932. /* decrypt encrypted CEK using simple bitwise complement,
  45933. only for example */
  45934. for (i = 0; i < (int)oriValueSz - 2; i++) {
  45935. decryptedKey[i] = ~oriValue[2 + i];
  45936. }
  45937. *decryptedKeySz = oriValueSz - 2;
  45938. (void)pkcs7;
  45939. (void)ctx;
  45940. return 0;
  45941. }
  45942. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45943. /* returns 0 on success */
  45944. static int myDecryptionFunc(wc_PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45945. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45946. byte* in, int inSz, byte* out, void* usrCtx)
  45947. {
  45948. wc_test_ret_t ret;
  45949. int keyId = -1, keySz;
  45950. word32 keyIdSz = 8;
  45951. const byte* key;
  45952. byte keyIdRaw[8];
  45953. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45954. Aes *aes;
  45955. #else
  45956. Aes aes[1];
  45957. #endif
  45958. /* looking for KEY ID
  45959. * fwDecryptKeyID OID "1.2.840.113549.1.9.16.2.37
  45960. */
  45961. WOLFSSL_SMALL_STACK_STATIC const unsigned char OID[] = {
  45962. /* 0x06, 0x0B do not pass in tag and length */
  45963. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  45964. 0x01, 0x09, 0x10, 0x02, 0x25
  45965. };
  45966. WOLFSSL_SMALL_STACK_STATIC const byte defKey[] = {
  45967. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45968. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45969. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45970. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45971. };
  45972. WOLFSSL_SMALL_STACK_STATIC const byte altKey[] = {
  45973. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45974. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45975. };
  45976. /* test user context passed in */
  45977. if (usrCtx == NULL || *(int*)usrCtx != 1) {
  45978. return WC_TEST_RET_ENC_NC;
  45979. }
  45980. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45981. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  45982. return WC_TEST_RET_ENC_ERRNO;
  45983. #endif
  45984. /* if needing to find keyIdSz can call with NULL */
  45985. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), NULL,
  45986. &keyIdSz);
  45987. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  45988. printf("Unexpected error %d when getting keyIdSz\n", ret);
  45989. printf("Possibly no KEY ID attribute set\n");
  45990. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45991. }
  45992. else {
  45993. XMEMSET(keyIdRaw, 0, sizeof(keyIdRaw));
  45994. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), keyIdRaw,
  45995. &keyIdSz);
  45996. if (ret < 0) {
  45997. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45998. }
  45999. if (keyIdSz < 3) {
  46000. printf("keyIdSz is smaller than expected\n");
  46001. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46002. }
  46003. if (keyIdSz > 2 + sizeof(int)) {
  46004. printf("example case was only expecting a keyId of int size\n");
  46005. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46006. }
  46007. /* keyIdRaw[0] OCTET TAG */
  46008. /* keyIdRaw[1] Length */
  46009. #ifdef BIG_ENDIAN_ORDER
  46010. if (keyIdRaw[1] == 0x01) {
  46011. keyId = 1;
  46012. }
  46013. #else
  46014. XMEMCPY(&keyId, keyIdRaw + 2, sizeof(keyId));
  46015. #endif
  46016. }
  46017. /* Use keyID here if found to select key and decrypt in HSM or in this
  46018. * example just select key and do software decryption */
  46019. if (keyId == 1) {
  46020. key = altKey;
  46021. keySz = sizeof(altKey);
  46022. }
  46023. else {
  46024. key = defKey;
  46025. keySz = sizeof(defKey);
  46026. }
  46027. switch (encryptOID) {
  46028. #ifdef WOLFSSL_AES_256
  46029. case AES256CBCb:
  46030. if ((keySz != 32 ) || (ivSz != WC_AES_BLOCK_SIZE))
  46031. WARNING_OUT(BAD_FUNC_ARG, out);
  46032. break;
  46033. #endif
  46034. #ifdef WOLFSSL_AES_128
  46035. case AES128CBCb:
  46036. if ((keySz != 16 ) || (ivSz != WC_AES_BLOCK_SIZE))
  46037. ERROR_OUT(BAD_FUNC_ARG, out);
  46038. break;
  46039. #endif
  46040. default:
  46041. printf("Unsupported content cipher type for example");
  46042. ERROR_OUT(ALGO_ID_E, out);
  46043. };
  46044. ret = wc_AesInit(aes, HEAP_HINT, INVALID_DEVID);
  46045. if (ret == 0) {
  46046. ret = wc_AesSetKey(aes, key, (word32)keySz, iv, AES_DECRYPTION);
  46047. if (ret == 0)
  46048. ret = wc_AesCbcDecrypt(aes, out, in, (word32)inSz);
  46049. wc_AesFree(aes);
  46050. }
  46051. out:
  46052. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  46053. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46054. #endif
  46055. (void)aad;
  46056. (void)aadSz;
  46057. (void)authTag;
  46058. (void)authTagSz;
  46059. return (int)ret;
  46060. }
  46061. #endif /* !NO_AES && HAVE_AES_CBC */
  46062. #define PKCS7_BUF_SIZE 2048
  46063. static wc_test_ret_t pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46064. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46065. byte* eccCert, word32 eccCertSz,
  46066. byte* eccPrivKey, word32 eccPrivKeySz)
  46067. {
  46068. wc_test_ret_t ret = 0;
  46069. int testSz = 0, i;
  46070. int envelopedSz, decodedSz;
  46071. byte *enveloped = NULL;
  46072. byte *decoded = NULL;
  46073. wc_PKCS7* pkcs7 = NULL;
  46074. #ifdef ECC_TIMING_RESISTANT
  46075. WC_RNG rng;
  46076. #endif
  46077. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46078. XFILE pkcs7File;
  46079. #endif
  46080. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46081. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46082. 0x72,0x6c,0x64
  46083. };
  46084. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256) && \
  46085. defined(HAVE_ECC) && defined(WOLFSSL_SHA512)
  46086. byte optionalUkm[] = {
  46087. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46088. };
  46089. #endif /* !NO_AES */
  46090. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  46091. !defined(NO_SHA)
  46092. /* encryption key for kekri recipient types */
  46093. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46094. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46095. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46096. };
  46097. /* encryption key identifier */
  46098. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46099. 0x02,0x02,0x03,0x04
  46100. };
  46101. #endif
  46102. #if !defined(NO_PWDBASED) && !defined(NO_SHA) && \
  46103. !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46104. #ifndef HAVE_FIPS
  46105. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password"; /* NOTE: Password is too short for FIPS */
  46106. #else
  46107. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46108. #endif
  46109. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46110. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46111. };
  46112. #endif
  46113. #define MAX_TESTVECTORS_LEN 13
  46114. #define ADD_PKCS7ENVELOPEDVECTOR(...) { \
  46115. pkcs7EnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46116. if (testSz == MAX_TESTVECTORS_LEN) { \
  46117. ret = WC_TEST_RET_ENC_NC; \
  46118. goto out; \
  46119. } \
  46120. XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\
  46121. }
  46122. pkcs7EnvelopedVector *testVectors = NULL;
  46123. #ifdef ECC_TIMING_RESISTANT
  46124. XMEMSET(&rng, 0, sizeof(rng));
  46125. #endif
  46126. testVectors = (pkcs7EnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46127. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46128. if (testVectors == NULL) {
  46129. ret = WC_TEST_RET_ENC_ERRNO;
  46130. goto out;
  46131. }
  46132. {
  46133. /* key transport key encryption technique */
  46134. #ifndef NO_RSA
  46135. #ifndef NO_DES3
  46136. ADD_PKCS7ENVELOPEDVECTOR(
  46137. data, (word32)sizeof(data), DATA, DES3b, 0, 0, rsaCert, rsaCertSz,
  46138. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46139. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46140. "pkcs7envelopedDataDES3.der");
  46141. #endif
  46142. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46143. #ifdef WOLFSSL_AES_128
  46144. ADD_PKCS7ENVELOPEDVECTOR(
  46145. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, rsaCert, rsaCertSz,
  46146. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46147. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46148. "pkcs7envelopedDataAES128CBC.der");
  46149. #endif
  46150. #ifdef WOLFSSL_AES_192
  46151. ADD_PKCS7ENVELOPEDVECTOR(
  46152. data, (word32)sizeof(data), DATA, AES192CBCb, 0, 0, rsaCert, rsaCertSz,
  46153. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46154. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46155. "pkcs7envelopedDataAES192CBC.der");
  46156. #endif
  46157. #ifdef WOLFSSL_AES_256
  46158. ADD_PKCS7ENVELOPEDVECTOR(
  46159. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46160. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46161. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46162. "pkcs7envelopedDataAES256CBC.der");
  46163. /* explicitly using SKID for SubjectKeyIdentifier */
  46164. ADD_PKCS7ENVELOPEDVECTOR(
  46165. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46166. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_SKID, 0, NULL, 0, NULL, 0, NULL,
  46167. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46168. "pkcs7envelopedDataAES256CBC_SKID.der");
  46169. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46170. ADD_PKCS7ENVELOPEDVECTOR(
  46171. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46172. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_ISSUER_AND_SERIAL_NUMBER, 0,
  46173. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46174. 0, 0, 0, 0, "pkcs7envelopedDataAES256CBC_IANDS.der");
  46175. #endif
  46176. #endif /* !NO_AES && HAVE_AES_CBC */
  46177. #endif
  46178. /* key agreement key encryption technique*/
  46179. #ifdef HAVE_ECC
  46180. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46181. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46182. ADD_PKCS7ENVELOPEDVECTOR(
  46183. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP,
  46184. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46185. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46186. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46187. "pkcs7envelopedDataAES128CBC_ECDH_SHA1KDF.der");
  46188. #endif
  46189. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46190. ADD_PKCS7ENVELOPEDVECTOR(
  46191. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46192. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46193. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46194. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46195. "pkcs7envelopedDataAES256CBC_ECDH_SHA256KDF.der");
  46196. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46197. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46198. ADD_PKCS7ENVELOPEDVECTOR(
  46199. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46200. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46201. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46202. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46203. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF.der");
  46204. /* with optional user keying material (ukm) */
  46205. ADD_PKCS7ENVELOPEDVECTOR(
  46206. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46207. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46208. eccPrivKeySz, optionalUkm, sizeof(optionalUkm), 0, 0, NULL, 0,
  46209. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46210. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF_ukm.der");
  46211. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46212. #endif /* !NO_AES && HAVE_AES_CBC */
  46213. #endif
  46214. /* kekri (KEKRecipientInfo) recipient types */
  46215. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46216. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46217. ADD_PKCS7ENVELOPEDVECTOR(
  46218. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP, 0,
  46219. NULL, 0, NULL, 0, NULL, 0, 0, 0, secretKey, sizeof(secretKey),
  46220. secretKeyId, sizeof(secretKeyId), NULL, NULL, 0, NULL, 0,
  46221. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46222. "pkcs7envelopedDataAES128CBC_KEKRI.der");
  46223. #endif
  46224. #endif /* !NO_AES && HAVE_AES_CBC */
  46225. /* pwri (PasswordRecipientInfo) recipient types */
  46226. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  46227. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46228. ADD_PKCS7ENVELOPEDVECTOR(
  46229. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0,
  46230. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46231. NULL, 0, NULL, NULL, 0, NULL, 0, 0, password,
  46232. (word32)XSTRLEN(password), salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46233. 0, 0, 0, "pkcs7envelopedDataAES128CBC_PWRI.der");
  46234. #endif
  46235. #endif
  46236. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_128)
  46237. /* ori (OtherRecipientInfo) recipient types */
  46238. ADD_PKCS7ENVELOPEDVECTOR(
  46239. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, NULL, 0, NULL, 0,
  46240. NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0,
  46241. NULL, 0, 0, 0, 0, 0, 1, 0, "pkcs7envelopedDataAES128CBC_ORI.der");
  46242. #endif
  46243. };
  46244. #undef MAX_TESTVECTORS_LEN
  46245. #undef ADD_PKCS7ENVELOPEDVECTOR
  46246. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46247. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46248. if ((! enveloped) || (! decoded)) {
  46249. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46250. }
  46251. #ifdef ECC_TIMING_RESISTANT
  46252. #ifndef HAVE_FIPS
  46253. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46254. #else
  46255. ret = wc_InitRng(&rng);
  46256. #endif
  46257. if (ret != 0)
  46258. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46259. #endif
  46260. for (i = 0; i < testSz; i++) {
  46261. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46262. #ifdef WOLFSSL_ASYNC_CRYPT
  46263. INVALID_DEVID /* async PKCS7 is not supported */
  46264. #else
  46265. devId
  46266. #endif
  46267. );
  46268. if (pkcs7 == NULL) {
  46269. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46270. }
  46271. if (testVectors[i].secretKey != NULL) {
  46272. /* KEKRI recipient type */
  46273. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46274. if (ret != 0)
  46275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46276. pkcs7->content = (byte*)testVectors[i].content;
  46277. pkcs7->contentSz = testVectors[i].contentSz;
  46278. pkcs7->contentOID = testVectors[i].contentOID;
  46279. pkcs7->encryptOID = testVectors[i].encryptOID;
  46280. pkcs7->ukm = testVectors[i].optionalUkm;
  46281. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46282. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46283. (byte *)testVectors[i].secretKey, testVectors[i].secretKeySz,
  46284. (byte *)testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46285. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46286. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46287. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46288. if (ret < 0) {
  46289. wc_PKCS7_Free(pkcs7);
  46290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46291. }
  46292. /* set key, for decryption */
  46293. ret = wc_PKCS7_SetKey(pkcs7, (byte *)testVectors[i].secretKey,
  46294. testVectors[i].secretKeySz);
  46295. if (ret != 0) {
  46296. wc_PKCS7_Free(pkcs7);
  46297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46298. }
  46299. } else if (testVectors[i].password != NULL) {
  46300. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46301. /* PWRI recipient type */
  46302. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46303. if (ret != 0)
  46304. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46305. pkcs7->content = (byte*)testVectors[i].content;
  46306. pkcs7->contentSz = testVectors[i].contentSz;
  46307. pkcs7->contentOID = testVectors[i].contentOID;
  46308. pkcs7->encryptOID = testVectors[i].encryptOID;
  46309. pkcs7->ukm = testVectors[i].optionalUkm;
  46310. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46311. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46312. (byte *)testVectors[i].password, testVectors[i].passwordSz,
  46313. (byte *)testVectors[i].salt, testVectors[i].saltSz,
  46314. testVectors[i].kdfOID,
  46315. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46316. testVectors[i].encryptOID, testVectors[i].pwriOptions);
  46317. if (ret < 0) {
  46318. wc_PKCS7_Free(pkcs7);
  46319. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46320. }
  46321. /* set password, for decryption */
  46322. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46323. testVectors[i].passwordSz);
  46324. if (ret < 0) {
  46325. wc_PKCS7_Free(pkcs7);
  46326. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46327. }
  46328. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46329. } else if (testVectors[i].isOri == 1) {
  46330. /* ORI recipient type */
  46331. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46332. if (ret != 0)
  46333. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46334. pkcs7->content = (byte*)testVectors[i].content;
  46335. pkcs7->contentSz = testVectors[i].contentSz;
  46336. pkcs7->contentOID = testVectors[i].contentOID;
  46337. pkcs7->encryptOID = testVectors[i].encryptOID;
  46338. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46339. testVectors[i].oriOptions);
  46340. if (ret < 0) {
  46341. wc_PKCS7_Free(pkcs7);
  46342. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46343. }
  46344. /* set decrypt callback for decryption */
  46345. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46346. if (ret < 0) {
  46347. wc_PKCS7_Free(pkcs7);
  46348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46349. }
  46350. } else {
  46351. /* KTRI or KARI recipient types */
  46352. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46353. if (ret != 0)
  46354. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46355. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46356. (word32)testVectors[i].certSz);
  46357. if (ret != 0) {
  46358. wc_PKCS7_Free(pkcs7);
  46359. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46360. }
  46361. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46362. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46363. pkcs7->privateKey = testVectors[i].privateKey;
  46364. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46365. pkcs7->content = (byte*)testVectors[i].content;
  46366. pkcs7->contentSz = testVectors[i].contentSz;
  46367. pkcs7->contentOID = testVectors[i].contentOID;
  46368. pkcs7->encryptOID = testVectors[i].encryptOID;
  46369. pkcs7->ukm = testVectors[i].optionalUkm;
  46370. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46371. /* set SubjectIdentifier type for KTRI types */
  46372. if (testVectors[i].ktriOptions & CMS_SKID) {
  46373. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46374. if (ret != 0) {
  46375. wc_PKCS7_Free(pkcs7);
  46376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46377. }
  46378. } else if (testVectors[i].ktriOptions &
  46379. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46380. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46381. CMS_ISSUER_AND_SERIAL_NUMBER);
  46382. if (ret != 0) {
  46383. wc_PKCS7_Free(pkcs7);
  46384. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46385. }
  46386. }
  46387. }
  46388. #ifdef ECC_TIMING_RESISTANT
  46389. pkcs7->rng = &rng;
  46390. #endif
  46391. /* encode envelopedData */
  46392. envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, enveloped,
  46393. PKCS7_BUF_SIZE);
  46394. if (envelopedSz <= 0) {
  46395. wc_PKCS7_Free(pkcs7);
  46396. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46397. }
  46398. /* decode envelopedData */
  46399. pkcs7->contentOID = 0;
  46400. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, (word32)envelopedSz,
  46401. decoded, PKCS7_BUF_SIZE);
  46402. if (pkcs7->contentOID != testVectors[i].contentOID ||
  46403. decodedSz <= 0) {
  46404. wc_PKCS7_Free(pkcs7);
  46405. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46406. }
  46407. /* test decode result */
  46408. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  46409. wc_PKCS7_Free(pkcs7);
  46410. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46411. }
  46412. #ifndef NO_PKCS7_STREAM
  46413. { /* test reading byte by byte */
  46414. int z;
  46415. for (z = 0; z < envelopedSz; z++) {
  46416. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped + z, 1,
  46417. decoded, PKCS7_BUF_SIZE);
  46418. if (decodedSz <= 0 &&
  46419. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46420. {
  46421. printf("unexpected error %d\n", decodedSz);
  46422. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46423. }
  46424. }
  46425. /* test decode result */
  46426. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46427. printf("stream read compare failed\n");
  46428. wc_PKCS7_Free(pkcs7);
  46429. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46430. }
  46431. }
  46432. #endif
  46433. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46434. /* output pkcs7 envelopedData for external testing */
  46435. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46436. if (!pkcs7File) {
  46437. wc_PKCS7_Free(pkcs7);
  46438. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46439. }
  46440. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  46441. XFCLOSE(pkcs7File);
  46442. if (ret != envelopedSz) {
  46443. wc_PKCS7_Free(pkcs7);
  46444. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46445. } else {
  46446. /* reset ret to 0 for success */
  46447. ret = 0;
  46448. }
  46449. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  46450. wc_PKCS7_Free(pkcs7);
  46451. pkcs7 = NULL;
  46452. }
  46453. #ifdef ECC_TIMING_RESISTANT
  46454. wc_FreeRng(&rng);
  46455. #endif
  46456. (void)eccCert;
  46457. (void)eccCertSz;
  46458. (void)eccPrivKey;
  46459. (void)eccPrivKeySz;
  46460. (void)rsaCert;
  46461. (void)rsaCertSz;
  46462. (void)rsaPrivKey;
  46463. (void)rsaPrivKeySz;
  46464. out:
  46465. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46466. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46467. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46468. return ret;
  46469. }
  46470. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void)
  46471. {
  46472. wc_test_ret_t ret = 0;
  46473. byte* rsaCert = NULL;
  46474. byte* rsaPrivKey = NULL;
  46475. word32 rsaCertSz = 0;
  46476. word32 rsaPrivKeySz = 0;
  46477. byte* eccCert = NULL;
  46478. byte* eccPrivKey = NULL;
  46479. word32 eccCertSz = 0;
  46480. word32 eccPrivKeySz = 0;
  46481. WOLFSSL_ENTER("pkcs7enveloped_test");
  46482. #ifndef NO_RSA
  46483. /* read client RSA cert and key in DER format */
  46484. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46485. if (rsaCert == NULL)
  46486. return WC_TEST_RET_ENC_ERRNO;
  46487. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46488. if (rsaPrivKey == NULL) {
  46489. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46490. return WC_TEST_RET_ENC_NC;
  46491. }
  46492. rsaCertSz = FOURK_BUF;
  46493. rsaPrivKeySz = FOURK_BUF;
  46494. #endif /* NO_RSA */
  46495. #ifdef HAVE_ECC
  46496. /* read client ECC cert and key in DER format */
  46497. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46498. if (eccCert == NULL) {
  46499. #ifndef NO_RSA
  46500. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46501. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46502. #endif
  46503. return WC_TEST_RET_ENC_NC;
  46504. }
  46505. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46506. if (eccPrivKey == NULL) {
  46507. #ifndef NO_RSA
  46508. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46509. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46510. #endif
  46511. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46512. return WC_TEST_RET_ENC_NC;
  46513. }
  46514. eccCertSz = FOURK_BUF;
  46515. eccPrivKeySz = FOURK_BUF;
  46516. #endif /* HAVE_ECC */
  46517. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  46518. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  46519. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  46520. eccPrivKey, &eccPrivKeySz);
  46521. if (ret < 0) {
  46522. #ifndef NO_RSA
  46523. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46524. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46525. #endif
  46526. #ifdef HAVE_ECC
  46527. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46528. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46529. #endif
  46530. return WC_TEST_RET_ENC_EC(ret);
  46531. }
  46532. ret = pkcs7enveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  46533. rsaPrivKey, (word32)rsaPrivKeySz,
  46534. eccCert, (word32)eccCertSz,
  46535. eccPrivKey, (word32)eccPrivKeySz);
  46536. #ifndef NO_RSA
  46537. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46538. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46539. #endif
  46540. #ifdef HAVE_ECC
  46541. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46542. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46543. #endif
  46544. return ret;
  46545. }
  46546. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  46547. typedef struct {
  46548. const byte* content;
  46549. word32 contentSz;
  46550. int contentOID;
  46551. int encryptOID;
  46552. int keyWrapOID;
  46553. int keyAgreeOID;
  46554. byte* cert;
  46555. size_t certSz;
  46556. byte* privateKey;
  46557. word32 privateKeySz;
  46558. PKCS7Attrib* authAttribs;
  46559. word32 authAttribsSz;
  46560. PKCS7Attrib* unauthAttribs;
  46561. word32 unauthAttribsSz;
  46562. /* KARI / KTRI specific */
  46563. byte* optionalUkm;
  46564. word32 optionalUkmSz;
  46565. int ktriOptions; /* KTRI options flags */
  46566. int kariOptions; /* KARI options flags */
  46567. /* KEKRI specific */
  46568. byte* secretKey; /* key, only for kekri RecipientInfo types */
  46569. word32 secretKeySz; /* size of secretKey, bytes */
  46570. byte* secretKeyId; /* key identifier */
  46571. word32 secretKeyIdSz; /* size of key identifier, bytes */
  46572. void* timePtr; /* time_t pointer */
  46573. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  46574. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  46575. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  46576. word32 otherAttrSz; /* size of otherAttr, bytes */
  46577. int kekriOptions; /* KEKRI options flags */
  46578. /* PWRI specific */
  46579. char* password; /* password */
  46580. word32 passwordSz; /* password size, bytes */
  46581. byte* salt; /* KDF salt */
  46582. word32 saltSz; /* KDF salt size, bytes */
  46583. int kdfOID; /* KDF OID */
  46584. int hashOID; /* KDF hash algorithm OID */
  46585. int kdfIterations; /* KDF iterations */
  46586. int kekEncryptOID; /* KEK encryption algorithm OID */
  46587. int pwriOptions; /* PWRI options flags */
  46588. /* ORI specific */
  46589. int isOri;
  46590. int oriOptions; /* ORI options flags */
  46591. const char* outFileName;
  46592. } pkcs7AuthEnvelopedVector;
  46593. static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46594. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46595. byte* eccCert, word32 eccCertSz,
  46596. byte* eccPrivKey, word32 eccPrivKeySz)
  46597. {
  46598. wc_test_ret_t ret = 0;
  46599. int testSz = 0, i;
  46600. int envelopedSz, decodedSz;
  46601. byte *enveloped = NULL;
  46602. byte *decoded = NULL;
  46603. WC_RNG rng;
  46604. wc_PKCS7* pkcs7;
  46605. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46606. XFILE pkcs7File;
  46607. #endif
  46608. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46609. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46610. 0x72,0x6c,0x64
  46611. };
  46612. byte senderNonce[PKCS7_NONCE_SZ + 2];
  46613. #ifdef HAVE_ECC
  46614. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46615. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46616. WOLFSSL_SMALL_STACK_STATIC const byte senderNonceOid[] =
  46617. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  46618. 0x09, 0x05 };
  46619. PKCS7Attrib attribs[] =
  46620. {
  46621. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  46622. sizeof(senderNonce) }
  46623. };
  46624. #endif
  46625. #endif
  46626. #endif
  46627. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && defined(HAVE_ECC) && \
  46628. defined(WOLFSSL_SHA512) && defined(HAVE_AESGCM)
  46629. WOLFSSL_SMALL_STACK_STATIC const byte optionalUkm[] = {
  46630. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46631. };
  46632. #endif /* !NO_AES */
  46633. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46634. /* encryption key for kekri recipient types */
  46635. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46636. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46637. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46638. };
  46639. /* encryption key identifier */
  46640. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46641. 0x02,0x02,0x03,0x04
  46642. };
  46643. #endif
  46644. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  46645. !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46646. #ifndef HAVE_FIPS
  46647. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password";
  46648. #else
  46649. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46650. #endif
  46651. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46652. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46653. };
  46654. #endif
  46655. #define MAX_TESTVECTORS_LEN 20
  46656. #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \
  46657. pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46658. if (testSz == MAX_TESTVECTORS_LEN) { \
  46659. ret = WC_TEST_RET_ENC_NC; \
  46660. goto out; \
  46661. } \
  46662. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  46663. sizeof _this_vector); \
  46664. }
  46665. pkcs7AuthEnvelopedVector *testVectors = NULL;
  46666. XMEMSET(&rng, 0, sizeof(rng));
  46667. testVectors = (pkcs7AuthEnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46668. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46669. if (testVectors == NULL) {
  46670. ret = WC_TEST_RET_ENC_ERRNO;
  46671. goto out;
  46672. }
  46673. {
  46674. /* key transport key encryption technique */
  46675. #ifndef NO_RSA
  46676. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46677. #ifdef WOLFSSL_AES_128
  46678. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46679. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, rsaCert, rsaCertSz,
  46680. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46681. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46682. 0, 0, "pkcs7authEnvelopedDataAES128GCM.der");
  46683. #endif
  46684. #ifdef WOLFSSL_AES_192
  46685. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46686. data, (word32)sizeof(data), DATA, AES192GCMb, 0, 0, rsaCert, rsaCertSz,
  46687. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46688. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46689. 0, 0, "pkcs7authEnvelopedDataAES192GCM.der");
  46690. #endif
  46691. #ifdef WOLFSSL_AES_256
  46692. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46693. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46694. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46695. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46696. 0, 0, "pkcs7authEnvelopedDataAES256GCM.der");
  46697. /* test with contentType set to FirmwarePkgData */
  46698. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46699. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, 0, 0,
  46700. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL,
  46701. 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL,
  46702. 0, 0, 0, 0, 0, 0, 0, 0,
  46703. "pkcs7authEnvelopedDataAES256GCM_firmwarePkgData.der");
  46704. /* explicitly using SKID for SubjectKeyIdentifier */
  46705. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46706. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46707. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, CMS_SKID, 0,
  46708. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46709. 0, 0, 0, 0, 0, "pkcs7authEnvelopedDataAES256GCM_SKID.der");
  46710. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46711. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46712. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46713. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0,
  46714. CMS_ISSUER_AND_SERIAL_NUMBER, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46715. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46716. "pkcs7authEnvelopedDataAES256GCM_IANDS.der");
  46717. #endif
  46718. #else
  46719. (void)rsaCert;
  46720. (void)rsaCertSz;
  46721. (void)rsaPrivKey;
  46722. (void)rsaPrivKeySz;
  46723. #endif /* !NO_AES && !HAVE_AESGCM */
  46724. #endif
  46725. /* key agreement key encryption technique*/
  46726. #ifdef HAVE_ECC
  46727. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46728. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46729. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46730. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP,
  46731. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46732. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46733. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46734. "pkcs7authEnvelopedDataAES128GCM_ECDH_SHA1KDF.der");
  46735. #endif
  46736. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46737. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46738. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46739. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46740. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46741. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46742. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF.der");
  46743. /* with authenticated attributes */
  46744. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46745. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46746. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46747. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46748. NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46749. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46750. 0, 0, 0,
  46751. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_authAttribs.der");
  46752. /* with unauthenticated attributes */
  46753. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46754. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46755. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46756. eccPrivKeySz, NULL, 0, attribs,
  46757. (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0, NULL, 0,
  46758. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46759. 0, 0, 0,
  46760. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_unauthAttribs.der");
  46761. /* with authenticated AND unauthenticated attributes */
  46762. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46763. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46764. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46765. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46766. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46767. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46768. 0, 0, 0, 0, 0, 0,
  46769. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_bothAttribs.der");
  46770. /* with authenticated AND unauthenticated attributes AND
  46771. * contentType of FirmwarePkgData */
  46772. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46773. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, AES256_WRAP,
  46774. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46775. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46776. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46777. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46778. 0, 0, 0, 0, 0, 0,
  46779. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_fw_bothAttribs.der");
  46780. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46781. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46782. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46783. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46784. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46785. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL,
  46786. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46787. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF.der");
  46788. /* with optional user keying material (ukm) */
  46789. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46790. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46791. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46792. eccPrivKeySz, NULL, 0, NULL, 0, (byte *)optionalUkm, sizeof(optionalUkm), 0,
  46793. 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46794. 0, 0, 0, 0, 0, 0,
  46795. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF_ukm.der");
  46796. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46797. #endif /* !NO_AES && HAVE_AESGCM */
  46798. #endif
  46799. /* kekri (KEKRecipientInfo) recipient types */
  46800. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46801. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46802. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46803. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP, 0,
  46804. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0,
  46805. (byte *)secretKey, sizeof(secretKey), (byte *)secretKeyId, sizeof(secretKeyId),
  46806. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46807. "pkcs7authEnvelopedDataAES128GCM_KEKRI.der");
  46808. #endif
  46809. #endif
  46810. /* pwri (PasswordRecipientInfo) recipient types */
  46811. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM)
  46812. #if !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46813. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46814. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0,
  46815. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46816. NULL, 0, NULL, NULL, 0, NULL, 0, 0, (char *)password,
  46817. (word32)XSTRLEN(password), (byte *)salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46818. AES128CBCb, 0, 0, 0, "pkcs7authEnvelopedDataAES128GCM_PWRI.der");
  46819. #endif
  46820. #endif
  46821. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46822. #ifdef WOLFSSL_AES_128
  46823. /* ori (OtherRecipientInfo) recipient types */
  46824. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46825. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, NULL, 0, NULL, 0,
  46826. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46827. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 1, 0,
  46828. "pkcs7authEnvelopedDataAES128GCM_ORI.der");
  46829. #endif
  46830. #endif
  46831. }
  46832. #undef MAX_TESTVECTORS_LEN
  46833. #undef ADD_PKCS7AUTHENVELOPEDVECTOR
  46834. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46835. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46836. if ((! enveloped) || (! decoded)) {
  46837. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46838. }
  46839. /* generate senderNonce */
  46840. {
  46841. #ifndef HAVE_FIPS
  46842. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46843. #else
  46844. ret = wc_InitRng(&rng);
  46845. #endif
  46846. if (ret != 0)
  46847. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46848. senderNonce[0] = 0x04;
  46849. senderNonce[1] = PKCS7_NONCE_SZ;
  46850. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  46851. if (ret != 0) {
  46852. wc_FreeRng(&rng);
  46853. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46854. }
  46855. }
  46856. for (i = 0; i < testSz; i++) {
  46857. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46858. #ifdef WOLFSSL_ASYNC_CRYPT
  46859. INVALID_DEVID /* async PKCS7 is not supported */
  46860. #else
  46861. devId
  46862. #endif
  46863. );
  46864. if (pkcs7 == NULL) {
  46865. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46866. }
  46867. if (testVectors[i].secretKey != NULL) {
  46868. /* KEKRI recipient type */
  46869. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46870. if (ret != 0)
  46871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46872. pkcs7->content = (byte*)testVectors[i].content;
  46873. pkcs7->contentSz = testVectors[i].contentSz;
  46874. pkcs7->contentOID = testVectors[i].contentOID;
  46875. pkcs7->encryptOID = testVectors[i].encryptOID;
  46876. pkcs7->ukm = testVectors[i].optionalUkm;
  46877. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46878. pkcs7->authAttribs = testVectors[i].authAttribs;
  46879. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46880. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46881. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46882. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46883. testVectors[i].secretKey, testVectors[i].secretKeySz,
  46884. testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46885. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46886. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46887. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46888. if (ret < 0) {
  46889. wc_PKCS7_Free(pkcs7);
  46890. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46891. }
  46892. /* set key, for decryption */
  46893. ret = wc_PKCS7_SetKey(pkcs7, testVectors[i].secretKey,
  46894. testVectors[i].secretKeySz);
  46895. if (ret != 0) {
  46896. wc_PKCS7_Free(pkcs7);
  46897. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46898. }
  46899. } else if (testVectors[i].password != NULL) {
  46900. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46901. /* PWRI recipient type */
  46902. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46903. if (ret != 0)
  46904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46905. pkcs7->content = (byte*)testVectors[i].content;
  46906. pkcs7->contentSz = testVectors[i].contentSz;
  46907. pkcs7->contentOID = testVectors[i].contentOID;
  46908. pkcs7->encryptOID = testVectors[i].encryptOID;
  46909. pkcs7->ukm = testVectors[i].optionalUkm;
  46910. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46911. pkcs7->authAttribs = testVectors[i].authAttribs;
  46912. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46913. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46914. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46915. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46916. (byte*)testVectors[i].password,
  46917. testVectors[i].passwordSz, testVectors[i].salt,
  46918. testVectors[i].saltSz, testVectors[i].kdfOID,
  46919. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46920. testVectors[i].kekEncryptOID, testVectors[i].pwriOptions);
  46921. if (ret < 0) {
  46922. wc_PKCS7_Free(pkcs7);
  46923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46924. }
  46925. /* set password, for decryption */
  46926. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46927. testVectors[i].passwordSz);
  46928. if (ret < 0) {
  46929. wc_PKCS7_Free(pkcs7);
  46930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46931. }
  46932. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46933. } else if (testVectors[i].isOri == 1) {
  46934. /* ORI recipient type */
  46935. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46936. if (ret != 0)
  46937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46938. pkcs7->content = (byte*)testVectors[i].content;
  46939. pkcs7->contentSz = testVectors[i].contentSz;
  46940. pkcs7->contentOID = testVectors[i].contentOID;
  46941. pkcs7->encryptOID = testVectors[i].encryptOID;
  46942. pkcs7->authAttribs = testVectors[i].authAttribs;
  46943. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46944. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46945. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46946. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46947. testVectors[i].oriOptions);
  46948. if (ret < 0) {
  46949. wc_PKCS7_Free(pkcs7);
  46950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46951. }
  46952. /* set decrypt callback for decryption */
  46953. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46954. if (ret < 0) {
  46955. wc_PKCS7_Free(pkcs7);
  46956. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46957. }
  46958. } else {
  46959. /* KTRI or KARI recipient types */
  46960. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46961. (word32)testVectors[i].certSz);
  46962. if (ret != 0) {
  46963. wc_PKCS7_Free(pkcs7);
  46964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46965. }
  46966. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46967. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46968. pkcs7->privateKey = testVectors[i].privateKey;
  46969. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46970. pkcs7->content = (byte*)testVectors[i].content;
  46971. pkcs7->contentSz = testVectors[i].contentSz;
  46972. pkcs7->contentOID = testVectors[i].contentOID;
  46973. pkcs7->encryptOID = testVectors[i].encryptOID;
  46974. pkcs7->ukm = testVectors[i].optionalUkm;
  46975. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46976. pkcs7->authAttribs = testVectors[i].authAttribs;
  46977. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46978. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46979. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46980. /* set SubjectIdentifier type for KTRI types */
  46981. if (testVectors[i].ktriOptions & CMS_SKID) {
  46982. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46983. if (ret != 0) {
  46984. wc_PKCS7_Free(pkcs7);
  46985. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46986. }
  46987. } else if (testVectors[i].ktriOptions &
  46988. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46989. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46990. CMS_ISSUER_AND_SERIAL_NUMBER);
  46991. if (ret != 0) {
  46992. wc_PKCS7_Free(pkcs7);
  46993. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46994. }
  46995. }
  46996. }
  46997. #ifdef ECC_TIMING_RESISTANT
  46998. pkcs7->rng = &rng;
  46999. #endif
  47000. /* encode envelopedData */
  47001. envelopedSz = wc_PKCS7_EncodeAuthEnvelopedData(pkcs7, enveloped,
  47002. PKCS7_BUF_SIZE);
  47003. if (envelopedSz <= 0) {
  47004. wc_PKCS7_Free(pkcs7);
  47005. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  47006. }
  47007. #ifndef NO_PKCS7_STREAM
  47008. { /* test reading byte by byte */
  47009. int z;
  47010. for (z = 0; z < envelopedSz; z++) {
  47011. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7,
  47012. enveloped + z, 1, decoded, PKCS7_BUF_SIZE);
  47013. if (decodedSz <= 0 &&
  47014. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  47015. {
  47016. printf("unexpected error %d\n", decodedSz);
  47017. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47018. }
  47019. }
  47020. /* test decode result */
  47021. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47022. printf("stream read compare failed\n");
  47023. wc_PKCS7_Free(pkcs7);
  47024. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47025. }
  47026. }
  47027. #endif
  47028. /* decode envelopedData */
  47029. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7, enveloped,
  47030. (word32)envelopedSz, decoded,
  47031. PKCS7_BUF_SIZE);
  47032. if (decodedSz <= 0) {
  47033. wc_PKCS7_Free(pkcs7);
  47034. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47035. }
  47036. /* test decode result */
  47037. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  47038. wc_PKCS7_Free(pkcs7);
  47039. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47040. }
  47041. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47042. /* output pkcs7 envelopedData for external testing */
  47043. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47044. if (!pkcs7File) {
  47045. wc_PKCS7_Free(pkcs7);
  47046. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47047. }
  47048. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  47049. XFCLOSE(pkcs7File);
  47050. if (ret != envelopedSz) {
  47051. wc_PKCS7_Free(pkcs7);
  47052. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47053. } else {
  47054. /* reset ret to 0 for success */
  47055. ret = 0;
  47056. }
  47057. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47058. wc_PKCS7_Free(pkcs7);
  47059. pkcs7 = NULL;
  47060. }
  47061. wc_FreeRng(&rng);
  47062. (void)eccCert;
  47063. (void)eccCertSz;
  47064. (void)eccPrivKey;
  47065. (void)eccPrivKeySz;
  47066. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  47067. (void)secretKey;
  47068. (void)secretKeyId;
  47069. #endif
  47070. #ifdef NO_RSA
  47071. (void)rsaCert;
  47072. (void)rsaCertSz;
  47073. (void)rsaPrivKey;
  47074. (void)rsaPrivKeySz;
  47075. #endif
  47076. out:
  47077. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47078. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47079. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47080. return ret;
  47081. }
  47082. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void)
  47083. {
  47084. wc_test_ret_t ret = 0;
  47085. byte* rsaCert = NULL;
  47086. byte* rsaPrivKey = NULL;
  47087. word32 rsaCertSz = 0;
  47088. word32 rsaPrivKeySz = 0;
  47089. byte* eccCert = NULL;
  47090. byte* eccPrivKey = NULL;
  47091. word32 eccCertSz = 0;
  47092. word32 eccPrivKeySz = 0;
  47093. WOLFSSL_ENTER("pkcs7authenveloped_test");
  47094. #ifndef NO_RSA
  47095. /* read client RSA cert and key in DER format */
  47096. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47097. if (rsaCert == NULL)
  47098. return WC_TEST_RET_ENC_ERRNO;
  47099. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47100. if (rsaPrivKey == NULL) {
  47101. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47102. return WC_TEST_RET_ENC_NC;
  47103. }
  47104. rsaCertSz = FOURK_BUF;
  47105. rsaPrivKeySz = FOURK_BUF;
  47106. #endif /* NO_RSA */
  47107. #ifdef HAVE_ECC
  47108. /* read client ECC cert and key in DER format */
  47109. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47110. if (eccCert == NULL) {
  47111. #ifndef NO_RSA
  47112. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47113. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47114. #endif
  47115. return WC_TEST_RET_ENC_NC;
  47116. }
  47117. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47118. if (eccPrivKey == NULL) {
  47119. #ifndef NO_RSA
  47120. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47121. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47122. #endif
  47123. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47124. return WC_TEST_RET_ENC_NC;
  47125. }
  47126. eccCertSz = FOURK_BUF;
  47127. eccPrivKeySz = FOURK_BUF;
  47128. #endif /* HAVE_ECC */
  47129. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  47130. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  47131. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  47132. eccPrivKey, &eccPrivKeySz);
  47133. if (ret < 0) {
  47134. #ifndef NO_RSA
  47135. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47136. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47137. #endif
  47138. #ifdef HAVE_ECC
  47139. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47140. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47141. #endif
  47142. return WC_TEST_RET_ENC_EC(ret);
  47143. }
  47144. ret = pkcs7authenveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  47145. rsaPrivKey, (word32)rsaPrivKeySz,
  47146. eccCert, (word32)eccCertSz,
  47147. eccPrivKey, (word32)eccPrivKeySz);
  47148. #ifndef NO_RSA
  47149. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47150. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47151. #endif
  47152. #ifdef HAVE_ECC
  47153. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47154. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47155. #endif
  47156. return ret;
  47157. }
  47158. #endif /* HAVE_AESGCM || HAVE_AESCCM */
  47159. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47160. static const byte p7DefKey[] = {
  47161. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47162. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47163. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47164. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47165. };
  47166. static const byte p7AltKey[] = {
  47167. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47168. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47169. };
  47170. static int myCEKwrapFunc(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  47171. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  47172. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  47173. {
  47174. wc_test_ret_t ret;
  47175. if (cek == NULL || out == NULL)
  47176. return BAD_FUNC_ARG;
  47177. /* test case sanity checks */
  47178. if (keyIdSz != 1) {
  47179. return WC_TEST_RET_ENC_NC;
  47180. }
  47181. if (keyId[0] != 0x00) {
  47182. return WC_TEST_RET_ENC_NC;
  47183. }
  47184. if (type != (int)PKCS7_KEKRI) {
  47185. return WC_TEST_RET_ENC_NC;
  47186. }
  47187. switch (keyWrapAlgo) {
  47188. case AES256_WRAP:
  47189. ret = wc_AesKeyUnWrap(p7DefKey, sizeof(p7DefKey), cek, cekSz,
  47190. out, outSz, NULL);
  47191. if (ret <= 0)
  47192. return (int)ret;
  47193. break;
  47194. default:
  47195. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  47196. return BAD_KEYWRAP_ALG_E;
  47197. };
  47198. (void)pkcs7;
  47199. (void)direction;
  47200. (void)orginKey; /* used with KAKRI */
  47201. (void)orginKeySz;
  47202. return (int)ret;
  47203. }
  47204. /* returns key size on success */
  47205. static wc_test_ret_t getFirmwareKey(wc_PKCS7* pkcs7, byte* key, word32 keySz)
  47206. {
  47207. wc_test_ret_t ret;
  47208. word32 atrSz;
  47209. byte atr[256];
  47210. /* Additionally can look for fwWrappedFirmwareKey
  47211. * 1.2.840.113529.1.9.16.1.16 */
  47212. const unsigned char fwWrappedFirmwareKey[] = {
  47213. /* 0x06, 0x0B */
  47214. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47215. 0x01, 0x09, 0x10, 0x02, 0x27
  47216. };
  47217. /* find keyID in fwWrappedFirmwareKey */
  47218. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  47219. sizeof(fwWrappedFirmwareKey), NULL, &atrSz);
  47220. if (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  47221. XMEMSET(atr, 0, sizeof(atr));
  47222. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  47223. sizeof(fwWrappedFirmwareKey), atr, &atrSz);
  47224. /* keyIdRaw[0] OCTET TAG */
  47225. /* keyIdRaw[1] Length */
  47226. if (ret > 0) {
  47227. wc_PKCS7* envPkcs7;
  47228. envPkcs7 = wc_PKCS7_New(NULL, 0);
  47229. if (envPkcs7 == NULL) {
  47230. return MEMORY_E;
  47231. }
  47232. wc_PKCS7_Init(envPkcs7, NULL, 0);
  47233. ret = wc_PKCS7_SetWrapCEKCb(envPkcs7, myCEKwrapFunc);
  47234. if (ret == 0) {
  47235. /* expecting FIRMWARE_PKG_DATA content */
  47236. envPkcs7->contentOID = FIRMWARE_PKG_DATA;
  47237. ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz,
  47238. key, keySz);
  47239. if (envPkcs7->contentOID != FIRMWARE_PKG_DATA) {
  47240. /* the contentOID should have been set to the inner
  47241. * FIRMWARE_PKG_DATA content */
  47242. ret = BAD_STATE_E;
  47243. }
  47244. }
  47245. wc_PKCS7_Free(envPkcs7);
  47246. }
  47247. }
  47248. return ret;
  47249. }
  47250. /* create a KEKRI enveloped data
  47251. * return size on success */
  47252. static wc_test_ret_t envelopedData_encrypt(byte* in, word32 inSz, byte* out,
  47253. word32 outSz)
  47254. {
  47255. wc_test_ret_t ret;
  47256. wc_PKCS7* pkcs7;
  47257. WOLFSSL_SMALL_STACK_STATIC const byte keyId[] = { 0x00 };
  47258. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  47259. if (pkcs7 == NULL)
  47260. return WC_TEST_RET_ENC_ERRNO;
  47261. pkcs7->content = in;
  47262. pkcs7->contentSz = inSz;
  47263. pkcs7->contentOID = FIRMWARE_PKG_DATA;
  47264. pkcs7->encryptOID = AES256CBCb;
  47265. pkcs7->ukm = NULL;
  47266. pkcs7->ukmSz = 0;
  47267. /* add recipient (KEKRI type) */
  47268. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP, (byte*)p7DefKey,
  47269. sizeof(p7DefKey), (byte*)keyId,
  47270. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0);
  47271. if (ret < 0) {
  47272. printf("wc_PKCS7_AddRecipient_KEKRI() failed\n");
  47273. wc_PKCS7_Free(pkcs7);
  47274. return WC_TEST_RET_ENC_EC(ret);
  47275. }
  47276. /* encode envelopedData, returns size */
  47277. ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
  47278. if (ret <= 0) {
  47279. printf("wc_PKCS7_EncodeEnvelopedData() failed\n");
  47280. wc_PKCS7_Free(pkcs7);
  47281. return WC_TEST_RET_ENC_EC(ret);
  47282. }
  47283. wc_PKCS7_Free(pkcs7);
  47284. return ret;
  47285. }
  47286. /*
  47287. * keyHint is the KeyID to be set in the fwDecryptKeyID attribute
  47288. * returns size of buffer output on success
  47289. */
  47290. static wc_test_ret_t generateBundle(byte* out, word32 *outSz, const byte* encryptKey,
  47291. word32 encryptKeySz, byte keyHint, byte* cert, word32 certSz,
  47292. byte* key, word32 keySz)
  47293. {
  47294. wc_test_ret_t ret;
  47295. int attribNum = 1;
  47296. wc_PKCS7* pkcs7;
  47297. /* KEY ID
  47298. * fwDecryptKeyID OID 1.2.840.113549.1.9.16.2.37
  47299. */
  47300. const unsigned char fwDecryptKeyID[] = {
  47301. 0x06, 0x0B,
  47302. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47303. 0x01, 0x09, 0x10, 0x02, 0x25
  47304. };
  47305. /* fwWrappedFirmwareKey 1.2.840.113529.1.9.16.1.16 */
  47306. const unsigned char fwWrappedFirmwareKey[] = {
  47307. 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47308. 0x01, 0x09, 0x10, 0x02, 0x27
  47309. };
  47310. byte keyID[] = { 0x04, 0x01, 0x00 };
  47311. byte env[256];
  47312. char data[] = "Test of wolfSSL PKCS7 decrypt callback";
  47313. PKCS7Attrib attribs[] =
  47314. {
  47315. { fwDecryptKeyID, sizeof(fwDecryptKeyID), keyID, sizeof(keyID) },
  47316. { fwWrappedFirmwareKey, sizeof(fwWrappedFirmwareKey), env, 0 }
  47317. };
  47318. keyID[2] = keyHint;
  47319. /* If using keyHint 0 then create a bundle with fwWrappedFirmwareKey */
  47320. if (keyHint == 0) {
  47321. ret = envelopedData_encrypt((byte*)p7DefKey, sizeof(p7DefKey), env,
  47322. sizeof(env));
  47323. if (ret <= 0) {
  47324. return ret;
  47325. }
  47326. attribs[1].valueSz = (word32)ret;
  47327. attribNum++;
  47328. }
  47329. /* init PKCS7 */
  47330. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  47331. if (pkcs7 == NULL)
  47332. return WC_TEST_RET_ENC_ERRNO;
  47333. ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz);
  47334. if (ret != 0) {
  47335. printf("ERROR: wc_PKCS7_InitWithCert() failed, ret = %d\n", ret);
  47336. wc_PKCS7_Free(pkcs7);
  47337. return WC_TEST_RET_ENC_EC(ret);
  47338. }
  47339. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47340. if (ret != 0) {
  47341. wc_PKCS7_Free(pkcs7);
  47342. return WC_TEST_RET_ENC_EC(ret);
  47343. }
  47344. /* encode Signed Encrypted FirmwarePkgData */
  47345. if (encryptKeySz == 16) {
  47346. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  47347. encryptKeySz, key, keySz, AES128CBCb, RSAk, SHA256h,
  47348. (byte*)data, sizeof(data), NULL, 0,
  47349. attribs, (word32)attribNum, out, *outSz);
  47350. }
  47351. else {
  47352. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  47353. encryptKeySz, key, keySz, AES256CBCb, RSAk, SHA256h,
  47354. (byte*)data, sizeof(data), NULL, 0,
  47355. attribs, (word32)attribNum, out, *outSz);
  47356. }
  47357. if (ret <= 0) {
  47358. printf("ERROR: wc_PKCS7_EncodeSignedEncryptedFPD() failed, "
  47359. "ret = %d\n", ret);
  47360. wc_PKCS7_Free(pkcs7);
  47361. return WC_TEST_RET_ENC_EC(ret);
  47362. } else {
  47363. *outSz = (word32)ret;
  47364. }
  47365. wc_PKCS7_Free(pkcs7);
  47366. return ret;
  47367. }
  47368. /* test verification and decryption of PKCS7 bundle
  47369. * return 0 on success
  47370. */
  47371. static wc_test_ret_t verifyBundle(byte* derBuf, word32 derSz, int keyHint)
  47372. {
  47373. wc_test_ret_t ret = 0;
  47374. int usrCtx = 1; /* test value to pass as user context to callback */
  47375. wc_PKCS7* pkcs7 = NULL;
  47376. byte* sid = NULL;
  47377. word32 sidSz;
  47378. byte key[256];
  47379. word32 keySz = sizeof(key);
  47380. byte *decoded = NULL;
  47381. int decodedSz = FOURK_BUF/2;
  47382. WOLFSSL_SMALL_STACK_STATIC const byte expectedSid[] = {
  47383. #ifdef NO_SHA
  47384. #ifdef USE_CERT_BUFFERS_1024
  47385. 0x70, 0xe7, 0x79, 0x60, 0x8f, 0x41, 0xdc, 0xe9,
  47386. 0xad, 0x8b, 0x3d, 0x0c, 0x20, 0xf4, 0xc3, 0xf2,
  47387. 0x8e, 0x05, 0xe8, 0xa1, 0xb6, 0x68, 0x74, 0x06,
  47388. 0xbc, 0xe7, 0xc5, 0x3c, 0x13, 0x99, 0x79, 0xb9
  47389. #else
  47390. 0xce, 0x06, 0x07, 0xbe, 0xf1, 0xa6, 0x1e, 0x36,
  47391. 0xef, 0xfa, 0xbc, 0x89, 0x71, 0xf3, 0x23, 0x9e,
  47392. 0x34, 0x6d, 0xae, 0x86, 0xae, 0x2b, 0xdc, 0xf4,
  47393. 0x4a, 0x27, 0xd5, 0x63, 0x59, 0x4f, 0x4a, 0x71
  47394. #endif
  47395. #else /* !NO_SHA */
  47396. #ifdef USE_CERT_BUFFERS_1024
  47397. 0x81, 0x69, 0x0f, 0xf8, 0xdf, 0xdd, 0xcf, 0x34,
  47398. 0x29, 0xd5, 0x67, 0x75, 0x71, 0x85, 0xc7, 0x75,
  47399. 0x10, 0x69, 0x59, 0xec,
  47400. #else
  47401. 0x33, 0xD8, 0x45, 0x66, 0xD7, 0x68, 0x87, 0x18,
  47402. 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26,
  47403. 0xD7, 0x85, 0x65, 0xC0
  47404. #endif
  47405. #endif /* !NO_SHA */
  47406. };
  47407. decoded = (byte *)XMALLOC(decodedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47408. if (decoded == NULL) {
  47409. ret = MEMORY_E;
  47410. goto out;
  47411. }
  47412. pkcs7 = wc_PKCS7_New(HEAP_HINT, INVALID_DEVID);
  47413. if (pkcs7 == NULL) {
  47414. ret = MEMORY_E;
  47415. goto out;
  47416. }
  47417. /* Test verify */
  47418. ret = wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID);
  47419. if (ret != 0)
  47420. goto out;
  47421. ret = wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47422. if (ret != 0)
  47423. goto out;
  47424. ret = wc_PKCS7_VerifySignedData(pkcs7, derBuf, derSz);
  47425. if (ret != 0)
  47426. goto out;
  47427. /* Get size of SID and print it out */
  47428. ret = wc_PKCS7_GetSignerSID(pkcs7, NULL, &sidSz);
  47429. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  47430. goto out;
  47431. sid = (byte*)XMALLOC(sidSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47432. if (sid == NULL) {
  47433. ret = MEMORY_E;
  47434. goto out;
  47435. }
  47436. ret = wc_PKCS7_GetSignerSID(pkcs7, sid, &sidSz);
  47437. if (ret != 0)
  47438. goto out;
  47439. ret = XMEMCMP(sid, expectedSid, sidSz);
  47440. if (ret != 0) {
  47441. ret = PKCS7_NO_SIGNER_E; /* close enough */
  47442. goto out;
  47443. }
  47444. /* get expected fwWrappedFirmwareKey */
  47445. if (keyHint == 0) {
  47446. ret = getFirmwareKey(pkcs7, key, keySz);
  47447. if (ret < 0)
  47448. goto out;
  47449. pkcs7->encryptionKey = key;
  47450. pkcs7->encryptionKeySz = (word32)ret;
  47451. }
  47452. else {
  47453. decodedSz = PKCS7_BUF_SIZE;
  47454. ret = wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc);
  47455. if (ret != 0)
  47456. goto out;
  47457. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)&usrCtx);
  47458. if (ret != 0)
  47459. goto out;
  47460. }
  47461. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  47462. pkcs7->contentSz, decoded, (word32)decodedSz);
  47463. if (decodedSz < 0) {
  47464. ret = decodedSz;
  47465. goto out;
  47466. }
  47467. ret = 0;
  47468. out:
  47469. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47470. if (pkcs7)
  47471. wc_PKCS7_Free(pkcs7);
  47472. XFREE(sid, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47473. return ret;
  47474. }
  47475. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key, word32 keySz)
  47476. {
  47477. wc_test_ret_t ret = 0;
  47478. word32 derSz;
  47479. byte *derBuf = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47480. WOLFSSL_ENTER("pkcs7callback_test");
  47481. if (! derBuf)
  47482. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47483. /* Doing default generation and verify */
  47484. derSz = FOURK_BUF;
  47485. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 0, cert,
  47486. certSz, key, keySz);
  47487. if (ret <= 0) {
  47488. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47489. }
  47490. ret = verifyBundle(derBuf, derSz, 0);
  47491. if (ret != 0)
  47492. ERROR_OUT(ret, out);
  47493. /* test choosing other key with keyID */
  47494. derSz = FOURK_BUF;
  47495. ret = generateBundle(derBuf, &derSz, p7AltKey, sizeof(p7AltKey), 1,
  47496. cert, certSz, key, keySz);
  47497. if (ret <= 0) {
  47498. ERROR_OUT(ret, out);
  47499. }
  47500. ret = verifyBundle(derBuf, derSz, 1);
  47501. if (ret != 0)
  47502. ERROR_OUT(ret, out);
  47503. /* test fail case with wrong keyID */
  47504. derSz = FOURK_BUF;
  47505. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 1,
  47506. cert, certSz, key, keySz);
  47507. if (ret <= 0) {
  47508. ERROR_OUT(ret, out);
  47509. }
  47510. ret = verifyBundle(derBuf, derSz, 1);
  47511. if (ret == 0) {
  47512. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47513. }
  47514. ret = 0;
  47515. out:
  47516. XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47517. return ret;
  47518. }
  47519. #endif /* !NO_AES && HAVE_AES_CBC */
  47520. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47521. typedef struct {
  47522. const byte* content;
  47523. word32 contentSz;
  47524. int contentOID;
  47525. int encryptOID;
  47526. byte* encryptionKey;
  47527. word32 encryptionKeySz;
  47528. PKCS7Attrib* attribs;
  47529. word32 attribsSz;
  47530. const char* outFileName;
  47531. } pkcs7EncryptedVector;
  47532. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void)
  47533. {
  47534. wc_test_ret_t ret = 0;
  47535. int i, testSz;
  47536. int encryptedSz, decodedSz, attribIdx;
  47537. wc_PKCS7* pkcs7;
  47538. byte *encrypted;
  47539. byte *decoded;
  47540. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47541. XFILE pkcs7File;
  47542. #endif
  47543. PKCS7Attrib* expectedAttrib;
  47544. PKCS7DecodedAttrib* decodedAttrib;
  47545. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47546. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47547. 0x72,0x6c,0x64
  47548. };
  47549. #ifndef NO_DES3
  47550. byte desKey[] = {
  47551. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  47552. };
  47553. byte des3Key[] = {
  47554. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  47555. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  47556. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  47557. };
  47558. #endif
  47559. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47560. #ifdef WOLFSSL_AES_128
  47561. byte aes128Key[] = {
  47562. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47563. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47564. };
  47565. #endif
  47566. #ifdef WOLFSSL_AES_192
  47567. byte aes192Key[] = {
  47568. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47569. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47570. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47571. };
  47572. #endif
  47573. #ifdef WOLFSSL_AES_256
  47574. byte aes256Key[] = {
  47575. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47576. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47577. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47578. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47579. };
  47580. #endif
  47581. #ifdef WOLFSSL_AES_256
  47582. /* Attribute example from RFC 4134, Section 7.2
  47583. * OID = 1.2.5555
  47584. * OCTET STRING = 'This is a test General ASN Attribute, number 1.' */
  47585. static const byte genAttrOid[] = { 0x06, 0x03, 0x2a, 0xab, 0x33 };
  47586. static const byte genAttr[] = { 0x04, 47,
  47587. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47588. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47589. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47590. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47591. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47592. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x31, 0x2e };
  47593. static const byte genAttrOid2[] = { 0x06, 0x03, 0x2a, 0xab, 0x34 };
  47594. static const byte genAttr2[] = { 0x04, 47,
  47595. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47596. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47597. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47598. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47599. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47600. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x32, 0x2e };
  47601. PKCS7Attrib attribs[] =
  47602. {
  47603. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) }
  47604. };
  47605. PKCS7Attrib multiAttribs[] =
  47606. {
  47607. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) },
  47608. { genAttrOid2, sizeof(genAttrOid2), genAttr2, sizeof(genAttr2) }
  47609. };
  47610. #endif
  47611. #endif /* NO_AES */
  47612. const pkcs7EncryptedVector testVectors[] =
  47613. {
  47614. #ifndef NO_DES3
  47615. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key),
  47616. NULL, 0, "pkcs7encryptedDataDES3.der"},
  47617. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey),
  47618. NULL, 0, "pkcs7encryptedDataDES.der"},
  47619. #endif /* NO_DES3 */
  47620. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47621. #ifdef WOLFSSL_AES_128
  47622. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  47623. sizeof(aes128Key), NULL, 0, "pkcs7encryptedDataAES128CBC.der"},
  47624. #endif
  47625. #ifdef WOLFSSL_AES_192
  47626. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  47627. sizeof(aes192Key), NULL, 0, "pkcs7encryptedDataAES192CBC.der"},
  47628. #endif
  47629. #ifdef WOLFSSL_AES_256
  47630. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47631. sizeof(aes256Key), NULL, 0, "pkcs7encryptedDataAES256CBC.der"},
  47632. /* test with optional unprotected attributes */
  47633. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47634. sizeof(aes256Key), attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47635. "pkcs7encryptedDataAES256CBC_attribs.der"},
  47636. /* test with multiple optional unprotected attributes */
  47637. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47638. sizeof(aes256Key), multiAttribs,
  47639. (sizeof(multiAttribs)/sizeof(PKCS7Attrib)),
  47640. "pkcs7encryptedDataAES256CBC_multi_attribs.der"},
  47641. /* test with contentType set to FirmwarePkgData */
  47642. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256CBCb, aes256Key,
  47643. sizeof(aes256Key), NULL, 0,
  47644. "pkcs7encryptedDataAES256CBC_firmwarePkgData.der"},
  47645. #endif
  47646. #endif /* !NO_AES && HAVE_AES_CBC */
  47647. };
  47648. WOLFSSL_ENTER("pkcs7encrypted_test");
  47649. encrypted = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47650. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47651. if ((! encrypted) || (! decoded)) {
  47652. ERROR_OUT(MEMORY_E, out);
  47653. }
  47654. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  47655. for (i = 0; i < testSz; i++) {
  47656. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47657. if (pkcs7 == NULL) {
  47658. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47659. }
  47660. pkcs7->content = (byte*)testVectors[i].content;
  47661. pkcs7->contentSz = testVectors[i].contentSz;
  47662. pkcs7->contentOID = testVectors[i].contentOID;
  47663. pkcs7->encryptOID = testVectors[i].encryptOID;
  47664. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  47665. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  47666. pkcs7->unprotectedAttribs = testVectors[i].attribs;
  47667. pkcs7->unprotectedAttribsSz = testVectors[i].attribsSz;
  47668. /* encode encryptedData */
  47669. encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47670. PKCS7_BUF_SIZE);
  47671. if (encryptedSz <= 0) {
  47672. wc_PKCS7_Free(pkcs7);
  47673. ERROR_OUT(WC_TEST_RET_ENC_EC(encryptedSz), out);
  47674. }
  47675. /* decode encryptedData */
  47676. #ifndef NO_PKCS7_STREAM
  47677. { /* test reading byte by byte */
  47678. int z;
  47679. for (z = 0; z < encryptedSz; z++) {
  47680. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted + z, 1,
  47681. decoded, PKCS7_BUF_SIZE);
  47682. if (decodedSz <= 0 &&
  47683. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  47684. {
  47685. printf("unexpected error %d\n", decodedSz);
  47686. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47687. }
  47688. }
  47689. /* test decode result */
  47690. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47691. printf("stream read failed\n");
  47692. wc_PKCS7_Free(pkcs7);
  47693. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47694. }
  47695. }
  47696. #endif
  47697. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47698. decoded, PKCS7_BUF_SIZE);
  47699. if (decodedSz <= 0){
  47700. wc_PKCS7_Free(pkcs7);
  47701. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47702. }
  47703. /* test decode result */
  47704. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47705. wc_PKCS7_Free(pkcs7);
  47706. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47707. }
  47708. /* verify decoded unprotected attributes */
  47709. if (pkcs7->decodedAttrib != NULL) {
  47710. decodedAttrib = pkcs7->decodedAttrib;
  47711. attribIdx = 1;
  47712. while (decodedAttrib != NULL) {
  47713. /* expected attribute, stored list is reversed */
  47714. expectedAttrib = &(pkcs7->unprotectedAttribs
  47715. [pkcs7->unprotectedAttribsSz - attribIdx]);
  47716. /* verify oid */
  47717. if (XMEMCMP(decodedAttrib->oid, expectedAttrib->oid,
  47718. decodedAttrib->oidSz) != 0) {
  47719. wc_PKCS7_Free(pkcs7);
  47720. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47721. }
  47722. /* verify value */
  47723. if (XMEMCMP(decodedAttrib->value, expectedAttrib->value,
  47724. decodedAttrib->valueSz) != 0) {
  47725. wc_PKCS7_Free(pkcs7);
  47726. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47727. }
  47728. decodedAttrib = decodedAttrib->next;
  47729. attribIdx++;
  47730. }
  47731. }
  47732. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47733. /* output pkcs7 envelopedData for external testing */
  47734. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47735. if (!pkcs7File) {
  47736. wc_PKCS7_Free(pkcs7);
  47737. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47738. }
  47739. ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File);
  47740. if (ret < 0)
  47741. ret = WC_TEST_RET_ENC_ERRNO;
  47742. else
  47743. ret = 0;
  47744. XFCLOSE(pkcs7File);
  47745. #endif
  47746. wc_PKCS7_Free(pkcs7);
  47747. }
  47748. out:
  47749. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47750. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47751. return ret;
  47752. }
  47753. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47754. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47755. typedef struct {
  47756. const byte* content;
  47757. word32 contentSz;
  47758. int contentOID;
  47759. const char* outFileName;
  47760. } pkcs7CompressedVector;
  47761. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void)
  47762. {
  47763. wc_test_ret_t ret = 0;
  47764. int i, testSz;
  47765. int compressedSz, decodedSz;
  47766. wc_PKCS7* pkcs7;
  47767. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47768. byte *compressed;
  47769. byte *decoded;
  47770. #else
  47771. byte compressed[PKCS7_BUF_SIZE];
  47772. byte decoded[PKCS7_BUF_SIZE];
  47773. #endif
  47774. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47775. XFILE pkcs7File;
  47776. #endif
  47777. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47778. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47779. 0x72,0x6c,0x64
  47780. };
  47781. const pkcs7CompressedVector testVectors[] =
  47782. {
  47783. {data, (word32)sizeof(data), DATA,
  47784. "pkcs7compressedData_data_zlib.der"},
  47785. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA,
  47786. "pkcs7compressedData_firmwarePkgData_zlib.der"},
  47787. };
  47788. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47789. compressed = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47790. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47791. if ((! compressed) || (! decoded)) {
  47792. ERROR_OUT(MEMORY_E, out);
  47793. }
  47794. #endif
  47795. WOLFSSL_ENTER("pkcs7compressed_test");
  47796. testSz = sizeof(testVectors) / sizeof(pkcs7CompressedVector);
  47797. for (i = 0; i < testSz; i++) {
  47798. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47799. if (pkcs7 == NULL) {
  47800. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47801. }
  47802. pkcs7->content = (byte*)testVectors[i].content;
  47803. pkcs7->contentSz = testVectors[i].contentSz;
  47804. pkcs7->contentOID = testVectors[i].contentOID;
  47805. /* encode compressedData */
  47806. compressedSz = wc_PKCS7_EncodeCompressedData(pkcs7, compressed,
  47807. PKCS7_BUF_SIZE);
  47808. if (compressedSz <= 0) {
  47809. wc_PKCS7_Free(pkcs7);
  47810. ERROR_OUT(WC_TEST_RET_ENC_EC(compressedSz), out);
  47811. }
  47812. /* decode compressedData */
  47813. decodedSz = wc_PKCS7_DecodeCompressedData(pkcs7, compressed,
  47814. compressedSz, decoded,
  47815. PKCS7_BUF_SIZE);
  47816. if (decodedSz <= 0){
  47817. wc_PKCS7_Free(pkcs7);
  47818. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47819. }
  47820. /* test decode result */
  47821. if (XMEMCMP(decoded, testVectors[i].content,
  47822. testVectors[i].contentSz) != 0) {
  47823. wc_PKCS7_Free(pkcs7);
  47824. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47825. }
  47826. /* make sure content type is the same */
  47827. if (testVectors[i].contentOID != pkcs7->contentOID) {
  47828. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47829. }
  47830. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47831. /* output pkcs7 compressedData for external testing */
  47832. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47833. if (!pkcs7File) {
  47834. wc_PKCS7_Free(pkcs7);
  47835. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47836. }
  47837. ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File);
  47838. if (ret < 0)
  47839. ret = WC_TEST_RET_ENC_ERRNO;
  47840. else
  47841. ret = 0;
  47842. XFCLOSE(pkcs7File);
  47843. #endif
  47844. wc_PKCS7_Free(pkcs7);
  47845. }
  47846. out:
  47847. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47848. XFREE(compressed, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47849. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47850. #endif
  47851. return ret;
  47852. } /* pkcs7compressed_test() */
  47853. #undef PKCS7_BUF_SIZE
  47854. #endif /* HAVE_LIBZ */
  47855. typedef struct {
  47856. const byte* content;
  47857. word32 contentSz;
  47858. int hashOID;
  47859. int signOID;
  47860. byte* privateKey;
  47861. word32 privateKeySz;
  47862. byte* cert;
  47863. size_t certSz;
  47864. byte* caCert;
  47865. size_t caCertSz;
  47866. PKCS7Attrib* signedAttribs;
  47867. word32 signedAttribsSz;
  47868. const char* outFileName;
  47869. int contentOID;
  47870. const byte* contentType;
  47871. word32 contentTypeSz;
  47872. int sidType;
  47873. int encryptOID; /* for single-shot encrypt alg OID */
  47874. int encCompFlag; /* for single-shot. 1 = enc, 2 = comp, 3 = both*/
  47875. const byte* encryptKey; /* for single-shot, encryptedData */
  47876. word32 encryptKeySz; /* for single-shot, encryptedData */
  47877. PKCS7Attrib* unprotectedAttribs; /* for single-shot, encryptedData */
  47878. word32 unprotectedAttribsSz; /* for single-shot, encryptedData */
  47879. word16 detachedSignature; /* generate detached signature (0:1) */
  47880. } pkcs7SignedVector;
  47881. static wc_test_ret_t pkcs7signed_run_vectors(
  47882. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47883. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47884. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47885. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47886. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47887. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47888. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47889. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47890. {
  47891. wc_test_ret_t ret;
  47892. int testSz = 0, i;
  47893. int encodedSz;
  47894. byte* out = NULL;
  47895. word32 outSz;
  47896. WC_RNG rng;
  47897. wc_PKCS7* pkcs7 = NULL;
  47898. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47899. XFILE file;
  47900. #endif
  47901. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47902. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47903. 0x72,0x6c,0x64
  47904. };
  47905. static const byte transIdOid[] =
  47906. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47907. 0x09, 0x07 };
  47908. static const byte messageTypeOid[] =
  47909. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47910. 0x09, 0x02 };
  47911. static const byte senderNonceOid[] =
  47912. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47913. 0x09, 0x05 };
  47914. #ifndef NO_SHA
  47915. byte transId[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47916. #else
  47917. byte transId[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47918. #endif
  47919. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47920. byte senderNonce[PKCS7_NONCE_SZ + 2];
  47921. PKCS7Attrib attribs[] =
  47922. {
  47923. { transIdOid, sizeof(transIdOid), transId,
  47924. sizeof(transId) - 1 }, /* take off the null */
  47925. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47926. sizeof(messageType) },
  47927. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  47928. sizeof(senderNonce) }
  47929. };
  47930. /* for testing custom contentType, FirmwarePkgData */
  47931. static const byte customContentType[] = { 0x06, 0x0B, 0x2A, 0x86,
  47932. 0x48, 0x86, 0xF7, 0x0D,
  47933. 0x01, 0x09, 0x10, 0x01, 0x10 };
  47934. #define MAX_TESTVECTORS_LEN 20
  47935. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47936. const pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47937. if (testSz == MAX_TESTVECTORS_LEN) { \
  47938. ret = WC_TEST_RET_ENC_NC; \
  47939. goto out; \
  47940. } \
  47941. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47942. sizeof _this_vector); \
  47943. }
  47944. pkcs7SignedVector *testVectors = NULL;
  47945. XMEMSET(&rng, 0, sizeof(rng));
  47946. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47947. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47948. if (testVectors == NULL) {
  47949. ret = WC_TEST_RET_ENC_ERRNO;
  47950. goto out;
  47951. }
  47952. {
  47953. #ifndef NO_RSA
  47954. #ifndef NO_SHA
  47955. /* RSA with SHA */
  47956. ADD_PKCS7SIGNEDVECTOR(
  47957. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47958. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47959. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47960. "pkcs7signedData_RSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0, NULL,
  47961. 0, 0);
  47962. /* RSA with SHA, no signed attributes */
  47963. ADD_PKCS7SIGNEDVECTOR(
  47964. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47965. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz,
  47966. NULL, 0, NULL, 0,
  47967. "pkcs7signedData_RSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47968. NULL, 0, 0);
  47969. #endif
  47970. #ifdef WOLFSSL_SHA224
  47971. /* RSA with SHA224 */
  47972. ADD_PKCS7SIGNEDVECTOR(
  47973. data, (word32)sizeof(data), SHA224h, RSAk, rsaClientPrivKeyBuf,
  47974. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47975. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47976. "pkcs7signedData_RSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47977. NULL, 0, 0);
  47978. #endif
  47979. #ifndef NO_SHA256
  47980. /* RSA with SHA256 */
  47981. ADD_PKCS7SIGNEDVECTOR(
  47982. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47983. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47984. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47985. "pkcs7signedData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47986. NULL, 0, 0);
  47987. /* RSA with SHA256, detached signature */
  47988. ADD_PKCS7SIGNEDVECTOR(
  47989. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47990. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47991. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47992. "pkcs7signedData_RSA_SHA256_detachedSig.der", 0, NULL, 0, 0, 0, 0,
  47993. NULL, 0, NULL, 0, 1);
  47994. /* RSA with SHA256 and SubjectKeyIdentifier in SignerIdentifier */
  47995. ADD_PKCS7SIGNEDVECTOR(
  47996. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47997. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47998. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47999. "pkcs7signedData_RSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  48000. NULL, 0, NULL, 0, 0);
  48001. /* RSA with SHA256 and custom contentType */
  48002. ADD_PKCS7SIGNEDVECTOR(
  48003. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48004. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48005. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48006. "pkcs7signedData_RSA_SHA256_custom_contentType.der", 0,
  48007. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  48008. NULL, 0, 0);
  48009. /* RSA with SHA256 and FirmwarePkgData contentType */
  48010. ADD_PKCS7SIGNEDVECTOR(
  48011. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48012. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48013. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48014. "pkcs7signedData_RSA_SHA256_firmwarePkgData.der",
  48015. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48016. /* RSA with SHA256 using server cert and ca cert */
  48017. ADD_PKCS7SIGNEDVECTOR(
  48018. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48019. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48020. rsaCaCertBuf, rsaCaCertBufSz,
  48021. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48022. "pkcs7signedData_RSA_SHA256_with_ca_cert.der", 0, NULL, 0, 0, 0, 0,
  48023. NULL, 0, NULL, 0, 0);
  48024. #endif
  48025. #if defined(WOLFSSL_SHA384)
  48026. /* RSA with SHA384 */
  48027. ADD_PKCS7SIGNEDVECTOR(
  48028. data, (word32)sizeof(data), SHA384h, RSAk, rsaClientPrivKeyBuf,
  48029. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48030. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48031. "pkcs7signedData_RSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48032. NULL, 0, 0);
  48033. #endif
  48034. #if defined(WOLFSSL_SHA512)
  48035. /* RSA with SHA512 */
  48036. ADD_PKCS7SIGNEDVECTOR(
  48037. data, (word32)sizeof(data), SHA512h, RSAk, rsaClientPrivKeyBuf,
  48038. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48039. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48040. "pkcs7signedData_RSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48041. NULL, 0, 0);
  48042. #endif
  48043. #endif /* NO_RSA */
  48044. #ifdef HAVE_ECC
  48045. #ifndef NO_SHA
  48046. /* ECDSA with SHA */
  48047. ADD_PKCS7SIGNEDVECTOR(
  48048. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  48049. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48050. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48051. "pkcs7signedData_ECDSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48052. NULL, 0, 0);
  48053. /* ECDSA with SHA, no signed attributes */
  48054. ADD_PKCS7SIGNEDVECTOR(
  48055. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  48056. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz,
  48057. NULL, 0, NULL, 0,
  48058. "pkcs7signedData_ECDSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48059. NULL, 0, 0);
  48060. #endif
  48061. #ifdef WOLFSSL_SHA224
  48062. /* ECDSA with SHA224 */
  48063. ADD_PKCS7SIGNEDVECTOR(
  48064. data, (word32)sizeof(data), SHA224h, ECDSAk, eccClientPrivKeyBuf,
  48065. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48066. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48067. "pkcs7signedData_ECDSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48068. NULL, 0, 0);
  48069. #endif
  48070. #ifndef NO_SHA256
  48071. /* ECDSA with SHA256 */
  48072. ADD_PKCS7SIGNEDVECTOR(
  48073. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48074. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48075. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48076. "pkcs7signedData_ECDSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48077. NULL, 0, 0);
  48078. /* ECDSA with SHA256 and SubjectKeyIdentifier in SigherIdentifier */
  48079. ADD_PKCS7SIGNEDVECTOR(
  48080. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48081. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48082. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48083. "pkcs7signedData_ECDSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  48084. NULL, 0, NULL, 0, 0);
  48085. /* ECDSA with SHA256 and custom contentType */
  48086. ADD_PKCS7SIGNEDVECTOR(
  48087. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48088. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48089. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48090. "pkcs7signedData_ECDSA_SHA256_custom_contentType.der", 0,
  48091. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  48092. NULL, 0, 0);
  48093. /* ECDSA with SHA256 and FirmwarePkgData contentType */
  48094. ADD_PKCS7SIGNEDVECTOR(
  48095. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48096. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48097. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48098. "pkcs7signedData_ECDSA_SHA256_firmwarePkgData.der",
  48099. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48100. #endif
  48101. #ifdef WOLFSSL_SHA384
  48102. /* ECDSA with SHA384 */
  48103. ADD_PKCS7SIGNEDVECTOR(
  48104. data, (word32)sizeof(data), SHA384h, ECDSAk, eccClientPrivKeyBuf,
  48105. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48106. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48107. "pkcs7signedData_ECDSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48108. NULL, 0, 0);
  48109. #endif
  48110. #ifdef WOLFSSL_SHA512
  48111. /* ECDSA with SHA512 */
  48112. ADD_PKCS7SIGNEDVECTOR(
  48113. data, (word32)sizeof(data), SHA512h, ECDSAk, eccClientPrivKeyBuf,
  48114. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48115. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48116. "pkcs7signedData_ECDSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48117. NULL, 0, 0);
  48118. #endif
  48119. #endif /* HAVE_ECC */
  48120. };
  48121. #undef MAX_TESTVECTORS_LEN
  48122. #undef ADD_PKCS7SIGNEDVECTOR
  48123. outSz = FOURK_BUF;
  48124. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48125. if (out == NULL)
  48126. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48127. XMEMSET(out, 0, outSz);
  48128. /* test inner pad size error with block size being 0 */
  48129. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 0);
  48130. if (ret > 0)
  48131. ERROR_OUT(-1, out);
  48132. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48133. if (ret < 0)
  48134. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48135. #ifndef HAVE_FIPS
  48136. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48137. #else
  48138. ret = wc_InitRng(&rng);
  48139. #endif
  48140. if (ret != 0)
  48141. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48142. for (i = 0; i < testSz; i++) {
  48143. if (pkcs7)
  48144. wc_PKCS7_Free(pkcs7);
  48145. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48146. if (pkcs7 == NULL)
  48147. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48148. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48149. (word32)testVectors[i].certSz);
  48150. if (ret != 0)
  48151. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48152. /* load CA certificate, if present */
  48153. if (testVectors[i].caCert != NULL) {
  48154. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48155. (word32)testVectors[i].caCertSz);
  48156. if (ret != 0)
  48157. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48158. }
  48159. pkcs7->rng = &rng;
  48160. pkcs7->content = (byte*)testVectors[i].content;
  48161. pkcs7->contentSz = testVectors[i].contentSz;
  48162. pkcs7->contentOID = testVectors[i].contentOID;
  48163. pkcs7->hashOID = testVectors[i].hashOID;
  48164. pkcs7->encryptOID = testVectors[i].signOID;
  48165. pkcs7->privateKey = testVectors[i].privateKey;
  48166. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  48167. pkcs7->signedAttribs = testVectors[i].signedAttribs;
  48168. pkcs7->signedAttribsSz = testVectors[i].signedAttribsSz;
  48169. /* optional custom contentType, default is DATA,
  48170. overrides contentOID if set */
  48171. if (testVectors[i].contentType != NULL) {
  48172. ret = wc_PKCS7_SetContentType(pkcs7,
  48173. (byte *)testVectors[i].contentType,
  48174. testVectors[i].contentTypeSz);
  48175. if (ret != 0)
  48176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48177. }
  48178. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48179. default is IssuerAndSerialNumber */
  48180. if (testVectors[i].sidType == CMS_SKID) {
  48181. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48182. if (ret != 0)
  48183. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48184. }
  48185. /* generate senderNonce */
  48186. {
  48187. senderNonce[0] = 0x04;
  48188. senderNonce[1] = PKCS7_NONCE_SZ;
  48189. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  48190. if (ret != 0)
  48191. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48192. }
  48193. /* generate transactionID (used with SCEP) */
  48194. {
  48195. #ifndef NO_SHA
  48196. wc_Sha sha;
  48197. byte digest[WC_SHA_DIGEST_SIZE];
  48198. #else
  48199. wc_Sha256 sha;
  48200. byte digest[WC_SHA256_DIGEST_SIZE];
  48201. #endif
  48202. int j,k;
  48203. transId[0] = 0x13;
  48204. transId[1] = sizeof(digest) * 2;
  48205. #ifndef NO_SHA
  48206. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  48207. if (ret != 0)
  48208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48209. wc_ShaUpdate(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  48210. wc_ShaFinal(&sha, digest);
  48211. wc_ShaFree(&sha);
  48212. #else
  48213. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  48214. if (ret != 0)
  48215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48216. wc_Sha256Update(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  48217. wc_Sha256Final(&sha, digest);
  48218. wc_Sha256Free(&sha);
  48219. #endif
  48220. for (j = 0, k = 2; j < (int)sizeof(digest); j++, k += 2) {
  48221. (void)XSNPRINTF((char*)&transId[k], 3, "%02x", digest[j]);
  48222. }
  48223. }
  48224. /* enable detached signature generation, if set */
  48225. if (testVectors[i].detachedSignature == 1) {
  48226. ret = wc_PKCS7_SetDetached(pkcs7, 1);
  48227. if (ret != 0)
  48228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48229. }
  48230. encodedSz = wc_PKCS7_EncodeSignedData(pkcs7, out, outSz);
  48231. if (encodedSz < 0)
  48232. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48233. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48234. /* write PKCS#7 to output file for more testing */
  48235. file = XFOPEN(testVectors[i].outFileName, "wb");
  48236. if (!file) {
  48237. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48238. }
  48239. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48240. XFCLOSE(file);
  48241. if (ret != (int)encodedSz)
  48242. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48243. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48244. wc_PKCS7_Free(pkcs7);
  48245. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48246. if (pkcs7 == NULL)
  48247. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48248. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48249. if (testVectors[i].detachedSignature == 1) {
  48250. /* set content for verifying detached signatures */
  48251. pkcs7->content = (byte*)testVectors[i].content;
  48252. pkcs7->contentSz = testVectors[i].contentSz;
  48253. }
  48254. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48255. if (ret < 0)
  48256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48257. /* verify contentType extracted successfully for custom content types */
  48258. if (testVectors[i].contentTypeSz > 0) {
  48259. if (pkcs7->contentTypeSz != testVectors[i].contentTypeSz) {
  48260. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48261. } else if (XMEMCMP(pkcs7->contentType, testVectors[i].contentType,
  48262. pkcs7->contentTypeSz) != 0) {
  48263. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48264. }
  48265. }
  48266. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48267. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48268. {
  48269. /* check getting signed attributes */
  48270. #ifndef NO_SHA
  48271. byte buf[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  48272. #else
  48273. byte buf[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  48274. #endif
  48275. const byte* oidPt = transIdOid + 2; /* skip object id tag and size */
  48276. int oidSz = (int)sizeof(transIdOid) - 2;
  48277. int bufSz = 0;
  48278. if (testVectors[i].signedAttribs != NULL) {
  48279. ret = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  48280. NULL, (word32*)&bufSz);
  48281. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  48282. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48283. ret = 0;
  48284. }
  48285. if (bufSz > (int)sizeof(buf))
  48286. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48287. bufSz = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  48288. buf, (word32*)&bufSz);
  48289. if ((testVectors[i].signedAttribs != NULL && bufSz < 0) ||
  48290. (testVectors[i].signedAttribs == NULL && bufSz > 0))
  48291. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48292. }
  48293. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48294. file = XFOPEN("./pkcs7cert.der", "wb");
  48295. if (!file)
  48296. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48297. ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file);
  48298. if (ret < 0)
  48299. ret = WC_TEST_RET_ENC_ERRNO;
  48300. else
  48301. ret = 0;
  48302. XFCLOSE(file);
  48303. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48304. }
  48305. out:
  48306. if (pkcs7 != NULL)
  48307. wc_PKCS7_Free(pkcs7);
  48308. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48309. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48310. wc_FreeRng(&rng);
  48311. if (ret > 0)
  48312. return 0;
  48313. (void)rsaClientCertBuf;
  48314. (void)rsaClientCertBufSz;
  48315. (void)rsaClientPrivKeyBuf;
  48316. (void)rsaClientPrivKeyBufSz;
  48317. (void)rsaServerCertBuf;
  48318. (void)rsaServerCertBufSz;
  48319. (void)rsaServerPrivKeyBuf;
  48320. (void)rsaServerPrivKeyBufSz;
  48321. (void)rsaCaCertBuf;
  48322. (void)rsaCaCertBufSz;
  48323. (void)rsaCaPrivKeyBuf;
  48324. (void)rsaCaPrivKeyBufSz;
  48325. (void)eccClientCertBuf;
  48326. (void)eccClientCertBufSz;
  48327. (void)eccClientPrivKeyBuf;
  48328. (void)eccClientPrivKeyBufSz;
  48329. return ret;
  48330. }
  48331. static wc_test_ret_t pkcs7signed_run_SingleShotVectors(
  48332. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  48333. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  48334. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  48335. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  48336. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  48337. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  48338. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  48339. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  48340. {
  48341. wc_test_ret_t ret;
  48342. int testSz = 0, i;
  48343. int encodedSz;
  48344. byte* out = NULL;
  48345. word32 outSz;
  48346. WC_RNG rng;
  48347. wc_PKCS7* pkcs7 = NULL;
  48348. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48349. XFILE file;
  48350. #endif
  48351. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48352. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48353. byte* encryptedTmp = NULL;
  48354. int encryptedTmpSz;
  48355. #endif
  48356. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  48357. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  48358. 0x72,0x6c,0x64
  48359. };
  48360. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48361. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48362. static const byte aes256Key[] = {
  48363. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48364. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48365. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48366. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  48367. };
  48368. #endif
  48369. static const byte messageTypeOid[] =
  48370. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  48371. 0x09, 0x02 };
  48372. static const byte messageType[] = { 0x13, 2, '1', '9' };
  48373. PKCS7Attrib attribs[] =
  48374. {
  48375. { messageTypeOid, sizeof(messageTypeOid), messageType,
  48376. sizeof(messageType) },
  48377. };
  48378. #define MAX_TESTVECTORS_LEN 19
  48379. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  48380. pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  48381. if (testSz == MAX_TESTVECTORS_LEN) { \
  48382. ret = WC_TEST_RET_ENC_NC; \
  48383. goto out; \
  48384. } \
  48385. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  48386. sizeof _this_vector); \
  48387. }
  48388. pkcs7SignedVector *testVectors = NULL;
  48389. XMEMSET(&rng, 0, sizeof(rng));
  48390. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  48391. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48392. if (testVectors == NULL) {
  48393. ret = WC_TEST_RET_ENC_ERRNO;
  48394. goto out;
  48395. }
  48396. {
  48397. #ifndef NO_RSA
  48398. #ifndef NO_SHA256
  48399. /* Signed FirmwarePkgData, RSA, SHA256, no attribs */
  48400. ADD_PKCS7SIGNEDVECTOR(
  48401. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48402. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48403. NULL, 0,
  48404. "pkcs7signedFirmwarePkgData_RSA_SHA256_noattr.der", 0, NULL, 0, 0,
  48405. 0, 0, NULL, 0, NULL, 0, 0);
  48406. /* Signed FirmwarePkgData, RSA, SHA256, attrs */
  48407. ADD_PKCS7SIGNEDVECTOR(
  48408. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48409. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48410. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48411. "pkcs7signedFirmwarePkgData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0,
  48412. NULL, 0, NULL, 0, 0);
  48413. /* Signed FirmwarePkgData, RSA, SHA256, SubjectKeyIdentifier, attrs */
  48414. ADD_PKCS7SIGNEDVECTOR(
  48415. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48416. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48417. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48418. "pkcs7signedFirmwarePkgData_RSA_SHA256_SKID.der", 0, NULL,
  48419. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48420. /* Signed FirmwraePkgData, RSA, SHA256, server cert and ca cert, attr */
  48421. ADD_PKCS7SIGNEDVECTOR(
  48422. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48423. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48424. rsaCaCertBuf, rsaCaCertBufSz,
  48425. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48426. "pkcs7signedFirmwarePkgData_RSA_SHA256_with_ca_cert.der", 0, NULL,
  48427. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48428. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48429. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48430. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, no attribs */
  48431. ADD_PKCS7SIGNEDVECTOR(
  48432. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48433. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48434. NULL, 0,
  48435. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48436. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48437. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, attribs */
  48438. ADD_PKCS7SIGNEDVECTOR(
  48439. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48440. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48441. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48442. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256.der", 0,
  48443. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48444. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48445. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48446. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48447. /* Signed Compressed FirmwarePkgData, RSA, SHA256, no attribs */
  48448. ADD_PKCS7SIGNEDVECTOR(
  48449. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48450. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48451. NULL, 0,
  48452. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48453. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48454. /* Signed Compressed FirmwarePkgData, RSA, SHA256, attribs */
  48455. ADD_PKCS7SIGNEDVECTOR(
  48456. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48457. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48458. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48459. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256.der", 0,
  48460. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48461. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48462. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48463. no attribs */
  48464. ADD_PKCS7SIGNEDVECTOR(
  48465. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48466. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48467. NULL, 0,
  48468. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der",
  48469. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48470. 0, 0);
  48471. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48472. attribs */
  48473. ADD_PKCS7SIGNEDVECTOR(
  48474. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48475. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48476. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48477. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256.der",
  48478. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48479. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48480. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48481. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48482. #endif /* NO_SHA256 */
  48483. #endif /* NO_RSA */
  48484. #ifdef HAVE_ECC
  48485. #ifndef NO_SHA256
  48486. /* Signed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48487. ADD_PKCS7SIGNEDVECTOR(
  48488. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48489. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48490. NULL, 0,
  48491. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48492. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48493. /* Signed FirmwarePkgData, ECDSA, SHA256, attribs */
  48494. ADD_PKCS7SIGNEDVECTOR(
  48495. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48496. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48497. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48498. "pkcs7signedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48499. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48500. /* Signed FirmwarePkgData, ECDSA, SHA256, SubjectKeyIdentifier, attr */
  48501. ADD_PKCS7SIGNEDVECTOR(
  48502. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48503. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48504. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48505. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_SKID.der", 0, NULL,
  48506. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48507. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48508. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48509. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, no attribs */
  48510. ADD_PKCS7SIGNEDVECTOR(
  48511. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48512. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48513. NULL, 0,
  48514. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48515. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48516. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, attribs */
  48517. ADD_PKCS7SIGNEDVECTOR(
  48518. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48519. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48520. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48521. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48522. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48523. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48524. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48525. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48526. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48527. ADD_PKCS7SIGNEDVECTOR(
  48528. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48529. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48530. NULL, 0,
  48531. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48532. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48533. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, attrib */
  48534. ADD_PKCS7SIGNEDVECTOR(
  48535. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48536. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48537. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48538. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48539. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48540. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48541. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48542. no attribs */
  48543. ADD_PKCS7SIGNEDVECTOR(
  48544. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48545. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48546. NULL, 0,
  48547. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der",
  48548. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48549. 0, 0);
  48550. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48551. attribs */
  48552. ADD_PKCS7SIGNEDVECTOR(
  48553. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48554. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48555. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48556. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256.der",
  48557. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48558. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48559. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48560. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48561. #endif /* NO_SHA256 */
  48562. #endif /* HAVE_ECC */
  48563. };
  48564. #undef MAX_TESTVECTORS_LEN
  48565. #undef ADD_PKCS7SIGNEDVECTOR
  48566. outSz = FOURK_BUF;
  48567. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48568. if (out == NULL)
  48569. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48570. XMEMSET(out, 0, outSz);
  48571. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48572. if (ret < 0)
  48573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48574. #ifndef HAVE_FIPS
  48575. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48576. #else
  48577. ret = wc_InitRng(&rng);
  48578. #endif
  48579. if (ret != 0)
  48580. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48581. for (i = 0; i < testSz; i++) {
  48582. if (pkcs7)
  48583. wc_PKCS7_Free(pkcs7);
  48584. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48585. if (pkcs7 == NULL)
  48586. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48587. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48588. (word32)testVectors[i].certSz);
  48589. if (ret != 0)
  48590. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48591. /* load CA certificate, if present */
  48592. if (testVectors[i].caCert != NULL) {
  48593. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48594. (word32)testVectors[i].caCertSz);
  48595. if (ret != 0)
  48596. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48597. }
  48598. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48599. default is IssuerAndSerialNumber */
  48600. if (testVectors[i].sidType == CMS_SKID) {
  48601. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48602. if (ret != 0)
  48603. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48604. }
  48605. if (testVectors[i].encCompFlag == 0) {
  48606. /* encode Signed FirmwarePkgData */
  48607. encodedSz = wc_PKCS7_EncodeSignedFPD(pkcs7,
  48608. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48609. testVectors[i].signOID, testVectors[i].hashOID,
  48610. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48611. testVectors[i].signedAttribs,
  48612. testVectors[i].signedAttribsSz, out, outSz);
  48613. if (encodedSz < 0)
  48614. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48615. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48616. } else if (testVectors[i].encCompFlag == 1) {
  48617. /* encode Signed Encrypted FirmwarePkgData */
  48618. encodedSz = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7,
  48619. (byte *)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48620. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48621. testVectors[i].encryptOID, testVectors[i].signOID,
  48622. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48623. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48624. testVectors[i].unprotectedAttribsSz,
  48625. testVectors[i].signedAttribs,
  48626. testVectors[i].signedAttribsSz, out, outSz);
  48627. if (encodedSz <= 0)
  48628. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48629. #endif
  48630. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48631. } else if (testVectors[i].encCompFlag == 2) {
  48632. /* encode Signed Compressed FirmwarePkgData */
  48633. encodedSz = wc_PKCS7_EncodeSignedCompressedFPD(pkcs7,
  48634. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48635. testVectors[i].signOID, testVectors[i].hashOID,
  48636. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48637. testVectors[i].signedAttribs,
  48638. testVectors[i].signedAttribsSz, out, outSz);
  48639. if (encodedSz <= 0)
  48640. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48641. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48642. } else if (testVectors[i].encCompFlag == 3) {
  48643. /* encode Signed Encrypted Compressed FirmwarePkgData */
  48644. encodedSz = wc_PKCS7_EncodeSignedEncryptedCompressedFPD(pkcs7,
  48645. (byte*)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48646. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48647. testVectors[i].encryptOID, testVectors[i].signOID,
  48648. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48649. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48650. testVectors[i].unprotectedAttribsSz,
  48651. testVectors[i].signedAttribs,
  48652. testVectors[i].signedAttribsSz, out, outSz);
  48653. if (encodedSz <= 0)
  48654. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48655. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48656. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48657. } else {
  48658. /* unsupported SignedData single-shot combination */
  48659. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48660. }
  48661. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48662. /* write PKCS#7 to output file for more testing */
  48663. file = XFOPEN(testVectors[i].outFileName, "wb");
  48664. if (!file)
  48665. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48666. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48667. XFCLOSE(file);
  48668. file = NULL;
  48669. if (ret != (int)encodedSz)
  48670. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48671. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48672. wc_PKCS7_Free(pkcs7);
  48673. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48674. if (pkcs7 == NULL)
  48675. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48676. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48677. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48678. if (ret < 0)
  48679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48680. #ifndef NO_PKCS7_STREAM
  48681. {
  48682. word32 z;
  48683. for (z = 0; z < outSz && ret != 0; z++) {
  48684. ret = wc_PKCS7_VerifySignedData(pkcs7, out + z, 1);
  48685. if (ret < 0 && ret != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  48686. printf("unexpected error %d\n", ret);
  48687. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48688. }
  48689. }
  48690. }
  48691. #endif
  48692. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48693. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48694. if (testVectors[i].encCompFlag == 0) {
  48695. /* verify decoded content matches expected */
  48696. if ((pkcs7->contentSz != testVectors[i].contentSz) ||
  48697. XMEMCMP(pkcs7->content, testVectors[i].content,
  48698. pkcs7->contentSz)) {
  48699. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48700. }
  48701. }
  48702. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48703. else if (testVectors[i].encCompFlag == 1) {
  48704. /* decrypt inner encryptedData */
  48705. pkcs7->encryptionKey = (byte *)testVectors[i].encryptKey;
  48706. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48707. ret = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48708. pkcs7->contentSz, out, outSz);
  48709. if (ret < 0)
  48710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48711. /* compare decrypted to expected */
  48712. if (((word32)ret != testVectors[i].contentSz) ||
  48713. XMEMCMP(out, testVectors[i].content, ret))
  48714. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48715. }
  48716. #endif
  48717. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48718. else if (testVectors[i].encCompFlag == 2) {
  48719. /* decompress inner compressedData */
  48720. ret = wc_PKCS7_DecodeCompressedData(pkcs7, pkcs7->content,
  48721. pkcs7->contentSz, out, outSz);
  48722. if (ret < 0)
  48723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48724. /* compare decompressed to expected */
  48725. if (((word32)ret != testVectors[i].contentSz) ||
  48726. XMEMCMP(out, testVectors[i].content, ret))
  48727. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48728. }
  48729. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48730. else if (testVectors[i].encCompFlag == 3) {
  48731. encryptedTmpSz = FOURK_BUF;
  48732. encryptedTmp = (byte*)XMALLOC(encryptedTmpSz, HEAP_HINT,
  48733. DYNAMIC_TYPE_TMP_BUFFER);
  48734. if (encryptedTmp == NULL)
  48735. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48736. XMEMSET(encryptedTmp, 0, encryptedTmpSz);
  48737. /* decrypt inner encryptedData */
  48738. pkcs7->encryptionKey = (byte*)testVectors[i].encryptKey;
  48739. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48740. encryptedTmpSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48741. pkcs7->contentSz, encryptedTmp,
  48742. encryptedTmpSz);
  48743. if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA)
  48744. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48745. /* decompress inner compressedData */
  48746. ret = wc_PKCS7_DecodeCompressedData(pkcs7, encryptedTmp,
  48747. encryptedTmpSz, out, outSz);
  48748. if (ret < 0)
  48749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48750. /* compare decompressed to expected */
  48751. if (((word32)ret != testVectors[i].contentSz) ||
  48752. XMEMCMP(out, testVectors[i].content, ret))
  48753. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48754. }
  48755. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48756. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48757. }
  48758. out:
  48759. if (pkcs7 != NULL)
  48760. wc_PKCS7_Free(pkcs7);
  48761. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48762. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48763. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48764. XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48765. #endif
  48766. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48767. wc_FreeRng(&rng);
  48768. if (ret > 0)
  48769. return 0;
  48770. (void)eccClientCertBuf;
  48771. (void)eccClientCertBufSz;
  48772. (void)eccClientPrivKeyBuf;
  48773. (void)eccClientPrivKeyBufSz;
  48774. (void)rsaClientCertBuf;
  48775. (void)rsaClientCertBufSz;
  48776. (void)rsaClientPrivKeyBuf;
  48777. (void)rsaClientPrivKeyBufSz;
  48778. (void)rsaServerCertBuf;
  48779. (void)rsaServerCertBufSz;
  48780. (void)rsaServerPrivKeyBuf;
  48781. (void)rsaServerPrivKeyBufSz;
  48782. (void)rsaCaCertBuf;
  48783. (void)rsaCaCertBufSz;
  48784. (void)rsaCaPrivKeyBuf;
  48785. (void)rsaCaPrivKeyBufSz;
  48786. return ret;
  48787. }
  48788. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void)
  48789. {
  48790. wc_test_ret_t ret = 0;
  48791. byte* rsaClientCertBuf = NULL;
  48792. byte* rsaServerCertBuf = NULL;
  48793. byte* rsaCaCertBuf = NULL;
  48794. byte* eccClientCertBuf = NULL;
  48795. byte* rsaClientPrivKeyBuf = NULL;
  48796. byte* rsaServerPrivKeyBuf = NULL;
  48797. byte* rsaCaPrivKeyBuf = NULL;
  48798. byte* eccClientPrivKeyBuf = NULL;
  48799. word32 rsaClientCertBufSz = 0;
  48800. word32 rsaServerCertBufSz = 0;
  48801. word32 rsaCaCertBufSz = 0;
  48802. word32 eccClientCertBufSz = 0;
  48803. word32 rsaClientPrivKeyBufSz = 0;
  48804. word32 rsaServerPrivKeyBufSz = 0;
  48805. word32 rsaCaPrivKeyBufSz = 0;
  48806. word32 eccClientPrivKeyBufSz = 0;
  48807. WOLFSSL_ENTER("pkcs7signed_test");
  48808. #ifndef NO_RSA
  48809. /* read client RSA cert and key in DER format */
  48810. rsaClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48811. DYNAMIC_TYPE_TMP_BUFFER);
  48812. if (rsaClientCertBuf == NULL)
  48813. ret = WC_TEST_RET_ENC_NC;
  48814. rsaClientPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48815. DYNAMIC_TYPE_TMP_BUFFER);
  48816. if (ret == 0 && rsaClientPrivKeyBuf == NULL) {
  48817. ret = WC_TEST_RET_ENC_ERRNO;
  48818. }
  48819. rsaClientCertBufSz = FOURK_BUF;
  48820. rsaClientPrivKeyBufSz = FOURK_BUF;
  48821. /* read server RSA cert and key in DER format */
  48822. rsaServerCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48823. DYNAMIC_TYPE_TMP_BUFFER);
  48824. if (ret == 0 && rsaServerCertBuf == NULL)
  48825. ret = WC_TEST_RET_ENC_NC;
  48826. rsaServerPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48827. DYNAMIC_TYPE_TMP_BUFFER);
  48828. if (ret == 0 && rsaServerPrivKeyBuf == NULL) {
  48829. ret = WC_TEST_RET_ENC_ERRNO;
  48830. }
  48831. rsaServerCertBufSz = FOURK_BUF;
  48832. rsaServerPrivKeyBufSz = FOURK_BUF;
  48833. /* read CA RSA cert and key in DER format, for use with server cert */
  48834. rsaCaCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48835. DYNAMIC_TYPE_TMP_BUFFER);
  48836. if (ret == 0 && rsaCaCertBuf == NULL)
  48837. ret = WC_TEST_RET_ENC_NC;
  48838. rsaCaPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48839. DYNAMIC_TYPE_TMP_BUFFER);
  48840. if (ret == 0 && rsaCaPrivKeyBuf == NULL) {
  48841. ret = WC_TEST_RET_ENC_ERRNO;
  48842. }
  48843. rsaCaCertBufSz = FOURK_BUF;
  48844. rsaCaPrivKeyBufSz = FOURK_BUF;
  48845. #endif /* NO_RSA */
  48846. #ifdef HAVE_ECC
  48847. /* read client ECC cert and key in DER format */
  48848. eccClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48849. DYNAMIC_TYPE_TMP_BUFFER);
  48850. if (ret == 0 && eccClientCertBuf == NULL) {
  48851. ret = WC_TEST_RET_ENC_ERRNO;
  48852. }
  48853. eccClientPrivKeyBuf =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48854. DYNAMIC_TYPE_TMP_BUFFER);
  48855. if (ret == 0 && eccClientPrivKeyBuf == NULL) {
  48856. ret = WC_TEST_RET_ENC_ERRNO;
  48857. }
  48858. eccClientCertBufSz = FOURK_BUF;
  48859. eccClientPrivKeyBufSz = FOURK_BUF;
  48860. #endif /* HAVE_ECC */
  48861. if (ret >= 0)
  48862. ret = pkcs7_load_certs_keys(rsaClientCertBuf, &rsaClientCertBufSz,
  48863. rsaClientPrivKeyBuf, &rsaClientPrivKeyBufSz,
  48864. rsaServerCertBuf, &rsaServerCertBufSz,
  48865. rsaServerPrivKeyBuf, &rsaServerPrivKeyBufSz,
  48866. rsaCaCertBuf, &rsaCaCertBufSz,
  48867. rsaCaPrivKeyBuf, &rsaCaPrivKeyBufSz,
  48868. eccClientCertBuf, &eccClientCertBufSz,
  48869. eccClientPrivKeyBuf, &eccClientPrivKeyBufSz);
  48870. if (ret < 0) {
  48871. ret = WC_TEST_RET_ENC_EC(ret);
  48872. }
  48873. if (ret >= 0)
  48874. ret = pkcs7signed_run_vectors(rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48875. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48876. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48877. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48878. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48879. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48880. eccClientCertBuf, (word32)eccClientCertBufSz,
  48881. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48882. if (ret >= 0)
  48883. ret = pkcs7signed_run_SingleShotVectors(
  48884. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48885. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48886. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48887. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48888. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48889. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48890. eccClientCertBuf, (word32)eccClientCertBufSz,
  48891. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48892. #if !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  48893. if (ret >= 0)
  48894. ret = pkcs7callback_test(
  48895. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48896. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz);
  48897. #endif
  48898. XFREE(rsaClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48899. XFREE(rsaClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48900. XFREE(rsaServerCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48901. XFREE(rsaServerPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48902. XFREE(rsaCaCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48903. XFREE(rsaCaPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48904. XFREE(eccClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48905. XFREE(eccClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48906. return ret;
  48907. }
  48908. #endif /* HAVE_PKCS7 */
  48909. #if defined(WOLFSSL_PUBLIC_MP) && \
  48910. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48911. defined(USE_FAST_MATH))
  48912. /* Maximum number of bytes in a number to test. */
  48913. #define MP_MAX_TEST_BYTE_LEN 32
  48914. static wc_test_ret_t randNum(mp_int* n, int len, WC_RNG* rng, void* heap)
  48915. {
  48916. byte d[MP_MAX_TEST_BYTE_LEN];
  48917. wc_test_ret_t ret;
  48918. (void)heap;
  48919. do {
  48920. ret = wc_RNG_GenerateBlock(rng, d, (word32)len);
  48921. if (ret != 0)
  48922. return ret;
  48923. ret = mp_read_unsigned_bin(n, d, (word32)len);
  48924. if (ret != 0)
  48925. return ret;
  48926. } while (mp_iszero(n));
  48927. return 0;
  48928. }
  48929. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  48930. static wc_test_ret_t mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng)
  48931. {
  48932. int i, j;
  48933. mp_digit rem;
  48934. mp_digit rem2;
  48935. wc_test_ret_t ret;
  48936. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48937. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  48938. for (i = 0; i < 10; i++) {
  48939. for (j = 1; j < 10; j++) {
  48940. ret = randNum(a, j, rng, NULL);
  48941. if (ret != 0)
  48942. return WC_TEST_RET_ENC_EC(ret);
  48943. ret = mp_div_3(a, r, &rem);
  48944. if (ret != 0)
  48945. return WC_TEST_RET_ENC_EC(ret);
  48946. ret = mp_mul_d(r, 3, r);
  48947. if (ret != 0)
  48948. return WC_TEST_RET_ENC_EC(ret);
  48949. ret = mp_add_d(r, rem, r);
  48950. if (ret != 0)
  48951. return WC_TEST_RET_ENC_EC(ret);
  48952. ret = mp_cmp(r, a);
  48953. if (ret != MP_EQ)
  48954. return WC_TEST_RET_ENC_NC;
  48955. }
  48956. }
  48957. ret = mp_div_3(a, r, &rem);
  48958. if (ret != 0)
  48959. return WC_TEST_RET_ENC_NC;
  48960. ret = mp_div_3(a, a, NULL);
  48961. if (ret != 0)
  48962. return WC_TEST_RET_ENC_NC;
  48963. ret = mp_cmp(r, a);
  48964. if (ret != MP_EQ)
  48965. return WC_TEST_RET_ENC_NC;
  48966. #endif
  48967. #if defined(WOLFSSL_SP_MATH_ALL)
  48968. ret = mp_div_d(a, 10, r, &rem);
  48969. if (ret != 0)
  48970. return WC_TEST_RET_ENC_EC(ret);
  48971. ret = mp_div_d(a, 10, a, NULL);
  48972. if (ret != 0)
  48973. return WC_TEST_RET_ENC_EC(ret);
  48974. ret = mp_cmp(r, a);
  48975. if (ret != MP_EQ)
  48976. return WC_TEST_RET_ENC_NC;
  48977. ret = mp_div_d(a, 12, r, &rem);
  48978. if (ret != 0)
  48979. return WC_TEST_RET_ENC_EC(ret);
  48980. ret = mp_div_d(a, 12, a, NULL);
  48981. if (ret != 0)
  48982. return WC_TEST_RET_ENC_EC(ret);
  48983. ret = mp_cmp(r, a);
  48984. if (ret != MP_EQ)
  48985. return WC_TEST_RET_ENC_NC;
  48986. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem);
  48987. if (ret != 0)
  48988. return WC_TEST_RET_ENC_EC(ret);
  48989. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2);
  48990. if (ret != 0)
  48991. return WC_TEST_RET_ENC_EC(ret);
  48992. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL);
  48993. if (ret != 0)
  48994. return WC_TEST_RET_ENC_EC(ret);
  48995. ret = mp_cmp(r, a);
  48996. if (ret != MP_EQ)
  48997. return WC_TEST_RET_ENC_NC;
  48998. if (rem != rem2)
  48999. return WC_TEST_RET_ENC_NC;
  49000. #endif
  49001. (void)a;
  49002. (void)r;
  49003. (void)rng;
  49004. (void)i;
  49005. (void)j;
  49006. (void)rem;
  49007. (void)rem2;
  49008. (void)ret;
  49009. return 0;
  49010. }
  49011. #endif /* WOLFSSL_SP_MATH || !USE_FAST_MATH */
  49012. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  49013. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49014. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  49015. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  49016. static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
  49017. {
  49018. wc_test_ret_t ret;
  49019. int i, j;
  49020. int size;
  49021. char str[30];
  49022. WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = "A";
  49023. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "a";
  49024. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  49025. WOLFSSL_SMALL_STACK_STATIC const char* zeros = "000";
  49026. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  49027. for (i = 0; i < 10; i++) {
  49028. for (j = 2; j < 12; j++) {
  49029. ret = randNum(a, j, rng, NULL);
  49030. if (ret != 0)
  49031. return WC_TEST_RET_ENC_EC(ret);
  49032. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  49033. if (ret != MP_OKAY)
  49034. return WC_TEST_RET_ENC_EC(ret);
  49035. ret = mp_toradix(a, str, MP_RADIX_DEC);
  49036. if (ret != MP_OKAY)
  49037. return WC_TEST_RET_ENC_EC(ret);
  49038. if ((int)XSTRLEN(str) != size - 1)
  49039. return WC_TEST_RET_ENC_NC;
  49040. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  49041. if (ret != MP_OKAY)
  49042. return WC_TEST_RET_ENC_EC(ret);
  49043. ret = mp_cmp(a, r);
  49044. if (ret != MP_EQ)
  49045. return WC_TEST_RET_ENC_NC;
  49046. }
  49047. }
  49048. ret = mp_read_radix(r, badStr1, MP_RADIX_DEC);
  49049. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49050. return WC_TEST_RET_ENC_EC(ret);
  49051. ret = mp_read_radix(r, badStr2, 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, empty2, MP_RADIX_DEC);
  49055. if (ret != MP_OKAY)
  49056. return WC_TEST_RET_ENC_EC(ret);
  49057. ret = mp_read_radix(r, zeros, MP_RADIX_DEC);
  49058. if (ret != MP_OKAY)
  49059. return WC_TEST_RET_ENC_EC(ret);
  49060. if (!mp_iszero(r))
  49061. return WC_TEST_RET_ENC_NC;
  49062. mp_set(r, 1);
  49063. ret = mp_read_radix(r, empty, MP_RADIX_DEC);
  49064. if (ret != MP_OKAY)
  49065. return WC_TEST_RET_ENC_EC(ret);
  49066. if (!mp_iszero(r))
  49067. return WC_TEST_RET_ENC_NC;
  49068. mp_zero(a);
  49069. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  49070. if (ret != 0)
  49071. return WC_TEST_RET_ENC_EC(ret);
  49072. if (size != 2)
  49073. return WC_TEST_RET_ENC_NC;
  49074. ret = mp_toradix(a, str, MP_RADIX_DEC);
  49075. if (ret != 0)
  49076. return WC_TEST_RET_ENC_EC(ret);
  49077. if ((int)XSTRLEN(str) != size - 1)
  49078. return WC_TEST_RET_ENC_NC;
  49079. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  49080. if (ret != 0)
  49081. return WC_TEST_RET_ENC_EC(ret);
  49082. if (!mp_iszero(r))
  49083. return WC_TEST_RET_ENC_NC;
  49084. return 0;
  49085. }
  49086. #endif
  49087. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  49088. defined(HAVE_ECC))
  49089. static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
  49090. {
  49091. wc_test_ret_t ret;
  49092. int i, j;
  49093. int size;
  49094. char str[30];
  49095. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  49096. static char longStr[2 * sizeof(a->dp) + 2];
  49097. #endif
  49098. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  49099. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "}";
  49100. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  49101. for (i = 0; i < 10; i++) {
  49102. for (j = 2; j < 12; j++) {
  49103. ret = randNum(a, j, rng, NULL);
  49104. if (ret != 0)
  49105. return WC_TEST_RET_ENC_EC(ret);
  49106. mp_radix_size(a, MP_RADIX_HEX, &size);
  49107. mp_toradix(a, str, MP_RADIX_HEX);
  49108. if ((int)XSTRLEN(str) != size - 1)
  49109. return WC_TEST_RET_ENC_NC;
  49110. mp_read_radix(r, str, MP_RADIX_HEX);
  49111. ret = mp_cmp(a, r);
  49112. if (ret != MP_EQ)
  49113. return WC_TEST_RET_ENC_NC;
  49114. }
  49115. }
  49116. ret = mp_read_radix(r, empty2, MP_RADIX_HEX);
  49117. if (ret != MP_OKAY)
  49118. return WC_TEST_RET_ENC_EC(ret);
  49119. ret = mp_read_radix(r, badStr2, MP_RADIX_HEX);
  49120. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49121. return WC_TEST_RET_ENC_EC(ret);
  49122. mp_set(r, 1);
  49123. ret = mp_read_radix(r, empty, MP_RADIX_HEX);
  49124. if (ret != MP_OKAY)
  49125. return WC_TEST_RET_ENC_EC(ret);
  49126. if (!mp_iszero(r))
  49127. return WC_TEST_RET_ENC_NC;
  49128. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  49129. /* Fixed MP data size - string can be too long. */
  49130. longStr[0] = '8';
  49131. XMEMSET(longStr+1, '0', sizeof(longStr) - 2);
  49132. longStr[sizeof(longStr)-1] = '\0';
  49133. ret = mp_read_radix(r, longStr, MP_RADIX_HEX);
  49134. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49135. return WC_TEST_RET_ENC_EC(ret);
  49136. #endif
  49137. mp_zero(a);
  49138. ret = mp_radix_size(a, MP_RADIX_HEX, &size);
  49139. if (ret != 0)
  49140. return WC_TEST_RET_ENC_EC(ret);
  49141. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  49142. if (size != 3)
  49143. #else
  49144. if (size != 2)
  49145. #endif
  49146. return WC_TEST_RET_ENC_NC;
  49147. ret = mp_toradix(a, str, MP_RADIX_HEX);
  49148. if (ret != 0)
  49149. return WC_TEST_RET_ENC_EC(ret);
  49150. if ((int)XSTRLEN(str) != size - 1)
  49151. return WC_TEST_RET_ENC_NC;
  49152. ret = mp_read_radix(r, str, MP_RADIX_HEX);
  49153. if (ret != 0)
  49154. return WC_TEST_RET_ENC_EC(ret);
  49155. if (!mp_iszero(r))
  49156. return WC_TEST_RET_ENC_NC;
  49157. #ifdef WOLFSSL_SP_MATH
  49158. ret = mp_toradix(a, str, 8);
  49159. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49160. return WC_TEST_RET_ENC_EC(ret);
  49161. ret = mp_radix_size(a, 8, &size);
  49162. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49163. return WC_TEST_RET_ENC_EC(ret);
  49164. #endif
  49165. return 0;
  49166. }
  49167. #endif
  49168. static wc_test_ret_t mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng)
  49169. {
  49170. int i;
  49171. wc_test_ret_t ret;
  49172. ret = randNum(a, 4, rng, NULL);
  49173. if (ret != 0)
  49174. return WC_TEST_RET_ENC_EC(ret);
  49175. for (i = 0; i < 4; i++) {
  49176. mp_copy(r1, a);
  49177. ret = mp_lshd(r1, i);
  49178. if (ret != MP_OKAY)
  49179. return WC_TEST_RET_ENC_EC(ret);
  49180. #ifndef WOLFSSL_SP_MATH
  49181. mp_rshd(r1, i);
  49182. #else
  49183. mp_rshb(r1, i * SP_WORD_SIZE);
  49184. #endif
  49185. ret = mp_cmp(a, r1);
  49186. if (ret != MP_EQ)
  49187. return WC_TEST_RET_ENC_NC;
  49188. }
  49189. #ifndef WOLFSSL_SP_MATH
  49190. for (i = 0; i < DIGIT_BIT+1; i++) {
  49191. ret = mp_mul_2d(a, i, r1);
  49192. if (ret != MP_OKAY)
  49193. return WC_TEST_RET_ENC_EC(ret);
  49194. mp_rshb(r1, i);
  49195. ret = mp_cmp(a, r1);
  49196. if (ret != MP_EQ)
  49197. return WC_TEST_RET_ENC_NC;
  49198. }
  49199. #endif
  49200. return 0;
  49201. }
  49202. static wc_test_ret_t mp_test_add_sub_d(mp_int* a, mp_int* r1)
  49203. {
  49204. int i, j;
  49205. wc_test_ret_t ret;
  49206. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49207. mp_zero(a);
  49208. mp_set_bit(a, i);
  49209. if ((int)a->used != (i + DIGIT_BIT) / DIGIT_BIT)
  49210. return WC_TEST_RET_ENC_NC;
  49211. for (j = 0; j < i && j < DIGIT_BIT; j++) {
  49212. mp_zero(r1);
  49213. mp_set_bit(r1, i);
  49214. ret = mp_sub_d(r1, (mp_digit)1 << j, r1);
  49215. if (ret != MP_OKAY)
  49216. return WC_TEST_RET_ENC_EC(ret);
  49217. ret = mp_add_d(r1, (mp_digit)1 << j, r1);
  49218. if (ret != MP_OKAY)
  49219. return WC_TEST_RET_ENC_EC(ret);
  49220. ret = mp_cmp(a, r1);
  49221. if (ret != MP_EQ)
  49222. return WC_TEST_RET_ENC_NC;
  49223. }
  49224. }
  49225. mp_zero(r1);
  49226. ret = mp_add_d(r1, 1, r1);
  49227. if (ret != MP_OKAY)
  49228. return WC_TEST_RET_ENC_EC(ret);
  49229. if (r1->used != 1)
  49230. return WC_TEST_RET_ENC_NC;
  49231. ret = mp_sub_d(r1, 1, r1);
  49232. if (ret != MP_OKAY)
  49233. return WC_TEST_RET_ENC_EC(ret);
  49234. if (r1->used != 0)
  49235. return WC_TEST_RET_ENC_NC;
  49236. return 0;
  49237. }
  49238. static wc_test_ret_t mp_test_read_to_bin(mp_int* a)
  49239. {
  49240. WOLFSSL_SMALL_STACK_STATIC const byte in[16] = {
  49241. 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7, 0x08,
  49242. 0x93, 0xa4, 0xb4, 0xc5, 0xd6, 0xe7, 0xf8, 0x09
  49243. };
  49244. byte out[24];
  49245. int i, j, k;
  49246. const byte* p;
  49247. wc_test_ret_t ret;
  49248. for (i = 0; i < (int)sizeof(in); i++) {
  49249. p = in + sizeof(in) - i;
  49250. ret = mp_read_unsigned_bin(a, p, (word32)i);
  49251. if (ret != 0)
  49252. return WC_TEST_RET_ENC_EC(ret);
  49253. for (j = i; j < (int)sizeof(out); j++) {
  49254. XMEMSET(out, 0xff, sizeof(out));
  49255. ret = mp_to_unsigned_bin_len(a, out, j);
  49256. if (ret != 0)
  49257. return WC_TEST_RET_ENC_EC(ret);
  49258. for (k = 0; k < j - i; k++) {
  49259. if (out[k] != 0)
  49260. return WC_TEST_RET_ENC_NC;
  49261. }
  49262. for (; k < j; k++) {
  49263. if (out[k] != p[k - (j - i)])
  49264. return WC_TEST_RET_ENC_NC;
  49265. }
  49266. }
  49267. }
  49268. /* Length too small. */
  49269. ret = mp_to_unsigned_bin_len(a, out, 1);
  49270. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49271. return WC_TEST_RET_ENC_EC(ret);
  49272. ret = mp_read_unsigned_bin(a, NULL, 0);
  49273. if (ret != 0)
  49274. return WC_TEST_RET_ENC_EC(ret);
  49275. if (!mp_iszero(a))
  49276. return WC_TEST_RET_ENC_NC;
  49277. return 0;
  49278. }
  49279. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49280. static wc_test_ret_t mp_test_set_int(mp_int* a)
  49281. {
  49282. #if SP_ULONG_BITS == 64
  49283. unsigned long n = 0xfedcba9876543210UL;
  49284. byte exp[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
  49285. byte out[8] = { 0 };
  49286. #elif SP_ULONG_BITS == 32
  49287. unsigned long n = 0xfedcba98UL;
  49288. byte exp[4] = { 0xfe, 0xdc, 0xba, 0x98 };
  49289. byte out[4] = { 0 };
  49290. #elif SP_ULONG_BITS == 16
  49291. unsigned long n = 0xfedc;
  49292. byte exp[2] = { 0xfe, 0xdc };
  49293. byte out[2] = { 0 };
  49294. #elif SP_ULONG_BITS == 8
  49295. unsigned long n = 0xfe;
  49296. byte exp[1] = { 0xfe };
  49297. byte out[1] = { 0 };
  49298. #endif
  49299. wc_test_ret_t ret;
  49300. ret = mp_set_int(a, n);
  49301. if (ret != 0)
  49302. return WC_TEST_RET_ENC_EC(ret);
  49303. ret = mp_unsigned_bin_size(a);
  49304. if (ret != sizeof(exp))
  49305. return WC_TEST_RET_ENC_NC;
  49306. ret = mp_to_unsigned_bin(a, out);
  49307. if (ret != 0)
  49308. return WC_TEST_RET_ENC_EC(ret);
  49309. if (XMEMCMP(exp, out, sizeof(exp)) != 0)
  49310. return WC_TEST_RET_ENC_NC;
  49311. return 0;
  49312. }
  49313. #endif
  49314. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49315. static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
  49316. {
  49317. byte buffer[16];
  49318. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49319. char hexStr[] = "abcdef0123456789";
  49320. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49321. char negStr[] = "-1234";
  49322. #endif
  49323. #endif
  49324. #if !defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
  49325. defined(HAVE_COMP_KEY)
  49326. char decStr[] = "0987654321";
  49327. #endif
  49328. wc_test_ret_t ret;
  49329. #ifdef WOLFSSL_SP_MATH_ALL
  49330. mp_digit rho;
  49331. int size;
  49332. #endif
  49333. #ifdef WOLFSSL_SP_PRIME_GEN
  49334. int result;
  49335. #endif
  49336. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49337. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49338. mp_digit rd;
  49339. #endif
  49340. (void)rng;
  49341. (void)r;
  49342. ret = mp_init(NULL);
  49343. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49344. return WC_TEST_RET_ENC_EC(ret);
  49345. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49346. ret = mp_init_multi(NULL, NULL, NULL, NULL, NULL, NULL);
  49347. if (ret != MP_OKAY)
  49348. return WC_TEST_RET_ENC_EC(ret);
  49349. #endif
  49350. mp_free(NULL);
  49351. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
  49352. ret = mp_grow(NULL, 1);
  49353. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49354. return WC_TEST_RET_ENC_EC(ret);
  49355. #ifdef WOLFSSL_SP_MATH
  49356. ret = mp_grow(a, SP_INT_DIGITS + 1);
  49357. if (ret != WC_NO_ERR_TRACE(MP_MEM))
  49358. return WC_TEST_RET_ENC_EC(ret);
  49359. #endif
  49360. #endif
  49361. mp_clear(NULL);
  49362. ret = mp_abs(NULL, NULL);
  49363. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49364. return WC_TEST_RET_ENC_EC(ret);
  49365. ret = mp_abs(a, NULL);
  49366. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49367. return WC_TEST_RET_ENC_EC(ret);
  49368. ret = mp_abs(NULL, b);
  49369. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49370. return WC_TEST_RET_ENC_EC(ret);
  49371. ret = mp_unsigned_bin_size(NULL);
  49372. if (ret != 0)
  49373. return WC_TEST_RET_ENC_EC(ret);
  49374. /* clear buffer to avoid provoking uninitvar errors. */
  49375. XMEMSET(buffer, 0, sizeof(buffer));
  49376. ret = mp_read_unsigned_bin(NULL, NULL, sizeof(buffer));
  49377. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49378. return WC_TEST_RET_ENC_EC(ret);
  49379. ret = mp_read_unsigned_bin(NULL, buffer, sizeof(buffer));
  49380. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49381. return WC_TEST_RET_ENC_EC(ret);
  49382. ret = mp_read_unsigned_bin(a, 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(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
  49386. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49387. return WC_TEST_RET_ENC_EC(ret);
  49388. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49389. ret = mp_read_radix(NULL, NULL, 16);
  49390. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49391. return WC_TEST_RET_ENC_EC(ret);
  49392. ret = mp_read_radix(a, NULL, 16);
  49393. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49394. return WC_TEST_RET_ENC_EC(ret);
  49395. ret = mp_read_radix(NULL, hexStr, 16);
  49396. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49397. return WC_TEST_RET_ENC_EC(ret);
  49398. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49399. ret = mp_read_radix(a, negStr, 16);
  49400. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49401. return WC_TEST_RET_ENC_EC(ret);
  49402. #ifdef WOLFSSL_SP_MATH_ALL
  49403. ret = mp_read_radix(a, negStr, 10);
  49404. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49405. return WC_TEST_RET_ENC_EC(ret);
  49406. #endif /* WOLFSSL_SP_MATH_ALL */
  49407. #endif /* WOLFSSL_SP_INT_NEGATIVE */
  49408. #endif
  49409. #ifndef WOLFSSL_SP_MATH_ALL
  49410. /* Radix 10 only supported with ALL. */
  49411. ret = mp_read_radix(a, decStr, 10);
  49412. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49413. return WC_TEST_RET_ENC_EC(ret);
  49414. #endif
  49415. /* Radix 8 not supported SP_INT. */
  49416. ret = mp_read_radix(a, "0123", 8);
  49417. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49418. return WC_TEST_RET_ENC_EC(ret);
  49419. ret = mp_count_bits(NULL);
  49420. if (ret != 0)
  49421. return WC_TEST_RET_ENC_EC(ret);
  49422. ret = mp_is_bit_set(NULL, 0);
  49423. if (ret != 0)
  49424. return WC_TEST_RET_ENC_EC(ret);
  49425. ret = mp_leading_bit(NULL);
  49426. if (ret != 0)
  49427. return WC_TEST_RET_ENC_EC(ret);
  49428. mp_zero(a);
  49429. ret = mp_leading_bit(a);
  49430. if (ret != 0)
  49431. return WC_TEST_RET_ENC_EC(ret);
  49432. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49433. defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || \
  49434. !defined(NO_RSA)
  49435. ret = mp_set_bit(NULL, 1);
  49436. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49437. return WC_TEST_RET_ENC_EC(ret);
  49438. #endif
  49439. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49440. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49441. ret = mp_to_unsigned_bin(NULL, NULL);
  49442. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49443. return WC_TEST_RET_ENC_EC(ret);
  49444. ret = mp_to_unsigned_bin(a, NULL);
  49445. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49446. return WC_TEST_RET_ENC_EC(ret);
  49447. ret = mp_to_unsigned_bin(NULL, buffer);
  49448. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49449. return WC_TEST_RET_ENC_EC(ret);
  49450. #endif
  49451. ret = mp_to_unsigned_bin_len(NULL, NULL, 1);
  49452. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49453. return WC_TEST_RET_ENC_EC(ret);
  49454. ret = mp_to_unsigned_bin_len(a, NULL, 1);
  49455. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49456. return WC_TEST_RET_ENC_EC(ret);
  49457. ret = mp_to_unsigned_bin_len(NULL, buffer, 1);
  49458. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49459. return WC_TEST_RET_ENC_EC(ret);
  49460. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  49461. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49462. ret = mp_to_unsigned_bin_at_pos(0, NULL, NULL);
  49463. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49464. return WC_TEST_RET_ENC_EC(ret);
  49465. ret = mp_to_unsigned_bin_at_pos(0, a, NULL);
  49466. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49467. return WC_TEST_RET_ENC_EC(ret);
  49468. ret = mp_to_unsigned_bin_at_pos(0, NULL, buffer);
  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, buffer);
  49472. if (ret != MP_OKAY)
  49473. return WC_TEST_RET_ENC_EC(ret);
  49474. #endif
  49475. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49476. ret = mp_copy(NULL, NULL);
  49477. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49478. return WC_TEST_RET_ENC_EC(ret);
  49479. ret = mp_copy(a, NULL);
  49480. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49481. return WC_TEST_RET_ENC_EC(ret);
  49482. ret = mp_copy(NULL, b);
  49483. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49484. return WC_TEST_RET_ENC_EC(ret);
  49485. #endif
  49486. #if defined(WOLFSSL_KEY_GEN) || !defined(NO_DH)
  49487. ret = sp_2expt(NULL, 1);
  49488. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49489. return WC_TEST_RET_ENC_EC(ret);
  49490. #endif
  49491. ret = mp_set(NULL, 0);
  49492. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49493. return WC_TEST_RET_ENC_EC(ret);
  49494. ret = mp_cmp_d(NULL, 0);
  49495. if (ret != MP_LT)
  49496. return WC_TEST_RET_ENC_EC(ret);
  49497. ret = mp_cmp(NULL, NULL);
  49498. if (ret != MP_EQ)
  49499. return WC_TEST_RET_ENC_NC;
  49500. ret = mp_cmp(a, NULL);
  49501. if (ret != MP_GT)
  49502. return WC_TEST_RET_ENC_NC;
  49503. ret = mp_cmp(NULL, b);
  49504. if (ret != MP_LT)
  49505. return WC_TEST_RET_ENC_NC;
  49506. #ifdef WOLFSSL_SP_MATH_ALL
  49507. mp_rshd(NULL, 1);
  49508. #endif
  49509. mp_zero(NULL);
  49510. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49511. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49512. ret = mp_lshd(NULL, 0);
  49513. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49514. return WC_TEST_RET_ENC_EC(ret);
  49515. ret = mp_lshd(a, SP_INT_DIGITS + 1);
  49516. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49517. return WC_TEST_RET_ENC_EC(ret);
  49518. #endif
  49519. #if defined(WOLFSSL_SP_MATH_ALL)
  49520. ret = mp_div(NULL, NULL, a, b);
  49521. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49522. return WC_TEST_RET_ENC_EC(ret);
  49523. ret = mp_div(a, NULL, a, b);
  49524. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49525. return WC_TEST_RET_ENC_EC(ret);
  49526. ret = mp_div(NULL, b, a, b);
  49527. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49528. return WC_TEST_RET_ENC_EC(ret);
  49529. ret = mp_div(a, b, NULL, NULL);
  49530. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49531. return WC_TEST_RET_ENC_EC(ret);
  49532. #endif
  49533. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49534. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49535. ret = mp_mod(NULL, NULL, NULL);
  49536. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49537. return WC_TEST_RET_ENC_EC(ret);
  49538. ret = mp_mod(a, NULL, NULL);
  49539. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49540. return WC_TEST_RET_ENC_EC(ret);
  49541. ret = mp_mod(NULL, b, NULL);
  49542. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49543. return WC_TEST_RET_ENC_EC(ret);
  49544. ret = mp_mod(NULL, NULL, r);
  49545. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49546. return WC_TEST_RET_ENC_EC(ret);
  49547. ret = mp_mod(a, b, NULL);
  49548. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49549. return WC_TEST_RET_ENC_EC(ret);
  49550. ret = mp_mod(a, NULL, r);
  49551. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49552. return WC_TEST_RET_ENC_EC(ret);
  49553. ret = mp_mod(NULL, b, r);
  49554. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49555. return WC_TEST_RET_ENC_EC(ret);
  49556. #endif
  49557. #if !defined(NO_RSA) || defined(WOLFSSL_SP_MATH_ALL)
  49558. ret = mp_set_int(NULL, 0);
  49559. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49560. return WC_TEST_RET_ENC_EC(ret);
  49561. #endif
  49562. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  49563. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  49564. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49565. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49566. return WC_TEST_RET_ENC_EC(ret);
  49567. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49568. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49569. return WC_TEST_RET_ENC_EC(ret);
  49570. ret = mp_exptmod_ex(NULL, a, 1, NULL, NULL);
  49571. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49572. return WC_TEST_RET_ENC_EC(ret);
  49573. ret = mp_exptmod_ex(NULL, NULL, 1, a, NULL);
  49574. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49575. return WC_TEST_RET_ENC_EC(ret);
  49576. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49577. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49578. return WC_TEST_RET_ENC_EC(ret);
  49579. ret = mp_exptmod_ex(a, a, 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(a, a, 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, NULL, 1, a, a);
  49586. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49587. return WC_TEST_RET_ENC_EC(ret);
  49588. ret = mp_exptmod_ex(NULL, a, 1, a, a);
  49589. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49590. return WC_TEST_RET_ENC_EC(ret);
  49591. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49592. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49593. return WC_TEST_RET_ENC_EC(ret);
  49594. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49595. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49596. return WC_TEST_RET_ENC_EC(ret);
  49597. ret = mp_exptmod_nct(NULL, a, NULL, NULL);
  49598. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49599. return WC_TEST_RET_ENC_EC(ret);
  49600. ret = mp_exptmod_nct(NULL, NULL, a, NULL);
  49601. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49602. return WC_TEST_RET_ENC_EC(ret);
  49603. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49604. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49605. return WC_TEST_RET_ENC_EC(ret);
  49606. ret = mp_exptmod_nct(a, a, a, NULL);
  49607. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49608. return WC_TEST_RET_ENC_EC(ret);
  49609. ret = mp_exptmod_nct(a, a, 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, NULL, a, a);
  49613. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49614. return WC_TEST_RET_ENC_EC(ret);
  49615. ret = mp_exptmod_nct(NULL, a, a, a);
  49616. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49617. return WC_TEST_RET_ENC_EC(ret);
  49618. #endif
  49619. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  49620. !defined(WC_NO_RNG)
  49621. ret = mp_rand_prime(NULL, 32, NULL, NULL);
  49622. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49623. return WC_TEST_RET_ENC_EC(ret);
  49624. ret = mp_rand_prime(a, 32, NULL, NULL);
  49625. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49626. return WC_TEST_RET_ENC_EC(ret);
  49627. ret = mp_rand_prime(NULL, 32, rng, NULL);
  49628. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49629. return WC_TEST_RET_ENC_EC(ret);
  49630. ret = mp_rand_prime(a, 0, rng, NULL);
  49631. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49632. return WC_TEST_RET_ENC_EC(ret);
  49633. #endif
  49634. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49635. ret = mp_mul(NULL, NULL, NULL);
  49636. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49637. return WC_TEST_RET_ENC_EC(ret);
  49638. ret = mp_mul(a, NULL, NULL);
  49639. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49640. return WC_TEST_RET_ENC_EC(ret);
  49641. ret = mp_mul(NULL, b, NULL);
  49642. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49643. return WC_TEST_RET_ENC_EC(ret);
  49644. ret = mp_mul(NULL, NULL, r);
  49645. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49646. return WC_TEST_RET_ENC_EC(ret);
  49647. ret = mp_mul(a, b, NULL);
  49648. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49649. return WC_TEST_RET_ENC_EC(ret);
  49650. ret = mp_mul(a, NULL, r);
  49651. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49652. return WC_TEST_RET_ENC_EC(ret);
  49653. ret = mp_mul(NULL, b, r);
  49654. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49655. return WC_TEST_RET_ENC_EC(ret);
  49656. #endif
  49657. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49658. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49659. ret = mp_sqr(NULL, NULL);
  49660. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49661. return WC_TEST_RET_ENC_EC(ret);
  49662. ret = mp_sqr(a, NULL);
  49663. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49664. return WC_TEST_RET_ENC_EC(ret);
  49665. ret = mp_sqr(NULL, r);
  49666. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49667. return WC_TEST_RET_ENC_EC(ret);
  49668. #endif
  49669. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49670. ret = mp_sqrmod(NULL, NULL, NULL);
  49671. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49672. return WC_TEST_RET_ENC_EC(ret);
  49673. ret = mp_sqrmod(a, NULL, NULL);
  49674. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49675. return WC_TEST_RET_ENC_EC(ret);
  49676. ret = mp_sqrmod(NULL, a, NULL);
  49677. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49678. return WC_TEST_RET_ENC_EC(ret);
  49679. ret = mp_sqrmod(NULL, NULL, a);
  49680. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49681. return WC_TEST_RET_ENC_EC(ret);
  49682. ret = mp_sqrmod(a, b, NULL);
  49683. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49684. return WC_TEST_RET_ENC_EC(ret);
  49685. ret = mp_sqrmod(a, NULL, b);
  49686. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49687. return WC_TEST_RET_ENC_EC(ret);
  49688. ret = mp_sqrmod(NULL, a, b);
  49689. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49690. return WC_TEST_RET_ENC_EC(ret);
  49691. ret = mp_mulmod(NULL, NULL, NULL, NULL);
  49692. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49693. return WC_TEST_RET_ENC_EC(ret);
  49694. ret = mp_mulmod(a, NULL, NULL, NULL);
  49695. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49696. return WC_TEST_RET_ENC_EC(ret);
  49697. ret = mp_mulmod(NULL, a, NULL, NULL);
  49698. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49699. return WC_TEST_RET_ENC_EC(ret);
  49700. ret = mp_mulmod(NULL, NULL, a, NULL);
  49701. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49702. return WC_TEST_RET_ENC_EC(ret);
  49703. ret = mp_mulmod(NULL, NULL, NULL, a);
  49704. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49705. return WC_TEST_RET_ENC_EC(ret);
  49706. ret = mp_mulmod(a, b, b, NULL);
  49707. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49708. return WC_TEST_RET_ENC_EC(ret);
  49709. ret = mp_mulmod(a, b, NULL, a);
  49710. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49711. return WC_TEST_RET_ENC_EC(ret);
  49712. ret = mp_mulmod(a, NULL, b, a);
  49713. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49714. return WC_TEST_RET_ENC_EC(ret);
  49715. ret = mp_mulmod(NULL, b, b, a);
  49716. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49717. return WC_TEST_RET_ENC_EC(ret);
  49718. #endif
  49719. #if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \
  49720. !defined(NO_RSA) || !defined(NO_DSA)
  49721. ret = mp_add_d(NULL, 1, NULL);
  49722. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49723. return WC_TEST_RET_ENC_EC(ret);
  49724. ret = mp_add_d(a, 1, NULL);
  49725. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49726. return WC_TEST_RET_ENC_EC(ret);
  49727. ret = mp_add_d(NULL, 1, b);
  49728. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49729. return WC_TEST_RET_ENC_EC(ret);
  49730. #endif
  49731. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49732. !defined(NO_DH) || defined(HAVE_ECC) || !defined(NO_DSA)
  49733. ret = mp_sub_d(NULL, 1, NULL);
  49734. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49735. return WC_TEST_RET_ENC_EC(ret);
  49736. ret = mp_sub_d(a, 1, NULL);
  49737. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49738. return WC_TEST_RET_ENC_EC(ret);
  49739. ret = mp_sub_d(NULL, 1, b);
  49740. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49741. return WC_TEST_RET_ENC_EC(ret);
  49742. #endif
  49743. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49744. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49745. ret = mp_div_d(NULL, 0, NULL, NULL);
  49746. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49747. return WC_TEST_RET_ENC_EC(ret);
  49748. ret = mp_div_d(a, 0, NULL, NULL);
  49749. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49750. return WC_TEST_RET_ENC_EC(ret);
  49751. ret = mp_div_d(NULL, 1, NULL, NULL);
  49752. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49753. return WC_TEST_RET_ENC_EC(ret);
  49754. #endif
  49755. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49756. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49757. ret = mp_mod_d(NULL, 0, NULL);
  49758. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49759. return WC_TEST_RET_ENC_EC(ret);
  49760. ret = mp_mod_d(a, 0, NULL);
  49761. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49762. return WC_TEST_RET_ENC_EC(ret);
  49763. ret = mp_mod_d(NULL, 0, &rd);
  49764. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49765. return WC_TEST_RET_ENC_EC(ret);
  49766. #endif
  49767. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  49768. ret = mp_gcd(NULL, NULL, NULL);
  49769. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49770. return WC_TEST_RET_ENC_EC(ret);
  49771. ret = mp_gcd(a, NULL, NULL);
  49772. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49773. return WC_TEST_RET_ENC_EC(ret);
  49774. ret = mp_gcd(NULL, a, NULL);
  49775. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49776. return WC_TEST_RET_ENC_EC(ret);
  49777. ret = mp_gcd(NULL, NULL, a);
  49778. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49779. return WC_TEST_RET_ENC_EC(ret);
  49780. ret = mp_gcd(a, b, NULL);
  49781. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49782. return WC_TEST_RET_ENC_EC(ret);
  49783. ret = mp_gcd(a, NULL, b);
  49784. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49785. return WC_TEST_RET_ENC_EC(ret);
  49786. ret = mp_gcd(NULL, a, b);
  49787. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49788. return WC_TEST_RET_ENC_EC(ret);
  49789. #endif
  49790. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49791. ret = mp_div_2_mod_ct(NULL, NULL, NULL);
  49792. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49793. return WC_TEST_RET_ENC_EC(ret);
  49794. ret = mp_div_2_mod_ct(a, NULL, NULL);
  49795. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49796. return WC_TEST_RET_ENC_EC(ret);
  49797. ret = mp_div_2_mod_ct(NULL, b, 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(NULL, NULL, a);
  49801. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49802. return WC_TEST_RET_ENC_EC(ret);
  49803. ret = mp_div_2_mod_ct(a, 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(a, b, NULL);
  49807. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49808. return WC_TEST_RET_ENC_EC(ret);
  49809. ret = mp_div_2_mod_ct(NULL, b, a);
  49810. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49811. return WC_TEST_RET_ENC_EC(ret);
  49812. ret = mp_div_2(NULL, NULL);
  49813. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49814. return WC_TEST_RET_ENC_EC(ret);
  49815. ret = mp_div_2(a, NULL);
  49816. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49817. return WC_TEST_RET_ENC_EC(ret);
  49818. ret = mp_div_2(NULL, a);
  49819. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49820. return WC_TEST_RET_ENC_EC(ret);
  49821. #endif
  49822. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49823. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  49824. ret = mp_invmod(NULL, NULL, NULL);
  49825. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49826. return WC_TEST_RET_ENC_EC(ret);
  49827. ret = mp_invmod(a, NULL, NULL);
  49828. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49829. return WC_TEST_RET_ENC_EC(ret);
  49830. ret = mp_invmod(NULL, b, NULL);
  49831. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49832. return WC_TEST_RET_ENC_EC(ret);
  49833. ret = mp_invmod(NULL, NULL, a);
  49834. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49835. return WC_TEST_RET_ENC_EC(ret);
  49836. ret = mp_invmod(a, b, NULL);
  49837. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49838. return WC_TEST_RET_ENC_EC(ret);
  49839. ret = mp_invmod(a, NULL, a);
  49840. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49841. return WC_TEST_RET_ENC_EC(ret);
  49842. ret = mp_invmod(NULL, b, a);
  49843. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49844. return WC_TEST_RET_ENC_EC(ret);
  49845. #endif
  49846. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49847. ret = mp_invmod_mont_ct(NULL, NULL, NULL, 1);
  49848. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49849. return WC_TEST_RET_ENC_EC(ret);
  49850. ret = mp_invmod_mont_ct(a, NULL, NULL, 1);
  49851. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49852. return WC_TEST_RET_ENC_EC(ret);
  49853. ret = mp_invmod_mont_ct(NULL, b, NULL, 1);
  49854. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49855. return WC_TEST_RET_ENC_EC(ret);
  49856. ret = mp_invmod_mont_ct(NULL, NULL, a, 1);
  49857. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49858. return WC_TEST_RET_ENC_EC(ret);
  49859. ret = mp_invmod_mont_ct(a, b, NULL, 1);
  49860. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49861. return WC_TEST_RET_ENC_EC(ret);
  49862. ret = mp_invmod_mont_ct(a, NULL, a, 1);
  49863. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49864. return WC_TEST_RET_ENC_EC(ret);
  49865. ret = mp_invmod_mont_ct(NULL, b, a, 1);
  49866. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49867. return WC_TEST_RET_ENC_EC(ret);
  49868. #endif
  49869. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  49870. ret = mp_lcm(NULL, NULL, NULL);
  49871. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49872. return WC_TEST_RET_ENC_EC(ret);
  49873. ret = mp_lcm(a, NULL, NULL);
  49874. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49875. return WC_TEST_RET_ENC_EC(ret);
  49876. ret = mp_lcm(NULL, b, NULL);
  49877. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49878. return WC_TEST_RET_ENC_EC(ret);
  49879. ret = mp_lcm(NULL, NULL, a);
  49880. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49881. return WC_TEST_RET_ENC_EC(ret);
  49882. ret = mp_lcm(a, b, NULL);
  49883. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49884. return WC_TEST_RET_ENC_EC(ret);
  49885. ret = mp_lcm(a, NULL, a);
  49886. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49887. return WC_TEST_RET_ENC_EC(ret);
  49888. ret = mp_lcm(NULL, b, a);
  49889. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49890. return WC_TEST_RET_ENC_EC(ret);
  49891. #endif
  49892. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49893. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49894. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49895. return WC_TEST_RET_ENC_EC(ret);
  49896. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49897. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49898. return WC_TEST_RET_ENC_EC(ret);
  49899. ret = mp_exptmod_ex(NULL, b, 1, NULL, NULL);
  49900. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49901. return WC_TEST_RET_ENC_EC(ret);
  49902. ret = mp_exptmod_ex(NULL, NULL, 1, b, NULL);
  49903. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49904. return WC_TEST_RET_ENC_EC(ret);
  49905. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49906. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49907. return WC_TEST_RET_ENC_EC(ret);
  49908. ret = mp_exptmod_ex(a, b, 1, b, NULL);
  49909. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49910. return WC_TEST_RET_ENC_EC(ret);
  49911. ret = mp_exptmod_ex(a, b, 1, NULL, a);
  49912. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49913. return WC_TEST_RET_ENC_EC(ret);
  49914. ret = mp_exptmod_ex(a, NULL, 1, b, a);
  49915. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49916. return WC_TEST_RET_ENC_EC(ret);
  49917. ret = mp_exptmod_ex(NULL, b, 1, b, a);
  49918. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49919. return WC_TEST_RET_ENC_EC(ret);
  49920. ret = mp_exptmod(NULL, NULL, NULL, NULL);
  49921. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49922. return WC_TEST_RET_ENC_EC(ret);
  49923. ret = mp_exptmod(a, NULL, NULL, NULL);
  49924. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49925. return WC_TEST_RET_ENC_EC(ret);
  49926. ret = mp_exptmod(NULL, b, NULL, NULL);
  49927. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49928. return WC_TEST_RET_ENC_EC(ret);
  49929. ret = mp_exptmod(NULL, NULL, b, NULL);
  49930. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49931. return WC_TEST_RET_ENC_EC(ret);
  49932. ret = mp_exptmod(NULL, NULL, NULL, a);
  49933. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49934. return WC_TEST_RET_ENC_EC(ret);
  49935. ret = mp_exptmod(a, b, b, NULL);
  49936. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49937. return WC_TEST_RET_ENC_EC(ret);
  49938. ret = mp_exptmod(a, b, NULL, a);
  49939. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49940. return WC_TEST_RET_ENC_EC(ret);
  49941. ret = mp_exptmod(a, NULL, b, a);
  49942. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49943. return WC_TEST_RET_ENC_EC(ret);
  49944. ret = mp_exptmod(NULL, b, b, a);
  49945. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49946. return WC_TEST_RET_ENC_EC(ret);
  49947. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49948. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49949. return WC_TEST_RET_ENC_EC(ret);
  49950. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49951. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49952. return WC_TEST_RET_ENC_EC(ret);
  49953. ret = mp_exptmod_nct(NULL, b, NULL, NULL);
  49954. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49955. return WC_TEST_RET_ENC_EC(ret);
  49956. ret = mp_exptmod_nct(NULL, NULL, b, NULL);
  49957. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49958. return WC_TEST_RET_ENC_EC(ret);
  49959. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49960. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49961. return WC_TEST_RET_ENC_EC(ret);
  49962. ret = mp_exptmod_nct(a, b, b, NULL);
  49963. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49964. return WC_TEST_RET_ENC_EC(ret);
  49965. ret = mp_exptmod_nct(a, b, NULL, a);
  49966. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49967. return WC_TEST_RET_ENC_EC(ret);
  49968. ret = mp_exptmod_nct(a, NULL, b, a);
  49969. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49970. return WC_TEST_RET_ENC_EC(ret);
  49971. ret = mp_exptmod_nct(NULL, b, b, a);
  49972. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49973. return WC_TEST_RET_ENC_EC(ret);
  49974. #endif
  49975. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  49976. ret = mp_cnt_lsb(NULL);
  49977. if (ret != 0)
  49978. return WC_TEST_RET_ENC_EC(ret);
  49979. #endif
  49980. #ifdef WOLFSSL_SP_PRIME_GEN
  49981. ret = mp_prime_is_prime(NULL, 1, NULL);
  49982. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49983. return WC_TEST_RET_ENC_EC(ret);
  49984. ret = mp_prime_is_prime(a, 1, NULL);
  49985. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49986. return WC_TEST_RET_ENC_EC(ret);
  49987. ret = mp_prime_is_prime(NULL, 1, &result);
  49988. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49989. return WC_TEST_RET_ENC_EC(ret);
  49990. ret = mp_prime_is_prime(a, 0, &result);
  49991. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49992. return WC_TEST_RET_ENC_EC(ret);
  49993. ret = mp_prime_is_prime(a, 1024, &result);
  49994. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49995. return WC_TEST_RET_ENC_EC(ret);
  49996. ret = mp_prime_is_prime_ex(NULL, 1, NULL, NULL);
  49997. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49998. return WC_TEST_RET_ENC_EC(ret);
  49999. ret = mp_prime_is_prime_ex(a, 1, NULL, NULL);
  50000. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50001. return WC_TEST_RET_ENC_EC(ret);
  50002. ret = mp_prime_is_prime_ex(NULL, 1, &result, NULL);
  50003. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50004. return WC_TEST_RET_ENC_EC(ret);
  50005. ret = mp_prime_is_prime_ex(NULL, 1, NULL, rng);
  50006. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50007. return WC_TEST_RET_ENC_EC(ret);
  50008. ret = mp_prime_is_prime_ex(a, 1, &result, NULL);
  50009. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50010. return WC_TEST_RET_ENC_EC(ret);
  50011. ret = mp_prime_is_prime_ex(a, 1, NULL, rng);
  50012. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50013. return WC_TEST_RET_ENC_EC(ret);
  50014. ret = mp_prime_is_prime_ex(NULL, 1, &result, rng);
  50015. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50016. return WC_TEST_RET_ENC_EC(ret);
  50017. #endif
  50018. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA)
  50019. ret = mp_exch(NULL, NULL);
  50020. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50021. return WC_TEST_RET_ENC_EC(ret);
  50022. ret = mp_exch(a, NULL);
  50023. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50024. return WC_TEST_RET_ENC_EC(ret);
  50025. ret = mp_exch(NULL, b);
  50026. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50027. return WC_TEST_RET_ENC_EC(ret);
  50028. #endif
  50029. #if (defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)) || \
  50030. defined(WOLFSSL_SP_MATH_ALL)
  50031. ret = mp_mul_d(NULL, 1, NULL);
  50032. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50033. return WC_TEST_RET_ENC_EC(ret);
  50034. ret = mp_mul_d(a, 1, NULL);
  50035. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50036. return WC_TEST_RET_ENC_EC(ret);
  50037. ret = mp_mul_d(NULL, 1, b);
  50038. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50039. return WC_TEST_RET_ENC_EC(ret);
  50040. #endif
  50041. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50042. ret = mp_add(NULL, NULL, NULL);
  50043. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50044. return WC_TEST_RET_ENC_EC(ret);
  50045. ret = mp_add(a, NULL, NULL);
  50046. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50047. return WC_TEST_RET_ENC_EC(ret);
  50048. ret = mp_add(NULL, b, NULL);
  50049. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50050. return WC_TEST_RET_ENC_EC(ret);
  50051. ret = mp_add(NULL, NULL, r);
  50052. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50053. return WC_TEST_RET_ENC_EC(ret);
  50054. ret = mp_add(a, b, NULL);
  50055. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50056. return WC_TEST_RET_ENC_EC(ret);
  50057. ret = mp_add(a, NULL, r);
  50058. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50059. return WC_TEST_RET_ENC_EC(ret);
  50060. ret = mp_add(NULL, b, r);
  50061. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50062. return WC_TEST_RET_ENC_EC(ret);
  50063. #endif
  50064. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50065. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50066. ret = mp_sub(NULL, NULL, NULL);
  50067. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50068. return WC_TEST_RET_ENC_EC(ret);
  50069. ret = mp_sub(a, NULL, NULL);
  50070. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50071. return WC_TEST_RET_ENC_EC(ret);
  50072. ret = mp_sub(NULL, b, NULL);
  50073. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50074. return WC_TEST_RET_ENC_EC(ret);
  50075. ret = mp_sub(NULL, NULL, r);
  50076. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50077. return WC_TEST_RET_ENC_EC(ret);
  50078. ret = mp_sub(a, b, NULL);
  50079. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50080. return WC_TEST_RET_ENC_EC(ret);
  50081. ret = mp_sub(a, NULL, r);
  50082. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50083. return WC_TEST_RET_ENC_EC(ret);
  50084. ret = mp_sub(NULL, b, r);
  50085. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50086. return WC_TEST_RET_ENC_EC(ret);
  50087. #endif
  50088. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined(WOLFSSL_SP_MATH) && \
  50089. defined(WOLFSSL_CUSTOM_CURVES))
  50090. ret = mp_addmod(NULL, NULL, NULL, NULL);
  50091. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50092. return WC_TEST_RET_ENC_EC(ret);
  50093. ret = mp_addmod(a, NULL, NULL, NULL);
  50094. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50095. return WC_TEST_RET_ENC_EC(ret);
  50096. ret = mp_addmod(NULL, b, NULL, NULL);
  50097. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50098. return WC_TEST_RET_ENC_EC(ret);
  50099. ret = mp_addmod(NULL, NULL, b, NULL);
  50100. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50101. return WC_TEST_RET_ENC_EC(ret);
  50102. ret = mp_addmod(NULL, NULL, NULL, a);
  50103. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50104. return WC_TEST_RET_ENC_EC(ret);
  50105. ret = mp_addmod(a, b, b, NULL);
  50106. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50107. return WC_TEST_RET_ENC_EC(ret);
  50108. ret = mp_addmod(a, b, NULL, a);
  50109. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50110. return WC_TEST_RET_ENC_EC(ret);
  50111. ret = mp_addmod(a, NULL, b, a);
  50112. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50113. return WC_TEST_RET_ENC_EC(ret);
  50114. ret = mp_addmod(NULL, b, b, a);
  50115. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50116. return WC_TEST_RET_ENC_EC(ret);
  50117. #endif
  50118. #ifdef WOLFSSL_SP_MATH_ALL
  50119. ret = mp_submod(NULL, NULL, NULL, NULL);
  50120. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50121. return WC_TEST_RET_ENC_EC(ret);
  50122. ret = mp_submod(a, NULL, NULL, NULL);
  50123. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50124. return WC_TEST_RET_ENC_EC(ret);
  50125. ret = mp_submod(NULL, b, NULL, NULL);
  50126. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50127. return WC_TEST_RET_ENC_EC(ret);
  50128. ret = mp_submod(NULL, NULL, b, NULL);
  50129. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50130. return WC_TEST_RET_ENC_EC(ret);
  50131. ret = mp_submod(NULL, NULL, NULL, a);
  50132. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50133. return WC_TEST_RET_ENC_EC(ret);
  50134. ret = mp_submod(a, b, b, NULL);
  50135. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50136. return WC_TEST_RET_ENC_EC(ret);
  50137. ret = mp_submod(a, b, NULL, a);
  50138. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50139. return WC_TEST_RET_ENC_EC(ret);
  50140. ret = mp_submod(a, NULL, b, a);
  50141. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50142. return WC_TEST_RET_ENC_EC(ret);
  50143. ret = mp_submod(NULL, b, b, a);
  50144. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50145. return WC_TEST_RET_ENC_EC(ret);
  50146. #endif
  50147. #ifdef WOLFSSL_SP_MATH_ALL
  50148. ret = mp_div_2d(NULL, 1, a, b);
  50149. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50150. return WC_TEST_RET_ENC_EC(ret);
  50151. ret = mp_mod_2d(NULL, 1, NULL);
  50152. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50153. return WC_TEST_RET_ENC_EC(ret);
  50154. ret = mp_mod_2d(a, 1, NULL);
  50155. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50156. return WC_TEST_RET_ENC_EC(ret);
  50157. ret = mp_mod_2d(NULL, 1, b);
  50158. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50159. return WC_TEST_RET_ENC_EC(ret);
  50160. ret = mp_mul_2d(NULL, 1, NULL);
  50161. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50162. return WC_TEST_RET_ENC_EC(ret);
  50163. ret = mp_mul_2d(a, 1, NULL);
  50164. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50165. return WC_TEST_RET_ENC_EC(ret);
  50166. ret = mp_mul_2d(NULL, 1, b);
  50167. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50168. return WC_TEST_RET_ENC_EC(ret);
  50169. #endif
  50170. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50171. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50172. ret = mp_montgomery_reduce(NULL, NULL, 1);
  50173. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50174. return WC_TEST_RET_ENC_EC(ret);
  50175. ret = mp_montgomery_reduce(a, NULL, 1);
  50176. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50177. return WC_TEST_RET_ENC_EC(ret);
  50178. ret = mp_montgomery_reduce(NULL, b, 1);
  50179. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50180. return WC_TEST_RET_ENC_EC(ret);
  50181. mp_zero(b);
  50182. ret = mp_montgomery_reduce(a, b, 1);
  50183. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50184. return WC_TEST_RET_ENC_EC(ret);
  50185. #endif
  50186. #ifdef WOLFSSL_SP_MATH_ALL
  50187. ret = mp_montgomery_setup(NULL, NULL);
  50188. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50189. return WC_TEST_RET_ENC_EC(ret);
  50190. ret = mp_montgomery_setup(a, NULL);
  50191. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50192. return WC_TEST_RET_ENC_EC(ret);
  50193. ret = mp_montgomery_setup(NULL, &rho);
  50194. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50195. return WC_TEST_RET_ENC_EC(ret);
  50196. ret = mp_montgomery_calc_normalization(NULL, NULL);
  50197. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50198. return WC_TEST_RET_ENC_EC(ret);
  50199. ret = mp_montgomery_calc_normalization(a, NULL);
  50200. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50201. return WC_TEST_RET_ENC_EC(ret);
  50202. ret = mp_montgomery_calc_normalization(NULL, b);
  50203. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50204. return WC_TEST_RET_ENC_EC(ret);
  50205. #endif
  50206. ret = mp_unsigned_bin_size(NULL);
  50207. if (ret != 0)
  50208. return WC_TEST_RET_ENC_EC(ret);
  50209. #if defined(WC_MP_TO_RADIX) || defined(WOLFSSL_SP_MATH_ALL)
  50210. ret = mp_tohex(NULL, NULL);
  50211. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50212. return WC_TEST_RET_ENC_EC(ret);
  50213. ret = mp_tohex(a, NULL);
  50214. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50215. return WC_TEST_RET_ENC_EC(ret);
  50216. ret = mp_tohex(NULL, hexStr);
  50217. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50218. return WC_TEST_RET_ENC_EC(ret);
  50219. #endif
  50220. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  50221. ret = mp_todecimal(NULL, NULL);
  50222. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50223. return WC_TEST_RET_ENC_EC(ret);
  50224. ret = mp_todecimal(a, NULL);
  50225. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50226. return WC_TEST_RET_ENC_EC(ret);
  50227. ret = mp_todecimal(NULL, decStr);
  50228. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50229. return WC_TEST_RET_ENC_EC(ret);
  50230. #endif
  50231. #ifdef WOLFSSL_SP_MATH_ALL
  50232. ret = mp_toradix(NULL, NULL, MP_RADIX_HEX);
  50233. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50234. return WC_TEST_RET_ENC_EC(ret);
  50235. ret = mp_toradix(a, NULL, MP_RADIX_HEX);
  50236. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50237. return WC_TEST_RET_ENC_EC(ret);
  50238. ret = mp_toradix(NULL, hexStr, MP_RADIX_HEX);
  50239. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50240. return WC_TEST_RET_ENC_EC(ret);
  50241. ret = mp_toradix(a, hexStr, 3);
  50242. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50243. return WC_TEST_RET_ENC_EC(ret);
  50244. ret = mp_radix_size(NULL, MP_RADIX_HEX, NULL);
  50245. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50246. return WC_TEST_RET_ENC_EC(ret);
  50247. ret = mp_radix_size(a, MP_RADIX_HEX, NULL);
  50248. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50249. return WC_TEST_RET_ENC_EC(ret);
  50250. ret = mp_radix_size(NULL, MP_RADIX_HEX, &size);
  50251. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50252. return WC_TEST_RET_ENC_EC(ret);
  50253. ret = mp_radix_size(a, 3, &size);
  50254. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50255. return WC_TEST_RET_ENC_EC(ret);
  50256. #endif
  50257. return 0;
  50258. }
  50259. #endif
  50260. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50261. static wc_test_ret_t mp_test_set_is_bit(mp_int* a)
  50262. {
  50263. int i, j;
  50264. wc_test_ret_t ret;
  50265. mp_zero(a);
  50266. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50267. if (mp_is_bit_set(a, i))
  50268. return WC_TEST_RET_ENC_NC;
  50269. for (j = 0; j < i; j++) {
  50270. if (!mp_is_bit_set(a, j))
  50271. return WC_TEST_RET_ENC_NC;
  50272. }
  50273. if (mp_set_bit(a, i) != 0)
  50274. return WC_TEST_RET_ENC_NC;
  50275. if (!mp_is_bit_set(a, i))
  50276. return WC_TEST_RET_ENC_NC;
  50277. }
  50278. mp_zero(a);
  50279. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50280. if (mp_is_bit_set(a, i))
  50281. return WC_TEST_RET_ENC_NC;
  50282. }
  50283. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50284. mp_zero(a);
  50285. if (mp_set_bit(a, i) != 0)
  50286. return WC_TEST_RET_ENC_NC;
  50287. for (j = 0; j < i; j++) {
  50288. if (mp_is_bit_set(a, j))
  50289. return WC_TEST_RET_ENC_NC;
  50290. }
  50291. if (!mp_is_bit_set(a, i))
  50292. return WC_TEST_RET_ENC_NC;
  50293. }
  50294. #ifdef WOLFSSL_KEY_GEN
  50295. for (i = 0; i < DIGIT_BIT * 2; i++) {
  50296. mp_set(a, 1);
  50297. ret = mp_2expt(a, i);
  50298. if (ret != 0)
  50299. return WC_TEST_RET_ENC_EC(ret);
  50300. for (j = 0; j < i; j++) {
  50301. if (mp_is_bit_set(a, j))
  50302. return WC_TEST_RET_ENC_NC;
  50303. }
  50304. if (!mp_is_bit_set(a, i))
  50305. return WC_TEST_RET_ENC_NC;
  50306. }
  50307. #endif
  50308. #ifdef WOLFSSL_SP_MATH
  50309. mp_zero(a);
  50310. for (j = 1; j <= 3; j++) {
  50311. i = SP_INT_MAX_BITS - j;
  50312. if (mp_is_bit_set(a, i))
  50313. return WC_TEST_RET_ENC_NC;
  50314. if (mp_set_bit(a, i) != 0)
  50315. return WC_TEST_RET_ENC_NC;
  50316. if (!mp_is_bit_set(a, i))
  50317. return WC_TEST_RET_ENC_NC;
  50318. #ifdef WOLFSSL_KEY_GEN
  50319. ret = mp_2expt(a, i);
  50320. if (ret != 0)
  50321. return WC_TEST_RET_ENC_EC(ret);
  50322. if (!mp_is_bit_set(a, i))
  50323. return WC_TEST_RET_ENC_NC;
  50324. #endif
  50325. }
  50326. mp_zero(a);
  50327. for (j = 0; j <= 3; j++) {
  50328. i = SP_INT_MAX_BITS + j;
  50329. if (mp_is_bit_set(a, i))
  50330. return WC_TEST_RET_ENC_NC;
  50331. if (mp_set_bit(a, i) != WC_NO_ERR_TRACE(MP_VAL))
  50332. return WC_TEST_RET_ENC_NC;
  50333. #ifdef WOLFSSL_KEY_GEN
  50334. ret = mp_2expt(a, i);
  50335. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50336. return WC_TEST_RET_ENC_EC(ret);
  50337. #endif
  50338. }
  50339. #endif
  50340. (void)ret;
  50341. return 0;
  50342. }
  50343. #endif /* !WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */
  50344. static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b)
  50345. {
  50346. wc_test_ret_t ret;
  50347. mp_zero(a);
  50348. mp_zero(b);
  50349. ret = mp_cmp_d(a, 0);
  50350. if (ret != MP_EQ)
  50351. return WC_TEST_RET_ENC_EC(ret);
  50352. ret = mp_cmp_d(a, 1);
  50353. if (ret != MP_LT)
  50354. return WC_TEST_RET_ENC_EC(ret);
  50355. ret = mp_cmp(a, b);
  50356. if (ret != MP_EQ)
  50357. return WC_TEST_RET_ENC_NC;
  50358. mp_set(a, 1);
  50359. ret = mp_cmp_d(a, 0);
  50360. if (ret != MP_GT)
  50361. return WC_TEST_RET_ENC_EC(ret);
  50362. ret = mp_cmp_d(a, 1);
  50363. if (ret != MP_EQ)
  50364. return WC_TEST_RET_ENC_EC(ret);
  50365. ret = mp_cmp_d(a, 2);
  50366. if (ret != MP_LT)
  50367. return WC_TEST_RET_ENC_EC(ret);
  50368. ret = mp_cmp(a, b);
  50369. if (ret != MP_GT)
  50370. return WC_TEST_RET_ENC_NC;
  50371. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50372. mp_read_radix(b, "1234567890123456789", MP_RADIX_HEX);
  50373. ret = mp_cmp_d(b, -1);
  50374. if (ret != MP_GT)
  50375. return WC_TEST_RET_ENC_EC(ret);
  50376. ret = mp_cmp(a, b);
  50377. if (ret != MP_LT)
  50378. return WC_TEST_RET_ENC_NC;
  50379. ret = mp_cmp(b, a);
  50380. if (ret != MP_GT)
  50381. return WC_TEST_RET_ENC_NC;
  50382. ret = mp_cmp(b, b);
  50383. if (ret != MP_EQ)
  50384. return WC_TEST_RET_ENC_NC;
  50385. #endif
  50386. #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
  50387. defined(WOLFSSL_SP_INT_NEGATIVE)
  50388. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50389. mp_read_radix(a, "-1", MP_RADIX_HEX);
  50390. mp_read_radix(a, "1", MP_RADIX_HEX);
  50391. ret = mp_cmp(a, b);
  50392. if (ret != MP_LT)
  50393. return WC_TEST_RET_ENC_NC;
  50394. ret = mp_cmp(b, a);
  50395. if (ret != MP_GT)
  50396. return WC_TEST_RET_ENC_NC;
  50397. mp_read_radix(b, "-2", MP_RADIX_HEX);
  50398. ret = mp_cmp(a, b);
  50399. if (ret != MP_GT)
  50400. return WC_TEST_RET_ENC_NC;
  50401. ret = mp_cmp(b, a);
  50402. if (ret != MP_LT)
  50403. return WC_TEST_RET_ENC_NC;
  50404. #endif
  50405. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50406. mp_read_radix(a, "-2", MP_RADIX_HEX);
  50407. ret = mp_cmp(a, b);
  50408. if (ret != MP_EQ)
  50409. return WC_TEST_RET_ENC_NC;
  50410. #endif
  50411. #endif
  50412. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  50413. defined(WOLFSSL_ECC_GEN_REJECT_SAMPLING)
  50414. mp_zero(a);
  50415. mp_zero(b);
  50416. ret = mp_cmp_ct(a, b, 1);
  50417. if (ret != MP_EQ)
  50418. return WC_TEST_RET_ENC_EC(ret);
  50419. ret = mp_cmp_ct(a, a, a->used);
  50420. if (ret != MP_EQ)
  50421. return WC_TEST_RET_ENC_EC(ret);
  50422. #ifdef WOLFSSL_SP_MATH_ALL
  50423. ret = mp_cmp_ct(a, NULL, a->used);
  50424. if (ret != MP_GT)
  50425. return WC_TEST_RET_ENC_EC(ret);
  50426. ret = mp_cmp_ct(NULL, a, a->used);
  50427. if (ret != MP_LT)
  50428. return WC_TEST_RET_ENC_EC(ret);
  50429. #endif
  50430. mp_read_radix(a, "1", MP_RADIX_HEX);
  50431. ret = mp_cmp_ct(a, b, 1);
  50432. if (ret != MP_GT)
  50433. return WC_TEST_RET_ENC_EC(ret);
  50434. ret = mp_cmp_ct(b, a, 1);
  50435. if (ret != MP_LT)
  50436. return WC_TEST_RET_ENC_EC(ret);
  50437. mp_read_radix(a, "0123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50438. ret = mp_cmp_ct(a, b, a->used);
  50439. if (ret != MP_GT)
  50440. return WC_TEST_RET_ENC_EC(ret);
  50441. ret = mp_cmp_ct(b, a, a->used);
  50442. if (ret != MP_LT)
  50443. return WC_TEST_RET_ENC_EC(ret);
  50444. mp_read_radix(b, "1123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50445. ret = mp_cmp_ct(b, a, a->used);
  50446. if (ret != MP_GT)
  50447. return WC_TEST_RET_ENC_EC(ret);
  50448. ret = mp_cmp_ct(a, b, a->used);
  50449. if (ret != MP_LT)
  50450. return WC_TEST_RET_ENC_EC(ret);
  50451. mp_read_radix(b, "0123456789abcdef0123456789abcdf0", 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, "0123456789abcdf0", MP_RADIX_HEX);
  50459. ret = mp_cmp_ct(a, b, a->used);
  50460. if (ret != MP_GT)
  50461. return WC_TEST_RET_ENC_EC(ret);
  50462. ret = mp_cmp_ct(b, a, a->used);
  50463. if (ret != MP_LT)
  50464. return WC_TEST_RET_ENC_EC(ret);
  50465. #endif
  50466. return 0;
  50467. }
  50468. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50469. static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
  50470. {
  50471. wc_test_ret_t ret;
  50472. int i, j, k;
  50473. #ifndef WOLFSSL_SP_MATH
  50474. for (i = 0; i < 10; i++) {
  50475. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50476. ret = randNum(a, j, rng, NULL);
  50477. if (ret != MP_OKAY)
  50478. return WC_TEST_RET_ENC_EC(ret);
  50479. mp_copy(a, b);
  50480. for (k = 0; k <= DIGIT_BIT * 2; k++) {
  50481. ret = mp_mul_2d(a, k, a);
  50482. if (ret != MP_OKAY)
  50483. return WC_TEST_RET_ENC_EC(ret);
  50484. mp_rshb(a, k);
  50485. ret = mp_cmp(a, b);
  50486. if (ret != MP_EQ)
  50487. return WC_TEST_RET_ENC_NC;
  50488. }
  50489. }
  50490. }
  50491. #endif
  50492. for (i = 0; i < 10; i++) {
  50493. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50494. ret = randNum(a, j, rng, NULL);
  50495. if (ret != MP_OKAY)
  50496. return WC_TEST_RET_ENC_EC(ret);
  50497. mp_copy(a, b);
  50498. for (k = 0; k < 10; k++) {
  50499. ret = mp_lshd(a, k);
  50500. if (ret != MP_OKAY)
  50501. return WC_TEST_RET_ENC_EC(ret);
  50502. #ifndef WOLFSSL_SP_MATH
  50503. mp_rshd(a, k);
  50504. #else
  50505. mp_rshb(a, k * SP_WORD_SIZE);
  50506. #endif
  50507. ret = mp_cmp(a, b);
  50508. if (ret != MP_EQ)
  50509. return WC_TEST_RET_ENC_NC;
  50510. }
  50511. }
  50512. }
  50513. #ifndef WOLFSSL_SP_MATH
  50514. mp_zero(a);
  50515. mp_rshd(a, 1);
  50516. if (!mp_iszero(a))
  50517. return WC_TEST_RET_ENC_NC;
  50518. mp_set(a, 1);
  50519. mp_rshd(a, 1);
  50520. if (!mp_iszero(a))
  50521. return WC_TEST_RET_ENC_NC;
  50522. mp_set(a, 1);
  50523. mp_rshd(a, 2);
  50524. if (!mp_iszero(a))
  50525. return WC_TEST_RET_ENC_NC;
  50526. #endif
  50527. return 0;
  50528. }
  50529. #endif
  50530. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50531. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  50532. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  50533. static wc_test_ret_t mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem,
  50534. WC_RNG* rng)
  50535. {
  50536. wc_test_ret_t ret;
  50537. int i, j, k;
  50538. mp_zero(a);
  50539. mp_zero(d);
  50540. ret = mp_div(a, d, r, rem);
  50541. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50542. return WC_TEST_RET_ENC_EC(ret);
  50543. mp_set(d, 1);
  50544. ret = mp_div(a, d, r, rem);
  50545. if (ret != MP_OKAY)
  50546. return WC_TEST_RET_ENC_EC(ret);
  50547. if (!mp_iszero(r))
  50548. return WC_TEST_RET_ENC_EC(ret);
  50549. if (!mp_iszero(rem))
  50550. return WC_TEST_RET_ENC_EC(ret);
  50551. mp_set(a, 1);
  50552. ret = mp_div(a, d, r, rem);
  50553. if (ret != MP_OKAY)
  50554. return WC_TEST_RET_ENC_EC(ret);
  50555. if (!mp_isone(r))
  50556. return WC_TEST_RET_ENC_EC(ret);
  50557. if (!mp_iszero(rem))
  50558. return WC_TEST_RET_ENC_EC(ret);
  50559. for (i = 0; i < 100; i++) {
  50560. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 2; j++) {
  50561. ret = randNum(d, j, rng, NULL);
  50562. if (ret != MP_OKAY)
  50563. return WC_TEST_RET_ENC_EC(ret);
  50564. for (k = 1; k < (DIGIT_BIT + 7) / 8 * 2 + 1; k++) {
  50565. ret = randNum(a, k, rng, NULL);
  50566. if (ret != MP_OKAY)
  50567. return WC_TEST_RET_ENC_EC(ret);
  50568. ret = mp_div(a, d, NULL, rem);
  50569. if (ret != MP_OKAY)
  50570. return WC_TEST_RET_ENC_EC(ret);
  50571. ret = mp_div(a, d, r, NULL);
  50572. if (ret != MP_OKAY)
  50573. return WC_TEST_RET_ENC_EC(ret);
  50574. ret = mp_div(a, d, r, rem);
  50575. if (ret != MP_OKAY)
  50576. return WC_TEST_RET_ENC_EC(ret);
  50577. mp_mul(r, d, r);
  50578. mp_add(r, rem, r);
  50579. if (mp_cmp(r, a) != MP_EQ)
  50580. return WC_TEST_RET_ENC_NC;
  50581. }
  50582. }
  50583. }
  50584. ret = randNum(d, (DIGIT_BIT + 7) / 8 * 2, rng, NULL);
  50585. if (ret != MP_OKAY)
  50586. return WC_TEST_RET_ENC_EC(ret);
  50587. mp_add(d, d, a);
  50588. mp_set(rem, 1);
  50589. mp_div(a, d, NULL, rem);
  50590. if (ret != MP_OKAY)
  50591. return WC_TEST_RET_ENC_EC(ret);
  50592. if (!mp_iszero(rem))
  50593. return WC_TEST_RET_ENC_EC(ret);
  50594. mp_set(r, 1);
  50595. mp_div(a, d, r, NULL);
  50596. if (ret != MP_OKAY)
  50597. return WC_TEST_RET_ENC_EC(ret);
  50598. if (mp_cmp_d(r, 2) != MP_EQ)
  50599. return WC_TEST_RET_ENC_EC(ret);
  50600. mp_set(r, 1);
  50601. mp_set(rem, 1);
  50602. mp_div(a, d, r, rem);
  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. if (!mp_iszero(rem))
  50608. return WC_TEST_RET_ENC_EC(ret);
  50609. mp_set(a, 0xfe);
  50610. mp_lshd(a, 3);
  50611. mp_add_d(a, 0xff, a);
  50612. mp_set(d, 0xfe);
  50613. mp_lshd(d, 2);
  50614. ret = mp_div(a, d, r, rem);
  50615. if (ret != MP_OKAY)
  50616. return WC_TEST_RET_ENC_EC(ret);
  50617. mp_mul(r, d, d);
  50618. mp_add(rem, d, d);
  50619. if (mp_cmp(a, d) != MP_EQ)
  50620. return WC_TEST_RET_ENC_NC;
  50621. /* Force (hi | lo) / d to be (d | 0) / d which will would not fit in
  50622. * a digit. So mp_div must detect and handle.
  50623. * For example: 0x800000 / 0x8001, DIGIT_BIT = 8
  50624. */
  50625. mp_zero(a);
  50626. mp_set_bit(a, DIGIT_BIT * 3 - 1);
  50627. mp_zero(d);
  50628. mp_set_bit(d, DIGIT_BIT * 2 - 1);
  50629. mp_add_d(d, 1, d);
  50630. ret = mp_div(a, d, r, rem);
  50631. if (ret != MP_OKAY)
  50632. return WC_TEST_RET_ENC_EC(ret);
  50633. /* Make sure [d | d] / d is handled. */
  50634. mp_zero(a);
  50635. mp_set_bit(a, DIGIT_BIT * 2 - 1);
  50636. mp_set_bit(a, DIGIT_BIT * 1 - 1);
  50637. mp_zero(d);
  50638. mp_set_bit(d, DIGIT_BIT - 1);
  50639. ret = mp_div(a, d, r, rem);
  50640. if (ret != MP_OKAY)
  50641. return WC_TEST_RET_ENC_EC(ret);
  50642. mp_zero(a);
  50643. mp_set_bit(a, DIGIT_BIT);
  50644. mp_set_bit(a, 0);
  50645. mp_zero(d);
  50646. if (mp_cmp(r, a) != MP_EQ)
  50647. return WC_TEST_RET_ENC_NC;
  50648. if (mp_cmp(rem, d) != MP_EQ)
  50649. return WC_TEST_RET_ENC_NC;
  50650. return 0;
  50651. }
  50652. #endif
  50653. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50654. !defined(WC_NO_RNG)
  50655. static wc_test_ret_t mp_test_prime(mp_int* a, WC_RNG* rng)
  50656. {
  50657. wc_test_ret_t ret;
  50658. int res;
  50659. ret = mp_rand_prime(a, 1, rng, NULL);
  50660. #if defined(WOLFSSL_SP_MATH_ALL)
  50661. if (ret != 0)
  50662. return WC_TEST_RET_ENC_EC(ret);
  50663. #else
  50664. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50665. return WC_TEST_RET_ENC_NC;
  50666. #endif
  50667. #ifndef WOLFSSL_SP_MATH
  50668. ret = mp_rand_prime(a, -5, rng, NULL);
  50669. if (ret != 0 || (a->dp[0] & 3) != 3)
  50670. return WC_TEST_RET_ENC_NC;
  50671. #endif
  50672. ret = mp_prime_is_prime(a, 1, &res);
  50673. if (ret != MP_OKAY)
  50674. return WC_TEST_RET_ENC_EC(ret);
  50675. #ifndef WOLFSSL_SP_MATH
  50676. if (res != MP_YES)
  50677. return WC_TEST_RET_ENC_EC(res);
  50678. #else
  50679. if (res != MP_NO)
  50680. return WC_TEST_RET_ENC_EC(res);
  50681. #endif
  50682. ret = mp_prime_is_prime(a, 0, &res);
  50683. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50684. return WC_TEST_RET_ENC_EC(ret);
  50685. ret = mp_prime_is_prime(a, -1, &res);
  50686. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50687. return WC_TEST_RET_ENC_EC(ret);
  50688. ret = mp_prime_is_prime(a, 257, &res);
  50689. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50690. return WC_TEST_RET_ENC_EC(ret);
  50691. mp_set(a, 1);
  50692. ret = mp_prime_is_prime(a, 1, &res);
  50693. if (ret != MP_OKAY)
  50694. return WC_TEST_RET_ENC_EC(ret);
  50695. if (res != MP_NO)
  50696. return WC_TEST_RET_ENC_EC(res);
  50697. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50698. if (ret != MP_OKAY)
  50699. return WC_TEST_RET_ENC_EC(ret);
  50700. if (res != MP_NO)
  50701. return WC_TEST_RET_ENC_EC(res);
  50702. mp_set(a, 2);
  50703. ret = mp_prime_is_prime(a, 1, &res);
  50704. if (ret != MP_OKAY)
  50705. return WC_TEST_RET_ENC_EC(ret);
  50706. if (res != MP_YES)
  50707. return WC_TEST_RET_ENC_EC(res);
  50708. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50709. if (ret != MP_OKAY)
  50710. return WC_TEST_RET_ENC_EC(ret);
  50711. if (res != MP_YES)
  50712. return WC_TEST_RET_ENC_EC(res);
  50713. mp_set(a, 0xfb);
  50714. ret = mp_prime_is_prime(a, 1, &res);
  50715. if (ret != MP_OKAY)
  50716. return WC_TEST_RET_ENC_EC(ret);
  50717. if (res != MP_YES)
  50718. return WC_TEST_RET_ENC_EC(res);
  50719. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50720. if (ret != MP_OKAY)
  50721. return WC_TEST_RET_ENC_EC(ret);
  50722. if (res != MP_YES)
  50723. return WC_TEST_RET_ENC_EC(res);
  50724. mp_set(a, 0x6);
  50725. ret = mp_prime_is_prime(a, 1, &res);
  50726. if (ret != MP_OKAY)
  50727. return WC_TEST_RET_ENC_EC(ret);
  50728. if (res != MP_NO)
  50729. return WC_TEST_RET_ENC_EC(res);
  50730. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50731. if (ret != MP_OKAY)
  50732. return WC_TEST_RET_ENC_EC(ret);
  50733. if (res != MP_NO)
  50734. return WC_TEST_RET_ENC_EC(res);
  50735. mp_set_int(a, 0x655 * 0x65b);
  50736. ret = mp_prime_is_prime(a, 10, &res);
  50737. if (ret != MP_OKAY)
  50738. return WC_TEST_RET_ENC_EC(ret);
  50739. if (res != MP_NO)
  50740. return WC_TEST_RET_ENC_EC(res);
  50741. ret = mp_prime_is_prime_ex(a, 10, &res, rng);
  50742. if (ret != MP_OKAY)
  50743. return WC_TEST_RET_ENC_EC(ret);
  50744. if (res != MP_NO)
  50745. return WC_TEST_RET_ENC_EC(res);
  50746. return 0;
  50747. }
  50748. #endif
  50749. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  50750. static wc_test_ret_t mp_test_lcm_gcd(mp_int* a, mp_int* b, mp_int* r, mp_int* exp,
  50751. WC_RNG* rng)
  50752. {
  50753. wc_test_ret_t ret;
  50754. int i;
  50755. WOLFSSL_SMALL_STACK_STATIC const int kat[][3] = {
  50756. { 1, 1, 1 }, { 2, 1, 2 }, { 1, 2, 2 }, { 2, 4, 4 }, { 4, 2, 4 },
  50757. { 12, 56, 168 }, { 56, 12, 168 }
  50758. };
  50759. (void)exp;
  50760. mp_set(a, 0);
  50761. mp_set(b, 1);
  50762. ret = mp_lcm(a, a, r);
  50763. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50764. return WC_TEST_RET_ENC_EC(ret);
  50765. ret = mp_lcm(a, b, r);
  50766. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50767. return WC_TEST_RET_ENC_EC(ret);
  50768. ret = mp_lcm(b, a, r);
  50769. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50770. return WC_TEST_RET_ENC_EC(ret);
  50771. for (i = 0; i < (int)(sizeof(kat) / sizeof(*kat)); i++) {
  50772. mp_set(a, kat[i][0]);
  50773. mp_set(b, kat[i][1]);
  50774. ret = mp_lcm(a, b, r);
  50775. if (ret != MP_OKAY)
  50776. return WC_TEST_RET_ENC_EC(ret);
  50777. mp_set(exp, kat[i][2]);
  50778. ret = mp_cmp(r, exp);
  50779. if (ret != MP_EQ)
  50780. return WC_TEST_RET_ENC_NC;
  50781. }
  50782. (void)rng;
  50783. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50784. !defined(WC_NO_RNG)
  50785. ret = mp_rand_prime(a, 20, rng, NULL);
  50786. if (ret != MP_OKAY)
  50787. return WC_TEST_RET_ENC_EC(ret);
  50788. ret = mp_rand_prime(b, 20, rng, NULL);
  50789. if (ret != MP_OKAY)
  50790. return WC_TEST_RET_ENC_EC(ret);
  50791. ret = mp_mul(a, b, exp);
  50792. if (ret != MP_OKAY)
  50793. return WC_TEST_RET_ENC_EC(ret);
  50794. ret = mp_lcm(a, b, r);
  50795. if (ret != MP_OKAY)
  50796. return WC_TEST_RET_ENC_EC(ret);
  50797. ret = mp_cmp(r, exp);
  50798. if (ret != MP_EQ)
  50799. return WC_TEST_RET_ENC_NC;
  50800. ret = mp_lcm(b, a, r);
  50801. if (ret != MP_OKAY)
  50802. return WC_TEST_RET_ENC_EC(ret);
  50803. ret = mp_cmp(r, exp);
  50804. if (ret != MP_EQ)
  50805. return WC_TEST_RET_ENC_NC;
  50806. #endif
  50807. mp_set(a, 11);
  50808. mp_zero(b);
  50809. ret = mp_gcd(a, b, r);
  50810. if (ret != MP_OKAY)
  50811. return WC_TEST_RET_ENC_EC(ret);
  50812. ret = mp_cmp_d(r, 11);
  50813. if (ret != MP_EQ)
  50814. return WC_TEST_RET_ENC_EC(ret);
  50815. ret = mp_gcd(b, a, r);
  50816. if (ret != MP_OKAY)
  50817. return WC_TEST_RET_ENC_EC(ret);
  50818. ret = mp_cmp_d(r, 11);
  50819. if (ret != MP_EQ)
  50820. return WC_TEST_RET_ENC_EC(ret);
  50821. ret = mp_gcd(b, b, r);
  50822. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50823. return WC_TEST_RET_ENC_EC(ret);
  50824. return 0;
  50825. }
  50826. #endif
  50827. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50828. defined(WOLFSSL_SP_MATH_ALL)
  50829. static wc_test_ret_t mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng)
  50830. {
  50831. wc_test_ret_t ret;
  50832. int i;
  50833. int j;
  50834. mp_set(a, 10);
  50835. ret = mp_mod_2d(a, 0, r);
  50836. if (ret != MP_OKAY)
  50837. return WC_TEST_RET_ENC_EC(ret);
  50838. if (!mp_iszero(r))
  50839. return WC_TEST_RET_ENC_NC;
  50840. ret = mp_mod_2d(a, 1, r);
  50841. if (ret != MP_OKAY)
  50842. return WC_TEST_RET_ENC_EC(ret);
  50843. if (!mp_iszero(r))
  50844. return WC_TEST_RET_ENC_NC;
  50845. ret = mp_mod_2d(a, 2, r);
  50846. if (ret != MP_OKAY)
  50847. return WC_TEST_RET_ENC_EC(ret);
  50848. ret = mp_cmp_d(r, 2);
  50849. if (ret != 0)
  50850. return WC_TEST_RET_ENC_EC(ret);
  50851. for (i = 2; i < 20; i++) {
  50852. ret = randNum(a, i, rng, NULL);
  50853. if (ret != 0)
  50854. return WC_TEST_RET_ENC_EC(ret);
  50855. for (j = 1; j <= mp_count_bits(a); j++) {
  50856. /* Get top part */
  50857. ret = mp_div_2d(a, j, t, NULL);
  50858. if (ret != 0)
  50859. return WC_TEST_RET_ENC_EC(ret);
  50860. ret = mp_mul_2d(t, j, t);
  50861. if (ret != 0)
  50862. return WC_TEST_RET_ENC_EC(ret);
  50863. /* Get bottom part */
  50864. ret = mp_mod_2d(a, j, r);
  50865. if (ret != 0)
  50866. return WC_TEST_RET_ENC_EC(ret);
  50867. /* Reassemble */
  50868. ret = mp_add(t, r, r);
  50869. if (ret != 0)
  50870. return WC_TEST_RET_ENC_EC(ret);
  50871. ret = mp_cmp(a, r);
  50872. if (ret != MP_EQ)
  50873. return WC_TEST_RET_ENC_NC;
  50874. }
  50875. }
  50876. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_SP_INT_NEGATIVE)
  50877. /* Test negative value being moded. */
  50878. for (j = 0; j < 20; j++) {
  50879. ret = randNum(a, 2, rng, NULL);
  50880. if (ret != 0)
  50881. return WC_TEST_RET_ENC_EC(ret);
  50882. a->sign = MP_NEG;
  50883. for (i = 1; i < DIGIT_BIT * 3 + 1; i++) {
  50884. ret = mp_mod_2d(a, i, r);
  50885. if (ret != 0)
  50886. return WC_TEST_RET_ENC_EC(ret);
  50887. mp_zero(t);
  50888. ret = mp_set_bit(t, i);
  50889. if (ret != 0)
  50890. return WC_TEST_RET_ENC_EC(ret);
  50891. ret = mp_mod(a, t, t);
  50892. if (ret != 0)
  50893. return WC_TEST_RET_ENC_EC(ret);
  50894. ret = mp_cmp(r, t);
  50895. if (ret != MP_EQ)
  50896. return WC_TEST_RET_ENC_NC;
  50897. }
  50898. }
  50899. #endif
  50900. return 0;
  50901. }
  50902. #endif
  50903. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50904. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50905. static wc_test_ret_t mp_test_mod_d(mp_int* a, WC_RNG* rng)
  50906. {
  50907. wc_test_ret_t ret;
  50908. mp_digit r;
  50909. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50910. mp_digit rem;
  50911. int i;
  50912. #endif
  50913. (void)rng;
  50914. ret = mp_set(a, 1);
  50915. if (ret != MP_OKAY)
  50916. return WC_TEST_RET_ENC_EC(ret);
  50917. ret = mp_mod_d(a, 0, &r);
  50918. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50919. return WC_TEST_RET_ENC_EC(ret);
  50920. mp_zero(a);
  50921. ret = mp_mod_d(a, 1, &r);
  50922. if (ret != MP_OKAY)
  50923. return WC_TEST_RET_ENC_EC(ret);
  50924. ret = mp_mod_d(a, 3, &r);
  50925. if (ret != MP_OKAY)
  50926. return WC_TEST_RET_ENC_EC(ret);
  50927. ret = mp_mod_d(a, 5, &r);
  50928. if (ret != MP_OKAY)
  50929. return WC_TEST_RET_ENC_EC(ret);
  50930. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50931. for (i = MP_MAX_TEST_BYTE_LEN - 16; i <= MP_MAX_TEST_BYTE_LEN; i++) {
  50932. ret = randNum(a, i, rng, NULL);
  50933. if (ret != MP_OKAY)
  50934. return WC_TEST_RET_ENC_EC(ret);
  50935. ret = mp_mod_d(a, 3, &r);
  50936. if (ret != MP_OKAY)
  50937. return WC_TEST_RET_ENC_EC(ret);
  50938. ret = mp_div_d(a, 3, a, &rem);
  50939. if (ret != MP_OKAY)
  50940. return WC_TEST_RET_ENC_EC(ret);
  50941. if (r != rem)
  50942. return WC_TEST_RET_ENC_NC;
  50943. }
  50944. #endif
  50945. return 0;
  50946. }
  50947. #endif
  50948. static wc_test_ret_t mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r2,
  50949. WC_RNG* rng)
  50950. {
  50951. wc_test_ret_t ret;
  50952. int i;
  50953. for (i = 1; i < 16; i++) {
  50954. ret = randNum(a, i, rng, NULL);
  50955. if (ret != 0)
  50956. return WC_TEST_RET_ENC_EC(ret);
  50957. ret = mp_mul(a, a, r1);
  50958. if (ret != 0)
  50959. return WC_TEST_RET_ENC_EC(ret);
  50960. ret = mp_sqr(a, r2);
  50961. if (ret != 0)
  50962. return WC_TEST_RET_ENC_EC(ret);
  50963. ret = mp_cmp(r1, r2);
  50964. if (ret != MP_EQ)
  50965. return WC_TEST_RET_ENC_NC;
  50966. }
  50967. ret = mp_set(b, 0);
  50968. if (ret != MP_OKAY)
  50969. return WC_TEST_RET_ENC_EC(ret);
  50970. ret = mp_mul(a, b, r1);
  50971. if (ret != MP_OKAY)
  50972. return WC_TEST_RET_ENC_EC(ret);
  50973. if (!mp_iszero(r1))
  50974. return WC_TEST_RET_ENC_EC(ret);
  50975. ret = mp_sqr(b, r1);
  50976. if (ret != MP_OKAY)
  50977. return WC_TEST_RET_ENC_EC(ret);
  50978. if (!mp_iszero(r1))
  50979. return WC_TEST_RET_ENC_NC;
  50980. #ifdef WOLFSSL_SP_MATH_ALL
  50981. ret = mp_set(a, 1);
  50982. if (ret != MP_OKAY)
  50983. return WC_TEST_RET_ENC_EC(ret);
  50984. i = (SP_INT_DIGITS / 2) + 1;
  50985. ret = mp_mul_2d(a, i * SP_WORD_SIZE - 1, a);
  50986. if (ret != MP_OKAY)
  50987. return WC_TEST_RET_ENC_EC(ret);
  50988. ret = mp_set(b, 1);
  50989. if (ret != MP_OKAY)
  50990. return WC_TEST_RET_ENC_EC(ret);
  50991. ret = mp_mul_2d(b, (SP_INT_DIGITS - 1 - i) * SP_WORD_SIZE - 1, b);
  50992. if (ret != MP_OKAY)
  50993. return WC_TEST_RET_ENC_EC(ret);
  50994. ret = mp_mul(a, b, r1);
  50995. if (ret != MP_OKAY)
  50996. return WC_TEST_RET_ENC_EC(ret);
  50997. ret = mp_mul(a, a, r1);
  50998. if (ret == MP_OKAY)
  50999. return WC_TEST_RET_ENC_NC;
  51000. ret = mp_sqr(a, r1);
  51001. if (ret == MP_OKAY)
  51002. return WC_TEST_RET_ENC_NC;
  51003. ret = mp_sqr(b, r1);
  51004. if (ret != MP_OKAY)
  51005. return WC_TEST_RET_ENC_EC(ret);
  51006. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51007. (defined(HAVE_ECC) && defined(FP_ECC))
  51008. ret = mp_mulmod(a, b, b, r1);
  51009. if (ret != MP_OKAY)
  51010. return WC_TEST_RET_ENC_EC(ret);
  51011. ret = mp_mulmod(a, a, b, r1);
  51012. if (ret == MP_OKAY)
  51013. return WC_TEST_RET_ENC_NC;
  51014. #if defined(HAVE_ECC) && (defined(ECC_SHAMIR) || defined(FP_ECC))
  51015. ret = mp_sqrmod(a, b, r1);
  51016. if (ret == MP_OKAY)
  51017. return WC_TEST_RET_ENC_NC;
  51018. ret = mp_sqrmod(b, a, r1);
  51019. if (ret != MP_OKAY)
  51020. return WC_TEST_RET_ENC_EC(ret);
  51021. #endif /* HAVE_ECC && (ECC_SHAMIR || FP_ECC) */
  51022. #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
  51023. #endif /* WOLFSSL_SP_MATH_ALL */
  51024. return 0;
  51025. }
  51026. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  51027. defined(OPENSSL_EXTRA)
  51028. static wc_test_ret_t mp_test_invmod(mp_int* a, mp_int* m, mp_int* r)
  51029. {
  51030. wc_test_ret_t ret;
  51031. mp_set(a, 0);
  51032. mp_set(m, 1);
  51033. ret = mp_invmod(a, m, r);
  51034. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51035. return WC_TEST_RET_ENC_EC(ret);
  51036. ret = mp_invmod(m, a, r);
  51037. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51038. return WC_TEST_RET_ENC_EC(ret);
  51039. mp_set(a, 2);
  51040. mp_set(m, 4);
  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. mp_set(a, 3);
  51045. mp_set(m, 6);
  51046. ret = mp_invmod(a, m, r);
  51047. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51048. return WC_TEST_RET_ENC_EC(ret);
  51049. mp_set(a, 5*9);
  51050. mp_set(m, 6*9);
  51051. ret = mp_invmod(a, m, r);
  51052. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51053. return WC_TEST_RET_ENC_EC(ret);
  51054. mp_set(a, 1);
  51055. mp_set(m, 4);
  51056. ret = mp_invmod(a, m, r);
  51057. if (ret != MP_OKAY)
  51058. return WC_TEST_RET_ENC_EC(ret);
  51059. if (!mp_isone(r))
  51060. return WC_TEST_RET_ENC_NC;
  51061. mp_set(a, 3);
  51062. mp_set(m, 4);
  51063. ret = mp_invmod(a, m, r);
  51064. if (ret != MP_OKAY)
  51065. return WC_TEST_RET_ENC_EC(ret);
  51066. ret = mp_cmp_d(r, 3);
  51067. if (ret != 0)
  51068. return WC_TEST_RET_ENC_EC(ret);
  51069. mp_set(a, 3);
  51070. mp_set(m, 5);
  51071. ret = mp_invmod(a, m, r);
  51072. if (ret != MP_OKAY)
  51073. return WC_TEST_RET_ENC_EC(ret);
  51074. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51075. /* Maximum 'a' */
  51076. mp_set(a, 0);
  51077. mp_set_bit(a, (r->size / 2)* SP_WORD_SIZE - 1);
  51078. mp_sub_d(a, 1, a);
  51079. /* Modulus too big. */
  51080. mp_set(m, 0);
  51081. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE);
  51082. ret = mp_invmod(a, m, r);
  51083. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51084. return WC_TEST_RET_ENC_EC(ret);
  51085. /* Maximum modulus - even. */
  51086. mp_set(m, 0);
  51087. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE - 1);
  51088. ret = mp_invmod(a, m, r);
  51089. if (ret != MP_OKAY)
  51090. return WC_TEST_RET_ENC_EC(ret);
  51091. #endif
  51092. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_INT_NEGATIVE)
  51093. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  51094. mp_read_radix(a, "-3", 16);
  51095. ret = mp_invmod(a, m, r);
  51096. if (ret != MP_OKAY)
  51097. return WC_TEST_RET_ENC_EC(ret);
  51098. #endif
  51099. #endif
  51100. #if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC)
  51101. mp_set(a, 0);
  51102. mp_set(m, 3);
  51103. ret = mp_invmod_mont_ct(a, m, r, 1);
  51104. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51105. return WC_TEST_RET_ENC_EC(ret);
  51106. mp_set(a, 1);
  51107. mp_set(m, 0);
  51108. ret = mp_invmod_mont_ct(a, m, r, 1);
  51109. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51110. return WC_TEST_RET_ENC_EC(ret);
  51111. mp_set(a, 1);
  51112. mp_set(m, 1);
  51113. ret = mp_invmod_mont_ct(a, m, r, 1);
  51114. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51115. return WC_TEST_RET_ENC_EC(ret);
  51116. mp_set(a, 1);
  51117. mp_set(m, 2);
  51118. ret = mp_invmod_mont_ct(a, m, r, 1);
  51119. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51120. return WC_TEST_RET_ENC_EC(ret);
  51121. mp_set(a, 1);
  51122. mp_set(m, 3);
  51123. ret = mp_invmod_mont_ct(a, m, r, 1);
  51124. if (ret != MP_OKAY)
  51125. return WC_TEST_RET_ENC_EC(ret);
  51126. #endif
  51127. return 0;
  51128. }
  51129. #endif /* !NO_RSA || HAVE_ECC || !NO_DSA || OPENSSL_EXTRA */
  51130. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51131. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51132. static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r)
  51133. {
  51134. wc_test_ret_t ret;
  51135. mp_set(b, 0x2);
  51136. mp_set(e, 0x3);
  51137. mp_set(m, 0x0);
  51138. ret = mp_exptmod_ex(b, e, 1, m, r);
  51139. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51140. return WC_TEST_RET_ENC_EC(ret);
  51141. ret = mp_exptmod_nct(b, e, m, r);
  51142. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51143. return WC_TEST_RET_ENC_EC(ret);
  51144. mp_set(b, 0x2);
  51145. mp_set(e, 0x3);
  51146. mp_set(m, 0x1);
  51147. ret = mp_exptmod_ex(b, e, 1, m, r);
  51148. if (ret != MP_OKAY)
  51149. return WC_TEST_RET_ENC_EC(ret);
  51150. if (!mp_iszero(r))
  51151. return WC_TEST_RET_ENC_NC;
  51152. ret = mp_exptmod_nct(b, e, m, r);
  51153. if (ret != MP_OKAY)
  51154. return WC_TEST_RET_ENC_EC(ret);
  51155. if (!mp_iszero(r))
  51156. return WC_TEST_RET_ENC_NC;
  51157. mp_set(b, 0x2);
  51158. mp_set(e, 0x0);
  51159. mp_set(m, 0x7);
  51160. ret = mp_exptmod_ex(b, e, 1, m, r);
  51161. if (ret != MP_OKAY)
  51162. return WC_TEST_RET_ENC_EC(ret);
  51163. if (!mp_isone(r))
  51164. return WC_TEST_RET_ENC_NC;
  51165. ret = mp_exptmod_nct(b, e, m, r);
  51166. if (ret != MP_OKAY)
  51167. return WC_TEST_RET_ENC_EC(ret);
  51168. if (!mp_isone(r))
  51169. return WC_TEST_RET_ENC_NC;
  51170. mp_set(b, 0x0);
  51171. mp_set(e, 0x3);
  51172. mp_set(m, 0x7);
  51173. ret = mp_exptmod_ex(b, e, 1, m, r);
  51174. if (ret != MP_OKAY)
  51175. return WC_TEST_RET_ENC_EC(ret);
  51176. if (!mp_iszero(r))
  51177. return WC_TEST_RET_ENC_NC;
  51178. ret = mp_exptmod_nct(b, e, m, r);
  51179. if (ret != MP_OKAY)
  51180. return WC_TEST_RET_ENC_EC(ret);
  51181. if (!mp_iszero(r))
  51182. return WC_TEST_RET_ENC_NC;
  51183. mp_set(b, 0x10);
  51184. mp_set(e, 0x3);
  51185. mp_set(m, 0x7);
  51186. ret = mp_exptmod_ex(b, e, 1, m, r);
  51187. if (ret != MP_OKAY)
  51188. return WC_TEST_RET_ENC_EC(ret);
  51189. ret = mp_exptmod_nct(b, e, m, r);
  51190. if (ret != MP_OKAY)
  51191. return WC_TEST_RET_ENC_EC(ret);
  51192. mp_set(b, 0x7);
  51193. mp_set(e, 0x3);
  51194. mp_set(m, 0x7);
  51195. ret = mp_exptmod_ex(b, e, 1, m, r);
  51196. if (ret != MP_OKAY)
  51197. return WC_TEST_RET_ENC_EC(ret);
  51198. if (!mp_iszero(r))
  51199. return WC_TEST_RET_ENC_NC;
  51200. ret = mp_exptmod_nct(b, e, m, r);
  51201. if (ret != MP_OKAY)
  51202. return WC_TEST_RET_ENC_EC(ret);
  51203. if (!mp_iszero(r))
  51204. return WC_TEST_RET_ENC_NC;
  51205. #ifndef WOLFSSL_SP_MATH
  51206. mp_set(b, 0x01);
  51207. mp_mul_2d(b, DIGIT_BIT, b);
  51208. mp_add_d(b, 1, b);
  51209. mp_set(e, 0x3);
  51210. mp_copy(b, m);
  51211. ret = mp_exptmod_ex(b, e, 1, m, r);
  51212. if (ret != MP_OKAY)
  51213. return WC_TEST_RET_ENC_EC(ret);
  51214. if (!mp_iszero(r))
  51215. return WC_TEST_RET_ENC_NC;
  51216. ret = mp_exptmod_nct(b, e, m, r);
  51217. if (ret != MP_OKAY)
  51218. return WC_TEST_RET_ENC_EC(ret);
  51219. if (!mp_iszero(r))
  51220. return WC_TEST_RET_ENC_NC;
  51221. #endif
  51222. mp_set(b, 0x2);
  51223. mp_set(e, 0x3);
  51224. mp_set(m, 0x7);
  51225. ret = mp_exptmod_ex(b, e, 1, m, r);
  51226. if (ret != MP_OKAY)
  51227. return WC_TEST_RET_ENC_EC(ret);
  51228. ret = mp_exptmod_nct(b, e, m, r);
  51229. if (ret != MP_OKAY)
  51230. return WC_TEST_RET_ENC_EC(ret);
  51231. #ifdef WOLFSSL_SP_MATH_ALL
  51232. mp_set(b, 0x2);
  51233. mp_set(e, 0x3);
  51234. mp_set(m, 0x01);
  51235. mp_mul_2d(m, SP_WORD_SIZE * SP_INT_DIGITS / 2, m);
  51236. mp_add_d(m, 0x01, m);
  51237. ret = mp_exptmod_ex(b, e, 1, m, r);
  51238. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51239. return WC_TEST_RET_ENC_EC(ret);
  51240. ret = mp_exptmod_nct(b, e, m, r);
  51241. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51242. return WC_TEST_RET_ENC_EC(ret);
  51243. #endif
  51244. return 0;
  51245. }
  51246. #endif /* !NO_RSA || !NO_DSA || !NO_DH || (HAVE_ECC && HAVE_COMP_KEY) ||
  51247. * OPENSSL_EXTRA */
  51248. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51249. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51250. static wc_test_ret_t mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng)
  51251. {
  51252. wc_test_ret_t ret;
  51253. mp_digit mp;
  51254. static int exp[] = { 7, 8, 16, 27, 32, 64,
  51255. 127, 128, 255, 256,
  51256. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  51257. 383, 384, 2033, 2048
  51258. #endif
  51259. };
  51260. static mp_digit sub[] = { 0x01, 0x05, 0x0f, 0x27, 0x05, 0x3b,
  51261. 0x01, 0x9f, 0x13, 0xbd,
  51262. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  51263. 0x1f, 0x13d, 0x45, 0x615
  51264. #endif
  51265. };
  51266. int bits[] = { 256, 384,
  51267. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 4096
  51268. 2048,
  51269. #endif
  51270. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 6144
  51271. 3072
  51272. #endif
  51273. };
  51274. int i;
  51275. int j;
  51276. for (i = 0; i < (int)(sizeof(exp) / sizeof(*exp)); i++) {
  51277. if (exp[i] >= DIGIT_BIT)
  51278. continue;
  51279. mp_zero(m);
  51280. ret = mp_set_bit(m, exp[i]);
  51281. if (ret != MP_OKAY)
  51282. return WC_TEST_RET_ENC_EC(ret);
  51283. ret = mp_sub_d(m, sub[i], m);
  51284. if (ret != MP_OKAY)
  51285. return WC_TEST_RET_ENC_EC(ret);
  51286. ret = mp_montgomery_setup(m, &mp);
  51287. if (ret != MP_OKAY)
  51288. return WC_TEST_RET_ENC_EC(ret);
  51289. ret = mp_montgomery_calc_normalization(n, m);
  51290. if (ret != MP_OKAY)
  51291. return WC_TEST_RET_ENC_EC(ret);
  51292. for (j = 0; j < 10; j++) {
  51293. ret = randNum(a, (exp[i] + DIGIT_BIT - 1) / DIGIT_BIT, rng, NULL);
  51294. if (ret != 0)
  51295. return WC_TEST_RET_ENC_EC(ret);
  51296. ret = mp_mod(a, m, a);
  51297. if (ret != 0)
  51298. return WC_TEST_RET_ENC_EC(ret);
  51299. /* r = a * a */
  51300. ret = mp_sqrmod(a, m, r);
  51301. if (ret != MP_OKAY)
  51302. return WC_TEST_RET_ENC_EC(ret);
  51303. /* Convert to Montgomery form = a*n */
  51304. ret = mp_mulmod(a, n, m, a);
  51305. if (ret != MP_OKAY)
  51306. return WC_TEST_RET_ENC_EC(ret);
  51307. /* a*a mod m == ((a*n) * (a*n)) / n / n */
  51308. ret = mp_sqr(a, a);
  51309. if (ret != MP_OKAY)
  51310. return WC_TEST_RET_ENC_EC(ret);
  51311. ret = mp_montgomery_reduce(a, m, mp);
  51312. if (ret != MP_OKAY)
  51313. return WC_TEST_RET_ENC_EC(ret);
  51314. ret = mp_montgomery_reduce(a, m, mp);
  51315. if (ret != MP_OKAY)
  51316. return WC_TEST_RET_ENC_EC(ret);
  51317. if (mp_cmp(a, r) != MP_EQ)
  51318. return WC_TEST_RET_ENC_NC;
  51319. }
  51320. }
  51321. /* Force carries. */
  51322. for (i = 0; i < (int)(sizeof(bits) / sizeof(*bits)); i++) {
  51323. /* a = 2^(bits*2) - 1 */
  51324. mp_zero(a);
  51325. mp_set_bit(a, bits[i] * 2);
  51326. ret = mp_sub_d(a, 1, a);
  51327. if (ret != MP_OKAY)
  51328. return WC_TEST_RET_ENC_EC(ret);
  51329. /* m = 2^(bits) - 1 */
  51330. mp_zero(m);
  51331. mp_set_bit(m, bits[i]);
  51332. ret = mp_sub_d(m, 1, m);
  51333. if (ret != MP_OKAY)
  51334. return WC_TEST_RET_ENC_EC(ret);
  51335. mp = 1;
  51336. /* result = r = 2^(bits) - 1 */
  51337. mp_zero(r);
  51338. mp_set_bit(r, bits[i]);
  51339. ret = mp_sub_d(r, 1, r);
  51340. if (ret != MP_OKAY)
  51341. return WC_TEST_RET_ENC_EC(ret);
  51342. ret = mp_montgomery_reduce(a, m, mp);
  51343. if (ret != MP_OKAY)
  51344. return WC_TEST_RET_ENC_EC(ret);
  51345. /* Result is m or 0 if reduced to range of modulus. */
  51346. if (mp_cmp(a, r) != MP_EQ && mp_iszero(a) != MP_YES)
  51347. return WC_TEST_RET_ENC_NC;
  51348. }
  51349. return 0;
  51350. }
  51351. #endif
  51352. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
  51353. {
  51354. WC_RNG rng;
  51355. int rng_inited = 0;
  51356. wc_test_ret_t ret;
  51357. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51358. int i, j;
  51359. #ifndef WOLFSSL_SP_MATH
  51360. int k;
  51361. #endif
  51362. mp_digit d = 0;
  51363. #endif
  51364. #ifdef WOLFSSL_SMALL_STACK
  51365. mp_int *a = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51366. DYNAMIC_TYPE_TMP_BUFFER),
  51367. *b = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51368. DYNAMIC_TYPE_TMP_BUFFER),
  51369. *r1 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51370. DYNAMIC_TYPE_TMP_BUFFER),
  51371. *r2 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51372. DYNAMIC_TYPE_TMP_BUFFER),
  51373. *p = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51374. DYNAMIC_TYPE_TMP_BUFFER);
  51375. if ((a == NULL) ||
  51376. (b == NULL) ||
  51377. (r1 == NULL) ||
  51378. (r2 == NULL) ||
  51379. (p == NULL))
  51380. {
  51381. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  51382. }
  51383. #else
  51384. mp_int a[1], b[1], r1[1], r2[1], p[1];
  51385. #endif
  51386. WOLFSSL_ENTER("mp_test");
  51387. ret = mp_init_multi(a, b, r1, r2, NULL, NULL);
  51388. if (ret != 0)
  51389. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51390. #ifdef WOLFSSL_SP_MATH_ALL
  51391. mp_init_copy(p, a);
  51392. #else
  51393. ret = mp_init(p);
  51394. if (ret != 0)
  51395. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51396. #endif
  51397. #ifndef HAVE_FIPS
  51398. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  51399. #else
  51400. ret = wc_InitRng(&rng);
  51401. #endif
  51402. if (ret != 0)
  51403. goto done;
  51404. rng_inited = 1;
  51405. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51406. mp_set_int(a, 0);
  51407. if (a->used != 0 || a->dp[0] != 0)
  51408. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51409. for (j = 1; j <= MP_MAX_TEST_BYTE_LEN; j++) {
  51410. for (i = 0; i < 4 * j; i++) {
  51411. /* New values to use. */
  51412. ret = randNum(p, j, &rng, NULL);
  51413. if (ret != 0)
  51414. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51415. ret = randNum(a, j, &rng, NULL);
  51416. if (ret != 0)
  51417. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51418. ret = randNum(b, j, &rng, NULL);
  51419. if (ret != 0)
  51420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51421. ret = wc_RNG_GenerateBlock(&rng, (byte*)&d, sizeof(d));
  51422. if (ret != 0)
  51423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51424. d &= MP_MASK;
  51425. #if !defined(WOLFSSL_SP_MATH) || (defined(HAVE_ECC) && \
  51426. (defined(ECC_SHAMIR) || defined(FP_ECC)))
  51427. /* Ensure sqrmod produce same result as mulmod. */
  51428. ret = mp_sqrmod(a, p, r1);
  51429. if (ret != 0)
  51430. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51431. ret = mp_mulmod(a, a, p, r2);
  51432. if (ret != 0)
  51433. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51434. if (mp_cmp(r1, r2) != 0) {
  51435. WOLFSSL_MSG("Fail: mp_mulmod result does not match mp_sqrmod!");
  51436. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51437. }
  51438. #endif
  51439. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51440. #if defined(WOLFSSL_SP_MATH) || (defined(WOLFSSL_SP_MATH_ALL) && \
  51441. !defined(WOLFSSL_SP_INT_NEGATIVE))
  51442. ret = mp_addmod(a, b, p, r1);
  51443. if (ret != 0)
  51444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51445. ret = mp_submod(r1, b, p, r2);
  51446. if (ret != 0)
  51447. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51448. ret = mp_mod(a, p, r1);
  51449. if (ret != 0)
  51450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51451. if (mp_cmp(r1, r2) != MP_EQ)
  51452. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51453. #else
  51454. /* Ensure add with mod produce same result as sub with mod. */
  51455. ret = mp_addmod(a, b, p, r1);
  51456. if (ret != 0)
  51457. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51458. b->sign ^= 1;
  51459. ret = mp_submod(a, b, p, r2);
  51460. if (ret != 0)
  51461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51462. if (mp_cmp(r1, r2) != 0)
  51463. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51464. #endif
  51465. #endif
  51466. /* Ensure add digit produce same result as sub digit. */
  51467. ret = mp_add_d(a, d, r1);
  51468. if (ret != 0)
  51469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51470. ret = mp_sub_d(r1, d, r2);
  51471. if (ret != 0)
  51472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51473. if (mp_cmp(a, r2) != 0)
  51474. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51475. /* Invert - if p is even it will use the slow impl.
  51476. * - if p and a are even it will fail.
  51477. */
  51478. ret = mp_invmod(a, p, r1);
  51479. if (ret != 0 && ret != WC_NO_ERR_TRACE(MP_VAL))
  51480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51481. #ifndef WOLFSSL_SP_MATH
  51482. /* Shift up and down number all bits in a digit. */
  51483. for (k = 0; k < DIGIT_BIT; k++) {
  51484. mp_mul_2d(a, k, r1);
  51485. mp_div_2d(r1, k, r2, p);
  51486. if (mp_cmp(a, r2) != 0)
  51487. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51488. if (!mp_iszero(p))
  51489. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51490. mp_rshb(r1, k);
  51491. if (mp_cmp(a, r1) != 0)
  51492. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51493. }
  51494. #endif
  51495. }
  51496. }
  51497. /* Test adding and subtracting zero from zero. */
  51498. mp_zero(a);
  51499. ret = mp_add_d(a, 0, r1);
  51500. if (ret != 0)
  51501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51502. if (!mp_iszero(r1)) {
  51503. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51504. }
  51505. ret = mp_sub_d(a, 0, r2);
  51506. if (ret != 0)
  51507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51508. if (!mp_iszero(r2)) {
  51509. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51510. }
  51511. #if DIGIT_BIT >= 32
  51512. /* Check that setting a 32-bit digit works. */
  51513. d &= 0xffffffffU;
  51514. mp_set_int(a, d);
  51515. if (a->used != 1 || a->dp[0] != d)
  51516. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51517. #endif
  51518. /* Check setting a bit and testing a bit works. */
  51519. for (i = 0; i < MP_MAX_TEST_BYTE_LEN * 8; i++) {
  51520. mp_zero(a);
  51521. mp_set_bit(a, i);
  51522. if (!mp_is_bit_set(a, i))
  51523. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51524. }
  51525. #endif
  51526. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  51527. mp_zero(a);
  51528. i = mp_cnt_lsb(a);
  51529. if (i != 0)
  51530. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51531. mp_set(a, 1);
  51532. i = mp_cnt_lsb(a);
  51533. if (i != 0)
  51534. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51535. mp_set(a, 32);
  51536. i = mp_cnt_lsb(a);
  51537. if (i != 5)
  51538. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51539. mp_zero(a);
  51540. mp_set_bit(a, 129);
  51541. i = mp_cnt_lsb(a);
  51542. if (i != 129)
  51543. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51544. #endif
  51545. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51546. if ((ret = mp_test_param(a, b, r1, &rng)) != 0)
  51547. goto done;
  51548. #endif
  51549. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  51550. if ((ret = mp_test_div_3(a, r1, &rng)) != 0)
  51551. goto done;
  51552. #endif
  51553. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  51554. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  51555. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  51556. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  51557. if ((ret = mp_test_radix_10(a, r1, &rng)) != 0)
  51558. goto done;
  51559. #endif
  51560. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  51561. defined(HAVE_ECC))
  51562. if ((ret = mp_test_radix_16(a, r1, &rng)) != 0)
  51563. goto done;
  51564. #endif
  51565. if ((ret = mp_test_shift(a, r1, &rng)) != 0)
  51566. goto done;
  51567. if ((ret = mp_test_add_sub_d(a, r1)) != 0)
  51568. goto done;
  51569. if ((ret = mp_test_read_to_bin(a)) != 0)
  51570. goto done;
  51571. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51572. if ((ret = mp_test_set_int(a)) != 0)
  51573. goto done;
  51574. #endif
  51575. if ((ret = mp_test_cmp(a, r1)) != 0)
  51576. goto done;
  51577. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51578. if ((ret = mp_test_shbd(a, b, &rng)) != 0)
  51579. goto done;
  51580. #endif
  51581. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51582. if ((ret = mp_test_set_is_bit(a)) != 0)
  51583. goto done;
  51584. #endif
  51585. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  51586. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  51587. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  51588. if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0)
  51589. goto done;
  51590. #endif
  51591. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  51592. !defined(WC_NO_RNG)
  51593. if ((ret = mp_test_prime(a, &rng)) != 0)
  51594. goto done;
  51595. #endif
  51596. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  51597. if ((ret = mp_test_lcm_gcd(a, b, r1, r2, &rng)) != 0)
  51598. goto done;
  51599. #endif
  51600. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  51601. defined(WOLFSSL_SP_MATH_ALL)
  51602. if ((ret = mp_test_mod_2d(a, r1, p, &rng)) != 0)
  51603. goto done;
  51604. #endif
  51605. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  51606. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  51607. if ((ret = mp_test_mod_d(a, &rng)) != 0)
  51608. goto done;
  51609. #endif
  51610. if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0)
  51611. goto done;
  51612. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  51613. defined(OPENSSL_EXTRA)
  51614. if ((ret = mp_test_invmod(a, b, r1)) != 0)
  51615. goto done;
  51616. #endif
  51617. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51618. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51619. if ((ret = mp_test_exptmod(a, b, r1, r2)) != 0)
  51620. goto done;
  51621. #endif
  51622. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51623. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51624. if ((ret = mp_test_mont(a, b, r1, r2, &rng)) != 0)
  51625. goto done;
  51626. #endif
  51627. done:
  51628. #ifdef WOLFSSL_SMALL_STACK
  51629. if (p) {
  51630. mp_clear(p);
  51631. XFREE(p, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51632. }
  51633. if (r2) {
  51634. mp_clear(r2);
  51635. XFREE(r2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51636. }
  51637. if (r1) {
  51638. mp_clear(r1);
  51639. XFREE(r1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51640. }
  51641. if (b) {
  51642. mp_clear(b);
  51643. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51644. }
  51645. if (a) {
  51646. mp_clear(a);
  51647. XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51648. }
  51649. #else
  51650. mp_clear(p);
  51651. mp_clear(r2);
  51652. mp_clear(r1);
  51653. mp_clear(b);
  51654. mp_clear(a);
  51655. #endif
  51656. if (rng_inited)
  51657. wc_FreeRng(&rng);
  51658. return ret;
  51659. }
  51660. #endif /* WOLFSSL_PUBLIC_MP && ((WOLFSSL_SP_MATH_ALL &&
  51661. * !WOLFSSL_RSA_VERIFY_ONLY) || USE_FAST_MATH) */
  51662. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  51663. typedef struct pairs_t {
  51664. const unsigned char* coeff;
  51665. int coeffSz;
  51666. int exp;
  51667. } pairs_t;
  51668. /*
  51669. n =p1p2p3, where pi = ki(p1-1)+1 with (k2,k3) = (173,293)
  51670. p1 = 2^192 * 0x000000000000e24fd4f6d6363200bf2323ec46285cac1d3a
  51671. + 2^0 * 0x0b2488b0c29d96c5e67f8bec15b54b189ae5636efe89b45b
  51672. */
  51673. static const unsigned char c192a[] =
  51674. {
  51675. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x4f,
  51676. 0xd4, 0xf6, 0xd6, 0x36, 0x32, 0x00, 0xbf, 0x23,
  51677. 0x23, 0xec, 0x46, 0x28, 0x5c, 0xac, 0x1d, 0x3a
  51678. };
  51679. static const unsigned char c0a[] =
  51680. {
  51681. 0x0b, 0x24, 0x88, 0xb0, 0xc2, 0x9d, 0x96, 0xc5,
  51682. 0xe6, 0x7f, 0x8b, 0xec, 0x15, 0xb5, 0x4b, 0x18,
  51683. 0x9a, 0xe5, 0x63, 0x6e, 0xfe, 0x89, 0xb4, 0x5b
  51684. };
  51685. static const pairs_t ecPairsA[] =
  51686. {
  51687. {c192a, sizeof(c192a), 192},
  51688. {c0a, sizeof(c0a), 0}
  51689. };
  51690. static const int kA[] = {173, 293};
  51691. static const unsigned char controlPrime[] = {
  51692. 0xe1, 0x76, 0x45, 0x80, 0x59, 0xb6, 0xd3, 0x49,
  51693. 0xdf, 0x0a, 0xef, 0x12, 0xd6, 0x0f, 0xf0, 0xb7,
  51694. 0xcb, 0x2a, 0x37, 0xbf, 0xa7, 0xf8, 0xb5, 0x4d,
  51695. 0xf5, 0x31, 0x35, 0xad, 0xe4, 0xa3, 0x94, 0xa1,
  51696. 0xdb, 0xf1, 0x96, 0xad, 0xb5, 0x05, 0x64, 0x85,
  51697. 0x83, 0xfc, 0x1b, 0x5b, 0x29, 0xaa, 0xbe, 0xf8,
  51698. 0x26, 0x3f, 0x76, 0x7e, 0xad, 0x1c, 0xf0, 0xcb,
  51699. 0xd7, 0x26, 0xb4, 0x1b, 0x05, 0x8e, 0x56, 0x86,
  51700. 0x7e, 0x08, 0x62, 0x21, 0xc1, 0x86, 0xd6, 0x47,
  51701. 0x79, 0x3e, 0xb7, 0x5d, 0xa4, 0xc6, 0x3a, 0xd7,
  51702. 0xb1, 0x74, 0x20, 0xf6, 0x50, 0x97, 0x41, 0x04,
  51703. 0x53, 0xed, 0x3f, 0x26, 0xd6, 0x6f, 0x91, 0xfa,
  51704. 0x68, 0x26, 0xec, 0x2a, 0xdc, 0x9a, 0xf1, 0xe7,
  51705. 0xdc, 0xfb, 0x73, 0xf0, 0x79, 0x43, 0x1b, 0x21,
  51706. 0xa3, 0x59, 0x04, 0x63, 0x52, 0x07, 0xc9, 0xd7,
  51707. 0xe6, 0xd1, 0x1b, 0x5d, 0x5e, 0x96, 0xfa, 0x53
  51708. };
  51709. static const unsigned char testOne[] = { 1 };
  51710. static wc_test_ret_t GenerateNextP(mp_int* p1, mp_int* p2, int k)
  51711. {
  51712. wc_test_ret_t ret;
  51713. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51714. mp_int *ki = (mp_int *)XMALLOC(sizeof(*ki), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51715. if (ki == NULL)
  51716. return MEMORY_E;
  51717. #else
  51718. mp_int ki[1];
  51719. #endif
  51720. ret = mp_init(ki);
  51721. if (ret != 0)
  51722. ret = WC_TEST_RET_ENC_EC(ret);
  51723. if (ret == 0) {
  51724. ret = mp_set(ki, (mp_digit)k);
  51725. if (ret != 0)
  51726. ret = WC_TEST_RET_ENC_EC(ret);
  51727. }
  51728. if (ret == 0) {
  51729. ret = mp_sub_d(p1, 1, p2);
  51730. if (ret != 0)
  51731. ret = WC_TEST_RET_ENC_EC(ret);
  51732. }
  51733. if (ret == 0) {
  51734. ret = mp_mul(p2, ki, p2);
  51735. if (ret != 0)
  51736. ret = WC_TEST_RET_ENC_EC(ret);
  51737. }
  51738. if (ret == 0) {
  51739. ret = mp_add_d(p2, 1, p2);
  51740. if (ret != 0)
  51741. ret = WC_TEST_RET_ENC_EC(ret);
  51742. }
  51743. mp_clear(ki);
  51744. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51745. XFREE(ki, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51746. #endif
  51747. return ret;
  51748. }
  51749. static wc_test_ret_t GenerateP(mp_int* p1, mp_int* p2, mp_int* p3,
  51750. const pairs_t* ecPairs, int ecPairsSz,
  51751. const int* k)
  51752. {
  51753. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51754. mp_int *x = NULL, *y = NULL;
  51755. #else
  51756. mp_int x[1], y[1];
  51757. #endif
  51758. wc_test_ret_t ret;
  51759. int i;
  51760. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51761. if (((x = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) ||
  51762. ((y = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)) {
  51763. ret = MEMORY_E;
  51764. goto out;
  51765. }
  51766. #endif
  51767. ret = mp_init_multi(x, y, NULL, NULL, NULL, NULL);
  51768. if (ret != 0) {
  51769. ret = WC_TEST_RET_ENC_EC(ret);
  51770. goto out;
  51771. }
  51772. for (i = 0; ret == 0 && i < ecPairsSz; i++) {
  51773. ret = mp_read_unsigned_bin(x, ecPairs[i].coeff, (word32)ecPairs[i].coeffSz);
  51774. if (ret != 0) {
  51775. ret = WC_TEST_RET_ENC_EC(ret);
  51776. break;
  51777. }
  51778. /* p1 = 2^exp */
  51779. ret = mp_2expt(y, ecPairs[i].exp);
  51780. if (ret != 0) {
  51781. ret = WC_TEST_RET_ENC_EC(ret);
  51782. break;
  51783. }
  51784. /* p1 = p1 * m */
  51785. ret = mp_mul(x, y, x);
  51786. if (ret != 0) {
  51787. ret = WC_TEST_RET_ENC_EC(ret);
  51788. break;
  51789. }
  51790. /* p1 += */
  51791. ret = mp_add(p1, x, p1);
  51792. if (ret != 0) {
  51793. ret = WC_TEST_RET_ENC_EC(ret);
  51794. break;
  51795. }
  51796. mp_zero(x);
  51797. mp_zero(y);
  51798. }
  51799. if (ret == 0)
  51800. ret = GenerateNextP(p1, p2, k[0]);
  51801. if (ret == 0)
  51802. ret = GenerateNextP(p1, p3, k[1]);
  51803. out:
  51804. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51805. if (x != NULL) {
  51806. mp_clear(x);
  51807. XFREE(x, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51808. }
  51809. if (y != NULL) {
  51810. mp_clear(y);
  51811. XFREE(y, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51812. }
  51813. #else
  51814. mp_clear(x);
  51815. mp_clear(y);
  51816. #endif
  51817. return ret;
  51818. }
  51819. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void)
  51820. {
  51821. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51822. mp_int *n = (mp_int *)XMALLOC(sizeof *n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51823. *p1 = (mp_int *)XMALLOC(sizeof *p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51824. *p2 = (mp_int *)XMALLOC(sizeof *p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51825. *p3 = (mp_int *)XMALLOC(sizeof *p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51826. #else
  51827. mp_int n[1],
  51828. p1[1],
  51829. p2[1],
  51830. p3[1];
  51831. #endif
  51832. wc_test_ret_t ret;
  51833. int isPrime = 0;
  51834. WC_RNG rng;
  51835. WOLFSSL_ENTER("prime_test");
  51836. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51837. if ((n == NULL) ||
  51838. (p1 == NULL) ||
  51839. (p2 == NULL) ||
  51840. (p3 == NULL))
  51841. ERROR_OUT(MEMORY_E, out);
  51842. #endif
  51843. ret = wc_InitRng(&rng);
  51844. if (ret != 0)
  51845. ret = WC_TEST_RET_ENC_EC(ret);
  51846. if (ret == 0) {
  51847. ret = mp_init_multi(n, p1, p2, p3, NULL, NULL);
  51848. if (ret != 0)
  51849. ret = WC_TEST_RET_ENC_EC(ret);
  51850. }
  51851. if (ret == 0)
  51852. ret = GenerateP(p1, p2, p3,
  51853. ecPairsA, sizeof(ecPairsA) / sizeof(ecPairsA[0]), kA);
  51854. if (ret == 0) {
  51855. ret = mp_mul(p1, p2, n);
  51856. if (ret != 0)
  51857. ret = WC_TEST_RET_ENC_EC(ret);
  51858. }
  51859. if (ret == 0) {
  51860. ret = mp_mul(n, p3, n);
  51861. if (ret != 0)
  51862. ret = WC_TEST_RET_ENC_EC(ret);
  51863. }
  51864. if (ret != 0)
  51865. ERROR_OUT(ret, out);
  51866. /* Check the old prime test using the number that false positives.
  51867. * This test result should indicate as not prime. */
  51868. ret = mp_prime_is_prime(n, 40, &isPrime);
  51869. if (ret != 0)
  51870. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51871. if (isPrime)
  51872. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51873. /* This test result should fail. It should indicate the value as prime. */
  51874. ret = mp_prime_is_prime(n, 8, &isPrime);
  51875. if (ret != 0)
  51876. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51877. if (!isPrime)
  51878. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51879. /* This test result should indicate the value as not prime. */
  51880. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51881. if (ret != 0)
  51882. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51883. if (isPrime)
  51884. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51885. ret = mp_read_unsigned_bin(n, controlPrime, sizeof(controlPrime));
  51886. if (ret != 0)
  51887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51888. /* This test result should indicate the value as prime. */
  51889. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51890. if (ret != 0)
  51891. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51892. if (!isPrime)
  51893. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51894. /* This test result should indicate the value as prime. */
  51895. isPrime = -1;
  51896. ret = mp_prime_is_prime(n, 8, &isPrime);
  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, testOne, sizeof(testOne));
  51902. if (ret != 0)
  51903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51904. /* This test result should indicate the value as not 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. ret = mp_prime_is_prime(n, 8, &isPrime);
  51911. if (ret != 0)
  51912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51913. if (isPrime)
  51914. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51915. ret = 0;
  51916. out:
  51917. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51918. if (n != NULL) {
  51919. mp_clear(n);
  51920. XFREE(n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51921. }
  51922. if (p1 != NULL) {
  51923. mp_clear(p1);
  51924. XFREE(p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51925. }
  51926. if (p2 != NULL) {
  51927. mp_clear(p2);
  51928. XFREE(p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51929. }
  51930. if (p3 != NULL) {
  51931. mp_clear(p3);
  51932. XFREE(p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51933. }
  51934. #else
  51935. mp_clear(p3);
  51936. mp_clear(p2);
  51937. mp_clear(p1);
  51938. mp_clear(n);
  51939. #endif
  51940. wc_FreeRng(&rng);
  51941. return ret;
  51942. }
  51943. #endif /* WOLFSSL_PUBLIC_MP */
  51944. #if defined(ASN_BER_TO_DER) && \
  51945. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  51946. defined(OPENSSL_EXTRA_X509_SMALL))
  51947. /* wc_BerToDer is only public facing in the case of test cert or opensslextra */
  51948. typedef struct berDerTestData {
  51949. const byte *in;
  51950. word32 inSz;
  51951. const byte *out;
  51952. word32 outSz;
  51953. } berDerTestData;
  51954. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void)
  51955. {
  51956. wc_test_ret_t ret;
  51957. int i;
  51958. word32 len = 0, l;
  51959. byte out[32];
  51960. WOLFSSL_SMALL_STACK_STATIC const byte good1_in[] = { 0x30, 0x80, 0x00, 0x00 };
  51961. WOLFSSL_SMALL_STACK_STATIC const byte good1_out[] = { 0x30, 0x00 };
  51962. WOLFSSL_SMALL_STACK_STATIC const byte good2_in[] = { 0x30, 0x80, 0x02, 0x01, 0x01, 0x00, 0x00 };
  51963. WOLFSSL_SMALL_STACK_STATIC const byte good2_out[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51964. WOLFSSL_SMALL_STACK_STATIC const byte good3_in[] = {
  51965. 0x24, 0x80, 0x04, 0x01, 0x01, 0x00, 0x00
  51966. };
  51967. WOLFSSL_SMALL_STACK_STATIC const byte good3_out[] = { 0x04, 0x1, 0x01 };
  51968. WOLFSSL_SMALL_STACK_STATIC const byte good4_in[] = {
  51969. 0x30, 0x80,
  51970. 0x02, 0x01, 0x01,
  51971. 0x30, 0x80,
  51972. 0x24, 0x80,
  51973. 0x04, 0x01, 0x01,
  51974. 0x04, 0x02, 0x02, 0x03,
  51975. 0x00, 0x00,
  51976. 0x06, 0x01, 0x01,
  51977. 0x00, 0x00,
  51978. 0x31, 0x80,
  51979. 0x06, 0x01, 0x01,
  51980. 0x00, 0x00,
  51981. 0x00, 0x00,
  51982. };
  51983. WOLFSSL_SMALL_STACK_STATIC const byte good4_out[] = {
  51984. 0x30, 0x12,
  51985. 0x02, 0x01, 0x01,
  51986. 0x30, 0x08,
  51987. 0x04, 0x03, 0x01, 0x02, 0x03,
  51988. 0x06, 0x01, 0x01,
  51989. 0x31, 0x03,
  51990. 0x06, 0x01, 0x01
  51991. };
  51992. WOLFSSL_SMALL_STACK_STATIC const byte good5_in[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51993. berDerTestData testData[] = {
  51994. { good1_in, sizeof(good1_in), good1_out, sizeof(good1_out) },
  51995. { good2_in, sizeof(good2_in), good2_out, sizeof(good2_out) },
  51996. { good3_in, sizeof(good3_in), good3_out, sizeof(good3_out) },
  51997. { good4_in, sizeof(good4_in), good4_out, sizeof(good4_out) },
  51998. { good5_in, sizeof(good5_in), good5_in , sizeof(good5_in ) },
  51999. };
  52000. WOLFSSL_ENTER("berder_test");
  52001. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  52002. ret = wc_BerToDer(testData[i].in, testData[i].inSz, NULL, &len);
  52003. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  52004. return WC_TEST_RET_ENC_I(i);
  52005. if (len != testData[i].outSz)
  52006. return WC_TEST_RET_ENC_I(i);
  52007. len = testData[i].outSz;
  52008. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &len);
  52009. if (ret != 0)
  52010. return WC_TEST_RET_ENC_I(i);
  52011. if (XMEMCMP(out, testData[i].out, len) != 0)
  52012. return WC_TEST_RET_ENC_I(i);
  52013. for (l = 1; l < testData[i].inSz; l++) {
  52014. ret = wc_BerToDer(testData[i].in, l, NULL, &len);
  52015. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  52016. return WC_TEST_RET_ENC_EC(ret);
  52017. len = testData[i].outSz;
  52018. ret = wc_BerToDer(testData[i].in, l, out, &len);
  52019. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  52020. return WC_TEST_RET_ENC_EC(ret);
  52021. }
  52022. for (l = 0; l < testData[i].outSz-1; l++) {
  52023. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &l);
  52024. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  52025. return WC_TEST_RET_ENC_EC(ret);
  52026. }
  52027. }
  52028. ret = wc_BerToDer(NULL, 4, NULL, NULL);
  52029. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52030. return WC_TEST_RET_ENC_EC(ret);
  52031. ret = wc_BerToDer(out, 4, NULL, NULL);
  52032. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52033. return WC_TEST_RET_ENC_EC(ret);
  52034. ret = wc_BerToDer(NULL, 4, NULL, &len);
  52035. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52036. return WC_TEST_RET_ENC_EC(ret);
  52037. ret = wc_BerToDer(NULL, 4, out, NULL);
  52038. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52039. return WC_TEST_RET_ENC_EC(ret);
  52040. ret = wc_BerToDer(out, 4, out, NULL);
  52041. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52042. return WC_TEST_RET_ENC_EC(ret);
  52043. ret = wc_BerToDer(NULL, 4, out, &len);
  52044. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52045. return WC_TEST_RET_ENC_EC(ret);
  52046. for (l = 1; l < sizeof(good4_out); l++) {
  52047. len = l;
  52048. ret = wc_BerToDer(good4_in, sizeof(good4_in), out, &len);
  52049. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  52050. return WC_TEST_RET_ENC_EC(ret);
  52051. }
  52052. return 0;
  52053. }
  52054. #endif /* ASN_BER_TO_DER && (WOLFSSL_TEST_CERT || OPENSSL_EXTRA ||
  52055. OPENSSL_EXTRA_X509_SMALL */
  52056. #ifdef DEBUG_WOLFSSL
  52057. static THREAD_LS_T int log_cnt = 0;
  52058. static void my_Logging_cb(const int logLevel, const char *const logMessage)
  52059. {
  52060. (void)logLevel;
  52061. (void)logMessage;
  52062. log_cnt++;
  52063. }
  52064. #endif /* DEBUG_WOLFSSL */
  52065. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void)
  52066. {
  52067. wc_test_ret_t ret;
  52068. #ifdef DEBUG_WOLFSSL
  52069. const char* msg = "Testing, testing. 1, 2, 3, 4 ...";
  52070. byte a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  52071. byte b[256];
  52072. int i;
  52073. WOLFSSL_ENTER("logging_test (debug)");
  52074. for (i = 0; i < (int)sizeof(b); i++)
  52075. b[i] = i;
  52076. ret = wolfSSL_Debugging_ON();
  52077. if (ret != 0)
  52078. return WC_TEST_RET_ENC_EC(ret);
  52079. ret = wolfSSL_SetLoggingCb(my_Logging_cb);
  52080. if (ret != 0)
  52081. return WC_TEST_RET_ENC_EC(ret);
  52082. WOLFSSL_MSG(msg);
  52083. WOLFSSL_BUFFER(a, sizeof(a));
  52084. WOLFSSL_BUFFER(b, sizeof(b));
  52085. WOLFSSL_BUFFER(NULL, 0);
  52086. WOLFSSL_ERROR(MEMORY_E);
  52087. WOLFSSL_ERROR_MSG(msg);
  52088. /* turn off logs */
  52089. wolfSSL_Debugging_OFF();
  52090. /* capture log count */
  52091. i = log_cnt;
  52092. /* validate no logs are output when disabled */
  52093. WOLFSSL_MSG(msg);
  52094. WOLFSSL_BUFFER(a, sizeof(a));
  52095. WOLFSSL_BUFFER(b, sizeof(b));
  52096. WOLFSSL_BUFFER(NULL, 0);
  52097. WOLFSSL_ERROR(MEMORY_E);
  52098. WOLFSSL_ERROR_MSG(msg);
  52099. /* check the logs were disabled */
  52100. if (i != log_cnt)
  52101. return WC_TEST_RET_ENC_NC;
  52102. /* restore callback and leave logging enabled */
  52103. wolfSSL_SetLoggingCb(NULL);
  52104. wolfSSL_Debugging_ON();
  52105. /* suppress unused args */
  52106. (void)a;
  52107. (void)b;
  52108. #else
  52109. WOLFSSL_ENTER("logging_test");
  52110. ret = wolfSSL_Debugging_ON();
  52111. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  52112. return WC_TEST_RET_ENC_EC(ret);
  52113. wolfSSL_Debugging_OFF();
  52114. ret = wolfSSL_SetLoggingCb(NULL);
  52115. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  52116. return WC_TEST_RET_ENC_EC(ret);
  52117. #endif /* DEBUG_WOLFSSL */
  52118. return 0;
  52119. }
  52120. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  52121. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void)
  52122. #else
  52123. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void)
  52124. #endif
  52125. {
  52126. #ifdef WOLFSSL_PTHREADS
  52127. wolfSSL_Mutex m;
  52128. #endif
  52129. #if defined(WOLFSSL_PTHREADS) || (!defined(WOLFSSL_NO_MALLOC) && \
  52130. !defined(WOLFSSL_USER_MUTEX) && defined(WOLFSSL_STATIC_MEMORY))
  52131. wc_test_ret_t ret;
  52132. #endif
  52133. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_USER_MUTEX)
  52134. #ifndef WOLFSSL_STATIC_MEMORY
  52135. wolfSSL_Mutex *mm = wc_InitAndAllocMutex();
  52136. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (1)");
  52137. #else
  52138. wolfSSL_Mutex *mm = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex),
  52139. HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52140. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (2)");
  52141. if (mm != NULL) {
  52142. ret = wc_InitMutex(mm);
  52143. if (ret != 0) {
  52144. WOLFSSL_MSG("Init Mutex failed");
  52145. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52146. return WC_TEST_RET_ENC_EC(ret);
  52147. }
  52148. }
  52149. #endif
  52150. if (mm == NULL)
  52151. return WC_TEST_RET_ENC_ERRNO;
  52152. wc_FreeMutex(mm);
  52153. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52154. #endif
  52155. /* Can optionally enable advanced pthread tests using "ENABLE_PTHREAD_LOCKFREE_TESTS" */
  52156. #ifdef WOLFSSL_PTHREADS
  52157. ret = wc_InitMutex(&m);
  52158. if (ret != 0)
  52159. return WC_TEST_RET_ENC_EC(ret);
  52160. ret = wc_LockMutex(&m);
  52161. if (ret != 0)
  52162. return WC_TEST_RET_ENC_EC(ret);
  52163. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  52164. /* trying to free a locked mutex is not portable behavior with pthread */
  52165. /* Attempting to destroy a locked mutex results in undefined behavior */
  52166. ret = wc_FreeMutex(&m);
  52167. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52168. return WC_TEST_RET_ENC_EC(ret);
  52169. #endif
  52170. ret = wc_UnLockMutex(&m);
  52171. if (ret != 0)
  52172. return WC_TEST_RET_ENC_EC(ret);
  52173. ret = wc_FreeMutex(&m);
  52174. if (ret != 0)
  52175. return WC_TEST_RET_ENC_EC(ret);
  52176. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  52177. /* Trying to use a pthread after free'ing is not portable behavior */
  52178. ret = wc_LockMutex(&m);
  52179. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52180. return WC_TEST_RET_ENC_EC(ret);
  52181. ret = wc_UnLockMutex(&m);
  52182. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52183. return WC_TEST_RET_ENC_EC(ret);
  52184. #endif
  52185. #endif
  52186. return 0;
  52187. }
  52188. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  52189. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \
  52190. !defined(WOLFSSL_STATIC_MEMORY)
  52191. static wc_test_ret_t malloc_cnt = 0;
  52192. static wc_test_ret_t realloc_cnt = 0;
  52193. static wc_test_ret_t free_cnt = 0;
  52194. #ifdef WOLFSSL_DEBUG_MEMORY
  52195. static void *my_Malloc_cb(size_t size, const char* func, unsigned int line)
  52196. {
  52197. (void) func;
  52198. (void) line;
  52199. #else
  52200. static void *my_Malloc_cb(size_t size)
  52201. {
  52202. #endif
  52203. malloc_cnt++;
  52204. #ifndef WOLFSSL_NO_MALLOC
  52205. return malloc(size); /* native heap */
  52206. #else
  52207. WOLFSSL_MSG("No malloc available");
  52208. (void)size;
  52209. return NULL;
  52210. #endif
  52211. }
  52212. #ifdef WOLFSSL_DEBUG_MEMORY
  52213. static void my_Free_cb(void *ptr, const char* func, unsigned int line)
  52214. {
  52215. (void) func;
  52216. (void) line;
  52217. #else
  52218. static void my_Free_cb(void *ptr)
  52219. {
  52220. #endif
  52221. free_cnt++;
  52222. #ifndef WOLFSSL_NO_MALLOC
  52223. free(ptr); /* native heap */
  52224. #else
  52225. WOLFSSL_MSG("No free available");
  52226. (void)ptr;
  52227. #endif
  52228. }
  52229. #ifdef WOLFSSL_DEBUG_MEMORY
  52230. static void *my_Realloc_cb(void *ptr, size_t size, const char* func, unsigned int line)
  52231. {
  52232. (void) func;
  52233. (void) line;
  52234. #else
  52235. static void *my_Realloc_cb(void *ptr, size_t size)
  52236. {
  52237. #endif
  52238. realloc_cnt++;
  52239. #ifndef WOLFSSL_NO_MALLOC
  52240. return realloc(ptr, size); /* native heap */
  52241. #else
  52242. WOLFSSL_MSG("No realloc available");
  52243. (void)ptr;
  52244. (void)size;
  52245. return NULL;
  52246. #endif
  52247. }
  52248. #endif /* !WOLFSSL_NO_MALLOC */
  52249. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void)
  52250. {
  52251. wc_test_ret_t ret = 0;
  52252. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52253. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52254. byte* b = NULL;
  52255. #endif
  52256. wolfSSL_Malloc_cb mc;
  52257. wolfSSL_Free_cb fc;
  52258. wolfSSL_Realloc_cb rc;
  52259. WOLFSSL_ENTER("memcb_test");
  52260. /* Save existing memory callbacks */
  52261. ret = wolfSSL_GetAllocators(&mc, &fc, &rc);
  52262. if (ret != 0)
  52263. return WC_TEST_RET_ENC_EC(ret);
  52264. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52265. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52266. /* test realloc */
  52267. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52268. if (b == NULL) {
  52269. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_memcb);
  52270. }
  52271. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52272. b = NULL;
  52273. /* Use API. */
  52274. ret = wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb,
  52275. (wolfSSL_Free_cb)my_Free_cb,
  52276. (wolfSSL_Realloc_cb)my_Realloc_cb);
  52277. if (ret != 0) {
  52278. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_memcb);
  52279. }
  52280. b = (byte*)XMALLOC(1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52281. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52282. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52283. #ifndef WOLFSSL_STATIC_MEMORY
  52284. #ifndef WOLFSSL_CHECK_MEM_ZERO
  52285. if (malloc_cnt != 1 || free_cnt != 1 || realloc_cnt != 1)
  52286. #else
  52287. /* Checking zeroized memory means realloc is a malloc and free. */
  52288. if (malloc_cnt != 2 || free_cnt != 2 || realloc_cnt != 0)
  52289. #endif
  52290. #else
  52291. if (malloc_cnt != 0 || free_cnt != 0 || realloc_cnt != 0)
  52292. #endif
  52293. ret = WC_TEST_RET_ENC_NC;
  52294. #endif /* !WOLFSSL_NO_MALLOC */
  52295. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52296. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52297. exit_memcb:
  52298. /* reset malloc/free/realloc counts */
  52299. malloc_cnt = 0;
  52300. free_cnt = 0;
  52301. realloc_cnt = 0;
  52302. #endif
  52303. /* restore memory callbacks */
  52304. wolfSSL_SetAllocators(mc, fc, rc);
  52305. return ret;
  52306. }
  52307. #endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_NO_MALLOC */
  52308. #if defined(WOLFSSL_CAAM_BLOB)
  52309. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void)
  52310. {
  52311. wc_test_ret_t ret = 0;
  52312. byte out[112];
  52313. byte blob[112];
  52314. word32 outSz;
  52315. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  52316. {
  52317. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  52318. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  52319. };
  52320. WOLFSSL_SMALL_STACK_STATIC const byte text[] =
  52321. {
  52322. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  52323. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  52324. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  52325. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  52326. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  52327. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  52328. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  52329. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  52330. };
  52331. WOLFSSL_ENTER("blob_test");
  52332. XMEMSET(blob, 0, sizeof(blob));
  52333. XMEMSET(out, 0, sizeof(out));
  52334. outSz = sizeof(blob);
  52335. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  52336. if (ret != 0)
  52337. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52338. blob[outSz - 2] += 1;
  52339. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52340. if (ret == 0) { /* should fail with altered blob */
  52341. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52342. }
  52343. XMEMSET(blob, 0, sizeof(blob));
  52344. outSz = sizeof(blob);
  52345. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  52346. if (ret != 0)
  52347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52348. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52349. if (ret != 0)
  52350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52351. if (XMEMCMP(out, iv, sizeof(iv))) {
  52352. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52353. }
  52354. XMEMSET(blob, 0, sizeof(blob));
  52355. outSz = sizeof(blob);
  52356. ret = wc_caamCreateBlob((byte*)text, sizeof(text), blob, &outSz);
  52357. if (ret != 0)
  52358. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52359. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52360. if (ret != 0)
  52361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52362. if (XMEMCMP(out, text, sizeof(text))) {
  52363. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52364. }
  52365. exit_blob:
  52366. return ret;
  52367. }
  52368. #endif /* WOLFSSL_CAAM_BLOB */
  52369. #ifdef WOLF_CRYPTO_CB
  52370. /* Example custom context for crypto callback */
  52371. typedef struct {
  52372. int exampleVar; /* flag for testing if only crypt is enabled. */
  52373. } myCryptoDevCtx;
  52374. #ifdef WOLF_CRYPTO_CB_ONLY_RSA
  52375. /* Testing rsa cb when CB_ONLY_RSA is enabled
  52376. * When CB_ONLY_RSA is enabled, software imple. is not available.
  52377. *
  52378. * ctx callback ctx
  52379. * returen 0 on success, otherwise return negative
  52380. */
  52381. static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
  52382. {
  52383. wc_test_ret_t ret = 0;
  52384. #if !defined(NO_RSA)
  52385. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52386. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key,
  52387. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52388. byte* tmp = NULL;
  52389. #else
  52390. RsaKey key[1];
  52391. byte tmp[FOURK_BUF];
  52392. #endif
  52393. size_t bytes;
  52394. const word32 inLen = (word32)TEST_STRING_SZ;
  52395. word32 idx = 0;
  52396. word32 sigSz;
  52397. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  52398. byte out[RSA_TEST_BYTES];
  52399. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  52400. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  52401. !defined(NO_FILESYSTEM)
  52402. XFILE file;
  52403. #endif
  52404. #ifdef WOLFSSL_KEY_GEN
  52405. WC_RNG rng;
  52406. #endif
  52407. #ifdef USE_CERT_BUFFERS_1024
  52408. bytes = (size_t)sizeof_client_key_der_1024;
  52409. if (bytes < (size_t)sizeof_client_cert_der_1024)
  52410. bytes = (size_t)sizeof_client_cert_der_1024;
  52411. #elif defined(USE_CERT_BUFFERS_2048)
  52412. bytes = (size_t)sizeof_client_key_der_2048;
  52413. if (bytes < (size_t)sizeof_client_cert_der_2048)
  52414. bytes = (size_t)sizeof_client_cert_der_2048;
  52415. #elif defined(USE_CERT_BUFFERS_3072)
  52416. bytes = (size_t)sizeof_client_key_der_3072;
  52417. if (bytes < (size_t)sizeof_client_cert_der_3072)
  52418. bytes = (size_t)sizeof_client_cert_der_3072;
  52419. #elif defined(USE_CERT_BUFFERS_4096)
  52420. bytes = (size_t)sizeof_client_key_der_4096;
  52421. if (bytes < (size_t)sizeof_client_cert_der_4096)
  52422. bytes = (size_t)sizeof_client_cert_der_4096;
  52423. #else
  52424. bytes = FOURK_BUF;
  52425. #endif
  52426. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52427. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52428. if (tmp == NULL)
  52429. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52430. #endif
  52431. #ifdef USE_CERT_BUFFERS_1024
  52432. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  52433. #elif defined(USE_CERT_BUFFERS_2048)
  52434. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  52435. #elif defined(USE_CERT_BUFFERS_3072)
  52436. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  52437. #elif defined(USE_CERT_BUFFERS_4096)
  52438. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  52439. #elif !defined(NO_FILESYSTEM)
  52440. file = XFOPEN(clientKey, "rb");
  52441. if (!file) {
  52442. ret = WC_TEST_RET_ENC_ERRNO;
  52443. err_sys("can't open ./certs/client-key.der, "
  52444. "Please run from wolfSSL home dir", ret);
  52445. ERROR_OUT(ret, exit_onlycb);
  52446. }
  52447. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  52448. XFCLOSE(file);
  52449. if (bytes == 0)
  52450. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52451. #endif
  52452. #ifdef WOLFSSL_KEY_GEN
  52453. /* wc_CryptoCb_MakeRsaKey cb test, no actual making key
  52454. * wc_MakeRsaKey() -> rsa cb ->
  52455. * myCryptoDevCb -> wc_MakeRsaKey(CBONLY_TEST_DEVID)
  52456. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
  52457. */
  52458. ctx->exampleVar = 99;
  52459. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52460. if (ret != 0)
  52461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52462. /* wc_MakeRsaKey() -> rsa cb ->
  52463. * myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
  52464. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
  52465. */
  52466. ctx->exampleVar = 1;
  52467. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52468. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52470. } else
  52471. /* reset return code */
  52472. ret = 0;
  52473. #endif
  52474. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  52475. if (ret != 0)
  52476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52477. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  52478. if (ret != 0)
  52479. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52480. sigSz = (word32)wc_RsaEncryptSize(key);
  52481. /* wc_CryptoCb_Rsa cb test, no actual rsa operation */
  52482. if (ret == 0) {
  52483. /* wc_SignatureGenerate() -> rsa cb ->
  52484. * myCryptoDevCb -> wc_RsaFunction(CBONLY_TEST_DEVID)
  52485. * wc_RsaFunction(CBONLY_TEST_DEVID) expects to return 0(success)
  52486. */
  52487. ctx->exampleVar = 99;
  52488. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52489. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52490. if (ret != 0)
  52491. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52492. }
  52493. if (ret == 0) {
  52494. /* wc_SignatureGenerate() -> rsa cb ->
  52495. * myCryptoDevCb -> wc_RsaFunction(INVALID_DEVID)
  52496. * wc_SignatureGenerate(INVALID_DEVID) expects to
  52497. * return NO_VALID_DEVID(failure)
  52498. */
  52499. ctx->exampleVar = 1;
  52500. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52501. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52502. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52503. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52504. } else
  52505. /* reset return code */
  52506. ret = 0;
  52507. }
  52508. exit_onlycb:
  52509. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52510. if (key != NULL) {
  52511. wc_FreeRsaKey(key);
  52512. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52513. }
  52514. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52515. #else
  52516. wc_FreeRsaKey(key);
  52517. #endif
  52518. #endif
  52519. return ret;
  52520. }
  52521. #endif
  52522. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  52523. /* Testing rsa cb when CB_ONLY_ECC is enabled
  52524. * When CB_ONLY_ECC is enabled, software imple. is not available.
  52525. *
  52526. * ctx callback ctx
  52527. * returen 0 on success, otherwise return negative
  52528. */
  52529. static wc_test_ret_t ecc_onlycb_test(myCryptoDevCtx *ctx)
  52530. {
  52531. wc_test_ret_t ret = 0;
  52532. #if defined(HAVE_ECC)
  52533. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52534. ecc_key* key = (ecc_key *)XMALLOC(sizeof *key,
  52535. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52536. ecc_key* pub = (ecc_key *)XMALLOC(sizeof *pub,
  52537. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52538. byte* out = (byte*)XMALLOC(sizeof(byte),
  52539. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52540. #ifdef OPENSSL_EXTRA
  52541. byte* check = (byte*)XMALLOC(sizeof(byte)*(256), HEAP_HINT,
  52542. DYNAMIC_TYPE_TMP_BUFFER);
  52543. #endif
  52544. #else
  52545. ecc_key key[1];
  52546. ecc_key pub[1];
  52547. byte out[256];
  52548. #ifdef OPENSSL_EXTRA
  52549. unsigned char check[256];
  52550. #endif
  52551. #endif
  52552. #ifdef OPENSSL_EXTRA
  52553. WOLFSSL_EVP_PKEY* privKey = NULL;
  52554. WOLFSSL_EVP_PKEY* pubKey = NULL;
  52555. #ifdef USE_CERT_BUFFERS_256
  52556. ecc_key* pkey;
  52557. const unsigned char* cp;
  52558. #endif
  52559. WOLFSSL_EVP_MD_CTX mdCtx;
  52560. const char testData[] = "Hi There";
  52561. size_t checkSz = -1;
  52562. const unsigned char* p;
  52563. const unsigned char check_v[256] = {
  52564. 0x30,0x45,0x02,0x20,0x1b,0x5c,0x2a,0xf0,0x18,0x09,
  52565. 0x74,0x65,0xa1,0x04,0x76,0x3a,0xce,0xcc,0xe5,0x34,
  52566. 0x5e,0x89,0xed,0x40,0x1e,0x5a,0xb1,0x53,0xb4,0xff,
  52567. 0xc7,0x18,0xfe,0x0f,0xc7,0xa6,0x02,0x21,0x00,0xe5,
  52568. 0x70,0x21,0xfc,0xf9,0x63,0x36,0xfd,0x16,0x18,0x08,
  52569. 0x9a,0x63,0x61,0x0f,0xe7,0x7c,0xa3,0xc9,0x14,0xa3,
  52570. 0x30,0x87,0xf7,0xf5,0x70,0x19,0xaf,0x56,0x96,0x9b,
  52571. 0xd8,0x64,0xcd,0xd9,0xff,0x7b,0x2a,0x55,0x52,0xca,
  52572. 0x41,0xb2,0xa6,0xa4,0x8a,0x3b,0x02,0x20,0x8c,0xc5,
  52573. 0xf9,0xc1,0x7d,0x2a,0x65,0x6c,0xe6,0x5a,0xe3,0x76,
  52574. 0x9b,0xab,0x0b,0x9f,0xaf,0x62,0x5d,0xb2,0x60,0xd7,
  52575. 0xeb,0xb4,0x1b,0x73,0xdc,0x01,0x7d,0x7b,0xab,0xc1,
  52576. 0x0c,0x74,0x96,0x41,0xe6,0x3f,0xc5,0x86,0xe6,0x7d,
  52577. 0x2b,0x9d,0x54,0x6b,0xcd,0x31,0x35,0x1f,0xdb,0x49,
  52578. 0x1f,0x32,0x34,0xf8,0x57,0x12,0x86,0x5c,0x0e,0x80,
  52579. 0x55,0x8d,0xff,0xd8,0xbd,0xdf,0x32,0x26,0x62,0x42,
  52580. 0x09,0xda,0xf7,0x74,0xf2,0x3f,0xe6,0xf1,0x77,0x82,
  52581. 0xce,0xe4,0xbb,0x61,0xa6,0xc0,0x17,0x0c,0x6c,0x47,
  52582. 0x2a,0x40,0x1c,0x2b,0xe0,0x98,0x3b,0xbf,0xc6,0xf8,
  52583. 0x6d,0xfd,0xd0,0xfa,0xc1,0x02,0xfb,0x5f,0xfb,0xb0,
  52584. 0xcb,0xd9,0xa3,0x59,0x94,0xe9,0x0f,0x74,0xbb,0x3f,
  52585. 0x64,0xa3,0x83,0xc4,0x2b,0xf7,0xd2,0x97,0xbf,0x3b,
  52586. 0xcf,0xbb,0x60,0x81,0x33,0x94,0xfa,0x0d,0x35,0xd2,
  52587. 0x3d,0xb9,0x99,0xe3,0x12,0xf8,0xf4,0xa3,0x74,0xf4,
  52588. 0x94,0x1d,0x7a,0x66,0xf8,0xd1,0x1d,0xcf,0xb0,0x48,
  52589. 0xef,0x8c,0x94,0x6f,0xdd,0x62,
  52590. };
  52591. #endif
  52592. WC_RNG rng;
  52593. EncryptedInfo encInfo;
  52594. int keyFormat = 0;
  52595. word32 keyIdx = 0;
  52596. byte in[] = "Everyone gets Friday off. ecc p";
  52597. word32 inLen = (word32)XSTRLEN((char*)in);
  52598. word32 outLen;
  52599. int verify;
  52600. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52601. if (key == NULL || pub == NULL) {
  52602. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52603. }
  52604. #endif
  52605. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  52606. if (ret != 0)
  52607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52608. /* wc_CryptoCb_MakeEccKey cb test, , no actual testing */
  52609. ctx->exampleVar = 99;
  52610. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52611. if (ret != 0)
  52612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52613. ctx->exampleVar = 1;
  52614. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52615. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52616. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52617. } else
  52618. /* reset return code */
  52619. ret = 0;
  52620. #ifdef USE_CERT_BUFFERS_256
  52621. if (ret == 0) {
  52622. /* load ECC private key and perform private transform */
  52623. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &keyIdx,
  52624. key, sizeof_ecc_key_der_256);
  52625. }
  52626. if (ret != 0)
  52627. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52628. /* wc_CryptoCb_EccSign cb test, no actual testing */
  52629. ctx->exampleVar = 99;
  52630. if (ret == 0) {
  52631. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  52632. }
  52633. if (ret != 0)
  52634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52635. ctx->exampleVar = 1;
  52636. if (ret == 0) {
  52637. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  52638. }
  52639. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52641. }
  52642. else
  52643. ret = 0;
  52644. /* wc_CryptoCb_EccVerify cb test, no actual testing */
  52645. ctx->exampleVar = 99;
  52646. if (ret == 0) {
  52647. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, 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_verify_hash(in, inLen, out, outLen, &verify, 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_Ecdh cb test, no actual testing */
  52661. /* make public key for shared secret */
  52662. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  52663. ctx->exampleVar = 99;
  52664. if (ret == 0) {
  52665. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52666. }
  52667. if (ret != 0)
  52668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52669. ctx->exampleVar = 1;
  52670. if (ret == 0) {
  52671. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52672. }
  52673. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52674. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52675. }
  52676. else
  52677. ret = 0;
  52678. #ifdef OPENSSL_EXTRA
  52679. (void)pkey;
  52680. cp = ecc_clikey_der_256;
  52681. privKey = d2i_PrivateKey(WC_EVP_PKEY_EC, NULL, &cp,
  52682. sizeof_ecc_clikey_der_256);
  52683. if (privKey == NULL) {
  52684. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52685. }
  52686. pkey = (ecc_key*)privKey->ecc->internal;
  52687. pkey->devId = devId;
  52688. p = ecc_clikeypub_der_256;
  52689. pubKey = d2i_PUBKEY(NULL, &p, sizeof_ecc_clikeypub_der_256);
  52690. if (pubKey == NULL) {
  52691. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52692. }
  52693. pkey = (ecc_key*)pubKey->ecc->internal;
  52694. pkey->devId = devId;
  52695. /* sign */
  52696. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52697. ret = EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, privKey);
  52698. if (ret != WOLFSSL_SUCCESS) {
  52699. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52700. }
  52701. ret = EVP_DigestSignUpdate(&mdCtx, testData,
  52702. (unsigned int)XSTRLEN(testData));
  52703. if (ret != WOLFSSL_SUCCESS) {
  52704. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52705. }
  52706. ret = EVP_DigestSignFinal(&mdCtx, NULL, &checkSz);
  52707. if (ret != WOLFSSL_SUCCESS) {
  52708. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52709. }
  52710. ctx->exampleVar = 99;
  52711. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52712. /* just called crypt callback as dummy
  52713. * EVP_DigestSignFinal returns 0 internally.
  52714. */
  52715. if (ret != 0)
  52716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52717. ctx->exampleVar = 1;
  52718. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52719. /* just called crypt callback as dummy
  52720. * EVP_DigestSignFinal returns 0 internally.
  52721. */
  52722. if (ret != 0)
  52723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52724. /* restore checkSz for verify */
  52725. checkSz = 71;
  52726. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52727. if (ret != WOLFSSL_SUCCESS) {
  52728. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52729. }
  52730. /* verify */
  52731. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52732. if (ret == WOLFSSL_SUCCESS) {
  52733. ret = EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, pubKey);
  52734. }
  52735. if (ret != WOLFSSL_SUCCESS) {
  52736. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52737. }
  52738. if (ret == WOLFSSL_SUCCESS) {
  52739. ret = EVP_DigestVerifyUpdate(&mdCtx, testData,
  52740. (unsigned int)XSTRLEN(testData));
  52741. }
  52742. if (ret != WOLFSSL_SUCCESS) {
  52743. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52744. }
  52745. ctx->exampleVar = 99;
  52746. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52747. /* just called crypt callback as dummy
  52748. * EVP_DigestSignFinal returns 0 internally.
  52749. */
  52750. if (ret != 0)
  52751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52752. ctx->exampleVar = 1;
  52753. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52754. /* just called crypt callback as dummy
  52755. * EVP_DigestVerifyFinal returns -1 internally rather than NO_VALID_DEVID.
  52756. */
  52757. if (ret != -1) {
  52758. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52759. }
  52760. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52761. if (ret != WOLFSSL_SUCCESS) {
  52762. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52763. } else
  52764. ret = 0;
  52765. #endif
  52766. #else
  52767. (void)verify;
  52768. (void)outLen;
  52769. (void)inLen;
  52770. (void)out;
  52771. (void)pub;
  52772. #ifdef OPENSSL_EXTRA
  52773. (void)privKey;
  52774. (void)pubKey;
  52775. (void)mdCtx;
  52776. (void)check;
  52777. (void)checkSz;
  52778. (void)p;
  52779. #endif
  52780. #endif
  52781. (void)keyFormat;
  52782. (void)encInfo;
  52783. exit_onlycb:
  52784. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52785. if (key != NULL) {
  52786. wc_ecc_free(key);
  52787. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52788. }
  52789. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52790. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52791. #ifdef OPENSSL_EXTRA
  52792. if (check) {
  52793. FREE(check, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52794. }
  52795. #endif
  52796. #else
  52797. wc_ecc_free(key);
  52798. #ifdef OPENSSL_EXTRA
  52799. if (privKey)
  52800. wolfSSL_EVP_PKEY_free(privKey);
  52801. if (pubKey)
  52802. wolfSSL_EVP_PKEY_free(pubKey);
  52803. #endif
  52804. #endif
  52805. #endif /* HAVE_ECC */
  52806. return ret;
  52807. }
  52808. #endif
  52809. /* Example crypto dev callback function that calls software version */
  52810. static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
  52811. {
  52812. int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN); /* return this to bypass HW and
  52813. use SW */
  52814. myCryptoDevCtx* myCtx = (myCryptoDevCtx*)ctx;
  52815. if (info == NULL)
  52816. return BAD_FUNC_ARG;
  52817. #ifdef DEBUG_WOLFSSL
  52818. WOLFSSL_MSG_EX("CryptoDevCb: Algo Type %d\n", info->algo_type);
  52819. #endif
  52820. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  52821. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  52822. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  52823. /* if RNG only supports crypto callback, just use seed */
  52824. ret = wc_GenerateSeed(&info->rng.rng->seed,
  52825. info->rng.out, info->rng.sz);
  52826. #elif !defined(WC_NO_RNG)
  52827. /* set devId to invalid, so software is used */
  52828. info->rng.rng->devId = INVALID_DEVID;
  52829. ret = wc_RNG_GenerateBlock(info->rng.rng,
  52830. info->rng.out, info->rng.sz);
  52831. /* reset devId */
  52832. info->rng.rng->devId = devIdArg;
  52833. #endif
  52834. }
  52835. else if (info->algo_type == WC_ALGO_TYPE_SEED) {
  52836. #ifndef WC_NO_RNG
  52837. ALIGN32 static byte seed[sizeof(word32)] = { 0x00, 0x00, 0x00, 0x01 };
  52838. word32* seedWord32 = (word32*)seed;
  52839. word32 len;
  52840. /* wc_GenerateSeed is a local symbol so we need to fake the entropy. */
  52841. while (info->seed.sz > 0) {
  52842. len = (word32)sizeof(seed);
  52843. if (info->seed.sz < len)
  52844. len = info->seed.sz;
  52845. XMEMCPY(info->seed.seed, seed, sizeof(seed));
  52846. info->seed.seed += len;
  52847. info->seed.sz -= len;
  52848. (*seedWord32)++;
  52849. }
  52850. ret = 0;
  52851. #endif
  52852. }
  52853. else if (info->algo_type == WC_ALGO_TYPE_PK) {
  52854. #ifdef DEBUG_WOLFSSL
  52855. WOLFSSL_MSG_EX("CryptoDevCb: Pk Type %d\n", info->pk.type);
  52856. #endif
  52857. #ifndef NO_RSA
  52858. if (info->pk.type == WC_PK_TYPE_RSA) {
  52859. /* set devId to invalid, so software is used */
  52860. info->pk.rsa.key->devId = INVALID_DEVID;
  52861. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52862. #ifdef DEBUG_WOLFSSL
  52863. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52864. #endif
  52865. if (myCtx->exampleVar == 99) {
  52866. info->pk.rsa.key->devId = devIdArg;
  52867. return 0;
  52868. }
  52869. #endif
  52870. switch (info->pk.rsa.type) {
  52871. case RSA_PUBLIC_ENCRYPT:
  52872. case RSA_PUBLIC_DECRYPT:
  52873. /* perform software based RSA public op */
  52874. ret = wc_RsaFunction(
  52875. info->pk.rsa.in, info->pk.rsa.inLen,
  52876. info->pk.rsa.out, info->pk.rsa.outLen,
  52877. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52878. break;
  52879. case RSA_PRIVATE_ENCRYPT:
  52880. case RSA_PRIVATE_DECRYPT:
  52881. /* perform software based RSA private op */
  52882. ret = wc_RsaFunction(
  52883. info->pk.rsa.in, info->pk.rsa.inLen,
  52884. info->pk.rsa.out, info->pk.rsa.outLen,
  52885. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52886. break;
  52887. }
  52888. /* reset devId */
  52889. info->pk.rsa.key->devId = devIdArg;
  52890. }
  52891. #ifdef WOLFSSL_KEY_GEN
  52892. else if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN) {
  52893. info->pk.rsakg.key->devId = INVALID_DEVID;
  52894. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52895. #ifdef DEBUG_WOLFSSL
  52896. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52897. #endif
  52898. if (myCtx->exampleVar == 99) {
  52899. info->pk.rsakg.key->devId = devIdArg;
  52900. return 0;
  52901. }
  52902. #endif
  52903. #ifdef HAVE_FIPS
  52904. for (;;) {
  52905. #endif
  52906. ret = wc_MakeRsaKey(info->pk.rsakg.key, info->pk.rsakg.size,
  52907. info->pk.rsakg.e, info->pk.rsakg.rng);
  52908. #ifdef HAVE_FIPS
  52909. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  52910. continue;
  52911. break;
  52912. }
  52913. #endif
  52914. /* reset devId */
  52915. info->pk.rsakg.key->devId = devIdArg;
  52916. }
  52917. #endif
  52918. #endif /* !NO_RSA */
  52919. #ifdef HAVE_ECC
  52920. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  52921. /* set devId to invalid, so software is used */
  52922. info->pk.eckg.key->devId = INVALID_DEVID;
  52923. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52924. #ifdef DEBUG_WOLFSSL
  52925. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52926. #endif
  52927. if (myCtx->exampleVar == 99) {
  52928. info->pk.eckg.key->devId = devIdArg;
  52929. return 0;
  52930. }
  52931. #endif
  52932. ret = wc_ecc_make_key_ex(info->pk.eckg.rng, info->pk.eckg.size,
  52933. info->pk.eckg.key, info->pk.eckg.curveId);
  52934. /* reset devId */
  52935. info->pk.eckg.key->devId = devIdArg;
  52936. }
  52937. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  52938. /* set devId to invalid, so software is used */
  52939. info->pk.eccsign.key->devId = INVALID_DEVID;
  52940. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52941. #ifdef DEBUG_WOLFSSL
  52942. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52943. #endif
  52944. if (myCtx->exampleVar == 99) {
  52945. info->pk.eccsign.key->devId = devIdArg;
  52946. return 0;
  52947. }
  52948. #endif
  52949. ret = wc_ecc_sign_hash(
  52950. info->pk.eccsign.in, info->pk.eccsign.inlen,
  52951. info->pk.eccsign.out, info->pk.eccsign.outlen,
  52952. info->pk.eccsign.rng, info->pk.eccsign.key);
  52953. /* reset devId */
  52954. info->pk.eccsign.key->devId = devIdArg;
  52955. }
  52956. else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
  52957. /* set devId to invalid, so software is used */
  52958. info->pk.eccverify.key->devId = INVALID_DEVID;
  52959. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52960. #ifdef DEBUG_WOLFSSL
  52961. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52962. #endif
  52963. if (myCtx->exampleVar == 99) {
  52964. info->pk.eccverify.key->devId = devIdArg;
  52965. return 0;
  52966. }
  52967. #endif
  52968. ret = wc_ecc_verify_hash(
  52969. info->pk.eccverify.sig, info->pk.eccverify.siglen,
  52970. info->pk.eccverify.hash, info->pk.eccverify.hashlen,
  52971. info->pk.eccverify.res, info->pk.eccverify.key);
  52972. /* reset devId */
  52973. info->pk.eccverify.key->devId = devIdArg;
  52974. }
  52975. else if (info->pk.type == WC_PK_TYPE_ECDH) {
  52976. /* set devId to invalid, so software is used */
  52977. info->pk.ecdh.private_key->devId = INVALID_DEVID;
  52978. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52979. #ifdef DEBUG_WOLFSSL
  52980. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52981. #endif
  52982. if (myCtx->exampleVar == 99) {
  52983. info->pk.ecdh.private_key->devId = devIdArg;
  52984. return 0;
  52985. }
  52986. #endif
  52987. ret = wc_ecc_shared_secret(
  52988. info->pk.ecdh.private_key, info->pk.ecdh.public_key,
  52989. info->pk.ecdh.out, info->pk.ecdh.outlen);
  52990. /* reset devId */
  52991. info->pk.ecdh.private_key->devId = devIdArg;
  52992. }
  52993. #endif /* HAVE_ECC */
  52994. #ifdef HAVE_CURVE25519
  52995. if (info->pk.type == WC_PK_TYPE_CURVE25519_KEYGEN) {
  52996. /* set devId to invalid, so software is used */
  52997. info->pk.curve25519kg.key->devId = INVALID_DEVID;
  52998. ret = wc_curve25519_make_key(info->pk.curve25519kg.rng,
  52999. info->pk.curve25519kg.size, info->pk.curve25519kg.key);
  53000. /* reset devId */
  53001. info->pk.curve25519kg.key->devId = devIdArg;
  53002. }
  53003. else if (info->pk.type == WC_PK_TYPE_CURVE25519) {
  53004. /* set devId to invalid, so software is used */
  53005. info->pk.curve25519.private_key->devId = INVALID_DEVID;
  53006. ret = wc_curve25519_shared_secret_ex(
  53007. info->pk.curve25519.private_key, info->pk.curve25519.public_key,
  53008. info->pk.curve25519.out, info->pk.curve25519.outlen,
  53009. info->pk.curve25519.endian);
  53010. /* reset devId */
  53011. info->pk.curve25519.private_key->devId = devIdArg;
  53012. }
  53013. #endif /* HAVE_CURVE25519 */
  53014. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  53015. if (info->pk.type == WC_PK_TYPE_ED25519_KEYGEN) {
  53016. /* set devId to invalid, so software is used */
  53017. info->pk.ed25519kg.key->devId = INVALID_DEVID;
  53018. ret = wc_ed25519_make_key(info->pk.ed25519kg.rng,
  53019. info->pk.ed25519kg.size, info->pk.ed25519kg.key);
  53020. /* reset devId */
  53021. info->pk.ed25519kg.key->devId = devIdArg;
  53022. }
  53023. #ifdef HAVE_ED25519_SIGN
  53024. else if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  53025. /* set devId to invalid, so software is used */
  53026. info->pk.ed25519sign.key->devId = INVALID_DEVID;
  53027. ret = wc_ed25519_sign_msg_ex(
  53028. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  53029. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  53030. info->pk.ed25519sign.key, info->pk.ed25519sign.type,
  53031. info->pk.ed25519sign.context, info->pk.ed25519sign.contextLen);
  53032. /* reset devId */
  53033. info->pk.ed25519sign.key->devId = devIdArg;
  53034. }
  53035. #endif
  53036. #ifdef HAVE_ED25519_VERIFY
  53037. else if (info->pk.type == WC_PK_TYPE_ED25519_VERIFY) {
  53038. /* set devId to invalid, so software is used */
  53039. info->pk.ed25519verify.key->devId = INVALID_DEVID;
  53040. ret = wc_ed25519_verify_msg_ex(
  53041. info->pk.ed25519verify.sig, info->pk.ed25519verify.sigLen,
  53042. info->pk.ed25519verify.msg, info->pk.ed25519verify.msgLen,
  53043. info->pk.ed25519verify.res, info->pk.ed25519verify.key,
  53044. info->pk.ed25519verify.type, info->pk.ed25519verify.context,
  53045. info->pk.ed25519verify.contextLen);
  53046. /* reset devId */
  53047. info->pk.ed25519verify.key->devId = devIdArg;
  53048. }
  53049. #endif
  53050. #endif /* HAVE_ED25519 */
  53051. }
  53052. else if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
  53053. #if !defined(NO_AES) || !defined(NO_DES3)
  53054. #ifdef HAVE_AESGCM
  53055. if (info->cipher.type == WC_CIPHER_AES_GCM) {
  53056. if (info->cipher.enc) {
  53057. /* set devId to invalid, so software is used */
  53058. info->cipher.aesgcm_enc.aes->devId = INVALID_DEVID;
  53059. ret = wc_AesGcmEncrypt(
  53060. info->cipher.aesgcm_enc.aes,
  53061. info->cipher.aesgcm_enc.out,
  53062. info->cipher.aesgcm_enc.in,
  53063. info->cipher.aesgcm_enc.sz,
  53064. info->cipher.aesgcm_enc.iv,
  53065. info->cipher.aesgcm_enc.ivSz,
  53066. info->cipher.aesgcm_enc.authTag,
  53067. info->cipher.aesgcm_enc.authTagSz,
  53068. info->cipher.aesgcm_enc.authIn,
  53069. info->cipher.aesgcm_enc.authInSz);
  53070. /* reset devId */
  53071. info->cipher.aesgcm_enc.aes->devId = devIdArg;
  53072. }
  53073. else {
  53074. /* set devId to invalid, so software is used */
  53075. info->cipher.aesgcm_dec.aes->devId = INVALID_DEVID;
  53076. ret = wc_AesGcmDecrypt(
  53077. info->cipher.aesgcm_dec.aes,
  53078. info->cipher.aesgcm_dec.out,
  53079. info->cipher.aesgcm_dec.in,
  53080. info->cipher.aesgcm_dec.sz,
  53081. info->cipher.aesgcm_dec.iv,
  53082. info->cipher.aesgcm_dec.ivSz,
  53083. info->cipher.aesgcm_dec.authTag,
  53084. info->cipher.aesgcm_dec.authTagSz,
  53085. info->cipher.aesgcm_dec.authIn,
  53086. info->cipher.aesgcm_dec.authInSz);
  53087. /* reset devId */
  53088. info->cipher.aesgcm_dec.aes->devId = devIdArg;
  53089. }
  53090. }
  53091. #endif /* HAVE_AESGCM */
  53092. #ifdef HAVE_AES_CBC
  53093. if (info->cipher.type == WC_CIPHER_AES_CBC) {
  53094. if (info->cipher.enc) {
  53095. /* set devId to invalid, so software is used */
  53096. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  53097. ret = wc_AesCbcEncrypt(
  53098. info->cipher.aescbc.aes,
  53099. info->cipher.aescbc.out,
  53100. info->cipher.aescbc.in,
  53101. info->cipher.aescbc.sz);
  53102. /* reset devId */
  53103. info->cipher.aescbc.aes->devId = devIdArg;
  53104. }
  53105. else {
  53106. /* set devId to invalid, so software is used */
  53107. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  53108. ret = wc_AesCbcDecrypt(
  53109. info->cipher.aescbc.aes,
  53110. info->cipher.aescbc.out,
  53111. info->cipher.aescbc.in,
  53112. info->cipher.aescbc.sz);
  53113. /* reset devId */
  53114. info->cipher.aescbc.aes->devId = devIdArg;
  53115. }
  53116. }
  53117. #endif /* HAVE_AES_CBC */
  53118. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  53119. if (info->cipher.type == WC_CIPHER_AES_ECB) {
  53120. if (info->cipher.enc) {
  53121. /* set devId to invalid, so software is used */
  53122. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  53123. ret = wc_AesEcbEncrypt(
  53124. info->cipher.aesecb.aes,
  53125. info->cipher.aesecb.out,
  53126. info->cipher.aesecb.in,
  53127. info->cipher.aesecb.sz);
  53128. /* reset devId */
  53129. info->cipher.aesecb.aes->devId = devIdArg;
  53130. }
  53131. else {
  53132. /* set devId to invalid, so software is used */
  53133. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  53134. ret = wc_AesEcbDecrypt(
  53135. info->cipher.aesecb.aes,
  53136. info->cipher.aesecb.out,
  53137. info->cipher.aesecb.in,
  53138. info->cipher.aesecb.sz);
  53139. /* reset devId */
  53140. info->cipher.aesecb.aes->devId = devIdArg;
  53141. }
  53142. }
  53143. #endif /* HAVE_AES_ECB */
  53144. #if defined(WOLFSSL_AES_COUNTER) && !defined(HAVE_FIPS) && \
  53145. !defined(HAVE_SELFTEST)
  53146. if (info->cipher.type == WC_CIPHER_AES_CTR) {
  53147. /* set devId to invalid, so software is used */
  53148. info->cipher.aesctr.aes->devId = INVALID_DEVID;
  53149. ret = wc_AesCtrEncrypt(
  53150. info->cipher.aesctr.aes,
  53151. info->cipher.aesctr.out,
  53152. info->cipher.aesctr.in,
  53153. info->cipher.aesctr.sz);
  53154. /* reset devId */
  53155. info->cipher.aesctr.aes->devId = devIdArg;
  53156. }
  53157. #endif /* WOLFSSL_AES_COUNTER */
  53158. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53159. if (info->cipher.type == WC_CIPHER_AES_CCM) {
  53160. if (info->cipher.enc) {
  53161. /* set devId to invalid, so software is used */
  53162. info->cipher.aesccm_enc.aes->devId = INVALID_DEVID;
  53163. ret = wc_AesCcmEncrypt(
  53164. info->cipher.aesccm_enc.aes,
  53165. info->cipher.aesccm_enc.out,
  53166. info->cipher.aesccm_enc.in,
  53167. info->cipher.aesccm_enc.sz,
  53168. info->cipher.aesccm_enc.nonce,
  53169. info->cipher.aesccm_enc.nonceSz,
  53170. info->cipher.aesccm_enc.authTag,
  53171. info->cipher.aesccm_enc.authTagSz,
  53172. info->cipher.aesccm_enc.authIn,
  53173. info->cipher.aesccm_enc.authInSz);
  53174. /* reset devId */
  53175. info->cipher.aesccm_enc.aes->devId = devIdArg;
  53176. }
  53177. else {
  53178. /* set devId to invalid, so software is used */
  53179. info->cipher.aesccm_dec.aes->devId = INVALID_DEVID;
  53180. ret = wc_AesCcmDecrypt(
  53181. info->cipher.aesccm_dec.aes,
  53182. info->cipher.aesccm_dec.out,
  53183. info->cipher.aesccm_dec.in,
  53184. info->cipher.aesccm_dec.sz,
  53185. info->cipher.aesccm_dec.nonce,
  53186. info->cipher.aesccm_dec.nonceSz,
  53187. info->cipher.aesccm_dec.authTag,
  53188. info->cipher.aesccm_dec.authTagSz,
  53189. info->cipher.aesccm_dec.authIn,
  53190. info->cipher.aesccm_dec.authInSz);
  53191. /* reset devId */
  53192. info->cipher.aesccm_dec.aes->devId = devIdArg;
  53193. }
  53194. }
  53195. #endif
  53196. #ifndef NO_DES3
  53197. if (info->cipher.type == WC_CIPHER_DES3) {
  53198. if (info->cipher.enc) {
  53199. /* set devId to invalid, so software is used */
  53200. info->cipher.des3.des->devId = INVALID_DEVID;
  53201. ret = wc_Des3_CbcEncrypt(
  53202. info->cipher.des3.des,
  53203. info->cipher.des3.out,
  53204. info->cipher.des3.in,
  53205. info->cipher.des3.sz);
  53206. /* reset devId */
  53207. info->cipher.des3.des->devId = devIdArg;
  53208. }
  53209. else {
  53210. /* set devId to invalid, so software is used */
  53211. info->cipher.des3.des->devId = INVALID_DEVID;
  53212. ret = wc_Des3_CbcDecrypt(
  53213. info->cipher.des3.des,
  53214. info->cipher.des3.out,
  53215. info->cipher.des3.in,
  53216. info->cipher.des3.sz);
  53217. /* reset devId */
  53218. info->cipher.des3.des->devId = devIdArg;
  53219. }
  53220. }
  53221. #endif /* !NO_DES3 */
  53222. #endif /* !NO_AES || !NO_DES3 */
  53223. }
  53224. #if !defined(NO_SHA) || !defined(NO_SHA256) || \
  53225. defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
  53226. else if (info->algo_type == WC_ALGO_TYPE_HASH) {
  53227. #if !defined(NO_SHA)
  53228. if (info->hash.type == WC_HASH_TYPE_SHA) {
  53229. if (info->hash.sha1 == NULL)
  53230. return NOT_COMPILED_IN;
  53231. /* set devId to invalid, so software is used */
  53232. info->hash.sha1->devId = INVALID_DEVID;
  53233. if (info->hash.in != NULL) {
  53234. ret = wc_ShaUpdate(
  53235. info->hash.sha1,
  53236. info->hash.in,
  53237. info->hash.inSz);
  53238. }
  53239. if (info->hash.digest != NULL) {
  53240. ret = wc_ShaFinal(
  53241. info->hash.sha1,
  53242. info->hash.digest);
  53243. }
  53244. /* reset devId */
  53245. info->hash.sha1->devId = devIdArg;
  53246. }
  53247. else
  53248. #endif
  53249. #if !defined(NO_SHA256)
  53250. if (info->hash.type == WC_HASH_TYPE_SHA256) {
  53251. if (info->hash.sha256 == NULL)
  53252. return NOT_COMPILED_IN;
  53253. /* set devId to invalid, so software is used */
  53254. info->hash.sha256->devId = INVALID_DEVID;
  53255. if (info->hash.in != NULL) {
  53256. ret = wc_Sha256Update(
  53257. info->hash.sha256,
  53258. info->hash.in,
  53259. info->hash.inSz);
  53260. }
  53261. if (info->hash.digest != NULL) {
  53262. ret = wc_Sha256Final(
  53263. info->hash.sha256,
  53264. info->hash.digest);
  53265. }
  53266. /* reset devId */
  53267. info->hash.sha256->devId = devIdArg;
  53268. }
  53269. else
  53270. #endif
  53271. #ifdef WOLFSSL_SHA384
  53272. if (info->hash.type == WC_HASH_TYPE_SHA384) {
  53273. if (info->hash.sha384 == NULL)
  53274. return NOT_COMPILED_IN;
  53275. #ifndef NO_SHA2_CRYPTO_CB
  53276. /* set devId to invalid, so software is used */
  53277. info->hash.sha384->devId = INVALID_DEVID;
  53278. #endif
  53279. if (info->hash.in != NULL) {
  53280. ret = wc_Sha384Update(
  53281. info->hash.sha384,
  53282. info->hash.in,
  53283. info->hash.inSz);
  53284. }
  53285. if (info->hash.digest != NULL) {
  53286. ret = wc_Sha384Final(
  53287. info->hash.sha384,
  53288. info->hash.digest);
  53289. }
  53290. #ifndef NO_SHA2_CRYPTO_CB
  53291. /* reset devId */
  53292. info->hash.sha384->devId = devIdArg;
  53293. #endif
  53294. }
  53295. else
  53296. #endif
  53297. #ifdef WOLFSSL_SHA512
  53298. if (info->hash.type == WC_HASH_TYPE_SHA512) {
  53299. if (info->hash.sha512 == NULL)
  53300. return NOT_COMPILED_IN;
  53301. #ifndef NO_SHA2_CRYPTO_CB
  53302. /* set devId to invalid, so software is used */
  53303. info->hash.sha512->devId = INVALID_DEVID;
  53304. #endif
  53305. if (info->hash.in != NULL) {
  53306. ret = wc_Sha512Update(
  53307. info->hash.sha512,
  53308. info->hash.in,
  53309. info->hash.inSz);
  53310. }
  53311. if (info->hash.digest != NULL) {
  53312. ret = wc_Sha512Final(
  53313. info->hash.sha512,
  53314. info->hash.digest);
  53315. }
  53316. #ifndef NO_SHA2_CRYPTO_CB
  53317. /* reset devId */
  53318. info->hash.sha512->devId = devIdArg;
  53319. #endif
  53320. }
  53321. else
  53322. #endif
  53323. #if defined(WOLFSSL_SHA3) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0))
  53324. if (info->hash.type == WC_HASH_TYPE_SHA3_224) {
  53325. if (info->hash.sha3 == NULL)
  53326. return NOT_COMPILED_IN;
  53327. /* set devId to invalid, so software is used */
  53328. info->hash.sha3->devId = INVALID_DEVID;
  53329. if (info->hash.in != NULL) {
  53330. ret = wc_Sha3_224_Update(
  53331. info->hash.sha3,
  53332. info->hash.in,
  53333. info->hash.inSz);
  53334. }
  53335. if (info->hash.digest != NULL) {
  53336. ret = wc_Sha3_224_Final(
  53337. info->hash.sha3,
  53338. info->hash.digest);
  53339. }
  53340. /* reset devId */
  53341. info->hash.sha3->devId = devIdArg;
  53342. }
  53343. else if (info->hash.type == WC_HASH_TYPE_SHA3_256) {
  53344. if (info->hash.sha3 == NULL)
  53345. return NOT_COMPILED_IN;
  53346. /* set devId to invalid, so software is used */
  53347. info->hash.sha3->devId = INVALID_DEVID;
  53348. if (info->hash.in != NULL) {
  53349. ret = wc_Sha3_256_Update(
  53350. info->hash.sha3,
  53351. info->hash.in,
  53352. info->hash.inSz);
  53353. }
  53354. if (info->hash.digest != NULL) {
  53355. ret = wc_Sha3_256_Final(
  53356. info->hash.sha3,
  53357. info->hash.digest);
  53358. }
  53359. /* reset devId */
  53360. info->hash.sha3->devId = devIdArg;
  53361. }
  53362. else if (info->hash.type == WC_HASH_TYPE_SHA3_384) {
  53363. if (info->hash.sha3 == NULL)
  53364. return NOT_COMPILED_IN;
  53365. /* set devId to invalid, so software is used */
  53366. info->hash.sha3->devId = INVALID_DEVID;
  53367. if (info->hash.in != NULL) {
  53368. ret = wc_Sha3_384_Update(
  53369. info->hash.sha3,
  53370. info->hash.in,
  53371. info->hash.inSz);
  53372. }
  53373. if (info->hash.digest != NULL) {
  53374. ret = wc_Sha3_384_Final(
  53375. info->hash.sha3,
  53376. info->hash.digest);
  53377. }
  53378. /* reset devId */
  53379. info->hash.sha3->devId = devIdArg;
  53380. }
  53381. else if (info->hash.type == WC_HASH_TYPE_SHA3_512) {
  53382. if (info->hash.sha3 == NULL)
  53383. return NOT_COMPILED_IN;
  53384. /* set devId to invalid, so software is used */
  53385. info->hash.sha3->devId = INVALID_DEVID;
  53386. if (info->hash.in != NULL) {
  53387. ret = wc_Sha3_512_Update(
  53388. info->hash.sha3,
  53389. info->hash.in,
  53390. info->hash.inSz);
  53391. }
  53392. if (info->hash.digest != NULL) {
  53393. ret = wc_Sha3_512_Final(
  53394. info->hash.sha3,
  53395. info->hash.digest);
  53396. }
  53397. /* reset devId */
  53398. info->hash.sha3->devId = devIdArg;
  53399. }
  53400. else
  53401. #endif
  53402. {
  53403. }
  53404. }
  53405. #endif /* !NO_SHA || !NO_SHA256 */
  53406. #ifndef NO_HMAC
  53407. else if (info->algo_type == WC_ALGO_TYPE_HMAC) {
  53408. if (info->hmac.hmac == NULL)
  53409. return NOT_COMPILED_IN;
  53410. /* set devId to invalid, so software is used */
  53411. info->hmac.hmac->devId = INVALID_DEVID;
  53412. if (info->hmac.in != NULL) {
  53413. ret = wc_HmacUpdate(
  53414. info->hmac.hmac,
  53415. info->hmac.in,
  53416. info->hmac.inSz);
  53417. }
  53418. else if (info->hmac.digest != NULL) {
  53419. ret = wc_HmacFinal(
  53420. info->hmac.hmac,
  53421. info->hmac.digest);
  53422. }
  53423. /* reset devId */
  53424. info->hmac.hmac->devId = devIdArg;
  53425. }
  53426. #endif
  53427. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53428. else if (info->algo_type == WC_ALGO_TYPE_CMAC) {
  53429. if (info->cmac.cmac == NULL) {
  53430. return NOT_COMPILED_IN;
  53431. }
  53432. /* set devId to invalid so software is used */
  53433. info->cmac.cmac->devId = INVALID_DEVID;
  53434. /* Handle one-shot cases */
  53435. if (info->cmac.key != NULL && info->cmac.in != NULL
  53436. && info->cmac.out != NULL) {
  53437. ret = wc_AesCmacGenerate(info->cmac.out,
  53438. info->cmac.outSz,
  53439. info->cmac.in,
  53440. info->cmac.inSz,
  53441. info->cmac.key,
  53442. info->cmac.keySz);
  53443. /* Sequentially handle incremental cases */
  53444. } else {
  53445. if (info->cmac.key != NULL) {
  53446. ret = wc_InitCmac(info->cmac.cmac,
  53447. info->cmac.key,
  53448. info->cmac.keySz,
  53449. info->cmac.type,
  53450. NULL);
  53451. }
  53452. if ((ret == 0) && (info->cmac.in != NULL)) {
  53453. ret = wc_CmacUpdate(info->cmac.cmac,
  53454. info->cmac.in,
  53455. info->cmac.inSz);
  53456. }
  53457. if ((ret ==0) && (info->cmac.out != NULL)) {
  53458. ret = wc_CmacFinal(info->cmac.cmac,
  53459. info->cmac.out,
  53460. info->cmac.outSz);
  53461. }
  53462. }
  53463. /* reset devId */
  53464. info->cmac.cmac->devId = devIdArg;
  53465. }
  53466. #endif /* WOLFSSL_CMAC && !(NO_AES) && WOLFSSL_AES_DIRECT */
  53467. (void)devIdArg;
  53468. (void)myCtx;
  53469. return ret;
  53470. }
  53471. #ifdef WOLF_CRYPTO_CB_FIND
  53472. static int myCryptoCbFind(int currentId, int algoType)
  53473. {
  53474. /* can have algo specific overrides here
  53475. switch (algoType) {
  53476. i.e.
  53477. WC_ALGO_TYPE_CMAC
  53478. WC_ALGO_TYPE_SEED
  53479. WC_ALGO_TYPE_HMAC
  53480. WC_ALGO_TYPE_HASH
  53481. WC_ALGO_TYPE_CIPHER
  53482. WC_ALGO_TYPE_PK
  53483. }
  53484. */
  53485. (void)algoType;
  53486. if (currentId == INVALID_DEVID) {
  53487. /* can override invalid devid found with 1 */
  53488. }
  53489. return currentId;
  53490. }
  53491. #endif /* WOLF_CRYPTO_CB_FIND */
  53492. #if !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  53493. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void)
  53494. {
  53495. wc_test_ret_t ret = 0;
  53496. int origDevId = devId;
  53497. myCryptoDevCtx myCtx;
  53498. WOLFSSL_ENTER("cryptocb_test");
  53499. /* example data for callback */
  53500. myCtx.exampleVar = 1;
  53501. /* set devId to something other than INVALID_DEVID */
  53502. devId = 1;
  53503. ret = wc_CryptoCb_RegisterDevice(devId, myCryptoDevCb, &myCtx);
  53504. #ifdef WOLF_CRYPTO_CB_FIND
  53505. wc_CryptoCb_SetDeviceFindCb(myCryptoCbFind);
  53506. #endif /* WOLF_CRYPTO_CB_FIND */
  53507. #ifndef WC_NO_RNG
  53508. if (ret == 0)
  53509. ret = random_test();
  53510. #endif /* WC_NO_RNG */
  53511. #if !defined(NO_RSA)
  53512. PRIVATE_KEY_UNLOCK();
  53513. if (ret == 0)
  53514. ret = rsa_test();
  53515. PRIVATE_KEY_LOCK();
  53516. #endif
  53517. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  53518. PRIVATE_KEY_UNLOCK();
  53519. if (ret == 0)
  53520. ret = rsa_onlycb_test(&myCtx);
  53521. PRIVATE_KEY_LOCK();
  53522. #endif
  53523. #if defined(HAVE_ECC)
  53524. PRIVATE_KEY_UNLOCK();
  53525. if (ret == 0)
  53526. ret = ecc_test();
  53527. PRIVATE_KEY_LOCK();
  53528. #endif
  53529. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  53530. PRIVATE_KEY_UNLOCK();
  53531. if (ret == 0)
  53532. ret = ecc_onlycb_test(&myCtx);
  53533. PRIVATE_KEY_LOCK();
  53534. #endif
  53535. #ifdef HAVE_ED25519
  53536. PRIVATE_KEY_UNLOCK();
  53537. if (ret == 0)
  53538. ret = ed25519_test();
  53539. PRIVATE_KEY_LOCK();
  53540. #endif
  53541. #ifdef HAVE_CURVE25519
  53542. if (ret == 0)
  53543. ret = curve25519_test();
  53544. #endif
  53545. #ifndef NO_AES
  53546. #ifdef HAVE_AESGCM
  53547. if (ret == 0)
  53548. ret = aesgcm_test();
  53549. #endif
  53550. #ifdef HAVE_AES_CBC
  53551. if (ret == 0)
  53552. ret = aes_test();
  53553. #endif
  53554. #ifdef WOLFSSL_AES_XTS
  53555. if (ret == 0)
  53556. ret = aes_xts_test();
  53557. #endif
  53558. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53559. if (ret == 0)
  53560. ret = aesccm_test();
  53561. #endif
  53562. #endif /* !NO_AES */
  53563. #ifndef NO_DES3
  53564. if (ret == 0)
  53565. ret = des3_test();
  53566. #endif /* !NO_DES3 */
  53567. #ifndef NO_SHA
  53568. if (ret == 0)
  53569. ret = sha_test();
  53570. #endif
  53571. #ifndef NO_SHA256
  53572. if (ret == 0)
  53573. ret = sha256_test();
  53574. #endif
  53575. #ifdef WOLFSSL_SHA384
  53576. if (ret == 0)
  53577. ret = sha384_test();
  53578. #endif
  53579. #ifdef WOLFSSL_SHA512
  53580. if (ret == 0)
  53581. ret = sha512_test();
  53582. #ifdef WOLFSSL_SHA3
  53583. if (ret == 0)
  53584. ret = sha3_test();
  53585. #endif
  53586. #endif
  53587. #ifndef NO_HMAC
  53588. #ifndef NO_SHA
  53589. if (ret == 0)
  53590. ret = hmac_sha_test();
  53591. #endif
  53592. #ifndef NO_SHA256
  53593. if (ret == 0)
  53594. ret = hmac_sha256_test();
  53595. #endif
  53596. #ifdef WOLFSSL_SHA3
  53597. if (ret == 0)
  53598. ret = hmac_sha3_test();
  53599. #endif
  53600. #endif
  53601. #ifndef NO_PWDBASED
  53602. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  53603. PRIVATE_KEY_UNLOCK();
  53604. if (ret == 0)
  53605. ret = pbkdf2_test();
  53606. PRIVATE_KEY_LOCK();
  53607. #endif
  53608. #endif
  53609. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53610. if (ret == 0)
  53611. ret = cmac_test();
  53612. #endif
  53613. /* restore devId */
  53614. devId = origDevId;
  53615. return ret;
  53616. }
  53617. #endif /* ! WC_TEST_NO_CRYPTOCB_SW_TEST */
  53618. #endif /* WOLF_CRYPTO_CB */
  53619. #ifdef WOLFSSL_CERT_PIV
  53620. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void)
  53621. {
  53622. wc_test_ret_t ret;
  53623. wc_CertPIV piv;
  53624. /* Template for Identiv PIV cert, nonce and signature */
  53625. WOLFSSL_SMALL_STACK_STATIC const byte pivCertIdentiv[] = {
  53626. 0x0A, 0x0B,
  53627. 0x53, 0x09, /* NIST PIV Cert */
  53628. 0x70, 0x02, /* Certificate */
  53629. 0x30, 0x00,
  53630. 0x71, 0x01, 0x05, /* Cert Info */
  53631. 0xFE, 0x00, /* Error Detection */
  53632. 0x0B, 0x01, 0x00, /* Nonce */
  53633. 0x0C, 0x01, 0x00, /* Signed Nonce */
  53634. };
  53635. /* PIV certificate data including certificate, info and error detection. */
  53636. WOLFSSL_SMALL_STACK_STATIC const byte pivCert[] = {
  53637. 0x53, 0x09, /* NIST PIV Cert */
  53638. 0x70, 0x02, /* Certificate */
  53639. 0x30, 0x00,
  53640. 0x71, 0x01, 0x04, /* Cert Info */
  53641. 0xFE, 0x00, /* Error Detection */
  53642. };
  53643. WOLFSSL_ENTER("certpiv_test");
  53644. XMEMSET(&piv, 0, sizeof(piv));
  53645. /* Test with Identiv 0x0A, 0x0B and 0x0C markers */
  53646. ret = wc_ParseCertPIV(&piv, pivCertIdentiv, sizeof(pivCertIdentiv));
  53647. if (ret != 0) {
  53648. return WC_TEST_RET_ENC_EC(ret);
  53649. }
  53650. if (!piv.isIdentiv) {
  53651. return WC_TEST_RET_ENC_NC;
  53652. }
  53653. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53654. return WC_TEST_RET_ENC_NC;
  53655. }
  53656. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53657. return WC_TEST_RET_ENC_NC;
  53658. }
  53659. if ((piv.compression != ASN_PIV_CERT_INFO_GZIP)) {
  53660. return WC_TEST_RET_ENC_NC;
  53661. }
  53662. if (!piv.isX509) {
  53663. return WC_TEST_RET_ENC_NC;
  53664. }
  53665. if ((piv.nonce == NULL) || (piv.nonceSz != 1)) {
  53666. return WC_TEST_RET_ENC_NC;
  53667. }
  53668. if ((piv.signedNonce == NULL) || (piv.signedNonceSz != 1)) {
  53669. return WC_TEST_RET_ENC_NC;
  53670. }
  53671. XMEMSET(&piv, 0, sizeof(piv));
  53672. /* Test with NIST PIV format */
  53673. ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert));
  53674. if (ret != 0) {
  53675. return WC_TEST_RET_ENC_EC(ret);
  53676. }
  53677. if (piv.isIdentiv) {
  53678. return WC_TEST_RET_ENC_NC;
  53679. }
  53680. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53681. return WC_TEST_RET_ENC_NC;
  53682. }
  53683. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53684. return WC_TEST_RET_ENC_NC;
  53685. }
  53686. if ((piv.compression != 0)) {
  53687. return WC_TEST_RET_ENC_NC;
  53688. }
  53689. if (!piv.isX509) {
  53690. return WC_TEST_RET_ENC_NC;
  53691. }
  53692. return ret;
  53693. }
  53694. #endif /* WOLFSSL_CERT_PIV */
  53695. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  53696. static time_t time_cb(time_t* t)
  53697. {
  53698. if (t != NULL) {
  53699. *t = 99;
  53700. }
  53701. return 99;
  53702. }
  53703. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void)
  53704. {
  53705. time_t t;
  53706. wc_test_ret_t ret;
  53707. WOLFSSL_ENTER("time_test");
  53708. ret = wc_SetTimeCb(time_cb);
  53709. if (ret != 0)
  53710. return WC_TEST_RET_ENC_EC(ret);
  53711. t = wc_Time(NULL);
  53712. if (t != 99)
  53713. return WC_TEST_RET_ENC_NC;
  53714. ret = wc_GetTime(&t, sizeof(time_t));
  53715. if (ret != 0)
  53716. return WC_TEST_RET_ENC_EC(ret);
  53717. if (t != 99)
  53718. return WC_TEST_RET_ENC_NC;
  53719. ret = wc_SetTimeCb(NULL);
  53720. if (ret != 0)
  53721. return WC_TEST_RET_ENC_EC(ret);
  53722. return 0;
  53723. }
  53724. #endif
  53725. #ifdef WOLFSSL_AES_SIV
  53726. typedef struct {
  53727. const byte key[33];
  53728. word32 keySz;
  53729. const byte nonce[49];
  53730. word32 nonceSz;
  53731. byte numAssoc;
  53732. const byte assoc1[81];
  53733. word32 assoc1Sz;
  53734. const byte assoc2[11];
  53735. word32 assoc2Sz;
  53736. const byte plaintext[83];
  53737. word32 plaintextSz;
  53738. const byte siv[WC_AES_BLOCK_SIZE+1];
  53739. const byte ciphertext[82];
  53740. word32 ciphertextSz;
  53741. } AesSivTestVector;
  53742. #define AES_SIV_TEST_VECTORS 9
  53743. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
  53744. {
  53745. WOLFSSL_SMALL_STACK_STATIC const AesSivTestVector testVectors[AES_SIV_TEST_VECTORS] = {
  53746. /* These test vectors come from chrony 4.1's SIV unit tests. */
  53747. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53748. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53749. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53750. 1,
  53751. "", 0,
  53752. "", 0,
  53753. "", 0,
  53754. "\x22\x3e\xb5\x94\xe0\xe0\x25\x4b\x00\x25\x8e\x21\x9a\x1c\xa4\x21",
  53755. "", 0
  53756. },
  53757. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53758. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53759. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53760. 1,
  53761. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53762. "", 0,
  53763. "", 0,
  53764. "\xd7\x20\x19\x89\xc6\xdb\xc6\xd6\x61\xfc\x62\xbc\x86\x5e\xee\xef",
  53765. "", 0
  53766. },
  53767. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53768. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53769. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53770. 1,
  53771. "", 0,
  53772. "", 0,
  53773. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53774. "\xb6\xc1\x60\xe9\xc2\xfd\x2a\xe8\xde\xc5\x36\x8b\x2a\x33\xed\xe1",
  53775. "\x14\xff\xb3\x97\x34\x5c\xcb\xe4\x4a\xa4\xde\xac\xd9\x36\x90\x46", 16
  53776. },
  53777. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53778. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53779. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e", 15,
  53780. 1,
  53781. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c", 15,
  53782. "", 0,
  53783. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4", 15,
  53784. "\x03\x8c\x41\x51\xba\x7a\x8f\x77\x6e\x56\x31\x99\x42\x0b\xc7\x03",
  53785. "\xe7\x6c\x67\xc9\xda\xb7\x0d\x5b\x44\x06\x26\x5a\xd0\xd2\x3b", 15
  53786. },
  53787. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53788. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53789. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53790. 1,
  53791. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53792. "", 0,
  53793. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7", 16,
  53794. "\x5c\x05\x23\x65\xf4\x57\x0a\xa0\xfb\x38\x3e\xce\x9b\x75\x85\xeb",
  53795. "\x68\x85\x19\x36\x0c\x7c\x48\x11\x40\xcb\x9b\x57\x9a\x0e\x65\x32", 16
  53796. },
  53797. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53798. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53799. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53800. "\xd5", 17,
  53801. 1,
  53802. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b"
  53803. "\xa0", 17,
  53804. "", 0,
  53805. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7"
  53806. "\x08", 17,
  53807. "\xaf\x58\x4b\xe7\x82\x1e\x96\x19\x29\x91\x25\xe0\xdd\x80\x3b\x49",
  53808. "\xa5\x11\xcd\xb6\x08\xf3\x76\xa0\xb6\xfa\x15\x82\xf3\x95\xe1\xeb"
  53809. "\xbd", 17
  53810. },
  53811. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53812. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53813. "\xb0\x5a\x1b\xc7\x56\xe7\xb6\x2c\xb4\x85\xe5\x56\xa5\x28\xc0\x6c"
  53814. "\x2f\x3b\x0b\x9d\x1a\x0c\xdf\x69\x47\xe0\xcc\xc0\x87\xaa\x5c\x09"
  53815. "\x98\x48\x8d\x6a\x8e\x1e\x05\xd7\x8b\x68\x74\x83\xb5\x1d\xf1\x2c", 48,
  53816. 1,
  53817. "\xe5\x8b\xd2\x6a\x30\xc5\xc5\x61\xcc\xbd\x7c\x27\xbf\xfe\xf9\x06"
  53818. "\x00\x5b\xd7\xfc\x11\x0b\xcf\x16\x61\xef\xac\x05\xa7\xaf\xec\x27"
  53819. "\x41\xc8\x5e\x9e\x0d\xf9\x2f\xaf\x20\x79\x17\xe5\x17\x91\x2a\x27"
  53820. "\x34\x1c\xbc\xaf\xeb\xef\x7f\x52\xe7\x1e\x4c\x2a\xca\xbd\x2b\xbe"
  53821. "\x34\xd6\xfb\x69\xd3\x3e\x49\x59\x60\xb4\x26\xc9\xb8\xce\xba", 79,
  53822. "", 0,
  53823. "\x6c\xe7\xcf\x7e\xab\x7b\xa0\xe1\xa7\x22\xcb\x88\xde\x5e\x42\xd2"
  53824. "\xec\x79\xe0\xa2\xcf\x5f\x0f\x6f\x6b\x89\x57\xcd\xae\x17\xd4\xc2"
  53825. "\xf3\x1b\xa2\xa8\x13\x78\x23\x2f\x83\xa8\xd4\x0c\xc0\xd2\xf3\x99"
  53826. "\xae\x81\xa1\xca\x5b\x5f\x45\xa6\x6f\x0c\x8a\xf3\xd4\x67\x40\x81"
  53827. "\x26\xe2\x01\x86\xe8\x5a\xd5\xf8\x58\x80\x9f\x56\xaa\x76\x96\xbf"
  53828. "\x31", 81,
  53829. "\x9a\x06\x33\xe0\xee\x00\x6a\x9b\xc8\x20\xd5\xe2\xc2\xed\xb5\x75",
  53830. "\xfa\x9e\x42\x2a\x31\x6b\xda\xca\xaa\x7d\x31\x8b\x84\x7a\xb8\xd7"
  53831. "\x8a\x81\x25\x64\xed\x41\x9b\xa9\x77\x10\xbd\x05\x0c\x4e\xc5\x31"
  53832. "\x0c\xa2\x86\xec\x8a\x94\xc8\x24\x23\x3c\x13\xee\xa5\x51\xc9\xdf"
  53833. "\x48\xc9\x55\xc5\x2f\x40\x73\x3f\x98\xbb\x8d\x69\x78\x46\x64\x17"
  53834. "\x8d\x49\x2f\x14\x62\xa4\x7c\x2a\x57\x38\x87\xce\xc6\x72\xd3\x5c"
  53835. "\xa1", 81
  53836. },
  53837. /* Example A.1 from RFC5297 */
  53838. {
  53839. "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0"
  53840. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 32,
  53841. "", 0,
  53842. 1,
  53843. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53844. "\x20\x21\x22\x23\x24\x25\x26\x27", 24,
  53845. "", 0,
  53846. "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee", 14,
  53847. "\x85\x63\x2d\x07\xc6\xe8\xf3\x7f\x95\x0a\xcd\x32\x0a\x2e\xcc\x93",
  53848. "\x40\xc0\x2b\x96\x90\xc4\xdc\x04\xda\xef\x7f\x6a\xfe\x5c", 14
  53849. },
  53850. /* Example A.2 from RFC5297 */
  53851. {
  53852. "\x7f\x7e\x7d\x7c\x7b\x7a\x79\x78\x77\x76\x75\x74\x73\x72\x71\x70"
  53853. "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", 32,
  53854. "\x09\xf9\x11\x02\x9d\x74\xe3\x5b\xd8\x41\x56\xc5\x63\x56\x88\xc0", 16,
  53855. 2,
  53856. "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
  53857. "\xde\xad\xda\xda\xde\xad\xda\xda\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
  53858. "\x77\x66\x55\x44\x33\x22\x11\x00", 40,
  53859. "\x10\x20\x30\x40\x50\x60\x70\x80\x90\xa0", 10,
  53860. "\x74\x68\x69\x73\x20\x69\x73\x20\x73\x6f\x6d\x65\x20\x70\x6c\x61"
  53861. "\x69\x6e\x74\x65\x78\x74\x20\x74\x6f\x20\x65\x6e\x63\x72\x79\x70"
  53862. "\x74\x20\x75\x73\x69\x6e\x67\x20\x53\x49\x56\x2d\x41\x45\x53", 47,
  53863. "\x7b\xdb\x6e\x3b\x43\x26\x67\xeb\x06\xf4\xd1\x4b\xff\x2f\xbd\x0f",
  53864. "\xcb\x90\x0f\x2f\xdd\xbe\x40\x43\x26\x60\x19\x65\xc8\x89\xbf\x17"
  53865. "\xdb\xa7\x7c\xeb\x09\x4f\xa6\x63\xb7\xa3\xf7\x48\xba\x8a\xf8\x29"
  53866. "\xea\x64\xad\x54\x4a\x27\x2e\x9c\x48\x5b\x62\xa3\xfd\x5c\x0d", 47
  53867. }
  53868. };
  53869. int i;
  53870. byte computedCiphertext[82];
  53871. byte computedPlaintext[82];
  53872. byte siv[WC_AES_BLOCK_SIZE];
  53873. wc_test_ret_t ret = 0;
  53874. WOLFSSL_ENTER("aes_siv_test");
  53875. /* First test legacy "exactly one Assoc" interface. */
  53876. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53877. if (testVectors[i].numAssoc != 1)
  53878. continue;
  53879. ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz,
  53880. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53881. testVectors[i].nonce, testVectors[i].nonceSz,
  53882. testVectors[i].plaintext,
  53883. testVectors[i].plaintextSz, siv,
  53884. computedCiphertext);
  53885. if (ret != 0) {
  53886. return WC_TEST_RET_ENC_EC(ret);
  53887. }
  53888. ret = XMEMCMP(siv, testVectors[i].siv, WC_AES_BLOCK_SIZE);
  53889. if (ret != 0) {
  53890. return WC_TEST_RET_ENC_NC;
  53891. }
  53892. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53893. testVectors[i].ciphertextSz);
  53894. if (ret != 0) {
  53895. return WC_TEST_RET_ENC_NC;
  53896. }
  53897. ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz,
  53898. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53899. testVectors[i].nonce, testVectors[i].nonceSz,
  53900. computedCiphertext, testVectors[i].plaintextSz,
  53901. siv, computedPlaintext);
  53902. if (ret != 0) {
  53903. return WC_TEST_RET_ENC_EC(ret);
  53904. }
  53905. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53906. testVectors[i].plaintextSz);
  53907. if (ret != 0) {
  53908. return WC_TEST_RET_ENC_NC;
  53909. }
  53910. }
  53911. /* Then test "multiple Assoc" interface. */
  53912. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53913. const struct AesSivAssoc assoc[2] = {
  53914. { testVectors[i].assoc1, testVectors[i].assoc1Sz },
  53915. { testVectors[i].assoc2, testVectors[i].assoc2Sz }
  53916. };
  53917. ret = wc_AesSivEncrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53918. assoc, testVectors[i].numAssoc,
  53919. testVectors[i].nonce, testVectors[i].nonceSz,
  53920. testVectors[i].plaintext,
  53921. testVectors[i].plaintextSz, siv,
  53922. computedCiphertext);
  53923. if (ret != 0) {
  53924. return WC_TEST_RET_ENC_EC(ret);
  53925. }
  53926. ret = XMEMCMP(siv, testVectors[i].siv, WC_AES_BLOCK_SIZE);
  53927. if (ret != 0) {
  53928. return WC_TEST_RET_ENC_NC;
  53929. }
  53930. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53931. testVectors[i].ciphertextSz);
  53932. if (ret != 0) {
  53933. return WC_TEST_RET_ENC_NC;
  53934. }
  53935. ret = wc_AesSivDecrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53936. assoc, testVectors[i].numAssoc,
  53937. testVectors[i].nonce, testVectors[i].nonceSz,
  53938. computedCiphertext,
  53939. testVectors[i].plaintextSz, siv,
  53940. computedPlaintext);
  53941. if (ret != 0) {
  53942. return WC_TEST_RET_ENC_EC(ret);
  53943. }
  53944. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53945. testVectors[i].plaintextSz);
  53946. if (ret != 0) {
  53947. return WC_TEST_RET_ENC_NC;
  53948. }
  53949. }
  53950. return 0;
  53951. }
  53952. #endif
  53953. #undef ERROR_OUT
  53954. static const int fiducial4 = WC_TEST_RET_LN;
  53955. /* print the fiducial line numbers assigned above, allowing confirmation of
  53956. * source code version match when in doubt.
  53957. */
  53958. static void print_fiducials(void) {
  53959. printf(" [fiducial line numbers: %d %d %d %d]\n",
  53960. fiducial1, fiducial2, fiducial3, fiducial4);
  53961. }
  53962. #else
  53963. #ifndef NO_MAIN_DRIVER
  53964. int main(void) { return 0; }
  53965. #endif
  53966. #endif /* NO_CRYPT_TEST */