test.c 2.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088
  1. /* test.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*
  22. * Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. *
  26. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  27. * WC_USE_DEVID=0x1234
  28. */
  29. #ifdef HAVE_CONFIG_H
  30. #include <config.h>
  31. #endif
  32. #ifndef WOLFSSL_USER_SETTINGS
  33. #include <wolfssl/options.h>
  34. #endif
  35. #include <wolfssl/wolfcrypt/settings.h>
  36. #ifdef WOLFSSL_DEBUG_TRACE_ERROR_CODES
  37. #define WOLFSSL_DEBUG_TRACE_ERROR_CODES_ALWAYS
  38. #endif
  39. #ifndef NO_CRYPT_TEST
  40. #include <wolfssl/version.h>
  41. #include <wolfssl/wolfcrypt/types.h>
  42. #include <wolfssl/wolfcrypt/wc_port.h>
  43. #include <wolfssl/wolfcrypt/mem_track.h>
  44. #if defined(HAVE_WOLFCRYPT_TEST_OPTIONS)
  45. #include <wolfssl/ssl.h>
  46. #define err_sys err_sys_remap /* remap err_sys */
  47. #include <wolfssl/test.h>
  48. #undef err_sys
  49. #endif
  50. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  51. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  52. #include <stdint.h>
  53. #endif
  54. #ifdef HAVE_STACK_SIZE_VERBOSE
  55. #ifdef WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES
  56. static WC_MAYBE_UNUSED ssize_t max_relative_stack =
  57. WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES;
  58. #else
  59. static WC_MAYBE_UNUSED ssize_t max_relative_stack = -1;
  60. #endif
  61. #endif
  62. const byte const_byte_array[] = "A+Gd\0\0\0";
  63. #define CBPTR_EXPECTED 'A'
  64. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  65. #ifdef WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS
  66. static ssize_t max_relative_heap_allocs = WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS;
  67. #else
  68. static ssize_t max_relative_heap_allocs = -1;
  69. #endif
  70. #ifdef WOLFSSL_TEST_MAX_RELATIVE_HEAP_BYTES
  71. static ssize_t max_relative_heap_bytes = WOLFSSL_TEST_MAX_RELATIVE_HEAP_BYTES;
  72. #else
  73. static ssize_t max_relative_heap_bytes = -1;
  74. #endif
  75. #define PRINT_HEAP_CHECKPOINT() { \
  76. const ssize_t _rha = wolfCrypt_heap_peakAllocs_checkpoint() - heap_baselineAllocs; \
  77. const ssize_t _rhb = wolfCrypt_heap_peakBytes_checkpoint() - heap_baselineBytes; \
  78. printf(" relative heap peak usage: %ld alloc%s, %ld bytes\n", \
  79. (long int)_rha, \
  80. _rha == 1 ? "" : "s", \
  81. (long int)_rhb); \
  82. if ((max_relative_heap_allocs > 0) && (_rha > max_relative_heap_allocs)) \
  83. return err_sys("heap allocs exceed designated max.", \
  84. WC_TEST_RET_ENC_NC); \
  85. if ((max_relative_heap_bytes > 0) && (_rhb > max_relative_heap_bytes)) \
  86. return err_sys("heap bytes exceed designated max.", \
  87. WC_TEST_RET_ENC_NC); \
  88. heap_baselineAllocs = wolfCrypt_heap_peakAllocs_checkpoint(); \
  89. heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint(); \
  90. }
  91. #else
  92. #define PRINT_HEAP_CHECKPOINT() WC_DO_NOTHING
  93. #endif /* WOLFSSL_TRACK_MEMORY_VERBOSE && !WOLFSSL_STATIC_MEMORY */
  94. #ifdef USE_FLAT_TEST_H
  95. #ifdef HAVE_CONFIG_H
  96. #include "test_paths.h"
  97. #endif
  98. #include "test.h"
  99. #else
  100. #ifdef HAVE_CONFIG_H
  101. #include "wolfcrypt/test/test_paths.h"
  102. #endif
  103. #include "wolfcrypt/test/test.h"
  104. #endif
  105. /* printf mappings */
  106. #ifndef WOLFSSL_LOG_PRINTF
  107. #if defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
  108. #include <mqx.h>
  109. #include <stdlib.h>
  110. /* see wc_port.h for fio.h and nio.h includes */
  111. #elif defined(FREESCALE_KSDK_BM)
  112. #include "fsl_debug_console.h"
  113. #undef printf
  114. #define printf PRINTF
  115. #elif defined(WOLFSSL_APACHE_MYNEWT)
  116. #include <assert.h>
  117. #include <string.h>
  118. #include "sysinit/sysinit.h"
  119. #include "os/os.h"
  120. #ifdef ARCH_sim
  121. #include "mcu/mcu_sim.h"
  122. #endif
  123. #include "os/os_time.h"
  124. #elif defined(WOLFSSL_ESPIDF)
  125. #include <time.h>
  126. #include <sys/time.h>
  127. #include <esp_log.h>
  128. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  129. #define ESPIDF_TAG "wc_test"
  130. #elif defined(WOLFSSL_ZEPHYR)
  131. #include <stdio.h>
  132. #define printf printk
  133. #elif defined(MICRIUM)
  134. #include <os.h>
  135. #if (OS_VERSION < 50000)
  136. #include <bsp_ser.h>
  137. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  138. #undef printf
  139. #define printf BSP_Ser_Printf
  140. #else
  141. #include <stdio.h>
  142. #endif
  143. #elif defined(WOLFSSL_PB)
  144. #include <stdarg.h>
  145. int wolfssl_pb_print(const char*, ...);
  146. #undef printf
  147. #define printf wolfssl_pb_print
  148. #elif defined(WOLFSSL_TELIT_M2MB)
  149. #include "wolfssl/wolfcrypt/wc_port.h" /* for m2mb headers */
  150. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  151. /* remap printf */
  152. #undef printf
  153. #define printf M2M_LOG_INFO
  154. /* OS requires occasional sleep() */
  155. #ifndef TEST_SLEEP_MS
  156. #define TEST_SLEEP_MS 50
  157. #endif
  158. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  159. /* don't use file system for these tests, since ./certs dir isn't loaded */
  160. #undef NO_FILESYSTEM
  161. #define NO_FILESYSTEM
  162. #elif defined(THREADX) && !defined(WOLFSSL_WICED) && \
  163. !defined(THREADX_NO_DC_PRINTF)
  164. #ifndef NETOS
  165. /* since just testing, use THREADX log printf instead (NETOS prototypes
  166. * this elsewhere) */
  167. int dc_log_printf(char*, ...);
  168. #endif
  169. #undef printf
  170. #define printf dc_log_printf
  171. #elif defined(ANDROID)
  172. #ifdef XMALLOC_USER
  173. #include <stdlib.h> /* we're using malloc / free direct here */
  174. #endif
  175. #ifndef STRING_USER
  176. #include <stdio.h>
  177. #endif
  178. #include <android/log.h>
  179. #ifdef ANDROID_V454 /* See fips/android/wolfCrypt_v454_android */
  180. #ifndef NO_FILESYSTEM
  181. #define NO_FILESYSTEM /* Turn off tests that want to call SaveDerAndPem() */
  182. #endif
  183. #else
  184. #define printf(...) \
  185. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  186. #define fprintf(fp, ...) \
  187. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  188. #endif
  189. #elif defined(WOLFSSL_DEOS)
  190. #include <printx.h>
  191. #undef printf
  192. #define printf printx
  193. #elif defined(WOLFSSL_RENESAS_RSIP)
  194. #ifndef TEST_SLEEP
  195. #define TEST_SLEEP() vTaskDelay(50)
  196. #endif
  197. #undef vprintf
  198. #define vprintf rsip_vprintf
  199. #include <stdarg.h> /* for var args */
  200. int rsip_vprintf(const char* restrict format, va_list args)
  201. {
  202. int ret;
  203. char tmpBuf[80];
  204. ret = XVSNPRINTF(tmpBuf, sizeof(tmpBuf), format, args);
  205. printf(tmpBuf);
  206. return ret;
  207. }
  208. #else
  209. #ifdef XMALLOC_USER
  210. #include <stdlib.h> /* we're using malloc / free direct here */
  211. #endif
  212. #if !defined(STRING_USER) && !defined(WOLFSSL_LINUXKM)
  213. #include <stdio.h>
  214. #endif
  215. #if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_LINUXKM_VERBOSE_DEBUG)
  216. #undef printf
  217. #define printf(...) ({})
  218. #endif
  219. /* enable way for customer to override test/bench printf */
  220. #ifdef XPRINTF
  221. #undef printf
  222. #define printf XPRINTF
  223. #elif !defined(printf)
  224. /* arrange for printf() to flush after every message -- this assures
  225. * redirected output (to a log file) records progress right up to the
  226. * moment of a crash/abort(); otherwise anything queued in stdout would
  227. * be lost.
  228. */
  229. #define printf(...) ( printf(__VA_ARGS__), fflush(stdout) )
  230. #endif
  231. #endif
  232. #endif /* !WOLFSSL_LOG_PRINTF */
  233. #include <wolfssl/wolfcrypt/memory.h>
  234. #include <wolfssl/wolfcrypt/wc_port.h>
  235. #include <wolfssl/wolfcrypt/logging.h>
  236. #include <wolfssl/wolfcrypt/types.h>
  237. #include <wolfssl/wolfcrypt/asn.h>
  238. #include <wolfssl/wolfcrypt/md2.h>
  239. #include <wolfssl/wolfcrypt/md5.h>
  240. #include <wolfssl/wolfcrypt/md4.h>
  241. #include <wolfssl/wolfcrypt/sha.h>
  242. #include <wolfssl/wolfcrypt/sha256.h>
  243. #include <wolfssl/wolfcrypt/sha512.h>
  244. #include <wolfssl/wolfcrypt/hash.h>
  245. #include <wolfssl/wolfcrypt/rc2.h>
  246. #include <wolfssl/wolfcrypt/arc4.h>
  247. #if !defined(WC_NO_RNG)
  248. #include <wolfssl/wolfcrypt/random.h>
  249. #endif
  250. #include <wolfssl/wolfcrypt/wolfmath.h>
  251. #include <wolfssl/wolfcrypt/coding.h>
  252. #include <wolfssl/wolfcrypt/signature.h>
  253. #include <wolfssl/wolfcrypt/rsa.h>
  254. #include <wolfssl/wolfcrypt/des3.h>
  255. #include <wolfssl/wolfcrypt/aes.h>
  256. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  257. #include <wolfssl/wolfcrypt/cmac.h>
  258. #include <wolfssl/wolfcrypt/siphash.h>
  259. #include <wolfssl/wolfcrypt/poly1305.h>
  260. #include <wolfssl/wolfcrypt/camellia.h>
  261. #include <wolfssl/wolfcrypt/hmac.h>
  262. #include <wolfssl/wolfcrypt/kdf.h>
  263. #include <wolfssl/wolfcrypt/dh.h>
  264. #include <wolfssl/wolfcrypt/dsa.h>
  265. #include <wolfssl/wolfcrypt/srp.h>
  266. #include <wolfssl/wolfcrypt/chacha.h>
  267. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  268. #include <wolfssl/wolfcrypt/pwdbased.h>
  269. #include <wolfssl/wolfcrypt/ripemd.h>
  270. #include <wolfssl/wolfcrypt/error-crypt.h>
  271. #ifdef HAVE_ECC
  272. #include <wolfssl/wolfcrypt/ecc.h>
  273. #endif
  274. #ifdef WOLFSSL_SM2
  275. #include <wolfssl/wolfcrypt/sm2.h>
  276. #endif
  277. #ifdef HAVE_HPKE
  278. #include <wolfssl/wolfcrypt/hpke.h>
  279. #endif
  280. #ifdef HAVE_CURVE25519
  281. #include <wolfssl/wolfcrypt/curve25519.h>
  282. #endif
  283. #ifdef HAVE_ED25519
  284. #include <wolfssl/wolfcrypt/ed25519.h>
  285. #endif
  286. #ifdef HAVE_CURVE448
  287. #include <wolfssl/wolfcrypt/curve448.h>
  288. #endif
  289. #ifdef HAVE_ED448
  290. #include <wolfssl/wolfcrypt/ed448.h>
  291. #endif
  292. #ifdef WOLFSSL_HAVE_KYBER
  293. #include <wolfssl/wolfcrypt/kyber.h>
  294. #ifdef WOLFSSL_WC_KYBER
  295. #include <wolfssl/wolfcrypt/wc_kyber.h>
  296. #endif
  297. #if defined(HAVE_LIBOQS)
  298. #include <wolfssl/wolfcrypt/ext_kyber.h>
  299. #endif
  300. #endif
  301. #ifdef HAVE_DILITHIUM
  302. #include <wolfssl/wolfcrypt/dilithium.h>
  303. #endif
  304. #if defined(WOLFSSL_HAVE_XMSS)
  305. #include <wolfssl/wolfcrypt/xmss.h>
  306. #ifdef HAVE_LIBXMSS
  307. #include <wolfssl/wolfcrypt/ext_xmss.h>
  308. #else
  309. #include <wolfssl/wolfcrypt/wc_xmss.h>
  310. #endif
  311. #endif
  312. #if defined(WOLFSSL_HAVE_LMS)
  313. #include <wolfssl/wolfcrypt/lms.h>
  314. #ifdef HAVE_LIBLMS
  315. #include <wolfssl/wolfcrypt/ext_lms.h>
  316. #else
  317. #include <wolfssl/wolfcrypt/wc_lms.h>
  318. #endif
  319. #endif
  320. #ifdef WOLFCRYPT_HAVE_ECCSI
  321. #include <wolfssl/wolfcrypt/eccsi.h>
  322. #endif
  323. #ifdef WOLFCRYPT_HAVE_SAKKE
  324. #include <wolfssl/wolfcrypt/sakke.h>
  325. #endif
  326. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  327. #include <wolfssl/wolfcrypt/blake2.h>
  328. #endif
  329. #ifdef WOLFSSL_SHA3
  330. #include <wolfssl/wolfcrypt/sha3.h>
  331. #endif
  332. #ifdef WOLFSSL_SM3
  333. #include <wolfssl/wolfcrypt/sm3.h>
  334. #endif
  335. #ifdef WOLFSSL_SM4
  336. #include <wolfssl/wolfcrypt/sm4.h>
  337. #endif
  338. #ifdef HAVE_LIBZ
  339. #include <wolfssl/wolfcrypt/compress.h>
  340. #endif
  341. #ifdef HAVE_PKCS7
  342. #include <wolfssl/wolfcrypt/pkcs7.h>
  343. #endif
  344. #ifdef HAVE_PKCS12
  345. #include <wolfssl/wolfcrypt/pkcs12.h>
  346. #endif
  347. #ifdef HAVE_FIPS
  348. #include <wolfssl/wolfcrypt/fips_test.h>
  349. #endif
  350. #ifdef HAVE_SELFTEST
  351. #include <wolfssl/wolfcrypt/selftest.h>
  352. #endif
  353. #ifdef WOLFSSL_ASYNC_CRYPT
  354. #include <wolfssl/wolfcrypt/async.h>
  355. #endif
  356. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  357. #include <wolfssl/wolfcrypt/logging.h>
  358. #endif
  359. #ifdef WOLFSSL_CAAM
  360. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  361. #endif
  362. #ifdef WOLF_CRYPTO_CB
  363. #include <wolfssl/wolfcrypt/cryptocb.h>
  364. #ifdef HAVE_INTEL_QA_SYNC
  365. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  366. #endif
  367. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  368. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  369. #endif
  370. #ifdef HAVE_RENESAS_SYNC
  371. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  372. #endif
  373. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  374. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  375. #endif
  376. #endif
  377. #ifdef _MSC_VER
  378. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  379. #pragma warning(disable: 4996)
  380. #endif
  381. #ifdef OPENSSL_EXTRA
  382. #ifndef WOLFCRYPT_ONLY
  383. #include <wolfssl/openssl/evp.h>
  384. #include <wolfssl/openssl/hmac.h>
  385. #endif
  386. #include <wolfssl/openssl/rand.h>
  387. #include <wolfssl/openssl/aes.h>
  388. #include <wolfssl/openssl/des.h>
  389. #endif
  390. #if defined(NO_FILESYSTEM) || defined(WC_NO_RNG)
  391. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  392. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  393. #define USE_CERT_BUFFERS_2048
  394. #endif
  395. #if !defined(USE_CERT_BUFFERS_256)
  396. #define USE_CERT_BUFFERS_256
  397. #endif
  398. #endif
  399. #if defined(WOLFSSL_CERT_GEN) && (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  400. #define ENABLE_ECC384_CERT_GEN_TEST
  401. #endif
  402. #include <wolfssl/certs_test.h>
  403. #ifdef DEVKITPRO
  404. #include <wiiuse/wpad.h>
  405. #endif
  406. #ifdef WOLFSSL_NDS
  407. #include <nds/ndstypes.h>
  408. #include <nds/arm9/console.h>
  409. #include <nds/arm9/input.h>
  410. #include <nds/interrupts.h>
  411. #include <fat.h>
  412. #endif
  413. #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  414. /* FIPS build has replaced ecc.h. */
  415. #define wc_ecc_key_get_priv(key) (&((key)->k))
  416. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  417. #endif
  418. #ifdef WOLFSSL_STATIC_MEMORY
  419. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  420. #else
  421. #define HEAP_HINT NULL
  422. #endif /* WOLFSSL_STATIC_MEMORY */
  423. /* these cases do not have intermediate hashing support */
  424. #if (defined(WOLFSSL_AFALG_XILINX_SHA3) && !defined(WOLFSSL_AFALG_HASH_KEEP)) \
  425. && !defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  426. #define NO_INTM_HASH_TEST
  427. #endif
  428. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  429. defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY) || \
  430. defined(WOLFSSL_SECO_CAAM)
  431. #define HASH_SIZE_LIMIT
  432. #endif
  433. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  434. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  435. static void initDefaultName(void);
  436. #endif
  437. /* for async devices */
  438. #ifdef WOLFSSL_CAAM_DEVID
  439. static int devId = WOLFSSL_CAAM_DEVID;
  440. #else
  441. #ifdef WC_USE_DEVID
  442. static int devId = WC_USE_DEVID;
  443. #else
  444. static int devId = INVALID_DEVID;
  445. #endif
  446. #endif
  447. #ifdef HAVE_WNR
  448. const char* wnrConfigFile = "wnr-example.conf";
  449. #endif
  450. #define TEST_STRING "Everyone gets Friday off."
  451. #define TEST_STRING_SZ 25
  452. typedef struct testVector {
  453. const char* input;
  454. const char* output;
  455. size_t inLen;
  456. size_t outLen;
  457. } testVector;
  458. #ifndef WOLFSSL_TEST_SUBROUTINE
  459. #define WOLFSSL_TEST_SUBROUTINE
  460. #endif
  461. PRAGMA_GCC("GCC diagnostic ignored \"-Wunused-function\"")
  462. PRAGMA_CLANG("clang diagnostic ignored \"-Wunused-function\"")
  463. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void);
  464. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void);
  465. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void);
  466. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void);
  467. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void);
  468. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void);
  469. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void);
  470. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void);
  471. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void);
  472. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void);
  473. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void);
  474. #if !defined(WOLFSSL_NOSHA512_224) && \
  475. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  476. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void);
  477. #endif
  478. #if !defined(WOLFSSL_NOSHA512_256) && \
  479. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  480. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void);
  481. #endif
  482. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void);
  483. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void);
  484. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void);
  485. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void);
  486. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void);
  487. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void);
  488. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void);
  489. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void);
  490. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void);
  491. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void);
  492. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void);
  493. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void);
  494. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void);
  495. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  496. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  497. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  498. defined(WOLFSSL_AFALG_XILINX_RSA)
  499. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  500. static wc_test_ret_t hkdf_test(void);
  501. #else
  502. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void);
  503. #endif
  504. #endif /* HAVE_HKDF && ! NO_HMAC */
  505. #ifdef WOLFSSL_HAVE_PRF
  506. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  507. #ifdef WOLFSSL_BASE16
  508. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void);
  509. #endif /* WOLFSSL_BASE16 */
  510. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  511. #endif /* WOLFSSL_HAVE_PRF */
  512. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  513. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void);
  514. #endif
  515. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void);
  516. #ifdef WOLFSSL_TLS13
  517. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void);
  518. #endif
  519. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void);
  520. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void);
  521. #ifdef WC_SRTP_KDF
  522. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void);
  523. #endif
  524. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void);
  525. #ifdef WC_RC2
  526. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void);
  527. #endif
  528. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void);
  529. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void);
  530. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void);
  531. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void);
  532. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void);
  533. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void);
  534. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void);
  535. #if defined(WOLFSSL_AES_CFB)
  536. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void);
  537. #endif
  538. #ifdef WOLFSSL_AES_XTS
  539. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void);
  540. #endif
  541. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void);
  542. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void);
  543. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void);
  544. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void);
  545. #if defined(WOLFSSL_SIPHASH)
  546. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void);
  547. #endif
  548. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void);
  549. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void);
  550. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void);
  551. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void);
  552. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void);
  553. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void);
  554. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void);
  555. #ifdef WOLFSSL_SM4
  556. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void);
  557. #endif
  558. #ifdef WC_RSA_NO_PADDING
  559. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void);
  560. #endif
  561. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void);
  562. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void);
  563. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void);
  564. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void);
  565. #ifndef WC_NO_RNG
  566. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void);
  567. #endif /* WC_NO_RNG */
  568. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void);
  569. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void);
  570. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void);
  571. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  572. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void); /* test mini api */
  573. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void);
  574. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void);
  575. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void);
  576. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void);
  577. #endif
  578. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void);
  579. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void);
  580. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  581. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void);
  582. #endif
  583. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
  584. #ifdef HAVE_ECC
  585. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void);
  586. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  587. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  588. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void);
  589. #endif
  590. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  591. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  592. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  593. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  594. /* skip for ATECC508/608A, cannot import private key buffers */
  595. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void);
  596. #endif
  597. #endif
  598. #ifdef HAVE_CURVE25519
  599. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void);
  600. #endif
  601. #ifdef HAVE_ED25519
  602. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void);
  603. #endif
  604. #ifdef HAVE_CURVE448
  605. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void);
  606. #endif
  607. #ifdef HAVE_ED448
  608. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void);
  609. #endif
  610. #ifdef WOLFSSL_HAVE_KYBER
  611. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void);
  612. #endif
  613. #ifdef HAVE_DILITHIUM
  614. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void);
  615. #endif
  616. #if defined(WOLFSSL_HAVE_XMSS)
  617. #if !defined(WOLFSSL_SMALL_STACK) && WOLFSSL_XMSS_MIN_HEIGHT <= 10
  618. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void);
  619. #endif
  620. #if !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  621. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void);
  622. #endif
  623. #endif
  624. #if defined(WOLFSSL_HAVE_LMS)
  625. #if !defined(WOLFSSL_SMALL_STACK)
  626. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
  627. defined(HAVE_LIBLMS)
  628. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void);
  629. #endif
  630. #endif
  631. #if !defined(WOLFSSL_LMS_VERIFY_ONLY)
  632. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void);
  633. #endif
  634. #endif
  635. #ifdef WOLFCRYPT_HAVE_ECCSI
  636. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void);
  637. #endif
  638. #ifdef WOLFCRYPT_HAVE_SAKKE
  639. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void);
  640. #endif
  641. #ifdef HAVE_BLAKE2
  642. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void);
  643. #endif
  644. #ifdef HAVE_BLAKE2S
  645. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void);
  646. #endif
  647. #ifdef HAVE_LIBZ
  648. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void);
  649. #endif
  650. #ifdef HAVE_PKCS7
  651. #ifndef NO_PKCS7_ENCRYPTED_DATA
  652. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void);
  653. #endif
  654. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  655. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void);
  656. #endif
  657. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void);
  658. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void);
  659. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  660. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void);
  661. #endif
  662. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  663. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key,
  664. word32 keySz);
  665. #endif
  666. #endif
  667. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  668. !defined(NO_FILESYSTEM)
  669. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void);
  670. #endif
  671. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  672. !defined(NO_FILESYSTEM) && defined(WOLFSSL_CERT_GEN)
  673. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void);
  674. #endif
  675. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  676. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  677. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void);
  678. #endif
  679. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void);
  680. #if defined(WOLFSSL_PUBLIC_MP) && \
  681. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  682. defined(USE_FAST_MATH))
  683. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void);
  684. #endif
  685. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  686. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void);
  687. #endif
  688. #ifdef ASN_BER_TO_DER
  689. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void);
  690. #endif
  691. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void);
  692. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  693. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void);
  694. #endif
  695. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  696. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void);
  697. #else
  698. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void);
  699. #endif
  700. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  701. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void);
  702. #endif
  703. #ifdef WOLFSSL_CAAM_BLOB
  704. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void);
  705. #endif
  706. #ifdef HAVE_ARIA
  707. #include "wolfssl/wolfcrypt/port/aria/aria-crypt.h"
  708. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz);
  709. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID);
  710. #endif
  711. #if defined(WOLF_CRYPTO_CB) && !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  712. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void);
  713. #endif
  714. #ifdef WOLFSSL_CERT_PIV
  715. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void);
  716. #endif
  717. #ifdef WOLFSSL_AES_SIV
  718. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void);
  719. #endif
  720. #if defined(WOLFSSL_AES_EAX) && \
  721. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  722. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void);
  723. #endif /* WOLFSSL_AES_EAX */
  724. /* General big buffer size for many tests. */
  725. #define FOURK_BUF 4096
  726. /* If not defined in user_settings, the ERROR_OUT pause is 120 seconds. */
  727. #ifndef WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION
  728. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION 120
  729. #endif
  730. #if defined(WOLFSSL_ESPIDF_ERROR_PAUSE)
  731. #if defined(CONFIG_FREERTOS_HZ)
  732. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS \
  733. (WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION * CONFIG_FREERTOS_HZ)
  734. #else
  735. /* If not defined, assume RTOS is 1000 ticks per second. */
  736. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS \
  737. (WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION * 1000)
  738. #endif
  739. /* When defined, pause at error condition rather than exit with error. */
  740. #define ERROR_OUT(err, eLabel) \
  741. do { \
  742. ret = (err); \
  743. ESP_LOGE(ESPIDF_TAG, "Failed: Error = %d during %s, line %d", \
  744. err, __FUNCTION__, __LINE__); \
  745. ESP_LOGI(ESPIDF_TAG, "Extended system info:"); \
  746. esp_ShowExtendedSystemInfo(); \
  747. ESP_LOGW(ESPIDF_TAG, "Paused for %d seconds! " \
  748. "WOLFSSL_ESPIDF_ERROR_PAUSE is enabled.", \
  749. WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION); \
  750. vTaskDelay(WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS); \
  751. goto eLabel; \
  752. } while (0)
  753. #else
  754. #define ERROR_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0)
  755. #endif
  756. /* Not all unexpected conditions are actually errors .*/
  757. #define WARNING_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0)
  758. static void render_error_message(const char* msg, wc_test_ret_t es)
  759. {
  760. (void)msg;
  761. (void)es;
  762. #ifdef WOLFSSL_LINUXKM
  763. #define err_sys_printf lkm_printf
  764. #else
  765. #define err_sys_printf printf
  766. #endif
  767. switch (WC_TEST_RET_DEC_TAG(es)) {
  768. case WC_TEST_RET_TAG_NC:
  769. err_sys_printf("%s error L=%d\n", msg, WC_TEST_RET_DEC_LN(es));
  770. break;
  771. case WC_TEST_RET_TAG_EC:
  772. #ifdef NO_ERROR_STRINGS
  773. err_sys_printf("%s error L=%d code=%d\n", msg,
  774. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es));
  775. #elif defined(WOLFCRYPT_ONLY) || !defined(WOLFSSL_TYPES_DEFINED)
  776. err_sys_printf("%s error L=%d code=%d (%s)\n", msg,
  777. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es),
  778. wc_GetErrorString(-WC_TEST_RET_DEC_I(es))
  779. );
  780. #else
  781. err_sys_printf("%s error L=%d code=%d (%s)\n", msg,
  782. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es),
  783. wolfSSL_ERR_reason_error_string(-WC_TEST_RET_DEC_I(es))
  784. );
  785. #endif
  786. break;
  787. case WC_TEST_RET_TAG_ERRNO:
  788. {
  789. /* strerror_r() comes in two mutually incompatible flavors, a native glibc
  790. * flavor that always returns a non-null char pointer that must be used
  791. * directly, and a POSIX flavor that returns an error int, and iff success,
  792. * stores an error string in the supplied buffer. this is all most
  793. * infelicitous...
  794. */
  795. #if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
  796. (defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \
  797. ((defined(__GLIBC__) && (__GLIBC__ >= 2)) || \
  798. (defined(__USE_XOPEN2K) && \
  799. defined(_POSIX_C_SOURCE) && \
  800. (_POSIX_C_SOURCE >= 200112L)))
  801. char errno_buf[64], *errno_string;
  802. /* precisely mirror the gate used in glibc string.h */
  803. #if defined __USE_XOPEN2K && !defined __USE_GNU
  804. if (strerror_r(WC_TEST_RET_DEC_I(es),
  805. errno_buf, sizeof(errno_buf)) != 0)
  806. XSTRLCPY(errno_buf, "?", sizeof(errno_buf));
  807. errno_string = errno_buf;
  808. #else
  809. errno_string = strerror_r(WC_TEST_RET_DEC_I(es),
  810. errno_buf, sizeof(errno_buf));
  811. #endif
  812. err_sys_printf("%s error L=%d errno=%d (%s)\n", msg,
  813. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es),
  814. errno_string);
  815. #else /* can't figure out how to strerror_r(), or don't want error strings */
  816. err_sys_printf("%s error L=%d errno=%d\n", msg,
  817. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es));
  818. #endif
  819. break;
  820. }
  821. case WC_TEST_RET_TAG_I:
  822. err_sys_printf("%s error L=%d i=%d\n", msg,
  823. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es));
  824. break;
  825. }
  826. #undef err_sys_printf
  827. }
  828. static void print_fiducials(void);
  829. #ifdef HAVE_STACK_SIZE
  830. static THREAD_RETURN err_sys(const char* msg, int es)
  831. #else
  832. static wc_test_ret_t err_sys(const char* msg, wc_test_ret_t es)
  833. #endif
  834. {
  835. render_error_message(msg, es);
  836. print_fiducials();
  837. #ifdef WOLFSSL_LINUXKM
  838. EXIT_TEST(es);
  839. #else
  840. EXIT_TEST(-1);
  841. #endif
  842. }
  843. #ifndef HAVE_WOLFCRYPT_TEST_OPTIONS
  844. /* func_args from test.h, so don't have to pull in other stuff */
  845. typedef struct func_args {
  846. int argc;
  847. char** argv;
  848. wc_test_ret_t return_code;
  849. } func_args;
  850. #endif /* !HAVE_WOLFCRYPT_TEST_OPTIONS */
  851. #if defined(HAVE_FIPS) && !defined(WOLFSSL_LINUXKM)
  852. static void myFipsCb(int ok, int err, const char* hash)
  853. {
  854. printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
  855. printf("message = %s\n", wc_GetErrorString(err));
  856. printf("hash = %s\n", hash);
  857. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  858. printf("In core integrity hash check failure, copy above hash\n");
  859. printf("into verifyCore[] in fips_test.c and rebuild\n");
  860. }
  861. }
  862. #endif /* HAVE_FIPS && !WOLFSSL_LINUXKM */
  863. #ifdef WOLFSSL_STATIC_MEMORY
  864. #if defined(WOLFSSL_STATIC_MEMORY_TEST_SZ)
  865. static byte gTestMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  866. #elif defined(BENCH_EMBEDDED)
  867. static byte gTestMemory[14000];
  868. #elif defined(WOLFSSL_CERT_EXT)
  869. static byte gTestMemory[140000];
  870. #elif (defined(WOLFSSL_SP_MATH_ALL) || defined(USE_FAST_MATH)) && \
  871. !defined(ALT_ECC_SIZE)
  872. static byte gTestMemory[160000];
  873. #else
  874. static byte gTestMemory[80000];
  875. #endif
  876. #endif
  877. #ifdef WOLFSSL_PB
  878. static int wolfssl_pb_print(const char* msg, ...)
  879. {
  880. int ret;
  881. va_list args;
  882. char tmpBuf[80];
  883. va_start(args, msg);
  884. ret = vsprint(tmpBuf, msg, args);
  885. va_end(args);
  886. fnDumpStringToSystemLog(tmpBuf);
  887. return ret;
  888. }
  889. #endif /* WOLFSSL_PB */
  890. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  891. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  892. /* Enable support for RNG with crypto callback */
  893. static int rng_crypto_cb(int thisDevId, wc_CryptoInfo* info, void* ctx)
  894. {
  895. int rc = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  896. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  897. rc = wc_GenerateSeed(&info->rng.rng->seed, info->rng.out, info->rng.sz);
  898. }
  899. (void)ctx;
  900. (void)thisDevId;
  901. return rc;
  902. }
  903. #endif
  904. #if defined(WC_KDF_NIST_SP_800_56C)
  905. #define INIT_SP80056C_TEST_VECTOR(_z, _fixedInfo, _derivedKey, _hashType) \
  906. { \
  907. .z = (const byte*)_z, .zSz = sizeof(_z) - 1, \
  908. .fixedInfo = (const byte*)_fixedInfo, \
  909. .fixedInfoSz = sizeof(_fixedInfo) - 1, \
  910. .derivedKey = (const byte*)_derivedKey, \
  911. .derivedKeySz = sizeof(_derivedKey) - 1, .hashType = _hashType, \
  912. }
  913. #define SP800_56C_MAX_OUT 128
  914. static WOLFSSL_TEST_SUBROUTINE wc_test_ret_t nist_sp80056c_kdf_test(void)
  915. {
  916. struct sp800_56c_test_vector {
  917. const byte* z;
  918. word32 zSz;
  919. const byte* fixedInfo;
  920. word32 fixedInfoSz;
  921. const byte* derivedKey;
  922. word32 derivedKeySz;
  923. enum wc_HashType hashType;
  924. };
  925. struct sp800_56c_test_vector* v;
  926. byte output[SP800_56C_MAX_OUT];
  927. word32 i;
  928. int ret;
  929. /* vectors from
  930. * https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
  931. *
  932. * (KeyManagement) */
  933. struct sp800_56c_test_vector vctors[] = {
  934. #if !defined(NO_SHA)
  935. /* SHA-1 */
  936. INIT_SP80056C_TEST_VECTOR(
  937. "\xad\x42\x01\x82\x63\x3f\x85\x26\xbf\xe9\x54\xac\xda\x37\x6f\x05"
  938. "\xe5\xff\x4f\x83\x7f\x54\xfe\xbe\x0f\xb1\x2a\x1b\x3b\xeb\xf2\x63"
  939. "\xee\x21\x64\x13\xed\x06\xa8\x4a\x12\xeb\x51\x11\x59\xf1\x33\x7d",
  940. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  941. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  942. "\x6f\xef\x44\x2f\xc1\x7a\x7e\x2b\x0c\x9d\xec\xe0\xe4\x7a\x57\x48"
  943. "\xac\xb4\x6a\xf1\x98\xd7\x67\x47\x0f\x28\xa1\x04\xb5\x61\x30\xae"
  944. "\xb0\x10\x09\xa4\x56\x82\xa5\xe1",
  945. WC_HASH_TYPE_SHA),
  946. INIT_SP80056C_TEST_VECTOR(
  947. "\xae\x64\xab\x2b\x2b\x75\xa9\x4c\xf8\xef\x24\xda\x24\x56\xbd\x3a"
  948. "\xa3\x6d\xb6\x14\x29\xea\x55\x21",
  949. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  950. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  951. "\xcc\x96\x5a\x52\xd0\x5c\x94\x9e\x52\xc0\x35\xfd\x03\x53\x0d\xb7"
  952. "\xea\xa4\x08\x70\x2c\x9d\x35\x21\x1e\x67\x21\x54\x12\x45\x91\x51"
  953. "\xba\x22\x62\xbd\x1e\x28\xe5\x6b",
  954. WC_HASH_TYPE_SHA),
  955. INIT_SP80056C_TEST_VECTOR(
  956. "\x71\x5d\xc0\xea\x24\x6b\x46\x56\x63\xa8\x9c\xde\x04\x12\xc1\x92"
  957. "\xe1\x9e\x58\xd5\xb0\xb6\x36\x6d\xa7\x89\xad\xbf\x44\x9a\x38\xaa"
  958. "\x46\x69\xfe\x36\x30\xa2\x0f\x7f\xa3\x14\x9c\x9b\x4b\x0a\xb5\xcd"
  959. "\x3e\x14\x18\x2b\x75\x04\xd5\xd2\x75\x2b\xf6\x58\x7a\xab\xc9\xf4"
  960. "\xcb\x8f\xe5\x29\x23\x6a\xb8\x15\x36\xad\xd2\xbd\x25\xd6\xbf\x9d"
  961. "\x5f\x1d\xf5\x76\x16\x5a\xa5\x5c\x24\x99\x61\xd8\xf8\x75\x00\xed"
  962. "\x8d\xbf\xc5\xd2\x50\x53\x4c\x07\xd9\x9a\xc9\x17\xf9\x84\x60\x46"
  963. "\xac\x5c\xb8\xa2\x98\x74\x26\x22\xd3\xc9\x86\x18\x06\x92\x46\xe8"
  964. "\xad\x37\x11\x25\x57\xe0\xe6\x34\xb5\x81\x32\x7a\x4a\xd3\x2c\x7c"
  965. "\x76\x4b\xe8\xf8\x08\x0d\x37\x2c\x63\x20\x93\xa7\x67\xf1\x55\xbd"
  966. "\x22\xec\x00\x3c\xa6\x1c\x8b\x43\x32\x0f\x3a\xbe\xb5\xdd\xc4\xa3"
  967. "\xb1\x89\x82\xfd\xd6\x51\x0f\x88\x3c\x8d\xc1\xe0\xb1\x57\xff\xb9"
  968. "\xcf\xc0\xa5\x9c\xe2\xd4\x05\x5f\xfc\x73\xe7\x15\x2a\x6a\x95\x43"
  969. "\xb9\x19\xe7\x94\xe9\x49\x61\x33\xbe\x2a\x23\x18\xd9\x05\x6e\xfd"
  970. "\x74\x48\x2d\xc6\x3c\x0d\xb5\x8f\xe6\x42\x6b\x0f\xe7\x35\x45\x42"
  971. "\xc2\x19\x7a\xb6\xbd\x35\xf1\xa9\x2d\xce\x90\xb1\xc4\x6d\x32\xc1",
  972. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  973. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  974. "\x1b\x5f\xcc\x8d\x81\xa5\xd9\xa9\x36\x94\xe6\x47\x77\x88\xd8\x03"
  975. "\x15\x84\xc3\xf5\x2e\x9f\x11\x7a\xe8\x18\x4d\xba\x56\x47\x9d\x87"
  976. "\x66\x76\x92\xf1\x2d\x7b\xd3\x8b",
  977. WC_HASH_TYPE_SHA),
  978. INIT_SP80056C_TEST_VECTOR(
  979. "\x33\xe0\x50\xbd\x20\x9f\x2d\xf2\x77\x19\x78\xfc\xd1\xd4\xc8\x2e"
  980. "\x49\xd0\x1d\x65\xbb\x62\x03\x20\xd3\x0b\xfe\xa8\x7a\xa8\x69\xe1"
  981. "\x07\xa5\x17\xa4\xc8\x5b\x69\x28\x45\x21\xca\x54\xb7\x7f\x59\xe9"
  982. "\x4a\x85\x6d\xaa\x30\xa3\x85\xa5\x25\xd8\xa3\xf7\xe1\x5e\xe5\xe9"
  983. "\xaa\x12\x8d\x45\xef\x63\xf9\x0c\x10\xe0\x8f\xc5\x26\x36\x13\x77"
  984. "\x81\x54\x7a\x58\x9f\x97\x87\xf9\xd7\xdd\x61\x43\x41\x9a\x26\x16"
  985. "\x80\x16\x82\x40\xaa\xb2\x01\x3d\x80\x20\xdb\xe8\x4b\x7e\x2b\xed"
  986. "\xce\x67\x1b\x94\x03\xbd\x1f\x91\x71\xa2\x57\x90\xce\x66\x7d\xed",
  987. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  988. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  989. "\x35\x10\x85\x85\xfc\x55\x62\xb5\xf1\x8f\x20\x7b\xa8\x35\x63\xe4"
  990. "\x49\x28\x45\x6a\x5e\x53\x63\x7e\xae\x6b\xb5\xfc\x33\x88\xae\x02"
  991. "\x91\x79\x0a\x1d\xc8\x31\x4e\x28",
  992. WC_HASH_TYPE_SHA),
  993. INIT_SP80056C_TEST_VECTOR(
  994. "\x5c\x80\x4f\x45\x4d\x30\xd9\xc4\xdf\x85\x27\x1f\x93\x52\x8c\x91"
  995. "\xdf\x6b\x48\xab\x5f\x80\xb3\xb5\x9c\xaa\xc1\xb2\x8f\x8a\xcb\xa9"
  996. "\xcd\x3e\x39\xf3\xcb\x61\x45\x25\xd9\x52\x1d\x2e\x64\x4c\x53\xb8"
  997. "\x07\xb8\x10\xf3\x40\x06\x2f\x25\x7d\x7d\x6f\xbf\xe8\xd5\xe8\xf0"
  998. "\x72\xe9\xb6\xe9\xaf\xda\x94\x13\xea\xfb\x2e\x8b\x06\x99\xb1\xfb"
  999. "\x5a\x0c\xac\xed\xde\xae\xad\x7e\x9c\xfb\xb3\x6a\xe2\xb4\x20\x83"
  1000. "\x5b\xd8\x3a\x19\xfb\x0b\x5e\x96\xbf\x8f\xa4\xd0\x9e\x34\x55\x25"
  1001. "\x16\x7e\xcd\x91\x55\x41\x6f\x46\xf4\x08\xed\x31\xb6\x3c\x6e\x6d",
  1002. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1003. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1004. "\xfa\xa0\x22\xce\x7f\xa9\xba\x95\xeb\xa3\x9f\x3f\x44\xf3\xee\x14"
  1005. "\x96\x0a\x0b\x23\x9d\x01\x4b\x57\x70\xe4\x71\xd7\x5a\x99\xea\x87"
  1006. "\x10\xe3\x8f\x0c\xef\x0f\xfc\x67",
  1007. WC_HASH_TYPE_SHA),
  1008. INIT_SP80056C_TEST_VECTOR(
  1009. "\xad\x42\x01\x82\x63\x3f\x85\x26\xbf\xe9\x54\xac\xda\x37\x6f\x05"
  1010. "\xe5\xff\x4f\x83\x7f\x54\xfe\xbe\x0f\xb1\x2a\x1b\x3b\xeb\xf2\x63"
  1011. "\xee\x21\x64\x13\xed\x06\xa8\x4a\x12\xeb\x51\x11\x59\xf1\x33\x7d",
  1012. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1013. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1014. "\x6f\xef\x44\x2f\xc1\x7a\x7e\x2b\x0c\x9d\xec\xe0\xe4\x7a\x57\x48"
  1015. "\xac\xb4\x6a\xf1\x98\xd7\x67\x47\x0f\x28\xa1\x04\xb5\x61\x30\xae"
  1016. "\xb0\x10\x09\xa4\x56\x82\xa5\xe1",
  1017. WC_HASH_TYPE_SHA),
  1018. #endif
  1019. #if defined(WOLFSSL_SHA224)
  1020. /* SHA-224*/
  1021. INIT_SP80056C_TEST_VECTOR(
  1022. "\x8c\x5d\x6e\x5d\x36\x06\x83\xba\x55\xb0\x9d\xb1\x69\x6d\x7c\x64"
  1023. "\x02\xff\x87\x88\x5f\xf5\x07\x70\xf2\x76\x7b\x75\x54\x60\x20\x7e"
  1024. "\xd5\xc7\x43\xfd\x27\xe7\xeb\x1d\x0c\xa5\x91\xf8\x56\x38\x93\x11"
  1025. "\x73\x07\x44\xf2\x04\xd2\xe5\x5b\x8b\xd4\x46\xce\xca\x03\x1f\x7b"
  1026. "\xac\xcf\xf1\xa7\x1b\x68\x34\x59\xcc\x54\xd5\x01\xda\xbf\x4a\x84"
  1027. "\xcd\xb8\x6d\xfa\xda\xff\x31\x0f\xbd\xba\xf7\x4d\xd5\x1b\xa1\xe1"
  1028. "\xe1\x19\x1a\xf1\x4c\x9b\xf8\x94\x43\xbf\x58\x8e\x9c\xe3\x30\x34"
  1029. "\xaf\x5e\x89\xbf\x6f\xfc\x47\xd7\xd9\xca\x4a\x5e\x8f\xf8\xa0\x50"
  1030. "\x20\xbb\x0f\x95\xbc\xde\x01\x56\xd8\x7f\xb8\x60\xbd\x40\x83\xfa"
  1031. "\x5b\x53\x1a\x08\xa4\xfb\x7e\xe0\x20\x1a\xe8\xb3\xcc\xff\xe9\x9f"
  1032. "\x27\x0b\xc3\x53\x4b\xaa\xcf\xc0\x01\xcd\xd8\x0a\xd8\x7c\xce\x71"
  1033. "\xf0\x91\xe7\x66\xca\x5c\xc2\x75\xcb\x49\x14\x5a\x5e\xe6\x16\x2e"
  1034. "\xcc\xf5\x58\xce\xc4\xd3\xee\x53\x1e\x91\xe9\xa5\x29\x69\x63\x4d"
  1035. "\x3a\xf8\xd2\x6f\x8d\x15\xdc\x0d\x6f\x6e\x0a\x97\x4b\xe4\x34\x1b"
  1036. "\x68\xa0\x19\x90\xdb\xb8\x64\x95\x89\x1a\xd3\xaf\xc1\xe4\xce\xdf"
  1037. "\x4c\x6a\xe1\xf1\xcd\x60\x81\xcd\xee\xd8\xe6\xb3\x26\x4e\xc3\xbe"
  1038. "\x24\x58\xd1\xc0\xca\x24\x43\x41\x0c\xf3\xb4\x7c\x0c\x25\x4c\x7d"
  1039. "\xc8\xec\xb4\x3e\x6c\x23\x64\xe1\xc0\x62\x19\xcc\x7e\xfb\xff\xbb"
  1040. "\x63\xd7\xff\xfc\x74\x58\x12\xfd\x24\x0c\x33\xd4\x96\xb9\x99\x2f"
  1041. "\x96\x80\xa6\x3c\x07\x96\x3c\x0c\x49\xf3\xc1\xba\xef\xec\xaf\x32"
  1042. "\xe2\xaa\x8a\x2f\x7c\xd3\x0d\x8f\x05\x1e\xe2\xf5\x0f\xbf\x05\xab"
  1043. "\x13\x96\xa4\xea\x87\x44\x7d\x7b\x98\x1b\x5e\x46\x14\x28\x18\x71"
  1044. "\xa6\xf0\xf6\xbf\x1f\xe0\x02\x2f\x7e\xa1\x32\xbe\x0a\xe9\x19\x26"
  1045. "\xab\x12\xaf\x6d\xc4\x50\x64\xaa\xd5\x6b\x84\xb9\x0c\x70\x08\x37"
  1046. "\x09\xcf\xf7\xe3\x1b\x54\x8f\xb7\xfb\x2c\xf7\x5a\xbf\x96\xe0\x1c"
  1047. "\xcd\x3e\x94\x2e\xed\x91\x48\x0d\x4c\x24\xc6\xb7\xf9\x79\xfb\xbe"
  1048. "\x5d\xa2\x39\xb3\x76\x16\x7d\x68\x57\x35\x24\xff\xcb\x50\x99\x54"
  1049. "\xcc\x80\xa0\xe1\xa7\x1c\x40\xc4\xda\x17\xb8\xd1\x57\x2b\x21\x58"
  1050. "\x7a\x8d\x66\xcc\x62\x1c\x7c\xd1\x0f\x49\xab\xd5\xef\x86\x31\x13"
  1051. "\xe6\x19\x21\x08\x6f\xac\x25\x31\x2b\x74\x1c\x11\xa8\xfb\xc1\xe3"
  1052. "\x3c\x34\xd9\xda\x14\xa8\x22\x47\x7f\xcc\x36\x66\x70\x25\xc4\xf1"
  1053. "\x30\xae\x10\x0e\x36\xf1\x5d\xa0\x03\x74\xce\x87\x41\x67\x9f\x61",
  1054. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1055. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1056. "\x4b\x99\x6a\x60\xc0\x4a\x35\xc5\xe6\xd4\x74\xb1\x0a\x25\x8d\x56"
  1057. "\x2e\xa6\xdc\x52\xf6\xc6\x9b\xf3\x9e\xf8\x8c\x89\xe3\xcc\x8a\x54"
  1058. "\xda\x2f\x3c\x0b\x56\x1b\x53\xfe\x76\x55\x13\x63\xd6\x9c\x3c\xef"
  1059. "\x74\xe3\x4f\xe8\x8e\xb3\xac\x51",
  1060. WC_HASH_TYPE_SHA224),
  1061. INIT_SP80056C_TEST_VECTOR(
  1062. "\x52\x27\x2f\x50\xf4\x6f\x4e\xdc\x91\x51\x56\x90\x92\xf4\x6d\xf2"
  1063. "\xd9\x6e\xcc\x3b\x6d\xc1\x71\x4a\x4e\xa9\x49\xfa\x9f\x18\xff\x54"
  1064. "\xf8\x87\x23\x07\x3f\x64\xa6\x95\x3d\x04\x91\x4f\x45\xa2\x3e\xee"
  1065. "\x7c\xfc\x46\x67\x08\x0a\xa0\xf9",
  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. "\x77\x56\xbc\xfd\xef\x3e\xe6\x9f\x6a\xc2\x3c\xd2\xdc\x60\x7d\x01"
  1069. "\xfa\x8c\xe1\xb2\x4f\x5c\xaa\xaa\x48\xe0\x4b\x81\x63\xe1\x73\x3a"
  1070. "\xed\x7a\x04\x0e\x73\xf2\xb5\x42\x36\x8f\x00\x54\x8b\x16\x3c\x3d"
  1071. "\xc9\x6d\x70\x09\x99\x16\xf1\x6b",
  1072. WC_HASH_TYPE_SHA224),
  1073. #endif
  1074. #if !defined(NO_SHA256)
  1075. /* SHA-256 */
  1076. INIT_SP80056C_TEST_VECTOR(
  1077. "\xdd\x0f\x53\x96\x21\x9d\x1e\xa3\x93\x31\x04\x12\xd1\x9a\x08\xf1"
  1078. "\xf5\x81\x1e\x9d\xc8\xec\x8e\xea\x7f\x80\xd2\x1c\x82\x0c\x27\x88"
  1079. "\x22\x76\x84\xe7\x1f\x5c\x31\x3f\xad\xc9\x1e\x52\x98\x07\xe3\x14"
  1080. "\x7d\x53\x14\x5b\x15\xab\xd6\xed\x41\x6a\xd3\x5c\xd7\xe6\x83\x8f",
  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. "\xc0\x8b\x3d\xe2\x4f\x1a\x38\x1e\x7a\x56\x75\xa2\xa6\x52\x3b\x08"
  1084. "\xf3\x54\x60\x5e\xee\x46\xb9\xf3\x9e\xad\xb1\xe9\x75\x34\x41\x6d"
  1085. "\x98\xb4\x3c\xae\x8a\xb0\x4a\xfd\x53\xde\xb3\x7f\x44\x02\x23\x52"
  1086. "\xc3\xfb\xde\x1e\x2f\x2c\xec\x53\x1c\xfc\x32\x4f\xdd\x0f\xcc\xa6",
  1087. WC_HASH_TYPE_SHA256),
  1088. INIT_SP80056C_TEST_VECTOR(
  1089. "\x44\xf4\x84\x09\xf3\x1b\xf3\x50\x94\x51\xdb\x4d\x30\x4b\xeb\xd8"
  1090. "\x3c\x2a\xd6\x50\x1c\x1b\x85\xe6\x32\xbc\x92\x58\x8e\x2d\x48\xb5"
  1091. "\xd2\xb8\x44\x44\x62\xad\x94\xe8\xa4\x44\x94\x1e\xd4\x97\x5c\x97"
  1092. "\x91\x17\xd7\x5a\x0a\x2b\xa8\x10\xdf\xa8\x80\x4a\x0f\xe9\x42\x6d"
  1093. "\xd7\xeb\x95\xf2\x9c\xa4\x30\xda\x37\xef\xa5\x2c\x42\xda\x1d\xe2"
  1094. "\x23\x76\x3b\xdd\xc9\x5e\x46\x6a\xa3\xb8\xd2\x06\xb8\x21\x8e\xdf"
  1095. "\x23\x97\x3d\x05\xf3\xc7\xc2\x2b\x22\x46\x53\xd4\xf9\x21\x85\x45"
  1096. "\x79\x83\x26\x2f\x27\xbc\x55\xa0\xa7\xae\xe5\x43\x54\x55\xd4\x3c"
  1097. "\x0e\x0c\x6d\x80\x67\xad\xaf\x90\x42\xb6\xb7\x77\x7e\x19\x8d\x67"
  1098. "\x60\x83\x0d\x96\xb2\x9a\x6a\xae\xf5\x74\xd7\x5e\x2d\x65\x43\x55"
  1099. "\x0f\x75\x55\xcf\x89\x82\xc8\x21\xc4\xec\x9b\x82\x66\x2b\x09\x36"
  1100. "\x69\xfd\x24\x6d\x4d\xcc\xbf\xf3\x1d\x98\x4e\xf6\x3c\x4f\x95\xd7"
  1101. "\x39\xc7\x7e\x66\xf6\x9b\x6d\xb0\xd9\xfc\x1a\x97\x3f\x52\x33\xd1"
  1102. "\x1f\xe7\x15\x4b\x8a\x6b\xe1\x50\x46\x7d\x92\xda\xf0\x91\x44\x34"
  1103. "\xf0\xcf\x17\x6e\x96\x1b\x31\x3f\xe3\xe2\x3b\xfe\x37\x8b\x87\xba"
  1104. "\xf2\x73\x93\x7f\xfa\xa6\x85\x65\x8b\x09\x78\x1d\x26\x97\x86\x4b"
  1105. "\x0d\x82\x48\x5c\xf7\xd6\x2f\xfc\xea\x34\x33\x88\xcf\xec\x15\x27"
  1106. "\x3a\x39\x4b\x84\x32\xee\xb6\x32\x1b\xe3\x1d\x4f\xcd\x16\x15\xc8"
  1107. "\x1c\x69\x37\xc0\x8d\x92\x41\x6e\xdb\xdd\x20\x10\xfa\x8b\x6e\x0a"
  1108. "\x8a\x60\x3d\xad\xe0\x10\xbc\x9c\xd7\x6b\x14\xe3\xe2\x19\x0e\x3b"
  1109. "\xa3\x00\xe7\x1a\xdd\xbf\x24\x4c\xf8\x06\x29\x49\x76\xea\xf0\x7d"
  1110. "\x02\x3b\xdb\x57\xfc\x5d\x19\x64\xc7\xd4\x20\x6e\x72\x06\x1b\xfe"
  1111. "\x1e\xe4\xee\xbc\x92\x00\xe1\x3a\x6c\xba\x32\x86\x9d\xbe\x80\x82"
  1112. "\xcd\xf3\x64\x5b\x5a\x72\x7d\xd2\x7c\xa5\x03\xf4\xed\xeb\x73\xe8"
  1113. "\x8a\x3a\x55\x2c\x7e\x00\xd4\xee\x72\x42\x13\x72\x36\xa0\x96\x5c"
  1114. "\x1e\xc3\xeb\xc0\xb4\x8c\x2b\x46\x7e\xb8\x42\x41\x5a\x28\x3f\x55"
  1115. "\xe2\x20\xff\xd1\x88\x19\x25\x6d\xa2\x47\x4d\x28\xfc\x3b\x04\xe0"
  1116. "\xc0\x7e\x4d\x25\xc1\x74\x93\x41\xd2\x22\x97\x01\x5c\xd8\x17\x8c"
  1117. "\x39\x18\xbe\x8c\x5c\xdf\x0f\xbf\xbb\x9a\x5a\xcc\xdd\x82\xaf\x07"
  1118. "\x83\xef\xe4\xdf\x64\xa8\xd8\x92\x82\x8f\x8d\xe5\x8c\x5d\x56\x9b"
  1119. "\x5b\x08\x45\x58\x96\xc4\xd3\xc3\x4f\xd3\xce\x93\xc4\x34\xc3\x8e"
  1120. "\xf5\x6c\xed\x30\x56\x1c\x37\x1a\xf9\xf2\xd8\x64\xfd\xc5\xb6\x2f",
  1121. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1122. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1123. "\x42\x35\xac\x89\xc9\xf3\x3e\x5d\xbb\x11\x60\x1a\x29\x83\xe3\x76"
  1124. "\xe2\x15\x39\x97\x87\xd8\x39\xa0\x38\x55\xfe\x04\x53\x3e\x1a\x67"
  1125. "\x66\x91\x5e\x67\xc2\x5e\xeb\x04\x08\x28\xe9\x6c\xd3\xd6\xef\x0a"
  1126. "\xb7\xd1\x7b\x43\x13\x43\xa7\xf3\xaa\xc6\x8f\x0c\x4a\x7e\x77\x9b",
  1127. WC_HASH_TYPE_SHA256),
  1128. /* slightly modified vector to test generation when derivedKeySz %
  1129. * hashOutSz != 0*/
  1130. INIT_SP80056C_TEST_VECTOR(
  1131. "\xdd\x0f\x53\x96\x21\x9d\x1e\xa3\x93\x31\x04\x12\xd1\x9a\x08\xf1"
  1132. "\xf5\x81\x1e\x9d\xc8\xec\x8e\xea\x7f\x80\xd2\x1c\x82\x0c\x27\x88"
  1133. "\x22\x76\x84\xe7\x1f\x5c\x31\x3f\xad\xc9\x1e\x52\x98\x07\xe3\x14"
  1134. "\x7d\x53\x14\x5b\x15\xab\xd6\xed\x41\x6a\xd3\x5c\xd7\xe6\x83\x8f",
  1135. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1136. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1137. "\xc0\x8b\x3d\xe2\x4f\x1a\x38\x1e\x7a\x56\x75\xa2\xa6\x52\x3b\x08"
  1138. "\xf3\x54\x60\x5e\xee\x46\xb9\xf3\x9e\xad\xb1\xe9\x75\x34\x41\x6d"
  1139. "\x98\xb4\x3c\xae\x8a\xb0\x4a\xfd\x53\xde\xb3\x7f\x44\x02\x23\x52"
  1140. "\xc3\xfb\xde\x1e\x2f\x2c\xec\x53\x1c\xfc\x32\x4f\xdd\x0f\xcc",
  1141. WC_HASH_TYPE_SHA256),
  1142. #endif
  1143. #if defined(WOLFSSL_SHA384)
  1144. /* SHA-384 */
  1145. INIT_SP80056C_TEST_VECTOR(
  1146. "\x5e\xa1\xfc\x4a\xf7\x25\x6d\x20\x55\x98\x1b\x11\x05\x75\xe0\xa8"
  1147. "\xca\xe5\x31\x60\x13\x7d\x90\x4c\x59\xd9\x26\xeb\x1b\x84\x56\xe4"
  1148. "\x27\xaa\x8a\x45\x40\x88\x4c\x37\xde\x15\x9a\x58\x02\x8a\xbc\x0e"
  1149. "\x88\x76\x9c\xb7\x2f\xc5\xac\x45\x7c\xd5\x8e\x89\x08\x9b\x19\x6a"
  1150. "\x70\xbf\x53\x3c\x6d\xc9\x1c\x9c\x7e\x17\x41\xdb\x5e\x7a\xb6\xb0"
  1151. "\x84\x9f\x01\xde\xa6\x5f\xed\xd0\x6c\x77\x18\x7c\xd8\x8e\xd0\x30",
  1152. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1153. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1154. "\x8e\x6e\x26\x5f\x20\x82\xf1\x4d\x34\xda\x23\xe1\x03\x2c\x90\x24"
  1155. "\x83\x4a\xf0\x15\x72\xb6\x64\x77\x82\x41\x1b\xdd\xcb\x84\xa5\xda"
  1156. "\xee\x11\x7b\xa6\xfb\xa6\xd0\xeb\x28\x08\xef\x8a\xb0\x70\x05\xee"
  1157. "\xab\xe5\x2d\x2e\xfd\x31\x12\x1c\x7b\xf9\xd5\xfa\xfc\x40\xe0\x0c"
  1158. "\x6d\x6d\xbf\x39\xef\x43\xfe\x97\x15\xc7\x20\x2c\xdc\x2d\xb7\xe8"
  1159. "\x2b\x88\xd7\x48\xeb\x84\x25\x8b\xf8\x4d\x85\x82\xf2\xbf\xd9\x40",
  1160. WC_HASH_TYPE_SHA384),
  1161. #endif
  1162. #if defined(WOLFSSL_SHA512)
  1163. /* SHA-512 */
  1164. INIT_SP80056C_TEST_VECTOR(
  1165. "\x00\xcd\xea\x89\x62\x1c\xfa\x46\xb1\x32\xf9\xe4\xcf\xe2\x26\x1c"
  1166. "\xde\x2d\x43\x68\xeb\x56\x56\x63\x4c\x7c\xc9\x8c\x7a\x00\xcd\xe5"
  1167. "\x4e\xd1\x86\x6a\x0d\xd3\xe6\x12\x6c\x9d\x2f\x84\x5d\xaf\xf8\x2c"
  1168. "\xeb\x1d\xa0\x8f\x5d\x87\x52\x1b\xb0\xeb\xec\xa7\x79\x11\x16\x9c"
  1169. "\x20\xcc\x01\x38\xa6\x72\xb6\x95\x8b\xd7\x84\xe5\xd7\xfa\x83\x73"
  1170. "\x8a\xc6\x8f\x9b\x34\x23\xb4\x83\xf9\xbf\x53\x9e\x71\x14\x1e\x45"
  1171. "\xdb\xfb\x7a\xfe\xd1\x8b\x11\xc0\x02\x8b\x13\xf1\xf8\x60\xef\x43"
  1172. "\xc4\x80\xf4\xda\xcd\xa2\x08\x10\x59\xd3\x97\x8c\x99\x9d\x5d\x1a"
  1173. "\xde\x34\x54\xe4",
  1174. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1175. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1176. "\x2d\x4a\x46\xa1\x70\x99\xba\xa8\x33\x0b\xc5\x9d\x4a\x1c\xf5\xae"
  1177. "\x3a\x30\x75\xb4\xc6\x2b\xb2\x6e\x7f\xc9\x89\x24\x72\x6d\x27\x4c"
  1178. "\x09\x64\x6f\x44\x08\xe6\x85\x8c\x43\xb4\x2d\xae\xd0\x15\xef\x26"
  1179. "\x17\x08\xd5\x5e\xf2\x4d\xaa\x7d\x3e\xa3\xd1\xc4\xa0\x8c\xfd\x24"
  1180. "\xdb\x60\x00\xa5\xb8\xa6\x7d\xe7\x46\xf3\xd3\xf4\xff\x34\x85\x15"
  1181. "\x8f\xd3\xb6\x91\x55\x79\x1d\xf4\x67\x47\xd4\xdb\xbe\x17\xc4\xb5"
  1182. "\x58\x46\x2e\x26\xbe\x5e\xd3\x5f\xe6\x80\xe2\x97\x14\x22\xc3\xb0"
  1183. "\x1b\x17\xe1\x67\xfc\x43\x7f\x84\x86\x9d\x85\x49\x53\x7b\x33\x38",
  1184. WC_HASH_TYPE_SHA512),
  1185. #endif
  1186. INIT_SP80056C_TEST_VECTOR(
  1187. "\x00\xcd\xea\x89\x62\x1c\xfa\x46\xb1\x32\xf9\xe4\xcf\xe2\x26\x1c"
  1188. "\xde\x2d\x43\x68\xeb\x56\x56\x63\x4c\x7c\xc9\x8c\x7a\x00\xcd\xe5"
  1189. "\x4e\xd1\x86\x6a\x0d\xd3\xe6\x12\x6c\x9d\x2f\x84\x5d\xaf\xf8\x2c"
  1190. "\xeb\x1d\xa0\x8f\x5d\x87\x52\x1b\xb0\xeb\xec\xa7\x79\x11\x16\x9c"
  1191. "\x20\xcc\x01\x38\xa6\x72\xb6\x95\x8b\xd7\x84\xe5\xd7\xfa\x83\x73"
  1192. "\x8a\xc6\x8f\x9b\x34\x23\xb4\x83\xf9\xbf\x53\x9e\x71\x14\x1e\x45"
  1193. "\xdb\xfb\x7a\xfe\xd1\x8b\x11\xc0\x02\x8b\x13\xf1\xf8\x60\xef\x43"
  1194. "\xc4\x80\xf4\xda\xcd\xa2\x08\x10\x59\xd3\x97\x8c\x99\x9d\x5d\x1a"
  1195. "\xde\x34\x54\xe4",
  1196. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1197. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1198. "\x2d\x4a",
  1199. WC_HASH_TYPE_SHA512),
  1200. };
  1201. for (i = 0; i < sizeof(vctors) / sizeof(vctors[0]); i++) {
  1202. v = &vctors[i];
  1203. ret = wc_KDA_KDF_onestep(v->z, v->zSz, v->fixedInfo, v->fixedInfoSz,
  1204. v->derivedKeySz, v->hashType, output,
  1205. /* use derivedKeySz to force the function to use a temporary buff
  1206. for the last block */
  1207. v->derivedKeySz);
  1208. if (ret != 0)
  1209. return WC_TEST_RET_ENC_EC(ret);
  1210. if (XMEMCMP(output, v->derivedKey, v->derivedKeySz) != 0)
  1211. return WC_TEST_RET_ENC_NC;
  1212. }
  1213. /* negative tests */
  1214. ret = wc_KDA_KDF_onestep(NULL, 0, (byte*)"fixed_info",
  1215. sizeof("fixed_info"), 16, WC_HASH_TYPE_SHA256, output, 16);
  1216. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  1217. return WC_TEST_RET_ENC_NC;
  1218. ret = wc_KDA_KDF_onestep((byte*)"secret", sizeof("secret"), NULL, 1, 16,
  1219. WC_HASH_TYPE_SHA256, output, 16);
  1220. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  1221. return WC_TEST_RET_ENC_NC;
  1222. /* allow empty FixedInfo */
  1223. ret = wc_KDA_KDF_onestep((byte*)"secret", sizeof("secret"), NULL, 0, 16,
  1224. WC_HASH_TYPE_SHA256, output, 16);
  1225. if (ret != 0)
  1226. return WC_TEST_RET_ENC_EC(ret);
  1227. return 0;
  1228. }
  1229. #endif /* WC_KDF_NIST_SP_800_56C */
  1230. /* optional macro to add sleep between tests */
  1231. #ifndef TEST_SLEEP
  1232. #define TEST_SLEEP() WC_DO_NOTHING
  1233. #else
  1234. #define TEST_PASS test_pass
  1235. #include <stdarg.h> /* for var args */
  1236. static WC_INLINE void test_pass(const char* fmt, ...)
  1237. {
  1238. va_list args;
  1239. va_start(args, fmt);
  1240. STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK(max_relative_stack, vprintf(fmt, args));
  1241. va_end(args);
  1242. PRINT_HEAP_CHECKPOINT();
  1243. TEST_SLEEP();
  1244. ASSERT_RESTORED_VECTOR_REGISTERS(exit(1););
  1245. }
  1246. #endif
  1247. /* set test pass output to printf if not overridden */
  1248. #ifndef TEST_PASS
  1249. /* redirect to printf */
  1250. #define TEST_PASS(...) { \
  1251. if (STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK \
  1252. (max_relative_stack, printf(__VA_ARGS__)) < 0) { \
  1253. return err_sys("post-test check failed", WC_TEST_RET_ENC_NC);\
  1254. } \
  1255. PRINT_HEAP_CHECKPOINT(); \
  1256. ASSERT_RESTORED_VECTOR_REGISTERS(exit(1);); \
  1257. }
  1258. #endif
  1259. #ifdef TEST_ALWAYS_RUN_TO_END
  1260. #define TEST_FAIL(msg, retval) do { last_failed_test_ret = (retval); render_error_message(msg, retval); } while (0)
  1261. #elif !defined(TEST_FAIL)
  1262. #define TEST_FAIL(msg, retval) return err_sys(msg, retval)
  1263. #endif
  1264. #ifdef HAVE_STACK_SIZE
  1265. THREAD_RETURN WOLFSSL_THREAD wolfcrypt_test(void* args)
  1266. #else
  1267. wc_test_ret_t wolfcrypt_test(void* args)
  1268. #endif
  1269. {
  1270. wc_test_ret_t ret;
  1271. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  1272. long heap_baselineAllocs, heap_baselineBytes;
  1273. #endif
  1274. #ifdef TEST_ALWAYS_RUN_TO_END
  1275. int last_failed_test_ret = 0;
  1276. #endif
  1277. STACK_SIZE_INIT();
  1278. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  1279. (void)wolfCrypt_heap_peakAllocs_checkpoint();
  1280. heap_baselineAllocs = wolfCrypt_heap_peakAllocs_checkpoint();
  1281. (void)wolfCrypt_heap_peakBytes_checkpoint();
  1282. heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint();
  1283. #endif
  1284. #ifdef WC_RNG_SEED_CB
  1285. wc_SetSeed_Cb(wc_GenerateSeed);
  1286. #endif
  1287. printf("------------------------------------------------------------------------------\n");
  1288. printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING);
  1289. #ifdef WOLF_CRYPTO_CB
  1290. if (devId != INVALID_DEVID)
  1291. printf(" CryptoCB with DevID:%X\n", devId);
  1292. #endif
  1293. printf("------------------------------------------------------------------------------\n");
  1294. if (args) {
  1295. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  1296. int ch;
  1297. #endif
  1298. ((func_args*)args)->return_code = -1; /* error state */
  1299. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  1300. while ((ch = mygetopt(((func_args*)args)->argc, ((func_args*)args)->argv, "s:m:a:h")) != -1) {
  1301. switch(ch) {
  1302. case 's':
  1303. #ifdef HAVE_STACK_SIZE_VERBOSE
  1304. max_relative_stack = (ssize_t)atoi(myoptarg);
  1305. break;
  1306. #else
  1307. return err_sys("-s (max relative stack bytes) requires HAVE_STACK_SIZE_VERBOSE (--enable-stacksize=verbose).", WC_TEST_RET_ENC_NC);
  1308. #endif
  1309. case 'm':
  1310. #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
  1311. max_relative_heap_bytes = (ssize_t)atoi(myoptarg);
  1312. break;
  1313. #else
  1314. return err_sys("-m (max relative heap memory bytes) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC);
  1315. #endif
  1316. case 'a':
  1317. #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
  1318. max_relative_heap_allocs = (ssize_t)atoi(myoptarg);
  1319. break;
  1320. #else
  1321. return err_sys("-a (max relative heap allocs) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC);
  1322. #endif
  1323. case 'h':
  1324. return err_sys("\
  1325. options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
  1326. [-a max_relative_heap_allocs] [-h]\n", 0);
  1327. default:
  1328. return err_sys("unknown test option. try -h.", WC_TEST_RET_ENC_NC);
  1329. }
  1330. }
  1331. #endif
  1332. }
  1333. #ifdef WOLFSSL_STATIC_MEMORY
  1334. if (wc_LoadStaticMemory(&HEAP_HINT, gTestMemory, sizeof(gTestMemory),
  1335. WOLFMEM_GENERAL, 1) != 0) {
  1336. printf("unable to load static memory.\n");
  1337. return(EXIT_FAILURE);
  1338. }
  1339. #ifndef OPENSSL_EXTRA
  1340. wolfSSL_SetGlobalHeapHint(HEAP_HINT);
  1341. #endif
  1342. #endif
  1343. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  1344. wolfSSL_Debugging_ON();
  1345. #endif
  1346. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  1347. wc_SetLoggingHeap(HEAP_HINT);
  1348. #endif
  1349. #if defined(HAVE_FIPS) && !defined(WOLFSSL_LINUXKM)
  1350. wolfCrypt_SetCb_fips(myFipsCb);
  1351. #if FIPS_VERSION3_GE(6,0,0)
  1352. printf("FIPS module version in use: %s\n",
  1353. wolfCrypt_GetVersion_fips());
  1354. #endif
  1355. #endif
  1356. #if !defined(NO_BIG_INT)
  1357. if (CheckCtcSettings() != 1) {
  1358. printf("Sizeof mismatch (build) %x != (run) %lx\n",
  1359. CTC_SETTINGS, (unsigned long)CheckRunTimeSettings());
  1360. return err_sys("Build vs runtime math mismatch\n", WC_TEST_RET_ENC_NC);
  1361. }
  1362. #if defined(USE_FAST_MATH) && \
  1363. (!defined(NO_RSA) || !defined(NO_DH) || defined(HAVE_ECC))
  1364. if (CheckFastMathSettings() != 1)
  1365. return err_sys("Build vs runtime fastmath FP_MAX_BITS mismatch\n",
  1366. WC_TEST_RET_ENC_NC);
  1367. #endif /* USE_FAST_MATH */
  1368. #endif /* !NO_BIG_INT */
  1369. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  1370. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  1371. initDefaultName();
  1372. #endif
  1373. #ifdef WOLFSSL_ASYNC_CRYPT
  1374. ret = wolfAsync_DevOpen(&devId);
  1375. if (ret < 0) {
  1376. printf("Async device open failed\nRunning without async\n");
  1377. }
  1378. #else
  1379. (void)devId;
  1380. #endif /* WOLFSSL_ASYNC_CRYPT */
  1381. #ifdef WOLF_CRYPTO_CB
  1382. #ifdef HAVE_INTEL_QA_SYNC
  1383. devId = wc_CryptoCb_InitIntelQa();
  1384. if (INVALID_DEVID == devId) {
  1385. printf("Couldn't init the Intel QA\n");
  1386. }
  1387. #endif
  1388. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  1389. devId = wc_CryptoCb_InitOcteon();
  1390. if (INVALID_DEVID == devId) {
  1391. printf("Couldn't init the Cavium Octeon\n");
  1392. }
  1393. #endif
  1394. #ifdef HAVE_RENESAS_SYNC
  1395. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  1396. if (devId == INVALID_DEVID) {
  1397. printf("Couldn't get the Renesas device ID\n");
  1398. }
  1399. #endif
  1400. #endif
  1401. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  1402. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  1403. if (devId == INVALID_DEVID) {
  1404. /* for testing RNG with crypto callback register function */
  1405. devId = 100; /* any value beside -2 (INVALID_DEVID) */
  1406. wc_CryptoCb_RegisterDevice(devId, rng_crypto_cb, NULL);
  1407. }
  1408. #endif
  1409. #ifdef HAVE_SELFTEST
  1410. if ( (ret = wolfCrypt_SelfTest()) != 0)
  1411. TEST_FAIL("CAVP selftest failed!\n", ret);
  1412. else
  1413. TEST_PASS("CAVP selftest passed!\n");
  1414. #endif
  1415. if ( (ret = error_test()) != 0)
  1416. TEST_FAIL("error test failed!\n", ret);
  1417. else
  1418. TEST_PASS("error test passed!\n");
  1419. if ( (ret = memory_test()) != 0)
  1420. TEST_FAIL("MEMORY test failed!\n", ret);
  1421. else
  1422. TEST_PASS("MEMORY test passed!\n");
  1423. #ifndef NO_CODING
  1424. if ( (ret = base64_test()) != 0)
  1425. TEST_FAIL("base64 test failed!\n", ret);
  1426. else
  1427. TEST_PASS("base64 test passed!\n");
  1428. #ifdef WOLFSSL_BASE16
  1429. if ( (ret = base16_test()) != 0)
  1430. TEST_FAIL("base16 test failed!\n", ret);
  1431. else
  1432. TEST_PASS("base16 test passed!\n");
  1433. #endif
  1434. #endif /* !NO_CODING */
  1435. #ifndef NO_ASN
  1436. if ( (ret = asn_test()) != 0)
  1437. TEST_FAIL("asn test failed!\n", ret);
  1438. else
  1439. TEST_PASS("asn test passed!\n");
  1440. #endif
  1441. #ifndef WC_NO_RNG
  1442. if ( (ret = random_test()) != 0)
  1443. TEST_FAIL("RANDOM test failed!\n", ret);
  1444. else
  1445. TEST_PASS("RANDOM test passed!\n");
  1446. #endif /* WC_NO_RNG */
  1447. #ifndef NO_MD5
  1448. if ( (ret = md5_test()) != 0)
  1449. TEST_FAIL("MD5 test failed!\n", ret);
  1450. else
  1451. TEST_PASS("MD5 test passed!\n");
  1452. #endif
  1453. #ifdef WOLFSSL_MD2
  1454. if ( (ret = md2_test()) != 0)
  1455. TEST_FAIL("MD2 test failed!\n", ret);
  1456. else
  1457. TEST_PASS("MD2 test passed!\n");
  1458. #endif
  1459. #ifndef NO_MD4
  1460. if ( (ret = md4_test()) != 0)
  1461. TEST_FAIL("MD4 test failed!\n", ret);
  1462. else
  1463. TEST_PASS("MD4 test passed!\n");
  1464. #endif
  1465. #ifndef NO_SHA
  1466. if ( (ret = sha_test()) != 0)
  1467. TEST_FAIL("SHA test failed!\n", ret);
  1468. else
  1469. TEST_PASS("SHA test passed!\n");
  1470. #endif
  1471. #ifdef WOLFSSL_SHA224
  1472. if ( (ret = sha224_test()) != 0)
  1473. TEST_FAIL("SHA-224 test failed!\n", ret);
  1474. else
  1475. TEST_PASS("SHA-224 test passed!\n");
  1476. #endif
  1477. #ifndef NO_SHA256
  1478. if ( (ret = sha256_test()) != 0)
  1479. TEST_FAIL("SHA-256 test failed!\n", ret);
  1480. else
  1481. TEST_PASS("SHA-256 test passed!\n");
  1482. #endif
  1483. #ifdef WOLFSSL_SHA384
  1484. if ( (ret = sha384_test()) != 0)
  1485. TEST_FAIL("SHA-384 test failed!\n", ret);
  1486. else
  1487. TEST_PASS("SHA-384 test passed!\n");
  1488. #endif
  1489. #ifdef WOLFSSL_SHA512
  1490. if ((ret = sha512_test()) != 0) {
  1491. TEST_FAIL("SHA-512 test failed!\n", ret);
  1492. }
  1493. else {
  1494. TEST_PASS("SHA-512 test passed!\n");
  1495. }
  1496. #if !defined(WOLFSSL_NOSHA512_224) && \
  1497. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1498. if ((ret = sha512_224_test()) != 0) {
  1499. TEST_FAIL("SHA-512/224 test failed!\n", ret);
  1500. }
  1501. else
  1502. TEST_PASS("SHA-512/224 test passed!\n");
  1503. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  1504. #if !defined(WOLFSSL_NOSHA512_256) && \
  1505. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1506. if ((ret = sha512_256_test()) != 0) {
  1507. TEST_FAIL("SHA-512/256 test failed!\n", ret);
  1508. }
  1509. else
  1510. TEST_PASS("SHA-512/256 test passed!\n");
  1511. #endif /* !defined(WOLFSSL_NOSHA512_256) & !FIPS ... */
  1512. #endif /* WOLFSSL_SHA512 */
  1513. #ifdef WOLFSSL_SHA3
  1514. if ( (ret = sha3_test()) != 0)
  1515. TEST_FAIL("SHA-3 test failed!\n", ret);
  1516. else
  1517. TEST_PASS("SHA-3 test passed!\n");
  1518. #endif
  1519. #ifdef WOLFSSL_SHAKE128
  1520. if ( (ret = shake128_test()) != 0)
  1521. TEST_FAIL("SHAKE128 test failed!\n", ret);
  1522. else
  1523. TEST_PASS("SHAKE128 test passed!\n");
  1524. #endif
  1525. #ifdef WOLFSSL_SHAKE256
  1526. if ( (ret = shake256_test()) != 0)
  1527. TEST_FAIL("SHAKE256 test failed!\n", ret);
  1528. else
  1529. TEST_PASS("SHAKE256 test passed!\n");
  1530. #endif
  1531. #ifdef WOLFSSL_SM3
  1532. if ( (ret = sm3_test()) != 0)
  1533. return err_sys("SM-3 test failed!\n", ret);
  1534. else
  1535. TEST_PASS("SM-3 test passed!\n");
  1536. #endif
  1537. #ifndef NO_HASH_WRAPPER
  1538. if ( (ret = hash_test()) != 0)
  1539. TEST_FAIL("Hash test failed!\n", ret);
  1540. else
  1541. TEST_PASS("Hash test passed!\n");
  1542. #endif
  1543. #ifdef WOLFSSL_RIPEMD
  1544. if ( (ret = ripemd_test()) != 0)
  1545. TEST_FAIL("RIPEMD test failed!\n", ret);
  1546. else
  1547. TEST_PASS("RIPEMD test passed!\n");
  1548. #endif
  1549. #ifdef HAVE_BLAKE2
  1550. if ( (ret = blake2b_test()) != 0)
  1551. TEST_FAIL("BLAKE2b test failed!\n", ret);
  1552. else
  1553. TEST_PASS("BLAKE2b test passed!\n");
  1554. #endif
  1555. #ifdef HAVE_BLAKE2S
  1556. if ( (ret = blake2s_test()) != 0)
  1557. TEST_FAIL("BLAKE2s test failed!\n", ret);
  1558. else
  1559. TEST_PASS("BLAKE2s test passed!\n");
  1560. #endif
  1561. #ifndef NO_HMAC
  1562. #if !defined(NO_MD5) && !(defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) \
  1563. && (HAVE_FIPS_VERSION >= 5))
  1564. if ( (ret = hmac_md5_test()) != 0)
  1565. TEST_FAIL("HMAC-MD5 test failed!\n", ret);
  1566. else
  1567. TEST_PASS("HMAC-MD5 test passed!\n");
  1568. #endif
  1569. #ifndef NO_SHA
  1570. if ( (ret = hmac_sha_test()) != 0)
  1571. TEST_FAIL("HMAC-SHA test failed!\n", ret);
  1572. else
  1573. TEST_PASS("HMAC-SHA test passed!\n");
  1574. #endif
  1575. #ifdef WOLFSSL_SHA224
  1576. if ( (ret = hmac_sha224_test()) != 0)
  1577. TEST_FAIL("HMAC-SHA224 test failed!\n", ret);
  1578. else
  1579. TEST_PASS("HMAC-SHA224 test passed!\n");
  1580. #endif
  1581. #ifndef NO_SHA256
  1582. if ( (ret = hmac_sha256_test()) != 0)
  1583. TEST_FAIL("HMAC-SHA256 test failed!\n", ret);
  1584. else
  1585. TEST_PASS("HMAC-SHA256 test passed!\n");
  1586. #endif
  1587. #ifdef WOLFSSL_SHA384
  1588. if ( (ret = hmac_sha384_test()) != 0)
  1589. TEST_FAIL("HMAC-SHA384 test failed!\n", ret);
  1590. else
  1591. TEST_PASS("HMAC-SHA384 test passed!\n");
  1592. #endif
  1593. #ifdef WOLFSSL_SHA512
  1594. if ( (ret = hmac_sha512_test()) != 0)
  1595. TEST_FAIL("HMAC-SHA512 test failed!\n", ret);
  1596. else
  1597. TEST_PASS("HMAC-SHA512 test passed!\n");
  1598. #endif
  1599. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  1600. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  1601. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  1602. if ( (ret = hmac_sha3_test()) != 0)
  1603. TEST_FAIL("HMAC-SHA3 test failed!\n", ret);
  1604. else
  1605. TEST_PASS("HMAC-SHA3 test passed!\n");
  1606. #endif
  1607. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  1608. PRIVATE_KEY_UNLOCK();
  1609. if ( (ret = hkdf_test()) != 0)
  1610. TEST_FAIL("HMAC-KDF test failed!\n", ret);
  1611. else
  1612. TEST_PASS("HMAC-KDF test passed!\n");
  1613. PRIVATE_KEY_LOCK();
  1614. #endif
  1615. #endif /* !NO_HMAC */
  1616. #ifdef WOLFSSL_WOLFSSH
  1617. PRIVATE_KEY_UNLOCK();
  1618. if ( (ret = sshkdf_test()) != 0)
  1619. TEST_FAIL("SSH-KDF test failed!\n", ret);
  1620. else
  1621. TEST_PASS("SSH-KDF test passed!\n");
  1622. PRIVATE_KEY_LOCK();
  1623. #endif /* WOLFSSL_WOLFSSH */
  1624. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  1625. PRIVATE_KEY_UNLOCK();
  1626. if ( (ret = prf_test()) != 0)
  1627. TEST_FAIL("PRF test failed!\n", ret);
  1628. else
  1629. TEST_PASS("PRF test passed!\n");
  1630. PRIVATE_KEY_LOCK();
  1631. #endif
  1632. #ifdef WOLFSSL_HAVE_PRF
  1633. #if defined (HAVE_HKDF) && !defined(NO_HMAC)
  1634. #ifdef WOLFSSL_BASE16
  1635. PRIVATE_KEY_UNLOCK();
  1636. if ( (ret = tls12_kdf_test()) != 0)
  1637. TEST_FAIL("TLSv1.2 KDF test failed!\n", ret);
  1638. else
  1639. TEST_PASS("TLSv1.2 KDF test passed!\n");
  1640. PRIVATE_KEY_LOCK();
  1641. #endif /* WOLFSSL_BASE16 */
  1642. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  1643. #endif /* WOLFSSL_HAVE_PRF */
  1644. #ifdef WOLFSSL_TLS13
  1645. PRIVATE_KEY_UNLOCK();
  1646. if ( (ret = tls13_kdf_test()) != 0)
  1647. TEST_FAIL("TLSv1.3 KDF test failed!\n", ret);
  1648. else
  1649. TEST_PASS("TLSv1.3 KDF test passed!\n");
  1650. PRIVATE_KEY_LOCK();
  1651. #endif /* WOLFSSL_TLS13 */
  1652. #if defined(HAVE_X963_KDF) && defined(HAVE_ECC)
  1653. if ( (ret = x963kdf_test()) != 0)
  1654. TEST_FAIL("X963-KDF test failed!\n", ret);
  1655. else
  1656. TEST_PASS("X963-KDF test passed!\n");
  1657. #endif
  1658. #if defined(HAVE_HPKE) && defined(HAVE_ECC) && defined(HAVE_AESGCM)
  1659. PRIVATE_KEY_UNLOCK();
  1660. if ( (ret = hpke_test()) != 0)
  1661. TEST_FAIL("HPKE test failed!\n", ret);
  1662. else
  1663. TEST_PASS("HPKE test passed!\n");
  1664. PRIVATE_KEY_LOCK();
  1665. #endif
  1666. #if defined(WC_SRTP_KDF)
  1667. PRIVATE_KEY_UNLOCK();
  1668. if ( (ret = srtpkdf_test()) != 0)
  1669. TEST_FAIL("SRTP KDF test failed!\n", ret);
  1670. else
  1671. TEST_PASS("SRTP KDF test passed!\n");
  1672. PRIVATE_KEY_LOCK();
  1673. #endif
  1674. #if defined(WC_KDF_NIST_SP_800_56C)
  1675. if ( (ret = nist_sp80056c_kdf_test()) != 0)
  1676. TEST_FAIL("NIST SP 800-56C KDF test failed!\n", ret);
  1677. else
  1678. TEST_PASS("NIST SP 800-56C KDF test passed!\n");
  1679. #endif
  1680. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \
  1681. !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \
  1682. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
  1683. if ( (ret = gmac_test()) != 0)
  1684. TEST_FAIL("GMAC test failed!\n", ret);
  1685. else
  1686. TEST_PASS("GMAC test passed!\n");
  1687. #endif
  1688. #ifdef WC_RC2
  1689. if ( (ret = rc2_test()) != 0)
  1690. TEST_FAIL("RC2 test failed!\n", ret);
  1691. else
  1692. TEST_PASS("RC2 test passed!\n");
  1693. #endif
  1694. #ifndef NO_RC4
  1695. if ( (ret = arc4_test()) != 0)
  1696. TEST_FAIL("ARC4 test failed!\n", ret);
  1697. else
  1698. TEST_PASS("ARC4 test passed!\n");
  1699. #endif
  1700. #ifdef HAVE_CHACHA
  1701. if ( (ret = chacha_test()) != 0)
  1702. TEST_FAIL("Chacha test failed!\n", ret);
  1703. else
  1704. TEST_PASS("Chacha test passed!\n");
  1705. #endif
  1706. #ifdef HAVE_XCHACHA
  1707. if ( (ret = XChaCha_test()) != 0)
  1708. TEST_FAIL("XChacha test failed!\n", ret);
  1709. else
  1710. TEST_PASS("XChacha test passed!\n");
  1711. #endif
  1712. #ifdef HAVE_POLY1305
  1713. if ( (ret = poly1305_test()) != 0)
  1714. TEST_FAIL("POLY1305 test failed!\n", ret);
  1715. else
  1716. TEST_PASS("POLY1305 test passed!\n");
  1717. #endif
  1718. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  1719. if ( (ret = chacha20_poly1305_aead_test()) != 0)
  1720. TEST_FAIL("ChaCha20-Poly1305 AEAD test failed!\n", ret);
  1721. else
  1722. TEST_PASS("ChaCha20-Poly1305 AEAD test passed!\n");
  1723. #endif
  1724. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  1725. if ( (ret = XChaCha20Poly1305_test()) != 0)
  1726. TEST_FAIL("XChaCha20-Poly1305 AEAD test failed!\n", ret);
  1727. else
  1728. TEST_PASS("XChaCha20-Poly1305 AEAD test passed!\n");
  1729. #endif
  1730. #ifndef NO_DES3
  1731. if ( (ret = des_test()) != 0)
  1732. TEST_FAIL("DES test failed!\n", ret);
  1733. else
  1734. TEST_PASS("DES test passed!\n");
  1735. #endif
  1736. #ifndef NO_DES3
  1737. if ( (ret = des3_test()) != 0)
  1738. TEST_FAIL("DES3 test failed!\n", ret);
  1739. else
  1740. TEST_PASS("DES3 test passed!\n");
  1741. #endif
  1742. #ifndef NO_AES
  1743. if ( (ret = aes_test()) != 0)
  1744. TEST_FAIL("AES test failed!\n", ret);
  1745. else
  1746. TEST_PASS("AES test passed!\n");
  1747. #if defined(WOLFSSL_AES_192) && \
  1748. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
  1749. if ( (ret = aes192_test()) != 0)
  1750. TEST_FAIL("AES192 test failed!\n", ret);
  1751. else
  1752. TEST_PASS("AES192 test passed!\n");
  1753. #endif
  1754. #if defined(WOLFSSL_AES_256)
  1755. if ( (ret = aes256_test()) != 0)
  1756. TEST_FAIL("AES256 test failed!\n", ret);
  1757. else
  1758. TEST_PASS("AES256 test passed!\n");
  1759. #endif
  1760. #ifdef WOLFSSL_AES_OFB
  1761. if ( (ret = aesofb_test()) != 0)
  1762. TEST_FAIL("AES-OFB test failed!\n", ret);
  1763. else
  1764. TEST_PASS("AES-OFB test passed!\n");
  1765. #endif
  1766. #ifdef HAVE_AESGCM
  1767. #if !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO)
  1768. if ( (ret = aesgcm_test()) != 0)
  1769. TEST_FAIL("AES-GCM test failed!\n", ret);
  1770. #endif
  1771. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \
  1772. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY) && \
  1773. !defined(WOLFSSL_KCAPI_AES) && !(defined(WOLF_CRYPTO_CB) && \
  1774. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  1775. if ((ret = aesgcm_default_test()) != 0) {
  1776. TEST_FAIL("AES-GCM test failed!\n", ret);
  1777. }
  1778. #endif
  1779. if (ret == 0) {
  1780. TEST_PASS("AES-GCM test passed!\n");
  1781. }
  1782. #endif
  1783. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  1784. if ( (ret = aesccm_test()) != 0)
  1785. TEST_FAIL("AES-CCM test failed!\n", ret);
  1786. else
  1787. TEST_PASS("AES-CCM test passed!\n");
  1788. #endif
  1789. #ifdef WOLFSSL_AES_CFB
  1790. if ( (ret = aes_cfb_test()) != 0)
  1791. TEST_FAIL("AES-CFB test failed!\n", ret);
  1792. else
  1793. TEST_PASS("AES-CFB test passed!\n");
  1794. #endif
  1795. #ifdef WOLFSSL_AES_XTS
  1796. if ( (ret = aes_xts_test()) != 0)
  1797. TEST_FAIL("AES-XTS test failed!\n", ret);
  1798. else
  1799. TEST_PASS("AES-XTS test passed!\n");
  1800. #endif
  1801. #ifdef HAVE_AES_KEYWRAP
  1802. if ( (ret = aeskeywrap_test()) != 0)
  1803. TEST_FAIL("AES Key Wrap test failed!\n", ret);
  1804. else
  1805. TEST_PASS("AES Key Wrap test passed!\n");
  1806. #endif
  1807. #ifdef WOLFSSL_AES_SIV
  1808. if ( (ret = aes_siv_test()) != 0)
  1809. TEST_FAIL("AES-SIV test failed!\n", ret);
  1810. else
  1811. TEST_PASS("AES-SIV test passed!\n");
  1812. #endif
  1813. #endif
  1814. #if defined(WOLFSSL_AES_EAX) && \
  1815. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1816. if ( (ret = aes_eax_test()) != 0)
  1817. TEST_FAIL("AES-EAX test failed!\n", ret);
  1818. else
  1819. TEST_PASS("AES-EAX test passed!\n");
  1820. #endif /* WOLFSSL_AES_EAX */
  1821. #ifdef HAVE_ARIA
  1822. if ( (ret = ariagcm_test(MC_ALGID_ARIA_128BITKEY)) != 0)
  1823. TEST_FAIL("ARIA128 test failed!\n", ret);
  1824. else
  1825. TEST_PASS("ARIA128 test passed!\n");
  1826. if ( (ret = ariagcm_test(MC_ALGID_ARIA_192BITKEY)) != 0)
  1827. TEST_FAIL("ARIA192 test failed!\n", ret);
  1828. else
  1829. TEST_PASS("ARIA192 test passed!\n");
  1830. if ( (ret = ariagcm_test(MC_ALGID_ARIA_256BITKEY)) != 0)
  1831. TEST_FAIL("ARIA256 test failed!\n", ret);
  1832. else
  1833. TEST_PASS("ARIA256 test passed!\n");
  1834. #endif
  1835. #ifdef HAVE_CAMELLIA
  1836. if ( (ret = camellia_test()) != 0)
  1837. TEST_FAIL("CAMELLIA test failed!\n", ret);
  1838. else
  1839. TEST_PASS("CAMELLIA test passed!\n");
  1840. #endif
  1841. #ifdef WOLFSSL_SM4
  1842. if ( (ret = sm4_test()) != 0)
  1843. return err_sys("SM-4 test failed!\n", ret);
  1844. else
  1845. TEST_PASS("SM-4 test passed!\n");
  1846. #endif
  1847. #if !defined(NO_RSA) && !defined(HAVE_RENESAS_SYNC)
  1848. #ifdef WC_RSA_NO_PADDING
  1849. if ( (ret = rsa_no_pad_test()) != 0)
  1850. TEST_FAIL("RSA NOPAD test failed!\n", ret);
  1851. else
  1852. TEST_PASS("RSA NOPAD test passed!\n");
  1853. #endif
  1854. if ( (ret = rsa_test()) != 0)
  1855. TEST_FAIL("RSA test failed!\n", ret);
  1856. else
  1857. TEST_PASS("RSA test passed!\n");
  1858. #endif
  1859. #ifndef NO_DH
  1860. PRIVATE_KEY_UNLOCK();
  1861. if ( (ret = dh_test()) != 0)
  1862. TEST_FAIL("DH test failed!\n", ret);
  1863. else
  1864. TEST_PASS("DH test passed!\n");
  1865. PRIVATE_KEY_LOCK();
  1866. #endif
  1867. #ifndef NO_DSA
  1868. if ( (ret = dsa_test()) != 0)
  1869. TEST_FAIL("DSA test failed!\n", ret);
  1870. else
  1871. TEST_PASS("DSA test passed!\n");
  1872. #endif
  1873. #ifdef WOLFCRYPT_HAVE_SRP
  1874. if ( (ret = srp_test()) != 0)
  1875. TEST_FAIL("SRP test failed!\n", ret);
  1876. else
  1877. TEST_PASS("SRP test passed!\n");
  1878. #endif
  1879. #ifndef NO_PWDBASED
  1880. PRIVATE_KEY_UNLOCK();
  1881. if ( (ret = pwdbased_test()) != 0)
  1882. TEST_FAIL("PWDBASED test failed!\n", ret);
  1883. else
  1884. TEST_PASS("PWDBASED test passed!\n");
  1885. PRIVATE_KEY_LOCK();
  1886. #endif
  1887. #if defined(USE_CERT_BUFFERS_2048) && \
  1888. defined(HAVE_PKCS12) && \
  1889. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  1890. !defined(NO_CERTS) && !defined(NO_DES3)
  1891. if ( (ret = pkcs12_test()) != 0)
  1892. TEST_FAIL("PKCS12 test failed!\n", ret);
  1893. else
  1894. TEST_PASS("PKCS12 test passed!\n");
  1895. #endif
  1896. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  1897. if ( (ret = openssl_test()) != 0)
  1898. TEST_FAIL("OPENSSL test failed!\n", ret);
  1899. else
  1900. TEST_PASS("OPENSSL test passed!\n");
  1901. if ( (ret = openSSL_evpMD_test()) != 0)
  1902. TEST_FAIL("OPENSSL (EVP MD) test failed!\n", ret);
  1903. else
  1904. TEST_PASS("OPENSSL (EVP MD) passed!\n");
  1905. if ( (ret = openssl_pkey0_test()) != 0)
  1906. TEST_FAIL("OPENSSL (PKEY0) test failed!\n", ret);
  1907. else
  1908. TEST_PASS("OPENSSL (PKEY0) passed!\n");
  1909. if ( (ret = openssl_pkey1_test()) != 0)
  1910. TEST_FAIL("OPENSSL (PKEY1) test failed!\n", ret);
  1911. else
  1912. TEST_PASS("OPENSSL (PKEY1) passed!\n");
  1913. #if !defined(WOLF_CRYPTO_CB_ONLY_RSA) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  1914. if ( (ret = openssl_evpSig_test()) != 0)
  1915. TEST_FAIL("OPENSSL (EVP Sign/Verify) test failed!\n", ret);
  1916. else
  1917. TEST_PASS("OPENSSL (EVP Sign/Verify) passed!\n");
  1918. #endif
  1919. #endif
  1920. #if defined(HAVE_ECC)
  1921. PRIVATE_KEY_UNLOCK();
  1922. if ( (ret = ecc_test()) != 0)
  1923. TEST_FAIL("ECC test failed!\n", ret);
  1924. else
  1925. TEST_PASS("ECC test passed!\n");
  1926. PRIVATE_KEY_LOCK();
  1927. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  1928. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  1929. if ( (ret = ecc_encrypt_test()) != 0)
  1930. TEST_FAIL("ECC Enc test failed!\n", ret);
  1931. else
  1932. TEST_PASS("ECC Enc test passed!\n");
  1933. #endif
  1934. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  1935. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  1936. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  1937. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  1938. /* skip for ATECC508/608A, cannot import private key buffers */
  1939. if ( (ret = ecc_test_buffers()) != 0)
  1940. TEST_FAIL("ECC buffer test failed!\n", ret);
  1941. else
  1942. TEST_PASS("ECC buffer test passed!\n");
  1943. #endif
  1944. #endif
  1945. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  1946. !defined(NO_FILESYSTEM)
  1947. if ( (ret = cert_test()) != 0)
  1948. TEST_FAIL("CERT test failed!\n", ret);
  1949. else
  1950. TEST_PASS("CERT test passed!\n");
  1951. #endif
  1952. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  1953. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  1954. if ( (ret = certext_test()) != 0)
  1955. TEST_FAIL("CERT EXT test failed!\n", ret);
  1956. else
  1957. TEST_PASS("CERT EXT test passed!\n");
  1958. #endif
  1959. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  1960. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  1961. if ( (ret = decodedCertCache_test()) != 0)
  1962. TEST_FAIL("DECODED CERT CACHE test failed!\n", ret);
  1963. else
  1964. TEST_PASS("DECODED CERT CACHE test passed!\n");
  1965. #endif
  1966. #ifdef HAVE_CURVE25519
  1967. if ( (ret = curve25519_test()) != 0)
  1968. TEST_FAIL("CURVE25519 test failed!\n", ret);
  1969. else
  1970. TEST_PASS("CURVE25519 test passed!\n");
  1971. #endif
  1972. #ifdef HAVE_ED25519
  1973. PRIVATE_KEY_UNLOCK();
  1974. if ( (ret = ed25519_test()) != 0)
  1975. TEST_FAIL("ED25519 test failed!\n", ret);
  1976. else
  1977. TEST_PASS("ED25519 test passed!\n");
  1978. PRIVATE_KEY_LOCK();
  1979. #endif
  1980. #ifdef HAVE_CURVE448
  1981. if ( (ret = curve448_test()) != 0)
  1982. TEST_FAIL("CURVE448 test failed!\n", ret);
  1983. else
  1984. TEST_PASS("CURVE448 test passed!\n");
  1985. #endif
  1986. #ifdef HAVE_ED448
  1987. PRIVATE_KEY_UNLOCK();
  1988. if ( (ret = ed448_test()) != 0)
  1989. TEST_FAIL("ED448 test failed!\n", ret);
  1990. else
  1991. TEST_PASS("ED448 test passed!\n");
  1992. PRIVATE_KEY_LOCK();
  1993. #endif
  1994. #ifdef WOLFSSL_HAVE_KYBER
  1995. if ( (ret = kyber_test()) != 0)
  1996. TEST_FAIL("KYBER test failed!\n", ret);
  1997. else
  1998. TEST_PASS("KYBER test passed!\n");
  1999. #endif
  2000. #ifdef HAVE_DILITHIUM
  2001. if ( (ret = dilithium_test()) != 0)
  2002. TEST_FAIL("DILITHIUM test failed!\n", ret);
  2003. else
  2004. TEST_PASS("DILITHIUM test passed!\n");
  2005. #endif
  2006. #if defined(WOLFSSL_HAVE_XMSS)
  2007. #if !defined(WOLFSSL_SMALL_STACK) && WOLFSSL_XMSS_MIN_HEIGHT <= 10
  2008. if ( (ret = xmss_test_verify_only()) != 0)
  2009. TEST_FAIL("XMSS Vfy test failed!\n", ret);
  2010. else
  2011. TEST_PASS("XMSS Vfy test passed!\n");
  2012. #endif
  2013. #if !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  2014. if ( (ret = xmss_test()) != 0)
  2015. TEST_FAIL("XMSS test failed!\n", ret);
  2016. else
  2017. TEST_PASS("XMSS test passed!\n");
  2018. #endif
  2019. #endif /* if defined(WOLFSSL_HAVE_XMSS) */
  2020. #if defined(WOLFSSL_HAVE_LMS)
  2021. #if !defined(WOLFSSL_SMALL_STACK)
  2022. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
  2023. defined(HAVE_LIBLMS)
  2024. if ( (ret = lms_test_verify_only()) != 0)
  2025. TEST_FAIL("LMS Vfy test failed!\n", ret);
  2026. else
  2027. TEST_PASS("LMS Vfy test passed!\n");
  2028. #endif
  2029. #endif
  2030. #if !defined(WOLFSSL_LMS_VERIFY_ONLY)
  2031. if ( (ret = lms_test()) != 0)
  2032. TEST_FAIL("LMS test failed!\n", ret);
  2033. else
  2034. TEST_PASS("LMS test passed!\n");
  2035. #endif
  2036. #endif /* if defined(WOLFSSL_HAVE_LMS) */
  2037. #ifdef WOLFCRYPT_HAVE_ECCSI
  2038. if ( (ret = eccsi_test()) != 0)
  2039. TEST_FAIL("ECCSI test failed!\n", ret);
  2040. else
  2041. TEST_PASS("ECCSI test passed!\n");
  2042. #endif
  2043. #ifdef WOLFCRYPT_HAVE_SAKKE
  2044. if ( (ret = sakke_test()) != 0)
  2045. TEST_FAIL("SAKKE test failed!\n", ret);
  2046. else
  2047. TEST_PASS("SAKKE test passed!\n");
  2048. #endif
  2049. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  2050. if ( (ret = cmac_test()) != 0)
  2051. TEST_FAIL("CMAC test failed!\n", ret);
  2052. else
  2053. TEST_PASS("CMAC test passed!\n");
  2054. #endif
  2055. #if defined(WOLFSSL_SIPHASH)
  2056. if ( (ret = siphash_test()) != 0)
  2057. TEST_FAIL("SipHash test failed!\n", ret);
  2058. else
  2059. TEST_PASS("SipHash test passed!\n");
  2060. #endif
  2061. #ifdef HAVE_LIBZ
  2062. if ( (ret = compress_test()) != 0)
  2063. TEST_FAIL("COMPRESS test failed!\n", ret);
  2064. else
  2065. TEST_PASS("COMPRESS test passed!\n");
  2066. #endif
  2067. #ifdef HAVE_PKCS7
  2068. #ifndef NO_PKCS7_ENCRYPTED_DATA
  2069. if ( (ret = pkcs7encrypted_test()) != 0)
  2070. TEST_FAIL("PKCS7encrypted test failed!\n", ret);
  2071. else
  2072. TEST_PASS("PKCS7encrypted test passed!\n");
  2073. #endif
  2074. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  2075. if ( (ret = pkcs7compressed_test()) != 0)
  2076. TEST_FAIL("PKCS7compressed test failed!\n", ret);
  2077. else
  2078. TEST_PASS("PKCS7compressed test passed!\n");
  2079. #endif
  2080. if ( (ret = pkcs7signed_test()) != 0)
  2081. TEST_FAIL("PKCS7signed test failed!\n", ret);
  2082. else
  2083. TEST_PASS("PKCS7signed test passed!\n");
  2084. if ( (ret = pkcs7enveloped_test()) != 0)
  2085. TEST_FAIL("PKCS7enveloped test failed!\n", ret);
  2086. else
  2087. TEST_PASS("PKCS7enveloped test passed!\n");
  2088. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  2089. if ( (ret = pkcs7authenveloped_test()) != 0)
  2090. TEST_FAIL("PKCS7authenveloped test failed!\n", ret);
  2091. else
  2092. TEST_PASS("PKCS7authenveloped test passed!\n");
  2093. #endif
  2094. #endif
  2095. #if defined(WOLFSSL_PUBLIC_MP) && \
  2096. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  2097. defined(USE_FAST_MATH))
  2098. if ( (ret = mp_test()) != 0)
  2099. TEST_FAIL("mp test failed!\n", ret);
  2100. else
  2101. TEST_PASS("mp test passed!\n");
  2102. #endif
  2103. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  2104. if ( (ret = prime_test()) != 0)
  2105. TEST_FAIL("prime test failed!\n", ret);
  2106. else
  2107. TEST_PASS("prime test passed!\n");
  2108. #endif
  2109. #if defined(ASN_BER_TO_DER) && \
  2110. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  2111. defined(OPENSSL_EXTRA_X509_SMALL))
  2112. if ( (ret = berder_test()) != 0)
  2113. TEST_FAIL("ber-der test failed!\n", ret);
  2114. else
  2115. TEST_PASS("ber-der test passed!\n");
  2116. #endif
  2117. if ( (ret = logging_test()) != 0)
  2118. TEST_FAIL("logging test failed!\n", ret);
  2119. else
  2120. TEST_PASS("logging test passed!\n");
  2121. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  2122. if ( (ret = time_test()) != 0)
  2123. TEST_FAIL("time test failed!\n", ret);
  2124. else
  2125. TEST_PASS("time test passed!\n");
  2126. #endif
  2127. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  2128. if ((ret = wolfcrypt_mutex_test()) != 0)
  2129. #else
  2130. if ((ret = mutex_test()) != 0)
  2131. #endif
  2132. TEST_FAIL("mutex test failed!\n", ret);
  2133. else
  2134. TEST_PASS("mutex test passed!\n");
  2135. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  2136. if ( (ret = memcb_test()) != 0)
  2137. TEST_FAIL("memcb test failed!\n", ret);
  2138. else
  2139. TEST_PASS("memcb test passed!\n");
  2140. #endif
  2141. #ifdef WOLFSSL_CAAM_BLOB
  2142. if ( (ret = blob_test()) != 0)
  2143. TEST_FAIL("blob test failed!\n", ret);
  2144. else
  2145. TEST_PASS("blob test passed!\n");
  2146. #endif
  2147. #if defined(WOLF_CRYPTO_CB) && !defined(WC_TEST_NO_CRYPTOCB_SW_TEST) && \
  2148. !(defined(HAVE_INTEL_QAT_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2149. defined(WOLFSSL_QNX_CAAM) || defined(HAVE_RENESAS_SYNC))
  2150. if ( (ret = cryptocb_test()) != 0)
  2151. TEST_FAIL("crypto callback test failed!\n", ret);
  2152. else
  2153. TEST_PASS("crypto callback test passed!\n");
  2154. #endif
  2155. #ifdef WOLFSSL_CERT_PIV
  2156. if ( (ret = certpiv_test()) != 0)
  2157. TEST_FAIL("cert piv test failed!\n", ret);
  2158. else
  2159. TEST_PASS("cert piv test passed!\n");
  2160. #endif
  2161. #ifdef WOLF_CRYPTO_CB
  2162. #ifdef HAVE_INTEL_QA_SYNC
  2163. wc_CryptoCb_CleanupIntelQa(&devId);
  2164. #endif
  2165. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2166. wc_CryptoCb_CleanupOcteon(&devId);
  2167. #endif
  2168. #endif
  2169. #ifdef WOLFSSL_ASYNC_CRYPT
  2170. wolfAsync_DevClose(&devId);
  2171. #endif
  2172. /* cleanup the thread if fixed point cache is enabled and have thread local */
  2173. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  2174. wc_ecc_fp_free();
  2175. #endif
  2176. #ifdef TEST_ALWAYS_RUN_TO_END
  2177. if (last_failed_test_ret != 0)
  2178. ret = last_failed_test_ret;
  2179. #endif
  2180. if (args)
  2181. ((func_args*)args)->return_code = ret;
  2182. /* If hardware acceleration and respective metrics tracked, show results: */
  2183. #ifdef WOLFSSL_HW_METRICS
  2184. #if defined(WOLFSSL_ESP32_CRYPT_RSA_PRI) && defined(WOLFSSL_HW_METRICS)
  2185. esp_hw_show_mp_metrics();
  2186. #endif
  2187. #endif
  2188. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(OPENSSL_EXTRA)
  2189. wolfSSL_SetGlobalHeapHint(NULL);
  2190. #endif
  2191. TEST_PASS("Test complete\n");
  2192. EXIT_TEST(ret);
  2193. } /* end of wolfcrypt_test() */
  2194. #ifndef NO_MAIN_DRIVER
  2195. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  2196. int myoptind = 0;
  2197. char* myoptarg = NULL;
  2198. #endif
  2199. /* so overall tests can pull in test function */
  2200. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  2201. wc_test_ret_t wolf_test_task(void)
  2202. #else
  2203. #ifndef NO_MAIN_FUNCTION
  2204. int main(int argc, char** argv)
  2205. {
  2206. return (int)wolfcrypt_test_main(argc, argv);
  2207. }
  2208. #endif
  2209. wc_test_ret_t wolfcrypt_test_main(int argc, char** argv)
  2210. #endif
  2211. {
  2212. wc_test_ret_t ret;
  2213. func_args args = { 0, 0, 0 };
  2214. #if defined(WOLFSSL_ESPIDF) || defined(WOLFSSL_SE050)
  2215. /* set dummy wallclock time. */
  2216. struct timeval utctime;
  2217. struct timezone tz;
  2218. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2219. utctime.tv_usec = 0;
  2220. tz.tz_minuteswest = 0;
  2221. tz.tz_dsttime = 0;
  2222. settimeofday(&utctime, &tz);
  2223. #endif
  2224. #ifdef WOLFSSL_APACHE_MYNEWT
  2225. #ifdef ARCH_sim
  2226. mcu_sim_parse_args(argc, argv);
  2227. #endif
  2228. sysinit();
  2229. /* set dummy wallclock time. */
  2230. struct os_timeval utctime;
  2231. struct os_timezone tz;
  2232. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2233. utctime.tv_usec = 0;
  2234. tz.tz_minuteswest = 0;
  2235. tz.tz_dsttime = 0;
  2236. os_settimeofday(&utctime, &tz);
  2237. #endif
  2238. #ifdef WOLFSSL_ZEPHYR
  2239. /* set dummy wallclock time. */
  2240. struct timespec utctime;
  2241. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2242. utctime.tv_nsec = 0;
  2243. clock_settime(CLOCK_REALTIME, &utctime);
  2244. #endif
  2245. #ifdef DEVKITPRO
  2246. void *framebuffer;
  2247. GXRModeObj *rmode = NULL;
  2248. VIDEO_Init();
  2249. WPAD_Init();
  2250. rmode = VIDEO_GetPreferredMode(NULL);
  2251. #pragma GCC diagnostic ignored "-Wbad-function-cast"
  2252. framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  2253. #pragma GCC diagnostic pop
  2254. console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
  2255. VIDEO_Configure(rmode);
  2256. VIDEO_SetNextFramebuffer(framebuffer);
  2257. VIDEO_SetBlack(FALSE);
  2258. VIDEO_Flush();
  2259. VIDEO_WaitVSync();
  2260. if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
  2261. #endif
  2262. #ifdef WOLFSSL_NDS
  2263. /* Init Console output */
  2264. consoleDemoInit();
  2265. /* Init the Filesystem */
  2266. fatInitDefault();
  2267. #endif
  2268. #ifdef HAVE_WNR
  2269. if ((ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000)) != 0) {
  2270. err_sys("Whitewood netRandom global config failed",
  2271. WC_TEST_RET_ENC_EC(ret));
  2272. return WC_TEST_RET_ENC_EC(ret);
  2273. }
  2274. #endif
  2275. #ifndef WOLFSSL_ESPIDF
  2276. args.argc = argc;
  2277. args.argv = argv;
  2278. #endif
  2279. if ((ret = wolfCrypt_Init()) != 0) {
  2280. printf("wolfCrypt_Init failed %d\n", (int)ret);
  2281. err_sys("Error with wolfCrypt_Init!\n", WC_TEST_RET_ENC_EC(ret));
  2282. }
  2283. #ifdef HAVE_WC_INTROSPECTION
  2284. printf("Math: %s\n", wc_GetMathInfo());
  2285. #endif
  2286. #ifdef HAVE_STACK_SIZE
  2287. StackSizeCheck(&args, wolfcrypt_test);
  2288. #else
  2289. wolfcrypt_test(&args);
  2290. #endif
  2291. if ((ret = wolfCrypt_Cleanup()) != 0) {
  2292. printf("wolfCrypt_Cleanup failed %d\n", (int)ret);
  2293. err_sys("Error with wolfCrypt_Cleanup!\n", WC_TEST_RET_ENC_EC(ret));
  2294. }
  2295. #ifdef HAVE_WNR
  2296. if ((ret = wc_FreeNetRandom()) < 0)
  2297. err_sys("Failed to free netRandom context",
  2298. WC_TEST_RET_ENC_EC(ret));
  2299. #endif /* HAVE_WNR */
  2300. #ifdef DOLPHIN_EMULATOR
  2301. /* Returning from main panics the emulator. Just hang
  2302. * and let the user force quit the emulator window. */
  2303. printf("args.return_code: %d\n", args.return_code);
  2304. printf("Testing complete. You may close the window now\n");
  2305. while (1);
  2306. #endif
  2307. #ifdef WOLFSSL_NDS
  2308. /* in Nintendo DS returning from main shuts down the Device without letting you see the Results. */
  2309. printf("args.return_code: %d\n", args.return_code);
  2310. printf("Testing complete. Press Start to exit the Program\n");
  2311. while(1) {
  2312. swiWaitForVBlank();
  2313. scanKeys();
  2314. int keys = keysDown();
  2315. if(keys & KEY_START) break;
  2316. }
  2317. #endif
  2318. #if defined(WOLFSSL_ESPIDF)
  2319. /* ESP_LOGI to print takes up a lot less memory than printf */
  2320. ESP_LOGI(ESPIDF_TAG, "Exiting main with return code: % d\n",
  2321. args.return_code);
  2322. #else
  2323. /* gate this for target platforms wishing to avoid printf reference */
  2324. printf("Exiting main with return code: %ld\n", (long int)args.return_code);
  2325. #endif
  2326. return args.return_code;
  2327. } /* wolfcrypt_test_main or wolf_test_task */
  2328. #endif /* NO_MAIN_DRIVER */
  2329. /* helper to save DER, convert to PEM and save PEM */
  2330. #if !defined(NO_ASN) && (defined(HAVE_ECC) || !defined(NO_DSA) || \
  2331. (!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)))) \
  2332. && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  2333. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2334. #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, fD, fP, pT, WC_TEST_RET_LN)
  2335. #else
  2336. #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, NULL, NULL, pT, WC_TEST_RET_LN)
  2337. #endif
  2338. static wc_test_ret_t _SaveDerAndPem(const byte* der, int derSz,
  2339. const char* fileDer, const char* filePem, int pemType, int calling_line)
  2340. {
  2341. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2342. wc_test_ret_t ret;
  2343. XFILE derFile;
  2344. derFile = XFOPEN(fileDer, "wb");
  2345. if (!derFile) {
  2346. return WC_TEST_RET_ENC(calling_line, 0, WC_TEST_RET_TAG_I);
  2347. }
  2348. ret = (int)XFWRITE(der, 1, (size_t)derSz, derFile);
  2349. XFCLOSE(derFile);
  2350. if (ret != derSz) {
  2351. return WC_TEST_RET_ENC(calling_line, 1, WC_TEST_RET_TAG_I);
  2352. }
  2353. #endif
  2354. #ifdef WOLFSSL_DER_TO_PEM
  2355. if (filePem) {
  2356. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2357. XFILE pemFile;
  2358. #endif
  2359. #ifndef WOLFSSL_NO_MALLOC
  2360. byte* pem;
  2361. #else
  2362. byte pem[1024];
  2363. #endif
  2364. int pemSz;
  2365. /* calculate PEM size */
  2366. pemSz = wc_DerToPem(der, (word32)derSz, NULL, 0, pemType);
  2367. if (pemSz < 0) {
  2368. return WC_TEST_RET_ENC(calling_line, 2, WC_TEST_RET_TAG_I);
  2369. }
  2370. #ifndef WOLFSSL_NO_MALLOC
  2371. pem = (byte*)XMALLOC((word32)pemSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2372. if (pem == NULL) {
  2373. return WC_TEST_RET_ENC(calling_line, 3, WC_TEST_RET_TAG_I);
  2374. }
  2375. #else
  2376. if (pemSz > (int)sizeof(pem))
  2377. return BAD_FUNC_ARG;
  2378. #endif
  2379. /* Convert to PEM */
  2380. pemSz = wc_DerToPem(der, (word32)derSz, pem, (word32)pemSz, pemType);
  2381. if (pemSz < 0) {
  2382. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2383. return WC_TEST_RET_ENC(calling_line, 4, WC_TEST_RET_TAG_I);
  2384. }
  2385. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2386. pemFile = XFOPEN(filePem, "wb");
  2387. if (!pemFile) {
  2388. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2389. return WC_TEST_RET_ENC(calling_line, 5, WC_TEST_RET_TAG_I);
  2390. }
  2391. ret = (int)XFWRITE(pem, 1, (size_t)pemSz, pemFile);
  2392. XFCLOSE(pemFile);
  2393. if (ret != pemSz) {
  2394. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2395. return WC_TEST_RET_ENC(calling_line, 6, WC_TEST_RET_TAG_I);
  2396. }
  2397. #endif
  2398. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2399. }
  2400. #endif /* WOLFSSL_DER_TO_PEM */
  2401. /* suppress unused variable warnings */
  2402. (void)der;
  2403. (void)derSz;
  2404. (void)filePem;
  2405. (void)fileDer;
  2406. (void)pemType;
  2407. (void)calling_line;
  2408. return 0;
  2409. }
  2410. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  2411. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void)
  2412. {
  2413. const char* errStr;
  2414. char out[WOLFSSL_MAX_ERROR_SZ];
  2415. const char* unknownStr = wc_GetErrorString(0);
  2416. #ifdef NO_ERROR_STRINGS
  2417. /* Ensure a valid error code's string matches an invalid code's.
  2418. * The string is that error strings are not available.
  2419. */
  2420. WOLFSSL_ENTER("error_test NO_ERROR_STRINGS");
  2421. errStr = wc_GetErrorString(WC_NO_ERR_TRACE(OPEN_RAN_E));
  2422. wc_ErrorString(WC_NO_ERR_TRACE(OPEN_RAN_E), out);
  2423. if (XSTRCMP(errStr, unknownStr) != 0)
  2424. return WC_TEST_RET_ENC_NC;
  2425. if (XSTRCMP(out, unknownStr) != 0)
  2426. return WC_TEST_RET_ENC_NC;
  2427. #else
  2428. int i;
  2429. int j = 0;
  2430. /* Values that are not or no longer error codes. */
  2431. static const struct {
  2432. int first;
  2433. int last;
  2434. } missing[] = {
  2435. { -124, -124 },
  2436. { -166, -169 }
  2437. };
  2438. /* Check that all errors have a string and it's the same through the two
  2439. * APIs. Check that the values that are not errors map to the unknown
  2440. * string.
  2441. */
  2442. for (i = WC_FIRST_E; i >= WC_LAST_E; i--) {
  2443. int this_missing = 0;
  2444. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  2445. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  2446. this_missing = 1;
  2447. break;
  2448. }
  2449. }
  2450. errStr = wc_GetErrorString(i);
  2451. wc_ErrorString(i, out);
  2452. if (! this_missing) {
  2453. if (XSTRCMP(errStr, unknownStr) == 0) {
  2454. WOLFSSL_MSG("errStr unknown");
  2455. return WC_TEST_RET_ENC_I(-i);
  2456. }
  2457. if (XSTRCMP(out, unknownStr) == 0) {
  2458. WOLFSSL_MSG("out unknown");
  2459. return WC_TEST_RET_ENC_I(-i);
  2460. }
  2461. if (XSTRCMP(errStr, out) != 0) {
  2462. WOLFSSL_MSG("errStr does not match output");
  2463. return WC_TEST_RET_ENC_I(-i);
  2464. }
  2465. if (XSTRLEN(errStr) >= WOLFSSL_MAX_ERROR_SZ) {
  2466. WOLFSSL_MSG("errStr too long");
  2467. return WC_TEST_RET_ENC_I(-i);
  2468. }
  2469. }
  2470. else {
  2471. j++;
  2472. if (XSTRCMP(errStr, unknownStr) != 0)
  2473. return WC_TEST_RET_ENC_I(-i);
  2474. if (XSTRCMP(out, unknownStr) != 0)
  2475. return WC_TEST_RET_ENC_I(-i);
  2476. }
  2477. }
  2478. /* Check if the next possible value has been given a string. */
  2479. errStr = wc_GetErrorString(i);
  2480. wc_ErrorString(i, out);
  2481. if (XSTRCMP(errStr, unknownStr) != 0)
  2482. return WC_TEST_RET_ENC_NC;
  2483. if (XSTRCMP(out, unknownStr) != 0)
  2484. return WC_TEST_RET_ENC_NC;
  2485. #endif
  2486. return 0;
  2487. }
  2488. #ifndef NO_CODING
  2489. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void)
  2490. {
  2491. wc_test_ret_t ret;
  2492. WOLFSSL_SMALL_STACK_STATIC const byte good[] = "A+Gd\0\0\0";
  2493. WOLFSSL_SMALL_STACK_STATIC const byte goodEnd[] = "A+Gd \r\n";
  2494. WOLFSSL_SMALL_STACK_STATIC const byte good_spaces[] = " A + G d \0";
  2495. byte out[128];
  2496. word32 outLen;
  2497. #ifdef WOLFSSL_BASE64_ENCODE
  2498. byte data[3];
  2499. word32 dataLen;
  2500. byte longData[79] = { 0 };
  2501. WOLFSSL_SMALL_STACK_STATIC const byte symbols[] = "+/A=";
  2502. #endif
  2503. WOLFSSL_SMALL_STACK_STATIC const byte badSmall[] = "AAA!Gdj=";
  2504. WOLFSSL_SMALL_STACK_STATIC const byte badLarge[] = "AAA~Gdj=";
  2505. WOLFSSL_SMALL_STACK_STATIC const byte badEOL[] = "A+Gd!AA";
  2506. WOLFSSL_SMALL_STACK_STATIC const byte badPadding[] = "AA=A";
  2507. WOLFSSL_SMALL_STACK_STATIC const byte badChar[] = ",-.:;<=>?@[\\]^_`";
  2508. byte goodChar[] =
  2509. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2510. "abcdefghijklmnopqrstuvwxyz"
  2511. "0123456789+/;";
  2512. byte charTest[] = "A+Gd\0\0\0";
  2513. int i;
  2514. WOLFSSL_ENTER("base64_test");
  2515. /* Good Base64 encodings. */
  2516. outLen = sizeof(out);
  2517. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2518. if (ret != 0)
  2519. return WC_TEST_RET_ENC_EC(ret);
  2520. outLen = sizeof(out);
  2521. ret = Base64_Decode(goodEnd, sizeof(goodEnd), out, &outLen);
  2522. if (ret != 0)
  2523. return WC_TEST_RET_ENC_EC(ret);
  2524. outLen = sizeof(goodChar);
  2525. ret = Base64_Decode(goodChar, sizeof(goodChar), goodChar, &outLen);
  2526. if (ret != 0)
  2527. return WC_TEST_RET_ENC_EC(ret);
  2528. if (outLen != 64 / 4 * 3)
  2529. return WC_TEST_RET_ENC_NC;
  2530. outLen = sizeof(out);
  2531. ret = Base64_Decode(good_spaces, sizeof(good_spaces), out, &outLen);
  2532. if (ret != 0)
  2533. return WC_TEST_RET_ENC_EC(ret);
  2534. /* Bad parameters. */
  2535. outLen = 1;
  2536. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2537. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2538. return WC_TEST_RET_ENC_EC(ret);
  2539. outLen = sizeof(out);
  2540. ret = Base64_Decode(badEOL, sizeof(badEOL), out, &outLen);
  2541. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2542. return WC_TEST_RET_ENC_EC(ret);
  2543. outLen = sizeof(out);
  2544. ret = Base64_Decode(badPadding, sizeof(badPadding), out, &outLen);
  2545. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2546. return WC_TEST_RET_ENC_EC(ret);
  2547. /* Bad character at each offset 0-3. */
  2548. for (i = 0; i < 4; i++) {
  2549. outLen = sizeof(out);
  2550. ret = Base64_Decode(badSmall + i, 4, out, &outLen);
  2551. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2552. return WC_TEST_RET_ENC_I(i);
  2553. ret = Base64_Decode(badLarge + i, 4, out, &outLen);
  2554. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2555. return WC_TEST_RET_ENC_I(i);
  2556. }
  2557. /* Invalid character less than 0x2b */
  2558. for (i = 1; i < 0x2b; i++) {
  2559. outLen = sizeof(out);
  2560. charTest[0] = (byte)i;
  2561. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2562. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2563. return WC_TEST_RET_ENC_I(i);
  2564. }
  2565. /* Bad characters in range 0x2b - 0x7a. */
  2566. for (i = 0; i < (int)sizeof(badChar) - 1; i++) {
  2567. outLen = sizeof(out);
  2568. charTest[0] = badChar[i];
  2569. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2570. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2571. return WC_TEST_RET_ENC_I(i);
  2572. }
  2573. /* Invalid character greater than 0x7a */
  2574. for (i = 0x7b; i < 0x100; i++) {
  2575. outLen = sizeof(out);
  2576. charTest[0] = (byte)i;
  2577. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2578. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2579. return WC_TEST_RET_ENC_I(i);
  2580. }
  2581. #ifdef WOLFSSL_BASE64_ENCODE
  2582. /* Decode and encode all symbols - non-alphanumeric. */
  2583. dataLen = sizeof(data);
  2584. ret = Base64_Decode(symbols, sizeof(symbols), data, &dataLen);
  2585. if (ret != 0)
  2586. return WC_TEST_RET_ENC_EC(ret);
  2587. outLen = sizeof(out);
  2588. ret = Base64_Encode(data, dataLen, NULL, &outLen);
  2589. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2590. return WC_TEST_RET_ENC_EC(ret);
  2591. outLen = sizeof(out);
  2592. ret = Base64_Encode(data, dataLen, out, &outLen);
  2593. if (ret != 0)
  2594. return WC_TEST_RET_ENC_EC(ret);
  2595. outLen = 7;
  2596. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2597. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  2598. return WC_TEST_RET_ENC_EC(ret);
  2599. outLen = sizeof(out);
  2600. ret = Base64_EncodeEsc(data, dataLen, NULL, &outLen);
  2601. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2602. return WC_TEST_RET_ENC_EC(ret);
  2603. outLen = sizeof(out);
  2604. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2605. if (ret != 0)
  2606. return WC_TEST_RET_ENC_EC(ret);
  2607. outLen = sizeof(out);
  2608. ret = Base64_Encode_NoNl(data, dataLen, out, &outLen);
  2609. if (ret != 0)
  2610. return WC_TEST_RET_ENC_EC(ret);
  2611. /* Data that results in an encoding longer than one line. */
  2612. outLen = sizeof(out);
  2613. dataLen = sizeof(longData);
  2614. ret = Base64_Encode(longData, dataLen, out, &outLen);
  2615. if (ret != 0)
  2616. return WC_TEST_RET_ENC_EC(ret);
  2617. outLen = sizeof(out);
  2618. ret = Base64_EncodeEsc(longData, dataLen, out, &outLen);
  2619. if (ret != 0)
  2620. return WC_TEST_RET_ENC_EC(ret);
  2621. outLen = sizeof(out);
  2622. ret = Base64_Encode_NoNl(longData, dataLen, out, &outLen);
  2623. if (ret != 0)
  2624. return WC_TEST_RET_ENC_EC(ret);
  2625. #endif
  2626. return 0;
  2627. }
  2628. #ifdef WOLFSSL_BASE16
  2629. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void)
  2630. {
  2631. wc_test_ret_t ret;
  2632. WOLFSSL_SMALL_STACK_STATIC const byte testData[] = "SomeDataToEncode\n";
  2633. WOLFSSL_SMALL_STACK_STATIC const byte encodedTestData[] = "536F6D6544617461546F456E636F64650A00";
  2634. byte encoded[40];
  2635. word32 encodedLen;
  2636. byte plain[40];
  2637. word32 len;
  2638. WOLFSSL_ENTER("base16_test");
  2639. /* length returned includes null termination */
  2640. encodedLen = sizeof(encoded);
  2641. ret = Base16_Encode(testData, sizeof(testData), encoded, &encodedLen);
  2642. if (ret != 0)
  2643. return WC_TEST_RET_ENC_EC(ret);
  2644. len = (word32)XSTRLEN((char*)encoded);
  2645. if (len != encodedLen - 1)
  2646. return WC_TEST_RET_ENC_NC;
  2647. len = sizeof(plain);
  2648. ret = Base16_Decode(encoded, encodedLen - 1, plain, &len);
  2649. if (ret != 0)
  2650. return WC_TEST_RET_ENC_EC(ret);
  2651. if (len != sizeof(testData) || XMEMCMP(testData, plain, len) != 0)
  2652. return WC_TEST_RET_ENC_NC;
  2653. if (encodedLen != sizeof(encodedTestData) ||
  2654. XMEMCMP(encoded, encodedTestData, encodedLen) != 0) {
  2655. return WC_TEST_RET_ENC_NC;
  2656. }
  2657. return 0;
  2658. }
  2659. #endif /* WOLFSSL_BASE16 */
  2660. #endif /* !NO_CODING */
  2661. #ifndef NO_ASN
  2662. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void)
  2663. {
  2664. wc_test_ret_t ret;
  2665. /* ASN1 encoded date buffer */
  2666. WOLFSSL_SMALL_STACK_STATIC const byte dateBuf[] = {
  2667. 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x31,
  2668. 0x32, 0x30, 0x30, 0x37, 0x33, 0x37, 0x5a
  2669. };
  2670. byte format;
  2671. int length;
  2672. const byte* datePart;
  2673. #ifndef NO_ASN_TIME
  2674. struct tm timearg;
  2675. time_t now;
  2676. #endif
  2677. WOLFSSL_ENTER("asn_test");
  2678. ret = wc_GetDateInfo(dateBuf, (int)sizeof(dateBuf), &datePart, &format,
  2679. &length);
  2680. if (ret != 0)
  2681. return WC_TEST_RET_ENC_EC(ret);
  2682. #ifndef NO_ASN_TIME
  2683. /* Parameter Validation tests. */
  2684. if ((ret = wc_GetTime(NULL, sizeof(now))) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2685. return WC_TEST_RET_ENC_EC(ret);
  2686. if ((ret = wc_GetTime(&now, 0)) != WC_NO_ERR_TRACE(BUFFER_E))
  2687. return WC_TEST_RET_ENC_EC(ret);
  2688. now = 0;
  2689. if ((ret = wc_GetTime(&now, sizeof(now))) != 0) {
  2690. return WC_TEST_RET_ENC_EC(ret);
  2691. }
  2692. if (now == 0) {
  2693. printf("RTC/Time not set!\n");
  2694. return WC_TEST_RET_ENC_NC;
  2695. }
  2696. ret = wc_GetDateAsCalendarTime(datePart, length, format, &timearg);
  2697. if (ret != 0)
  2698. return WC_TEST_RET_ENC_EC(ret);
  2699. #endif /* !NO_ASN_TIME */
  2700. return 0;
  2701. }
  2702. #endif /* !NO_ASN */
  2703. #ifdef WOLFSSL_MD2
  2704. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void)
  2705. {
  2706. wc_test_ret_t ret = 0;
  2707. Md2 md2;
  2708. byte hash[MD2_DIGEST_SIZE];
  2709. testVector a, b, c, d, e, f, g;
  2710. testVector test_md2[7];
  2711. int times = sizeof(test_md2) / sizeof(testVector), i;
  2712. WOLFSSL_ENTER("md2_test");
  2713. a.input = "";
  2714. a.output = "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69"
  2715. "\x27\x73";
  2716. a.inLen = XSTRLEN(a.input);
  2717. a.outLen = MD2_DIGEST_SIZE;
  2718. b.input = "a";
  2719. b.output = "\x32\xec\x01\xec\x4a\x6d\xac\x72\xc0\xab\x96\xfb\x34\xc0"
  2720. "\xb5\xd1";
  2721. b.inLen = XSTRLEN(b.input);
  2722. b.outLen = MD2_DIGEST_SIZE;
  2723. c.input = "abc";
  2724. c.output = "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde"
  2725. "\xd6\xbb";
  2726. c.inLen = XSTRLEN(c.input);
  2727. c.outLen = MD2_DIGEST_SIZE;
  2728. d.input = "message digest";
  2729. d.output = "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe"
  2730. "\x06\xb0";
  2731. d.inLen = XSTRLEN(d.input);
  2732. d.outLen = MD2_DIGEST_SIZE;
  2733. e.input = "abcdefghijklmnopqrstuvwxyz";
  2734. e.output = "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47"
  2735. "\x94\x0b";
  2736. e.inLen = XSTRLEN(e.input);
  2737. e.outLen = MD2_DIGEST_SIZE;
  2738. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2739. "6789";
  2740. f.output = "\xda\x33\xde\xf2\xa4\x2d\xf1\x39\x75\x35\x28\x46\xc3\x03"
  2741. "\x38\xcd";
  2742. f.inLen = XSTRLEN(f.input);
  2743. f.outLen = MD2_DIGEST_SIZE;
  2744. g.input = "1234567890123456789012345678901234567890123456789012345678"
  2745. "9012345678901234567890";
  2746. g.output = "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3"
  2747. "\xef\xd8";
  2748. g.inLen = XSTRLEN(g.input);
  2749. g.outLen = MD2_DIGEST_SIZE;
  2750. test_md2[0] = a;
  2751. test_md2[1] = b;
  2752. test_md2[2] = c;
  2753. test_md2[3] = d;
  2754. test_md2[4] = e;
  2755. test_md2[5] = f;
  2756. test_md2[6] = g;
  2757. wc_InitMd2(&md2);
  2758. for (i = 0; i < times; ++i) {
  2759. wc_Md2Update(&md2, (byte*)test_md2[i].input, (word32)test_md2[i].inLen);
  2760. wc_Md2Final(&md2, hash);
  2761. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0)
  2762. return WC_TEST_RET_ENC_I(i);
  2763. }
  2764. for (i = 0; i < times; ++i) {
  2765. ret = wc_Md2Hash((byte*)test_md2[i].input, (word32)test_md2[i].inLen, hash);
  2766. if (ret != 0) {
  2767. return WC_TEST_RET_ENC_I(i);
  2768. }
  2769. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) {
  2770. return WC_TEST_RET_ENC_I(i);
  2771. }
  2772. }
  2773. return 0;
  2774. }
  2775. #endif
  2776. #ifndef NO_MD5
  2777. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void)
  2778. {
  2779. wc_test_ret_t ret = 0;
  2780. wc_Md5 md5, md5Copy;
  2781. byte hash[WC_MD5_DIGEST_SIZE];
  2782. byte hashcopy[WC_MD5_DIGEST_SIZE];
  2783. testVector a, b, c, d, e, f;
  2784. testVector test_md5[6];
  2785. int times = sizeof(test_md5) / sizeof(testVector), i;
  2786. WOLFSSL_ENTER("md5_test");
  2787. a.input = "";
  2788. a.output = "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42"
  2789. "\x7e";
  2790. a.inLen = XSTRLEN(a.input);
  2791. a.outLen = WC_MD5_DIGEST_SIZE;
  2792. b.input = "abc";
  2793. b.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  2794. "\x72";
  2795. b.inLen = XSTRLEN(b.input);
  2796. b.outLen = WC_MD5_DIGEST_SIZE;
  2797. c.input = "message digest";
  2798. c.output = "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61"
  2799. "\xd0";
  2800. c.inLen = XSTRLEN(c.input);
  2801. c.outLen = WC_MD5_DIGEST_SIZE;
  2802. d.input = "abcdefghijklmnopqrstuvwxyz";
  2803. d.output = "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1"
  2804. "\x3b";
  2805. d.inLen = XSTRLEN(d.input);
  2806. d.outLen = WC_MD5_DIGEST_SIZE;
  2807. e.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2808. "6789";
  2809. e.output = "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d"
  2810. "\x9f";
  2811. e.inLen = XSTRLEN(e.input);
  2812. e.outLen = WC_MD5_DIGEST_SIZE;
  2813. f.input = "1234567890123456789012345678901234567890123456789012345678"
  2814. "9012345678901234567890";
  2815. f.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  2816. "\x7a";
  2817. f.inLen = XSTRLEN(f.input);
  2818. f.outLen = WC_MD5_DIGEST_SIZE;
  2819. test_md5[0] = a;
  2820. test_md5[1] = b;
  2821. test_md5[2] = c;
  2822. test_md5[3] = d;
  2823. test_md5[4] = e;
  2824. test_md5[5] = f;
  2825. ret = wc_InitMd5_ex(&md5, HEAP_HINT, devId);
  2826. if (ret != 0)
  2827. return WC_TEST_RET_ENC_EC(ret);
  2828. ret = wc_InitMd5_ex(&md5Copy, HEAP_HINT, devId);
  2829. if (ret != 0) {
  2830. wc_Md5Free(&md5);
  2831. return WC_TEST_RET_ENC_EC(ret);
  2832. }
  2833. for (i = 0; i < times; ++i) {
  2834. ret = wc_Md5Update(&md5, (byte*)test_md5[i].input,
  2835. (word32)test_md5[i].inLen);
  2836. if (ret != 0)
  2837. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2838. ret = wc_Md5GetHash(&md5, hashcopy);
  2839. if (ret != 0)
  2840. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2841. ret = wc_Md5Copy(&md5, &md5Copy);
  2842. if (ret != 0)
  2843. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2844. ret = wc_Md5Final(&md5, hash);
  2845. if (ret != 0)
  2846. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2847. wc_Md5Free(&md5Copy);
  2848. if (XMEMCMP(hash, test_md5[i].output, WC_MD5_DIGEST_SIZE) != 0)
  2849. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2850. if (XMEMCMP(hash, hashcopy, WC_MD5_DIGEST_SIZE) != 0)
  2851. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2852. }
  2853. #ifndef NO_LARGE_HASH_TEST
  2854. /* BEGIN LARGE HASH TEST */ {
  2855. byte large_input[1024];
  2856. const char* large_digest =
  2857. "\x44\xd0\x88\xce\xf1\x36\xd1\x78\xe9\xc8\xba\x84\xc3\xfd\xf6\xca";
  2858. for (i = 0; i < (int)sizeof(large_input); i++) {
  2859. large_input[i] = (byte)(i & 0xFF);
  2860. }
  2861. times = 100;
  2862. #ifdef WOLFSSL_PIC32MZ_HASH
  2863. wc_Md5SizeSet(&md5, times * sizeof(large_input));
  2864. #endif
  2865. for (i = 0; i < times; ++i) {
  2866. ret = wc_Md5Update(&md5, (byte*)large_input,
  2867. (word32)sizeof(large_input));
  2868. if (ret != 0)
  2869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2870. }
  2871. ret = wc_Md5Final(&md5, hash);
  2872. if (ret != 0)
  2873. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2874. if (XMEMCMP(hash, large_digest, WC_MD5_DIGEST_SIZE) != 0)
  2875. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  2876. } /* END LARGE HASH TEST */
  2877. #endif /* NO_LARGE_HASH_TEST */
  2878. exit:
  2879. wc_Md5Free(&md5);
  2880. wc_Md5Free(&md5Copy);
  2881. return ret;
  2882. }
  2883. #endif /* NO_MD5 */
  2884. #ifndef NO_MD4
  2885. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void)
  2886. {
  2887. Md4 md4;
  2888. byte hash[MD4_DIGEST_SIZE];
  2889. testVector a, b, c, d, e, f, g;
  2890. testVector test_md4[7];
  2891. int times = sizeof(test_md4) / sizeof(testVector), i;
  2892. WOLFSSL_ENTER("md4_test");
  2893. a.input = "";
  2894. a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
  2895. "\xc0";
  2896. a.inLen = XSTRLEN(a.input);
  2897. a.outLen = MD4_DIGEST_SIZE;
  2898. b.input = "a";
  2899. b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
  2900. "\x24";
  2901. b.inLen = XSTRLEN(b.input);
  2902. b.outLen = MD4_DIGEST_SIZE;
  2903. c.input = "abc";
  2904. c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
  2905. "\x9d";
  2906. c.inLen = XSTRLEN(c.input);
  2907. c.outLen = MD4_DIGEST_SIZE;
  2908. d.input = "message digest";
  2909. d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
  2910. "\x4b";
  2911. d.inLen = XSTRLEN(d.input);
  2912. d.outLen = MD4_DIGEST_SIZE;
  2913. e.input = "abcdefghijklmnopqrstuvwxyz";
  2914. e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
  2915. "\xa9";
  2916. e.inLen = XSTRLEN(e.input);
  2917. e.outLen = MD4_DIGEST_SIZE;
  2918. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2919. "6789";
  2920. f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
  2921. "\xe4";
  2922. f.inLen = XSTRLEN(f.input);
  2923. f.outLen = MD4_DIGEST_SIZE;
  2924. g.input = "1234567890123456789012345678901234567890123456789012345678"
  2925. "9012345678901234567890";
  2926. g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
  2927. "\x36";
  2928. g.inLen = XSTRLEN(g.input);
  2929. g.outLen = MD4_DIGEST_SIZE;
  2930. test_md4[0] = a;
  2931. test_md4[1] = b;
  2932. test_md4[2] = c;
  2933. test_md4[3] = d;
  2934. test_md4[4] = e;
  2935. test_md4[5] = f;
  2936. test_md4[6] = g;
  2937. wc_InitMd4(&md4);
  2938. for (i = 0; i < times; ++i) {
  2939. wc_Md4Update(&md4, (byte*)test_md4[i].input, (word32)test_md4[i].inLen);
  2940. wc_Md4Final(&md4, hash);
  2941. if (XMEMCMP(hash, test_md4[i].output, MD4_DIGEST_SIZE) != 0)
  2942. return WC_TEST_RET_ENC_I(i);
  2943. }
  2944. return 0;
  2945. }
  2946. #endif /* NO_MD4 */
  2947. #ifndef NO_SHA
  2948. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void)
  2949. {
  2950. wc_test_ret_t ret = 0;
  2951. wc_Sha sha, shaCopy;
  2952. byte hash[WC_SHA_DIGEST_SIZE];
  2953. byte hashcopy[WC_SHA_DIGEST_SIZE];
  2954. testVector a, b, c, d, e;
  2955. testVector test_sha[5];
  2956. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  2957. WOLFSSL_ENTER("sha_test");
  2958. a.input = "";
  2959. a.output = "\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18"
  2960. "\x90\xaf\xd8\x07\x09";
  2961. a.inLen = XSTRLEN(a.input);
  2962. a.outLen = WC_SHA_DIGEST_SIZE;
  2963. b.input = "abc";
  2964. b.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  2965. "\x6C\x9C\xD0\xD8\x9D";
  2966. b.inLen = XSTRLEN(b.input);
  2967. b.outLen = WC_SHA_DIGEST_SIZE;
  2968. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  2969. c.output = "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
  2970. "\xE5\xE5\x46\x70\xF1";
  2971. c.inLen = XSTRLEN(c.input);
  2972. c.outLen = WC_SHA_DIGEST_SIZE;
  2973. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  2974. "aaaaaa";
  2975. d.output = "\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
  2976. "\x2A\x25\xEC\x64\x4D";
  2977. d.inLen = XSTRLEN(d.input);
  2978. d.outLen = WC_SHA_DIGEST_SIZE;
  2979. e.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  2980. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  2981. "aaaaaaaaaa";
  2982. e.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  2983. "\x53\x99\x5E\x26\xA0";
  2984. e.inLen = XSTRLEN(e.input);
  2985. e.outLen = WC_SHA_DIGEST_SIZE;
  2986. test_sha[0] = a;
  2987. test_sha[1] = b;
  2988. test_sha[2] = c;
  2989. test_sha[3] = d;
  2990. test_sha[4] = e;
  2991. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  2992. if (ret != 0)
  2993. return WC_TEST_RET_ENC_EC(ret);
  2994. ret = wc_InitSha_ex(&shaCopy, HEAP_HINT, devId);
  2995. if (ret != 0) {
  2996. wc_ShaFree(&sha);
  2997. return WC_TEST_RET_ENC_EC(ret);
  2998. }
  2999. for (i = 0; i < times; ++i) {
  3000. ret = wc_ShaUpdate(&sha, (byte*)test_sha[i].input,
  3001. (word32)test_sha[i].inLen);
  3002. if (ret != 0)
  3003. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3004. ret = wc_ShaGetHash(&sha, hashcopy);
  3005. if (ret != 0)
  3006. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3007. ret = wc_ShaCopy(&sha, &shaCopy);
  3008. if (ret != 0)
  3009. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3010. ret = wc_ShaFinal(&sha, hash);
  3011. if (ret != 0)
  3012. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3013. wc_ShaFree(&shaCopy);
  3014. if (XMEMCMP(hash, test_sha[i].output, WC_SHA_DIGEST_SIZE) != 0)
  3015. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3016. if (XMEMCMP(hash, hashcopy, WC_SHA_DIGEST_SIZE) != 0)
  3017. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3018. }
  3019. #ifndef NO_LARGE_HASH_TEST
  3020. /* BEGIN LARGE HASH TEST */ {
  3021. byte large_input[1024];
  3022. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3023. defined(HASH_SIZE_LIMIT)
  3024. const char* large_digest =
  3025. "\x1d\x6a\x5a\xf6\xe5\x7c\x86\xce\x7f\x7c\xaf\xd5\xdb\x08\xcd\x59"
  3026. "\x15\x8c\x6d\xb6";
  3027. #else
  3028. const char* large_digest =
  3029. "\x8b\x77\x02\x48\x39\xe8\xdb\xd3\x9a\xf4\x05\x24\x66\x12\x2d\x9e"
  3030. "\xc5\xd9\x0a\xac";
  3031. #endif
  3032. for (i = 0; i < (int)sizeof(large_input); i++) {
  3033. large_input[i] = (byte)(i & 0xFF);
  3034. }
  3035. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3036. defined(HASH_SIZE_LIMIT)
  3037. times = 20;
  3038. #else
  3039. times = 100;
  3040. #endif
  3041. #ifdef WOLFSSL_PIC32MZ_HASH
  3042. wc_ShaSizeSet(&sha, times * sizeof(large_input));
  3043. #endif
  3044. for (i = 0; i < times; ++i) {
  3045. ret = wc_ShaUpdate(&sha, (byte*)large_input,
  3046. (word32)sizeof(large_input));
  3047. if (ret != 0)
  3048. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3049. }
  3050. ret = wc_ShaFinal(&sha, hash);
  3051. if (ret != 0)
  3052. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3053. if (XMEMCMP(hash, large_digest, WC_SHA_DIGEST_SIZE) != 0)
  3054. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3055. } /* END LARGE HASH TEST */
  3056. #endif /* NO_LARGE_HASH_TEST */
  3057. exit:
  3058. wc_ShaFree(&sha);
  3059. wc_ShaFree(&shaCopy);
  3060. return ret;
  3061. }
  3062. #endif /* NO_SHA */
  3063. #ifdef WOLFSSL_RIPEMD
  3064. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void)
  3065. {
  3066. RipeMd ripemd;
  3067. wc_test_ret_t ret;
  3068. byte hash[RIPEMD_DIGEST_SIZE];
  3069. testVector a, b, c, d;
  3070. testVector test_ripemd[4];
  3071. int times = sizeof(test_ripemd) / sizeof(struct testVector), i;
  3072. WOLFSSL_ENTER("ripemd_test");
  3073. a.input = "abc";
  3074. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  3075. "\xb0\x87\xf1\x5a\x0b\xfc";
  3076. a.inLen = XSTRLEN(a.input);
  3077. a.outLen = RIPEMD_DIGEST_SIZE;
  3078. b.input = "message digest";
  3079. b.output = "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8"
  3080. "\x5f\xfa\x21\x59\x5f\x36";
  3081. b.inLen = XSTRLEN(b.input);
  3082. b.outLen = RIPEMD_DIGEST_SIZE;
  3083. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3084. c.output = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
  3085. "\xf4\x9a\xda\x62\xeb\x2b";
  3086. c.inLen = XSTRLEN(c.input);
  3087. c.outLen = RIPEMD_DIGEST_SIZE;
  3088. d.input = "12345678901234567890123456789012345678901234567890123456"
  3089. "789012345678901234567890";
  3090. d.output = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
  3091. "\x82\xbf\x63\x32\x6b\xfb";
  3092. d.inLen = XSTRLEN(d.input);
  3093. d.outLen = RIPEMD_DIGEST_SIZE;
  3094. test_ripemd[0] = a;
  3095. test_ripemd[1] = b;
  3096. test_ripemd[2] = c;
  3097. test_ripemd[3] = d;
  3098. ret = wc_InitRipeMd(&ripemd);
  3099. if (ret != 0) {
  3100. return WC_TEST_RET_ENC_EC(ret);
  3101. }
  3102. for (i = 0; i < times; ++i) {
  3103. ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
  3104. (word32)test_ripemd[i].inLen);
  3105. if (ret != 0) {
  3106. return WC_TEST_RET_ENC_I(i);
  3107. }
  3108. ret = wc_RipeMdFinal(&ripemd, hash);
  3109. if (ret != 0) {
  3110. return WC_TEST_RET_ENC_I(i);
  3111. }
  3112. if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
  3113. return WC_TEST_RET_ENC_I(i);
  3114. }
  3115. return 0;
  3116. }
  3117. #endif /* WOLFSSL_RIPEMD */
  3118. #ifdef HAVE_BLAKE2
  3119. #define BLAKE2B_TESTS 3
  3120. static const byte blake2b_vec[BLAKE2B_TESTS][BLAKE2B_OUTBYTES] =
  3121. {
  3122. {
  3123. 0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03,
  3124. 0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72,
  3125. 0x91, 0x2F, 0x47, 0x40, 0xE1, 0x58, 0x47, 0x61,
  3126. 0x8A, 0x86, 0xE2, 0x17, 0xF7, 0x1F, 0x54, 0x19,
  3127. 0xD2, 0x5E, 0x10, 0x31, 0xAF, 0xEE, 0x58, 0x53,
  3128. 0x13, 0x89, 0x64, 0x44, 0x93, 0x4E, 0xB0, 0x4B,
  3129. 0x90, 0x3A, 0x68, 0x5B, 0x14, 0x48, 0xB7, 0x55,
  3130. 0xD5, 0x6F, 0x70, 0x1A, 0xFE, 0x9B, 0xE2, 0xCE
  3131. },
  3132. {
  3133. 0x2F, 0xA3, 0xF6, 0x86, 0xDF, 0x87, 0x69, 0x95,
  3134. 0x16, 0x7E, 0x7C, 0x2E, 0x5D, 0x74, 0xC4, 0xC7,
  3135. 0xB6, 0xE4, 0x8F, 0x80, 0x68, 0xFE, 0x0E, 0x44,
  3136. 0x20, 0x83, 0x44, 0xD4, 0x80, 0xF7, 0x90, 0x4C,
  3137. 0x36, 0x96, 0x3E, 0x44, 0x11, 0x5F, 0xE3, 0xEB,
  3138. 0x2A, 0x3A, 0xC8, 0x69, 0x4C, 0x28, 0xBC, 0xB4,
  3139. 0xF5, 0xA0, 0xF3, 0x27, 0x6F, 0x2E, 0x79, 0x48,
  3140. 0x7D, 0x82, 0x19, 0x05, 0x7A, 0x50, 0x6E, 0x4B
  3141. },
  3142. {
  3143. 0x1C, 0x08, 0x79, 0x8D, 0xC6, 0x41, 0xAB, 0xA9,
  3144. 0xDE, 0xE4, 0x35, 0xE2, 0x25, 0x19, 0xA4, 0x72,
  3145. 0x9A, 0x09, 0xB2, 0xBF, 0xE0, 0xFF, 0x00, 0xEF,
  3146. 0x2D, 0xCD, 0x8E, 0xD6, 0xF8, 0xA0, 0x7D, 0x15,
  3147. 0xEA, 0xF4, 0xAE, 0xE5, 0x2B, 0xBF, 0x18, 0xAB,
  3148. 0x56, 0x08, 0xA6, 0x19, 0x0F, 0x70, 0xB9, 0x04,
  3149. 0x86, 0xC8, 0xA7, 0xD4, 0x87, 0x37, 0x10, 0xB1,
  3150. 0x11, 0x5D, 0x3D, 0xEB, 0xBB, 0x43, 0x27, 0xB5
  3151. }
  3152. };
  3153. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void)
  3154. {
  3155. Blake2b b2b;
  3156. byte digest[64];
  3157. byte input[64];
  3158. int i, ret;
  3159. WOLFSSL_ENTER("blake2b_test");
  3160. for (i = 0; i < (int)sizeof(input); i++)
  3161. input[i] = (byte)i;
  3162. for (i = 0; i < BLAKE2B_TESTS; i++) {
  3163. ret = wc_InitBlake2b(&b2b, 64);
  3164. if (ret != 0)
  3165. return WC_TEST_RET_ENC_I(i);
  3166. ret = wc_Blake2bUpdate(&b2b, input, (word32)i);
  3167. if (ret != 0)
  3168. return WC_TEST_RET_ENC_I(i);
  3169. ret = wc_Blake2bFinal(&b2b, digest, 64);
  3170. if (ret != 0)
  3171. return WC_TEST_RET_ENC_I(i);
  3172. if (XMEMCMP(digest, blake2b_vec[i], 64) != 0) {
  3173. return WC_TEST_RET_ENC_I(i);
  3174. }
  3175. }
  3176. return 0;
  3177. }
  3178. #endif /* HAVE_BLAKE2 */
  3179. #ifdef HAVE_BLAKE2S
  3180. #define BLAKE2S_TESTS 3
  3181. static const byte blake2s_vec[BLAKE2S_TESTS][BLAKE2S_OUTBYTES] =
  3182. {
  3183. {
  3184. 0x69, 0x21, 0x7a, 0x30, 0x79, 0x90, 0x80, 0x94,
  3185. 0xe1, 0x11, 0x21, 0xd0, 0x42, 0x35, 0x4a, 0x7c,
  3186. 0x1f, 0x55, 0xb6, 0x48, 0x2c, 0xa1, 0xa5, 0x1e,
  3187. 0x1b, 0x25, 0x0d, 0xfd, 0x1e, 0xd0, 0xee, 0xf9,
  3188. },
  3189. {
  3190. 0xe3, 0x4d, 0x74, 0xdb, 0xaf, 0x4f, 0xf4, 0xc6,
  3191. 0xab, 0xd8, 0x71, 0xcc, 0x22, 0x04, 0x51, 0xd2,
  3192. 0xea, 0x26, 0x48, 0x84, 0x6c, 0x77, 0x57, 0xfb,
  3193. 0xaa, 0xc8, 0x2f, 0xe5, 0x1a, 0xd6, 0x4b, 0xea,
  3194. },
  3195. {
  3196. 0xdd, 0xad, 0x9a, 0xb1, 0x5d, 0xac, 0x45, 0x49,
  3197. 0xba, 0x42, 0xf4, 0x9d, 0x26, 0x24, 0x96, 0xbe,
  3198. 0xf6, 0xc0, 0xba, 0xe1, 0xdd, 0x34, 0x2a, 0x88,
  3199. 0x08, 0xf8, 0xea, 0x26, 0x7c, 0x6e, 0x21, 0x0c,
  3200. }
  3201. };
  3202. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void)
  3203. {
  3204. Blake2s b2s;
  3205. byte digest[32];
  3206. byte input[64];
  3207. int i, ret;
  3208. WOLFSSL_ENTER("blake2s_test");
  3209. for (i = 0; i < (int)sizeof(input); i++)
  3210. input[i] = (byte)i;
  3211. for (i = 0; i < BLAKE2S_TESTS; i++) {
  3212. ret = wc_InitBlake2s(&b2s, 32);
  3213. if (ret != 0)
  3214. return WC_TEST_RET_ENC_I(i);
  3215. ret = wc_Blake2sUpdate(&b2s, input, (word32)i);
  3216. if (ret != 0)
  3217. return WC_TEST_RET_ENC_I(i);
  3218. ret = wc_Blake2sFinal(&b2s, digest, 32);
  3219. if (ret != 0)
  3220. return WC_TEST_RET_ENC_I(i);
  3221. if (XMEMCMP(digest, blake2s_vec[i], 32) != 0) {
  3222. return WC_TEST_RET_ENC_I(i);
  3223. }
  3224. }
  3225. return 0;
  3226. }
  3227. #endif /* HAVE_BLAKE2S */
  3228. #ifdef WOLFSSL_SHA224
  3229. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void)
  3230. {
  3231. wc_Sha224 sha, shaCopy;
  3232. byte hash[WC_SHA224_DIGEST_SIZE];
  3233. byte hashcopy[WC_SHA224_DIGEST_SIZE];
  3234. wc_test_ret_t ret = 0;
  3235. testVector a, b, c;
  3236. testVector test_sha[3];
  3237. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3238. WOLFSSL_ENTER("sha224_test");
  3239. a.input = "";
  3240. a.output = "\xd1\x4a\x02\x8c\x2a\x3a\x2b\xc9\x47\x61\x02\xbb\x28\x82\x34"
  3241. "\xc4\x15\xa2\xb0\x1f\x82\x8e\xa6\x2a\xc5\xb3\xe4\x2f";
  3242. a.inLen = XSTRLEN(a.input);
  3243. a.outLen = WC_SHA224_DIGEST_SIZE;
  3244. b.input = "abc";
  3245. b.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55"
  3246. "\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  3247. b.inLen = XSTRLEN(b.input);
  3248. b.outLen = WC_SHA224_DIGEST_SIZE;
  3249. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3250. c.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  3251. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  3252. c.inLen = XSTRLEN(c.input);
  3253. c.outLen = WC_SHA224_DIGEST_SIZE;
  3254. test_sha[0] = a;
  3255. test_sha[1] = b;
  3256. test_sha[2] = c;
  3257. ret = wc_InitSha224_ex(&sha, HEAP_HINT, devId);
  3258. if (ret != 0)
  3259. return WC_TEST_RET_ENC_EC(ret);
  3260. ret = wc_InitSha224_ex(&shaCopy, HEAP_HINT, devId);
  3261. if (ret != 0) {
  3262. wc_Sha224Free(&sha);
  3263. return WC_TEST_RET_ENC_EC(ret);
  3264. }
  3265. for (i = 0; i < times; ++i) {
  3266. ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,
  3267. (word32)test_sha[i].inLen);
  3268. if (ret != 0)
  3269. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3270. ret = wc_Sha224GetHash(&sha, hashcopy);
  3271. if (ret != 0)
  3272. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3273. ret = wc_Sha224Copy(&sha, &shaCopy);
  3274. if (ret != 0)
  3275. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3276. ret = wc_Sha224Final(&sha, hash);
  3277. if (ret != 0)
  3278. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3279. wc_Sha224Free(&shaCopy);
  3280. if (XMEMCMP(hash, test_sha[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  3281. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3282. if (XMEMCMP(hash, hashcopy, WC_SHA224_DIGEST_SIZE) != 0)
  3283. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3284. }
  3285. exit:
  3286. wc_Sha224Free(&sha);
  3287. wc_Sha224Free(&shaCopy);
  3288. return ret;
  3289. }
  3290. #endif
  3291. #ifndef NO_SHA256
  3292. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
  3293. {
  3294. wc_Sha256 sha, shaCopy;
  3295. byte hash[WC_SHA256_DIGEST_SIZE];
  3296. byte hashcopy[WC_SHA256_DIGEST_SIZE];
  3297. wc_test_ret_t ret = 0;
  3298. testVector a, b, c, d;
  3299. testVector test_sha[4];
  3300. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3301. byte i_hash[WC_SHA256_DIGEST_SIZE];
  3302. byte i_hashcopy[WC_SHA256_DIGEST_SIZE];
  3303. testVector interleave_test_sha[4];
  3304. wc_Sha256 i_sha, i_shaCopy;
  3305. #endif
  3306. #ifndef NO_LARGE_HASH_TEST
  3307. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3308. #ifdef WOLFSSL_SMALL_STACK
  3309. byte *large_input = NULL;
  3310. #else
  3311. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3312. #endif
  3313. #endif
  3314. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3315. WOLFSSL_ENTER("sha256_test");
  3316. a.input = "";
  3317. a.output = "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9"
  3318. "\x24\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52"
  3319. "\xb8\x55";
  3320. a.inLen = XSTRLEN(a.input);
  3321. a.outLen = WC_SHA256_DIGEST_SIZE;
  3322. b.input = "abc";
  3323. b.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  3324. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  3325. "\x15\xAD";
  3326. b.inLen = XSTRLEN(b.input);
  3327. b.outLen = WC_SHA256_DIGEST_SIZE;
  3328. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3329. c.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  3330. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  3331. "\x06\xC1";
  3332. c.inLen = XSTRLEN(c.input);
  3333. c.outLen = WC_SHA256_DIGEST_SIZE;
  3334. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3335. "aaaaaa"; /* this is BLOCKSIZE length */
  3336. d.output = "\xFF\xE0\x54\xFE\x7A\xE0\xCB\x6D\xC6\x5C\x3A\xF9\xB6\x1D\x52"
  3337. "\x09\xF4\x39\x85\x1D\xB4\x3D\x0B\xA5\x99\x73\x37\xDF\x15\x46"
  3338. "\x68\xEB";
  3339. d.inLen = XSTRLEN(d.input);
  3340. d.outLen = WC_SHA256_DIGEST_SIZE;
  3341. test_sha[0] = a;
  3342. test_sha[1] = b;
  3343. test_sha[2] = c;
  3344. test_sha[3] = d;
  3345. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3346. interleave_test_sha[0] = a;
  3347. interleave_test_sha[1] = b;
  3348. interleave_test_sha[2] = c;
  3349. interleave_test_sha[3] = d;
  3350. #endif
  3351. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  3352. if (ret != 0)
  3353. return WC_TEST_RET_ENC_EC(ret);
  3354. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3355. ret = wc_InitSha256_ex(&i_sha, HEAP_HINT, devId);
  3356. if (ret != 0)
  3357. return WC_TEST_RET_ENC_EC(ret);
  3358. #endif
  3359. ret = wc_InitSha256_ex(&shaCopy, HEAP_HINT, devId);
  3360. if (ret != 0) {
  3361. wc_Sha256Free(&sha);
  3362. return WC_TEST_RET_ENC_EC(ret);
  3363. }
  3364. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3365. ret = wc_InitSha256_ex(&i_shaCopy, HEAP_HINT, devId);
  3366. if (ret != 0) {
  3367. wc_Sha256Free(&sha);
  3368. wc_Sha256Free(&i_sha);
  3369. return WC_TEST_RET_ENC_EC(ret);
  3370. }
  3371. #endif
  3372. for (i = 0; i < times; ++i) {
  3373. ret = wc_Sha256Update(&sha, (byte*)test_sha[i].input,
  3374. (word32)test_sha[i].inLen);
  3375. if (ret != 0) {
  3376. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3377. }
  3378. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3379. ret = wc_Sha256Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3380. (word32)interleave_test_sha[i].inLen);
  3381. if (ret != 0) {
  3382. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3383. }
  3384. #endif
  3385. ret = wc_Sha256GetHash(&sha, hashcopy);
  3386. if (ret != 0)
  3387. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3388. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3389. ret = wc_Sha256GetHash(&i_sha, i_hashcopy);
  3390. if (ret != 0)
  3391. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3392. #endif
  3393. ret = wc_Sha256Copy(&sha, &shaCopy);
  3394. if (ret != 0)
  3395. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3396. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3397. ret = wc_Sha256Copy(&i_sha, &i_shaCopy);
  3398. if (ret != 0)
  3399. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3400. #endif
  3401. ret = wc_Sha256Final(&sha, hash);
  3402. if (ret != 0)
  3403. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3404. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3405. ret = wc_Sha256Final(&i_sha, i_hash);
  3406. if (ret != 0)
  3407. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3408. #endif
  3409. wc_Sha256Free(&shaCopy);
  3410. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3411. wc_Sha256Free(&i_shaCopy);
  3412. #endif
  3413. if (XMEMCMP(hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3414. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3415. }
  3416. if (XMEMCMP(hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3417. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3418. }
  3419. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3420. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3421. WC_SHA256_DIGEST_SIZE) != 0) {
  3422. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3423. }
  3424. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3425. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3426. }
  3427. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3428. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3429. }
  3430. if (XMEMCMP(i_hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3431. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3432. }
  3433. #endif
  3434. }
  3435. #ifndef NO_LARGE_HASH_TEST
  3436. /* BEGIN LARGE HASH TEST */ {
  3437. #ifdef HASH_SIZE_LIMIT
  3438. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3439. "\xa4\x75\x9e\x7a\xa2\x03\x38\x32\x88\x66\xa2\xea\x17\xea\xf8\xc7"
  3440. "\xfe\x4e\xc6\xbb\xe3\xbb\x71\xce\xe7\xdf\x7c\x04\x61\xb3\xc2\x2f";
  3441. #else
  3442. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3443. "\x27\x78\x3e\x87\x96\x3a\x4e\xfb\x68\x29\xb5\x31\xc9\xba\x57\xb4"
  3444. "\x4f\x45\x79\x7f\x67\x70\xbd\x63\x7f\xbf\x0d\x80\x7c\xbd\xba\xe0";
  3445. #endif
  3446. #ifdef WOLFSSL_SMALL_STACK
  3447. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3448. DYNAMIC_TYPE_TMP_BUFFER);
  3449. if (large_input == NULL) {
  3450. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3451. }
  3452. #endif
  3453. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3454. large_input[i] = (byte)(i & 0xFF);
  3455. }
  3456. #ifdef HASH_SIZE_LIMIT
  3457. times = 20;
  3458. #else
  3459. times = 100;
  3460. #endif
  3461. #ifdef WOLFSSL_PIC32MZ_HASH
  3462. wc_Sha256SizeSet(&sha, times * LARGE_HASH_TEST_INPUT_SZ);
  3463. #endif
  3464. for (i = 0; i < times; ++i) {
  3465. ret = wc_Sha256Update(&sha, (byte*)large_input,
  3466. LARGE_HASH_TEST_INPUT_SZ);
  3467. if (ret != 0)
  3468. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3469. }
  3470. ret = wc_Sha256Final(&sha, hash);
  3471. if (ret != 0)
  3472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3473. if (XMEMCMP(hash, large_digest, WC_SHA256_DIGEST_SIZE) != 0)
  3474. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3475. } /* END LARGE HASH TEST */
  3476. #undef LARGE_HASH_TEST_INPUT_SZ
  3477. #endif /* NO_LARGE_HASH_TEST */
  3478. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_FULL_HASH)
  3479. {
  3480. WOLFSSL_SMALL_STACK_STATIC const unsigned char
  3481. data_hb[WC_SHA256_BLOCK_SIZE] = {
  3482. 0x61, 0x62, 0x63, 0x80, 0x00, 0x00, 0x00, 0x00,
  3483. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3484. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3485. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3486. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3487. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3488. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3489. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18
  3490. };
  3491. ret = wc_Sha256HashBlock(&sha, data_hb, hash);
  3492. if (ret != 0) {
  3493. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3494. }
  3495. if (XMEMCMP(hash, b.output, WC_SHA256_DIGEST_SIZE) != 0) {
  3496. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3497. }
  3498. }
  3499. #endif
  3500. exit:
  3501. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3502. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3503. #endif
  3504. wc_Sha256Free(&sha);
  3505. wc_Sha256Free(&shaCopy);
  3506. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3507. wc_Sha256Free(&i_sha);
  3508. wc_Sha256Free(&i_shaCopy);
  3509. #endif
  3510. return ret;
  3511. }
  3512. #endif
  3513. #ifdef WOLFSSL_SHA512
  3514. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
  3515. {
  3516. /*
  3517. ** See https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512.pdf
  3518. */
  3519. wc_Sha512 sha, shaCopy;
  3520. byte hash[WC_SHA512_DIGEST_SIZE];
  3521. byte hashcopy[WC_SHA512_DIGEST_SIZE];
  3522. wc_test_ret_t ret = 0;
  3523. testVector a, b, c;
  3524. testVector test_sha[3];
  3525. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3526. wc_Sha512 i_sha, i_shaCopy;
  3527. byte i_hash[WC_SHA512_DIGEST_SIZE];
  3528. byte i_hashcopy[WC_SHA512_DIGEST_SIZE];
  3529. testVector interleave_test_sha[3];
  3530. #endif
  3531. #ifndef NO_LARGE_HASH_TEST
  3532. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3533. #ifdef WOLFSSL_SMALL_STACK
  3534. byte *large_input = NULL;
  3535. #else
  3536. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3537. #endif
  3538. #endif
  3539. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3540. WOLFSSL_ENTER("sha512_test");
  3541. a.input = "";
  3542. a.output = "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80"
  3543. "\x07\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c"
  3544. "\xe9\xce\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87"
  3545. "\x7e\xec\x2f\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a"
  3546. "\xf9\x27\xda\x3e";
  3547. a.inLen = XSTRLEN(a.input);
  3548. a.outLen = WC_SHA512_DIGEST_SIZE;
  3549. b.input = "abc";
  3550. b.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  3551. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  3552. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  3553. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  3554. "\xa5\x4c\xa4\x9f";
  3555. b.inLen = XSTRLEN(b.input);
  3556. b.outLen = WC_SHA512_DIGEST_SIZE;
  3557. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3558. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3559. c.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  3560. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  3561. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  3562. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  3563. "\x87\x4b\xe9\x09";
  3564. c.inLen = XSTRLEN(c.input);
  3565. c.outLen = WC_SHA512_DIGEST_SIZE;
  3566. test_sha[0] = a;
  3567. test_sha[1] = b;
  3568. test_sha[2] = c;
  3569. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3570. interleave_test_sha[0] = a;
  3571. interleave_test_sha[1] = b;
  3572. interleave_test_sha[2] = c;
  3573. #endif
  3574. ret = wc_InitSha512_ex(&sha, HEAP_HINT, devId);
  3575. if (ret != 0)
  3576. return WC_TEST_RET_ENC_EC(ret);
  3577. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3578. ret = wc_InitSha512_ex(&i_sha, HEAP_HINT, devId);
  3579. if (ret != 0)
  3580. return WC_TEST_RET_ENC_EC(ret);
  3581. #endif
  3582. ret = wc_InitSha512_ex(&shaCopy, HEAP_HINT, devId);
  3583. if (ret != 0) {
  3584. wc_Sha512Free(&sha);
  3585. return WC_TEST_RET_ENC_EC(ret);
  3586. }
  3587. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3588. ret = wc_InitSha512_ex(&i_shaCopy, HEAP_HINT, devId);
  3589. if (ret != 0) {
  3590. wc_Sha512Free(&sha);
  3591. wc_Sha512Free(&i_sha);
  3592. return WC_TEST_RET_ENC_EC(ret);
  3593. }
  3594. #endif
  3595. for (i = 0; i < times; ++i) {
  3596. ret = wc_Sha512Update(&sha, (byte*)test_sha[i].input,
  3597. (word32)test_sha[i].inLen);
  3598. if (ret != 0)
  3599. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3600. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3601. ret = wc_Sha512Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3602. (word32)interleave_test_sha[i].inLen);
  3603. if (ret != 0)
  3604. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3605. #endif
  3606. ret = wc_Sha512GetHash(&sha, hashcopy);
  3607. if (ret != 0)
  3608. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3609. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3610. ret = wc_Sha512GetHash(&i_sha, i_hashcopy);
  3611. if (ret != 0)
  3612. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3613. #endif
  3614. ret = wc_Sha512Copy(&sha, &shaCopy);
  3615. if (ret != 0)
  3616. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3617. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3618. ret = wc_Sha512Copy(&i_sha, &i_shaCopy);
  3619. if (ret != 0)
  3620. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3621. #endif
  3622. ret = wc_Sha512Final(&sha, hash);
  3623. if (ret != 0)
  3624. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3625. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3626. ret = wc_Sha512Final(&i_sha, i_hash);
  3627. if (ret != 0)
  3628. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3629. #endif
  3630. wc_Sha512Free(&shaCopy);
  3631. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3632. wc_Sha512Free(&i_shaCopy);
  3633. #endif
  3634. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  3635. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3636. if (XMEMCMP(hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0)
  3637. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3638. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3639. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3640. WC_SHA512_DIGEST_SIZE) != 0) {
  3641. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3642. }
  3643. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3644. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3645. }
  3646. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0) {
  3647. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3648. }
  3649. if (XMEMCMP(i_hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3650. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3651. }
  3652. #endif
  3653. }
  3654. #ifndef NO_LARGE_HASH_TEST
  3655. /* BEGIN LARGE HASH TEST */ {
  3656. #ifdef HASH_SIZE_LIMIT
  3657. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3658. "\x30\x9B\x96\xA6\xE9\x43\x78\x30\xA3\x71\x51\x61\xC1\xEB\xE1\xBE"
  3659. "\xC8\xA5\xF9\x13\x5A\xD6\x6D\x9E\x46\x31\x31\x67\x8D\xE2\xC0\x0B"
  3660. "\x2A\x1A\x03\xE1\xF3\x48\xA7\x33\xBD\x49\xF8\xFF\xF1\xC2\xC2\x95"
  3661. "\xCB\xF0\xAF\x87\x61\x85\x58\x63\x6A\xCA\x70\x9C\x8B\x83\x3F\x5D";
  3662. #else
  3663. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3664. "\x5a\x1f\x73\x90\xbd\x8c\xe4\x63\x54\xce\xa0\x9b\xef\x32\x78\x2d"
  3665. "\x2e\xe7\x0d\x5e\x2f\x9d\x15\x1b\xdd\x2d\xde\x65\x0c\x7b\xfa\x83"
  3666. "\x5e\x80\x02\x13\x84\xb8\x3f\xff\x71\x62\xb5\x09\x89\x63\xe1\xdc"
  3667. "\xa5\xdc\xfc\xfa\x9d\x1a\x4d\xc0\xfa\x3a\x14\xf6\x01\x51\x90\xa4";
  3668. #endif
  3669. #ifdef WOLFSSL_SMALL_STACK
  3670. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3671. DYNAMIC_TYPE_TMP_BUFFER);
  3672. if (large_input == NULL) {
  3673. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3674. }
  3675. #endif
  3676. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3677. large_input[i] = (byte)(i & 0xFF);
  3678. }
  3679. #ifdef HASH_SIZE_LIMIT
  3680. times = 20;
  3681. #else
  3682. times = 100;
  3683. #endif
  3684. for (i = 0; i < times; ++i) {
  3685. ret = wc_Sha512Update(&sha, (byte*)large_input,
  3686. LARGE_HASH_TEST_INPUT_SZ);
  3687. if (ret != 0)
  3688. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3689. }
  3690. ret = wc_Sha512Final(&sha, hash);
  3691. if (ret != 0)
  3692. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3693. if (XMEMCMP(hash, large_digest, WC_SHA512_DIGEST_SIZE) != 0)
  3694. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3695. #ifndef NO_UNALIGNED_MEMORY_TEST
  3696. /* Unaligned memory access test */
  3697. for (i = 1; i < 16; i++) {
  3698. ret = wc_Sha512Update(&sha, (byte*)large_input + i,
  3699. LARGE_HASH_TEST_INPUT_SZ - (word32)i);
  3700. if (ret != 0)
  3701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3702. ret = wc_Sha512Final(&sha, hash);
  3703. }
  3704. #endif
  3705. } /* END LARGE HASH TEST */
  3706. #undef LARGE_HASH_TEST_INPUT_SZ
  3707. #endif /* NO_LARGE_HASH_TEST */
  3708. exit:
  3709. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3710. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3711. #endif
  3712. wc_Sha512Free(&sha);
  3713. wc_Sha512Free(&shaCopy);
  3714. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3715. wc_Sha512Free(&i_sha);
  3716. wc_Sha512Free(&i_shaCopy);
  3717. #endif
  3718. return ret;
  3719. }
  3720. #if !defined(WOLFSSL_NOSHA512_224) && \
  3721. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3722. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void)
  3723. {
  3724. /*
  3725. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3726. **
  3727. ** NIST SHA512/224 Document Example:
  3728. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_224.pdf
  3729. */
  3730. wc_Sha512 sha, shaCopy;
  3731. byte hash[WC_SHA512_224_DIGEST_SIZE];
  3732. byte hashcopy[WC_SHA512_224_DIGEST_SIZE];
  3733. wc_test_ret_t ret = 0;
  3734. testVector a, b, c;
  3735. testVector test_sha[3];
  3736. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3737. WOLFSSL_ENTER("sha512_224_test");
  3738. a.input = "";
  3739. a.output = "\x6e\xd0\xdd\x02"
  3740. "\x80\x6f\xa8\x9e" "\x25\xde\x06\x0c"
  3741. "\x19\xd3\xac\x86" "\xca\xbb\x87\xd6"
  3742. "\xa0\xdd\xd0\x5c" "\x33\x3b\x84\xf4";
  3743. a.inLen = XSTRLEN(a.input);
  3744. a.outLen = WC_SHA512_224_DIGEST_SIZE;
  3745. /*
  3746. ** See page 1 in above document for the SHA512/224 "abc" test:
  3747. */
  3748. b.input = "abc";
  3749. /*
  3750. ** See page 1 in above document for the SHA512/224 "abc" test digest:
  3751. */
  3752. b.output = "\x46\x34\x27\x0f"
  3753. "\x70\x7b\x6a\x54" "\xda\xae\x75\x30"
  3754. "\x46\x08\x42\xe2" "\x0e\x37\xed\x26"
  3755. "\x5c\xee\xe9\xa4" "\x3e\x89\x24\xaa";
  3756. b.inLen = XSTRLEN(b.input);
  3757. b.outLen = WC_SHA512_224_DIGEST_SIZE;
  3758. /*
  3759. ** See page 4 in above for the 2-block test:
  3760. */
  3761. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3762. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3763. /*
  3764. ** see page 9 in above document for the 2-block test message digest:
  3765. */
  3766. c.output = "\x23\xfe\xc5\xbb"
  3767. "\x94\xd6\x0b\x23" "\x30\x81\x92\x64"
  3768. "\x0b\x0c\x45\x33" "\x35\xd6\x64\x73"
  3769. "\x4f\xe4\x0e\x72" "\x68\x67\x4a\xf9";
  3770. c.inLen = XSTRLEN(c.input);
  3771. c.outLen = WC_SHA512_224_DIGEST_SIZE;
  3772. test_sha[0] = a;
  3773. test_sha[1] = b;
  3774. test_sha[2] = c;
  3775. ret = wc_InitSha512_224_ex(&sha, HEAP_HINT, devId);
  3776. if (ret != 0)
  3777. return WC_TEST_RET_ENC_EC(ret);
  3778. ret = wc_InitSha512_224_ex(&shaCopy, HEAP_HINT, devId);
  3779. if (ret != 0) {
  3780. wc_Sha512_224Free(&sha);
  3781. return WC_TEST_RET_ENC_EC(ret);
  3782. }
  3783. for (i = 0; i < times; ++i) {
  3784. ret = wc_Sha512_224Update(&sha, (byte*)test_sha[i].input,
  3785. (word32)test_sha[i].inLen);
  3786. if (ret != 0)
  3787. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3788. ret = wc_Sha512_224GetHash(&sha, hashcopy);
  3789. if (ret != 0)
  3790. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3791. ret = wc_Sha512_224Copy(&sha, &shaCopy);
  3792. if (ret != 0)
  3793. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3794. ret = wc_Sha512_224Final(&sha, hash);
  3795. if (ret != 0)
  3796. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3797. wc_Sha512_224Free(&shaCopy);
  3798. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_224_DIGEST_SIZE) != 0)
  3799. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3800. if (XMEMCMP(hash, hashcopy, WC_SHA512_224_DIGEST_SIZE) != 0)
  3801. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3802. }
  3803. #ifndef NO_LARGE_HASH_TEST
  3804. /* BEGIN LARGE HASH TEST */ {
  3805. byte large_input[1024];
  3806. #ifdef HASH_SIZE_LIMIT
  3807. const char* large_digest =
  3808. "\x98\x68\xc3\xd9\xb9\xef\x17\x53"
  3809. "\x43\x66\x0e\x60\xdf\x29\xf8\xef"
  3810. "\x96\xe3\x93\x34\x8c\x6f\xc0\xeb"
  3811. "\x14\x6c\xcf\x6a";
  3812. #else
  3813. const char* large_digest =
  3814. "\x26\x5f\x98\xd1\x76\x49\x71\x4e"
  3815. "\x82\xb7\x9d\x52\x32\x67\x9d\x56"
  3816. "\x91\xf5\x88\xc3\x05\xbb\x3f\x90"
  3817. "\xe2\x4e\x85\x05";
  3818. #endif
  3819. for (i = 0; i < (int)sizeof(large_input); i++) {
  3820. large_input[i] = (byte)(i & 0xFF);
  3821. }
  3822. #ifdef HASH_SIZE_LIMIT
  3823. times = 20;
  3824. #else
  3825. times = 100;
  3826. #endif
  3827. for (i = 0; i < times; ++i) {
  3828. ret = wc_Sha512_224Update(&sha, (byte*)large_input,
  3829. (word32)sizeof(large_input));
  3830. if (ret != 0)
  3831. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3832. }
  3833. ret = wc_Sha512_224Final(&sha, hash);
  3834. if (ret != 0)
  3835. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3836. if (XMEMCMP(hash, large_digest, WC_SHA512_224_DIGEST_SIZE) != 0)
  3837. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3838. #ifndef NO_UNALIGNED_MEMORY_TEST
  3839. /* Unaligned memory access test */
  3840. for (i = 1; i < 16; i++) {
  3841. ret = wc_Sha512_224Update(&sha, (byte*)large_input + i,
  3842. (word32)sizeof(large_input) - (word32)i);
  3843. if (ret != 0)
  3844. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3845. ret = wc_Sha512_224Final(&sha, hash);
  3846. }
  3847. #endif
  3848. } /* END LARGE HASH TEST */
  3849. #endif /* NO_LARGE_HASH_TEST */
  3850. exit:
  3851. wc_Sha512_224Free(&sha);
  3852. wc_Sha512_224Free(&shaCopy);
  3853. return ret;
  3854. } /* sha512_224_test */
  3855. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  3856. #if !defined(WOLFSSL_NOSHA512_256) && \
  3857. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3858. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void)
  3859. {
  3860. /*
  3861. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3862. ** NIST SHA512/256 Document Example:
  3863. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_256.pdf
  3864. */
  3865. wc_Sha512 sha, shaCopy;
  3866. byte hash[WC_SHA512_256_DIGEST_SIZE];
  3867. byte hashcopy[WC_SHA512_256_DIGEST_SIZE];
  3868. wc_test_ret_t ret = 0;
  3869. testVector a, b, c;
  3870. testVector test_sha[3];
  3871. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3872. WOLFSSL_ENTER("sha512_256_test");
  3873. a.input = "";
  3874. a.output = "\xc6\x72\xb8\xd1" "\xef\x56\xed\x28"
  3875. "\xab\x87\xc3\x62" "\x2c\x51\x14\x06"
  3876. "\x9b\xdd\x3a\xd7" "\xb8\xf9\x73\x74"
  3877. "\x98\xd0\xc0\x1e" "\xce\xf0\x96\x7a";
  3878. a.inLen = XSTRLEN(a.input);
  3879. a.outLen = WC_SHA512_256_DIGEST_SIZE;
  3880. /*
  3881. ** See page 1 of above document for "abc" example:
  3882. */
  3883. b.input = "abc";
  3884. /*
  3885. ** See page 4 of above document for "abc" example digest:
  3886. */
  3887. b.output = "\x53\x04\x8e\x26" "\x81\x94\x1e\xf9"
  3888. "\x9b\x2e\x29\xb7" "\x6b\x4c\x7d\xab"
  3889. "\xe4\xc2\xd0\xc6" "\x34\xfc\x6d\x46"
  3890. "\xe0\xe2\xf1\x31" "\x07\xe7\xaf\x23";
  3891. b.inLen = XSTRLEN(b.input);
  3892. b.outLen = WC_SHA512_256_DIGEST_SIZE;
  3893. /*
  3894. ** See page 4 of above document for Two Block Message Sample:
  3895. */
  3896. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3897. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3898. /*
  3899. ** See page 10 of above document for Two Block Message Sample digest:
  3900. */
  3901. c.output = "\x39\x28\xe1\x84" "\xfb\x86\x90\xf8"
  3902. "\x40\xda\x39\x88" "\x12\x1d\x31\xbe"
  3903. "\x65\xcb\x9d\x3e" "\xf8\x3e\xe6\x14"
  3904. "\x6f\xea\xc8\x61" "\xe1\x9b\x56\x3a";
  3905. c.inLen = XSTRLEN(c.input);
  3906. c.outLen = WC_SHA512_256_DIGEST_SIZE;
  3907. test_sha[0] = a;
  3908. test_sha[1] = b;
  3909. test_sha[2] = c;
  3910. ret = wc_InitSha512_256_ex(&sha, HEAP_HINT, devId);
  3911. if (ret != 0)
  3912. return WC_TEST_RET_ENC_EC(ret);
  3913. ret = wc_InitSha512_256_ex(&shaCopy, HEAP_HINT, devId);
  3914. if (ret != 0) {
  3915. wc_Sha512_256Free(&sha);
  3916. return WC_TEST_RET_ENC_EC(ret);
  3917. }
  3918. for (i = 0; i < times; ++i) {
  3919. ret = wc_Sha512_256Update(&sha, (byte*)test_sha[i].input,
  3920. (word32)test_sha[i].inLen);
  3921. if (ret != 0)
  3922. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3923. ret = wc_Sha512_256GetHash(&sha, hashcopy);
  3924. if (ret != 0)
  3925. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3926. ret = wc_Sha512_256Copy(&sha, &shaCopy);
  3927. if (ret != 0)
  3928. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3929. ret = wc_Sha512_256Final(&sha, hash);
  3930. if (ret != 0)
  3931. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3932. wc_Sha512_256Free(&shaCopy);
  3933. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_256_DIGEST_SIZE) != 0)
  3934. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3935. if (XMEMCMP(hash, hashcopy, WC_SHA512_256_DIGEST_SIZE) != 0)
  3936. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3937. }
  3938. #ifndef NO_LARGE_HASH_TEST
  3939. /* BEGIN LARGE HASH TEST */ {
  3940. byte large_input[1024];
  3941. #ifdef HASH_SIZE_LIMIT
  3942. const char* large_digest =
  3943. "\x49\xcc\xbc\x7a\x93\x0b\x02\xb8"
  3944. "\xad\x9a\x46\x51\x00\x1f\x13\x80"
  3945. "\x35\x84\x36\xf1\xf2\x3c\xeb\xd8"
  3946. "\x41\xd4\x06\x8b\x1d\x19\xad\x72";
  3947. #else
  3948. const char* large_digest =
  3949. "\x7a\xe3\x84\x05\xcb\x06\x22\x08"
  3950. "\x7e\x2c\x65\x89\x1f\x26\x45\xfd"
  3951. "\xad\xbc\x2e\x29\x83\x12\x84\x4b"
  3952. "\xf2\xa0\xde\xbe\x06\x11\xd7\x44";
  3953. #endif
  3954. for (i = 0; i < (int)sizeof(large_input); i++) {
  3955. large_input[i] = (byte)(i & 0xFF);
  3956. }
  3957. #ifdef HASH_SIZE_LIMIT
  3958. times = 20;
  3959. #else
  3960. times = 100;
  3961. #endif
  3962. for (i = 0; i < times; ++i) {
  3963. ret = wc_Sha512_256Update(&sha, (byte*)large_input,
  3964. (word32)sizeof(large_input));
  3965. if (ret != 0)
  3966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3967. }
  3968. ret = wc_Sha512_256Final(&sha, hash);
  3969. if (ret != 0)
  3970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3971. if (XMEMCMP(hash, large_digest, WC_SHA512_256_DIGEST_SIZE) != 0)
  3972. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3973. #ifndef NO_UNALIGNED_MEMORY_TEST
  3974. /* Unaligned memory access test */
  3975. for (i = 1; i < 16; i++) {
  3976. ret = wc_Sha512_256Update(&sha, (byte*)large_input + i,
  3977. (word32)sizeof(large_input) - (word32)i);
  3978. if (ret != 0)
  3979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3980. ret = wc_Sha512_256Final(&sha, hash);
  3981. }
  3982. #endif
  3983. } /* END LARGE HASH TEST */
  3984. #endif /* NO_LARGE_HASH_TEST */
  3985. exit:
  3986. wc_Sha512_256Free(&sha);
  3987. wc_Sha512_256Free(&shaCopy);
  3988. return ret;
  3989. } /* sha512_256_test */
  3990. #endif /* !defined(WOLFSSL_NOSHA512_256) && !FIPS ... */
  3991. #endif /* WOLFSSL_SHA512 */
  3992. #ifdef WOLFSSL_SHA384
  3993. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void)
  3994. {
  3995. wc_Sha384 sha, shaCopy;
  3996. byte hash[WC_SHA384_DIGEST_SIZE];
  3997. byte hashcopy[WC_SHA384_DIGEST_SIZE];
  3998. wc_test_ret_t ret = 0;
  3999. testVector a, b, c;
  4000. testVector test_sha[3];
  4001. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4002. WOLFSSL_ENTER("sha384_test");
  4003. a.input = "";
  4004. a.output = "\x38\xb0\x60\xa7\x51\xac\x96\x38\x4c\xd9\x32\x7e\xb1\xb1\xe3"
  4005. "\x6a\x21\xfd\xb7\x11\x14\xbe\x07\x43\x4c\x0c\xc7\xbf\x63\xf6"
  4006. "\xe1\xda\x27\x4e\xde\xbf\xe7\x6f\x65\xfb\xd5\x1a\xd2\xf1\x48"
  4007. "\x98\xb9\x5b";
  4008. a.inLen = XSTRLEN(a.input);
  4009. a.outLen = WC_SHA384_DIGEST_SIZE;
  4010. b.input = "abc";
  4011. b.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  4012. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  4013. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  4014. "\xc8\x25\xa7";
  4015. b.inLen = XSTRLEN(b.input);
  4016. b.outLen = WC_SHA384_DIGEST_SIZE;
  4017. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  4018. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  4019. c.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  4020. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  4021. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  4022. "\x74\x60\x39";
  4023. c.inLen = XSTRLEN(c.input);
  4024. c.outLen = WC_SHA384_DIGEST_SIZE;
  4025. test_sha[0] = a;
  4026. test_sha[1] = b;
  4027. test_sha[2] = c;
  4028. ret = wc_InitSha384_ex(&sha, HEAP_HINT, devId);
  4029. if (ret != 0)
  4030. return WC_TEST_RET_ENC_EC(ret);
  4031. ret = wc_InitSha384_ex(&shaCopy, HEAP_HINT, devId);
  4032. if (ret != 0) {
  4033. wc_Sha384Free(&sha);
  4034. return WC_TEST_RET_ENC_EC(ret);
  4035. }
  4036. for (i = 0; i < times; ++i) {
  4037. ret = wc_Sha384Update(&sha, (byte*)test_sha[i].input,
  4038. (word32)test_sha[i].inLen);
  4039. if (ret != 0)
  4040. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4041. ret = wc_Sha384GetHash(&sha, hashcopy);
  4042. if (ret != 0)
  4043. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4044. ret = wc_Sha384Copy(&sha, &shaCopy);
  4045. if (ret != 0)
  4046. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4047. ret = wc_Sha384Final(&sha, hash);
  4048. if (ret != 0)
  4049. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4050. wc_Sha384Free(&shaCopy);
  4051. if (XMEMCMP(hash, test_sha[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  4052. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4053. if (XMEMCMP(hash, hashcopy, WC_SHA384_DIGEST_SIZE) != 0)
  4054. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4055. }
  4056. #ifndef NO_LARGE_HASH_TEST
  4057. /* BEGIN LARGE HASH TEST */ {
  4058. byte large_input[1024];
  4059. #ifdef HASH_SIZE_LIMIT
  4060. const char* large_digest =
  4061. "\xB5\xAD\x66\x6F\xD9\x58\x5E\x68\xDD\x5E\x30\xD3\x95\x72\x33\xA4"
  4062. "\xE9\x4B\x99\x3A\xEF\xF8\xE1\xBF\x1F\x05\x32\xAA\x16\x00\x82\xEC"
  4063. "\x15\xDA\xF2\x75\xEE\xE9\x06\xAF\x52\x8A\x5C\xEF\x72\x81\x80\xD6";
  4064. #else
  4065. const char* large_digest =
  4066. "\x37\x01\xdb\xff\x1e\x40\x4f\xe1\xe2\xea\x0b\x40\xbb\x3b\x39\x9a"
  4067. "\xcc\xe8\x44\x8e\x7e\xe5\x64\xb5\x6b\x7f\x56\x64\xa7\x2b\x84\xe3"
  4068. "\xc5\xd7\x79\x03\x25\x90\xf7\xa4\x58\xcb\x97\xa8\x8b\xb1\xa4\x81";
  4069. #endif
  4070. for (i = 0; i < (int)sizeof(large_input); i++) {
  4071. large_input[i] = (byte)(i & 0xFF);
  4072. }
  4073. #ifdef HASH_SIZE_LIMIT
  4074. times = 20;
  4075. #else
  4076. times = 100;
  4077. #endif
  4078. for (i = 0; i < times; ++i) {
  4079. ret = wc_Sha384Update(&sha, (byte*)large_input,
  4080. (word32)sizeof(large_input));
  4081. if (ret != 0)
  4082. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4083. }
  4084. ret = wc_Sha384Final(&sha, hash);
  4085. if (ret != 0)
  4086. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4087. if (XMEMCMP(hash, large_digest, WC_SHA384_DIGEST_SIZE) != 0)
  4088. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4089. } /* END LARGE HASH TEST */
  4090. #endif /* NO_LARGE_HASH_TEST */
  4091. exit:
  4092. wc_Sha384Free(&sha);
  4093. wc_Sha384Free(&shaCopy);
  4094. return ret;
  4095. }
  4096. #endif /* WOLFSSL_SHA384 */
  4097. #ifdef WOLFSSL_SHA3
  4098. #ifndef WOLFSSL_NOSHA3_224
  4099. static wc_test_ret_t sha3_224_test(void)
  4100. {
  4101. wc_Sha3 sha;
  4102. byte hash[WC_SHA3_224_DIGEST_SIZE];
  4103. byte hashcopy[WC_SHA3_224_DIGEST_SIZE];
  4104. testVector a, b, c;
  4105. testVector test_sha[3];
  4106. wc_test_ret_t ret = 0;
  4107. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4108. a.input = "";
  4109. a.output = "\x6b\x4e\x03\x42\x36\x67\xdb\xb7\x3b\x6e\x15\x45\x4f\x0e\xb1"
  4110. "\xab\xd4\x59\x7f\x9a\x1b\x07\x8e\x3f\x5b\x5a\x6b\xc7";
  4111. a.inLen = XSTRLEN(a.input);
  4112. a.outLen = WC_SHA3_224_DIGEST_SIZE;
  4113. b.input = "abc";
  4114. b.output = "\xe6\x42\x82\x4c\x3f\x8c\xf2\x4a\xd0\x92\x34\xee\x7d\x3c\x76"
  4115. "\x6f\xc9\xa3\xa5\x16\x8d\x0c\x94\xad\x73\xb4\x6f\xdf";
  4116. b.inLen = XSTRLEN(b.input);
  4117. b.outLen = WC_SHA3_224_DIGEST_SIZE;
  4118. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4119. c.output = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55\x74\x49\x44\x79"
  4120. "\xba\x5c\x7e\x7a\xb7\x6e\xf2\x64\xea\xd0\xfc\xce\x33";
  4121. c.inLen = XSTRLEN(c.input);
  4122. c.outLen = WC_SHA3_224_DIGEST_SIZE;
  4123. test_sha[0] = a;
  4124. test_sha[1] = b;
  4125. test_sha[2] = c;
  4126. ret = wc_InitSha3_224(&sha, HEAP_HINT, devId);
  4127. if (ret != 0)
  4128. return WC_TEST_RET_ENC_EC(ret);
  4129. for (i = 0; i < times; ++i) {
  4130. ret = wc_Sha3_224_Update(&sha, (byte*)test_sha[i].input,
  4131. (word32)test_sha[i].inLen);
  4132. if (ret != 0)
  4133. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4134. ret = wc_Sha3_224_GetHash(&sha, hashcopy);
  4135. if (ret != 0)
  4136. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4137. ret = wc_Sha3_224_Final(&sha, hash);
  4138. if (ret != 0)
  4139. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4140. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_224_DIGEST_SIZE) != 0)
  4141. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4142. if (XMEMCMP(hash, hashcopy, WC_SHA3_224_DIGEST_SIZE) != 0)
  4143. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4144. }
  4145. #ifndef NO_LARGE_HASH_TEST
  4146. /* BEGIN LARGE HASH TEST */ {
  4147. byte large_input[1024];
  4148. const char* large_digest =
  4149. "\x13\xe5\xd3\x98\x7b\x94\xda\x41\x12\xc7\x1e\x92\x3a\x19"
  4150. "\x21\x20\x86\x6f\x24\xbf\x0a\x31\xbc\xfd\xd6\x70\x36\xf3";
  4151. for (i = 0; i < (int)sizeof(large_input); i++) {
  4152. large_input[i] = (byte)(i & 0xFF);
  4153. }
  4154. times = 100;
  4155. for (i = 0; i < times; ++i) {
  4156. ret = wc_Sha3_224_Update(&sha, (byte*)large_input,
  4157. (word32)sizeof(large_input));
  4158. if (ret != 0)
  4159. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4160. }
  4161. ret = wc_Sha3_224_Final(&sha, hash);
  4162. if (ret != 0)
  4163. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4164. if (XMEMCMP(hash, large_digest, WC_SHA3_224_DIGEST_SIZE) != 0)
  4165. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4166. } /* END LARGE HASH TEST */
  4167. #endif /* NO_LARGE_HASH_TEST */
  4168. exit:
  4169. wc_Sha3_224_Free(&sha);
  4170. return ret;
  4171. }
  4172. #endif /* WOLFSSL_NOSHA3_224 */
  4173. #ifndef WOLFSSL_NOSHA3_256
  4174. static wc_test_ret_t sha3_256_test(void)
  4175. {
  4176. wc_Sha3 sha;
  4177. byte hash[WC_SHA3_256_DIGEST_SIZE];
  4178. byte hashcopy[WC_SHA3_256_DIGEST_SIZE];
  4179. testVector a, b, c;
  4180. testVector test_sha[3];
  4181. wc_test_ret_t ret = 0;
  4182. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4183. byte large_input[1024];
  4184. const char* large_digest =
  4185. "\xdc\x90\xc0\xb1\x25\xdb\x2c\x34\x81\xa3\xff\xbc\x1e\x2e\x87\xeb"
  4186. "\x6d\x70\x85\x61\xe0\xe9\x63\x61\xff\xe5\x84\x4b\x1f\x68\x05\x15";
  4187. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4188. /* test vector with hash of empty string */
  4189. const char* Keccak256EmptyOut =
  4190. "\xc5\xd2\x46\x01\x86\xf7\x23\x3c\x92\x7e\x7d\xb2\xdc\xc7\x03\xc0"
  4191. "\xe5\x00\xb6\x53\xca\x82\x27\x3b\x7b\xfa\xd8\x04\x5d\x85\xa4\x70";
  4192. #endif
  4193. /*
  4194. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-256_Msg0.pdf
  4195. */
  4196. a.input = "";
  4197. a.output = "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66\x51\xc1\x47\x56\xa0\x61\xd6"
  4198. "\x62\xf5\x80\xff\x4d\xe4\x3b\x49\xfa\x82\xd8\x0a\x4b\x80\xf8"
  4199. "\x43\x4a";
  4200. a.inLen = XSTRLEN(a.input);
  4201. a.outLen = WC_SHA3_256_DIGEST_SIZE;
  4202. b.input = "abc";
  4203. b.output = "\x3a\x98\x5d\xa7\x4f\xe2\x25\xb2\x04\x5c\x17\x2d\x6b\xd3\x90"
  4204. "\xbd\x85\x5f\x08\x6e\x3e\x9d\x52\x5b\x46\xbf\xe2\x45\x11\x43"
  4205. "\x15\x32";
  4206. b.inLen = XSTRLEN(b.input);
  4207. b.outLen = WC_SHA3_256_DIGEST_SIZE;
  4208. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4209. c.output = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8\x23\x5e"
  4210. "\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32\xdd\x97\x49\x6d"
  4211. "\x33\x76";
  4212. c.inLen = XSTRLEN(c.input);
  4213. c.outLen = WC_SHA3_256_DIGEST_SIZE;
  4214. test_sha[0] = a;
  4215. test_sha[1] = b;
  4216. test_sha[2] = c;
  4217. ret = wc_InitSha3_256(&sha, HEAP_HINT, devId);
  4218. if (ret != 0)
  4219. return WC_TEST_RET_ENC_EC(ret);
  4220. for (i = 0; i < times; ++i) {
  4221. ret = wc_Sha3_256_Update(&sha, (byte*)test_sha[i].input,
  4222. (word32)test_sha[i].inLen);
  4223. if (ret != 0)
  4224. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4225. ret = wc_Sha3_256_GetHash(&sha, hashcopy);
  4226. if (ret != 0)
  4227. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4228. ret = wc_Sha3_256_Final(&sha, hash);
  4229. if (ret != 0)
  4230. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4231. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_256_DIGEST_SIZE) != 0)
  4232. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4233. if (XMEMCMP(hash, hashcopy, WC_SHA3_256_DIGEST_SIZE) != 0)
  4234. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4235. }
  4236. #ifndef NO_LARGE_HASH_TEST
  4237. /* BEGIN LARGE HASH TEST */ {
  4238. for (i = 0; i < (int)sizeof(large_input); i++) {
  4239. large_input[i] = (byte)(i & 0xFF);
  4240. }
  4241. times = 100;
  4242. for (i = 0; i < times; ++i) {
  4243. ret = wc_Sha3_256_Update(&sha, (byte*)large_input,
  4244. (word32)sizeof(large_input));
  4245. if (ret != 0)
  4246. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4247. }
  4248. ret = wc_Sha3_256_Final(&sha, hash);
  4249. if (ret != 0)
  4250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4251. if (XMEMCMP(hash, large_digest, WC_SHA3_256_DIGEST_SIZE) != 0)
  4252. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4253. } /* END LARGE HASH TEST */
  4254. #endif /* NO_LARGE_HASH_TEST */
  4255. /* this is a software only variant of SHA3 not supported by external hardware devices */
  4256. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4257. /* Test for Keccak256 */
  4258. ret = wc_Sha3_SetFlags(&sha, WC_HASH_SHA3_KECCAK256);
  4259. if (ret != 0) {
  4260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4261. }
  4262. ret = wc_Sha3_256_Update(&sha, (byte*)"", 0);
  4263. if (ret != 0) {
  4264. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4265. }
  4266. ret = wc_Sha3_256_Final(&sha, hash);
  4267. if (ret != 0) {
  4268. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4269. }
  4270. if (XMEMCMP(hash, Keccak256EmptyOut, WC_SHA3_256_DIGEST_SIZE) != 0) {
  4271. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4272. }
  4273. #endif /* WOLFSSL_HASH_FLAGS && !WOLFSSL_ASYNC_CRYPT */
  4274. exit:
  4275. wc_Sha3_256_Free(&sha);
  4276. return ret;
  4277. }
  4278. #endif /* WOLFSSL_NOSHA3_256 */
  4279. #ifndef WOLFSSL_NOSHA3_384
  4280. static wc_test_ret_t sha3_384_test(void)
  4281. {
  4282. wc_Sha3 sha;
  4283. byte hash[WC_SHA3_384_DIGEST_SIZE];
  4284. byte buf[64];
  4285. #ifndef NO_INTM_HASH_TEST
  4286. byte hashcopy[WC_SHA3_384_DIGEST_SIZE];
  4287. #endif
  4288. testVector a, b, c;
  4289. testVector test_sha[3];
  4290. wc_test_ret_t ret;
  4291. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4292. /*
  4293. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-384_Msg0.pdf
  4294. */
  4295. a.input = "";
  4296. a.output = "\x0c\x63\xa7\x5b\x84\x5e\x4f\x7d\x01\x10\x7d\x85\x2e\x4c\x24"
  4297. "\x85\xc5\x1a\x50\xaa\xaa\x94\xfc\x61\x99\x5e\x71\xbb\xee\x98"
  4298. "\x3a\x2a\xc3\x71\x38\x31\x26\x4a\xdb\x47\xfb\x6b\xd1\xe0\x58"
  4299. "\xd5\xf0\x04";
  4300. a.inLen = XSTRLEN(a.input);
  4301. a.outLen = WC_SHA3_384_DIGEST_SIZE;
  4302. #if defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4303. /* NIST test vector with a length that is a multiple of 4 */
  4304. b.input = "\x7d\x80\xb1\x60\xc4\xb5\x36\xa3\xbe\xb7\x99\x80\x59\x93\x44"
  4305. "\x04\x7c\x5f\x82\xa1\xdf\xc3\xee\xd4";
  4306. b.output = "\x04\x1c\xc5\x86\x1b\xa3\x34\x56\x3c\x61\xd4\xef\x97\x10\xd4"
  4307. "\x89\x6c\x31\x1c\x92\xed\xbe\x0d\x7c\xd5\x3e\x80\x3b\xf2\xf4"
  4308. "\xeb\x60\x57\x23\x55\x70\x77\x0c\xe8\x7c\x55\x20\xd7\xec\x14"
  4309. "\x19\x87\x22";
  4310. b.inLen = XSTRLEN(b.input);
  4311. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4312. #else
  4313. b.input = "abc";
  4314. b.output = "\xec\x01\x49\x82\x88\x51\x6f\xc9\x26\x45\x9f\x58\xe2\xc6\xad"
  4315. "\x8d\xf9\xb4\x73\xcb\x0f\xc0\x8c\x25\x96\xda\x7c\xf0\xe4\x9b"
  4316. "\xe4\xb2\x98\xd8\x8c\xea\x92\x7a\xc7\xf5\x39\xf1\xed\xf2\x28"
  4317. "\x37\x6d\x25";
  4318. b.inLen = XSTRLEN(b.input);
  4319. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4320. #endif
  4321. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4322. c.output = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7\x8a\x49"
  4323. "\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd\xbc\x32\xb9\xd4"
  4324. "\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe\xa1\x9e\xef\x51\xac\xd0"
  4325. "\x65\x7c\x22";
  4326. c.inLen = XSTRLEN(c.input);
  4327. c.outLen = WC_SHA3_384_DIGEST_SIZE;
  4328. #if defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4329. test_sha[0] = b; /* hardware acc. pre-Versal can not handle "" string */
  4330. #else
  4331. test_sha[0] = a;
  4332. #endif
  4333. test_sha[1] = b;
  4334. test_sha[2] = c;
  4335. ret = wc_InitSha3_384(&sha, HEAP_HINT, devId);
  4336. if (ret != 0)
  4337. return WC_TEST_RET_ENC_EC(ret);
  4338. for (i = 0; i < times; ++i) {
  4339. XMEMCPY(buf, test_sha[i].input, test_sha[i].inLen);
  4340. ret = wc_Sha3_384_Update(&sha, buf,
  4341. (word32)test_sha[i].inLen);
  4342. if (ret != 0)
  4343. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4344. #ifndef NO_INTM_HASH_TEST
  4345. ret = wc_Sha3_384_GetHash(&sha, hashcopy);
  4346. if (ret != 0)
  4347. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4348. #endif
  4349. ret = wc_Sha3_384_Final(&sha, hash);
  4350. if (ret != 0)
  4351. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4352. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_384_DIGEST_SIZE) != 0)
  4353. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4354. #ifndef NO_INTM_HASH_TEST
  4355. if (XMEMCMP(hash, hashcopy, WC_SHA3_384_DIGEST_SIZE) != 0)
  4356. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4357. #endif
  4358. }
  4359. #ifndef NO_LARGE_HASH_TEST
  4360. /* BEGIN LARGE HASH TEST */ {
  4361. byte large_input[1024];
  4362. const char* large_digest =
  4363. "\x30\x44\xec\x17\xef\x47\x9f\x55\x36\x11\xd6\x3f\x8a\x31\x5a\x71"
  4364. "\x8a\x71\xa7\x1d\x8e\x84\xe8\x6c\x24\x02\x2f\x7a\x08\x4e\xea\xd7"
  4365. "\x42\x36\x5d\xa8\xc2\xb7\x42\xad\xec\x19\xfb\xca\xc6\x64\xb3\xa4";
  4366. for (i = 0; i < (int)sizeof(large_input); i++) {
  4367. large_input[i] = (byte)(i & 0xFF);
  4368. }
  4369. times = 100;
  4370. for (i = 0; i < times; ++i) {
  4371. ret = wc_Sha3_384_Update(&sha, (byte*)large_input,
  4372. (word32)sizeof(large_input));
  4373. if (ret != 0)
  4374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4375. }
  4376. ret = wc_Sha3_384_Final(&sha, hash);
  4377. if (ret != 0)
  4378. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4379. if (XMEMCMP(hash, large_digest, WC_SHA3_384_DIGEST_SIZE) != 0)
  4380. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4381. } /* END LARGE HASH TEST */
  4382. #endif /* NO_LARGE_HASH_TEST */
  4383. exit:
  4384. wc_Sha3_384_Free(&sha);
  4385. return ret;
  4386. }
  4387. #endif /* WOLFSSL_NOSHA3_384 */
  4388. #ifndef WOLFSSL_NOSHA3_512
  4389. static wc_test_ret_t sha3_512_test(void)
  4390. {
  4391. wc_Sha3 sha;
  4392. byte hash[WC_SHA3_512_DIGEST_SIZE];
  4393. byte hashcopy[WC_SHA3_512_DIGEST_SIZE];
  4394. testVector a, b, c;
  4395. testVector test_sha[3];
  4396. wc_test_ret_t ret;
  4397. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4398. /*
  4399. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-512_Msg0.pdf
  4400. */
  4401. a.input = "";
  4402. a.output = "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5\xc8\xb5\x67\xdc\x18\x5a\x75"
  4403. "\x6e\x97\xc9\x82\x16\x4f\xe2\x58\x59\xe0\xd1\xdc\xc1\x47\x5c"
  4404. "\x80\xa6\x15\xb2\x12\x3a\xf1\xf5\xf9\x4c\x11\xe3\xe9\x40\x2c"
  4405. "\x3a\xc5\x58\xf5\x00\x19\x9d\x95\xb6\xd3\xe3\x01\x75\x85\x86"
  4406. "\x28\x1d\xcd\x26";
  4407. a.inLen = XSTRLEN(a.input);
  4408. a.outLen = WC_SHA3_512_DIGEST_SIZE;
  4409. b.input = "abc";
  4410. b.output = "\xb7\x51\x85\x0b\x1a\x57\x16\x8a\x56\x93\xcd\x92\x4b\x6b\x09"
  4411. "\x6e\x08\xf6\x21\x82\x74\x44\xf7\x0d\x88\x4f\x5d\x02\x40\xd2"
  4412. "\x71\x2e\x10\xe1\x16\xe9\x19\x2a\xf3\xc9\x1a\x7e\xc5\x76\x47"
  4413. "\xe3\x93\x40\x57\x34\x0b\x4c\xf4\x08\xd5\xa5\x65\x92\xf8\x27"
  4414. "\x4e\xec\x53\xf0";
  4415. b.inLen = XSTRLEN(b.input);
  4416. b.outLen = WC_SHA3_512_DIGEST_SIZE;
  4417. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4418. c.output = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10\xfc\xa8"
  4419. "\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7\xec\x2f\x1e\x91"
  4420. "\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53\x02\xba\x1b\x0d\x8d\xc7"
  4421. "\x8c\x08\x63\x46\xb5\x33\xb4\x9c\x03\x0d\x99\xa2\x7d\xaf\x11"
  4422. "\x39\xd6\xe7\x5e";
  4423. c.inLen = XSTRLEN(c.input);
  4424. c.outLen = WC_SHA3_512_DIGEST_SIZE;
  4425. test_sha[0] = a;
  4426. test_sha[1] = b;
  4427. test_sha[2] = c;
  4428. ret = wc_InitSha3_512(&sha, HEAP_HINT, devId);
  4429. if (ret != 0)
  4430. return WC_TEST_RET_ENC_EC(ret);
  4431. for (i = 0; i < times; ++i) {
  4432. ret = wc_Sha3_512_Update(&sha, (byte*)test_sha[i].input,
  4433. (word32)test_sha[i].inLen);
  4434. if (ret != 0)
  4435. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4436. ret = wc_Sha3_512_GetHash(&sha, hashcopy);
  4437. if (ret != 0)
  4438. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4439. ret = wc_Sha3_512_Final(&sha, hash);
  4440. if (ret != 0)
  4441. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4442. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_512_DIGEST_SIZE) != 0)
  4443. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4444. if (XMEMCMP(hash, hashcopy, WC_SHA3_512_DIGEST_SIZE) != 0)
  4445. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4446. }
  4447. #ifndef NO_LARGE_HASH_TEST
  4448. /* BEGIN LARGE HASH TEST */ {
  4449. byte large_input[1024];
  4450. const char* large_digest =
  4451. "\x9c\x13\x26\xb6\x26\xb2\x94\x31\xbc\xf4\x34\xe9\x6f\xf2\xd6\x29"
  4452. "\x9a\xd0\x9b\x32\x63\x2f\x18\xa7\x5f\x23\xc9\x60\xc2\x32\x0c\xbc"
  4453. "\x57\x77\x33\xf1\x83\x81\x8a\xd3\x15\x7c\x93\xdc\x80\x9f\xed\x61"
  4454. "\x41\xa7\x5b\xfd\x32\x0e\x38\x15\xb0\x46\x3b\x7a\x4f\xfd\x44\x88";
  4455. for (i = 0; i < (int)sizeof(large_input); i++) {
  4456. large_input[i] = (byte)(i & 0xFF);
  4457. }
  4458. times = 100;
  4459. for (i = 0; i < times; ++i) {
  4460. ret = wc_Sha3_512_Update(&sha, (byte*)large_input,
  4461. (word32)sizeof(large_input));
  4462. if (ret != 0)
  4463. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4464. }
  4465. ret = wc_Sha3_512_Final(&sha, hash);
  4466. if (ret != 0)
  4467. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4468. if (XMEMCMP(hash, large_digest, WC_SHA3_512_DIGEST_SIZE) != 0)
  4469. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4470. } /* END LARGE HASH TEST */
  4471. #endif /* NO_LARGE_HASH_TEST */
  4472. exit:
  4473. wc_Sha3_512_Free(&sha);
  4474. return ret;
  4475. }
  4476. #endif /* WOLFSSL_NOSHA3_512 */
  4477. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void)
  4478. {
  4479. wc_test_ret_t ret;
  4480. (void)ret;
  4481. WOLFSSL_ENTER("sha3_test");
  4482. #ifndef WOLFSSL_NOSHA3_224
  4483. if ((ret = sha3_224_test()) != 0)
  4484. return ret;
  4485. #endif
  4486. #ifndef WOLFSSL_NOSHA3_256
  4487. if ((ret = sha3_256_test()) != 0)
  4488. return ret;
  4489. #endif
  4490. #ifndef WOLFSSL_NOSHA3_384
  4491. if ((ret = sha3_384_test()) != 0)
  4492. return ret;
  4493. #endif
  4494. #ifndef WOLFSSL_NOSHA3_512
  4495. if ((ret = sha3_512_test()) != 0)
  4496. return ret;
  4497. #endif
  4498. return 0;
  4499. }
  4500. #endif /* WOLFSSL_SHA3 */
  4501. #ifdef WOLFSSL_SHAKE128
  4502. static wc_test_ret_t shake128_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4503. size_t large_input_buf_size)
  4504. {
  4505. testVector a, b, c, d, e;
  4506. testVector test_sha[5];
  4507. wc_test_ret_t ret = 0;
  4508. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4509. static const char large_digest[] =
  4510. "\x2b\xd1\x69\x9f\xb3\x75\x40\x74\xb8\xb2\xd2\x0b\x92\x47\x9b\xfe"
  4511. "\xc9\x91\x48\xbe\xda\xa4\x09\xd7\x61\x35\x18\x05\x07\x71\xa5\x61"
  4512. "\x4d\xc4\x94\xad\xbe\x04\x7d\xad\x95\x2f\xeb\x2c\xc0\x10\x67\x43"
  4513. "\x40\xf1\x4a\x58\x1c\x54\xfa\x24\x1c\x1a\x4e\x8d\x9b\xbc\xea\xa7"
  4514. "\x32\xf2\x4c\xc7\x86\x05\x36\xdc\xb4\x42\xd8\x35\xd1\xb4\xa2\x79"
  4515. "\xa2\xe6\xee\x67\x4f\xbf\x2a\x93\x41\x88\x25\x56\x29\x90\x1a\x06"
  4516. "\xba\xfe\x9f\xa6\x1a\x74\xe8\x7e\x85\x4a\xc8\x58\x60\xb1\x7b\x18"
  4517. "\xdf\x77\x59\x46\x04\xc1\xff\x4b\x9b\xcb\xad\xfe\x91\x28\xf0\x01"
  4518. "\xc1\x33\xd0\x99\x99\x2e\x0c\x86\x84\x67\x4d\x37\xa4\x42\x45\x10"
  4519. "\xdc\x8f\xdb\x6f\xa6\x9b\xee\x8a\x60\xa5\x1f\x95\x3f\x8f\xf5\x31"
  4520. "\x4b\x1d\x48\x1e\x45\xff\x79\x5c\xbe\x72\xfc\x56\xed\x6d\x1a\x99"
  4521. "\x7f\x23\x7c\xd1\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b"
  4522. "\xa3\x60\x51\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41"
  4523. "\x77\x2c\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59"
  4524. "\x0d\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4525. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d\xa8"
  4526. "\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb\x67\x86"
  4527. "\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b\x3d\xca\x95"
  4528. "\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47\xcf\x56\xba\x71"
  4529. "\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a\xff\xb4\xbe\x72\x26"
  4530. "\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e\xd9\xe9\xe6\xf9\xff\xa5";
  4531. byte hash[sizeof(large_digest) - 1];
  4532. /*
  4533. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4534. */
  4535. a.input = "";
  4536. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4537. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4538. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4539. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4540. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4541. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4542. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4543. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a\x04\x30\x2e\x10\xc8\xbc"
  4544. "\x1c\xbf\x1a\x0b\x3a\x51\x20\xea\x17\xcd\xa7\xcf\xad\x76\x5f"
  4545. "\x56\x23\x47\x4d\x36\x8c\xcc\xa8\xaf\x00\x07\xcd\x9f\x5e\x4c"
  4546. "\x84\x9f\x16\x7a\x58\x0b\x14\xaa\xbd\xef\xae\xe7\xee\xf4\x7c"
  4547. "\xb0\xfc\xa9";
  4548. a.inLen = XSTRLEN(a.input);
  4549. a.outLen = WC_SHA3_128_BLOCK_SIZE;
  4550. b.input = "abc";
  4551. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4552. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4553. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4554. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4555. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4556. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4557. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4558. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3\x77\xcf\xb9\xcd\xe4\xc6"
  4559. "\x35\x99\xb2\x7f\x34\x62\xbb\xa4\xa0\xed\x29\x6c\x80\x1f\x9f"
  4560. "\xf7\xf5\x73\x02\xbb\x30\x76\xee\x14\x5f\x97\xa3\x2a\xe6\x8e"
  4561. "\x76\xab\x66\xc4\x8d\x51\x67\x5b\xd4\x9a\xcc\x29\x08\x2f\x56"
  4562. "\x47\x58\x4e";
  4563. b.inLen = XSTRLEN(b.input);
  4564. b.outLen = WC_SHA3_128_BLOCK_SIZE;
  4565. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4566. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4567. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4568. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4569. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4570. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4571. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4572. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4573. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa\x54\x56\x54\xf7\x0a\xe5"
  4574. "\x86\xff\x10\x13\x14\x20\x77\x14\x83\xec\x92\xed\xab\x40\x8c"
  4575. "\x76\x7b\xf4\xc5\xb4\xff\xfa\xa8\x0c\x8c\xa2\x14\xd8\x4c\x4d"
  4576. "\xc7\x00\xd0\xc5\x06\x30\xb2\xff\xc3\x79\x3e\xa4\xd8\x72\x58"
  4577. "\xb4\xc9\x54";
  4578. c.inLen = XSTRLEN(c.input);
  4579. c.outLen = WC_SHA3_128_BLOCK_SIZE;
  4580. /* Taken from NIST CAVP test vectors - full rate output. */
  4581. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4582. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4583. "\x85\xe0";
  4584. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4585. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4586. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4587. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4588. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4589. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4590. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4591. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4592. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4593. "\xa1\x41\x9b\xaf\x60\x52\xc0\xc1\xb4\x45\xf8\x35\x17\x57\xb0"
  4594. "\xd0\x22\x87\x21\x89\xe2\xc0\x27\x3f\x82\xd9\x69\x69\x66\x3e"
  4595. "\x55\x4d\x09";
  4596. d.inLen = 32;
  4597. d.outLen = WC_SHA3_128_BLOCK_SIZE;
  4598. /* Taken from NIST CAVP test vectors - more than one output block. */
  4599. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4600. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4601. "\x47\xe4";
  4602. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4603. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4604. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4605. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4606. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4607. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4608. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4609. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4610. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4611. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4612. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4613. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4614. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4615. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4616. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4617. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4618. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d"
  4619. "\xa8\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb"
  4620. "\x67\x86\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b"
  4621. "\x3d\xca\x95\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47"
  4622. "\xcf\x56\xba\x71\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a"
  4623. "\xff\xb4\xbe\x72\x26\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e"
  4624. "\xd9\xe9\xe6\xf9\xff\xa5";
  4625. e.inLen = 32;
  4626. e.outLen = 2 * WC_SHA3_128_BLOCK_SIZE;
  4627. test_sha[0] = a;
  4628. test_sha[1] = b;
  4629. test_sha[2] = c;
  4630. test_sha[3] = d;
  4631. test_sha[4] = e;
  4632. for (i = 0; i < times; ++i) {
  4633. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4634. if (ret != 0)
  4635. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4636. ret = wc_Shake128_Absorb(sha, (byte*)test_sha[i].input,
  4637. (word32)test_sha[i].inLen);
  4638. if (ret != 0)
  4639. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4640. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4641. (word32)test_sha[i].outLen / WC_SHA3_128_BLOCK_SIZE);
  4642. if (ret != 0)
  4643. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4644. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  4645. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4646. }
  4647. #ifndef NO_LARGE_HASH_TEST
  4648. /* BEGIN LARGE HASH TEST */ {
  4649. for (i = 0; i < (int)large_input_buf_size; i++) {
  4650. large_input_buf[i] = (byte)(i & 0xFF);
  4651. }
  4652. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4653. if (ret != 0)
  4654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4655. /* Absorb is non-incremental. */
  4656. ret = wc_Shake128_Absorb(sha, (byte*)large_input_buf,
  4657. (word32)large_input_buf_size);
  4658. if (ret != 0)
  4659. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4660. /* Able to squeeze out blocks incrementally. */
  4661. ret = wc_Shake128_SqueezeBlocks(sha, hash, 1);
  4662. if (ret != 0)
  4663. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4664. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4665. ((word32)sizeof(hash) / WC_SHA3_128_BLOCK_SIZE) - 1);
  4666. if (ret != 0)
  4667. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4668. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  4669. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4670. } /* END LARGE HASH TEST */
  4671. #endif /* NO_LARGE_HASH_TEST */
  4672. exit:
  4673. return ret;
  4674. }
  4675. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void)
  4676. {
  4677. wc_Shake sha;
  4678. byte hash[250];
  4679. testVector a, b, c, d, e;
  4680. testVector test_sha[5];
  4681. wc_test_ret_t ret = 0;
  4682. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4683. #define SHAKE128_LARGE_INPUT_BUFSIZ 1024
  4684. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4685. byte *large_input = NULL;
  4686. #else
  4687. byte large_input[SHAKE128_LARGE_INPUT_BUFSIZ];
  4688. #endif
  4689. static const char large_digest[] =
  4690. "\x88\xd7\x0e\x86\x46\x72\x6b\x3d\x7d\x22\xe1\xa9\x2d\x02\xdb\x35"
  4691. "\x92\x4f\x1b\x03\x90\xee\xa3\xce\xd1\x3a\x08\x3a\xd7\x4e\x10\xdf"
  4692. "\x09\x67\x33\x35\x4f\xdd\x38\x50\x5b\xcb\x75\xc7\xba\x65\xe5\xe8"
  4693. "\xb8\x76\xde\xc5\xee\xd7\xf1\x65\x93\x4e\x5e\xc4\xb1\xd7\x6b\xee"
  4694. "\x4b\x57\x48\xf5\x38\x49\x9e\x45\xa0\xf7\x32\xe9\x05\x26\x6a\x10"
  4695. "\x70\xd4\x7c\x19\x01\x1f\x6d\x37\xba\x7b\x74\xc2\xbc\xb6\xbc\x74"
  4696. "\xa3\x66\x6c\x9b\x11\x84\x9d\x4a\x36\xbc\x8a\x0d\x4c\xe3\x39\xfa"
  4697. "\xfa\x1b";
  4698. WOLFSSL_ENTER("shake128_test");
  4699. /*
  4700. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4701. */
  4702. a.input = "";
  4703. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4704. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4705. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4706. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4707. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4708. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4709. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4710. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a";
  4711. a.inLen = XSTRLEN(a.input);
  4712. a.outLen = 114;
  4713. b.input = "abc";
  4714. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4715. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4716. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4717. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4718. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4719. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4720. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4721. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3";
  4722. b.inLen = XSTRLEN(b.input);
  4723. b.outLen = 114;
  4724. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4725. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4726. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4727. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4728. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4729. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4730. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4731. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4732. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa";
  4733. c.inLen = XSTRLEN(c.input);
  4734. c.outLen = 114;
  4735. /* Taken from NIST CAVP test vectors - full rate output. */
  4736. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4737. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4738. "\x85\xe0";
  4739. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4740. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4741. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4742. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4743. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4744. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4745. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4746. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4747. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4748. "\xa1";
  4749. d.inLen = 32;
  4750. d.outLen = 136;
  4751. /* Taken from NIST CAVP test vectors - more than one output block. */
  4752. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4753. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4754. "\x47\xe4";
  4755. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4756. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4757. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4758. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4759. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4760. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4761. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4762. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4763. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4764. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4765. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4766. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4767. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4768. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4769. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4770. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4771. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4";
  4772. e.inLen = 32;
  4773. e.outLen = 250;
  4774. test_sha[0] = a;
  4775. test_sha[1] = b;
  4776. test_sha[2] = c;
  4777. test_sha[3] = d;
  4778. test_sha[4] = e;
  4779. ret = wc_InitShake128(&sha, HEAP_HINT, devId);
  4780. if (ret != 0)
  4781. return WC_TEST_RET_ENC_EC(ret);
  4782. for (i = 0; i < times; ++i) {
  4783. ret = wc_Shake128_Update(&sha, (byte*)test_sha[i].input,
  4784. (word32)test_sha[i].inLen);
  4785. if (ret != 0)
  4786. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4787. ret = wc_Shake128_Final(&sha, hash, (word32)test_sha[i].outLen);
  4788. if (ret != 0)
  4789. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4790. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  4791. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4792. }
  4793. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4794. large_input = (byte *)XMALLOC(SHAKE128_LARGE_INPUT_BUFSIZ, NULL,
  4795. DYNAMIC_TYPE_TMP_BUFFER);
  4796. if (large_input == NULL)
  4797. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  4798. #endif
  4799. #ifndef NO_LARGE_HASH_TEST
  4800. /* BEGIN LARGE HASH TEST */ {
  4801. for (i = 0; i < SHAKE128_LARGE_INPUT_BUFSIZ; i++) {
  4802. large_input[i] = (byte)(i & 0xFF);
  4803. }
  4804. times = 100;
  4805. for (i = 0; i < times; ++i) {
  4806. ret = wc_Shake128_Update(&sha, (byte*)large_input,
  4807. SHAKE128_LARGE_INPUT_BUFSIZ);
  4808. if (ret != 0)
  4809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4810. }
  4811. ret = wc_Shake128_Final(&sha, hash, (word32)sizeof(hash));
  4812. if (ret != 0)
  4813. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4814. if (XMEMCMP(hash, large_digest, sizeof(large_digest) - 1) != 0)
  4815. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4816. } /* END LARGE HASH TEST */
  4817. #endif /* NO_LARGE_HASH_TEST */
  4818. ret = shake128_absorb_test(&sha, large_input, SHAKE128_LARGE_INPUT_BUFSIZ);
  4819. exit:
  4820. wc_Shake128_Free(&sha);
  4821. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4822. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4823. #endif
  4824. return ret;
  4825. }
  4826. #endif
  4827. #ifdef WOLFSSL_SHAKE256
  4828. static wc_test_ret_t shake256_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4829. size_t large_input_buf_size)
  4830. {
  4831. testVector a, b, c, d, e;
  4832. testVector test_sha[5];
  4833. wc_test_ret_t ret = 0;
  4834. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4835. static const char large_digest[] =
  4836. "\x21\x25\x8e\xae\x6e\x4f\xa7\xe1\xb9\x6d\xa7\xc9\x7d\x46\x03\x69"
  4837. "\x29\x0d\x81\x49\xba\x5d\xaf\x37\xfd\xeb\x25\x52\x1d\xd9\xbd\x65"
  4838. "\xfa\x99\xb9\xd1\x70\x6b\xeb\xd4\xc1\x2c\xea\x24\x20\x27\xa7\xcd"
  4839. "\xfa\xe1\x81\xd9\xd5\xc1\x1c\xc7\xe9\x70\xc3\xc7\x21\x6f\x32\x22"
  4840. "\xe3\x27\xdb\x58\x5e\xea\x18\x2d\x63\x4d\x14\x6c\x94\xcf\x2b\x7e"
  4841. "\x6e\x2a\x74\xf3\xe0\xac\xb3\xb2\xcc\xef\x38\xe9\xe7\x35\xb3\xc5"
  4842. "\x77\x9d\xff\xe3\x08\x8e\xf8\x2c\x89\xbb\x45\x22\x16\x99\x91\xc0"
  4843. "\xe7\x71\x57\x75\xc5\xb1\xc6\xaf\x27\xcb\x64\x8c\xc4\xee\x3d\x5f"
  4844. "\x4c\x35\xfb\x1c\xf3\xf8\x0e\xfd\x5e\xfc\x07\xd8\x4d\x55\x32\x49"
  4845. "\x45\x0d\xab\x4a\x49\xc4\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93"
  4846. "\x7a\xe6\x6b\xb4\x36\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43"
  4847. "\x2f\x3b\xfc\x09\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48"
  4848. "\x3d\x0e\xda\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08"
  4849. "\xd9\xdc\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a"
  4850. "\xb7\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  4851. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4\xe6"
  4852. "\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97\x68\x44";
  4853. byte hash[sizeof(large_digest) - 1];
  4854. /*
  4855. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  4856. */
  4857. a.input = "";
  4858. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  4859. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  4860. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  4861. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  4862. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  4863. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  4864. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  4865. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46\xc1\x85\xc1\x51\x11\xe5"
  4866. "\x95\x52\x2a\x6b\xcd\x16\xcf\x86\xf3\xd1\x22\x10\x9e\x3b\x1f"
  4867. "\xdd";
  4868. a.inLen = XSTRLEN(a.input);
  4869. a.outLen = WC_SHA3_256_BLOCK_SIZE;
  4870. b.input = "abc";
  4871. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  4872. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  4873. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  4874. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  4875. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  4876. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  4877. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  4878. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0\x9a\x3e\x6d\x51\xcb\xfc"
  4879. "\x62\x27\x20\xd7\xa7\x5c\x63\x34\xe8\xa2\xd7\xec\x71\xa7\xcc"
  4880. "\x29";
  4881. b.inLen = XSTRLEN(b.input);
  4882. b.outLen = WC_SHA3_256_BLOCK_SIZE;
  4883. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4884. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  4885. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  4886. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  4887. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  4888. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  4889. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  4890. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  4891. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4\x9d\xd3\xef\x7e\x18\x2b"
  4892. "\x15\x24\xdf\x82\xea\x1c\xef\xe1\xc6\xc3\x96\x61\x75\xf0\x22"
  4893. "\x8d";
  4894. c.inLen = XSTRLEN(c.input);
  4895. c.outLen = WC_SHA3_256_BLOCK_SIZE;
  4896. /* Taken from NIST CAVP test vectors - full rate output. */
  4897. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4898. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4899. "\x85\xe0";
  4900. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  4901. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  4902. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  4903. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  4904. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  4905. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  4906. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  4907. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  4908. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  4909. "\xc2";
  4910. d.inLen = 32;
  4911. d.outLen = WC_SHA3_256_BLOCK_SIZE;
  4912. /* Taken from NIST CAVP test vectors - more than one output block. */
  4913. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4914. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4915. "\x47\xe4";
  4916. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  4917. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  4918. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  4919. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  4920. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  4921. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  4922. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  4923. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  4924. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  4925. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  4926. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  4927. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  4928. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  4929. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  4930. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  4931. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  4932. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4"
  4933. "\xe6\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97"
  4934. "\x68\x44";
  4935. e.inLen = 32;
  4936. e.outLen = 2 * WC_SHA3_256_BLOCK_SIZE;
  4937. test_sha[0] = a;
  4938. test_sha[1] = b;
  4939. test_sha[2] = c;
  4940. test_sha[3] = d;
  4941. test_sha[4] = e;
  4942. for (i = 0; i < times; ++i) {
  4943. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  4944. if (ret != 0)
  4945. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4946. ret = wc_Shake256_Absorb(sha, (byte*)test_sha[i].input,
  4947. (word32)test_sha[i].inLen);
  4948. if (ret != 0)
  4949. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4950. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  4951. (word32)test_sha[i].outLen / WC_SHA3_256_BLOCK_SIZE);
  4952. if (ret != 0)
  4953. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4954. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  4955. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4956. }
  4957. #ifndef NO_LARGE_HASH_TEST
  4958. /* BEGIN LARGE HASH TEST */ {
  4959. for (i = 0; i < (int)large_input_buf_size; i++) {
  4960. large_input_buf[i] = (byte)(i & 0xFF);
  4961. }
  4962. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  4963. if (ret != 0)
  4964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4965. /* Absorb is non-incremental. */
  4966. ret = wc_Shake256_Absorb(sha, large_input_buf,
  4967. (word32)large_input_buf_size);
  4968. if (ret != 0)
  4969. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4970. /* Able to squeeze out blocks incrementally. */
  4971. ret = wc_Shake256_SqueezeBlocks(sha, hash, 1);
  4972. if (ret != 0)
  4973. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4974. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  4975. ((word32)sizeof(hash) / WC_SHA3_256_BLOCK_SIZE) - 1);
  4976. if (ret != 0)
  4977. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4978. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  4979. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4980. } /* END LARGE HASH TEST */
  4981. #endif /* NO_LARGE_HASH_TEST */
  4982. exit:
  4983. return ret;
  4984. }
  4985. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void)
  4986. {
  4987. wc_Shake sha;
  4988. byte hash[250];
  4989. testVector a, b, c, d, e;
  4990. testVector test_sha[5];
  4991. wc_test_ret_t ret = 0;
  4992. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4993. #define SHAKE256_LARGE_INPUT_BUFSIZ 1024
  4994. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4995. byte *large_input = NULL;
  4996. #else
  4997. byte large_input[SHAKE256_LARGE_INPUT_BUFSIZ];
  4998. #endif
  4999. const char* large_digest =
  5000. "\x90\x32\x4a\xcc\xd1\xdf\xb8\x0b\x79\x1f\xb8\xc8\x5b\x54\xc8\xe7"
  5001. "\x45\xf5\x60\x6b\x38\x26\xb2\x0a\xee\x38\x01\xf3\xd9\xfa\x96\x9f"
  5002. "\x6a\xd7\x15\xdf\xb6\xc2\xf4\x20\x33\x44\x55\xe8\x2a\x09\x2b\x68"
  5003. "\x2e\x18\x65\x5e\x65\x93\x28\xbc\xb1\x9e\xe2\xb1\x92\xea\x98\xac"
  5004. "\x21\xef\x4c\xe1\xb4\xb7\xbe\x81\x5c\x1d\xd3\xb7\x17\xe5\xbb\xc5"
  5005. "\x8c\x68\xb7\xfb\xac\x55\x8a\x9b\x4d\x91\xe4\x9f\x72\xbb\x6e\x38"
  5006. "\xaf\x21\x7d\x21\xaa\x98\x4e\x75\xc4\xb4\x1c\x7c\x50\x45\x54\xf9"
  5007. "\xea\x26";
  5008. WOLFSSL_ENTER("shake256_test");
  5009. /*
  5010. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  5011. */
  5012. a.input = "";
  5013. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  5014. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  5015. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  5016. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  5017. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  5018. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  5019. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  5020. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46";
  5021. a.inLen = XSTRLEN(a.input);
  5022. a.outLen = 114;
  5023. b.input = "abc";
  5024. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  5025. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  5026. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  5027. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  5028. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  5029. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  5030. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  5031. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0";
  5032. b.inLen = XSTRLEN(b.input);
  5033. b.outLen = 114;
  5034. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5035. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  5036. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  5037. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  5038. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  5039. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  5040. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  5041. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  5042. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  5043. c.inLen = XSTRLEN(c.input);
  5044. c.outLen = 114;
  5045. /* Taken from NIST CAVP test vectors - full rate output. */
  5046. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  5047. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  5048. "\x85\xe0";
  5049. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  5050. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  5051. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  5052. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  5053. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  5054. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  5055. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  5056. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  5057. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  5058. "\xc2";
  5059. d.inLen = 32;
  5060. d.outLen = 136;
  5061. /* Taken from NIST CAVP test vectors - more than one output block. */
  5062. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  5063. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  5064. "\x47\xe4";
  5065. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  5066. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  5067. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  5068. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  5069. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  5070. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  5071. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  5072. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  5073. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  5074. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  5075. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  5076. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  5077. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  5078. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  5079. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  5080. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  5081. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c";
  5082. e.inLen = 32;
  5083. e.outLen = 250;
  5084. test_sha[0] = a;
  5085. test_sha[1] = b;
  5086. test_sha[2] = c;
  5087. test_sha[3] = d;
  5088. test_sha[4] = e;
  5089. ret = wc_InitShake256(&sha, HEAP_HINT, devId);
  5090. if (ret != 0)
  5091. return WC_TEST_RET_ENC_EC(ret);
  5092. for (i = 0; i < times; ++i) {
  5093. ret = wc_Shake256_Update(&sha, (byte*)test_sha[i].input,
  5094. (word32)test_sha[i].inLen);
  5095. if (ret != 0)
  5096. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5097. ret = wc_Shake256_Final(&sha, hash, (word32)test_sha[i].outLen);
  5098. if (ret != 0)
  5099. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5100. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  5101. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5102. }
  5103. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5104. large_input = (byte *)XMALLOC(SHAKE256_LARGE_INPUT_BUFSIZ, NULL,
  5105. DYNAMIC_TYPE_TMP_BUFFER);
  5106. if (large_input == NULL)
  5107. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  5108. #endif
  5109. #ifndef NO_LARGE_HASH_TEST
  5110. /* BEGIN LARGE HASH TEST */ {
  5111. for (i = 0; i < SHAKE256_LARGE_INPUT_BUFSIZ; i++) {
  5112. large_input[i] = (byte)(i & 0xFF);
  5113. }
  5114. times = 100;
  5115. for (i = 0; i < times; ++i) {
  5116. ret = wc_Shake256_Update(&sha, (byte*)large_input,
  5117. SHAKE256_LARGE_INPUT_BUFSIZ);
  5118. if (ret != 0)
  5119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5120. }
  5121. ret = wc_Shake256_Final(&sha, hash, (word32)sizeof(hash));
  5122. if (ret != 0)
  5123. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5124. if (XMEMCMP(hash, large_digest, 114) != 0)
  5125. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  5126. } /* END LARGE HASH TEST */
  5127. #endif /* NO_LARGE_HASH_TEST */
  5128. ret = shake256_absorb_test(&sha, large_input, SHAKE256_LARGE_INPUT_BUFSIZ);
  5129. exit:
  5130. wc_Shake256_Free(&sha);
  5131. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5132. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  5133. #endif
  5134. return ret;
  5135. }
  5136. #endif
  5137. #ifdef WOLFSSL_SM3
  5138. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void)
  5139. {
  5140. wc_Sm3 sm3, sm3Copy;
  5141. byte hash[WC_SM3_DIGEST_SIZE];
  5142. byte hashGet[WC_SM3_DIGEST_SIZE];
  5143. byte hashCopy[WC_SM3_DIGEST_SIZE];
  5144. wc_test_ret_t ret = 0;
  5145. WOLFSSL_ENTER("sm3_test");
  5146. testVector a, b, c;
  5147. testVector test_sm3[3];
  5148. int times = sizeof(test_sm3) / sizeof(struct testVector), i;
  5149. a.input = "";
  5150. a.output = "\x1a\xb2\x1d\x83\x55\xcf\xa1\x7f\x8e\x61\x19\x48\x31\xe8\x1a"
  5151. "\x8f\x22\xbe\xc8\xc7\x28\xfe\xfb\x74\x7e\xd0\x35\xeb\x50\x82"
  5152. "\xaa\x2b";
  5153. a.inLen = XSTRLEN(a.input);
  5154. a.outLen = WC_SM3_DIGEST_SIZE;
  5155. b.input = "abc";
  5156. b.output = "\x66\xc7\xf0\xf4\x62\xee\xed\xd9\xd1\xf2\xd4\x6b\xdc\x10\xe4"
  5157. "\xe2\x41\x67\xc4\x87\x5c\xf2\xf7\xa2\x29\x7d\xa0\x2b\x8f\x4b"
  5158. "\xa8\xe0";
  5159. b.inLen = XSTRLEN(b.input);
  5160. b.outLen = WC_SM3_DIGEST_SIZE;
  5161. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5162. c.output = "\x63\x9b\x6c\xc5\xe6\x4d\x9e\x37\xa3\x90\xb1\x92\xdf\x4f\xa1"
  5163. "\xea\x07\x20\xab\x74\x7f\xf6\x92\xb9\xf3\x8c\x4e\x66\xad\x7b"
  5164. "\x8c\x05";
  5165. c.inLen = XSTRLEN(c.input);
  5166. c.outLen = WC_SM3_DIGEST_SIZE;
  5167. test_sm3[0] = a;
  5168. test_sm3[1] = b;
  5169. test_sm3[2] = c;
  5170. ret = wc_InitSm3(&sm3, HEAP_HINT, devId);
  5171. if (ret != 0)
  5172. return WC_TEST_RET_ENC_EC(ret);
  5173. ret = wc_InitSm3(&sm3Copy, HEAP_HINT, devId);
  5174. if (ret != 0) {
  5175. wc_Sm3Free(&sm3);
  5176. return WC_TEST_RET_ENC_EC(ret);
  5177. }
  5178. /* Test all the KATs. */
  5179. for (i = 0; i < times; ++i) {
  5180. ret = wc_Sm3Update(&sm3, (byte*)test_sm3[i].input,
  5181. (word32)test_sm3[i].inLen);
  5182. if (ret != 0) {
  5183. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5184. }
  5185. /* Get the final hash but leave ready for more updates. */
  5186. ret = wc_Sm3GetHash(&sm3, hashGet);
  5187. if (ret != 0)
  5188. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5189. /* Make a copy of the hash. */
  5190. ret = wc_Sm3Copy(&sm3, &sm3Copy);
  5191. if (ret != 0)
  5192. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5193. /* Get the final hash with original. */
  5194. ret = wc_Sm3Final(&sm3, hash);
  5195. if (ret != 0)
  5196. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5197. /* Get the final hash with copy. */
  5198. ret = wc_Sm3Final(&sm3Copy, hashCopy);
  5199. if (ret != 0)
  5200. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5201. /* Dispose of copy. */
  5202. wc_Sm3Free(&sm3Copy);
  5203. /* Check hashes match expected. */
  5204. if (XMEMCMP(hash, test_sm3[i].output, WC_SM3_DIGEST_SIZE) != 0)
  5205. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5206. if (XMEMCMP(hash, hashGet, WC_SM3_DIGEST_SIZE) != 0)
  5207. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5208. if (XMEMCMP(hash, hashCopy, WC_SM3_DIGEST_SIZE) != 0)
  5209. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5210. }
  5211. #ifndef NO_LARGE_HASH_TEST
  5212. {
  5213. word32 sz;
  5214. byte large_input[1024];
  5215. #ifdef HASH_SIZE_LIMIT
  5216. const char* large_digest =
  5217. "\x6c\x42\x57\x64\x8e\x45\xf3\xb6\xc0\x83\xd3\x41\x83\x66\x51\xb4"
  5218. "\x50\xfe\x06\xb5\xb7\x1e\xd5\x0d\x41\xfc\x1e\xe5\xc6\x57\x95\x0f";
  5219. times = 20;
  5220. #else
  5221. const char* large_digest =
  5222. "\x34\x51\x3c\xde\x7c\x30\xb7\xc5\xaa\x97\x3b\xed\xb3\x16\xb9\x76"
  5223. "\x35\x46\x14\x80\x2a\x57\xca\xd9\x48\xf9\x93\xcc\x1f\xdd\xab\x79";
  5224. times = 100;
  5225. #endif
  5226. /* Set large input to something. */
  5227. for (i = 0; i < (int)sizeof(large_input); i++) {
  5228. large_input[i] = (byte)(i & 0xFF);
  5229. }
  5230. /* Hash a large number of times. */
  5231. for (i = 0; i < times; ++i) {
  5232. ret = wc_Sm3Update(&sm3, (byte*)large_input,
  5233. (word32)sizeof(large_input));
  5234. if (ret != 0)
  5235. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5236. }
  5237. /* Calculate hash and compare to expected. */
  5238. ret = wc_Sm3Final(&sm3, hash);
  5239. if (ret != 0)
  5240. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5241. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5242. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5243. /* Check updating with various sizes works. */
  5244. for (sz = 1; sz <= 64; sz++) {
  5245. /* Hash a large number of times. */
  5246. for (i = 0; i < times; ++i) {
  5247. word32 o;
  5248. /* Update sz bytes at a time from large input buffer. */
  5249. for (o = 0; o + sz <= (word32)sizeof(large_input); o += sz) {
  5250. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o), sz);
  5251. if (ret != 0)
  5252. ERROR_OUT(WC_TEST_RET_ENC_I(o), exit);
  5253. }
  5254. /* Check for left-overs. */
  5255. if (o < (word32)sizeof(large_input)) {
  5256. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o),
  5257. (word32)sizeof(large_input) - o);
  5258. if (ret != 0)
  5259. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5260. }
  5261. }
  5262. /* Calculate hash and compare to expected. */
  5263. ret = wc_Sm3Final(&sm3, hash);
  5264. if (ret != 0)
  5265. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5266. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5267. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5268. }
  5269. }
  5270. #endif /* NO_LARGE_HASH_TEST */
  5271. exit:
  5272. wc_Sm3Free(&sm3);
  5273. wc_Sm3Free(&sm3Copy);
  5274. return ret;
  5275. }
  5276. #endif
  5277. #ifndef NO_HASH_WRAPPER
  5278. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void)
  5279. {
  5280. wc_HashAlg hash;
  5281. int ret, exp_ret;
  5282. int i, j;
  5283. int digestSz;
  5284. byte data[] = "0123456789abcdef0123456789abcdef0123456";
  5285. byte out[WC_MAX_DIGEST_SIZE];
  5286. byte hashOut[WC_MAX_DIGEST_SIZE];
  5287. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5288. enum wc_HashType hashType;
  5289. #endif
  5290. enum wc_HashType typesGood[] = { WC_HASH_TYPE_MD5, WC_HASH_TYPE_SHA,
  5291. WC_HASH_TYPE_SHA224, WC_HASH_TYPE_SHA256,
  5292. WC_HASH_TYPE_SHA384, WC_HASH_TYPE_SHA512,
  5293. WC_HASH_TYPE_SHA3_224,
  5294. WC_HASH_TYPE_SHA3_256,
  5295. WC_HASH_TYPE_SHA3_384,
  5296. WC_HASH_TYPE_SHA3_512 };
  5297. enum wc_HashType typesNoImpl[] = {
  5298. #ifdef NO_MD5
  5299. WC_HASH_TYPE_MD5,
  5300. #endif
  5301. #ifdef NO_SHA
  5302. WC_HASH_TYPE_SHA,
  5303. #endif
  5304. #ifndef WOLFSSL_SHA224
  5305. WC_HASH_TYPE_SHA224,
  5306. #endif
  5307. #ifdef NO_SHA256
  5308. WC_HASH_TYPE_SHA256,
  5309. #endif
  5310. #ifndef WOLFSSL_SHA384
  5311. WC_HASH_TYPE_SHA384,
  5312. #endif
  5313. #ifndef WOLFSSL_SHA512
  5314. WC_HASH_TYPE_SHA512,
  5315. #endif
  5316. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_224)
  5317. WC_HASH_TYPE_SHA3_224,
  5318. #endif
  5319. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_256)
  5320. WC_HASH_TYPE_SHA3_256,
  5321. #endif
  5322. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_384)
  5323. WC_HASH_TYPE_SHA3_384,
  5324. #endif
  5325. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_512)
  5326. WC_HASH_TYPE_SHA3_512,
  5327. #endif
  5328. WC_HASH_TYPE_NONE
  5329. };
  5330. enum wc_HashType typesBad[] = { WC_HASH_TYPE_NONE, WC_HASH_TYPE_MD5_SHA,
  5331. WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4 };
  5332. enum wc_HashType typesHashBad[] = { WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4,
  5333. WC_HASH_TYPE_BLAKE2B,
  5334. WC_HASH_TYPE_NONE };
  5335. WOLFSSL_ENTER("hash_test");
  5336. /* Parameter Validation testing. */
  5337. ret = wc_HashInit(NULL, WC_HASH_TYPE_SHA256);
  5338. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5339. return WC_TEST_RET_ENC_EC(ret);
  5340. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5341. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5342. return WC_TEST_RET_ENC_EC(ret);
  5343. ret = wc_HashUpdate(&hash, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5344. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5345. return WC_TEST_RET_ENC_EC(ret);
  5346. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, data, sizeof(data));
  5347. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5348. return WC_TEST_RET_ENC_EC(ret);
  5349. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, NULL);
  5350. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5351. return WC_TEST_RET_ENC_EC(ret);
  5352. ret = wc_HashFinal(&hash, WC_HASH_TYPE_SHA256, NULL);
  5353. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5354. return WC_TEST_RET_ENC_EC(ret);
  5355. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, out);
  5356. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5357. return WC_TEST_RET_ENC_EC(ret);
  5358. /* Try invalid hash algorithms. */
  5359. for (i = 0; i < (int)(sizeof(typesBad)/sizeof(*typesBad)); i++) {
  5360. ret = wc_HashInit(&hash, typesBad[i]);
  5361. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5362. return WC_TEST_RET_ENC_I(i);
  5363. ret = wc_HashUpdate(&hash, typesBad[i], data, sizeof(data));
  5364. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5365. return WC_TEST_RET_ENC_I(i);
  5366. ret = wc_HashFinal(&hash, typesBad[i], out);
  5367. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5368. return WC_TEST_RET_ENC_I(i);
  5369. wc_HashFree(&hash, typesBad[i]);
  5370. }
  5371. /* Try valid hash algorithms. */
  5372. for (i = 0, j = 0; i < (int)(sizeof(typesGood)/sizeof(*typesGood)); i++) {
  5373. exp_ret = 0;
  5374. if (typesGood[i] == typesNoImpl[j]) {
  5375. /* Recognized but no implementation compiled in. */
  5376. exp_ret = HASH_TYPE_E;
  5377. j++;
  5378. }
  5379. ret = wc_HashInit(&hash, typesGood[i]);
  5380. if (ret != exp_ret)
  5381. return WC_TEST_RET_ENC_I(i);
  5382. ret = wc_HashUpdate(&hash, typesGood[i], data, sizeof(data));
  5383. if (ret != exp_ret)
  5384. return WC_TEST_RET_ENC_I(i);
  5385. ret = wc_HashFinal(&hash, typesGood[i], out);
  5386. if (ret != exp_ret)
  5387. return WC_TEST_RET_ENC_I(i);
  5388. wc_HashFree(&hash, typesGood[i]);
  5389. digestSz = wc_HashGetDigestSize(typesGood[i]);
  5390. if (exp_ret < 0 && digestSz != exp_ret)
  5391. return WC_TEST_RET_ENC_I(i);
  5392. if (exp_ret == 0 && digestSz < 0)
  5393. return WC_TEST_RET_ENC_I(i);
  5394. if (exp_ret == 0) {
  5395. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut,
  5396. (word32)digestSz - 1);
  5397. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  5398. return WC_TEST_RET_ENC_I(i);
  5399. }
  5400. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, (word32)digestSz);
  5401. if (ret != exp_ret)
  5402. return WC_TEST_RET_ENC_I(i);
  5403. if (exp_ret == 0 && XMEMCMP(out, hashOut, (word32)digestSz) != 0)
  5404. return WC_TEST_RET_ENC_I(i);
  5405. ret = wc_HashGetBlockSize(typesGood[i]);
  5406. if (exp_ret < 0 && ret != exp_ret)
  5407. return WC_TEST_RET_ENC_I(i);
  5408. if (exp_ret == 0 && ret < 0)
  5409. return WC_TEST_RET_ENC_I(i);
  5410. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5411. ret = wc_HashGetOID(typesGood[i]);
  5412. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG) ||
  5413. (exp_ret == 0 && ret == WC_NO_ERR_TRACE(HASH_TYPE_E)) ||
  5414. (exp_ret != 0 && ret != WC_NO_ERR_TRACE(HASH_TYPE_E))) {
  5415. return WC_TEST_RET_ENC_I(i);
  5416. }
  5417. hashType = wc_OidGetHash(ret);
  5418. if (exp_ret == 0 && hashType != typesGood[i])
  5419. return WC_TEST_RET_ENC_I(i);
  5420. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5421. }
  5422. for (i = 0; i < (int)(sizeof(typesHashBad)/sizeof(*typesHashBad)); i++) {
  5423. ret = wc_Hash(typesHashBad[i], data, sizeof(data), out, sizeof(out));
  5424. if ((ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) &&
  5425. (ret != WC_NO_ERR_TRACE(BUFFER_E)) &&
  5426. (ret != WC_NO_ERR_TRACE(HASH_TYPE_E)))
  5427. {
  5428. return WC_TEST_RET_ENC_I(i);
  5429. }
  5430. }
  5431. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5432. ret = wc_HashGetOID(WC_HASH_TYPE_MD2);
  5433. #ifdef WOLFSSL_MD2
  5434. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5435. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5436. {
  5437. return WC_TEST_RET_ENC_EC(ret);
  5438. }
  5439. #else
  5440. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5441. return WC_TEST_RET_ENC_EC(ret);
  5442. #endif
  5443. hashType = wc_OidGetHash(646); /* Md2h */
  5444. #ifdef WOLFSSL_MD2
  5445. if (hashType != WC_HASH_TYPE_MD2)
  5446. return WC_TEST_RET_ENC_NC;
  5447. #else
  5448. if (hashType != WC_HASH_TYPE_NONE)
  5449. return WC_TEST_RET_ENC_NC;
  5450. #endif
  5451. ret = wc_HashGetOID(WC_HASH_TYPE_MD5_SHA);
  5452. #ifndef NO_MD5
  5453. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5454. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5455. {
  5456. return WC_TEST_RET_ENC_EC(ret);
  5457. }
  5458. #else
  5459. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5460. return WC_TEST_RET_ENC_EC(ret);
  5461. #endif
  5462. ret = wc_HashGetOID(WC_HASH_TYPE_MD4);
  5463. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5464. return WC_TEST_RET_ENC_EC(ret);
  5465. ret = wc_HashGetOID(WC_HASH_TYPE_NONE);
  5466. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5467. return WC_TEST_RET_ENC_EC(ret);
  5468. hashType = wc_OidGetHash(0);
  5469. if (hashType != WC_HASH_TYPE_NONE)
  5470. return WC_TEST_RET_ENC_NC;
  5471. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5472. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD2);
  5473. #ifdef WOLFSSL_MD2
  5474. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5475. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5476. {
  5477. return WC_TEST_RET_ENC_EC(ret);
  5478. }
  5479. #else
  5480. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5481. return WC_TEST_RET_ENC_EC(ret);
  5482. #endif
  5483. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD2);
  5484. #ifdef WOLFSSL_MD2
  5485. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5486. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5487. {
  5488. return WC_TEST_RET_ENC_EC(ret);
  5489. }
  5490. #else
  5491. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5492. return WC_TEST_RET_ENC_EC(ret);
  5493. #endif
  5494. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD4);
  5495. #ifndef NO_MD4
  5496. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5497. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5498. {
  5499. return WC_TEST_RET_ENC_EC(ret);
  5500. }
  5501. #else
  5502. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5503. return WC_TEST_RET_ENC_EC(ret);
  5504. #endif
  5505. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD4);
  5506. #ifndef NO_MD4
  5507. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5508. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5509. {
  5510. return WC_TEST_RET_ENC_EC(ret);
  5511. }
  5512. #else
  5513. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5514. return WC_TEST_RET_ENC_EC(ret);
  5515. #endif
  5516. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD5_SHA);
  5517. #if !defined(NO_MD5) && !defined(NO_SHA)
  5518. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5519. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5520. {
  5521. return WC_TEST_RET_ENC_EC(ret);
  5522. }
  5523. #else
  5524. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5525. return WC_TEST_RET_ENC_EC(ret);
  5526. #endif
  5527. ret = wc_HashGetBlockSize(WC_HASH_TYPE_BLAKE2B);
  5528. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5529. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5530. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5531. {
  5532. return WC_TEST_RET_ENC_EC(ret);
  5533. }
  5534. #else
  5535. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5536. return WC_TEST_RET_ENC_EC(ret);
  5537. #endif
  5538. ret = wc_HashGetDigestSize(WC_HASH_TYPE_BLAKE2B);
  5539. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5540. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5541. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5542. {
  5543. return WC_TEST_RET_ENC_EC(ret);
  5544. }
  5545. #else
  5546. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5547. return WC_TEST_RET_ENC_EC(ret);
  5548. #endif
  5549. ret = wc_HashGetBlockSize(WC_HASH_TYPE_NONE);
  5550. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5551. return WC_TEST_RET_ENC_EC(ret);
  5552. ret = wc_HashGetDigestSize(WC_HASH_TYPE_NONE);
  5553. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5554. return WC_TEST_RET_ENC_EC(ret);
  5555. #if !defined(NO_CERTS) && !defined(NO_ASN)
  5556. #if defined(WOLFSSL_MD2) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  5557. ret = wc_GetCTC_HashOID(MD2);
  5558. if (ret == 0)
  5559. return WC_TEST_RET_ENC_EC(ret);
  5560. #endif
  5561. #ifndef NO_MD5
  5562. ret = wc_GetCTC_HashOID(WC_MD5);
  5563. if (ret == 0)
  5564. return WC_TEST_RET_ENC_EC(ret);
  5565. #endif
  5566. #ifndef NO_SHA
  5567. ret = wc_GetCTC_HashOID(WC_SHA);
  5568. if (ret == 0)
  5569. return WC_TEST_RET_ENC_EC(ret);
  5570. #endif
  5571. #ifdef WOLFSSL_SHA224
  5572. ret = wc_GetCTC_HashOID(WC_SHA224);
  5573. if (ret == 0)
  5574. return WC_TEST_RET_ENC_EC(ret);
  5575. #endif
  5576. #ifndef NO_SHA256
  5577. ret = wc_GetCTC_HashOID(WC_SHA256);
  5578. if (ret == 0)
  5579. return WC_TEST_RET_ENC_EC(ret);
  5580. #endif
  5581. #ifdef WOLFSSL_SHA384
  5582. ret = wc_GetCTC_HashOID(WC_SHA384);
  5583. if (ret == 0)
  5584. return WC_TEST_RET_ENC_EC(ret);
  5585. #endif
  5586. #ifdef WOLFSSL_SHA512
  5587. ret = wc_GetCTC_HashOID(WC_SHA512);
  5588. if (ret == 0)
  5589. return WC_TEST_RET_ENC_EC(ret);
  5590. #endif
  5591. ret = wc_GetCTC_HashOID(-1);
  5592. if (ret != 0)
  5593. return WC_TEST_RET_ENC_EC(ret);
  5594. #endif
  5595. return 0;
  5596. }
  5597. #endif /* !NO_HASH_WRAPPER */
  5598. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS) && \
  5599. defined(HAVE_FIPS_VERSION) && \
  5600. (HAVE_FIPS_VERSION >= 5))
  5601. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void)
  5602. {
  5603. Hmac hmac;
  5604. byte hash[WC_MD5_DIGEST_SIZE];
  5605. const char* keys[]=
  5606. {
  5607. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  5608. "Jefe",
  5609. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA",
  5610. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5611. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5612. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5613. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5614. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5615. };
  5616. testVector a, b, c, d;
  5617. testVector test_hmac[4];
  5618. wc_test_ret_t ret;
  5619. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5620. WOLFSSL_ENTER("hmac_md5_test");
  5621. /* Following test vectors are from RFC 2202 section 2 */
  5622. a.input = "Hi There";
  5623. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  5624. "\x9d";
  5625. a.inLen = XSTRLEN(a.input);
  5626. a.outLen = WC_MD5_DIGEST_SIZE;
  5627. b.input = "what do ya want for nothing?";
  5628. b.output = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
  5629. "\x38";
  5630. b.inLen = XSTRLEN(b.input);
  5631. b.outLen = WC_MD5_DIGEST_SIZE;
  5632. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5633. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5634. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5635. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5636. c.output = "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3"
  5637. "\xf6";
  5638. c.inLen = XSTRLEN(c.input);
  5639. c.outLen = WC_MD5_DIGEST_SIZE;
  5640. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5641. d.output = "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0"
  5642. "\xcd";
  5643. d.inLen = XSTRLEN(d.input);
  5644. d.outLen = WC_MD5_DIGEST_SIZE;
  5645. test_hmac[0] = a;
  5646. test_hmac[1] = b;
  5647. test_hmac[2] = c;
  5648. test_hmac[3] = d;
  5649. for (i = 0; i < times; ++i) {
  5650. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5651. if (i == 1) {
  5652. continue; /* cavium can't handle short keys, fips not allowed */
  5653. }
  5654. #endif
  5655. ret = wc_HmacInit(&hmac, HEAP_HINT, devId);
  5656. if (ret != 0)
  5657. return WC_TEST_RET_ENC_EC(ret);
  5658. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[i],
  5659. (word32)XSTRLEN(keys[i]));
  5660. if (ret != 0)
  5661. return WC_TEST_RET_ENC_EC(ret);
  5662. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5663. (word32)test_hmac[i].inLen);
  5664. if (ret != 0)
  5665. return WC_TEST_RET_ENC_EC(ret);
  5666. ret = wc_HmacFinal(&hmac, hash);
  5667. if (ret != 0)
  5668. return WC_TEST_RET_ENC_EC(ret);
  5669. if (XMEMCMP(hash, test_hmac[i].output, WC_MD5_DIGEST_SIZE) != 0)
  5670. return WC_TEST_RET_ENC_I(i);
  5671. wc_HmacFree(&hmac);
  5672. }
  5673. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5674. if ((ret = wc_HmacSizeByType(WC_MD5)) != WC_MD5_DIGEST_SIZE)
  5675. return WC_TEST_RET_ENC_EC(ret);
  5676. #endif
  5677. return 0;
  5678. }
  5679. #endif /* !NO_HMAC && !NO_MD5 && (!HAVE_FIPS || (HAVE_FIPS_VERSION < 5)) */
  5680. #if !defined(NO_HMAC) && !defined(NO_SHA)
  5681. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void)
  5682. {
  5683. Hmac hmac;
  5684. byte hash[WC_SHA_DIGEST_SIZE];
  5685. const char* keys[]=
  5686. {
  5687. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5688. "\x0b\x0b\x0b",
  5689. "Jefe",
  5690. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5691. "\xAA\xAA\xAA",
  5692. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5693. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5694. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5695. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5696. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5697. };
  5698. testVector a, b, c, d;
  5699. testVector test_hmac[4];
  5700. wc_test_ret_t ret;
  5701. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5702. WOLFSSL_ENTER("hmac_sha_test");
  5703. /* Following test vectors are from RFC 2202 section 3 */
  5704. a.input = "Hi There";
  5705. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  5706. "\x8e\xf1\x46\xbe\x00";
  5707. a.inLen = XSTRLEN(a.input);
  5708. a.outLen = WC_SHA_DIGEST_SIZE;
  5709. b.input = "what do ya want for nothing?";
  5710. b.output = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf"
  5711. "\x9c\x25\x9a\x7c\x79";
  5712. b.inLen = XSTRLEN(b.input);
  5713. b.outLen = WC_SHA_DIGEST_SIZE;
  5714. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5715. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5716. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5717. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5718. c.output = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b"
  5719. "\x4f\x63\xf1\x75\xd3";
  5720. c.inLen = XSTRLEN(c.input);
  5721. c.outLen = WC_SHA_DIGEST_SIZE;
  5722. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5723. d.output = "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b"
  5724. "\x55\xed\x40\x21\x12";
  5725. d.inLen = XSTRLEN(d.input);
  5726. d.outLen = WC_SHA_DIGEST_SIZE;
  5727. test_hmac[0] = a;
  5728. test_hmac[1] = b;
  5729. test_hmac[2] = c;
  5730. test_hmac[3] = d;
  5731. #if FIPS_VERSION3_GE(6,0,0)
  5732. int allowShortKeyWithFips = 1;
  5733. #endif
  5734. for (i = 0; i < times; ++i) {
  5735. #if defined(HAVE_CAVIUM) || (defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0))
  5736. if (i == 1)
  5737. continue; /* cavium can't handle short keys, fips not allowed */
  5738. #endif
  5739. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5740. return WC_TEST_RET_ENC_EC(ret);
  5741. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[i],
  5742. (word32)XSTRLEN(keys[i]));
  5743. #if FIPS_VERSION3_GE(6,0,0)
  5744. if (i == 1) {
  5745. if (ret != WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E))
  5746. return WC_TEST_RET_ENC_EC(ret);
  5747. /* Now use the ex and allow short keys with FIPS option */
  5748. ret = wc_HmacSetKey_ex(&hmac, WC_SHA, (byte*) keys[i],
  5749. (word32)XSTRLEN(keys[i]), allowShortKeyWithFips);
  5750. }
  5751. #endif
  5752. if (ret != 0)
  5753. return WC_TEST_RET_ENC_EC(ret);
  5754. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5755. (word32)test_hmac[i].inLen);
  5756. if (ret != 0)
  5757. return WC_TEST_RET_ENC_EC(ret);
  5758. ret = wc_HmacFinal(&hmac, hash);
  5759. if (ret != 0)
  5760. return WC_TEST_RET_ENC_EC(ret);
  5761. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA_DIGEST_SIZE) != 0)
  5762. return WC_TEST_RET_ENC_I(i);
  5763. wc_HmacFree(&hmac);
  5764. }
  5765. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5766. if ((ret = wc_HmacSizeByType(WC_SHA)) != WC_SHA_DIGEST_SIZE)
  5767. return WC_TEST_RET_ENC_EC(ret);
  5768. #endif
  5769. return 0;
  5770. }
  5771. #endif
  5772. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  5773. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void)
  5774. {
  5775. Hmac hmac;
  5776. byte hash[WC_SHA224_DIGEST_SIZE];
  5777. const char* keys[]=
  5778. {
  5779. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5780. "\x0b\x0b\x0b",
  5781. "Jefe",
  5782. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5783. "\xAA\xAA\xAA",
  5784. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5785. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5786. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5787. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5788. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5789. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5790. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5791. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5792. "\xAA\xAA\xAA"
  5793. };
  5794. testVector a, b, c, d;
  5795. testVector test_hmac[4];
  5796. wc_test_ret_t ret;
  5797. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5798. WOLFSSL_ENTER("hmac_sha224_test");
  5799. /* Following test vectors are from RFC 4231 section 4 */
  5800. a.input = "Hi There";
  5801. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  5802. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  5803. a.inLen = XSTRLEN(a.input);
  5804. a.outLen = WC_SHA224_DIGEST_SIZE;
  5805. b.input = "what do ya want for nothing?";
  5806. b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d"
  5807. "\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44";
  5808. b.inLen = XSTRLEN(b.input);
  5809. b.outLen = WC_SHA224_DIGEST_SIZE;
  5810. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5811. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5812. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5813. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5814. c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2"
  5815. "\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea";
  5816. c.inLen = XSTRLEN(c.input);
  5817. c.outLen = WC_SHA224_DIGEST_SIZE;
  5818. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5819. 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";
  5820. d.inLen = XSTRLEN(d.input);
  5821. d.outLen = WC_SHA224_DIGEST_SIZE;
  5822. test_hmac[0] = a;
  5823. test_hmac[1] = b;
  5824. test_hmac[2] = c;
  5825. test_hmac[3] = d;
  5826. for (i = 0; i < times; ++i) {
  5827. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5828. if (i == 1)
  5829. continue; /* cavium can't handle short keys, fips not allowed */
  5830. #endif
  5831. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5832. return WC_TEST_RET_ENC_EC(ret);
  5833. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[i],
  5834. (word32)XSTRLEN(keys[i]));
  5835. if (ret != 0)
  5836. return WC_TEST_RET_ENC_EC(ret);
  5837. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5838. (word32)test_hmac[i].inLen);
  5839. if (ret != 0)
  5840. return WC_TEST_RET_ENC_EC(ret);
  5841. ret = wc_HmacFinal(&hmac, hash);
  5842. if (ret != 0)
  5843. return WC_TEST_RET_ENC_EC(ret);
  5844. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  5845. return WC_TEST_RET_ENC_I(i);
  5846. wc_HmacFree(&hmac);
  5847. }
  5848. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5849. if ((ret = wc_HmacSizeByType(WC_SHA224)) != WC_SHA224_DIGEST_SIZE)
  5850. return WC_TEST_RET_ENC_EC(ret);
  5851. #endif
  5852. return 0;
  5853. }
  5854. #endif
  5855. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  5856. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void)
  5857. {
  5858. Hmac hmac;
  5859. byte hash[WC_SHA256_DIGEST_SIZE];
  5860. const char* keys[]=
  5861. {
  5862. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5863. "\x0b\x0b\x0b",
  5864. "Jefe",
  5865. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5866. "\xAA\xAA\xAA",
  5867. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5868. "\xAA\xAA\xAA",
  5869. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5870. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5871. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5872. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5873. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5874. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5875. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5876. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5877. "\xAA\xAA\xAA"
  5878. };
  5879. testVector a, b, c, d, e;
  5880. testVector test_hmac[5];
  5881. wc_test_ret_t ret;
  5882. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5883. WOLFSSL_ENTER("hmac_sha256_test");
  5884. /* Following test vectors are from RFC 4231 section 4 */
  5885. a.input = "Hi There";
  5886. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  5887. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  5888. "\xcf\xf7";
  5889. a.inLen = XSTRLEN(a.input);
  5890. a.outLen = WC_SHA256_DIGEST_SIZE;
  5891. b.input = "what do ya want for nothing?";
  5892. b.output = "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75"
  5893. "\xc7\x5a\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec"
  5894. "\x38\x43";
  5895. b.inLen = XSTRLEN(b.input);
  5896. b.outLen = WC_SHA256_DIGEST_SIZE;
  5897. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5898. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5899. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5900. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5901. c.output = "\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81"
  5902. "\xa7\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5"
  5903. "\x65\xfe";
  5904. c.inLen = XSTRLEN(c.input);
  5905. c.outLen = WC_SHA256_DIGEST_SIZE;
  5906. d.input = 0;
  5907. d.output = "\x86\xe5\x4f\xd4\x48\x72\x5d\x7e\x5d\xcf\xe2\x23\x53\xc8\x28"
  5908. "\xaf\x48\x78\x1e\xb4\x8c\xae\x81\x06\xa7\xe1\xd4\x98\x94\x9f"
  5909. "\x3e\x46";
  5910. d.inLen = 0;
  5911. d.outLen = WC_SHA256_DIGEST_SIZE;
  5912. e.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5913. e.output = "\x60\xe4\x31\x59\x1e\xe0\xb6\x7f\x0d\x8a\x26\xaa\xcb\xf5\xb7"
  5914. "\x7f\x8e\x0b\xc6\x21\x37\x28\xc5\x14\x05\x46\x04\x0f\x0e\xe3"
  5915. "\x7f\x54";
  5916. e.inLen = XSTRLEN(e.input);;
  5917. e.outLen = WC_SHA256_DIGEST_SIZE;
  5918. test_hmac[0] = a;
  5919. test_hmac[1] = b;
  5920. test_hmac[2] = c;
  5921. test_hmac[3] = d;
  5922. test_hmac[4] = e;
  5923. for (i = 0; i < times; ++i) {
  5924. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5925. if (i == 1)
  5926. continue; /* cavium can't handle short keys, fips not allowed */
  5927. #endif
  5928. #if defined(HAVE_INTEL_QA) || defined(HAVE_CAVIUM)
  5929. if (i == 3)
  5930. continue; /* QuickAssist can't handle empty HMAC */
  5931. #endif
  5932. if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0)
  5933. return WC_TEST_RET_ENC_I(i);
  5934. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[i],
  5935. (word32)XSTRLEN(keys[i]));
  5936. if (ret != 0)
  5937. return WC_TEST_RET_ENC_I(i);
  5938. if (test_hmac[i].input != NULL) {
  5939. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5940. (word32)test_hmac[i].inLen);
  5941. if (ret != 0)
  5942. return WC_TEST_RET_ENC_I(i);
  5943. }
  5944. ret = wc_HmacFinal(&hmac, hash);
  5945. if (ret != 0)
  5946. return WC_TEST_RET_ENC_I(i);
  5947. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA256_DIGEST_SIZE) != 0)
  5948. return WC_TEST_RET_ENC_I(i);
  5949. wc_HmacFree(&hmac);
  5950. }
  5951. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5952. if ((ret = wc_HmacSizeByType(WC_SHA256)) != WC_SHA256_DIGEST_SIZE)
  5953. return WC_TEST_RET_ENC_EC(ret);
  5954. #if FIPS_VERSION3_GE(6,0,0)
  5955. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(HMAC_KAT_FIPS_E))
  5956. #else
  5957. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5958. #endif
  5959. {
  5960. return WC_TEST_RET_ENC_EC(ret);
  5961. }
  5962. #endif
  5963. if ((ret = wolfSSL_GetHmacMaxSize()) != WC_MAX_DIGEST_SIZE)
  5964. return WC_TEST_RET_ENC_EC(ret);
  5965. return 0;
  5966. }
  5967. #endif
  5968. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  5969. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void)
  5970. {
  5971. Hmac hmac;
  5972. byte hash[WC_SHA384_DIGEST_SIZE];
  5973. const char* keys[]=
  5974. {
  5975. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5976. "\x0b\x0b\x0b",
  5977. "Jefe",
  5978. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5979. "\xAA\xAA\xAA",
  5980. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5981. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5982. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5983. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5984. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5985. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\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"
  5989. };
  5990. testVector a, b, c, d;
  5991. testVector test_hmac[4];
  5992. wc_test_ret_t ret;
  5993. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5994. WOLFSSL_ENTER("hmac_sha384_test");
  5995. /* Following test vectors are from RFC 4231 section 4 */
  5996. a.input = "Hi There";
  5997. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  5998. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  5999. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  6000. "\xfa\x9c\xb6";
  6001. a.inLen = XSTRLEN(a.input);
  6002. a.outLen = WC_SHA384_DIGEST_SIZE;
  6003. b.input = "what do ya want for nothing?";
  6004. b.output = "\xaf\x45\xd2\xe3\x76\x48\x40\x31\x61\x7f\x78\xd2\xb5\x8a\x6b"
  6005. "\x1b\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47\xe4\x2e\xc3\x73\x63\x22"
  6006. "\x44\x5e\x8e\x22\x40\xca\x5e\x69\xe2\xc7\x8b\x32\x39\xec\xfa"
  6007. "\xb2\x16\x49";
  6008. b.inLen = XSTRLEN(b.input);
  6009. b.outLen = WC_SHA384_DIGEST_SIZE;
  6010. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6011. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6012. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6013. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6014. c.output = "\x88\x06\x26\x08\xd3\xe6\xad\x8a\x0a\xa2\xac\xe0\x14\xc8\xa8"
  6015. "\x6f\x0a\xa6\x35\xd9\x47\xac\x9f\xeb\xe8\x3e\xf4\xe5\x59\x66"
  6016. "\x14\x4b\x2a\x5a\xb3\x9d\xc1\x38\x14\xb9\x4e\x3a\xb6\xe1\x01"
  6017. "\xa3\x4f\x27";
  6018. c.inLen = XSTRLEN(c.input);
  6019. c.outLen = WC_SHA384_DIGEST_SIZE;
  6020. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6021. d.output = "\x4e\xce\x08\x44\x85\x81\x3e\x90\x88\xd2\xc6\x3a\x04\x1b\xc5"
  6022. "\xb4\x4f\x9e\xf1\x01\x2a\x2b\x58\x8f\x3c\xd1\x1f\x05\x03\x3a"
  6023. "\xc4\xc6\x0c\x2e\xf6\xab\x40\x30\xfe\x82\x96\x24\x8d\xf1\x63"
  6024. "\xf4\x49\x52";
  6025. d.inLen = XSTRLEN(d.input);
  6026. d.outLen = WC_SHA384_DIGEST_SIZE;
  6027. test_hmac[0] = a;
  6028. test_hmac[1] = b;
  6029. test_hmac[2] = c;
  6030. test_hmac[3] = d;
  6031. for (i = 0; i < times; ++i) {
  6032. #if defined(HAVE_FIPS)
  6033. if (i == 1)
  6034. continue; /* fips not allowed */
  6035. #endif
  6036. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6037. return WC_TEST_RET_ENC_EC(ret);
  6038. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[i],
  6039. (word32)XSTRLEN(keys[i]));
  6040. if (ret != 0)
  6041. return WC_TEST_RET_ENC_EC(ret);
  6042. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6043. (word32)test_hmac[i].inLen);
  6044. if (ret != 0)
  6045. return WC_TEST_RET_ENC_EC(ret);
  6046. ret = wc_HmacFinal(&hmac, hash);
  6047. if (ret != 0)
  6048. return WC_TEST_RET_ENC_EC(ret);
  6049. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  6050. return WC_TEST_RET_ENC_I(i);
  6051. wc_HmacFree(&hmac);
  6052. }
  6053. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6054. if ((ret = wc_HmacSizeByType(WC_SHA384)) != WC_SHA384_DIGEST_SIZE)
  6055. return WC_TEST_RET_ENC_EC(ret);
  6056. #endif
  6057. return 0;
  6058. }
  6059. #endif
  6060. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA512)
  6061. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void)
  6062. {
  6063. Hmac hmac;
  6064. byte hash[WC_SHA512_DIGEST_SIZE];
  6065. const char* keys[]=
  6066. {
  6067. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6068. "\x0b\x0b\x0b",
  6069. "Jefe",
  6070. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6071. "\xAA\xAA\xAA",
  6072. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6073. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6074. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6075. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6076. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6077. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6078. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6079. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6080. "\xAA\xAA\xAA"
  6081. };
  6082. testVector a, b, c, d;
  6083. testVector test_hmac[4];
  6084. wc_test_ret_t ret;
  6085. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6086. WOLFSSL_ENTER("hmac_sha512_test");
  6087. /* Following test vectors are from RFC 4231 section 4 */
  6088. a.input = "Hi There";
  6089. a.output = "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c"
  6090. "\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1"
  6091. "\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae"
  6092. "\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20"
  6093. "\x3a\x12\x68\x54";
  6094. a.inLen = XSTRLEN(a.input);
  6095. a.outLen = WC_SHA512_DIGEST_SIZE;
  6096. b.input = "what do ya want for nothing?";
  6097. b.output = "\x16\x4b\x7a\x7b\xfc\xf8\x19\xe2\xe3\x95\xfb\xe7\x3b\x56\xe0"
  6098. "\xa3\x87\xbd\x64\x22\x2e\x83\x1f\xd6\x10\x27\x0c\xd7\xea\x25"
  6099. "\x05\x54\x97\x58\xbf\x75\xc0\x5a\x99\x4a\x6d\x03\x4f\x65\xf8"
  6100. "\xf0\xe6\xfd\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b\x63\x6e\x07\x0a"
  6101. "\x38\xbc\xe7\x37";
  6102. b.inLen = XSTRLEN(b.input);
  6103. b.outLen = WC_SHA512_DIGEST_SIZE;
  6104. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6105. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6106. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6107. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6108. c.output = "\xfa\x73\xb0\x08\x9d\x56\xa2\x84\xef\xb0\xf0\x75\x6c\x89\x0b"
  6109. "\xe9\xb1\xb5\xdb\xdd\x8e\xe8\x1a\x36\x55\xf8\x3e\x33\xb2\x27"
  6110. "\x9d\x39\xbf\x3e\x84\x82\x79\xa7\x22\xc8\x06\xb4\x85\xa4\x7e"
  6111. "\x67\xc8\x07\xb9\x46\xa3\x37\xbe\xe8\x94\x26\x74\x27\x88\x59"
  6112. "\xe1\x32\x92\xfb";
  6113. c.inLen = XSTRLEN(c.input);
  6114. c.outLen = WC_SHA512_DIGEST_SIZE;
  6115. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6116. d.output = "\x80\xb2\x42\x63\xc7\xc1\xa3\xeb\xb7\x14\x93\xc1\xdd\x7b\xe8"
  6117. "\xb4\x9b\x46\xd1\xf4\x1b\x4a\xee\xc1\x12\x1b\x01\x37\x83\xf8"
  6118. "\xf3\x52\x6b\x56\xd0\x37\xe0\x5f\x25\x98\xbd\x0f\xd2\x21\x5d"
  6119. "\x6a\x1e\x52\x95\xe6\x4f\x73\xf6\x3f\x0a\xec\x8b\x91\x5a\x98"
  6120. "\x5d\x78\x65\x98";
  6121. d.inLen = XSTRLEN(d.input);
  6122. d.outLen = WC_SHA512_DIGEST_SIZE;
  6123. test_hmac[0] = a;
  6124. test_hmac[1] = b;
  6125. test_hmac[2] = c;
  6126. test_hmac[3] = d;
  6127. for (i = 0; i < times; ++i) {
  6128. #if defined(HAVE_FIPS)
  6129. if (i == 1)
  6130. continue; /* fips not allowed */
  6131. #endif
  6132. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6133. return WC_TEST_RET_ENC_EC(ret);
  6134. ret = wc_HmacSetKey(&hmac, WC_SHA512, (byte*)keys[i],
  6135. (word32)XSTRLEN(keys[i]));
  6136. if (ret != 0)
  6137. return WC_TEST_RET_ENC_EC(ret);
  6138. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6139. (word32)test_hmac[i].inLen);
  6140. if (ret != 0)
  6141. return WC_TEST_RET_ENC_EC(ret);
  6142. ret = wc_HmacFinal(&hmac, hash);
  6143. if (ret != 0)
  6144. return WC_TEST_RET_ENC_EC(ret);
  6145. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  6146. return WC_TEST_RET_ENC_I(i);
  6147. wc_HmacFree(&hmac);
  6148. }
  6149. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6150. if ((ret = wc_HmacSizeByType(WC_SHA512)) != WC_SHA512_DIGEST_SIZE)
  6151. return WC_TEST_RET_ENC_EC(ret);
  6152. #endif
  6153. return 0;
  6154. }
  6155. #endif
  6156. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  6157. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  6158. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  6159. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void)
  6160. {
  6161. Hmac hmac;
  6162. byte hash[WC_SHA3_512_DIGEST_SIZE];
  6163. const char* key[4] =
  6164. {
  6165. "Jefe",
  6166. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6167. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  6168. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
  6169. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
  6170. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6171. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6172. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6173. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6174. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6175. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6176. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6177. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6178. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6179. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6180. };
  6181. const char* input[4] =
  6182. {
  6183. "what do ya want for nothing?",
  6184. "Hi There",
  6185. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6186. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6187. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6188. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6189. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
  6190. "Big Key Input"
  6191. };
  6192. const int hashType[4] =
  6193. {
  6194. WC_SHA3_224, WC_SHA3_256, WC_SHA3_384, WC_SHA3_512
  6195. };
  6196. const int hashSz[4] =
  6197. {
  6198. WC_SHA3_224_DIGEST_SIZE, WC_SHA3_256_DIGEST_SIZE,
  6199. WC_SHA3_384_DIGEST_SIZE, WC_SHA3_512_DIGEST_SIZE
  6200. };
  6201. const char* output[16] =
  6202. {
  6203. /* key = jefe, input = what do ya want for nothing? */
  6204. /* HMAC-SHA3-224 */
  6205. "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d\x1b\x79\x86\x34\xad\x38\x68\x11"
  6206. "\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b\xba\xce\x5e\x66",
  6207. /* HMAC-SHA3-256 */
  6208. "\xc7\xd4\x07\x2e\x78\x88\x77\xae\x35\x96\xbb\xb0\xda\x73\xb8\x87"
  6209. "\xc9\x17\x1f\x93\x09\x5b\x29\x4a\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5",
  6210. /* HMAC-SHA3-384 */
  6211. "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd\x67\x64\xd2\xed\x61\x90\x3f\x21"
  6212. "\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2\x3c\xa1\x35\x08\xa9\x32\x43\xce"
  6213. "\x48\xc0\x45\xdc\x00\x7f\x26\xa2\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a",
  6214. /* HMAC-SHA3-512 */
  6215. "\x5a\x4b\xfe\xab\x61\x66\x42\x7c\x7a\x36\x47\xb7\x47\x29\x2b\x83"
  6216. "\x84\x53\x7c\xdb\x89\xaf\xb3\xbf\x56\x65\xe4\xc5\xe7\x09\x35\x0b"
  6217. "\x28\x7b\xae\xc9\x21\xfd\x7c\xa0\xee\x7a\x0c\x31\xd0\x22\xa9\x5e"
  6218. "\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83\x96\x02\x75\xbe\xb4\xe6\x20\x24",
  6219. /* key = 0b..., input = Hi There */
  6220. /* HMAC-SHA3-224 */
  6221. "\x3b\x16\x54\x6b\xbc\x7b\xe2\x70\x6a\x03\x1d\xca\xfd\x56\x37\x3d"
  6222. "\x98\x84\x36\x76\x41\xd8\xc5\x9a\xf3\xc8\x60\xf7",
  6223. /* HMAC-SHA3-256 */
  6224. "\xba\x85\x19\x23\x10\xdf\xfa\x96\xe2\xa3\xa4\x0e\x69\x77\x43\x51"
  6225. "\x14\x0b\xb7\x18\x5e\x12\x02\xcd\xcc\x91\x75\x89\xf9\x5e\x16\xbb",
  6226. /* HMAC-SHA3-384 */
  6227. "\x68\xd2\xdc\xf7\xfd\x4d\xdd\x0a\x22\x40\xc8\xa4\x37\x30\x5f\x61"
  6228. "\xfb\x73\x34\xcf\xb5\xd0\x22\x6e\x1b\xc2\x7d\xc1\x0a\x2e\x72\x3a"
  6229. "\x20\xd3\x70\xb4\x77\x43\x13\x0e\x26\xac\x7e\x3d\x53\x28\x86\xbd",
  6230. /* HMAC-SHA3-512 */
  6231. "\xeb\x3f\xbd\x4b\x2e\xaa\xb8\xf5\xc5\x04\xbd\x3a\x41\x46\x5a\xac"
  6232. "\xec\x15\x77\x0a\x7c\xab\xac\x53\x1e\x48\x2f\x86\x0b\x5e\xc7\xba"
  6233. "\x47\xcc\xb2\xc6\xf2\xaf\xce\x8f\x88\xd2\x2b\x6d\xc6\x13\x80\xf2"
  6234. "\x3a\x66\x8f\xd3\x88\x8b\xb8\x05\x37\xc0\xa0\xb8\x64\x07\x68\x9e",
  6235. /* key = aa..., output = dd... */
  6236. /* HMAC-SHA3-224 */
  6237. "\x67\x6c\xfc\x7d\x16\x15\x36\x38\x78\x03\x90\x69\x2b\xe1\x42\xd2"
  6238. "\xdf\x7c\xe9\x24\xb9\x09\xc0\xc0\x8d\xbf\xdc\x1a",
  6239. /* HMAC-SHA3-256 */
  6240. "\x84\xec\x79\x12\x4a\x27\x10\x78\x65\xce\xdd\x8b\xd8\x2d\xa9\x96"
  6241. "\x5e\x5e\xd8\xc3\x7b\x0a\xc9\x80\x05\xa7\xf3\x9e\xd5\x8a\x42\x07",
  6242. /* HMAC-SHA3-384 */
  6243. "\x27\x5c\xd0\xe6\x61\xbb\x8b\x15\x1c\x64\xd2\x88\xf1\xf7\x82\xfb"
  6244. "\x91\xa8\xab\xd5\x68\x58\xd7\x2b\xab\xb2\xd4\x76\xf0\x45\x83\x73"
  6245. "\xb4\x1b\x6a\xb5\xbf\x17\x4b\xec\x42\x2e\x53\xfc\x31\x35\xac\x6e",
  6246. /* HMAC-SHA3-512 */
  6247. "\x30\x9e\x99\xf9\xec\x07\x5e\xc6\xc6\xd4\x75\xed\xa1\x18\x06\x87"
  6248. "\xfc\xf1\x53\x11\x95\x80\x2a\x99\xb5\x67\x74\x49\xa8\x62\x51\x82"
  6249. "\x85\x1c\xb3\x32\xaf\xb6\xa8\x9c\x41\x13\x25\xfb\xcb\xcd\x42\xaf"
  6250. "\xcb\x7b\x6e\x5a\xab\x7e\xa4\x2c\x66\x0f\x97\xfd\x85\x84\xbf\x03",
  6251. /* key = big key, input = Big Key Input */
  6252. /* HMAC-SHA3-224 */
  6253. "\x29\xe0\x5e\x46\xc4\xa4\x5e\x46\x74\xbf\xd7\x2d\x1a\xd8\x66\xdb"
  6254. "\x2d\x0d\x10\x4e\x2b\xfa\xad\x53\x7d\x15\x69\x8b",
  6255. /* HMAC-SHA3-256 */
  6256. "\xb5\x5b\x8d\x64\xb6\x9c\x21\xd0\xbf\x20\x5c\xa2\xf7\xb9\xb1\x4e"
  6257. "\x88\x21\x61\x2c\x66\xc3\x91\xae\x6c\x95\x16\x85\x83\xe6\xf4\x9b",
  6258. /* HMAC-SHA3-384 */
  6259. "\xaa\x91\xb3\xa6\x2f\x56\xa1\xbe\x8c\x3e\x74\x38\xdb\x58\xd9\xd3"
  6260. "\x34\xde\xa0\x60\x6d\x8d\x46\xe0\xec\xa9\xf6\x06\x35\x14\xe6\xed"
  6261. "\x83\xe6\x7c\x77\x24\x6c\x11\xb5\x90\x82\xb5\x75\xda\x7b\x83\x2d",
  6262. /* HMAC-SHA3-512 */
  6263. "\x1c\xc3\xa9\x24\x4a\x4a\x3f\xbd\xc7\x20\x00\x16\x9b\x79\x47\x03"
  6264. "\x78\x75\x2c\xb5\xf1\x2e\x62\x7c\xbe\xef\x4e\x8f\x0b\x11\x2b\x32"
  6265. "\xa0\xee\xc9\xd0\x4d\x64\x64\x0b\x37\xf4\xdd\x66\xf7\x8b\xb3\xad"
  6266. "\x52\x52\x6b\x65\x12\xde\x0d\x7c\xc0\x8b\x60\x01\x6c\x37\xd7\xa8"
  6267. };
  6268. int i = 0, iMax = sizeof(input) / sizeof(input[0]),
  6269. j, jMax = sizeof(hashType) / sizeof(hashType[0]);
  6270. int ret;
  6271. WOLFSSL_ENTER("hmac_sha3_test");
  6272. #ifdef HAVE_FIPS
  6273. /* FIPS requires a minimum length for HMAC keys, and "Jefe" is too
  6274. * short. Skip it in FIPS builds. */
  6275. i = 1;
  6276. #endif
  6277. for (; i < iMax; i++) {
  6278. for (j = 0; j < jMax; j++) {
  6279. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6280. return WC_TEST_RET_ENC_EC(ret);
  6281. ret = wc_HmacSetKey(&hmac, hashType[j], (byte*)key[i],
  6282. (word32)XSTRLEN(key[i]));
  6283. if (ret != 0)
  6284. return WC_TEST_RET_ENC_EC(ret);
  6285. ret = wc_HmacUpdate(&hmac, (byte*)input[i],
  6286. (word32)XSTRLEN(input[i]));
  6287. if (ret != 0)
  6288. return WC_TEST_RET_ENC_EC(ret);
  6289. ret = wc_HmacFinal(&hmac, hash);
  6290. if (ret != 0)
  6291. return WC_TEST_RET_ENC_EC(ret);
  6292. if (XMEMCMP(hash, output[(i*jMax) + j], (size_t)hashSz[j]) != 0)
  6293. return WC_TEST_RET_ENC_NC;
  6294. wc_HmacFree(&hmac);
  6295. if (i > 0)
  6296. continue;
  6297. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6298. ret = wc_HmacSizeByType(hashType[j]);
  6299. if (ret != hashSz[j])
  6300. return WC_TEST_RET_ENC_EC(ret);
  6301. #endif
  6302. }
  6303. }
  6304. return 0;
  6305. }
  6306. #endif
  6307. #ifdef WC_RC2
  6308. typedef struct rc2TestVector {
  6309. const char* input;
  6310. const char* output;
  6311. const char* key; /* Key, variable up to 128 bytes */
  6312. const char* iv; /* IV, 8-bytes */
  6313. int inLen;
  6314. int outLen;
  6315. int keyLen;
  6316. int effectiveKeyBits; /* Up to 1024 bits supported */
  6317. } rc2TestVector;
  6318. static wc_test_ret_t rc2_ecb_test(void)
  6319. {
  6320. wc_test_ret_t ret = 0;
  6321. byte cipher[RC2_BLOCK_SIZE];
  6322. byte plain[RC2_BLOCK_SIZE];
  6323. rc2TestVector a, b, c, d, e, f, g, h;
  6324. rc2TestVector test_rc2[8];
  6325. int times = sizeof(test_rc2) / sizeof(rc2TestVector), i;
  6326. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6327. a.output = "\xeb\xb7\x73\xf9\x93\x27\x8e\xff";
  6328. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6329. a.inLen = RC2_BLOCK_SIZE;
  6330. a.outLen = RC2_BLOCK_SIZE;
  6331. a.keyLen = 8;
  6332. a.effectiveKeyBits = 63;
  6333. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6334. b.output = "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49";
  6335. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6336. b.inLen = RC2_BLOCK_SIZE;
  6337. b.outLen = RC2_BLOCK_SIZE;
  6338. b.keyLen = 8;
  6339. b.effectiveKeyBits = 64;
  6340. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01";
  6341. c.output = "\x30\x64\x9e\xdf\x9b\xe7\xd2\xc2";
  6342. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6343. c.inLen = RC2_BLOCK_SIZE;
  6344. c.outLen = RC2_BLOCK_SIZE;
  6345. c.keyLen = 8;
  6346. c.effectiveKeyBits = 64;
  6347. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6348. d.output = "\x61\xa8\xa2\x44\xad\xac\xcc\xf0";
  6349. d.key = "\x88";
  6350. d.inLen = RC2_BLOCK_SIZE;
  6351. d.outLen = RC2_BLOCK_SIZE;
  6352. d.keyLen = 1;
  6353. d.effectiveKeyBits = 64;
  6354. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6355. e.output = "\x6c\xcf\x43\x08\x97\x4c\x26\x7f";
  6356. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6357. e.inLen = RC2_BLOCK_SIZE;
  6358. e.outLen = RC2_BLOCK_SIZE;
  6359. e.keyLen = 7;
  6360. e.effectiveKeyBits = 64;
  6361. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6362. f.output = "\x1a\x80\x7d\x27\x2b\xbe\x5d\xb1";
  6363. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6364. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6365. f.inLen = RC2_BLOCK_SIZE;
  6366. f.outLen = RC2_BLOCK_SIZE;
  6367. f.keyLen = 16;
  6368. f.effectiveKeyBits = 64;
  6369. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6370. g.output = "\x22\x69\x55\x2a\xb0\xf8\x5c\xa6";
  6371. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6372. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6373. g.inLen = RC2_BLOCK_SIZE;
  6374. g.outLen = RC2_BLOCK_SIZE;
  6375. g.keyLen = 16;
  6376. g.effectiveKeyBits = 128;
  6377. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6378. h.output = "\x5b\x78\xd3\xa4\x3d\xff\xf1\xf1";
  6379. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6380. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6381. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6382. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6383. "\x1e";
  6384. h.inLen = RC2_BLOCK_SIZE;
  6385. h.outLen = RC2_BLOCK_SIZE;
  6386. h.keyLen = 33;
  6387. h.effectiveKeyBits = 129;
  6388. a.iv = b.iv = c.iv = d.iv = e.iv = f.iv = g.iv = h.iv = NULL;
  6389. test_rc2[0] = a;
  6390. test_rc2[1] = b;
  6391. test_rc2[2] = c;
  6392. test_rc2[3] = d;
  6393. test_rc2[4] = e;
  6394. test_rc2[5] = f;
  6395. test_rc2[6] = g;
  6396. test_rc2[7] = h;
  6397. for (i = 0; i < times; ++i) {
  6398. Rc2 enc;
  6399. XMEMSET(cipher, 0, RC2_BLOCK_SIZE);
  6400. XMEMSET(plain, 0, RC2_BLOCK_SIZE);
  6401. ret = wc_Rc2SetKey(&enc, (byte*)test_rc2[i].key, test_rc2[i].keyLen,
  6402. NULL, test_rc2[i].effectiveKeyBits);
  6403. if (ret != 0) {
  6404. return WC_TEST_RET_ENC_EC(ret);
  6405. }
  6406. /* ECB encrypt */
  6407. ret = wc_Rc2EcbEncrypt(&enc, cipher, (byte*)test_rc2[i].input,
  6408. (word32)test_rc2[i].outLen);
  6409. if (ret != 0) {
  6410. return WC_TEST_RET_ENC_EC(ret);
  6411. }
  6412. if (XMEMCMP(cipher, test_rc2[i].output, test_rc2[i].outLen)) {
  6413. return WC_TEST_RET_ENC_NC;
  6414. }
  6415. /* ECB decrypt */
  6416. ret = wc_Rc2EcbDecrypt(&enc, plain, cipher, RC2_BLOCK_SIZE);
  6417. if (ret != 0) {
  6418. return WC_TEST_RET_ENC_EC(ret);
  6419. }
  6420. if (XMEMCMP(plain, test_rc2[i].input, RC2_BLOCK_SIZE)) {
  6421. return WC_TEST_RET_ENC_NC;
  6422. }
  6423. }
  6424. return 0;
  6425. }
  6426. static wc_test_ret_t rc2_cbc_test(void)
  6427. {
  6428. wc_test_ret_t ret = 0;
  6429. byte cipher[128];
  6430. byte plain[128];
  6431. rc2TestVector a, b, c, d, e, f, g, h, i;
  6432. rc2TestVector test_rc2[9];
  6433. int times = sizeof(test_rc2) / sizeof(rc2TestVector), j;
  6434. /* key length = 7, effective key bits = 63 */
  6435. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6436. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6437. a.output = "\xEB\xB7\x73\xF9\x93\x27\x8E\xFF"
  6438. "\xF0\x51\x77\x8B\x65\xDB\x13\x57";
  6439. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6440. a.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6441. a.inLen = RC2_BLOCK_SIZE*2;
  6442. a.outLen = RC2_BLOCK_SIZE*2;
  6443. a.keyLen = 8;
  6444. a.effectiveKeyBits = 63;
  6445. /* key length = 8, effective key bits = 64, all 0xFF */
  6446. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff"
  6447. "\xff\xff\xff\xff\xff\xff\xff\xff";
  6448. b.output = "\xA3\xA1\x12\x65\x4F\x81\xC5\xCD"
  6449. "\xB6\x94\x3E\xEA\x3E\x8B\x9D\x1F";
  6450. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6451. b.iv = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6452. b.inLen = RC2_BLOCK_SIZE*2;
  6453. b.outLen = RC2_BLOCK_SIZE*2;
  6454. b.keyLen = 8;
  6455. b.effectiveKeyBits = 64;
  6456. /* key length = 8, effective key bits = 64 */
  6457. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01"
  6458. "\x10\x00\x00\x00\x00\x00\x00\x01";
  6459. c.output = "\xB5\x70\x14\xA2\x5F\x40\xE3\x6D"
  6460. "\x81\x99\x8D\xE0\xB5\xD5\x3A\x05";
  6461. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6462. c.iv = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6463. c.inLen = RC2_BLOCK_SIZE*2;
  6464. c.outLen = RC2_BLOCK_SIZE*2;
  6465. c.keyLen = 8;
  6466. c.effectiveKeyBits = 64;
  6467. /* key length = 1, effective key bits = 64 */
  6468. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6469. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6470. d.output = "\x61\xA8\xA2\x44\xAD\xAC\xCC\xF0"
  6471. "\x6D\x19\xE8\xF1\xFC\xE7\x38\x87";
  6472. d.key = "\x88";
  6473. d.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6474. d.inLen = RC2_BLOCK_SIZE*2;
  6475. d.outLen = RC2_BLOCK_SIZE*2;
  6476. d.keyLen = 1;
  6477. d.effectiveKeyBits = 64;
  6478. /* key length = 7, effective key bits = 64 */
  6479. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6480. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6481. e.output = "\x6C\xCF\x43\x08\x97\x4C\x26\x7F"
  6482. "\xCC\x3C\x53\x57\x7C\xA1\xA4\x4B";
  6483. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6484. e.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6485. e.inLen = RC2_BLOCK_SIZE*2;
  6486. e.outLen = RC2_BLOCK_SIZE*2;
  6487. e.keyLen = 7;
  6488. e.effectiveKeyBits = 64;
  6489. /* key length = 16, effective key bits = 64 */
  6490. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6491. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6492. f.output = "\x1A\x80\x7D\x27\x2B\xBE\x5D\xB1"
  6493. "\x64\xEF\xE1\xC3\xB8\xAD\xFB\xBA";
  6494. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6495. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6496. f.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6497. f.inLen = RC2_BLOCK_SIZE*2;
  6498. f.outLen = RC2_BLOCK_SIZE*2;
  6499. f.keyLen = 16;
  6500. f.effectiveKeyBits = 64;
  6501. /* key length = 16, effective bits = 128 */
  6502. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6503. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6504. g.output = "\x22\x69\x55\x2A\xB0\xF8\x5C\xA6"
  6505. "\x53\x6E\xFD\x2D\x89\xE1\x2A\x73";
  6506. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6507. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6508. g.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6509. g.inLen = RC2_BLOCK_SIZE*2;
  6510. g.outLen = RC2_BLOCK_SIZE*2;
  6511. g.keyLen = 16;
  6512. g.effectiveKeyBits = 128;
  6513. /* key length = 33, effective bits = 129 */
  6514. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6515. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6516. h.output = "\x5B\x78\xD3\xA4\x3D\xFF\xF1\xF1"
  6517. "\x45\x30\xA8\xD5\xC7\x7C\x46\x19";
  6518. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6519. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6520. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6521. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6522. "\x1e";
  6523. h.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6524. h.inLen = RC2_BLOCK_SIZE*2;
  6525. h.outLen = RC2_BLOCK_SIZE*2;
  6526. h.keyLen = 33;
  6527. h.effectiveKeyBits = 129;
  6528. /* key length = 10, effective bits = 40 */
  6529. i.input = "\x11\x22\x33\x44\x55\x66\x77\x88"
  6530. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00"
  6531. "\x11\x22\x33\x44\x55\x66\x77\x88"
  6532. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00";
  6533. i.output = "\x71\x2D\x11\x99\xC9\xA0\x78\x4F"
  6534. "\xCD\xF1\x1E\x3D\xFD\x21\x7E\xDB"
  6535. "\xB2\x6E\x0D\xA4\x72\xBC\x31\x51"
  6536. "\x48\xEF\x4E\x68\x3B\xDC\xCD\x7D";
  6537. i.key = "\x26\x1E\x57\x8E\xC9\x62\xBF\xB8"
  6538. "\x3E\x96";
  6539. i.iv = "\x01\x02\x03\x04\x05\x06\x07\x08";
  6540. i.inLen = RC2_BLOCK_SIZE*4;
  6541. i.outLen = RC2_BLOCK_SIZE*4;
  6542. i.keyLen = 10;
  6543. i.effectiveKeyBits = 40;
  6544. test_rc2[0] = a;
  6545. test_rc2[1] = b;
  6546. test_rc2[2] = c;
  6547. test_rc2[3] = d;
  6548. test_rc2[4] = e;
  6549. test_rc2[5] = f;
  6550. test_rc2[6] = g;
  6551. test_rc2[7] = h;
  6552. test_rc2[8] = i;
  6553. for (j = 0; j < times; ++j) {
  6554. Rc2 rc2;
  6555. XMEMSET(cipher, 0, sizeof(cipher));
  6556. XMEMSET(plain, 0, sizeof(plain));
  6557. ret = wc_Rc2SetKey(&rc2, (byte*)test_rc2[j].key, test_rc2[j].keyLen,
  6558. (byte*)test_rc2[j].iv, test_rc2[j].effectiveKeyBits);
  6559. if (ret != 0) {
  6560. return WC_TEST_RET_ENC_EC(ret);
  6561. }
  6562. ret = wc_Rc2CbcEncrypt(&rc2, cipher, (byte*)test_rc2[j].input,
  6563. test_rc2[j].inLen);
  6564. if (ret != 0) {
  6565. return WC_TEST_RET_ENC_EC(ret);
  6566. }
  6567. if (XMEMCMP(cipher, (byte*)test_rc2[j].output, test_rc2[j].outLen)) {
  6568. return WC_TEST_RET_ENC_NC;
  6569. }
  6570. /* reset IV for decrypt, since overridden by encrypt operation */
  6571. ret = wc_Rc2SetIV(&rc2, (byte*)test_rc2[j].iv);
  6572. if (ret != 0) {
  6573. return WC_TEST_RET_ENC_EC(ret);
  6574. }
  6575. ret = wc_Rc2CbcDecrypt(&rc2, plain, cipher, test_rc2[j].outLen);
  6576. if (ret != 0) {
  6577. return WC_TEST_RET_ENC_EC(ret);
  6578. }
  6579. if (XMEMCMP(plain, (byte*)test_rc2[j].input, test_rc2[j].inLen)) {
  6580. return WC_TEST_RET_ENC_NC;
  6581. }
  6582. }
  6583. return 0;
  6584. }
  6585. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void)
  6586. {
  6587. wc_test_ret_t ret = 0;
  6588. WOLFSSL_ENTER("rc2_test");
  6589. ret = rc2_ecb_test();
  6590. if (ret != 0) {
  6591. return ret;
  6592. }
  6593. return rc2_cbc_test();
  6594. }
  6595. #endif
  6596. #ifndef NO_RC4
  6597. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void)
  6598. {
  6599. byte cipher[16];
  6600. byte plain[16];
  6601. wc_test_ret_t ret;
  6602. const char* keys[] =
  6603. {
  6604. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6605. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6606. "\x00\x00\x00\x00\x00\x00\x00\x00",
  6607. "\xef\x01\x23\x45"
  6608. };
  6609. testVector a, b, c, d;
  6610. testVector test_arc4[4];
  6611. int times = sizeof(test_arc4) / sizeof(testVector), i;
  6612. WOLFSSL_ENTER("arc4_test");
  6613. a.input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  6614. a.output = "\x75\xb7\x87\x80\x99\xe0\xc5\x96";
  6615. a.inLen = 8;
  6616. a.outLen = 8;
  6617. b.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6618. b.output = "\x74\x94\xc2\xe7\x10\x4b\x08\x79";
  6619. b.inLen = 8;
  6620. b.outLen = 8;
  6621. c.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6622. c.output = "\xde\x18\x89\x41\xa3\x37\x5d\x3a";
  6623. c.inLen = 8;
  6624. c.outLen = 8;
  6625. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  6626. d.output = "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61";
  6627. d.inLen = 10;
  6628. d.outLen = 10;
  6629. test_arc4[0] = a;
  6630. test_arc4[1] = b;
  6631. test_arc4[2] = c;
  6632. test_arc4[3] = d;
  6633. for (i = 0; i < times; ++i) {
  6634. Arc4 enc;
  6635. Arc4 dec;
  6636. int keylen = 8; /* XSTRLEN with key 0x00 not good */
  6637. if (i == 3)
  6638. keylen = 4;
  6639. ret = wc_Arc4Init(&enc, HEAP_HINT, devId);
  6640. if (ret != 0)
  6641. return WC_TEST_RET_ENC_EC(ret);
  6642. ret = wc_Arc4Init(&dec, HEAP_HINT, devId);
  6643. if (ret != 0)
  6644. return WC_TEST_RET_ENC_EC(ret);
  6645. ret = wc_Arc4SetKey(&enc, (byte*)keys[i], (word32)keylen);
  6646. if (ret != 0)
  6647. return WC_TEST_RET_ENC_EC(ret);
  6648. ret = wc_Arc4SetKey(&dec, (byte*)keys[i], (word32)keylen);
  6649. if (ret != 0)
  6650. return WC_TEST_RET_ENC_EC(ret);
  6651. ret = wc_Arc4Process(&enc, cipher, (byte*)test_arc4[i].input,
  6652. (word32)test_arc4[i].outLen);
  6653. if (ret != 0)
  6654. return WC_TEST_RET_ENC_EC(ret);
  6655. ret = wc_Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen);
  6656. if (ret != 0)
  6657. return WC_TEST_RET_ENC_EC(ret);
  6658. if (XMEMCMP(plain, test_arc4[i].input, test_arc4[i].outLen))
  6659. return WC_TEST_RET_ENC_I(i);
  6660. if (XMEMCMP(cipher, test_arc4[i].output, test_arc4[i].outLen))
  6661. return WC_TEST_RET_ENC_I(i);
  6662. wc_Arc4Free(&enc);
  6663. wc_Arc4Free(&dec);
  6664. }
  6665. return 0;
  6666. }
  6667. #endif
  6668. #ifdef HAVE_CHACHA
  6669. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void)
  6670. {
  6671. ChaCha enc;
  6672. ChaCha dec;
  6673. byte cipher[128];
  6674. byte plain[128];
  6675. byte sliver[64];
  6676. byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  6677. word32 keySz = 32;
  6678. wc_test_ret_t ret = 0;
  6679. int i;
  6680. int times = 4;
  6681. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  6682. {
  6683. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6684. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6685. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6686. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6687. };
  6688. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  6689. {
  6690. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6691. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6692. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6693. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  6694. };
  6695. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  6696. {
  6697. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6698. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6699. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6700. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6701. };
  6702. /* 128 bit key */
  6703. WOLFSSL_SMALL_STACK_STATIC const byte key4[] =
  6704. {
  6705. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6706. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6707. };
  6708. const byte* keys[] = {key1, key2, key3, key4};
  6709. WOLFSSL_SMALL_STACK_STATIC const byte ivs1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6710. WOLFSSL_SMALL_STACK_STATIC const byte ivs2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6711. WOLFSSL_SMALL_STACK_STATIC const byte ivs3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00};
  6712. WOLFSSL_SMALL_STACK_STATIC const byte ivs4[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6713. const byte* ivs[] = {ivs1, ivs2, ivs3, ivs4};
  6714. #ifndef BENCH_EMBEDDED
  6715. WOLFSSL_SMALL_STACK_STATIC const byte cipher_big_result[] = {
  6716. 0x06, 0xa6, 0x5d, 0x31, 0x21, 0x6c, 0xdb, 0x37, 0x48, 0x7c, 0x01, 0x9d,
  6717. 0x72, 0xdf, 0x0a, 0x5b, 0x64, 0x74, 0x20, 0xba, 0x9e, 0xe0, 0x26, 0x7a,
  6718. 0xbf, 0xdf, 0x83, 0x34, 0x3b, 0x4f, 0x94, 0x3f, 0x37, 0x89, 0xaf, 0x00,
  6719. 0xdf, 0x0f, 0x2e, 0x75, 0x16, 0x41, 0xf6, 0x7a, 0x86, 0x94, 0x9d, 0x32,
  6720. 0x56, 0xf0, 0x79, 0x71, 0x68, 0x6f, 0xa6, 0x6b, 0xc6, 0x59, 0x49, 0xf6,
  6721. 0x10, 0x34, 0x03, 0x03, 0x16, 0x53, 0x9a, 0x98, 0x2a, 0x46, 0xde, 0x17,
  6722. 0x06, 0x65, 0x70, 0xca, 0x0a, 0x1f, 0xab, 0x80, 0x26, 0x96, 0x3f, 0x3e,
  6723. 0x7a, 0x3c, 0xa8, 0x87, 0xbb, 0x65, 0xdd, 0x5e, 0x07, 0x7b, 0x34, 0xe0,
  6724. 0x56, 0xda, 0x32, 0x13, 0x30, 0xc9, 0x0c, 0xd7, 0xba, 0xe4, 0x1f, 0xa6,
  6725. 0x91, 0x4f, 0x72, 0x9f, 0xd9, 0x5c, 0x62, 0x7d, 0xa6, 0xc2, 0xbc, 0x87,
  6726. 0xae, 0x64, 0x11, 0x94, 0x3b, 0xbc, 0x6c, 0x23, 0xbd, 0x7d, 0x00, 0xb4,
  6727. 0x99, 0xf2, 0x68, 0xb5, 0x59, 0x70, 0x93, 0xad, 0x69, 0xd0, 0xb1, 0x28,
  6728. 0x70, 0x92, 0xeb, 0xec, 0x39, 0x80, 0x82, 0xde, 0x44, 0xe2, 0x8a, 0x26,
  6729. 0xb3, 0xe9, 0x45, 0xcf, 0x83, 0x76, 0x9f, 0x6a, 0xa0, 0x46, 0x4a, 0x3d,
  6730. 0x26, 0x56, 0xaf, 0x49, 0x41, 0x26, 0x1b, 0x6a, 0x41, 0x37, 0x65, 0x91,
  6731. 0x72, 0xc4, 0xe7, 0x3c, 0x17, 0x31, 0xae, 0x2e, 0x2b, 0x31, 0x45, 0xe4,
  6732. 0x93, 0xd3, 0x10, 0xaa, 0xc5, 0x62, 0xd5, 0x11, 0x4b, 0x57, 0x1d, 0xad,
  6733. 0x48, 0x06, 0xd0, 0x0d, 0x98, 0xa5, 0xc6, 0x5b, 0xd0, 0x9e, 0x22, 0xc0,
  6734. 0x00, 0x32, 0x5a, 0xf5, 0x1c, 0x89, 0x6d, 0x54, 0x97, 0x55, 0x6b, 0x46,
  6735. 0xc5, 0xc7, 0xc4, 0x48, 0x9c, 0xbf, 0x47, 0xdc, 0x03, 0xc4, 0x1b, 0xcb,
  6736. 0x65, 0xa6, 0x91, 0x9d, 0x6d, 0xf1, 0xb0, 0x7a, 0x4d, 0x3b, 0x03, 0x95,
  6737. 0xf4, 0x8b, 0x0b, 0xae, 0x39, 0xff, 0x3f, 0xf6, 0xc0, 0x14, 0x18, 0x8a,
  6738. 0xe5, 0x19, 0xbd, 0xc1, 0xb4, 0x05, 0x4e, 0x29, 0x2f, 0x0b, 0x33, 0x76,
  6739. 0x28, 0x16, 0xa4, 0xa6, 0x93, 0x04, 0xb5, 0x55, 0x6b, 0x89, 0x3d, 0xa5,
  6740. 0x0f, 0xd3, 0xad, 0xfa, 0xd9, 0xfd, 0x05, 0x5d, 0x48, 0x94, 0x25, 0x5a,
  6741. 0x2c, 0x9a, 0x94, 0x80, 0xb0, 0xe7, 0xcb, 0x4d, 0x77, 0xbf, 0xca, 0xd8,
  6742. 0x55, 0x48, 0xbd, 0x66, 0xb1, 0x85, 0x81, 0xb1, 0x37, 0x79, 0xab, 0x52,
  6743. 0x08, 0x14, 0x12, 0xac, 0xcd, 0x45, 0x4d, 0x53, 0x6b, 0xca, 0x96, 0xc7,
  6744. 0x3b, 0x2f, 0x73, 0xb1, 0x5a, 0x23, 0xbd, 0x65, 0xd5, 0xea, 0x17, 0xb3,
  6745. 0xdc, 0xa1, 0x17, 0x1b, 0x2d, 0xb3, 0x9c, 0xd0, 0xdb, 0x41, 0x77, 0xef,
  6746. 0x93, 0x20, 0x52, 0x3e, 0x9d, 0xf5, 0xbf, 0x33, 0xf7, 0x52, 0xc1, 0x90,
  6747. 0xa0, 0x15, 0x17, 0xce, 0xf7, 0xf7, 0xd0, 0x3a, 0x3b, 0xd1, 0x72, 0x56,
  6748. 0x31, 0x81, 0xae, 0x60, 0xab, 0x40, 0xc1, 0xd1, 0x28, 0x77, 0x53, 0xac,
  6749. 0x9f, 0x11, 0x0a, 0x88, 0x36, 0x4b, 0xda, 0x57, 0xa7, 0x28, 0x5c, 0x85,
  6750. 0xd3, 0x85, 0x9b, 0x79, 0xad, 0x05, 0x1c, 0x37, 0x14, 0x5e, 0x0d, 0xd0,
  6751. 0x23, 0x03, 0x42, 0x1d, 0x48, 0x5d, 0xc5, 0x3c, 0x5a, 0x08, 0xa9, 0x0d,
  6752. 0x6e, 0x82, 0x7c, 0x2e, 0x3c, 0x41, 0xcc, 0x96, 0x8e, 0xad, 0xee, 0x2a,
  6753. 0x61, 0x0b, 0x16, 0x0f, 0xa9, 0x24, 0x40, 0x85, 0xbc, 0x9f, 0x28, 0x8d,
  6754. 0xe6, 0x68, 0x4d, 0x8f, 0x30, 0x48, 0xd9, 0x73, 0x73, 0x6c, 0x9a, 0x7f,
  6755. 0x67, 0xf7, 0xde, 0x4c, 0x0a, 0x8b, 0xe4, 0xb3, 0x08, 0x2a, 0x52, 0xda,
  6756. 0x54, 0xee, 0xcd, 0xb5, 0x62, 0x4a, 0x26, 0x20, 0xfb, 0x40, 0xbb, 0x39,
  6757. 0x3a, 0x0f, 0x09, 0xe8, 0x00, 0xd1, 0x24, 0x97, 0x60, 0xe9, 0x83, 0x83,
  6758. 0xfe, 0x9f, 0x9c, 0x15, 0xcf, 0x69, 0x03, 0x9f, 0x03, 0xe1, 0xe8, 0x6e,
  6759. 0xbd, 0x87, 0x58, 0x68, 0xee, 0xec, 0xd8, 0x29, 0x46, 0x23, 0x49, 0x92,
  6760. 0x72, 0x95, 0x5b, 0x49, 0xca, 0xe0, 0x45, 0x59, 0xb2, 0xca, 0xf4, 0xfc,
  6761. 0xb7, 0x59, 0x37, 0x49, 0x28, 0xbc, 0xf3, 0xd7, 0x61, 0xbc, 0x4b, 0xf3,
  6762. 0xa9, 0x4b, 0x2f, 0x05, 0xa8, 0x01, 0xa5, 0xdc, 0x00, 0x6e, 0x01, 0xb6,
  6763. 0x45, 0x3c, 0xd5, 0x49, 0x7d, 0x5c, 0x25, 0xe8, 0x31, 0x87, 0xb2, 0xb9,
  6764. 0xbf, 0xb3, 0x01, 0x62, 0x0c, 0xd0, 0x48, 0x77, 0xa2, 0x34, 0x0f, 0x16,
  6765. 0x22, 0x28, 0xee, 0x54, 0x08, 0x93, 0x3b, 0xe4, 0xde, 0x7e, 0x63, 0xf7,
  6766. 0x97, 0x16, 0x5d, 0x71, 0x58, 0xc2, 0x2e, 0xf2, 0x36, 0xa6, 0x12, 0x65,
  6767. 0x94, 0x17, 0xac, 0x66, 0x23, 0x7e, 0xc6, 0x72, 0x79, 0x24, 0xce, 0x8f,
  6768. 0x55, 0x19, 0x97, 0x44, 0xfc, 0x55, 0xec, 0x85, 0x26, 0x27, 0xdb, 0x38,
  6769. 0xb1, 0x42, 0x0a, 0xdd, 0x05, 0x99, 0x28, 0xeb, 0x03, 0x6c, 0x9a, 0xe9,
  6770. 0x17, 0xf6, 0x2c, 0xb0, 0xfe, 0xe7, 0xa4, 0xa7, 0x31, 0xda, 0x4d, 0xb0,
  6771. 0x29, 0xdb, 0xdd, 0x8d, 0x12, 0x13, 0x9c, 0xb4, 0xcc, 0x83, 0x97, 0xfb,
  6772. 0x1a, 0xdc, 0x08, 0xd6, 0x30, 0x62, 0xe8, 0xeb, 0x8b, 0x61, 0xcb, 0x1d,
  6773. 0x06, 0xe3, 0xa5, 0x4d, 0x35, 0xdb, 0x59, 0xa8, 0x2d, 0x87, 0x27, 0x44,
  6774. 0x6f, 0xc0, 0x38, 0x97, 0xe4, 0x85, 0x00, 0x02, 0x09, 0xf6, 0x69, 0x3a,
  6775. 0xcf, 0x08, 0x1b, 0x21, 0xbb, 0x79, 0xb1, 0xa1, 0x34, 0x09, 0xe0, 0x80,
  6776. 0xca, 0xb0, 0x78, 0x8a, 0x11, 0x97, 0xd4, 0x07, 0xbe, 0x1b, 0x6a, 0x5d,
  6777. 0xdb, 0xd6, 0x1f, 0x76, 0x6b, 0x16, 0xf0, 0x58, 0x84, 0x5f, 0x59, 0xce,
  6778. 0x62, 0x34, 0xc3, 0xdf, 0x94, 0xb8, 0x2f, 0x84, 0x68, 0xf0, 0xb8, 0x51,
  6779. 0xd9, 0x6d, 0x8e, 0x4a, 0x1d, 0xe6, 0x5c, 0xd8, 0x86, 0x25, 0xe3, 0x24,
  6780. 0xfd, 0x21, 0x61, 0x13, 0x48, 0x3e, 0xf6, 0x7d, 0xa6, 0x71, 0x9b, 0xd2,
  6781. 0x6e, 0xe6, 0xd2, 0x08, 0x94, 0x62, 0x6c, 0x98, 0xfe, 0x2f, 0x9c, 0x88,
  6782. 0x7e, 0x78, 0x15, 0x02, 0x00, 0xf0, 0xba, 0x24, 0x91, 0xf2, 0xdc, 0x47,
  6783. 0x51, 0x4d, 0x15, 0x5e, 0x91, 0x5f, 0x57, 0x5b, 0x1d, 0x35, 0x24, 0x45,
  6784. 0x75, 0x9b, 0x88, 0x75, 0xf1, 0x2f, 0x85, 0xe7, 0x89, 0xd1, 0x01, 0xb4,
  6785. 0xc8, 0x18, 0xb7, 0x97, 0xef, 0x4b, 0x90, 0xf4, 0xbf, 0x10, 0x27, 0x3c,
  6786. 0x60, 0xff, 0xc4, 0x94, 0x20, 0x2f, 0x93, 0x4b, 0x4d, 0xe3, 0x80, 0xf7,
  6787. 0x2c, 0x71, 0xd9, 0xe3, 0x68, 0xb4, 0x77, 0x2b, 0xc7, 0x0d, 0x39, 0x92,
  6788. 0xef, 0x91, 0x0d, 0xb2, 0x11, 0x50, 0x0e, 0xe8, 0xad, 0x3b, 0xf6, 0xb5,
  6789. 0xc6, 0x14, 0x4d, 0x33, 0x53, 0xa7, 0x60, 0x15, 0xc7, 0x27, 0x51, 0xdc,
  6790. 0x54, 0x29, 0xa7, 0x0d, 0x6a, 0x7b, 0x72, 0x13, 0xad, 0x7d, 0x41, 0x19,
  6791. 0x4e, 0x42, 0x49, 0xcc, 0x42, 0xe4, 0xbd, 0x99, 0x13, 0xd9, 0x7f, 0xf3,
  6792. 0x38, 0xa4, 0xb6, 0x33, 0xed, 0x07, 0x48, 0x7e, 0x8e, 0x82, 0xfe, 0x3a,
  6793. 0x9d, 0x75, 0x93, 0xba, 0x25, 0x4e, 0x37, 0x3c, 0x0c, 0xd5, 0x69, 0xa9,
  6794. 0x2d, 0x9e, 0xfd, 0xe8, 0xbb, 0xf5, 0x0c, 0xe2, 0x86, 0xb9, 0x5e, 0x6f,
  6795. 0x28, 0xe4, 0x19, 0xb3, 0x0b, 0xa4, 0x86, 0xd7, 0x24, 0xd0, 0xb8, 0x89,
  6796. 0x7b, 0x76, 0xec, 0x05, 0x10, 0x5b, 0x68, 0xe9, 0x58, 0x66, 0xa3, 0xc5,
  6797. 0xb6, 0x63, 0x20, 0x0e, 0x0e, 0xea, 0x3d, 0x61, 0x5e, 0xda, 0x3d, 0x3c,
  6798. 0xf9, 0xfd, 0xed, 0xa9, 0xdb, 0x52, 0x94, 0x8a, 0x00, 0xca, 0x3c, 0x8d,
  6799. 0x66, 0x8f, 0xb0, 0xf0, 0x5a, 0xca, 0x3f, 0x63, 0x71, 0xbf, 0xca, 0x99,
  6800. 0x37, 0x9b, 0x75, 0x97, 0x89, 0x10, 0x6e, 0xcf, 0xf2, 0xf5, 0xe3, 0xd5,
  6801. 0x45, 0x9b, 0xad, 0x10, 0x71, 0x6c, 0x5f, 0x6f, 0x7f, 0x22, 0x77, 0x18,
  6802. 0x2f, 0xf9, 0x99, 0xc5, 0x69, 0x58, 0x03, 0x12, 0x86, 0x82, 0x3e, 0xbf,
  6803. 0xc2, 0x12, 0x35, 0x43, 0xa3, 0xd9, 0x18, 0x4f, 0x41, 0x11, 0x6b, 0xf3,
  6804. 0x67, 0xaf, 0x3d, 0x78, 0xe4, 0x22, 0x2d, 0xb3, 0x48, 0x43, 0x31, 0x1d,
  6805. 0xef, 0xa8, 0xba, 0x49, 0x8e, 0xa9, 0xa7, 0xb6, 0x18, 0x77, 0x84, 0xca,
  6806. 0xbd, 0xa2, 0x02, 0x1b, 0x6a, 0xf8, 0x5f, 0xda, 0xff, 0xcf, 0x01, 0x6a,
  6807. 0x86, 0x69, 0xa9, 0xe9, 0xcb, 0x60, 0x1e, 0x15, 0xdc, 0x8f, 0x5d, 0x39,
  6808. 0xb5, 0xce, 0x55, 0x5f, 0x47, 0x97, 0xb1, 0x19, 0x6e, 0x21, 0xd6, 0x13,
  6809. 0x39, 0xb2, 0x24, 0xe0, 0x62, 0x82, 0x9f, 0xed, 0x12, 0x81, 0xed, 0xee,
  6810. 0xab, 0xd0, 0x2f, 0x19, 0x89, 0x3f, 0x57, 0x2e, 0xc2, 0xe2, 0x67, 0xe8,
  6811. 0xae, 0x03, 0x56, 0xba, 0xd4, 0xd0, 0xa4, 0x89, 0x03, 0x06, 0x5b, 0xcc,
  6812. 0xf2, 0x22, 0xb8, 0x0e, 0x76, 0x79, 0x4a, 0x42, 0x1d, 0x37, 0x51, 0x5a,
  6813. 0xaa, 0x46, 0x6c, 0x2a, 0xdd, 0x66, 0xfe, 0xc6, 0x68, 0xc3, 0x38, 0xa2,
  6814. 0xae, 0x5b, 0x98, 0x24, 0x5d, 0x43, 0x05, 0x82, 0x38, 0x12, 0xd3, 0xd1,
  6815. 0x75, 0x2d, 0x4f, 0x61, 0xbd, 0xb9, 0x10, 0x87, 0x44, 0x2a, 0x78, 0x07,
  6816. 0xff, 0xf4, 0x0f, 0xa1, 0xf3, 0x68, 0x9f, 0xbe, 0xae, 0xa2, 0x91, 0xf0,
  6817. 0xc7, 0x55, 0x7a, 0x52, 0xd5, 0xa3, 0x8d, 0x6f, 0xe4, 0x90, 0x5c, 0xf3,
  6818. 0x5f, 0xce, 0x3d, 0x23, 0xf9, 0x8e, 0xae, 0x14, 0xfb, 0x82, 0x9a, 0xa3,
  6819. 0x04, 0x5f, 0xbf, 0xad, 0x3e, 0xf2, 0x97, 0x0a, 0x60, 0x40, 0x70, 0x19,
  6820. 0x72, 0xad, 0x66, 0xfb, 0x78, 0x1b, 0x84, 0x6c, 0x98, 0xbc, 0x8c, 0xf8,
  6821. 0x4f, 0xcb, 0xb5, 0xf6, 0xaf, 0x7a, 0xb7, 0x93, 0xef, 0x67, 0x48, 0x02,
  6822. 0x2c, 0xcb, 0xe6, 0x77, 0x0f, 0x7b, 0xc1, 0xee, 0xc5, 0xb6, 0x2d, 0x7e,
  6823. 0x62, 0xa0, 0xc0, 0xa7, 0xa5, 0x80, 0x31, 0x92, 0x50, 0xa1, 0x28, 0x22,
  6824. 0x95, 0x03, 0x17, 0xd1, 0x0f, 0xf6, 0x08, 0xe5, 0xec
  6825. };
  6826. #define CHACHA_BIG_TEST_SIZE 1305
  6827. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  6828. byte cipher_big[CHACHA_BIG_TEST_SIZE] = {0};
  6829. byte plain_big[CHACHA_BIG_TEST_SIZE] = {0};
  6830. byte input_big[CHACHA_BIG_TEST_SIZE] = {0};
  6831. #else
  6832. byte* cipher_big;
  6833. byte* plain_big;
  6834. byte* input_big;
  6835. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6836. int block_size;
  6837. #endif /* BENCH_EMBEDDED */
  6838. byte a[] = {0x76,0xb8,0xe0,0xad,0xa0,0xf1,0x3d,0x90};
  6839. byte b[] = {0x45,0x40,0xf0,0x5a,0x9f,0x1f,0xb2,0x96};
  6840. byte c[] = {0xde,0x9c,0xba,0x7b,0xf3,0xd6,0x9e,0xf5};
  6841. byte d[] = {0x89,0x67,0x09,0x52,0x60,0x83,0x64,0xfd};
  6842. byte* test_chacha[4];
  6843. test_chacha[0] = a;
  6844. test_chacha[1] = b;
  6845. test_chacha[2] = c;
  6846. test_chacha[3] = d;
  6847. WOLFSSL_ENTER("chacha_test");
  6848. #ifndef BENCH_EMBEDDED
  6849. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  6850. cipher_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6851. DYNAMIC_TYPE_TMP_BUFFER);
  6852. if (cipher_big == NULL) {
  6853. return MEMORY_E;
  6854. }
  6855. plain_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6856. DYNAMIC_TYPE_TMP_BUFFER);
  6857. if (plain_big == NULL) {
  6858. return MEMORY_E;
  6859. }
  6860. input_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6861. DYNAMIC_TYPE_TMP_BUFFER);
  6862. if (input_big == NULL) {
  6863. return MEMORY_E;
  6864. }
  6865. XMEMSET(cipher_big, 0, CHACHA_BIG_TEST_SIZE);
  6866. XMEMSET(plain_big, 0, CHACHA_BIG_TEST_SIZE);
  6867. XMEMSET(input_big, 0, CHACHA_BIG_TEST_SIZE);
  6868. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6869. #endif /* BENCH_EMBEDDED */
  6870. for (i = 0; i < times; ++i) {
  6871. if (i < 3) {
  6872. keySz = 32;
  6873. }
  6874. else {
  6875. keySz = 16;
  6876. }
  6877. XMEMCPY(plain, keys[i], keySz);
  6878. XMEMSET(cipher, 0, 32);
  6879. XMEMCPY(cipher + 4, ivs[i], 8);
  6880. ret |= wc_Chacha_SetKey(&enc, keys[i], keySz);
  6881. ret |= wc_Chacha_SetKey(&dec, keys[i], keySz);
  6882. if (ret != 0)
  6883. return ret;
  6884. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  6885. ret |= wc_Chacha_SetIV(&dec, cipher, 0);
  6886. if (ret != 0)
  6887. return ret;
  6888. XMEMCPY(plain, input, 8);
  6889. ret |= wc_Chacha_Process(&enc, cipher, plain, (word32)8);
  6890. ret |= wc_Chacha_Process(&dec, plain, cipher, (word32)8);
  6891. if (ret != 0)
  6892. return ret;
  6893. if (XMEMCMP(test_chacha[i], cipher, 8))
  6894. return WC_TEST_RET_ENC_I(i);
  6895. if (XMEMCMP(plain, input, 8))
  6896. return WC_TEST_RET_ENC_I(i);
  6897. }
  6898. /* test of starting at a different counter
  6899. encrypts all of the information and decrypts starting at 2nd chunk */
  6900. XMEMSET(plain, 0, sizeof(plain));
  6901. XMEMSET(sliver, 1, sizeof(sliver)); /* set as 1's to not match plain */
  6902. XMEMSET(cipher, 0, sizeof(cipher));
  6903. XMEMCPY(cipher + 4, ivs[0], 8);
  6904. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  6905. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  6906. if (ret != 0)
  6907. return ret;
  6908. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  6909. ret |= wc_Chacha_SetIV(&dec, cipher, 1);
  6910. if (ret != 0)
  6911. return ret;
  6912. ret |= wc_Chacha_Process(&enc, cipher, plain, sizeof(plain));
  6913. ret |= wc_Chacha_Process(&dec, sliver, cipher + 64, sizeof(sliver));
  6914. if (ret != 0)
  6915. return ret;
  6916. if (XMEMCMP(plain + 64, sliver, 64))
  6917. return WC_TEST_RET_ENC_NC;
  6918. #ifndef BENCH_EMBEDDED
  6919. /* test of encrypting more data */
  6920. keySz = 32;
  6921. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  6922. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  6923. if (ret != 0)
  6924. return ret;
  6925. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  6926. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  6927. if (ret != 0)
  6928. return ret;
  6929. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big, CHACHA_BIG_TEST_SIZE);
  6930. ret |= wc_Chacha_Process(&dec, plain_big, cipher_big,
  6931. CHACHA_BIG_TEST_SIZE);
  6932. if (ret != 0)
  6933. return ret;
  6934. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  6935. return WC_TEST_RET_ENC_NC;
  6936. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  6937. return WC_TEST_RET_ENC_NC;
  6938. for (i = 0; i < 18; ++i) {
  6939. /* this will test all paths
  6940. * block sizes: 1 3 7 15 31 63 127 255 511 (i = 0- 8)
  6941. * 2 4 8 16 32 64 128 256 512 (i = 9-17)
  6942. */
  6943. block_size = (2 << (i%9)) - (i<9?1:0);
  6944. keySz = 32;
  6945. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  6946. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  6947. if (ret != 0)
  6948. return ret;
  6949. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  6950. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  6951. if (ret != 0)
  6952. return ret;
  6953. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big , (word32)block_size);
  6954. ret |= wc_Chacha_Process(&dec, plain_big , cipher_big, (word32)block_size);
  6955. if (ret != 0)
  6956. return ret;
  6957. if (XMEMCMP(plain_big, input_big, (word32)block_size))
  6958. return WC_TEST_RET_ENC_I(i);
  6959. if (XMEMCMP(cipher_big, cipher_big_result, (word32)block_size))
  6960. return WC_TEST_RET_ENC_I(i);
  6961. }
  6962. /* Streaming test */
  6963. for (i = 1; i <= (int)CHACHA_CHUNK_BYTES + 1; i++) {
  6964. int j, rem;
  6965. ret = wc_Chacha_SetKey(&enc, keys[0], keySz);
  6966. if (ret != 0)
  6967. return WC_TEST_RET_ENC_EC(ret);
  6968. ret = wc_Chacha_SetKey(&dec, keys[0], keySz);
  6969. if (ret != 0)
  6970. return WC_TEST_RET_ENC_EC(ret);
  6971. ret = wc_Chacha_SetIV(&enc, ivs[2], 0);
  6972. if (ret != 0)
  6973. return WC_TEST_RET_ENC_EC(ret);
  6974. ret = wc_Chacha_SetIV(&dec, ivs[2], 0);
  6975. if (ret != 0)
  6976. return WC_TEST_RET_ENC_EC(ret);
  6977. for (j = 0; j < CHACHA_BIG_TEST_SIZE - i; j+= i) {
  6978. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)i);
  6979. if (ret != 0)
  6980. return WC_TEST_RET_ENC_EC(ret);
  6981. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)i);
  6982. if (ret != 0)
  6983. return WC_TEST_RET_ENC_EC(ret);
  6984. }
  6985. rem = CHACHA_BIG_TEST_SIZE - j;
  6986. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)rem);
  6987. if (ret != 0)
  6988. return WC_TEST_RET_ENC_EC(ret);
  6989. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)rem);
  6990. if (ret != 0)
  6991. return WC_TEST_RET_ENC_EC(ret);
  6992. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  6993. return WC_TEST_RET_ENC_I(i);
  6994. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  6995. return WC_TEST_RET_ENC_I(i);
  6996. }
  6997. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  6998. XFREE(cipher_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  6999. XFREE(plain_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7000. XFREE(input_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7001. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  7002. #endif /* BENCH_EMBEDDED */
  7003. return 0;
  7004. }
  7005. #endif /* HAVE_CHACHA */
  7006. #ifdef HAVE_POLY1305
  7007. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void)
  7008. {
  7009. byte tag[16];
  7010. Poly1305 enc;
  7011. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {
  7012. 0x43,0x72,0x79,0x70,0x74,0x6f,0x67,0x72,
  7013. 0x61,0x70,0x68,0x69,0x63,0x20,0x46,0x6f,
  7014. 0x72,0x75,0x6d,0x20,0x52,0x65,0x73,0x65,
  7015. 0x61,0x72,0x63,0x68,0x20,0x47,0x72,0x6f,
  7016. 0x75,0x70
  7017. };
  7018. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {
  7019. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x77,0x6f,0x72,
  7020. 0x6c,0x64,0x21
  7021. };
  7022. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {
  7023. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7024. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7025. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7026. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7027. };
  7028. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  7029. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7030. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7031. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7032. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7033. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7034. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7035. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7036. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7037. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7038. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7039. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7040. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7041. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7042. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7043. 0x61,0x16
  7044. };
  7045. WOLFSSL_SMALL_STACK_STATIC const byte msg5[] = {
  7046. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7047. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7048. };
  7049. WOLFSSL_SMALL_STACK_STATIC const byte msg6[] = {
  7050. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7051. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7052. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7053. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7054. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7055. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7056. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7057. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7058. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7059. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7060. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7061. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7062. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7063. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7064. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7065. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7066. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7067. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7068. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7069. 0x61,0x16
  7070. };
  7071. WOLFSSL_SMALL_STACK_STATIC const byte msg7[] = {
  7072. 0xe8,0x8c,0x85,0x03,0x43,0xaf,0xa7,0x85,
  7073. 0x21,0x6b,0xc3,0x45,0xc4,0x53,0x98,0xf8,
  7074. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7075. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7076. };
  7077. byte additional[] = {
  7078. 0x50,0x51,0x52,0x53,0xc0,0xc1,0xc2,0xc3,
  7079. 0xc4,0xc5,0xc6,0xc7
  7080. };
  7081. WOLFSSL_SMALL_STACK_STATIC const byte correct0[] = {
  7082. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7083. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7084. };
  7085. WOLFSSL_SMALL_STACK_STATIC const byte correct1[] = {
  7086. 0xa8,0x06,0x1d,0xc1,0x30,0x51,0x36,0xc6,
  7087. 0xc2,0x2b,0x8b,0xaf,0x0c,0x01,0x27,0xa9
  7088. };
  7089. WOLFSSL_SMALL_STACK_STATIC const byte correct2[] = {
  7090. 0xa6,0xf7,0x45,0x00,0x8f,0x81,0xc9,0x16,
  7091. 0xa2,0x0d,0xcc,0x74,0xee,0xf2,0xb2,0xf0
  7092. };
  7093. WOLFSSL_SMALL_STACK_STATIC const byte correct3[] = {
  7094. 0x49,0xec,0x78,0x09,0x0e,0x48,0x1e,0xc6,
  7095. 0xc2,0x6b,0x33,0xb9,0x1c,0xcc,0x03,0x07
  7096. };
  7097. WOLFSSL_SMALL_STACK_STATIC const byte correct4[] = {
  7098. 0x1a,0xe1,0x0b,0x59,0x4f,0x09,0xe2,0x6a,
  7099. 0x7e,0x90,0x2e,0xcb,0xd0,0x60,0x06,0x91
  7100. };
  7101. WOLFSSL_SMALL_STACK_STATIC const byte correct5[] = {
  7102. 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7103. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7104. };
  7105. WOLFSSL_SMALL_STACK_STATIC const byte correct6[] = {
  7106. 0xea,0x11,0x5c,0x4f,0xd0,0xc0,0x10,0xae,
  7107. 0xf7,0xdf,0xda,0x77,0xa2,0xe9,0xaf,0xca
  7108. };
  7109. WOLFSSL_SMALL_STACK_STATIC const byte correct7[] = {
  7110. 0x14,0x00,0x00,0x88,0x5c,0x00,0x00,0x88,
  7111. 0x5c,0x00,0x00,0x88,0x5c,0x00,0x00,0x88
  7112. };
  7113. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7114. 0x85,0xd6,0xbe,0x78,0x57,0x55,0x6d,0x33,
  7115. 0x7f,0x44,0x52,0xfe,0x42,0xd5,0x06,0xa8,
  7116. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7117. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7118. };
  7119. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7120. 0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,
  7121. 0x33,0x32,0x2d,0x62,0x79,0x74,0x65,0x20,
  7122. 0x6b,0x65,0x79,0x20,0x66,0x6f,0x72,0x20,
  7123. 0x50,0x6f,0x6c,0x79,0x31,0x33,0x30,0x35
  7124. };
  7125. WOLFSSL_SMALL_STACK_STATIC const byte key4[] = {
  7126. 0x7b,0xac,0x2b,0x25,0x2d,0xb4,0x47,0xaf,
  7127. 0x09,0xb6,0x7a,0x55,0xa4,0xe9,0x55,0x84,
  7128. 0x0a,0xe1,0xd6,0x73,0x10,0x75,0xd9,0xeb,
  7129. 0x2a,0x93,0x75,0x78,0x3e,0xd5,0x53,0xff
  7130. };
  7131. WOLFSSL_SMALL_STACK_STATIC const byte key5[] = {
  7132. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7133. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7134. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7135. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7136. };
  7137. WOLFSSL_SMALL_STACK_STATIC const byte key7[] = {
  7138. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7139. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7140. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7141. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  7142. };
  7143. const byte* msgs[] = {NULL, msg1, msg2, msg3, msg5, msg6, msg7};
  7144. word32 szm[] = {0, sizeof(msg1), sizeof(msg2),
  7145. sizeof(msg3), sizeof(msg5), sizeof(msg6),
  7146. sizeof(msg7)};
  7147. const byte* keys[] = {key, key, key2, key2, key5, key, key7};
  7148. const byte* tests[] = {correct0, correct1, correct2, correct3, correct5,
  7149. correct6, correct7};
  7150. int i;
  7151. wc_test_ret_t ret = 0;
  7152. WOLFSSL_ENTER("poly1305_test");
  7153. for (i = 0; i < 7; i++) {
  7154. ret = wc_Poly1305SetKey(&enc, keys[i], 32);
  7155. if (ret != 0)
  7156. return WC_TEST_RET_ENC_I(i);
  7157. ret = wc_Poly1305Update(&enc, msgs[i], szm[i]);
  7158. if (ret != 0)
  7159. return WC_TEST_RET_ENC_I(i);
  7160. ret = wc_Poly1305Final(&enc, tag);
  7161. if (ret != 0)
  7162. return WC_TEST_RET_ENC_I(i);
  7163. if (XMEMCMP(tag, tests[i], sizeof(tag)))
  7164. return WC_TEST_RET_ENC_I(i);
  7165. }
  7166. /* Check TLS MAC function from 2.8.2 https://tools.ietf.org/html/rfc7539 */
  7167. XMEMSET(tag, 0, sizeof(tag));
  7168. ret = wc_Poly1305SetKey(&enc, key4, sizeof(key4));
  7169. if (ret != 0)
  7170. return WC_TEST_RET_ENC_EC(ret);
  7171. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7172. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7173. if (ret != 0)
  7174. return WC_TEST_RET_ENC_EC(ret);
  7175. if (XMEMCMP(tag, correct4, sizeof(tag)))
  7176. return WC_TEST_RET_ENC_NC;
  7177. /* Check fail of TLS MAC function if altering additional data */
  7178. XMEMSET(tag, 0, sizeof(tag));
  7179. additional[0]++;
  7180. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7181. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7182. if (ret != 0)
  7183. return WC_TEST_RET_ENC_EC(ret);
  7184. if (XMEMCMP(tag, correct4, sizeof(tag)) == 0)
  7185. return WC_TEST_RET_ENC_NC;
  7186. return 0;
  7187. }
  7188. #endif /* HAVE_POLY1305 */
  7189. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  7190. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void)
  7191. {
  7192. /* Test #1 from Section 2.8.2 of draft-irtf-cfrg-chacha20-poly1305-10 */
  7193. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7194. WOLFSSL_SMALL_STACK_STATIC const byte key1[] = {
  7195. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  7196. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  7197. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  7198. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  7199. };
  7200. WOLFSSL_SMALL_STACK_STATIC const byte plaintext1[] = {
  7201. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  7202. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  7203. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  7204. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  7205. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  7206. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  7207. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  7208. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  7209. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  7210. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  7211. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  7212. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  7213. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  7214. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  7215. 0x74, 0x2e
  7216. };
  7217. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] = {
  7218. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  7219. 0x44, 0x45, 0x46, 0x47
  7220. };
  7221. WOLFSSL_SMALL_STACK_STATIC const byte aad1[] = { /* additional data */
  7222. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  7223. 0xc4, 0xc5, 0xc6, 0xc7
  7224. };
  7225. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] = { /* expected output from operation */
  7226. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  7227. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  7228. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  7229. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  7230. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  7231. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  7232. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  7233. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  7234. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  7235. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  7236. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  7237. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  7238. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  7239. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  7240. 0x61, 0x16
  7241. };
  7242. WOLFSSL_SMALL_STACK_STATIC const byte authTag1[] = { /* expected output from operation */
  7243. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  7244. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  7245. };
  7246. /* Test #2 from Appendix A.2 in draft-irtf-cfrg-chacha20-poly1305-10 */
  7247. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7248. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7249. 0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a,
  7250. 0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0,
  7251. 0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09,
  7252. 0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0
  7253. };
  7254. WOLFSSL_SMALL_STACK_STATIC const byte plaintext2[] = {
  7255. 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
  7256. 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20,
  7257. 0x61, 0x72, 0x65, 0x20, 0x64, 0x72, 0x61, 0x66,
  7258. 0x74, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7259. 0x6e, 0x74, 0x73, 0x20, 0x76, 0x61, 0x6c, 0x69,
  7260. 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20,
  7261. 0x6d, 0x61, 0x78, 0x69, 0x6d, 0x75, 0x6d, 0x20,
  7262. 0x6f, 0x66, 0x20, 0x73, 0x69, 0x78, 0x20, 0x6d,
  7263. 0x6f, 0x6e, 0x74, 0x68, 0x73, 0x20, 0x61, 0x6e,
  7264. 0x64, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65,
  7265. 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
  7266. 0x2c, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63,
  7267. 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f,
  7268. 0x62, 0x73, 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x64,
  7269. 0x20, 0x62, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65,
  7270. 0x72, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7271. 0x6e, 0x74, 0x73, 0x20, 0x61, 0x74, 0x20, 0x61,
  7272. 0x6e, 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x2e,
  7273. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69,
  7274. 0x6e, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72,
  7275. 0x69, 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20,
  7276. 0x75, 0x73, 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65,
  7277. 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61,
  7278. 0x66, 0x74, 0x73, 0x20, 0x61, 0x73, 0x20, 0x72,
  7279. 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
  7280. 0x20, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61,
  7281. 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x20,
  7282. 0x63, 0x69, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65,
  7283. 0x6d, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20,
  7284. 0x74, 0x68, 0x61, 0x6e, 0x20, 0x61, 0x73, 0x20,
  7285. 0x2f, 0xe2, 0x80, 0x9c, 0x77, 0x6f, 0x72, 0x6b,
  7286. 0x20, 0x69, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67,
  7287. 0x72, 0x65, 0x73, 0x73, 0x2e, 0x2f, 0xe2, 0x80,
  7288. 0x9d
  7289. };
  7290. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  7291. 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
  7292. 0x05, 0x06, 0x07, 0x08
  7293. };
  7294. WOLFSSL_SMALL_STACK_STATIC const byte aad2[] = { /* additional data */
  7295. 0xf3, 0x33, 0x88, 0x86, 0x00, 0x00, 0x00, 0x00,
  7296. 0x00, 0x00, 0x4e, 0x91
  7297. };
  7298. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] = { /* expected output from operation */
  7299. 0x64, 0xa0, 0x86, 0x15, 0x75, 0x86, 0x1a, 0xf4,
  7300. 0x60, 0xf0, 0x62, 0xc7, 0x9b, 0xe6, 0x43, 0xbd,
  7301. 0x5e, 0x80, 0x5c, 0xfd, 0x34, 0x5c, 0xf3, 0x89,
  7302. 0xf1, 0x08, 0x67, 0x0a, 0xc7, 0x6c, 0x8c, 0xb2,
  7303. 0x4c, 0x6c, 0xfc, 0x18, 0x75, 0x5d, 0x43, 0xee,
  7304. 0xa0, 0x9e, 0xe9, 0x4e, 0x38, 0x2d, 0x26, 0xb0,
  7305. 0xbd, 0xb7, 0xb7, 0x3c, 0x32, 0x1b, 0x01, 0x00,
  7306. 0xd4, 0xf0, 0x3b, 0x7f, 0x35, 0x58, 0x94, 0xcf,
  7307. 0x33, 0x2f, 0x83, 0x0e, 0x71, 0x0b, 0x97, 0xce,
  7308. 0x98, 0xc8, 0xa8, 0x4a, 0xbd, 0x0b, 0x94, 0x81,
  7309. 0x14, 0xad, 0x17, 0x6e, 0x00, 0x8d, 0x33, 0xbd,
  7310. 0x60, 0xf9, 0x82, 0xb1, 0xff, 0x37, 0xc8, 0x55,
  7311. 0x97, 0x97, 0xa0, 0x6e, 0xf4, 0xf0, 0xef, 0x61,
  7312. 0xc1, 0x86, 0x32, 0x4e, 0x2b, 0x35, 0x06, 0x38,
  7313. 0x36, 0x06, 0x90, 0x7b, 0x6a, 0x7c, 0x02, 0xb0,
  7314. 0xf9, 0xf6, 0x15, 0x7b, 0x53, 0xc8, 0x67, 0xe4,
  7315. 0xb9, 0x16, 0x6c, 0x76, 0x7b, 0x80, 0x4d, 0x46,
  7316. 0xa5, 0x9b, 0x52, 0x16, 0xcd, 0xe7, 0xa4, 0xe9,
  7317. 0x90, 0x40, 0xc5, 0xa4, 0x04, 0x33, 0x22, 0x5e,
  7318. 0xe2, 0x82, 0xa1, 0xb0, 0xa0, 0x6c, 0x52, 0x3e,
  7319. 0xaf, 0x45, 0x34, 0xd7, 0xf8, 0x3f, 0xa1, 0x15,
  7320. 0x5b, 0x00, 0x47, 0x71, 0x8c, 0xbc, 0x54, 0x6a,
  7321. 0x0d, 0x07, 0x2b, 0x04, 0xb3, 0x56, 0x4e, 0xea,
  7322. 0x1b, 0x42, 0x22, 0x73, 0xf5, 0x48, 0x27, 0x1a,
  7323. 0x0b, 0xb2, 0x31, 0x60, 0x53, 0xfa, 0x76, 0x99,
  7324. 0x19, 0x55, 0xeb, 0xd6, 0x31, 0x59, 0x43, 0x4e,
  7325. 0xce, 0xbb, 0x4e, 0x46, 0x6d, 0xae, 0x5a, 0x10,
  7326. 0x73, 0xa6, 0x72, 0x76, 0x27, 0x09, 0x7a, 0x10,
  7327. 0x49, 0xe6, 0x17, 0xd9, 0x1d, 0x36, 0x10, 0x94,
  7328. 0xfa, 0x68, 0xf0, 0xff, 0x77, 0x98, 0x71, 0x30,
  7329. 0x30, 0x5b, 0xea, 0xba, 0x2e, 0xda, 0x04, 0xdf,
  7330. 0x99, 0x7b, 0x71, 0x4d, 0x6c, 0x6f, 0x2c, 0x29,
  7331. 0xa6, 0xad, 0x5c, 0xb4, 0x02, 0x2b, 0x02, 0x70,
  7332. 0x9b
  7333. };
  7334. WOLFSSL_SMALL_STACK_STATIC const byte authTag2[] = { /* expected output from operation */
  7335. 0xee, 0xad, 0x9d, 0x67, 0x89, 0x0c, 0xbb, 0x22,
  7336. 0x39, 0x23, 0x36, 0xfe, 0xa1, 0x85, 0x1f, 0x38
  7337. };
  7338. byte generatedCiphertext[265]; /* max plaintext2/cipher2 */
  7339. byte generatedPlaintext[265]; /* max plaintext2/cipher2 */
  7340. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  7341. ChaChaPoly_Aead aead;
  7342. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  7343. #define TEST_SMALL_CHACHA_CHUNKS 32
  7344. #else
  7345. #define TEST_SMALL_CHACHA_CHUNKS 64
  7346. #endif
  7347. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7348. word32 testLen;
  7349. #endif
  7350. wc_test_ret_t err;
  7351. WOLFSSL_ENTER("chacha20_poly1305_aead_test");
  7352. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7353. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7354. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7355. /* Parameter Validation testing */
  7356. /* Encrypt */
  7357. err = wc_ChaCha20Poly1305_Encrypt(NULL, iv1, aad1, sizeof(aad1), plaintext1,
  7358. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7359. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7360. return WC_TEST_RET_ENC_EC(err);
  7361. err = wc_ChaCha20Poly1305_Encrypt(key1, NULL, aad1, sizeof(aad1),
  7362. plaintext1, sizeof(plaintext1), generatedCiphertext,
  7363. generatedAuthTag);
  7364. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7365. return WC_TEST_RET_ENC_EC(err);
  7366. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7367. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7368. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7369. return WC_TEST_RET_ENC_EC(err);
  7370. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7371. sizeof(plaintext1), NULL, generatedAuthTag);
  7372. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7373. return WC_TEST_RET_ENC_EC(err);
  7374. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7375. sizeof(plaintext1), generatedCiphertext, NULL);
  7376. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7377. return WC_TEST_RET_ENC_EC(err);
  7378. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7379. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7380. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7381. return WC_TEST_RET_ENC_EC(err);
  7382. /* Decrypt */
  7383. err = wc_ChaCha20Poly1305_Decrypt(NULL, iv2, aad2, sizeof(aad2), cipher2,
  7384. sizeof(cipher2), authTag2, generatedPlaintext);
  7385. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7386. return WC_TEST_RET_ENC_EC(err);
  7387. err = wc_ChaCha20Poly1305_Decrypt(key2, NULL, aad2, sizeof(aad2), cipher2,
  7388. sizeof(cipher2), authTag2, generatedPlaintext);
  7389. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7390. return WC_TEST_RET_ENC_EC(err);
  7391. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7392. sizeof(cipher2), authTag2, generatedPlaintext);
  7393. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7394. return WC_TEST_RET_ENC_EC(err);
  7395. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7396. sizeof(cipher2), NULL, generatedPlaintext);
  7397. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7398. return WC_TEST_RET_ENC_EC(err);
  7399. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7400. sizeof(cipher2), authTag2, NULL);
  7401. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7402. return WC_TEST_RET_ENC_EC(err);
  7403. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7404. sizeof(cipher2), authTag2, generatedPlaintext);
  7405. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7406. return WC_TEST_RET_ENC_EC(err);
  7407. /* Test #1 */
  7408. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1,
  7409. aad1, sizeof(aad1),
  7410. plaintext1, sizeof(plaintext1),
  7411. generatedCiphertext, generatedAuthTag);
  7412. if (err) {
  7413. return WC_TEST_RET_ENC_EC(err);
  7414. }
  7415. /* -- Check the ciphertext and authtag */
  7416. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7417. return WC_TEST_RET_ENC_NC;
  7418. }
  7419. if (XMEMCMP(generatedAuthTag, authTag1, sizeof(authTag1))) {
  7420. return WC_TEST_RET_ENC_NC;
  7421. }
  7422. /* -- Verify decryption works */
  7423. err = wc_ChaCha20Poly1305_Decrypt(key1, iv1,
  7424. aad1, sizeof(aad1),
  7425. cipher1, sizeof(cipher1),
  7426. authTag1, generatedPlaintext);
  7427. if (err) {
  7428. return err;
  7429. }
  7430. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7431. return WC_TEST_RET_ENC_NC;
  7432. }
  7433. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7434. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7435. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7436. /* Test #2 */
  7437. err = wc_ChaCha20Poly1305_Encrypt(key2, iv2,
  7438. aad2, sizeof(aad2),
  7439. plaintext2, sizeof(plaintext2),
  7440. generatedCiphertext, generatedAuthTag);
  7441. if (err) {
  7442. return err;
  7443. }
  7444. /* -- Check the ciphertext and authtag */
  7445. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7446. return WC_TEST_RET_ENC_NC;
  7447. }
  7448. if (XMEMCMP(generatedAuthTag, authTag2, sizeof(authTag2))) {
  7449. return WC_TEST_RET_ENC_NC;
  7450. }
  7451. /* -- Verify decryption works */
  7452. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2,
  7453. aad2, sizeof(aad2),
  7454. cipher2, sizeof(cipher2),
  7455. authTag2, generatedPlaintext);
  7456. if (err) {
  7457. return err;
  7458. }
  7459. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7460. return WC_TEST_RET_ENC_NC;
  7461. }
  7462. /* AEAD init/update/final - bad argument tests */
  7463. err = wc_ChaCha20Poly1305_Init(NULL, key1, iv1,
  7464. CHACHA20_POLY1305_AEAD_DECRYPT);
  7465. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7466. return WC_TEST_RET_ENC_EC(err);
  7467. err = wc_ChaCha20Poly1305_Init(&aead, NULL, iv1,
  7468. CHACHA20_POLY1305_AEAD_DECRYPT);
  7469. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7470. return WC_TEST_RET_ENC_EC(err);
  7471. err = wc_ChaCha20Poly1305_Init(&aead, key1, NULL,
  7472. CHACHA20_POLY1305_AEAD_DECRYPT);
  7473. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7474. return WC_TEST_RET_ENC_EC(err);
  7475. err = wc_ChaCha20Poly1305_UpdateAad(NULL, aad1, sizeof(aad1));
  7476. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7477. return WC_TEST_RET_ENC_EC(err);
  7478. err = wc_ChaCha20Poly1305_UpdateAad(&aead, NULL, sizeof(aad1));
  7479. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7480. return WC_TEST_RET_ENC_EC(err);
  7481. err = wc_ChaCha20Poly1305_UpdateData(NULL, generatedPlaintext,
  7482. generatedPlaintext, sizeof(plaintext1));
  7483. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7484. return WC_TEST_RET_ENC_EC(err);
  7485. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext, NULL,
  7486. sizeof(plaintext1));
  7487. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7488. return WC_TEST_RET_ENC_EC(err);
  7489. err = wc_ChaCha20Poly1305_UpdateData(&aead, NULL, generatedPlaintext,
  7490. sizeof(plaintext1));
  7491. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7492. return WC_TEST_RET_ENC_EC(err);
  7493. err = wc_ChaCha20Poly1305_Final(NULL, generatedAuthTag);
  7494. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7495. return WC_TEST_RET_ENC_EC(err);
  7496. err = wc_ChaCha20Poly1305_Final(&aead, NULL);
  7497. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7498. return WC_TEST_RET_ENC_EC(err);
  7499. /* AEAD init/update/final - bad state tests */
  7500. /* clear struct - make valgrind happy to resolve
  7501. "Conditional jump or move depends on uninitialised value(s)".
  7502. The enum is "int" size and aead.state is "byte" */
  7503. /* The wc_ChaCha20Poly1305_Init function does this normally */
  7504. XMEMSET(&aead, 0, sizeof(aead));
  7505. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7506. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7507. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7508. return WC_TEST_RET_ENC_EC(err);
  7509. aead.state = CHACHA20_POLY1305_STATE_DATA;
  7510. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7511. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7512. return WC_TEST_RET_ENC_EC(err);
  7513. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7514. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext,
  7515. generatedPlaintext, sizeof(plaintext1));
  7516. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7517. return WC_TEST_RET_ENC_EC(err);
  7518. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7519. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7520. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7521. return WC_TEST_RET_ENC_EC(err);
  7522. aead.state = CHACHA20_POLY1305_STATE_READY;
  7523. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7524. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7525. return WC_TEST_RET_ENC_EC(err);
  7526. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7527. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7528. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7529. /* Test 1 - Encrypt */
  7530. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7531. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7532. if (err != 0)
  7533. return WC_TEST_RET_ENC_EC(err);
  7534. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7535. if (err != 0)
  7536. return WC_TEST_RET_ENC_EC(err);
  7537. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7538. /* test doing data in smaller chunks */
  7539. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7540. word32 dataLen = sizeof(plaintext1) - testLen;
  7541. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7542. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7543. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext1[testLen],
  7544. &generatedCiphertext[testLen], dataLen);
  7545. if (err != 0)
  7546. return WC_TEST_RET_ENC_EC(err);
  7547. testLen += dataLen;
  7548. }
  7549. #else
  7550. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext1,
  7551. generatedCiphertext, sizeof(plaintext1));
  7552. #endif
  7553. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7554. if (err != 0)
  7555. return WC_TEST_RET_ENC_EC(err);
  7556. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7557. if (err != 0)
  7558. return WC_TEST_RET_ENC_EC(err);
  7559. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7560. return WC_TEST_RET_ENC_NC;
  7561. }
  7562. /* Test 1 - Decrypt */
  7563. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7564. CHACHA20_POLY1305_AEAD_DECRYPT);
  7565. if (err != 0)
  7566. return WC_TEST_RET_ENC_EC(err);
  7567. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7568. if (err != 0)
  7569. return WC_TEST_RET_ENC_EC(err);
  7570. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7571. /* test doing data in smaller chunks */
  7572. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7573. word32 dataLen = sizeof(plaintext1) - testLen;
  7574. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7575. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7576. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7577. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7578. dataLen);
  7579. if (err != 0)
  7580. return WC_TEST_RET_ENC_EC(err);
  7581. testLen += dataLen;
  7582. }
  7583. #else
  7584. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7585. generatedPlaintext, sizeof(cipher1));
  7586. #endif
  7587. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7588. if (err != 0)
  7589. return WC_TEST_RET_ENC_EC(err);
  7590. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7591. if (err != 0)
  7592. return WC_TEST_RET_ENC_EC(err);
  7593. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7594. return WC_TEST_RET_ENC_NC;
  7595. }
  7596. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7597. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7598. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7599. /* Test 2 - Encrypt */
  7600. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7601. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7602. if (err != 0)
  7603. return WC_TEST_RET_ENC_EC(err);
  7604. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7605. if (err != 0)
  7606. return WC_TEST_RET_ENC_EC(err);
  7607. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7608. /* test doing data in smaller chunks */
  7609. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7610. word32 dataLen = sizeof(plaintext2) - testLen;
  7611. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7612. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7613. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext2[testLen],
  7614. &generatedCiphertext[testLen], dataLen);
  7615. if (err != 0)
  7616. return WC_TEST_RET_ENC_EC(err);
  7617. testLen += dataLen;
  7618. }
  7619. #else
  7620. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext2, generatedCiphertext,
  7621. sizeof(plaintext2));
  7622. #endif
  7623. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7624. if (err != 0)
  7625. return WC_TEST_RET_ENC_EC(err);
  7626. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7627. if (err != 0)
  7628. return WC_TEST_RET_ENC_EC(err);
  7629. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7630. return WC_TEST_RET_ENC_NC;
  7631. }
  7632. /* Test 2 - Decrypt */
  7633. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7634. CHACHA20_POLY1305_AEAD_DECRYPT);
  7635. if (err != 0)
  7636. return WC_TEST_RET_ENC_EC(err);
  7637. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7638. if (err != 0)
  7639. return WC_TEST_RET_ENC_EC(err);
  7640. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7641. /* test doing data in smaller chunks */
  7642. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7643. word32 dataLen = sizeof(plaintext2) - testLen;
  7644. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7645. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7646. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7647. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7648. dataLen);
  7649. if (err != 0)
  7650. return WC_TEST_RET_ENC_EC(err);
  7651. testLen += dataLen;
  7652. }
  7653. #else
  7654. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7655. generatedPlaintext, sizeof(cipher2));
  7656. #endif
  7657. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7658. if (err != 0)
  7659. return WC_TEST_RET_ENC_EC(err);
  7660. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7661. if (err != 0)
  7662. return WC_TEST_RET_ENC_EC(err);
  7663. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7664. return WC_TEST_RET_ENC_NC;
  7665. }
  7666. return err;
  7667. }
  7668. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  7669. #ifndef NO_DES3
  7670. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void)
  7671. {
  7672. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  7673. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7674. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7675. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7676. };
  7677. byte plain[24];
  7678. byte cipher[24];
  7679. Des enc;
  7680. Des dec;
  7681. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  7682. {
  7683. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  7684. };
  7685. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  7686. {
  7687. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  7688. };
  7689. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  7690. {
  7691. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  7692. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  7693. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  7694. };
  7695. #ifdef WOLFSSL_DES_ECB
  7696. /* "Stay strong and move on!"" */
  7697. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7698. {
  7699. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7700. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7701. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7702. };
  7703. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb[] =
  7704. {
  7705. 0x70,0x4F,0x20,0xF6,0x72,0xB4,0xD0,0x2A,
  7706. 0xB5,0xA9,0x94,0x9F,0x11,0xCF,0x87,0xED,
  7707. 0x13,0x33,0x82,0xCB,0x8B,0xF1,0x82,0x56
  7708. };
  7709. /* "Lemmings" */
  7710. WOLFSSL_SMALL_STACK_STATIC const byte key_ecb[] =
  7711. {
  7712. 0x4C,0x65,0x6D,0x6D,0x69,0x6E,0x67,0x73
  7713. };
  7714. #endif /* WOLFSSL_DES_ECB */
  7715. wc_test_ret_t ret;
  7716. WOLFSSL_ENTER("des_test");
  7717. ret = wc_Des_SetKey(&enc, key, iv, DES_ENCRYPTION);
  7718. if (ret != 0)
  7719. return WC_TEST_RET_ENC_EC(ret);
  7720. ret = wc_Des_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7721. if (ret != 0)
  7722. return WC_TEST_RET_ENC_EC(ret);
  7723. ret = wc_Des_SetKey(&dec, key, iv, DES_DECRYPTION);
  7724. if (ret != 0)
  7725. return WC_TEST_RET_ENC_EC(ret);
  7726. ret = wc_Des_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7727. if (ret != 0)
  7728. return WC_TEST_RET_ENC_EC(ret);
  7729. if (XMEMCMP(plain, vector, sizeof(plain)))
  7730. return WC_TEST_RET_ENC_NC;
  7731. if (XMEMCMP(cipher, verify, sizeof(cipher)))
  7732. return WC_TEST_RET_ENC_NC;
  7733. ret = wc_Des_CbcEncryptWithKey(cipher, vector, sizeof(vector), key, iv);
  7734. if (ret != 0)
  7735. return WC_TEST_RET_ENC_EC(ret);
  7736. /* Test basic ECB Process for DES*/
  7737. #ifdef WOLFSSL_DES_ECB
  7738. ret = wc_Des_SetKey(&enc, key_ecb, iv, DES_ENCRYPTION);
  7739. if (ret != 0)
  7740. return WC_TEST_RET_ENC_EC(ret);
  7741. ret = wc_Des_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector));
  7742. if (ret != 0)
  7743. return WC_TEST_RET_ENC_EC(ret);
  7744. ret = wc_Des_SetKey(&dec, key_ecb, iv, DES_DECRYPTION);
  7745. if (ret != 0)
  7746. return WC_TEST_RET_ENC_EC(ret);
  7747. ret = wc_Des_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  7748. if (ret != 0)
  7749. return WC_TEST_RET_ENC_EC(ret);
  7750. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  7751. return WC_TEST_RET_ENC_NC;
  7752. if (XMEMCMP(cipher, verify_ecb, sizeof(cipher)))
  7753. return WC_TEST_RET_ENC_NC;
  7754. #endif /* WOLFSSL_DES_ECB */
  7755. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  7756. {
  7757. EncryptedInfo info;
  7758. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  7759. XMEMCPY(info.iv, iv, sizeof(iv));
  7760. info.ivSz = sizeof(iv);
  7761. info.keySz = sizeof(key);
  7762. info.cipherType = WC_CIPHER_DES;
  7763. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7764. sizeof(key), WC_HASH_TYPE_SHA);
  7765. if (ret != 0)
  7766. return WC_TEST_RET_ENC_EC(ret);
  7767. /* Test invalid info ptr */
  7768. ret = wc_BufferKeyEncrypt(NULL, cipher, sizeof(cipher), key,
  7769. sizeof(key), WC_HASH_TYPE_SHA);
  7770. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7771. return WC_TEST_RET_ENC_EC(ret);
  7772. #ifndef NO_PWDBASED
  7773. /* Test invalid hash type - only applies to wc_PBKDF1 call */
  7774. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7775. sizeof(key), WC_HASH_TYPE_NONE);
  7776. if (ret == 0)
  7777. return WC_TEST_RET_ENC_EC(ret);
  7778. #endif /* !NO_PWDBASED */
  7779. }
  7780. #endif
  7781. return 0;
  7782. }
  7783. #endif /* !NO_DES3 */
  7784. #ifndef NO_DES3
  7785. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void)
  7786. {
  7787. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  7788. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7789. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7790. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7791. };
  7792. byte plain[24];
  7793. byte cipher[24];
  7794. Des3 enc;
  7795. Des3 dec;
  7796. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  7797. {
  7798. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  7799. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  7800. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  7801. };
  7802. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  7803. {
  7804. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  7805. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  7806. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  7807. };
  7808. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] =
  7809. {
  7810. 0x43,0xa0,0x29,0x7e,0xd1,0x84,0xf8,0x0e,
  7811. 0x89,0x64,0x84,0x32,0x12,0xd5,0x08,0x98,
  7812. 0x18,0x94,0x15,0x74,0x87,0x12,0x7d,0xb0
  7813. };
  7814. #ifdef WOLFSSL_DES_ECB
  7815. /* Stay strong and move on! */
  7816. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7817. {
  7818. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7819. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7820. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7821. };
  7822. WOLFSSL_SMALL_STACK_STATIC const byte verify3_ecb[] =
  7823. {
  7824. 0x45,0x7E,0xFA,0xA1,0x05,0xDD,0x48,0x86,
  7825. 0x4D,0xB2,0xAB,0xE4,0xF9,0x63,0xD6,0x54,
  7826. 0x7C,0x5A,0xB3,0x67,0x32,0x25,0x67,0x3D
  7827. };
  7828. /* "Life is what you make it" */
  7829. WOLFSSL_SMALL_STACK_STATIC const byte key3_ecb[] =
  7830. {
  7831. 0x4C,0x69,0x66,0x65,0x20,0x69,0x73,0x20,
  7832. 0x77,0x68,0x61,0x74,0x20,0x79,0x6F,0x75,
  7833. 0x20,0x6D,0x61,0x6B,0x65,0x20,0x69,0x74
  7834. };
  7835. #endif /* WOLFSSL_DES_ECB */
  7836. wc_test_ret_t ret;
  7837. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  7838. size_t i;
  7839. #endif
  7840. WOLFSSL_ENTER("des3_test");
  7841. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7842. if (ret != 0)
  7843. return WC_TEST_RET_ENC_EC(ret);
  7844. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7845. if (ret != 0)
  7846. return WC_TEST_RET_ENC_EC(ret);
  7847. ret = wc_Des3_SetKey(&enc, key3, iv3, DES_ENCRYPTION);
  7848. if (ret != 0)
  7849. return WC_TEST_RET_ENC_EC(ret);
  7850. ret = wc_Des3_SetKey(&dec, key3, iv3, DES_DECRYPTION);
  7851. if (ret != 0)
  7852. return WC_TEST_RET_ENC_EC(ret);
  7853. ret = wc_Des3_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7854. #if defined(WOLFSSL_ASYNC_CRYPT)
  7855. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  7856. #endif
  7857. if (ret != 0)
  7858. return WC_TEST_RET_ENC_EC(ret);
  7859. ret = wc_Des3_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7860. #if defined(WOLFSSL_ASYNC_CRYPT)
  7861. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  7862. #endif
  7863. if (ret != 0)
  7864. return WC_TEST_RET_ENC_EC(ret);
  7865. if (XMEMCMP(plain, vector, sizeof(plain)))
  7866. return WC_TEST_RET_ENC_NC;
  7867. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  7868. return WC_TEST_RET_ENC_NC;
  7869. /* Test basic ECB Process for DES3*/
  7870. #ifdef WOLFSSL_DES_ECB
  7871. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7872. if (ret != 0)
  7873. return WC_TEST_RET_ENC_EC(ret);
  7874. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7875. if (ret != 0)
  7876. return WC_TEST_RET_ENC_EC(ret);
  7877. ret = wc_Des3_SetKey(&enc, key3_ecb, NULL, DES_ENCRYPTION);
  7878. if (ret != 0)
  7879. return WC_TEST_RET_ENC_EC(ret);
  7880. ret = wc_Des3_SetKey(&dec, key3_ecb, NULL, DES_DECRYPTION);
  7881. if (ret != 0)
  7882. return WC_TEST_RET_ENC_EC(ret);
  7883. ret = wc_Des3_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector_ecb));
  7884. #if defined(WOLFSSL_ASYNC_CRYPT)
  7885. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  7886. #endif
  7887. if (ret != 0)
  7888. return WC_TEST_RET_ENC_EC(ret);
  7889. ret = wc_Des3_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  7890. #if defined(WOLFSSL_ASYNC_CRYPT)
  7891. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  7892. #endif
  7893. if (ret != 0)
  7894. return WC_TEST_RET_ENC_EC(ret);
  7895. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  7896. return WC_TEST_RET_ENC_NC;
  7897. if (XMEMCMP(cipher, verify3_ecb, sizeof(cipher)))
  7898. return WC_TEST_RET_ENC_NC;
  7899. #endif /* WOLFSSL_DES_ECB */
  7900. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  7901. /* test the same vectors with using compatibility layer */
  7902. for (i = 0; i < sizeof(vector); i += DES_BLOCK_SIZE){
  7903. DES_key_schedule ks1;
  7904. DES_key_schedule ks2;
  7905. DES_key_schedule ks3;
  7906. DES_cblock iv4;
  7907. byte tmp[sizeof(vector)];
  7908. XMEMCPY(ks1, key3, sizeof(DES_key_schedule));
  7909. XMEMCPY(ks2, key3 + 8, sizeof(DES_key_schedule));
  7910. XMEMCPY(ks3, key3 + 16, sizeof(DES_key_schedule));
  7911. XMEMSET(plain, 0, sizeof(plain));
  7912. XMEMSET(cipher, 0, sizeof(cipher));
  7913. /* Test in-place encrypt/decrypt */
  7914. XMEMCPY(tmp, vector, sizeof(vector));
  7915. /* Use i as the splitter */
  7916. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  7917. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  7918. &iv4, DES_ENCRYPT);
  7919. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(vector) - i),
  7920. &ks1, &ks2, &ks3, &iv4, DES_ENCRYPT);
  7921. XMEMCPY(cipher, tmp, sizeof(cipher));
  7922. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  7923. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  7924. &iv4, DES_DECRYPT);
  7925. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(cipher) - i),
  7926. &ks1, &ks2, &ks3, &iv4, DES_DECRYPT);
  7927. XMEMCPY(plain, tmp, sizeof(plain));
  7928. if (XMEMCMP(plain, vector, sizeof(plain)))
  7929. return WC_TEST_RET_ENC_NC;
  7930. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  7931. return WC_TEST_RET_ENC_NC;
  7932. }
  7933. #endif /* OPENSSL_EXTRA */
  7934. wc_Des3Free(&enc);
  7935. wc_Des3Free(&dec);
  7936. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  7937. {
  7938. EncryptedInfo info;
  7939. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  7940. XMEMCPY(info.iv, iv3, sizeof(iv3));
  7941. info.ivSz = sizeof(iv3);
  7942. info.keySz = sizeof(key3);
  7943. info.cipherType = WC_CIPHER_DES3;
  7944. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key3,
  7945. sizeof(key3), WC_HASH_TYPE_SHA);
  7946. if (ret != 0)
  7947. return WC_TEST_RET_ENC_EC(ret);
  7948. }
  7949. #endif
  7950. return 0;
  7951. }
  7952. #endif /* NO_DES3 */
  7953. static const int fiducial1 = WC_TEST_RET_LN; /* source code reference point --
  7954. * see print_fiducials() below.
  7955. */
  7956. #ifndef NO_AES
  7957. #if defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_CFB) || \
  7958. defined(WOLFSSL_AES_XTS)
  7959. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  7960. && !defined(HAVE_SELFTEST)
  7961. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  7962. /* pass in the function, key, iv, plain text and expected and this function
  7963. * tests that the encryption and decryption is successful */
  7964. static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
  7965. const byte* iv, const byte* plain, int plainSz,
  7966. const byte* expected, int expectedSz)
  7967. {
  7968. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  7969. EVP_CIPHER_CTX *ctx = NULL;
  7970. #else
  7971. EVP_CIPHER_CTX ctx[1];
  7972. #endif
  7973. int ctx_inited = 0;
  7974. int idx, cipherSz;
  7975. wc_test_ret_t ret = 0;
  7976. byte* cipher;
  7977. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  7978. if ((ctx = wolfSSL_EVP_CIPHER_CTX_new()) == NULL)
  7979. return MEMORY_E;
  7980. #endif
  7981. cipher = (byte*)XMALLOC(plainSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7982. if (cipher == NULL) {
  7983. ret = WC_TEST_RET_ENC_ERRNO;
  7984. goto EVP_TEST_END;
  7985. }
  7986. /* test encrypt */
  7987. EVP_CIPHER_CTX_init(ctx);
  7988. ctx_inited = 1;
  7989. if (EVP_CipherInit(ctx, type, key, iv, 1) == 0) {
  7990. ret = WC_TEST_RET_ENC_NC;
  7991. goto EVP_TEST_END;
  7992. }
  7993. if (EVP_CipherUpdate(ctx, cipher, &idx, plain, expectedSz) == 0) {
  7994. ret = WC_TEST_RET_ENC_NC;
  7995. goto EVP_TEST_END;
  7996. }
  7997. cipherSz = idx;
  7998. if (EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  7999. ret = WC_TEST_RET_ENC_NC;
  8000. goto EVP_TEST_END;
  8001. }
  8002. cipherSz += idx;
  8003. if (XMEMCMP(cipher, expected, plainSz)) {
  8004. ret = WC_TEST_RET_ENC_NC;
  8005. goto EVP_TEST_END;
  8006. }
  8007. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8008. ctx_inited = 0;
  8009. if (ret == WOLFSSL_SUCCESS)
  8010. ret = 0;
  8011. else {
  8012. ret = WC_TEST_RET_ENC_NC;
  8013. goto EVP_TEST_END;
  8014. }
  8015. /* test decrypt */
  8016. EVP_CIPHER_CTX_init(ctx);
  8017. ctx_inited = 1;
  8018. if (EVP_CipherInit(ctx, type, key, iv, 0) == 0) {
  8019. ret = WC_TEST_RET_ENC_NC;
  8020. goto EVP_TEST_END;
  8021. }
  8022. if (EVP_CipherUpdate(ctx, cipher, &idx, cipher, expectedSz) == 0) {
  8023. ret = WC_TEST_RET_ENC_NC;
  8024. goto EVP_TEST_END;
  8025. }
  8026. cipherSz = idx;
  8027. if (EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  8028. ret = WC_TEST_RET_ENC_NC;
  8029. goto EVP_TEST_END;
  8030. }
  8031. cipherSz += idx;
  8032. if ((expectedSz != cipherSz) || XMEMCMP(plain, cipher, plainSz)) {
  8033. ret = WC_TEST_RET_ENC_NC;
  8034. goto EVP_TEST_END;
  8035. }
  8036. EVP_TEST_END:
  8037. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8038. (void)cipherSz;
  8039. if (ctx_inited) {
  8040. int cleanup_ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8041. if (cleanup_ret != WOLFSSL_SUCCESS)
  8042. ret = WC_TEST_RET_ENC_NC;
  8043. }
  8044. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8045. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  8046. #endif
  8047. return ret;
  8048. }
  8049. #endif /* !HAVE_FIPS || FIPS_VERSION3_GE(6,0,0) */
  8050. #endif /* OPENSSL_EXTRA && !WOLFCRYPT_ONLY && !HAVE_SELFTEST */
  8051. #endif /* WOLFSSL_AES_OFB || WOLFSSL_AES_CFB */
  8052. #ifdef WOLFSSL_AES_OFB
  8053. /* test vector from https://csrc.nist.gov/Projects/cryptographic-algorithm-validation-program/Block-Ciphers */
  8054. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void)
  8055. {
  8056. #ifdef WOLFSSL_AES_256
  8057. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8058. {
  8059. 0xc4,0xc7,0xfa,0xd6,0x53,0x5c,0xb8,0x71,
  8060. 0x4a,0x5c,0x40,0x77,0x9a,0x8b,0xa1,0xd2,
  8061. 0x53,0x3e,0x23,0xb4,0xb2,0x58,0x73,0x2a,
  8062. 0x5b,0x78,0x01,0xf4,0xe3,0x71,0xa7,0x94
  8063. };
  8064. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  8065. {
  8066. 0x5e,0xb9,0x33,0x13,0xb8,0x71,0xff,0x16,
  8067. 0xb9,0x8a,0x9b,0xcb,0x43,0x33,0x0d,0x6f
  8068. };
  8069. WOLFSSL_SMALL_STACK_STATIC const byte plain1[] =
  8070. {
  8071. 0x6d,0x0b,0xb0,0x79,0x63,0x84,0x71,0xe9,
  8072. 0x39,0xd4,0x53,0x14,0x86,0xc1,0x4c,0x25,
  8073. 0x9a,0xee,0xc6,0xf3,0xc0,0x0d,0xfd,0xd6,
  8074. 0xc0,0x50,0xa8,0xba,0xa8,0x20,0xdb,0x71,
  8075. 0xcc,0x12,0x2c,0x4e,0x0c,0x17,0x15,0xef,
  8076. 0x55,0xf3,0x99,0x5a,0x6b,0xf0,0x2a,0x4c
  8077. };
  8078. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8079. {
  8080. 0x0f,0x54,0x61,0x71,0x59,0xd0,0x3f,0xfc,
  8081. 0x1b,0xfa,0xfb,0x60,0x29,0x30,0xd7,0x00,
  8082. 0xf4,0xa4,0xa8,0xe6,0xdd,0x93,0x94,0x46,
  8083. 0x64,0xd2,0x19,0xc4,0xc5,0x4d,0xde,0x1b,
  8084. 0x04,0x53,0xe1,0x73,0xf5,0x18,0x74,0xae,
  8085. 0xfd,0x64,0xa2,0xe1,0xe2,0x76,0x13,0xb0
  8086. };
  8087. #endif /* WOLFSSL_AES_256 */
  8088. #ifdef WOLFSSL_AES_128
  8089. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8090. {
  8091. 0x10,0xa5,0x88,0x69,0xd7,0x4b,0xe5,0xa3,
  8092. 0x74,0xcf,0x86,0x7c,0xfb,0x47,0x38,0x59
  8093. };
  8094. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  8095. {
  8096. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8097. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8098. };
  8099. WOLFSSL_SMALL_STACK_STATIC const byte plain2[] =
  8100. {
  8101. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8102. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8103. };
  8104. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8105. {
  8106. 0x6d,0x25,0x1e,0x69,0x44,0xb0,0x51,0xe0,
  8107. 0x4e,0xaa,0x6f,0xb4,0xdb,0xf7,0x84,0x65
  8108. };
  8109. #endif /* WOLFSSL_AES_128 */
  8110. #ifdef WOLFSSL_AES_192
  8111. WOLFSSL_SMALL_STACK_STATIC const byte key3[] = {
  8112. 0xd0,0x77,0xa0,0x3b,0xd8,0xa3,0x89,0x73,
  8113. 0x92,0x8c,0xca,0xfe,0x4a,0x9d,0x2f,0x45,
  8114. 0x51,0x30,0xbd,0x0a,0xf5,0xae,0x46,0xa9
  8115. };
  8116. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  8117. {
  8118. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8119. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8120. };
  8121. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8122. {
  8123. 0xab,0xc7,0x86,0xfb,0x1e,0xdb,0x50,0x45,
  8124. 0x80,0xc4,0xd8,0x82,0xef,0x29,0xa0,0xc7
  8125. };
  8126. WOLFSSL_SMALL_STACK_STATIC const byte plain3[] =
  8127. {
  8128. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8129. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8130. };
  8131. #endif /* WOLFSSL_AES_192 */
  8132. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8133. Aes *enc = NULL;
  8134. #else
  8135. Aes enc[1];
  8136. #endif
  8137. byte cipher[AES_BLOCK_SIZE * 4];
  8138. #ifdef HAVE_AES_DECRYPT
  8139. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8140. Aes *dec = NULL;
  8141. #else
  8142. Aes dec[1];
  8143. #endif
  8144. byte plain [AES_BLOCK_SIZE * 4];
  8145. #endif
  8146. wc_test_ret_t ret = 0;
  8147. WOLFSSL_ENTER("aesofb_test");
  8148. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8149. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8150. ERROR_OUT(-1, out);
  8151. #ifdef HAVE_AES_DECRYPT
  8152. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8153. ERROR_OUT(-1, out);
  8154. #endif
  8155. #endif
  8156. XMEMSET(enc, 0, sizeof *enc);
  8157. #ifdef HAVE_AES_DECRYPT
  8158. XMEMSET(dec, 0, sizeof *dec);
  8159. #endif
  8160. #ifdef WOLFSSL_AES_128
  8161. /* 128 key size test */
  8162. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8163. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8164. ret = EVP_test(EVP_aes_128_ofb(), key2, iv2, plain2, sizeof(plain2),
  8165. cipher2, sizeof(cipher2));
  8166. if (ret != 0) {
  8167. goto out;
  8168. }
  8169. #endif
  8170. ret = wc_AesInit(enc, HEAP_HINT, INVALID_DEVID);
  8171. if (ret != 0)
  8172. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8173. #ifdef HAVE_AES_DECRYPT
  8174. ret = wc_AesInit(dec, HEAP_HINT, INVALID_DEVID);
  8175. if (ret != 0)
  8176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8177. #endif
  8178. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8179. if (ret != 0)
  8180. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8181. #ifdef HAVE_AES_DECRYPT
  8182. /* decrypt uses AES_ENCRYPTION */
  8183. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8184. if (ret != 0)
  8185. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8186. #endif
  8187. XMEMSET(cipher, 0, sizeof(cipher));
  8188. ret = wc_AesOfbEncrypt(enc, cipher, plain2, AES_BLOCK_SIZE);
  8189. if (ret != 0)
  8190. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8191. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE))
  8192. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8193. #ifdef HAVE_AES_DECRYPT
  8194. ret = wc_AesOfbDecrypt(dec, plain, cipher2, AES_BLOCK_SIZE);
  8195. if (ret != 0)
  8196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8197. if (XMEMCMP(plain, plain2, AES_BLOCK_SIZE))
  8198. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8199. #endif /* HAVE_AES_DECRYPT */
  8200. #endif /* WOLFSSL_AES_128 */
  8201. #ifdef WOLFSSL_AES_192
  8202. /* 192 key size test */
  8203. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8204. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8205. ret = EVP_test(EVP_aes_192_ofb(), key3, iv3, plain3, sizeof(plain3),
  8206. cipher3, sizeof(cipher3));
  8207. if (ret != 0) {
  8208. goto out;
  8209. }
  8210. #endif
  8211. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8212. if (ret != 0)
  8213. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8214. #ifdef HAVE_AES_DECRYPT
  8215. /* decrypt uses AES_ENCRYPTION */
  8216. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8217. if (ret != 0)
  8218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8219. #endif
  8220. XMEMSET(cipher, 0, sizeof(cipher));
  8221. ret = wc_AesOfbEncrypt(enc, cipher, plain3, AES_BLOCK_SIZE);
  8222. if (ret != 0)
  8223. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8224. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE))
  8225. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8226. #ifdef HAVE_AES_DECRYPT
  8227. ret = wc_AesOfbDecrypt(dec, plain, cipher3, AES_BLOCK_SIZE);
  8228. if (ret != 0)
  8229. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8230. if (XMEMCMP(plain, plain3, AES_BLOCK_SIZE))
  8231. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8232. #endif /* HAVE_AES_DECRYPT */
  8233. #endif /* WOLFSSL_AES_192 */
  8234. #ifdef WOLFSSL_AES_256
  8235. /* 256 key size test */
  8236. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8237. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8238. ret = EVP_test(EVP_aes_256_ofb(), key1, iv1, plain1, sizeof(plain1),
  8239. cipher1, sizeof(cipher1));
  8240. if (ret != 0) {
  8241. goto out;
  8242. }
  8243. #endif
  8244. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8245. if (ret != 0)
  8246. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8247. #ifdef HAVE_AES_DECRYPT
  8248. /* decrypt uses AES_ENCRYPTION */
  8249. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8250. if (ret != 0)
  8251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8252. #endif
  8253. XMEMSET(cipher, 0, sizeof(cipher));
  8254. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE);
  8255. if (ret != 0)
  8256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8257. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE))
  8258. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8259. ret = wc_AesOfbEncrypt(enc, cipher + AES_BLOCK_SIZE,
  8260. plain1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8261. if (ret != 0)
  8262. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8263. if (XMEMCMP(cipher + AES_BLOCK_SIZE, cipher1 + AES_BLOCK_SIZE,
  8264. AES_BLOCK_SIZE))
  8265. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8266. #ifdef HAVE_AES_DECRYPT
  8267. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE);
  8268. if (ret != 0)
  8269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8270. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE))
  8271. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8272. ret = wc_AesOfbDecrypt(dec, plain + AES_BLOCK_SIZE,
  8273. cipher1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8274. if (ret != 0)
  8275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8276. if (XMEMCMP(plain + AES_BLOCK_SIZE, plain1 + AES_BLOCK_SIZE,
  8277. AES_BLOCK_SIZE))
  8278. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8279. #endif /* HAVE_AES_DECRYPT */
  8280. /* multiple blocks at once */
  8281. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8282. if (ret != 0)
  8283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8284. #ifdef HAVE_AES_DECRYPT
  8285. /* decrypt uses AES_ENCRYPTION */
  8286. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8287. if (ret != 0)
  8288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8289. #endif
  8290. XMEMSET(cipher, 0, sizeof(cipher));
  8291. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE * 3);
  8292. if (ret != 0)
  8293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8294. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 3))
  8295. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8296. #ifdef HAVE_AES_DECRYPT
  8297. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE * 3);
  8298. if (ret != 0)
  8299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8300. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE * 3))
  8301. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8302. #endif /* HAVE_AES_DECRYPT */
  8303. /* inline decrypt/encrypt*/
  8304. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8305. if (ret != 0)
  8306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8307. #ifdef HAVE_AES_DECRYPT
  8308. /* decrypt uses AES_ENCRYPTION */
  8309. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8310. if (ret != 0)
  8311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8312. #endif
  8313. XMEMCPY(cipher, plain1, AES_BLOCK_SIZE * 2);
  8314. ret = wc_AesOfbEncrypt(enc, cipher, cipher, AES_BLOCK_SIZE * 2);
  8315. if (ret != 0)
  8316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8317. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8318. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8319. #ifdef HAVE_AES_DECRYPT
  8320. ret = wc_AesOfbDecrypt(dec, cipher, cipher, AES_BLOCK_SIZE * 2);
  8321. if (ret != 0)
  8322. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8323. if (XMEMCMP(cipher, plain1, AES_BLOCK_SIZE * 2))
  8324. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8325. #endif /* HAVE_AES_DECRYPT */
  8326. /* 256 key size test leftover support */
  8327. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8328. if (ret != 0)
  8329. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8330. #ifdef HAVE_AES_DECRYPT
  8331. /* decrypt uses AES_ENCRYPTION */
  8332. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8333. if (ret != 0)
  8334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8335. #endif
  8336. XMEMSET(cipher, 0, sizeof(cipher));
  8337. ret = wc_AesOfbEncrypt(enc, cipher, plain1, 3);
  8338. if (ret != 0)
  8339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8340. if (XMEMCMP(cipher, cipher1, 3))
  8341. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8342. ret = wc_AesOfbEncrypt(enc, cipher + 3, plain1 + 3, AES_BLOCK_SIZE);
  8343. if (ret != 0)
  8344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8345. if (XMEMCMP(cipher + 3, cipher1 + 3, AES_BLOCK_SIZE))
  8346. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8347. #ifdef HAVE_AES_DECRYPT
  8348. ret = wc_AesOfbDecrypt(dec, plain, cipher1, 6);
  8349. if (ret != 0)
  8350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8351. if (XMEMCMP(plain, plain1, 6))
  8352. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8353. ret = wc_AesOfbDecrypt(dec, plain + 6, cipher1 + 6, AES_BLOCK_SIZE);
  8354. if (ret != 0)
  8355. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8356. if (XMEMCMP(plain + 6, plain1 + 6, AES_BLOCK_SIZE))
  8357. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8358. #endif /* HAVE_AES_DECRYPT */
  8359. out:
  8360. wc_AesFree(enc);
  8361. #ifdef HAVE_AES_DECRYPT
  8362. wc_AesFree(dec);
  8363. #endif
  8364. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8365. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  8366. #ifdef HAVE_AES_DECRYPT
  8367. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  8368. #endif
  8369. #endif
  8370. #endif /* WOLFSSL_AES_256 */
  8371. return ret;
  8372. }
  8373. #endif /* WOLFSSL_AES_OFB */
  8374. #if defined(WOLFSSL_AES_CFB)
  8375. /* Test cases from NIST SP 800-38A, Recommendation for Block Cipher Modes of
  8376. * Operation Methods and Techniques
  8377. */
  8378. static wc_test_ret_t aescfb_test_0(void)
  8379. {
  8380. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8381. Aes *enc = NULL;
  8382. #else
  8383. Aes enc[1];
  8384. #endif
  8385. int enc_inited = 0;
  8386. byte cipher[AES_BLOCK_SIZE * 4];
  8387. #ifdef HAVE_AES_DECRYPT
  8388. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8389. Aes *dec = NULL;
  8390. #else
  8391. Aes dec[1];
  8392. #endif
  8393. int dec_inited = 0;
  8394. byte plain [AES_BLOCK_SIZE * 4];
  8395. #endif
  8396. wc_test_ret_t ret = 0;
  8397. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8398. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  8399. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  8400. };
  8401. #ifdef WOLFSSL_AES_128
  8402. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8403. {
  8404. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  8405. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  8406. };
  8407. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8408. {
  8409. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  8410. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  8411. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  8412. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b,
  8413. 0x26,0x75,0x1f,0x67,0xa3,0xcb,0xb1,0x40,
  8414. 0xb1,0x80,0x8c,0xf1,0x87,0xa4,0xf4,0xdf
  8415. };
  8416. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8417. {
  8418. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8419. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8420. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8421. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8422. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8423. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef
  8424. };
  8425. #endif /* WOLFSSL_AES_128 */
  8426. #ifdef WOLFSSL_AES_192
  8427. /* 192 size key test */
  8428. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8429. {
  8430. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  8431. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  8432. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  8433. };
  8434. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8435. {
  8436. 0xcd,0xc8,0x0d,0x6f,0xdd,0xf1,0x8c,0xab,
  8437. 0x34,0xc2,0x59,0x09,0xc9,0x9a,0x41,0x74,
  8438. 0x67,0xce,0x7f,0x7f,0x81,0x17,0x36,0x21,
  8439. 0x96,0x1a,0x2b,0x70,0x17,0x1d,0x3d,0x7a,
  8440. 0x2e,0x1e,0x8a,0x1d,0xd5,0x9b,0x88,0xb1,
  8441. 0xc8,0xe6,0x0f,0xed,0x1e,0xfa,0xc4,0xc9,
  8442. 0xc0,0x5f,0x9f,0x9c,0xa9,0x83,0x4f,0xa0,
  8443. 0x42,0xae,0x8f,0xba,0x58,0x4b,0x09,0xff
  8444. };
  8445. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8446. {
  8447. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8448. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8449. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8450. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8451. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8452. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8453. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8454. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8455. };
  8456. #endif /* WOLFSSL_AES_192 */
  8457. #ifdef WOLFSSL_AES_256
  8458. /* 256 size key simple test */
  8459. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8460. {
  8461. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  8462. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  8463. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  8464. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  8465. };
  8466. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8467. {
  8468. 0xdc,0x7e,0x84,0xbf,0xda,0x79,0x16,0x4b,
  8469. 0x7e,0xcd,0x84,0x86,0x98,0x5d,0x38,0x60,
  8470. 0x39,0xff,0xed,0x14,0x3b,0x28,0xb1,0xc8,
  8471. 0x32,0x11,0x3c,0x63,0x31,0xe5,0x40,0x7b,
  8472. 0xdf,0x10,0x13,0x24,0x15,0xe5,0x4b,0x92,
  8473. 0xa1,0x3e,0xd0,0xa8,0x26,0x7a,0xe2,0xf9,
  8474. 0x75,0xa3,0x85,0x74,0x1a,0xb9,0xce,0xf8,
  8475. 0x20,0x31,0x62,0x3d,0x55,0xb1,0xe4,0x71
  8476. };
  8477. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8478. {
  8479. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8480. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8481. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8482. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8483. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8484. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8485. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8486. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8487. };
  8488. #endif /* WOLFSSL_AES_256 */
  8489. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8490. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8491. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8492. #ifdef HAVE_AES_DECRYPT
  8493. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8494. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8495. #endif
  8496. #endif
  8497. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8498. if (ret != 0)
  8499. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8500. else
  8501. enc_inited = 1;
  8502. #ifdef HAVE_AES_DECRYPT
  8503. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8504. if (ret != 0)
  8505. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8506. else
  8507. dec_inited = 1;
  8508. #endif
  8509. #ifdef WOLFSSL_AES_128
  8510. /* 128 key tests */
  8511. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8512. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8513. ret = EVP_test(EVP_aes_128_cfb128(), key1, iv, msg1, sizeof(msg1),
  8514. cipher1, sizeof(cipher1));
  8515. if (ret != 0) {
  8516. return ret;
  8517. }
  8518. #endif
  8519. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8520. if (ret != 0)
  8521. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8522. #ifdef HAVE_AES_DECRYPT
  8523. /* decrypt uses AES_ENCRYPTION */
  8524. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8525. if (ret != 0)
  8526. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8527. #endif
  8528. XMEMSET(cipher, 0, sizeof(cipher));
  8529. ret = wc_AesCfbEncrypt(enc, cipher, msg1, AES_BLOCK_SIZE * 2);
  8530. if (ret != 0)
  8531. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8532. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8533. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8534. /* test restarting encryption process */
  8535. ret = wc_AesCfbEncrypt(enc, cipher + (AES_BLOCK_SIZE * 2),
  8536. msg1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE);
  8537. if (ret != 0)
  8538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8539. if (XMEMCMP(cipher + (AES_BLOCK_SIZE * 2),
  8540. cipher1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE))
  8541. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8542. #ifdef HAVE_AES_DECRYPT
  8543. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 3);
  8544. if (ret != 0)
  8545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8546. if (XMEMCMP(plain, msg1, AES_BLOCK_SIZE * 3))
  8547. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8548. #endif /* HAVE_AES_DECRYPT */
  8549. #endif /* WOLFSSL_AES_128 */
  8550. #ifdef WOLFSSL_AES_192
  8551. /* 192 key size test */
  8552. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8553. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8554. ret = EVP_test(EVP_aes_192_cfb128(), key2, iv, msg2, sizeof(msg2),
  8555. cipher2, sizeof(cipher2));
  8556. if (ret != 0) {
  8557. return ret;
  8558. }
  8559. #endif
  8560. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8561. if (ret != 0)
  8562. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8563. #ifdef HAVE_AES_DECRYPT
  8564. /* decrypt uses AES_ENCRYPTION */
  8565. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8566. if (ret != 0)
  8567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8568. #endif
  8569. XMEMSET(cipher, 0, sizeof(cipher));
  8570. ret = wc_AesCfbEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE * 4);
  8571. if (ret != 0)
  8572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8573. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE * 4))
  8574. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8575. #ifdef HAVE_AES_DECRYPT
  8576. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 4);
  8577. if (ret != 0)
  8578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8579. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE * 4))
  8580. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8581. #endif /* HAVE_AES_DECRYPT */
  8582. #endif /* WOLFSSL_AES_192 */
  8583. #ifdef WOLFSSL_AES_256
  8584. /* 256 key size test */
  8585. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8586. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8587. ret = EVP_test(EVP_aes_256_cfb128(), key3, iv, msg3, sizeof(msg3),
  8588. cipher3, sizeof(cipher3));
  8589. if (ret != 0) {
  8590. return ret;
  8591. }
  8592. #endif
  8593. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8594. if (ret != 0)
  8595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8596. #ifdef HAVE_AES_DECRYPT
  8597. /* decrypt uses AES_ENCRYPTION */
  8598. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8599. if (ret != 0)
  8600. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8601. #endif
  8602. /* test with data left overs, magic lengths are checking near edges */
  8603. XMEMSET(cipher, 0, sizeof(cipher));
  8604. ret = wc_AesCfbEncrypt(enc, cipher, msg3, 4);
  8605. if (ret != 0)
  8606. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8607. if (XMEMCMP(cipher, cipher3, 4))
  8608. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8609. ret = wc_AesCfbEncrypt(enc, cipher + 4, msg3 + 4, 27);
  8610. if (ret != 0)
  8611. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8612. if (XMEMCMP(cipher + 4, cipher3 + 4, 27))
  8613. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8614. ret = wc_AesCfbEncrypt(enc, cipher + 31, msg3 + 31,
  8615. (AES_BLOCK_SIZE * 4) - 31);
  8616. if (ret != 0)
  8617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8618. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE * 4))
  8619. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8620. #ifdef HAVE_AES_DECRYPT
  8621. ret = wc_AesCfbDecrypt(dec, plain, cipher, 4);
  8622. if (ret != 0)
  8623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8624. if (XMEMCMP(plain, msg3, 4))
  8625. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8626. ret = wc_AesCfbDecrypt(dec, plain + 4, cipher + 4, 4);
  8627. if (ret != 0)
  8628. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8629. ret = wc_AesCfbDecrypt(dec, plain + 8, cipher + 8, 23);
  8630. if (ret != 0)
  8631. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8632. if (XMEMCMP(plain + 4, msg3 + 4, 27))
  8633. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8634. ret = wc_AesCfbDecrypt(dec, plain + 31, cipher + 31,
  8635. (AES_BLOCK_SIZE * 4) - 31);
  8636. if (ret != 0)
  8637. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8638. if (XMEMCMP(plain, msg3, AES_BLOCK_SIZE * 4))
  8639. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8640. #endif /* HAVE_AES_DECRYPT */
  8641. #endif /* WOLFSSL_AES_256 */
  8642. out:
  8643. if (enc_inited)
  8644. wc_AesFree(enc);
  8645. #ifdef HAVE_AES_DECRYPT
  8646. if (dec_inited)
  8647. wc_AesFree(dec);
  8648. #endif
  8649. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8650. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  8651. #ifdef HAVE_AES_DECRYPT
  8652. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  8653. #endif
  8654. #endif
  8655. return ret;
  8656. }
  8657. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0))
  8658. static wc_test_ret_t aescfb1_test(void)
  8659. {
  8660. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8661. Aes *enc = NULL;
  8662. #else
  8663. Aes enc[1];
  8664. #endif
  8665. int enc_inited = 0;
  8666. byte cipher[AES_BLOCK_SIZE];
  8667. #ifdef HAVE_AES_DECRYPT
  8668. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8669. Aes *dec = NULL;
  8670. #else
  8671. Aes dec[1];
  8672. #endif
  8673. int dec_inited = 0;
  8674. byte plain [AES_BLOCK_SIZE];
  8675. #endif
  8676. wc_test_ret_t ret = 0;
  8677. #ifdef WOLFSSL_AES_128
  8678. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8679. 0x4d,0xbb,0xdc,0xaa,0x59,0xf3,0x63,0xc9,
  8680. 0x2a,0x3b,0x98,0x43,0xad,0x20,0xe2,0xb7
  8681. };
  8682. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8683. {
  8684. 0xcd,0xef,0x9d,0x06,0x61,0xba,0xe4,0x73,
  8685. 0x8d,0x1a,0x58,0xa2,0xa6,0x22,0x8b,0x66
  8686. };
  8687. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8688. {
  8689. 0x00
  8690. };
  8691. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8692. {
  8693. 0xC0
  8694. };
  8695. WOLFSSL_SMALL_STACK_STATIC const byte cipher1_7bit[] =
  8696. {
  8697. 0x1C
  8698. };
  8699. #endif /* WOLFSSL_AES_128 */
  8700. #ifdef WOLFSSL_AES_192
  8701. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  8702. 0x57,0xc6,0x89,0x7c,0x99,0x52,0x28,0x13,
  8703. 0xbf,0x67,0x9c,0xe1,0x13,0x70,0xaf,0x5e
  8704. };
  8705. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8706. {
  8707. 0xba,0xa1,0x58,0xa1,0x6b,0x50,0x4a,0x10,
  8708. 0x8e,0xd4,0x33,0x2e,0xe7,0xf2,0x9b,0xf6,
  8709. 0xd1,0xac,0x46,0xa8,0xde,0x5a,0xfe,0x7a
  8710. };
  8711. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8712. {
  8713. 0x30
  8714. };
  8715. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8716. {
  8717. 0x80
  8718. };
  8719. #endif /* WOLFSSL_AES_192 */
  8720. #ifdef WOLFSSL_AES_256
  8721. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  8722. 0x63,0x2e,0x9f,0x83,0x1f,0xa3,0x80,0x5e,
  8723. 0x52,0x02,0xbc,0xe0,0x6d,0x04,0xf9,0xa0
  8724. };
  8725. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8726. {
  8727. 0xf6,0xfa,0xe4,0xf1,0x5d,0x91,0xfc,0x50,
  8728. 0x88,0x78,0x4f,0x84,0xa5,0x37,0x12,0x7e,
  8729. 0x32,0x63,0x55,0x9c,0x62,0x73,0x88,0x20,
  8730. 0xc2,0xcf,0x3d,0xe1,0x1c,0x2a,0x30,0x40
  8731. };
  8732. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8733. {
  8734. 0xF7, 0x00
  8735. };
  8736. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8737. {
  8738. 0x41, 0xC0
  8739. };
  8740. #endif /* WOLFSSL_AES_256 */
  8741. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8742. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8743. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8744. #ifdef HAVE_AES_DECRYPT
  8745. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8746. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8747. #endif
  8748. #endif
  8749. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8750. if (ret != 0)
  8751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8752. else
  8753. enc_inited = 1;
  8754. #ifdef HAVE_AES_DECRYPT
  8755. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8756. if (ret != 0)
  8757. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8758. else
  8759. dec_inited = 1;
  8760. #endif
  8761. #ifdef WOLFSSL_AES_128
  8762. /* 128 key tests */
  8763. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8764. if (ret != 0)
  8765. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8766. #ifdef HAVE_AES_DECRYPT
  8767. /* decrypt uses AES_ENCRYPTION */
  8768. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8769. if (ret != 0)
  8770. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8771. #endif
  8772. XMEMSET(cipher, 0, sizeof(cipher));
  8773. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 2);
  8774. if (ret != 0)
  8775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8776. if (cipher[0] != cipher1[0])
  8777. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8778. #ifdef HAVE_AES_DECRYPT
  8779. ret = wc_AesCfb1Decrypt(dec, plain, cipher, 2);
  8780. if (ret != 0)
  8781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8782. if (plain[0] != msg1[0])
  8783. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8784. #endif /* HAVE_AES_DECRYPT */
  8785. XMEMSET(cipher, 0, sizeof(cipher));
  8786. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 7);
  8787. if (ret != 0)
  8788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8789. if (cipher[0] != cipher1_7bit[0])
  8790. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8791. #ifdef OPENSSL_EXTRA
  8792. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8793. if (ret != 0)
  8794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8795. XMEMSET(cipher, 0, sizeof(cipher));
  8796. ret = wc_AesCfb1Encrypt(enc, cipher, msg1,
  8797. sizeof(msg1) * WOLFSSL_BIT_SIZE);
  8798. if (ret != 0)
  8799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8800. #ifndef WOLFCRYPT_ONLY
  8801. ret = EVP_test(EVP_aes_128_cfb1(), key1, iv, msg1, sizeof(msg1),
  8802. cipher, sizeof(msg1));
  8803. if (ret != 0) {
  8804. goto out;
  8805. }
  8806. #endif
  8807. #endif
  8808. #endif /* WOLFSSL_AES_128 */
  8809. #ifdef WOLFSSL_AES_192
  8810. /* 192 key tests */
  8811. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8812. if (ret != 0)
  8813. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8814. XMEMSET(cipher, 0, sizeof(cipher));
  8815. ret = wc_AesCfb1Encrypt(enc, cipher, msg2, 4);
  8816. if (ret != 0)
  8817. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8818. if (XMEMCMP(cipher, cipher2, sizeof(cipher2)) != 0)
  8819. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8820. #ifdef OPENSSL_EXTRA
  8821. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8822. if (ret != 0)
  8823. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8824. XMEMSET(cipher, 0, sizeof(cipher));
  8825. ret = wc_AesCfb1Encrypt(enc, cipher, msg2,
  8826. sizeof(msg2) * WOLFSSL_BIT_SIZE);
  8827. if (ret != 0)
  8828. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8829. #ifndef WOLFCRYPT_ONLY
  8830. ret = EVP_test(EVP_aes_192_cfb1(), key2, iv2, msg2, sizeof(msg2),
  8831. cipher, sizeof(msg2));
  8832. if (ret != 0) {
  8833. goto out;
  8834. }
  8835. #endif
  8836. #endif
  8837. #endif /* WOLFSSL_AES_192 */
  8838. #ifdef WOLFSSL_AES_256
  8839. /* 256 key tests */
  8840. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8841. if (ret != 0)
  8842. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8843. XMEMSET(cipher, 0, sizeof(cipher));
  8844. ret = wc_AesCfb1Encrypt(enc, cipher, msg3, 10);
  8845. if (ret != 0)
  8846. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8847. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  8848. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8849. #ifdef OPENSSL_EXTRA
  8850. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8851. if (ret != 0)
  8852. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8853. XMEMSET(cipher, 0, sizeof(cipher));
  8854. ret = wc_AesCfb1Encrypt(enc, cipher, msg3,
  8855. sizeof(msg3) * WOLFSSL_BIT_SIZE);
  8856. if (ret != 0)
  8857. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8858. #ifndef WOLFCRYPT_ONLY
  8859. ret = EVP_test(EVP_aes_256_cfb1(), key3, iv3, msg3, sizeof(msg3),
  8860. cipher, sizeof(msg3));
  8861. if (ret != 0) {
  8862. goto out;
  8863. }
  8864. #endif
  8865. #endif
  8866. #endif /* WOLFSSL_AES_256 */
  8867. out:
  8868. if (enc_inited)
  8869. wc_AesFree(enc);
  8870. #ifdef HAVE_AES_DECRYPT
  8871. if (dec_inited)
  8872. wc_AesFree(dec);
  8873. #endif
  8874. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8875. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  8876. #ifdef HAVE_AES_DECRYPT
  8877. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  8878. #endif
  8879. #endif
  8880. return ret;
  8881. }
  8882. static wc_test_ret_t aescfb8_test(void)
  8883. {
  8884. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8885. Aes *enc = NULL;
  8886. #else
  8887. Aes enc[1];
  8888. #endif
  8889. int enc_inited = 0;
  8890. byte cipher[AES_BLOCK_SIZE];
  8891. #ifdef HAVE_AES_DECRYPT
  8892. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8893. Aes *dec = NULL;
  8894. #else
  8895. Aes dec[1];
  8896. #endif
  8897. int dec_inited = 0;
  8898. byte plain [AES_BLOCK_SIZE];
  8899. #endif
  8900. wc_test_ret_t ret = 0;
  8901. #ifdef WOLFSSL_AES_128
  8902. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8903. 0xf4,0x75,0xc6,0x49,0x91,0xb2,0x0e,0xae,
  8904. 0xe1,0x83,0xa2,0x26,0x29,0xe2,0x1e,0x22
  8905. };
  8906. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8907. {
  8908. 0xc8,0xfe,0x9b,0xf7,0x7b,0x93,0x0f,0x46,
  8909. 0xd2,0x07,0x8b,0x8c,0x0e,0x65,0x7c,0xd4
  8910. };
  8911. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8912. {
  8913. 0xd2,0x76,0x91
  8914. };
  8915. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8916. {
  8917. 0xc9,0x06,0x35
  8918. };
  8919. #endif /* WOLFSSL_AES_128 */
  8920. #ifdef WOLFSSL_AES_192
  8921. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  8922. 0x0a,0x02,0x84,0x6b,0x62,0xab,0xb6,0x93,
  8923. 0xef,0x31,0xd7,0x54,0x84,0x2e,0xed,0x29
  8924. };
  8925. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8926. {
  8927. 0xba,0xf0,0x8b,0x76,0x31,0x7a,0x65,0xc5,
  8928. 0xf0,0x7a,0xe6,0xf5,0x7e,0xb0,0xe6,0x54,
  8929. 0x88,0x65,0x93,0x24,0xd2,0x97,0x09,0xe3
  8930. };
  8931. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8932. {
  8933. 0x72,0x9c,0x0b,0x6d,0xeb,0x75,0xfa,0x6e,
  8934. 0xb5,0xe8
  8935. };
  8936. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8937. {
  8938. 0x98,0x95,0x93,0x24,0x02,0x39,0x3d,0xc3,
  8939. 0x3a,0x60
  8940. };
  8941. #endif
  8942. #ifdef WOLFSSL_AES_256
  8943. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  8944. 0x33,0x8c,0x55,0x2f,0xf1,0xec,0xa1,0x44,
  8945. 0x08,0xe0,0x5d,0x8c,0xf9,0xf3,0xb3,0x1b
  8946. };
  8947. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8948. {
  8949. 0x06,0x48,0x74,0x09,0x2f,0x7a,0x13,0xcc,
  8950. 0x44,0x62,0x24,0x7a,0xd4,0x23,0xd0,0xe9,
  8951. 0x6e,0xdf,0x42,0xe8,0xb6,0x7a,0x5a,0x23,
  8952. 0xb7,0xa0,0xa6,0x47,0x7b,0x09,0x8e,0x66
  8953. };
  8954. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8955. {
  8956. 0x1c,0xff,0x95
  8957. };
  8958. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8959. {
  8960. 0xb9,0x74,0xfa
  8961. };
  8962. #endif
  8963. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8964. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8965. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8966. #ifdef HAVE_AES_DECRYPT
  8967. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  8968. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  8969. #endif
  8970. #endif
  8971. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8972. if (ret != 0)
  8973. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8974. else
  8975. enc_inited = 1;
  8976. #ifdef HAVE_AES_DECRYPT
  8977. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8978. if (ret != 0)
  8979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8980. else
  8981. dec_inited = 1;
  8982. #endif
  8983. #ifdef WOLFSSL_AES_128
  8984. /* 128 key tests */
  8985. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  8986. ret = EVP_test(EVP_aes_128_cfb8(), key1, iv, msg1, sizeof(msg1),
  8987. cipher1, sizeof(cipher1));
  8988. if (ret != 0) {
  8989. return ret;
  8990. }
  8991. #endif
  8992. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8993. if (ret != 0)
  8994. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8995. #ifdef HAVE_AES_DECRYPT
  8996. /* decrypt uses AES_ENCRYPTION */
  8997. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8998. if (ret != 0)
  8999. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9000. #endif
  9001. XMEMSET(cipher, 0, sizeof(cipher));
  9002. ret = wc_AesCfb8Encrypt(enc, cipher, msg1, sizeof(msg1));
  9003. if (ret != 0)
  9004. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9005. if (XMEMCMP(cipher, cipher1, sizeof(cipher1)) != 0)
  9006. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9007. #ifdef HAVE_AES_DECRYPT
  9008. ret = wc_AesCfb8Decrypt(dec, plain, cipher, sizeof(msg1));
  9009. if (ret != 0)
  9010. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9011. if (XMEMCMP(plain, msg1, sizeof(msg1)) != 0)
  9012. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9013. #endif /* HAVE_AES_DECRYPT */
  9014. #endif /* WOLFSSL_AES_128 */
  9015. #ifdef WOLFSSL_AES_192
  9016. /* 192 key tests */
  9017. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  9018. if (ret != 0)
  9019. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9020. XMEMSET(cipher, 0, sizeof(cipher));
  9021. ret = wc_AesCfb8Encrypt(enc, cipher, msg2, sizeof(msg2));
  9022. if (ret != 0)
  9023. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9024. if (XMEMCMP(cipher, cipher2, sizeof(msg2)) != 0)
  9025. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9026. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9027. ret = EVP_test(EVP_aes_192_cfb8(), key2, iv2, msg2, sizeof(msg2),
  9028. cipher2, sizeof(msg2));
  9029. if (ret != 0) {
  9030. return ret;
  9031. }
  9032. #endif
  9033. #endif /* WOLFSSL_AES_192 */
  9034. #ifdef WOLFSSL_AES_256
  9035. /* 256 key tests */
  9036. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  9037. if (ret != 0)
  9038. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9039. XMEMSET(cipher, 0, sizeof(cipher));
  9040. ret = wc_AesCfb8Encrypt(enc, cipher, msg3, sizeof(msg3));
  9041. if (ret != 0)
  9042. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9043. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  9044. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9045. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9046. ret = EVP_test(EVP_aes_256_cfb8(), key3, iv3, msg3, sizeof(msg3),
  9047. cipher3, sizeof(msg3));
  9048. if (ret != 0) {
  9049. goto out;
  9050. }
  9051. #endif
  9052. #endif /* WOLFSSL_AES_256 */
  9053. out:
  9054. if (enc_inited)
  9055. wc_AesFree(enc);
  9056. #ifdef HAVE_AES_DECRYPT
  9057. if (dec_inited)
  9058. wc_AesFree(dec);
  9059. #endif
  9060. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9061. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  9062. #ifdef HAVE_AES_DECRYPT
  9063. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  9064. #endif
  9065. #endif
  9066. return ret;
  9067. }
  9068. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  9069. #endif /* WOLFSSL_AES_CFB */
  9070. static wc_test_ret_t aes_key_size_test(void)
  9071. {
  9072. wc_test_ret_t ret;
  9073. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9074. Aes *aes;
  9075. #else
  9076. Aes aes[1];
  9077. #endif
  9078. byte key16[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9079. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9080. #ifndef WOLFSSL_CRYPTOCELL
  9081. byte key24[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9082. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9083. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
  9084. #endif
  9085. byte key32[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9086. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9087. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9088. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9089. byte iv[] = "1234567890abcdef";
  9090. #ifndef HAVE_FIPS
  9091. word32 keySize;
  9092. #endif
  9093. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9094. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9095. return WC_TEST_RET_ENC_ERRNO;
  9096. #endif
  9097. #if !defined(HAVE_FIPS) || \
  9098. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  9099. /* w/ FIPS v1 (cert 2425) wc_AesInit just returns 0 always as it's not
  9100. * supported with that FIPS version */
  9101. ret = wc_AesInit(NULL, HEAP_HINT, devId);
  9102. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9103. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9104. #endif
  9105. ret = wc_AesInit(aes, HEAP_HINT, devId);
  9106. /* 0 check OK for FIPSv1 */
  9107. if (ret != 0)
  9108. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9109. #ifndef HAVE_FIPS
  9110. /* Parameter Validation testing. */
  9111. ret = wc_AesGetKeySize(NULL, NULL);
  9112. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9113. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9114. ret = wc_AesGetKeySize(aes, NULL);
  9115. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9116. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9117. ret = wc_AesGetKeySize(NULL, &keySize);
  9118. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9120. /* Crashes in FIPS */
  9121. ret = wc_AesSetKey(NULL, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9122. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9123. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9124. #endif
  9125. /* NULL IV indicates to use all zeros IV. */
  9126. ret = wc_AesSetKey(aes, key16, sizeof(key16), NULL, AES_ENCRYPTION);
  9127. #ifdef WOLFSSL_AES_128
  9128. if (ret != 0)
  9129. #else
  9130. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9131. #endif
  9132. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9133. ret = wc_AesSetKey(aes, key32, sizeof(key32) - 1, iv, AES_ENCRYPTION);
  9134. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9135. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9136. /* CryptoCell handles rounds internally */
  9137. #if !defined(HAVE_FIPS) && !defined(WOLFSSL_CRYPTOCELL)
  9138. /* PSA don't use aes->rounds */
  9139. #if !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_AES)
  9140. /* Force invalid rounds */
  9141. aes->rounds = 16;
  9142. ret = wc_AesGetKeySize(aes, &keySize);
  9143. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9144. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9145. #endif
  9146. #endif
  9147. ret = wc_AesSetKey(aes, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9148. #ifdef WOLFSSL_AES_128
  9149. if (ret != 0)
  9150. #else
  9151. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9152. #endif
  9153. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9154. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_128)
  9155. ret = wc_AesGetKeySize(aes, &keySize);
  9156. if (ret != 0 || keySize != sizeof(key16))
  9157. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9158. #endif
  9159. #ifndef WOLFSSL_CRYPTOCELL
  9160. /* Cryptocell only supports AES-128 key size */
  9161. ret = wc_AesSetKey(aes, key24, sizeof(key24), iv, AES_ENCRYPTION);
  9162. #ifdef WOLFSSL_AES_192
  9163. if (ret != 0)
  9164. #else
  9165. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9166. #endif
  9167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9168. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_192)
  9169. ret = wc_AesGetKeySize(aes, &keySize);
  9170. if (ret != 0 || keySize != sizeof(key24))
  9171. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9172. #endif
  9173. ret = wc_AesSetKey(aes, key32, sizeof(key32), iv, AES_ENCRYPTION);
  9174. #ifdef WOLFSSL_AES_256
  9175. if (ret != 0)
  9176. #else
  9177. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9178. #endif
  9179. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9180. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_256)
  9181. ret = wc_AesGetKeySize(aes, &keySize);
  9182. if (ret != 0 || keySize != sizeof(key32))
  9183. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9184. #endif
  9185. #endif /* !WOLFSSL_CRYPTOCELL */
  9186. ret = 0; /* success */
  9187. out:
  9188. wc_AesFree(aes);
  9189. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9190. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9191. #endif
  9192. return ret;
  9193. }
  9194. #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  9195. /* test vectors from http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html */
  9196. #ifdef WOLFSSL_AES_128
  9197. static wc_test_ret_t aes_xts_128_test(void)
  9198. {
  9199. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9200. XtsAes *aes = NULL;
  9201. #else
  9202. XtsAes aes[1];
  9203. #endif
  9204. int aes_inited = 0;
  9205. wc_test_ret_t ret = 0;
  9206. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9207. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9208. #ifdef WOLFSSL_AESXTS_STREAM
  9209. struct XtsAesStreamData stream;
  9210. #endif
  9211. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9212. !defined(WOLFSSL_AFALG)
  9213. #define LARGE_XTS_SZ 1024
  9214. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9215. byte* large_input = NULL;
  9216. #else
  9217. byte large_input[LARGE_XTS_SZ];
  9218. #endif
  9219. #endif
  9220. /* 128 key tests */
  9221. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9222. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  9223. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  9224. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  9225. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  9226. };
  9227. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9228. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9229. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9230. };
  9231. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9232. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9233. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9234. };
  9235. /* plain text test of partial block is not from NIST test vector list */
  9236. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9237. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9238. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9239. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9240. };
  9241. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9242. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a,
  9243. 0x82, 0x50, 0x81, 0xd5, 0xbe, 0x47, 0x1c, 0x63
  9244. };
  9245. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9246. 0x39, 0x25, 0x79, 0x05, 0xdf, 0xcc, 0x77, 0x76,
  9247. 0x6c, 0x87, 0x0a, 0x80, 0x6a, 0x60, 0xe3, 0xc0,
  9248. 0x93, 0xd1, 0x2a, 0xcf, 0xcb, 0x51, 0x42, 0xfa,
  9249. 0x09, 0x69, 0x89, 0x62, 0x5b, 0x60, 0xdb, 0x16
  9250. };
  9251. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9252. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9253. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9254. };
  9255. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9256. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9257. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9258. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9259. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9260. };
  9261. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9262. 0xd6, 0xbe, 0x04, 0x6d, 0x41, 0xf2, 0x3b, 0x5e,
  9263. 0xd7, 0x0b, 0x6b, 0x3d, 0x5c, 0x8e, 0x66, 0x23,
  9264. 0x2b, 0xe6, 0xb8, 0x07, 0xd4, 0xdc, 0xc6, 0x0e,
  9265. 0xff, 0x8d, 0xbc, 0x1d, 0x9f, 0x7f, 0xc8, 0x22
  9266. };
  9267. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9268. 0x2b, 0xf7, 0x2c, 0xf3, 0xeb, 0x85, 0xef, 0x7b,
  9269. 0x0b, 0x76, 0xa0, 0xaa, 0xf3, 0x3f, 0x25, 0x8b,
  9270. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a
  9271. };
  9272. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9273. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9274. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9275. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9276. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9277. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9278. };
  9279. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9280. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9281. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9282. };
  9283. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9284. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9285. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9286. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9287. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9288. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9289. };
  9290. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9291. 0xA2, 0x07, 0x47, 0x76, 0x3F, 0xEC, 0x0C, 0x23,
  9292. 0x1B, 0xD0, 0xBD, 0x46, 0x9A, 0x27, 0x38, 0x12,
  9293. 0x95, 0x02, 0x3D, 0x5D, 0xC6, 0x94, 0x51, 0x36,
  9294. 0xA0, 0x85, 0xD2, 0x69, 0x6E, 0x87, 0x0A, 0xBF,
  9295. 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD
  9296. };
  9297. #endif /* HAVE_FIPS */
  9298. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9299. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9300. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9301. #endif
  9302. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  9303. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  9304. ret = EVP_test(EVP_aes_128_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  9305. if (ret != 0) {
  9306. printf("EVP_aes_128_xts failed!\n");
  9307. goto out;
  9308. }
  9309. #endif
  9310. XMEMSET(buf, 0, sizeof(buf));
  9311. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9312. if (ret != 0)
  9313. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9314. else
  9315. aes_inited = 1;
  9316. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9317. if (ret != 0)
  9318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9319. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9320. #if defined(WOLFSSL_ASYNC_CRYPT)
  9321. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9322. #endif
  9323. if (ret != 0)
  9324. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9325. if (XMEMCMP(c2, buf, sizeof(c2)))
  9326. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9327. #ifdef WOLFSSL_AESXTS_STREAM
  9328. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9329. #if defined(WOLFSSL_ASYNC_CRYPT)
  9330. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9331. #endif
  9332. if (ret != 0)
  9333. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9334. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  9335. #if defined(WOLFSSL_ASYNC_CRYPT)
  9336. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9337. #endif
  9338. if (ret != 0)
  9339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9340. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  9341. #if defined(WOLFSSL_ASYNC_CRYPT)
  9342. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9343. #endif
  9344. if (ret != 0)
  9345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9346. if (XMEMCMP(c2, buf, sizeof(c2)))
  9347. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9348. #endif /* WOLFSSL_AESXTS_STREAM */
  9349. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9350. defined(WC_C_DYNAMIC_FALLBACK)
  9351. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9352. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9353. #if defined(WOLFSSL_ASYNC_CRYPT)
  9354. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9355. #endif
  9356. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9357. if (ret != 0)
  9358. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9359. if (XMEMCMP(c2, buf, sizeof(c2)))
  9360. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9361. #endif
  9362. XMEMSET(buf, 0, sizeof(buf));
  9363. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9364. if (ret != 0)
  9365. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9366. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9367. #if defined(WOLFSSL_ASYNC_CRYPT)
  9368. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9369. #endif
  9370. if (ret != 0)
  9371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9372. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9373. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9374. #ifdef WOLFSSL_AESXTS_STREAM
  9375. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i2), &stream);
  9376. #if defined(WOLFSSL_ASYNC_CRYPT)
  9377. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9378. #endif
  9379. if (ret != 0)
  9380. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9381. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  9382. #if defined(WOLFSSL_ASYNC_CRYPT)
  9383. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9384. #endif
  9385. if (ret != 0)
  9386. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9387. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9388. #if defined(WOLFSSL_ASYNC_CRYPT)
  9389. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9390. #endif
  9391. if (ret != 0)
  9392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9393. if (XMEMCMP(c1, buf, sizeof(c1)))
  9394. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9395. #endif /* WOLFSSL_AESXTS_STREAM */
  9396. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9397. defined(WC_C_DYNAMIC_FALLBACK)
  9398. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9399. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9400. #if defined(WOLFSSL_ASYNC_CRYPT)
  9401. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9402. #endif
  9403. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9404. if (ret != 0)
  9405. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9406. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9407. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9408. #endif
  9409. /* partial block encryption test */
  9410. XMEMSET(cipher, 0, sizeof(cipher));
  9411. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9412. #if defined(WOLFSSL_ASYNC_CRYPT)
  9413. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9414. #endif
  9415. if (ret != 0)
  9416. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9417. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9418. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9419. #ifdef WOLFSSL_AESXTS_STREAM
  9420. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9421. #if defined(WOLFSSL_ASYNC_CRYPT)
  9422. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9423. #endif
  9424. if (ret != 0)
  9425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9426. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  9427. #if defined(WOLFSSL_ASYNC_CRYPT)
  9428. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9429. #endif
  9430. if (ret != 0)
  9431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9432. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9433. #if defined(WOLFSSL_ASYNC_CRYPT)
  9434. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9435. #endif
  9436. if (ret != 0)
  9437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9438. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  9439. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9440. #endif /* WOLFSSL_AESXTS_STREAM */
  9441. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9442. defined(WC_C_DYNAMIC_FALLBACK)
  9443. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9444. XMEMSET(cipher, 0, sizeof(cipher));
  9445. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9446. #if defined(WOLFSSL_ASYNC_CRYPT)
  9447. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9448. #endif
  9449. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9450. if (ret != 0)
  9451. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9452. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9453. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9454. #endif
  9455. /* partial block decrypt test */
  9456. XMEMSET(buf, 0, sizeof(buf));
  9457. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9458. if (ret != 0)
  9459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9460. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9461. #if defined(WOLFSSL_ASYNC_CRYPT)
  9462. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9463. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9464. #else
  9465. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9466. #endif
  9467. #endif
  9468. if (ret != 0)
  9469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9470. if (XMEMCMP(pp, buf, sizeof(pp)))
  9471. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9472. #ifdef WOLFSSL_AESXTS_STREAM
  9473. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9474. #if defined(WOLFSSL_ASYNC_CRYPT)
  9475. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9476. #endif
  9477. if (ret != 0)
  9478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9479. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  9480. #if defined(WOLFSSL_ASYNC_CRYPT)
  9481. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9482. #endif
  9483. if (ret != 0)
  9484. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9485. if (XMEMCMP(pp, buf, sizeof(pp)))
  9486. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9487. #endif /* WOLFSSL_AESXTS_STREAM */
  9488. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9489. defined(WC_C_DYNAMIC_FALLBACK)
  9490. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9491. XMEMSET(buf, 0, sizeof(buf));
  9492. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9493. #if defined(WOLFSSL_ASYNC_CRYPT)
  9494. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9495. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9496. #else
  9497. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9498. #endif
  9499. #endif
  9500. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9501. if (ret != 0)
  9502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9503. if (XMEMCMP(pp, buf, sizeof(pp)))
  9504. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9505. #endif
  9506. /* NIST decrypt test vector */
  9507. XMEMSET(buf, 0, sizeof(buf));
  9508. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9509. #if defined(WOLFSSL_ASYNC_CRYPT)
  9510. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9511. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9512. #else
  9513. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9514. #endif
  9515. #endif
  9516. if (ret != 0)
  9517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9518. if (XMEMCMP(p1, buf, sizeof(p1)))
  9519. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9520. #ifdef WOLFSSL_AESXTS_STREAM
  9521. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9522. #if defined(WOLFSSL_ASYNC_CRYPT)
  9523. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9524. #endif
  9525. if (ret != 0)
  9526. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9527. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  9528. #if defined(WOLFSSL_ASYNC_CRYPT)
  9529. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9530. #endif
  9531. if (ret != 0)
  9532. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9533. if (XMEMCMP(p1, buf, sizeof(p1)))
  9534. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9535. #endif /* WOLFSSL_AESXTS_STREAM */
  9536. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9537. defined(WC_C_DYNAMIC_FALLBACK)
  9538. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9539. XMEMSET(buf, 0, sizeof(buf));
  9540. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9541. #if defined(WOLFSSL_ASYNC_CRYPT)
  9542. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9543. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9544. #else
  9545. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9546. #endif
  9547. #endif
  9548. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9549. if (ret != 0)
  9550. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9551. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  9552. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9553. #endif
  9554. /* fail case with decrypting using wrong key */
  9555. XMEMSET(buf, 0, sizeof(buf));
  9556. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9557. #if defined(WOLFSSL_ASYNC_CRYPT)
  9558. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9559. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9560. #else
  9561. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9562. #endif
  9563. #endif
  9564. if (ret != 0)
  9565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9566. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  9567. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9568. /* set correct key and retest */
  9569. XMEMSET(buf, 0, sizeof(buf));
  9570. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  9571. if (ret != 0)
  9572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9573. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9574. #if defined(WOLFSSL_ASYNC_CRYPT)
  9575. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9576. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9577. #else
  9578. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9579. #endif
  9580. #endif
  9581. if (ret != 0)
  9582. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9583. if (XMEMCMP(p2, buf, sizeof(p2)))
  9584. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9585. #ifndef HAVE_FIPS
  9586. /* Test ciphertext stealing in-place. */
  9587. XMEMCPY(buf, p3, sizeof(p3));
  9588. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  9589. if (ret != 0)
  9590. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9591. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  9592. #if defined(WOLFSSL_ASYNC_CRYPT)
  9593. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9594. #endif
  9595. if (ret != 0)
  9596. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9597. if (XMEMCMP(c3, buf, sizeof(c3)))
  9598. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9599. #ifdef WOLFSSL_AESXTS_STREAM
  9600. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  9601. #if defined(WOLFSSL_ASYNC_CRYPT)
  9602. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9603. #endif
  9604. if (ret != 0)
  9605. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9606. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  9607. #if defined(WOLFSSL_ASYNC_CRYPT)
  9608. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9609. #endif
  9610. if (ret != 0)
  9611. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9612. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  9613. #if defined(WOLFSSL_ASYNC_CRYPT)
  9614. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9615. #endif
  9616. if (ret != 0)
  9617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9618. if (XMEMCMP(c3, buf, sizeof(c3)))
  9619. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9620. #endif /* WOLFSSL_AESXTS_STREAM */
  9621. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  9622. if (ret != 0)
  9623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9624. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  9625. #if defined(WOLFSSL_ASYNC_CRYPT)
  9626. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9627. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9628. #else
  9629. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9630. #endif
  9631. #endif
  9632. if (ret != 0)
  9633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9634. if (XMEMCMP(p3, buf, sizeof(p3)))
  9635. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9636. #ifdef WOLFSSL_AESXTS_STREAM
  9637. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  9638. #if defined(WOLFSSL_ASYNC_CRYPT)
  9639. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9640. #endif
  9641. if (ret != 0)
  9642. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9643. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  9644. #if defined(WOLFSSL_ASYNC_CRYPT)
  9645. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9646. #endif
  9647. if (ret != 0)
  9648. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9649. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  9650. #if defined(WOLFSSL_ASYNC_CRYPT)
  9651. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9652. #endif
  9653. if (ret != 0)
  9654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9655. if (XMEMCMP(p3, buf, sizeof(p3)))
  9656. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9657. #endif /* WOLFSSL_AESXTS_STREAM */
  9658. #endif /* !HAVE_FIPS */
  9659. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9660. !defined(WOLFSSL_AFALG)
  9661. {
  9662. int i;
  9663. int j;
  9664. #ifdef WOLFSSL_AESXTS_STREAM
  9665. int k;
  9666. #endif
  9667. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9668. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  9669. DYNAMIC_TYPE_TMP_BUFFER);
  9670. if (large_input == NULL)
  9671. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  9672. #endif
  9673. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9674. large_input[i] = (byte)i;
  9675. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9676. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9677. if (ret != 0)
  9678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9679. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9680. sizeof(i1));
  9681. #if defined(WOLFSSL_ASYNC_CRYPT)
  9682. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9683. #endif
  9684. if (ret != 0)
  9685. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9686. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9687. if (ret != 0)
  9688. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9689. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9690. sizeof(i1));
  9691. #if defined(WOLFSSL_ASYNC_CRYPT)
  9692. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9693. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9694. WC_ASYNC_FLAG_NONE);
  9695. #else
  9696. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9697. #endif
  9698. #endif
  9699. if (ret != 0)
  9700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9701. for (i = 0; i < j; i++) {
  9702. if (large_input[i] != (byte)i) {
  9703. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9704. }
  9705. }
  9706. }
  9707. #ifdef WOLFSSL_AESXTS_STREAM
  9708. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9709. large_input[i] = (byte)i;
  9710. /* first, encrypt block by block then decrypt with a one-shot call. */
  9711. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9712. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9713. if (ret != 0)
  9714. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9715. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9716. #if defined(WOLFSSL_ASYNC_CRYPT)
  9717. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9718. #endif
  9719. if (ret != 0)
  9720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9721. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9722. if ((j - k) < AES_BLOCK_SIZE*2)
  9723. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9724. else
  9725. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9726. #if defined(WOLFSSL_ASYNC_CRYPT)
  9727. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9728. #endif
  9729. if (ret != 0)
  9730. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9731. if ((j - k) < AES_BLOCK_SIZE*2)
  9732. break;
  9733. }
  9734. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9735. if (ret != 0)
  9736. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9737. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9738. sizeof(i1));
  9739. #if defined(WOLFSSL_ASYNC_CRYPT)
  9740. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9741. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9742. WC_ASYNC_FLAG_NONE);
  9743. #else
  9744. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9745. #endif
  9746. #endif
  9747. if (ret != 0)
  9748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9749. for (i = 0; i < j; i++) {
  9750. if (large_input[i] != (byte)i) {
  9751. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9752. }
  9753. }
  9754. }
  9755. /* second, encrypt with a one-shot call then decrypt block by block. */
  9756. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9757. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9758. if (ret != 0)
  9759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9760. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9761. sizeof(i1));
  9762. #if defined(WOLFSSL_ASYNC_CRYPT)
  9763. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9764. #endif
  9765. if (ret != 0)
  9766. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9767. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9768. if (ret != 0)
  9769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9770. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9771. #if defined(WOLFSSL_ASYNC_CRYPT)
  9772. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9773. #endif
  9774. if (ret != 0)
  9775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9776. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9777. if ((j - k) < AES_BLOCK_SIZE*2)
  9778. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9779. else
  9780. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9781. #if defined(WOLFSSL_ASYNC_CRYPT)
  9782. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9783. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9784. WC_ASYNC_FLAG_NONE);
  9785. #else
  9786. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9787. #endif
  9788. #endif
  9789. if (ret != 0)
  9790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9791. if ((j - k) < AES_BLOCK_SIZE*2)
  9792. break;
  9793. }
  9794. for (i = 0; i < j; i++) {
  9795. if (large_input[i] != (byte)i) {
  9796. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9797. }
  9798. }
  9799. }
  9800. #endif /* WOLFSSL_AESXTS_STREAM */
  9801. }
  9802. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  9803. * !WOLFSSL_AFALG
  9804. */
  9805. out:
  9806. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9807. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  9808. !defined(WOLFSSL_NO_MALLOC)
  9809. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9810. #endif
  9811. if (aes_inited)
  9812. wc_AesXtsFree(aes);
  9813. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9814. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9815. #endif
  9816. return ret;
  9817. }
  9818. #endif /* WOLFSSL_AES_128 */
  9819. #ifdef WOLFSSL_AES_192
  9820. static wc_test_ret_t aes_xts_192_test(void)
  9821. {
  9822. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9823. XtsAes *aes = NULL;
  9824. #else
  9825. XtsAes aes[1];
  9826. #endif
  9827. int aes_inited = 0;
  9828. wc_test_ret_t ret = 0;
  9829. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9830. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9831. #ifdef WOLFSSL_AESXTS_STREAM
  9832. struct XtsAesStreamData stream;
  9833. #endif
  9834. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9835. !defined(WOLFSSL_AFALG)
  9836. #define LARGE_XTS_SZ 1024
  9837. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9838. byte* large_input = NULL;
  9839. #else
  9840. byte large_input[LARGE_XTS_SZ];
  9841. #endif
  9842. #endif
  9843. /* 192 bit key tests */
  9844. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9845. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  9846. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  9847. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  9848. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  9849. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  9850. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3
  9851. };
  9852. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9853. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9854. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9855. };
  9856. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9857. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9858. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9859. };
  9860. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9861. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9862. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9863. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9864. };
  9865. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9866. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4,
  9867. 0xdb, 0x4e, 0xd3, 0x69, 0xdf, 0x8e, 0x3a, 0xe0
  9868. };
  9869. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9870. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  9871. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  9872. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  9873. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  9874. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  9875. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a
  9876. };
  9877. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9878. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9879. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9880. };
  9881. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9882. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9883. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9884. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9885. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9886. };
  9887. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9888. 0x6c, 0xa6, 0xb5, 0x73, 0x48, 0xf1, 0x89, 0xfa,
  9889. 0xdd, 0x80, 0x72, 0x1f, 0xb8, 0x56, 0x0c, 0xa2,
  9890. 0x35, 0xd4, 0x08, 0xbf, 0x24, 0xcb, 0xec, 0xdb,
  9891. 0x81, 0xe0, 0xe6, 0x4f, 0x3d, 0x1c, 0x5c, 0x46
  9892. };
  9893. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9894. 0xe9, 0x58, 0xfe, 0xab, 0x66, 0xb4, 0xf1, 0x79,
  9895. 0x91, 0x3f, 0x91, 0xdc, 0x6f, 0xdf, 0xd6, 0xac,
  9896. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4
  9897. };
  9898. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9899. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9900. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9901. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9902. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9903. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9904. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9905. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9906. };
  9907. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9908. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9909. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9910. };
  9911. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9912. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9913. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9914. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9915. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9916. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9917. };
  9918. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9919. 0xa4, 0xf2, 0x71, 0x5d, 0x80, 0x60, 0x68, 0xa0,
  9920. 0x80, 0x61, 0xd7, 0xc1, 0x55, 0xc8, 0x3a, 0x2e,
  9921. 0xd7, 0xf4, 0x62, 0xaf, 0xbd, 0x2d, 0xf9, 0x5f,
  9922. 0xe8, 0xc5, 0x99, 0x3d, 0x58, 0x3c, 0xeb, 0xba,
  9923. 0x86, 0xea, 0x2c, 0x7e, 0x1f, 0xba, 0x81, 0xde
  9924. };
  9925. #endif /* HAVE_FIPS */
  9926. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9927. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9928. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9929. #endif
  9930. XMEMSET(buf, 0, sizeof(buf));
  9931. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9932. if (ret != 0)
  9933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9934. else
  9935. aes_inited = 1;
  9936. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9937. if (ret != 0)
  9938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9939. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9940. #if defined(WOLFSSL_ASYNC_CRYPT)
  9941. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9942. #endif
  9943. if (ret != 0)
  9944. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9945. if (XMEMCMP(c2, buf, sizeof(c2)))
  9946. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9947. #ifdef WOLFSSL_AESXTS_STREAM
  9948. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9949. #if defined(WOLFSSL_ASYNC_CRYPT)
  9950. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9951. #endif
  9952. if (ret != 0)
  9953. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9954. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  9955. #if defined(WOLFSSL_ASYNC_CRYPT)
  9956. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9957. #endif
  9958. if (ret != 0)
  9959. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9960. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  9961. #if defined(WOLFSSL_ASYNC_CRYPT)
  9962. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9963. #endif
  9964. if (ret != 0)
  9965. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9966. if (XMEMCMP(c2, buf, sizeof(c2)))
  9967. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9968. #endif /* WOLFSSL_AESXTS_STREAM */
  9969. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9970. defined(WC_C_DYNAMIC_FALLBACK)
  9971. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9972. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9973. #if defined(WOLFSSL_ASYNC_CRYPT)
  9974. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9975. #endif
  9976. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9977. if (ret != 0)
  9978. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9979. if (XMEMCMP(c2, buf, sizeof(c2)))
  9980. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9981. #endif
  9982. XMEMSET(buf, 0, sizeof(buf));
  9983. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9984. if (ret != 0)
  9985. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9986. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9987. #if defined(WOLFSSL_ASYNC_CRYPT)
  9988. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9989. #endif
  9990. if (ret != 0)
  9991. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9992. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9993. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9994. #ifdef WOLFSSL_AESXTS_STREAM
  9995. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9996. #if defined(WOLFSSL_ASYNC_CRYPT)
  9997. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9998. #endif
  9999. if (ret != 0)
  10000. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10001. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10002. #if defined(WOLFSSL_ASYNC_CRYPT)
  10003. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10004. #endif
  10005. if (ret != 0)
  10006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10007. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10008. #if defined(WOLFSSL_ASYNC_CRYPT)
  10009. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10010. #endif
  10011. if (ret != 0)
  10012. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10013. if (XMEMCMP(c1, buf, sizeof(c1)))
  10014. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10015. #endif /* WOLFSSL_AESXTS_STREAM */
  10016. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10017. defined(WC_C_DYNAMIC_FALLBACK)
  10018. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10019. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10020. #if defined(WOLFSSL_ASYNC_CRYPT)
  10021. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10022. #endif
  10023. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10024. if (ret != 0)
  10025. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10026. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10027. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10028. #endif
  10029. /* partial block encryption test */
  10030. XMEMSET(cipher, 0, sizeof(cipher));
  10031. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10032. #if defined(WOLFSSL_ASYNC_CRYPT)
  10033. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10034. #endif
  10035. if (ret != 0)
  10036. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10037. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10038. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10039. #ifdef WOLFSSL_AESXTS_STREAM
  10040. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10041. #if defined(WOLFSSL_ASYNC_CRYPT)
  10042. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10043. #endif
  10044. if (ret != 0)
  10045. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10046. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  10047. #if defined(WOLFSSL_ASYNC_CRYPT)
  10048. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10049. #endif
  10050. if (ret != 0)
  10051. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10052. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10053. #if defined(WOLFSSL_ASYNC_CRYPT)
  10054. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10055. #endif
  10056. if (ret != 0)
  10057. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10058. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  10059. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10060. #endif /* WOLFSSL_AESXTS_STREAM */
  10061. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10062. defined(WC_C_DYNAMIC_FALLBACK)
  10063. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10064. XMEMSET(cipher, 0, sizeof(cipher));
  10065. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10066. #if defined(WOLFSSL_ASYNC_CRYPT)
  10067. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10068. #endif
  10069. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10070. if (ret != 0)
  10071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10072. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10073. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10074. #endif
  10075. /* partial block decrypt test */
  10076. XMEMSET(buf, 0, sizeof(buf));
  10077. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10078. if (ret != 0)
  10079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10080. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10081. #if defined(WOLFSSL_ASYNC_CRYPT)
  10082. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10083. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10084. #else
  10085. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10086. #endif
  10087. #endif
  10088. if (ret != 0)
  10089. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10090. if (XMEMCMP(pp, buf, sizeof(pp)))
  10091. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10092. #ifdef WOLFSSL_AESXTS_STREAM
  10093. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10094. #if defined(WOLFSSL_ASYNC_CRYPT)
  10095. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10096. #endif
  10097. if (ret != 0)
  10098. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10099. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  10100. #if defined(WOLFSSL_ASYNC_CRYPT)
  10101. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10102. #endif
  10103. if (ret != 0)
  10104. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10105. if (XMEMCMP(pp, buf, sizeof(pp)))
  10106. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10107. #endif /* WOLFSSL_AESXTS_STREAM */
  10108. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10109. defined(WC_C_DYNAMIC_FALLBACK)
  10110. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10111. XMEMSET(buf, 0, sizeof(buf));
  10112. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10113. #if defined(WOLFSSL_ASYNC_CRYPT)
  10114. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10115. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10116. #else
  10117. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10118. #endif
  10119. #endif
  10120. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10121. if (ret != 0)
  10122. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10123. if (XMEMCMP(pp, buf, sizeof(pp)))
  10124. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10125. #endif
  10126. /* NIST decrypt test vector */
  10127. XMEMSET(buf, 0, sizeof(buf));
  10128. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10129. #if defined(WOLFSSL_ASYNC_CRYPT)
  10130. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10131. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10132. #else
  10133. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10134. #endif
  10135. #endif
  10136. if (ret != 0)
  10137. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10138. if (XMEMCMP(p1, buf, sizeof(p1)))
  10139. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10140. #ifdef WOLFSSL_AESXTS_STREAM
  10141. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10142. #if defined(WOLFSSL_ASYNC_CRYPT)
  10143. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10144. #endif
  10145. if (ret != 0)
  10146. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10147. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10148. #if defined(WOLFSSL_ASYNC_CRYPT)
  10149. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10150. #endif
  10151. if (ret != 0)
  10152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10153. if (XMEMCMP(p1, buf, sizeof(p1)))
  10154. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10155. #endif /* WOLFSSL_AESXTS_STREAM */
  10156. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10157. defined(WC_C_DYNAMIC_FALLBACK)
  10158. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10159. XMEMSET(buf, 0, sizeof(buf));
  10160. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10161. #if defined(WOLFSSL_ASYNC_CRYPT)
  10162. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10163. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10164. #else
  10165. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10166. #endif
  10167. #endif
  10168. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10169. if (ret != 0)
  10170. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10171. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  10172. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10173. #endif
  10174. /* fail case with decrypting using wrong key */
  10175. XMEMSET(buf, 0, sizeof(buf));
  10176. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10177. #if defined(WOLFSSL_ASYNC_CRYPT)
  10178. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10179. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10180. #else
  10181. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10182. #endif
  10183. #endif
  10184. if (ret != 0)
  10185. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10186. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  10187. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10188. /* set correct key and retest */
  10189. XMEMSET(buf, 0, sizeof(buf));
  10190. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10191. if (ret != 0)
  10192. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10193. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10194. #if defined(WOLFSSL_ASYNC_CRYPT)
  10195. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10196. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10197. #else
  10198. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10199. #endif
  10200. #endif
  10201. if (ret != 0)
  10202. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10203. if (XMEMCMP(p2, buf, sizeof(p2)))
  10204. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10205. #ifndef HAVE_FIPS
  10206. /* Test ciphertext stealing in-place. */
  10207. XMEMCPY(buf, p3, sizeof(p3));
  10208. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  10209. if (ret != 0)
  10210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10211. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  10212. #if defined(WOLFSSL_ASYNC_CRYPT)
  10213. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10214. #endif
  10215. if (ret != 0)
  10216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10217. if (XMEMCMP(c3, buf, sizeof(c3)))
  10218. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10219. #ifdef WOLFSSL_AESXTS_STREAM
  10220. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  10221. #if defined(WOLFSSL_ASYNC_CRYPT)
  10222. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10223. #endif
  10224. if (ret != 0)
  10225. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10226. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  10227. #if defined(WOLFSSL_ASYNC_CRYPT)
  10228. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10229. #endif
  10230. if (ret != 0)
  10231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10232. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  10233. #if defined(WOLFSSL_ASYNC_CRYPT)
  10234. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10235. #endif
  10236. if (ret != 0)
  10237. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10238. if (XMEMCMP(c3, buf, sizeof(c3)))
  10239. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10240. #endif /* WOLFSSL_AESXTS_STREAM */
  10241. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  10242. if (ret != 0)
  10243. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10244. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  10245. #if defined(WOLFSSL_ASYNC_CRYPT)
  10246. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10247. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10248. #else
  10249. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10250. #endif
  10251. #endif
  10252. if (ret != 0)
  10253. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10254. if (XMEMCMP(p3, buf, sizeof(p3)))
  10255. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10256. #ifdef WOLFSSL_AESXTS_STREAM
  10257. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  10258. #if defined(WOLFSSL_ASYNC_CRYPT)
  10259. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10260. #endif
  10261. if (ret != 0)
  10262. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10263. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  10264. #if defined(WOLFSSL_ASYNC_CRYPT)
  10265. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10266. #endif
  10267. if (ret != 0)
  10268. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10269. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  10270. #if defined(WOLFSSL_ASYNC_CRYPT)
  10271. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10272. #endif
  10273. if (ret != 0)
  10274. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10275. if (XMEMCMP(p3, buf, sizeof(p3)))
  10276. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10277. #endif /* WOLFSSL_AESXTS_STREAM */
  10278. #endif /* !HAVE_FIPS */
  10279. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10280. !defined(WOLFSSL_AFALG)
  10281. {
  10282. int i;
  10283. int j;
  10284. #ifdef WOLFSSL_AESXTS_STREAM
  10285. int k;
  10286. #endif
  10287. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10288. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10289. DYNAMIC_TYPE_TMP_BUFFER);
  10290. if (large_input == NULL)
  10291. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10292. #endif
  10293. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10294. large_input[i] = (byte)i;
  10295. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10296. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10297. if (ret != 0)
  10298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10299. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10300. sizeof(i1));
  10301. #if defined(WOLFSSL_ASYNC_CRYPT)
  10302. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10303. #endif
  10304. if (ret != 0)
  10305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10306. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10307. if (ret != 0)
  10308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10309. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10310. sizeof(i1));
  10311. #if defined(WOLFSSL_ASYNC_CRYPT)
  10312. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10313. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10314. WC_ASYNC_FLAG_NONE);
  10315. #else
  10316. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10317. #endif
  10318. #endif
  10319. if (ret != 0)
  10320. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10321. for (i = 0; i < j; i++) {
  10322. if (large_input[i] != (byte)i) {
  10323. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10324. }
  10325. }
  10326. }
  10327. #ifdef WOLFSSL_AESXTS_STREAM
  10328. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10329. large_input[i] = (byte)i;
  10330. /* first, encrypt block by block then decrypt with a one-shot call. */
  10331. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10332. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10333. if (ret != 0)
  10334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10335. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10336. #if defined(WOLFSSL_ASYNC_CRYPT)
  10337. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10338. #endif
  10339. if (ret != 0)
  10340. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10341. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10342. if ((j - k) < AES_BLOCK_SIZE*2)
  10343. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10344. else
  10345. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10346. #if defined(WOLFSSL_ASYNC_CRYPT)
  10347. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10348. #endif
  10349. if (ret != 0)
  10350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10351. if ((j - k) < AES_BLOCK_SIZE*2)
  10352. break;
  10353. }
  10354. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10355. if (ret != 0)
  10356. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10357. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10358. sizeof(i1));
  10359. #if defined(WOLFSSL_ASYNC_CRYPT)
  10360. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10361. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10362. WC_ASYNC_FLAG_NONE);
  10363. #else
  10364. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10365. #endif
  10366. #endif
  10367. if (ret != 0)
  10368. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10369. for (i = 0; i < j; i++) {
  10370. if (large_input[i] != (byte)i) {
  10371. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10372. }
  10373. }
  10374. }
  10375. /* second, encrypt with a one-shot call then decrypt block by block. */
  10376. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10377. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10378. if (ret != 0)
  10379. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10380. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10381. sizeof(i1));
  10382. #if defined(WOLFSSL_ASYNC_CRYPT)
  10383. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10384. #endif
  10385. if (ret != 0)
  10386. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10387. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10388. if (ret != 0)
  10389. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10390. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10391. #if defined(WOLFSSL_ASYNC_CRYPT)
  10392. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10393. #endif
  10394. if (ret != 0)
  10395. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10396. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10397. if ((j - k) < AES_BLOCK_SIZE*2)
  10398. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10399. else
  10400. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10401. #if defined(WOLFSSL_ASYNC_CRYPT)
  10402. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10403. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10404. WC_ASYNC_FLAG_NONE);
  10405. #else
  10406. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10407. #endif
  10408. #endif
  10409. if (ret != 0)
  10410. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10411. if ((j - k) < AES_BLOCK_SIZE*2)
  10412. break;
  10413. }
  10414. for (i = 0; i < j; i++) {
  10415. if (large_input[i] != (byte)i) {
  10416. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10417. }
  10418. }
  10419. }
  10420. #endif /* WOLFSSL_AESXTS_STREAM */
  10421. }
  10422. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10423. * !WOLFSSL_AFALG
  10424. */
  10425. out:
  10426. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10427. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10428. !defined(WOLFSSL_NO_MALLOC)
  10429. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10430. #endif
  10431. if (aes_inited)
  10432. wc_AesXtsFree(aes);
  10433. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10434. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10435. #endif
  10436. return ret;
  10437. }
  10438. #endif /* WOLFSSL_AES_192 */
  10439. #ifdef WOLFSSL_AES_256
  10440. static wc_test_ret_t aes_xts_256_test(void)
  10441. {
  10442. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10443. XtsAes *aes = NULL;
  10444. #else
  10445. XtsAes aes[1];
  10446. #endif
  10447. int aes_inited = 0;
  10448. wc_test_ret_t ret = 0;
  10449. unsigned char buf[AES_BLOCK_SIZE * 3];
  10450. unsigned char cipher[AES_BLOCK_SIZE * 3];
  10451. #ifdef WOLFSSL_AESXTS_STREAM
  10452. struct XtsAesStreamData stream;
  10453. #endif
  10454. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10455. !defined(WOLFSSL_AFALG)
  10456. #define LARGE_XTS_SZ 1024
  10457. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10458. byte* large_input = NULL;
  10459. #else
  10460. byte large_input[LARGE_XTS_SZ];
  10461. #endif
  10462. #endif
  10463. /* 256 key tests */
  10464. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10465. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  10466. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  10467. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  10468. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  10469. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  10470. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3,
  10471. 0xd6, 0x19, 0xb7, 0xe2, 0xb9, 0x14, 0x1e, 0x58,
  10472. 0x31, 0x8e, 0xea, 0x39, 0x2c, 0xf4, 0x1b, 0x08
  10473. };
  10474. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  10475. 0xad, 0xf8, 0xd9, 0x26, 0x27, 0x46, 0x4a, 0xd2,
  10476. 0xf0, 0x42, 0x8e, 0x84, 0xa9, 0xf8, 0x75, 0x64
  10477. };
  10478. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10479. 0x2e, 0xed, 0xea, 0x52, 0xcd, 0x82, 0x15, 0xe1,
  10480. 0xac, 0xc6, 0x47, 0xe8, 0x10, 0xbb, 0xc3, 0x64,
  10481. 0x2e, 0x87, 0x28, 0x7f, 0x8d, 0x2e, 0x57, 0xe3,
  10482. 0x6c, 0x0a, 0x24, 0xfb, 0xc1, 0x2a, 0x20, 0x2e
  10483. };
  10484. /* plain text test of partial block is not from NIST test vector list */
  10485. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  10486. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  10487. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  10488. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  10489. };
  10490. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10491. 0xcb, 0xaa, 0xd0, 0xe2, 0xf6, 0xce, 0xa3, 0xf5,
  10492. 0x0b, 0x37, 0xf9, 0x34, 0xd4, 0x6a, 0x9b, 0x13,
  10493. 0x0b, 0x9d, 0x54, 0xf0, 0x7e, 0x34, 0xf3, 0x6a,
  10494. 0xf7, 0x93, 0xe8, 0x6f, 0x73, 0xc6, 0xd7, 0xdb
  10495. };
  10496. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10497. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10498. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10499. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10500. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10501. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10502. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a,
  10503. 0xb5, 0xb0, 0xc7, 0xe5, 0x2d, 0xb5, 0x06, 0x12,
  10504. 0xd2, 0xb5, 0x3a, 0xcb, 0x47, 0x8a, 0x53, 0xb4
  10505. };
  10506. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10507. 0xe6, 0x42, 0x19, 0xed, 0xe0, 0xe1, 0xc2, 0xa0,
  10508. 0x0e, 0xf5, 0x58, 0x6a, 0xc4, 0x9b, 0xeb, 0x6f
  10509. };
  10510. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10511. 0x24, 0xcb, 0x76, 0x22, 0x55, 0xb5, 0xa8, 0x00,
  10512. 0xf4, 0x6e, 0x80, 0x60, 0x56, 0x9e, 0x05, 0x53,
  10513. 0xbc, 0xfe, 0x86, 0x55, 0x3b, 0xca, 0xd5, 0x89,
  10514. 0xc7, 0x54, 0x1a, 0x73, 0xac, 0xc3, 0x9a, 0xbd,
  10515. 0x53, 0xc4, 0x07, 0x76, 0xd8, 0xe8, 0x22, 0x61,
  10516. 0x9e, 0xa9, 0xad, 0x77, 0xa0, 0x13, 0x4c, 0xfc
  10517. };
  10518. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10519. 0xa3, 0xc6, 0xf3, 0xf3, 0x82, 0x79, 0x5b, 0x10,
  10520. 0x87, 0xd7, 0x02, 0x50, 0xdb, 0x2c, 0xd3, 0xb1,
  10521. 0xa1, 0x62, 0xa8, 0xb6, 0xdc, 0x12, 0x60, 0x61,
  10522. 0xc1, 0x0a, 0x84, 0xa5, 0x85, 0x3f, 0x3a, 0x89,
  10523. 0xe6, 0x6c, 0xdb, 0xb7, 0x9a, 0xb4, 0x28, 0x9b,
  10524. 0xc3, 0xea, 0xd8, 0x10, 0xe9, 0xc0, 0xaf, 0x92
  10525. };
  10526. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10527. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10528. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10529. #endif
  10530. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  10531. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  10532. ret = EVP_test(EVP_aes_256_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  10533. if (ret != 0) {
  10534. printf("EVP_aes_256_xts failed\n");
  10535. goto out;
  10536. }
  10537. #endif
  10538. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10539. if (ret != 0)
  10540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10541. else
  10542. aes_inited = 1;
  10543. XMEMSET(buf, 0, sizeof(buf));
  10544. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10545. if (ret != 0)
  10546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10547. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10548. #if defined(WOLFSSL_ASYNC_CRYPT)
  10549. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10550. #endif
  10551. if (ret != 0)
  10552. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10553. if (XMEMCMP(c2, buf, sizeof(c2)))
  10554. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10555. #ifdef WOLFSSL_AESXTS_STREAM
  10556. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10557. #if defined(WOLFSSL_ASYNC_CRYPT)
  10558. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10559. #endif
  10560. if (ret != 0)
  10561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10562. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  10563. #if defined(WOLFSSL_ASYNC_CRYPT)
  10564. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10565. #endif
  10566. if (ret != 0)
  10567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10568. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  10569. #if defined(WOLFSSL_ASYNC_CRYPT)
  10570. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10571. #endif
  10572. if (ret != 0)
  10573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10574. if (XMEMCMP(c2, buf, sizeof(c2)))
  10575. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10576. #endif /* WOLFSSL_AESXTS_STREAM */
  10577. XMEMSET(buf, 0, sizeof(buf));
  10578. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10579. if (ret != 0)
  10580. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10581. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10582. #if defined(WOLFSSL_ASYNC_CRYPT)
  10583. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10584. #endif
  10585. if (ret != 0)
  10586. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10587. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10588. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10589. #ifdef WOLFSSL_AESXTS_STREAM
  10590. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10591. #if defined(WOLFSSL_ASYNC_CRYPT)
  10592. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10593. #endif
  10594. if (ret != 0)
  10595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10596. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10597. #if defined(WOLFSSL_ASYNC_CRYPT)
  10598. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10599. #endif
  10600. if (ret != 0)
  10601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10602. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10603. #if defined(WOLFSSL_ASYNC_CRYPT)
  10604. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10605. #endif
  10606. if (ret != 0)
  10607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10608. if (XMEMCMP(c1, buf, sizeof(c1)))
  10609. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10610. #endif /* WOLFSSL_AESXTS_STREAM */
  10611. /* partial block encryption test */
  10612. XMEMSET(cipher, 0, sizeof(cipher));
  10613. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10614. #if defined(WOLFSSL_ASYNC_CRYPT)
  10615. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10616. #endif
  10617. if (ret != 0)
  10618. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10619. /* partial block decrypt test */
  10620. XMEMSET(buf, 0, sizeof(buf));
  10621. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10622. if (ret != 0)
  10623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10624. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10625. #if defined(WOLFSSL_ASYNC_CRYPT)
  10626. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10627. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10628. #else
  10629. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10630. #endif
  10631. #endif
  10632. if (ret != 0)
  10633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10634. if (XMEMCMP(pp, buf, sizeof(pp)))
  10635. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10636. /* NIST decrypt test vector */
  10637. XMEMSET(buf, 0, sizeof(buf));
  10638. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10639. #if defined(WOLFSSL_ASYNC_CRYPT)
  10640. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10641. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10642. #else
  10643. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10644. #endif
  10645. #endif
  10646. if (ret != 0)
  10647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10648. if (XMEMCMP(p1, buf, sizeof(p1)))
  10649. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10650. #ifdef WOLFSSL_AESXTS_STREAM
  10651. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10652. #if defined(WOLFSSL_ASYNC_CRYPT)
  10653. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10654. #endif
  10655. if (ret != 0)
  10656. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10657. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10658. #if defined(WOLFSSL_ASYNC_CRYPT)
  10659. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10660. #endif
  10661. if (ret != 0)
  10662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10663. if (XMEMCMP(p1, buf, sizeof(p1)))
  10664. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10665. #endif /* WOLFSSL_AESXTS_STREAM */
  10666. XMEMSET(buf, 0, sizeof(buf));
  10667. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10668. if (ret != 0)
  10669. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10670. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10671. #if defined(WOLFSSL_ASYNC_CRYPT)
  10672. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10673. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10674. #else
  10675. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10676. #endif
  10677. #endif
  10678. if (ret != 0)
  10679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10680. if (XMEMCMP(p2, buf, sizeof(p2)))
  10681. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10682. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10683. !defined(WOLFSSL_AFALG)
  10684. {
  10685. int i;
  10686. int j;
  10687. #ifdef WOLFSSL_AESXTS_STREAM
  10688. int k;
  10689. #endif
  10690. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10691. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10692. DYNAMIC_TYPE_TMP_BUFFER);
  10693. if (large_input == NULL)
  10694. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10695. #endif
  10696. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10697. large_input[i] = (byte)i;
  10698. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10699. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10700. if (ret != 0)
  10701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10702. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10703. sizeof(i1));
  10704. #if defined(WOLFSSL_ASYNC_CRYPT)
  10705. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10706. #endif
  10707. if (ret != 0)
  10708. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10709. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10710. if (ret != 0)
  10711. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10712. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10713. sizeof(i1));
  10714. #if defined(WOLFSSL_ASYNC_CRYPT)
  10715. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10716. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10717. WC_ASYNC_FLAG_NONE);
  10718. #else
  10719. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10720. #endif
  10721. #endif
  10722. if (ret != 0)
  10723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10724. for (i = 0; i < j; i++) {
  10725. if (large_input[i] != (byte)i) {
  10726. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10727. }
  10728. }
  10729. }
  10730. #ifdef WOLFSSL_AESXTS_STREAM
  10731. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10732. large_input[i] = (byte)i;
  10733. /* first, encrypt block by block then decrypt with a one-shot call. */
  10734. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10735. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10736. if (ret != 0)
  10737. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10738. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10739. #if defined(WOLFSSL_ASYNC_CRYPT)
  10740. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10741. #endif
  10742. if (ret != 0)
  10743. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10744. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10745. if ((j - k) < AES_BLOCK_SIZE*2)
  10746. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10747. else
  10748. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10749. #if defined(WOLFSSL_ASYNC_CRYPT)
  10750. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10751. #endif
  10752. if (ret != 0)
  10753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10754. if ((j - k) < AES_BLOCK_SIZE*2)
  10755. break;
  10756. }
  10757. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10758. if (ret != 0)
  10759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10760. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10761. sizeof(i1));
  10762. #if defined(WOLFSSL_ASYNC_CRYPT)
  10763. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10764. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10765. WC_ASYNC_FLAG_NONE);
  10766. #else
  10767. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10768. #endif
  10769. #endif
  10770. if (ret != 0)
  10771. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10772. for (i = 0; i < j; i++) {
  10773. if (large_input[i] != (byte)i) {
  10774. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10775. }
  10776. }
  10777. }
  10778. /* second, encrypt with a one-shot call then decrypt block by block. */
  10779. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10780. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10781. if (ret != 0)
  10782. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10783. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10784. sizeof(i1));
  10785. #if defined(WOLFSSL_ASYNC_CRYPT)
  10786. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10787. #endif
  10788. if (ret != 0)
  10789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10790. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10791. if (ret != 0)
  10792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10793. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10794. #if defined(WOLFSSL_ASYNC_CRYPT)
  10795. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10796. #endif
  10797. if (ret != 0)
  10798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10799. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10800. if ((j - k) < AES_BLOCK_SIZE*2)
  10801. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10802. else
  10803. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10804. #if defined(WOLFSSL_ASYNC_CRYPT)
  10805. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10806. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10807. WC_ASYNC_FLAG_NONE);
  10808. #else
  10809. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10810. #endif
  10811. #endif
  10812. if (ret != 0)
  10813. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10814. if ((j - k) < AES_BLOCK_SIZE*2)
  10815. break;
  10816. }
  10817. for (i = 0; i < j; i++) {
  10818. if (large_input[i] != (byte)i) {
  10819. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10820. }
  10821. }
  10822. }
  10823. #endif /* WOLFSSL_AESXTS_STREAM */
  10824. }
  10825. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10826. * !WOLFSSL_AFALG
  10827. */
  10828. out:
  10829. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10830. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10831. !defined(WOLFSSL_NO_MALLOC)
  10832. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10833. #endif
  10834. if (aes_inited)
  10835. wc_AesXtsFree(aes);
  10836. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10837. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10838. #endif
  10839. return ret;
  10840. }
  10841. #endif /* WOLFSSL_AES_256 */
  10842. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  10843. /* both 128 and 256 bit key test */
  10844. static wc_test_ret_t aes_xts_sector_test(void)
  10845. {
  10846. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10847. XtsAes *aes = NULL;
  10848. #else
  10849. XtsAes aes[1];
  10850. #endif
  10851. int aes_inited = 0;
  10852. wc_test_ret_t ret = 0;
  10853. unsigned char buf[AES_BLOCK_SIZE * 2];
  10854. /* 128 key tests */
  10855. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10856. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  10857. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  10858. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  10859. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  10860. };
  10861. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10862. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  10863. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  10864. };
  10865. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10866. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  10867. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  10868. };
  10869. word64 s1 = 141;
  10870. /* 256 key tests */
  10871. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10872. 0xef, 0x01, 0x0c, 0xa1, 0xa3, 0x66, 0x3e, 0x32,
  10873. 0x53, 0x43, 0x49, 0xbc, 0x0b, 0xae, 0x62, 0x23,
  10874. 0x2a, 0x15, 0x73, 0x34, 0x85, 0x68, 0xfb, 0x9e,
  10875. 0xf4, 0x17, 0x68, 0xa7, 0x67, 0x4f, 0x50, 0x7a,
  10876. 0x72, 0x7f, 0x98, 0x75, 0x53, 0x97, 0xd0, 0xe0,
  10877. 0xaa, 0x32, 0xf8, 0x30, 0x33, 0x8c, 0xc7, 0xa9,
  10878. 0x26, 0xc7, 0x73, 0xf0, 0x9e, 0x57, 0xb3, 0x57,
  10879. 0xcd, 0x15, 0x6a, 0xfb, 0xca, 0x46, 0xe1, 0xa0
  10880. };
  10881. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10882. 0xed, 0x98, 0xe0, 0x17, 0x70, 0xa8, 0x53, 0xb4,
  10883. 0x9d, 0xb9, 0xe6, 0xaa, 0xf8, 0x8f, 0x0a, 0x41,
  10884. 0xb9, 0xb5, 0x6e, 0x91, 0xa5, 0xa2, 0xb1, 0x1d,
  10885. 0x40, 0x52, 0x92, 0x54, 0xf5, 0x52, 0x3e, 0x75
  10886. };
  10887. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10888. 0xca, 0x20, 0xc5, 0x5e, 0x8d, 0xc1, 0x49, 0x68,
  10889. 0x7d, 0x25, 0x41, 0xde, 0x39, 0xc3, 0xdf, 0x63,
  10890. 0x00, 0xbb, 0x5a, 0x16, 0x3c, 0x10, 0xce, 0xd3,
  10891. 0x66, 0x6b, 0x13, 0x57, 0xdb, 0x8b, 0xd3, 0x9d
  10892. };
  10893. word64 s2 = 187;
  10894. #if !defined(BENCH_EMBEDDED) && \
  10895. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  10896. /* Sector size for encrypt/decrypt consecutive sectors testcase */
  10897. word32 sectorSz = 512;
  10898. unsigned char data[550];
  10899. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  10900. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  10901. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  10902. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  10903. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
  10904. };
  10905. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  10906. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  10907. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  10908. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  10909. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  10910. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  10911. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  10912. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  10913. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  10914. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  10915. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  10916. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  10917. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  10918. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  10919. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  10920. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  10921. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  10922. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  10923. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  10924. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  10925. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  10926. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  10927. 0xfc, 0xfd, 0xfe, 0xff,
  10928. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  10929. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  10930. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  10931. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  10932. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  10933. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  10934. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  10935. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  10936. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  10937. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  10938. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  10939. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  10940. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  10941. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  10942. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  10943. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  10944. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  10945. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  10946. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  10947. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  10948. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  10949. 0xfc, 0xfd, 0xfe, 0xff,
  10950. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  10951. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  10952. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  10953. };
  10954. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  10955. 0xb9, 0x6b, 0x2b, 0xfd, 0x61, 0x87, 0x84, 0xd5, 0x26, 0xd2, 0x8c, 0x62,
  10956. 0x63, 0x01, 0xca, 0x46, 0xb1, 0x82, 0xfa, 0xdc, 0xbc, 0x32, 0x18, 0xe9,
  10957. 0xda, 0xe6, 0xda, 0xd1, 0x1a, 0x52, 0x77, 0xca, 0xdb, 0x0e, 0xbe, 0x37,
  10958. 0x88, 0x36, 0x1c, 0x87, 0x16, 0x60, 0xfe, 0xa8, 0x9e, 0xf6, 0x48, 0x64,
  10959. 0x94, 0x34, 0x64, 0xed, 0xf6, 0x9a, 0xc5, 0x28, 0xc9, 0xed, 0x64, 0x80,
  10960. 0x85, 0xd8, 0x93, 0xa7, 0x50, 0xb1, 0x9d, 0x2f, 0x1e, 0x34, 0xcc, 0xb4,
  10961. 0x03, 0xfb, 0x6b, 0x43, 0x21, 0xa8, 0x5b, 0xc6, 0x59, 0x13, 0xd2, 0xb5,
  10962. 0xf5, 0x7b, 0xf6, 0xb2, 0xa4, 0x7a, 0xd2, 0x50, 0x26, 0xcb, 0xa4, 0x83,
  10963. 0xc3, 0x56, 0xb0, 0xb1, 0x14, 0x34, 0x12, 0x1b, 0xea, 0x26, 0x97, 0x24,
  10964. 0x54, 0xcc, 0x32, 0x4c, 0xa4, 0xc2, 0xa3, 0x07, 0xfa, 0x30, 0xa9, 0xf0,
  10965. 0x91, 0x17, 0x60, 0x68, 0x88, 0x7f, 0x34, 0x7e, 0xbd, 0x20, 0x33, 0x95,
  10966. 0x6e, 0xc0, 0xb6, 0x2b, 0xff, 0x7e, 0x61, 0x35, 0x9a, 0x88, 0xff, 0xd9,
  10967. 0x69, 0x21, 0xe7, 0x8f, 0x45, 0x02, 0xf9, 0xd7, 0xeb, 0xa6, 0x53, 0xf1,
  10968. 0x73, 0x04, 0xf1, 0x0b, 0x85, 0xc6, 0x1f, 0x4a, 0x51, 0x2f, 0x95, 0x87,
  10969. 0x5a, 0x67, 0x37, 0xb2, 0x87, 0xf7, 0xbe, 0x2a, 0x17, 0x57, 0xca, 0xfc,
  10970. 0xdd, 0x5f, 0x37, 0x48, 0x78, 0xbd, 0xfa, 0x75, 0xc9, 0xfa, 0x86, 0x7e,
  10971. 0xc4, 0x0f, 0x60, 0x85, 0xce, 0x12, 0x44, 0x7c, 0xd9, 0xb2, 0x50, 0xd9,
  10972. 0x57, 0x85, 0xa5, 0xd7, 0x68, 0x59, 0x03, 0x09, 0x97, 0x2e, 0x8e, 0xa5,
  10973. 0xe3, 0x98, 0xac, 0x16, 0xfb, 0x6d, 0x54, 0xc5, 0x5d, 0x7a, 0x33, 0x44,
  10974. 0x0a, 0x39, 0x91, 0xcc, 0x9f, 0x67, 0xf9, 0x89, 0xbb, 0x62, 0x02, 0xc4,
  10975. 0x22, 0xec, 0xcf, 0x97, 0x69, 0x81, 0x3d, 0x00, 0xfd, 0xeb, 0x55, 0x08,
  10976. 0xa2, 0xff, 0x97, 0xaa, 0x79, 0xde, 0x3c, 0x8a, 0x78, 0x71, 0x73, 0xa2,
  10977. 0x98, 0x2f, 0xd8, 0x5c, 0x62, 0x1c, 0x5c, 0x23, 0x0a, 0xd1, 0xf1, 0x81,
  10978. 0x8a, 0x12, 0xe7, 0x4d, 0xdd, 0x4f, 0xd4, 0xf1, 0xe8, 0x0f, 0x25, 0x79,
  10979. 0x45, 0x4a, 0x49, 0x49, 0x7e, 0x56, 0x91, 0x4e, 0xaa, 0xba, 0x18, 0xe1,
  10980. 0xe4, 0xbe, 0x21, 0xdc, 0x58, 0x60, 0x6f, 0x6a, 0x7f, 0xdc, 0x5e, 0x74,
  10981. 0x47, 0xbf, 0xeb, 0x84, 0xc4, 0x1e, 0x5a, 0x61, 0x64, 0xc8, 0x63, 0x68,
  10982. 0xfa, 0x17, 0x9c, 0xac, 0x60, 0x1c, 0xa5, 0x6e, 0x00, 0x21, 0x93, 0x3c,
  10983. 0xd7, 0xbb, 0x73, 0x45, 0xf7, 0x34, 0x81, 0x6c, 0xfa, 0xf2, 0x33, 0xfd,
  10984. 0xb1, 0x40, 0x30, 0x6b, 0x30, 0xd1, 0x83, 0x5e, 0x2e, 0x7a, 0xce, 0xa6,
  10985. 0x12, 0x2a, 0x15, 0x03, 0x78, 0x29, 0xb9, 0x07, 0xae, 0xe7, 0xc2, 0x78,
  10986. 0x74, 0x72, 0xa5, 0x0e, 0x6b, 0x1f, 0x78, 0xf2, 0x5a, 0x69, 0xb6, 0x2b,
  10987. 0x99, 0x94, 0x1f, 0x89, 0xd1, 0x21, 0x14, 0x4a, 0x54, 0xab, 0x5a, 0x9f,
  10988. 0xaa, 0xa7, 0x96, 0x0a, 0x21, 0xce, 0x30, 0xb6, 0x70, 0x81, 0xe9, 0xd3,
  10989. 0x71, 0xc0, 0xf1, 0x15, 0xe2, 0xf6, 0xd3, 0xcc, 0x41, 0x15, 0x9d, 0xd5,
  10990. 0xa3, 0xa4, 0xe0, 0xf8, 0x62, 0xc4, 0x76, 0x65, 0x63, 0x89, 0xa7, 0xe2,
  10991. 0xfb, 0xf5, 0xc9, 0x80, 0x15, 0x5b, 0xc1, 0x59, 0xb2, 0xd0, 0x01, 0x3a,
  10992. 0xf9, 0xab, 0x5b, 0x79, 0x54, 0xed, 0x6b, 0xf9, 0x1d, 0x9d, 0x87, 0x63,
  10993. 0x80, 0x4f, 0xec, 0x9c, 0x4f, 0xad, 0x97, 0x04, 0xff, 0x62, 0x4a, 0x17,
  10994. 0xc0, 0x09, 0x2a, 0x2c, 0x23, 0x4b, 0xc3, 0xb6, 0x6d, 0xed, 0xdb, 0x1a,
  10995. 0x6f, 0x56, 0x2b, 0x78, 0x92, 0x3a, 0x5c, 0x7f, 0xb2, 0x63, 0xd3, 0xd5,
  10996. 0x1a, 0xbe, 0xc2, 0x34, 0xc8, 0xad, 0x36, 0xb7, 0x12, 0xb8, 0xe1, 0xb7,
  10997. 0x52, 0x7f, 0x16, 0x84, 0x2c, 0x47, 0x7e, 0xf2, 0xa5, 0x36, 0x2e, 0xad,
  10998. 0xe7, 0xbb, 0xc0, 0x6f, 0x27, 0x8e, 0x41, 0x08, 0x75, 0xe5, 0xff, 0xde,
  10999. 0x08, 0x9f, 0x8c, 0x91, 0xba, 0xc9, 0x9d, 0x9f, 0x27, 0x90, 0x50, 0x44,
  11000. 0x24, 0xe7, 0x3d, 0x6f
  11001. };
  11002. word64 s3 = 0x000000ffffffffff;
  11003. #endif
  11004. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11005. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11006. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11007. #endif
  11008. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11009. if (ret != 0)
  11010. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11011. else
  11012. aes_inited = 1;
  11013. XMEMSET(buf, 0, sizeof(buf));
  11014. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11015. if (ret != 0)
  11016. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11017. ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1);
  11018. #if defined(WOLFSSL_ASYNC_CRYPT)
  11019. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11020. #endif
  11021. if (ret != 0)
  11022. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11023. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  11024. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11025. /* decrypt test */
  11026. XMEMSET(buf, 0, sizeof(buf));
  11027. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11028. if (ret != 0)
  11029. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11030. ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1);
  11031. #if defined(WOLFSSL_ASYNC_CRYPT)
  11032. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11033. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11034. #else
  11035. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11036. #endif
  11037. #endif
  11038. if (ret != 0)
  11039. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11040. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  11041. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11042. /* 256 bit key tests */
  11043. XMEMSET(buf, 0, sizeof(buf));
  11044. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  11045. if (ret != 0)
  11046. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11047. ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2);
  11048. #if defined(WOLFSSL_ASYNC_CRYPT)
  11049. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11050. #endif
  11051. if (ret != 0)
  11052. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11053. if (XMEMCMP(c2, buf, sizeof(c2)))
  11054. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11055. /* decrypt test */
  11056. XMEMSET(buf, 0, sizeof(buf));
  11057. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  11058. if (ret != 0)
  11059. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11060. ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2);
  11061. #if defined(WOLFSSL_ASYNC_CRYPT)
  11062. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11063. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11064. #else
  11065. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11066. #endif
  11067. #endif
  11068. if (ret != 0)
  11069. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11070. if (XMEMCMP(p2, buf, sizeof(p2)))
  11071. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11072. #if !defined(BENCH_EMBEDDED) && \
  11073. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11074. /* encrypt consecutive sectors test */
  11075. XMEMSET(data, 0, sizeof(buf));
  11076. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  11077. if (ret != 0)
  11078. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11079. ret = wc_AesXtsEncryptConsecutiveSectors(aes, data, p3,
  11080. sizeof(p3), s3, sectorSz);
  11081. #if defined(WOLFSSL_ASYNC_CRYPT)
  11082. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11083. #endif
  11084. if (ret != 0)
  11085. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11086. if (XMEMCMP(c3, data, sizeof(c3)))
  11087. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11088. /* decrypt consecutive sectors test */
  11089. XMEMSET(data, 0, sizeof(buf));
  11090. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  11091. if (ret != 0)
  11092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11093. ret = wc_AesXtsDecryptConsecutiveSectors(aes, data, c3,
  11094. sizeof(c3), s3, sectorSz);
  11095. #if defined(WOLFSSL_ASYNC_CRYPT)
  11096. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11097. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11098. #else
  11099. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11100. #endif
  11101. #endif
  11102. if (ret != 0)
  11103. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11104. if (XMEMCMP(p3, data, sizeof(p3)))
  11105. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11106. #endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */
  11107. out:
  11108. if (aes_inited)
  11109. wc_AesXtsFree(aes);
  11110. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11111. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11112. #endif
  11113. return ret;
  11114. }
  11115. #endif /* WOLFSSL_AES_128 && WOLFSSL_AES_256 */
  11116. #ifdef WOLFSSL_AES_128
  11117. /* testing of bad arguments */
  11118. static wc_test_ret_t aes_xts_args_test(void)
  11119. {
  11120. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11121. XtsAes *aes = NULL;
  11122. #else
  11123. XtsAes aes[1];
  11124. #endif
  11125. int aes_inited = 0;
  11126. wc_test_ret_t ret;
  11127. unsigned char buf[AES_BLOCK_SIZE * 2];
  11128. /* 128 key tests */
  11129. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  11130. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  11131. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  11132. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  11133. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  11134. };
  11135. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  11136. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  11137. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  11138. };
  11139. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  11140. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  11141. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  11142. };
  11143. word64 s1 = 141;
  11144. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11145. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11146. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11147. #endif
  11148. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11149. if (ret != 0)
  11150. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11151. else
  11152. aes_inited = 1;
  11153. if (wc_AesXtsSetKeyNoInit(NULL, k1, sizeof(k1), AES_ENCRYPTION) == 0)
  11154. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11155. if (wc_AesXtsSetKeyNoInit(aes, NULL, sizeof(k1), AES_ENCRYPTION) == 0)
  11156. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11157. /* encryption operations */
  11158. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11159. if (ret != 0)
  11160. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11161. ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1);
  11162. #if defined(WOLFSSL_ASYNC_CRYPT)
  11163. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11164. #endif
  11165. if (ret == 0)
  11166. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11167. ret = wc_AesXtsEncryptSector(aes, NULL, p1, sizeof(p1), s1);
  11168. #if defined(WOLFSSL_ASYNC_CRYPT)
  11169. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11170. #endif
  11171. if (ret == 0)
  11172. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11173. /* decryption operations */
  11174. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11175. if (ret != 0)
  11176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11177. ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1);
  11178. #if defined(WOLFSSL_ASYNC_CRYPT)
  11179. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11180. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11181. #else
  11182. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11183. #endif
  11184. #endif
  11185. if (ret == 0)
  11186. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11187. ret = wc_AesXtsDecryptSector(aes, NULL, c1, sizeof(c1), s1);
  11188. #if defined(WOLFSSL_ASYNC_CRYPT)
  11189. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11190. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11191. #else
  11192. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11193. #endif
  11194. #endif
  11195. if (ret == 0)
  11196. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11197. ret = 0;
  11198. out:
  11199. if (aes_inited)
  11200. wc_AesXtsFree(aes);
  11201. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11202. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11203. #endif
  11204. return ret;
  11205. }
  11206. #endif /* WOLFSSL_AES_128 */
  11207. #endif /* WOLFSSL_AES_XTS && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  11208. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  11209. static wc_test_ret_t aes_cbc_test(void)
  11210. {
  11211. byte cipher[AES_BLOCK_SIZE];
  11212. byte plain[AES_BLOCK_SIZE];
  11213. wc_test_ret_t ret;
  11214. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  11215. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  11216. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  11217. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  11218. };
  11219. byte key[] = "0123456789abcdef "; /* align */
  11220. byte iv[] = "1234567890abcdef "; /* align */
  11221. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11222. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11223. /* Parameter Validation testing. */
  11224. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, 17, NULL);
  11225. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11226. return WC_TEST_RET_ENC_EC(ret);
  11227. #ifdef HAVE_AES_DECRYPT
  11228. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, 17, NULL);
  11229. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11230. return WC_TEST_RET_ENC_EC(ret);
  11231. #endif
  11232. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key,
  11233. AES_BLOCK_SIZE, iv);
  11234. if (ret != 0)
  11235. return WC_TEST_RET_ENC_EC(ret);
  11236. #ifdef HAVE_AES_DECRYPT
  11237. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key,
  11238. AES_BLOCK_SIZE, iv);
  11239. if (ret != 0)
  11240. return WC_TEST_RET_ENC_EC(ret);
  11241. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0)
  11242. return WC_TEST_RET_ENC_NC;
  11243. #endif /* HAVE_AES_DECRYPT */
  11244. (void)plain;
  11245. return 0;
  11246. }
  11247. #endif
  11248. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  11249. static wc_test_ret_t aesecb_test(void)
  11250. {
  11251. wc_test_ret_t ret = 0;
  11252. #if defined(WOLFSSL_AES_256)
  11253. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11254. Aes *enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  11255. #else
  11256. Aes enc[1];
  11257. #endif
  11258. int enc_inited = 0;
  11259. byte cipher[AES_BLOCK_SIZE * 4];
  11260. #ifdef HAVE_AES_DECRYPT
  11261. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11262. Aes *dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  11263. #else
  11264. Aes dec[1];
  11265. #endif
  11266. int dec_inited = 0;
  11267. byte plain[AES_BLOCK_SIZE * 4];
  11268. #endif /* HAVE_AES_DECRYPT */
  11269. {
  11270. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  11271. {
  11272. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11273. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  11274. };
  11275. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  11276. {
  11277. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  11278. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  11279. };
  11280. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  11281. {
  11282. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11283. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11284. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11285. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11286. };
  11287. ret = wc_AesInit(enc, HEAP_HINT, devId);
  11288. if (ret != 0)
  11289. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11290. enc_inited = 1;
  11291. #if defined(HAVE_AES_DECRYPT)
  11292. ret = wc_AesInit(dec, HEAP_HINT, devId);
  11293. if (ret != 0)
  11294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11295. dec_inited = 1;
  11296. #endif
  11297. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11298. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  11299. if (ret != 0)
  11300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11301. if (wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE) != 0)
  11302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11303. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  11304. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11305. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11306. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11307. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11308. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  11309. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11310. if (ret != 0)
  11311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11312. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11313. ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE);
  11314. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11315. if (ret != 0)
  11316. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11317. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  11318. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11319. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11320. ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE);
  11321. if (ret != 0)
  11322. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11323. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  11324. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11325. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11326. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  11327. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11328. ret = wc_AesEcbEncrypt(enc, cipher, niPlain, AES_BLOCK_SIZE);
  11329. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11330. if (ret != 0)
  11331. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11332. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  11333. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11334. #endif
  11335. #ifdef HAVE_AES_DECRYPT
  11336. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11337. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  11338. if (ret != 0)
  11339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11340. if (wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE) != 0)
  11341. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11342. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  11343. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11344. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11345. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11346. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11347. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  11348. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11349. if (ret != 0)
  11350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11351. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11352. ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE);
  11353. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11354. if (ret != 0)
  11355. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11356. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  11357. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11358. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11359. ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE);
  11360. if (ret != 0)
  11361. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11362. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  11363. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11364. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11365. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  11366. if (ret != 0)
  11367. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11368. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11369. ret = wc_AesEcbDecrypt(dec, plain, niCipher, AES_BLOCK_SIZE);
  11370. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11371. if (ret != 0)
  11372. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11373. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  11374. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11375. #endif
  11376. #endif /* HAVE_AES_DECRYPT */
  11377. }
  11378. out:
  11379. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11380. if (enc) {
  11381. if (enc_inited)
  11382. wc_AesFree(enc);
  11383. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  11384. }
  11385. #ifdef HAVE_AES_DECRYPT
  11386. if (dec) {
  11387. if (dec_inited)
  11388. wc_AesFree(dec);
  11389. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  11390. }
  11391. #endif
  11392. #else
  11393. if (enc_inited)
  11394. wc_AesFree(enc);
  11395. #ifdef HAVE_AES_DECRYPT
  11396. if (dec_inited)
  11397. wc_AesFree(dec);
  11398. #endif
  11399. #endif
  11400. #endif /* WOLFSSL_AES_256 */
  11401. return ret;
  11402. }
  11403. #endif /* HAVE_AES_ECB */
  11404. #ifdef WOLFSSL_AES_COUNTER
  11405. static wc_test_ret_t aesctr_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  11406. {
  11407. wc_test_ret_t ret = 0;
  11408. /* test vectors from "Recommendation for Block Cipher Modes of
  11409. * Operation" NIST Special Publication 800-38A */
  11410. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  11411. {
  11412. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  11413. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  11414. };
  11415. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  11416. {
  11417. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11418. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  11419. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  11420. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  11421. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  11422. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  11423. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  11424. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  11425. };
  11426. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11427. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32[] =
  11428. {
  11429. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,
  11430. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11431. };
  11432. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32_2[] =
  11433. {
  11434. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11435. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xfe
  11436. };
  11437. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64[] =
  11438. {
  11439. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11440. 0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11441. };
  11442. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64_2[] =
  11443. {
  11444. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
  11445. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11446. };
  11447. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96[] =
  11448. {
  11449. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11450. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff
  11451. };
  11452. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96_2[] =
  11453. {
  11454. 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,
  11455. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11456. };
  11457. #endif
  11458. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
  11459. {
  11460. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11461. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11462. };
  11463. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11464. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128_2[] =
  11465. {
  11466. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11467. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11468. };
  11469. #endif
  11470. #ifdef WOLFSSL_AES_128
  11471. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  11472. {
  11473. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  11474. 0xc2
  11475. };
  11476. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Key[] =
  11477. {
  11478. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  11479. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  11480. };
  11481. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Cipher[] =
  11482. {
  11483. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  11484. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  11485. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  11486. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  11487. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  11488. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  11489. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  11490. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  11491. };
  11492. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11493. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32Cipher[] =
  11494. {
  11495. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11496. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11497. 0x7e,0xad,0xea,0x5c,0xd1
  11498. };
  11499. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32CipherLong[] =
  11500. {
  11501. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11502. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11503. 0x7e,0xad,0xea,0x5c,0xd1,0xb7,0x98,0xf0,
  11504. 0x22,0x20,0xfe,0x67,0xb0,0x02,0x23,0x50
  11505. };
  11506. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32_2CipherLong[] =
  11507. {
  11508. 0x6e,0xa1,0x27,0x4d,0xea,0x20,0x5f,0x39,
  11509. 0x68,0xc8,0xb6,0x78,0xde,0xfc,0x53,0x5c,
  11510. 0x90,0xc8,0xf6,0xc6,0xfa,0xe0,0x7b,0x09,
  11511. 0x7c,0xf8,0x9c,0x6a,0x5a,0xa5,0x17,0x7f,
  11512. 0x03,0x92,0x5f,0x4e,0x85,0xea,0x26,0xc9,
  11513. 0x5a,0xc2,0x74,0xe2,0xbf,0xe4,0x1b,0xd4
  11514. };
  11515. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64Cipher[] =
  11516. {
  11517. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11518. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11519. 0xae,0x74,0x94,0x72,0x8e
  11520. };
  11521. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64CipherLong[] =
  11522. {
  11523. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11524. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11525. 0xae,0x74,0x94,0x72,0x8e,0xd0,0x71,0xc0,
  11526. 0x89,0x8a,0xa1,0xb0,0x29,0xa0,0x10,0x9e
  11527. };
  11528. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64_2CipherLong[] =
  11529. {
  11530. 0x3f,0xe7,0xd5,0xf3,0xfa,0x09,0xfe,0x40,
  11531. 0xa6,0xa1,0x32,0x8b,0x57,0x12,0xb9,0xfa,
  11532. 0xf2,0x2d,0xe4,0x3c,0x66,0x1d,0x0a,0x8e,
  11533. 0x46,0xf8,0x2e,0x33,0xce,0x8d,0x4e,0x3b,
  11534. 0x17,0x67,0x9e,0x9f,0x76,0x9e,0xc2,0x99,
  11535. 0xd5,0xd4,0x71,0xed,0xb4,0x33,0xb2,0xcd
  11536. };
  11537. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96Cipher[] =
  11538. {
  11539. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11540. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11541. 0x9d,0x77,0xc9,0x5f,0x38
  11542. };
  11543. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96CipherLong[] =
  11544. {
  11545. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11546. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11547. 0x9d,0x77,0xc9,0x5f,0x38,0xb5,0x6e,0x44,
  11548. 0x21,0x8e,0xda,0x57,0xe0,0x41,0xc7,0x6a
  11549. };
  11550. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96_2CipherLong[] =
  11551. {
  11552. 0xc8,0x81,0x1a,0xbe,0xc7,0x5b,0x93,0x6f,
  11553. 0xe6,0x52,0xe4,0xb1,0x2d,0x1c,0x39,0xbc,
  11554. 0xeb,0x82,0x27,0x0a,0x7e,0xa5,0x0e,0x2d,
  11555. 0x32,0xda,0xbe,0x10,0x7a,0x10,0xcc,0xd3,
  11556. 0x6f,0xc6,0x83,0x28,0x05,0x57,0x8a,0x24,
  11557. 0x44,0x76,0x17,0x81,0xb9,0x5c,0x94,0x81
  11558. };
  11559. #endif
  11560. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
  11561. {
  11562. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11563. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11564. 0xd3,0xda,0xe1,0x5b,0x04
  11565. };
  11566. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128CipherLong[] =
  11567. {
  11568. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11569. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11570. 0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
  11571. 0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
  11572. };
  11573. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11574. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128_2CipherLong[] =
  11575. {
  11576. 0xba,0x76,0xaa,0x54,0xd5,0xb5,0x60,0x67,
  11577. 0xc1,0xa7,0x90,0x3b,0x3f,0xdd,0xfa,0x89,
  11578. 0x24,0xdf,0x0c,0x56,0x5c,0xf4,0x2a,0x68,
  11579. 0x97,0x87,0x13,0xb6,0x7a,0xd1,0x24,0xfd,
  11580. 0x4d,0x3f,0x77,0x4a,0xb9,0xe4,0x7d,0xa2,
  11581. 0xdb,0xb9,0x31,0x5e,0xa3,0x11,0x06,0x80
  11582. };
  11583. #endif
  11584. #endif /* WOLFSSL_AES_128 */
  11585. #ifdef WOLFSSL_AES_192
  11586. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  11587. {
  11588. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  11589. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  11590. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  11591. };
  11592. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  11593. {
  11594. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  11595. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b,
  11596. 0x09,0x03,0x39,0xec,0x0a,0xa6,0xfa,0xef,
  11597. 0xd5,0xcc,0xc2,0xc6,0xf4,0xce,0x8e,0x94,
  11598. 0x1e,0x36,0xb2,0x6b,0xd1,0xeb,0xc6,0x70,
  11599. 0xd1,0xbd,0x1d,0x66,0x56,0x20,0xab,0xf7,
  11600. 0x4f,0x78,0xa7,0xf6,0xd2,0x98,0x09,0x58,
  11601. 0x5a,0x97,0xda,0xec,0x58,0xc6,0xb0,0x50
  11602. };
  11603. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11604. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32Cipher[] =
  11605. {
  11606. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11607. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11608. 0x0c,0x33,0x97,0x06,0xc0
  11609. };
  11610. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32CipherLong[] =
  11611. {
  11612. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11613. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11614. 0x0c,0x33,0x97,0x06,0xc0,0xbe,0x83,0x87,
  11615. 0xdd,0xd3,0xff,0xd8,0xe4,0x6a,0x5b,0x84
  11616. };
  11617. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32_2CipherLong[] =
  11618. {
  11619. 0xf5,0x00,0xa2,0x91,0x54,0xa3,0x76,0xa2,
  11620. 0xdd,0xad,0x16,0x89,0xe5,0xf0,0x1d,0x40,
  11621. 0x84,0xcd,0x74,0x84,0xcb,0x8b,0x9e,0x29,
  11622. 0xa9,0x8a,0x12,0x65,0xa0,0x79,0x5e,0xce,
  11623. 0xd9,0x50,0x65,0x21,0x86,0xb0,0x85,0x0d,
  11624. 0x98,0x2d,0x9a,0x5a,0x11,0xbe,0xa5,0x7f
  11625. };
  11626. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64Cipher[] =
  11627. {
  11628. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11629. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11630. 0x3d,0xf7,0xb4,0xfd,0x8c
  11631. };
  11632. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64CipherLong[] =
  11633. {
  11634. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11635. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11636. 0x3d,0xf7,0xb4,0xfd,0x8c,0x55,0x47,0x10,
  11637. 0xd5,0x91,0x35,0xbe,0xd8,0x0d,0xa5,0x9e
  11638. };
  11639. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64_2CipherLong[] =
  11640. {
  11641. 0x59,0xf1,0xed,0x70,0x62,0x42,0xa8,0x06,
  11642. 0x07,0x36,0xe1,0xc5,0x04,0x79,0xc3,0x9b,
  11643. 0xd1,0x14,0x5c,0xcc,0x6f,0x81,0x5f,0x2f,
  11644. 0xa0,0xde,0xcf,0x61,0x55,0x18,0x7a,0xac,
  11645. 0xb0,0x59,0x37,0x90,0x53,0xb3,0x00,0x88,
  11646. 0xb4,0x49,0x90,0x7b,0x96,0xcd,0xcc,0xc3
  11647. };
  11648. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96Cipher[] =
  11649. {
  11650. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11651. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11652. 0x47,0xb5,0xf3,0x30,0x3b
  11653. };
  11654. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96CipherLong[] =
  11655. {
  11656. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11657. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11658. 0x47,0xb5,0xf3,0x30,0x3b,0xef,0xcd,0x80,
  11659. 0xe3,0x61,0x34,0xef,0x4e,0x1b,0x79,0xc1
  11660. };
  11661. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96_2CipherLong[] =
  11662. {
  11663. 0x3c,0xb2,0xff,0xc0,0x24,0xe1,0xf5,0xc4,
  11664. 0x0f,0xd1,0x0a,0x1b,0xbe,0x1f,0x23,0xa1,
  11665. 0x8e,0xbf,0x2b,0x96,0xb6,0x37,0xc8,0x25,
  11666. 0x06,0x90,0xe2,0xca,0x71,0x24,0x52,0x95,
  11667. 0xaa,0x8c,0x80,0xdf,0xb7,0xd7,0x30,0xb0,
  11668. 0xcc,0x06,0x4f,0x28,0xa2,0x74,0x27,0xf8
  11669. };
  11670. #endif
  11671. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128Cipher[] =
  11672. {
  11673. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11674. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11675. 0x8c,0x68,0xa7,0xd9,0x57
  11676. };
  11677. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128CipherLong[] =
  11678. {
  11679. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11680. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11681. 0x8c,0x68,0xa7,0xd9,0x57,0xab,0x09,0x0f,
  11682. 0x01,0xc4,0x4e,0x62,0xaf,0xc2,0xdf,0x1a
  11683. };
  11684. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11685. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128_2CipherLong[] =
  11686. {
  11687. 0x88,0x0a,0x26,0x4e,0xa8,0x26,0x21,0xe0,
  11688. 0xfc,0xbc,0x63,0xdc,0xd9,0x60,0x52,0xb2,
  11689. 0x99,0x2f,0xbb,0x1e,0x00,0xf5,0x9f,0x6d,
  11690. 0xab,0x48,0x0f,0xc6,0x37,0x12,0x56,0xe3,
  11691. 0x12,0x8d,0x31,0xc8,0xea,0xf4,0x41,0x82,
  11692. 0x7a,0x88,0xe0,0xd7,0xf0,0x67,0x03,0xa4
  11693. };
  11694. #endif
  11695. #endif
  11696. #ifdef WOLFSSL_AES_256
  11697. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  11698. {
  11699. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11700. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11701. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11702. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11703. };
  11704. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  11705. {
  11706. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  11707. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
  11708. 0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,
  11709. 0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
  11710. 0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,
  11711. 0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
  11712. 0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,
  11713. 0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6
  11714. };
  11715. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11716. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32Cipher[] =
  11717. {
  11718. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11719. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11720. 0xa2,0x13,0x47,0x74,0xda
  11721. };
  11722. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32CipherLong[] =
  11723. {
  11724. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11725. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11726. 0xa2,0x13,0x47,0x74,0xda,0x89,0x77,0x40,
  11727. 0x28,0x9c,0xe8,0x19,0x26,0x32,0xd8,0x1f
  11728. };
  11729. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32_2CipherLong[] =
  11730. {
  11731. 0xf6,0xd9,0x22,0xc6,0x80,0x29,0xaf,0x14,
  11732. 0x54,0x6c,0x0a,0xce,0x42,0xea,0x3c,0xa1,
  11733. 0x7c,0xeb,0x36,0x0d,0x8e,0xd7,0x8c,0x59,
  11734. 0xa8,0x09,0x9f,0x9e,0xba,0x5b,0x95,0xfa,
  11735. 0x26,0x8c,0x37,0x59,0xf8,0xae,0x8e,0xaa,
  11736. 0x4d,0xe4,0x1c,0xfe,0x51,0xc7,0xb7,0xcc
  11737. };
  11738. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64Cipher[] =
  11739. {
  11740. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11741. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11742. 0xd4,0x94,0x4c,0xcd,0x4d
  11743. };
  11744. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64CipherLong[] =
  11745. {
  11746. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11747. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11748. 0xd4,0x94,0x4c,0xcd,0x4d,0x47,0x5a,0x92,
  11749. 0x26,0x49,0x81,0x7a,0xda,0x36,0x27,0x01
  11750. };
  11751. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64_2CipherLong[] =
  11752. {
  11753. 0xf7,0x9c,0xbf,0xf6,0xa2,0xaa,0x8a,0x0a,
  11754. 0x63,0x8a,0x20,0x2f,0x12,0xf1,0x8e,0x49,
  11755. 0x30,0xc0,0x8d,0x5c,0x5f,0x8b,0xbc,0x16,
  11756. 0xdd,0x71,0xee,0x13,0x14,0x7b,0xe1,0x25,
  11757. 0xcb,0x87,0x8a,0xc6,0xdc,0x1d,0x54,0x7a,
  11758. 0xe1,0xe4,0x6f,0x0d,0x95,0x1b,0xd1,0x8b
  11759. };
  11760. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96Cipher[] =
  11761. {
  11762. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11763. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11764. 0xb8,0x69,0xa1,0x48,0x45
  11765. };
  11766. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96CipherLong[] =
  11767. {
  11768. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11769. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11770. 0xb8,0x69,0xa1,0x48,0x45,0xf1,0xc6,0x27,
  11771. 0x36,0xa8,0xb2,0x4b,0x0e,0x62,0x6b,0x72
  11772. };
  11773. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96_2CipherLong[] =
  11774. {
  11775. 0xd5,0x56,0x73,0xaa,0xb8,0xe4,0x06,0xf6,
  11776. 0x83,0x45,0x3a,0xb4,0xb9,0x63,0xec,0xad,
  11777. 0x73,0xc5,0xab,0x78,0xb1,0x21,0xab,0xef,
  11778. 0x69,0x15,0xb7,0x0c,0xe9,0xb4,0x3a,0xe7,
  11779. 0xbc,0xc4,0x22,0xbd,0x93,0xba,0x52,0xe0,
  11780. 0x91,0x2f,0x5e,0x8d,0x6d,0x59,0xf7,0xc2
  11781. };
  11782. #endif
  11783. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
  11784. {
  11785. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11786. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11787. 0x4b,0x45,0x7c,0xd6,0x8a
  11788. };
  11789. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128CipherLong[] =
  11790. {
  11791. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11792. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11793. 0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
  11794. 0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
  11795. };
  11796. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11797. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128_2CipherLong[] =
  11798. {
  11799. 0x24,0x5c,0x09,0xa0,0x3b,0x1a,0x5a,0x94,
  11800. 0x2b,0x93,0x56,0x13,0x48,0xa0,0x21,0xce,
  11801. 0x95,0x11,0xa3,0x76,0xd6,0x59,0x88,0x42,
  11802. 0x04,0x71,0x69,0x62,0x28,0xb2,0xee,0x9d,
  11803. 0xd5,0xa0,0xea,0xc7,0x37,0x93,0x92,0xc7,
  11804. 0xf2,0xb6,0x8d,0xd9,0x59,0x1a,0xfa,0xbb
  11805. };
  11806. #endif
  11807. #endif
  11808. int i;
  11809. struct {
  11810. const byte* key;
  11811. int keySz;
  11812. const byte* iv;
  11813. const byte* plain;
  11814. int len;
  11815. const byte* cipher;
  11816. } testVec[] = {
  11817. #ifdef WOLFSSL_AES_128
  11818. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11819. ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
  11820. /* let's try with just 9 bytes, non block size test */
  11821. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11822. ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
  11823. /* and an additional 9 bytes to reuse tmp left buffer */
  11824. { NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
  11825. /* Counter wrapping */
  11826. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11827. ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
  11828. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11829. ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
  11830. ctr128Wrap128CipherLong },
  11831. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11832. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128_2,
  11833. ctrPlain, (int)sizeof(ctr128Wrap128_2CipherLong),
  11834. ctr128Wrap128_2CipherLong },
  11835. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11836. ctrPlain, (int)sizeof(ctr128Wrap96Cipher), ctr128Wrap96Cipher },
  11837. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11838. ctrPlain, (int)sizeof(ctr128Wrap96CipherLong),
  11839. ctr128Wrap96CipherLong },
  11840. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96_2,
  11841. ctrPlain, (int)sizeof(ctr128Wrap96_2CipherLong),
  11842. ctr128Wrap96_2CipherLong },
  11843. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11844. ctrPlain, (int)sizeof(ctr128Wrap64Cipher), ctr128Wrap64Cipher },
  11845. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11846. ctrPlain, (int)sizeof(ctr128Wrap64CipherLong),
  11847. ctr128Wrap64CipherLong },
  11848. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64_2,
  11849. ctrPlain, (int)sizeof(ctr128Wrap64_2CipherLong),
  11850. ctr128Wrap64_2CipherLong },
  11851. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11852. ctrPlain, (int)sizeof(ctr128Wrap32Cipher), ctr128Wrap32Cipher },
  11853. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11854. ctrPlain, (int)sizeof(ctr128Wrap32CipherLong),
  11855. ctr128Wrap32CipherLong },
  11856. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32_2,
  11857. ctrPlain, (int)sizeof(ctr128Wrap32_2CipherLong),
  11858. ctr128Wrap32_2CipherLong },
  11859. #endif
  11860. #endif
  11861. #ifdef WOLFSSL_AES_192
  11862. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11863. ctrPlain, (int)sizeof(ctrPlain), ctr192Cipher },
  11864. /* let's try with just 9 bytes, non block size test */
  11865. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11866. ctrPlain, (int)sizeof(oddCipher), ctr192Cipher },
  11867. /* Counter wrapping */
  11868. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11869. ctrPlain, (int)sizeof(ctr192Wrap128Cipher), ctr192Wrap128Cipher },
  11870. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11871. ctrPlain, (int)sizeof(ctr192Wrap128CipherLong),
  11872. ctr192Wrap128CipherLong },
  11873. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11874. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128_2,
  11875. ctrPlain, (int)sizeof(ctr192Wrap128_2CipherLong),
  11876. ctr192Wrap128_2CipherLong },
  11877. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11878. ctrPlain, (int)sizeof(ctr192Wrap96Cipher), ctr192Wrap96Cipher },
  11879. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11880. ctrPlain, (int)sizeof(ctr192Wrap96CipherLong),
  11881. ctr192Wrap96CipherLong },
  11882. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96_2,
  11883. ctrPlain, (int)sizeof(ctr192Wrap96_2CipherLong),
  11884. ctr192Wrap96_2CipherLong },
  11885. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11886. ctrPlain, (int)sizeof(ctr192Wrap64Cipher), ctr192Wrap64Cipher },
  11887. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11888. ctrPlain, (int)sizeof(ctr192Wrap64CipherLong),
  11889. ctr192Wrap64CipherLong },
  11890. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64_2,
  11891. ctrPlain, (int)sizeof(ctr192Wrap64_2CipherLong),
  11892. ctr192Wrap64_2CipherLong },
  11893. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11894. ctrPlain, (int)sizeof(ctr192Wrap32Cipher), ctr192Wrap32Cipher },
  11895. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11896. ctrPlain, (int)sizeof(ctr192Wrap32CipherLong),
  11897. ctr192Wrap32CipherLong },
  11898. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32_2,
  11899. ctrPlain, (int)sizeof(ctr192Wrap32_2CipherLong),
  11900. ctr192Wrap32_2CipherLong },
  11901. #endif
  11902. #endif
  11903. #ifdef WOLFSSL_AES_256
  11904. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11905. ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
  11906. /* let's try with just 9 bytes, non block size test */
  11907. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11908. ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
  11909. /* Counter wrapping */
  11910. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11911. ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
  11912. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11913. ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
  11914. ctr256Wrap128CipherLong },
  11915. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11916. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128_2,
  11917. ctrPlain, (int)sizeof(ctr256Wrap128_2CipherLong),
  11918. ctr256Wrap128_2CipherLong },
  11919. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11920. ctrPlain, (int)sizeof(ctr256Wrap96Cipher), ctr256Wrap96Cipher },
  11921. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11922. ctrPlain, (int)sizeof(ctr256Wrap96CipherLong),
  11923. ctr256Wrap96CipherLong },
  11924. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96_2,
  11925. ctrPlain, (int)sizeof(ctr256Wrap96_2CipherLong),
  11926. ctr256Wrap96_2CipherLong },
  11927. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11928. ctrPlain, (int)sizeof(ctr256Wrap64Cipher), ctr256Wrap64Cipher },
  11929. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11930. ctrPlain, (int)sizeof(ctr256Wrap64CipherLong),
  11931. ctr256Wrap64CipherLong },
  11932. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64_2,
  11933. ctrPlain, (int)sizeof(ctr256Wrap64_2CipherLong),
  11934. ctr256Wrap64_2CipherLong },
  11935. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11936. ctrPlain, (int)sizeof(ctr256Wrap32Cipher), ctr256Wrap32Cipher },
  11937. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11938. ctrPlain, (int)sizeof(ctr256Wrap32CipherLong),
  11939. ctr256Wrap32CipherLong },
  11940. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32_2,
  11941. ctrPlain, (int)sizeof(ctr256Wrap32_2CipherLong),
  11942. ctr256Wrap32_2CipherLong },
  11943. #endif
  11944. #endif
  11945. };
  11946. #define AES_CTR_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  11947. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11948. if (testVec[i].key != NULL) {
  11949. ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
  11950. testVec[i].iv, AES_ENCRYPTION);
  11951. if (ret != 0) {
  11952. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11953. }
  11954. /* Ctr only uses encrypt, even on key setup */
  11955. ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
  11956. testVec[i].iv, AES_ENCRYPTION);
  11957. if (ret != 0) {
  11958. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11959. }
  11960. }
  11961. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
  11962. if (ret != 0) {
  11963. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11964. }
  11965. ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
  11966. if (ret != 0) {
  11967. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11968. }
  11969. if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
  11970. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11971. }
  11972. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  11973. if (XMEMCMP(cipher, testVec[i].cipher, (size_t)testVec[i].len)) {
  11974. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11975. }
  11976. #endif
  11977. }
  11978. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11979. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11980. if (testVec[i].key != NULL) {
  11981. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  11982. testVec[i].iv, AES_ENCRYPTION);
  11983. if (ret != 0) {
  11984. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11985. }
  11986. /* Ctr only uses encrypt, even on key setup */
  11987. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  11988. testVec[i].iv, AES_ENCRYPTION);
  11989. if (ret != 0) {
  11990. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11991. }
  11992. }
  11993. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11994. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  11995. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11996. if (ret != 0) {
  11997. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11998. }
  11999. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12000. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12001. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12002. if (ret != 0) {
  12003. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12004. }
  12005. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12006. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12007. }
  12008. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12009. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12010. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12011. }
  12012. #endif
  12013. }
  12014. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  12015. if (testVec[i].key != NULL) {
  12016. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12017. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  12018. testVec[i].iv, AES_ENCRYPTION);
  12019. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12020. if (ret != 0) {
  12021. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12022. }
  12023. /* Ctr only uses encrypt, even on key setup */
  12024. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12025. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  12026. testVec[i].iv, AES_ENCRYPTION);
  12027. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12028. if (ret != 0) {
  12029. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12030. }
  12031. }
  12032. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  12033. if (ret != 0) {
  12034. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12035. }
  12036. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12037. if (ret != 0) {
  12038. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12039. }
  12040. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12041. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12042. }
  12043. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12044. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12045. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12046. }
  12047. #endif
  12048. }
  12049. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12050. out:
  12051. return ret;
  12052. }
  12053. #endif /* WOLFSSL_AES_COUNTER */
  12054. #ifdef HAVE_AES_ECB
  12055. static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12056. {
  12057. wc_test_ret_t ret = 0;
  12058. WOLFSSL_SMALL_STACK_STATIC const byte key_128[] = "0123456789abcdef ";
  12059. WOLFSSL_SMALL_STACK_STATIC const byte key_192[] =
  12060. "0123456789abcdef01234567 ";
  12061. WOLFSSL_SMALL_STACK_STATIC const byte key_256[] =
  12062. "0123456789abcdef0123456789abcdef ";
  12063. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12064. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12065. 0x6e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  12066. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20
  12067. };
  12068. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[AES_BLOCK_SIZE] = {
  12069. 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6,
  12070. 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1
  12071. };
  12072. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[AES_BLOCK_SIZE] = {
  12073. 0x06, 0x57, 0xee, 0x78, 0x3f, 0x96, 0x00, 0xb1,
  12074. 0xec, 0x76, 0x94, 0x30, 0x29, 0xbe, 0x15, 0xab
  12075. };
  12076. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[AES_BLOCK_SIZE] = {
  12077. 0xcd, 0xf2, 0x81, 0x3e, 0x73, 0x3e, 0xf7, 0x33,
  12078. 0x3d, 0x18, 0xfd, 0x41, 0x85, 0x37, 0x04, 0x82
  12079. };
  12080. int i;
  12081. struct {
  12082. const byte* key;
  12083. int keySz;
  12084. const byte* iv;
  12085. const byte* verify;
  12086. } testVec[] = {
  12087. { key_128, 16, iv, verify_ecb_128 },
  12088. { key_192, 24, iv, verify_ecb_192 },
  12089. { key_256, 32, iv, verify_ecb_256 },
  12090. };
  12091. #define AES_ECB_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  12092. for (i = 0; i < AES_ECB_TEST_LEN; i++) {
  12093. ret = wc_AesSetKey(enc, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12094. AES_ENCRYPTION);
  12095. if (ret != 0)
  12096. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12097. #ifdef HAVE_AES_DECRYPT
  12098. ret = wc_AesSetKey(dec, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12099. AES_DECRYPTION);
  12100. if (ret != 0)
  12101. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12102. #endif
  12103. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4);
  12104. ret = wc_AesEcbEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
  12105. #if defined(WOLFSSL_ASYNC_CRYPT)
  12106. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12107. #endif
  12108. if (ret != 0)
  12109. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12110. if (XMEMCMP(cipher, testVec[i].verify, AES_BLOCK_SIZE)) {
  12111. WOLFSSL_MSG("aes_test cipher vs verify_ecb mismatch!");
  12112. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12113. }
  12114. #ifdef HAVE_AES_DECRYPT
  12115. XMEMSET(plain, 0, AES_BLOCK_SIZE * 4);
  12116. ret = wc_AesEcbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12117. #if defined(WOLFSSL_ASYNC_CRYPT)
  12118. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12119. #endif
  12120. if (ret != 0)
  12121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12122. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  12123. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12124. #endif /* HAVE_AES_DECRYPT */
  12125. (void)dec;
  12126. (void)plain;
  12127. }
  12128. out:
  12129. return ret;
  12130. }
  12131. #endif
  12132. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void)
  12133. {
  12134. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_DIRECT)
  12135. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12136. Aes *enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  12137. #else
  12138. Aes enc[1];
  12139. #endif
  12140. int enc_inited = 0;
  12141. byte cipher[AES_BLOCK_SIZE * 4];
  12142. #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER)
  12143. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12144. Aes *dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  12145. #else
  12146. Aes dec[1];
  12147. #endif
  12148. int dec_inited = 0;
  12149. byte plain [AES_BLOCK_SIZE * 4];
  12150. #endif /* HAVE_AES_DECRYPT || WOLFSSL_AES_COUNTER */
  12151. #endif /* HAVE_AES_CBC || WOLFSSL_AES_COUNTER || WOLFSSL_AES_DIRECT */
  12152. wc_test_ret_t ret = 0;
  12153. #ifdef HAVE_AES_CBC
  12154. #ifdef WOLFSSL_AES_128
  12155. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  12156. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  12157. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  12158. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  12159. };
  12160. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12161. {
  12162. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  12163. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  12164. };
  12165. #ifdef HAVE_RENESAS_SYNC
  12166. const byte *key =
  12167. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  12168. #else
  12169. WOLFSSL_SMALL_STACK_STATIC const
  12170. byte key[] = "0123456789abcdef "; /* align */
  12171. #endif
  12172. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef "; /* align */
  12173. WOLFSSL_ENTER("aes_test");
  12174. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12175. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || \
  12176. defined(WOLFSSL_AES_DIRECT)
  12177. if (enc == NULL)
  12178. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12179. #endif
  12180. #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER)
  12181. if (dec == NULL)
  12182. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12183. #endif
  12184. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12185. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12186. if (ret != 0)
  12187. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12188. enc_inited = 1;
  12189. #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER)
  12190. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12191. if (ret != 0)
  12192. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12193. dec_inited = 1;
  12194. #endif
  12195. #ifdef HAVE_AES_ECB
  12196. ret = aes_ecb_test(enc, dec, cipher, plain);
  12197. if (ret != 0)
  12198. return ret;
  12199. #endif
  12200. ret = wc_AesSetKey(enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  12201. if (ret != 0)
  12202. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12203. #ifdef HAVE_AES_DECRYPT
  12204. ret = wc_AesSetKey(dec, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION);
  12205. if (ret != 0)
  12206. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12207. #endif
  12208. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 4);
  12209. ret = wc_AesCbcEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
  12210. #if defined(WOLFSSL_ASYNC_CRYPT)
  12211. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12212. #endif
  12213. if (ret != 0)
  12214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12215. #ifdef HAVE_AES_DECRYPT
  12216. XMEMSET(plain, 0, AES_BLOCK_SIZE * 4);
  12217. ret = wc_AesCbcDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12218. #if defined(WOLFSSL_ASYNC_CRYPT)
  12219. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12220. #endif
  12221. if (ret != 0) {
  12222. WOLFSSL_MSG("failed wc_AesCbcDecrypt");
  12223. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12224. }
  12225. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) {
  12226. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain compare");
  12227. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12228. }
  12229. #endif /* HAVE_AES_DECRYPT */
  12230. /* skipped because wrapped key use in case of renesas sm */
  12231. #ifndef HAVE_RENESAS_SYNC
  12232. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) {
  12233. WOLFSSL_MSG("wc_AesCbcDecrypt failed cipher-verify compare");
  12234. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12235. }
  12236. #endif
  12237. #endif /* WOLFSSL_AES_128 */
  12238. #if defined(WOLFSSL_AESNI) && defined(HAVE_AES_DECRYPT)
  12239. {
  12240. WOLFSSL_SMALL_STACK_STATIC const byte bigMsg[] = {
  12241. /* "All work and no play makes Jack a dull boy. " */
  12242. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12243. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12244. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12245. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12246. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12247. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12248. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12249. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12250. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12251. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12252. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12253. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12254. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12255. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12256. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12257. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12258. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12259. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12260. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12261. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12262. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12263. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12264. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12265. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12266. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12267. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12268. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12269. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12270. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12271. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12272. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12273. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12274. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12275. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12276. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12277. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12278. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12279. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12280. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12281. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12282. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12283. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12284. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12285. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12286. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12287. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12288. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12289. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20
  12290. };
  12291. WOLFSSL_SMALL_STACK_STATIC const byte bigKey[] = "0123456789abcdeffedcba9876543210";
  12292. word32 keySz, msgSz;
  12293. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12294. byte *bigCipher = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12295. byte *bigPlain = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12296. if ((bigCipher == NULL) ||
  12297. (bigPlain == NULL)) {
  12298. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12299. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12300. }
  12301. #else
  12302. byte bigCipher[sizeof(bigMsg)];
  12303. byte bigPlain[sizeof(bigMsg)];
  12304. #endif
  12305. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12306. * message by AES_BLOCK_SIZE for each size of AES key. */
  12307. for (keySz = 16; keySz <= 32; keySz += 8) {
  12308. for (msgSz = AES_BLOCK_SIZE;
  12309. msgSz <= sizeof(bigMsg);
  12310. msgSz += AES_BLOCK_SIZE) {
  12311. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12312. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12313. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12314. if (ret != 0) {
  12315. ret = WC_TEST_RET_ENC_EC(ret);
  12316. break;
  12317. }
  12318. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12319. if (ret != 0) {
  12320. ret = WC_TEST_RET_ENC_EC(ret);
  12321. break;
  12322. }
  12323. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12324. #if defined(WOLFSSL_ASYNC_CRYPT)
  12325. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12326. #endif
  12327. if (ret != 0) {
  12328. ret = WC_TEST_RET_ENC_EC(ret);
  12329. break;
  12330. }
  12331. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12332. #if defined(WOLFSSL_ASYNC_CRYPT)
  12333. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12334. #endif
  12335. if (ret != 0) {
  12336. ret = WC_TEST_RET_ENC_EC(ret);
  12337. break;
  12338. }
  12339. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12340. ret = WC_TEST_RET_ENC_NC;
  12341. break;
  12342. }
  12343. }
  12344. if (ret != 0)
  12345. break;
  12346. }
  12347. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12348. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12349. * message by AES_BLOCK_SIZE for each size of AES key. */
  12350. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12351. for (keySz = 16; keySz <= 32; keySz += 8) {
  12352. for (msgSz = AES_BLOCK_SIZE;
  12353. msgSz <= sizeof(bigMsg);
  12354. msgSz += AES_BLOCK_SIZE) {
  12355. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12356. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12357. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12358. if (ret != 0) {
  12359. ret = WC_TEST_RET_ENC_EC(ret);
  12360. break;
  12361. }
  12362. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12363. if (ret != 0) {
  12364. ret = WC_TEST_RET_ENC_EC(ret);
  12365. break;
  12366. }
  12367. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12368. #if defined(WOLFSSL_ASYNC_CRYPT)
  12369. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12370. #endif
  12371. if (ret != 0) {
  12372. ret = WC_TEST_RET_ENC_EC(ret);
  12373. break;
  12374. }
  12375. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12376. #if defined(WOLFSSL_ASYNC_CRYPT)
  12377. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12378. #endif
  12379. if (ret != 0) {
  12380. ret = WC_TEST_RET_ENC_EC(ret);
  12381. break;
  12382. }
  12383. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12384. ret = WC_TEST_RET_ENC_NC;
  12385. break;
  12386. }
  12387. }
  12388. if (ret != 0)
  12389. break;
  12390. }
  12391. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12392. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12393. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12394. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12395. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12396. #endif
  12397. if (ret != 0)
  12398. goto out;
  12399. }
  12400. #endif /* WOLFSSL_AESNI && HAVE_AES_DECRYPT */
  12401. /* Test of AES IV state with encrypt/decrypt */
  12402. #if defined(WOLFSSL_AES_128) && !defined(HAVE_RENESAS_SYNC)
  12403. {
  12404. /* Test Vector from "NIST Special Publication 800-38A, 2001 Edition"
  12405. * https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38a.pdf
  12406. */
  12407. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  12408. {
  12409. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  12410. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  12411. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  12412. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51
  12413. };
  12414. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] =
  12415. {
  12416. 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
  12417. 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
  12418. 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
  12419. 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2
  12420. };
  12421. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  12422. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  12423. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  12424. };
  12425. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  12426. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  12427. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  12428. };
  12429. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  12430. if (ret != 0)
  12431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12432. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 2);
  12433. ret = wc_AesCbcEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE);
  12434. #if defined(WOLFSSL_ASYNC_CRYPT)
  12435. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12436. #endif
  12437. if (ret != 0)
  12438. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12439. #ifndef HAVE_RENESAS_SYNC
  12440. if (XMEMCMP(cipher, verify2, AES_BLOCK_SIZE))
  12441. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12442. #endif
  12443. ret = wc_AesCbcEncrypt(enc, cipher + AES_BLOCK_SIZE,
  12444. msg2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12445. #if defined(WOLFSSL_ASYNC_CRYPT)
  12446. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12447. #endif
  12448. if (ret != 0)
  12449. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12450. if (XMEMCMP(cipher + AES_BLOCK_SIZE, verify2 + AES_BLOCK_SIZE,
  12451. AES_BLOCK_SIZE))
  12452. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12453. #if defined(HAVE_AES_DECRYPT)
  12454. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION);
  12455. if (ret != 0)
  12456. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12457. XMEMSET(plain, 0, AES_BLOCK_SIZE * 2);
  12458. ret = wc_AesCbcDecrypt(dec, plain, verify2, AES_BLOCK_SIZE);
  12459. #if defined(WOLFSSL_ASYNC_CRYPT)
  12460. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12461. #endif
  12462. if (ret != 0)
  12463. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12464. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE))
  12465. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12466. ret = wc_AesCbcDecrypt(dec, plain + AES_BLOCK_SIZE,
  12467. verify2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12468. #if defined(WOLFSSL_ASYNC_CRYPT)
  12469. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12470. #endif
  12471. if (ret != 0)
  12472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12473. if (XMEMCMP(plain + AES_BLOCK_SIZE, msg2 + AES_BLOCK_SIZE,
  12474. AES_BLOCK_SIZE)) {
  12475. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain-msg2 compare");
  12476. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12477. }
  12478. #endif /* HAVE_AES_DECRYPT */
  12479. }
  12480. #endif /* WOLFSSL_AES_128 && !HAVE_RENESAS_SYNC */
  12481. #endif /* HAVE_AES_CBC */
  12482. #ifdef WOLFSSL_AES_COUNTER
  12483. ret = aesctr_test(enc, dec, cipher, plain);
  12484. if (ret != 0)
  12485. return ret;
  12486. #endif
  12487. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  12488. {
  12489. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  12490. {
  12491. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12492. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12493. };
  12494. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  12495. {
  12496. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12497. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12498. };
  12499. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  12500. {
  12501. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12502. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12503. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12504. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12505. };
  12506. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12507. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  12508. if (ret != 0)
  12509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12510. #if !defined(HAVE_SELFTEST) && \
  12511. (defined(WOLFSSL_LINUXKM) || \
  12512. !defined(HAVE_FIPS) || \
  12513. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12514. ret = wc_AesEncryptDirect(enc, cipher, niPlain);
  12515. if (ret != 0)
  12516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12517. #else
  12518. wc_AesEncryptDirect(enc, cipher, niPlain);
  12519. #endif
  12520. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  12521. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12522. #ifdef HAVE_AES_DECRYPT
  12523. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12524. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  12525. if (ret != 0)
  12526. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12527. #if !defined(HAVE_SELFTEST) && \
  12528. (defined(WOLFSSL_LINUXKM) || \
  12529. !defined(HAVE_FIPS) || \
  12530. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12531. ret = wc_AesDecryptDirect(dec, plain, niCipher);
  12532. if (ret != 0)
  12533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12534. #else
  12535. wc_AesDecryptDirect(dec, plain, niCipher);
  12536. #endif
  12537. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  12538. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12539. #endif /* HAVE_AES_DECRYPT */
  12540. }
  12541. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  12542. #ifndef HAVE_RENESAS_SYNC
  12543. ret = aes_key_size_test();
  12544. if (ret != 0)
  12545. goto out;
  12546. #endif
  12547. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  12548. !defined(HAVE_RENESAS_SYNC)
  12549. ret = aes_cbc_test();
  12550. if (ret != 0)
  12551. goto out;
  12552. #endif
  12553. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12554. ret = aesecb_test();
  12555. if (ret != 0)
  12556. goto out;
  12557. #endif
  12558. out:
  12559. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_DIRECT)
  12560. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12561. if (enc) {
  12562. if (enc_inited)
  12563. wc_AesFree(enc);
  12564. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  12565. }
  12566. #else
  12567. if (enc_inited)
  12568. wc_AesFree(enc);
  12569. #endif
  12570. (void)cipher;
  12571. #if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_COUNTER)
  12572. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12573. if (dec) {
  12574. if (dec_inited)
  12575. wc_AesFree(dec);
  12576. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  12577. }
  12578. #else
  12579. if (dec_inited)
  12580. wc_AesFree(dec);
  12581. #endif
  12582. (void)plain;
  12583. #endif /* HAVE_AES_DECRYPT || WOLFSSL_AES_COUNTER */
  12584. #endif /* HAVE_AES_CBC || WOLFSSL_AES_COUNTER || WOLFSSL_AES_DIRECT */
  12585. return ret;
  12586. }
  12587. #if defined(WOLFSSL_AES_CFB)
  12588. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void)
  12589. {
  12590. int ret;
  12591. WOLFSSL_ENTER("aes_cfb_test");
  12592. ret = aescfb_test_0();
  12593. if (ret != 0)
  12594. return ret;
  12595. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  12596. ret = aescfb1_test();
  12597. if (ret != 0)
  12598. return ret;
  12599. ret = aescfb8_test();
  12600. if (ret != 0)
  12601. return ret;
  12602. #endif
  12603. return 0;
  12604. }
  12605. #endif
  12606. #if defined(WOLFSSL_AES_XTS)
  12607. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void)
  12608. {
  12609. int ret = 0;
  12610. WOLFSSL_ENTER("aes_xts_test");
  12611. #ifdef WOLFSSL_AES_128
  12612. ret = aes_xts_128_test();
  12613. if (ret != 0)
  12614. return ret;
  12615. #endif
  12616. #ifdef WOLFSSL_AES_192
  12617. ret = aes_xts_192_test();
  12618. if (ret != 0)
  12619. return ret;
  12620. #endif
  12621. #ifdef WOLFSSL_AES_256
  12622. ret = aes_xts_256_test();
  12623. if (ret != 0)
  12624. return ret;
  12625. #endif
  12626. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  12627. ret = aes_xts_sector_test();
  12628. if (ret != 0)
  12629. return ret;
  12630. #endif
  12631. #ifdef WOLFSSL_AES_128
  12632. ret = aes_xts_args_test();
  12633. if (ret != 0)
  12634. return ret;
  12635. #endif
  12636. return 0;
  12637. }
  12638. #endif
  12639. #ifdef WOLFSSL_AES_192
  12640. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
  12641. {
  12642. wc_test_ret_t ret = 0;
  12643. #ifdef HAVE_AES_CBC
  12644. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12645. Aes *enc = NULL;
  12646. #else
  12647. Aes enc[1];
  12648. #endif
  12649. int enc_inited = 0;
  12650. byte cipher[AES_BLOCK_SIZE];
  12651. #ifdef HAVE_AES_DECRYPT
  12652. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12653. Aes *dec = NULL;
  12654. #else
  12655. Aes dec[1];
  12656. #endif
  12657. byte plain[AES_BLOCK_SIZE];
  12658. #endif
  12659. #ifdef HAVE_AES_DECRYPT
  12660. int dec_inited = 0;
  12661. #endif
  12662. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  12663. * Appendix F.2.3 */
  12664. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12665. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12666. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12667. };
  12668. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12669. {
  12670. 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  12671. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8
  12672. };
  12673. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12674. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  12675. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  12676. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  12677. };
  12678. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12679. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12680. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12681. };
  12682. WOLFSSL_ENTER("aes192_test");
  12683. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12684. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12685. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12686. #ifdef HAVE_AES_DECRYPT
  12687. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12688. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12689. #endif
  12690. #endif
  12691. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12692. if (ret != 0)
  12693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12694. enc_inited = 1;
  12695. #ifdef HAVE_AES_DECRYPT
  12696. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12697. if (ret != 0)
  12698. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12699. dec_inited = 1;
  12700. #endif
  12701. ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
  12702. if (ret != 0)
  12703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12704. #ifdef HAVE_AES_DECRYPT
  12705. ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION);
  12706. if (ret != 0)
  12707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12708. #endif
  12709. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12710. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12711. #if defined(WOLFSSL_ASYNC_CRYPT)
  12712. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12713. #endif
  12714. if (ret != 0)
  12715. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12716. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12717. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12718. #ifdef HAVE_AES_DECRYPT
  12719. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12720. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12721. #if defined(WOLFSSL_ASYNC_CRYPT)
  12722. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12723. #endif
  12724. if (ret != 0)
  12725. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12726. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12727. WOLFSSL_MSG("failed wc_AesCbcDecrypt plain-msg compare");
  12728. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12729. }
  12730. #endif
  12731. out:
  12732. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12733. if (enc) {
  12734. if (enc_inited)
  12735. wc_AesFree(enc);
  12736. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  12737. }
  12738. #ifdef HAVE_AES_DECRYPT
  12739. if (dec) {
  12740. if (dec_inited)
  12741. wc_AesFree(dec);
  12742. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  12743. }
  12744. #endif
  12745. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  12746. if (enc_inited)
  12747. wc_AesFree(enc);
  12748. #ifdef HAVE_AES_DECRYPT
  12749. if (dec_inited)
  12750. wc_AesFree(dec);
  12751. #endif
  12752. #endif
  12753. #endif /* HAVE_AES_CBC */
  12754. return ret;
  12755. }
  12756. #endif /* WOLFSSL_AES_192 */
  12757. #ifdef WOLFSSL_AES_256
  12758. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
  12759. {
  12760. #ifdef HAVE_AES_CBC
  12761. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12762. Aes *enc = NULL;
  12763. #else
  12764. Aes enc[1];
  12765. #endif
  12766. int enc_inited = 0;
  12767. byte cipher[AES_BLOCK_SIZE];
  12768. #ifdef HAVE_AES_DECRYPT
  12769. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12770. Aes *dec = NULL;
  12771. #else
  12772. Aes dec[1];
  12773. #endif
  12774. int dec_inited = 0;
  12775. byte plain[AES_BLOCK_SIZE];
  12776. #endif
  12777. #endif /* HAVE_AES_CBC */
  12778. wc_test_ret_t ret = 0;
  12779. #ifdef HAVE_AES_CBC
  12780. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  12781. * Appendix F.2.5 */
  12782. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12783. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12784. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12785. };
  12786. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12787. {
  12788. 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  12789. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6
  12790. };
  12791. #ifdef HAVE_RENESAS_SYNC
  12792. byte *key =
  12793. (byte*)guser_PKCbInfo.wrapped_key_aes256;
  12794. int keySz = (256/8);
  12795. #else
  12796. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12797. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12798. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12799. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12800. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12801. };
  12802. int keySz = (int)sizeof(key);
  12803. #endif
  12804. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12805. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12806. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12807. };
  12808. WOLFSSL_ENTER("aes256_test");
  12809. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12810. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12811. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12812. #ifdef HAVE_AES_DECRYPT
  12813. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12814. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12815. #endif
  12816. #endif
  12817. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12818. if (ret != 0)
  12819. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12820. enc_inited = 1;
  12821. #ifdef HAVE_AES_DECRYPT
  12822. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12823. if (ret != 0)
  12824. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12825. dec_inited = 1;
  12826. #endif
  12827. ret = wc_AesSetKey(enc, key, (word32)keySz, iv, AES_ENCRYPTION);
  12828. if (ret != 0)
  12829. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12830. #ifdef HAVE_AES_DECRYPT
  12831. ret = wc_AesSetKey(dec, key, (word32)keySz, iv, AES_DECRYPTION);
  12832. if (ret != 0)
  12833. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12834. #endif
  12835. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12836. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12837. #if defined(WOLFSSL_ASYNC_CRYPT)
  12838. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12839. #endif
  12840. if (ret != 0)
  12841. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12842. #ifdef HAVE_AES_DECRYPT
  12843. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12844. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12845. #if defined(WOLFSSL_ASYNC_CRYPT)
  12846. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12847. #endif
  12848. if (ret != 0)
  12849. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12850. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12851. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12852. }
  12853. #endif
  12854. #ifndef HAVE_RENESAS_SYNC
  12855. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12856. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12857. #endif
  12858. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12859. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12860. if (ret != 0)
  12861. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12862. #ifdef HAVE_AES_DECRYPT
  12863. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12864. if (ret != 0)
  12865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12866. #endif
  12867. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12868. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12869. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12870. #if defined(WOLFSSL_ASYNC_CRYPT)
  12871. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12872. #endif
  12873. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12874. if (ret != 0)
  12875. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12876. #ifdef HAVE_AES_DECRYPT
  12877. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12878. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12879. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12880. #if defined(WOLFSSL_ASYNC_CRYPT)
  12881. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12882. #endif
  12883. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12884. if (ret != 0)
  12885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12886. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12887. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12888. }
  12889. #endif
  12890. #ifndef HAVE_RENESAS_SYNC
  12891. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12892. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12893. #endif
  12894. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12895. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12896. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12897. if (ret != 0)
  12898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12899. #ifdef HAVE_AES_DECRYPT
  12900. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12901. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12902. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12903. if (ret != 0)
  12904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12905. #endif
  12906. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12907. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12908. #if defined(WOLFSSL_ASYNC_CRYPT)
  12909. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12910. #endif
  12911. if (ret != 0)
  12912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12913. #ifdef HAVE_AES_DECRYPT
  12914. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12915. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12916. #if defined(WOLFSSL_ASYNC_CRYPT)
  12917. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12918. #endif
  12919. if (ret != 0)
  12920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12921. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12922. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12923. }
  12924. #endif
  12925. #ifndef HAVE_RENESAS_SYNC
  12926. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12927. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12928. #endif
  12929. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12930. out:
  12931. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12932. if (enc) {
  12933. if (enc_inited)
  12934. wc_AesFree(enc);
  12935. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  12936. }
  12937. #ifdef HAVE_AES_DECRYPT
  12938. if (dec) {
  12939. if (dec_inited)
  12940. wc_AesFree(dec);
  12941. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  12942. }
  12943. #endif
  12944. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  12945. if (enc_inited)
  12946. wc_AesFree(enc);
  12947. #ifdef HAVE_AES_DECRYPT
  12948. if (dec_inited)
  12949. wc_AesFree(dec);
  12950. #endif /* HAVE_AES_DECRYPT */
  12951. #endif /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  12952. #endif /* HAVE_AES_CBC */
  12953. return ret;
  12954. }
  12955. #endif /* WOLFSSL_AES_256 */
  12956. #ifdef HAVE_AESGCM
  12957. #ifdef WOLFSSL_AES_128
  12958. static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz,
  12959. byte* plain, int plainSz, byte* cipher, int cipherSz,
  12960. byte* aad, int aadSz, byte* tag, int tagSz)
  12961. {
  12962. wc_test_ret_t ret;
  12963. int enc_inited = 0, dec_inited = 0;
  12964. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12965. Aes *enc = NULL;
  12966. Aes *dec = NULL;
  12967. #else
  12968. Aes enc[1];
  12969. Aes dec[1];
  12970. #endif
  12971. byte resultT[AES_BLOCK_SIZE];
  12972. byte resultP[AES_BLOCK_SIZE * 3];
  12973. byte resultC[AES_BLOCK_SIZE * 3];
  12974. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12975. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12976. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12977. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  12978. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  12979. #endif
  12980. XMEMSET(resultT, 0, sizeof(resultT));
  12981. XMEMSET(resultC, 0, sizeof(resultC));
  12982. XMEMSET(resultP, 0, sizeof(resultP));
  12983. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12984. if (ret != 0)
  12985. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12986. else
  12987. enc_inited = 1;
  12988. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12989. if (ret != 0)
  12990. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12991. else
  12992. dec_inited = 1;
  12993. ret = wc_AesGcmSetKey(enc, key, (word32)keySz);
  12994. if (ret != 0)
  12995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12996. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  12997. ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, (word32)ivSz,
  12998. resultT, (word32)tagSz, aad, (word32)aadSz);
  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. if (cipher != NULL) {
  13005. if (XMEMCMP(cipher, resultC, (word32)cipherSz))
  13006. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13007. }
  13008. if (XMEMCMP(tag, resultT, (unsigned long)tagSz))
  13009. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13010. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13011. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13012. ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz,
  13013. resultT, tagSz, aad, aadSz);
  13014. #if defined(WOLFSSL_ASYNC_CRYPT)
  13015. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13016. #endif
  13017. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13018. if (ret != 0)
  13019. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13020. if (cipher != NULL) {
  13021. if (XMEMCMP(cipher, resultC, (unsigned long)cipherSz))
  13022. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13023. }
  13024. if (XMEMCMP(tag, resultT, tagSz))
  13025. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13026. #endif
  13027. #ifdef HAVE_AES_DECRYPT
  13028. ret = wc_AesGcmSetKey(dec, key, (word32)keySz);
  13029. if (ret != 0)
  13030. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13031. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)cipherSz,
  13032. iv, (word32)ivSz, resultT, (word32)tagSz, aad, (word32)aadSz);
  13033. #if defined(WOLFSSL_ASYNC_CRYPT)
  13034. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13035. #endif
  13036. if (ret != 0)
  13037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13038. if (plain != NULL) {
  13039. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13040. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13041. }
  13042. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13043. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13044. ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz,
  13045. iv, ivSz, resultT, tagSz, aad, aadSz);
  13046. #if defined(WOLFSSL_ASYNC_CRYPT)
  13047. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13048. #endif
  13049. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13050. if (ret != 0)
  13051. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13052. if (plain != NULL) {
  13053. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13054. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13055. }
  13056. #endif
  13057. #endif /* HAVE_AES_DECRYPT */
  13058. ret = 0;
  13059. out:
  13060. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13061. if (enc) {
  13062. if (enc_inited)
  13063. wc_AesFree(enc);
  13064. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  13065. }
  13066. if (dec) {
  13067. if (dec_inited)
  13068. wc_AesFree(dec);
  13069. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  13070. }
  13071. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  13072. if (enc_inited)
  13073. wc_AesFree(enc);
  13074. if (dec_inited)
  13075. wc_AesFree(dec);
  13076. #endif
  13077. return ret;
  13078. }
  13079. #endif
  13080. /* tests that only use 12 byte IV and 16 or less byte AAD
  13081. * test vectors are from NIST SP 800-38D
  13082. * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES*/
  13083. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void)
  13084. {
  13085. #ifdef WOLFSSL_AES_128
  13086. byte key1[] = {
  13087. 0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62,
  13088. 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc
  13089. };
  13090. byte iv1[] = {
  13091. 0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa,
  13092. 0xe4, 0xed, 0x2f, 0x6d
  13093. };
  13094. ALIGN64 byte plain1[] = {
  13095. 0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad,
  13096. 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01,
  13097. 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac,
  13098. 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01
  13099. };
  13100. byte aad1[] = {
  13101. 0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73,
  13102. 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1
  13103. };
  13104. ALIGN64 byte cipher1[] = {
  13105. 0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d,
  13106. 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d,
  13107. 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46,
  13108. 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb
  13109. };
  13110. byte tag1[] = {
  13111. 0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7,
  13112. 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2
  13113. };
  13114. byte key2[] = {
  13115. 0x01, 0x6d, 0xbb, 0x38, 0xda, 0xa7, 0x6d, 0xfe,
  13116. 0x7d, 0xa3, 0x84, 0xeb, 0xf1, 0x24, 0x03, 0x64
  13117. };
  13118. byte iv2[] = {
  13119. 0x07, 0x93, 0xef, 0x3a, 0xda, 0x78, 0x2f, 0x78,
  13120. 0xc9, 0x8a, 0xff, 0xe3
  13121. };
  13122. ALIGN64 byte plain2[] = {
  13123. 0x4b, 0x34, 0xa9, 0xec, 0x57, 0x63, 0x52, 0x4b,
  13124. 0x19, 0x1d, 0x56, 0x16, 0xc5, 0x47, 0xf6, 0xb7
  13125. };
  13126. ALIGN64 byte cipher2[] = {
  13127. 0x60, 0x9a, 0xa3, 0xf4, 0x54, 0x1b, 0xc0, 0xfe,
  13128. 0x99, 0x31, 0xda, 0xad, 0x2e, 0xe1, 0x5d, 0x0c
  13129. };
  13130. byte tag2[] = {
  13131. 0x33, 0xaf, 0xec, 0x59, 0xc4, 0x5b, 0xaf, 0x68,
  13132. 0x9a, 0x5e, 0x1b, 0x13, 0xae, 0x42, 0x36, 0x19
  13133. };
  13134. byte key3[] = {
  13135. 0xb0, 0x1e, 0x45, 0xcc, 0x30, 0x88, 0xaa, 0xba,
  13136. 0x9f, 0xa4, 0x3d, 0x81, 0xd4, 0x81, 0x82, 0x3f
  13137. };
  13138. byte iv3[] = {
  13139. 0x5a, 0x2c, 0x4a, 0x66, 0x46, 0x87, 0x13, 0x45,
  13140. 0x6a, 0x4b, 0xd5, 0xe1
  13141. };
  13142. byte tag3[] = {
  13143. 0x01, 0x42, 0x80, 0xf9, 0x44, 0xf5, 0x3c, 0x68,
  13144. 0x11, 0x64, 0xb2, 0xff
  13145. };
  13146. wc_test_ret_t ret;
  13147. WOLFSSL_ENTER("aesgcm_default_test");
  13148. ret = aesgcm_default_test_helper(key1, sizeof(key1), iv1, sizeof(iv1),
  13149. plain1, sizeof(plain1), cipher1, sizeof(cipher1),
  13150. aad1, sizeof(aad1), tag1, sizeof(tag1));
  13151. if (ret != 0) {
  13152. return ret;
  13153. }
  13154. ret = aesgcm_default_test_helper(key2, sizeof(key2), iv2, sizeof(iv2),
  13155. plain2, sizeof(plain2), cipher2, sizeof(cipher2),
  13156. NULL, 0, tag2, sizeof(tag2));
  13157. if (ret != 0) {
  13158. return ret;
  13159. }
  13160. ret = aesgcm_default_test_helper(key3, sizeof(key3), iv3, sizeof(iv3),
  13161. NULL, 0, NULL, 0,
  13162. NULL, 0, tag3, sizeof(tag3));
  13163. if (ret != 0) {
  13164. return ret;
  13165. }
  13166. #endif
  13167. return 0;
  13168. }
  13169. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
  13170. {
  13171. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13172. Aes *enc = NULL;
  13173. Aes *dec = NULL;
  13174. #else
  13175. Aes enc[1];
  13176. Aes dec[1];
  13177. #endif
  13178. /*
  13179. * This is Test Case 16 from the document Galois/
  13180. * Counter Mode of Operation (GCM) by McGrew and
  13181. * Viega.
  13182. */
  13183. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  13184. {
  13185. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  13186. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  13187. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  13188. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  13189. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  13190. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  13191. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  13192. 0xba, 0x63, 0x7b, 0x39
  13193. };
  13194. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  13195. {
  13196. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13197. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13198. 0xab, 0xad, 0xda, 0xd2
  13199. };
  13200. #ifdef WOLFSSL_AES_256
  13201. #ifdef HAVE_RENESAS_SYNC
  13202. const byte *k1 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  13203. int k1Sz = (int)(256/8);
  13204. #else
  13205. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13206. {
  13207. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13208. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13209. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13210. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  13211. };
  13212. int k1Sz = (int)sizeof(k1);
  13213. #endif
  13214. #endif /* WOLFSSL_AES_256 */
  13215. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13216. {
  13217. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  13218. 0xde, 0xca, 0xf8, 0x88
  13219. };
  13220. #if defined(WOLFSSL_AES_256) || defined(WOLFSSL_AES_192)
  13221. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  13222. {
  13223. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  13224. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  13225. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  13226. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  13227. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  13228. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  13229. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  13230. 0xbc, 0xc9, 0xf6, 0x62
  13231. };
  13232. #endif /* WOLFSSL_AES_256 || WOLFSSL_AES_192 */
  13233. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13234. {
  13235. 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
  13236. 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b
  13237. };
  13238. /* FIPS, QAT and PIC32MZ HW Crypto only support 12-byte IV */
  13239. #if !defined(HAVE_FIPS) && \
  13240. !defined(WOLFSSL_PIC32MZ_CRYPT) && \
  13241. !defined(FREESCALE_LTC) && !defined(FREESCALE_MMCAU) && \
  13242. !defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13243. !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(WOLFSSL_KCAPI_AES) && \
  13244. !(defined(WOLF_CRYPTO_CB) && \
  13245. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  13246. #define ENABLE_NON_12BYTE_IV_TEST
  13247. #ifdef WOLFSSL_AES_192
  13248. /* Test Case 12, uses same plaintext and AAD data. */
  13249. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13250. {
  13251. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13252. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13253. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c
  13254. };
  13255. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13256. {
  13257. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  13258. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  13259. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  13260. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  13261. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  13262. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  13263. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  13264. 0xa6, 0x37, 0xb3, 0x9b
  13265. };
  13266. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  13267. {
  13268. 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
  13269. 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
  13270. 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
  13271. 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
  13272. 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
  13273. 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
  13274. 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
  13275. 0xe9, 0xb7, 0x37, 0x3b
  13276. };
  13277. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13278. {
  13279. 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
  13280. 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9
  13281. };
  13282. #endif /* WOLFSSL_AES_192 */
  13283. #ifdef WOLFSSL_AES_128
  13284. /* The following is an interesting test case from the example
  13285. * FIPS test vectors for AES-GCM. IVlen = 1 byte */
  13286. WOLFSSL_SMALL_STACK_STATIC const byte p3[] =
  13287. {
  13288. 0x57, 0xce, 0x45, 0x1f, 0xa5, 0xe2, 0x35, 0xa5,
  13289. 0x8e, 0x1a, 0xa2, 0x3b, 0x77, 0xcb, 0xaf, 0xe2
  13290. };
  13291. #ifdef HAVE_RENESAS_SYNC
  13292. const byte *k3 =
  13293. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  13294. int k3Sz = (int)(128/8);
  13295. #else
  13296. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  13297. {
  13298. 0xbb, 0x01, 0xd7, 0x03, 0x81, 0x1c, 0x10, 0x1a,
  13299. 0x35, 0xe0, 0xff, 0xd2, 0x91, 0xba, 0xf2, 0x4b
  13300. };
  13301. int k3Sz = (int)sizeof(k3);
  13302. #endif
  13303. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  13304. {
  13305. 0xca
  13306. };
  13307. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  13308. {
  13309. 0x6b, 0x5f, 0xb3, 0x9d, 0xc1, 0xc5, 0x7a, 0x4f,
  13310. 0xf3, 0x51, 0x4d, 0xc2, 0xd5, 0xf0, 0xd0, 0x07
  13311. };
  13312. WOLFSSL_SMALL_STACK_STATIC const byte a3[] =
  13313. {
  13314. 0x40, 0xfc, 0xdc, 0xd7, 0x4a, 0xd7, 0x8b, 0xf1,
  13315. 0x3e, 0x7c, 0x60, 0x55, 0x50, 0x51, 0xdd, 0x54
  13316. };
  13317. WOLFSSL_SMALL_STACK_STATIC const byte t3[] =
  13318. {
  13319. 0x06, 0x90, 0xed, 0x01, 0x34, 0xdd, 0xc6, 0x95,
  13320. 0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
  13321. };
  13322. #endif /* WOLFSSL_AES_128 */
  13323. #ifdef WOLFSSL_AES_256
  13324. int ivlen;
  13325. #endif
  13326. #endif
  13327. byte resultT[sizeof(t1) + AES_BLOCK_SIZE];
  13328. byte resultP[sizeof(p) + AES_BLOCK_SIZE];
  13329. byte resultC[sizeof(p) + AES_BLOCK_SIZE];
  13330. wc_test_ret_t ret = 0;
  13331. int alen;
  13332. int plen;
  13333. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13334. byte buf[sizeof(p) + AES_BLOCK_SIZE];
  13335. byte bufA[sizeof(a) + 1];
  13336. byte *large_aad = (byte*)XMALLOC((size_t)1024 + 16, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13337. #endif
  13338. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM)
  13339. #if !defined(BENCH_AESGCM_LARGE)
  13340. #define BENCH_AESGCM_LARGE 1024
  13341. #endif
  13342. #ifndef WOLFSSL_NO_MALLOC
  13343. byte *large_input = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13344. byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13345. byte *large_outdec = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13346. (void)alen;
  13347. (void)plen;
  13348. if ((! large_input) || (! large_output) || (! large_outdec))
  13349. ERROR_OUT(MEMORY_E, out);
  13350. #else
  13351. byte large_input[BENCH_AESGCM_LARGE];
  13352. byte large_output[BENCH_AESGCM_LARGE + AES_BLOCK_SIZE];
  13353. byte large_outdec[BENCH_AESGCM_LARGE];
  13354. #endif
  13355. XMEMSET(large_input, 0, BENCH_AESGCM_LARGE);
  13356. XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + AES_BLOCK_SIZE);
  13357. XMEMSET(large_outdec, 0, BENCH_AESGCM_LARGE);
  13358. #endif
  13359. WOLFSSL_ENTER("aesgcm_test");
  13360. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13361. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  13362. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  13363. if ((dec = (Aes *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  13364. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  13365. #endif
  13366. XMEMSET(resultT, 0, sizeof(resultT));
  13367. XMEMSET(resultC, 0, sizeof(resultC));
  13368. XMEMSET(resultP, 0, sizeof(resultP));
  13369. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13370. if (ret != 0)
  13371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13372. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13373. if (ret != 0)
  13374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13375. #ifdef WOLFSSL_AES_256
  13376. ret = wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13377. if (ret != 0)
  13378. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13379. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13380. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13381. resultT, sizeof(t1), a, sizeof(a));
  13382. #if defined(WOLFSSL_ASYNC_CRYPT)
  13383. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13384. #endif
  13385. if (ret != 0)
  13386. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13387. #ifndef HAVE_RENESAS_SYNC
  13388. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13389. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13390. if (XMEMCMP(t1, resultT, sizeof(t1)))
  13391. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13392. #endif
  13393. #ifdef HAVE_AES_DECRYPT
  13394. ret = wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13395. if (ret != 0)
  13396. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13397. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1),
  13398. iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13399. #if defined(WOLFSSL_ASYNC_CRYPT)
  13400. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13401. #endif
  13402. if (ret != 0)
  13403. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13404. if (XMEMCMP(p, resultP, sizeof(p)))
  13405. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13406. #endif /* HAVE_AES_DECRYPT */
  13407. /* Large buffer test */
  13408. #ifdef BENCH_AESGCM_LARGE
  13409. /* setup test buffer */
  13410. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13411. large_input[alen] = (byte)alen;
  13412. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13413. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13414. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13415. resultT, sizeof(t1), a, sizeof(a));
  13416. #if defined(WOLFSSL_ASYNC_CRYPT)
  13417. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13418. #endif
  13419. if (ret != 0)
  13420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13421. #ifdef HAVE_AES_DECRYPT
  13422. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13423. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13424. sizeof(t1), a, sizeof(a));
  13425. #if defined(WOLFSSL_ASYNC_CRYPT)
  13426. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13427. #endif
  13428. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13429. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13430. if (ret != 0)
  13431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13432. #endif /* HAVE_AES_DECRYPT */
  13433. #endif /* BENCH_AESGCM_LARGE */
  13434. #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256)
  13435. /* Variable IV length test */
  13436. for (ivlen=1; ivlen<k1Sz; ivlen++) {
  13437. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13438. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1,
  13439. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13440. #if defined(WOLFSSL_ASYNC_CRYPT)
  13441. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13442. #endif
  13443. if (ret != 0)
  13444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13445. #ifdef HAVE_AES_DECRYPT
  13446. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1,
  13447. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13448. #if defined(WOLFSSL_ASYNC_CRYPT)
  13449. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13450. #endif
  13451. if (ret != 0)
  13452. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13453. #endif /* HAVE_AES_DECRYPT */
  13454. }
  13455. #endif
  13456. #if !(defined(WOLF_CRYPTO_CB) && defined(HAVE_INTEL_QA_SYNC))
  13457. /* Variable authenticated data length test */
  13458. for (alen=0; alen<(int)sizeof(p); alen++) {
  13459. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13460. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13461. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13462. #if defined(WOLFSSL_ASYNC_CRYPT)
  13463. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13464. #endif
  13465. if (ret != 0)
  13466. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13467. #ifdef HAVE_AES_DECRYPT
  13468. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13469. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13470. #if defined(WOLFSSL_ASYNC_CRYPT)
  13471. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13472. #endif
  13473. if (ret != 0)
  13474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13475. #endif /* HAVE_AES_DECRYPT */
  13476. }
  13477. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13478. if (! large_aad)
  13479. ERROR_OUT(MEMORY_E, out);
  13480. XMEMSET(large_aad, 0, 1024+16);
  13481. /* Variable authenticated data length test */
  13482. for (alen=0; alen<=1024; alen+=16) {
  13483. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13484. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13485. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13486. if (ret != 0)
  13487. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13488. #ifdef HAVE_AES_DECRYPT
  13489. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13490. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13491. if (ret != 0)
  13492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13493. #endif /* HAVE_AES_DECRYPT */
  13494. }
  13495. /* Test unaligned memory of all potential arguments */
  13496. ret = wc_AesGcmSetKey(enc, k1, k1Sz);
  13497. if (ret != 0)
  13498. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13499. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13500. XMEMCPY(&buf[1], p, sizeof(p));
  13501. XMEMCPY(&bufA[1], a, sizeof(a));
  13502. ret = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1),
  13503. &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13504. if (ret != 0)
  13505. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13506. if (XMEMCMP(c1, &resultC[1], sizeof(c1)))
  13507. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13508. if (XMEMCMP(t1, &resultT[1], sizeof(t1)))
  13509. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13510. #ifdef HAVE_AES_DECRYPT
  13511. ret = wc_AesGcmSetKey(dec, k1, k1Sz);
  13512. if (ret != 0)
  13513. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13514. ret = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1),
  13515. iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13516. if (ret != 0)
  13517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13518. if (XMEMCMP(p, &resultP[1], sizeof(p)))
  13519. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13520. #endif /* HAVE_AES_DECRYPT */
  13521. #endif /* Xilinx Versal */
  13522. #endif
  13523. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13524. #ifdef BENCH_AESGCM_LARGE
  13525. /* Variable plain text length test */
  13526. for (plen=1; plen<BENCH_AESGCM_LARGE; plen++) {
  13527. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13528. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13529. (word32)plen, iv1, sizeof(iv1), resultT,
  13530. sizeof(t1), a, sizeof(a));
  13531. #if defined(WOLFSSL_ASYNC_CRYPT)
  13532. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13533. #endif
  13534. if (ret != 0)
  13535. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13536. #ifdef HAVE_AES_DECRYPT
  13537. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13538. (word32)plen, iv1, sizeof(iv1), resultT,
  13539. sizeof(t1), a, sizeof(a));
  13540. #if defined(WOLFSSL_ASYNC_CRYPT)
  13541. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13542. #endif
  13543. if (ret != 0)
  13544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13545. #endif /* HAVE_AES_DECRYPT */
  13546. }
  13547. #else /* BENCH_AESGCM_LARGE */
  13548. /* Variable plain text length test */
  13549. for (plen=1; plen<(int)sizeof(p); plen++) {
  13550. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13551. ret = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1,
  13552. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13553. #if defined(WOLFSSL_ASYNC_CRYPT)
  13554. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13555. #endif
  13556. if (ret != 0)
  13557. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13558. #ifdef HAVE_AES_DECRYPT
  13559. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1,
  13560. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13561. #if defined(WOLFSSL_ASYNC_CRYPT)
  13562. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13563. #endif
  13564. if (ret != 0)
  13565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13566. #endif /* HAVE_AES_DECRYPT */
  13567. }
  13568. #endif /* BENCH_AESGCM_LARGE */
  13569. #endif
  13570. #endif /* WOLFSSL_AES_256 */
  13571. /* test with IV != 12 bytes */
  13572. #ifdef ENABLE_NON_12BYTE_IV_TEST
  13573. XMEMSET(resultT, 0, sizeof(resultT));
  13574. XMEMSET(resultC, 0, sizeof(resultC));
  13575. XMEMSET(resultP, 0, sizeof(resultP));
  13576. #ifdef WOLFSSL_AES_192
  13577. wc_AesGcmSetKey(enc, k2, sizeof(k2));
  13578. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13579. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2),
  13580. resultT, sizeof(t1), a, sizeof(a));
  13581. #if defined(WOLFSSL_ASYNC_CRYPT)
  13582. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13583. #endif
  13584. if (ret != 0)
  13585. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13586. if (XMEMCMP(c2, resultC, sizeof(c2)))
  13587. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13588. if (XMEMCMP(t2, resultT, sizeof(t1)))
  13589. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13590. #ifdef HAVE_AES_DECRYPT
  13591. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1),
  13592. iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a));
  13593. #if defined(WOLFSSL_ASYNC_CRYPT)
  13594. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13595. #endif
  13596. if (ret != 0)
  13597. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13598. if (XMEMCMP(p, resultP, sizeof(p)))
  13599. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13600. #endif /* HAVE_AES_DECRYPT */
  13601. /* Large buffer test */
  13602. #ifdef BENCH_AESGCM_LARGE
  13603. wc_AesGcmSetKey(enc, k2, (word32)sizeof(k2));
  13604. wc_AesGcmSetKey(dec, k2, (word32)sizeof(k2));
  13605. /* setup test buffer */
  13606. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13607. large_input[alen] = (byte)alen;
  13608. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13609. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13610. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13611. resultT, sizeof(t1), a, sizeof(a));
  13612. #if defined(WOLFSSL_ASYNC_CRYPT)
  13613. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13614. #endif
  13615. if (ret != 0)
  13616. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13617. #ifdef HAVE_AES_DECRYPT
  13618. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13619. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13620. sizeof(t1), a, sizeof(a));
  13621. #if defined(WOLFSSL_ASYNC_CRYPT)
  13622. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13623. #endif
  13624. if (ret != 0)
  13625. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13626. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13627. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13628. #endif /* HAVE_AES_DECRYPT */
  13629. #endif /* BENCH_AESGCM_LARGE */
  13630. XMEMSET(resultT, 0, sizeof(resultT));
  13631. XMEMSET(resultC, 0, sizeof(resultC));
  13632. XMEMSET(resultP, 0, sizeof(resultP));
  13633. #endif /* WOLFSSL_AES_192 */
  13634. #ifdef WOLFSSL_AES_128
  13635. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13636. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13637. ret = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3),
  13638. resultT, sizeof(t3), a3, sizeof(a3));
  13639. #if defined(WOLFSSL_ASYNC_CRYPT)
  13640. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13641. #endif
  13642. if (ret != 0)
  13643. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13644. #ifndef HAVE_RENESAS_SYNC
  13645. if (XMEMCMP(c3, resultC, sizeof(c3)))
  13646. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13647. if (XMEMCMP(t3, resultT, sizeof(t3)))
  13648. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13649. #endif
  13650. #ifdef HAVE_AES_DECRYPT
  13651. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
  13652. iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3));
  13653. #if defined(WOLFSSL_ASYNC_CRYPT)
  13654. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13655. #endif
  13656. if (ret != 0)
  13657. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13658. if (XMEMCMP(p3, resultP, sizeof(p3)))
  13659. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13660. #endif /* HAVE_AES_DECRYPT */
  13661. /* Large buffer test */
  13662. #ifdef BENCH_AESGCM_LARGE
  13663. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13664. wc_AesGcmSetKey(dec, k3, (word32)k3Sz);
  13665. /* setup test buffer */
  13666. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13667. large_input[alen] = (byte)alen;
  13668. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13669. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13670. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13671. resultT, sizeof(t1), a, sizeof(a));
  13672. #if defined(WOLFSSL_ASYNC_CRYPT)
  13673. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13674. #endif
  13675. if (ret != 0)
  13676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13677. #ifdef HAVE_AES_DECRYPT
  13678. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13679. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13680. sizeof(t1), a, sizeof(a));
  13681. #if defined(WOLFSSL_ASYNC_CRYPT)
  13682. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13683. #endif
  13684. if (ret != 0)
  13685. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13686. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13687. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13688. #endif /* HAVE_AES_DECRYPT */
  13689. #endif /* BENCH_AESGCM_LARGE */
  13690. #endif /* WOLFSSL_AES_128 */
  13691. #endif /* ENABLE_NON_12BYTE_IV_TEST */
  13692. #if defined(WOLFSSL_AES_256) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13693. !defined(WOLFSSL_XILINX_CRYPT) && \
  13694. !(defined(WOLF_CRYPTO_CB) && \
  13695. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC))
  13696. XMEMSET(resultT, 0, sizeof(resultT));
  13697. XMEMSET(resultC, 0, sizeof(resultC));
  13698. XMEMSET(resultP, 0, sizeof(resultP));
  13699. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13700. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13701. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13702. resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13703. #if defined(WOLFSSL_ASYNC_CRYPT)
  13704. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13705. #endif
  13706. if (ret != 0)
  13707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13708. #ifndef HAVE_RENESAS_SYNC
  13709. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13710. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13711. if (XMEMCMP(t1, resultT + 1, sizeof(t1) - 1))
  13712. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13713. #endif
  13714. #ifdef HAVE_AES_DECRYPT
  13715. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p),
  13716. iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13717. #if defined(WOLFSSL_ASYNC_CRYPT)
  13718. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13719. #endif
  13720. if (ret != 0)
  13721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13722. if (XMEMCMP(p, resultP, sizeof(p)))
  13723. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13724. #endif /* HAVE_AES_DECRYPT */
  13725. #endif /* WOLFSSL_AES_256 */
  13726. #if !defined(HAVE_FIPS) || \
  13727. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  13728. /* Test encrypt with internally generated IV */
  13729. #if defined(WOLFSSL_AES_256) && !(defined(WC_NO_RNG) || defined(HAVE_SELFTEST)) \
  13730. && !(defined(WOLF_CRYPTO_CB) && defined(HAVE_CAVIUM_OCTEON_SYNC))
  13731. {
  13732. WC_RNG rng;
  13733. byte randIV[12];
  13734. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  13735. if (ret != 0)
  13736. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13737. XMEMSET(randIV, 0, sizeof(randIV));
  13738. XMEMSET(resultT, 0, sizeof(resultT));
  13739. XMEMSET(resultC, 0, sizeof(resultC));
  13740. XMEMSET(resultP, 0, sizeof(resultP));
  13741. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13742. ret = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng);
  13743. if (ret != 0)
  13744. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13745. ret = wc_AesGcmEncrypt_ex(enc,
  13746. resultC, p, sizeof(p),
  13747. randIV, sizeof(randIV),
  13748. resultT, sizeof(t1),
  13749. a, sizeof(a));
  13750. #if defined(WOLFSSL_ASYNC_CRYPT)
  13751. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13752. #endif
  13753. if (ret != 0)
  13754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13755. /* Check the IV has been set. */
  13756. {
  13757. word32 i, ivSum = 0;
  13758. for (i = 0; i < sizeof(randIV); i++)
  13759. ivSum += randIV[i];
  13760. if (ivSum == 0)
  13761. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13762. }
  13763. #ifdef HAVE_AES_DECRYPT
  13764. wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13765. ret = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng);
  13766. if (ret != 0)
  13767. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13768. ret = wc_AesGcmDecrypt(dec,
  13769. resultP, resultC, sizeof(c1),
  13770. randIV, sizeof(randIV),
  13771. resultT, sizeof(t1),
  13772. a, sizeof(a));
  13773. #if defined(WOLFSSL_ASYNC_CRYPT)
  13774. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13775. #endif
  13776. if (ret != 0)
  13777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13778. if (XMEMCMP(p, resultP, sizeof(p)))
  13779. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13780. #endif /* HAVE_AES_DECRYPT */
  13781. wc_FreeRng(&rng);
  13782. }
  13783. #endif /* WOLFSSL_AES_256 && !(WC_NO_RNG || HAVE_SELFTEST) */
  13784. #endif /* HAVE_FIPS_VERSION >= 2 */
  13785. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13786. #ifdef WOLFSSL_AES_256
  13787. #ifdef WOLFSSL_AESGCM_STREAM
  13788. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13789. if (ret != 0)
  13790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13791. ret = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a));
  13792. if (ret != 0)
  13793. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13794. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13795. if (ret != 0)
  13796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13797. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13798. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13799. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13800. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13801. #ifdef HAVE_AES_DECRYPT
  13802. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13803. if (ret != 0)
  13804. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13805. ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a));
  13806. if (ret != 0)
  13807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13808. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13809. if (ret != 0)
  13810. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13811. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13812. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13813. #endif
  13814. /* alen is the size to pass in with each update. */
  13815. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13816. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13817. if (ret != 0)
  13818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13819. /* plen is the offset into AAD to update with. */
  13820. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13821. int len = sizeof(a) - plen;
  13822. if (len > alen) len = alen;
  13823. ret = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13824. if (ret != 0)
  13825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13826. }
  13827. /* plen is the offset into plaintext to update with. */
  13828. for (plen = 0; plen < (int)sizeof(p); plen += alen) {
  13829. int len = sizeof(p) - plen;
  13830. if (len > alen) len = alen;
  13831. ret = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, (word32)len,
  13832. NULL, 0);
  13833. if (ret != 0)
  13834. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13835. }
  13836. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13837. if (ret != 0)
  13838. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13839. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13840. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13841. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13842. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13843. }
  13844. #ifdef HAVE_AES_DECRYPT
  13845. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13846. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13847. if (ret != 0)
  13848. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13849. /* plen is the offset into AAD to update with. */
  13850. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13851. int len = sizeof(a) - plen;
  13852. if (len > alen) len = alen;
  13853. ret = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13854. if (ret != 0)
  13855. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13856. }
  13857. /* plen is the offset into cipher text to update with. */
  13858. for (plen = 0; plen < (int)sizeof(c1); plen += alen) {
  13859. int len = sizeof(c1) - plen;
  13860. if (len > alen) len = alen;
  13861. ret = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, (word32)len,
  13862. NULL, 0);
  13863. if (ret != 0)
  13864. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13865. }
  13866. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13867. if (ret != 0)
  13868. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13869. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13870. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13871. }
  13872. #endif /* HAVE_AES_DECRYPT */
  13873. #ifdef BENCH_AESGCM_LARGE
  13874. /* setup test buffer */
  13875. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13876. if (ret != 0)
  13877. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13878. ret = wc_AesGcmEncryptUpdate(enc, large_output, large_input,
  13879. BENCH_AESGCM_LARGE, a, sizeof(a));
  13880. if (ret != 0)
  13881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13882. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13883. if (ret != 0)
  13884. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13885. #ifdef HAVE_AES_DECRYPT
  13886. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13887. if (ret != 0)
  13888. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13889. ret = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output,
  13890. BENCH_AESGCM_LARGE, a, sizeof(a));
  13891. if (ret != 0)
  13892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13893. ret = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1));
  13894. if (ret != 0)
  13895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13896. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13897. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13898. #endif /* HAVE_AES_DECRYPT */
  13899. #endif /* BENCH_AESGCM_LARGE */
  13900. #endif /* WOLFSSL_AESGCM_STREAM */
  13901. #endif /* WOLFSSL_AES_256 */
  13902. #endif /* !WOLFSSL_AFALG_XILINX_AES && !WOLFSSL_XILINX_CRYPT */
  13903. wc_AesFree(enc);
  13904. wc_AesFree(dec);
  13905. ret = 0;
  13906. out:
  13907. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  13908. !defined(WOLFSSL_NO_MALLOC)
  13909. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13910. XFREE(large_output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13911. XFREE(large_outdec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13912. #endif
  13913. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13914. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  13915. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  13916. #endif
  13917. return ret;
  13918. }
  13919. #ifdef WOLFSSL_AES_128
  13920. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void)
  13921. {
  13922. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13923. Gmac *gmac;
  13924. #else
  13925. Gmac gmac[1];
  13926. #endif
  13927. wc_test_ret_t ret;
  13928. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13929. {
  13930. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  13931. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  13932. };
  13933. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13934. {
  13935. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  13936. 0xe2, 0x8c, 0x8f, 0x16
  13937. };
  13938. WOLFSSL_SMALL_STACK_STATIC const byte a1[] =
  13939. {
  13940. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  13941. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  13942. };
  13943. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13944. {
  13945. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  13946. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  13947. };
  13948. #if (!defined(HAVE_FIPS) || \
  13949. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
  13950. /* FIPS builds only allow 16-byte auth tags. */
  13951. /* This sample uses a 15-byte auth tag. */
  13952. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13953. {
  13954. 0x40, 0xf7, 0xec, 0xb2, 0x52, 0x6d, 0xaa, 0xd4,
  13955. 0x74, 0x25, 0x1d, 0xf4, 0x88, 0x9e, 0xf6, 0x5b
  13956. };
  13957. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13958. {
  13959. 0xee, 0x9c, 0x6e, 0x06, 0x15, 0x45, 0x45, 0x03,
  13960. 0x1a, 0x60, 0x24, 0xa7
  13961. };
  13962. WOLFSSL_SMALL_STACK_STATIC const byte a2[] =
  13963. {
  13964. 0x94, 0x81, 0x2c, 0x87, 0x07, 0x4e, 0x15, 0x18,
  13965. 0x34, 0xb8, 0x35, 0xaf, 0x1c, 0xa5, 0x7e, 0x56
  13966. };
  13967. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13968. {
  13969. 0xc6, 0x81, 0x79, 0x8e, 0x3d, 0xda, 0xb0, 0x9f,
  13970. 0x8d, 0x83, 0xb0, 0xbb, 0x14, 0xb6, 0x91
  13971. };
  13972. #endif
  13973. byte tag[16];
  13974. WOLFSSL_ENTER("gmac_test");
  13975. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13976. if ((gmac = (Gmac *)XMALLOC(sizeof *gmac, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  13977. return WC_TEST_RET_ENC_ERRNO;
  13978. #endif
  13979. XMEMSET(gmac, 0, sizeof *gmac); /* clear context */
  13980. (void)wc_AesInit(&gmac->aes, HEAP_HINT, INVALID_DEVID); /* Make sure devId updated */
  13981. XMEMSET(tag, 0, sizeof(tag));
  13982. wc_GmacSetKey(gmac, k1, sizeof(k1));
  13983. wc_GmacUpdate(gmac, iv1, sizeof(iv1), a1, sizeof(a1), tag, sizeof(t1));
  13984. if (XMEMCMP(t1, tag, sizeof(t1)) != 0)
  13985. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13986. #if (!defined(HAVE_FIPS) || \
  13987. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) )
  13988. XMEMSET(tag, 0, sizeof(tag));
  13989. wc_GmacSetKey(gmac, k2, sizeof(k2));
  13990. wc_GmacUpdate(gmac, iv2, sizeof(iv2), a2, sizeof(a2), tag, sizeof(t2));
  13991. if (XMEMCMP(t2, tag, sizeof(t2)) != 0)
  13992. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13993. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT)
  13994. {
  13995. WOLFSSL_SMALL_STACK_STATIC const byte badT[] =
  13996. {
  13997. 0xde, 0xad, 0xbe, 0xef, 0x17, 0x2e, 0xd0, 0x43,
  13998. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  13999. };
  14000. WC_RNG rng;
  14001. byte iv[12];
  14002. #ifndef HAVE_FIPS
  14003. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14004. if (ret != 0)
  14005. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14006. #else
  14007. ret = wc_InitRng(&rng);
  14008. if (ret != 0)
  14009. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14010. #endif
  14011. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14012. t1, sizeof(t1));
  14013. if (ret != 0)
  14014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14015. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14016. badT, sizeof(badT));
  14017. if (ret != WC_NO_ERR_TRACE(AES_GCM_AUTH_E))
  14018. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14019. ret = wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2),
  14020. t2, sizeof(t2));
  14021. if (ret != 0)
  14022. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14023. XMEMSET(tag, 0, sizeof(tag));
  14024. XMEMSET(iv, 0, sizeof(iv));
  14025. ret = wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14026. tag, sizeof(tag), &rng);
  14027. if (ret != 0)
  14028. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14029. ret = wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14030. tag, sizeof(tag));
  14031. if (ret != 0)
  14032. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14033. wc_FreeRng(&rng);
  14034. }
  14035. #endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */
  14036. #endif /* HAVE_FIPS */
  14037. ret = 0;
  14038. out:
  14039. wc_AesFree(&gmac->aes);
  14040. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14041. XFREE(gmac, HEAP_HINT, DYNAMIC_TYPE_AES);
  14042. #endif
  14043. return ret;
  14044. }
  14045. #endif /* WOLFSSL_AES_128 */
  14046. #endif /* HAVE_AESGCM */
  14047. #if defined(HAVE_AESCCM)
  14048. #if defined(WOLFSSL_AES_256)
  14049. static wc_test_ret_t aesccm_256_test(void)
  14050. {
  14051. wc_test_ret_t ret;
  14052. /* Test vectors from NIST AES CCM 256-bit CAST Example #1 */
  14053. WOLFSSL_SMALL_STACK_STATIC const byte in_key[32] = {
  14054. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14055. 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
  14056. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14057. 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
  14058. };
  14059. WOLFSSL_SMALL_STACK_STATIC const byte in_nonce[7] = {
  14060. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
  14061. WOLFSSL_SMALL_STACK_STATIC const byte in_auth[8] = {
  14062. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  14063. WOLFSSL_SMALL_STACK_STATIC const byte in_plaintext[4] = {
  14064. 0x20, 0x21, 0x22, 0x23};
  14065. WOLFSSL_SMALL_STACK_STATIC const byte exp_ciphertext[4] = {
  14066. 0x8A, 0xB1, 0xA8, 0x74};
  14067. WOLFSSL_SMALL_STACK_STATIC const byte exp_tag[4] = {
  14068. 0x95, 0xFC, 0x08, 0x20};
  14069. byte output[sizeof(in_plaintext)];
  14070. byte atag[sizeof(exp_tag)];
  14071. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14072. Aes* aes = (Aes*)XMALLOC(sizeof(Aes), HEAP_HINT, DYNAMIC_TYPE_AES);
  14073. if (aes == NULL) {
  14074. return MEMORY_E;
  14075. }
  14076. #else
  14077. Aes aes[1];
  14078. #endif
  14079. ret = wc_AesInit(aes, HEAP_HINT, devId);
  14080. if (ret == 0) {
  14081. ret = wc_AesCcmSetKey(aes, in_key, sizeof(in_key));
  14082. }
  14083. if (ret == 0) {
  14084. ret = wc_AesCcmEncrypt(aes, output, in_plaintext, sizeof(in_plaintext),
  14085. in_nonce, sizeof(in_nonce),
  14086. atag, sizeof(atag),
  14087. in_auth, sizeof(in_auth));
  14088. }
  14089. /* Verify we produce the proper ciphertext and tag */
  14090. if (ret == 0 &&
  14091. (XMEMCMP(output, exp_ciphertext, sizeof(output)) ||
  14092. XMEMCMP(atag, exp_tag, sizeof(atag)))) {
  14093. ret = WC_TEST_RET_ENC_NC;
  14094. }
  14095. #ifdef HAVE_AES_DECRYPT
  14096. if (ret == 0) {
  14097. /* decrypt inline */
  14098. ret = wc_AesCcmDecrypt(aes, output, output, sizeof(output),
  14099. in_nonce, sizeof(in_nonce),
  14100. atag, sizeof(atag),
  14101. in_auth, sizeof(in_auth));
  14102. }
  14103. /* Verify decryption was successful */
  14104. if (ret == 0 &&
  14105. XMEMCMP(output, in_plaintext, sizeof(output))) {
  14106. ret = WC_TEST_RET_ENC_NC;
  14107. }
  14108. #endif
  14109. wc_AesFree(aes);
  14110. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14111. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  14112. #endif
  14113. return ret;
  14114. }
  14115. #endif /* WOLFSSL_AES_256 */
  14116. #if defined(WOLFSSL_AES_128)
  14117. static wc_test_ret_t aesccm_128_test(void)
  14118. {
  14119. wc_test_ret_t ret;
  14120. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14121. Aes *enc;
  14122. #else
  14123. Aes enc[1];
  14124. #endif
  14125. /* key */
  14126. WOLFSSL_SMALL_STACK_STATIC const byte k[] =
  14127. {
  14128. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  14129. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  14130. };
  14131. /* nonce */
  14132. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  14133. {
  14134. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  14135. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  14136. };
  14137. /* plaintext */
  14138. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  14139. {
  14140. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14141. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14142. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  14143. };
  14144. /* plaintext - long */
  14145. WOLFSSL_SMALL_STACK_STATIC const byte pl[] =
  14146. {
  14147. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14148. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14149. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  14150. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14151. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  14152. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  14153. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  14154. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14155. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  14156. 0x50
  14157. };
  14158. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  14159. {
  14160. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14161. };
  14162. /* ciphertext */
  14163. WOLFSSL_SMALL_STACK_STATIC const byte c[] =
  14164. {
  14165. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14166. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14167. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  14168. };
  14169. /* tag - authentication */
  14170. WOLFSSL_SMALL_STACK_STATIC const byte t[] =
  14171. {
  14172. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  14173. };
  14174. /* ciphertext - long */
  14175. WOLFSSL_SMALL_STACK_STATIC const byte cl[] =
  14176. {
  14177. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14178. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14179. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0xe0,
  14180. 0x44, 0x2d, 0xbe, 0x25, 0xfa, 0x48, 0x2b, 0xa8,
  14181. 0x36, 0x0b, 0xbf, 0x01, 0xc0, 0x12, 0x45, 0xa4,
  14182. 0x82, 0x9f, 0x20, 0x6c, 0xc3, 0xd6, 0xae, 0x5b,
  14183. 0x54, 0x8d, 0xd0, 0xb1, 0x69, 0x2c, 0xec, 0x5e,
  14184. 0x95, 0xa5, 0x6b, 0x48, 0xc3, 0xc6, 0xc8, 0x9e,
  14185. 0xc7, 0x92, 0x98, 0x9d, 0x26, 0x7d, 0x2a, 0x10,
  14186. 0x0b
  14187. };
  14188. /* tag - authentication - long */
  14189. WOLFSSL_SMALL_STACK_STATIC const byte tl[] =
  14190. {
  14191. 0x89, 0xd8, 0xd2, 0x02, 0xc5, 0xcf, 0xae, 0xf4
  14192. };
  14193. /* tag - authentication - empty plaintext */
  14194. WOLFSSL_SMALL_STACK_STATIC const byte t_empty[] =
  14195. {
  14196. 0xe4, 0x28, 0x8a, 0xc3, 0x78, 0x00, 0x0f, 0xf5
  14197. };
  14198. byte t2[sizeof(t)];
  14199. byte p2[sizeof(p)];
  14200. byte c2[sizeof(c)];
  14201. byte iv2[sizeof(iv)];
  14202. byte pl2[sizeof(pl)];
  14203. byte cl2[sizeof(cl)];
  14204. byte tl2[sizeof(tl)];
  14205. byte t_empty2[sizeof(t_empty)];
  14206. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14207. if ((enc = (Aes *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  14208. return WC_TEST_RET_ENC_ERRNO;
  14209. #endif
  14210. XMEMSET(enc, 0, sizeof *enc); /* clear context */
  14211. XMEMSET(t2, 0, sizeof(t2));
  14212. XMEMSET(c2, 0, sizeof(c2));
  14213. XMEMSET(p2, 0, sizeof(p2));
  14214. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14215. if (ret != 0)
  14216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14217. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14218. if (ret != 0)
  14219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14220. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14221. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14222. t2, sizeof(t2), a, sizeof(a));
  14223. if (ret != 0)
  14224. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14225. if (XMEMCMP(c, c2, sizeof(c2)))
  14226. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14227. if (XMEMCMP(t, t2, sizeof(t2)))
  14228. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14229. #ifdef HAVE_AES_DECRYPT
  14230. ret = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv),
  14231. t2, sizeof(t2), a, sizeof(a));
  14232. if (ret != 0)
  14233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14234. if (XMEMCMP(p, p2, sizeof(p2)))
  14235. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14236. /* Test the authentication failure */
  14237. t2[0]++; /* Corrupt the authentication tag. */
  14238. ret = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv),
  14239. t2, sizeof(t2), a, sizeof(a));
  14240. if (ret == 0)
  14241. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14242. /* Clear c2 to compare against p2. p2 should be set to zero in case of
  14243. * authentication fail. */
  14244. XMEMSET(c2, 0, sizeof(c2));
  14245. if (XMEMCMP(p2, c2, sizeof(p2)))
  14246. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14247. #endif
  14248. wc_AesFree(enc);
  14249. XMEMSET(enc, 0, sizeof(Aes)); /* clear context */
  14250. XMEMSET(t2, 0, sizeof(t2));
  14251. XMEMSET(c2, 0, sizeof(c2));
  14252. XMEMSET(p2, 0, sizeof(p2));
  14253. XMEMSET(iv2, 0, sizeof(iv2));
  14254. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14255. if (ret != 0)
  14256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14257. #ifndef HAVE_SELFTEST
  14258. /* selftest build does not have wc_AesCcmSetNonce() or
  14259. * wc_AesCcmEncrypt_ex() */
  14260. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14261. if (ret != 0)
  14262. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14263. ret = wc_AesCcmSetNonce(enc, iv, sizeof(iv));
  14264. if (ret != 0)
  14265. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14266. ret = wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2),
  14267. t2, sizeof(t2), a, sizeof(a));
  14268. if (ret != 0)
  14269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14270. if (XMEMCMP(iv, iv2, sizeof(iv2)))
  14271. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14272. if (XMEMCMP(c, c2, sizeof(c2)))
  14273. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14274. if (XMEMCMP(t, t2, sizeof(t2)))
  14275. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14276. #endif
  14277. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  14278. /* test fail on invalid IV sizes */
  14279. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14280. if (ret != 0)
  14281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14282. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14283. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14284. t2, 1, a, sizeof(a));
  14285. if (ret == 0) {
  14286. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14287. }
  14288. #endif
  14289. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14290. ret = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv),
  14291. tl2, sizeof(tl2), a, sizeof(a));
  14292. if (ret != 0)
  14293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14294. if (XMEMCMP(cl, cl2, sizeof(cl2)))
  14295. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14296. if (XMEMCMP(tl, tl2, sizeof(tl2)))
  14297. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14298. #ifdef HAVE_AES_DECRYPT
  14299. ret = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv),
  14300. tl2, sizeof(tl2), a, sizeof(a));
  14301. if (ret != 0)
  14302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14303. if (XMEMCMP(pl, pl2, sizeof(pl2)))
  14304. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14305. #endif
  14306. /* test empty message as null input or output with nonzero inSz. */
  14307. ret = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* in */, 1 /* inSz */,
  14308. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14309. a, sizeof(a));
  14310. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14312. ret = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14313. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14314. a, sizeof(a));
  14315. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14317. #ifdef HAVE_AES_DECRYPT
  14318. ret = wc_AesCcmDecrypt(enc, pl2, NULL /* in */, 1 /* inSz */,
  14319. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14320. sizeof(a));
  14321. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14322. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14323. ret = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14324. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14325. sizeof(a));
  14326. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14327. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14328. #endif
  14329. /* test empty message as null input and output with zero inSz --
  14330. * must either succeed, or fail early with BAD_FUNC_ARG.
  14331. */
  14332. ret = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */,
  14333. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14334. a, sizeof(a));
  14335. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  14336. if (ret != 0)
  14337. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14338. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14339. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14340. #ifdef HAVE_AES_DECRYPT
  14341. ret = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */,
  14342. 0 /* inSz */, iv, sizeof(iv), t_empty2,
  14343. sizeof(t_empty2), a, sizeof(a));
  14344. if (ret != 0)
  14345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14346. #endif
  14347. }
  14348. /* test empty message as zero-length string -- must work. */
  14349. ret = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv,
  14350. sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14351. sizeof(a));
  14352. if (ret != 0)
  14353. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14354. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14355. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14356. #ifdef HAVE_AES_DECRYPT
  14357. ret = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */,
  14358. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14359. sizeof(a));
  14360. if (ret != 0)
  14361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14362. #endif
  14363. wc_AesFree(enc);
  14364. ret = 0;
  14365. out:
  14366. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14367. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  14368. #endif
  14369. return ret;
  14370. }
  14371. #endif /* WOLFSSL_AES_128 */
  14372. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void)
  14373. {
  14374. wc_test_ret_t ret = 0;
  14375. WOLFSSL_ENTER("aesccm_test");
  14376. #ifdef WOLFSSL_AES_128
  14377. if (ret == 0)
  14378. ret = aesccm_128_test();
  14379. #endif
  14380. #ifdef WOLFSSL_AES_256
  14381. if (ret == 0)
  14382. ret = aesccm_256_test();
  14383. #endif
  14384. return ret;
  14385. }
  14386. #endif /* HAVE_AESCCM */
  14387. #if defined(WOLFSSL_AES_EAX) && \
  14388. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  14389. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void)
  14390. {
  14391. typedef struct {
  14392. byte key[AES_256_KEY_SIZE];
  14393. int key_length;
  14394. byte iv[AES_BLOCK_SIZE];
  14395. int iv_length;
  14396. byte aad[AES_BLOCK_SIZE * 2];
  14397. int aad_length;
  14398. byte msg[AES_BLOCK_SIZE * 2];
  14399. int msg_length;
  14400. byte ct[AES_BLOCK_SIZE * 2];
  14401. int ct_length;
  14402. byte tag[AES_BLOCK_SIZE];
  14403. int tag_length;
  14404. int valid;
  14405. } AadVector;
  14406. /* A small selection of Google wycheproof vectors that use vectors
  14407. * from the original paper: eprint.iacr.org/2003/069
  14408. * https://github.com/google/wycheproof/blob/master/testvectors/aes_eax_test.json
  14409. */
  14410. WOLFSSL_SMALL_STACK_STATIC const AadVector vectors[] = {
  14411. /* Vector from paper - empty message with auth data */
  14412. {
  14413. /* key, key length */
  14414. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  14415. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  14416. /* iv, iv length */
  14417. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  14418. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  14419. /* aad, aad length */
  14420. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  14421. /* msg, msg length */
  14422. {0}, 0,
  14423. /* ct, ct length */
  14424. {0}, 0,
  14425. /* tag, tag length */
  14426. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2,
  14427. 0x7b, 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  14428. /* valid */
  14429. 1,
  14430. },
  14431. /* Vector from paper - no auth data, valid auth tag */
  14432. {
  14433. /* key, key length */
  14434. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14435. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14436. /* iv , iv length */
  14437. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  14438. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  14439. /* aad, aad length */
  14440. {0}, 0,
  14441. /* msg, msg length */
  14442. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14443. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14444. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  14445. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  14446. /* ct, ct length */
  14447. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  14448. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  14449. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  14450. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  14451. /* tag, tag length */
  14452. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  14453. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  14454. /* valid */
  14455. 1,
  14456. },
  14457. /* Vector from paper - no auth data with invalid auth tag */
  14458. {
  14459. /* key, key length */
  14460. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14461. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14462. /* iv, iv length */
  14463. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14464. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  14465. /* aad, aad length */
  14466. {0}, 0,
  14467. /* msg, msg length */
  14468. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14469. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  14470. /* ct , ct length */
  14471. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  14472. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  14473. /* tag, tag length */
  14474. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  14475. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  14476. /* valid */
  14477. 0,
  14478. },
  14479. };
  14480. WOLFSSL_SMALL_STACK_STATIC byte ciphertext[sizeof(vectors[0].ct)];
  14481. WOLFSSL_SMALL_STACK_STATIC byte authtag[sizeof(vectors[0].tag)];
  14482. int i;
  14483. int len;
  14484. wc_test_ret_t ret;
  14485. WOLFSSL_ENTER("aes_eax_test");
  14486. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  14487. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14488. len = sizeof(authtag);
  14489. ret = wc_AesEaxEncryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14490. ciphertext,
  14491. vectors[i].msg, (word32)vectors[i].msg_length,
  14492. vectors[i].iv, (word32)vectors[i].iv_length,
  14493. authtag, (word32)len,
  14494. vectors[i].aad, (word32)vectors[i].aad_length);
  14495. if (ret != 0) {
  14496. return WC_TEST_RET_ENC_EC(ret);
  14497. }
  14498. /* check ciphertext matches vector */
  14499. if (XMEMCMP(ciphertext, vectors[i].ct, (size_t)vectors[i].ct_length)) {
  14500. return WC_TEST_RET_ENC_NC;
  14501. }
  14502. /* check that tag matches vector only for vectors marked as valid */
  14503. ret = XMEMCMP(authtag, vectors[i].tag, len);
  14504. if (vectors[i].valid == 1 && ret != 0 ) {
  14505. return WC_TEST_RET_ENC_NC;
  14506. }
  14507. else if (vectors[i].valid == 0 && ret == 0) {
  14508. return WC_TEST_RET_ENC_NC;
  14509. }
  14510. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14511. ret = wc_AesEaxDecryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14512. ciphertext,
  14513. vectors[i].ct, (word32)vectors[i].ct_length,
  14514. vectors[i].iv, (word32)vectors[i].iv_length,
  14515. authtag, (word32)len,
  14516. vectors[i].aad, (word32)vectors[i].aad_length);
  14517. if (ret != 0) {
  14518. return WC_TEST_RET_ENC_EC(ret);
  14519. }
  14520. /* check decrypted ciphertext matches vector plaintext */
  14521. if (XMEMCMP(ciphertext, vectors[i].msg, (size_t)vectors[i].msg_length)) {
  14522. return WC_TEST_RET_ENC_NC;
  14523. }
  14524. }
  14525. return 0;
  14526. }
  14527. #endif /* WOLFSSL_AES_EAX */
  14528. #ifdef HAVE_AES_KEYWRAP
  14529. #define MAX_KEYWRAP_TEST_OUTLEN 40
  14530. #define MAX_KEYWRAP_TEST_PLAINLEN 32
  14531. typedef struct keywrapVector {
  14532. const byte* kek;
  14533. const byte* data;
  14534. const byte* verify;
  14535. word32 kekLen;
  14536. word32 dataLen;
  14537. word32 verifyLen;
  14538. } keywrapVector;
  14539. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void)
  14540. {
  14541. int wrapSz, plainSz, testSz, i;
  14542. /* test vectors from RFC 3394 (kek, data, verify) */
  14543. #ifdef WOLFSSL_AES_128
  14544. /* Wrap 128 bits of Key Data with a 128-bit KEK */
  14545. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14546. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14547. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14548. };
  14549. WOLFSSL_SMALL_STACK_STATIC const byte d1[] = {
  14550. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14551. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14552. };
  14553. WOLFSSL_SMALL_STACK_STATIC const byte v1[] = {
  14554. 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
  14555. 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
  14556. 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
  14557. };
  14558. #endif /* WOLFSSL_AES_128 */
  14559. #ifdef WOLFSSL_AES_192
  14560. /* Wrap 128 bits of Key Data with a 192-bit KEK */
  14561. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  14562. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14563. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14564. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14565. };
  14566. WOLFSSL_SMALL_STACK_STATIC const byte d2[] = {
  14567. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14568. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14569. };
  14570. WOLFSSL_SMALL_STACK_STATIC const byte v2[] = {
  14571. 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35,
  14572. 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2,
  14573. 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D
  14574. };
  14575. #endif
  14576. #ifdef WOLFSSL_AES_256
  14577. /* Wrap 128 bits of Key Data with a 256-bit KEK */
  14578. WOLFSSL_SMALL_STACK_STATIC const byte k3[] = {
  14579. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14580. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14581. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14582. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14583. };
  14584. WOLFSSL_SMALL_STACK_STATIC const byte d3[] = {
  14585. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14586. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14587. };
  14588. WOLFSSL_SMALL_STACK_STATIC const byte v3[] = {
  14589. 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2,
  14590. 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A,
  14591. 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7
  14592. };
  14593. #endif
  14594. #ifdef WOLFSSL_AES_192
  14595. /* Wrap 192 bits of Key Data with a 192-bit KEK */
  14596. WOLFSSL_SMALL_STACK_STATIC const byte k4[] = {
  14597. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14598. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14599. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14600. };
  14601. WOLFSSL_SMALL_STACK_STATIC const byte d4[] = {
  14602. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14603. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14604. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14605. };
  14606. WOLFSSL_SMALL_STACK_STATIC const byte v4[] = {
  14607. 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32,
  14608. 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC,
  14609. 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93,
  14610. 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2
  14611. };
  14612. #endif
  14613. #ifdef WOLFSSL_AES_256
  14614. /* Wrap 192 bits of Key Data with a 256-bit KEK */
  14615. WOLFSSL_SMALL_STACK_STATIC const byte k5[] = {
  14616. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14617. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14618. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14619. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14620. };
  14621. WOLFSSL_SMALL_STACK_STATIC const byte d5[] = {
  14622. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14623. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14624. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14625. };
  14626. WOLFSSL_SMALL_STACK_STATIC const byte v5[] = {
  14627. 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F,
  14628. 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4,
  14629. 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95,
  14630. 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1
  14631. };
  14632. /* Wrap 256 bits of Key Data with a 256-bit KEK */
  14633. WOLFSSL_SMALL_STACK_STATIC const byte k6[] = {
  14634. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14635. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14636. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14637. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14638. };
  14639. WOLFSSL_SMALL_STACK_STATIC const byte d6[] = {
  14640. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14641. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14642. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14643. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14644. };
  14645. WOLFSSL_SMALL_STACK_STATIC const byte v6[] = {
  14646. 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4,
  14647. 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26,
  14648. 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26,
  14649. 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B,
  14650. 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21
  14651. };
  14652. #endif /* WOLFSSL_AES_256 */
  14653. byte output[MAX_KEYWRAP_TEST_OUTLEN];
  14654. byte plain [MAX_KEYWRAP_TEST_PLAINLEN];
  14655. const keywrapVector test_wrap[] =
  14656. {
  14657. #ifdef WOLFSSL_AES_128
  14658. {k1, d1, v1, sizeof(k1), sizeof(d1), sizeof(v1)},
  14659. #endif
  14660. #ifdef WOLFSSL_AES_192
  14661. {k2, d2, v2, sizeof(k2), sizeof(d2), sizeof(v2)},
  14662. #endif
  14663. #ifdef WOLFSSL_AES_256
  14664. {k3, d3, v3, sizeof(k3), sizeof(d3), sizeof(v3)},
  14665. #endif
  14666. #ifdef WOLFSSL_AES_192
  14667. {k4, d4, v4, sizeof(k4), sizeof(d4), sizeof(v4)},
  14668. #endif
  14669. #ifdef WOLFSSL_AES_256
  14670. {k5, d5, v5, sizeof(k5), sizeof(d5), sizeof(v5)},
  14671. {k6, d6, v6, sizeof(k6), sizeof(d6), sizeof(v6)}
  14672. #endif
  14673. };
  14674. WOLFSSL_ENTER("aeskeywrap_test");
  14675. testSz = sizeof(test_wrap) / sizeof(keywrapVector);
  14676. XMEMSET(output, 0, sizeof(output));
  14677. XMEMSET(plain, 0, sizeof(plain));
  14678. for (i = 0; i < testSz; i++) {
  14679. wrapSz = wc_AesKeyWrap(test_wrap[i].kek, test_wrap[i].kekLen,
  14680. test_wrap[i].data, test_wrap[i].dataLen,
  14681. output, sizeof(output), NULL);
  14682. if ( (wrapSz < 0) || (wrapSz != (int)test_wrap[i].verifyLen) )
  14683. return WC_TEST_RET_ENC_NC;
  14684. if (XMEMCMP(output, test_wrap[i].verify, test_wrap[i].verifyLen) != 0)
  14685. return WC_TEST_RET_ENC_NC;
  14686. plainSz = wc_AesKeyUnWrap((byte*)test_wrap[i].kek, test_wrap[i].kekLen,
  14687. output, (word32)wrapSz,
  14688. plain, sizeof(plain), NULL);
  14689. if ( (plainSz < 0) || (plainSz != (int)test_wrap[i].dataLen) )
  14690. return WC_TEST_RET_ENC_NC;
  14691. if (XMEMCMP(plain, test_wrap[i].data, test_wrap[i].dataLen) != 0)
  14692. return WC_TEST_RET_ENC_I(i);
  14693. }
  14694. return 0;
  14695. }
  14696. #endif /* HAVE_AES_KEYWRAP */
  14697. #endif /* NO_AES */
  14698. #ifdef HAVE_ARIA
  14699. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz)
  14700. {
  14701. #ifndef DEBUG_WOLFSSL
  14702. (void)strName;
  14703. (void)data;
  14704. (void)dataSz;
  14705. #else
  14706. WOLFSSL_MSG_EX("%s (%d):", strName,dataSz);
  14707. WOLFSSL_BUFFER(data,dataSz);
  14708. #endif
  14709. }
  14710. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID algo)
  14711. {
  14712. byte data[] = TEST_STRING;
  14713. word32 dataSz = TEST_STRING_SZ;
  14714. /* Arbitrarily random long key that we will truncate to the right size */
  14715. byte key[] = { 0x1E, 0xCC, 0x95, 0xCB, 0xD3, 0x74, 0x58, 0x4F,
  14716. 0x6F, 0x8A, 0x70, 0x26, 0xF7, 0x3C, 0x8D, 0xB6,
  14717. 0xDC, 0x32, 0x76, 0x20, 0xCF, 0x05, 0x4A, 0xCF,
  14718. 0x11, 0x86, 0xCD, 0x23, 0x5E, 0xC1, 0x6E, 0x2B };
  14719. byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[AES_BLOCK_SIZE];
  14720. word32 keySz, adSz = 256, authTagSz = sizeof(authTag);
  14721. wc_Aria aria;
  14722. int ret = 0;
  14723. WOLFSSL_ENTER("ariagcm_test");
  14724. XMEMSET((void *)&aria, 0, sizeof(aria));
  14725. ret = wc_AriaInitCrypt(&aria, algo);
  14726. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14727. ret = wc_AriaSetKey(&aria, key);
  14728. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14729. MC_GetObjectValue(aria.hSession, aria.hKey, key, &keySz);
  14730. printOutput("Key", key, keySz);
  14731. WC_RNG rng;
  14732. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14733. if (ret != 0)
  14734. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14735. ret = wc_AriaGcmSetIV(&aria, GCM_NONCE_MID_SZ, NULL, 0, &rng);
  14736. if (ret != 0)
  14737. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14738. wc_FreeRng(&rng);
  14739. printOutput("Plaintext", data, sizeof(data));
  14740. XMEMSET(cipher, 0, sizeof(cipher));
  14741. ret = wc_AriaEncrypt(&aria, cipher, data, dataSz,
  14742. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14743. authTag, authTagSz);
  14744. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14745. printOutput("Ciphertext", cipher, sizeof(cipher));
  14746. printOutput("AuthTag", authTag, sizeof(authTag));
  14747. XMEMSET(plain, 0, sizeof(plain));
  14748. ret = wc_AriaDecrypt(&aria, plain, cipher, dataSz,
  14749. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14750. authTag, authTagSz);
  14751. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14752. printOutput("Plaintext", plain, sizeof(plain));
  14753. if (XMEMCMP(plain, data, dataSz) != 0)
  14754. ERROR_OUT(WC_TEST_RET_ENC_NC,out);
  14755. out:
  14756. if (ret != 0) { wc_AriaFreeCrypt(&aria); }
  14757. else { ret = wc_AriaFreeCrypt(&aria); }
  14758. return ret;
  14759. }
  14760. #endif /* HAVE_ARIA */
  14761. #ifdef HAVE_CAMELLIA
  14762. enum {
  14763. CAM_ECB_ENC, CAM_ECB_DEC, CAM_CBC_ENC, CAM_CBC_DEC
  14764. };
  14765. typedef struct {
  14766. int type;
  14767. const byte* plaintext;
  14768. const byte* iv;
  14769. const byte* ciphertext;
  14770. const byte* key;
  14771. word32 keySz;
  14772. int errorCode;
  14773. } test_vector_t;
  14774. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void)
  14775. {
  14776. /* Camellia ECB Test Plaintext */
  14777. WOLFSSL_SMALL_STACK_STATIC const byte pte[] =
  14778. {
  14779. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14780. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14781. };
  14782. /* Camellia ECB Test Initialization Vector */
  14783. WOLFSSL_SMALL_STACK_STATIC const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  14784. /* Test 1: Camellia ECB 128-bit key */
  14785. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14786. {
  14787. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14788. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14789. };
  14790. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  14791. {
  14792. 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
  14793. 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
  14794. };
  14795. /* Test 2: Camellia ECB 192-bit key */
  14796. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14797. {
  14798. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14799. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14800. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  14801. };
  14802. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  14803. {
  14804. 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
  14805. 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9
  14806. };
  14807. /* Test 3: Camellia ECB 256-bit key */
  14808. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  14809. {
  14810. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14811. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14812. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14813. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  14814. };
  14815. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  14816. {
  14817. 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
  14818. 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09
  14819. };
  14820. /* Camellia CBC Test Plaintext */
  14821. WOLFSSL_SMALL_STACK_STATIC const byte ptc[] =
  14822. {
  14823. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  14824. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  14825. };
  14826. /* Camellia CBC Test Initialization Vector */
  14827. WOLFSSL_SMALL_STACK_STATIC const byte ivc[] =
  14828. {
  14829. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14830. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14831. };
  14832. /* Test 4: Camellia-CBC 128-bit key */
  14833. WOLFSSL_SMALL_STACK_STATIC const byte k4[] =
  14834. {
  14835. 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
  14836. 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
  14837. };
  14838. WOLFSSL_SMALL_STACK_STATIC const byte c4[] =
  14839. {
  14840. 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
  14841. 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB
  14842. };
  14843. /* Test 5: Camellia-CBC 192-bit key */
  14844. WOLFSSL_SMALL_STACK_STATIC const byte k5[] =
  14845. {
  14846. 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
  14847. 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
  14848. 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B
  14849. };
  14850. WOLFSSL_SMALL_STACK_STATIC const byte c5[] =
  14851. {
  14852. 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
  14853. 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93
  14854. };
  14855. /* Test 6: CBC 256-bit key */
  14856. WOLFSSL_SMALL_STACK_STATIC const byte k6[] =
  14857. {
  14858. 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
  14859. 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
  14860. 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
  14861. 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4
  14862. };
  14863. WOLFSSL_SMALL_STACK_STATIC const byte c6[] =
  14864. {
  14865. 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
  14866. 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
  14867. };
  14868. byte out[CAMELLIA_BLOCK_SIZE];
  14869. Camellia cam;
  14870. WOLFSSL_SMALL_STACK_STATIC const test_vector_t testVectors[] =
  14871. {
  14872. {CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114},
  14873. {CAM_ECB_ENC, pte, ive, c2, k2, sizeof(k2), -115},
  14874. {CAM_ECB_ENC, pte, ive, c3, k3, sizeof(k3), -116},
  14875. {CAM_ECB_DEC, pte, ive, c1, k1, sizeof(k1), -117},
  14876. {CAM_ECB_DEC, pte, ive, c2, k2, sizeof(k2), -118},
  14877. {CAM_ECB_DEC, pte, ive, c3, k3, sizeof(k3), -119},
  14878. {CAM_CBC_ENC, ptc, ivc, c4, k4, sizeof(k4), -120},
  14879. {CAM_CBC_ENC, ptc, ivc, c5, k5, sizeof(k5), -121},
  14880. {CAM_CBC_ENC, ptc, ivc, c6, k6, sizeof(k6), -122},
  14881. {CAM_CBC_DEC, ptc, ivc, c4, k4, sizeof(k4), -123},
  14882. {CAM_CBC_DEC, ptc, ivc, c5, k5, sizeof(k5), -124},
  14883. {CAM_CBC_DEC, ptc, ivc, c6, k6, sizeof(k6), -125}
  14884. };
  14885. int i, testsSz;
  14886. int ret;
  14887. WOLFSSL_ENTER("camellia_test");
  14888. testsSz = sizeof(testVectors)/sizeof(test_vector_t);
  14889. for (i = 0; i < testsSz; i++) {
  14890. if (wc_CamelliaSetKey(&cam, testVectors[i].key, testVectors[i].keySz,
  14891. testVectors[i].iv) != 0)
  14892. return testVectors[i].errorCode;
  14893. switch (testVectors[i].type) {
  14894. case CAM_ECB_ENC:
  14895. ret = wc_CamelliaEncryptDirect(&cam, out,
  14896. testVectors[i].plaintext);
  14897. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14898. CAMELLIA_BLOCK_SIZE))
  14899. return testVectors[i].errorCode;
  14900. break;
  14901. case CAM_ECB_DEC:
  14902. ret = wc_CamelliaDecryptDirect(&cam, out,
  14903. testVectors[i].ciphertext);
  14904. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14905. CAMELLIA_BLOCK_SIZE))
  14906. return testVectors[i].errorCode;
  14907. break;
  14908. case CAM_CBC_ENC:
  14909. ret = wc_CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext,
  14910. CAMELLIA_BLOCK_SIZE);
  14911. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14912. CAMELLIA_BLOCK_SIZE))
  14913. return testVectors[i].errorCode;
  14914. break;
  14915. case CAM_CBC_DEC:
  14916. ret = wc_CamelliaCbcDecrypt(&cam, out,
  14917. testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE);
  14918. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14919. CAMELLIA_BLOCK_SIZE))
  14920. return testVectors[i].errorCode;
  14921. break;
  14922. default:
  14923. break;
  14924. }
  14925. }
  14926. /* Setting the IV and checking it was actually set. */
  14927. ret = wc_CamelliaSetIV(&cam, ivc);
  14928. if (ret != 0)
  14929. return WC_TEST_RET_ENC_EC(ret);
  14930. if (XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE) != 0)
  14931. return WC_TEST_RET_ENC_NC;
  14932. /* Setting the IV to NULL should be same as all zeros IV */
  14933. ret = wc_CamelliaSetIV(&cam, NULL);
  14934. if (ret != 0)
  14935. return WC_TEST_RET_ENC_EC(ret);
  14936. if (XMEMCMP(cam.reg, ive, CAMELLIA_BLOCK_SIZE) != 0)
  14937. return WC_TEST_RET_ENC_NC;
  14938. /* First parameter should never be null */
  14939. if (wc_CamelliaSetIV(NULL, NULL) == 0)
  14940. return WC_TEST_RET_ENC_NC;
  14941. /* First parameter should never be null, check it fails */
  14942. if (wc_CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0)
  14943. return WC_TEST_RET_ENC_NC;
  14944. /* Key should have a size of 16, 24, or 32 */
  14945. if (wc_CamelliaSetKey(&cam, k1, 0, NULL) == 0)
  14946. return WC_TEST_RET_ENC_NC;
  14947. return 0;
  14948. }
  14949. #endif /* HAVE_CAMELLIA */
  14950. #ifdef WOLFSSL_SM4
  14951. #ifdef WOLFSSL_SM4_ECB
  14952. static int sm4_ecb_test(void)
  14953. {
  14954. /* draft-ribose-cfrg-sm4-10 A.2.1.1 */
  14955. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14956. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  14957. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  14958. };
  14959. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  14960. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  14961. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  14962. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  14963. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  14964. };
  14965. WOLFSSL_SMALL_STACK_STATIC const byte c1_ecb[] = {
  14966. 0x5E, 0xC8, 0x14, 0x3D, 0xE5, 0x09, 0xCF, 0xF7,
  14967. 0xB5, 0x17, 0x9F, 0x8F, 0x47, 0x4B, 0x86, 0x19,
  14968. 0x2F, 0x1D, 0x30, 0x5A, 0x7F, 0xB1, 0x7D, 0xF9,
  14969. 0x85, 0xF8, 0x1C, 0x84, 0x82, 0x19, 0x23, 0x04
  14970. };
  14971. wc_Sm4 sm4;
  14972. byte enc[SM4_BLOCK_SIZE * 4];
  14973. byte dec[SM4_BLOCK_SIZE * 4];
  14974. int ret;
  14975. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  14976. if (ret != 0)
  14977. return WC_TEST_RET_ENC_EC(ret);
  14978. /* Encrypt and decrypt with ECB. */
  14979. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  14980. if (ret != 0)
  14981. return WC_TEST_RET_ENC_EC(ret);
  14982. ret = wc_Sm4EcbEncrypt(&sm4, enc, p1, sizeof(p1));
  14983. if (ret != 0)
  14984. return WC_TEST_RET_ENC_EC(ret);
  14985. if (XMEMCMP(enc, c1_ecb, sizeof(c1_ecb)) != 0)
  14986. return WC_TEST_RET_ENC_NC;
  14987. ret = wc_Sm4EcbDecrypt(&sm4, dec, enc, sizeof(c1_ecb));
  14988. if (ret != 0)
  14989. return WC_TEST_RET_ENC_EC(ret);
  14990. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  14991. return WC_TEST_RET_ENC_NC;
  14992. wc_Sm4Free(&sm4);
  14993. return 0;
  14994. }
  14995. #endif
  14996. #ifdef WOLFSSL_SM4_CBC
  14997. static int sm4_cbc_test(void)
  14998. {
  14999. /* draft-ribose-cfrg-sm4-10 A.2.2.1 */
  15000. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15001. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15002. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15003. };
  15004. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15005. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15006. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15007. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15008. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15009. };
  15010. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15011. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15012. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15013. };
  15014. WOLFSSL_SMALL_STACK_STATIC const byte c1_cbc[] = {
  15015. 0x78, 0xEB, 0xB1, 0x1C, 0xC4, 0x0B, 0x0A, 0x48,
  15016. 0x31, 0x2A, 0xAE, 0xB2, 0x04, 0x02, 0x44, 0xCB,
  15017. 0x4C, 0xB7, 0x01, 0x69, 0x51, 0x90, 0x92, 0x26,
  15018. 0x97, 0x9B, 0x0D, 0x15, 0xDC, 0x6A, 0x8F, 0x6D
  15019. };
  15020. wc_Sm4 sm4;
  15021. byte enc[SM4_BLOCK_SIZE * 4];
  15022. byte dec[SM4_BLOCK_SIZE * 4];
  15023. int ret;
  15024. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15025. if (ret != 0)
  15026. return WC_TEST_RET_ENC_EC(ret);
  15027. /* Encrypt and decrypt with CBC. */
  15028. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15029. if (ret != 0)
  15030. return WC_TEST_RET_ENC_EC(ret);
  15031. ret = wc_Sm4SetIV(&sm4, i1);
  15032. if (ret != 0)
  15033. return WC_TEST_RET_ENC_EC(ret);
  15034. ret = wc_Sm4CbcEncrypt(&sm4, enc, p1, sizeof(p1));
  15035. if (ret != 0)
  15036. return WC_TEST_RET_ENC_EC(ret);
  15037. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15038. return WC_TEST_RET_ENC_NC;
  15039. ret = wc_Sm4SetIV(&sm4, i1);
  15040. if (ret != 0)
  15041. return WC_TEST_RET_ENC_EC(ret);
  15042. ret = wc_Sm4CbcDecrypt(&sm4, dec, enc, sizeof(c1_cbc));
  15043. if (ret != 0)
  15044. return WC_TEST_RET_ENC_EC(ret);
  15045. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15046. return WC_TEST_RET_ENC_NC;
  15047. /* Encrypt and decrypt in-place with CBC. */
  15048. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15049. if (ret != 0)
  15050. return WC_TEST_RET_ENC_EC(ret);
  15051. ret = wc_Sm4SetIV(&sm4, i1);
  15052. if (ret != 0)
  15053. return WC_TEST_RET_ENC_EC(ret);
  15054. XMEMCPY(enc, p1, sizeof(p1));
  15055. ret = wc_Sm4CbcEncrypt(&sm4, enc, enc, sizeof(p1));
  15056. if (ret != 0)
  15057. return WC_TEST_RET_ENC_EC(ret);
  15058. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15059. return WC_TEST_RET_ENC_NC;
  15060. ret = wc_Sm4SetIV(&sm4, i1);
  15061. if (ret != 0)
  15062. return WC_TEST_RET_ENC_EC(ret);
  15063. ret = wc_Sm4CbcDecrypt(&sm4, enc, enc, sizeof(c1_cbc));
  15064. if (ret != 0)
  15065. return WC_TEST_RET_ENC_EC(ret);
  15066. if (XMEMCMP(enc, p1, sizeof(p1)) != 0)
  15067. return WC_TEST_RET_ENC_NC;
  15068. wc_Sm4Free(&sm4);
  15069. return 0;
  15070. }
  15071. #endif
  15072. #ifdef WOLFSSL_SM4_CTR
  15073. static int sm4_ctr_test(void)
  15074. {
  15075. /* draft-ribose-cfrg-sm4-10 A.2.5.1 */
  15076. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15077. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15078. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15079. };
  15080. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15081. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15082. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15083. };
  15084. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15085. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15086. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15087. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15088. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15089. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15090. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15091. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15092. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB
  15093. };
  15094. WOLFSSL_SMALL_STACK_STATIC const byte c2_ctr[] = {
  15095. 0xAC, 0x32, 0x36, 0xCB, 0x97, 0x0C, 0xC2, 0x07,
  15096. 0x91, 0x36, 0x4C, 0x39, 0x5A, 0x13, 0x42, 0xD1,
  15097. 0xA3, 0xCB, 0xC1, 0x87, 0x8C, 0x6F, 0x30, 0xCD,
  15098. 0x07, 0x4C, 0xCE, 0x38, 0x5C, 0xDD, 0x70, 0xC7,
  15099. 0xF2, 0x34, 0xBC, 0x0E, 0x24, 0xC1, 0x19, 0x80,
  15100. 0xFD, 0x12, 0x86, 0x31, 0x0C, 0xE3, 0x7B, 0x92,
  15101. 0x6E, 0x02, 0xFC, 0xD0, 0xFA, 0xA0, 0xBA, 0xF3,
  15102. 0x8B, 0x29, 0x33, 0x85, 0x1D, 0x82, 0x45, 0x14
  15103. };
  15104. wc_Sm4 sm4;
  15105. byte enc[SM4_BLOCK_SIZE * 4];
  15106. byte dec[SM4_BLOCK_SIZE * 4];
  15107. int chunk;
  15108. int i;
  15109. int ret;
  15110. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15111. if (ret != 0)
  15112. return WC_TEST_RET_ENC_EC(ret);
  15113. /* Encrypt and decrypt using encrypt with CTR. */
  15114. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15115. if (ret != 0)
  15116. return WC_TEST_RET_ENC_EC(ret);
  15117. ret = wc_Sm4SetIV(&sm4, i1);
  15118. if (ret != 0)
  15119. return WC_TEST_RET_ENC_EC(ret);
  15120. ret = wc_Sm4CtrEncrypt(&sm4, enc, p2, sizeof(p2));
  15121. if (ret != 0)
  15122. return WC_TEST_RET_ENC_EC(ret);
  15123. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15124. return WC_TEST_RET_ENC_NC;
  15125. ret = wc_Sm4SetIV(&sm4, i1);
  15126. if (ret != 0)
  15127. return WC_TEST_RET_ENC_EC(ret);
  15128. ret = wc_Sm4CtrEncrypt(&sm4, dec, enc, sizeof(c2_ctr));
  15129. if (ret != 0)
  15130. return WC_TEST_RET_ENC_EC(ret);
  15131. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15132. return WC_TEST_RET_ENC_NC;
  15133. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15134. ret = wc_Sm4SetIV(&sm4, i1);
  15135. if (ret != 0)
  15136. return WC_TEST_RET_ENC_I(chunk);
  15137. XMEMSET(enc, 0, sizeof(enc));
  15138. for (i = 0; i + chunk <= (int)sizeof(p2); i += chunk) {
  15139. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, chunk);
  15140. if (ret != 0)
  15141. return WC_TEST_RET_ENC_I(i);
  15142. }
  15143. if (i < (int)sizeof(p2)) {
  15144. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, sizeof(p2) - i);
  15145. if (ret != 0)
  15146. return WC_TEST_RET_ENC_I(chunk);
  15147. }
  15148. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15149. return WC_TEST_RET_ENC_I(chunk);
  15150. }
  15151. wc_Sm4Free(&sm4);
  15152. return 0;
  15153. }
  15154. #endif
  15155. #ifdef WOLFSSL_SM4_GCM
  15156. static int sm4_gcm_test(void)
  15157. {
  15158. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15159. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15160. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15161. };
  15162. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15163. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15164. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15165. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15166. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15167. };
  15168. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15169. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15170. 0x08, 0x09, 0x0A, 0x0B
  15171. };
  15172. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15173. 0xFF, 0xEE, 0xDD
  15174. };
  15175. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15176. 0x83, 0xb2, 0x91, 0xcf, 0x22, 0xc9, 0x5f, 0x89,
  15177. 0xde, 0x3d, 0x52, 0x8d, 0xd7, 0x13, 0x50, 0x89
  15178. };
  15179. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15180. 0xff, 0x8b, 0xb2, 0x3b, 0x0a, 0x0a, 0x12, 0xa4,
  15181. 0xa8, 0x4c, 0x4f, 0x67, 0x06, 0x81, 0xbb, 0x88,
  15182. 0x66, 0x17, 0xc7, 0x43, 0xbf, 0xae, 0x41, 0x40,
  15183. 0xec, 0x1e, 0x03, 0x85, 0x2b, 0x56, 0xa8, 0xc0
  15184. };
  15185. /* RFC8998 A.1. */
  15186. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15187. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15188. 0x00, 0x00, 0xAB, 0xCD
  15189. };
  15190. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15191. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15192. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15193. };
  15194. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15195. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15196. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15197. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15198. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15199. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15200. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15201. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15202. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15203. };
  15204. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15205. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15206. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15207. 0xAB, 0xAD, 0xDA, 0xD2
  15208. };
  15209. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15210. 0x17, 0xF3, 0x99, 0xF0, 0x8C, 0x67, 0xD5, 0xEE,
  15211. 0x19, 0xD0, 0xDC, 0x99, 0x69, 0xC4, 0xBB, 0x7D,
  15212. 0x5F, 0xD4, 0x6F, 0xD3, 0x75, 0x64, 0x89, 0x06,
  15213. 0x91, 0x57, 0xB2, 0x82, 0xBB, 0x20, 0x07, 0x35,
  15214. 0xD8, 0x27, 0x10, 0xCA, 0x5C, 0x22, 0xF0, 0xCC,
  15215. 0xFA, 0x7C, 0xBF, 0x93, 0xD4, 0x96, 0xAC, 0x15,
  15216. 0xA5, 0x68, 0x34, 0xCB, 0xCF, 0x98, 0xC3, 0x97,
  15217. 0xB4, 0x02, 0x4A, 0x26, 0x91, 0x23, 0x3B, 0x8D
  15218. };
  15219. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15220. 0x83, 0xDE, 0x35, 0x41, 0xE4, 0xC2, 0xB5, 0x81,
  15221. 0x77, 0xE0, 0x65, 0xA9, 0xBF, 0x7B, 0x62, 0xEC
  15222. };
  15223. wc_Sm4 sm4;
  15224. byte enc[SM4_BLOCK_SIZE * 4];
  15225. byte dec[SM4_BLOCK_SIZE * 4];
  15226. byte tag[SM4_BLOCK_SIZE];
  15227. int ret;
  15228. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15229. if (ret != 0)
  15230. return WC_TEST_RET_ENC_EC(ret);
  15231. /* Encrypt and decrypt using encrypt with GCM. */
  15232. ret = wc_Sm4GcmSetKey(&sm4, k1, sizeof(k1));
  15233. if (ret != 0)
  15234. return WC_TEST_RET_ENC_EC(ret);
  15235. ret = wc_Sm4GcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15236. sizeof(tag), a1, sizeof(a1));
  15237. if (ret != 0)
  15238. return WC_TEST_RET_ENC_EC(ret);
  15239. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15240. return WC_TEST_RET_ENC_NC;
  15241. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15242. return WC_TEST_RET_ENC_NC;
  15243. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15244. sizeof(tag), a1, sizeof(a1));
  15245. if (ret != 0)
  15246. return WC_TEST_RET_ENC_EC(ret);
  15247. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15248. return WC_TEST_RET_ENC_NC;
  15249. /* RFC8998 test vector. */
  15250. ret = wc_Sm4GcmSetKey(&sm4, k2, sizeof(k2));
  15251. if (ret != 0)
  15252. return WC_TEST_RET_ENC_EC(ret);
  15253. ret = wc_Sm4GcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15254. sizeof(tag), a2, sizeof(a2));
  15255. if (ret != 0)
  15256. return WC_TEST_RET_ENC_EC(ret);
  15257. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15258. return WC_TEST_RET_ENC_NC;
  15259. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15260. return WC_TEST_RET_ENC_NC;
  15261. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15262. sizeof(tag), a2, sizeof(a2));
  15263. if (ret != 0)
  15264. return WC_TEST_RET_ENC_EC(ret);
  15265. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15266. return WC_TEST_RET_ENC_NC;
  15267. wc_Sm4Free(&sm4);
  15268. return 0;
  15269. }
  15270. #endif
  15271. #ifdef WOLFSSL_SM4_CCM
  15272. static int sm4_ccm_test(void)
  15273. {
  15274. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15275. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15276. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15277. };
  15278. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15279. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15280. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15281. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15282. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15283. };
  15284. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15285. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15286. 0x08, 0x09, 0x0A, 0x0B
  15287. };
  15288. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15289. 0xFF, 0xEE, 0xDD
  15290. };
  15291. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15292. 0x9a, 0x98, 0x04, 0xb6, 0x0f, 0x19, 0x4a, 0x46,
  15293. 0xba, 0xed, 0xe6, 0x89, 0x69, 0x34, 0xad, 0x61
  15294. };
  15295. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15296. 0xbd, 0xc0, 0x72, 0x60, 0xda, 0x2d, 0x11, 0xdc,
  15297. 0x66, 0x33, 0xcc, 0xec, 0xb2, 0xf4, 0x53, 0x59,
  15298. 0x9e, 0xb1, 0xb3, 0x6b, 0x1f, 0x1c, 0xfb, 0x29,
  15299. 0xf5, 0x37, 0xfc, 0x00, 0xf2, 0x4e, 0x70, 0x6f
  15300. };
  15301. /* RFC8998 A.1. */
  15302. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15303. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15304. 0x00, 0x00, 0xAB, 0xCD
  15305. };
  15306. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15307. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15308. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15309. };
  15310. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15311. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15312. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15313. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15314. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15315. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15316. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15317. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15318. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15319. };
  15320. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15321. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15322. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15323. 0xAB, 0xAD, 0xDA, 0xD2
  15324. };
  15325. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15326. 0x48, 0xAF, 0x93, 0x50, 0x1F, 0xA6, 0x2A, 0xDB,
  15327. 0xCD, 0x41, 0x4C, 0xCE, 0x60, 0x34, 0xD8, 0x95,
  15328. 0xDD, 0xA1, 0xBF, 0x8F, 0x13, 0x2F, 0x04, 0x20,
  15329. 0x98, 0x66, 0x15, 0x72, 0xE7, 0x48, 0x30, 0x94,
  15330. 0xFD, 0x12, 0xE5, 0x18, 0xCE, 0x06, 0x2C, 0x98,
  15331. 0xAC, 0xEE, 0x28, 0xD9, 0x5D, 0xF4, 0x41, 0x6B,
  15332. 0xED, 0x31, 0xA2, 0xF0, 0x44, 0x76, 0xC1, 0x8B,
  15333. 0xB4, 0x0C, 0x84, 0xA7, 0x4B, 0x97, 0xDC, 0x5B
  15334. };
  15335. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15336. 0x16, 0x84, 0x2D, 0x4F, 0xA1, 0x86, 0xF5, 0x6A,
  15337. 0xB3, 0x32, 0x56, 0x97, 0x1F, 0xA1, 0x10, 0xF4
  15338. };
  15339. wc_Sm4 sm4;
  15340. byte enc[SM4_BLOCK_SIZE * 4];
  15341. byte dec[SM4_BLOCK_SIZE * 4];
  15342. byte tag[SM4_BLOCK_SIZE];
  15343. int ret;
  15344. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15345. if (ret != 0)
  15346. return WC_TEST_RET_ENC_EC(ret);
  15347. /* Encrypt and decrypt using encrypt with CCM. */
  15348. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15349. if (ret != 0)
  15350. return WC_TEST_RET_ENC_EC(ret);
  15351. ret = wc_Sm4CcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15352. sizeof(tag), a1, sizeof(a1));
  15353. if (ret != 0)
  15354. return WC_TEST_RET_ENC_EC(ret);
  15355. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15356. return WC_TEST_RET_ENC_NC;
  15357. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15358. return WC_TEST_RET_ENC_NC;
  15359. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15360. sizeof(tag), a1, sizeof(a1));
  15361. if (ret != 0)
  15362. return WC_TEST_RET_ENC_EC(ret);
  15363. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15364. return WC_TEST_RET_ENC_NC;
  15365. /* RFC8998 test vector. */
  15366. ret = wc_Sm4SetKey(&sm4, k2, sizeof(k2));
  15367. if (ret != 0)
  15368. return WC_TEST_RET_ENC_EC(ret);
  15369. ret = wc_Sm4CcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15370. sizeof(tag), a2, sizeof(a2));
  15371. if (ret != 0)
  15372. return WC_TEST_RET_ENC_EC(ret);
  15373. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15374. return WC_TEST_RET_ENC_NC;
  15375. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15376. return WC_TEST_RET_ENC_NC;
  15377. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15378. sizeof(tag), a2, sizeof(a2));
  15379. if (ret != 0)
  15380. return WC_TEST_RET_ENC_EC(ret);
  15381. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15382. return WC_TEST_RET_ENC_NC;
  15383. wc_Sm4Free(&sm4);
  15384. return 0;
  15385. }
  15386. #endif
  15387. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void)
  15388. {
  15389. wc_test_ret_t ret;
  15390. WOLFSSL_ENTER("sm4_test");
  15391. #ifdef WOLFSSL_SM4_ECB
  15392. ret = sm4_ecb_test();
  15393. if (ret != 0)
  15394. return ret;
  15395. #endif
  15396. #ifdef WOLFSSL_SM4_CBC
  15397. ret = sm4_cbc_test();
  15398. if (ret != 0)
  15399. return ret;
  15400. #endif
  15401. #ifdef WOLFSSL_SM4_CTR
  15402. ret = sm4_ctr_test();
  15403. if (ret != 0)
  15404. return ret;
  15405. #endif
  15406. #ifdef WOLFSSL_SM4_GCM
  15407. ret = sm4_gcm_test();
  15408. if (ret != 0)
  15409. return ret;
  15410. #endif
  15411. #ifdef WOLFSSL_SM4_CCM
  15412. ret = sm4_ccm_test();
  15413. if (ret != 0)
  15414. return ret;
  15415. #endif
  15416. return 0;
  15417. }
  15418. #endif
  15419. #ifdef HAVE_XCHACHA
  15420. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void) {
  15421. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15422. 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, /* The dhole (prono */
  15423. 0x75, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x22, 0x64, 0x6f, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x69, 0x73, /* unced "dole") is */
  15424. 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x74, /* also known as t */
  15425. 0x68, 0x65, 0x20, 0x41, 0x73, 0x69, 0x61, 0x74, 0x69, 0x63, 0x20, 0x77, 0x69, 0x6c, 0x64, 0x20, /* he Asiatic wild */
  15426. 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x72, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x61, 0x6e, /* dog, red dog, an */
  15427. 0x64, 0x20, 0x77, 0x68, 0x69, 0x73, 0x74, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x64, 0x6f, 0x67, 0x2e, /* d whistling dog. */
  15428. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, /* It is about the */
  15429. 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x47, 0x65, 0x72, 0x6d, 0x61, /* size of a Germa */
  15430. 0x6e, 0x20, 0x73, 0x68, 0x65, 0x70, 0x68, 0x65, 0x72, 0x64, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6c, /* n shepherd but l */
  15431. 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x61, /* ooks more like a */
  15432. 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x6c, 0x65, 0x67, 0x67, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x78, /* long-legged fox */
  15433. 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x79, 0x20, 0x65, 0x6c, /* . This highly el */
  15434. 0x75, 0x73, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x65, /* usive and skille */
  15435. 0x64, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6c, 0x61, 0x73, /* d jumper is clas */
  15436. 0x73, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x77, 0x6f, 0x6c, 0x76, /* sified with wolv */
  15437. 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6f, 0x79, 0x6f, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x6a, 0x61, 0x63, /* es, coyotes, jac */
  15438. 0x6b, 0x61, 0x6c, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x78, 0x65, 0x73, 0x20, /* kals, and foxes */
  15439. 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x61, 0x78, 0x6f, 0x6e, 0x6f, 0x6d, 0x69, 0x63, /* in the taxonomic */
  15440. 0x20, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x20, 0x43, 0x61, 0x6e, 0x69, 0x64, 0x61, 0x65, 0x2e /* family Canidae. */
  15441. };
  15442. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15443. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15444. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15445. };
  15446. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15447. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15448. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58 }; /* PQRSTUVW */
  15449. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15450. 0x45, 0x59, 0xab, 0xba, 0x4e, 0x48, 0xc1, 0x61, 0x02, 0xe8, 0xbb, 0x2c, 0x05, 0xe6, 0x94, 0x7f,
  15451. 0x50, 0xa7, 0x86, 0xde, 0x16, 0x2f, 0x9b, 0x0b, 0x7e, 0x59, 0x2a, 0x9b, 0x53, 0xd0, 0xd4, 0xe9,
  15452. 0x8d, 0x8d, 0x64, 0x10, 0xd5, 0x40, 0xa1, 0xa6, 0x37, 0x5b, 0x26, 0xd8, 0x0d, 0xac, 0xe4, 0xfa,
  15453. 0xb5, 0x23, 0x84, 0xc7, 0x31, 0xac, 0xbf, 0x16, 0xa5, 0x92, 0x3c, 0x0c, 0x48, 0xd3, 0x57, 0x5d,
  15454. 0x4d, 0x0d, 0x2c, 0x67, 0x3b, 0x66, 0x6f, 0xaa, 0x73, 0x10, 0x61, 0x27, 0x77, 0x01, 0x09, 0x3a,
  15455. 0x6b, 0xf7, 0xa1, 0x58, 0xa8, 0x86, 0x42, 0x92, 0xa4, 0x1c, 0x48, 0xe3, 0xa9, 0xb4, 0xc0, 0xda,
  15456. 0xec, 0xe0, 0xf8, 0xd9, 0x8d, 0x0d, 0x7e, 0x05, 0xb3, 0x7a, 0x30, 0x7b, 0xbb, 0x66, 0x33, 0x31,
  15457. 0x64, 0xec, 0x9e, 0x1b, 0x24, 0xea, 0x0d, 0x6c, 0x3f, 0xfd, 0xdc, 0xec, 0x4f, 0x68, 0xe7, 0x44,
  15458. 0x30, 0x56, 0x19, 0x3a, 0x03, 0xc8, 0x10, 0xe1, 0x13, 0x44, 0xca, 0x06, 0xd8, 0xed, 0x8a, 0x2b,
  15459. 0xfb, 0x1e, 0x8d, 0x48, 0xcf, 0xa6, 0xbc, 0x0e, 0xb4, 0xe2, 0x46, 0x4b, 0x74, 0x81, 0x42, 0x40,
  15460. 0x7c, 0x9f, 0x43, 0x1a, 0xee, 0x76, 0x99, 0x60, 0xe1, 0x5b, 0xa8, 0xb9, 0x68, 0x90, 0x46, 0x6e,
  15461. 0xf2, 0x45, 0x75, 0x99, 0x85, 0x23, 0x85, 0xc6, 0x61, 0xf7, 0x52, 0xce, 0x20, 0xf9, 0xda, 0x0c,
  15462. 0x09, 0xab, 0x6b, 0x19, 0xdf, 0x74, 0xe7, 0x6a, 0x95, 0x96, 0x74, 0x46, 0xf8, 0xd0, 0xfd, 0x41,
  15463. 0x5e, 0x7b, 0xee, 0x2a, 0x12, 0xa1, 0x14, 0xc2, 0x0e, 0xb5, 0x29, 0x2a, 0xe7, 0xa3, 0x49, 0xae,
  15464. 0x57, 0x78, 0x20, 0xd5, 0x52, 0x0a, 0x1f, 0x3f, 0xb6, 0x2a, 0x17, 0xce, 0x6a, 0x7e, 0x68, 0xfa,
  15465. 0x7c, 0x79, 0x11, 0x1d, 0x88, 0x60, 0x92, 0x0b, 0xc0, 0x48, 0xef, 0x43, 0xfe, 0x84, 0x48, 0x6c,
  15466. 0xcb, 0x87, 0xc2, 0x5f, 0x0a, 0xe0, 0x45, 0xf0, 0xcc, 0xe1, 0xe7, 0x98, 0x9a, 0x9a, 0xa2, 0x20,
  15467. 0xa2, 0x8b, 0xdd, 0x48, 0x27, 0xe7, 0x51, 0xa2, 0x4a, 0x6d, 0x5c, 0x62, 0xd7, 0x90, 0xa6, 0x63,
  15468. 0x93, 0xb9, 0x31, 0x11, 0xc1, 0xa5, 0x5d, 0xd7, 0x42, 0x1a, 0x10, 0x18, 0x49, 0x74, 0xc7, 0xc5
  15469. };
  15470. wc_test_ret_t ret;
  15471. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15472. struct ChaCha *chacha = (struct ChaCha *)XMALLOC(sizeof *chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15473. byte *buf1 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15474. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15475. WOLFSSL_ENTER("XChaCha_test");
  15476. if ((chacha == NULL) || (buf1 == NULL) || (buf2 == NULL))
  15477. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15478. #else
  15479. struct ChaCha chacha[1];
  15480. byte buf1[sizeof Plaintext];
  15481. byte buf2[sizeof Plaintext];
  15482. WOLFSSL_ENTER("XChaCha_test");
  15483. #endif
  15484. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15485. if (ret < 0)
  15486. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15487. ret = wc_Chacha_Process(chacha, buf1, Plaintext, sizeof Plaintext);
  15488. if (ret < 0)
  15489. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15490. if (XMEMCMP(buf1, Ciphertext, sizeof Plaintext))
  15491. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15492. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15493. if (ret < 0)
  15494. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15495. ret = wc_Chacha_Process(chacha, buf2, buf1, sizeof Plaintext);
  15496. if (ret < 0)
  15497. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15498. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15499. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15500. out:
  15501. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15502. XFREE(chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15503. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15504. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15505. #endif
  15506. return ret;
  15507. }
  15508. #endif /* HAVE_XCHACHA */
  15509. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  15510. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void) {
  15511. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15512. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, /* Ladies and Gentl */
  15513. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, /* emen of the clas */
  15514. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, /* s of '99: If I c */
  15515. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, /* ould offer you o */
  15516. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, /* nly one tip for */
  15517. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, /* the future, suns */
  15518. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, /* creen would be i */
  15519. 0x74, 0x2e }; /* t. */
  15520. WOLFSSL_SMALL_STACK_STATIC const byte AAD[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; /* PQRS........ */
  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, 0x57 }; /* PQRSTUVW */
  15528. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15529. 0xbd, 0x6d, 0x17, 0x9d, 0x3e, 0x83, 0xd4, 0x3b, 0x95, 0x76, 0x57, 0x94, 0x93, 0xc0, 0xe9, 0x39,
  15530. 0x57, 0x2a, 0x17, 0x00, 0x25, 0x2b, 0xfa, 0xcc, 0xbe, 0xd2, 0x90, 0x2c, 0x21, 0x39, 0x6c, 0xbb,
  15531. 0x73, 0x1c, 0x7f, 0x1b, 0x0b, 0x4a, 0xa6, 0x44, 0x0b, 0xf3, 0xa8, 0x2f, 0x4e, 0xda, 0x7e, 0x39,
  15532. 0xae, 0x64, 0xc6, 0x70, 0x8c, 0x54, 0xc2, 0x16, 0xcb, 0x96, 0xb7, 0x2e, 0x12, 0x13, 0xb4, 0x52,
  15533. 0x2f, 0x8c, 0x9b, 0xa4, 0x0d, 0xb5, 0xd9, 0x45, 0xb1, 0x1b, 0x69, 0xb9, 0x82, 0xc1, 0xbb, 0x9e,
  15534. 0x3f, 0x3f, 0xac, 0x2b, 0xc3, 0x69, 0x48, 0x8f, 0x76, 0xb2, 0x38, 0x35, 0x65, 0xd3, 0xff, 0xf9,
  15535. 0x21, 0xf9, 0x66, 0x4c, 0x97, 0x63, 0x7d, 0xa9, 0x76, 0x88, 0x12, 0xf6, 0x15, 0xc6, 0x8b, 0x13,
  15536. 0xb5, 0x2e };
  15537. WOLFSSL_SMALL_STACK_STATIC const byte Tag[] = {
  15538. 0xc0, 0x87, 0x59, 0x24, 0xc1, 0xc7, 0x98, 0x79, 0x47, 0xde, 0xaf, 0xd8, 0x78, 0x0a, 0xcf, 0x49
  15539. };
  15540. wc_test_ret_t ret;
  15541. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15542. byte *buf1 = (byte *)XMALLOC(sizeof Ciphertext + sizeof Tag, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15543. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15544. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15545. if ((buf1 == NULL) || (buf2 == NULL))
  15546. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15547. #else
  15548. byte buf1[sizeof Ciphertext + sizeof Tag];
  15549. byte buf2[sizeof Plaintext];
  15550. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15551. #endif
  15552. ret = wc_XChaCha20Poly1305_Encrypt(buf1, sizeof Ciphertext + sizeof Tag,
  15553. Plaintext, sizeof Plaintext,
  15554. AAD, sizeof AAD,
  15555. IV, sizeof IV,
  15556. Key, sizeof Key);
  15557. if (ret < 0)
  15558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15559. if (XMEMCMP(buf1, Ciphertext, sizeof Ciphertext))
  15560. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15561. if (XMEMCMP(buf1 + sizeof Ciphertext, Tag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE))
  15562. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15563. ret = wc_XChaCha20Poly1305_Decrypt(buf2, sizeof Plaintext,
  15564. buf1, sizeof Ciphertext + sizeof Tag,
  15565. AAD, sizeof AAD,
  15566. IV, sizeof IV,
  15567. Key, sizeof Key);
  15568. if (ret < 0)
  15569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15570. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15571. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15572. out:
  15573. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15574. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15575. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15576. #endif
  15577. return ret;
  15578. }
  15579. #endif /* defined(HAVE_XCHACHA) && defined(HAVE_POLY1305) */
  15580. #ifndef WC_NO_RNG
  15581. static wc_test_ret_t _rng_test(WC_RNG* rng)
  15582. {
  15583. byte block[32];
  15584. wc_test_ret_t ret;
  15585. int i;
  15586. XMEMSET(block, 0, sizeof(block));
  15587. ret = wc_RNG_GenerateBlock(rng, block, sizeof(block));
  15588. if (ret != 0) {
  15589. return WC_TEST_RET_ENC_EC(ret);
  15590. }
  15591. /* Check for 0's */
  15592. for (i=0; i<(int)sizeof(block); i++) {
  15593. if (block[i] == 0) {
  15594. ret++;
  15595. }
  15596. }
  15597. /* All zeros count check */
  15598. if (ret >= (int)sizeof(block)) {
  15599. return WC_TEST_RET_ENC_NC;
  15600. }
  15601. ret = wc_RNG_GenerateByte(rng, block);
  15602. if (ret != 0) {
  15603. return WC_TEST_RET_ENC_EC(ret);
  15604. }
  15605. /* Parameter validation testing. */
  15606. ret = wc_RNG_GenerateBlock(NULL, block, sizeof(block));
  15607. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15608. return WC_TEST_RET_ENC_EC(ret);
  15609. }
  15610. ret = wc_RNG_GenerateBlock(rng, NULL, sizeof(block));
  15611. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15612. return WC_TEST_RET_ENC_EC(ret);
  15613. }
  15614. ret = wc_RNG_GenerateByte(NULL, block);
  15615. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15616. return WC_TEST_RET_ENC_EC(ret);
  15617. }
  15618. ret = wc_RNG_GenerateByte(rng, NULL);
  15619. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15620. return WC_TEST_RET_ENC_EC(ret);
  15621. }
  15622. return 0;
  15623. }
  15624. static wc_test_ret_t random_rng_test(void)
  15625. {
  15626. WC_RNG localRng;
  15627. WC_RNG* rng;
  15628. wc_test_ret_t ret;
  15629. rng = &localRng;
  15630. /* Test stack based RNG. */
  15631. #ifndef HAVE_FIPS
  15632. ret = wc_InitRng_ex(rng, HEAP_HINT, devId);
  15633. #else
  15634. ret = wc_InitRng(rng);
  15635. #endif
  15636. if (ret != 0)
  15637. return WC_TEST_RET_ENC_EC(ret);
  15638. ret = _rng_test(rng);
  15639. /* Make sure and free RNG */
  15640. wc_FreeRng(rng);
  15641. if (ret != 0)
  15642. return ret;
  15643. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
  15644. {
  15645. byte nonce[8] = { 0 };
  15646. /* Test dynamic RNG */
  15647. rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
  15648. if (rng == NULL)
  15649. return WC_TEST_RET_ENC_ERRNO;
  15650. ret = _rng_test(rng);
  15651. wc_rng_free(rng);
  15652. rng = NULL;
  15653. if (ret != 0)
  15654. return ret;
  15655. /* Test dynamic RNG using extended API */
  15656. ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
  15657. HEAP_HINT, devId);
  15658. if (ret != 0)
  15659. return WC_TEST_RET_ENC_EC(ret);
  15660. ret = _rng_test(rng);
  15661. wc_rng_free(rng);
  15662. if (ret != 0)
  15663. return ret;
  15664. }
  15665. #endif
  15666. return ret;
  15667. }
  15668. #if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  15669. #ifdef WC_RNG_SEED_CB
  15670. static int seed_cb(OS_Seed* os, byte* output, word32 sz)
  15671. {
  15672. word32 i;
  15673. (void)os;
  15674. /* Known answer test. Set the seed to the same value every time. */
  15675. for (i = 0; i < sz; i++)
  15676. output[i] = (byte)i;
  15677. return 0;
  15678. }
  15679. static wc_test_ret_t rng_seed_test(void)
  15680. {
  15681. #ifndef HAVE_FIPS
  15682. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15683. {
  15684. 0x83, 0x46, 0x65, 0x2f, 0x5c, 0x44, 0x16, 0x5f,
  15685. 0xb3, 0x89, 0x26, 0xde, 0x0b, 0x6b, 0xa2, 0x06,
  15686. 0x7e, 0xa7, 0x9a, 0x55, 0x22, 0x01, 0xb0, 0x22,
  15687. 0xf4, 0x7e, 0xa2, 0x66, 0xc4, 0x08, 0x6f, 0xba
  15688. };
  15689. #else
  15690. /* FIPS uses a longer seed, so different check value. */
  15691. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15692. {
  15693. 0xaf, 0x31, 0xcc, 0xef, 0xa9, 0x29, 0x4c, 0x24,
  15694. 0xbd, 0xa5, 0xa3, 0x52, 0x69, 0xf3, 0xb9, 0xb2,
  15695. 0x1e, 0xd4, 0x52, 0x3b, 0x9a, 0x96, 0x06, 0x20,
  15696. 0xc0, 0x5f, 0x44, 0x06, 0x1f, 0x80, 0xdf, 0xe0
  15697. };
  15698. #endif
  15699. byte output[WC_SHA256_DIGEST_SIZE];
  15700. WC_RNG rng;
  15701. wc_test_ret_t ret;
  15702. ret = wc_SetSeed_Cb(seed_cb);
  15703. if (ret != 0) {
  15704. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15705. }
  15706. ret = wc_InitRng(&rng);
  15707. if (ret != 0) {
  15708. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15709. }
  15710. ret = wc_RNG_GenerateBlock(&rng, output, sizeof(output));
  15711. if (ret != 0) {
  15712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15713. }
  15714. ret = XMEMCMP(output, check, sizeof(output));
  15715. if (ret != 0) {
  15716. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15717. }
  15718. ret = wc_FreeRng(&rng);
  15719. if (ret != 0) {
  15720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15721. }
  15722. ret = wc_SetSeed_Cb(wc_GenerateSeed);
  15723. if (ret != 0) {
  15724. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15725. }
  15726. out:
  15727. return ret;
  15728. }
  15729. #endif
  15730. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15731. {
  15732. WOLFSSL_SMALL_STACK_STATIC const byte test1Entropy[] =
  15733. {
  15734. 0xa6, 0x5a, 0xd0, 0xf3, 0x45, 0xdb, 0x4e, 0x0e, 0xff, 0xe8, 0x75, 0xc3,
  15735. 0xa2, 0xe7, 0x1f, 0x42, 0xc7, 0x12, 0x9d, 0x62, 0x0f, 0xf5, 0xc1, 0x19,
  15736. 0xa9, 0xef, 0x55, 0xf0, 0x51, 0x85, 0xe0, 0xfb, 0x85, 0x81, 0xf9, 0x31,
  15737. 0x75, 0x17, 0x27, 0x6e, 0x06, 0xe9, 0x60, 0x7d, 0xdb, 0xcb, 0xcc, 0x2e
  15738. };
  15739. WOLFSSL_SMALL_STACK_STATIC const byte test1Output[] =
  15740. {
  15741. 0xd3, 0xe1, 0x60, 0xc3, 0x5b, 0x99, 0xf3, 0x40, 0xb2, 0x62, 0x82, 0x64,
  15742. 0xd1, 0x75, 0x10, 0x60, 0xe0, 0x04, 0x5d, 0xa3, 0x83, 0xff, 0x57, 0xa5,
  15743. 0x7d, 0x73, 0xa6, 0x73, 0xd2, 0xb8, 0xd8, 0x0d, 0xaa, 0xf6, 0xa6, 0xc3,
  15744. 0x5a, 0x91, 0xbb, 0x45, 0x79, 0xd7, 0x3f, 0xd0, 0xc8, 0xfe, 0xd1, 0x11,
  15745. 0xb0, 0x39, 0x13, 0x06, 0x82, 0x8a, 0xdf, 0xed, 0x52, 0x8f, 0x01, 0x81,
  15746. 0x21, 0xb3, 0xfe, 0xbd, 0xc3, 0x43, 0xe7, 0x97, 0xb8, 0x7d, 0xbb, 0x63,
  15747. 0xdb, 0x13, 0x33, 0xde, 0xd9, 0xd1, 0xec, 0xe1, 0x77, 0xcf, 0xa6, 0xb7,
  15748. 0x1f, 0xe8, 0xab, 0x1d, 0xa4, 0x66, 0x24, 0xed, 0x64, 0x15, 0xe5, 0x1c,
  15749. 0xcd, 0xe2, 0xc7, 0xca, 0x86, 0xe2, 0x83, 0x99, 0x0e, 0xea, 0xeb, 0x91,
  15750. 0x12, 0x04, 0x15, 0x52, 0x8b, 0x22, 0x95, 0x91, 0x02, 0x81, 0xb0, 0x2d,
  15751. 0xd4, 0x31, 0xf4, 0xc9, 0xf7, 0x04, 0x27, 0xdf
  15752. };
  15753. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyA[] =
  15754. {
  15755. 0x63, 0x36, 0x33, 0x77, 0xe4, 0x1e, 0x86, 0x46, 0x8d, 0xeb, 0x0a, 0xb4,
  15756. 0xa8, 0xed, 0x68, 0x3f, 0x6a, 0x13, 0x4e, 0x47, 0xe0, 0x14, 0xc7, 0x00,
  15757. 0x45, 0x4e, 0x81, 0xe9, 0x53, 0x58, 0xa5, 0x69, 0x80, 0x8a, 0xa3, 0x8f,
  15758. 0x2a, 0x72, 0xa6, 0x23, 0x59, 0x91, 0x5a, 0x9f, 0x8a, 0x04, 0xca, 0x68
  15759. };
  15760. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyB[] =
  15761. {
  15762. 0xe6, 0x2b, 0x8a, 0x8e, 0xe8, 0xf1, 0x41, 0xb6, 0x98, 0x05, 0x66, 0xe3,
  15763. 0xbf, 0xe3, 0xc0, 0x49, 0x03, 0xda, 0xd4, 0xac, 0x2c, 0xdf, 0x9f, 0x22,
  15764. 0x80, 0x01, 0x0a, 0x67, 0x39, 0xbc, 0x83, 0xd3
  15765. };
  15766. WOLFSSL_SMALL_STACK_STATIC const byte test2Output[] =
  15767. {
  15768. 0x04, 0xee, 0xc6, 0x3b, 0xb2, 0x31, 0xdf, 0x2c, 0x63, 0x0a, 0x1a, 0xfb,
  15769. 0xe7, 0x24, 0x94, 0x9d, 0x00, 0x5a, 0x58, 0x78, 0x51, 0xe1, 0xaa, 0x79,
  15770. 0x5e, 0x47, 0x73, 0x47, 0xc8, 0xb0, 0x56, 0x62, 0x1c, 0x18, 0xbd, 0xdc,
  15771. 0xdd, 0x8d, 0x99, 0xfc, 0x5f, 0xc2, 0xb9, 0x20, 0x53, 0xd8, 0xcf, 0xac,
  15772. 0xfb, 0x0b, 0xb8, 0x83, 0x12, 0x05, 0xfa, 0xd1, 0xdd, 0xd6, 0xc0, 0x71,
  15773. 0x31, 0x8a, 0x60, 0x18, 0xf0, 0x3b, 0x73, 0xf5, 0xed, 0xe4, 0xd4, 0xd0,
  15774. 0x71, 0xf9, 0xde, 0x03, 0xfd, 0x7a, 0xea, 0x10, 0x5d, 0x92, 0x99, 0xb8,
  15775. 0xaf, 0x99, 0xaa, 0x07, 0x5b, 0xdb, 0x4d, 0xb9, 0xaa, 0x28, 0xc1, 0x8d,
  15776. 0x17, 0x4b, 0x56, 0xee, 0x2a, 0x01, 0x4d, 0x09, 0x88, 0x96, 0xff, 0x22,
  15777. 0x82, 0xc9, 0x55, 0xa8, 0x19, 0x69, 0xe0, 0x69, 0xfa, 0x8c, 0xe0, 0x07,
  15778. 0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17
  15779. };
  15780. byte output[WC_SHA256_DIGEST_SIZE * 4];
  15781. wc_test_ret_t ret;
  15782. WOLFSSL_ENTER("random_test");
  15783. ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
  15784. output, sizeof(output));
  15785. if (ret != 0)
  15786. return WC_TEST_RET_ENC_EC(ret);
  15787. if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
  15788. return WC_TEST_RET_ENC_NC;
  15789. ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
  15790. test2EntropyB, sizeof(test2EntropyB),
  15791. output, sizeof(output));
  15792. if (ret != 0)
  15793. return WC_TEST_RET_ENC_EC(ret);
  15794. if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
  15795. return WC_TEST_RET_ENC_NC;
  15796. /* Basic RNG generate block test */
  15797. if ((ret = random_rng_test()) != 0)
  15798. return ret;
  15799. /* Test the seed check function. */
  15800. #if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
  15801. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  15802. {
  15803. word32 i, outputSz;
  15804. /* Repeat the same byte over and over. Should fail. */
  15805. outputSz = sizeof(output);
  15806. XMEMSET(output, 1, outputSz);
  15807. ret = wc_RNG_TestSeed(output, outputSz);
  15808. if (ret == 0)
  15809. return WC_TEST_RET_ENC_NC;
  15810. /* Every byte of the entropy scratch is different,
  15811. * entropy is a single byte that shouldn't match. */
  15812. outputSz = (sizeof(output) / 2) + 1;
  15813. for (i = 0; i < outputSz; i++)
  15814. output[i] = (byte)i;
  15815. ret = wc_RNG_TestSeed(output, outputSz);
  15816. if (ret != 0)
  15817. return WC_TEST_RET_ENC_EC(ret);
  15818. outputSz = sizeof(output);
  15819. for (i = 0; i < outputSz; i++)
  15820. output[i] = (byte)i;
  15821. ret = wc_RNG_TestSeed(output, outputSz);
  15822. if (ret != 0)
  15823. return WC_TEST_RET_ENC_EC(ret);
  15824. }
  15825. #endif
  15826. /* Test the seed callback. */
  15827. #ifdef WC_RNG_SEED_CB
  15828. if ((ret = rng_seed_test()) != 0)
  15829. return ret;
  15830. #endif
  15831. return 0;
  15832. }
  15833. #else
  15834. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15835. {
  15836. WOLFSSL_ENTER("random_test");
  15837. /* Basic RNG generate block test */
  15838. return random_rng_test();
  15839. }
  15840. #endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
  15841. #endif /* WC_NO_RNG */
  15842. #ifndef MEM_TEST_SZ
  15843. #define MEM_TEST_SZ 1024
  15844. #endif
  15845. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15846. static int simple_mem_test(size_t sz)
  15847. {
  15848. int ret = 0;
  15849. byte* b;
  15850. int i;
  15851. b = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15852. if (b == NULL) {
  15853. return WC_TEST_RET_ENC_NC;
  15854. }
  15855. /* utilize memory */
  15856. for (i = 0; i < (int)sz; i++) {
  15857. b[i] = (byte)i;
  15858. }
  15859. /* read back and verify */
  15860. for (i = 0; i < (int)sz; i++) {
  15861. if (b[i] != (byte)i) {
  15862. ret = WC_TEST_RET_ENC_NC;
  15863. break;
  15864. }
  15865. }
  15866. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15867. return ret;
  15868. }
  15869. #endif
  15870. /* If successful, returns the first letter of the byte array `in`.
  15871. **
  15872. ** This is a deceptively simple test of a read-only embedded Linux file system.
  15873. ** (e.g CFLAGS `-mfdpic` and `-mforce-l32`) for Xtensa Linux ESP32. When the
  15874. ** `-mforce-l32` is missing, access to `in` will fail with Illegal Instruction.
  15875. ** Const is on read-only memory-mapped file system, *not* loaded in app memory.
  15876. **
  15877. ** Edit with caution. See PR #6523. */
  15878. static wc_test_ret_t const_byte_ptr_test(const byte* in, word32 *outJ)
  15879. {
  15880. wc_test_ret_t ret = 0;
  15881. volatile word32 j = (word32)-1; /* must be volatile to properly detect error */
  15882. ret = (wc_test_ret_t)*in; /* accessed *in value. */
  15883. (void)ret;
  15884. j = *outJ; /* Found index to use in const array. */
  15885. if (j == 0) {
  15886. #ifdef WOLFSSL_DEBUG
  15887. printf("Testing const byte ptr reference...\n");
  15888. #endif
  15889. /* although j is zero, in[0] does not detect the Illegal instruction */
  15890. ret = in[j]; /* The big test: can we actually access the `in` data? */
  15891. }
  15892. else {
  15893. ret = WC_TEST_RET_ENC_I(j);
  15894. }
  15895. return ret;
  15896. }
  15897. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
  15898. {
  15899. wc_test_ret_t ret = 0;
  15900. word32 j = 0; /* used in embedded const pointer test */
  15901. WOLFSSL_ENTER("memory_test");
  15902. #if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY)
  15903. int i;
  15904. #endif
  15905. #ifdef WOLFSSL_STATIC_MEMORY
  15906. word32 size[] = { WOLFMEM_BUCKETS };
  15907. word32 dist[] = { WOLFMEM_DIST };
  15908. byte buffer[30000]; /* make large enough to involve many bucket sizes */
  15909. int pad = -(int)((wc_ptr_t)buffer) & (WOLFSSL_STATIC_ALIGN - 1);
  15910. /* pad to account for if head of buffer is not at set memory
  15911. * alignment when tests are ran */
  15912. #endif
  15913. #ifdef WOLFSSL_STATIC_MEMORY
  15914. /* check macro settings */
  15915. if (sizeof(size)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15916. return WC_TEST_RET_ENC_NC;
  15917. }
  15918. if (sizeof(dist)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15919. return WC_TEST_RET_ENC_NC;
  15920. }
  15921. if (WOLFMEM_DEF_BUCKETS > WOLFMEM_MAX_BUCKETS) {
  15922. return WC_TEST_RET_ENC_NC;
  15923. }
  15924. for (i = 0; i < WOLFMEM_DEF_BUCKETS; i++) {
  15925. if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) {
  15926. /* each element in array should be divisible by alignment size */
  15927. return WC_TEST_RET_ENC_NC;
  15928. }
  15929. }
  15930. for (i = 1; i < WOLFMEM_DEF_BUCKETS; i++) {
  15931. if (size[i - 1] >= size[i]) {
  15932. return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */
  15933. }
  15934. }
  15935. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  15936. /* check that padding size returned is possible */
  15937. if (wolfSSL_MemoryPaddingSz() < WOLFSSL_STATIC_ALIGN) {
  15938. return WC_TEST_RET_ENC_NC; /* no room for wc_Memory struct */
  15939. }
  15940. ret = wolfSSL_MemoryPaddingSz();
  15941. if (ret < 0) {
  15942. return WC_TEST_RET_ENC_EC(ret);
  15943. }
  15944. if (wolfSSL_MemoryPaddingSz() % WOLFSSL_STATIC_ALIGN != 0) {
  15945. return WC_TEST_RET_ENC_NC; /* not aligned! */
  15946. }
  15947. /* check function to return optimum buffer size (rounded down) */
  15948. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_GENERAL);
  15949. if (ret < 0) {
  15950. return WC_TEST_RET_ENC_EC(ret);
  15951. }
  15952. if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) {
  15953. return WC_TEST_RET_ENC_NC; /* not aligned! */
  15954. }
  15955. if ((unsigned int)ret > sizeof(buffer)) {
  15956. return WC_TEST_RET_ENC_NC; /* did not round down as expected */
  15957. }
  15958. if (ret != wolfSSL_StaticBufferSz(buffer, ret, WOLFMEM_GENERAL)) {
  15959. return WC_TEST_RET_ENC_NC; /* return value changed when using suggested
  15960. * value
  15961. */
  15962. }
  15963. ret = wolfSSL_MemoryPaddingSz();
  15964. ret += pad; /* add space that is going to be needed if buffer not aligned */
  15965. if (wolfSSL_StaticBufferSz(buffer, size[0] + ret + 1, WOLFMEM_GENERAL) !=
  15966. (ret + (int)size[0])) {
  15967. return WC_TEST_RET_ENC_NC; /* did not round down to nearest bucket
  15968. * value
  15969. */
  15970. }
  15971. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_IO_POOL);
  15972. if ((ret - pad) < 0) {
  15973. return WC_TEST_RET_ENC_NC;
  15974. }
  15975. if (((ret - pad) % (WOLFMEM_IO_SZ + wolfSSL_MemoryPaddingSz())) != 0) {
  15976. return WC_TEST_RET_ENC_NC; /* not even chunks of memory for IO size */
  15977. }
  15978. if (((ret - pad) % WOLFSSL_STATIC_ALIGN) != 0) {
  15979. return WC_TEST_RET_ENC_NC; /* memory not aligned */
  15980. }
  15981. /* check for passing bad or unknown arguments to functions */
  15982. if (wolfSSL_StaticBufferSz(NULL, 1, WOLFMEM_GENERAL) > 0) {
  15983. return WC_TEST_RET_ENC_NC;
  15984. }
  15985. if (wolfSSL_StaticBufferSz(buffer, 1, WOLFMEM_GENERAL) != 0) {
  15986. return WC_TEST_RET_ENC_NC; /* should round to 0
  15987. since struct + bucket will not fit */
  15988. }
  15989. #endif
  15990. (void)pad;
  15991. (void)dist; /* avoid static analysis warning of variable not used */
  15992. #endif
  15993. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15994. /* simple test */
  15995. ret = simple_mem_test((size_t)MEM_TEST_SZ);
  15996. if (ret != 0)
  15997. return ret;
  15998. #endif
  15999. #ifdef COMPLEX_MEM_TEST
  16000. /* test various size blocks */
  16001. for (i = 1; i < MEM_TEST_SZ; i*=2) {
  16002. ret = simple_mem_test((size_t)i);
  16003. if (ret != 0)
  16004. return ret;
  16005. }
  16006. #endif
  16007. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) && defined(XREALLOC)
  16008. /* realloc test */
  16009. {
  16010. byte *b = (byte*)XMALLOC(MEM_TEST_SZ, HEAP_HINT,
  16011. DYNAMIC_TYPE_TMP_BUFFER);
  16012. #ifndef WOLFSSL_NO_REALLOC
  16013. byte *c = NULL;
  16014. if (b) {
  16015. c = (byte*)XREALLOC(b, MEM_TEST_SZ+sizeof(word32), HEAP_HINT,
  16016. DYNAMIC_TYPE_TMP_BUFFER);
  16017. if (c)
  16018. b = c;
  16019. }
  16020. #endif
  16021. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16022. if (b == NULL
  16023. #ifndef WOLFSSL_NO_REALLOC
  16024. || c == NULL
  16025. #endif
  16026. ) {
  16027. return WC_TEST_RET_ENC_ERRNO;
  16028. }
  16029. }
  16030. #endif
  16031. if (ret == 0) {
  16032. /* This test is only interesting on embedded R/O Flash systems */
  16033. if (const_byte_ptr_test(const_byte_array, &j) != CBPTR_EXPECTED) {
  16034. ret = 1;
  16035. }
  16036. }
  16037. return ret;
  16038. }
  16039. #ifndef NO_FILESYSTEM
  16040. /* Cert Paths */
  16041. #ifdef FREESCALE_MQX
  16042. #define CERT_PREFIX "a:\\"
  16043. #define CERT_PATH_SEP "\\"
  16044. #elif defined(WOLFSSL_uTKERNEL2)
  16045. #define CERT_PREFIX "/uda/"
  16046. #define CERT_PATH_SEP "/"
  16047. #elif defined(_WIN32_WCE)
  16048. #define CERT_PREFIX "\\windows\\"
  16049. #define CERT_PATH_SEP "\\"
  16050. #elif defined(WOLFSSL_NDS)
  16051. #undef CERT_PREFIX
  16052. #define CERT_PREFIX "fat:/_nds/"
  16053. #define CERT_PATH_SEP "/"
  16054. #endif
  16055. #ifndef CERT_PREFIX
  16056. #define CERT_PREFIX "./"
  16057. #endif
  16058. #ifndef CERT_PATH_SEP
  16059. #define CERT_PATH_SEP "/"
  16060. #endif
  16061. #ifndef CERT_WRITE_TEMP_DIR
  16062. #define CERT_WRITE_TEMP_DIR CERT_PREFIX
  16063. #endif
  16064. #define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
  16065. /* Generated Test Certs */
  16066. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16067. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16068. #if !defined(NO_RSA) && !defined(NO_ASN)
  16069. static const char* clientKey = CERT_ROOT "client-key.der";
  16070. static const char* clientCert = CERT_ROOT "client-cert.der";
  16071. #ifdef WOLFSSL_CERT_EXT
  16072. static const char* clientKeyPub = CERT_ROOT "client-keyPub.der";
  16073. #endif
  16074. #endif /* !NO_RSA && !NO_ASN */
  16075. #endif
  16076. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16077. #if !defined(NO_RSA) && !defined(NO_ASN)
  16078. #if defined(WOLFSSL_CERT_GEN) || defined(HAVE_PKCS7)
  16079. static const char* rsaCaKeyFile = CERT_ROOT "ca-key.der";
  16080. #ifdef WOLFSSL_CERT_GEN
  16081. static const char* rsaCaCertFile = CERT_ROOT "ca-cert.pem";
  16082. #endif
  16083. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  16084. static const char* rsaCaCertDerFile = CERT_ROOT "ca-cert.der";
  16085. #endif
  16086. #ifdef HAVE_PKCS7
  16087. static const char* rsaServerCertDerFile =
  16088. CERT_ROOT "server-cert.der";
  16089. static const char* rsaServerKeyDerFile =
  16090. CERT_ROOT "server-key.der";
  16091. #endif
  16092. #endif
  16093. #endif /* !NO_RSA && !NO_ASN */
  16094. #endif /* !USE_CERT_BUFFER_* */
  16095. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16096. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16097. #if !defined(NO_ASN) && !defined(NO_DH)
  16098. static const char* dhParamsFile = CERT_ROOT "dh2048.der";
  16099. #endif
  16100. #endif
  16101. #if !defined(NO_ASN) && !defined(NO_DH)
  16102. #if defined(WOLFSSL_DH_EXTRA) && (!defined(HAVE_FIPS) || \
  16103. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  16104. #if !defined(USE_CERT_BUFFERS_2048)
  16105. static const char* dhKeyFile = CERT_ROOT "statickeys/dh-ffdhe2048.der";
  16106. static const char* dhKeyPubFile = CERT_ROOT "statickeys/dh-ffdhe2048-pub.der";
  16107. #endif
  16108. #endif
  16109. #endif
  16110. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16111. #ifndef NO_DSA
  16112. static const char* dsaKey = CERT_ROOT "dsa2048.der";
  16113. #endif
  16114. #endif /* !USE_CERT_BUFFER_* */
  16115. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ECC256)
  16116. #ifdef HAVE_ECC
  16117. /* cert files to be used in rsa cert gen test, check if RSA enabled */
  16118. #ifdef HAVE_ECC_KEY_IMPORT
  16119. static const char* eccKeyDerFile = CERT_ROOT "ecc-key.der";
  16120. #endif
  16121. #endif
  16122. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN)
  16123. #if defined(HAVE_ECC) && defined(WOLFSSL_CERT_GEN) && \
  16124. !defined(NO_ECC_SECP)
  16125. #ifndef NO_RSA
  16126. static const char* eccKeyPubFileDer = CERT_ROOT "ecc-keyPub.der";
  16127. #endif
  16128. #ifndef NO_ASN_TIME
  16129. static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der";
  16130. static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem";
  16131. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16132. static const char* eccCaKey384File =
  16133. CERT_ROOT "ca-ecc384-key.der";
  16134. static const char* eccCaCert384File =
  16135. CERT_ROOT "ca-ecc384-cert.pem";
  16136. #endif
  16137. #endif
  16138. #endif
  16139. #if defined(HAVE_PKCS7) && defined(HAVE_ECC)
  16140. static const char* eccClientKey = CERT_ROOT "ecc-client-key.der";
  16141. static const char* eccClientCert = CERT_ROOT "client-ecc-cert.der";
  16142. #endif
  16143. #endif /* HAVE_ECC */
  16144. #ifdef HAVE_ED25519
  16145. #ifdef WOLFSSL_TEST_CERT
  16146. static const char* serverEd25519Cert =
  16147. CERT_ROOT "ed25519/server-ed25519.der";
  16148. static const char* caEd25519Cert =
  16149. CERT_ROOT "ed25519/ca-ed25519.der";
  16150. #endif
  16151. #endif
  16152. #ifdef HAVE_ED448
  16153. #ifdef WOLFSSL_TEST_CERT
  16154. static const char* serverEd448Cert =
  16155. CERT_ROOT "ed448/server-ed448.der";
  16156. static const char* caEd448Cert = CERT_ROOT "ed448/ca-ed448.der";
  16157. #endif
  16158. #endif
  16159. #endif /* !USE_CERT_BUFFER_* */
  16160. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16161. !defined(NO_FILESYSTEM)
  16162. static const char* certExtNc =
  16163. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nc.der";
  16164. static const char* certExtIa =
  16165. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-ia.der";
  16166. static const char* certExtNct =
  16167. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nct.der";
  16168. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16169. static const char* certBadNegInt =
  16170. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-neg-int.der";
  16171. #endif
  16172. static const char* certBadOid =
  16173. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-oid.der";
  16174. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16175. static const char* certBadUtf8 =
  16176. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-utf8.der";
  16177. #endif
  16178. #endif
  16179. #ifndef NO_WRITE_TEMP_FILES
  16180. #ifdef HAVE_ECC
  16181. #ifndef NO_ECC_SECP
  16182. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME)
  16183. static const char* certEccPemFile = CERT_WRITE_TEMP_DIR "certecc.pem";
  16184. static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der";
  16185. #endif
  16186. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  16187. static const char* certEccRsaPemFile = CERT_WRITE_TEMP_DIR "certeccrsa.pem";
  16188. static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der";
  16189. #endif
  16190. #endif
  16191. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  16192. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ASN_CRYPT)
  16193. static const char* eccCaKeyPemFile = CERT_WRITE_TEMP_DIR "ecc-key.pem";
  16194. static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der";
  16195. static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der";
  16196. #if defined(HAVE_PKCS8) && !defined(WC_NO_RNG) && \
  16197. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  16198. static const char* eccPkcs8KeyDerFile = CERT_WRITE_TEMP_DIR "ecc-key-pkcs8.der";
  16199. #endif
  16200. #endif /* HAVE_ECC_KEY_EXPORT */
  16201. #endif /* HAVE_ECC */
  16202. #ifndef NO_RSA
  16203. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME)
  16204. static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der";
  16205. static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der";
  16206. static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem";
  16207. static const char* certPemFile = CERT_WRITE_TEMP_DIR "cert.pem";
  16208. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  16209. static const char* certReqDerFile = CERT_WRITE_TEMP_DIR "certreq.der";
  16210. static const char* certReqPemFile = CERT_WRITE_TEMP_DIR "certreq.pem";
  16211. #endif
  16212. #endif
  16213. #endif /* !NO_RSA */
  16214. #if !defined(NO_RSA) || !defined(NO_DSA)
  16215. #ifdef WOLFSSL_KEY_GEN
  16216. static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
  16217. static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
  16218. #endif
  16219. #endif
  16220. #endif /* !NO_WRITE_TEMP_FILES */
  16221. #endif /* !NO_FILESYSTEM */
  16222. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  16223. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  16224. static CertName certDefaultName;
  16225. static void initDefaultName(void)
  16226. {
  16227. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16228. NameAttrib* n;
  16229. #endif
  16230. XMEMCPY(certDefaultName.country, "US", sizeof("US"));
  16231. certDefaultName.countryEnc = CTC_PRINTABLE;
  16232. XMEMCPY(certDefaultName.state, "Oregon", sizeof("Oregon"));
  16233. certDefaultName.stateEnc = CTC_UTF8;
  16234. XMEMCPY(certDefaultName.street, "Main St", sizeof("Main St"));
  16235. certDefaultName.streetEnc = CTC_UTF8;
  16236. XMEMCPY(certDefaultName.locality, "Portland", sizeof("Portland"));
  16237. certDefaultName.localityEnc = CTC_UTF8;
  16238. XMEMCPY(certDefaultName.sur, "Test", sizeof("Test"));
  16239. certDefaultName.surEnc = CTC_UTF8;
  16240. XMEMCPY(certDefaultName.org, "wolfSSL", sizeof("wolfSSL"));
  16241. certDefaultName.orgEnc = CTC_UTF8;
  16242. XMEMCPY(certDefaultName.unit, "Development", sizeof("Development"));
  16243. certDefaultName.unitEnc = CTC_UTF8;
  16244. XMEMCPY(certDefaultName.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  16245. certDefaultName.commonNameEnc = CTC_UTF8;
  16246. XMEMCPY(certDefaultName.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  16247. certDefaultName.serialDevEnc = CTC_PRINTABLE;
  16248. XMEMCPY(certDefaultName.postalCode, "12-456", sizeof("12-456"));
  16249. certDefaultName.postalCodeEnc = CTC_PRINTABLE;
  16250. #ifdef WOLFSSL_CERT_EXT
  16251. XMEMCPY(certDefaultName.busCat, "Private Organization", sizeof("Private Organization"));
  16252. certDefaultName.busCatEnc = CTC_UTF8;
  16253. XMEMCPY(certDefaultName.joiSt, "US", sizeof("US"));
  16254. certDefaultName.joiStEnc = CTC_PRINTABLE;
  16255. XMEMCPY(certDefaultName.joiC, "Oregon", sizeof("Oregon"));
  16256. certDefaultName.joiCEnc = CTC_PRINTABLE;
  16257. #endif
  16258. XMEMCPY(certDefaultName.email, "info@wolfssl.com", sizeof("info@wolfssl.com"));
  16259. XMEMCPY(certDefaultName.userId, "TestUserID", sizeof("TestUserID"));
  16260. certDefaultName.userIdEnc = CTC_PRINTABLE;
  16261. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16262. /* test having additional OUs and setting DC */
  16263. n = &certDefaultName.name[0];
  16264. n->id = ASN_ORGUNIT_NAME;
  16265. n->type = CTC_UTF8;
  16266. n->sz = XSTRLEN("Development-2");
  16267. XMEMCPY(n->value, "Development-2", sizeof("Development-2"));
  16268. #if CTC_MAX_ATTRIB > 3
  16269. n = &certDefaultName.name[1];
  16270. n->id = ASN_DOMAIN_COMPONENT;
  16271. n->type = CTC_UTF8;
  16272. n->sz = XSTRLEN("com");
  16273. XMEMCPY(n->value, "com", sizeof("com"));
  16274. n = &certDefaultName.name[2];
  16275. n->id = ASN_DOMAIN_COMPONENT;
  16276. n->type = CTC_UTF8;
  16277. n->sz = XSTRLEN("wolfssl");
  16278. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  16279. #endif
  16280. #endif /* WOLFSSL_MULTI_ATTRIB && WOLFSSL_TEST_CERT */
  16281. #ifdef WOLFSSL_CUSTOM_OID
  16282. /* TODO: Add test case for custom OID's */
  16283. #endif
  16284. }
  16285. #ifdef WOLFSSL_CERT_EXT
  16286. #if ((defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  16287. defined(WOLFSSL_TEST_CERT)) || defined(HAVE_ECC)
  16288. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage[] =
  16289. "digitalSignature,nonRepudiation";
  16290. #endif
  16291. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_ASN_TIME)
  16292. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage2[] =
  16293. "digitalSignature,nonRepudiation,keyEncipherment,keyAgreement";
  16294. #endif
  16295. #endif /* WOLFSSL_CERT_EXT */
  16296. #endif /* WOLFSSL_CERT_GEN */
  16297. #ifndef NO_RSA
  16298. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16299. !defined(NO_FILESYSTEM)
  16300. static const byte minSerial[] = { 0x02, 0x01, 0x01 };
  16301. static const byte minName[] = { 0x30, 0x00 };
  16302. static const byte nameBad[] = {
  16303. 0x30, 0x08,
  16304. 0x31, 0x06,
  16305. 0x30, 0x04,
  16306. 0x06, 0x02,
  16307. 0x55, 0x04,
  16308. };
  16309. static const byte minDates[] = {
  16310. 0x30, 0x1e,
  16311. 0x17, 0x0d,
  16312. 0x31, 0x38, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35,
  16313. 0x32, 0x33, 0x31, 0x30, 0x5a,
  16314. 0x17, 0x0d,
  16315. 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x31, 0x35,
  16316. 0x32, 0x33, 0x31, 0x30, 0x5a
  16317. };
  16318. static const byte minPubKey[] = {
  16319. 0x30, 0x1c,
  16320. 0x30, 0x0d,
  16321. 0x06, 0x09,
  16322. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16323. 0x01,
  16324. 0x05, 0x00,
  16325. 0x03, 0x0b,
  16326. 0x00, 0x30, 0x08,
  16327. 0x02, 0x01,
  16328. 0x03,
  16329. 0x02, 0x03,
  16330. 0x01, 0x00, 0x01
  16331. };
  16332. static const byte minSigAlg[] = {
  16333. 0x30, 0x0d,
  16334. 0x06, 0x09,
  16335. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16336. 0x0b,
  16337. 0x05, 0x00
  16338. };
  16339. static const byte minSig[] = {
  16340. 0x03, 0x01,
  16341. 0x00
  16342. };
  16343. static int add_seq(byte* certData, int offset, byte* data, byte length)
  16344. {
  16345. XMEMMOVE(certData + offset + 2, data, length);
  16346. certData[offset++] = 0x30;
  16347. certData[offset++] = length;
  16348. return offset + length;
  16349. }
  16350. static int add_data(byte* certData, int offset, const byte* data, byte length)
  16351. {
  16352. XMEMCPY(certData + offset, data, length);
  16353. return offset + length;
  16354. }
  16355. static wc_test_ret_t cert_asn1_test(void)
  16356. {
  16357. wc_test_ret_t ret;
  16358. int len[3];
  16359. DecodedCert cert;
  16360. byte certData[114];
  16361. byte* badCert = NULL;
  16362. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16363. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16364. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16365. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16366. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16367. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16368. len[1] = add_seq(certData, 0, certData, len[2]);
  16369. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16370. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16371. len[0] = add_seq(certData, 0, certData, len[1]);
  16372. /* Minimal good certificate */
  16373. InitDecodedCert(&cert, certData, len[0], 0);
  16374. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16375. FreeDecodedCert(&cert);
  16376. if (ret != 0)
  16377. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16378. /* Bad issuer name */
  16379. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16380. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16381. len[2] = add_data(certData, len[2], nameBad, (byte)sizeof(nameBad));
  16382. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16383. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16384. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16385. len[1] = add_seq(certData, 0, certData, len[2]);
  16386. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16387. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16388. len[0] = add_seq(certData, 0, certData, len[1]);
  16389. /* Put data into allocated buffer to allow access error checking. */
  16390. badCert = (byte*)XMALLOC(len[0], HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16391. XMEMCPY(badCert, certData, len[0]);
  16392. InitDecodedCert(&cert, badCert, len[0], 0);
  16393. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16394. FreeDecodedCert(&cert);
  16395. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  16396. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16397. }
  16398. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16399. badCert = NULL;
  16400. ret = 0;
  16401. done:
  16402. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16403. return ret;
  16404. }
  16405. static wc_test_ret_t cert_load_bad(const char* fname, byte* tmp, int err)
  16406. {
  16407. wc_test_ret_t ret;
  16408. DecodedCert cert;
  16409. XFILE file;
  16410. size_t bytes;
  16411. if ((fname == NULL) || (tmp == NULL)) {
  16412. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  16413. }
  16414. file = XFOPEN(fname, "rb");
  16415. if (!file) {
  16416. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16417. }
  16418. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16419. XFCLOSE(file);
  16420. if (bytes == 0) {
  16421. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16422. }
  16423. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16424. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16425. FreeDecodedCert(&cert);
  16426. if (ret != err) {
  16427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16428. }
  16429. ret = 0;
  16430. done:
  16431. return ret;
  16432. }
  16433. static wc_test_ret_t cert_bad_asn1_test(void)
  16434. {
  16435. wc_test_ret_t ret = 0;
  16436. byte* tmp;
  16437. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16438. if (tmp == NULL) {
  16439. ret = WC_TEST_RET_ENC_ERRNO;
  16440. }
  16441. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16442. if (ret == 0) {
  16443. /* Serial number: 0xff 0xa8. 0xff and top bit set on next byte invalid.
  16444. */
  16445. ret = cert_load_bad(certBadNegInt, tmp, ASN_EXPECT_0_E);
  16446. }
  16447. #endif
  16448. if (ret == 0) {
  16449. /* Subject name OID: 55 04 f4. Last byte with top bit set invalid. */
  16450. ret = cert_load_bad(certBadOid, tmp, ASN_PARSE_E);
  16451. }
  16452. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16453. if (ret == 0) {
  16454. /* Issuer name UTF8STRING: df 52 4e 44. Top bit of second byte not set.
  16455. */
  16456. ret = cert_load_bad(certBadUtf8, tmp, ASN_PARSE_E);
  16457. }
  16458. #endif
  16459. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16460. return ret;
  16461. }
  16462. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void)
  16463. {
  16464. #if !defined(NO_FILESYSTEM)
  16465. DecodedCert cert;
  16466. byte* tmp;
  16467. size_t bytes;
  16468. XFILE file;
  16469. wc_test_ret_t ret;
  16470. WOLFSSL_ENTER("cert_test");
  16471. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16472. if (tmp == NULL)
  16473. return WC_TEST_RET_ENC_ERRNO;
  16474. /* Certificate with Name Constraints extension. */
  16475. file = XFOPEN(certExtNc, "rb");
  16476. if (!file) {
  16477. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16478. }
  16479. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16480. XFCLOSE(file);
  16481. if (bytes == 0)
  16482. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16483. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16484. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16485. if (ret != 0)
  16486. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16487. FreeDecodedCert(&cert);
  16488. /* Certificate with Inhibit Any Policy extension. */
  16489. file = XFOPEN(certExtIa, "rb");
  16490. if (!file) {
  16491. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16492. }
  16493. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16494. XFCLOSE(file);
  16495. if (bytes == 0)
  16496. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16497. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16498. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16499. if (ret != 0)
  16500. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16501. FreeDecodedCert(&cert);
  16502. /* Certificate with Netscape Certificate Type extension. */
  16503. file = XFOPEN(certExtNct, "rb");
  16504. if (!file) {
  16505. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16506. }
  16507. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16508. XFCLOSE(file);
  16509. if (bytes == 0)
  16510. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16511. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16512. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16513. #ifndef IGNORE_NETSCAPE_CERT_TYPE
  16514. if (ret != 0)
  16515. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16516. #else
  16517. if (ret != WC_NO_ERR_TRACE(ASN_CRIT_EXT_E)) {
  16518. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16519. }
  16520. ret = 0;
  16521. #endif
  16522. done:
  16523. FreeDecodedCert(&cert);
  16524. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16525. #endif /* !NO_FILESYSTEM */
  16526. if (ret == 0)
  16527. ret = cert_asn1_test();
  16528. if (ret == 0)
  16529. ret = cert_bad_asn1_test();
  16530. return ret;
  16531. }
  16532. #endif /* WOLFSSL_TEST_CERT */
  16533. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  16534. !defined(NO_FILESYSTEM) && defined(WOLFSSL_CERT_GEN)
  16535. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void)
  16536. {
  16537. DecodedCert cert;
  16538. byte* tmp;
  16539. size_t bytes;
  16540. XFILE file;
  16541. wc_test_ret_t ret;
  16542. /* created from rsa_test : othercert.der */
  16543. byte skid_rsa[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16544. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16545. /* created from rsa_test : othercert.der */
  16546. byte akid_rsa[] = "\x27\x8E\x67\x11\x74\xC3\x26\x1D\x3F\xED"
  16547. "\x33\x63\xB3\xA4\xD8\x1D\x30\xE5\xE8\xD5";
  16548. #ifdef HAVE_ECC
  16549. /* created from ecc_test_cert_gen : certecc.der */
  16550. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16551. /* Authority key id from ./certs/ca-ecc384-cert.pem */
  16552. byte akid_ecc[] = "\xAB\xE0\xC3\x26\x4C\x18\xD4\x72\xBB\xD2"
  16553. "\x84\x8C\x9C\x0A\x05\x92\x80\x12\x53\x52";
  16554. #else
  16555. /* Authority key id from ./certs/ca-ecc-cert.pem */
  16556. byte akid_ecc[] = "\x56\x8E\x9A\xC3\xF0\x42\xDE\x18\xB9\x45"
  16557. "\x55\x6E\xF9\x93\xCF\xEA\xC3\xF3\xA5\x21";
  16558. #endif
  16559. #endif /* HAVE_ECC */
  16560. /* created from rsa_test : cert.der */
  16561. byte kid_ca[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16562. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16563. WOLFSSL_ENTER("certext_test");
  16564. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16565. if (tmp == NULL)
  16566. return WC_TEST_RET_ENC_ERRNO;
  16567. /* load othercert.der (Cert signed by an authority) */
  16568. file = XFOPEN(otherCertDerFile, "rb");
  16569. if (!file) {
  16570. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16571. return WC_TEST_RET_ENC_ERRNO;
  16572. }
  16573. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16574. XFCLOSE(file);
  16575. if (bytes == 0)
  16576. return WC_TEST_RET_ENC_ERRNO;
  16577. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16578. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16579. if (ret != 0)
  16580. return WC_TEST_RET_ENC_EC(ret);
  16581. /* check the SKID from a RSA certificate */
  16582. if ((sizeof(skid_rsa) - 1 != cert.extSubjKeyIdSz) ||
  16583. (XMEMCMP(skid_rsa, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16584. return WC_TEST_RET_ENC_NC;
  16585. /* check the AKID from an RSA certificate */
  16586. if ((sizeof(akid_rsa) - 1 != cert.extAuthKeyIdSz) ||
  16587. (XMEMCMP(akid_rsa, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16588. return WC_TEST_RET_ENC_NC;
  16589. /* check the Key Usage from an RSA certificate */
  16590. if (!cert.extKeyUsageSet)
  16591. return WC_TEST_RET_ENC_NC;
  16592. if (cert.extKeyUsage != (KEYUSE_KEY_ENCIPHER|KEYUSE_KEY_AGREE))
  16593. return WC_TEST_RET_ENC_NC;
  16594. /* check the CA Basic Constraints from an RSA certificate */
  16595. if (cert.isCA)
  16596. return WC_TEST_RET_ENC_NC;
  16597. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16598. /* check the Certificate Policies Id */
  16599. if (cert.extCertPoliciesNb != 1)
  16600. return WC_TEST_RET_ENC_NC;
  16601. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16602. return WC_TEST_RET_ENC_NC;
  16603. #endif
  16604. FreeDecodedCert(&cert);
  16605. #ifdef HAVE_ECC
  16606. /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */
  16607. file = XFOPEN(certEccDerFile, "rb");
  16608. if (!file) {
  16609. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16610. return WC_TEST_RET_ENC_ERRNO;
  16611. }
  16612. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16613. XFCLOSE(file);
  16614. if (bytes == 0)
  16615. return WC_TEST_RET_ENC_ERRNO;
  16616. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16617. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16618. if (ret != 0)
  16619. return WC_TEST_RET_ENC_EC(ret);
  16620. /* check the SKID from a ECC certificate - generated dynamically */
  16621. /* check the AKID from an ECC certificate */
  16622. if ((sizeof(akid_ecc) - 1 != cert.extAuthKeyIdSz) ||
  16623. (XMEMCMP(akid_ecc, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16624. return WC_TEST_RET_ENC_NC;
  16625. /* check the Key Usage from an ECC certificate */
  16626. if (!cert.extKeyUsageSet)
  16627. return WC_TEST_RET_ENC_NC;
  16628. if (cert.extKeyUsage != (KEYUSE_DIGITAL_SIG|KEYUSE_CONTENT_COMMIT))
  16629. return WC_TEST_RET_ENC_NC;
  16630. /* check the CA Basic Constraints from an ECC certificate */
  16631. if (cert.isCA)
  16632. return WC_TEST_RET_ENC_NC;
  16633. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16634. /* check the Certificate Policies Id */
  16635. if (cert.extCertPoliciesNb != 2)
  16636. return WC_TEST_RET_ENC_NC;
  16637. if (strncmp(cert.extCertPolicies[0], "2.4.589440.587.101.2.1.9632587.1", 32))
  16638. return WC_TEST_RET_ENC_NC;
  16639. if (strncmp(cert.extCertPolicies[1], "1.2.13025.489.1.113549", 22))
  16640. return WC_TEST_RET_ENC_NC;
  16641. #endif
  16642. FreeDecodedCert(&cert);
  16643. #endif /* HAVE_ECC */
  16644. /* load cert.der (self signed certificate) */
  16645. file = XFOPEN(certDerFile, "rb");
  16646. if (!file) {
  16647. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16648. return WC_TEST_RET_ENC_ERRNO;
  16649. }
  16650. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16651. XFCLOSE(file);
  16652. if (bytes == 0)
  16653. return WC_TEST_RET_ENC_ERRNO;
  16654. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16655. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16656. if (ret != 0)
  16657. return WC_TEST_RET_ENC_EC(ret);
  16658. /* check the SKID from a CA certificate */
  16659. if ((sizeof(kid_ca) - 1 != cert.extSubjKeyIdSz) ||
  16660. (XMEMCMP(kid_ca, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16661. return WC_TEST_RET_ENC_NC;
  16662. /* check the AKID from an CA certificate */
  16663. if ((sizeof(kid_ca) - 1 != cert.extAuthKeyIdSz) ||
  16664. (XMEMCMP(kid_ca, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16665. return WC_TEST_RET_ENC_NC;
  16666. /* check the Key Usage from CA certificate */
  16667. if (!cert.extKeyUsageSet)
  16668. return WC_TEST_RET_ENC_NC;
  16669. if (cert.extKeyUsage != (KEYUSE_KEY_CERT_SIGN|KEYUSE_CRL_SIGN))
  16670. return WC_TEST_RET_ENC_NC;
  16671. /* check the CA Basic Constraints CA certificate */
  16672. if (!cert.isCA)
  16673. return WC_TEST_RET_ENC_NC;
  16674. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16675. /* check the Certificate Policies Id */
  16676. if (cert.extCertPoliciesNb != 2)
  16677. return WC_TEST_RET_ENC_NC;
  16678. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16679. return WC_TEST_RET_ENC_NC;
  16680. if (strncmp(cert.extCertPolicies[1], "1.2.840.113549.1.9.16.6.5", 25))
  16681. return WC_TEST_RET_ENC_NC;
  16682. #endif
  16683. FreeDecodedCert(&cert);
  16684. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16685. return 0;
  16686. }
  16687. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_TEST_CERT &&
  16688. !NO_FILESYSTEM && WOLFSSL_CERT_GEN */
  16689. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  16690. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  16691. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void)
  16692. {
  16693. wc_test_ret_t ret = 0;
  16694. Cert cert;
  16695. FILE* file;
  16696. byte* der;
  16697. word32 derSz;
  16698. WOLFSSL_ENTER("decodedCertCache_test");
  16699. derSz = FOURK_BUF;
  16700. der = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16701. if (der == NULL)
  16702. ret = WC_TEST_RET_ENC_NC;
  16703. if (ret == 0) {
  16704. /* load cert.der */
  16705. file = XFOPEN(certDerFile, "rb");
  16706. if (file != NULL) {
  16707. derSz = (word32)XFREAD(der, 1, FOURK_BUF, file);
  16708. XFCLOSE(file);
  16709. if (derSz == 0)
  16710. ret = WC_TEST_RET_ENC_ERRNO;
  16711. }
  16712. else
  16713. ret = WC_TEST_RET_ENC_ERRNO;
  16714. }
  16715. if (ret == 0) {
  16716. ret = wc_InitCert_ex(&cert, HEAP_HINT, devId);
  16717. if (ret != 0)
  16718. ret = WC_TEST_RET_ENC_EC(ret);
  16719. }
  16720. if (ret == 0) {
  16721. ret = wc_SetSubjectBuffer(&cert, der, derSz);
  16722. if (ret != 0)
  16723. ret = WC_TEST_RET_ENC_EC(ret);
  16724. }
  16725. if (ret == 0) {
  16726. ret = wc_SetSubjectBuffer(NULL, der, derSz);
  16727. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16728. ret = 0;
  16729. else
  16730. ret = WC_TEST_RET_ENC_EC(ret);
  16731. }
  16732. if (ret == 0) {
  16733. ret = wc_SetSubjectRaw(&cert, der, derSz);
  16734. if (ret != 0)
  16735. ret = WC_TEST_RET_ENC_EC(ret);
  16736. }
  16737. if (ret == 0) {
  16738. ret = wc_SetSubjectRaw(NULL, der, derSz);
  16739. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16740. ret = 0;
  16741. else
  16742. ret = WC_TEST_RET_ENC_EC(ret);
  16743. }
  16744. if (ret == 0) {
  16745. ret = wc_SetIssuerBuffer(&cert, der, derSz);
  16746. if (ret != 0)
  16747. ret = WC_TEST_RET_ENC_EC(ret);
  16748. }
  16749. if (ret == 0) {
  16750. ret = wc_SetIssuerBuffer(NULL, der, derSz);
  16751. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16752. ret = 0;
  16753. else
  16754. ret = WC_TEST_RET_ENC_EC(ret);
  16755. }
  16756. if (ret == 0) {
  16757. ret = wc_SetIssuerRaw(&cert, der, derSz);
  16758. if (ret != 0)
  16759. ret = WC_TEST_RET_ENC_EC(ret);
  16760. }
  16761. if (ret == 0) {
  16762. ret = wc_SetIssuerRaw(NULL, der, derSz);
  16763. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16764. ret = 0;
  16765. else
  16766. ret = WC_TEST_RET_ENC_EC(ret);
  16767. }
  16768. #ifdef WOLFSSL_ALT_NAMES
  16769. if (ret == 0) {
  16770. ret = wc_SetAltNamesBuffer(&cert, der, derSz);
  16771. if (ret != 0)
  16772. ret = WC_TEST_RET_ENC_EC(ret);
  16773. }
  16774. if (ret == 0) {
  16775. ret = wc_SetAltNamesBuffer(NULL, der, derSz);
  16776. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16777. ret = 0;
  16778. else
  16779. ret = WC_TEST_RET_ENC_EC(ret);
  16780. }
  16781. if (ret == 0) {
  16782. ret = wc_SetDatesBuffer(&cert, der, derSz);
  16783. if (ret != 0)
  16784. ret = WC_TEST_RET_ENC_EC(ret);
  16785. }
  16786. if (ret == 0) {
  16787. ret = wc_SetDatesBuffer(NULL, der, derSz);
  16788. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16789. ret = 0;
  16790. else
  16791. ret = WC_TEST_RET_ENC_EC(ret);
  16792. }
  16793. #endif
  16794. if (ret == 0) {
  16795. ret = wc_SetAuthKeyIdFromCert(&cert, der, derSz);
  16796. if (ret != 0)
  16797. ret = WC_TEST_RET_ENC_EC(ret);
  16798. }
  16799. if (ret == 0) {
  16800. ret = wc_SetAuthKeyIdFromCert(NULL, der, derSz);
  16801. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16802. ret = 0;
  16803. else
  16804. ret = WC_TEST_RET_ENC_NC;
  16805. }
  16806. wc_SetCert_Free(&cert);
  16807. if (ret == 0) {
  16808. if(cert.decodedCert != NULL)
  16809. ret = WC_TEST_RET_ENC_NC;
  16810. }
  16811. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16812. return ret;
  16813. }
  16814. #endif /* defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) &&
  16815. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) */
  16816. #define RSA_TEST_BYTES 512 /* up to 4096-bit key */
  16817. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  16818. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16819. static wc_test_ret_t rsa_flatten_test(RsaKey* key)
  16820. {
  16821. wc_test_ret_t ret;
  16822. byte e[RSA_TEST_BYTES];
  16823. byte n[RSA_TEST_BYTES];
  16824. word32 eSz = sizeof(e);
  16825. word32 nSz = sizeof(n);
  16826. /* Parameter Validation testing. */
  16827. ret = wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz);
  16828. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16829. return WC_TEST_RET_ENC_EC(ret);
  16830. ret = wc_RsaFlattenPublicKey(key, NULL, &eSz, n, &nSz);
  16831. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16832. return WC_TEST_RET_ENC_EC(ret);
  16833. ret = wc_RsaFlattenPublicKey(key, e, NULL, n, &nSz);
  16834. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16835. return WC_TEST_RET_ENC_EC(ret);
  16836. ret = wc_RsaFlattenPublicKey(key, e, &eSz, NULL, &nSz);
  16837. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16838. return WC_TEST_RET_ENC_EC(ret);
  16839. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, NULL);
  16840. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16841. return WC_TEST_RET_ENC_EC(ret);
  16842. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16843. if (ret != 0)
  16844. return WC_TEST_RET_ENC_EC(ret);
  16845. eSz = 0;
  16846. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16847. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16848. return WC_TEST_RET_ENC_EC(ret);
  16849. eSz = sizeof(e);
  16850. nSz = 0;
  16851. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16852. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16853. return WC_TEST_RET_ENC_EC(ret);
  16854. return 0;
  16855. }
  16856. #endif /* NO_ASN */
  16857. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  16858. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16859. static wc_test_ret_t rsa_export_key_test(RsaKey* key)
  16860. {
  16861. wc_test_ret_t ret;
  16862. byte e[3];
  16863. word32 eSz = sizeof(e);
  16864. byte n[RSA_TEST_BYTES];
  16865. word32 nSz = sizeof(n);
  16866. byte d[RSA_TEST_BYTES];
  16867. word32 dSz = sizeof(d);
  16868. byte p[RSA_TEST_BYTES/2];
  16869. word32 pSz = sizeof(p);
  16870. byte q[RSA_TEST_BYTES/2];
  16871. word32 qSz = sizeof(q);
  16872. word32 zero = 0;
  16873. ret = wc_RsaExportKey(NULL, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16874. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16875. return WC_TEST_RET_ENC_EC(ret);
  16876. ret = wc_RsaExportKey(key, NULL, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16877. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16878. return WC_TEST_RET_ENC_EC(ret);
  16879. ret = wc_RsaExportKey(key, e, NULL, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16880. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16881. return WC_TEST_RET_ENC_EC(ret);
  16882. ret = wc_RsaExportKey(key, e, &eSz, NULL, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16883. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16884. return WC_TEST_RET_ENC_EC(ret);
  16885. ret = wc_RsaExportKey(key, e, &eSz, n, NULL, d, &dSz, p, &pSz, q, &qSz);
  16886. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16887. return WC_TEST_RET_ENC_EC(ret);
  16888. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, NULL, &dSz, p, &pSz, q, &qSz);
  16889. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16890. return WC_TEST_RET_ENC_EC(ret);
  16891. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, NULL, p, &pSz, q, &qSz);
  16892. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16893. return WC_TEST_RET_ENC_EC(ret);
  16894. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, NULL, &pSz, q, &qSz);
  16895. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16896. return WC_TEST_RET_ENC_EC(ret);
  16897. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, NULL, q, &qSz);
  16898. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16899. return WC_TEST_RET_ENC_EC(ret);
  16900. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, NULL, &qSz);
  16901. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16902. return WC_TEST_RET_ENC_EC(ret);
  16903. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, NULL);
  16904. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16905. return WC_TEST_RET_ENC_EC(ret);
  16906. ret = wc_RsaExportKey(key, e, &zero, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16907. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16908. return WC_TEST_RET_ENC_EC(ret);
  16909. ret = wc_RsaExportKey(key, e, &eSz, n, &zero, d, &dSz, p, &pSz, q, &qSz);
  16910. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16911. return WC_TEST_RET_ENC_EC(ret);
  16912. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  16913. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &zero, p, &pSz, q, &qSz);
  16914. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16915. return WC_TEST_RET_ENC_EC(ret);
  16916. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &zero, q, &qSz);
  16917. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16918. return WC_TEST_RET_ENC_EC(ret);
  16919. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &zero);
  16920. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16921. return WC_TEST_RET_ENC_EC(ret);
  16922. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  16923. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16924. if (ret != 0)
  16925. return WC_TEST_RET_ENC_EC(ret);
  16926. return 0;
  16927. }
  16928. #endif /* !HAVE_FIPS && !NO_ASN && !WOLFSSL_RSA_VERIFY_ONLY */
  16929. #ifndef NO_SIG_WRAPPER
  16930. static wc_test_ret_t rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng)
  16931. {
  16932. wc_test_ret_t ret;
  16933. word32 sigSz;
  16934. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  16935. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  16936. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  16937. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  16938. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  16939. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  16940. };
  16941. WOLFSSL_SMALL_STACK_STATIC const byte hashEnc[] = {
  16942. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  16943. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  16944. 0x00, 0x04, 0x20,
  16945. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  16946. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  16947. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  16948. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  16949. };
  16950. word32 inLen = (word32)XSTRLEN((char*)in);
  16951. byte out[RSA_TEST_BYTES];
  16952. /* Parameter Validation testing. */
  16953. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_NONE, key, keyLen);
  16954. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16955. return WC_TEST_RET_ENC_EC(ret);
  16956. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, 0);
  16957. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16958. return WC_TEST_RET_ENC_EC(ret);
  16959. sigSz = (word32)modLen;
  16960. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  16961. inLen, out, &sigSz, key, keyLen, rng);
  16962. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16963. return WC_TEST_RET_ENC_EC(ret);
  16964. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16965. 0, out, &sigSz, key, keyLen, rng);
  16966. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16967. return WC_TEST_RET_ENC_EC(ret);
  16968. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16969. inLen, NULL, &sigSz, key, keyLen, rng);
  16970. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16971. return WC_TEST_RET_ENC_EC(ret);
  16972. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16973. inLen, out, NULL, key, keyLen, rng);
  16974. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16975. return WC_TEST_RET_ENC_EC(ret);
  16976. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16977. inLen, out, &sigSz, NULL, keyLen, rng);
  16978. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16979. return WC_TEST_RET_ENC_EC(ret);
  16980. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16981. inLen, out, &sigSz, key, 0, rng);
  16982. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16983. return WC_TEST_RET_ENC_EC(ret);
  16984. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  16985. inLen, out, &sigSz, key, keyLen, NULL);
  16986. #if defined(WOLFSSL_AFALG_XILINX_RSA) || defined(WOLFSSL_XILINX_CRYPT)
  16987. /* blinding / rng handled with hardware acceleration */
  16988. if (ret != 0)
  16989. #elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
  16990. /* async may not require RNG */
  16991. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  16992. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID))
  16993. #else
  16994. if (ret != 0 && ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  16995. #endif
  16996. #elif defined(HAVE_FIPS) || !defined(WC_RSA_BLINDING)
  16997. /* FIPS140 implementation does not do blinding */
  16998. if (ret != 0)
  16999. #elif defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY)
  17000. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17001. #elif defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SE050)
  17002. /* RNG is handled by hardware */
  17003. if (ret != 0)
  17004. #else
  17005. if (ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17006. #endif
  17007. return WC_TEST_RET_ENC_EC(ret);
  17008. sigSz = 0;
  17009. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17010. inLen, out, &sigSz, key, keyLen, rng);
  17011. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17012. return WC_TEST_RET_ENC_EC(ret);
  17013. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17014. inLen, out, (word32)modLen, key, keyLen);
  17015. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17016. return WC_TEST_RET_ENC_EC(ret);
  17017. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17018. 0, out, (word32)modLen, key, keyLen);
  17019. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17020. return WC_TEST_RET_ENC_EC(ret);
  17021. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17022. inLen, NULL, (word32)modLen, key, keyLen);
  17023. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17024. return WC_TEST_RET_ENC_EC(ret);
  17025. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17026. inLen, out, 0, key, keyLen);
  17027. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17028. return WC_TEST_RET_ENC_EC(ret);
  17029. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17030. inLen, out, (word32)modLen, NULL, keyLen);
  17031. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17032. return WC_TEST_RET_ENC_EC(ret);
  17033. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17034. inLen, out, (word32)modLen, key, 0);
  17035. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17036. return WC_TEST_RET_ENC_EC(ret);
  17037. #ifndef HAVE_ECC
  17038. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, keyLen);
  17039. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17040. return WC_TEST_RET_ENC_EC(ret);
  17041. #endif
  17042. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17043. return 0;
  17044. #endif
  17045. /* Use APIs. */
  17046. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, keyLen);
  17047. if (ret != modLen)
  17048. return WC_TEST_RET_ENC_EC(ret);
  17049. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA_W_ENC, key, keyLen);
  17050. if (ret != modLen)
  17051. return WC_TEST_RET_ENC_EC(ret);
  17052. sigSz = (word32)ret;
  17053. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  17054. XMEMSET(out, 0, sizeof(out));
  17055. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17056. inLen, out, &sigSz, key, keyLen, rng);
  17057. if (ret != 0)
  17058. return WC_TEST_RET_ENC_EC(ret);
  17059. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17060. inLen, out, (word32)modLen, key, keyLen);
  17061. if (ret != 0)
  17062. return WC_TEST_RET_ENC_EC(ret);
  17063. sigSz = (word32)sizeof(out);
  17064. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17065. in, inLen, out, &sigSz, key, keyLen, rng);
  17066. if (ret != 0)
  17067. return WC_TEST_RET_ENC_EC(ret);
  17068. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17069. in, inLen, out, (word32)modLen, key, keyLen);
  17070. if (ret != 0)
  17071. return WC_TEST_RET_ENC_EC(ret);
  17072. /* Wrong signature type. */
  17073. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17074. inLen, out, (word32)modLen, key, keyLen);
  17075. if (ret == 0)
  17076. return WC_TEST_RET_ENC_EC(ret);
  17077. /* check hash functions */
  17078. sigSz = (word32)sizeof(out);
  17079. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17080. hash, (int)sizeof(hash), out, &sigSz, key, keyLen, rng);
  17081. if (ret != 0)
  17082. return WC_TEST_RET_ENC_EC(ret);
  17083. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17084. hash, (int)sizeof(hash), out, (word32)modLen, key, keyLen);
  17085. if (ret != 0)
  17086. return WC_TEST_RET_ENC_EC(ret);
  17087. sigSz = (word32)sizeof(out);
  17088. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17089. hashEnc, (int)sizeof(hashEnc), out, &sigSz, key, keyLen, rng);
  17090. if (ret != 0)
  17091. return WC_TEST_RET_ENC_EC(ret);
  17092. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17093. hashEnc, (int)sizeof(hashEnc), out, (word32)modLen, key, keyLen);
  17094. if (ret != 0)
  17095. return WC_TEST_RET_ENC_EC(ret);
  17096. #else
  17097. (void)hash;
  17098. (void)hashEnc;
  17099. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  17100. return 0;
  17101. }
  17102. #endif /* !NO_SIG_WRAPPER */
  17103. #ifdef WC_RSA_NONBLOCK
  17104. static wc_test_ret_t rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out,
  17105. word32 outSz, byte* plain, word32 plainSz, WC_RNG* rng)
  17106. {
  17107. wc_test_ret_t ret = 0;
  17108. int count;
  17109. int signSz = 0;
  17110. RsaNb nb;
  17111. byte* inlinePlain = NULL;
  17112. /* Enable non-blocking RSA mode - provide context */
  17113. ret = wc_RsaSetNonBlock(key, &nb);
  17114. if (ret != 0)
  17115. return ret;
  17116. #ifdef WC_RSA_NONBLOCK_TIME
  17117. /* Enable time based RSA blocking. 8 microseconds max (3.1GHz) */
  17118. ret = wc_RsaSetNonBlockTime(key, 8, 3100);
  17119. if (ret != 0)
  17120. return ret;
  17121. #endif
  17122. count = 0;
  17123. do {
  17124. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, rng);
  17125. count++; /* track number of would blocks */
  17126. if (ret == FP_WOULDBLOCK) {
  17127. /* do "other" work here */
  17128. }
  17129. } while (ret == FP_WOULDBLOCK);
  17130. if (ret < 0) {
  17131. return ret;
  17132. }
  17133. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17134. printf("RSA non-block sign: %d times\n", count);
  17135. #endif
  17136. signSz = ret;
  17137. /* Test non-blocking verify */
  17138. XMEMSET(plain, 0, plainSz);
  17139. count = 0;
  17140. do {
  17141. ret = wc_RsaSSL_Verify(out, (word32)signSz, plain, plainSz, key);
  17142. count++; /* track number of would blocks */
  17143. if (ret == FP_WOULDBLOCK) {
  17144. /* do "other" work here */
  17145. }
  17146. } while (ret == FP_WOULDBLOCK);
  17147. if (ret < 0) {
  17148. return ret;
  17149. }
  17150. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17151. printf("RSA non-block verify: %d times\n", count);
  17152. #endif
  17153. if (signSz == ret && XMEMCMP(plain, in, (size_t)ret)) {
  17154. return SIG_VERIFY_E;
  17155. }
  17156. /* Test inline non-blocking verify */
  17157. count = 0;
  17158. do {
  17159. ret = wc_RsaSSL_VerifyInline(out, (word32)signSz, &inlinePlain, key);
  17160. count++; /* track number of would blocks */
  17161. if (ret == FP_WOULDBLOCK) {
  17162. /* do "other" work here */
  17163. }
  17164. } while (ret == FP_WOULDBLOCK);
  17165. if (ret < 0) {
  17166. return ret;
  17167. }
  17168. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17169. printf("RSA non-block inline verify: %d times\n", count);
  17170. #endif
  17171. if (signSz == ret && XMEMCMP(inlinePlain, in, (size_t)ret)) {
  17172. return SIG_VERIFY_E;
  17173. }
  17174. /* Disabling non-block RSA mode */
  17175. ret = wc_RsaSetNonBlock(key, NULL);
  17176. (void)count;
  17177. return 0;
  17178. }
  17179. #endif
  17180. #if !defined(NO_ASN)
  17181. static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
  17182. {
  17183. wc_test_ret_t ret;
  17184. word32 inSz;
  17185. word32 inOutIdx;
  17186. WOLFSSL_SMALL_STACK_STATIC const byte n[2] = { 0x00, 0x23 };
  17187. WOLFSSL_SMALL_STACK_STATIC const byte e[2] = { 0x00, 0x03 };
  17188. WOLFSSL_SMALL_STACK_STATIC const byte good[] = { 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1,
  17189. 0x03 };
  17190. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgId[] = {
  17191. 0x30, 0x18, 0x30, 0x16,
  17192. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17193. 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17194. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgIdNull[] = {
  17195. 0x30, 0x1a, 0x30, 0x18,
  17196. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17197. 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17198. 0x02, 0x1, 0x03 };
  17199. WOLFSSL_SMALL_STACK_STATIC const byte badAlgIdNull[] = {
  17200. 0x30, 0x1b, 0x30, 0x19,
  17201. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17202. 0x05, 0x01, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17203. 0x02, 0x1, 0x03 };
  17204. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitString[] = {
  17205. 0x30, 0x18, 0x30, 0x16,
  17206. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17207. 0x04, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17208. WOLFSSL_SMALL_STACK_STATIC const byte badBitStringLen[] = {
  17209. 0x30, 0x18, 0x30, 0x16,
  17210. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17211. 0x03, 0x0a, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17212. WOLFSSL_SMALL_STACK_STATIC const byte badNoSeq[] = {
  17213. 0x30, 0x16, 0x30, 0x14,
  17214. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17215. 0x07, 0x00, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17216. WOLFSSL_SMALL_STACK_STATIC const byte badNoObj[] = {
  17217. 0x30, 0x0f, 0x30, 0x0d, 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06,
  17218. 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17219. WOLFSSL_SMALL_STACK_STATIC const byte badIntN[] = {
  17220. 0x30, 0x06, 0x02, 0x05, 0x23, 0x02, 0x1, 0x03 };
  17221. WOLFSSL_SMALL_STACK_STATIC const byte badNotIntE[] = {
  17222. 0x30, 0x06, 0x02, 0x01, 0x23, 0x04, 0x1, 0x03 };
  17223. WOLFSSL_SMALL_STACK_STATIC const byte badLength[] = {
  17224. 0x30, 0x04, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17225. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrNoZero[] = {
  17226. 0x30, 0x17, 0x30, 0x15,
  17227. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17228. 0x03, 0x08, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17229. ret = wc_InitRsaKey(keyPub, NULL);
  17230. if (ret != 0)
  17231. return WC_TEST_RET_ENC_EC(ret);
  17232. /* Parameter Validation testing. */
  17233. ret = wc_RsaPublicKeyDecodeRaw(NULL, sizeof(n), e, sizeof(e), keyPub);
  17234. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17235. ret = WC_TEST_RET_ENC_EC(ret);
  17236. goto done;
  17237. }
  17238. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), NULL, sizeof(e), keyPub);
  17239. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17240. ret = WC_TEST_RET_ENC_EC(ret);
  17241. goto done;
  17242. }
  17243. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), NULL);
  17244. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17245. ret = WC_TEST_RET_ENC_EC(ret);
  17246. goto done;
  17247. }
  17248. ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub);
  17249. #if defined(USE_INTEGER_HEAP_MATH)
  17250. if (ret != 0)
  17251. #else
  17252. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17253. #endif
  17254. {
  17255. ret = WC_TEST_RET_ENC_EC(ret);
  17256. goto done;
  17257. }
  17258. wc_FreeRsaKey(keyPub);
  17259. ret = wc_InitRsaKey(keyPub, NULL);
  17260. if (ret != 0)
  17261. return WC_TEST_RET_ENC_EC(ret);
  17262. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub);
  17263. #if defined(USE_INTEGER_HEAP_MATH)
  17264. if (ret != 0)
  17265. #else
  17266. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17267. #endif
  17268. {
  17269. ret = WC_TEST_RET_ENC_EC(ret);
  17270. goto done;
  17271. }
  17272. wc_FreeRsaKey(keyPub);
  17273. ret = wc_InitRsaKey(keyPub, NULL);
  17274. if (ret != 0)
  17275. return WC_TEST_RET_ENC_EC(ret);
  17276. /* Use API. */
  17277. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), keyPub);
  17278. if (ret != 0) {
  17279. ret = WC_TEST_RET_ENC_EC(ret);
  17280. goto done;
  17281. }
  17282. wc_FreeRsaKey(keyPub);
  17283. ret = wc_InitRsaKey(keyPub, NULL);
  17284. if (ret != 0)
  17285. return WC_TEST_RET_ENC_EC(ret);
  17286. /* Parameter Validation testing. */
  17287. inSz = sizeof(good);
  17288. ret = wc_RsaPublicKeyDecode(NULL, &inOutIdx, keyPub, inSz);
  17289. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17290. ret = WC_TEST_RET_ENC_EC(ret);
  17291. goto done;
  17292. }
  17293. ret = wc_RsaPublicKeyDecode(good, NULL, keyPub, inSz);
  17294. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17295. ret = WC_TEST_RET_ENC_EC(ret);
  17296. goto done;
  17297. }
  17298. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  17299. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17300. ret = WC_TEST_RET_ENC_EC(ret);
  17301. goto done;
  17302. }
  17303. /* Use good data and offset to bad data. */
  17304. inOutIdx = 2;
  17305. inSz = sizeof(good) - inOutIdx;
  17306. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17307. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17308. ret = WC_TEST_RET_ENC_EC(ret);
  17309. goto done;
  17310. }
  17311. inOutIdx = 2;
  17312. inSz = sizeof(goodAlgId) - inOutIdx;
  17313. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17314. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17315. ret = WC_TEST_RET_ENC_EC(ret);
  17316. goto done;
  17317. }
  17318. inOutIdx = 2;
  17319. inSz = sizeof(goodAlgId);
  17320. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17321. #ifndef WOLFSSL_NO_DECODE_EXTRA
  17322. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17323. #else
  17324. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E))
  17325. #endif
  17326. {
  17327. ret = WC_TEST_RET_ENC_EC(ret);
  17328. goto done;
  17329. }
  17330. /* Try different bad data. */
  17331. inSz = sizeof(badAlgIdNull);
  17332. inOutIdx = 0;
  17333. ret = wc_RsaPublicKeyDecode(badAlgIdNull, &inOutIdx, keyPub, inSz);
  17334. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E)) {
  17335. ret = WC_TEST_RET_ENC_EC(ret);
  17336. goto done;
  17337. }
  17338. inSz = sizeof(badNotBitString);
  17339. inOutIdx = 0;
  17340. ret = wc_RsaPublicKeyDecode(badNotBitString, &inOutIdx, keyPub, inSz);
  17341. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E)) {
  17342. ret = WC_TEST_RET_ENC_EC(ret);
  17343. goto done;
  17344. }
  17345. inSz = sizeof(badBitStringLen);
  17346. inOutIdx = 0;
  17347. ret = wc_RsaPublicKeyDecode(badBitStringLen, &inOutIdx, keyPub, inSz);
  17348. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17349. ret = WC_TEST_RET_ENC_EC(ret);
  17350. goto done;
  17351. }
  17352. inSz = sizeof(badNoSeq);
  17353. inOutIdx = 0;
  17354. ret = wc_RsaPublicKeyDecode(badNoSeq, &inOutIdx, keyPub, inSz);
  17355. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17356. ret = WC_TEST_RET_ENC_EC(ret);
  17357. goto done;
  17358. }
  17359. inSz = sizeof(badNoObj);
  17360. inOutIdx = 0;
  17361. ret = wc_RsaPublicKeyDecode(badNoObj, &inOutIdx, keyPub, inSz);
  17362. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E) &&
  17363. ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E))
  17364. {
  17365. ret = WC_TEST_RET_ENC_EC(ret);
  17366. goto done;
  17367. }
  17368. inSz = sizeof(badIntN);
  17369. inOutIdx = 0;
  17370. ret = wc_RsaPublicKeyDecode(badIntN, &inOutIdx, keyPub, inSz);
  17371. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17372. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17373. {
  17374. ret = WC_TEST_RET_ENC_EC(ret);
  17375. goto done;
  17376. }
  17377. inSz = sizeof(badNotIntE);
  17378. inOutIdx = 0;
  17379. ret = wc_RsaPublicKeyDecode(badNotIntE, &inOutIdx, keyPub, inSz);
  17380. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17381. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17382. {
  17383. ret = WC_TEST_RET_ENC_EC(ret);
  17384. goto done;
  17385. }
  17386. /* TODO: Shouldn't pass as the sequence length is too small. */
  17387. inSz = sizeof(badLength);
  17388. inOutIdx = 0;
  17389. ret = wc_RsaPublicKeyDecode(badLength, &inOutIdx, keyPub, inSz);
  17390. #ifndef WOLFSSL_ASN_TEMPLATE
  17391. if (ret != 0)
  17392. #else
  17393. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17394. #endif
  17395. {
  17396. ret = WC_TEST_RET_ENC_EC(ret);
  17397. goto done;
  17398. }
  17399. /* TODO: Shouldn't ignore object id's data. */
  17400. wc_FreeRsaKey(keyPub);
  17401. ret = wc_InitRsaKey(keyPub, NULL);
  17402. if (ret != 0)
  17403. return WC_TEST_RET_ENC_EC(ret);
  17404. inSz = sizeof(badBitStrNoZero);
  17405. inOutIdx = 0;
  17406. ret = wc_RsaPublicKeyDecode(badBitStrNoZero, &inOutIdx, keyPub, inSz);
  17407. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  17408. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17409. {
  17410. ret = WC_TEST_RET_ENC_EC(ret);
  17411. goto done;
  17412. }
  17413. wc_FreeRsaKey(keyPub);
  17414. ret = wc_InitRsaKey(keyPub, NULL);
  17415. if (ret != 0)
  17416. return WC_TEST_RET_ENC_EC(ret);
  17417. /* Valid data cases. */
  17418. inSz = sizeof(good);
  17419. inOutIdx = 0;
  17420. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17421. if (ret != 0) {
  17422. ret = WC_TEST_RET_ENC_EC(ret);
  17423. goto done;
  17424. }
  17425. if (inOutIdx != inSz) {
  17426. ret = WC_TEST_RET_ENC_NC;
  17427. goto done;
  17428. }
  17429. wc_FreeRsaKey(keyPub);
  17430. ret = wc_InitRsaKey(keyPub, NULL);
  17431. if (ret != 0)
  17432. return WC_TEST_RET_ENC_EC(ret);
  17433. inSz = sizeof(goodAlgId);
  17434. inOutIdx = 0;
  17435. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17436. if (ret != 0) {
  17437. ret = WC_TEST_RET_ENC_EC(ret);
  17438. goto done;
  17439. }
  17440. if (inOutIdx != inSz) {
  17441. ret = WC_TEST_RET_ENC_NC;
  17442. goto done;
  17443. }
  17444. wc_FreeRsaKey(keyPub);
  17445. ret = wc_InitRsaKey(keyPub, NULL);
  17446. if (ret != 0)
  17447. return WC_TEST_RET_ENC_EC(ret);
  17448. inSz = sizeof(goodAlgIdNull);
  17449. inOutIdx = 0;
  17450. ret = wc_RsaPublicKeyDecode(goodAlgIdNull, &inOutIdx, keyPub, inSz);
  17451. if (ret != 0) {
  17452. ret = WC_TEST_RET_ENC_EC(ret);
  17453. goto done;
  17454. }
  17455. if (inOutIdx != inSz) {
  17456. ret = WC_TEST_RET_ENC_NC;
  17457. goto done;
  17458. }
  17459. done:
  17460. wc_FreeRsaKey(keyPub);
  17461. return ret;
  17462. }
  17463. #endif
  17464. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  17465. /* Need to create known good signatures to test with this. */
  17466. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  17467. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17468. static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key)
  17469. {
  17470. byte digest[WC_MAX_DIGEST_SIZE];
  17471. wc_test_ret_t ret = 0;
  17472. const char inStr[] = TEST_STRING;
  17473. word32 inLen = (word32)TEST_STRING_SZ;
  17474. word32 outSz;
  17475. word32 plainSz;
  17476. word32 digestSz;
  17477. int i, j;
  17478. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17479. int k, l;
  17480. #endif
  17481. #ifndef WOLFSSL_SE050
  17482. int len;
  17483. #endif
  17484. byte* plain;
  17485. int mgf[] = {
  17486. #ifndef NO_SHA
  17487. WC_MGF1SHA1,
  17488. #endif
  17489. #ifdef WOLFSSL_SHA224
  17490. WC_MGF1SHA224,
  17491. #endif
  17492. WC_MGF1SHA256,
  17493. #ifdef WOLFSSL_SHA384
  17494. WC_MGF1SHA384,
  17495. #endif
  17496. #ifdef WOLFSSL_SHA512
  17497. WC_MGF1SHA512
  17498. #endif
  17499. };
  17500. enum wc_HashType hash[] = {
  17501. #ifndef NO_SHA
  17502. WC_HASH_TYPE_SHA,
  17503. #endif
  17504. #ifdef WOLFSSL_SHA224
  17505. WC_HASH_TYPE_SHA224,
  17506. #endif
  17507. WC_HASH_TYPE_SHA256,
  17508. #ifdef WOLFSSL_SHA384
  17509. WC_HASH_TYPE_SHA384,
  17510. #endif
  17511. #ifdef WOLFSSL_SHA512
  17512. WC_HASH_TYPE_SHA512,
  17513. #endif
  17514. };
  17515. WC_DECLARE_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17516. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17517. WC_DECLARE_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17518. WC_ALLOC_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17519. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17520. WC_ALLOC_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17521. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17522. if (in == NULL || out == NULL || sig == NULL)
  17523. ERROR_OUT(MEMORY_E, exit_rsa_pss);
  17524. #endif
  17525. XMEMCPY(in, inStr, inLen);
  17526. /* Test all combinations of hash and MGF. */
  17527. for (j = 0; j < (int)(sizeof(hash)/sizeof(*hash)); j++) {
  17528. /* Calculate hash of message. */
  17529. ret = wc_Hash(hash[j], in, inLen, digest, sizeof(digest));
  17530. if (ret != 0)
  17531. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17532. digestSz = (word32)wc_HashGetDigestSize(hash[j]);
  17533. #ifdef WOLFSSL_SE050
  17534. /* SE050 only supports MGF matched to same hash type */
  17535. i = j;
  17536. #else
  17537. for (i = 0; i < (int)(sizeof(mgf)/sizeof(*mgf)); i++) {
  17538. #endif
  17539. outSz = RSA_TEST_BYTES;
  17540. do {
  17541. #if defined(WOLFSSL_ASYNC_CRYPT)
  17542. ret = wc_AsyncWait(ret, &key->asyncDev,
  17543. WC_ASYNC_FLAG_CALL_AGAIN);
  17544. #endif
  17545. if (ret >= 0) {
  17546. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz,
  17547. hash[j], mgf[i], -1, key, rng);
  17548. }
  17549. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17550. if (ret <= 0)
  17551. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17552. outSz = (word32)ret;
  17553. XMEMCPY(sig, out, outSz);
  17554. plain = NULL;
  17555. TEST_SLEEP();
  17556. do {
  17557. #if defined(WOLFSSL_ASYNC_CRYPT)
  17558. ret = wc_AsyncWait(ret, &key->asyncDev,
  17559. WC_ASYNC_FLAG_CALL_AGAIN);
  17560. #endif
  17561. if (ret >= 0) {
  17562. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[j],
  17563. mgf[i], -1, key);
  17564. }
  17565. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17566. if (ret <= 0)
  17567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17568. plainSz = (word32)ret;
  17569. TEST_SLEEP();
  17570. #if defined(HAVE_SELFTEST) && \
  17571. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17572. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17573. hash[j], -1);
  17574. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17575. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17576. hash[j], -1, 0);
  17577. #else
  17578. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz,
  17579. hash[j], -1, wc_RsaEncryptSize(key)*8, HEAP_HINT);
  17580. #endif
  17581. if (ret != 0)
  17582. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17583. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17584. for (k = 0; k < (int)(sizeof(mgf)/sizeof(*mgf)); k++) {
  17585. for (l = 0; l < (int)(sizeof(hash)/sizeof(*hash)); l++) {
  17586. if (i == k && j == l)
  17587. continue;
  17588. XMEMCPY(sig, out, outSz);
  17589. do {
  17590. #if defined(WOLFSSL_ASYNC_CRYPT)
  17591. ret = wc_AsyncWait(ret, &key->asyncDev,
  17592. WC_ASYNC_FLAG_CALL_AGAIN);
  17593. #endif
  17594. if (ret >= 0) {
  17595. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz,
  17596. (byte**)&plain, hash[l], mgf[k], -1, key);
  17597. }
  17598. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17599. if (ret >= 0)
  17600. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17601. }
  17602. }
  17603. #endif
  17604. #ifndef WOLFSSL_SE050
  17605. } /* end mgf for loop */
  17606. #endif
  17607. }
  17608. /* SE050 generates salts internally only of hash length */
  17609. #ifndef WOLFSSL_SE050
  17610. /* Test that a salt length of zero works. */
  17611. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17612. outSz = RSA_TEST_BYTES;
  17613. do {
  17614. #if defined(WOLFSSL_ASYNC_CRYPT)
  17615. ret = wc_AsyncWait(ret, &key->asyncDev,
  17616. WC_ASYNC_FLAG_CALL_AGAIN);
  17617. #endif
  17618. if (ret >= 0) {
  17619. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17620. mgf[0], 0, key, rng);
  17621. }
  17622. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17623. if (ret <= 0)
  17624. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17625. outSz = (word32)ret;
  17626. TEST_SLEEP();
  17627. do {
  17628. #if defined(WOLFSSL_ASYNC_CRYPT)
  17629. ret = wc_AsyncWait(ret, &key->asyncDev,
  17630. WC_ASYNC_FLAG_CALL_AGAIN);
  17631. #endif
  17632. if (ret >= 0) {
  17633. ret = wc_RsaPSS_Verify_ex(out, outSz, sig, outSz, hash[0], mgf[0],
  17634. 0, key);
  17635. }
  17636. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17637. if (ret <= 0)
  17638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17639. plainSz = (word32)ret;
  17640. TEST_SLEEP();
  17641. do {
  17642. #if defined(WOLFSSL_ASYNC_CRYPT)
  17643. ret = wc_AsyncWait(ret, &key->asyncDev,
  17644. WC_ASYNC_FLAG_CALL_AGAIN);
  17645. #endif
  17646. if (ret >= 0) {
  17647. #if defined(HAVE_SELFTEST) && \
  17648. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17649. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17650. hash[0], 0);
  17651. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17652. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17653. hash[0], 0, 0);
  17654. #else
  17655. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, sig, plainSz,
  17656. hash[0], 0, 0, HEAP_HINT);
  17657. #endif
  17658. }
  17659. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17660. if (ret != 0)
  17661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17662. XMEMCPY(sig, out, outSz);
  17663. plain = NULL;
  17664. do {
  17665. #if defined(WOLFSSL_ASYNC_CRYPT)
  17666. ret = wc_AsyncWait(ret, &key->asyncDev,
  17667. WC_ASYNC_FLAG_CALL_AGAIN);
  17668. #endif
  17669. if (ret >= 0) {
  17670. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17671. 0, key);
  17672. }
  17673. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17674. if (ret <= 0)
  17675. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17676. plainSz = (word32)ret;
  17677. TEST_SLEEP();
  17678. #if defined(HAVE_SELFTEST) && \
  17679. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17680. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17681. hash[0], 0);
  17682. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17683. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17684. hash[0], 0, 0);
  17685. #else
  17686. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17687. 0, 0, HEAP_HINT);
  17688. #endif
  17689. if (ret != 0)
  17690. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17691. /* Test bad salt lengths in various APIs. */
  17692. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17693. outSz = RSA_TEST_BYTES;
  17694. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17695. len = -2;
  17696. #else
  17697. len = -3;
  17698. #endif
  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], len, key, rng);
  17707. }
  17708. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17709. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17711. do {
  17712. #if defined(WOLFSSL_ASYNC_CRYPT)
  17713. ret = wc_AsyncWait(ret, &key->asyncDev,
  17714. WC_ASYNC_FLAG_CALL_AGAIN);
  17715. #endif
  17716. if (ret >= 0) {
  17717. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17718. mgf[0], (int)digestSz + 1, key, rng);
  17719. }
  17720. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17721. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17722. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17723. TEST_SLEEP();
  17724. do {
  17725. #if defined(WOLFSSL_ASYNC_CRYPT)
  17726. ret = wc_AsyncWait(ret, &key->asyncDev,
  17727. WC_ASYNC_FLAG_CALL_AGAIN);
  17728. #endif
  17729. if (ret >= 0) {
  17730. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0],
  17731. mgf[0], -2, key);
  17732. }
  17733. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17734. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17736. TEST_SLEEP();
  17737. do {
  17738. #if defined(WOLFSSL_ASYNC_CRYPT)
  17739. ret = wc_AsyncWait(ret, &key->asyncDev,
  17740. WC_ASYNC_FLAG_CALL_AGAIN);
  17741. #endif
  17742. if (ret >= 0) {
  17743. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17744. (int)digestSz + 1, key);
  17745. }
  17746. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17747. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17749. TEST_SLEEP();
  17750. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17751. len = -2;
  17752. #else
  17753. len = -3;
  17754. #endif
  17755. #if defined(HAVE_SELFTEST) && \
  17756. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17757. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17758. hash[0], len);
  17759. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17760. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17761. hash[0], len, 0);
  17762. #else
  17763. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17764. len, 0, HEAP_HINT);
  17765. #endif
  17766. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17767. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17768. #ifndef WOLFSSL_PSS_LONG_SALT
  17769. len = (int)(digestSz + 1);
  17770. #else
  17771. len = (int)(plainSz - digestSz - 1);
  17772. #endif
  17773. #if defined(HAVE_SELFTEST) && \
  17774. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17775. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17776. hash[0], len);
  17777. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17779. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17780. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17781. hash[0], len, 0);
  17782. if (ret != WC_NO_ERR_TRACE(BAD_PADDING_E))
  17783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17784. #else
  17785. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17786. len, 0, HEAP_HINT);
  17787. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17789. #endif
  17790. ret = 0;
  17791. #endif /* WOLFSSL_SE050 */
  17792. exit_rsa_pss:
  17793. WC_FREE_VAR(sig, HEAP_HINT);
  17794. WC_FREE_VAR(in, HEAP_HINT);
  17795. WC_FREE_VAR(out, HEAP_HINT);
  17796. return ret;
  17797. }
  17798. #endif /* !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY */
  17799. #endif
  17800. #ifdef WC_RSA_NO_PADDING
  17801. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void)
  17802. {
  17803. WC_RNG rng;
  17804. byte* tmp = NULL;
  17805. size_t bytes;
  17806. wc_test_ret_t ret;
  17807. word32 inLen = 0;
  17808. word32 idx = 0;
  17809. word32 outSz = RSA_TEST_BYTES;
  17810. word32 plainSz = RSA_TEST_BYTES;
  17811. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  17812. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  17813. !defined(NO_FILESYSTEM)
  17814. XFILE file;
  17815. #endif
  17816. WC_DECLARE_VAR(key, RsaKey, 1, HEAP_HINT);
  17817. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17818. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17819. WC_ALLOC_VAR(key, RsaKey, 1, HEAP_HINT);
  17820. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17821. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17822. WOLFSSL_ENTER("rsa_no_pad_test");
  17823. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17824. if (key == NULL || out == NULL || plain == NULL)
  17825. ERROR_OUT(MEMORY_E, exit_rsa_nopadding);
  17826. #endif
  17827. /* initialize stack structures */
  17828. XMEMSET(&rng, 0, sizeof(rng));
  17829. XMEMSET(key, 0, sizeof(RsaKey));
  17830. #ifdef USE_CERT_BUFFERS_1024
  17831. bytes = (size_t)sizeof_client_key_der_1024;
  17832. if (bytes < (size_t)sizeof_client_cert_der_1024)
  17833. bytes = (size_t)sizeof_client_cert_der_1024;
  17834. #elif defined(USE_CERT_BUFFERS_2048)
  17835. bytes = (size_t)sizeof_client_key_der_2048;
  17836. if (bytes < (size_t)sizeof_client_cert_der_2048)
  17837. bytes = (size_t)sizeof_client_cert_der_2048;
  17838. #else
  17839. bytes = FOURK_BUF;
  17840. #endif
  17841. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  17842. if (tmp == NULL
  17843. #ifdef WOLFSSL_ASYNC_CRYPT
  17844. || out == NULL || plain == NULL
  17845. #endif
  17846. ) {
  17847. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17848. }
  17849. #ifdef USE_CERT_BUFFERS_1024
  17850. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  17851. #elif defined(USE_CERT_BUFFERS_2048)
  17852. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  17853. #elif defined(USE_CERT_BUFFERS_3072)
  17854. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  17855. #elif defined(USE_CERT_BUFFERS_4096)
  17856. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  17857. #elif !defined(NO_FILESYSTEM)
  17858. file = XFOPEN(clientKey, "rb");
  17859. if (!file) {
  17860. err_sys("can't open clientKey, Please run from wolfSSL home dir",
  17861. WC_TEST_RET_ENC_ERRNO);
  17862. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17863. }
  17864. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  17865. XFCLOSE(file);
  17866. if (bytes == 0)
  17867. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17868. #else
  17869. /* No key to use. */
  17870. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17871. #endif /* USE_CERT_BUFFERS */
  17872. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  17873. if (ret != 0) {
  17874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17875. }
  17876. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  17877. if (ret != 0) {
  17878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17879. }
  17880. /* after loading in key use tmp as the test buffer */
  17881. #ifndef HAVE_FIPS
  17882. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  17883. #else
  17884. ret = wc_InitRng(&rng);
  17885. #endif
  17886. if (ret != 0) {
  17887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17888. }
  17889. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17890. inLen = (word32)wc_RsaEncryptSize(key);
  17891. outSz = inLen;
  17892. plainSz = inLen;
  17893. XMEMSET(tmp, 7, inLen);
  17894. do {
  17895. #if defined(WOLFSSL_ASYNC_CRYPT)
  17896. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17897. #endif
  17898. if (ret >= 0) {
  17899. ret = wc_RsaDirect(tmp, inLen, out, &outSz, key,
  17900. RSA_PRIVATE_ENCRYPT, &rng);
  17901. }
  17902. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17903. if (ret <= 0) {
  17904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17905. }
  17906. /* encrypted result should not be the same as input */
  17907. if (XMEMCMP(out, tmp, inLen) == 0) {
  17908. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17909. }
  17910. TEST_SLEEP();
  17911. /* decrypt with public key and compare result */
  17912. do {
  17913. #if defined(WOLFSSL_ASYNC_CRYPT)
  17914. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17915. #endif
  17916. if (ret >= 0) {
  17917. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key,
  17918. RSA_PUBLIC_DECRYPT, &rng);
  17919. }
  17920. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17921. if (ret <= 0) {
  17922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17923. }
  17924. if (XMEMCMP(plain, tmp, inLen) != 0) {
  17925. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17926. }
  17927. TEST_SLEEP();
  17928. #endif
  17929. #ifdef WC_RSA_BLINDING
  17930. ret = wc_RsaSetRNG(NULL, &rng);
  17931. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17932. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17933. }
  17934. ret = wc_RsaSetRNG(key, &rng);
  17935. if (ret < 0) {
  17936. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17937. }
  17938. #endif
  17939. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  17940. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17941. do {
  17942. #if defined(WOLFSSL_ASYNC_CRYPT)
  17943. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17944. #endif
  17945. if (ret >= 0) {
  17946. ret = wc_RsaPublicEncrypt_ex(tmp, inLen, out, outSz, key, &rng,
  17947. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  17948. }
  17949. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17950. if (ret < 0) {
  17951. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17952. }
  17953. TEST_SLEEP();
  17954. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  17955. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  17956. do {
  17957. #if defined(WOLFSSL_ASYNC_CRYPT)
  17958. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17959. #endif
  17960. if (ret >= 0) {
  17961. ret = wc_RsaPrivateDecrypt_ex(out, outSz, plain, plainSz, key,
  17962. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  17963. }
  17964. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17965. if (ret < 0) {
  17966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17967. }
  17968. if (XMEMCMP(plain, tmp, inLen) != 0) {
  17969. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17970. }
  17971. TEST_SLEEP();
  17972. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  17973. /* test some bad arguments */
  17974. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key, -1,
  17975. &rng);
  17976. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17977. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17978. }
  17979. ret = wc_RsaDirect(out, outSz, plain, &plainSz, NULL, RSA_PUBLIC_DECRYPT,
  17980. &rng);
  17981. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17982. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17983. }
  17984. ret = wc_RsaDirect(out, outSz, NULL, &plainSz, key, RSA_PUBLIC_DECRYPT,
  17985. &rng);
  17986. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || plainSz != inLen) {
  17987. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17988. }
  17989. ret = wc_RsaDirect(out, outSz - 10, plain, &plainSz, key,
  17990. RSA_PUBLIC_DECRYPT, &rng);
  17991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17992. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17993. }
  17994. /* if making it to this point of code without hitting an ERROR_OUT then
  17995. * all tests have passed */
  17996. ret = 0;
  17997. exit_rsa_nopadding:
  17998. wc_FreeRsaKey(key);
  17999. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18000. WC_FREE_VAR(key, HEAP_HINT);
  18001. WC_FREE_VAR(out, HEAP_HINT);
  18002. WC_FREE_VAR(plain, HEAP_HINT);
  18003. wc_FreeRng(&rng);
  18004. return ret;
  18005. }
  18006. #endif /* WC_RSA_NO_PADDING */
  18007. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  18008. static wc_test_ret_t rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
  18009. {
  18010. byte* tmp = NULL;
  18011. size_t bytes;
  18012. wc_test_ret_t ret;
  18013. word32 inLen = 0;
  18014. #ifndef NO_ASN
  18015. word32 idx = 0;
  18016. #endif
  18017. word32 outSz = RSA_TEST_BYTES;
  18018. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18019. word32 plainSz = RSA_TEST_BYTES;
  18020. #endif
  18021. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_3072) && \
  18022. !defined(USE_CERT_BUFFERS_4096) && !defined(NO_FILESYSTEM)
  18023. XFILE file;
  18024. #endif
  18025. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18026. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18027. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18028. #endif
  18029. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18030. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18031. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18032. #endif
  18033. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18034. if (out == NULL
  18035. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18036. || plain == NULL
  18037. #endif
  18038. ) {
  18039. ERROR_OUT(MEMORY_E, exit_rsa_even_mod);
  18040. }
  18041. #endif
  18042. #if defined(USE_CERT_BUFFERS_2048)
  18043. bytes = (size_t)sizeof_client_key_der_2048;
  18044. if (bytes < (size_t)sizeof_client_cert_der_2048)
  18045. bytes = (size_t)sizeof_client_cert_der_2048;
  18046. #else
  18047. bytes = FOURK_BUF;
  18048. #endif
  18049. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18050. if (tmp == NULL
  18051. #ifdef WOLFSSL_ASYNC_CRYPT
  18052. || out == NULL || plain == NULL
  18053. #endif
  18054. ) {
  18055. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18056. }
  18057. #if defined(USE_CERT_BUFFERS_2048)
  18058. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  18059. #elif defined(USE_CERT_BUFFERS_3072)
  18060. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  18061. #elif defined(USE_CERT_BUFFERS_4096)
  18062. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  18063. #elif !defined(NO_FILESYSTEM)
  18064. file = XFOPEN(clientKey, "rb");
  18065. if (!file) {
  18066. err_sys("can't open ./certs/client-key.der, "
  18067. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  18068. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18069. }
  18070. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  18071. XFCLOSE(file);
  18072. if (bytes == 0)
  18073. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18074. #else
  18075. /* No key to use. */
  18076. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18077. #endif /* USE_CERT_BUFFERS */
  18078. #ifndef NO_ASN
  18079. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  18080. if (ret != 0) {
  18081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18082. }
  18083. #else
  18084. #ifdef USE_CERT_BUFFERS_2048
  18085. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  18086. if (ret != 0) {
  18087. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18088. }
  18089. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  18090. if (ret != 0) {
  18091. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18092. }
  18093. #ifndef NO_SIG_WRAPPER
  18094. modLen = 2048;
  18095. #endif
  18096. #else
  18097. #error Not supported yet!
  18098. #endif
  18099. #endif
  18100. key->n.dp[0] &= (mp_digit)-2;
  18101. if (ret != 0) {
  18102. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18103. }
  18104. /* after loading in key use tmp as the test buffer */
  18105. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  18106. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM))) && \
  18107. !defined(WOLFSSL_XILINX_CRYPT)
  18108. /* The ARM64_ASM code that was FIPS validated did not return these expected
  18109. * failure codes. These tests cases were added after the assembly was
  18110. * in-lined in the module and validated, these tests will be available in
  18111. * the 140-3 module */
  18112. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18113. inLen = 32;
  18114. outSz = wc_RsaEncryptSize(key);
  18115. XMEMSET(tmp, 7, plainSz);
  18116. ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng);
  18117. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18118. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18119. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18120. {
  18121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18122. }
  18123. ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key);
  18124. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18125. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18126. {
  18127. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18128. }
  18129. #endif
  18130. #ifdef WC_RSA_BLINDING
  18131. ret = wc_RsaSetRNG(key, rng);
  18132. if (ret < 0) {
  18133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18134. }
  18135. #endif
  18136. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18137. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18138. ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
  18139. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18140. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18141. {
  18142. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18143. }
  18144. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18145. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18146. ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key);
  18147. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18148. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18149. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18150. {
  18151. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18152. }
  18153. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18154. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  18155. /* if making it to this point of code without hitting an ERROR_OUT then
  18156. * all tests have passed */
  18157. ret = 0;
  18158. exit_rsa_even_mod:
  18159. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18160. WC_FREE_VAR(out, HEAP_HINT);
  18161. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18162. WC_FREE_VAR(plain, HEAP_HINT);
  18163. #endif
  18164. (void)out;
  18165. (void)outSz;
  18166. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18167. (void)plain;
  18168. (void)plainSz;
  18169. #endif
  18170. (void)inLen;
  18171. (void)rng;
  18172. return ret;
  18173. }
  18174. #endif /* WOLFSSL_HAVE_SP_RSA */
  18175. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME)
  18176. static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp)
  18177. {
  18178. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18179. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18180. #ifdef WOLFSSL_TEST_CERT
  18181. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18182. #endif
  18183. #else
  18184. RsaKey caKey[1];
  18185. #ifdef WOLFSSL_TEST_CERT
  18186. DecodedCert decode[1];
  18187. #endif
  18188. #endif
  18189. byte* der = NULL;
  18190. wc_test_ret_t ret;
  18191. Cert* myCert = NULL;
  18192. int certSz;
  18193. size_t bytes3;
  18194. word32 idx3 = 0;
  18195. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  18196. XFILE file3;
  18197. #endif
  18198. #if defined(WOLFSSL_ALT_NAMES) && !defined(NO_ASN_TIME)
  18199. struct tm beforeTime;
  18200. struct tm afterTime;
  18201. #endif
  18202. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  18203. (void)keypub;
  18204. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18205. if (caKey == NULL)
  18206. ERROR_OUT(MEMORY_E, exit_rsa);
  18207. #ifdef WOLFSSL_TEST_CERT
  18208. if (decode == NULL)
  18209. ERROR_OUT(MEMORY_E, exit_rsa);
  18210. #endif
  18211. #endif
  18212. XMEMSET(caKey, 0, sizeof *caKey);
  18213. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18214. if (der == NULL) {
  18215. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18216. }
  18217. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18218. if (myCert == NULL) {
  18219. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18220. }
  18221. /* self signed */
  18222. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18223. if (ret != 0) {
  18224. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18225. }
  18226. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18227. XMEMCPY(myCert->serial, mySerial, sizeof(mySerial));
  18228. myCert->serialSz = (int)sizeof(mySerial);
  18229. myCert->isCA = 1;
  18230. #ifndef NO_SHA256
  18231. myCert->sigType = CTC_SHA256wRSA;
  18232. #else
  18233. myCert->sigType = CTC_SHAwRSA;
  18234. #endif
  18235. #ifdef WOLFSSL_CERT_EXT
  18236. /* add Policies */
  18237. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18238. CTC_MAX_CERTPOL_SZ);
  18239. XSTRNCPY(myCert->certPolicies[1], "1.2.840.113549.1.9.16.6.5",
  18240. CTC_MAX_CERTPOL_SZ);
  18241. myCert->certPoliciesNb = 2;
  18242. /* add SKID from the Public Key */
  18243. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL);
  18244. if (ret != 0) {
  18245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18246. }
  18247. /* add AKID from the Public Key */
  18248. ret = wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL);
  18249. if (ret != 0) {
  18250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18251. }
  18252. /* add Key Usage */
  18253. ret = wc_SetKeyUsage(myCert,"cRLSign,keyCertSign");
  18254. if (ret != 0) {
  18255. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18256. }
  18257. #ifdef WOLFSSL_EKU_OID
  18258. {
  18259. const char unique[] = "2.16.840.1.111111.100.1.10.1";
  18260. ret = wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0,
  18261. HEAP_HINT);
  18262. if (ret != 0) {
  18263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18264. }
  18265. }
  18266. #endif /* WOLFSSL_EKU_OID */
  18267. #endif /* WOLFSSL_CERT_EXT */
  18268. do {
  18269. #if defined(WOLFSSL_ASYNC_CRYPT)
  18270. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18271. #endif
  18272. if (ret >= 0) {
  18273. ret = wc_MakeSelfCert(myCert, der, FOURK_BUF, key, rng);
  18274. }
  18275. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18276. if (ret < 0) {
  18277. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18278. }
  18279. certSz = (int)ret;
  18280. #ifdef WOLFSSL_TEST_CERT
  18281. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18282. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18283. if (ret != 0) {
  18284. FreeDecodedCert(decode);
  18285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18286. }
  18287. FreeDecodedCert(decode);
  18288. #endif
  18289. ret = SaveDerAndPem(der, certSz, certDerFile, certPemFile,
  18290. CERT_TYPE);
  18291. if (ret != 0) {
  18292. goto exit_rsa;
  18293. }
  18294. /* Setup Certificate */
  18295. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18296. if (ret < 0) {
  18297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18298. }
  18299. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  18300. /* Get CA Cert for testing */
  18301. #ifdef USE_CERT_BUFFERS_1024
  18302. XMEMCPY(tmp, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  18303. bytes3 = sizeof_ca_cert_der_1024;
  18304. #elif defined(USE_CERT_BUFFERS_2048)
  18305. XMEMCPY(tmp, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  18306. bytes3 = sizeof_ca_cert_der_2048;
  18307. #else
  18308. file3 = XFOPEN(rsaCaCertDerFile, "rb");
  18309. if (!file3) {
  18310. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18311. }
  18312. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18313. XFCLOSE(file3);
  18314. if (bytes3 == 0)
  18315. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18316. #endif /* USE_CERT_BUFFERS */
  18317. #if defined(WOLFSSL_ALT_NAMES)
  18318. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \
  18319. !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  18320. ret = wc_SetAltNames(myCert, rsaCaCertFile);
  18321. if (ret != 0)
  18322. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18323. #endif
  18324. /* get alt names from der */
  18325. ret = wc_SetAltNamesBuffer(myCert, tmp, (int)bytes3);
  18326. if (ret != 0)
  18327. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18328. /* get dates from der */
  18329. ret = wc_SetDatesBuffer(myCert, tmp, (int)bytes3);
  18330. if (ret != 0)
  18331. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18332. #ifndef NO_ASN_TIME
  18333. ret = wc_GetCertDates(myCert, &beforeTime, &afterTime);
  18334. if (ret < 0)
  18335. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18336. #endif
  18337. #endif /* WOLFSSL_ALT_NAMES */
  18338. #endif /* WOLFSSL_ALT_NAMES || HAVE_PKCS7 */
  18339. /* Get CA Key */
  18340. #ifdef USE_CERT_BUFFERS_1024
  18341. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18342. bytes3 = sizeof_ca_key_der_1024;
  18343. #elif defined(USE_CERT_BUFFERS_2048)
  18344. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18345. bytes3 = sizeof_ca_key_der_2048;
  18346. #else
  18347. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18348. if (!file3) {
  18349. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18350. }
  18351. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18352. XFCLOSE(file3);
  18353. if (bytes3 == 0)
  18354. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18355. #endif /* USE_CERT_BUFFERS */
  18356. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18357. if (ret != 0)
  18358. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18359. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18360. if (ret != 0)
  18361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18362. #ifndef NO_SHA256
  18363. myCert->sigType = CTC_SHA256wRSA;
  18364. #else
  18365. myCert->sigType = CTC_SHAwRSA;
  18366. #endif
  18367. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18368. #ifdef WOLFSSL_CERT_EXT
  18369. /* add Policies */
  18370. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18371. CTC_MAX_CERTPOL_SZ);
  18372. myCert->certPoliciesNb =1;
  18373. /* add SKID from the Public Key */
  18374. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL);
  18375. if (ret != 0)
  18376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18377. /* add AKID from the CA certificate */
  18378. #if defined(USE_CERT_BUFFERS_2048)
  18379. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18380. sizeof_ca_cert_der_2048);
  18381. #elif defined(USE_CERT_BUFFERS_1024)
  18382. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18383. sizeof_ca_cert_der_1024);
  18384. #else
  18385. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18386. #endif
  18387. if (ret != 0)
  18388. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18389. /* add Key Usage */
  18390. ret = wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement");
  18391. if (ret != 0)
  18392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18393. #endif /* WOLFSSL_CERT_EXT */
  18394. #if defined(USE_CERT_BUFFERS_2048)
  18395. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18396. sizeof_ca_cert_der_2048);
  18397. #elif defined(USE_CERT_BUFFERS_1024)
  18398. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18399. sizeof_ca_cert_der_1024);
  18400. #else
  18401. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18402. #endif
  18403. if (ret < 0)
  18404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18405. certSz = wc_MakeCert(myCert, der, FOURK_BUF, key, NULL, rng);
  18406. if (certSz < 0) {
  18407. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18408. }
  18409. ret = 0;
  18410. do {
  18411. #if defined(WOLFSSL_ASYNC_CRYPT)
  18412. ret = wc_AsyncWait(ret, &caKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18413. #endif
  18414. if (ret >= 0) {
  18415. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der, FOURK_BUF,
  18416. caKey, NULL, rng);
  18417. }
  18418. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18419. if (ret < 0)
  18420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18421. certSz = (int)ret;
  18422. #ifdef WOLFSSL_TEST_CERT
  18423. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18424. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18425. if (ret != 0) {
  18426. FreeDecodedCert(decode);
  18427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18428. }
  18429. FreeDecodedCert(decode);
  18430. #endif
  18431. ret = SaveDerAndPem(der, certSz, otherCertDerFile, otherCertPemFile,
  18432. CERT_TYPE);
  18433. if (ret != 0) {
  18434. goto exit_rsa;
  18435. }
  18436. exit_rsa:
  18437. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18438. if (caKey != NULL) {
  18439. wc_FreeRsaKey(caKey);
  18440. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18441. }
  18442. #ifdef WOLFSSL_TEST_CERT
  18443. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18444. #endif
  18445. #else
  18446. wc_FreeRsaKey(caKey);
  18447. #endif
  18448. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18449. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18450. return ret;
  18451. }
  18452. #endif
  18453. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP) && \
  18454. defined(WOLFSSL_CERT_GEN)
  18455. /* Make Cert / Sign example for ECC cert and RSA CA */
  18456. static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
  18457. {
  18458. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18459. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18460. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18461. ecc_key *caEccKeyPub = (ecc_key *)XMALLOC(sizeof *caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18462. #ifdef WOLFSSL_TEST_CERT
  18463. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18464. #endif
  18465. #else
  18466. RsaKey caKey[1];
  18467. ecc_key caEccKey[1];
  18468. ecc_key caEccKeyPub[1];
  18469. #ifdef WOLFSSL_TEST_CERT
  18470. DecodedCert decode[1];
  18471. #endif
  18472. #endif
  18473. byte* der = NULL;
  18474. Cert* myCert = NULL;
  18475. int certSz;
  18476. size_t bytes3;
  18477. word32 idx3 = 0;
  18478. #if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
  18479. || !defined(USE_CERT_BUFFERS_256)
  18480. #ifndef NO_FILESYSTEM
  18481. XFILE file3;
  18482. #endif
  18483. #endif
  18484. wc_test_ret_t ret;
  18485. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18486. if ((caKey == NULL) || (caEccKey == NULL) || (caEccKeyPub == NULL)
  18487. #ifdef WOLFSSL_TEST_CERT
  18488. || (decode == NULL)
  18489. #endif
  18490. )
  18491. ERROR_OUT(MEMORY_E, exit_rsa);
  18492. #endif
  18493. XMEMSET(caKey, 0, sizeof *caKey);
  18494. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  18495. XMEMSET(caEccKeyPub, 0, sizeof *caEccKeyPub);
  18496. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18497. if (der == NULL) {
  18498. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18499. }
  18500. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18501. if (myCert == NULL) {
  18502. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18503. }
  18504. /* Get CA Key */
  18505. #ifdef USE_CERT_BUFFERS_1024
  18506. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18507. bytes3 = sizeof_ca_key_der_1024;
  18508. #elif defined(USE_CERT_BUFFERS_2048)
  18509. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18510. bytes3 = sizeof_ca_key_der_2048;
  18511. #else
  18512. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18513. if (!file3) {
  18514. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18515. }
  18516. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18517. XFCLOSE(file3);
  18518. if (bytes3 == 0)
  18519. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18520. #endif /* USE_CERT_BUFFERS */
  18521. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18522. if (ret != 0)
  18523. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18524. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18525. if (ret != 0)
  18526. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18527. /* Get Cert Key */
  18528. #if defined(USE_CERT_BUFFERS_256)
  18529. {
  18530. XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
  18531. bytes3 = sizeof_ecc_key_pub_der_256;
  18532. }
  18533. #elif !defined(NO_FILESYSTEM)
  18534. {
  18535. file3 = XFOPEN(eccKeyPubFileDer, "rb");
  18536. if (!file3) {
  18537. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18538. }
  18539. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18540. XFCLOSE(file3);
  18541. if (bytes3 == 0)
  18542. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18543. }
  18544. #else
  18545. {
  18546. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
  18547. ERROR_OUT(ASN_PARSE_E, exit_rsa);
  18548. }
  18549. #endif
  18550. ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
  18551. if (ret != 0)
  18552. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18553. idx3 = 0;
  18554. ret = wc_EccPublicKeyDecode(tmp, &idx3, caEccKeyPub, (word32)bytes3);
  18555. if (ret != 0)
  18556. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18557. /* Setup Certificate */
  18558. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18559. if (ret != 0)
  18560. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18561. #ifndef NO_SHA256
  18562. myCert->sigType = CTC_SHA256wRSA;
  18563. #else
  18564. myCert->sigType = CTC_SHAwRSA;
  18565. #endif
  18566. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18567. #ifdef WOLFSSL_CERT_EXT
  18568. /* add Policies */
  18569. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  18570. CTC_MAX_CERTPOL_SZ);
  18571. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  18572. CTC_MAX_CERTPOL_SZ);
  18573. myCert->certPoliciesNb = 2;
  18574. /* add SKID from the Public Key */
  18575. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub);
  18576. if (ret != 0)
  18577. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18578. /* add AKID from the CA certificate */
  18579. #if defined(USE_CERT_BUFFERS_2048)
  18580. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18581. sizeof_ca_cert_der_2048);
  18582. #elif defined(USE_CERT_BUFFERS_1024)
  18583. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18584. sizeof_ca_cert_der_1024);
  18585. #else
  18586. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18587. #endif
  18588. if (ret != 0)
  18589. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18590. /* add Key Usage */
  18591. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  18592. if (ret != 0)
  18593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18594. #endif /* WOLFSSL_CERT_EXT */
  18595. #if defined(USE_CERT_BUFFERS_2048)
  18596. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18597. sizeof_ca_cert_der_2048);
  18598. #elif defined(USE_CERT_BUFFERS_1024)
  18599. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18600. sizeof_ca_cert_der_1024);
  18601. #else
  18602. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18603. #endif
  18604. if (ret < 0)
  18605. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18606. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, caEccKeyPub, rng);
  18607. if (certSz < 0) {
  18608. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18609. }
  18610. ret = 0;
  18611. do {
  18612. #if defined(WOLFSSL_ASYNC_CRYPT)
  18613. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18614. #endif
  18615. if (ret >= 0) {
  18616. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  18617. FOURK_BUF, caKey, NULL, rng);
  18618. }
  18619. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18620. if (ret < 0)
  18621. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18622. certSz = (int)ret;
  18623. #ifdef WOLFSSL_TEST_CERT
  18624. InitDecodedCert(decode, der, certSz, 0);
  18625. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18626. if (ret != 0) {
  18627. FreeDecodedCert(decode);
  18628. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18629. }
  18630. FreeDecodedCert(decode);
  18631. #endif
  18632. ret = SaveDerAndPem(der, certSz, certEccRsaDerFile, certEccRsaPemFile,
  18633. CERT_TYPE);
  18634. if (ret != 0) {
  18635. goto exit_rsa;
  18636. }
  18637. exit_rsa:
  18638. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18639. if (caKey != NULL) {
  18640. wc_FreeRsaKey(caKey);
  18641. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18642. }
  18643. if (caEccKey != NULL) {
  18644. wc_ecc_free(caEccKey);
  18645. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18646. }
  18647. if (caEccKeyPub != NULL) {
  18648. wc_ecc_free(caEccKeyPub);
  18649. XFREE(caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18650. }
  18651. #ifdef WOLFSSL_TEST_CERT
  18652. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18653. #endif
  18654. #else
  18655. wc_FreeRsaKey(caKey);
  18656. wc_ecc_free(caEccKey);
  18657. wc_ecc_free(caEccKeyPub);
  18658. #endif
  18659. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18660. myCert = NULL;
  18661. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18662. der = NULL;
  18663. if (ret >= 0)
  18664. ret = 0;
  18665. return ret;
  18666. }
  18667. #endif /* !NO_RSA && HAVE_ECC && WOLFSSL_CERT_GEN */
  18668. #ifdef WOLFSSL_KEY_GEN
  18669. static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
  18670. {
  18671. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18672. RsaKey *genKey = (RsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18673. #else
  18674. RsaKey genKey[1];
  18675. #endif
  18676. wc_test_ret_t ret;
  18677. #ifndef WOLFSSL_NO_MALLOC
  18678. byte* der = NULL;
  18679. #else
  18680. byte der[1280];
  18681. #endif
  18682. #ifndef WOLFSSL_CRYPTOCELL
  18683. word32 idx = 0;
  18684. #endif
  18685. int derSz = 0;
  18686. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FIPS) && \
  18687. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18688. int keySz = 1024;
  18689. #else
  18690. int keySz = 2048;
  18691. #endif
  18692. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18693. if (! genKey)
  18694. ERROR_OUT(MEMORY_E, exit_rsa);
  18695. #endif
  18696. XMEMSET(genKey, 0, sizeof *genKey);
  18697. ret = wc_InitRsaKey_ex(genKey, HEAP_HINT, devId);
  18698. if (ret != 0)
  18699. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18700. #ifdef HAVE_FIPS
  18701. for (;;) {
  18702. #endif
  18703. ret = wc_MakeRsaKey(genKey, keySz, WC_RSA_EXPONENT, rng);
  18704. #if defined(WOLFSSL_ASYNC_CRYPT)
  18705. ret = wc_AsyncWait(ret, &genKey->asyncDev, WC_ASYNC_FLAG_NONE);
  18706. #endif
  18707. #ifdef HAVE_FIPS
  18708. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  18709. continue;
  18710. break;
  18711. }
  18712. #endif
  18713. if (ret != 0)
  18714. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18715. TEST_SLEEP();
  18716. #ifdef WOLFSSL_RSA_KEY_CHECK
  18717. ret = wc_CheckRsaKey(genKey);
  18718. if (ret != 0)
  18719. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18720. #endif
  18721. #ifndef WOLFSSL_NO_MALLOC
  18722. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18723. if (der == NULL) {
  18724. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18725. }
  18726. derSz = FOURK_BUF;
  18727. #else
  18728. derSz = sizeof(der);
  18729. #endif
  18730. derSz = wc_RsaKeyToDer(genKey, der, derSz);
  18731. if (derSz < 0) {
  18732. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  18733. }
  18734. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  18735. PRIVATEKEY_TYPE);
  18736. if (ret != 0) {
  18737. goto exit_rsa;
  18738. }
  18739. wc_FreeRsaKey(genKey);
  18740. ret = wc_InitRsaKey(genKey, HEAP_HINT);
  18741. if (ret != 0)
  18742. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18743. #ifndef WOLFSSL_CRYPTOCELL
  18744. idx = 0;
  18745. /* The private key part of the key gen pairs from cryptocell can't be exported */
  18746. ret = wc_RsaPrivateKeyDecode(der, &idx, genKey, (word32)derSz);
  18747. if (ret != 0)
  18748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18749. #endif /* WOLFSSL_CRYPTOCELL */
  18750. exit_rsa:
  18751. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18752. if (genKey) {
  18753. wc_FreeRsaKey(genKey);
  18754. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18755. }
  18756. #else
  18757. wc_FreeRsaKey(genKey);
  18758. #endif
  18759. #ifndef WOLFSSL_NO_MALLOC
  18760. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18761. der = NULL;
  18762. #endif
  18763. return ret;
  18764. }
  18765. #endif
  18766. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18767. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) && \
  18768. (!defined(HAVE_FIPS) || \
  18769. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  18770. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  18771. static wc_test_ret_t rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng)
  18772. {
  18773. wc_test_ret_t ret = 0;
  18774. word32 idx = 0;
  18775. const char inStr[] = TEST_STRING;
  18776. const word32 inLen = (word32)TEST_STRING_SZ;
  18777. const word32 outSz = RSA_TEST_BYTES;
  18778. const word32 plainSz = RSA_TEST_BYTES;
  18779. byte* res = NULL;
  18780. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18781. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18782. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18783. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18784. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18785. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18786. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18787. if (in == NULL || out == NULL || plain == NULL)
  18788. ERROR_OUT(MEMORY_E, exit_rsa);
  18789. #endif
  18790. XMEMCPY(in, inStr, inLen);
  18791. #ifndef NO_SHA
  18792. do {
  18793. #if defined(WOLFSSL_ASYNC_CRYPT)
  18794. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18795. #endif
  18796. if (ret >= 0) {
  18797. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18798. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18799. }
  18800. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18801. if (ret < 0)
  18802. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18803. TEST_SLEEP();
  18804. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18805. idx = (word32)ret;
  18806. do {
  18807. #if defined(WOLFSSL_ASYNC_CRYPT)
  18808. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18809. #endif
  18810. if (ret >= 0) {
  18811. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18812. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18813. }
  18814. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18815. if (ret < 0)
  18816. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18817. if (XMEMCMP(plain, in, inLen)) {
  18818. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18819. }
  18820. TEST_SLEEP();
  18821. #endif /* NO_SHA */
  18822. #endif
  18823. #ifndef NO_SHA256
  18824. XMEMSET(plain, 0, plainSz);
  18825. do {
  18826. #if defined(WOLFSSL_ASYNC_CRYPT)
  18827. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18828. #endif
  18829. if (ret >= 0) {
  18830. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18831. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18832. }
  18833. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18834. if (ret < 0)
  18835. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18836. TEST_SLEEP();
  18837. idx = (word32)ret;
  18838. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18839. do {
  18840. #if defined(WOLFSSL_ASYNC_CRYPT)
  18841. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18842. #endif
  18843. if (ret >= 0) {
  18844. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18845. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18846. }
  18847. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18848. if (ret < 0)
  18849. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18850. if (XMEMCMP(plain, in, inLen)) {
  18851. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18852. }
  18853. TEST_SLEEP();
  18854. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18855. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18856. do {
  18857. #if defined(WOLFSSL_ASYNC_CRYPT)
  18858. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18859. #endif
  18860. if (ret >= 0) {
  18861. ret = wc_RsaPrivateDecryptInline_ex(out, idx, &res, key,
  18862. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18863. }
  18864. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18865. if (ret < 0)
  18866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18867. if (ret != (int)inLen) {
  18868. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18869. }
  18870. if (XMEMCMP(res, in, inLen)) {
  18871. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18872. }
  18873. TEST_SLEEP();
  18874. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18875. /* check fails if not using the same optional label */
  18876. XMEMSET(plain, 0, plainSz);
  18877. do {
  18878. #if defined(WOLFSSL_ASYNC_CRYPT)
  18879. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18880. #endif
  18881. if (ret >= 0) {
  18882. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18883. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18884. }
  18885. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18886. if (ret < 0)
  18887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18888. TEST_SLEEP();
  18889. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18890. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18891. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18892. /* label is unused in cryptocell and SE050 so it won't detect decrypt error
  18893. * due to label */
  18894. idx = (word32)ret;
  18895. do {
  18896. #if defined(WOLFSSL_ASYNC_CRYPT)
  18897. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18898. #endif
  18899. if (ret >= 0) {
  18900. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18901. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18902. }
  18903. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18904. if (ret > 0) { /* in this case decrypt should fail */
  18905. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18906. }
  18907. ret = 0;
  18908. TEST_SLEEP();
  18909. #endif /* !HAVE_CAVIUM */
  18910. /* check using optional label with encrypt/decrypt */
  18911. XMEMSET(plain, 0, plainSz);
  18912. do {
  18913. #if defined(WOLFSSL_ASYNC_CRYPT)
  18914. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18915. #endif
  18916. if (ret >= 0) {
  18917. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18918. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18919. }
  18920. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18921. if (ret < 0)
  18922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18923. TEST_SLEEP();
  18924. idx = (word32)ret;
  18925. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18926. do {
  18927. #if defined(WOLFSSL_ASYNC_CRYPT)
  18928. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18929. #endif
  18930. if (ret >= 0) {
  18931. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18932. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18933. }
  18934. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18935. if (ret < 0)
  18936. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18937. if (XMEMCMP(plain, in, inLen)) {
  18938. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18939. }
  18940. TEST_SLEEP();
  18941. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18942. #ifndef NO_SHA
  18943. /* check fail using mismatch hash algorithms */
  18944. XMEMSET(plain, 0, plainSz);
  18945. do {
  18946. #if defined(WOLFSSL_ASYNC_CRYPT)
  18947. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18948. #endif
  18949. if (ret >= 0) {
  18950. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18951. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, in, inLen);
  18952. }
  18953. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18954. if (ret < 0)
  18955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18956. TEST_SLEEP();
  18957. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18958. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18959. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18960. idx = (word32)ret;
  18961. do {
  18962. #if defined(WOLFSSL_ASYNC_CRYPT)
  18963. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18964. #endif
  18965. if (ret >= 0) {
  18966. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18967. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256,
  18968. in, inLen);
  18969. }
  18970. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18971. if (ret > 0) { /* should fail */
  18972. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18973. }
  18974. ret = 0;
  18975. TEST_SLEEP();
  18976. #endif /* !HAVE_CAVIUM */
  18977. #endif /* NO_SHA */
  18978. #endif /* NO_SHA256 */
  18979. #ifdef WOLFSSL_SHA512
  18980. /* Check valid RSA key size is used while using hash length of SHA512
  18981. If key size is less than (hash length * 2) + 2 then is invalid use
  18982. and test, since OAEP padding requires this.
  18983. BAD_FUNC_ARG is returned when this case is not met */
  18984. if (wc_RsaEncryptSize(key) > ((int)WC_SHA512_DIGEST_SIZE * 2) + 2) {
  18985. XMEMSET(plain, 0, plainSz);
  18986. do {
  18987. #if defined(WOLFSSL_ASYNC_CRYPT)
  18988. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18989. #endif
  18990. if (ret >= 0) {
  18991. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18992. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  18993. }
  18994. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18995. if (ret < 0)
  18996. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18997. TEST_SLEEP();
  18998. idx = (word32)ret;
  18999. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19000. do {
  19001. #if defined(WOLFSSL_ASYNC_CRYPT)
  19002. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19003. #endif
  19004. if (ret >= 0) {
  19005. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19006. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19007. }
  19008. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19009. if (ret < 0)
  19010. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19011. if (XMEMCMP(plain, in, inLen)) {
  19012. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19013. }
  19014. TEST_SLEEP();
  19015. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19016. }
  19017. #endif /* WOLFSSL_SHA512 */
  19018. /* check using pkcsv15 padding with _ex API */
  19019. XMEMSET(plain, 0, plainSz);
  19020. do {
  19021. #if defined(WOLFSSL_ASYNC_CRYPT)
  19022. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19023. #endif
  19024. if (ret >= 0) {
  19025. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19026. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19027. }
  19028. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19029. if (ret < 0)
  19030. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19031. TEST_SLEEP();
  19032. idx = (word32)ret;
  19033. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19034. do {
  19035. #if defined(WOLFSSL_ASYNC_CRYPT)
  19036. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19037. #endif
  19038. if (ret >= 0) {
  19039. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19040. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19041. }
  19042. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19043. if (ret < 0)
  19044. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19045. if (XMEMCMP(plain, in, inLen)) {
  19046. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19047. }
  19048. TEST_SLEEP();
  19049. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19050. exit_rsa:
  19051. WC_FREE_VAR(in, HEAP_HINT);
  19052. WC_FREE_VAR(out, HEAP_HINT);
  19053. WC_FREE_VAR(plain, HEAP_HINT);
  19054. (void)idx;
  19055. (void)inStr;
  19056. (void)res;
  19057. if (ret >= 0)
  19058. ret = 0;
  19059. return ret;
  19060. }
  19061. #endif
  19062. #endif
  19063. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
  19064. {
  19065. wc_test_ret_t ret;
  19066. size_t bytes;
  19067. WC_RNG rng;
  19068. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19069. byte* tmp = NULL;
  19070. byte* der = NULL;
  19071. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19072. #else
  19073. RsaKey key[1];
  19074. byte tmp[FOURK_BUF];
  19075. #endif
  19076. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19077. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19078. RsaKey *keypub = (RsaKey *)XMALLOC(sizeof *keypub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19079. #else
  19080. RsaKey keypub[1];
  19081. #endif
  19082. #endif
  19083. word32 idx = 0;
  19084. const char inStr[] = TEST_STRING;
  19085. const word32 inLen = (word32)TEST_STRING_SZ;
  19086. const word32 outSz = RSA_TEST_BYTES;
  19087. const word32 plainSz = RSA_TEST_BYTES;
  19088. byte* res = NULL;
  19089. #ifndef NO_SIG_WRAPPER
  19090. int modLen;
  19091. #endif
  19092. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19093. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  19094. !defined(NO_FILESYSTEM)
  19095. XFILE file;
  19096. #ifdef WOLFSSL_TEST_CERT
  19097. XFILE file2;
  19098. #endif
  19099. #endif
  19100. #ifdef WOLFSSL_TEST_CERT
  19101. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19102. DecodedCert *cert = (DecodedCert *)XMALLOC(sizeof *cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19103. #else
  19104. DecodedCert cert[1];
  19105. #endif
  19106. #ifndef NO_ASN_TIME
  19107. struct tm timearg;
  19108. const byte* date;
  19109. byte dateFormat;
  19110. int dateLength;
  19111. #endif
  19112. #endif
  19113. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19114. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19115. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19116. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19117. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19118. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19119. WOLFSSL_ENTER("rsa_test");
  19120. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  19121. if (in == NULL || out == NULL || plain == NULL)
  19122. ERROR_OUT(MEMORY_E, exit_rsa);
  19123. #endif
  19124. XMEMCPY(in, inStr, inLen);
  19125. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19126. if (key == NULL)
  19127. ERROR_OUT(MEMORY_E, exit_rsa);
  19128. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19129. if (keypub == NULL)
  19130. ERROR_OUT(MEMORY_E, exit_rsa);
  19131. #endif
  19132. #ifdef WOLFSSL_TEST_CERT
  19133. if (cert == NULL)
  19134. ERROR_OUT(MEMORY_E, exit_rsa);
  19135. #endif
  19136. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19137. /* initialize stack structures */
  19138. XMEMSET(&rng, 0, sizeof(rng));
  19139. XMEMSET(key, 0, sizeof *key);
  19140. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19141. XMEMSET(keypub, 0, sizeof *keypub);
  19142. #endif
  19143. #if !defined(NO_ASN)
  19144. ret = rsa_decode_test(key);
  19145. if (ret != 0)
  19146. ERROR_OUT(ret, exit_rsa);
  19147. #endif
  19148. #ifdef USE_CERT_BUFFERS_1024
  19149. bytes = (size_t)sizeof_client_key_der_1024;
  19150. if (bytes < (size_t)sizeof_client_cert_der_1024)
  19151. bytes = (size_t)sizeof_client_cert_der_1024;
  19152. #elif defined(USE_CERT_BUFFERS_2048)
  19153. bytes = (size_t)sizeof_client_key_der_2048;
  19154. if (bytes < (size_t)sizeof_client_cert_der_2048)
  19155. bytes = (size_t)sizeof_client_cert_der_2048;
  19156. #elif defined(USE_CERT_BUFFERS_3072)
  19157. bytes = (size_t)sizeof_client_key_der_3072;
  19158. if (bytes < (size_t)sizeof_client_cert_der_3072)
  19159. bytes = (size_t)sizeof_client_cert_der_3072;
  19160. #elif defined(USE_CERT_BUFFERS_4096)
  19161. bytes = (size_t)sizeof_client_key_der_4096;
  19162. if (bytes < (size_t)sizeof_client_cert_der_4096)
  19163. bytes = (size_t)sizeof_client_cert_der_4096;
  19164. #else
  19165. bytes = FOURK_BUF;
  19166. #endif
  19167. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19168. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19169. if (tmp == NULL)
  19170. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19171. #endif
  19172. #ifdef USE_CERT_BUFFERS_1024
  19173. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  19174. #elif defined(USE_CERT_BUFFERS_2048)
  19175. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  19176. #elif defined(USE_CERT_BUFFERS_3072)
  19177. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  19178. #elif defined(USE_CERT_BUFFERS_4096)
  19179. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  19180. #elif !defined(NO_FILESYSTEM)
  19181. file = XFOPEN(clientKey, "rb");
  19182. if (!file) {
  19183. err_sys("can't open ./certs/client-key.der, "
  19184. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19185. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19186. }
  19187. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19188. XFCLOSE(file);
  19189. if (bytes == 0)
  19190. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19191. #else
  19192. /* No key to use. */
  19193. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19194. #endif /* USE_CERT_BUFFERS */
  19195. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19196. if (ret != 0)
  19197. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19198. #ifndef NO_ASN
  19199. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  19200. if (ret != 0)
  19201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19202. #ifndef NO_SIG_WRAPPER
  19203. modLen = wc_RsaEncryptSize(key);
  19204. #endif
  19205. #else
  19206. #ifdef USE_CERT_BUFFERS_2048
  19207. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  19208. if (ret != 0)
  19209. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19210. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  19211. if (ret != 0)
  19212. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19213. #ifndef NO_SIG_WRAPPER
  19214. modLen = 2048;
  19215. #endif
  19216. #else
  19217. #error Not supported yet!
  19218. #endif
  19219. #endif
  19220. #ifndef WC_NO_RNG
  19221. #ifndef HAVE_FIPS
  19222. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  19223. #else
  19224. ret = wc_InitRng(&rng);
  19225. #endif
  19226. if (ret != 0)
  19227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19228. #endif
  19229. #ifndef NO_SIG_WRAPPER
  19230. ret = rsa_sig_test(key, sizeof *key, modLen, &rng);
  19231. if (ret != 0)
  19232. goto exit_rsa;
  19233. #endif
  19234. #ifdef WC_RSA_NONBLOCK
  19235. ret = rsa_nb_test(key, in, inLen, out, outSz, plain, plainSz, &rng);
  19236. if (ret != 0)
  19237. goto exit_rsa;
  19238. #endif
  19239. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19240. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19241. do {
  19242. #if defined(WOLFSSL_ASYNC_CRYPT)
  19243. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19244. #endif
  19245. if (ret >= 0) {
  19246. ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, key, &rng);
  19247. }
  19248. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19249. if (ret < 0)
  19250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19251. TEST_SLEEP();
  19252. #ifdef WC_RSA_BLINDING
  19253. {
  19254. wc_test_ret_t tmpret = ret;
  19255. ret = wc_RsaSetRNG(key, &rng);
  19256. if (ret < 0)
  19257. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19258. ret = tmpret;
  19259. }
  19260. #endif
  19261. idx = (word32)ret; /* save off encrypted length */
  19262. do {
  19263. #if defined(WOLFSSL_ASYNC_CRYPT)
  19264. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19265. #endif
  19266. if (ret >= 0) {
  19267. ret = wc_RsaPrivateDecrypt(out, idx, plain, plainSz, key);
  19268. }
  19269. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19270. if (ret < 0)
  19271. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19272. if (XMEMCMP(plain, in, inLen)) {
  19273. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19274. }
  19275. TEST_SLEEP();
  19276. do {
  19277. #if defined(WOLFSSL_ASYNC_CRYPT)
  19278. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19279. #endif
  19280. if (ret >= 0) {
  19281. ret = wc_RsaPrivateDecryptInline(out, idx, &res, key);
  19282. }
  19283. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19284. if (ret < 0)
  19285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19286. if (ret != (int)inLen) {
  19287. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19288. }
  19289. if (XMEMCMP(res, in, inLen)) {
  19290. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19291. }
  19292. TEST_SLEEP();
  19293. do {
  19294. #if defined(WOLFSSL_ASYNC_CRYPT)
  19295. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19296. #endif
  19297. if (ret >= 0) {
  19298. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng);
  19299. }
  19300. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19301. if (ret < 0)
  19302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19303. TEST_SLEEP();
  19304. #elif defined(WOLFSSL_PUBLIC_MP)
  19305. {
  19306. static const byte signature_2048[] = {
  19307. 0x07, 0x6f, 0xc9, 0x85, 0x73, 0x9e, 0x21, 0x79,
  19308. 0x47, 0xf1, 0xa3, 0xd7, 0xf4, 0x27, 0x29, 0xbe,
  19309. 0x99, 0x5d, 0xac, 0xb2, 0x10, 0x3f, 0x95, 0xda,
  19310. 0x89, 0x23, 0xb8, 0x96, 0x13, 0x57, 0x72, 0x30,
  19311. 0xa1, 0xfe, 0x5a, 0x68, 0x9c, 0x99, 0x9d, 0x1e,
  19312. 0x05, 0xa4, 0x80, 0xb0, 0xbb, 0xd9, 0xd9, 0xa1,
  19313. 0x69, 0x97, 0x74, 0xb3, 0x41, 0x21, 0x3b, 0x47,
  19314. 0xf5, 0x51, 0xb1, 0xfb, 0xc7, 0xaa, 0xcc, 0xdc,
  19315. 0xcd, 0x76, 0xa0, 0x28, 0x4d, 0x27, 0x14, 0xa4,
  19316. 0xb9, 0x41, 0x68, 0x7c, 0xb3, 0x66, 0xe6, 0x6f,
  19317. 0x40, 0x76, 0xe4, 0x12, 0xfd, 0xae, 0x29, 0xb5,
  19318. 0x63, 0x60, 0x87, 0xce, 0x49, 0x6b, 0xf3, 0x05,
  19319. 0x9a, 0x14, 0xb5, 0xcc, 0xcd, 0xf7, 0x30, 0x95,
  19320. 0xd2, 0x72, 0x52, 0x1d, 0x5b, 0x7e, 0xef, 0x4a,
  19321. 0x02, 0x96, 0x21, 0x6c, 0x55, 0xa5, 0x15, 0xb1,
  19322. 0x57, 0x63, 0x2c, 0xa3, 0x8e, 0x9d, 0x3d, 0x45,
  19323. 0xcc, 0xb8, 0xe6, 0xa1, 0xc8, 0x59, 0xcd, 0xf5,
  19324. 0xdc, 0x0a, 0x51, 0xb6, 0x9d, 0xfb, 0xf4, 0x6b,
  19325. 0xfd, 0x32, 0x71, 0x6e, 0xcf, 0xcb, 0xb3, 0xd9,
  19326. 0xe0, 0x4a, 0x77, 0x34, 0xd6, 0x61, 0xf5, 0x7c,
  19327. 0xf9, 0xa9, 0xa4, 0xb0, 0x8e, 0x3b, 0xd6, 0x04,
  19328. 0xe0, 0xde, 0x2b, 0x5b, 0x5a, 0xbf, 0xd9, 0xef,
  19329. 0x8d, 0xa3, 0xf5, 0xb1, 0x67, 0xf3, 0xb9, 0x72,
  19330. 0x0a, 0x37, 0x12, 0x35, 0x6c, 0x8e, 0x10, 0x8b,
  19331. 0x38, 0x06, 0x16, 0x4b, 0x20, 0x20, 0x13, 0x00,
  19332. 0x2e, 0x6d, 0xc2, 0x59, 0x23, 0x67, 0x4a, 0x6d,
  19333. 0xa1, 0x46, 0x8b, 0xee, 0xcf, 0x44, 0xb4, 0x3e,
  19334. 0x56, 0x75, 0x00, 0x68, 0xb5, 0x7d, 0x0f, 0x20,
  19335. 0x79, 0x5d, 0x7f, 0x12, 0x15, 0x32, 0x89, 0x61,
  19336. 0x6b, 0x29, 0xb7, 0x52, 0xf5, 0x25, 0xd8, 0x98,
  19337. 0xe8, 0x6f, 0xf9, 0x22, 0xb4, 0xbb, 0xe5, 0xff,
  19338. 0xd0, 0x92, 0x86, 0x9a, 0x88, 0xa2, 0xaf, 0x6b
  19339. };
  19340. ret = sizeof(signature_2048);
  19341. XMEMCPY(out, signature_2048, ret);
  19342. }
  19343. #endif
  19344. #if !defined(WC_NO_RNG) && !defined(WC_NO_RSA_OAEP) && \
  19345. ((!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  19346. defined(WOLFSSL_PUBLIC_MP)) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19347. idx = (word32)ret;
  19348. XMEMSET(plain, 0, plainSz);
  19349. do {
  19350. #if defined(WOLFSSL_ASYNC_CRYPT)
  19351. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19352. #endif
  19353. if (ret >= 0) {
  19354. #ifndef WOLFSSL_RSA_VERIFY_INLINE
  19355. #if defined(WOLFSSL_CRYPTOCELL)
  19356. /*
  19357. Cryptocell requires the input data and signature byte array to verify.
  19358. first argument must be the input data
  19359. second argument must be the length of input data
  19360. third argument must be the signature byte array or the output from
  19361. wc_RsaSSL_Sign()
  19362. fourth argument must be the length of the signature byte array
  19363. */
  19364. ret = wc_RsaSSL_Verify(in, inLen, out, outSz, key);
  19365. #else
  19366. ret = wc_RsaSSL_Verify(out, idx, plain, plainSz, key);
  19367. #endif /* WOLFSSL_CRYPTOCELL */
  19368. #else
  19369. byte* dec = NULL;
  19370. ret = wc_RsaSSL_VerifyInline(out, idx, &dec, key);
  19371. if (ret > 0) {
  19372. XMEMCPY(plain, dec, ret);
  19373. }
  19374. #endif
  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 (XMEMCMP(plain, in, (size_t)ret)) {
  19380. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19381. }
  19382. TEST_SLEEP();
  19383. #endif
  19384. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  19385. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG)
  19386. #if (!defined(HAVE_FIPS) || \
  19387. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  19388. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19389. ret = rsa_oaep_padding_test(key, &rng);
  19390. if (ret != 0)
  19391. return ret;
  19392. #endif /* !HAVE_FIPS */
  19393. #endif /* WC_NO_RSA_OAEP && !WC_NO_RNG */
  19394. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  19395. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  19396. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19397. ret = rsa_export_key_test(key);
  19398. if (ret != 0)
  19399. return ret;
  19400. #endif
  19401. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19402. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19403. ret = rsa_flatten_test(key);
  19404. if (ret != 0)
  19405. return ret;
  19406. #endif
  19407. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_ASN) && \
  19408. !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19409. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  19410. (void)clientCert;
  19411. #endif
  19412. #ifdef WOLFSSL_TEST_CERT
  19413. #if defined(WOLFSSL_MDK_ARM)
  19414. #define sizeof(s) XSTRLEN((char *)(s))
  19415. #endif
  19416. #ifdef USE_CERT_BUFFERS_1024
  19417. XMEMCPY(tmp, client_cert_der_1024, (size_t)sizeof_client_cert_der_1024);
  19418. bytes = (size_t)sizeof_client_cert_der_1024;
  19419. #elif defined(USE_CERT_BUFFERS_2048)
  19420. XMEMCPY(tmp, client_cert_der_2048, (size_t)sizeof_client_cert_der_2048);
  19421. bytes = (size_t)sizeof_client_cert_der_2048;
  19422. #elif defined(USE_CERT_BUFFERS_3072)
  19423. XMEMCPY(tmp, client_cert_der_3072, (size_t)sizeof_client_cert_der_3072);
  19424. bytes = (size_t)sizeof_client_cert_der_3072;
  19425. #elif defined(USE_CERT_BUFFERS_4096)
  19426. XMEMCPY(tmp, client_cert_der_4096, (size_t)sizeof_client_cert_der_4096);
  19427. bytes = (size_t)sizeof_client_cert_der_4096;
  19428. #elif !defined(NO_FILESYSTEM)
  19429. file2 = XFOPEN(clientCert, "rb");
  19430. if (!file2) {
  19431. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19432. }
  19433. bytes = XFREAD(tmp, 1, FOURK_BUF, file2);
  19434. XFCLOSE(file2);
  19435. if (bytes == 0)
  19436. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19437. #else
  19438. /* No certificate to use. */
  19439. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19440. #endif
  19441. #ifdef sizeof
  19442. #undef sizeof
  19443. #endif
  19444. InitDecodedCert(cert, tmp, (word32)bytes, NULL);
  19445. ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL);
  19446. if (ret != 0) {
  19447. FreeDecodedCert(cert);
  19448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19449. }
  19450. #ifndef NO_ASN_TIME
  19451. ret = wc_GetDateInfo(cert->afterDate, cert->afterDateLen, &date,
  19452. &dateFormat, &dateLength);
  19453. if (ret != 0) {
  19454. FreeDecodedCert(cert);
  19455. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19456. }
  19457. ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg);
  19458. if (ret != 0) {
  19459. FreeDecodedCert(cert);
  19460. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19461. }
  19462. #endif
  19463. FreeDecodedCert(cert);
  19464. #endif /* WOLFSSL_TEST_CERT */
  19465. #ifdef WOLFSSL_CERT_EXT
  19466. #ifdef USE_CERT_BUFFERS_1024
  19467. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  19468. bytes = sizeof_client_keypub_der_1024;
  19469. #elif defined(USE_CERT_BUFFERS_2048)
  19470. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  19471. bytes = sizeof_client_keypub_der_2048;
  19472. #elif defined(USE_CERT_BUFFERS_3072)
  19473. XMEMCPY(tmp, client_keypub_der_3072, sizeof_client_keypub_der_3072);
  19474. bytes = sizeof_client_keypub_der_3072;
  19475. #elif defined(USE_CERT_BUFFERS_4096)
  19476. XMEMCPY(tmp, client_keypub_der_4096, sizeof_client_keypub_der_4096);
  19477. bytes = sizeof_client_keypub_der_4096;
  19478. #else
  19479. file = XFOPEN(clientKeyPub, "rb");
  19480. if (!file) {
  19481. err_sys("can't open ./certs/client-keyPub.der, "
  19482. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19483. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19484. }
  19485. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19486. XFCLOSE(file);
  19487. if (bytes == 0)
  19488. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19489. #endif /* USE_CERT_BUFFERS */
  19490. ret = wc_InitRsaKey(keypub, HEAP_HINT);
  19491. if (ret != 0)
  19492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19493. idx = 0;
  19494. ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
  19495. if (ret != 0)
  19496. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19497. #endif /* WOLFSSL_CERT_EXT */
  19498. #ifdef WOLFSSL_KEY_GEN
  19499. ret = rsa_keygen_test(&rng);
  19500. if (ret != 0)
  19501. goto exit_rsa;
  19502. #endif
  19503. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME)
  19504. /* Make Cert / Sign example for RSA cert and RSA CA */
  19505. ret = rsa_certgen_test(key, keypub, &rng, tmp);
  19506. if (ret != 0)
  19507. goto exit_rsa;
  19508. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP)
  19509. ret = rsa_ecc_certgen_test(&rng, tmp);
  19510. if (ret != 0)
  19511. goto exit_rsa;
  19512. #endif
  19513. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  19514. {
  19515. Cert *req;
  19516. int derSz;
  19517. #ifndef WOLFSSL_SMALL_STACK
  19518. byte* der = NULL;
  19519. #endif
  19520. req = (Cert *)XMALLOC(sizeof *req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19521. if (! req)
  19522. ERROR_OUT(MEMORY_E, exit_rsa);
  19523. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,DYNAMIC_TYPE_TMP_BUFFER);
  19524. if (der == NULL) {
  19525. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19526. }
  19527. ret = wc_InitCert_ex(req, HEAP_HINT, devId);
  19528. if (ret != 0)
  19529. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19530. req->version = 0;
  19531. req->isCA = 1;
  19532. XSTRNCPY(req->challengePw, "wolf123", CTC_NAME_SIZE);
  19533. XMEMCPY(&req->subject, &certDefaultName, sizeof(CertName));
  19534. #ifndef NO_SHA256
  19535. req->sigType = CTC_SHA256wRSA;
  19536. #else
  19537. req->sigType = CTC_SHAwRSA;
  19538. #endif
  19539. #ifdef WOLFSSL_CERT_EXT
  19540. /* add SKID from the Public Key */
  19541. ret = wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL);
  19542. if (ret != 0)
  19543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19544. /* add Key Usage */
  19545. ret = wc_SetKeyUsage(req, certKeyUsage2);
  19546. if (ret != 0)
  19547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19548. /* add Extended Key Usage */
  19549. ret = wc_SetExtKeyUsage(req,
  19550. "serverAuth,clientAuth,codeSigning,"
  19551. "emailProtection,timeStamping,OCSPSigning");
  19552. if (ret != 0)
  19553. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19554. #ifdef WOLFSSL_EKU_OID
  19555. {
  19556. WOLFSSL_SMALL_STACK_STATIC const char unique[] =
  19557. "2.16.840.1.111111.100.1.10.1";
  19558. ret = wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0,
  19559. HEAP_HINT);
  19560. if (ret != 0)
  19561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19562. }
  19563. #endif /* WOLFSSL_EKU_OID */
  19564. #endif /* WOLFSSL_CERT_EXT */
  19565. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19566. if (derSz < 0) {
  19567. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19568. }
  19569. #ifdef WOLFSSL_CERT_EXT
  19570. /* Try again with "any" flag set, will override all others */
  19571. ret = wc_SetExtKeyUsage(req, "any");
  19572. if (ret != 0)
  19573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19574. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19575. if (derSz < 0) {
  19576. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19577. }
  19578. #endif /* WOLFSSL_CERT_EXT */
  19579. ret = 0;
  19580. do {
  19581. #if defined(WOLFSSL_ASYNC_CRYPT)
  19582. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19583. #endif
  19584. if (ret >= 0) {
  19585. ret = wc_SignCert(req->bodySz, req->sigType, der, FOURK_BUF,
  19586. key, NULL, &rng);
  19587. }
  19588. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19589. if (ret < 0)
  19590. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19591. derSz = (int)ret;
  19592. ret = SaveDerAndPem(der, derSz, certReqDerFile, certReqPemFile,
  19593. CERTREQ_TYPE);
  19594. if (ret != 0) {
  19595. goto exit_rsa;
  19596. }
  19597. derSz = wc_MakeCertReq_ex(req, der, FOURK_BUF, RSA_TYPE, key);
  19598. if (derSz < 0) {
  19599. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19600. }
  19601. /* Test getting the size of the buffer without providing the buffer.
  19602. * derSz is set to the "largest buffer" we are willing to allocate. */
  19603. derSz = wc_MakeCertReq(req, NULL, 10000, key, NULL);
  19604. if (derSz < 0) {
  19605. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19606. }
  19607. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19608. XFREE(req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19609. der = NULL;
  19610. }
  19611. #endif /* WOLFSSL_CERT_REQ */
  19612. #endif /* WOLFSSL_CERT_GEN */
  19613. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  19614. /* Need to create known good signatures to test with this. */
  19615. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19616. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19617. ret = rsa_pss_test(&rng, key);
  19618. if (ret != 0)
  19619. goto exit_rsa;
  19620. #endif
  19621. #endif
  19622. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  19623. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19624. /* New key to be loaded in rsa_even_mod_test(). */
  19625. if (key != NULL)
  19626. #endif
  19627. wc_FreeRsaKey(key);
  19628. /* New key to be loaded in rsa_even_mod_test(). */
  19629. ret = rsa_even_mod_test(&rng, key);
  19630. #endif
  19631. exit_rsa:
  19632. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19633. if (key != NULL) {
  19634. wc_FreeRsaKey(key);
  19635. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19636. }
  19637. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19638. if (keypub != NULL) {
  19639. wc_FreeRsaKey(keypub);
  19640. XFREE(keypub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19641. }
  19642. #endif
  19643. #ifdef WOLFSSL_TEST_CERT
  19644. XFREE(cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19645. #endif
  19646. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19647. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19648. #else
  19649. wc_FreeRsaKey(key);
  19650. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19651. wc_FreeRsaKey(keypub);
  19652. #endif
  19653. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19654. wc_FreeRng(&rng);
  19655. WC_FREE_VAR(in, HEAP_HINT);
  19656. WC_FREE_VAR(out, HEAP_HINT);
  19657. WC_FREE_VAR(plain, HEAP_HINT);
  19658. (void)res;
  19659. (void)bytes;
  19660. (void)idx;
  19661. (void)in;
  19662. (void)out;
  19663. (void)plain;
  19664. (void)idx;
  19665. (void)inStr;
  19666. (void)inLen;
  19667. (void)outSz;
  19668. (void)plainSz;
  19669. /* ret can be greater then 0 with certgen but all negative values should
  19670. * be returned and treated as an error */
  19671. if (ret >= 0) {
  19672. return 0;
  19673. }
  19674. else {
  19675. return ret;
  19676. }
  19677. }
  19678. #endif /* !NO_RSA */
  19679. #ifndef NO_DH
  19680. static wc_test_ret_t dh_fips_generate_test(WC_RNG *rng)
  19681. {
  19682. wc_test_ret_t ret = 0;
  19683. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19684. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19685. #else
  19686. DhKey key[1];
  19687. #endif
  19688. WOLFSSL_SMALL_STACK_STATIC const byte p[] = {
  19689. 0xc5, 0x7c, 0xa2, 0x4f, 0x4b, 0xd6, 0x8c, 0x3c,
  19690. 0xda, 0xc7, 0xba, 0xaa, 0xea, 0x2e, 0x5c, 0x1e,
  19691. 0x18, 0xb2, 0x7b, 0x8c, 0x55, 0x65, 0x9f, 0xea,
  19692. 0xe0, 0xa1, 0x36, 0x53, 0x2b, 0x36, 0xe0, 0x4e,
  19693. 0x3e, 0x64, 0xa9, 0xe4, 0xfc, 0x8f, 0x32, 0x62,
  19694. 0x97, 0xe4, 0xbe, 0xf7, 0xc1, 0xde, 0x07, 0x5a,
  19695. 0x89, 0x28, 0xf3, 0xfe, 0x4f, 0xfe, 0x68, 0xbc,
  19696. 0xfb, 0x0a, 0x7c, 0xa4, 0xb3, 0x14, 0x48, 0x89,
  19697. 0x9f, 0xaf, 0xb8, 0x43, 0xe2, 0xa0, 0x62, 0x5c,
  19698. 0xb4, 0x88, 0x3f, 0x06, 0x50, 0x11, 0xfe, 0x65,
  19699. 0x8d, 0x49, 0xd2, 0xf5, 0x4b, 0x74, 0x79, 0xdb,
  19700. 0x06, 0x62, 0x92, 0x89, 0xed, 0xda, 0xcb, 0x87,
  19701. 0x37, 0x16, 0xd2, 0xa1, 0x7a, 0xe8, 0xde, 0x92,
  19702. 0xee, 0x3e, 0x41, 0x4a, 0x91, 0x5e, 0xed, 0xf3,
  19703. 0x6c, 0x6b, 0x7e, 0xfd, 0x15, 0x92, 0x18, 0xfc,
  19704. 0xa7, 0xac, 0x42, 0x85, 0x57, 0xe9, 0xdc, 0xda,
  19705. 0x55, 0xc9, 0x8b, 0x28, 0x9e, 0xc1, 0xc4, 0x46,
  19706. 0x4d, 0x88, 0xed, 0x62, 0x8e, 0xdb, 0x3f, 0xb9,
  19707. 0xd7, 0xc8, 0xe3, 0xcf, 0xb8, 0x34, 0x2c, 0xd2,
  19708. 0x6f, 0x28, 0x06, 0x41, 0xe3, 0x66, 0x8c, 0xfc,
  19709. 0x72, 0xff, 0x26, 0x3b, 0x6b, 0x6c, 0x6f, 0x73,
  19710. 0xde, 0xf2, 0x90, 0x29, 0xe0, 0x61, 0x32, 0xc4,
  19711. 0x12, 0x74, 0x09, 0x52, 0xec, 0xf3, 0x1b, 0xa6,
  19712. 0x45, 0x98, 0xac, 0xf9, 0x1c, 0x65, 0x8e, 0x3a,
  19713. 0x91, 0x84, 0x4b, 0x23, 0x8a, 0xb2, 0x3c, 0xc9,
  19714. 0xfa, 0xea, 0xf1, 0x38, 0xce, 0xd8, 0x05, 0xe0,
  19715. 0xfa, 0x44, 0x68, 0x1f, 0xeb, 0xd9, 0x57, 0xb8,
  19716. 0x4a, 0x97, 0x5b, 0x88, 0xc5, 0xf1, 0xbb, 0xb0,
  19717. 0x49, 0xc3, 0x91, 0x7c, 0xd3, 0x13, 0xb9, 0x47,
  19718. 0xbb, 0x91, 0x8f, 0xe5, 0x26, 0x07, 0xab, 0xa9,
  19719. 0xc5, 0xd0, 0x3d, 0x95, 0x41, 0x26, 0x92, 0x9d,
  19720. 0x13, 0x67, 0xf2, 0x7e, 0x11, 0x88, 0xdc, 0x2d
  19721. };
  19722. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  19723. 0x4a, 0x1a, 0xf3, 0xa4, 0x92, 0xe9, 0xee, 0x74,
  19724. 0x6e, 0x57, 0xd5, 0x8c, 0x2c, 0x5b, 0x41, 0x41,
  19725. 0x5e, 0xd4, 0x55, 0x19, 0xdc, 0xd9, 0x32, 0x91,
  19726. 0xf7, 0xfd, 0xc2, 0x57, 0xff, 0x03, 0x14, 0xdb,
  19727. 0xf1, 0xb7, 0x60, 0x0c, 0x43, 0x59, 0x3f, 0xff,
  19728. 0xac, 0xf1, 0x80, 0x9a, 0x15, 0x6f, 0xd8, 0x6e,
  19729. 0xb7, 0x85, 0x18, 0xc8, 0xec, 0x4e, 0x59, 0x4a,
  19730. 0xe2, 0x91, 0x43, 0x4c, 0xeb, 0x95, 0xb6, 0x2e,
  19731. 0x9a, 0xea, 0x53, 0x68, 0x80, 0x64, 0x69, 0x40,
  19732. 0xf9, 0xec, 0xbd, 0x85, 0x89, 0x26, 0x97, 0x67,
  19733. 0xaf, 0xb0, 0xad, 0x00, 0x1b, 0xd4, 0xfd, 0x94,
  19734. 0xd3, 0xe9, 0x92, 0xb1, 0xb4, 0xbc, 0x5a, 0xaa,
  19735. 0x92, 0x80, 0x89, 0x3b, 0x39, 0x05, 0x6c, 0x22,
  19736. 0x26, 0xfe, 0x5a, 0x28, 0x6c, 0x37, 0x50, 0x5a,
  19737. 0x38, 0x99, 0xcf, 0xf3, 0xc1, 0x96, 0x45, 0xdc,
  19738. 0x01, 0xcb, 0x20, 0x87, 0xa5, 0x00, 0x8c, 0xf5,
  19739. 0x4d, 0xc2, 0xef, 0xb8, 0x9b, 0xd1, 0x87, 0xbe,
  19740. 0xed, 0xd5, 0x0a, 0x29, 0x15, 0x34, 0x59, 0x4c,
  19741. 0x3a, 0x05, 0x22, 0x05, 0x44, 0x4f, 0x9f, 0xc8,
  19742. 0x47, 0x12, 0x24, 0x8e, 0xa8, 0x79, 0xe4, 0x67,
  19743. 0xba, 0x4d, 0x5b, 0x75, 0x56, 0x95, 0xeb, 0xe8,
  19744. 0x8a, 0xfa, 0x8e, 0x01, 0x8c, 0x1b, 0x74, 0x63,
  19745. 0xd9, 0x2f, 0xf7, 0xd3, 0x44, 0x8f, 0xa8, 0xf5,
  19746. 0xaf, 0x6c, 0x4f, 0xdb, 0xe7, 0xc9, 0x6c, 0x71,
  19747. 0x22, 0xa3, 0x1d, 0xf1, 0x40, 0xb2, 0xe0, 0x9a,
  19748. 0xb6, 0x72, 0xc9, 0xc0, 0x13, 0x16, 0xa2, 0x4a,
  19749. 0xe1, 0x92, 0xc7, 0x54, 0x23, 0xab, 0x9d, 0xa1,
  19750. 0xa1, 0xe5, 0x0b, 0xed, 0xba, 0xe8, 0x84, 0x37,
  19751. 0xb2, 0xe7, 0xfe, 0x32, 0x8d, 0xfa, 0x1c, 0x53,
  19752. 0x77, 0x97, 0xc7, 0xf3, 0x48, 0xc9, 0xdb, 0x2d,
  19753. 0x75, 0x52, 0x9d, 0x42, 0x51, 0x78, 0x62, 0x68,
  19754. 0x05, 0x45, 0x15, 0xf8, 0xa2, 0x4e, 0xf3, 0x0b
  19755. };
  19756. WOLFSSL_SMALL_STACK_STATIC const byte q[] = {
  19757. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19758. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19759. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19760. 0x40, 0x52, 0xed, 0x41
  19761. };
  19762. WOLFSSL_SMALL_STACK_STATIC const byte q0[] = {
  19763. 0x00,
  19764. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19765. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19766. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19767. 0x40, 0x52, 0xed, 0x41
  19768. };
  19769. byte priv[256];
  19770. byte pub[256];
  19771. word32 privSz = sizeof(priv);
  19772. word32 pubSz = sizeof(pub);
  19773. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19774. if (key == NULL)
  19775. ERROR_OUT(MEMORY_E, exit_gen_test);
  19776. #endif
  19777. /* Parameter Validation testing. */
  19778. ret = wc_DhGenerateKeyPair(NULL, rng, priv, &privSz, pub, &pubSz);
  19779. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19781. ret = wc_DhGenerateKeyPair(key, NULL, priv, &privSz, pub, &pubSz);
  19782. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19784. ret = wc_DhGenerateKeyPair(key, rng, NULL, &privSz, pub, &pubSz);
  19785. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19786. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19787. ret = wc_DhGenerateKeyPair(key, rng, priv, NULL, pub, &pubSz);
  19788. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19790. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, NULL, &pubSz);
  19791. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19793. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, NULL);
  19794. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19795. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19796. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19797. if (ret != 0)
  19798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19799. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q0, sizeof(q0));
  19800. if (ret != 0)
  19801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19802. wc_FreeDhKey(key);
  19803. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19804. if (ret != 0)
  19805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19806. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q, sizeof(q));
  19807. if (ret != 0)
  19808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19809. /* Use API. */
  19810. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19811. #if defined(WOLFSSL_ASYNC_CRYPT)
  19812. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19813. #endif
  19814. if (ret != 0)
  19815. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19816. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q0, sizeof(q0));
  19817. if (ret != 0)
  19818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19819. wc_FreeDhKey(key);
  19820. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19821. if (ret != 0)
  19822. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19823. ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
  19824. if (ret != 0)
  19825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19826. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q, sizeof(q));
  19827. if (ret != 0)
  19828. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19829. #ifndef HAVE_SELFTEST
  19830. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19831. if (ret != 0)
  19832. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19833. /* Taint the public key so the check fails. */
  19834. pub[0]++;
  19835. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19836. if (ret != WC_NO_ERR_TRACE(MP_CMP_E)) {
  19837. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19838. }
  19839. #ifdef WOLFSSL_KEY_GEN
  19840. wc_FreeDhKey(key);
  19841. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19842. if (ret != 0)
  19843. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19844. ret = wc_DhGenerateParams(rng, 2048, key);
  19845. if (ret != 0)
  19846. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19847. privSz = sizeof(priv);
  19848. pubSz = sizeof(pub);
  19849. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19850. #if defined(WOLFSSL_ASYNC_CRYPT)
  19851. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19852. #endif
  19853. if (ret != 0)
  19854. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19855. #endif /* WOLFSSL_KEY_GEN */
  19856. #endif /* HAVE_SELFTEST */
  19857. ret = 0;
  19858. exit_gen_test:
  19859. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19860. if (key) {
  19861. wc_FreeDhKey(key);
  19862. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19863. }
  19864. #else
  19865. wc_FreeDhKey(key);
  19866. #endif
  19867. return ret;
  19868. }
  19869. static wc_test_ret_t dh_generate_test(WC_RNG *rng)
  19870. {
  19871. wc_test_ret_t ret = 0;
  19872. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19873. DhKey *smallKey = NULL;
  19874. #else
  19875. DhKey smallKey[1];
  19876. #endif
  19877. byte p[2] = { 1, 7 }; /* 263 in decimal */
  19878. byte g[2] = { 0, 2 };
  19879. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19880. #ifdef WOLFSSL_DH_CONST
  19881. /* the table for constant DH lookup will round to the lowest byte size 21 */
  19882. byte priv[21];
  19883. byte pub[21];
  19884. #else
  19885. byte priv[2];
  19886. byte pub[2];
  19887. #endif
  19888. word32 privSz = sizeof(priv);
  19889. word32 pubSz = sizeof(pub);
  19890. #endif
  19891. int smallKey_inited = 0;
  19892. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19893. if ((smallKey = (DhKey *)XMALLOC(sizeof(*smallKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  19894. return WC_TEST_RET_ENC_ERRNO;
  19895. #endif
  19896. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19897. if (ret != 0)
  19898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19899. smallKey_inited = 1;
  19900. /* Parameter Validation testing. */
  19901. ret = wc_InitDhKey_ex(NULL, HEAP_HINT, devId);
  19902. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19903. return WC_TEST_RET_ENC_EC(ret);
  19904. wc_FreeDhKey(NULL);
  19905. ret = wc_DhSetKey(NULL, p, sizeof(p), g, sizeof(g));
  19906. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19908. }
  19909. ret = wc_DhSetKey(smallKey, NULL, sizeof(p), g, sizeof(g));
  19910. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19912. }
  19913. ret = wc_DhSetKey(smallKey, p, 0, g, sizeof(g));
  19914. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19915. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19916. }
  19917. ret = wc_DhSetKey(smallKey, p, sizeof(p), NULL, sizeof(g));
  19918. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19920. }
  19921. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, 0);
  19922. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19924. }
  19925. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, sizeof(g));
  19926. if (ret != 0)
  19927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19928. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19929. /* Use API. */
  19930. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  19931. #if defined(WOLFSSL_ASYNC_CRYPT)
  19932. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  19933. #endif
  19934. if (ret != 0) {
  19935. ret = WC_TEST_RET_ENC_EC(ret);
  19936. }
  19937. #else
  19938. (void)rng;
  19939. #if defined(HAVE_FIPS) || !defined(WOLFSSL_NO_DH186)
  19940. ret = 0;
  19941. #endif
  19942. #endif
  19943. #if !defined(HAVE_FIPS) && defined(WOLFSSL_NO_DH186)
  19944. {
  19945. byte priv[260];
  19946. byte pub[260];
  19947. word32 privSz = sizeof(priv);
  19948. word32 pubSz = sizeof(pub);
  19949. /* test odd ball param generation with DH */
  19950. wc_FreeDhKey(smallKey);
  19951. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19952. if (ret != 0)
  19953. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19954. /* should fail since modSz is 16 and group size is 20 */
  19955. ret = wc_DhGenerateParams(rng, 128, smallKey);
  19956. if (ret == 0)
  19957. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19958. ret = wc_DhGenerateParams(rng, 2056, smallKey);
  19959. if (ret != 0)
  19960. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19961. privSz = sizeof(priv);
  19962. pubSz = sizeof(pub);
  19963. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  19964. #if defined(WOLFSSL_ASYNC_CRYPT)
  19965. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  19966. #endif
  19967. if (ret != 0)
  19968. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19969. }
  19970. #endif /* !HAVE_FIPS and WOLFSSL_NO_DH186 */
  19971. exit_gen_test:
  19972. if (smallKey_inited)
  19973. wc_FreeDhKey(smallKey);
  19974. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19975. XFREE(smallKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19976. #endif
  19977. return ret;
  19978. }
  19979. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  19980. typedef struct dh_pubvalue_test {
  19981. const byte* data;
  19982. word32 len;
  19983. } dh_pubvalue_test;
  19984. static wc_test_ret_t dh_test_check_pubvalue(void)
  19985. {
  19986. wc_test_ret_t ret;
  19987. word32 i;
  19988. WOLFSSL_SMALL_STACK_STATIC const byte prime[] = {0x01, 0x00, 0x01};
  19989. WOLFSSL_SMALL_STACK_STATIC const byte pubValZero[] = { 0x00 };
  19990. WOLFSSL_SMALL_STACK_STATIC const byte pubValZeroLong[] = { 0x00, 0x00, 0x00 };
  19991. WOLFSSL_SMALL_STACK_STATIC const byte pubValOne[] = { 0x01 };
  19992. WOLFSSL_SMALL_STACK_STATIC const byte pubValOneLong[] = { 0x00, 0x00, 0x01 };
  19993. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeMinusOne[] = { 0x01, 0x00, 0x00 };
  19994. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeLong[] = {0x00, 0x01, 0x00, 0x01};
  19995. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimePlusOne[] = { 0x01, 0x00, 0x02 };
  19996. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig0[] = { 0x02, 0x00, 0x01 };
  19997. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig1[] = { 0x01, 0x01, 0x01 };
  19998. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooLong[] = { 0x01, 0x00, 0x00, 0x01 };
  19999. const dh_pubvalue_test dh_pubval_fail[] = {
  20000. { prime, sizeof(prime) },
  20001. { pubValZero, sizeof(pubValZero) },
  20002. { pubValZeroLong, sizeof(pubValZeroLong) },
  20003. { pubValOne, sizeof(pubValOne) },
  20004. { pubValOneLong, sizeof(pubValOneLong) },
  20005. { pubValPrimeMinusOne, sizeof(pubValPrimeMinusOne) },
  20006. { pubValPrimeLong, sizeof(pubValPrimeLong) },
  20007. { pubValPrimePlusOne, sizeof(pubValPrimePlusOne) },
  20008. { pubValTooBig0, sizeof(pubValTooBig0) },
  20009. { pubValTooBig1, sizeof(pubValTooBig1) },
  20010. { pubValTooLong, sizeof(pubValTooLong) },
  20011. };
  20012. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwo[] = { 0x02 };
  20013. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwoLong[] = { 0x00, 0x00, 0x02 };
  20014. WOLFSSL_SMALL_STACK_STATIC const byte pubValGood[] = { 0x12, 0x34 };
  20015. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLen[] = { 0x00, 0x12, 0x34 };
  20016. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLong[] = { 0x00, 0x00, 0x12, 0x34 };
  20017. const dh_pubvalue_test dh_pubval_pass[] = {
  20018. { pubValTwo, sizeof(pubValTwo) },
  20019. { pubValTwoLong, sizeof(pubValTwoLong) },
  20020. { pubValGood, sizeof(pubValGood) },
  20021. { pubValGoodLen, sizeof(pubValGoodLen) },
  20022. { pubValGoodLong, sizeof(pubValGoodLong) },
  20023. };
  20024. for (i = 0; i < sizeof(dh_pubval_fail) / sizeof(*dh_pubval_fail); i++) {
  20025. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_fail[i].data,
  20026. dh_pubval_fail[i].len);
  20027. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  20028. return WC_TEST_RET_ENC_I(i);
  20029. }
  20030. for (i = 0; i < sizeof(dh_pubval_pass) / sizeof(*dh_pubval_pass); i++) {
  20031. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_pass[i].data,
  20032. dh_pubval_pass[i].len);
  20033. if (ret != 0)
  20034. return WC_TEST_RET_ENC_I(i);
  20035. }
  20036. return 0;
  20037. }
  20038. #endif
  20039. #if defined(HAVE_FFDHE)
  20040. #if defined(HAVE_FFDHE_4096)
  20041. #define MAX_DH_PRIV_SZ 39
  20042. #define MAX_DH_KEY_SZ 512
  20043. #elif defined(HAVE_FFDHE_3072)
  20044. #define MAX_DH_PRIV_SZ 34
  20045. #define MAX_DH_KEY_SZ 384
  20046. #else
  20047. #define MAX_DH_PRIV_SZ 29
  20048. #define MAX_DH_KEY_SZ 256
  20049. #endif
  20050. #ifndef WC_NO_RNG
  20051. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20052. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20053. #ifdef HAVE_PUBLIC_FFDHE
  20054. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, const DhParams* params)
  20055. #else
  20056. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, int name)
  20057. #endif
  20058. {
  20059. wc_test_ret_t ret;
  20060. word32 privSz, pubSz, privSz2, pubSz2;
  20061. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20062. byte *priv = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20063. byte *pub = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20064. byte *priv2 = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20065. byte *pub2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20066. byte *agree = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20067. byte *agree2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20068. DhKey *key = (DhKey*)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20069. DhKey *key2 = (DhKey*)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20070. #else
  20071. byte priv[MAX_DH_PRIV_SZ];
  20072. byte pub[MAX_DH_KEY_SZ];
  20073. byte priv2[MAX_DH_PRIV_SZ];
  20074. byte pub2[MAX_DH_KEY_SZ];
  20075. byte agree[MAX_DH_KEY_SZ];
  20076. byte agree2[MAX_DH_KEY_SZ];
  20077. DhKey key[1];
  20078. DhKey key2[1];
  20079. #endif
  20080. word32 agreeSz = MAX_DH_KEY_SZ;
  20081. word32 agreeSz2 = MAX_DH_KEY_SZ;
  20082. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20083. if ((priv == NULL) ||
  20084. (pub == NULL) ||
  20085. (priv2 == NULL) ||
  20086. (pub2 == NULL) ||
  20087. (agree == NULL) ||
  20088. (agree2 == NULL) ||
  20089. (key == NULL) ||
  20090. (key2 == NULL))
  20091. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20092. #endif
  20093. pubSz = MAX_DH_KEY_SZ;
  20094. pubSz2 = MAX_DH_KEY_SZ;
  20095. #ifdef HAVE_PUBLIC_FFDHE
  20096. privSz = MAX_DH_PRIV_SZ;
  20097. privSz2 = MAX_DH_PRIV_SZ;
  20098. #else
  20099. privSz = wc_DhGetNamedKeyMinSize(name);
  20100. privSz2 = privSz;
  20101. #endif
  20102. XMEMSET(key, 0, sizeof(*key));
  20103. XMEMSET(key2, 0, sizeof(*key2));
  20104. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20105. if (ret != 0)
  20106. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20107. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20108. if (ret != 0)
  20109. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20110. #ifdef HAVE_PUBLIC_FFDHE
  20111. ret = wc_DhSetKey(key, params->p, params->p_len, params->g, params->g_len);
  20112. #else
  20113. ret = wc_DhSetNamedKey(key, name);
  20114. #endif
  20115. if (ret != 0)
  20116. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20117. #ifdef HAVE_PUBLIC_FFDHE
  20118. ret = wc_DhSetKey(key2, params->p, params->p_len, params->g,
  20119. params->g_len);
  20120. #else
  20121. ret = wc_DhSetNamedKey(key2, name);
  20122. #endif
  20123. if (ret != 0)
  20124. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20125. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20126. #if defined(WOLFSSL_ASYNC_CRYPT)
  20127. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20128. #endif
  20129. if (ret != 0)
  20130. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20131. ret = wc_DhGenerateKeyPair(key2, rng, priv2, &privSz2, pub2, &pubSz2);
  20132. #if defined(WOLFSSL_ASYNC_CRYPT)
  20133. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20134. #endif
  20135. if (ret != 0)
  20136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20137. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20138. #if defined(WOLFSSL_ASYNC_CRYPT)
  20139. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20140. #endif
  20141. if (ret != 0)
  20142. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20143. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20144. #if defined(WOLFSSL_ASYNC_CRYPT)
  20145. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20146. #endif
  20147. if (ret != 0)
  20148. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20149. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20150. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20151. }
  20152. #if (defined(WOLFSSL_HAVE_SP_DH) || defined(USE_FAST_MATH)) && \
  20153. !defined(HAVE_INTEL_QA)
  20154. /* Make p even */
  20155. key->p.dp[0] &= (mp_digit)-2;
  20156. if (ret != 0)
  20157. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20158. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20159. #if defined(WOLFSSL_ASYNC_CRYPT)
  20160. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20161. #endif
  20162. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20163. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  20164. {
  20165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20166. }
  20167. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20168. #if defined(WOLFSSL_ASYNC_CRYPT)
  20169. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20170. #endif
  20171. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20172. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20173. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20174. {
  20175. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20176. }
  20177. #ifndef HAVE_SELFTEST
  20178. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  20179. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20180. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20181. ret != WC_NO_ERR_TRACE(MP_CMP_E) &&
  20182. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20183. {
  20184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20185. }
  20186. #endif
  20187. /* Getting here means success - set ret to 0. */
  20188. ret = 0;
  20189. #endif /* (SP DH or Fast Math) and not Intel QuickAssist */
  20190. done:
  20191. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) && \
  20192. !defined(WC_NO_RNG)
  20193. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20194. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20195. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20196. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20197. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20198. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20199. if (key) {
  20200. wc_FreeDhKey(key);
  20201. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20202. }
  20203. if (key2) {
  20204. wc_FreeDhKey(key2);
  20205. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20206. }
  20207. #else
  20208. wc_FreeDhKey(key);
  20209. wc_FreeDhKey(key2);
  20210. #endif
  20211. return ret;
  20212. }
  20213. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  20214. #endif /* !WC_NO_RNG */
  20215. #endif /* HAVE_FFDHE */
  20216. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void)
  20217. {
  20218. wc_test_ret_t ret;
  20219. word32 bytes;
  20220. word32 idx = 0, privSz, pubSz, privSz2, pubSz2;
  20221. #ifndef WC_NO_RNG
  20222. WC_RNG rng;
  20223. int rngInit = 0;
  20224. #endif
  20225. int keyInit = 0, key2Init = 0;
  20226. #define DH_TEST_TMP_SIZE 1024
  20227. #if !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  20228. #define DH_TEST_BUF_SIZE 256
  20229. #else
  20230. #define DH_TEST_BUF_SIZE 512
  20231. #endif
  20232. #ifndef WC_NO_RNG
  20233. word32 agreeSz = DH_TEST_BUF_SIZE;
  20234. word32 agreeSz2 = DH_TEST_BUF_SIZE;
  20235. #endif
  20236. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20237. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20238. DhKey *key2 = (DhKey *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20239. byte *tmp = (byte *)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20240. #else
  20241. DhKey key[1];
  20242. DhKey key2[1];
  20243. byte tmp[DH_TEST_TMP_SIZE];
  20244. #endif
  20245. #ifndef WC_NO_RNG
  20246. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20247. byte *priv = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20248. byte *pub = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20249. byte *priv2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20250. byte *pub2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20251. byte *agree = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20252. byte *agree2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20253. if (priv == NULL || pub == NULL || priv2 == NULL || pub2 == NULL ||
  20254. agree == NULL || agree2 == NULL) {
  20255. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20256. }
  20257. #else
  20258. byte priv[DH_TEST_BUF_SIZE];
  20259. byte pub[DH_TEST_BUF_SIZE];
  20260. byte priv2[DH_TEST_BUF_SIZE];
  20261. byte pub2[DH_TEST_BUF_SIZE];
  20262. byte agree[DH_TEST_BUF_SIZE];
  20263. byte agree2[DH_TEST_BUF_SIZE];
  20264. #endif
  20265. #endif /* !WC_NO_RNG */
  20266. WOLFSSL_ENTER("dh_test");
  20267. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20268. if (key == NULL || key2 == NULL || tmp == NULL) {
  20269. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20270. }
  20271. #endif
  20272. #ifdef USE_CERT_BUFFERS_1024
  20273. XMEMCPY(tmp, dh_key_der_1024, (size_t)sizeof_dh_key_der_1024);
  20274. bytes = (size_t)sizeof_dh_key_der_1024;
  20275. #elif defined(USE_CERT_BUFFERS_2048)
  20276. XMEMCPY(tmp, dh_key_der_2048, (size_t)sizeof_dh_key_der_2048);
  20277. bytes = (size_t)sizeof_dh_key_der_2048;
  20278. #elif defined(USE_CERT_BUFFERS_3072)
  20279. XMEMCPY(tmp, dh_key_der_3072, (size_t)sizeof_dh_key_der_3072);
  20280. bytes = (size_t)sizeof_dh_key_der_3072;
  20281. #elif defined(USE_CERT_BUFFERS_4096)
  20282. XMEMCPY(tmp, dh_key_der_4096, (size_t)sizeof_dh_key_der_4096);
  20283. bytes = (size_t)sizeof_dh_key_der_4096;
  20284. #elif defined(NO_ASN)
  20285. /* don't use file, no DER parsing */
  20286. #elif !defined(NO_FILESYSTEM)
  20287. {
  20288. XFILE file = XFOPEN(dhParamsFile, "rb");
  20289. if (! file)
  20290. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20291. bytes = (word32) XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20292. XFCLOSE(file);
  20293. if (bytes == 0)
  20294. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20295. }
  20296. #else
  20297. /* No DH key to use. */
  20298. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20299. #endif /* USE_CERT_BUFFERS */
  20300. (void)idx;
  20301. (void)tmp;
  20302. (void)bytes;
  20303. pubSz = DH_TEST_BUF_SIZE;
  20304. pubSz2 = DH_TEST_BUF_SIZE;
  20305. privSz = DH_TEST_BUF_SIZE;
  20306. privSz2 = DH_TEST_BUF_SIZE;
  20307. #ifndef WC_NO_RNG
  20308. XMEMSET(&rng, 0, sizeof(rng));
  20309. #endif
  20310. /* Use API for coverage. */
  20311. ret = wc_InitDhKey(key);
  20312. if (ret != 0)
  20313. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20314. wc_FreeDhKey(key);
  20315. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20316. if (ret != 0)
  20317. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20318. keyInit = 1;
  20319. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20320. if (ret != 0)
  20321. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20322. key2Init = 1;
  20323. #ifdef NO_ASN
  20324. #ifndef WOLFSSL_SP_MATH
  20325. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20326. if (ret != 0)
  20327. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20328. ret = wc_DhSetKey(key2, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20329. if (ret != 0)
  20330. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20331. #else
  20332. ret = wc_DhSetKey(key, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20333. sizeof(dh2048_g));
  20334. if (ret != 0)
  20335. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20336. ret = wc_DhSetKey(key2, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20337. sizeof(dh2048_g));
  20338. if (ret != 0)
  20339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20340. #endif
  20341. #else
  20342. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20343. if (ret != 0)
  20344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20345. idx = 0;
  20346. ret = wc_DhKeyDecode(tmp, &idx, key2, bytes);
  20347. if (ret != 0)
  20348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20349. #endif
  20350. #ifndef WC_NO_RNG
  20351. #ifndef HAVE_FIPS
  20352. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20353. #else
  20354. ret = wc_InitRng(&rng);
  20355. #endif
  20356. if (ret != 0)
  20357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20358. rngInit = 1;
  20359. ret = wc_DhGenerateKeyPair(key, &rng, priv, &privSz, pub, &pubSz);
  20360. #if defined(WOLFSSL_ASYNC_CRYPT)
  20361. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20362. #endif
  20363. if (ret != 0)
  20364. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20365. ret = wc_DhGenerateKeyPair(key2, &rng, priv2, &privSz2, pub2, &pubSz2);
  20366. #if defined(WOLFSSL_ASYNC_CRYPT)
  20367. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20368. #endif
  20369. if (ret != 0)
  20370. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20371. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20372. #if defined(WOLFSSL_ASYNC_CRYPT)
  20373. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20374. #endif
  20375. if (ret != 0)
  20376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20377. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20378. #if defined(WOLFSSL_ASYNC_CRYPT)
  20379. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20380. #endif
  20381. if (ret != 0)
  20382. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20383. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20384. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20385. }
  20386. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) && \
  20387. !defined(HAVE_SELFTEST)
  20388. agreeSz = DH_TEST_BUF_SIZE;
  20389. agreeSz2 = DH_TEST_BUF_SIZE;
  20390. ret = wc_DhAgree_ct(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20391. if (ret != 0)
  20392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20393. ret = wc_DhAgree_ct(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20394. if (ret != 0)
  20395. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20396. #ifdef WOLFSSL_PUBLIC_MP
  20397. if (agreeSz != (word32)mp_unsigned_bin_size(&key->p))
  20398. {
  20399. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20400. }
  20401. #endif
  20402. if (agreeSz != agreeSz2)
  20403. {
  20404. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20405. }
  20406. if (XMEMCMP(agree, agree2, agreeSz) != 0)
  20407. {
  20408. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20409. }
  20410. #endif /* (!HAVE_FIPS || FIPS_VERSION_GE(7,0)) && !HAVE_SELFTEST */
  20411. #endif /* !WC_NO_RNG */
  20412. #if defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20413. ret = wc_DhCheckPrivKey(NULL, NULL, 0);
  20414. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20416. ret = wc_DhCheckPrivKey(key, priv, privSz);
  20417. if (ret != 0)
  20418. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20419. ret = wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  20420. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20422. {
  20423. word32 pSz, qSz, gSz;
  20424. ret = wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz);
  20425. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  20426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20427. }
  20428. #endif
  20429. /* Test DH key import / export */
  20430. #if defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM) && \
  20431. (!defined(HAVE_FIPS) || \
  20432. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  20433. wc_FreeDhKey(key);
  20434. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20435. if (ret != 0)
  20436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20437. #ifndef NO_ASN
  20438. {
  20439. /* DH Private - Key Export / Import */
  20440. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20441. byte *tmp2;
  20442. #else
  20443. byte tmp2[DH_TEST_TMP_SIZE];
  20444. #endif
  20445. #if defined(USE_CERT_BUFFERS_2048)
  20446. XMEMCPY(tmp, dh_ffdhe_statickey_der_2048, sizeof_dh_ffdhe_statickey_der_2048);
  20447. bytes = sizeof_dh_ffdhe_statickey_der_2048;
  20448. #else
  20449. XFILE file = XFOPEN(dhKeyFile, "rb");
  20450. if (!file)
  20451. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20452. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20453. XFCLOSE(file);
  20454. if (bytes == 0)
  20455. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20456. #endif
  20457. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20458. tmp2 = (byte*)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20459. if (tmp2 == NULL)
  20460. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20461. #endif
  20462. idx = 0;
  20463. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20464. /* Import DH Private key as DER */
  20465. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20466. if (ret == 0) {
  20467. /* Export as DER */
  20468. idx = DH_TEST_TMP_SIZE;
  20469. ret = wc_DhPrivKeyToDer(key, tmp2, &idx);
  20470. }
  20471. /* Verify export matches original */
  20472. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20473. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20474. }
  20475. /* DH Public Key - Export / Import */
  20476. #if defined(USE_CERT_BUFFERS_2048)
  20477. XMEMCPY(tmp, dh_ffdhe_pub_statickey_der_2048, sizeof_dh_ffdhe_pub_statickey_der_2048);
  20478. bytes = sizeof_dh_ffdhe_pub_statickey_der_2048;
  20479. #else
  20480. file = XFOPEN(dhKeyPubFile, "rb");
  20481. if (!file)
  20482. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20483. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20484. XFCLOSE(file);
  20485. if (bytes == 0)
  20486. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20487. #endif
  20488. /* for HAVE_WOLF_BIGINT prevent leak */
  20489. wc_FreeDhKey(key);
  20490. (void)wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20491. idx = 0;
  20492. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20493. /* Import DH Public key as DER */
  20494. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20495. if (ret == 0) {
  20496. /* Export as DER */
  20497. idx = DH_TEST_TMP_SIZE;
  20498. ret = wc_DhPubKeyToDer(key, tmp2, &idx);
  20499. }
  20500. /* Verify export matches original */
  20501. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20502. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20503. }
  20504. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20505. XFREE(tmp2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20506. #endif
  20507. }
  20508. #else
  20509. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20510. if (ret != 0)
  20511. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20512. #endif /* !NO_ASN */
  20513. privSz = DH_TEST_BUF_SIZE;
  20514. pubSz = DH_TEST_BUF_SIZE;
  20515. ret = wc_DhExportKeyPair(key, priv, &privSz, pub, &pubSz);
  20516. if (ret != 0)
  20517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20518. ret = wc_DhImportKeyPair(key2, priv, privSz, pub, pubSz);
  20519. if (ret != 0)
  20520. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20521. #endif /* WOLFSSL_DH_EXTRA && !NO_FILESYSTEM && !FIPS <= 2 */
  20522. #ifndef WC_NO_RNG
  20523. ret = dh_generate_test(&rng);
  20524. if (ret != 0)
  20525. ERROR_OUT(ret, done);
  20526. ret = dh_fips_generate_test(&rng);
  20527. if (ret != 0)
  20528. ERROR_OUT(ret, done);
  20529. #endif /* !WC_NO_RNG */
  20530. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20531. ret = dh_test_check_pubvalue();
  20532. if (ret != 0)
  20533. ERROR_OUT(ret, done);
  20534. #endif
  20535. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20536. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20537. /* RNG with DH and SP_ASM code not supported in the in-lined FIPS ASM code,
  20538. * this will be available for testing in the 140-3 module */
  20539. #ifndef WC_NO_RNG
  20540. /* Specialized code for key gen when using FFDHE-2048, FFDHE-3072 and FFDHE-4096 */
  20541. #ifdef HAVE_FFDHE_2048
  20542. #ifdef HAVE_PUBLIC_FFDHE
  20543. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe2048_Get());
  20544. #else
  20545. ret = dh_ffdhe_test(&rng, WC_FFDHE_2048);
  20546. #endif
  20547. if (ret != 0)
  20548. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20549. #endif
  20550. #ifdef HAVE_FFDHE_3072
  20551. #ifdef HAVE_PUBLIC_FFDHE
  20552. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe3072_Get());
  20553. #else
  20554. ret = dh_ffdhe_test(&rng, WC_FFDHE_3072);
  20555. #endif
  20556. if (ret != 0)
  20557. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20558. #endif
  20559. #ifdef HAVE_FFDHE_4096
  20560. #ifdef HAVE_PUBLIC_FFDHE
  20561. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe4096_Get());
  20562. #else
  20563. ret = dh_ffdhe_test(&rng, WC_FFDHE_4096);
  20564. #endif
  20565. if (ret != 0)
  20566. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20567. #endif
  20568. #endif /* !WC_NO_RNG */
  20569. #endif /* HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM64_ASM */
  20570. wc_FreeDhKey(key);
  20571. keyInit = 0;
  20572. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  20573. !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(WC_NO_RNG)
  20574. /* Test Check Key */
  20575. ret = wc_DhSetCheckKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g),
  20576. NULL, 0, 0, &rng);
  20577. if (ret != 0)
  20578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20579. keyInit = 1; /* DhSetCheckKey also initializes the key, free it */
  20580. #endif
  20581. done:
  20582. #ifndef WC_NO_RNG
  20583. if (rngInit)
  20584. wc_FreeRng(&rng);
  20585. #endif
  20586. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20587. if (key) {
  20588. if (keyInit)
  20589. wc_FreeDhKey(key);
  20590. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20591. }
  20592. if (key2) {
  20593. if (key2Init)
  20594. wc_FreeDhKey(key2);
  20595. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20596. }
  20597. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20598. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20599. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20600. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20601. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20602. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20603. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20604. #else
  20605. if (keyInit)
  20606. wc_FreeDhKey(key);
  20607. if (key2Init)
  20608. wc_FreeDhKey(key2);
  20609. #endif
  20610. (void)privSz;
  20611. (void)pubSz;
  20612. (void)pubSz2;
  20613. (void)privSz2;
  20614. return ret;
  20615. #undef DH_TEST_BUF_SIZE
  20616. #undef DH_TEST_TMP_SIZE
  20617. }
  20618. #endif /* NO_DH */
  20619. #ifndef NO_DSA
  20620. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void)
  20621. {
  20622. wc_test_ret_t ret = 0;
  20623. int answer;
  20624. word32 bytes;
  20625. word32 idx = 0;
  20626. WC_RNG rng;
  20627. int rng_inited = 0;
  20628. wc_Sha sha;
  20629. byte hash[WC_SHA_DIGEST_SIZE];
  20630. byte signature[40];
  20631. int key_inited = 0;
  20632. #ifdef WOLFSSL_KEY_GEN
  20633. byte* der = 0;
  20634. int derIn_inited = 0;
  20635. int genKey_inited = 0;
  20636. #endif
  20637. #define DSA_TEST_TMP_SIZE 1024
  20638. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20639. byte *tmp = (byte *)XMALLOC(DSA_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20640. DsaKey *key = (DsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20641. #ifdef WOLFSSL_KEY_GEN
  20642. DsaKey *derIn = (DsaKey *)XMALLOC(sizeof *derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20643. DsaKey *genKey = (DsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20644. #endif
  20645. WOLFSSL_ENTER("dsa_test");
  20646. if ((tmp == NULL) ||
  20647. (key == NULL)
  20648. #ifdef WOLFSSL_KEY_GEN
  20649. || (derIn == NULL)
  20650. || (genKey == NULL)
  20651. #endif
  20652. ) {
  20653. ret = WC_TEST_RET_ENC_NC;
  20654. goto out;
  20655. }
  20656. #else
  20657. byte tmp[1024];
  20658. DsaKey key[1];
  20659. #ifdef WOLFSSL_KEY_GEN
  20660. DsaKey derIn[1];
  20661. DsaKey genKey[1];
  20662. #endif
  20663. #endif
  20664. #ifdef USE_CERT_BUFFERS_1024
  20665. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20666. bytes = sizeof_dsa_key_der_1024;
  20667. #elif defined(USE_CERT_BUFFERS_2048)
  20668. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20669. bytes = sizeof_dsa_key_der_2048;
  20670. #else
  20671. {
  20672. XFILE file = XFOPEN(dsaKey, "rb");
  20673. if (!file)
  20674. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20675. bytes = (word32) XFREAD(tmp, 1, DSA_TEST_TMP_SIZE, file);
  20676. XFCLOSE(file);
  20677. if (bytes == 0)
  20678. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20679. }
  20680. #endif /* USE_CERT_BUFFERS */
  20681. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  20682. if (ret != 0)
  20683. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20684. wc_ShaUpdate(&sha, tmp, bytes);
  20685. wc_ShaFinal(&sha, hash);
  20686. wc_ShaFree(&sha);
  20687. ret = wc_InitDsaKey(key);
  20688. if (ret != 0)
  20689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20690. key_inited = 1;
  20691. ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes);
  20692. if (ret != 0)
  20693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20694. #ifndef HAVE_FIPS
  20695. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20696. #else
  20697. ret = wc_InitRng(&rng);
  20698. #endif
  20699. if (ret != 0)
  20700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20701. rng_inited = 1;
  20702. ret = wc_DsaSign(hash, signature, key, &rng);
  20703. if (ret != 0)
  20704. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20705. ret = wc_DsaVerify(hash, signature, key, &answer);
  20706. if (ret != 0)
  20707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20708. if (answer != 1)
  20709. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20710. wc_FreeDsaKey(key);
  20711. key_inited = 0;
  20712. ret = wc_InitDsaKey_h(key, NULL);
  20713. if (ret != 0)
  20714. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20715. key_inited = 1;
  20716. #ifdef WOLFSSL_KEY_GEN
  20717. {
  20718. int derSz = 0;
  20719. ret = wc_InitDsaKey(genKey);
  20720. if (ret != 0)
  20721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20722. genKey_inited = 1;
  20723. ret = wc_MakeDsaParameters(&rng, 1024, genKey);
  20724. if (ret != 0)
  20725. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20726. ret = wc_MakeDsaKey(&rng, genKey);
  20727. if (ret != 0)
  20728. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20729. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20730. if (der == NULL)
  20731. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20732. derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF);
  20733. if (derSz < 0)
  20734. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out);
  20735. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  20736. DSA_PRIVATEKEY_TYPE);
  20737. if (ret != 0)
  20738. goto out;
  20739. ret = wc_InitDsaKey(derIn);
  20740. if (ret != 0)
  20741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20742. derIn_inited = 1;
  20743. idx = 0;
  20744. ret = wc_DsaPrivateKeyDecode(der, &idx, derIn, (word32)derSz);
  20745. if (ret != 0)
  20746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20747. }
  20748. #endif /* WOLFSSL_KEY_GEN */
  20749. out:
  20750. #ifdef WOLFSSL_KEY_GEN
  20751. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20752. #endif
  20753. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20754. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20755. if (key) {
  20756. if (key_inited)
  20757. wc_FreeDsaKey(key);
  20758. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20759. }
  20760. #ifdef WOLFSSL_KEY_GEN
  20761. if (derIn) {
  20762. if (derIn_inited)
  20763. wc_FreeDsaKey(derIn);
  20764. XFREE(derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20765. }
  20766. if (genKey) {
  20767. if (genKey_inited)
  20768. wc_FreeDsaKey(genKey);
  20769. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20770. }
  20771. #endif
  20772. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  20773. if (key_inited)
  20774. wc_FreeDsaKey(key);
  20775. #ifdef WOLFSSL_KEY_GEN
  20776. if (derIn_inited)
  20777. wc_FreeDsaKey(derIn);
  20778. if (genKey_inited)
  20779. wc_FreeDsaKey(genKey);
  20780. #endif
  20781. #endif
  20782. if (rng_inited)
  20783. wc_FreeRng(&rng);
  20784. return ret;
  20785. }
  20786. #endif /* NO_DSA */
  20787. #ifdef WOLFCRYPT_HAVE_SRP
  20788. static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
  20789. {
  20790. wc_test_ret_t ret = WC_TEST_RET_ENC_NC;
  20791. WC_RNG rng;
  20792. if(NULL == buf || !size)
  20793. return WC_TEST_RET_ENC_NC;
  20794. if (buf && size && wc_InitRng_ex(&rng, HEAP_HINT, devId) == 0) {
  20795. ret = wc_RNG_GenerateBlock(&rng, (byte *)buf, size);
  20796. wc_FreeRng(&rng);
  20797. }
  20798. return ret;
  20799. }
  20800. static wc_test_ret_t srp_test_digest(SrpType dgstType)
  20801. {
  20802. wc_test_ret_t r;
  20803. byte clientPubKey[192]; /* A */
  20804. byte serverPubKey[192]; /* B */
  20805. word32 clientPubKeySz = 192;
  20806. word32 serverPubKeySz = 192;
  20807. byte username[] = "user";
  20808. word32 usernameSz = 4;
  20809. byte password[] = "password";
  20810. word32 passwordSz = 8;
  20811. WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
  20812. 0xfc, 0x58, 0x7a, 0x8a, 0x70, 0xfb, 0x5a, 0x9a,
  20813. 0x5d, 0x39, 0x48, 0xbf, 0x1c, 0x46, 0xd8, 0x3b,
  20814. 0x7a, 0xe9, 0x1f, 0x85, 0x36, 0x18, 0xc4, 0x35,
  20815. 0x3f, 0xf8, 0x8a, 0x8f, 0x8c, 0x10, 0x2e, 0x01,
  20816. 0x58, 0x1d, 0x41, 0xcb, 0xc4, 0x47, 0xa8, 0xaf,
  20817. 0x9a, 0x6f, 0x58, 0x14, 0xa4, 0x68, 0xf0, 0x9c,
  20818. 0xa6, 0xe7, 0xbf, 0x0d, 0xe9, 0x62, 0x0b, 0xd7,
  20819. 0x26, 0x46, 0x5b, 0x27, 0xcb, 0x4c, 0xf9, 0x7e,
  20820. 0x1e, 0x8b, 0xe6, 0xdd, 0x29, 0xb7, 0xb7, 0x15,
  20821. 0x2e, 0xcf, 0x23, 0xa6, 0x4b, 0x97, 0x9f, 0x89,
  20822. 0xd4, 0x86, 0xc4, 0x90, 0x63, 0x92, 0xf4, 0x30,
  20823. 0x26, 0x69, 0x48, 0x9d, 0x7a, 0x4f, 0xad, 0xb5,
  20824. 0x6a, 0x51, 0xad, 0xeb, 0xf9, 0x90, 0x31, 0x77,
  20825. 0x53, 0x30, 0x2a, 0x85, 0xf7, 0x11, 0x21, 0x0c,
  20826. 0xb8, 0x4b, 0x56, 0x03, 0x5e, 0xbb, 0x25, 0x33,
  20827. 0x7c, 0xd9, 0x5a, 0xd1, 0x5c, 0xb2, 0xd4, 0x53,
  20828. 0xc5, 0x16, 0x68, 0xf0, 0xdf, 0x48, 0x55, 0x3e,
  20829. 0xd4, 0x59, 0x87, 0x64, 0x59, 0xaa, 0x39, 0x01,
  20830. 0x45, 0x89, 0x9c, 0x72, 0xff, 0xdd, 0x8f, 0x6d,
  20831. 0xa0, 0x42, 0xbc, 0x6f, 0x6e, 0x62, 0x18, 0x2d,
  20832. 0x50, 0xe8, 0x18, 0x97, 0x87, 0xfc, 0xef, 0x1f,
  20833. 0xf5, 0x53, 0x68, 0xe8, 0x49, 0xd1, 0xa2, 0xe8,
  20834. 0xb9, 0x26, 0x03, 0xba, 0xb5, 0x58, 0x6f, 0x6c,
  20835. 0x8b, 0x08, 0xa1, 0x7b, 0x6f, 0x42, 0xc9, 0x53
  20836. };
  20837. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  20838. 0x02
  20839. };
  20840. byte salt[10];
  20841. byte verifier[192];
  20842. word32 v_size = sizeof(verifier);
  20843. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  20844. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  20845. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20846. Srp *cli = (Srp *)XMALLOC(sizeof *cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20847. Srp *srv = (Srp *)XMALLOC(sizeof *srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20848. byte *clientProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20849. DYNAMIC_TYPE_TMP_BUFFER); /* M1 */
  20850. byte *serverProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20851. DYNAMIC_TYPE_TMP_BUFFER); /* M2 */
  20852. if ((cli == NULL) ||
  20853. (srv == NULL) ||
  20854. (clientProof == NULL) ||
  20855. (serverProof == NULL)) {
  20856. r = WC_TEST_RET_ENC_NC;
  20857. goto out;
  20858. }
  20859. #else
  20860. Srp cli[1], srv[1];
  20861. byte clientProof[SRP_MAX_DIGEST_SIZE]; /* M1 */
  20862. byte serverProof[SRP_MAX_DIGEST_SIZE]; /* M2 */
  20863. #endif
  20864. /* set as 0's so if second init on srv not called SrpTerm is not on
  20865. * garbage values */
  20866. XMEMSET(srv, 0, sizeof *srv);
  20867. XMEMSET(cli, 0, sizeof *cli);
  20868. /* generating random salt */
  20869. r = generate_random_salt(salt, sizeof(salt));
  20870. /* client knows username and password. */
  20871. /* server knows N, g, salt and verifier. */
  20872. if (!r) r = wc_SrpInit_ex(cli, dgstType, SRP_CLIENT_SIDE, HEAP_HINT, devId);
  20873. if (!r) r = wc_SrpSetUsername(cli, username, usernameSz);
  20874. /* loading N, g and salt in advance to generate the verifier. */
  20875. if (!r) r = wc_SrpSetParams(cli, N, sizeof(N),
  20876. g, sizeof(g),
  20877. salt, sizeof(salt));
  20878. if (!r) r = wc_SrpSetPassword(cli, password, passwordSz);
  20879. if (!r) r = wc_SrpGetVerifier(cli, verifier, &v_size);
  20880. /* client sends username to server */
  20881. if (!r) r = wc_SrpInit_ex(srv, dgstType, SRP_SERVER_SIDE, HEAP_HINT, devId);
  20882. if (!r) r = wc_SrpSetUsername(srv, username, usernameSz);
  20883. if (!r) r = wc_SrpSetParams(srv, N, sizeof(N),
  20884. g, sizeof(g),
  20885. salt, sizeof(salt));
  20886. if (!r) r = wc_SrpSetVerifier(srv, verifier, v_size);
  20887. if (!r) r = wc_SrpGetPublic(srv, serverPubKey, &serverPubKeySz);
  20888. /* server sends N, g, salt and B to client */
  20889. if (!r) r = wc_SrpGetPublic(cli, clientPubKey, &clientPubKeySz);
  20890. if (!r) r = wc_SrpComputeKey(cli, clientPubKey, clientPubKeySz,
  20891. serverPubKey, serverPubKeySz);
  20892. if (!r) r = wc_SrpGetProof(cli, clientProof, &clientProofSz);
  20893. /* client sends A and M1 to server */
  20894. if (!r) r = wc_SrpComputeKey(srv, clientPubKey, clientPubKeySz,
  20895. serverPubKey, serverPubKeySz);
  20896. if (!r) r = wc_SrpVerifyPeersProof(srv, clientProof, clientProofSz);
  20897. if (!r) r = wc_SrpGetProof(srv, serverProof, &serverProofSz);
  20898. /* server sends M2 to client */
  20899. if (!r) r = wc_SrpVerifyPeersProof(cli, serverProof, serverProofSz);
  20900. wc_SrpTerm(cli);
  20901. wc_SrpTerm(srv);
  20902. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20903. out:
  20904. XFREE(cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20905. XFREE(srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20906. XFREE(clientProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20907. XFREE(serverProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20908. #endif
  20909. return r;
  20910. }
  20911. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void)
  20912. {
  20913. wc_test_ret_t ret;
  20914. WOLFSSL_ENTER("srp_test");
  20915. #ifndef NO_SHA
  20916. ret = srp_test_digest(SRP_TYPE_SHA);
  20917. if (ret != 0)
  20918. return ret;
  20919. #endif
  20920. #ifndef NO_SHA256
  20921. ret = srp_test_digest(SRP_TYPE_SHA256);
  20922. if (ret != 0)
  20923. return ret;
  20924. #endif
  20925. #ifdef WOLFSSL_SHA384
  20926. ret = srp_test_digest(SRP_TYPE_SHA384);
  20927. if (ret != 0)
  20928. return ret;
  20929. #endif
  20930. #ifdef WOLFSSL_SHA512
  20931. ret = srp_test_digest(SRP_TYPE_SHA512);
  20932. if (ret != 0)
  20933. return ret;
  20934. #endif
  20935. return ret;
  20936. }
  20937. #endif /* WOLFCRYPT_HAVE_SRP */
  20938. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  20939. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  20940. static wc_test_ret_t openssl_aes_test(void)
  20941. {
  20942. #ifdef HAVE_AES_CBC
  20943. #ifdef WOLFSSL_AES_128
  20944. {
  20945. /* EVP_CipherUpdate test */
  20946. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  20947. {
  20948. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  20949. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  20950. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  20951. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  20952. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  20953. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  20954. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  20955. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  20956. };
  20957. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  20958. "0123456789abcdef "; /* align */
  20959. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  20960. "1234567890abcdef "; /* align */
  20961. byte cipher[AES_BLOCK_SIZE * 4];
  20962. byte plain [AES_BLOCK_SIZE * 4];
  20963. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20964. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  20965. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  20966. #else
  20967. EVP_CIPHER_CTX en[1];
  20968. EVP_CIPHER_CTX de[1];
  20969. #endif
  20970. int outlen ;
  20971. int total = 0;
  20972. int i;
  20973. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20974. if ((en == NULL) || (de == NULL))
  20975. return MEMORY_E;
  20976. #endif
  20977. EVP_CIPHER_CTX_init(en);
  20978. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  20979. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  20980. return WC_TEST_RET_ENC_NC;
  20981. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  20982. (byte*)cbcPlain, 9) == 0)
  20983. return WC_TEST_RET_ENC_NC;
  20984. if (outlen != 0)
  20985. return WC_TEST_RET_ENC_NC;
  20986. total += outlen;
  20987. if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  20988. (byte*)&cbcPlain[9] , 9) == 0)
  20989. return WC_TEST_RET_ENC_NC;
  20990. if (outlen != 16)
  20991. return WC_TEST_RET_ENC_NC;
  20992. total += outlen;
  20993. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  20994. return WC_TEST_RET_ENC_NC;
  20995. if (outlen != 16)
  20996. return WC_TEST_RET_ENC_NC;
  20997. total += outlen;
  20998. if (total != 32)
  20999. return 3408;
  21000. EVP_CIPHER_CTX_cleanup(en);
  21001. total = 0;
  21002. EVP_CIPHER_CTX_init(de);
  21003. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21004. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21005. return WC_TEST_RET_ENC_NC;
  21006. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  21007. return WC_TEST_RET_ENC_NC;
  21008. if (outlen != 0)
  21009. return WC_TEST_RET_ENC_NC;
  21010. total += outlen;
  21011. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21012. (byte*)&cipher[6], 12) == 0)
  21013. return WC_TEST_RET_ENC_NC;
  21014. if (outlen != 0)
  21015. total += outlen;
  21016. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21017. (byte*)&cipher[6+12], 14) == 0)
  21018. return WC_TEST_RET_ENC_NC;
  21019. if (outlen != 16)
  21020. return WC_TEST_RET_ENC_NC;
  21021. total += outlen;
  21022. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21023. return WC_TEST_RET_ENC_NC;
  21024. if (outlen != 2)
  21025. return WC_TEST_RET_ENC_NC;
  21026. total += outlen;
  21027. if (total != 18)
  21028. return 3427;
  21029. if (XMEMCMP(plain, cbcPlain, 18))
  21030. return WC_TEST_RET_ENC_NC;
  21031. EVP_CIPHER_CTX_cleanup(de);
  21032. /* test with encrypting/decrypting more than 16 bytes at once */
  21033. total = 0;
  21034. EVP_CIPHER_CTX_init(en);
  21035. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  21036. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21037. return WC_TEST_RET_ENC_NC;
  21038. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21039. (byte*)cbcPlain, 17) == 0)
  21040. return WC_TEST_RET_ENC_NC;
  21041. if (outlen != 16)
  21042. return WC_TEST_RET_ENC_NC;
  21043. total += outlen;
  21044. if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21045. (byte*)&cbcPlain[17] , 1) == 0)
  21046. return WC_TEST_RET_ENC_NC;
  21047. if (outlen != 0)
  21048. return WC_TEST_RET_ENC_NC;
  21049. total += outlen;
  21050. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21051. return WC_TEST_RET_ENC_NC;
  21052. if (outlen != 16)
  21053. return WC_TEST_RET_ENC_NC;
  21054. total += outlen;
  21055. if (total != 32)
  21056. return WC_TEST_RET_ENC_NC;
  21057. EVP_CIPHER_CTX_cleanup(en);
  21058. total = 0;
  21059. EVP_CIPHER_CTX_init(de);
  21060. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21061. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21062. return WC_TEST_RET_ENC_NC;
  21063. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 17) == 0)
  21064. return WC_TEST_RET_ENC_NC;
  21065. if (outlen != 16)
  21066. return WC_TEST_RET_ENC_NC;
  21067. total += outlen;
  21068. /* final call on non block size should fail */
  21069. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21070. return WC_TEST_RET_ENC_NC;
  21071. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21072. (byte*)&cipher[17], 1) == 0)
  21073. return WC_TEST_RET_ENC_NC;
  21074. if (outlen != 0)
  21075. total += outlen;
  21076. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21077. (byte*)&cipher[17+1], 14) == 0)
  21078. return WC_TEST_RET_ENC_NC;
  21079. if (outlen != 0)
  21080. return WC_TEST_RET_ENC_NC;
  21081. total += outlen;
  21082. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21083. return WC_TEST_RET_ENC_NC;
  21084. if (outlen != 2)
  21085. return WC_TEST_RET_ENC_NC;
  21086. total += outlen;
  21087. if (total != 18)
  21088. return WC_TEST_RET_ENC_NC;
  21089. if (XMEMCMP(plain, cbcPlain, 18))
  21090. return WC_TEST_RET_ENC_NC;
  21091. /* test byte by byte decrypt */
  21092. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21093. plain[i] = i;
  21094. }
  21095. EVP_CIPHER_CTX_cleanup(de);
  21096. total = 0;
  21097. EVP_CIPHER_CTX_init(en);
  21098. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  21099. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21100. return WC_TEST_RET_ENC_NC;
  21101. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21102. (byte*)plain, AES_BLOCK_SIZE * 3) == 0)
  21103. return WC_TEST_RET_ENC_NC;
  21104. if (outlen != AES_BLOCK_SIZE * 3)
  21105. return WC_TEST_RET_ENC_NC;
  21106. total += outlen;
  21107. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21108. return WC_TEST_RET_ENC_NC;
  21109. if (outlen != AES_BLOCK_SIZE)
  21110. return WC_TEST_RET_ENC_NC;
  21111. total += outlen;
  21112. if (total != sizeof(plain))
  21113. return WC_TEST_RET_ENC_NC;
  21114. EVP_CIPHER_CTX_cleanup(en);
  21115. total = 0;
  21116. EVP_CIPHER_CTX_init(de);
  21117. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21118. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21119. return WC_TEST_RET_ENC_NC;
  21120. for (i = 0; i < AES_BLOCK_SIZE * 4; i++) {
  21121. if (EVP_CipherUpdate(de, (byte*)plain + total, &outlen,
  21122. (byte*)cipher + i, 1) == 0)
  21123. return WC_TEST_RET_ENC_NC;
  21124. if (outlen > 0) {
  21125. int j;
  21126. total += outlen;
  21127. for (j = 0; j < total; j++) {
  21128. if (plain[j] != j) {
  21129. return WC_TEST_RET_ENC_NC;
  21130. }
  21131. }
  21132. }
  21133. }
  21134. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21135. return WC_TEST_RET_ENC_NC;
  21136. total += outlen;
  21137. if (total != AES_BLOCK_SIZE * 3) {
  21138. return WC_TEST_RET_ENC_NC;
  21139. }
  21140. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21141. if (plain[i] != i) {
  21142. return WC_TEST_RET_ENC_NC;
  21143. }
  21144. }
  21145. EVP_CIPHER_CTX_cleanup(de);
  21146. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21147. wolfSSL_EVP_CIPHER_CTX_free(en);
  21148. wolfSSL_EVP_CIPHER_CTX_free(de);
  21149. #endif
  21150. }
  21151. /* set buffers to be exact size to catch potential over read/write */
  21152. {
  21153. /* EVP_CipherUpdate test */
  21154. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21155. {
  21156. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21157. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21158. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21159. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21160. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21161. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21162. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21163. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21164. };
  21165. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21166. "0123456789abcdef "; /* align */
  21167. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21168. "1234567890abcdef "; /* align */
  21169. #define EVP_TEST_BUF_SZ 18
  21170. #define EVP_TEST_BUF_PAD 32
  21171. byte cipher[EVP_TEST_BUF_SZ];
  21172. byte plain [EVP_TEST_BUF_SZ];
  21173. byte padded[EVP_TEST_BUF_PAD];
  21174. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21175. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21176. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21177. #else
  21178. EVP_CIPHER_CTX en[1];
  21179. EVP_CIPHER_CTX de[1];
  21180. #endif
  21181. int outlen ;
  21182. int total = 0;
  21183. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21184. if ((en == NULL) || (de == NULL))
  21185. return MEMORY_E;
  21186. #endif
  21187. EVP_CIPHER_CTX_init(en);
  21188. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  21189. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21190. return WC_TEST_RET_ENC_NC;
  21191. if (EVP_CIPHER_CTX_set_padding(en, 0) != 1)
  21192. return WC_TEST_RET_ENC_NC;
  21193. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21194. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21195. return WC_TEST_RET_ENC_NC;
  21196. if (outlen != 16)
  21197. return WC_TEST_RET_ENC_NC;
  21198. total += outlen;
  21199. /* should fail here */
  21200. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0)
  21201. return WC_TEST_RET_ENC_NC;
  21202. EVP_CIPHER_CTX_cleanup(en);
  21203. /* turn padding back on and do successful encrypt */
  21204. total = 0;
  21205. EVP_CIPHER_CTX_init(en);
  21206. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  21207. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21208. return WC_TEST_RET_ENC_NC;
  21209. if (EVP_CIPHER_CTX_set_padding(en, 1) != 1)
  21210. return WC_TEST_RET_ENC_NC;
  21211. if (EVP_CipherUpdate(en, (byte*)padded, &outlen,
  21212. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21213. return WC_TEST_RET_ENC_NC;
  21214. if (outlen != 16)
  21215. return WC_TEST_RET_ENC_NC;
  21216. total += outlen;
  21217. if (EVP_CipherFinal(en, (byte*)&padded[total], &outlen) == 0)
  21218. return WC_TEST_RET_ENC_NC;
  21219. total += outlen;
  21220. if (total != 32)
  21221. return WC_TEST_RET_ENC_NC;
  21222. XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ);
  21223. EVP_CIPHER_CTX_cleanup(en);
  21224. /* test out of bounds read on buffers w/o padding during decryption */
  21225. total = 0;
  21226. EVP_CIPHER_CTX_init(de);
  21227. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21228. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21229. return WC_TEST_RET_ENC_NC;
  21230. if (EVP_CIPHER_CTX_set_padding(de, 0) != 1)
  21231. return WC_TEST_RET_ENC_NC;
  21232. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher,
  21233. EVP_TEST_BUF_SZ) == 0)
  21234. return WC_TEST_RET_ENC_NC;
  21235. if (outlen != 16)
  21236. return WC_TEST_RET_ENC_NC;
  21237. total += outlen;
  21238. /* should fail since not using padding */
  21239. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21240. return WC_TEST_RET_ENC_NC;
  21241. EVP_CIPHER_CTX_cleanup(de);
  21242. total = 0;
  21243. EVP_CIPHER_CTX_init(de);
  21244. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  21245. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21246. return WC_TEST_RET_ENC_NC;
  21247. if (EVP_CIPHER_CTX_set_padding(de, 1) != 1)
  21248. return WC_TEST_RET_ENC_NC;
  21249. if (EVP_CipherUpdate(de, (byte*)padded, &outlen, (byte*)padded,
  21250. EVP_TEST_BUF_PAD) == 0)
  21251. return WC_TEST_RET_ENC_NC;
  21252. if (outlen != 16)
  21253. return WC_TEST_RET_ENC_NC;
  21254. total += outlen;
  21255. if (EVP_CipherFinal(de, (byte*)&padded[total], &outlen) == 0)
  21256. return WC_TEST_RET_ENC_NC;
  21257. if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ))
  21258. return WC_TEST_RET_ENC_NC;
  21259. EVP_CIPHER_CTX_cleanup(de);
  21260. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21261. wolfSSL_EVP_CIPHER_CTX_free(en);
  21262. wolfSSL_EVP_CIPHER_CTX_free(de);
  21263. #endif
  21264. }
  21265. { /* evp_cipher test: EVP_aes_128_cbc */
  21266. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21267. EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21268. #else
  21269. EVP_CIPHER_CTX ctx[1];
  21270. #endif
  21271. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  21272. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  21273. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  21274. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  21275. };
  21276. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21277. {
  21278. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  21279. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  21280. };
  21281. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21282. "0123456789abcdef "; /* align */
  21283. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21284. "1234567890abcdef "; /* align */
  21285. byte cipher[AES_BLOCK_SIZE * 4];
  21286. byte plain [AES_BLOCK_SIZE * 4];
  21287. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21288. if (ctx == NULL)
  21289. return MEMORY_E;
  21290. #endif
  21291. EVP_CIPHER_CTX_init(ctx);
  21292. if (EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 1) == 0)
  21293. return WC_TEST_RET_ENC_NC;
  21294. if (EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21295. return WC_TEST_RET_ENC_NC;
  21296. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21297. return WC_TEST_RET_ENC_NC;
  21298. EVP_CIPHER_CTX_cleanup(ctx);
  21299. EVP_CIPHER_CTX_init(ctx);
  21300. if (EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 0) == 0)
  21301. return WC_TEST_RET_ENC_NC;
  21302. if (EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21303. return WC_TEST_RET_ENC_NC;
  21304. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21305. return WC_TEST_RET_ENC_NC;
  21306. EVP_CIPHER_CTX_cleanup(ctx);
  21307. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21308. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21309. #endif
  21310. } /* end evp_cipher test: EVP_aes_128_cbc*/
  21311. #endif /* WOLFSSL_AES_128 */
  21312. #endif /* HAVE_AES_CBC */
  21313. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21314. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  21315. { /* evp_cipher test: EVP_aes_256_ecb*/
  21316. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21317. EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21318. #else
  21319. EVP_CIPHER_CTX ctx[1];
  21320. #endif
  21321. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21322. {
  21323. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21324. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21325. };
  21326. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21327. {
  21328. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21329. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21330. };
  21331. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21332. {
  21333. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21334. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21335. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21336. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21337. };
  21338. byte cipher[AES_BLOCK_SIZE * 4];
  21339. byte plain [AES_BLOCK_SIZE * 4];
  21340. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21341. if (ctx == NULL)
  21342. return MEMORY_E;
  21343. #endif
  21344. EVP_CIPHER_CTX_init(ctx);
  21345. if (EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1) == 0)
  21346. return WC_TEST_RET_ENC_NC;
  21347. if (EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21348. return WC_TEST_RET_ENC_NC;
  21349. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21350. return WC_TEST_RET_ENC_NC;
  21351. EVP_CIPHER_CTX_init(ctx);
  21352. if (EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0) == 0)
  21353. return WC_TEST_RET_ENC_NC;
  21354. if (EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21355. return WC_TEST_RET_ENC_NC;
  21356. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21357. return WC_TEST_RET_ENC_NC;
  21358. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21359. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21360. #endif
  21361. } /* end evp_cipher test */
  21362. #endif /* HAVE_AES_ECB && WOLFSSL_AES_256 */
  21363. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  21364. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  21365. {
  21366. /* Test: AES_encrypt/decrypt/set Key */
  21367. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21368. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21369. #ifdef HAVE_AES_DECRYPT
  21370. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21371. #endif
  21372. #else
  21373. AES_KEY enc[1];
  21374. #ifdef HAVE_AES_DECRYPT
  21375. AES_KEY dec[1];
  21376. #endif
  21377. #endif
  21378. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21379. {
  21380. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21381. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21382. };
  21383. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21384. {
  21385. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21386. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21387. };
  21388. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21389. {
  21390. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21391. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21392. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21393. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21394. };
  21395. byte plain[sizeof(msg)];
  21396. byte cipher[sizeof(msg)];
  21397. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21398. if (enc == NULL)
  21399. return MEMORY_E;
  21400. #ifdef HAVE_AES_DECRYPT
  21401. if (dec == NULL)
  21402. return MEMORY_E;
  21403. #endif
  21404. #endif
  21405. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  21406. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  21407. AES_encrypt(msg, cipher, enc);
  21408. #ifdef HAVE_AES_DECRYPT
  21409. AES_decrypt(cipher, plain, dec);
  21410. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21411. return WC_TEST_RET_ENC_NC;
  21412. #endif /* HAVE_AES_DECRYPT */
  21413. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21414. return WC_TEST_RET_ENC_NC;
  21415. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21416. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21417. #ifdef HAVE_AES_DECRYPT
  21418. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21419. #endif
  21420. #endif
  21421. }
  21422. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  21423. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21424. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  21425. #ifdef WOLFSSL_AES_COUNTER
  21426. {
  21427. byte plainBuff [64];
  21428. byte cipherBuff[64];
  21429. #ifdef WOLFSSL_AES_128
  21430. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  21431. {
  21432. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21433. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21434. };
  21435. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  21436. {
  21437. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21438. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21439. };
  21440. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  21441. {
  21442. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21443. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21444. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21445. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21446. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21447. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21448. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21449. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21450. };
  21451. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  21452. {
  21453. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  21454. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  21455. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  21456. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  21457. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  21458. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  21459. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  21460. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  21461. };
  21462. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  21463. {
  21464. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  21465. 0xc2
  21466. };
  21467. #endif
  21468. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21469. * NIST Special Publication 800-38A */
  21470. #ifdef WOLFSSL_AES_192
  21471. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  21472. {
  21473. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  21474. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  21475. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  21476. };
  21477. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  21478. {
  21479. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21480. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21481. };
  21482. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  21483. {
  21484. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21485. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21486. };
  21487. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  21488. {
  21489. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  21490. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  21491. };
  21492. #endif /* WOLFSSL_AES_192 */
  21493. #ifdef WOLFSSL_AES_256
  21494. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21495. * NIST Special Publication 800-38A */
  21496. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  21497. {
  21498. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21499. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21500. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21501. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21502. };
  21503. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  21504. {
  21505. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21506. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21507. };
  21508. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  21509. {
  21510. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21511. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21512. };
  21513. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  21514. {
  21515. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  21516. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  21517. };
  21518. #endif /* WOLFSSL_AES_256 */
  21519. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21520. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21521. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21522. #else
  21523. EVP_CIPHER_CTX en[1];
  21524. EVP_CIPHER_CTX de[1];
  21525. #endif
  21526. #ifdef WOLFSSL_AES_128
  21527. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21528. EVP_CIPHER_CTX *p_en;
  21529. EVP_CIPHER_CTX *p_de;
  21530. #endif
  21531. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21532. if ((en == NULL) || (de == NULL))
  21533. return MEMORY_E;
  21534. #endif
  21535. EVP_CIPHER_CTX_init(en);
  21536. if (EVP_CipherInit(en, EVP_aes_128_ctr(),
  21537. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21538. return WC_TEST_RET_ENC_NC;
  21539. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  21540. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21541. return WC_TEST_RET_ENC_NC;
  21542. EVP_CIPHER_CTX_init(de);
  21543. if (EVP_CipherInit(de, EVP_aes_128_ctr(),
  21544. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21545. return WC_TEST_RET_ENC_NC;
  21546. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21547. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21548. return WC_TEST_RET_ENC_NC;
  21549. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21550. return WC_TEST_RET_ENC_NC;
  21551. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21552. return WC_TEST_RET_ENC_NC;
  21553. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21554. return WC_TEST_RET_ENC_NC;
  21555. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21556. return WC_TEST_RET_ENC_NC;
  21557. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21558. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  21559. if (p_en == NULL)
  21560. return WC_TEST_RET_ENC_ERRNO;
  21561. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  21562. if (p_de == NULL)
  21563. return WC_TEST_RET_ENC_ERRNO;
  21564. if (EVP_CipherInit(p_en, EVP_aes_128_ctr(),
  21565. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21566. return WC_TEST_RET_ENC_NC;
  21567. if (EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  21568. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21569. return WC_TEST_RET_ENC_NC;
  21570. if (EVP_CipherInit(p_de, EVP_aes_128_ctr(),
  21571. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21572. return WC_TEST_RET_ENC_NC;
  21573. if (EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  21574. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21575. return WC_TEST_RET_ENC_NC;
  21576. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21577. return WC_TEST_RET_ENC_NC;
  21578. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21579. return WC_TEST_RET_ENC_NC;
  21580. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  21581. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  21582. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  21583. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21584. return WC_TEST_RET_ENC_NC;
  21585. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21586. return WC_TEST_RET_ENC_NC;
  21587. EVP_CIPHER_CTX_init(en);
  21588. if (EVP_CipherInit(en, EVP_aes_128_ctr(),
  21589. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21590. return WC_TEST_RET_ENC_NC;
  21591. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21592. return WC_TEST_RET_ENC_NC;
  21593. EVP_CIPHER_CTX_init(de);
  21594. if (EVP_CipherInit(de, EVP_aes_128_ctr(),
  21595. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21596. return WC_TEST_RET_ENC_NC;
  21597. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21598. return WC_TEST_RET_ENC_NC;
  21599. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21600. return WC_TEST_RET_ENC_NC;
  21601. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  21602. return WC_TEST_RET_ENC_NC;
  21603. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21604. return WC_TEST_RET_ENC_NC;
  21605. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21606. return WC_TEST_RET_ENC_NC;
  21607. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21608. return WC_TEST_RET_ENC_NC;
  21609. if (XMEMCMP(cipherBuff, oddCipher, 9))
  21610. return WC_TEST_RET_ENC_NC;
  21611. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21612. return WC_TEST_RET_ENC_NC;
  21613. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21614. return WC_TEST_RET_ENC_NC;
  21615. #endif /* WOLFSSL_AES_128 */
  21616. #ifdef WOLFSSL_AES_192
  21617. EVP_CIPHER_CTX_init(en);
  21618. if (EVP_CipherInit(en, EVP_aes_192_ctr(),
  21619. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21620. return WC_TEST_RET_ENC_NC;
  21621. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  21622. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21623. return WC_TEST_RET_ENC_NC;
  21624. EVP_CIPHER_CTX_init(de);
  21625. if (EVP_CipherInit(de, EVP_aes_192_ctr(),
  21626. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21627. return WC_TEST_RET_ENC_NC;
  21628. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21629. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21630. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21631. return WC_TEST_RET_ENC_NC;
  21632. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  21633. return WC_TEST_RET_ENC_NC;
  21634. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  21635. return WC_TEST_RET_ENC_NC;
  21636. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21637. return WC_TEST_RET_ENC_NC;
  21638. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21639. return WC_TEST_RET_ENC_NC;
  21640. #endif /* WOLFSSL_AES_192 */
  21641. #ifdef WOLFSSL_AES_256
  21642. EVP_CIPHER_CTX_init(en);
  21643. if (EVP_CipherInit(en, EVP_aes_256_ctr(),
  21644. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21645. return WC_TEST_RET_ENC_NC;
  21646. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  21647. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21648. return WC_TEST_RET_ENC_NC;
  21649. EVP_CIPHER_CTX_init(de);
  21650. if (EVP_CipherInit(de, EVP_aes_256_ctr(),
  21651. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21652. return WC_TEST_RET_ENC_NC;
  21653. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21654. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21655. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21656. return WC_TEST_RET_ENC_NC;
  21657. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  21658. return WC_TEST_RET_ENC_NC;
  21659. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  21660. return WC_TEST_RET_ENC_NC;
  21661. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21662. return WC_TEST_RET_ENC_NC;
  21663. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21664. return WC_TEST_RET_ENC_NC;
  21665. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21666. wolfSSL_EVP_CIPHER_CTX_free(en);
  21667. wolfSSL_EVP_CIPHER_CTX_free(de);
  21668. #endif
  21669. #endif /* WOLFSSL_AES_256 */
  21670. }
  21671. #endif /* HAVE_AES_COUNTER */
  21672. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21673. #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128)
  21674. {
  21675. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21676. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21677. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21678. #else
  21679. AES_KEY enc[1];
  21680. AES_KEY dec[1];
  21681. #endif
  21682. WOLFSSL_SMALL_STACK_STATIC const byte setIv[] = {
  21683. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  21684. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  21685. };
  21686. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21687. {
  21688. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21689. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21690. };
  21691. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  21692. {
  21693. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  21694. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  21695. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  21696. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b
  21697. };
  21698. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21699. {
  21700. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21701. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21702. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21703. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51
  21704. };
  21705. byte cipher[AES_BLOCK_SIZE * 2];
  21706. byte iv[AES_BLOCK_SIZE]; /* iv buffer is updeated by API */
  21707. int num = 0;
  21708. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21709. if ((enc == NULL) || (dec == NULL))
  21710. return MEMORY_E;
  21711. #endif
  21712. XMEMCPY(iv, setIv, sizeof(setIv));
  21713. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, enc);
  21714. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, dec);
  21715. wolfSSL_AES_cfb128_encrypt(msg, cipher, AES_BLOCK_SIZE - 1, enc, iv,
  21716. &num, AES_ENCRYPT);
  21717. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE - 1))
  21718. return WC_TEST_RET_ENC_NC;
  21719. if (num != 15) /* should have used 15 of the 16 bytes */
  21720. return WC_TEST_RET_ENC_NC;
  21721. wolfSSL_AES_cfb128_encrypt(msg + AES_BLOCK_SIZE - 1,
  21722. cipher + AES_BLOCK_SIZE - 1, AES_BLOCK_SIZE + 1, enc, iv,
  21723. &num, AES_ENCRYPT);
  21724. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  21725. return WC_TEST_RET_ENC_NC;
  21726. if (num != 0)
  21727. return WC_TEST_RET_ENC_NC;
  21728. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21729. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21730. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21731. #endif
  21732. }
  21733. #endif /* WOLFSSL_AES_CFB && WOLFSSL_AES_128 */
  21734. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21735. return 0;
  21736. }
  21737. #endif /* !defined(NO_AES) && !defined(WOLFCRYPT_ONLY) */
  21738. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void)
  21739. {
  21740. wc_test_ret_t ret;
  21741. #ifdef WOLFSSL_SMALL_STACK
  21742. EVP_MD_CTX *md_ctx = (EVP_MD_CTX *)XMALLOC(sizeof(EVP_MD_CTX), NULL, DYNAMIC_TYPE_OPENSSL);
  21743. #else
  21744. EVP_MD_CTX md_ctx[1];
  21745. #endif
  21746. testVector a, b, c, d, e, f;
  21747. byte hash[WC_SHA256_DIGEST_SIZE*2]; /* max size */
  21748. #ifdef WOLFSSL_SMALL_STACK
  21749. if (md_ctx == NULL)
  21750. return WC_TEST_RET_ENC_EC(MEMORY_E);
  21751. #endif
  21752. WOLFSSL_ENTER("openssl_test");
  21753. a.inLen = 0;
  21754. b.inLen = c.inLen = d.inLen = e.inLen = f.inLen = a.inLen;
  21755. (void)a;
  21756. (void)b;
  21757. (void)c;
  21758. (void)d;
  21759. (void)e;
  21760. (void)f;
  21761. /* test malloc / free , 10 is an arbitrary amount of memory chosen */
  21762. {
  21763. byte* p;
  21764. p = (byte*)CRYPTO_malloc(10, "", 0);
  21765. if (p == NULL) {
  21766. return WC_TEST_RET_ENC_NC;
  21767. }
  21768. XMEMSET(p, 0, 10);
  21769. CRYPTO_free(p, "", 0);
  21770. }
  21771. #ifndef NO_MD5
  21772. a.input = "1234567890123456789012345678901234567890123456789012345678"
  21773. "9012345678901234567890";
  21774. a.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  21775. "\x7a";
  21776. a.inLen = XSTRLEN(a.input);
  21777. a.outLen = WC_MD5_DIGEST_SIZE;
  21778. EVP_MD_CTX_init(md_ctx);
  21779. ret = EVP_DigestInit(md_ctx, EVP_md5());
  21780. if (ret == WOLFSSL_SUCCESS) {
  21781. ret = EVP_DigestUpdate(md_ctx, a.input, (unsigned long)a.inLen);
  21782. }
  21783. if (ret == WOLFSSL_SUCCESS) {
  21784. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21785. }
  21786. EVP_MD_CTX_cleanup(md_ctx);
  21787. if (ret != WOLFSSL_SUCCESS)
  21788. return WC_TEST_RET_ENC_NC;
  21789. if (XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE) != 0)
  21790. return WC_TEST_RET_ENC_NC;
  21791. #endif /* NO_MD5 */
  21792. #ifndef NO_SHA
  21793. b.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21794. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21795. "aaaaaaaaaa";
  21796. b.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  21797. "\x53\x99\x5E\x26\xA0";
  21798. b.inLen = XSTRLEN(b.input);
  21799. b.outLen = WC_SHA_DIGEST_SIZE;
  21800. EVP_MD_CTX_init(md_ctx);
  21801. ret = EVP_DigestInit(md_ctx, EVP_sha1());
  21802. if (ret == WOLFSSL_SUCCESS) {
  21803. ret = EVP_DigestUpdate(md_ctx, b.input, (unsigned long)b.inLen);
  21804. if (ret == WOLFSSL_SUCCESS)
  21805. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21806. }
  21807. EVP_MD_CTX_cleanup(md_ctx);
  21808. if (ret != WOLFSSL_SUCCESS)
  21809. return WC_TEST_RET_ENC_NC;
  21810. if (XMEMCMP(hash, b.output, b.outLen) != 0)
  21811. return WC_TEST_RET_ENC_NC;
  21812. #endif /* NO_SHA */
  21813. #ifdef WOLFSSL_SHA224
  21814. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21815. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21816. e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99"
  21817. "\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3";
  21818. e.inLen = XSTRLEN(e.input);
  21819. e.outLen = WC_SHA224_DIGEST_SIZE;
  21820. EVP_MD_CTX_init(md_ctx);
  21821. ret = EVP_DigestInit(md_ctx, EVP_sha224());
  21822. if (ret == WOLFSSL_SUCCESS) {
  21823. ret = EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21824. if (ret == WOLFSSL_SUCCESS)
  21825. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21826. }
  21827. EVP_MD_CTX_cleanup(md_ctx);
  21828. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21829. return WC_TEST_RET_ENC_NC;
  21830. }
  21831. #endif /* WOLFSSL_SHA224 */
  21832. #ifndef NO_SHA256
  21833. d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  21834. d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  21835. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  21836. "\x06\xC1";
  21837. d.inLen = XSTRLEN(d.input);
  21838. d.outLen = WC_SHA256_DIGEST_SIZE;
  21839. EVP_MD_CTX_init(md_ctx);
  21840. ret = EVP_DigestInit(md_ctx, EVP_sha256());
  21841. if (ret == WOLFSSL_SUCCESS) {
  21842. ret = EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21843. if (ret == WOLFSSL_SUCCESS)
  21844. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21845. }
  21846. EVP_MD_CTX_cleanup(md_ctx);
  21847. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21848. return WC_TEST_RET_ENC_NC;
  21849. }
  21850. #endif /* !NO_SHA256 */
  21851. #ifdef WOLFSSL_SHA384
  21852. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21853. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21854. e.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  21855. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  21856. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  21857. "\x74\x60\x39";
  21858. e.inLen = XSTRLEN(e.input);
  21859. e.outLen = WC_SHA384_DIGEST_SIZE;
  21860. EVP_MD_CTX_init(md_ctx);
  21861. ret = EVP_DigestInit(md_ctx, EVP_sha384());
  21862. if (ret == WOLFSSL_SUCCESS) {
  21863. ret = EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21864. if (ret == WOLFSSL_SUCCESS)
  21865. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21866. }
  21867. EVP_MD_CTX_cleanup(md_ctx);
  21868. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21869. return WC_TEST_RET_ENC_NC;
  21870. }
  21871. #endif /* WOLFSSL_SHA384 */
  21872. #ifdef WOLFSSL_SHA512
  21873. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21874. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21875. f.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  21876. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  21877. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  21878. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  21879. "\x87\x4b\xe9\x09";
  21880. f.inLen = XSTRLEN(f.input);
  21881. f.outLen = WC_SHA512_DIGEST_SIZE;
  21882. EVP_MD_CTX_init(md_ctx);
  21883. ret = EVP_DigestInit(md_ctx, EVP_sha512());
  21884. if (ret == WOLFSSL_SUCCESS) {
  21885. ret = EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21886. if (ret == WOLFSSL_SUCCESS)
  21887. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21888. }
  21889. EVP_MD_CTX_cleanup(md_ctx);
  21890. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21891. return WC_TEST_RET_ENC_NC;
  21892. }
  21893. #if !defined(WOLFSSL_NOSHA512_224) && \
  21894. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21895. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21896. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21897. f.output = "\x23\xfe\xc5\xbb\x94\xd6\x0b\x23\x30\x81\x92\x64\x0b\x0c\x45"
  21898. "\x33\x35\xd6\x64\x73\x4f\xe4\x0e\x72\x68\x67\x4a\xf9";
  21899. f.inLen = XSTRLEN(f.input);
  21900. f.outLen = WC_SHA512_224_DIGEST_SIZE;
  21901. EVP_MD_CTX_init(md_ctx);
  21902. ret = EVP_DigestInit(md_ctx, EVP_sha512_224());
  21903. if (ret == WOLFSSL_SUCCESS) {
  21904. ret = EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21905. if (ret == WOLFSSL_SUCCESS)
  21906. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21907. }
  21908. EVP_MD_CTX_cleanup(md_ctx);
  21909. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21910. return WC_TEST_RET_ENC_NC;
  21911. }
  21912. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  21913. #if !defined(WOLFSSL_NOSHA512_256) && \
  21914. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21915. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21916. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21917. f.output = "\x39\x28\xe1\x84\xfb\x86\x90\xf8\x40\xda\x39\x88\x12\x1d\x31"
  21918. "\xbe\x65\xcb\x9d\x3e\xf8\x3e\xe6\x14\x6f\xea\xc8\x61\xe1\x9b"
  21919. "\x56\x3a";
  21920. f.inLen = XSTRLEN(f.input);
  21921. f.outLen = WC_SHA512_256_DIGEST_SIZE;
  21922. EVP_MD_CTX_init(md_ctx);
  21923. ret = EVP_DigestInit(md_ctx, EVP_sha512_256());
  21924. if (ret == WOLFSSL_SUCCESS) {
  21925. ret = EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21926. if (ret == WOLFSSL_SUCCESS)
  21927. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21928. }
  21929. EVP_MD_CTX_cleanup(md_ctx);
  21930. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21931. return WC_TEST_RET_ENC_NC;
  21932. }
  21933. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  21934. #endif /* WOLFSSL_SHA512 */
  21935. #ifdef WOLFSSL_SHA3
  21936. #ifndef WOLFSSL_NOSHA3_224
  21937. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21938. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21939. e.output = "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a"
  21940. "\xe5\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc";
  21941. e.inLen = XSTRLEN(e.input);
  21942. e.outLen = WC_SHA3_224_DIGEST_SIZE;
  21943. EVP_MD_CTX_init(md_ctx);
  21944. ret = EVP_DigestInit(md_ctx, EVP_sha3_224());
  21945. if (ret == WOLFSSL_SUCCESS) {
  21946. ret = EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21947. if (ret == WOLFSSL_SUCCESS)
  21948. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21949. }
  21950. EVP_MD_CTX_cleanup(md_ctx);
  21951. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21952. return WC_TEST_RET_ENC_NC;
  21953. }
  21954. #endif /* WOLFSSL_NOSHA3_224 */
  21955. #ifndef WOLFSSL_NOSHA3_256
  21956. d.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21957. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21958. d.output = "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf"
  21959. "\xdb\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad"
  21960. "\x1d\x18";
  21961. d.inLen = XSTRLEN(d.input);
  21962. d.outLen = WC_SHA3_256_DIGEST_SIZE;
  21963. EVP_MD_CTX_init(md_ctx);
  21964. ret = EVP_DigestInit(md_ctx, EVP_sha3_256());
  21965. if (ret == WOLFSSL_SUCCESS) {
  21966. ret = EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21967. if (ret == WOLFSSL_SUCCESS)
  21968. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21969. }
  21970. EVP_MD_CTX_cleanup(md_ctx);
  21971. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21972. return WC_TEST_RET_ENC_NC;
  21973. }
  21974. #endif /* WOLFSSL_NOSHA3_256 */
  21975. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21976. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21977. e.output = "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47"
  21978. "\x91\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6"
  21979. "\x25\xdc\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79"
  21980. "\xaa\x7f\xc7";
  21981. e.inLen = XSTRLEN(e.input);
  21982. e.outLen = WC_SHA3_384_DIGEST_SIZE;
  21983. EVP_MD_CTX_init(md_ctx);
  21984. ret = EVP_DigestInit(md_ctx, EVP_sha3_384());
  21985. if (ret == WOLFSSL_SUCCESS) {
  21986. ret = EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21987. if (ret == WOLFSSL_SUCCESS)
  21988. ret = EVP_DigestFinal(md_ctx, hash, 0);
  21989. }
  21990. EVP_MD_CTX_cleanup(md_ctx);
  21991. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21992. return WC_TEST_RET_ENC_NC;
  21993. }
  21994. #ifndef WOLFSSL_NOSHA3_512
  21995. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21996. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21997. f.output = "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78"
  21998. "\xf9\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18"
  21999. "\xa4\xfa\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8"
  22000. "\x2e\x21\x89\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55"
  22001. "\xf2\x1d\xd1\x85";
  22002. f.inLen = XSTRLEN(f.input);
  22003. f.outLen = WC_SHA3_512_DIGEST_SIZE;
  22004. EVP_MD_CTX_init(md_ctx);
  22005. ret = EVP_DigestInit(md_ctx, EVP_sha3_512());
  22006. if (ret == WOLFSSL_SUCCESS) {
  22007. ret = EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22008. if (ret == WOLFSSL_SUCCESS)
  22009. ret = EVP_DigestFinal(md_ctx, hash, 0);
  22010. }
  22011. EVP_MD_CTX_cleanup(md_ctx);
  22012. if (ret != WOLFSSL_SUCCESS ||
  22013. XMEMCMP(hash, f.output, f.outLen) != 0) {
  22014. return WC_TEST_RET_ENC_NC;
  22015. }
  22016. #endif /* WOLFSSL_NOSHA3_512 */
  22017. #endif /* WOLFSSL_SHA3 */
  22018. #ifdef WOLFSSL_SMALL_STACK
  22019. XFREE(md_ctx, NULL, DYNAMIC_TYPE_OPENSSL);
  22020. md_ctx = NULL;
  22021. #endif
  22022. #ifndef WC_NO_RNG
  22023. if (RAND_bytes(hash, sizeof(hash)) != WOLFSSL_SUCCESS)
  22024. return WC_TEST_RET_ENC_NC;
  22025. #endif
  22026. #ifndef NO_MD5
  22027. c.input = "what do ya want for nothing?";
  22028. c.output = "\x55\x78\xe8\x48\x4b\xcc\x93\x80\x93\xec\x53\xaf\x22\xd6\x14"
  22029. "\x76";
  22030. c.inLen = XSTRLEN(c.input);
  22031. c.outLen = WC_MD5_DIGEST_SIZE;
  22032. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)
  22033. /* Expect failure with MD5 + HMAC when using FIPS 140-3. */
  22034. if (HMAC(EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22035. hash, 0) != NULL)
  22036. #else
  22037. if (HMAC(EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22038. hash, 0) == NULL ||
  22039. XMEMCMP(hash, c.output, c.outLen) != 0)
  22040. #endif
  22041. {
  22042. return WC_TEST_RET_ENC_NC;
  22043. }
  22044. #endif /* NO_MD5 */
  22045. #ifndef NO_DES3
  22046. { /* des test */
  22047. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  22048. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22049. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22050. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22051. };
  22052. byte plain[24];
  22053. byte cipher[24];
  22054. const_DES_cblock key = {
  22055. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  22056. };
  22057. DES_cblock iv = {
  22058. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  22059. };
  22060. DES_key_schedule sched;
  22061. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22062. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  22063. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  22064. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  22065. };
  22066. DES_key_sched(&key, &sched);
  22067. DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, DES_ENCRYPT);
  22068. DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, DES_DECRYPT);
  22069. if (XMEMCMP(plain, vector, sizeof(vector)) != 0)
  22070. return WC_TEST_RET_ENC_NC;
  22071. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22072. return WC_TEST_RET_ENC_NC;
  22073. /* test changing iv */
  22074. DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, DES_ENCRYPT);
  22075. DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, DES_ENCRYPT);
  22076. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22077. return WC_TEST_RET_ENC_NC;
  22078. } /* end des test */
  22079. #endif /* NO_DES3 */
  22080. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  22081. if ((ret = openssl_aes_test()) != 0) {
  22082. return ret;
  22083. }
  22084. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  22085. { /* evp_cipher test: EVP_aes_128_cbc */
  22086. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22087. EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22088. #else
  22089. EVP_CIPHER_CTX ctx[1];
  22090. #endif
  22091. int idx, cipherSz, plainSz;
  22092. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  22093. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22094. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22095. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22096. };
  22097. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22098. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22099. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22100. 0x3b,0x5d,0x41,0x97,0x94,0x25,0xa4,0xb4,
  22101. 0xae,0x7b,0x34,0xd0,0x3f,0x0c,0xbc,0x06
  22102. };
  22103. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  22104. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22105. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22106. 0x7d,0x37,0x7b,0x0b,0x44,0xaa,0xb5,0xf0,
  22107. 0x5f,0x34,0xb4,0xde,0xb5,0xbd,0x2a,0xbb
  22108. };
  22109. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22110. "0123456789abcdef "; /* align */
  22111. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  22112. "1234567890abcdef "; /* align */
  22113. byte cipher[AES_BLOCK_SIZE * 4];
  22114. byte plain [AES_BLOCK_SIZE * 4];
  22115. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22116. if (ctx == NULL)
  22117. return MEMORY_E;
  22118. #endif
  22119. cipherSz = 0;
  22120. EVP_CIPHER_CTX_init(ctx);
  22121. ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 1);
  22122. if (ret == WOLFSSL_SUCCESS) {
  22123. ret = EVP_CipherUpdate(ctx, cipher, &idx, (byte*)msg, sizeof(msg));
  22124. if (ret == WOLFSSL_SUCCESS)
  22125. cipherSz += idx;
  22126. }
  22127. if (ret == WOLFSSL_SUCCESS) {
  22128. ret = EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22129. if (ret == WOLFSSL_SUCCESS)
  22130. cipherSz += idx;
  22131. }
  22132. EVP_CIPHER_CTX_cleanup(ctx);
  22133. if (ret != WOLFSSL_SUCCESS)
  22134. return WC_TEST_RET_ENC_NC;
  22135. if (cipherSz != (int)sizeof(verify) || XMEMCMP(cipher, verify, cipherSz))
  22136. return WC_TEST_RET_ENC_NC;
  22137. /* check partial decrypt (not enough padding for full block) */
  22138. plainSz = 0;
  22139. EVP_CIPHER_CTX_init(ctx);
  22140. ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 0);
  22141. if (ret == WOLFSSL_SUCCESS) {
  22142. ret = EVP_CipherUpdate(ctx, plain, &idx, cipher, 1);
  22143. if (ret == WOLFSSL_SUCCESS)
  22144. plainSz += idx;
  22145. }
  22146. if (ret == WOLFSSL_SUCCESS) {
  22147. /* this test should fail... not enough padding for full block */
  22148. ret = EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22149. if (plainSz == 0 && ret != WOLFSSL_SUCCESS)
  22150. ret = WOLFSSL_SUCCESS;
  22151. else
  22152. ret = WC_TEST_RET_ENC_NC;
  22153. }
  22154. else
  22155. ret = WC_TEST_RET_ENC_NC;
  22156. EVP_CIPHER_CTX_cleanup(ctx);
  22157. if (ret != WOLFSSL_SUCCESS)
  22158. return ret;
  22159. plainSz = 0;
  22160. EVP_CIPHER_CTX_init(ctx);
  22161. ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 0);
  22162. if (ret == WOLFSSL_SUCCESS) {
  22163. ret = EVP_CipherUpdate(ctx, plain, &idx, cipher, cipherSz);
  22164. if (ret == WOLFSSL_SUCCESS)
  22165. plainSz += idx;
  22166. }
  22167. if (ret == WOLFSSL_SUCCESS) {
  22168. ret = EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22169. if (ret == WOLFSSL_SUCCESS)
  22170. plainSz += idx;
  22171. }
  22172. EVP_CIPHER_CTX_cleanup(ctx);
  22173. if (ret != WOLFSSL_SUCCESS)
  22174. return WC_TEST_RET_ENC_NC;
  22175. if (plainSz != (int)sizeof(msg) || XMEMCMP(plain, msg, sizeof(msg)))
  22176. return WC_TEST_RET_ENC_NC;
  22177. cipherSz = 0;
  22178. EVP_CIPHER_CTX_init(ctx);
  22179. ret = EVP_CipherInit(ctx, EVP_aes_128_cbc(), key, iv, 1);
  22180. if (ret == WOLFSSL_SUCCESS) {
  22181. ret = EVP_CipherUpdate(ctx, cipher, &idx, msg, AES_BLOCK_SIZE);
  22182. if (ret == WOLFSSL_SUCCESS)
  22183. cipherSz += idx;
  22184. }
  22185. if (ret == WOLFSSL_SUCCESS) {
  22186. ret = EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22187. if (ret == WOLFSSL_SUCCESS)
  22188. cipherSz += idx;
  22189. }
  22190. EVP_CIPHER_CTX_cleanup(ctx);
  22191. if (ret != WOLFSSL_SUCCESS)
  22192. return WC_TEST_RET_ENC_NC;
  22193. if (cipherSz != (int)sizeof(verify2) || XMEMCMP(cipher, verify2, cipherSz))
  22194. return WC_TEST_RET_ENC_NC;
  22195. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22196. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22197. #endif
  22198. } /* end evp_cipher test: EVP_aes_128_cbc*/
  22199. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22200. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  22201. { /* evp_cipher test: EVP_aes_256_ecb*/
  22202. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22203. EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22204. #else
  22205. EVP_CIPHER_CTX ctx[1];
  22206. #endif
  22207. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  22208. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22209. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22210. };
  22211. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22212. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22213. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22214. };
  22215. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  22216. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22217. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22218. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22219. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22220. };
  22221. byte cipher[AES_BLOCK_SIZE * 4];
  22222. byte plain [AES_BLOCK_SIZE * 4];
  22223. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22224. if (ctx == NULL)
  22225. return MEMORY_E;
  22226. #endif
  22227. EVP_CIPHER_CTX_init(ctx);
  22228. ret = EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1);
  22229. if (ret == WOLFSSL_SUCCESS)
  22230. ret = EVP_Cipher(ctx, cipher, (byte*)msg, 16);
  22231. EVP_CIPHER_CTX_cleanup(ctx);
  22232. if (ret != 16)
  22233. return WC_TEST_RET_ENC_NC;
  22234. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22235. return WC_TEST_RET_ENC_NC;
  22236. EVP_CIPHER_CTX_init(ctx);
  22237. ret = EVP_CipherInit(ctx, EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0);
  22238. if (ret == WOLFSSL_SUCCESS)
  22239. ret = EVP_Cipher(ctx, plain, cipher, 16);
  22240. EVP_CIPHER_CTX_cleanup(ctx);
  22241. if (ret != 16)
  22242. return WC_TEST_RET_ENC_NC;
  22243. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22244. return WC_TEST_RET_ENC_NC;
  22245. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22246. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22247. #endif
  22248. } /* end evp_cipher test */
  22249. #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */
  22250. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  22251. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  22252. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  22253. {
  22254. /* Test: AES_encrypt/decrypt/set Key */
  22255. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22256. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22257. #ifdef HAVE_AES_DECRYPT
  22258. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22259. #endif
  22260. #else
  22261. AES_KEY enc[1];
  22262. #ifdef HAVE_AES_DECRYPT
  22263. AES_KEY dec[1];
  22264. #endif
  22265. #endif
  22266. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  22267. {
  22268. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22269. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22270. };
  22271. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  22272. {
  22273. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22274. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22275. };
  22276. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22277. {
  22278. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22279. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22280. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22281. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22282. };
  22283. byte plain[sizeof(msg)];
  22284. byte cipher[sizeof(msg)];
  22285. printf("openSSL extra test\n") ;
  22286. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22287. if (enc == NULL)
  22288. return MEMORY_E;
  22289. #ifdef HAVE_AES_DECRYPT
  22290. if (dec == NULL)
  22291. return MEMORY_E;
  22292. #endif
  22293. #endif
  22294. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  22295. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  22296. AES_encrypt(msg, cipher, enc);
  22297. #ifdef HAVE_AES_DECRYPT
  22298. AES_decrypt(cipher, plain, dec);
  22299. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22300. return WC_TEST_RET_ENC_NC;
  22301. #endif /* HAVE_AES_DECRYPT */
  22302. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22303. return WC_TEST_RET_ENC_NC;
  22304. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22305. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22306. #ifdef HAVE_AES_DECRYPT
  22307. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22308. #endif
  22309. #endif
  22310. }
  22311. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  22312. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  22313. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  22314. #ifdef WOLFSSL_AES_COUNTER
  22315. {
  22316. byte plainBuff [64];
  22317. byte cipherBuff[64];
  22318. #ifdef WOLFSSL_AES_128
  22319. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  22320. {
  22321. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  22322. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  22323. };
  22324. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  22325. {
  22326. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22327. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22328. };
  22329. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  22330. {
  22331. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22332. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22333. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22334. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22335. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22336. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22337. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22338. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22339. };
  22340. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  22341. {
  22342. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  22343. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  22344. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  22345. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  22346. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  22347. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  22348. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  22349. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  22350. };
  22351. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  22352. {
  22353. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  22354. 0xc2
  22355. };
  22356. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22357. EVP_CIPHER_CTX *p_en;
  22358. EVP_CIPHER_CTX *p_de;
  22359. #endif
  22360. #endif /* WOLFSSL_AES_128 */
  22361. #ifdef WOLFSSL_AES_192
  22362. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22363. * NIST Special Publication 800-38A */
  22364. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  22365. {
  22366. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  22367. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  22368. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  22369. };
  22370. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  22371. {
  22372. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22373. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22374. };
  22375. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  22376. {
  22377. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22378. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22379. };
  22380. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  22381. {
  22382. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  22383. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  22384. };
  22385. #endif /* WOLFSSL_AES_192 */
  22386. #ifdef WOLFSSL_AES_256
  22387. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22388. * NIST Special Publication 800-38A */
  22389. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  22390. {
  22391. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22392. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22393. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22394. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22395. };
  22396. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  22397. {
  22398. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22399. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22400. };
  22401. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  22402. {
  22403. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22404. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22405. };
  22406. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  22407. {
  22408. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  22409. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  22410. };
  22411. #endif /* WOLFSSL_AES_256 */
  22412. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22413. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22414. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22415. if ((en == NULL) || (de == NULL))
  22416. return MEMORY_E;
  22417. #else
  22418. EVP_CIPHER_CTX en[1];
  22419. EVP_CIPHER_CTX de[1];
  22420. #endif
  22421. #ifdef WOLFSSL_AES_128
  22422. EVP_CIPHER_CTX_init(en);
  22423. if (EVP_CipherInit(en, EVP_aes_128_ctr(),
  22424. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22425. return WC_TEST_RET_ENC_NC;
  22426. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  22427. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22428. return WC_TEST_RET_ENC_NC;
  22429. EVP_CIPHER_CTX_init(de);
  22430. if (EVP_CipherInit(de, EVP_aes_128_ctr(),
  22431. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22432. return WC_TEST_RET_ENC_NC;
  22433. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22434. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22435. return WC_TEST_RET_ENC_NC;
  22436. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22437. return WC_TEST_RET_ENC_NC;
  22438. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22439. return WC_TEST_RET_ENC_NC;
  22440. EVP_CIPHER_CTX_cleanup(en);
  22441. EVP_CIPHER_CTX_cleanup(de);
  22442. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22443. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  22444. if (p_en == NULL)
  22445. return WC_TEST_RET_ENC_ERRNO;
  22446. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  22447. if (p_de == NULL)
  22448. return WC_TEST_RET_ENC_ERRNO;
  22449. if (EVP_CipherInit(p_en, EVP_aes_128_ctr(),
  22450. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22451. return WC_TEST_RET_ENC_NC;
  22452. if (EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  22453. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22454. return WC_TEST_RET_ENC_NC;
  22455. if (EVP_CipherInit(p_de, EVP_aes_128_ctr(),
  22456. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22457. return WC_TEST_RET_ENC_NC;
  22458. if (EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  22459. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22460. return WC_TEST_RET_ENC_NC;
  22461. EVP_CIPHER_CTX_cleanup(p_en);
  22462. EVP_CIPHER_CTX_cleanup(p_de);
  22463. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  22464. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  22465. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  22466. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22467. return WC_TEST_RET_ENC_NC;
  22468. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22469. return WC_TEST_RET_ENC_NC;
  22470. EVP_CIPHER_CTX_init(en);
  22471. if (EVP_CipherInit(en, EVP_aes_128_ctr(),
  22472. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22473. return WC_TEST_RET_ENC_NC;
  22474. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22475. return WC_TEST_RET_ENC_NC;
  22476. EVP_CIPHER_CTX_init(de);
  22477. if (EVP_CipherInit(de, EVP_aes_128_ctr(),
  22478. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22479. return WC_TEST_RET_ENC_NC;
  22480. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22481. return WC_TEST_RET_ENC_NC;
  22482. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22483. return WC_TEST_RET_ENC_NC;
  22484. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  22485. return WC_TEST_RET_ENC_NC;
  22486. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22487. return WC_TEST_RET_ENC_NC;
  22488. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22489. return WC_TEST_RET_ENC_NC;
  22490. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22491. return WC_TEST_RET_ENC_NC;
  22492. if (XMEMCMP(cipherBuff, oddCipher, 9))
  22493. return WC_TEST_RET_ENC_NC;
  22494. EVP_CIPHER_CTX_cleanup(en);
  22495. EVP_CIPHER_CTX_cleanup(de);
  22496. #endif /* WOLFSSL_AES_128 */
  22497. #ifdef WOLFSSL_AES_192
  22498. EVP_CIPHER_CTX_init(en);
  22499. if (EVP_CipherInit(en, EVP_aes_192_ctr(),
  22500. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22501. return WC_TEST_RET_ENC_NC;
  22502. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  22503. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22504. return WC_TEST_RET_ENC_NC;
  22505. EVP_CIPHER_CTX_init(de);
  22506. if (EVP_CipherInit(de, EVP_aes_192_ctr(),
  22507. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22508. return WC_TEST_RET_ENC_NC;
  22509. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22510. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22511. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22512. return WC_TEST_RET_ENC_NC;
  22513. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  22514. return WC_TEST_RET_ENC_NC;
  22515. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  22516. return WC_TEST_RET_ENC_NC;
  22517. EVP_CIPHER_CTX_cleanup(en);
  22518. EVP_CIPHER_CTX_cleanup(de);
  22519. #endif /* WOLFSSL_AES_192 */
  22520. #ifdef WOLFSSL_AES_256
  22521. EVP_CIPHER_CTX_init(en);
  22522. if (EVP_CipherInit(en, EVP_aes_256_ctr(),
  22523. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22524. return WC_TEST_RET_ENC_NC;
  22525. if (EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  22526. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22527. return WC_TEST_RET_ENC_NC;
  22528. EVP_CIPHER_CTX_init(de);
  22529. if (EVP_CipherInit(de, EVP_aes_256_ctr(),
  22530. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22531. return WC_TEST_RET_ENC_NC;
  22532. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22533. if (EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22534. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22535. return WC_TEST_RET_ENC_NC;
  22536. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  22537. return WC_TEST_RET_ENC_NC;
  22538. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  22539. return WC_TEST_RET_ENC_NC;
  22540. EVP_CIPHER_CTX_cleanup(en);
  22541. EVP_CIPHER_CTX_cleanup(de);
  22542. #endif /* WOLFSSL_AES_256 */
  22543. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22544. wolfSSL_EVP_CIPHER_CTX_free(en);
  22545. wolfSSL_EVP_CIPHER_CTX_free(de);
  22546. #endif
  22547. }
  22548. #endif /* HAVE_AES_COUNTER */
  22549. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22550. {
  22551. /* EVP_CipherUpdate test */
  22552. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  22553. {
  22554. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22555. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22556. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22557. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22558. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22559. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22560. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22561. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22562. };
  22563. byte key[] = "0123456789abcdef "; /* align */
  22564. byte iv[] = "1234567890abcdef "; /* align */
  22565. byte cipher[AES_BLOCK_SIZE * 4];
  22566. byte plain [AES_BLOCK_SIZE * 4];
  22567. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22568. EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22569. EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22570. #else
  22571. EVP_CIPHER_CTX en[1];
  22572. EVP_CIPHER_CTX de[1];
  22573. #endif
  22574. int outlen ;
  22575. int total = 0;
  22576. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22577. if ((en == NULL) || (de == NULL))
  22578. return MEMORY_E;
  22579. #endif
  22580. EVP_CIPHER_CTX_init(en);
  22581. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  22582. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22583. return WC_TEST_RET_ENC_NC;
  22584. /* openSSL compatibility, if(inlen == 0)return 1; */
  22585. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22586. (byte*)cbcPlain, 0) != 1)
  22587. return WC_TEST_RET_ENC_NC;
  22588. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22589. return WC_TEST_RET_ENC_NC;
  22590. EVP_CIPHER_CTX_init(en);
  22591. if (EVP_CipherInit(en, EVP_aes_128_cbc(),
  22592. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22593. return WC_TEST_RET_ENC_NC;
  22594. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22595. (byte*)cbcPlain, 9) == 0)
  22596. return WC_TEST_RET_ENC_NC;
  22597. if(outlen != 0)
  22598. return WC_TEST_RET_ENC_NC;
  22599. total += outlen;
  22600. if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  22601. (byte*)&cbcPlain[9] , 9) == 0)
  22602. return WC_TEST_RET_ENC_NC;
  22603. if(outlen != 16)
  22604. return WC_TEST_RET_ENC_NC;
  22605. total += outlen;
  22606. if (EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22607. return WC_TEST_RET_ENC_NC;
  22608. if(outlen != 16)
  22609. return WC_TEST_RET_ENC_NC;
  22610. total += outlen;
  22611. if(total != 32)
  22612. return WC_TEST_RET_ENC_NC;
  22613. total = 0;
  22614. EVP_CIPHER_CTX_init(de);
  22615. if (EVP_CipherInit(de, EVP_aes_128_cbc(),
  22616. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22617. return WC_TEST_RET_ENC_NC;
  22618. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22619. return WC_TEST_RET_ENC_NC;
  22620. if(outlen != 0)
  22621. return WC_TEST_RET_ENC_NC;
  22622. total += outlen;
  22623. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22624. (byte*)&cipher[6], 12) == 0)
  22625. return WC_TEST_RET_ENC_NC;
  22626. if(outlen != 0)
  22627. total += outlen;
  22628. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22629. (byte*)&cipher[6+12], 14) == 0)
  22630. return WC_TEST_RET_ENC_NC;
  22631. if(outlen != 16)
  22632. return WC_TEST_RET_ENC_NC;
  22633. total += outlen;
  22634. if (EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  22635. return WC_TEST_RET_ENC_NC;
  22636. if(outlen != 2)
  22637. return WC_TEST_RET_ENC_NC;
  22638. total += outlen;
  22639. if(total != 18)
  22640. return WC_TEST_RET_ENC_NC;
  22641. if (XMEMCMP(plain, cbcPlain, 18))
  22642. return WC_TEST_RET_ENC_NC;
  22643. total = 0;
  22644. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22645. return WC_TEST_RET_ENC_NC;
  22646. EVP_CIPHER_CTX_init(en);
  22647. if (EVP_EncryptInit(en, EVP_aes_128_cbc(),
  22648. (unsigned char*)key, (unsigned char*)iv) == 0)
  22649. return WC_TEST_RET_ENC_NC;
  22650. if (EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0)
  22651. return WC_TEST_RET_ENC_NC;
  22652. if(outlen != 0)
  22653. return WC_TEST_RET_ENC_NC;
  22654. total += outlen;
  22655. if (EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0)
  22656. return WC_TEST_RET_ENC_NC;
  22657. if(outlen != 16)
  22658. return WC_TEST_RET_ENC_NC;
  22659. total += outlen;
  22660. if (EVP_EncryptFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22661. return WC_TEST_RET_ENC_NC;
  22662. if(outlen != 16)
  22663. return WC_TEST_RET_ENC_NC;
  22664. total += outlen;
  22665. if(total != 32)
  22666. return 3438;
  22667. total = 0;
  22668. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22669. return WC_TEST_RET_ENC_NC;
  22670. EVP_CIPHER_CTX_init(de);
  22671. if (EVP_DecryptInit(de, EVP_aes_128_cbc(),
  22672. (unsigned char*)key, (unsigned char*)iv) == 0)
  22673. return WC_TEST_RET_ENC_NC;
  22674. if (EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22675. return WC_TEST_RET_ENC_NC;
  22676. if(outlen != 0)
  22677. return WC_TEST_RET_ENC_NC;
  22678. total += outlen;
  22679. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0)
  22680. return WC_TEST_RET_ENC_NC;
  22681. if(outlen != 0)
  22682. total += outlen;
  22683. if (EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0)
  22684. return WC_TEST_RET_ENC_NC;
  22685. if(outlen != 16)
  22686. return WC_TEST_RET_ENC_NC;
  22687. total += outlen;
  22688. if (EVP_DecryptFinal(de, (byte*)&plain[total], &outlen) == 0)
  22689. return WC_TEST_RET_ENC_NC;
  22690. if(outlen != 2)
  22691. return WC_TEST_RET_ENC_NC;
  22692. total += outlen;
  22693. if(total != 18)
  22694. return 3447;
  22695. if (XMEMCMP(plain, cbcPlain, 18))
  22696. return WC_TEST_RET_ENC_NC;
  22697. if (EVP_CIPHER_key_length(NULL) != 0)
  22698. return WC_TEST_RET_ENC_NC;
  22699. if (EVP_CIPHER_key_length(EVP_aes_128_cbc()) != 16)
  22700. return WC_TEST_RET_ENC_NC;
  22701. if (EVP_CIPHER_CTX_mode(NULL) != 0)
  22702. return WC_TEST_RET_ENC_NC;
  22703. if (EVP_CIPHER_CTX_mode(en) != (en->flags & WOLFSSL_EVP_CIPH_MODE))
  22704. return WC_TEST_RET_ENC_NC;
  22705. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22706. return WC_TEST_RET_ENC_NC;
  22707. EVP_CIPHER_CTX_init(en);
  22708. if (EVP_CipherInit_ex(en, EVP_aes_128_cbc(), NULL,
  22709. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22710. return WC_TEST_RET_ENC_NC;
  22711. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22712. return WC_TEST_RET_ENC_NC;
  22713. EVP_CIPHER_CTX_init(en);
  22714. if (EVP_EncryptInit_ex(en, EVP_aes_128_cbc(), NULL,
  22715. (unsigned char*)key, (unsigned char*)iv) == 0)
  22716. return WC_TEST_RET_ENC_NC;
  22717. if (wolfSSL_EVP_EncryptFinal_ex(NULL, NULL, NULL)
  22718. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22719. {
  22720. return WC_TEST_RET_ENC_NC;
  22721. }
  22722. if (wolfSSL_EVP_EncryptFinal(NULL, NULL, NULL)
  22723. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22724. {
  22725. return WC_TEST_RET_ENC_NC;
  22726. }
  22727. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22728. return WC_TEST_RET_ENC_NC;
  22729. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22730. return WC_TEST_RET_ENC_NC;
  22731. EVP_CIPHER_CTX_init(de);
  22732. if (EVP_DecryptInit_ex(de, EVP_aes_128_cbc(), NULL,
  22733. (unsigned char*)key, (unsigned char*)iv) == 0)
  22734. return WC_TEST_RET_ENC_NC;
  22735. if (wolfSSL_EVP_DecryptFinal(NULL, NULL, NULL)
  22736. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22737. {
  22738. return WC_TEST_RET_ENC_NC;
  22739. }
  22740. if (wolfSSL_EVP_DecryptFinal_ex(NULL, NULL, NULL)
  22741. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22742. {
  22743. return WC_TEST_RET_ENC_NC;
  22744. }
  22745. if (EVP_CIPHER_CTX_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22746. return WC_TEST_RET_ENC_NC;
  22747. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22748. return WC_TEST_RET_ENC_NC;
  22749. EVP_CIPHER_CTX_init(en);
  22750. EVP_EncryptInit_ex(en, EVP_aes_128_cbc(), NULL,
  22751. (unsigned char*)key, (unsigned char*)iv);
  22752. if (EVP_CIPHER_CTX_block_size(en) != en->block_size)
  22753. return WC_TEST_RET_ENC_NC;
  22754. if (EVP_CIPHER_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22755. return WC_TEST_RET_ENC_NC;
  22756. if (EVP_CIPHER_block_size(EVP_aes_128_cbc()) != AES_BLOCK_SIZE)
  22757. return WC_TEST_RET_ENC_NC;
  22758. if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0)
  22759. return WC_TEST_RET_ENC_NC;
  22760. if (EVP_CIPHER_flags(EVP_aes_128_cbc()) != WOLFSSL_EVP_CIPH_CBC_MODE)
  22761. return WC_TEST_RET_ENC_NC;
  22762. EVP_CIPHER_CTX_clear_flags(en, 0xFFFFFFFF);
  22763. EVP_CIPHER_CTX_set_flags(en, 42);
  22764. if (en->flags != 42)
  22765. return WC_TEST_RET_ENC_NC;
  22766. if (EVP_CIPHER_CTX_set_padding(NULL, 0) !=
  22767. WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22768. return WC_TEST_RET_ENC_NC;
  22769. if (EVP_CIPHER_CTX_set_padding(en, 0) != WOLFSSL_SUCCESS)
  22770. return WC_TEST_RET_ENC_NC;
  22771. if (EVP_CIPHER_CTX_set_padding(en, 1) != WOLFSSL_SUCCESS)
  22772. return WC_TEST_RET_ENC_NC;
  22773. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22774. return WC_TEST_RET_ENC_NC;
  22775. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22776. return WC_TEST_RET_ENC_NC;
  22777. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22778. wolfSSL_EVP_CIPHER_CTX_free(en);
  22779. wolfSSL_EVP_CIPHER_CTX_free(de);
  22780. #endif
  22781. }
  22782. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22783. #endif /* ifndef NO_AES */
  22784. return 0;
  22785. }
  22786. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void)
  22787. {
  22788. wc_test_ret_t ret = 0;
  22789. #if !defined(NO_SHA256) && !defined(NO_SHA)
  22790. WOLFSSL_EVP_MD_CTX* ctx;
  22791. WOLFSSL_EVP_MD_CTX* ctx2;
  22792. WOLFSSL_ENTER("openSSL_evpMD_test");
  22793. ctx = EVP_MD_CTX_create();
  22794. ctx2 = EVP_MD_CTX_create();
  22795. ret = EVP_DigestInit(ctx, EVP_sha256());
  22796. if (ret != SSL_SUCCESS) {
  22797. ret = WC_TEST_RET_ENC_NC;
  22798. goto openSSL_evpMD_test_done;
  22799. }
  22800. ret = EVP_MD_CTX_copy(ctx2, ctx);
  22801. if (ret != SSL_SUCCESS) {
  22802. ret = WC_TEST_RET_ENC_NC;
  22803. goto openSSL_evpMD_test_done;
  22804. }
  22805. if (EVP_MD_type(EVP_sha256()) != EVP_MD_CTX_type(ctx2)) {
  22806. ret = WC_TEST_RET_ENC_NC;
  22807. goto openSSL_evpMD_test_done;
  22808. }
  22809. ret = EVP_DigestInit(ctx, EVP_sha1());
  22810. if (ret != SSL_SUCCESS) {
  22811. ret = WC_TEST_RET_ENC_NC;
  22812. goto openSSL_evpMD_test_done;
  22813. }
  22814. if (EVP_MD_type(EVP_sha256()) != EVP_MD_CTX_type(ctx2)) {
  22815. ret = WC_TEST_RET_ENC_NC;
  22816. goto openSSL_evpMD_test_done;
  22817. }
  22818. ret = EVP_MD_CTX_copy_ex(ctx2, ctx);
  22819. if (ret != SSL_SUCCESS) {
  22820. ret = WC_TEST_RET_ENC_NC;
  22821. goto openSSL_evpMD_test_done;
  22822. }
  22823. if (EVP_MD_type(EVP_sha256()) == EVP_MD_CTX_type(ctx2)) {
  22824. ret = WC_TEST_RET_ENC_NC;
  22825. goto openSSL_evpMD_test_done;
  22826. }
  22827. if (EVP_MD_type(EVP_sha1()) != EVP_MD_CTX_type(ctx2)) {
  22828. ret = WC_TEST_RET_ENC_NC;
  22829. goto openSSL_evpMD_test_done;
  22830. }
  22831. if (EVP_DigestInit_ex(ctx, EVP_sha1(), NULL) != SSL_SUCCESS) {
  22832. ret = WC_TEST_RET_ENC_NC;
  22833. goto openSSL_evpMD_test_done;
  22834. }
  22835. if (EVP_add_digest(NULL) != 0) {
  22836. ret = WC_TEST_RET_ENC_NC;
  22837. goto openSSL_evpMD_test_done;
  22838. }
  22839. if (wolfSSL_EVP_add_cipher(NULL) != 0) {
  22840. ret = WC_TEST_RET_ENC_NC;
  22841. goto openSSL_evpMD_test_done;
  22842. }
  22843. ret = 0; /* got to success state without jumping to end with a fail */
  22844. openSSL_evpMD_test_done:
  22845. EVP_MD_CTX_destroy(ctx);
  22846. EVP_MD_CTX_destroy(ctx2);
  22847. #endif /* NO_SHA256 */
  22848. return ret;
  22849. }
  22850. #ifdef DEBUG_SIGN
  22851. static void show(const char *title, const char *p, unsigned int s) {
  22852. char* i;
  22853. printf("%s: ", title);
  22854. for (i = p;
  22855. i < p + s;
  22856. printf("%c", *i), i++);
  22857. printf("\n");
  22858. }
  22859. #else
  22860. #define show(a,b,c) WC_DO_NOTHING
  22861. #endif
  22862. #define FOURK_BUFF 4096
  22863. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void)
  22864. {
  22865. wc_test_ret_t ret = 0;
  22866. #if !defined(NO_RSA) && !defined(NO_SHA)
  22867. byte* prvTmp;
  22868. byte* pubTmp;
  22869. int prvBytes;
  22870. int pubBytes;
  22871. RSA *prvRsa = NULL;
  22872. RSA *pubRsa = NULL;
  22873. EVP_PKEY *prvPkey = NULL;
  22874. EVP_PKEY *pubPkey = NULL;
  22875. EVP_PKEY_CTX *enc = NULL;
  22876. EVP_PKEY_CTX *dec = NULL;
  22877. byte in[] = TEST_STRING;
  22878. byte out[256];
  22879. size_t outlen;
  22880. size_t keySz;
  22881. byte plain[256];
  22882. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  22883. XFILE keyFile;
  22884. XFILE keypubFile;
  22885. char cliKey[] = "./certs/client-key.der";
  22886. char cliKeypub[] = "./certs/client-keyPub.der";
  22887. #endif
  22888. WOLFSSL_ENTER("openssl_pkey0_test");
  22889. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22890. if (prvTmp == NULL)
  22891. return WC_TEST_RET_ENC_ERRNO;
  22892. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22893. if (pubTmp == NULL) {
  22894. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22895. return WC_TEST_RET_ENC_NC;
  22896. }
  22897. #ifdef USE_CERT_BUFFERS_1024
  22898. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  22899. prvBytes = sizeof_client_key_der_1024;
  22900. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  22901. pubBytes = sizeof_client_keypub_der_1024;
  22902. #elif defined(USE_CERT_BUFFERS_2048)
  22903. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  22904. prvBytes = sizeof_client_key_der_2048;
  22905. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  22906. pubBytes = sizeof_client_keypub_der_2048;
  22907. #else
  22908. keyFile = XFOPEN(cliKey, "rb");
  22909. if (!keyFile) {
  22910. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22911. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22912. err_sys("can't open ./certs/client-key.der, "
  22913. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  22914. return WC_TEST_RET_ENC_ERRNO;
  22915. }
  22916. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  22917. XFCLOSE(keyFile);
  22918. if (prvBytes == 0) {
  22919. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22920. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22921. return WC_TEST_RET_ENC_ERRNO;
  22922. }
  22923. keypubFile = XFOPEN(cliKeypub, "rb");
  22924. if (!keypubFile) {
  22925. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22926. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22927. err_sys("can't open ./certs/client-cert.der, "
  22928. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  22929. return WC_TEST_RET_ENC_ERRNO;
  22930. }
  22931. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  22932. XFCLOSE(keypubFile);
  22933. if (pubBytes == 0) {
  22934. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22935. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22936. return WC_TEST_RET_ENC_ERRNO;
  22937. }
  22938. #endif /* USE_CERT_BUFFERS */
  22939. prvRsa = wolfSSL_RSA_new();
  22940. pubRsa = wolfSSL_RSA_new();
  22941. if((prvRsa == NULL) || (pubRsa == NULL)){
  22942. printf("error with RSA_new\n");
  22943. ret = WC_TEST_RET_ENC_ERRNO;
  22944. goto openssl_pkey0_test_done;
  22945. }
  22946. ret = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  22947. if(ret != SSL_SUCCESS){
  22948. printf("error with RSA_LoadDer_ex\n");
  22949. ret = WC_TEST_RET_ENC_EC(ret);
  22950. goto openssl_pkey0_test_done;
  22951. }
  22952. ret = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  22953. if(ret != SSL_SUCCESS){
  22954. printf("error with RSA_LoadDer_ex\n");
  22955. ret = WC_TEST_RET_ENC_EC(ret);
  22956. goto openssl_pkey0_test_done;
  22957. }
  22958. keySz = (size_t)RSA_size(pubRsa);
  22959. prvPkey = wolfSSL_EVP_PKEY_new();
  22960. pubPkey = wolfSSL_EVP_PKEY_new();
  22961. if((prvPkey == NULL) || (pubPkey == NULL)){
  22962. printf("error with PKEY_new\n");
  22963. ret = WC_TEST_RET_ENC_NC;
  22964. goto openssl_pkey0_test_done;
  22965. }
  22966. ret = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  22967. ret += wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  22968. if(ret != 2){
  22969. printf("error with PKEY_set1_RSA\n");
  22970. ret = WC_TEST_RET_ENC_I(ret);
  22971. goto openssl_pkey0_test_done;
  22972. }
  22973. dec = EVP_PKEY_CTX_new(prvPkey, NULL);
  22974. enc = EVP_PKEY_CTX_new(pubPkey, NULL);
  22975. if((dec == NULL)||(enc==NULL)){
  22976. printf("error with EVP_PKEY_CTX_new\n");
  22977. ret = WC_TEST_RET_ENC_NC;
  22978. goto openssl_pkey0_test_done;
  22979. }
  22980. ret = EVP_PKEY_decrypt_init(dec);
  22981. if (ret != 1) {
  22982. printf("error with decrypt init\n");
  22983. ret = WC_TEST_RET_ENC_NC;
  22984. goto openssl_pkey0_test_done;
  22985. }
  22986. ret = EVP_PKEY_encrypt_init(enc);
  22987. if (ret != 1) {
  22988. printf("error with encrypt init\n");
  22989. ret = WC_TEST_RET_ENC_NC;
  22990. goto openssl_pkey0_test_done;
  22991. }
  22992. XMEMSET(out, 0, sizeof(out));
  22993. ret = EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  22994. if (ret != 1) {
  22995. printf("error encrypting msg\n");
  22996. ret = WC_TEST_RET_ENC_NC;
  22997. goto openssl_pkey0_test_done;
  22998. }
  22999. show("encrypted msg", out, outlen);
  23000. XMEMSET(plain, 0, sizeof(plain));
  23001. ret = EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23002. if (ret != 1) {
  23003. printf("error decrypting msg\n");
  23004. ret = WC_TEST_RET_ENC_NC;
  23005. goto openssl_pkey0_test_done;
  23006. }
  23007. show("decrypted msg", plain, outlen);
  23008. /* RSA_PKCS1_OAEP_PADDING test */
  23009. ret = EVP_PKEY_decrypt_init(dec);
  23010. if (ret != 1) {
  23011. printf("error with decrypt init\n");
  23012. ret = WC_TEST_RET_ENC_NC;
  23013. goto openssl_pkey0_test_done;
  23014. }
  23015. ret = EVP_PKEY_encrypt_init(enc);
  23016. if (ret != 1) {
  23017. printf("error with encrypt init\n");
  23018. ret = WC_TEST_RET_ENC_NC;
  23019. goto openssl_pkey0_test_done;
  23020. }
  23021. if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_PADDING) <= 0) {
  23022. printf("first set rsa padding error\n");
  23023. ret = WC_TEST_RET_ENC_EC(ret);
  23024. goto openssl_pkey0_test_done;
  23025. }
  23026. #ifndef HAVE_FIPS
  23027. if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_OAEP_PADDING) <= 0){
  23028. printf("second set rsa padding error\n");
  23029. ret = WC_TEST_RET_ENC_EC(ret);
  23030. goto openssl_pkey0_test_done;
  23031. }
  23032. if (EVP_PKEY_CTX_set_rsa_padding(enc, RSA_PKCS1_OAEP_PADDING) <= 0) {
  23033. printf("third set rsa padding error\n");
  23034. ret = WC_TEST_RET_ENC_EC(ret);
  23035. goto openssl_pkey0_test_done;
  23036. }
  23037. #endif
  23038. XMEMSET(out, 0, sizeof(out));
  23039. ret = EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23040. if (ret != 1) {
  23041. printf("error encrypting msg\n");
  23042. ret = WC_TEST_RET_ENC_NC;
  23043. goto openssl_pkey0_test_done;
  23044. }
  23045. show("encrypted msg", out, outlen);
  23046. XMEMSET(plain, 0, sizeof(plain));
  23047. ret = EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23048. if (ret != 1) {
  23049. printf("error decrypting msg\n");
  23050. ret = WC_TEST_RET_ENC_NC;
  23051. goto openssl_pkey0_test_done;
  23052. }
  23053. show("decrypted msg", plain, outlen);
  23054. ret = 0; /* made it to this point without error then set success */
  23055. openssl_pkey0_test_done:
  23056. wolfSSL_RSA_free(prvRsa);
  23057. wolfSSL_RSA_free(pubRsa);
  23058. EVP_PKEY_free(pubPkey);
  23059. EVP_PKEY_free(prvPkey);
  23060. EVP_PKEY_CTX_free(dec);
  23061. EVP_PKEY_CTX_free(enc);
  23062. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23063. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23064. #endif /* NO_RSA */
  23065. return ret;
  23066. }
  23067. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void)
  23068. {
  23069. wc_test_ret_t ret = 0;
  23070. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_SHA)
  23071. EVP_PKEY_CTX* dec = NULL;
  23072. EVP_PKEY_CTX* enc = NULL;
  23073. EVP_PKEY* pubKey = NULL;
  23074. EVP_PKEY* prvKey = NULL;
  23075. X509* x509 = NULL;
  23076. WOLFSSL_SMALL_STACK_STATIC const unsigned char msg[] = "sugar slapped";
  23077. const unsigned char* clikey;
  23078. long cliKeySz;
  23079. size_t outlen;
  23080. int keyLenBits = 2048;
  23081. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23082. unsigned char *tmp = (unsigned char *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23083. unsigned char *cipher = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23084. unsigned char *plain = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23085. if ((tmp == NULL) ||
  23086. (cipher == NULL) ||
  23087. (plain == NULL)) {
  23088. ret = WC_TEST_RET_ENC_NC;
  23089. goto openssl_pkey1_test_done;
  23090. }
  23091. #else
  23092. unsigned char tmp[FOURK_BUF];
  23093. unsigned char cipher[RSA_TEST_BYTES];
  23094. unsigned char plain[RSA_TEST_BYTES];
  23095. #endif
  23096. WOLFSSL_ENTER("openssl_pkey1_test");
  23097. #if defined(USE_CERT_BUFFERS_1024)
  23098. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  23099. cliKeySz = (long)sizeof_client_key_der_1024;
  23100. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_1024,
  23101. sizeof_client_cert_der_1024, SSL_FILETYPE_ASN1);
  23102. keyLenBits = 1024;
  23103. #elif defined(USE_CERT_BUFFERS_2048)
  23104. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  23105. cliKeySz = (long)sizeof_client_key_der_2048;
  23106. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_2048,
  23107. sizeof_client_cert_der_2048, SSL_FILETYPE_ASN1);
  23108. #elif defined(USE_CERT_BUFFERS_3072)
  23109. XMEMCPY(tmp, client_key_der_3072, sizeof_client_key_der_3072);
  23110. cliKeySz = (long)sizeof_client_key_der_3072;
  23111. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_3072,
  23112. sizeof_client_cert_der_3072, SSL_FILETYPE_ASN1);
  23113. keyLenBits = 3072;
  23114. #elif defined(USE_CERT_BUFFERS_4096)
  23115. XMEMCPY(tmp, client_key_der_4096, sizeof_client_key_der_4096);
  23116. cliKeySz = (long)sizeof_client_key_der_4096;
  23117. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_4096,
  23118. sizeof_client_cert_der_4096, SSL_FILETYPE_ASN1);
  23119. keyLenBits = 4096;
  23120. #else
  23121. {
  23122. XFILE f;
  23123. f = XFOPEN(clientKey, "rb");
  23124. if (!f) {
  23125. err_sys("can't open ./certs/client-key.der, "
  23126. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23127. ret = WC_TEST_RET_ENC_ERRNO;
  23128. goto openssl_pkey1_test_done;
  23129. }
  23130. cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f);
  23131. XFCLOSE(f);
  23132. if (cliKeySz == 0)
  23133. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, openssl_pkey1_test_done);
  23134. }
  23135. /* using existing wolfSSL api to get public and private key */
  23136. x509 = wolfSSL_X509_load_certificate_file(clientCert, SSL_FILETYPE_ASN1);
  23137. #endif /* USE_CERT_BUFFERS */
  23138. clikey = tmp;
  23139. if ((prvKey = EVP_PKEY_new()) == NULL) {
  23140. ret = WC_TEST_RET_ENC_ERRNO;
  23141. goto openssl_pkey1_test_done;
  23142. }
  23143. EVP_PKEY_free(prvKey);
  23144. prvKey = NULL;
  23145. if (x509 == NULL) {
  23146. ret = WC_TEST_RET_ENC_NC;
  23147. goto openssl_pkey1_test_done;
  23148. }
  23149. pubKey = X509_get_pubkey(x509);
  23150. if (pubKey == NULL) {
  23151. ret = WC_TEST_RET_ENC_NC;
  23152. goto openssl_pkey1_test_done;
  23153. }
  23154. prvKey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &clikey, cliKeySz);
  23155. if (prvKey == NULL) {
  23156. ret = WC_TEST_RET_ENC_NC;
  23157. goto openssl_pkey1_test_done;
  23158. }
  23159. /* phase 2 API to create EVP_PKEY_CTX and encrypt/decrypt */
  23160. if (EVP_PKEY_bits(prvKey) != keyLenBits) {
  23161. ret = WC_TEST_RET_ENC_NC;
  23162. goto openssl_pkey1_test_done;
  23163. }
  23164. if (EVP_PKEY_size(prvKey) != keyLenBits/8) {
  23165. ret = WC_TEST_RET_ENC_NC;
  23166. goto openssl_pkey1_test_done;
  23167. }
  23168. dec = EVP_PKEY_CTX_new(prvKey, NULL);
  23169. enc = EVP_PKEY_CTX_new(pubKey, NULL);
  23170. if (dec == NULL || enc == NULL) {
  23171. ret = WC_TEST_RET_ENC_ERRNO;
  23172. goto openssl_pkey1_test_done;
  23173. }
  23174. if (EVP_PKEY_decrypt_init(dec) != 1) {
  23175. ret = WC_TEST_RET_ENC_NC;
  23176. goto openssl_pkey1_test_done;
  23177. }
  23178. if (EVP_PKEY_encrypt_init(enc) != 1) {
  23179. ret = WC_TEST_RET_ENC_NC;
  23180. goto openssl_pkey1_test_done;
  23181. }
  23182. if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_PADDING) <= 0) {
  23183. ret = WC_TEST_RET_ENC_NC;
  23184. goto openssl_pkey1_test_done;
  23185. }
  23186. #ifndef HAVE_FIPS
  23187. if (EVP_PKEY_CTX_set_rsa_padding(dec, RSA_PKCS1_OAEP_PADDING) <= 0){
  23188. ret = WC_TEST_RET_ENC_EC(ret);
  23189. goto openssl_pkey1_test_done;
  23190. }
  23191. if (EVP_PKEY_CTX_set_rsa_padding(enc, RSA_PKCS1_OAEP_PADDING) <= 0) {
  23192. ret = WC_TEST_RET_ENC_EC(ret);
  23193. goto openssl_pkey1_test_done;
  23194. }
  23195. #endif
  23196. XMEMSET(cipher, 0, RSA_TEST_BYTES);
  23197. outlen = (size_t)(keyLenBits/8);
  23198. if (EVP_PKEY_encrypt(enc, cipher, &outlen, msg, sizeof(msg)) < 0) {
  23199. ret = WC_TEST_RET_ENC_EC(ret);
  23200. goto openssl_pkey1_test_done;
  23201. }
  23202. XMEMSET(plain, 0, RSA_TEST_BYTES);
  23203. if (EVP_PKEY_decrypt(dec, plain, &outlen, cipher, outlen) != 1) {
  23204. ret = WC_TEST_RET_ENC_NC;
  23205. goto openssl_pkey1_test_done;
  23206. }
  23207. openssl_pkey1_test_done:
  23208. if (pubKey != NULL) {
  23209. EVP_PKEY_free(pubKey);
  23210. }
  23211. if (prvKey != NULL) {
  23212. EVP_PKEY_free(prvKey);
  23213. }
  23214. if (dec != NULL) {
  23215. EVP_PKEY_CTX_free(dec);
  23216. }
  23217. if (enc != NULL) {
  23218. EVP_PKEY_CTX_free(enc);
  23219. }
  23220. if (x509 != NULL) {
  23221. X509_free(x509);
  23222. }
  23223. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23224. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23225. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23226. XFREE(plain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23227. #endif
  23228. #endif
  23229. return ret;
  23230. }
  23231. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void)
  23232. {
  23233. #if !defined(NO_RSA) && !defined(NO_SHA)
  23234. byte* prvTmp;
  23235. byte* pubTmp;
  23236. int prvBytes;
  23237. int pubBytes;
  23238. RSA *prvRsa;
  23239. RSA *pubRsa;
  23240. EVP_PKEY *prvPkey;
  23241. EVP_PKEY *pubPkey;
  23242. EVP_MD_CTX* sign;
  23243. EVP_MD_CTX* verf;
  23244. char msg[] = "see spot run";
  23245. unsigned char sig[256];
  23246. unsigned int sigSz;
  23247. const void* pt;
  23248. unsigned int count;
  23249. wc_test_ret_t ret, ret1, ret2;
  23250. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  23251. XFILE keyFile;
  23252. XFILE keypubFile;
  23253. char cliKey[] = "./certs/client-key.der";
  23254. char cliKeypub[] = "./certs/client-keyPub.der";
  23255. #endif
  23256. WOLFSSL_ENTER("openssl_evpSig_test");
  23257. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23258. if (prvTmp == NULL)
  23259. return WC_TEST_RET_ENC_ERRNO;
  23260. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23261. if (pubTmp == NULL) {
  23262. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23263. return WC_TEST_RET_ENC_NC;
  23264. }
  23265. #ifdef USE_CERT_BUFFERS_1024
  23266. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  23267. prvBytes = sizeof_client_key_der_1024;
  23268. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  23269. pubBytes = sizeof_client_keypub_der_1024;
  23270. #elif defined(USE_CERT_BUFFERS_2048)
  23271. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  23272. prvBytes = sizeof_client_key_der_2048;
  23273. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  23274. pubBytes = sizeof_client_keypub_der_2048;
  23275. #else
  23276. keyFile = XFOPEN(cliKey, "rb");
  23277. if (!keyFile) {
  23278. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23279. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23280. err_sys("can't open ./certs/client-key.der, "
  23281. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23282. return WC_TEST_RET_ENC_ERRNO;
  23283. }
  23284. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23285. XFCLOSE(keyFile);
  23286. if (prvBytes == 0) {
  23287. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23288. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23289. return WC_TEST_RET_ENC_ERRNO;
  23290. }
  23291. keypubFile = XFOPEN(cliKeypub, "rb");
  23292. if (!keypubFile) {
  23293. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23294. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23295. err_sys("can't open ./certs/client-cert.der, "
  23296. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23297. return WC_TEST_RET_ENC_ERRNO;
  23298. }
  23299. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23300. XFCLOSE(keypubFile);
  23301. if (pubBytes == 0) {
  23302. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23303. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23304. return WC_TEST_RET_ENC_ERRNO;
  23305. }
  23306. #endif /* USE_CERT_BUFFERS */
  23307. prvRsa = wolfSSL_RSA_new();
  23308. pubRsa = wolfSSL_RSA_new();
  23309. if((prvRsa == NULL) || (pubRsa == NULL)){
  23310. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23311. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23312. err_sys("ERROR with RSA_new", WC_TEST_RET_ENC_NC);
  23313. return WC_TEST_RET_ENC_NC;
  23314. }
  23315. ret1 = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23316. ret2 = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23317. if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){
  23318. printf("error with RSA_LoadDer_ex\n");
  23319. return WC_TEST_RET_ENC_NC;
  23320. }
  23321. prvPkey = wolfSSL_EVP_PKEY_new();
  23322. pubPkey = wolfSSL_EVP_PKEY_new();
  23323. if((prvPkey == NULL) || (pubPkey == NULL)){
  23324. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23325. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23326. printf("error with KEY_new\n");
  23327. return WC_TEST_RET_ENC_NC;
  23328. }
  23329. ret1 = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23330. ret2 = wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23331. if((ret1 != 1) || (ret2 != 1)){
  23332. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23333. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23334. printf("error with EVP_PKEY_set1_RSA\n");
  23335. return WC_TEST_RET_ENC_NC;
  23336. }
  23337. /****************** sign and verify *******************/
  23338. sign = EVP_MD_CTX_create();
  23339. verf = EVP_MD_CTX_create();
  23340. if((sign == NULL)||(verf == NULL)){
  23341. printf("error with EVP_MD_CTX_create\n");
  23342. EVP_MD_CTX_destroy(sign);
  23343. EVP_MD_CTX_destroy(verf);
  23344. return WC_TEST_RET_ENC_NC;
  23345. }
  23346. ret = EVP_SignInit(sign, EVP_sha1());
  23347. if (ret != SSL_SUCCESS){
  23348. printf("error with EVP_SignInit\n");
  23349. EVP_MD_CTX_destroy(sign);
  23350. EVP_MD_CTX_destroy(verf);
  23351. return WC_TEST_RET_ENC_NC;
  23352. }
  23353. count = sizeof(msg);
  23354. show("message = ", (char *)msg, count);
  23355. /* sign */
  23356. XMEMSET(sig, 0, sizeof(sig));
  23357. pt = (const void*)msg;
  23358. ret1 = EVP_SignUpdate(sign, pt, count);
  23359. ret2 = EVP_SignFinal(sign, sig, &sigSz, prvPkey);
  23360. if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){
  23361. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23362. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23363. EVP_MD_CTX_destroy(sign);
  23364. EVP_MD_CTX_destroy(verf);
  23365. printf("error with EVP_MD_CTX_create\n");
  23366. return WC_TEST_RET_ENC_NC;
  23367. }
  23368. show("signature = ", (char *)sig, sigSz);
  23369. /* verify */
  23370. pt = (const void*)msg;
  23371. ret1 = EVP_VerifyInit(verf, EVP_sha1());
  23372. ret2 = EVP_VerifyUpdate(verf, pt, count);
  23373. if((ret1 != SSL_SUCCESS) || (ret2 != SSL_SUCCESS)){
  23374. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23375. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23376. EVP_MD_CTX_destroy(sign);
  23377. EVP_MD_CTX_destroy(verf);
  23378. printf("error with EVP_Verify\n");
  23379. return WC_TEST_RET_ENC_NC;
  23380. }
  23381. if (EVP_VerifyFinal(verf, sig, sigSz, pubPkey) != 1) {
  23382. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23383. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23384. EVP_MD_CTX_destroy(sign);
  23385. EVP_MD_CTX_destroy(verf);
  23386. printf("error with EVP_VerifyFinal\n");
  23387. return WC_TEST_RET_ENC_NC;
  23388. }
  23389. /* expect fail without update */
  23390. EVP_VerifyInit(verf, EVP_sha1());
  23391. if (EVP_VerifyFinal(verf, sig, sigSz, pubPkey) == 1) {
  23392. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23393. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23394. EVP_MD_CTX_destroy(sign);
  23395. EVP_MD_CTX_destroy(verf);
  23396. printf("EVP_VerifyInit without update not detected\n");
  23397. return WC_TEST_RET_ENC_NC;
  23398. }
  23399. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23400. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23401. EVP_MD_CTX_destroy(sign);
  23402. EVP_MD_CTX_destroy(verf);
  23403. wolfSSL_RSA_free(prvRsa);
  23404. wolfSSL_RSA_free(pubRsa);
  23405. EVP_PKEY_free(pubPkey);
  23406. EVP_PKEY_free(prvPkey);
  23407. #endif /* NO_RSA */
  23408. return 0;
  23409. }
  23410. #endif /* OPENSSL_EXTRA */
  23411. #ifndef NO_PWDBASED
  23412. #ifdef HAVE_SCRYPT
  23413. /* Test vectors taken from RFC 7914: scrypt PBKDF - Section 12. */
  23414. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void)
  23415. {
  23416. #ifdef HAVE_FIPS
  23417. /* RFC 7914 test vector keys are too short for FIPS. */
  23418. #else
  23419. wc_test_ret_t ret;
  23420. byte derived[64];
  23421. WOLFSSL_SMALL_STACK_STATIC const byte verify1[] = {
  23422. 0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20,
  23423. 0x3b, 0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97,
  23424. 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8,
  23425. 0xdf, 0xdf, 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42,
  23426. 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, 0xf8,
  23427. 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17,
  23428. 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d, 0x36, 0x28,
  23429. 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06
  23430. };
  23431. #if !defined(BENCH_EMBEDDED)
  23432. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23433. 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00,
  23434. 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe,
  23435. 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30,
  23436. 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62,
  23437. 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88,
  23438. 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda,
  23439. 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d,
  23440. 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40
  23441. };
  23442. #endif
  23443. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23444. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  23445. 0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48,
  23446. 0x46, 0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb,
  23447. 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e,
  23448. 0xa9, 0xb5, 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2,
  23449. 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, 0xcf,
  23450. 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9,
  23451. 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65, 0x1e, 0x40,
  23452. 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87
  23453. };
  23454. #endif
  23455. #ifdef SCRYPT_TEST_ALL
  23456. /* Test case is very slow.
  23457. * Use for confirmation after code change or new platform.
  23458. */
  23459. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  23460. 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae,
  23461. 0xad, 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81,
  23462. 0xec, 0x56, 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d,
  23463. 0xab, 0xe5, 0xee, 0x98, 0x20, 0xad, 0xaa, 0x47,
  23464. 0x8e, 0x56, 0xfd, 0x8f, 0x4b, 0xa5, 0xd0, 0x9f,
  23465. 0xfa, 0x1c, 0x6d, 0x92, 0x7c, 0x40, 0xf4, 0xc3,
  23466. 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, 0x52, 0xfb,
  23467. 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, 0xa4
  23468. };
  23469. #endif
  23470. WOLFSSL_ENTER("scrypt_test");
  23471. ret = wc_scrypt(derived, NULL, 0, NULL, 0, 4, 1, 1, sizeof(verify1));
  23472. if (ret != 0)
  23473. return WC_TEST_RET_ENC_EC(ret);
  23474. if (XMEMCMP(derived, verify1, sizeof(verify1)) != 0)
  23475. return WC_TEST_RET_ENC_NC;
  23476. #if !defined(BENCH_EMBEDDED)
  23477. ret = wc_scrypt(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 10, 8, 16,
  23478. sizeof(verify2));
  23479. if (ret != 0)
  23480. return WC_TEST_RET_ENC_EC(ret);
  23481. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23482. return WC_TEST_RET_ENC_NC;
  23483. #endif
  23484. /* Test case with parallel overflowing */
  23485. ret = wc_scrypt(derived, (byte*)"password", 16, (byte*)"NaCl", 16, 2, 4, 8388608,
  23486. sizeof(verify1));
  23487. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  23488. return WC_TEST_RET_ENC_EC(ret);
  23489. /* Don't run these test on embedded, since they use large mallocs */
  23490. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23491. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23492. (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(verify3));
  23493. if (ret != 0)
  23494. return WC_TEST_RET_ENC_EC(ret);
  23495. if (XMEMCMP(derived, verify3, sizeof(verify3)) != 0)
  23496. return WC_TEST_RET_ENC_NC;
  23497. #ifdef SCRYPT_TEST_ALL
  23498. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23499. (byte*)"SodiumChloride", 14, 20, 8, 1, sizeof(verify4));
  23500. if (ret != 0)
  23501. return WC_TEST_RET_ENC_EC(ret);
  23502. if (XMEMCMP(derived, verify4, sizeof(verify4)) != 0)
  23503. return WC_TEST_RET_ENC_NC;
  23504. #endif
  23505. #else
  23506. #ifdef SCRYPT_TEST_ALL
  23507. (void)verify4;
  23508. #endif
  23509. #endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */
  23510. #if !defined(BENCH_EMBEDDED)
  23511. ret = wc_scrypt_ex(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 1<<10,
  23512. 8, 16, sizeof(verify2));
  23513. if (ret != 0)
  23514. return WC_TEST_RET_ENC_EC(ret);
  23515. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23516. return WC_TEST_RET_ENC_NC;
  23517. #endif
  23518. #endif /* !HAVE_FIPS */
  23519. return 0;
  23520. }
  23521. #endif
  23522. #ifdef HAVE_PKCS12
  23523. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void)
  23524. {
  23525. WOLFSSL_SMALL_STACK_STATIC const byte passwd[] = { 0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
  23526. 0x00, 0x00 };
  23527. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f };
  23528. WOLFSSL_SMALL_STACK_STATIC const byte passwd2[] = { 0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
  23529. 0x00, 0x67, 0x00, 0x00 };
  23530. WOLFSSL_SMALL_STACK_STATIC const byte salt2[] = { 0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5 };
  23531. byte derived[64];
  23532. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23533. 0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
  23534. 0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
  23535. 0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
  23536. };
  23537. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23538. 0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
  23539. 0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
  23540. 0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
  23541. };
  23542. int id = 1;
  23543. int kLen = 24;
  23544. int iterations = 1;
  23545. wc_test_ret_t ret;
  23546. WOLFSSL_ENTER("pkcs12_pbkdf_test");
  23547. ret = wc_PKCS12_PBKDF(derived, passwd, sizeof(passwd), salt, 8,
  23548. iterations, kLen, WC_SHA256, id);
  23549. if (ret < 0)
  23550. return WC_TEST_RET_ENC_EC(ret);
  23551. if (XMEMCMP(derived, verify, (unsigned long)kLen) != 0)
  23552. return WC_TEST_RET_ENC_NC;
  23553. iterations = 1000;
  23554. ret = wc_PKCS12_PBKDF(derived, passwd2, sizeof(passwd2), salt2, 8,
  23555. iterations, kLen, WC_SHA256, id);
  23556. if (ret < 0)
  23557. return WC_TEST_RET_ENC_EC(ret);
  23558. ret = wc_PKCS12_PBKDF_ex(derived, passwd2, sizeof(passwd2), salt2, 8,
  23559. iterations, kLen, WC_SHA256, id, HEAP_HINT);
  23560. if (ret < 0)
  23561. return WC_TEST_RET_ENC_EC(ret);
  23562. if (XMEMCMP(derived, verify2, 24) != 0)
  23563. return WC_TEST_RET_ENC_NC;
  23564. return 0;
  23565. }
  23566. #endif /* HAVE_PKCS12 */
  23567. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23568. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void)
  23569. {
  23570. char passwd[] = "passwordpassword";
  23571. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a,
  23572. 0x5d, 0x63, 0xcb, 0x06 };
  23573. int iterations = 2048;
  23574. int kLen = 24;
  23575. byte derived[64];
  23576. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23577. 0x43, 0x6d, 0xb5, 0xe8, 0xd0, 0xfb, 0x3f, 0x35, 0x42, 0x48, 0x39, 0xbc,
  23578. 0x2d, 0xd4, 0xf9, 0x37, 0xd4, 0x95, 0x16, 0xa7, 0x2a, 0x9a, 0x21, 0xd1
  23579. };
  23580. wc_test_ret_t ret;
  23581. WOLFSSL_ENTER("pbkdf2_test");
  23582. ret = wc_PBKDF2_ex(derived, (byte*)passwd, (int)XSTRLEN(passwd),
  23583. salt, (int)sizeof(salt), iterations,
  23584. kLen, WC_SHA256, HEAP_HINT, devId);
  23585. if (ret != 0)
  23586. return WC_TEST_RET_ENC_EC(ret);
  23587. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23588. return WC_TEST_RET_ENC_NC;
  23589. return 0;
  23590. }
  23591. #endif /* HAVE_PBKDF2 && !NO_SHA256 && !NO_HMAC */
  23592. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23593. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void)
  23594. {
  23595. char passwd[] = "password";
  23596. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  23597. int iterations = 1000;
  23598. int kLen = 16;
  23599. byte derived[16];
  23600. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23601. 0xDC, 0x19, 0x84, 0x7E, 0x05, 0xC6, 0x4D, 0x2F,
  23602. 0xAF, 0x10, 0xEB, 0xFB, 0x4A, 0x3D, 0x2A, 0x20
  23603. };
  23604. wc_test_ret_t ret;
  23605. WOLFSSL_ENTER("pbkdf1_test");
  23606. ret = wc_PBKDF1_ex(derived, kLen, NULL, 0, (byte*)passwd,
  23607. (int)XSTRLEN(passwd), salt, (int)sizeof(salt), iterations, WC_SHA,
  23608. HEAP_HINT);
  23609. if (ret != 0)
  23610. return ret;
  23611. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23612. return WC_TEST_RET_ENC_NC;
  23613. return 0;
  23614. }
  23615. #endif /* HAVE_PBKDF2 && !NO_SHA */
  23616. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void)
  23617. {
  23618. wc_test_ret_t ret = 0;
  23619. WOLFSSL_ENTER("pwdbased_test");
  23620. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23621. ret = pbkdf1_test();
  23622. if (ret != 0)
  23623. return ret;
  23624. #endif
  23625. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23626. ret = pbkdf2_test();
  23627. if (ret != 0)
  23628. return ret;
  23629. #endif
  23630. #ifdef HAVE_PKCS12
  23631. ret = pkcs12_pbkdf_test();
  23632. if (ret != 0)
  23633. return ret;
  23634. #endif
  23635. #ifdef HAVE_SCRYPT
  23636. ret = scrypt_test();
  23637. if (ret != 0)
  23638. return ret;
  23639. #endif
  23640. return ret;
  23641. }
  23642. #endif /* NO_PWDBASED */
  23643. #if defined(USE_CERT_BUFFERS_2048) && \
  23644. defined(HAVE_PKCS12) && \
  23645. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  23646. !defined(NO_CERTS) && !defined(NO_DES3)
  23647. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
  23648. {
  23649. wc_test_ret_t ret = 0;
  23650. WC_PKCS12* pkcs12 = NULL;
  23651. /* Gen vars */
  23652. byte* pkcs12der = NULL;
  23653. int pkcs12derSz = 0;
  23654. WC_DerCertList derCaList = {
  23655. (byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
  23656. };
  23657. char* pass = (char*)"wolfSSL test";
  23658. /* Parsing vars */
  23659. WC_DerCertList* derCaListOut = NULL;
  23660. byte* keyDer = NULL;
  23661. byte* certDer = NULL;
  23662. word32 keySz;
  23663. word32 certSz;
  23664. WOLFSSL_ENTER("pkcs12_test");
  23665. pkcs12 = wc_PKCS12_create(pass, (word32)XSTRLEN(pass),
  23666. (char*)"friendlyName" /* not used currently */,
  23667. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  23668. (byte*)server_cert_der_2048, sizeof_server_cert_der_2048,
  23669. &derCaList, PBE_SHA1_DES3, PBE_SHA1_DES3, 100, 100,
  23670. 0 /* not used currently */, HEAP_HINT);
  23671. if (pkcs12 == NULL) {
  23672. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23673. goto out;
  23674. }
  23675. ret = wc_i2d_PKCS12(pkcs12, NULL, &pkcs12derSz);
  23676. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  23677. if (ret == 0)
  23678. ret = WC_TEST_RET_ENC_NC;
  23679. else
  23680. ret = WC_TEST_RET_ENC_I(ret);
  23681. goto out;
  23682. }
  23683. pkcs12der = (byte*)XMALLOC(pkcs12derSz, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23684. if (pkcs12der == NULL) {
  23685. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23686. goto out;
  23687. }
  23688. {
  23689. /* Use tmp pointer to avoid advancing pkcs12der */
  23690. byte* tmp = pkcs12der;
  23691. ret = wc_i2d_PKCS12(pkcs12, &tmp, &pkcs12derSz);
  23692. if (ret <= 0) {
  23693. if (ret == 0)
  23694. ret = WC_TEST_RET_ENC_NC;
  23695. else
  23696. ret = WC_TEST_RET_ENC_I(ret);
  23697. goto out;
  23698. }
  23699. }
  23700. wc_PKCS12_free(pkcs12);
  23701. pkcs12 = wc_PKCS12_new_ex(HEAP_HINT);
  23702. if (pkcs12 == NULL) {
  23703. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23704. goto out;
  23705. }
  23706. /* convert the DER file into an internal structure */
  23707. ret = wc_d2i_PKCS12(pkcs12der, pkcs12derSz, pkcs12);
  23708. if (ret != 0) {
  23709. ret = WC_TEST_RET_ENC_EC(ret);
  23710. goto out;
  23711. }
  23712. /* parse the internal structure into its parts */
  23713. ret = wc_PKCS12_parse(pkcs12, "wolfSSL test", &keyDer, &keySz,
  23714. &certDer, &certSz, &derCaListOut);
  23715. if (ret != 0) {
  23716. ret = WC_TEST_RET_ENC_EC(ret);
  23717. goto out;
  23718. }
  23719. if (keyDer == NULL || certDer == NULL || derCaListOut == NULL) {
  23720. ret = WC_TEST_RET_ENC_NC;
  23721. goto out;
  23722. }
  23723. out:
  23724. if (derCaListOut)
  23725. wc_FreeCertList(derCaListOut, HEAP_HINT);
  23726. XFREE(keyDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23727. XFREE(certDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23728. if (pkcs12)
  23729. wc_PKCS12_free(pkcs12);
  23730. XFREE(pkcs12der, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23731. return ret;
  23732. }
  23733. #endif
  23734. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  23735. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  23736. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  23737. defined(WOLFSSL_AFALG_XILINX_RSA)
  23738. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  23739. static wc_test_ret_t hkdf_test(void)
  23740. #else
  23741. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void)
  23742. #endif
  23743. {
  23744. wc_test_ret_t ret = 0;
  23745. #if !defined(NO_SHA) || !defined(NO_SHA256)
  23746. int L;
  23747. byte okm1[42];
  23748. byte ikm1[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23749. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23750. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  23751. #ifndef HAVE_FIPS
  23752. byte salt1[13] ={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  23753. 0x08, 0x09, 0x0a, 0x0b, 0x0c };
  23754. byte info1[10] ={ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  23755. 0xf8, 0xf9 };
  23756. #endif
  23757. #ifndef NO_SHA
  23758. byte res1[42] = { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61,
  23759. 0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06,
  23760. 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06,
  23761. 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0,
  23762. 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
  23763. 0x49, 0x18 };
  23764. #ifndef HAVE_FIPS
  23765. byte res2[42] = { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69,
  23766. 0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81,
  23767. 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15,
  23768. 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2,
  23769. 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
  23770. 0xf8, 0x96 };
  23771. #endif
  23772. #endif /* !NO_SHA */
  23773. #ifndef NO_SHA256
  23774. byte res3[42] = { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
  23775. 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
  23776. 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
  23777. 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
  23778. 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
  23779. 0x96, 0xc8 };
  23780. #ifndef HAVE_FIPS
  23781. byte res4[42] = { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
  23782. 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
  23783. 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
  23784. 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
  23785. 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
  23786. 0x58, 0x65 };
  23787. #endif
  23788. #endif /* !NO_SHA256 */
  23789. WOLFSSL_ENTER("hkdf_test");
  23790. XMEMSET(okm1, 0, sizeof(okm1));
  23791. L = (int)sizeof(okm1);
  23792. #ifndef NO_SHA
  23793. ret = wc_HKDF(WC_SHA, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23794. okm1, (word32)L);
  23795. if (ret != 0)
  23796. return WC_TEST_RET_ENC_EC(ret);
  23797. if (XMEMCMP(okm1, res1, (unsigned long)L) != 0)
  23798. return WC_TEST_RET_ENC_NC;
  23799. #ifndef HAVE_FIPS
  23800. /* fips can't have key size under 14 bytes, salt is key too */
  23801. L = (int)sizeof(okm1);
  23802. ret = wc_HKDF(WC_SHA, ikm1, 11, salt1, (word32)sizeof(salt1),
  23803. info1, (word32)sizeof(info1), okm1, (word32)L);
  23804. if (ret != 0)
  23805. return WC_TEST_RET_ENC_EC(ret);
  23806. if (XMEMCMP(okm1, res2, (unsigned long)L) != 0)
  23807. return WC_TEST_RET_ENC_NC;
  23808. #endif /* HAVE_FIPS */
  23809. #endif /* !NO_SHA */
  23810. #ifndef NO_SHA256
  23811. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23812. okm1, (word32)L);
  23813. if (ret != 0)
  23814. return WC_TEST_RET_ENC_EC(ret);
  23815. if (XMEMCMP(okm1, res3, (unsigned long)L) != 0)
  23816. return WC_TEST_RET_ENC_NC;
  23817. #ifndef HAVE_FIPS
  23818. /* fips can't have key size under 14 bytes, salt is key too */
  23819. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1),
  23820. salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, (word32)L);
  23821. if (ret != 0)
  23822. return WC_TEST_RET_ENC_EC(ret);
  23823. if (XMEMCMP(okm1, res4, (unsigned long)L) != 0)
  23824. return WC_TEST_RET_ENC_NC;
  23825. #endif /* HAVE_FIPS */
  23826. #endif /* !NO_SHA256 */
  23827. #endif /* !NO_SHA || !NO_SHA256 */
  23828. return ret;
  23829. }
  23830. #endif /* HAVE_HKDF */
  23831. #ifdef WOLFSSL_WOLFSSH
  23832. typedef struct {
  23833. byte hashId;
  23834. byte keyId;
  23835. const byte* k;
  23836. word32 kSz;
  23837. const byte* h;
  23838. word32 hSz;
  23839. const byte* sessionId;
  23840. word32 sessionIdSz;
  23841. const byte* expectedKey;
  23842. word32 expectedKeySz;
  23843. } SshKdfTestVector;
  23844. /** Test Vector Set #3: SHA-256 **/
  23845. static const byte sshKdfTvSet3k[] = {
  23846. 0x6A, 0xC3, 0x82, 0xEA, 0xAC, 0xA0, 0x93, 0xE1,
  23847. 0x25, 0xE2, 0x5C, 0x24, 0xBE, 0xBC, 0x84, 0x64,
  23848. 0x0C, 0x11, 0x98, 0x75, 0x07, 0x34, 0x4B, 0x5C,
  23849. 0x73, 0x9C, 0xEB, 0x84, 0xA9, 0xE0, 0xB2, 0x22,
  23850. 0xB9, 0xA8, 0xB5, 0x1C, 0x83, 0x9E, 0x5E, 0xBE,
  23851. 0x49, 0xCF, 0xAD, 0xBF, 0xB3, 0x95, 0x99, 0x76,
  23852. 0x4E, 0xD5, 0x22, 0x09, 0x9D, 0xC9, 0x12, 0x75,
  23853. 0x19, 0x50, 0xDC, 0x7D, 0xC9, 0x7F, 0xBD, 0xC0,
  23854. 0x63, 0x28, 0xB6, 0x8F, 0x22, 0x78, 0x1F, 0xD3,
  23855. 0x15, 0xAF, 0x56, 0x80, 0x09, 0xA5, 0x50, 0x9E,
  23856. 0x5B, 0x87, 0xA1, 0x1B, 0xF5, 0x27, 0xC0, 0x56,
  23857. 0xDA, 0xFF, 0xD8, 0x2A, 0xB6, 0xCB, 0xC2, 0x5C,
  23858. 0xCA, 0x37, 0x14, 0x34, 0x59, 0xE7, 0xBC, 0x63,
  23859. 0xBC, 0xDE, 0x52, 0x75, 0x7A, 0xDE, 0xB7, 0xDF,
  23860. 0x01, 0xCF, 0x12, 0x17, 0x3F, 0x1F, 0xEF, 0x81,
  23861. 0x02, 0xEC, 0x5A, 0xB1, 0x42, 0xC2, 0x13, 0xDD,
  23862. 0x9D, 0x30, 0x69, 0x62, 0x78, 0xA8, 0xD8, 0xBC,
  23863. 0x32, 0xDD, 0xE9, 0x59, 0x2D, 0x28, 0xC0, 0x78,
  23864. 0xC6, 0xD9, 0x2B, 0x94, 0x7D, 0x82, 0x5A, 0xCA,
  23865. 0xAB, 0x64, 0x94, 0x84, 0x6A, 0x49, 0xDE, 0x24,
  23866. 0xB9, 0x62, 0x3F, 0x48, 0x89, 0xE8, 0xAD, 0xC3,
  23867. 0x8E, 0x8C, 0x66, 0x9E, 0xFF, 0xEF, 0x17, 0x60,
  23868. 0x40, 0xAD, 0x94, 0x5E, 0x90, 0xA7, 0xD3, 0xEE,
  23869. 0xC1, 0x5E, 0xFE, 0xEE, 0x78, 0xAE, 0x71, 0x04,
  23870. 0x3C, 0x96, 0x51, 0x11, 0x03, 0xA1, 0x6B, 0xA7,
  23871. 0xCA, 0xF0, 0xAC, 0xD0, 0x64, 0x2E, 0xFD, 0xBE,
  23872. 0x80, 0x99, 0x34, 0xFA, 0xA1, 0xA5, 0xF1, 0xBD,
  23873. 0x11, 0x04, 0x36, 0x49, 0xB2, 0x5C, 0xCD, 0x1F,
  23874. 0xEE, 0x2E, 0x38, 0x81, 0x5D, 0x4D, 0x5F, 0x5F,
  23875. 0xC6, 0xB4, 0x10, 0x29, 0x69, 0xF2, 0x1C, 0x22,
  23876. 0xAE, 0x1B, 0x0E, 0x7D, 0x36, 0x03, 0xA5, 0x56,
  23877. 0xA1, 0x32, 0x62, 0xFF, 0x62, 0x8D, 0xE2, 0x22
  23878. };
  23879. static const byte sshKdfTvSet3h[] = {
  23880. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23881. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23882. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23883. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23884. };
  23885. static const byte sshKdfTvSet3sid[] = {
  23886. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23887. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23888. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23889. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23890. };
  23891. static const byte sshKdfTvSet3a[] = {
  23892. 0x81, 0xF0, 0x33, 0x0E, 0xF6, 0xF0, 0x53, 0x61,
  23893. 0xB3, 0x82, 0x3B, 0xFD, 0xED, 0x6E, 0x1D, 0xE9
  23894. };
  23895. static const byte sshKdfTvSet3b[] = {
  23896. 0x3F, 0x6F, 0xD2, 0x06, 0x5E, 0xEB, 0x2B, 0x0B,
  23897. 0x1D, 0x93, 0x19, 0x5A, 0x1F, 0xED, 0x48, 0xA5
  23898. };
  23899. static const byte sshKdfTvSet3c[] = {
  23900. 0xC3, 0x54, 0x71, 0x03, 0x4E, 0x6F, 0xD6, 0x54,
  23901. 0x76, 0x13, 0x17, 0x8E, 0x23, 0x43, 0x5F, 0x21
  23902. };
  23903. static const byte sshKdfTvSet3d[] = {
  23904. 0x7E, 0x9D, 0x79, 0x03, 0x20, 0x90, 0xD9, 0x9F,
  23905. 0x98, 0xB0, 0x15, 0x63, 0x4D, 0xD9, 0xF4, 0x62
  23906. };
  23907. static const byte sshKdfTvSet3e[] = {
  23908. 0x24, 0xEE, 0x55, 0x9A, 0xD7, 0xCE, 0x71, 0x2B,
  23909. 0x68, 0x5D, 0x0B, 0x22, 0x71, 0xE4, 0x43, 0xC1,
  23910. 0x7A, 0xB1, 0xD1, 0xDC, 0xEB, 0x5A, 0x36, 0x05,
  23911. 0x69, 0xD2, 0x5D, 0x5D, 0xC2, 0x43, 0x00, 0x2F
  23912. };
  23913. static const byte sshKdfTvSet3f[] = {
  23914. 0xC3, 0x41, 0x9C, 0x2B, 0x96, 0x62, 0x35, 0x86,
  23915. 0x9D, 0x71, 0x4B, 0xA5, 0xAC, 0x48, 0xDD, 0xB7,
  23916. 0xD9, 0xE3, 0x5C, 0x8C, 0x19, 0xAA, 0xC7, 0x34,
  23917. 0x22, 0x33, 0x7A, 0x37, 0x34, 0x53, 0x60, 0x7E
  23918. };
  23919. static const SshKdfTestVector sshKdfTestVectors[] = {
  23920. {WC_HASH_TYPE_SHA256, 'A',
  23921. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23922. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23923. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23924. sshKdfTvSet3a, sizeof(sshKdfTvSet3a)},
  23925. {WC_HASH_TYPE_SHA256, 'B',
  23926. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23927. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23928. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23929. sshKdfTvSet3b, sizeof(sshKdfTvSet3b)},
  23930. {WC_HASH_TYPE_SHA256, 'C',
  23931. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23932. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23933. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23934. sshKdfTvSet3c, sizeof(sshKdfTvSet3c)},
  23935. {WC_HASH_TYPE_SHA256, 'D',
  23936. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23937. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23938. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23939. sshKdfTvSet3d, sizeof(sshKdfTvSet3d)},
  23940. {WC_HASH_TYPE_SHA256, 'E',
  23941. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23942. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23943. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23944. sshKdfTvSet3e, sizeof(sshKdfTvSet3e)},
  23945. {WC_HASH_TYPE_SHA256, 'F',
  23946. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  23947. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  23948. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  23949. sshKdfTvSet3f, sizeof(sshKdfTvSet3f)},
  23950. };
  23951. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void)
  23952. {
  23953. byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and AES_BLOCK_SIZE */
  23954. word32 i;
  23955. word32 tc = sizeof(sshKdfTestVectors)/sizeof(SshKdfTestVector);
  23956. const SshKdfTestVector* tv = NULL;
  23957. wc_test_ret_t result = 0;
  23958. WOLFSSL_ENTER("sshkdf_test");
  23959. /* sId - Session ID, eKey - Expected Key, cKey - Calculated Key */
  23960. for (i = 0, tv = sshKdfTestVectors; i < tc; i++, tv++) {
  23961. result = wc_SSH_KDF(tv->hashId, tv->keyId,
  23962. cKey, tv->expectedKeySz,
  23963. tv->k, tv->kSz, tv->h, tv->hSz,
  23964. tv->sessionId, tv->sessionIdSz);
  23965. if (result != 0) {
  23966. printf("KDF: Could not derive key.\n");
  23967. result = WC_TEST_RET_ENC_EC(result);
  23968. }
  23969. else {
  23970. if (XMEMCMP(cKey, tv->expectedKey, tv->expectedKeySz) != 0) {
  23971. printf("KDF: Calculated Key does not match Expected Key.\n");
  23972. result = WC_TEST_RET_ENC_EC(result);
  23973. }
  23974. }
  23975. if (result != 0) break;
  23976. }
  23977. return result;
  23978. }
  23979. #endif /* WOLFSSL_WOLFSSH */
  23980. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  23981. #define DIGL 12
  23982. #define SECL 48
  23983. #define LBSL 63
  23984. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void)
  23985. {
  23986. int ret;
  23987. byte dig[DIGL] = {0};
  23988. byte secret[SECL] = {
  23989. 0x10, 0xbc, 0xb4, 0xa2, 0xe8, 0xdc, 0xf1, 0x9b, 0x4c,
  23990. 0x51, 0x9c, 0xed, 0x31, 0x1b, 0x51, 0x57, 0x02, 0x3f,
  23991. 0xa1, 0x7d, 0xfb, 0x0e, 0xf3, 0x4e, 0x8f, 0x6f, 0x71,
  23992. 0xa3, 0x67, 0x76, 0x6b, 0xfa, 0x5d, 0x46, 0x4a, 0xe8,
  23993. 0x61, 0x18, 0x81, 0xc4, 0x66, 0xcc, 0x6f, 0x09, 0x99,
  23994. 0x9d, 0xfc, 0x47
  23995. };
  23996. byte lablSd[LBSL] = {
  23997. 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69,
  23998. 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x0b, 0x46, 0xba,
  23999. 0x56, 0xbf, 0x1f, 0x5d, 0x99, 0xff, 0xe9, 0xbb, 0x43,
  24000. 0x01, 0xe7, 0xca, 0x2c, 0x00, 0xdf, 0x9a, 0x39, 0x6e,
  24001. 0xcf, 0x6d, 0x15, 0x27, 0x4d, 0xf2, 0x93, 0x96, 0x4a,
  24002. 0x91, 0xde, 0x5c, 0xc0, 0x47, 0x7c, 0xa8, 0xae, 0xcf,
  24003. 0x5d, 0x93, 0x5f, 0x4c, 0x92, 0xcc, 0x98, 0x5b, 0x43
  24004. };
  24005. byte expected[DIGL] = {
  24006. 0xee, 0xcb, 0xb1, 0x30, 0xf2, 0xcd, 0xb3, 0x4a,
  24007. 0xbe, 0xda, 0xc1, 0xf6
  24008. };
  24009. int digL = DIGL;
  24010. int secL = SECL;
  24011. int lblsdL = LBSL;
  24012. int hash_type = sha384_mac;
  24013. ret = wc_PRF(dig, (word32)digL, secret, (word32)secL, lablSd,
  24014. (word32)lblsdL, hash_type,
  24015. HEAP_HINT, INVALID_DEVID);
  24016. if (ret != 0) {
  24017. printf("Failed w/ code: %d\n", ret);
  24018. return WC_TEST_RET_ENC_EC(ret);
  24019. }
  24020. if (XMEMCMP(expected, dig, DIGL) != 0) {
  24021. printf("Got unexpected digest\n");
  24022. return WC_TEST_RET_ENC_NC;
  24023. }
  24024. return 0;
  24025. }
  24026. #endif /* WOLFSSL_HAVE_PRF && !NO_HMAC */
  24027. #ifdef WOLFSSL_HAVE_PRF
  24028. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  24029. #ifdef WOLFSSL_BASE16
  24030. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
  24031. {
  24032. const char* preMasterSecret = "D06F9C19BFF49B1E91E4EFE97345D089"
  24033. "4E6C2E6C34A165B24540E2970875D641"
  24034. "2AA6515871B389B4C199BB8389C71CED";
  24035. const char* helloRandom = "162B81EDFBEAE4F25240320B87E7651C"
  24036. "865564191DD782DB0B9ECA275FBA1BB9"
  24037. "5A1DA3DF436D68DA86C5E7B4B4A36E46"
  24038. "B977C61767983A31BE270D74517BD0F6";
  24039. const char* masterSecret = "EB38B8D89B98B1C266DE44BB3CA14E83"
  24040. "C32F009F9955B1D994E61D3C51EE8760"
  24041. "90B4EF89CC7AF42F46E72201BFCC7977";
  24042. const char* label = "master secret";
  24043. byte pms[48] = {0};
  24044. byte seed[64] = {0};
  24045. byte ms[48] = {0};
  24046. byte result[48] = {0};
  24047. word32 pmsSz = (word32)sizeof(pms);
  24048. word32 seedSz = (word32)sizeof(seed);
  24049. word32 msSz = (word32)sizeof(ms);
  24050. int ret;
  24051. ret = Base16_Decode((const byte*)preMasterSecret,
  24052. (word32)XSTRLEN(preMasterSecret), pms, &pmsSz);
  24053. if (ret != 0)
  24054. return ret;
  24055. ret = Base16_Decode((const byte*)helloRandom,
  24056. (word32)XSTRLEN(helloRandom), seed, &seedSz);
  24057. if (ret != 0)
  24058. return ret;
  24059. ret = Base16_Decode((const byte*)masterSecret,
  24060. (word32)XSTRLEN(masterSecret), ms, &msSz);
  24061. if (ret != 0)
  24062. return ret;
  24063. ret = wc_PRF_TLS(result, msSz, pms, pmsSz,
  24064. (const byte*)label, (word32)XSTRLEN(label), seed, seedSz,
  24065. 1, sha256_mac, NULL, INVALID_DEVID);
  24066. if (ret != 0) {
  24067. if (ret == WC_NO_ERR_TRACE(FIPS_PRIVATE_KEY_LOCKED_E)) {
  24068. printf(" wc_PRF_TLSv12: Private key locked.\n");
  24069. }
  24070. return WC_TEST_RET_ENC_NC;
  24071. }
  24072. if (XMEMCMP(result, ms, msSz) != 0)
  24073. return WC_TEST_RET_ENC_NC;
  24074. return 0;
  24075. }
  24076. #endif /* WOLFSSL_BASE16 */
  24077. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  24078. #endif /* WOLFSSL_HAVE_PRF */
  24079. #ifdef WOLFSSL_TLS13
  24080. #define TLSV13_PSK_DHE_SZ 40
  24081. typedef struct {
  24082. enum wc_HashType hashAlg;
  24083. word32 pskSz;
  24084. word32 dheSz;
  24085. byte psk[TLSV13_PSK_DHE_SZ];
  24086. byte dhe[TLSV13_PSK_DHE_SZ];
  24087. byte hashHello1[WC_MAX_DIGEST_SIZE];
  24088. byte hashHello2[WC_MAX_DIGEST_SIZE];
  24089. byte hashFinished1[WC_MAX_DIGEST_SIZE];
  24090. byte hashFinished2[WC_MAX_DIGEST_SIZE];
  24091. /* Expected */
  24092. byte clientEarlyTrafficSecret[WC_MAX_DIGEST_SIZE];
  24093. byte earlyExporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24094. byte clientHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24095. byte serverHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24096. byte clientApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24097. byte serverApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24098. byte exporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24099. byte resumptionMasterSecret[WC_MAX_DIGEST_SIZE];
  24100. } Tls13KdfTestVector;
  24101. /* The following tests come from the CAVP test vectors we used for
  24102. * our FIPS validation. The hash values used are the components from
  24103. * the test hashed together. hashHello1 is the hash of the
  24104. * clientHelloRandom value of the test vector. hashHello2 is the hash
  24105. * of the clientHelloRandom and serverHelloRandom values from the test
  24106. * vector. hashFinished1 is clientHelloRandom, serverHelloRandom, and
  24107. * serverFinishedRandom. hashFinished2 is clientHelloRandom,
  24108. * serverHelloRandom, serverFinishedRandom, and clietnFinishedRandom
  24109. * hashed together. */
  24110. static const Tls13KdfTestVector tls13KdfTestVectors[] = {
  24111. { /* 1 */
  24112. WC_HASH_TYPE_SHA256, 35, 35,
  24113. { /* PSK */
  24114. 0x7b, 0xf1, 0x05, 0x31, 0x36, 0xfa, 0x03, 0xdc,
  24115. 0x31, 0x97, 0x88, 0x04, 0x9c, 0xbc, 0xee, 0xf7,
  24116. 0x8d, 0x84, 0x95, 0x26, 0xaf, 0x1d, 0x68, 0xb0,
  24117. 0x60, 0x7a, 0xcc, 0x4f, 0xc1, 0xd3, 0xa1, 0x68,
  24118. 0x7f, 0x6d, 0xbe
  24119. },
  24120. { /* DHE */
  24121. 0x6e, 0xa1, 0x77, 0xab, 0x2f, 0x43, 0xd2, 0x4b,
  24122. 0xe5, 0xa1, 0x09, 0xe0, 0x7a, 0xd0, 0x01, 0x35,
  24123. 0x8d, 0xf8, 0xf2, 0x5c, 0x91, 0x02, 0xb0, 0x6c,
  24124. 0x3f, 0xeb, 0xee, 0xa4, 0x42, 0x19, 0xce, 0xdc,
  24125. 0x81, 0x26, 0x40
  24126. },
  24127. { /* Hello 1 */
  24128. 0xd9, 0x4b, 0xe4, 0x17, 0xef, 0x58, 0x73, 0x7d,
  24129. 0x28, 0x3d, 0xf0, 0xcc, 0x05, 0x03, 0xaf, 0xac,
  24130. 0x3d, 0x92, 0x79, 0x48, 0xe8, 0x8c, 0xdb, 0xce,
  24131. 0x95, 0x82, 0x21, 0x31, 0x7b, 0x61, 0xd7, 0xc6
  24132. },
  24133. { /* Hello 2 */
  24134. 0xb7, 0x7f, 0x29, 0x91, 0xa4, 0x8b, 0x34, 0xdb,
  24135. 0xbd, 0xc7, 0x54, 0x1c, 0x3b, 0x86, 0xa3, 0x69,
  24136. 0xfe, 0x26, 0xe4, 0x7b, 0xac, 0x57, 0x71, 0xb3,
  24137. 0x32, 0x97, 0xed, 0xd2, 0x0e, 0x95, 0xb8, 0x63
  24138. },
  24139. { /* Finished 1 */
  24140. 0x65, 0xdb, 0x6d, 0x71, 0x71, 0xd0, 0xd8, 0x49,
  24141. 0xd0, 0x3c, 0x8e, 0x2b, 0x24, 0xdf, 0xc2, 0xe9,
  24142. 0xd6, 0xfd, 0xea, 0x04, 0x95, 0x7c, 0xf0, 0x7e,
  24143. 0x57, 0x74, 0x7c, 0xdd, 0xa3, 0x0b, 0x2b, 0x36
  24144. },
  24145. { /* Finished 2 */
  24146. 0x28, 0xf2, 0xf2, 0x79, 0xcf, 0x20, 0x52, 0x90,
  24147. 0x1d, 0x91, 0x05, 0xad, 0x44, 0x26, 0x23, 0x96,
  24148. 0x32, 0xce, 0xec, 0x61, 0xd1, 0xbf, 0x00, 0x48,
  24149. 0x4a, 0xa5, 0x60, 0xcc, 0x28, 0xb5, 0x8d, 0x98
  24150. },
  24151. { /* Client Early Traffic Secret */
  24152. 0x07, 0x14, 0x6a, 0x26, 0x5b, 0x6c, 0x7f, 0x4d, 0x6b, 0x47, 0x3f, 0xd5,
  24153. 0x03, 0x1d, 0xd2, 0x23, 0x3d, 0x89, 0x3e, 0xc6, 0x51, 0xd1, 0xac, 0xf8,
  24154. 0x28, 0xae, 0x4b, 0x76, 0xc8, 0x10, 0x7e, 0xdd
  24155. },
  24156. { /* Early Exporter Master Secret */
  24157. 0xb8, 0xd3, 0x25, 0x7e, 0x2d, 0x41, 0x7b, 0xcb, 0x5e, 0x82, 0x49, 0xf5,
  24158. 0x51, 0x3d, 0xb7, 0x59, 0x32, 0xb3, 0xdf, 0x99, 0x4e, 0x04, 0x69, 0xc6,
  24159. 0x96, 0x8e, 0xe6, 0x3d, 0x91, 0xe4, 0x81, 0x11
  24160. },
  24161. { /* Client Handshake Traffic Secret */
  24162. 0xd9, 0x3b, 0x54, 0xe2, 0xb0, 0xd1, 0x85, 0xf0, 0xfd, 0xf3, 0x48, 0x4a,
  24163. 0xf8, 0x0b, 0xa5, 0xdc, 0x4c, 0x37, 0xcb, 0xd4, 0x20, 0xaf, 0x60, 0xc7,
  24164. 0xd5, 0x50, 0x5d, 0x0c, 0x77, 0x3b, 0x6f, 0xd2
  24165. },
  24166. { /* Server Handshake Traffic Secret */
  24167. 0x4d, 0x40, 0x2b, 0xd2, 0x8c, 0x33, 0x90, 0x39, 0x67, 0x67, 0x05, 0xf7,
  24168. 0x5d, 0x37, 0x1e, 0xdc, 0x4a, 0x70, 0x6b, 0x9e, 0xf8, 0x06, 0x61, 0x89,
  24169. 0x70, 0xe1, 0x3d, 0x36, 0xad, 0x88, 0x7e, 0x5b
  24170. },
  24171. { /* Client Application Traffic Secret */
  24172. 0x74, 0x6e, 0xa0, 0x13, 0x18, 0x34, 0x48, 0x4d, 0x23, 0x31, 0xf1, 0xf9,
  24173. 0xee, 0x44, 0x6d, 0xad, 0xc1, 0xad, 0x92, 0x73, 0xca, 0x27, 0x16, 0x91,
  24174. 0xa2, 0x50, 0x9a, 0xfc, 0xec, 0xf0, 0x6b, 0x24
  24175. },
  24176. { /* Server Application Traffic Secret */
  24177. 0x89, 0x18, 0x7e, 0x34, 0x8d, 0xfc, 0x14, 0xb1, 0x4f, 0x21, 0xd8, 0x29,
  24178. 0xdb, 0x9b, 0xfb, 0x55, 0xcf, 0xa1, 0x4f, 0x95, 0xf8, 0xe0, 0xb0, 0x83,
  24179. 0xd5, 0x34, 0x9e, 0x0b, 0x83, 0x37, 0x42, 0x93
  24180. },
  24181. { /* Exporter Master Secret */
  24182. 0x7d, 0xc8, 0x88, 0x46, 0xd5, 0x57, 0x15, 0xb6, 0x24, 0x25, 0x92, 0x61,
  24183. 0xb1, 0x18, 0x86, 0x2a, 0x6d, 0xa5, 0x84, 0xeb, 0x59, 0xdf, 0x13, 0xbd,
  24184. 0x73, 0xaa, 0x5d, 0x65, 0xab, 0xd9, 0xb4, 0x56
  24185. },
  24186. { /* Resumption Master Secret */
  24187. 0x20, 0xb7, 0xd0, 0xe3, 0x82, 0x01, 0xa1, 0x04, 0xb8, 0x13, 0x29, 0xed,
  24188. 0x35, 0xe4, 0x2f, 0xbf, 0x58, 0x23, 0x7f, 0x21, 0xdb, 0x9f, 0xf8, 0xe0,
  24189. 0xe8, 0xe4, 0xab, 0xc4, 0xa1, 0x61, 0xb9, 0xbb
  24190. }
  24191. },
  24192. { /* 6 */
  24193. WC_HASH_TYPE_SHA256, 0, 33,
  24194. { 0 }, /* PSK */
  24195. { /* DHE */
  24196. 0x7a, 0x46, 0x8c, 0x5a, 0xd1, 0x8e, 0x95, 0xba,
  24197. 0x61, 0xe6, 0x6f, 0xe6, 0x76, 0x0c, 0x20, 0x43,
  24198. 0x16, 0x82, 0x15, 0xfe, 0x54, 0xa3, 0xc7, 0xfd,
  24199. 0x3b, 0x2c, 0x88, 0xb4, 0xd3, 0x42, 0x70, 0x12,
  24200. 0x18
  24201. },
  24202. { /* Hello 1 */
  24203. 0x63, 0x83, 0x58, 0xab, 0x36, 0xcd, 0x0c, 0xf3,
  24204. 0x26, 0x07, 0xb5, 0x5f, 0x0b, 0x8b, 0x45, 0xd6,
  24205. 0x7d, 0x5b, 0x42, 0xdc, 0xa8, 0xaa, 0x06, 0xfb,
  24206. 0x20, 0xa5, 0xbb, 0x85, 0xdb, 0x54, 0xd8, 0x8b
  24207. },
  24208. { /* Hello 2 */
  24209. 0xea, 0xfe, 0x9e, 0x8e, 0xff, 0x1f, 0x6f, 0x43,
  24210. 0xf9, 0x5d, 0xfd, 0xbf, 0xe2, 0x5f, 0x02, 0x2f,
  24211. 0x6d, 0x47, 0x60, 0x9a, 0x48, 0x9a, 0x75, 0xfb,
  24212. 0xb5, 0x4a, 0xbf, 0x9c, 0x4e, 0xff, 0xbf, 0x0b
  24213. },
  24214. { /* Finished 1 */
  24215. 0xca, 0x25, 0xb3, 0x53, 0x8e, 0x6d, 0xc3, 0x36,
  24216. 0x17, 0x30, 0x07, 0xdf, 0x0d, 0xd7, 0x79, 0xb0,
  24217. 0x7f, 0xcb, 0xbe, 0x7a, 0xbc, 0x2d, 0x9f, 0x2d,
  24218. 0x94, 0x44, 0x94, 0xe6, 0xa4, 0xf3, 0xe8, 0x53
  24219. },
  24220. { /* Finished 2 */
  24221. 0x2e, 0xa6, 0x5a, 0xaf, 0xb5, 0xba, 0x9f, 0x2f,
  24222. 0x74, 0x83, 0x5d, 0xbf, 0x86, 0xa4, 0xa6, 0xf6,
  24223. 0xb9, 0x89, 0xdf, 0x17, 0xe1, 0xa8, 0x14, 0xc0,
  24224. 0xe1, 0x50, 0xfa, 0xec, 0xfa, 0xae, 0x8b, 0x7b
  24225. },
  24226. {
  24227. 0x20, 0x18, 0x72, 0x7c, 0xde, 0x3a, 0x85, 0x17, 0x72, 0xdc, 0xd7, 0x72,
  24228. 0xb0, 0xfc, 0x45, 0xd0, 0x62, 0xb9, 0xbb, 0x38, 0x69, 0x05, 0x7b, 0xb4,
  24229. 0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
  24230. },
  24231. {
  24232. 0x68, 0x10, 0x20, 0xd1, 0x5e, 0xfc, 0x0c, 0x53, 0x85, 0xbb, 0xdb, 0x18,
  24233. 0xa8, 0x78, 0xf1, 0x2b, 0x13, 0xba, 0x64, 0x1d, 0xe7, 0x09, 0xbe, 0x13,
  24234. 0x49, 0x26, 0xf9, 0x98, 0x56, 0xf1, 0x43, 0xfb
  24235. },
  24236. {
  24237. 0x24, 0x35, 0x3e, 0x10, 0x6f, 0x39, 0x50, 0xd6, 0xa2, 0x12, 0x99, 0xf2,
  24238. 0xd5, 0xf5, 0x19, 0xf5, 0x84, 0xed, 0xee, 0x78, 0x2a, 0xa6, 0xfa, 0x3d,
  24239. 0x06, 0xa8, 0xa7, 0x5d, 0x97, 0x78, 0xd6, 0x58
  24240. },
  24241. {
  24242. 0xf4, 0x57, 0xac, 0x24, 0x7a, 0xfb, 0x7c, 0x3b, 0xb6, 0x39, 0x17, 0x14,
  24243. 0xd9, 0xd4, 0x58, 0x4d, 0x46, 0xd5, 0x1b, 0xde, 0xf7, 0x9d, 0x06, 0xee,
  24244. 0x8d, 0x1a, 0x2c, 0x25, 0x6d, 0x64, 0xde, 0x89
  24245. },
  24246. {
  24247. 0xb6, 0x00, 0xce, 0x63, 0xed, 0x65, 0x8b, 0x66, 0x66, 0x42, 0xc6, 0xbd,
  24248. 0x89, 0xc4, 0x71, 0x6f, 0xce, 0x28, 0xb2, 0xac, 0x97, 0x07, 0x5b, 0xea,
  24249. 0xb8, 0x1d, 0x4c, 0xeb, 0x9e, 0x71, 0x07, 0x8f
  24250. },
  24251. {
  24252. 0xf8, 0x92, 0xc8, 0xba, 0xe7, 0x83, 0xfe, 0x68, 0xe4, 0xd6, 0x5e, 0xcb,
  24253. 0xb3, 0xef, 0x49, 0xd0, 0xe7, 0xb1, 0xac, 0xcb, 0x39, 0x19, 0xfd, 0xa7,
  24254. 0xf7, 0xca, 0xab, 0x1e, 0x42, 0x14, 0xd8, 0xe7
  24255. },
  24256. {
  24257. 0x32, 0x4a, 0x1a, 0xad, 0xe2, 0xbb, 0x55, 0x8a, 0xdd, 0xe9, 0xa5, 0x2a,
  24258. 0x46, 0x5e, 0x6c, 0x83, 0x66, 0x27, 0x27, 0x94, 0xdd, 0x68, 0x59, 0xa0,
  24259. 0xbb, 0xe8, 0x31, 0x7c, 0x39, 0xd7, 0xfd, 0x6d
  24260. },
  24261. {
  24262. 0x58, 0xbc, 0x6c, 0x5b, 0x24, 0xad, 0x82, 0xb3, 0xcc, 0xc7, 0xd1, 0xa1,
  24263. 0xaa, 0x2b, 0x98, 0x9f, 0x2f, 0x7e, 0xa9, 0x63, 0xc2, 0x8e, 0xb6, 0x06,
  24264. 0xc2, 0x2b, 0x74, 0x4b, 0x79, 0x19, 0x7e, 0x2e
  24265. }
  24266. },
  24267. { /* 11 */
  24268. WC_HASH_TYPE_SHA256, 33, 0,
  24269. { /* PSK */
  24270. 0x3d, 0x39, 0x49, 0x36, 0x98, 0xc5, 0xfd, 0xcd,
  24271. 0xa0, 0x17, 0xbd, 0x65, 0x0a, 0xdb, 0xd4, 0x07,
  24272. 0x56, 0xa2, 0x7b, 0xb8, 0x2a, 0x7e, 0xfb, 0x26,
  24273. 0x74, 0xe1, 0xbc, 0x08, 0x4b, 0xf0, 0x30, 0x14,
  24274. 0x12
  24275. },
  24276. { 0 }, /* DHE */
  24277. { /* Hello 1 */
  24278. 0xb7, 0x44, 0x74, 0x6c, 0x57, 0x1f, 0xf3, 0x84,
  24279. 0x8f, 0x63, 0xfb, 0x8c, 0x94, 0x6c, 0x16, 0x68,
  24280. 0x4b, 0xe1, 0xb5, 0xb5, 0x2a, 0x4e, 0x5f, 0xdf,
  24281. 0x4b, 0x53, 0xb2, 0x35, 0xfc, 0x30, 0xf1, 0x36
  24282. },
  24283. { /* Hello 2 */
  24284. 0xe6, 0x4f, 0x3a, 0x4f, 0xd7, 0xe0, 0x64, 0xd4,
  24285. 0x69, 0x50, 0xe4, 0x8b, 0xba, 0xbc, 0x47, 0x74,
  24286. 0xa7, 0x9b, 0x40, 0x91, 0x8f, 0xa8, 0x72, 0x22,
  24287. 0x97, 0xad, 0x43, 0xa7, 0x11, 0x86, 0xb5, 0x72
  24288. },
  24289. { /* Finished 1 */
  24290. 0x5f, 0xa6, 0x10, 0xe2, 0xa3, 0x99, 0x0b, 0x5e,
  24291. 0x57, 0xee, 0xc3, 0x3a, 0x8e, 0x04, 0xf3, 0x0e,
  24292. 0x58, 0x02, 0x09, 0xb2, 0x7e, 0x2d, 0xc6, 0xd2,
  24293. 0x08, 0xae, 0x68, 0x0a, 0x55, 0xa5, 0xda, 0x51
  24294. },
  24295. { /* Finished 2 */
  24296. 0xfc, 0x5b, 0xc0, 0x7e, 0x1b, 0xaa, 0xc0, 0xb4,
  24297. 0x34, 0x85, 0x49, 0x8e, 0x16, 0x31, 0x98, 0xdf,
  24298. 0x10, 0x54, 0x22, 0xda, 0x1e, 0x6b, 0x51, 0xf6,
  24299. 0x97, 0x57, 0xa0, 0x7a, 0x92, 0xe7, 0x47, 0x52
  24300. },
  24301. {
  24302. 0x80, 0xfa, 0x36, 0x30, 0xb8, 0x65, 0xb3, 0x2a, 0x1d, 0x68, 0x91, 0x06,
  24303. 0x98, 0xa0, 0x17, 0x8f, 0xee, 0xb7, 0x9e, 0x3d, 0xd8, 0x84, 0x99, 0x30,
  24304. 0xb9, 0xd6, 0x09, 0x25, 0x5e, 0xfb, 0x8f, 0xd3 },
  24305. {
  24306. 0xa9, 0x89, 0x29, 0x70, 0xe4, 0x55, 0xec, 0x97, 0xfb, 0x24, 0x5b, 0xf9,
  24307. 0xf1, 0xa3, 0x19, 0x3d, 0xf1, 0x31, 0x14, 0xcd, 0x2a, 0xed, 0x21, 0xc8,
  24308. 0xb1, 0x53, 0xad, 0x11, 0x0b, 0x9e, 0x5a, 0xee },
  24309. {
  24310. 0x72, 0xad, 0x8d, 0x7f, 0xfc, 0xb7, 0x68, 0xda, 0x27, 0x60, 0x37, 0xa3,
  24311. 0x4a, 0x63, 0xe8, 0xa5, 0xc8, 0xcd, 0x36, 0x6a, 0x77, 0x99, 0x0d, 0xa9,
  24312. 0xb1, 0x5b, 0x2f, 0x47, 0x2e, 0x22, 0xa7, 0x5e },
  24313. {
  24314. 0x95, 0x6e, 0x85, 0x09, 0xe5, 0x04, 0x88, 0x14, 0x28, 0x8d, 0xdf, 0xe6,
  24315. 0x0d, 0x0f, 0x0d, 0x6b, 0x4e, 0x66, 0x1c, 0x03, 0xb9, 0xaa, 0x2d, 0x45,
  24316. 0x56, 0x67, 0x5c, 0x55, 0x29, 0xd6, 0x89, 0xd0 },
  24317. {
  24318. 0xe8, 0xf2, 0x14, 0xf9, 0x9b, 0x2b, 0x9f, 0x24, 0x2b, 0x37, 0xbe, 0x86,
  24319. 0xdb, 0x23, 0x4b, 0xbe, 0x39, 0x57, 0xe8, 0xa9, 0xa5, 0xee, 0x08, 0xf2,
  24320. 0x75, 0x58, 0xdb, 0xd9, 0x51, 0xc1, 0x46, 0x02 },
  24321. {
  24322. 0x3d, 0x19, 0xaf, 0xa3, 0x0b, 0x21, 0xf7, 0x3d, 0xe7, 0x37, 0x6e, 0x32,
  24323. 0x13, 0x48, 0x9d, 0xea, 0xe0, 0x90, 0xbf, 0x64, 0x48, 0xf7, 0x1e, 0xcc,
  24324. 0xf0, 0xbc, 0x92, 0xd7, 0x8a, 0x4a, 0xa8, 0xc1 },
  24325. {
  24326. 0x16, 0x35, 0xb1, 0x66, 0x28, 0xa3, 0x3e, 0x19, 0xf5, 0x2d, 0x92, 0x22,
  24327. 0x95, 0x48, 0xe8, 0x34, 0x7b, 0x30, 0x50, 0xa2, 0xa0, 0xd9, 0xc2, 0x59,
  24328. 0x39, 0xf9, 0x8c, 0x69, 0xf2, 0x2a, 0xb9, 0xff },
  24329. {
  24330. 0x32, 0x71, 0xa6, 0x87, 0x0c, 0x97, 0x42, 0x07, 0xdd, 0x5f, 0xc9, 0x44,
  24331. 0xa5, 0x7c, 0x50, 0x14, 0xfd, 0xe7, 0x5f, 0x8b, 0xd3, 0x2f, 0xdc, 0x9b,
  24332. 0xa9, 0x93, 0x22, 0x19, 0xe6, 0xf2, 0x0c, 0xd8 }
  24333. },
  24334. #ifdef WOLFSSL_SHA384
  24335. { /* 26 */
  24336. WC_HASH_TYPE_SHA384, 35, 35,
  24337. { /* PSK */
  24338. 0x62, 0x83, 0x25, 0xc7, 0xcc, 0x08, 0x5e, 0x63,
  24339. 0x64, 0x56, 0xf0, 0xc6, 0x88, 0x27, 0x5a, 0x5b,
  24340. 0x68, 0x59, 0x0b, 0x14, 0x55, 0x13, 0x2e, 0xfd,
  24341. 0x8f, 0x28, 0x5b, 0x3d, 0xe3, 0xad, 0x67, 0xe4,
  24342. 0x68, 0xba, 0xf9
  24343. },
  24344. { /* DHE */
  24345. 0xa8, 0xb1, 0xab, 0xd8, 0xc8, 0x5b, 0x52, 0xdf,
  24346. 0x7f, 0x49, 0x10, 0xf4, 0xa1, 0x31, 0xd1, 0x91,
  24347. 0x36, 0xc1, 0x87, 0x5d, 0x42, 0x2a, 0xe7, 0x1d,
  24348. 0x2c, 0x29, 0x3d, 0x40, 0x64, 0x61, 0x63, 0x76,
  24349. 0xd8, 0x66, 0xac
  24350. },
  24351. { /* Hello 1 */
  24352. 0x6f, 0xc6, 0x4c, 0xe1, 0xc6, 0x68, 0x34, 0x8c,
  24353. 0x0a, 0xe1, 0xf8, 0xb8, 0x3e, 0xd4, 0xf8, 0x0b,
  24354. 0x54, 0x50, 0xe4, 0xc5, 0x4a, 0x33, 0x7d, 0xbd,
  24355. 0x90, 0xd2, 0xa2, 0xb9, 0xb7, 0x92, 0xed, 0xab,
  24356. 0x14, 0xf1, 0xe4, 0x86, 0x22, 0x67, 0xd7, 0x44,
  24357. 0x03, 0x21, 0xdc, 0x51, 0x52, 0x7f, 0x35, 0x80
  24358. },
  24359. { /* Hello 2 */
  24360. 0x3e, 0xcf, 0x2f, 0xc3, 0x87, 0xba, 0xc5, 0xbd,
  24361. 0x7c, 0xe8, 0x35, 0x5b, 0x95, 0x51, 0x30, 0x3b,
  24362. 0x08, 0xcc, 0x2a, 0x7d, 0xb5, 0x74, 0x7c, 0x16,
  24363. 0xb3, 0x0b, 0xe7, 0x61, 0xa3, 0x7c, 0x6c, 0xbd,
  24364. 0x39, 0x74, 0xfd, 0x1e, 0x4c, 0xff, 0xc8, 0xcc,
  24365. 0xa0, 0xef, 0x29, 0x4d, 0x94, 0xaa, 0x55, 0x6f,
  24366. },
  24367. { /* Finished 1 */
  24368. 0x06, 0xc1, 0x47, 0x78, 0x66, 0x53, 0x6f, 0x24,
  24369. 0x94, 0x61, 0x69, 0xec, 0xd8, 0x60, 0x31, 0x2f,
  24370. 0xbf, 0xd6, 0x8a, 0x29, 0x17, 0xff, 0xa3, 0x88,
  24371. 0x13, 0x09, 0x8c, 0x9d, 0x6c, 0x64, 0x84, 0x48,
  24372. 0x44, 0xdd, 0x2d, 0x29, 0x4d, 0xe6, 0x98, 0x2b,
  24373. 0x45, 0x3b, 0x84, 0x33, 0x79, 0xb2, 0x75, 0x68
  24374. },
  24375. { /* Finished 2 */
  24376. 0x28, 0x1e, 0x18, 0xf7, 0x9c, 0x32, 0xa9, 0xbf,
  24377. 0x0c, 0x24, 0x58, 0x21, 0xce, 0xbc, 0xf2, 0x44,
  24378. 0xb1, 0x18, 0xaf, 0x9d, 0xd9, 0x20, 0xf9, 0xf4,
  24379. 0xed, 0xcc, 0x53, 0x82, 0x66, 0x5c, 0x46, 0x94,
  24380. 0x8c, 0x36, 0x5e, 0xca, 0x9f, 0xd8, 0x9a, 0xd3,
  24381. 0xf0, 0xe1, 0x53, 0x71, 0xdd, 0x19, 0x1e, 0x59
  24382. },
  24383. {
  24384. 0xd0, 0xef, 0xa8, 0xcb, 0x5b, 0x14, 0x0f, 0x0a, 0x62, 0xba, 0x5a, 0xb1,
  24385. 0xc5, 0xb5, 0x3f, 0x11, 0xda, 0xa1, 0x0c, 0x9c, 0xb4, 0x32, 0x48, 0x4e,
  24386. 0xfa, 0x84, 0x4f, 0xe4, 0xe7, 0x91, 0x8f, 0x42, 0x3f, 0xc7, 0x4e, 0xd3,
  24387. 0x83, 0x3d, 0x7f, 0x70, 0x12, 0xee, 0x9a, 0x37, 0x01, 0xbb, 0x14, 0xd3
  24388. },
  24389. {
  24390. 0x48, 0x6f, 0x77, 0x1d, 0x39, 0x1b, 0xa5, 0x9a, 0x76, 0xd9, 0x1d, 0x7d,
  24391. 0xb3, 0xd9, 0xb9, 0x78, 0x35, 0x0f, 0xd0, 0xe1, 0x07, 0x1f, 0x8d, 0xe5,
  24392. 0x75, 0x00, 0xda, 0xc0, 0x19, 0x01, 0xfb, 0x08, 0x35, 0xe7, 0x18, 0x8f,
  24393. 0xf0, 0x19, 0xfb, 0x46, 0xf6, 0xa5, 0x77, 0x0e, 0x90, 0x38, 0x8b, 0x15
  24394. },
  24395. {
  24396. 0x80, 0x8c, 0xa7, 0x24, 0x97, 0xf9, 0xd3, 0x52, 0xb0, 0x69, 0x9d, 0x4b,
  24397. 0xa4, 0x19, 0x4a, 0xb1, 0x46, 0x53, 0x3a, 0xc8, 0xe4, 0x02, 0x69, 0xf2,
  24398. 0xe7, 0xb6, 0x1d, 0x33, 0x51, 0xcc, 0x14, 0x40, 0x4a, 0xb0, 0xe7, 0x58,
  24399. 0x84, 0xba, 0xc2, 0x14, 0x58, 0x6b, 0xb9, 0xdc, 0x50, 0x98, 0x67, 0x01
  24400. },
  24401. {
  24402. 0xb1, 0xa8, 0xc0, 0x06, 0xb3, 0x2e, 0xa7, 0x8a, 0x6a, 0x12, 0x88, 0x00,
  24403. 0x65, 0x88, 0x9c, 0x5d, 0x35, 0xee, 0xe5, 0x51, 0x0b, 0x62, 0xf8, 0x67,
  24404. 0xe5, 0xef, 0x15, 0x1f, 0x23, 0x02, 0x74, 0x08, 0x9c, 0xc8, 0xba, 0x27,
  24405. 0x5d, 0x32, 0x19, 0x6f, 0x6d, 0x5d, 0x72, 0x5e, 0x15, 0xde, 0x30, 0xc3
  24406. },
  24407. {
  24408. 0xfd, 0xce, 0xf5, 0x65, 0x45, 0x84, 0xfb, 0x8c, 0x79, 0xa4, 0x6c, 0x1b,
  24409. 0x0e, 0x1b, 0xfd, 0x26, 0xa2, 0x53, 0xf4, 0x4e, 0x00, 0x4d, 0x4b, 0x0b,
  24410. 0x24, 0x6d, 0x35, 0x35, 0xd9, 0x97, 0x70, 0xc5, 0xf4, 0xee, 0xe3, 0xba,
  24411. 0x31, 0x1e, 0x2a, 0x42, 0xcb, 0xdf, 0x40, 0xb1, 0x14, 0xb8, 0x53, 0xce
  24412. },
  24413. {
  24414. 0xbb, 0xb3, 0x26, 0x7c, 0x22, 0x21, 0x9b, 0x72, 0x32, 0xa1, 0x97, 0xfb,
  24415. 0x78, 0x8c, 0xbe, 0x3d, 0x71, 0x45, 0xb8, 0xf5, 0x24, 0x8f, 0x0f, 0xac,
  24416. 0x42, 0x5b, 0x81, 0xe8, 0xd0, 0x71, 0x4a, 0xcb, 0x32, 0x3f, 0x03, 0xfb,
  24417. 0xec, 0x6a, 0x1f, 0x76, 0x80, 0x65, 0x01, 0x7a, 0x3d, 0xce, 0xc4, 0xdf
  24418. },
  24419. {
  24420. 0x3f, 0xcf, 0x2f, 0x63, 0x94, 0x94, 0x99, 0xfd, 0x04, 0x3a, 0x89, 0x83,
  24421. 0xcf, 0x06, 0x05, 0xec, 0x20, 0x3e, 0x5f, 0x51, 0x9d, 0x6e, 0x4a, 0xc6,
  24422. 0xf1, 0x2b, 0x37, 0x17, 0x34, 0x72, 0x6e, 0x1d, 0x2a, 0xfd, 0xc7, 0x73,
  24423. 0xb5, 0x07, 0x22, 0x81, 0x32, 0x2e, 0x21, 0x85, 0xaf, 0x10, 0xb2, 0x73
  24424. },
  24425. {
  24426. 0x52, 0x0c, 0x3d, 0x2e, 0x2d, 0x4a, 0x11, 0xae, 0x96, 0x78, 0xe9, 0x5b,
  24427. 0xd8, 0x0f, 0x6c, 0xf4, 0xbd, 0x96, 0x13, 0x55, 0x88, 0xdd, 0xa3, 0x67,
  24428. 0x36, 0x86, 0x1e, 0x0b, 0x36, 0x41, 0xec, 0xf6, 0x04, 0xb2, 0xc4, 0x16,
  24429. 0xbc, 0x2c, 0xdb, 0x30, 0x02, 0x94, 0xd4, 0x42, 0xbf, 0x38, 0xee, 0x9d
  24430. }
  24431. },
  24432. { /* 36 */
  24433. WC_HASH_TYPE_SHA384, 0, 33,
  24434. { 0 }, /* PSK */
  24435. { /* DHE */
  24436. 0xd3, 0x00, 0x72, 0x9a, 0xa8, 0xc5, 0xf3, 0xc4,
  24437. 0xf1, 0xa0, 0x26, 0x89, 0x65, 0x70, 0xc7, 0x0b,
  24438. 0x77, 0xbb, 0xe1, 0x4b, 0x2b, 0xa8, 0x4f, 0xa6,
  24439. 0x09, 0x4b, 0xba, 0x45, 0x36, 0x15, 0xee, 0x68,
  24440. 0xfd
  24441. },
  24442. { /* Hello 1 */
  24443. 0x10, 0x9d, 0x8b, 0xa2, 0x93, 0xe7, 0xd3, 0xb9,
  24444. 0xb4, 0x0f, 0xeb, 0x6a, 0xb9, 0x69, 0xcb, 0x39,
  24445. 0x16, 0x29, 0xcc, 0xd3, 0xcc, 0x1a, 0x4c, 0x1b,
  24446. 0x53, 0x7c, 0x33, 0x88, 0x06, 0xbc, 0x0a, 0x02,
  24447. 0xa0, 0xbe, 0x62, 0xc0, 0xe6, 0x5e, 0x97, 0x5b,
  24448. 0x6a, 0xa1, 0x98, 0xf3, 0xd2, 0x1e, 0xcd, 0xc5
  24449. },
  24450. { /* Hello 2 */
  24451. 0x74, 0xc0, 0x07, 0x2c, 0xc1, 0x63, 0xcc, 0x11,
  24452. 0xad, 0x1a, 0x55, 0x63, 0xbc, 0x20, 0x77, 0x96,
  24453. 0x30, 0x1c, 0x68, 0x45, 0x1e, 0x9b, 0xa7, 0xb4,
  24454. 0xf3, 0x04, 0x45, 0x16, 0x76, 0x55, 0xf9, 0xdf,
  24455. 0x4b, 0x2f, 0x1a, 0xdf, 0x5a, 0xb0, 0x93, 0xc9,
  24456. 0xab, 0xf5, 0x32, 0x47, 0x79, 0x9c, 0x01, 0xeb
  24457. },
  24458. { /* Finished 1 */
  24459. 0x27, 0x08, 0x8e, 0xa5, 0xf1, 0x30, 0xe1, 0xd6,
  24460. 0x4f, 0xa2, 0x9e, 0x3b, 0x03, 0x2d, 0x2e, 0xa3,
  24461. 0x84, 0x75, 0x51, 0x3a, 0xc3, 0xf6, 0xee, 0x2e,
  24462. 0x37, 0x0c, 0xe3, 0x28, 0x46, 0xa5, 0x2d, 0xc7,
  24463. 0xf0, 0x64, 0x78, 0x53, 0x66, 0x43, 0x02, 0xa4,
  24464. 0x7a, 0x43, 0x66, 0x4b, 0xa7, 0xcb, 0x97, 0x16
  24465. },
  24466. { /* Finished 2 */
  24467. 0x1d, 0x0d, 0xf8, 0xe1, 0x81, 0xa5, 0xbd, 0xa8,
  24468. 0x6f, 0x9d, 0x01, 0xa4, 0x9a, 0x92, 0xe2, 0xef,
  24469. 0x08, 0xab, 0xef, 0x3e, 0x2d, 0xd4, 0x82, 0xac,
  24470. 0x68, 0x9d, 0xe0, 0x54, 0x17, 0xde, 0x1a, 0xed,
  24471. 0x57, 0xcb, 0xd9, 0x2d, 0xc8, 0xbc, 0x93, 0xe6,
  24472. 0xa3, 0xec, 0xde, 0xee, 0xa1, 0x1c, 0x41, 0x85
  24473. },
  24474. {
  24475. 0x7f, 0x1f, 0xe6, 0x7b, 0xd8, 0xf5, 0x2b, 0x37, 0xbe, 0xb7, 0xd0, 0x37,
  24476. 0xce, 0x46, 0xad, 0x04, 0x2f, 0xc7, 0xdb, 0xc9, 0x9a, 0xb6, 0x00, 0x3f,
  24477. 0xc1, 0x97, 0xe9, 0x5c, 0x5e, 0x14, 0xd1, 0x38, 0x4d, 0x55, 0xe1, 0x07,
  24478. 0xb5, 0x85, 0x6d, 0xfa, 0xa7, 0x66, 0xad, 0xfa, 0xb6, 0xad, 0x29, 0x44
  24479. },
  24480. {
  24481. 0x4e, 0x6b, 0x20, 0x99, 0x55, 0x1b, 0x21, 0x89, 0xb6, 0x70, 0xdb, 0xe8,
  24482. 0xa7, 0x16, 0x55, 0xf2, 0x93, 0x13, 0x90, 0x7d, 0xfa, 0x62, 0x65, 0x53,
  24483. 0xa0, 0x97, 0xe9, 0xb4, 0xc0, 0xf1, 0xc9, 0x1a, 0x67, 0xdd, 0xca, 0x57,
  24484. 0xbc, 0xca, 0x39, 0xe6, 0x39, 0x6b, 0x63, 0x47, 0x25, 0x08, 0x3a, 0xd7
  24485. },
  24486. {
  24487. 0x35, 0x0d, 0xac, 0xd8, 0x10, 0x6a, 0x46, 0x50, 0x66, 0xae, 0x02, 0xc9,
  24488. 0xde, 0x13, 0x48, 0xce, 0x53, 0xd4, 0x92, 0x62, 0xc5, 0x65, 0x10, 0x08,
  24489. 0xc2, 0xc2, 0x82, 0xed, 0x9d, 0xc9, 0x6f, 0xa8, 0xc3, 0xc1, 0x0b, 0x7c,
  24490. 0xe1, 0x97, 0x85, 0xd6, 0x46, 0x29, 0x0e, 0x42, 0x51, 0xc1, 0x35, 0xcf
  24491. },
  24492. {
  24493. 0x3d, 0x5d, 0x84, 0xbd, 0x16, 0x46, 0x34, 0xb3, 0xf6, 0x31, 0x49, 0x3e,
  24494. 0x8d, 0xdc, 0xcb, 0x8c, 0x6a, 0x42, 0xf4, 0x88, 0xfc, 0x19, 0xfa, 0xa2,
  24495. 0x25, 0xc7, 0xa0, 0xa4, 0xca, 0xf0, 0xea, 0x2d, 0xe8, 0xc4, 0x02, 0x14,
  24496. 0x63, 0xfb, 0xd3, 0x7b, 0x51, 0x1c, 0xce, 0xca, 0xa3, 0xc3, 0xe4, 0xa5
  24497. },
  24498. {
  24499. 0x7c, 0x3a, 0x55, 0x92, 0x2e, 0xdd, 0x75, 0xdd, 0x76, 0x54, 0x4a, 0x9f,
  24500. 0xd0, 0xa2, 0x88, 0x83, 0xe9, 0x27, 0xda, 0x30, 0xe9, 0x96, 0x58, 0xc5,
  24501. 0xb7, 0x56, 0xfc, 0x4b, 0xb8, 0x5d, 0xee, 0x46, 0x70, 0x4e, 0x1b, 0x06,
  24502. 0x86, 0xaf, 0x48, 0x5c, 0x17, 0x35, 0xfa, 0x69, 0xc2, 0x4d, 0xfb, 0x09
  24503. },
  24504. {
  24505. 0x00, 0x0e, 0x28, 0x51, 0xc1, 0x7f, 0x41, 0x89, 0x6f, 0x9a, 0xca, 0x15,
  24506. 0xee, 0xed, 0x43, 0xca, 0x6d, 0x65, 0x6f, 0x51, 0x18, 0x6c, 0x08, 0x4b,
  24507. 0x77, 0xca, 0x75, 0xc4, 0xc3, 0xde, 0x29, 0x41, 0x8b, 0xaf, 0xa7, 0x1c,
  24508. 0x28, 0x37, 0xa0, 0xa0, 0x74, 0x8e, 0x09, 0x42, 0x7a, 0x1b, 0x68, 0xdb
  24509. },
  24510. {
  24511. 0x14, 0x8f, 0xab, 0x28, 0x64, 0xea, 0x45, 0x88, 0xdb, 0xc1, 0xc6, 0xa0,
  24512. 0x48, 0xdf, 0x15, 0xd0, 0x28, 0x07, 0x2d, 0x6c, 0xb8, 0x42, 0xbb, 0x60,
  24513. 0x02, 0x08, 0x9e, 0x29, 0x9b, 0x8d, 0xd6, 0x1c, 0xaf, 0xf2, 0x1a, 0xdc,
  24514. 0xf0, 0x78, 0x0b, 0x4d, 0x90, 0xa1, 0x0c, 0xb3, 0x13, 0xde, 0xca, 0x5a
  24515. },
  24516. {
  24517. 0x4d, 0x80, 0x7d, 0x0b, 0xb9, 0x00, 0x6f, 0x65, 0x51, 0x65, 0x23, 0xde,
  24518. 0x72, 0xdc, 0x4f, 0x04, 0xa5, 0xa2, 0x90, 0x45, 0x51, 0x9e, 0xd0, 0x3a,
  24519. 0xe4, 0xd7, 0x78, 0xa3, 0x0f, 0x2d, 0x65, 0x12, 0xad, 0xc8, 0x92, 0x30,
  24520. 0x79, 0x9d, 0x9d, 0x08, 0x7a, 0x9c, 0x9f, 0x83, 0xb1, 0xca, 0x59, 0x56
  24521. }
  24522. },
  24523. { /* 41 */
  24524. WC_HASH_TYPE_SHA384, 33, 0,
  24525. { /* PSK */
  24526. 0xa4, 0x8b, 0x1b, 0x5f, 0xd0, 0xea, 0x75, 0x62,
  24527. 0x06, 0x4d, 0x68, 0x40, 0x85, 0x20, 0x45, 0x95,
  24528. 0x4a, 0x00, 0xca, 0x05, 0xeb, 0xd4, 0x1d, 0x48,
  24529. 0x81, 0x89, 0xe8, 0x86, 0x43, 0xfa, 0x28, 0x17,
  24530. 0x12
  24531. },
  24532. { 0 }, /* DHE */
  24533. { /* Hello 1 */
  24534. 0x03, 0x7c, 0x33, 0x75, 0xdc, 0xc5, 0x46, 0x3a,
  24535. 0x0d, 0x56, 0xc6, 0xfb, 0xab, 0x1e, 0x1d, 0xda,
  24536. 0x59, 0xc2, 0xb2, 0xb1, 0x7c, 0x48, 0x9b, 0x06,
  24537. 0x0a, 0x5a, 0xbb, 0xf8, 0x98, 0x53, 0x78, 0x2d,
  24538. 0xd2, 0xcc, 0x87, 0x68, 0x25, 0xdd, 0x88, 0x22,
  24539. 0xcd, 0xb7, 0x74, 0x55, 0x21, 0xf9, 0x34, 0x98
  24540. },
  24541. { /* Hello 2 */
  24542. 0x03, 0xb4, 0xfb, 0xcc, 0x28, 0x2c, 0xc1, 0x70,
  24543. 0x42, 0x73, 0x57, 0xac, 0xdb, 0x47, 0x71, 0xf6,
  24544. 0x2e, 0x11, 0x8a, 0x5b, 0x47, 0x2f, 0x02, 0x54,
  24545. 0x95, 0x34, 0xed, 0x5f, 0x19, 0xc1, 0x75, 0xe0,
  24546. 0x76, 0xad, 0xb0, 0x90, 0x57, 0xcd, 0xfd, 0xd7,
  24547. 0x58, 0x1f, 0x0d, 0x6b, 0x9e, 0x51, 0x3c, 0x08
  24548. },
  24549. { /* Finished 1 */
  24550. 0x2b, 0x50, 0xd9, 0xa7, 0x43, 0x24, 0xda, 0x2c,
  24551. 0x7a, 0xaa, 0x0e, 0x37, 0xd7, 0x6b, 0x2c, 0xab,
  24552. 0x8e, 0xb2, 0xfe, 0x31, 0x1b, 0xa8, 0x12, 0x59,
  24553. 0x5b, 0x7b, 0xdc, 0x3e, 0xa7, 0x86, 0xa5, 0x48,
  24554. 0xe4, 0x46, 0x2b, 0x4c, 0xc1, 0x66, 0x4b, 0xf3,
  24555. 0x2a, 0x99, 0x93, 0x08, 0xbc, 0x3d, 0x08, 0x76
  24556. },
  24557. { /* Finished 2 */
  24558. 0x7c, 0x34, 0xc8, 0x56, 0x17, 0xf1, 0x62, 0x1c,
  24559. 0x9f, 0x0b, 0xeb, 0xfd, 0x69, 0x72, 0x51, 0xc5,
  24560. 0xfa, 0x74, 0x87, 0xc9, 0xbd, 0x50, 0xe9, 0x48,
  24561. 0xa7, 0x3c, 0x94, 0x3e, 0x06, 0x7d, 0xe8, 0x8e,
  24562. 0xc1, 0xd1, 0x08, 0x1f, 0x5d, 0x48, 0x8a, 0x25,
  24563. 0xfc, 0xea, 0xe7, 0xd9, 0xd4, 0xd0, 0xf9, 0xad
  24564. },
  24565. {
  24566. 0x4b, 0x0b, 0xed, 0xb9, 0xc8, 0xb8, 0xa8, 0x1e, 0xb0, 0x81, 0x76, 0xd5,
  24567. 0x33, 0x22, 0x71, 0x33, 0x3a, 0x85, 0x19, 0x67, 0x7e, 0x91, 0x37, 0xf2,
  24568. 0xa6, 0x11, 0x22, 0xdf, 0x41, 0x04, 0x3d, 0xa9, 0x13, 0xb9, 0xb2, 0xb1,
  24569. 0xbb, 0xd8, 0xef, 0x23, 0x7c, 0xc2, 0xab, 0x70, 0x1b, 0x51, 0x9f, 0xc9
  24570. },
  24571. {
  24572. 0xeb, 0x96, 0x10, 0x8c, 0x7d, 0x92, 0xea, 0x80, 0x86, 0xb2, 0xf8, 0x27,
  24573. 0xf2, 0x9a, 0x09, 0xc1, 0x7c, 0x09, 0x43, 0xbc, 0xfe, 0xc8, 0x75, 0xe0,
  24574. 0x97, 0xe7, 0x6d, 0xd5, 0xb2, 0x3c, 0xed, 0x12, 0xb7, 0x74, 0x0e, 0xe3,
  24575. 0xb6, 0xe0, 0xba, 0xe1, 0x8d, 0x89, 0xcf, 0x4f, 0x57, 0xf6, 0x6d, 0x90
  24576. },
  24577. {
  24578. 0x22, 0xb0, 0x39, 0x34, 0xb6, 0x6c, 0x2d, 0x7a, 0x97, 0x1c, 0x5d, 0xcc,
  24579. 0x78, 0x84, 0x71, 0xbb, 0xc6, 0x7b, 0xb6, 0xbc, 0xcc, 0x0b, 0xf8, 0xac,
  24580. 0x8e, 0xd7, 0x20, 0xbd, 0xbe, 0x32, 0xf0, 0xd6, 0xe9, 0x69, 0x13, 0xf2,
  24581. 0x9a, 0xce, 0xfe, 0x86, 0xd3, 0xee, 0xba, 0x69, 0x51, 0xb6, 0x77, 0x56
  24582. },
  24583. {
  24584. 0x16, 0xfd, 0xda, 0xf3, 0x5e, 0xb9, 0xa6, 0x17, 0x24, 0xb2, 0x16, 0x9f,
  24585. 0xb6, 0x59, 0x13, 0x0f, 0x25, 0x5a, 0xf1, 0x5b, 0x5f, 0xe4, 0x54, 0x2a,
  24586. 0xa7, 0xbf, 0x29, 0xaf, 0x5a, 0x77, 0xf4, 0x4f, 0x25, 0xba, 0x94, 0xad,
  24587. 0x6b, 0x91, 0x3b, 0xe7, 0xd5, 0x73, 0x0d, 0xff, 0xaa, 0xe3, 0x72, 0x2c
  24588. },
  24589. {
  24590. 0x22, 0xb4, 0x94, 0xc0, 0x53, 0xd7, 0x82, 0x06, 0x38, 0x9d, 0x4a, 0xa0,
  24591. 0x3f, 0xf1, 0x5f, 0x6e, 0x23, 0x8d, 0x09, 0x62, 0xbf, 0x6f, 0x7c, 0x84,
  24592. 0xc6, 0x3e, 0x15, 0xad, 0x18, 0x37, 0x76, 0x29, 0xc7, 0xd6, 0x68, 0x0c,
  24593. 0x1e, 0xc6, 0x93, 0x31, 0xef, 0x85, 0x69, 0x30, 0x68, 0xf0, 0x1e, 0x37
  24594. },
  24595. {
  24596. 0x6d, 0x4d, 0x20, 0xaf, 0x47, 0xe8, 0x1b, 0xfa, 0xd0, 0xb6, 0xc8, 0x97,
  24597. 0xd1, 0x03, 0xfc, 0x9d, 0x59, 0xa0, 0x68, 0x9d, 0xe9, 0x17, 0x8b, 0xce,
  24598. 0x48, 0x2c, 0x77, 0x8a, 0x22, 0x4b, 0x5c, 0x54, 0x22, 0xa1, 0x15, 0x12,
  24599. 0xe1, 0x07, 0x8e, 0x15, 0xd8, 0x7b, 0x16, 0x65, 0x99, 0x6b, 0xcb, 0x71
  24600. },
  24601. {
  24602. 0x79, 0x64, 0x79, 0xdd, 0x75, 0x5c, 0x6f, 0x98, 0xac, 0x03, 0xe0, 0xcd,
  24603. 0x92, 0xba, 0x0e, 0x2d, 0xb4, 0xd1, 0x8b, 0x97, 0xd0, 0x85, 0xbb, 0x2e,
  24604. 0x4f, 0x26, 0x93, 0xf5, 0x1d, 0xf3, 0xd2, 0x43, 0x4f, 0xd2, 0x47, 0xaa,
  24605. 0x91, 0x1e, 0xf3, 0x67, 0x10, 0x18, 0x2c, 0xb9, 0x01, 0xba, 0x10, 0x9f
  24606. },
  24607. {
  24608. 0x79, 0xb6, 0x9c, 0xbe, 0xf1, 0x6a, 0xb0, 0x92, 0xa0, 0x29, 0x52, 0x61,
  24609. 0xf1, 0xcd, 0x3a, 0x67, 0xe1, 0x6b, 0xb8, 0x9d, 0x0d, 0x95, 0xb6, 0x03,
  24610. 0x80, 0x1f, 0xd5, 0x75, 0xb6, 0x1d, 0x79, 0x02, 0x93, 0x43, 0x77, 0xa7,
  24611. 0x9d, 0x2f, 0xc3, 0x84, 0xc6, 0x83, 0x76, 0x16, 0x06, 0x98, 0x7b, 0x79
  24612. }
  24613. },
  24614. #endif /* WOLFSSL_SHA384 */
  24615. };
  24616. static const char protocolLabel[] = "tls13 ";
  24617. static const char ceTrafficLabel[] = "c e traffic";
  24618. static const char eExpMasterLabel[] = "e exp master";
  24619. static const char cHsTrafficLabel[] = "c hs traffic";
  24620. static const char sHsTrafficLabel[] = "s hs traffic";
  24621. static const char cAppTrafficLabel[] = "c ap traffic";
  24622. static const char sAppTrafficLabel[] = "s ap traffic";
  24623. static const char expMasterLabel[] = "exp master";
  24624. static const char resMasterLabel[] = "res master";
  24625. static const char derivedLabel[] = "derived";
  24626. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void)
  24627. {
  24628. wc_test_ret_t ret = 0;
  24629. word32 i;
  24630. word32 tc = sizeof(tls13KdfTestVectors)/sizeof(Tls13KdfTestVector);
  24631. const Tls13KdfTestVector* tv = NULL;
  24632. WOLFSSL_ENTER("tls13_kdf_test");
  24633. for (i = 0, tv = tls13KdfTestVectors; i < tc; i++, tv++) {
  24634. byte output[WC_MAX_DIGEST_SIZE];
  24635. byte secret[WC_MAX_DIGEST_SIZE];
  24636. byte salt[WC_MAX_DIGEST_SIZE];
  24637. byte zeroes[WC_MAX_DIGEST_SIZE];
  24638. byte hashZero[WC_MAX_DIGEST_SIZE];
  24639. int hashAlgSz;
  24640. XMEMSET(zeroes, 0, sizeof zeroes);
  24641. hashAlgSz = wc_HashGetDigestSize(tv->hashAlg);
  24642. if (hashAlgSz == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) break;
  24643. ret = wc_Hash(tv->hashAlg, NULL, 0, hashZero, (word32)hashAlgSz);
  24644. if (ret != 0) break;
  24645. ret = wc_Tls13_HKDF_Extract(secret, NULL, 0,
  24646. (tv->pskSz == 0) ? zeroes : (byte*)tv->psk,
  24647. tv->pskSz, (int)tv->hashAlg);
  24648. if (ret != 0) break;
  24649. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24650. secret, (word32)hashAlgSz,
  24651. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24652. (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel),
  24653. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24654. if (ret != 0) break;
  24655. ret = XMEMCMP(tv->clientEarlyTrafficSecret, output,
  24656. (unsigned long)hashAlgSz);
  24657. if (ret != 0) break;
  24658. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24659. secret, (word32)hashAlgSz,
  24660. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24661. (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel),
  24662. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24663. if (ret != 0) break;
  24664. ret = XMEMCMP(tv->earlyExporterMasterSecret, output,
  24665. (unsigned long)hashAlgSz);
  24666. if (ret != 0) break;
  24667. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24668. secret, (word32)hashAlgSz,
  24669. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24670. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24671. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24672. if (ret != 0) break;
  24673. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24674. (tv->dheSz == 0) ? zeroes : (byte*)tv->dhe,
  24675. tv->dheSz, (int)tv->hashAlg);
  24676. if (ret != 0) break;
  24677. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24678. secret, (word32)hashAlgSz,
  24679. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24680. (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel),
  24681. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24682. if (ret != 0) break;
  24683. ret = XMEMCMP(tv->clientHandshakeTrafficSecret,
  24684. output, (unsigned long)hashAlgSz);
  24685. if (ret != 0) break;
  24686. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24687. secret, (word32)hashAlgSz,
  24688. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24689. (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel),
  24690. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24691. if (ret != 0) break;
  24692. ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output,
  24693. (unsigned long)hashAlgSz);
  24694. if (ret != 0) break;
  24695. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24696. secret, (word32)hashAlgSz,
  24697. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24698. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24699. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24700. if (ret != 0) break;
  24701. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24702. zeroes, (word32)(word32)hashAlgSz, (int)tv->hashAlg);
  24703. if (ret != 0) break;
  24704. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24705. secret, (word32)hashAlgSz,
  24706. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24707. (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel),
  24708. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24709. if (ret != 0) break;
  24710. ret = XMEMCMP(tv->clientApplicationTrafficSecret, output,
  24711. (unsigned long)hashAlgSz);
  24712. if (ret != 0) break;
  24713. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24714. secret, (word32)hashAlgSz,
  24715. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24716. (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel),
  24717. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24718. if (ret != 0) break;
  24719. ret = XMEMCMP(tv->serverApplicationTrafficSecret, output,
  24720. (unsigned long)hashAlgSz);
  24721. if (ret != 0) break;
  24722. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24723. secret, (word32)hashAlgSz,
  24724. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24725. (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel),
  24726. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24727. if (ret != 0) break;
  24728. ret = XMEMCMP(tv->exporterMasterSecret, output, (unsigned long)hashAlgSz);
  24729. if (ret != 0) break;
  24730. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24731. secret, (word32)hashAlgSz,
  24732. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24733. (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel),
  24734. tv->hashFinished2, (word32)hashAlgSz, (int)tv->hashAlg);
  24735. if (ret != 0) break;
  24736. ret = XMEMCMP(tv->resumptionMasterSecret, output,
  24737. (unsigned long)hashAlgSz);
  24738. if (ret != 0) break;
  24739. }
  24740. return ret;
  24741. }
  24742. #endif /* WOLFSSL_TLS13 */
  24743. static const int fiducial2 = WC_TEST_RET_LN; /* source code reference point --
  24744. * see print_fiducials() below.
  24745. */
  24746. #if defined(HAVE_ECC) && defined(HAVE_X963_KDF)
  24747. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void)
  24748. {
  24749. wc_test_ret_t ret;
  24750. byte kek[128];
  24751. #ifndef NO_SHA
  24752. /* SHA-1, COUNT = 0
  24753. * shared secret length: 192
  24754. * SharedInfo length: 0
  24755. * key data length: 128
  24756. */
  24757. WOLFSSL_SMALL_STACK_STATIC const byte Z[] = {
  24758. 0x1c, 0x7d, 0x7b, 0x5f, 0x05, 0x97, 0xb0, 0x3d,
  24759. 0x06, 0xa0, 0x18, 0x46, 0x6e, 0xd1, 0xa9, 0x3e,
  24760. 0x30, 0xed, 0x4b, 0x04, 0xdc, 0x64, 0xcc, 0xdd
  24761. };
  24762. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  24763. 0xbf, 0x71, 0xdf, 0xfd, 0x8f, 0x4d, 0x99, 0x22,
  24764. 0x39, 0x36, 0xbe, 0xb4, 0x6f, 0xee, 0x8c, 0xcc
  24765. };
  24766. #endif
  24767. #ifndef NO_SHA256
  24768. /* SHA-256, COUNT = 3
  24769. * shared secret length: 192
  24770. * SharedInfo length: 0
  24771. * key data length: 128
  24772. */
  24773. WOLFSSL_SMALL_STACK_STATIC const byte Z2[] = {
  24774. 0xd3, 0x8b, 0xdb, 0xe5, 0xc4, 0xfc, 0x16, 0x4c,
  24775. 0xdd, 0x96, 0x7f, 0x63, 0xc0, 0x4f, 0xe0, 0x7b,
  24776. 0x60, 0xcd, 0xe8, 0x81, 0xc2, 0x46, 0x43, 0x8c
  24777. };
  24778. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  24779. 0x5e, 0x67, 0x4d, 0xb9, 0x71, 0xba, 0xc2, 0x0a,
  24780. 0x80, 0xba, 0xd0, 0xd4, 0x51, 0x4d, 0xc4, 0x84
  24781. };
  24782. #endif
  24783. #ifdef WOLFSSL_SHA512
  24784. /* SHA-512, COUNT = 0
  24785. * shared secret length: 192
  24786. * SharedInfo length: 0
  24787. * key data length: 128
  24788. */
  24789. WOLFSSL_SMALL_STACK_STATIC const byte Z3[] = {
  24790. 0x87, 0xfc, 0x0d, 0x8c, 0x44, 0x77, 0x48, 0x5b,
  24791. 0xb5, 0x74, 0xf5, 0xfc, 0xea, 0x26, 0x4b, 0x30,
  24792. 0x88, 0x5d, 0xc8, 0xd9, 0x0a, 0xd8, 0x27, 0x82
  24793. };
  24794. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  24795. 0x94, 0x76, 0x65, 0xfb, 0xb9, 0x15, 0x21, 0x53,
  24796. 0xef, 0x46, 0x02, 0x38, 0x50, 0x6a, 0x02, 0x45
  24797. };
  24798. /* SHA-512, COUNT = 0
  24799. * shared secret length: 521
  24800. * SharedInfo length: 128
  24801. * key data length: 1024
  24802. */
  24803. WOLFSSL_SMALL_STACK_STATIC const byte Z4[] = {
  24804. 0x00, 0xaa, 0x5b, 0xb7, 0x9b, 0x33, 0xe3, 0x89,
  24805. 0xfa, 0x58, 0xce, 0xad, 0xc0, 0x47, 0x19, 0x7f,
  24806. 0x14, 0xe7, 0x37, 0x12, 0xf4, 0x52, 0xca, 0xa9,
  24807. 0xfc, 0x4c, 0x9a, 0xdb, 0x36, 0x93, 0x48, 0xb8,
  24808. 0x15, 0x07, 0x39, 0x2f, 0x1a, 0x86, 0xdd, 0xfd,
  24809. 0xb7, 0xc4, 0xff, 0x82, 0x31, 0xc4, 0xbd, 0x0f,
  24810. 0x44, 0xe4, 0x4a, 0x1b, 0x55, 0xb1, 0x40, 0x47,
  24811. 0x47, 0xa9, 0xe2, 0xe7, 0x53, 0xf5, 0x5e, 0xf0,
  24812. 0x5a, 0x2d
  24813. };
  24814. WOLFSSL_SMALL_STACK_STATIC const byte info4[] = {
  24815. 0xe3, 0xb5, 0xb4, 0xc1, 0xb0, 0xd5, 0xcf, 0x1d,
  24816. 0x2b, 0x3a, 0x2f, 0x99, 0x37, 0x89, 0x5d, 0x31
  24817. };
  24818. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  24819. 0x44, 0x63, 0xf8, 0x69, 0xf3, 0xcc, 0x18, 0x76,
  24820. 0x9b, 0x52, 0x26, 0x4b, 0x01, 0x12, 0xb5, 0x85,
  24821. 0x8f, 0x7a, 0xd3, 0x2a, 0x5a, 0x2d, 0x96, 0xd8,
  24822. 0xcf, 0xfa, 0xbf, 0x7f, 0xa7, 0x33, 0x63, 0x3d,
  24823. 0x6e, 0x4d, 0xd2, 0xa5, 0x99, 0xac, 0xce, 0xb3,
  24824. 0xea, 0x54, 0xa6, 0x21, 0x7c, 0xe0, 0xb5, 0x0e,
  24825. 0xef, 0x4f, 0x6b, 0x40, 0xa5, 0xc3, 0x02, 0x50,
  24826. 0xa5, 0xa8, 0xee, 0xee, 0x20, 0x80, 0x02, 0x26,
  24827. 0x70, 0x89, 0xdb, 0xf3, 0x51, 0xf3, 0xf5, 0x02,
  24828. 0x2a, 0xa9, 0x63, 0x8b, 0xf1, 0xee, 0x41, 0x9d,
  24829. 0xea, 0x9c, 0x4f, 0xf7, 0x45, 0xa2, 0x5a, 0xc2,
  24830. 0x7b, 0xda, 0x33, 0xca, 0x08, 0xbd, 0x56, 0xdd,
  24831. 0x1a, 0x59, 0xb4, 0x10, 0x6c, 0xf2, 0xdb, 0xbc,
  24832. 0x0a, 0xb2, 0xaa, 0x8e, 0x2e, 0xfa, 0x7b, 0x17,
  24833. 0x90, 0x2d, 0x34, 0x27, 0x69, 0x51, 0xce, 0xcc,
  24834. 0xab, 0x87, 0xf9, 0x66, 0x1c, 0x3e, 0x88, 0x16
  24835. };
  24836. #endif
  24837. WOLFSSL_ENTER("x963kdf_test");
  24838. #ifndef NO_SHA
  24839. ret = wc_X963_KDF(WC_HASH_TYPE_SHA, Z, sizeof(Z), NULL, 0,
  24840. kek, sizeof(verify));
  24841. if (ret != 0)
  24842. return WC_TEST_RET_ENC_EC(ret);
  24843. if (XMEMCMP(verify, kek, sizeof(verify)) != 0)
  24844. return WC_TEST_RET_ENC_NC;
  24845. #endif
  24846. #ifndef NO_SHA256
  24847. ret = wc_X963_KDF(WC_HASH_TYPE_SHA256, Z2, sizeof(Z2), NULL, 0,
  24848. kek, sizeof(verify2));
  24849. if (ret != 0)
  24850. return WC_TEST_RET_ENC_EC(ret);
  24851. if (XMEMCMP(verify2, kek, sizeof(verify2)) != 0)
  24852. return WC_TEST_RET_ENC_NC;
  24853. #endif
  24854. #ifdef WOLFSSL_SHA512
  24855. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z3, sizeof(Z3), NULL, 0,
  24856. kek, sizeof(verify3));
  24857. if (ret != 0)
  24858. return WC_TEST_RET_ENC_EC(ret);
  24859. if (XMEMCMP(verify3, kek, sizeof(verify3)) != 0)
  24860. return WC_TEST_RET_ENC_NC;
  24861. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z4, sizeof(Z4), info4,
  24862. sizeof(info4), kek, sizeof(verify4));
  24863. if (ret != 0)
  24864. return WC_TEST_RET_ENC_EC(ret);
  24865. if (XMEMCMP(verify4, kek, sizeof(verify4)) != 0)
  24866. return WC_TEST_RET_ENC_NC;
  24867. #endif
  24868. return 0;
  24869. }
  24870. #endif /* HAVE_X963_KDF */
  24871. #if defined(HAVE_HPKE) && \
  24872. (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) && \
  24873. defined(HAVE_AESGCM)
  24874. static wc_test_ret_t hpke_test_single(Hpke* hpke)
  24875. {
  24876. wc_test_ret_t ret = 0;
  24877. int rngRet = 0;
  24878. WC_RNG rng[1];
  24879. const char* start_text = "this is a test";
  24880. const char* info_text = "info";
  24881. const char* aad_text = "aad";
  24882. byte ciphertext[MAX_HPKE_LABEL_SZ];
  24883. byte plaintext[MAX_HPKE_LABEL_SZ];
  24884. void* receiverKey = NULL;
  24885. void* ephemeralKey = NULL;
  24886. #ifdef WOLFSSL_SMALL_STACK
  24887. byte *pubKey = NULL; /* public key */
  24888. word16 pubKeySz = (word16)HPKE_Npk_MAX;
  24889. #else
  24890. byte pubKey[HPKE_Npk_MAX]; /* public key */
  24891. word16 pubKeySz = (word16)sizeof(pubKey);
  24892. #endif
  24893. rngRet = ret = wc_InitRng(rng);
  24894. if (ret != 0)
  24895. return WC_TEST_RET_ENC_EC(ret);
  24896. #ifdef WOLFSSL_SMALL_STACK
  24897. if (ret == 0) {
  24898. pubKey = (byte *)XMALLOC(pubKeySz, HEAP_HINT,
  24899. DYNAMIC_TYPE_TMP_BUFFER);
  24900. if (pubKey == NULL)
  24901. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  24902. }
  24903. #endif
  24904. /* generate the keys */
  24905. if (ret == 0) {
  24906. ret = wc_HpkeGenerateKeyPair(hpke, &ephemeralKey, rng);
  24907. if (ret != 0)
  24908. ret = WC_TEST_RET_ENC_EC(ret);
  24909. }
  24910. if (ret == 0) {
  24911. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, rng);
  24912. if (ret != 0)
  24913. ret = WC_TEST_RET_ENC_EC(ret);
  24914. }
  24915. /* seal */
  24916. if (ret == 0) {
  24917. ret = wc_HpkeSealBase(hpke, ephemeralKey, receiverKey,
  24918. (byte*)info_text, (word32)XSTRLEN(info_text),
  24919. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  24920. (byte*)start_text, (word32)XSTRLEN(start_text),
  24921. ciphertext);
  24922. if (ret != 0)
  24923. ret = WC_TEST_RET_ENC_EC(ret);
  24924. }
  24925. /* export ephemeral key */
  24926. if (ret == 0) {
  24927. ret = wc_HpkeSerializePublicKey(hpke, ephemeralKey, pubKey, &pubKeySz);
  24928. if (ret != 0)
  24929. ret = WC_TEST_RET_ENC_EC(ret);
  24930. }
  24931. /* open with exported ephemeral key */
  24932. if (ret == 0) {
  24933. ret = wc_HpkeOpenBase(hpke, receiverKey, pubKey, pubKeySz,
  24934. (byte*)info_text, (word32)XSTRLEN(info_text),
  24935. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  24936. ciphertext, (word32)XSTRLEN(start_text),
  24937. plaintext);
  24938. if (ret != 0)
  24939. ret = WC_TEST_RET_ENC_EC(ret);
  24940. }
  24941. if (ret == 0) {
  24942. ret = XMEMCMP(plaintext, start_text, XSTRLEN(start_text));
  24943. if (ret != 0)
  24944. ret = WC_TEST_RET_ENC_NC;
  24945. }
  24946. /* Negative test case with NULL argument */
  24947. if (ret == 0) {
  24948. ret = wc_HpkeGenerateKeyPair(NULL, &receiverKey, rng);
  24949. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  24950. ret = WC_TEST_RET_ENC_EC(ret);
  24951. else
  24952. ret = 0;
  24953. }
  24954. if (ret == 0) {
  24955. ret = wc_HpkeGenerateKeyPair(hpke, NULL, rng);
  24956. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  24957. ret = WC_TEST_RET_ENC_EC(ret);
  24958. else
  24959. ret = 0;
  24960. }
  24961. if (ret == 0) {
  24962. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, NULL);
  24963. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  24964. ret = WC_TEST_RET_ENC_EC(ret);
  24965. else
  24966. ret = 0;
  24967. }
  24968. if (ephemeralKey != NULL)
  24969. wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap);
  24970. if (receiverKey != NULL)
  24971. wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap);
  24972. #ifdef WOLFSSL_SMALL_STACK
  24973. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  24974. #endif
  24975. if (rngRet == 0)
  24976. wc_FreeRng(rng);
  24977. return ret;
  24978. }
  24979. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void)
  24980. {
  24981. wc_test_ret_t ret = 0;
  24982. Hpke hpke[1];
  24983. WOLFSSL_ENTER("hpke_test");
  24984. #if defined(HAVE_ECC)
  24985. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
  24986. /* p256 */
  24987. ret = wc_HpkeInit(hpke, DHKEM_P256_HKDF_SHA256, HKDF_SHA256,
  24988. HPKE_AES_128_GCM, NULL);
  24989. if (ret != 0)
  24990. return WC_TEST_RET_ENC_EC(ret);
  24991. ret = hpke_test_single(hpke);
  24992. if (ret != 0)
  24993. return ret;
  24994. #endif
  24995. #if defined(WOLFSSL_SHA384) && \
  24996. (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  24997. /* p384 */
  24998. ret = wc_HpkeInit(hpke, DHKEM_P384_HKDF_SHA384, HKDF_SHA384,
  24999. HPKE_AES_128_GCM, NULL);
  25000. if (ret != 0)
  25001. return WC_TEST_RET_ENC_EC(ret);
  25002. ret = hpke_test_single(hpke);
  25003. if (ret != 0)
  25004. return ret;
  25005. #endif
  25006. #if (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) && \
  25007. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25008. /* p521 */
  25009. ret = wc_HpkeInit(hpke, DHKEM_P521_HKDF_SHA512, HKDF_SHA512,
  25010. HPKE_AES_128_GCM, NULL);
  25011. if (ret != 0)
  25012. return WC_TEST_RET_ENC_EC(ret);
  25013. ret = hpke_test_single(hpke);
  25014. if (ret != 0)
  25015. return ret;
  25016. #endif
  25017. #endif
  25018. #if defined(HAVE_CURVE25519)
  25019. /* test with curve25519 and aes256 */
  25020. ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256,
  25021. HPKE_AES_256_GCM, NULL);
  25022. if (ret != 0)
  25023. return WC_TEST_RET_ENC_EC(ret);
  25024. ret = hpke_test_single(hpke);
  25025. if (ret != 0)
  25026. return ret;
  25027. #endif
  25028. #if defined(HAVE_CURVE448) && \
  25029. (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512))
  25030. /* test with curve448 and aes256 */
  25031. ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512,
  25032. HPKE_AES_256_GCM, NULL);
  25033. /* HPKE does not support X448 yet, so expect failure */
  25034. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25035. return WC_TEST_RET_ENC_EC(ret);
  25036. ret = hpke_test_single(hpke);
  25037. /* HPKE does not support X448 yet, so expect failure */
  25038. if (WC_TEST_RET_DEC_EC(ret) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25039. return ret;
  25040. ret = 0; /* reset error code */
  25041. #endif
  25042. /* TODO: HPKE chacha20 is not implemented */
  25043. return ret;
  25044. }
  25045. #endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */
  25046. #if defined(WC_SRTP_KDF)
  25047. typedef struct Srtp_Kdf_Tv {
  25048. const unsigned char* key;
  25049. word32 keySz;
  25050. const unsigned char* salt;
  25051. word32 saltSz;
  25052. int kdfIdx;
  25053. const unsigned char* index;
  25054. const unsigned char* ke;
  25055. const unsigned char* ka;
  25056. const unsigned char* ks;
  25057. const unsigned char* index_c;
  25058. const unsigned char* ke_c;
  25059. const unsigned char* ka_c;
  25060. const unsigned char* ks_c;
  25061. word32 keSz;
  25062. word32 kaSz;
  25063. word32 ksSz;
  25064. } Srtp_Kdf_Tv;
  25065. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
  25066. {
  25067. wc_test_ret_t ret = 0;
  25068. /* 128-bit key, kdrIdx = -1 */
  25069. WOLFSSL_SMALL_STACK_STATIC const byte key_0[] = {
  25070. 0xc4, 0x80, 0x9f, 0x6d, 0x36, 0x98, 0x88, 0x72,
  25071. 0x8e, 0x26, 0xad, 0xb5, 0x32, 0x12, 0x98, 0x90
  25072. };
  25073. WOLFSSL_SMALL_STACK_STATIC const byte salt_0[] = {
  25074. 0x0e, 0x23, 0x00, 0x6c, 0x6c, 0x04, 0x4f, 0x56,
  25075. 0x62, 0x40, 0x0e, 0x9d, 0x1b, 0xd6
  25076. };
  25077. WOLFSSL_SMALL_STACK_STATIC const byte index_0[] = {
  25078. 0x48, 0x71, 0x65, 0x64, 0x9c, 0xca
  25079. };
  25080. WOLFSSL_SMALL_STACK_STATIC const byte ke_0[] = {
  25081. 0xdc, 0x38, 0x21, 0x92, 0xab, 0x65, 0x10, 0x8a,
  25082. 0x86, 0xb2, 0x59, 0xb6, 0x1b, 0x3a, 0xf4, 0x6f
  25083. };
  25084. WOLFSSL_SMALL_STACK_STATIC const byte ka_0[] = {
  25085. 0xb8, 0x39, 0x37, 0xfb, 0x32, 0x17, 0x92, 0xee,
  25086. 0x87, 0xb7, 0x88, 0x19, 0x3b, 0xe5, 0xa4, 0xe3,
  25087. 0xbd, 0x32, 0x6e, 0xe4
  25088. };
  25089. WOLFSSL_SMALL_STACK_STATIC const byte ks_0[] = {
  25090. 0xf1, 0xc0, 0x35, 0xc0, 0x0b, 0x5a, 0x54, 0xa6,
  25091. 0x16, 0x92, 0xc0, 0x16, 0x27, 0x6c
  25092. };
  25093. WOLFSSL_SMALL_STACK_STATIC const byte index_c_0[] = {
  25094. 0x56, 0xf3, 0xf1, 0x97
  25095. };
  25096. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_0[] = {
  25097. 0xab, 0x5b, 0xe0, 0xb4, 0x56, 0x23, 0x5d, 0xcf,
  25098. 0x77, 0xd5, 0x08, 0x69, 0x29, 0xba, 0xfb, 0x38
  25099. };
  25100. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_0[] = {
  25101. 0xc5, 0x2f, 0xde, 0x0b, 0x80, 0xb0, 0xf0, 0xba,
  25102. 0xd8, 0xd1, 0x56, 0x45, 0xcb, 0x86, 0xe7, 0xc7,
  25103. 0xc3, 0xd8, 0x77, 0x0e
  25104. };
  25105. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_0[] = {
  25106. 0xde, 0xb5, 0xf8, 0x5f, 0x81, 0x33, 0x6a, 0x96,
  25107. 0x5e, 0xd3, 0x2b, 0xb7, 0xed, 0xe8
  25108. };
  25109. /* 192-bit key, kdrIdx = 0 */
  25110. WOLFSSL_SMALL_STACK_STATIC const byte key_1[] = {
  25111. 0xbb, 0x04, 0x5b, 0x1f, 0x53, 0xc6, 0x93, 0x2c,
  25112. 0x2b, 0xa6, 0x88, 0xf5, 0xe3, 0xf2, 0x24, 0x70,
  25113. 0xe1, 0x7d, 0x7d, 0xec, 0x8a, 0x93, 0x4d, 0xf2
  25114. };
  25115. WOLFSSL_SMALL_STACK_STATIC const byte salt_1[] = {
  25116. 0xe7, 0x22, 0xab, 0x92, 0xfc, 0x7c, 0x89, 0xb6,
  25117. 0x53, 0x8a, 0xf9, 0x3c, 0xb9, 0x52
  25118. };
  25119. WOLFSSL_SMALL_STACK_STATIC const byte index_1[] = {
  25120. 0xd7, 0x87, 0x8f, 0x33, 0xb1, 0x76
  25121. };
  25122. WOLFSSL_SMALL_STACK_STATIC const byte ke_1[] = {
  25123. 0x2c, 0xc8, 0x3e, 0x54, 0xb2, 0x33, 0x89, 0xb3,
  25124. 0x71, 0x65, 0x0f, 0x51, 0x61, 0x65, 0xe4, 0x93,
  25125. 0x07, 0x4e, 0xb3, 0x47, 0xba, 0x2d, 0x60, 0x60
  25126. };
  25127. WOLFSSL_SMALL_STACK_STATIC const byte ka_1[] = {
  25128. 0x2e, 0x80, 0xe4, 0x82, 0x55, 0xa2, 0xbe, 0x6d,
  25129. 0xe0, 0x46, 0xcc, 0xc1, 0x75, 0x78, 0x6e, 0x78,
  25130. 0xd1, 0xd1, 0x47, 0x08
  25131. };
  25132. WOLFSSL_SMALL_STACK_STATIC const byte ks_1[] = {
  25133. 0xe0, 0xc1, 0xe6, 0xaf, 0x1e, 0x8d, 0x8c, 0xfe,
  25134. 0xe5, 0x60, 0x70, 0xb5, 0xe6, 0xea
  25135. };
  25136. WOLFSSL_SMALL_STACK_STATIC const byte index_c_1[] = {
  25137. 0x40, 0xbf, 0xd4, 0xa9
  25138. };
  25139. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_1[] = {
  25140. 0x94, 0x0f, 0x55, 0xce, 0x58, 0xd8, 0x16, 0x65,
  25141. 0xf0, 0xfa, 0x46, 0x40, 0x0c, 0xda, 0xb1, 0x11,
  25142. 0x9e, 0x69, 0xa0, 0x93, 0x4e, 0xd7, 0xf2, 0x84
  25143. };
  25144. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_1[] = {
  25145. 0xf5, 0x41, 0x6f, 0xc2, 0x65, 0xc5, 0xb3, 0xef,
  25146. 0xbb, 0x22, 0xc8, 0xfc, 0x6b, 0x00, 0x14, 0xb2,
  25147. 0xf3, 0x3b, 0x8e, 0x29
  25148. };
  25149. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_1[] = {
  25150. 0x35, 0xb7, 0x42, 0x43, 0xf0, 0x01, 0x01, 0xb4,
  25151. 0x68, 0xa1, 0x28, 0x80, 0x37, 0xf0
  25152. };
  25153. /* 256-bit key, kdrIdx = 1 */
  25154. WOLFSSL_SMALL_STACK_STATIC const byte key_2[] = {
  25155. 0x10, 0x38, 0x0a, 0xcd, 0xd6, 0x47, 0xab, 0xee,
  25156. 0xc0, 0xd4, 0x44, 0xf4, 0x7e, 0x51, 0x36, 0x02,
  25157. 0x79, 0xa8, 0x94, 0x80, 0x35, 0x40, 0xed, 0x50,
  25158. 0xf4, 0x45, 0x30, 0x3d, 0xb5, 0xf0, 0x2b, 0xbb
  25159. };
  25160. WOLFSSL_SMALL_STACK_STATIC const byte salt_2[] = {
  25161. 0xc7, 0x31, 0xf2, 0xc8, 0x40, 0x43, 0xb8, 0x74,
  25162. 0x8a, 0x61, 0x84, 0x7a, 0x25, 0x8a
  25163. };
  25164. WOLFSSL_SMALL_STACK_STATIC const byte index_2[] = {
  25165. 0x82, 0xf1, 0x84, 0x8c, 0xac, 0x42
  25166. };
  25167. WOLFSSL_SMALL_STACK_STATIC const byte ke_2[] = {
  25168. 0xb2, 0x26, 0x60, 0xaf, 0x08, 0x23, 0x14, 0x98,
  25169. 0x91, 0xde, 0x5d, 0x87, 0x95, 0x61, 0xca, 0x8f,
  25170. 0x0e, 0xce, 0xfb, 0x68, 0x4d, 0xd6, 0x28, 0xcb,
  25171. 0x28, 0xe2, 0x27, 0x20, 0x2d, 0xff, 0x64, 0xbb
  25172. };
  25173. WOLFSSL_SMALL_STACK_STATIC const byte ka_2[] = {
  25174. 0x12, 0x6f, 0x52, 0xe8, 0x07, 0x7f, 0x07, 0x84,
  25175. 0xa0, 0x61, 0x96, 0xf8, 0xee, 0x4d, 0x05, 0x57,
  25176. 0x65, 0xc7, 0x50, 0xc1
  25177. };
  25178. WOLFSSL_SMALL_STACK_STATIC const byte ks_2[] = {
  25179. 0x18, 0x5a, 0x59, 0xe5, 0x91, 0x4d, 0xc9, 0x6c,
  25180. 0xfa, 0x5b, 0x36, 0x06, 0x8c, 0x9a
  25181. };
  25182. WOLFSSL_SMALL_STACK_STATIC const byte index_c_2[] = {
  25183. 0x31, 0x2d, 0x58, 0x15
  25184. };
  25185. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_2[] = {
  25186. 0x14, 0xf2, 0xc8, 0x25, 0x02, 0x79, 0x22, 0xa1,
  25187. 0x96, 0xb6, 0xf7, 0x07, 0x76, 0xa6, 0xa3, 0xc4,
  25188. 0x37, 0xdf, 0xa0, 0xf8, 0x78, 0x93, 0x2c, 0xfa,
  25189. 0xea, 0x35, 0xf0, 0xf3, 0x3f, 0x32, 0x6e, 0xfd
  25190. };
  25191. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_2[] = {
  25192. 0x6e, 0x3d, 0x4a, 0x99, 0xea, 0x2f, 0x9d, 0x13,
  25193. 0x4a, 0x1e, 0x71, 0x2e, 0x15, 0xc0, 0xca, 0xb6,
  25194. 0x35, 0x78, 0xdf, 0xa4
  25195. };
  25196. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_2[] = {
  25197. 0xae, 0xe4, 0xec, 0x18, 0x31, 0x70, 0x5d, 0x3f,
  25198. 0xdc, 0x97, 0x89, 0x88, 0xfd, 0xff
  25199. };
  25200. /* 128-bit key, kdrIdx = 8 */
  25201. WOLFSSL_SMALL_STACK_STATIC const byte key_3[] = {
  25202. 0x36, 0xb4, 0xde, 0xcb, 0x2e, 0x51, 0x23, 0x76,
  25203. 0xe0, 0x27, 0x7e, 0x3e, 0xc8, 0xf6, 0x54, 0x04
  25204. };
  25205. WOLFSSL_SMALL_STACK_STATIC const byte salt_3[] = {
  25206. 0x73, 0x26, 0xf4, 0x3f, 0xc0, 0xd9, 0xc6, 0xe3,
  25207. 0x2f, 0x92, 0x7d, 0x46, 0x12, 0x76
  25208. };
  25209. WOLFSSL_SMALL_STACK_STATIC const byte index_3[] = {
  25210. 0x44, 0x73, 0xb2, 0x2d, 0xb2, 0x60
  25211. };
  25212. WOLFSSL_SMALL_STACK_STATIC const byte ke_3[] = {
  25213. 0x79, 0x91, 0x3d, 0x7b, 0x20, 0x5d, 0xea, 0xe2,
  25214. 0xeb, 0x46, 0x89, 0x68, 0x5a, 0x06, 0x73, 0x74
  25215. };
  25216. WOLFSSL_SMALL_STACK_STATIC const byte ka_3[] = {
  25217. 0x2d, 0x2e, 0x97, 0x4e, 0x76, 0x8c, 0x62, 0xa6,
  25218. 0x57, 0x80, 0x13, 0x42, 0x0b, 0x51, 0xa7, 0x66,
  25219. 0xea, 0x31, 0x24, 0xe6
  25220. };
  25221. WOLFSSL_SMALL_STACK_STATIC const byte ks_3[] = {
  25222. 0xcc, 0xd7, 0x31, 0xf6, 0x3b, 0xf3, 0x89, 0x8a,
  25223. 0x5b, 0x7b, 0xb5, 0x8b, 0x4c, 0x3f
  25224. };
  25225. WOLFSSL_SMALL_STACK_STATIC const byte index_c_3[] = {
  25226. 0x4a, 0x7d, 0xaa, 0x85
  25227. };
  25228. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_3[] = {
  25229. 0x34, 0x99, 0x71, 0xfe, 0x12, 0x93, 0xae, 0x8c,
  25230. 0x4a, 0xe9, 0x84, 0xe4, 0x93, 0x53, 0x63, 0x88
  25231. };
  25232. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_3[] = {
  25233. 0xa4, 0x53, 0x5e, 0x0a, 0x9c, 0xf2, 0xce, 0x13,
  25234. 0xef, 0x7a, 0x13, 0xee, 0x0a, 0xef, 0xba, 0x17,
  25235. 0x05, 0x18, 0xe3, 0xed
  25236. };
  25237. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_3[] = {
  25238. 0xe1, 0x29, 0x4f, 0x61, 0x30, 0x3c, 0x4d, 0x46,
  25239. 0x5f, 0x5c, 0x81, 0x3c, 0x38, 0xb6
  25240. };
  25241. /* SRTCP w/ 48-bit idx - KDR 0 (-1) */
  25242. WOLFSSL_SMALL_STACK_STATIC const byte mk48_1[] = {
  25243. 0xFF, 0xB6, 0xCB, 0x09, 0x71, 0x3F, 0x63, 0x4D,
  25244. 0x7F, 0x42, 0xED, 0xA8, 0x12, 0x81, 0x50, 0xE6
  25245. };
  25246. WOLFSSL_SMALL_STACK_STATIC const byte ms48_1[] = {
  25247. 0x1F, 0x04, 0x76, 0xC8, 0x7F, 0x58, 0x23, 0xEF,
  25248. 0xD3, 0x57, 0xB2, 0xBD, 0xF1, 0x32
  25249. };
  25250. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_1[] = {
  25251. 0x00, 0x00, 0x08, 0x56, 0xBC, 0x39
  25252. };
  25253. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_1[] = {
  25254. 0xD2, 0xC3, 0xF3, 0x49, 0x00, 0x1A, 0x18, 0x0F,
  25255. 0xB6, 0x05, 0x5A, 0x5A, 0x67, 0x8E, 0xE5, 0xB2
  25256. };
  25257. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_1[] = {
  25258. 0x8D, 0x54, 0xBE, 0xB5, 0x7B, 0x7F, 0x7A, 0xAB,
  25259. 0xF5, 0x46, 0xCE, 0x5B, 0x45, 0x69, 0x4A, 0x75,
  25260. 0x81, 0x2A, 0xE2, 0xCB
  25261. };
  25262. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_1[] = {
  25263. 0x76, 0x3C, 0x97, 0x6A, 0x45, 0x31, 0xA7, 0x79,
  25264. 0x3C, 0x28, 0x4A, 0xA6, 0x82, 0x03
  25265. };
  25266. /* SRTCP w/ 48-bit idx - KDR 19 */
  25267. WOLFSSL_SMALL_STACK_STATIC const byte mk48_2[] = {
  25268. 0xBD, 0x1D, 0x71, 0x6B, 0xDA, 0x28, 0xE3, 0xFC,
  25269. 0xA5, 0xA0, 0x66, 0x3F, 0x2E, 0x34, 0xA8, 0x58
  25270. };
  25271. WOLFSSL_SMALL_STACK_STATIC const byte ms48_2[] = {
  25272. 0x79, 0x06, 0xE5, 0xAB, 0x5C, 0x2B, 0x1B, 0x69,
  25273. 0xFA, 0xEE, 0xD2, 0x29, 0x57, 0x3C
  25274. };
  25275. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_2[] = {
  25276. 0x00, 0x00, 0x59, 0xD0, 0xC2, 0xE8
  25277. };
  25278. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_2[] = {
  25279. 0xB9, 0xD7, 0xAD, 0xD8, 0x90, 0x94, 0xC2, 0x92,
  25280. 0xA5, 0x04, 0x87, 0xC4, 0x8C, 0xEF, 0xE2, 0xA3
  25281. };
  25282. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_2[] = {
  25283. 0x07, 0xD5, 0xC4, 0xD2, 0x06, 0xFB, 0x63, 0x15,
  25284. 0xC2, 0x9C, 0x7F, 0x55, 0xD1, 0x16, 0x5C, 0xB5,
  25285. 0xB7, 0x44, 0x54, 0xBD
  25286. };
  25287. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_2[] = {
  25288. 0x0C, 0x5E, 0x53, 0xC1, 0xD0, 0x75, 0xAD, 0x65,
  25289. 0xBF, 0x51, 0x74, 0x50, 0x89, 0xD7
  25290. };
  25291. int kdr_48_1 = -1;
  25292. int kdr_48_2 = 19;
  25293. #define SRTP_TV_CNT 4
  25294. Srtp_Kdf_Tv tv[SRTP_TV_CNT] = {
  25295. { key_0, (word32)sizeof(key_0), salt_0, (word32)sizeof(salt_0), -1,
  25296. index_0, ke_0, ka_0, ks_0, index_c_0, ke_c_0, ka_c_0, ks_c_0,
  25297. 16, 20, 14 },
  25298. { key_1, (word32)sizeof(key_1), salt_1, (word32)sizeof(salt_1), 0,
  25299. index_1, ke_1, ka_1, ks_1, index_c_1, ke_c_1, ka_c_1, ks_c_1,
  25300. 24, 20, 14 },
  25301. { key_2, (word32)sizeof(key_2), salt_2, (word32)sizeof(salt_2), 1,
  25302. index_2, ke_2, ka_2, ks_2, index_c_2, ke_c_2, ka_c_2, ks_c_2,
  25303. 32, 20, 14 },
  25304. { key_3, (word32)sizeof(key_3), salt_3, (word32)sizeof(salt_3), 8,
  25305. index_3, ke_3, ka_3, ks_3, index_c_3, ke_c_3, ka_c_3, ks_c_3,
  25306. 16, 20, 14 },
  25307. };
  25308. int i;
  25309. int idx;
  25310. unsigned char keyE[32];
  25311. unsigned char keyA[20];
  25312. unsigned char keyS[14];
  25313. WOLFSSL_ENTER("srtpkdf_test");
  25314. for (i = 0; (ret == 0) && (i < SRTP_TV_CNT); i++) {
  25315. #ifndef WOLFSSL_AES_128
  25316. if (tv[i].keySz == AES_128_KEY_SIZE) {
  25317. continue;
  25318. }
  25319. #endif
  25320. #ifndef WOLFSSL_AES_192
  25321. if (tv[i].keySz == AES_192_KEY_SIZE) {
  25322. continue;
  25323. }
  25324. #endif
  25325. #ifndef WOLFSSL_AES_256
  25326. if (tv[i].keySz == AES_256_KEY_SIZE) {
  25327. continue;
  25328. }
  25329. #endif
  25330. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25331. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25332. keyS, tv[i].ksSz);
  25333. if (ret != 0)
  25334. return WC_TEST_RET_ENC_EC(ret);
  25335. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25336. return WC_TEST_RET_ENC_NC;
  25337. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25338. return WC_TEST_RET_ENC_NC;
  25339. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25340. return WC_TEST_RET_ENC_NC;
  25341. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25342. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_ENCRYPTION,
  25343. keyE, tv[i].keSz);
  25344. if (ret != 0)
  25345. return WC_TEST_RET_ENC_EC(ret);
  25346. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25347. return WC_TEST_RET_ENC_NC;
  25348. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25349. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_MSG_AUTH,
  25350. keyA, tv[i].kaSz);
  25351. if (ret != 0)
  25352. return WC_TEST_RET_ENC_EC(ret);
  25353. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25354. return WC_TEST_RET_ENC_NC;
  25355. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25356. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_SALT, keyS,
  25357. tv[i].ksSz);
  25358. if (ret != 0)
  25359. return WC_TEST_RET_ENC_EC(ret);
  25360. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25361. return WC_TEST_RET_ENC_NC;
  25362. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25363. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25364. keyS, tv[i].ksSz);
  25365. if (ret != 0)
  25366. return WC_TEST_RET_ENC_EC(ret);
  25367. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25368. return WC_TEST_RET_ENC_NC;
  25369. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25370. return WC_TEST_RET_ENC_NC;
  25371. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25372. return WC_TEST_RET_ENC_NC;
  25373. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25374. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c,
  25375. WC_SRTCP_LABEL_ENCRYPTION, keyE, tv[i].keSz);
  25376. if (ret != 0)
  25377. return WC_TEST_RET_ENC_EC(ret);
  25378. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25379. return WC_TEST_RET_ENC_NC;
  25380. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25381. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_MSG_AUTH,
  25382. keyA, tv[i].kaSz);
  25383. if (ret != 0)
  25384. return WC_TEST_RET_ENC_EC(ret);
  25385. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25386. return WC_TEST_RET_ENC_NC;
  25387. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25388. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT,
  25389. keyS, tv[i].ksSz);
  25390. if (ret != 0)
  25391. return WC_TEST_RET_ENC_EC(ret);
  25392. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25393. return WC_TEST_RET_ENC_NC;
  25394. }
  25395. #ifdef WOLFSSL_AES_128
  25396. i = 0;
  25397. #elif defined(WOLFSSL_AES_192)
  25398. i = 1;
  25399. #else
  25400. i = 2;
  25401. #endif
  25402. ret = wc_SRTP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25403. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25404. keyS, tv[i].ksSz);
  25405. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25406. return WC_TEST_RET_ENC_EC(ret);
  25407. ret = wc_SRTCP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25408. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25409. keyS, tv[i].ksSz);
  25410. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25411. return WC_TEST_RET_ENC_EC(ret);
  25412. ret = wc_SRTP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25413. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25414. keyS, tv[i].ksSz);
  25415. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25416. return WC_TEST_RET_ENC_EC(ret);
  25417. ret = wc_SRTCP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25418. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25419. keyS, tv[i].ksSz);
  25420. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25421. return WC_TEST_RET_ENC_EC(ret);
  25422. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25423. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25424. keyS, tv[i].ksSz);
  25425. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25426. return WC_TEST_RET_ENC_EC(ret);
  25427. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25428. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25429. keyS, tv[i].ksSz);
  25430. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25431. return WC_TEST_RET_ENC_EC(ret);
  25432. ret = wc_SRTP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25433. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25434. keyS, tv[i].ksSz);
  25435. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25436. return WC_TEST_RET_ENC_EC(ret);
  25437. ret = wc_SRTCP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25438. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25439. keyS, tv[i].ksSz);
  25440. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25441. return WC_TEST_RET_ENC_EC(ret);
  25442. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25443. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25444. keyS, tv[i].ksSz);
  25445. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25446. return WC_TEST_RET_ENC_EC(ret);
  25447. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25448. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25449. keyS, tv[i].ksSz);
  25450. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25451. return WC_TEST_RET_ENC_EC(ret);
  25452. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25453. 25, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25454. keyS, tv[i].ksSz);
  25455. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25456. return WC_TEST_RET_ENC_EC(ret);
  25457. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25458. 25, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25459. keyS, tv[i].ksSz);
  25460. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25461. return WC_TEST_RET_ENC_EC(ret);
  25462. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25463. -2, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25464. keyS, tv[i].ksSz);
  25465. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25466. return WC_TEST_RET_ENC_EC(ret);
  25467. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25468. -2, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25469. keyS, tv[i].ksSz);
  25470. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25471. return WC_TEST_RET_ENC_EC(ret);
  25472. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25473. tv[i].kdfIdx, tv[i].index, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25474. keyS, tv[i].ksSz);
  25475. if (ret != 0)
  25476. return WC_TEST_RET_ENC_EC(ret);
  25477. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25478. tv[i].kdfIdx, tv[i].index_c, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25479. keyS, tv[i].ksSz);
  25480. if (ret != 0)
  25481. return WC_TEST_RET_ENC_EC(ret);
  25482. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25483. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25484. keyS, tv[i].ksSz);
  25485. if (ret != 0)
  25486. return WC_TEST_RET_ENC_EC(ret);
  25487. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25488. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25489. keyS, tv[i].ksSz);
  25490. if (ret != 0)
  25491. return WC_TEST_RET_ENC_EC(ret);
  25492. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25493. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25494. NULL, tv[i].ksSz);
  25495. if (ret != 0)
  25496. return WC_TEST_RET_ENC_EC(ret);
  25497. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25498. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25499. NULL, tv[i].ksSz);
  25500. if (ret != 0)
  25501. return WC_TEST_RET_ENC_EC(ret);
  25502. idx = wc_SRTP_KDF_kdr_to_idx(0);
  25503. if (idx != -1)
  25504. return WC_TEST_RET_ENC_NC;
  25505. for (i = 0; i < 32; i++) {
  25506. word32 kdr = 1U << i;
  25507. /* SRTCP w/ 48-bit IDX, 128-bit key test */
  25508. if (i == 0) {
  25509. ret = wc_SRTCP_KDF_ex(mk48_1, (word32)sizeof(mk48_1),
  25510. ms48_1, (word32)sizeof(ms48_1),
  25511. kdr_48_1, srtcp48idx_1, keyE, tv[i].keSz,
  25512. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25513. WC_SRTCP_48BIT_IDX);
  25514. if (ret != 0)
  25515. return WC_TEST_RET_ENC_EC(ret);
  25516. if (XMEMCMP(keyE, srtcpKe_48_1, tv[i].keSz) != 0)
  25517. return WC_TEST_RET_ENC_NC;
  25518. if (XMEMCMP(keyA, srtcpKa_48_1, tv[i].kaSz) != 0)
  25519. return WC_TEST_RET_ENC_NC;
  25520. if (XMEMCMP(keyS, srtcpKs_48_1, tv[i].ksSz) != 0)
  25521. return WC_TEST_RET_ENC_NC;
  25522. ret = wc_SRTCP_KDF_ex(mk48_2, (word32)sizeof(mk48_2),
  25523. ms48_2, (word32)sizeof(ms48_2),
  25524. kdr_48_2, srtcp48idx_2, keyE, tv[i].keSz,
  25525. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25526. WC_SRTCP_48BIT_IDX);
  25527. if (ret != 0)
  25528. return WC_TEST_RET_ENC_EC(ret);
  25529. if (XMEMCMP(keyE, srtcpKe_48_2, tv[i].keSz) != 0)
  25530. return WC_TEST_RET_ENC_NC;
  25531. if (XMEMCMP(keyA, srtcpKa_48_2, tv[i].kaSz) != 0)
  25532. return WC_TEST_RET_ENC_NC;
  25533. if (XMEMCMP(keyS, srtcpKs_48_2, tv[i].ksSz) != 0)
  25534. return WC_TEST_RET_ENC_NC;
  25535. }
  25536. idx = wc_SRTP_KDF_kdr_to_idx(kdr);
  25537. if (idx != i)
  25538. return WC_TEST_RET_ENC_NC;
  25539. }
  25540. return 0;
  25541. }
  25542. #endif
  25543. #ifdef HAVE_ECC
  25544. /* size to use for ECC key gen tests */
  25545. #ifndef ECC_KEYGEN_SIZE
  25546. #if !defined(NO_ECC256) || defined(WOLFSSL_SM2)
  25547. #define ECC_KEYGEN_SIZE 32
  25548. #elif defined(HAVE_ECC384)
  25549. #define ECC_KEYGEN_SIZE 48
  25550. #elif defined(HAVE_ECC224)
  25551. #define ECC_KEYGEN_SIZE 28
  25552. #elif defined(HAVE_ECC521)
  25553. #define ECC_KEYGEN_SIZE 66
  25554. #else
  25555. #error No ECC keygen size defined for test
  25556. #endif
  25557. #endif
  25558. #ifdef BENCH_EMBEDDED
  25559. #define ECC_SHARED_SIZE 128
  25560. #else
  25561. #define ECC_SHARED_SIZE MAX_ECC_BYTES
  25562. #endif
  25563. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  25564. #define HAVE_ECC_DETERMINISTIC_K
  25565. #define ECC_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  25566. #else
  25567. #define ECC_DIGEST_SIZE MAX_ECC_BYTES
  25568. #endif
  25569. #define ECC_SIG_SIZE ECC_MAX_SIG_SIZE
  25570. #ifdef NO_ECC_SECP
  25571. #define NO_ECC_VECTOR_TEST
  25572. #endif
  25573. #ifndef NO_ECC_VECTOR_TEST
  25574. #if (defined(HAVE_ECC192) || defined(HAVE_ECC224) ||\
  25575. !defined(NO_ECC256) || defined(HAVE_ECC384) ||\
  25576. defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25577. #define HAVE_ECC_VECTOR_TEST
  25578. #endif
  25579. #endif
  25580. #ifdef HAVE_ECC_VECTOR_TEST
  25581. typedef struct eccVector {
  25582. const char* msg; /* SHA-1 Encoded Message */
  25583. const char* Qx;
  25584. const char* Qy;
  25585. const char* d; /* Private Key */
  25586. const char* R;
  25587. const char* S;
  25588. const char* curveName;
  25589. word32 msgLen;
  25590. word32 keySize;
  25591. const byte* r;
  25592. word32 rSz;
  25593. const byte* s;
  25594. word32 sSz;
  25595. } eccVector;
  25596. #if !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  25597. static wc_test_ret_t ecc_test_vector_item(const eccVector* vector)
  25598. {
  25599. wc_test_ret_t ret = 0;
  25600. int verify = 0;
  25601. word32 sigSz;
  25602. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25603. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25604. #else
  25605. ecc_key userA[1];
  25606. #endif
  25607. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25608. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25609. word32 sigRawSz, rSz = MAX_ECC_BYTES, sSz = MAX_ECC_BYTES;
  25610. WC_DECLARE_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25611. WC_DECLARE_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25612. WC_DECLARE_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25613. #endif
  25614. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25615. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25616. WC_ALLOC_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25617. WC_ALLOC_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25618. WC_ALLOC_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25619. #endif
  25620. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  25621. if (sig == NULL)
  25622. ERROR_OUT(MEMORY_E, done);
  25623. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25624. if (sigRaw == NULL || r == NULL || s == NULL)
  25625. ERROR_OUT(MEMORY_E, done);
  25626. #endif
  25627. #endif
  25628. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25629. if (userA == NULL)
  25630. ERROR_OUT(MEMORY_E, done);
  25631. #endif
  25632. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  25633. if (ret != 0)
  25634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25635. ret = wc_ecc_import_raw(userA, vector->Qx, vector->Qy,
  25636. vector->d, vector->curveName);
  25637. if (ret != 0)
  25638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25639. #if !defined(NO_ASN)
  25640. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25641. sigSz = ECC_SIG_SIZE;
  25642. ret = wc_ecc_rs_to_sig(vector->R, vector->S, sig, &sigSz);
  25643. if (ret != 0)
  25644. goto done;
  25645. #if !defined(HAVE_SELFTEST)
  25646. XMEMSET(sigRaw, 0, ECC_SIG_SIZE);
  25647. sigRawSz = ECC_SIG_SIZE;
  25648. ret = wc_ecc_rs_raw_to_sig(vector->r, vector->rSz, vector->s, vector->sSz,
  25649. sigRaw, &sigRawSz);
  25650. if (ret != 0)
  25651. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25652. if (sigSz != sigRawSz || XMEMCMP(sig, sigRaw, sigSz) != 0) {
  25653. ret = WC_TEST_RET_ENC_NC;
  25654. goto done;
  25655. }
  25656. ret = wc_ecc_sig_to_rs(sig, sigSz, r, &rSz, s, &sSz);
  25657. if (ret != 0)
  25658. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25659. if (rSz != vector->rSz || XMEMCMP(r, vector->r, rSz) != 0 ||
  25660. sSz != vector->sSz || XMEMCMP(s, vector->s, sSz) != 0) {
  25661. ret = WC_TEST_RET_ENC_NC;
  25662. goto done;
  25663. }
  25664. #endif /* !HAVE_SELFTEST */
  25665. #else
  25666. /* Signature will be R+S directly */
  25667. /* Make sure and zero pad if r or s is less than key size */
  25668. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25669. sigSz = vector->keySize * 2;
  25670. XMEMCPY(sig + (vector->keySize - vector->rSz),
  25671. vector->r, vector->rSz);
  25672. XMEMCPY(sig + vector->keySize + (vector->keySize - vector->sSz),
  25673. vector->s, vector->sSz);
  25674. #endif /* !NO_ASN */
  25675. #ifdef HAVE_ECC_VERIFY
  25676. do {
  25677. #if defined(WOLFSSL_ASYNC_CRYPT)
  25678. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25679. #endif
  25680. if (ret == 0)
  25681. ret = wc_ecc_verify_hash(sig, sigSz, (byte*)vector->msg,
  25682. vector->msgLen, &verify, userA);
  25683. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25684. if (ret != 0)
  25685. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25686. TEST_SLEEP();
  25687. if (verify != 1)
  25688. ret = WC_TEST_RET_ENC_NC;
  25689. #endif
  25690. done:
  25691. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25692. if (userA != NULL) {
  25693. wc_ecc_free(userA);
  25694. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25695. }
  25696. #else
  25697. wc_ecc_free(userA);
  25698. #endif
  25699. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25700. WC_FREE_VAR(sigRaw, HEAP_HINT);
  25701. WC_FREE_VAR(r, HEAP_HINT);
  25702. WC_FREE_VAR(s, HEAP_HINT);
  25703. #endif
  25704. WC_FREE_VAR(sig, HEAP_HINT);
  25705. return ret;
  25706. }
  25707. static wc_test_ret_t ecc_test_vector(int keySize)
  25708. {
  25709. wc_test_ret_t ret;
  25710. eccVector vec;
  25711. XMEMSET(&vec, 0, sizeof(vec));
  25712. vec.keySize = (word32)keySize;
  25713. switch(keySize) {
  25714. #if defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)
  25715. case 14:
  25716. return 0;
  25717. #endif /* HAVE_ECC112 */
  25718. #if defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)
  25719. case 16:
  25720. return 0;
  25721. #endif /* HAVE_ECC128 */
  25722. #if defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)
  25723. case 20:
  25724. return 0;
  25725. #endif /* HAVE_ECC160 */
  25726. #if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)
  25727. case 24:
  25728. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  25729. #if 1
  25730. vec.msg = "\x60\x80\x79\x42\x3f\x12\x42\x1d\xe6\x16\xb7\x49\x3e\xbe\x55\x1c\xf4\xd6\x5b\x92";
  25731. vec.msgLen = 20;
  25732. #else
  25733. /* This is the raw message prior to SHA-1 */
  25734. vec.msg =
  25735. "\xeb\xf7\x48\xd7\x48\xeb\xbc\xa7\xd2\x9f\xb4\x73\x69\x8a\x6e\x6b"
  25736. "\x4f\xb1\x0c\x86\x5d\x4a\xf0\x24\xcc\x39\xae\x3d\xf3\x46\x4b\xa4"
  25737. "\xf1\xd6\xd4\x0f\x32\xbf\x96\x18\xa9\x1b\xb5\x98\x6f\xa1\xa2\xaf"
  25738. "\x04\x8a\x0e\x14\xdc\x51\xe5\x26\x7e\xb0\x5e\x12\x7d\x68\x9d\x0a"
  25739. "\xc6\xf1\xa7\xf1\x56\xce\x06\x63\x16\xb9\x71\xcc\x7a\x11\xd0\xfd"
  25740. "\x7a\x20\x93\xe2\x7c\xf2\xd0\x87\x27\xa4\xe6\x74\x8c\xc3\x2f\xd5"
  25741. "\x9c\x78\x10\xc5\xb9\x01\x9d\xf2\x1c\xdc\xc0\xbc\xa4\x32\xc0\xa3"
  25742. "\xee\xd0\x78\x53\x87\x50\x88\x77\x11\x43\x59\xce\xe4\xa0\x71\xcf";
  25743. vec.msgLen = 128;
  25744. #endif
  25745. vec.Qx = "07008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6";
  25746. vec.Qy = "76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477";
  25747. vec.d = "e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3";
  25748. vec.R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  25749. vec.S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  25750. vec.curveName = "SECP192R1";
  25751. vec.r = (byte*)"\x69\x94\xd9\x62\xbd\xd0\xd7\x93\xff\xdd\xf8\x55"
  25752. "\xec\x5b\xf2\xf9\x1a\x96\x98\xb4\x62\x58\xa6\x3e";
  25753. vec.rSz = 24;
  25754. vec.s = (byte*)"\x02\xba\x64\x65\xa2\x34\x90\x37\x44\xab\x02\xbc"
  25755. "\x85\x21\x40\x5b\x73\xcf\x5f\xc0\x0e\x1a\x9f\x41";
  25756. vec.sSz = 24;
  25757. break;
  25758. #endif /* HAVE_ECC192 */
  25759. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  25760. case 28:
  25761. /* first [P-224,SHA-1] vector from FIPS 186-3 NIST vectors */
  25762. #if 1
  25763. vec.msg = "\xb9\xa3\xb8\x6d\xb0\xba\x99\xfd\xc6\xd2\x94\x6b\xfe\xbe\x9c\xe8\x3f\x10\x74\xfc";
  25764. vec.msgLen = 20;
  25765. #else
  25766. /* This is the raw message prior to SHA-1 */
  25767. vec.msg =
  25768. "\x36\xc8\xb2\x29\x86\x48\x7f\x67\x7c\x18\xd0\x97\x2a\x9e\x20\x47"
  25769. "\xb3\xaf\xa5\x9e\xc1\x62\x76\x4e\xc3\x0b\x5b\x69\xe0\x63\x0f\x99"
  25770. "\x0d\x4e\x05\xc2\x73\xb0\xe5\xa9\xd4\x28\x27\xb6\x95\xfc\x2d\x64"
  25771. "\xd9\x13\x8b\x1c\xf4\xc1\x21\x55\x89\x4c\x42\x13\x21\xa7\xbb\x97"
  25772. "\x0b\xdc\xe0\xfb\xf0\xd2\xae\x85\x61\xaa\xd8\x71\x7f\x2e\x46\xdf"
  25773. "\xe3\xff\x8d\xea\xb4\xd7\x93\x23\x56\x03\x2c\x15\x13\x0d\x59\x9e"
  25774. "\x26\xc1\x0f\x2f\xec\x96\x30\x31\xac\x69\x38\xa1\x8d\x66\x45\x38"
  25775. "\xb9\x4d\xac\x55\x34\xef\x7b\x59\x94\x24\xd6\x9b\xe1\xf7\x1c\x20";
  25776. vec.msgLen = 128;
  25777. #endif
  25778. vec.Qx = "8a4dca35136c4b70e588e23554637ae251077d1365a6ba5db9585de7";
  25779. vec.Qy = "ad3dee06de0be8279d4af435d7245f14f3b4f82eb578e519ee0057b1";
  25780. vec.d = "97c4b796e1639dd1035b708fc00dc7ba1682cec44a1002a1a820619f";
  25781. vec.R = "147b33758321e722a0360a4719738af848449e2c1d08defebc1671a7";
  25782. vec.S = "24fc7ed7f1352ca3872aa0916191289e2e04d454935d50fe6af3ad5b";
  25783. vec.curveName = "SECP224R1";
  25784. vec.r = (byte*)"\x14\x7b\x33\x75\x83\x21\xe7\x22\xa0\x36\x0a\x47"
  25785. "\x19\x73\x8a\xf8\x48\x44\x9e\x2c\x1d\x08\xde\xfe"
  25786. "\xbc\x16\x71\xa7";
  25787. vec.rSz = 28;
  25788. vec.s = (byte*)"\x24\xfc\x7e\xd7\xf1\x35\x2c\xa3\x87\x2a\xa0\x91"
  25789. "\x61\x91\x28\x9e\x2e\x04\xd4\x54\x93\x5d\x50\xfe"
  25790. "\x6a\xf3\xad\x5b";
  25791. vec.sSz = 28;
  25792. break;
  25793. #endif /* HAVE_ECC224 */
  25794. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  25795. case 30:
  25796. return 0;
  25797. #endif /* HAVE_ECC239 */
  25798. #if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES)
  25799. case 32:
  25800. /* first [P-256,SHA-1] vector from FIPS 186-3 NIST vectors */
  25801. #if 1
  25802. vec.msg = "\xa3\xf9\x1a\xe2\x1b\xa6\xb3\x03\x98\x64\x47\x2f\x18\x41\x44\xc6\xaf\x62\xcd\x0e";
  25803. vec.msgLen = 20;
  25804. #else
  25805. /* This is the raw message prior to SHA-1 */
  25806. vec.msg =
  25807. "\xa2\x4b\x21\x76\x2e\x6e\xdb\x15\x3c\xc1\x14\x38\xdb\x0e\x92\xcd"
  25808. "\xf5\x2b\x86\xb0\x6c\xa9\x70\x16\x06\x27\x59\xc7\x0d\x36\xd1\x56"
  25809. "\x2c\xc9\x63\x0d\x7f\xc7\xc7\x74\xb2\x8b\x54\xe3\x1e\xf5\x58\x72"
  25810. "\xb2\xa6\x5d\xf1\xd7\xec\x26\xde\xbb\x33\xe7\xd9\x27\xef\xcc\xf4"
  25811. "\x6b\x63\xde\x52\xa4\xf4\x31\xea\xca\x59\xb0\x5d\x2e\xde\xc4\x84"
  25812. "\x5f\xff\xc0\xee\x15\x03\x94\xd6\x1f\x3d\xfe\xcb\xcd\xbf\x6f\x5a"
  25813. "\x73\x38\xd0\xbe\x3f\x2a\x77\x34\x51\x98\x3e\xba\xeb\x48\xf6\x73"
  25814. "\x8f\xc8\x95\xdf\x35\x7e\x1a\x48\xa6\x53\xbb\x35\x5a\x31\xa1\xb4"
  25815. vec.msgLen = 128;
  25816. #endif
  25817. vec.Qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  25818. vec.Qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  25819. vec.d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  25820. vec.R = "2b826f5d44e2d0b6de531ad96b51e8f0c56fdfead3c236892e4d84eacfc3b75c";
  25821. vec.S = "a2248b62c03db35a7cd63e8a120a3521a89d3d2f61ff99035a2148ae32e3a248";
  25822. vec.r = (byte*)"\x2b\x82\x6f\x5d\x44\xe2\xd0\xb6\xde\x53\x1a\xd9"
  25823. "\x6b\x51\xe8\xf0\xc5\x6f\xdf\xea\xd3\xc2\x36\x89"
  25824. "\x2e\x4d\x84\xea\xcf\xc3\xb7\x5c";
  25825. vec.rSz = 32;
  25826. vec.s = (byte*)"\xa2\x24\x8b\x62\xc0\x3d\xb3\x5a\x7c\xd6\x3e\x8a"
  25827. "\x12\x0a\x35\x21\xa8\x9d\x3d\x2f\x61\xff\x99\x03"
  25828. "\x5a\x21\x48\xae\x32\xe3\xa2\x48";
  25829. vec.sSz = 32;
  25830. vec.curveName = "SECP256R1";
  25831. break;
  25832. #endif /* !NO_ECC256 */
  25833. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  25834. case 40:
  25835. return 0;
  25836. #endif /* HAVE_ECC320 */
  25837. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  25838. case 48:
  25839. /* first [P-384,SHA-1] vector from FIPS 186-3 NIST vectors */
  25840. #if 1
  25841. vec.msg = "\x9b\x9f\x8c\x95\x35\xa5\xca\x26\x60\x5d\xb7\xf2\xfa\x57\x3b\xdf\xc3\x2e\xab\x8b";
  25842. vec.msgLen = 20;
  25843. #else
  25844. /* This is the raw message prior to SHA-1 */
  25845. vec.msg =
  25846. "\xab\xe1\x0a\xce\x13\xe7\xe1\xd9\x18\x6c\x48\xf7\x88\x9d\x51\x47"
  25847. "\x3d\x3a\x09\x61\x98\x4b\xc8\x72\xdf\x70\x8e\xcc\x3e\xd3\xb8\x16"
  25848. "\x9d\x01\xe3\xd9\x6f\xc4\xf1\xd5\xea\x00\xa0\x36\x92\xbc\xc5\xcf"
  25849. "\xfd\x53\x78\x7c\x88\xb9\x34\xaf\x40\x4c\x03\x9d\x32\x89\xb5\xba"
  25850. "\xc5\xae\x7d\xb1\x49\x68\x75\xb5\xdc\x73\xc3\x09\xf9\x25\xc1\x3d"
  25851. "\x1c\x01\xab\xda\xaf\xeb\xcd\xac\x2c\xee\x43\x39\x39\xce\x8d\x4a"
  25852. "\x0a\x5d\x57\xbb\x70\x5f\x3b\xf6\xec\x08\x47\x95\x11\xd4\xb4\xa3"
  25853. "\x21\x1f\x61\x64\x9a\xd6\x27\x43\x14\xbf\x0d\x43\x8a\x81\xe0\x60"
  25854. vec.msgLen = 128;
  25855. #endif
  25856. vec.Qx = "e55fee6c49d8d523f5ce7bf9c0425ce4ff650708b7de5cfb095901523979a7f042602db30854735369813b5c3f5ef868";
  25857. vec.Qy = "28f59cc5dc509892a988d38a8e2519de3d0c4fd0fbdb0993e38f18506c17606c5e24249246f1ce94983a5361c5be983e";
  25858. vec.d = "a492ce8fa90084c227e1a32f7974d39e9ff67a7e8705ec3419b35fb607582bebd461e0b1520ac76ec2dd4e9b63ebae71";
  25859. vec.R = "6820b8585204648aed63bdff47f6d9acebdea62944774a7d14f0e14aa0b9a5b99545b2daee6b3c74ebf606667a3f39b7";
  25860. vec.S = "491af1d0cccd56ddd520b233775d0bc6b40a6255cc55207d8e9356741f23c96c14714221078dbd5c17f4fdd89b32a907";
  25861. vec.curveName = "SECP384R1";
  25862. vec.r = (byte*)"\x68\x20\xb8\x58\x52\x04\x64\x8a\xed\x63\xbd\xff"
  25863. "\x47\xf6\xd9\xac\xeb\xde\xa6\x29\x44\x77\x4a\x7d"
  25864. "\x14\xf0\xe1\x4a\xa0\xb9\xa5\xb9\x95\x45\xb2\xda"
  25865. "\xee\x6b\x3c\x74\xeb\xf6\x06\x66\x7a\x3f\x39\xb7";
  25866. vec.rSz = 48;
  25867. vec.s = (byte*)"\x49\x1a\xf1\xd0\xcc\xcd\x56\xdd\xd5\x20\xb2\x33"
  25868. "\x77\x5d\x0b\xc6\xb4\x0a\x62\x55\xcc\x55\x20\x7d"
  25869. "\x8e\x93\x56\x74\x1f\x23\xc9\x6c\x14\x71\x42\x21"
  25870. "\x07\x8d\xbd\x5c\x17\xf4\xfd\xd8\x9b\x32\xa9\x07";
  25871. vec.sSz = 48;
  25872. break;
  25873. #endif /* HAVE_ECC384 */
  25874. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  25875. case 64:
  25876. return 0;
  25877. #endif /* HAVE_ECC512 */
  25878. #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
  25879. case 66:
  25880. /* first [P-521,SHA-1] vector from FIPS 186-3 NIST vectors */
  25881. #if 1
  25882. vec.msg = "\x1b\xf7\x03\x9c\xca\x23\x94\x27\x3f\x11\xa1\xd4\x8d\xcc\xb4\x46\x6f\x31\x61\xdf";
  25883. vec.msgLen = 20;
  25884. #else
  25885. /* This is the raw message prior to SHA-1 */
  25886. vec.msg =
  25887. "\x50\x3f\x79\x39\x34\x0a\xc7\x23\xcd\x4a\x2f\x4e\x6c\xcc\x27\x33"
  25888. "\x38\x3a\xca\x2f\xba\x90\x02\x19\x9d\x9e\x1f\x94\x8b\xe0\x41\x21"
  25889. "\x07\xa3\xfd\xd5\x14\xd9\x0c\xd4\xf3\x7c\xc3\xac\x62\xef\x00\x3a"
  25890. "\x2d\xb1\xd9\x65\x7a\xb7\x7f\xe7\x55\xbf\x71\xfa\x59\xe4\xd9\x6e"
  25891. "\xa7\x2a\xe7\xbf\x9d\xe8\x7d\x79\x34\x3b\xc1\xa4\xbb\x14\x4d\x16"
  25892. "\x28\xd1\xe9\xe9\xc8\xed\x80\x8b\x96\x2c\x54\xe5\xf9\x6d\x53\xda"
  25893. "\x14\x7a\x96\x38\xf9\x4a\x91\x75\xd8\xed\x61\x05\x5f\x0b\xa5\x73"
  25894. "\xa8\x2b\xb7\xe0\x18\xee\xda\xc4\xea\x7b\x36\x2e\xc8\x9c\x38\x2b"
  25895. vec.msgLen = 128;
  25896. #endif
  25897. vec.Qx = "12fbcaeffa6a51f3ee4d3d2b51c5dec6d7c726ca353fc014ea2bf7cfbb9b910d32cbfa6a00fe39b6cdb8946f22775398b2e233c0cf144d78c8a7742b5c7a3bb5d23";
  25898. vec.Qy = "09cdef823dd7bf9a79e8cceacd2e4527c231d0ae5967af0958e931d7ddccf2805a3e618dc3039fec9febbd33052fe4c0fee98f033106064982d88f4e03549d4a64d";
  25899. vec.d = "1bd56bd106118eda246155bd43b42b8e13f0a6e25dd3bb376026fab4dc92b6157bc6dfec2d15dd3d0cf2a39aa68494042af48ba9601118da82c6f2108a3a203ad74";
  25900. vec.R = "0bd117b4807710898f9dd7778056485777668f0e78e6ddf5b000356121eb7a220e9493c7f9a57c077947f89ac45d5acb6661bbcd17abb3faea149ba0aa3bb1521be";
  25901. vec.S = "019cd2c5c3f9870ecdeb9b323abdf3a98cd5e231d85c6ddc5b71ab190739f7f226e6b134ba1d5889ddeb2751dabd97911dff90c34684cdbe7bb669b6c3d22f2480c";
  25902. vec.curveName = "SECP521R1";
  25903. vec.r = (byte*)"\xbd\x11\x7b\x48\x07\x71\x08\x98\xf9\xdd\x77\x78"
  25904. "\x05\x64\x85\x77\x76\x68\xf0\xe7\x8e\x6d\xdf\x5b"
  25905. "\x00\x03\x56\x12\x1e\xb7\xa2\x20\xe9\x49\x3c\x7f"
  25906. "\x9a\x57\xc0\x77\x94\x7f\x89\xac\x45\xd5\xac\xb6"
  25907. "\x66\x1b\xbc\xd1\x7a\xbb\x3f\xae\xa1\x49\xba\x0a"
  25908. "\xa3\xbb\x15\x21\xbe";
  25909. vec.rSz = 65;
  25910. vec.s = (byte*)"\x19\xcd\x2c\x5c\x3f\x98\x70\xec\xde\xb9\xb3\x23"
  25911. "\xab\xdf\x3a\x98\xcd\x5e\x23\x1d\x85\xc6\xdd\xc5"
  25912. "\xb7\x1a\xb1\x90\x73\x9f\x7f\x22\x6e\x6b\x13\x4b"
  25913. "\xa1\xd5\x88\x9d\xde\xb2\x75\x1d\xab\xd9\x79\x11"
  25914. "\xdf\xf9\x0c\x34\x68\x4c\xdb\xe7\xbb\x66\x9b\x6c"
  25915. "\x3d\x22\xf2\x48\x0c";
  25916. vec.sSz = 65;
  25917. break;
  25918. #endif /* HAVE_ECC521 */
  25919. default:
  25920. return WC_TEST_RET_ENC_EC(NOT_COMPILED_IN); /* Invalid key size /
  25921. * Not supported
  25922. */
  25923. }; /* Switch */
  25924. ret = ecc_test_vector_item(&vec);
  25925. if (ret < 0) {
  25926. return ret;
  25927. }
  25928. return 0;
  25929. }
  25930. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  25931. #if defined(HAVE_ECC_SIGN) && \
  25932. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  25933. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  25934. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  25935. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  25936. static wc_test_ret_t ecdsa_test_deterministic_k_sig(ecc_key *key,
  25937. enum wc_HashType hashType, const char* msg, WC_RNG* rng, const byte* expSig,
  25938. size_t expSigSz)
  25939. {
  25940. wc_test_ret_t ret;
  25941. int verify;
  25942. byte sig[ECC_MAX_SIG_SIZE];
  25943. word32 sigSz;
  25944. unsigned char hash[WC_MAX_DIGEST_SIZE];
  25945. ret = wc_Hash(hashType,
  25946. (byte*)msg, (word32)XSTRLEN(msg),
  25947. hash, sizeof(hash));
  25948. if (ret != 0)
  25949. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25950. /* Sign test */
  25951. sigSz = sizeof(sig);
  25952. do {
  25953. #if defined(WOLFSSL_ASYNC_CRYPT)
  25954. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25955. #endif
  25956. if (ret == 0)
  25957. ret = wc_ecc_sign_hash(hash, wc_HashGetDigestSize(hashType),
  25958. sig, &sigSz, rng, key);
  25959. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25960. if (ret != 0)
  25961. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25962. TEST_SLEEP();
  25963. /* Compare test vector */
  25964. if (sigSz != expSigSz) {
  25965. ret = WC_TEST_RET_ENC_NC;
  25966. goto done;
  25967. }
  25968. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  25969. ret = WC_TEST_RET_ENC_NC;
  25970. goto done;
  25971. }
  25972. /* Verification */
  25973. verify = 0;
  25974. do {
  25975. #if defined(WOLFSSL_ASYNC_CRYPT)
  25976. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25977. #endif
  25978. if (ret == 0)
  25979. ret = wc_ecc_verify_hash(sig, sigSz,
  25980. hash, wc_HashGetDigestSize(hashType), &verify, key);
  25981. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25982. if (ret != 0)
  25983. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25984. if (verify != 1) {
  25985. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  25986. }
  25987. done:
  25988. return ret;
  25989. }
  25990. static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
  25991. {
  25992. wc_test_ret_t ret;
  25993. #ifdef WOLFSSL_SMALL_STACK
  25994. ecc_key *key = NULL;
  25995. #else
  25996. ecc_key key[1];
  25997. #endif
  25998. int key_inited = 0;
  25999. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26000. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26001. "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721";
  26002. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26003. "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6";
  26004. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26005. "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299";
  26006. #ifndef NO_SHA256
  26007. WOLFSSL_SMALL_STACK_STATIC const byte expSig256[] = {
  26008. 0x30, 0x46, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26009. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26010. 0x00, 0xEF, 0xD4, 0x8B, 0x2A, 0xAC, 0xB6, 0xA8,
  26011. 0xFD, 0x11, 0x40, 0xDD, 0x9C, 0xD4, 0x5E, 0x81,
  26012. 0xD6, 0x9D, 0x2C, 0x87, 0x7B, 0x56, 0xAA, 0xF9,
  26013. 0x91, 0xC3, 0x4D, 0x0E, 0xA8, 0x4E, 0xAF, 0x37,
  26014. 0x16,
  26015. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26016. 0x00, 0xF7, 0xCB, 0x1C, 0x94, 0x2D, 0x65, 0x7C,
  26017. 0x41, 0xD4, 0x36, 0xC7, 0xA1, 0xB6, 0xE2, 0x9F,
  26018. 0x65, 0xF3, 0xE9, 0x00, 0xDB, 0xB9, 0xAF, 0xF4,
  26019. 0x06, 0x4D, 0xC4, 0xAB, 0x2F, 0x84, 0x3A, 0xCD,
  26020. 0xA8
  26021. };
  26022. #endif
  26023. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26024. WOLFSSL_SMALL_STACK_STATIC const byte expSig384[] = {
  26025. 0x30, 0x44, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26026. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26027. 0x0e, 0xaf, 0xea, 0x03, 0x9b, 0x20, 0xe9, 0xb4,
  26028. 0x23, 0x09, 0xfb, 0x1d, 0x89, 0xe2, 0x13, 0x05,
  26029. 0x7c, 0xbf, 0x97, 0x3d, 0xc0, 0xcf, 0xc8, 0xf1,
  26030. 0x29, 0xed, 0xdd, 0xc8, 0x00, 0xef, 0x77, 0x19,
  26031. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26032. 0x48, 0x61, 0xf0, 0x49, 0x1e, 0x69, 0x98, 0xb9,
  26033. 0x45, 0x51, 0x93, 0xe3, 0x4e, 0x7b, 0x0d, 0x28,
  26034. 0x4d, 0xdd, 0x71, 0x49, 0xa7, 0x4b, 0x95, 0xb9,
  26035. 0x26, 0x1f, 0x13, 0xab, 0xde, 0x94, 0x09, 0x54
  26036. };
  26037. #endif
  26038. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26039. WOLFSSL_SMALL_STACK_STATIC const byte expSig512[] = {
  26040. 0x30, 0x45, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26041. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26042. 0x00, 0x84, 0x96, 0xa6, 0x0b, 0x5e, 0x9b, 0x47,
  26043. 0xc8, 0x25, 0x48, 0x88, 0x27, 0xe0, 0x49, 0x5b,
  26044. 0x0e, 0x3f, 0xa1, 0x09, 0xec, 0x45, 0x68, 0xfd,
  26045. 0x3f, 0x8d, 0x10, 0x97, 0x67, 0x8e, 0xb9, 0x7f,
  26046. 0x00,
  26047. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26048. 0x23, 0x62, 0xab, 0x1a, 0xdb, 0xe2, 0xb8, 0xad,
  26049. 0xf9, 0xcb, 0x9e, 0xda, 0xb7, 0x40, 0xea, 0x60,
  26050. 0x49, 0xc0, 0x28, 0x11, 0x4f, 0x24, 0x60, 0xf9,
  26051. 0x65, 0x54, 0xf6, 0x1f, 0xae, 0x33, 0x02, 0xfe
  26052. };
  26053. #endif
  26054. #ifdef WOLFSSL_SMALL_STACK
  26055. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26056. if (key == NULL)
  26057. return MEMORY_E;
  26058. #endif
  26059. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26060. if (ret != 0)
  26061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26062. key_inited = 1;
  26063. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26064. if (ret != 0)
  26065. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26066. ret = wc_ecc_set_deterministic(key, 1);
  26067. if (ret != 0)
  26068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26069. #ifndef NO_SHA256
  26070. /* Test for SHA2-256 */
  26071. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA256, msg, rng,
  26072. expSig256, sizeof(expSig256));
  26073. if (ret != 0)
  26074. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26075. #endif /* !NO_SHA256 */
  26076. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26077. /* Test for SHA2-384 */
  26078. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA384, msg, rng,
  26079. expSig384, sizeof(expSig384));
  26080. if (ret != 0)
  26081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26082. #endif /* WOLFSSL_SHA384 */
  26083. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26084. /* Test for SHA2-512 */
  26085. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA512, msg, rng,
  26086. expSig512, sizeof(expSig512));
  26087. if (ret != 0)
  26088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26089. #endif /* WOLFSSL_SHA512 */
  26090. done:
  26091. if (key_inited)
  26092. wc_ecc_free(key);
  26093. #ifdef WOLFSSL_SMALL_STACK
  26094. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26095. #endif
  26096. return ret;
  26097. }
  26098. #endif /* NO_ECC256 || HAVE_ALL_CURVES */
  26099. #ifdef WOLFSSL_PUBLIC_MP
  26100. static wc_test_ret_t ecdsa_test_deterministic_k_rs(ecc_key *key,
  26101. enum wc_HashType hashType, const char* msg, WC_RNG* rng,
  26102. mp_int* r, mp_int* s,
  26103. mp_int* expR, mp_int* expS)
  26104. {
  26105. wc_test_ret_t ret;
  26106. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26107. int verify;
  26108. ret = wc_Hash(hashType,
  26109. (byte*)msg, (word32)XSTRLEN(msg),
  26110. hash, sizeof(hash));
  26111. if (ret != 0)
  26112. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26113. ret = wc_ecc_sign_hash_ex(hash, wc_HashGetDigestSize(hashType), rng, key,
  26114. r, s);
  26115. #if defined(WOLFSSL_ASYNC_CRYPT)
  26116. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26117. #endif
  26118. if (ret != 0)
  26119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26120. TEST_SLEEP();
  26121. if (mp_cmp(r, expR) != MP_EQ && mp_cmp(s, expS) != MP_EQ) {
  26122. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26123. }
  26124. /* Verification */
  26125. verify = 0;
  26126. ret = wc_ecc_verify_hash_ex(r, s, hash, wc_HashGetDigestSize(hashType),
  26127. &verify, key);
  26128. #if defined(WOLFSSL_ASYNC_CRYPT)
  26129. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26130. #endif
  26131. if (ret != 0)
  26132. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26133. if (verify != 1) {
  26134. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26135. }
  26136. done:
  26137. return ret;
  26138. }
  26139. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  26140. /* KAT from RFC6979 */
  26141. static wc_test_ret_t ecc384_test_deterministic_k(WC_RNG* rng)
  26142. {
  26143. wc_test_ret_t ret;
  26144. #ifdef WOLFSSL_SMALL_STACK
  26145. ecc_key *key;
  26146. mp_int *r, *s, *expR, *expS;
  26147. #else
  26148. ecc_key key[1];
  26149. mp_int r[1], s[1], expR[1], expS[1];
  26150. #endif
  26151. int key_inited = 0,
  26152. tmp_mp_ints_inited = 0;
  26153. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26154. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26155. "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D8"
  26156. "96D5724E4C70A825F872C9EA60D2EDF5";
  26157. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26158. "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64"
  26159. "DEF8F0EA9055866064A254515480BC13";
  26160. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26161. "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1"
  26162. "288B231C3AE0D4FE7344FD2533264720";
  26163. #ifndef NO_SHA256
  26164. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26165. "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33"
  26166. "BDE1E888E63355D92FA2B3C36D8FB2CD";
  26167. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26168. "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEB"
  26169. "EFDC63ECCD1AC42EC0CB8668A4FA0AB0";
  26170. #endif
  26171. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26172. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26173. "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C"
  26174. "81A648152E44ACF96E36DD1E80FABE46";
  26175. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26176. "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94F"
  26177. "A329C145786E679E7B82C71A38628AC8";
  26178. #endif
  26179. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26180. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26181. "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799C"
  26182. "FE30F35CC900056D7C99CD7882433709";
  26183. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26184. "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112"
  26185. "DC7CC3EF3446DEFCEB01A45C2667FDD5";
  26186. #endif
  26187. #ifdef WOLFSSL_SMALL_STACK
  26188. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26189. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26190. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26191. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26192. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26193. if ((key == NULL) ||
  26194. (r == NULL) ||
  26195. (s == NULL) ||
  26196. (expR == NULL) ||
  26197. (expS == NULL))
  26198. {
  26199. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26200. }
  26201. #endif
  26202. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26203. if (ret != MP_OKAY)
  26204. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26205. tmp_mp_ints_inited = 1;
  26206. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26207. if (ret != 0)
  26208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26209. key_inited = 1;
  26210. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP384R1");
  26211. if (ret != 0)
  26212. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26213. ret = wc_ecc_set_deterministic(key, 1);
  26214. if (ret != 0)
  26215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26216. #ifndef NO_SHA256
  26217. /* Test for SHA2-256 */
  26218. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26219. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26220. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26221. r, s, expR, expS);
  26222. if (ret != 0)
  26223. ERROR_OUT(ret, done);
  26224. #endif /* NO_SHA256 */
  26225. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26226. /* Test for SHA2-384 */
  26227. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26228. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26229. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26230. r, s, expR, expS);
  26231. if (ret != 0)
  26232. ERROR_OUT(ret, done);
  26233. #endif /* WOLFSSL_SHA384 */
  26234. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26235. /* Test for SHA2-512 */
  26236. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26237. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26238. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26239. r, s, expR, expS);
  26240. if (ret != 0)
  26241. ERROR_OUT(ret, done);
  26242. #endif /* WOLFSSL_SHA512 */
  26243. done:
  26244. if (key_inited)
  26245. wc_ecc_free(key);
  26246. if (tmp_mp_ints_inited) {
  26247. mp_free(r);
  26248. mp_free(s);
  26249. mp_free(expR);
  26250. mp_free(expS);
  26251. }
  26252. #ifdef WOLFSSL_SMALL_STACK
  26253. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26254. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26255. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26256. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26257. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26258. #endif
  26259. return ret;
  26260. }
  26261. #endif /* HAVE_ECC384 */
  26262. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  26263. /* KAT from RFC6979 */
  26264. static wc_test_ret_t ecc521_test_deterministic_k(WC_RNG* rng)
  26265. {
  26266. wc_test_ret_t ret;
  26267. #ifdef WOLFSSL_SMALL_STACK
  26268. ecc_key *key;
  26269. mp_int *r, *s, *expR, *expS;
  26270. #else
  26271. ecc_key key[1];
  26272. mp_int r[1], s[1], expR[1], expS[1];
  26273. #endif
  26274. int key_inited = 0,
  26275. tmp_mp_ints_inited = 0;
  26276. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26277. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26278. "0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75C"
  26279. "AA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83"
  26280. "538";
  26281. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26282. "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD3"
  26283. "71123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F502"
  26284. "3A4";
  26285. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26286. "0493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A2"
  26287. "8A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDF"
  26288. "CF5";
  26289. #ifndef NO_SHA256
  26290. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26291. "1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659"
  26292. "D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E"
  26293. "1A7";
  26294. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26295. "04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916"
  26296. "E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7E"
  26297. "CFC";
  26298. #endif
  26299. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26300. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26301. "1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4"
  26302. "B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67"
  26303. "451";
  26304. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26305. "1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5"
  26306. "FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65"
  26307. "D61";
  26308. #endif
  26309. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26310. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26311. "0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F1"
  26312. "74E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E37"
  26313. "7FA";
  26314. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26315. "0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF2"
  26316. "82623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A"
  26317. "67A";
  26318. #endif
  26319. #ifdef WOLFSSL_SMALL_STACK
  26320. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26321. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26322. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26323. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26324. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26325. if ((key == NULL) ||
  26326. (r == NULL) ||
  26327. (s == NULL) ||
  26328. (expR == NULL) ||
  26329. (expS == NULL))
  26330. {
  26331. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26332. goto done;
  26333. }
  26334. #endif
  26335. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26336. if (ret != MP_OKAY)
  26337. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26338. tmp_mp_ints_inited = 1;
  26339. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26340. if (ret != 0)
  26341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26342. key_inited = 1;
  26343. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP521R1");
  26344. if (ret != 0)
  26345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26346. ret = wc_ecc_set_deterministic(key, 1);
  26347. if (ret != 0)
  26348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26349. #ifndef NO_SHA256
  26350. /* Test for SHA2-256 */
  26351. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26352. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26353. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26354. r, s, expR, expS);
  26355. if (ret != 0)
  26356. ERROR_OUT(ret, done);
  26357. #endif /* NO_SHA256 */
  26358. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26359. /* Test for SHA2-384 */
  26360. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26361. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26362. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26363. r, s, expR, expS);
  26364. if (ret != 0)
  26365. ERROR_OUT(ret, done);
  26366. #endif /* WOLFSSL_SHA384 */
  26367. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26368. /* Test for SHA2-512 */
  26369. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26370. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26371. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26372. r, s, expR, expS);
  26373. if (ret != 0)
  26374. ERROR_OUT(ret, done);
  26375. #endif /* WOLFSSL_SHA512 */
  26376. done:
  26377. if (key_inited)
  26378. wc_ecc_free(key);
  26379. if (tmp_mp_ints_inited) {
  26380. mp_free(r);
  26381. mp_free(s);
  26382. mp_free(expR);
  26383. mp_free(expS);
  26384. }
  26385. #ifdef WOLFSSL_SMALL_STACK
  26386. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26387. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26388. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26389. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26390. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26391. #endif
  26392. return ret;
  26393. }
  26394. #endif /* HAVE_ECC521 */
  26395. #endif /* WOLFSSL_PUBLIC_MP */
  26396. #endif /* HAVE_ECC_SIGN && (WOLFSSL_ECDSA_DETERMINISTIC_K ||
  26397. WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  26398. && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  26399. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  26400. !defined(WOLFSSL_KCAPI_ECC)
  26401. static wc_test_ret_t ecc_test_sign_vectors(WC_RNG* rng)
  26402. {
  26403. wc_test_ret_t ret;
  26404. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26405. ecc_key *key = NULL;
  26406. #else
  26407. ecc_key key[1];
  26408. #endif
  26409. int key_inited = 0;
  26410. byte sig[72];
  26411. word32 sigSz;
  26412. WOLFSSL_SMALL_STACK_STATIC const unsigned char hash[32] = "test wolfSSL deterministic sign";
  26413. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26414. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26415. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26416. WOLFSSL_SMALL_STACK_STATIC const byte k[1] = { 0x02 };
  26417. WOLFSSL_SMALL_STACK_STATIC const byte expSig[71] = {
  26418. 0x30, 0x45, 0x02, 0x20, 0x7c, 0xf2, 0x7b, 0x18,
  26419. 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03,
  26420. 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2,
  26421. 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc,
  26422. 0x47, 0x66, 0x99, 0x78, 0x02, 0x21, 0x00, 0xa8,
  26423. 0x43, 0xa0, 0xce, 0x6c, 0x5e, 0x17, 0x8a, 0x53,
  26424. 0x4d, 0xaf, 0xd2, 0x95, 0x78, 0x9f, 0x84, 0x4f,
  26425. 0x94, 0xb8, 0x75, 0xa3, 0x19, 0xa5, 0xd4, 0xdf,
  26426. 0xe1, 0xd4, 0x5e, 0x9d, 0x97, 0xfe, 0x81
  26427. };
  26428. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26429. if ((key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  26430. return MEMORY_E;
  26431. #endif
  26432. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26433. if (ret != 0)
  26434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26435. key_inited = 1;
  26436. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26437. if (ret != 0)
  26438. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26439. #if (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) \
  26440. && (HAVE_FIPS_VERSION > 2)))
  26441. wc_ecc_set_flags(key, WC_ECC_FLAG_DEC_SIGN);
  26442. #endif
  26443. ret = wc_ecc_sign_set_k(k, sizeof(k), key);
  26444. if (ret != 0)
  26445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26446. sigSz = sizeof(sig);
  26447. do {
  26448. #if defined(WOLFSSL_ASYNC_CRYPT)
  26449. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26450. #endif
  26451. if (ret == 0)
  26452. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26453. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26454. if (ret != 0)
  26455. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26456. TEST_SLEEP();
  26457. if (sigSz != sizeof(expSig)) {
  26458. ret = WC_TEST_RET_ENC_NC;
  26459. goto done;
  26460. }
  26461. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26462. ret = WC_TEST_RET_ENC_NC;
  26463. goto done;
  26464. }
  26465. sigSz = sizeof(sig);
  26466. do {
  26467. #if defined(WOLFSSL_ASYNC_CRYPT)
  26468. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26469. #endif
  26470. if (ret == 0)
  26471. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26472. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26473. if (ret != 0)
  26474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26475. TEST_SLEEP();
  26476. done:
  26477. if (key_inited)
  26478. wc_ecc_free(key);
  26479. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26480. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26481. #endif
  26482. return ret;
  26483. }
  26484. #endif
  26485. #if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE)
  26486. static wc_test_ret_t ecc_test_cdh_vectors(WC_RNG* rng)
  26487. {
  26488. wc_test_ret_t ret;
  26489. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26490. ecc_key *pub_key = (ecc_key *)XMALLOC(sizeof *pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26491. ecc_key *priv_key = (ecc_key *)XMALLOC(sizeof *priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26492. #else
  26493. ecc_key pub_key[1], priv_key[1];
  26494. #endif
  26495. byte sharedA[32] = {0}, sharedB[32] = {0};
  26496. word32 x, z;
  26497. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287";
  26498. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac";
  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 char* ZIUT = "46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b";
  26503. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26504. if ((pub_key == NULL) ||
  26505. (priv_key == NULL)) {
  26506. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26507. goto done;
  26508. }
  26509. #endif
  26510. XMEMSET(pub_key, 0, sizeof *pub_key);
  26511. XMEMSET(priv_key, 0, sizeof *priv_key);
  26512. /* setup private and public keys */
  26513. ret = wc_ecc_init_ex(pub_key, HEAP_HINT, devId);
  26514. if (ret != 0)
  26515. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26516. ret = wc_ecc_init_ex(priv_key, HEAP_HINT, devId);
  26517. if (ret != 0)
  26518. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26519. wc_ecc_set_flags(pub_key, WC_ECC_FLAG_COFACTOR);
  26520. wc_ecc_set_flags(priv_key, WC_ECC_FLAG_COFACTOR);
  26521. ret = wc_ecc_import_raw(pub_key, QCAVSx, QCAVSy, NULL, "SECP256R1");
  26522. if (ret != 0)
  26523. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26524. ret = wc_ecc_import_raw(priv_key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26525. if (ret != 0)
  26526. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26527. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26528. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26529. !defined(HAVE_SELFTEST)
  26530. ret = wc_ecc_set_rng(priv_key, rng);
  26531. if (ret != 0)
  26532. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26533. #else
  26534. (void)rng;
  26535. #endif
  26536. /* compute ECC Cofactor shared secret */
  26537. x = sizeof(sharedA);
  26538. do {
  26539. #if defined(WOLFSSL_ASYNC_CRYPT)
  26540. ret = wc_AsyncWait(ret, &priv_key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26541. #endif
  26542. if (ret == 0)
  26543. ret = wc_ecc_shared_secret(priv_key, pub_key, sharedA, &x);
  26544. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26545. if (ret != 0)
  26546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26547. TEST_SLEEP();
  26548. /* read in expected Z */
  26549. z = sizeof(sharedB);
  26550. ret = Base16_Decode((const byte*)ZIUT, (word32)XSTRLEN(ZIUT), sharedB, &z);
  26551. if (ret != 0)
  26552. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26553. /* compare results */
  26554. if (x != z || XMEMCMP(sharedA, sharedB, x)) {
  26555. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26556. }
  26557. done:
  26558. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26559. if (priv_key) {
  26560. wc_ecc_free(priv_key);
  26561. XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26562. }
  26563. if (pub_key) {
  26564. wc_ecc_free(pub_key);
  26565. XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26566. }
  26567. #else
  26568. wc_ecc_free(priv_key);
  26569. wc_ecc_free(pub_key);
  26570. #endif
  26571. return ret;
  26572. }
  26573. #endif /* HAVE_ECC_CDH && HAVE_ECC_DHE */
  26574. #endif /* HAVE_ECC_VECTOR_TEST */
  26575. #ifdef HAVE_ECC_KEY_IMPORT
  26576. /* returns 0 on success */
  26577. static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
  26578. {
  26579. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26580. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26581. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26582. ecc_key *pub = (ecc_key *)XMALLOC(sizeof *pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26583. #endif
  26584. byte *exportBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26585. byte *tmp = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26586. #else
  26587. ecc_key key[1];
  26588. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  26589. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26590. ecc_key pub[1];
  26591. #endif
  26592. byte exportBuf[ECC_BUFSIZE];
  26593. byte tmp[ECC_BUFSIZE];
  26594. #endif
  26595. const byte* msg = (const byte*)"test wolfSSL ECC public gen";
  26596. word32 x;
  26597. word32 tmpSz;
  26598. wc_test_ret_t ret = 0;
  26599. ecc_point* pubPoint = NULL;
  26600. #ifdef HAVE_ECC_VERIFY
  26601. int verify = 0;
  26602. #endif
  26603. #ifdef NO_ASN
  26604. /* private d for eccKeyDerFile / ecc_key_der_256 */
  26605. const byte keyPriv[] = {
  26606. 0x45, 0xB6, 0x69, 0x02, 0x73, 0x9C, 0x6C, 0x85,
  26607. 0xA1, 0x38, 0x5B, 0x72, 0xE8, 0xE8, 0xC7, 0xAC,
  26608. 0xC4, 0x03, 0x8D, 0x53, 0x35, 0x04, 0xFA, 0x6C,
  26609. 0x28, 0xDC, 0x34, 0x8D, 0xE1, 0xA8, 0x09, 0x8C
  26610. };
  26611. #endif
  26612. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26613. if ((key == NULL) ||
  26614. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26615. (pub == NULL) ||
  26616. #endif
  26617. (exportBuf == NULL) ||
  26618. (tmp == NULL))
  26619. ERROR_OUT(MEMORY_E, done);
  26620. #endif
  26621. (void)msg;
  26622. (void)verify;
  26623. (void)exportBuf;
  26624. (void)rng;
  26625. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26626. #ifndef NO_ECC256
  26627. #if defined(USE_CERT_BUFFERS_256)
  26628. {
  26629. XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
  26630. tmpSz = (size_t)sizeof_ecc_key_der_256;
  26631. }
  26632. #elif !defined(NO_FILESYSTEM)
  26633. {
  26634. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  26635. if (!file) {
  26636. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26637. }
  26638. tmpSz = (word32)XFREAD(tmp, 1, ECC_BUFSIZE, file);
  26639. XFCLOSE(file);
  26640. if (tmpSz == 0)
  26641. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26642. }
  26643. #else
  26644. {
  26645. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
  26646. ERROR_OUT(ASN_PARSE_E, done);
  26647. }
  26648. #endif /* USE_CERT_BUFFERS_256 */
  26649. /* import private only then test with */
  26650. ret = wc_ecc_import_private_key(tmp, tmpSz, NULL, 0, NULL);
  26651. if (ret == 0) {
  26652. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26653. }
  26654. ret = wc_ecc_import_private_key(NULL, tmpSz, NULL, 0, key);
  26655. if (ret == 0) {
  26656. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26657. }
  26658. #ifndef NO_ASN
  26659. x = 0;
  26660. ret = wc_EccPrivateKeyDecode(tmp, &x, key, tmpSz);
  26661. if (ret != 0)
  26662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26663. #ifdef HAVE_ECC_KEY_EXPORT
  26664. x = ECC_BUFSIZE;
  26665. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26666. if (ret != 0)
  26667. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26668. /* make private only key */
  26669. wc_ecc_free(key);
  26670. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26671. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26672. if (ret != 0)
  26673. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26674. x = ECC_BUFSIZE;
  26675. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26676. if (ret == 0) {
  26677. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26678. }
  26679. #endif /* HAVE_ECC_KEY_EXPORT */
  26680. #else
  26681. /* Load raw private d directly */
  26682. ret = wc_ecc_import_private_key(keyPriv, sizeof(keyPriv), NULL, 0, key);
  26683. #endif /* !NO_ASN */
  26684. ret = wc_ecc_make_pub(NULL, NULL);
  26685. if (ret == 0) {
  26686. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26687. }
  26688. TEST_SLEEP();
  26689. #ifndef WOLFSSL_NO_MALLOC
  26690. pubPoint = wc_ecc_new_point_h(HEAP_HINT);
  26691. if (pubPoint == NULL) {
  26692. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26693. }
  26694. #if !defined(WOLFSSL_CRYPTOCELL)
  26695. ret = wc_ecc_make_pub(key, pubPoint);
  26696. #if defined(WOLFSSL_ASYNC_CRYPT)
  26697. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26698. #endif
  26699. if (ret != 0)
  26700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26701. #endif /* !WOLFSSL_CRYPTOCELL */
  26702. TEST_SLEEP();
  26703. #ifdef HAVE_ECC_KEY_EXPORT
  26704. /* export should still fail, is private only key */
  26705. x = ECC_BUFSIZE;
  26706. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26707. if (ret == 0) {
  26708. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26709. }
  26710. #endif /* HAVE_ECC_KEY_EXPORT */
  26711. #endif /* !WOLFSSL_NO_MALLOC */
  26712. #endif /* !NO_ECC256 */
  26713. /* create a new key since above test for loading key is not supported */
  26714. #if defined(WOLFSSL_CRYPTOCELL) || defined(NO_ECC256) || \
  26715. defined(WOLFSSL_QNX_CAAM) || defined(WOLFSSL_SE050) || \
  26716. defined(WOLFSSL_SECO_CAAM) || defined(WOLFSSL_IMXRT1170_CAAM)
  26717. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  26718. if (ret != 0)
  26719. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26720. #endif
  26721. #if defined(HAVE_ECC_SIGN) && (!defined(ECC_TIMING_RESISTANT) || \
  26722. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG))) && \
  26723. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(HAVE_ECC_DETERMINISTIC_K)
  26724. tmpSz = ECC_BUFSIZE;
  26725. ret = 0;
  26726. do {
  26727. #if defined(WOLFSSL_ASYNC_CRYPT)
  26728. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26729. #endif
  26730. if (ret == 0) {
  26731. ret = wc_ecc_sign_hash(msg, (word32)XSTRLEN((const char* )msg), tmp,
  26732. &tmpSz, rng, key);
  26733. }
  26734. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26735. if (ret != 0)
  26736. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26737. TEST_SLEEP();
  26738. #ifdef HAVE_ECC_VERIFY
  26739. /* try verify with private only key */
  26740. ret = 0;
  26741. do {
  26742. #if defined(WOLFSSL_ASYNC_CRYPT)
  26743. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26744. #endif
  26745. if (ret == 0) {
  26746. ret = wc_ecc_verify_hash(tmp, tmpSz, msg,
  26747. (word32)XSTRLEN((const char*)msg), &verify, key);
  26748. }
  26749. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26750. if (ret != 0)
  26751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26752. if (verify != 1) {
  26753. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26754. }
  26755. TEST_SLEEP();
  26756. #ifdef HAVE_ECC_KEY_EXPORT
  26757. /* exporting the public part should now work */
  26758. x = ECC_BUFSIZE;
  26759. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26760. if (ret != 0)
  26761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26762. #endif /* HAVE_ECC_KEY_EXPORT */
  26763. #endif /* HAVE_ECC_VERIFY */
  26764. #endif /* HAVE_ECC_SIGN */
  26765. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  26766. /* now test private only key with creating a shared secret */
  26767. x = ECC_BUFSIZE;
  26768. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26769. if (ret != 0)
  26770. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26771. #if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SE050)
  26772. /* make private only key */
  26773. wc_ecc_free(key);
  26774. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26775. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26776. if (ret != 0)
  26777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26778. /* check that public export fails with private only key */
  26779. x = ECC_BUFSIZE;
  26780. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26781. if (ret == 0) {
  26782. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26783. }
  26784. #endif /* WOLFSSL_QNX_CAAM */
  26785. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  26786. /* make public key for shared secret */
  26787. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  26788. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, pub);
  26789. #ifdef HAVE_ECC_CDH
  26790. wc_ecc_set_flags(key, WC_ECC_FLAG_COFACTOR);
  26791. #endif
  26792. #if defined(WOLFSSL_ASYNC_CRYPT)
  26793. ret = wc_AsyncWait(ret, &pub->asyncDev, WC_ASYNC_FLAG_NONE);
  26794. #endif
  26795. if (ret != 0)
  26796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26797. TEST_SLEEP();
  26798. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26799. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26800. !defined(HAVE_SELFTEST)
  26801. ret = wc_ecc_set_rng(key, rng);
  26802. if (ret != 0)
  26803. goto done;
  26804. #endif
  26805. x = ECC_BUFSIZE;
  26806. do {
  26807. #if defined(WOLFSSL_ASYNC_CRYPT)
  26808. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26809. #endif
  26810. if (ret == 0) {
  26811. ret = wc_ecc_shared_secret(key, pub, exportBuf, &x);
  26812. }
  26813. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26814. wc_ecc_free(pub);
  26815. if (ret != 0)
  26816. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26817. TEST_SLEEP();
  26818. #endif /* HAVE_ECC_DHE && HAVE_ECC_KEY_EXPORT && !WC_NO_RNG */
  26819. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26820. ret = 0;
  26821. done:
  26822. wc_ecc_del_point_h(pubPoint, HEAP_HINT);
  26823. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26824. if (key != NULL) {
  26825. wc_ecc_free(key);
  26826. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26827. }
  26828. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26829. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26830. #endif
  26831. XFREE(exportBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26832. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26833. #else
  26834. wc_ecc_free(key);
  26835. #endif
  26836. return ret;
  26837. }
  26838. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26839. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26840. static wc_test_ret_t ecc_test_key_decode(WC_RNG* rng, int keySize)
  26841. {
  26842. wc_test_ret_t ret;
  26843. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26844. ecc_key *eccKey = (ecc_key *)XMALLOC(sizeof *eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26845. byte *tmpBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26846. #else
  26847. ecc_key eccKey[1];
  26848. byte tmpBuf[ECC_BUFSIZE];
  26849. #endif
  26850. word32 tmpSz;
  26851. word32 idx;
  26852. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26853. if ((eccKey == NULL) || (tmpBuf == NULL))
  26854. ERROR_OUT(MEMORY_E, done);
  26855. #endif
  26856. ret = wc_ecc_init(eccKey);
  26857. if (ret != 0) {
  26858. goto done;
  26859. }
  26860. ret = wc_ecc_make_key(rng, keySize, eccKey);
  26861. #if defined(WOLFSSL_ASYNC_CRYPT)
  26862. ret = wc_AsyncWait(ret, &eccKey->asyncDev, WC_ASYNC_FLAG_NONE);
  26863. #endif
  26864. if (ret != 0) {
  26865. goto done;
  26866. }
  26867. tmpSz = ECC_BUFSIZE;
  26868. ret = wc_EccKeyToDer(eccKey, tmpBuf, tmpSz);
  26869. wc_ecc_free(eccKey);
  26870. if (ret < 0) {
  26871. goto done;
  26872. }
  26873. tmpSz = (word32)ret;
  26874. ret = wc_ecc_init(eccKey);
  26875. if (ret != 0) {
  26876. goto done;
  26877. }
  26878. idx = 0;
  26879. ret = wc_EccPrivateKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26880. if (ret != 0) {
  26881. goto done;
  26882. }
  26883. wc_ecc_free(eccKey);
  26884. ret = wc_ecc_init(eccKey);
  26885. if (ret != 0) {
  26886. goto done;
  26887. }
  26888. idx = 0;
  26889. ret = wc_EccPublicKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26890. if (ret != 0) {
  26891. goto done;
  26892. }
  26893. ret = 0;
  26894. done:
  26895. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26896. if (eccKey != NULL) {
  26897. wc_ecc_free(eccKey);
  26898. XFREE(eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26899. }
  26900. XFREE(tmpBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26901. #else
  26902. wc_ecc_free(eccKey);
  26903. #endif
  26904. return ret;
  26905. }
  26906. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26907. #endif /* HAVE_ECC_KEY_IMPORT */
  26908. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26909. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26910. static wc_test_ret_t ecc_test_key_gen(WC_RNG* rng, int keySize)
  26911. {
  26912. wc_test_ret_t ret = 0;
  26913. int derSz;
  26914. #ifdef HAVE_PKCS8
  26915. word32 pkcs8Sz;
  26916. #endif
  26917. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26918. byte *der = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26919. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26920. #else
  26921. byte der[ECC_BUFSIZE];
  26922. ecc_key userA[1];
  26923. #endif
  26924. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26925. if ((der == NULL) || (userA == NULL))
  26926. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26927. #endif
  26928. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  26929. if (ret != 0)
  26930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26931. ret = wc_ecc_make_key(rng, keySize, userA);
  26932. #if defined(WOLFSSL_ASYNC_CRYPT)
  26933. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  26934. #endif
  26935. if (ret != 0)
  26936. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26937. TEST_SLEEP();
  26938. ret = wc_ecc_check_key(userA);
  26939. if (ret != 0)
  26940. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26941. TEST_SLEEP();
  26942. derSz = wc_EccKeyToDer(userA, der, ECC_BUFSIZE);
  26943. if (derSz < 0) {
  26944. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  26945. }
  26946. ret = SaveDerAndPem(der, derSz, eccCaKeyTempFile, eccCaKeyPemFile,
  26947. ECC_PRIVATEKEY_TYPE);
  26948. if (ret != 0)
  26949. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26950. /* test export of public key */
  26951. derSz = wc_EccPublicKeyToDer(userA, der, ECC_BUFSIZE, 1);
  26952. if (derSz < 0) {
  26953. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  26954. }
  26955. if (derSz == 0) {
  26956. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26957. }
  26958. #ifdef HAVE_COMP_KEY
  26959. /* test export of compressed public key */
  26960. derSz = wc_EccPublicKeyToDer_ex(userA, der, ECC_BUFSIZE, 1, 1);
  26961. if (derSz < 0) {
  26962. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  26963. }
  26964. if (derSz == 0) {
  26965. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26966. }
  26967. #endif
  26968. ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0);
  26969. if (ret != 0)
  26970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26971. #ifdef HAVE_PKCS8
  26972. /* test export of PKCS#8 unencrypted private key */
  26973. pkcs8Sz = FOURK_BUF;
  26974. derSz = wc_EccPrivateKeyToPKCS8(userA, der, &pkcs8Sz);
  26975. if (derSz < 0) {
  26976. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  26977. }
  26978. if (derSz == 0) {
  26979. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26980. }
  26981. ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0);
  26982. if (ret != 0) {
  26983. goto done;
  26984. }
  26985. #endif /* HAVE_PKCS8 */
  26986. done:
  26987. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26988. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26989. if (userA != NULL) {
  26990. wc_ecc_free(userA);
  26991. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26992. }
  26993. #else
  26994. wc_ecc_free(userA);
  26995. #endif
  26996. return ret;
  26997. }
  26998. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26999. static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
  27000. int curve_id, const ecc_set_type* dp)
  27001. {
  27002. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27003. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27004. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27005. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27006. word32 y;
  27007. #endif
  27008. #ifdef HAVE_ECC_KEY_EXPORT
  27009. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  27010. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27011. #endif
  27012. word32 x = 0;
  27013. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27014. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27015. defined(HAVE_ECC_SIGN)
  27016. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27017. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27018. int i;
  27019. #ifdef HAVE_ECC_VERIFY
  27020. int verify;
  27021. #endif /* HAVE_ECC_VERIFY */
  27022. #endif /* HAVE_ECC_SIGN */
  27023. wc_test_ret_t ret;
  27024. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27025. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27026. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27027. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27028. #else
  27029. ecc_key userA[1];
  27030. ecc_key userB[1];
  27031. ecc_key pubKey[1];
  27032. #endif
  27033. #ifndef WC_NO_RNG
  27034. int curveSize;
  27035. #endif
  27036. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27037. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27038. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27039. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27040. #endif
  27041. #ifdef HAVE_ECC_KEY_EXPORT
  27042. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27043. #endif
  27044. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27045. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27046. defined(HAVE_ECC_SIGN)
  27047. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27048. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27049. #endif
  27050. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  27051. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \
  27052. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27053. if (sharedA == NULL || sharedB == NULL)
  27054. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27055. #endif
  27056. #ifdef HAVE_ECC_KEY_EXPORT
  27057. if (exportBuf == NULL)
  27058. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27059. #endif
  27060. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27061. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27062. defined(HAVE_ECC_SIGN)
  27063. if (sig == NULL || digest == NULL)
  27064. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27065. #endif
  27066. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  27067. (void)testVerifyCount;
  27068. (void)dp;
  27069. (void)x;
  27070. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27071. if ((userA == NULL) ||
  27072. (userB == NULL) ||
  27073. (pubKey == NULL))
  27074. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27075. #endif
  27076. XMEMSET(userA, 0, sizeof *userA);
  27077. XMEMSET(userB, 0, sizeof *userB);
  27078. XMEMSET(pubKey, 0, sizeof *pubKey);
  27079. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27080. if (ret != 0)
  27081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27082. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  27083. if (ret != 0)
  27084. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27085. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27086. if (ret != 0)
  27087. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27088. #ifdef WOLFSSL_CUSTOM_CURVES
  27089. if (dp != NULL) {
  27090. ret = wc_ecc_set_custom_curve(userA, dp);
  27091. if (ret != 0)
  27092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27093. ret = wc_ecc_set_custom_curve(userB, dp);
  27094. if (ret != 0)
  27095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27096. }
  27097. #endif
  27098. #ifndef WC_NO_RNG
  27099. ret = wc_ecc_make_key_ex(rng, keySize, userA, curve_id);
  27100. #if defined(WOLFSSL_ASYNC_CRYPT)
  27101. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27102. #endif
  27103. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  27104. if (ret == WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  27105. ret = 0;
  27106. goto done; /* no software case */
  27107. }
  27108. #endif
  27109. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  27110. goto done; /* catch case, where curve is not supported */
  27111. if (ret != 0)
  27112. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27113. TEST_SLEEP();
  27114. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  27115. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  27116. if (curveSize != userA->dp->size)
  27117. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27118. }
  27119. ret = wc_ecc_check_key(userA);
  27120. if (ret != 0)
  27121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27122. TEST_SLEEP();
  27123. /* ATECC508/608 configuration may not support more than one ECDH key */
  27124. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27125. ret = wc_ecc_make_key_ex(rng, keySize, userB, curve_id);
  27126. #if defined(WOLFSSL_ASYNC_CRYPT)
  27127. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  27128. #endif
  27129. if (ret != 0)
  27130. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27131. TEST_SLEEP();
  27132. /* only perform the below tests if the key size matches */
  27133. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  27134. /* Not an error, just not a key size match */
  27135. WARNING_OUT(ECC_CURVE_OID_E, done);
  27136. #ifdef HAVE_ECC_DHE
  27137. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27138. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27139. !defined(HAVE_SELFTEST)
  27140. ret = wc_ecc_set_rng(userA, rng);
  27141. if (ret != 0)
  27142. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27143. ret = wc_ecc_set_rng(userB, rng);
  27144. if (ret != 0)
  27145. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27146. #endif
  27147. x = ECC_SHARED_SIZE;
  27148. do {
  27149. #if defined(WOLFSSL_ASYNC_CRYPT)
  27150. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27151. #endif
  27152. if (ret == 0)
  27153. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27154. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27155. if (ret != 0)
  27156. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27157. TEST_SLEEP();
  27158. y = ECC_SHARED_SIZE;
  27159. do {
  27160. #if defined(WOLFSSL_ASYNC_CRYPT)
  27161. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27162. #endif
  27163. if (ret == 0)
  27164. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27165. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27166. if (ret != 0)
  27167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27168. if (y != x)
  27169. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27170. if (XMEMCMP(sharedA, sharedB, x))
  27171. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27172. TEST_SLEEP();
  27173. #ifdef HAVE_ECC_CDH
  27174. /* add cofactor flag */
  27175. wc_ecc_set_flags(userA, WC_ECC_FLAG_COFACTOR);
  27176. wc_ecc_set_flags(userB, WC_ECC_FLAG_COFACTOR);
  27177. x = ECC_SHARED_SIZE;
  27178. do {
  27179. #if defined(WOLFSSL_ASYNC_CRYPT)
  27180. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27181. #endif
  27182. if (ret == 0)
  27183. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27184. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27185. if (ret != 0)
  27186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27187. TEST_SLEEP();
  27188. y = ECC_SHARED_SIZE;
  27189. do {
  27190. #if defined(WOLFSSL_ASYNC_CRYPT)
  27191. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27192. #endif
  27193. if (ret == 0)
  27194. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27195. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27196. if (ret != 0)
  27197. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27198. if (y != x)
  27199. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27200. if (XMEMCMP(sharedA, sharedB, x))
  27201. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27202. TEST_SLEEP();
  27203. /* remove cofactor flag */
  27204. wc_ecc_set_flags(userA, 0);
  27205. wc_ecc_set_flags(userB, 0);
  27206. #endif /* HAVE_ECC_CDH */
  27207. #endif /* HAVE_ECC_DHE */
  27208. #endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */
  27209. #ifdef HAVE_ECC_KEY_EXPORT
  27210. x = ECC_KEY_EXPORT_BUF_SIZE;
  27211. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  27212. if (ret != 0)
  27213. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27214. #ifdef HAVE_ECC_KEY_IMPORT
  27215. #ifdef WOLFSSL_CUSTOM_CURVES
  27216. if (dp != NULL) {
  27217. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27218. if (ret != 0)
  27219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27220. }
  27221. #endif
  27222. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27223. if (ret != 0)
  27224. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27225. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27226. #ifdef HAVE_ECC_DHE
  27227. y = ECC_SHARED_SIZE;
  27228. do {
  27229. #if defined(WOLFSSL_ASYNC_CRYPT)
  27230. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27231. #endif
  27232. if (ret == 0)
  27233. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27234. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27235. if (ret != 0)
  27236. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27237. if (XMEMCMP(sharedA, sharedB, y))
  27238. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27239. TEST_SLEEP();
  27240. #endif /* HAVE_ECC_DHE */
  27241. #ifdef HAVE_COMP_KEY
  27242. /* try compressed export / import too */
  27243. x = ECC_KEY_EXPORT_BUF_SIZE;
  27244. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  27245. if (ret != 0)
  27246. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27247. wc_ecc_free(pubKey);
  27248. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27249. if (ret != 0)
  27250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27251. #ifdef WOLFSSL_CUSTOM_CURVES
  27252. if (dp != NULL) {
  27253. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27254. if (ret != 0)
  27255. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27256. }
  27257. #endif
  27258. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27259. if (ret != 0)
  27260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27261. #ifdef HAVE_ECC_DHE
  27262. y = ECC_SHARED_SIZE;
  27263. do {
  27264. #if defined(WOLFSSL_ASYNC_CRYPT)
  27265. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27266. #endif
  27267. if (ret == 0)
  27268. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27269. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27270. if (ret != 0)
  27271. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27272. if (XMEMCMP(sharedA, sharedB, y))
  27273. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27274. TEST_SLEEP();
  27275. #endif /* HAVE_ECC_DHE */
  27276. #endif /* HAVE_COMP_KEY */
  27277. #endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A */
  27278. #endif /* !WC_NO_RNG */
  27279. #endif /* HAVE_ECC_KEY_IMPORT */
  27280. #endif /* HAVE_ECC_KEY_EXPORT */
  27281. /* For KCAPI cannot sign using generated ECDH key */
  27282. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27283. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC))
  27284. #ifdef HAVE_ECC_SIGN
  27285. /* ECC w/out Shamir has issue with all 0 digest */
  27286. /* WC_BIGINT doesn't have 0 len well on hardware */
  27287. /* Cryptocell has issues with all 0 digest */
  27288. #if defined(ECC_SHAMIR) && !defined(WOLFSSL_ASYNC_CRYPT) && \
  27289. !defined(WOLFSSL_CRYPTOCELL)
  27290. /* test DSA sign hash with zeros */
  27291. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27292. digest[i] = 0;
  27293. }
  27294. x = ECC_SIG_SIZE;
  27295. do {
  27296. #if defined(WOLFSSL_ASYNC_CRYPT)
  27297. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27298. #endif
  27299. if (ret == 0)
  27300. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng,
  27301. userA);
  27302. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27303. if (ret != 0)
  27304. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27305. TEST_SLEEP();
  27306. #ifdef HAVE_ECC_VERIFY
  27307. for (i=0; i<testVerifyCount; i++) {
  27308. verify = 0;
  27309. do {
  27310. #if defined(WOLFSSL_ASYNC_CRYPT)
  27311. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27312. #endif
  27313. if (ret == 0)
  27314. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE,
  27315. &verify, userA);
  27316. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27317. if (ret != 0)
  27318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27319. if (verify != 1)
  27320. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27321. TEST_SLEEP();
  27322. }
  27323. #endif /* HAVE_ECC_VERIFY */
  27324. #endif /* ECC_SHAMIR && !WOLFSSL_ASYNC_CRYPT && !WOLFSSL_CRYPTOCELL */
  27325. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  27326. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27327. digest[i] = (byte)i;
  27328. }
  27329. x = ECC_SIG_SIZE;
  27330. do {
  27331. #if defined(WOLFSSL_ASYNC_CRYPT)
  27332. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27333. #endif
  27334. if (ret == 0)
  27335. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  27336. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27337. if (ret != 0)
  27338. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27339. TEST_SLEEP();
  27340. #ifdef HAVE_ECC_VERIFY
  27341. for (i=0; i<testVerifyCount; i++) {
  27342. verify = 0;
  27343. do {
  27344. #if defined(WOLFSSL_ASYNC_CRYPT)
  27345. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27346. #endif
  27347. if (ret == 0)
  27348. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, userA);
  27349. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27350. if (ret != 0)
  27351. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27352. if (verify != 1)
  27353. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27354. TEST_SLEEP();
  27355. }
  27356. #endif /* HAVE_ECC_VERIFY */
  27357. #endif /* HAVE_ECC_SIGN */
  27358. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT &&
  27359. * !WC_NO_RNG && !WOLFSSL_KCAPI_ECC) */
  27360. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  27361. !defined(WOLFSSL_ATECC508) && !defined(WOLFSSL_ATECC608A) && \
  27362. !defined(WOLFSSL_KCAPI_ECC)
  27363. x = ECC_KEY_EXPORT_BUF_SIZE;
  27364. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  27365. if (ret != 0)
  27366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27367. #elif defined(HAVE_ECC_KEY_EXPORT)
  27368. (void)exportBuf;
  27369. #endif /* HAVE_ECC_KEY_EXPORT */
  27370. done:
  27371. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27372. if (userA != NULL) {
  27373. wc_ecc_free(userA);
  27374. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27375. }
  27376. if (userB != NULL) {
  27377. wc_ecc_free(userB);
  27378. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27379. }
  27380. if (pubKey != NULL) {
  27381. wc_ecc_free(pubKey);
  27382. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27383. }
  27384. #else
  27385. wc_ecc_free(pubKey);
  27386. wc_ecc_free(userB);
  27387. wc_ecc_free(userA);
  27388. #endif
  27389. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  27390. WC_FREE_VAR(sharedA, HEAP_HINT);
  27391. WC_FREE_VAR(sharedB, HEAP_HINT);
  27392. #endif
  27393. #ifdef HAVE_ECC_KEY_EXPORT
  27394. WC_FREE_VAR(exportBuf, HEAP_HINT);
  27395. #endif
  27396. #ifdef HAVE_ECC_SIGN
  27397. WC_FREE_VAR(sig, HEAP_HINT);
  27398. WC_FREE_VAR(digest, HEAP_HINT);
  27399. #endif
  27400. (void)keySize;
  27401. (void)curve_id;
  27402. (void)rng;
  27403. return ret;
  27404. }
  27405. #undef ECC_TEST_VERIFY_COUNT
  27406. #define ECC_TEST_VERIFY_COUNT 2
  27407. static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
  27408. {
  27409. wc_test_ret_t ret;
  27410. WOLFSSL_MSG_EX("ecc_test_curve keySize = %d", keySize);
  27411. #if FIPS_VERSION3_GE(6,0,0)
  27412. #ifdef DEBUG_WOLFSSL
  27413. printf("keySize is %d\n", keySize);
  27414. #endif
  27415. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27416. goto skip_A;
  27417. }
  27418. #endif
  27419. ret = ecc_test_curve_size(rng, keySize, ECC_TEST_VERIFY_COUNT, curve_id,
  27420. NULL);
  27421. if (ret < 0) {
  27422. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27423. /* ignore error for curves not found */
  27424. /* some curve sizes are only available with:
  27425. HAVE_ECC_SECPR2, HAVE_ECC_SECPR3, HAVE_ECC_BRAINPOOL
  27426. and HAVE_ECC_KOBLITZ */
  27427. }
  27428. else {
  27429. printf("ecc_test_curve_size %d failed!\n", keySize);
  27430. return ret;
  27431. }
  27432. }
  27433. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27434. #if FIPS_VERSION3_GE(6,0,0)
  27435. skip_A:
  27436. #endif
  27437. #ifdef HAVE_ECC_VECTOR_TEST
  27438. ret = ecc_test_vector(keySize);
  27439. if (ret < 0) {
  27440. printf("ecc_test_vector %d failed!\n", keySize);
  27441. return ret;
  27442. }
  27443. #endif
  27444. #if FIPS_VERSION3_GE(6,0,0)
  27445. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27446. goto skip_B;
  27447. }
  27448. #endif
  27449. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27450. !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27451. ret = ecc_test_key_decode(rng, keySize);
  27452. if (ret < 0) {
  27453. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27454. /* ignore error for curves not found */
  27455. }
  27456. else {
  27457. printf("ecc_test_key_decode %d failed!\n", keySize);
  27458. return ret;
  27459. }
  27460. }
  27461. #endif
  27462. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27463. ret = ecc_test_key_gen(rng, keySize);
  27464. if (ret < 0) {
  27465. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27466. /* ignore error for curves not found */
  27467. }
  27468. else {
  27469. printf("ecc_test_key_gen %d failed!\n", keySize);
  27470. return ret;
  27471. }
  27472. }
  27473. #endif
  27474. #if FIPS_VERSION3_GE(6,0,0)
  27475. skip_B:
  27476. #endif
  27477. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  27478. return 0;
  27479. }
  27480. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  27481. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  27482. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27483. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27484. static wc_test_ret_t ecc_point_test(void)
  27485. {
  27486. wc_test_ret_t ret;
  27487. ecc_point* point;
  27488. ecc_point* point2;
  27489. #ifdef HAVE_COMP_KEY
  27490. ecc_point* point3;
  27491. ecc_point* point4;
  27492. #endif
  27493. word32 outLen;
  27494. byte out[65];
  27495. byte der[] = { 0x04, /* = Uncompressed */
  27496. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27497. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27498. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27499. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27500. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27501. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27502. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27503. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27504. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27505. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27506. byte derComp0[] = { 0x02, /* = Compressed, y even */
  27507. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27508. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27509. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27510. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27511. byte derComp1[] = { 0x03, /* = Compressed, y odd */
  27512. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27513. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27514. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27515. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27516. #endif
  27517. byte altDer[] = { 0x04, /* = Uncompressed */
  27518. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27519. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27520. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27521. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27522. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27523. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27524. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27525. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  27526. int curve_idx = wc_ecc_get_curve_idx(ECC_SECP256R1);
  27527. /* if curve P256 is not enabled then test should not fail */
  27528. if (curve_idx == ECC_CURVE_INVALID)
  27529. return 0;
  27530. outLen = sizeof(out);
  27531. point = wc_ecc_new_point();
  27532. if (point == NULL)
  27533. return WC_TEST_RET_ENC_ERRNO;
  27534. point2 = wc_ecc_new_point();
  27535. if (point2 == NULL) {
  27536. wc_ecc_del_point(point);
  27537. return WC_TEST_RET_ENC_NC;
  27538. }
  27539. #ifdef HAVE_COMP_KEY
  27540. point3 = wc_ecc_new_point();
  27541. if (point3 == NULL) {
  27542. wc_ecc_del_point(point2);
  27543. wc_ecc_del_point(point);
  27544. return WC_TEST_RET_ENC_NC;
  27545. }
  27546. point4 = wc_ecc_new_point();
  27547. if (point4 == NULL) {
  27548. wc_ecc_del_point(point3);
  27549. wc_ecc_del_point(point2);
  27550. wc_ecc_del_point(point);
  27551. return WC_TEST_RET_ENC_NC;
  27552. }
  27553. #endif
  27554. /* Parameter Validation testing. */
  27555. wc_ecc_del_point(NULL);
  27556. ret = wc_ecc_import_point_der(NULL, sizeof(der), curve_idx, point);
  27557. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27558. ret = WC_TEST_RET_ENC_EC(ret);
  27559. goto done;
  27560. }
  27561. ret = wc_ecc_import_point_der(der, sizeof(der), ECC_CURVE_INVALID, point);
  27562. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27563. ret = WC_TEST_RET_ENC_EC(ret);
  27564. goto done;
  27565. }
  27566. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, NULL);
  27567. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27568. ret = WC_TEST_RET_ENC_EC(ret);
  27569. goto done;
  27570. }
  27571. ret = wc_ecc_export_point_der(-1, point, out, &outLen);
  27572. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27573. ret = WC_TEST_RET_ENC_EC(ret);
  27574. goto done;
  27575. }
  27576. ret = wc_ecc_export_point_der(curve_idx, NULL, out, &outLen);
  27577. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27578. ret = WC_TEST_RET_ENC_EC(ret);
  27579. goto done;
  27580. }
  27581. ret = wc_ecc_export_point_der(curve_idx, point, NULL, &outLen);
  27582. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || outLen != sizeof(out)) {
  27583. ret = WC_TEST_RET_ENC_EC(ret);
  27584. goto done;
  27585. }
  27586. ret = wc_ecc_export_point_der(curve_idx, point, out, NULL);
  27587. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27588. ret = WC_TEST_RET_ENC_EC(ret);
  27589. goto done;
  27590. }
  27591. outLen = 0;
  27592. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27593. if (ret != WC_NO_ERR_TRACE(BUFFER_E)) {
  27594. ret = WC_TEST_RET_ENC_EC(ret);
  27595. goto done;
  27596. }
  27597. ret = wc_ecc_copy_point(NULL, NULL);
  27598. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27599. ret = WC_TEST_RET_ENC_EC(ret);
  27600. goto done;
  27601. }
  27602. ret = wc_ecc_copy_point(NULL, point2);
  27603. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27604. ret = WC_TEST_RET_ENC_EC(ret);
  27605. goto done;
  27606. }
  27607. ret = wc_ecc_copy_point(point, NULL);
  27608. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27609. ret = WC_TEST_RET_ENC_EC(ret);
  27610. goto done;
  27611. }
  27612. ret = wc_ecc_cmp_point(NULL, NULL);
  27613. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27614. ret = WC_TEST_RET_ENC_EC(ret);
  27615. goto done;
  27616. }
  27617. ret = wc_ecc_cmp_point(NULL, point2);
  27618. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27619. ret = WC_TEST_RET_ENC_EC(ret);
  27620. goto done;
  27621. }
  27622. ret = wc_ecc_cmp_point(point, NULL);
  27623. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27624. ret = WC_TEST_RET_ENC_EC(ret);
  27625. goto done;
  27626. }
  27627. /* Use API. */
  27628. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, point);
  27629. if (ret != 0)
  27630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27631. outLen = sizeof(out);
  27632. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27633. if (ret != 0)
  27634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27635. if (outLen != sizeof(der)) {
  27636. ret = WC_TEST_RET_ENC_NC;
  27637. goto done;
  27638. }
  27639. if (XMEMCMP(out, der, outLen) != 0) {
  27640. ret = WC_TEST_RET_ENC_NC;
  27641. goto done;
  27642. }
  27643. ret = wc_ecc_copy_point(point2, point);
  27644. if (ret != MP_OKAY) {
  27645. ret = WC_TEST_RET_ENC_EC(ret);
  27646. goto done;
  27647. }
  27648. ret = wc_ecc_cmp_point(point2, point);
  27649. if (ret != MP_EQ) {
  27650. ret = WC_TEST_RET_ENC_EC(ret);
  27651. goto done;
  27652. }
  27653. ret = wc_ecc_import_point_der(altDer, sizeof(altDer), curve_idx, point2);
  27654. if (ret != 0)
  27655. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27656. ret = wc_ecc_cmp_point(point2, point);
  27657. if (ret != MP_GT) {
  27658. ret = WC_TEST_RET_ENC_EC(ret);
  27659. goto done;
  27660. }
  27661. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27662. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27663. ret = wc_ecc_import_point_der(derComp0, sizeof(derComp0)*2-1, curve_idx, point3);
  27664. if (ret != 0)
  27665. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27666. ret = wc_ecc_import_point_der_ex(derComp0, sizeof(derComp0), curve_idx, point4, 0);
  27667. if (ret != 0)
  27668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27669. ret = wc_ecc_cmp_point(point3, point4);
  27670. if (ret != MP_EQ) {
  27671. ret = WC_TEST_RET_ENC_EC(ret);
  27672. goto done;
  27673. }
  27674. ret = wc_ecc_import_point_der(derComp1, sizeof(derComp1)*2-1, curve_idx, point3);
  27675. if (ret != 0)
  27676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27677. ret = wc_ecc_import_point_der_ex(derComp1, sizeof(derComp1), curve_idx, point4, 0);
  27678. if (ret != 0)
  27679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27680. ret = wc_ecc_cmp_point(point3, point4);
  27681. if (ret != MP_EQ) {
  27682. ret = WC_TEST_RET_ENC_EC(ret);
  27683. goto done;
  27684. }
  27685. #endif
  27686. done:
  27687. #ifdef HAVE_COMP_KEY
  27688. wc_ecc_del_point(point4);
  27689. wc_ecc_del_point(point3);
  27690. #endif
  27691. wc_ecc_del_point(point2);
  27692. wc_ecc_del_point(point);
  27693. return ret;
  27694. }
  27695. #endif /* !WOLFSSL_ATECC508A && HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27696. #if !defined(NO_SIG_WRAPPER) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27697. static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key)
  27698. {
  27699. wc_test_ret_t ret;
  27700. word32 sigSz;
  27701. int size;
  27702. byte out[ECC_MAX_SIG_SIZE];
  27703. byte in[] = TEST_STRING;
  27704. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  27705. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  27706. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  27707. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  27708. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  27709. };
  27710. word32 inLen = (word32)XSTRLEN((char*)in);
  27711. size = wc_ecc_sig_size(key);
  27712. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, sizeof(*key));
  27713. if (ret != size)
  27714. return WC_TEST_RET_ENC_NC;
  27715. sigSz = (word32)ret;
  27716. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27717. inLen, out, &sigSz, key, sizeof(*key), rng);
  27718. if (ret != 0)
  27719. return WC_TEST_RET_ENC_EC(ret);
  27720. TEST_SLEEP();
  27721. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27722. inLen, out, sigSz, key, sizeof(*key));
  27723. if (ret != 0)
  27724. return WC_TEST_RET_ENC_EC(ret);
  27725. TEST_SLEEP();
  27726. sigSz = (word32)sizeof(out);
  27727. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27728. hash, (int)sizeof(hash), out, &sigSz, key, sizeof(*key), rng);
  27729. if (ret != 0)
  27730. return WC_TEST_RET_ENC_EC(ret);
  27731. TEST_SLEEP();
  27732. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27733. hash, (int)sizeof(hash), out, sigSz, key, sizeof(*key));
  27734. if (ret != 0)
  27735. return WC_TEST_RET_ENC_EC(ret);
  27736. TEST_SLEEP();
  27737. return 0;
  27738. }
  27739. #endif
  27740. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27741. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27742. static wc_test_ret_t ecc_exp_imp_test(ecc_key* key)
  27743. {
  27744. wc_test_ret_t ret;
  27745. int curve_id;
  27746. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27747. ecc_key *keyImp = (ecc_key *)XMALLOC(sizeof *keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27748. #else
  27749. ecc_key keyImp[1];
  27750. #endif
  27751. byte priv[32];
  27752. word32 privLen;
  27753. byte pub[65*2];
  27754. word32 pubLen, pubLenX, pubLenY;
  27755. const char qx[] = "7a4e287890a1a47ad3457e52f2f76a83"
  27756. "ce46cbc947616d0cbaa82323818a793d";
  27757. const char qy[] = "eec4084f5b29ebf29c44cce3b3059610"
  27758. "922f8b30ea6e8811742ac7238fe87308";
  27759. const char d[] = "8c14b793cb19137e323a6d2e2a870bca"
  27760. "2e7a493ec1153b3a95feb8a4873f8d08";
  27761. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27762. if (keyImp == NULL)
  27763. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27764. #endif
  27765. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27766. privLen = sizeof(priv);
  27767. ret = wc_ecc_export_private_only(key, priv, &privLen);
  27768. if (ret != 0)
  27769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27770. pubLen = sizeof(pub);
  27771. ret = wc_ecc_export_point_der(key->idx, &key->pubkey, pub, &pubLen);
  27772. if (ret != 0)
  27773. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27774. ret = wc_ecc_import_private_key(priv, privLen, pub, pubLen, keyImp);
  27775. if (ret != 0)
  27776. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27777. wc_ecc_free(keyImp);
  27778. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27779. ret = wc_ecc_import_raw_ex(keyImp, qx, qy, d, ECC_SECP256R1);
  27780. if (ret != 0)
  27781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27782. wc_ecc_free(keyImp);
  27783. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27784. curve_id = wc_ecc_get_curve_id(key->idx);
  27785. if (curve_id < 0) {
  27786. ret = WC_TEST_RET_ENC_EC(curve_id);
  27787. goto done;
  27788. }
  27789. /* test import private only */
  27790. ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, keyImp,
  27791. curve_id);
  27792. if (ret != 0)
  27793. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27794. wc_ecc_free(keyImp);
  27795. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27796. /* test export public raw */
  27797. pubLenX = pubLenY = 32;
  27798. ret = wc_ecc_export_public_raw(key, pub, &pubLenX, &pub[32], &pubLenY);
  27799. if (ret != 0)
  27800. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27801. #ifndef HAVE_SELFTEST
  27802. /* test import of public */
  27803. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], NULL, ECC_SECP256R1);
  27804. if (ret != 0)
  27805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27806. #endif
  27807. wc_ecc_free(keyImp);
  27808. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27809. /* test export private and public raw */
  27810. pubLenX = pubLenY = privLen = 32;
  27811. ret = wc_ecc_export_private_raw(key, pub, &pubLenX, &pub[32], &pubLenY,
  27812. priv, &privLen);
  27813. if (ret != 0)
  27814. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27815. #ifndef HAVE_SELFTEST
  27816. /* test import of private and public */
  27817. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], priv, ECC_SECP256R1);
  27818. if (ret != 0)
  27819. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27820. #endif
  27821. done:
  27822. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27823. if (keyImp != NULL) {
  27824. wc_ecc_free(keyImp);
  27825. XFREE(keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27826. }
  27827. #else
  27828. wc_ecc_free(keyImp);
  27829. #endif
  27830. return ret;
  27831. }
  27832. #endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27833. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  27834. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27835. static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
  27836. {
  27837. wc_test_ret_t ret;
  27838. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27839. ecc_key *key2 = (ecc_key *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27840. ecc_key *key3 = (ecc_key *)XMALLOC(sizeof *key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27841. #else
  27842. ecc_key key2[1];
  27843. ecc_key key3[1];
  27844. #endif
  27845. #ifdef WOLFSSL_PUBLIC_MP
  27846. mp_int* priv;
  27847. #endif
  27848. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27849. if ((key2 == NULL) || (key3 == NULL))
  27850. ERROR_OUT(MEMORY_E, done);
  27851. #endif
  27852. wc_ecc_init_ex(key2, HEAP_HINT, devId);
  27853. wc_ecc_init_ex(key3, HEAP_HINT, devId);
  27854. /* TODO: Use test data, test with WOLFSSL_VALIDATE_ECC_IMPORT. */
  27855. /* Need base point (Gx,Gy) and parameter A - load them as the public and
  27856. * private key in key2.
  27857. */
  27858. ret = wc_ecc_import_raw_ex(key2, key1->dp->Gx, key1->dp->Gy, key1->dp->Af,
  27859. ECC_SECP256R1);
  27860. if (ret != 0)
  27861. goto done;
  27862. /* Need a point (Gx,Gy) and prime - load them as the public and private key
  27863. * in key3.
  27864. */
  27865. ret = wc_ecc_import_raw_ex(key3, key1->dp->Gx, key1->dp->Gy,
  27866. key1->dp->prime, ECC_SECP256R1);
  27867. if (ret != 0)
  27868. goto done;
  27869. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27870. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27871. 1);
  27872. if (ret != 0)
  27873. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27874. #ifdef WOLFSSL_PUBLIC_MP
  27875. priv = wc_ecc_key_get_priv(key1);
  27876. mp_zero(priv);
  27877. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27878. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27879. 1);
  27880. if (ret != 0)
  27881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27882. if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
  27883. ret = WC_TEST_RET_ENC_EC(ret);
  27884. goto done;
  27885. }
  27886. if (mp_cmp_d(key3->pubkey.z, 1) != MP_EQ) {
  27887. ret = WC_TEST_RET_ENC_EC(ret);
  27888. goto done;
  27889. }
  27890. #endif
  27891. done:
  27892. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27893. if (key2 != NULL) {
  27894. wc_ecc_free(key2);
  27895. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27896. }
  27897. if (key3 != NULL) {
  27898. wc_ecc_free(key3);
  27899. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27900. }
  27901. #else
  27902. wc_ecc_free(key3);
  27903. wc_ecc_free(key2);
  27904. #endif
  27905. return ret;
  27906. }
  27907. #endif
  27908. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27909. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_ATECC508A) && \
  27910. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  27911. !defined(WOLFSSL_CRYPTOCELL)
  27912. static wc_test_ret_t ecc_ssh_test(ecc_key* key, WC_RNG* rng)
  27913. {
  27914. wc_test_ret_t ret;
  27915. byte out[128];
  27916. word32 outLen = sizeof(out);
  27917. /* Parameter Validation testing. */
  27918. ret = wc_ecc_shared_secret_ssh(NULL, &key->pubkey, out, &outLen);
  27919. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  27920. return WC_TEST_RET_ENC_EC(ret);
  27921. ret = wc_ecc_shared_secret_ssh(key, NULL, out, &outLen);
  27922. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  27923. return WC_TEST_RET_ENC_EC(ret);
  27924. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, NULL, &outLen);
  27925. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  27926. return WC_TEST_RET_ENC_EC(ret);
  27927. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, NULL);
  27928. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  27929. return WC_TEST_RET_ENC_EC(ret);
  27930. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27931. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27932. !defined(HAVE_SELFTEST)
  27933. ret = wc_ecc_set_rng(key, rng);
  27934. if (ret != 0)
  27935. return WC_TEST_RET_ENC_EC(ret);
  27936. #else
  27937. (void)rng;
  27938. #endif
  27939. /* Use API. */
  27940. ret = 0;
  27941. do {
  27942. #if defined(WOLFSSL_ASYNC_CRYPT)
  27943. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27944. #endif
  27945. if (ret == 0)
  27946. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen);
  27947. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27948. if (ret != 0)
  27949. return WC_TEST_RET_ENC_EC(ret);
  27950. TEST_SLEEP();
  27951. return 0;
  27952. }
  27953. #endif /* HAVE_ECC_DHE && !WC_NO_RNG */
  27954. static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
  27955. {
  27956. wc_test_ret_t ret;
  27957. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27958. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27959. #else
  27960. ecc_key key[1];
  27961. #endif
  27962. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  27963. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  27964. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  27965. word32 idx = 0;
  27966. #endif
  27967. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27968. if (key == NULL)
  27969. ERROR_OUT(MEMORY_E, done);
  27970. #endif
  27971. wc_ecc_init_ex(key, HEAP_HINT, devId);
  27972. /* Use API */
  27973. ret = wc_ecc_set_flags(NULL, 0);
  27974. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27975. ret = WC_TEST_RET_ENC_EC(ret);
  27976. goto done;
  27977. }
  27978. ret = wc_ecc_set_flags(key, 0);
  27979. if (ret != 0)
  27980. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27981. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27982. #ifndef WC_NO_RNG
  27983. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  27984. #if defined(WOLFSSL_ASYNC_CRYPT)
  27985. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  27986. #endif
  27987. if (ret != 0) {
  27988. goto done;
  27989. }
  27990. #ifndef NO_SIG_WRAPPER
  27991. ret = ecc_sig_test(rng, key);
  27992. if (ret < 0)
  27993. goto done;
  27994. #endif
  27995. TEST_SLEEP();
  27996. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_CRYPTOCELL) && \
  27997. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27998. ret = ecc_ssh_test(key, rng);
  27999. if (ret < 0)
  28000. goto done;
  28001. #endif
  28002. wc_ecc_free(key);
  28003. #else
  28004. (void)rng;
  28005. #endif /* !WC_NO_RNG */
  28006. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28007. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28008. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28009. /* Use test ECC key - ensure real private "d" exists */
  28010. #if defined(USE_CERT_BUFFERS_256)
  28011. {
  28012. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  28013. sizeof_ecc_key_der_256);
  28014. }
  28015. #elif !defined(NO_FILESYSTEM)
  28016. {
  28017. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  28018. byte der[128];
  28019. word32 derSz;
  28020. if (!file) {
  28021. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28022. }
  28023. derSz = (word32)XFREAD(der, 1, sizeof(der), file);
  28024. XFCLOSE(file);
  28025. if (derSz == 0)
  28026. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28027. ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
  28028. }
  28029. #else
  28030. {
  28031. (void)idx;
  28032. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
  28033. ERROR_OUT(ASN_PARSE_E, done);
  28034. }
  28035. #endif
  28036. if (ret != 0) {
  28037. goto done;
  28038. }
  28039. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)
  28040. ret = ecc_exp_imp_test(key);
  28041. if (ret < 0)
  28042. goto done;
  28043. #endif
  28044. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  28045. !defined(WOLFSSL_CRYPTOCELL)
  28046. ret = ecc_mulmod_test(key);
  28047. if (ret < 0)
  28048. goto done;
  28049. #endif
  28050. #endif
  28051. #else
  28052. (void)rng;
  28053. (void)idx;
  28054. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  28055. done:
  28056. wc_ecc_free(key);
  28057. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28058. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28059. #endif
  28060. return ret;
  28061. }
  28062. #endif /* !NO_ECC256 || HAVE_ALL_CURVES */
  28063. #if defined(WOLFSSL_CERT_EXT) && \
  28064. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  28065. static wc_test_ret_t ecc_decode_test(void)
  28066. {
  28067. wc_test_ret_t ret;
  28068. word32 inSz;
  28069. word32 inOutIdx;
  28070. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28071. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28072. #else
  28073. ecc_key key[1];
  28074. #endif
  28075. /* SECP256R1 OID: 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 */
  28076. /* This is ecc_clikeypub_der_256. */
  28077. WOLFSSL_SMALL_STACK_STATIC const byte good[] = {
  28078. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  28079. 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  28080. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xbf, 0xf4,
  28081. 0x0f, 0x44, 0x50, 0x9a, 0x3d, 0xce, 0x9b, 0xb7, 0xf0, 0xc5,
  28082. 0x4d, 0xf5, 0x70, 0x7b, 0xd4, 0xec, 0x24, 0x8e, 0x19, 0x80,
  28083. 0xec, 0x5a, 0x4c, 0xa2, 0x24, 0x03, 0x62, 0x2c, 0x9b, 0xda,
  28084. 0xef, 0xa2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xc6, 0x56,
  28085. 0x95, 0x06, 0xcc, 0x01, 0xa9, 0xbd, 0xf6, 0x75, 0x1a, 0x42,
  28086. 0xf7, 0xbd, 0xa9, 0xb2, 0x36, 0x22, 0x5f, 0xc7, 0x5d, 0x7f,
  28087. 0xb4 };
  28088. WOLFSSL_SMALL_STACK_STATIC const byte badNoObjId[] = { 0x30, 0x08, 0x30, 0x06, 0x03, 0x04,
  28089. 0x00, 0x04, 0x01, 0x01 };
  28090. WOLFSSL_SMALL_STACK_STATIC const byte badOneObjId[] = { 0x30, 0x0a, 0x30, 0x08, 0x06, 0x00,
  28091. 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28092. WOLFSSL_SMALL_STACK_STATIC const byte badObjId1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x09,
  28093. 0x06, 0x00, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28094. WOLFSSL_SMALL_STACK_STATIC const byte badObj2d1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
  28095. 0x06, 0x07, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28096. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitStr[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28097. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28098. 0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28099. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrLen[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28100. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28101. 0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
  28102. WOLFSSL_SMALL_STACK_STATIC const byte badNoBitStrZero[] = { 0x30, 0x13, 0x30, 0x0a, 0x06, 0x00,
  28103. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28104. 0x03, 0x03, 0x04, 0x01, 0x01 };
  28105. WOLFSSL_SMALL_STACK_STATIC const byte badPoint[] = { 0x30, 0x12, 0x30, 0x09, 0x06, 0x00,
  28106. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28107. 0x03, 0x03, 0x00, 0x04, 0x01 };
  28108. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28109. if (key == NULL)
  28110. ERROR_OUT(MEMORY_E, done);
  28111. #endif
  28112. XMEMSET(key, 0, sizeof *key);
  28113. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28114. inSz = sizeof(good);
  28115. ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, key, inSz);
  28116. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28117. ret = WC_TEST_RET_ENC_EC(ret);
  28118. goto done;
  28119. }
  28120. ret = wc_EccPublicKeyDecode(good, NULL, key, inSz);
  28121. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28122. ret = WC_TEST_RET_ENC_EC(ret);
  28123. goto done;
  28124. }
  28125. ret = wc_EccPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  28126. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28127. ret = WC_TEST_RET_ENC_EC(ret);
  28128. goto done;
  28129. }
  28130. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, 0);
  28131. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28132. ret = WC_TEST_RET_ENC_EC(ret);
  28133. goto done;
  28134. }
  28135. /* Change offset to produce bad input data. */
  28136. inOutIdx = 2;
  28137. inSz = sizeof(good) - inOutIdx;
  28138. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28139. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28140. ret = WC_TEST_RET_ENC_EC(ret);
  28141. goto done;
  28142. }
  28143. inOutIdx = 4;
  28144. inSz = sizeof(good) - inOutIdx;
  28145. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28146. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28147. ret = WC_TEST_RET_ENC_EC(ret);
  28148. goto done;
  28149. }
  28150. /* Bad data. */
  28151. inSz = sizeof(badNoObjId);
  28152. inOutIdx = 0;
  28153. ret = wc_EccPublicKeyDecode(badNoObjId, &inOutIdx, key, inSz);
  28154. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28155. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28156. {
  28157. ret = WC_TEST_RET_ENC_EC(ret);
  28158. goto done;
  28159. }
  28160. inSz = sizeof(badOneObjId);
  28161. inOutIdx = 0;
  28162. ret = wc_EccPublicKeyDecode(badOneObjId, &inOutIdx, key, inSz);
  28163. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28164. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28165. {
  28166. ret = WC_TEST_RET_ENC_EC(ret);
  28167. goto done;
  28168. }
  28169. inSz = sizeof(badObjId1Len);
  28170. inOutIdx = 0;
  28171. ret = wc_EccPublicKeyDecode(badObjId1Len, &inOutIdx, key, inSz);
  28172. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28173. ret = WC_TEST_RET_ENC_EC(ret);
  28174. goto done;
  28175. }
  28176. inSz = sizeof(badObj2d1Len);
  28177. inOutIdx = 0;
  28178. ret = wc_EccPublicKeyDecode(badObj2d1Len, &inOutIdx, key, inSz);
  28179. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28180. ret = WC_TEST_RET_ENC_EC(ret);
  28181. goto done;
  28182. }
  28183. inSz = sizeof(badNotBitStr);
  28184. inOutIdx = 0;
  28185. ret = wc_EccPublicKeyDecode(badNotBitStr, &inOutIdx, key, inSz);
  28186. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E) &&
  28187. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28188. {
  28189. ret = WC_TEST_RET_ENC_EC(ret);
  28190. goto done;
  28191. }
  28192. inSz = sizeof(badBitStrLen);
  28193. inOutIdx = 0;
  28194. ret = wc_EccPublicKeyDecode(badBitStrLen, &inOutIdx, key, inSz);
  28195. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28196. ret = WC_TEST_RET_ENC_EC(ret);
  28197. goto done;
  28198. }
  28199. inSz = sizeof(badNoBitStrZero);
  28200. inOutIdx = 0;
  28201. ret = wc_EccPublicKeyDecode(badNoBitStrZero, &inOutIdx, key, inSz);
  28202. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  28203. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28204. {
  28205. ret = WC_TEST_RET_ENC_EC(ret);
  28206. goto done;
  28207. }
  28208. inSz = sizeof(badPoint);
  28209. inOutIdx = 0;
  28210. ret = wc_EccPublicKeyDecode(badPoint, &inOutIdx, key, inSz);
  28211. if (ret != WC_NO_ERR_TRACE(ASN_ECC_KEY_E) &&
  28212. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28213. {
  28214. ret = WC_TEST_RET_ENC_EC(ret);
  28215. goto done;
  28216. }
  28217. inSz = sizeof(good);
  28218. inOutIdx = 0;
  28219. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28220. if (ret != 0)
  28221. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28222. done:
  28223. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28224. if (key != NULL) {
  28225. wc_ecc_free(key);
  28226. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28227. }
  28228. #else
  28229. wc_ecc_free(key);
  28230. #endif
  28231. return ret;
  28232. }
  28233. #endif /* WOLFSSL_CERT_EXT */
  28234. #ifdef WOLFSSL_CUSTOM_CURVES
  28235. static const byte eccKeyExplicitCurve[] = {
  28236. 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07,
  28237. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  28238. 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  28239. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  28240. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  28241. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28242. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28243. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  28244. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  28245. 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe,
  28246. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  28247. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  28248. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  28249. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
  28250. 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4,
  28251. 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17,
  28252. 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47,
  28253. 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21,
  28254. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28255. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28256. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  28257. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  28258. 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04,
  28259. 0x3c, 0x4c, 0xc9, 0x5e, 0x2e, 0xa2, 0x3d, 0x49,
  28260. 0xcc, 0x5b, 0xff, 0x4f, 0xc9, 0x2e, 0x1d, 0x4a,
  28261. 0xc6, 0x21, 0xf6, 0xf3, 0xe6, 0x0b, 0x4f, 0xa9,
  28262. 0x9d, 0x74, 0x99, 0xdd, 0x97, 0xc7, 0x6e, 0xbe,
  28263. 0x14, 0x2b, 0x39, 0x9d, 0x63, 0xc7, 0x97, 0x0d,
  28264. 0x45, 0x25, 0x40, 0x30, 0x77, 0x05, 0x76, 0x88,
  28265. 0x38, 0x96, 0x29, 0x7d, 0x9c, 0xe1, 0x50, 0xbe,
  28266. 0xac, 0xf0, 0x1d, 0x86, 0xf4, 0x2f, 0x65, 0x0b
  28267. };
  28268. static wc_test_ret_t ecc_test_custom_curves(WC_RNG* rng)
  28269. {
  28270. wc_test_ret_t ret;
  28271. word32 inOutIdx;
  28272. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28273. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28274. #else
  28275. ecc_key key[1];
  28276. #endif
  28277. /* test use of custom curve - using BRAINPOOLP256R1 for test */
  28278. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28279. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28280. WOLFSSL_SMALL_STACK_STATIC const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
  28281. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
  28282. };
  28283. #define ecc_oid_brainpoolp256r1_sz \
  28284. (sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t))
  28285. #else
  28286. #define ecc_oid_brainpoolp256r1 { \
  28287. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 \
  28288. }
  28289. #define ecc_oid_brainpoolp256r1_sz 9
  28290. #endif
  28291. #define ecc_oid_brainpoolp256r1_sum 104
  28292. WOLFSSL_SMALL_STACK_STATIC const ecc_set_type ecc_dp_brainpool256r1 = {
  28293. 32, /* size/bytes */
  28294. ECC_CURVE_CUSTOM, /* ID */
  28295. "BRAINPOOLP256R1", /* curve name */
  28296. "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
  28297. "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
  28298. "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", /* B */
  28299. "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", /* order */
  28300. "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", /* Gx */
  28301. "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
  28302. ecc_oid_brainpoolp256r1, /* oid/oidSz */
  28303. ecc_oid_brainpoolp256r1_sz,
  28304. ecc_oid_brainpoolp256r1_sum, /* oid sum */
  28305. 1, /* cofactor */
  28306. };
  28307. #endif /* HAVE_ECC_BRAINPOOL */
  28308. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28309. if (! key) {
  28310. ret = MEMORY_E;
  28311. goto done;
  28312. }
  28313. #endif
  28314. XMEMSET(key, 0, sizeof *key);
  28315. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28316. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, ECC_CURVE_DEF,
  28317. &ecc_dp_brainpool256r1);
  28318. if (ret != 0) {
  28319. printf("ECC test for custom curve failed!\n");
  28320. goto done;
  28321. }
  28322. #endif
  28323. #if defined(HAVE_ECC_BRAINPOOL) || defined(HAVE_ECC_KOBLITZ)
  28324. {
  28325. int curve_id;
  28326. #ifdef HAVE_ECC_BRAINPOOL
  28327. curve_id = ECC_BRAINPOOLP256R1;
  28328. #else
  28329. curve_id = ECC_SECP256K1;
  28330. #endif
  28331. /* Test and demonstrate use of non-SECP curve */
  28332. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, curve_id, NULL);
  28333. if (ret < 0) {
  28334. printf("ECC test for curve_id %d failed!\n", curve_id);
  28335. goto done;
  28336. }
  28337. }
  28338. #endif
  28339. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  28340. if (ret != 0)
  28341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28342. inOutIdx = 0;
  28343. ret = wc_EccPublicKeyDecode(eccKeyExplicitCurve, &inOutIdx, key,
  28344. sizeof(eccKeyExplicitCurve));
  28345. if (ret != 0)
  28346. ret = WC_TEST_RET_ENC_EC(ret);
  28347. done:
  28348. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28349. if (key) {
  28350. wc_ecc_free(key);
  28351. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28352. }
  28353. #else
  28354. wc_ecc_free(key);
  28355. #endif
  28356. (void)rng;
  28357. return ret;
  28358. }
  28359. #endif /* WOLFSSL_CUSTOM_CURVES */
  28360. #ifdef WOLFSSL_SM2
  28361. #ifdef HAVE_ECC_VERIFY
  28362. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28363. #ifdef HAVE_OID_ENCODING
  28364. #define CODED_SM2P256V1 {1,2,156,10197,1,301}
  28365. #define CODED_SM2P256V1_SZ 6
  28366. #else
  28367. #define CODED_SM2P256V1 {0x06,0x08,0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D}
  28368. #define CODED_SM2P256V1_SZ 10
  28369. #endif
  28370. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28371. static const ecc_oid_t ecc_oid_sm2p256v1[] = CODED_SM2P256V1;
  28372. #else
  28373. #define ecc_oid_sm2p256v1 CODED_SM2P256V1
  28374. #endif
  28375. #define ecc_oid_sm2p256v1_sz CODED_SM2P256V1_SZ
  28376. #define ECC_SM2P256V1_TEST 102
  28377. static int test_sm2_verify_caseA2(void)
  28378. {
  28379. ecc_key key;
  28380. int ret, res;
  28381. mp_int r,s;
  28382. /* test key values */
  28383. const char qx[] = "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A";
  28384. const char qy[] = "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857";
  28385. const char d[] = "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263";
  28386. const ecc_set_type ecc_sm2_A2 = {
  28387. 32, /* size/bytes */
  28388. ECC_SM2P256V1_TEST, /* ID */
  28389. "SM2P256V1_TEST", /* curve name */
  28390. /* from test case A.2 in draft-shen-sm2-ecdsa-02 */
  28391. "8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", /* prime */
  28392. "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", /* A */
  28393. "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", /* B */
  28394. "8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", /* order n */
  28395. "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", /* Gx */
  28396. "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", /* Gy */
  28397. ecc_oid_sm2p256v1, /* oid/oidSz */
  28398. ecc_oid_sm2p256v1_sz,
  28399. ECC_SM2P256V1_OID, /* oid sum */
  28400. 1, /* cofactor */
  28401. };
  28402. /* use canned hash value hash = H(ZA||M) */
  28403. const byte hash[] = {
  28404. 0xB5,0x24,0xF5,0x52,0xCD,0x82,0xB8,0xB0,
  28405. 0x28,0x47,0x6E,0x00,0x5C,0x37,0x7F,0xB1,
  28406. 0x9A,0x87,0xE6,0xFC,0x68,0x2D,0x48,0xBB,
  28407. 0x5D,0x42,0xE3,0xD9,0xB9,0xEF,0xFE,0x76
  28408. };
  28409. /* canned r and s */
  28410. const byte rCan[] = {
  28411. 0x40,0xF1,0xEC,0x59,0xF7,0x93,0xD9,0xF4,
  28412. 0x9E,0x09,0xDC,0xEF,0x49,0x13,0x0D,0x41,
  28413. 0x94,0xF7,0x9F,0xB1,0xEE,0xD2,0xCA,0xA5,
  28414. 0x5B,0xAC,0xDB,0x49,0xC4,0xE7,0x55,0xD1
  28415. };
  28416. const byte sCan[] = {
  28417. 0x6F,0xC6,0xDA,0xC3,0x2C,0x5D,0x5C,0xF1,
  28418. 0x0C,0x77,0xDF,0xB2,0x0F,0x7C,0x2E,0xB6,
  28419. 0x67,0xA4,0x57,0x87,0x2F,0xB0,0x9E,0xC5,
  28420. 0x63,0x27,0xA6,0x7E,0xC7,0xDE,0xEB,0xE7
  28421. };
  28422. mp_init(&r);
  28423. mp_init(&s);
  28424. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28425. if (ret != 0)
  28426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28427. ret = wc_ecc_set_custom_curve(&key, &ecc_sm2_A2);
  28428. if (ret != 0)
  28429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28430. ret = wc_ecc_import_raw_ex(&key, qx, qy, d, ECC_SM2P256V1_TEST);
  28431. if (ret != 0)
  28432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28433. mp_read_unsigned_bin(&r, rCan, sizeof(rCan));
  28434. mp_read_unsigned_bin(&s, sCan, sizeof(sCan));
  28435. ret = wc_ecc_sm2_verify_hash_ex(&r, &s, hash, sizeof(hash), &res, &key);
  28436. if (ret != 0)
  28437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28438. if (res != 1)
  28439. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28440. done:
  28441. mp_free(&r);
  28442. mp_free(&s);
  28443. wc_ecc_free(&key);
  28444. return ret;
  28445. }
  28446. #endif /* WOLFSSL_PUBLIC_MP && WOLFSSL_CUSTOM_CURVES */
  28447. static int test_sm2_verify_case(void)
  28448. {
  28449. ecc_key key;
  28450. int ret, res;
  28451. /* test key values */
  28452. const char qx[] = "637F1B135036C933DC3F7A8EBB1B7B2FD1DFBD268D4F894B5AD47DBDBECD558F";
  28453. const char qy[] = "E88101D08048E36CCBF61CA38DDF7ABA542B4486E99E49F3A7470A857A096433";
  28454. /* use canned hash value hash = H(ZA||M) */
  28455. const byte hash[] = {
  28456. 0x3B,0xFA,0x5F,0xFB,0xC4,0x27,0x8C,0x9D,
  28457. 0x02,0x3A,0x19,0xCB,0x1E,0xAA,0xD2,0xF1,
  28458. 0x50,0x69,0x5B,0x20
  28459. };
  28460. const byte sig[] = {
  28461. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28462. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28463. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28464. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28465. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28466. 0xB5,0xB5,0xD9,0xD8,0xF1,0x20,0xDD,0x97,
  28467. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28468. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28469. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28470. };
  28471. const byte badSig[] = {
  28472. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28473. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28474. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28475. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28476. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28477. 0xB5,0xB5,0xE9,0xD8,0xF1,0x20,0xDD,0x97,
  28478. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28479. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28480. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28481. };
  28482. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28483. if (ret != 0)
  28484. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28485. ret = wc_ecc_import_raw(&key, qx, qy, NULL, "SM2P256V1");
  28486. if (ret != 0)
  28487. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28488. ret = wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash), &res,
  28489. &key);
  28490. if (ret != 0)
  28491. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28492. if (res != 1)
  28493. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28494. /* now test a case that should fail */
  28495. ret = wc_ecc_sm2_verify_hash(badSig, sizeof(badSig), hash, sizeof(hash),
  28496. &res, &key);
  28497. if (ret != 0)
  28498. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28499. if (res == 1)
  28500. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28501. done:
  28502. wc_ecc_free(&key);
  28503. return ret;
  28504. }
  28505. static int ecc_sm2_test_curve(WC_RNG* rng, int testVerifyCount)
  28506. {
  28507. const ecc_set_type* dp = wc_ecc_get_curve_params(
  28508. wc_ecc_get_curve_idx(ECC_SM2P256V1));
  28509. int keySize = 32;
  28510. int curve_id = ECC_SM2P256V1;
  28511. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28512. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28513. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28514. #endif
  28515. #ifdef HAVE_ECC_KEY_EXPORT
  28516. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  28517. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28518. #endif
  28519. word32 x = 0;
  28520. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28521. word32 y;
  28522. #endif
  28523. #ifdef HAVE_ECC_SIGN
  28524. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28525. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28526. int i;
  28527. int verify;
  28528. #endif /* HAVE_ECC_SIGN */
  28529. int ret;
  28530. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28531. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28532. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28533. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28534. #else
  28535. ecc_key userA[1];
  28536. ecc_key userB[1];
  28537. ecc_key pubKey[1];
  28538. #endif
  28539. #ifndef WC_NO_RNG
  28540. int curveSize;
  28541. #endif
  28542. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28543. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28544. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28545. #endif
  28546. #ifdef HAVE_ECC_KEY_EXPORT
  28547. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28548. #endif
  28549. #ifdef HAVE_ECC_SIGN
  28550. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28551. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28552. #endif
  28553. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  28554. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28555. if (sharedA == NULL || sharedB == NULL)
  28556. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28557. #endif
  28558. #ifdef HAVE_ECC_KEY_EXPORT
  28559. if (exportBuf == NULL)
  28560. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28561. #endif
  28562. #ifdef HAVE_ECC_SIGN
  28563. if (sig == NULL || digest == NULL)
  28564. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28565. #endif
  28566. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  28567. (void)testVerifyCount;
  28568. (void)dp;
  28569. (void)x;
  28570. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28571. if ((userA == NULL) ||
  28572. (userB == NULL) ||
  28573. (pubKey == NULL))
  28574. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28575. #endif
  28576. XMEMSET(userA, 0, sizeof *userA);
  28577. XMEMSET(userB, 0, sizeof *userB);
  28578. XMEMSET(pubKey, 0, sizeof *pubKey);
  28579. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  28580. if (ret != 0)
  28581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28582. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  28583. if (ret != 0)
  28584. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28585. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28586. if (ret != 0)
  28587. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28588. #ifndef WC_NO_RNG
  28589. ret = wc_ecc_sm2_make_key(rng, userA, WC_ECC_FLAG_NONE);
  28590. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  28591. goto done; /* catch case, where curve is not supported */
  28592. if (ret != 0)
  28593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28594. TEST_SLEEP();
  28595. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  28596. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  28597. if (curveSize != userA->dp->size) {
  28598. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28599. }
  28600. }
  28601. ret = wc_ecc_check_key(userA);
  28602. if (ret != 0)
  28603. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28604. TEST_SLEEP();
  28605. ret = wc_ecc_sm2_make_key(rng, userB, WC_ECC_FLAG_NONE);
  28606. if (ret != 0)
  28607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28608. /* only perform the below tests if the key size matches */
  28609. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  28610. if (ret != 0) {
  28611. ret = ECC_CURVE_OID_E;
  28612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28613. }
  28614. #ifdef HAVE_ECC_DHE
  28615. #if defined(ECC_TIMING_RESISTANT)
  28616. ret = wc_ecc_set_rng(userA, rng);
  28617. if (ret != 0)
  28618. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28619. ret = wc_ecc_set_rng(userB, rng);
  28620. if (ret != 0)
  28621. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28622. #endif
  28623. x = ECC_SHARED_SIZE;
  28624. ret = wc_ecc_sm2_shared_secret(userA, userB, sharedA, &x);
  28625. if (ret != 0)
  28626. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28627. y = ECC_SHARED_SIZE;
  28628. ret = wc_ecc_sm2_shared_secret(userB, userA, sharedB, &y);
  28629. if (ret != 0)
  28630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28631. if (y != x)
  28632. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28633. if (XMEMCMP(sharedA, sharedB, x))
  28634. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28635. #endif /* HAVE_ECC_DHE */
  28636. #ifdef HAVE_ECC_KEY_EXPORT
  28637. x = ECC_KEY_EXPORT_BUF_SIZE;
  28638. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  28639. if (ret != 0)
  28640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28641. #ifdef HAVE_ECC_KEY_IMPORT
  28642. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28643. if (ret != 0)
  28644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28645. #ifdef HAVE_ECC_DHE
  28646. y = ECC_SHARED_SIZE;
  28647. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28648. if (ret != 0)
  28649. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28650. if (XMEMCMP(sharedA, sharedB, y))
  28651. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28652. #endif /* HAVE_ECC_DHE */
  28653. #ifdef HAVE_COMP_KEY
  28654. /* try compressed export / import too */
  28655. x = ECC_KEY_EXPORT_BUF_SIZE;
  28656. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  28657. if (ret != 0)
  28658. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28659. wc_ecc_free(pubKey);
  28660. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28661. if (ret != 0)
  28662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28663. #endif
  28664. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28665. if (ret != 0)
  28666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28667. #ifdef HAVE_ECC_DHE
  28668. y = ECC_SHARED_SIZE;
  28669. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28670. if (ret != 0)
  28671. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28672. if (XMEMCMP(sharedA, sharedB, y))
  28673. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28674. #endif /* HAVE_ECC_DHE */
  28675. #endif /* HAVE_ECC_KEY_IMPORT */
  28676. #endif /* HAVE_ECC_KEY_EXPORT */
  28677. #endif /* !WC_NO_RNG */
  28678. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  28679. !defined(WC_NO_RNG))
  28680. #ifdef HAVE_ECC_SIGN
  28681. /* ECC w/out Shamir has issue with all 0 digest */
  28682. /* WC_BIGINT doesn't have 0 len well on hardware */
  28683. /* Cryptocell has issues with all 0 digest */
  28684. #if defined(ECC_SHAMIR)
  28685. /* test DSA sign hash with zeros */
  28686. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28687. digest[i] = 0;
  28688. }
  28689. x = ECC_SIG_SIZE;
  28690. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28691. if (ret != 0)
  28692. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28693. for (i = 0; i < testVerifyCount; i++) {
  28694. verify = 0;
  28695. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28696. userA);
  28697. if (ret != 0)
  28698. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28699. if (verify != 1)
  28700. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28701. }
  28702. #endif /* ECC_SHAMIR */
  28703. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  28704. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28705. digest[i] = (byte)i;
  28706. }
  28707. x = ECC_SIG_SIZE;
  28708. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28709. if (ret != 0)
  28710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28711. for (i = 0; i < testVerifyCount; i++) {
  28712. verify = 0;
  28713. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28714. userA);
  28715. if (ret != 0)
  28716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28717. if (verify != 1)
  28718. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28719. }
  28720. #endif /* HAVE_ECC_SIGN */
  28721. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT && !WC_NO_RNG) */
  28722. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  28723. x = ECC_KEY_EXPORT_BUF_SIZE;
  28724. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  28725. if (ret != 0)
  28726. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28727. #elif defined(HAVE_ECC_KEY_EXPORT)
  28728. (void)exportBuf;
  28729. #endif /* HAVE_ECC_KEY_EXPORT */
  28730. done:
  28731. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28732. if (userA != NULL) {
  28733. wc_ecc_free(userA);
  28734. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28735. }
  28736. if (userB != NULL) {
  28737. wc_ecc_free(userB);
  28738. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28739. }
  28740. if (pubKey != NULL) {
  28741. wc_ecc_free(pubKey);
  28742. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28743. }
  28744. #else
  28745. wc_ecc_free(pubKey);
  28746. wc_ecc_free(userB);
  28747. wc_ecc_free(userA);
  28748. #endif
  28749. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  28750. WC_FREE_VAR(sharedA, HEAP_HINT);
  28751. WC_FREE_VAR(sharedB, HEAP_HINT);
  28752. #endif
  28753. #ifdef HAVE_ECC_KEY_EXPORT
  28754. WC_FREE_VAR(exportBuf, HEAP_HINT);
  28755. #endif
  28756. #ifdef HAVE_ECC_SIGN
  28757. WC_FREE_VAR(sig, HEAP_HINT);
  28758. WC_FREE_VAR(digest, HEAP_HINT);
  28759. #endif
  28760. (void)keySize;
  28761. (void)curve_id;
  28762. (void)rng;
  28763. return ret;
  28764. }
  28765. #endif /* HAVE_ECC_VERIFY */
  28766. static int test_sm2_create_digest(void)
  28767. {
  28768. #ifndef WOLFSSL_SM3
  28769. const byte msg[] = "message to sign";
  28770. const byte id[] = "0123456789";
  28771. const byte badId[] = "0123556789";
  28772. byte expected[] = {
  28773. 0xdd, 0x4d, 0x65, 0x49, 0xa3, 0x64, 0x76, 0xc0,
  28774. 0x73, 0x05, 0xdc, 0x05, 0x16, 0xb5, 0xee, 0x9f,
  28775. 0x82, 0xf9, 0xe9, 0x7d, 0x01, 0x1a, 0xdc, 0x88,
  28776. 0x5a, 0x59, 0x9c, 0x44, 0xcc, 0x47, 0xa4, 0x78
  28777. };
  28778. ecc_key key;
  28779. int ret;
  28780. /* test key values */
  28781. const char qx[] =
  28782. "af178b7b8740cc9d5b493fbd22049c12621bc27dcc5802e75ff4d045a4158baf";
  28783. const char qy[] =
  28784. "89933faf7a4798f48c5b9b4cd3a7693d54c9e05449946eb489c0dd50a5294805";
  28785. const char d[] =
  28786. "b3e66c2dbfb50c6ff6830c1fac4b51293a2562f9e667052b03df2d4b43c1f34a";
  28787. int hash_type = WC_HASH_TYPE_SHA256;
  28788. byte digest[WC_SHA256_DIGEST_SIZE];
  28789. #else
  28790. ecc_key key;
  28791. int ret;
  28792. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20,
  28793. 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x00 };
  28794. const byte id[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28795. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28796. 0x00 };
  28797. const byte badId[] = "0123556789";
  28798. const char qx[] =
  28799. "09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020";
  28800. const char qy[] =
  28801. "CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13";
  28802. const char d[] =
  28803. "3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8";
  28804. byte expected[] = {
  28805. 0xf0, 0xb4, 0x3e, 0x94, 0xba, 0x45, 0xac, 0xca,
  28806. 0xac, 0xe6, 0x92, 0xed, 0x53, 0x43, 0x82, 0xeb,
  28807. 0x17, 0xe6, 0xab, 0x5a, 0x19, 0xce, 0x7b, 0x31,
  28808. 0xf4, 0x48, 0x6f, 0xdf, 0xc0, 0xd2, 0x86, 0x40
  28809. };
  28810. int hash_type = WC_HASH_TYPE_SM3;
  28811. byte digest[WC_SM3_DIGEST_SIZE];
  28812. #endif
  28813. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28814. if (ret != 0)
  28815. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28816. ret = wc_ecc_import_raw(&key, qx, qy, d, "SM2P256V1");
  28817. if (ret != 0)
  28818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28819. ret = wc_ecc_sm2_create_digest(id, (int)XSTRLEN((const char*)id),
  28820. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28821. &key);
  28822. if (ret != 0)
  28823. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28824. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) != 0)
  28825. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28826. ret = wc_ecc_sm2_create_digest(badId, (int)XSTRLEN((const char*)badId),
  28827. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28828. &key);
  28829. if (ret != 0)
  28830. goto done;
  28831. /* should be different than the previous ID used */
  28832. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) == 0)
  28833. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28834. done:
  28835. wc_ecc_free(&key);
  28836. return ret;
  28837. }
  28838. static int test_sm2_verify(void)
  28839. {
  28840. int ret = 0;
  28841. #ifdef HAVE_ECC_VERIFY
  28842. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28843. ret = test_sm2_verify_caseA2();
  28844. if (ret != 0)
  28845. return ret;
  28846. #endif
  28847. ret = test_sm2_verify_case();
  28848. if (ret != 0)
  28849. return ret;
  28850. #endif /* HAVE_ECC_VERIFY */
  28851. ret = test_sm2_create_digest();
  28852. return ret;
  28853. }
  28854. #endif /* WOLFSSL_SM2 */
  28855. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && !defined(NO_ASN_TIME)
  28856. /* Make Cert / Sign example for ECC cert and ECC CA */
  28857. static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
  28858. {
  28859. wc_test_ret_t ret;
  28860. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28861. Cert *myCert = (Cert *)XMALLOC(sizeof *myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28862. #ifdef WOLFSSL_TEST_CERT
  28863. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28864. #endif
  28865. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28866. ecc_key *certPubKey = (ecc_key *)XMALLOC(sizeof *certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28867. #else
  28868. Cert myCert[1];
  28869. #ifdef WOLFSSL_TEST_CERT
  28870. DecodedCert decode[1];
  28871. #endif
  28872. ecc_key caEccKey[1];
  28873. ecc_key certPubKey[1];
  28874. #endif
  28875. int certSz;
  28876. size_t bytes = 0;
  28877. word32 idx = 0;
  28878. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
  28879. XFILE file;
  28880. #endif
  28881. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28882. byte* der = NULL;
  28883. #else
  28884. byte der[FOURK_BUF];
  28885. #endif
  28886. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28887. if ((myCert == NULL)
  28888. #ifdef WOLFSSL_TEST_CERT
  28889. || (decode == NULL)
  28890. #endif
  28891. || (caEccKey == NULL) || (certPubKey == NULL))
  28892. ERROR_OUT(MEMORY_E, exit);
  28893. #endif
  28894. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  28895. XMEMSET(certPubKey, 0, sizeof *certPubKey);
  28896. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28897. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28898. if (der == NULL) {
  28899. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28900. }
  28901. #endif
  28902. /* Get cert private key */
  28903. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28904. /* Get Cert Key 384 */
  28905. #ifdef USE_CERT_BUFFERS_256
  28906. XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
  28907. bytes = sizeof_ca_ecc_key_der_384;
  28908. #elif !defined(NO_FILESYSTEM)
  28909. file = XFOPEN(eccCaKey384File, "rb");
  28910. if (!file) {
  28911. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28912. }
  28913. bytes = XFREAD(der, 1, FOURK_BUF, file);
  28914. XFCLOSE(file);
  28915. if (bytes == 0)
  28916. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28917. (void)eccCaKeyFile;
  28918. #else
  28919. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
  28920. ERROR_OUT(ASN_PARSE_E, exit);
  28921. #endif /* USE_CERT_BUFFERS_256 */
  28922. /* end if ENABLE_ECC384_CERT_GEN_TEST */
  28923. #else
  28924. /* !ENABLE_ECC384_CERT_GEN_TEST */
  28925. #ifdef USE_CERT_BUFFERS_256
  28926. XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
  28927. bytes = sizeof_ca_ecc_key_der_256;
  28928. #else
  28929. file = XFOPEN(eccCaKeyFile, "rb");
  28930. if (!file) {
  28931. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28932. }
  28933. bytes = XFREAD(der, 1, FOURK_BUF, file);
  28934. XFCLOSE(file);
  28935. if (bytes == 0)
  28936. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28937. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28938. (void)eccCaKey384File;
  28939. #endif
  28940. #endif /* USE_CERT_BUFFERS_256 */
  28941. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  28942. /* Get CA Key */
  28943. ret = wc_ecc_init_ex(caEccKey, HEAP_HINT, devId);
  28944. if (ret != 0)
  28945. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28946. ret = wc_EccPrivateKeyDecode(der, &idx, caEccKey, (word32)bytes);
  28947. if (ret != 0)
  28948. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28949. /* Make a public key */
  28950. ret = wc_ecc_init_ex(certPubKey, HEAP_HINT, devId);
  28951. if (ret != 0)
  28952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28953. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, certPubKey);
  28954. #if defined(WOLFSSL_ASYNC_CRYPT)
  28955. ret = wc_AsyncWait(ret, &certPubKey->asyncDev, WC_ASYNC_FLAG_NONE);
  28956. #endif
  28957. if (ret != 0)
  28958. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28959. TEST_SLEEP();
  28960. /* Setup Certificate */
  28961. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  28962. if (ret != 0)
  28963. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28964. #ifndef NO_SHA256
  28965. myCert->sigType = CTC_SHA256wECDSA;
  28966. #else
  28967. myCert->sigType = CTC_SHAwECDSA;
  28968. #endif
  28969. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  28970. #ifdef WOLFSSL_CERT_EXT
  28971. /* add Policies */
  28972. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  28973. CTC_MAX_CERTPOL_SZ);
  28974. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  28975. CTC_MAX_CERTPOL_SZ);
  28976. myCert->certPoliciesNb = 2;
  28977. /* add SKID from the Public Key */
  28978. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey);
  28979. if (ret != 0)
  28980. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28981. /* add AKID from the Public Key */
  28982. ret = wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey);
  28983. if (ret != 0)
  28984. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28985. /* add Key Usage */
  28986. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  28987. if (ret != 0)
  28988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  28989. #endif /* WOLFSSL_CERT_EXT */
  28990. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28991. #if defined(USE_CERT_BUFFERS_256)
  28992. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
  28993. sizeof_ca_ecc_cert_der_384);
  28994. #elif !defined(NO_FILESYSTEM)
  28995. ret = wc_SetIssuer(myCert, eccCaCert384File);
  28996. (void)eccCaCertFile;
  28997. #else
  28998. /* not testing with embedded, no file system target */
  28999. ERROR_OUT(ASN_PARSE_E, exit);
  29000. #endif /* USE_CERT_BUFFERS_256 */
  29001. #else
  29002. /* not ENABLE_ECC384_CERT_GEN_TEST */
  29003. #if defined(USE_CERT_BUFFERS_256)
  29004. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
  29005. sizeof_ca_ecc_cert_der_256);
  29006. #else
  29007. ret = wc_SetIssuer(myCert, eccCaCertFile);
  29008. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29009. (void)eccCaCert384File;
  29010. #endif
  29011. #endif
  29012. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29013. if (ret < 0)
  29014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29015. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, certPubKey, rng);
  29016. if (certSz < 0) {
  29017. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit);
  29018. }
  29019. ret = 0;
  29020. do {
  29021. #if defined(WOLFSSL_ASYNC_CRYPT)
  29022. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  29023. #endif
  29024. if (ret >= 0) {
  29025. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  29026. FOURK_BUF, NULL, caEccKey, rng);
  29027. }
  29028. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  29029. if (ret < 0)
  29030. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29031. certSz = (int)ret;
  29032. TEST_SLEEP();
  29033. #ifdef WOLFSSL_TEST_CERT
  29034. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  29035. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  29036. if (ret != 0) {
  29037. FreeDecodedCert(decode);
  29038. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29039. }
  29040. FreeDecodedCert(decode);
  29041. #endif
  29042. ret = SaveDerAndPem(der, certSz, certEccDerFile, certEccPemFile,
  29043. CERT_TYPE);
  29044. if (ret != 0) {
  29045. goto exit;
  29046. }
  29047. exit:
  29048. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29049. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29050. #endif
  29051. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29052. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29053. #ifdef WOLFSSL_TEST_CERT
  29054. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29055. #endif
  29056. if (caEccKey != NULL) {
  29057. wc_ecc_free(caEccKey);
  29058. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29059. }
  29060. if (certPubKey != NULL) {
  29061. wc_ecc_free(certPubKey);
  29062. XFREE(certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29063. }
  29064. #else
  29065. wc_ecc_free(certPubKey);
  29066. wc_ecc_free(caEccKey);
  29067. #endif
  29068. return ret;
  29069. }
  29070. #endif /* WOLFSSL_CERT_GEN */
  29071. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  29072. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
  29073. (!defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES))
  29074. /* Test for the wc_ecc_key_new() and wc_ecc_key_free() functions. */
  29075. static wc_test_ret_t ecc_test_allocator(WC_RNG* rng)
  29076. {
  29077. wc_test_ret_t ret = 0;
  29078. ecc_key* key;
  29079. #ifdef WC_NO_RNG
  29080. word32 idx = 0;
  29081. #endif
  29082. key = wc_ecc_key_new(HEAP_HINT);
  29083. if (key == NULL) {
  29084. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29085. }
  29086. #ifndef WC_NO_RNG
  29087. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  29088. #if defined(WOLFSSL_ASYNC_CRYPT)
  29089. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  29090. #endif
  29091. if (ret != 0)
  29092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29093. #else
  29094. /* use test ECC key */
  29095. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  29096. (word32)sizeof_ecc_key_der_256);
  29097. (void)rng;
  29098. #endif
  29099. exit:
  29100. wc_ecc_key_free(key);
  29101. return ret;
  29102. }
  29103. #endif
  29104. /* ECC Non-blocking tests for Sign and Verify */
  29105. /* Requires SP math and supports P384 or P256 */
  29106. /* ./configure --enable-ecc=nonblock --enable-sp=yes,nonblock CFLAGS="-DWOLFSSL_PUBLIC_MP" */
  29107. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_HAVE_SP_ECC) && \
  29108. defined(WOLFSSL_PUBLIC_MP)
  29109. /* ECC Private Key "d" */
  29110. static const byte p256PrivKey[] = {
  29111. /* SECP256R1 */
  29112. /* d */
  29113. 0x1e, 0xe7, 0x70, 0x07, 0xd3, 0x30, 0x94, 0x39,
  29114. 0x28, 0x90, 0xdf, 0x23, 0x88, 0x2c, 0x4a, 0x34,
  29115. 0x15, 0xdb, 0x4c, 0x43, 0xcd, 0xfa, 0xe5, 0x1f,
  29116. 0x3d, 0x4c, 0x37, 0xfe, 0x59, 0x3b, 0x96, 0xd8
  29117. };
  29118. #ifdef HAVE_ECC384
  29119. static const byte p384PrivKey[] = {
  29120. /* SECP384R1 */
  29121. /* d */
  29122. 0xa4, 0xe5, 0x06, 0xe8, 0x06, 0x16, 0x3e, 0xab,
  29123. 0x89, 0xf8, 0x60, 0x43, 0xc0, 0x60, 0x25, 0xdb,
  29124. 0xba, 0x7b, 0xfe, 0x19, 0x35, 0x08, 0x55, 0x65,
  29125. 0x76, 0xe2, 0xdc, 0xe0, 0x01, 0x8b, 0x6b, 0x68,
  29126. 0xdf, 0xcf, 0x6f, 0x80, 0x12, 0xce, 0x79, 0x37,
  29127. 0xeb, 0x2b, 0x9c, 0x7b, 0xc4, 0x68, 0x1c, 0x74
  29128. };
  29129. #endif /* HAVE_ECC384 */
  29130. #ifdef HAVE_ECC521
  29131. static const byte p521PrivKey[] = {
  29132. /* SECP521R1 */
  29133. /* d */
  29134. 0x01, 0x68, 0x91, 0x33, 0x53, 0xe2, 0x90, 0x68,
  29135. 0x11, 0x8f, 0xaa, 0xa8, 0x76, 0x0c, 0xf7, 0x2a,
  29136. 0x07, 0x1b, 0x92, 0x2a, 0xa7, 0x82, 0x3d, 0xfa,
  29137. 0x83, 0xce, 0x70, 0xc8, 0xc2, 0x60, 0x82, 0xfe,
  29138. 0x18, 0x88, 0x68, 0xda, 0x6a, 0x83, 0x46, 0x78,
  29139. 0xe4, 0xe9, 0xe9, 0xcc, 0x51, 0x7f, 0xed, 0x81,
  29140. 0x02, 0x32, 0xee, 0x26, 0x87, 0xcc, 0xed, 0x63,
  29141. 0x3f, 0x39, 0x27, 0xf0, 0xd7, 0x17, 0x77, 0xa1,
  29142. 0xa4, 0x36
  29143. };
  29144. #endif /* HAVE_ECC521 */
  29145. /* ECC public key Qx/Qy */
  29146. static const byte p256PubKey[] = {
  29147. /* SECP256R1 */
  29148. /* Qx */
  29149. 0x96, 0x93, 0x1c, 0x53, 0x0b, 0x43, 0x6c, 0x42,
  29150. 0x0c, 0x52, 0x90, 0xe4, 0xa7, 0xec, 0x98, 0xb1,
  29151. 0xaf, 0xd4, 0x14, 0x49, 0xd8, 0xc1, 0x42, 0x82,
  29152. 0x04, 0x78, 0xd1, 0x90, 0xae, 0xa0, 0x6c, 0x07,
  29153. /* Qy */
  29154. 0xf2, 0x3a, 0xb5, 0x10, 0x32, 0x8d, 0xce, 0x9e,
  29155. 0x76, 0xa0, 0xd2, 0x8c, 0xf3, 0xfc, 0xa9, 0x94,
  29156. 0x43, 0x24, 0xe6, 0x82, 0x00, 0x40, 0xc6, 0xdb,
  29157. 0x1c, 0x2f, 0xcd, 0x38, 0x4b, 0x60, 0xdd, 0x61
  29158. };
  29159. #ifdef HAVE_ECC384
  29160. static const byte p384PubKey[] = {
  29161. /* SECP384R1 */
  29162. /* Qx */
  29163. 0xea, 0xcf, 0x93, 0x4f, 0x2c, 0x09, 0xbb, 0x39,
  29164. 0x14, 0x0f, 0x56, 0x64, 0xc3, 0x40, 0xb4, 0xdf,
  29165. 0x0e, 0x63, 0xae, 0xe5, 0x71, 0x4b, 0x00, 0xcc,
  29166. 0x04, 0x97, 0xff, 0xe1, 0xe9, 0x38, 0x96, 0xbb,
  29167. 0x5f, 0x91, 0xb2, 0x6a, 0xcc, 0xb5, 0x39, 0x5f,
  29168. 0x8f, 0x70, 0x59, 0xf1, 0x01, 0xf6, 0x5a, 0x2b,
  29169. /* Qy */
  29170. 0x01, 0x6c, 0x68, 0x0b, 0xcf, 0x55, 0x25, 0xaf,
  29171. 0x6d, 0x98, 0x48, 0x0a, 0xa8, 0x74, 0xc9, 0xa9,
  29172. 0x17, 0xa0, 0x0c, 0xc3, 0xfb, 0xd3, 0x23, 0x68,
  29173. 0xfe, 0x04, 0x3c, 0x63, 0x50, 0x88, 0x3b, 0xb9,
  29174. 0x4f, 0x7c, 0x67, 0x34, 0xf7, 0x3b, 0xa9, 0x73,
  29175. 0xe7, 0x1b, 0xc3, 0x51, 0x5e, 0x22, 0x18, 0xec
  29176. };
  29177. #endif
  29178. #ifdef HAVE_ECC521
  29179. static const byte p521PubKey[] = {
  29180. /* SECP521R1 */
  29181. /* Qx */
  29182. 0x01, 0x62, 0x6e, 0xf1, 0x00, 0xec, 0xd8, 0x99,
  29183. 0x58, 0x9b, 0x80, 0x6b, 0xfe, 0x2c, 0xf1, 0xb2,
  29184. 0xf0, 0xc8, 0x48, 0xdf, 0xac, 0xd2, 0x3b, 0x71,
  29185. 0x29, 0xab, 0xf0, 0x66, 0x63, 0xd8, 0x8e, 0xb5,
  29186. 0xc8, 0xc2, 0xfc, 0x99, 0x44, 0xe2, 0x45, 0xb1,
  29187. 0x5a, 0x7b, 0xb9, 0x73, 0x01, 0xda, 0x79, 0xec,
  29188. 0x9c, 0x26, 0x27, 0x34, 0x45, 0x26, 0xd5, 0x89,
  29189. 0x4b, 0x44, 0xfe, 0x69, 0x4e, 0x72, 0x14, 0xe3,
  29190. 0x8b, 0xbc,
  29191. /* Qy */
  29192. 0x00, 0x0f, 0x09, 0xa2, 0x03, 0xc3, 0x5a, 0xdc,
  29193. 0x95, 0x82, 0xf6, 0xf9, 0xf6, 0x9c, 0xff, 0xb5,
  29194. 0x6b, 0x75, 0x95, 0x4b, 0xa4, 0x28, 0x5d, 0x9e,
  29195. 0x90, 0x04, 0xd1, 0xc0, 0x1e, 0xd5, 0xfd, 0x43,
  29196. 0x9e, 0x1e, 0x83, 0xc0, 0x11, 0x2b, 0x2b, 0x07,
  29197. 0x6d, 0xa9, 0x7a, 0x10, 0xd7, 0x67, 0xe7, 0x51,
  29198. 0x37, 0x24, 0xd8, 0xbf, 0x03, 0x0d, 0x8b, 0xb5,
  29199. 0x40, 0x5c, 0x4f, 0xd6, 0x13, 0x73, 0x42, 0xbc,
  29200. 0x91, 0xd9
  29201. };
  29202. /* perform verify of signature and hash using public key */
  29203. /* key is public Qx + public Qy */
  29204. /* sig is r + s */
  29205. static wc_test_ret_t crypto_ecc_verify(const byte *key, uint32_t keySz,
  29206. const byte *hash, uint32_t hashSz, const byte *sig, uint32_t sigSz,
  29207. uint32_t curveSz, int curveId)
  29208. {
  29209. wc_test_ret_t ret;
  29210. int verify_res = 0, count = 0;
  29211. mp_int r, s;
  29212. ecc_key ecc;
  29213. ecc_nb_ctx_t nb_ctx;
  29214. /* validate arguments */
  29215. if (key == NULL || hash == NULL || sig == NULL || curveSz == 0 ||
  29216. hashSz == 0 || keySz < (curveSz*2) || sigSz < (curveSz*2))
  29217. {
  29218. return WC_TEST_RET_ENC_NC;
  29219. }
  29220. /* Setup the ECC key */
  29221. ret = wc_ecc_init(&ecc);
  29222. if (ret < 0) {
  29223. return WC_TEST_RET_ENC_EC(ret);
  29224. }
  29225. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29226. if (ret != MP_OKAY) {
  29227. wc_ecc_free(&ecc);
  29228. return WC_TEST_RET_ENC_EC(ret);
  29229. }
  29230. /* Setup the signature r/s variables */
  29231. ret = mp_init(&r);
  29232. if (ret != MP_OKAY) {
  29233. wc_ecc_free(&ecc);
  29234. return WC_TEST_RET_ENC_EC(ret);
  29235. }
  29236. ret = mp_init(&s);
  29237. if (ret != MP_OKAY) {
  29238. mp_clear(&r);
  29239. wc_ecc_free(&ecc);
  29240. return WC_TEST_RET_ENC_EC(ret);
  29241. }
  29242. /* Import public key x/y */
  29243. ret = wc_ecc_import_unsigned(
  29244. &ecc,
  29245. (byte*)key, /* Public "x" Coordinate */
  29246. (byte*)(key + curveSz), /* Public "y" Coordinate */
  29247. NULL, /* Private "d" (optional) */
  29248. curveId /* ECC Curve Id */
  29249. );
  29250. /* Make sure it was a public key imported */
  29251. if (ret == 0 && ecc.type != ECC_PUBLICKEY) {
  29252. ret = WC_TEST_RET_ENC_NC; /* ECC_BAD_ARG_E */
  29253. }
  29254. /* Import signature r/s */
  29255. if (ret == 0) {
  29256. ret = mp_read_unsigned_bin(&r, sig, curveSz);
  29257. if (ret < 0)
  29258. ret = WC_TEST_RET_ENC_EC(ret);
  29259. }
  29260. if (ret == 0) {
  29261. ret = mp_read_unsigned_bin(&s, sig + curveSz, curveSz);
  29262. if (ret < 0)
  29263. ret = WC_TEST_RET_ENC_EC(ret);
  29264. }
  29265. /* Verify ECC Signature */
  29266. if (ret == 0) {
  29267. do {
  29268. ret = wc_ecc_verify_hash_ex(
  29269. &r, &s, /* r/s as mp_int */
  29270. hash, hashSz, /* computed hash digest */
  29271. &verify_res, /* verification result 1=success */
  29272. &ecc
  29273. );
  29274. count++;
  29275. /* This is where real-time work could be called */
  29276. } while (ret == FP_WOULDBLOCK);
  29277. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29278. printf("ECC non-block verify: %d times\n", count);
  29279. #endif
  29280. if (ret < 0)
  29281. ret = WC_TEST_RET_ENC_EC(ret);
  29282. }
  29283. /* check verify result */
  29284. if (ret == 0 && verify_res == 0) {
  29285. ret = WC_TEST_RET_ENC_NC /* SIG_VERIFY_E */;
  29286. }
  29287. mp_clear(&r);
  29288. mp_clear(&s);
  29289. wc_ecc_free(&ecc);
  29290. (void)count;
  29291. return ret;
  29292. }
  29293. /* perform signature operation against hash using private key */
  29294. static wc_test_ret_t crypto_ecc_sign(const byte *key, uint32_t keySz,
  29295. const byte *hash, uint32_t hashSz, byte *sig, uint32_t* sigSz,
  29296. uint32_t curveSz, int curveId, WC_RNG* rng)
  29297. {
  29298. wc_test_ret_t ret;
  29299. int count = 0;
  29300. mp_int r, s;
  29301. ecc_key ecc;
  29302. ecc_nb_ctx_t nb_ctx;
  29303. /* validate arguments */
  29304. if (key == NULL || hash == NULL || sig == NULL || sigSz == NULL ||
  29305. curveSz == 0 || hashSz == 0 || keySz < curveSz || *sigSz < (curveSz*2))
  29306. {
  29307. return WC_TEST_RET_ENC_NC /* BAD_FUNC_ARG */;
  29308. }
  29309. /* Initialize signature result */
  29310. memset(sig, 0, curveSz*2);
  29311. /* Setup the ECC key */
  29312. ret = wc_ecc_init(&ecc);
  29313. if (ret < 0) {
  29314. return WC_TEST_RET_ENC_EC(ret);
  29315. }
  29316. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29317. if (ret != MP_OKAY) {
  29318. wc_ecc_free(&ecc);
  29319. return WC_TEST_RET_ENC_EC(ret);
  29320. }
  29321. /* Setup the signature r/s variables */
  29322. ret = mp_init(&r);
  29323. if (ret != MP_OKAY) {
  29324. wc_ecc_free(&ecc);
  29325. return WC_TEST_RET_ENC_EC(ret);
  29326. }
  29327. ret = mp_init(&s);
  29328. if (ret != MP_OKAY) {
  29329. mp_clear(&r);
  29330. wc_ecc_free(&ecc);
  29331. return WC_TEST_RET_ENC_EC(ret);
  29332. }
  29333. /* Import private key "k" */
  29334. ret = wc_ecc_import_private_key_ex(
  29335. key, keySz, /* private key "d" */
  29336. NULL, 0, /* public (optional) */
  29337. &ecc,
  29338. curveId /* ECC Curve Id */
  29339. );
  29340. if (ret < 0)
  29341. ret = WC_TEST_RET_ENC_EC(ret);
  29342. if (ret == 0) {
  29343. do {
  29344. /* Verify ECC Signature */
  29345. ret = wc_ecc_sign_hash_ex(
  29346. hash, hashSz, /* computed hash digest */
  29347. rng, &ecc, /* random and key context */
  29348. &r, &s /* r/s as mp_int */
  29349. );
  29350. count++;
  29351. /* This is where real-time work could be called */
  29352. } while (ret == FP_WOULDBLOCK);
  29353. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29354. printf("ECC non-block sign: %d times\n", count);
  29355. #endif
  29356. if (ret < 0)
  29357. ret = WC_TEST_RET_ENC_EC(ret);
  29358. }
  29359. if (ret == 0) {
  29360. /* export r/s */
  29361. mp_to_unsigned_bin_len(&r, sig, curveSz);
  29362. mp_to_unsigned_bin_len(&s, sig + curveSz, curveSz);
  29363. }
  29364. mp_clear(&r);
  29365. mp_clear(&s);
  29366. wc_ecc_free(&ecc);
  29367. (void)count;
  29368. return ret;
  29369. }
  29370. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29371. /*
  29372. * This test doesn't work with WOLFSSL_VALIDATE_ECC_KEYGEN defined because we
  29373. * don't have non-blocking versions of the key checking functions, yet.
  29374. */
  29375. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29376. static wc_test_ret_t ecc_test_nonblock_dhe(int curveId, word32 curveSz,
  29377. const byte* privKey, const byte* pubKey, WC_RNG* rng)
  29378. {
  29379. wc_test_ret_t ret;
  29380. ecc_key keyA;
  29381. ecc_key keyB;
  29382. ecc_nb_ctx_t nbCtxA;
  29383. ecc_nb_ctx_t nbCtxB;
  29384. byte secretA[ECC_SHARED_SIZE];
  29385. byte secretB[ECC_SHARED_SIZE];
  29386. word32 secretSzA = ECC_SHARED_SIZE;
  29387. word32 secretSzB = ECC_SHARED_SIZE;
  29388. int count = 0;
  29389. ret = wc_ecc_init(&keyA);
  29390. if (ret == 0) {
  29391. ret = wc_ecc_init(&keyB);
  29392. if (ret < 0)
  29393. ret = WC_TEST_RET_ENC_EC(ret);
  29394. }
  29395. if (ret == 0) {
  29396. ret = wc_ecc_set_nonblock(&keyA, &nbCtxA);
  29397. if (ret < 0)
  29398. ret = WC_TEST_RET_ENC_EC(ret);
  29399. }
  29400. if (ret == 0) {
  29401. ret = wc_ecc_set_nonblock(&keyB, &nbCtxB);
  29402. if (ret < 0)
  29403. ret = WC_TEST_RET_ENC_EC(ret);
  29404. }
  29405. if (ret == 0) {
  29406. do {
  29407. ret = wc_ecc_make_key_ex(rng, curveSz, &keyA, curveId);
  29408. count++;
  29409. } while (ret == FP_WOULDBLOCK);
  29410. if (ret < 0)
  29411. ret = WC_TEST_RET_ENC_EC(ret);
  29412. }
  29413. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29414. fprintf(stderr, "ECC non-block key gen: %d times\n", count);
  29415. #endif
  29416. if (ret == 0) {
  29417. ret = wc_ecc_check_key(&keyA);
  29418. if (ret < 0)
  29419. ret = WC_TEST_RET_ENC_EC(ret);
  29420. }
  29421. if (ret == 0) {
  29422. ret = wc_ecc_import_unsigned(&keyB, pubKey, pubKey + curveSz,
  29423. privKey, curveId);
  29424. if (ret < 0)
  29425. ret = WC_TEST_RET_ENC_EC(ret);
  29426. }
  29427. count = 0;
  29428. if (ret == 0) {
  29429. do {
  29430. ret = wc_ecc_shared_secret(&keyA, &keyB, secretA, &secretSzA);
  29431. count++;
  29432. } while (ret == FP_WOULDBLOCK);
  29433. if (ret < 0)
  29434. ret = WC_TEST_RET_ENC_EC(ret);
  29435. }
  29436. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29437. fprintf(stderr, "ECC non-block shared secret: %d times\n", count);
  29438. #endif
  29439. if (ret == 0) {
  29440. do {
  29441. ret = wc_ecc_shared_secret(&keyB, &keyA, secretB, &secretSzB);
  29442. } while (ret == FP_WOULDBLOCK);
  29443. if (ret < 0)
  29444. ret = WC_TEST_RET_ENC_EC(ret);
  29445. }
  29446. if (ret == 0) {
  29447. if (secretSzA != secretSzB ||
  29448. XMEMCMP(secretA, secretB, secretSzA) != 0) {
  29449. ret = WC_TEST_RET_ENC_NC;
  29450. }
  29451. }
  29452. wc_ecc_free(&keyA);
  29453. wc_ecc_free(&keyB);
  29454. return ret;
  29455. }
  29456. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29457. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29458. static wc_test_ret_t ecc_test_nonblock_ecdsa(int curveId, word32 curveSz,
  29459. const byte* privKey, word32 privKeySz, const byte* pubKey, word32 pubKeySz,
  29460. WC_RNG* rng)
  29461. {
  29462. wc_test_ret_t ret = 0;
  29463. byte* sig = NULL;
  29464. word32 sigSz = curveSz * 2;
  29465. static const byte hash[] = {
  29466. 0x8d, 0x28, 0xa3, 0x8b, 0x0b, 0xa9, 0xfe, 0xd4, 0x0e, 0x54, 0xc4, 0x17,
  29467. 0x3d, 0x54, 0x66, 0x34, 0xbf, 0x5d, 0x6f, 0x46, 0xc2, 0x20, 0xcb, 0xc3,
  29468. 0x22, 0xe9, 0xb0, 0xdf, 0xe7, 0x64, 0x3f, 0xd9
  29469. };
  29470. sig = (byte*)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29471. if (sig == NULL) {
  29472. ret = WC_TEST_RET_ENC_ERRNO;
  29473. }
  29474. if (ret == 0) {
  29475. /* Sign hash using private key */
  29476. /* Note: result of an ECC sign varies for each call even with same
  29477. private key and hash. This is because a new random public key is
  29478. used for each operation. */
  29479. ret = crypto_ecc_sign(privKey, privKeySz, hash, sizeof(hash), sig,
  29480. &sigSz, curveSz, curveId, rng);
  29481. }
  29482. if (ret == 0) {
  29483. /* Verify generated signature is valid */
  29484. ret = crypto_ecc_verify(pubKey, pubKeySz, hash, sizeof(hash), sig,
  29485. sigSz, curveSz, curveId);
  29486. }
  29487. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29488. return ret;
  29489. }
  29490. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29491. static wc_test_ret_t ecc_test_nonblock(WC_RNG* rng)
  29492. {
  29493. wc_test_ret_t ret = 0;
  29494. word32 i;
  29495. int curveIds[3] = {0, 0, 0};
  29496. word32 curveSzs[3] = {0, 0, 0};
  29497. const byte* privKeys[3] = {NULL, NULL, NULL};
  29498. word32 privKeySzs[3] = {0, 0, 0};
  29499. const byte* pubKeys[3] = {NULL, NULL, NULL};
  29500. word32 pubKeySzs[3] = {0, 0, 0};
  29501. curveIds[0] = ECC_SECP256R1;
  29502. curveSzs[0] = 32;
  29503. privKeys[0] = p256PrivKey;
  29504. privKeySzs[0] = sizeof(p256PrivKey);
  29505. pubKeys[0] = p256PubKey;
  29506. pubKeySzs[0] = sizeof(p256PubKey);
  29507. #ifdef HAVE_ECC384
  29508. curveIds[1] = ECC_SECP384R1;
  29509. curveSzs[1] = 48;
  29510. privKeys[1] = p384PrivKey;
  29511. privKeySzs[1] = sizeof(p384PrivKey);
  29512. pubKeys[1] = p384PubKey;
  29513. pubKeySzs[1] = sizeof(p384PubKey);
  29514. #endif
  29515. #ifdef HAVE_ECC521
  29516. curveIds[2] = ECC_SECP521R1;
  29517. curveSzs[2] = 66;
  29518. privKeys[2] = p521PrivKey;
  29519. privKeySzs[2] = sizeof(p521PrivKey);
  29520. pubKeys[2] = p521PubKey;
  29521. pubKeySzs[2] = sizeof(p521PubKey);
  29522. #endif
  29523. for (i = 0; ret == 0 && i < sizeof(curveIds) / sizeof(curveIds[0]); ++i) {
  29524. if (curveIds[i] == 0) {
  29525. continue;
  29526. }
  29527. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29528. ret = ecc_test_nonblock_ecdsa(curveIds[i], curveSzs[i], privKeys[i],
  29529. privKeySzs[i], pubKeys[i], pubKeySzs[i], rng);
  29530. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29531. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29532. if (ret == 0) {
  29533. ret = ecc_test_nonblock_dhe(curveIds[i], curveSzs[i], privKeys[i],
  29534. pubKeys[i], rng);
  29535. }
  29536. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29537. }
  29538. return ret;
  29539. }
  29540. #endif /* WC_ECC_NONBLOCK && WOLFSSL_HAVE_SP_ECC && WOLFSSL_PUBLIC_MP */
  29541. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29542. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29543. (HAVE_FIPS_VERSION > 2)))
  29544. static int ecc_test_raw_enc_dec(void)
  29545. {
  29546. int ret;
  29547. unsigned char r[1];
  29548. word32 rSz;
  29549. unsigned char s[1];
  29550. word32 sSz;
  29551. unsigned char rZero[] = { 0, 0, 0, 0 };
  29552. unsigned char sOne[] = { 0, 0, 1 };
  29553. unsigned char sigRaw[32];
  29554. word32 sigRawSz;
  29555. unsigned char expSig[] = { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01 };
  29556. sigRawSz = sizeof(sigRaw);
  29557. ret = wc_ecc_rs_raw_to_sig(rZero, sizeof(rZero), sOne, sizeof(sOne),
  29558. sigRaw, &sigRawSz);
  29559. if (ret != 0) {
  29560. return WC_TEST_RET_ENC_EC(ret);
  29561. }
  29562. if (sigRawSz != sizeof(expSig)) {
  29563. return WC_TEST_RET_ENC_EC((int)sigRawSz);
  29564. }
  29565. if (XMEMCMP(sigRaw, expSig, sizeof(expSig)) != 0) {
  29566. return WC_TEST_RET_ENC_NC;
  29567. }
  29568. rSz = sizeof(r);
  29569. sSz = sizeof(s);
  29570. ret = wc_ecc_sig_to_rs(sigRaw, sigRawSz, r, &rSz, s, &sSz);
  29571. if (ret != 0) {
  29572. return WC_TEST_RET_ENC_EC(ret);
  29573. }
  29574. if (rSz != 1) {
  29575. return WC_TEST_RET_ENC_EC((int)rSz);
  29576. }
  29577. if (sSz != 1) {
  29578. return WC_TEST_RET_ENC_EC((int)sSz);
  29579. }
  29580. if (r[0] != 0) {
  29581. return WC_TEST_RET_ENC_EC(r[0]);
  29582. }
  29583. if (s[0] != 1) {
  29584. return WC_TEST_RET_ENC_EC(s[0]);
  29585. }
  29586. return ret;
  29587. }
  29588. #endif
  29589. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void)
  29590. {
  29591. wc_test_ret_t ret;
  29592. WC_RNG rng;
  29593. WOLFSSL_ENTER("ecc_test");
  29594. #if defined(ECC_MIN_KEY_SZ)
  29595. WOLFSSL_MSG_EX("ecc_test ECC_MIN_KEY_SZ = %d\n", ECC_MIN_KEY_SZ);
  29596. #else
  29597. WOLFSSL_MSG("ecc_test ECC_MIN_KEY_SZ not defined.");
  29598. #endif
  29599. #if defined(WOLFSSL_CERT_EXT) && \
  29600. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29601. ret = ecc_decode_test();
  29602. if (ret < 0)
  29603. return ret;
  29604. #endif
  29605. #ifndef HAVE_FIPS
  29606. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  29607. #else
  29608. ret = wc_InitRng(&rng);
  29609. #endif
  29610. #ifndef WC_NO_RNG
  29611. if (ret != 0)
  29612. return WC_TEST_RET_ENC_EC(ret);
  29613. #else
  29614. (void)ret;
  29615. #endif
  29616. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  29617. ret = ecc_test_curve(&rng, 14, ECC_CURVE_DEF);
  29618. if (ret < 0) {
  29619. printf("keySize=14, Default\n");
  29620. goto done;
  29621. }
  29622. #endif /* HAVE_ECC112 */
  29623. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  29624. ret = ecc_test_curve(&rng, 16, ECC_CURVE_DEF);
  29625. if (ret < 0) {
  29626. printf("keySize=16, Default\n");
  29627. goto done;
  29628. }
  29629. #endif /* HAVE_ECC128 */
  29630. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  29631. ret = ecc_test_curve(&rng, 20, ECC_CURVE_DEF);
  29632. if (ret < 0) {
  29633. printf("keySize=20, Default\n");
  29634. goto done;
  29635. }
  29636. #endif /* HAVE_ECC160 */
  29637. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  29638. #if !FIPS_VERSION3_GE(6,0,0)
  29639. ret = ecc_test_curve(&rng, 24, ECC_CURVE_DEF);
  29640. if (ret < 0) {
  29641. printf("keySize=24, Default\n");
  29642. goto done;
  29643. }
  29644. #endif
  29645. #endif /* HAVE_ECC192 */
  29646. #if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224
  29647. ret = ecc_test_curve(&rng, 28, ECC_CURVE_DEF);
  29648. if (ret < 0) {
  29649. printf("keySize=28, Default\n");
  29650. goto done;
  29651. }
  29652. #endif /* HAVE_ECC224 */
  29653. #if (defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 239
  29654. ret = ecc_test_curve(&rng, 30, ECC_CURVE_DEF);
  29655. if (ret < 0) {
  29656. printf("keySize=30, Default\n");
  29657. goto done;
  29658. }
  29659. #endif /* HAVE_ECC239 */
  29660. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29661. ret = ecc_test_curve(&rng, 32, ECC_CURVE_DEF);
  29662. if (ret < 0) {
  29663. printf("keySize=32, Default\n");
  29664. goto done;
  29665. }
  29666. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29667. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  29668. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  29669. ret = ecc_point_test();
  29670. if (ret < 0) {
  29671. goto done;
  29672. }
  29673. #endif
  29674. #if !defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES)
  29675. ret = ecc_def_curve_test(&rng);
  29676. if (ret < 0) {
  29677. printf("Default\n");
  29678. goto done;
  29679. }
  29680. #endif
  29681. #endif /* !NO_ECC256 */
  29682. #if (defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 320
  29683. ret = ecc_test_curve(&rng, 40, ECC_CURVE_DEF);
  29684. if (ret < 0) {
  29685. printf("keySize=40, Default\n");
  29686. goto done;
  29687. }
  29688. #endif /* HAVE_ECC320 */
  29689. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  29690. ret = ecc_test_curve(&rng, 48, ECC_CURVE_DEF);
  29691. if (ret < 0) {
  29692. printf("keySize=48, Default\n");
  29693. goto done;
  29694. }
  29695. #endif /* HAVE_ECC384 */
  29696. #if (defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 512
  29697. ret = ecc_test_curve(&rng, 64, ECC_CURVE_DEF);
  29698. if (ret < 0) {
  29699. printf("keySize=64, Default\n");
  29700. goto done;
  29701. }
  29702. #endif /* HAVE_ECC512 */
  29703. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  29704. ret = ecc_test_curve(&rng, 66, ECC_CURVE_DEF);
  29705. if (ret < 0) {
  29706. printf("keySize=66, Default\n");
  29707. goto done;
  29708. }
  29709. #endif /* HAVE_ECC521 */
  29710. #ifdef WOLFSSL_SM2
  29711. ret = ecc_test_curve(&rng, 32, ECC_SM2P256V1);
  29712. if (ret < 0) {
  29713. printf("SM2\n");
  29714. goto done;
  29715. }
  29716. #endif
  29717. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29718. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29719. (HAVE_FIPS_VERSION > 2)))
  29720. ret = ecc_test_raw_enc_dec();
  29721. if (ret != 0) {
  29722. printf("raw sig encode/decode\n");
  29723. goto done;
  29724. }
  29725. #endif
  29726. #if defined(WOLFSSL_CUSTOM_CURVES)
  29727. ret = ecc_test_custom_curves(&rng);
  29728. if (ret != 0) {
  29729. printf("Custom\n");
  29730. goto done;
  29731. }
  29732. #endif
  29733. #if defined(WOLFSSL_SM2)
  29734. ret = test_sm2_verify();
  29735. if (ret != 0) {
  29736. printf("SM2 Verify\n");
  29737. goto done;
  29738. }
  29739. ret = ecc_sm2_test_curve(&rng, ECC_TEST_VERIFY_COUNT);
  29740. if (ret != 0) {
  29741. printf("SM2 test\n");
  29742. goto done;
  29743. }
  29744. #endif
  29745. #if defined(HAVE_ECC_SIGN) && \
  29746. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  29747. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  29748. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  29749. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29750. ret = ecc_test_deterministic_k(&rng);
  29751. if (ret != 0) {
  29752. printf("ecc_test_deterministic_k failed!\n");
  29753. goto done;
  29754. }
  29755. #endif
  29756. #ifdef WOLFSSL_PUBLIC_MP
  29757. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  29758. ECC_MIN_KEY_SZ <= 384
  29759. ret = ecc384_test_deterministic_k(&rng);
  29760. if (ret != 0) {
  29761. printf("ecc384_test_deterministic_k failed!\n");
  29762. goto done;
  29763. }
  29764. #endif
  29765. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && \
  29766. ECC_MIN_KEY_SZ <= 521
  29767. ret = ecc521_test_deterministic_k(&rng);
  29768. if (ret != 0) {
  29769. printf("ecc512_test_deterministic_k failed!\n");
  29770. goto done;
  29771. }
  29772. #endif
  29773. #endif
  29774. #endif
  29775. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  29776. !defined(WOLFSSL_KCAPI_ECC)
  29777. ret = ecc_test_sign_vectors(&rng);
  29778. if (ret != 0) {
  29779. printf("ecc_test_sign_vectors failed!\n");
  29780. goto done;
  29781. }
  29782. #endif
  29783. #if defined(HAVE_ECC_VECTOR_TEST) && defined(HAVE_ECC_CDH) && \
  29784. defined(HAVE_ECC_DHE)
  29785. ret = ecc_test_cdh_vectors(&rng);
  29786. if (ret != 0) {
  29787. printf("ecc_test_cdh_vectors failed!\n");
  29788. goto done;
  29789. }
  29790. #endif
  29791. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29792. !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
  29793. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  29794. ret = ecc_test_make_pub(&rng);
  29795. if (ret != 0) {
  29796. printf("ecc_test_make_pub failed!\n");
  29797. goto done;
  29798. }
  29799. #elif defined(HAVE_ECC_KEY_IMPORT)
  29800. (void)ecc_test_make_pub; /* for compiler warning */
  29801. #endif
  29802. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && !defined(NO_ASN_TIME)
  29803. ret = ecc_test_cert_gen(&rng);
  29804. if (ret != 0) {
  29805. printf("ecc_test_cert_gen failed!\n");
  29806. goto done;
  29807. }
  29808. #endif
  29809. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) && \
  29810. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && (!defined(NO_ECC_SECP) || \
  29811. defined(WOLFSSL_CUSTOM_CURVES))
  29812. ret = ecc_test_allocator(&rng);
  29813. if (ret != 0) {
  29814. printf("ecc_test_allocator failed!\n");
  29815. goto done;
  29816. }
  29817. #endif
  29818. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  29819. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29820. ret = ecc_test_nonblock(&rng);
  29821. if (ret != 0) {
  29822. printf("ecc_test_nonblock failed!\n");
  29823. goto done;
  29824. }
  29825. #endif
  29826. done:
  29827. wc_FreeRng(&rng);
  29828. return ret;
  29829. }
  29830. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  29831. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  29832. #if ((! defined(HAVE_FIPS)) || FIPS_VERSION_GE(5,3))
  29833. static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
  29834. {
  29835. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29836. byte* plaintext;
  29837. byte* encrypted;
  29838. byte* decrypted;
  29839. #else
  29840. byte plaintext[128];
  29841. byte encrypted[128];
  29842. byte decrypted[128];
  29843. #endif
  29844. ecEncCtx* aCtx = NULL;
  29845. ecEncCtx* bCtx = NULL;
  29846. static const byte salt[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  29847. 14, 15};
  29848. wc_test_ret_t ret = 0;
  29849. static const char message[] = "Hello wolfSSL!";
  29850. word32 plaintextLen;
  29851. word32 encryptLen = 128;
  29852. word32 decryptLen = 128;
  29853. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29854. plaintext = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29855. encrypted = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29856. decrypted = XMALLOC(128, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29857. #endif
  29858. wc_ecc_free(a);
  29859. wc_ecc_free(b);
  29860. ret = wc_ecc_init(a);
  29861. if (ret != 0)
  29862. ret = WC_TEST_RET_ENC_EC(ret);
  29863. if (ret == 0) {
  29864. ret = wc_ecc_init(b);
  29865. if (ret != 0)
  29866. ret = WC_TEST_RET_ENC_EC(ret);
  29867. }
  29868. if (ret == 0)
  29869. ret = wc_ecc_make_key(rng, 32, a);
  29870. if (ret == 0)
  29871. ret = wc_ecc_make_key(rng, 32, b);
  29872. /* create context */
  29873. if (ret == 0) {
  29874. aCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  29875. if (aCtx == NULL)
  29876. ret = WC_TEST_RET_ENC_NC;
  29877. }
  29878. if (ret == 0) {
  29879. bCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  29880. if (bCtx == NULL)
  29881. ret = WC_TEST_RET_ENC_NC;
  29882. }
  29883. /* set salt */
  29884. if (ret == 0) {
  29885. ret = wc_ecc_ctx_set_kdf_salt(aCtx, salt, sizeof(salt));
  29886. if (ret != 0)
  29887. ret = 10472;
  29888. }
  29889. if (ret == 0) {
  29890. ret = wc_ecc_ctx_set_kdf_salt(bCtx, salt, sizeof(salt));
  29891. if (ret != 0)
  29892. ret = 10473;
  29893. }
  29894. XMEMSET(plaintext, 0, 128);
  29895. XSTRLCPY((char *)plaintext, message, sizeof plaintext);
  29896. plaintextLen = (((word32)XSTRLEN(message) + AES_BLOCK_SIZE - 1) /
  29897. AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
  29898. /* encrypt */
  29899. if (ret == 0) {
  29900. ret = wc_ecc_encrypt(a, b, plaintext, plaintextLen, encrypted,
  29901. &encryptLen, aCtx);
  29902. if (ret != 0)
  29903. ret = WC_TEST_RET_ENC_EC(ret);
  29904. }
  29905. /* decrypt */
  29906. if (ret == 0) {
  29907. ret = wc_ecc_decrypt(b, a, encrypted, encryptLen, decrypted,
  29908. &decryptLen, bCtx);
  29909. if (ret != 0)
  29910. ret = WC_TEST_RET_ENC_EC(ret);
  29911. }
  29912. /* compare */
  29913. if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
  29914. ret = WC_TEST_RET_ENC_NC;
  29915. wc_ecc_free(a);
  29916. wc_ecc_free(b);
  29917. wc_ecc_ctx_free(aCtx);
  29918. wc_ecc_ctx_free(bCtx);
  29919. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29920. XFREE(plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29921. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29922. XFREE(decrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29923. #endif
  29924. return ret;
  29925. }
  29926. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  29927. /* ecc_encrypt_e2e_test() uses wc_ecc_ctx_set_algo(), which was added in
  29928. * wolfFIPS 5.3.
  29929. * ecc_encrypt_kat() is used only by ecc_encrypt_e2e_test().
  29930. */
  29931. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  29932. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  29933. ECC_MIN_KEY_SZ <= 256 && defined(WOLFSSL_AES_128)
  29934. static wc_test_ret_t ecc_encrypt_kat(WC_RNG *rng)
  29935. {
  29936. wc_test_ret_t ret = 0;
  29937. #ifdef WOLFSSL_ECIES_OLD
  29938. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29939. ecc_key* userA = NULL;
  29940. #else
  29941. ecc_key userA[1];
  29942. #endif
  29943. int userAInit = 0;
  29944. #endif
  29945. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29946. ecc_key* userB = NULL;
  29947. #else
  29948. ecc_key userB[1];
  29949. #endif
  29950. int userBInit = 0;
  29951. ecc_key* tmpKey;
  29952. byte plain[48];
  29953. word32 plainSz = sizeof(plain);
  29954. WOLFSSL_SMALL_STACK_STATIC const byte privKey[] = {
  29955. 0x04, 0x80, 0xef, 0x1d, 0xbe, 0x02, 0x0c, 0x20,
  29956. 0x5b, 0xab, 0x80, 0x35, 0x5b, 0x2a, 0x0f, 0x6d,
  29957. 0xd3, 0xb0, 0x7f, 0x7e, 0x7f, 0x86, 0x8a, 0x49,
  29958. 0xee, 0xb4, 0xaa, 0x09, 0x2d, 0x1e, 0x1d, 0x02
  29959. };
  29960. #if defined(WOLFSSL_ECIES_OLD) || defined(WOLFSSL_QNX_CAAM)
  29961. WOLFSSL_SMALL_STACK_STATIC const byte pubKey[] = {
  29962. 0x04,
  29963. /* X */
  29964. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  29965. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  29966. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  29967. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  29968. /* X */
  29969. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  29970. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  29971. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  29972. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28
  29973. };
  29974. #endif
  29975. WOLFSSL_SMALL_STACK_STATIC const byte enc_msg[] = {
  29976. #ifdef WOLFSSL_ECIES_OLD
  29977. 0x42, 0x70, 0xbf, 0xf9, 0xf4, 0x7e, 0x4b, 0x9b,
  29978. 0xb5, 0x4c, 0xcc, 0xc5, 0x94, 0xa7, 0xef, 0xaa,
  29979. 0xc3, 0x7c, 0x85, 0xa6, 0x51, 0x6e, 0xd3, 0xfa,
  29980. 0x56, 0xc9, 0x10, 0x4d, 0x14, 0x32, 0x61, 0xb8,
  29981. 0xbb, 0x66, 0x7a, 0xb5, 0xbc, 0x95, 0xf8, 0xca,
  29982. 0xd1, 0x2a, 0x19, 0x51, 0x44, 0xd8, 0x0e, 0x57,
  29983. 0x34, 0xed, 0x45, 0x89, 0x2e, 0x57, 0xbe, 0xd5,
  29984. 0x06, 0x22, 0xd7, 0x13, 0x0a, 0x0e, 0x40, 0x36,
  29985. 0x0d, 0x05, 0x0d, 0xb6, 0xae, 0x61, 0x37, 0x18,
  29986. 0x83, 0x90, 0x0a, 0x27, 0x95, 0x41, 0x8c, 0x45
  29987. #elif defined(WOLFSSL_ECIES_ISO18033)
  29988. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  29989. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  29990. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  29991. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  29992. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  29993. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  29994. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  29995. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  29996. 0x28, 0xbb, 0x9f, 0xa8, 0x2d, 0xe1, 0xf1, 0x67,
  29997. 0x45, 0x02, 0x19, 0xdc, 0xc8, 0x24, 0x8b, 0x20,
  29998. 0x02, 0xa0, 0x8f, 0x95, 0x12, 0x55, 0x51, 0xf8,
  29999. 0x03, 0xc4, 0x54, 0x13, 0x98, 0x2d, 0xf0, 0x31,
  30000. 0x51, 0x80, 0x45, 0x24, 0xcb, 0x8b, 0x48, 0xa6,
  30001. 0x8b, 0x8e, 0x97, 0x9c, 0x56, 0x4d, 0x70, 0x00,
  30002. 0x53, 0xd3, 0x47, 0x00, 0x5a, 0x23, 0x8c, 0xf9,
  30003. 0xfd, 0xd2, 0x33, 0x2c, 0x43, 0x6e, 0x9e, 0xb2,
  30004. 0xf4, 0x95, 0xd4, 0xcf, 0x30, 0xd6, 0xa2, 0xc5,
  30005. 0x35, 0x96, 0x6a, 0xd4, 0x36, 0x15, 0xa9, 0xbd,
  30006. 0x7f
  30007. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30008. /* EC P-256 point */
  30009. 0x04,
  30010. /* X */
  30011. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30012. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30013. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30014. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30015. /* Y */
  30016. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30017. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30018. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30019. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28,
  30020. /* IV */
  30021. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30022. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30023. /* Encrypted Msg */
  30024. 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d, 0x50,
  30025. 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c, 0x1f,
  30026. 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc, 0x44,
  30027. 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca, 0x65,
  30028. 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61, 0xbd,
  30029. 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1, 0xde,
  30030. /* HMAC */
  30031. 0x5a, 0x22, 0xc1, 0x5d, 0x99, 0x66, 0x3f, 0x24,
  30032. 0x35, 0x96, 0xac, 0xf7, 0xf6, 0x28, 0x45, 0x16,
  30033. 0x52, 0x19, 0x0d, 0xe4, 0xb2, 0xca, 0x5b, 0x28,
  30034. 0x4e, 0xbb, 0xf3, 0x98, 0x57, 0xd7, 0x3b, 0xe2
  30035. #else
  30036. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30037. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30038. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30039. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30040. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30041. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30042. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30043. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30044. 0x28, 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d,
  30045. 0x50, 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c,
  30046. 0x1f, 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc,
  30047. 0x44, 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca,
  30048. 0x65, 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61,
  30049. 0xbd, 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1,
  30050. 0xde, 0xc7, 0x3f, 0x6f, 0xce, 0xbe, 0x49, 0x61,
  30051. 0x48, 0x01, 0x77, 0x41, 0xd0, 0xd8, 0x5b, 0x48,
  30052. 0xca, 0x4e, 0x47, 0x3e, 0x47, 0xbf, 0x1d, 0x28,
  30053. 0x4c, 0x18, 0x1a, 0xfb, 0x96, 0x95, 0xda, 0xde,
  30054. 0x55
  30055. #endif
  30056. };
  30057. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  30058. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  30059. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  30060. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  30061. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  30062. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  30063. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  30064. };
  30065. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30066. userB = (ecc_key *)XMALLOC(sizeof(*userB), HEAP_HINT,
  30067. DYNAMIC_TYPE_TMP_BUFFER);
  30068. if (userB == NULL) {
  30069. ret = WC_TEST_RET_ENC_ERRNO;
  30070. }
  30071. #ifdef WOLFSSL_ECIES_OLD
  30072. if (ret == 0) {
  30073. userA = (ecc_key *)XMALLOC(sizeof(*userA), HEAP_HINT,
  30074. DYNAMIC_TYPE_TMP_BUFFER);
  30075. if (userA == NULL) {
  30076. ret = WC_TEST_RET_ENC_ERRNO;
  30077. }
  30078. }
  30079. #endif
  30080. #endif
  30081. if (ret == 0) {
  30082. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30083. if (ret != 0)
  30084. ret = WC_TEST_RET_ENC_EC(ret);
  30085. }
  30086. if (ret == 0) {
  30087. userBInit = 1;
  30088. #ifdef WOLFSSL_ECIES_OLD
  30089. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30090. if (ret != 0)
  30091. ret = WC_TEST_RET_ENC_EC(ret);
  30092. }
  30093. if (ret == 0) {
  30094. userAInit = 1;
  30095. tmpKey = userA;
  30096. #else
  30097. tmpKey = NULL;
  30098. #endif
  30099. }
  30100. if (ret == 0) {
  30101. #ifdef WOLFSSL_QNX_CAAM
  30102. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), pubKey,
  30103. sizeof(pubKey), userB, ECC_SECP256R1);
  30104. #else
  30105. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), NULL, 0,
  30106. userB, ECC_SECP256R1);
  30107. #endif
  30108. if (ret != 0)
  30109. ret = WC_TEST_RET_ENC_EC(ret);
  30110. }
  30111. #ifdef WOLFSSL_ECIES_OLD
  30112. if (ret == 0) {
  30113. ret = wc_ecc_import_x963_ex(pubKey, sizeof(pubKey), userA,
  30114. ECC_SECP256R1);
  30115. if (ret != 0)
  30116. ret = WC_TEST_RET_ENC_EC(ret);
  30117. }
  30118. #endif
  30119. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30120. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30121. !defined(HAVE_SELFTEST)
  30122. if (ret == 0) {
  30123. ret = wc_ecc_set_rng(userB, rng);
  30124. if (ret != 0) {
  30125. ret = WC_TEST_RET_ENC_EC(ret);
  30126. }
  30127. }
  30128. #else
  30129. (void)rng;
  30130. #endif
  30131. if (ret == 0) {
  30132. ret = wc_ecc_decrypt(userB, tmpKey, enc_msg, sizeof(enc_msg), plain,
  30133. &plainSz, NULL);
  30134. if (ret != 0)
  30135. ret = WC_TEST_RET_ENC_EC(ret);
  30136. }
  30137. if (ret == 0) {
  30138. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30139. ret = WC_TEST_RET_ENC_NC;
  30140. }
  30141. }
  30142. if (userBInit)
  30143. wc_ecc_free(userB);
  30144. #ifdef WOLFSSL_ECIES_OLD
  30145. if (userAInit)
  30146. wc_ecc_free(userA);
  30147. #endif
  30148. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30149. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30150. #ifdef WOLFSSL_ECIES_OLD
  30151. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30152. #endif
  30153. #endif
  30154. return ret;
  30155. }
  30156. #endif
  30157. static wc_test_ret_t ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB,
  30158. byte encAlgo, byte kdfAlgo, byte macAlgo)
  30159. {
  30160. wc_test_ret_t ret = 0;
  30161. byte msg[48];
  30162. byte plain[48];
  30163. #ifdef WOLFSSL_ECIES_OLD
  30164. byte out[80];
  30165. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30166. byte out[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30167. #else
  30168. byte out[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30169. #endif
  30170. word32 outSz = sizeof(out);
  30171. word32 plainSz = sizeof(plain);
  30172. int i;
  30173. ecEncCtx* cliCtx = NULL;
  30174. ecEncCtx* srvCtx = NULL;
  30175. byte cliSalt[EXCHANGE_SALT_SZ];
  30176. byte srvSalt[EXCHANGE_SALT_SZ];
  30177. const byte* tmpSalt;
  30178. byte msg2[48];
  30179. byte plain2[48];
  30180. #ifdef WOLFSSL_ECIES_OLD
  30181. byte out2[80];
  30182. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30183. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30184. #else
  30185. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30186. #endif
  30187. word32 outSz2 = sizeof(out2);
  30188. word32 plainSz2 = sizeof(plain2);
  30189. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30190. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof(ecc_key), HEAP_HINT,
  30191. DYNAMIC_TYPE_TMP_BUFFER);
  30192. #else
  30193. ecc_key tmpKey[1];
  30194. #endif
  30195. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30196. if (tmpKey == NULL) {
  30197. ERROR_OUT(MEMORY_E, done);
  30198. }
  30199. #endif
  30200. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30201. if (ret != 0)
  30202. goto done;
  30203. /* set message to incrementing 0,1,2,etc... */
  30204. for (i = 0; i < (int)sizeof(msg); i++)
  30205. msg[i] = i;
  30206. /* encrypt msg to B */
  30207. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz, NULL);
  30208. if (ret != 0) {
  30209. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30210. }
  30211. #ifdef WOLFSSL_ECIES_OLD
  30212. tmpKey->dp = userA->dp;
  30213. ret = wc_ecc_copy_point(&userA->pubkey, &tmpKey->pubkey);
  30214. if (ret != 0) {
  30215. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30216. }
  30217. #endif
  30218. /* decrypt msg from A */
  30219. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, NULL);
  30220. if (ret != 0) {
  30221. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30222. }
  30223. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30224. ret = WC_TEST_RET_ENC_NC; goto done;
  30225. }
  30226. #ifndef WOLFSSL_ECIES_OLD
  30227. /* A decrypts msg (response) from B */
  30228. ret = wc_ecc_decrypt(userB, NULL, out, outSz, plain2, &plainSz2, NULL);
  30229. if (ret != 0)
  30230. goto done;
  30231. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30232. ret = WC_TEST_RET_ENC_NC; goto done;
  30233. }
  30234. #endif
  30235. /* let's verify message exchange works, A is client, B is server */
  30236. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30237. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30238. if (cliCtx == NULL || srvCtx == NULL) {
  30239. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30240. }
  30241. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30242. if (ret != 0)
  30243. goto done;
  30244. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30245. if (ret != 0)
  30246. goto done;
  30247. /* get salt to send to peer */
  30248. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30249. if (tmpSalt == NULL) {
  30250. ret = WC_TEST_RET_ENC_NC; goto done;
  30251. }
  30252. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30253. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30254. if (tmpSalt == NULL) {
  30255. ret = WC_TEST_RET_ENC_NC; goto done;
  30256. }
  30257. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30258. /* in actual use, we'd get the peer's salt over the transport */
  30259. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30260. if (ret != 0)
  30261. goto done;
  30262. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30263. if (ret != 0)
  30264. goto done;
  30265. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 11);
  30266. if (ret != 0)
  30267. goto done;
  30268. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 11);
  30269. if (ret != 0)
  30270. goto done;
  30271. /* get encrypted msg (request) to send to B */
  30272. outSz = sizeof(out);
  30273. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz,cliCtx);
  30274. if (ret != 0)
  30275. goto done;
  30276. #ifndef WOLFSSL_ECIES_OLD
  30277. wc_ecc_free(tmpKey);
  30278. #endif
  30279. /* B decrypts msg (request) from A */
  30280. plainSz = sizeof(plain);
  30281. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30282. if (ret != 0)
  30283. goto done;
  30284. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30285. ret = WC_TEST_RET_ENC_NC; goto done;
  30286. }
  30287. /* msg2 (response) from B to A */
  30288. for (i = 0; i < (int)sizeof(msg2); i++)
  30289. msg2[i] = i + sizeof(msg2);
  30290. /* get encrypted msg (response) to send to B */
  30291. ret = wc_ecc_encrypt(userB, userA, msg2, sizeof(msg2), out2,
  30292. &outSz2, srvCtx);
  30293. if (ret != 0)
  30294. goto done;
  30295. #ifdef WOLFSSL_ECIES_OLD
  30296. tmpKey->dp = userB->dp;
  30297. ret = wc_ecc_copy_point(&userB->pubkey, &tmpKey->pubkey);
  30298. if (ret != 0) {
  30299. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30300. }
  30301. #else
  30302. wc_ecc_free(tmpKey);
  30303. #endif
  30304. /* A decrypts msg (response) from B */
  30305. ret = wc_ecc_decrypt(userA, tmpKey, out2, outSz2, plain2, &plainSz2,
  30306. cliCtx);
  30307. if (ret != 0)
  30308. goto done;
  30309. if (XMEMCMP(plain2, msg2, sizeof(msg2)) != 0) {
  30310. ret = WC_TEST_RET_ENC_NC; goto done;
  30311. }
  30312. #if defined(HAVE_COMP_KEY) && \
  30313. (! defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  30314. /* Create new client and server contexts. */
  30315. wc_ecc_ctx_free(srvCtx);
  30316. wc_ecc_ctx_free(cliCtx);
  30317. /* let's verify message exchange works, A is client, B is server */
  30318. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30319. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30320. if (cliCtx == NULL || srvCtx == NULL) {
  30321. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30322. }
  30323. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30324. if (ret != 0)
  30325. goto done;
  30326. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30327. if (ret != 0)
  30328. goto done;
  30329. /* get salt to send to peer */
  30330. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30331. if (tmpSalt == NULL) {
  30332. ret = WC_TEST_RET_ENC_NC; goto done;
  30333. }
  30334. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30335. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30336. if (tmpSalt == NULL) {
  30337. ret = WC_TEST_RET_ENC_NC; goto done;
  30338. }
  30339. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30340. /* in actual use, we'd get the peer's salt over the transport */
  30341. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30342. if (ret != 0)
  30343. goto done;
  30344. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30345. if (ret != 0)
  30346. goto done;
  30347. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 12);
  30348. if (ret != 0)
  30349. goto done;
  30350. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 12);
  30351. if (ret != 0)
  30352. goto done;
  30353. /* get encrypted msg (request) to send to B - compressed public key */
  30354. outSz = sizeof(out);
  30355. ret = wc_ecc_encrypt_ex(userA, userB, msg, sizeof(msg), out, &outSz, cliCtx,
  30356. 1);
  30357. if (ret != 0)
  30358. goto done;
  30359. #ifndef WOLFSSL_ECIES_OLD
  30360. wc_ecc_free(tmpKey);
  30361. #endif
  30362. /* B decrypts msg (request) from A - out has a compressed public key */
  30363. plainSz = sizeof(plain);
  30364. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30365. if (ret != 0)
  30366. goto done;
  30367. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30368. ret = WC_TEST_RET_ENC_NC; goto done;
  30369. }
  30370. #endif /* HAVE_COMP_KEY && (!FIPS || FIPS>=5.3) */
  30371. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30372. (ECC_MIN_KEY_SZ <= 256) && defined(WOLFSSL_AES_128)
  30373. ret = ecc_encrypt_kat(rng);
  30374. #endif
  30375. done:
  30376. /* cleanup */
  30377. wc_ecc_ctx_free(srvCtx);
  30378. wc_ecc_ctx_free(cliCtx);
  30379. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30380. if (tmpKey != NULL) {
  30381. wc_ecc_free(tmpKey);
  30382. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30383. }
  30384. #else
  30385. wc_ecc_free(tmpKey);
  30386. #endif
  30387. return ret;
  30388. }
  30389. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30390. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void)
  30391. {
  30392. WC_RNG rng;
  30393. wc_test_ret_t ret;
  30394. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30395. ecc_key *userA;
  30396. ecc_key *userB;
  30397. #else
  30398. ecc_key userA[1];
  30399. ecc_key userB[1];
  30400. #endif
  30401. WOLFSSL_ENTER("ecc_encrypt_test");
  30402. #ifndef HAVE_FIPS
  30403. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30404. #else
  30405. ret = wc_InitRng(&rng);
  30406. #endif
  30407. if (ret != 0)
  30408. return WC_TEST_RET_ENC_EC(ret);
  30409. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30410. userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT,
  30411. DYNAMIC_TYPE_TMP_BUFFER);
  30412. userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT,
  30413. DYNAMIC_TYPE_TMP_BUFFER);
  30414. if ((userA == NULL) || (userB == NULL)) {
  30415. ERROR_OUT(MEMORY_E, done);
  30416. }
  30417. #endif
  30418. XMEMSET(userA, 0, sizeof *userA);
  30419. XMEMSET(userB, 0, sizeof *userB);
  30420. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30421. if (ret != 0)
  30422. goto done;
  30423. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30424. if (ret != 0)
  30425. goto done;
  30426. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userA);
  30427. #if defined(WOLFSSL_ASYNC_CRYPT)
  30428. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  30429. #endif
  30430. if (ret != 0){
  30431. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30432. }
  30433. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userB);
  30434. #if defined(WOLFSSL_ASYNC_CRYPT)
  30435. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  30436. #endif
  30437. if (ret != 0){
  30438. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30439. }
  30440. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30441. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30442. !defined(HAVE_SELFTEST)
  30443. ret = wc_ecc_set_rng(userA, &rng);
  30444. if (ret != 0) {
  30445. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30446. }
  30447. ret = wc_ecc_set_rng(userB, &rng);
  30448. if (ret != 0) {
  30449. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30450. }
  30451. #endif
  30452. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30453. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  30454. #ifdef WOLFSSL_AES_128
  30455. if (ret == 0) {
  30456. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30457. ecHKDF_SHA256, ecHMAC_SHA256);
  30458. if (ret != 0) {
  30459. printf("ECIES: AES_128_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30460. }
  30461. }
  30462. #ifdef HAVE_X963_KDF
  30463. if (ret == 0) {
  30464. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30465. ecKDF_X963_SHA256, ecHMAC_SHA256);
  30466. if (ret != 0) {
  30467. printf("ECIES: AES_128_CBC, KDF_X963_SHA256, HMAC_SHA256\n");
  30468. }
  30469. }
  30470. if (ret == 0) {
  30471. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30472. ecKDF_SHA256, ecHMAC_SHA256);
  30473. if (ret != 0) {
  30474. printf("ECIES: AES_128_CBC, KDF_SHA256, HMAC_SHA256\n");
  30475. }
  30476. }
  30477. #endif
  30478. #endif
  30479. #ifdef WOLFSSL_AES_256
  30480. if (ret == 0) {
  30481. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CBC,
  30482. ecHKDF_SHA256, ecHMAC_SHA256);
  30483. if (ret != 0) {
  30484. printf("ECIES: AES_256_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30485. }
  30486. }
  30487. #endif
  30488. #endif
  30489. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER)
  30490. #ifdef WOLFSSL_AES_128
  30491. if (ret == 0) {
  30492. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CTR,
  30493. ecHKDF_SHA256, ecHMAC_SHA256);
  30494. if (ret != 0) {
  30495. printf("ECIES: AES_128_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30496. }
  30497. }
  30498. #endif
  30499. #ifdef WOLFSSL_AES_256
  30500. if (ret == 0) {
  30501. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CTR,
  30502. ecHKDF_SHA256, ecHMAC_SHA256);
  30503. if (ret != 0) {
  30504. printf("ECIES: AES_256_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30505. }
  30506. }
  30507. #endif
  30508. #endif /* !NO_AES && WOLFSSL_AES_COUNTER */
  30509. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  30510. if (ret == 0) {
  30511. ret = ecc_ctx_kdf_salt_test(&rng, userA, userB);
  30512. }
  30513. #endif
  30514. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30515. done:
  30516. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30517. if (userA != NULL) {
  30518. wc_ecc_free(userA);
  30519. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30520. }
  30521. if (userB != NULL) {
  30522. wc_ecc_free(userB);
  30523. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30524. }
  30525. #else
  30526. wc_ecc_free(userB);
  30527. wc_ecc_free(userA);
  30528. #endif
  30529. wc_FreeRng(&rng);
  30530. return ret;
  30531. }
  30532. #endif /* HAVE_ECC_ENCRYPT && HAVE_AES_CBC && WOLFSSL_AES_128 */
  30533. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  30534. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  30535. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  30536. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  30537. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void)
  30538. {
  30539. size_t bytes;
  30540. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30541. ecc_key *cliKey = (ecc_key *)XMALLOC(sizeof *cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30542. ecc_key *servKey = (ecc_key *)XMALLOC(sizeof *servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30543. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof *tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30544. #else
  30545. ecc_key cliKey[1];
  30546. ecc_key servKey[1];
  30547. ecc_key tmpKey[1];
  30548. #endif
  30549. WC_RNG rng;
  30550. word32 idx = 0;
  30551. wc_test_ret_t ret;
  30552. /* pad our test message to 32 bytes so evenly divisible by AES_BLOCK_SZ */
  30553. byte in[] = "Everyone gets Friday off. ecc p";
  30554. word32 inLen = (word32)XSTRLEN((char*)in);
  30555. byte out[256];
  30556. byte plain[256];
  30557. int verify = 0;
  30558. word32 x;
  30559. WOLFSSL_ENTER("ecc_test_buffers");
  30560. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30561. if ((cliKey == NULL) || (servKey == NULL) || (tmpKey == NULL))
  30562. ERROR_OUT(MEMORY_E, done);
  30563. #endif
  30564. ret = wc_ecc_init_ex(cliKey, HEAP_HINT, devId);
  30565. if (ret != 0)
  30566. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30567. ret = wc_ecc_init_ex(servKey, HEAP_HINT, devId);
  30568. if (ret != 0)
  30569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30570. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30571. if (ret != 0)
  30572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30573. bytes = (size_t)sizeof_ecc_clikey_der_256;
  30574. /* place client key into ecc_key struct cliKey */
  30575. ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, cliKey,
  30576. (word32)bytes);
  30577. if (ret != 0)
  30578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30579. idx = 0;
  30580. bytes = (size_t)sizeof_ecc_key_der_256;
  30581. /* place server key into ecc_key struct servKey */
  30582. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, servKey,
  30583. (word32)bytes);
  30584. if (ret != 0)
  30585. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30586. #ifndef WC_NO_RNG
  30587. #ifndef HAVE_FIPS
  30588. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30589. #else
  30590. ret = wc_InitRng(&rng);
  30591. #endif
  30592. if (ret != 0)
  30593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30594. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30595. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30596. !defined(HAVE_SELFTEST)
  30597. ret = wc_ecc_set_rng(cliKey, &rng);
  30598. if (ret != 0)
  30599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30600. ret = wc_ecc_set_rng(servKey, &rng);
  30601. if (ret != 0)
  30602. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30603. #endif
  30604. #endif /* !WC_NO_RNG */
  30605. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_HKDF) && \
  30606. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  30607. {
  30608. word32 y;
  30609. /* test encrypt and decrypt if they're available */
  30610. x = sizeof(out);
  30611. ret = wc_ecc_encrypt(cliKey, servKey, in, sizeof(in), out, &x, NULL);
  30612. if (ret < 0)
  30613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30614. #ifdef WOLFSSL_ECIES_OLD
  30615. tmpKey->dp = cliKey->dp;
  30616. ret = wc_ecc_copy_point(&cliKey->pubkey, &tmpKey->pubkey);
  30617. if (ret != 0) {
  30618. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30619. }
  30620. #endif
  30621. y = sizeof(plain);
  30622. ret = wc_ecc_decrypt(servKey, tmpKey, out, x, plain, &y, NULL);
  30623. if (ret < 0)
  30624. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30625. if (XMEMCMP(plain, in, inLen))
  30626. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30627. }
  30628. #endif
  30629. x = sizeof(out);
  30630. do {
  30631. #if defined(WOLFSSL_ASYNC_CRYPT)
  30632. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30633. #endif
  30634. if (ret == 0)
  30635. ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, cliKey);
  30636. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30637. if (ret < 0)
  30638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30639. TEST_SLEEP();
  30640. XMEMSET(plain, 0, sizeof(plain));
  30641. do {
  30642. #if defined(WOLFSSL_ASYNC_CRYPT)
  30643. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30644. #endif
  30645. if (ret == 0)
  30646. ret = wc_ecc_verify_hash(out, x, in, inLen, &verify,
  30647. cliKey);
  30648. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30649. if (ret < 0)
  30650. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30651. if (verify != 1)
  30652. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30653. TEST_SLEEP();
  30654. #ifdef WOLFSSL_CERT_EXT
  30655. idx = 0;
  30656. bytes = sizeof_ecc_clikeypub_der_256;
  30657. ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &idx, cliKey,
  30658. (word32) bytes);
  30659. if (ret != 0)
  30660. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30661. #endif
  30662. ret = 0;
  30663. done:
  30664. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30665. if (cliKey != NULL) {
  30666. wc_ecc_free(cliKey);
  30667. XFREE(cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30668. }
  30669. if (servKey != NULL) {
  30670. wc_ecc_free(servKey);
  30671. XFREE(servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30672. }
  30673. if (tmpKey != NULL) {
  30674. wc_ecc_free(tmpKey);
  30675. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30676. }
  30677. #else
  30678. wc_ecc_free(cliKey);
  30679. wc_ecc_free(servKey);
  30680. wc_ecc_free(tmpKey);
  30681. #endif
  30682. wc_FreeRng(&rng);
  30683. return ret;
  30684. }
  30685. #endif /* USE_CERT_BUFFERS_256 && !WOLFSSL_ATECCX08A && !NO_ECC256 */
  30686. #endif /* HAVE_ECC */
  30687. #ifdef HAVE_CURVE25519
  30688. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  30689. defined(HAVE_CURVE25519_KEY_IMPORT)
  30690. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30691. #define X25519_TEST_CNT 5
  30692. #else
  30693. #define X25519_TEST_CNT 1
  30694. #endif
  30695. static wc_test_ret_t curve25519_overflow_test(void)
  30696. {
  30697. /* secret key for party a */
  30698. byte sa[X25519_TEST_CNT][32] = {
  30699. {
  30700. 0x8d,0xaf,0x6e,0x7a,0xc1,0xeb,0x8d,0x30,
  30701. 0x99,0x86,0xd3,0x90,0x47,0x96,0x21,0x3c,
  30702. 0x3a,0x75,0xc0,0x7b,0x75,0x01,0x75,0xa3,
  30703. 0x81,0x4b,0xff,0x5a,0xbc,0x96,0x87,0x28
  30704. },
  30705. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30706. {
  30707. 0x9d,0x63,0x5f,0xce,0xe2,0xe8,0xd7,0xfb,
  30708. 0x68,0x77,0x0e,0x44,0xd1,0xad,0x87,0x2b,
  30709. 0xf4,0x65,0x06,0xb7,0xbb,0xdb,0xbe,0x6e,
  30710. 0x02,0x43,0x24,0xc7,0x3d,0x7b,0x88,0x60
  30711. },
  30712. {
  30713. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30714. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30715. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30716. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30717. },
  30718. {
  30719. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30720. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30721. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30722. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30723. },
  30724. {
  30725. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30726. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30727. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30728. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30729. }
  30730. #endif
  30731. };
  30732. /* public key for party b */
  30733. byte pb[X25519_TEST_CNT][32] = {
  30734. {
  30735. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30736. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30737. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30738. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30739. },
  30740. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30741. {
  30742. /* 0xff first byte in original - invalid! */
  30743. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30744. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30745. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30746. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30747. },
  30748. {
  30749. 0x36,0x1a,0x74,0x87,0x28,0x59,0xe0,0xb6,
  30750. 0xe4,0x2b,0x17,0x9b,0x16,0xb0,0x3b,0xf8,
  30751. 0xb8,0x9f,0x2a,0x8f,0xc5,0x33,0x68,0x4f,
  30752. 0xde,0x4d,0xd8,0x80,0x63,0xe7,0xb4,0x0a
  30753. },
  30754. {
  30755. 0x00,0x80,0x38,0x59,0x19,0x3a,0x66,0x12,
  30756. 0xfd,0xa1,0xec,0x1c,0x40,0x84,0x40,0xbd,
  30757. 0x64,0x10,0x8b,0x53,0x81,0x21,0x03,0x2d,
  30758. 0x7d,0x33,0xb4,0x01,0x57,0x0d,0xe1,0x89
  30759. },
  30760. {
  30761. 0x1d,0xf8,0xf8,0x33,0x89,0x6c,0xb7,0xba,
  30762. 0x94,0x73,0xfa,0xc2,0x36,0xac,0xbe,0x49,
  30763. 0xaf,0x85,0x3e,0x93,0x5f,0xae,0xb2,0xc0,
  30764. 0xc8,0x80,0x8f,0x4a,0xaa,0xd3,0x55,0x2b
  30765. }
  30766. #endif
  30767. };
  30768. /* expected shared key */
  30769. byte ss[X25519_TEST_CNT][32] = {
  30770. {
  30771. 0x5c,0x4c,0x85,0x5f,0xfb,0x20,0x38,0xcc,
  30772. 0x55,0x16,0x5b,0x8a,0xa7,0xed,0x57,0x6e,
  30773. 0x35,0xaa,0x71,0x67,0x85,0x1f,0xb6,0x28,
  30774. 0x17,0x07,0x7b,0xda,0x76,0xdd,0xe0,0xb4
  30775. },
  30776. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30777. {
  30778. 0x33,0xf6,0xc1,0x34,0x62,0x92,0x06,0x02,
  30779. 0x95,0xdb,0x91,0x4c,0x5d,0x52,0x54,0xc7,
  30780. 0xd2,0x5b,0x24,0xb5,0x4f,0x33,0x59,0x79,
  30781. 0x9f,0x6d,0x7e,0x4a,0x4c,0x30,0xd6,0x38
  30782. },
  30783. {
  30784. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30785. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30786. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30787. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02
  30788. },
  30789. {
  30790. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30791. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30792. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30793. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09
  30794. },
  30795. {
  30796. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30797. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30798. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30799. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10
  30800. }
  30801. #endif
  30802. };
  30803. wc_test_ret_t ret = 0;
  30804. int i;
  30805. word32 y;
  30806. byte shared[32];
  30807. curve25519_key userA;
  30808. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  30809. for (i = 0; i < X25519_TEST_CNT; i++) {
  30810. if (wc_curve25519_import_private_raw(sa[i], sizeof(sa[i]), pb[i],
  30811. sizeof(pb[i]), &userA) != 0) {
  30812. ret = WC_TEST_RET_ENC_I(i); break;
  30813. }
  30814. /* test against known test vector */
  30815. XMEMSET(shared, 0, sizeof(shared));
  30816. y = sizeof(shared);
  30817. if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) {
  30818. ret = WC_TEST_RET_ENC_I(i); break;
  30819. }
  30820. if (XMEMCMP(ss[i], shared, y)) {
  30821. ret = WC_TEST_RET_ENC_I(i); break;
  30822. }
  30823. }
  30824. wc_curve25519_free(&userA);
  30825. return ret;
  30826. }
  30827. /* Test the wc_curve25519_check_public API.
  30828. *
  30829. * returns 0 on success and -ve on failure.
  30830. */
  30831. static wc_test_ret_t curve25519_check_public_test(void)
  30832. {
  30833. wc_test_ret_t ret;
  30834. /* Little-endian values that will fail */
  30835. byte fail_le[][CURVE25519_KEYSIZE] = {
  30836. {
  30837. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30838. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30839. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30840. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30841. },
  30842. {
  30843. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30844. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30845. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30846. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30847. },
  30848. {
  30849. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30850. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30851. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30852. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81
  30853. },
  30854. };
  30855. /* Big-endian values that will fail */
  30856. byte fail_be[][CURVE25519_KEYSIZE] = {
  30857. {
  30858. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30859. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30860. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30861. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30862. },
  30863. {
  30864. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30865. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30866. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30867. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30868. },
  30869. {
  30870. 0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30871. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30872. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30873. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30874. },
  30875. };
  30876. /* Good or valid public value */
  30877. byte good[CURVE25519_KEYSIZE] = {
  30878. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30879. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30880. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30881. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30882. };
  30883. int i;
  30884. /* Parameter checks */
  30885. /* NULL pointer */
  30886. ret = wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN);
  30887. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30888. return WC_TEST_RET_ENC_EC(ret);
  30889. }
  30890. ret = wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN);
  30891. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30892. return WC_TEST_RET_ENC_EC(ret);
  30893. }
  30894. /* Length of 0 treated differently to other invalid lengths for TLS */
  30895. ret = wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN);
  30896. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  30897. return WC_TEST_RET_ENC_EC(ret);
  30898. ret = wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN);
  30899. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  30900. return WC_TEST_RET_ENC_EC(ret);
  30901. /* Length not CURVE25519_KEYSIZE */
  30902. for (i = 1; i < CURVE25519_KEYSIZE + 2; i++) {
  30903. if (i == CURVE25519_KEYSIZE)
  30904. continue;
  30905. if (wc_curve25519_check_public(good, (word32)i, EC25519_LITTLE_ENDIAN) !=
  30906. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  30907. return WC_TEST_RET_ENC_I(i);
  30908. }
  30909. if (wc_curve25519_check_public(good, (word32)i, EC25519_BIG_ENDIAN) !=
  30910. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  30911. return WC_TEST_RET_ENC_I(i);
  30912. }
  30913. }
  30914. /* Little-endian fail cases */
  30915. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  30916. if (wc_curve25519_check_public(fail_le[i], CURVE25519_KEYSIZE,
  30917. EC25519_LITTLE_ENDIAN) == 0) {
  30918. return WC_TEST_RET_ENC_I(i);
  30919. }
  30920. }
  30921. /* Big-endian fail cases */
  30922. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  30923. if (wc_curve25519_check_public(fail_be[i], CURVE25519_KEYSIZE,
  30924. EC25519_BIG_ENDIAN) == 0) {
  30925. return WC_TEST_RET_ENC_I(i);
  30926. }
  30927. }
  30928. /* Check a valid public value works! */
  30929. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  30930. EC25519_LITTLE_ENDIAN);
  30931. if (ret != 0) {
  30932. return WC_TEST_RET_ENC_EC(ret);
  30933. }
  30934. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  30935. EC25519_BIG_ENDIAN);
  30936. if (ret != 0) {
  30937. return WC_TEST_RET_ENC_EC(ret);
  30938. }
  30939. return 0;
  30940. }
  30941. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  30942. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  30943. defined(HAVE_CURVE25519_KEY_IMPORT)
  30944. static wc_test_ret_t curve255519_der_test(void)
  30945. {
  30946. wc_test_ret_t ret = 0;
  30947. /* certs/statickeys/x25519.der */
  30948. const byte kCurve25519PrivDer[] = {
  30949. 0x30, 0x2E, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E,
  30950. 0x04, 0x22, 0x04, 0x20, 0x78, 0x8E, 0x31, 0x5C, 0x33, 0xA9, 0x19, 0xC0,
  30951. 0x5E, 0x36, 0x70, 0x1B, 0xA4, 0xE8, 0xEF, 0xC1, 0x89, 0x8C, 0xB3, 0x15,
  30952. 0xC6, 0x79, 0xD3, 0xAC, 0x22, 0x00, 0xAE, 0xFA, 0xB3, 0xB7, 0x0F, 0x78
  30953. };
  30954. /* certs/statickeys/x25519-pub.der */
  30955. const byte kCurve25519PubDer[] = {
  30956. 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00,
  30957. 0x09, 0xBC, 0x8C, 0xC7, 0x45, 0x0D, 0xC1, 0xC2, 0x02, 0x57, 0x9A, 0x68,
  30958. 0x3A, 0xFD, 0x7A, 0xA8, 0xA5, 0x2F, 0xF0, 0x99, 0x39, 0x98, 0xEA, 0x26,
  30959. 0xA2, 0x5B, 0x38, 0xFD, 0x96, 0xDB, 0x2A, 0x26
  30960. };
  30961. curve25519_key key;
  30962. byte output[128];
  30963. word32 outputSz = 128;
  30964. word32 idx;
  30965. ret = wc_curve25519_init_ex(&key, HEAP_HINT, devId);
  30966. if (ret != 0)
  30967. return WC_TEST_RET_ENC_EC(ret);
  30968. /* Test decode / encode of Curve25519 private key only */
  30969. if (ret == 0) {
  30970. idx = 0;
  30971. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx, &key,
  30972. (word32)sizeof(kCurve25519PrivDer));
  30973. if (ret < 0)
  30974. ret = WC_TEST_RET_ENC_EC(ret);
  30975. }
  30976. if (ret == 0) {
  30977. outputSz = (word32)sizeof(output);
  30978. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  30979. if (ret >= 0) {
  30980. outputSz = (word32)ret;
  30981. ret = 0;
  30982. }
  30983. else {
  30984. ret = WC_TEST_RET_ENC_EC(ret);
  30985. }
  30986. }
  30987. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  30988. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  30989. ret = WC_TEST_RET_ENC_NC;
  30990. }
  30991. /* Test decode / encode of Curve25519 public key only */
  30992. if (ret == 0) {
  30993. idx = 0;
  30994. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx, &key,
  30995. (word32)sizeof(kCurve25519PubDer));
  30996. if (ret < 0)
  30997. ret = WC_TEST_RET_ENC_EC(ret);
  30998. }
  30999. if (ret == 0) {
  31000. outputSz = (word32)sizeof(output);
  31001. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31002. if (ret >= 0) {
  31003. outputSz = (word32)ret;
  31004. ret = 0;
  31005. }
  31006. else {
  31007. ret = WC_TEST_RET_ENC_EC(ret);
  31008. }
  31009. }
  31010. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31011. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31012. ret = WC_TEST_RET_ENC_NC;
  31013. }
  31014. wc_curve25519_free(&key);
  31015. return ret;
  31016. }
  31017. #endif /* !NO_ASN && HAVE_CURVE25519_KEY_EXPORT && HAVE_CURVE25519_KEY_IMPORT */
  31018. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
  31019. {
  31020. WC_RNG rng;
  31021. wc_test_ret_t ret;
  31022. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31023. byte sharedA[32];
  31024. byte sharedB[32];
  31025. word32 y;
  31026. #endif
  31027. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31028. byte exportBuf[32];
  31029. #endif
  31030. word32 x = 0;
  31031. curve25519_key userA, userB, pubKey;
  31032. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31033. defined(HAVE_CURVE25519_KEY_IMPORT)
  31034. /* test vectors from
  31035. https://tools.ietf.org/html/draft-josefsson-tls-curve25519-03
  31036. */
  31037. /* secret key for party a */
  31038. byte sa[] = {
  31039. 0x5A,0xC9,0x9F,0x33,0x63,0x2E,0x5A,0x76,
  31040. 0x8D,0xE7,0xE8,0x1B,0xF8,0x54,0xC2,0x7C,
  31041. 0x46,0xE3,0xFB,0xF2,0xAB,0xBA,0xCD,0x29,
  31042. 0xEC,0x4A,0xFF,0x51,0x73,0x69,0xC6,0x60
  31043. };
  31044. /* public key for party a */
  31045. byte pa[] = {
  31046. 0x05,0x7E,0x23,0xEA,0x9F,0x1C,0xBE,0x8A,
  31047. 0x27,0x16,0x8F,0x6E,0x69,0x6A,0x79,0x1D,
  31048. 0xE6,0x1D,0xD3,0xAF,0x7A,0xCD,0x4E,0xEA,
  31049. 0xCC,0x6E,0x7B,0xA5,0x14,0xFD,0xA8,0x63
  31050. };
  31051. /* secret key for party b */
  31052. byte sb[] = {
  31053. 0x47,0xDC,0x3D,0x21,0x41,0x74,0x82,0x0E,
  31054. 0x11,0x54,0xB4,0x9B,0xC6,0xCD,0xB2,0xAB,
  31055. 0xD4,0x5E,0xE9,0x58,0x17,0x05,0x5D,0x25,
  31056. 0x5A,0xA3,0x58,0x31,0xB7,0x0D,0x32,0x60
  31057. };
  31058. /* public key for party b */
  31059. byte pb[] = {
  31060. 0x6E,0xB8,0x9D,0xA9,0x19,0x89,0xAE,0x37,
  31061. 0xC7,0xEA,0xC7,0x61,0x8D,0x9E,0x5C,0x49,
  31062. 0x51,0xDB,0xA1,0xD7,0x3C,0x28,0x5A,0xE1,
  31063. 0xCD,0x26,0xA8,0x55,0x02,0x0E,0xEF,0x04
  31064. };
  31065. /* expected shared key */
  31066. byte ss[] = {
  31067. 0x61,0x45,0x0C,0xD9,0x8E,0x36,0x01,0x6B,
  31068. 0x58,0x77,0x6A,0x89,0x7A,0x9F,0x0A,0xEF,
  31069. 0x73,0x8B,0x99,0xF0,0x94,0x68,0xB8,0xD6,
  31070. 0xB8,0x51,0x11,0x84,0xD5,0x34,0x94,0xAB
  31071. };
  31072. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  31073. (void)x;
  31074. WOLFSSL_ENTER("curve25519_test");
  31075. #ifndef HAVE_FIPS
  31076. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31077. #else
  31078. ret = wc_InitRng(&rng);
  31079. #endif
  31080. if (ret != 0)
  31081. return WC_TEST_RET_ENC_EC(ret);
  31082. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  31083. wc_curve25519_init_ex(&userB, HEAP_HINT, devId);
  31084. wc_curve25519_init_ex(&pubKey, HEAP_HINT, devId);
  31085. /* make curve25519 keys */
  31086. ret = wc_curve25519_make_key(&rng, 32, &userA);
  31087. if (ret != 0)
  31088. return WC_TEST_RET_ENC_EC(ret);
  31089. ret = wc_curve25519_make_key(&rng, 32, &userB);
  31090. if (ret != 0)
  31091. return WC_TEST_RET_ENC_EC(ret);
  31092. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31093. /* find shared secret key */
  31094. x = sizeof(sharedA);
  31095. if ((ret = wc_curve25519_shared_secret(&userA, &userB, sharedA, &x)) != 0) {
  31096. printf("wc_curve25519_shared_secret 1 failed\n");
  31097. return WC_TEST_RET_ENC_EC(ret);
  31098. }
  31099. y = sizeof(sharedB);
  31100. if ((ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y)) != 0) {
  31101. printf("wc_curve25519_shared_secret 2 failed\n");
  31102. return WC_TEST_RET_ENC_EC(ret);
  31103. }
  31104. /* compare shared secret keys to test they are the same */
  31105. if (y != x)
  31106. return WC_TEST_RET_ENC_NC;
  31107. if (XMEMCMP(sharedA, sharedB, x))
  31108. return WC_TEST_RET_ENC_NC;
  31109. #endif
  31110. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31111. /* export a public key and import it for another user */
  31112. x = sizeof(exportBuf);
  31113. ret = wc_curve25519_export_public(&userA, exportBuf, &x);
  31114. if (ret != 0)
  31115. return WC_TEST_RET_ENC_EC(ret);
  31116. #ifdef HAVE_CURVE25519_KEY_IMPORT
  31117. ret = wc_curve25519_import_public(exportBuf, x, &pubKey);
  31118. if (ret != 0)
  31119. return WC_TEST_RET_ENC_EC(ret);
  31120. #endif
  31121. #endif
  31122. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31123. defined(HAVE_CURVE25519_KEY_IMPORT)
  31124. /* test shared key after importing a public key */
  31125. XMEMSET(sharedB, 0, sizeof(sharedB));
  31126. y = sizeof(sharedB);
  31127. if (wc_curve25519_shared_secret(&userB, &pubKey, sharedB, &y) != 0) {
  31128. return WC_TEST_RET_ENC_NC;
  31129. }
  31130. if (XMEMCMP(sharedA, sharedB, y))
  31131. return WC_TEST_RET_ENC_NC;
  31132. /* import RFC test vectors and compare shared key */
  31133. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31134. &userA);
  31135. if (ret != 0)
  31136. return WC_TEST_RET_ENC_EC(ret);
  31137. ret = wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb),
  31138. &userB);
  31139. if (ret != 0)
  31140. return WC_TEST_RET_ENC_EC(ret);
  31141. /* test against known test vector */
  31142. XMEMSET(sharedB, 0, sizeof(sharedB));
  31143. y = sizeof(sharedB);
  31144. ret = wc_curve25519_shared_secret(&userA, &userB, sharedB, &y);
  31145. if (ret != 0)
  31146. return WC_TEST_RET_ENC_EC(ret);
  31147. if (XMEMCMP(ss, sharedB, y))
  31148. return WC_TEST_RET_ENC_NC;
  31149. /* test swapping roles of keys and generating same shared key */
  31150. XMEMSET(sharedB, 0, sizeof(sharedB));
  31151. y = sizeof(sharedB);
  31152. ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y);
  31153. if (ret != 0)
  31154. return WC_TEST_RET_ENC_EC(ret);
  31155. if (XMEMCMP(ss, sharedB, y))
  31156. return WC_TEST_RET_ENC_NC;
  31157. /* test with 1 generated key and 1 from known test vector */
  31158. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31159. &userA);
  31160. if (ret != 0)
  31161. return WC_TEST_RET_ENC_EC(ret);
  31162. wc_curve25519_free(&userB);
  31163. wc_curve25519_init_ex(&userB, HEAP_HINT, devId);
  31164. ret = wc_curve25519_make_key(&rng, 32, &userB);
  31165. if (ret != 0)
  31166. return WC_TEST_RET_ENC_EC(ret);
  31167. x = sizeof(sharedA);
  31168. ret = wc_curve25519_shared_secret(&userA, &userB, sharedA, &x);
  31169. if (ret != 0)
  31170. return WC_TEST_RET_ENC_EC(ret);
  31171. y = sizeof(sharedB);
  31172. ret = wc_curve25519_shared_secret(&userB, &userA, sharedB, &y);
  31173. if (ret != 0)
  31174. return WC_TEST_RET_ENC_EC(ret);
  31175. /* compare shared secret keys to test they are the same */
  31176. if (y != x)
  31177. return WC_TEST_RET_ENC_NC;
  31178. if (XMEMCMP(sharedA, sharedB, x))
  31179. return WC_TEST_RET_ENC_NC;
  31180. ret = curve25519_overflow_test();
  31181. if (ret != 0)
  31182. return ret;
  31183. ret = curve25519_check_public_test();
  31184. if (ret != 0)
  31185. return ret;
  31186. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31187. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31188. defined(HAVE_CURVE25519_KEY_IMPORT)
  31189. ret = curve255519_der_test();
  31190. if (ret != 0)
  31191. return ret;
  31192. #endif
  31193. /* clean up keys when done */
  31194. wc_curve25519_free(&pubKey);
  31195. wc_curve25519_free(&userB);
  31196. wc_curve25519_free(&userA);
  31197. wc_FreeRng(&rng);
  31198. return 0;
  31199. }
  31200. #endif /* HAVE_CURVE25519 */
  31201. #ifdef HAVE_ED25519
  31202. #ifdef WOLFSSL_TEST_CERT
  31203. static wc_test_ret_t ed25519_test_cert(void)
  31204. {
  31205. DecodedCert cert[2];
  31206. DecodedCert* serverCert = NULL;
  31207. DecodedCert* caCert = NULL;
  31208. #ifdef HAVE_ED25519_VERIFY
  31209. ed25519_key key;
  31210. ed25519_key* pubKey = NULL;
  31211. int verify;
  31212. #endif /* HAVE_ED25519_VERIFY */
  31213. wc_test_ret_t ret;
  31214. byte* tmp;
  31215. size_t bytes;
  31216. XFILE file;
  31217. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31218. if (tmp == NULL) {
  31219. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31220. }
  31221. #ifdef USE_CERT_BUFFERS_256
  31222. XMEMCPY(tmp, ca_ed25519_cert, sizeof_ca_ed25519_cert);
  31223. bytes = sizeof_ca_ed25519_cert;
  31224. #elif !defined(NO_FILESYSTEM)
  31225. file = XFOPEN(caEd25519Cert, "rb");
  31226. if (file == NULL) {
  31227. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31228. }
  31229. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31230. XFCLOSE(file);
  31231. if (bytes == 0)
  31232. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31233. #else
  31234. /* No certificate to use. */
  31235. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31236. #endif
  31237. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  31238. caCert = &cert[0];
  31239. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  31240. if (ret != 0)
  31241. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31242. #ifdef USE_CERT_BUFFERS_256
  31243. XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert);
  31244. bytes = sizeof_server_ed25519_cert;
  31245. #elif !defined(NO_FILESYSTEM)
  31246. file = XFOPEN(serverEd25519Cert, "rb");
  31247. if (file == NULL) {
  31248. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31249. }
  31250. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31251. XFCLOSE(file);
  31252. if (bytes == 0)
  31253. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31254. #else
  31255. /* No certificate to use. */
  31256. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31257. #endif
  31258. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  31259. serverCert = &cert[1];
  31260. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  31261. if (ret != 0)
  31262. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31263. #ifdef HAVE_ED25519_VERIFY
  31264. ret = wc_ed25519_init(&key);
  31265. if (ret < 0)
  31266. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31267. pubKey = &key;
  31268. ret = wc_ed25519_import_public(caCert->publicKey, caCert->pubKeySize,
  31269. pubKey);
  31270. if (ret < 0)
  31271. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31272. ret = wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength,
  31273. serverCert->source + serverCert->certBegin,
  31274. serverCert->sigIndex - serverCert->certBegin,
  31275. &verify, pubKey);
  31276. if (ret < 0 || verify != 1)
  31277. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31278. #endif /* HAVE_ED25519_VERIFY */
  31279. done:
  31280. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31281. #ifdef HAVE_ED25519_VERIFY
  31282. wc_ed25519_free(pubKey);
  31283. #endif /* HAVE_ED25519_VERIFY */
  31284. if (caCert != NULL)
  31285. FreeDecodedCert(caCert);
  31286. if (serverCert != NULL)
  31287. FreeDecodedCert(serverCert);
  31288. return ret;
  31289. }
  31290. static wc_test_ret_t ed25519_test_make_cert(void)
  31291. {
  31292. WC_RNG rng;
  31293. Cert cert;
  31294. DecodedCert decode;
  31295. ed25519_key key;
  31296. ed25519_key* privKey = NULL;
  31297. wc_test_ret_t ret = 0;
  31298. byte* tmp = NULL;
  31299. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  31300. #ifndef HAVE_FIPS
  31301. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31302. #else
  31303. ret = wc_InitRng(&rng);
  31304. #endif
  31305. if (ret != 0)
  31306. return WC_TEST_RET_ENC_EC(ret);
  31307. wc_ed25519_init(&key);
  31308. privKey = &key;
  31309. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, privKey);
  31310. cert.daysValid = 365 * 2;
  31311. cert.selfSigned = 1;
  31312. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  31313. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  31314. cert.isCA = 0;
  31315. #ifdef WOLFSSL_CERT_EXT
  31316. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  31317. if (ret < 0)
  31318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31319. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31320. if (ret < 0)
  31321. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31322. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31323. if (ret < 0)
  31324. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31325. #endif
  31326. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31327. if (tmp == NULL) {
  31328. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31329. }
  31330. cert.sigType = CTC_ED25519;
  31331. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng);
  31332. if (ret < 0)
  31333. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31334. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF,
  31335. ED25519_TYPE, privKey, &rng);
  31336. if (ret < 0)
  31337. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31338. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  31339. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  31340. FreeDecodedCert(&decode);
  31341. if (ret != 0)
  31342. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31343. done:
  31344. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31345. wc_ed25519_free(privKey);
  31346. wc_FreeRng(&rng);
  31347. return ret;
  31348. }
  31349. #endif /* WOLFSSL_TEST_CERT */
  31350. #if defined(HAVE_ED25519_KEY_IMPORT)
  31351. static wc_test_ret_t ed25519_test_check_key(void)
  31352. {
  31353. /* Fails to find x-ordinate from this y-ordinate. */
  31354. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  31355. 0x40,
  31356. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31357. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31358. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31359. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31360. };
  31361. /* Y-ordinate value larger than prime. */
  31362. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  31363. 0x40,
  31364. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31365. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31366. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31367. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31368. };
  31369. /* Y-ordinate value equal to prime. */
  31370. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  31371. 0x40,
  31372. 0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31373. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31374. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31375. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31376. };
  31377. /* Y-ordinate value equal to prime - 1. */
  31378. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  31379. 0x40,
  31380. 0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31381. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31382. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31383. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31384. };
  31385. ed25519_key key;
  31386. int ret;
  31387. int res = 0;
  31388. /* Initialize key for use. */
  31389. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31390. if (ret != 0) {
  31391. return WC_TEST_RET_ENC_NC;
  31392. }
  31393. /* Load bad public key only and perform checks. */
  31394. ret = wc_ed25519_import_public(key_bad_y, ED25519_PUB_KEY_SIZE + 1, &key);
  31395. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31396. res = WC_TEST_RET_ENC_NC;
  31397. }
  31398. if (res == 0) {
  31399. /* Load bad public key only and perform checks. */
  31400. ret = wc_ed25519_import_public(key_bad_y_max, ED25519_PUB_KEY_SIZE + 1,
  31401. &key);
  31402. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31403. res = WC_TEST_RET_ENC_NC;
  31404. }
  31405. }
  31406. if (res == 0) {
  31407. /* Load bad public key only and perform checks. */
  31408. ret = wc_ed25519_import_public(key_bad_y_is_p, ED25519_PUB_KEY_SIZE + 1,
  31409. &key);
  31410. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31411. res = WC_TEST_RET_ENC_NC;
  31412. }
  31413. }
  31414. if (res == 0) {
  31415. /* Load good public key only and perform checks. */
  31416. ret = wc_ed25519_import_public(key_y_is_p_minus_1,
  31417. ED25519_PUB_KEY_SIZE + 1, &key);
  31418. if (ret != 0) {
  31419. res = WC_TEST_RET_ENC_NC;
  31420. }
  31421. }
  31422. /* Dispose of key. */
  31423. wc_ed25519_free(&key);
  31424. return res;
  31425. }
  31426. #endif
  31427. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31428. defined(HAVE_ED25519_KEY_IMPORT)
  31429. static wc_test_ret_t ed25519ctx_test(void)
  31430. {
  31431. wc_test_ret_t ret;
  31432. byte out[ED25519_SIG_SIZE];
  31433. word32 outlen;
  31434. #ifdef HAVE_ED25519_VERIFY
  31435. int verify = 0;
  31436. #endif /* HAVE_ED25519_VERIFY */
  31437. ed25519_key key;
  31438. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  31439. 0x03,0x05,0x33,0x4e,0x38,0x1a,0xf7,0x8f,
  31440. 0x14,0x1c,0xb6,0x66,0xf6,0x19,0x9f,0x57,
  31441. 0xbc,0x34,0x95,0x33,0x5a,0x25,0x6a,0x95,
  31442. 0xbd,0x2a,0x55,0xbf,0x54,0x66,0x63,0xf6
  31443. };
  31444. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  31445. 0xdf,0xc9,0x42,0x5e,0x4f,0x96,0x8f,0x7f,
  31446. 0x0c,0x29,0xf0,0x25,0x9c,0xf5,0xf9,0xae,
  31447. 0xd6,0x85,0x1c,0x2b,0xb4,0xad,0x8b,0xfb,
  31448. 0x86,0x0c,0xfe,0xe0,0xab,0x24,0x82,0x92
  31449. };
  31450. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx1[] = {
  31451. 0x55,0xa4,0xcc,0x2f,0x70,0xa5,0x4e,0x04,
  31452. 0x28,0x8c,0x5f,0x4c,0xd1,0xe4,0x5a,0x7b,
  31453. 0xb5,0x20,0xb3,0x62,0x92,0x91,0x18,0x76,
  31454. 0xca,0xda,0x73,0x23,0x19,0x8d,0xd8,0x7a,
  31455. 0x8b,0x36,0x95,0x0b,0x95,0x13,0x00,0x22,
  31456. 0x90,0x7a,0x7f,0xb7,0xc4,0xe9,0xb2,0xd5,
  31457. 0xf6,0xcc,0xa6,0x85,0xa5,0x87,0xb4,0xb2,
  31458. 0x1f,0x4b,0x88,0x8e,0x4e,0x7e,0xdb,0x0d
  31459. };
  31460. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx2[] = {
  31461. 0xcc,0x5e,0x63,0xa2,0x7e,0x94,0xaf,0xd3,
  31462. 0x41,0x83,0x38,0xd2,0x48,0x6f,0xa9,0x2a,
  31463. 0xf9,0x91,0x7c,0x2d,0x98,0x9e,0x06,0xe5,
  31464. 0x02,0x77,0x72,0x1c,0x34,0x38,0x18,0xb4,
  31465. 0x21,0x96,0xbc,0x29,0x2e,0x68,0xf3,0x4d,
  31466. 0x85,0x9b,0xbe,0xad,0x17,0x9f,0x54,0x54,
  31467. 0x2d,0x4b,0x04,0xdc,0xfb,0xfa,0x4a,0x68,
  31468. 0x4e,0x39,0x50,0xfb,0x1c,0xcd,0x8d,0x0d
  31469. };
  31470. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  31471. 0xf7,0x26,0x93,0x6d,0x19,0xc8,0x00,0x49,
  31472. 0x4e,0x3f,0xda,0xff,0x20,0xb2,0x76,0xa8
  31473. };
  31474. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  31475. 0x66,0x6f,0x6f
  31476. };
  31477. outlen = sizeof(out);
  31478. XMEMSET(out, 0, sizeof(out));
  31479. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31480. if (ret != 0)
  31481. return 10800;
  31482. ret = wc_ed25519_import_private_key(sKeyCtx, ED25519_KEY_SIZE, pKeyCtx,
  31483. sizeof(pKeyCtx), &key);
  31484. if (ret == 0)
  31485. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31486. contextCtx, sizeof(contextCtx));
  31487. if (ret == 0 && XMEMCMP(out, sigCtx1, 64) != 0)
  31488. ret = WC_TEST_RET_ENC_NC;
  31489. #if defined(HAVE_ED25519_VERIFY)
  31490. /* test verify on good msg */
  31491. if (ret == 0)
  31492. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31493. &verify, &key, contextCtx, sizeof(contextCtx));
  31494. if (ret == 0 && verify != 1)
  31495. ret = WC_TEST_RET_ENC_NC;
  31496. #endif
  31497. if (ret == 0)
  31498. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31499. NULL, 0);
  31500. if (ret == 0 && XMEMCMP(out, sigCtx2, 64) != 0)
  31501. ret = WC_TEST_RET_ENC_NC;
  31502. #if defined(HAVE_ED25519_VERIFY)
  31503. /* test verify on good msg */
  31504. if (ret == 0)
  31505. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31506. &verify, &key, NULL, 0);
  31507. if (ret == 0 && verify != 1)
  31508. ret = WC_TEST_RET_ENC_NC;
  31509. #endif
  31510. wc_ed25519_free(&key);
  31511. return ret;
  31512. }
  31513. static wc_test_ret_t ed25519ph_test(void)
  31514. {
  31515. wc_test_ret_t ret = 0;
  31516. byte out[ED25519_SIG_SIZE];
  31517. word32 outlen;
  31518. #ifdef HAVE_ED25519_VERIFY
  31519. int verify = 0;
  31520. #endif /* HAVE_ED25519_VERIFY */
  31521. ed25519_key key;
  31522. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  31523. 0x83,0x3f,0xe6,0x24,0x09,0x23,0x7b,0x9d,
  31524. 0x62,0xec,0x77,0x58,0x75,0x20,0x91,0x1e,
  31525. 0x9a,0x75,0x9c,0xec,0x1d,0x19,0x75,0x5b,
  31526. 0x7d,0xa9,0x01,0xb9,0x6d,0xca,0x3d,0x42
  31527. };
  31528. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  31529. 0xec,0x17,0x2b,0x93,0xad,0x5e,0x56,0x3b,
  31530. 0xf4,0x93,0x2c,0x70,0xe1,0x24,0x50,0x34,
  31531. 0xc3,0x54,0x67,0xef,0x2e,0xfd,0x4d,0x64,
  31532. 0xeb,0xf8,0x19,0x68,0x34,0x67,0xe2,0xbf
  31533. };
  31534. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  31535. 0x98,0xa7,0x02,0x22,0xf0,0xb8,0x12,0x1a,
  31536. 0xa9,0xd3,0x0f,0x81,0x3d,0x68,0x3f,0x80,
  31537. 0x9e,0x46,0x2b,0x46,0x9c,0x7f,0xf8,0x76,
  31538. 0x39,0x49,0x9b,0xb9,0x4e,0x6d,0xae,0x41,
  31539. 0x31,0xf8,0x50,0x42,0x46,0x3c,0x2a,0x35,
  31540. 0x5a,0x20,0x03,0xd0,0x62,0xad,0xf5,0xaa,
  31541. 0xa1,0x0b,0x8c,0x61,0xe6,0x36,0x06,0x2a,
  31542. 0xaa,0xd1,0x1c,0x2a,0x26,0x08,0x34,0x06
  31543. };
  31544. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  31545. 0xe0,0x39,0x70,0x2b,0x4c,0x25,0x95,0xa6,
  31546. 0xa5,0x41,0xac,0x85,0x09,0x23,0x6e,0x29,
  31547. 0x90,0x47,0x47,0x95,0x33,0x0c,0x9b,0x34,
  31548. 0xa7,0x5f,0x58,0xa6,0x60,0x12,0x9e,0x08,
  31549. 0xfd,0x73,0x69,0x43,0xfb,0x19,0x43,0xa5,
  31550. 0x57,0x20,0xb9,0xe0,0x95,0x7b,0x1e,0xd6,
  31551. 0x73,0x48,0x16,0x61,0x9f,0x13,0x88,0xf4,
  31552. 0x3f,0x73,0xe6,0xe3,0xba,0xa8,0x1c,0x0e
  31553. };
  31554. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  31555. 0x61,0x62,0x63
  31556. };
  31557. /* SHA-512 hash of msgPh */
  31558. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  31559. 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
  31560. 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
  31561. 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
  31562. 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
  31563. 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
  31564. 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
  31565. 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
  31566. 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f
  31567. };
  31568. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  31569. 0x66,0x6f,0x6f
  31570. };
  31571. outlen = sizeof(out);
  31572. XMEMSET(out, 0, sizeof(out));
  31573. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31574. if (ret != 0)
  31575. return WC_TEST_RET_ENC_EC(ret);
  31576. ret = wc_ed25519_import_private_key(sKeyPh, ED25519_KEY_SIZE, pKeyPh,
  31577. sizeof(pKeyPh), &key);
  31578. if (ret == 0)
  31579. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31580. NULL, 0);
  31581. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31582. ret = WC_TEST_RET_ENC_NC;
  31583. #if defined(HAVE_ED25519_VERIFY)
  31584. /* test verify on good msg */
  31585. if (ret == 0)
  31586. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh),
  31587. &verify, &key, NULL, 0);
  31588. if (ret == 0 && verify != 1)
  31589. ret = WC_TEST_RET_ENC_NC;
  31590. #endif
  31591. if (ret == 0)
  31592. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31593. contextPh2, sizeof(contextPh2));
  31594. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31595. ret = WC_TEST_RET_ENC_NC;
  31596. #if defined(HAVE_ED25519_VERIFY)
  31597. /* test verify on good msg */
  31598. if (ret == 0)
  31599. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify,
  31600. &key, contextPh2, sizeof(contextPh2));
  31601. if (ret == 0 && verify != 1)
  31602. ret = WC_TEST_RET_ENC_NC;
  31603. #endif
  31604. if (ret == 0)
  31605. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31606. NULL, 0);
  31607. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31608. ret = WC_TEST_RET_ENC_NC;
  31609. #if defined(HAVE_ED25519_VERIFY)
  31610. if (ret == 0)
  31611. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh),
  31612. &verify, &key, NULL, 0);
  31613. if (ret == 0 && verify != 1)
  31614. ret = WC_TEST_RET_ENC_NC;
  31615. #endif
  31616. if (ret == 0)
  31617. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31618. contextPh2, sizeof(contextPh2));
  31619. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31620. ret = WC_TEST_RET_ENC_NC;
  31621. #if defined(HAVE_ED25519_VERIFY)
  31622. if (ret == 0)
  31623. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  31624. &key, contextPh2, sizeof(contextPh2));
  31625. if (ret == 0 && verify != 1)
  31626. ret = WC_TEST_RET_ENC_NC;
  31627. #endif
  31628. wc_ed25519_free(&key);
  31629. return ret;
  31630. }
  31631. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31632. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
  31633. {
  31634. wc_test_ret_t ret;
  31635. WC_RNG rng;
  31636. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  31637. defined(HAVE_ED25519_KEY_IMPORT)
  31638. byte out[ED25519_SIG_SIZE];
  31639. byte exportPKey[ED25519_KEY_SIZE];
  31640. byte exportSKey[ED25519_KEY_SIZE];
  31641. word32 exportPSz;
  31642. word32 exportSSz;
  31643. int i;
  31644. word32 outlen;
  31645. #ifdef HAVE_ED25519_VERIFY
  31646. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  31647. int j;
  31648. #endif
  31649. int verify;
  31650. #endif /* HAVE_ED25519_VERIFY */
  31651. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31652. word32 keySz, sigSz;
  31653. ed25519_key key;
  31654. ed25519_key key2;
  31655. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31656. defined(HAVE_ED25519_KEY_IMPORT)
  31657. /* test vectors from
  31658. https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02
  31659. */
  31660. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  31661. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31662. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31663. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31664. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31665. };
  31666. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  31667. 0x4c,0xcd,0x08,0x9b,0x28,0xff,0x96,0xda,
  31668. 0x9d,0xb6,0xc3,0x46,0xec,0x11,0x4e,0x0f,
  31669. 0x5b,0x8a,0x31,0x9f,0x35,0xab,0xa6,0x24,
  31670. 0xda,0x8c,0xf6,0xed,0x4f,0xb8,0xa6,0xfb
  31671. };
  31672. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  31673. 0xc5,0xaa,0x8d,0xf4,0x3f,0x9f,0x83,0x7b,
  31674. 0xed,0xb7,0x44,0x2f,0x31,0xdc,0xb7,0xb1,
  31675. 0x66,0xd3,0x85,0x35,0x07,0x6f,0x09,0x4b,
  31676. 0x85,0xce,0x3a,0x2e,0x0b,0x44,0x58,0xf7
  31677. };
  31678. /* uncompressed test */
  31679. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  31680. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31681. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31682. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31683. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31684. };
  31685. /* compressed prefix test */
  31686. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  31687. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31688. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31689. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31690. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31691. };
  31692. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  31693. 0xf5,0xe5,0x76,0x7c,0xf1,0x53,0x31,0x95,
  31694. 0x17,0x63,0x0f,0x22,0x68,0x76,0xb8,0x6c,
  31695. 0x81,0x60,0xcc,0x58,0x3b,0xc0,0x13,0x74,
  31696. 0x4c,0x6b,0xf2,0x55,0xf5,0xcc,0x0e,0xe5
  31697. };
  31698. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  31699. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  31700. 0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31701. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31702. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31703. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31704. };
  31705. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  31706. 0x3d,0x40,0x17,0xc3,0xe8,0x43,0x89,0x5a,
  31707. 0x92,0xb7,0x0a,0xa7,0x4d,0x1b,0x7e,0xbc,
  31708. 0x9c,0x98,0x2c,0xcf,0x2e,0xc4,0x96,0x8c,
  31709. 0xc0,0xcd,0x55,0xf1,0x2a,0xf4,0x66,0x0c
  31710. };
  31711. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  31712. 0xfc,0x51,0xcd,0x8e,0x62,0x18,0xa1,0xa3,
  31713. 0x8d,0xa4,0x7e,0xd0,0x02,0x30,0xf0,0x58,
  31714. 0x08,0x16,0xed,0x13,0xba,0x33,0x03,0xac,
  31715. 0x5d,0xeb,0x91,0x15,0x48,0x90,0x80,0x25
  31716. };
  31717. /* uncompressed test */
  31718. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  31719. 0x04,0x55,0xd0,0xe0,0x9a,0x2b,0x9d,0x34,
  31720. 0x29,0x22,0x97,0xe0,0x8d,0x60,0xd0,0xf6,
  31721. 0x20,0xc5,0x13,0xd4,0x72,0x53,0x18,0x7c,
  31722. 0x24,0xb1,0x27,0x86,0xbd,0x77,0x76,0x45,
  31723. 0xce,0x1a,0x51,0x07,0xf7,0x68,0x1a,0x02,
  31724. 0xaf,0x25,0x23,0xa6,0xda,0xf3,0x72,0xe1,
  31725. 0x0e,0x3a,0x07,0x64,0xc9,0xd3,0xfe,0x4b,
  31726. 0xd5,0xb7,0x0a,0xb1,0x82,0x01,0x98,0x5a,
  31727. 0xd7
  31728. };
  31729. /* compressed prefix */
  31730. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  31731. 0x40,0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31732. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31733. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31734. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31735. };
  31736. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  31737. 0x27,0x81,0x17,0xfc,0x14,0x4c,0x72,0x34,
  31738. 0x0f,0x67,0xd0,0xf2,0x31,0x6e,0x83,0x86,
  31739. 0xce,0xff,0xbf,0x2b,0x24,0x28,0xc9,0xc5,
  31740. 0x1f,0xef,0x7c,0x59,0x7f,0x1d,0x42,0x6e
  31741. };
  31742. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  31743. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  31744. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  31745. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  31746. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  31747. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  31748. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  31749. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  31750. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  31751. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  31752. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  31753. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  31754. };
  31755. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  31756. 0x92,0xa0,0x09,0xa9,0xf0,0xd4,0xca,0xb8,
  31757. 0x72,0x0e,0x82,0x0b,0x5f,0x64,0x25,0x40,
  31758. 0xa2,0xb2,0x7b,0x54,0x16,0x50,0x3f,0x8f,
  31759. 0xb3,0x76,0x22,0x23,0xeb,0xdb,0x69,0xda,
  31760. 0x08,0x5a,0xc1,0xe4,0x3e,0x15,0x99,0x6e,
  31761. 0x45,0x8f,0x36,0x13,0xd0,0xf1,0x1d,0x8c,
  31762. 0x38,0x7b,0x2e,0xae,0xb4,0x30,0x2a,0xee,
  31763. 0xb0,0x0d,0x29,0x16,0x12,0xbb,0x0c,0x00
  31764. };
  31765. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  31766. 0x62,0x91,0xd6,0x57,0xde,0xec,0x24,0x02,
  31767. 0x48,0x27,0xe6,0x9c,0x3a,0xbe,0x01,0xa3,
  31768. 0x0c,0xe5,0x48,0xa2,0x84,0x74,0x3a,0x44,
  31769. 0x5e,0x36,0x80,0xd7,0xdb,0x5a,0xc3,0xac,
  31770. 0x18,0xff,0x9b,0x53,0x8d,0x16,0xf2,0x90,
  31771. 0xae,0x67,0xf7,0x60,0x98,0x4d,0xc6,0x59,
  31772. 0x4a,0x7c,0x15,0xe9,0x71,0x6e,0xd2,0x8d,
  31773. 0xc0,0x27,0xbe,0xce,0xea,0x1e,0xc4,0x0a
  31774. };
  31775. /* uncompressed test */
  31776. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  31777. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  31778. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  31779. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  31780. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  31781. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  31782. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  31783. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  31784. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  31785. };
  31786. /* compressed prefix */
  31787. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  31788. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  31789. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  31790. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  31791. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  31792. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  31793. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  31794. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  31795. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  31796. };
  31797. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  31798. 0x0a,0xab,0x4c,0x90,0x05,0x01,0xb3,0xe2,
  31799. 0x4d,0x7c,0xdf,0x46,0x63,0x32,0x6a,0x3a,
  31800. 0x87,0xdf,0x5e,0x48,0x43,0xb2,0xcb,0xdb,
  31801. 0x67,0xcb,0xf6,0xe4,0x60,0xfe,0xc3,0x50,
  31802. 0xaa,0x53,0x71,0xb1,0x50,0x8f,0x9f,0x45,
  31803. 0x28,0xec,0xea,0x23,0xc4,0x36,0xd9,0x4b,
  31804. 0x5e,0x8f,0xcd,0x4f,0x68,0x1e,0x30,0xa6,
  31805. 0xac,0x00,0xa9,0x70,0x4a,0x18,0x8a,0x03
  31806. };
  31807. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  31808. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {0x0 };
  31809. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {0x72};
  31810. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {0xAF,0x82};
  31811. /* test of a 1024 byte long message */
  31812. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  31813. 0x08,0xb8,0xb2,0xb7,0x33,0x42,0x42,0x43,
  31814. 0x76,0x0f,0xe4,0x26,0xa4,0xb5,0x49,0x08,
  31815. 0x63,0x21,0x10,0xa6,0x6c,0x2f,0x65,0x91,
  31816. 0xea,0xbd,0x33,0x45,0xe3,0xe4,0xeb,0x98,
  31817. 0xfa,0x6e,0x26,0x4b,0xf0,0x9e,0xfe,0x12,
  31818. 0xee,0x50,0xf8,0xf5,0x4e,0x9f,0x77,0xb1,
  31819. 0xe3,0x55,0xf6,0xc5,0x05,0x44,0xe2,0x3f,
  31820. 0xb1,0x43,0x3d,0xdf,0x73,0xbe,0x84,0xd8,
  31821. 0x79,0xde,0x7c,0x00,0x46,0xdc,0x49,0x96,
  31822. 0xd9,0xe7,0x73,0xf4,0xbc,0x9e,0xfe,0x57,
  31823. 0x38,0x82,0x9a,0xdb,0x26,0xc8,0x1b,0x37,
  31824. 0xc9,0x3a,0x1b,0x27,0x0b,0x20,0x32,0x9d,
  31825. 0x65,0x86,0x75,0xfc,0x6e,0xa5,0x34,0xe0,
  31826. 0x81,0x0a,0x44,0x32,0x82,0x6b,0xf5,0x8c,
  31827. 0x94,0x1e,0xfb,0x65,0xd5,0x7a,0x33,0x8b,
  31828. 0xbd,0x2e,0x26,0x64,0x0f,0x89,0xff,0xbc,
  31829. 0x1a,0x85,0x8e,0xfc,0xb8,0x55,0x0e,0xe3,
  31830. 0xa5,0xe1,0x99,0x8b,0xd1,0x77,0xe9,0x3a,
  31831. 0x73,0x63,0xc3,0x44,0xfe,0x6b,0x19,0x9e,
  31832. 0xe5,0xd0,0x2e,0x82,0xd5,0x22,0xc4,0xfe,
  31833. 0xba,0x15,0x45,0x2f,0x80,0x28,0x8a,0x82,
  31834. 0x1a,0x57,0x91,0x16,0xec,0x6d,0xad,0x2b,
  31835. 0x3b,0x31,0x0d,0xa9,0x03,0x40,0x1a,0xa6,
  31836. 0x21,0x00,0xab,0x5d,0x1a,0x36,0x55,0x3e,
  31837. 0x06,0x20,0x3b,0x33,0x89,0x0c,0xc9,0xb8,
  31838. 0x32,0xf7,0x9e,0xf8,0x05,0x60,0xcc,0xb9,
  31839. 0xa3,0x9c,0xe7,0x67,0x96,0x7e,0xd6,0x28,
  31840. 0xc6,0xad,0x57,0x3c,0xb1,0x16,0xdb,0xef,
  31841. 0xef,0xd7,0x54,0x99,0xda,0x96,0xbd,0x68,
  31842. 0xa8,0xa9,0x7b,0x92,0x8a,0x8b,0xbc,0x10,
  31843. 0x3b,0x66,0x21,0xfc,0xde,0x2b,0xec,0xa1,
  31844. 0x23,0x1d,0x20,0x6b,0xe6,0xcd,0x9e,0xc7,
  31845. 0xaf,0xf6,0xf6,0xc9,0x4f,0xcd,0x72,0x04,
  31846. 0xed,0x34,0x55,0xc6,0x8c,0x83,0xf4,0xa4,
  31847. 0x1d,0xa4,0xaf,0x2b,0x74,0xef,0x5c,0x53,
  31848. 0xf1,0xd8,0xac,0x70,0xbd,0xcb,0x7e,0xd1,
  31849. 0x85,0xce,0x81,0xbd,0x84,0x35,0x9d,0x44,
  31850. 0x25,0x4d,0x95,0x62,0x9e,0x98,0x55,0xa9,
  31851. 0x4a,0x7c,0x19,0x58,0xd1,0xf8,0xad,0xa5,
  31852. 0xd0,0x53,0x2e,0xd8,0xa5,0xaa,0x3f,0xb2,
  31853. 0xd1,0x7b,0xa7,0x0e,0xb6,0x24,0x8e,0x59,
  31854. 0x4e,0x1a,0x22,0x97,0xac,0xbb,0xb3,0x9d,
  31855. 0x50,0x2f,0x1a,0x8c,0x6e,0xb6,0xf1,0xce,
  31856. 0x22,0xb3,0xde,0x1a,0x1f,0x40,0xcc,0x24,
  31857. 0x55,0x41,0x19,0xa8,0x31,0xa9,0xaa,0xd6,
  31858. 0x07,0x9c,0xad,0x88,0x42,0x5d,0xe6,0xbd,
  31859. 0xe1,0xa9,0x18,0x7e,0xbb,0x60,0x92,0xcf,
  31860. 0x67,0xbf,0x2b,0x13,0xfd,0x65,0xf2,0x70,
  31861. 0x88,0xd7,0x8b,0x7e,0x88,0x3c,0x87,0x59,
  31862. 0xd2,0xc4,0xf5,0xc6,0x5a,0xdb,0x75,0x53,
  31863. 0x87,0x8a,0xd5,0x75,0xf9,0xfa,0xd8,0x78,
  31864. 0xe8,0x0a,0x0c,0x9b,0xa6,0x3b,0xcb,0xcc,
  31865. 0x27,0x32,0xe6,0x94,0x85,0xbb,0xc9,0xc9,
  31866. 0x0b,0xfb,0xd6,0x24,0x81,0xd9,0x08,0x9b,
  31867. 0xec,0xcf,0x80,0xcf,0xe2,0xdf,0x16,0xa2,
  31868. 0xcf,0x65,0xbd,0x92,0xdd,0x59,0x7b,0x07,
  31869. 0x07,0xe0,0x91,0x7a,0xf4,0x8b,0xbb,0x75,
  31870. 0xfe,0xd4,0x13,0xd2,0x38,0xf5,0x55,0x5a,
  31871. 0x7a,0x56,0x9d,0x80,0xc3,0x41,0x4a,0x8d,
  31872. 0x08,0x59,0xdc,0x65,0xa4,0x61,0x28,0xba,
  31873. 0xb2,0x7a,0xf8,0x7a,0x71,0x31,0x4f,0x31,
  31874. 0x8c,0x78,0x2b,0x23,0xeb,0xfe,0x80,0x8b,
  31875. 0x82,0xb0,0xce,0x26,0x40,0x1d,0x2e,0x22,
  31876. 0xf0,0x4d,0x83,0xd1,0x25,0x5d,0xc5,0x1a,
  31877. 0xdd,0xd3,0xb7,0x5a,0x2b,0x1a,0xe0,0x78,
  31878. 0x45,0x04,0xdf,0x54,0x3a,0xf8,0x96,0x9b,
  31879. 0xe3,0xea,0x70,0x82,0xff,0x7f,0xc9,0x88,
  31880. 0x8c,0x14,0x4d,0xa2,0xaf,0x58,0x42,0x9e,
  31881. 0xc9,0x60,0x31,0xdb,0xca,0xd3,0xda,0xd9,
  31882. 0xaf,0x0d,0xcb,0xaa,0xaf,0x26,0x8c,0xb8,
  31883. 0xfc,0xff,0xea,0xd9,0x4f,0x3c,0x7c,0xa4,
  31884. 0x95,0xe0,0x56,0xa9,0xb4,0x7a,0xcd,0xb7,
  31885. 0x51,0xfb,0x73,0xe6,0x66,0xc6,0xc6,0x55,
  31886. 0xad,0xe8,0x29,0x72,0x97,0xd0,0x7a,0xd1,
  31887. 0xba,0x5e,0x43,0xf1,0xbc,0xa3,0x23,0x01,
  31888. 0x65,0x13,0x39,0xe2,0x29,0x04,0xcc,0x8c,
  31889. 0x42,0xf5,0x8c,0x30,0xc0,0x4a,0xaf,0xdb,
  31890. 0x03,0x8d,0xda,0x08,0x47,0xdd,0x98,0x8d,
  31891. 0xcd,0xa6,0xf3,0xbf,0xd1,0x5c,0x4b,0x4c,
  31892. 0x45,0x25,0x00,0x4a,0xa0,0x6e,0xef,0xf8,
  31893. 0xca,0x61,0x78,0x3a,0xac,0xec,0x57,0xfb,
  31894. 0x3d,0x1f,0x92,0xb0,0xfe,0x2f,0xd1,0xa8,
  31895. 0x5f,0x67,0x24,0x51,0x7b,0x65,0xe6,0x14,
  31896. 0xad,0x68,0x08,0xd6,0xf6,0xee,0x34,0xdf,
  31897. 0xf7,0x31,0x0f,0xdc,0x82,0xae,0xbf,0xd9,
  31898. 0x04,0xb0,0x1e,0x1d,0xc5,0x4b,0x29,0x27,
  31899. 0x09,0x4b,0x2d,0xb6,0x8d,0x6f,0x90,0x3b,
  31900. 0x68,0x40,0x1a,0xde,0xbf,0x5a,0x7e,0x08,
  31901. 0xd7,0x8f,0xf4,0xef,0x5d,0x63,0x65,0x3a,
  31902. 0x65,0x04,0x0c,0xf9,0xbf,0xd4,0xac,0xa7,
  31903. 0x98,0x4a,0x74,0xd3,0x71,0x45,0x98,0x67,
  31904. 0x80,0xfc,0x0b,0x16,0xac,0x45,0x16,0x49,
  31905. 0xde,0x61,0x88,0xa7,0xdb,0xdf,0x19,0x1f,
  31906. 0x64,0xb5,0xfc,0x5e,0x2a,0xb4,0x7b,0x57,
  31907. 0xf7,0xf7,0x27,0x6c,0xd4,0x19,0xc1,0x7a,
  31908. 0x3c,0xa8,0xe1,0xb9,0x39,0xae,0x49,0xe4,
  31909. 0x88,0xac,0xba,0x6b,0x96,0x56,0x10,0xb5,
  31910. 0x48,0x01,0x09,0xc8,0xb1,0x7b,0x80,0xe1,
  31911. 0xb7,0xb7,0x50,0xdf,0xc7,0x59,0x8d,0x5d,
  31912. 0x50,0x11,0xfd,0x2d,0xcc,0x56,0x00,0xa3,
  31913. 0x2e,0xf5,0xb5,0x2a,0x1e,0xcc,0x82,0x0e,
  31914. 0x30,0x8a,0xa3,0x42,0x72,0x1a,0xac,0x09,
  31915. 0x43,0xbf,0x66,0x86,0xb6,0x4b,0x25,0x79,
  31916. 0x37,0x65,0x04,0xcc,0xc4,0x93,0xd9,0x7e,
  31917. 0x6a,0xed,0x3f,0xb0,0xf9,0xcd,0x71,0xa4,
  31918. 0x3d,0xd4,0x97,0xf0,0x1f,0x17,0xc0,0xe2,
  31919. 0xcb,0x37,0x97,0xaa,0x2a,0x2f,0x25,0x66,
  31920. 0x56,0x16,0x8e,0x6c,0x49,0x6a,0xfc,0x5f,
  31921. 0xb9,0x32,0x46,0xf6,0xb1,0x11,0x63,0x98,
  31922. 0xa3,0x46,0xf1,0xa6,0x41,0xf3,0xb0,0x41,
  31923. 0xe9,0x89,0xf7,0x91,0x4f,0x90,0xcc,0x2c,
  31924. 0x7f,0xff,0x35,0x78,0x76,0xe5,0x06,0xb5,
  31925. 0x0d,0x33,0x4b,0xa7,0x7c,0x22,0x5b,0xc3,
  31926. 0x07,0xba,0x53,0x71,0x52,0xf3,0xf1,0x61,
  31927. 0x0e,0x4e,0xaf,0xe5,0x95,0xf6,0xd9,0xd9,
  31928. 0x0d,0x11,0xfa,0xa9,0x33,0xa1,0x5e,0xf1,
  31929. 0x36,0x95,0x46,0x86,0x8a,0x7f,0x3a,0x45,
  31930. 0xa9,0x67,0x68,0xd4,0x0f,0xd9,0xd0,0x34,
  31931. 0x12,0xc0,0x91,0xc6,0x31,0x5c,0xf4,0xfd,
  31932. 0xe7,0xcb,0x68,0x60,0x69,0x37,0x38,0x0d,
  31933. 0xb2,0xea,0xaa,0x70,0x7b,0x4c,0x41,0x85,
  31934. 0xc3,0x2e,0xdd,0xcd,0xd3,0x06,0x70,0x5e,
  31935. 0x4d,0xc1,0xff,0xc8,0x72,0xee,0xee,0x47,
  31936. 0x5a,0x64,0xdf,0xac,0x86,0xab,0xa4,0x1c,
  31937. 0x06,0x18,0x98,0x3f,0x87,0x41,0xc5,0xef,
  31938. 0x68,0xd3,0xa1,0x01,0xe8,0xa3,0xb8,0xca,
  31939. 0xc6,0x0c,0x90,0x5c,0x15,0xfc,0x91,0x08,
  31940. 0x40,0xb9,0x4c,0x00,0xa0,0xb9,0xd0
  31941. };
  31942. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  31943. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  31944. sizeof(msg2),
  31945. sizeof(msg3),
  31946. 0 /*sizeof(msg1)*/,
  31947. 0 /*sizeof(msg1)*/,
  31948. sizeof(msg4)
  31949. };
  31950. #ifndef NO_ASN
  31951. static const byte privateEd25519[] = {
  31952. 0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,
  31953. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  31954. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31955. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31956. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31957. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31958. };
  31959. static const byte badPrivateEd25519[] = {
  31960. 0x30,0x52,0x02,0x01,0x00,0x30,0x05,0x06,
  31961. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  31962. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31963. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31964. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31965. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  31966. 0xa1,0x22,0x04,0x21,0xd7,0x5a,0x98,0x01, /* octet len 0x20 -> 0x21 */
  31967. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  31968. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  31969. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  31970. 0xf7,0x07,0x51,0x1a,
  31971. 0x00 /* add additional bytes to make the pubkey bigger */
  31972. };
  31973. static const byte publicEd25519[] = {
  31974. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  31975. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  31976. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  31977. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  31978. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  31979. 0xf7,0x07,0x51,0x1a
  31980. };
  31981. /* size has been altered to catch if sanity check is done */
  31982. static const byte badPublicEd25519[] = {
  31983. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  31984. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  31985. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  31986. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  31987. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  31988. 0xf7,0x07,0x51,0x1a,
  31989. 0x00 /* add an additional byte to make the pubkey appear bigger */
  31990. };
  31991. static const byte privPubEd25519[] = {
  31992. 0x30,0x50,0x02,0x01,0x00,0x30,0x05,0x06,
  31993. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  31994. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31995. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31996. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31997. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  31998. 0x81,0x20,0xd7,0x5a,0x98,0x01,0x82,0xb1,
  31999. 0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,
  32000. 0x07,0x3a,0x0e,0xe1,0x72,0xf3,0xda,0xa6,
  32001. 0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7,0x07,
  32002. 0x51,0x1a
  32003. };
  32004. word32 idx;
  32005. #endif /* NO_ASN */
  32006. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32007. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32008. ed25519_key key3;
  32009. #endif
  32010. WOLFSSL_ENTER("ed25519_test");
  32011. /* create ed25519 keys */
  32012. #ifndef HAVE_FIPS
  32013. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32014. #else
  32015. ret = wc_InitRng(&rng);
  32016. #endif
  32017. if (ret != 0)
  32018. return WC_TEST_RET_ENC_EC(ret);
  32019. wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  32020. wc_ed25519_init_ex(&key2, HEAP_HINT, devId);
  32021. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32022. wc_ed25519_init_ex(&key3, HEAP_HINT, devId);
  32023. #endif
  32024. #ifdef HAVE_ED25519_MAKE_KEY
  32025. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key);
  32026. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key2);
  32027. #endif
  32028. /* helper functions for signature and key size */
  32029. keySz = (word32)wc_ed25519_size(&key);
  32030. sigSz = (word32)wc_ed25519_sig_size(&key);
  32031. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  32032. defined(HAVE_ED25519_KEY_IMPORT)
  32033. for (i = 0; i < 6; i++) {
  32034. outlen = sizeof(out);
  32035. XMEMSET(out, 0, sizeof(out));
  32036. if (wc_ed25519_import_private_key(sKeys[i], ED25519_KEY_SIZE, pKeys[i],
  32037. pKeySz[i], &key) != 0)
  32038. return WC_TEST_RET_ENC_I(i);
  32039. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, &key) != 0)
  32040. return WC_TEST_RET_ENC_I(i);
  32041. if (XMEMCMP(out, sigs[i], 64))
  32042. return WC_TEST_RET_ENC_I(i);
  32043. #if defined(HAVE_ED25519_VERIFY)
  32044. /* test verify on good msg */
  32045. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32046. &key) != 0 || verify != 1)
  32047. return WC_TEST_RET_ENC_I(i);
  32048. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  32049. /* test verify on good msg using streaming interface directly */
  32050. if (wc_ed25519_verify_msg_init(out, outlen,
  32051. &key, (byte)Ed25519, NULL, 0) != 0)
  32052. return WC_TEST_RET_ENC_I(i);
  32053. for (j = 0; j < msgSz[i]; j += i) {
  32054. if (wc_ed25519_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), &key) != 0)
  32055. return WC_TEST_RET_ENC_I(i);
  32056. }
  32057. if (wc_ed25519_verify_msg_final(out, outlen, &verify,
  32058. &key) != 0 || verify != 1)
  32059. return WC_TEST_RET_ENC_I(i);
  32060. #endif /* WOLFSSL_ED25519_STREAMING_VERIFY */
  32061. /* test verify on bad msg */
  32062. out[outlen-1] = out[outlen-1] + 1;
  32063. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32064. &key) == 0 || verify == 1)
  32065. return WC_TEST_RET_ENC_I(i);
  32066. #endif /* HAVE_ED25519_VERIFY */
  32067. /* test api for import/exporting keys */
  32068. exportPSz = sizeof(exportPKey);
  32069. exportSSz = sizeof(exportSKey);
  32070. if (wc_ed25519_export_public(&key, exportPKey, &exportPSz) != 0)
  32071. return WC_TEST_RET_ENC_I(i);
  32072. if (wc_ed25519_import_public_ex(exportPKey, exportPSz, &key2, 1) != 0)
  32073. return WC_TEST_RET_ENC_I(i);
  32074. if (wc_ed25519_export_private_only(&key, exportSKey, &exportSSz) != 0)
  32075. return WC_TEST_RET_ENC_I(i);
  32076. if (wc_ed25519_import_private_key(exportSKey, exportSSz,
  32077. exportPKey, exportPSz, &key2) != 0)
  32078. return WC_TEST_RET_ENC_I(i);
  32079. /* clear "out" buffer and test sign with imported keys */
  32080. outlen = sizeof(out);
  32081. XMEMSET(out, 0, sizeof(out));
  32082. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, &key2) != 0)
  32083. return WC_TEST_RET_ENC_I(i);
  32084. #if defined(HAVE_ED25519_VERIFY)
  32085. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32086. &key2) != 0 || verify != 1)
  32087. return WC_TEST_RET_ENC_I(i);
  32088. if (XMEMCMP(out, sigs[i], 64))
  32089. return WC_TEST_RET_ENC_I(i);
  32090. #endif /* HAVE_ED25519_VERIFY */
  32091. }
  32092. {
  32093. /* Run tests for some rare code paths */
  32094. /* sig is exactly equal to the order */
  32095. static const byte rareEd1[] = {
  32096. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32097. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32098. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32099. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32100. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32101. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32102. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32103. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32104. };
  32105. /* sig is larger than the order before we get to the low part */
  32106. static const byte rareEd2[] = {
  32107. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32108. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32109. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32110. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32111. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32112. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32113. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32114. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10
  32115. };
  32116. /* sig is larger than the order in the low part */
  32117. static const byte rareEd3[] = {
  32118. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32119. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32120. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32121. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32122. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32123. 0xd6, 0x9c, 0xf9, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32124. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32125. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32126. };
  32127. /* sig is smaller than the order */
  32128. static const byte rareEd4[] = {
  32129. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32130. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32131. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32132. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32133. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32134. 0xd6, 0x9c, 0xf1, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32135. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32136. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32137. };
  32138. ret = wc_ed25519_import_private_key(sKeys[0], ED25519_KEY_SIZE,
  32139. pKeys[0], pKeySz[0], &key);
  32140. if (ret != 0)
  32141. return ret;
  32142. ret = wc_ed25519_verify_msg(rareEd1, sizeof(rareEd1), msgs[0], msgSz[0],
  32143. &verify, &key);
  32144. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32145. return ret;
  32146. ret = wc_ed25519_verify_msg(rareEd2, sizeof(rareEd2), msgs[0], msgSz[0],
  32147. &verify, &key);
  32148. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32149. return ret;
  32150. ret = wc_ed25519_verify_msg(rareEd3, sizeof(rareEd3), msgs[0], msgSz[0],
  32151. &verify, &key);
  32152. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32153. return ret;
  32154. ret = wc_ed25519_verify_msg(rareEd4, sizeof(rareEd4), msgs[0], msgSz[0],
  32155. &verify, &key);
  32156. if (ret != WC_NO_ERR_TRACE(SIG_VERIFY_E))
  32157. return ret;
  32158. }
  32159. ret = ed25519ctx_test();
  32160. if (ret != 0)
  32161. return ret;
  32162. ret = ed25519ph_test();
  32163. if (ret != 0)
  32164. return ret;
  32165. #ifndef NO_ASN
  32166. /* Try ASN.1 encoded private-only key and public key. */
  32167. idx = 0;
  32168. ret = wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, &key3,
  32169. sizeof(privateEd25519));
  32170. if (ret != 0)
  32171. return WC_TEST_RET_ENC_EC(ret);
  32172. idx = 0;
  32173. if (wc_Ed25519PrivateKeyDecode(badPrivateEd25519, &idx, &key3,
  32174. sizeof(badPrivateEd25519)) == 0)
  32175. return WC_TEST_RET_ENC_NC;
  32176. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3);
  32177. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32178. return WC_TEST_RET_ENC_EC(ret);
  32179. /* try with a buffer size that is too large */
  32180. idx = 0;
  32181. if (wc_Ed25519PublicKeyDecode(badPublicEd25519, &idx, &key3,
  32182. sizeof(badPublicEd25519)) == 0)
  32183. return WC_TEST_RET_ENC_NC;
  32184. idx = 0;
  32185. ret = wc_Ed25519PublicKeyDecode(publicEd25519, &idx, &key3,
  32186. sizeof(publicEd25519));
  32187. if (ret != 0)
  32188. return WC_TEST_RET_ENC_EC(ret);
  32189. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3);
  32190. if (ret != 0)
  32191. return WC_TEST_RET_ENC_EC(ret);
  32192. if (XMEMCMP(out, sigs[0], 64))
  32193. return WC_TEST_RET_ENC_NC;
  32194. #if defined(HAVE_ED25519_VERIFY)
  32195. /* test verify on good msg */
  32196. ret = wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, &key3);
  32197. if (ret != 0 || verify != 1)
  32198. return WC_TEST_RET_ENC_EC(ret);
  32199. #endif /* HAVE_ED25519_VERIFY */
  32200. wc_ed25519_free(&key3);
  32201. wc_ed25519_init(&key3);
  32202. idx = 0;
  32203. ret = wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, &key3,
  32204. sizeof(privPubEd25519));
  32205. if (ret != 0)
  32206. return WC_TEST_RET_ENC_EC(ret);
  32207. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, &key3);
  32208. if (ret != 0)
  32209. return WC_TEST_RET_ENC_EC(ret);
  32210. if (XMEMCMP(out, sigs[0], 64))
  32211. return WC_TEST_RET_ENC_NC;
  32212. wc_ed25519_free(&key3);
  32213. #endif /* NO_ASN */
  32214. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32215. /* clean up keys when done */
  32216. wc_ed25519_free(&key);
  32217. wc_ed25519_free(&key2);
  32218. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  32219. wc_FreeRng(&rng);
  32220. #endif
  32221. /* hush warnings of unused keySz and sigSz */
  32222. (void)keySz;
  32223. (void)sigSz;
  32224. ret = ed25519_test_check_key();
  32225. if (ret < 0)
  32226. return ret;
  32227. #ifdef WOLFSSL_TEST_CERT
  32228. ret = ed25519_test_cert();
  32229. if (ret < 0)
  32230. return ret;
  32231. #if defined(WOLFSSL_CERT_GEN) && defined(HAVE_ED25519_MAKE_KEY)
  32232. ret = ed25519_test_make_cert();
  32233. if (ret < 0)
  32234. return ret;
  32235. #endif /* WOLFSSL_CERT_GEN */
  32236. #endif /* WOLFSSL_TEST_CERT */
  32237. return 0;
  32238. }
  32239. #endif /* HAVE_ED25519 */
  32240. #ifdef HAVE_CURVE448
  32241. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32242. defined(HAVE_CURVE448_KEY_IMPORT)
  32243. /* Test the wc_curve448_check_public API.
  32244. *
  32245. * returns 0 on success and -ve on failure.
  32246. */
  32247. static wc_test_ret_t curve448_check_public_test(void)
  32248. {
  32249. /* Little-endian values that will fail */
  32250. byte fail_le[][CURVE448_KEY_SIZE] = {
  32251. {
  32252. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32253. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32254. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32255. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32256. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32257. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32258. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32259. },
  32260. {
  32261. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32262. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32263. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32264. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32265. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32266. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32267. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32268. },
  32269. };
  32270. /* Big-endian values that will fail */
  32271. byte fail_be[][CURVE448_KEY_SIZE] = {
  32272. {
  32273. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32274. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32275. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32276. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32277. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32278. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32279. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32280. },
  32281. {
  32282. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32283. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32284. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32285. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32286. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32287. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32288. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32289. },
  32290. };
  32291. /* Good or valid public value */
  32292. byte good[CURVE448_KEY_SIZE] = {
  32293. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32294. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32295. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32296. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32297. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32298. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32299. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32300. };
  32301. int i;
  32302. wc_test_ret_t ret;
  32303. /* Parameter checks */
  32304. /* NULL pointer */
  32305. ret = wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN);
  32306. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32307. return WC_TEST_RET_ENC_EC(ret);
  32308. ret = wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN);
  32309. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32310. return WC_TEST_RET_ENC_EC(ret);
  32311. /* Length of 0 treated differently to other invalid lengths for TLS */
  32312. ret = wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN);
  32313. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32314. return WC_TEST_RET_ENC_EC(ret);
  32315. ret = wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN);
  32316. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32317. return WC_TEST_RET_ENC_EC(ret);
  32318. /* Length not CURVE448_KEY_SIZE */
  32319. for (i = 1; i < CURVE448_KEY_SIZE + 2; i++) {
  32320. if (i == CURVE448_KEY_SIZE)
  32321. continue;
  32322. if (wc_curve448_check_public(good, (word32)i, EC448_LITTLE_ENDIAN) !=
  32323. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32324. return WC_TEST_RET_ENC_I(i);
  32325. }
  32326. if (wc_curve448_check_public(good, (word32)i, EC448_BIG_ENDIAN) !=
  32327. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32328. return WC_TEST_RET_ENC_I(i);
  32329. }
  32330. }
  32331. /* Little-endian fail cases */
  32332. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  32333. if (wc_curve448_check_public(fail_le[i], CURVE448_KEY_SIZE,
  32334. EC448_LITTLE_ENDIAN) == 0) {
  32335. return WC_TEST_RET_ENC_I(i);
  32336. }
  32337. }
  32338. /* Big-endian fail cases */
  32339. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  32340. if (wc_curve448_check_public(fail_be[i], CURVE448_KEY_SIZE,
  32341. EC448_BIG_ENDIAN) == 0) {
  32342. return WC_TEST_RET_ENC_I(i);
  32343. }
  32344. }
  32345. /* Check a valid public value works! */
  32346. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE,
  32347. EC448_LITTLE_ENDIAN);
  32348. if (ret != 0)
  32349. return WC_TEST_RET_ENC_EC(ret);
  32350. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN);
  32351. if (ret != 0)
  32352. return WC_TEST_RET_ENC_EC(ret);
  32353. return 0;
  32354. }
  32355. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32356. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void)
  32357. {
  32358. WC_RNG rng;
  32359. wc_test_ret_t ret;
  32360. #ifdef HAVE_CURVE448_SHARED_SECRET
  32361. byte sharedA[CURVE448_KEY_SIZE];
  32362. byte sharedB[CURVE448_KEY_SIZE];
  32363. word32 y;
  32364. #endif
  32365. #ifdef HAVE_CURVE448_KEY_EXPORT
  32366. byte exportBuf[CURVE448_KEY_SIZE];
  32367. #endif
  32368. word32 x = 0;
  32369. curve448_key userA, userB, pubKey;
  32370. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32371. defined(HAVE_CURVE448_KEY_IMPORT)
  32372. /* test vectors from
  32373. https://www.rfc-editor.org/rfc/rfc7748.html
  32374. */
  32375. /* secret key for party a */
  32376. byte sa[] = {
  32377. 0x6b, 0x72, 0x98, 0xa5, 0xc0, 0xd8, 0xc2, 0x9a,
  32378. 0x1d, 0xab, 0x27, 0xf1, 0xa6, 0x82, 0x63, 0x00,
  32379. 0x91, 0x73, 0x89, 0x44, 0x97, 0x41, 0xa9, 0x74,
  32380. 0xf5, 0xba, 0xc9, 0xd9, 0x8d, 0xc2, 0x98, 0xd4,
  32381. 0x65, 0x55, 0xbc, 0xe8, 0xba, 0xe8, 0x9e, 0xee,
  32382. 0xd4, 0x00, 0x58, 0x4b, 0xb0, 0x46, 0xcf, 0x75,
  32383. 0x57, 0x9f, 0x51, 0xd1, 0x25, 0x49, 0x8f, 0x9a,
  32384. };
  32385. /* public key for party a */
  32386. byte pa[] = {
  32387. 0xa0, 0x1f, 0xc4, 0x32, 0xe5, 0x80, 0x7f, 0x17,
  32388. 0x53, 0x0d, 0x12, 0x88, 0xda, 0x12, 0x5b, 0x0c,
  32389. 0xd4, 0x53, 0xd9, 0x41, 0x72, 0x64, 0x36, 0xc8,
  32390. 0xbb, 0xd9, 0xc5, 0x22, 0x2c, 0x3d, 0xa7, 0xfa,
  32391. 0x63, 0x9c, 0xe0, 0x3d, 0xb8, 0xd2, 0x3b, 0x27,
  32392. 0x4a, 0x07, 0x21, 0xa1, 0xae, 0xd5, 0x22, 0x7d,
  32393. 0xe6, 0xe3, 0xb7, 0x31, 0xcc, 0xf7, 0x08, 0x9b,
  32394. };
  32395. /* secret key for party b */
  32396. byte sb[] = {
  32397. 0x2d, 0x99, 0x73, 0x51, 0xb6, 0x10, 0x6f, 0x36,
  32398. 0xb0, 0xd1, 0x09, 0x1b, 0x92, 0x9c, 0x4c, 0x37,
  32399. 0x21, 0x3e, 0x0d, 0x2b, 0x97, 0xe8, 0x5e, 0xbb,
  32400. 0x20, 0xc1, 0x27, 0x69, 0x1d, 0x0d, 0xad, 0x8f,
  32401. 0x1d, 0x81, 0x75, 0xb0, 0x72, 0x37, 0x45, 0xe6,
  32402. 0x39, 0xa3, 0xcb, 0x70, 0x44, 0x29, 0x0b, 0x99,
  32403. 0xe0, 0xe2, 0xa0, 0xc2, 0x7a, 0x6a, 0x30, 0x1c,
  32404. };
  32405. /* public key for party b */
  32406. byte pb[] = {
  32407. 0x09, 0x36, 0xf3, 0x7b, 0xc6, 0xc1, 0xbd, 0x07,
  32408. 0xae, 0x3d, 0xec, 0x7a, 0xb5, 0xdc, 0x06, 0xa7,
  32409. 0x3c, 0xa1, 0x32, 0x42, 0xfb, 0x34, 0x3e, 0xfc,
  32410. 0x72, 0xb9, 0xd8, 0x27, 0x30, 0xb4, 0x45, 0xf3,
  32411. 0xd4, 0xb0, 0xbd, 0x07, 0x71, 0x62, 0xa4, 0x6d,
  32412. 0xcf, 0xec, 0x6f, 0x9b, 0x59, 0x0b, 0xfc, 0xbc,
  32413. 0xf5, 0x20, 0xcd, 0xb0, 0x29, 0xa8, 0xb7, 0x3e,
  32414. };
  32415. /* expected shared key */
  32416. byte ss[] = {
  32417. 0x9d, 0x87, 0x4a, 0x51, 0x37, 0x50, 0x9a, 0x44,
  32418. 0x9a, 0xd5, 0x85, 0x30, 0x40, 0x24, 0x1c, 0x52,
  32419. 0x36, 0x39, 0x54, 0x35, 0xc3, 0x64, 0x24, 0xfd,
  32420. 0x56, 0x0b, 0x0c, 0xb6, 0x2b, 0x28, 0x1d, 0x28,
  32421. 0x52, 0x75, 0xa7, 0x40, 0xce, 0x32, 0xa2, 0x2d,
  32422. 0xd1, 0x74, 0x0f, 0x4a, 0xa9, 0x16, 0x1c, 0xec,
  32423. 0x95, 0xcc, 0xc6, 0x1a, 0x18, 0xf4, 0xff, 0x07,
  32424. };
  32425. #endif /* HAVE_CURVE448_SHARED_SECRET */
  32426. (void)x;
  32427. WOLFSSL_ENTER("curve448_test");
  32428. #ifndef HAVE_FIPS
  32429. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32430. #else
  32431. ret = wc_InitRng(&rng);
  32432. #endif
  32433. if (ret != 0)
  32434. return WC_TEST_RET_ENC_EC(ret);
  32435. wc_curve448_init(&userA);
  32436. wc_curve448_init(&userB);
  32437. wc_curve448_init(&pubKey);
  32438. /* make curve448 keys */
  32439. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA);
  32440. if (ret != 0)
  32441. return WC_TEST_RET_ENC_EC(ret);
  32442. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB);
  32443. if (ret != 0)
  32444. return WC_TEST_RET_ENC_EC(ret);
  32445. #ifdef HAVE_CURVE448_SHARED_SECRET
  32446. /* find shared secret key */
  32447. x = sizeof(sharedA);
  32448. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32449. if (ret != 0)
  32450. return WC_TEST_RET_ENC_EC(ret);
  32451. y = sizeof(sharedB);
  32452. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32453. if (ret != 0)
  32454. return WC_TEST_RET_ENC_EC(ret);
  32455. /* compare shared secret keys to test they are the same */
  32456. if (y != x)
  32457. return WC_TEST_RET_ENC_NC;
  32458. if (XMEMCMP(sharedA, sharedB, x))
  32459. return WC_TEST_RET_ENC_NC;
  32460. #endif
  32461. #ifdef HAVE_CURVE448_KEY_EXPORT
  32462. /* export a public key and import it for another user */
  32463. x = sizeof(exportBuf);
  32464. ret = wc_curve448_export_public(&userA, exportBuf, &x);
  32465. if (ret != 0)
  32466. return WC_TEST_RET_ENC_EC(ret);
  32467. #ifdef HAVE_CURVE448_KEY_IMPORT
  32468. ret = wc_curve448_import_public(exportBuf, x, &pubKey);
  32469. if (ret != 0)
  32470. return WC_TEST_RET_ENC_EC(ret);
  32471. #endif
  32472. #endif
  32473. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32474. defined(HAVE_CURVE448_KEY_IMPORT)
  32475. /* test shared key after importing a public key */
  32476. XMEMSET(sharedB, 0, sizeof(sharedB));
  32477. y = sizeof(sharedB);
  32478. ret = wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y);
  32479. if (ret != 0)
  32480. return WC_TEST_RET_ENC_EC(ret);
  32481. if (XMEMCMP(sharedA, sharedB, y))
  32482. return WC_TEST_RET_ENC_NC;
  32483. /* import RFC test vectors and compare shared key */
  32484. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32485. if (ret != 0)
  32486. return WC_TEST_RET_ENC_EC(ret);
  32487. ret = wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB);
  32488. if (ret != 0)
  32489. return WC_TEST_RET_ENC_EC(ret);
  32490. /* test against known test vector */
  32491. XMEMSET(sharedB, 0, sizeof(sharedB));
  32492. y = sizeof(sharedB);
  32493. ret = wc_curve448_shared_secret(&userA, &userB, sharedB, &y);
  32494. if (ret != 0)
  32495. return WC_TEST_RET_ENC_EC(ret);
  32496. if (XMEMCMP(ss, sharedB, y))
  32497. return WC_TEST_RET_ENC_NC;
  32498. /* test swapping roles of keys and generating same shared key */
  32499. XMEMSET(sharedB, 0, sizeof(sharedB));
  32500. y = sizeof(sharedB);
  32501. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32502. if (ret != 0)
  32503. return WC_TEST_RET_ENC_EC(ret);
  32504. if (XMEMCMP(ss, sharedB, y))
  32505. return WC_TEST_RET_ENC_NC;
  32506. /* test with 1 generated key and 1 from known test vector */
  32507. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32508. if (ret != 0)
  32509. return WC_TEST_RET_ENC_EC(ret);
  32510. ret = wc_curve448_make_key(&rng, 56, &userB);
  32511. if (ret != 0)
  32512. return WC_TEST_RET_ENC_EC(ret);
  32513. x = sizeof(sharedA);
  32514. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32515. if (ret != 0)
  32516. return WC_TEST_RET_ENC_EC(ret);
  32517. y = sizeof(sharedB);
  32518. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32519. if (ret != 0)
  32520. return WC_TEST_RET_ENC_EC(ret);
  32521. /* compare shared secret keys to test they are the same */
  32522. if (y != x)
  32523. return WC_TEST_RET_ENC_NC;
  32524. if (XMEMCMP(sharedA, sharedB, x))
  32525. return WC_TEST_RET_ENC_NC;
  32526. ret = curve448_check_public_test();
  32527. if (ret != 0)
  32528. return ret;
  32529. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32530. /* clean up keys when done */
  32531. wc_curve448_free(&pubKey);
  32532. wc_curve448_free(&userB);
  32533. wc_curve448_free(&userA);
  32534. wc_FreeRng(&rng);
  32535. return 0;
  32536. }
  32537. #endif /* HAVE_CURVE448 */
  32538. #ifdef HAVE_ED448
  32539. #ifdef WOLFSSL_TEST_CERT
  32540. static wc_test_ret_t ed448_test_cert(void)
  32541. {
  32542. DecodedCert cert[2];
  32543. DecodedCert* serverCert = NULL;
  32544. DecodedCert* caCert = NULL;
  32545. #ifdef HAVE_ED448_VERIFY
  32546. ed448_key key;
  32547. ed448_key* pubKey = NULL;
  32548. int verify;
  32549. #endif /* HAVE_ED448_VERIFY */
  32550. wc_test_ret_t ret;
  32551. byte* tmp;
  32552. size_t bytes;
  32553. XFILE file;
  32554. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32555. if (tmp == NULL) {
  32556. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32557. }
  32558. #ifdef USE_CERT_BUFFERS_256
  32559. XMEMCPY(tmp, ca_ed448_cert, sizeof_ca_ed448_cert);
  32560. bytes = sizeof_ca_ed448_cert;
  32561. #elif !defined(NO_FILESYSTEM)
  32562. file = XFOPEN(caEd448Cert, "rb");
  32563. if (file == NULL) {
  32564. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32565. }
  32566. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32567. XFCLOSE(file);
  32568. if (bytes == 0)
  32569. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32570. #else
  32571. /* No certificate to use. */
  32572. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32573. #endif
  32574. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  32575. caCert = &cert[0];
  32576. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  32577. if (ret != 0)
  32578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32579. #ifdef USE_CERT_BUFFERS_256
  32580. XMEMCPY(tmp, server_ed448_cert, sizeof_server_ed448_cert);
  32581. bytes = sizeof_server_ed448_cert;
  32582. #elif !defined(NO_FILESYSTEM)
  32583. file = XFOPEN(serverEd448Cert, "rb");
  32584. if (file == NULL) {
  32585. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32586. }
  32587. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32588. XFCLOSE(file);
  32589. if (bytes == 0)
  32590. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32591. #else
  32592. /* No certificate to use. */
  32593. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32594. #endif
  32595. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  32596. serverCert = &cert[1];
  32597. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  32598. if (ret != 0)
  32599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32600. #ifdef HAVE_ED448_VERIFY
  32601. ret = wc_ed448_init(&key);
  32602. if (ret < 0)
  32603. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32604. pubKey = &key;
  32605. ret = wc_ed448_import_public(caCert->publicKey, caCert->pubKeySize, pubKey);
  32606. if (ret < 0)
  32607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32608. ret = wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength,
  32609. serverCert->source + serverCert->certBegin,
  32610. serverCert->sigIndex - serverCert->certBegin,
  32611. &verify, pubKey, NULL, 0);
  32612. if (ret < 0 || verify != 1) {
  32613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32614. }
  32615. #endif /* HAVE_ED448_VERIFY */
  32616. done:
  32617. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32618. #ifdef HAVE_ED448_VERIFY
  32619. wc_ed448_free(pubKey);
  32620. #endif /* HAVE_ED448_VERIFY */
  32621. if (caCert != NULL)
  32622. FreeDecodedCert(caCert);
  32623. if (serverCert != NULL)
  32624. FreeDecodedCert(serverCert);
  32625. return ret;
  32626. }
  32627. static wc_test_ret_t ed448_test_make_cert(void)
  32628. {
  32629. WC_RNG rng;
  32630. Cert cert;
  32631. DecodedCert decode;
  32632. ed448_key key;
  32633. ed448_key* privKey = NULL;
  32634. wc_test_ret_t ret = 0;
  32635. byte* tmp = NULL;
  32636. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  32637. #ifndef HAVE_FIPS
  32638. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32639. #else
  32640. ret = wc_InitRng(&rng);
  32641. #endif
  32642. if (ret != 0)
  32643. return WC_TEST_RET_ENC_EC(ret);
  32644. wc_ed448_init(&key);
  32645. privKey = &key;
  32646. wc_ed448_make_key(&rng, ED448_KEY_SIZE, privKey);
  32647. cert.daysValid = 365 * 2;
  32648. cert.selfSigned = 1;
  32649. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  32650. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  32651. cert.isCA = 0;
  32652. #ifdef WOLFSSL_CERT_EXT
  32653. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  32654. if (ret < 0)
  32655. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32656. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32657. if (ret < 0)
  32658. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32659. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32660. if (ret < 0)
  32661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32662. #endif
  32663. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32664. if (tmp == NULL) {
  32665. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32666. }
  32667. cert.sigType = CTC_ED448;
  32668. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng);
  32669. if (ret < 0)
  32670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32671. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED448_TYPE,
  32672. privKey, &rng);
  32673. if (ret < 0)
  32674. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32675. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  32676. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  32677. FreeDecodedCert(&decode);
  32678. if (ret != 0)
  32679. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32680. done:
  32681. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32682. wc_ed448_free(privKey);
  32683. wc_FreeRng(&rng);
  32684. return ret;
  32685. }
  32686. #endif /* WOLFSSL_TEST_CERT */
  32687. #if defined(HAVE_ED448_KEY_IMPORT)
  32688. static wc_test_ret_t ed448_test_check_key(void)
  32689. {
  32690. /* Fails to find x-ordinate from this y-ordinate. */
  32691. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  32692. 0x40,
  32693. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32694. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32695. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32696. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32697. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32698. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32699. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32700. 0x00
  32701. };
  32702. /* Y-ordinate value larger than prime. */
  32703. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  32704. 0x40,
  32705. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32706. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32707. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32708. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32709. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32710. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32711. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32712. 0xff
  32713. };
  32714. /* Y-ordinate value equal to prime. */
  32715. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  32716. 0x40,
  32717. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32718. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32719. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32720. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  32721. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32722. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32723. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32724. 0xff
  32725. };
  32726. /* Y-ordinate value equal to prime - 1. */
  32727. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  32728. 0x40,
  32729. 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32730. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32731. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32732. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  32733. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32734. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32735. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32736. 0xff
  32737. };
  32738. ed448_key key;
  32739. int ret;
  32740. int res = 0;
  32741. /* Initialize key for use. */
  32742. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  32743. if (ret != 0) {
  32744. return WC_TEST_RET_ENC_NC;
  32745. }
  32746. /* Load bad public key only and perform checks. */
  32747. ret = wc_ed448_import_public(key_bad_y, ED448_PUB_KEY_SIZE + 1, &key);
  32748. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  32749. res = WC_TEST_RET_ENC_NC;
  32750. }
  32751. if (ret == 0) {
  32752. /* Load bad public key only and perform checks. */
  32753. ret = wc_ed448_import_public(key_bad_y_max, ED448_PUB_KEY_SIZE + 1,
  32754. &key);
  32755. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  32756. res = WC_TEST_RET_ENC_NC;
  32757. }
  32758. }
  32759. if (res == 0) {
  32760. /* Load bad public key only and perform checks. */
  32761. ret = wc_ed448_import_public(key_bad_y_is_p, ED448_PUB_KEY_SIZE + 1,
  32762. &key);
  32763. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  32764. res = WC_TEST_RET_ENC_NC;
  32765. }
  32766. }
  32767. if (res == 0) {
  32768. /* Load good public key only and perform checks. */
  32769. ret = wc_ed448_import_public(key_y_is_p_minus_1, ED448_PUB_KEY_SIZE + 1,
  32770. &key);
  32771. if (ret != 0) {
  32772. res = WC_TEST_RET_ENC_NC;
  32773. }
  32774. }
  32775. /* Dispose of key. */
  32776. wc_ed448_free(&key);
  32777. return res;
  32778. }
  32779. #endif
  32780. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  32781. defined(HAVE_ED448_KEY_IMPORT)
  32782. static wc_test_ret_t ed448_ctx_test(void)
  32783. {
  32784. wc_test_ret_t ret;
  32785. byte out[ED448_SIG_SIZE];
  32786. word32 outlen;
  32787. #ifdef HAVE_ED448_VERIFY
  32788. int verify;
  32789. #endif /* HAVE_ED448_VERIFY */
  32790. ed448_key key;
  32791. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  32792. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  32793. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  32794. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  32795. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  32796. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  32797. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  32798. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  32799. 0x4e
  32800. };
  32801. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  32802. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  32803. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  32804. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  32805. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  32806. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  32807. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  32808. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  32809. 0x80
  32810. };
  32811. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx[] = {
  32812. 0xd4, 0xf8, 0xf6, 0x13, 0x17, 0x70, 0xdd, 0x46,
  32813. 0xf4, 0x08, 0x67, 0xd6, 0xfd, 0x5d, 0x50, 0x55,
  32814. 0xde, 0x43, 0x54, 0x1f, 0x8c, 0x5e, 0x35, 0xab,
  32815. 0xbc, 0xd0, 0x01, 0xb3, 0x2a, 0x89, 0xf7, 0xd2,
  32816. 0x15, 0x1f, 0x76, 0x47, 0xf1, 0x1d, 0x8c, 0xa2,
  32817. 0xae, 0x27, 0x9f, 0xb8, 0x42, 0xd6, 0x07, 0x21,
  32818. 0x7f, 0xce, 0x6e, 0x04, 0x2f, 0x68, 0x15, 0xea,
  32819. 0x00, 0x0c, 0x85, 0x74, 0x1d, 0xe5, 0xc8, 0xda,
  32820. 0x11, 0x44, 0xa6, 0xa1, 0xab, 0xa7, 0xf9, 0x6d,
  32821. 0xe4, 0x25, 0x05, 0xd7, 0xa7, 0x29, 0x85, 0x24,
  32822. 0xfd, 0xa5, 0x38, 0xfc, 0xcb, 0xbb, 0x75, 0x4f,
  32823. 0x57, 0x8c, 0x1c, 0xad, 0x10, 0xd5, 0x4d, 0x0d,
  32824. 0x54, 0x28, 0x40, 0x7e, 0x85, 0xdc, 0xbc, 0x98,
  32825. 0xa4, 0x91, 0x55, 0xc1, 0x37, 0x64, 0xe6, 0x6c,
  32826. 0x3c, 0x00
  32827. };
  32828. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  32829. 0x03
  32830. };
  32831. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  32832. 0x66,0x6f,0x6f
  32833. };
  32834. outlen = sizeof(out);
  32835. XMEMSET(out, 0, sizeof(out));
  32836. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  32837. if (ret != 0)
  32838. return WC_TEST_RET_ENC_EC(ret);
  32839. ret = wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx,
  32840. sizeof(pKeyCtx), &key);
  32841. if (ret != 0)
  32842. return WC_TEST_RET_ENC_EC(ret);
  32843. ret = wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  32844. contextCtx, sizeof(contextCtx));
  32845. if (ret != 0)
  32846. return WC_TEST_RET_ENC_EC(ret);
  32847. if (XMEMCMP(out, sigCtx, sizeof(sigCtx)))
  32848. return WC_TEST_RET_ENC_NC;
  32849. #if defined(HAVE_ED448_VERIFY)
  32850. /* test verify on good msg */
  32851. ret = wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key,
  32852. contextCtx, sizeof(contextCtx));
  32853. if (ret != 0 || verify != 1)
  32854. return WC_TEST_RET_ENC_EC(ret);
  32855. #endif
  32856. wc_ed448_free(&key);
  32857. return 0;
  32858. }
  32859. static wc_test_ret_t ed448ph_test(void)
  32860. {
  32861. wc_test_ret_t ret;
  32862. byte out[ED448_SIG_SIZE];
  32863. word32 outlen;
  32864. #ifdef HAVE_ED448_VERIFY
  32865. int verify;
  32866. #endif /* HAVE_ED448_VERIFY */
  32867. ed448_key key;
  32868. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  32869. 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
  32870. 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
  32871. 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
  32872. 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42,
  32873. 0xef, 0x78, 0x22, 0xe0, 0xd5, 0x10, 0x41, 0x27,
  32874. 0xdc, 0x05, 0xd6, 0xdb, 0xef, 0xde, 0x69, 0xe3,
  32875. 0xab, 0x2c, 0xec, 0x7c, 0x86, 0x7c, 0x6e, 0x2c,
  32876. 0x49
  32877. };
  32878. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  32879. 0x25, 0x9b, 0x71, 0xc1, 0x9f, 0x83, 0xef, 0x77,
  32880. 0xa7, 0xab, 0xd2, 0x65, 0x24, 0xcb, 0xdb, 0x31,
  32881. 0x61, 0xb5, 0x90, 0xa4, 0x8f, 0x7d, 0x17, 0xde,
  32882. 0x3e, 0xe0, 0xba, 0x9c, 0x52, 0xbe, 0xb7, 0x43,
  32883. 0xc0, 0x94, 0x28, 0xa1, 0x31, 0xd6, 0xb1, 0xb5,
  32884. 0x73, 0x03, 0xd9, 0x0d, 0x81, 0x32, 0xc2, 0x76,
  32885. 0xd5, 0xed, 0x3d, 0x5d, 0x01, 0xc0, 0xf5, 0x38,
  32886. 0x80
  32887. };
  32888. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  32889. 0x82, 0x2f, 0x69, 0x01, 0xf7, 0x48, 0x0f, 0x3d,
  32890. 0x5f, 0x56, 0x2c, 0x59, 0x29, 0x94, 0xd9, 0x69,
  32891. 0x36, 0x02, 0x87, 0x56, 0x14, 0x48, 0x32, 0x56,
  32892. 0x50, 0x56, 0x00, 0xbb, 0xc2, 0x81, 0xae, 0x38,
  32893. 0x1f, 0x54, 0xd6, 0xbc, 0xe2, 0xea, 0x91, 0x15,
  32894. 0x74, 0x93, 0x2f, 0x52, 0xa4, 0xe6, 0xca, 0xdd,
  32895. 0x78, 0x76, 0x93, 0x75, 0xec, 0x3f, 0xfd, 0x1b,
  32896. 0x80, 0x1a, 0x0d, 0x9b, 0x3f, 0x40, 0x30, 0xcd,
  32897. 0x43, 0x39, 0x64, 0xb6, 0x45, 0x7e, 0xa3, 0x94,
  32898. 0x76, 0x51, 0x12, 0x14, 0xf9, 0x74, 0x69, 0xb5,
  32899. 0x7d, 0xd3, 0x2d, 0xbc, 0x56, 0x0a, 0x9a, 0x94,
  32900. 0xd0, 0x0b, 0xff, 0x07, 0x62, 0x04, 0x64, 0xa3,
  32901. 0xad, 0x20, 0x3d, 0xf7, 0xdc, 0x7c, 0xe3, 0x60,
  32902. 0xc3, 0xcd, 0x36, 0x96, 0xd9, 0xd9, 0xfa, 0xb9,
  32903. 0x0f, 0x00
  32904. };
  32905. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  32906. 0xc3, 0x22, 0x99, 0xd4, 0x6e, 0xc8, 0xff, 0x02,
  32907. 0xb5, 0x45, 0x40, 0x98, 0x28, 0x14, 0xdc, 0xe9,
  32908. 0xa0, 0x58, 0x12, 0xf8, 0x19, 0x62, 0xb6, 0x49,
  32909. 0xd5, 0x28, 0x09, 0x59, 0x16, 0xa2, 0xaa, 0x48,
  32910. 0x10, 0x65, 0xb1, 0x58, 0x04, 0x23, 0xef, 0x92,
  32911. 0x7e, 0xcf, 0x0a, 0xf5, 0x88, 0x8f, 0x90, 0xda,
  32912. 0x0f, 0x6a, 0x9a, 0x85, 0xad, 0x5d, 0xc3, 0xf2,
  32913. 0x80, 0xd9, 0x12, 0x24, 0xba, 0x99, 0x11, 0xa3,
  32914. 0x65, 0x3d, 0x00, 0xe4, 0x84, 0xe2, 0xce, 0x23,
  32915. 0x25, 0x21, 0x48, 0x1c, 0x86, 0x58, 0xdf, 0x30,
  32916. 0x4b, 0xb7, 0x74, 0x5a, 0x73, 0x51, 0x4c, 0xdb,
  32917. 0x9b, 0xf3, 0xe1, 0x57, 0x84, 0xab, 0x71, 0x28,
  32918. 0x4f, 0x8d, 0x07, 0x04, 0xa6, 0x08, 0xc5, 0x4a,
  32919. 0x6b, 0x62, 0xd9, 0x7b, 0xeb, 0x51, 0x1d, 0x13,
  32920. 0x21, 0x00
  32921. };
  32922. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  32923. 0x61,0x62,0x63
  32924. };
  32925. /* SHA-512 hash of msgPh */
  32926. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  32927. 0x48, 0x33, 0x66, 0x60, 0x13, 0x60, 0xa8, 0x77,
  32928. 0x1c, 0x68, 0x63, 0x08, 0x0c, 0xc4, 0x11, 0x4d,
  32929. 0x8d, 0xb4, 0x45, 0x30, 0xf8, 0xf1, 0xe1, 0xee,
  32930. 0x4f, 0x94, 0xea, 0x37, 0xe7, 0x8b, 0x57, 0x39,
  32931. 0xd5, 0xa1, 0x5b, 0xef, 0x18, 0x6a, 0x53, 0x86,
  32932. 0xc7, 0x57, 0x44, 0xc0, 0x52, 0x7e, 0x1f, 0xaa,
  32933. 0x9f, 0x87, 0x26, 0xe4, 0x62, 0xa1, 0x2a, 0x4f,
  32934. 0xeb, 0x06, 0xbd, 0x88, 0x01, 0xe7, 0x51, 0xe4
  32935. };
  32936. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  32937. 0x66,0x6f,0x6f
  32938. };
  32939. outlen = sizeof(out);
  32940. XMEMSET(out, 0, sizeof(out));
  32941. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  32942. if (ret != 0)
  32943. return WC_TEST_RET_ENC_EC(ret);
  32944. ret = wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh,
  32945. sizeof(pKeyPh), &key);
  32946. if (ret != 0)
  32947. return WC_TEST_RET_ENC_EC(ret);
  32948. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL,
  32949. 0);
  32950. if (ret != 0)
  32951. return WC_TEST_RET_ENC_EC(ret);
  32952. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  32953. return WC_TEST_RET_ENC_NC;
  32954. #if defined(HAVE_ED448_VERIFY)
  32955. /* test verify on good msg */
  32956. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  32957. NULL, 0);
  32958. if (ret != 0 || verify != 1) {
  32959. return WC_TEST_RET_ENC_EC(ret);
  32960. }
  32961. #endif
  32962. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  32963. contextPh2, sizeof(contextPh2));
  32964. if (ret != 0)
  32965. return WC_TEST_RET_ENC_EC(ret);
  32966. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  32967. return WC_TEST_RET_ENC_NC;
  32968. #if defined(HAVE_ED448_VERIFY)
  32969. /* test verify on good msg */
  32970. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  32971. contextPh2, sizeof(contextPh2));
  32972. if (ret != 0 || verify != 1) {
  32973. return WC_TEST_RET_ENC_EC(ret);
  32974. }
  32975. #endif
  32976. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL,
  32977. 0);
  32978. if (ret != 0)
  32979. return WC_TEST_RET_ENC_EC(ret);
  32980. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  32981. return WC_TEST_RET_ENC_NC;
  32982. #if defined(HAVE_ED448_VERIFY)
  32983. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  32984. &key, NULL, 0);
  32985. if (ret != 0 || verify != 1) {
  32986. return WC_TEST_RET_ENC_EC(ret);
  32987. }
  32988. #endif
  32989. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  32990. contextPh2, sizeof(contextPh2));
  32991. if (ret != 0)
  32992. return WC_TEST_RET_ENC_EC(ret);
  32993. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  32994. return WC_TEST_RET_ENC_NC;
  32995. #if defined(HAVE_ED448_VERIFY)
  32996. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  32997. &key, contextPh2, sizeof(contextPh2));
  32998. if (ret != 0 || verify != 1) {
  32999. return WC_TEST_RET_ENC_EC(ret);
  33000. }
  33001. #endif
  33002. wc_ed448_free(&key);
  33003. return 0;
  33004. }
  33005. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33006. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
  33007. {
  33008. wc_test_ret_t ret;
  33009. WC_RNG rng;
  33010. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33011. defined(HAVE_ED448_KEY_IMPORT)
  33012. byte out[ED448_SIG_SIZE];
  33013. int i;
  33014. word32 outlen;
  33015. #ifdef HAVE_ED448_VERIFY
  33016. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33017. int j;
  33018. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33019. int verify;
  33020. #endif /* HAVE_ED448_VERIFY */
  33021. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33022. word32 keySz, sigSz;
  33023. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33024. ed448_key *key = NULL;
  33025. ed448_key *key2 = NULL;
  33026. #else
  33027. ed448_key key[1];
  33028. ed448_key key2[1];
  33029. #endif
  33030. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33031. defined(HAVE_ED448_KEY_IMPORT)
  33032. /* test vectors from
  33033. https://tools.ietf.org/html/rfc8032
  33034. */
  33035. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  33036. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33037. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33038. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33039. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33040. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33041. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33042. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33043. 0x5b
  33044. };
  33045. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  33046. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33047. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33048. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33049. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33050. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33051. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33052. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33053. 0x4e
  33054. };
  33055. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  33056. 0x25, 0x8c, 0xdd, 0x4a, 0xda, 0x32, 0xed, 0x9c,
  33057. 0x9f, 0xf5, 0x4e, 0x63, 0x75, 0x6a, 0xe5, 0x82,
  33058. 0xfb, 0x8f, 0xab, 0x2a, 0xc7, 0x21, 0xf2, 0xc8,
  33059. 0xe6, 0x76, 0xa7, 0x27, 0x68, 0x51, 0x3d, 0x93,
  33060. 0x9f, 0x63, 0xdd, 0xdb, 0x55, 0x60, 0x91, 0x33,
  33061. 0xf2, 0x9a, 0xdf, 0x86, 0xec, 0x99, 0x29, 0xdc,
  33062. 0xcb, 0x52, 0xc1, 0xc5, 0xfd, 0x2f, 0xf7, 0xe2,
  33063. 0x1b
  33064. };
  33065. /* uncompressed test */
  33066. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  33067. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33068. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33069. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33070. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33071. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33072. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33073. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33074. 0x5b
  33075. };
  33076. /* compressed prefix test */
  33077. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  33078. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33079. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33080. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33081. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33082. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33083. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33084. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33085. 0x5b
  33086. };
  33087. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  33088. 0x87, 0x2d, 0x09, 0x37, 0x80, 0xf5, 0xd3, 0x73,
  33089. 0x0d, 0xf7, 0xc2, 0x12, 0x66, 0x4b, 0x37, 0xb8,
  33090. 0xa0, 0xf2, 0x4f, 0x56, 0x81, 0x0d, 0xaa, 0x83,
  33091. 0x82, 0xcd, 0x4f, 0xa3, 0xf7, 0x76, 0x34, 0xec,
  33092. 0x44, 0xdc, 0x54, 0xf1, 0xc2, 0xed, 0x9b, 0xea,
  33093. 0x86, 0xfa, 0xfb, 0x76, 0x32, 0xd8, 0xbe, 0x19,
  33094. 0x9e, 0xa1, 0x65, 0xf5, 0xad, 0x55, 0xdd, 0x9c,
  33095. 0xe8
  33096. };
  33097. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  33098. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  33099. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33100. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33101. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33102. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33103. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33104. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33105. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33106. 0x80
  33107. };
  33108. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  33109. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33110. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33111. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33112. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33113. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33114. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33115. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33116. 0x80
  33117. };
  33118. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  33119. 0x3b, 0xa1, 0x6d, 0xa0, 0xc6, 0xf2, 0xcc, 0x1f,
  33120. 0x30, 0x18, 0x77, 0x40, 0x75, 0x6f, 0x5e, 0x79,
  33121. 0x8d, 0x6b, 0xc5, 0xfc, 0x01, 0x5d, 0x7c, 0x63,
  33122. 0xcc, 0x95, 0x10, 0xee, 0x3f, 0xd4, 0x4a, 0xdc,
  33123. 0x24, 0xd8, 0xe9, 0x68, 0xb6, 0xe4, 0x6e, 0x6f,
  33124. 0x94, 0xd1, 0x9b, 0x94, 0x53, 0x61, 0x72, 0x6b,
  33125. 0xd7, 0x5e, 0x14, 0x9e, 0xf0, 0x98, 0x17, 0xf5,
  33126. 0x80
  33127. };
  33128. /* uncompressed test */
  33129. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  33130. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33131. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33132. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33133. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33134. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33135. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33136. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33137. 0x80
  33138. };
  33139. /* compressed prefix */
  33140. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  33141. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33142. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33143. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33144. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33145. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33146. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33147. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33148. 0x80
  33149. };
  33150. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  33151. 0xa8, 0x1b, 0x2e, 0x8a, 0x70, 0xa5, 0xac, 0x94,
  33152. 0xff, 0xdb, 0xcc, 0x9b, 0xad, 0xfc, 0x3f, 0xeb,
  33153. 0x08, 0x01, 0xf2, 0x58, 0x57, 0x8b, 0xb1, 0x14,
  33154. 0xad, 0x44, 0xec, 0xe1, 0xec, 0x0e, 0x79, 0x9d,
  33155. 0xa0, 0x8e, 0xff, 0xb8, 0x1c, 0x5d, 0x68, 0x5c,
  33156. 0x0c, 0x56, 0xf6, 0x4e, 0xec, 0xae, 0xf8, 0xcd,
  33157. 0xf1, 0x1c, 0xc3, 0x87, 0x37, 0x83, 0x8c, 0xf4,
  33158. 0x00
  33159. };
  33160. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  33161. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  33162. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  33163. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  33164. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33165. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33166. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33167. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33168. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33169. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33170. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33171. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33172. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33173. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33174. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33175. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33176. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33177. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33178. 0x26, 0x00
  33179. };
  33180. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  33181. 0x26, 0xb8, 0xf9, 0x17, 0x27, 0xbd, 0x62, 0x89,
  33182. 0x7a, 0xf1, 0x5e, 0x41, 0xeb, 0x43, 0xc3, 0x77,
  33183. 0xef, 0xb9, 0xc6, 0x10, 0xd4, 0x8f, 0x23, 0x35,
  33184. 0xcb, 0x0b, 0xd0, 0x08, 0x78, 0x10, 0xf4, 0x35,
  33185. 0x25, 0x41, 0xb1, 0x43, 0xc4, 0xb9, 0x81, 0xb7,
  33186. 0xe1, 0x8f, 0x62, 0xde, 0x8c, 0xcd, 0xf6, 0x33,
  33187. 0xfc, 0x1b, 0xf0, 0x37, 0xab, 0x7c, 0xd7, 0x79,
  33188. 0x80, 0x5e, 0x0d, 0xbc, 0xc0, 0xaa, 0xe1, 0xcb,
  33189. 0xce, 0xe1, 0xaf, 0xb2, 0xe0, 0x27, 0xdf, 0x36,
  33190. 0xbc, 0x04, 0xdc, 0xec, 0xbf, 0x15, 0x43, 0x36,
  33191. 0xc1, 0x9f, 0x0a, 0xf7, 0xe0, 0xa6, 0x47, 0x29,
  33192. 0x05, 0xe7, 0x99, 0xf1, 0x95, 0x3d, 0x2a, 0x0f,
  33193. 0xf3, 0x34, 0x8a, 0xb2, 0x1a, 0xa4, 0xad, 0xaf,
  33194. 0xd1, 0xd2, 0x34, 0x44, 0x1c, 0xf8, 0x07, 0xc0,
  33195. 0x3a, 0x00
  33196. };
  33197. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  33198. 0x7e, 0xee, 0xab, 0x7c, 0x4e, 0x50, 0xfb, 0x79,
  33199. 0x9b, 0x41, 0x8e, 0xe5, 0xe3, 0x19, 0x7f, 0xf6,
  33200. 0xbf, 0x15, 0xd4, 0x3a, 0x14, 0xc3, 0x43, 0x89,
  33201. 0xb5, 0x9d, 0xd1, 0xa7, 0xb1, 0xb8, 0x5b, 0x4a,
  33202. 0xe9, 0x04, 0x38, 0xac, 0xa6, 0x34, 0xbe, 0xa4,
  33203. 0x5e, 0x3a, 0x26, 0x95, 0xf1, 0x27, 0x0f, 0x07,
  33204. 0xfd, 0xcd, 0xf7, 0xc6, 0x2b, 0x8e, 0xfe, 0xaf,
  33205. 0x00, 0xb4, 0x5c, 0x2c, 0x96, 0xba, 0x45, 0x7e,
  33206. 0xb1, 0xa8, 0xbf, 0x07, 0x5a, 0x3d, 0xb2, 0x8e,
  33207. 0x5c, 0x24, 0xf6, 0xb9, 0x23, 0xed, 0x4a, 0xd7,
  33208. 0x47, 0xc3, 0xc9, 0xe0, 0x3c, 0x70, 0x79, 0xef,
  33209. 0xb8, 0x7c, 0xb1, 0x10, 0xd3, 0xa9, 0x98, 0x61,
  33210. 0xe7, 0x20, 0x03, 0xcb, 0xae, 0x6d, 0x6b, 0x8b,
  33211. 0x82, 0x7e, 0x4e, 0x6c, 0x14, 0x30, 0x64, 0xff,
  33212. 0x3c, 0x00
  33213. };
  33214. /* uncompressed test */
  33215. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  33216. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33217. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33218. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33219. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33220. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33221. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33222. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33223. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33224. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33225. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33226. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33227. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33228. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33229. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33230. 0x26, 0x00
  33231. };
  33232. /* compressed prefix */
  33233. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  33234. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33235. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33236. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33237. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33238. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33239. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33240. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33241. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33242. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33243. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33244. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33245. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33246. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33247. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33248. 0x26, 0x00
  33249. };
  33250. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  33251. 0xe3, 0x01, 0x34, 0x5a, 0x41, 0xa3, 0x9a, 0x4d,
  33252. 0x72, 0xff, 0xf8, 0xdf, 0x69, 0xc9, 0x80, 0x75,
  33253. 0xa0, 0xcc, 0x08, 0x2b, 0x80, 0x2f, 0xc9, 0xb2,
  33254. 0xb6, 0xbc, 0x50, 0x3f, 0x92, 0x6b, 0x65, 0xbd,
  33255. 0xdf, 0x7f, 0x4c, 0x8f, 0x1c, 0xb4, 0x9f, 0x63,
  33256. 0x96, 0xaf, 0xc8, 0xa7, 0x0a, 0xbe, 0x6d, 0x8a,
  33257. 0xef, 0x0d, 0xb4, 0x78, 0xd4, 0xc6, 0xb2, 0x97,
  33258. 0x00, 0x76, 0xc6, 0xa0, 0x48, 0x4f, 0xe7, 0x6d,
  33259. 0x76, 0xb3, 0xa9, 0x76, 0x25, 0xd7, 0x9f, 0x1c,
  33260. 0xe2, 0x40, 0xe7, 0xc5, 0x76, 0x75, 0x0d, 0x29,
  33261. 0x55, 0x28, 0x28, 0x6f, 0x71, 0x9b, 0x41, 0x3d,
  33262. 0xe9, 0xad, 0xa3, 0xe8, 0xeb, 0x78, 0xed, 0x57,
  33263. 0x36, 0x03, 0xce, 0x30, 0xd8, 0xbb, 0x76, 0x17,
  33264. 0x85, 0xdc, 0x30, 0xdb, 0xc3, 0x20, 0x86, 0x9e,
  33265. 0x1a, 0x00
  33266. };
  33267. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  33268. #define SIGSZ sizeof(sig1)
  33269. PEDANTIC_EXTENSION WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = { 0 };
  33270. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = { 0x03 };
  33271. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = { 0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd,
  33272. 0x66, 0x81, 0x1e, 0x29, 0x15 };
  33273. /* test of a 1023 byte long message */
  33274. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  33275. 0x6d, 0xdf, 0x80, 0x2e, 0x1a, 0xae, 0x49, 0x86,
  33276. 0x93, 0x5f, 0x7f, 0x98, 0x1b, 0xa3, 0xf0, 0x35,
  33277. 0x1d, 0x62, 0x73, 0xc0, 0xa0, 0xc2, 0x2c, 0x9c,
  33278. 0x0e, 0x83, 0x39, 0x16, 0x8e, 0x67, 0x54, 0x12,
  33279. 0xa3, 0xde, 0xbf, 0xaf, 0x43, 0x5e, 0xd6, 0x51,
  33280. 0x55, 0x80, 0x07, 0xdb, 0x43, 0x84, 0xb6, 0x50,
  33281. 0xfc, 0xc0, 0x7e, 0x3b, 0x58, 0x6a, 0x27, 0xa4,
  33282. 0xf7, 0xa0, 0x0a, 0xc8, 0xa6, 0xfe, 0xc2, 0xcd,
  33283. 0x86, 0xae, 0x4b, 0xf1, 0x57, 0x0c, 0x41, 0xe6,
  33284. 0xa4, 0x0c, 0x93, 0x1d, 0xb2, 0x7b, 0x2f, 0xaa,
  33285. 0x15, 0xa8, 0xce, 0xdd, 0x52, 0xcf, 0xf7, 0x36,
  33286. 0x2c, 0x4e, 0x6e, 0x23, 0xda, 0xec, 0x0f, 0xbc,
  33287. 0x3a, 0x79, 0xb6, 0x80, 0x6e, 0x31, 0x6e, 0xfc,
  33288. 0xc7, 0xb6, 0x81, 0x19, 0xbf, 0x46, 0xbc, 0x76,
  33289. 0xa2, 0x60, 0x67, 0xa5, 0x3f, 0x29, 0x6d, 0xaf,
  33290. 0xdb, 0xdc, 0x11, 0xc7, 0x7f, 0x77, 0x77, 0xe9,
  33291. 0x72, 0x66, 0x0c, 0xf4, 0xb6, 0xa9, 0xb3, 0x69,
  33292. 0xa6, 0x66, 0x5f, 0x02, 0xe0, 0xcc, 0x9b, 0x6e,
  33293. 0xdf, 0xad, 0x13, 0x6b, 0x4f, 0xab, 0xe7, 0x23,
  33294. 0xd2, 0x81, 0x3d, 0xb3, 0x13, 0x6c, 0xfd, 0xe9,
  33295. 0xb6, 0xd0, 0x44, 0x32, 0x2f, 0xee, 0x29, 0x47,
  33296. 0x95, 0x2e, 0x03, 0x1b, 0x73, 0xab, 0x5c, 0x60,
  33297. 0x33, 0x49, 0xb3, 0x07, 0xbd, 0xc2, 0x7b, 0xc6,
  33298. 0xcb, 0x8b, 0x8b, 0xbd, 0x7b, 0xd3, 0x23, 0x21,
  33299. 0x9b, 0x80, 0x33, 0xa5, 0x81, 0xb5, 0x9e, 0xad,
  33300. 0xeb, 0xb0, 0x9b, 0x3c, 0x4f, 0x3d, 0x22, 0x77,
  33301. 0xd4, 0xf0, 0x34, 0x36, 0x24, 0xac, 0xc8, 0x17,
  33302. 0x80, 0x47, 0x28, 0xb2, 0x5a, 0xb7, 0x97, 0x17,
  33303. 0x2b, 0x4c, 0x5c, 0x21, 0xa2, 0x2f, 0x9c, 0x78,
  33304. 0x39, 0xd6, 0x43, 0x00, 0x23, 0x2e, 0xb6, 0x6e,
  33305. 0x53, 0xf3, 0x1c, 0x72, 0x3f, 0xa3, 0x7f, 0xe3,
  33306. 0x87, 0xc7, 0xd3, 0xe5, 0x0b, 0xdf, 0x98, 0x13,
  33307. 0xa3, 0x0e, 0x5b, 0xb1, 0x2c, 0xf4, 0xcd, 0x93,
  33308. 0x0c, 0x40, 0xcf, 0xb4, 0xe1, 0xfc, 0x62, 0x25,
  33309. 0x92, 0xa4, 0x95, 0x88, 0x79, 0x44, 0x94, 0xd5,
  33310. 0x6d, 0x24, 0xea, 0x4b, 0x40, 0xc8, 0x9f, 0xc0,
  33311. 0x59, 0x6c, 0xc9, 0xeb, 0xb9, 0x61, 0xc8, 0xcb,
  33312. 0x10, 0xad, 0xde, 0x97, 0x6a, 0x5d, 0x60, 0x2b,
  33313. 0x1c, 0x3f, 0x85, 0xb9, 0xb9, 0xa0, 0x01, 0xed,
  33314. 0x3c, 0x6a, 0x4d, 0x3b, 0x14, 0x37, 0xf5, 0x20,
  33315. 0x96, 0xcd, 0x19, 0x56, 0xd0, 0x42, 0xa5, 0x97,
  33316. 0xd5, 0x61, 0xa5, 0x96, 0xec, 0xd3, 0xd1, 0x73,
  33317. 0x5a, 0x8d, 0x57, 0x0e, 0xa0, 0xec, 0x27, 0x22,
  33318. 0x5a, 0x2c, 0x4a, 0xaf, 0xf2, 0x63, 0x06, 0xd1,
  33319. 0x52, 0x6c, 0x1a, 0xf3, 0xca, 0x6d, 0x9c, 0xf5,
  33320. 0xa2, 0xc9, 0x8f, 0x47, 0xe1, 0xc4, 0x6d, 0xb9,
  33321. 0xa3, 0x32, 0x34, 0xcf, 0xd4, 0xd8, 0x1f, 0x2c,
  33322. 0x98, 0x53, 0x8a, 0x09, 0xeb, 0xe7, 0x69, 0x98,
  33323. 0xd0, 0xd8, 0xfd, 0x25, 0x99, 0x7c, 0x7d, 0x25,
  33324. 0x5c, 0x6d, 0x66, 0xec, 0xe6, 0xfa, 0x56, 0xf1,
  33325. 0x11, 0x44, 0x95, 0x0f, 0x02, 0x77, 0x95, 0xe6,
  33326. 0x53, 0x00, 0x8f, 0x4b, 0xd7, 0xca, 0x2d, 0xee,
  33327. 0x85, 0xd8, 0xe9, 0x0f, 0x3d, 0xc3, 0x15, 0x13,
  33328. 0x0c, 0xe2, 0xa0, 0x03, 0x75, 0xa3, 0x18, 0xc7,
  33329. 0xc3, 0xd9, 0x7b, 0xe2, 0xc8, 0xce, 0x5b, 0x6d,
  33330. 0xb4, 0x1a, 0x62, 0x54, 0xff, 0x26, 0x4f, 0xa6,
  33331. 0x15, 0x5b, 0xae, 0xe3, 0xb0, 0x77, 0x3c, 0x0f,
  33332. 0x49, 0x7c, 0x57, 0x3f, 0x19, 0xbb, 0x4f, 0x42,
  33333. 0x40, 0x28, 0x1f, 0x0b, 0x1f, 0x4f, 0x7b, 0xe8,
  33334. 0x57, 0xa4, 0xe5, 0x9d, 0x41, 0x6c, 0x06, 0xb4,
  33335. 0xc5, 0x0f, 0xa0, 0x9e, 0x18, 0x10, 0xdd, 0xc6,
  33336. 0xb1, 0x46, 0x7b, 0xae, 0xac, 0x5a, 0x36, 0x68,
  33337. 0xd1, 0x1b, 0x6e, 0xca, 0xa9, 0x01, 0x44, 0x00,
  33338. 0x16, 0xf3, 0x89, 0xf8, 0x0a, 0xcc, 0x4d, 0xb9,
  33339. 0x77, 0x02, 0x5e, 0x7f, 0x59, 0x24, 0x38, 0x8c,
  33340. 0x7e, 0x34, 0x0a, 0x73, 0x2e, 0x55, 0x44, 0x40,
  33341. 0xe7, 0x65, 0x70, 0xf8, 0xdd, 0x71, 0xb7, 0xd6,
  33342. 0x40, 0xb3, 0x45, 0x0d, 0x1f, 0xd5, 0xf0, 0x41,
  33343. 0x0a, 0x18, 0xf9, 0xa3, 0x49, 0x4f, 0x70, 0x7c,
  33344. 0x71, 0x7b, 0x79, 0xb4, 0xbf, 0x75, 0xc9, 0x84,
  33345. 0x00, 0xb0, 0x96, 0xb2, 0x16, 0x53, 0xb5, 0xd2,
  33346. 0x17, 0xcf, 0x35, 0x65, 0xc9, 0x59, 0x74, 0x56,
  33347. 0xf7, 0x07, 0x03, 0x49, 0x7a, 0x07, 0x87, 0x63,
  33348. 0x82, 0x9b, 0xc0, 0x1b, 0xb1, 0xcb, 0xc8, 0xfa,
  33349. 0x04, 0xea, 0xdc, 0x9a, 0x6e, 0x3f, 0x66, 0x99,
  33350. 0x58, 0x7a, 0x9e, 0x75, 0xc9, 0x4e, 0x5b, 0xab,
  33351. 0x00, 0x36, 0xe0, 0xb2, 0xe7, 0x11, 0x39, 0x2c,
  33352. 0xff, 0x00, 0x47, 0xd0, 0xd6, 0xb0, 0x5b, 0xd2,
  33353. 0xa5, 0x88, 0xbc, 0x10, 0x97, 0x18, 0x95, 0x42,
  33354. 0x59, 0xf1, 0xd8, 0x66, 0x78, 0xa5, 0x79, 0xa3,
  33355. 0x12, 0x0f, 0x19, 0xcf, 0xb2, 0x96, 0x3f, 0x17,
  33356. 0x7a, 0xeb, 0x70, 0xf2, 0xd4, 0x84, 0x48, 0x26,
  33357. 0x26, 0x2e, 0x51, 0xb8, 0x02, 0x71, 0x27, 0x20,
  33358. 0x68, 0xef, 0x5b, 0x38, 0x56, 0xfa, 0x85, 0x35,
  33359. 0xaa, 0x2a, 0x88, 0xb2, 0xd4, 0x1f, 0x2a, 0x0e,
  33360. 0x2f, 0xda, 0x76, 0x24, 0xc2, 0x85, 0x02, 0x72,
  33361. 0xac, 0x4a, 0x2f, 0x56, 0x1f, 0x8f, 0x2f, 0x7a,
  33362. 0x31, 0x8b, 0xfd, 0x5c, 0xaf, 0x96, 0x96, 0x14,
  33363. 0x9e, 0x4a, 0xc8, 0x24, 0xad, 0x34, 0x60, 0x53,
  33364. 0x8f, 0xdc, 0x25, 0x42, 0x1b, 0xee, 0xc2, 0xcc,
  33365. 0x68, 0x18, 0x16, 0x2d, 0x06, 0xbb, 0xed, 0x0c,
  33366. 0x40, 0xa3, 0x87, 0x19, 0x23, 0x49, 0xdb, 0x67,
  33367. 0xa1, 0x18, 0xba, 0xda, 0x6c, 0xd5, 0xab, 0x01,
  33368. 0x40, 0xee, 0x27, 0x32, 0x04, 0xf6, 0x28, 0xaa,
  33369. 0xd1, 0xc1, 0x35, 0xf7, 0x70, 0x27, 0x9a, 0x65,
  33370. 0x1e, 0x24, 0xd8, 0xc1, 0x4d, 0x75, 0xa6, 0x05,
  33371. 0x9d, 0x76, 0xb9, 0x6a, 0x6f, 0xd8, 0x57, 0xde,
  33372. 0xf5, 0xe0, 0xb3, 0x54, 0xb2, 0x7a, 0xb9, 0x37,
  33373. 0xa5, 0x81, 0x5d, 0x16, 0xb5, 0xfa, 0xe4, 0x07,
  33374. 0xff, 0x18, 0x22, 0x2c, 0x6d, 0x1e, 0xd2, 0x63,
  33375. 0xbe, 0x68, 0xc9, 0x5f, 0x32, 0xd9, 0x08, 0xbd,
  33376. 0x89, 0x5c, 0xd7, 0x62, 0x07, 0xae, 0x72, 0x64,
  33377. 0x87, 0x56, 0x7f, 0x9a, 0x67, 0xda, 0xd7, 0x9a,
  33378. 0xbe, 0xc3, 0x16, 0xf6, 0x83, 0xb1, 0x7f, 0x2d,
  33379. 0x02, 0xbf, 0x07, 0xe0, 0xac, 0x8b, 0x5b, 0xc6,
  33380. 0x16, 0x2c, 0xf9, 0x46, 0x97, 0xb3, 0xc2, 0x7c,
  33381. 0xd1, 0xfe, 0xa4, 0x9b, 0x27, 0xf2, 0x3b, 0xa2,
  33382. 0x90, 0x18, 0x71, 0x96, 0x25, 0x06, 0x52, 0x0c,
  33383. 0x39, 0x2d, 0xa8, 0xb6, 0xad, 0x0d, 0x99, 0xf7,
  33384. 0x01, 0x3f, 0xbc, 0x06, 0xc2, 0xc1, 0x7a, 0x56,
  33385. 0x95, 0x00, 0xc8, 0xa7, 0x69, 0x64, 0x81, 0xc1,
  33386. 0xcd, 0x33, 0xe9, 0xb1, 0x4e, 0x40, 0xb8, 0x2e,
  33387. 0x79, 0xa5, 0xf5, 0xdb, 0x82, 0x57, 0x1b, 0xa9,
  33388. 0x7b, 0xae, 0x3a, 0xd3, 0xe0, 0x47, 0x95, 0x15,
  33389. 0xbb, 0x0e, 0x2b, 0x0f, 0x3b, 0xfc, 0xd1, 0xfd,
  33390. 0x33, 0x03, 0x4e, 0xfc, 0x62, 0x45, 0xed, 0xdd,
  33391. 0x7e, 0xe2, 0x08, 0x6d, 0xda, 0xe2, 0x60, 0x0d,
  33392. 0x8c, 0xa7, 0x3e, 0x21, 0x4e, 0x8c, 0x2b, 0x0b,
  33393. 0xdb, 0x2b, 0x04, 0x7c, 0x6a, 0x46, 0x4a, 0x56,
  33394. 0x2e, 0xd7, 0x7b, 0x73, 0xd2, 0xd8, 0x41, 0xc4,
  33395. 0xb3, 0x49, 0x73, 0x55, 0x12, 0x57, 0x71, 0x3b,
  33396. 0x75, 0x36, 0x32, 0xef, 0xba, 0x34, 0x81, 0x69,
  33397. 0xab, 0xc9, 0x0a, 0x68, 0xf4, 0x26, 0x11, 0xa4,
  33398. 0x01, 0x26, 0xd7, 0xcb, 0x21, 0xb5, 0x86, 0x95,
  33399. 0x56, 0x81, 0x86, 0xf7, 0xe5, 0x69, 0xd2, 0xff,
  33400. 0x0f, 0x9e, 0x74, 0x5d, 0x04, 0x87, 0xdd, 0x2e,
  33401. 0xb9, 0x97, 0xca, 0xfc, 0x5a, 0xbf, 0x9d, 0xd1,
  33402. 0x02, 0xe6, 0x2f, 0xf6, 0x6c, 0xba, 0x87
  33403. };
  33404. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  33405. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  33406. sizeof(msg2),
  33407. sizeof(msg3),
  33408. 0 /*sizeof(msg1)*/,
  33409. 0 /*sizeof(msg1)*/,
  33410. sizeof(msg4)
  33411. };
  33412. #ifndef NO_ASN
  33413. static const byte privateEd448[] = {
  33414. 0x30, 0x47, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
  33415. 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04, 0x39,
  33416. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33417. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33418. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33419. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33420. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33421. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33422. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33423. 0x5b
  33424. };
  33425. static const byte publicEd448[] = {
  33426. 0x30, 0x43, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
  33427. 0x71, 0x03, 0x3a, 0x00, 0x5f, 0xd7, 0x44, 0x9b,
  33428. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33429. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33430. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33431. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33432. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33433. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33434. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33435. };
  33436. static const byte privPubEd448[] = {
  33437. 0x30, 0x81, 0x82, 0x02, 0x01, 0x00, 0x30, 0x05,
  33438. 0x06, 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04,
  33439. 0x39, 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d,
  33440. 0x10, 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e,
  33441. 0xbf, 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c,
  33442. 0x9f, 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48,
  33443. 0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04,
  33444. 0x4e, 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f,
  33445. 0x8f, 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98,
  33446. 0xf9, 0x5b, 0x81, 0x39, 0x5f, 0xd7, 0x44, 0x9b,
  33447. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33448. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33449. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33450. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33451. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33452. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33453. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33454. };
  33455. word32 idx;
  33456. #endif /* NO_ASN */
  33457. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33458. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33459. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33460. ed448_key *key3 = NULL;
  33461. #else
  33462. ed448_key key3[1];
  33463. #endif
  33464. #endif
  33465. WOLFSSL_ENTER("ed448_test");
  33466. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33467. key = (ed448_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33468. key2 = (ed448_key *)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33469. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33470. key3 = (ed448_key *)XMALLOC(sizeof(*key3), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33471. #endif
  33472. #endif
  33473. /* create ed448 keys */
  33474. #ifndef HAVE_FIPS
  33475. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  33476. #else
  33477. ret = wc_InitRng(&rng);
  33478. #endif
  33479. if (ret != 0) {
  33480. XMEMSET(&rng, 0, sizeof(rng));
  33481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33482. }
  33483. ret = wc_ed448_init(key);
  33484. if (ret < 0)
  33485. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33486. ret = wc_ed448_init(key2);
  33487. if (ret < 0)
  33488. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33489. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33490. ret = wc_ed448_init(key3);
  33491. if (ret < 0)
  33492. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33493. #endif
  33494. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key);
  33495. if (ret < 0)
  33496. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33497. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2);
  33498. if (ret < 0)
  33499. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33500. /* helper functions for signature and key size */
  33501. keySz = (word32)wc_ed448_size(key);
  33502. sigSz = (word32)wc_ed448_sig_size(key);
  33503. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33504. defined(HAVE_ED448_KEY_IMPORT)
  33505. for (i = 0; i < 6; i++) {
  33506. outlen = sizeof(out);
  33507. XMEMSET(out, 0, sizeof(out));
  33508. if (wc_ed448_import_private_key(sKeys[i], ED448_KEY_SIZE, pKeys[i],
  33509. pKeySz[i], key) != 0)
  33510. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33511. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key, NULL,
  33512. 0) != 0)
  33513. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33514. if (XMEMCMP(out, sigs[i], 114))
  33515. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33516. #if defined(HAVE_ED448_VERIFY)
  33517. /* test verify on good msg */
  33518. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33519. NULL, 0) != 0 || verify != 1)
  33520. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33521. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33522. /* test verify on good msg using streaming interface directly */
  33523. if (wc_ed448_verify_msg_init(out, outlen,
  33524. key, (byte)Ed448, NULL, 0) != 0)
  33525. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33526. for (j = 0; j < msgSz[i]; j += i) {
  33527. if (wc_ed448_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  33528. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33529. }
  33530. if (wc_ed448_verify_msg_final(out, outlen, &verify,
  33531. key) != 0 || verify != 1)
  33532. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33533. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33534. /* test verify on bad msg */
  33535. out[outlen-2] = out[outlen-2] + 1;
  33536. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33537. NULL, 0) == 0 || verify == 1)
  33538. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33539. #endif /* HAVE_ED448_VERIFY */
  33540. /* test api for import/exporting keys */
  33541. {
  33542. byte *exportPKey = NULL;
  33543. byte *exportSKey = NULL;
  33544. word32 exportPSz = ED448_KEY_SIZE;
  33545. word32 exportSSz = ED448_KEY_SIZE;
  33546. exportPKey = (byte *)XMALLOC(exportPSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33547. exportSKey = (byte *)XMALLOC(exportSSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33548. if ((exportPKey == NULL) || (exportSKey == NULL))
  33549. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33550. ret = 0;
  33551. do {
  33552. if (wc_ed448_export_public(key, exportPKey, &exportPSz) != 0) {
  33553. ret = WC_TEST_RET_ENC_I(i);
  33554. break;
  33555. }
  33556. if (wc_ed448_import_public_ex(exportPKey, exportPSz, key2, 1) != 0) {
  33557. ret = WC_TEST_RET_ENC_I(i);
  33558. break;
  33559. }
  33560. if (wc_ed448_export_private_only(key, exportSKey, &exportSSz) != 0) {
  33561. ret = WC_TEST_RET_ENC_I(i);
  33562. break;
  33563. }
  33564. if (wc_ed448_import_private_key(exportSKey, exportSSz,
  33565. exportPKey, exportPSz, key2) != 0) {
  33566. ret = WC_TEST_RET_ENC_I(i);
  33567. break;
  33568. }
  33569. /* clear "out" buffer and test sign with imported keys */
  33570. outlen = sizeof(out);
  33571. XMEMSET(out, 0, sizeof(out));
  33572. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key2, NULL,
  33573. 0) != 0) {
  33574. ret = WC_TEST_RET_ENC_I(i);
  33575. break;
  33576. }
  33577. } while(0);
  33578. XFREE(exportPKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33579. XFREE(exportSKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33580. if (ret != 0)
  33581. goto out;
  33582. }
  33583. #if defined(HAVE_ED448_VERIFY)
  33584. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key2,
  33585. NULL, 0) != 0 || verify != 1)
  33586. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33587. if (XMEMCMP(out, sigs[i], SIGSZ))
  33588. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33589. #endif /* HAVE_ED448_VERIFY */
  33590. }
  33591. ret = ed448_ctx_test();
  33592. if (ret != 0)
  33593. goto out;
  33594. ret = ed448ph_test();
  33595. if (ret != 0)
  33596. goto out;
  33597. #ifndef NO_ASN
  33598. /* Try ASN.1 encoded private-only key and public key. */
  33599. idx = 0;
  33600. ret = wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3,
  33601. sizeof(privateEd448));
  33602. if (ret != 0)
  33603. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33604. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33605. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  33606. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33607. idx = 0;
  33608. ret = wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, sizeof(publicEd448));
  33609. if (ret != 0)
  33610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33611. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33612. if (ret != 0)
  33613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33614. if (XMEMCMP(out, sigs[0], SIGSZ))
  33615. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33616. #if defined(HAVE_ED448_VERIFY)
  33617. /* test verify on good msg */
  33618. ret = wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3,
  33619. NULL, 0);
  33620. if (ret != 0 || verify != 1)
  33621. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33622. #endif /* HAVE_ED448_VERIFY */
  33623. wc_ed448_free(key3);
  33624. ret = wc_ed448_init(key3);
  33625. if (ret < 0)
  33626. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33627. idx = 0;
  33628. ret = wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3,
  33629. sizeof(privPubEd448));
  33630. if (ret != 0)
  33631. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33632. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33633. if (ret != 0)
  33634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33635. if (XMEMCMP(out, sigs[0], SIGSZ))
  33636. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33637. #endif /* NO_ASN */
  33638. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33639. ret = 0;
  33640. out:
  33641. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33642. if (key) {
  33643. wc_ed448_free(key);
  33644. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33645. }
  33646. if (key2) {
  33647. wc_ed448_free(key2);
  33648. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33649. }
  33650. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33651. if (key3) {
  33652. wc_ed448_free(key3);
  33653. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33654. }
  33655. #endif
  33656. #else
  33657. wc_ed448_free(key);
  33658. wc_ed448_free(key2);
  33659. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33660. wc_ed448_free(key3);
  33661. #endif
  33662. #endif
  33663. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  33664. wc_FreeRng(&rng);
  33665. #endif
  33666. if (ret < 0)
  33667. return ret;
  33668. /* hush warnings of unused keySz and sigSz */
  33669. (void)keySz;
  33670. (void)sigSz;
  33671. ret = ed448_test_check_key();
  33672. if (ret < 0)
  33673. return ret;
  33674. #ifdef WOLFSSL_TEST_CERT
  33675. ret = ed448_test_cert();
  33676. if (ret < 0)
  33677. return ret;
  33678. #ifdef WOLFSSL_CERT_GEN
  33679. ret = ed448_test_make_cert();
  33680. if (ret < 0)
  33681. return ret;
  33682. #endif /* WOLFSSL_CERT_GEN */
  33683. #endif /* WOLFSSL_TEST_CERT */
  33684. return 0;
  33685. }
  33686. #endif /* HAVE_ED448 */
  33687. #ifdef WOLFSSL_HAVE_KYBER
  33688. #ifdef WOLFSSL_WC_KYBER /* OQS does not support KATs */
  33689. #ifdef WOLFSSL_KYBER512
  33690. static wc_test_ret_t kyber512_kat(void)
  33691. {
  33692. wc_test_ret_t ret;
  33693. #ifdef WOLFSSL_SMALL_STACK
  33694. KyberKey *key = NULL;
  33695. byte *priv = NULL;
  33696. byte *pub = NULL;
  33697. byte *ct = NULL;
  33698. byte *ss = NULL;
  33699. byte *ss_dec = NULL;
  33700. #else
  33701. KyberKey key[1];
  33702. byte priv[KYBER512_PRIVATE_KEY_SIZE];
  33703. byte pub[KYBER512_PUBLIC_KEY_SIZE];
  33704. byte ct[KYBER512_CIPHER_TEXT_SIZE];
  33705. byte ss[KYBER_SS_SZ];
  33706. byte ss_dec[KYBER_SS_SZ];
  33707. #endif
  33708. int key_inited = 0;
  33709. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_rand[] = {
  33710. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  33711. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  33712. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  33713. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  33714. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  33715. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  33716. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  33717. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  33718. };
  33719. WOLFSSL_SMALL_STACK_STATIC const byte kyber512enc_rand[] = {
  33720. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  33721. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  33722. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  33723. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  33724. };
  33725. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_pk[] = {
  33726. #ifdef WOLFSSL_KYBER_ORIGINAL
  33727. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  33728. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  33729. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  33730. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  33731. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  33732. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  33733. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  33734. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  33735. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  33736. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  33737. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  33738. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  33739. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  33740. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  33741. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  33742. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  33743. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  33744. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  33745. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  33746. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  33747. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  33748. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  33749. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  33750. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  33751. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  33752. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  33753. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  33754. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  33755. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  33756. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  33757. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  33758. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  33759. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  33760. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  33761. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  33762. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  33763. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  33764. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  33765. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  33766. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  33767. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  33768. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  33769. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  33770. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  33771. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  33772. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  33773. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  33774. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  33775. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  33776. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  33777. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  33778. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  33779. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  33780. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  33781. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  33782. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  33783. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  33784. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  33785. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  33786. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  33787. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  33788. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  33789. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  33790. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  33791. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  33792. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  33793. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  33794. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  33795. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  33796. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  33797. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  33798. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  33799. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  33800. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  33801. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  33802. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  33803. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  33804. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  33805. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  33806. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  33807. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  33808. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  33809. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  33810. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  33811. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  33812. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  33813. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  33814. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  33815. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  33816. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  33817. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  33818. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  33819. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  33820. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  33821. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  33822. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  33823. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  33824. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  33825. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  33826. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  33827. #else
  33828. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  33829. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  33830. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  33831. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  33832. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  33833. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  33834. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  33835. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  33836. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  33837. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  33838. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  33839. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  33840. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  33841. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  33842. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  33843. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  33844. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  33845. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  33846. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  33847. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  33848. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  33849. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  33850. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  33851. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  33852. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  33853. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  33854. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  33855. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  33856. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  33857. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  33858. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  33859. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  33860. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  33861. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  33862. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  33863. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  33864. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  33865. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  33866. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  33867. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  33868. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  33869. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  33870. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  33871. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  33872. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  33873. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  33874. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  33875. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  33876. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  33877. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  33878. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  33879. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  33880. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  33881. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  33882. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  33883. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  33884. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  33885. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  33886. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  33887. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  33888. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  33889. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  33890. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  33891. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  33892. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  33893. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  33894. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  33895. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  33896. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  33897. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  33898. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  33899. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  33900. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  33901. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  33902. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  33903. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  33904. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  33905. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  33906. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  33907. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  33908. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  33909. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  33910. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  33911. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  33912. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  33913. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  33914. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  33915. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  33916. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  33917. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  33918. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  33919. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  33920. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  33921. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  33922. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  33923. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  33924. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  33925. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  33926. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  33927. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39
  33928. #endif
  33929. };
  33930. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_sk[] = {
  33931. #ifdef WOLFSSL_KYBER_ORIGINAL
  33932. 0x6C, 0x89, 0x2B, 0x02, 0x97, 0xA9, 0xC7, 0x64,
  33933. 0x14, 0x93, 0xF8, 0x7D, 0xAF, 0x35, 0x33, 0xEE,
  33934. 0xD6, 0x1F, 0x07, 0xF4, 0x65, 0x20, 0x66, 0x33,
  33935. 0x7E, 0xD7, 0x40, 0x46, 0xDC, 0xC7, 0x1B, 0xA0,
  33936. 0x3F, 0x30, 0x96, 0x01, 0x03, 0x16, 0x1F, 0x7D,
  33937. 0xEB, 0x53, 0xA7, 0x1B, 0x11, 0x61, 0x72, 0x63,
  33938. 0xFE, 0x2A, 0x80, 0x97, 0x69, 0xCE, 0x6D, 0x70,
  33939. 0xA8, 0x5F, 0xE6, 0x00, 0xEC, 0xE2, 0x9D, 0x7F,
  33940. 0x36, 0xA1, 0x6D, 0x33, 0x1B, 0x8B, 0x2A, 0x9E,
  33941. 0x1D, 0xB8, 0xC0, 0x90, 0x74, 0x2D, 0xF0, 0x73,
  33942. 0x9F, 0xF0, 0x60, 0xCE, 0xB4, 0xEC, 0xC5, 0xAB,
  33943. 0x1C, 0x5E, 0x55, 0xAC, 0x97, 0xBB, 0x66, 0xA7,
  33944. 0xF8, 0x95, 0x10, 0x5D, 0x57, 0x78, 0x2B, 0x22,
  33945. 0x95, 0x38, 0xE3, 0x42, 0x15, 0x44, 0xA3, 0x42,
  33946. 0x14, 0x08, 0xDB, 0xF4, 0x49, 0x10, 0x93, 0x4C,
  33947. 0xC4, 0x23, 0x77, 0x4F, 0x16, 0x76, 0xFF, 0x1C,
  33948. 0x30, 0x6F, 0x97, 0x55, 0x5F, 0x57, 0xB4, 0xAE,
  33949. 0xD7, 0xA6, 0xBA, 0xB9, 0x50, 0xA8, 0x16, 0x3C,
  33950. 0x8D, 0x31, 0x8D, 0xEA, 0x62, 0x75, 0x1B, 0xD6,
  33951. 0xAB, 0xC5, 0x06, 0x9C, 0x06, 0xC8, 0x8F, 0x33,
  33952. 0x00, 0x26, 0xA1, 0x98, 0x06, 0xA0, 0x3B, 0x97,
  33953. 0xA7, 0x69, 0x6B, 0x56, 0xDA, 0x21, 0x82, 0x7B,
  33954. 0xB4, 0xE8, 0xDC, 0x03, 0x11, 0x52, 0xB4, 0x1B,
  33955. 0x89, 0x2A, 0x9E, 0x99, 0xAD, 0xF6, 0xE1, 0x96,
  33956. 0x3E, 0x96, 0x57, 0x88, 0x28, 0x15, 0x4F, 0x46,
  33957. 0x70, 0x33, 0x84, 0x69, 0x20, 0xFB, 0xB4, 0xB8,
  33958. 0x05, 0x44, 0xE7, 0xE8, 0xA8, 0x1A, 0xE9, 0x63,
  33959. 0xCF, 0x36, 0x8C, 0x9B, 0xA0, 0x37, 0xA8, 0xC2,
  33960. 0xAD, 0x62, 0xE3, 0x2B, 0x6E, 0x61, 0xC9, 0x1D,
  33961. 0x75, 0xCE, 0x00, 0x5A, 0xB3, 0x0F, 0x80, 0x99,
  33962. 0xA1, 0xF2, 0x9D, 0x7B, 0x63, 0x05, 0xB4, 0xDC,
  33963. 0x06, 0xE2, 0x56, 0x80, 0xBB, 0x00, 0x99, 0x2F,
  33964. 0x71, 0x7F, 0xE6, 0xC1, 0x15, 0xA8, 0x08, 0x42,
  33965. 0x31, 0xCC, 0x79, 0xDD, 0x70, 0x0E, 0xA6, 0x91,
  33966. 0x2A, 0xC7, 0xFA, 0x0D, 0x93, 0x7B, 0xB6, 0xA7,
  33967. 0x56, 0x66, 0x22, 0x30, 0x47, 0x0C, 0x18, 0x9B,
  33968. 0x5A, 0xA1, 0x65, 0x3D, 0xEB, 0x93, 0x7D, 0x5A,
  33969. 0x9C, 0x25, 0xA2, 0x1D, 0x93, 0xB1, 0x90, 0x74,
  33970. 0xFC, 0x23, 0x9D, 0x81, 0x53, 0x53, 0x97, 0x97,
  33971. 0xC7, 0xD4, 0xAB, 0x62, 0x64, 0x9D, 0x76, 0xAA,
  33972. 0x55, 0x37, 0x36, 0xA9, 0x49, 0x02, 0x2C, 0x22,
  33973. 0xC5, 0x2B, 0xAE, 0xEC, 0x60, 0x5B, 0x32, 0xCE,
  33974. 0x9E, 0x5B, 0x93, 0x84, 0x90, 0x35, 0x58, 0xCA,
  33975. 0x9D, 0x6A, 0x3A, 0xBA, 0x90, 0x42, 0x3E, 0xED,
  33976. 0xA0, 0x1C, 0x94, 0x19, 0x8B, 0x19, 0x2A, 0x8B,
  33977. 0xA9, 0x06, 0x34, 0x97, 0xA0, 0xC5, 0x01, 0x33,
  33978. 0x07, 0xDD, 0xD8, 0x63, 0x52, 0x64, 0x71, 0xA4,
  33979. 0xD9, 0x95, 0x23, 0xEB, 0x41, 0x7F, 0x29, 0x1A,
  33980. 0xAC, 0x0C, 0x3A, 0x58, 0x1B, 0x6D, 0xA0, 0x07,
  33981. 0x32, 0xE5, 0xE8, 0x1B, 0x1F, 0x7C, 0x87, 0x9B,
  33982. 0x16, 0x93, 0xC1, 0x3B, 0x6F, 0x9F, 0x79, 0x31,
  33983. 0x62, 0x24, 0x29, 0xE5, 0x42, 0xAF, 0x40, 0x69,
  33984. 0x22, 0x2F, 0x04, 0x55, 0x44, 0xE0, 0xCC, 0x4F,
  33985. 0xB2, 0x4D, 0x44, 0x48, 0xCF, 0x2C, 0x65, 0x96,
  33986. 0xF5, 0xCB, 0x08, 0x62, 0x4B, 0x11, 0x85, 0x01,
  33987. 0x3B, 0x6B, 0x02, 0x08, 0x92, 0xF9, 0x6B, 0xDF,
  33988. 0xD4, 0xAD, 0xA9, 0x17, 0x9D, 0xE7, 0x27, 0xB8,
  33989. 0xD9, 0x42, 0x6E, 0x09, 0x96, 0xB5, 0xD3, 0x49,
  33990. 0x48, 0xCE, 0x02, 0xD0, 0xC3, 0x69, 0xB3, 0x7C,
  33991. 0xBB, 0x54, 0xD3, 0x47, 0x9E, 0xD8, 0xB5, 0x82,
  33992. 0xE9, 0xE7, 0x28, 0x92, 0x9B, 0x4C, 0x71, 0xC9,
  33993. 0xBE, 0x11, 0xD4, 0x5B, 0x20, 0xC4, 0xBD, 0xC3,
  33994. 0xC7, 0x43, 0x13, 0x22, 0x3F, 0x58, 0x27, 0x4E,
  33995. 0x8B, 0xA5, 0x24, 0x44, 0x47, 0xC4, 0x95, 0x95,
  33996. 0x0B, 0x84, 0xCB, 0x0C, 0x3C, 0x27, 0x36, 0x40,
  33997. 0x10, 0x8A, 0x33, 0x97, 0x94, 0x45, 0x73, 0x27,
  33998. 0x93, 0x28, 0x99, 0x6C, 0xDC, 0x0C, 0x91, 0x3C,
  33999. 0x95, 0x8A, 0xD6, 0x20, 0xBA, 0x8B, 0x5E, 0x5E,
  34000. 0xCB, 0xBB, 0x7E, 0x13, 0xCB, 0x9C, 0x70, 0xBD,
  34001. 0x5A, 0xB3, 0x0E, 0xB7, 0x48, 0x8C, 0x97, 0x00,
  34002. 0x1C, 0x20, 0x49, 0x8F, 0x1D, 0x7C, 0xC0, 0x6D,
  34003. 0xA7, 0x6B, 0xF5, 0x20, 0xC6, 0x58, 0xCC, 0xAD,
  34004. 0xFA, 0x29, 0x56, 0x42, 0x45, 0x57, 0xAB, 0xEA,
  34005. 0x8A, 0xB8, 0x92, 0x39, 0xC1, 0x78, 0x33, 0xDC,
  34006. 0x3A, 0x49, 0xB3, 0x6A, 0x9A, 0xE9, 0xA4, 0x86,
  34007. 0x94, 0x05, 0x40, 0xEB, 0x44, 0x4F, 0x97, 0x15,
  34008. 0x23, 0x57, 0xE0, 0x20, 0x35, 0x93, 0x9D, 0x75,
  34009. 0xA3, 0xC0, 0x25, 0xF4, 0x1A, 0x40, 0x08, 0x23,
  34010. 0x82, 0xA0, 0x73, 0x3C, 0x39, 0xB0, 0x62, 0x2B,
  34011. 0x74, 0x0E, 0x40, 0x75, 0x92, 0xC6, 0x2E, 0xCA,
  34012. 0xEB, 0x14, 0x32, 0xC4, 0x45, 0xB3, 0x70, 0x3A,
  34013. 0x86, 0xF6, 0x98, 0x1A, 0x27, 0x81, 0x57, 0xEA,
  34014. 0x95, 0xA6, 0xE9, 0x2D, 0x55, 0xE4, 0xB9, 0x72,
  34015. 0xF9, 0x36, 0xC2, 0xF0, 0xA6, 0x58, 0x28, 0x0E,
  34016. 0xA2, 0xB0, 0x7A, 0x48, 0x99, 0x2D, 0xF8, 0x93,
  34017. 0x7E, 0x0A, 0x2A, 0xC1, 0xDC, 0xC9, 0x74, 0xFE,
  34018. 0x00, 0xAA, 0xE1, 0xF5, 0x61, 0xFA, 0x25, 0x8E,
  34019. 0x2D, 0x25, 0x9C, 0x3E, 0x86, 0x1D, 0xCE, 0x23,
  34020. 0x60, 0x39, 0x12, 0x76, 0x06, 0xFC, 0x1C, 0xE0,
  34021. 0x09, 0x00, 0x3A, 0x7B, 0xAC, 0x94, 0x21, 0x01,
  34022. 0xDC, 0xB8, 0x22, 0xB1, 0xF3, 0xC1, 0x2B, 0xF7,
  34023. 0x32, 0x38, 0xF5, 0x46, 0xE0, 0x1C, 0x36, 0xB5,
  34024. 0xA6, 0x93, 0x61, 0x92, 0x99, 0x5C, 0xC6, 0x9C,
  34025. 0x63, 0x23, 0x74, 0x09, 0xCB, 0x53, 0xC2, 0xE3,
  34026. 0x5D, 0x74, 0x89, 0x0D, 0x18, 0x88, 0x53, 0x76,
  34027. 0xFA, 0x55, 0x03, 0xB1, 0x07, 0xA2, 0xA3, 0x92,
  34028. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34029. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34030. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34031. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34032. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34033. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34034. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34035. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34036. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34037. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34038. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34039. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34040. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34041. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34042. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34043. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34044. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34045. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34046. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34047. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34048. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34049. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34050. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34051. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34052. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34053. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34054. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34055. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34056. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34057. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34058. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34059. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34060. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34061. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34062. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34063. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34064. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34065. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34066. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34067. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34068. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34069. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34070. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34071. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34072. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34073. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34074. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34075. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34076. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34077. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34078. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34079. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34080. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34081. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34082. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34083. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34084. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34085. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34086. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34087. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34088. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34089. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34090. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34091. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34092. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34093. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34094. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34095. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34096. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34097. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34098. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34099. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34100. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34101. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34102. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34103. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34104. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34105. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34106. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34107. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34108. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34109. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34110. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34111. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34112. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34113. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34114. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34115. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34116. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34117. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34118. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34119. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34120. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34121. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34122. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34123. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34124. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34125. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34126. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34127. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  34128. 0x7F, 0xFA, 0xD1, 0xBC, 0x8A, 0xF7, 0x3B, 0x7E,
  34129. 0x87, 0x49, 0x56, 0xB8, 0x1C, 0x2A, 0x2E, 0xF0,
  34130. 0xBF, 0xAB, 0xE8, 0xDC, 0x93, 0xD7, 0x7B, 0x2F,
  34131. 0xBC, 0x9E, 0x0C, 0x64, 0xEF, 0xA0, 0x1E, 0x84,
  34132. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34133. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34134. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34135. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34136. #else
  34137. 0x9c, 0xda, 0x16, 0x86, 0xa3, 0x39, 0x6a, 0x7c,
  34138. 0x10, 0x9b, 0x41, 0x52, 0x89, 0xf5, 0x6a, 0x9e,
  34139. 0xc4, 0x4c, 0xd5, 0xb9, 0xb6, 0x74, 0xc3, 0x8a,
  34140. 0x3b, 0xba, 0xb3, 0x0a, 0x2c, 0x90, 0xf0, 0x04,
  34141. 0x37, 0xa2, 0x64, 0xb0, 0xbe, 0x9a, 0x1e, 0x8b,
  34142. 0xa8, 0x87, 0xd3, 0xc3, 0xb1, 0x00, 0x89, 0x80,
  34143. 0x54, 0x27, 0x2f, 0x94, 0x1c, 0x88, 0xa1, 0xf2,
  34144. 0x08, 0xf1, 0xc9, 0x14, 0xf9, 0x64, 0xc1, 0xaa,
  34145. 0xd6, 0x13, 0xa6, 0xa8, 0x4f, 0x88, 0xe4, 0x2d,
  34146. 0x35, 0x56, 0x83, 0x5f, 0xb1, 0x61, 0xfd, 0xc5,
  34147. 0xcd, 0x15, 0xa3, 0xbc, 0x7e, 0x74, 0xb6, 0xf2,
  34148. 0x61, 0x2f, 0xa8, 0x27, 0x1c, 0x7e, 0xa1, 0x12,
  34149. 0xb0, 0x5c, 0x2a, 0x36, 0xcc, 0x70, 0x7c, 0xe3,
  34150. 0x8d, 0x5d, 0x1a, 0xcc, 0x51, 0x15, 0x46, 0x2a,
  34151. 0x8c, 0x1a, 0xab, 0xf0, 0x72, 0x76, 0xc7, 0x23,
  34152. 0x18, 0x33, 0x7f, 0x74, 0xb5, 0xcb, 0xef, 0xea,
  34153. 0x7a, 0x80, 0x37, 0x90, 0xbc, 0x03, 0x93, 0xf3,
  34154. 0xa5, 0x4c, 0x72, 0x4a, 0x57, 0x65, 0xa4, 0x8f,
  34155. 0x29, 0x6b, 0x03, 0xf4, 0x84, 0x37, 0x60, 0x23,
  34156. 0x62, 0x69, 0x30, 0x22, 0x27, 0x04, 0xc0, 0x8f,
  34157. 0xd3, 0xbc, 0x72, 0x93, 0x15, 0xd1, 0xfc, 0x70,
  34158. 0xeb, 0x79, 0x75, 0xa9, 0x7b, 0x9d, 0xee, 0xd1,
  34159. 0x62, 0xf4, 0x86, 0xbb, 0xc6, 0x4a, 0x09, 0x71,
  34160. 0x11, 0x95, 0x2d, 0x89, 0xb5, 0x7d, 0x76, 0x5e,
  34161. 0x8a, 0x99, 0x1a, 0x2e, 0x56, 0x42, 0x06, 0xea,
  34162. 0x7b, 0xf5, 0xe4, 0x00, 0x7a, 0x66, 0x35, 0x88,
  34163. 0x31, 0xca, 0x0e, 0x34, 0xb2, 0xf6, 0xa8, 0x4d,
  34164. 0x10, 0xf7, 0x9c, 0x47, 0x7c, 0xb6, 0x6a, 0x8a,
  34165. 0x95, 0x25, 0x69, 0x36, 0x73, 0x88, 0x13, 0x0d,
  34166. 0x7b, 0x97, 0x4a, 0x63, 0xaa, 0x51, 0x99, 0x6c,
  34167. 0x97, 0x70, 0x9b, 0xb8, 0xea, 0xbc, 0x94, 0xe6,
  34168. 0xa5, 0x35, 0xd7, 0x92, 0xd2, 0x90, 0x54, 0x74,
  34169. 0x95, 0x2d, 0x6b, 0x8c, 0x22, 0x22, 0xb2, 0xae,
  34170. 0x56, 0xdc, 0x66, 0xfb, 0x04, 0x61, 0x19, 0x20,
  34171. 0x66, 0xcd, 0xdb, 0x43, 0xec, 0x05, 0x98, 0x4f,
  34172. 0xb4, 0x98, 0x26, 0x49, 0x77, 0x13, 0x97, 0xc6,
  34173. 0xa8, 0x37, 0x9f, 0x3b, 0x56, 0x43, 0x06, 0x98,
  34174. 0x48, 0x87, 0x59, 0x19, 0xe8, 0x9c, 0xc4, 0x39,
  34175. 0xa3, 0xbe, 0x2f, 0x08, 0x14, 0x90, 0xf3, 0x41,
  34176. 0xbd, 0x12, 0x40, 0xad, 0xd8, 0x0d, 0xdb, 0x8c,
  34177. 0x99, 0x63, 0xb4, 0x7a, 0x2a, 0x09, 0x92, 0x29,
  34178. 0x03, 0x38, 0xda, 0x9c, 0x3b, 0x72, 0x5c, 0x6d,
  34179. 0xa4, 0x47, 0x18, 0xc0, 0x10, 0x46, 0x81, 0x25,
  34180. 0x62, 0xaf, 0xb0, 0x84, 0x83, 0x7a, 0xcb, 0x3c,
  34181. 0x57, 0x5e, 0x4f, 0x93, 0x93, 0x6c, 0x35, 0x2a,
  34182. 0xc0, 0xe7, 0x0a, 0xa3, 0x84, 0x5e, 0xe4, 0x85,
  34183. 0x29, 0x6e, 0x6b, 0x02, 0xde, 0x0b, 0x47, 0xb5,
  34184. 0xc4, 0xc9, 0x6b, 0x0b, 0x7c, 0xf9, 0x4c, 0x4a,
  34185. 0xbe, 0x95, 0x48, 0x61, 0x53, 0x11, 0x8e, 0x43,
  34186. 0xc2, 0xb9, 0xc8, 0x4d, 0x9d, 0xa9, 0x1c, 0x6c,
  34187. 0x5a, 0xcd, 0x5a, 0x57, 0x00, 0x2d, 0x05, 0x84,
  34188. 0x97, 0x99, 0x27, 0x99, 0xe5, 0xba, 0x1c, 0xe6,
  34189. 0xc2, 0x5e, 0xb2, 0x98, 0x44, 0xd8, 0x58, 0xba,
  34190. 0x1c, 0x37, 0x85, 0x0c, 0x0c, 0x2f, 0x57, 0xc6,
  34191. 0x0d, 0xe3, 0x7f, 0x77, 0xc0, 0x82, 0xec, 0x14,
  34192. 0x49, 0x4e, 0xba, 0x28, 0x8a, 0x65, 0x91, 0x51,
  34193. 0x16, 0xc2, 0x0a, 0x32, 0x5d, 0xe3, 0x1a, 0xaa,
  34194. 0xdd, 0x68, 0x0d, 0xb1, 0x9c, 0x0c, 0xfc, 0xc3,
  34195. 0x46, 0x0f, 0x0a, 0xa0, 0x1a, 0x87, 0xa6, 0xa5,
  34196. 0x80, 0xc6, 0xca, 0x29, 0x1f, 0xae, 0xf0, 0xcc,
  34197. 0xc4, 0x9b, 0x76, 0xa8, 0xda, 0xc4, 0xf9, 0xd4,
  34198. 0x16, 0x40, 0x50, 0x9d, 0xbd, 0x0b, 0x40, 0x45,
  34199. 0xc1, 0x53, 0x0e, 0xd3, 0x47, 0x55, 0xd4, 0x74,
  34200. 0x62, 0x70, 0x0f, 0x2a, 0x8c, 0xaf, 0x96, 0x80,
  34201. 0xa6, 0xd7, 0xe3, 0x8a, 0x7e, 0x2a, 0x63, 0xe9,
  34202. 0x37, 0x65, 0x0a, 0x23, 0x30, 0x6d, 0x85, 0x5d,
  34203. 0xa2, 0xa2, 0xb7, 0xef, 0x50, 0x5c, 0xa5, 0x96,
  34204. 0xab, 0x04, 0x85, 0x01, 0x3e, 0xa9, 0x27, 0xc7,
  34205. 0x34, 0x23, 0x43, 0x61, 0x36, 0x43, 0xba, 0x40,
  34206. 0x07, 0xd6, 0xc8, 0x74, 0xb9, 0x80, 0xc7, 0x9c,
  34207. 0x3a, 0xa1, 0xc7, 0x4f, 0x85, 0x81, 0xc3, 0x48,
  34208. 0x49, 0xb3, 0x6e, 0xa7, 0x98, 0x15, 0xfb, 0xb4,
  34209. 0xcc, 0xf9, 0x61, 0x05, 0x83, 0x08, 0x1d, 0x7c,
  34210. 0x5b, 0x44, 0x09, 0xb8, 0xd0, 0x53, 0x1c, 0x04,
  34211. 0xbc, 0xaf, 0x7c, 0xc7, 0x51, 0x10, 0x3a, 0x5f,
  34212. 0xd1, 0xba, 0x44, 0x70, 0x83, 0x3e, 0x89, 0x77,
  34213. 0x5a, 0xde, 0xd9, 0x70, 0xb5, 0x47, 0x18, 0x59,
  34214. 0x25, 0x0f, 0xe7, 0x26, 0x71, 0x05, 0x83, 0x5f,
  34215. 0x39, 0x00, 0x30, 0xc5, 0xe7, 0xcd, 0x3f, 0x96,
  34216. 0x10, 0x19, 0xea, 0xae, 0xa2, 0x37, 0x77, 0xd3,
  34217. 0x47, 0xbb, 0x2a, 0xdc, 0xb6, 0x73, 0xc0, 0x20,
  34218. 0x34, 0xf3, 0x94, 0x34, 0x22, 0x71, 0xbc, 0xea,
  34219. 0x64, 0x14, 0xe5, 0x46, 0xc3, 0xb2, 0x0b, 0xd5,
  34220. 0x74, 0x81, 0xc7, 0xea, 0x14, 0xc7, 0x7c, 0x38,
  34221. 0x8c, 0xc8, 0x62, 0x51, 0xc1, 0x25, 0x58, 0xb1,
  34222. 0x00, 0xf8, 0xc5, 0xb3, 0xd0, 0x3c, 0xa2, 0xc7,
  34223. 0x07, 0x13, 0x90, 0x96, 0x59, 0xc8, 0xba, 0x26,
  34224. 0xd0, 0xd1, 0x76, 0x5e, 0x0b, 0xc8, 0x23, 0xd6,
  34225. 0x8c, 0xa5, 0x57, 0x0d, 0xe6, 0x00, 0xcd, 0x09,
  34226. 0x41, 0x72, 0x5d, 0x38, 0x6e, 0x14, 0xc1, 0x01,
  34227. 0x2d, 0xf5, 0x95, 0x1b, 0xeb, 0x8d, 0x82, 0x81,
  34228. 0xa4, 0xf6, 0x81, 0x5d, 0x37, 0x60, 0xb7, 0x64,
  34229. 0x29, 0x5a, 0xd0, 0x40, 0x6c, 0x2b, 0xf7, 0x92,
  34230. 0x8a, 0xd6, 0x50, 0x32, 0xb6, 0x5f, 0x14, 0xb7,
  34231. 0x7c, 0xcb, 0x89, 0x17, 0xc9, 0x3a, 0x29, 0xd6,
  34232. 0x28, 0x7d, 0x8a, 0x60, 0x62, 0x39, 0x9c, 0xb6,
  34233. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34234. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34235. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34236. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34237. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34238. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34239. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34240. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34241. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34242. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34243. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34244. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34245. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34246. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34247. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34248. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34249. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34250. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34251. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34252. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34253. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34254. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34255. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34256. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34257. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34258. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34259. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34260. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34261. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34262. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34263. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34264. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34265. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34266. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34267. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34268. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34269. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34270. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34271. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34272. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34273. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34274. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34275. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34276. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34277. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34278. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34279. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34280. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34281. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34282. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34283. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34284. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34285. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34286. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34287. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34288. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34289. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34290. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34291. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34292. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34293. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34294. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34295. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34296. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34297. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34298. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34299. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34300. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34301. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34302. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34303. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34304. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34305. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34306. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34307. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34308. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34309. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34310. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34311. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34312. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34313. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34314. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34315. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34316. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34317. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34318. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34319. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34320. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34321. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34322. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34323. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34324. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34325. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34326. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34327. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34328. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34329. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34330. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34331. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34332. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39,
  34333. 0x50, 0xc8, 0xdd, 0x15, 0x2a, 0x45, 0x31, 0xaa,
  34334. 0xb5, 0x60, 0xd2, 0xfc, 0x7c, 0xa9, 0xa4, 0x0a,
  34335. 0xd8, 0xaf, 0x25, 0xad, 0x1d, 0xd0, 0x8c, 0x6d,
  34336. 0x79, 0xaf, 0xe4, 0xdd, 0x4d, 0x1e, 0xee, 0x5a,
  34337. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  34338. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  34339. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  34340. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  34341. #endif
  34342. };
  34343. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ct[] = {
  34344. #ifdef WOLFSSL_KYBER_ORIGINAL
  34345. 0xED, 0xF2, 0x41, 0x45, 0xE4, 0x3B, 0x4F, 0x6D,
  34346. 0xC6, 0xBF, 0x83, 0x32, 0xF5, 0x4E, 0x02, 0xCA,
  34347. 0xB0, 0x2D, 0xBF, 0x3B, 0x56, 0x05, 0xDD, 0xC9,
  34348. 0x0A, 0x15, 0xC8, 0x86, 0xAD, 0x3E, 0xD4, 0x89,
  34349. 0x46, 0x26, 0x99, 0xE4, 0xAB, 0xED, 0x44, 0x35,
  34350. 0x0B, 0xC3, 0x75, 0x7E, 0x26, 0x96, 0xFB, 0xFB,
  34351. 0x25, 0x34, 0x41, 0x2E, 0x8D, 0xD2, 0x01, 0xF1,
  34352. 0xE4, 0x54, 0x0A, 0x39, 0x70, 0xB0, 0x55, 0xFE,
  34353. 0x3B, 0x0B, 0xEC, 0x3A, 0x71, 0xF9, 0xE1, 0x15,
  34354. 0xB3, 0xF9, 0xF3, 0x91, 0x02, 0x06, 0x5B, 0x1C,
  34355. 0xCA, 0x83, 0x14, 0xDC, 0xC7, 0x95, 0xE3, 0xC0,
  34356. 0xE8, 0xFA, 0x98, 0xEE, 0x83, 0xCA, 0x66, 0x28,
  34357. 0x45, 0x70, 0x28, 0xA4, 0xD0, 0x9E, 0x83, 0x9E,
  34358. 0x55, 0x48, 0x62, 0xCF, 0x0B, 0x7B, 0xF5, 0x6C,
  34359. 0x5C, 0x0A, 0x82, 0x9E, 0x86, 0x57, 0x94, 0x79,
  34360. 0x45, 0xFE, 0x9C, 0x22, 0x56, 0x4F, 0xBA, 0xEB,
  34361. 0xC1, 0xB3, 0xAF, 0x35, 0x0D, 0x79, 0x55, 0x50,
  34362. 0x8A, 0x26, 0xD8, 0xA8, 0xEB, 0x54, 0x7B, 0x8B,
  34363. 0x1A, 0x2C, 0xF0, 0x3C, 0xCA, 0x1A, 0xAB, 0xCE,
  34364. 0x6C, 0x34, 0x97, 0x78, 0x3B, 0x64, 0x65, 0xBA,
  34365. 0x0B, 0x6E, 0x7A, 0xCB, 0xA8, 0x21, 0x19, 0x51,
  34366. 0x24, 0xAE, 0xF0, 0x9E, 0x62, 0x83, 0x82, 0xA1,
  34367. 0xF9, 0x14, 0x04, 0x3B, 0xE7, 0x09, 0x6E, 0x95,
  34368. 0x2C, 0xBC, 0x4F, 0xB4, 0xAF, 0xED, 0x13, 0x60,
  34369. 0x90, 0x46, 0x11, 0x7C, 0x01, 0x1F, 0xD7, 0x41,
  34370. 0xEE, 0x28, 0x6C, 0x83, 0x77, 0x16, 0x90, 0xF0,
  34371. 0xAE, 0xB5, 0x0D, 0xA0, 0xD7, 0x12, 0x85, 0xA1,
  34372. 0x79, 0xB2, 0x15, 0xC6, 0x03, 0x6D, 0xEB, 0x78,
  34373. 0x0F, 0x4D, 0x16, 0x76, 0x9F, 0x72, 0xDE, 0x16,
  34374. 0xFD, 0xAD, 0xAC, 0x73, 0xBE, 0xFA, 0x5B, 0xEF,
  34375. 0x89, 0x43, 0x19, 0x7F, 0x44, 0xC5, 0x95, 0x89,
  34376. 0xDC, 0x9F, 0x49, 0x73, 0xDE, 0x14, 0x50, 0xBA,
  34377. 0x1D, 0x0C, 0x32, 0x90, 0xD6, 0xB1, 0xD6, 0x83,
  34378. 0xF2, 0x94, 0xE7, 0x59, 0xC9, 0x54, 0xAB, 0xE8,
  34379. 0xA7, 0xDA, 0x5B, 0x10, 0x54, 0xFD, 0x6D, 0x21,
  34380. 0x32, 0x9B, 0x8E, 0x73, 0xD3, 0x75, 0x6A, 0xFD,
  34381. 0xA0, 0xDC, 0xB1, 0xFC, 0x8B, 0x15, 0x82, 0xD1,
  34382. 0xF9, 0x0C, 0xF2, 0x75, 0xA1, 0x02, 0xAB, 0xC6,
  34383. 0xAC, 0x69, 0x9D, 0xF0, 0xC5, 0x87, 0x0E, 0x50,
  34384. 0xA1, 0xF9, 0x89, 0xE4, 0xE6, 0x24, 0x1B, 0x60,
  34385. 0xAA, 0xA2, 0xEC, 0xF9, 0xE8, 0xE3, 0x3E, 0x0F,
  34386. 0xFC, 0xF4, 0x0F, 0xE8, 0x31, 0xE8, 0xFD, 0xC2,
  34387. 0xE8, 0x3B, 0x52, 0xCA, 0x7A, 0xB6, 0xD9, 0x3F,
  34388. 0x14, 0x6D, 0x29, 0xDC, 0xA5, 0x3C, 0x7D, 0xA1,
  34389. 0xDB, 0x4A, 0xC4, 0xF2, 0xDB, 0x39, 0xEA, 0x12,
  34390. 0x0D, 0x90, 0xFA, 0x60, 0xF4, 0xD4, 0x37, 0xC6,
  34391. 0xD0, 0x0E, 0xF4, 0x83, 0xBC, 0x94, 0xA3, 0x17,
  34392. 0x5C, 0xDA, 0x16, 0x3F, 0xC1, 0xC2, 0x82, 0x8B,
  34393. 0xE4, 0xDB, 0xD6, 0x43, 0x05, 0x07, 0xB5, 0x84,
  34394. 0xBB, 0x51, 0x77, 0xE1, 0x71, 0xB8, 0xDD, 0xA9,
  34395. 0xA4, 0x29, 0x3C, 0x32, 0x00, 0x29, 0x5C, 0x80,
  34396. 0x3A, 0x86, 0x5D, 0x6D, 0x21, 0x66, 0xF6, 0x6B,
  34397. 0xA5, 0x40, 0x1F, 0xB7, 0xA0, 0xE8, 0x53, 0x16,
  34398. 0x86, 0x00, 0xA2, 0x94, 0x84, 0x37, 0xE0, 0x36,
  34399. 0xE3, 0xBF, 0x19, 0xE1, 0x2F, 0xD3, 0xF2, 0xA2,
  34400. 0xB8, 0xB3, 0x43, 0xF7, 0x84, 0x24, 0x8E, 0x8D,
  34401. 0x68, 0x5E, 0xB0, 0xAF, 0xDE, 0x63, 0x15, 0x33,
  34402. 0x87, 0x30, 0xE7, 0xA1, 0x00, 0x1C, 0x27, 0xD8,
  34403. 0xD2, 0xA7, 0x6F, 0xA6, 0x9D, 0x15, 0x7B, 0xA1,
  34404. 0xAC, 0x7A, 0xD5, 0x6D, 0xA5, 0xA8, 0xC7, 0x0F,
  34405. 0xE4, 0xB5, 0xB8, 0xD7, 0x86, 0xDC, 0x6F, 0xC0,
  34406. 0x56, 0x6B, 0xA8, 0xE1, 0xB8, 0x81, 0x63, 0x34,
  34407. 0xD3, 0x2A, 0x3F, 0xB1, 0xCE, 0x7D, 0x4D, 0x5E,
  34408. 0x4C, 0x33, 0x2A, 0xF7, 0xB0, 0x03, 0xD0, 0x91,
  34409. 0x74, 0x1A, 0x3D, 0x5C, 0x96, 0x52, 0x92, 0x25,
  34410. 0x5D, 0xFF, 0x8E, 0xD2, 0xBB, 0xF1, 0xF9, 0x11,
  34411. 0x6B, 0xE5, 0x0C, 0x17, 0xB8, 0xE5, 0x48, 0x74,
  34412. 0x8A, 0xD4, 0xB2, 0xE9, 0x57, 0xBB, 0xD1, 0x95,
  34413. 0x34, 0x82, 0xA2, 0xE1, 0x71, 0x8C, 0xEC, 0x66,
  34414. 0xCD, 0x2C, 0x81, 0xF5, 0x72, 0xD5, 0x52, 0xB7,
  34415. 0x18, 0x78, 0x85, 0xE6, 0xB8, 0x94, 0x3D, 0x64,
  34416. 0x31, 0x41, 0x3C, 0x59, 0xEB, 0xB7, 0xE0, 0x36,
  34417. 0x04, 0x84, 0x90, 0xBE, 0x52, 0x89, 0xE9, 0x5B,
  34418. 0x20, 0xA8, 0x9E, 0x8B, 0x15, 0x9F, 0x61, 0xA9,
  34419. 0xA9, 0x88, 0x6E, 0x14, 0x75, 0x68, 0xF4, 0xC9,
  34420. 0x02, 0x1F, 0x36, 0x2F, 0x02, 0x68, 0x8A, 0x1C,
  34421. 0x8C, 0x3B, 0xB0, 0xD2, 0x40, 0x86, 0x88, 0x0E,
  34422. 0x55, 0xB6, 0xED, 0xB4, 0x3F, 0x37, 0x45, 0xD2,
  34423. 0xC1, 0x66, 0xDC, 0x1C, 0xB7, 0x43, 0xC7, 0x6F,
  34424. 0xE6, 0xBE, 0x52, 0x3A, 0x89, 0x3C, 0xC7, 0x64,
  34425. 0xD1, 0x64, 0x35, 0xC3, 0x78, 0x51, 0x25, 0x2A,
  34426. 0x81, 0xE2, 0xFF, 0xBA, 0x0F, 0x18, 0x97, 0x1A,
  34427. 0x3D, 0xEE, 0x37, 0xD4, 0x87, 0x7C, 0xB9, 0x28,
  34428. 0xE3, 0x6E, 0x52, 0x35, 0x03, 0x7A, 0x6B, 0x20,
  34429. 0x57, 0x89, 0x7D, 0x51, 0x8A, 0x5F, 0x0E, 0x34,
  34430. 0x8E, 0x3A, 0xB6, 0xD5, 0xB5, 0x2D, 0xFC, 0x60,
  34431. 0x75, 0x7F, 0x3B, 0x41, 0xA4, 0xFE, 0xC7, 0x82,
  34432. 0x8F, 0x1D, 0xEE, 0xAF, 0x45, 0x87, 0xCC, 0xC8,
  34433. 0xEA, 0xDF, 0x64, 0x7F, 0x4D, 0x20, 0x3B, 0x2F,
  34434. 0xAA, 0x05, 0xA6, 0x49, 0xB5, 0x82, 0x34, 0x0C,
  34435. 0xB4, 0xCA, 0xCE, 0x57, 0xA3, 0x07, 0x11, 0xBE,
  34436. 0x75, 0x2F, 0xAC, 0xF0, 0x22, 0x7D, 0x0A, 0x80,
  34437. 0xC4, 0x12, 0x84, 0x42, 0xDD, 0xC5, 0x44, 0xBE,
  34438. 0x80, 0x5B, 0x9C, 0xFE, 0x8F, 0xE9, 0xB1, 0x23,
  34439. 0x7C, 0x80, 0xF9, 0x67, 0x87, 0xCD, 0x92, 0x81,
  34440. 0xCC, 0xF2, 0x70, 0xC1, 0xAF, 0xC0, 0x67, 0x0D
  34441. #else
  34442. 0x11, 0x3d, 0xb2, 0xdd, 0x06, 0x87, 0x12, 0x35,
  34443. 0xe7, 0xbc, 0x36, 0xc9, 0xdc, 0xaa, 0x52, 0x8f,
  34444. 0xc2, 0x6c, 0xe5, 0xdb, 0x9e, 0xcc, 0x1d, 0xc3,
  34445. 0x2e, 0x95, 0x7d, 0x7f, 0xfb, 0x3c, 0x74, 0x29,
  34446. 0xd5, 0x0c, 0x3c, 0x35, 0x77, 0xa5, 0x15, 0xd3,
  34447. 0x18, 0x3a, 0x1b, 0x9d, 0x26, 0x7b, 0x93, 0x6b,
  34448. 0x7e, 0xb8, 0xf5, 0x43, 0xa3, 0xaf, 0xb7, 0x77,
  34449. 0x65, 0xca, 0x79, 0x38, 0xf7, 0x8a, 0xa6, 0x43,
  34450. 0x8c, 0xe8, 0x0a, 0x06, 0xa6, 0x96, 0x6d, 0x0d,
  34451. 0x06, 0xaf, 0x75, 0xba, 0x3e, 0x0d, 0x4f, 0x37,
  34452. 0xba, 0xc7, 0x33, 0x69, 0xf5, 0xa7, 0x29, 0xf7,
  34453. 0x3e, 0x85, 0x72, 0x9e, 0xdd, 0x97, 0xc8, 0xc2,
  34454. 0xa8, 0xcc, 0x26, 0x19, 0xe4, 0xcf, 0x7b, 0x60,
  34455. 0x91, 0x86, 0x9e, 0x90, 0x9f, 0xd4, 0x7d, 0x97,
  34456. 0x09, 0x14, 0x92, 0x04, 0xb0, 0x83, 0x7d, 0x8d,
  34457. 0x6f, 0x25, 0xd2, 0x67, 0x97, 0x2b, 0xe6, 0x3b,
  34458. 0xad, 0x34, 0xb5, 0x44, 0x52, 0x3c, 0x01, 0xc0,
  34459. 0x9d, 0xe3, 0xb1, 0xfa, 0x1d, 0x6b, 0x7b, 0x05,
  34460. 0x9e, 0xee, 0x9e, 0x65, 0x20, 0x62, 0xfe, 0x87,
  34461. 0x0f, 0x68, 0xc6, 0x80, 0x05, 0x33, 0x9e, 0xa1,
  34462. 0x81, 0xe1, 0xd0, 0x76, 0x7c, 0x15, 0x2a, 0xeb,
  34463. 0x38, 0xfa, 0xf0, 0xf9, 0x24, 0x5a, 0xe5, 0x9d,
  34464. 0x5c, 0xb0, 0xd2, 0xb7, 0xf2, 0x01, 0x22, 0x9e,
  34465. 0xd9, 0x70, 0x20, 0xd0, 0x62, 0x3a, 0x46, 0x10,
  34466. 0x0d, 0x09, 0x7b, 0x0c, 0xe1, 0x15, 0x4e, 0x02,
  34467. 0x8a, 0xe6, 0x19, 0x4d, 0xe0, 0x5d, 0xe9, 0x7d,
  34468. 0xd9, 0xae, 0x2e, 0x85, 0xff, 0xd2, 0x5d, 0x95,
  34469. 0xeb, 0x22, 0xef, 0xfe, 0x5b, 0xa1, 0x9c, 0xd8,
  34470. 0x07, 0xc5, 0x30, 0xeb, 0xaa, 0x9f, 0xe9, 0xf6,
  34471. 0x42, 0xcc, 0xac, 0xff, 0x47, 0xed, 0x15, 0xc2,
  34472. 0x2b, 0xfe, 0x30, 0x36, 0xeb, 0xf8, 0xad, 0x9c,
  34473. 0x8e, 0xd2, 0x32, 0x40, 0xae, 0xeb, 0xaa, 0x24,
  34474. 0xd1, 0x35, 0x75, 0x51, 0x00, 0xb8, 0x5e, 0xce,
  34475. 0xe3, 0x17, 0x49, 0x06, 0xe4, 0x63, 0x12, 0x06,
  34476. 0x2c, 0xee, 0xca, 0xc7, 0x5d, 0xe5, 0x27, 0x52,
  34477. 0x56, 0xc2, 0xc1, 0xa6, 0x53, 0xfd, 0x69, 0x15,
  34478. 0xb1, 0xb3, 0x0c, 0x8e, 0xcb, 0xb6, 0xfd, 0x42,
  34479. 0x80, 0x43, 0x74, 0x53, 0x17, 0x3a, 0x96, 0x23,
  34480. 0x8b, 0xc7, 0xd1, 0x08, 0x89, 0x23, 0x43, 0xe0,
  34481. 0x33, 0xbc, 0xd9, 0x8e, 0x43, 0x7e, 0x78, 0x9f,
  34482. 0xc5, 0xbe, 0xba, 0xa1, 0x2b, 0x26, 0x34, 0xb5,
  34483. 0x1e, 0xd0, 0xd5, 0x89, 0xf1, 0x11, 0x43, 0xa0,
  34484. 0x21, 0xd8, 0xec, 0xce, 0x59, 0x4f, 0xdd, 0x48,
  34485. 0xda, 0xe8, 0x4c, 0x80, 0x63, 0xef, 0x35, 0x81,
  34486. 0xbc, 0x37, 0x8a, 0x48, 0xda, 0x4e, 0x51, 0xbb,
  34487. 0x17, 0x5b, 0x0d, 0xb4, 0x7f, 0x9d, 0xcf, 0x99,
  34488. 0x31, 0x8c, 0x30, 0x22, 0x5c, 0xa7, 0xfa, 0x79,
  34489. 0xc8, 0x79, 0xbf, 0x1c, 0x93, 0x97, 0xb5, 0xcc,
  34490. 0xc5, 0xef, 0xad, 0x94, 0xc5, 0x00, 0xed, 0x7f,
  34491. 0x9f, 0x38, 0x5d, 0x08, 0x8e, 0x34, 0x93, 0x22,
  34492. 0x21, 0xfc, 0x0f, 0xc9, 0xaf, 0xe5, 0x1f, 0x68,
  34493. 0x75, 0x54, 0x81, 0x31, 0x69, 0x76, 0x95, 0x47,
  34494. 0x8a, 0xbd, 0xc8, 0x73, 0x6f, 0x10, 0x09, 0x5a,
  34495. 0x6b, 0x92, 0xec, 0x67, 0x9f, 0xe0, 0xe2, 0xae,
  34496. 0x5d, 0x8b, 0x33, 0x53, 0x55, 0xd5, 0x8d, 0xae,
  34497. 0x4d, 0x4f, 0x0b, 0x17, 0xaa, 0x5d, 0x1e, 0x52,
  34498. 0xf1, 0xd4, 0x55, 0x84, 0xa8, 0x92, 0xc3, 0x4c,
  34499. 0xe4, 0xb0, 0x4f, 0xcd, 0x00, 0x98, 0x1d, 0x51,
  34500. 0xca, 0xa1, 0x60, 0x64, 0xba, 0xd9, 0x2d, 0x01,
  34501. 0x9d, 0xc3, 0xad, 0xed, 0x91, 0x96, 0x84, 0x11,
  34502. 0x2b, 0x29, 0xda, 0xa2, 0x8b, 0x9d, 0xae, 0x09,
  34503. 0xb8, 0x6b, 0x21, 0xa9, 0x33, 0x10, 0xd5, 0xfb,
  34504. 0xc6, 0x52, 0x7b, 0x22, 0x4b, 0x9c, 0xe8, 0x7d,
  34505. 0x27, 0x82, 0xbb, 0x29, 0x46, 0x73, 0xf0, 0xec,
  34506. 0x06, 0xf2, 0x6b, 0x08, 0x76, 0x52, 0xa1, 0x8d,
  34507. 0x6a, 0xd7, 0xb1, 0xc9, 0x33, 0x03, 0xef, 0x05,
  34508. 0x61, 0xc0, 0xfc, 0x9c, 0xd4, 0xf6, 0x78, 0xf6,
  34509. 0x06, 0xf1, 0x92, 0xcf, 0x5d, 0xf9, 0x2b, 0x15,
  34510. 0x48, 0xf5, 0xdd, 0x26, 0x87, 0xed, 0xbe, 0xcc,
  34511. 0xfc, 0x6d, 0x4e, 0x9d, 0xe4, 0xbd, 0x50, 0xd3,
  34512. 0xc7, 0x4f, 0xb2, 0x75, 0xab, 0xd9, 0xb3, 0xe9,
  34513. 0x02, 0x77, 0xdb, 0x4a, 0x00, 0x69, 0xc0, 0xa2,
  34514. 0xa7, 0x13, 0x6f, 0x50, 0xce, 0xad, 0x4b, 0x2f,
  34515. 0x19, 0x95, 0xfa, 0xaf, 0x16, 0x80, 0x40, 0xe9,
  34516. 0xe4, 0xbe, 0xb7, 0xc5, 0x72, 0x20, 0x49, 0xd6,
  34517. 0xda, 0x64, 0x02, 0x99, 0x2f, 0xce, 0xa4, 0x50,
  34518. 0x97, 0xdf, 0x7c, 0x1c, 0x20, 0xfb, 0x06, 0x82,
  34519. 0x22, 0x00, 0x05, 0x76, 0x93, 0x5a, 0x08, 0x06,
  34520. 0x77, 0x34, 0x51, 0x92, 0x1f, 0x54, 0xc5, 0x5f,
  34521. 0xbf, 0x59, 0x3a, 0x4f, 0x14, 0x7c, 0x1f, 0xef,
  34522. 0x3a, 0xca, 0xf0, 0xcf, 0xa9, 0x07, 0xae, 0x48,
  34523. 0xc8, 0xc0, 0x63, 0x12, 0xcf, 0xdf, 0x51, 0x86,
  34524. 0x90, 0x4b, 0xec, 0x7f, 0xed, 0x4e, 0xd9, 0x33,
  34525. 0xc9, 0x25, 0x6a, 0xb0, 0x4c, 0xbf, 0xa0, 0x3a,
  34526. 0x96, 0x7c, 0x1f, 0x7e, 0xad, 0x4a, 0xb4, 0x0d,
  34527. 0xf1, 0x16, 0xbe, 0x66, 0x0e, 0x27, 0xca, 0x2b,
  34528. 0x54, 0x35, 0x26, 0xd4, 0xb9, 0x68, 0x4c, 0x31,
  34529. 0xe1, 0xe4, 0x23, 0x83, 0xb9, 0x69, 0xf8, 0x96,
  34530. 0x29, 0x9d, 0x71, 0x39, 0x0c, 0xc8, 0x5b, 0x70,
  34531. 0x32, 0x02, 0xac, 0xad, 0xec, 0xfa, 0x8c, 0x40,
  34532. 0x96, 0x5c, 0x08, 0xc5, 0x3b, 0x56, 0x71, 0xe0,
  34533. 0xd5, 0x94, 0x55, 0xbc, 0x5a, 0x85, 0x86, 0xc6,
  34534. 0x55, 0xdb, 0x8c, 0x2a, 0xde, 0x4b, 0xa8, 0x87,
  34535. 0x7f, 0x19, 0xb6, 0x00, 0x0e, 0x18, 0xf8, 0xfe,
  34536. 0xad, 0xda, 0x7e, 0xde, 0x8f, 0xe8, 0x0a, 0xa6,
  34537. 0x62, 0xd6, 0x94, 0xc6, 0xd8, 0xc3, 0x3b, 0x52
  34538. #endif
  34539. };
  34540. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ss[] = {
  34541. #ifdef WOLFSSL_KYBER_ORIGINAL
  34542. 0x0A, 0x69, 0x25, 0x67, 0x6F, 0x24, 0xB2, 0x2C,
  34543. 0x28, 0x6F, 0x4C, 0x81, 0xA4, 0x22, 0x4C, 0xEC,
  34544. 0x50, 0x6C, 0x9B, 0x25, 0x7D, 0x48, 0x0E, 0x02,
  34545. 0xE3, 0xB4, 0x9F, 0x44, 0xCA, 0xA3, 0x23, 0x7F
  34546. #else
  34547. 0x31, 0x98, 0x39, 0xe8, 0x2a, 0xb6, 0xb2, 0x22,
  34548. 0xde, 0x7b, 0x61, 0x9e, 0x80, 0xda, 0x83, 0x91,
  34549. 0x52, 0x2b, 0xbb, 0x37, 0x67, 0x70, 0x18, 0x49,
  34550. 0x4a, 0x47, 0x42, 0xc5, 0x3f, 0x9a, 0xbf, 0xdf
  34551. #endif
  34552. };
  34553. #ifdef WOLFSSL_SMALL_STACK
  34554. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  34555. DYNAMIC_TYPE_TMP_BUFFER);
  34556. priv = (byte *)XMALLOC(KYBER512_PRIVATE_KEY_SIZE, HEAP_HINT,
  34557. DYNAMIC_TYPE_TMP_BUFFER);
  34558. pub = (byte *)XMALLOC(KYBER512_PUBLIC_KEY_SIZE, HEAP_HINT,
  34559. DYNAMIC_TYPE_TMP_BUFFER);
  34560. ct = (byte *)XMALLOC(KYBER512_CIPHER_TEXT_SIZE, HEAP_HINT,
  34561. DYNAMIC_TYPE_TMP_BUFFER);
  34562. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34563. DYNAMIC_TYPE_TMP_BUFFER);
  34564. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34565. DYNAMIC_TYPE_TMP_BUFFER);
  34566. if (! (key && priv && pub && ct && ss && ss_dec))
  34567. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  34568. #endif
  34569. ret = wc_KyberKey_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
  34570. if (ret != 0)
  34571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34572. else
  34573. key_inited = 1;
  34574. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34575. sizeof(kyber512_rand));
  34576. if (ret != 0)
  34577. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34578. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
  34579. if (ret != 0)
  34580. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34581. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
  34582. if (ret != 0)
  34583. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34584. if (XMEMCMP(pub, kyber512_pk, sizeof(kyber512_pk)) != 0)
  34585. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34586. if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0)
  34587. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34588. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34589. sizeof(kyber512enc_rand));
  34590. if (ret != 0)
  34591. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34592. if (XMEMCMP(ct, kyber512_ct, sizeof(kyber512_ct)) != 0)
  34593. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34594. if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34595. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34596. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
  34597. if (ret != 0)
  34598. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34599. if (XMEMCMP(ss_dec, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34600. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34601. out:
  34602. if (key_inited)
  34603. wc_KyberKey_Free(key);
  34604. #ifdef WOLFSSL_SMALL_STACK
  34605. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34606. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34607. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34608. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34609. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34610. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34611. #endif
  34612. return ret;
  34613. }
  34614. #endif /* WOLFSSL_KYBER512 */
  34615. #ifdef WOLFSSL_KYBER768
  34616. static wc_test_ret_t kyber768_kat(void)
  34617. {
  34618. wc_test_ret_t ret;
  34619. #ifdef WOLFSSL_SMALL_STACK
  34620. KyberKey *key = NULL;
  34621. byte *priv = NULL;
  34622. byte *pub = NULL;
  34623. byte *ct = NULL;
  34624. byte *ss = NULL;
  34625. byte *ss_dec = NULL;
  34626. #else
  34627. KyberKey key[1];
  34628. byte priv[KYBER768_PRIVATE_KEY_SIZE];
  34629. byte pub[KYBER768_PUBLIC_KEY_SIZE];
  34630. byte ct[KYBER768_CIPHER_TEXT_SIZE];
  34631. byte ss[KYBER_SS_SZ];
  34632. byte ss_dec[KYBER_SS_SZ];
  34633. #endif
  34634. int key_inited = 0;
  34635. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_rand[] = {
  34636. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  34637. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  34638. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  34639. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  34640. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34641. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34642. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34643. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34644. };
  34645. WOLFSSL_SMALL_STACK_STATIC const byte kyber768enc_rand[] = {
  34646. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  34647. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  34648. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  34649. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  34650. };
  34651. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_pk[] = {
  34652. #ifdef WOLFSSL_KYBER_ORIGINAL
  34653. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  34654. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  34655. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  34656. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  34657. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  34658. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  34659. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  34660. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  34661. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  34662. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  34663. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  34664. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  34665. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  34666. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  34667. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  34668. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  34669. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  34670. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  34671. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  34672. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  34673. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  34674. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  34675. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  34676. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  34677. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  34678. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  34679. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  34680. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  34681. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  34682. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  34683. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  34684. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  34685. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  34686. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  34687. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  34688. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  34689. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  34690. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  34691. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  34692. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  34693. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  34694. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  34695. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  34696. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  34697. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  34698. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  34699. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  34700. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  34701. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  34702. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  34703. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  34704. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  34705. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  34706. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  34707. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  34708. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  34709. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  34710. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  34711. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  34712. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  34713. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  34714. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  34715. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  34716. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  34717. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  34718. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  34719. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  34720. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  34721. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  34722. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  34723. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  34724. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  34725. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  34726. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  34727. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  34728. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  34729. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  34730. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  34731. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  34732. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  34733. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  34734. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  34735. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  34736. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  34737. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  34738. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  34739. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  34740. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  34741. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  34742. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  34743. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  34744. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  34745. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  34746. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  34747. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  34748. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  34749. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  34750. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  34751. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  34752. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  34753. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  34754. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  34755. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  34756. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  34757. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  34758. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  34759. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  34760. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  34761. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  34762. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  34763. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  34764. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  34765. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  34766. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  34767. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  34768. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  34769. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  34770. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  34771. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  34772. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  34773. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  34774. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  34775. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  34776. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  34777. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  34778. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  34779. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  34780. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  34781. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  34782. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  34783. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  34784. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  34785. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  34786. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  34787. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  34788. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  34789. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  34790. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  34791. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  34792. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  34793. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  34794. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  34795. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  34796. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  34797. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34798. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34799. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34800. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  34801. #else
  34802. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  34803. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  34804. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  34805. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  34806. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  34807. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  34808. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  34809. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  34810. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  34811. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  34812. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  34813. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  34814. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  34815. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  34816. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  34817. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  34818. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  34819. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  34820. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  34821. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  34822. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  34823. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  34824. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  34825. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  34826. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  34827. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  34828. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  34829. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  34830. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  34831. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  34832. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  34833. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  34834. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  34835. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  34836. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  34837. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  34838. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  34839. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  34840. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  34841. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  34842. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  34843. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  34844. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  34845. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  34846. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  34847. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  34848. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  34849. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  34850. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  34851. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  34852. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  34853. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  34854. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  34855. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  34856. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  34857. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  34858. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  34859. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  34860. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  34861. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  34862. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  34863. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  34864. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  34865. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  34866. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  34867. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  34868. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  34869. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  34870. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  34871. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  34872. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  34873. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  34874. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  34875. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  34876. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  34877. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  34878. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  34879. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  34880. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  34881. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  34882. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  34883. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  34884. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  34885. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  34886. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  34887. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  34888. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  34889. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  34890. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  34891. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  34892. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  34893. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  34894. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  34895. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  34896. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  34897. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  34898. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  34899. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  34900. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  34901. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  34902. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  34903. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  34904. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  34905. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  34906. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  34907. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  34908. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  34909. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  34910. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  34911. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  34912. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  34913. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  34914. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  34915. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  34916. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  34917. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  34918. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  34919. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  34920. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  34921. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  34922. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  34923. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  34924. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  34925. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  34926. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  34927. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  34928. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  34929. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  34930. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  34931. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  34932. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  34933. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  34934. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  34935. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  34936. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  34937. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  34938. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  34939. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  34940. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  34941. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  34942. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  34943. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  34944. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  34945. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  34946. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  34947. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  34948. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  34949. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28
  34950. #endif
  34951. };
  34952. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_sk[] = {
  34953. #ifdef WOLFSSL_KYBER_ORIGINAL
  34954. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  34955. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  34956. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  34957. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  34958. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  34959. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  34960. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  34961. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  34962. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  34963. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  34964. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  34965. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  34966. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  34967. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  34968. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  34969. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  34970. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  34971. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  34972. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  34973. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  34974. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  34975. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  34976. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  34977. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  34978. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  34979. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  34980. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  34981. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  34982. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  34983. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  34984. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  34985. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  34986. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  34987. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  34988. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  34989. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  34990. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  34991. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  34992. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  34993. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  34994. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  34995. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  34996. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  34997. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  34998. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  34999. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  35000. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  35001. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  35002. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  35003. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  35004. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  35005. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  35006. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  35007. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  35008. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  35009. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  35010. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  35011. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  35012. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  35013. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  35014. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  35015. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  35016. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  35017. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  35018. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  35019. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  35020. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  35021. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  35022. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  35023. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  35024. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  35025. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  35026. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  35027. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  35028. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  35029. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  35030. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  35031. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  35032. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  35033. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  35034. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  35035. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  35036. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  35037. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  35038. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  35039. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  35040. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  35041. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  35042. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  35043. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  35044. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  35045. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  35046. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  35047. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  35048. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  35049. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  35050. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  35051. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  35052. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  35053. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  35054. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  35055. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  35056. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  35057. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  35058. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  35059. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  35060. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  35061. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  35062. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  35063. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  35064. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  35065. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  35066. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  35067. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  35068. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  35069. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  35070. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  35071. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  35072. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  35073. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  35074. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  35075. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  35076. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  35077. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  35078. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  35079. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  35080. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  35081. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  35082. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  35083. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  35084. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  35085. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  35086. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  35087. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  35088. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  35089. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  35090. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  35091. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  35092. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  35093. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  35094. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  35095. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  35096. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  35097. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  35098. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35099. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35100. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35101. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35102. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35103. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35104. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35105. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35106. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35107. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35108. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35109. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35110. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35111. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35112. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35113. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35114. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35115. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35116. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35117. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35118. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35119. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35120. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35121. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35122. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35123. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35124. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35125. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35126. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35127. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35128. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35129. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35130. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35131. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35132. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35133. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35134. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35135. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35136. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35137. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35138. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35139. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35140. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35141. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35142. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35143. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35144. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35145. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35146. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35147. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35148. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35149. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35150. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35151. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35152. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35153. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35154. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35155. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35156. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35157. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35158. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35159. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35160. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35161. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35162. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35163. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35164. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35165. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35166. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35167. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35168. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35169. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35170. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35171. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35172. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35173. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35174. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35175. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35176. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35177. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35178. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35179. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35180. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35181. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35182. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35183. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35184. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35185. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35186. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35187. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35188. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35189. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35190. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35191. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35192. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35193. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35194. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35195. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35196. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35197. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35198. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35199. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35200. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35201. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35202. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35203. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35204. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35205. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35206. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35207. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35208. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35209. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35210. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35211. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35212. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35213. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35214. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35215. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35216. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35217. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35218. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35219. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35220. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35221. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35222. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35223. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35224. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35225. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35226. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35227. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35228. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35229. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35230. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35231. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35232. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35233. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35234. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35235. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35236. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35237. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35238. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35239. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35240. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35241. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35242. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35243. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35244. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35245. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  35246. 0xD4, 0xEC, 0x14, 0x3B, 0x50, 0xF0, 0x14, 0x23,
  35247. 0xB1, 0x77, 0x89, 0x5E, 0xDE, 0xE2, 0x2B, 0xB7,
  35248. 0x39, 0xF6, 0x47, 0xEC, 0xF8, 0x5F, 0x50, 0xBC,
  35249. 0x25, 0xEF, 0x7B, 0x5A, 0x72, 0x5D, 0xEE, 0x86,
  35250. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35251. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35252. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35253. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35254. #else
  35255. 0xda, 0x0a, 0xc7, 0xb6, 0x60, 0x40, 0x4e, 0x61,
  35256. 0x3a, 0xa1, 0xf9, 0x80, 0x38, 0x0c, 0xb3, 0x6d,
  35257. 0xba, 0x18, 0xd2, 0x32, 0x56, 0xc7, 0x26, 0x7a,
  35258. 0x00, 0xa6, 0x7b, 0xa6, 0xc2, 0xa2, 0xb1, 0x4c,
  35259. 0x41, 0x42, 0x39, 0x66, 0x2f, 0x68, 0xbd, 0x44,
  35260. 0x6c, 0x8e, 0xfd, 0xf3, 0x66, 0x56, 0xa0, 0x89,
  35261. 0x1a, 0x3c, 0xc6, 0x23, 0xfc, 0x68, 0xb6, 0x57,
  35262. 0x2f, 0x7b, 0x29, 0xa6, 0xde, 0x12, 0x80, 0x14,
  35263. 0x41, 0x1e, 0xe4, 0x19, 0x06, 0xd0, 0x80, 0x71,
  35264. 0xf9, 0x48, 0x56, 0xe3, 0x6a, 0x83, 0x2b, 0x40,
  35265. 0x33, 0x8d, 0x74, 0x35, 0x16, 0x65, 0x9b, 0xd2,
  35266. 0x58, 0x79, 0xc0, 0x07, 0xa5, 0x2b, 0xc9, 0x58,
  35267. 0x6f, 0x79, 0x87, 0x6a, 0xfa, 0xc6, 0xc9, 0xa3,
  35268. 0x0d, 0x8f, 0xac, 0x24, 0x3b, 0xd2, 0x24, 0x25,
  35269. 0xd6, 0xad, 0xce, 0x42, 0xab, 0x7e, 0xd3, 0x90,
  35270. 0x14, 0x75, 0x7a, 0x95, 0x8b, 0xc8, 0xa7, 0x45,
  35271. 0x65, 0xf0, 0x19, 0x23, 0x4f, 0xf0, 0x4b, 0x34,
  35272. 0x89, 0x3e, 0xd6, 0xd0, 0x55, 0x01, 0xc3, 0x72,
  35273. 0x55, 0x23, 0x9a, 0xae, 0x2a, 0xc1, 0x9f, 0x8c,
  35274. 0x75, 0xac, 0x59, 0x00, 0xda, 0xe8, 0x30, 0x0d,
  35275. 0xbb, 0xa7, 0x10, 0xdc, 0x2c, 0xaa, 0xe1, 0xbc,
  35276. 0xa3, 0xa3, 0x8c, 0x58, 0x34, 0x2b, 0x28, 0x6b,
  35277. 0x85, 0x18, 0xf1, 0x36, 0xad, 0x15, 0xb9, 0xf7,
  35278. 0xbc, 0xbb, 0x06, 0xa5, 0x60, 0x7d, 0xb3, 0x75,
  35279. 0xdb, 0xe9, 0x76, 0x45, 0x7c, 0x26, 0xc6, 0x59,
  35280. 0x82, 0x57, 0x53, 0x1b, 0x2c, 0xfb, 0x6e, 0xe7,
  35281. 0xf5, 0x15, 0x91, 0x84, 0x08, 0x04, 0xc3, 0x83,
  35282. 0x88, 0x37, 0x6c, 0x27, 0x14, 0x84, 0x13, 0xda,
  35283. 0x9e, 0x92, 0x92, 0x0b, 0xfd, 0x9a, 0x06, 0x9e,
  35284. 0x01, 0x8b, 0xd2, 0x72, 0x05, 0x3d, 0xa8, 0x77,
  35285. 0x5c, 0x0b, 0x73, 0x9f, 0x76, 0x1d, 0xb2, 0x10,
  35286. 0x7c, 0xf3, 0x5a, 0x43, 0x4d, 0x69, 0xb0, 0x7e,
  35287. 0x5b, 0xcd, 0xb8, 0x74, 0x34, 0x13, 0x8b, 0x0c,
  35288. 0xb5, 0x56, 0x76, 0x1b, 0xa5, 0x22, 0xa5, 0x74,
  35289. 0x7b, 0x28, 0x74, 0x7d, 0x80, 0xeb, 0x9d, 0x6c,
  35290. 0xc6, 0x73, 0xbe, 0xe5, 0x76, 0x93, 0x77, 0xb9,
  35291. 0x96, 0xd3, 0x6c, 0xeb, 0x0c, 0x0c, 0x7e, 0xd9,
  35292. 0xa6, 0x58, 0x53, 0x33, 0x24, 0x86, 0x9c, 0x18,
  35293. 0xa1, 0xa3, 0x6f, 0x31, 0x47, 0x0f, 0x14, 0xc5,
  35294. 0xae, 0x49, 0xab, 0x07, 0x05, 0x07, 0xf8, 0x24,
  35295. 0x9c, 0xe4, 0x04, 0xb4, 0x9c, 0x0a, 0x8c, 0x3e,
  35296. 0xe4, 0x2f, 0xea, 0x96, 0x31, 0xfa, 0x1a, 0x0d,
  35297. 0x10, 0xd8, 0x6b, 0x93, 0xf9, 0x86, 0xe0, 0xe3,
  35298. 0xa8, 0x2e, 0x70, 0x3b, 0x74, 0xe5, 0xae, 0x61,
  35299. 0x01, 0x24, 0x24, 0x21, 0xa8, 0x9a, 0xa0, 0x7f,
  35300. 0xe6, 0x85, 0x88, 0x46, 0x0b, 0xaa, 0x36, 0x87,
  35301. 0x86, 0x48, 0x6a, 0x72, 0xe4, 0xf2, 0x4d, 0x2d,
  35302. 0xd7, 0x6c, 0xfc, 0x03, 0xb6, 0x94, 0xa5, 0xba,
  35303. 0x91, 0xa7, 0x55, 0xa0, 0xb9, 0x8f, 0x3b, 0xf9,
  35304. 0x33, 0x07, 0xc0, 0xab, 0x64, 0x63, 0x9a, 0xea,
  35305. 0x7a, 0x64, 0x98, 0xa3, 0xc3, 0xdd, 0xc5, 0x71,
  35306. 0x14, 0x1a, 0xbc, 0xa4, 0x67, 0x8c, 0xd2, 0xe2,
  35307. 0xb8, 0x57, 0xfb, 0x88, 0xf6, 0x00, 0xca, 0xa5,
  35308. 0x96, 0xb4, 0x4b, 0xc4, 0x22, 0x25, 0x0b, 0x28,
  35309. 0x19, 0xe0, 0x51, 0x5f, 0x04, 0x72, 0x39, 0x18,
  35310. 0x53, 0x70, 0x0b, 0x01, 0xef, 0xf9, 0x45, 0x3f,
  35311. 0xd1, 0x18, 0x76, 0xb7, 0xc7, 0x59, 0xa0, 0x7d,
  35312. 0xd8, 0x45, 0xca, 0xba, 0x45, 0x55, 0x26, 0x4a,
  35313. 0x82, 0x76, 0x51, 0x93, 0xfd, 0xf8, 0x1b, 0x62,
  35314. 0x0a, 0x1e, 0x1f, 0x92, 0x3f, 0xb2, 0x44, 0x42,
  35315. 0xcd, 0x1c, 0xbe, 0x94, 0x17, 0x50, 0x03, 0xec,
  35316. 0x06, 0xce, 0x77, 0xa3, 0xc6, 0x44, 0x93, 0xc1,
  35317. 0x99, 0x98, 0x7a, 0x30, 0x0c, 0x95, 0xc5, 0x3c,
  35318. 0x00, 0x89, 0xb5, 0xd6, 0x5c, 0x92, 0xea, 0x97,
  35319. 0x1b, 0x2f, 0xfa, 0x93, 0xb5, 0x2a, 0x46, 0x1e,
  35320. 0xa2, 0xac, 0x8c, 0x19, 0x9c, 0x2f, 0x4c, 0x2b,
  35321. 0x70, 0x42, 0x97, 0xce, 0x3c, 0x39, 0x49, 0xe0,
  35322. 0x73, 0x5e, 0xa8, 0xa1, 0x4a, 0xa5, 0x9e, 0x8d,
  35323. 0xec, 0x0c, 0x87, 0x83, 0x99, 0xff, 0x70, 0x74,
  35324. 0x7a, 0xb2, 0x44, 0xce, 0x46, 0xb5, 0xf2, 0x23,
  35325. 0x04, 0x73, 0x32, 0x3d, 0x25, 0xc6, 0x6f, 0xe6,
  35326. 0xb4, 0x19, 0xb1, 0xf4, 0xa1, 0x12, 0xe5, 0x21,
  35327. 0x40, 0x35, 0x25, 0x6b, 0xc4, 0x3f, 0xfd, 0x2b,
  35328. 0x6b, 0x7b, 0x37, 0x87, 0x69, 0xa6, 0xb4, 0x70,
  35329. 0x00, 0xbf, 0xb6, 0x35, 0x7d, 0x45, 0x81, 0x4b,
  35330. 0xae, 0xf3, 0x85, 0x7d, 0x37, 0x9e, 0x2f, 0xb8,
  35331. 0xb5, 0xe5, 0x20, 0x1a, 0xb2, 0x62, 0x74, 0xbb,
  35332. 0x1b, 0x70, 0xad, 0x32, 0x2c, 0xd0, 0x43, 0x9b,
  35333. 0x2d, 0xb1, 0x09, 0xcf, 0xf0, 0xa2, 0xf8, 0xe6,
  35334. 0x00, 0x99, 0x55, 0x71, 0xff, 0xc3, 0x8c, 0x59,
  35335. 0x0b, 0xc4, 0xc7, 0x61, 0x5c, 0x69, 0xd0, 0xc9,
  35336. 0x8e, 0xf4, 0x30, 0xf3, 0x08, 0x61, 0xa7, 0x72,
  35337. 0x38, 0xff, 0xc0, 0x70, 0x61, 0xe4, 0x75, 0xd6,
  35338. 0xa3, 0x0a, 0xd1, 0xb4, 0x7f, 0xd0, 0x39, 0xc3,
  35339. 0xa4, 0x47, 0x76, 0x2d, 0xb2, 0x21, 0x1d, 0xc3,
  35340. 0x1d, 0x0a, 0xca, 0xcf, 0xd5, 0x58, 0x90, 0xa5,
  35341. 0x82, 0x47, 0x98, 0xf9, 0xae, 0xad, 0x74, 0x13,
  35342. 0xdf, 0xe0, 0x28, 0xb1, 0x01, 0x2b, 0xe8, 0xb6,
  35343. 0xca, 0x10, 0x26, 0x66, 0x6a, 0xc6, 0xbc, 0x94,
  35344. 0x40, 0xa4, 0x49, 0xb5, 0x1a, 0xd8, 0xbb, 0xa7,
  35345. 0xb0, 0x92, 0x1d, 0xd4, 0xd8, 0xb4, 0xa5, 0x78,
  35346. 0x13, 0x6d, 0x1a, 0x05, 0xdb, 0x38, 0xcc, 0x85,
  35347. 0x84, 0x37, 0xb2, 0x51, 0x61, 0xd1, 0xc3, 0xc2,
  35348. 0x8e, 0xe0, 0x7b, 0xbc, 0xf2, 0xb2, 0x49, 0x11,
  35349. 0x0d, 0x22, 0x78, 0x1d, 0xc3, 0x05, 0x0d, 0x8c,
  35350. 0xc0, 0x09, 0x00, 0x96, 0xb3, 0x8a, 0x85, 0x06,
  35351. 0x96, 0xf8, 0x6e, 0x9e, 0x6b, 0xab, 0x32, 0x52,
  35352. 0x71, 0xb2, 0x24, 0x86, 0x75, 0x01, 0x19, 0x68,
  35353. 0x50, 0x28, 0x81, 0x09, 0x04, 0x97, 0xfa, 0xc0,
  35354. 0xaf, 0x84, 0x3c, 0x1a, 0xea, 0x76, 0xdd, 0x81,
  35355. 0xcf, 0x29, 0xc0, 0x12, 0xc6, 0x62, 0x27, 0xb7,
  35356. 0xf0, 0x6d, 0x99, 0x61, 0x30, 0x9b, 0x02, 0x62,
  35357. 0xf7, 0x32, 0xc9, 0xa4, 0xd0, 0xbb, 0xd0, 0x67,
  35358. 0x27, 0xab, 0xb8, 0x37, 0x1f, 0xf2, 0xc1, 0x18,
  35359. 0x99, 0xa0, 0x98, 0x37, 0x5c, 0x46, 0x05, 0x16,
  35360. 0xb2, 0xcc, 0x88, 0xbc, 0xf6, 0x28, 0xed, 0xe3,
  35361. 0x7d, 0x8f, 0x3b, 0x33, 0x42, 0xe4, 0x49, 0x0a,
  35362. 0x85, 0x60, 0x6e, 0xc0, 0x3d, 0xa2, 0x9b, 0x02,
  35363. 0x56, 0x27, 0x53, 0x82, 0xa3, 0x31, 0x3d, 0xc0,
  35364. 0x41, 0x11, 0x48, 0x01, 0x03, 0x2c, 0x51, 0x9f,
  35365. 0x35, 0x0c, 0x3e, 0x6a, 0xba, 0xc3, 0xe3, 0x3b,
  35366. 0x93, 0xb4, 0xa1, 0x9f, 0x7c, 0x54, 0x66, 0xe5,
  35367. 0x8c, 0xb1, 0xdc, 0x14, 0xb4, 0xa9, 0x6c, 0x47,
  35368. 0x57, 0x29, 0xf9, 0x71, 0xbd, 0xf1, 0x73, 0xcd,
  35369. 0xf3, 0x54, 0x82, 0x4d, 0x01, 0x94, 0x27, 0xf9,
  35370. 0x5b, 0x3b, 0x4a, 0x4a, 0x4a, 0x95, 0x8e, 0x47,
  35371. 0x6a, 0x6e, 0x69, 0x91, 0xce, 0x6f, 0x06, 0xcb,
  35372. 0x5d, 0xfc, 0xa7, 0xd4, 0x38, 0x0c, 0x3d, 0x92,
  35373. 0x0b, 0x57, 0x11, 0xac, 0x1f, 0xcb, 0xaf, 0x4b,
  35374. 0x9a, 0xc8, 0x00, 0xb9, 0x76, 0xd1, 0xec, 0x76,
  35375. 0x6a, 0x62, 0x6c, 0xc1, 0x90, 0x0b, 0x66, 0xb3,
  35376. 0xa9, 0xdc, 0x62, 0xc5, 0xc1, 0x44, 0x52, 0x7a,
  35377. 0x29, 0x6b, 0xaf, 0x70, 0x43, 0x3b, 0xf6, 0x57,
  35378. 0xc0, 0x43, 0x7f, 0x87, 0x59, 0x7b, 0xd7, 0xc8,
  35379. 0xbb, 0xbe, 0x9a, 0xbc, 0x37, 0x05, 0x09, 0x31,
  35380. 0xa4, 0xa8, 0x69, 0x82, 0xa2, 0x02, 0x8a, 0x74,
  35381. 0x45, 0x4c, 0x9b, 0x81, 0x0c, 0x88, 0xd1, 0x70,
  35382. 0x1c, 0x8c, 0xc9, 0x8a, 0x1d, 0x4c, 0xa1, 0x07,
  35383. 0xa6, 0xb2, 0x5e, 0x96, 0x2f, 0xe4, 0xb6, 0xb0,
  35384. 0x3c, 0x95, 0x45, 0x32, 0x60, 0xb8, 0x07, 0x22,
  35385. 0x86, 0x37, 0xcc, 0x9e, 0xb1, 0x2a, 0xcc, 0x09,
  35386. 0x54, 0x95, 0x9a, 0x52, 0xae, 0x54, 0xd1, 0x97,
  35387. 0x73, 0x00, 0xab, 0xa0, 0xba, 0x2c, 0x14, 0x60,
  35388. 0x9b, 0xb2, 0x8c, 0x11, 0xd5, 0xfa, 0xc5, 0xca,
  35389. 0xc8, 0x82, 0x97, 0x60, 0x32, 0x83, 0xe8, 0x67,
  35390. 0xa3, 0x64, 0x83, 0x66, 0xc7, 0x24, 0xd9, 0x35,
  35391. 0x4c, 0xd7, 0xa1, 0x96, 0xdb, 0xd9, 0x80, 0x2f,
  35392. 0x7b, 0x88, 0xd3, 0xfa, 0x00, 0x1f, 0x9c, 0x97,
  35393. 0x73, 0x22, 0x54, 0x62, 0x23, 0x5e, 0x91, 0x35,
  35394. 0x2a, 0x20, 0x79, 0x1f, 0xd8, 0xb8, 0x7f, 0xe3,
  35395. 0x37, 0x7e, 0xc6, 0xa3, 0x94, 0x0b, 0x11, 0x30,
  35396. 0xa0, 0xbb, 0x04, 0xe7, 0x41, 0x0a, 0x34, 0xe2,
  35397. 0x58, 0x0d, 0x07, 0x1d, 0x6c, 0x56, 0x20, 0x20,
  35398. 0x86, 0x78, 0x7a, 0x65, 0x90, 0xf8, 0x43, 0x93,
  35399. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35400. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35401. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35402. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35403. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35404. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35405. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35406. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35407. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35408. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35409. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35410. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35411. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35412. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35413. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35414. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35415. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35416. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35417. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35418. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35419. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35420. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35421. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35422. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35423. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35424. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35425. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35426. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35427. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35428. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35429. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35430. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35431. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35432. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35433. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35434. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35435. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35436. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35437. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35438. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35439. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35440. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35441. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35442. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35443. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35444. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35445. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35446. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35447. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35448. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35449. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35450. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35451. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35452. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35453. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35454. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35455. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35456. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35457. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35458. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35459. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35460. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35461. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35462. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35463. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35464. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35465. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35466. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35467. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35468. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35469. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35470. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35471. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35472. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35473. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35474. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35475. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35476. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35477. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35478. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35479. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35480. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35481. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35482. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35483. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35484. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35485. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35486. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35487. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35488. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35489. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35490. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35491. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35492. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35493. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35494. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35495. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35496. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35497. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35498. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35499. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35500. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35501. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35502. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35503. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35504. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35505. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35506. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35507. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35508. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35509. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35510. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35511. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35512. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35513. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35514. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35515. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35516. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35517. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35518. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35519. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35520. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35521. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35522. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35523. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35524. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35525. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35526. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35527. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35528. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35529. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35530. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35531. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35532. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35533. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35534. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35535. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35536. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35537. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35538. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35539. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35540. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35541. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35542. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35543. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35544. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35545. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35546. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28,
  35547. 0xf5, 0x72, 0x62, 0x66, 0x13, 0x58, 0xcd, 0xe8,
  35548. 0xd3, 0xeb, 0xf9, 0x90, 0xe5, 0xfd, 0x1d, 0x5b,
  35549. 0x89, 0x6c, 0x99, 0x2c, 0xcf, 0xaa, 0xdb, 0x52,
  35550. 0x56, 0xb6, 0x8b, 0xbf, 0x59, 0x43, 0xb1, 0x32,
  35551. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  35552. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  35553. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  35554. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  35555. #endif
  35556. };
  35557. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ct[] = {
  35558. #ifdef WOLFSSL_KYBER_ORIGINAL
  35559. 0xB5, 0x2C, 0x56, 0xB9, 0x2A, 0x4B, 0x7C, 0xE9,
  35560. 0xE4, 0xCB, 0x7C, 0x5B, 0x1B, 0x16, 0x31, 0x67,
  35561. 0xA8, 0xA1, 0x67, 0x5B, 0x2F, 0xDE, 0xF8, 0x4A,
  35562. 0x5B, 0x67, 0xCA, 0x15, 0xDB, 0x69, 0x4C, 0x9F,
  35563. 0x11, 0xBD, 0x02, 0x7C, 0x30, 0xAE, 0x22, 0xEC,
  35564. 0x92, 0x1A, 0x1D, 0x91, 0x15, 0x99, 0xAF, 0x05,
  35565. 0x85, 0xE4, 0x8D, 0x20, 0xDA, 0x70, 0xDF, 0x9F,
  35566. 0x39, 0xE3, 0x2E, 0xF9, 0x5D, 0x4C, 0x8F, 0x44,
  35567. 0xBF, 0xEF, 0xDA, 0xA5, 0xDA, 0x64, 0xF1, 0x05,
  35568. 0x46, 0x31, 0xD0, 0x4D, 0x6D, 0x3C, 0xFD, 0x0A,
  35569. 0x54, 0x0D, 0xD7, 0xBA, 0x38, 0x86, 0xE4, 0xB5,
  35570. 0xF1, 0x3E, 0x87, 0x87, 0x88, 0x60, 0x4C, 0x95,
  35571. 0xC0, 0x96, 0xEA, 0xB3, 0x91, 0x9F, 0x42, 0x75,
  35572. 0x21, 0x41, 0x9A, 0x94, 0x6C, 0x26, 0xCC, 0x04,
  35573. 0x14, 0x75, 0xD7, 0x12, 0x4C, 0xDC, 0x01, 0xD0,
  35574. 0x37, 0x3E, 0x5B, 0x09, 0xC7, 0xA7, 0x06, 0x03,
  35575. 0xCF, 0xDB, 0x4F, 0xB3, 0x40, 0x50, 0x23, 0xF2,
  35576. 0x26, 0x4D, 0xC3, 0xF9, 0x83, 0xC4, 0xFC, 0x02,
  35577. 0xA2, 0xD1, 0xB2, 0x68, 0xF2, 0x20, 0x8A, 0x1F,
  35578. 0x6E, 0x2A, 0x62, 0x09, 0xBF, 0xF1, 0x2F, 0x6F,
  35579. 0x46, 0x5F, 0x0B, 0x06, 0x9C, 0x3A, 0x7F, 0x84,
  35580. 0xF6, 0x06, 0xD8, 0xA9, 0x40, 0x64, 0x00, 0x3D,
  35581. 0x6E, 0xC1, 0x14, 0xC8, 0xE8, 0x08, 0xD3, 0x05,
  35582. 0x38, 0x84, 0xC1, 0xD5, 0xA1, 0x42, 0xFB, 0xF2,
  35583. 0x01, 0x12, 0xEB, 0x36, 0x0F, 0xDA, 0x3F, 0x0F,
  35584. 0x28, 0xB1, 0x72, 0xAE, 0x50, 0xF5, 0xE7, 0xD8,
  35585. 0x38, 0x01, 0xFB, 0x3F, 0x00, 0x64, 0xB6, 0x87,
  35586. 0x18, 0x70, 0x74, 0xBD, 0x7F, 0xE3, 0x0E, 0xDD,
  35587. 0xAA, 0x33, 0x4C, 0xF8, 0xFC, 0x04, 0xFA, 0x8C,
  35588. 0xED, 0x89, 0x9C, 0xEA, 0xDE, 0x4B, 0x4F, 0x28,
  35589. 0xB6, 0x83, 0x72, 0xBA, 0xF9, 0x8F, 0xF4, 0x82,
  35590. 0xA4, 0x15, 0xB7, 0x31, 0x15, 0x5B, 0x75, 0xCE,
  35591. 0xB9, 0x76, 0xBE, 0x0E, 0xA0, 0x28, 0x5B, 0xA0,
  35592. 0x1A, 0x27, 0xF1, 0x85, 0x7A, 0x8F, 0xB3, 0x77,
  35593. 0xA3, 0xAE, 0x0C, 0x23, 0xB2, 0xAA, 0x9A, 0x07,
  35594. 0x9B, 0xFA, 0xBF, 0xF0, 0xD5, 0xB2, 0xF1, 0xCD,
  35595. 0x9B, 0x71, 0x8B, 0xEA, 0x03, 0xC4, 0x2F, 0x34,
  35596. 0x3A, 0x39, 0xB4, 0xF1, 0x42, 0xD0, 0x1A, 0xD8,
  35597. 0xAC, 0xBB, 0x50, 0xE3, 0x88, 0x53, 0xCF, 0x9A,
  35598. 0x50, 0xC8, 0xB4, 0x4C, 0x3C, 0xF6, 0x71, 0xA4,
  35599. 0xA9, 0x04, 0x3B, 0x26, 0xDD, 0xBB, 0x24, 0x95,
  35600. 0x9A, 0xD6, 0x71, 0x5C, 0x08, 0x52, 0x18, 0x55,
  35601. 0xC7, 0x9A, 0x23, 0xB9, 0xC3, 0xD6, 0x47, 0x17,
  35602. 0x49, 0xC4, 0x07, 0x25, 0xBD, 0xD5, 0xC2, 0x77,
  35603. 0x6D, 0x43, 0xAE, 0xD2, 0x02, 0x04, 0xBA, 0xA1,
  35604. 0x41, 0xEF, 0xB3, 0x30, 0x49, 0x17, 0x47, 0x4B,
  35605. 0x7F, 0x9F, 0x7A, 0x4B, 0x08, 0xB1, 0xA9, 0x3D,
  35606. 0xAE, 0xD9, 0x8C, 0x67, 0x49, 0x53, 0x59, 0xD3,
  35607. 0x7D, 0x67, 0xF7, 0x43, 0x8B, 0xEE, 0x5E, 0x43,
  35608. 0x58, 0x56, 0x34, 0xB2, 0x6C, 0x6B, 0x38, 0x10,
  35609. 0xD7, 0xCD, 0xCB, 0xC0, 0xF6, 0xEB, 0x87, 0x7A,
  35610. 0x60, 0x87, 0xE6, 0x8A, 0xCB, 0x84, 0x80, 0xD3,
  35611. 0xA8, 0xCF, 0x69, 0x00, 0x44, 0x7E, 0x49, 0xB4,
  35612. 0x17, 0xF1, 0x5A, 0x53, 0xB6, 0x07, 0xA0, 0xE2,
  35613. 0x16, 0xB8, 0x55, 0x97, 0x0D, 0x37, 0x40, 0x68,
  35614. 0x70, 0xB4, 0x56, 0x87, 0x22, 0xDA, 0x77, 0xA4,
  35615. 0x08, 0x47, 0x03, 0x81, 0x67, 0x84, 0xE2, 0xF1,
  35616. 0x6B, 0xED, 0x18, 0x99, 0x65, 0x32, 0xC5, 0xD8,
  35617. 0xB7, 0xF5, 0xD2, 0x14, 0x46, 0x4E, 0x5F, 0x3F,
  35618. 0x6E, 0x90, 0x58, 0x67, 0xB0, 0xCE, 0x11, 0x9E,
  35619. 0x25, 0x2A, 0x66, 0x71, 0x32, 0x53, 0x54, 0x46,
  35620. 0x85, 0xD2, 0x08, 0xE1, 0x72, 0x39, 0x08, 0xA0,
  35621. 0xCE, 0x97, 0x83, 0x46, 0x52, 0xE0, 0x8A, 0xE7,
  35622. 0xBD, 0xC8, 0x81, 0xA1, 0x31, 0xB7, 0x3C, 0x71,
  35623. 0xE8, 0x4D, 0x20, 0xD6, 0x8F, 0xDE, 0xFF, 0x4F,
  35624. 0x5D, 0x70, 0xCD, 0x1A, 0xF5, 0x7B, 0x78, 0xE3,
  35625. 0x49, 0x1A, 0x98, 0x65, 0x94, 0x23, 0x21, 0x80,
  35626. 0x0A, 0x20, 0x3C, 0x05, 0xED, 0x1F, 0xEE, 0xB5,
  35627. 0xA2, 0x8E, 0x58, 0x4E, 0x19, 0xF6, 0x53, 0x5E,
  35628. 0x7F, 0x84, 0xE4, 0xA2, 0x4F, 0x84, 0xA7, 0x2D,
  35629. 0xCA, 0xF5, 0x64, 0x8B, 0x4A, 0x42, 0x35, 0xDD,
  35630. 0x66, 0x44, 0x64, 0x48, 0x2F, 0x03, 0x17, 0x6E,
  35631. 0x88, 0x8C, 0x28, 0xBF, 0xC6, 0xC1, 0xCB, 0x23,
  35632. 0x8C, 0xFF, 0xA3, 0x5A, 0x32, 0x1E, 0x71, 0x79,
  35633. 0x1D, 0x9E, 0xA8, 0xED, 0x08, 0x78, 0xC6, 0x11,
  35634. 0x21, 0xBF, 0x8D, 0x2A, 0x4A, 0xB2, 0xC1, 0xA5,
  35635. 0xE1, 0x20, 0xBC, 0x40, 0xAB, 0xB1, 0x89, 0x2D,
  35636. 0x17, 0x15, 0x09, 0x0A, 0x0E, 0xE4, 0x82, 0x52,
  35637. 0xCA, 0x29, 0x7A, 0x99, 0xAA, 0x0E, 0x51, 0x0C,
  35638. 0xF2, 0x6B, 0x1A, 0xDD, 0x06, 0xCA, 0x54, 0x3E,
  35639. 0x1C, 0x5D, 0x6B, 0xDC, 0xD3, 0xB9, 0xC5, 0x85,
  35640. 0xC8, 0x53, 0x80, 0x45, 0xDB, 0x5C, 0x25, 0x2E,
  35641. 0xC3, 0xC8, 0xC3, 0xC9, 0x54, 0xD9, 0xBE, 0x59,
  35642. 0x07, 0x09, 0x4A, 0x89, 0x4E, 0x60, 0xEA, 0xB4,
  35643. 0x35, 0x38, 0xCF, 0xEE, 0x82, 0xE8, 0xFF, 0xC0,
  35644. 0x79, 0x1B, 0x0D, 0x0F, 0x43, 0xAC, 0x16, 0x27,
  35645. 0x83, 0x0A, 0x61, 0xD5, 0x6D, 0xAD, 0x96, 0xC6,
  35646. 0x29, 0x58, 0xB0, 0xDE, 0x78, 0x0B, 0x78, 0xBD,
  35647. 0x47, 0xA6, 0x04, 0x55, 0x0D, 0xAB, 0x83, 0xFF,
  35648. 0xF2, 0x27, 0xC3, 0x24, 0x04, 0x94, 0x71, 0xF3,
  35649. 0x52, 0x48, 0xCF, 0xB8, 0x49, 0xB2, 0x57, 0x24,
  35650. 0xFF, 0x70, 0x4D, 0x52, 0x77, 0xAA, 0x35, 0x2D,
  35651. 0x55, 0x09, 0x58, 0xBE, 0x3B, 0x23, 0x7D, 0xFF,
  35652. 0x47, 0x3E, 0xC2, 0xAD, 0xBA, 0xEA, 0x48, 0xCA,
  35653. 0x26, 0x58, 0xAE, 0xFC, 0xC7, 0x7B, 0xBD, 0x42,
  35654. 0x64, 0xAB, 0x37, 0x4D, 0x70, 0xEA, 0xE5, 0xB9,
  35655. 0x64, 0x41, 0x6C, 0xE8, 0x22, 0x6A, 0x7E, 0x32,
  35656. 0x55, 0xA0, 0xF8, 0xD7, 0xE2, 0xAD, 0xCA, 0x06,
  35657. 0x2B, 0xCD, 0x6D, 0x78, 0xD6, 0x0D, 0x1B, 0x32,
  35658. 0xE1, 0x14, 0x05, 0xBE, 0x54, 0xB6, 0x6E, 0xF0,
  35659. 0xFD, 0xDD, 0x56, 0x77, 0x02, 0xA3, 0xBC, 0xCF,
  35660. 0xED, 0xE3, 0xC5, 0x84, 0x70, 0x12, 0x69, 0xED,
  35661. 0x14, 0x80, 0x9F, 0x06, 0xF8, 0x96, 0x83, 0x56,
  35662. 0xBB, 0x92, 0x67, 0xFE, 0x86, 0xE5, 0x14, 0x25,
  35663. 0x2E, 0x88, 0xBB, 0x5C, 0x30, 0xA7, 0xEC, 0xB3,
  35664. 0xD0, 0xE6, 0x21, 0x02, 0x1E, 0xE0, 0xFB, 0xF7,
  35665. 0x87, 0x1B, 0x09, 0x34, 0x2B, 0xF8, 0x4F, 0x55,
  35666. 0xC9, 0x7E, 0xAF, 0x86, 0xC4, 0x81, 0x89, 0xC7,
  35667. 0xFF, 0x4D, 0xF3, 0x89, 0xF0, 0x77, 0xE2, 0x80,
  35668. 0x6E, 0x5F, 0xA7, 0x3B, 0x3E, 0x94, 0x58, 0xA1,
  35669. 0x6C, 0x7E, 0x27, 0x5F, 0x4F, 0x60, 0x22, 0x75,
  35670. 0x58, 0x0E, 0xB7, 0xB7, 0x13, 0x5F, 0xB5, 0x37,
  35671. 0xFA, 0x0C, 0xD9, 0x5D, 0x6E, 0xA5, 0x8C, 0x10,
  35672. 0x8C, 0xD8, 0x94, 0x3D, 0x70, 0xC1, 0x64, 0x31,
  35673. 0x11, 0xF4, 0xF0, 0x1C, 0xA8, 0xA8, 0x27, 0x6A,
  35674. 0x90, 0x26, 0x66, 0xED, 0x81, 0xB7, 0x8D, 0x16,
  35675. 0x8B, 0x00, 0x6F, 0x16, 0xAA, 0xA3, 0xD8, 0xE4,
  35676. 0xCE, 0x4F, 0x4D, 0x0F, 0xB0, 0x99, 0x7E, 0x41,
  35677. 0xAE, 0xFF, 0xB5, 0xB3, 0xDA, 0xA8, 0x38, 0x73,
  35678. 0x2F, 0x35, 0x73, 0x49, 0x44, 0x7F, 0x38, 0x77,
  35679. 0x76, 0xC7, 0x93, 0xC0, 0x47, 0x9D, 0xE9, 0xE9,
  35680. 0x94, 0x98, 0xCC, 0x35, 0x6F, 0xDB, 0x00, 0x75,
  35681. 0xA7, 0x03, 0xF2, 0x3C, 0x55, 0xD4, 0x7B, 0x55,
  35682. 0x0E, 0xC8, 0x9B, 0x02, 0xAD, 0xE8, 0x93, 0x29,
  35683. 0x08, 0x6A, 0x50, 0x84, 0x34, 0x56, 0xFE, 0xDC,
  35684. 0x37, 0x88, 0xAC, 0x8D, 0x97, 0x23, 0x3C, 0x54,
  35685. 0x56, 0x04, 0x67, 0xEE, 0x1D, 0x0F, 0x02, 0x4B,
  35686. 0x18, 0x42, 0x8F, 0x0D, 0x73, 0xB3, 0x0E, 0x19,
  35687. 0xF5, 0xC6, 0x3B, 0x9A, 0xBF, 0x11, 0x41, 0x5B,
  35688. 0xEA, 0x4D, 0x01, 0x70, 0x13, 0x0B, 0xAA, 0xBD,
  35689. 0x33, 0xC0, 0x5E, 0x65, 0x24, 0xE5, 0xFB, 0x55,
  35690. 0x81, 0xB2, 0x2B, 0x04, 0x33, 0x34, 0x22, 0x48,
  35691. 0x26, 0x6D, 0x0F, 0x10, 0x53, 0xB2, 0x45, 0xCC,
  35692. 0x24, 0x62, 0xDC, 0x44, 0xD3, 0x49, 0x65, 0x10,
  35693. 0x24, 0x82, 0xA8, 0xED, 0x9E, 0x4E, 0x96, 0x4D,
  35694. 0x56, 0x83, 0xE5, 0xD4, 0x5D, 0x0C, 0x82, 0x69
  35695. #else
  35696. 0xc8, 0x39, 0x10, 0x85, 0xb8, 0xd3, 0xea, 0x97,
  35697. 0x94, 0x21, 0x25, 0x41, 0xb2, 0x91, 0x4f, 0x08,
  35698. 0x96, 0x4d, 0x33, 0x52, 0x1d, 0x3f, 0x67, 0xad,
  35699. 0x66, 0x09, 0x6e, 0xbf, 0xb1, 0xf7, 0x06, 0x42,
  35700. 0x4b, 0x49, 0x55, 0x8f, 0x75, 0x5b, 0x56, 0x25,
  35701. 0xba, 0xe2, 0x36, 0xf2, 0xe0, 0x07, 0x96, 0x01,
  35702. 0xc7, 0x66, 0xf7, 0xd9, 0x60, 0x80, 0x8f, 0x7e,
  35703. 0x2b, 0xb0, 0xc7, 0xa5, 0xe0, 0x66, 0xed, 0x34,
  35704. 0x6d, 0xe6, 0x28, 0xf8, 0xc5, 0x7e, 0xeb, 0xab,
  35705. 0xbb, 0x0c, 0x22, 0xd9, 0x11, 0x54, 0x84, 0x63,
  35706. 0x69, 0x3e, 0xf3, 0xce, 0x52, 0xa5, 0x3f, 0x7f,
  35707. 0xf4, 0x15, 0xf0, 0x0e, 0x65, 0x7a, 0xe1, 0xc5,
  35708. 0xa4, 0x8f, 0xa5, 0xec, 0x6e, 0x4b, 0xe5, 0xcf,
  35709. 0x46, 0x2d, 0xaf, 0xfc, 0x84, 0xd2, 0xf6, 0xd5,
  35710. 0xff, 0x55, 0xdc, 0x9b, 0xbe, 0x8b, 0xb0, 0xd7,
  35711. 0x25, 0xec, 0x64, 0xfd, 0x4c, 0xd4, 0xbd, 0x8d,
  35712. 0xba, 0x0a, 0x84, 0x4e, 0x8b, 0x5c, 0xe4, 0xb6,
  35713. 0xa2, 0x89, 0x34, 0xd7, 0xf7, 0xa0, 0x50, 0x99,
  35714. 0x1f, 0xe1, 0x85, 0xb5, 0x06, 0xb4, 0x51, 0xda,
  35715. 0xbf, 0xad, 0x52, 0xd5, 0x2c, 0xb2, 0x11, 0x4c,
  35716. 0xa7, 0xd9, 0xa5, 0xcf, 0x98, 0x6c, 0x8f, 0xdc,
  35717. 0x1b, 0xc1, 0x0e, 0xc0, 0xc1, 0x86, 0x9e, 0x50,
  35718. 0xc0, 0x3c, 0x55, 0xa7, 0x61, 0x92, 0xa1, 0x04,
  35719. 0x9a, 0xca, 0x63, 0x6b, 0xa9, 0x02, 0x0b, 0xda,
  35720. 0xa8, 0xd0, 0xf5, 0x8c, 0x76, 0x3b, 0x0b, 0x89,
  35721. 0x84, 0x5c, 0xa0, 0x6d, 0x4c, 0x4d, 0xdc, 0x21,
  35722. 0x43, 0x3e, 0x16, 0xb9, 0xc6, 0x2e, 0x44, 0x87,
  35723. 0x1f, 0xdb, 0xc0, 0x5b, 0xa2, 0x18, 0xaf, 0x87,
  35724. 0x1f, 0xdd, 0x7d, 0xcf, 0xa4, 0x64, 0xe6, 0x0f,
  35725. 0xaa, 0x52, 0x65, 0x26, 0x4c, 0xe1, 0x39, 0x1b,
  35726. 0xd9, 0xa8, 0xc5, 0xfa, 0xa7, 0x62, 0x6d, 0x5f,
  35727. 0x15, 0x9b, 0x98, 0x05, 0xb9, 0x75, 0x71, 0x0a,
  35728. 0x35, 0x03, 0xa0, 0xb8, 0x58, 0xa1, 0x1c, 0x6a,
  35729. 0x64, 0x7c, 0xc0, 0xe1, 0x9a, 0xc8, 0x8b, 0x1b,
  35730. 0xe9, 0x05, 0x6c, 0x95, 0xb4, 0xd2, 0x08, 0x7d,
  35731. 0x09, 0x51, 0xd1, 0xd2, 0xf4, 0x99, 0x24, 0x91,
  35732. 0x11, 0x7e, 0x63, 0x47, 0x79, 0x4b, 0xa5, 0x45,
  35733. 0x71, 0xec, 0x49, 0xbb, 0xa7, 0x1a, 0xf3, 0x41,
  35734. 0x3d, 0x38, 0xa3, 0x0b, 0xf5, 0x87, 0x22, 0x48,
  35735. 0xd1, 0xf6, 0xd0, 0x7c, 0x86, 0xba, 0xf7, 0x82,
  35736. 0xe7, 0x3d, 0x26, 0x37, 0xf0, 0x43, 0xd3, 0x41,
  35737. 0xa0, 0x09, 0x21, 0x85, 0x7d, 0x8b, 0x21, 0xdd,
  35738. 0xf3, 0xe1, 0xd6, 0x31, 0x00, 0x36, 0xed, 0x27,
  35739. 0xaf, 0x49, 0xe5, 0xde, 0x1b, 0x90, 0x0f, 0xe4,
  35740. 0xde, 0x79, 0x80, 0x8f, 0xf2, 0x9f, 0x95, 0x70,
  35741. 0x85, 0x96, 0x12, 0xb1, 0x5a, 0xdc, 0x01, 0xfb,
  35742. 0xb2, 0x65, 0xb3, 0x05, 0xb1, 0xe3, 0xa1, 0x2a,
  35743. 0xe4, 0x19, 0xda, 0x5b, 0x74, 0x26, 0x1f, 0xa2,
  35744. 0x84, 0xc1, 0x01, 0xda, 0x3d, 0x8d, 0xca, 0x8b,
  35745. 0x2e, 0x45, 0x21, 0xac, 0xa5, 0x71, 0xef, 0x44,
  35746. 0xa0, 0x58, 0xe8, 0x44, 0xff, 0x32, 0xb1, 0x6d,
  35747. 0x5a, 0xae, 0xa0, 0x5f, 0x7f, 0x3a, 0xf8, 0xe2,
  35748. 0xab, 0x16, 0x22, 0x2e, 0x34, 0x76, 0x62, 0xed,
  35749. 0xdf, 0xb8, 0x91, 0xd0, 0xec, 0xc2, 0xa5, 0x5c,
  35750. 0x56, 0x38, 0xf9, 0xdd, 0xe9, 0x2d, 0x9a, 0x3d,
  35751. 0x54, 0x4a, 0x5f, 0x90, 0x1a, 0xc5, 0x01, 0xac,
  35752. 0xd1, 0xea, 0x6a, 0x01, 0x02, 0x01, 0xfc, 0xb1,
  35753. 0x0a, 0xd7, 0x02, 0xc4, 0x25, 0xa9, 0x4b, 0xdf,
  35754. 0x58, 0x90, 0xd5, 0x00, 0xa2, 0xa1, 0x47, 0xee,
  35755. 0xe1, 0xd1, 0xfc, 0xba, 0x8c, 0x3a, 0xbe, 0x7c,
  35756. 0x2d, 0xfe, 0x70, 0xf3, 0x46, 0xf0, 0x33, 0xd8,
  35757. 0x16, 0xa0, 0xb2, 0x79, 0x1b, 0x4f, 0x0b, 0x2d,
  35758. 0x95, 0x6d, 0x9e, 0xe5, 0x97, 0x17, 0x15, 0x39,
  35759. 0x9a, 0x56, 0x88, 0x30, 0x24, 0x95, 0xe2, 0xe0,
  35760. 0x7c, 0x1c, 0x8c, 0x01, 0x52, 0x71, 0x84, 0xbc,
  35761. 0xd0, 0xc2, 0x08, 0xbc, 0x15, 0x9f, 0x2e, 0x13,
  35762. 0x31, 0x8c, 0x0b, 0xb3, 0xdd, 0x24, 0xa6, 0xa7,
  35763. 0xfc, 0x84, 0x9f, 0x83, 0x38, 0x5e, 0xd4, 0xdb,
  35764. 0xa0, 0x7f, 0xe1, 0xd7, 0xbd, 0x56, 0x40, 0xcc,
  35765. 0x9e, 0xd5, 0xcc, 0xfd, 0xd6, 0x87, 0x63, 0xcb,
  35766. 0x0d, 0x0e, 0xdf, 0x61, 0xb2, 0x92, 0x17, 0x7f,
  35767. 0xc1, 0xd2, 0xd3, 0xc1, 0x1d, 0xd0, 0x49, 0x50,
  35768. 0x56, 0xbc, 0xb1, 0x25, 0x58, 0xae, 0xbc, 0xfd,
  35769. 0xde, 0xf9, 0xfe, 0xb4, 0xae, 0xbc, 0x57, 0xaf,
  35770. 0xd9, 0x02, 0x3c, 0x65, 0xcf, 0xe6, 0x5a, 0x24,
  35771. 0xe3, 0x3f, 0x1b, 0x00, 0x11, 0x1e, 0x92, 0xe6,
  35772. 0x3e, 0x01, 0x1e, 0xaf, 0x0b, 0x21, 0x2c, 0xf9,
  35773. 0x57, 0x43, 0xcd, 0x07, 0xf5, 0x18, 0x9e, 0xce,
  35774. 0x1f, 0x20, 0x5b, 0x7f, 0x6f, 0xcb, 0x2e, 0x6b,
  35775. 0x19, 0x61, 0xb5, 0x40, 0x4c, 0xeb, 0xe4, 0x7c,
  35776. 0x8c, 0xd1, 0x3b, 0x85, 0x99, 0xd5, 0xb4, 0x9e,
  35777. 0x6d, 0x87, 0xee, 0xda, 0x36, 0xe9, 0xb8, 0xfc,
  35778. 0x4c, 0x00, 0x63, 0x58, 0x96, 0xaa, 0x2b, 0x75,
  35779. 0x89, 0x6e, 0x33, 0x6d, 0x1b, 0x61, 0x2e, 0xe1,
  35780. 0x3d, 0xb8, 0x11, 0xe1, 0xf0, 0x7e, 0x61, 0x74,
  35781. 0x8d, 0x92, 0x0f, 0x48, 0x65, 0xf3, 0xf1, 0x17,
  35782. 0x41, 0x39, 0x9d, 0xc6, 0x16, 0x2c, 0x91, 0xca,
  35783. 0x16, 0x8a, 0x02, 0x32, 0x9d, 0xff, 0x82, 0x1d,
  35784. 0x58, 0x19, 0x87, 0x12, 0xdd, 0x55, 0x8a, 0xbb,
  35785. 0x09, 0x9b, 0x3a, 0x0b, 0xaf, 0x9d, 0xa1, 0xb7,
  35786. 0x30, 0xb2, 0xaa, 0x73, 0xbc, 0xf5, 0x8d, 0x74,
  35787. 0xf3, 0x57, 0xb0, 0x6f, 0x72, 0x11, 0xc8, 0x04,
  35788. 0xb6, 0xc8, 0xaf, 0x16, 0xff, 0x35, 0x09, 0xfa,
  35789. 0xd1, 0xd3, 0x5b, 0x14, 0xbf, 0xdc, 0xed, 0x7d,
  35790. 0xb8, 0xa6, 0xa2, 0x5c, 0x48, 0xe5, 0x95, 0x64,
  35791. 0x80, 0x72, 0x4d, 0xaa, 0x05, 0x7c, 0xd6, 0x60,
  35792. 0xb6, 0x7e, 0xe3, 0xe4, 0x72, 0x57, 0x41, 0x82,
  35793. 0x67, 0x9d, 0x48, 0x58, 0x38, 0xa6, 0x47, 0x6e,
  35794. 0xac, 0x02, 0x14, 0x10, 0x75, 0xc8, 0x12, 0xaf,
  35795. 0x79, 0x67, 0xba, 0x7c, 0x91, 0x85, 0xcc, 0x2a,
  35796. 0xbd, 0x2a, 0x45, 0x45, 0xb8, 0x0f, 0x3d, 0x31,
  35797. 0x04, 0xd5, 0x8d, 0x65, 0x4a, 0x57, 0x79, 0x2d,
  35798. 0xcf, 0xab, 0xbe, 0x9c, 0x07, 0x15, 0xe8, 0xde,
  35799. 0x2e, 0xf8, 0x1e, 0xf4, 0x04, 0xc8, 0x16, 0x8f,
  35800. 0xd7, 0xa4, 0x3e, 0xfa, 0xb3, 0xd4, 0x48, 0xe6,
  35801. 0x86, 0xa0, 0x88, 0xef, 0xd2, 0x6a, 0x26, 0x15,
  35802. 0x99, 0x48, 0x92, 0x67, 0x23, 0xd7, 0xec, 0xcc,
  35803. 0x39, 0xe3, 0xc1, 0xb7, 0x19, 0xcf, 0x8b, 0xec,
  35804. 0xb7, 0xbe, 0x7e, 0x96, 0x4f, 0x22, 0xcd, 0x8c,
  35805. 0xb1, 0xb7, 0xe2, 0x5e, 0x80, 0x0e, 0xa9, 0x7d,
  35806. 0x60, 0xa6, 0x4c, 0xc0, 0xbb, 0xd9, 0xcb, 0x40,
  35807. 0x7a, 0x3a, 0xb9, 0xf8, 0x8f, 0x5e, 0x29, 0x16,
  35808. 0x9e, 0xea, 0xfd, 0x4e, 0x03, 0x22, 0xfd, 0xe6,
  35809. 0x59, 0x0a, 0xe0, 0x93, 0xce, 0x8f, 0xee, 0xae,
  35810. 0x98, 0xb6, 0x22, 0xca, 0xa7, 0x55, 0x6f, 0xf4,
  35811. 0x26, 0xc9, 0xe7, 0xa4, 0x04, 0xce, 0x69, 0x35,
  35812. 0x58, 0x30, 0xa7, 0xa6, 0x77, 0x67, 0xa7, 0x6c,
  35813. 0x7d, 0x9a, 0x97, 0xb8, 0x4b, 0xfc, 0xf5, 0x0a,
  35814. 0x02, 0xf7, 0x5c, 0x23, 0x5d, 0x2f, 0x9c, 0x67,
  35815. 0x11, 0x38, 0x04, 0x9f, 0xfc, 0x7c, 0x80, 0x55,
  35816. 0x92, 0x6c, 0x03, 0xeb, 0x3f, 0xb8, 0x7f, 0x96,
  35817. 0x95, 0x18, 0x5a, 0x42, 0xec, 0xa9, 0xa4, 0x16,
  35818. 0x55, 0x87, 0x3d, 0x30, 0xa6, 0xb3, 0xbf, 0x42,
  35819. 0x8b, 0x24, 0x62, 0x23, 0x48, 0x4a, 0x8f, 0xf6,
  35820. 0x1e, 0xe3, 0xee, 0xaf, 0xff, 0x10, 0xe9, 0x9c,
  35821. 0x2c, 0x13, 0xa7, 0x62, 0x84, 0xd0, 0x63, 0xe5,
  35822. 0x6a, 0xb7, 0x11, 0xa3, 0x5a, 0x85, 0xb5, 0x38,
  35823. 0x3d, 0xf8, 0x1d, 0xa2, 0x34, 0x90, 0xf6, 0x6e,
  35824. 0x8e, 0xa3, 0xfc, 0xba, 0x06, 0x7f, 0x55, 0x30,
  35825. 0xc6, 0x54, 0x1c, 0x2b, 0x8f, 0x74, 0x71, 0x7c,
  35826. 0x35, 0x02, 0x3e, 0x7b, 0x9b, 0x39, 0x56, 0xc3,
  35827. 0xee, 0x2f, 0xf8, 0x4b, 0xa0, 0x3c, 0xcf, 0x4b,
  35828. 0x4b, 0x53, 0x21, 0xb9, 0x24, 0x08, 0x95, 0x48,
  35829. 0x1b, 0xc6, 0xd6, 0x3c, 0x16, 0x93, 0xc1, 0x84,
  35830. 0x78, 0x52, 0xf8, 0xe9, 0x7f, 0x50, 0xa1, 0x33,
  35831. 0x53, 0x2a, 0xc3, 0xee, 0x1e, 0x52, 0xd4, 0x64
  35832. #endif
  35833. };
  35834. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ss[] = {
  35835. #ifdef WOLFSSL_KYBER_ORIGINAL
  35836. 0x91, 0x4C, 0xB6, 0x7F, 0xE5, 0xC3, 0x8E, 0x73,
  35837. 0xBF, 0x74, 0x18, 0x1C, 0x0A, 0xC5, 0x04, 0x28,
  35838. 0xDE, 0xDF, 0x77, 0x50, 0xA9, 0x80, 0x58, 0xF7,
  35839. 0xD5, 0x36, 0x70, 0x87, 0x74, 0x53, 0x5B, 0x29
  35840. #else
  35841. 0xe7, 0x18, 0x4a, 0x09, 0x75, 0xee, 0x34, 0x70,
  35842. 0x87, 0x8d, 0x2d, 0x15, 0x9e, 0xc8, 0x31, 0x29,
  35843. 0xc8, 0xae, 0xc2, 0x53, 0xd4, 0xee, 0x17, 0xb4,
  35844. 0x81, 0x03, 0x11, 0xd1, 0x98, 0xcd, 0x03, 0x68
  35845. #endif
  35846. };
  35847. #ifdef WOLFSSL_SMALL_STACK
  35848. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  35849. DYNAMIC_TYPE_TMP_BUFFER);
  35850. priv = (byte *)XMALLOC(KYBER768_PRIVATE_KEY_SIZE, HEAP_HINT,
  35851. DYNAMIC_TYPE_TMP_BUFFER);
  35852. pub = (byte *)XMALLOC(KYBER768_PUBLIC_KEY_SIZE, HEAP_HINT,
  35853. DYNAMIC_TYPE_TMP_BUFFER);
  35854. ct = (byte *)XMALLOC(KYBER768_CIPHER_TEXT_SIZE, HEAP_HINT,
  35855. DYNAMIC_TYPE_TMP_BUFFER);
  35856. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  35857. DYNAMIC_TYPE_TMP_BUFFER);
  35858. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  35859. DYNAMIC_TYPE_TMP_BUFFER);
  35860. if (! (key && priv && pub && ct && ss && ss_dec))
  35861. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  35862. #endif
  35863. ret = wc_KyberKey_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
  35864. if (ret != 0)
  35865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35866. else
  35867. key_inited = 1;
  35868. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  35869. sizeof(kyber768_rand));
  35870. if (ret != 0)
  35871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35872. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
  35873. if (ret != 0)
  35874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35875. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
  35876. if (ret != 0)
  35877. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35878. if (XMEMCMP(pub, kyber768_pk, sizeof(kyber768_pk)) != 0)
  35879. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35880. if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0)
  35881. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35882. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  35883. sizeof(kyber768enc_rand));
  35884. if (ret != 0)
  35885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35886. if (XMEMCMP(ct, kyber768_ct, sizeof(kyber768_ct)) != 0)
  35887. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35888. if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0)
  35889. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35890. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
  35891. if (ret != 0)
  35892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  35893. if (XMEMCMP(ss_dec, kyber768_ss, sizeof(kyber768_ss)) != 0)
  35894. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  35895. out:
  35896. if (key_inited)
  35897. wc_KyberKey_Free(key);
  35898. #ifdef WOLFSSL_SMALL_STACK
  35899. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35900. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35901. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35902. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35903. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35904. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  35905. #endif
  35906. return ret;
  35907. }
  35908. #endif /* WOLFSSL_KYBER768 */
  35909. #ifdef WOLFSSL_KYBER1024
  35910. static wc_test_ret_t kyber1024_kat(void)
  35911. {
  35912. wc_test_ret_t ret;
  35913. #ifdef WOLFSSL_SMALL_STACK
  35914. KyberKey *key = NULL;
  35915. byte *priv = NULL;
  35916. byte *pub = NULL;
  35917. byte *ct = NULL;
  35918. byte *ss = NULL;
  35919. byte *ss_dec = NULL;
  35920. #else
  35921. KyberKey key[1];
  35922. byte priv[KYBER1024_PRIVATE_KEY_SIZE];
  35923. byte pub[KYBER1024_PUBLIC_KEY_SIZE];
  35924. byte ct[KYBER1024_CIPHER_TEXT_SIZE];
  35925. byte ss[KYBER_SS_SZ];
  35926. byte ss_dec[KYBER_SS_SZ];
  35927. #endif
  35928. int key_inited = 0;
  35929. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_rand[] = {
  35930. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  35931. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  35932. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  35933. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  35934. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35935. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35936. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35937. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35938. };
  35939. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024enc_rand[] = {
  35940. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  35941. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  35942. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  35943. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  35944. };
  35945. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_pk[] = {
  35946. #ifdef WOLFSSL_KYBER_ORIGINAL
  35947. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  35948. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  35949. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  35950. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  35951. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  35952. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  35953. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  35954. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  35955. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  35956. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  35957. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  35958. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  35959. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  35960. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  35961. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  35962. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  35963. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  35964. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  35965. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  35966. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  35967. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  35968. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  35969. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  35970. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  35971. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  35972. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  35973. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  35974. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  35975. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  35976. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  35977. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  35978. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  35979. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  35980. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  35981. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  35982. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  35983. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  35984. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  35985. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  35986. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  35987. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  35988. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  35989. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  35990. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  35991. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  35992. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  35993. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  35994. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  35995. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  35996. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  35997. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  35998. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  35999. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36000. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36001. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36002. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36003. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36004. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36005. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36006. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36007. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36008. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36009. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36010. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36011. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36012. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36013. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36014. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36015. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36016. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36017. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36018. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36019. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36020. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36021. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36022. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36023. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36024. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36025. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36026. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36027. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36028. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36029. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36030. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36031. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36032. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36033. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36034. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36035. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36036. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36037. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36038. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36039. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36040. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36041. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36042. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36043. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36044. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36045. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36046. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36047. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36048. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36049. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36050. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36051. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36052. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36053. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36054. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36055. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36056. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36057. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36058. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36059. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36060. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36061. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36062. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36063. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36064. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36065. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36066. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36067. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36068. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36069. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36070. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36071. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36072. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36073. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36074. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36075. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36076. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36077. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36078. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36079. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36080. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36081. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36082. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36083. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36084. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36085. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36086. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36087. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36088. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36089. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36090. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36091. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36092. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36093. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36094. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36095. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36096. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36097. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36098. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36099. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36100. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36101. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36102. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36103. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36104. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36105. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36106. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36107. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36108. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36109. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36110. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36111. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36112. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36113. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36114. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36115. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36116. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36117. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36118. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36119. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36120. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36121. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36122. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36123. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36124. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36125. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36126. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36127. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36128. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36129. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36130. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36131. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36132. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36133. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36134. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36135. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36136. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36137. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36138. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36139. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36140. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36141. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36142. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  36143. #else
  36144. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36145. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36146. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36147. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36148. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36149. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36150. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36151. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36152. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36153. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36154. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36155. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36156. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36157. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36158. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36159. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36160. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36161. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36162. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36163. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36164. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36165. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36166. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36167. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36168. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36169. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36170. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36171. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36172. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36173. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36174. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36175. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36176. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36177. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36178. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36179. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36180. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36181. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36182. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36183. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36184. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36185. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36186. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36187. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36188. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36189. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36190. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36191. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36192. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36193. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36194. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36195. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36196. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36197. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36198. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36199. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36200. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36201. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36202. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36203. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36204. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36205. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36206. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36207. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36208. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36209. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36210. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  36211. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  36212. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  36213. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  36214. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  36215. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  36216. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  36217. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  36218. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  36219. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  36220. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  36221. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  36222. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  36223. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  36224. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  36225. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  36226. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  36227. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  36228. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  36229. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  36230. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  36231. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  36232. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  36233. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  36234. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  36235. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  36236. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  36237. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  36238. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  36239. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  36240. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  36241. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  36242. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  36243. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  36244. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  36245. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  36246. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  36247. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  36248. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  36249. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  36250. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  36251. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  36252. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  36253. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  36254. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  36255. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  36256. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  36257. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  36258. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  36259. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  36260. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  36261. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  36262. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  36263. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  36264. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  36265. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  36266. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  36267. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  36268. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  36269. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  36270. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  36271. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  36272. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  36273. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  36274. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  36275. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  36276. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  36277. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  36278. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  36279. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  36280. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  36281. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  36282. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  36283. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  36284. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  36285. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  36286. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  36287. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  36288. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  36289. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  36290. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  36291. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  36292. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  36293. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  36294. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  36295. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  36296. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  36297. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  36298. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  36299. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  36300. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  36301. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  36302. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  36303. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  36304. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  36305. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  36306. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  36307. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  36308. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  36309. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  36310. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  36311. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  36312. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  36313. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  36314. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  36315. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  36316. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  36317. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  36318. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  36319. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  36320. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  36321. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  36322. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  36323. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  36324. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  36325. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  36326. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  36327. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  36328. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  36329. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  36330. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  36331. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  36332. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  36333. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  36334. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  36335. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  36336. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  36337. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  36338. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  36339. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb
  36340. #endif
  36341. };
  36342. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_sk[] = {
  36343. #ifdef WOLFSSL_KYBER_ORIGINAL
  36344. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  36345. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  36346. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  36347. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  36348. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  36349. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  36350. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  36351. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  36352. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  36353. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  36354. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  36355. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  36356. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  36357. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  36358. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  36359. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  36360. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  36361. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  36362. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  36363. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  36364. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  36365. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  36366. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  36367. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  36368. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  36369. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  36370. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  36371. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  36372. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  36373. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  36374. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  36375. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  36376. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  36377. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  36378. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  36379. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  36380. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  36381. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  36382. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  36383. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  36384. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  36385. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  36386. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  36387. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  36388. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  36389. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  36390. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  36391. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  36392. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  36393. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  36394. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  36395. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  36396. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  36397. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  36398. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  36399. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  36400. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  36401. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  36402. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  36403. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  36404. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  36405. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  36406. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  36407. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  36408. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  36409. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  36410. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  36411. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  36412. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  36413. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  36414. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  36415. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  36416. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  36417. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  36418. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  36419. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  36420. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  36421. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  36422. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  36423. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  36424. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  36425. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  36426. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  36427. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  36428. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  36429. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  36430. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  36431. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  36432. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  36433. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  36434. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  36435. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  36436. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  36437. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  36438. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  36439. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  36440. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  36441. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  36442. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  36443. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  36444. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  36445. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  36446. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  36447. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  36448. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  36449. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  36450. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  36451. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  36452. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  36453. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  36454. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  36455. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  36456. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  36457. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  36458. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  36459. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  36460. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  36461. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  36462. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  36463. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  36464. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  36465. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  36466. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  36467. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  36468. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  36469. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  36470. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  36471. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  36472. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  36473. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  36474. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  36475. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  36476. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  36477. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  36478. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  36479. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  36480. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  36481. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  36482. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  36483. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  36484. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  36485. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  36486. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  36487. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  36488. 0x85, 0xA4, 0xC1, 0xA1, 0xAB, 0x9B, 0x6A, 0xEB,
  36489. 0x49, 0xCC, 0xE1, 0xC2, 0xF8, 0xA9, 0x7C, 0x35,
  36490. 0x16, 0xC7, 0x2A, 0x00, 0xA4, 0x62, 0x63, 0xBA,
  36491. 0xA6, 0x96, 0xBF, 0x25, 0x72, 0x77, 0x19, 0xC3,
  36492. 0x21, 0x64, 0x23, 0x61, 0x8F, 0xF3, 0x33, 0x80,
  36493. 0x93, 0x4A, 0x6C, 0x10, 0x54, 0x5C, 0x4C, 0x5C,
  36494. 0x51, 0x55, 0xB1, 0x24, 0x86, 0x18, 0x1F, 0xC7,
  36495. 0xA2, 0x31, 0x98, 0x73, 0x97, 0x8B, 0x6A, 0x2A,
  36496. 0x67, 0x49, 0x0F, 0x82, 0x56, 0xBD, 0x21, 0x96,
  36497. 0xFE, 0x17, 0x92, 0xA4, 0xC0, 0x00, 0x77, 0xB8,
  36498. 0x12, 0xEA, 0xE8, 0xBE, 0xD3, 0x57, 0x24, 0x99,
  36499. 0x68, 0x4A, 0xB3, 0x37, 0x18, 0x76, 0x76, 0x1E,
  36500. 0x45, 0x0C, 0x9F, 0x9D, 0x27, 0x68, 0xA3, 0x68,
  36501. 0x06, 0xD7, 0xAB, 0x20, 0x46, 0xC9, 0x1F, 0x17,
  36502. 0x59, 0x9E, 0x9A, 0xC5, 0x92, 0x99, 0x08, 0x08,
  36503. 0xDC, 0xD7, 0xB4, 0xD0, 0x91, 0x90, 0x72, 0xF1,
  36504. 0x4E, 0xC3, 0x61, 0x77, 0x3B, 0x72, 0x52, 0x44,
  36505. 0x4C, 0x32, 0x3C, 0x30, 0x83, 0x26, 0xF4, 0xA3,
  36506. 0x0F, 0x86, 0x80, 0xD2, 0xF7, 0x48, 0xF5, 0x6A,
  36507. 0x13, 0x2B, 0x82, 0x67, 0x4E, 0xD0, 0x18, 0x46,
  36508. 0x20, 0xB8, 0x2A, 0xD2, 0xCB, 0x18, 0x2C, 0x97,
  36509. 0xB4, 0x81, 0x62, 0x66, 0x47, 0x49, 0x12, 0x90,
  36510. 0xA0, 0x11, 0xCC, 0x73, 0x82, 0x86, 0x85, 0xA8,
  36511. 0xC3, 0x67, 0xA5, 0xB9, 0xCF, 0x8D, 0x62, 0x1B,
  36512. 0x0D, 0x5C, 0x1E, 0xFF, 0x03, 0x17, 0x27, 0x58,
  36513. 0xBD, 0x00, 0x49, 0x78, 0xC2, 0x51, 0xCD, 0x51,
  36514. 0x34, 0x22, 0x28, 0x98, 0x9C, 0xAE, 0x63, 0x32,
  36515. 0xAC, 0x48, 0x64, 0x37, 0xCB, 0x5C, 0x57, 0xD4,
  36516. 0x30, 0x74, 0x62, 0x86, 0x52, 0x53, 0xBE, 0x21,
  36517. 0x7B, 0x35, 0x15, 0xC7, 0x3D, 0xF4, 0x05, 0xB7,
  36518. 0xF2, 0x82, 0x17, 0xAD, 0x0B, 0x8C, 0xF6, 0x0C,
  36519. 0x2F, 0xFF, 0xAA, 0x0A, 0x00, 0x48, 0xB1, 0xFB,
  36520. 0x4A, 0xCD, 0xCD, 0xC3, 0x8B, 0x52, 0x50, 0xCF,
  36521. 0xEC, 0x35, 0x6A, 0x6D, 0xE2, 0x6C, 0xFA, 0x7A,
  36522. 0x58, 0x8F, 0xDC, 0x86, 0xF9, 0x8C, 0x85, 0x4A,
  36523. 0xC6, 0x4C, 0x7B, 0xFA, 0xA9, 0x6F, 0x5A, 0x32,
  36524. 0xCC, 0x06, 0x10, 0x93, 0x4B, 0xAA, 0x6A, 0x58,
  36525. 0x6B, 0x9A, 0x20, 0x54, 0xF1, 0x3B, 0xA2, 0x74,
  36526. 0x17, 0x4A, 0xA0, 0xD2, 0xB3, 0xA8, 0x1B, 0x96,
  36527. 0xA9, 0x40, 0x66, 0x6F, 0x78, 0x9B, 0x5A, 0x6B,
  36528. 0xCD, 0xC0, 0xA6, 0xA0, 0x17, 0x8A, 0x0C, 0x9A,
  36529. 0x02, 0x57, 0x8A, 0x49, 0x3F, 0x6E, 0xEA, 0x0D,
  36530. 0x2E, 0x6C, 0x13, 0x95, 0x1C, 0x9F, 0x24, 0x9A,
  36531. 0x5E, 0x8D, 0xD7, 0x1D, 0xD4, 0x9A, 0x74, 0x2D,
  36532. 0x45, 0x1F, 0x1A, 0xBB, 0xA1, 0x9A, 0xF8, 0xC5,
  36533. 0x47, 0x85, 0x5E, 0x0A, 0xFC, 0x72, 0x8E, 0x90,
  36534. 0xAB, 0xB4, 0x99, 0xC9, 0xBE, 0xEB, 0x76, 0x6F,
  36535. 0x47, 0x29, 0xCD, 0xA2, 0x22, 0x63, 0xE3, 0x24,
  36536. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36537. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36538. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36539. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36540. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36541. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36542. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36543. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36544. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36545. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36546. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36547. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36548. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36549. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36550. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36551. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36552. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36553. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36554. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36555. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36556. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36557. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36558. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36559. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36560. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36561. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36562. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36563. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36564. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36565. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36566. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36567. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36568. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36569. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36570. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36571. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36572. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36573. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36574. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36575. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36576. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36577. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36578. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36579. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36580. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36581. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36582. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  36583. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  36584. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  36585. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  36586. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  36587. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  36588. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36589. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36590. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36591. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36592. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36593. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36594. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36595. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36596. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36597. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36598. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36599. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36600. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36601. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36602. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36603. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36604. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36605. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36606. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36607. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36608. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36609. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36610. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36611. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36612. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36613. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36614. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36615. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36616. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36617. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36618. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36619. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36620. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36621. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36622. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36623. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36624. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36625. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36626. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36627. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36628. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36629. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36630. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36631. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36632. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36633. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36634. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36635. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36636. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36637. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36638. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36639. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36640. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36641. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36642. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36643. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36644. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36645. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36646. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36647. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36648. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36649. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36650. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36651. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36652. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36653. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36654. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36655. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36656. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36657. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36658. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36659. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36660. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36661. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36662. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36663. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36664. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36665. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36666. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36667. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36668. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36669. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36670. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36671. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36672. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36673. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36674. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36675. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36676. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36677. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36678. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36679. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36680. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36681. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36682. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36683. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36684. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36685. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36686. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36687. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36688. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36689. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36690. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36691. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36692. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36693. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36694. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36695. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36696. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36697. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36698. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36699. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36700. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36701. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36702. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36703. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36704. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36705. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36706. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36707. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36708. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36709. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36710. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36711. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36712. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36713. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36714. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36715. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36716. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36717. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36718. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36719. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36720. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36721. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36722. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36723. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36724. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36725. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36726. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36727. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36728. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36729. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36730. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36731. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  36732. 0x8A, 0x39, 0xE8, 0x7D, 0x53, 0x1F, 0x35, 0x27,
  36733. 0xC2, 0x07, 0xED, 0xCC, 0x1D, 0xB7, 0xFA, 0xDD,
  36734. 0xCF, 0x96, 0x28, 0x39, 0x18, 0x79, 0xB3, 0x35,
  36735. 0xC7, 0x07, 0x83, 0x9A, 0x0D, 0xB0, 0x51, 0xA8,
  36736. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  36737. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  36738. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  36739. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  36740. #else
  36741. 0x43, 0x3a, 0x70, 0xee, 0x69, 0x50, 0xf9, 0x88,
  36742. 0x2a, 0xcd, 0xd5, 0xa4, 0x78, 0x20, 0xa6, 0xa8,
  36743. 0x16, 0x37, 0x08, 0xf0, 0x4d, 0x45, 0x7c, 0x77,
  36744. 0x99, 0x79, 0xb8, 0x3f, 0xe1, 0x17, 0x22, 0x47,
  36745. 0x01, 0x49, 0x08, 0x30, 0x38, 0x66, 0x37, 0xda,
  36746. 0x33, 0x2e, 0x74, 0xb1, 0xae, 0xda, 0x0b, 0x2f,
  36747. 0x81, 0xca, 0x4f, 0x9b, 0xb2, 0xc2, 0xb0, 0x2b,
  36748. 0x0c, 0xfd, 0x68, 0x0c, 0x11, 0x48, 0x2f, 0x33,
  36749. 0x5a, 0xcf, 0x7b, 0x91, 0x39, 0xb5, 0xb8, 0x8a,
  36750. 0x34, 0xe3, 0x54, 0x2c, 0x68, 0x61, 0x37, 0x75,
  36751. 0x45, 0x98, 0x33, 0x43, 0xcd, 0x82, 0x94, 0x14,
  36752. 0xe4, 0x78, 0x64, 0x21, 0x2e, 0x78, 0xf8, 0x55,
  36753. 0xf5, 0x23, 0x90, 0x37, 0x9a, 0xcc, 0x3a, 0x62,
  36754. 0x95, 0x31, 0x31, 0xb6, 0x3e, 0xe8, 0x32, 0xad,
  36755. 0xb3, 0xbf, 0x4b, 0xf5, 0x8e, 0x24, 0x73, 0x49,
  36756. 0xb5, 0xe0, 0x97, 0xe5, 0x5a, 0xbe, 0x49, 0x7b,
  36757. 0x15, 0x98, 0x23, 0x73, 0xae, 0x73, 0x2e, 0x04,
  36758. 0x39, 0xac, 0x67, 0xd0, 0x5c, 0x7f, 0x03, 0x7c,
  36759. 0x8a, 0x73, 0x9b, 0x18, 0x14, 0x0e, 0x14, 0x4c,
  36760. 0x85, 0x1d, 0xc9, 0x61, 0x1f, 0x4b, 0xcf, 0x04,
  36761. 0xf3, 0xa2, 0x09, 0x3c, 0x19, 0x7b, 0xd6, 0x3b,
  36762. 0xb5, 0xe6, 0x19, 0x01, 0x00, 0x54, 0x5f, 0xf8,
  36763. 0x1d, 0xb7, 0xfc, 0xcd, 0xdd, 0x9a, 0x32, 0x4b,
  36764. 0x0b, 0xac, 0x3c, 0x2c, 0x23, 0x82, 0x28, 0x40,
  36765. 0x58, 0xf0, 0x8b, 0x96, 0x19, 0x52, 0xc0, 0x94,
  36766. 0x01, 0x9c, 0x10, 0xbe, 0x37, 0xa5, 0x3d, 0x5a,
  36767. 0xc7, 0x94, 0xc0, 0x10, 0xa9, 0xd0, 0x82, 0x1f,
  36768. 0x15, 0x02, 0x7a, 0x1c, 0x41, 0x9c, 0x3c, 0x71,
  36769. 0xc9, 0xa1, 0xd2, 0x8a, 0xed, 0x02, 0x59, 0x7a,
  36770. 0xb7, 0x9b, 0x87, 0x53, 0x94, 0x62, 0x6b, 0xa3,
  36771. 0x9a, 0xdc, 0x09, 0x0c, 0x3a, 0x90, 0xcf, 0x75,
  36772. 0x87, 0x1a, 0x65, 0x27, 0x5e, 0xb1, 0xc5, 0xb0,
  36773. 0x33, 0x72, 0xe1, 0x3a, 0x1a, 0x23, 0xd0, 0xcf,
  36774. 0x93, 0x74, 0x11, 0x1f, 0x80, 0xcc, 0x83, 0xa9,
  36775. 0x05, 0x62, 0x2b, 0x83, 0xfc, 0x51, 0x39, 0x71,
  36776. 0xec, 0x84, 0x19, 0xf0, 0x88, 0x0c, 0x30, 0x67,
  36777. 0x63, 0x36, 0x71, 0xb0, 0x9b, 0x54, 0x56, 0xab,
  36778. 0x60, 0x57, 0x93, 0x6d, 0x19, 0xa4, 0xa2, 0xa2,
  36779. 0x67, 0x91, 0x1b, 0x00, 0x0a, 0x13, 0x95, 0x6f,
  36780. 0xbd, 0x49, 0x38, 0x21, 0xda, 0x07, 0x2c, 0x04,
  36781. 0x64, 0x2b, 0x0c, 0x20, 0xda, 0x6c, 0xc0, 0xd9,
  36782. 0xd8, 0x64, 0xa3, 0x93, 0x65, 0xdf, 0xd6, 0x4f,
  36783. 0x10, 0x18, 0x78, 0x25, 0xfa, 0x33, 0x25, 0x07,
  36784. 0x49, 0xcb, 0xc0, 0xc9, 0x05, 0xd7, 0xb1, 0xff,
  36785. 0x3c, 0xae, 0x24, 0x12, 0xbf, 0x86, 0xb8, 0x1a,
  36786. 0x81, 0x7b, 0x86, 0xba, 0xa3, 0x0e, 0xdf, 0x78,
  36787. 0x62, 0xe5, 0xf6, 0xba, 0xc9, 0x87, 0x26, 0xe5,
  36788. 0x6b, 0x3c, 0xec, 0x60, 0x66, 0x4c, 0xaa, 0x2a,
  36789. 0x7d, 0xf6, 0x70, 0xc5, 0xe2, 0x07, 0xdf, 0xac,
  36790. 0x03, 0x82, 0x4c, 0x89, 0x89, 0x7c, 0xb4, 0x90,
  36791. 0xea, 0xa7, 0x65, 0x21, 0x22, 0x2c, 0x86, 0x20,
  36792. 0x51, 0x69, 0xc9, 0x1c, 0x32, 0x9c, 0x4a, 0x18,
  36793. 0x4d, 0x78, 0x72, 0x1a, 0xf8, 0x36, 0xad, 0x4d,
  36794. 0xb0, 0xca, 0x78, 0x46, 0x4d, 0x41, 0x71, 0x47,
  36795. 0x30, 0x12, 0xb7, 0xd1, 0x83, 0xba, 0xfa, 0x62,
  36796. 0x75, 0x85, 0xc6, 0x4b, 0xe3, 0x80, 0x9d, 0x7e,
  36797. 0x60, 0x04, 0xcb, 0xdc, 0x79, 0xa5, 0x46, 0x0f,
  36798. 0x0a, 0xd6, 0x77, 0xcb, 0x71, 0x65, 0x12, 0x40,
  36799. 0x7d, 0x3a, 0x61, 0x9a, 0xd0, 0x95, 0x43, 0xb7,
  36800. 0x39, 0x54, 0x74, 0x72, 0xa7, 0x06, 0xb3, 0x17,
  36801. 0xa5, 0x09, 0xbe, 0x5d, 0x86, 0x1f, 0xd6, 0x6c,
  36802. 0x7d, 0x0e, 0xd9, 0x4c, 0xd5, 0x00, 0x47, 0x95,
  36803. 0xc1, 0x81, 0x59, 0xe3, 0xa3, 0x3d, 0x79, 0x87,
  36804. 0x11, 0x52, 0x5f, 0x16, 0x35, 0xa6, 0x84, 0x28,
  36805. 0x17, 0x29, 0x23, 0x24, 0x96, 0x35, 0xaa, 0xd0,
  36806. 0x32, 0xb9, 0xe5, 0x66, 0x64, 0xbd, 0xd4, 0x8e,
  36807. 0xd2, 0x4a, 0xc7, 0x5c, 0x64, 0x68, 0xd1, 0x90,
  36808. 0x3e, 0x47, 0x10, 0x86, 0xc5, 0xf1, 0x56, 0x7e,
  36809. 0x83, 0x1a, 0x05, 0x08, 0xc5, 0x39, 0x63, 0x25,
  36810. 0x91, 0xab, 0x57, 0x7d, 0x32, 0x4a, 0x82, 0x42,
  36811. 0x97, 0x25, 0x80, 0x99, 0x50, 0x76, 0x1d, 0x84,
  36812. 0x34, 0x28, 0x8c, 0x14, 0x03, 0x4f, 0x1c, 0x06,
  36813. 0xc1, 0xd0, 0xaa, 0xe0, 0x9a, 0x71, 0xc7, 0x40,
  36814. 0xa5, 0x57, 0x01, 0xc2, 0x8f, 0xf8, 0x44, 0x99,
  36815. 0xf2, 0xbb, 0x18, 0xb6, 0x62, 0x8c, 0xaa, 0xa3,
  36816. 0xfe, 0x75, 0xac, 0x4d, 0xe0, 0x4c, 0x6f, 0x91,
  36817. 0x39, 0x00, 0xd8, 0x6c, 0x88, 0x12, 0x62, 0x52,
  36818. 0xa1, 0x7c, 0x4d, 0x30, 0x39, 0x91, 0xdb, 0x02,
  36819. 0x87, 0x12, 0x08, 0x81, 0xbb, 0x88, 0x47, 0x8a,
  36820. 0xaa, 0x9a, 0xf9, 0xbc, 0x53, 0xd3, 0x72, 0x98,
  36821. 0x43, 0x85, 0x8f, 0xdb, 0x46, 0x48, 0x05, 0x9c,
  36822. 0xac, 0x82, 0xc1, 0xa1, 0x08, 0x78, 0xba, 0x39,
  36823. 0x82, 0x3b, 0x04, 0x1b, 0xd0, 0xe2, 0x58, 0x48,
  36824. 0x7b, 0x56, 0xcc, 0x8a, 0x32, 0x20, 0xc1, 0xa5,
  36825. 0x8b, 0xf6, 0x6a, 0x17, 0x2b, 0x5b, 0x9a, 0x0c,
  36826. 0x63, 0x2d, 0x67, 0x4e, 0xae, 0x88, 0x5a, 0x01,
  36827. 0x5c, 0x4e, 0x37, 0xba, 0x07, 0x36, 0x80, 0xbe,
  36828. 0xde, 0x75, 0x34, 0xf3, 0xe3, 0x4b, 0x60, 0x50,
  36829. 0xc8, 0x6b, 0x21, 0xc3, 0xc0, 0x90, 0x94, 0x1f,
  36830. 0x23, 0xb7, 0xf6, 0x73, 0x1e, 0x2b, 0xda, 0x0e,
  36831. 0x6e, 0xa4, 0x64, 0x67, 0x71, 0xce, 0xc5, 0x72,
  36832. 0xb9, 0x8c, 0xa0, 0xa1, 0x58, 0x91, 0x9a, 0xdb,
  36833. 0xeb, 0x84, 0xce, 0x58, 0x5f, 0xf9, 0xf2, 0x5e,
  36834. 0xbd, 0xda, 0x6c, 0xb6, 0xf0, 0x7a, 0x8f, 0x81,
  36835. 0x12, 0x32, 0x60, 0x7e, 0x72, 0x17, 0xbb, 0x03,
  36836. 0x9b, 0xab, 0xd0, 0xd9, 0x19, 0x34, 0xa8, 0x59,
  36837. 0x40, 0x59, 0xc9, 0x68, 0x77, 0x23, 0xc0, 0x43,
  36838. 0x81, 0xbf, 0xd6, 0x27, 0xa1, 0x05, 0x17, 0xf5,
  36839. 0xf4, 0xbf, 0xc7, 0x77, 0x77, 0xaa, 0x26, 0x71,
  36840. 0xae, 0x12, 0x4f, 0x2b, 0x7a, 0x5f, 0x4d, 0x56,
  36841. 0x14, 0x02, 0x91, 0x97, 0xe6, 0x58, 0x6f, 0xa8,
  36842. 0xc1, 0x7e, 0x0a, 0xd9, 0x07, 0x81, 0xbc, 0x7b,
  36843. 0xb1, 0x9a, 0x77, 0x2d, 0x5a, 0x4e, 0xfe, 0x32,
  36844. 0xca, 0xc8, 0x9b, 0x76, 0xc4, 0x2a, 0x5e, 0xde,
  36845. 0x9b, 0xcc, 0x20, 0xc1, 0x89, 0x8c, 0x08, 0xa5,
  36846. 0xb0, 0xc0, 0x7e, 0x47, 0x8b, 0x1b, 0xbc, 0x22,
  36847. 0x6e, 0xfa, 0xd1, 0x5f, 0x2a, 0xc7, 0x37, 0x51,
  36848. 0x4b, 0x8c, 0x61, 0x49, 0x81, 0x07, 0x79, 0x22,
  36849. 0x24, 0x16, 0x53, 0x7e, 0xd0, 0x0d, 0xae, 0xab,
  36850. 0x17, 0x7e, 0x90, 0x3e, 0xad, 0x6b, 0x4a, 0xc4,
  36851. 0x23, 0x70, 0xaf, 0x1b, 0x1f, 0x50, 0xeb, 0xaf,
  36852. 0xaa, 0x1c, 0x6e, 0x64, 0x7b, 0xba, 0xcc, 0xe7,
  36853. 0x2c, 0x7d, 0x0b, 0x88, 0xae, 0xb0, 0xb0, 0x6f,
  36854. 0xc1, 0xa4, 0x54, 0x57, 0xa9, 0xc1, 0x87, 0x57,
  36855. 0x9b, 0xf1, 0x84, 0x57, 0x9c, 0xc3, 0x51, 0xc4,
  36856. 0x3d, 0xff, 0x94, 0x26, 0x05, 0xaa, 0x56, 0x04,
  36857. 0xfc, 0x85, 0xfc, 0x55, 0x83, 0xf6, 0xf1, 0x49,
  36858. 0x6f, 0xe6, 0x1d, 0x70, 0xd6, 0xcd, 0xe2, 0x32,
  36859. 0x7f, 0xee, 0x71, 0x3d, 0x86, 0xf2, 0x9b, 0x3a,
  36860. 0xfc, 0xbb, 0x54, 0xe9, 0xa9, 0x2a, 0x33, 0xa6,
  36861. 0xc1, 0xea, 0x6f, 0xfa, 0x30, 0x95, 0x66, 0xb0,
  36862. 0x68, 0x62, 0x33, 0xc0, 0xf3, 0xb1, 0xc3, 0x14,
  36863. 0x48, 0x90, 0xe4, 0xf0, 0x82, 0x9a, 0x60, 0x99,
  36864. 0xc5, 0x74, 0x9c, 0xde, 0xc8, 0x43, 0x28, 0xec,
  36865. 0x2c, 0xb6, 0x4a, 0x73, 0x85, 0xa7, 0x61, 0xd6,
  36866. 0x4b, 0x3a, 0x23, 0xc4, 0x89, 0x34, 0x33, 0x43,
  36867. 0xb9, 0x77, 0x23, 0xae, 0x78, 0xc7, 0xd8, 0x05,
  36868. 0x45, 0x8e, 0x16, 0x20, 0xf0, 0x29, 0x28, 0x97,
  36869. 0x69, 0x17, 0x04, 0xcb, 0x76, 0xe3, 0xb0, 0xb2,
  36870. 0x81, 0xa8, 0x3c, 0xf6, 0x44, 0x90, 0x49, 0x8c,
  36871. 0xbc, 0xaf, 0x04, 0x80, 0x24, 0x16, 0xb3, 0x3c,
  36872. 0x56, 0x51, 0x71, 0xd7, 0x72, 0xd3, 0xb9, 0x35,
  36873. 0x40, 0x37, 0x58, 0x76, 0x29, 0xae, 0x14, 0xa5,
  36874. 0xc5, 0x03, 0x1a, 0xc3, 0x66, 0x71, 0xa0, 0xd0,
  36875. 0xc9, 0x1c, 0xc0, 0xb4, 0xcd, 0x69, 0xd8, 0x40,
  36876. 0x2e, 0x33, 0xb9, 0xbc, 0xc2, 0xbb, 0xaf, 0x6b,
  36877. 0x97, 0x1e, 0x30, 0x3f, 0xa1, 0x37, 0xbe, 0x23,
  36878. 0x25, 0x98, 0xa4, 0x99, 0x9b, 0xc0, 0x12, 0x57,
  36879. 0x4c, 0x81, 0x65, 0x1b, 0x38, 0xb3, 0x83, 0x96,
  36880. 0xc1, 0xc3, 0x65, 0x30, 0x3a, 0xd2, 0x5d, 0x49,
  36881. 0xfc, 0x6b, 0x68, 0x99, 0x51, 0xa1, 0xcc, 0x4c,
  36882. 0x60, 0x07, 0x61, 0x30, 0x65, 0x49, 0x5f, 0x97,
  36883. 0x91, 0x0f, 0x97, 0x35, 0xd4, 0xea, 0x4e, 0x44,
  36884. 0x2a, 0xcb, 0x2f, 0xab, 0xae, 0xcf, 0xe1, 0xad,
  36885. 0xef, 0x06, 0x67, 0xba, 0x42, 0x2c, 0x95, 0x4a,
  36886. 0x05, 0xd1, 0xb6, 0x16, 0x7a, 0x26, 0x3e, 0x12,
  36887. 0x75, 0xc6, 0xad, 0xa8, 0x38, 0x59, 0x65, 0x30,
  36888. 0x4b, 0x30, 0x32, 0x40, 0x40, 0x54, 0x2c, 0xf5,
  36889. 0xa4, 0x51, 0xbc, 0xaf, 0xc7, 0x47, 0x88, 0xbe,
  36890. 0x3b, 0x9b, 0x9f, 0xcc, 0x45, 0xd4, 0x79, 0x0e,
  36891. 0x2d, 0x73, 0x35, 0xc6, 0x0a, 0x14, 0xf0, 0xa4,
  36892. 0x9d, 0x13, 0x05, 0x3f, 0x26, 0x26, 0xa6, 0x27,
  36893. 0xca, 0x19, 0x55, 0x3c, 0xb3, 0x36, 0xa2, 0xcb,
  36894. 0x4a, 0x45, 0x5d, 0x8e, 0xf3, 0x98, 0x94, 0x91,
  36895. 0x47, 0x2b, 0xa0, 0x05, 0x1e, 0xf7, 0x41, 0x6e,
  36896. 0x0b, 0xbf, 0x1a, 0x61, 0x08, 0xfa, 0x07, 0xc1,
  36897. 0x61, 0x54, 0x8e, 0x7c, 0x62, 0x33, 0x1a, 0xe5,
  36898. 0xa2, 0xb4, 0xe4, 0xa1, 0x08, 0xa5, 0x10, 0x93,
  36899. 0xd3, 0x15, 0x08, 0x21, 0xa2, 0xfb, 0x54, 0x71,
  36900. 0x70, 0xa1, 0xb7, 0x3c, 0x43, 0xc5, 0x50, 0xc6,
  36901. 0x55, 0x7a, 0x40, 0x48, 0xa5, 0x8a, 0x2c, 0xd7,
  36902. 0x7a, 0x24, 0x42, 0x34, 0xb2, 0x23, 0x51, 0x75,
  36903. 0xa0, 0x89, 0x7d, 0x50, 0x61, 0xb4, 0x61, 0x34,
  36904. 0x82, 0xdc, 0x13, 0x64, 0x14, 0x04, 0x8c, 0x11,
  36905. 0xdb, 0x37, 0xea, 0xe0, 0xa5, 0xdf, 0x87, 0xc1,
  36906. 0x93, 0x14, 0xb0, 0xe8, 0x23, 0x97, 0xa0, 0xd3,
  36907. 0x38, 0xdc, 0x21, 0x53, 0x8a, 0xf3, 0x61, 0x49,
  36908. 0xd9, 0x3f, 0x8b, 0x1a, 0x11, 0xc5, 0x3b, 0xb5,
  36909. 0xde, 0xf8, 0xb7, 0xa2, 0xcc, 0xa3, 0x36, 0x2b,
  36910. 0x7f, 0xe3, 0xa1, 0x40, 0x8a, 0x25, 0x47, 0xe2,
  36911. 0x09, 0x05, 0x8c, 0x67, 0x3a, 0x75, 0x66, 0xc2,
  36912. 0x61, 0x23, 0xa6, 0xd8, 0xb6, 0x92, 0xa5, 0xf3,
  36913. 0x3e, 0xbd, 0xcb, 0x26, 0x24, 0xb7, 0x9d, 0x87,
  36914. 0x7b, 0xce, 0x5f, 0xa1, 0x4e, 0x42, 0xe8, 0x3f,
  36915. 0xaa, 0xd8, 0x2e, 0x99, 0x00, 0x55, 0x3a, 0x3c,
  36916. 0x60, 0x45, 0xca, 0x32, 0x9f, 0xea, 0x4a, 0x50,
  36917. 0x65, 0x58, 0xc4, 0x91, 0xb6, 0xa6, 0x16, 0xc6,
  36918. 0xfd, 0x40, 0x0b, 0x42, 0x13, 0x6f, 0x44, 0xcb,
  36919. 0x0d, 0x02, 0x57, 0x65, 0x08, 0x19, 0x01, 0x8d,
  36920. 0x3c, 0x56, 0x8e, 0xf6, 0xc6, 0x0c, 0x6c, 0x40,
  36921. 0x9e, 0x70, 0xa8, 0x29, 0x28, 0x71, 0x08, 0xc1,
  36922. 0xb6, 0xa4, 0xd3, 0x2f, 0x76, 0xe5, 0xcc, 0x4d,
  36923. 0x10, 0x4b, 0x02, 0x43, 0x8e, 0xf7, 0xa4, 0x67,
  36924. 0x91, 0x23, 0x98, 0xea, 0x9c, 0x7c, 0xbd, 0x99,
  36925. 0x81, 0x58, 0x9a, 0x34, 0x18, 0x97, 0x68, 0x7b,
  36926. 0x51, 0x6a, 0x13, 0x30, 0x7d, 0x66, 0xc0, 0x68,
  36927. 0xc4, 0x44, 0xb4, 0xb9, 0x49, 0xa1, 0x74, 0x12,
  36928. 0x41, 0x33, 0x15, 0xcc, 0xf4, 0x9b, 0x99, 0x98,
  36929. 0x00, 0x34, 0xb5, 0xb8, 0xcf, 0xde, 0xc4, 0xa6,
  36930. 0x0b, 0x9c, 0x1e, 0x74, 0x55, 0xaa, 0xfb, 0xf3,
  36931. 0xa7, 0x57, 0x34, 0x69, 0x90, 0xcc, 0x32, 0xb0,
  36932. 0x59, 0x9b, 0xa2, 0x17, 0xa6, 0xc5, 0xfc, 0x39,
  36933. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36934. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36935. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36936. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36937. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36938. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36939. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36940. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36941. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36942. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36943. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36944. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36945. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36946. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36947. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36948. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36949. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36950. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36951. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36952. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36953. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36954. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36955. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36956. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36957. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36958. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36959. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36960. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36961. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36962. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36963. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36964. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36965. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36966. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36967. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36968. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36969. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36970. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36971. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36972. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36973. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36974. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36975. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36976. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36977. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36978. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36979. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36980. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36981. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36982. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36983. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36984. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36985. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36986. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36987. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36988. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36989. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36990. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36991. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36992. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36993. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36994. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36995. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36996. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36997. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36998. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36999. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  37000. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  37001. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  37002. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  37003. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  37004. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  37005. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  37006. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  37007. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  37008. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  37009. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  37010. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  37011. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  37012. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  37013. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  37014. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  37015. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  37016. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  37017. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  37018. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  37019. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  37020. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  37021. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  37022. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  37023. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  37024. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  37025. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  37026. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  37027. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  37028. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  37029. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  37030. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  37031. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  37032. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  37033. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  37034. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  37035. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  37036. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  37037. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  37038. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  37039. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  37040. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  37041. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  37042. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  37043. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  37044. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  37045. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  37046. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  37047. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  37048. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  37049. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  37050. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  37051. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  37052. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  37053. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  37054. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  37055. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  37056. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  37057. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  37058. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  37059. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  37060. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  37061. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  37062. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  37063. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  37064. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  37065. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  37066. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  37067. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  37068. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  37069. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  37070. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  37071. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  37072. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  37073. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  37074. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  37075. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  37076. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  37077. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  37078. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  37079. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  37080. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  37081. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  37082. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  37083. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  37084. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  37085. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  37086. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  37087. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  37088. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  37089. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  37090. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  37091. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  37092. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  37093. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  37094. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  37095. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  37096. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  37097. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  37098. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  37099. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  37100. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  37101. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  37102. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  37103. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  37104. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  37105. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  37106. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  37107. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  37108. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  37109. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  37110. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  37111. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  37112. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  37113. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  37114. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  37115. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  37116. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  37117. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  37118. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  37119. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  37120. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  37121. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  37122. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  37123. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  37124. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  37125. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  37126. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  37127. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  37128. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb,
  37129. 0xeb, 0xbe, 0x41, 0xcd, 0x4d, 0xea, 0x48, 0x9d,
  37130. 0xed, 0xd0, 0x0e, 0x76, 0xae, 0x0b, 0xcf, 0x54,
  37131. 0xaa, 0x85, 0x50, 0x20, 0x29, 0x20, 0xeb, 0x64,
  37132. 0xd5, 0x89, 0x2a, 0xd0, 0x2b, 0x13, 0xf2, 0xe5,
  37133. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  37134. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  37135. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  37136. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  37137. #endif
  37138. };
  37139. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ct[] = {
  37140. #ifdef WOLFSSL_KYBER_ORIGINAL
  37141. 0xA6, 0xAF, 0x29, 0xD5, 0xF5, 0xB8, 0x0B, 0xD1,
  37142. 0x30, 0xF5, 0x18, 0xBA, 0xDD, 0xD6, 0xC8, 0xF1,
  37143. 0x75, 0x45, 0x41, 0x3D, 0x86, 0x0F, 0xB3, 0xDE,
  37144. 0x45, 0x19, 0x79, 0xEB, 0xFA, 0x5E, 0x4E, 0x31,
  37145. 0x12, 0xC7, 0xC0, 0xAD, 0xF9, 0x98, 0x24, 0xBB,
  37146. 0x52, 0x6F, 0x2C, 0x35, 0x50, 0x74, 0x8E, 0xD0,
  37147. 0xE1, 0x34, 0xF0, 0x45, 0x7A, 0x7C, 0x61, 0xF9,
  37148. 0xF5, 0x26, 0xF0, 0x02, 0xBA, 0xAD, 0xC0, 0x3F,
  37149. 0xC1, 0x3E, 0x38, 0x13, 0x12, 0x19, 0x51, 0x3C,
  37150. 0x3E, 0xDE, 0x06, 0x16, 0x61, 0xE7, 0x4F, 0x60,
  37151. 0x3C, 0x4F, 0xCF, 0x79, 0x51, 0xC8, 0xE5, 0x2C,
  37152. 0x9C, 0x21, 0x3B, 0x0D, 0x22, 0xD9, 0x29, 0x36,
  37153. 0x63, 0xD6, 0x69, 0xA6, 0xB5, 0x8E, 0xD8, 0xFC,
  37154. 0xEF, 0xCF, 0x82, 0x49, 0xD7, 0xBB, 0x52, 0x98,
  37155. 0xF5, 0x57, 0x61, 0x44, 0x5B, 0x2B, 0x83, 0xCE,
  37156. 0x7F, 0x00, 0x5C, 0xB0, 0x42, 0x48, 0xAE, 0xC8,
  37157. 0xBD, 0xA2, 0x2F, 0xD2, 0xD4, 0x2A, 0xA7, 0x66,
  37158. 0x32, 0x20, 0x14, 0xEA, 0x03, 0x8C, 0xC3, 0x2C,
  37159. 0x55, 0xC8, 0xE4, 0xB9, 0xE2, 0x8E, 0xC9, 0x11,
  37160. 0x9F, 0x52, 0x73, 0x41, 0xE4, 0xF6, 0x6A, 0x03,
  37161. 0x51, 0x21, 0x07, 0x3B, 0x85, 0xDE, 0x67, 0x06,
  37162. 0xDA, 0x19, 0xE0, 0x83, 0x8A, 0x9F, 0x33, 0xB7,
  37163. 0x19, 0xA6, 0x8F, 0x03, 0x9B, 0x66, 0x4D, 0xC0,
  37164. 0x02, 0x65, 0x9E, 0xAB, 0xFC, 0x39, 0x86, 0x79,
  37165. 0xAA, 0x70, 0x09, 0xCE, 0x0C, 0xD0, 0x1C, 0xDA,
  37166. 0xFB, 0x6C, 0xD2, 0xA2, 0x6F, 0xE4, 0x10, 0x16,
  37167. 0x72, 0xC9, 0x8F, 0xF5, 0x8F, 0x7C, 0x47, 0xD5,
  37168. 0xBD, 0xA2, 0x90, 0x66, 0x53, 0xB3, 0xA6, 0xF9,
  37169. 0x65, 0x1F, 0x7A, 0x12, 0x1E, 0xA7, 0x7E, 0xA7,
  37170. 0x47, 0x23, 0xFA, 0xE5, 0xB8, 0x73, 0xF9, 0xBB,
  37171. 0x7B, 0x66, 0x4F, 0x0C, 0x8A, 0x93, 0x83, 0x1E,
  37172. 0xF9, 0xD5, 0x1C, 0x7C, 0xC1, 0xEF, 0x44, 0xAC,
  37173. 0x0E, 0x55, 0xA5, 0x5C, 0xA7, 0x6D, 0x13, 0x7F,
  37174. 0xE9, 0xB7, 0x5F, 0x40, 0x50, 0x9C, 0xEF, 0x15,
  37175. 0x6E, 0x5A, 0xD1, 0x8F, 0x9F, 0xB9, 0x99, 0x68,
  37176. 0x00, 0x08, 0xE5, 0x47, 0xD5, 0x5E, 0xEC, 0xD5,
  37177. 0xB4, 0xD1, 0xCB, 0x1D, 0x9F, 0x07, 0x6C, 0xEC,
  37178. 0x21, 0x50, 0x1C, 0x74, 0x02, 0x50, 0x9E, 0xCB,
  37179. 0x77, 0xAF, 0xB2, 0xCB, 0x9A, 0x61, 0x34, 0x0A,
  37180. 0x8B, 0xD1, 0x51, 0x4C, 0x6E, 0x71, 0xB4, 0xAA,
  37181. 0x45, 0xE4, 0x7E, 0xC3, 0x75, 0x12, 0x27, 0x1B,
  37182. 0x91, 0x1F, 0x8F, 0xB4, 0x6C, 0x90, 0x82, 0xC9,
  37183. 0xDF, 0x07, 0x20, 0x4A, 0xBB, 0x5A, 0x50, 0xE6,
  37184. 0xE3, 0x64, 0x7A, 0x8A, 0xD4, 0xD8, 0xD5, 0xD7,
  37185. 0xBF, 0xF1, 0x9C, 0x8A, 0x50, 0x93, 0x08, 0xBC,
  37186. 0xFB, 0x89, 0x55, 0x36, 0xD0, 0x45, 0xCA, 0x2B,
  37187. 0x97, 0xCB, 0x16, 0xA2, 0x9B, 0xB7, 0x18, 0x1C,
  37188. 0xAD, 0x05, 0x09, 0xDD, 0xB9, 0x17, 0x35, 0x02,
  37189. 0x8E, 0xBA, 0x8C, 0x31, 0xD7, 0x4B, 0xD2, 0x75,
  37190. 0xEA, 0xA6, 0x5B, 0x53, 0x40, 0xB3, 0xA4, 0x3F,
  37191. 0xBF, 0xE0, 0xB3, 0x06, 0x1D, 0x6B, 0xAE, 0x7E,
  37192. 0x75, 0xB7, 0x09, 0x8C, 0xDA, 0xBE, 0x91, 0xD4,
  37193. 0xB3, 0x1E, 0x36, 0xC9, 0xAA, 0x7A, 0x82, 0x98,
  37194. 0x86, 0x2A, 0xD6, 0x3C, 0x8F, 0xD2, 0x82, 0xE0,
  37195. 0x3B, 0x46, 0x0B, 0x3A, 0xB4, 0x64, 0xCE, 0x0F,
  37196. 0x27, 0xB1, 0xC3, 0xD1, 0x11, 0x55, 0xAC, 0xAA,
  37197. 0x01, 0x1E, 0xB9, 0xE2, 0xAE, 0x3E, 0x6D, 0xDA,
  37198. 0x07, 0xD6, 0xF4, 0x91, 0x73, 0x7C, 0xBC, 0xE9,
  37199. 0xB0, 0x5F, 0x9B, 0xC5, 0x6B, 0xE2, 0x0E, 0x8D,
  37200. 0x32, 0x6B, 0xA1, 0x32, 0xC5, 0x7F, 0xB2, 0x35,
  37201. 0x16, 0x11, 0x44, 0x51, 0x9C, 0xDF, 0x40, 0x56,
  37202. 0x0F, 0xBE, 0x27, 0x9B, 0xDE, 0x41, 0x1E, 0x11,
  37203. 0x25, 0x31, 0xF8, 0x26, 0xD6, 0xAB, 0x10, 0xD4,
  37204. 0x54, 0x73, 0x50, 0xAD, 0xD2, 0xA9, 0xDE, 0x8D,
  37205. 0x62, 0xC2, 0xAC, 0x82, 0xCA, 0xBE, 0x68, 0x15,
  37206. 0x64, 0x6F, 0x4D, 0xC9, 0x74, 0x2B, 0xB0, 0xC2,
  37207. 0xA3, 0xF7, 0x7E, 0xC7, 0xB4, 0x6C, 0x6B, 0x53,
  37208. 0x76, 0x05, 0xFA, 0x31, 0x79, 0x8C, 0xD8, 0x92,
  37209. 0x81, 0x22, 0x1A, 0x33, 0xDF, 0xB9, 0x79, 0x6E,
  37210. 0x64, 0x43, 0x05, 0x63, 0x03, 0x32, 0xC2, 0xCB,
  37211. 0x93, 0x14, 0x08, 0xAB, 0x48, 0x1A, 0x16, 0xD9,
  37212. 0x53, 0xF6, 0xBE, 0xAE, 0x38, 0x91, 0xD6, 0xD9,
  37213. 0xAC, 0x1F, 0xAB, 0x38, 0x22, 0x2D, 0x92, 0x71,
  37214. 0x87, 0x2D, 0x9D, 0x0C, 0xAD, 0xB9, 0x1A, 0xBE,
  37215. 0x9B, 0x4E, 0x26, 0x5F, 0x75, 0xC6, 0xE5, 0xE8,
  37216. 0x29, 0xE1, 0x46, 0xC3, 0xD8, 0xCE, 0x1E, 0x9D,
  37217. 0x12, 0xE0, 0xD1, 0x29, 0x80, 0x19, 0x57, 0xF4,
  37218. 0x6B, 0x0D, 0x2D, 0xBE, 0x1F, 0x74, 0x9B, 0x1D,
  37219. 0x08, 0xE2, 0x34, 0x5F, 0x62, 0x39, 0xA7, 0x31,
  37220. 0x34, 0x2E, 0xB7, 0x5B, 0x0C, 0xF1, 0xBF, 0x41,
  37221. 0x17, 0x49, 0xBC, 0x2C, 0xAF, 0x28, 0x10, 0xB7,
  37222. 0x88, 0xC6, 0xB7, 0x23, 0x8B, 0x4D, 0x3D, 0xA2,
  37223. 0xD6, 0x31, 0x5C, 0xE9, 0x54, 0x2E, 0x24, 0x40,
  37224. 0x4F, 0x14, 0x57, 0x55, 0xA3, 0x0A, 0xB8, 0x51,
  37225. 0xE4, 0x44, 0x58, 0x41, 0xBD, 0x33, 0xF7, 0x16,
  37226. 0xA5, 0x86, 0x88, 0x48, 0x88, 0xEC, 0xC6, 0xBC,
  37227. 0x64, 0x98, 0xAA, 0x32, 0x91, 0x9A, 0xE8, 0x1D,
  37228. 0x20, 0xC2, 0x69, 0x73, 0xC2, 0xBD, 0x54, 0x58,
  37229. 0x2A, 0x0F, 0x6A, 0xD9, 0x8A, 0xBF, 0xD2, 0x62,
  37230. 0x7E, 0x15, 0x69, 0x0A, 0x72, 0x7E, 0x69, 0xF5,
  37231. 0x81, 0xDD, 0x2A, 0x71, 0x27, 0x98, 0x2A, 0x90,
  37232. 0xE3, 0x3E, 0x2D, 0x4A, 0x03, 0xFE, 0x33, 0x91,
  37233. 0x42, 0xC7, 0xE4, 0x4C, 0x32, 0x6A, 0xC4, 0x6E,
  37234. 0xD3, 0x95, 0xA2, 0x25, 0xD3, 0x03, 0x33, 0x89,
  37235. 0x91, 0x73, 0x28, 0xB4, 0x53, 0x16, 0xB1, 0x58,
  37236. 0x5A, 0x01, 0xB2, 0xC3, 0x04, 0xB2, 0x94, 0x4E,
  37237. 0x90, 0x3A, 0xBB, 0xB3, 0xEC, 0x56, 0x19, 0x44,
  37238. 0x1C, 0xFC, 0x89, 0x65, 0xA4, 0x46, 0xDF, 0x75,
  37239. 0xDE, 0xFA, 0x80, 0xC6, 0xE1, 0x5A, 0xDB, 0xD5,
  37240. 0x06, 0xB7, 0xAB, 0x2D, 0xE1, 0x2D, 0xDA, 0x9B,
  37241. 0xC8, 0x14, 0x41, 0xCF, 0xC8, 0x90, 0x52, 0xE2,
  37242. 0xE5, 0x80, 0x8F, 0x71, 0x26, 0xC6, 0xFD, 0x3A,
  37243. 0xC6, 0xAC, 0x80, 0x81, 0x25, 0x8A, 0x84, 0xA0,
  37244. 0x9A, 0xE5, 0x0F, 0x6C, 0xD7, 0xCC, 0x0F, 0x4A,
  37245. 0xF3, 0x36, 0xFD, 0x1D, 0x64, 0x3E, 0x99, 0x07,
  37246. 0x99, 0x96, 0x26, 0x8C, 0x2D, 0x32, 0xD9, 0x09,
  37247. 0xF2, 0x2E, 0x35, 0x04, 0xF0, 0x7F, 0xBB, 0x56,
  37248. 0x31, 0x96, 0xD4, 0x31, 0x2F, 0xDD, 0xB9, 0x33,
  37249. 0x5D, 0x5C, 0x1D, 0x36, 0xE8, 0xC5, 0xEE, 0xA2,
  37250. 0x27, 0x8D, 0xBA, 0x23, 0xB9, 0x4D, 0x19, 0x3C,
  37251. 0x94, 0x7C, 0xC4, 0x1C, 0xA9, 0x93, 0xDC, 0x7D,
  37252. 0xB1, 0x39, 0x63, 0x40, 0xAD, 0x9C, 0x4F, 0xE6,
  37253. 0x87, 0xDD, 0x7B, 0x8D, 0x0C, 0x7A, 0x51, 0x20,
  37254. 0xAE, 0x02, 0x04, 0xF2, 0xC6, 0x65, 0xBD, 0x5F,
  37255. 0x47, 0x3D, 0x64, 0x4C, 0x7F, 0xF2, 0x6B, 0xFF,
  37256. 0xBA, 0x7A, 0x36, 0x98, 0x08, 0x30, 0x70, 0x21,
  37257. 0x28, 0xA7, 0xE6, 0x61, 0xD6, 0x77, 0xA0, 0x92,
  37258. 0xA3, 0x6E, 0x74, 0x28, 0xA4, 0x13, 0x9F, 0xB2,
  37259. 0x9B, 0x00, 0x95, 0xCC, 0x11, 0x08, 0x6F, 0x44,
  37260. 0x7D, 0x2A, 0x9E, 0xF6, 0xC9, 0xB1, 0x61, 0xF1,
  37261. 0x89, 0xC6, 0x29, 0x9E, 0x08, 0x4C, 0xB7, 0xAA,
  37262. 0x00, 0xFA, 0xF7, 0x87, 0x79, 0x7B, 0xFB, 0x06,
  37263. 0x9F, 0xBC, 0x08, 0x7F, 0xDE, 0x26, 0x25, 0x2A,
  37264. 0x16, 0x64, 0xF1, 0x9C, 0x5A, 0x8A, 0x22, 0xEC,
  37265. 0x5E, 0xE1, 0xAE, 0xB0, 0x76, 0x35, 0x7B, 0x7D,
  37266. 0xC3, 0x7E, 0x6B, 0x0F, 0x15, 0x20, 0xF9, 0x58,
  37267. 0xF7, 0x85, 0x1B, 0xAC, 0xB9, 0x2C, 0x89, 0xFD,
  37268. 0x11, 0x4A, 0x72, 0xFE, 0xAC, 0x54, 0x65, 0x2D,
  37269. 0x45, 0xB0, 0x9E, 0x1A, 0xE7, 0x65, 0x1A, 0xBD,
  37270. 0x16, 0x4B, 0xCD, 0x53, 0x7D, 0x58, 0xFA, 0x39,
  37271. 0xD3, 0xEC, 0x8A, 0xCD, 0xCD, 0xF9, 0x84, 0x25,
  37272. 0x00, 0x58, 0x62, 0xFA, 0x59, 0x69, 0x2D, 0xE1,
  37273. 0x62, 0xB7, 0x7E, 0x62, 0x97, 0xC6, 0x62, 0x33,
  37274. 0x34, 0x84, 0x08, 0xA8, 0xAB, 0x69, 0x5C, 0xE2,
  37275. 0xF2, 0x72, 0x8D, 0xB9, 0xFB, 0xE2, 0x7E, 0x95,
  37276. 0x89, 0x67, 0xEC, 0x59, 0x74, 0x76, 0x7C, 0x5A,
  37277. 0x66, 0x02, 0x30, 0x74, 0xB4, 0xA7, 0x1A, 0xFD,
  37278. 0x26, 0x4A, 0xD2, 0x89, 0x0E, 0x97, 0x0A, 0x1F,
  37279. 0x31, 0xD6, 0xE3, 0x31, 0x1B, 0x73, 0x6F, 0x9F,
  37280. 0x94, 0x88, 0x79, 0x3D, 0xDC, 0x88, 0xF2, 0x34,
  37281. 0x58, 0x06, 0x42, 0x54, 0xC8, 0x2A, 0x1D, 0x9E,
  37282. 0x59, 0xEA, 0xD2, 0xFC, 0xEC, 0x40, 0xB4, 0x30,
  37283. 0x68, 0x7C, 0x4B, 0x7E, 0x28, 0x96, 0x09, 0x26,
  37284. 0xAF, 0xCA, 0xCC, 0x9B, 0xD7, 0x56, 0xA7, 0x10,
  37285. 0x88, 0xC7, 0x84, 0x50, 0xE2, 0x0A, 0x2E, 0x98,
  37286. 0x0A, 0xED, 0xE9, 0xEB, 0xED, 0xFE, 0x7F, 0xAB,
  37287. 0xD6, 0xAB, 0xFE, 0x96, 0xF9, 0x34, 0xC4, 0xB0,
  37288. 0x2C, 0x01, 0xCA, 0x19, 0x4D, 0x01, 0xB7, 0x3C,
  37289. 0x25, 0xD5, 0x99, 0x70, 0x39, 0xD3, 0xFC, 0xD0,
  37290. 0xF0, 0x99, 0x52, 0x1F, 0x70, 0xCA, 0xEE, 0x69,
  37291. 0x11, 0x0A, 0xC1, 0xFC, 0x5A, 0x99, 0x91, 0x7A,
  37292. 0xD7, 0x52, 0xFC, 0x96, 0xAD, 0xFA, 0xD7, 0x18,
  37293. 0x6D, 0x0A, 0x7C, 0x9C, 0xFE, 0x56, 0x01, 0xC0,
  37294. 0x75, 0x14, 0xEA, 0x64, 0x48, 0xD6, 0x61, 0xC5,
  37295. 0x7A, 0xA2, 0x02, 0x42, 0x10, 0x3C, 0x42, 0x76,
  37296. 0xA0, 0x70, 0xA4, 0x89, 0xA4, 0xCB, 0x6B, 0xCA,
  37297. 0x0F, 0x9E, 0xCC, 0x43, 0x79, 0xFB, 0x22, 0x02,
  37298. 0x15, 0xFD, 0x91, 0xF8, 0x10, 0x19, 0xD5, 0xB0,
  37299. 0xAE, 0x61, 0x93, 0x58, 0xB5, 0x24, 0x68, 0xF2,
  37300. 0x72, 0xC1, 0x78, 0xE3, 0xA7, 0x4C, 0xF6, 0x77,
  37301. 0x5A, 0xA9, 0x24, 0xFE, 0x32, 0x9C, 0x31, 0x75,
  37302. 0xD9, 0xE4, 0xC3, 0xE2, 0x1A, 0xB9, 0xEC, 0x83,
  37303. 0x6E, 0xDC, 0x3A, 0xCA, 0xB2, 0xE3, 0x89, 0x1E,
  37304. 0xE8, 0xDE, 0xDA, 0x51, 0x5D, 0x39, 0xAF, 0x9B,
  37305. 0x8D, 0xDD, 0x0E, 0xE7, 0xB0, 0x16, 0x4F, 0x80,
  37306. 0x5C, 0x38, 0x35, 0xF6, 0xD2, 0xBA, 0xBD, 0xB3,
  37307. 0x0E, 0xAB, 0x47, 0x56, 0xE7, 0xEC, 0x7F, 0x82,
  37308. 0x9E, 0xCE, 0x01, 0xE8, 0xEA, 0xDF, 0xBB, 0xED,
  37309. 0x12, 0xFC, 0x28, 0x3B, 0x3D, 0x4C, 0x69, 0xF5,
  37310. 0x75, 0xE7, 0xF8, 0x04, 0x17, 0x68, 0x9F, 0xDF,
  37311. 0xCF, 0xC7, 0xBE, 0x27, 0xEE, 0x3B, 0x8C, 0xDF,
  37312. 0x57, 0xAA, 0xEB, 0xEC, 0x4A, 0x95, 0xB7, 0xE5,
  37313. 0xBB, 0x58, 0x5B, 0x85, 0x22, 0x7F, 0x7C, 0x32,
  37314. 0xBE, 0x30, 0xDB, 0x3E, 0x65, 0xE4, 0x2E, 0x30,
  37315. 0xDC, 0xF5, 0xA5, 0xFA, 0x07, 0x3D, 0xBA, 0x39,
  37316. 0x9D, 0x94, 0x2F, 0x22, 0x22, 0xAD, 0xB9, 0xB9,
  37317. 0x89, 0x81, 0x02, 0xAF, 0xE5, 0x43, 0x2E, 0xDC,
  37318. 0x7F, 0x04, 0xAE, 0x34, 0xA8, 0xFE, 0xC2, 0xD8,
  37319. 0x1C, 0xB4, 0x9A, 0x9A, 0x9B, 0x43, 0x81, 0x4C,
  37320. 0xE7, 0x1D, 0x97, 0xF7, 0x26, 0xE2, 0xB1, 0xE8,
  37321. 0xF6, 0x4B, 0x50, 0xE6, 0x5D, 0xFB, 0x48, 0x16,
  37322. 0xE1, 0x2E, 0x82, 0xA3, 0x19, 0x74, 0x84, 0xA4,
  37323. 0xE9, 0xBB, 0xA4, 0xD2, 0xD6, 0x9E, 0x3F, 0x19,
  37324. 0xD0, 0xB7, 0x5C, 0x21, 0xE2, 0xBF, 0xFE, 0x9F,
  37325. 0xC0, 0xC9, 0x8C, 0xF4, 0x8A, 0x3A, 0xAF, 0x08,
  37326. 0xD4, 0x67, 0xF7, 0x26, 0x87, 0xDF, 0x01, 0x78,
  37327. 0x17, 0x4B, 0x78, 0x97, 0xF7, 0x34, 0x34, 0x9B,
  37328. 0x18, 0x1E, 0xCA, 0x86, 0xA5, 0x98, 0xA0, 0xC5,
  37329. 0xE8, 0xC2, 0x59, 0x46, 0xF2, 0x4D, 0xC5, 0x57,
  37330. 0x2B, 0xD3, 0x24, 0xA4, 0x04, 0x58, 0xA7, 0x88,
  37331. 0xE5, 0x13, 0x7F, 0x3C, 0x7A, 0x7C, 0x97, 0xFC,
  37332. 0x9F, 0x12, 0xA3, 0xC4, 0x63, 0xA8, 0xFE, 0x94,
  37333. 0x49, 0x10, 0x1C, 0xCE, 0x96, 0x6D, 0x7C, 0x00,
  37334. 0x93, 0x23, 0x93, 0x29, 0x98, 0xD5, 0x6E, 0xF4,
  37335. 0x30, 0xC7, 0x3B, 0xC2, 0x4F, 0x5D, 0x95, 0xF7,
  37336. 0x37, 0x85, 0x8D, 0xDC, 0x4F, 0x32, 0xC0, 0x13
  37337. #else
  37338. 0xc9, 0xbe, 0xad, 0x6b, 0x0c, 0x11, 0x14, 0x38,
  37339. 0x9b, 0xd4, 0x76, 0x1c, 0x73, 0xab, 0x90, 0x95,
  37340. 0xb5, 0x80, 0x9d, 0xaa, 0xc9, 0xf6, 0x59, 0xbb,
  37341. 0x56, 0x4a, 0xf2, 0x26, 0x17, 0x30, 0x52, 0xa4,
  37342. 0xa3, 0xe7, 0xf2, 0xe5, 0xfd, 0x47, 0xd2, 0xb0,
  37343. 0x2a, 0xae, 0xb5, 0x18, 0x9e, 0x06, 0xb9, 0xf4,
  37344. 0xae, 0x98, 0xb6, 0x19, 0xcb, 0x63, 0xef, 0xbd,
  37345. 0xf3, 0x98, 0x9a, 0x94, 0xb3, 0x6e, 0x8e, 0xa0,
  37346. 0xd7, 0x00, 0x63, 0x3b, 0x95, 0x0a, 0x0a, 0xe2,
  37347. 0xa7, 0x8e, 0xd9, 0x2e, 0x85, 0xc8, 0x5c, 0x70,
  37348. 0xe1, 0x3e, 0x62, 0x6f, 0xb2, 0x63, 0xfa, 0xc9,
  37349. 0x68, 0x15, 0x21, 0xc3, 0xab, 0x22, 0xfd, 0xab,
  37350. 0x29, 0x17, 0x3c, 0x96, 0x16, 0xa2, 0xb0, 0x37,
  37351. 0x08, 0x3f, 0xf7, 0xb2, 0xe0, 0x19, 0xb5, 0xbc,
  37352. 0xde, 0x06, 0x8f, 0xac, 0x25, 0x7e, 0xf8, 0xf1,
  37353. 0x27, 0x98, 0x41, 0x16, 0x93, 0xc1, 0xbd, 0xcc,
  37354. 0x65, 0x42, 0x09, 0x97, 0xa5, 0x13, 0xa8, 0xa6,
  37355. 0x95, 0x02, 0x62, 0x0b, 0xe8, 0xe4, 0xce, 0x73,
  37356. 0x62, 0xe4, 0x12, 0xa7, 0x6c, 0xf5, 0x1c, 0x1f,
  37357. 0x24, 0x33, 0xf1, 0xab, 0x64, 0xce, 0x0e, 0x5d,
  37358. 0x2f, 0x56, 0xd7, 0xc9, 0xad, 0xe9, 0x94, 0xd0,
  37359. 0xe3, 0x5d, 0x0a, 0xee, 0xf3, 0xac, 0x51, 0x5b,
  37360. 0x48, 0x24, 0x37, 0x66, 0x4d, 0x8c, 0x1d, 0x25,
  37361. 0xe5, 0xa5, 0x50, 0x7c, 0xf8, 0x0f, 0x97, 0x0d,
  37362. 0x3e, 0xa7, 0x22, 0x6a, 0xac, 0xdc, 0x45, 0x7c,
  37363. 0xbf, 0x88, 0xa0, 0x56, 0x0a, 0xa3, 0x5b, 0xb2,
  37364. 0xc5, 0xc4, 0x55, 0x86, 0x7e, 0x21, 0x59, 0x91,
  37365. 0x0a, 0x35, 0x81, 0x0b, 0xef, 0xe3, 0xaa, 0x10,
  37366. 0xeb, 0x04, 0xd8, 0xd5, 0x71, 0x47, 0xcb, 0x8f,
  37367. 0x66, 0xd2, 0xb0, 0x70, 0xba, 0xc4, 0x3d, 0x1f,
  37368. 0x1f, 0xfd, 0xd5, 0x7a, 0x93, 0x99, 0x95, 0x1f,
  37369. 0x64, 0x96, 0x57, 0x27, 0xbc, 0xb9, 0xf6, 0x6a,
  37370. 0xd4, 0x23, 0x09, 0xda, 0xfc, 0x79, 0x9c, 0x1c,
  37371. 0x54, 0x0a, 0xf1, 0xaf, 0x93, 0xef, 0xf6, 0x8a,
  37372. 0x86, 0xd6, 0x1f, 0x51, 0x15, 0xdb, 0x66, 0x2d,
  37373. 0xee, 0x7a, 0xc9, 0xa3, 0x62, 0x67, 0x77, 0x62,
  37374. 0xb6, 0xa1, 0x64, 0xa0, 0xfa, 0x0a, 0x4d, 0x85,
  37375. 0x9e, 0x4b, 0x8c, 0x8d, 0xbd, 0xb4, 0xe1, 0x83,
  37376. 0xf5, 0xe6, 0x80, 0x8f, 0xc5, 0x22, 0x29, 0x65,
  37377. 0x0c, 0xaf, 0x7c, 0xf3, 0xe1, 0x6d, 0xe3, 0xd8,
  37378. 0x95, 0xd1, 0x48, 0xc3, 0x54, 0x48, 0xab, 0x8c,
  37379. 0x27, 0x53, 0xc9, 0x83, 0x1b, 0x24, 0xbd, 0x49,
  37380. 0x21, 0x49, 0x7e, 0xaa, 0x19, 0x25, 0x65, 0xca,
  37381. 0xbf, 0xd8, 0x3c, 0x0c, 0x68, 0xdf, 0xe7, 0xd3,
  37382. 0x92, 0xab, 0xf5, 0xe5, 0xe6, 0xf8, 0x4b, 0xb9,
  37383. 0xf5, 0xaf, 0x4b, 0x71, 0x18, 0xc0, 0xb5, 0x58,
  37384. 0x10, 0x5f, 0x9c, 0x10, 0xc9, 0xb6, 0xd7, 0x06,
  37385. 0x82, 0xe1, 0xde, 0x6e, 0x06, 0x89, 0xd7, 0x10,
  37386. 0x6a, 0x63, 0x74, 0xbd, 0x34, 0xae, 0xd7, 0x22,
  37387. 0x9e, 0x6c, 0xb3, 0x56, 0xf2, 0xea, 0x65, 0xe6,
  37388. 0x80, 0xce, 0x7b, 0x1e, 0x2c, 0x37, 0x04, 0xe1,
  37389. 0x16, 0xa3, 0x85, 0x42, 0x82, 0x6e, 0x8a, 0x00,
  37390. 0x11, 0x41, 0xba, 0xf2, 0xe3, 0x4d, 0xe3, 0x7a,
  37391. 0x03, 0x04, 0x09, 0x86, 0xd4, 0xc0, 0xcd, 0x5d,
  37392. 0x57, 0xf0, 0x70, 0x1c, 0xe9, 0x30, 0x98, 0x6f,
  37393. 0xd9, 0x52, 0x5b, 0x58, 0xe2, 0xe5, 0x9f, 0x45,
  37394. 0xb8, 0xdd, 0x04, 0xc0, 0xf3, 0x5b, 0x0f, 0x47,
  37395. 0x97, 0x0c, 0xc6, 0x70, 0x79, 0x61, 0x8e, 0xb9,
  37396. 0xe6, 0xd9, 0x1e, 0x9b, 0x0f, 0x8c, 0x6d, 0x2e,
  37397. 0x16, 0x5c, 0xf4, 0x48, 0xa2, 0xc1, 0xeb, 0xf7,
  37398. 0x1b, 0x65, 0x37, 0xe0, 0xf3, 0x75, 0x18, 0x5d,
  37399. 0xfa, 0xfe, 0xf6, 0x98, 0xb6, 0x23, 0x9b, 0xb3,
  37400. 0x55, 0x80, 0xb3, 0x15, 0xbc, 0xb5, 0xed, 0x40,
  37401. 0x8c, 0x35, 0x7f, 0x19, 0x2d, 0xef, 0x89, 0xbc,
  37402. 0x1b, 0x75, 0xcd, 0xd6, 0xaa, 0xe8, 0xb5, 0xfa,
  37403. 0xf0, 0xc3, 0xe1, 0x38, 0x03, 0xf6, 0xbd, 0xfa,
  37404. 0x76, 0xfb, 0x40, 0x7f, 0xcb, 0xda, 0x79, 0x0c,
  37405. 0x32, 0x9b, 0x3e, 0xe4, 0x2f, 0xd3, 0xd3, 0xb0,
  37406. 0x3b, 0xd5, 0x00, 0x3f, 0x0b, 0xc4, 0x32, 0xf7,
  37407. 0xba, 0x39, 0x63, 0x11, 0x12, 0x45, 0x2d, 0xfd,
  37408. 0x12, 0x14, 0x04, 0x33, 0xff, 0x89, 0x80, 0xeb,
  37409. 0x6a, 0x52, 0x6b, 0xa8, 0x5e, 0xf9, 0x94, 0x77,
  37410. 0x37, 0x8b, 0x4d, 0xc7, 0x66, 0x35, 0xa5, 0xcd,
  37411. 0x50, 0x40, 0xe4, 0x3b, 0x8c, 0x1f, 0xe4, 0xee,
  37412. 0x5e, 0x15, 0x8e, 0x42, 0x3b, 0xfc, 0x0c, 0x89,
  37413. 0x3c, 0x1d, 0x56, 0x13, 0xbe, 0xd0, 0x8d, 0xa7,
  37414. 0x19, 0xc9, 0x07, 0x31, 0x84, 0xee, 0xb3, 0x6f,
  37415. 0xd3, 0x57, 0x38, 0x0f, 0xb1, 0x87, 0x3d, 0x8c,
  37416. 0xbd, 0x36, 0xe2, 0x25, 0x5e, 0x98, 0x5b, 0x1b,
  37417. 0x76, 0x81, 0x97, 0x43, 0xa6, 0x58, 0x4a, 0x9b,
  37418. 0x3a, 0x58, 0x09, 0x96, 0xc9, 0xc2, 0xee, 0xd9,
  37419. 0xbb, 0xbf, 0xff, 0x78, 0xa6, 0x20, 0x4b, 0x5e,
  37420. 0x5e, 0xea, 0xe5, 0xf4, 0xef, 0xd2, 0x66, 0x00,
  37421. 0x78, 0xb3, 0x7f, 0x07, 0x54, 0xab, 0x5d, 0xa8,
  37422. 0x62, 0xe6, 0x66, 0xb1, 0x45, 0xb5, 0xf2, 0x3f,
  37423. 0x3d, 0x09, 0x77, 0x79, 0x99, 0x29, 0xdf, 0xa2,
  37424. 0xae, 0xdd, 0xa5, 0x3d, 0x15, 0x2e, 0xda, 0x1d,
  37425. 0x0d, 0x0e, 0x4e, 0xa4, 0x3f, 0x6e, 0xd8, 0x89,
  37426. 0xbb, 0x96, 0x5e, 0xef, 0xe0, 0xa7, 0xc6, 0x85,
  37427. 0xbb, 0x36, 0x77, 0x0e, 0xaa, 0x87, 0x42, 0x42,
  37428. 0xc0, 0xe2, 0x29, 0xcf, 0x6c, 0xe5, 0x6d, 0xef,
  37429. 0xa5, 0xae, 0xae, 0x64, 0xd0, 0xc4, 0x0d, 0xda,
  37430. 0x8a, 0xa2, 0x6e, 0xae, 0xb3, 0x14, 0x58, 0xf0,
  37431. 0x70, 0xa3, 0xbc, 0x72, 0xe1, 0x61, 0x9e, 0xe9,
  37432. 0xb5, 0xf6, 0x42, 0x29, 0x1c, 0x56, 0xdf, 0x5b,
  37433. 0x7e, 0x43, 0xdb, 0x6c, 0x80, 0x2f, 0xc7, 0x4f,
  37434. 0x4f, 0x3f, 0x9b, 0x5c, 0x0d, 0x35, 0x5c, 0x3a,
  37435. 0xae, 0x52, 0x0a, 0xa3, 0x12, 0x29, 0xd1, 0x2f,
  37436. 0x3e, 0x7c, 0xc5, 0xd4, 0x8e, 0x69, 0x11, 0x91,
  37437. 0xa3, 0x6b, 0x28, 0x37, 0x65, 0xf4, 0x13, 0x3f,
  37438. 0x0f, 0xf1, 0xfe, 0x2f, 0x01, 0xc6, 0x64, 0x8b,
  37439. 0x27, 0x98, 0xa7, 0x4e, 0xb5, 0xd8, 0x42, 0xa2,
  37440. 0x48, 0xf5, 0x24, 0xa7, 0xe7, 0xf8, 0x97, 0x42,
  37441. 0x11, 0x29, 0x7b, 0x44, 0xf0, 0xdd, 0x19, 0xf3,
  37442. 0x86, 0xe8, 0x6b, 0xe6, 0xba, 0x78, 0x2d, 0xe7,
  37443. 0x7f, 0xde, 0x88, 0x72, 0x26, 0xf3, 0x7a, 0x1c,
  37444. 0x77, 0xbc, 0x5e, 0xdd, 0xee, 0xe5, 0xbf, 0x46,
  37445. 0xb6, 0x7f, 0xb7, 0x47, 0x8d, 0x55, 0x98, 0x65,
  37446. 0xf2, 0x62, 0xca, 0xa8, 0x4d, 0x64, 0xa8, 0xce,
  37447. 0x59, 0xe4, 0xdf, 0x08, 0x18, 0xe1, 0x48, 0x61,
  37448. 0x52, 0x6a, 0xcd, 0x34, 0x83, 0x60, 0x0f, 0x3d,
  37449. 0xae, 0x79, 0x59, 0xd3, 0x5d, 0x81, 0x81, 0xca,
  37450. 0x6a, 0x81, 0xce, 0x79, 0x1b, 0xe0, 0x07, 0x52,
  37451. 0xda, 0x77, 0x59, 0x44, 0x6a, 0x2c, 0xfb, 0xe0,
  37452. 0x0b, 0x82, 0x48, 0xb9, 0x34, 0x91, 0xde, 0xbd,
  37453. 0x52, 0x02, 0x20, 0xb7, 0x55, 0x41, 0x6d, 0x2f,
  37454. 0xc6, 0xb7, 0xc8, 0xaf, 0x2f, 0xf7, 0x5e, 0x5b,
  37455. 0xcb, 0xb8, 0xe7, 0x53, 0x73, 0x80, 0xa5, 0x72,
  37456. 0x1c, 0x77, 0x48, 0x49, 0x57, 0xa6, 0x92, 0x71,
  37457. 0xd8, 0xba, 0xfc, 0xe0, 0xf1, 0x66, 0x73, 0x5f,
  37458. 0xf8, 0x69, 0x23, 0x2d, 0xe5, 0xd3, 0x81, 0xaf,
  37459. 0xbf, 0x0e, 0x44, 0xd6, 0x91, 0x72, 0xb7, 0x9a,
  37460. 0x35, 0x19, 0x19, 0x49, 0xde, 0x09, 0x70, 0x3b,
  37461. 0x94, 0x22, 0x2b, 0x13, 0xc3, 0x85, 0xc6, 0x08,
  37462. 0x1e, 0x6d, 0x2e, 0xde, 0x1e, 0x57, 0xfe, 0x18,
  37463. 0x4e, 0xf8, 0xf6, 0x01, 0x96, 0xb9, 0xa3, 0xa7,
  37464. 0xb7, 0xef, 0xf7, 0x49, 0x71, 0x91, 0xca, 0x87,
  37465. 0x41, 0xb5, 0xa0, 0x1e, 0x79, 0xcb, 0x69, 0xa6,
  37466. 0x11, 0x42, 0xe6, 0xf5, 0xd0, 0x80, 0xfb, 0xb3,
  37467. 0xe5, 0x66, 0xf7, 0x9e, 0x14, 0x6f, 0x75, 0xc8,
  37468. 0xa1, 0x09, 0x78, 0x60, 0x84, 0x1b, 0x47, 0x47,
  37469. 0xdf, 0x60, 0x4d, 0xba, 0x95, 0x4e, 0x4a, 0x8d,
  37470. 0x9e, 0x0d, 0xcc, 0xc1, 0xf6, 0x09, 0xd0, 0x5c,
  37471. 0xf8, 0xd3, 0x12, 0x19, 0xec, 0xd6, 0x0c, 0x31,
  37472. 0x2d, 0xe6, 0x84, 0x55, 0x2f, 0x09, 0x22, 0x7c,
  37473. 0xb8, 0x29, 0x29, 0x1c, 0x64, 0x57, 0x32, 0xc5,
  37474. 0xf5, 0xd4, 0xd7, 0x11, 0x63, 0x9f, 0x42, 0xa2,
  37475. 0x30, 0x80, 0xaa, 0x34, 0xfe, 0x14, 0x20, 0xf2,
  37476. 0x19, 0xbd, 0x6b, 0xcf, 0x4e, 0x3b, 0x29, 0xb9,
  37477. 0xd0, 0x22, 0x93, 0xb2, 0xda, 0x81, 0x38, 0x3e,
  37478. 0x0a, 0x51, 0xd2, 0xbb, 0x18, 0x6c, 0x7b, 0x0a,
  37479. 0x21, 0x1a, 0x0c, 0xd6, 0x3a, 0xcb, 0xfc, 0x02,
  37480. 0x10, 0x40, 0x1e, 0x98, 0x5d, 0x43, 0x6b, 0x38,
  37481. 0x03, 0xd5, 0x60, 0x1c, 0x24, 0x13, 0x6a, 0xfd,
  37482. 0x15, 0x62, 0x52, 0x2e, 0x45, 0xb4, 0x57, 0xcb,
  37483. 0x43, 0x91, 0x78, 0xbe, 0x4a, 0x87, 0xcc, 0xe4,
  37484. 0x03, 0x46, 0xd3, 0x4a, 0xe0, 0xf3, 0xc3, 0x91,
  37485. 0x03, 0xc8, 0xa3, 0xeb, 0xc9, 0xc8, 0x6c, 0x8d,
  37486. 0xb8, 0xfc, 0x55, 0x61, 0xeb, 0x0f, 0x3a, 0x14,
  37487. 0x3d, 0x4e, 0x9f, 0xe9, 0x3a, 0x5c, 0xba, 0x6f,
  37488. 0x6f, 0xca, 0xe5, 0x65, 0x0d, 0x3f, 0x43, 0xd2,
  37489. 0x66, 0x8a, 0x59, 0x56, 0xc9, 0x22, 0x89, 0x3b,
  37490. 0x81, 0x66, 0x47, 0xde, 0xd0, 0xaf, 0xc0, 0x52,
  37491. 0xa6, 0xc3, 0xd9, 0xd0, 0x1a, 0x3d, 0x3a, 0xf0,
  37492. 0xf1, 0xba, 0x80, 0x7f, 0xf1, 0x04, 0x91, 0xe1,
  37493. 0x31, 0xdc, 0x15, 0xe1, 0x65, 0xcf, 0xd0, 0x65,
  37494. 0x0a, 0x1f, 0x2c, 0x31, 0x3d, 0x79, 0x56, 0x14,
  37495. 0x1e, 0xdc, 0xc6, 0x1c, 0xb9, 0x0e, 0x9e, 0x7a,
  37496. 0xbf, 0x2f, 0xe3, 0x5f, 0xc9, 0xdc, 0x1b, 0xde,
  37497. 0x88, 0x93, 0x9f, 0xa1, 0x1f, 0x7b, 0xbe, 0x3e,
  37498. 0xb4, 0xd8, 0xff, 0xa6, 0x43, 0xb0, 0x74, 0xd7,
  37499. 0x4f, 0x45, 0x11, 0x35, 0x86, 0xe9, 0xbb, 0x12,
  37500. 0x06, 0x00, 0x03, 0xd7, 0x19, 0x41, 0xf2, 0xda,
  37501. 0x09, 0x8d, 0xc0, 0xe9, 0x6c, 0xad, 0x32, 0x55,
  37502. 0xcf, 0x32, 0x8e, 0xa2, 0xd3, 0x30, 0x8c, 0x1f,
  37503. 0x45, 0x85, 0xe8, 0x9c, 0x61, 0x3c, 0x42, 0x6b,
  37504. 0x7e, 0x79, 0x8e, 0x1e, 0xc4, 0xe9, 0x8f, 0xe6,
  37505. 0xc7, 0x1e, 0x74, 0x91, 0xf5, 0xec, 0xa0, 0xcd,
  37506. 0x05, 0x11, 0x58, 0x61, 0xbd, 0x16, 0x0e, 0x3f,
  37507. 0xe7, 0x3a, 0x58, 0xa0, 0x26, 0xba, 0x53, 0x8e,
  37508. 0x0e, 0x25, 0x6b, 0x92, 0xf1, 0xd7, 0xa2, 0x49,
  37509. 0x75, 0x70, 0x59, 0x48, 0x56, 0x86, 0x0f, 0xfd,
  37510. 0x06, 0xb6, 0x01, 0xac, 0x57, 0x55, 0x92, 0xf4,
  37511. 0xac, 0x61, 0x2b, 0x5d, 0xe7, 0x86, 0x60, 0x42,
  37512. 0x12, 0x3e, 0xbc, 0x60, 0xc5, 0x57, 0x68, 0xe3,
  37513. 0xa7, 0x60, 0x0a, 0x32, 0x60, 0x55, 0x1f, 0x2b,
  37514. 0xea, 0x22, 0xbb, 0xf6, 0xb6, 0xc8, 0x24, 0x6e,
  37515. 0x80, 0xf9, 0x12, 0x5c, 0x4b, 0xb9, 0xdb, 0x35,
  37516. 0x4d, 0xd6, 0x4a, 0xe6, 0x95, 0xc1, 0x5f, 0x50,
  37517. 0x71, 0xf4, 0xab, 0xb9, 0x63, 0x92, 0x07, 0xca,
  37518. 0xc7, 0x33, 0x1b, 0x31, 0x0f, 0x69, 0xa0, 0x5f,
  37519. 0x54, 0xb9, 0x95, 0xde, 0x52, 0x9a, 0x02, 0x3f,
  37520. 0x03, 0x3b, 0x05, 0x5d, 0xb9, 0x52, 0x87, 0xa1,
  37521. 0x4b, 0xa3, 0x0a, 0x7c, 0xc5, 0x26, 0xbb, 0x72,
  37522. 0x4c, 0x41, 0x7f, 0xba, 0x29, 0x06, 0x36, 0xa9,
  37523. 0x96, 0xf2, 0x86, 0xe3, 0xe9, 0xe9, 0x39, 0xe4,
  37524. 0xfe, 0x1c, 0x39, 0x8b, 0x5c, 0x65, 0x99, 0x95,
  37525. 0x9d, 0x0b, 0x44, 0x45, 0xa3, 0x27, 0xec, 0x46,
  37526. 0x9a, 0x16, 0x53, 0xcf, 0xae, 0xa7, 0x55, 0x2c,
  37527. 0xec, 0xec, 0x08, 0x5c, 0xca, 0xa6, 0x89, 0x38,
  37528. 0xae, 0x4a, 0xc3, 0xc4, 0x24, 0xf7, 0xe4, 0x80,
  37529. 0x43, 0x9e, 0xbd, 0x2c, 0x99, 0x2b, 0x5f, 0x6f,
  37530. 0x95, 0xec, 0x24, 0x4b, 0x65, 0x7d, 0xbd, 0xea,
  37531. 0xa9, 0xae, 0x11, 0x0a, 0xaf, 0x4d, 0x68, 0xbf,
  37532. 0x4e, 0x27, 0x41, 0x0d, 0x43, 0xce, 0xef, 0x3e,
  37533. 0x88, 0xe9, 0xc7, 0x17, 0xdd, 0x44, 0xc9, 0xee
  37534. #endif
  37535. };
  37536. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ss[] = {
  37537. #ifdef WOLFSSL_KYBER_ORIGINAL
  37538. 0xB1, 0x0F, 0x73, 0x94, 0x92, 0x6A, 0xD3, 0xB4,
  37539. 0x9C, 0x5D, 0x62, 0xD5, 0xAE, 0xB5, 0x31, 0xD5,
  37540. 0x75, 0x75, 0x38, 0xBC, 0xC0, 0xDA, 0x9E, 0x55,
  37541. 0x0D, 0x43, 0x8F, 0x1B, 0x61, 0xBD, 0x74, 0x19
  37542. #else
  37543. 0x48, 0x9d, 0xd1, 0xe9, 0xc2, 0xbe, 0x4a, 0xf3,
  37544. 0x48, 0x2b, 0xdb, 0x35, 0xbb, 0x26, 0xce, 0x76,
  37545. 0x0e, 0x6e, 0x41, 0x4d, 0xa6, 0xec, 0xbe, 0x48,
  37546. 0x99, 0x85, 0x74, 0x8a, 0x82, 0x5f, 0x1c, 0xd6
  37547. #endif
  37548. };
  37549. #ifdef WOLFSSL_SMALL_STACK
  37550. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37551. DYNAMIC_TYPE_TMP_BUFFER);
  37552. priv = (byte *)XMALLOC(KYBER1024_PRIVATE_KEY_SIZE, HEAP_HINT,
  37553. DYNAMIC_TYPE_TMP_BUFFER);
  37554. pub = (byte *)XMALLOC(KYBER1024_PUBLIC_KEY_SIZE, HEAP_HINT,
  37555. DYNAMIC_TYPE_TMP_BUFFER);
  37556. ct = (byte *)XMALLOC(KYBER1024_CIPHER_TEXT_SIZE, HEAP_HINT,
  37557. DYNAMIC_TYPE_TMP_BUFFER);
  37558. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37559. DYNAMIC_TYPE_TMP_BUFFER);
  37560. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37561. DYNAMIC_TYPE_TMP_BUFFER);
  37562. if (! (key && priv && pub && ct && ss && ss_dec))
  37563. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37564. #endif
  37565. ret = wc_KyberKey_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
  37566. if (ret != 0)
  37567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37568. else
  37569. key_inited = 1;
  37570. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  37571. sizeof(kyber1024_rand));
  37572. if (ret != 0)
  37573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37574. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
  37575. if (ret != 0)
  37576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37577. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
  37578. if (ret != 0)
  37579. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37580. if (XMEMCMP(pub, kyber1024_pk, sizeof(kyber1024_pk)) != 0)
  37581. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37582. if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0)
  37583. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37584. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  37585. sizeof(kyber1024enc_rand));
  37586. if (ret != 0)
  37587. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37588. if (XMEMCMP(ct, kyber1024_ct, sizeof(kyber1024_ct)) != 0)
  37589. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37590. if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  37591. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37592. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
  37593. if (ret != 0)
  37594. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37595. if (XMEMCMP(ss_dec, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  37596. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37597. out:
  37598. if (key_inited)
  37599. wc_KyberKey_Free(key);
  37600. #ifdef WOLFSSL_SMALL_STACK
  37601. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37602. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37603. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37604. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37605. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37606. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37607. #endif
  37608. return ret;
  37609. }
  37610. #endif /* WOLFSSL_KYBER1024 */
  37611. #endif /* WOLFSSL_WC_KYBER */
  37612. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
  37613. {
  37614. wc_test_ret_t ret;
  37615. WC_RNG rng;
  37616. int i;
  37617. #ifdef WOLFSSL_SMALL_STACK
  37618. KyberKey *key = NULL;
  37619. byte *priv = NULL;
  37620. byte *pub = NULL;
  37621. byte *priv2 = NULL;
  37622. byte *pub2 = NULL;
  37623. byte *ct = NULL;
  37624. byte *ss = NULL;
  37625. byte *ss_dec = NULL;
  37626. #else
  37627. KyberKey key[1];
  37628. byte priv[KYBER_MAX_PRIVATE_KEY_SIZE];
  37629. byte pub[KYBER_MAX_PUBLIC_KEY_SIZE];
  37630. byte priv2[KYBER_MAX_PRIVATE_KEY_SIZE];
  37631. byte pub2[KYBER_MAX_PUBLIC_KEY_SIZE];
  37632. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  37633. byte ss[KYBER_SS_SZ];
  37634. byte ss_dec[KYBER_SS_SZ];
  37635. #endif
  37636. int key_inited = 0;
  37637. static const int testData[][4] = {
  37638. #ifdef WOLFSSL_KYBER512
  37639. { KYBER512, KYBER512_PRIVATE_KEY_SIZE, KYBER512_PUBLIC_KEY_SIZE,
  37640. KYBER512_CIPHER_TEXT_SIZE },
  37641. #endif
  37642. #ifdef WOLFSSL_KYBER768
  37643. { KYBER768, KYBER768_PRIVATE_KEY_SIZE, KYBER768_PUBLIC_KEY_SIZE,
  37644. KYBER768_CIPHER_TEXT_SIZE },
  37645. #endif
  37646. #ifdef WOLFSSL_KYBER1024
  37647. { KYBER1024, KYBER1024_PRIVATE_KEY_SIZE, KYBER1024_PUBLIC_KEY_SIZE,
  37648. KYBER1024_CIPHER_TEXT_SIZE },
  37649. #endif
  37650. };
  37651. WOLFSSL_ENTER("kyber_test");
  37652. #ifdef WOLFSSL_SMALL_STACK
  37653. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37654. DYNAMIC_TYPE_TMP_BUFFER);
  37655. priv = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  37656. DYNAMIC_TYPE_TMP_BUFFER);
  37657. pub = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  37658. DYNAMIC_TYPE_TMP_BUFFER);
  37659. priv2 = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  37660. DYNAMIC_TYPE_TMP_BUFFER);
  37661. pub2 = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  37662. DYNAMIC_TYPE_TMP_BUFFER);
  37663. ct = (byte *)XMALLOC(KYBER_MAX_CIPHER_TEXT_SIZE, HEAP_HINT,
  37664. DYNAMIC_TYPE_TMP_BUFFER);
  37665. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37666. DYNAMIC_TYPE_TMP_BUFFER);
  37667. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37668. DYNAMIC_TYPE_TMP_BUFFER);
  37669. if (! (key && priv && pub && priv2 && pub2 && ct && ss && ss_dec))
  37670. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37671. #endif
  37672. #ifndef HAVE_FIPS
  37673. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  37674. #else
  37675. ret = wc_InitRng(&rng);
  37676. #endif
  37677. if (ret != 0)
  37678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37679. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  37680. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  37681. if (ret != 0)
  37682. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37683. else
  37684. key_inited = 1;
  37685. ret = wc_KyberKey_MakeKey(key, &rng);
  37686. if (ret != 0)
  37687. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37688. ret = wc_KyberKey_EncodePublicKey(key, pub, testData[i][2]);
  37689. if (ret != 0)
  37690. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37691. ret = wc_KyberKey_EncodePrivateKey(key, priv, testData[i][1]);
  37692. if (ret != 0)
  37693. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37694. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  37695. if (ret != 0)
  37696. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37697. ret = wc_KyberKey_DecodePublicKey(key, pub, testData[i][2]);
  37698. if (ret != 0)
  37699. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37700. ret = wc_KyberKey_Encapsulate(key, ct, ss, &rng);
  37701. if (ret != 0)
  37702. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37703. ret = wc_KyberKey_EncodePublicKey(key, pub2, testData[i][2]);
  37704. if (ret != 0)
  37705. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37706. if (XMEMCMP(pub, pub2, testData[i][2]) != 0)
  37707. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37708. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  37709. if (ret != 0)
  37710. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37711. ret = wc_KyberKey_DecodePrivateKey(key, priv, testData[i][1]);
  37712. if (ret != 0)
  37713. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37714. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, testData[i][3]);
  37715. if (ret != 0)
  37716. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37717. if (XMEMCMP(ss, ss_dec, KYBER_SS_SZ) != 0)
  37718. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37719. ret = wc_KyberKey_EncodePrivateKey(key, priv2, testData[i][1]);
  37720. if (ret != 0)
  37721. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37722. if (XMEMCMP(priv, priv2, testData[i][2]) != 0)
  37723. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  37724. }
  37725. wc_FreeRng(&rng);
  37726. #ifdef WOLFSSL_WC_KYBER
  37727. #ifdef WOLFSSL_KYBER512
  37728. ret = kyber512_kat();
  37729. if (ret != 0)
  37730. goto out;
  37731. #endif
  37732. #ifdef WOLFSSL_KYBER768
  37733. ret = kyber768_kat();
  37734. if (ret != 0)
  37735. goto out;
  37736. #endif
  37737. #ifdef WOLFSSL_KYBER1024
  37738. ret = kyber1024_kat();
  37739. if (ret != 0)
  37740. goto out;
  37741. #endif
  37742. #endif /* WOLFSSL_WC_KYBER */
  37743. out:
  37744. if (key_inited)
  37745. wc_KyberKey_Free(key);
  37746. #ifdef WOLFSSL_SMALL_STACK
  37747. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37748. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37749. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37750. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37751. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37752. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37753. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37754. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37755. #endif
  37756. return ret;
  37757. }
  37758. #endif /* WOLFSSL_HAVE_KYBER */
  37759. #ifdef HAVE_DILITHIUM
  37760. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  37761. static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
  37762. word32 pubKeyLen, const byte* sig, word32 sigLen)
  37763. {
  37764. byte msg[512];
  37765. dilithium_key* key;
  37766. wc_test_ret_t ret;
  37767. int i;
  37768. int res = 0;
  37769. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  37770. DYNAMIC_TYPE_TMP_BUFFER);
  37771. if (key == NULL) {
  37772. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37773. }
  37774. /* make dummy msg */
  37775. for (i = 0; i < (int)sizeof(msg); i++) {
  37776. msg[i] = (byte)i;
  37777. }
  37778. ret = wc_dilithium_init(key);
  37779. if (ret != 0) {
  37780. ret = WC_TEST_RET_ENC_EC(ret);
  37781. return ret;
  37782. }
  37783. ret = wc_dilithium_set_level(key, param);
  37784. if (ret != 0)
  37785. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37786. ret = wc_dilithium_import_public(pubKey, pubKeyLen, key);
  37787. if (ret != 0)
  37788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37789. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  37790. if (param >= WC_ML_DSA_DRAFT) {
  37791. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg),
  37792. &res, key);
  37793. }
  37794. else
  37795. #endif
  37796. {
  37797. ret = wc_dilithium_verify_ctx_msg(sig, sigLen, NULL, 0, msg,
  37798. (word32)sizeof(msg), &res, key);
  37799. }
  37800. if (ret != 0)
  37801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37802. if (res != 1)
  37803. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  37804. out:
  37805. wc_dilithium_free(key);
  37806. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37807. return ret;
  37808. }
  37809. #ifndef WOLFSSL_NO_ML_DSA_44
  37810. static wc_test_ret_t dilithium_param_44_vfy_test(void)
  37811. {
  37812. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_pub_key[] = {
  37813. 0xd8, 0xac, 0xaf, 0xd8, 0x2e, 0x14, 0x23, 0x78, 0xf7, 0x0d, 0x9a, 0x04,
  37814. 0x2b, 0x92, 0x48, 0x67, 0x60, 0x55, 0x34, 0xd9, 0xac, 0x0b, 0xc4, 0x1f,
  37815. 0x46, 0xe8, 0x85, 0xb9, 0x2e, 0x1b, 0x10, 0x3a, 0x75, 0x7a, 0xc2, 0xbc,
  37816. 0x76, 0xf0, 0x6d, 0x05, 0xa4, 0x78, 0x48, 0x84, 0x26, 0x69, 0xbd, 0x26,
  37817. 0x1d, 0x73, 0x60, 0xaa, 0x57, 0x9d, 0x8c, 0x66, 0xb1, 0x19, 0xea, 0x11,
  37818. 0xff, 0xbb, 0xf6, 0xeb, 0x26, 0x26, 0xac, 0x78, 0x74, 0x46, 0x6d, 0x51,
  37819. 0x6e, 0x92, 0xdf, 0x6a, 0x98, 0x41, 0xe9, 0x10, 0xf2, 0xcc, 0xa8, 0x7a,
  37820. 0x50, 0xdb, 0x1f, 0x4c, 0x42, 0x19, 0xd5, 0xbc, 0x76, 0x20, 0x6f, 0x2f,
  37821. 0xbf, 0xc2, 0xc9, 0x1b, 0x02, 0xb5, 0xb1, 0x09, 0x46, 0x06, 0x87, 0x02,
  37822. 0xac, 0x3d, 0xcf, 0xc3, 0xa5, 0x1b, 0xf0, 0xce, 0xd4, 0x9e, 0x84, 0x34,
  37823. 0x3c, 0x24, 0x7d, 0x89, 0xf3, 0xbf, 0x9c, 0x18, 0x9d, 0x1b, 0x1d, 0xd4,
  37824. 0xf6, 0xda, 0xc9, 0xa4, 0x14, 0xc4, 0x6b, 0xd7, 0x05, 0x6d, 0xed, 0x54,
  37825. 0x42, 0x6b, 0x5f, 0x6d, 0x1e, 0xda, 0x6b, 0x47, 0x70, 0xe5, 0x4e, 0xe7,
  37826. 0x25, 0x06, 0xf8, 0x28, 0x24, 0x34, 0xd6, 0xe5, 0xbe, 0xc5, 0x4f, 0x9e,
  37827. 0x5d, 0x33, 0xfc, 0xef, 0xe4, 0xe9, 0x55, 0x67, 0x93, 0x1f, 0x2e, 0x11,
  37828. 0x3a, 0x2e, 0xf2, 0xbb, 0x82, 0x09, 0x8d, 0xb2, 0x09, 0xf3, 0x2f, 0xef,
  37829. 0x6f, 0x38, 0xc6, 0x56, 0xf2, 0x23, 0x08, 0x63, 0x99, 0x7f, 0x4e, 0xc0,
  37830. 0x9d, 0x08, 0x9d, 0xa1, 0x59, 0x6e, 0xe1, 0x00, 0x2c, 0x99, 0xec, 0x83,
  37831. 0x2f, 0x12, 0x97, 0x2f, 0x75, 0x04, 0x67, 0x44, 0xb5, 0x95, 0xce, 0xc6,
  37832. 0x3e, 0x7a, 0x10, 0x77, 0x5e, 0xbe, 0x9c, 0x0f, 0xb3, 0xc7, 0x38, 0xbf,
  37833. 0x9e, 0x35, 0x8f, 0xe4, 0x8d, 0x19, 0xc3, 0x41, 0xb1, 0x0b, 0x8c, 0x10,
  37834. 0x9a, 0x58, 0xec, 0x4f, 0xb3, 0xe9, 0x5b, 0x72, 0x4b, 0xb8, 0x99, 0x34,
  37835. 0x9a, 0xcd, 0xb0, 0x69, 0xd0, 0x67, 0xef, 0x96, 0xb9, 0xe5, 0x54, 0x92,
  37836. 0xb7, 0x1a, 0x52, 0xf6, 0x0a, 0xc2, 0x23, 0x8d, 0x4f, 0xad, 0x00, 0xae,
  37837. 0x0f, 0x97, 0xfa, 0xce, 0x96, 0xba, 0xe7, 0x74, 0x55, 0xd4, 0xaf, 0xbf,
  37838. 0xa1, 0x32, 0x91, 0x2d, 0x03, 0x9f, 0xe3, 0x10, 0x8c, 0x77, 0x5d, 0x26,
  37839. 0x76, 0xf1, 0x87, 0x90, 0xf0, 0x20, 0xd1, 0xea, 0xf7, 0xa4, 0xe8, 0x2c,
  37840. 0x32, 0x1c, 0x55, 0xc0, 0x5d, 0xc9, 0xcd, 0x4e, 0x8f, 0x0d, 0xef, 0x0a,
  37841. 0x27, 0xb6, 0x4f, 0xa4, 0xd3, 0xa4, 0xed, 0x33, 0x22, 0xa1, 0xd3, 0x15,
  37842. 0xac, 0x1a, 0x20, 0x4e, 0x28, 0x8c, 0x8c, 0xd0, 0x71, 0xd1, 0xf2, 0xdb,
  37843. 0x33, 0x63, 0xb6, 0xa4, 0xf2, 0x17, 0x3c, 0x12, 0xb0, 0xad, 0xef, 0x31,
  37844. 0x91, 0xfe, 0xe5, 0x53, 0x99, 0xb6, 0x85, 0x63, 0xfa, 0xe6, 0xcd, 0xf6,
  37845. 0xb9, 0xce, 0x4a, 0x7d, 0x4a, 0x49, 0x29, 0xd2, 0xd9, 0xc9, 0x47, 0x4a,
  37846. 0x8a, 0x5c, 0x14, 0x5e, 0x0f, 0x7c, 0xc3, 0x91, 0xb0, 0xab, 0x37, 0xf5,
  37847. 0x26, 0x8d, 0x46, 0x74, 0x49, 0xad, 0x51, 0xc3, 0x11, 0xfa, 0x85, 0x15,
  37848. 0xa5, 0x84, 0xc1, 0xe0, 0x3c, 0x13, 0x6d, 0x13, 0xa3, 0xe6, 0xa8, 0x3c,
  37849. 0x22, 0xac, 0x17, 0x48, 0x57, 0x7c, 0x81, 0xe2, 0x4e, 0xd8, 0x33, 0x5d,
  37850. 0x4d, 0x65, 0xf7, 0xe1, 0xb8, 0x00, 0x78, 0x09, 0x16, 0xb0, 0x0b, 0xca,
  37851. 0x15, 0x0d, 0xcd, 0x9a, 0xd8, 0x47, 0x4c, 0x9b, 0x69, 0xb2, 0xa0, 0x9d,
  37852. 0x96, 0x96, 0x52, 0x6d, 0x89, 0xad, 0xff, 0x55, 0xde, 0x7b, 0xd6, 0x3d,
  37853. 0x1d, 0x5e, 0x8d, 0xf1, 0xfc, 0x48, 0x1c, 0x50, 0x59, 0x55, 0xb9, 0x07,
  37854. 0xfd, 0x6b, 0xcb, 0x95, 0xa6, 0x14, 0x73, 0xdb, 0x40, 0x40, 0x1c, 0x44,
  37855. 0xe6, 0x79, 0x30, 0x88, 0xbd, 0xa0, 0xde, 0x9b, 0xb8, 0x76, 0xf8, 0x98,
  37856. 0x56, 0x4b, 0xb9, 0x7a, 0xf6, 0xd4, 0x73, 0x89, 0x6b, 0xf7, 0x7d, 0x05,
  37857. 0x33, 0xbe, 0xb6, 0x1c, 0x4d, 0xa7, 0x12, 0x3b, 0x3f, 0xed, 0x4a, 0x0f,
  37858. 0xae, 0xa7, 0x6a, 0x26, 0x0d, 0x01, 0x84, 0x84, 0xa8, 0x0e, 0xc1, 0xc1,
  37859. 0xfd, 0xe4, 0xa9, 0xe2, 0x3f, 0xab, 0xce, 0x20, 0x90, 0x86, 0x79, 0xa2,
  37860. 0x40, 0xd0, 0xef, 0x79, 0x34, 0x2b, 0xe8, 0xc9, 0x54, 0xa7, 0x19, 0x62,
  37861. 0xcc, 0x20, 0x79, 0x3f, 0x5b, 0x9c, 0x61, 0xc2, 0xc1, 0xd2, 0x36, 0x7c,
  37862. 0x8e, 0xe3, 0x01, 0xbe, 0xc4, 0xb2, 0xb8, 0x07, 0x51, 0x23, 0x5b, 0x5d,
  37863. 0x00, 0xe6, 0x7f, 0xd6, 0xbb, 0x32, 0xa9, 0x7e, 0xb4, 0x30, 0xeb, 0x5e,
  37864. 0x6d, 0xed, 0xb2, 0xc3, 0x88, 0x81, 0xa3, 0x3b, 0x1f, 0x1e, 0xf9, 0x48,
  37865. 0x10, 0xd6, 0x01, 0x65, 0x5f, 0x6d, 0xc5, 0xeb, 0x76, 0x5f, 0x10, 0x79,
  37866. 0xaa, 0xc0, 0x86, 0xe7, 0x44, 0x95, 0x44, 0x4b, 0x54, 0x0c, 0x46, 0x2a,
  37867. 0x98, 0x01, 0x6e, 0xc0, 0xb9, 0x59, 0x2a, 0xff, 0x8f, 0xb3, 0x80, 0x15,
  37868. 0xec, 0xcd, 0x39, 0x36, 0xd7, 0x2f, 0x20, 0x9e, 0x3a, 0xc1, 0x90, 0xe5,
  37869. 0x99, 0x27, 0x16, 0xd7, 0x6c, 0x30, 0x10, 0x12, 0x03, 0x3e, 0xdc, 0xb9,
  37870. 0x03, 0x25, 0xb0, 0x8a, 0x27, 0x4d, 0x1a, 0x32, 0x36, 0x54, 0xc0, 0xba,
  37871. 0x22, 0xb2, 0xe2, 0xf6, 0x39, 0x23, 0x03, 0xc4, 0xc9, 0xe4, 0x0d, 0x99,
  37872. 0xfb, 0x98, 0xa5, 0x9b, 0x12, 0x9b, 0x58, 0x44, 0x74, 0x9f, 0x65, 0x61,
  37873. 0x51, 0xba, 0x31, 0x60, 0x9c, 0xec, 0xf8, 0x4d, 0x36, 0x61, 0xd1, 0x33,
  37874. 0x6d, 0xa6, 0x28, 0x75, 0xba, 0x7c, 0x82, 0xcb, 0x7e, 0xbe, 0x8f, 0x2d,
  37875. 0x21, 0x84, 0xb9, 0xf2, 0x4e, 0x7b, 0x95, 0x99, 0x11, 0xf3, 0xe1, 0xc0,
  37876. 0x6a, 0x44, 0xae, 0x11, 0xcb, 0x04, 0xa0, 0xf2, 0x3e, 0x17, 0xdf, 0xb2,
  37877. 0x6a, 0xdf, 0x5c, 0xf3, 0x8a, 0xf8, 0x90, 0x86, 0x64, 0xea, 0x0a, 0x32,
  37878. 0x7f, 0x9f, 0x90, 0xa8, 0x9d, 0x33, 0x12, 0xa6, 0xa4, 0xe7, 0x74, 0xa0,
  37879. 0x75, 0xa9, 0x65, 0xf8, 0x39, 0xae, 0x14, 0x32, 0x79, 0xcc, 0xaa, 0x34,
  37880. 0x86, 0x55, 0xcc, 0x99, 0xb7, 0x00, 0x05, 0x8b, 0xe3, 0x76, 0x28, 0x12,
  37881. 0xb6, 0x2a, 0x3e, 0x44, 0x8d, 0xf4, 0xba, 0xef, 0xf6, 0xdc, 0x29, 0x08,
  37882. 0x29, 0x7d, 0xd1, 0x1d, 0x17, 0x15, 0xb6, 0xb6, 0x58, 0x67, 0xd5, 0xd3,
  37883. 0x12, 0x05, 0x4e, 0xb0, 0xc3, 0x83, 0xe0, 0x35, 0x30, 0x60, 0x59, 0xa0,
  37884. 0xc5, 0x97, 0x5b, 0x81, 0xd3, 0x68, 0x6c, 0x8c, 0x17, 0x28, 0xa9, 0x24,
  37885. 0x4f, 0x80, 0x20, 0xa5, 0x21, 0x9f, 0x8f, 0x15, 0x89, 0x2d, 0x87, 0xae,
  37886. 0x2e, 0xcc, 0x73, 0x3e, 0x06, 0x43, 0xbc, 0xb3, 0x1b, 0xa6, 0x72, 0xaa,
  37887. 0xa3, 0xaa, 0xbb, 0x6f, 0x2d, 0x68, 0x60, 0xcf, 0x05, 0x94, 0x25, 0x3e,
  37888. 0x59, 0xf3, 0x64, 0x61, 0x5e, 0x78, 0x9a, 0x7e, 0x0d, 0x50, 0x45, 0x78,
  37889. 0x51, 0xab, 0x11, 0xb1, 0xc6, 0x95, 0xfc, 0x29, 0x28, 0x10, 0x9c, 0x1a,
  37890. 0x8c, 0x37, 0xb5, 0x4f, 0x0e, 0xed, 0x4a, 0x28, 0x6c, 0xaa, 0xb7, 0x0d,
  37891. 0x12, 0xfa, 0x87, 0x5d, 0xd4, 0x9a, 0xb7, 0x2b, 0x46, 0x90, 0x58, 0x4e,
  37892. 0xd7, 0x8b, 0x41, 0x1b, 0xf8, 0xc4, 0xc2, 0xde, 0xda, 0xec, 0x61, 0xe7,
  37893. 0xbf, 0x11, 0xdd, 0x6e, 0x4e, 0x6a, 0xd4, 0x87, 0x01, 0xe4, 0xac, 0xe8,
  37894. 0xaf, 0x2b, 0x01, 0xe1, 0x09, 0x20, 0xe0, 0xbd, 0x7d, 0x03, 0x73, 0x23,
  37895. 0xdf, 0x77, 0x71, 0xa4, 0x25, 0x8b, 0x0a, 0x93, 0x49, 0x32, 0x45, 0x1a,
  37896. 0xa4, 0x94, 0x31, 0x61, 0x2e, 0x17, 0x39, 0x8a, 0x66, 0xc9, 0xf9, 0x20,
  37897. 0x2d, 0x6a, 0x97, 0x2f, 0xe7, 0x26, 0xd8, 0x01, 0x42, 0x65, 0xcf, 0xce,
  37898. 0xd4, 0x24, 0x41, 0xfb, 0x9b, 0x6f, 0xf1, 0xc2, 0x9e, 0xd5, 0x08, 0x0c,
  37899. 0xdc, 0x4d, 0x8e, 0xae, 0xcb, 0x5f, 0xd4, 0xcd, 0x7c, 0xf6, 0x82, 0xc6,
  37900. 0xee, 0xf9, 0x88, 0x3a, 0x34, 0x07, 0x04, 0xb4, 0x84, 0x69, 0xb3, 0xa4,
  37901. 0x67, 0xab, 0x09, 0xc0, 0x83, 0xfe, 0x59, 0xaf, 0x18, 0x2c, 0xc8, 0x09,
  37902. 0xc1, 0xbb, 0x13, 0x7c, 0xce, 0x01, 0x5d, 0x85, 0xaa, 0x10, 0x28, 0xa2,
  37903. 0x96, 0x98, 0x69, 0x23, 0xa3, 0xe7, 0x67, 0xbc, 0x7c, 0x7e, 0xde, 0x4b,
  37904. 0x36, 0xab, 0x94, 0xd2, 0xb8, 0xf9, 0xdf, 0xee, 0xa1, 0x69, 0xa1, 0xc8,
  37905. 0xe9, 0x83, 0x21, 0xac, 0x1b, 0x39, 0xf7, 0x6d, 0xbf, 0x8c, 0xdb, 0xd6,
  37906. 0x2f, 0xc9, 0x3c, 0x3d, 0x50, 0xcf, 0x7f, 0xbe, 0x4a, 0x8d, 0xd8, 0x14,
  37907. 0xad, 0x69, 0xb0, 0x3e, 0x8a, 0xaf, 0xeb, 0xd9, 0x1a, 0x15, 0x4a, 0xe4,
  37908. 0xdd, 0xd9, 0xb2, 0xf8, 0x6b, 0xe2, 0x42, 0x9e, 0x29, 0x16, 0xfc, 0x85,
  37909. 0x9c, 0x47, 0x4b, 0x1f, 0x3d, 0x7b, 0x8c, 0xe1, 0x6d, 0xa3, 0xb8, 0x0a,
  37910. 0xe6, 0xfa, 0x27, 0xfe, 0x52, 0x72, 0xab, 0x3a, 0xa6, 0x58, 0xd7, 0x53,
  37911. 0xaf, 0x9f, 0xee, 0x03, 0x85, 0xfc, 0xa4, 0x7a, 0x72, 0x29, 0x7e, 0x62,
  37912. 0x28, 0x08, 0x79, 0xa8, 0xb8, 0xc7, 0x51, 0x8d, 0xaa, 0x40, 0x2d, 0x4a,
  37913. 0xd9, 0x47, 0xb4, 0xa8, 0xa2, 0x0a, 0x43, 0xd0, 0xe0, 0x4a, 0x39, 0xa3,
  37914. 0x06, 0x08, 0x9a, 0xe2, 0xf3, 0xf2, 0xf8, 0xb9, 0x9f, 0x63, 0x32, 0xa0,
  37915. 0x65, 0x0b, 0xb0, 0x50, 0x96, 0xa6, 0xa8, 0x7a, 0x18, 0xdd, 0x6c, 0xd1,
  37916. 0x9b, 0xd9, 0x4e, 0x76, 0x8f, 0xfb, 0x22, 0xa6, 0x1d, 0x29, 0xfc, 0xb8,
  37917. 0x47, 0x29, 0xb6, 0xd1, 0xb1, 0x63, 0x4a, 0x36, 0x1b, 0x10, 0xe6, 0x4c,
  37918. 0x65, 0x68, 0x1f, 0xad, 0x4f, 0x7d, 0x6b, 0x01, 0x41, 0x18, 0x5f, 0xba,
  37919. 0x3d, 0xa6, 0x54, 0x28, 0x58, 0xd5, 0x81, 0x60, 0xdf, 0x84, 0x76, 0x00,
  37920. 0x21, 0x53, 0xeb, 0xd3, 0xa6, 0xec, 0x7d, 0x3c, 0xb8, 0xcd, 0x91, 0x4c,
  37921. 0x2f, 0x4b, 0x2e, 0x23, 0x4c, 0x0f, 0x0f, 0xe0, 0x14, 0xa5, 0xe7, 0xe5,
  37922. 0x70, 0x8d, 0x8b, 0x9c
  37923. };
  37924. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  37925. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_pub_key[] = {
  37926. 0xea, 0x05, 0x24, 0x0d, 0x80, 0x72, 0x25, 0x55, 0xf4, 0x5b,
  37927. 0xc2, 0x13, 0x8b, 0x87, 0x5d, 0x31, 0x99, 0x2f, 0x1d, 0xa9,
  37928. 0x41, 0x09, 0x05, 0x76, 0xa7, 0xb7, 0x5e, 0x8c, 0x44, 0xe2,
  37929. 0x64, 0x79, 0xa0, 0xec, 0x1f, 0x24, 0xb6, 0xc8, 0x05, 0x5b,
  37930. 0xc1, 0x18, 0xb0, 0xb7, 0xcf, 0x8c, 0x60, 0x67, 0x6b, 0x81,
  37931. 0x44, 0x27, 0xb6, 0x0e, 0xfd, 0x9b, 0xc3, 0xcb, 0x52, 0x31,
  37932. 0xfa, 0xc9, 0x34, 0x8d, 0x22, 0x1e, 0x07, 0x9d, 0x96, 0x6a,
  37933. 0x63, 0x83, 0x5c, 0xd7, 0x83, 0x2d, 0x7f, 0x48, 0x64, 0x79,
  37934. 0xca, 0xb4, 0x9f, 0xa2, 0x02, 0xb7, 0x86, 0x1d, 0x0e, 0xc7,
  37935. 0xf9, 0x6c, 0x07, 0xc0, 0x35, 0x6a, 0x34, 0x79, 0x7c, 0xb8,
  37936. 0x0f, 0xed, 0x98, 0x50, 0xfb, 0x51, 0xe0, 0x36, 0x44, 0x4c,
  37937. 0xc6, 0x35, 0xa2, 0xbb, 0x55, 0xb0, 0x5c, 0x39, 0x08, 0x02,
  37938. 0x20, 0x35, 0x5c, 0x56, 0x6d, 0x2e, 0xb9, 0xef, 0x21, 0x26,
  37939. 0x87, 0x87, 0x85, 0x8a, 0x32, 0xb5, 0xa7, 0x68, 0x70, 0x3a,
  37940. 0xfd, 0x0d, 0x21, 0x48, 0x91, 0xa3, 0x29, 0xc1, 0x2a, 0x38,
  37941. 0xe5, 0x26, 0x31, 0x1f, 0x42, 0xde, 0x0b, 0x25, 0xff, 0x1d,
  37942. 0x6b, 0xb4, 0xe0, 0x5d, 0x2d, 0xcf, 0x44, 0xd5, 0x7d, 0xc4,
  37943. 0xf6, 0x95, 0xf2, 0x06, 0x4f, 0x83, 0x88, 0x9d, 0x1e, 0xeb,
  37944. 0x1c, 0x09, 0x45, 0x62, 0x67, 0x3d, 0xff, 0x51, 0x47, 0xe8,
  37945. 0xbc, 0x9b, 0x03, 0x1f, 0xc7, 0x72, 0x65, 0xce, 0xa8, 0x8c,
  37946. 0xc2, 0xa0, 0xc2, 0xbd, 0x5b, 0x7c, 0x17, 0x16, 0x8b, 0x72,
  37947. 0xfa, 0xb1, 0xbd, 0xdf, 0x49, 0xd6, 0xa1, 0x00, 0x65, 0xbe,
  37948. 0x82, 0xe7, 0x68, 0xc7, 0xe7, 0xbc, 0xc2, 0xa4, 0xdb, 0xaa,
  37949. 0xcc, 0xea, 0x41, 0x52, 0x7f, 0x56, 0xb4, 0x68, 0x1f, 0x92,
  37950. 0x96, 0x0f, 0xce, 0xd4, 0xd0, 0x87, 0x4c, 0x4a, 0x73, 0xb5,
  37951. 0x6c, 0xd4, 0x69, 0x55, 0x15, 0x47, 0xdc, 0x94, 0x7f, 0xd2,
  37952. 0x54, 0x5e, 0xb2, 0x90, 0xc2, 0x47, 0xe4, 0xf5, 0xde, 0x8b,
  37953. 0x9b, 0xc6, 0x5d, 0x50, 0x95, 0x60, 0xe0, 0xf0, 0xa7, 0x4e,
  37954. 0xe0, 0xcd, 0x41, 0x09, 0xef, 0xb3, 0x3d, 0x90, 0x5c, 0x77,
  37955. 0x54, 0xec, 0x9e, 0x5d, 0x8a, 0xe7, 0x09, 0x5c, 0xc9, 0x58,
  37956. 0x0c, 0xd0, 0x42, 0x35, 0xd2, 0x14, 0x59, 0x38, 0x69, 0xad,
  37957. 0xf9, 0xb5, 0xbf, 0x8a, 0x8e, 0x33, 0xd8, 0x5e, 0x7a, 0x55,
  37958. 0xd0, 0x53, 0x15, 0x40, 0x4e, 0xc5, 0x86, 0xd7, 0x8f, 0x5f,
  37959. 0x2f, 0x55, 0x82, 0xc2, 0x4f, 0x16, 0xe5, 0xea, 0x1c, 0xbc,
  37960. 0xff, 0x5e, 0x1f, 0x39, 0x46, 0x70, 0x54, 0x7a, 0x3a, 0x27,
  37961. 0x16, 0x1a, 0x2b, 0x6c, 0xd2, 0xb7, 0x80, 0xd3, 0xd1, 0x9d,
  37962. 0x25, 0x59, 0xed, 0xe6, 0x51, 0xb1, 0xf2, 0xad, 0x7e, 0x51,
  37963. 0x78, 0x14, 0x2b, 0x19, 0xae, 0x64, 0x72, 0x0f, 0xd8, 0x18,
  37964. 0x79, 0x8e, 0x66, 0x88, 0xd3, 0xa4, 0xa3, 0xc3, 0x76, 0x21,
  37965. 0xcb, 0xe4, 0x79, 0x5e, 0x95, 0x74, 0xe3, 0x31, 0x18, 0x79,
  37966. 0xed, 0xc7, 0xe7, 0xfb, 0x86, 0x48, 0x1b, 0x7b, 0x75, 0x5b,
  37967. 0x7f, 0x7c, 0x82, 0xc5, 0xab, 0x11, 0xb4, 0x5d, 0x59, 0x6f,
  37968. 0x78, 0xb2, 0xa5, 0x39, 0xc6, 0x63, 0x38, 0x6c, 0xeb, 0x50,
  37969. 0x06, 0x14, 0x76, 0xf0, 0xe8, 0xfb, 0x11, 0x95, 0x1f, 0x9d,
  37970. 0x9c, 0xa6, 0xe1, 0xe2, 0x0d, 0xa3, 0x66, 0xfc, 0x20, 0x83,
  37971. 0x50, 0x0e, 0x53, 0x75, 0xb5, 0x12, 0xf4, 0xdf, 0x31, 0x46,
  37972. 0x83, 0xac, 0x5b, 0xf3, 0x99, 0xa6, 0xd1, 0x7b, 0x2b, 0xc5,
  37973. 0xdc, 0x71, 0x07, 0x27, 0x33, 0x35, 0x34, 0xf5, 0x30, 0x19,
  37974. 0xc1, 0x3b, 0xba, 0x8a, 0xaf, 0x7e, 0x49, 0x93, 0x48, 0x5b,
  37975. 0x38, 0xc0, 0xbc, 0x2e, 0xc7, 0x59, 0x1b, 0xd9, 0xf5, 0xcc,
  37976. 0x86, 0xf5, 0x7b, 0x4d, 0xd7, 0x39, 0xa7, 0xa2, 0x56, 0x20,
  37977. 0x48, 0x98, 0x7d, 0x4f, 0x75, 0x56, 0x9b, 0xb8, 0x95, 0x45,
  37978. 0x17, 0xf3, 0x86, 0x3d, 0x97, 0x0a, 0x49, 0x1b, 0xca, 0xff,
  37979. 0x20, 0xc0, 0x24, 0x2c, 0x51, 0xc2, 0x0a, 0x3c, 0xbf, 0x07,
  37980. 0x60, 0x1c, 0x88, 0x85, 0x9b, 0x85, 0x2d, 0x4a, 0xfe, 0x5a,
  37981. 0x1c, 0x90, 0xf5, 0x90, 0x12, 0xd3, 0x03, 0x3c, 0x8c, 0x2e,
  37982. 0x95, 0x4a, 0x47, 0x76, 0x0f, 0x1f, 0x5d, 0x9e, 0xed, 0xc5,
  37983. 0x64, 0xc4, 0x9b, 0xbf, 0x86, 0xc5, 0x63, 0x84, 0x33, 0x00,
  37984. 0xf1, 0x26, 0x18, 0x21, 0xf3, 0x88, 0x1a, 0x08, 0x18, 0x6d,
  37985. 0x2f, 0xef, 0xd5, 0xeb, 0x2f, 0x69, 0xc8, 0x6e, 0x92, 0x34,
  37986. 0xfc, 0x72, 0x3d, 0x9a, 0xa7, 0x9e, 0x51, 0xfb, 0x56, 0xe3,
  37987. 0xdc, 0xf4, 0x8f, 0x9b, 0x6d, 0x0d, 0x2a, 0xec, 0x66, 0x12,
  37988. 0x26, 0x35, 0xbd, 0x61, 0xc2, 0x67, 0x19, 0xf5, 0x7e, 0xa1,
  37989. 0x67, 0xa2, 0x9c, 0x3b, 0x67, 0xb0, 0xc2, 0x51, 0x6a, 0x37,
  37990. 0x7c, 0x48, 0xe9, 0x4b, 0xb9, 0xa3, 0x38, 0x2f, 0xfc, 0xde,
  37991. 0xb4, 0x7c, 0xda, 0x52, 0x84, 0x0b, 0xb0, 0xd9, 0x08, 0xe9,
  37992. 0x7a, 0x4a, 0x6f, 0x79, 0x29, 0x3d, 0xc4, 0x5c, 0x78, 0xee,
  37993. 0x63, 0xb6, 0x96, 0x68, 0xd9, 0x82, 0x4e, 0xc1, 0x1b, 0x6f,
  37994. 0x52, 0xf5, 0xb3, 0xfb, 0xe8, 0xc4, 0x2a, 0x07, 0xc6, 0x3b,
  37995. 0x85, 0x0d, 0xf4, 0xbf, 0xb0, 0x6b, 0xfb, 0xce, 0x1d, 0xb4,
  37996. 0xbf, 0x63, 0x0b, 0x91, 0x67, 0xc4, 0xa3, 0x06, 0xa4, 0xaf,
  37997. 0x6c, 0xd3, 0xe5, 0x8b, 0x87, 0x4e, 0x64, 0x9c, 0xb1, 0xf3,
  37998. 0x70, 0x7c, 0x68, 0x43, 0x46, 0x13, 0x46, 0xee, 0x27, 0x75,
  37999. 0x12, 0x45, 0x42, 0xde, 0xa5, 0x8d, 0xcf, 0xf7, 0x09, 0x87,
  38000. 0xa8, 0x80, 0x3d, 0xb6, 0x45, 0xee, 0x41, 0x2d, 0x7c, 0x45,
  38001. 0x01, 0x9d, 0xaa, 0x78, 0xa8, 0x10, 0xa4, 0xfd, 0xb5, 0x5f,
  38002. 0xee, 0x0f, 0x77, 0xba, 0x73, 0xff, 0x49, 0xdc, 0xfa, 0x39,
  38003. 0xd6, 0xa3, 0x6f, 0x25, 0xb9, 0x63, 0x2c, 0x92, 0xc5, 0xdf,
  38004. 0xfb, 0xba, 0x89, 0xf9, 0xfa, 0x94, 0x5b, 0x6f, 0x5a, 0x4d,
  38005. 0x1c, 0xe4, 0xc9, 0x10, 0xf9, 0xa0, 0xe8, 0xc4, 0xcb, 0x55,
  38006. 0x1a, 0xdb, 0x56, 0x5f, 0x8e, 0x91, 0x03, 0x23, 0xca, 0xb0,
  38007. 0x1f, 0xef, 0xb8, 0x6c, 0x13, 0x5a, 0x99, 0x25, 0xf0, 0x49,
  38008. 0xa9, 0x5a, 0x45, 0xf7, 0xfd, 0x1a, 0xc2, 0x71, 0x06, 0xe3,
  38009. 0x2d, 0x25, 0x64, 0xb0, 0x52, 0x12, 0x03, 0x62, 0xc7, 0xb6,
  38010. 0xf9, 0xdc, 0x1f, 0x78, 0xff, 0x8b, 0xfa, 0xde, 0x7f, 0x71,
  38011. 0xa6, 0x35, 0x3e, 0xac, 0x20, 0x54, 0x94, 0xa7, 0x2e, 0x9d,
  38012. 0x47, 0x17, 0x4b, 0xad, 0x92, 0xb3, 0x14, 0x26, 0x8c, 0x5a,
  38013. 0xd0, 0x16, 0x4b, 0x22, 0xe9, 0x0c, 0x79, 0x6b, 0x8e, 0xac,
  38014. 0x0d, 0x12, 0xf5, 0x66, 0x8e, 0x82, 0x1a, 0x44, 0xf3, 0xe9,
  38015. 0x56, 0x5a, 0xcd, 0x1c, 0x1b, 0x81, 0x7b, 0x63, 0x59, 0xfe,
  38016. 0xc8, 0xc0, 0xe3, 0xda, 0x16, 0x6b, 0x6f, 0x0d, 0xba, 0x0e,
  38017. 0x47, 0x12, 0x86, 0x9e, 0xf0, 0x3b, 0x4d, 0x87, 0x3b, 0xf2,
  38018. 0x75, 0x73, 0x2d, 0xdf, 0xca, 0x76, 0x0b, 0xbd, 0xe7, 0xb7,
  38019. 0x74, 0x24, 0xf3, 0xc6, 0xe6, 0x75, 0x3f, 0x8b, 0x6a, 0xd9,
  38020. 0xad, 0xed, 0xc0, 0x70, 0x04, 0x1e, 0x0b, 0x8e, 0x8b, 0x7f,
  38021. 0xea, 0xbc, 0x39, 0x6b, 0x8a, 0x44, 0xa6, 0x9a, 0x2d, 0x0d,
  38022. 0x8c, 0x21, 0x60, 0x09, 0xd2, 0x4a, 0xe0, 0x62, 0xcf, 0xfa,
  38023. 0xe8, 0x9b, 0x35, 0x6f, 0x23, 0x2f, 0xb5, 0x65, 0x08, 0x60,
  38024. 0x92, 0x15, 0xd0, 0x5b, 0x63, 0xcc, 0x65, 0x05, 0xd1, 0xef,
  38025. 0x0f, 0x7e, 0x1b, 0xb3, 0x8e, 0xc6, 0x12, 0x85, 0xc9, 0x82,
  38026. 0x53, 0x79, 0x2e, 0x80, 0x5f, 0x0c, 0x7b, 0xc7, 0x1c, 0x83,
  38027. 0x41, 0x06, 0xd8, 0x41, 0xc9, 0xe7, 0xb9, 0x4b, 0xa1, 0x61,
  38028. 0xc6, 0x86, 0x67, 0xf5, 0x10, 0xf7, 0x34, 0x0d, 0x39, 0x9e,
  38029. 0x2b, 0x5f, 0x19, 0x06, 0x02, 0xa5, 0x02, 0x23, 0x71, 0xc2,
  38030. 0x12, 0x65, 0xcc, 0x81, 0x06, 0xfd, 0x8d, 0x09, 0x68, 0x37,
  38031. 0x06, 0x3b, 0xff, 0xc4, 0x24, 0xb3, 0x1f, 0xd6, 0xe6, 0x8f,
  38032. 0x9c, 0x74, 0x2c, 0x5e, 0xc5, 0xf4, 0xe9, 0xeb, 0xca, 0xd3,
  38033. 0x04, 0x5b, 0x92, 0x9e, 0x5c, 0x1a, 0x1d, 0xa1, 0xa7, 0x34,
  38034. 0xd2, 0x05, 0xae, 0xdb, 0x3d, 0x71, 0x10, 0x6e, 0x30, 0xd9,
  38035. 0xa3, 0x44, 0xa0, 0xbd, 0x9e, 0x7b, 0xb5, 0x12, 0x8a, 0x12,
  38036. 0x07, 0x60, 0xd7, 0x1f, 0x92, 0xe6, 0xfe, 0x04, 0xa9, 0x3e,
  38037. 0x62, 0x64, 0x00, 0x5f, 0x7c, 0x7b, 0x34, 0x09, 0xeb, 0x4a,
  38038. 0x18, 0x9e, 0x77, 0x72, 0x3a, 0x31, 0x1a, 0x62, 0x2a, 0xb5,
  38039. 0xcb, 0x4e, 0x53, 0xce, 0xad, 0x8b, 0x5a, 0x20, 0x4f, 0xd7,
  38040. 0x3e, 0x16, 0xf8, 0x10, 0xe2, 0xae, 0xbd, 0x3f, 0x02, 0xa9,
  38041. 0x18, 0xa0, 0x01, 0x18, 0x84, 0x95, 0x22, 0x2e, 0x93, 0x76,
  38042. 0x44, 0x4e, 0x11, 0x7b, 0x03, 0x51, 0x50, 0x19, 0x79, 0xe7,
  38043. 0xbb, 0x5c, 0x7b, 0xca, 0x74, 0xb4, 0x25, 0x26, 0xdb, 0x66,
  38044. 0xaa, 0x0b, 0x21, 0x07, 0xfb, 0x7a, 0x96, 0x10, 0x7d, 0x99,
  38045. 0xa9, 0x16, 0xcb, 0x0e, 0xba, 0x63, 0xab, 0x95, 0xfc, 0x5a,
  38046. 0xbe, 0xa6, 0x7f, 0xd8, 0xb4, 0xcd, 0x7c, 0xc5, 0xd0, 0xb1,
  38047. 0x1b, 0x48, 0x40, 0xfb, 0xe6, 0x2f, 0x2b, 0x94, 0xfe, 0x68,
  38048. 0xa2, 0xc4, 0x36, 0xd9, 0xcd, 0xc1, 0x93, 0x6d, 0xef, 0x39,
  38049. 0x5e, 0x43, 0x30, 0x5a, 0x2e, 0x66, 0xb6, 0xf2, 0xed, 0x9a,
  38050. 0x8d, 0x12, 0xdf, 0x5c, 0xae, 0xad, 0x16, 0x12, 0x7e, 0x81,
  38051. 0x82, 0x91, 0x7d, 0x2b, 0x12, 0xe9, 0x96, 0xb8, 0xb7, 0x42,
  38052. 0xcb, 0x1f, 0xf8, 0xd1, 0xfd, 0x83, 0x7a, 0xe4, 0x36, 0x1d,
  38053. 0x04, 0x27, 0x4c, 0xe5, 0xbd, 0x75, 0x24, 0xf7, 0xbd, 0xb6,
  38054. 0x6a, 0x68, 0x4e, 0x2c, 0x1b, 0x56, 0x3e, 0x60, 0xa4, 0x42,
  38055. 0xca, 0x7a, 0x54, 0xe5, 0x06, 0xe3, 0xda, 0x05, 0xf7, 0x77,
  38056. 0x36, 0x8b, 0x81, 0x26, 0x99, 0x92, 0x42, 0xda, 0x45, 0xb1,
  38057. 0xfe, 0x4b
  38058. };
  38059. #endif
  38060. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_sig[] = {
  38061. 0x27, 0x3b, 0x58, 0xa0, 0xcf, 0x00, 0x29, 0x5e, 0x1a, 0x63, 0xbf, 0xb4,
  38062. 0x97, 0x16, 0xa1, 0x9c, 0x78, 0xd1, 0x33, 0xdc, 0x72, 0xde, 0xa3, 0xfc,
  38063. 0xf4, 0x09, 0xb1, 0x09, 0x16, 0x3f, 0x80, 0x72, 0x22, 0x68, 0x65, 0x68,
  38064. 0xb9, 0x80, 0x5a, 0x4a, 0x0d, 0x73, 0x49, 0xe1, 0xc6, 0xde, 0xca, 0x08,
  38065. 0x4f, 0xca, 0xf8, 0xb2, 0xf8, 0x45, 0x3b, 0x6b, 0x8c, 0x6c, 0xfd, 0x3a,
  38066. 0xf4, 0xde, 0xde, 0x82, 0xd8, 0x04, 0xbe, 0x4f, 0x4a, 0xdb, 0x92, 0x47,
  38067. 0x83, 0x2d, 0xc4, 0x55, 0xed, 0x20, 0x4f, 0x71, 0xb1, 0x58, 0xd9, 0x70,
  38068. 0x73, 0xbd, 0xb0, 0x3a, 0xb4, 0x8f, 0xd6, 0x9e, 0x32, 0x98, 0x2b, 0x9e,
  38069. 0xff, 0x2a, 0x7c, 0xcb, 0x05, 0x1b, 0x8e, 0xe6, 0x3a, 0x45, 0xc6, 0x7a,
  38070. 0xc8, 0xaf, 0x62, 0xd3, 0x04, 0xfa, 0x69, 0x4f, 0xda, 0x1b, 0x74, 0x16,
  38071. 0x0d, 0xb3, 0x1a, 0xee, 0x71, 0xd7, 0xb0, 0xef, 0x69, 0xf5, 0xe2, 0xe9,
  38072. 0xc2, 0xcc, 0x15, 0x66, 0x28, 0x0a, 0xac, 0xe2, 0x63, 0x06, 0xb7, 0x21,
  38073. 0x0d, 0xd8, 0x5c, 0x94, 0x63, 0xfd, 0x51, 0x18, 0x9f, 0x07, 0x19, 0x3d,
  38074. 0xa2, 0x50, 0x40, 0xd3, 0xe9, 0x05, 0xd4, 0x11, 0x13, 0x15, 0xaa, 0x46,
  38075. 0xda, 0x3e, 0x5f, 0xcd, 0x3c, 0xfa, 0x42, 0xba, 0x79, 0x4a, 0xb7, 0x43,
  38076. 0x91, 0xa5, 0xcb, 0xbc, 0xeb, 0x37, 0x94, 0xf1, 0x9c, 0xb9, 0xdb, 0x41,
  38077. 0x06, 0xd8, 0x7b, 0x5e, 0x90, 0xe3, 0x3c, 0x8a, 0x10, 0x62, 0x9a, 0x15,
  38078. 0x27, 0x78, 0xed, 0x69, 0x11, 0x2c, 0xb5, 0xb4, 0xdb, 0xc8, 0x70, 0x50,
  38079. 0x62, 0x47, 0x96, 0xcb, 0xd9, 0xb2, 0x3e, 0x59, 0x2f, 0x1c, 0xac, 0xcb,
  38080. 0xcf, 0x22, 0xc2, 0x9b, 0xc7, 0x92, 0xe9, 0x4d, 0x8d, 0x5d, 0xcf, 0x06,
  38081. 0x53, 0x7e, 0xf4, 0x4e, 0xfe, 0x9e, 0x41, 0x5d, 0x00, 0x8c, 0x08, 0xf4,
  38082. 0x02, 0x79, 0x33, 0x1c, 0x27, 0x1d, 0xe3, 0x94, 0xac, 0xe6, 0x87, 0xa0,
  38083. 0x08, 0xb4, 0x60, 0x0c, 0xff, 0x47, 0xdc, 0x16, 0x3a, 0x1d, 0x89, 0xc0,
  38084. 0x6a, 0xa4, 0x3d, 0x71, 0x33, 0xdd, 0x1e, 0x70, 0xfe, 0xd4, 0x8b, 0xed,
  38085. 0x7c, 0x91, 0xe4, 0xe2, 0x15, 0x06, 0xc1, 0x83, 0x24, 0x55, 0xa7, 0x2a,
  38086. 0x9f, 0x4e, 0xd9, 0x56, 0x7a, 0x95, 0xa8, 0xdd, 0xc4, 0xf0, 0x71, 0x3a,
  38087. 0x99, 0x65, 0x31, 0x4b, 0xb7, 0x96, 0x2c, 0x53, 0x54, 0x83, 0xec, 0xc9,
  38088. 0x97, 0x2f, 0x0c, 0xa4, 0x8f, 0xbb, 0x93, 0x9d, 0xea, 0xae, 0xf9, 0xcb,
  38089. 0xb2, 0xb9, 0xa3, 0x61, 0x5f, 0x77, 0x8c, 0xb6, 0x5a, 0x56, 0xbe, 0x5f,
  38090. 0x85, 0xd1, 0xb5, 0x0a, 0x53, 0xe2, 0xc7, 0xbf, 0x76, 0x8b, 0x97, 0x6f,
  38091. 0x10, 0xdd, 0x1f, 0x44, 0x69, 0x66, 0x03, 0xc4, 0x6b, 0x59, 0xf7, 0xb4,
  38092. 0xc1, 0x12, 0xcc, 0x00, 0x70, 0xe8, 0xbd, 0x44, 0x28, 0xf5, 0xfa, 0x96,
  38093. 0xf3, 0x59, 0xed, 0x81, 0x67, 0xe0, 0xbe, 0x47, 0x75, 0xb3, 0xa8, 0x9f,
  38094. 0x21, 0x70, 0x2e, 0x6f, 0xef, 0x54, 0x11, 0x3f, 0x34, 0xaf, 0x0d, 0x73,
  38095. 0x5b, 0x9e, 0x6d, 0x86, 0x58, 0xb7, 0x34, 0xc2, 0xc2, 0xb3, 0x64, 0xd5,
  38096. 0x9b, 0x6e, 0xb9, 0x99, 0x6a, 0xe4, 0xfd, 0xc3, 0x17, 0xf3, 0x10, 0xfc,
  38097. 0x6e, 0xf5, 0x65, 0xe1, 0x9c, 0x59, 0x15, 0x11, 0x00, 0xea, 0x96, 0x81,
  38098. 0x69, 0x9b, 0x05, 0x4d, 0xf3, 0xce, 0xf3, 0xf0, 0xa9, 0x01, 0x3f, 0x13,
  38099. 0xbb, 0xb0, 0xac, 0xc3, 0x92, 0x1c, 0x2b, 0x61, 0xe3, 0x01, 0x22, 0x45,
  38100. 0x4a, 0x23, 0x19, 0x80, 0xca, 0xb9, 0xef, 0x4e, 0x76, 0x52, 0xc5, 0x9d,
  38101. 0x91, 0x33, 0x17, 0xc4, 0x28, 0x83, 0x55, 0x61, 0x49, 0x72, 0x04, 0xaa,
  38102. 0xf8, 0xe3, 0x4b, 0x20, 0xf7, 0x6a, 0x74, 0x56, 0x64, 0xf9, 0xb3, 0xc9,
  38103. 0x67, 0x5b, 0x55, 0x29, 0x9a, 0x89, 0xa5, 0x14, 0x67, 0xea, 0x6d, 0x6a,
  38104. 0xde, 0x98, 0x58, 0x73, 0x25, 0xa3, 0xdb, 0xed, 0x3d, 0x62, 0xaa, 0xe0,
  38105. 0x79, 0x7f, 0xa3, 0xd9, 0xb5, 0x4c, 0xe9, 0xa8, 0xdf, 0xfd, 0x59, 0x31,
  38106. 0x42, 0x81, 0x9e, 0xb7, 0x81, 0x3f, 0x0e, 0xfb, 0xef, 0x80, 0x71, 0x9d,
  38107. 0xb7, 0xa5, 0xfc, 0xb1, 0x80, 0xc9, 0x7e, 0x31, 0xd9, 0x47, 0xe2, 0xca,
  38108. 0x10, 0x7b, 0xd1, 0xa1, 0x1c, 0x28, 0xc7, 0x7f, 0x51, 0x26, 0xb1, 0x4e,
  38109. 0x57, 0xdd, 0x7d, 0x76, 0x5c, 0x5a, 0x85, 0xa7, 0x7b, 0x8c, 0xc5, 0x6e,
  38110. 0xac, 0x20, 0xf8, 0x49, 0x16, 0xd6, 0x64, 0xf5, 0xf4, 0x2c, 0x32, 0xa1,
  38111. 0x5d, 0xfb, 0x87, 0xb6, 0x14, 0xfe, 0x68, 0x7c, 0x4d, 0xce, 0xd7, 0x94,
  38112. 0xf9, 0x8b, 0xf0, 0x61, 0xfd, 0xe0, 0x83, 0x7f, 0x13, 0xec, 0x7a, 0xb7,
  38113. 0x41, 0x04, 0x51, 0x6e, 0x30, 0xa2, 0x01, 0xf7, 0x30, 0x12, 0xec, 0xd2,
  38114. 0x8f, 0x73, 0xe7, 0x8e, 0x12, 0xb4, 0xe5, 0xc1, 0xff, 0xdf, 0x67, 0x14,
  38115. 0xb1, 0xe9, 0xba, 0x36, 0x19, 0x18, 0xf4, 0xaa, 0xe0, 0xe4, 0x9d, 0xcd,
  38116. 0xe8, 0xe7, 0x2b, 0x33, 0xb3, 0xdc, 0xb9, 0x19, 0xd7, 0xad, 0xa4, 0x68,
  38117. 0xcd, 0x83, 0x77, 0x98, 0x36, 0x49, 0xd9, 0x32, 0x20, 0xfd, 0xfc, 0x34,
  38118. 0xe7, 0x54, 0xd9, 0xb5, 0x05, 0xab, 0x0e, 0x08, 0x0e, 0x16, 0x8a, 0x7d,
  38119. 0x91, 0x4c, 0xaa, 0x19, 0x04, 0x37, 0x35, 0xa5, 0xab, 0x6c, 0xee, 0xc4,
  38120. 0x90, 0xf0, 0x5f, 0xc7, 0xae, 0x82, 0xfd, 0x59, 0x53, 0xe5, 0x36, 0x5a,
  38121. 0x56, 0x37, 0x61, 0x69, 0xda, 0xe5, 0x8f, 0xfd, 0x2e, 0xd4, 0x9c, 0x7f,
  38122. 0xb6, 0x39, 0xa4, 0x8d, 0x0a, 0xab, 0x82, 0x0f, 0xfe, 0x84, 0x69, 0x44,
  38123. 0x8a, 0xa6, 0xd0, 0x39, 0xf9, 0x72, 0x68, 0xe7, 0x97, 0xd8, 0x6c, 0x7b,
  38124. 0xec, 0x85, 0x8c, 0x52, 0xc9, 0x97, 0xbb, 0xc4, 0x7a, 0x67, 0x22, 0x60,
  38125. 0x46, 0x9f, 0x16, 0xf1, 0x67, 0x0e, 0x1b, 0x50, 0x7c, 0xc4, 0x29, 0x15,
  38126. 0xbc, 0x55, 0x6a, 0x67, 0xf6, 0xa8, 0x85, 0x66, 0x89, 0x9f, 0xff, 0x38,
  38127. 0x28, 0xaa, 0x87, 0x91, 0xce, 0xde, 0x8d, 0x45, 0x5c, 0xa1, 0x25, 0x95,
  38128. 0xe2, 0x86, 0xdd, 0xa1, 0x87, 0x6a, 0x0a, 0xa8, 0x3e, 0x63, 0x0e, 0x21,
  38129. 0xa5, 0x6e, 0x08, 0x4d, 0x07, 0xb6, 0x26, 0xa8, 0x92, 0xdb, 0xed, 0x13,
  38130. 0x01, 0xc3, 0xba, 0xcf, 0xad, 0x01, 0xbc, 0xe5, 0xc0, 0xba, 0xbe, 0x7c,
  38131. 0x75, 0xf1, 0xb9, 0xfe, 0xd3, 0xf0, 0xa5, 0x2c, 0x8e, 0x10, 0xff, 0x99,
  38132. 0xcb, 0xe2, 0x2d, 0xdc, 0x2f, 0x76, 0x00, 0xf8, 0x51, 0x7c, 0xcc, 0x52,
  38133. 0x16, 0x0f, 0x18, 0x98, 0xea, 0x34, 0x06, 0x7f, 0xb7, 0x2e, 0xe9, 0x40,
  38134. 0xf0, 0x2d, 0x30, 0x3d, 0xc0, 0x67, 0x4c, 0xe6, 0x63, 0x40, 0x41, 0x42,
  38135. 0x96, 0xbb, 0x0b, 0xd6, 0xc9, 0x1c, 0x22, 0x7a, 0xa9, 0x4d, 0xcc, 0x5b,
  38136. 0xaa, 0x03, 0xc6, 0x3b, 0x1e, 0x2f, 0x11, 0xae, 0x34, 0x6f, 0x0c, 0xe9,
  38137. 0x16, 0x9c, 0x82, 0x3b, 0x90, 0x4c, 0x0e, 0xf0, 0xf9, 0x7f, 0x02, 0xca,
  38138. 0xb9, 0xa9, 0x49, 0x6d, 0x27, 0x73, 0xd0, 0xbf, 0x15, 0x61, 0x52, 0xbc,
  38139. 0xd6, 0x31, 0x59, 0x2b, 0x52, 0x5b, 0xaf, 0x3c, 0xc0, 0x8f, 0xdc, 0xd5,
  38140. 0x2c, 0x1d, 0xe4, 0xe9, 0x41, 0xe8, 0xd3, 0x35, 0xd6, 0xb1, 0xf3, 0x32,
  38141. 0xe0, 0x52, 0x08, 0x73, 0x99, 0xb6, 0x6b, 0xbc, 0x26, 0xfb, 0x2e, 0xa7,
  38142. 0xb7, 0xcd, 0x14, 0xf0, 0xf9, 0xe5, 0x3a, 0xd0, 0x05, 0x5b, 0x2b, 0x38,
  38143. 0xbd, 0x7c, 0xda, 0xd4, 0x15, 0x45, 0xfa, 0x3b, 0x6f, 0x94, 0x8e, 0x22,
  38144. 0xce, 0xfa, 0x53, 0xe0, 0x5f, 0xa6, 0x9d, 0x1c, 0x26, 0x91, 0x8a, 0xab,
  38145. 0x72, 0x5b, 0x18, 0x78, 0x69, 0x98, 0x3f, 0x8d, 0x33, 0x7c, 0x21, 0x93,
  38146. 0x9e, 0xf0, 0xaf, 0xb7, 0x30, 0xc8, 0xac, 0xbc, 0xdb, 0x9c, 0x29, 0x17,
  38147. 0x6b, 0x9d, 0x0f, 0x16, 0xd6, 0xc0, 0xcc, 0x3b, 0xce, 0x11, 0xe9, 0x64,
  38148. 0xc8, 0xd4, 0x4c, 0x98, 0x7c, 0x8f, 0xf1, 0x5e, 0x84, 0xe4, 0x72, 0xf9,
  38149. 0x69, 0xf5, 0x9d, 0xad, 0x95, 0x3b, 0xfb, 0x6d, 0x30, 0x7e, 0x0a, 0x47,
  38150. 0x5b, 0x26, 0xb2, 0x4e, 0xeb, 0x1a, 0xc3, 0x37, 0x16, 0x28, 0x79, 0x62,
  38151. 0xb4, 0x36, 0x85, 0x4a, 0x15, 0x5a, 0xc3, 0x6e, 0xbe, 0x7e, 0x00, 0xe9,
  38152. 0x4a, 0xa5, 0xd7, 0x90, 0xcf, 0x59, 0x63, 0x2d, 0x2b, 0xc2, 0xc6, 0x47,
  38153. 0xe6, 0x77, 0xb7, 0x6e, 0x9b, 0xc8, 0x0d, 0x18, 0x2b, 0x45, 0x2b, 0xc9,
  38154. 0x5a, 0x6e, 0xb4, 0x50, 0xa5, 0x23, 0x7d, 0x17, 0xcc, 0x49, 0xe2, 0xb3,
  38155. 0xf4, 0x6d, 0xb4, 0xb7, 0xbb, 0x9e, 0xdd, 0x20, 0x99, 0x19, 0xf5, 0x53,
  38156. 0x1f, 0xd0, 0xff, 0x67, 0xf3, 0x8e, 0x6a, 0xcd, 0x2a, 0x6e, 0x2b, 0x0a,
  38157. 0x90, 0xd7, 0xdb, 0xe1, 0xff, 0x1c, 0x40, 0xa1, 0xb0, 0x5d, 0x94, 0x4d,
  38158. 0x20, 0x14, 0x01, 0xa1, 0xa8, 0xd1, 0x15, 0xd2, 0xd9, 0x1b, 0xbf, 0xc2,
  38159. 0x8a, 0xd0, 0x02, 0xf6, 0x16, 0xa1, 0xb7, 0x40, 0xe0, 0x36, 0x88, 0xc8,
  38160. 0x17, 0x0a, 0xf0, 0xb6, 0x0d, 0x3c, 0x53, 0xb9, 0x51, 0xed, 0xef, 0x20,
  38161. 0x6f, 0xf3, 0x0c, 0xb5, 0xce, 0x0e, 0x9e, 0xfd, 0x0f, 0x5e, 0x3f, 0x8f,
  38162. 0x3c, 0xb7, 0x2a, 0xdb, 0xc6, 0xa7, 0xf2, 0x11, 0x6e, 0xdc, 0x05, 0x33,
  38163. 0xd4, 0xd8, 0xb0, 0x2d, 0x8a, 0xe5, 0x39, 0x82, 0x00, 0x49, 0x7d, 0xfd,
  38164. 0x32, 0x29, 0xbb, 0x79, 0x5d, 0xcb, 0x21, 0x7b, 0x2d, 0x36, 0x58, 0x73,
  38165. 0x52, 0x57, 0x52, 0x96, 0x4d, 0x89, 0x61, 0xf4, 0xad, 0x1f, 0x48, 0xd5,
  38166. 0x7a, 0x4a, 0xaa, 0x1c, 0xa1, 0xf4, 0xb4, 0x9c, 0x43, 0x3b, 0x95, 0x72,
  38167. 0xd0, 0x0e, 0x35, 0x82, 0x26, 0xd4, 0x2e, 0xe3, 0x83, 0x96, 0x97, 0x5a,
  38168. 0x7b, 0xfc, 0x48, 0x17, 0x3c, 0xba, 0x9e, 0x5f, 0x46, 0x1a, 0x53, 0xe3,
  38169. 0x2e, 0x78, 0x79, 0x80, 0xf6, 0x2d, 0x24, 0xcf, 0x62, 0xb6, 0x86, 0xeb,
  38170. 0xee, 0xec, 0xf2, 0x1d, 0x00, 0xc8, 0x28, 0x9d, 0x93, 0x16, 0xa7, 0xd9,
  38171. 0x11, 0x47, 0xe3, 0xc4, 0xb6, 0xc4, 0xa0, 0x99, 0x83, 0xc1, 0x17, 0xd8,
  38172. 0x8e, 0xde, 0x69, 0x1d, 0xcb, 0xdd, 0xe7, 0x86, 0x6f, 0xf2, 0x36, 0x07,
  38173. 0x23, 0x86, 0x0d, 0xe9, 0xad, 0x87, 0xae, 0x76, 0x98, 0x95, 0x51, 0xf2,
  38174. 0xb3, 0x11, 0xc5, 0x34, 0xf0, 0x0c, 0xf8, 0x29, 0x9c, 0x84, 0x4f, 0x81,
  38175. 0x49, 0x85, 0x63, 0x25, 0x16, 0xb0, 0xc3, 0xaa, 0xd7, 0x8a, 0x2e, 0x4b,
  38176. 0x97, 0x60, 0x74, 0xf8, 0xa7, 0x39, 0xec, 0x6c, 0x2c, 0x9b, 0x33, 0x3a,
  38177. 0x11, 0xbd, 0xa6, 0x90, 0x48, 0x65, 0xb1, 0xe7, 0x38, 0x53, 0x47, 0x1b,
  38178. 0x62, 0xd5, 0xb7, 0xa8, 0xd4, 0xae, 0xf5, 0x12, 0x06, 0x12, 0x54, 0xa2,
  38179. 0xce, 0xf1, 0x6b, 0x3a, 0xda, 0x63, 0x2e, 0x37, 0x2a, 0x25, 0x89, 0x30,
  38180. 0x98, 0x77, 0x1d, 0x4b, 0x5a, 0x1e, 0xb7, 0x3d, 0xed, 0x19, 0xec, 0x9f,
  38181. 0x64, 0x46, 0xa8, 0x2a, 0x79, 0xf3, 0x70, 0x39, 0x9f, 0x8c, 0xc3, 0x28,
  38182. 0xcc, 0x2a, 0xc0, 0xd0, 0xe6, 0x80, 0xf5, 0x01, 0x78, 0x72, 0x7f, 0xe7,
  38183. 0x2e, 0x7b, 0x5f, 0x05, 0xc3, 0x41, 0x33, 0x07, 0xdb, 0x9c, 0xa8, 0x96,
  38184. 0xa7, 0x21, 0x20, 0x23, 0xd0, 0x59, 0x39, 0x06, 0x19, 0xa4, 0x29, 0xe5,
  38185. 0x72, 0x39, 0x69, 0x23, 0xe3, 0xfa, 0x28, 0x63, 0xf5, 0x42, 0x3b, 0xca,
  38186. 0x88, 0x5d, 0x7e, 0x47, 0x93, 0xa8, 0x8c, 0x75, 0xf2, 0x19, 0x44, 0x43,
  38187. 0x15, 0x39, 0x03, 0x42, 0xd8, 0x1d, 0x81, 0x30, 0x8e, 0x84, 0x31, 0x24,
  38188. 0x75, 0x67, 0x4e, 0xbe, 0xfe, 0x0a, 0xd8, 0xc3, 0xe7, 0x5b, 0xe1, 0xd5,
  38189. 0x12, 0x6a, 0x69, 0x99, 0xcd, 0x35, 0xca, 0x22, 0x02, 0x65, 0xb3, 0x0f,
  38190. 0x50, 0xb6, 0xaa, 0xc6, 0x91, 0x5c, 0x4d, 0xd4, 0x07, 0x93, 0x46, 0xf0,
  38191. 0xcc, 0xe1, 0x92, 0x14, 0x91, 0x21, 0x43, 0xc4, 0xba, 0x45, 0x1c, 0x47,
  38192. 0x29, 0xdf, 0xff, 0x89, 0x60, 0xee, 0x89, 0x1e, 0xc3, 0xb4, 0xb9, 0x0b,
  38193. 0xc9, 0x7e, 0xd9, 0x15, 0xb0, 0x80, 0x91, 0xbe, 0xb9, 0x43, 0x48, 0x12,
  38194. 0x86, 0x8e, 0x79, 0x38, 0x4d, 0xce, 0x36, 0x7f, 0xc3, 0xe8, 0xb7, 0xb9,
  38195. 0x92, 0xbf, 0x27, 0x20, 0x54, 0xc8, 0x05, 0x63, 0x3b, 0xf5, 0x48, 0x1a,
  38196. 0xa9, 0x04, 0x6c, 0xb6, 0x0e, 0x11, 0xea, 0xf3, 0x59, 0xb9, 0xa6, 0xf6,
  38197. 0xf8, 0x0b, 0x15, 0xed, 0x30, 0xf9, 0xe4, 0xe5, 0x26, 0x2d, 0xbb, 0xc6,
  38198. 0x5b, 0x36, 0xbb, 0x73, 0xa6, 0x4f, 0xf5, 0x43, 0x9f, 0xd7, 0xb9, 0x0f,
  38199. 0xbc, 0x4f, 0x8d, 0xb8, 0xec, 0x1d, 0x42, 0x19, 0x56, 0x37, 0xc4, 0xcb,
  38200. 0xd0, 0x16, 0x85, 0xff, 0xd3, 0x9b, 0xef, 0xc8, 0x75, 0x37, 0xd1, 0x92,
  38201. 0xad, 0x21, 0x94, 0x1e, 0x9a, 0xf6, 0x2f, 0x6d, 0x30, 0xba, 0x37, 0xc3,
  38202. 0xdc, 0x11, 0xe0, 0x79, 0xa4, 0x92, 0x1f, 0xe4, 0xaa, 0x7a, 0x6b, 0x2a,
  38203. 0xe4, 0x04, 0xb7, 0xf9, 0x86, 0x95, 0xdb, 0xa8, 0xfc, 0x8a, 0x53, 0x21,
  38204. 0x31, 0x14, 0xf7, 0x40, 0x01, 0x78, 0x4e, 0x73, 0x18, 0xb3, 0x54, 0xd7,
  38205. 0xa6, 0x93, 0xf0, 0x70, 0x04, 0x1c, 0xe0, 0x2b, 0xef, 0xee, 0xd4, 0x64,
  38206. 0xa7, 0xd9, 0x9f, 0x81, 0x4f, 0xe5, 0x1e, 0xbe, 0x6e, 0xd2, 0xf6, 0x3a,
  38207. 0xba, 0xcf, 0x8c, 0x96, 0x2a, 0x3d, 0xf7, 0xe5, 0x5c, 0x59, 0x40, 0x9c,
  38208. 0xe3, 0xf9, 0x2b, 0x6d, 0x3d, 0xf2, 0x6f, 0x81, 0xd6, 0xab, 0x9c, 0xab,
  38209. 0xc6, 0xf7, 0x8f, 0xaa, 0xe5, 0x71, 0xe3, 0xc9, 0x8c, 0x1a, 0xeb, 0xc5,
  38210. 0x87, 0xe7, 0xb0, 0xde, 0x18, 0xba, 0xaa, 0x1e, 0xda, 0x12, 0x32, 0x16,
  38211. 0x94, 0x3a, 0x6e, 0x4f, 0x84, 0x06, 0x8e, 0x33, 0xf7, 0xfa, 0x35, 0xb8,
  38212. 0x45, 0xe4, 0x5e, 0x9e, 0x46, 0x05, 0x7a, 0xf7, 0xf4, 0x99, 0xad, 0xb9,
  38213. 0xdd, 0x55, 0xd9, 0x52, 0x3b, 0x93, 0xe3, 0x9b, 0x54, 0x1b, 0xe6, 0xa9,
  38214. 0x70, 0xd3, 0x48, 0xf9, 0x3d, 0xdb, 0x88, 0x63, 0x66, 0xa0, 0xab, 0x72,
  38215. 0x83, 0x6e, 0x8f, 0x78, 0x9d, 0x55, 0x46, 0x21, 0xca, 0x7c, 0xb7, 0x5d,
  38216. 0x16, 0xe8, 0x66, 0x3b, 0x7b, 0xaa, 0xfe, 0x9c, 0x9c, 0x33, 0xc9, 0xc2,
  38217. 0xa4, 0x3c, 0x78, 0x97, 0xf3, 0x5b, 0xc2, 0x29, 0x36, 0x98, 0x68, 0x28,
  38218. 0xfe, 0x0a, 0xae, 0x6f, 0xe5, 0xf7, 0xfb, 0x9d, 0xf8, 0x8c, 0xd9, 0xd0,
  38219. 0x4d, 0xfe, 0xc7, 0xd0, 0xb0, 0xe3, 0x9c, 0xdb, 0xac, 0x9e, 0x1b, 0x55,
  38220. 0x7e, 0x24, 0xfe, 0xc4, 0x12, 0xcb, 0xc2, 0xdd, 0x0a, 0xda, 0x31, 0x40,
  38221. 0x41, 0xb7, 0xfc, 0x3f, 0x6d, 0xe2, 0xd3, 0x8a, 0x0f, 0x21, 0x33, 0x3a,
  38222. 0xbc, 0xa7, 0x62, 0x18, 0xb3, 0xaf, 0x48, 0xc6, 0xe2, 0xa3, 0xdd, 0x1d,
  38223. 0x20, 0x62, 0xe4, 0x4b, 0x81, 0x6b, 0x3a, 0xc5, 0xb1, 0x07, 0xe1, 0xf1,
  38224. 0xe1, 0xba, 0xf6, 0x01, 0xc6, 0xf2, 0xea, 0xc0, 0x97, 0x73, 0x79, 0x19,
  38225. 0x06, 0xaa, 0x62, 0x42, 0xcb, 0x21, 0x5f, 0x08, 0x97, 0x7d, 0x72, 0xb5,
  38226. 0x39, 0x4d, 0x99, 0xe3, 0xa2, 0x3f, 0xb9, 0xb4, 0xed, 0xf4, 0x61, 0x35,
  38227. 0xe1, 0x50, 0xfb, 0x56, 0x7c, 0x35, 0xfd, 0x44, 0x8a, 0x57, 0x22, 0xed,
  38228. 0x30, 0x33, 0xc3, 0x0b, 0xf1, 0x88, 0xe4, 0x44, 0x46, 0xf5, 0x73, 0x6d,
  38229. 0x9b, 0x98, 0x88, 0x92, 0xf5, 0x34, 0x85, 0x18, 0x66, 0xef, 0x70, 0xbe,
  38230. 0x7b, 0xc1, 0x0f, 0x1c, 0x78, 0x2d, 0x42, 0x13, 0x2d, 0x2f, 0x4d, 0x40,
  38231. 0x8e, 0xe2, 0x6f, 0xe0, 0x04, 0xdb, 0x58, 0xbc, 0x65, 0x80, 0xba, 0xfc,
  38232. 0x89, 0xee, 0xf3, 0x78, 0xb2, 0xd9, 0x78, 0x93, 0x6d, 0xbf, 0xd4, 0x74,
  38233. 0x24, 0xf4, 0x5c, 0x37, 0x89, 0x0c, 0x14, 0xd5, 0xbd, 0xc5, 0xfc, 0x37,
  38234. 0xe8, 0x8b, 0xe0, 0xc5, 0x89, 0xc9, 0x70, 0xb3, 0x76, 0x46, 0xce, 0x0d,
  38235. 0x7c, 0x3d, 0xa4, 0x5d, 0x02, 0x95, 0x03, 0xba, 0x24, 0xaa, 0xf7, 0xd0,
  38236. 0x75, 0x35, 0x78, 0x27, 0x9c, 0x6d, 0x2a, 0xef, 0xaa, 0xac, 0x85, 0xef,
  38237. 0x8d, 0xfc, 0xc0, 0xfc, 0x72, 0x02, 0xf4, 0xa3, 0xd3, 0x87, 0xfc, 0x4d,
  38238. 0xce, 0x3d, 0xcb, 0xc2, 0x74, 0x5b, 0xb0, 0x83, 0xc5, 0x72, 0x72, 0xd6,
  38239. 0xa1, 0x67, 0x4d, 0xa1, 0xd6, 0xaa, 0xe7, 0x9b, 0xe7, 0xc0, 0xfd, 0x86,
  38240. 0x91, 0x08, 0xfa, 0x48, 0x2f, 0x50, 0xce, 0x17, 0xea, 0x1c, 0xe3, 0x90,
  38241. 0x35, 0xe6, 0x6c, 0xc9, 0x66, 0x7d, 0x51, 0x32, 0x20, 0x0c, 0x2d, 0x4b,
  38242. 0xa1, 0xbf, 0x78, 0x87, 0xe1, 0x5a, 0x28, 0x0e, 0x9a, 0x85, 0xf6, 0x7e,
  38243. 0x39, 0x60, 0xbc, 0x64, 0x42, 0x5d, 0xf0, 0x0a, 0xd7, 0x3e, 0xbb, 0xa0,
  38244. 0x6d, 0x7c, 0xfa, 0x75, 0xee, 0x34, 0x39, 0x23, 0x0e, 0xbd, 0x50, 0x19,
  38245. 0x7a, 0x2a, 0xb7, 0x17, 0x3a, 0x8b, 0xb7, 0xb6, 0xf4, 0xd8, 0x47, 0x71,
  38246. 0x6b, 0x21, 0x1b, 0x56, 0xcc, 0xfb, 0x7b, 0x81, 0x99, 0x46, 0x88, 0x23,
  38247. 0x40, 0x49, 0x66, 0x8b, 0xac, 0x84, 0x16, 0x8a, 0x86, 0xae, 0x38, 0xc4,
  38248. 0x5b, 0x1f, 0x2b, 0xfa, 0xf2, 0x8b, 0x81, 0xc1, 0x22, 0x61, 0x61, 0x6c,
  38249. 0x43, 0x16, 0x8c, 0x1d, 0x37, 0xb2, 0xaf, 0x3c, 0x3a, 0x90, 0x33, 0xed,
  38250. 0xf5, 0x08, 0x78, 0xfd, 0x5a, 0xde, 0xd3, 0x38, 0x6d, 0xd7, 0x1c, 0x23,
  38251. 0xeb, 0xb4, 0x9b, 0x8e, 0xc2, 0x48, 0x47, 0x8e, 0x84, 0xbb, 0xc4, 0xd0,
  38252. 0xcc, 0xf9, 0x55, 0x5a, 0x57, 0xb9, 0x99, 0x52, 0x82, 0x21, 0x3b, 0x83,
  38253. 0xda, 0x8f, 0xa3, 0x88, 0x9c, 0x57, 0xe0, 0x4b, 0xc1, 0xce, 0xbe, 0xd3,
  38254. 0xea, 0xdd, 0xf2, 0x07, 0xc1, 0x73, 0x6f, 0xc0, 0x5e, 0x8e, 0x85, 0x72,
  38255. 0xab, 0x2f, 0xa9, 0xac, 0x39, 0xee, 0x05, 0x34, 0x13, 0x16, 0x1b, 0x1c,
  38256. 0x21, 0x24, 0x41, 0x49, 0x78, 0x87, 0x8b, 0x97, 0x9c, 0x9f, 0xa3, 0xa8,
  38257. 0xb9, 0xbc, 0xc6, 0xcc, 0xf2, 0xfd, 0x18, 0x2a, 0x46, 0x58, 0x5a, 0x88,
  38258. 0xa2, 0xb5, 0xcc, 0xd2, 0xda, 0xe1, 0xe3, 0x0d, 0x20, 0x23, 0x2b, 0x2f,
  38259. 0x47, 0x57, 0x5e, 0x64, 0x87, 0x97, 0x9c, 0xa7, 0xaa, 0xbc, 0xc1, 0xe4,
  38260. 0xe5, 0xea, 0x0b, 0x16, 0x3b, 0x3c, 0x3e, 0x45, 0x58, 0x63, 0x6a, 0x6f,
  38261. 0x7c, 0x8c, 0x8d, 0x92, 0x99, 0x9c, 0xad, 0xb5, 0xb7, 0xce, 0x00, 0x00,
  38262. 0x00, 0x00, 0x00, 0x00, 0x16, 0x23, 0x36, 0x4a
  38263. };
  38264. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38265. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_sig[] = {
  38266. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  38267. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  38268. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  38269. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  38270. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  38271. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  38272. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  38273. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  38274. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  38275. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  38276. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  38277. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  38278. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  38279. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  38280. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  38281. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  38282. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  38283. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  38284. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  38285. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  38286. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  38287. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  38288. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  38289. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  38290. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  38291. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  38292. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  38293. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  38294. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  38295. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  38296. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  38297. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  38298. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  38299. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  38300. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  38301. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  38302. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  38303. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  38304. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  38305. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  38306. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  38307. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  38308. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  38309. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  38310. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  38311. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  38312. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  38313. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  38314. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  38315. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  38316. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  38317. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  38318. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  38319. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  38320. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  38321. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  38322. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  38323. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  38324. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  38325. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  38326. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  38327. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  38328. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  38329. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  38330. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  38331. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  38332. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  38333. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  38334. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  38335. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  38336. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  38337. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  38338. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  38339. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  38340. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  38341. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  38342. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  38343. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  38344. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  38345. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  38346. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  38347. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  38348. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  38349. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  38350. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  38351. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  38352. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  38353. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  38354. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  38355. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  38356. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  38357. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  38358. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  38359. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  38360. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  38361. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  38362. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  38363. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  38364. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  38365. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  38366. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  38367. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  38368. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  38369. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  38370. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  38371. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  38372. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  38373. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  38374. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  38375. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  38376. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  38377. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  38378. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  38379. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  38380. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  38381. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  38382. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  38383. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  38384. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  38385. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  38386. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  38387. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  38388. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  38389. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  38390. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  38391. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  38392. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  38393. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  38394. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  38395. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  38396. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  38397. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  38398. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  38399. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  38400. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  38401. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  38402. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  38403. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  38404. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  38405. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  38406. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  38407. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  38408. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  38409. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  38410. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  38411. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  38412. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  38413. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  38414. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  38415. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  38416. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  38417. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  38418. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  38419. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  38420. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  38421. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  38422. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  38423. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  38424. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  38425. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  38426. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  38427. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  38428. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  38429. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  38430. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  38431. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  38432. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  38433. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  38434. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  38435. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  38436. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  38437. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  38438. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  38439. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  38440. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  38441. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  38442. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  38443. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  38444. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  38445. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  38446. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  38447. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  38448. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  38449. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  38450. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  38451. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  38452. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  38453. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  38454. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  38455. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  38456. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  38457. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  38458. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  38459. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  38460. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  38461. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  38462. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  38463. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  38464. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  38465. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  38466. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  38467. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  38468. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  38469. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  38470. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  38471. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  38472. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  38473. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  38474. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  38475. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  38476. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  38477. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  38478. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  38479. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  38480. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  38481. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  38482. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  38483. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  38484. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  38485. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  38486. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  38487. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  38488. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  38489. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  38490. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  38491. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  38492. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  38493. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  38494. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  38495. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  38496. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  38497. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  38498. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  38499. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  38500. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  38501. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  38502. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  38503. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  38504. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  38505. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  38506. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  38507. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46
  38508. };
  38509. #endif
  38510. wc_test_ret_t ret;
  38511. ret = dilithium_param_vfy_test(WC_ML_DSA_44, ml_dsa_44_pub_key,
  38512. (word32)sizeof(ml_dsa_44_pub_key), ml_dsa_44_sig,
  38513. (word32)sizeof(ml_dsa_44_sig));
  38514. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38515. if (ret == 0) {
  38516. ret = dilithium_param_vfy_test(WC_ML_DSA_44_DRAFT,
  38517. ml_dsa_44_draft_pub_key, (word32)sizeof(ml_dsa_44_draft_pub_key),
  38518. ml_dsa_44_draft_sig, (word32)sizeof(ml_dsa_44_draft_sig));
  38519. }
  38520. #endif
  38521. return ret;
  38522. }
  38523. #endif
  38524. #ifndef WOLFSSL_NO_ML_DSA_65
  38525. static wc_test_ret_t dilithium_param_65_vfy_test(void)
  38526. {
  38527. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_pub_key[] = {
  38528. 0x2c, 0x32, 0xfa, 0x59, 0x71, 0x16, 0x4a, 0x0e, 0x45, 0x0f, 0x21, 0xfd,
  38529. 0x65, 0xee, 0x50, 0xb0, 0xbf, 0xea, 0x8e, 0x4e, 0xa2, 0x55, 0x71, 0xa6,
  38530. 0x65, 0x48, 0x56, 0x20, 0x8a, 0x48, 0x9d, 0xd7, 0xc9, 0x2c, 0x80, 0x62,
  38531. 0x88, 0x68, 0x4d, 0x5f, 0xbe, 0x5f, 0xe5, 0xf5, 0xa4, 0x75, 0xb6, 0x88,
  38532. 0x26, 0xae, 0x7d, 0x11, 0x43, 0x89, 0xcd, 0xe9, 0x67, 0x0c, 0x91, 0x0b,
  38533. 0xd1, 0xd8, 0x8b, 0x7b, 0x73, 0x75, 0x94, 0xc1, 0xc9, 0x61, 0xc7, 0x35,
  38534. 0x21, 0x99, 0x2e, 0xab, 0xe0, 0xdf, 0x4d, 0xac, 0x0d, 0xd0, 0xa2, 0x61,
  38535. 0x5f, 0x04, 0x08, 0x83, 0x66, 0x5c, 0x67, 0x47, 0x0c, 0xab, 0x2c, 0xb7,
  38536. 0x6d, 0x0e, 0x32, 0x4c, 0x8c, 0x25, 0x80, 0xf5, 0xe5, 0x7e, 0x3b, 0xa1,
  38537. 0xc6, 0xc5, 0x87, 0xd8, 0x68, 0xb2, 0xd5, 0x67, 0xf9, 0x5a, 0x8b, 0x88,
  38538. 0xf8, 0xcd, 0x0c, 0xda, 0x4f, 0xfc, 0xd2, 0xaf, 0xb2, 0xa2, 0x38, 0x21,
  38539. 0xf9, 0xd8, 0xf1, 0x1c, 0x8d, 0xb4, 0xe8, 0xfb, 0x76, 0x36, 0x87, 0xf4,
  38540. 0x7d, 0x03, 0xc4, 0x06, 0xab, 0x87, 0xac, 0x52, 0xe8, 0xd5, 0xf7, 0x63,
  38541. 0xf0, 0xa8, 0x0b, 0x95, 0xbd, 0x07, 0xf1, 0x1d, 0x33, 0x7b, 0x8a, 0x2c,
  38542. 0xef, 0x85, 0xbe, 0xf8, 0xc1, 0x4b, 0xa2, 0xb0, 0xe0, 0x7a, 0x85, 0xfa,
  38543. 0x52, 0x36, 0x05, 0xa7, 0x65, 0x4a, 0x0c, 0x21, 0x5c, 0xc0, 0x4f, 0x18,
  38544. 0xb8, 0x66, 0x02, 0xe6, 0xd0, 0x45, 0x60, 0x56, 0xfc, 0x40, 0x94, 0xb5,
  38545. 0xa5, 0x2b, 0xc7, 0x57, 0xc3, 0xc5, 0x30, 0x72, 0x1c, 0x4c, 0x2a, 0xd5,
  38546. 0x75, 0xae, 0x43, 0x9f, 0x01, 0x71, 0xac, 0x5c, 0xdf, 0x9c, 0x0a, 0x3c,
  38547. 0xb5, 0x89, 0x07, 0x9b, 0x28, 0x25, 0x31, 0x31, 0xc5, 0xb7, 0x24, 0x53,
  38548. 0x2c, 0x3c, 0x2a, 0x96, 0xe5, 0x0d, 0xa2, 0x97, 0xa7, 0x08, 0x9d, 0x31,
  38549. 0xc0, 0xcd, 0x53, 0xd5, 0xa8, 0x58, 0xa6, 0xac, 0x43, 0x2d, 0xac, 0x39,
  38550. 0x01, 0x2c, 0x60, 0xf6, 0x82, 0x86, 0xd0, 0xaf, 0xad, 0x61, 0x3f, 0x82,
  38551. 0x80, 0xa1, 0xe1, 0x12, 0x83, 0x6e, 0x1d, 0x5e, 0xfe, 0xc6, 0x1e, 0x2a,
  38552. 0x7a, 0x44, 0xcd, 0xc2, 0x0a, 0xf5, 0xc8, 0x72, 0x3e, 0x29, 0xc7, 0x0a,
  38553. 0xd1, 0x4c, 0x17, 0xdd, 0x1f, 0xb6, 0x95, 0x34, 0xc2, 0x6c, 0xdc, 0x63,
  38554. 0xd1, 0x7e, 0xb0, 0x52, 0x06, 0x18, 0x6c, 0xb1, 0x99, 0x6a, 0xbe, 0x42,
  38555. 0xa9, 0xc0, 0x22, 0xcc, 0x09, 0x11, 0x84, 0x1f, 0x16, 0x9a, 0x0e, 0xdd,
  38556. 0x18, 0x7a, 0x39, 0x34, 0xb0, 0x49, 0x44, 0xcb, 0x88, 0x1f, 0x91, 0x93,
  38557. 0x49, 0x3f, 0xcc, 0x62, 0x56, 0x33, 0x15, 0xcb, 0x02, 0x9b, 0x33, 0xe8,
  38558. 0xd7, 0xab, 0x51, 0xc0, 0x91, 0xe0, 0x9c, 0xd2, 0xf9, 0x52, 0x05, 0x0c,
  38559. 0xbf, 0xf1, 0x97, 0x42, 0xfe, 0xd0, 0x32, 0x27, 0x34, 0xf8, 0x82, 0x2d,
  38560. 0x65, 0x3a, 0x36, 0xce, 0xd1, 0x07, 0x82, 0x3a, 0x6a, 0xaa, 0x56, 0xf1,
  38561. 0x9b, 0x98, 0xca, 0x8e, 0x55, 0xff, 0xa0, 0x74, 0xd6, 0x6a, 0x42, 0xaa,
  38562. 0x0a, 0xd4, 0x59, 0x74, 0xfb, 0xd4, 0xdb, 0x14, 0x10, 0xee, 0xca, 0x78,
  38563. 0x83, 0x83, 0x95, 0x9b, 0x77, 0xf1, 0x9a, 0x48, 0xe0, 0x8f, 0xa4, 0x5a,
  38564. 0x4d, 0xa9, 0x3f, 0x32, 0x78, 0x4a, 0x25, 0x96, 0x9c, 0x20, 0x0a, 0xcc,
  38565. 0x5b, 0xd8, 0xca, 0x19, 0x47, 0x77, 0xb8, 0x7c, 0x51, 0x3e, 0xd6, 0x30,
  38566. 0xdb, 0x45, 0xb0, 0xe6, 0x9d, 0x6f, 0xc5, 0x0a, 0x5d, 0x5f, 0x55, 0xcd,
  38567. 0x0f, 0x20, 0x22, 0x7e, 0x09, 0x99, 0xac, 0xb8, 0x9c, 0x9d, 0xf7, 0x3e,
  38568. 0x7e, 0x07, 0xd7, 0xbc, 0x21, 0x76, 0x8c, 0x27, 0x81, 0x94, 0xab, 0x57,
  38569. 0x4a, 0xe2, 0x91, 0x1c, 0xa4, 0x77, 0x4a, 0xd2, 0x96, 0x52, 0x9d, 0x33,
  38570. 0xb5, 0x58, 0x70, 0xd7, 0xff, 0x22, 0xe8, 0x14, 0xea, 0xd0, 0x8c, 0xd4,
  38571. 0x06, 0x08, 0xd8, 0x73, 0x66, 0x4b, 0x93, 0x41, 0xc9, 0x73, 0x5b, 0x07,
  38572. 0x5f, 0x31, 0xc5, 0x25, 0x98, 0x7b, 0x7b, 0xa5, 0x26, 0x83, 0x94, 0x22,
  38573. 0x42, 0x1c, 0x51, 0xe6, 0x80, 0x48, 0xca, 0xd4, 0x53, 0x40, 0x3a, 0xee,
  38574. 0x2c, 0x29, 0x07, 0xed, 0xdf, 0x97, 0x44, 0x19, 0xe5, 0xe5, 0x35, 0x66,
  38575. 0x1f, 0xbd, 0x29, 0x77, 0x0c, 0x15, 0x6c, 0x95, 0x08, 0x81, 0xe0, 0x76,
  38576. 0x86, 0x5e, 0x6d, 0x77, 0x78, 0x76, 0x07, 0xdd, 0x21, 0x97, 0x59, 0xdb,
  38577. 0xd4, 0xbd, 0xb6, 0x4c, 0x3f, 0x07, 0x93, 0xb6, 0x4a, 0xce, 0xf7, 0x08,
  38578. 0x86, 0xfd, 0x9c, 0x03, 0x08, 0x94, 0x00, 0xea, 0x4b, 0xd6, 0x1e, 0x17,
  38579. 0xfb, 0xb5, 0xba, 0xde, 0x25, 0x95, 0xe7, 0xf8, 0x97, 0x9e, 0x99, 0xae,
  38580. 0x5d, 0xdd, 0xf6, 0x32, 0x1a, 0xf2, 0x4f, 0xcf, 0x0c, 0x17, 0x55, 0xb8,
  38581. 0xfb, 0xae, 0xc8, 0x46, 0xb0, 0x3e, 0x86, 0x2b, 0x5e, 0xef, 0x36, 0xca,
  38582. 0x24, 0xed, 0x32, 0x5b, 0xc8, 0xfb, 0x88, 0x35, 0x6a, 0x26, 0xfe, 0x06,
  38583. 0x54, 0x0c, 0x3e, 0x2c, 0x71, 0xdf, 0x98, 0xf0, 0xbb, 0xb2, 0xe0, 0x9d,
  38584. 0xf7, 0xeb, 0xce, 0x07, 0xfa, 0xc4, 0xab, 0x88, 0xc3, 0x14, 0x33, 0x60,
  38585. 0x48, 0xcf, 0x39, 0x26, 0x90, 0xac, 0xfa, 0x39, 0x6f, 0x2d, 0x9d, 0x6d,
  38586. 0x15, 0x7f, 0x84, 0x6b, 0x0a, 0x1c, 0xf4, 0x6c, 0x78, 0x62, 0x52, 0x93,
  38587. 0x2c, 0x7e, 0x9f, 0x4a, 0x51, 0x7a, 0x2e, 0xad, 0xea, 0xe4, 0xe5, 0x9c,
  38588. 0x15, 0x15, 0x28, 0x4d, 0x3e, 0x5e, 0xb4, 0x3b, 0xff, 0x81, 0xe0, 0x56,
  38589. 0x44, 0x33, 0x33, 0xd9, 0x4b, 0xb2, 0x23, 0x60, 0xed, 0x0d, 0xa5, 0x4e,
  38590. 0x9f, 0x7d, 0xbc, 0x6e, 0x3a, 0xf9, 0x7e, 0x16, 0x47, 0x66, 0xb1, 0x6c,
  38591. 0xc7, 0x26, 0x62, 0x9b, 0x3c, 0x53, 0xb3, 0xa1, 0x16, 0x62, 0x31, 0x64,
  38592. 0xd2, 0xbb, 0x28, 0x5c, 0xe8, 0x21, 0xc3, 0xfc, 0xc3, 0x6d, 0xa7, 0x35,
  38593. 0x4d, 0x57, 0xe0, 0xbd, 0x54, 0x1a, 0x84, 0xf7, 0x9c, 0x8a, 0x54, 0x3d,
  38594. 0x59, 0xb3, 0xa2, 0x46, 0x3b, 0x16, 0x48, 0x3b, 0x3a, 0x3c, 0x5e, 0x88,
  38595. 0xc3, 0x60, 0x63, 0x7e, 0xca, 0x68, 0xb7, 0x2f, 0x2b, 0xb5, 0x62, 0x2e,
  38596. 0x51, 0x89, 0xbe, 0x78, 0xf7, 0xfa, 0x19, 0xcc, 0xca, 0x87, 0x9a, 0xf5,
  38597. 0xef, 0x0d, 0x21, 0x08, 0x3b, 0xd6, 0x9a, 0x94, 0xc5, 0xd1, 0x1b, 0xa9,
  38598. 0x7c, 0xc8, 0x9f, 0x9a, 0xb0, 0xb8, 0xf7, 0x02, 0x12, 0x31, 0x70, 0x52,
  38599. 0x52, 0xda, 0xb5, 0x9a, 0x08, 0x20, 0xc3, 0xc4, 0x0c, 0x6a, 0x34, 0x58,
  38600. 0x75, 0x9b, 0xdc, 0x1a, 0x6a, 0x37, 0x42, 0x9f, 0x16, 0x70, 0xbb, 0x39,
  38601. 0x86, 0xbd, 0x09, 0x9c, 0x04, 0x44, 0xbe, 0x1a, 0xe5, 0xe9, 0x50, 0x9b,
  38602. 0x14, 0x50, 0x4f, 0x00, 0xba, 0xb0, 0xf6, 0x36, 0x4d, 0x69, 0x16, 0x11,
  38603. 0x40, 0x5a, 0x4e, 0x8b, 0x39, 0xb4, 0xf1, 0xb2, 0x11, 0x36, 0x2f, 0x02,
  38604. 0x15, 0xca, 0x78, 0xde, 0x75, 0x07, 0x64, 0x72, 0xfd, 0xd4, 0x48, 0xdd,
  38605. 0xfb, 0xf5, 0x8a, 0x3d, 0xa8, 0x8e, 0x14, 0xd1, 0x69, 0xe3, 0x21, 0x50,
  38606. 0x39, 0xfd, 0xd0, 0x3b, 0xa0, 0x22, 0x61, 0x5c, 0x7e, 0x88, 0x91, 0xe1,
  38607. 0xf0, 0xf6, 0x16, 0x23, 0xdb, 0xdb, 0x50, 0x0e, 0x39, 0xcc, 0x86, 0xf1,
  38608. 0xab, 0x89, 0x60, 0xb0, 0xac, 0x28, 0xc6, 0x57, 0xe4, 0xee, 0xa9, 0x1b,
  38609. 0xae, 0x78, 0xc5, 0x67, 0x1a, 0xeb, 0xb3, 0x43, 0xbc, 0xea, 0x11, 0x0c,
  38610. 0x64, 0xf6, 0xd2, 0x52, 0xa0, 0x7e, 0xcd, 0x6d, 0x84, 0x8c, 0xf8, 0x80,
  38611. 0xb7, 0xdb, 0x26, 0x91, 0x4a, 0xa0, 0x61, 0x69, 0x2f, 0x6f, 0x1c, 0x9d,
  38612. 0x2a, 0x20, 0x44, 0xdc, 0x58, 0xaf, 0x7d, 0xfe, 0x4d, 0xa2, 0x10, 0x21,
  38613. 0x88, 0xef, 0x42, 0x2e, 0x8e, 0xfb, 0x63, 0xbc, 0xc8, 0x26, 0xe7, 0x80,
  38614. 0xa5, 0xbf, 0xe0, 0x7a, 0xcb, 0xf3, 0x31, 0x1c, 0xd9, 0xa3, 0x12, 0x00,
  38615. 0x2f, 0x20, 0xc6, 0xc1, 0x15, 0xfd, 0x5b, 0x0d, 0x8a, 0x4d, 0xfb, 0x84,
  38616. 0x4d, 0xb4, 0x64, 0xeb, 0x12, 0xf3, 0x78, 0x6b, 0x4d, 0xc6, 0x98, 0x46,
  38617. 0x4c, 0xb3, 0xb4, 0x59, 0xdc, 0xb7, 0xdc, 0xbb, 0x56, 0x0f, 0x09, 0x14,
  38618. 0x28, 0x43, 0x9f, 0xb8, 0x75, 0xed, 0xcb, 0x97, 0x25, 0xaf, 0xa5, 0xeb,
  38619. 0x46, 0x14, 0xa6, 0x38, 0x68, 0x06, 0xe0, 0x6e, 0x55, 0x68, 0x6b, 0xf3,
  38620. 0xd8, 0x6d, 0x59, 0x65, 0x65, 0xff, 0x48, 0xfd, 0xdb, 0x3d, 0xe2, 0x21,
  38621. 0xb4, 0x7b, 0x78, 0x6a, 0x2e, 0x28, 0xb8, 0x21, 0xc4, 0x72, 0xf4, 0xef,
  38622. 0xfb, 0x74, 0x43, 0x29, 0xf2, 0x30, 0xc9, 0xca, 0x78, 0x93, 0x72, 0xfd,
  38623. 0x84, 0xa4, 0x95, 0xe0, 0xcd, 0xb1, 0x48, 0x29, 0xe7, 0xd1, 0x27, 0xf7,
  38624. 0xdc, 0x31, 0x6e, 0x00, 0x04, 0xd7, 0x7c, 0xfd, 0x2d, 0x25, 0xe9, 0xdb,
  38625. 0xc2, 0xb8, 0x14, 0x26, 0xed, 0x63, 0xb1, 0x50, 0x0a, 0x3c, 0xb2, 0x79,
  38626. 0x98, 0x79, 0x81, 0x2d, 0xdb, 0x60, 0x97, 0x99, 0xc0, 0x0a, 0x89, 0x9f,
  38627. 0x90, 0x19, 0x0b, 0xb3, 0x97, 0xd2, 0xf7, 0x50, 0xa5, 0x1d, 0x7d, 0x71,
  38628. 0x75, 0xe6, 0x58, 0x62, 0x53, 0x95, 0x40, 0x9e, 0xc7, 0xd3, 0x72, 0xa1,
  38629. 0xae, 0x07, 0xb3, 0x8a, 0x56, 0x61, 0x99, 0x81, 0x3e, 0xe4, 0x5e, 0x78,
  38630. 0x57, 0xd1, 0x8a, 0xc4, 0x04, 0x38, 0x13, 0xa0, 0x5d, 0x68, 0x6d, 0x22,
  38631. 0xae, 0xda, 0xfc, 0x67, 0xbb, 0xfb, 0x8e, 0x1a, 0xdc, 0x24, 0xf7, 0xc8,
  38632. 0xf9, 0x92, 0x6f, 0x4e, 0xb5, 0xe7, 0x6d, 0x13, 0x88, 0x05, 0x5c, 0xbb,
  38633. 0xe0, 0x24, 0x2a, 0x96, 0xc6, 0x70, 0x52, 0x14, 0xd0, 0xd9, 0xd8, 0xb2,
  38634. 0x5b, 0xdc, 0x85, 0xcf, 0x62, 0xb4, 0xcf, 0x77, 0xf1, 0xe5, 0x51, 0xeb,
  38635. 0xef, 0xe9, 0x3e, 0xf0, 0x16, 0xd2, 0xcc, 0x38, 0x0a, 0x47, 0x91, 0xc0,
  38636. 0xe0, 0x14, 0x1a, 0xf9, 0x74, 0xd1, 0x32, 0x8b, 0x02, 0x36, 0x05, 0x55,
  38637. 0x62, 0xa7, 0xae, 0x77, 0xb0, 0x01, 0x3d, 0x2c, 0x91, 0xbe, 0xfa, 0xdd,
  38638. 0x9c, 0x17, 0x42, 0xc1, 0x01, 0x4d, 0xd8, 0x27, 0x3c, 0x10, 0x82, 0x66,
  38639. 0x11, 0x91, 0x8b, 0xc8, 0x52, 0xd5, 0xc1, 0x1d, 0xee, 0xb2, 0x90, 0x17,
  38640. 0xed, 0xf3, 0xad, 0xa5, 0xd5, 0xeb, 0xf2, 0x9b, 0x78, 0xbf, 0x2d, 0x5a,
  38641. 0xad, 0xe5, 0x53, 0xe6, 0xc1, 0x3b, 0xd8, 0xf3, 0x6b, 0xc5, 0x4c, 0x87,
  38642. 0x0a, 0xe3, 0xc8, 0xc7, 0xe5, 0x42, 0x2c, 0xe2, 0x13, 0x1a, 0xe7, 0x27,
  38643. 0x20, 0x3e, 0x95, 0x13, 0x1e, 0xbb, 0x03, 0xae, 0xc0, 0x84, 0x14, 0x6d,
  38644. 0x7b, 0xf7, 0x98, 0x08, 0x18, 0x12, 0xb4, 0x4f, 0x99, 0x4a, 0xcf, 0xd0,
  38645. 0x4a, 0x5d, 0x21, 0x16, 0xf6, 0xdf, 0x10, 0xc7, 0xbe, 0xe6, 0x79, 0x3b,
  38646. 0x35, 0x2a, 0xa6, 0xd6, 0x19, 0x9c, 0xde, 0xbd, 0xaf, 0x72, 0xd2, 0x25,
  38647. 0xe0, 0xa4, 0xde, 0x99, 0x44, 0x18, 0x66, 0x41, 0xc7, 0x56, 0xf7, 0xdc,
  38648. 0x32, 0x56, 0x57, 0x39, 0x18, 0x31, 0xc8, 0x75, 0x01, 0xc3, 0xf3, 0x46,
  38649. 0xcf, 0xbf, 0xc6, 0x10, 0xb5, 0x1c, 0x38, 0xf9, 0xa4, 0xa5, 0x44, 0xa1,
  38650. 0x0b, 0x25, 0x48, 0x9c, 0xd3, 0x1c, 0x55, 0x54, 0x15, 0x9f, 0xe3, 0x74,
  38651. 0x5b, 0xb1, 0x92, 0xb6, 0x52, 0x61, 0xba, 0x2f, 0x53, 0x91, 0x17, 0x44,
  38652. 0x94, 0x00, 0xe4, 0x43, 0xa0, 0xe7, 0x0d, 0xaa, 0x8a, 0x5b, 0x81, 0x43,
  38653. 0xad, 0xfb, 0x50, 0xfe, 0xcf, 0x85, 0x2d, 0xfa, 0xc8, 0x1d, 0xad, 0xc8,
  38654. 0x7a, 0x7c, 0x5e, 0xf3, 0x90, 0x35, 0x5e, 0x67, 0xce, 0x57, 0x4d, 0xa0,
  38655. 0x22, 0x9e, 0x07, 0x4a, 0xf5, 0x9e, 0x5f, 0x91, 0x45, 0xd8, 0x62, 0xe0,
  38656. 0xf3, 0x87, 0x3b, 0xb7, 0x89, 0x2f, 0xdf, 0x8b, 0x82, 0xb1, 0x86, 0xc3,
  38657. 0xa4, 0xa3, 0x68, 0xc7, 0x73, 0x9e, 0x68, 0x8d, 0x24, 0x6a, 0x29, 0x94,
  38658. 0x58, 0x57, 0x4b, 0x81, 0x00, 0xe2, 0x2b, 0x94, 0x0a, 0xf5, 0x96, 0xa3,
  38659. 0x23, 0x9a, 0x7b, 0xd0, 0x2d, 0xcb, 0x6a, 0x8e, 0xae, 0x1b, 0x1c, 0x34,
  38660. 0xed, 0x30, 0x4e, 0xca, 0x29, 0x21, 0xfc, 0x3d, 0x70, 0x11, 0xc1, 0x5f,
  38661. 0x3e, 0xc2, 0x9e, 0x88, 0x71, 0x29, 0xa3, 0x8f, 0x92, 0xf5, 0x46, 0x77,
  38662. 0xd5, 0x47, 0x2d, 0x2b, 0x66, 0x1c, 0x07, 0xf0, 0xfc, 0x7b, 0xa0, 0x13,
  38663. 0x00, 0xae, 0xa5, 0x61, 0x92, 0x36, 0xeb, 0x7e, 0x43, 0x91, 0x20, 0x72,
  38664. 0xe5, 0xba, 0x7f, 0x79, 0x23, 0x12, 0x3e, 0xb2, 0x4b, 0x13, 0xa1, 0x8c,
  38665. 0x84, 0x72, 0x3b, 0x45, 0x62, 0xcf, 0x2e, 0x78, 0xc4, 0x9c, 0x22, 0x09,
  38666. 0xfa, 0x59, 0x9d, 0xdf, 0x13, 0x54, 0x66, 0xe2, 0x6f, 0xfa, 0xb5, 0x2a,
  38667. 0x27, 0x3e, 0x17, 0x82, 0xf3, 0x2a, 0x4d, 0x36, 0xd3, 0xf0, 0x8d, 0x43,
  38668. 0x40, 0x2c, 0x84, 0x68, 0xbe, 0x40, 0x50, 0x7d, 0xa3, 0x27, 0x5e, 0xde,
  38669. 0x4d, 0x04, 0x6f, 0xe8, 0x96, 0x9c, 0x7a, 0x1d, 0xb8, 0x2b, 0x8a, 0xb1,
  38670. 0x6e, 0xe2, 0x36, 0x07, 0x22, 0x50, 0xd9, 0x71, 0x93, 0x48, 0xb5, 0x51,
  38671. 0xce, 0x2a, 0x64, 0x6b, 0x11, 0xa6, 0xb9, 0x40, 0x2d, 0x6c, 0xd2, 0x76,
  38672. 0x52, 0xc6, 0xe3, 0xa6, 0x6b, 0xd2, 0x3f, 0x39, 0xd2, 0x13, 0x28, 0xa4,
  38673. 0xa9, 0x58, 0x99, 0xe8, 0x3d, 0x08, 0xfa, 0x3c, 0x34, 0x39, 0x4d, 0x7d,
  38674. 0x5e, 0x10, 0x72, 0x51, 0x96, 0x1d, 0x4b, 0xd9, 0x3e, 0xc9, 0x22, 0x4c,
  38675. 0x72, 0x63, 0xf8, 0x87, 0x4b, 0xe7, 0x41, 0xac, 0xcd, 0xd6, 0x34, 0xa2,
  38676. 0xe1, 0xe8, 0x66, 0x81, 0x04, 0x7d, 0x70, 0x95, 0xba, 0x37, 0x86, 0x9e,
  38677. 0x1f, 0x9a, 0x1b, 0xe4, 0x35, 0xac, 0xe6, 0xcf, 0x48, 0x55, 0x6e, 0xbb,
  38678. 0x9d, 0x40, 0x79, 0x96, 0xdd, 0xac, 0xf8, 0xf5, 0x99, 0xad, 0x43, 0x0d,
  38679. 0xad, 0xa9, 0x62, 0xc0, 0x70, 0x8b, 0x50, 0x9b, 0xca, 0x0d, 0x3e, 0x54,
  38680. 0x9c, 0x27, 0xd5, 0x9e, 0x20, 0xe2, 0xe0, 0xb0, 0xb0, 0xbe, 0x8e, 0x56,
  38681. 0x43, 0x95, 0x9b, 0x34, 0xd1, 0x05, 0x28, 0xa0, 0xee, 0xd9, 0xab, 0x6a,
  38682. 0xa7, 0xbb, 0xb7, 0x1b, 0x3a, 0x5d, 0x33, 0x97, 0x25, 0x54, 0xe4, 0x0e,
  38683. 0x64, 0x79, 0xed, 0x16, 0x62, 0x89, 0x70, 0x4a, 0xa6, 0x47, 0x40, 0xd7,
  38684. 0xa3, 0xd2, 0x6f, 0x28, 0xdd, 0xc5, 0x04, 0xab, 0x7e, 0x7e, 0x1e, 0xb0,
  38685. 0x19, 0x02, 0x48, 0xb5, 0x88, 0x82, 0x75, 0xaf, 0x66, 0x74, 0xca, 0xf6,
  38686. 0xd7, 0xe8, 0x6d, 0xfa, 0x5e, 0xfa, 0xaf, 0xa8, 0x04, 0xaa, 0x2c, 0x09,
  38687. 0xf1, 0x4c, 0x36, 0x75, 0xb5, 0xdc, 0xe8, 0x04, 0x80, 0xd3, 0x14, 0x78,
  38688. 0x09, 0x5b, 0xfd, 0x52, 0x6f, 0xd9, 0x3c, 0x1c, 0x02, 0x3b, 0x77, 0xb8,
  38689. 0xa1, 0xe9, 0xa4, 0xb7, 0x42, 0x62, 0xee, 0xea, 0x43, 0xf3, 0xd8, 0xd0,
  38690. 0x7a, 0x53, 0x91, 0x34, 0x7f, 0xe7, 0x9a, 0xc6
  38691. };
  38692. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38693. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_pub_key[] = {
  38694. 0x15, 0xc9, 0xe5, 0x53, 0x2f, 0xd8, 0x1f, 0xb4, 0xa3, 0x9f,
  38695. 0xae, 0xad, 0xb3, 0x10, 0xd0, 0x72, 0x69, 0xd3, 0x02, 0xf3,
  38696. 0xdf, 0x67, 0x5a, 0x31, 0x52, 0x19, 0xca, 0x39, 0x27, 0x77,
  38697. 0x61, 0x6d, 0x0f, 0xc1, 0x33, 0x26, 0x09, 0xf0, 0xf9, 0x4d,
  38698. 0x12, 0x7a, 0xef, 0xf7, 0x21, 0x26, 0x2c, 0xe0, 0xe2, 0x92,
  38699. 0x1f, 0x9d, 0xd1, 0xaa, 0xaf, 0x08, 0x14, 0xf2, 0xaa, 0x24,
  38700. 0x99, 0x0f, 0x20, 0x57, 0x35, 0x04, 0x32, 0x96, 0x8e, 0x6e,
  38701. 0x10, 0x64, 0xe3, 0xe3, 0x57, 0x26, 0x33, 0x32, 0x7b, 0xe4,
  38702. 0x18, 0x41, 0x77, 0xd3, 0x24, 0x63, 0x3d, 0x11, 0xea, 0xdc,
  38703. 0xbe, 0x59, 0xff, 0x8d, 0xc2, 0xe4, 0xc7, 0x04, 0xf3, 0xd4,
  38704. 0xe0, 0x1d, 0x5e, 0x09, 0x46, 0xbf, 0x02, 0x05, 0xc7, 0xa6,
  38705. 0xb7, 0x82, 0x40, 0x1f, 0x55, 0xe9, 0x77, 0x82, 0xc0, 0xcc,
  38706. 0x86, 0x99, 0x19, 0x99, 0xa2, 0xc9, 0x1b, 0x4f, 0xdd, 0x49,
  38707. 0x4c, 0x78, 0x0a, 0x58, 0xb8, 0xf0, 0x23, 0xac, 0x1a, 0x71,
  38708. 0x57, 0x6d, 0xd6, 0x3a, 0x3a, 0x6f, 0x93, 0xb3, 0x2b, 0x09,
  38709. 0xbe, 0xec, 0x7b, 0x5b, 0xf7, 0x3a, 0xed, 0xf9, 0xd0, 0xb1,
  38710. 0xfe, 0x9f, 0x9b, 0xec, 0x11, 0xb6, 0x6b, 0xd1, 0xb6, 0x00,
  38711. 0x72, 0x7f, 0x68, 0x9a, 0x61, 0xa5, 0xf5, 0x6e, 0xe9, 0x46,
  38712. 0xa4, 0x82, 0x08, 0x9f, 0x50, 0x4c, 0x75, 0xc3, 0x48, 0x85,
  38713. 0x76, 0x39, 0xea, 0x0c, 0xf2, 0xe8, 0x7e, 0x48, 0x69, 0xd9,
  38714. 0x6f, 0x9a, 0x89, 0x7d, 0x98, 0xc1, 0x16, 0xdc, 0x2f, 0xc7,
  38715. 0x0a, 0x11, 0xa8, 0xbb, 0xe7, 0x91, 0xb1, 0x0f, 0x0e, 0xf0,
  38716. 0xb4, 0xc8, 0x41, 0x7e, 0x62, 0x9e, 0x3c, 0x30, 0x4c, 0xbc,
  38717. 0x4c, 0xeb, 0x37, 0xaf, 0x48, 0x72, 0x59, 0x64, 0x8e, 0xfb,
  38718. 0x77, 0x11, 0x28, 0xdd, 0x30, 0x52, 0x8e, 0x69, 0x8c, 0x9f,
  38719. 0x3d, 0xec, 0xdf, 0xa7, 0x5f, 0x42, 0x18, 0xda, 0xba, 0x1a,
  38720. 0x96, 0x91, 0x7d, 0x62, 0xd5, 0x52, 0xff, 0x44, 0xc9, 0x1d,
  38721. 0x29, 0xa6, 0xb9, 0x03, 0x9a, 0x26, 0x26, 0xcf, 0x57, 0x40,
  38722. 0x70, 0x7e, 0x2b, 0xbd, 0xf0, 0x81, 0x71, 0x0f, 0x0b, 0x2e,
  38723. 0x9b, 0x03, 0xba, 0x31, 0x41, 0x68, 0x37, 0xc8, 0xff, 0xea,
  38724. 0xc4, 0x73, 0xa5, 0xf9, 0xc2, 0x92, 0x78, 0x0c, 0xe7, 0xfd,
  38725. 0x5d, 0xb2, 0x01, 0xb5, 0x8d, 0xeb, 0x64, 0xd4, 0x14, 0xea,
  38726. 0x7a, 0xd1, 0x42, 0xc8, 0x99, 0xe4, 0x7d, 0x5b, 0x7e, 0x3b,
  38727. 0x8f, 0xab, 0x82, 0x12, 0xdf, 0xbb, 0xa1, 0x45, 0x30, 0xc9,
  38728. 0x0f, 0xb9, 0xe5, 0xba, 0xe6, 0x8a, 0xf3, 0x78, 0x61, 0xcc,
  38729. 0x9f, 0xe1, 0x46, 0x2a, 0x9a, 0x18, 0x0e, 0x2a, 0x57, 0xf3,
  38730. 0xe5, 0x56, 0xd1, 0x42, 0x48, 0xe1, 0x5a, 0x8e, 0x33, 0xce,
  38731. 0x19, 0xe5, 0x3e, 0x7f, 0x00, 0x70, 0x9c, 0x4c, 0xd3, 0xe1,
  38732. 0x0c, 0xa1, 0x7e, 0xd4, 0xa9, 0x9e, 0x8b, 0xe2, 0xf0, 0xac,
  38733. 0xdb, 0xa6, 0x72, 0x75, 0x67, 0xa6, 0x57, 0xed, 0x79, 0x2e,
  38734. 0xca, 0x8d, 0xeb, 0x9b, 0x9e, 0xb7, 0xbf, 0x30, 0x02, 0x2b,
  38735. 0xb3, 0x43, 0x89, 0x9b, 0xa8, 0x88, 0xa5, 0xbb, 0x33, 0xd9,
  38736. 0x99, 0x30, 0x7c, 0xc7, 0xd4, 0x28, 0x5e, 0x5e, 0x3f, 0x9d,
  38737. 0x6d, 0x35, 0x75, 0x33, 0x8e, 0xff, 0x84, 0x2e, 0x2d, 0xda,
  38738. 0xf0, 0xff, 0x70, 0xe5, 0xb5, 0x62, 0x96, 0x33, 0x3a, 0xd9,
  38739. 0xb5, 0x82, 0x25, 0x81, 0x81, 0x40, 0x5d, 0x4f, 0x11, 0x86,
  38740. 0x63, 0x1a, 0x06, 0xc1, 0x67, 0xc7, 0x49, 0x03, 0xc7, 0xe4,
  38741. 0x6f, 0xb4, 0x13, 0x3e, 0x57, 0x62, 0xfd, 0x8a, 0xc6, 0x2b,
  38742. 0x65, 0x5b, 0xa4, 0x29, 0x57, 0x8d, 0xde, 0xa5, 0xee, 0x32,
  38743. 0xc2, 0x76, 0x03, 0xca, 0xce, 0xc1, 0x48, 0xec, 0x45, 0xcf,
  38744. 0x30, 0x21, 0x28, 0x7f, 0x10, 0x47, 0xd2, 0xdb, 0xee, 0xca,
  38745. 0x5b, 0x0f, 0xd5, 0x39, 0x3a, 0xc3, 0xa6, 0x78, 0xb2, 0x15,
  38746. 0xaf, 0x82, 0x3c, 0x2f, 0xc4, 0x51, 0x5c, 0x52, 0xad, 0xf2,
  38747. 0x89, 0x92, 0x8e, 0xf3, 0x50, 0x38, 0xed, 0xf8, 0xc9, 0x14,
  38748. 0x4c, 0xe4, 0xa3, 0x9a, 0xaf, 0xc4, 0x5c, 0xf3, 0x9f, 0xc3,
  38749. 0xa3, 0xc0, 0xbe, 0x45, 0x1b, 0x21, 0x63, 0xfa, 0xe0, 0xe0,
  38750. 0x91, 0x2b, 0x42, 0xca, 0x91, 0xfb, 0x5e, 0x97, 0x9a, 0x0a,
  38751. 0xd4, 0x88, 0xba, 0xb8, 0x22, 0xc6, 0xbf, 0x56, 0x58, 0x1e,
  38752. 0x92, 0xa9, 0x9d, 0xa7, 0xed, 0xc9, 0xab, 0x54, 0x4f, 0x75,
  38753. 0x8d, 0x42, 0xc1, 0xe1, 0x61, 0xd0, 0x91, 0x9a, 0x3a, 0x40,
  38754. 0x9a, 0xa3, 0xfb, 0x7b, 0x4e, 0xf0, 0x85, 0xf0, 0xdc, 0x40,
  38755. 0x72, 0x9f, 0x05, 0xa8, 0xbe, 0x95, 0x5a, 0x7f, 0xba, 0x75,
  38756. 0x00, 0x6e, 0x95, 0x76, 0xbd, 0xb2, 0x40, 0xf5, 0xb0, 0x64,
  38757. 0x0a, 0x2f, 0x06, 0x3d, 0x9f, 0xac, 0x6a, 0xa5, 0x46, 0x5a,
  38758. 0x85, 0xa4, 0x6f, 0xee, 0x27, 0xa0, 0xeb, 0x5f, 0x1f, 0x91,
  38759. 0xbd, 0x2b, 0x02, 0x16, 0xdf, 0x74, 0x97, 0x2c, 0xd0, 0xa8,
  38760. 0x9f, 0x3a, 0x7b, 0xdf, 0x3e, 0x98, 0x4a, 0x91, 0xdc, 0x19,
  38761. 0x96, 0x88, 0x75, 0x21, 0x1a, 0x6a, 0xa8, 0x4b, 0x1f, 0x35,
  38762. 0xd1, 0x92, 0xf5, 0x76, 0xf4, 0x72, 0x55, 0x13, 0xdb, 0x5d,
  38763. 0x07, 0x8d, 0xd9, 0x72, 0xe4, 0x75, 0xde, 0x80, 0xbc, 0xe9,
  38764. 0x9c, 0xf0, 0x5c, 0x6a, 0x8a, 0x0e, 0x34, 0xf6, 0x3f, 0x5c,
  38765. 0xef, 0x0e, 0xcc, 0x52, 0x38, 0x2d, 0x7b, 0xc2, 0x1b, 0x69,
  38766. 0x9f, 0xe5, 0xed, 0x14, 0xb0, 0x91, 0x0b, 0xe9, 0x4d, 0x34,
  38767. 0xd5, 0xaa, 0xd4, 0xd2, 0x46, 0x39, 0x45, 0x7e, 0x85, 0x2f,
  38768. 0xdb, 0x89, 0xf4, 0xff, 0x05, 0x74, 0x51, 0xba, 0xdd, 0xee,
  38769. 0xf6, 0xc2, 0xc1, 0x0a, 0x8f, 0xd9, 0xeb, 0xc7, 0x61, 0x30,
  38770. 0x8f, 0x86, 0x8b, 0x1f, 0x82, 0xc1, 0x22, 0xfd, 0x83, 0xf4,
  38771. 0x5d, 0xc5, 0x94, 0xf5, 0xd7, 0x17, 0xc7, 0x7b, 0x71, 0xf5,
  38772. 0x5e, 0x15, 0x49, 0x70, 0xb2, 0x57, 0xa0, 0xc0, 0x57, 0x63,
  38773. 0x53, 0x35, 0xb6, 0x52, 0x20, 0x7b, 0x83, 0xd4, 0x57, 0x63,
  38774. 0x25, 0x8e, 0x83, 0xb3, 0x8e, 0x26, 0x1f, 0x09, 0xde, 0x14,
  38775. 0xd6, 0xa6, 0xfc, 0xe5, 0x93, 0x3c, 0x88, 0x8e, 0xf5, 0x10,
  38776. 0x57, 0xb9, 0xc9, 0x9b, 0xff, 0x72, 0x9d, 0x3d, 0x3f, 0x97,
  38777. 0xd9, 0x3c, 0x20, 0xe2, 0x57, 0xfd, 0x2a, 0x5c, 0x17, 0x12,
  38778. 0xe6, 0x08, 0xaf, 0xe4, 0x26, 0x96, 0xb9, 0x6d, 0xc3, 0xac,
  38779. 0x22, 0xf3, 0x8b, 0x89, 0xde, 0xc7, 0x8a, 0x93, 0x06, 0xf7,
  38780. 0x1d, 0x08, 0x21, 0x36, 0x16, 0x74, 0x2b, 0x97, 0x23, 0xe4,
  38781. 0x79, 0x31, 0x08, 0x23, 0x62, 0x30, 0x67, 0xe2, 0xed, 0x30,
  38782. 0x9b, 0x0c, 0xf9, 0x08, 0x7a, 0x29, 0x73, 0xc6, 0x77, 0x8a,
  38783. 0xbb, 0x2a, 0x1c, 0x66, 0xd0, 0xdd, 0x9e, 0xa3, 0xe9, 0x62,
  38784. 0xcc, 0xb7, 0x88, 0x25, 0x4a, 0x5f, 0xbc, 0xaa, 0xe3, 0xe4,
  38785. 0x4f, 0xec, 0xa6, 0x8e, 0xa6, 0xa4, 0x1b, 0x22, 0x2b, 0x2c,
  38786. 0x8f, 0x57, 0x7f, 0xb7, 0x33, 0xfe, 0x16, 0x43, 0x85, 0xc5,
  38787. 0xd2, 0x95, 0xe6, 0xb9, 0x21, 0x68, 0x88, 0x98, 0x33, 0x8c,
  38788. 0x1d, 0x15, 0x9c, 0x4d, 0x62, 0x1f, 0x6b, 0xe8, 0x7a, 0x2d,
  38789. 0x6b, 0x0e, 0xc3, 0xde, 0x1a, 0xa8, 0xed, 0x67, 0xb3, 0xb3,
  38790. 0x36, 0x5b, 0x4b, 0xcb, 0xe8, 0xa8, 0x5c, 0x0b, 0x2f, 0xca,
  38791. 0xd7, 0x71, 0xe8, 0x85, 0xe7, 0x4d, 0xe5, 0x7b, 0x45, 0xed,
  38792. 0xb2, 0x4c, 0x69, 0x04, 0x7e, 0x4f, 0xc0, 0xef, 0x1a, 0xca,
  38793. 0x0d, 0xa6, 0xc4, 0x79, 0x15, 0x78, 0x9c, 0xd2, 0x91, 0x3c,
  38794. 0x32, 0x55, 0x40, 0xe7, 0xcb, 0x7e, 0xde, 0x07, 0xa6, 0x97,
  38795. 0x00, 0x2d, 0x70, 0xf6, 0x3d, 0x15, 0xdf, 0x29, 0x8e, 0xa3,
  38796. 0x96, 0x6d, 0xf2, 0xbb, 0xa5, 0x1b, 0x7b, 0x58, 0x30, 0xf6,
  38797. 0x17, 0xbd, 0xda, 0x13, 0xf7, 0x33, 0xc2, 0x62, 0x32, 0xd4,
  38798. 0x1c, 0x2e, 0x31, 0x74, 0x92, 0xad, 0x99, 0x8c, 0x0e, 0x7c,
  38799. 0x50, 0x21, 0xcd, 0xff, 0x41, 0xeb, 0xd1, 0xca, 0x14, 0xb7,
  38800. 0xb2, 0x31, 0x2f, 0xbe, 0x16, 0xce, 0x4f, 0x26, 0x16, 0x04,
  38801. 0xc2, 0xaf, 0xbe, 0x0d, 0x24, 0xab, 0x9a, 0x21, 0x37, 0x06,
  38802. 0xac, 0x50, 0x23, 0xf1, 0xbe, 0x5c, 0xbb, 0x64, 0xf3, 0xd3,
  38803. 0x66, 0xa3, 0xb8, 0xbe, 0x8b, 0x49, 0x8d, 0xf6, 0xc7, 0xb9,
  38804. 0x8f, 0x4e, 0x31, 0x06, 0x51, 0xe5, 0xf3, 0x0e, 0x56, 0xc4,
  38805. 0x24, 0x30, 0xf5, 0xe9, 0x36, 0x71, 0xbc, 0xc9, 0x70, 0x2c,
  38806. 0x6c, 0x4c, 0x15, 0x43, 0x44, 0xa4, 0xfc, 0xf1, 0xd2, 0x71,
  38807. 0x6c, 0x4c, 0xce, 0x30, 0x6c, 0x05, 0x7d, 0x2e, 0xb7, 0xbc,
  38808. 0xe4, 0x65, 0x76, 0x24, 0x75, 0x36, 0xdf, 0x28, 0xfc, 0xcd,
  38809. 0x9a, 0xba, 0xc2, 0xcd, 0xb0, 0x30, 0xdb, 0xe7, 0x2e, 0x3c,
  38810. 0x92, 0x63, 0x1d, 0x30, 0x23, 0x74, 0xb1, 0xb8, 0xcc, 0xd7,
  38811. 0xb6, 0x90, 0x65, 0x73, 0xa2, 0x2a, 0x6e, 0x49, 0x95, 0x0d,
  38812. 0xab, 0x24, 0xdf, 0x2d, 0xbf, 0x76, 0x46, 0x01, 0x44, 0xe4,
  38813. 0x18, 0x8e, 0xd5, 0x9a, 0x76, 0xc9, 0xc6, 0xbc, 0xdb, 0x7f,
  38814. 0x80, 0x52, 0xc6, 0x40, 0x41, 0x12, 0x36, 0x7c, 0x80, 0x69,
  38815. 0xce, 0x7b, 0xe1, 0xa0, 0x53, 0xa2, 0xd6, 0x8f, 0x3f, 0xf7,
  38816. 0xd7, 0x61, 0x09, 0x70, 0xa2, 0xa0, 0xc6, 0xaf, 0xa0, 0xd0,
  38817. 0xfa, 0x13, 0xbf, 0xc0, 0x69, 0x15, 0xce, 0x15, 0xec, 0x24,
  38818. 0x4b, 0x6b, 0xdc, 0x93, 0x51, 0xc6, 0x82, 0x19, 0x92, 0x84,
  38819. 0x5d, 0x99, 0xb0, 0x90, 0x2c, 0xcc, 0x2a, 0x81, 0x6b, 0x22,
  38820. 0x64, 0x0a, 0xcb, 0x51, 0x25, 0x82, 0x50, 0x02, 0x2d, 0x3e,
  38821. 0xd4, 0x72, 0xb3, 0x0c, 0x15, 0x77, 0xd2, 0xca, 0x98, 0x2f,
  38822. 0x41, 0x93, 0x14, 0xb2, 0x7f, 0xa1, 0x97, 0xa3, 0xb8, 0x8a,
  38823. 0x56, 0x24, 0x38, 0xa7, 0x36, 0xc5, 0x01, 0xc0, 0x9f, 0x3f,
  38824. 0x3e, 0x9a, 0xf6, 0xe9, 0x16, 0x82, 0x01, 0x58, 0x70, 0x0e,
  38825. 0x0d, 0xbc, 0xfa, 0x03, 0x57, 0x65, 0xa8, 0x5a, 0x3d, 0x57,
  38826. 0x81, 0x23, 0xbe, 0x6e, 0xa9, 0xe8, 0x22, 0xdf, 0x2f, 0x70,
  38827. 0xeb, 0x0a, 0x03, 0x96, 0x6b, 0xef, 0x20, 0x9f, 0xf2, 0x62,
  38828. 0xe7, 0xb2, 0x6e, 0x3a, 0x1e, 0x40, 0x1f, 0xd2, 0x97, 0x48,
  38829. 0xd1, 0x18, 0xf0, 0xeb, 0x52, 0x58, 0x02, 0x26, 0xce, 0x75,
  38830. 0xb1, 0x3a, 0x9d, 0x5b, 0x52, 0x94, 0xb2, 0x6e, 0x0e, 0x3f,
  38831. 0x39, 0xb6, 0xd9, 0x8a, 0x9d, 0xe8, 0x7c, 0x83, 0x32, 0xcc,
  38832. 0x43, 0x35, 0x9b, 0x7a, 0xed, 0xb2, 0x1e, 0x51, 0x37, 0x6c,
  38833. 0x14, 0xd8, 0xb8, 0x55, 0xb3, 0x91, 0xef, 0x0c, 0x3a, 0xe5,
  38834. 0x77, 0xd0, 0xbd, 0xb0, 0x7d, 0x38, 0x84, 0x2a, 0x47, 0xb2,
  38835. 0xb6, 0xda, 0xd7, 0x75, 0xd6, 0x2e, 0x60, 0xc7, 0x10, 0x52,
  38836. 0xf7, 0xdd, 0x09, 0x15, 0x6f, 0x04, 0x31, 0xc3, 0x5a, 0x6b,
  38837. 0x0c, 0x60, 0x10, 0xa8, 0x6e, 0x20, 0xa9, 0xdd, 0xb7, 0x72,
  38838. 0xc3, 0x9e, 0x85, 0xd2, 0x8f, 0x16, 0x7e, 0x3d, 0xe0, 0x63,
  38839. 0x81, 0x32, 0xfd, 0xca, 0xbc, 0x0f, 0xef, 0x3e, 0x74, 0x6a,
  38840. 0xb1, 0x60, 0xc1, 0x10, 0x50, 0x7c, 0x67, 0xa4, 0x19, 0xa7,
  38841. 0xb8, 0xed, 0xe6, 0xf5, 0x4e, 0x41, 0x53, 0xa6, 0x72, 0x1b,
  38842. 0x2c, 0x33, 0x6a, 0x37, 0xf1, 0xb5, 0x1c, 0x01, 0x7d, 0xa2,
  38843. 0x1f, 0x2c, 0x4e, 0x0a, 0xbf, 0xd4, 0x2c, 0x24, 0x91, 0x58,
  38844. 0x62, 0xfb, 0xf8, 0x63, 0xd9, 0xf8, 0x78, 0xf5, 0xc7, 0x78,
  38845. 0x32, 0xda, 0x99, 0xeb, 0x58, 0x20, 0x25, 0x19, 0xb1, 0x06,
  38846. 0x7f, 0x6a, 0x29, 0x20, 0xdb, 0xc8, 0x22, 0x48, 0xa9, 0x7f,
  38847. 0x24, 0x54, 0x8d, 0x7d, 0x8d, 0xb1, 0x69, 0xb2, 0xa3, 0x98,
  38848. 0x14, 0x0f, 0xba, 0xfa, 0xb6, 0x15, 0xe8, 0x28, 0x99, 0x3f,
  38849. 0x30, 0x04, 0x50, 0xab, 0x5a, 0x3c, 0xf1, 0x97, 0xe1, 0xc8,
  38850. 0x0f, 0x0e, 0xb4, 0x11, 0x63, 0x5a, 0x79, 0x08, 0x48, 0x75,
  38851. 0xaf, 0x9b, 0xca, 0xd9, 0x13, 0x18, 0xcc, 0xb1, 0xb3, 0xee,
  38852. 0xdd, 0x63, 0xdd, 0xf4, 0x21, 0x98, 0x76, 0xe2, 0x3e, 0xd5,
  38853. 0x86, 0x23, 0x33, 0x7e, 0xc7, 0xb4, 0x35, 0x4b, 0xc2, 0x2d,
  38854. 0xe1, 0xe2, 0xb0, 0x6c, 0x8b, 0x9b, 0x20, 0x3d, 0x48, 0x24,
  38855. 0x7c, 0xea, 0xa1, 0x75, 0x27, 0xe5, 0xf4, 0x70, 0xeb, 0x3b,
  38856. 0xc7, 0x26, 0x37, 0x04, 0xff, 0x8a, 0x7a, 0xd0, 0xc2, 0xb7,
  38857. 0x84, 0xb7, 0x29, 0xfb, 0x0e, 0xa3, 0xa8, 0x71, 0xcd, 0x58,
  38858. 0x06, 0x36, 0xe2, 0xf2, 0x77, 0xcc, 0x0f, 0x78, 0x08, 0x2b,
  38859. 0xbb, 0xe3, 0x53, 0x05, 0x71, 0xdc, 0x6c, 0x37, 0x32, 0x91,
  38860. 0x46, 0x42, 0x4f, 0x21, 0xe0, 0x34, 0xad, 0x3f, 0x30, 0x5a,
  38861. 0xc7, 0x0d, 0x17, 0x19, 0x39, 0x31, 0x58, 0x69, 0x3c, 0x8c,
  38862. 0xbe, 0xe7, 0xa6, 0x3b, 0xad, 0xfb, 0x46, 0x89, 0x06, 0xc1,
  38863. 0x8c, 0x16, 0x9a, 0x06, 0x3a, 0xd0, 0x7e, 0xd6, 0xb0, 0x7b,
  38864. 0x7d, 0xf8, 0x91, 0x7c, 0xfa, 0xd9, 0x66, 0x39, 0xfa, 0xbc,
  38865. 0x57, 0xa7, 0x78, 0x8b, 0x36, 0x78, 0xc0, 0x1c, 0x0e, 0x23,
  38866. 0x05, 0x0e, 0x04, 0x61, 0x16, 0x34, 0xf9, 0xc6, 0x63, 0x58,
  38867. 0xdf, 0xf4, 0x52, 0xce, 0xd0, 0x0f, 0x0c, 0xec, 0xb1, 0x82,
  38868. 0xf4, 0x72, 0x73, 0x72, 0x3f, 0x02, 0xbe, 0xe3, 0x9c, 0x63,
  38869. 0x73, 0xc8, 0x21, 0x65, 0xba, 0x57, 0x52, 0xa9, 0x19, 0xac,
  38870. 0x68, 0x50, 0xbd, 0x2d, 0x72, 0x5b, 0x93, 0x0f, 0x1c, 0x81,
  38871. 0x77, 0xd7, 0x2e, 0xc3, 0x93, 0x52, 0x6e, 0xdc, 0x79, 0x52,
  38872. 0x9f, 0xe3, 0xde, 0xe1, 0xba, 0x58, 0x55, 0xab, 0x8a, 0xf2,
  38873. 0x35, 0x6a, 0xcf, 0x94, 0x1f, 0x17, 0xa4, 0x23, 0x2e, 0x8e,
  38874. 0x18, 0x21, 0xbe, 0x14, 0xfa, 0xe7, 0x59, 0xc5, 0x44, 0x34,
  38875. 0xce, 0x03, 0xf4, 0xb7, 0x75, 0xd3, 0x51, 0x55, 0xdf, 0xff,
  38876. 0xcf, 0x4f, 0x44, 0xee, 0x13, 0x9b, 0xcb, 0x12, 0xae, 0xe5,
  38877. 0x5b, 0x44, 0x65, 0x28, 0xcb, 0x6a, 0x9c, 0x24, 0x1d, 0xea,
  38878. 0x2d, 0x5e, 0xa5, 0xc3, 0x78, 0xad, 0xed, 0x0c, 0x05, 0xa6,
  38879. 0xaf, 0x95, 0x04, 0xd2, 0xb5, 0x91, 0x0e, 0xa0, 0x06, 0x77,
  38880. 0xc5, 0x82, 0xf6, 0xdd, 0x72, 0x83, 0x04, 0xcc, 0xb0, 0xab,
  38881. 0x7a, 0xf0, 0xb4, 0x4d, 0x36, 0x71, 0x72, 0x1a, 0x9a, 0x0d,
  38882. 0xcd, 0xa3, 0x11, 0xa8, 0x0d, 0x7d, 0x49, 0xce, 0x9c, 0x09,
  38883. 0x1d, 0x08, 0xa4, 0x39, 0x2e, 0x03, 0xdf, 0x3a, 0xc8, 0xfe,
  38884. 0x6a, 0x2b, 0x0b, 0x07, 0x80, 0x55, 0x8a, 0xa8, 0xe6, 0x0e,
  38885. 0xc9, 0x7e, 0x83, 0xce, 0x3a, 0x98, 0x98, 0x4e, 0x3e, 0x08,
  38886. 0x20, 0x8f, 0x10, 0xfc, 0xc1, 0xc4, 0xcf, 0x37, 0x8d, 0x69,
  38887. 0xd8, 0x57, 0x9d, 0x48, 0x80, 0x6a, 0xef, 0x0c, 0xdd, 0x27,
  38888. 0x99, 0xf9, 0xe7, 0xd0, 0xd2, 0x36, 0xd8, 0xed, 0x41, 0x14,
  38889. 0x1b, 0x10
  38890. };
  38891. #endif
  38892. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_sig[] = {
  38893. 0xb1, 0xd1, 0x8e, 0x83, 0x0b, 0x0d, 0xd2, 0x71, 0xb2, 0xaa, 0x31, 0x38,
  38894. 0x16, 0xf0, 0xb4, 0xbc, 0x64, 0x2b, 0x97, 0xa1, 0x08, 0x19, 0x4f, 0x52,
  38895. 0xfe, 0x99, 0x1a, 0xa9, 0xd4, 0x08, 0x93, 0x99, 0x88, 0xfd, 0x6a, 0xd6,
  38896. 0xd8, 0xdb, 0xf0, 0x71, 0x2a, 0xc9, 0x04, 0x83, 0xc9, 0x45, 0x59, 0x5d,
  38897. 0xe0, 0x36, 0x59, 0x53, 0x1b, 0xb8, 0x5a, 0xa6, 0x1f, 0xb4, 0x1b, 0x0a,
  38898. 0xfb, 0x3a, 0xba, 0xe3, 0xb7, 0x5e, 0x04, 0x14, 0x59, 0x09, 0x9a, 0x8e,
  38899. 0xc2, 0x77, 0x5a, 0x3d, 0xf1, 0x43, 0x67, 0x74, 0x78, 0xfc, 0xcd, 0x34,
  38900. 0xed, 0x35, 0x16, 0x38, 0x04, 0xe6, 0xe7, 0xd6, 0xd2, 0x90, 0x1b, 0x28,
  38901. 0xb6, 0x66, 0x1b, 0x57, 0x85, 0x5e, 0xa7, 0x9f, 0x86, 0x1a, 0x0d, 0xc3,
  38902. 0x7e, 0xed, 0xbd, 0x32, 0x8a, 0x35, 0xe1, 0xb3, 0x01, 0xdc, 0x9b, 0x44,
  38903. 0x88, 0xa1, 0x0b, 0x87, 0x6e, 0x55, 0x31, 0xb1, 0x27, 0xcb, 0x85, 0xa4,
  38904. 0x27, 0x56, 0x33, 0xb0, 0x39, 0x0d, 0xd3, 0x4b, 0xd1, 0xa2, 0x47, 0x07,
  38905. 0xc6, 0xf4, 0xe6, 0x1f, 0x88, 0x70, 0x70, 0x13, 0x7e, 0x2e, 0x17, 0x32,
  38906. 0x0a, 0x6b, 0x38, 0x34, 0xcf, 0x2f, 0x00, 0x36, 0x58, 0x8d, 0xe1, 0xdd,
  38907. 0xa7, 0x94, 0x2a, 0x8f, 0x87, 0x99, 0x67, 0x02, 0x4d, 0x5b, 0x56, 0xaf,
  38908. 0xef, 0xc4, 0x3c, 0xff, 0x72, 0x53, 0x95, 0x27, 0x03, 0x49, 0x94, 0x4f,
  38909. 0x94, 0x87, 0x1f, 0x52, 0x33, 0xed, 0xb9, 0x14, 0x7b, 0xe5, 0x6c, 0xef,
  38910. 0x7a, 0x17, 0x5a, 0xa4, 0x89, 0x2a, 0xfe, 0x68, 0xda, 0xdd, 0x48, 0xc2,
  38911. 0xf0, 0x92, 0xf4, 0xe4, 0xd6, 0xa6, 0x48, 0x08, 0x2c, 0xe8, 0xcd, 0x72,
  38912. 0xf6, 0x94, 0x3e, 0xc1, 0x82, 0xb8, 0x01, 0x58, 0xb2, 0xef, 0xef, 0xf4,
  38913. 0xcb, 0x93, 0x63, 0x2e, 0x33, 0x5b, 0xc9, 0xd6, 0x6a, 0xde, 0xad, 0xe8,
  38914. 0x1e, 0x3f, 0xa3, 0xf2, 0x35, 0x87, 0xc1, 0xc9, 0x48, 0x2f, 0x1b, 0x00,
  38915. 0xea, 0x3d, 0x04, 0x29, 0xd5, 0xc0, 0xe9, 0x1a, 0xc5, 0xce, 0x5e, 0xdb,
  38916. 0xd1, 0xee, 0x16, 0x9c, 0x05, 0x40, 0xf9, 0x21, 0x13, 0x72, 0x08, 0x39,
  38917. 0x6b, 0x63, 0x19, 0xcd, 0x6f, 0x64, 0xa0, 0xc3, 0x77, 0xb7, 0x50, 0xed,
  38918. 0xe9, 0x2d, 0xd5, 0x72, 0xea, 0xa6, 0xc1, 0x97, 0xb9, 0x6b, 0xe5, 0x81,
  38919. 0x91, 0x8e, 0xd1, 0x36, 0x11, 0xee, 0xfb, 0x2b, 0x66, 0xba, 0xe4, 0x3e,
  38920. 0xd0, 0xdd, 0x17, 0xc5, 0x24, 0x3b, 0xc3, 0x5b, 0x75, 0xfc, 0xd5, 0xb6,
  38921. 0x8c, 0xba, 0x8c, 0x66, 0xb2, 0xee, 0x40, 0x45, 0x8c, 0x23, 0xbb, 0xe0,
  38922. 0xc8, 0xd6, 0x05, 0xfd, 0x71, 0x5b, 0x24, 0xbb, 0x37, 0x65, 0x5f, 0x57,
  38923. 0x92, 0x22, 0x13, 0xb2, 0x9a, 0x70, 0x22, 0x4b, 0xbe, 0x03, 0xd1, 0x54,
  38924. 0xb0, 0x3a, 0x30, 0x50, 0x71, 0x24, 0xf7, 0x81, 0x8c, 0x20, 0x67, 0x74,
  38925. 0x5a, 0xef, 0xa1, 0x6a, 0xe3, 0xd0, 0x04, 0xd6, 0xa5, 0x6e, 0xad, 0xa7,
  38926. 0x15, 0x41, 0xf3, 0x21, 0xe8, 0xd9, 0xe6, 0xe5, 0x97, 0xbd, 0xc2, 0x1b,
  38927. 0xbb, 0xd1, 0x4e, 0x7e, 0x5a, 0xd6, 0xe4, 0x19, 0xa5, 0xe4, 0x76, 0xf4,
  38928. 0xce, 0x00, 0x94, 0x76, 0xef, 0x1b, 0xb3, 0x47, 0xb9, 0xa3, 0x32, 0xf7,
  38929. 0x45, 0x6d, 0x32, 0x73, 0x06, 0xc0, 0xb9, 0xaf, 0x9c, 0x46, 0x99, 0xbe,
  38930. 0x14, 0x06, 0xcd, 0x35, 0x7c, 0x90, 0x7c, 0xe7, 0x97, 0x0a, 0x9f, 0xb4,
  38931. 0x21, 0xff, 0xf0, 0xea, 0x83, 0xc0, 0x86, 0x68, 0x9f, 0x36, 0xb0, 0xad,
  38932. 0xe1, 0x8d, 0xc5, 0x76, 0x55, 0xb5, 0xb6, 0x7e, 0x1f, 0xa7, 0x5b, 0x26,
  38933. 0x6c, 0xb5, 0xf9, 0x54, 0x1f, 0x76, 0xc1, 0x9c, 0xfc, 0x57, 0xc8, 0x86,
  38934. 0xc1, 0x7d, 0x59, 0x55, 0x92, 0xa5, 0xb8, 0x03, 0xfa, 0xa5, 0x72, 0xd1,
  38935. 0x5c, 0x8d, 0x9b, 0x2e, 0x84, 0x07, 0x18, 0xee, 0x49, 0xc5, 0x99, 0x8e,
  38936. 0x15, 0x7c, 0xbf, 0xad, 0x8b, 0x13, 0xcd, 0x97, 0xf9, 0x3c, 0xa2, 0x89,
  38937. 0x9c, 0x9c, 0x89, 0xc9, 0x7a, 0x46, 0xb3, 0x42, 0x7b, 0xd4, 0x28, 0x0d,
  38938. 0x55, 0x63, 0x28, 0xd6, 0xc1, 0x65, 0xf5, 0x34, 0x6e, 0x38, 0x2a, 0xb4,
  38939. 0x35, 0x40, 0xed, 0x7e, 0x80, 0x61, 0x9d, 0x8f, 0x68, 0x4f, 0x74, 0x0c,
  38940. 0x30, 0x35, 0x0e, 0xb3, 0x07, 0xf4, 0x92, 0xed, 0x9c, 0x7f, 0xf5, 0xed,
  38941. 0x3e, 0x17, 0x5b, 0x6e, 0x91, 0x46, 0xa1, 0x25, 0x1d, 0x83, 0x50, 0x93,
  38942. 0x35, 0x06, 0x6c, 0x2f, 0x99, 0x8b, 0x21, 0x4c, 0x5c, 0x34, 0xb1, 0xa7,
  38943. 0x82, 0xbc, 0x70, 0x28, 0x56, 0x61, 0x29, 0x35, 0x89, 0x0b, 0x41, 0x21,
  38944. 0xf0, 0xf7, 0xff, 0x69, 0x3d, 0xa4, 0x28, 0x1e, 0x0d, 0x5d, 0xa7, 0x0e,
  38945. 0xaa, 0xd3, 0x4a, 0x95, 0x49, 0xfe, 0x35, 0x5f, 0xa9, 0xc0, 0xe4, 0xe1,
  38946. 0x9a, 0x03, 0xd4, 0xac, 0x96, 0xe3, 0xea, 0x7e, 0xa6, 0x85, 0x7e, 0xb0,
  38947. 0xb8, 0xc2, 0xe8, 0x07, 0xd6, 0xd3, 0x1a, 0x84, 0x90, 0x24, 0x04, 0xef,
  38948. 0x7c, 0x93, 0x15, 0x83, 0xea, 0xe2, 0x42, 0xc6, 0xe7, 0x13, 0x45, 0xbf,
  38949. 0x35, 0xae, 0x5d, 0x50, 0x79, 0x16, 0xbb, 0x11, 0x17, 0x1b, 0xf4, 0x08,
  38950. 0x88, 0x9d, 0x66, 0x14, 0x6a, 0xa0, 0x71, 0x76, 0x80, 0x51, 0x73, 0x7c,
  38951. 0x1d, 0xb0, 0xc1, 0xad, 0x58, 0xfb, 0xbe, 0xcf, 0x73, 0xe0, 0xd9, 0xf8,
  38952. 0xd5, 0xac, 0xd7, 0x49, 0xd9, 0xc9, 0x59, 0xbf, 0xfa, 0xf5, 0xb1, 0xd2,
  38953. 0x5a, 0x01, 0xcd, 0x8b, 0x07, 0x8b, 0x59, 0x37, 0xc0, 0x8c, 0x7d, 0xa9,
  38954. 0x71, 0x83, 0xf9, 0x7c, 0x58, 0xa9, 0x77, 0x01, 0x3d, 0x39, 0x56, 0x5c,
  38955. 0x93, 0xfe, 0x40, 0x87, 0x5a, 0x31, 0x81, 0x53, 0x8e, 0x0d, 0x99, 0x7e,
  38956. 0xdf, 0x37, 0xd9, 0xe3, 0x91, 0xb8, 0x60, 0x3a, 0x5b, 0xca, 0xe8, 0x91,
  38957. 0x56, 0x89, 0x59, 0x61, 0xc6, 0x31, 0xe2, 0x6c, 0x81, 0xda, 0xc7, 0x5c,
  38958. 0x04, 0x9d, 0xe4, 0x23, 0x12, 0x73, 0xfc, 0x48, 0xfb, 0xa5, 0xce, 0x87,
  38959. 0x37, 0x47, 0x71, 0x5c, 0xd1, 0x2a, 0x63, 0x89, 0xdc, 0x07, 0xe7, 0x7f,
  38960. 0x5d, 0x48, 0xe6, 0xd2, 0x96, 0xc6, 0x6f, 0xed, 0xee, 0x8c, 0xed, 0x5e,
  38961. 0x41, 0x38, 0xbd, 0xdf, 0x21, 0xaa, 0x9e, 0x51, 0x16, 0x22, 0x4a, 0xdc,
  38962. 0xd8, 0x12, 0xdf, 0x5a, 0x83, 0xd6, 0xd0, 0x07, 0xa4, 0x42, 0x41, 0x13,
  38963. 0xe1, 0x08, 0xc9, 0x00, 0x0f, 0x37, 0xc0, 0x7d, 0xda, 0xb2, 0x25, 0xfc,
  38964. 0xc9, 0xbc, 0xa8, 0x86, 0xcc, 0x38, 0x0e, 0x06, 0x51, 0x1b, 0x37, 0xc1,
  38965. 0x0e, 0x2a, 0x58, 0x49, 0xbc, 0x7c, 0xa7, 0xf0, 0xda, 0xd7, 0x74, 0x34,
  38966. 0xf5, 0xd8, 0x99, 0x8c, 0x94, 0x86, 0xe3, 0x1e, 0x6b, 0xf5, 0x68, 0xfa,
  38967. 0xa6, 0x69, 0x63, 0x22, 0x5a, 0x3c, 0x6f, 0x29, 0xc9, 0x40, 0xc0, 0xbe,
  38968. 0x8d, 0xb5, 0xcc, 0x82, 0x6e, 0x9d, 0xd1, 0x1f, 0x13, 0x63, 0xd8, 0x24,
  38969. 0x63, 0x38, 0x59, 0xf0, 0x4a, 0x8c, 0x0f, 0x28, 0x8a, 0x77, 0x81, 0xa2,
  38970. 0xa0, 0x23, 0x11, 0x59, 0xa9, 0x5a, 0x2d, 0x71, 0x8f, 0x82, 0xa7, 0xbd,
  38971. 0x85, 0x26, 0x4d, 0xc2, 0x2f, 0x11, 0xe8, 0xff, 0x96, 0xa1, 0x2d, 0xf2,
  38972. 0xd5, 0xf3, 0x1d, 0x54, 0xd0, 0x5f, 0x71, 0x07, 0xaf, 0x22, 0xa0, 0xcd,
  38973. 0x78, 0xb3, 0x47, 0xb1, 0x40, 0x3d, 0x6b, 0xfd, 0x10, 0x1b, 0xc6, 0x60,
  38974. 0xef, 0x5c, 0x24, 0xa3, 0x1f, 0xee, 0xc0, 0x0b, 0xed, 0x1d, 0x38, 0xc8,
  38975. 0xf2, 0x8c, 0xec, 0x5e, 0xd9, 0x70, 0x1a, 0x2b, 0x25, 0xe6, 0xed, 0xa9,
  38976. 0x0c, 0xb3, 0x78, 0xe1, 0x91, 0x01, 0x41, 0x2e, 0xfe, 0x7d, 0xbd, 0xfe,
  38977. 0xcf, 0x48, 0x6d, 0x2e, 0x05, 0x31, 0x89, 0x24, 0xc4, 0xd7, 0xc4, 0x26,
  38978. 0x2f, 0x64, 0x43, 0xa3, 0xdd, 0x56, 0x11, 0x5c, 0x65, 0x76, 0x96, 0xcc,
  38979. 0x3c, 0x12, 0x42, 0xf2, 0x6b, 0x20, 0xc2, 0xe6, 0xc3, 0x5c, 0xfa, 0x91,
  38980. 0xb1, 0xbd, 0x3b, 0xd3, 0x99, 0xde, 0x59, 0x7a, 0x34, 0x40, 0x56, 0xb0,
  38981. 0x88, 0x02, 0x19, 0xc8, 0xf9, 0xf9, 0x8f, 0xe7, 0x60, 0xfb, 0x42, 0x87,
  38982. 0x57, 0xb4, 0x42, 0xb4, 0x65, 0x94, 0x0a, 0x5f, 0xdb, 0xf5, 0x32, 0xe9,
  38983. 0x49, 0x28, 0xbe, 0xa6, 0x64, 0x0d, 0x6d, 0x08, 0x43, 0x91, 0x16, 0x7a,
  38984. 0x6c, 0xa9, 0x02, 0xe4, 0x84, 0x03, 0x39, 0x48, 0x08, 0xcc, 0xcb, 0x56,
  38985. 0xad, 0x52, 0x95, 0x9e, 0x9a, 0x2b, 0xf1, 0x6d, 0x3f, 0x4b, 0x02, 0xc6,
  38986. 0x52, 0xc7, 0x09, 0x6b, 0x3f, 0xa9, 0x60, 0xe2, 0x19, 0x5d, 0x0a, 0x61,
  38987. 0xcd, 0xc8, 0x36, 0xdb, 0x8e, 0x57, 0xd2, 0x11, 0x49, 0x1c, 0x26, 0x58,
  38988. 0x04, 0x07, 0x32, 0x2a, 0x34, 0xf0, 0x6a, 0x88, 0xcf, 0x63, 0xb7, 0xef,
  38989. 0x7e, 0x93, 0xcc, 0x64, 0x07, 0x14, 0xfa, 0x63, 0x38, 0xdd, 0xc0, 0xf0,
  38990. 0xaa, 0x56, 0xa1, 0xed, 0x16, 0xaa, 0x53, 0x8c, 0x99, 0xc0, 0xd4, 0xda,
  38991. 0x94, 0x58, 0x13, 0xd9, 0x5f, 0x98, 0x9a, 0xa1, 0x57, 0xbd, 0x89, 0xca,
  38992. 0x9d, 0x3e, 0xdf, 0x75, 0x26, 0x29, 0x0f, 0xb2, 0x33, 0x4b, 0x83, 0xb3,
  38993. 0x99, 0x1f, 0x06, 0x5d, 0x10, 0xf5, 0x1c, 0x75, 0x97, 0xec, 0x5b, 0x87,
  38994. 0xc7, 0xf1, 0xd8, 0xbd, 0x0e, 0x4c, 0x1a, 0xb0, 0x59, 0x3b, 0x27, 0x73,
  38995. 0xdc, 0xde, 0xca, 0x0c, 0x2e, 0x1f, 0x42, 0x7f, 0xd8, 0x0f, 0x9b, 0x3f,
  38996. 0x49, 0x3f, 0x63, 0x7d, 0x71, 0xe3, 0x77, 0x79, 0xcc, 0x9c, 0xbf, 0xff,
  38997. 0x23, 0xa9, 0x74, 0xa2, 0xda, 0xb7, 0xca, 0x86, 0x7f, 0x12, 0xc1, 0x1b,
  38998. 0x41, 0x35, 0xb5, 0xc7, 0x10, 0x09, 0xc0, 0xa2, 0x1b, 0x41, 0x31, 0x5e,
  38999. 0x6c, 0x35, 0xb5, 0x63, 0x13, 0x19, 0x61, 0x8e, 0xbd, 0x89, 0xf6, 0x0a,
  39000. 0xbd, 0x16, 0x15, 0xd8, 0xfa, 0xcc, 0x9f, 0x97, 0x02, 0x8f, 0x1b, 0x34,
  39001. 0x40, 0xbc, 0x4a, 0xb1, 0x39, 0x12, 0xf8, 0x66, 0xda, 0x34, 0x03, 0xf2,
  39002. 0x5c, 0x33, 0x9c, 0x63, 0x0b, 0xb6, 0x8f, 0xca, 0x81, 0xa2, 0x4a, 0x43,
  39003. 0xe7, 0xe7, 0x66, 0x41, 0x45, 0x6b, 0x7c, 0xd1, 0x1d, 0xbc, 0x4f, 0x91,
  39004. 0xab, 0x24, 0x0b, 0x9f, 0x60, 0x47, 0x36, 0x04, 0x8b, 0x72, 0xb6, 0x65,
  39005. 0x35, 0xfc, 0xbf, 0xc9, 0x26, 0xaf, 0x84, 0x04, 0x30, 0x32, 0x02, 0xc0,
  39006. 0x94, 0x98, 0xbc, 0x17, 0x33, 0x99, 0xac, 0xb1, 0x4e, 0xdd, 0xf0, 0x46,
  39007. 0x68, 0x6a, 0xac, 0x6d, 0xdb, 0x85, 0xfd, 0xc6, 0x3b, 0xc8, 0x93, 0x89,
  39008. 0xbf, 0xd7, 0xd9, 0x94, 0xe4, 0xa4, 0x37, 0xb9, 0x67, 0x52, 0x84, 0xcf,
  39009. 0x88, 0xba, 0x01, 0x8b, 0xe4, 0xd4, 0x3e, 0xde, 0x94, 0xa1, 0xa9, 0xd8,
  39010. 0x15, 0xb5, 0x6e, 0xa0, 0x62, 0x92, 0x5c, 0xb1, 0x1b, 0xbf, 0x4f, 0xaf,
  39011. 0xf5, 0x99, 0x35, 0xce, 0x7d, 0xa9, 0x4b, 0xa8, 0x60, 0x31, 0xf5, 0x0a,
  39012. 0x83, 0x58, 0xf5, 0x83, 0xde, 0xb2, 0xfe, 0xf3, 0x12, 0x08, 0x3d, 0xe3,
  39013. 0x14, 0x89, 0x17, 0x93, 0x5c, 0x87, 0xe4, 0x89, 0xcb, 0xb7, 0x67, 0x3e,
  39014. 0xea, 0x0e, 0x08, 0x57, 0xf1, 0xca, 0xe0, 0x18, 0xd7, 0xae, 0x5f, 0x9e,
  39015. 0x62, 0x5c, 0xd7, 0x6a, 0x2f, 0xd6, 0x30, 0x67, 0xfb, 0x5e, 0xed, 0xcf,
  39016. 0xa9, 0x88, 0x04, 0x0a, 0xf2, 0x62, 0x50, 0xc5, 0x39, 0xc6, 0xa1, 0x3c,
  39017. 0xe4, 0x9a, 0x81, 0x55, 0x96, 0xca, 0x60, 0xb2, 0x53, 0x62, 0xee, 0xa1,
  39018. 0x1d, 0xfc, 0xd9, 0x5c, 0x51, 0xbf, 0x55, 0x65, 0x1d, 0x13, 0x2a, 0x13,
  39019. 0x58, 0xa3, 0x18, 0x52, 0x6b, 0xb4, 0xae, 0x60, 0x1c, 0x26, 0x3e, 0xb1,
  39020. 0x4c, 0xb1, 0x72, 0x1b, 0x8a, 0x4c, 0xaa, 0xb5, 0x5b, 0x8a, 0x3b, 0x2f,
  39021. 0x1f, 0xc3, 0x29, 0x41, 0xe6, 0x6d, 0xd7, 0x96, 0x26, 0xdd, 0x37, 0x67,
  39022. 0x4f, 0x9d, 0x31, 0xc6, 0x54, 0x51, 0xaa, 0xba, 0x73, 0xae, 0xd2, 0x00,
  39023. 0x0b, 0x05, 0x98, 0x73, 0xd6, 0x9c, 0xb4, 0x2e, 0x23, 0xd0, 0xc3, 0xac,
  39024. 0x46, 0x6f, 0x3e, 0x05, 0x43, 0xf8, 0x96, 0xa0, 0xe0, 0xfe, 0x17, 0x3f,
  39025. 0xfa, 0xc2, 0xc3, 0xf6, 0x1a, 0x46, 0xd0, 0x05, 0x53, 0x0e, 0xea, 0xd8,
  39026. 0xba, 0xa3, 0xab, 0xb6, 0x58, 0xd1, 0x40, 0x1c, 0x97, 0x38, 0xd4, 0x77,
  39027. 0x58, 0x03, 0xf5, 0x8a, 0xc7, 0x48, 0x19, 0x71, 0x71, 0xb5, 0x4b, 0x08,
  39028. 0x85, 0x35, 0x1c, 0xdf, 0xbd, 0xa9, 0xc9, 0xd1, 0x40, 0x62, 0xa3, 0xd6,
  39029. 0x3b, 0xa1, 0xf7, 0x4e, 0xc6, 0xfe, 0xc4, 0x07, 0x2f, 0xf5, 0xc9, 0x0c,
  39030. 0xb6, 0xa0, 0xb3, 0x25, 0x3e, 0x2a, 0x07, 0xe3, 0x63, 0xe3, 0x9e, 0x8d,
  39031. 0x0d, 0x7a, 0x70, 0x1e, 0x65, 0x95, 0x47, 0x37, 0xa8, 0xd2, 0x35, 0x09,
  39032. 0x09, 0x70, 0xf5, 0xc9, 0xc9, 0x30, 0x95, 0xd9, 0xf2, 0x5d, 0x10, 0x3c,
  39033. 0xc3, 0x66, 0x66, 0xb6, 0xdc, 0x14, 0xf6, 0x91, 0xc2, 0x7b, 0x4b, 0x71,
  39034. 0x42, 0xf9, 0x35, 0xe7, 0x08, 0x1e, 0xb6, 0x9a, 0x5c, 0x0e, 0x8b, 0x41,
  39035. 0x44, 0x7f, 0xad, 0xca, 0x8a, 0x4b, 0x6a, 0x02, 0x81, 0x96, 0xe7, 0xe1,
  39036. 0xb0, 0x5b, 0xaf, 0xf2, 0x17, 0x44, 0x7f, 0xd1, 0x49, 0x77, 0xfd, 0x07,
  39037. 0x59, 0x53, 0x8e, 0x51, 0xac, 0x0f, 0x0c, 0xb4, 0xa3, 0xf6, 0x24, 0x16,
  39038. 0x47, 0xf3, 0xa4, 0x36, 0x17, 0x3e, 0x01, 0x1e, 0xf1, 0xec, 0x78, 0x4a,
  39039. 0xcb, 0xbd, 0x2a, 0xfd, 0x01, 0xdd, 0xa5, 0xad, 0x7b, 0xef, 0x5e, 0x56,
  39040. 0xb2, 0x60, 0xb4, 0xf2, 0x27, 0xc8, 0x9b, 0x5b, 0x31, 0x49, 0x54, 0xbc,
  39041. 0x69, 0x9b, 0xc6, 0x1a, 0x79, 0xe7, 0xd4, 0x46, 0xc8, 0x50, 0xc3, 0xaa,
  39042. 0xfc, 0xb5, 0x28, 0x87, 0x1e, 0xa0, 0x0c, 0xc6, 0x1a, 0xa7, 0x34, 0xd6,
  39043. 0xbb, 0x9d, 0x9c, 0x0d, 0x90, 0x6f, 0x1a, 0x3c, 0xdc, 0x3b, 0x95, 0xc4,
  39044. 0x38, 0x25, 0x7a, 0xc6, 0x46, 0x82, 0x9f, 0x68, 0xca, 0x6a, 0x63, 0xa7,
  39045. 0x99, 0xfe, 0x64, 0xe6, 0x6f, 0x11, 0xcd, 0x2c, 0x76, 0x1e, 0xe6, 0x08,
  39046. 0xb8, 0x33, 0x64, 0x43, 0x51, 0xbd, 0x52, 0xf7, 0x05, 0x06, 0xd5, 0xcc,
  39047. 0x6a, 0xde, 0x1a, 0xa2, 0xbe, 0xf8, 0x8c, 0x44, 0x5e, 0x2d, 0xc2, 0x28,
  39048. 0xcd, 0x9a, 0x53, 0x04, 0x96, 0xcc, 0x1e, 0xbb, 0x96, 0x07, 0xc9, 0x17,
  39049. 0x04, 0xf8, 0xd8, 0xd9, 0xdd, 0x35, 0x35, 0x3d, 0x53, 0x30, 0x60, 0xb3,
  39050. 0x87, 0x5d, 0xf3, 0xe5, 0xa7, 0x20, 0x30, 0x9d, 0xb0, 0x5b, 0xc4, 0x36,
  39051. 0xf7, 0xd7, 0xb6, 0x3e, 0x44, 0x98, 0x99, 0xe7, 0xc3, 0x29, 0xcb, 0x70,
  39052. 0xc4, 0x91, 0x8b, 0xfc, 0x63, 0x60, 0x29, 0x95, 0xeb, 0x61, 0x7f, 0xdf,
  39053. 0xf7, 0x3a, 0x69, 0x3a, 0xeb, 0xa1, 0x73, 0x1d, 0x13, 0x18, 0x29, 0x2c,
  39054. 0x89, 0x82, 0x56, 0x42, 0xe7, 0xa3, 0xba, 0xe9, 0x59, 0x2e, 0xfd, 0xff,
  39055. 0xb6, 0xf7, 0xbd, 0x2a, 0xc9, 0xff, 0x4c, 0x63, 0xef, 0x54, 0x63, 0x82,
  39056. 0x7c, 0xa5, 0x11, 0x44, 0xc7, 0x68, 0xf5, 0x7b, 0x44, 0x2c, 0xee, 0xab,
  39057. 0xa3, 0x84, 0x5a, 0x99, 0x28, 0x98, 0x97, 0x2e, 0x8b, 0x07, 0x09, 0x6c,
  39058. 0xea, 0xc1, 0x81, 0x0b, 0xe0, 0xc4, 0xb7, 0xc2, 0x73, 0xbe, 0x8b, 0x72,
  39059. 0xf8, 0xc9, 0x8d, 0x50, 0x28, 0xf2, 0x95, 0x54, 0x8a, 0x3b, 0x23, 0x86,
  39060. 0xc4, 0xe8, 0xe8, 0xe5, 0x45, 0x0d, 0xdf, 0xa3, 0xe6, 0x00, 0x71, 0xe8,
  39061. 0x20, 0xd2, 0x6d, 0x22, 0x23, 0xaf, 0x37, 0x04, 0x55, 0x05, 0x8d, 0xc9,
  39062. 0x38, 0x38, 0x12, 0x4c, 0x9f, 0x28, 0x56, 0x14, 0x76, 0xe5, 0x10, 0x54,
  39063. 0xd9, 0x68, 0xca, 0xc3, 0x97, 0x9f, 0xd2, 0x25, 0x2c, 0x0d, 0xa0, 0xff,
  39064. 0xea, 0xab, 0x61, 0xd2, 0xb2, 0x06, 0xc2, 0x93, 0xfd, 0x5a, 0xfe, 0xe3,
  39065. 0x98, 0xbf, 0x37, 0x2e, 0xa5, 0x74, 0x56, 0xd0, 0x7a, 0x5a, 0x23, 0x3b,
  39066. 0xd2, 0xa0, 0x1f, 0x4b, 0xeb, 0x7f, 0x5a, 0xc5, 0x51, 0x79, 0xf6, 0x95,
  39067. 0x19, 0x50, 0xb1, 0x6a, 0x80, 0xcb, 0xcf, 0x19, 0xa4, 0x67, 0xf4, 0x08,
  39068. 0x0f, 0x6a, 0xd9, 0x3f, 0x15, 0x96, 0x2c, 0x6d, 0xd5, 0x69, 0x7a, 0x56,
  39069. 0x4d, 0x17, 0xc8, 0xcb, 0xba, 0x9b, 0x6e, 0x65, 0xa2, 0x3d, 0x66, 0xed,
  39070. 0xea, 0xe2, 0x54, 0x88, 0x6c, 0xc1, 0x1a, 0x11, 0xde, 0x4e, 0x0c, 0x8a,
  39071. 0x42, 0x04, 0xe1, 0x77, 0xc3, 0x0c, 0xff, 0x10, 0x7d, 0x4a, 0x45, 0x3f,
  39072. 0xb8, 0x40, 0xf9, 0x75, 0x76, 0x9f, 0x65, 0x42, 0x2f, 0x78, 0x5b, 0x0b,
  39073. 0x32, 0xbc, 0x45, 0xfc, 0xd4, 0x29, 0x49, 0x34, 0x76, 0xda, 0x5f, 0xe8,
  39074. 0x39, 0x35, 0x9e, 0xba, 0x7f, 0x19, 0x7e, 0x14, 0xe6, 0x71, 0x9c, 0x72,
  39075. 0x6a, 0xce, 0xcc, 0xa6, 0x72, 0x73, 0x3f, 0x4e, 0x9b, 0x9e, 0x94, 0x0c,
  39076. 0xce, 0x00, 0x15, 0xb4, 0x50, 0xff, 0xcf, 0xcd, 0x78, 0xd3, 0x08, 0x0e,
  39077. 0x95, 0x48, 0x24, 0x13, 0x16, 0x54, 0xb4, 0xe0, 0xa9, 0x29, 0xa3, 0x05,
  39078. 0x77, 0x2f, 0x5d, 0x47, 0x6a, 0xa5, 0xb0, 0x4e, 0xf3, 0xa9, 0x4a, 0x82,
  39079. 0xb9, 0x2c, 0x26, 0x07, 0x9c, 0x33, 0xc6, 0x68, 0xc2, 0xe0, 0xc0, 0x7d,
  39080. 0x70, 0x48, 0x74, 0xb9, 0xf5, 0x1e, 0x6c, 0x15, 0x7f, 0xba, 0xe5, 0xa1,
  39081. 0xb4, 0x36, 0x41, 0x20, 0xf4, 0x2d, 0x97, 0x27, 0x0b, 0x10, 0x30, 0x57,
  39082. 0x7f, 0x38, 0x66, 0xe1, 0xc4, 0xf6, 0xa4, 0xc9, 0x8d, 0xbc, 0x2b, 0x4f,
  39083. 0x14, 0xb3, 0xf0, 0x1e, 0x80, 0x70, 0xc0, 0x0f, 0x69, 0x06, 0xe7, 0x95,
  39084. 0xd1, 0x53, 0x65, 0x49, 0x1c, 0xa8, 0xfa, 0x9e, 0x2b, 0xcc, 0x33, 0x71,
  39085. 0x76, 0xa4, 0x0b, 0x4a, 0xc7, 0xea, 0xa0, 0xfa, 0x1b, 0x2b, 0xfb, 0xa5,
  39086. 0x59, 0x06, 0x2a, 0xef, 0x4b, 0xbf, 0x05, 0x4b, 0x87, 0x70, 0x3c, 0xde,
  39087. 0xc7, 0xb2, 0x4f, 0xf2, 0x5b, 0x1a, 0xbe, 0xda, 0x04, 0x31, 0x57, 0xff,
  39088. 0xf2, 0xa5, 0x43, 0x12, 0xff, 0x8d, 0xf4, 0x99, 0x05, 0xe1, 0x34, 0xa9,
  39089. 0xb9, 0x0a, 0xb3, 0x1f, 0x3d, 0x6d, 0x0d, 0xb7, 0xd3, 0x35, 0x0b, 0x04,
  39090. 0x44, 0x77, 0x60, 0xc0, 0x96, 0x99, 0x7b, 0xa8, 0x8e, 0x79, 0x4a, 0x96,
  39091. 0x24, 0xef, 0xb1, 0xf4, 0x8a, 0x2f, 0x3e, 0x08, 0xf3, 0x3d, 0xf2, 0xfe,
  39092. 0x5f, 0x0a, 0xf7, 0x0a, 0xf5, 0xd8, 0xf2, 0xa0, 0x1b, 0xe7, 0x9e, 0xc9,
  39093. 0x0b, 0xcf, 0x58, 0x97, 0x92, 0x90, 0xad, 0x3d, 0xfc, 0x42, 0xc1, 0x7f,
  39094. 0x39, 0xe8, 0xd1, 0x35, 0x14, 0x8a, 0xb3, 0x77, 0xb1, 0xa9, 0xdb, 0xb4,
  39095. 0x3a, 0x3d, 0xeb, 0x59, 0x0b, 0x5b, 0x3a, 0x63, 0x54, 0x70, 0xda, 0xf0,
  39096. 0xf0, 0xb9, 0xe6, 0x07, 0x69, 0x27, 0x9d, 0xc6, 0xb6, 0x00, 0x2d, 0xd6,
  39097. 0xc7, 0xd7, 0x2e, 0xf8, 0x9c, 0xfe, 0x4c, 0xfb, 0xc0, 0x7b, 0xbf, 0xa2,
  39098. 0x25, 0xb8, 0x2a, 0x5c, 0x06, 0xca, 0x12, 0x2c, 0x96, 0xa4, 0x27, 0xa6,
  39099. 0x73, 0x0b, 0xb8, 0x42, 0x93, 0x51, 0x87, 0xfe, 0xe6, 0x8f, 0xca, 0x00,
  39100. 0x53, 0xdc, 0xc0, 0x38, 0x03, 0x9e, 0x66, 0x13, 0x84, 0x68, 0xe7, 0x04,
  39101. 0x93, 0x79, 0x0c, 0x3e, 0x4c, 0x90, 0xe2, 0xf7, 0x81, 0x15, 0x49, 0x05,
  39102. 0xe1, 0x8f, 0xe6, 0xfc, 0xc8, 0x40, 0xae, 0x3d, 0x7a, 0x16, 0xec, 0xc6,
  39103. 0x39, 0xa5, 0x04, 0x95, 0x35, 0xac, 0xdd, 0x0d, 0x19, 0xd6, 0xa9, 0xd9,
  39104. 0xd2, 0x53, 0x71, 0x31, 0x38, 0xa2, 0xf1, 0x9c, 0x13, 0x2c, 0x8c, 0x21,
  39105. 0x9c, 0x3a, 0x1b, 0xf2, 0xd8, 0x4c, 0xeb, 0xe9, 0x8b, 0x27, 0x52, 0xd3,
  39106. 0x6c, 0x01, 0xc0, 0x60, 0x32, 0x8c, 0x6e, 0xfb, 0xd6, 0xd6, 0x1b, 0xc6,
  39107. 0x93, 0xff, 0xdc, 0xdb, 0x38, 0xf5, 0x0e, 0xd5, 0x15, 0xcd, 0x65, 0x76,
  39108. 0x78, 0x42, 0x13, 0x37, 0x6b, 0x2e, 0xe8, 0xe2, 0x54, 0x4d, 0x45, 0x34,
  39109. 0x73, 0x1b, 0x61, 0x35, 0x2c, 0xf7, 0x20, 0x3e, 0xe9, 0x7c, 0xf0, 0xf3,
  39110. 0xba, 0x41, 0xfc, 0x49, 0xe4, 0x5d, 0xd4, 0xb8, 0x07, 0x15, 0x7b, 0x16,
  39111. 0xc7, 0x7f, 0x78, 0xef, 0xd6, 0x53, 0x3f, 0xe4, 0xa6, 0x33, 0xcf, 0xcc,
  39112. 0x78, 0x53, 0x0c, 0x59, 0xf7, 0x28, 0xa5, 0x83, 0x2b, 0x5a, 0xd3, 0xd6,
  39113. 0xb7, 0xb2, 0xd1, 0x73, 0x63, 0xa9, 0xad, 0x16, 0xf2, 0xed, 0x48, 0x6e,
  39114. 0x88, 0x22, 0xbd, 0x16, 0x9d, 0x6a, 0xc2, 0x48, 0x83, 0xdf, 0x40, 0xb7,
  39115. 0x0a, 0x50, 0x23, 0x3d, 0x58, 0x50, 0x00, 0x02, 0x04, 0xd2, 0x31, 0x72,
  39116. 0x28, 0x7b, 0x10, 0x96, 0xe0, 0xe7, 0x3f, 0xe0, 0xd0, 0x61, 0x70, 0x5c,
  39117. 0x0a, 0xdb, 0xc0, 0x7b, 0xea, 0xef, 0xba, 0xc0, 0x90, 0xe0, 0xf9, 0x0e,
  39118. 0x83, 0x8c, 0x3b, 0x05, 0x2b, 0xb6, 0xcb, 0xbb, 0x37, 0xa1, 0xd3, 0x28,
  39119. 0x02, 0x40, 0xe3, 0x76, 0xbf, 0x27, 0x0b, 0x4f, 0x82, 0xb9, 0x22, 0xee,
  39120. 0x0b, 0x3a, 0xcb, 0xcc, 0x56, 0x13, 0x51, 0xb8, 0xb6, 0x2d, 0xd3, 0x6c,
  39121. 0x96, 0x10, 0xd9, 0x51, 0x24, 0x7b, 0x2b, 0xb8, 0x7b, 0xbd, 0x8d, 0xd9,
  39122. 0xf2, 0x50, 0x61, 0xbb, 0x0c, 0xb7, 0x71, 0x65, 0x3a, 0x25, 0x18, 0x09,
  39123. 0x1a, 0x9d, 0x41, 0xf4, 0xdb, 0x5a, 0x1c, 0x61, 0x0a, 0xbb, 0x43, 0x27,
  39124. 0x8a, 0xa8, 0x83, 0x60, 0x8c, 0x5d, 0x4c, 0x9b, 0xa9, 0xe5, 0xa7, 0x67,
  39125. 0x99, 0x98, 0xdc, 0x7a, 0x3a, 0x55, 0x0d, 0x25, 0x69, 0x47, 0x21, 0xb1,
  39126. 0xd7, 0x0c, 0x0c, 0x43, 0x58, 0xc9, 0xbf, 0x74, 0x91, 0x1b, 0x2b, 0xf3,
  39127. 0x29, 0x8d, 0x10, 0x41, 0xaf, 0xdd, 0x42, 0x0a, 0x71, 0xe3, 0xb8, 0x4d,
  39128. 0x3a, 0xf3, 0x9c, 0x5a, 0x46, 0x4e, 0x70, 0xbe, 0xdb, 0x0d, 0x03, 0xee,
  39129. 0xcb, 0xfb, 0x61, 0x45, 0xbd, 0x25, 0xb4, 0x72, 0xd1, 0x51, 0x03, 0x19,
  39130. 0x82, 0x53, 0x83, 0x18, 0xab, 0xa3, 0x6c, 0x9e, 0xa2, 0xe9, 0x15, 0xb1,
  39131. 0x74, 0x61, 0xa1, 0xaf, 0x09, 0x4b, 0x4a, 0x34, 0x9b, 0xd0, 0xd2, 0x80,
  39132. 0x43, 0xd9, 0x90, 0x53, 0x71, 0x38, 0xb9, 0x80, 0x58, 0x1b, 0x9f, 0x9e,
  39133. 0xfe, 0x07, 0x1b, 0x33, 0x24, 0xb2, 0x58, 0x7f, 0x01, 0xbe, 0xe8, 0x25,
  39134. 0x53, 0x08, 0x06, 0x77, 0x7d, 0x5a, 0x16, 0x83, 0x67, 0x91, 0x0b, 0xa2,
  39135. 0xd2, 0x1e, 0x5f, 0x9c, 0x39, 0xda, 0x57, 0xbc, 0x67, 0xc5, 0x39, 0xbe,
  39136. 0xb9, 0x73, 0x03, 0x19, 0x97, 0x34, 0x4f, 0x1e, 0x6b, 0x4d, 0x87, 0xef,
  39137. 0x79, 0x4f, 0xd1, 0xdd, 0x80, 0x13, 0xbe, 0x3b, 0x0f, 0xea, 0x77, 0x9a,
  39138. 0x1a, 0x46, 0x63, 0xc5, 0x2f, 0x93, 0xfe, 0x18, 0x71, 0xfb, 0x70, 0xbf,
  39139. 0x85, 0x3b, 0x3e, 0x54, 0xe6, 0xf8, 0xe0, 0xb9, 0xd0, 0x9d, 0xf5, 0x2b,
  39140. 0x12, 0x22, 0x39, 0x6a, 0x8d, 0x13, 0xa1, 0x3a, 0x95, 0xd0, 0xe7, 0x07,
  39141. 0xa4, 0x2c, 0x33, 0xba, 0x43, 0x1d, 0xd8, 0xb5, 0xd0, 0x8e, 0x6c, 0x85,
  39142. 0x6f, 0xf8, 0x8f, 0xd3, 0x72, 0x65, 0xc1, 0xff, 0x8f, 0xf6, 0xb5, 0x19,
  39143. 0x59, 0x34, 0xf9, 0xe8, 0xdb, 0xf3, 0x10, 0x68, 0xbd, 0xd5, 0x59, 0xf7,
  39144. 0xe5, 0xf2, 0x84, 0x98, 0x8d, 0xd6, 0x6f, 0xcc, 0xde, 0xc5, 0xee, 0xf7,
  39145. 0x16, 0xca, 0xec, 0xc4, 0x00, 0x89, 0x2e, 0x0d, 0x0d, 0xb6, 0xa8, 0xe0,
  39146. 0x9a, 0xb0, 0xe5, 0x8e, 0xb6, 0x64, 0x47, 0x7d, 0x01, 0x59, 0x8a, 0x90,
  39147. 0xa6, 0x9b, 0x2b, 0x63, 0xad, 0x70, 0xc8, 0x07, 0x36, 0x3e, 0xa9, 0x8f,
  39148. 0xd9, 0xc2, 0xf7, 0x4b, 0xec, 0x95, 0x53, 0xec, 0x6b, 0x2d, 0x1f, 0xb5,
  39149. 0x91, 0xbf, 0x9f, 0xc5, 0x85, 0x61, 0x3a, 0xc7, 0x5c, 0x15, 0x2a, 0x0b,
  39150. 0x4b, 0x3c, 0x38, 0x6d, 0xc9, 0x2c, 0x91, 0x11, 0xc6, 0x6b, 0x44, 0x71,
  39151. 0x9f, 0x89, 0xd5, 0xde, 0x27, 0x99, 0x81, 0xa2, 0x59, 0x8b, 0x57, 0x97,
  39152. 0x83, 0x46, 0x33, 0xe1, 0x8c, 0xdf, 0xcf, 0x5b, 0x6b, 0xb3, 0x0e, 0x17,
  39153. 0x1a, 0xb8, 0x7d, 0x6e, 0x71, 0xe5, 0xc8, 0x4c, 0xa9, 0xe2, 0x52, 0x81,
  39154. 0xf6, 0x2f, 0x3a, 0xef, 0x5a, 0x1b, 0x6b, 0x7b, 0x61, 0x51, 0xcb, 0xd5,
  39155. 0x7b, 0x5f, 0xf0, 0x1c, 0xb8, 0xeb, 0x9a, 0xe4, 0x0a, 0x6e, 0x53, 0x59,
  39156. 0x2e, 0x2d, 0x78, 0x27, 0xb7, 0x47, 0x35, 0x1a, 0x01, 0x25, 0x0a, 0xcc,
  39157. 0x67, 0xae, 0xda, 0xaf, 0xfe, 0x22, 0x63, 0xe8, 0xa2, 0x1c, 0x34, 0xe6,
  39158. 0x6b, 0x73, 0xcf, 0x6f, 0x3e, 0x0a, 0x4a, 0x36, 0xbc, 0xda, 0x43, 0xbc,
  39159. 0x5e, 0x9c, 0x91, 0xe4, 0x8b, 0x34, 0x2e, 0x09, 0x87, 0x69, 0x96, 0x93,
  39160. 0xb4, 0xff, 0x97, 0xbc, 0x4e, 0xd6, 0xa2, 0xb4, 0x16, 0x78, 0x7c, 0x62,
  39161. 0xd0, 0x78, 0x3f, 0x37, 0xdb, 0xf2, 0x92, 0xad, 0x9b, 0x51, 0x77, 0x08,
  39162. 0x19, 0xd2, 0x09, 0x12, 0xf7, 0x52, 0xe8, 0xc8, 0xb2, 0xfb, 0x6f, 0xcd,
  39163. 0x05, 0x5b, 0xd2, 0x8e, 0x0d, 0x6e, 0x0c, 0x16, 0x5b, 0x8a, 0xc2, 0x09,
  39164. 0x13, 0x3b, 0x69, 0x85, 0xbd, 0xc0, 0xcc, 0x2b, 0x48, 0x65, 0xa7, 0xc1,
  39165. 0xc3, 0xe0, 0xea, 0x14, 0x67, 0x6f, 0xa4, 0xb8, 0xc6, 0xf0, 0x12, 0x3e,
  39166. 0x96, 0x0d, 0x23, 0x2b, 0x37, 0x87, 0x8d, 0xc8, 0xf7, 0x00, 0x00, 0x00,
  39167. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39168. 0x00, 0x00, 0x00, 0x03, 0x0b, 0x13, 0x1a, 0x1d, 0x25
  39169. };
  39170. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39171. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_sig[] = {
  39172. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  39173. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  39174. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  39175. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  39176. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  39177. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  39178. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  39179. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  39180. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  39181. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  39182. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  39183. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  39184. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  39185. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  39186. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  39187. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  39188. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  39189. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  39190. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  39191. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  39192. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  39193. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  39194. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  39195. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  39196. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  39197. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  39198. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  39199. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  39200. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  39201. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  39202. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  39203. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  39204. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  39205. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  39206. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  39207. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  39208. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  39209. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  39210. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  39211. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  39212. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  39213. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  39214. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  39215. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  39216. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  39217. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  39218. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  39219. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  39220. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  39221. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  39222. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  39223. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  39224. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  39225. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  39226. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  39227. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  39228. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  39229. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  39230. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  39231. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  39232. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  39233. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  39234. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  39235. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  39236. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  39237. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  39238. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  39239. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  39240. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  39241. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  39242. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  39243. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  39244. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  39245. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  39246. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  39247. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  39248. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  39249. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  39250. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  39251. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  39252. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  39253. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  39254. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  39255. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  39256. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  39257. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  39258. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  39259. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  39260. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  39261. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  39262. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  39263. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  39264. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  39265. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  39266. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  39267. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  39268. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  39269. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  39270. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  39271. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  39272. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  39273. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  39274. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  39275. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  39276. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  39277. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  39278. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  39279. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  39280. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  39281. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  39282. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  39283. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  39284. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  39285. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  39286. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  39287. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  39288. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  39289. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  39290. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  39291. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  39292. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  39293. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  39294. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  39295. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  39296. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  39297. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  39298. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  39299. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  39300. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  39301. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  39302. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  39303. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  39304. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  39305. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  39306. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  39307. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  39308. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  39309. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  39310. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  39311. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  39312. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  39313. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  39314. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  39315. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  39316. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  39317. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  39318. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  39319. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  39320. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  39321. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  39322. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  39323. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  39324. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  39325. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  39326. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  39327. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  39328. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  39329. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  39330. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  39331. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  39332. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  39333. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  39334. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  39335. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  39336. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  39337. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  39338. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  39339. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  39340. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  39341. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  39342. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  39343. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  39344. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  39345. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  39346. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  39347. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  39348. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  39349. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  39350. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  39351. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  39352. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  39353. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  39354. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  39355. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  39356. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  39357. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  39358. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  39359. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  39360. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  39361. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  39362. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  39363. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  39364. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  39365. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  39366. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  39367. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  39368. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  39369. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  39370. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  39371. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  39372. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  39373. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  39374. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  39375. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  39376. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  39377. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  39378. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  39379. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  39380. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  39381. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  39382. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  39383. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  39384. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  39385. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  39386. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  39387. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  39388. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  39389. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  39390. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  39391. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  39392. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  39393. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  39394. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  39395. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  39396. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  39397. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  39398. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  39399. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  39400. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  39401. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  39402. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  39403. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  39404. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  39405. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  39406. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  39407. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  39408. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  39409. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  39410. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  39411. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  39412. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  39413. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  39414. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  39415. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  39416. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  39417. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  39418. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  39419. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  39420. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  39421. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  39422. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  39423. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  39424. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  39425. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  39426. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  39427. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  39428. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  39429. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  39430. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  39431. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  39432. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  39433. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  39434. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  39435. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  39436. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  39437. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  39438. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  39439. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  39440. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  39441. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  39442. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  39443. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  39444. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  39445. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  39446. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  39447. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  39448. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  39449. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  39450. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  39451. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  39452. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  39453. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  39454. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  39455. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  39456. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  39457. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  39458. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  39459. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  39460. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  39461. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  39462. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  39463. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  39464. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  39465. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  39466. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  39467. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  39468. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  39469. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  39470. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  39471. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  39472. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  39473. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  39474. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  39475. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  39476. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  39477. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  39478. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  39479. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  39480. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  39481. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  39482. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  39483. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  39484. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  39485. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  39486. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  39487. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  39488. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  39489. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  39490. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  39491. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  39492. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  39493. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  39494. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  39495. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  39496. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  39497. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  39498. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  39499. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  39500. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  39501. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39502. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28
  39503. };
  39504. #endif
  39505. wc_test_ret_t ret;
  39506. ret = dilithium_param_vfy_test(WC_ML_DSA_65, ml_dsa_65_pub_key,
  39507. (word32)sizeof(ml_dsa_65_pub_key), ml_dsa_65_sig,
  39508. (word32)sizeof(ml_dsa_65_sig));
  39509. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39510. if (ret == 0) {
  39511. ret = dilithium_param_vfy_test(WC_ML_DSA_65_DRAFT,
  39512. ml_dsa_65_draft_pub_key, (word32)sizeof(ml_dsa_65_draft_pub_key),
  39513. ml_dsa_65_draft_sig, (word32)sizeof(ml_dsa_65_draft_sig));
  39514. }
  39515. #endif
  39516. return ret;
  39517. }
  39518. #endif
  39519. #ifndef WOLFSSL_NO_ML_DSA_87
  39520. static wc_test_ret_t dilithium_param_87_vfy_test(void)
  39521. {
  39522. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_pub_key[] = {
  39523. 0x8a, 0x66, 0xe3, 0x6e, 0x3c, 0x11, 0x70, 0x9f, 0x82, 0xdd, 0xeb, 0x9e,
  39524. 0xc0, 0xd7, 0x25, 0x87, 0x0c, 0x65, 0x07, 0x9d, 0x47, 0x39, 0x5d, 0x04,
  39525. 0x42, 0x5c, 0xd6, 0x0a, 0xdc, 0x39, 0x44, 0x04, 0xd9, 0x79, 0x43, 0x87,
  39526. 0x98, 0x64, 0x88, 0x82, 0x3a, 0x31, 0xbd, 0xec, 0x66, 0xcb, 0x01, 0x90,
  39527. 0xf9, 0x85, 0xcc, 0xde, 0x54, 0x69, 0x7d, 0x84, 0xb3, 0x84, 0x3c, 0x42,
  39528. 0x0d, 0x09, 0x63, 0xdb, 0xe6, 0x5d, 0xc2, 0x8a, 0xcf, 0xe1, 0xf4, 0x86,
  39529. 0x13, 0x05, 0x09, 0x9a, 0x4d, 0x05, 0xd4, 0x31, 0xe7, 0x27, 0x39, 0xfd,
  39530. 0x3a, 0xdb, 0x63, 0x9f, 0x1c, 0x67, 0x0b, 0x01, 0xec, 0xf9, 0xff, 0xf3,
  39531. 0xda, 0xa9, 0xf4, 0x9a, 0x59, 0x52, 0x76, 0xc2, 0xd2, 0xd5, 0xdd, 0x8d,
  39532. 0xb1, 0xa2, 0xef, 0xb3, 0x73, 0x99, 0xe3, 0xcd, 0x1c, 0xf5, 0xca, 0x6e,
  39533. 0x39, 0xfa, 0x26, 0x83, 0x45, 0xe7, 0xd0, 0x9c, 0x1b, 0xf7, 0xb2, 0x64,
  39534. 0xf1, 0x70, 0x00, 0x10, 0xc0, 0x7c, 0x7f, 0xb2, 0x32, 0xce, 0x6d, 0x71,
  39535. 0xa5, 0x43, 0x7c, 0x40, 0x71, 0x09, 0x54, 0x74, 0xac, 0xb5, 0xeb, 0xe0,
  39536. 0x04, 0x02, 0xe5, 0x82, 0x4d, 0x5a, 0x85, 0x1e, 0x19, 0x86, 0x39, 0x33,
  39537. 0x92, 0x2f, 0xa9, 0xa8, 0x10, 0xd2, 0x31, 0x60, 0x16, 0x08, 0x99, 0xe3,
  39538. 0x2c, 0x93, 0x13, 0xc4, 0x4b, 0x10, 0xe0, 0x42, 0xca, 0x3f, 0x32, 0xa7,
  39539. 0xa4, 0xd2, 0xfc, 0x9c, 0x93, 0xb6, 0x5f, 0xe2, 0x5b, 0x6e, 0x40, 0x0c,
  39540. 0x63, 0xf8, 0xf8, 0xe1, 0x2d, 0xcd, 0x86, 0x07, 0x79, 0xdb, 0x61, 0xad,
  39541. 0x24, 0xfd, 0x1e, 0x66, 0x3e, 0x8d, 0x76, 0xba, 0x98, 0x8e, 0x94, 0xc7,
  39542. 0x57, 0xb1, 0x65, 0xce, 0x4f, 0x97, 0xfa, 0x34, 0x7c, 0x97, 0x6b, 0xcd,
  39543. 0x3c, 0x42, 0x81, 0xa4, 0xd1, 0x75, 0xeb, 0x6d, 0x0c, 0x31, 0x0e, 0x6f,
  39544. 0xd5, 0x75, 0xe7, 0xff, 0x83, 0xdd, 0x7a, 0x4d, 0x83, 0x67, 0xa7, 0x4b,
  39545. 0xc1, 0x74, 0xad, 0x37, 0x38, 0x99, 0xe0, 0xf5, 0x5a, 0x44, 0x36, 0xa2,
  39546. 0x20, 0x2b, 0xfc, 0xc9, 0xfa, 0x68, 0xcb, 0xf0, 0x6f, 0x0a, 0x46, 0x1d,
  39547. 0xb5, 0xca, 0x5b, 0x96, 0x1b, 0x3a, 0xaf, 0x7d, 0x01, 0x7a, 0xd2, 0x09,
  39548. 0xcc, 0xd4, 0xe4, 0xb1, 0x49, 0x34, 0x56, 0x68, 0x9c, 0x0f, 0x23, 0xe9,
  39549. 0xb3, 0x4b, 0xed, 0x3d, 0xe7, 0x8d, 0x19, 0x6e, 0xe6, 0xfa, 0x06, 0x55,
  39550. 0xb8, 0x06, 0x4d, 0xa8, 0x45, 0x20, 0x91, 0xf7, 0xfa, 0x0b, 0x6b, 0xce,
  39551. 0x55, 0xa7, 0x14, 0x1b, 0xf9, 0xea, 0xc5, 0x79, 0x78, 0xf7, 0x3a, 0xd9,
  39552. 0xfc, 0x07, 0x43, 0x06, 0x90, 0x94, 0x5e, 0xc9, 0x48, 0x51, 0xe5, 0x96,
  39553. 0x68, 0x78, 0xc8, 0xcb, 0xd1, 0xf3, 0x65, 0xef, 0x14, 0x91, 0xa3, 0xca,
  39554. 0x8b, 0x77, 0x40, 0x84, 0xf4, 0x2e, 0xe7, 0x56, 0xe3, 0xab, 0xa0, 0xa8,
  39555. 0x61, 0x93, 0x17, 0x95, 0x9e, 0xff, 0x3a, 0xd4, 0x12, 0xea, 0x13, 0xe6,
  39556. 0x82, 0x16, 0xed, 0x14, 0x70, 0x91, 0xcc, 0x72, 0x58, 0x99, 0xa1, 0x7f,
  39557. 0xf3, 0x84, 0x10, 0xf4, 0x01, 0x0d, 0x05, 0x45, 0x4d, 0xca, 0x05, 0x03,
  39558. 0x75, 0x7e, 0xbb, 0x44, 0x2e, 0xf5, 0xee, 0xed, 0x64, 0x9b, 0xd3, 0xde,
  39559. 0x3e, 0xfc, 0x31, 0x8c, 0xca, 0x23, 0x66, 0x25, 0xac, 0x5f, 0x0f, 0x33,
  39560. 0x0f, 0xd2, 0xe9, 0xc9, 0x96, 0x2a, 0xe2, 0xb8, 0xed, 0x93, 0xd3, 0x78,
  39561. 0xd8, 0x81, 0xe4, 0x52, 0x9a, 0xc6, 0x64, 0x1d, 0x2d, 0x5f, 0x93, 0x9a,
  39562. 0x2e, 0x73, 0xc4, 0x17, 0xae, 0xc6, 0x08, 0x0d, 0x2d, 0xe9, 0x4b, 0x10,
  39563. 0x29, 0xa8, 0x4e, 0x8c, 0x08, 0x59, 0x87, 0x10, 0x0d, 0x5d, 0xfa, 0xec,
  39564. 0xd6, 0x42, 0xf6, 0x5c, 0xa4, 0x0d, 0xaa, 0x64, 0x8e, 0x20, 0xa5, 0x50,
  39565. 0x9f, 0x0b, 0x85, 0x37, 0x57, 0x15, 0x7c, 0xb1, 0xe4, 0xdd, 0xd5, 0x19,
  39566. 0x3b, 0x10, 0x7d, 0x22, 0xdb, 0x53, 0x8b, 0x7b, 0x32, 0xf7, 0xf2, 0x24,
  39567. 0x92, 0xb2, 0x05, 0xd1, 0xfd, 0xfc, 0x11, 0xd6, 0xfd, 0x3c, 0x8d, 0xd7,
  39568. 0xb0, 0x58, 0x50, 0x06, 0x84, 0x61, 0xa6, 0x78, 0x04, 0x1d, 0x7f, 0x92,
  39569. 0x0e, 0x8b, 0xb3, 0x63, 0x43, 0xc5, 0x30, 0x4c, 0xce, 0x2b, 0x44, 0x70,
  39570. 0x53, 0x7c, 0xb5, 0xbd, 0x30, 0xcb, 0x41, 0x19, 0x27, 0x69, 0xfe, 0x41,
  39571. 0x92, 0xae, 0xf0, 0x37, 0x33, 0xf0, 0x95, 0xe4, 0xe8, 0x4f, 0x75, 0x41,
  39572. 0x64, 0x87, 0xc5, 0x68, 0xd3, 0xce, 0xfa, 0xaa, 0xe8, 0x59, 0x88, 0xfe,
  39573. 0x24, 0x46, 0x27, 0x60, 0x71, 0x36, 0x78, 0x66, 0x3c, 0x36, 0x8e, 0xdb,
  39574. 0x90, 0x67, 0xa5, 0x6a, 0xfe, 0xd3, 0x23, 0x28, 0x91, 0x34, 0x24, 0x67,
  39575. 0x4b, 0x01, 0x6a, 0x0e, 0x02, 0xb7, 0xf0, 0xa8, 0xd4, 0x76, 0xd5, 0xa8,
  39576. 0x1c, 0xd3, 0xb3, 0x7d, 0x74, 0xc6, 0x17, 0x96, 0xa7, 0xf9, 0xad, 0x24,
  39577. 0x36, 0xd2, 0xeb, 0x34, 0x5a, 0xcc, 0x9c, 0x01, 0x99, 0xbe, 0x21, 0x4f,
  39578. 0x27, 0x9d, 0x6b, 0xca, 0x27, 0x1b, 0x60, 0x51, 0x41, 0x23, 0xe1, 0xcb,
  39579. 0xfc, 0x17, 0x2e, 0x1a, 0x4d, 0x3d, 0x51, 0xb3, 0x91, 0x8c, 0x53, 0x4d,
  39580. 0xd7, 0xbc, 0xa4, 0x07, 0xd7, 0x17, 0x19, 0x18, 0x61, 0x38, 0x4e, 0x05,
  39581. 0x81, 0x3f, 0x43, 0x8a, 0x00, 0x60, 0xdc, 0x30, 0xf4, 0x38, 0x3f, 0x93,
  39582. 0x82, 0x10, 0x29, 0x73, 0xa9, 0xbd, 0x63, 0x15, 0x7d, 0xac, 0x2e, 0xc9,
  39583. 0x05, 0xc1, 0x01, 0x41, 0x18, 0x5a, 0xc0, 0xc8, 0xc7, 0x81, 0x69, 0xe7,
  39584. 0x24, 0x21, 0x57, 0xaf, 0x88, 0x73, 0x7c, 0x53, 0x29, 0xae, 0x5a, 0xdf,
  39585. 0x76, 0x37, 0x56, 0x4f, 0x1f, 0x6b, 0xfd, 0x71, 0xbb, 0x80, 0x4a, 0xd7,
  39586. 0x53, 0x50, 0x10, 0x2d, 0xfc, 0x1a, 0xaf, 0x7c, 0x1f, 0xe8, 0xd0, 0x6c,
  39587. 0xa6, 0x45, 0x3d, 0xb5, 0x3d, 0xb2, 0xfc, 0x97, 0xa9, 0xbf, 0x7c, 0x0f,
  39588. 0x32, 0x7a, 0xcc, 0xa9, 0x2f, 0xd0, 0xc6, 0xe6, 0xcd, 0x04, 0x1d, 0x71,
  39589. 0x91, 0xb9, 0x59, 0x4b, 0xad, 0xa0, 0xde, 0x9e, 0xdc, 0x9c, 0x10, 0xeb,
  39590. 0x8d, 0xd6, 0x65, 0x57, 0xbc, 0x96, 0xfd, 0x0f, 0xcc, 0x73, 0xbe, 0x39,
  39591. 0x27, 0x99, 0x94, 0xf5, 0xe1, 0xbb, 0x32, 0xcd, 0x27, 0x7e, 0x08, 0xa0,
  39592. 0xd2, 0x92, 0x39, 0xeb, 0x71, 0xc8, 0xe8, 0x34, 0x57, 0x34, 0x4b, 0x20,
  39593. 0x3f, 0xe2, 0x68, 0xec, 0xc0, 0x8a, 0x71, 0xa3, 0x16, 0xa2, 0x91, 0x77,
  39594. 0xde, 0x41, 0x12, 0xa5, 0xf5, 0x2a, 0x63, 0x60, 0x55, 0xd0, 0x33, 0xa4,
  39595. 0xa7, 0x2e, 0xcb, 0x80, 0x08, 0xe5, 0x76, 0x16, 0x75, 0x04, 0x57, 0xe3,
  39596. 0x14, 0x71, 0x4e, 0x57, 0x29, 0x23, 0x0e, 0xc0, 0xcc, 0xad, 0xba, 0xdc,
  39597. 0x96, 0x5d, 0x23, 0x49, 0x42, 0xd8, 0x91, 0x08, 0x0d, 0x52, 0xf4, 0x5f,
  39598. 0xcd, 0xb7, 0x03, 0xaa, 0x73, 0x26, 0xa8, 0xd5, 0x5b, 0x0c, 0x85, 0xc8,
  39599. 0x84, 0x50, 0x9e, 0x70, 0x18, 0x45, 0x27, 0x82, 0x20, 0x75, 0xad, 0x52,
  39600. 0x5c, 0x80, 0x4b, 0xb1, 0x0b, 0x3b, 0x30, 0x39, 0x02, 0x54, 0x18, 0x5d,
  39601. 0x02, 0x9e, 0x85, 0x31, 0x4a, 0x07, 0x9c, 0x59, 0x5d, 0xab, 0x13, 0x4f,
  39602. 0x8f, 0x6e, 0x39, 0x20, 0xb2, 0xc5, 0x31, 0x93, 0xc6, 0xcc, 0xfb, 0xdc,
  39603. 0x15, 0xba, 0x3d, 0xcc, 0xbb, 0xd2, 0x6f, 0x04, 0x21, 0xdf, 0x0b, 0x27,
  39604. 0x5c, 0xd2, 0x6e, 0xfa, 0xda, 0x86, 0x5d, 0xe4, 0xca, 0xa4, 0x90, 0x22,
  39605. 0xa2, 0x80, 0xb5, 0x33, 0x17, 0xdb, 0x9b, 0x7b, 0x0a, 0xcc, 0x0f, 0x9b,
  39606. 0x38, 0x06, 0xdf, 0x10, 0x11, 0xa1, 0xd7, 0x2c, 0x24, 0xf0, 0xa8, 0x34,
  39607. 0x24, 0xfb, 0x99, 0xba, 0x0a, 0xb5, 0xa1, 0x94, 0x6c, 0x2d, 0xf8, 0xda,
  39608. 0x74, 0xaf, 0x19, 0x59, 0x84, 0xb2, 0x68, 0x1c, 0xef, 0xa1, 0xf5, 0x18,
  39609. 0x8f, 0x10, 0xf6, 0xb3, 0x6d, 0x33, 0x87, 0xe0, 0x25, 0xc8, 0x65, 0x5c,
  39610. 0x2f, 0x51, 0x07, 0x83, 0x69, 0x1b, 0xce, 0xa8, 0xe6, 0xe4, 0x27, 0x62,
  39611. 0x5d, 0x9b, 0x7f, 0xa7, 0x07, 0xc8, 0x54, 0x86, 0x90, 0xa5, 0x06, 0x6a,
  39612. 0x94, 0x80, 0x84, 0x97, 0xaa, 0x2a, 0xb9, 0x79, 0xe5, 0x19, 0x7a, 0x91,
  39613. 0xef, 0x8b, 0x58, 0xdc, 0xf9, 0x90, 0x94, 0xa2, 0x25, 0x4c, 0x69, 0xd8,
  39614. 0x6e, 0x9e, 0xad, 0xf8, 0x82, 0x17, 0x37, 0xc9, 0x20, 0x15, 0x24, 0x40,
  39615. 0xe5, 0xc6, 0xc1, 0xc7, 0xbd, 0xd4, 0x62, 0xff, 0x16, 0x6d, 0xa5, 0xec,
  39616. 0xe9, 0x67, 0x41, 0x9d, 0x3e, 0xfb, 0x22, 0x81, 0x80, 0x61, 0x37, 0x45,
  39617. 0xa5, 0x9f, 0x70, 0xff, 0xd4, 0x99, 0x3d, 0x79, 0x45, 0xd0, 0x27, 0xc2,
  39618. 0x32, 0xbe, 0xd4, 0xe2, 0x53, 0xa8, 0x8c, 0x94, 0x8b, 0xbe, 0x8a, 0x43,
  39619. 0xf7, 0x2a, 0x28, 0x49, 0xf4, 0xce, 0x2e, 0x0b, 0x98, 0xc7, 0xaf, 0x7d,
  39620. 0x51, 0x2e, 0xda, 0xd0, 0x7a, 0xfa, 0x91, 0x3a, 0xe6, 0xe7, 0x64, 0xd6,
  39621. 0x09, 0xd8, 0x5d, 0x6a, 0x97, 0xcf, 0x89, 0x96, 0x72, 0x21, 0x97, 0x61,
  39622. 0xc5, 0x1b, 0xd8, 0xa1, 0xf0, 0xcd, 0x9d, 0xe4, 0xe9, 0x13, 0xd0, 0x16,
  39623. 0x41, 0x20, 0xa4, 0x2c, 0x33, 0xf5, 0x3d, 0xfe, 0x80, 0xe8, 0xb2, 0x52,
  39624. 0x0e, 0x18, 0x31, 0x19, 0x50, 0xeb, 0xc6, 0x99, 0x43, 0xab, 0x9a, 0x59,
  39625. 0x5d, 0x6c, 0x84, 0x00, 0x88, 0x45, 0x7c, 0x73, 0xdf, 0x56, 0x61, 0x3a,
  39626. 0xe1, 0x55, 0xb8, 0x59, 0x13, 0xcc, 0x0e, 0x53, 0xe9, 0xf4, 0x74, 0xa0,
  39627. 0xf2, 0x15, 0xd2, 0xa8, 0xf9, 0xd4, 0x0d, 0x3d, 0xe7, 0x3d, 0x7d, 0x5b,
  39628. 0x19, 0x89, 0x8b, 0x2c, 0x4d, 0x8a, 0xeb, 0xc3, 0x43, 0x31, 0x9a, 0x45,
  39629. 0x72, 0x5b, 0x25, 0xb6, 0xa2, 0xc1, 0x98, 0xe3, 0x8a, 0xd4, 0x90, 0xd0,
  39630. 0x3e, 0x13, 0xf0, 0xd7, 0x90, 0x34, 0x94, 0xcc, 0xf1, 0x0a, 0xa9, 0x30,
  39631. 0xd1, 0x95, 0x43, 0x07, 0xcd, 0xd2, 0xca, 0xb0, 0xe5, 0xd4, 0xf1, 0xa1,
  39632. 0xc5, 0x9b, 0xf4, 0x98, 0x28, 0xba, 0xde, 0x40, 0xd6, 0x98, 0x98, 0x20,
  39633. 0x9c, 0x84, 0x9e, 0xc6, 0x57, 0xd8, 0x84, 0xc4, 0xa2, 0x9b, 0x53, 0x50,
  39634. 0xa5, 0xa6, 0x0b, 0x47, 0xe8, 0x08, 0x7d, 0xd7, 0x09, 0xa4, 0x0c, 0x2b,
  39635. 0x27, 0xde, 0xf9, 0x78, 0xbc, 0xa4, 0xb6, 0xc6, 0x1b, 0xda, 0xce, 0x6a,
  39636. 0xf8, 0x1a, 0xf5, 0xfe, 0x7b, 0xab, 0x58, 0x7c, 0xdc, 0x72, 0x02, 0x94,
  39637. 0x99, 0xf0, 0x3c, 0x37, 0x87, 0x5b, 0xd2, 0x4b, 0x5a, 0x80, 0x83, 0xd7,
  39638. 0xfc, 0x9d, 0xa7, 0x51, 0x81, 0xb8, 0x62, 0xff, 0x4b, 0xb3, 0x9f, 0x07,
  39639. 0xc3, 0x54, 0xfb, 0x41, 0x85, 0x42, 0x9d, 0xac, 0x27, 0x81, 0x2e, 0xaf,
  39640. 0x98, 0x67, 0x8c, 0x23, 0xad, 0x45, 0xfe, 0x6a, 0x57, 0x9f, 0x18, 0xc5,
  39641. 0x71, 0x8c, 0xad, 0x3f, 0x30, 0x3c, 0xaa, 0x47, 0x8d, 0xba, 0xc8, 0x7f,
  39642. 0x03, 0x1c, 0x86, 0xee, 0xba, 0x3f, 0x59, 0x45, 0xd4, 0xd0, 0xf5, 0x54,
  39643. 0x9e, 0xcb, 0x08, 0xcf, 0xca, 0x40, 0x0a, 0x06, 0xc0, 0x1e, 0x60, 0x1f,
  39644. 0x33, 0xbf, 0x2c, 0xa8, 0x5f, 0xce, 0x23, 0xa0, 0xe2, 0x1c, 0x2d, 0x56,
  39645. 0x2a, 0x44, 0x61, 0x58, 0xf1, 0x84, 0x63, 0x4f, 0x0d, 0x5e, 0xfb, 0x83,
  39646. 0x0f, 0x36, 0x1b, 0xf4, 0x8f, 0x17, 0x82, 0x2e, 0x04, 0x2c, 0x77, 0x9d,
  39647. 0x32, 0x58, 0xb8, 0xb0, 0xf9, 0x44, 0xd2, 0xf6, 0x84, 0xa4, 0x8b, 0x28,
  39648. 0x53, 0xd6, 0x99, 0x81, 0x84, 0x43, 0xf0, 0xc1, 0x15, 0xc6, 0x74, 0x4f,
  39649. 0xab, 0x05, 0xcc, 0x80, 0xdf, 0xef, 0xcf, 0xaf, 0x14, 0x82, 0xdf, 0x51,
  39650. 0x7c, 0x28, 0x5e, 0x5b, 0x27, 0x5e, 0x91, 0x8b, 0x54, 0x3d, 0x54, 0x26,
  39651. 0xb0, 0x3f, 0xd7, 0xc5, 0xce, 0xf3, 0x6d, 0x2c, 0x12, 0xc6, 0xb4, 0x48,
  39652. 0x60, 0x11, 0x9c, 0xef, 0x29, 0x98, 0x9c, 0x76, 0x4e, 0x73, 0x2b, 0xd2,
  39653. 0x23, 0x53, 0x7d, 0x03, 0xc2, 0x2f, 0x8a, 0xa1, 0xe2, 0x84, 0x54, 0x2d,
  39654. 0xd8, 0xc6, 0x55, 0x77, 0x9d, 0x07, 0x67, 0x1f, 0x1a, 0xd3, 0x57, 0x4c,
  39655. 0x25, 0x79, 0x8f, 0xd8, 0x82, 0xc2, 0x4d, 0x87, 0x84, 0x33, 0xdc, 0x47,
  39656. 0xed, 0x9e, 0xfb, 0xd2, 0x62, 0xc8, 0x50, 0x76, 0xda, 0x3c, 0x3c, 0x05,
  39657. 0x0e, 0x2d, 0x30, 0x56, 0xca, 0x4d, 0x6a, 0xe2, 0x17, 0x24, 0x26, 0x9c,
  39658. 0xff, 0x09, 0xec, 0xb3, 0x94, 0xec, 0xab, 0x69, 0xb2, 0xf0, 0xa5, 0x66,
  39659. 0x18, 0x92, 0x49, 0x6b, 0x90, 0xf5, 0x77, 0x5a, 0x18, 0xe5, 0x51, 0x36,
  39660. 0x4a, 0x35, 0x54, 0x98, 0x48, 0x04, 0xa9, 0x0f, 0xcb, 0x55, 0xf1, 0x71,
  39661. 0xad, 0x1a, 0x4a, 0x2c, 0x0e, 0x5d, 0x5e, 0x77, 0x47, 0xf5, 0x46, 0x17,
  39662. 0x6b, 0x94, 0x2a, 0xbc, 0x40, 0xe5, 0xa7, 0xa6, 0x88, 0x41, 0x76, 0x22,
  39663. 0x47, 0xd1, 0xe8, 0x2b, 0x18, 0x48, 0x21, 0xc0, 0xe8, 0x4f, 0xe2, 0xb2,
  39664. 0x7e, 0x03, 0xbb, 0x25, 0x9c, 0xc8, 0x68, 0x66, 0x48, 0x25, 0x6a, 0xf2,
  39665. 0x64, 0x29, 0xec, 0x79, 0xba, 0xdb, 0x34, 0xe1, 0xd4, 0xf9, 0x52, 0x0e,
  39666. 0xfd, 0x8d, 0x86, 0x94, 0x71, 0xd8, 0xe0, 0x86, 0x02, 0x9b, 0xd4, 0x65,
  39667. 0x69, 0x5e, 0x01, 0x32, 0x87, 0x59, 0xd8, 0x6c, 0xbc, 0x8a, 0x9f, 0x58,
  39668. 0x28, 0x8c, 0x97, 0xef, 0x33, 0xb2, 0xda, 0x45, 0xa0, 0xec, 0xe5, 0x5b,
  39669. 0xac, 0xc6, 0x65, 0xc1, 0xb6, 0xcb, 0xf7, 0x85, 0x0e, 0xfa, 0x78, 0x36,
  39670. 0x30, 0x84, 0x90, 0xa8, 0xf8, 0x42, 0x25, 0xa5, 0xdd, 0xdc, 0xdc, 0x89,
  39671. 0xd3, 0xf0, 0x73, 0x9a, 0xd8, 0x95, 0x8f, 0x04, 0xbf, 0xc1, 0xfd, 0x94,
  39672. 0xff, 0xe6, 0xf8, 0x4e, 0xc6, 0x43, 0xc9, 0x60, 0x30, 0xe9, 0x68, 0xa8,
  39673. 0x76, 0xfb, 0xfa, 0xdf, 0xc0, 0x9b, 0xbc, 0xbc, 0x34, 0xe4, 0x38, 0xfd,
  39674. 0x93, 0xb0, 0x47, 0xb2, 0x3e, 0x83, 0x6c, 0xef, 0xe1, 0xaf, 0x35, 0xb4,
  39675. 0x90, 0x2a, 0x32, 0xaf, 0x25, 0x3f, 0x3e, 0x72, 0x61, 0xc0, 0x0f, 0x29,
  39676. 0xbb, 0x46, 0x6e, 0x2e, 0x94, 0x7d, 0xdd, 0xb7, 0x67, 0x1f, 0x7b, 0x64,
  39677. 0xcb, 0xa5, 0x9a, 0x58, 0x63, 0x20, 0xa7, 0xc0, 0x94, 0xa9, 0xad, 0x90,
  39678. 0x7d, 0xf3, 0x2b, 0x61, 0x2b, 0x64, 0x3d, 0x8a, 0xc3, 0xd1, 0xcb, 0xad,
  39679. 0x36, 0x44, 0xe6, 0x29, 0x8b, 0x3d, 0x95, 0x7c, 0xa7, 0xa2, 0xfa, 0x1b,
  39680. 0x16, 0x8d, 0x9e, 0xc4, 0xf8, 0x4c, 0x76, 0x20, 0x00, 0x68, 0x07, 0x99,
  39681. 0x9c, 0x60, 0xe6, 0x16, 0x6a, 0x6f, 0x8a, 0xbe, 0x71, 0x95, 0xa1, 0xcb,
  39682. 0xfe, 0x7c, 0x41, 0x59, 0x61, 0x20, 0xf9, 0x54, 0x3c, 0xb1, 0x19, 0x5c,
  39683. 0x42, 0x67, 0x3f, 0xff, 0xf3, 0x32, 0x21, 0x9c, 0x9e, 0x88, 0xf9, 0x97,
  39684. 0x00, 0x43, 0x73, 0x4a, 0xfc, 0x54, 0xeb, 0x27, 0x79, 0x14, 0x85, 0xd3,
  39685. 0xdc, 0x47, 0xb3, 0x6d, 0x24, 0xd3, 0xf7, 0x7a, 0xfb, 0x90, 0x7c, 0x6e,
  39686. 0xcd, 0x4e, 0xbf, 0x26, 0x76, 0xd2, 0xe8, 0xcc, 0x67, 0xd1, 0x23, 0x3c,
  39687. 0x94, 0x16, 0x1e, 0x07, 0x36, 0x7c, 0x96, 0xf6, 0xe8, 0x50, 0x72, 0x26,
  39688. 0x56, 0x67, 0x89, 0xa9, 0x11, 0xfb, 0x1d, 0xb8, 0xb9, 0x2a, 0x55, 0xb7,
  39689. 0x85, 0xf7, 0x40, 0xa2, 0xfc, 0x9f, 0x30, 0xec, 0x8f, 0x9a, 0x1c, 0xc8,
  39690. 0xe4, 0xc5, 0x1f, 0xcb, 0x0a, 0x60, 0x80, 0x41, 0xec, 0x88, 0x8a, 0xda,
  39691. 0x7c, 0x7a, 0xa1, 0x96, 0x51, 0x62, 0x16, 0x63, 0x75, 0x36, 0x28, 0x7c,
  39692. 0xc9, 0xd0, 0x27, 0x0c, 0x9e, 0x18, 0x4a, 0x82, 0xf7, 0x02, 0xb9, 0x40,
  39693. 0x8f, 0xd5, 0x97, 0x7a, 0x35, 0xa9, 0x3a, 0xb3, 0x8b, 0x6b, 0xf1, 0x9a,
  39694. 0xd1, 0xe7, 0x14, 0x38, 0x5e, 0xba, 0x8c, 0xbf, 0x32, 0xaa, 0x34, 0x30,
  39695. 0x7c, 0x1e, 0x11, 0xcd, 0x1f, 0x9f, 0xcf, 0x4d, 0x14, 0xce, 0x67, 0xf9,
  39696. 0x9c, 0x89, 0x07, 0x92, 0x44, 0x6e, 0x9a, 0x16, 0xe4, 0xfb, 0x67, 0x01,
  39697. 0x3f, 0x4c, 0x14, 0x89, 0x33, 0x87, 0x46, 0xc6, 0xe4, 0x66, 0x94, 0xd4,
  39698. 0x87, 0x4f, 0x2c, 0x92, 0x1b, 0xae, 0x82, 0xe7, 0x99, 0xaa, 0xb4, 0x99,
  39699. 0x81, 0x26, 0xa6, 0x6f, 0x1d, 0xc1, 0x95, 0x80, 0xe9, 0xea, 0xe3, 0x44,
  39700. 0x6a, 0x2b, 0xd2, 0xe0, 0x0d, 0x69, 0x42, 0xf7, 0x27, 0x6b, 0x4f, 0x02,
  39701. 0x7a, 0x33, 0x7b, 0x43, 0x3d, 0xef, 0x10, 0xaa, 0xab, 0xc5, 0xa2, 0xf0,
  39702. 0xbb, 0x07, 0x4b, 0x26, 0x0c, 0x58, 0xcd, 0x3b, 0xd2, 0x6d, 0xa5, 0x32,
  39703. 0x37, 0x88, 0x4e, 0x8b, 0xe3, 0x75, 0xb0, 0xbb, 0x87, 0xea, 0xa4, 0x53,
  39704. 0xf3, 0xff, 0x39, 0x92, 0x44, 0xab, 0x7b, 0x71, 0x62, 0x31, 0x6b, 0x31,
  39705. 0xca, 0x97, 0xba, 0xd7, 0x41, 0xe0, 0x47, 0x47, 0x4f, 0x77, 0xa2, 0x35,
  39706. 0x62, 0x7a, 0xc1, 0xb6, 0x69, 0x10, 0x09, 0xce, 0xfc, 0x92, 0xcc, 0xc5,
  39707. 0x7a, 0x11, 0xf1, 0xc1, 0xa0, 0x80, 0xe5, 0x42, 0x17, 0xb6, 0x3f, 0xab,
  39708. 0xc1, 0xa2, 0x41, 0xfb, 0xe3, 0x98, 0x2d, 0x7a, 0xe4, 0x1b, 0x1f, 0x7e,
  39709. 0x71, 0x3c, 0x3e, 0x90, 0x8c, 0x60, 0x30, 0xb7, 0x73, 0x06, 0x1f, 0x8a,
  39710. 0xce, 0x50, 0x20, 0x7c, 0xfa, 0x8c, 0xf2, 0x14, 0xd9, 0x00, 0xa2, 0x21,
  39711. 0xea, 0x10, 0x36, 0x21, 0x6f, 0x7f, 0x13, 0xe3, 0x6c, 0xb2, 0xd6, 0xa5,
  39712. 0xa6, 0x6e, 0xa9, 0xe7, 0x1d, 0xdf, 0xc9, 0x97, 0x60, 0x75, 0xa3, 0x55,
  39713. 0xa1, 0x2c, 0x94, 0xd7, 0x85, 0x4b, 0x44, 0xc6, 0x9c, 0x17, 0xc2, 0xad,
  39714. 0xe6, 0x56, 0x72, 0x1d, 0xb9, 0x13, 0x54, 0xfe, 0x8c, 0xec, 0xf4, 0xa3,
  39715. 0x54, 0x6b, 0x31, 0xbc, 0x55, 0x9e, 0x01, 0xd4, 0x9b, 0x24, 0x9e, 0x51,
  39716. 0xaf, 0x67, 0x76, 0x02, 0xf7, 0x34, 0x6a, 0xaa, 0xb0, 0x3c, 0x70, 0x2e,
  39717. 0xc8, 0x86, 0xfa, 0x40, 0x89, 0x12, 0xb7, 0x49, 0x38, 0x0b, 0xf7, 0x66,
  39718. 0xd2, 0x2e, 0x58, 0xf1, 0x22, 0x3b, 0xb3, 0x40, 0x6b, 0x7a, 0x68, 0x4d,
  39719. 0x42, 0xfd, 0xbf, 0xa0, 0xf7, 0x2f, 0x63, 0x4a, 0x87, 0xe7, 0x99, 0x52,
  39720. 0x6e, 0xe7, 0xdd, 0xca, 0x19, 0x71, 0xee, 0x92, 0xe2, 0x68, 0x0e, 0xe1,
  39721. 0xb7, 0x90, 0x1f, 0xc4, 0xef, 0xf8, 0xf6, 0x85, 0x53, 0x18, 0x33, 0x86,
  39722. 0x15, 0xc8, 0x29, 0x58, 0x6f, 0xf0, 0x1c, 0x14, 0x73, 0xa9, 0x8e, 0x88,
  39723. 0x74, 0xd4, 0x21, 0xf5, 0xc6, 0x7c, 0xd8, 0x96, 0x0f, 0xb0, 0xa6, 0x7b,
  39724. 0xf7, 0x72, 0x15, 0xd7, 0x30, 0x6b, 0x15, 0x1d, 0x3f, 0xb7, 0x4e, 0xaa,
  39725. 0xc0, 0x52, 0x1d, 0x84, 0xbf, 0x98, 0xbd, 0x33, 0x02, 0xab, 0x8b, 0xd0,
  39726. 0x9c, 0x85, 0x2f, 0xa3, 0xfb, 0x46, 0x8d, 0x4d, 0x97, 0x1a, 0x8a, 0x3c,
  39727. 0x73, 0x5b, 0x3b, 0x58, 0x26, 0xba, 0x6b, 0x45, 0x2e, 0x24, 0x66, 0x79,
  39728. 0x7d, 0xc4, 0xf8, 0x8c, 0x05, 0x7d, 0x5c, 0x23, 0xb9, 0xe8, 0x5d, 0xfe,
  39729. 0xc9, 0x84, 0xe5, 0x58, 0x40, 0xa4, 0xb7, 0x55, 0x74, 0x69, 0x92, 0x9c,
  39730. 0x3e, 0x19, 0xb1, 0xb6, 0x51, 0xe9, 0x71, 0xcc, 0x96, 0x2b, 0x01, 0x71,
  39731. 0xf5, 0xb9, 0xde, 0x77, 0xfe, 0x2e, 0x74, 0x9c, 0x6a, 0x52, 0x17, 0x1e,
  39732. 0xea, 0xd9, 0xc8, 0x14, 0xbe, 0x61, 0xdf, 0xe9, 0x96, 0x24, 0x5a, 0x9a,
  39733. 0xd8, 0xd7, 0xad, 0x71, 0xe0, 0xf4, 0xbb, 0x9e, 0xae, 0x95, 0xcd, 0x58,
  39734. 0x94, 0x81, 0xee, 0x46, 0x84, 0x65, 0x39, 0xb1, 0x1b, 0x1e, 0xf5, 0x50,
  39735. 0xad, 0x56, 0x58, 0xb7, 0x53, 0x9b, 0x2a, 0x2f, 0x09, 0x61, 0x57, 0xda,
  39736. 0xf5, 0xdc, 0x9f, 0x3c, 0x6c, 0x69, 0x0d, 0x61, 0x49, 0xb2, 0xe0, 0xb2,
  39737. 0xe5, 0xef, 0x19, 0xbe, 0x04, 0xf6, 0x6b, 0xad, 0x41, 0x4c, 0x5a, 0x50,
  39738. 0xf6, 0xac, 0x1b, 0x25, 0x8a, 0xdd, 0xe3, 0x57, 0xab, 0x7c, 0x92, 0xe4
  39739. };
  39740. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39741. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_pub_key[] = {
  39742. 0xef, 0x49, 0x79, 0x47, 0x15, 0xc4, 0x8a, 0xa9, 0x74, 0x2a,
  39743. 0xf0, 0x36, 0x94, 0x5c, 0x91, 0x1c, 0x5d, 0xff, 0x2c, 0x83,
  39744. 0xf2, 0x8b, 0x04, 0xfc, 0x5d, 0x64, 0xbd, 0x49, 0x73, 0xcd,
  39745. 0xcc, 0x99, 0x50, 0x5f, 0x2b, 0x16, 0x3a, 0xbb, 0x98, 0xc0,
  39746. 0xa7, 0x69, 0x0e, 0x95, 0x99, 0x0b, 0xa2, 0x6c, 0xfe, 0x6c,
  39747. 0xdb, 0xc8, 0xa7, 0x09, 0x46, 0x6c, 0x90, 0x50, 0xa4, 0x75,
  39748. 0x30, 0xf7, 0x90, 0xac, 0x31, 0xb6, 0xdd, 0x21, 0xaf, 0xc6,
  39749. 0xf9, 0xfe, 0xee, 0xc6, 0x5b, 0xa8, 0x8f, 0x0a, 0x2e, 0xd0,
  39750. 0x42, 0xab, 0xa8, 0x3c, 0x8d, 0xbf, 0xf7, 0x44, 0xbd, 0x0d,
  39751. 0xcf, 0xf4, 0x68, 0xfc, 0x16, 0x67, 0xf7, 0x39, 0x48, 0x5f,
  39752. 0x56, 0xd1, 0xe7, 0x1f, 0x49, 0x80, 0x50, 0xbe, 0x54, 0xd1,
  39753. 0xb7, 0xc9, 0xd2, 0x32, 0xc7, 0x08, 0x8c, 0xde, 0x2c, 0x31,
  39754. 0xf6, 0x1d, 0xc7, 0xac, 0xb3, 0x79, 0xd7, 0x4b, 0x1b, 0x23,
  39755. 0x89, 0x0a, 0xdc, 0x8e, 0x44, 0x41, 0x14, 0x28, 0x99, 0x13,
  39756. 0xb3, 0x26, 0xa6, 0x0e, 0x83, 0x60, 0xaa, 0x8d, 0x7c, 0x23,
  39757. 0x13, 0xba, 0x6c, 0x28, 0x90, 0x56, 0x84, 0xa1, 0x23, 0x8b,
  39758. 0x81, 0x20, 0x97, 0x7c, 0x66, 0x3f, 0xed, 0x5d, 0xd0, 0xe4,
  39759. 0x5d, 0xee, 0x46, 0xbc, 0x4b, 0x3c, 0x03, 0xb5, 0xbc, 0x4d,
  39760. 0x8d, 0x37, 0xa3, 0x56, 0x4b, 0x33, 0xad, 0xef, 0xd4, 0xb6,
  39761. 0xec, 0xdb, 0x04, 0x9a, 0x19, 0x58, 0x57, 0xd8, 0x00, 0x3a,
  39762. 0x92, 0x61, 0x0c, 0x0b, 0xc8, 0x52, 0xe5, 0x04, 0x02, 0x9a,
  39763. 0x00, 0x7e, 0xec, 0x7e, 0x94, 0xaa, 0xef, 0x2d, 0x7f, 0xb6,
  39764. 0x2e, 0x7c, 0xb0, 0x73, 0xa2, 0x20, 0xc0, 0x07, 0x30, 0x41,
  39765. 0x50, 0x20, 0x14, 0x18, 0x21, 0x5e, 0x2a, 0x6f, 0x70, 0x21,
  39766. 0xd6, 0x97, 0x13, 0xb9, 0xc1, 0x9e, 0x90, 0x67, 0xcc, 0x55,
  39767. 0x8a, 0xec, 0xec, 0x0a, 0x1e, 0x90, 0xdc, 0x3f, 0xb0, 0x4d,
  39768. 0xd1, 0x18, 0xea, 0x4f, 0xcb, 0x5d, 0x15, 0x4c, 0xb8, 0x35,
  39769. 0x9b, 0x34, 0x24, 0x30, 0x06, 0x53, 0x17, 0xf0, 0xbe, 0x27,
  39770. 0x36, 0xb3, 0x04, 0x6a, 0xbd, 0xbf, 0xa7, 0x39, 0xee, 0xa9,
  39771. 0x8f, 0x0e, 0x98, 0xc5, 0xf5, 0x9f, 0x46, 0x25, 0x93, 0xc9,
  39772. 0xf2, 0xf6, 0x2b, 0x8e, 0x92, 0x06, 0x01, 0x3d, 0x81, 0x18,
  39773. 0xf2, 0xec, 0xf1, 0x05, 0x4c, 0xad, 0x4b, 0xcb, 0x98, 0xa4,
  39774. 0xb5, 0x61, 0x20, 0xda, 0x81, 0xa1, 0xfb, 0x92, 0x4c, 0xaf,
  39775. 0x87, 0x6f, 0x6e, 0xd2, 0x57, 0xec, 0xcd, 0x94, 0xb3, 0x79,
  39776. 0xbf, 0x59, 0x88, 0x17, 0x81, 0xce, 0x8a, 0x57, 0xce, 0x57,
  39777. 0xae, 0x3e, 0x82, 0x81, 0x2f, 0x83, 0x61, 0xd8, 0xf9, 0x68,
  39778. 0x21, 0xe7, 0x72, 0x5b, 0xd6, 0x80, 0x55, 0x68, 0x5d, 0x67,
  39779. 0x15, 0x0c, 0x8b, 0xdc, 0x4f, 0xc3, 0x89, 0x36, 0x3c, 0xac,
  39780. 0xaf, 0x16, 0x5e, 0x1c, 0xfa, 0x68, 0x74, 0x6a, 0xab, 0x68,
  39781. 0xd8, 0x59, 0x96, 0x2d, 0x33, 0x62, 0xe4, 0xbd, 0xb3, 0xb7,
  39782. 0x4d, 0x88, 0x35, 0xb8, 0xed, 0xb2, 0x16, 0x85, 0x97, 0x08,
  39783. 0x71, 0x71, 0x39, 0x7e, 0x0c, 0x53, 0x16, 0xda, 0x38, 0xe5,
  39784. 0x28, 0x09, 0x9c, 0xd9, 0x46, 0xec, 0x68, 0xda, 0x8d, 0xd0,
  39785. 0xad, 0xb2, 0x79, 0x28, 0x3b, 0x1e, 0x12, 0xc9, 0xdf, 0xa9,
  39786. 0x6d, 0x3d, 0x29, 0x99, 0x2f, 0x53, 0xc2, 0xd0, 0xf9, 0x88,
  39787. 0x26, 0x94, 0x47, 0xaf, 0xf6, 0x96, 0xf3, 0xe1, 0x11, 0xa6,
  39788. 0x82, 0x3d, 0x43, 0x3f, 0x1f, 0xbc, 0xf6, 0x98, 0xbe, 0xff,
  39789. 0x06, 0x86, 0x61, 0x27, 0xdc, 0x91, 0x54, 0xd4, 0xfc, 0x68,
  39790. 0x83, 0xe8, 0x35, 0x3e, 0xee, 0x94, 0x59, 0x28, 0x2f, 0xde,
  39791. 0xdd, 0x03, 0x60, 0x66, 0xc1, 0x49, 0x57, 0xdd, 0xbc, 0xd5,
  39792. 0x0a, 0x67, 0x34, 0xf1, 0xa6, 0x0a, 0x57, 0x94, 0x65, 0x02,
  39793. 0x2c, 0x52, 0x43, 0x70, 0x3b, 0xc1, 0x9a, 0xff, 0xda, 0x6f,
  39794. 0xb9, 0x54, 0x47, 0x01, 0xda, 0x27, 0xe4, 0x48, 0x4a, 0x90,
  39795. 0x9f, 0xb5, 0xc3, 0xee, 0x0e, 0x09, 0x57, 0xfe, 0x48, 0x51,
  39796. 0x08, 0x34, 0x5e, 0x8f, 0x16, 0xc9, 0x0b, 0x74, 0xd9, 0x7d,
  39797. 0x22, 0x3f, 0xd6, 0xb7, 0x5d, 0xd6, 0x76, 0x00, 0x8d, 0x4e,
  39798. 0x78, 0x73, 0x86, 0xd6, 0xdb, 0x2a, 0x65, 0xab, 0xdf, 0xb0,
  39799. 0xea, 0x11, 0xad, 0xdf, 0xba, 0x43, 0xdb, 0xa8, 0x0a, 0xfb,
  39800. 0x04, 0x38, 0x81, 0x2b, 0xa3, 0x29, 0xfc, 0x95, 0x73, 0x9a,
  39801. 0x0c, 0x6c, 0x9e, 0xcd, 0xdc, 0xcf, 0x0a, 0x0c, 0x18, 0x41,
  39802. 0x6f, 0x1d, 0xa3, 0xf6, 0x12, 0x4c, 0x13, 0xf2, 0x02, 0xc6,
  39803. 0x50, 0x99, 0x86, 0x73, 0xa7, 0xf9, 0x7e, 0x84, 0x7f, 0x4c,
  39804. 0x00, 0xce, 0x2e, 0x21, 0x76, 0x8e, 0x17, 0x7a, 0x87, 0x6f,
  39805. 0x81, 0xe6, 0xc0, 0x52, 0xa5, 0xa0, 0x3c, 0x54, 0x3c, 0xec,
  39806. 0xb0, 0x9d, 0x1c, 0x3b, 0xec, 0xe5, 0x4e, 0x4a, 0x37, 0xe7,
  39807. 0xd5, 0xa9, 0x07, 0x87, 0x23, 0x28, 0x5d, 0x3d, 0x22, 0x02,
  39808. 0x79, 0x40, 0x3f, 0x2d, 0x40, 0xc9, 0xe5, 0xa6, 0x9b, 0xa8,
  39809. 0xb8, 0x76, 0xf6, 0x77, 0x5b, 0x8d, 0x72, 0x96, 0x3e, 0x13,
  39810. 0xbf, 0x76, 0xfa, 0x7b, 0xb7, 0x82, 0x5f, 0xe7, 0x9d, 0x54,
  39811. 0x0e, 0x05, 0x1a, 0x9f, 0xa4, 0x42, 0xa5, 0xb4, 0x93, 0x23,
  39812. 0x06, 0x59, 0x43, 0xa8, 0xe8, 0x5c, 0xfc, 0x18, 0x97, 0xdb,
  39813. 0xad, 0x9a, 0x80, 0x0a, 0xf2, 0x20, 0x50, 0xac, 0xc1, 0x13,
  39814. 0x3e, 0x98, 0x09, 0xde, 0xf2, 0x70, 0x9e, 0x14, 0xc2, 0x5c,
  39815. 0xec, 0x65, 0x07, 0x0b, 0xfa, 0x02, 0x5c, 0xf8, 0x71, 0xaa,
  39816. 0x9b, 0x45, 0x62, 0xe2, 0x27, 0xaf, 0x77, 0xf8, 0xe3, 0xeb,
  39817. 0x7b, 0x24, 0x7b, 0x3c, 0x67, 0xc2, 0x6d, 0x6e, 0x17, 0xae,
  39818. 0x6e, 0x86, 0x6f, 0x98, 0xc9, 0xac, 0x13, 0x9f, 0x87, 0x64,
  39819. 0x3d, 0x4d, 0x6f, 0xa0, 0xb3, 0x39, 0xc6, 0x68, 0x1b, 0xa7,
  39820. 0xeb, 0x3e, 0x0f, 0x6b, 0xc7, 0xa4, 0xe2, 0x20, 0x27, 0x75,
  39821. 0x3f, 0x09, 0x16, 0xff, 0x1a, 0xcc, 0xa7, 0xc4, 0x6d, 0xc2,
  39822. 0xfc, 0xc3, 0x0b, 0x37, 0x63, 0xff, 0x9b, 0x10, 0xe6, 0x00,
  39823. 0xf7, 0x18, 0x43, 0x9f, 0x07, 0x50, 0x31, 0x51, 0xd4, 0xfd,
  39824. 0xad, 0xa2, 0x0f, 0x77, 0xda, 0x41, 0xc1, 0x0a, 0x6f, 0x86,
  39825. 0xd7, 0xdc, 0x8a, 0x52, 0xd6, 0xa1, 0x27, 0xdb, 0x14, 0x67,
  39826. 0x26, 0x91, 0xb3, 0xcd, 0x01, 0x5f, 0x60, 0xa1, 0x7f, 0x43,
  39827. 0x15, 0x1a, 0x82, 0x0f, 0xd3, 0x66, 0x5f, 0x60, 0x57, 0x2f,
  39828. 0xb2, 0x8c, 0x27, 0x2a, 0x9d, 0x1b, 0xf9, 0xf2, 0x59, 0x20,
  39829. 0x39, 0xd9, 0xc5, 0xaf, 0xf2, 0x36, 0x8c, 0x58, 0x00, 0x1b,
  39830. 0xd0, 0xc5, 0x8e, 0x1a, 0x49, 0xa8, 0x60, 0xbe, 0xd1, 0xd7,
  39831. 0x2a, 0xb0, 0xc2, 0xab, 0x58, 0x8a, 0x7a, 0xa9, 0x41, 0x68,
  39832. 0x70, 0xbd, 0xea, 0x73, 0xa5, 0x03, 0x11, 0xb2, 0x27, 0xd9,
  39833. 0xcd, 0xf5, 0x09, 0xe8, 0x1c, 0xe2, 0x4f, 0x50, 0x6a, 0x84,
  39834. 0x34, 0x62, 0x2e, 0x36, 0xaa, 0x4c, 0xc1, 0x83, 0x78, 0x98,
  39835. 0x35, 0x7a, 0x27, 0x7e, 0xfe, 0xf1, 0x6f, 0x59, 0x27, 0x35,
  39836. 0x73, 0xce, 0x74, 0xaa, 0xb4, 0x72, 0x82, 0xa8, 0xe2, 0x81,
  39837. 0x7a, 0x6b, 0xca, 0x33, 0xa5, 0xda, 0xa2, 0x63, 0xca, 0x2e,
  39838. 0x90, 0x03, 0x32, 0xec, 0x63, 0xdb, 0x52, 0x7b, 0x16, 0xfc,
  39839. 0x01, 0x2d, 0x30, 0x12, 0x1e, 0xf9, 0xa3, 0x72, 0x21, 0x3c,
  39840. 0x75, 0x0c, 0x61, 0x9c, 0x7e, 0x73, 0x04, 0x71, 0x41, 0x45,
  39841. 0x5d, 0x7f, 0x49, 0x1c, 0x09, 0x08, 0xa4, 0xec, 0x2f, 0xfd,
  39842. 0xc4, 0xfb, 0x59, 0x6a, 0x27, 0x7a, 0xd4, 0xfc, 0x5f, 0x20,
  39843. 0x04, 0x34, 0x7d, 0x08, 0xed, 0x82, 0x5a, 0x90, 0xe1, 0xab,
  39844. 0xfd, 0x35, 0x3a, 0x8d, 0xbb, 0x0a, 0x9d, 0x73, 0xff, 0x69,
  39845. 0xe5, 0xe9, 0x09, 0x55, 0x14, 0xd9, 0x7b, 0x6f, 0x0d, 0x99,
  39846. 0xd2, 0x7e, 0x71, 0xf8, 0x4f, 0x72, 0x2f, 0xbb, 0xc6, 0xc4,
  39847. 0x36, 0xc9, 0x01, 0xd3, 0x9b, 0x94, 0xab, 0x41, 0x0f, 0x4a,
  39848. 0x61, 0x5c, 0x68, 0xe5, 0xd7, 0x0d, 0x94, 0xaa, 0xee, 0xba,
  39849. 0x95, 0xcb, 0x8c, 0x0e, 0x85, 0x3a, 0x02, 0x6b, 0x95, 0x50,
  39850. 0xfd, 0x02, 0xfd, 0xa4, 0x58, 0x29, 0x78, 0x4f, 0xd0, 0xae,
  39851. 0x66, 0xd6, 0x5c, 0xe7, 0x45, 0xfe, 0x98, 0xb0, 0xa3, 0xe2,
  39852. 0x87, 0xc0, 0xd2, 0x81, 0x08, 0xf1, 0xf1, 0xe7, 0xda, 0x62,
  39853. 0x9e, 0xa0, 0x34, 0x86, 0xeb, 0xa1, 0x6e, 0x4a, 0x26, 0x8e,
  39854. 0x39, 0x0c, 0x51, 0x10, 0x33, 0x11, 0x87, 0xf8, 0x79, 0x3c,
  39855. 0x49, 0x7a, 0x8b, 0xce, 0xc1, 0x0a, 0x0e, 0xe1, 0xd5, 0x2a,
  39856. 0xac, 0xf0, 0x3a, 0x1d, 0x6a, 0x6a, 0xe5, 0xe1, 0x81, 0x70,
  39857. 0xad, 0xaf, 0x15, 0x4c, 0x2a, 0x70, 0x2a, 0x6b, 0x22, 0x0d,
  39858. 0x30, 0xe7, 0x56, 0xed, 0x2d, 0x4b, 0x85, 0x17, 0x49, 0x72,
  39859. 0x3a, 0x1b, 0x6f, 0x57, 0x1c, 0xf7, 0x72, 0x9e, 0x20, 0xdb,
  39860. 0x57, 0x1c, 0xfb, 0x36, 0x50, 0x52, 0xec, 0x5b, 0xd6, 0x6a,
  39861. 0x1b, 0xf8, 0x74, 0xad, 0xe6, 0x00, 0x74, 0x04, 0xc5, 0x99,
  39862. 0x83, 0xe4, 0x5a, 0x0c, 0xc3, 0xe8, 0x6d, 0x3a, 0xd7, 0x3c,
  39863. 0x3c, 0xc0, 0x1a, 0x28, 0xb3, 0x29, 0x7a, 0x10, 0x9e, 0x39,
  39864. 0x66, 0x5b, 0xc1, 0x38, 0xac, 0x21, 0x4e, 0xcd, 0x01, 0xf2,
  39865. 0xf6, 0x30, 0x2c, 0x2b, 0xb6, 0xbf, 0xf5, 0xea, 0x61, 0xaf,
  39866. 0x0c, 0xa6, 0x01, 0x11, 0x15, 0x19, 0x09, 0x8c, 0x7e, 0x69,
  39867. 0xdf, 0x3b, 0xea, 0xd3, 0x0a, 0x3a, 0xd7, 0xbd, 0xe1, 0x17,
  39868. 0xaf, 0x92, 0x3c, 0xf5, 0xfe, 0x35, 0xd6, 0xcf, 0x07, 0xa6,
  39869. 0xf7, 0xe9, 0xc1, 0x99, 0xed, 0x80, 0xe3, 0x12, 0xd5, 0x4b,
  39870. 0xb9, 0xdf, 0xaf, 0x4e, 0x52, 0xad, 0x8e, 0x66, 0x87, 0xe5,
  39871. 0x2c, 0xd0, 0x45, 0x70, 0xd9, 0x78, 0x8f, 0x4b, 0xf4, 0xe1,
  39872. 0xf1, 0x22, 0xf2, 0xe3, 0xed, 0x1f, 0xeb, 0xe9, 0x70, 0x31,
  39873. 0x4c, 0x65, 0x5f, 0x55, 0xee, 0x5d, 0xaa, 0x83, 0x87, 0x76,
  39874. 0xbe, 0x11, 0xae, 0xd7, 0xf2, 0xfb, 0x43, 0xe7, 0x17, 0x81,
  39875. 0x33, 0x15, 0x47, 0xa0, 0xf3, 0x8e, 0x84, 0x57, 0xff, 0x35,
  39876. 0x9e, 0x4a, 0x8a, 0xab, 0x50, 0x3a, 0x45, 0xe0, 0xc3, 0x73,
  39877. 0xca, 0x77, 0x61, 0x68, 0x38, 0xd0, 0xa3, 0x5f, 0x03, 0x8d,
  39878. 0x41, 0xc2, 0xd3, 0x4a, 0x17, 0xe0, 0xa8, 0xaa, 0x00, 0xf3,
  39879. 0xf2, 0x5b, 0xa8, 0xe1, 0x06, 0xa6, 0x2b, 0xdb, 0xe1, 0x74,
  39880. 0xbd, 0xc4, 0xd2, 0x2b, 0x55, 0x9a, 0xb0, 0xf8, 0x35, 0xd8,
  39881. 0x6b, 0xec, 0xdb, 0xc5, 0xf4, 0x6c, 0x40, 0x90, 0x6a, 0x68,
  39882. 0xc9, 0xb5, 0xcb, 0xbb, 0xd0, 0xb0, 0xbc, 0x9f, 0xb9, 0xaa,
  39883. 0x50, 0x14, 0x93, 0x3b, 0x9f, 0x25, 0xcb, 0x40, 0xb8, 0x08,
  39884. 0xcc, 0x13, 0xe5, 0xdc, 0x3f, 0x84, 0x96, 0xe0, 0x73, 0x7b,
  39885. 0x7d, 0x9e, 0x41, 0x92, 0x5d, 0xcc, 0xa4, 0xea, 0x4f, 0x93,
  39886. 0x0c, 0x40, 0x2e, 0x42, 0x8a, 0xe9, 0xb9, 0x12, 0x74, 0xbb,
  39887. 0x79, 0x7c, 0xb0, 0x37, 0x20, 0xb6, 0xaf, 0x43, 0x3a, 0x88,
  39888. 0x59, 0x7c, 0x68, 0x28, 0x5f, 0x98, 0xc2, 0xf0, 0x2a, 0xbc,
  39889. 0xa1, 0x61, 0x88, 0x1f, 0x43, 0xbc, 0x42, 0x8f, 0x43, 0xf3,
  39890. 0x7e, 0x16, 0x96, 0xfa, 0x92, 0x70, 0xaf, 0x3c, 0x9f, 0x4b,
  39891. 0xd9, 0x60, 0xe9, 0xf6, 0x2e, 0x84, 0xda, 0x88, 0x31, 0x34,
  39892. 0xa6, 0x85, 0x10, 0x05, 0xef, 0x40, 0xa8, 0xa5, 0x4f, 0x92,
  39893. 0x59, 0xf7, 0xe0, 0xc4, 0x2b, 0x12, 0x17, 0x71, 0xbe, 0x8c,
  39894. 0x4a, 0x02, 0xfe, 0x12, 0xb6, 0x3b, 0x85, 0x75, 0x37, 0xf3,
  39895. 0x73, 0x2d, 0x9c, 0x00, 0x5d, 0x80, 0xad, 0x20, 0x2f, 0x5a,
  39896. 0x0b, 0x17, 0x7e, 0x67, 0x72, 0x24, 0x5a, 0xb9, 0xf3, 0xb1,
  39897. 0x33, 0xa4, 0x57, 0x1d, 0x49, 0x72, 0x2c, 0x7f, 0x47, 0x15,
  39898. 0x07, 0xe0, 0x45, 0x14, 0xdd, 0x77, 0x86, 0x6d, 0x03, 0xbe,
  39899. 0x57, 0xd0, 0xaa, 0x18, 0xa6, 0xdd, 0x94, 0x18, 0x3f, 0x8a,
  39900. 0xf3, 0xb5, 0xd7, 0x5a, 0xec, 0xc8, 0x79, 0x7f, 0x51, 0x61,
  39901. 0x3c, 0x9b, 0xb2, 0x9b, 0xf3, 0xb4, 0x35, 0xd1, 0x38, 0xbf,
  39902. 0x37, 0xce, 0x54, 0xd1, 0xf8, 0xb6, 0x45, 0xeb, 0x52, 0x0d,
  39903. 0x9a, 0x09, 0x58, 0x0d, 0x2c, 0x0b, 0xb1, 0xf2, 0x30, 0x3a,
  39904. 0x95, 0xc1, 0x13, 0x91, 0xd2, 0x9f, 0x8d, 0x8d, 0xd0, 0x38,
  39905. 0x3e, 0x4c, 0xae, 0x4a, 0x55, 0xa7, 0x42, 0x11, 0x83, 0xc4,
  39906. 0x70, 0xf0, 0x2b, 0x68, 0x9e, 0x07, 0xad, 0xb7, 0x83, 0xc6,
  39907. 0x53, 0x3c, 0xfb, 0x0a, 0x5d, 0x24, 0xdc, 0xe1, 0x55, 0x72,
  39908. 0xcf, 0xce, 0x3e, 0xc8, 0xd0, 0x57, 0x8a, 0x82, 0x5e, 0x78,
  39909. 0x2b, 0x80, 0xc5, 0xb9, 0x09, 0x46, 0xf8, 0x90, 0x39, 0x52,
  39910. 0xa9, 0xce, 0x3f, 0x3d, 0x41, 0x3b, 0x28, 0x45, 0xa3, 0xb3,
  39911. 0x21, 0xc2, 0xcd, 0x14, 0x49, 0x41, 0x6c, 0x38, 0xda, 0x1b,
  39912. 0x5f, 0x16, 0x49, 0xf9, 0x65, 0x00, 0x4e, 0xb4, 0x20, 0x55,
  39913. 0x70, 0xe8, 0x58, 0x1a, 0x18, 0xbf, 0x41, 0xef, 0x31, 0xb1,
  39914. 0xe7, 0x8d, 0x89, 0xc1, 0x48, 0xe8, 0xf5, 0x57, 0x35, 0xfa,
  39915. 0xc1, 0x79, 0xee, 0x2c, 0xe8, 0x7d, 0xb6, 0x03, 0xcc, 0x66,
  39916. 0x09, 0x6f, 0x52, 0x84, 0x0a, 0x34, 0x18, 0x2c, 0x01, 0x45,
  39917. 0x81, 0x00, 0xe5, 0x5e, 0x8d, 0xae, 0x1c, 0x96, 0x8b, 0x45,
  39918. 0x73, 0x00, 0x0a, 0xb5, 0xcf, 0x8d, 0x0e, 0x35, 0x5d, 0x1a,
  39919. 0x0e, 0xbf, 0x64, 0x9a, 0x52, 0x20, 0x48, 0xc6, 0xb9, 0x40,
  39920. 0xd3, 0x2c, 0x52, 0xca, 0x93, 0xcf, 0xbb, 0x94, 0x06, 0xf3,
  39921. 0x97, 0xee, 0xcc, 0x5d, 0xa3, 0xea, 0xf8, 0x5a, 0x39, 0x77,
  39922. 0x34, 0xd7, 0xf6, 0x4e, 0xbe, 0x8a, 0x07, 0x5f, 0x51, 0x53,
  39923. 0xc5, 0x1b, 0x8c, 0x47, 0x8f, 0x34, 0x0e, 0x60, 0x0a, 0x90,
  39924. 0xe2, 0xda, 0x7b, 0xef, 0xd6, 0xf5, 0x5d, 0xe5, 0x32, 0x37,
  39925. 0x75, 0x99, 0x81, 0x4a, 0x2a, 0x78, 0x71, 0xdc, 0xf4, 0xe5,
  39926. 0xca, 0xd8, 0x6b, 0x3b, 0x90, 0x68, 0x2e, 0x93, 0xc5, 0x10,
  39927. 0x42, 0x5d, 0x38, 0x90, 0x32, 0x46, 0xea, 0x87, 0xe0, 0xbc,
  39928. 0xb8, 0x9a, 0x18, 0x20, 0x68, 0x85, 0x6d, 0x9b, 0xc9, 0x8f,
  39929. 0x9b, 0xd2, 0xbe, 0x15, 0x12, 0x68, 0xd0, 0xb0, 0x16, 0x5f,
  39930. 0xe2, 0x69, 0x1d, 0x04, 0x00, 0xfc, 0x63, 0x33, 0xcd, 0x1f,
  39931. 0x89, 0xcd, 0x52, 0xff, 0xec, 0x19, 0x69, 0x74, 0xa3, 0xce,
  39932. 0x4d, 0xab, 0x93, 0xe4, 0xc6, 0x13, 0x56, 0x27, 0xc9, 0x25,
  39933. 0x5a, 0x01, 0xb2, 0x36, 0x8b, 0x61, 0xe5, 0x8b, 0x98, 0xac,
  39934. 0xe4, 0x2a, 0xb6, 0x40, 0x9f, 0x42, 0xe4, 0x1b, 0x52, 0xf7,
  39935. 0xfd, 0xd8, 0x30, 0x07, 0x33, 0xf9, 0x47, 0xcb, 0x3c, 0xad,
  39936. 0x12, 0xc1, 0xcc, 0x29, 0x62, 0x49, 0x04, 0x0c, 0x23, 0x97,
  39937. 0x5a, 0xa4, 0x84, 0x67, 0xde, 0x5a, 0xe5, 0x36, 0xd2, 0x88,
  39938. 0xf1, 0xd4, 0xeb, 0x13, 0x81, 0x54, 0x51, 0x11, 0xe3, 0xba,
  39939. 0xbc, 0xee, 0xdd, 0x6c, 0xcd, 0xe6, 0xb4, 0xa1, 0x8b, 0x0b,
  39940. 0x66, 0xfb, 0x8e, 0x50, 0xa0, 0xda, 0x69, 0x8d, 0xcc, 0x2d,
  39941. 0xe4, 0x2c, 0xc4, 0x37, 0xdf, 0x61, 0xc0, 0x03, 0xbd, 0x8b,
  39942. 0x28, 0xca, 0xd2, 0x8c, 0x1c, 0xf1, 0xa4, 0x26, 0x69, 0xe5,
  39943. 0xcf, 0x45, 0xdb, 0x5a, 0x47, 0x79, 0xed, 0x9f, 0xf7, 0xd2,
  39944. 0xdb, 0xba, 0x46, 0x53, 0x4f, 0xce, 0xa8, 0xbe, 0x8f, 0x4a,
  39945. 0xd6, 0xdf, 0x2e, 0x06, 0xe6, 0x4c, 0x9a, 0xc1, 0xb6, 0x49,
  39946. 0xed, 0xc4, 0xeb, 0xaa, 0xa4, 0x29, 0x6d, 0xd4, 0xcc, 0x8c,
  39947. 0xb6, 0x40, 0x11, 0x39, 0x69, 0xf7, 0x75, 0xcd, 0xb1, 0x99,
  39948. 0x46, 0x4e, 0xde, 0xcb, 0xf6, 0x9d, 0x32, 0xf3, 0xc9, 0x47,
  39949. 0x47, 0x7a, 0xcb, 0xfb, 0xa3, 0x0c, 0x3b, 0xdf, 0xb7, 0xde,
  39950. 0xec, 0x99, 0xde, 0xb0, 0x26, 0x04, 0x34, 0xae, 0x6b, 0xfc,
  39951. 0x99, 0xbc, 0xde, 0xd5, 0xbe, 0xe7, 0xeb, 0xf9, 0xe7, 0xa6,
  39952. 0x01, 0x9a, 0x0c, 0x5e, 0x66, 0xe6, 0x53, 0xe4, 0xd1, 0x58,
  39953. 0xac, 0xda, 0x69, 0x77, 0x7b, 0x68, 0xd6, 0x30, 0x2a, 0x9c,
  39954. 0x6b, 0xbe, 0x9f, 0x3d, 0x71, 0xd6, 0x54, 0xcd, 0x59, 0x4e,
  39955. 0x1f, 0xe3, 0x83, 0x4e, 0xd1, 0x8e, 0xaf, 0x97, 0xa8, 0xe5,
  39956. 0xb6, 0x59, 0x77, 0xa8, 0x02, 0x20, 0xe4, 0xeb, 0x44, 0x71,
  39957. 0xbc, 0x07, 0x14, 0x79, 0x4f, 0x0c, 0x27, 0x06, 0x39, 0xcf,
  39958. 0x7c, 0xef, 0x2b, 0x9b, 0x5e, 0xc4, 0x6d, 0x79, 0x13, 0x00,
  39959. 0x43, 0x6f, 0x51, 0x77, 0xb5, 0xc3, 0x72, 0xad, 0x13, 0xa9,
  39960. 0xe5, 0x9a, 0x5b, 0x1a, 0x99, 0x74, 0xc0, 0x7a, 0xf9, 0xc5,
  39961. 0xb0, 0x58, 0x35, 0x1c, 0xa5, 0x51, 0xdb, 0xa1, 0x14, 0xcd,
  39962. 0x26, 0x71, 0xb1, 0xe7, 0xaa, 0x14, 0xa7, 0x46, 0x93, 0xd3,
  39963. 0x5c, 0x8c, 0x1a, 0x91, 0x77, 0x46, 0x2e, 0x15, 0xaa, 0x9e,
  39964. 0xf7, 0x2b, 0x79, 0x41, 0x76, 0xf7, 0x22, 0x53, 0x7d, 0x51,
  39965. 0xdb, 0x98, 0x3d, 0x5b, 0x78, 0x5f, 0xc3, 0xc9, 0x29, 0xa3,
  39966. 0xff, 0x75, 0x82, 0x06, 0x9a, 0x16, 0x5e, 0xa4, 0x79, 0x0d,
  39967. 0xd1, 0x6d, 0x08, 0xff, 0x43, 0xef, 0x9c, 0xf3, 0x1b, 0x7a,
  39968. 0x3f, 0x34, 0xbe, 0x19, 0x15, 0x06, 0x33, 0xdb, 0xa5, 0x71,
  39969. 0xcb, 0x5f, 0x6b, 0x8d, 0xbd, 0x5b, 0x32, 0x91, 0xb2, 0x37,
  39970. 0x3d, 0xb4, 0x40, 0x9e, 0x02, 0x9b, 0xb7, 0x68, 0x20, 0x58,
  39971. 0x5c, 0xab, 0xcb, 0xc8, 0x23, 0x2d, 0x77, 0xcc, 0x0b, 0xf6,
  39972. 0x78, 0x6b, 0x80, 0x06, 0x91, 0xa9, 0xfd, 0x7e, 0xfa, 0x25,
  39973. 0x98, 0x9f, 0xcc, 0x79, 0x0a, 0x1a, 0x54, 0x83, 0xac, 0x64,
  39974. 0x16, 0x90, 0xe5, 0xd9, 0xa7, 0xd7, 0x1b, 0x86, 0x0d, 0xe6,
  39975. 0xe6, 0x22, 0x2b, 0x1f, 0x44, 0x49, 0x98, 0x9c, 0x51, 0x6f,
  39976. 0xcf, 0x58, 0x4a, 0xfa, 0xfa, 0x84, 0x12, 0xa5, 0x10, 0xf4,
  39977. 0xca, 0xf0, 0x98, 0x2b, 0xc9, 0x03, 0x71, 0x37, 0xe7, 0xdc,
  39978. 0xc2, 0xb1, 0x4e, 0x64, 0xde, 0x4f, 0x46, 0x0d, 0x6b, 0x25,
  39979. 0x88, 0x5d, 0xd6, 0xff, 0x23, 0x46, 0x57, 0x36, 0x14, 0x18,
  39980. 0xa7, 0xcb, 0xb8, 0xbd, 0xf0, 0xc5, 0x37, 0x36, 0xee, 0xe1,
  39981. 0xed, 0x9f, 0x4d, 0xd4, 0x39, 0xe5, 0x92, 0xcf, 0x95, 0x4d,
  39982. 0x66, 0x36, 0x5d, 0xd0, 0xcc, 0x07, 0xcf, 0x15, 0x5a, 0xce,
  39983. 0x14, 0xb8, 0xda, 0x0d, 0x3d, 0x1b, 0x45, 0xc5, 0x2e, 0x34,
  39984. 0x43, 0x25, 0x02, 0x3a, 0xcd, 0x14, 0x45, 0xfb, 0x3e, 0xf9,
  39985. 0x88, 0x5d, 0x0d, 0x29, 0x31, 0xb9, 0xa1, 0xe6, 0x31, 0x18,
  39986. 0x52, 0x46, 0x3f, 0x22, 0x4f, 0x9f, 0x7a, 0x65, 0x36, 0x88,
  39987. 0xa3, 0x1c, 0x3e, 0x6f, 0x50, 0x7a, 0x36, 0xbe, 0x56, 0x7e,
  39988. 0x50, 0xcb, 0x7a, 0x10, 0xa0, 0xec, 0xf6, 0x82, 0xd6, 0x30,
  39989. 0x1c, 0xe8, 0x4c, 0x50, 0xf9, 0x3e, 0xdb, 0xac, 0xbe, 0x4f,
  39990. 0x90, 0xb1, 0xd5, 0x1b, 0x12, 0x95, 0xfb, 0xe8, 0x08, 0x64,
  39991. 0x56, 0x7c, 0x96, 0xcc, 0x90, 0xb1, 0xbc, 0xa0, 0xf5, 0x32,
  39992. 0x69, 0xb3, 0x5f, 0x27, 0x0f, 0xbe, 0xc9, 0xbd, 0xeb, 0xfa,
  39993. 0x4b, 0x5c, 0xc5, 0x99, 0x9e, 0x5a, 0x04, 0xcc, 0xd0, 0x4d,
  39994. 0x29, 0xe8, 0x84, 0x55, 0x8c, 0xd7, 0xc4, 0x06, 0x13, 0x4d,
  39995. 0x92, 0xe5, 0x98, 0x9c, 0x4c, 0xc1, 0xf7, 0xaf, 0x7b, 0xd5,
  39996. 0x2b, 0x92, 0x68, 0x68, 0x19, 0x70, 0x4c, 0x9e, 0x46, 0xb8,
  39997. 0x34, 0xeb, 0x01, 0x47, 0xbe, 0x59, 0xab, 0x0b, 0x22, 0x25,
  39998. 0xe7, 0x56, 0xa8, 0xb4, 0x93, 0x3c, 0xd5, 0x98, 0x9f, 0x61,
  39999. 0x2e, 0xfa, 0xcb, 0x5f, 0x5b, 0xd8, 0x09, 0x83, 0xe9, 0x40,
  40000. 0xe9, 0x0e, 0x42, 0xdd, 0x17, 0xd7, 0x6e, 0x19, 0x8d, 0x95,
  40001. 0x0a, 0x93
  40002. };
  40003. #endif
  40004. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_sig[] = {
  40005. 0x20, 0xff, 0x12, 0xe1, 0x87, 0xf6, 0x11, 0x38, 0xff, 0x41, 0xd0, 0x8f,
  40006. 0xcd, 0x7e, 0xd1, 0xf6, 0x21, 0x17, 0xd0, 0x46, 0xe9, 0x86, 0x83, 0x1b,
  40007. 0xaf, 0xe5, 0x2b, 0x59, 0x21, 0xd1, 0x6b, 0xc9, 0xdb, 0x34, 0xdc, 0xba,
  40008. 0xfd, 0xd3, 0xf8, 0x71, 0x49, 0xd8, 0x31, 0xbc, 0x48, 0x83, 0x22, 0x7b,
  40009. 0xfd, 0x6a, 0x93, 0xa6, 0x39, 0x4c, 0xda, 0xdb, 0x15, 0xe7, 0x41, 0x14,
  40010. 0xb4, 0xb8, 0xfe, 0xb0, 0x1f, 0xf9, 0x0a, 0x2c, 0x0b, 0xc0, 0xac, 0x09,
  40011. 0x84, 0x69, 0x5e, 0x64, 0x8c, 0xa8, 0xee, 0xa1, 0x52, 0x22, 0xde, 0x0d,
  40012. 0xc7, 0x25, 0xef, 0xa8, 0xfd, 0x8c, 0xb9, 0x45, 0x4f, 0xa4, 0x9c, 0xbc,
  40013. 0x70, 0xf2, 0x88, 0xea, 0x79, 0x13, 0xb0, 0xfc, 0xe6, 0x41, 0x48, 0x1c,
  40014. 0x33, 0x48, 0xa2, 0x77, 0x75, 0x37, 0x9f, 0xc1, 0x86, 0x94, 0xcd, 0x69,
  40015. 0x98, 0x87, 0x47, 0x49, 0x75, 0x93, 0xf1, 0xa4, 0x2d, 0x8e, 0xa8, 0x7e,
  40016. 0x0f, 0x95, 0xf5, 0x3e, 0x5d, 0x31, 0x2d, 0xc9, 0x58, 0x1c, 0x42, 0xfd,
  40017. 0x79, 0x6a, 0x49, 0xa3, 0x84, 0xc5, 0x2e, 0x8d, 0x96, 0x9c, 0xc8, 0x05,
  40018. 0x93, 0xdb, 0x6d, 0xbf, 0x83, 0x34, 0xc2, 0x81, 0x47, 0x90, 0xc9, 0xa9,
  40019. 0x82, 0xbd, 0xe1, 0xc8, 0x89, 0xa2, 0x36, 0x47, 0xed, 0xfb, 0x47, 0x57,
  40020. 0x01, 0x1a, 0x75, 0x8c, 0x6b, 0x83, 0xcf, 0x56, 0xae, 0x52, 0x66, 0x8b,
  40021. 0xab, 0x7f, 0x0c, 0xec, 0xde, 0x5c, 0x13, 0xbe, 0xbd, 0x5b, 0x74, 0x28,
  40022. 0xb5, 0xd7, 0x68, 0xd5, 0xd2, 0xe9, 0x96, 0x3b, 0x55, 0xda, 0x3a, 0x93,
  40023. 0x3c, 0xd9, 0x9f, 0x53, 0x2a, 0x31, 0x84, 0x45, 0x3f, 0xee, 0x2b, 0xfc,
  40024. 0x92, 0xb0, 0x9c, 0xc6, 0x16, 0x16, 0x4f, 0x33, 0x41, 0x17, 0x58, 0xbe,
  40025. 0x5d, 0x57, 0x4b, 0x04, 0x82, 0xe3, 0xb3, 0x68, 0xdf, 0x7c, 0x93, 0xce,
  40026. 0x9d, 0xf6, 0x7e, 0x21, 0x3d, 0x28, 0x1c, 0xf0, 0x37, 0x46, 0xf2, 0xc2,
  40027. 0x73, 0x7c, 0xbe, 0x98, 0x0e, 0x09, 0x75, 0xa7, 0x21, 0x11, 0xa9, 0xd6,
  40028. 0xd1, 0x47, 0xac, 0xd0, 0x19, 0x48, 0x3b, 0x74, 0xc1, 0x3c, 0x37, 0x43,
  40029. 0x49, 0x12, 0x62, 0xee, 0xaf, 0x5c, 0x38, 0xf7, 0x8a, 0xce, 0xb3, 0x7a,
  40030. 0x05, 0x16, 0xd4, 0x71, 0x8b, 0xbe, 0x1a, 0xe0, 0x1e, 0xbc, 0x4b, 0x54,
  40031. 0x0f, 0xb5, 0x73, 0x2b, 0xb8, 0x3a, 0x75, 0xf0, 0x26, 0xcd, 0xf9, 0xca,
  40032. 0x32, 0xf9, 0x7e, 0x15, 0x38, 0x75, 0x9c, 0x4d, 0xbc, 0x11, 0xf8, 0xea,
  40033. 0x8e, 0xe8, 0x38, 0x17, 0xc5, 0x62, 0xf4, 0x34, 0xfb, 0xd6, 0xf5, 0x76,
  40034. 0xfc, 0xa3, 0xf3, 0x44, 0xf9, 0xab, 0x2e, 0x9a, 0x68, 0xcd, 0xa1, 0x29,
  40035. 0xff, 0xda, 0xe8, 0xb5, 0xb0, 0x20, 0x5d, 0x02, 0x01, 0x62, 0x26, 0x44,
  40036. 0x32, 0xc8, 0x94, 0xf8, 0xf1, 0xaa, 0xf9, 0xc2, 0x86, 0xcb, 0x55, 0x7f,
  40037. 0x8d, 0xb3, 0xf6, 0x63, 0xb1, 0xa4, 0x95, 0x57, 0xb8, 0x1d, 0xc3, 0x42,
  40038. 0xd2, 0x4b, 0x69, 0xcd, 0x7a, 0x10, 0x5b, 0x6a, 0x13, 0xd1, 0x02, 0x98,
  40039. 0x38, 0x87, 0x9b, 0x9a, 0x5a, 0x66, 0x73, 0xcb, 0x75, 0xd0, 0x7a, 0x4b,
  40040. 0xad, 0x23, 0x06, 0x1c, 0xc8, 0x6b, 0x0c, 0xa8, 0xfe, 0x7b, 0x8f, 0x65,
  40041. 0x50, 0xd7, 0xf7, 0x76, 0x88, 0x42, 0xe0, 0x5e, 0x18, 0x91, 0x8b, 0x99,
  40042. 0x37, 0x56, 0x08, 0x91, 0xe7, 0x01, 0xe7, 0x05, 0xd5, 0xed, 0x43, 0x25,
  40043. 0x71, 0x7e, 0x3e, 0xfc, 0xc4, 0xfd, 0xed, 0x8b, 0x85, 0x16, 0x8c, 0xe3,
  40044. 0x05, 0xee, 0x51, 0x02, 0xa4, 0x4b, 0xd8, 0x3c, 0xcf, 0x4d, 0x2f, 0x2d,
  40045. 0x68, 0x6e, 0xc1, 0xd5, 0xfa, 0x91, 0xfd, 0x6a, 0xe0, 0x64, 0x85, 0x35,
  40046. 0x9c, 0x75, 0xe6, 0x0d, 0xb8, 0xec, 0x97, 0x88, 0x62, 0x98, 0x78, 0x75,
  40047. 0xc7, 0x1e, 0x68, 0xa7, 0xb9, 0x7b, 0xab, 0x75, 0x7a, 0x72, 0x3c, 0x7b,
  40048. 0xab, 0x60, 0x03, 0xb7, 0x38, 0x13, 0xe4, 0x96, 0x6e, 0xcb, 0x95, 0xcc,
  40049. 0xdc, 0x6a, 0x47, 0x67, 0x77, 0xd7, 0x95, 0xc4, 0x87, 0x66, 0xc2, 0x7e,
  40050. 0x42, 0x90, 0x59, 0x4f, 0xd6, 0xf3, 0xf4, 0xa7, 0xd0, 0x29, 0xf9, 0x5d,
  40051. 0x4b, 0x06, 0x06, 0xf7, 0x6e, 0xb2, 0xab, 0xb0, 0x8e, 0x21, 0xa6, 0xff,
  40052. 0x5e, 0x7b, 0x47, 0xb6, 0x3a, 0xa6, 0x9e, 0x19, 0xf6, 0xdf, 0x9b, 0x3b,
  40053. 0x3d, 0x07, 0x37, 0xd1, 0x0b, 0xa8, 0xf3, 0x9c, 0x43, 0x89, 0xee, 0xba,
  40054. 0x03, 0xee, 0x38, 0x74, 0x13, 0x09, 0x8e, 0x47, 0x4e, 0xa9, 0x14, 0xf5,
  40055. 0xb0, 0x55, 0xe0, 0x03, 0xe5, 0xb9, 0x53, 0xef, 0x03, 0x15, 0x60, 0xb3,
  40056. 0x4a, 0x71, 0x31, 0x4b, 0xf1, 0xc8, 0xe4, 0x63, 0x9b, 0x8b, 0x78, 0x3c,
  40057. 0x1f, 0xac, 0x27, 0x20, 0xa8, 0x53, 0x7d, 0xdd, 0x72, 0xd3, 0x90, 0x8f,
  40058. 0x71, 0xa6, 0xa7, 0xeb, 0xb0, 0xeb, 0x42, 0x96, 0xa4, 0xc3, 0xba, 0xc6,
  40059. 0x3c, 0xe7, 0x7b, 0x15, 0x1e, 0xfa, 0x15, 0x23, 0x37, 0xf3, 0xc8, 0xb2,
  40060. 0xf9, 0x46, 0x04, 0xd1, 0x5e, 0x44, 0xd7, 0x8f, 0x70, 0xb1, 0x0a, 0xde,
  40061. 0x6a, 0xe3, 0xaf, 0x9e, 0x49, 0x55, 0x78, 0x79, 0x11, 0x22, 0x87, 0xa9,
  40062. 0x54, 0x7c, 0xb4, 0x83, 0xe1, 0x25, 0xcd, 0x89, 0xa6, 0x91, 0x21, 0x7b,
  40063. 0xbe, 0x3d, 0x2f, 0x46, 0xb5, 0x5b, 0x50, 0x1a, 0xc8, 0x8d, 0x32, 0xf3,
  40064. 0x62, 0x1f, 0x24, 0x64, 0xe8, 0xb6, 0x02, 0x4f, 0x1f, 0x52, 0x3c, 0x40,
  40065. 0xfc, 0x72, 0x38, 0xd4, 0xba, 0x40, 0x8e, 0xb7, 0xc0, 0x97, 0x06, 0x16,
  40066. 0xd5, 0xe3, 0x39, 0x45, 0xd7, 0x7c, 0x0e, 0xed, 0x6b, 0x19, 0x19, 0x0a,
  40067. 0x8e, 0xcb, 0x2b, 0xee, 0x4d, 0xa1, 0x5e, 0x84, 0x22, 0x66, 0xcd, 0x4f,
  40068. 0xb9, 0x1a, 0x25, 0x85, 0x02, 0xc0, 0x67, 0xc4, 0xd5, 0x1a, 0xcb, 0xbb,
  40069. 0xde, 0x4d, 0x3c, 0x3c, 0x62, 0x9f, 0x76, 0x8f, 0x15, 0x29, 0xa5, 0xbb,
  40070. 0x5a, 0x48, 0x38, 0x66, 0xfa, 0x56, 0x0a, 0x09, 0xbd, 0xdf, 0xdf, 0x4a,
  40071. 0xe7, 0x0e, 0xa6, 0xb1, 0xb5, 0x7c, 0xe1, 0xed, 0x8d, 0x63, 0x07, 0x42,
  40072. 0xf3, 0xf8, 0x15, 0x28, 0x7c, 0x09, 0xf5, 0x02, 0x69, 0x1b, 0x88, 0x1e,
  40073. 0x3d, 0xad, 0x5f, 0x46, 0xed, 0xab, 0x2b, 0x11, 0x96, 0x73, 0xa8, 0xe8,
  40074. 0xe6, 0x64, 0x7d, 0xae, 0x13, 0xa1, 0x7d, 0x54, 0xae, 0xc0, 0x82, 0xeb,
  40075. 0x2a, 0xd1, 0x76, 0xb7, 0x9f, 0xbd, 0x33, 0x8f, 0xe7, 0xe6, 0x79, 0x92,
  40076. 0xa6, 0xaf, 0x61, 0x91, 0x49, 0xbc, 0xd2, 0x3c, 0x6f, 0x8b, 0xbe, 0x8f,
  40077. 0x5f, 0x1f, 0x00, 0x2c, 0x2e, 0x2c, 0xa0, 0x14, 0xcf, 0x34, 0x42, 0x44,
  40078. 0x41, 0x11, 0xd7, 0x37, 0xd3, 0x99, 0x44, 0x36, 0x43, 0x03, 0xb9, 0x50,
  40079. 0x4f, 0xab, 0xfe, 0x48, 0xe2, 0x4b, 0xed, 0x51, 0x8b, 0xe0, 0x04, 0x3c,
  40080. 0x93, 0x28, 0x55, 0xc8, 0x5a, 0xb3, 0x52, 0x2c, 0x56, 0xbd, 0x43, 0xb9,
  40081. 0x4a, 0x6c, 0x4c, 0xcc, 0xda, 0xba, 0x9c, 0xe6, 0x3e, 0x50, 0x8b, 0x1a,
  40082. 0xe5, 0x83, 0xc1, 0x60, 0x55, 0xb2, 0x02, 0x16, 0x54, 0x33, 0x62, 0x69,
  40083. 0x7c, 0x7d, 0x94, 0xf2, 0xb0, 0x3a, 0x22, 0xf0, 0x21, 0x46, 0xd7, 0x94,
  40084. 0x53, 0xec, 0x63, 0x4c, 0x3e, 0xc3, 0x71, 0xd1, 0xb9, 0x2e, 0x16, 0xe8,
  40085. 0x17, 0x63, 0x7e, 0x0c, 0x83, 0x05, 0x72, 0xe6, 0x20, 0x60, 0x34, 0xae,
  40086. 0x0e, 0x54, 0xa0, 0x57, 0x75, 0x93, 0x2e, 0xb8, 0x6c, 0xec, 0xda, 0x44,
  40087. 0x1b, 0xac, 0xd6, 0x75, 0xc5, 0x79, 0x3c, 0xc2, 0xa6, 0xa2, 0x7f, 0x3a,
  40088. 0xb0, 0xec, 0xeb, 0xc1, 0xe6, 0xd6, 0xae, 0xac, 0x2e, 0x55, 0x30, 0x1c,
  40089. 0x81, 0xa4, 0x4c, 0x35, 0x0e, 0xd8, 0xa6, 0x4e, 0xea, 0x0e, 0xbf, 0x79,
  40090. 0xf7, 0xdf, 0x55, 0xfc, 0xf9, 0x24, 0xb0, 0xa6, 0xba, 0xc3, 0x72, 0x42,
  40091. 0x60, 0x06, 0x44, 0x03, 0xe3, 0x40, 0x3c, 0x2a, 0x13, 0xf7, 0xdf, 0x3d,
  40092. 0xb7, 0x0d, 0x86, 0x6c, 0xb0, 0x0f, 0x2e, 0x72, 0x91, 0x16, 0x4f, 0x5f,
  40093. 0xd0, 0x3e, 0x8c, 0x36, 0xed, 0xa8, 0x6f, 0xbc, 0x65, 0xb0, 0x65, 0x99,
  40094. 0x47, 0x50, 0xa5, 0x9c, 0xea, 0xee, 0x8a, 0x44, 0x70, 0xf5, 0x31, 0x1a,
  40095. 0xe9, 0x11, 0xc1, 0xce, 0xe0, 0x21, 0x52, 0x70, 0x89, 0xf7, 0xc3, 0x35,
  40096. 0xfa, 0x55, 0x5a, 0xc5, 0x10, 0x02, 0xc4, 0xc7, 0xf7, 0xe1, 0xaf, 0x49,
  40097. 0x48, 0x61, 0xe7, 0x0d, 0xa1, 0x2d, 0x7d, 0x03, 0x00, 0x38, 0xa7, 0xd5,
  40098. 0xd3, 0xbf, 0x95, 0x29, 0xed, 0xcc, 0x70, 0x3e, 0xbe, 0x95, 0x8a, 0xdf,
  40099. 0xaf, 0xbf, 0xec, 0xf8, 0x6a, 0x4f, 0x9e, 0x69, 0xee, 0x4e, 0x3d, 0x8b,
  40100. 0x58, 0xa0, 0x2e, 0xb5, 0x83, 0x6a, 0x0e, 0x04, 0xa4, 0xa9, 0x74, 0xcb,
  40101. 0x4f, 0xb0, 0x39, 0x37, 0x8f, 0xcf, 0xbf, 0x77, 0xe4, 0x1a, 0x74, 0xcf,
  40102. 0x0e, 0x0d, 0x2d, 0x6e, 0x1d, 0xba, 0xc1, 0xf5, 0x7c, 0x54, 0x6e, 0x92,
  40103. 0xec, 0x4b, 0x03, 0xc3, 0xa4, 0x44, 0xad, 0x3e, 0x4f, 0xa4, 0xd9, 0xe9,
  40104. 0x71, 0x3c, 0xe6, 0xb6, 0xbe, 0xe7, 0xfc, 0x72, 0x76, 0x86, 0x9a, 0x73,
  40105. 0xb1, 0xb3, 0xf3, 0x84, 0xb6, 0x2a, 0x40, 0x0b, 0x8c, 0xae, 0xb3, 0xc4,
  40106. 0xdc, 0xb5, 0x21, 0x85, 0x87, 0xdc, 0x19, 0x18, 0xd5, 0xba, 0xa4, 0x5e,
  40107. 0x88, 0x89, 0xa4, 0xf4, 0x88, 0x75, 0xc2, 0x7a, 0xb4, 0xee, 0x9d, 0x54,
  40108. 0x66, 0x97, 0x70, 0x08, 0x8f, 0x99, 0x84, 0x5d, 0x5e, 0xa7, 0x6f, 0x92,
  40109. 0xe8, 0xa3, 0x65, 0xfa, 0x0e, 0x87, 0xfb, 0x3c, 0xe9, 0x17, 0x2d, 0xc7,
  40110. 0x2d, 0x30, 0x8f, 0x41, 0x82, 0x68, 0x2b, 0xf1, 0x67, 0x8e, 0xf7, 0x05,
  40111. 0x78, 0xfa, 0xc3, 0x61, 0xba, 0x35, 0xe7, 0x2f, 0x19, 0xef, 0x71, 0x36,
  40112. 0xac, 0x5b, 0xf0, 0x45, 0x30, 0x70, 0xdc, 0xc7, 0xab, 0x7b, 0x62, 0x17,
  40113. 0x9d, 0xc4, 0x43, 0x6f, 0xfc, 0x02, 0x56, 0x5f, 0x65, 0xaa, 0x68, 0x3b,
  40114. 0x5c, 0xfa, 0x71, 0x28, 0x89, 0xe9, 0x28, 0x2f, 0x95, 0x4b, 0xfc, 0xe6,
  40115. 0xe7, 0xc8, 0x44, 0x28, 0x5c, 0x3c, 0x08, 0x5f, 0x9c, 0xbc, 0x41, 0x68,
  40116. 0x91, 0x98, 0x7a, 0x00, 0x63, 0xc9, 0x5c, 0x75, 0x8f, 0xcc, 0x33, 0x77,
  40117. 0x7b, 0xd0, 0x2d, 0xe8, 0xa2, 0x98, 0xa4, 0x1b, 0xfa, 0x09, 0x67, 0x7b,
  40118. 0x25, 0x96, 0x19, 0xf4, 0x77, 0x33, 0x20, 0x4f, 0x19, 0xf6, 0x9c, 0x6c,
  40119. 0x2e, 0xd9, 0x68, 0x95, 0xb0, 0xe2, 0x18, 0x06, 0xe5, 0x84, 0x8e, 0xf7,
  40120. 0xbf, 0x6c, 0x96, 0xa8, 0x9d, 0x37, 0xc7, 0x28, 0xa1, 0x3d, 0x90, 0x8c,
  40121. 0x40, 0x3d, 0xe2, 0x51, 0xfd, 0x55, 0x09, 0xf8, 0x83, 0x43, 0x44, 0x4d,
  40122. 0x1c, 0x8a, 0x8d, 0x36, 0x84, 0x64, 0xc4, 0xfa, 0x1d, 0x72, 0x04, 0x0b,
  40123. 0x1d, 0x49, 0x13, 0x88, 0x78, 0x5f, 0x07, 0x9b, 0xc8, 0x01, 0x9c, 0x3c,
  40124. 0xfc, 0xff, 0x0f, 0xd5, 0x13, 0xcd, 0x15, 0x98, 0xcc, 0xe6, 0x59, 0x1e,
  40125. 0x83, 0x38, 0x8f, 0x6c, 0x75, 0xbe, 0xdf, 0xe9, 0x1b, 0xc5, 0xb9, 0x6b,
  40126. 0xa4, 0x5a, 0x0c, 0xae, 0x98, 0x8d, 0x93, 0xfa, 0x76, 0x7f, 0x0d, 0x0b,
  40127. 0xe8, 0xa0, 0x3b, 0x9e, 0x5e, 0xc8, 0xa8, 0xcc, 0x02, 0xc9, 0x86, 0x9c,
  40128. 0x78, 0xaf, 0x6e, 0x6a, 0xf4, 0xfe, 0x49, 0xad, 0xc5, 0x93, 0xae, 0x62,
  40129. 0xbd, 0xe3, 0x3a, 0xa8, 0xf2, 0x60, 0xb5, 0x29, 0xde, 0x5f, 0x12, 0x02,
  40130. 0x2d, 0x43, 0x90, 0xf5, 0x9d, 0x9d, 0x97, 0x29, 0xfa, 0xdd, 0x60, 0x41,
  40131. 0x64, 0xb7, 0xa5, 0x03, 0x72, 0x10, 0x2b, 0xdd, 0x5b, 0x60, 0xe6, 0xf0,
  40132. 0xe1, 0xd7, 0xa5, 0x97, 0xec, 0xb4, 0x9a, 0x4c, 0x3e, 0x16, 0xa2, 0x82,
  40133. 0xb3, 0xc3, 0x3f, 0x3e, 0x5d, 0x32, 0xac, 0x5a, 0x40, 0xb4, 0x00, 0xfa,
  40134. 0xd9, 0x47, 0xe8, 0x77, 0xa8, 0x96, 0x5c, 0x60, 0x04, 0x9c, 0x5c, 0xdf,
  40135. 0x24, 0x3b, 0xa7, 0x4a, 0x58, 0x25, 0x12, 0x9a, 0xa8, 0x7b, 0x3e, 0x14,
  40136. 0xc8, 0x06, 0x79, 0x23, 0xea, 0x91, 0x7f, 0xe1, 0x78, 0x41, 0x6c, 0xdb,
  40137. 0x8c, 0xeb, 0x66, 0x35, 0x87, 0x87, 0x81, 0x65, 0x2c, 0xef, 0x3a, 0x6e,
  40138. 0xae, 0xb3, 0x6c, 0xe9, 0x86, 0x50, 0x6d, 0x89, 0xd6, 0x27, 0x0a, 0xdb,
  40139. 0xf8, 0xd4, 0xb8, 0x85, 0x8e, 0x37, 0xa6, 0x56, 0xf7, 0x58, 0x18, 0x4c,
  40140. 0x44, 0xcf, 0xeb, 0xc4, 0x79, 0x19, 0xfc, 0x2e, 0x53, 0x18, 0x0e, 0x7b,
  40141. 0x51, 0x86, 0xf3, 0x59, 0x13, 0xb2, 0xaf, 0xd3, 0xee, 0xf4, 0xd5, 0xbf,
  40142. 0x2c, 0xb8, 0x6d, 0x71, 0x74, 0x7c, 0x67, 0x54, 0xa7, 0x4b, 0x03, 0xa9,
  40143. 0x1b, 0x62, 0x95, 0x9f, 0xc3, 0xf0, 0x71, 0x39, 0x2d, 0x26, 0xaf, 0xaf,
  40144. 0xa7, 0xa5, 0x58, 0xf8, 0xf8, 0x8a, 0xe0, 0x62, 0x90, 0x3f, 0x72, 0x9d,
  40145. 0x21, 0x82, 0x76, 0x3e, 0x4c, 0x5d, 0xe0, 0xb5, 0x67, 0x23, 0xe3, 0x13,
  40146. 0x1a, 0x29, 0xa3, 0xda, 0xa4, 0xb4, 0x5c, 0x1d, 0x47, 0xdf, 0xdf, 0xc9,
  40147. 0x93, 0x6c, 0xb2, 0xb5, 0x22, 0xb3, 0x47, 0x2b, 0xcf, 0xf0, 0x36, 0x87,
  40148. 0x51, 0x3c, 0x79, 0x41, 0x70, 0xbd, 0xea, 0x70, 0xa2, 0x29, 0x90, 0x55,
  40149. 0x30, 0x6f, 0x3e, 0x50, 0xc8, 0x38, 0xd6, 0xfa, 0x6f, 0xe3, 0x39, 0x67,
  40150. 0x88, 0x52, 0x1f, 0xd3, 0x52, 0xbf, 0x3e, 0x7b, 0x2a, 0xe5, 0x1e, 0xcd,
  40151. 0xf9, 0xf1, 0x91, 0x1d, 0x04, 0x61, 0x25, 0xbb, 0xe1, 0x33, 0xe3, 0x66,
  40152. 0x46, 0xed, 0x06, 0x8d, 0xc3, 0x4f, 0x20, 0xc6, 0x24, 0xa7, 0xb5, 0x49,
  40153. 0x3b, 0xc7, 0xe6, 0xa0, 0x77, 0x58, 0xd9, 0x70, 0xb1, 0xf5, 0xec, 0x94,
  40154. 0x19, 0xf3, 0x5b, 0x0f, 0x9a, 0xe4, 0xad, 0x37, 0x81, 0xaf, 0x68, 0x7b,
  40155. 0xe5, 0x67, 0xb5, 0xae, 0x7f, 0x2d, 0x64, 0x78, 0x68, 0x5a, 0xd1, 0x8f,
  40156. 0x1c, 0xc0, 0xc3, 0x5b, 0x21, 0x77, 0xe4, 0xa8, 0x5d, 0x05, 0x50, 0xc1,
  40157. 0x92, 0xee, 0x36, 0x2d, 0xd2, 0xff, 0xee, 0xc2, 0x11, 0x99, 0xee, 0xd7,
  40158. 0x48, 0xfb, 0x6a, 0xa3, 0xc9, 0xb7, 0x0c, 0xc1, 0xe5, 0x12, 0xbf, 0x6f,
  40159. 0x58, 0x66, 0x35, 0x34, 0x26, 0xaa, 0xbe, 0xc3, 0x33, 0x86, 0xfd, 0xc0,
  40160. 0x1c, 0xa5, 0xe4, 0x1e, 0x91, 0xc4, 0x55, 0x4e, 0xf1, 0xcb, 0xd2, 0x0b,
  40161. 0xe8, 0x0d, 0x89, 0x6a, 0x00, 0xbd, 0x7b, 0xf5, 0x3d, 0x1a, 0x4a, 0x48,
  40162. 0xfc, 0xf0, 0x5b, 0xcd, 0xdb, 0xb2, 0xa0, 0x27, 0x4b, 0x8f, 0xf7, 0x87,
  40163. 0x78, 0x13, 0xdb, 0x3f, 0xfb, 0x0b, 0xda, 0x22, 0xb3, 0x2b, 0x3a, 0x38,
  40164. 0xd2, 0x29, 0x73, 0x77, 0xb8, 0xd6, 0xec, 0xab, 0xb4, 0xfe, 0xbe, 0xbb,
  40165. 0x6e, 0xe2, 0xc8, 0x45, 0x7b, 0x0d, 0x36, 0x28, 0x0f, 0x45, 0x72, 0xea,
  40166. 0x6d, 0x38, 0x02, 0x5e, 0x48, 0x89, 0x12, 0x24, 0x1b, 0x33, 0x0f, 0xe9,
  40167. 0xf4, 0xce, 0xf8, 0x27, 0x16, 0x37, 0x29, 0xae, 0xe8, 0x22, 0x03, 0x31,
  40168. 0xa9, 0xa0, 0x73, 0x0c, 0x40, 0xe4, 0xfc, 0x6b, 0xe2, 0x1c, 0x8d, 0x7c,
  40169. 0x40, 0x82, 0x72, 0x28, 0xd0, 0x7d, 0xe5, 0xef, 0x05, 0x14, 0x80, 0x28,
  40170. 0x11, 0x32, 0x0d, 0x63, 0x8a, 0xc3, 0x7c, 0xfe, 0xf5, 0x06, 0x0e, 0xb0,
  40171. 0x78, 0x5c, 0x3a, 0xb6, 0x54, 0x37, 0x46, 0xa7, 0x43, 0x4f, 0x05, 0xec,
  40172. 0xe4, 0x9f, 0xd8, 0x55, 0x1f, 0x70, 0xb3, 0xe6, 0xbc, 0x46, 0x34, 0x9e,
  40173. 0xfc, 0xa4, 0x57, 0x8f, 0x0f, 0x25, 0x6f, 0x9f, 0xb3, 0x80, 0x21, 0x0b,
  40174. 0xa1, 0xca, 0x59, 0xcd, 0x37, 0xf7, 0xc9, 0xcb, 0xbe, 0x91, 0xad, 0x07,
  40175. 0x4f, 0xc7, 0x4e, 0x04, 0xbd, 0x38, 0x8b, 0x63, 0xb5, 0x51, 0xac, 0xc8,
  40176. 0x83, 0x3a, 0xa7, 0xe1, 0x77, 0xbc, 0xa4, 0x0c, 0x6c, 0x50, 0xeb, 0x46,
  40177. 0xe1, 0x45, 0x9a, 0x7b, 0x01, 0xca, 0x54, 0xf0, 0x0f, 0xa0, 0x1f, 0x43,
  40178. 0x9a, 0x19, 0x70, 0x2e, 0x70, 0x5a, 0xcf, 0x3b, 0x1b, 0x41, 0xfd, 0xd3,
  40179. 0x9a, 0xa2, 0x36, 0x14, 0xf0, 0xdd, 0xb0, 0x12, 0x6d, 0xcf, 0x55, 0x3f,
  40180. 0xef, 0x0a, 0xc1, 0x80, 0xa9, 0x68, 0xc3, 0x98, 0x03, 0x46, 0x34, 0xce,
  40181. 0x91, 0xb2, 0x7a, 0x94, 0xd2, 0xe7, 0xb9, 0x9c, 0x56, 0xb8, 0xf8, 0xd6,
  40182. 0xff, 0xbf, 0x8b, 0x39, 0x45, 0x04, 0x45, 0xc9, 0xa2, 0xe2, 0xbb, 0x50,
  40183. 0x68, 0x13, 0x32, 0x1e, 0x09, 0x51, 0xb7, 0xb9, 0xcf, 0x5f, 0xcc, 0x54,
  40184. 0xd2, 0xf3, 0xc1, 0x9d, 0xa0, 0x8d, 0x22, 0xc8, 0x7e, 0x1b, 0xc6, 0x14,
  40185. 0xde, 0x5f, 0x52, 0xb4, 0x69, 0x71, 0xca, 0x58, 0x1d, 0x1e, 0x89, 0xcb,
  40186. 0x56, 0x78, 0x7a, 0x85, 0xee, 0xfd, 0xf6, 0x7e, 0xbe, 0x49, 0x9b, 0xb1,
  40187. 0x05, 0x95, 0x12, 0xe9, 0x63, 0xbd, 0x61, 0x9a, 0x26, 0xf9, 0x0b, 0x9f,
  40188. 0x23, 0x0a, 0x59, 0x55, 0x93, 0xd3, 0x2d, 0xca, 0x66, 0x45, 0x03, 0xb7,
  40189. 0xf0, 0x88, 0x9e, 0xc1, 0x11, 0xbb, 0x62, 0x2c, 0x6f, 0xac, 0x3e, 0x87,
  40190. 0xd7, 0xe6, 0x4a, 0x44, 0x83, 0x04, 0x5d, 0x5d, 0xbc, 0x3c, 0xce, 0x83,
  40191. 0x2b, 0x11, 0x42, 0x02, 0x73, 0x1c, 0x24, 0x90, 0xd9, 0x1a, 0x7d, 0x96,
  40192. 0x82, 0x33, 0x75, 0x1e, 0x59, 0xea, 0xa7, 0x99, 0xe1, 0x5b, 0xdc, 0xe4,
  40193. 0x07, 0xc5, 0x48, 0x07, 0xb4, 0xbc, 0x80, 0x0e, 0xbd, 0x63, 0x6e, 0x66,
  40194. 0xf1, 0x12, 0xb6, 0x67, 0xe0, 0x14, 0x74, 0x9f, 0xbb, 0xb3, 0xb8, 0x16,
  40195. 0xd0, 0x25, 0xe9, 0x21, 0x80, 0x1a, 0x32, 0xb0, 0x58, 0x9a, 0x62, 0x17,
  40196. 0x18, 0x9d, 0x64, 0x2d, 0x47, 0x89, 0x82, 0x3b, 0x8c, 0x5d, 0x60, 0xc4,
  40197. 0x54, 0x69, 0xaa, 0xb4, 0x6a, 0x1d, 0x16, 0xb0, 0xe2, 0x5d, 0x7d, 0xeb,
  40198. 0xb9, 0x80, 0x37, 0xcd, 0x5b, 0xf0, 0xa1, 0xa8, 0x39, 0xb2, 0xd6, 0x3a,
  40199. 0xc8, 0xcd, 0xca, 0xaf, 0xcb, 0x3b, 0x54, 0xc2, 0x67, 0x49, 0xf3, 0xf1,
  40200. 0x11, 0x4d, 0x53, 0x7c, 0x46, 0x8d, 0x22, 0xf6, 0x9a, 0x0d, 0x9e, 0xda,
  40201. 0x37, 0xc6, 0x06, 0x00, 0xca, 0xb6, 0xb6, 0x99, 0xc5, 0xb6, 0x81, 0x7e,
  40202. 0x87, 0x62, 0xcf, 0x07, 0x76, 0xc1, 0x5f, 0xfe, 0x86, 0xfc, 0x5b, 0xa0,
  40203. 0xac, 0xca, 0xcb, 0x7d, 0xf5, 0x5a, 0xc2, 0x5e, 0x41, 0x48, 0x35, 0xc4,
  40204. 0x71, 0x9d, 0xc4, 0x0a, 0x79, 0x6f, 0xe3, 0x6d, 0x47, 0xd4, 0xaa, 0xfd,
  40205. 0x97, 0xe7, 0xb0, 0x7e, 0x61, 0xf1, 0x7d, 0x7e, 0xf8, 0x78, 0x4c, 0x2e,
  40206. 0x65, 0x51, 0xeb, 0x99, 0xd0, 0x3e, 0x24, 0x4c, 0xe0, 0x40, 0x7e, 0x2d,
  40207. 0xf7, 0x00, 0x9d, 0x50, 0x87, 0xce, 0x1f, 0x9a, 0xd2, 0x76, 0x00, 0x09,
  40208. 0xeb, 0x10, 0x1b, 0x4c, 0xf1, 0x43, 0x0e, 0x35, 0xbb, 0x23, 0x2e, 0x26,
  40209. 0x3d, 0x66, 0xa3, 0x0f, 0xf6, 0x10, 0x8b, 0x67, 0xce, 0x66, 0xfd, 0xb5,
  40210. 0x07, 0xdc, 0x04, 0x69, 0xad, 0xe0, 0x4d, 0xdf, 0xdb, 0x2f, 0x87, 0xf7,
  40211. 0xde, 0xc3, 0x77, 0x89, 0x71, 0xfd, 0x70, 0x38, 0xed, 0xe6, 0x27, 0xb1,
  40212. 0xbd, 0x94, 0x5f, 0x39, 0x20, 0x72, 0x59, 0xc4, 0x39, 0xd0, 0x20, 0x5d,
  40213. 0xe2, 0xe7, 0xe0, 0x00, 0x61, 0xc7, 0x65, 0xbd, 0xef, 0x05, 0xb3, 0xc7,
  40214. 0x7e, 0xae, 0xc5, 0x83, 0x7f, 0xc1, 0x32, 0x4e, 0x2a, 0x17, 0x64, 0x4e,
  40215. 0x2a, 0x9a, 0x2d, 0x26, 0x99, 0xa2, 0xd7, 0x37, 0x3a, 0x10, 0x6a, 0x89,
  40216. 0x72, 0x43, 0x0e, 0x3a, 0x03, 0x4c, 0xf9, 0xfe, 0xe8, 0xfc, 0x87, 0x71,
  40217. 0x37, 0x71, 0x5a, 0x05, 0xbc, 0x4e, 0x20, 0x4c, 0xd7, 0xf9, 0x8d, 0x4e,
  40218. 0xb8, 0xb8, 0x56, 0x07, 0xc8, 0x6e, 0x34, 0x6d, 0x45, 0x83, 0x34, 0xf0,
  40219. 0x77, 0xfb, 0x18, 0xec, 0x72, 0xf6, 0x4c, 0xfb, 0xba, 0x84, 0xe9, 0x89,
  40220. 0x3d, 0xfd, 0xb7, 0x0d, 0x70, 0xae, 0xa4, 0x48, 0x6b, 0x39, 0xf8, 0x62,
  40221. 0xc0, 0x7f, 0x0c, 0xf2, 0xa3, 0xfa, 0x7a, 0x64, 0x83, 0x57, 0x7d, 0x4c,
  40222. 0x04, 0x96, 0xd7, 0x9d, 0x10, 0x8b, 0x34, 0x48, 0x17, 0xff, 0x74, 0x5c,
  40223. 0x9c, 0xbe, 0xeb, 0xe5, 0x52, 0x94, 0x6a, 0x34, 0x6f, 0xf7, 0x95, 0x32,
  40224. 0x38, 0x5a, 0x9b, 0x08, 0xf6, 0xda, 0x8c, 0x0f, 0x9c, 0x5d, 0x04, 0x45,
  40225. 0xd4, 0xe9, 0xa4, 0x7a, 0xc4, 0xfd, 0x70, 0xfe, 0xa1, 0x3d, 0x21, 0xa0,
  40226. 0x01, 0xe5, 0x21, 0xca, 0xa7, 0xd9, 0xf1, 0x9f, 0x45, 0xe1, 0xe8, 0x2d,
  40227. 0x27, 0xe6, 0x87, 0xc8, 0x0d, 0xad, 0x13, 0xdb, 0xfe, 0x2f, 0xaa, 0x2b,
  40228. 0xdc, 0xa6, 0x1a, 0xc9, 0x19, 0x78, 0x1a, 0x1f, 0x10, 0xcf, 0x31, 0xe1,
  40229. 0x06, 0x28, 0x66, 0xb3, 0xa7, 0xa2, 0xa6, 0xf1, 0x3b, 0x2d, 0xd3, 0x81,
  40230. 0xaf, 0x6f, 0xc9, 0x88, 0x76, 0xe9, 0x83, 0x6c, 0x52, 0xb9, 0x70, 0x51,
  40231. 0x87, 0x6b, 0x8b, 0xbd, 0x5b, 0x9c, 0xa9, 0xf3, 0xcb, 0x55, 0xd1, 0x76,
  40232. 0x40, 0xe1, 0x90, 0xb9, 0x4c, 0xbd, 0xab, 0x1d, 0xa0, 0x5b, 0x5b, 0x34,
  40233. 0x14, 0x2f, 0x87, 0x8f, 0x63, 0xa0, 0x2d, 0x29, 0x4e, 0x50, 0x4b, 0x18,
  40234. 0x5f, 0x86, 0xac, 0x1b, 0x93, 0xe9, 0x59, 0x38, 0xa1, 0x2a, 0x36, 0x21,
  40235. 0xb2, 0xa4, 0xc0, 0x79, 0xc1, 0x60, 0xfc, 0x0f, 0xbf, 0x99, 0x04, 0x9d,
  40236. 0x4b, 0x17, 0x60, 0x5b, 0xcd, 0x78, 0x03, 0xd7, 0x7c, 0x4b, 0x9b, 0x17,
  40237. 0x58, 0x24, 0x60, 0xb8, 0x08, 0x92, 0x48, 0x4f, 0x66, 0x42, 0x9a, 0x98,
  40238. 0x2a, 0x99, 0x9a, 0x8f, 0xdd, 0xd7, 0x09, 0xf3, 0x22, 0x66, 0x62, 0xef,
  40239. 0xe5, 0x64, 0xd3, 0xdf, 0x31, 0xaa, 0x84, 0x4c, 0xa5, 0x3f, 0x4e, 0x27,
  40240. 0x48, 0x37, 0x96, 0x63, 0xbf, 0x8d, 0xe1, 0xf0, 0xd1, 0xef, 0x95, 0x1a,
  40241. 0xe6, 0xf4, 0x02, 0x61, 0xbf, 0xe3, 0xbc, 0x8b, 0x3d, 0x0b, 0x77, 0x91,
  40242. 0xc0, 0x5d, 0xfb, 0xe6, 0x7e, 0xab, 0x5e, 0xc5, 0x1c, 0x5b, 0x16, 0xfd,
  40243. 0x88, 0xa4, 0x78, 0x4c, 0x06, 0x77, 0xc3, 0x6e, 0x84, 0x0c, 0xda, 0xbf,
  40244. 0xf3, 0x8e, 0xd3, 0x61, 0x65, 0xac, 0xf2, 0x18, 0x70, 0x68, 0x84, 0x6f,
  40245. 0x9f, 0x3a, 0x94, 0x81, 0xa6, 0xc7, 0xc3, 0x92, 0xee, 0x4b, 0x20, 0x15,
  40246. 0x4e, 0x03, 0x76, 0x51, 0x5b, 0x4e, 0xe1, 0x5c, 0x51, 0x5e, 0x1b, 0x9c,
  40247. 0x30, 0x25, 0x79, 0xdd, 0x70, 0x12, 0xec, 0xdc, 0x45, 0x95, 0x45, 0x43,
  40248. 0xcd, 0xbb, 0xae, 0xa0, 0x0d, 0x43, 0xb4, 0xc9, 0x8c, 0x62, 0xfd, 0x7b,
  40249. 0xed, 0x50, 0x78, 0xb7, 0xa6, 0x94, 0xcb, 0x98, 0xb0, 0xbe, 0x09, 0xd9,
  40250. 0x0c, 0xb2, 0xc4, 0x8b, 0x96, 0x93, 0xd9, 0x26, 0xc6, 0x6d, 0x26, 0x93,
  40251. 0x32, 0x4e, 0x86, 0x72, 0x74, 0x92, 0x00, 0x72, 0x0b, 0x20, 0xa3, 0x2b,
  40252. 0x94, 0xe6, 0x10, 0x56, 0x5a, 0x41, 0x71, 0x92, 0x08, 0xce, 0x6c, 0xc4,
  40253. 0x1d, 0x9e, 0x71, 0x82, 0x64, 0x23, 0xe5, 0x15, 0xef, 0x4a, 0x7c, 0x4d,
  40254. 0xe3, 0x92, 0xbc, 0xa3, 0xa2, 0x29, 0xb7, 0x46, 0xfa, 0x8f, 0x9f, 0xc2,
  40255. 0x5d, 0xe4, 0xc0, 0x9c, 0x3f, 0x40, 0x17, 0xae, 0x44, 0xf3, 0x28, 0x10,
  40256. 0x29, 0x24, 0xa9, 0x1c, 0x9e, 0xd2, 0x55, 0x4c, 0xee, 0x45, 0xfe, 0x4a,
  40257. 0x45, 0x12, 0xf5, 0xde, 0xc7, 0x64, 0x15, 0xc3, 0x4a, 0x77, 0x63, 0x05,
  40258. 0x8d, 0xa6, 0x31, 0xa0, 0xad, 0x64, 0xaf, 0x3c, 0x69, 0x2c, 0x25, 0x78,
  40259. 0xae, 0xa0, 0x88, 0x96, 0x8a, 0xc2, 0x9b, 0x8d, 0xee, 0x6f, 0x2e, 0x79,
  40260. 0x1f, 0xec, 0x32, 0x35, 0x75, 0x83, 0x19, 0x8b, 0xda, 0xca, 0xd0, 0xaf,
  40261. 0x6a, 0x6c, 0x42, 0xe8, 0x81, 0xb5, 0x69, 0x31, 0x0b, 0x7d, 0xbc, 0xd8,
  40262. 0xd2, 0xb7, 0x7a, 0x8f, 0xfa, 0xcf, 0x91, 0x07, 0x1f, 0xda, 0xa9, 0x1f,
  40263. 0xb7, 0x2d, 0xff, 0x50, 0x15, 0x2a, 0xef, 0x8c, 0xa1, 0xe3, 0x7f, 0x08,
  40264. 0x95, 0xf2, 0x99, 0x83, 0x1f, 0x97, 0x71, 0x3e, 0x35, 0x3c, 0x8c, 0xe7,
  40265. 0x08, 0xd8, 0xa6, 0x1f, 0x0c, 0xa6, 0x52, 0xdc, 0x73, 0xa0, 0xfc, 0xd2,
  40266. 0x73, 0xe9, 0x27, 0x9d, 0xfd, 0x7a, 0x4a, 0x29, 0xd3, 0x12, 0x26, 0x13,
  40267. 0x0f, 0xce, 0xea, 0x56, 0x99, 0x61, 0x78, 0x47, 0x2c, 0xa0, 0x16, 0xa0,
  40268. 0xe2, 0x64, 0x97, 0x57, 0x31, 0xf0, 0x32, 0x5b, 0x44, 0x93, 0x76, 0x8b,
  40269. 0x59, 0x63, 0x5c, 0x5b, 0x0f, 0xe1, 0xe7, 0x74, 0x98, 0x11, 0x2d, 0x90,
  40270. 0xe4, 0xde, 0xd4, 0x3a, 0xc2, 0xfd, 0x24, 0xe3, 0x1f, 0x7a, 0xf4, 0x40,
  40271. 0xbb, 0x51, 0x92, 0x8f, 0x68, 0x9c, 0x51, 0xab, 0xdc, 0xf6, 0x1e, 0x96,
  40272. 0xca, 0x56, 0x5c, 0x92, 0xca, 0xb2, 0x1b, 0x2e, 0x6d, 0x20, 0x28, 0xb3,
  40273. 0x0a, 0x8e, 0xfd, 0xa9, 0xa2, 0x38, 0x74, 0x60, 0x37, 0xa6, 0x96, 0x02,
  40274. 0x20, 0x8a, 0x9a, 0x2b, 0x8c, 0xb9, 0x6d, 0xec, 0xff, 0xbf, 0x88, 0xbd,
  40275. 0x6c, 0xb4, 0x10, 0xbd, 0xfa, 0x5a, 0xeb, 0xb2, 0x6b, 0x74, 0x13, 0x2d,
  40276. 0xa5, 0xdb, 0x60, 0x93, 0xc6, 0xed, 0x39, 0x4f, 0xc5, 0x63, 0xe1, 0x9e,
  40277. 0x57, 0x1f, 0xe7, 0x47, 0xa4, 0xfb, 0x7f, 0xfa, 0x3a, 0x46, 0x50, 0x3a,
  40278. 0xd8, 0xd3, 0x83, 0xf5, 0xe6, 0x5e, 0xf8, 0x09, 0x0d, 0xfa, 0x33, 0xe1,
  40279. 0x50, 0xe4, 0x36, 0x3e, 0x0a, 0x5d, 0xe6, 0xf8, 0x2e, 0x17, 0x87, 0x8f,
  40280. 0xe1, 0x8c, 0x82, 0x73, 0xbd, 0xdd, 0x3b, 0x77, 0x47, 0x9f, 0x42, 0xd7,
  40281. 0xf4, 0x2d, 0x6c, 0xef, 0xcc, 0x22, 0x15, 0x3c, 0xe9, 0x26, 0xea, 0xbc,
  40282. 0xee, 0x09, 0xd3, 0xea, 0x84, 0x0f, 0x46, 0xa8, 0xe0, 0xda, 0xc5, 0x57,
  40283. 0x02, 0x54, 0xb6, 0x88, 0x2b, 0x37, 0xe5, 0x96, 0xc5, 0x33, 0xb7, 0x45,
  40284. 0x5d, 0xb7, 0xc7, 0xfd, 0xa0, 0xfa, 0x85, 0x1b, 0x2f, 0xe1, 0xec, 0x89,
  40285. 0xc6, 0xb2, 0x51, 0x71, 0xcb, 0x08, 0x82, 0x3e, 0xc9, 0xed, 0x80, 0x9d,
  40286. 0x37, 0x31, 0x9d, 0x15, 0xde, 0x24, 0x6f, 0xbd, 0x0e, 0x73, 0xa2, 0xb8,
  40287. 0x7e, 0x29, 0x7e, 0x96, 0xe4, 0xbb, 0xd6, 0x23, 0x17, 0xff, 0x33, 0x97,
  40288. 0x9c, 0x87, 0xe0, 0xe5, 0x0f, 0xb9, 0xb6, 0x31, 0x33, 0xad, 0xf8, 0xd8,
  40289. 0xdb, 0xa0, 0x71, 0x13, 0xe4, 0x1c, 0xce, 0xd0, 0x7e, 0x65, 0x7b, 0xa0,
  40290. 0x38, 0x17, 0x53, 0x4f, 0x71, 0x75, 0x6d, 0x02, 0x61, 0xc4, 0x52, 0xf8,
  40291. 0xe4, 0x2e, 0xbc, 0x52, 0xc1, 0xb1, 0x7e, 0x83, 0x0a, 0xa1, 0xd1, 0xcd,
  40292. 0x2f, 0xa0, 0x30, 0xfd, 0x41, 0x86, 0x7f, 0x26, 0xd1, 0xe7, 0xfc, 0xd7,
  40293. 0xc7, 0x37, 0xe5, 0x11, 0xa6, 0xc0, 0x9a, 0x75, 0x18, 0x04, 0x36, 0xca,
  40294. 0x8e, 0x26, 0x7d, 0xcf, 0xa2, 0x6a, 0x94, 0x9b, 0xc4, 0xf7, 0xc7, 0xeb,
  40295. 0x51, 0x13, 0xa3, 0x6f, 0x8c, 0x80, 0x5f, 0xae, 0xf0, 0x18, 0xa0, 0x88,
  40296. 0xe0, 0x8d, 0xb7, 0x80, 0x4e, 0x8c, 0xec, 0xc8, 0x7b, 0xeb, 0xac, 0x29,
  40297. 0xb7, 0x4a, 0x0f, 0x33, 0xdd, 0x9d, 0x89, 0x0a, 0x10, 0xb0, 0xce, 0x74,
  40298. 0x59, 0xa2, 0x62, 0x91, 0xc9, 0xac, 0x56, 0xcd, 0x69, 0xd3, 0x01, 0x6d,
  40299. 0x51, 0xe7, 0x04, 0xc3, 0xfb, 0xe9, 0x79, 0x1b, 0x72, 0x72, 0x1a, 0x90,
  40300. 0x0a, 0x20, 0x55, 0x85, 0xc1, 0x8b, 0xeb, 0x1e, 0x9f, 0x9f, 0x4a, 0x81,
  40301. 0x47, 0x97, 0x96, 0xbc, 0xc2, 0xe4, 0xc2, 0xfe, 0xa0, 0x20, 0xda, 0x70,
  40302. 0x0c, 0x2b, 0xe2, 0xd4, 0xc8, 0xcb, 0x46, 0x00, 0xb6, 0x7c, 0xfb, 0xbd,
  40303. 0x56, 0x94, 0x3d, 0x7f, 0x64, 0xf7, 0x88, 0xb5, 0xa7, 0xfe, 0xbe, 0x64,
  40304. 0x8a, 0xe4, 0x00, 0x08, 0x82, 0x5b, 0x8f, 0x98, 0x77, 0x87, 0xda, 0xaf,
  40305. 0x16, 0x25, 0x4a, 0x9a, 0xed, 0xfb, 0x50, 0x18, 0x45, 0x46, 0x2b, 0x73,
  40306. 0xff, 0xb9, 0xb9, 0xab, 0xa2, 0x8f, 0x3a, 0xaf, 0xc5, 0x0a, 0x14, 0x91,
  40307. 0xb2, 0x3f, 0xa6, 0x93, 0xf4, 0x81, 0x20, 0x77, 0xfa, 0x51, 0x79, 0x62,
  40308. 0xe8, 0xe6, 0x89, 0x52, 0x39, 0xd5, 0x01, 0xa2, 0x87, 0xa3, 0x53, 0x74,
  40309. 0x3c, 0x36, 0x8a, 0xc3, 0xb4, 0x44, 0x3b, 0x15, 0x21, 0xf6, 0xdc, 0x18,
  40310. 0x02, 0xd2, 0x57, 0xe5, 0x10, 0xf0, 0x3d, 0x61, 0xa7, 0x16, 0x85, 0x6f,
  40311. 0x71, 0x07, 0x75, 0x50, 0x4b, 0x21, 0x53, 0x47, 0x38, 0x35, 0x9e, 0xa7,
  40312. 0xd8, 0xfd, 0x74, 0x59, 0x15, 0x32, 0x7b, 0x89, 0xd0, 0x2c, 0xd9, 0xf6,
  40313. 0x40, 0x49, 0x79, 0xdc, 0xfb, 0x0a, 0x64, 0x59, 0x9b, 0x17, 0x47, 0x36,
  40314. 0xcb, 0xf0, 0xc3, 0xcc, 0x14, 0x8e, 0x1f, 0xa8, 0x12, 0xaa, 0xb7, 0x6a,
  40315. 0xba, 0x45, 0xf9, 0xc4, 0x44, 0xe7, 0xb5, 0x7c, 0xdd, 0xbe, 0x16, 0x76,
  40316. 0x52, 0x92, 0x3d, 0x78, 0xb7, 0xec, 0x81, 0x96, 0xd8, 0x7f, 0x34, 0x2a,
  40317. 0xa2, 0x64, 0x5f, 0xfd, 0xb1, 0x42, 0x4c, 0x79, 0x98, 0xc9, 0x17, 0x48,
  40318. 0x74, 0x12, 0x72, 0x2c, 0xde, 0x91, 0x7e, 0xa9, 0x49, 0x2a, 0xcc, 0x5c,
  40319. 0x60, 0x05, 0x25, 0x09, 0x72, 0x20, 0x80, 0x42, 0x7b, 0x18, 0xc2, 0xfc,
  40320. 0x2a, 0x5e, 0x3e, 0x2d, 0x61, 0xa6, 0xf6, 0x82, 0x42, 0x83, 0x81, 0x66,
  40321. 0x4d, 0xa6, 0xe1, 0xf9, 0xf6, 0x48, 0xd4, 0xc8, 0x69, 0xed, 0xee, 0xb5,
  40322. 0x7a, 0xcb, 0xf6, 0x0a, 0x76, 0x0e, 0x61, 0x8b, 0xf2, 0x1a, 0x8a, 0xa7,
  40323. 0x88, 0xb0, 0x90, 0xd5, 0x23, 0xaa, 0xe0, 0x2b, 0xd6, 0xd0, 0xef, 0x49,
  40324. 0x13, 0x88, 0xc7, 0x50, 0xf0, 0x9e, 0xd5, 0x28, 0xe1, 0xaa, 0x1d, 0xaf,
  40325. 0xd9, 0x73, 0xb3, 0x9e, 0xa7, 0xd8, 0xfc, 0xb9, 0x22, 0x97, 0x0e, 0x21,
  40326. 0xa0, 0xb9, 0xf9, 0xea, 0x1e, 0x95, 0x88, 0xda, 0x85, 0x7c, 0x32, 0x7c,
  40327. 0xbd, 0xef, 0xf8, 0x44, 0x25, 0x5f, 0x23, 0xfd, 0x14, 0x78, 0xc6, 0xdb,
  40328. 0x86, 0xee, 0xf8, 0xda, 0xc0, 0xae, 0x92, 0x6a, 0x03, 0xa9, 0x0a, 0xee,
  40329. 0x4a, 0x22, 0x5a, 0x6c, 0x39, 0xd3, 0x91, 0x7d, 0x91, 0x43, 0xac, 0x79,
  40330. 0xad, 0xab, 0xb7, 0x91, 0xb1, 0x20, 0x84, 0x7f, 0x0a, 0xd7, 0xa8, 0x62,
  40331. 0x95, 0xab, 0x04, 0xb6, 0xb2, 0xf1, 0xd4, 0xb0, 0xac, 0x52, 0x89, 0xb0,
  40332. 0x93, 0xdf, 0xdf, 0x80, 0x26, 0x0c, 0x32, 0x31, 0xb3, 0xba, 0xa1, 0xba,
  40333. 0x6f, 0xa3, 0x14, 0x5c, 0xfa, 0x37, 0x3b, 0x6a, 0xf2, 0xc4, 0x34, 0x27,
  40334. 0x08, 0x1a, 0xe4, 0xfc, 0x89, 0x58, 0x79, 0x34, 0x36, 0xe4, 0xad, 0x4b,
  40335. 0x3f, 0x57, 0x7b, 0xc1, 0x59, 0x2d, 0xb6, 0x54, 0x44, 0xbe, 0x4e, 0x5d,
  40336. 0x0d, 0x6a, 0xf3, 0xcd, 0xbf, 0xcd, 0x4d, 0x9f, 0x9a, 0x50, 0x09, 0xa4,
  40337. 0x6b, 0x8b, 0xb3, 0x01, 0x69, 0x6c, 0x69, 0x5d, 0x28, 0x73, 0x9e, 0xb5,
  40338. 0xc2, 0xc7, 0x6e, 0xff, 0x4c, 0x5c, 0x6b, 0x93, 0x22, 0xc1, 0x9f, 0xa6,
  40339. 0x71, 0xbf, 0x4d, 0x2d, 0x4e, 0x4e, 0x98, 0xa3, 0x6d, 0xab, 0x05, 0xa0,
  40340. 0xde, 0x34, 0x41, 0x28, 0xa4, 0x38, 0x75, 0x4e, 0xdf, 0x7f, 0xc9, 0xdd,
  40341. 0xbf, 0x5a, 0xd4, 0xcd, 0x38, 0x0c, 0x89, 0xe7, 0x0e, 0xfc, 0x0f, 0x27,
  40342. 0x39, 0x21, 0xa4, 0xa6, 0x07, 0x7b, 0x2a, 0x13, 0x56, 0xe7, 0x4e, 0x55,
  40343. 0x57, 0x71, 0x98, 0xb9, 0x3d, 0x59, 0xb5, 0xa8, 0x24, 0x18, 0x08, 0xa2,
  40344. 0x6e, 0x9a, 0xe5, 0x97, 0xa7, 0x38, 0xd9, 0x43, 0x9b, 0x19, 0x17, 0x34,
  40345. 0x03, 0xd6, 0xba, 0xe9, 0x71, 0x38, 0x26, 0x90, 0x78, 0x9e, 0x1c, 0x41,
  40346. 0x8d, 0x60, 0xdd, 0x0e, 0x12, 0x46, 0x37, 0xb4, 0x79, 0x87, 0x33, 0x12,
  40347. 0x24, 0xc4, 0x5a, 0x6c, 0x70, 0xa2, 0xb2, 0x58, 0xbb, 0xe7, 0xd6, 0x88,
  40348. 0x42, 0x2d, 0x49, 0xc8, 0x67, 0x1e, 0xc5, 0xed, 0x16, 0xa8, 0x1f, 0x36,
  40349. 0x2b, 0xfb, 0x0d, 0x51, 0x96, 0xc8, 0x78, 0xf2, 0xab, 0x82, 0xa1, 0xe2,
  40350. 0xaf, 0x8c, 0xa4, 0x13, 0x54, 0x90, 0xf1, 0xe7, 0xbb, 0xd1, 0x09, 0x23,
  40351. 0x76, 0x0e, 0x50, 0x32, 0xc5, 0x54, 0xbb, 0x1e, 0x12, 0x5d, 0x59, 0xf3,
  40352. 0xe9, 0xc9, 0xa4, 0xaa, 0xbc, 0x13, 0x1d, 0xf0, 0x79, 0x54, 0xae, 0x70,
  40353. 0xc0, 0xea, 0xcb, 0x21, 0x32, 0xe6, 0xe6, 0x8e, 0xaa, 0x51, 0x46, 0x25,
  40354. 0x1e, 0xf1, 0x3f, 0x9f, 0xf6, 0xff, 0x19, 0x53, 0x97, 0xbc, 0xa2, 0xb6,
  40355. 0x91, 0x59, 0x27, 0x1e, 0x39, 0x76, 0x76, 0x02, 0x0b, 0x03, 0x25, 0x6b,
  40356. 0x00, 0x02, 0xfa, 0x7d, 0x69, 0x5e, 0xde, 0x64, 0x33, 0xbf, 0xab, 0x3e,
  40357. 0x3f, 0x24, 0x32, 0x68, 0xbf, 0x90, 0x8f, 0x0f, 0xc5, 0x36, 0x58, 0x9e,
  40358. 0x9b, 0x11, 0xd1, 0x2a, 0x8a, 0x0d, 0xac, 0x3a, 0x23, 0xe2, 0x8e, 0xd6,
  40359. 0x0d, 0x4a, 0x8b, 0x45, 0x04, 0x47, 0xd9, 0x5a, 0x46, 0x6c, 0x70, 0x82,
  40360. 0xc7, 0x81, 0x67, 0xdc, 0xa6, 0xfa, 0x6a, 0x86, 0xfd, 0x01, 0xed, 0x90,
  40361. 0xf6, 0xe6, 0x26, 0x6d, 0xac, 0x52, 0x03, 0x4a, 0x91, 0x08, 0x7b, 0xa5,
  40362. 0x9c, 0xca, 0xd3, 0x2d, 0x79, 0xf1, 0xed, 0xcb, 0xaa, 0x8f, 0x77, 0xc8,
  40363. 0x17, 0xa8, 0xfb, 0x6c, 0x15, 0x62, 0xab, 0x34, 0xd1, 0xdd, 0x94, 0x3e,
  40364. 0xd4, 0x0c, 0x47, 0xed, 0x04, 0x91, 0xd2, 0xd7, 0x98, 0xb4, 0x43, 0x57,
  40365. 0xd1, 0x54, 0xef, 0x63, 0xba, 0xe3, 0x8a, 0x72, 0xc5, 0xb9, 0xf4, 0x30,
  40366. 0xfa, 0x16, 0x3c, 0xe1, 0xbb, 0xbe, 0x57, 0x90, 0xb9, 0xa1, 0xa0, 0x23,
  40367. 0xfa, 0xdd, 0xbe, 0x2f, 0xb3, 0xec, 0x41, 0x8b, 0x64, 0xeb, 0xc5, 0x41,
  40368. 0xea, 0xa8, 0x16, 0x76, 0x6f, 0x28, 0xda, 0x2b, 0x5f, 0x03, 0x0b, 0xe8,
  40369. 0x1c, 0x29, 0x71, 0xd8, 0x4e, 0x41, 0xdf, 0x39, 0x8e, 0x6a, 0x95, 0x79,
  40370. 0x85, 0x9c, 0xa9, 0x79, 0xd9, 0x8f, 0x33, 0xaf, 0x15, 0x3b, 0x5a, 0x82,
  40371. 0x56, 0x32, 0x98, 0x0c, 0xf6, 0xf6, 0x64, 0x42, 0xd4, 0x6a, 0x15, 0x0f,
  40372. 0xb9, 0x75, 0x22, 0xbd, 0x9a, 0x58, 0xa6, 0x01, 0x3a, 0x63, 0xf0, 0x80,
  40373. 0x78, 0x22, 0x80, 0xa0, 0x14, 0xe1, 0x37, 0x6b, 0xd4, 0x99, 0x3f, 0xc2,
  40374. 0xba, 0x2b, 0x8f, 0xf3, 0x56, 0xc8, 0x1b, 0xe4, 0x7a, 0x5e, 0x96, 0x60,
  40375. 0xee, 0x74, 0x54, 0xb6, 0x6d, 0x5c, 0x3d, 0x3e, 0x05, 0xf0, 0x9a, 0xf6,
  40376. 0xcd, 0xdd, 0x06, 0xdb, 0x8c, 0x21, 0xb9, 0xf5, 0x28, 0x57, 0x9c, 0x4f,
  40377. 0xb4, 0x08, 0xcf, 0xac, 0x6c, 0xfe, 0x30, 0xaf, 0xa2, 0xef, 0xcf, 0x93,
  40378. 0x15, 0xdd, 0x12, 0x16, 0x19, 0x7d, 0xbc, 0x57, 0xd9, 0xce, 0xbe, 0x0e,
  40379. 0xfc, 0xe1, 0xf0, 0x4a, 0x7c, 0xaa, 0xbf, 0x20, 0x64, 0x00, 0x34, 0x59,
  40380. 0xed, 0xea, 0x12, 0x58, 0x46, 0x4c, 0xc6, 0x2f, 0x77, 0x62, 0x1d, 0x82,
  40381. 0x5c, 0xe8, 0x98, 0x0d, 0xef, 0x5c, 0x0e, 0xec, 0x5d, 0x2e, 0x5f, 0xd2,
  40382. 0x22, 0x43, 0x2d, 0xe1, 0x02, 0xd5, 0x4a, 0x0a, 0x79, 0x6f, 0xa5, 0xec,
  40383. 0x48, 0xaa, 0xee, 0xf8, 0xe3, 0x5f, 0xdd, 0xe7, 0x26, 0x87, 0xb5, 0xc4,
  40384. 0xcf, 0xd9, 0x7f, 0xa8, 0xaa, 0xb6, 0xbe, 0xe9, 0x02, 0x49, 0x5d, 0x5f,
  40385. 0x81, 0x8b, 0xb9, 0xbd, 0xc0, 0xc9, 0xd5, 0xfe, 0x36, 0x3e, 0x49, 0x56,
  40386. 0x63, 0x8b, 0xce, 0xef, 0x48, 0x6e, 0xc0, 0xd4, 0x04, 0x0c, 0x33, 0x45,
  40387. 0x6e, 0x97, 0x9e, 0xa3, 0xae, 0xbc, 0xc2, 0xce, 0xdc, 0xe3, 0xff, 0x48,
  40388. 0x51, 0x68, 0x89, 0xad, 0xae, 0xc7, 0xd1, 0xde, 0xe2, 0xf9, 0xfe, 0x00,
  40389. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40390. 0x0c, 0x18, 0x20, 0x24, 0x2f, 0x33, 0x3f
  40391. };
  40392. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40393. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_sig[] = {
  40394. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  40395. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  40396. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  40397. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  40398. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  40399. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  40400. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  40401. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  40402. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  40403. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  40404. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  40405. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  40406. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  40407. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  40408. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  40409. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  40410. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  40411. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  40412. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  40413. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  40414. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  40415. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  40416. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  40417. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  40418. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  40419. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  40420. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  40421. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  40422. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  40423. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  40424. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  40425. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  40426. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  40427. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  40428. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  40429. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  40430. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  40431. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  40432. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  40433. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  40434. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  40435. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  40436. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  40437. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  40438. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  40439. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  40440. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  40441. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  40442. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  40443. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  40444. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  40445. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  40446. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  40447. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  40448. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  40449. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  40450. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  40451. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  40452. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  40453. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  40454. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  40455. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  40456. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  40457. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  40458. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  40459. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  40460. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  40461. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  40462. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  40463. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  40464. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  40465. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  40466. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  40467. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  40468. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  40469. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  40470. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  40471. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  40472. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  40473. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  40474. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  40475. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  40476. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  40477. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  40478. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  40479. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  40480. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  40481. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  40482. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  40483. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  40484. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  40485. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  40486. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  40487. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  40488. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  40489. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  40490. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  40491. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  40492. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  40493. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  40494. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  40495. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  40496. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  40497. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  40498. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  40499. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  40500. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  40501. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  40502. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  40503. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  40504. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  40505. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  40506. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  40507. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  40508. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  40509. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  40510. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  40511. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  40512. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  40513. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  40514. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  40515. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  40516. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  40517. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  40518. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  40519. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  40520. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  40521. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  40522. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  40523. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  40524. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  40525. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  40526. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  40527. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  40528. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  40529. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  40530. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  40531. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  40532. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  40533. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  40534. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  40535. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  40536. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  40537. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  40538. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  40539. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  40540. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  40541. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  40542. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  40543. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  40544. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  40545. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  40546. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  40547. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  40548. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  40549. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  40550. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  40551. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  40552. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  40553. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  40554. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  40555. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  40556. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  40557. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  40558. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  40559. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  40560. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  40561. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  40562. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  40563. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  40564. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  40565. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  40566. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  40567. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  40568. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  40569. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  40570. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  40571. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  40572. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  40573. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  40574. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  40575. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  40576. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  40577. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  40578. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  40579. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  40580. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  40581. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  40582. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  40583. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  40584. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  40585. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  40586. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  40587. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  40588. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  40589. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  40590. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  40591. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  40592. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  40593. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  40594. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  40595. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  40596. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  40597. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  40598. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  40599. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  40600. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  40601. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  40602. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  40603. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  40604. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  40605. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  40606. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  40607. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  40608. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  40609. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  40610. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  40611. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  40612. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  40613. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  40614. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  40615. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  40616. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  40617. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  40618. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  40619. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  40620. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  40621. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  40622. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  40623. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  40624. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  40625. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  40626. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  40627. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  40628. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  40629. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  40630. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  40631. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  40632. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  40633. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  40634. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  40635. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  40636. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  40637. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  40638. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  40639. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  40640. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  40641. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  40642. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  40643. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  40644. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  40645. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  40646. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  40647. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  40648. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  40649. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  40650. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  40651. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  40652. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  40653. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  40654. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  40655. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  40656. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  40657. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  40658. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  40659. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  40660. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  40661. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  40662. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  40663. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  40664. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  40665. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  40666. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  40667. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  40668. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  40669. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  40670. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  40671. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  40672. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  40673. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  40674. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  40675. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  40676. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  40677. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  40678. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  40679. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  40680. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  40681. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  40682. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  40683. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  40684. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  40685. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  40686. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  40687. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  40688. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  40689. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  40690. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  40691. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  40692. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  40693. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  40694. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  40695. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  40696. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  40697. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  40698. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  40699. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  40700. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  40701. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  40702. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  40703. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  40704. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  40705. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  40706. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  40707. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  40708. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  40709. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  40710. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  40711. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  40712. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  40713. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  40714. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  40715. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  40716. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  40717. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  40718. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  40719. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  40720. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  40721. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  40722. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  40723. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  40724. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  40725. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  40726. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  40727. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  40728. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  40729. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  40730. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  40731. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  40732. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  40733. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  40734. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  40735. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  40736. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  40737. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  40738. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  40739. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  40740. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  40741. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  40742. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  40743. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  40744. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  40745. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  40746. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  40747. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  40748. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  40749. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  40750. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  40751. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  40752. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  40753. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  40754. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  40755. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  40756. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  40757. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  40758. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  40759. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  40760. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  40761. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  40762. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  40763. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  40764. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  40765. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  40766. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  40767. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  40768. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  40769. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  40770. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  40771. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  40772. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  40773. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  40774. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  40775. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  40776. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  40777. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  40778. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  40779. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  40780. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  40781. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  40782. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  40783. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  40784. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  40785. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  40786. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  40787. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  40788. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  40789. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  40790. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  40791. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  40792. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  40793. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  40794. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  40795. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  40796. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  40797. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  40798. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  40799. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  40800. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  40801. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  40802. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  40803. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  40804. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  40805. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  40806. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  40807. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  40808. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  40809. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  40810. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  40811. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  40812. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  40813. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  40814. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  40815. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  40816. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  40817. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  40818. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  40819. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  40820. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  40821. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  40822. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  40823. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  40824. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  40825. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  40826. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  40827. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  40828. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  40829. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  40830. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  40831. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  40832. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  40833. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  40834. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  40835. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  40836. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  40837. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  40838. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  40839. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  40840. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  40841. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  40842. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  40843. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  40844. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  40845. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  40846. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  40847. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  40848. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  40849. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  40850. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  40851. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  40852. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  40853. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  40854. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  40855. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  40856. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f
  40857. };
  40858. #endif
  40859. wc_test_ret_t ret;
  40860. ret = dilithium_param_vfy_test(WC_ML_DSA_87, ml_dsa_87_pub_key,
  40861. (word32)sizeof(ml_dsa_87_pub_key), ml_dsa_87_sig,
  40862. (word32)sizeof(ml_dsa_87_sig));
  40863. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40864. if (ret == 0) {
  40865. ret = dilithium_param_vfy_test(WC_ML_DSA_87_DRAFT,
  40866. ml_dsa_87_draft_pub_key, (word32)sizeof(ml_dsa_87_draft_pub_key),
  40867. ml_dsa_87_draft_sig, (word32)sizeof(ml_dsa_87_draft_sig));
  40868. }
  40869. #endif
  40870. return ret;
  40871. }
  40872. #endif
  40873. #endif
  40874. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  40875. static wc_test_ret_t dilithium_param_test(int param, WC_RNG* rng)
  40876. {
  40877. wc_test_ret_t ret;
  40878. dilithium_key* key;
  40879. byte* sig = NULL;
  40880. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  40881. word32 sigLen;
  40882. byte msg[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  40883. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40884. int res = 0;
  40885. #endif
  40886. #endif
  40887. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  40888. DYNAMIC_TYPE_TMP_BUFFER);
  40889. if (key == NULL) {
  40890. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  40891. }
  40892. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT,
  40893. DYNAMIC_TYPE_TMP_BUFFER);
  40894. if (sig == NULL) {
  40895. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  40896. }
  40897. ret = wc_dilithium_init(key);
  40898. if (ret != 0) {
  40899. ret = WC_TEST_RET_ENC_EC(ret);
  40900. return ret;
  40901. }
  40902. ret = wc_dilithium_set_level(key, param);
  40903. if (ret != 0)
  40904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40905. ret = wc_dilithium_make_key(key, rng);
  40906. if (ret != 0)
  40907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40908. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  40909. sigLen = wc_dilithium_sig_size(key);
  40910. if (sigLen <= 0)
  40911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40912. ret = wc_dilithium_sign_msg(msg, (word32)sizeof(msg), sig, &sigLen, key,
  40913. rng);
  40914. if (ret != 0)
  40915. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40916. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40917. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg), &res,
  40918. key);
  40919. if (ret != 0)
  40920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40921. if (res != 1)
  40922. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  40923. #endif
  40924. #endif
  40925. out:
  40926. wc_dilithium_free(key);
  40927. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  40928. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  40929. return ret;
  40930. }
  40931. #endif
  40932. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
  40933. {
  40934. wc_test_ret_t ret;
  40935. WC_RNG rng;
  40936. #ifndef HAVE_FIPS
  40937. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  40938. #else
  40939. ret = wc_InitRng(&rng);
  40940. #endif
  40941. if (ret != 0) {
  40942. ret = WC_TEST_RET_ENC_EC(ret);
  40943. return ret;
  40944. }
  40945. #ifndef WOLFSSL_NO_ML_DSA_44
  40946. #ifdef WOLFSSL_WC_DILITHIUM
  40947. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40948. ret = dilithium_param_44_vfy_test();
  40949. if (ret != 0)
  40950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40951. #endif
  40952. #endif
  40953. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  40954. ret = dilithium_param_test(WC_ML_DSA_44, &rng);
  40955. if (ret != 0)
  40956. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40957. #endif
  40958. #endif
  40959. #ifndef WOLFSSL_NO_ML_DSA_65
  40960. #ifdef WOLFSSL_WC_DILITHIUM
  40961. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40962. ret = dilithium_param_65_vfy_test();
  40963. if (ret != 0)
  40964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40965. #endif
  40966. #endif
  40967. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  40968. ret = dilithium_param_test(WC_ML_DSA_65, &rng);
  40969. if (ret != 0)
  40970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40971. #endif
  40972. #endif
  40973. #ifndef WOLFSSL_NO_ML_DSA_87
  40974. #ifdef WOLFSSL_WC_DILITHIUM
  40975. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  40976. ret = dilithium_param_87_vfy_test();
  40977. if (ret != 0)
  40978. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40979. #endif
  40980. #endif
  40981. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  40982. ret = dilithium_param_test(WC_ML_DSA_87, &rng);
  40983. if (ret != 0)
  40984. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  40985. #endif
  40986. #endif
  40987. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  40988. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  40989. out:
  40990. #endif
  40991. wc_FreeRng(&rng);
  40992. return ret;
  40993. }
  40994. #endif /* HAVE_DILITHIUM */
  40995. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  40996. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  40997. void *context)
  40998. {
  40999. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41000. * BE USED FOR TESTING PURPOSES! Production applications should
  41001. * write only to non-volatile storage. */
  41002. XMEMCPY(context, priv, privSz);
  41003. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  41004. }
  41005. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  41006. void *context)
  41007. {
  41008. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41009. * BE USED FOR TESTING PURPOSES! */
  41010. XMEMCPY(priv, context, privSz);
  41011. return WC_XMSS_RC_READ_TO_MEMORY;
  41012. }
  41013. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
  41014. {
  41015. int i = 0;
  41016. int j = 0;
  41017. XmssKey signingKey;
  41018. XmssKey verifyKey;
  41019. WC_RNG rng;
  41020. word32 pkSz = 0;
  41021. word32 skSz = 0;
  41022. word32 sigSz = 0;
  41023. word32 bufSz = 0;
  41024. unsigned char * sk = NULL;
  41025. unsigned char * old_sk = NULL;
  41026. const char * msg = "XMSS post quantum signature test";
  41027. word32 msgSz = (word32) XSTRLEN(msg);
  41028. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41029. const char * param = "XMSS-SHA2_10_256";
  41030. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 20
  41031. const char * param = "XMSSMT-SHA2_20/4_256";
  41032. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 40
  41033. const char * param = "XMSSMT-SHA2_40/8_256";
  41034. #else
  41035. const char * param = "XMSSMT-SHA2_60/12_256";
  41036. #endif
  41037. byte * sig = NULL;
  41038. int ret2 = -1;
  41039. int ret = WC_TEST_RET_ENC_NC;
  41040. WOLFSSL_ENTER("xmss_test");
  41041. #ifndef HAVE_FIPS
  41042. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41043. #else
  41044. ret = wc_InitRng(&rng);
  41045. #endif
  41046. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41047. ret = wc_XmssKey_Init(&signingKey, NULL, INVALID_DEVID);
  41048. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41049. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41050. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41051. /* Set the parameter string to the signing key, and
  41052. * get sizes for secret key, pub key, and signature. */
  41053. ret = wc_XmssKey_SetParamStr(&signingKey, param);
  41054. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41055. ret = wc_XmssKey_GetPubLen(&signingKey, &pkSz);
  41056. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41057. if (pkSz != XMSS_SHA256_PUBLEN) {
  41058. return WC_TEST_RET_ENC_EC(pkSz);
  41059. }
  41060. ret = wc_XmssKey_GetPrivLen(&signingKey, &skSz);
  41061. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41062. ret = wc_XmssKey_GetSigLen(&signingKey, &sigSz);
  41063. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41064. /* Allocate signature array. */
  41065. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41066. if (sig == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41067. bufSz = sigSz;
  41068. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41069. fprintf(stderr, "param: %s\n", param);
  41070. fprintf(stderr, "pkSz: %d\n", pkSz);
  41071. fprintf(stderr, "skSz: %d\n", skSz);
  41072. fprintf(stderr, "sigSz: %d\n", sigSz);
  41073. #endif
  41074. /* Allocate current and old secret keys.*/
  41075. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41076. if (sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41077. old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41078. if (old_sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41079. XMEMSET(sk, 0, skSz);
  41080. XMEMSET(old_sk, 0, skSz);
  41081. XMEMSET(sig, 0, sigSz);
  41082. ret = wc_XmssKey_SetWriteCb(&signingKey, xmss_write_key_mem);
  41083. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41084. ret = wc_XmssKey_SetReadCb(&signingKey, xmss_read_key_mem);
  41085. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41086. ret = wc_XmssKey_SetContext(&signingKey, (void *) sk);
  41087. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41088. ret = wc_XmssKey_MakeKey(&signingKey, &rng);
  41089. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41090. /* Export the pub to a verify key. */
  41091. ret = wc_XmssKey_ExportPub(&verifyKey, &signingKey);
  41092. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41093. /* Repeat a few times to check that:
  41094. * 1. The secret key is mutated on each sign.
  41095. * 2. We can verify each new signature.
  41096. * Only do a few times, because the full signature space
  41097. * for this parameter set is huge. */
  41098. for (i = 0; i < 10; ++i) {
  41099. XMEMCPY(old_sk, sk, skSz);
  41100. ret = wc_XmssKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41101. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41102. if (sigSz != bufSz) { return WC_TEST_RET_ENC_I(i); }
  41103. /* Old secret key and current secret key should not match. */
  41104. ret = XMEMCMP(old_sk, sk, skSz);
  41105. if (ret == 0) { return WC_TEST_RET_ENC_I(i); }
  41106. ret = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41107. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41108. /* Flip bits in a few places throughout the signature, stepping in multiple
  41109. * of hash size. These should all fail with -1. */
  41110. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41111. sig[j] ^= 1;
  41112. ret2 = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41113. msgSz);
  41114. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41115. /* Verify passed when it should have failed. */
  41116. return WC_TEST_RET_ENC_I(j);
  41117. }
  41118. /* Flip this spot back. */
  41119. sig[j] ^= 1;
  41120. }
  41121. }
  41122. /* Cleanup everything. */
  41123. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41124. sig = NULL;
  41125. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41126. sk = NULL;
  41127. XFREE(old_sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41128. old_sk = NULL;
  41129. wc_XmssKey_Free(&signingKey);
  41130. wc_FreeRng(&rng);
  41131. return ret;
  41132. }
  41133. #endif /*if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)*/
  41134. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_SMALL_STACK) && \
  41135. WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41136. /* A simple xmss verify only test using:
  41137. * XMSS-SHA2_10_256
  41138. * pub len: 68
  41139. * msg len: 32
  41140. * sig len: 2500
  41141. *
  41142. * These were generated with the test xmss_fast, from the unpatched
  41143. * xmss-reference repository:
  41144. * https://github.com/XMSS/xmss-reference
  41145. * */
  41146. static const byte xmss_pub[XMSS_SHA256_PUBLEN] =
  41147. {
  41148. 0x00,0x00,0x00,0x01,0xA5,0x41,0x31,0x96,
  41149. 0x0A,0xF9,0xF3,0xB2,0x4B,0x2E,0x5B,0x3E,
  41150. 0xCA,0x74,0xAD,0x6C,0xA5,0x89,0xAD,0x2C,
  41151. 0x0E,0x96,0xB3,0x54,0xFB,0x5B,0x63,0x50,
  41152. 0x96,0x81,0xE2,0x59,0x72,0x10,0x09,0x54,
  41153. 0xBB,0x39,0xAC,0xEE,0x78,0xEF,0x95,0xEC,
  41154. 0x01,0x1D,0xF0,0x36,0x68,0xE2,0xC4,0xA5,
  41155. 0x2F,0x60,0x42,0x7E,0xD3,0x8E,0xAA,0x27,
  41156. 0xC9,0xB7,0x39,0x4E
  41157. };
  41158. static /* not const */ byte xmss_msg[32] =
  41159. {
  41160. 0x07,0x9F,0x80,0x86,0xDB,0x76,0x27,0xDF,
  41161. 0xED,0x5B,0x2A,0x81,0x60,0x60,0x7D,0xB4,
  41162. 0xE8,0x7A,0x69,0x45,0x20,0x6B,0xA2,0x96,
  41163. 0xC0,0x21,0xA5,0x46,0x29,0x63,0x9B,0x37
  41164. };
  41165. /* This was actually the 5th signature produced from
  41166. * xmss_fast test in xmss-reference. */
  41167. static /* not const */ byte xmss_sig[2500] =
  41168. {
  41169. 0x00,0x00,0x00,0x05,0xF0,0x15,0x34,0xBA,
  41170. 0x92,0x03,0x6A,0xB9,0xA5,0x23,0x86,0x11,
  41171. 0xAE,0x65,0x0A,0x5C,0x78,0x2C,0xC9,0xBE,
  41172. 0x7E,0xA6,0xDC,0xA2,0x8B,0xA9,0x9C,0x50,
  41173. 0xF6,0x61,0x8D,0x9D,0xD7,0xE9,0xC0,0xF8,
  41174. 0x67,0xCD,0x8A,0xC4,0x9B,0x74,0x96,0x07,
  41175. 0x5D,0xF2,0xC9,0xCC,0x28,0x05,0xB1,0xBE,
  41176. 0x5E,0xA4,0xBA,0xBE,0xAB,0xD8,0x21,0x6B,
  41177. 0x21,0x5F,0xAB,0xB7,0x6C,0xEC,0x2F,0xC8,
  41178. 0xC6,0x74,0x3E,0x97,0x1B,0xC3,0x45,0x57,
  41179. 0xAF,0xAA,0x1E,0xA8,0xF2,0x86,0xA8,0xAA,
  41180. 0x43,0x6D,0x66,0xE9,0x81,0x14,0xDE,0x09,
  41181. 0x39,0xD2,0xAF,0xD1,0x4C,0xE7,0x75,0x18,
  41182. 0x0D,0xAA,0x29,0xA1,0x92,0x53,0xCC,0xE9,
  41183. 0xF3,0x0B,0x1E,0x3B,0xE2,0xAE,0x80,0x0C,
  41184. 0xE7,0x7A,0x7C,0x13,0x8A,0x28,0xC6,0x5F,
  41185. 0x0A,0xA4,0xA3,0x73,0x0A,0x3A,0xC2,0xA6,
  41186. 0x3B,0xB4,0x30,0x67,0xC0,0x36,0x18,0xA1,
  41187. 0x58,0xCD,0xAD,0x54,0x36,0x64,0xCE,0xFD,
  41188. 0x52,0xFF,0x70,0x7E,0x09,0xFB,0x13,0xA2,
  41189. 0xEA,0xDF,0x67,0x8D,0x6C,0x42,0xB2,0x78,
  41190. 0xF5,0x7D,0x5C,0x4B,0xF7,0x8E,0xCF,0x3E,
  41191. 0xB7,0xC6,0xC1,0x23,0xFA,0x65,0xDE,0xD2,
  41192. 0xFA,0x40,0x51,0x97,0x0D,0x52,0x32,0x76,
  41193. 0x7E,0x82,0x8D,0xD0,0xB9,0x1E,0x62,0xD9,
  41194. 0x1E,0xC1,0xDB,0x40,0x43,0x37,0x4A,0x23,
  41195. 0x8A,0x1D,0x35,0xFA,0xF4,0x53,0x11,0x5A,
  41196. 0xB5,0x6D,0x1E,0x8B,0x22,0xC8,0x7D,0x2A,
  41197. 0xE4,0x94,0xAA,0x25,0x20,0x40,0x96,0xDB,
  41198. 0x82,0x62,0xBA,0x8F,0x8B,0x45,0xCB,0x4F,
  41199. 0x35,0x88,0x33,0xEB,0xEF,0xB3,0xBA,0xA7,
  41200. 0x09,0x72,0xB3,0x4C,0xEC,0xF2,0xC3,0xC7,
  41201. 0x5E,0x02,0x6C,0x41,0x93,0xCB,0x3C,0x89,
  41202. 0x12,0x09,0x68,0x54,0x8E,0xEC,0x6A,0x7E,
  41203. 0x20,0xE1,0x70,0x3D,0x8C,0xEB,0xB4,0x36,
  41204. 0xBE,0x91,0xBE,0x97,0xB5,0xA6,0x34,0x16,
  41205. 0x95,0x0F,0x10,0x26,0xA9,0x13,0x80,0x88,
  41206. 0x9C,0xAA,0x68,0xEC,0x34,0x70,0x4A,0x15,
  41207. 0x9B,0x5E,0x57,0x05,0x87,0x1C,0xF8,0x35,
  41208. 0x45,0x29,0xE9,0x6E,0xF2,0x70,0x13,0x42,
  41209. 0x89,0x4E,0x77,0xC0,0x18,0xC7,0x55,0x6D,
  41210. 0xE7,0xFA,0x0D,0x63,0x83,0x16,0x19,0x01,
  41211. 0x2D,0xFD,0x31,0x14,0x94,0xCA,0x3E,0x0E,
  41212. 0xD6,0x11,0x34,0x81,0x57,0x58,0xEC,0x24,
  41213. 0xA4,0x17,0x63,0xD3,0x25,0x00,0xBF,0x7D,
  41214. 0x78,0x5D,0xC5,0xD8,0xC6,0xC1,0xBD,0x8C,
  41215. 0xD0,0x94,0x0A,0xB1,0x33,0xA5,0x4B,0x31,
  41216. 0x25,0xF5,0xAF,0xE7,0x84,0x26,0xAA,0x05,
  41217. 0xBB,0xF3,0x9A,0xAF,0x58,0x36,0x40,0xEF,
  41218. 0x3D,0xA2,0xBD,0xCA,0xA1,0x8D,0x2F,0x6D,
  41219. 0x54,0xD2,0x62,0x33,0x09,0xAE,0xE6,0x73,
  41220. 0xD6,0x44,0xE8,0x7C,0x5C,0x39,0x2B,0x78,
  41221. 0x94,0x14,0xC7,0xC9,0xAF,0xEC,0x77,0x36,
  41222. 0xA1,0x61,0x61,0xF1,0xD0,0x09,0xA2,0xEE,
  41223. 0xE7,0x55,0xD7,0x35,0x89,0x89,0x9B,0xCF,
  41224. 0xFA,0xA6,0x09,0x1E,0x3B,0xBD,0x5D,0xD9,
  41225. 0x25,0xE7,0xED,0xDD,0x7C,0xF0,0x1C,0x57,
  41226. 0xE0,0x06,0xBB,0x08,0x39,0x59,0xDF,0xD7,
  41227. 0xAF,0x4B,0x88,0x0D,0x87,0x8F,0x4A,0xF3,
  41228. 0x1C,0xD4,0x4B,0xB3,0xE2,0xF3,0x1B,0x86,
  41229. 0x4F,0xCD,0x35,0x75,0xE2,0x03,0xF9,0x1D,
  41230. 0xBF,0x3E,0xD1,0x7B,0xC7,0x23,0x11,0x75,
  41231. 0x5F,0x92,0x0D,0x98,0xEE,0x14,0xE1,0xDA,
  41232. 0x7A,0x02,0x17,0x47,0x6B,0x41,0xEA,0x47,
  41233. 0xA1,0xAF,0x06,0x79,0x1A,0x52,0x6F,0x19,
  41234. 0x31,0x70,0x71,0xBD,0xC2,0x61,0x8D,0xB7,
  41235. 0xEE,0x6B,0x69,0x2A,0xE8,0x21,0x7A,0x95,
  41236. 0xBE,0x86,0x2A,0xA1,0xF4,0xE2,0x2F,0x17,
  41237. 0x02,0xFD,0xAD,0x17,0x9F,0x0A,0x0A,0x78,
  41238. 0xA9,0x92,0x30,0x21,0x72,0x2B,0x28,0xF8,
  41239. 0xF2,0x3E,0x05,0xD5,0xAC,0xC0,0x82,0xF8,
  41240. 0xD2,0xDA,0xD0,0xA3,0xBC,0x93,0xDB,0xA5,
  41241. 0x46,0xDE,0x14,0x1E,0xD4,0x3A,0x5D,0x79,
  41242. 0x3D,0x31,0x4B,0x06,0xCE,0x22,0x29,0x3C,
  41243. 0x98,0xB6,0x18,0x8A,0xAE,0xF7,0xBA,0x22,
  41244. 0x88,0xA1,0xEE,0xC0,0x14,0x4C,0x4A,0xA0,
  41245. 0x57,0x0A,0xD3,0x18,0xA2,0x3D,0xDD,0xC7,
  41246. 0x83,0x73,0xFC,0x38,0x9B,0x31,0xA3,0xE1,
  41247. 0x17,0x76,0xA1,0xA2,0x69,0xFC,0xAB,0x08,
  41248. 0x80,0x72,0x8D,0xF5,0xE4,0x14,0xB7,0x6B,
  41249. 0x03,0xFF,0xE8,0x11,0x4B,0x06,0x55,0x7E,
  41250. 0x36,0x21,0x2F,0xD7,0x54,0x82,0xC9,0x31,
  41251. 0xB4,0x85,0x68,0x41,0xEF,0x75,0xB0,0x3A,
  41252. 0xEA,0x4F,0xE0,0xEC,0x72,0xCC,0x33,0x96,
  41253. 0xCE,0x7D,0xAD,0xDD,0x0D,0x27,0x05,0x6E,
  41254. 0xA2,0xD4,0x11,0x07,0xD8,0x7D,0x27,0xD4,
  41255. 0x80,0x8F,0x00,0x22,0xE4,0xFC,0x2C,0x9D,
  41256. 0xD5,0xD8,0x18,0x7F,0x4E,0xF4,0xB9,0x7F,
  41257. 0xEF,0xD6,0x00,0x08,0x5C,0x05,0x04,0x1E,
  41258. 0x9A,0xC6,0x8D,0xCC,0x19,0xD9,0x0B,0x06,
  41259. 0xCC,0x6A,0x17,0xE2,0x03,0x23,0xDB,0x1C,
  41260. 0xBC,0xA2,0xB9,0xA2,0x95,0x3C,0x73,0xD8,
  41261. 0xFF,0xE6,0x0E,0xAE,0x04,0xB2,0xFC,0x91,
  41262. 0x4F,0xEF,0x8A,0x58,0xB7,0x31,0x68,0x4C,
  41263. 0x1E,0xD0,0x5B,0x85,0xCC,0x03,0xDC,0xF4,
  41264. 0xAC,0xDB,0x03,0x9B,0x35,0x33,0x08,0x71,
  41265. 0xD0,0x50,0x8D,0xDC,0xE3,0x3A,0x98,0x40,
  41266. 0x41,0x80,0xDD,0x35,0xE1,0xA2,0xAF,0x14,
  41267. 0x9A,0xDB,0xD3,0x68,0x14,0xE2,0x50,0x7A,
  41268. 0x76,0x3F,0xE4,0xA4,0x1B,0xAA,0xC1,0x06,
  41269. 0x87,0x9A,0x92,0xF9,0xBE,0x9E,0x86,0x8C,
  41270. 0x92,0x1D,0x74,0xB1,0x7F,0x27,0x43,0xC0,
  41271. 0xEE,0x2E,0xC2,0x6C,0x6D,0xAA,0x0C,0x0E,
  41272. 0x71,0xC9,0x56,0xD6,0x3A,0x56,0xCB,0x90,
  41273. 0xD1,0x7E,0x6E,0x1C,0x6A,0x00,0x2D,0x02,
  41274. 0x2C,0x96,0xF0,0x2A,0x37,0x37,0x18,0x07,
  41275. 0x0B,0xF4,0xB4,0x8C,0x30,0xF2,0xA4,0xAB,
  41276. 0x66,0xFB,0x8B,0x22,0xC0,0x00,0x7E,0x05,
  41277. 0xB6,0xF9,0x95,0x49,0x33,0xA1,0xDC,0x97,
  41278. 0x0C,0x5C,0x61,0x46,0xE2,0xD7,0x87,0x4B,
  41279. 0xC4,0xC7,0x5F,0x26,0x06,0x84,0xD7,0x47,
  41280. 0x05,0xF1,0x33,0xFF,0x85,0x85,0xB2,0xBD,
  41281. 0x1F,0x44,0xC6,0xC2,0x7D,0x51,0xBE,0x0E,
  41282. 0xB5,0xC4,0x44,0x2F,0xFE,0x73,0x5F,0xF4,
  41283. 0xA4,0xEF,0xE2,0xF1,0x73,0x0B,0xEF,0x3E,
  41284. 0x2B,0xD7,0xCC,0x9F,0xDA,0x1A,0x7E,0x92,
  41285. 0x39,0xA1,0x55,0xBF,0x60,0x0A,0xDB,0x23,
  41286. 0x74,0xFE,0xE7,0x05,0x63,0xA9,0x85,0x52,
  41287. 0x9F,0xCC,0xC3,0xFF,0xF6,0x6C,0x1B,0x4E,
  41288. 0x4F,0x01,0xBD,0xC3,0xEB,0x37,0xEC,0x29,
  41289. 0x21,0x3B,0x2C,0xC9,0x2E,0x93,0x20,0x3E,
  41290. 0x19,0xC0,0x8B,0xE8,0x33,0xCD,0xC6,0x6A,
  41291. 0x6E,0x72,0x13,0x15,0xA1,0x90,0x20,0x0C,
  41292. 0x14,0x66,0xED,0xCC,0xA4,0xDD,0x7F,0x58,
  41293. 0x53,0xBC,0x4A,0x68,0xFC,0x86,0x3E,0xAA,
  41294. 0xF1,0x17,0x0F,0x3E,0x20,0x54,0x93,0xF4,
  41295. 0x98,0xBF,0xB4,0x07,0x05,0xBD,0x70,0xE7,
  41296. 0xD7,0x34,0xFD,0xE3,0x69,0xDF,0xCD,0xF5,
  41297. 0x1A,0x73,0x6E,0xC9,0x2B,0x21,0xFB,0xB8,
  41298. 0x7E,0x44,0x10,0x83,0x56,0xCE,0xD5,0x15,
  41299. 0x9A,0x75,0xFC,0x91,0x8E,0x6B,0x9E,0x1A,
  41300. 0x3A,0x33,0x39,0x35,0xB4,0x0D,0x74,0xF4,
  41301. 0xFB,0x4C,0x0E,0x37,0xFE,0x82,0x95,0x46,
  41302. 0x6B,0xD2,0x6E,0xEE,0xCD,0x4D,0x38,0xAF,
  41303. 0x0A,0xAA,0xF1,0xD5,0xA4,0x7C,0x04,0xD8,
  41304. 0xB9,0xDB,0x11,0x68,0x88,0x35,0x41,0xDE,
  41305. 0x31,0x33,0x0C,0xDC,0x2D,0x4C,0xA8,0x20,
  41306. 0xCC,0x2C,0x4C,0x63,0xAB,0xBA,0xDF,0x48,
  41307. 0x84,0xD5,0x25,0xBC,0x70,0xE3,0x49,0xAA,
  41308. 0x43,0xCA,0x8B,0xE7,0x9F,0xDD,0x20,0x76,
  41309. 0x9B,0x38,0xF4,0xBA,0x4D,0x4E,0x34,0x4A,
  41310. 0xAF,0x81,0xE7,0x0B,0xEC,0xE9,0x59,0xC1,
  41311. 0x35,0x22,0x7F,0x69,0x46,0x62,0xD2,0x18,
  41312. 0x6E,0x1F,0x79,0xD1,0xAD,0xC3,0x84,0x95,
  41313. 0x96,0xB2,0x18,0x58,0x5E,0x7E,0x0C,0x25,
  41314. 0x0A,0x0F,0x69,0xA3,0x1D,0xEC,0x29,0xCB,
  41315. 0xDA,0xA2,0xD1,0x1A,0x10,0xA5,0x52,0xC3,
  41316. 0x62,0x1E,0xC5,0x83,0xFF,0xA3,0x56,0xC2,
  41317. 0xFD,0x87,0x3B,0x57,0x52,0x98,0x36,0x95,
  41318. 0x77,0x6B,0xE5,0x49,0x10,0x8E,0x39,0xDD,
  41319. 0xCA,0x4B,0xB3,0x9F,0x4C,0x0C,0x11,0x62,
  41320. 0xF3,0x22,0x78,0xDB,0x48,0xEB,0x68,0xFE,
  41321. 0xE4,0x2A,0xE9,0xAA,0x8F,0x7A,0x2F,0x69,
  41322. 0xA5,0xC5,0x03,0x2D,0xEF,0x62,0xA8,0x71,
  41323. 0x65,0x06,0x40,0x84,0x10,0x0F,0xF2,0xED,
  41324. 0xBC,0x70,0x71,0x69,0x24,0xA2,0xBF,0x83,
  41325. 0x39,0xDD,0xFA,0xA2,0x7B,0xE5,0xEC,0x3D,
  41326. 0xFE,0x3B,0x52,0x6E,0x3D,0x82,0xA6,0x2A,
  41327. 0x86,0x01,0x61,0x51,0x63,0xBF,0xF9,0x0A,
  41328. 0x06,0x72,0xF1,0xD5,0x39,0x0C,0xBA,0xC9,
  41329. 0x78,0xC6,0x77,0x22,0xE4,0x96,0x6E,0xB1,
  41330. 0x48,0x62,0x84,0x62,0x2D,0xEA,0x49,0x56,
  41331. 0x50,0x86,0x3F,0x90,0xC3,0x01,0x42,0x45,
  41332. 0xED,0xE6,0x9A,0x65,0x19,0x93,0x7F,0x48,
  41333. 0x16,0xF2,0x50,0xA7,0x70,0xB3,0xF5,0xDB,
  41334. 0x0E,0x5E,0x22,0x9E,0x64,0x04,0x26,0x69,
  41335. 0xC1,0x16,0xEE,0x65,0x08,0x82,0x27,0x65,
  41336. 0xEC,0x3D,0xDF,0x51,0x5E,0x2D,0xE8,0x76,
  41337. 0xF2,0xE3,0xE4,0x24,0x04,0x88,0x06,0x0F,
  41338. 0xB2,0x7B,0x9B,0x72,0x3D,0x4C,0x7D,0x6A,
  41339. 0x1F,0xB2,0xA2,0xD2,0x35,0xD6,0x40,0x25,
  41340. 0xC2,0x0B,0x25,0xF9,0xDF,0x26,0xE4,0xDC,
  41341. 0xFB,0xB1,0x84,0x84,0x77,0x1B,0x45,0x51,
  41342. 0x60,0xD5,0xF0,0xB6,0x09,0xE6,0xBC,0xE3,
  41343. 0x1C,0x70,0x96,0x2C,0xD3,0x9D,0x7D,0x7F,
  41344. 0xB1,0x70,0xDA,0x79,0xB8,0x74,0x99,0xBF,
  41345. 0x84,0x95,0xCC,0x93,0xD7,0x51,0xDD,0x66,
  41346. 0xD3,0x70,0x0C,0x75,0x86,0x09,0x06,0xFD,
  41347. 0x66,0x14,0x80,0xCD,0xF3,0x59,0xB4,0x92,
  41348. 0x5F,0xE4,0xEE,0x00,0xA8,0xB0,0x8B,0x5C,
  41349. 0x3E,0xDB,0x8A,0x9C,0x0B,0xB5,0x99,0xC2,
  41350. 0x0D,0x81,0x09,0x06,0x6C,0x28,0xC0,0x7E,
  41351. 0xA5,0x07,0x70,0x64,0xD7,0x41,0xF4,0xC3,
  41352. 0x66,0x61,0x1C,0xA8,0x51,0xF6,0x3C,0xBA,
  41353. 0xE0,0x94,0xA3,0x11,0x8C,0x2E,0xBA,0x13,
  41354. 0xB2,0x47,0x48,0x93,0xB4,0x1A,0x2C,0x9A,
  41355. 0x6E,0x8E,0x30,0x66,0x7B,0xD3,0xBB,0x3B,
  41356. 0x5D,0x97,0x0D,0xE4,0xEA,0x24,0x28,0x9E,
  41357. 0xB4,0x88,0xCE,0x1D,0x7D,0x6F,0x39,0xB3,
  41358. 0x87,0x21,0xE5,0x08,0x93,0xF0,0xD4,0x9D,
  41359. 0x2D,0x91,0xC9,0xFD,0x0C,0x74,0x34,0xB4,
  41360. 0x1F,0xFE,0xDA,0xDC,0x10,0x5B,0x8D,0x2B,
  41361. 0x87,0xD3,0x42,0xB4,0xAE,0x32,0x9C,0xAE,
  41362. 0x4C,0x99,0xD8,0xED,0x44,0x41,0x07,0xE0,
  41363. 0x8F,0xBD,0xA5,0x7C,0x5A,0xDF,0x91,0x29,
  41364. 0x00,0xB5,0x4B,0xC3,0x3A,0x40,0x6C,0x48,
  41365. 0xAB,0x2A,0xF3,0x02,0xCB,0xB3,0x69,0xDA,
  41366. 0x06,0x0C,0x4D,0x5C,0x45,0xC3,0x28,0xAC,
  41367. 0x7A,0x01,0xD4,0xF8,0xCB,0x07,0x63,0x89,
  41368. 0x09,0x34,0x78,0xA7,0x14,0x39,0xCF,0x2D,
  41369. 0x94,0x8D,0x7A,0x4E,0x4E,0xBD,0xC4,0x32,
  41370. 0xAB,0x21,0xC9,0xDA,0x3F,0x5F,0x04,0x6B,
  41371. 0x14,0x40,0x18,0x18,0x2F,0xF9,0x46,0x17,
  41372. 0x57,0x54,0x9B,0x28,0x7B,0xBD,0xF9,0xA2,
  41373. 0x13,0xAC,0x69,0x24,0xB1,0x31,0x39,0xBF,
  41374. 0x8D,0x75,0xC3,0xFD,0x03,0x54,0x5A,0xFD,
  41375. 0xD4,0x7A,0xB7,0x56,0x4F,0x66,0x43,0x57,
  41376. 0x1B,0xFB,0xF9,0x92,0x7A,0x83,0xE6,0xFF,
  41377. 0xB4,0xBA,0x83,0xD2,0x61,0x8E,0x4A,0x82,
  41378. 0x82,0xA8,0xF5,0x0C,0xD2,0x43,0x53,0xA8,
  41379. 0x85,0x0A,0xD4,0x69,0x7B,0x04,0x71,0x3B,
  41380. 0x80,0x49,0x27,0x47,0x12,0xB6,0xB0,0xEA,
  41381. 0x90,0x0A,0xFA,0xA8,0xC8,0x78,0x61,0xDE,
  41382. 0x30,0x12,0xBB,0xDC,0xA6,0x57,0x56,0x30,
  41383. 0x6E,0xF1,0xA8,0x3B,0xF6,0x09,0x07,0xEA,
  41384. 0x31,0xE2,0x08,0x23,0x31,0x0F,0xD4,0x34,
  41385. 0xE3,0x60,0xC2,0x2B,0xDB,0x5A,0x99,0xCF,
  41386. 0xD4,0x6B,0x4E,0x75,0x65,0x35,0xE8,0x8B,
  41387. 0x93,0x7D,0xCA,0x11,0x47,0xF0,0x3E,0x11,
  41388. 0x5C,0xD1,0xEE,0x4B,0x11,0xB4,0x65,0x2B,
  41389. 0x6B,0x79,0xC0,0x86,0x60,0xA4,0x4B,0x24,
  41390. 0xA0,0x5C,0x70,0x34,0xC3,0x7C,0xE7,0x4F,
  41391. 0x97,0x89,0x4D,0xFE,0x22,0x89,0x3A,0xE9,
  41392. 0x07,0xB9,0x1A,0x86,0xB8,0x7A,0x12,0x38,
  41393. 0xE1,0x24,0x46,0xBC,0x9B,0x21,0xCD,0xAC,
  41394. 0x30,0xAB,0x98,0x21,0x31,0xC5,0x17,0x3F,
  41395. 0x1E,0x56,0xC3,0x18,0xCE,0xF0,0xA1,0xCC,
  41396. 0xFF,0x9D,0xA8,0x53,0xAF,0x74,0x77,0x54,
  41397. 0x02,0x9A,0x8F,0xA4,0xD4,0xBD,0xB2,0x1A,
  41398. 0xBA,0x52,0x2E,0x19,0xBE,0x49,0x11,0x45,
  41399. 0x02,0x01,0x7A,0xBF,0x28,0xD6,0x18,0xED,
  41400. 0xBD,0xCE,0xE4,0xDE,0xB5,0xF1,0x53,0x5D,
  41401. 0x65,0xF9,0x5F,0x83,0x8F,0x2D,0xF2,0x82,
  41402. 0xA0,0x2D,0x28,0xD3,0x0A,0x9E,0x0F,0x7F,
  41403. 0xC7,0xC4,0x43,0x7F,0xC3,0x0E,0x06,0xEB,
  41404. 0x4E,0xB4,0x2D,0xFA,0xDD,0x48,0xAB,0xF4,
  41405. 0x7D,0x41,0x48,0x33,0x5A,0xE6,0x70,0x02,
  41406. 0xE7,0x71,0x8D,0xD9,0x6B,0x0C,0x5A,0x8F,
  41407. 0xA4,0xC1,0xB7,0x4E,0x96,0x83,0xD6,0xA7,
  41408. 0x1D,0xF1,0x88,0xB3,0x6E,0xF4,0x12,0xA9,
  41409. 0xF6,0x31,0x69,0x66,0xFE,0xFE,0x02,0xF2,
  41410. 0x86,0x6D,0xBB,0x57,0x51,0x8C,0x4C,0xE9,
  41411. 0x7C,0x92,0x3E,0x3A,0xD3,0x2D,0xA8,0x82,
  41412. 0x53,0x84,0x26,0x89,0xBB,0xCC,0x13,0x12,
  41413. 0x3D,0x94,0xBB,0xDF,0x3D,0x4C,0xDF,0x27,
  41414. 0x9B,0x1F,0xB8,0xB6,0xE4,0xEA,0xA2,0x07,
  41415. 0xF8,0x4D,0x42,0x8F,0x29,0x90,0xFE,0x21,
  41416. 0x20,0xE9,0x55,0x02,0xAD,0x90,0xA7,0x77,
  41417. 0x4E,0x29,0xB6,0xD9,0x14,0x94,0xB2,0x25,
  41418. 0xA4,0xB2,0x0E,0x96,0x31,0xAB,0x9E,0x93,
  41419. 0x49,0xAC,0xA9,0xCB,0x68,0x22,0xBA,0xB8,
  41420. 0x57,0x5C,0x9D,0x65,0xC1,0xF1,0xFC,0x99,
  41421. 0x7C,0x3C,0xE9,0xEA,0x4B,0x29,0x22,0x2F,
  41422. 0xDB,0x17,0x21,0x8D,0xB0,0x13,0xBF,0xEE,
  41423. 0x7D,0xE4,0x8B,0x6D,0x17,0xE0,0x53,0x92,
  41424. 0x0B,0x32,0x6B,0xB1,0x65,0x2E,0xA7,0x83,
  41425. 0xFD,0x62,0x62,0xE3,0xAA,0x81,0xE8,0xD6,
  41426. 0xF7,0xB1,0x30,0x65,0x80,0x9F,0x77,0x1E,
  41427. 0x4A,0xEA,0xE8,0x45,0x32,0x12,0x3A,0xFB,
  41428. 0x22,0xE9,0xA9,0xF6,0xCB,0xAB,0xA8,0x0C,
  41429. 0x20,0xA8,0x7C,0xF9,0xF7,0x53,0xC1,0xB4,
  41430. 0xC0,0x5D,0x06,0x45,0xDD,0x7E,0xA7,0x34,
  41431. 0xA1,0x21,0xC2,0x62,0xAB,0x22,0x45,0x3D,
  41432. 0x73,0x4C,0x26,0xD1,0x1A,0xB2,0xF0,0xB2,
  41433. 0x6D,0x11,0x70,0x58,0xAA,0xF5,0xA4,0xF5,
  41434. 0xF8,0x0B,0x3D,0xC1,0xF6,0x17,0x70,0x15,
  41435. 0xCD,0x72,0x02,0x7E,0x4E,0x94,0x96,0x0A,
  41436. 0x56,0xCC,0xA5,0xA3,0xB3,0x7E,0xDD,0x5A,
  41437. 0x72,0xD2,0xFB,0xAC,0x3D,0x0E,0x66,0x65,
  41438. 0xE9,0x08,0x6C,0xB0,0x1C,0xE2,0x1A,0x82,
  41439. 0xF6,0xF3,0x34,0x89,0x73,0x02,0x5B,0x42,
  41440. 0x6D,0x40,0x61,0xB6,0xE0,0xE6,0x53,0x32,
  41441. 0xA5,0x72,0x17,0x4F,0x3B,0x51,0x4F,0xBC,
  41442. 0x00,0xE0,0x69,0x26,0xA9,0xAE,0x83,0xE3,
  41443. 0x73,0x7F,0x71,0x97,0xE0,0xDC,0x7C,0x63,
  41444. 0x9C,0x85,0x5F,0xDF,0x7D,0xE4,0x6C,0xD8,
  41445. 0xA9,0x3A,0x6F,0x5E,0x4A,0x2E,0xB0,0xE7,
  41446. 0x8B,0x45,0xE2,0x90,0x05,0x37,0xE8,0xAB,
  41447. 0x49,0x48,0x4C,0xC0,0x59,0x1D,0x8C,0x46,
  41448. 0x5B,0x84,0xE0,0x83,0xCE,0xEA,0x4B,0xF9,
  41449. 0xD4,0xDC,0x63,0xDF,0x79,0xB7,0x5C,0x11,
  41450. 0x25,0x7F,0x90,0x2E,0x0A,0x38,0x03,0xEA,
  41451. 0xEA,0xA1,0x26,0x52,0x20,0x19,0xA3,0xBE,
  41452. 0xFC,0x9D,0xB7,0x6E,0xA6,0x58,0x8E,0x6D,
  41453. 0xC5,0x58,0xE9,0xED,0x2F,0x55,0x43,0x8B,
  41454. 0x03,0x8B,0xE6,0xA4,0xC2,0x25,0x4B,0x36,
  41455. 0xBA,0xD3,0x27,0x48,0x40,0x2E,0x87,0xA2,
  41456. 0xD4,0x12,0xC6,0x05,0x36,0x03,0x11,0x51,
  41457. 0xD1,0xF2,0xAC,0x71,0x2C,0xB6,0xC3,0xA5,
  41458. 0x57,0x0F,0xAF,0x4B,0xBD,0xCD,0x47,0x4C,
  41459. 0x3A,0x52,0x6F,0x47,0xE7,0x0B,0xB7,0xD5,
  41460. 0xF7,0xA6,0x39,0x63,0x82,0x08,0x4C,0x41,
  41461. 0x0E,0x2A,0x52,0x42,0x5A,0xEA,0x59,0xC7,
  41462. 0x94,0xFB,0xD0,0x88,0x47,0x27,0xF6,0x97,
  41463. 0x03,0x9E,0x29,0xB8,0x3A,0x67,0xE6,0xF3,
  41464. 0x95,0xA7,0x42,0xC1,0x96,0xD1,0x9A,0xA6,
  41465. 0xF0,0x09,0x0C,0xEA,0xE0,0xAB,0x0F,0x15,
  41466. 0xE9,0xC3,0xEB,0xA5,0x89,0x86,0x98,0x32,
  41467. 0x83,0xAB,0x30,0x33,0xAE,0x90,0x8D,0x2E,
  41468. 0xB3,0xAA,0x91,0xA6,0xD9,0xA4,0x4A,0x54,
  41469. 0xE0,0xD3,0x08,0xCC,0x79,0xCE,0xE4,0x15,
  41470. 0x31,0xA6,0xCE,0x61,0xCF,0x03,0x06,0xEE,
  41471. 0x8E,0xE2,0x64,0x29,0xD1,0x54,0x9B,0xD0,
  41472. 0x5F,0x09,0x2B,0x8B,0xD5,0xF8,0xD4,0x7D,
  41473. 0xF1,0x97,0x32,0xD9,0xEA,0x5A,0x0E,0x10,
  41474. 0x8C,0x4D,0xFB,0x55,0xE6,0x27,0x0C,0xBA,
  41475. 0xC1,0x73,0xC1,0x73,0xE3,0x1C,0x09,0xB3,
  41476. 0x6F,0xB4,0x12,0xFA,0xF3,0x29,0xDC,0x23,
  41477. 0x32,0xED,0x80,0x87,0x83,0xC2,0xF6,0x07,
  41478. 0xB5,0xA9,0x22,0xDE,0x66,0x1A,0xA7,0x4A,
  41479. 0x86,0xF1,0x39,0x9B,0xF4,0xE7,0x50,0x15,
  41480. 0x4A,0x55,0x3C,0x93,0xB9,0xF9,0xFD,0xDC,
  41481. 0xB3,0x5D,0x73,0x52
  41482. };
  41483. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void)
  41484. {
  41485. XmssKey verifyKey;
  41486. unsigned char pub_raw[XMSS_SHA256_PUBLEN];
  41487. word32 pub_len = sizeof(pub_raw);
  41488. word32 pkSz = 0;
  41489. word32 sigSz = 0;
  41490. const char * param = "XMSS-SHA2_10_256";
  41491. int j = 0;
  41492. int ret2 = WC_TEST_RET_ENC_NC;
  41493. int ret = WC_TEST_RET_ENC_NC;
  41494. int n_diff = 0;
  41495. WOLFSSL_ENTER("xmss_test_verify_only");
  41496. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  41497. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41498. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41499. ret = wc_XmssKey_SetParamStr(&verifyKey, param);
  41500. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41501. ret = wc_XmssKey_GetPubLen(&verifyKey, &pkSz);
  41502. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41503. if (pkSz != XMSS_SHA256_PUBLEN) {
  41504. return WC_TEST_RET_ENC_EC(pkSz);
  41505. }
  41506. ret = wc_XmssKey_GetSigLen(&verifyKey, &sigSz);
  41507. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41508. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41509. fprintf(stderr, "param: %s\n", param);
  41510. fprintf(stderr, "pkSz: %d\n", pkSz);
  41511. fprintf(stderr, "sigSz: %d\n", sigSz);
  41512. #endif
  41513. if (sigSz != sizeof(xmss_sig)) {
  41514. return WC_TEST_RET_ENC_EC(sigSz);
  41515. }
  41516. ret = wc_XmssKey_ImportPubRaw(&verifyKey, xmss_pub, XMSS_SHA256_PUBLEN);
  41517. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41518. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41519. (byte *) xmss_msg, sizeof(xmss_msg));
  41520. if (ret != 0) {
  41521. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  41522. return WC_TEST_RET_ENC_EC(ret);
  41523. }
  41524. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  41525. ret = wc_XmssKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  41526. if (ret != 0) {
  41527. printf("error: wc_XmssKey_ExportPubRaw returned %d, expected 0\n", ret);
  41528. return WC_TEST_RET_ENC_EC(ret);
  41529. }
  41530. if (pub_len != XMSS_SHA256_PUBLEN) {
  41531. printf("error: xmss pub len %u, expected %d\n", pub_len,
  41532. XMSS_SHA256_PUBLEN);
  41533. return WC_TEST_RET_ENC_EC(pub_len);
  41534. }
  41535. n_diff = XMEMCMP(pub_raw, xmss_pub, sizeof(xmss_pub));
  41536. if (n_diff != 0) {
  41537. printf("error: exported and imported pub raw do not match: %d\n",
  41538. n_diff);
  41539. return WC_TEST_RET_ENC_EC(n_diff);
  41540. }
  41541. /* Flip bits in message. This should fail. */
  41542. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  41543. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41544. (byte *) xmss_msg, sizeof(xmss_msg));
  41545. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41546. printf("error: wc_XmssKey_Verify returned %d, expected -1\n", ret2);
  41547. return WC_TEST_RET_ENC_EC(ret2);
  41548. }
  41549. /* Flip it back. This should pass again. */
  41550. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  41551. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41552. (byte *) xmss_msg, sizeof(xmss_msg));
  41553. if (ret != 0) {
  41554. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  41555. return WC_TEST_RET_ENC_EC(ret);
  41556. }
  41557. /* Flip bits in a few places throughout the signature, stepping in multiple
  41558. * of hash size. These should all fail with -1. */
  41559. for (j = 0; j < (int) sizeof(xmss_sig); j+= 4 * 32) {
  41560. xmss_sig[j] ^= 1;
  41561. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41562. (byte *) xmss_msg, sizeof(xmss_msg));
  41563. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41564. /* Verify passed when it should have failed. */
  41565. return WC_TEST_RET_ENC_I(j);
  41566. }
  41567. /* Flip this spot back. */
  41568. xmss_sig[j] ^= 1;
  41569. }
  41570. /* Cleanup everything. */
  41571. wc_XmssKey_Free(&verifyKey);
  41572. return ret;
  41573. }
  41574. #endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_SMALL_STACK &&
  41575. * WOLFSSL_XMSS_MIN_HEIGHT <= 10 */
  41576. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  41577. static int lms_write_key_mem(const byte * priv, word32 privSz, void *context)
  41578. {
  41579. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41580. * BE USED FOR TESTING PURPOSES! Production applications should
  41581. * write only to non-volatile storage. */
  41582. XMEMCPY(context, priv, privSz);
  41583. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  41584. }
  41585. static int lms_read_key_mem(byte * priv, word32 privSz, void *context)
  41586. {
  41587. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41588. * BE USED FOR TESTING PURPOSES! */
  41589. XMEMCPY(priv, context, privSz);
  41590. return WC_LMS_RC_READ_TO_MEMORY;
  41591. }
  41592. /* LMS signature sizes are a function of their parameters. This
  41593. * test has a signature of 8688 bytes. */
  41594. #define WC_TEST_LMS_SIG_LEN (8688)
  41595. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
  41596. {
  41597. int i = 0;
  41598. int j = 0;
  41599. int ret = WC_TEST_RET_ENC_NC;
  41600. int ret2 = WC_TEST_RET_ENC_NC;
  41601. int sigsLeft = 0;
  41602. LmsKey signingKey;
  41603. LmsKey verifyKey;
  41604. WC_RNG rng;
  41605. word32 sigSz = 0;
  41606. const char * msg = "LMS HSS post quantum signature test";
  41607. word32 msgSz = (word32) XSTRLEN(msg);
  41608. unsigned char priv[HSS_MAX_PRIVATE_KEY_LEN];
  41609. unsigned char old_priv[HSS_MAX_PRIVATE_KEY_LEN];
  41610. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  41611. byte * sig = XMALLOC(WC_TEST_LMS_SIG_LEN, HEAP_HINT,
  41612. DYNAMIC_TYPE_TMP_BUFFER);
  41613. if (sig == NULL) {
  41614. return WC_TEST_RET_ENC_ERRNO;
  41615. }
  41616. #else
  41617. byte sig[WC_TEST_LMS_SIG_LEN];
  41618. #endif
  41619. WOLFSSL_ENTER("lms_test");
  41620. XMEMSET(priv, 0, sizeof(priv));
  41621. XMEMSET(old_priv, 0, sizeof(old_priv));
  41622. XMEMSET(sig, 0, WC_TEST_LMS_SIG_LEN);
  41623. #ifndef HAVE_FIPS
  41624. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41625. #else
  41626. ret = wc_InitRng(&rng);
  41627. #endif
  41628. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41629. /* This test:
  41630. * levels: 1
  41631. * height: 5
  41632. * winternitz: 1
  41633. *
  41634. * max sigs: 2 ** (1 * 5) = 32
  41635. * signature length: 8688
  41636. */
  41637. ret = wc_LmsKey_Init(&signingKey, NULL, INVALID_DEVID);
  41638. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41639. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41640. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41641. ret = wc_LmsKey_SetParameters(&signingKey, 1, 5, 1);
  41642. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41643. ret = wc_LmsKey_SetWriteCb(&signingKey, lms_write_key_mem);
  41644. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41645. ret = wc_LmsKey_SetReadCb(&signingKey, lms_read_key_mem);
  41646. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41647. ret = wc_LmsKey_SetContext(&signingKey, (void *) priv);
  41648. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41649. ret = wc_LmsKey_MakeKey(&signingKey, &rng);
  41650. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41651. XMEMCPY(old_priv, priv, sizeof(priv));
  41652. ret = wc_LmsKey_ExportPub(&verifyKey, &signingKey);
  41653. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41654. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  41655. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41656. if (sigSz != WC_TEST_LMS_SIG_LEN) {
  41657. printf("error: got %u, expected %d\n", sigSz, WC_TEST_LMS_SIG_LEN);
  41658. return WC_TEST_RET_ENC_EC(sigSz);
  41659. }
  41660. /* 2 ** 5 should be the max number of signatures */
  41661. for (i = 0; i < 32; ++i) {
  41662. /* We should have remaining signstures. */
  41663. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  41664. if (sigsLeft == 0) {
  41665. return WC_TEST_RET_ENC_EC(sigsLeft);
  41666. }
  41667. /* Sign with key. The private key will be updated on every signature. */
  41668. ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41669. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41670. /* The updated private key should not match the old one. */
  41671. if (XMEMCMP(old_priv, priv, sizeof(priv)) == 0) {
  41672. printf("error: current priv key should not match old: %d\n", i);
  41673. return WC_TEST_RET_ENC_I(i);
  41674. }
  41675. XMEMCPY(old_priv, priv, sizeof(priv));
  41676. ret = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41677. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41678. /* Flip bits in a few places throughout the signature, stepping in multiple
  41679. * of hash size. These should all fail with -1. */
  41680. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41681. sig[j] ^= 1;
  41682. ret2 = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41683. msgSz);
  41684. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41685. /* Verify passed when it should have failed. */
  41686. return WC_TEST_RET_ENC_I(j);
  41687. }
  41688. /* Flip this spot back. */
  41689. sig[j] ^= 1;
  41690. }
  41691. }
  41692. /* This should be the last signature. */
  41693. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  41694. if (sigsLeft != 0) {
  41695. return WC_TEST_RET_ENC_EC(sigsLeft);
  41696. }
  41697. wc_LmsKey_Free(&signingKey);
  41698. wc_LmsKey_Free(&verifyKey);
  41699. wc_FreeRng(&rng);
  41700. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  41701. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41702. #endif
  41703. return ret;
  41704. }
  41705. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  41706. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK)
  41707. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10)) || \
  41708. defined(HAVE_LIBLMS)
  41709. /* A simple LMS verify only test.
  41710. *
  41711. * Note: LMS signature sizes are a function of their parameters. This
  41712. * test has a signature of 1456 bytes:
  41713. * levels: 1
  41714. * height: 10
  41715. * winternitz: 8
  41716. * max sigs: 2 ** (1 * 10) = 1024
  41717. * signature length: 1456
  41718. * */
  41719. /* "wolfSSL LMS example message!" without null terminator. */
  41720. static byte lms_msg[28] =
  41721. {
  41722. 0x77,0x6F,0x6C,0x66,0x53,0x53,0x4C,0x20,
  41723. 0x4C,0x4D,0x53,0x20,0x65,0x78,0x61,0x6D,
  41724. 0x70,0x6C,0x65,0x20,0x6D,0x65,0x73,0x73,
  41725. 0x61,0x67,0x65,0x21
  41726. };
  41727. static const byte lms_L1H10W8_pub[HSS_MAX_PUBLIC_KEY_LEN] =
  41728. {
  41729. 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,
  41730. 0x00,0x00,0x00,0x04,0xA1,0x26,0x76,0xF8,
  41731. 0xBB,0x0B,0xC0,0x82,0x21,0x71,0x0B,0x2E,
  41732. 0x8C,0xA6,0xEF,0x12,0xED,0x41,0x0E,0x8C,
  41733. 0xAF,0x11,0x93,0x34,0x7B,0x49,0x79,0xB7,
  41734. 0xDE,0x63,0x1C,0xFE,0x1F,0xD1,0x17,0x49,
  41735. 0xCD,0x5C,0xD4,0x26,0xA0,0x53,0x26,0x1A,
  41736. 0xC5,0xB4,0x8F,0x23
  41737. };
  41738. #define LMS_L1H10W8_SIGLEN (1456)
  41739. static byte lms_L1H10W8_sig[LMS_L1H10W8_SIGLEN] =
  41740. {
  41741. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  41742. 0x00,0x00,0x00,0x04,0x18,0x70,0x09,0x2E,
  41743. 0x21,0xC9,0x6A,0xC9,0x5C,0xB6,0xB0,0xAA,
  41744. 0xC3,0xED,0x6E,0x66,0x2F,0xCC,0x45,0x81,
  41745. 0xBC,0xBA,0x44,0x96,0x1C,0xBF,0x4E,0xFB,
  41746. 0x7A,0x46,0xFB,0xBE,0x9A,0x0C,0xE4,0x50,
  41747. 0x90,0xC7,0x92,0xAC,0x53,0xAE,0x53,0x76,
  41748. 0x29,0xA6,0x65,0xF1,0x09,0xED,0x1A,0x8E,
  41749. 0x03,0x2E,0x5A,0x06,0x51,0xE3,0x1E,0xE6,
  41750. 0xF6,0xFE,0x3A,0x6E,0xD1,0x92,0x31,0x1D,
  41751. 0xA1,0x6A,0x5C,0x30,0x3A,0xC7,0xFD,0x5B,
  41752. 0xFE,0x71,0x2C,0x5C,0x2F,0x5B,0x5B,0xCF,
  41753. 0xBC,0x7F,0xBF,0x6C,0xAF,0x44,0x8A,0xAE,
  41754. 0x14,0x60,0xAB,0x88,0xED,0x0E,0x4F,0xF8,
  41755. 0xC7,0x1B,0x74,0x28,0x72,0xB3,0x96,0xA6,
  41756. 0xE6,0x46,0x22,0x82,0xCF,0x1F,0x4D,0xA6,
  41757. 0xEA,0x22,0x06,0x07,0x52,0xF5,0x26,0x16,
  41758. 0x0B,0x90,0xE3,0xFF,0x64,0xA9,0xE4,0x61,
  41759. 0x1E,0x9C,0x12,0x9C,0xF6,0xD4,0x63,0x29,
  41760. 0xEA,0x02,0xF7,0x18,0x52,0x79,0x6C,0x43,
  41761. 0xDC,0xCF,0x43,0x23,0xB9,0xCC,0x4A,0x25,
  41762. 0x9D,0x10,0xAF,0xA3,0xE6,0x47,0x5A,0x1C,
  41763. 0xFE,0x68,0x89,0xAF,0x1B,0x2D,0x88,0x3E,
  41764. 0xCA,0xDC,0x70,0xEA,0xAC,0x11,0x00,0x8A,
  41765. 0x6E,0xE0,0xC7,0xD0,0xD2,0x1A,0x36,0x18,
  41766. 0x97,0xB3,0x5F,0x0E,0x75,0x48,0x28,0xF8,
  41767. 0xA8,0xF5,0x90,0xD1,0xA1,0x84,0xFB,0xA4,
  41768. 0xAD,0x50,0xBE,0xE9,0x39,0x8C,0xC5,0xA1,
  41769. 0x67,0x51,0xA1,0x8C,0xD6,0x6B,0x97,0x1F,
  41770. 0x47,0x99,0xEE,0xE0,0x70,0x01,0xC7,0x07,
  41771. 0x50,0xF3,0x5E,0x3F,0xE7,0x06,0xD6,0x8D,
  41772. 0x26,0xD6,0x5A,0x59,0x18,0x72,0x6B,0x12,
  41773. 0xD2,0xAF,0x9B,0xB4,0x2B,0xD0,0xB2,0xF2,
  41774. 0x96,0x2F,0x40,0xEA,0xBE,0xE6,0xAC,0x1F,
  41775. 0xB8,0x33,0xC2,0x76,0xDC,0x8C,0xAC,0xC1,
  41776. 0x46,0x5E,0x04,0x84,0x1B,0xC8,0xB9,0x65,
  41777. 0x8D,0xAD,0x96,0xB5,0xB1,0xF6,0x17,0x4A,
  41778. 0x19,0x87,0xE7,0xBF,0x29,0xC7,0x9B,0xB9,
  41779. 0xD6,0x11,0x2C,0x92,0x2F,0xB7,0x24,0xD5,
  41780. 0x01,0x1D,0x80,0x37,0x54,0xED,0x33,0x32,
  41781. 0xAB,0x7A,0x12,0xD4,0x02,0x1D,0x27,0x52,
  41782. 0x89,0xDB,0x32,0xBF,0x61,0xD4,0xBB,0xB4,
  41783. 0x46,0x78,0x1B,0x64,0x17,0x84,0x4B,0x8A,
  41784. 0xBA,0xC6,0xC1,0xCF,0xC7,0x5D,0x8F,0x93,
  41785. 0xC5,0x9A,0x27,0x90,0xAC,0x17,0x98,0xFF,
  41786. 0xC8,0x22,0x59,0x55,0x90,0xB2,0x29,0x39,
  41787. 0xA0,0xBE,0x00,0x23,0x55,0x6B,0xDA,0x83,
  41788. 0xD8,0x5B,0x57,0x7C,0x67,0x1B,0xC3,0x6B,
  41789. 0x6D,0xC7,0x9B,0x2B,0x9E,0xB7,0x95,0xB3,
  41790. 0xF0,0x1B,0x89,0x5A,0xD7,0x4B,0x67,0xAF,
  41791. 0xDC,0x9E,0xCF,0x7E,0x1A,0xBA,0x1B,0xB9,
  41792. 0x3B,0x7A,0xDD,0x3F,0x0D,0xEE,0x4C,0x0B,
  41793. 0xD1,0x4F,0x34,0xF2,0x93,0xF7,0x21,0x64,
  41794. 0x2C,0x07,0x00,0x15,0x4F,0xE3,0x6A,0x9F,
  41795. 0x08,0x52,0xC2,0x65,0x47,0x1F,0x34,0x64,
  41796. 0x66,0x07,0xBC,0xEA,0xAF,0x9B,0xAA,0x39,
  41797. 0x15,0x8B,0x08,0x8C,0x24,0x41,0x9B,0x46,
  41798. 0x1B,0x5B,0x91,0x11,0xC4,0xFD,0xA9,0x88,
  41799. 0x35,0x0E,0x7D,0xAF,0xFD,0xB7,0x90,0x7E,
  41800. 0xD7,0x29,0x02,0x0A,0xDC,0xC8,0x3F,0xC0,
  41801. 0xFD,0x97,0xAF,0x50,0x49,0xA6,0x5E,0x12,
  41802. 0xC1,0xCD,0xEC,0x52,0xC5,0x51,0xF2,0x80,
  41803. 0x17,0x61,0xC7,0x7E,0xBE,0xD1,0x1B,0x65,
  41804. 0xA4,0xAB,0x92,0x8D,0x89,0xB2,0xC5,0x8F,
  41805. 0xFF,0xA5,0x6F,0xFA,0x62,0x75,0xE4,0xA1,
  41806. 0xD4,0x22,0xA8,0x9E,0x40,0x04,0x27,0x1F,
  41807. 0xCC,0x81,0xBA,0x28,0x67,0xA0,0x1C,0x80,
  41808. 0xEB,0xCA,0xB0,0x61,0xA5,0x48,0xD0,0x8A,
  41809. 0x25,0xEB,0x9E,0x67,0x8C,0x8E,0x9B,0xD1,
  41810. 0xAD,0xBB,0xC3,0xEA,0xD3,0xD4,0xC5,0x12,
  41811. 0x7B,0xDD,0x00,0x57,0x7F,0xF6,0xF7,0xF6,
  41812. 0x3C,0x05,0xCF,0xFC,0x12,0xE1,0x93,0x05,
  41813. 0xE5,0x9B,0x79,0x87,0x69,0xD8,0x82,0xD9,
  41814. 0xD7,0x1D,0x41,0x73,0xE4,0x52,0x1D,0x3E,
  41815. 0xE5,0x8C,0x8D,0x34,0xE1,0x75,0xA9,0xF1,
  41816. 0x9D,0x09,0xA2,0x5B,0xEF,0xDA,0x96,0x6E,
  41817. 0x76,0x3D,0xEA,0x50,0xD9,0xCF,0x4F,0xAC,
  41818. 0xAD,0x1D,0x35,0x72,0x1B,0x88,0x8B,0xCD,
  41819. 0x8C,0x8A,0x8A,0xE0,0x96,0x04,0xD8,0xBB,
  41820. 0x28,0x43,0x16,0x77,0x60,0x98,0x63,0xF9,
  41821. 0xB9,0x71,0x46,0xB7,0xE1,0xA7,0xA9,0x84,
  41822. 0xC3,0x65,0x82,0xE1,0x1B,0x67,0x04,0x2D,
  41823. 0x55,0x6B,0xF9,0xC0,0x79,0x09,0x09,0xE7,
  41824. 0xFD,0x06,0x4D,0x09,0x9B,0x1A,0xCE,0x35,
  41825. 0xFA,0x27,0x6F,0x2F,0x01,0x65,0x0D,0xA0,
  41826. 0x97,0x59,0x11,0xF0,0x48,0xD2,0xE7,0x46,
  41827. 0xBE,0xB4,0x0A,0xA3,0xE2,0x75,0x0E,0x09,
  41828. 0x94,0xD9,0x69,0x28,0xD4,0xDA,0x64,0xBA,
  41829. 0xFE,0xA4,0xB9,0xF0,0xBA,0xEB,0xBA,0xAC,
  41830. 0xA8,0xF9,0xD3,0x82,0x4C,0x36,0x80,0xFA,
  41831. 0xE5,0xF6,0x76,0xC3,0x80,0xFA,0x90,0x29,
  41832. 0xF4,0x85,0xA4,0xC6,0x25,0x22,0x79,0x7E,
  41833. 0x39,0x1E,0x30,0xB8,0x65,0x72,0xCF,0xE1,
  41834. 0x99,0xF0,0x75,0xE8,0x09,0xB4,0x92,0x96,
  41835. 0x1B,0x68,0x50,0x88,0xF1,0x2C,0x97,0xE3,
  41836. 0x2D,0x26,0x8F,0xC5,0x30,0xCF,0x24,0xCB,
  41837. 0xB2,0x60,0x77,0xDC,0x02,0x72,0x0D,0xD9,
  41838. 0x2E,0xF2,0x52,0xEA,0x00,0xF6,0x32,0x65,
  41839. 0xA5,0xC6,0x43,0x29,0x29,0x69,0xAB,0x27,
  41840. 0x0C,0x39,0xDF,0x76,0x3E,0x93,0x95,0xB1,
  41841. 0x2C,0xA2,0x0D,0x18,0xCE,0xA0,0x97,0x10,
  41842. 0x3C,0x90,0xC0,0xEF,0x0E,0x04,0xA6,0xC8,
  41843. 0xA0,0x21,0x3C,0x0B,0x22,0x77,0x7A,0x66,
  41844. 0xA5,0x90,0x25,0xA4,0x09,0x3E,0xD5,0x27,
  41845. 0x1F,0x6C,0x99,0x85,0x5C,0xA2,0x99,0x7A,
  41846. 0x25,0xEE,0x8D,0x32,0x3D,0xD3,0xDC,0xF5,
  41847. 0x00,0x5A,0x34,0x61,0xB6,0xCD,0x4E,0xBC,
  41848. 0x26,0x36,0xFB,0x44,0x97,0x35,0xBD,0x06,
  41849. 0x7D,0x2E,0x4A,0xA2,0xDC,0x24,0xFE,0x70,
  41850. 0x0A,0xF9,0x57,0xE3,0xEE,0xAB,0xD1,0x17,
  41851. 0xF3,0x7C,0xD6,0x37,0x26,0xFA,0x83,0x9F,
  41852. 0xDD,0xB2,0xE1,0xD7,0xF9,0xC7,0x0E,0x15,
  41853. 0x01,0xA6,0x58,0x32,0x98,0x04,0x32,0xD4,
  41854. 0xDE,0xB9,0xEF,0x09,0xFA,0xE4,0x5A,0xD7,
  41855. 0xDD,0x09,0x1C,0xC9,0xAC,0xB8,0x6A,0xF5,
  41856. 0x00,0x5D,0x6B,0x95,0x12,0x8C,0x2F,0xCC,
  41857. 0xD8,0xB9,0x50,0x3A,0xEB,0x74,0x86,0xD2,
  41858. 0x3F,0xA1,0x05,0x8F,0x6E,0xEF,0xF5,0xA4,
  41859. 0xD6,0x6E,0x53,0xFA,0x9E,0xFA,0xCE,0xDB,
  41860. 0x99,0x46,0xE7,0xC5,0xDA,0x92,0x51,0x4F,
  41861. 0x22,0x07,0xF3,0xA5,0x38,0x26,0xD3,0xEC,
  41862. 0xD6,0x01,0xDD,0x31,0x3A,0x48,0x93,0xF6,
  41863. 0x69,0x4F,0xD8,0xF6,0xC2,0x91,0xA5,0x7C,
  41864. 0xDF,0x51,0x64,0xF1,0x3B,0x79,0xBC,0x0A,
  41865. 0x2C,0xDC,0x33,0x5A,0x29,0xF6,0xB2,0x09,
  41866. 0x66,0xCA,0x24,0x9F,0x1A,0x18,0xF3,0x76,
  41867. 0x4C,0x5E,0x0B,0x81,0x7F,0x29,0x84,0xD8,
  41868. 0x7A,0xA8,0xD6,0x11,0xAC,0xEC,0xD9,0x07,
  41869. 0x91,0xEC,0xB6,0x6D,0xEC,0xDB,0xBE,0x6F,
  41870. 0x9F,0xC5,0x19,0x5E,0x56,0x87,0x20,0x80,
  41871. 0x75,0xD5,0x64,0xE9,0x80,0xBF,0x2D,0xD5,
  41872. 0x94,0x9F,0x8C,0xA4,0x54,0x41,0xAB,0xB1,
  41873. 0x8E,0xAD,0x51,0xE4,0x3C,0x24,0xF7,0x1D,
  41874. 0xFE,0x02,0x48,0x7C,0x6D,0xED,0xF1,0xAC,
  41875. 0xD9,0x79,0x42,0xE5,0x3A,0xCF,0x6A,0x4C,
  41876. 0x6D,0xE2,0x13,0xD2,0x2B,0x9D,0xAB,0x1F,
  41877. 0x70,0xD3,0xC0,0x6F,0x81,0xE9,0x9A,0x86,
  41878. 0x33,0x39,0x60,0xE7,0x6A,0x00,0x1F,0x97,
  41879. 0xEB,0xE5,0x1D,0x0D,0x66,0x15,0xC9,0xA2,
  41880. 0xB1,0xC0,0xF0,0x2E,0xF4,0x07,0xA2,0x2E,
  41881. 0x49,0x92,0x95,0x13,0xA3,0x18,0x46,0x25,
  41882. 0xB9,0x3C,0xA1,0x4B,0x00,0x00,0x00,0x06,
  41883. 0xAB,0xAA,0xF9,0x3F,0x7E,0x21,0xF4,0x0E,
  41884. 0xCE,0xFD,0xE0,0x44,0xAC,0xC7,0x1A,0x30,
  41885. 0x22,0x9D,0x0A,0xD7,0x96,0x2D,0x8F,0x9A,
  41886. 0x99,0x1F,0x40,0x75,0x7F,0x62,0xF9,0xC1,
  41887. 0x81,0x7B,0x4A,0x1B,0xFA,0xD6,0x87,0xB9,
  41888. 0xEF,0x58,0x48,0xE4,0x5C,0x79,0xE5,0xB1,
  41889. 0x2C,0x59,0xA4,0x42,0xDB,0xA6,0x53,0x70,
  41890. 0x80,0x61,0x17,0xD4,0xD3,0x77,0xBD,0x53,
  41891. 0x26,0x7C,0x0E,0x0E,0xFF,0x30,0x4B,0xD0,
  41892. 0x86,0xFC,0x02,0x20,0x24,0x46,0x5B,0xF5,
  41893. 0xE3,0x99,0x73,0x85,0x60,0x00,0x36,0x47,
  41894. 0x17,0xEE,0x0C,0xD2,0x80,0x71,0x46,0x0E,
  41895. 0x2B,0xB0,0xEF,0x7F,0xFE,0x3B,0xE5,0xE1,
  41896. 0x87,0xC2,0xAF,0x1A,0x6F,0x63,0xF4,0x5A,
  41897. 0xC4,0x16,0xF7,0xAD,0x07,0x70,0x71,0x85,
  41898. 0x7D,0x3D,0x67,0x08,0xB8,0xD8,0xE2,0xF0,
  41899. 0xA1,0xAC,0xD2,0x94,0x7D,0x93,0x03,0xDD,
  41900. 0x54,0xF9,0x64,0x19,0xB3,0xED,0x24,0x22,
  41901. 0x01,0xD7,0x12,0x5E,0xC1,0x2B,0x39,0x10,
  41902. 0x13,0xE2,0x56,0x1C,0xEE,0xF4,0x2A,0x49,
  41903. 0x7B,0xFB,0x36,0x8D,0xF8,0xAF,0x60,0xDF,
  41904. 0x10,0xF0,0x72,0xA2,0xED,0xB6,0x53,0x88,
  41905. 0xA9,0x0C,0xED,0x9C,0x18,0x33,0x7D,0x65,
  41906. 0x9B,0xB2,0x9C,0x3E,0xE9,0x1E,0x43,0x51,
  41907. 0x7E,0xBE,0x01,0x95,0xF6,0x60,0x65,0xBE,
  41908. 0xD1,0xF4,0xE2,0x83,0x6B,0xCA,0x7A,0x70,
  41909. 0x41,0x83,0x72,0xC0,0x23,0x51,0x13,0x11,
  41910. 0x2D,0xF9,0xC0,0x0D,0x7D,0x73,0x76,0xA5,
  41911. 0x30,0x83,0x68,0x10,0x35,0xA2,0x18,0x22,
  41912. 0x4E,0x21,0x93,0x27,0x6A,0x19,0x28,0x83,
  41913. 0x7F,0xDD,0xDD,0xFF,0xC3,0x8A,0x64,0x00,
  41914. 0x5F,0x1C,0x0D,0xF8,0xBB,0xD7,0x15,0xB9,
  41915. 0xEF,0xE0,0x07,0x62,0x05,0x9E,0xCF,0xFC,
  41916. 0x08,0x52,0x1E,0x65,0x41,0x56,0x6A,0xEB,
  41917. 0x81,0x53,0x30,0x7B,0xF2,0xFD,0x65,0xFF,
  41918. 0xA2,0x14,0xF5,0x62,0x1E,0x24,0x48,0x47,
  41919. 0xA5,0x41,0x80,0xB4,0xC5,0xDC,0xB2,0xB4,
  41920. 0x2D,0x17,0xE7,0xBE,0x49,0x53,0x7A,0x25,
  41921. 0xC5,0x0D,0x19,0x59,0xF4,0x88,0x59,0xED,
  41922. 0x92,0x13,0xEE,0x7A,0x4F,0x12,0x98,0x4C
  41923. };
  41924. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
  41925. {
  41926. LmsKey verifyKey;
  41927. unsigned char pub_raw[HSS_MAX_PUBLIC_KEY_LEN];
  41928. word32 pub_len = sizeof(pub_raw);
  41929. word32 sigSz = 0;
  41930. word32 msgSz = sizeof(lms_msg);
  41931. word32 pubSz = 0;
  41932. int levels = 0;
  41933. int height = 0;
  41934. int winternitz = 0;
  41935. int ret = WC_TEST_RET_ENC_NC;
  41936. int ret2 = WC_TEST_RET_ENC_NC;
  41937. int j = 0;
  41938. int n_diff = 0;
  41939. WOLFSSL_ENTER("lms_test_verify_only");
  41940. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  41941. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41942. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41943. ret = wc_LmsKey_SetParameters(&verifyKey, 1, 10, 8);
  41944. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41945. ret = wc_LmsKey_ImportPubRaw(&verifyKey, lms_L1H10W8_pub,
  41946. HSS_MAX_PUBLIC_KEY_LEN);
  41947. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41948. /* Verify parameters, pub length, and sig length are correct. */
  41949. ret = wc_LmsKey_GetParameters(&verifyKey, &levels, &height, &winternitz);
  41950. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41951. if (levels != 1 || height != 10 || winternitz != 8) {
  41952. printf("error: invalid LMS parameters: L%d-H%d-W%d\n", levels, height,
  41953. winternitz);
  41954. return WC_TEST_RET_ENC_NC;
  41955. }
  41956. ret = wc_LmsKey_GetPubLen(&verifyKey, &pubSz);
  41957. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41958. if (pubSz != HSS_MAX_PUBLIC_KEY_LEN) {
  41959. printf("error: got %u, expected %d\n", pubSz, HSS_MAX_PUBLIC_KEY_LEN);
  41960. return WC_TEST_RET_ENC_EC(pubSz);
  41961. }
  41962. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  41963. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41964. if (sigSz != LMS_L1H10W8_SIGLEN) {
  41965. printf("error: got %u, expected %d\n", sigSz, LMS_L1H10W8_SIGLEN);
  41966. return WC_TEST_RET_ENC_EC(sigSz);
  41967. }
  41968. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  41969. (byte *) lms_msg, msgSz);
  41970. if (ret != 0) {
  41971. printf("error: wc_LmsKey_Verify returned %d\n", ret);
  41972. return WC_TEST_RET_ENC_EC(ret);
  41973. }
  41974. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  41975. ret = wc_LmsKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  41976. if (ret != 0) {
  41977. printf("error: wc_LmsKey_ExportPubRaw returned %d, expected 0\n", ret);
  41978. return WC_TEST_RET_ENC_EC(ret);
  41979. }
  41980. if (pub_len != HSS_MAX_PUBLIC_KEY_LEN) {
  41981. printf("error: LMS pub len %u, expected %d\n", pub_len,
  41982. HSS_MAX_PUBLIC_KEY_LEN);
  41983. return WC_TEST_RET_ENC_EC(pub_len);
  41984. }
  41985. n_diff = XMEMCMP(pub_raw, lms_L1H10W8_pub, sizeof(lms_L1H10W8_pub));
  41986. if (n_diff != 0) {
  41987. printf("error: exported and imported pub raw do not match: %d\n",
  41988. n_diff);
  41989. return WC_TEST_RET_ENC_EC(n_diff);
  41990. }
  41991. /* Flip bits in message. This should fail. */
  41992. lms_msg[msgSz / 2] ^= 1;
  41993. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  41994. (byte *) lms_msg, msgSz);
  41995. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41996. printf("error: wc_LmsKey_Verify returned %d, expected -1\n", ret2);
  41997. return WC_TEST_RET_ENC_EC(ret);
  41998. }
  41999. /* Flip it back. This should pass again. */
  42000. lms_msg[msgSz / 2] ^= 1;
  42001. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42002. (byte *) lms_msg, msgSz);
  42003. if (ret != 0) {
  42004. printf("error: wc_LmsKey_Verify returned %d, expected 0\n", ret);
  42005. return WC_TEST_RET_ENC_EC(ret);
  42006. }
  42007. /* Flip bits in a few places throughout the signature, stepping in multiple
  42008. * of hash size. These should all fail with -1. */
  42009. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42010. lms_L1H10W8_sig[j] ^= 1;
  42011. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig,
  42012. LMS_L1H10W8_SIGLEN,
  42013. (byte *) lms_msg, msgSz);
  42014. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42015. /* Verify passed when it should have failed. */
  42016. return WC_TEST_RET_ENC_I(j);
  42017. }
  42018. /* Flip this spot back. */
  42019. lms_L1H10W8_sig[j] ^= 1;
  42020. }
  42021. wc_LmsKey_Free(&verifyKey);
  42022. return ret;
  42023. }
  42024. #endif
  42025. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK) */
  42026. static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point --
  42027. * see print_fiducials() below.
  42028. */
  42029. #ifdef WOLFCRYPT_HAVE_ECCSI
  42030. static wc_test_ret_t eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk,
  42031. ecc_point* pvt)
  42032. {
  42033. wc_test_ret_t ret;
  42034. byte id[1] = { 0x00 };
  42035. int valid;
  42036. word32 sz;
  42037. byte data[256];
  42038. byte hash[WC_MAX_DIGEST_SIZE];
  42039. byte hashSz;
  42040. byte sig[257];
  42041. word32 sigSz;
  42042. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42043. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42044. return WC_TEST_RET_ENC_EC(ret);
  42045. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42046. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42047. return WC_TEST_RET_ENC_EC(ret);
  42048. ret = wc_InitEccsiKey(NULL, NULL, INVALID_DEVID);
  42049. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42050. return WC_TEST_RET_ENC_EC(ret);
  42051. ret = wc_InitEccsiKey(NULL, HEAP_HINT, INVALID_DEVID);
  42052. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42053. return WC_TEST_RET_ENC_EC(ret);
  42054. wc_FreeEccsiKey(NULL);
  42055. /* Create a valid key. */
  42056. ret = wc_InitEccsiKey(key, NULL, INVALID_DEVID);
  42057. if (ret != 0)
  42058. return WC_TEST_RET_ENC_EC(ret);
  42059. ret = wc_MakeEccsiKey(NULL, NULL);
  42060. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42061. return WC_TEST_RET_ENC_EC(ret);
  42062. ret = wc_MakeEccsiKey(key, NULL);
  42063. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42064. return WC_TEST_RET_ENC_EC(ret);
  42065. ret = wc_MakeEccsiKey(NULL, rng);
  42066. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42067. return WC_TEST_RET_ENC_EC(ret);
  42068. ret = wc_MakeEccsiPair(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL,
  42069. NULL);
  42070. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42071. return WC_TEST_RET_ENC_EC(ret);
  42072. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL);
  42073. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42074. return WC_TEST_RET_ENC_EC(ret);
  42075. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt);
  42076. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42077. return WC_TEST_RET_ENC_EC(ret);
  42078. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt);
  42079. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42080. return WC_TEST_RET_ENC_EC(ret);
  42081. ret = wc_MakeEccsiPair(key, NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42082. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42083. return WC_TEST_RET_ENC_EC(ret);
  42084. ret = wc_MakeEccsiPair(NULL, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42085. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42086. return WC_TEST_RET_ENC_EC(ret);
  42087. /* No key set */
  42088. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42089. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42090. return WC_TEST_RET_ENC_EC(ret);
  42091. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL,
  42092. NULL);
  42093. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42094. return WC_TEST_RET_ENC_EC(ret);
  42095. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42096. NULL);
  42097. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42098. return WC_TEST_RET_ENC_EC(ret);
  42099. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL,
  42100. &valid);
  42101. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42102. return WC_TEST_RET_ENC_EC(ret);
  42103. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt,
  42104. &valid);
  42105. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42106. return WC_TEST_RET_ENC_EC(ret);
  42107. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt,
  42108. &valid);
  42109. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42110. return WC_TEST_RET_ENC_EC(ret);
  42111. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42112. &valid);
  42113. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42114. return WC_TEST_RET_ENC_EC(ret);
  42115. /* No key set */
  42116. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42117. &valid);
  42118. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42119. return WC_TEST_RET_ENC_EC(ret);
  42120. ret = wc_ValidateEccsiPvt(NULL, NULL, NULL);
  42121. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42122. return WC_TEST_RET_ENC_EC(ret);
  42123. ret = wc_ValidateEccsiPvt(key, NULL, NULL);
  42124. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42125. return WC_TEST_RET_ENC_EC(ret);
  42126. ret = wc_ValidateEccsiPvt(NULL, pvt, NULL);
  42127. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42128. return WC_TEST_RET_ENC_EC(ret);
  42129. ret = wc_ValidateEccsiPvt(NULL, NULL, &valid);
  42130. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42131. return WC_TEST_RET_ENC_EC(ret);
  42132. ret = wc_ValidateEccsiPvt(key, pvt, NULL);
  42133. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42134. return WC_TEST_RET_ENC_EC(ret);
  42135. ret = wc_ValidateEccsiPvt(key, NULL, &valid);
  42136. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42137. return WC_TEST_RET_ENC_EC(ret);
  42138. ret = wc_ValidateEccsiPvt(NULL, pvt, &valid);
  42139. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42140. return WC_TEST_RET_ENC_EC(ret);
  42141. ret = wc_EncodeEccsiPair(NULL, NULL, NULL, data, NULL);
  42142. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42143. return WC_TEST_RET_ENC_EC(ret);
  42144. ret = wc_EncodeEccsiPair(key, ssk, pvt, data, NULL);
  42145. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42146. return WC_TEST_RET_ENC_EC(ret);
  42147. ret = wc_EncodeEccsiPair(key, ssk, NULL, data, &sz);
  42148. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42149. return WC_TEST_RET_ENC_EC(ret);
  42150. ret = wc_EncodeEccsiPair(key, NULL, pvt, data, &sz);
  42151. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42152. return WC_TEST_RET_ENC_EC(ret);
  42153. ret = wc_EncodeEccsiPair(NULL, ssk, pvt, data, &sz);
  42154. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42155. return WC_TEST_RET_ENC_EC(ret);
  42156. /* No key created so no curve information. */
  42157. ret = wc_EncodeEccsiPair(key, ssk, pvt, NULL, &sz);
  42158. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42159. return WC_TEST_RET_ENC_EC(ret);
  42160. ret = wc_EncodeEccsiSsk(NULL, NULL, data, NULL);
  42161. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42162. return WC_TEST_RET_ENC_EC(ret);
  42163. ret = wc_EncodeEccsiSsk(key, ssk, data, NULL);
  42164. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42165. return WC_TEST_RET_ENC_EC(ret);
  42166. ret = wc_EncodeEccsiSsk(key, NULL, data, &sz);
  42167. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42168. return WC_TEST_RET_ENC_EC(ret);
  42169. ret = wc_EncodeEccsiSsk(NULL, ssk, data, &sz);
  42170. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42171. return WC_TEST_RET_ENC_EC(ret);
  42172. ret = wc_EncodeEccsiPvt(NULL, NULL, data, NULL, 1);
  42173. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42174. return WC_TEST_RET_ENC_EC(ret);
  42175. ret = wc_EncodeEccsiPvt(key, pvt, data, NULL, 1);
  42176. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42177. return WC_TEST_RET_ENC_EC(ret);
  42178. ret = wc_EncodeEccsiPvt(key, NULL, data, &sz, 1);
  42179. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42180. return WC_TEST_RET_ENC_EC(ret);
  42181. ret = wc_EncodeEccsiPvt(NULL, pvt, data, &sz, 1);
  42182. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42183. return WC_TEST_RET_ENC_EC(ret);
  42184. ret = wc_DecodeEccsiPair(NULL, NULL, 0, NULL, NULL);
  42185. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42186. return WC_TEST_RET_ENC_EC(ret);
  42187. ret = wc_DecodeEccsiPair(key, data, 0, ssk, NULL);
  42188. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42189. return WC_TEST_RET_ENC_EC(ret);
  42190. ret = wc_DecodeEccsiPair(key, data, 0, NULL, pvt);
  42191. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42192. return WC_TEST_RET_ENC_EC(ret);
  42193. ret = wc_DecodeEccsiPair(key, NULL, 0, ssk, pvt);
  42194. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42195. return WC_TEST_RET_ENC_EC(ret);
  42196. ret = wc_DecodeEccsiPair(NULL, data, 0, ssk, pvt);
  42197. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42198. return WC_TEST_RET_ENC_EC(ret);
  42199. ret = wc_DecodeEccsiSsk(NULL, NULL, 0, NULL);
  42200. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42201. return WC_TEST_RET_ENC_EC(ret);
  42202. ret = wc_DecodeEccsiSsk(key, data, 0, NULL);
  42203. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42204. return WC_TEST_RET_ENC_EC(ret);
  42205. ret = wc_DecodeEccsiSsk(key, NULL, 0, ssk);
  42206. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42207. return WC_TEST_RET_ENC_EC(ret);
  42208. ret = wc_DecodeEccsiSsk(NULL, data, 0, ssk);
  42209. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42210. return WC_TEST_RET_ENC_EC(ret);
  42211. ret = wc_DecodeEccsiPvt(NULL, NULL, 0, NULL);
  42212. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42213. return WC_TEST_RET_ENC_EC(ret);
  42214. ret = wc_DecodeEccsiPvt(key, data, 0, NULL);
  42215. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42216. return WC_TEST_RET_ENC_EC(ret);
  42217. ret = wc_DecodeEccsiPvt(key, NULL, 0, pvt);
  42218. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42219. return WC_TEST_RET_ENC_EC(ret);
  42220. ret = wc_DecodeEccsiPvt(NULL, data, 0, pvt);
  42221. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42222. return WC_TEST_RET_ENC_EC(ret);
  42223. ret = wc_DecodeEccsiPvtFromSig(NULL, NULL, 0, NULL);
  42224. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42225. return WC_TEST_RET_ENC_EC(ret);
  42226. ret = wc_DecodeEccsiPvtFromSig(key, data, 0, NULL);
  42227. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42228. return WC_TEST_RET_ENC_EC(ret);
  42229. ret = wc_DecodeEccsiPvtFromSig(key, NULL, 0, pvt);
  42230. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42231. return WC_TEST_RET_ENC_EC(ret);
  42232. ret = wc_DecodeEccsiPvtFromSig(NULL, data, 0, pvt);
  42233. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42234. return WC_TEST_RET_ENC_EC(ret);
  42235. ret = wc_ExportEccsiKey(NULL, data, NULL);
  42236. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42237. return WC_TEST_RET_ENC_EC(ret);
  42238. ret = wc_ExportEccsiKey(key, data, NULL);
  42239. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42240. return WC_TEST_RET_ENC_EC(ret);
  42241. ret = wc_ExportEccsiKey(NULL, data, &sz);
  42242. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42243. return WC_TEST_RET_ENC_EC(ret);
  42244. /* No key to export */
  42245. ret = wc_ExportEccsiKey(key, NULL, &sz);
  42246. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42247. return WC_TEST_RET_ENC_EC(ret);
  42248. ret = wc_ImportEccsiKey(NULL, NULL, 0);
  42249. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42250. return WC_TEST_RET_ENC_EC(ret);
  42251. ret = wc_ImportEccsiKey(key, NULL, 0);
  42252. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42253. return WC_TEST_RET_ENC_EC(ret);
  42254. ret = wc_ImportEccsiKey(NULL, data, 0);
  42255. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42256. return WC_TEST_RET_ENC_EC(ret);
  42257. ret = wc_ExportEccsiPrivateKey(NULL, data, NULL);
  42258. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42259. return WC_TEST_RET_ENC_EC(ret);
  42260. ret = wc_ExportEccsiPrivateKey(key, data, NULL);
  42261. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42262. return WC_TEST_RET_ENC_EC(ret);
  42263. ret = wc_ExportEccsiPrivateKey(NULL, data, &sz);
  42264. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42265. return WC_TEST_RET_ENC_EC(ret);
  42266. /* No key to export */
  42267. ret = wc_ExportEccsiPrivateKey(key, NULL, &sz);
  42268. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42269. return WC_TEST_RET_ENC_EC(ret);
  42270. ret = wc_ImportEccsiPrivateKey(NULL, NULL, 0);
  42271. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42272. return WC_TEST_RET_ENC_EC(ret);
  42273. ret = wc_ImportEccsiPrivateKey(key, NULL, 0);
  42274. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42275. return WC_TEST_RET_ENC_EC(ret);
  42276. ret = wc_ImportEccsiPrivateKey(NULL, data, 0);
  42277. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42278. return WC_TEST_RET_ENC_EC(ret);
  42279. ret = wc_ExportEccsiPublicKey(NULL, data, NULL, 1);
  42280. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42281. return WC_TEST_RET_ENC_EC(ret);
  42282. ret = wc_ExportEccsiPublicKey(key, data, NULL, 1);
  42283. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42284. return WC_TEST_RET_ENC_EC(ret);
  42285. ret = wc_ExportEccsiPublicKey(NULL, data, &sz, 1);
  42286. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42287. return WC_TEST_RET_ENC_EC(ret);
  42288. /* No key to export */
  42289. ret = wc_ExportEccsiPublicKey(key, data, &sz, 1);
  42290. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42291. return WC_TEST_RET_ENC_EC(ret);
  42292. ret = wc_ImportEccsiPublicKey(NULL, NULL, 0, 1);
  42293. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42294. return WC_TEST_RET_ENC_EC(ret);
  42295. ret = wc_ImportEccsiPublicKey(key, NULL, 0, 1);
  42296. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42297. return WC_TEST_RET_ENC_EC(ret);
  42298. ret = wc_ImportEccsiPublicKey(NULL, data, 0, 1);
  42299. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42300. return WC_TEST_RET_ENC_EC(ret);
  42301. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL);
  42302. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42303. return WC_TEST_RET_ENC_EC(ret);
  42304. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, NULL);
  42305. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42306. return WC_TEST_RET_ENC_EC(ret);
  42307. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, NULL, &hashSz);
  42308. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42309. return WC_TEST_RET_ENC_EC(ret);
  42310. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, NULL, hash, &hashSz);
  42311. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42312. return WC_TEST_RET_ENC_EC(ret);
  42313. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, NULL, 1, pvt, hash,
  42314. &hashSz);
  42315. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42316. return WC_TEST_RET_ENC_EC(ret);
  42317. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  42318. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42319. return WC_TEST_RET_ENC_EC(ret);
  42320. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  42321. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42322. return WC_TEST_RET_ENC_EC(ret);
  42323. ret = wc_SetEccsiHash(NULL, NULL, 1);
  42324. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42325. return WC_TEST_RET_ENC_EC(ret);
  42326. ret = wc_SetEccsiHash(key, NULL, 1);
  42327. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42328. return WC_TEST_RET_ENC_EC(ret);
  42329. ret = wc_SetEccsiHash(NULL, hash, 1);
  42330. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42331. return WC_TEST_RET_ENC_EC(ret);
  42332. ret = wc_SetEccsiPair(NULL, NULL, NULL);
  42333. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42334. return WC_TEST_RET_ENC_EC(ret);
  42335. ret = wc_SetEccsiPair(key, NULL, NULL);
  42336. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42337. return WC_TEST_RET_ENC_EC(ret);
  42338. ret = wc_SetEccsiPair(NULL, ssk, NULL);
  42339. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42340. return WC_TEST_RET_ENC_EC(ret);
  42341. ret = wc_SetEccsiPair(NULL, NULL, pvt);
  42342. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42343. return WC_TEST_RET_ENC_EC(ret);
  42344. ret = wc_SetEccsiPair(key, ssk, NULL);
  42345. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42346. return WC_TEST_RET_ENC_EC(ret);
  42347. ret = wc_SetEccsiPair(key, NULL, pvt);
  42348. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42349. return WC_TEST_RET_ENC_EC(ret);
  42350. ret = wc_SetEccsiPair(NULL, ssk, pvt);
  42351. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42352. return WC_TEST_RET_ENC_EC(ret);
  42353. ret = wc_SignEccsiHash(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, NULL);
  42354. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42355. return WC_TEST_RET_ENC_EC(ret);
  42356. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, sig, NULL);
  42357. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42358. return WC_TEST_RET_ENC_EC(ret);
  42359. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, NULL, 0, sig,
  42360. &sigSz);
  42361. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42362. return WC_TEST_RET_ENC_EC(ret);
  42363. ret = wc_SignEccsiHash(key, NULL, WC_HASH_TYPE_SHA256, data, 0, sig,
  42364. &sigSz);
  42365. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42366. return WC_TEST_RET_ENC_EC(ret);
  42367. ret = wc_SignEccsiHash(NULL, rng, WC_HASH_TYPE_SHA256, data, 0, sig,
  42368. &sigSz);
  42369. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42370. return WC_TEST_RET_ENC_EC(ret);
  42371. /* Key not set. */
  42372. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  42373. &sigSz);
  42374. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42375. return WC_TEST_RET_ENC_EC(ret);
  42376. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  42377. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42378. return WC_TEST_RET_ENC_EC(ret);
  42379. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  42380. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42381. return WC_TEST_RET_ENC_EC(ret);
  42382. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, NULL, 0, NULL);
  42383. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42384. return WC_TEST_RET_ENC_EC(ret);
  42385. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0, NULL);
  42386. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42387. return WC_TEST_RET_ENC_EC(ret);
  42388. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0,
  42389. &valid);
  42390. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42391. return WC_TEST_RET_ENC_EC(ret);
  42392. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, NULL);
  42393. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42394. return WC_TEST_RET_ENC_EC(ret);
  42395. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, NULL, 0,
  42396. &valid);
  42397. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42398. return WC_TEST_RET_ENC_EC(ret);
  42399. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0,
  42400. &valid);
  42401. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42402. return WC_TEST_RET_ENC_EC(ret);
  42403. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  42404. &valid);
  42405. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42406. return WC_TEST_RET_ENC_EC(ret);
  42407. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  42408. &valid);
  42409. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42410. return WC_TEST_RET_ENC_EC(ret);
  42411. ret = wc_SetEccsiPair(key, ssk, pvt);
  42412. if (ret != 0)
  42413. return WC_TEST_RET_ENC_EC(ret);
  42414. /* Identity hash not set. */
  42415. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  42416. &sigSz);
  42417. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42418. return WC_TEST_RET_ENC_EC(ret);
  42419. wc_FreeEccsiKey(key);
  42420. return 0;
  42421. }
  42422. /* RFC 6507: Appendix A */
  42423. static wc_test_ret_t eccsi_kat_verify_test(EccsiKey* key, ecc_point* pvt)
  42424. {
  42425. wc_test_ret_t ret;
  42426. int verified;
  42427. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00 };
  42428. word32 msgSz = sizeof(msg);
  42429. byte hash[WC_SHA256_DIGEST_SIZE];
  42430. byte hashSz = WC_SHA256_DIGEST_SIZE;
  42431. static const byte id[] = {
  42432. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  42433. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  42434. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  42435. 0x33, 0x00
  42436. };
  42437. word32 idSz = sizeof(id);
  42438. static const byte sig[] = {
  42439. 0x26, 0x9D, 0x4C, 0x8F, 0xDE, 0xB6, 0x6A, 0x74,
  42440. 0xE4, 0xEF, 0x8C, 0x0D, 0x5D, 0xCC, 0x59, 0x7D,
  42441. 0xDF, 0xE6, 0x02, 0x9C, 0x2A, 0xFF, 0xC4, 0x93,
  42442. 0x60, 0x08, 0xCD, 0x2C, 0xC1, 0x04, 0x5D, 0x81,
  42443. 0xE0, 0x9B, 0x52, 0x8D, 0x0E, 0xF8, 0xD6, 0xDF,
  42444. 0x1A, 0xA3, 0xEC, 0xBF, 0x80, 0x11, 0x0C, 0xFC,
  42445. 0xEC, 0x9F, 0xC6, 0x82, 0x52, 0xCE, 0xBB, 0x67,
  42446. 0x9F, 0x41, 0x34, 0x84, 0x69, 0x40, 0xCC, 0xFD,
  42447. 0x04,
  42448. 0x75, 0x8A, 0x14, 0x27, 0x79, 0xBE, 0x89, 0xE8,
  42449. 0x29, 0xE7, 0x19, 0x84, 0xCB, 0x40, 0xEF, 0x75,
  42450. 0x8C, 0xC4, 0xAD, 0x77, 0x5F, 0xC5, 0xB9, 0xA3,
  42451. 0xE1, 0xC8, 0xED, 0x52, 0xF6, 0xFA, 0x36, 0xD9,
  42452. 0xA7, 0x9D, 0x24, 0x76, 0x92, 0xF4, 0xED, 0xA3,
  42453. 0xA6, 0xBD, 0xAB, 0x77, 0xD6, 0xAA, 0x64, 0x74,
  42454. 0xA4, 0x64, 0xAE, 0x49, 0x34, 0x66, 0x3C, 0x52,
  42455. 0x65, 0xBA, 0x70, 0x18, 0xBA, 0x09, 0x1F, 0x79
  42456. };
  42457. word32 sigSz = sizeof(sig);
  42458. static const byte pubData[] = {
  42459. 0x50, 0xD4, 0x67, 0x0B, 0xDE, 0x75, 0x24, 0x4F,
  42460. 0x28, 0xD2, 0x83, 0x8A, 0x0D, 0x25, 0x55, 0x8A,
  42461. 0x7A, 0x72, 0x68, 0x6D, 0x45, 0x22, 0xD4, 0xC8,
  42462. 0x27, 0x3F, 0xB6, 0x44, 0x2A, 0xEB, 0xFA, 0x93,
  42463. 0xDB, 0xDD, 0x37, 0x55, 0x1A, 0xFD, 0x26, 0x3B,
  42464. 0x5D, 0xFD, 0x61, 0x7F, 0x39, 0x60, 0xC6, 0x5A,
  42465. 0x8C, 0x29, 0x88, 0x50, 0xFF, 0x99, 0xF2, 0x03,
  42466. 0x66, 0xDC, 0xE7, 0xD4, 0x36, 0x72, 0x17, 0xF4
  42467. };
  42468. static const byte expHash[] = {
  42469. 0x49, 0x0f, 0x3f, 0xeb, 0xbc, 0x1c, 0x90, 0x2f,
  42470. 0x62, 0x89, 0x72, 0x3d, 0x7f, 0x8c, 0xbf, 0x79,
  42471. 0xdb, 0x88, 0x93, 0x08, 0x49, 0xd1, 0x9f, 0x38,
  42472. 0xf0, 0x29, 0x5b, 0x5c, 0x27, 0x6c, 0x14, 0xd1
  42473. };
  42474. ret = wc_ImportEccsiPublicKey(key, pubData, sizeof(pubData), 0);
  42475. if (ret != 0)
  42476. return WC_TEST_RET_ENC_EC(ret);
  42477. ret = wc_DecodeEccsiPvtFromSig(key, sig, sigSz, pvt);
  42478. if (ret != 0)
  42479. return WC_TEST_RET_ENC_EC(ret);
  42480. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, idSz, pvt, hash,
  42481. &hashSz);
  42482. if (ret != 0)
  42483. return WC_TEST_RET_ENC_EC(ret);
  42484. if (hashSz != sizeof(expHash))
  42485. return WC_TEST_RET_ENC_NC;
  42486. if (XMEMCMP(hash, expHash, hashSz) != 0)
  42487. return WC_TEST_RET_ENC_NC;
  42488. ret = wc_SetEccsiHash(key, hash, hashSz);
  42489. if (ret != 0)
  42490. return WC_TEST_RET_ENC_EC(ret);
  42491. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42492. &verified);
  42493. if (ret != 0)
  42494. return WC_TEST_RET_ENC_EC(ret);
  42495. if (!verified)
  42496. return WC_TEST_RET_ENC_NC;
  42497. return 0;
  42498. }
  42499. static wc_test_ret_t eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt)
  42500. {
  42501. wc_test_ret_t ret;
  42502. byte data[32 * 3];
  42503. word32 sz;
  42504. ecc_point* decPvt = NULL;
  42505. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42506. mp_int *decSsk = (mp_int *)XMALLOC(sizeof(*decSsk), HEAP_HINT,
  42507. DYNAMIC_TYPE_TMP_BUFFER);
  42508. if (decSsk == NULL)
  42509. return WC_TEST_RET_ENC_ERRNO;
  42510. #else
  42511. mp_int decSsk[1];
  42512. #endif
  42513. ret = mp_init(decSsk);
  42514. if (ret != 0)
  42515. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42516. decPvt = wc_ecc_new_point();
  42517. if (decPvt == NULL)
  42518. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  42519. ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz);
  42520. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42521. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42522. if (sz != 32 * 3)
  42523. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42524. ret = wc_EncodeEccsiPair(priv, ssk, pvt, data, &sz);
  42525. if (ret != 0)
  42526. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42527. if (sz != 32* 3)
  42528. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42529. ret = wc_DecodeEccsiPair(priv, data, sz, decSsk, decPvt);
  42530. if (ret != 0)
  42531. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42532. ret = mp_cmp(ssk, decSsk);
  42533. if (ret != MP_EQ)
  42534. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42535. ret = wc_ecc_cmp_point(pvt, decPvt);
  42536. if (ret != MP_EQ)
  42537. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42538. ret = wc_EncodeEccsiSsk(priv, ssk, NULL, &sz);
  42539. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42541. if (sz != 32)
  42542. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42543. ret = wc_EncodeEccsiSsk(priv, ssk, data, &sz);
  42544. if (ret != 0)
  42545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42546. if (sz != 32)
  42547. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42548. ret = wc_DecodeEccsiSsk(priv, data, sz, decSsk);
  42549. if (ret != 0)
  42550. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42551. ret = mp_cmp(ssk, decSsk);
  42552. if (ret != MP_EQ)
  42553. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42554. ret = wc_EncodeEccsiPvt(priv, pvt, NULL, &sz, 1);
  42555. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42556. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42557. if (sz != 32 * 2)
  42558. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42559. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 1);
  42560. if (ret != 0)
  42561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42562. if (sz != 32 * 2)
  42563. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42564. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  42565. if (ret != 0)
  42566. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42567. ret = wc_ecc_cmp_point(pvt, decPvt);
  42568. if (ret != MP_EQ)
  42569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42570. sz = sizeof(data);
  42571. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 0);
  42572. if (ret != 0)
  42573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42574. if (sz != 32 * 2 + 1)
  42575. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42576. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  42577. if (ret != 0)
  42578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42579. ret = wc_ecc_cmp_point(pvt, decPvt);
  42580. if (ret != MP_EQ)
  42581. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42582. wc_ecc_del_point(decPvt);
  42583. out:
  42584. mp_free(decSsk);
  42585. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42586. XFREE(decSsk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42587. #endif
  42588. return ret;
  42589. }
  42590. static wc_test_ret_t eccsi_imp_exp_key_test(EccsiKey* priv)
  42591. {
  42592. wc_test_ret_t ret;
  42593. byte data[32 * 3];
  42594. byte out[32 * 3];
  42595. word32 sz;
  42596. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  42597. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42598. return WC_TEST_RET_ENC_EC(ret);
  42599. if (sz != 32 * 3)
  42600. return WC_TEST_RET_ENC_NC;
  42601. ret = wc_ExportEccsiKey(priv, data, &sz);
  42602. if (ret != 0)
  42603. return WC_TEST_RET_ENC_EC(ret);
  42604. ret = wc_ImportEccsiKey(priv, data, sz);
  42605. if (ret != 0)
  42606. return WC_TEST_RET_ENC_EC(ret);
  42607. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  42608. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42609. return WC_TEST_RET_ENC_EC(ret);
  42610. if (sz != 32 * 3)
  42611. return WC_TEST_RET_ENC_NC;
  42612. ret = wc_ExportEccsiKey(priv, out, &sz);
  42613. if (ret != 0)
  42614. return WC_TEST_RET_ENC_EC(ret);
  42615. if (sz != 32 * 3)
  42616. return WC_TEST_RET_ENC_NC;
  42617. if (XMEMCMP(data, out, sz) != 0)
  42618. return WC_TEST_RET_ENC_NC;
  42619. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  42620. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42621. return WC_TEST_RET_ENC_EC(ret);
  42622. if (sz != 32)
  42623. return WC_TEST_RET_ENC_NC;
  42624. ret = wc_ExportEccsiPrivateKey(priv, data, &sz);
  42625. if (ret != 0)
  42626. return WC_TEST_RET_ENC_EC(ret);
  42627. ret = wc_ImportEccsiPrivateKey(priv, data, sz);
  42628. if (ret != 0)
  42629. return WC_TEST_RET_ENC_EC(ret);
  42630. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  42631. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42632. return WC_TEST_RET_ENC_EC(ret);
  42633. if (sz != 32)
  42634. return WC_TEST_RET_ENC_NC;
  42635. ret = wc_ExportEccsiPrivateKey(priv, out, &sz);
  42636. if (ret != 0)
  42637. return WC_TEST_RET_ENC_EC(ret);
  42638. if (sz != 32)
  42639. return WC_TEST_RET_ENC_NC;
  42640. if (XMEMCMP(data, out, sz) != 0)
  42641. return WC_TEST_RET_ENC_NC;
  42642. return 0;
  42643. }
  42644. static wc_test_ret_t eccsi_imp_exp_pubkey_test(EccsiKey* key1, EccsiKey* key2)
  42645. {
  42646. wc_test_ret_t ret;
  42647. byte data[32 * 2 + 1];
  42648. byte pubData[32 * 2 + 1];
  42649. word32 sz;
  42650. ret = wc_ExportEccsiPublicKey(key1, NULL, &sz, 1);
  42651. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42652. return WC_TEST_RET_ENC_EC(ret);
  42653. if (sz != 32 * 2)
  42654. return WC_TEST_RET_ENC_NC;
  42655. ret = wc_ExportEccsiPublicKey(key1, data, &sz, 1);
  42656. if (ret != 0)
  42657. return WC_TEST_RET_ENC_EC(ret);
  42658. ret = wc_ImportEccsiPublicKey(key2, data, sz, 1);
  42659. if (ret != 0)
  42660. return WC_TEST_RET_ENC_EC(ret);
  42661. sz = sizeof(pubData);
  42662. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 1);
  42663. if (ret != 0)
  42664. return WC_TEST_RET_ENC_EC(ret);
  42665. if (sz != 32 * 2)
  42666. return WC_TEST_RET_ENC_NC;
  42667. if (XMEMCMP(data, pubData, sz) != 0)
  42668. return WC_TEST_RET_ENC_NC;
  42669. sz = sizeof(pubData);
  42670. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 0);
  42671. if (ret != 0)
  42672. return WC_TEST_RET_ENC_EC(ret);
  42673. if (sz != 32 * 2 + 1)
  42674. return WC_TEST_RET_ENC_NC;
  42675. if (pubData[0] != 0x04)
  42676. return WC_TEST_RET_ENC_NC;
  42677. if (XMEMCMP(pubData + 1, data, sz - 1) != 0)
  42678. return WC_TEST_RET_ENC_NC;
  42679. ret = wc_ImportEccsiPublicKey(key2, pubData, sz, 0);
  42680. if (ret != 0)
  42681. return WC_TEST_RET_ENC_EC(ret);
  42682. return 0;
  42683. }
  42684. static wc_test_ret_t eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  42685. mp_int* ssk, ecc_point* pvt)
  42686. {
  42687. wc_test_ret_t ret;
  42688. char mail[] = "test@wolfssl.com";
  42689. byte* id = (byte*)mail;
  42690. word32 idSz = (word32) XSTRLEN(mail);
  42691. int valid;
  42692. ret = wc_MakeEccsiKey(priv, rng);
  42693. if (ret != 0)
  42694. return WC_TEST_RET_ENC_EC(ret);
  42695. ret = eccsi_imp_exp_key_test(priv);
  42696. if (ret < 0)
  42697. return ret;
  42698. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  42699. if (ret < 0)
  42700. return ret;
  42701. ret = wc_MakeEccsiPair(priv, rng, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt);
  42702. if (ret != 0)
  42703. return WC_TEST_RET_ENC_EC(ret);
  42704. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  42705. &valid);
  42706. if (ret != 0)
  42707. return WC_TEST_RET_ENC_EC(ret);
  42708. if (!valid)
  42709. return WC_TEST_RET_ENC_NC;
  42710. ret = eccsi_enc_dec_pair_test(priv, ssk, pvt);
  42711. if (ret != 0)
  42712. return ret;
  42713. return 0;
  42714. }
  42715. static wc_test_ret_t eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  42716. mp_int* ssk, ecc_point* pvt)
  42717. {
  42718. wc_test_ret_t ret;
  42719. byte hashPriv[WC_MAX_DIGEST_SIZE];
  42720. byte hashPub[WC_MAX_DIGEST_SIZE];
  42721. byte hashSz;
  42722. byte sig[144];
  42723. word32 sigSz;
  42724. int verified, valid;
  42725. char mail[] = "test@wolfssl.com";
  42726. byte* id = (byte*)mail;
  42727. word32 idSz = (word32) XSTRLEN(mail);
  42728. byte msg[] = { 0x00 };
  42729. word32 msgSz = sizeof(msg);
  42730. #ifdef WOLFSSL_SHA384
  42731. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA384, id, idSz, pvt, hashPriv,
  42732. &hashSz);
  42733. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42734. return WC_TEST_RET_ENC_EC(ret);
  42735. #endif
  42736. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPriv,
  42737. &hashSz);
  42738. if (ret != 0)
  42739. return WC_TEST_RET_ENC_EC(ret);
  42740. if (hashSz != 32)
  42741. return WC_TEST_RET_ENC_NC;
  42742. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPub,
  42743. &hashSz);
  42744. if (ret != 0)
  42745. return WC_TEST_RET_ENC_EC(ret);
  42746. if (hashSz != 32)
  42747. return WC_TEST_RET_ENC_NC;
  42748. if (XMEMCMP(hashPriv, hashPub, hashSz) != 0)
  42749. return WC_TEST_RET_ENC_NC;
  42750. ret = wc_SetEccsiHash(priv, hashPriv, hashSz);
  42751. if (ret != 0)
  42752. return WC_TEST_RET_ENC_EC(ret);
  42753. ret = wc_SetEccsiPair(priv, ssk, pvt);
  42754. if (ret != 0)
  42755. return WC_TEST_RET_ENC_EC(ret);
  42756. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, NULL,
  42757. &sigSz);
  42758. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42759. return WC_TEST_RET_ENC_EC(ret);
  42760. if (sigSz != 129)
  42761. return WC_TEST_RET_ENC_NC;
  42762. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, sig,
  42763. &sigSz);
  42764. if (ret != 0)
  42765. return WC_TEST_RET_ENC_EC(ret);
  42766. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  42767. if (ret != 0)
  42768. return WC_TEST_RET_ENC_EC(ret);
  42769. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42770. &verified);
  42771. if (ret != 0)
  42772. return WC_TEST_RET_ENC_EC(ret);
  42773. if (!verified)
  42774. return WC_TEST_RET_ENC_NC;
  42775. /* Check that changing HS results in verification failure. */
  42776. hashPub[0] ^= 0x80;
  42777. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  42778. if (ret != 0)
  42779. return WC_TEST_RET_ENC_EC(ret);
  42780. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42781. &verified);
  42782. if (ret != 0)
  42783. return WC_TEST_RET_ENC_EC(ret);
  42784. if (verified)
  42785. return WC_TEST_RET_ENC_NC;
  42786. hashPub[0] ^= 0x80;
  42787. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  42788. if (ret != 0)
  42789. return WC_TEST_RET_ENC_EC(ret);
  42790. /* Check that changing msg results in verification failure. */
  42791. msg[0] ^= 0x80;
  42792. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42793. &verified);
  42794. if (ret != 0)
  42795. return WC_TEST_RET_ENC_EC(ret);
  42796. if (verified)
  42797. return WC_TEST_RET_ENC_NC;
  42798. msg[0] ^= 0x80;
  42799. /* Check that changing signature results in verification failure. */
  42800. sig[0] ^= 0x80;
  42801. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42802. &verified);
  42803. if (ret != 0)
  42804. return WC_TEST_RET_ENC_EC(ret);
  42805. if (verified)
  42806. return WC_TEST_RET_ENC_NC;
  42807. sig[0] ^= 0x80;
  42808. /* Check that key state hasn't been invalidated. */
  42809. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42810. &verified);
  42811. if (ret != 0)
  42812. return WC_TEST_RET_ENC_EC(ret);
  42813. if (!verified)
  42814. return WC_TEST_RET_ENC_NC;
  42815. /* Check that verifying with the private key works. */
  42816. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42817. &verified);
  42818. if (ret != 0)
  42819. return WC_TEST_RET_ENC_EC(ret);
  42820. if (!verified)
  42821. return WC_TEST_RET_ENC_NC;
  42822. /* Check that the KPAK is converted from montgomery form. */
  42823. ret = eccsi_imp_exp_key_test(priv);
  42824. if (ret != 0)
  42825. return ret;
  42826. /* Check that KPAK can converted to Montgomery form again. */
  42827. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42828. &verified);
  42829. if (ret != 0)
  42830. return WC_TEST_RET_ENC_EC(ret);
  42831. if (!verified)
  42832. return WC_TEST_RET_ENC_NC;
  42833. /* Check that the KPAK is converted from montgomery form. */
  42834. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  42835. &valid);
  42836. if (ret != 0)
  42837. return WC_TEST_RET_ENC_EC(ret);
  42838. if (!valid)
  42839. return WC_TEST_RET_ENC_NC;
  42840. /* Check that KPAK can converted to Montgomery form again. */
  42841. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42842. &verified);
  42843. if (ret != 0)
  42844. return WC_TEST_RET_ENC_EC(ret);
  42845. if (!verified)
  42846. return WC_TEST_RET_ENC_NC;
  42847. /* Check that the KPAK is converted from montgomery form. */
  42848. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  42849. if (ret != 0)
  42850. return ret;
  42851. return 0;
  42852. }
  42853. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void)
  42854. {
  42855. wc_test_ret_t ret = 0;
  42856. WC_RNG rng;
  42857. int rng_inited = 0;
  42858. EccsiKey* priv = NULL;
  42859. EccsiKey* pub = NULL;
  42860. mp_int* ssk = NULL;
  42861. ecc_point* pvt = NULL;
  42862. WOLFSSL_ENTER("eccsi_test");
  42863. priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  42864. DYNAMIC_TYPE_TMP_BUFFER);
  42865. if (priv == NULL)
  42866. ret = WC_TEST_RET_ENC_NC;
  42867. else
  42868. XMEMSET(priv, 0, sizeof(*priv));
  42869. if (ret == 0) {
  42870. pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  42871. DYNAMIC_TYPE_TMP_BUFFER);
  42872. if (pub == NULL)
  42873. ret = WC_TEST_RET_ENC_NC;
  42874. else
  42875. XMEMSET(pub, 0, sizeof(*pub));
  42876. }
  42877. if (ret == 0) {
  42878. ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT,
  42879. DYNAMIC_TYPE_TMP_BUFFER);
  42880. if (ssk == NULL)
  42881. ret = WC_TEST_RET_ENC_NC;
  42882. else
  42883. XMEMSET(ssk, 0, sizeof(*ssk));
  42884. }
  42885. if (ret == 0) {
  42886. #ifndef HAVE_FIPS
  42887. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  42888. #else
  42889. ret = wc_InitRng(&rng);
  42890. #endif
  42891. if (ret != 0)
  42892. ret = WC_TEST_RET_ENC_EC(ret);
  42893. else
  42894. rng_inited = 1;
  42895. }
  42896. if (ret == 0) {
  42897. pvt = wc_ecc_new_point();
  42898. if (pvt == NULL)
  42899. ret = WC_TEST_RET_ENC_NC;
  42900. }
  42901. if (ret == 0) {
  42902. ret = mp_init(ssk);
  42903. if (ret != 0)
  42904. ret = WC_TEST_RET_ENC_EC(ret);
  42905. }
  42906. if (ret == 0) {
  42907. ret = eccsi_api_test(&rng, priv, ssk, pvt);
  42908. }
  42909. if (ret == 0) {
  42910. ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID);
  42911. if (ret != 0)
  42912. ret = WC_TEST_RET_ENC_EC(ret);
  42913. }
  42914. if (ret == 0) {
  42915. ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID);
  42916. if (ret != 0)
  42917. ret = WC_TEST_RET_ENC_EC(ret);
  42918. }
  42919. if (ret == 0) {
  42920. ret = eccsi_kat_verify_test(pub, pvt);
  42921. }
  42922. if (ret == 0) {
  42923. ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt);
  42924. }
  42925. if (ret == 0) {
  42926. ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt);
  42927. }
  42928. if (pvt != NULL)
  42929. wc_ecc_del_point(pvt);
  42930. if (rng_inited)
  42931. wc_FreeRng(&rng);
  42932. if (ssk != NULL) {
  42933. mp_free(ssk);
  42934. XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42935. }
  42936. if (pub != NULL) {
  42937. wc_FreeEccsiKey(pub);
  42938. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42939. }
  42940. if (priv != NULL) {
  42941. wc_FreeEccsiKey(priv);
  42942. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42943. }
  42944. return ret;
  42945. }
  42946. #endif /* WOLFCRYPT_HAVE_ECCSI */
  42947. #ifdef WOLFCRYPT_HAVE_SAKKE
  42948. static wc_test_ret_t sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk)
  42949. {
  42950. wc_test_ret_t ret;
  42951. byte id[1] = { 0x00 };
  42952. int valid;
  42953. byte data[256];
  42954. word32 sz;
  42955. byte auth[257];
  42956. word16 authSz;
  42957. byte ssv[256];
  42958. word16 ssvSz;
  42959. word32 len;
  42960. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  42961. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42962. return WC_TEST_RET_ENC_EC(ret);
  42963. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  42964. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42965. return WC_TEST_RET_ENC_EC(ret);
  42966. wc_FreeSakkeKey(NULL);
  42967. XMEMSET(key, 0, sizeof(*key));
  42968. wc_FreeSakkeKey(key);
  42969. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  42970. if (ret != 0)
  42971. return WC_TEST_RET_ENC_EC(ret);
  42972. ret = wc_MakeSakkeKey(NULL, NULL);
  42973. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42974. return WC_TEST_RET_ENC_EC(ret);
  42975. ret = wc_MakeSakkeKey(key, NULL);
  42976. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42977. return WC_TEST_RET_ENC_EC(ret);
  42978. ret = wc_MakeSakkeKey(NULL, rng);
  42979. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42980. return WC_TEST_RET_ENC_EC(ret);
  42981. ret = wc_MakeSakkePublicKey(NULL, NULL);
  42982. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42983. return WC_TEST_RET_ENC_EC(ret);
  42984. ret = wc_MakeSakkePublicKey(key, NULL);
  42985. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42986. return WC_TEST_RET_ENC_EC(ret);
  42987. ret = wc_MakeSakkePublicKey(NULL, rsk);
  42988. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42989. return WC_TEST_RET_ENC_EC(ret);
  42990. ret = wc_MakeSakkeRsk(NULL, NULL, 1, NULL);
  42991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42992. return WC_TEST_RET_ENC_EC(ret);
  42993. ret = wc_MakeSakkeRsk(key, id, 1, NULL);
  42994. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42995. return WC_TEST_RET_ENC_EC(ret);
  42996. ret = wc_MakeSakkeRsk(key, NULL, 1, rsk);
  42997. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42998. return WC_TEST_RET_ENC_EC(ret);
  42999. ret = wc_MakeSakkeRsk(NULL, id, 1, rsk);
  43000. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43001. return WC_TEST_RET_ENC_EC(ret);
  43002. ret = wc_ValidateSakkeRsk(NULL, NULL, 1, NULL, NULL);
  43003. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43004. return WC_TEST_RET_ENC_EC(ret);
  43005. ret = wc_ValidateSakkeRsk(key, id, 1, rsk, NULL);
  43006. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43007. return WC_TEST_RET_ENC_EC(ret);
  43008. ret = wc_ValidateSakkeRsk(NULL, id, 1, rsk, &valid);
  43009. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43010. return WC_TEST_RET_ENC_EC(ret);
  43011. ret = wc_ExportSakkeKey(NULL, NULL, NULL);
  43012. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43013. return WC_TEST_RET_ENC_EC(ret);
  43014. ret = wc_ExportSakkeKey(key, data, NULL);
  43015. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43016. return WC_TEST_RET_ENC_EC(ret);
  43017. ret = wc_ExportSakkeKey(NULL, data, &sz);
  43018. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43019. return WC_TEST_RET_ENC_EC(ret);
  43020. ret = wc_ImportSakkeKey(NULL, NULL, 1);
  43021. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43022. return WC_TEST_RET_ENC_EC(ret);
  43023. ret = wc_ImportSakkeKey(key, NULL, 1);
  43024. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43025. return WC_TEST_RET_ENC_EC(ret);
  43026. ret = wc_ImportSakkeKey(NULL, data, 1);
  43027. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43028. return WC_TEST_RET_ENC_EC(ret);
  43029. ret = wc_ExportSakkePrivateKey(NULL, NULL, NULL);
  43030. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43031. return WC_TEST_RET_ENC_EC(ret);
  43032. ret = wc_ExportSakkePrivateKey(key, data, NULL);
  43033. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43034. return WC_TEST_RET_ENC_EC(ret);
  43035. ret = wc_ExportSakkePrivateKey(NULL, data, &sz);
  43036. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43037. return WC_TEST_RET_ENC_EC(ret);
  43038. ret = wc_ImportSakkePrivateKey(NULL, NULL, 1);
  43039. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43040. return WC_TEST_RET_ENC_EC(ret);
  43041. ret = wc_ImportSakkePrivateKey(key, NULL, 1);
  43042. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43043. return WC_TEST_RET_ENC_EC(ret);
  43044. ret = wc_ImportSakkePrivateKey(NULL, data, 1);
  43045. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43046. return WC_TEST_RET_ENC_EC(ret);
  43047. sz = sizeof(data);
  43048. ret = wc_EncodeSakkeRsk(NULL, NULL, data, NULL, 1);
  43049. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43050. return WC_TEST_RET_ENC_EC(ret);
  43051. ret = wc_EncodeSakkeRsk(key, rsk, data, NULL, 1);
  43052. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43053. return WC_TEST_RET_ENC_EC(ret);
  43054. ret = wc_EncodeSakkeRsk(key, NULL, data, &sz, 1);
  43055. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43056. return WC_TEST_RET_ENC_EC(ret);
  43057. ret = wc_EncodeSakkeRsk(NULL, rsk, data, &sz, 1);
  43058. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43059. return WC_TEST_RET_ENC_EC(ret);
  43060. ret = wc_DecodeSakkeRsk(NULL, NULL, sz, NULL);
  43061. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43062. return WC_TEST_RET_ENC_EC(ret);
  43063. ret = wc_DecodeSakkeRsk(key, data, sz, NULL);
  43064. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43065. return WC_TEST_RET_ENC_EC(ret);
  43066. ret = wc_DecodeSakkeRsk(key, NULL, sz, rsk);
  43067. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43068. return WC_TEST_RET_ENC_EC(ret);
  43069. ret = wc_DecodeSakkeRsk(NULL, data, sz, rsk);
  43070. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43071. return WC_TEST_RET_ENC_EC(ret);
  43072. ret = wc_ImportSakkeRsk(NULL, NULL, sz);
  43073. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43074. return WC_TEST_RET_ENC_EC(ret);
  43075. ret = wc_ImportSakkeRsk(key, NULL, sz);
  43076. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43077. return WC_TEST_RET_ENC_EC(ret);
  43078. ret = wc_ImportSakkeRsk(NULL, data, sz);
  43079. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43080. return WC_TEST_RET_ENC_EC(ret);
  43081. ret = wc_ImportSakkeRsk(key, data, 1);
  43082. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43083. return WC_TEST_RET_ENC_EC(ret);
  43084. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, NULL);
  43085. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43086. return WC_TEST_RET_ENC_EC(ret);
  43087. ret = wc_GenerateSakkeRskTable(key, NULL, data, NULL);
  43088. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43089. return WC_TEST_RET_ENC_EC(ret);
  43090. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, NULL);
  43091. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43092. return WC_TEST_RET_ENC_EC(ret);
  43093. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, &len);
  43094. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43095. return WC_TEST_RET_ENC_EC(ret);
  43096. ret = wc_GenerateSakkeRskTable(key, rsk, data, NULL);
  43097. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43098. return WC_TEST_RET_ENC_EC(ret);
  43099. ret = wc_GenerateSakkeRskTable(key, NULL, data, &len);
  43100. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43101. return WC_TEST_RET_ENC_EC(ret);
  43102. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, &len);
  43103. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43104. return WC_TEST_RET_ENC_EC(ret);
  43105. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43106. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43107. return WC_TEST_RET_ENC_EC(ret);
  43108. len--;
  43109. ret = wc_GenerateSakkeRskTable(key, rsk, data, &len);
  43110. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43111. return WC_TEST_RET_ENC_EC(ret);
  43112. ret = wc_ExportSakkePublicKey(NULL, data, NULL, 1);
  43113. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43114. return WC_TEST_RET_ENC_EC(ret);
  43115. ret = wc_ExportSakkePublicKey(key, data, NULL, 1);
  43116. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43117. return WC_TEST_RET_ENC_EC(ret);
  43118. ret = wc_ExportSakkePublicKey(NULL, data, &sz, 1);
  43119. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43120. return WC_TEST_RET_ENC_EC(ret);
  43121. ret = wc_ImportSakkePublicKey(NULL, NULL, sz, 1);
  43122. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43123. return WC_TEST_RET_ENC_EC(ret);
  43124. ret = wc_ImportSakkePublicKey(key, NULL, sz, 1);
  43125. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43126. return WC_TEST_RET_ENC_EC(ret);
  43127. ret = wc_ImportSakkePublicKey(NULL, data, sz, 1);
  43128. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43129. return WC_TEST_RET_ENC_EC(ret);
  43130. ret = wc_GetSakkeAuthSize(NULL, NULL);
  43131. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43132. return WC_TEST_RET_ENC_EC(ret);
  43133. ret = wc_GetSakkeAuthSize(key, NULL);
  43134. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43135. return WC_TEST_RET_ENC_EC(ret);
  43136. ret = wc_GetSakkeAuthSize(NULL, &authSz);
  43137. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43138. return WC_TEST_RET_ENC_EC(ret);
  43139. ret = wc_MakeSakkePointI(NULL, NULL, SAKKE_ID_MAX_SIZE + 1);
  43140. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43141. return WC_TEST_RET_ENC_EC(ret);
  43142. ret = wc_MakeSakkePointI(key, NULL, SAKKE_ID_MAX_SIZE + 1);
  43143. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43144. return WC_TEST_RET_ENC_EC(ret);
  43145. ret = wc_MakeSakkePointI(NULL, id, 1);
  43146. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43147. return WC_TEST_RET_ENC_EC(ret);
  43148. ret = wc_MakeSakkePointI(NULL, NULL, 1);
  43149. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43150. return WC_TEST_RET_ENC_EC(ret);
  43151. ret = wc_MakeSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1);
  43152. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43153. return WC_TEST_RET_ENC_EC(ret);
  43154. ret = wc_MakeSakkePointI(key, NULL, 1);
  43155. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43156. return WC_TEST_RET_ENC_EC(ret);
  43157. ret = wc_MakeSakkePointI(NULL, id, 1);
  43158. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43159. return WC_TEST_RET_ENC_EC(ret);
  43160. ret = wc_GenerateSakkePointITable(NULL, data, NULL);
  43161. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43162. return WC_TEST_RET_ENC_EC(ret);
  43163. ret = wc_GenerateSakkePointITable(key, data, NULL);
  43164. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43165. return WC_TEST_RET_ENC_EC(ret);
  43166. ret = wc_GenerateSakkePointITable(NULL, data, &len);
  43167. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43168. return WC_TEST_RET_ENC_EC(ret);
  43169. ret = wc_GenerateSakkePointITable(key, NULL, &len);
  43170. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43171. return WC_TEST_RET_ENC_EC(ret);
  43172. len--;
  43173. ret = wc_GenerateSakkePointITable(key, data, &len);
  43174. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43175. return WC_TEST_RET_ENC_EC(ret);
  43176. ret = wc_SetSakkePointITable(NULL, NULL, 1);
  43177. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43178. return WC_TEST_RET_ENC_EC(ret);
  43179. ret = wc_SetSakkePointITable(key, NULL, 1);
  43180. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43181. return WC_TEST_RET_ENC_EC(ret);
  43182. ret = wc_SetSakkePointITable(NULL, data, 1);
  43183. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43184. return WC_TEST_RET_ENC_EC(ret);
  43185. ret = wc_SetSakkePointITable(key, data, 1);
  43186. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43187. return WC_TEST_RET_ENC_EC(ret);
  43188. ret = wc_ClearSakkePointITable(NULL);
  43189. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43190. return WC_TEST_RET_ENC_EC(ret);
  43191. ret = wc_GetSakkePointI(NULL, data, NULL);
  43192. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43193. return WC_TEST_RET_ENC_EC(ret);
  43194. ret = wc_GetSakkePointI(key, data, NULL);
  43195. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43196. return WC_TEST_RET_ENC_EC(ret);
  43197. ret = wc_GetSakkePointI(NULL, data, &sz);
  43198. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43199. return WC_TEST_RET_ENC_EC(ret);
  43200. sz = 1;
  43201. ret = wc_GetSakkePointI(key, data, &sz);
  43202. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43203. return WC_TEST_RET_ENC_EC(ret);
  43204. sz = 256;
  43205. ret = wc_SetSakkePointI(NULL, NULL, 1, NULL, sz);
  43206. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43207. return WC_TEST_RET_ENC_EC(ret);
  43208. ret = wc_SetSakkePointI(key, NULL, 1, NULL, sz);
  43209. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43210. return WC_TEST_RET_ENC_EC(ret);
  43211. ret = wc_SetSakkePointI(NULL, id, 1, NULL, sz);
  43212. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43213. return WC_TEST_RET_ENC_EC(ret);
  43214. ret = wc_SetSakkePointI(NULL, NULL, 1, data, sz);
  43215. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43216. return WC_TEST_RET_ENC_EC(ret);
  43217. ret = wc_SetSakkePointI(key, id, 1, NULL, sz);
  43218. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43219. return WC_TEST_RET_ENC_EC(ret);
  43220. ret = wc_SetSakkePointI(key, NULL, 1, data, sz);
  43221. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43222. return WC_TEST_RET_ENC_EC(ret);
  43223. ret = wc_SetSakkePointI(NULL, id, 1, data, sz);
  43224. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43225. return WC_TEST_RET_ENC_EC(ret);
  43226. ret = wc_SetSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1, data, sz);
  43227. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43228. return WC_TEST_RET_ENC_EC(ret);
  43229. ret = wc_SetSakkePointI(key, id, 1, data, sz - 1);
  43230. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43231. return WC_TEST_RET_ENC_EC(ret);
  43232. ret = wc_SetSakkeIdentity(NULL, NULL, 1);
  43233. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43234. return WC_TEST_RET_ENC_EC(ret);
  43235. ret = wc_SetSakkeIdentity(key, NULL, 1);
  43236. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43237. return WC_TEST_RET_ENC_EC(ret);
  43238. ret = wc_SetSakkeIdentity(NULL, id, 1);
  43239. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43240. return WC_TEST_RET_ENC_EC(ret);
  43241. ssvSz = sizeof(ssv);
  43242. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43243. auth, NULL);
  43244. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43245. return WC_TEST_RET_ENC_EC(ret);
  43246. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43247. auth, NULL);
  43248. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43249. return WC_TEST_RET_ENC_EC(ret);
  43250. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43251. auth, NULL);
  43252. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43253. return WC_TEST_RET_ENC_EC(ret);
  43254. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43255. auth, &authSz);
  43256. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43257. return WC_TEST_RET_ENC_EC(ret);
  43258. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43259. auth, NULL);
  43260. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43261. return WC_TEST_RET_ENC_EC(ret);
  43262. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43263. auth, &authSz);
  43264. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43265. return WC_TEST_RET_ENC_EC(ret);
  43266. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43267. auth, &authSz);
  43268. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43269. return WC_TEST_RET_ENC_EC(ret);
  43270. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43271. auth, &authSz);
  43272. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43273. return WC_TEST_RET_ENC_EC(ret);
  43274. ret = wc_GenerateSakkeSSV(NULL, NULL, data, NULL);
  43275. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43276. return WC_TEST_RET_ENC_EC(ret);
  43277. ret = wc_GenerateSakkeSSV(key, rng, data, NULL);
  43278. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43279. return WC_TEST_RET_ENC_EC(ret);
  43280. ret = wc_GenerateSakkeSSV(key, NULL, data, &ssvSz);
  43281. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43282. return WC_TEST_RET_ENC_EC(ret);
  43283. ret = wc_GenerateSakkeSSV(NULL, rng, data, &ssvSz);
  43284. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43285. return WC_TEST_RET_ENC_EC(ret);
  43286. ret = wc_SetSakkeRsk(NULL, NULL, data, 1);
  43287. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43288. return WC_TEST_RET_ENC_EC(ret);
  43289. ret = wc_SetSakkeRsk(key, NULL, data, 1);
  43290. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43291. return WC_TEST_RET_ENC_EC(ret);
  43292. ret = wc_SetSakkeRsk(NULL, rsk, data, 1);
  43293. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43294. return WC_TEST_RET_ENC_EC(ret);
  43295. ssvSz = sizeof(ssv);
  43296. authSz = sizeof(auth);
  43297. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  43298. authSz);
  43299. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43300. return WC_TEST_RET_ENC_EC(ret);
  43301. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  43302. authSz);
  43303. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43304. return WC_TEST_RET_ENC_EC(ret);
  43305. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  43306. authSz);
  43307. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43308. return WC_TEST_RET_ENC_EC(ret);
  43309. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  43310. authSz);
  43311. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43312. return WC_TEST_RET_ENC_EC(ret);
  43313. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  43314. authSz);
  43315. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43316. return WC_TEST_RET_ENC_EC(ret);
  43317. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  43318. authSz);
  43319. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43320. return WC_TEST_RET_ENC_EC(ret);
  43321. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43322. authSz);
  43323. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43324. return WC_TEST_RET_ENC_EC(ret);
  43325. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43326. authSz);
  43327. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43328. return WC_TEST_RET_ENC_EC(ret);
  43329. ret = wc_SetSakkeIdentity(key, id, 1);
  43330. if (ret != 0)
  43331. return WC_TEST_RET_ENC_EC(ret);
  43332. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43333. authSz);
  43334. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43335. return WC_TEST_RET_ENC_EC(ret);
  43336. ret = wc_SetSakkeIdentity(key, id, 0);
  43337. if (ret != 0)
  43338. return WC_TEST_RET_ENC_EC(ret);
  43339. ret = wc_SetSakkeRsk(key, rsk, data, 1);
  43340. if (ret != 0)
  43341. return WC_TEST_RET_ENC_EC(ret);
  43342. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43343. authSz);
  43344. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43345. return WC_TEST_RET_ENC_EC(ret);
  43346. wc_FreeSakkeKey(key);
  43347. return 0;
  43348. }
  43349. static wc_test_ret_t sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk)
  43350. {
  43351. WOLFSSL_SMALL_STACK_STATIC const byte pubData[] = {
  43352. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  43353. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  43354. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  43355. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  43356. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  43357. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  43358. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  43359. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  43360. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  43361. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  43362. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  43363. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  43364. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  43365. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  43366. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  43367. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  43368. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  43369. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  43370. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  43371. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  43372. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  43373. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  43374. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  43375. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  43376. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  43377. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  43378. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  43379. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  43380. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  43381. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  43382. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  43383. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  43384. };
  43385. WOLFSSL_SMALL_STACK_STATIC const byte rskData[] = {
  43386. 0x93, 0xAF, 0x67, 0xE5, 0x00, 0x7B, 0xA6, 0xE6,
  43387. 0xA8, 0x0D, 0xA7, 0x93, 0xDA, 0x30, 0x0F, 0xA4,
  43388. 0xB5, 0x2D, 0x0A, 0x74, 0xE2, 0x5E, 0x6E, 0x7B,
  43389. 0x2B, 0x3D, 0x6E, 0xE9, 0xD1, 0x8A, 0x9B, 0x5C,
  43390. 0x50, 0x23, 0x59, 0x7B, 0xD8, 0x2D, 0x80, 0x62,
  43391. 0xD3, 0x40, 0x19, 0x56, 0x3B, 0xA1, 0xD2, 0x5C,
  43392. 0x0D, 0xC5, 0x6B, 0x7B, 0x97, 0x9D, 0x74, 0xAA,
  43393. 0x50, 0xF2, 0x9F, 0xBF, 0x11, 0xCC, 0x2C, 0x93,
  43394. 0xF5, 0xDF, 0xCA, 0x61, 0x5E, 0x60, 0x92, 0x79,
  43395. 0xF6, 0x17, 0x5C, 0xEA, 0xDB, 0x00, 0xB5, 0x8C,
  43396. 0x6B, 0xEE, 0x1E, 0x7A, 0x2A, 0x47, 0xC4, 0xF0,
  43397. 0xC4, 0x56, 0xF0, 0x52, 0x59, 0xA6, 0xFA, 0x94,
  43398. 0xA6, 0x34, 0xA4, 0x0D, 0xAE, 0x1D, 0xF5, 0x93,
  43399. 0xD4, 0xFE, 0xCF, 0x68, 0x8D, 0x5F, 0xC6, 0x78,
  43400. 0xBE, 0x7E, 0xFC, 0x6D, 0xF3, 0xD6, 0x83, 0x53,
  43401. 0x25, 0xB8, 0x3B, 0x2C, 0x6E, 0x69, 0x03, 0x6B,
  43402. 0x15, 0x5F, 0x0A, 0x27, 0x24, 0x10, 0x94, 0xB0,
  43403. 0x4B, 0xFB, 0x0B, 0xDF, 0xAC, 0x6C, 0x67, 0x0A,
  43404. 0x65, 0xC3, 0x25, 0xD3, 0x9A, 0x06, 0x9F, 0x03,
  43405. 0x65, 0x9D, 0x44, 0xCA, 0x27, 0xD3, 0xBE, 0x8D,
  43406. 0xF3, 0x11, 0x17, 0x2B, 0x55, 0x41, 0x60, 0x18,
  43407. 0x1C, 0xBE, 0x94, 0xA2, 0xA7, 0x83, 0x32, 0x0C,
  43408. 0xED, 0x59, 0x0B, 0xC4, 0x26, 0x44, 0x70, 0x2C,
  43409. 0xF3, 0x71, 0x27, 0x1E, 0x49, 0x6B, 0xF2, 0x0F,
  43410. 0x58, 0x8B, 0x78, 0xA1, 0xBC, 0x01, 0xEC, 0xBB,
  43411. 0x65, 0x59, 0x93, 0x4B, 0xDD, 0x2F, 0xB6, 0x5D,
  43412. 0x28, 0x84, 0x31, 0x8A, 0x33, 0xD1, 0xA4, 0x2A,
  43413. 0xDF, 0x5E, 0x33, 0xCC, 0x58, 0x00, 0x28, 0x0B,
  43414. 0x28, 0x35, 0x64, 0x97, 0xF8, 0x71, 0x35, 0xBA,
  43415. 0xB9, 0x61, 0x2A, 0x17, 0x26, 0x04, 0x24, 0x40,
  43416. 0x9A, 0xC1, 0x5F, 0xEE, 0x99, 0x6B, 0x74, 0x4C,
  43417. 0x33, 0x21, 0x51, 0x23, 0x5D, 0xEC, 0xB0, 0xF5
  43418. };
  43419. WOLFSSL_SMALL_STACK_STATIC const byte id[] = {
  43420. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43421. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43422. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43423. 0x33, 0x00
  43424. };
  43425. WOLFSSL_SMALL_STACK_STATIC const byte ssv[] = {
  43426. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  43427. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  43428. };
  43429. WOLFSSL_SMALL_STACK_STATIC const byte auth[] = {
  43430. 0x04,
  43431. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  43432. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  43433. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  43434. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  43435. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  43436. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  43437. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  43438. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  43439. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  43440. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  43441. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  43442. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  43443. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  43444. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  43445. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  43446. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  43447. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  43448. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  43449. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  43450. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  43451. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  43452. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  43453. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  43454. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  43455. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  43456. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  43457. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  43458. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  43459. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  43460. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  43461. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  43462. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  43463. };
  43464. WOLFSSL_SMALL_STACK_STATIC const byte encSsv[] = {
  43465. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  43466. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  43467. };
  43468. wc_test_ret_t ret;
  43469. int valid;
  43470. byte pubKey[sizeof(pubData) + 1];
  43471. word32 sz = sizeof(pubKey);
  43472. byte tmpSsv[sizeof(encSsv)];
  43473. byte* iTable = NULL;
  43474. word32 iTableLen;
  43475. byte* table = NULL;
  43476. word32 len;
  43477. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  43478. if (ret != 0)
  43479. return WC_TEST_RET_ENC_EC(ret);
  43480. ret = wc_DecodeSakkeRsk(key, rskData, sizeof(rskData), rsk);
  43481. if (ret != 0)
  43482. return WC_TEST_RET_ENC_EC(ret);
  43483. ret = wc_ValidateSakkeRsk(key, id, sizeof(id), rsk, &valid);
  43484. if (ret != 0)
  43485. return WC_TEST_RET_ENC_EC(ret);
  43486. if (valid != 1)
  43487. return WC_TEST_RET_ENC_NC;
  43488. ret = wc_SetSakkeRsk(key, rsk, NULL, 0);
  43489. if (ret != 0)
  43490. return WC_TEST_RET_ENC_EC(ret);
  43491. ret = wc_SetSakkeIdentity(key, id, sizeof(id));
  43492. if (ret != 0)
  43493. return WC_TEST_RET_ENC_EC(ret);
  43494. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  43495. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  43496. auth, sizeof(auth));
  43497. if (ret != 0)
  43498. return WC_TEST_RET_ENC_EC(ret);
  43499. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  43500. return WC_TEST_RET_ENC_NC;
  43501. ret = wc_MakeSakkePointI(key, id, sizeof(id));
  43502. if (ret != 0)
  43503. return WC_TEST_RET_ENC_EC(ret);
  43504. iTableLen = 0;
  43505. ret = wc_GenerateSakkePointITable(key, NULL, &iTableLen);
  43506. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43507. return WC_TEST_RET_ENC_EC(ret);
  43508. if (iTableLen != 0) {
  43509. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43510. if (iTable == NULL)
  43511. return WC_TEST_RET_ENC_ERRNO;
  43512. ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen);
  43513. if (ret != 0)
  43514. return WC_TEST_RET_ENC_EC(ret);
  43515. }
  43516. len = 0;
  43517. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43518. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43519. return WC_TEST_RET_ENC_EC(ret);
  43520. if (len > 0) {
  43521. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43522. if (table == NULL)
  43523. return WC_TEST_RET_ENC_ERRNO;
  43524. ret = wc_GenerateSakkeRskTable(key, rsk, table, &len);
  43525. if (ret != 0)
  43526. return WC_TEST_RET_ENC_EC(ret);
  43527. }
  43528. ret = wc_SetSakkeRsk(key, rsk, table, len);
  43529. if (ret != 0)
  43530. return WC_TEST_RET_ENC_EC(ret);
  43531. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  43532. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  43533. auth, sizeof(auth));
  43534. if (ret != 0)
  43535. return WC_TEST_RET_ENC_EC(ret);
  43536. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  43537. return WC_TEST_RET_ENC_NC;
  43538. /* Don't reference table that is about to be freed. */
  43539. ret = wc_ClearSakkePointITable(key);
  43540. if (ret != 0)
  43541. return WC_TEST_RET_ENC_EC(ret);
  43542. /* Dispose of tables */
  43543. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43544. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43545. /* Make sure the key public key is exportable - convert to Montgomery form
  43546. * in Validation.
  43547. */
  43548. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 1);
  43549. if (ret != 0)
  43550. return WC_TEST_RET_ENC_EC(ret);
  43551. if (sz != sizeof(pubData))
  43552. return WC_TEST_RET_ENC_NC;
  43553. if (XMEMCMP(pubKey, pubData, sizeof(pubData)) != 0)
  43554. return WC_TEST_RET_ENC_NC;
  43555. sz = sizeof(pubData) + 1;
  43556. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 0);
  43557. if (ret != 0)
  43558. return WC_TEST_RET_ENC_EC(ret);
  43559. if (sz != sizeof(pubData) + 1)
  43560. return WC_TEST_RET_ENC_NC;
  43561. if (pubKey[0] != 0x04)
  43562. return WC_TEST_RET_ENC_NC;
  43563. if (XMEMCMP(pubKey + 1, pubData, sizeof(pubData)) != 0)
  43564. return WC_TEST_RET_ENC_NC;
  43565. return 0;
  43566. }
  43567. static wc_test_ret_t sakke_kat_encapsulate_test(SakkeKey* key)
  43568. {
  43569. static const byte pubData[] = {
  43570. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  43571. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  43572. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  43573. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  43574. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  43575. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  43576. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  43577. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  43578. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  43579. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  43580. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  43581. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  43582. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  43583. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  43584. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  43585. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  43586. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  43587. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  43588. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  43589. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  43590. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  43591. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  43592. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  43593. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  43594. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  43595. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  43596. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  43597. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  43598. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  43599. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  43600. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  43601. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  43602. };
  43603. static const byte id[] = {
  43604. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43605. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43606. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43607. 0x33, 0x00
  43608. };
  43609. static const word32 idSz = sizeof(id);
  43610. byte ssv[] = {
  43611. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  43612. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  43613. };
  43614. static const word16 ssvSz = sizeof(ssv);
  43615. static const byte expAuth[] = {
  43616. 0x04,
  43617. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  43618. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  43619. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  43620. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  43621. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  43622. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  43623. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  43624. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  43625. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  43626. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  43627. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  43628. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  43629. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  43630. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  43631. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  43632. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  43633. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  43634. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  43635. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  43636. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  43637. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  43638. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  43639. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  43640. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  43641. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  43642. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  43643. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  43644. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  43645. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  43646. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  43647. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  43648. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  43649. };
  43650. static const byte encSsv[] = {
  43651. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  43652. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  43653. };
  43654. wc_test_ret_t ret;
  43655. byte auth[257];
  43656. word16 authSz = sizeof(auth);
  43657. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  43658. if (ret != 0)
  43659. return WC_TEST_RET_ENC_EC(ret);
  43660. ret = wc_SetSakkeIdentity(key, id, idSz);
  43661. if (ret != 0)
  43662. return WC_TEST_RET_ENC_EC(ret);
  43663. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43664. auth, &authSz);
  43665. if (ret != 0)
  43666. return WC_TEST_RET_ENC_EC(ret);
  43667. if (authSz != 257)
  43668. return WC_TEST_RET_ENC_NC;
  43669. if (XMEMCMP(ssv, encSsv, ssvSz) != 0)
  43670. return WC_TEST_RET_ENC_NC;
  43671. if (XMEMCMP(auth, expAuth, authSz) != 0)
  43672. return WC_TEST_RET_ENC_NC;
  43673. return 0;
  43674. }
  43675. static wc_test_ret_t sakke_make_key_test(SakkeKey* priv, SakkeKey* pub, SakkeKey* key,
  43676. WC_RNG* rng, ecc_point* rsk)
  43677. {
  43678. wc_test_ret_t ret;
  43679. byte data[440];
  43680. byte pubData[257];
  43681. word32 sz;
  43682. char mail[] = "test@wolfssl.com";
  43683. byte* id = (byte*)mail;
  43684. word32 idSz = (word32)XSTRLEN(mail);
  43685. int valid;
  43686. ecc_point* pubKey = rsk;
  43687. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43688. if (ret != 0)
  43689. return WC_TEST_RET_ENC_EC(ret);
  43690. ret = wc_MakeSakkeKey(priv, rng);
  43691. if (ret != 0)
  43692. return WC_TEST_RET_ENC_EC(ret);
  43693. ret = wc_ExportSakkeKey(priv, NULL, &sz);
  43694. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43695. return WC_TEST_RET_ENC_EC(ret);
  43696. if (sz != 384)
  43697. return WC_TEST_RET_ENC_NC;
  43698. sz--;
  43699. ret = wc_ExportSakkeKey(priv, data, &sz);
  43700. if (ret == 0)
  43701. return WC_TEST_RET_ENC_NC;
  43702. sz++;
  43703. ret = wc_ExportSakkeKey(priv, data, &sz);
  43704. if (ret != 0)
  43705. return WC_TEST_RET_ENC_EC(ret);
  43706. if (sz != 384)
  43707. return WC_TEST_RET_ENC_NC;
  43708. ret = wc_ImportSakkeKey(key, data, sz - 1);
  43709. if (ret == 0)
  43710. return WC_TEST_RET_ENC_NC;
  43711. ret = wc_ImportSakkeKey(key, data, sz);
  43712. if (ret != 0)
  43713. return WC_TEST_RET_ENC_EC(ret);
  43714. wc_FreeSakkeKey(key);
  43715. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43716. if (ret != 0)
  43717. return WC_TEST_RET_ENC_EC(ret);
  43718. ret = wc_ExportSakkePrivateKey(priv, NULL, &sz);
  43719. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43720. return WC_TEST_RET_ENC_EC(ret);
  43721. if (sz != 128)
  43722. return WC_TEST_RET_ENC_NC;
  43723. sz--;
  43724. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  43725. if (ret == 0)
  43726. return WC_TEST_RET_ENC_NC;
  43727. sz++;
  43728. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  43729. if (ret != 0)
  43730. return WC_TEST_RET_ENC_EC(ret);
  43731. if (sz != 128)
  43732. return WC_TEST_RET_ENC_NC;
  43733. ret = wc_ImportSakkePrivateKey(key, data, sz - 1);
  43734. if (ret == 0)
  43735. return WC_TEST_RET_ENC_NC;
  43736. ret = wc_ImportSakkePrivateKey(key, data, sz);
  43737. if (ret != 0)
  43738. return WC_TEST_RET_ENC_EC(ret);
  43739. ret = wc_MakeSakkePublicKey(key, pubKey);
  43740. if (ret != 0)
  43741. return WC_TEST_RET_ENC_EC(ret);
  43742. ret = wc_ExportSakkePublicKey(priv, NULL, &sz, 1);
  43743. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43744. return WC_TEST_RET_ENC_EC(ret);
  43745. if (sz != 256)
  43746. return WC_TEST_RET_ENC_NC;
  43747. sz--;
  43748. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  43749. if (ret == 0)
  43750. return WC_TEST_RET_ENC_NC;
  43751. sz++;
  43752. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  43753. if (ret != 0)
  43754. return WC_TEST_RET_ENC_EC(ret);
  43755. if (sz != 256)
  43756. return WC_TEST_RET_ENC_NC;
  43757. ret = wc_ImportSakkePublicKey(pub, data, sz - 1, 1);
  43758. if (ret == 0)
  43759. return WC_TEST_RET_ENC_NC;
  43760. ret = wc_ImportSakkePublicKey(pub, data, sz, 1);
  43761. if (ret != 0)
  43762. return WC_TEST_RET_ENC_EC(ret);
  43763. ret = wc_ExportSakkePublicKey(pub, pubData, &sz, 1);
  43764. if (ret != 0)
  43765. return WC_TEST_RET_ENC_EC(ret);
  43766. if (sz != 256)
  43767. return WC_TEST_RET_ENC_NC;
  43768. if (XMEMCMP(data, pubData, sz) != 0)
  43769. return WC_TEST_RET_ENC_NC;
  43770. ret = wc_MakeSakkeRsk(priv, id, idSz, rsk);
  43771. if (ret != 0)
  43772. return WC_TEST_RET_ENC_EC(ret);
  43773. ret = wc_ValidateSakkeRsk(priv, id, idSz, rsk, &valid);
  43774. if (ret != 0)
  43775. return WC_TEST_RET_ENC_EC(ret);
  43776. if (valid != 1)
  43777. return WC_TEST_RET_ENC_NC;
  43778. ret = wc_ValidateSakkeRsk(pub, id, idSz, rsk, &valid);
  43779. if (ret != 0)
  43780. return WC_TEST_RET_ENC_EC(ret);
  43781. if (valid != 1)
  43782. return WC_TEST_RET_ENC_NC;
  43783. sz = sizeof(data);
  43784. ret = wc_EncodeSakkeRsk(priv, rsk, data, &sz, 1);
  43785. if (ret != 0)
  43786. return WC_TEST_RET_ENC_EC(ret);
  43787. if (sz != 256)
  43788. return WC_TEST_RET_ENC_NC;
  43789. ret = wc_DecodeSakkeRsk(priv, data, sz, rsk);
  43790. if (ret != 0)
  43791. return WC_TEST_RET_ENC_EC(ret);
  43792. sz = sizeof(pubData);
  43793. ret = wc_EncodeSakkeRsk(priv, rsk, pubData, &sz, 0);
  43794. if (ret != 0)
  43795. return WC_TEST_RET_ENC_EC(ret);
  43796. if (sz != sizeof(pubData))
  43797. return WC_TEST_RET_ENC_NC;
  43798. ret = wc_DecodeSakkeRsk(priv, pubData, sz, rsk);
  43799. if (ret != 0)
  43800. return WC_TEST_RET_ENC_EC(ret);
  43801. wc_FreeSakkeKey(key);
  43802. return 0;
  43803. }
  43804. static wc_test_ret_t sakke_op_test(SakkeKey* priv, SakkeKey* pub, WC_RNG* rng,
  43805. ecc_point* rsk)
  43806. {
  43807. wc_test_ret_t ret;
  43808. byte ssv[16];
  43809. word16 ssvSz;
  43810. byte auth[257];
  43811. word16 authSz;
  43812. char mail[] = "test@wolfssl.com";
  43813. byte* id = (byte*)mail;
  43814. word32 idSz = (word32)XSTRLEN(mail);
  43815. byte pointI[256];
  43816. word32 sz;
  43817. ret = wc_GenerateSakkeSSV(pub, rng, NULL, &ssvSz);
  43818. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43819. return WC_TEST_RET_ENC_EC(ret);
  43820. if (ssvSz != 16)
  43821. return WC_TEST_RET_ENC_NC;
  43822. ssvSz += 128;
  43823. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  43824. if (ret == 0)
  43825. return WC_TEST_RET_ENC_NC;
  43826. ssvSz -= 128;
  43827. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  43828. if (ret != 0)
  43829. return WC_TEST_RET_ENC_EC(ret);
  43830. if (ssvSz != 16)
  43831. return WC_TEST_RET_ENC_NC;
  43832. ret = wc_GetSakkeAuthSize(pub, &authSz);
  43833. if (ret != 0)
  43834. return WC_TEST_RET_ENC_EC(ret);
  43835. ret = wc_SetSakkeIdentity(pub, id, idSz);
  43836. if (ret != 0)
  43837. return WC_TEST_RET_ENC_EC(ret);
  43838. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43839. NULL, &authSz);
  43840. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43841. return WC_TEST_RET_ENC_EC(ret);
  43842. if (authSz != 257)
  43843. return WC_TEST_RET_ENC_NC;
  43844. authSz--;
  43845. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43846. auth, &authSz);
  43847. if (ret == 0)
  43848. return WC_TEST_RET_ENC_NC;
  43849. authSz++;
  43850. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43851. auth, &authSz);
  43852. if (ret != 0)
  43853. return WC_TEST_RET_ENC_EC(ret);
  43854. if (authSz != 257)
  43855. return WC_TEST_RET_ENC_NC;
  43856. ret = wc_GetSakkePointI(pub, NULL, &sz);
  43857. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43858. return WC_TEST_RET_ENC_EC(ret);
  43859. if (sz != 256)
  43860. return WC_TEST_RET_ENC_NC;
  43861. ret = wc_GetSakkePointI(pub, pointI, &sz);
  43862. if (ret != 0)
  43863. return WC_TEST_RET_ENC_EC(ret);
  43864. if (sz != 256)
  43865. return WC_TEST_RET_ENC_NC;
  43866. /* Bogus identity - make it check and regenerate I. */
  43867. ret = wc_MakeSakkePointI(pub, ssv, ssvSz);
  43868. if (ret != 0)
  43869. return WC_TEST_RET_ENC_EC(ret);
  43870. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43871. auth, &authSz);
  43872. if (ret != 0)
  43873. return WC_TEST_RET_ENC_EC(ret);
  43874. if (authSz != 257)
  43875. return WC_TEST_RET_ENC_NC;
  43876. ret = wc_SetSakkeRsk(priv, rsk, NULL, 0);
  43877. if (ret != 0)
  43878. return WC_TEST_RET_ENC_EC(ret);
  43879. ret = wc_SetSakkeIdentity(priv, id, idSz);
  43880. if (ret != 0)
  43881. return WC_TEST_RET_ENC_EC(ret);
  43882. authSz--;
  43883. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43884. authSz);
  43885. if (ret == 0)
  43886. return WC_TEST_RET_ENC_NC;
  43887. authSz++;
  43888. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43889. authSz);
  43890. if (ret != 0)
  43891. return WC_TEST_RET_ENC_EC(ret);
  43892. ssv[0] ^= 0x80;
  43893. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43894. authSz);
  43895. if (ret != WC_NO_ERR_TRACE(SAKKE_VERIFY_FAIL_E))
  43896. return WC_TEST_RET_ENC_EC(ret);
  43897. ssv[0] ^= 0x80;
  43898. /* Bogus identity - make it check and regenerate I. */
  43899. ret = wc_MakeSakkePointI(pub, ssv, idSz);
  43900. if (ret != 0)
  43901. return WC_TEST_RET_ENC_EC(ret);
  43902. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43903. authSz);
  43904. if (ret != 0)
  43905. return WC_TEST_RET_ENC_EC(ret);
  43906. return 0;
  43907. }
  43908. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void)
  43909. {
  43910. wc_test_ret_t ret = 0;
  43911. WC_RNG rng;
  43912. int rng_inited = 0;
  43913. SakkeKey* priv = NULL;
  43914. SakkeKey* pub = NULL;
  43915. SakkeKey* key = NULL;
  43916. ecc_point* rsk = NULL;
  43917. WOLFSSL_ENTER("sakke_test");
  43918. priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  43919. DYNAMIC_TYPE_TMP_BUFFER);
  43920. if (priv == NULL)
  43921. ret = WC_TEST_RET_ENC_NC;
  43922. else
  43923. XMEMSET(priv, 0, sizeof(*priv));
  43924. if (ret == 0) {
  43925. pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  43926. DYNAMIC_TYPE_TMP_BUFFER);
  43927. if (pub == NULL)
  43928. ret = WC_TEST_RET_ENC_NC;
  43929. else
  43930. XMEMSET(pub, 0, sizeof(*pub));
  43931. }
  43932. if (ret == 0) {
  43933. key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  43934. DYNAMIC_TYPE_TMP_BUFFER);
  43935. if (key == NULL)
  43936. ret = WC_TEST_RET_ENC_NC;
  43937. else
  43938. XMEMSET(key, 0, sizeof(*key));
  43939. }
  43940. if (ret == 0) {
  43941. #ifndef HAVE_FIPS
  43942. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  43943. #else
  43944. ret = wc_InitRng(&rng);
  43945. #endif
  43946. if (ret == 0)
  43947. rng_inited = 1;
  43948. else
  43949. ret = WC_TEST_RET_ENC_EC(ret);
  43950. }
  43951. if (ret == 0) {
  43952. rsk = wc_ecc_new_point();
  43953. if (rsk == NULL)
  43954. ret = WC_TEST_RET_ENC_NC;
  43955. }
  43956. if (ret == 0) {
  43957. ret = wc_InitSakkeKey(pub, HEAP_HINT, INVALID_DEVID);
  43958. if (ret != 0)
  43959. ret = WC_TEST_RET_ENC_EC(ret);
  43960. }
  43961. if (ret == 0) {
  43962. ret = wc_InitSakkeKey(priv, HEAP_HINT, INVALID_DEVID);
  43963. if (ret != 0)
  43964. ret = WC_TEST_RET_ENC_EC(ret);
  43965. }
  43966. if (ret == 0) {
  43967. ret = sakke_api_test(&rng, key, rsk);
  43968. }
  43969. if (ret == 0) {
  43970. ret = sakke_kat_derive_test(pub, rsk);
  43971. }
  43972. if (ret == 0) {
  43973. ret = sakke_kat_encapsulate_test(pub);
  43974. }
  43975. if (ret == 0) {
  43976. ret = sakke_make_key_test(priv, pub, key, &rng, rsk);
  43977. }
  43978. if (ret == 0) {
  43979. ret = sakke_op_test(priv, pub, &rng, rsk);
  43980. }
  43981. if (rsk != NULL) {
  43982. wc_ecc_forcezero_point(rsk);
  43983. wc_ecc_del_point(rsk);
  43984. }
  43985. if (rng_inited)
  43986. wc_FreeRng(&rng);
  43987. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43988. if (pub != NULL) {
  43989. wc_FreeSakkeKey(pub);
  43990. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43991. }
  43992. if (priv != NULL) {
  43993. wc_FreeSakkeKey(priv);
  43994. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43995. }
  43996. return ret;
  43997. }
  43998. #endif /* WOLFCRYPT_HAVE_SAKKE */
  43999. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  44000. typedef struct CMAC_Test_Case {
  44001. int type;
  44002. int partial;
  44003. const byte* m;
  44004. word32 mSz;
  44005. const byte* k;
  44006. word32 kSz;
  44007. const byte* t;
  44008. word32 tSz;
  44009. } CMAC_Test_Case;
  44010. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void)
  44011. {
  44012. #ifdef WOLFSSL_AES_128
  44013. WOLFSSL_SMALL_STACK_STATIC const byte k128[] =
  44014. {
  44015. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  44016. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  44017. };
  44018. #define KLEN_128 (sizeof(k128))
  44019. #endif
  44020. #ifdef WOLFSSL_AES_192
  44021. WOLFSSL_SMALL_STACK_STATIC const byte k192[] =
  44022. {
  44023. 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
  44024. 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
  44025. 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
  44026. };
  44027. #define KLEN_192 (sizeof(k192))
  44028. #endif
  44029. #ifdef WOLFSSL_AES_256
  44030. WOLFSSL_SMALL_STACK_STATIC const byte k256[] =
  44031. {
  44032. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  44033. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  44034. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  44035. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  44036. };
  44037. #define KLEN_256 (sizeof(k256))
  44038. #endif
  44039. WOLFSSL_SMALL_STACK_STATIC const byte m[] =
  44040. {
  44041. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  44042. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  44043. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  44044. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  44045. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  44046. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  44047. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  44048. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  44049. };
  44050. #define MLEN_0 (0)
  44051. #define MLEN_128 (128/8)
  44052. #define MLEN_320 (320/8)
  44053. #define MLEN_319 (MLEN_320 - 1)
  44054. #define MLEN_512 (512/8)
  44055. #ifdef WOLFSSL_AES_128
  44056. WOLFSSL_SMALL_STACK_STATIC const byte t128_0[] =
  44057. {
  44058. 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
  44059. 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
  44060. };
  44061. WOLFSSL_SMALL_STACK_STATIC const byte t128_128[] =
  44062. {
  44063. 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
  44064. 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
  44065. };
  44066. WOLFSSL_SMALL_STACK_STATIC const byte t128_319[] =
  44067. {
  44068. 0x2c, 0x17, 0x84, 0x4c, 0x93, 0x1c, 0x07, 0x95,
  44069. 0x15, 0x92, 0x73, 0x0a, 0x34, 0xd0, 0xd9, 0xd2
  44070. };
  44071. WOLFSSL_SMALL_STACK_STATIC const byte t128_320[] =
  44072. {
  44073. 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
  44074. 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
  44075. };
  44076. WOLFSSL_SMALL_STACK_STATIC const byte t128_512[] =
  44077. {
  44078. 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
  44079. 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
  44080. };
  44081. #endif
  44082. #ifdef WOLFSSL_AES_192
  44083. WOLFSSL_SMALL_STACK_STATIC const byte t192_0[] =
  44084. {
  44085. 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
  44086. 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
  44087. };
  44088. WOLFSSL_SMALL_STACK_STATIC const byte t192_128[] =
  44089. {
  44090. 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
  44091. 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
  44092. };
  44093. WOLFSSL_SMALL_STACK_STATIC const byte t192_320[] =
  44094. {
  44095. 0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
  44096. 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e
  44097. };
  44098. WOLFSSL_SMALL_STACK_STATIC const byte t192_512[] =
  44099. {
  44100. 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
  44101. 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
  44102. };
  44103. #endif
  44104. #ifdef WOLFSSL_AES_256
  44105. WOLFSSL_SMALL_STACK_STATIC const byte t256_0[] =
  44106. {
  44107. 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
  44108. 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
  44109. };
  44110. WOLFSSL_SMALL_STACK_STATIC const byte t256_128[] =
  44111. {
  44112. 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
  44113. 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
  44114. };
  44115. WOLFSSL_SMALL_STACK_STATIC const byte t256_320[] =
  44116. {
  44117. 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
  44118. 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6
  44119. };
  44120. WOLFSSL_SMALL_STACK_STATIC const byte t256_512[] =
  44121. {
  44122. 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
  44123. 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
  44124. };
  44125. #endif
  44126. const CMAC_Test_Case testCases[] =
  44127. {
  44128. #ifdef WOLFSSL_AES_128
  44129. {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, AES_BLOCK_SIZE},
  44130. {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, AES_BLOCK_SIZE},
  44131. {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, AES_BLOCK_SIZE},
  44132. {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44133. {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44134. #endif
  44135. #ifdef WOLFSSL_AES_192
  44136. {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, AES_BLOCK_SIZE},
  44137. {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, AES_BLOCK_SIZE},
  44138. {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, AES_BLOCK_SIZE},
  44139. {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, AES_BLOCK_SIZE},
  44140. #endif
  44141. #ifdef WOLFSSL_AES_256
  44142. {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, AES_BLOCK_SIZE},
  44143. {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, AES_BLOCK_SIZE},
  44144. {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, AES_BLOCK_SIZE},
  44145. {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, AES_BLOCK_SIZE},
  44146. #endif
  44147. #ifdef WOLFSSL_AES_128
  44148. {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, AES_BLOCK_SIZE}
  44149. #endif
  44150. };
  44151. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44152. Cmac *cmac;
  44153. #else
  44154. Cmac cmac[1];
  44155. #endif
  44156. byte tag[AES_BLOCK_SIZE];
  44157. const CMAC_Test_Case* tc;
  44158. word32 i, tagSz;
  44159. wc_test_ret_t ret;
  44160. WOLFSSL_ENTER("cmac_test");
  44161. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44162. if ((cmac = (Cmac *)XMALLOC(sizeof *cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC)) == NULL)
  44163. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  44164. #endif
  44165. for (i = 0, tc = testCases;
  44166. i < sizeof(testCases)/sizeof(CMAC_Test_Case);
  44167. i++, tc++) {
  44168. XMEMSET(tag, 0, sizeof(tag));
  44169. tagSz = AES_BLOCK_SIZE;
  44170. #if !defined(HAVE_FIPS) || \
  44171. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)
  44172. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44173. #else
  44174. ret = wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL);
  44175. #endif
  44176. if (ret != 0)
  44177. {
  44178. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44179. }
  44180. if (tc->partial) {
  44181. ret = wc_CmacUpdate(cmac, tc->m,
  44182. tc->mSz/2 - tc->partial);
  44183. if (ret != 0)
  44184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44185. ret = wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial,
  44186. tc->mSz/2 + tc->partial);
  44187. if (ret != 0)
  44188. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44189. }
  44190. else {
  44191. ret = wc_CmacUpdate(cmac, tc->m, tc->mSz);
  44192. if (ret != 0)
  44193. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44194. }
  44195. ret = wc_CmacFinal(cmac, tag, &tagSz);
  44196. if (ret != 0)
  44197. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44198. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44199. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44200. XMEMSET(tag, 0, sizeof(tag));
  44201. tagSz = sizeof(tag);
  44202. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44203. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44204. tc->k, tc->kSz, NULL, devId);
  44205. #else
  44206. ret = wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz,
  44207. tc->k, tc->kSz);
  44208. #endif
  44209. if (ret != 0)
  44210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44211. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44212. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44213. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44214. ret = wc_AesCmacVerify_ex(cmac, tc->t, tc->tSz, tc->m, tc->mSz,
  44215. tc->k, tc->kSz, HEAP_HINT, devId);
  44216. #else
  44217. ret = wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz,
  44218. tc->k, tc->kSz);
  44219. #endif
  44220. if (ret != 0)
  44221. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44222. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44223. /* Test that keyless generate with init is the same */
  44224. XMEMSET(tag, 0, sizeof(tag));
  44225. tagSz = sizeof(tag);
  44226. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44227. if (ret != 0) {
  44228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44229. }
  44230. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44231. NULL, 0, HEAP_HINT, devId);
  44232. if (ret != 0) {
  44233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44234. }
  44235. #endif
  44236. }
  44237. ret = 0;
  44238. out:
  44239. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44240. XFREE(cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC);
  44241. #endif
  44242. return ret;
  44243. }
  44244. #endif /* NO_AES && WOLFSSL_CMAC */
  44245. #if defined(WOLFSSL_SIPHASH)
  44246. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44247. /* Test vectors from:
  44248. * https://github.com/veorq/SipHash/blob/master/vectors.h
  44249. */
  44250. static const unsigned char siphash_key[SIPHASH_KEY_SIZE] = {
  44251. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44252. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  44253. };
  44254. static const unsigned char siphash_msg[64] = {
  44255. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44256. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  44257. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  44258. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  44259. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  44260. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  44261. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  44262. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
  44263. };
  44264. static const unsigned char siphash_r8[64][SIPHASH_MAC_SIZE_8] = {
  44265. { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, },
  44266. { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, },
  44267. { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, },
  44268. { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, },
  44269. { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, },
  44270. { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, },
  44271. { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, },
  44272. { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, },
  44273. { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, },
  44274. { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, },
  44275. { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, },
  44276. { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, },
  44277. { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, },
  44278. { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, },
  44279. { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, },
  44280. { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, },
  44281. { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, },
  44282. { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, },
  44283. { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, },
  44284. { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, },
  44285. { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, },
  44286. { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, },
  44287. { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, },
  44288. { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, },
  44289. { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, },
  44290. { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, },
  44291. { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, },
  44292. { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, },
  44293. { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, },
  44294. { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, },
  44295. { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, },
  44296. { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, },
  44297. { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, },
  44298. { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, },
  44299. { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, },
  44300. { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, },
  44301. { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, },
  44302. { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, },
  44303. { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, },
  44304. { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, },
  44305. { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, },
  44306. { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, },
  44307. { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, },
  44308. { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, },
  44309. { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, },
  44310. { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, },
  44311. { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, },
  44312. { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, },
  44313. { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, },
  44314. { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, },
  44315. { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, },
  44316. { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, },
  44317. { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, },
  44318. { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, },
  44319. { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, },
  44320. { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, },
  44321. { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, },
  44322. { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, },
  44323. { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, },
  44324. { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, },
  44325. { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, },
  44326. { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, },
  44327. { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, },
  44328. { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, },
  44329. };
  44330. static const unsigned char siphash_r16[64][SIPHASH_MAC_SIZE_16] = {
  44331. { 0xa3, 0x81, 0x7f, 0x04, 0xba, 0x25, 0xa8, 0xe6,
  44332. 0x6d, 0xf6, 0x72, 0x14, 0xc7, 0x55, 0x02, 0x93, },
  44333. { 0xda, 0x87, 0xc1, 0xd8, 0x6b, 0x99, 0xaf, 0x44,
  44334. 0x34, 0x76, 0x59, 0x11, 0x9b, 0x22, 0xfc, 0x45, },
  44335. { 0x81, 0x77, 0x22, 0x8d, 0xa4, 0xa4, 0x5d, 0xc7,
  44336. 0xfc, 0xa3, 0x8b, 0xde, 0xf6, 0x0a, 0xff, 0xe4, },
  44337. { 0x9c, 0x70, 0xb6, 0x0c, 0x52, 0x67, 0xa9, 0x4e,
  44338. 0x5f, 0x33, 0xb6, 0xb0, 0x29, 0x85, 0xed, 0x51, },
  44339. { 0xf8, 0x81, 0x64, 0xc1, 0x2d, 0x9c, 0x8f, 0xaf,
  44340. 0x7d, 0x0f, 0x6e, 0x7c, 0x7b, 0xcd, 0x55, 0x79, },
  44341. { 0x13, 0x68, 0x87, 0x59, 0x80, 0x77, 0x6f, 0x88,
  44342. 0x54, 0x52, 0x7a, 0x07, 0x69, 0x0e, 0x96, 0x27, },
  44343. { 0x14, 0xee, 0xca, 0x33, 0x8b, 0x20, 0x86, 0x13,
  44344. 0x48, 0x5e, 0xa0, 0x30, 0x8f, 0xd7, 0xa1, 0x5e, },
  44345. { 0xa1, 0xf1, 0xeb, 0xbe, 0xd8, 0xdb, 0xc1, 0x53,
  44346. 0xc0, 0xb8, 0x4a, 0xa6, 0x1f, 0xf0, 0x82, 0x39, },
  44347. { 0x3b, 0x62, 0xa9, 0xba, 0x62, 0x58, 0xf5, 0x61,
  44348. 0x0f, 0x83, 0xe2, 0x64, 0xf3, 0x14, 0x97, 0xb4, },
  44349. { 0x26, 0x44, 0x99, 0x06, 0x0a, 0xd9, 0xba, 0xab,
  44350. 0xc4, 0x7f, 0x8b, 0x02, 0xbb, 0x6d, 0x71, 0xed, },
  44351. { 0x00, 0x11, 0x0d, 0xc3, 0x78, 0x14, 0x69, 0x56,
  44352. 0xc9, 0x54, 0x47, 0xd3, 0xf3, 0xd0, 0xfb, 0xba, },
  44353. { 0x01, 0x51, 0xc5, 0x68, 0x38, 0x6b, 0x66, 0x77,
  44354. 0xa2, 0xb4, 0xdc, 0x6f, 0x81, 0xe5, 0xdc, 0x18, },
  44355. { 0xd6, 0x26, 0xb2, 0x66, 0x90, 0x5e, 0xf3, 0x58,
  44356. 0x82, 0x63, 0x4d, 0xf6, 0x85, 0x32, 0xc1, 0x25, },
  44357. { 0x98, 0x69, 0xe2, 0x47, 0xe9, 0xc0, 0x8b, 0x10,
  44358. 0xd0, 0x29, 0x93, 0x4f, 0xc4, 0xb9, 0x52, 0xf7, },
  44359. { 0x31, 0xfc, 0xef, 0xac, 0x66, 0xd7, 0xde, 0x9c,
  44360. 0x7e, 0xc7, 0x48, 0x5f, 0xe4, 0x49, 0x49, 0x02, },
  44361. { 0x54, 0x93, 0xe9, 0x99, 0x33, 0xb0, 0xa8, 0x11,
  44362. 0x7e, 0x08, 0xec, 0x0f, 0x97, 0xcf, 0xc3, 0xd9, },
  44363. { 0x6e, 0xe2, 0xa4, 0xca, 0x67, 0xb0, 0x54, 0xbb,
  44364. 0xfd, 0x33, 0x15, 0xbf, 0x85, 0x23, 0x05, 0x77, },
  44365. { 0x47, 0x3d, 0x06, 0xe8, 0x73, 0x8d, 0xb8, 0x98,
  44366. 0x54, 0xc0, 0x66, 0xc4, 0x7a, 0xe4, 0x77, 0x40, },
  44367. { 0xa4, 0x26, 0xe5, 0xe4, 0x23, 0xbf, 0x48, 0x85,
  44368. 0x29, 0x4d, 0xa4, 0x81, 0xfe, 0xae, 0xf7, 0x23, },
  44369. { 0x78, 0x01, 0x77, 0x31, 0xcf, 0x65, 0xfa, 0xb0,
  44370. 0x74, 0xd5, 0x20, 0x89, 0x52, 0x51, 0x2e, 0xb1, },
  44371. { 0x9e, 0x25, 0xfc, 0x83, 0x3f, 0x22, 0x90, 0x73,
  44372. 0x3e, 0x93, 0x44, 0xa5, 0xe8, 0x38, 0x39, 0xeb, },
  44373. { 0x56, 0x8e, 0x49, 0x5a, 0xbe, 0x52, 0x5a, 0x21,
  44374. 0x8a, 0x22, 0x14, 0xcd, 0x3e, 0x07, 0x1d, 0x12, },
  44375. { 0x4a, 0x29, 0xb5, 0x45, 0x52, 0xd1, 0x6b, 0x9a,
  44376. 0x46, 0x9c, 0x10, 0x52, 0x8e, 0xff, 0x0a, 0xae, },
  44377. { 0xc9, 0xd1, 0x84, 0xdd, 0xd5, 0xa9, 0xf5, 0xe0,
  44378. 0xcf, 0x8c, 0xe2, 0x9a, 0x9a, 0xbf, 0x69, 0x1c, },
  44379. { 0x2d, 0xb4, 0x79, 0xae, 0x78, 0xbd, 0x50, 0xd8,
  44380. 0x88, 0x2a, 0x8a, 0x17, 0x8a, 0x61, 0x32, 0xad, },
  44381. { 0x8e, 0xce, 0x5f, 0x04, 0x2d, 0x5e, 0x44, 0x7b,
  44382. 0x50, 0x51, 0xb9, 0xea, 0xcb, 0x8d, 0x8f, 0x6f, },
  44383. { 0x9c, 0x0b, 0x53, 0xb4, 0xb3, 0xc3, 0x07, 0xe8,
  44384. 0x7e, 0xae, 0xe0, 0x86, 0x78, 0x14, 0x1f, 0x66, },
  44385. { 0xab, 0xf2, 0x48, 0xaf, 0x69, 0xa6, 0xea, 0xe4,
  44386. 0xbf, 0xd3, 0xeb, 0x2f, 0x12, 0x9e, 0xeb, 0x94, },
  44387. { 0x06, 0x64, 0xda, 0x16, 0x68, 0x57, 0x4b, 0x88,
  44388. 0xb9, 0x35, 0xf3, 0x02, 0x73, 0x58, 0xae, 0xf4, },
  44389. { 0xaa, 0x4b, 0x9d, 0xc4, 0xbf, 0x33, 0x7d, 0xe9,
  44390. 0x0c, 0xd4, 0xfd, 0x3c, 0x46, 0x7c, 0x6a, 0xb7, },
  44391. { 0xea, 0x5c, 0x7f, 0x47, 0x1f, 0xaf, 0x6b, 0xde,
  44392. 0x2b, 0x1a, 0xd7, 0xd4, 0x68, 0x6d, 0x22, 0x87, },
  44393. { 0x29, 0x39, 0xb0, 0x18, 0x32, 0x23, 0xfa, 0xfc,
  44394. 0x17, 0x23, 0xde, 0x4f, 0x52, 0xc4, 0x3d, 0x35, },
  44395. { 0x7c, 0x39, 0x56, 0xca, 0x5e, 0xea, 0xfc, 0x3e,
  44396. 0x36, 0x3e, 0x9d, 0x55, 0x65, 0x46, 0xeb, 0x68, },
  44397. { 0x77, 0xc6, 0x07, 0x71, 0x46, 0xf0, 0x1c, 0x32,
  44398. 0xb6, 0xb6, 0x9d, 0x5f, 0x4e, 0xa9, 0xff, 0xcf, },
  44399. { 0x37, 0xa6, 0x98, 0x6c, 0xb8, 0x84, 0x7e, 0xdf,
  44400. 0x09, 0x25, 0xf0, 0xf1, 0x30, 0x9b, 0x54, 0xde, },
  44401. { 0xa7, 0x05, 0xf0, 0xe6, 0x9d, 0xa9, 0xa8, 0xf9,
  44402. 0x07, 0x24, 0x1a, 0x2e, 0x92, 0x3c, 0x8c, 0xc8, },
  44403. { 0x3d, 0xc4, 0x7d, 0x1f, 0x29, 0xc4, 0x48, 0x46,
  44404. 0x1e, 0x9e, 0x76, 0xed, 0x90, 0x4f, 0x67, 0x11, },
  44405. { 0x0d, 0x62, 0xbf, 0x01, 0xe6, 0xfc, 0x0e, 0x1a,
  44406. 0x0d, 0x3c, 0x47, 0x51, 0xc5, 0xd3, 0x69, 0x2b, },
  44407. { 0x8c, 0x03, 0x46, 0x8b, 0xca, 0x7c, 0x66, 0x9e,
  44408. 0xe4, 0xfd, 0x5e, 0x08, 0x4b, 0xbe, 0xe7, 0xb5, },
  44409. { 0x52, 0x8a, 0x5b, 0xb9, 0x3b, 0xaf, 0x2c, 0x9c,
  44410. 0x44, 0x73, 0xcc, 0xe5, 0xd0, 0xd2, 0x2b, 0xd9, },
  44411. { 0xdf, 0x6a, 0x30, 0x1e, 0x95, 0xc9, 0x5d, 0xad,
  44412. 0x97, 0xae, 0x0c, 0xc8, 0xc6, 0x91, 0x3b, 0xd8, },
  44413. { 0x80, 0x11, 0x89, 0x90, 0x2c, 0x85, 0x7f, 0x39,
  44414. 0xe7, 0x35, 0x91, 0x28, 0x5e, 0x70, 0xb6, 0xdb, },
  44415. { 0xe6, 0x17, 0x34, 0x6a, 0xc9, 0xc2, 0x31, 0xbb,
  44416. 0x36, 0x50, 0xae, 0x34, 0xcc, 0xca, 0x0c, 0x5b, },
  44417. { 0x27, 0xd9, 0x34, 0x37, 0xef, 0xb7, 0x21, 0xaa,
  44418. 0x40, 0x18, 0x21, 0xdc, 0xec, 0x5a, 0xdf, 0x89, },
  44419. { 0x89, 0x23, 0x7d, 0x9d, 0xed, 0x9c, 0x5e, 0x78,
  44420. 0xd8, 0xb1, 0xc9, 0xb1, 0x66, 0xcc, 0x73, 0x42, },
  44421. { 0x4a, 0x6d, 0x80, 0x91, 0xbf, 0x5e, 0x7d, 0x65,
  44422. 0x11, 0x89, 0xfa, 0x94, 0xa2, 0x50, 0xb1, 0x4c, },
  44423. { 0x0e, 0x33, 0xf9, 0x60, 0x55, 0xe7, 0xae, 0x89,
  44424. 0x3f, 0xfc, 0x0e, 0x3d, 0xcf, 0x49, 0x29, 0x02, },
  44425. { 0xe6, 0x1c, 0x43, 0x2b, 0x72, 0x0b, 0x19, 0xd1,
  44426. 0x8e, 0xc8, 0xd8, 0x4b, 0xdc, 0x63, 0x15, 0x1b, },
  44427. { 0xf7, 0xe5, 0xae, 0xf5, 0x49, 0xf7, 0x82, 0xcf,
  44428. 0x37, 0x90, 0x55, 0xa6, 0x08, 0x26, 0x9b, 0x16, },
  44429. { 0x43, 0x8d, 0x03, 0x0f, 0xd0, 0xb7, 0xa5, 0x4f,
  44430. 0xa8, 0x37, 0xf2, 0xad, 0x20, 0x1a, 0x64, 0x03, },
  44431. { 0xa5, 0x90, 0xd3, 0xee, 0x4f, 0xbf, 0x04, 0xe3,
  44432. 0x24, 0x7e, 0x0d, 0x27, 0xf2, 0x86, 0x42, 0x3f, },
  44433. { 0x5f, 0xe2, 0xc1, 0xa1, 0x72, 0xfe, 0x93, 0xc4,
  44434. 0xb1, 0x5c, 0xd3, 0x7c, 0xae, 0xf9, 0xf5, 0x38, },
  44435. { 0x2c, 0x97, 0x32, 0x5c, 0xbd, 0x06, 0xb3, 0x6e,
  44436. 0xb2, 0x13, 0x3d, 0xd0, 0x8b, 0x3a, 0x01, 0x7c, },
  44437. { 0x92, 0xc8, 0x14, 0x22, 0x7a, 0x6b, 0xca, 0x94,
  44438. 0x9f, 0xf0, 0x65, 0x9f, 0x00, 0x2a, 0xd3, 0x9e, },
  44439. { 0xdc, 0xe8, 0x50, 0x11, 0x0b, 0xd8, 0x32, 0x8c,
  44440. 0xfb, 0xd5, 0x08, 0x41, 0xd6, 0x91, 0x1d, 0x87, },
  44441. { 0x67, 0xf1, 0x49, 0x84, 0xc7, 0xda, 0x79, 0x12,
  44442. 0x48, 0xe3, 0x2b, 0xb5, 0x92, 0x25, 0x83, 0xda, },
  44443. { 0x19, 0x38, 0xf2, 0xcf, 0x72, 0xd5, 0x4e, 0xe9,
  44444. 0x7e, 0x94, 0x16, 0x6f, 0xa9, 0x1d, 0x2a, 0x36, },
  44445. { 0x74, 0x48, 0x1e, 0x96, 0x46, 0xed, 0x49, 0xfe,
  44446. 0x0f, 0x62, 0x24, 0x30, 0x16, 0x04, 0x69, 0x8e, },
  44447. { 0x57, 0xfc, 0xa5, 0xde, 0x98, 0xa9, 0xd6, 0xd8,
  44448. 0x00, 0x64, 0x38, 0xd0, 0x58, 0x3d, 0x8a, 0x1d, },
  44449. { 0x9f, 0xec, 0xde, 0x1c, 0xef, 0xdc, 0x1c, 0xbe,
  44450. 0xd4, 0x76, 0x36, 0x74, 0xd9, 0x57, 0x53, 0x59, },
  44451. { 0xe3, 0x04, 0x0c, 0x00, 0xeb, 0x28, 0xf1, 0x53,
  44452. 0x66, 0xca, 0x73, 0xcb, 0xd8, 0x72, 0xe7, 0x40, },
  44453. { 0x76, 0x97, 0x00, 0x9a, 0x6a, 0x83, 0x1d, 0xfe,
  44454. 0xcc, 0xa9, 0x1c, 0x59, 0x93, 0x67, 0x0f, 0x7a, },
  44455. { 0x58, 0x53, 0x54, 0x23, 0x21, 0xf5, 0x67, 0xa0,
  44456. 0x05, 0xd5, 0x47, 0xa4, 0xf0, 0x47, 0x59, 0xbd, },
  44457. { 0x51, 0x50, 0xd1, 0x77, 0x2f, 0x50, 0x83, 0x4a,
  44458. 0x50, 0x3e, 0x06, 0x9a, 0x97, 0x3f, 0xbd, 0x7c, },
  44459. };
  44460. #endif
  44461. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void)
  44462. {
  44463. wc_test_ret_t ret = 0;
  44464. int i;
  44465. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44466. unsigned char res[SIPHASH_MAC_SIZE_16];
  44467. unsigned char tmp[SIPHASH_MAC_SIZE_8];
  44468. SipHash siphash;
  44469. WOLFSSL_ENTER("siphash_test (1)");
  44470. for (i = 0; i < 64; i++) {
  44471. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44472. if (ret != 0)
  44473. return WC_TEST_RET_ENC_I(i);
  44474. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  44475. if (ret != 0)
  44476. return WC_TEST_RET_ENC_I(i);
  44477. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  44478. if (ret != 0)
  44479. return WC_TEST_RET_ENC_I(i);
  44480. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  44481. return WC_TEST_RET_ENC_I(i);
  44482. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_8);
  44483. if (ret != 0)
  44484. return WC_TEST_RET_ENC_I(i);
  44485. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  44486. return WC_TEST_RET_ENC_I(i);
  44487. }
  44488. for (i = 0; i < 64; i++) {
  44489. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_16);
  44490. if (ret != 0)
  44491. return WC_TEST_RET_ENC_I(i);
  44492. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  44493. if (ret != 0)
  44494. return WC_TEST_RET_ENC_I(i);
  44495. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  44496. if (ret != 0)
  44497. return WC_TEST_RET_ENC_I(i);
  44498. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  44499. return WC_TEST_RET_ENC_I(i);
  44500. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_16);
  44501. if (ret != 0)
  44502. return WC_TEST_RET_ENC_I(i);
  44503. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  44504. return WC_TEST_RET_ENC_I(i);
  44505. }
  44506. #else
  44507. WOLFSSL_ENTER("siphash_test (1)");
  44508. #endif
  44509. /* Testing bad parameters. */
  44510. ret = wc_InitSipHash(NULL, NULL, SIPHASH_MAC_SIZE_8);
  44511. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44512. return WC_TEST_RET_ENC_EC(ret);
  44513. ret = wc_InitSipHash(NULL, siphash_key, SIPHASH_MAC_SIZE_8);
  44514. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44515. return WC_TEST_RET_ENC_EC(ret);
  44516. ret = wc_InitSipHash(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  44517. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44518. return WC_TEST_RET_ENC_EC(ret);
  44519. ret = wc_InitSipHash(&siphash, siphash_key, 7);
  44520. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44521. return WC_TEST_RET_ENC_EC(ret);
  44522. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44523. if (ret != 0)
  44524. return WC_TEST_RET_ENC_EC(ret);
  44525. ret = wc_SipHashUpdate(NULL, NULL, 0);
  44526. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44527. return WC_TEST_RET_ENC_EC(ret);
  44528. ret = wc_SipHashUpdate(&siphash, NULL, 1);
  44529. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44530. return WC_TEST_RET_ENC_EC(ret);
  44531. ret = wc_SipHashFinal(NULL, NULL, SIPHASH_MAC_SIZE_8);
  44532. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44533. return WC_TEST_RET_ENC_EC(ret);
  44534. ret = wc_SipHashFinal(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  44535. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44536. return WC_TEST_RET_ENC_EC(ret);
  44537. ret = wc_SipHashFinal(NULL, res, SIPHASH_MAC_SIZE_8);
  44538. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44539. return WC_TEST_RET_ENC_EC(ret);
  44540. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  44541. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44542. return WC_TEST_RET_ENC_EC(ret);
  44543. ret = wc_SipHash(NULL, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  44544. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44545. return WC_TEST_RET_ENC_EC(ret);
  44546. ret = wc_SipHash(siphash_key, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  44547. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44548. return WC_TEST_RET_ENC_EC(ret);
  44549. ret = wc_SipHash(NULL, NULL, 0, res, SIPHASH_MAC_SIZE_16);
  44550. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44551. return WC_TEST_RET_ENC_EC(ret);
  44552. ret = wc_SipHash(siphash_key, NULL, 0, res, 15);
  44553. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44554. return WC_TEST_RET_ENC_EC(ret);
  44555. ret = wc_SipHash(siphash_key, NULL, 1, res, SIPHASH_MAC_SIZE_16);
  44556. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44557. return WC_TEST_RET_ENC_EC(ret);
  44558. /* Test cache with multiple non blocksize bytes */
  44559. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44560. if (ret != 0)
  44561. return WC_TEST_RET_ENC_EC(ret);
  44562. ret = wc_SipHashUpdate(&siphash, siphash_msg, 5);
  44563. if (ret != 0)
  44564. return WC_TEST_RET_ENC_EC(ret);
  44565. ret = wc_SipHashUpdate(&siphash, siphash_msg + 5, 4);
  44566. if (ret != 0)
  44567. return WC_TEST_RET_ENC_EC(ret);
  44568. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  44569. if (ret != 0)
  44570. return WC_TEST_RET_ENC_EC(ret);
  44571. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44572. if (ret != 0)
  44573. return WC_TEST_RET_ENC_EC(ret);
  44574. ret = wc_SipHashUpdate(&siphash, siphash_msg, 9);
  44575. if (ret != 0)
  44576. return WC_TEST_RET_ENC_EC(ret);
  44577. ret = wc_SipHashFinal(&siphash, tmp, SIPHASH_MAC_SIZE_8);
  44578. if (ret != 0)
  44579. return WC_TEST_RET_ENC_EC(ret);
  44580. if (XMEMCMP(res, tmp, SIPHASH_MAC_SIZE_8) != 0)
  44581. return WC_TEST_RET_ENC_NC;
  44582. return 0;
  44583. }
  44584. #endif /* WOLFSSL_SIPHASH */
  44585. #ifdef HAVE_LIBZ
  44586. static const byte sample_text[] =
  44587. "Biodiesel cupidatat marfa, cliche aute put a bird on it incididunt elit\n"
  44588. "polaroid. Sunt tattooed bespoke reprehenderit. Sint twee organic id\n"
  44589. "marfa. Commodo veniam ad esse gastropub. 3 wolf moon sartorial vero,\n"
  44590. "plaid delectus biodiesel squid +1 vice. Post-ironic keffiyeh leggings\n"
  44591. "selfies cray fap hoodie, forage anim. Carles cupidatat shoreditch, VHS\n"
  44592. "small batch meggings kogi dolore food truck bespoke gastropub.\n"
  44593. "\n"
  44594. "Terry richardson adipisicing actually typewriter tumblr, twee whatever\n"
  44595. "four loko you probably haven't heard of them high life. Messenger bag\n"
  44596. "whatever tattooed deep v mlkshk. Brooklyn pinterest assumenda chillwave\n"
  44597. "et, banksy ullamco messenger bag umami pariatur direct trade forage.\n"
  44598. "Typewriter culpa try-hard, pariatur sint brooklyn meggings. Gentrify\n"
  44599. "food truck next level, tousled irony non semiotics PBR ethical anim cred\n"
  44600. "readymade. Mumblecore brunch lomo odd future, portland organic terry\n"
  44601. "richardson elit leggings adipisicing ennui raw denim banjo hella. Godard\n"
  44602. "mixtape polaroid, pork belly readymade organic cray typewriter helvetica\n"
  44603. "four loko whatever street art yr farm-to-table.\n"
  44604. "\n"
  44605. "Vinyl keytar vice tofu. Locavore you probably haven't heard of them pug\n"
  44606. "pickled, hella tonx labore truffaut DIY mlkshk elit cosby sweater sint\n"
  44607. "et mumblecore. Elit swag semiotics, reprehenderit DIY sartorial nisi ugh\n"
  44608. "nesciunt pug pork belly wayfarers selfies delectus. Ethical hoodie\n"
  44609. "seitan fingerstache kale chips. Terry richardson artisan williamsburg,\n"
  44610. "eiusmod fanny pack irony tonx ennui lo-fi incididunt tofu YOLO\n"
  44611. "readymade. 8-bit sed ethnic beard officia. Pour-over iphone DIY butcher,\n"
  44612. "ethnic art party qui letterpress nisi proident jean shorts mlkshk\n"
  44613. "locavore.\n"
  44614. "\n"
  44615. "Narwhal flexitarian letterpress, do gluten-free voluptate next level\n"
  44616. "banh mi tonx incididunt carles DIY. Odd future nulla 8-bit beard ut\n"
  44617. "cillum pickled velit, YOLO officia you probably haven't heard of them\n"
  44618. "trust fund gastropub. Nisi adipisicing tattooed, Austin mlkshk 90's\n"
  44619. "small batch american apparel. Put a bird on it cosby sweater before they\n"
  44620. "sold out pork belly kogi hella. Street art mollit sustainable polaroid,\n"
  44621. "DIY ethnic ea pug beard dreamcatcher cosby sweater magna scenester nisi.\n"
  44622. "Sed pork belly skateboard mollit, labore proident eiusmod. Sriracha\n"
  44623. "excepteur cosby sweater, anim deserunt laborum eu aliquip ethical et\n"
  44624. "neutra PBR selvage.\n"
  44625. "\n"
  44626. "Raw denim pork belly truffaut, irony plaid sustainable put a bird on it\n"
  44627. "next level jean shorts exercitation. Hashtag keytar whatever, nihil\n"
  44628. "authentic aliquip disrupt laborum. Tattooed selfies deserunt trust fund\n"
  44629. "wayfarers. 3 wolf moon synth church-key sartorial, gastropub leggings\n"
  44630. "tattooed. Labore high life commodo, meggings raw denim fingerstache pug\n"
  44631. "trust fund leggings seitan forage. Nostrud ullamco duis, reprehenderit\n"
  44632. "incididunt flannel sustainable helvetica pork belly pug banksy you\n"
  44633. "probably haven't heard of them nesciunt farm-to-table. Disrupt nostrud\n"
  44634. "mollit magna, sriracha sartorial helvetica.\n"
  44635. "\n"
  44636. "Nulla kogi reprehenderit, skateboard sustainable duis adipisicing viral\n"
  44637. "ad fanny pack salvia. Fanny pack trust fund you probably haven't heard\n"
  44638. "of them YOLO vice nihil. Keffiyeh cray lo-fi pinterest cardigan aliqua,\n"
  44639. "reprehenderit aute. Culpa tousled williamsburg, marfa lomo actually anim\n"
  44640. "skateboard. Iphone aliqua ugh, semiotics pariatur vero readymade\n"
  44641. "organic. Marfa squid nulla, in laborum disrupt laboris irure gastropub.\n"
  44642. "Veniam sunt food truck leggings, sint vinyl fap.\n"
  44643. "\n"
  44644. "Hella dolore pork belly, truffaut carles you probably haven't heard of\n"
  44645. "them PBR helvetica in sapiente. Fashion axe ugh bushwick american\n"
  44646. "apparel. Fingerstache sed iphone, jean shorts blue bottle nisi bushwick\n"
  44647. "flexitarian officia veniam plaid bespoke fap YOLO lo-fi. Blog\n"
  44648. "letterpress mumblecore, food truck id cray brooklyn cillum ad sed.\n"
  44649. "Assumenda chambray wayfarers vinyl mixtape sustainable. VHS vinyl\n"
  44650. "delectus, culpa williamsburg polaroid cliche swag church-key synth kogi\n"
  44651. "magna pop-up literally. Swag thundercats ennui shoreditch vegan\n"
  44652. "pitchfork neutra truffaut etsy, sed single-origin coffee craft beer.\n"
  44653. "\n"
  44654. "Odio letterpress brooklyn elit. Nulla single-origin coffee in occaecat\n"
  44655. "meggings. Irony meggings 8-bit, chillwave lo-fi adipisicing cred\n"
  44656. "dreamcatcher veniam. Put a bird on it irony umami, trust fund bushwick\n"
  44657. "locavore kale chips. Sriracha swag thundercats, chillwave disrupt\n"
  44658. "tousled beard mollit mustache leggings portland next level. Nihil esse\n"
  44659. "est, skateboard art party etsy thundercats sed dreamcatcher ut iphone\n"
  44660. "swag consectetur et. Irure skateboard banjo, nulla deserunt messenger\n"
  44661. "bag dolor terry richardson sapiente.\n";
  44662. static const byte sample_text_gz[] = {
  44663. 0x1F, 0x8B, 0x08, 0x08, 0xC5, 0x49, 0xB5, 0x5B, 0x00, 0x03, 0x63, 0x69, 0x70,
  44664. 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x8D,
  44665. 0x58, 0xCB, 0x92, 0xE4, 0xB6, 0x11, 0xBC, 0xE3, 0x2B, 0xEA, 0xA6, 0x83, 0xD9,
  44666. 0x1D, 0x72, 0xF8, 0x22, 0x1F, 0xB5, 0x96, 0xA5, 0xDD, 0x90, 0xBC, 0xAB, 0xD0,
  44667. 0x28, 0x36, 0x42, 0x47, 0x90, 0x2C, 0x36, 0xA1, 0x06, 0x09, 0x0A, 0x8F, 0xEE,
  44668. 0xE1, 0xDF, 0x3B, 0x0B, 0xE0, 0x73, 0x2C, 0x4B, 0xBA, 0xCD, 0xCE, 0x80, 0x78,
  44669. 0x64, 0x65, 0x65, 0x66, 0xED, 0x3B, 0xE3, 0x5A, 0xC3, 0x81, 0x2D, 0x35, 0x69,
  44670. 0x32, 0xAD, 0x8E, 0x3A, 0xD2, 0xA0, 0x7D, 0xA7, 0x2B, 0x6A, 0xAC, 0x69, 0x7A,
  44671. 0x26, 0x9D, 0x22, 0xD3, 0x94, 0x22, 0x69, 0xAA, 0x8D, 0x6F, 0xC9, 0x8D, 0x64,
  44672. 0x22, 0x99, 0xB1, 0x31, 0xAD, 0x69, 0xD3, 0x18, 0x89, 0xAD, 0x89, 0x6A, 0x72,
  44673. 0x56, 0x7B, 0x67, 0xDA, 0x2B, 0xBD, 0xC8, 0xEF, 0xB0, 0x4D, 0x74, 0x8E, 0x5B,
  44674. 0xAA, 0x39, 0x4C, 0xEE, 0xCE, 0xE4, 0x79, 0xF2, 0xDC, 0xF3, 0xD8, 0xB2, 0x37,
  44675. 0x11, 0x8B, 0x8C, 0x2C, 0x7A, 0x32, 0x93, 0xF3, 0x37, 0x3D, 0x9A, 0x86, 0x4C,
  44676. 0xAB, 0xF2, 0xB9, 0x57, 0xFA, 0x97, 0x1B, 0x06, 0xD7, 0x3A, 0x7A, 0xF0, 0x68,
  44677. 0xF4, 0x40, 0xBA, 0x25, 0x0E, 0x81, 0xE9, 0xA6, 0x43, 0xF4, 0x6E, 0x4A, 0xF5,
  44678. 0x95, 0xFE, 0x41, 0x4F, 0x67, 0x3B, 0x1A, 0x1C, 0xEE, 0x12, 0xB4, 0x8F, 0xCE,
  44679. 0x1B, 0x6D, 0xB1, 0xDE, 0xBB, 0x4A, 0x4D, 0x56, 0x9B, 0x96, 0x5A, 0xB6, 0xDC,
  44680. 0xC4, 0x14, 0x70, 0xE5, 0xF5, 0x7D, 0xE1, 0xB7, 0x84, 0x3F, 0xFC, 0xED, 0xEF,
  44681. 0xF4, 0x30, 0x0D, 0x5F, 0xE9, 0x47, 0x17, 0xE2, 0xC5, 0x78, 0x27, 0x67, 0xDF,
  44682. 0xB9, 0xEB, 0xCC, 0xCC, 0x3D, 0x59, 0xBE, 0xDD, 0xCC, 0x78, 0x0B, 0x0A, 0x1F,
  44683. 0x74, 0xF8, 0x8C, 0x1A, 0xAF, 0x67, 0xEA, 0xF4, 0x44, 0xBD, 0x93, 0x7D, 0x2A,
  44684. 0xEA, 0x9C, 0xD7, 0x37, 0x80, 0x32, 0x9A, 0x01, 0x37, 0xD5, 0xDE, 0xCA, 0xA2,
  44685. 0x0D, 0xB9, 0xD0, 0x3B, 0xCF, 0xAD, 0x89, 0x4D, 0x5F, 0xD1, 0xE7, 0xF7, 0x2F,
  44686. 0x2A, 0x0C, 0xDA, 0x5A, 0xAA, 0x35, 0x7E, 0x41, 0xC3, 0xB2, 0x37, 0xDD, 0xDD,
  44687. 0xCD, 0x50, 0xEB, 0x2C, 0x96, 0x62, 0x3B, 0xD7, 0x52, 0xF4, 0xA9, 0xB9, 0x6F,
  44688. 0x48, 0xED, 0xEF, 0x54, 0xEA, 0x67, 0xF6, 0x7E, 0x26, 0x8F, 0x3A, 0x68, 0xDF,
  44689. 0x06, 0xBC, 0x56, 0xB7, 0x66, 0x32, 0xC1, 0x34, 0xD8, 0x88, 0x34, 0x1E, 0x88,
  44690. 0xED, 0x67, 0x8A, 0xF3, 0xC4, 0x4F, 0xC0, 0xCA, 0x9E, 0x62, 0x1A, 0x6A, 0xEB,
  44691. 0xAB, 0x02, 0xED, 0xB3, 0xD7, 0x91, 0x81, 0x8A, 0xEA, 0x5C, 0xF2, 0x64, 0xDD,
  44692. 0xDD, 0xD1, 0xEC, 0x12, 0x4D, 0xDE, 0xD5, 0xBA, 0xC6, 0x77, 0xBD, 0x06, 0xC4,
  44693. 0x5F, 0x44, 0xEA, 0x59, 0x4B, 0x5D, 0x3B, 0x8A, 0x3D, 0x0F, 0xD4, 0x9B, 0x1B,
  44694. 0x80, 0x30, 0x1D, 0x30, 0xFA, 0x8F, 0x00, 0x3F, 0xDE, 0xB0, 0x6F, 0xAD, 0x6F,
  44695. 0x6A, 0xDD, 0x6E, 0x2F, 0x6E, 0xCB, 0x3C, 0xD1, 0x83, 0x06, 0x7B, 0x0F, 0xFD,
  44696. 0xFD, 0x4A, 0xEF, 0xBC, 0x73, 0x77, 0x3B, 0x8F, 0x34, 0xA1, 0xBA, 0xEC, 0x39,
  44697. 0x80, 0x33, 0x21, 0xA4, 0x01, 0x55, 0xD7, 0xD4, 0xF4, 0xC6, 0xDA, 0x27, 0x4E,
  44698. 0x54, 0x1C, 0x2B, 0xEC, 0x37, 0xDE, 0xC3, 0x4C, 0xC9, 0x5A, 0x3D, 0x34, 0x0E,
  44699. 0xD8, 0x1C, 0x0E, 0xA2, 0x34, 0xE8, 0xC1, 0xD0, 0xA4, 0x51, 0xD5, 0x88, 0x8B,
  44700. 0xB7, 0xC6, 0xA3, 0x96, 0x40, 0x49, 0xB7, 0xBC, 0xE0, 0x7F, 0x55, 0x3F, 0xEF,
  44701. 0x6F, 0x6E, 0x92, 0x9D, 0x34, 0xFE, 0x3C, 0x5F, 0x04, 0xA5, 0x6A, 0xFF, 0x30,
  44702. 0x08, 0xC9, 0xEA, 0xF5, 0x52, 0x2B, 0xFE, 0x57, 0xFA, 0x8E, 0xC7, 0xE8, 0x4D,
  44703. 0x37, 0xAB, 0x03, 0xFA, 0x23, 0xBF, 0x46, 0x94, 0xFF, 0xC1, 0x16, 0xE0, 0xB9,
  44704. 0x14, 0x2C, 0x9E, 0x27, 0xEC, 0x98, 0x69, 0x14, 0x92, 0xF1, 0x60, 0x5C, 0x34,
  44705. 0x4D, 0xA0, 0x1F, 0xDF, 0xFD, 0x44, 0x1C, 0x7B, 0xD3, 0x80, 0x70, 0x42, 0x02,
  44706. 0x30, 0x84, 0x5B, 0xE5, 0x59, 0xB7, 0xF3, 0x80, 0xFB, 0x01, 0x33, 0xA9, 0x00,
  44707. 0x37, 0x52, 0xDC, 0xDA, 0xA7, 0x11, 0x85, 0xB7, 0x6E, 0x70, 0xE4, 0xDA, 0x96,
  44708. 0xBA, 0x84, 0x5B, 0x81, 0x43, 0x93, 0xF3, 0xD1, 0xEA, 0xB1, 0xDD, 0xB8, 0x1F,
  44709. 0xA5, 0xCC, 0xEA, 0x50, 0x66, 0x69, 0xA9, 0x8D, 0x8C, 0xA7, 0xA2, 0xF3, 0x38,
  44710. 0x26, 0x43, 0x5E, 0x3F, 0x01, 0xBE, 0x1C, 0x0F, 0x20, 0x7F, 0x75, 0xA8, 0x20,
  44711. 0x80, 0xC4, 0xC3, 0x5C, 0x8B, 0x0D, 0xD4, 0x60, 0x5E, 0xA3, 0x9E, 0xD0, 0xB4,
  44712. 0x4B, 0x4F, 0xE6, 0x13, 0x85, 0x60, 0x42, 0x96, 0xED, 0xAA, 0xDB, 0xE9, 0x99,
  44713. 0xE3, 0x07, 0x0E, 0x61, 0xB3, 0x07, 0xE3, 0xB1, 0xFA, 0xC0, 0x9B, 0xAD, 0xF6,
  44714. 0xE0, 0x26, 0x33, 0xEA, 0xEA, 0x23, 0xCD, 0x1E, 0x9D, 0xE1, 0x87, 0x4B, 0x74,
  44715. 0x97, 0x08, 0x3E, 0xA1, 0x28, 0xEA, 0xB3, 0x19, 0x67, 0x8B, 0x76, 0x9A, 0xA3,
  44716. 0xF6, 0xB9, 0xCF, 0x80, 0x65, 0x97, 0xAE, 0xF4, 0x83, 0x6B, 0xF4, 0x43, 0x20,
  44717. 0xF9, 0x0B, 0xFC, 0x9B, 0xD2, 0x4D, 0x4D, 0xA6, 0xB9, 0xA3, 0x02, 0x55, 0x79,
  44718. 0x18, 0x36, 0x19, 0x5F, 0xC9, 0xEA, 0x5A, 0x76, 0x40, 0xB9, 0xBA, 0x0E, 0x9A,
  44719. 0x44, 0xDF, 0x7C, 0xF8, 0x65, 0x61, 0x5E, 0x81, 0xAB, 0x71, 0xA1, 0x9E, 0x29,
  44720. 0x3C, 0x59, 0xCB, 0x23, 0xA4, 0xF6, 0x60, 0x1A, 0x0D, 0x5B, 0x39, 0xAE, 0xF4,
  44721. 0x6F, 0x59, 0x16, 0x9E, 0x60, 0xD8, 0x56, 0xCF, 0xEA, 0x2C, 0x4C, 0x79, 0xD3,
  44722. 0x5D, 0x51, 0x46, 0xA0, 0x4E, 0xE9, 0xD6, 0xAB, 0x91, 0x43, 0x63, 0x44, 0xD7,
  44723. 0x70, 0xB9, 0x23, 0x98, 0x4F, 0x3D, 0x03, 0x02, 0xF6, 0x81, 0x56, 0xC1, 0x58,
  44724. 0x85, 0x07, 0xA7, 0x2D, 0x2C, 0x29, 0xCA, 0x01, 0x45, 0x31, 0x51, 0x8F, 0xD4,
  44725. 0x19, 0xA1, 0x79, 0x88, 0x5A, 0xA4, 0xF5, 0xAE, 0x2D, 0x4B, 0x63, 0x4C, 0x58,
  44726. 0xFE, 0xBF, 0xAD, 0xEE, 0xA3, 0x09, 0xF8, 0xE2, 0x89, 0xBE, 0x81, 0x0E, 0x86,
  44727. 0x3A, 0xF9, 0x5B, 0xA5, 0xD8, 0xA4, 0x00, 0x75, 0x04, 0xF2, 0x23, 0xB8, 0x39,
  44728. 0x69, 0x50, 0xB7, 0xD0, 0x34, 0x63, 0x54, 0xD8, 0x61, 0xDD, 0xA5, 0x33, 0x47,
  44729. 0x85, 0x96, 0x22, 0xD0, 0x2F, 0x9F, 0x7E, 0xF8, 0x74, 0x24, 0xEA, 0x57, 0x97,
  44730. 0x5A, 0xE0, 0x00, 0xCF, 0xC1, 0x67, 0xE1, 0x41, 0xBD, 0x94, 0xA1, 0x03, 0xD3,
  44731. 0xB4, 0x08, 0x64, 0xF2, 0x17, 0x27, 0x35, 0x37, 0x53, 0xEF, 0x46, 0xCE, 0xD8,
  44732. 0xD4, 0x09, 0x52, 0xC6, 0x1E, 0xF7, 0x28, 0xDF, 0x08, 0x0F, 0xD0, 0x6F, 0x71,
  44733. 0xA6, 0xDF, 0xE4, 0x60, 0x8E, 0xC0, 0x1E, 0x78, 0x86, 0x50, 0xB0, 0x9B, 0x84,
  44734. 0x7E, 0xE8, 0x36, 0xFA, 0x95, 0xF1, 0x12, 0x51, 0xC7, 0x18, 0x96, 0xA2, 0x29,
  44735. 0xBB, 0x70, 0x02, 0xB4, 0xF9, 0xA8, 0x3D, 0x08, 0x66, 0xA9, 0xB3, 0xFC, 0x0A,
  44736. 0x94, 0x80, 0xFD, 0x78, 0xDC, 0xAB, 0x82, 0x5A, 0xD2, 0xCD, 0xC2, 0x87, 0xC6,
  44737. 0x4B, 0x07, 0xFA, 0xD1, 0xC3, 0xD9, 0x34, 0x41, 0x85, 0xF8, 0xD0, 0xB6, 0x0A,
  44738. 0x9D, 0x00, 0x91, 0x35, 0x05, 0x88, 0xC3, 0xE3, 0x9B, 0x22, 0xD2, 0xB8, 0xFD,
  44739. 0x95, 0x3E, 0x6D, 0x5D, 0x48, 0xA3, 0x68, 0xCF, 0x02, 0x42, 0x79, 0x79, 0x8A,
  44740. 0xAA, 0x01, 0xD6, 0x09, 0x14, 0x2C, 0xF4, 0x83, 0xA3, 0x80, 0x31, 0x55, 0x46,
  44741. 0x6E, 0xC5, 0xE5, 0x2F, 0x30, 0x58, 0x81, 0xA2, 0x90, 0xBE, 0x2E, 0xA1, 0xC3,
  44742. 0x0F, 0xA6, 0xF5, 0x51, 0x00, 0x39, 0xB6, 0xF2, 0x2A, 0xA3, 0x15, 0x7D, 0x8D,
  44743. 0xF5, 0x66, 0x5C, 0xD9, 0xFC, 0xCF, 0x2F, 0xBF, 0x08, 0x27, 0xE7, 0xD0, 0x03,
  44744. 0xB8, 0xD9, 0x00, 0x13, 0x3D, 0x01, 0x6B, 0xB6, 0xA8, 0xCD, 0x5B, 0x3B, 0x3E,
  44745. 0x93, 0xBF, 0xE6, 0x2E, 0xB7, 0x4A, 0xCF, 0xB3, 0x0A, 0xCE, 0x62, 0x11, 0xD6,
  44746. 0x1F, 0x68, 0x9B, 0x1D, 0x68, 0xD1, 0x8C, 0x97, 0xBD, 0xA1, 0x07, 0x67, 0x73,
  44747. 0x87, 0xE0, 0x36, 0xDA, 0x8C, 0xD2, 0xD2, 0xBB, 0x84, 0x28, 0xA9, 0xFE, 0x52,
  44748. 0x74, 0xD6, 0xB9, 0x0F, 0x0A, 0x6A, 0x2D, 0x28, 0x35, 0x34, 0x3A, 0xD3, 0xE2,
  44749. 0xCD, 0x35, 0x06, 0x7D, 0x1B, 0x35, 0x85, 0x86, 0xD1, 0x3E, 0xF2, 0x6F, 0xA1,
  44750. 0xC4, 0x55, 0xBD, 0x00, 0xD8, 0xC3, 0x5D, 0xC2, 0x1D, 0x6B, 0x6B, 0x27, 0x5B,
  44751. 0x95, 0xF3, 0xAB, 0xB5, 0xD3, 0x37, 0xF2, 0x2C, 0x9C, 0xC7, 0x5D, 0xBD, 0xF1,
  44752. 0x68, 0x1C, 0xAD, 0xF8, 0xB5, 0xE1, 0x29, 0x72, 0x7A, 0x73, 0x62, 0x55, 0x24,
  44753. 0xB9, 0x85, 0xDF, 0x7B, 0x29, 0x7D, 0xDE, 0x08, 0xF5, 0xE4, 0x44, 0xDA, 0x1A,
  44754. 0x30, 0x74, 0xDA, 0xB4, 0x9B, 0x23, 0x9A, 0x3A, 0xC1, 0x53, 0xB2, 0xA2, 0xA3,
  44755. 0x7B, 0x1F, 0xD9, 0x56, 0xD4, 0x4F, 0x9B, 0xB2, 0x1E, 0xEE, 0xB8, 0x6A, 0x4E,
  44756. 0xB5, 0xF4, 0x5A, 0xC9, 0x18, 0x27, 0x9C, 0xDE, 0x14, 0x44, 0xED, 0xC4, 0x3C,
  44757. 0x71, 0x9F, 0x5F, 0xD9, 0x37, 0xA0, 0x78, 0x34, 0x6E, 0xBC, 0xD2, 0x7B, 0x1D,
  44758. 0xFA, 0x08, 0x39, 0x5A, 0x04, 0x73, 0x15, 0xD9, 0x0A, 0x48, 0xC1, 0x2D, 0x15,
  44759. 0x4E, 0x84, 0x30, 0x45, 0x69, 0xB3, 0xE5, 0xF6, 0xAD, 0x09, 0x1E, 0xCC, 0x5F,
  44760. 0x1F, 0x06, 0xD5, 0x58, 0xAD, 0x78, 0xD7, 0x9F, 0xE5, 0xED, 0x3B, 0x09, 0xD5,
  44761. 0xA6, 0x52, 0x6F, 0x92, 0xD3, 0x3C, 0xC6, 0x1E, 0xF2, 0x93, 0x7C, 0xD3, 0x5F,
  44762. 0x70, 0x85, 0x5D, 0xF8, 0xAA, 0x9D, 0xB7, 0x7B, 0x24, 0x5A, 0xE9, 0x0A, 0x35,
  44763. 0x2F, 0xF5, 0xD9, 0x82, 0x02, 0x8A, 0x90, 0x13, 0x5B, 0xB5, 0x67, 0x9C, 0xDD,
  44764. 0xA0, 0x4E, 0x82, 0x27, 0xDA, 0x7E, 0xE8, 0x8E, 0xCD, 0xE1, 0x56, 0x71, 0x2C,
  44765. 0xE6, 0x4E, 0x1F, 0x91, 0xCD, 0x7C, 0x6A, 0xB7, 0x78, 0xD0, 0x26, 0xF3, 0x56,
  44766. 0xA9, 0xD5, 0xA1, 0xC3, 0x3B, 0x98, 0xE9, 0x28, 0x09, 0xEF, 0x50, 0x90, 0xCD,
  44767. 0xC4, 0x8E, 0x75, 0xCC, 0xAC, 0x2D, 0xC9, 0x03, 0x6D, 0xAC, 0xFE, 0xC4, 0x88,
  44768. 0x36, 0xD1, 0x3F, 0xBB, 0x1C, 0x7D, 0xB3, 0x14, 0x61, 0x2C, 0xB7, 0x54, 0x4B,
  44769. 0xDB, 0x64, 0xB6, 0x57, 0x14, 0x16, 0x8E, 0x1E, 0x6C, 0x64, 0xBB, 0x8B, 0x48,
  44770. 0x5D, 0x96, 0x9D, 0xDC, 0x80, 0xA7, 0xF7, 0x54, 0xC7, 0x46, 0x38, 0x3E, 0x44,
  44771. 0xDE, 0x7E, 0x92, 0x8D, 0x07, 0xF6, 0x07, 0x37, 0x4E, 0x16, 0x10, 0xB4, 0x7D,
  44772. 0x88, 0x66, 0x7F, 0xBB, 0xFF, 0xEA, 0x00, 0xF3, 0xFF, 0x97, 0x2C, 0xB5, 0xBE,
  44773. 0x35, 0x4B, 0x5C, 0x36, 0xEC, 0x4C, 0xBD, 0x2B, 0x7D, 0xBF, 0x46, 0xE2, 0x9C,
  44774. 0x0E, 0x8A, 0xA3, 0xEC, 0xB1, 0x0E, 0x9A, 0xDA, 0x9A, 0x9B, 0x28, 0x92, 0x10,
  44775. 0x53, 0x57, 0xEA, 0xEC, 0xA2, 0x32, 0x32, 0x20, 0x1D, 0x97, 0x5C, 0xB6, 0x84,
  44776. 0xA9, 0x93, 0x8D, 0x95, 0x11, 0xA3, 0x24, 0xA3, 0x2D, 0xC6, 0x4A, 0xEF, 0xAA,
  44777. 0x1D, 0x85, 0x2B, 0x7D, 0x28, 0xBE, 0x53, 0xCE, 0x10, 0x1F, 0xAE, 0x0E, 0x41,
  44778. 0x6C, 0x4B, 0x79, 0x12, 0xFB, 0xF7, 0x54, 0xA3, 0x96, 0x54, 0x83, 0x20, 0x96,
  44779. 0x8F, 0x28, 0xA9, 0x3F, 0x8B, 0x3D, 0xBA, 0x77, 0xDC, 0x24, 0xE1, 0xD4, 0x49,
  44780. 0x40, 0xD8, 0x78, 0x31, 0x85, 0x43, 0xF6, 0xFE, 0x5C, 0xA6, 0x8F, 0x90, 0x09,
  44781. 0xB0, 0xE7, 0xC4, 0x95, 0xB2, 0x55, 0x49, 0x97, 0x8F, 0x1C, 0x78, 0x30, 0x20,
  44782. 0xA0, 0xB4, 0xEF, 0x73, 0x56, 0x59, 0x82, 0xFD, 0xCE, 0xBA, 0x6A, 0x8F, 0x2C,
  44783. 0x8B, 0x15, 0xFD, 0xA1, 0x85, 0xA8, 0x5C, 0x0F, 0x11, 0xA5, 0x9D, 0xC2, 0x46,
  44784. 0xC6, 0x9C, 0xC9, 0x40, 0x0B, 0x58, 0x6A, 0x1C, 0x7A, 0x23, 0xF9, 0xE0, 0x95,
  44785. 0x05, 0x13, 0x58, 0x72, 0xE8, 0x9F, 0x30, 0xAC, 0xCD, 0x26, 0xD4, 0x66, 0x13,
  44786. 0xDF, 0x1E, 0x7B, 0x4F, 0x9C, 0xBE, 0x38, 0x79, 0x75, 0x92, 0xA4, 0xDA, 0x26,
  44787. 0x44, 0x55, 0x17, 0xA3, 0xE5, 0x62, 0xDA, 0xEB, 0x86, 0xEA, 0x68, 0xC7, 0xAB,
  44788. 0xFD, 0x2D, 0x43, 0x59, 0x51, 0xC0, 0x75, 0x64, 0x91, 0x01, 0x29, 0x33, 0x28,
  44789. 0xF3, 0x04, 0x83, 0x80, 0x75, 0x37, 0x75, 0x0C, 0x03, 0x7B, 0x0A, 0xAB, 0x8E,
  44790. 0x60, 0x62, 0x8B, 0x4C, 0xAF, 0x2D, 0xA3, 0x2F, 0xFE, 0xAB, 0x45, 0xCF, 0xDA,
  44791. 0xAB, 0xFA, 0xFA, 0x30, 0x3D, 0xE8, 0xA1, 0x96, 0xA5, 0x7B, 0xE2, 0x2A, 0xD0,
  44792. 0xAF, 0x59, 0xF7, 0xD0, 0x32, 0x57, 0x19, 0xBD, 0xCA, 0x9F, 0xD5, 0x1A, 0xC7,
  44793. 0xAA, 0x65, 0x4A, 0x38, 0xB2, 0x70, 0x33, 0xB7, 0x75, 0xD2, 0xCD, 0xD1, 0xF0,
  44794. 0xA8, 0x87, 0x59, 0x20, 0xA5, 0x57, 0x55, 0xB1, 0xB2, 0xC9, 0x4D, 0x97, 0x34,
  44795. 0x41, 0xF3, 0xF0, 0x30, 0xA1, 0x2C, 0x1C, 0x49, 0x3E, 0x89, 0x7D, 0x12, 0xE2,
  44796. 0xC3, 0x04, 0xC3, 0x92, 0xC0, 0xF6, 0x39, 0x10, 0x80, 0x81, 0x8F, 0x08, 0xB4,
  44797. 0xF8, 0xB9, 0x13, 0x4E, 0x2C, 0xAE, 0xB3, 0x71, 0x82, 0x63, 0x98, 0xAB, 0x5C,
  44798. 0x1C, 0x10, 0xEA, 0x66, 0xF9, 0x02, 0x3A, 0x82, 0x61, 0xD0, 0xD4, 0xAE, 0x43,
  44799. 0xD4, 0x01, 0x3E, 0x9D, 0x04, 0x14, 0xF6, 0x60, 0xD8, 0xA7, 0xD6, 0xB8, 0x53,
  44800. 0xC8, 0xDA, 0x80, 0x93, 0xA0, 0x02, 0xDD, 0xCC, 0xE2, 0xF2, 0xBB, 0xFB, 0xE0,
  44801. 0x27, 0xD7, 0x34, 0x9A, 0x71, 0x49, 0xB5, 0x4F, 0x42, 0x1F, 0xB2, 0x9D, 0x6D,
  44802. 0xAA, 0x9D, 0xD3, 0x50, 0xB5, 0x8F, 0x6A, 0x4B, 0xDF, 0x1F, 0xD5, 0x27, 0x8F,
  44803. 0x3B, 0x27, 0xCF, 0x2F, 0x8C, 0xF8, 0x9D, 0x4C, 0x52, 0xBC, 0x32, 0x0F, 0x73,
  44804. 0xD5, 0x51, 0x8E, 0x36, 0x7E, 0xAD, 0x09, 0xF0, 0x94, 0x83, 0x5F, 0x36, 0xFD,
  44805. 0x7C, 0x03, 0xED, 0xF1, 0x5E, 0x4B, 0xF7, 0xAA, 0x55, 0x5C, 0x4A, 0x14, 0x59,
  44806. 0x85, 0x38, 0x2D, 0x8C, 0xDF, 0xEC, 0x65, 0x1B, 0xB8, 0x76, 0x57, 0x96, 0x3C,
  44807. 0x86, 0xED, 0xF2, 0x7F, 0x2D, 0x28, 0x48, 0xDA, 0x49, 0x7F, 0xF7, 0x54, 0x2B,
  44808. 0xD5, 0x39, 0xD5, 0x57, 0x0A, 0x75, 0x7A, 0x3E, 0x5E, 0x5D, 0xBA, 0x4A, 0x15,
  44809. 0xFA, 0xB8, 0x31, 0x80, 0x71, 0x2C, 0xCA, 0xC4, 0x51, 0x10, 0x16, 0x5D, 0x39,
  44810. 0xEC, 0x9D, 0x07, 0xB6, 0x6A, 0x89, 0x9F, 0x9B, 0x5B, 0x6F, 0x03, 0xB0, 0x92,
  44811. 0x01, 0x38, 0x6B, 0x48, 0x99, 0x0A, 0x8F, 0x13, 0xC1, 0xA6, 0x01, 0xEA, 0xBF,
  44812. 0x6F, 0x86, 0x43, 0x51, 0xB6, 0x11, 0x00, 0x00
  44813. };
  44814. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void)
  44815. {
  44816. wc_test_ret_t ret = 0;
  44817. word32 dSz = sizeof(sample_text);
  44818. word32 cSz = (dSz + (word32)(dSz * 0.001) + 12);
  44819. byte *c;
  44820. byte *d;
  44821. WOLFSSL_ENTER("compress_test");
  44822. c = (byte *)XMALLOC(cSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44823. d = (byte *)XMALLOC(dSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44824. if (c == NULL || d == NULL) {
  44825. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  44826. }
  44827. /* follow calloc and initialize to 0 */
  44828. XMEMSET(c, 0, cSz);
  44829. XMEMSET(d, 0, dSz);
  44830. if ((ret = wc_Compress(c, cSz, sample_text, dSz, 0)) < 0) {
  44831. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44832. }
  44833. cSz = (word32)ret;
  44834. if ((ret = wc_DeCompress(d, dSz, c, cSz)) != (int)dSz) {
  44835. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44836. }
  44837. dSz = (word32)ret;
  44838. if (XMEMCMP(d, sample_text, dSz) != 0) {
  44839. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  44840. }
  44841. /* GZIP tests */
  44842. cSz = (dSz + (word32)(dSz * 0.001) + 12); /* reset cSz */
  44843. XMEMSET(c, 0, cSz);
  44844. XMEMSET(d, 0, dSz);
  44845. ret = wc_Compress_ex(c, cSz, sample_text, dSz, 0, LIBZ_WINBITS_GZIP);
  44846. if (ret < 0)
  44847. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44848. cSz = (word32)ret;
  44849. ret = wc_DeCompress_ex(d, dSz, c, cSz, LIBZ_WINBITS_GZIP);
  44850. if (ret < 0)
  44851. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44852. if (XMEMCMP(d, sample_text, dSz) != 0) {
  44853. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  44854. }
  44855. /* Try with gzip generated output */
  44856. XMEMSET(d, 0, dSz);
  44857. ret = wc_DeCompress_ex(d, dSz, sample_text_gz, sizeof(sample_text_gz),
  44858. LIBZ_WINBITS_GZIP);
  44859. if (ret < 0)
  44860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  44861. dSz = (word32)ret;
  44862. if (XMEMCMP(d, sample_text, dSz) != 0) {
  44863. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  44864. }
  44865. ret = 0; /* success */
  44866. exit:
  44867. XFREE(c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44868. XFREE(d, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44869. return ret;
  44870. }
  44871. #endif /* HAVE_LIBZ */
  44872. #ifdef HAVE_PKCS7
  44873. /* External Debugging/Testing Note:
  44874. *
  44875. * PKCS#7 test functions can output generated PKCS#7/CMS bundles for
  44876. * additional testing. To dump bundles to files DER encoded files, please
  44877. * define:
  44878. *
  44879. * #define PKCS7_OUTPUT_TEST_BUNDLES
  44880. */
  44881. /* Loads certs and keys for use with PKCS7 tests, from either files
  44882. * or buffers.
  44883. *
  44884. * rsaClientCertBuf - output buffer for RSA client cert
  44885. * rsaClientCertBufSz - IN/OUT size of output buffer, size of RSA client cert
  44886. * rsaClientPrivKeyBuf - output buffer for RSA client private key
  44887. * rsaClientPrivKeyBufSz - IN/OUT size of output buffer, size of RSA client key
  44888. *
  44889. * rsaServerCertBuf - output buffer for RSA server cert
  44890. * rsaServerCertBufSz - IN/OUT size of output buffer, size of RSA server cert
  44891. * rsaServerPrivKeyBuf - output buffer for RSA server private key
  44892. * rsaServerPrivKeyBufSz - IN/OUT size of output buffer, size of RSA server key
  44893. *
  44894. * rsaCaCertBuf - output buffer for RSA CA cert
  44895. * rsaCaCertBufSz - IN/OUT size of output buffer, size of RSA ca cert
  44896. * rsaCaPrivKeyBuf - output buffer for RSA CA private key
  44897. * rsaCaPrivKeyBufSz - IN/OUT size of output buffer, size of RSA CA key
  44898. *
  44899. * eccClientCertBuf - output buffer for ECC cert
  44900. * eccClientCertBufSz - IN/OUT size of output buffer, size of ECC cert
  44901. * eccClientPrivKeyBuf - output buffer for ECC private key
  44902. * eccClientPrivKeyBufSz - IN/OUT size of output buffer, size of ECC private key
  44903. *
  44904. * Returns 0 on success, negative on error
  44905. */
  44906. static wc_test_ret_t pkcs7_load_certs_keys(
  44907. byte* rsaClientCertBuf, word32* rsaClientCertBufSz,
  44908. byte* rsaClientPrivKeyBuf, word32* rsaClientPrivKeyBufSz,
  44909. byte* rsaServerCertBuf, word32* rsaServerCertBufSz,
  44910. byte* rsaServerPrivKeyBuf, word32* rsaServerPrivKeyBufSz,
  44911. byte* rsaCaCertBuf, word32* rsaCaCertBufSz,
  44912. byte* rsaCaPrivKeyBuf, word32* rsaCaPrivKeyBufSz,
  44913. byte* eccClientCertBuf, word32* eccClientCertBufSz,
  44914. byte* eccClientPrivKeyBuf, word32* eccClientPrivKeyBufSz)
  44915. {
  44916. #ifndef NO_FILESYSTEM
  44917. XFILE certFile;
  44918. XFILE keyFile;
  44919. (void)certFile;
  44920. (void)keyFile;
  44921. #endif
  44922. #ifndef NO_RSA
  44923. if (rsaClientCertBuf == NULL || rsaClientCertBufSz == NULL ||
  44924. rsaClientPrivKeyBuf == NULL || rsaClientPrivKeyBufSz == NULL)
  44925. return BAD_FUNC_ARG;
  44926. #endif
  44927. #ifdef HAVE_ECC
  44928. if (eccClientCertBuf == NULL || eccClientCertBufSz == NULL ||
  44929. eccClientPrivKeyBuf == NULL || eccClientPrivKeyBufSz == NULL)
  44930. return BAD_FUNC_ARG;
  44931. #endif
  44932. /* RSA */
  44933. #ifndef NO_RSA
  44934. #ifdef USE_CERT_BUFFERS_1024
  44935. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_1024)
  44936. return WC_TEST_RET_ENC_NC;
  44937. XMEMCPY(rsaClientCertBuf, client_cert_der_1024,
  44938. sizeof_client_cert_der_1024);
  44939. *rsaClientCertBufSz = sizeof_client_cert_der_1024;
  44940. if (rsaServerCertBuf != NULL) {
  44941. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_1024)
  44942. return WC_TEST_RET_ENC_NC;
  44943. XMEMCPY(rsaServerCertBuf, server_cert_der_1024,
  44944. sizeof_server_cert_der_1024);
  44945. *rsaServerCertBufSz = sizeof_server_cert_der_1024;
  44946. }
  44947. if (rsaCaCertBuf != NULL) {
  44948. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_1024)
  44949. return WC_TEST_RET_ENC_NC;
  44950. XMEMCPY(rsaCaCertBuf, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  44951. *rsaCaCertBufSz = sizeof_ca_cert_der_1024;
  44952. }
  44953. #elif defined(USE_CERT_BUFFERS_2048)
  44954. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_2048)
  44955. return WC_TEST_RET_ENC_NC;
  44956. XMEMCPY(rsaClientCertBuf, client_cert_der_2048,
  44957. sizeof_client_cert_der_2048);
  44958. *rsaClientCertBufSz = sizeof_client_cert_der_2048;
  44959. if (rsaServerCertBuf != NULL) {
  44960. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_2048)
  44961. return WC_TEST_RET_ENC_NC;
  44962. XMEMCPY(rsaServerCertBuf, server_cert_der_2048,
  44963. sizeof_server_cert_der_2048);
  44964. *rsaServerCertBufSz = sizeof_server_cert_der_2048;
  44965. }
  44966. if (rsaCaCertBuf != NULL) {
  44967. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_2048)
  44968. return WC_TEST_RET_ENC_NC;
  44969. XMEMCPY(rsaCaCertBuf, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  44970. *rsaCaCertBufSz = sizeof_ca_cert_der_2048;
  44971. }
  44972. #else
  44973. certFile = XFOPEN(clientCert, "rb");
  44974. if (!certFile)
  44975. return WC_TEST_RET_ENC_ERRNO;
  44976. *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1,
  44977. *rsaClientCertBufSz, certFile);
  44978. XFCLOSE(certFile);
  44979. if (*rsaClientCertBufSz == 0)
  44980. return WC_TEST_RET_ENC_ERRNO;
  44981. if (rsaServerCertBuf != NULL) {
  44982. certFile = XFOPEN(rsaServerCertDerFile, "rb");
  44983. if (!certFile)
  44984. return WC_TEST_RET_ENC_ERRNO;
  44985. *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1,
  44986. *rsaServerCertBufSz, certFile);
  44987. XFCLOSE(certFile);
  44988. if (*rsaServerCertBufSz == 0)
  44989. return WC_TEST_RET_ENC_ERRNO;
  44990. }
  44991. if (rsaCaCertBuf != NULL) {
  44992. certFile = XFOPEN(rsaCaCertDerFile, "rb");
  44993. if (!certFile)
  44994. return WC_TEST_RET_ENC_ERRNO;
  44995. *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz,
  44996. certFile);
  44997. XFCLOSE(certFile);
  44998. if (*rsaCaCertBufSz == 0)
  44999. return WC_TEST_RET_ENC_ERRNO;
  45000. }
  45001. #endif
  45002. #ifdef USE_CERT_BUFFERS_1024
  45003. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_1024)
  45004. return WC_TEST_RET_ENC_NC;
  45005. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_1024,
  45006. sizeof_client_key_der_1024);
  45007. *rsaClientPrivKeyBufSz = sizeof_client_key_der_1024;
  45008. if (rsaServerPrivKeyBuf != NULL) {
  45009. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_1024)
  45010. return WC_TEST_RET_ENC_NC;
  45011. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_1024,
  45012. sizeof_server_key_der_1024);
  45013. *rsaServerPrivKeyBufSz = sizeof_server_key_der_1024;
  45014. }
  45015. if (rsaCaPrivKeyBuf != NULL) {
  45016. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_1024)
  45017. return WC_TEST_RET_ENC_NC;
  45018. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_1024, sizeof_ca_key_der_1024);
  45019. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_1024;
  45020. }
  45021. #elif defined(USE_CERT_BUFFERS_2048)
  45022. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_2048)
  45023. return WC_TEST_RET_ENC_NC;
  45024. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_2048,
  45025. sizeof_client_key_der_2048);
  45026. *rsaClientPrivKeyBufSz = sizeof_client_key_der_2048;
  45027. if (rsaServerPrivKeyBuf != NULL) {
  45028. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_2048)
  45029. return WC_TEST_RET_ENC_NC;
  45030. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_2048,
  45031. sizeof_server_key_der_2048);
  45032. *rsaServerPrivKeyBufSz = sizeof_server_key_der_2048;
  45033. }
  45034. if (rsaCaPrivKeyBuf != NULL) {
  45035. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_2048)
  45036. return WC_TEST_RET_ENC_NC;
  45037. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_2048, sizeof_ca_key_der_2048);
  45038. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048;
  45039. }
  45040. #else
  45041. keyFile = XFOPEN(clientKey, "rb");
  45042. if (!keyFile)
  45043. return WC_TEST_RET_ENC_ERRNO;
  45044. *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1,
  45045. *rsaClientPrivKeyBufSz, keyFile);
  45046. XFCLOSE(keyFile);
  45047. if (*rsaClientPrivKeyBufSz == 0)
  45048. return WC_TEST_RET_ENC_ERRNO;
  45049. if (rsaServerPrivKeyBuf != NULL) {
  45050. keyFile = XFOPEN(rsaServerKeyDerFile, "rb");
  45051. if (!keyFile)
  45052. return WC_TEST_RET_ENC_ERRNO;
  45053. *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1,
  45054. *rsaServerPrivKeyBufSz, keyFile);
  45055. XFCLOSE(keyFile);
  45056. if (*rsaServerPrivKeyBufSz == 0)
  45057. return WC_TEST_RET_ENC_ERRNO;
  45058. }
  45059. if (rsaCaPrivKeyBuf != NULL) {
  45060. keyFile = XFOPEN(rsaCaKeyFile, "rb");
  45061. if (!keyFile)
  45062. return WC_TEST_RET_ENC_ERRNO;
  45063. *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1,
  45064. *rsaCaPrivKeyBufSz, keyFile);
  45065. XFCLOSE(keyFile);
  45066. if (*rsaCaPrivKeyBufSz == 0)
  45067. return WC_TEST_RET_ENC_ERRNO;
  45068. }
  45069. #endif /* USE_CERT_BUFFERS */
  45070. #endif /* NO_RSA */
  45071. /* ECC */
  45072. #ifdef HAVE_ECC
  45073. #ifdef USE_CERT_BUFFERS_256
  45074. if (*eccClientCertBufSz < (word32)sizeof_cliecc_cert_der_256)
  45075. return WC_TEST_RET_ENC_NC;
  45076. XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45077. *eccClientCertBufSz = sizeof_cliecc_cert_der_256;
  45078. #else
  45079. certFile = XFOPEN(eccClientCert, "rb");
  45080. if (!certFile)
  45081. return WC_TEST_RET_ENC_ERRNO;
  45082. *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1,
  45083. *eccClientCertBufSz, certFile);
  45084. XFCLOSE(certFile);
  45085. if (*eccClientCertBufSz == 0)
  45086. return WC_TEST_RET_ENC_ERRNO;
  45087. #endif /* USE_CERT_BUFFERS_256 */
  45088. #ifdef USE_CERT_BUFFERS_256
  45089. if (*eccClientPrivKeyBufSz < (word32)sizeof_ecc_clikey_der_256)
  45090. return WC_TEST_RET_ENC_NC;
  45091. XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45092. *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256;
  45093. #else
  45094. keyFile = XFOPEN(eccClientKey, "rb");
  45095. if (!keyFile)
  45096. return WC_TEST_RET_ENC_ERRNO;
  45097. *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1,
  45098. *eccClientPrivKeyBufSz, keyFile);
  45099. XFCLOSE(keyFile);
  45100. if (*eccClientPrivKeyBufSz == 0)
  45101. return WC_TEST_RET_ENC_ERRNO;
  45102. #endif /* USE_CERT_BUFFERS_256 */
  45103. #endif /* HAVE_ECC */
  45104. #ifdef NO_RSA
  45105. (void)rsaClientCertBuf;
  45106. (void)rsaClientCertBufSz;
  45107. (void)rsaClientPrivKeyBuf;
  45108. (void)rsaClientPrivKeyBufSz;
  45109. (void)rsaServerCertBuf;
  45110. (void)rsaServerCertBufSz;
  45111. (void)rsaServerPrivKeyBuf;
  45112. (void)rsaServerPrivKeyBufSz;
  45113. (void)rsaCaCertBuf;
  45114. (void)rsaCaCertBufSz;
  45115. (void)rsaCaPrivKeyBuf;
  45116. (void)rsaCaPrivKeyBufSz;
  45117. #endif
  45118. #ifndef HAVE_ECC
  45119. (void)eccClientCertBuf;
  45120. (void)eccClientCertBufSz;
  45121. (void)eccClientPrivKeyBuf;
  45122. (void)eccClientPrivKeyBufSz;
  45123. #endif
  45124. #ifndef NO_FILESYSTEM
  45125. (void)certFile;
  45126. (void)keyFile;
  45127. #endif
  45128. return 0;
  45129. }
  45130. typedef struct {
  45131. const byte* content;
  45132. word32 contentSz;
  45133. int contentOID;
  45134. int encryptOID;
  45135. int keyWrapOID;
  45136. int keyAgreeOID;
  45137. byte* cert;
  45138. size_t certSz;
  45139. byte* privateKey;
  45140. word32 privateKeySz;
  45141. byte* optionalUkm;
  45142. word32 optionalUkmSz;
  45143. int ktriOptions; /* KTRI options flags */
  45144. int kariOptions; /* KARI options flags */
  45145. /* KEKRI specific */
  45146. const byte* secretKey; /* key, only for kekri RecipientInfo types */
  45147. word32 secretKeySz; /* size of secretKey, bytes */
  45148. const byte* secretKeyId; /* key identifier */
  45149. word32 secretKeyIdSz; /* size of key identifier, bytes */
  45150. void* timePtr; /* time_t pointer */
  45151. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  45152. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  45153. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  45154. word32 otherAttrSz; /* size of otherAttr, bytes */
  45155. int kekriOptions; /* KEKRI options flags */
  45156. /* PWRI specific */
  45157. const char* password;
  45158. word32 passwordSz;
  45159. const byte* salt;
  45160. word32 saltSz;
  45161. int kdfOID;
  45162. int hashOID;
  45163. int kdfIterations;
  45164. int pwriOptions; /* PWRI options flags */
  45165. /* ORI specific */
  45166. int isOri;
  45167. int oriOptions; /* ORI options flags */
  45168. const char* outFileName;
  45169. } pkcs7EnvelopedVector;
  45170. static const byte asnDataOid[] = {
  45171. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01
  45172. };
  45173. /* ORI encrypt callback, responsible for encrypting content-encryption key (CEK)
  45174. * and giving wolfCrypt the value for oriOID and oriValue to place in
  45175. * OtherRecipientInfo.
  45176. *
  45177. * Returns 0 on success, negative upon error. */
  45178. static int myOriEncryptCb(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* oriType,
  45179. word32* oriTypeSz, byte* oriValue, word32* oriValueSz,
  45180. void* ctx)
  45181. {
  45182. int i;
  45183. /* make sure buffers are large enough */
  45184. if (*oriValueSz < (2 + cekSz))
  45185. return WC_TEST_RET_ENC_NC;
  45186. if (*oriTypeSz < sizeof(asnDataOid))
  45187. return WC_TEST_RET_ENC_NC;
  45188. /* our simple encryption algorithm will be take the bitwise complement */
  45189. oriValue[0] = 0x04; /*ASN OCTET STRING */
  45190. oriValue[1] = (byte)cekSz; /* length */
  45191. for (i = 0; i < (int)cekSz; i++) {
  45192. oriValue[2 + i] = ~cek[i];
  45193. }
  45194. *oriValueSz = 2 + cekSz;
  45195. /* set oriType to ASN.1 encoded data OID */
  45196. XMEMCPY(oriType, asnDataOid, sizeof(asnDataOid));
  45197. *oriTypeSz = sizeof(asnDataOid);
  45198. (void)pkcs7;
  45199. (void)ctx;
  45200. return 0;
  45201. }
  45202. /* ORI decrypt callback, responsible for providing a decrypted content
  45203. * encryption key (CEK) placed into decryptedKey and size placed into
  45204. * decryptedKeySz. oriOID and oriValue are given to the callback to help
  45205. * in decrypting the encrypted CEK.
  45206. *
  45207. * Returns 0 on success, negative upon error. */
  45208. static int myOriDecryptCb(PKCS7* pkcs7, byte* oriType, word32 oriTypeSz,
  45209. byte* oriValue, word32 oriValueSz, byte* decryptedKey,
  45210. word32* decryptedKeySz, void* ctx)
  45211. {
  45212. int i;
  45213. /* make sure oriType matches what we expect */
  45214. if (oriTypeSz != sizeof(asnDataOid))
  45215. return WC_TEST_RET_ENC_NC;
  45216. if (XMEMCMP(oriType, asnDataOid, sizeof(asnDataOid)) != 0)
  45217. return WC_TEST_RET_ENC_NC;
  45218. /* make sure decrypted buffer is large enough */
  45219. if (*decryptedKeySz < oriValueSz)
  45220. return WC_TEST_RET_ENC_NC;
  45221. /* decrypt encrypted CEK using simple bitwise complement,
  45222. only for example */
  45223. for (i = 0; i < (int)oriValueSz - 2; i++) {
  45224. decryptedKey[i] = ~oriValue[2 + i];
  45225. }
  45226. *decryptedKeySz = oriValueSz - 2;
  45227. (void)pkcs7;
  45228. (void)ctx;
  45229. return 0;
  45230. }
  45231. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45232. /* returns 0 on success */
  45233. static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45234. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45235. byte* in, int inSz, byte* out, void* usrCtx)
  45236. {
  45237. wc_test_ret_t ret;
  45238. int keyId = -1, keySz;
  45239. word32 keyIdSz = 8;
  45240. const byte* key;
  45241. byte keyIdRaw[8];
  45242. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45243. Aes *aes;
  45244. #else
  45245. Aes aes[1];
  45246. #endif
  45247. /* looking for KEY ID
  45248. * fwDecryptKeyID OID "1.2.840.113549.1.9.16.2.37
  45249. */
  45250. WOLFSSL_SMALL_STACK_STATIC const unsigned char OID[] = {
  45251. /* 0x06, 0x0B do not pass in tag and length */
  45252. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  45253. 0x01, 0x09, 0x10, 0x02, 0x25
  45254. };
  45255. WOLFSSL_SMALL_STACK_STATIC const byte defKey[] = {
  45256. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45257. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45258. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45259. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45260. };
  45261. WOLFSSL_SMALL_STACK_STATIC const byte altKey[] = {
  45262. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45263. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45264. };
  45265. /* test user context passed in */
  45266. if (usrCtx == NULL || *(int*)usrCtx != 1) {
  45267. return WC_TEST_RET_ENC_NC;
  45268. }
  45269. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45270. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  45271. return WC_TEST_RET_ENC_ERRNO;
  45272. #endif
  45273. /* if needing to find keyIdSz can call with NULL */
  45274. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), NULL,
  45275. &keyIdSz);
  45276. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  45277. printf("Unexpected error %d when getting keyIdSz\n", ret);
  45278. printf("Possibly no KEY ID attribute set\n");
  45279. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45280. }
  45281. else {
  45282. XMEMSET(keyIdRaw, 0, sizeof(keyIdRaw));
  45283. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), keyIdRaw,
  45284. &keyIdSz);
  45285. if (ret < 0) {
  45286. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45287. }
  45288. if (keyIdSz < 3) {
  45289. printf("keyIdSz is smaller than expected\n");
  45290. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45291. }
  45292. if (keyIdSz > 2 + sizeof(int)) {
  45293. printf("example case was only expecting a keyId of int size\n");
  45294. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45295. }
  45296. /* keyIdRaw[0] OCTET TAG */
  45297. /* keyIdRaw[1] Length */
  45298. #ifdef BIG_ENDIAN_ORDER
  45299. if (keyIdRaw[1] == 0x01) {
  45300. keyId = 1;
  45301. }
  45302. #else
  45303. XMEMCPY(&keyId, keyIdRaw + 2, sizeof(keyId));
  45304. #endif
  45305. }
  45306. /* Use keyID here if found to select key and decrypt in HSM or in this
  45307. * example just select key and do software decryption */
  45308. if (keyId == 1) {
  45309. key = altKey;
  45310. keySz = sizeof(altKey);
  45311. }
  45312. else {
  45313. key = defKey;
  45314. keySz = sizeof(defKey);
  45315. }
  45316. switch (encryptOID) {
  45317. #ifdef WOLFSSL_AES_256
  45318. case AES256CBCb:
  45319. if ((keySz != 32 ) || (ivSz != AES_BLOCK_SIZE))
  45320. WARNING_OUT(BAD_FUNC_ARG, out);
  45321. break;
  45322. #endif
  45323. #ifdef WOLFSSL_AES_128
  45324. case AES128CBCb:
  45325. if ((keySz != 16 ) || (ivSz != AES_BLOCK_SIZE))
  45326. ERROR_OUT(BAD_FUNC_ARG, out);
  45327. break;
  45328. #endif
  45329. default:
  45330. printf("Unsupported content cipher type for example");
  45331. ERROR_OUT(ALGO_ID_E, out);
  45332. };
  45333. ret = wc_AesInit(aes, HEAP_HINT, INVALID_DEVID);
  45334. if (ret == 0) {
  45335. ret = wc_AesSetKey(aes, key, (word32)keySz, iv, AES_DECRYPTION);
  45336. if (ret == 0)
  45337. ret = wc_AesCbcDecrypt(aes, out, in, (word32)inSz);
  45338. wc_AesFree(aes);
  45339. }
  45340. out:
  45341. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45342. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45343. #endif
  45344. (void)aad;
  45345. (void)aadSz;
  45346. (void)authTag;
  45347. (void)authTagSz;
  45348. return (int)ret;
  45349. }
  45350. #endif /* !NO_AES && HAVE_AES_CBC */
  45351. #define PKCS7_BUF_SIZE 2048
  45352. static wc_test_ret_t pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  45353. byte* rsaPrivKey, word32 rsaPrivKeySz,
  45354. byte* eccCert, word32 eccCertSz,
  45355. byte* eccPrivKey, word32 eccPrivKeySz)
  45356. {
  45357. wc_test_ret_t ret = 0;
  45358. int testSz = 0, i;
  45359. int envelopedSz, decodedSz;
  45360. byte *enveloped = NULL;
  45361. byte *decoded = NULL;
  45362. PKCS7* pkcs7 = NULL;
  45363. #ifdef ECC_TIMING_RESISTANT
  45364. WC_RNG rng;
  45365. #endif
  45366. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  45367. XFILE pkcs7File;
  45368. #endif
  45369. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  45370. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  45371. 0x72,0x6c,0x64
  45372. };
  45373. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256) && \
  45374. defined(HAVE_ECC) && defined(WOLFSSL_SHA512)
  45375. byte optionalUkm[] = {
  45376. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45377. };
  45378. #endif /* NO_AES */
  45379. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  45380. !defined(NO_SHA)
  45381. /* encryption key for kekri recipient types */
  45382. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  45383. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  45384. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45385. };
  45386. /* encryption key identifier */
  45387. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  45388. 0x02,0x02,0x03,0x04
  45389. };
  45390. #endif
  45391. #if !defined(NO_PWDBASED) && !defined(NO_SHA) && \
  45392. !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  45393. #ifndef HAVE_FIPS
  45394. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password"; /* NOTE: Password is too short for FIPS */
  45395. #else
  45396. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  45397. #endif
  45398. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  45399. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  45400. };
  45401. #endif
  45402. #define MAX_TESTVECTORS_LEN 13
  45403. #define ADD_PKCS7ENVELOPEDVECTOR(...) { \
  45404. pkcs7EnvelopedVector _this_vector = { __VA_ARGS__ }; \
  45405. if (testSz == MAX_TESTVECTORS_LEN) { \
  45406. ret = WC_TEST_RET_ENC_NC; \
  45407. goto out; \
  45408. } \
  45409. XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\
  45410. }
  45411. pkcs7EnvelopedVector *testVectors = NULL;
  45412. #ifdef ECC_TIMING_RESISTANT
  45413. XMEMSET(&rng, 0, sizeof(rng));
  45414. #endif
  45415. testVectors = (pkcs7EnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  45416. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45417. if (testVectors == NULL) {
  45418. ret = WC_TEST_RET_ENC_ERRNO;
  45419. goto out;
  45420. }
  45421. {
  45422. /* key transport key encryption technique */
  45423. #ifndef NO_RSA
  45424. #ifndef NO_DES3
  45425. ADD_PKCS7ENVELOPEDVECTOR(
  45426. data, (word32)sizeof(data), DATA, DES3b, 0, 0, rsaCert, rsaCertSz,
  45427. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45428. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45429. "pkcs7envelopedDataDES3.der");
  45430. #endif
  45431. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45432. #ifdef WOLFSSL_AES_128
  45433. ADD_PKCS7ENVELOPEDVECTOR(
  45434. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, rsaCert, rsaCertSz,
  45435. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45436. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45437. "pkcs7envelopedDataAES128CBC.der");
  45438. #endif
  45439. #ifdef WOLFSSL_AES_192
  45440. ADD_PKCS7ENVELOPEDVECTOR(
  45441. data, (word32)sizeof(data), DATA, AES192CBCb, 0, 0, rsaCert, rsaCertSz,
  45442. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45443. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45444. "pkcs7envelopedDataAES192CBC.der");
  45445. #endif
  45446. #ifdef WOLFSSL_AES_256
  45447. ADD_PKCS7ENVELOPEDVECTOR(
  45448. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45449. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45450. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45451. "pkcs7envelopedDataAES256CBC.der");
  45452. /* explicitly using SKID for SubjectKeyIdentifier */
  45453. ADD_PKCS7ENVELOPEDVECTOR(
  45454. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45455. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_SKID, 0, NULL, 0, NULL, 0, NULL,
  45456. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45457. "pkcs7envelopedDataAES256CBC_SKID.der");
  45458. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  45459. ADD_PKCS7ENVELOPEDVECTOR(
  45460. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45461. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_ISSUER_AND_SERIAL_NUMBER, 0,
  45462. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  45463. 0, 0, 0, 0, "pkcs7envelopedDataAES256CBC_IANDS.der");
  45464. #endif
  45465. #endif /* !NO_AES && HAVE_AES_CBC */
  45466. #endif
  45467. /* key agreement key encryption technique*/
  45468. #ifdef HAVE_ECC
  45469. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45470. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45471. ADD_PKCS7ENVELOPEDVECTOR(
  45472. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP,
  45473. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45474. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45475. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45476. "pkcs7envelopedDataAES128CBC_ECDH_SHA1KDF.der");
  45477. #endif
  45478. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  45479. ADD_PKCS7ENVELOPEDVECTOR(
  45480. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45481. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45482. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45483. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45484. "pkcs7envelopedDataAES256CBC_ECDH_SHA256KDF.der");
  45485. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  45486. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  45487. ADD_PKCS7ENVELOPEDVECTOR(
  45488. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45489. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45490. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45491. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45492. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF.der");
  45493. /* with optional user keying material (ukm) */
  45494. ADD_PKCS7ENVELOPEDVECTOR(
  45495. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45496. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45497. eccPrivKeySz, optionalUkm, sizeof(optionalUkm), 0, 0, NULL, 0,
  45498. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45499. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF_ukm.der");
  45500. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  45501. #endif /* !NO_AES && HAVE_AES_CBC */
  45502. #endif
  45503. /* kekri (KEKRecipientInfo) recipient types */
  45504. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45505. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45506. ADD_PKCS7ENVELOPEDVECTOR(
  45507. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP, 0,
  45508. NULL, 0, NULL, 0, NULL, 0, 0, 0, secretKey, sizeof(secretKey),
  45509. secretKeyId, sizeof(secretKeyId), NULL, NULL, 0, NULL, 0,
  45510. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45511. "pkcs7envelopedDataAES128CBC_KEKRI.der");
  45512. #endif
  45513. #endif /* !NO_AES && HAVE_AES_CBC */
  45514. /* pwri (PasswordRecipientInfo) recipient types */
  45515. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  45516. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45517. ADD_PKCS7ENVELOPEDVECTOR(
  45518. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0,
  45519. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45520. NULL, 0, NULL, NULL, 0, NULL, 0, 0, password,
  45521. (word32)XSTRLEN(password), salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  45522. 0, 0, 0, "pkcs7envelopedDataAES128CBC_PWRI.der");
  45523. #endif
  45524. #endif
  45525. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_128)
  45526. /* ori (OtherRecipientInfo) recipient types */
  45527. ADD_PKCS7ENVELOPEDVECTOR(
  45528. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, NULL, 0, NULL, 0,
  45529. NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0,
  45530. NULL, 0, 0, 0, 0, 0, 1, 0, "pkcs7envelopedDataAES128CBC_ORI.der");
  45531. #endif
  45532. };
  45533. #undef MAX_TESTVECTORS_LEN
  45534. #undef ADD_PKCS7ENVELOPEDVECTOR
  45535. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45536. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45537. if ((! enveloped) || (! decoded)) {
  45538. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45539. }
  45540. #ifdef ECC_TIMING_RESISTANT
  45541. #ifndef HAVE_FIPS
  45542. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  45543. #else
  45544. ret = wc_InitRng(&rng);
  45545. #endif
  45546. if (ret != 0)
  45547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45548. #endif
  45549. for (i = 0; i < testSz; i++) {
  45550. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  45551. #ifdef WOLFSSL_ASYNC_CRYPT
  45552. INVALID_DEVID /* async PKCS7 is not supported */
  45553. #else
  45554. devId
  45555. #endif
  45556. );
  45557. if (pkcs7 == NULL) {
  45558. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  45559. }
  45560. if (testVectors[i].secretKey != NULL) {
  45561. /* KEKRI recipient type */
  45562. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45563. if (ret != 0)
  45564. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45565. pkcs7->content = (byte*)testVectors[i].content;
  45566. pkcs7->contentSz = testVectors[i].contentSz;
  45567. pkcs7->contentOID = testVectors[i].contentOID;
  45568. pkcs7->encryptOID = testVectors[i].encryptOID;
  45569. pkcs7->ukm = testVectors[i].optionalUkm;
  45570. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  45571. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  45572. (byte *)testVectors[i].secretKey, testVectors[i].secretKeySz,
  45573. (byte *)testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  45574. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  45575. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  45576. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  45577. if (ret < 0) {
  45578. wc_PKCS7_Free(pkcs7);
  45579. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45580. }
  45581. /* set key, for decryption */
  45582. ret = wc_PKCS7_SetKey(pkcs7, (byte *)testVectors[i].secretKey,
  45583. testVectors[i].secretKeySz);
  45584. if (ret != 0) {
  45585. wc_PKCS7_Free(pkcs7);
  45586. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45587. }
  45588. } else if (testVectors[i].password != NULL) {
  45589. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  45590. /* PWRI recipient type */
  45591. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45592. if (ret != 0)
  45593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45594. pkcs7->content = (byte*)testVectors[i].content;
  45595. pkcs7->contentSz = testVectors[i].contentSz;
  45596. pkcs7->contentOID = testVectors[i].contentOID;
  45597. pkcs7->encryptOID = testVectors[i].encryptOID;
  45598. pkcs7->ukm = testVectors[i].optionalUkm;
  45599. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  45600. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  45601. (byte *)testVectors[i].password, testVectors[i].passwordSz,
  45602. (byte *)testVectors[i].salt, testVectors[i].saltSz,
  45603. testVectors[i].kdfOID,
  45604. testVectors[i].hashOID, testVectors[i].kdfIterations,
  45605. testVectors[i].encryptOID, testVectors[i].pwriOptions);
  45606. if (ret < 0) {
  45607. wc_PKCS7_Free(pkcs7);
  45608. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45609. }
  45610. /* set password, for decryption */
  45611. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  45612. testVectors[i].passwordSz);
  45613. if (ret < 0) {
  45614. wc_PKCS7_Free(pkcs7);
  45615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45616. }
  45617. #endif /* ! NO_PWDBASED && ! NO_SHA */
  45618. } else if (testVectors[i].isOri == 1) {
  45619. /* ORI recipient type */
  45620. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45621. if (ret != 0)
  45622. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45623. pkcs7->content = (byte*)testVectors[i].content;
  45624. pkcs7->contentSz = testVectors[i].contentSz;
  45625. pkcs7->contentOID = testVectors[i].contentOID;
  45626. pkcs7->encryptOID = testVectors[i].encryptOID;
  45627. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  45628. testVectors[i].oriOptions);
  45629. if (ret < 0) {
  45630. wc_PKCS7_Free(pkcs7);
  45631. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45632. }
  45633. /* set decrypt callback for decryption */
  45634. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  45635. if (ret < 0) {
  45636. wc_PKCS7_Free(pkcs7);
  45637. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45638. }
  45639. } else {
  45640. /* KTRI or KARI recipient types */
  45641. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45642. if (ret != 0)
  45643. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45644. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  45645. (word32)testVectors[i].certSz);
  45646. if (ret != 0) {
  45647. wc_PKCS7_Free(pkcs7);
  45648. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45649. }
  45650. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  45651. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  45652. pkcs7->privateKey = testVectors[i].privateKey;
  45653. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  45654. pkcs7->content = (byte*)testVectors[i].content;
  45655. pkcs7->contentSz = testVectors[i].contentSz;
  45656. pkcs7->contentOID = testVectors[i].contentOID;
  45657. pkcs7->encryptOID = testVectors[i].encryptOID;
  45658. pkcs7->ukm = testVectors[i].optionalUkm;
  45659. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  45660. /* set SubjectIdentifier type for KTRI types */
  45661. if (testVectors[i].ktriOptions & CMS_SKID) {
  45662. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  45663. if (ret != 0) {
  45664. wc_PKCS7_Free(pkcs7);
  45665. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45666. }
  45667. } else if (testVectors[i].ktriOptions &
  45668. CMS_ISSUER_AND_SERIAL_NUMBER) {
  45669. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  45670. CMS_ISSUER_AND_SERIAL_NUMBER);
  45671. if (ret != 0) {
  45672. wc_PKCS7_Free(pkcs7);
  45673. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45674. }
  45675. }
  45676. }
  45677. #ifdef ECC_TIMING_RESISTANT
  45678. pkcs7->rng = &rng;
  45679. #endif
  45680. /* encode envelopedData */
  45681. envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, enveloped,
  45682. PKCS7_BUF_SIZE);
  45683. if (envelopedSz <= 0) {
  45684. wc_PKCS7_Free(pkcs7);
  45685. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  45686. }
  45687. /* decode envelopedData */
  45688. pkcs7->contentOID = 0;
  45689. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, (word32)envelopedSz,
  45690. decoded, PKCS7_BUF_SIZE);
  45691. if (pkcs7->contentOID != testVectors[i].contentOID ||
  45692. decodedSz <= 0) {
  45693. wc_PKCS7_Free(pkcs7);
  45694. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  45695. }
  45696. /* test decode result */
  45697. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  45698. wc_PKCS7_Free(pkcs7);
  45699. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45700. }
  45701. #ifndef NO_PKCS7_STREAM
  45702. { /* test reading byte by byte */
  45703. int z;
  45704. for (z = 0; z < envelopedSz; z++) {
  45705. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped + z, 1,
  45706. decoded, PKCS7_BUF_SIZE);
  45707. if (decodedSz <= 0 &&
  45708. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  45709. {
  45710. printf("unexpected error %d\n", decodedSz);
  45711. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  45712. }
  45713. }
  45714. /* test decode result */
  45715. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  45716. printf("stream read compare failed\n");
  45717. wc_PKCS7_Free(pkcs7);
  45718. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45719. }
  45720. }
  45721. #endif
  45722. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  45723. /* output pkcs7 envelopedData for external testing */
  45724. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  45725. if (!pkcs7File) {
  45726. wc_PKCS7_Free(pkcs7);
  45727. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  45728. }
  45729. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  45730. XFCLOSE(pkcs7File);
  45731. if (ret != envelopedSz) {
  45732. wc_PKCS7_Free(pkcs7);
  45733. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  45734. } else {
  45735. /* reset ret to 0 for success */
  45736. ret = 0;
  45737. }
  45738. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  45739. wc_PKCS7_Free(pkcs7);
  45740. pkcs7 = NULL;
  45741. }
  45742. #ifdef ECC_TIMING_RESISTANT
  45743. wc_FreeRng(&rng);
  45744. #endif
  45745. (void)eccCert;
  45746. (void)eccCertSz;
  45747. (void)eccPrivKey;
  45748. (void)eccPrivKeySz;
  45749. (void)rsaCert;
  45750. (void)rsaCertSz;
  45751. (void)rsaPrivKey;
  45752. (void)rsaPrivKeySz;
  45753. out:
  45754. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45755. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45756. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45757. return ret;
  45758. }
  45759. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void)
  45760. {
  45761. wc_test_ret_t ret = 0;
  45762. byte* rsaCert = NULL;
  45763. byte* rsaPrivKey = NULL;
  45764. word32 rsaCertSz = 0;
  45765. word32 rsaPrivKeySz = 0;
  45766. byte* eccCert = NULL;
  45767. byte* eccPrivKey = NULL;
  45768. word32 eccCertSz = 0;
  45769. word32 eccPrivKeySz = 0;
  45770. WOLFSSL_ENTER("pkcs7enveloped_test");
  45771. #ifndef NO_RSA
  45772. /* read client RSA cert and key in DER format */
  45773. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45774. if (rsaCert == NULL)
  45775. return WC_TEST_RET_ENC_ERRNO;
  45776. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45777. if (rsaPrivKey == NULL) {
  45778. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45779. return WC_TEST_RET_ENC_NC;
  45780. }
  45781. rsaCertSz = FOURK_BUF;
  45782. rsaPrivKeySz = FOURK_BUF;
  45783. #endif /* NO_RSA */
  45784. #ifdef HAVE_ECC
  45785. /* read client ECC cert and key in DER format */
  45786. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45787. if (eccCert == NULL) {
  45788. #ifndef NO_RSA
  45789. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45790. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45791. #endif
  45792. return WC_TEST_RET_ENC_NC;
  45793. }
  45794. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45795. if (eccPrivKey == NULL) {
  45796. #ifndef NO_RSA
  45797. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45798. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45799. #endif
  45800. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45801. return WC_TEST_RET_ENC_NC;
  45802. }
  45803. eccCertSz = FOURK_BUF;
  45804. eccPrivKeySz = FOURK_BUF;
  45805. #endif /* HAVE_ECC */
  45806. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  45807. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  45808. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  45809. eccPrivKey, &eccPrivKeySz);
  45810. if (ret < 0) {
  45811. #ifndef NO_RSA
  45812. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45813. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45814. #endif
  45815. #ifdef HAVE_ECC
  45816. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45817. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45818. #endif
  45819. return WC_TEST_RET_ENC_EC(ret);
  45820. }
  45821. ret = pkcs7enveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  45822. rsaPrivKey, (word32)rsaPrivKeySz,
  45823. eccCert, (word32)eccCertSz,
  45824. eccPrivKey, (word32)eccPrivKeySz);
  45825. #ifndef NO_RSA
  45826. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45827. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45828. #endif
  45829. #ifdef HAVE_ECC
  45830. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45831. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45832. #endif
  45833. return ret;
  45834. }
  45835. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  45836. typedef struct {
  45837. const byte* content;
  45838. word32 contentSz;
  45839. int contentOID;
  45840. int encryptOID;
  45841. int keyWrapOID;
  45842. int keyAgreeOID;
  45843. byte* cert;
  45844. size_t certSz;
  45845. byte* privateKey;
  45846. word32 privateKeySz;
  45847. PKCS7Attrib* authAttribs;
  45848. word32 authAttribsSz;
  45849. PKCS7Attrib* unauthAttribs;
  45850. word32 unauthAttribsSz;
  45851. /* KARI / KTRI specific */
  45852. byte* optionalUkm;
  45853. word32 optionalUkmSz;
  45854. int ktriOptions; /* KTRI options flags */
  45855. int kariOptions; /* KARI options flags */
  45856. /* KEKRI specific */
  45857. byte* secretKey; /* key, only for kekri RecipientInfo types */
  45858. word32 secretKeySz; /* size of secretKey, bytes */
  45859. 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. char* password; /* password */
  45869. word32 passwordSz; /* password size, bytes */
  45870. byte* salt; /* KDF salt */
  45871. word32 saltSz; /* KDF salt size, bytes */
  45872. int kdfOID; /* KDF OID */
  45873. int hashOID; /* KDF hash algorithm OID */
  45874. int kdfIterations; /* KDF iterations */
  45875. int kekEncryptOID; /* KEK encryption algorithm OID */
  45876. int pwriOptions; /* PWRI options flags */
  45877. /* ORI specific */
  45878. int isOri;
  45879. int oriOptions; /* ORI options flags */
  45880. const char* outFileName;
  45881. } pkcs7AuthEnvelopedVector;
  45882. static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  45883. byte* rsaPrivKey, word32 rsaPrivKeySz,
  45884. byte* eccCert, word32 eccCertSz,
  45885. byte* eccPrivKey, word32 eccPrivKeySz)
  45886. {
  45887. wc_test_ret_t ret = 0;
  45888. int testSz = 0, i;
  45889. int envelopedSz, decodedSz;
  45890. byte *enveloped = NULL;
  45891. byte *decoded = NULL;
  45892. WC_RNG rng;
  45893. PKCS7* pkcs7;
  45894. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  45895. XFILE pkcs7File;
  45896. #endif
  45897. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  45898. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  45899. 0x72,0x6c,0x64
  45900. };
  45901. byte senderNonce[PKCS7_NONCE_SZ + 2];
  45902. #ifdef HAVE_ECC
  45903. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  45904. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  45905. WOLFSSL_SMALL_STACK_STATIC const byte senderNonceOid[] =
  45906. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  45907. 0x09, 0x05 };
  45908. PKCS7Attrib attribs[] =
  45909. {
  45910. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  45911. sizeof(senderNonce) }
  45912. };
  45913. #endif
  45914. #endif
  45915. #endif
  45916. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && defined(HAVE_ECC) && \
  45917. defined(WOLFSSL_SHA512) && defined(HAVE_AESGCM)
  45918. WOLFSSL_SMALL_STACK_STATIC const byte optionalUkm[] = {
  45919. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45920. };
  45921. #endif /* NO_AES */
  45922. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45923. /* encryption key for kekri recipient types */
  45924. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  45925. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  45926. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45927. };
  45928. /* encryption key identifier */
  45929. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  45930. 0x02,0x02,0x03,0x04
  45931. };
  45932. #endif
  45933. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  45934. !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  45935. #ifndef HAVE_FIPS
  45936. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password";
  45937. #else
  45938. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  45939. #endif
  45940. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  45941. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  45942. };
  45943. #endif
  45944. #define MAX_TESTVECTORS_LEN 20
  45945. #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \
  45946. pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \
  45947. if (testSz == MAX_TESTVECTORS_LEN) { \
  45948. ret = WC_TEST_RET_ENC_NC; \
  45949. goto out; \
  45950. } \
  45951. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  45952. sizeof _this_vector); \
  45953. }
  45954. pkcs7AuthEnvelopedVector *testVectors = NULL;
  45955. XMEMSET(&rng, 0, sizeof(rng));
  45956. testVectors = (pkcs7AuthEnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  45957. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45958. if (testVectors == NULL) {
  45959. ret = WC_TEST_RET_ENC_ERRNO;
  45960. goto out;
  45961. }
  45962. {
  45963. /* key transport key encryption technique */
  45964. #ifndef NO_RSA
  45965. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  45966. #ifdef WOLFSSL_AES_128
  45967. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45968. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, rsaCert, rsaCertSz,
  45969. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45970. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  45971. 0, 0, "pkcs7authEnvelopedDataAES128GCM.der");
  45972. #endif
  45973. #ifdef WOLFSSL_AES_192
  45974. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45975. data, (word32)sizeof(data), DATA, AES192GCMb, 0, 0, rsaCert, rsaCertSz,
  45976. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45977. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  45978. 0, 0, "pkcs7authEnvelopedDataAES192GCM.der");
  45979. #endif
  45980. #ifdef WOLFSSL_AES_256
  45981. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45982. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  45983. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45984. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  45985. 0, 0, "pkcs7authEnvelopedDataAES256GCM.der");
  45986. /* test with contentType set to FirmwarePkgData */
  45987. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45988. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, 0, 0,
  45989. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL,
  45990. 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL,
  45991. 0, 0, 0, 0, 0, 0, 0, 0,
  45992. "pkcs7authEnvelopedDataAES256GCM_firmwarePkgData.der");
  45993. /* explicitly using SKID for SubjectKeyIdentifier */
  45994. ADD_PKCS7AUTHENVELOPEDVECTOR(
  45995. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  45996. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, CMS_SKID, 0,
  45997. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  45998. 0, 0, 0, 0, 0, "pkcs7authEnvelopedDataAES256GCM_SKID.der");
  45999. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46000. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46001. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46002. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0,
  46003. CMS_ISSUER_AND_SERIAL_NUMBER, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46004. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46005. "pkcs7authEnvelopedDataAES256GCM_IANDS.der");
  46006. #endif
  46007. #else /* NO_AES || !HAVE_AESGCM */
  46008. (void)rsaCert;
  46009. (void)rsaCertSz;
  46010. (void)rsaPrivKey;
  46011. (void)rsaPrivKeySz;
  46012. #endif /* NO_AES || !HAVE_AESGCM */
  46013. #endif
  46014. /* key agreement key encryption technique*/
  46015. #ifdef HAVE_ECC
  46016. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46017. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46018. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46019. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP,
  46020. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46021. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46022. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46023. "pkcs7authEnvelopedDataAES128GCM_ECDH_SHA1KDF.der");
  46024. #endif
  46025. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46026. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46027. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46028. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46029. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46030. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46031. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF.der");
  46032. /* with authenticated attributes */
  46033. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46034. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46035. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46036. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46037. NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46038. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46039. 0, 0, 0,
  46040. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_authAttribs.der");
  46041. /* with unauthenticated attributes */
  46042. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46043. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46044. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46045. eccPrivKeySz, NULL, 0, attribs,
  46046. (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0, NULL, 0,
  46047. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46048. 0, 0, 0,
  46049. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_unauthAttribs.der");
  46050. /* with authenticated AND unauthenticated attributes */
  46051. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46052. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46053. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46054. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46055. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46056. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46057. 0, 0, 0, 0, 0, 0,
  46058. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_bothAttribs.der");
  46059. /* with authenticated AND unauthenticated attributes AND
  46060. * contentType of FirmwarePkgData */
  46061. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46062. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, AES256_WRAP,
  46063. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46064. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46065. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46066. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46067. 0, 0, 0, 0, 0, 0,
  46068. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_fw_bothAttribs.der");
  46069. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46070. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46071. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46072. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46073. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46074. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL,
  46075. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46076. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF.der");
  46077. /* with optional user keying material (ukm) */
  46078. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46079. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46080. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46081. eccPrivKeySz, NULL, 0, NULL, 0, (byte *)optionalUkm, sizeof(optionalUkm), 0,
  46082. 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46083. 0, 0, 0, 0, 0, 0,
  46084. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF_ukm.der");
  46085. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46086. #endif /* NO_AES */
  46087. #endif
  46088. /* kekri (KEKRecipientInfo) recipient types */
  46089. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46090. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46091. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46092. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP, 0,
  46093. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0,
  46094. (byte *)secretKey, sizeof(secretKey), (byte *)secretKeyId, sizeof(secretKeyId),
  46095. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46096. "pkcs7authEnvelopedDataAES128GCM_KEKRI.der");
  46097. #endif
  46098. #endif
  46099. /* pwri (PasswordRecipientInfo) recipient types */
  46100. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM)
  46101. #if !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46102. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46103. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0,
  46104. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46105. NULL, 0, NULL, NULL, 0, NULL, 0, 0, (char *)password,
  46106. (word32)XSTRLEN(password), (byte *)salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46107. AES128CBCb, 0, 0, 0, "pkcs7authEnvelopedDataAES128GCM_PWRI.der");
  46108. #endif
  46109. #endif
  46110. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46111. #ifdef WOLFSSL_AES_128
  46112. /* ori (OtherRecipientInfo) recipient types */
  46113. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46114. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, NULL, 0, NULL, 0,
  46115. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46116. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 1, 0,
  46117. "pkcs7authEnvelopedDataAES128GCM_ORI.der");
  46118. #endif
  46119. #endif
  46120. }
  46121. #undef MAX_TESTVECTORS_LEN
  46122. #undef ADD_PKCS7AUTHENVELOPEDVECTOR
  46123. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46124. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46125. if ((! enveloped) || (! decoded)) {
  46126. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46127. }
  46128. /* generate senderNonce */
  46129. {
  46130. #ifndef HAVE_FIPS
  46131. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46132. #else
  46133. ret = wc_InitRng(&rng);
  46134. #endif
  46135. if (ret != 0)
  46136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46137. senderNonce[0] = 0x04;
  46138. senderNonce[1] = PKCS7_NONCE_SZ;
  46139. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  46140. if (ret != 0) {
  46141. wc_FreeRng(&rng);
  46142. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46143. }
  46144. }
  46145. for (i = 0; i < testSz; i++) {
  46146. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46147. #ifdef WOLFSSL_ASYNC_CRYPT
  46148. INVALID_DEVID /* async PKCS7 is not supported */
  46149. #else
  46150. devId
  46151. #endif
  46152. );
  46153. if (pkcs7 == NULL) {
  46154. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46155. }
  46156. if (testVectors[i].secretKey != NULL) {
  46157. /* KEKRI recipient type */
  46158. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46159. if (ret != 0)
  46160. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46161. pkcs7->content = (byte*)testVectors[i].content;
  46162. pkcs7->contentSz = testVectors[i].contentSz;
  46163. pkcs7->contentOID = testVectors[i].contentOID;
  46164. pkcs7->encryptOID = testVectors[i].encryptOID;
  46165. pkcs7->ukm = testVectors[i].optionalUkm;
  46166. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46167. pkcs7->authAttribs = testVectors[i].authAttribs;
  46168. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46169. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46170. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46171. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46172. testVectors[i].secretKey, testVectors[i].secretKeySz,
  46173. testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46174. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46175. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46176. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46177. if (ret < 0) {
  46178. wc_PKCS7_Free(pkcs7);
  46179. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46180. }
  46181. /* set key, for decryption */
  46182. ret = wc_PKCS7_SetKey(pkcs7, testVectors[i].secretKey,
  46183. testVectors[i].secretKeySz);
  46184. if (ret != 0) {
  46185. wc_PKCS7_Free(pkcs7);
  46186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46187. }
  46188. } else if (testVectors[i].password != NULL) {
  46189. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46190. /* PWRI recipient type */
  46191. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46192. if (ret != 0)
  46193. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46194. pkcs7->content = (byte*)testVectors[i].content;
  46195. pkcs7->contentSz = testVectors[i].contentSz;
  46196. pkcs7->contentOID = testVectors[i].contentOID;
  46197. pkcs7->encryptOID = testVectors[i].encryptOID;
  46198. pkcs7->ukm = testVectors[i].optionalUkm;
  46199. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46200. pkcs7->authAttribs = testVectors[i].authAttribs;
  46201. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46202. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46203. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46204. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46205. (byte*)testVectors[i].password,
  46206. testVectors[i].passwordSz, testVectors[i].salt,
  46207. testVectors[i].saltSz, testVectors[i].kdfOID,
  46208. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46209. testVectors[i].kekEncryptOID, testVectors[i].pwriOptions);
  46210. if (ret < 0) {
  46211. wc_PKCS7_Free(pkcs7);
  46212. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46213. }
  46214. /* set password, for decryption */
  46215. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46216. testVectors[i].passwordSz);
  46217. if (ret < 0) {
  46218. wc_PKCS7_Free(pkcs7);
  46219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46220. }
  46221. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46222. } else if (testVectors[i].isOri == 1) {
  46223. /* ORI recipient type */
  46224. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46225. if (ret != 0)
  46226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46227. pkcs7->content = (byte*)testVectors[i].content;
  46228. pkcs7->contentSz = testVectors[i].contentSz;
  46229. pkcs7->contentOID = testVectors[i].contentOID;
  46230. pkcs7->encryptOID = testVectors[i].encryptOID;
  46231. pkcs7->authAttribs = testVectors[i].authAttribs;
  46232. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46233. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46234. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46235. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46236. testVectors[i].oriOptions);
  46237. if (ret < 0) {
  46238. wc_PKCS7_Free(pkcs7);
  46239. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46240. }
  46241. /* set decrypt callback for decryption */
  46242. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46243. if (ret < 0) {
  46244. wc_PKCS7_Free(pkcs7);
  46245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46246. }
  46247. } else {
  46248. /* KTRI or KARI recipient types */
  46249. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46250. (word32)testVectors[i].certSz);
  46251. if (ret != 0) {
  46252. wc_PKCS7_Free(pkcs7);
  46253. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46254. }
  46255. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46256. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46257. pkcs7->privateKey = testVectors[i].privateKey;
  46258. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46259. pkcs7->content = (byte*)testVectors[i].content;
  46260. pkcs7->contentSz = testVectors[i].contentSz;
  46261. pkcs7->contentOID = testVectors[i].contentOID;
  46262. pkcs7->encryptOID = testVectors[i].encryptOID;
  46263. pkcs7->ukm = testVectors[i].optionalUkm;
  46264. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46265. pkcs7->authAttribs = testVectors[i].authAttribs;
  46266. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46267. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46268. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46269. /* set SubjectIdentifier type for KTRI types */
  46270. if (testVectors[i].ktriOptions & CMS_SKID) {
  46271. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46272. if (ret != 0) {
  46273. wc_PKCS7_Free(pkcs7);
  46274. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46275. }
  46276. } else if (testVectors[i].ktriOptions &
  46277. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46278. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46279. CMS_ISSUER_AND_SERIAL_NUMBER);
  46280. if (ret != 0) {
  46281. wc_PKCS7_Free(pkcs7);
  46282. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46283. }
  46284. }
  46285. }
  46286. #ifdef ECC_TIMING_RESISTANT
  46287. pkcs7->rng = &rng;
  46288. #endif
  46289. /* encode envelopedData */
  46290. envelopedSz = wc_PKCS7_EncodeAuthEnvelopedData(pkcs7, enveloped,
  46291. PKCS7_BUF_SIZE);
  46292. if (envelopedSz <= 0) {
  46293. wc_PKCS7_Free(pkcs7);
  46294. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46295. }
  46296. #ifndef NO_PKCS7_STREAM
  46297. { /* test reading byte by byte */
  46298. int z;
  46299. for (z = 0; z < envelopedSz; z++) {
  46300. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7,
  46301. enveloped + z, 1, decoded, PKCS7_BUF_SIZE);
  46302. if (decodedSz <= 0 &&
  46303. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46304. {
  46305. printf("unexpected error %d\n", decodedSz);
  46306. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46307. }
  46308. }
  46309. /* test decode result */
  46310. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46311. printf("stream read compare failed\n");
  46312. wc_PKCS7_Free(pkcs7);
  46313. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46314. }
  46315. }
  46316. #endif
  46317. /* decode envelopedData */
  46318. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7, enveloped,
  46319. (word32)envelopedSz, decoded,
  46320. PKCS7_BUF_SIZE);
  46321. if (decodedSz <= 0) {
  46322. wc_PKCS7_Free(pkcs7);
  46323. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46324. }
  46325. /* test decode result */
  46326. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  46327. wc_PKCS7_Free(pkcs7);
  46328. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46329. }
  46330. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46331. /* output pkcs7 envelopedData for external testing */
  46332. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46333. if (!pkcs7File) {
  46334. wc_PKCS7_Free(pkcs7);
  46335. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46336. }
  46337. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  46338. XFCLOSE(pkcs7File);
  46339. if (ret != envelopedSz) {
  46340. wc_PKCS7_Free(pkcs7);
  46341. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46342. } else {
  46343. /* reset ret to 0 for success */
  46344. ret = 0;
  46345. }
  46346. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  46347. wc_PKCS7_Free(pkcs7);
  46348. pkcs7 = NULL;
  46349. }
  46350. wc_FreeRng(&rng);
  46351. (void)eccCert;
  46352. (void)eccCertSz;
  46353. (void)eccPrivKey;
  46354. (void)eccPrivKeySz;
  46355. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46356. (void)secretKey;
  46357. (void)secretKeyId;
  46358. #endif
  46359. #ifdef NO_RSA
  46360. (void)rsaCert;
  46361. (void)rsaCertSz;
  46362. (void)rsaPrivKey;
  46363. (void)rsaPrivKeySz;
  46364. #endif
  46365. out:
  46366. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46367. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46368. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46369. return ret;
  46370. }
  46371. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void)
  46372. {
  46373. wc_test_ret_t ret = 0;
  46374. byte* rsaCert = NULL;
  46375. byte* rsaPrivKey = NULL;
  46376. word32 rsaCertSz = 0;
  46377. word32 rsaPrivKeySz = 0;
  46378. byte* eccCert = NULL;
  46379. byte* eccPrivKey = NULL;
  46380. word32 eccCertSz = 0;
  46381. word32 eccPrivKeySz = 0;
  46382. WOLFSSL_ENTER("pkcs7authenveloped_test");
  46383. #ifndef NO_RSA
  46384. /* read client RSA cert and key in DER format */
  46385. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46386. if (rsaCert == NULL)
  46387. return WC_TEST_RET_ENC_ERRNO;
  46388. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46389. if (rsaPrivKey == NULL) {
  46390. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46391. return WC_TEST_RET_ENC_NC;
  46392. }
  46393. rsaCertSz = FOURK_BUF;
  46394. rsaPrivKeySz = FOURK_BUF;
  46395. #endif /* NO_RSA */
  46396. #ifdef HAVE_ECC
  46397. /* read client ECC cert and key in DER format */
  46398. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46399. if (eccCert == NULL) {
  46400. #ifndef NO_RSA
  46401. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46402. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46403. #endif
  46404. return WC_TEST_RET_ENC_NC;
  46405. }
  46406. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46407. if (eccPrivKey == NULL) {
  46408. #ifndef NO_RSA
  46409. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46410. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46411. #endif
  46412. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46413. return WC_TEST_RET_ENC_NC;
  46414. }
  46415. eccCertSz = FOURK_BUF;
  46416. eccPrivKeySz = FOURK_BUF;
  46417. #endif /* HAVE_ECC */
  46418. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  46419. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  46420. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  46421. eccPrivKey, &eccPrivKeySz);
  46422. if (ret < 0) {
  46423. #ifndef NO_RSA
  46424. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46425. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46426. #endif
  46427. #ifdef HAVE_ECC
  46428. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46429. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46430. #endif
  46431. return WC_TEST_RET_ENC_EC(ret);
  46432. }
  46433. ret = pkcs7authenveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  46434. rsaPrivKey, (word32)rsaPrivKeySz,
  46435. eccCert, (word32)eccCertSz,
  46436. eccPrivKey, (word32)eccPrivKeySz);
  46437. #ifndef NO_RSA
  46438. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46439. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46440. #endif
  46441. #ifdef HAVE_ECC
  46442. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46443. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46444. #endif
  46445. return ret;
  46446. }
  46447. #endif /* HAVE_AESGCM || HAVE_AESCCM */
  46448. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46449. static const byte p7DefKey[] = {
  46450. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46451. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46452. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46453. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46454. };
  46455. static const byte p7AltKey[] = {
  46456. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46457. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46458. };
  46459. static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  46460. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  46461. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  46462. {
  46463. wc_test_ret_t ret;
  46464. if (cek == NULL || out == NULL)
  46465. return BAD_FUNC_ARG;
  46466. /* test case sanity checks */
  46467. if (keyIdSz != 1) {
  46468. return WC_TEST_RET_ENC_NC;
  46469. }
  46470. if (keyId[0] != 0x00) {
  46471. return WC_TEST_RET_ENC_NC;
  46472. }
  46473. if (type != (int)PKCS7_KEKRI) {
  46474. return WC_TEST_RET_ENC_NC;
  46475. }
  46476. switch (keyWrapAlgo) {
  46477. case AES256_WRAP:
  46478. ret = wc_AesKeyUnWrap(p7DefKey, sizeof(p7DefKey), cek, cekSz,
  46479. out, outSz, NULL);
  46480. if (ret <= 0)
  46481. return (int)ret;
  46482. break;
  46483. default:
  46484. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  46485. return BAD_KEYWRAP_ALG_E;
  46486. };
  46487. (void)pkcs7;
  46488. (void)direction;
  46489. (void)orginKey; /* used with KAKRI */
  46490. (void)orginKeySz;
  46491. return (int)ret;
  46492. }
  46493. /* returns key size on success */
  46494. static wc_test_ret_t getFirmwareKey(PKCS7* pkcs7, byte* key, word32 keySz)
  46495. {
  46496. wc_test_ret_t ret;
  46497. word32 atrSz;
  46498. byte atr[256];
  46499. /* Additionally can look for fwWrappedFirmwareKey
  46500. * 1.2.840.113529.1.9.16.1.16 */
  46501. const unsigned char fwWrappedFirmwareKey[] = {
  46502. /* 0x06, 0x0B */
  46503. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46504. 0x01, 0x09, 0x10, 0x02, 0x27
  46505. };
  46506. /* find keyID in fwWrappedFirmwareKey */
  46507. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  46508. sizeof(fwWrappedFirmwareKey), NULL, &atrSz);
  46509. if (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  46510. XMEMSET(atr, 0, sizeof(atr));
  46511. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  46512. sizeof(fwWrappedFirmwareKey), atr, &atrSz);
  46513. /* keyIdRaw[0] OCTET TAG */
  46514. /* keyIdRaw[1] Length */
  46515. if (ret > 0) {
  46516. PKCS7* envPkcs7;
  46517. envPkcs7 = wc_PKCS7_New(NULL, 0);
  46518. if (envPkcs7 == NULL) {
  46519. return MEMORY_E;
  46520. }
  46521. wc_PKCS7_Init(envPkcs7, NULL, 0);
  46522. ret = wc_PKCS7_SetWrapCEKCb(envPkcs7, myCEKwrapFunc);
  46523. if (ret == 0) {
  46524. /* expecting FIRMWARE_PKG_DATA content */
  46525. envPkcs7->contentOID = FIRMWARE_PKG_DATA;
  46526. ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz,
  46527. key, keySz);
  46528. if (envPkcs7->contentOID != FIRMWARE_PKG_DATA) {
  46529. /* the contentOID should have been set to the inner
  46530. * FIRMWARE_PKG_DATA content */
  46531. ret = BAD_STATE_E;
  46532. }
  46533. }
  46534. wc_PKCS7_Free(envPkcs7);
  46535. }
  46536. }
  46537. return ret;
  46538. }
  46539. /* create a KEKRI enveloped data
  46540. * return size on success */
  46541. static wc_test_ret_t envelopedData_encrypt(byte* in, word32 inSz, byte* out,
  46542. word32 outSz)
  46543. {
  46544. wc_test_ret_t ret;
  46545. PKCS7* pkcs7;
  46546. WOLFSSL_SMALL_STACK_STATIC const byte keyId[] = { 0x00 };
  46547. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  46548. if (pkcs7 == NULL)
  46549. return WC_TEST_RET_ENC_ERRNO;
  46550. pkcs7->content = in;
  46551. pkcs7->contentSz = inSz;
  46552. pkcs7->contentOID = FIRMWARE_PKG_DATA;
  46553. pkcs7->encryptOID = AES256CBCb;
  46554. pkcs7->ukm = NULL;
  46555. pkcs7->ukmSz = 0;
  46556. /* add recipient (KEKRI type) */
  46557. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP, (byte*)p7DefKey,
  46558. sizeof(p7DefKey), (byte*)keyId,
  46559. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0);
  46560. if (ret < 0) {
  46561. printf("wc_PKCS7_AddRecipient_KEKRI() failed\n");
  46562. wc_PKCS7_Free(pkcs7);
  46563. return WC_TEST_RET_ENC_EC(ret);
  46564. }
  46565. /* encode envelopedData, returns size */
  46566. ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
  46567. if (ret <= 0) {
  46568. printf("wc_PKCS7_EncodeEnvelopedData() failed\n");
  46569. wc_PKCS7_Free(pkcs7);
  46570. return WC_TEST_RET_ENC_EC(ret);
  46571. }
  46572. wc_PKCS7_Free(pkcs7);
  46573. return ret;
  46574. }
  46575. /*
  46576. * keyHint is the KeyID to be set in the fwDecryptKeyID attribute
  46577. * returns size of buffer output on success
  46578. */
  46579. static wc_test_ret_t generateBundle(byte* out, word32 *outSz, const byte* encryptKey,
  46580. word32 encryptKeySz, byte keyHint, byte* cert, word32 certSz,
  46581. byte* key, word32 keySz)
  46582. {
  46583. wc_test_ret_t ret;
  46584. int attribNum = 1;
  46585. PKCS7* pkcs7;
  46586. /* KEY ID
  46587. * fwDecryptKeyID OID 1.2.840.113549.1.9.16.2.37
  46588. */
  46589. const unsigned char fwDecryptKeyID[] = {
  46590. 0x06, 0x0B,
  46591. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46592. 0x01, 0x09, 0x10, 0x02, 0x25
  46593. };
  46594. /* fwWrappedFirmwareKey 1.2.840.113529.1.9.16.1.16 */
  46595. const unsigned char fwWrappedFirmwareKey[] = {
  46596. 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46597. 0x01, 0x09, 0x10, 0x02, 0x27
  46598. };
  46599. byte keyID[] = { 0x04, 0x01, 0x00 };
  46600. byte env[256];
  46601. char data[] = "Test of wolfSSL PKCS7 decrypt callback";
  46602. PKCS7Attrib attribs[] =
  46603. {
  46604. { fwDecryptKeyID, sizeof(fwDecryptKeyID), keyID, sizeof(keyID) },
  46605. { fwWrappedFirmwareKey, sizeof(fwWrappedFirmwareKey), env, 0 }
  46606. };
  46607. keyID[2] = keyHint;
  46608. /* If using keyHint 0 then create a bundle with fwWrappedFirmwareKey */
  46609. if (keyHint == 0) {
  46610. ret = envelopedData_encrypt((byte*)p7DefKey, sizeof(p7DefKey), env,
  46611. sizeof(env));
  46612. if (ret <= 0) {
  46613. return ret;
  46614. }
  46615. attribs[1].valueSz = (word32)ret;
  46616. attribNum++;
  46617. }
  46618. /* init PKCS7 */
  46619. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  46620. if (pkcs7 == NULL)
  46621. return WC_TEST_RET_ENC_ERRNO;
  46622. ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz);
  46623. if (ret != 0) {
  46624. printf("ERROR: wc_PKCS7_InitWithCert() failed, ret = %d\n", ret);
  46625. wc_PKCS7_Free(pkcs7);
  46626. return WC_TEST_RET_ENC_EC(ret);
  46627. }
  46628. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46629. if (ret != 0) {
  46630. wc_PKCS7_Free(pkcs7);
  46631. return WC_TEST_RET_ENC_EC(ret);
  46632. }
  46633. /* encode Signed Encrypted FirmwarePkgData */
  46634. if (encryptKeySz == 16) {
  46635. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  46636. encryptKeySz, key, keySz, AES128CBCb, RSAk, SHA256h,
  46637. (byte*)data, sizeof(data), NULL, 0,
  46638. attribs, (word32)attribNum, out, *outSz);
  46639. }
  46640. else {
  46641. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  46642. encryptKeySz, key, keySz, AES256CBCb, RSAk, SHA256h,
  46643. (byte*)data, sizeof(data), NULL, 0,
  46644. attribs, (word32)attribNum, out, *outSz);
  46645. }
  46646. if (ret <= 0) {
  46647. printf("ERROR: wc_PKCS7_EncodeSignedEncryptedFPD() failed, "
  46648. "ret = %d\n", ret);
  46649. wc_PKCS7_Free(pkcs7);
  46650. return WC_TEST_RET_ENC_EC(ret);
  46651. } else {
  46652. *outSz = (word32)ret;
  46653. }
  46654. wc_PKCS7_Free(pkcs7);
  46655. return ret;
  46656. }
  46657. /* test verification and decryption of PKCS7 bundle
  46658. * return 0 on success
  46659. */
  46660. static wc_test_ret_t verifyBundle(byte* derBuf, word32 derSz, int keyHint)
  46661. {
  46662. wc_test_ret_t ret = 0;
  46663. int usrCtx = 1; /* test value to pass as user context to callback */
  46664. PKCS7* pkcs7 = NULL;
  46665. byte* sid = NULL;
  46666. word32 sidSz;
  46667. byte key[256];
  46668. word32 keySz = sizeof(key);
  46669. byte *decoded = NULL;
  46670. int decodedSz = FOURK_BUF/2;
  46671. WOLFSSL_SMALL_STACK_STATIC const byte expectedSid[] = {
  46672. #ifdef NO_SHA
  46673. #ifdef USE_CERT_BUFFERS_1024
  46674. 0x70, 0xe7, 0x79, 0x60, 0x8f, 0x41, 0xdc, 0xe9,
  46675. 0xad, 0x8b, 0x3d, 0x0c, 0x20, 0xf4, 0xc3, 0xf2,
  46676. 0x8e, 0x05, 0xe8, 0xa1, 0xb6, 0x68, 0x74, 0x06,
  46677. 0xbc, 0xe7, 0xc5, 0x3c, 0x13, 0x99, 0x79, 0xb9
  46678. #else
  46679. 0xce, 0x06, 0x07, 0xbe, 0xf1, 0xa6, 0x1e, 0x36,
  46680. 0xef, 0xfa, 0xbc, 0x89, 0x71, 0xf3, 0x23, 0x9e,
  46681. 0x34, 0x6d, 0xae, 0x86, 0xae, 0x2b, 0xdc, 0xf4,
  46682. 0x4a, 0x27, 0xd5, 0x63, 0x59, 0x4f, 0x4a, 0x71
  46683. #endif
  46684. #else /* !NO_SHA */
  46685. #ifdef USE_CERT_BUFFERS_1024
  46686. 0x81, 0x69, 0x0f, 0xf8, 0xdf, 0xdd, 0xcf, 0x34,
  46687. 0x29, 0xd5, 0x67, 0x75, 0x71, 0x85, 0xc7, 0x75,
  46688. 0x10, 0x69, 0x59, 0xec,
  46689. #else
  46690. 0x33, 0xD8, 0x45, 0x66, 0xD7, 0x68, 0x87, 0x18,
  46691. 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26,
  46692. 0xD7, 0x85, 0x65, 0xC0
  46693. #endif
  46694. #endif /* !NO_SHA */
  46695. };
  46696. decoded = (byte *)XMALLOC(decodedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46697. if (decoded == NULL) {
  46698. ret = MEMORY_E;
  46699. goto out;
  46700. }
  46701. pkcs7 = wc_PKCS7_New(HEAP_HINT, INVALID_DEVID);
  46702. if (pkcs7 == NULL) {
  46703. ret = MEMORY_E;
  46704. goto out;
  46705. }
  46706. /* Test verify */
  46707. ret = wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID);
  46708. if (ret != 0)
  46709. goto out;
  46710. ret = wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  46711. if (ret != 0)
  46712. goto out;
  46713. ret = wc_PKCS7_VerifySignedData(pkcs7, derBuf, derSz);
  46714. if (ret != 0)
  46715. goto out;
  46716. /* Get size of SID and print it out */
  46717. ret = wc_PKCS7_GetSignerSID(pkcs7, NULL, &sidSz);
  46718. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  46719. goto out;
  46720. sid = (byte*)XMALLOC(sidSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46721. if (sid == NULL) {
  46722. ret = MEMORY_E;
  46723. goto out;
  46724. }
  46725. ret = wc_PKCS7_GetSignerSID(pkcs7, sid, &sidSz);
  46726. if (ret != 0)
  46727. goto out;
  46728. ret = XMEMCMP(sid, expectedSid, sidSz);
  46729. if (ret != 0) {
  46730. ret = PKCS7_NO_SIGNER_E; /* close enough */
  46731. goto out;
  46732. }
  46733. /* get expected fwWrappedFirmwareKey */
  46734. if (keyHint == 0) {
  46735. ret = getFirmwareKey(pkcs7, key, keySz);
  46736. if (ret < 0)
  46737. goto out;
  46738. pkcs7->encryptionKey = key;
  46739. pkcs7->encryptionKeySz = (word32)ret;
  46740. }
  46741. else {
  46742. decodedSz = PKCS7_BUF_SIZE;
  46743. ret = wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc);
  46744. if (ret != 0)
  46745. goto out;
  46746. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)&usrCtx);
  46747. if (ret != 0)
  46748. goto out;
  46749. }
  46750. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  46751. pkcs7->contentSz, decoded, (word32)decodedSz);
  46752. if (decodedSz < 0) {
  46753. ret = decodedSz;
  46754. goto out;
  46755. }
  46756. ret = 0;
  46757. out:
  46758. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46759. if (pkcs7)
  46760. wc_PKCS7_Free(pkcs7);
  46761. XFREE(sid, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46762. return ret;
  46763. }
  46764. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key, word32 keySz)
  46765. {
  46766. wc_test_ret_t ret = 0;
  46767. word32 derSz;
  46768. byte *derBuf = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46769. WOLFSSL_ENTER("pkcs7callback_test");
  46770. if (! derBuf)
  46771. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46772. /* Doing default generation and verify */
  46773. derSz = FOURK_BUF;
  46774. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 0, cert,
  46775. certSz, key, keySz);
  46776. if (ret <= 0) {
  46777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46778. }
  46779. ret = verifyBundle(derBuf, derSz, 0);
  46780. if (ret != 0)
  46781. ERROR_OUT(ret, out);
  46782. /* test choosing other key with keyID */
  46783. derSz = FOURK_BUF;
  46784. ret = generateBundle(derBuf, &derSz, p7AltKey, sizeof(p7AltKey), 1,
  46785. cert, certSz, key, keySz);
  46786. if (ret <= 0) {
  46787. ERROR_OUT(ret, out);
  46788. }
  46789. ret = verifyBundle(derBuf, derSz, 1);
  46790. if (ret != 0)
  46791. ERROR_OUT(ret, out);
  46792. /* test fail case with wrong keyID */
  46793. derSz = FOURK_BUF;
  46794. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 1,
  46795. cert, certSz, key, keySz);
  46796. if (ret <= 0) {
  46797. ERROR_OUT(ret, out);
  46798. }
  46799. ret = verifyBundle(derBuf, derSz, 1);
  46800. if (ret == 0) {
  46801. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46802. }
  46803. ret = 0;
  46804. out:
  46805. XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46806. return ret;
  46807. }
  46808. #endif /* !NO_AES && HAVE_AES_CBC */
  46809. #ifndef NO_PKCS7_ENCRYPTED_DATA
  46810. typedef struct {
  46811. const byte* content;
  46812. word32 contentSz;
  46813. int contentOID;
  46814. int encryptOID;
  46815. byte* encryptionKey;
  46816. word32 encryptionKeySz;
  46817. PKCS7Attrib* attribs;
  46818. word32 attribsSz;
  46819. const char* outFileName;
  46820. } pkcs7EncryptedVector;
  46821. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void)
  46822. {
  46823. wc_test_ret_t ret = 0;
  46824. int i, testSz;
  46825. int encryptedSz, decodedSz, attribIdx;
  46826. PKCS7* pkcs7;
  46827. byte *encrypted;
  46828. byte *decoded;
  46829. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46830. XFILE pkcs7File;
  46831. #endif
  46832. PKCS7Attrib* expectedAttrib;
  46833. PKCS7DecodedAttrib* decodedAttrib;
  46834. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46835. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46836. 0x72,0x6c,0x64
  46837. };
  46838. #ifndef NO_DES3
  46839. byte desKey[] = {
  46840. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  46841. };
  46842. byte des3Key[] = {
  46843. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  46844. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  46845. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  46846. };
  46847. #endif
  46848. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46849. #ifdef WOLFSSL_AES_128
  46850. byte aes128Key[] = {
  46851. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46852. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46853. };
  46854. #endif
  46855. #ifdef WOLFSSL_AES_192
  46856. byte aes192Key[] = {
  46857. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46858. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46859. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46860. };
  46861. #endif
  46862. #ifdef WOLFSSL_AES_256
  46863. byte aes256Key[] = {
  46864. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46865. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46866. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46867. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46868. };
  46869. #endif
  46870. #ifdef WOLFSSL_AES_256
  46871. /* Attribute example from RFC 4134, Section 7.2
  46872. * OID = 1.2.5555
  46873. * OCTET STRING = 'This is a test General ASN Attribute, number 1.' */
  46874. static const byte genAttrOid[] = { 0x06, 0x03, 0x2a, 0xab, 0x33 };
  46875. static const byte genAttr[] = { 0x04, 47,
  46876. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  46877. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  46878. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  46879. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  46880. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  46881. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x31, 0x2e };
  46882. static const byte genAttrOid2[] = { 0x06, 0x03, 0x2a, 0xab, 0x34 };
  46883. static const byte genAttr2[] = { 0x04, 47,
  46884. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  46885. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  46886. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  46887. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  46888. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  46889. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x32, 0x2e };
  46890. PKCS7Attrib attribs[] =
  46891. {
  46892. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) }
  46893. };
  46894. PKCS7Attrib multiAttribs[] =
  46895. {
  46896. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) },
  46897. { genAttrOid2, sizeof(genAttrOid2), genAttr2, sizeof(genAttr2) }
  46898. };
  46899. #endif
  46900. #endif /* NO_AES */
  46901. const pkcs7EncryptedVector testVectors[] =
  46902. {
  46903. #ifndef NO_DES3
  46904. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key),
  46905. NULL, 0, "pkcs7encryptedDataDES3.der"},
  46906. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey),
  46907. NULL, 0, "pkcs7encryptedDataDES.der"},
  46908. #endif /* NO_DES3 */
  46909. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46910. #ifdef WOLFSSL_AES_128
  46911. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  46912. sizeof(aes128Key), NULL, 0, "pkcs7encryptedDataAES128CBC.der"},
  46913. #endif
  46914. #ifdef WOLFSSL_AES_192
  46915. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  46916. sizeof(aes192Key), NULL, 0, "pkcs7encryptedDataAES192CBC.der"},
  46917. #endif
  46918. #ifdef WOLFSSL_AES_256
  46919. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46920. sizeof(aes256Key), NULL, 0, "pkcs7encryptedDataAES256CBC.der"},
  46921. /* test with optional unprotected attributes */
  46922. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46923. sizeof(aes256Key), attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  46924. "pkcs7encryptedDataAES256CBC_attribs.der"},
  46925. /* test with multiple optional unprotected attributes */
  46926. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46927. sizeof(aes256Key), multiAttribs,
  46928. (sizeof(multiAttribs)/sizeof(PKCS7Attrib)),
  46929. "pkcs7encryptedDataAES256CBC_multi_attribs.der"},
  46930. /* test with contentType set to FirmwarePkgData */
  46931. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256CBCb, aes256Key,
  46932. sizeof(aes256Key), NULL, 0,
  46933. "pkcs7encryptedDataAES256CBC_firmwarePkgData.der"},
  46934. #endif
  46935. #endif /* !NO_AES && HAVE_AES_CBC */
  46936. };
  46937. WOLFSSL_ENTER("pkcs7encrypted_test");
  46938. encrypted = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46939. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46940. if ((! encrypted) || (! decoded)) {
  46941. ERROR_OUT(MEMORY_E, out);
  46942. }
  46943. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  46944. for (i = 0; i < testSz; i++) {
  46945. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  46946. if (pkcs7 == NULL) {
  46947. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46948. }
  46949. pkcs7->content = (byte*)testVectors[i].content;
  46950. pkcs7->contentSz = testVectors[i].contentSz;
  46951. pkcs7->contentOID = testVectors[i].contentOID;
  46952. pkcs7->encryptOID = testVectors[i].encryptOID;
  46953. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  46954. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  46955. pkcs7->unprotectedAttribs = testVectors[i].attribs;
  46956. pkcs7->unprotectedAttribsSz = testVectors[i].attribsSz;
  46957. /* encode encryptedData */
  46958. encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46959. PKCS7_BUF_SIZE);
  46960. if (encryptedSz <= 0) {
  46961. wc_PKCS7_Free(pkcs7);
  46962. ERROR_OUT(WC_TEST_RET_ENC_EC(encryptedSz), out);
  46963. }
  46964. /* decode encryptedData */
  46965. #ifndef NO_PKCS7_STREAM
  46966. { /* test reading byte by byte */
  46967. int z;
  46968. for (z = 0; z < encryptedSz; z++) {
  46969. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted + z, 1,
  46970. decoded, PKCS7_BUF_SIZE);
  46971. if (decodedSz <= 0 &&
  46972. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46973. {
  46974. printf("unexpected error %d\n", decodedSz);
  46975. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46976. }
  46977. }
  46978. /* test decode result */
  46979. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46980. printf("stream read failed\n");
  46981. wc_PKCS7_Free(pkcs7);
  46982. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46983. }
  46984. }
  46985. #endif
  46986. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46987. decoded, PKCS7_BUF_SIZE);
  46988. if (decodedSz <= 0){
  46989. wc_PKCS7_Free(pkcs7);
  46990. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46991. }
  46992. /* test decode result */
  46993. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46994. wc_PKCS7_Free(pkcs7);
  46995. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46996. }
  46997. /* verify decoded unprotected attributes */
  46998. if (pkcs7->decodedAttrib != NULL) {
  46999. decodedAttrib = pkcs7->decodedAttrib;
  47000. attribIdx = 1;
  47001. while (decodedAttrib != NULL) {
  47002. /* expected attribute, stored list is reversed */
  47003. expectedAttrib = &(pkcs7->unprotectedAttribs
  47004. [pkcs7->unprotectedAttribsSz - attribIdx]);
  47005. /* verify oid */
  47006. if (XMEMCMP(decodedAttrib->oid, expectedAttrib->oid,
  47007. decodedAttrib->oidSz) != 0) {
  47008. wc_PKCS7_Free(pkcs7);
  47009. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47010. }
  47011. /* verify value */
  47012. if (XMEMCMP(decodedAttrib->value, expectedAttrib->value,
  47013. decodedAttrib->valueSz) != 0) {
  47014. wc_PKCS7_Free(pkcs7);
  47015. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47016. }
  47017. decodedAttrib = decodedAttrib->next;
  47018. attribIdx++;
  47019. }
  47020. }
  47021. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47022. /* output pkcs7 envelopedData for external testing */
  47023. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47024. if (!pkcs7File) {
  47025. wc_PKCS7_Free(pkcs7);
  47026. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47027. }
  47028. ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File);
  47029. if (ret < 0)
  47030. ret = WC_TEST_RET_ENC_ERRNO;
  47031. else
  47032. ret = 0;
  47033. XFCLOSE(pkcs7File);
  47034. #endif
  47035. wc_PKCS7_Free(pkcs7);
  47036. }
  47037. out:
  47038. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47039. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47040. return ret;
  47041. }
  47042. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47043. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47044. typedef struct {
  47045. const byte* content;
  47046. word32 contentSz;
  47047. int contentOID;
  47048. const char* outFileName;
  47049. } pkcs7CompressedVector;
  47050. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void)
  47051. {
  47052. wc_test_ret_t ret = 0;
  47053. int i, testSz;
  47054. int compressedSz, decodedSz;
  47055. PKCS7* pkcs7;
  47056. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47057. byte *compressed;
  47058. byte *decoded;
  47059. #else
  47060. byte compressed[PKCS7_BUF_SIZE];
  47061. byte decoded[PKCS7_BUF_SIZE];
  47062. #endif
  47063. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47064. XFILE pkcs7File;
  47065. #endif
  47066. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47067. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47068. 0x72,0x6c,0x64
  47069. };
  47070. const pkcs7CompressedVector testVectors[] =
  47071. {
  47072. {data, (word32)sizeof(data), DATA,
  47073. "pkcs7compressedData_data_zlib.der"},
  47074. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA,
  47075. "pkcs7compressedData_firmwarePkgData_zlib.der"},
  47076. };
  47077. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47078. compressed = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47079. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47080. if ((! compressed) || (! decoded)) {
  47081. ERROR_OUT(MEMORY_E, out);
  47082. }
  47083. #endif
  47084. WOLFSSL_ENTER("pkcs7compressed_test");
  47085. testSz = sizeof(testVectors) / sizeof(pkcs7CompressedVector);
  47086. for (i = 0; i < testSz; i++) {
  47087. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47088. if (pkcs7 == NULL) {
  47089. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47090. }
  47091. pkcs7->content = (byte*)testVectors[i].content;
  47092. pkcs7->contentSz = testVectors[i].contentSz;
  47093. pkcs7->contentOID = testVectors[i].contentOID;
  47094. /* encode compressedData */
  47095. compressedSz = wc_PKCS7_EncodeCompressedData(pkcs7, compressed,
  47096. PKCS7_BUF_SIZE);
  47097. if (compressedSz <= 0) {
  47098. wc_PKCS7_Free(pkcs7);
  47099. ERROR_OUT(WC_TEST_RET_ENC_EC(compressedSz), out);
  47100. }
  47101. /* decode compressedData */
  47102. decodedSz = wc_PKCS7_DecodeCompressedData(pkcs7, compressed,
  47103. compressedSz, decoded,
  47104. PKCS7_BUF_SIZE);
  47105. if (decodedSz <= 0){
  47106. wc_PKCS7_Free(pkcs7);
  47107. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47108. }
  47109. /* test decode result */
  47110. if (XMEMCMP(decoded, testVectors[i].content,
  47111. testVectors[i].contentSz) != 0) {
  47112. wc_PKCS7_Free(pkcs7);
  47113. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47114. }
  47115. /* make sure content type is the same */
  47116. if (testVectors[i].contentOID != pkcs7->contentOID) {
  47117. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47118. }
  47119. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47120. /* output pkcs7 compressedData for external testing */
  47121. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47122. if (!pkcs7File) {
  47123. wc_PKCS7_Free(pkcs7);
  47124. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47125. }
  47126. ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File);
  47127. if (ret < 0)
  47128. ret = WC_TEST_RET_ENC_ERRNO;
  47129. else
  47130. ret = 0;
  47131. XFCLOSE(pkcs7File);
  47132. #endif
  47133. wc_PKCS7_Free(pkcs7);
  47134. }
  47135. out:
  47136. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47137. XFREE(compressed, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47138. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47139. #endif
  47140. return ret;
  47141. } /* pkcs7compressed_test() */
  47142. #undef PKCS7_BUF_SIZE
  47143. #endif /* HAVE_LIBZ */
  47144. typedef struct {
  47145. const byte* content;
  47146. word32 contentSz;
  47147. int hashOID;
  47148. int signOID;
  47149. byte* privateKey;
  47150. word32 privateKeySz;
  47151. byte* cert;
  47152. size_t certSz;
  47153. byte* caCert;
  47154. size_t caCertSz;
  47155. PKCS7Attrib* signedAttribs;
  47156. word32 signedAttribsSz;
  47157. const char* outFileName;
  47158. int contentOID;
  47159. const byte* contentType;
  47160. word32 contentTypeSz;
  47161. int sidType;
  47162. int encryptOID; /* for single-shot encrypt alg OID */
  47163. int encCompFlag; /* for single-shot. 1 = enc, 2 = comp, 3 = both*/
  47164. const byte* encryptKey; /* for single-shot, encryptedData */
  47165. word32 encryptKeySz; /* for single-shot, encryptedData */
  47166. PKCS7Attrib* unprotectedAttribs; /* for single-shot, encryptedData */
  47167. word32 unprotectedAttribsSz; /* for single-shot, encryptedData */
  47168. word16 detachedSignature; /* generate detached signature (0:1) */
  47169. } pkcs7SignedVector;
  47170. static wc_test_ret_t pkcs7signed_run_vectors(
  47171. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47172. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47173. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47174. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47175. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47176. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47177. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47178. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47179. {
  47180. wc_test_ret_t ret;
  47181. int testSz = 0, i;
  47182. int encodedSz;
  47183. byte* out = NULL;
  47184. word32 outSz;
  47185. WC_RNG rng;
  47186. PKCS7* pkcs7 = NULL;
  47187. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47188. XFILE file;
  47189. #endif
  47190. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47191. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47192. 0x72,0x6c,0x64
  47193. };
  47194. static const byte transIdOid[] =
  47195. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47196. 0x09, 0x07 };
  47197. static const byte messageTypeOid[] =
  47198. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47199. 0x09, 0x02 };
  47200. static const byte senderNonceOid[] =
  47201. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47202. 0x09, 0x05 };
  47203. #ifndef NO_SHA
  47204. byte transId[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47205. #else
  47206. byte transId[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47207. #endif
  47208. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47209. byte senderNonce[PKCS7_NONCE_SZ + 2];
  47210. PKCS7Attrib attribs[] =
  47211. {
  47212. { transIdOid, sizeof(transIdOid), transId,
  47213. sizeof(transId) - 1 }, /* take off the null */
  47214. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47215. sizeof(messageType) },
  47216. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  47217. sizeof(senderNonce) }
  47218. };
  47219. /* for testing custom contentType, FirmwarePkgData */
  47220. static const byte customContentType[] = { 0x06, 0x0B, 0x2A, 0x86,
  47221. 0x48, 0x86, 0xF7, 0x0D,
  47222. 0x01, 0x09, 0x10, 0x01, 0x10 };
  47223. #define MAX_TESTVECTORS_LEN 20
  47224. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47225. const pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47226. if (testSz == MAX_TESTVECTORS_LEN) { \
  47227. ret = WC_TEST_RET_ENC_NC; \
  47228. goto out; \
  47229. } \
  47230. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47231. sizeof _this_vector); \
  47232. }
  47233. pkcs7SignedVector *testVectors = NULL;
  47234. XMEMSET(&rng, 0, sizeof(rng));
  47235. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47236. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47237. if (testVectors == NULL) {
  47238. ret = WC_TEST_RET_ENC_ERRNO;
  47239. goto out;
  47240. }
  47241. {
  47242. #ifndef NO_RSA
  47243. #ifndef NO_SHA
  47244. /* RSA with SHA */
  47245. ADD_PKCS7SIGNEDVECTOR(
  47246. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47247. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47248. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47249. "pkcs7signedData_RSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0, NULL,
  47250. 0, 0);
  47251. /* RSA with SHA, no signed attributes */
  47252. ADD_PKCS7SIGNEDVECTOR(
  47253. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47254. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz,
  47255. NULL, 0, NULL, 0,
  47256. "pkcs7signedData_RSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47257. NULL, 0, 0);
  47258. #endif
  47259. #ifdef WOLFSSL_SHA224
  47260. /* RSA with SHA224 */
  47261. ADD_PKCS7SIGNEDVECTOR(
  47262. data, (word32)sizeof(data), SHA224h, RSAk, rsaClientPrivKeyBuf,
  47263. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47264. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47265. "pkcs7signedData_RSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47266. NULL, 0, 0);
  47267. #endif
  47268. #ifndef NO_SHA256
  47269. /* RSA with SHA256 */
  47270. ADD_PKCS7SIGNEDVECTOR(
  47271. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47272. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47273. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47274. "pkcs7signedData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47275. NULL, 0, 0);
  47276. /* RSA with SHA256, detached signature */
  47277. ADD_PKCS7SIGNEDVECTOR(
  47278. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47279. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47280. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47281. "pkcs7signedData_RSA_SHA256_detachedSig.der", 0, NULL, 0, 0, 0, 0,
  47282. NULL, 0, NULL, 0, 1);
  47283. /* RSA with SHA256 and SubjectKeyIdentifier in SignerIdentifier */
  47284. ADD_PKCS7SIGNEDVECTOR(
  47285. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47286. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47287. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47288. "pkcs7signedData_RSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  47289. NULL, 0, NULL, 0, 0);
  47290. /* RSA with SHA256 and custom contentType */
  47291. ADD_PKCS7SIGNEDVECTOR(
  47292. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47293. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47294. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47295. "pkcs7signedData_RSA_SHA256_custom_contentType.der", 0,
  47296. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  47297. NULL, 0, 0);
  47298. /* RSA with SHA256 and FirmwarePkgData contentType */
  47299. ADD_PKCS7SIGNEDVECTOR(
  47300. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47301. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47302. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47303. "pkcs7signedData_RSA_SHA256_firmwarePkgData.der",
  47304. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47305. /* RSA with SHA256 using server cert and ca cert */
  47306. ADD_PKCS7SIGNEDVECTOR(
  47307. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  47308. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  47309. rsaCaCertBuf, rsaCaCertBufSz,
  47310. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47311. "pkcs7signedData_RSA_SHA256_with_ca_cert.der", 0, NULL, 0, 0, 0, 0,
  47312. NULL, 0, NULL, 0, 0);
  47313. #endif
  47314. #if defined(WOLFSSL_SHA384)
  47315. /* RSA with SHA384 */
  47316. ADD_PKCS7SIGNEDVECTOR(
  47317. data, (word32)sizeof(data), SHA384h, RSAk, rsaClientPrivKeyBuf,
  47318. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47319. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47320. "pkcs7signedData_RSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47321. NULL, 0, 0);
  47322. #endif
  47323. #if defined(WOLFSSL_SHA512)
  47324. /* RSA with SHA512 */
  47325. ADD_PKCS7SIGNEDVECTOR(
  47326. data, (word32)sizeof(data), SHA512h, RSAk, rsaClientPrivKeyBuf,
  47327. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47328. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47329. "pkcs7signedData_RSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47330. NULL, 0, 0);
  47331. #endif
  47332. #endif /* NO_RSA */
  47333. #ifdef HAVE_ECC
  47334. #ifndef NO_SHA
  47335. /* ECDSA with SHA */
  47336. ADD_PKCS7SIGNEDVECTOR(
  47337. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  47338. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47339. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47340. "pkcs7signedData_ECDSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47341. NULL, 0, 0);
  47342. /* ECDSA with SHA, no signed attributes */
  47343. ADD_PKCS7SIGNEDVECTOR(
  47344. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  47345. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz,
  47346. NULL, 0, NULL, 0,
  47347. "pkcs7signedData_ECDSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47348. NULL, 0, 0);
  47349. #endif
  47350. #ifdef WOLFSSL_SHA224
  47351. /* ECDSA with SHA224 */
  47352. ADD_PKCS7SIGNEDVECTOR(
  47353. data, (word32)sizeof(data), SHA224h, ECDSAk, eccClientPrivKeyBuf,
  47354. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47355. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47356. "pkcs7signedData_ECDSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47357. NULL, 0, 0);
  47358. #endif
  47359. #ifndef NO_SHA256
  47360. /* ECDSA with SHA256 */
  47361. ADD_PKCS7SIGNEDVECTOR(
  47362. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47363. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47364. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47365. "pkcs7signedData_ECDSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47366. NULL, 0, 0);
  47367. /* ECDSA with SHA256 and SubjectKeyIdentifier in SigherIdentifier */
  47368. ADD_PKCS7SIGNEDVECTOR(
  47369. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47370. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47371. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47372. "pkcs7signedData_ECDSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  47373. NULL, 0, NULL, 0, 0);
  47374. /* ECDSA with SHA256 and custom contentType */
  47375. ADD_PKCS7SIGNEDVECTOR(
  47376. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47377. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47378. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47379. "pkcs7signedData_ECDSA_SHA256_custom_contentType.der", 0,
  47380. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  47381. NULL, 0, 0);
  47382. /* ECDSA with SHA256 and FirmwarePkgData contentType */
  47383. ADD_PKCS7SIGNEDVECTOR(
  47384. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47385. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47386. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47387. "pkcs7signedData_ECDSA_SHA256_firmwarePkgData.der",
  47388. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47389. #endif
  47390. #ifdef WOLFSSL_SHA384
  47391. /* ECDSA with SHA384 */
  47392. ADD_PKCS7SIGNEDVECTOR(
  47393. data, (word32)sizeof(data), SHA384h, ECDSAk, eccClientPrivKeyBuf,
  47394. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47395. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47396. "pkcs7signedData_ECDSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47397. NULL, 0, 0);
  47398. #endif
  47399. #ifdef WOLFSSL_SHA512
  47400. /* ECDSA with SHA512 */
  47401. ADD_PKCS7SIGNEDVECTOR(
  47402. data, (word32)sizeof(data), SHA512h, ECDSAk, eccClientPrivKeyBuf,
  47403. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47404. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47405. "pkcs7signedData_ECDSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47406. NULL, 0, 0);
  47407. #endif
  47408. #endif /* HAVE_ECC */
  47409. };
  47410. #undef MAX_TESTVECTORS_LEN
  47411. #undef ADD_PKCS7SIGNEDVECTOR
  47412. outSz = FOURK_BUF;
  47413. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47414. if (out == NULL)
  47415. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47416. XMEMSET(out, 0, outSz);
  47417. /* test inner pad size error with block size being 0 */
  47418. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 0);
  47419. if (ret > 0)
  47420. ERROR_OUT(-1, out);
  47421. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  47422. if (ret < 0)
  47423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47424. #ifndef HAVE_FIPS
  47425. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  47426. #else
  47427. ret = wc_InitRng(&rng);
  47428. #endif
  47429. if (ret != 0)
  47430. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47431. for (i = 0; i < testSz; i++) {
  47432. if (pkcs7)
  47433. wc_PKCS7_Free(pkcs7);
  47434. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47435. if (pkcs7 == NULL)
  47436. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47437. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  47438. (word32)testVectors[i].certSz);
  47439. if (ret != 0)
  47440. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47441. /* load CA certificate, if present */
  47442. if (testVectors[i].caCert != NULL) {
  47443. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  47444. (word32)testVectors[i].caCertSz);
  47445. if (ret != 0)
  47446. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47447. }
  47448. pkcs7->rng = &rng;
  47449. pkcs7->content = (byte*)testVectors[i].content;
  47450. pkcs7->contentSz = testVectors[i].contentSz;
  47451. pkcs7->contentOID = testVectors[i].contentOID;
  47452. pkcs7->hashOID = testVectors[i].hashOID;
  47453. pkcs7->encryptOID = testVectors[i].signOID;
  47454. pkcs7->privateKey = testVectors[i].privateKey;
  47455. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  47456. pkcs7->signedAttribs = testVectors[i].signedAttribs;
  47457. pkcs7->signedAttribsSz = testVectors[i].signedAttribsSz;
  47458. /* optional custom contentType, default is DATA,
  47459. overrides contentOID if set */
  47460. if (testVectors[i].contentType != NULL) {
  47461. ret = wc_PKCS7_SetContentType(pkcs7,
  47462. (byte *)testVectors[i].contentType,
  47463. testVectors[i].contentTypeSz);
  47464. if (ret != 0)
  47465. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47466. }
  47467. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  47468. default is IssuerAndSerialNumber */
  47469. if (testVectors[i].sidType == CMS_SKID) {
  47470. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47471. if (ret != 0)
  47472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47473. }
  47474. /* generate senderNonce */
  47475. {
  47476. senderNonce[0] = 0x04;
  47477. senderNonce[1] = PKCS7_NONCE_SZ;
  47478. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  47479. if (ret != 0)
  47480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47481. }
  47482. /* generate transactionID (used with SCEP) */
  47483. {
  47484. #ifndef NO_SHA
  47485. wc_Sha sha;
  47486. byte digest[WC_SHA_DIGEST_SIZE];
  47487. #else
  47488. wc_Sha256 sha;
  47489. byte digest[WC_SHA256_DIGEST_SIZE];
  47490. #endif
  47491. int j,k;
  47492. transId[0] = 0x13;
  47493. transId[1] = sizeof(digest) * 2;
  47494. #ifndef NO_SHA
  47495. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  47496. if (ret != 0)
  47497. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47498. wc_ShaUpdate(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  47499. wc_ShaFinal(&sha, digest);
  47500. wc_ShaFree(&sha);
  47501. #else
  47502. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  47503. if (ret != 0)
  47504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47505. wc_Sha256Update(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  47506. wc_Sha256Final(&sha, digest);
  47507. wc_Sha256Free(&sha);
  47508. #endif
  47509. for (j = 0, k = 2; j < (int)sizeof(digest); j++, k += 2) {
  47510. (void)XSNPRINTF((char*)&transId[k], 3, "%02x", digest[j]);
  47511. }
  47512. }
  47513. /* enable detached signature generation, if set */
  47514. if (testVectors[i].detachedSignature == 1) {
  47515. ret = wc_PKCS7_SetDetached(pkcs7, 1);
  47516. if (ret != 0)
  47517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47518. }
  47519. encodedSz = wc_PKCS7_EncodeSignedData(pkcs7, out, outSz);
  47520. if (encodedSz < 0)
  47521. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47522. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47523. /* write PKCS#7 to output file for more testing */
  47524. file = XFOPEN(testVectors[i].outFileName, "wb");
  47525. if (!file) {
  47526. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47527. }
  47528. ret = (int)XFWRITE(out, 1, encodedSz, file);
  47529. XFCLOSE(file);
  47530. if (ret != (int)encodedSz)
  47531. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47532. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47533. wc_PKCS7_Free(pkcs7);
  47534. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47535. if (pkcs7 == NULL)
  47536. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47537. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47538. if (testVectors[i].detachedSignature == 1) {
  47539. /* set content for verifying detached signatures */
  47540. pkcs7->content = (byte*)testVectors[i].content;
  47541. pkcs7->contentSz = testVectors[i].contentSz;
  47542. }
  47543. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  47544. if (ret < 0)
  47545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47546. /* verify contentType extracted successfully for custom content types */
  47547. if (testVectors[i].contentTypeSz > 0) {
  47548. if (pkcs7->contentTypeSz != testVectors[i].contentTypeSz) {
  47549. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47550. } else if (XMEMCMP(pkcs7->contentType, testVectors[i].contentType,
  47551. pkcs7->contentTypeSz) != 0) {
  47552. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47553. }
  47554. }
  47555. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  47556. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47557. {
  47558. /* check getting signed attributes */
  47559. #ifndef NO_SHA
  47560. byte buf[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47561. #else
  47562. byte buf[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47563. #endif
  47564. const byte* oidPt = transIdOid + 2; /* skip object id tag and size */
  47565. int oidSz = (int)sizeof(transIdOid) - 2;
  47566. int bufSz = 0;
  47567. if (testVectors[i].signedAttribs != NULL) {
  47568. ret = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  47569. NULL, (word32*)&bufSz);
  47570. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  47571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47572. ret = 0;
  47573. }
  47574. if (bufSz > (int)sizeof(buf))
  47575. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47576. bufSz = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  47577. buf, (word32*)&bufSz);
  47578. if ((testVectors[i].signedAttribs != NULL && bufSz < 0) ||
  47579. (testVectors[i].signedAttribs == NULL && bufSz > 0))
  47580. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47581. }
  47582. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47583. file = XFOPEN("./pkcs7cert.der", "wb");
  47584. if (!file)
  47585. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47586. ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file);
  47587. if (ret < 0)
  47588. ret = WC_TEST_RET_ENC_ERRNO;
  47589. else
  47590. ret = 0;
  47591. XFCLOSE(file);
  47592. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47593. }
  47594. out:
  47595. if (pkcs7 != NULL)
  47596. wc_PKCS7_Free(pkcs7);
  47597. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47598. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47599. wc_FreeRng(&rng);
  47600. if (ret > 0)
  47601. return 0;
  47602. (void)rsaClientCertBuf;
  47603. (void)rsaClientCertBufSz;
  47604. (void)rsaClientPrivKeyBuf;
  47605. (void)rsaClientPrivKeyBufSz;
  47606. (void)rsaServerCertBuf;
  47607. (void)rsaServerCertBufSz;
  47608. (void)rsaServerPrivKeyBuf;
  47609. (void)rsaServerPrivKeyBufSz;
  47610. (void)rsaCaCertBuf;
  47611. (void)rsaCaCertBufSz;
  47612. (void)rsaCaPrivKeyBuf;
  47613. (void)rsaCaPrivKeyBufSz;
  47614. (void)eccClientCertBuf;
  47615. (void)eccClientCertBufSz;
  47616. (void)eccClientPrivKeyBuf;
  47617. (void)eccClientPrivKeyBufSz;
  47618. return ret;
  47619. }
  47620. static wc_test_ret_t pkcs7signed_run_SingleShotVectors(
  47621. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47622. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47623. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47624. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47625. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47626. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47627. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47628. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47629. {
  47630. wc_test_ret_t ret;
  47631. int testSz = 0, i;
  47632. int encodedSz;
  47633. byte* out = NULL;
  47634. word32 outSz;
  47635. WC_RNG rng;
  47636. PKCS7* pkcs7 = NULL;
  47637. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47638. XFILE file;
  47639. #endif
  47640. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  47641. !defined(NO_PKCS7_ENCRYPTED_DATA)
  47642. byte* encryptedTmp = NULL;
  47643. int encryptedTmpSz;
  47644. #endif
  47645. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47646. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47647. 0x72,0x6c,0x64
  47648. };
  47649. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  47650. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  47651. static const byte aes256Key[] = {
  47652. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47653. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47654. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47655. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47656. };
  47657. #endif
  47658. static const byte messageTypeOid[] =
  47659. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47660. 0x09, 0x02 };
  47661. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47662. PKCS7Attrib attribs[] =
  47663. {
  47664. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47665. sizeof(messageType) },
  47666. };
  47667. #define MAX_TESTVECTORS_LEN 19
  47668. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47669. pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47670. if (testSz == MAX_TESTVECTORS_LEN) { \
  47671. ret = WC_TEST_RET_ENC_NC; \
  47672. goto out; \
  47673. } \
  47674. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47675. sizeof _this_vector); \
  47676. }
  47677. pkcs7SignedVector *testVectors = NULL;
  47678. XMEMSET(&rng, 0, sizeof(rng));
  47679. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47680. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47681. if (testVectors == NULL) {
  47682. ret = WC_TEST_RET_ENC_ERRNO;
  47683. goto out;
  47684. }
  47685. {
  47686. #ifndef NO_RSA
  47687. #ifndef NO_SHA256
  47688. /* Signed FirmwarePkgData, RSA, SHA256, no attribs */
  47689. ADD_PKCS7SIGNEDVECTOR(
  47690. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47691. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47692. NULL, 0,
  47693. "pkcs7signedFirmwarePkgData_RSA_SHA256_noattr.der", 0, NULL, 0, 0,
  47694. 0, 0, NULL, 0, NULL, 0, 0);
  47695. /* Signed FirmwarePkgData, RSA, SHA256, attrs */
  47696. ADD_PKCS7SIGNEDVECTOR(
  47697. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47698. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47699. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47700. "pkcs7signedFirmwarePkgData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0,
  47701. NULL, 0, NULL, 0, 0);
  47702. /* Signed FirmwarePkgData, RSA, SHA256, SubjectKeyIdentifier, attrs */
  47703. ADD_PKCS7SIGNEDVECTOR(
  47704. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47705. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47706. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47707. "pkcs7signedFirmwarePkgData_RSA_SHA256_SKID.der", 0, NULL,
  47708. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  47709. /* Signed FirmwraePkgData, RSA, SHA256, server cert and ca cert, attr */
  47710. ADD_PKCS7SIGNEDVECTOR(
  47711. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  47712. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  47713. rsaCaCertBuf, rsaCaCertBufSz,
  47714. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47715. "pkcs7signedFirmwarePkgData_RSA_SHA256_with_ca_cert.der", 0, NULL,
  47716. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47717. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  47718. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  47719. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, no attribs */
  47720. ADD_PKCS7SIGNEDVECTOR(
  47721. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47722. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47723. NULL, 0,
  47724. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  47725. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  47726. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, attribs */
  47727. ADD_PKCS7SIGNEDVECTOR(
  47728. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47729. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47730. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47731. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256.der", 0,
  47732. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  47733. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  47734. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  47735. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47736. /* Signed Compressed FirmwarePkgData, RSA, SHA256, no attribs */
  47737. ADD_PKCS7SIGNEDVECTOR(
  47738. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47739. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47740. NULL, 0,
  47741. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  47742. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  47743. /* Signed Compressed FirmwarePkgData, RSA, SHA256, attribs */
  47744. ADD_PKCS7SIGNEDVECTOR(
  47745. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47746. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47747. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47748. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256.der", 0,
  47749. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  47750. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47751. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  47752. no attribs */
  47753. ADD_PKCS7SIGNEDVECTOR(
  47754. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47755. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47756. NULL, 0,
  47757. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der",
  47758. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  47759. 0, 0);
  47760. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  47761. attribs */
  47762. ADD_PKCS7SIGNEDVECTOR(
  47763. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47764. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47765. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47766. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256.der",
  47767. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  47768. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  47769. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  47770. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  47771. #endif /* NO_SHA256 */
  47772. #endif /* NO_RSA */
  47773. #ifdef HAVE_ECC
  47774. #ifndef NO_SHA256
  47775. /* Signed FirmwarePkgData, ECDSA, SHA256, no attribs */
  47776. ADD_PKCS7SIGNEDVECTOR(
  47777. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47778. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47779. NULL, 0,
  47780. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  47781. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47782. /* Signed FirmwarePkgData, ECDSA, SHA256, attribs */
  47783. ADD_PKCS7SIGNEDVECTOR(
  47784. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47785. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47786. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47787. "pkcs7signedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  47788. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47789. /* Signed FirmwarePkgData, ECDSA, SHA256, SubjectKeyIdentifier, attr */
  47790. ADD_PKCS7SIGNEDVECTOR(
  47791. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47792. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47793. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47794. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_SKID.der", 0, NULL,
  47795. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  47796. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  47797. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  47798. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, no attribs */
  47799. ADD_PKCS7SIGNEDVECTOR(
  47800. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47801. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47802. NULL, 0,
  47803. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  47804. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  47805. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, attribs */
  47806. ADD_PKCS7SIGNEDVECTOR(
  47807. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47808. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47809. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47810. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  47811. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  47812. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  47813. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  47814. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47815. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, no attribs */
  47816. ADD_PKCS7SIGNEDVECTOR(
  47817. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47818. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47819. NULL, 0,
  47820. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  47821. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  47822. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, attrib */
  47823. ADD_PKCS7SIGNEDVECTOR(
  47824. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47825. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47826. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47827. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  47828. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  47829. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47830. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  47831. no attribs */
  47832. ADD_PKCS7SIGNEDVECTOR(
  47833. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47834. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47835. NULL, 0,
  47836. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der",
  47837. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  47838. 0, 0);
  47839. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  47840. attribs */
  47841. ADD_PKCS7SIGNEDVECTOR(
  47842. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47843. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47844. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47845. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256.der",
  47846. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  47847. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  47848. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  47849. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  47850. #endif /* NO_SHA256 */
  47851. #endif /* HAVE_ECC */
  47852. };
  47853. #undef MAX_TESTVECTORS_LEN
  47854. #undef ADD_PKCS7SIGNEDVECTOR
  47855. outSz = FOURK_BUF;
  47856. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47857. if (out == NULL)
  47858. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47859. XMEMSET(out, 0, outSz);
  47860. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  47861. if (ret < 0)
  47862. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47863. #ifndef HAVE_FIPS
  47864. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  47865. #else
  47866. ret = wc_InitRng(&rng);
  47867. #endif
  47868. if (ret != 0)
  47869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47870. for (i = 0; i < testSz; i++) {
  47871. if (pkcs7)
  47872. wc_PKCS7_Free(pkcs7);
  47873. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47874. if (pkcs7 == NULL)
  47875. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47876. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  47877. (word32)testVectors[i].certSz);
  47878. if (ret != 0)
  47879. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47880. /* load CA certificate, if present */
  47881. if (testVectors[i].caCert != NULL) {
  47882. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  47883. (word32)testVectors[i].caCertSz);
  47884. if (ret != 0)
  47885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47886. }
  47887. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  47888. default is IssuerAndSerialNumber */
  47889. if (testVectors[i].sidType == CMS_SKID) {
  47890. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47891. if (ret != 0)
  47892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47893. }
  47894. if (testVectors[i].encCompFlag == 0) {
  47895. /* encode Signed FirmwarePkgData */
  47896. encodedSz = wc_PKCS7_EncodeSignedFPD(pkcs7,
  47897. testVectors[i].privateKey, testVectors[i].privateKeySz,
  47898. testVectors[i].signOID, testVectors[i].hashOID,
  47899. (byte*)testVectors[i].content, testVectors[i].contentSz,
  47900. testVectors[i].signedAttribs,
  47901. testVectors[i].signedAttribsSz, out, outSz);
  47902. if (encodedSz < 0)
  47903. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47904. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47905. } else if (testVectors[i].encCompFlag == 1) {
  47906. /* encode Signed Encrypted FirmwarePkgData */
  47907. encodedSz = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7,
  47908. (byte *)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  47909. testVectors[i].privateKey, testVectors[i].privateKeySz,
  47910. testVectors[i].encryptOID, testVectors[i].signOID,
  47911. testVectors[i].hashOID, (byte*)testVectors[i].content,
  47912. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  47913. testVectors[i].unprotectedAttribsSz,
  47914. testVectors[i].signedAttribs,
  47915. testVectors[i].signedAttribsSz, out, outSz);
  47916. if (encodedSz <= 0)
  47917. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47918. #endif
  47919. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47920. } else if (testVectors[i].encCompFlag == 2) {
  47921. /* encode Signed Compressed FirmwarePkgData */
  47922. encodedSz = wc_PKCS7_EncodeSignedCompressedFPD(pkcs7,
  47923. testVectors[i].privateKey, testVectors[i].privateKeySz,
  47924. testVectors[i].signOID, testVectors[i].hashOID,
  47925. (byte*)testVectors[i].content, testVectors[i].contentSz,
  47926. testVectors[i].signedAttribs,
  47927. testVectors[i].signedAttribsSz, out, outSz);
  47928. if (encodedSz <= 0)
  47929. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47930. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47931. } else if (testVectors[i].encCompFlag == 3) {
  47932. /* encode Signed Encrypted Compressed FirmwarePkgData */
  47933. encodedSz = wc_PKCS7_EncodeSignedEncryptedCompressedFPD(pkcs7,
  47934. (byte*)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  47935. testVectors[i].privateKey, testVectors[i].privateKeySz,
  47936. testVectors[i].encryptOID, testVectors[i].signOID,
  47937. testVectors[i].hashOID, (byte*)testVectors[i].content,
  47938. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  47939. testVectors[i].unprotectedAttribsSz,
  47940. testVectors[i].signedAttribs,
  47941. testVectors[i].signedAttribsSz, out, outSz);
  47942. if (encodedSz <= 0)
  47943. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47944. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47945. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  47946. } else {
  47947. /* unsupported SignedData single-shot combination */
  47948. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47949. }
  47950. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47951. /* write PKCS#7 to output file for more testing */
  47952. file = XFOPEN(testVectors[i].outFileName, "wb");
  47953. if (!file)
  47954. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47955. ret = (int)XFWRITE(out, 1, encodedSz, file);
  47956. XFCLOSE(file);
  47957. file = NULL;
  47958. if (ret != (int)encodedSz)
  47959. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47960. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47961. wc_PKCS7_Free(pkcs7);
  47962. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47963. if (pkcs7 == NULL)
  47964. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47965. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47966. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  47967. if (ret < 0)
  47968. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47969. #ifndef NO_PKCS7_STREAM
  47970. {
  47971. word32 z;
  47972. for (z = 0; z < outSz && ret != 0; z++) {
  47973. ret = wc_PKCS7_VerifySignedData(pkcs7, out + z, 1);
  47974. if (ret < 0 && ret != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  47975. printf("unexpected error %d\n", ret);
  47976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47977. }
  47978. }
  47979. }
  47980. #endif
  47981. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  47982. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47983. if (testVectors[i].encCompFlag == 0) {
  47984. /* verify decoded content matches expected */
  47985. if ((pkcs7->contentSz != testVectors[i].contentSz) ||
  47986. XMEMCMP(pkcs7->content, testVectors[i].content,
  47987. pkcs7->contentSz)) {
  47988. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47989. }
  47990. }
  47991. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47992. else if (testVectors[i].encCompFlag == 1) {
  47993. /* decrypt inner encryptedData */
  47994. pkcs7->encryptionKey = (byte *)testVectors[i].encryptKey;
  47995. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  47996. ret = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  47997. pkcs7->contentSz, out, outSz);
  47998. if (ret < 0)
  47999. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48000. /* compare decrypted to expected */
  48001. if (((word32)ret != testVectors[i].contentSz) ||
  48002. XMEMCMP(out, testVectors[i].content, ret))
  48003. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48004. }
  48005. #endif
  48006. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48007. else if (testVectors[i].encCompFlag == 2) {
  48008. /* decompress inner compressedData */
  48009. ret = wc_PKCS7_DecodeCompressedData(pkcs7, pkcs7->content,
  48010. pkcs7->contentSz, out, outSz);
  48011. if (ret < 0)
  48012. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48013. /* compare decompressed to expected */
  48014. if (((word32)ret != testVectors[i].contentSz) ||
  48015. XMEMCMP(out, testVectors[i].content, ret))
  48016. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48017. }
  48018. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48019. else if (testVectors[i].encCompFlag == 3) {
  48020. encryptedTmpSz = FOURK_BUF;
  48021. encryptedTmp = (byte*)XMALLOC(encryptedTmpSz, HEAP_HINT,
  48022. DYNAMIC_TYPE_TMP_BUFFER);
  48023. if (encryptedTmp == NULL)
  48024. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48025. XMEMSET(encryptedTmp, 0, encryptedTmpSz);
  48026. /* decrypt inner encryptedData */
  48027. pkcs7->encryptionKey = (byte*)testVectors[i].encryptKey;
  48028. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48029. encryptedTmpSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48030. pkcs7->contentSz, encryptedTmp,
  48031. encryptedTmpSz);
  48032. if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA)
  48033. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48034. /* decompress inner compressedData */
  48035. ret = wc_PKCS7_DecodeCompressedData(pkcs7, encryptedTmp,
  48036. encryptedTmpSz, out, outSz);
  48037. if (ret < 0)
  48038. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48039. /* compare decompressed to expected */
  48040. if (((word32)ret != testVectors[i].contentSz) ||
  48041. XMEMCMP(out, testVectors[i].content, ret))
  48042. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48043. }
  48044. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48045. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48046. }
  48047. out:
  48048. if (pkcs7 != NULL)
  48049. wc_PKCS7_Free(pkcs7);
  48050. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48051. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48052. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48053. XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48054. #endif
  48055. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48056. wc_FreeRng(&rng);
  48057. if (ret > 0)
  48058. return 0;
  48059. (void)eccClientCertBuf;
  48060. (void)eccClientCertBufSz;
  48061. (void)eccClientPrivKeyBuf;
  48062. (void)eccClientPrivKeyBufSz;
  48063. (void)rsaClientCertBuf;
  48064. (void)rsaClientCertBufSz;
  48065. (void)rsaClientPrivKeyBuf;
  48066. (void)rsaClientPrivKeyBufSz;
  48067. (void)rsaServerCertBuf;
  48068. (void)rsaServerCertBufSz;
  48069. (void)rsaServerPrivKeyBuf;
  48070. (void)rsaServerPrivKeyBufSz;
  48071. (void)rsaCaCertBuf;
  48072. (void)rsaCaCertBufSz;
  48073. (void)rsaCaPrivKeyBuf;
  48074. (void)rsaCaPrivKeyBufSz;
  48075. return ret;
  48076. }
  48077. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void)
  48078. {
  48079. wc_test_ret_t ret = 0;
  48080. byte* rsaClientCertBuf = NULL;
  48081. byte* rsaServerCertBuf = NULL;
  48082. byte* rsaCaCertBuf = NULL;
  48083. byte* eccClientCertBuf = NULL;
  48084. byte* rsaClientPrivKeyBuf = NULL;
  48085. byte* rsaServerPrivKeyBuf = NULL;
  48086. byte* rsaCaPrivKeyBuf = NULL;
  48087. byte* eccClientPrivKeyBuf = NULL;
  48088. word32 rsaClientCertBufSz = 0;
  48089. word32 rsaServerCertBufSz = 0;
  48090. word32 rsaCaCertBufSz = 0;
  48091. word32 eccClientCertBufSz = 0;
  48092. word32 rsaClientPrivKeyBufSz = 0;
  48093. word32 rsaServerPrivKeyBufSz = 0;
  48094. word32 rsaCaPrivKeyBufSz = 0;
  48095. word32 eccClientPrivKeyBufSz = 0;
  48096. WOLFSSL_ENTER("pkcs7signed_test");
  48097. #ifndef NO_RSA
  48098. /* read client RSA cert and key in DER format */
  48099. rsaClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48100. DYNAMIC_TYPE_TMP_BUFFER);
  48101. if (rsaClientCertBuf == NULL)
  48102. ret = WC_TEST_RET_ENC_NC;
  48103. rsaClientPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48104. DYNAMIC_TYPE_TMP_BUFFER);
  48105. if (ret == 0 && rsaClientPrivKeyBuf == NULL) {
  48106. ret = WC_TEST_RET_ENC_ERRNO;
  48107. }
  48108. rsaClientCertBufSz = FOURK_BUF;
  48109. rsaClientPrivKeyBufSz = FOURK_BUF;
  48110. /* read server RSA cert and key in DER format */
  48111. rsaServerCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48112. DYNAMIC_TYPE_TMP_BUFFER);
  48113. if (ret == 0 && rsaServerCertBuf == NULL)
  48114. ret = WC_TEST_RET_ENC_NC;
  48115. rsaServerPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48116. DYNAMIC_TYPE_TMP_BUFFER);
  48117. if (ret == 0 && rsaServerPrivKeyBuf == NULL) {
  48118. ret = WC_TEST_RET_ENC_ERRNO;
  48119. }
  48120. rsaServerCertBufSz = FOURK_BUF;
  48121. rsaServerPrivKeyBufSz = FOURK_BUF;
  48122. /* read CA RSA cert and key in DER format, for use with server cert */
  48123. rsaCaCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48124. DYNAMIC_TYPE_TMP_BUFFER);
  48125. if (ret == 0 && rsaCaCertBuf == NULL)
  48126. ret = WC_TEST_RET_ENC_NC;
  48127. rsaCaPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48128. DYNAMIC_TYPE_TMP_BUFFER);
  48129. if (ret == 0 && rsaCaPrivKeyBuf == NULL) {
  48130. ret = WC_TEST_RET_ENC_ERRNO;
  48131. }
  48132. rsaCaCertBufSz = FOURK_BUF;
  48133. rsaCaPrivKeyBufSz = FOURK_BUF;
  48134. #endif /* NO_RSA */
  48135. #ifdef HAVE_ECC
  48136. /* read client ECC cert and key in DER format */
  48137. eccClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48138. DYNAMIC_TYPE_TMP_BUFFER);
  48139. if (ret == 0 && eccClientCertBuf == NULL) {
  48140. ret = WC_TEST_RET_ENC_ERRNO;
  48141. }
  48142. eccClientPrivKeyBuf =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48143. DYNAMIC_TYPE_TMP_BUFFER);
  48144. if (ret == 0 && eccClientPrivKeyBuf == NULL) {
  48145. ret = WC_TEST_RET_ENC_ERRNO;
  48146. }
  48147. eccClientCertBufSz = FOURK_BUF;
  48148. eccClientPrivKeyBufSz = FOURK_BUF;
  48149. #endif /* HAVE_ECC */
  48150. if (ret >= 0)
  48151. ret = pkcs7_load_certs_keys(rsaClientCertBuf, &rsaClientCertBufSz,
  48152. rsaClientPrivKeyBuf, &rsaClientPrivKeyBufSz,
  48153. rsaServerCertBuf, &rsaServerCertBufSz,
  48154. rsaServerPrivKeyBuf, &rsaServerPrivKeyBufSz,
  48155. rsaCaCertBuf, &rsaCaCertBufSz,
  48156. rsaCaPrivKeyBuf, &rsaCaPrivKeyBufSz,
  48157. eccClientCertBuf, &eccClientCertBufSz,
  48158. eccClientPrivKeyBuf, &eccClientPrivKeyBufSz);
  48159. if (ret < 0) {
  48160. ret = WC_TEST_RET_ENC_EC(ret);
  48161. }
  48162. if (ret >= 0)
  48163. ret = pkcs7signed_run_vectors(rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48164. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48165. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48166. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48167. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48168. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48169. eccClientCertBuf, (word32)eccClientCertBufSz,
  48170. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48171. if (ret >= 0)
  48172. ret = pkcs7signed_run_SingleShotVectors(
  48173. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48174. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48175. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48176. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48177. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48178. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48179. eccClientCertBuf, (word32)eccClientCertBufSz,
  48180. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48181. #if !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  48182. if (ret >= 0)
  48183. ret = pkcs7callback_test(
  48184. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48185. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz);
  48186. #endif
  48187. XFREE(rsaClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48188. XFREE(rsaClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48189. XFREE(rsaServerCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48190. XFREE(rsaServerPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48191. XFREE(rsaCaCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48192. XFREE(rsaCaPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48193. XFREE(eccClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48194. XFREE(eccClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48195. return ret;
  48196. }
  48197. #endif /* HAVE_PKCS7 */
  48198. #if defined(WOLFSSL_PUBLIC_MP) && \
  48199. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48200. defined(USE_FAST_MATH))
  48201. /* Maximum number of bytes in a number to test. */
  48202. #define MP_MAX_TEST_BYTE_LEN 32
  48203. static wc_test_ret_t randNum(mp_int* n, int len, WC_RNG* rng, void* heap)
  48204. {
  48205. byte d[MP_MAX_TEST_BYTE_LEN];
  48206. wc_test_ret_t ret;
  48207. (void)heap;
  48208. do {
  48209. ret = wc_RNG_GenerateBlock(rng, d, (word32)len);
  48210. if (ret != 0)
  48211. return ret;
  48212. ret = mp_read_unsigned_bin(n, d, (word32)len);
  48213. if (ret != 0)
  48214. return ret;
  48215. } while (mp_iszero(n));
  48216. return 0;
  48217. }
  48218. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  48219. static wc_test_ret_t mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng)
  48220. {
  48221. int i, j;
  48222. mp_digit rem;
  48223. mp_digit rem2;
  48224. wc_test_ret_t ret;
  48225. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48226. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  48227. for (i = 0; i < 10; i++) {
  48228. for (j = 1; j < 10; j++) {
  48229. ret = randNum(a, j, rng, NULL);
  48230. if (ret != 0)
  48231. return WC_TEST_RET_ENC_EC(ret);
  48232. ret = mp_div_3(a, r, &rem);
  48233. if (ret != 0)
  48234. return WC_TEST_RET_ENC_EC(ret);
  48235. ret = mp_mul_d(r, 3, r);
  48236. if (ret != 0)
  48237. return WC_TEST_RET_ENC_EC(ret);
  48238. ret = mp_add_d(r, rem, r);
  48239. if (ret != 0)
  48240. return WC_TEST_RET_ENC_EC(ret);
  48241. ret = mp_cmp(r, a);
  48242. if (ret != MP_EQ)
  48243. return WC_TEST_RET_ENC_NC;
  48244. }
  48245. }
  48246. ret = mp_div_3(a, r, &rem);
  48247. if (ret != 0)
  48248. return WC_TEST_RET_ENC_NC;
  48249. ret = mp_div_3(a, a, NULL);
  48250. if (ret != 0)
  48251. return WC_TEST_RET_ENC_NC;
  48252. ret = mp_cmp(r, a);
  48253. if (ret != MP_EQ)
  48254. return WC_TEST_RET_ENC_NC;
  48255. #endif
  48256. #if defined(WOLFSSL_SP_MATH_ALL)
  48257. ret = mp_div_d(a, 10, r, &rem);
  48258. if (ret != 0)
  48259. return WC_TEST_RET_ENC_EC(ret);
  48260. ret = mp_div_d(a, 10, a, NULL);
  48261. if (ret != 0)
  48262. return WC_TEST_RET_ENC_EC(ret);
  48263. ret = mp_cmp(r, a);
  48264. if (ret != MP_EQ)
  48265. return WC_TEST_RET_ENC_NC;
  48266. ret = mp_div_d(a, 12, r, &rem);
  48267. if (ret != 0)
  48268. return WC_TEST_RET_ENC_EC(ret);
  48269. ret = mp_div_d(a, 12, a, NULL);
  48270. if (ret != 0)
  48271. return WC_TEST_RET_ENC_EC(ret);
  48272. ret = mp_cmp(r, a);
  48273. if (ret != MP_EQ)
  48274. return WC_TEST_RET_ENC_NC;
  48275. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem);
  48276. if (ret != 0)
  48277. return WC_TEST_RET_ENC_EC(ret);
  48278. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2);
  48279. if (ret != 0)
  48280. return WC_TEST_RET_ENC_EC(ret);
  48281. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL);
  48282. if (ret != 0)
  48283. return WC_TEST_RET_ENC_EC(ret);
  48284. ret = mp_cmp(r, a);
  48285. if (ret != MP_EQ)
  48286. return WC_TEST_RET_ENC_NC;
  48287. if (rem != rem2)
  48288. return WC_TEST_RET_ENC_NC;
  48289. #endif
  48290. (void)a;
  48291. (void)r;
  48292. (void)rng;
  48293. (void)i;
  48294. (void)j;
  48295. (void)rem;
  48296. (void)rem2;
  48297. (void)ret;
  48298. return 0;
  48299. }
  48300. #endif /* WOLFSSL_SP_MATH || !USE_FAST_MATH */
  48301. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  48302. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48303. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  48304. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  48305. static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
  48306. {
  48307. wc_test_ret_t ret;
  48308. int i, j;
  48309. int size;
  48310. char str[30];
  48311. WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = "A";
  48312. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "a";
  48313. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  48314. WOLFSSL_SMALL_STACK_STATIC const char* zeros = "000";
  48315. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  48316. for (i = 0; i < 10; i++) {
  48317. for (j = 2; j < 12; j++) {
  48318. ret = randNum(a, j, rng, NULL);
  48319. if (ret != 0)
  48320. return WC_TEST_RET_ENC_EC(ret);
  48321. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  48322. if (ret != MP_OKAY)
  48323. return WC_TEST_RET_ENC_EC(ret);
  48324. ret = mp_toradix(a, str, MP_RADIX_DEC);
  48325. if (ret != MP_OKAY)
  48326. return WC_TEST_RET_ENC_EC(ret);
  48327. if ((int)XSTRLEN(str) != size - 1)
  48328. return WC_TEST_RET_ENC_NC;
  48329. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  48330. if (ret != MP_OKAY)
  48331. return WC_TEST_RET_ENC_EC(ret);
  48332. ret = mp_cmp(a, r);
  48333. if (ret != MP_EQ)
  48334. return WC_TEST_RET_ENC_NC;
  48335. }
  48336. }
  48337. ret = mp_read_radix(r, badStr1, MP_RADIX_DEC);
  48338. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48339. return WC_TEST_RET_ENC_EC(ret);
  48340. ret = mp_read_radix(r, badStr2, MP_RADIX_DEC);
  48341. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48342. return WC_TEST_RET_ENC_EC(ret);
  48343. ret = mp_read_radix(r, empty2, MP_RADIX_DEC);
  48344. if (ret != MP_OKAY)
  48345. return WC_TEST_RET_ENC_EC(ret);
  48346. ret = mp_read_radix(r, zeros, MP_RADIX_DEC);
  48347. if (ret != MP_OKAY)
  48348. return WC_TEST_RET_ENC_EC(ret);
  48349. if (!mp_iszero(r))
  48350. return WC_TEST_RET_ENC_NC;
  48351. mp_set(r, 1);
  48352. ret = mp_read_radix(r, empty, MP_RADIX_DEC);
  48353. if (ret != MP_OKAY)
  48354. return WC_TEST_RET_ENC_EC(ret);
  48355. if (!mp_iszero(r))
  48356. return WC_TEST_RET_ENC_NC;
  48357. mp_zero(a);
  48358. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  48359. if (ret != 0)
  48360. return WC_TEST_RET_ENC_EC(ret);
  48361. if (size != 2)
  48362. return WC_TEST_RET_ENC_NC;
  48363. ret = mp_toradix(a, str, MP_RADIX_DEC);
  48364. if (ret != 0)
  48365. return WC_TEST_RET_ENC_EC(ret);
  48366. if ((int)XSTRLEN(str) != size - 1)
  48367. return WC_TEST_RET_ENC_NC;
  48368. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  48369. if (ret != 0)
  48370. return WC_TEST_RET_ENC_EC(ret);
  48371. if (!mp_iszero(r))
  48372. return WC_TEST_RET_ENC_NC;
  48373. return 0;
  48374. }
  48375. #endif
  48376. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  48377. defined(HAVE_ECC))
  48378. static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
  48379. {
  48380. wc_test_ret_t ret;
  48381. int i, j;
  48382. int size;
  48383. char str[30];
  48384. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  48385. static char longStr[2 * sizeof(a->dp) + 2];
  48386. #endif
  48387. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  48388. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "}";
  48389. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  48390. for (i = 0; i < 10; i++) {
  48391. for (j = 2; j < 12; j++) {
  48392. ret = randNum(a, j, rng, NULL);
  48393. if (ret != 0)
  48394. return WC_TEST_RET_ENC_EC(ret);
  48395. mp_radix_size(a, MP_RADIX_HEX, &size);
  48396. mp_toradix(a, str, MP_RADIX_HEX);
  48397. if ((int)XSTRLEN(str) != size - 1)
  48398. return WC_TEST_RET_ENC_NC;
  48399. mp_read_radix(r, str, MP_RADIX_HEX);
  48400. ret = mp_cmp(a, r);
  48401. if (ret != MP_EQ)
  48402. return WC_TEST_RET_ENC_NC;
  48403. }
  48404. }
  48405. ret = mp_read_radix(r, empty2, MP_RADIX_HEX);
  48406. if (ret != MP_OKAY)
  48407. return WC_TEST_RET_ENC_EC(ret);
  48408. ret = mp_read_radix(r, badStr2, MP_RADIX_HEX);
  48409. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48410. return WC_TEST_RET_ENC_EC(ret);
  48411. mp_set(r, 1);
  48412. ret = mp_read_radix(r, empty, MP_RADIX_HEX);
  48413. if (ret != MP_OKAY)
  48414. return WC_TEST_RET_ENC_EC(ret);
  48415. if (!mp_iszero(r))
  48416. return WC_TEST_RET_ENC_NC;
  48417. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  48418. /* Fixed MP data size - string can be too long. */
  48419. longStr[0] = '8';
  48420. XMEMSET(longStr+1, '0', sizeof(longStr) - 2);
  48421. longStr[sizeof(longStr)-1] = '\0';
  48422. ret = mp_read_radix(r, longStr, MP_RADIX_HEX);
  48423. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48424. return WC_TEST_RET_ENC_EC(ret);
  48425. #endif
  48426. mp_zero(a);
  48427. ret = mp_radix_size(a, MP_RADIX_HEX, &size);
  48428. if (ret != 0)
  48429. return WC_TEST_RET_ENC_EC(ret);
  48430. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  48431. if (size != 3)
  48432. #else
  48433. if (size != 2)
  48434. #endif
  48435. return WC_TEST_RET_ENC_NC;
  48436. ret = mp_toradix(a, str, MP_RADIX_HEX);
  48437. if (ret != 0)
  48438. return WC_TEST_RET_ENC_EC(ret);
  48439. if ((int)XSTRLEN(str) != size - 1)
  48440. return WC_TEST_RET_ENC_NC;
  48441. ret = mp_read_radix(r, str, MP_RADIX_HEX);
  48442. if (ret != 0)
  48443. return WC_TEST_RET_ENC_EC(ret);
  48444. if (!mp_iszero(r))
  48445. return WC_TEST_RET_ENC_NC;
  48446. #ifdef WOLFSSL_SP_MATH
  48447. ret = mp_toradix(a, str, 8);
  48448. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48449. return WC_TEST_RET_ENC_EC(ret);
  48450. ret = mp_radix_size(a, 8, &size);
  48451. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48452. return WC_TEST_RET_ENC_EC(ret);
  48453. #endif
  48454. return 0;
  48455. }
  48456. #endif
  48457. static wc_test_ret_t mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng)
  48458. {
  48459. int i;
  48460. wc_test_ret_t ret;
  48461. ret = randNum(a, 4, rng, NULL);
  48462. if (ret != 0)
  48463. return WC_TEST_RET_ENC_EC(ret);
  48464. for (i = 0; i < 4; i++) {
  48465. mp_copy(r1, a);
  48466. ret = mp_lshd(r1, i);
  48467. if (ret != MP_OKAY)
  48468. return WC_TEST_RET_ENC_EC(ret);
  48469. #ifndef WOLFSSL_SP_MATH
  48470. mp_rshd(r1, i);
  48471. #else
  48472. mp_rshb(r1, i * SP_WORD_SIZE);
  48473. #endif
  48474. ret = mp_cmp(a, r1);
  48475. if (ret != MP_EQ)
  48476. return WC_TEST_RET_ENC_NC;
  48477. }
  48478. #ifndef WOLFSSL_SP_MATH
  48479. for (i = 0; i < DIGIT_BIT+1; i++) {
  48480. ret = mp_mul_2d(a, i, r1);
  48481. if (ret != MP_OKAY)
  48482. return WC_TEST_RET_ENC_EC(ret);
  48483. mp_rshb(r1, i);
  48484. ret = mp_cmp(a, r1);
  48485. if (ret != MP_EQ)
  48486. return WC_TEST_RET_ENC_NC;
  48487. }
  48488. #endif
  48489. return 0;
  48490. }
  48491. static wc_test_ret_t mp_test_add_sub_d(mp_int* a, mp_int* r1)
  48492. {
  48493. int i, j;
  48494. wc_test_ret_t ret;
  48495. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  48496. mp_zero(a);
  48497. mp_set_bit(a, i);
  48498. if ((int)a->used != (i + DIGIT_BIT) / DIGIT_BIT)
  48499. return WC_TEST_RET_ENC_NC;
  48500. for (j = 0; j < i && j < DIGIT_BIT; j++) {
  48501. mp_zero(r1);
  48502. mp_set_bit(r1, i);
  48503. ret = mp_sub_d(r1, (mp_digit)1 << j, r1);
  48504. if (ret != MP_OKAY)
  48505. return WC_TEST_RET_ENC_EC(ret);
  48506. ret = mp_add_d(r1, (mp_digit)1 << j, r1);
  48507. if (ret != MP_OKAY)
  48508. return WC_TEST_RET_ENC_EC(ret);
  48509. ret = mp_cmp(a, r1);
  48510. if (ret != MP_EQ)
  48511. return WC_TEST_RET_ENC_NC;
  48512. }
  48513. }
  48514. mp_zero(r1);
  48515. ret = mp_add_d(r1, 1, r1);
  48516. if (ret != MP_OKAY)
  48517. return WC_TEST_RET_ENC_EC(ret);
  48518. if (r1->used != 1)
  48519. return WC_TEST_RET_ENC_NC;
  48520. ret = mp_sub_d(r1, 1, r1);
  48521. if (ret != MP_OKAY)
  48522. return WC_TEST_RET_ENC_EC(ret);
  48523. if (r1->used != 0)
  48524. return WC_TEST_RET_ENC_NC;
  48525. return 0;
  48526. }
  48527. static wc_test_ret_t mp_test_read_to_bin(mp_int* a)
  48528. {
  48529. WOLFSSL_SMALL_STACK_STATIC const byte in[16] = {
  48530. 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7, 0x08,
  48531. 0x93, 0xa4, 0xb4, 0xc5, 0xd6, 0xe7, 0xf8, 0x09
  48532. };
  48533. byte out[24];
  48534. int i, j, k;
  48535. const byte* p;
  48536. wc_test_ret_t ret;
  48537. for (i = 0; i < (int)sizeof(in); i++) {
  48538. p = in + sizeof(in) - i;
  48539. ret = mp_read_unsigned_bin(a, p, (word32)i);
  48540. if (ret != 0)
  48541. return WC_TEST_RET_ENC_EC(ret);
  48542. for (j = i; j < (int)sizeof(out); j++) {
  48543. XMEMSET(out, 0xff, sizeof(out));
  48544. ret = mp_to_unsigned_bin_len(a, out, j);
  48545. if (ret != 0)
  48546. return WC_TEST_RET_ENC_EC(ret);
  48547. for (k = 0; k < j - i; k++) {
  48548. if (out[k] != 0)
  48549. return WC_TEST_RET_ENC_NC;
  48550. }
  48551. for (; k < j; k++) {
  48552. if (out[k] != p[k - (j - i)])
  48553. return WC_TEST_RET_ENC_NC;
  48554. }
  48555. }
  48556. }
  48557. /* Length too small. */
  48558. ret = mp_to_unsigned_bin_len(a, out, 1);
  48559. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48560. return WC_TEST_RET_ENC_EC(ret);
  48561. ret = mp_read_unsigned_bin(a, NULL, 0);
  48562. if (ret != 0)
  48563. return WC_TEST_RET_ENC_EC(ret);
  48564. if (!mp_iszero(a))
  48565. return WC_TEST_RET_ENC_NC;
  48566. return 0;
  48567. }
  48568. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  48569. static wc_test_ret_t mp_test_set_int(mp_int* a)
  48570. {
  48571. #if SP_ULONG_BITS == 64
  48572. unsigned long n = 0xfedcba9876543210UL;
  48573. byte exp[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
  48574. byte out[8] = { 0 };
  48575. #elif SP_ULONG_BITS == 32
  48576. unsigned long n = 0xfedcba98UL;
  48577. byte exp[4] = { 0xfe, 0xdc, 0xba, 0x98 };
  48578. byte out[4] = { 0 };
  48579. #elif SP_ULONG_BITS == 16
  48580. unsigned long n = 0xfedc;
  48581. byte exp[2] = { 0xfe, 0xdc };
  48582. byte out[2] = { 0 };
  48583. #elif SP_ULONG_BITS == 8
  48584. unsigned long n = 0xfe;
  48585. byte exp[1] = { 0xfe };
  48586. byte out[1] = { 0 };
  48587. #endif
  48588. wc_test_ret_t ret;
  48589. ret = mp_set_int(a, n);
  48590. if (ret != 0)
  48591. return WC_TEST_RET_ENC_EC(ret);
  48592. ret = mp_unsigned_bin_size(a);
  48593. if (ret != sizeof(exp))
  48594. return WC_TEST_RET_ENC_NC;
  48595. ret = mp_to_unsigned_bin(a, out);
  48596. if (ret != 0)
  48597. return WC_TEST_RET_ENC_EC(ret);
  48598. if (XMEMCMP(exp, out, sizeof(exp)) != 0)
  48599. return WC_TEST_RET_ENC_NC;
  48600. return 0;
  48601. }
  48602. #endif
  48603. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  48604. static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
  48605. {
  48606. byte buffer[16];
  48607. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  48608. char hexStr[] = "abcdef0123456789";
  48609. #ifndef WOLFSSL_SP_INT_NEGATIVE
  48610. char negStr[] = "-1234";
  48611. #endif
  48612. #endif
  48613. #if !defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
  48614. defined(HAVE_COMP_KEY)
  48615. char decStr[] = "0987654321";
  48616. #endif
  48617. wc_test_ret_t ret;
  48618. #ifdef WOLFSSL_SP_MATH_ALL
  48619. mp_digit rho;
  48620. int size;
  48621. #endif
  48622. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  48623. int result;
  48624. #endif
  48625. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  48626. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  48627. mp_digit rd;
  48628. #endif
  48629. (void)rng;
  48630. (void)r;
  48631. ret = mp_init(NULL);
  48632. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48633. return WC_TEST_RET_ENC_EC(ret);
  48634. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  48635. ret = mp_init_multi(NULL, NULL, NULL, NULL, NULL, NULL);
  48636. if (ret != MP_OKAY)
  48637. return WC_TEST_RET_ENC_EC(ret);
  48638. #endif
  48639. mp_free(NULL);
  48640. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
  48641. ret = mp_grow(NULL, 1);
  48642. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48643. return WC_TEST_RET_ENC_EC(ret);
  48644. #ifdef WOLFSSL_SP_MATH
  48645. ret = mp_grow(a, SP_INT_DIGITS + 1);
  48646. if (ret != WC_NO_ERR_TRACE(MP_MEM))
  48647. return WC_TEST_RET_ENC_EC(ret);
  48648. #endif
  48649. #endif
  48650. mp_clear(NULL);
  48651. ret = mp_abs(NULL, NULL);
  48652. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48653. return WC_TEST_RET_ENC_EC(ret);
  48654. ret = mp_abs(a, NULL);
  48655. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48656. return WC_TEST_RET_ENC_EC(ret);
  48657. ret = mp_abs(NULL, b);
  48658. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48659. return WC_TEST_RET_ENC_EC(ret);
  48660. ret = mp_unsigned_bin_size(NULL);
  48661. if (ret != 0)
  48662. return WC_TEST_RET_ENC_EC(ret);
  48663. /* clear buffer to avoid provoking uninitvar errors. */
  48664. XMEMSET(buffer, 0, sizeof(buffer));
  48665. ret = mp_read_unsigned_bin(NULL, NULL, sizeof(buffer));
  48666. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48667. return WC_TEST_RET_ENC_EC(ret);
  48668. ret = mp_read_unsigned_bin(NULL, buffer, sizeof(buffer));
  48669. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48670. return WC_TEST_RET_ENC_EC(ret);
  48671. ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer));
  48672. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48673. return WC_TEST_RET_ENC_EC(ret);
  48674. ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
  48675. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48676. return WC_TEST_RET_ENC_EC(ret);
  48677. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  48678. ret = mp_read_radix(NULL, NULL, 16);
  48679. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48680. return WC_TEST_RET_ENC_EC(ret);
  48681. ret = mp_read_radix(a, NULL, 16);
  48682. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48683. return WC_TEST_RET_ENC_EC(ret);
  48684. ret = mp_read_radix(NULL, hexStr, 16);
  48685. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48686. return WC_TEST_RET_ENC_EC(ret);
  48687. #ifndef WOLFSSL_SP_INT_NEGATIVE
  48688. ret = mp_read_radix(a, negStr, 16);
  48689. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48690. return WC_TEST_RET_ENC_EC(ret);
  48691. #ifdef WOLFSSL_SP_MATH_ALL
  48692. ret = mp_read_radix(a, negStr, 10);
  48693. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48694. return WC_TEST_RET_ENC_EC(ret);
  48695. #endif /* WOLFSSL_SP_MATH_ALL */
  48696. #endif /* WOLFSSL_SP_INT_NEGATIVE */
  48697. #endif
  48698. #ifndef WOLFSSL_SP_MATH_ALL
  48699. /* Radix 10 only supported with ALL. */
  48700. ret = mp_read_radix(a, decStr, 10);
  48701. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48702. return WC_TEST_RET_ENC_EC(ret);
  48703. #endif
  48704. /* Radix 8 not supported SP_INT. */
  48705. ret = mp_read_radix(a, "0123", 8);
  48706. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48707. return WC_TEST_RET_ENC_EC(ret);
  48708. ret = mp_count_bits(NULL);
  48709. if (ret != 0)
  48710. return WC_TEST_RET_ENC_EC(ret);
  48711. ret = mp_is_bit_set(NULL, 0);
  48712. if (ret != 0)
  48713. return WC_TEST_RET_ENC_EC(ret);
  48714. ret = mp_leading_bit(NULL);
  48715. if (ret != 0)
  48716. return WC_TEST_RET_ENC_EC(ret);
  48717. mp_zero(a);
  48718. ret = mp_leading_bit(a);
  48719. if (ret != 0)
  48720. return WC_TEST_RET_ENC_EC(ret);
  48721. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  48722. defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || \
  48723. !defined(NO_RSA)
  48724. ret = mp_set_bit(NULL, 1);
  48725. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48726. return WC_TEST_RET_ENC_EC(ret);
  48727. #endif
  48728. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  48729. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48730. ret = mp_to_unsigned_bin(NULL, NULL);
  48731. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48732. return WC_TEST_RET_ENC_EC(ret);
  48733. ret = mp_to_unsigned_bin(a, NULL);
  48734. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48735. return WC_TEST_RET_ENC_EC(ret);
  48736. ret = mp_to_unsigned_bin(NULL, buffer);
  48737. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48738. return WC_TEST_RET_ENC_EC(ret);
  48739. #endif
  48740. ret = mp_to_unsigned_bin_len(NULL, NULL, 1);
  48741. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48742. return WC_TEST_RET_ENC_EC(ret);
  48743. ret = mp_to_unsigned_bin_len(a, NULL, 1);
  48744. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48745. return WC_TEST_RET_ENC_EC(ret);
  48746. ret = mp_to_unsigned_bin_len(NULL, buffer, 1);
  48747. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48748. return WC_TEST_RET_ENC_EC(ret);
  48749. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  48750. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48751. ret = mp_to_unsigned_bin_at_pos(0, NULL, NULL);
  48752. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48753. return WC_TEST_RET_ENC_EC(ret);
  48754. ret = mp_to_unsigned_bin_at_pos(0, a, NULL);
  48755. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48756. return WC_TEST_RET_ENC_EC(ret);
  48757. ret = mp_to_unsigned_bin_at_pos(0, NULL, buffer);
  48758. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48759. return WC_TEST_RET_ENC_EC(ret);
  48760. ret = mp_to_unsigned_bin_at_pos(0, a, buffer);
  48761. if (ret != MP_OKAY)
  48762. return WC_TEST_RET_ENC_EC(ret);
  48763. #endif
  48764. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  48765. ret = mp_copy(NULL, NULL);
  48766. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48767. return WC_TEST_RET_ENC_EC(ret);
  48768. ret = mp_copy(a, NULL);
  48769. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48770. return WC_TEST_RET_ENC_EC(ret);
  48771. ret = mp_copy(NULL, b);
  48772. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48773. return WC_TEST_RET_ENC_EC(ret);
  48774. #endif
  48775. #if defined(WOLFSSL_KEY_GEN) || !defined(NO_DH)
  48776. ret = sp_2expt(NULL, 1);
  48777. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48778. return WC_TEST_RET_ENC_EC(ret);
  48779. #endif
  48780. ret = mp_set(NULL, 0);
  48781. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48782. return WC_TEST_RET_ENC_EC(ret);
  48783. ret = mp_cmp_d(NULL, 0);
  48784. if (ret != MP_LT)
  48785. return WC_TEST_RET_ENC_EC(ret);
  48786. ret = mp_cmp(NULL, NULL);
  48787. if (ret != MP_EQ)
  48788. return WC_TEST_RET_ENC_NC;
  48789. ret = mp_cmp(a, NULL);
  48790. if (ret != MP_GT)
  48791. return WC_TEST_RET_ENC_NC;
  48792. ret = mp_cmp(NULL, b);
  48793. if (ret != MP_LT)
  48794. return WC_TEST_RET_ENC_NC;
  48795. #ifdef WOLFSSL_SP_MATH_ALL
  48796. mp_rshd(NULL, 1);
  48797. #endif
  48798. mp_zero(NULL);
  48799. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  48800. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48801. ret = mp_lshd(NULL, 0);
  48802. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48803. return WC_TEST_RET_ENC_EC(ret);
  48804. ret = mp_lshd(a, SP_INT_DIGITS + 1);
  48805. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48806. return WC_TEST_RET_ENC_EC(ret);
  48807. #endif
  48808. #if defined(WOLFSSL_SP_MATH_ALL)
  48809. ret = mp_div(NULL, NULL, a, b);
  48810. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48811. return WC_TEST_RET_ENC_EC(ret);
  48812. ret = mp_div(a, NULL, a, b);
  48813. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48814. return WC_TEST_RET_ENC_EC(ret);
  48815. ret = mp_div(NULL, b, a, b);
  48816. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48817. return WC_TEST_RET_ENC_EC(ret);
  48818. ret = mp_div(a, b, NULL, NULL);
  48819. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48820. return WC_TEST_RET_ENC_EC(ret);
  48821. #endif
  48822. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  48823. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  48824. ret = mp_mod(NULL, NULL, NULL);
  48825. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48826. return WC_TEST_RET_ENC_EC(ret);
  48827. ret = mp_mod(a, NULL, NULL);
  48828. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48829. return WC_TEST_RET_ENC_EC(ret);
  48830. ret = mp_mod(NULL, b, NULL);
  48831. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48832. return WC_TEST_RET_ENC_EC(ret);
  48833. ret = mp_mod(NULL, NULL, r);
  48834. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48835. return WC_TEST_RET_ENC_EC(ret);
  48836. ret = mp_mod(a, b, NULL);
  48837. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48838. return WC_TEST_RET_ENC_EC(ret);
  48839. ret = mp_mod(a, NULL, r);
  48840. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48841. return WC_TEST_RET_ENC_EC(ret);
  48842. ret = mp_mod(NULL, b, r);
  48843. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48844. return WC_TEST_RET_ENC_EC(ret);
  48845. #endif
  48846. #if !defined(NO_RSA) || defined(WOLFSSL_SP_MATH_ALL)
  48847. ret = mp_set_int(NULL, 0);
  48848. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48849. return WC_TEST_RET_ENC_EC(ret);
  48850. #endif
  48851. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  48852. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  48853. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  48854. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48855. return WC_TEST_RET_ENC_EC(ret);
  48856. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  48857. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48858. return WC_TEST_RET_ENC_EC(ret);
  48859. ret = mp_exptmod_ex(NULL, a, 1, NULL, NULL);
  48860. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48861. return WC_TEST_RET_ENC_EC(ret);
  48862. ret = mp_exptmod_ex(NULL, NULL, 1, a, NULL);
  48863. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48864. return WC_TEST_RET_ENC_EC(ret);
  48865. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  48866. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48867. return WC_TEST_RET_ENC_EC(ret);
  48868. ret = mp_exptmod_ex(a, a, 1, a, NULL);
  48869. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48870. return WC_TEST_RET_ENC_EC(ret);
  48871. ret = mp_exptmod_ex(a, a, 1, NULL, a);
  48872. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48873. return WC_TEST_RET_ENC_EC(ret);
  48874. ret = mp_exptmod_ex(a, NULL, 1, a, a);
  48875. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48876. return WC_TEST_RET_ENC_EC(ret);
  48877. ret = mp_exptmod_ex(NULL, a, 1, a, a);
  48878. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48879. return WC_TEST_RET_ENC_EC(ret);
  48880. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  48881. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48882. return WC_TEST_RET_ENC_EC(ret);
  48883. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  48884. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48885. return WC_TEST_RET_ENC_EC(ret);
  48886. ret = mp_exptmod_nct(NULL, a, NULL, NULL);
  48887. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48888. return WC_TEST_RET_ENC_EC(ret);
  48889. ret = mp_exptmod_nct(NULL, NULL, a, NULL);
  48890. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48891. return WC_TEST_RET_ENC_EC(ret);
  48892. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  48893. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48894. return WC_TEST_RET_ENC_EC(ret);
  48895. ret = mp_exptmod_nct(a, a, a, NULL);
  48896. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48897. return WC_TEST_RET_ENC_EC(ret);
  48898. ret = mp_exptmod_nct(a, a, NULL, a);
  48899. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48900. return WC_TEST_RET_ENC_EC(ret);
  48901. ret = mp_exptmod_nct(a, NULL, a, a);
  48902. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48903. return WC_TEST_RET_ENC_EC(ret);
  48904. ret = mp_exptmod_nct(NULL, a, a, a);
  48905. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48906. return WC_TEST_RET_ENC_EC(ret);
  48907. #endif
  48908. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  48909. !defined(WC_NO_RNG)
  48910. ret = mp_rand_prime(NULL, 32, NULL, NULL);
  48911. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48912. return WC_TEST_RET_ENC_EC(ret);
  48913. ret = mp_rand_prime(a, 32, NULL, NULL);
  48914. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48915. return WC_TEST_RET_ENC_EC(ret);
  48916. ret = mp_rand_prime(NULL, 32, rng, NULL);
  48917. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48918. return WC_TEST_RET_ENC_EC(ret);
  48919. ret = mp_rand_prime(a, 0, rng, NULL);
  48920. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48921. return WC_TEST_RET_ENC_EC(ret);
  48922. #endif
  48923. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48924. ret = mp_mul(NULL, NULL, NULL);
  48925. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48926. return WC_TEST_RET_ENC_EC(ret);
  48927. ret = mp_mul(a, NULL, NULL);
  48928. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48929. return WC_TEST_RET_ENC_EC(ret);
  48930. ret = mp_mul(NULL, b, NULL);
  48931. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48932. return WC_TEST_RET_ENC_EC(ret);
  48933. ret = mp_mul(NULL, NULL, r);
  48934. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48935. return WC_TEST_RET_ENC_EC(ret);
  48936. ret = mp_mul(a, b, NULL);
  48937. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48938. return WC_TEST_RET_ENC_EC(ret);
  48939. ret = mp_mul(a, NULL, r);
  48940. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48941. return WC_TEST_RET_ENC_EC(ret);
  48942. ret = mp_mul(NULL, b, r);
  48943. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48944. return WC_TEST_RET_ENC_EC(ret);
  48945. #endif
  48946. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  48947. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  48948. ret = mp_sqr(NULL, NULL);
  48949. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48950. return WC_TEST_RET_ENC_EC(ret);
  48951. ret = mp_sqr(a, NULL);
  48952. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48953. return WC_TEST_RET_ENC_EC(ret);
  48954. ret = mp_sqr(NULL, r);
  48955. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48956. return WC_TEST_RET_ENC_EC(ret);
  48957. #endif
  48958. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  48959. ret = mp_sqrmod(NULL, NULL, NULL);
  48960. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48961. return WC_TEST_RET_ENC_EC(ret);
  48962. ret = mp_sqrmod(a, NULL, NULL);
  48963. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48964. return WC_TEST_RET_ENC_EC(ret);
  48965. ret = mp_sqrmod(NULL, a, NULL);
  48966. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48967. return WC_TEST_RET_ENC_EC(ret);
  48968. ret = mp_sqrmod(NULL, NULL, a);
  48969. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48970. return WC_TEST_RET_ENC_EC(ret);
  48971. ret = mp_sqrmod(a, b, NULL);
  48972. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48973. return WC_TEST_RET_ENC_EC(ret);
  48974. ret = mp_sqrmod(a, NULL, b);
  48975. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48976. return WC_TEST_RET_ENC_EC(ret);
  48977. ret = mp_sqrmod(NULL, a, b);
  48978. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48979. return WC_TEST_RET_ENC_EC(ret);
  48980. ret = mp_mulmod(NULL, NULL, NULL, NULL);
  48981. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48982. return WC_TEST_RET_ENC_EC(ret);
  48983. ret = mp_mulmod(a, NULL, NULL, NULL);
  48984. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48985. return WC_TEST_RET_ENC_EC(ret);
  48986. ret = mp_mulmod(NULL, a, NULL, NULL);
  48987. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48988. return WC_TEST_RET_ENC_EC(ret);
  48989. ret = mp_mulmod(NULL, NULL, a, NULL);
  48990. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48991. return WC_TEST_RET_ENC_EC(ret);
  48992. ret = mp_mulmod(NULL, NULL, NULL, a);
  48993. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48994. return WC_TEST_RET_ENC_EC(ret);
  48995. ret = mp_mulmod(a, b, b, NULL);
  48996. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48997. return WC_TEST_RET_ENC_EC(ret);
  48998. ret = mp_mulmod(a, b, NULL, a);
  48999. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49000. return WC_TEST_RET_ENC_EC(ret);
  49001. ret = mp_mulmod(a, NULL, b, a);
  49002. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49003. return WC_TEST_RET_ENC_EC(ret);
  49004. ret = mp_mulmod(NULL, b, b, a);
  49005. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49006. return WC_TEST_RET_ENC_EC(ret);
  49007. #endif
  49008. #if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \
  49009. !defined(NO_RSA) || !defined(NO_DSA)
  49010. ret = mp_add_d(NULL, 1, NULL);
  49011. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49012. return WC_TEST_RET_ENC_EC(ret);
  49013. ret = mp_add_d(a, 1, NULL);
  49014. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49015. return WC_TEST_RET_ENC_EC(ret);
  49016. ret = mp_add_d(NULL, 1, b);
  49017. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49018. return WC_TEST_RET_ENC_EC(ret);
  49019. #endif
  49020. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49021. !defined(NO_DH) || defined(HAVE_ECC) || !defined(NO_DSA)
  49022. ret = mp_sub_d(NULL, 1, NULL);
  49023. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49024. return WC_TEST_RET_ENC_EC(ret);
  49025. ret = mp_sub_d(a, 1, NULL);
  49026. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49027. return WC_TEST_RET_ENC_EC(ret);
  49028. ret = mp_sub_d(NULL, 1, b);
  49029. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49030. return WC_TEST_RET_ENC_EC(ret);
  49031. #endif
  49032. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49033. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49034. ret = mp_div_d(NULL, 0, NULL, NULL);
  49035. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49036. return WC_TEST_RET_ENC_EC(ret);
  49037. ret = mp_div_d(a, 0, NULL, NULL);
  49038. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49039. return WC_TEST_RET_ENC_EC(ret);
  49040. ret = mp_div_d(NULL, 1, NULL, NULL);
  49041. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49042. return WC_TEST_RET_ENC_EC(ret);
  49043. #endif
  49044. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49045. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49046. ret = mp_mod_d(NULL, 0, NULL);
  49047. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49048. return WC_TEST_RET_ENC_EC(ret);
  49049. ret = mp_mod_d(a, 0, NULL);
  49050. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49051. return WC_TEST_RET_ENC_EC(ret);
  49052. ret = mp_mod_d(NULL, 0, &rd);
  49053. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49054. return WC_TEST_RET_ENC_EC(ret);
  49055. #endif
  49056. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  49057. ret = mp_gcd(NULL, NULL, NULL);
  49058. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49059. return WC_TEST_RET_ENC_EC(ret);
  49060. ret = mp_gcd(a, NULL, NULL);
  49061. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49062. return WC_TEST_RET_ENC_EC(ret);
  49063. ret = mp_gcd(NULL, a, NULL);
  49064. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49065. return WC_TEST_RET_ENC_EC(ret);
  49066. ret = mp_gcd(NULL, NULL, a);
  49067. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49068. return WC_TEST_RET_ENC_EC(ret);
  49069. ret = mp_gcd(a, b, NULL);
  49070. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49071. return WC_TEST_RET_ENC_EC(ret);
  49072. ret = mp_gcd(a, NULL, b);
  49073. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49074. return WC_TEST_RET_ENC_EC(ret);
  49075. ret = mp_gcd(NULL, a, b);
  49076. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49077. return WC_TEST_RET_ENC_EC(ret);
  49078. #endif
  49079. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49080. ret = mp_div_2_mod_ct(NULL, NULL, NULL);
  49081. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49082. return WC_TEST_RET_ENC_EC(ret);
  49083. ret = mp_div_2_mod_ct(a, NULL, NULL);
  49084. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49085. return WC_TEST_RET_ENC_EC(ret);
  49086. ret = mp_div_2_mod_ct(NULL, b, NULL);
  49087. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49088. return WC_TEST_RET_ENC_EC(ret);
  49089. ret = mp_div_2_mod_ct(NULL, NULL, a);
  49090. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49091. return WC_TEST_RET_ENC_EC(ret);
  49092. ret = mp_div_2_mod_ct(a, b, NULL);
  49093. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49094. return WC_TEST_RET_ENC_EC(ret);
  49095. ret = mp_div_2_mod_ct(a, b, NULL);
  49096. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49097. return WC_TEST_RET_ENC_EC(ret);
  49098. ret = mp_div_2_mod_ct(NULL, b, a);
  49099. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49100. return WC_TEST_RET_ENC_EC(ret);
  49101. ret = mp_div_2(NULL, NULL);
  49102. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49103. return WC_TEST_RET_ENC_EC(ret);
  49104. ret = mp_div_2(a, NULL);
  49105. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49106. return WC_TEST_RET_ENC_EC(ret);
  49107. ret = mp_div_2(NULL, a);
  49108. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49109. return WC_TEST_RET_ENC_EC(ret);
  49110. #endif
  49111. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49112. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  49113. ret = mp_invmod(NULL, NULL, NULL);
  49114. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49115. return WC_TEST_RET_ENC_EC(ret);
  49116. ret = mp_invmod(a, NULL, NULL);
  49117. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49118. return WC_TEST_RET_ENC_EC(ret);
  49119. ret = mp_invmod(NULL, b, NULL);
  49120. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49121. return WC_TEST_RET_ENC_EC(ret);
  49122. ret = mp_invmod(NULL, NULL, a);
  49123. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49124. return WC_TEST_RET_ENC_EC(ret);
  49125. ret = mp_invmod(a, b, NULL);
  49126. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49127. return WC_TEST_RET_ENC_EC(ret);
  49128. ret = mp_invmod(a, NULL, a);
  49129. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49130. return WC_TEST_RET_ENC_EC(ret);
  49131. ret = mp_invmod(NULL, b, a);
  49132. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49133. return WC_TEST_RET_ENC_EC(ret);
  49134. #endif
  49135. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49136. ret = mp_invmod_mont_ct(NULL, NULL, NULL, 1);
  49137. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49138. return WC_TEST_RET_ENC_EC(ret);
  49139. ret = mp_invmod_mont_ct(a, NULL, NULL, 1);
  49140. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49141. return WC_TEST_RET_ENC_EC(ret);
  49142. ret = mp_invmod_mont_ct(NULL, b, NULL, 1);
  49143. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49144. return WC_TEST_RET_ENC_EC(ret);
  49145. ret = mp_invmod_mont_ct(NULL, NULL, a, 1);
  49146. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49147. return WC_TEST_RET_ENC_EC(ret);
  49148. ret = mp_invmod_mont_ct(a, b, NULL, 1);
  49149. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49150. return WC_TEST_RET_ENC_EC(ret);
  49151. ret = mp_invmod_mont_ct(a, NULL, a, 1);
  49152. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49153. return WC_TEST_RET_ENC_EC(ret);
  49154. ret = mp_invmod_mont_ct(NULL, b, a, 1);
  49155. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49156. return WC_TEST_RET_ENC_EC(ret);
  49157. #endif
  49158. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  49159. ret = mp_lcm(NULL, NULL, NULL);
  49160. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49161. return WC_TEST_RET_ENC_EC(ret);
  49162. ret = mp_lcm(a, NULL, NULL);
  49163. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49164. return WC_TEST_RET_ENC_EC(ret);
  49165. ret = mp_lcm(NULL, b, NULL);
  49166. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49167. return WC_TEST_RET_ENC_EC(ret);
  49168. ret = mp_lcm(NULL, NULL, a);
  49169. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49170. return WC_TEST_RET_ENC_EC(ret);
  49171. ret = mp_lcm(a, b, NULL);
  49172. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49173. return WC_TEST_RET_ENC_EC(ret);
  49174. ret = mp_lcm(a, NULL, a);
  49175. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49176. return WC_TEST_RET_ENC_EC(ret);
  49177. ret = mp_lcm(NULL, b, a);
  49178. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49179. return WC_TEST_RET_ENC_EC(ret);
  49180. #endif
  49181. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49182. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49183. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49184. return WC_TEST_RET_ENC_EC(ret);
  49185. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49186. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49187. return WC_TEST_RET_ENC_EC(ret);
  49188. ret = mp_exptmod_ex(NULL, b, 1, NULL, NULL);
  49189. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49190. return WC_TEST_RET_ENC_EC(ret);
  49191. ret = mp_exptmod_ex(NULL, NULL, 1, b, NULL);
  49192. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49193. return WC_TEST_RET_ENC_EC(ret);
  49194. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49195. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49196. return WC_TEST_RET_ENC_EC(ret);
  49197. ret = mp_exptmod_ex(a, b, 1, b, NULL);
  49198. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49199. return WC_TEST_RET_ENC_EC(ret);
  49200. ret = mp_exptmod_ex(a, b, 1, NULL, a);
  49201. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49202. return WC_TEST_RET_ENC_EC(ret);
  49203. ret = mp_exptmod_ex(a, NULL, 1, b, a);
  49204. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49205. return WC_TEST_RET_ENC_EC(ret);
  49206. ret = mp_exptmod_ex(NULL, b, 1, b, a);
  49207. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49208. return WC_TEST_RET_ENC_EC(ret);
  49209. ret = mp_exptmod(NULL, NULL, NULL, NULL);
  49210. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49211. return WC_TEST_RET_ENC_EC(ret);
  49212. ret = mp_exptmod(a, NULL, NULL, NULL);
  49213. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49214. return WC_TEST_RET_ENC_EC(ret);
  49215. ret = mp_exptmod(NULL, b, NULL, NULL);
  49216. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49217. return WC_TEST_RET_ENC_EC(ret);
  49218. ret = mp_exptmod(NULL, NULL, b, NULL);
  49219. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49220. return WC_TEST_RET_ENC_EC(ret);
  49221. ret = mp_exptmod(NULL, NULL, NULL, a);
  49222. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49223. return WC_TEST_RET_ENC_EC(ret);
  49224. ret = mp_exptmod(a, b, b, NULL);
  49225. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49226. return WC_TEST_RET_ENC_EC(ret);
  49227. ret = mp_exptmod(a, b, NULL, a);
  49228. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49229. return WC_TEST_RET_ENC_EC(ret);
  49230. ret = mp_exptmod(a, NULL, b, a);
  49231. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49232. return WC_TEST_RET_ENC_EC(ret);
  49233. ret = mp_exptmod(NULL, b, b, a);
  49234. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49235. return WC_TEST_RET_ENC_EC(ret);
  49236. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49237. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49238. return WC_TEST_RET_ENC_EC(ret);
  49239. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49240. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49241. return WC_TEST_RET_ENC_EC(ret);
  49242. ret = mp_exptmod_nct(NULL, b, NULL, NULL);
  49243. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49244. return WC_TEST_RET_ENC_EC(ret);
  49245. ret = mp_exptmod_nct(NULL, NULL, b, NULL);
  49246. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49247. return WC_TEST_RET_ENC_EC(ret);
  49248. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49249. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49250. return WC_TEST_RET_ENC_EC(ret);
  49251. ret = mp_exptmod_nct(a, b, b, NULL);
  49252. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49253. return WC_TEST_RET_ENC_EC(ret);
  49254. ret = mp_exptmod_nct(a, b, NULL, a);
  49255. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49256. return WC_TEST_RET_ENC_EC(ret);
  49257. ret = mp_exptmod_nct(a, NULL, b, a);
  49258. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49259. return WC_TEST_RET_ENC_EC(ret);
  49260. ret = mp_exptmod_nct(NULL, b, b, a);
  49261. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49262. return WC_TEST_RET_ENC_EC(ret);
  49263. #endif
  49264. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  49265. ret = mp_cnt_lsb(NULL);
  49266. if (ret != 0)
  49267. return WC_TEST_RET_ENC_EC(ret);
  49268. #endif
  49269. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49270. ret = mp_prime_is_prime(NULL, 1, NULL);
  49271. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49272. return WC_TEST_RET_ENC_EC(ret);
  49273. ret = mp_prime_is_prime(a, 1, NULL);
  49274. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49275. return WC_TEST_RET_ENC_EC(ret);
  49276. ret = mp_prime_is_prime(NULL, 1, &result);
  49277. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49278. return WC_TEST_RET_ENC_EC(ret);
  49279. ret = mp_prime_is_prime(a, 0, &result);
  49280. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49281. return WC_TEST_RET_ENC_EC(ret);
  49282. ret = mp_prime_is_prime(a, 1024, &result);
  49283. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49284. return WC_TEST_RET_ENC_EC(ret);
  49285. ret = mp_prime_is_prime_ex(NULL, 1, NULL, NULL);
  49286. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49287. return WC_TEST_RET_ENC_EC(ret);
  49288. ret = mp_prime_is_prime_ex(a, 1, NULL, NULL);
  49289. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49290. return WC_TEST_RET_ENC_EC(ret);
  49291. ret = mp_prime_is_prime_ex(NULL, 1, &result, NULL);
  49292. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49293. return WC_TEST_RET_ENC_EC(ret);
  49294. ret = mp_prime_is_prime_ex(NULL, 1, NULL, rng);
  49295. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49296. return WC_TEST_RET_ENC_EC(ret);
  49297. ret = mp_prime_is_prime_ex(a, 1, &result, NULL);
  49298. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49299. return WC_TEST_RET_ENC_EC(ret);
  49300. ret = mp_prime_is_prime_ex(a, 1, NULL, rng);
  49301. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49302. return WC_TEST_RET_ENC_EC(ret);
  49303. ret = mp_prime_is_prime_ex(NULL, 1, &result, rng);
  49304. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49305. return WC_TEST_RET_ENC_EC(ret);
  49306. #endif
  49307. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA)
  49308. ret = mp_exch(NULL, NULL);
  49309. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49310. return WC_TEST_RET_ENC_EC(ret);
  49311. ret = mp_exch(a, NULL);
  49312. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49313. return WC_TEST_RET_ENC_EC(ret);
  49314. ret = mp_exch(NULL, b);
  49315. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49316. return WC_TEST_RET_ENC_EC(ret);
  49317. #endif
  49318. #if (defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)) || \
  49319. defined(WOLFSSL_SP_MATH_ALL)
  49320. ret = mp_mul_d(NULL, 1, NULL);
  49321. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49322. return WC_TEST_RET_ENC_EC(ret);
  49323. ret = mp_mul_d(a, 1, NULL);
  49324. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49325. return WC_TEST_RET_ENC_EC(ret);
  49326. ret = mp_mul_d(NULL, 1, b);
  49327. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49328. return WC_TEST_RET_ENC_EC(ret);
  49329. #endif
  49330. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49331. ret = mp_add(NULL, NULL, NULL);
  49332. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49333. return WC_TEST_RET_ENC_EC(ret);
  49334. ret = mp_add(a, NULL, NULL);
  49335. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49336. return WC_TEST_RET_ENC_EC(ret);
  49337. ret = mp_add(NULL, b, NULL);
  49338. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49339. return WC_TEST_RET_ENC_EC(ret);
  49340. ret = mp_add(NULL, NULL, r);
  49341. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49342. return WC_TEST_RET_ENC_EC(ret);
  49343. ret = mp_add(a, b, NULL);
  49344. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49345. return WC_TEST_RET_ENC_EC(ret);
  49346. ret = mp_add(a, NULL, r);
  49347. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49348. return WC_TEST_RET_ENC_EC(ret);
  49349. ret = mp_add(NULL, b, r);
  49350. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49351. return WC_TEST_RET_ENC_EC(ret);
  49352. #endif
  49353. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49354. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49355. ret = mp_sub(NULL, NULL, NULL);
  49356. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49357. return WC_TEST_RET_ENC_EC(ret);
  49358. ret = mp_sub(a, NULL, NULL);
  49359. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49360. return WC_TEST_RET_ENC_EC(ret);
  49361. ret = mp_sub(NULL, b, NULL);
  49362. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49363. return WC_TEST_RET_ENC_EC(ret);
  49364. ret = mp_sub(NULL, NULL, r);
  49365. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49366. return WC_TEST_RET_ENC_EC(ret);
  49367. ret = mp_sub(a, b, NULL);
  49368. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49369. return WC_TEST_RET_ENC_EC(ret);
  49370. ret = mp_sub(a, NULL, r);
  49371. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49372. return WC_TEST_RET_ENC_EC(ret);
  49373. ret = mp_sub(NULL, b, r);
  49374. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49375. return WC_TEST_RET_ENC_EC(ret);
  49376. #endif
  49377. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined(WOLFSSL_SP_MATH) && \
  49378. defined(WOLFSSL_CUSTOM_CURVES))
  49379. ret = mp_addmod(NULL, NULL, NULL, NULL);
  49380. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49381. return WC_TEST_RET_ENC_EC(ret);
  49382. ret = mp_addmod(a, NULL, NULL, NULL);
  49383. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49384. return WC_TEST_RET_ENC_EC(ret);
  49385. ret = mp_addmod(NULL, b, NULL, NULL);
  49386. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49387. return WC_TEST_RET_ENC_EC(ret);
  49388. ret = mp_addmod(NULL, NULL, b, NULL);
  49389. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49390. return WC_TEST_RET_ENC_EC(ret);
  49391. ret = mp_addmod(NULL, NULL, NULL, a);
  49392. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49393. return WC_TEST_RET_ENC_EC(ret);
  49394. ret = mp_addmod(a, b, b, NULL);
  49395. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49396. return WC_TEST_RET_ENC_EC(ret);
  49397. ret = mp_addmod(a, b, NULL, a);
  49398. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49399. return WC_TEST_RET_ENC_EC(ret);
  49400. ret = mp_addmod(a, NULL, b, a);
  49401. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49402. return WC_TEST_RET_ENC_EC(ret);
  49403. ret = mp_addmod(NULL, b, b, a);
  49404. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49405. return WC_TEST_RET_ENC_EC(ret);
  49406. #endif
  49407. #ifdef WOLFSSL_SP_MATH_ALL
  49408. ret = mp_submod(NULL, NULL, NULL, NULL);
  49409. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49410. return WC_TEST_RET_ENC_EC(ret);
  49411. ret = mp_submod(a, NULL, NULL, NULL);
  49412. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49413. return WC_TEST_RET_ENC_EC(ret);
  49414. ret = mp_submod(NULL, b, NULL, NULL);
  49415. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49416. return WC_TEST_RET_ENC_EC(ret);
  49417. ret = mp_submod(NULL, NULL, b, NULL);
  49418. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49419. return WC_TEST_RET_ENC_EC(ret);
  49420. ret = mp_submod(NULL, NULL, NULL, a);
  49421. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49422. return WC_TEST_RET_ENC_EC(ret);
  49423. ret = mp_submod(a, b, b, NULL);
  49424. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49425. return WC_TEST_RET_ENC_EC(ret);
  49426. ret = mp_submod(a, b, NULL, a);
  49427. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49428. return WC_TEST_RET_ENC_EC(ret);
  49429. ret = mp_submod(a, NULL, b, a);
  49430. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49431. return WC_TEST_RET_ENC_EC(ret);
  49432. ret = mp_submod(NULL, b, b, a);
  49433. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49434. return WC_TEST_RET_ENC_EC(ret);
  49435. #endif
  49436. #ifdef WOLFSSL_SP_MATH_ALL
  49437. ret = mp_div_2d(NULL, 1, a, b);
  49438. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49439. return WC_TEST_RET_ENC_EC(ret);
  49440. ret = mp_mod_2d(NULL, 1, NULL);
  49441. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49442. return WC_TEST_RET_ENC_EC(ret);
  49443. ret = mp_mod_2d(a, 1, NULL);
  49444. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49445. return WC_TEST_RET_ENC_EC(ret);
  49446. ret = mp_mod_2d(NULL, 1, b);
  49447. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49448. return WC_TEST_RET_ENC_EC(ret);
  49449. ret = mp_mul_2d(NULL, 1, NULL);
  49450. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49451. return WC_TEST_RET_ENC_EC(ret);
  49452. ret = mp_mul_2d(a, 1, NULL);
  49453. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49454. return WC_TEST_RET_ENC_EC(ret);
  49455. ret = mp_mul_2d(NULL, 1, b);
  49456. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49457. return WC_TEST_RET_ENC_EC(ret);
  49458. #endif
  49459. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49460. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49461. ret = mp_montgomery_reduce(NULL, NULL, 1);
  49462. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49463. return WC_TEST_RET_ENC_EC(ret);
  49464. ret = mp_montgomery_reduce(a, NULL, 1);
  49465. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49466. return WC_TEST_RET_ENC_EC(ret);
  49467. ret = mp_montgomery_reduce(NULL, b, 1);
  49468. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49469. return WC_TEST_RET_ENC_EC(ret);
  49470. mp_zero(b);
  49471. ret = mp_montgomery_reduce(a, b, 1);
  49472. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49473. return WC_TEST_RET_ENC_EC(ret);
  49474. #endif
  49475. #ifdef WOLFSSL_SP_MATH_ALL
  49476. ret = mp_montgomery_setup(NULL, NULL);
  49477. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49478. return WC_TEST_RET_ENC_EC(ret);
  49479. ret = mp_montgomery_setup(a, NULL);
  49480. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49481. return WC_TEST_RET_ENC_EC(ret);
  49482. ret = mp_montgomery_setup(NULL, &rho);
  49483. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49484. return WC_TEST_RET_ENC_EC(ret);
  49485. ret = mp_montgomery_calc_normalization(NULL, NULL);
  49486. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49487. return WC_TEST_RET_ENC_EC(ret);
  49488. ret = mp_montgomery_calc_normalization(a, NULL);
  49489. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49490. return WC_TEST_RET_ENC_EC(ret);
  49491. ret = mp_montgomery_calc_normalization(NULL, b);
  49492. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49493. return WC_TEST_RET_ENC_EC(ret);
  49494. #endif
  49495. ret = mp_unsigned_bin_size(NULL);
  49496. if (ret != 0)
  49497. return WC_TEST_RET_ENC_EC(ret);
  49498. #if defined(WC_MP_TO_RADIX) || defined(WOLFSSL_SP_MATH_ALL)
  49499. ret = mp_tohex(NULL, NULL);
  49500. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49501. return WC_TEST_RET_ENC_EC(ret);
  49502. ret = mp_tohex(a, NULL);
  49503. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49504. return WC_TEST_RET_ENC_EC(ret);
  49505. ret = mp_tohex(NULL, hexStr);
  49506. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49507. return WC_TEST_RET_ENC_EC(ret);
  49508. #endif
  49509. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49510. ret = mp_todecimal(NULL, NULL);
  49511. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49512. return WC_TEST_RET_ENC_EC(ret);
  49513. ret = mp_todecimal(a, NULL);
  49514. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49515. return WC_TEST_RET_ENC_EC(ret);
  49516. ret = mp_todecimal(NULL, decStr);
  49517. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49518. return WC_TEST_RET_ENC_EC(ret);
  49519. #endif
  49520. #ifdef WOLFSSL_SP_MATH_ALL
  49521. ret = mp_toradix(NULL, NULL, MP_RADIX_HEX);
  49522. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49523. return WC_TEST_RET_ENC_EC(ret);
  49524. ret = mp_toradix(a, NULL, MP_RADIX_HEX);
  49525. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49526. return WC_TEST_RET_ENC_EC(ret);
  49527. ret = mp_toradix(NULL, hexStr, MP_RADIX_HEX);
  49528. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49529. return WC_TEST_RET_ENC_EC(ret);
  49530. ret = mp_toradix(a, hexStr, 3);
  49531. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49532. return WC_TEST_RET_ENC_EC(ret);
  49533. ret = mp_radix_size(NULL, MP_RADIX_HEX, NULL);
  49534. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49535. return WC_TEST_RET_ENC_EC(ret);
  49536. ret = mp_radix_size(a, MP_RADIX_HEX, NULL);
  49537. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49538. return WC_TEST_RET_ENC_EC(ret);
  49539. ret = mp_radix_size(NULL, MP_RADIX_HEX, &size);
  49540. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49541. return WC_TEST_RET_ENC_EC(ret);
  49542. ret = mp_radix_size(a, 3, &size);
  49543. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49544. return WC_TEST_RET_ENC_EC(ret);
  49545. #endif
  49546. return 0;
  49547. }
  49548. #endif
  49549. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49550. static wc_test_ret_t mp_test_set_is_bit(mp_int* a)
  49551. {
  49552. int i, j;
  49553. wc_test_ret_t ret;
  49554. mp_zero(a);
  49555. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49556. if (mp_is_bit_set(a, i))
  49557. return WC_TEST_RET_ENC_NC;
  49558. for (j = 0; j < i; j++) {
  49559. if (!mp_is_bit_set(a, j))
  49560. return WC_TEST_RET_ENC_NC;
  49561. }
  49562. if (mp_set_bit(a, i) != 0)
  49563. return WC_TEST_RET_ENC_NC;
  49564. if (!mp_is_bit_set(a, i))
  49565. return WC_TEST_RET_ENC_NC;
  49566. }
  49567. mp_zero(a);
  49568. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49569. if (mp_is_bit_set(a, i))
  49570. return WC_TEST_RET_ENC_NC;
  49571. }
  49572. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49573. mp_zero(a);
  49574. if (mp_set_bit(a, i) != 0)
  49575. return WC_TEST_RET_ENC_NC;
  49576. for (j = 0; j < i; j++) {
  49577. if (mp_is_bit_set(a, j))
  49578. return WC_TEST_RET_ENC_NC;
  49579. }
  49580. if (!mp_is_bit_set(a, i))
  49581. return WC_TEST_RET_ENC_NC;
  49582. }
  49583. #ifdef WOLFSSL_KEY_GEN
  49584. for (i = 0; i < DIGIT_BIT * 2; i++) {
  49585. mp_set(a, 1);
  49586. ret = mp_2expt(a, i);
  49587. if (ret != 0)
  49588. return WC_TEST_RET_ENC_EC(ret);
  49589. for (j = 0; j < i; j++) {
  49590. if (mp_is_bit_set(a, j))
  49591. return WC_TEST_RET_ENC_NC;
  49592. }
  49593. if (!mp_is_bit_set(a, i))
  49594. return WC_TEST_RET_ENC_NC;
  49595. }
  49596. #endif
  49597. #ifdef WOLFSSL_SP_MATH
  49598. mp_zero(a);
  49599. for (j = 1; j <= 3; j++) {
  49600. i = SP_INT_MAX_BITS - j;
  49601. if (mp_is_bit_set(a, i))
  49602. return WC_TEST_RET_ENC_NC;
  49603. if (mp_set_bit(a, i) != 0)
  49604. return WC_TEST_RET_ENC_NC;
  49605. if (!mp_is_bit_set(a, i))
  49606. return WC_TEST_RET_ENC_NC;
  49607. #ifdef WOLFSSL_KEY_GEN
  49608. ret = mp_2expt(a, i);
  49609. if (ret != 0)
  49610. return WC_TEST_RET_ENC_EC(ret);
  49611. if (!mp_is_bit_set(a, i))
  49612. return WC_TEST_RET_ENC_NC;
  49613. #endif
  49614. }
  49615. mp_zero(a);
  49616. for (j = 0; j <= 3; j++) {
  49617. i = SP_INT_MAX_BITS + j;
  49618. if (mp_is_bit_set(a, i))
  49619. return WC_TEST_RET_ENC_NC;
  49620. if (mp_set_bit(a, i) != WC_NO_ERR_TRACE(MP_VAL))
  49621. return WC_TEST_RET_ENC_NC;
  49622. #ifdef WOLFSSL_KEY_GEN
  49623. ret = mp_2expt(a, i);
  49624. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49625. return WC_TEST_RET_ENC_EC(ret);
  49626. #endif
  49627. }
  49628. #endif
  49629. (void)ret;
  49630. return 0;
  49631. }
  49632. #endif /* !WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */
  49633. static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b)
  49634. {
  49635. wc_test_ret_t ret;
  49636. mp_zero(a);
  49637. mp_zero(b);
  49638. ret = mp_cmp_d(a, 0);
  49639. if (ret != MP_EQ)
  49640. return WC_TEST_RET_ENC_EC(ret);
  49641. ret = mp_cmp_d(a, 1);
  49642. if (ret != MP_LT)
  49643. return WC_TEST_RET_ENC_EC(ret);
  49644. ret = mp_cmp(a, b);
  49645. if (ret != MP_EQ)
  49646. return WC_TEST_RET_ENC_NC;
  49647. mp_set(a, 1);
  49648. ret = mp_cmp_d(a, 0);
  49649. if (ret != MP_GT)
  49650. return WC_TEST_RET_ENC_EC(ret);
  49651. ret = mp_cmp_d(a, 1);
  49652. if (ret != MP_EQ)
  49653. return WC_TEST_RET_ENC_EC(ret);
  49654. ret = mp_cmp_d(a, 2);
  49655. if (ret != MP_LT)
  49656. return WC_TEST_RET_ENC_EC(ret);
  49657. ret = mp_cmp(a, b);
  49658. if (ret != MP_GT)
  49659. return WC_TEST_RET_ENC_NC;
  49660. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  49661. mp_read_radix(b, "1234567890123456789", MP_RADIX_HEX);
  49662. ret = mp_cmp_d(b, -1);
  49663. if (ret != MP_GT)
  49664. return WC_TEST_RET_ENC_EC(ret);
  49665. ret = mp_cmp(a, b);
  49666. if (ret != MP_LT)
  49667. return WC_TEST_RET_ENC_NC;
  49668. ret = mp_cmp(b, a);
  49669. if (ret != MP_GT)
  49670. return WC_TEST_RET_ENC_NC;
  49671. ret = mp_cmp(b, b);
  49672. if (ret != MP_EQ)
  49673. return WC_TEST_RET_ENC_NC;
  49674. #endif
  49675. #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
  49676. defined(WOLFSSL_SP_INT_NEGATIVE)
  49677. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  49678. mp_read_radix(a, "-1", MP_RADIX_HEX);
  49679. mp_read_radix(a, "1", MP_RADIX_HEX);
  49680. ret = mp_cmp(a, b);
  49681. if (ret != MP_LT)
  49682. return WC_TEST_RET_ENC_NC;
  49683. ret = mp_cmp(b, a);
  49684. if (ret != MP_GT)
  49685. return WC_TEST_RET_ENC_NC;
  49686. mp_read_radix(b, "-2", MP_RADIX_HEX);
  49687. ret = mp_cmp(a, b);
  49688. if (ret != MP_GT)
  49689. return WC_TEST_RET_ENC_NC;
  49690. ret = mp_cmp(b, a);
  49691. if (ret != MP_LT)
  49692. return WC_TEST_RET_ENC_NC;
  49693. #endif
  49694. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  49695. mp_read_radix(a, "-2", MP_RADIX_HEX);
  49696. ret = mp_cmp(a, b);
  49697. if (ret != MP_EQ)
  49698. return WC_TEST_RET_ENC_NC;
  49699. #endif
  49700. #endif
  49701. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  49702. defined(WOLFSSL_ECC_GEN_REJECT_SAMPLING)
  49703. mp_zero(a);
  49704. mp_zero(b);
  49705. ret = mp_cmp_ct(a, b, 1);
  49706. if (ret != MP_EQ)
  49707. return WC_TEST_RET_ENC_EC(ret);
  49708. ret = mp_cmp_ct(a, a, a->used);
  49709. if (ret != MP_EQ)
  49710. return WC_TEST_RET_ENC_EC(ret);
  49711. #ifdef WOLFSSL_SP_MATH_ALL
  49712. ret = mp_cmp_ct(a, NULL, a->used);
  49713. if (ret != MP_GT)
  49714. return WC_TEST_RET_ENC_EC(ret);
  49715. ret = mp_cmp_ct(NULL, a, a->used);
  49716. if (ret != MP_LT)
  49717. return WC_TEST_RET_ENC_EC(ret);
  49718. #endif
  49719. mp_read_radix(a, "1", MP_RADIX_HEX);
  49720. ret = mp_cmp_ct(a, b, 1);
  49721. if (ret != MP_GT)
  49722. return WC_TEST_RET_ENC_EC(ret);
  49723. ret = mp_cmp_ct(b, a, 1);
  49724. if (ret != MP_LT)
  49725. return WC_TEST_RET_ENC_EC(ret);
  49726. mp_read_radix(a, "0123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  49727. ret = mp_cmp_ct(a, b, a->used);
  49728. if (ret != MP_GT)
  49729. return WC_TEST_RET_ENC_EC(ret);
  49730. ret = mp_cmp_ct(b, a, a->used);
  49731. if (ret != MP_LT)
  49732. return WC_TEST_RET_ENC_EC(ret);
  49733. mp_read_radix(b, "1123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  49734. ret = mp_cmp_ct(b, a, a->used);
  49735. if (ret != MP_GT)
  49736. return WC_TEST_RET_ENC_EC(ret);
  49737. ret = mp_cmp_ct(a, b, a->used);
  49738. if (ret != MP_LT)
  49739. return WC_TEST_RET_ENC_EC(ret);
  49740. mp_read_radix(b, "0123456789abcdef0123456789abcdf0", MP_RADIX_HEX);
  49741. ret = mp_cmp_ct(b, a, a->used);
  49742. if (ret != MP_GT)
  49743. return WC_TEST_RET_ENC_EC(ret);
  49744. ret = mp_cmp_ct(a, b, a->used);
  49745. if (ret != MP_LT)
  49746. return WC_TEST_RET_ENC_EC(ret);
  49747. mp_read_radix(b, "0123456789abcdf0", MP_RADIX_HEX);
  49748. ret = mp_cmp_ct(a, b, a->used);
  49749. if (ret != MP_GT)
  49750. return WC_TEST_RET_ENC_EC(ret);
  49751. ret = mp_cmp_ct(b, a, a->used);
  49752. if (ret != MP_LT)
  49753. return WC_TEST_RET_ENC_EC(ret);
  49754. #endif
  49755. return 0;
  49756. }
  49757. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49758. static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
  49759. {
  49760. wc_test_ret_t ret;
  49761. int i, j, k;
  49762. #ifndef WOLFSSL_SP_MATH
  49763. for (i = 0; i < 10; i++) {
  49764. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  49765. ret = randNum(a, j, rng, NULL);
  49766. if (ret != MP_OKAY)
  49767. return WC_TEST_RET_ENC_EC(ret);
  49768. mp_copy(a, b);
  49769. for (k = 0; k <= DIGIT_BIT * 2; k++) {
  49770. ret = mp_mul_2d(a, k, a);
  49771. if (ret != MP_OKAY)
  49772. return WC_TEST_RET_ENC_EC(ret);
  49773. mp_rshb(a, k);
  49774. ret = mp_cmp(a, b);
  49775. if (ret != MP_EQ)
  49776. return WC_TEST_RET_ENC_NC;
  49777. }
  49778. }
  49779. }
  49780. #endif
  49781. for (i = 0; i < 10; i++) {
  49782. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  49783. ret = randNum(a, j, rng, NULL);
  49784. if (ret != MP_OKAY)
  49785. return WC_TEST_RET_ENC_EC(ret);
  49786. mp_copy(a, b);
  49787. for (k = 0; k < 10; k++) {
  49788. ret = mp_lshd(a, k);
  49789. if (ret != MP_OKAY)
  49790. return WC_TEST_RET_ENC_EC(ret);
  49791. #ifndef WOLFSSL_SP_MATH
  49792. mp_rshd(a, k);
  49793. #else
  49794. mp_rshb(a, k * SP_WORD_SIZE);
  49795. #endif
  49796. ret = mp_cmp(a, b);
  49797. if (ret != MP_EQ)
  49798. return WC_TEST_RET_ENC_NC;
  49799. }
  49800. }
  49801. }
  49802. #ifndef WOLFSSL_SP_MATH
  49803. mp_zero(a);
  49804. mp_rshd(a, 1);
  49805. if (!mp_iszero(a))
  49806. return WC_TEST_RET_ENC_NC;
  49807. mp_set(a, 1);
  49808. mp_rshd(a, 1);
  49809. if (!mp_iszero(a))
  49810. return WC_TEST_RET_ENC_NC;
  49811. mp_set(a, 1);
  49812. mp_rshd(a, 2);
  49813. if (!mp_iszero(a))
  49814. return WC_TEST_RET_ENC_NC;
  49815. #endif
  49816. return 0;
  49817. }
  49818. #endif
  49819. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49820. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  49821. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  49822. static wc_test_ret_t mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem,
  49823. WC_RNG* rng)
  49824. {
  49825. wc_test_ret_t ret;
  49826. int i, j, k;
  49827. mp_zero(a);
  49828. mp_zero(d);
  49829. ret = mp_div(a, d, r, rem);
  49830. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49831. return WC_TEST_RET_ENC_EC(ret);
  49832. mp_set(d, 1);
  49833. ret = mp_div(a, d, r, rem);
  49834. if (ret != MP_OKAY)
  49835. return WC_TEST_RET_ENC_EC(ret);
  49836. if (!mp_iszero(r))
  49837. return WC_TEST_RET_ENC_EC(ret);
  49838. if (!mp_iszero(rem))
  49839. return WC_TEST_RET_ENC_EC(ret);
  49840. mp_set(a, 1);
  49841. ret = mp_div(a, d, r, rem);
  49842. if (ret != MP_OKAY)
  49843. return WC_TEST_RET_ENC_EC(ret);
  49844. if (!mp_isone(r))
  49845. return WC_TEST_RET_ENC_EC(ret);
  49846. if (!mp_iszero(rem))
  49847. return WC_TEST_RET_ENC_EC(ret);
  49848. for (i = 0; i < 100; i++) {
  49849. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 2; j++) {
  49850. ret = randNum(d, j, rng, NULL);
  49851. if (ret != MP_OKAY)
  49852. return WC_TEST_RET_ENC_EC(ret);
  49853. for (k = 1; k < (DIGIT_BIT + 7) / 8 * 2 + 1; k++) {
  49854. ret = randNum(a, k, rng, NULL);
  49855. if (ret != MP_OKAY)
  49856. return WC_TEST_RET_ENC_EC(ret);
  49857. ret = mp_div(a, d, NULL, rem);
  49858. if (ret != MP_OKAY)
  49859. return WC_TEST_RET_ENC_EC(ret);
  49860. ret = mp_div(a, d, r, NULL);
  49861. if (ret != MP_OKAY)
  49862. return WC_TEST_RET_ENC_EC(ret);
  49863. ret = mp_div(a, d, r, rem);
  49864. if (ret != MP_OKAY)
  49865. return WC_TEST_RET_ENC_EC(ret);
  49866. mp_mul(r, d, r);
  49867. mp_add(r, rem, r);
  49868. if (mp_cmp(r, a) != MP_EQ)
  49869. return WC_TEST_RET_ENC_NC;
  49870. }
  49871. }
  49872. }
  49873. ret = randNum(d, (DIGIT_BIT + 7) / 8 * 2, rng, NULL);
  49874. if (ret != MP_OKAY)
  49875. return WC_TEST_RET_ENC_EC(ret);
  49876. mp_add(d, d, a);
  49877. mp_set(rem, 1);
  49878. mp_div(a, d, NULL, rem);
  49879. if (ret != MP_OKAY)
  49880. return WC_TEST_RET_ENC_EC(ret);
  49881. if (!mp_iszero(rem))
  49882. return WC_TEST_RET_ENC_EC(ret);
  49883. mp_set(r, 1);
  49884. mp_div(a, d, r, NULL);
  49885. if (ret != MP_OKAY)
  49886. return WC_TEST_RET_ENC_EC(ret);
  49887. if (mp_cmp_d(r, 2) != MP_EQ)
  49888. return WC_TEST_RET_ENC_EC(ret);
  49889. mp_set(r, 1);
  49890. mp_set(rem, 1);
  49891. mp_div(a, d, r, rem);
  49892. if (ret != MP_OKAY)
  49893. return WC_TEST_RET_ENC_EC(ret);
  49894. if (mp_cmp_d(r, 2) != MP_EQ)
  49895. return WC_TEST_RET_ENC_EC(ret);
  49896. if (!mp_iszero(rem))
  49897. return WC_TEST_RET_ENC_EC(ret);
  49898. mp_set(a, 0xfe);
  49899. mp_lshd(a, 3);
  49900. mp_add_d(a, 0xff, a);
  49901. mp_set(d, 0xfe);
  49902. mp_lshd(d, 2);
  49903. ret = mp_div(a, d, r, rem);
  49904. if (ret != MP_OKAY)
  49905. return WC_TEST_RET_ENC_EC(ret);
  49906. mp_mul(r, d, d);
  49907. mp_add(rem, d, d);
  49908. if (mp_cmp(a, d) != MP_EQ)
  49909. return WC_TEST_RET_ENC_NC;
  49910. /* Force (hi | lo) / d to be (d | 0) / d which will would not fit in
  49911. * a digit. So mp_div must detect and handle.
  49912. * For example: 0x800000 / 0x8001, DIGIT_BIT = 8
  49913. */
  49914. mp_zero(a);
  49915. mp_set_bit(a, DIGIT_BIT * 3 - 1);
  49916. mp_zero(d);
  49917. mp_set_bit(d, DIGIT_BIT * 2 - 1);
  49918. mp_add_d(d, 1, d);
  49919. ret = mp_div(a, d, r, rem);
  49920. if (ret != MP_OKAY)
  49921. return WC_TEST_RET_ENC_EC(ret);
  49922. /* Make sure [d | d] / d is handled. */
  49923. mp_zero(a);
  49924. mp_set_bit(a, DIGIT_BIT * 2 - 1);
  49925. mp_set_bit(a, DIGIT_BIT * 1 - 1);
  49926. mp_zero(d);
  49927. mp_set_bit(d, DIGIT_BIT - 1);
  49928. ret = mp_div(a, d, r, rem);
  49929. if (ret != MP_OKAY)
  49930. return WC_TEST_RET_ENC_EC(ret);
  49931. mp_zero(a);
  49932. mp_set_bit(a, DIGIT_BIT);
  49933. mp_set_bit(a, 0);
  49934. mp_zero(d);
  49935. if (mp_cmp(r, a) != MP_EQ)
  49936. return WC_TEST_RET_ENC_NC;
  49937. if (mp_cmp(rem, d) != MP_EQ)
  49938. return WC_TEST_RET_ENC_NC;
  49939. return 0;
  49940. }
  49941. #endif
  49942. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  49943. !defined(WC_NO_RNG)
  49944. static wc_test_ret_t mp_test_prime(mp_int* a, WC_RNG* rng)
  49945. {
  49946. wc_test_ret_t ret;
  49947. int res;
  49948. ret = mp_rand_prime(a, 1, rng, NULL);
  49949. #if defined(WOLFSSL_SP_MATH_ALL)
  49950. if (ret != 0)
  49951. return WC_TEST_RET_ENC_EC(ret);
  49952. #else
  49953. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49954. return WC_TEST_RET_ENC_NC;
  49955. #endif
  49956. #ifndef WOLFSSL_SP_MATH
  49957. ret = mp_rand_prime(a, -5, rng, NULL);
  49958. if (ret != 0 || (a->dp[0] & 3) != 3)
  49959. return WC_TEST_RET_ENC_NC;
  49960. #endif
  49961. ret = mp_prime_is_prime(a, 1, &res);
  49962. if (ret != MP_OKAY)
  49963. return WC_TEST_RET_ENC_EC(ret);
  49964. #ifndef WOLFSSL_SP_MATH
  49965. if (res != MP_YES)
  49966. return WC_TEST_RET_ENC_EC(res);
  49967. #else
  49968. if (res != MP_NO)
  49969. return WC_TEST_RET_ENC_EC(res);
  49970. #endif
  49971. ret = mp_prime_is_prime(a, 0, &res);
  49972. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49973. return WC_TEST_RET_ENC_EC(ret);
  49974. ret = mp_prime_is_prime(a, -1, &res);
  49975. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49976. return WC_TEST_RET_ENC_EC(ret);
  49977. ret = mp_prime_is_prime(a, 257, &res);
  49978. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49979. return WC_TEST_RET_ENC_EC(ret);
  49980. mp_set(a, 1);
  49981. ret = mp_prime_is_prime(a, 1, &res);
  49982. if (ret != MP_OKAY)
  49983. return WC_TEST_RET_ENC_EC(ret);
  49984. if (res != MP_NO)
  49985. return WC_TEST_RET_ENC_EC(res);
  49986. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  49987. if (ret != MP_OKAY)
  49988. return WC_TEST_RET_ENC_EC(ret);
  49989. if (res != MP_NO)
  49990. return WC_TEST_RET_ENC_EC(res);
  49991. mp_set(a, 2);
  49992. ret = mp_prime_is_prime(a, 1, &res);
  49993. if (ret != MP_OKAY)
  49994. return WC_TEST_RET_ENC_EC(ret);
  49995. if (res != MP_YES)
  49996. return WC_TEST_RET_ENC_EC(res);
  49997. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  49998. if (ret != MP_OKAY)
  49999. return WC_TEST_RET_ENC_EC(ret);
  50000. if (res != MP_YES)
  50001. return WC_TEST_RET_ENC_EC(res);
  50002. mp_set(a, 0xfb);
  50003. ret = mp_prime_is_prime(a, 1, &res);
  50004. if (ret != MP_OKAY)
  50005. return WC_TEST_RET_ENC_EC(ret);
  50006. if (res != MP_YES)
  50007. return WC_TEST_RET_ENC_EC(res);
  50008. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50009. if (ret != MP_OKAY)
  50010. return WC_TEST_RET_ENC_EC(ret);
  50011. if (res != MP_YES)
  50012. return WC_TEST_RET_ENC_EC(res);
  50013. mp_set(a, 0x6);
  50014. ret = mp_prime_is_prime(a, 1, &res);
  50015. if (ret != MP_OKAY)
  50016. return WC_TEST_RET_ENC_EC(ret);
  50017. if (res != MP_NO)
  50018. return WC_TEST_RET_ENC_EC(res);
  50019. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50020. if (ret != MP_OKAY)
  50021. return WC_TEST_RET_ENC_EC(ret);
  50022. if (res != MP_NO)
  50023. return WC_TEST_RET_ENC_EC(res);
  50024. mp_set_int(a, 0x655 * 0x65b);
  50025. ret = mp_prime_is_prime(a, 10, &res);
  50026. if (ret != MP_OKAY)
  50027. return WC_TEST_RET_ENC_EC(ret);
  50028. if (res != MP_NO)
  50029. return WC_TEST_RET_ENC_EC(res);
  50030. ret = mp_prime_is_prime_ex(a, 10, &res, rng);
  50031. if (ret != MP_OKAY)
  50032. return WC_TEST_RET_ENC_EC(ret);
  50033. if (res != MP_NO)
  50034. return WC_TEST_RET_ENC_EC(res);
  50035. return 0;
  50036. }
  50037. #endif
  50038. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  50039. static wc_test_ret_t mp_test_lcm_gcd(mp_int* a, mp_int* b, mp_int* r, mp_int* exp,
  50040. WC_RNG* rng)
  50041. {
  50042. wc_test_ret_t ret;
  50043. int i;
  50044. WOLFSSL_SMALL_STACK_STATIC const int kat[][3] = {
  50045. { 1, 1, 1 }, { 2, 1, 2 }, { 1, 2, 2 }, { 2, 4, 4 }, { 4, 2, 4 },
  50046. { 12, 56, 168 }, { 56, 12, 168 }
  50047. };
  50048. (void)exp;
  50049. mp_set(a, 0);
  50050. mp_set(b, 1);
  50051. ret = mp_lcm(a, a, r);
  50052. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50053. return WC_TEST_RET_ENC_EC(ret);
  50054. ret = mp_lcm(a, b, r);
  50055. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50056. return WC_TEST_RET_ENC_EC(ret);
  50057. ret = mp_lcm(b, a, r);
  50058. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50059. return WC_TEST_RET_ENC_EC(ret);
  50060. for (i = 0; i < (int)(sizeof(kat) / sizeof(*kat)); i++) {
  50061. mp_set(a, kat[i][0]);
  50062. mp_set(b, kat[i][1]);
  50063. ret = mp_lcm(a, b, r);
  50064. if (ret != MP_OKAY)
  50065. return WC_TEST_RET_ENC_EC(ret);
  50066. mp_set(exp, kat[i][2]);
  50067. ret = mp_cmp(r, exp);
  50068. if (ret != MP_EQ)
  50069. return WC_TEST_RET_ENC_NC;
  50070. }
  50071. (void)rng;
  50072. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50073. !defined(WC_NO_RNG)
  50074. ret = mp_rand_prime(a, 20, rng, NULL);
  50075. if (ret != MP_OKAY)
  50076. return WC_TEST_RET_ENC_EC(ret);
  50077. ret = mp_rand_prime(b, 20, rng, NULL);
  50078. if (ret != MP_OKAY)
  50079. return WC_TEST_RET_ENC_EC(ret);
  50080. ret = mp_mul(a, b, exp);
  50081. if (ret != MP_OKAY)
  50082. return WC_TEST_RET_ENC_EC(ret);
  50083. ret = mp_lcm(a, b, r);
  50084. if (ret != MP_OKAY)
  50085. return WC_TEST_RET_ENC_EC(ret);
  50086. ret = mp_cmp(r, exp);
  50087. if (ret != MP_EQ)
  50088. return WC_TEST_RET_ENC_NC;
  50089. ret = mp_lcm(b, a, r);
  50090. if (ret != MP_OKAY)
  50091. return WC_TEST_RET_ENC_EC(ret);
  50092. ret = mp_cmp(r, exp);
  50093. if (ret != MP_EQ)
  50094. return WC_TEST_RET_ENC_NC;
  50095. #endif
  50096. mp_set(a, 11);
  50097. mp_zero(b);
  50098. ret = mp_gcd(a, b, r);
  50099. if (ret != MP_OKAY)
  50100. return WC_TEST_RET_ENC_EC(ret);
  50101. ret = mp_cmp_d(r, 11);
  50102. if (ret != MP_EQ)
  50103. return WC_TEST_RET_ENC_EC(ret);
  50104. ret = mp_gcd(b, a, r);
  50105. if (ret != MP_OKAY)
  50106. return WC_TEST_RET_ENC_EC(ret);
  50107. ret = mp_cmp_d(r, 11);
  50108. if (ret != MP_EQ)
  50109. return WC_TEST_RET_ENC_EC(ret);
  50110. ret = mp_gcd(b, b, r);
  50111. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50112. return WC_TEST_RET_ENC_EC(ret);
  50113. return 0;
  50114. }
  50115. #endif
  50116. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50117. defined(WOLFSSL_SP_MATH_ALL)
  50118. static wc_test_ret_t mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng)
  50119. {
  50120. wc_test_ret_t ret;
  50121. int i;
  50122. int j;
  50123. mp_set(a, 10);
  50124. ret = mp_mod_2d(a, 0, r);
  50125. if (ret != MP_OKAY)
  50126. return WC_TEST_RET_ENC_EC(ret);
  50127. if (!mp_iszero(r))
  50128. return WC_TEST_RET_ENC_NC;
  50129. ret = mp_mod_2d(a, 1, r);
  50130. if (ret != MP_OKAY)
  50131. return WC_TEST_RET_ENC_EC(ret);
  50132. if (!mp_iszero(r))
  50133. return WC_TEST_RET_ENC_NC;
  50134. ret = mp_mod_2d(a, 2, r);
  50135. if (ret != MP_OKAY)
  50136. return WC_TEST_RET_ENC_EC(ret);
  50137. ret = mp_cmp_d(r, 2);
  50138. if (ret != 0)
  50139. return WC_TEST_RET_ENC_EC(ret);
  50140. for (i = 2; i < 20; i++) {
  50141. ret = randNum(a, i, rng, NULL);
  50142. if (ret != 0)
  50143. return WC_TEST_RET_ENC_EC(ret);
  50144. for (j = 1; j <= mp_count_bits(a); j++) {
  50145. /* Get top part */
  50146. ret = mp_div_2d(a, j, t, NULL);
  50147. if (ret != 0)
  50148. return WC_TEST_RET_ENC_EC(ret);
  50149. ret = mp_mul_2d(t, j, t);
  50150. if (ret != 0)
  50151. return WC_TEST_RET_ENC_EC(ret);
  50152. /* Get bottom part */
  50153. ret = mp_mod_2d(a, j, r);
  50154. if (ret != 0)
  50155. return WC_TEST_RET_ENC_EC(ret);
  50156. /* Reassemble */
  50157. ret = mp_add(t, r, r);
  50158. if (ret != 0)
  50159. return WC_TEST_RET_ENC_EC(ret);
  50160. ret = mp_cmp(a, r);
  50161. if (ret != MP_EQ)
  50162. return WC_TEST_RET_ENC_NC;
  50163. }
  50164. }
  50165. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_SP_INT_NEGATIVE)
  50166. /* Test negative value being moded. */
  50167. for (j = 0; j < 20; j++) {
  50168. ret = randNum(a, 2, rng, NULL);
  50169. if (ret != 0)
  50170. return WC_TEST_RET_ENC_EC(ret);
  50171. a->sign = MP_NEG;
  50172. for (i = 1; i < DIGIT_BIT * 3 + 1; i++) {
  50173. ret = mp_mod_2d(a, i, r);
  50174. if (ret != 0)
  50175. return WC_TEST_RET_ENC_EC(ret);
  50176. mp_zero(t);
  50177. ret = mp_set_bit(t, i);
  50178. if (ret != 0)
  50179. return WC_TEST_RET_ENC_EC(ret);
  50180. ret = mp_mod(a, t, t);
  50181. if (ret != 0)
  50182. return WC_TEST_RET_ENC_EC(ret);
  50183. ret = mp_cmp(r, t);
  50184. if (ret != MP_EQ)
  50185. return WC_TEST_RET_ENC_NC;
  50186. }
  50187. }
  50188. #endif
  50189. return 0;
  50190. }
  50191. #endif
  50192. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50193. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50194. static wc_test_ret_t mp_test_mod_d(mp_int* a, WC_RNG* rng)
  50195. {
  50196. wc_test_ret_t ret;
  50197. mp_digit r;
  50198. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50199. mp_digit rem;
  50200. int i;
  50201. #endif
  50202. (void)rng;
  50203. ret = mp_set(a, 1);
  50204. if (ret != MP_OKAY)
  50205. return WC_TEST_RET_ENC_EC(ret);
  50206. ret = mp_mod_d(a, 0, &r);
  50207. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50208. return WC_TEST_RET_ENC_EC(ret);
  50209. mp_zero(a);
  50210. ret = mp_mod_d(a, 1, &r);
  50211. if (ret != MP_OKAY)
  50212. return WC_TEST_RET_ENC_EC(ret);
  50213. ret = mp_mod_d(a, 3, &r);
  50214. if (ret != MP_OKAY)
  50215. return WC_TEST_RET_ENC_EC(ret);
  50216. ret = mp_mod_d(a, 5, &r);
  50217. if (ret != MP_OKAY)
  50218. return WC_TEST_RET_ENC_EC(ret);
  50219. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50220. for (i = MP_MAX_TEST_BYTE_LEN - 16; i <= MP_MAX_TEST_BYTE_LEN; i++) {
  50221. ret = randNum(a, i, rng, NULL);
  50222. if (ret != MP_OKAY)
  50223. return WC_TEST_RET_ENC_EC(ret);
  50224. ret = mp_mod_d(a, 3, &r);
  50225. if (ret != MP_OKAY)
  50226. return WC_TEST_RET_ENC_EC(ret);
  50227. ret = mp_div_d(a, 3, a, &rem);
  50228. if (ret != MP_OKAY)
  50229. return WC_TEST_RET_ENC_EC(ret);
  50230. if (r != rem)
  50231. return WC_TEST_RET_ENC_NC;
  50232. }
  50233. #endif
  50234. return 0;
  50235. }
  50236. #endif
  50237. static wc_test_ret_t mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r2,
  50238. WC_RNG* rng)
  50239. {
  50240. wc_test_ret_t ret;
  50241. int i;
  50242. for (i = 1; i < 16; i++) {
  50243. ret = randNum(a, i, rng, NULL);
  50244. if (ret != 0)
  50245. return WC_TEST_RET_ENC_EC(ret);
  50246. ret = mp_mul(a, a, r1);
  50247. if (ret != 0)
  50248. return WC_TEST_RET_ENC_EC(ret);
  50249. ret = mp_sqr(a, r2);
  50250. if (ret != 0)
  50251. return WC_TEST_RET_ENC_EC(ret);
  50252. ret = mp_cmp(r1, r2);
  50253. if (ret != MP_EQ)
  50254. return WC_TEST_RET_ENC_NC;
  50255. }
  50256. ret = mp_set(b, 0);
  50257. if (ret != MP_OKAY)
  50258. return WC_TEST_RET_ENC_EC(ret);
  50259. ret = mp_mul(a, b, r1);
  50260. if (ret != MP_OKAY)
  50261. return WC_TEST_RET_ENC_EC(ret);
  50262. if (!mp_iszero(r1))
  50263. return WC_TEST_RET_ENC_EC(ret);
  50264. ret = mp_sqr(b, r1);
  50265. if (ret != MP_OKAY)
  50266. return WC_TEST_RET_ENC_EC(ret);
  50267. if (!mp_iszero(r1))
  50268. return WC_TEST_RET_ENC_NC;
  50269. #ifdef WOLFSSL_SP_MATH_ALL
  50270. ret = mp_set(a, 1);
  50271. if (ret != MP_OKAY)
  50272. return WC_TEST_RET_ENC_EC(ret);
  50273. i = (SP_INT_DIGITS / 2) + 1;
  50274. ret = mp_mul_2d(a, i * SP_WORD_SIZE - 1, a);
  50275. if (ret != MP_OKAY)
  50276. return WC_TEST_RET_ENC_EC(ret);
  50277. ret = mp_set(b, 1);
  50278. if (ret != MP_OKAY)
  50279. return WC_TEST_RET_ENC_EC(ret);
  50280. ret = mp_mul_2d(b, (SP_INT_DIGITS - 1 - i) * SP_WORD_SIZE - 1, b);
  50281. if (ret != MP_OKAY)
  50282. return WC_TEST_RET_ENC_EC(ret);
  50283. ret = mp_mul(a, b, r1);
  50284. if (ret != MP_OKAY)
  50285. return WC_TEST_RET_ENC_EC(ret);
  50286. ret = mp_mul(a, a, r1);
  50287. if (ret == MP_OKAY)
  50288. return WC_TEST_RET_ENC_NC;
  50289. ret = mp_sqr(a, r1);
  50290. if (ret == MP_OKAY)
  50291. return WC_TEST_RET_ENC_NC;
  50292. ret = mp_sqr(b, r1);
  50293. if (ret != MP_OKAY)
  50294. return WC_TEST_RET_ENC_EC(ret);
  50295. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50296. (defined(HAVE_ECC) && defined(FP_ECC))
  50297. ret = mp_mulmod(a, b, b, r1);
  50298. if (ret != MP_OKAY)
  50299. return WC_TEST_RET_ENC_EC(ret);
  50300. ret = mp_mulmod(a, a, b, r1);
  50301. if (ret == MP_OKAY)
  50302. return WC_TEST_RET_ENC_NC;
  50303. #if defined(HAVE_ECC) && (defined(ECC_SHAMIR) || defined(FP_ECC))
  50304. ret = mp_sqrmod(a, b, r1);
  50305. if (ret == MP_OKAY)
  50306. return WC_TEST_RET_ENC_NC;
  50307. ret = mp_sqrmod(b, a, r1);
  50308. if (ret != MP_OKAY)
  50309. return WC_TEST_RET_ENC_EC(ret);
  50310. #endif /* HAVE_ECC && (ECC_SHAMIR || FP_ECC) */
  50311. #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
  50312. #endif /* WOLFSSL_SP_MATH_ALL */
  50313. return 0;
  50314. }
  50315. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  50316. defined(OPENSSL_EXTRA)
  50317. static wc_test_ret_t mp_test_invmod(mp_int* a, mp_int* m, mp_int* r)
  50318. {
  50319. wc_test_ret_t ret;
  50320. mp_set(a, 0);
  50321. mp_set(m, 1);
  50322. ret = mp_invmod(a, m, r);
  50323. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50324. return WC_TEST_RET_ENC_EC(ret);
  50325. ret = mp_invmod(m, a, r);
  50326. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50327. return WC_TEST_RET_ENC_EC(ret);
  50328. mp_set(a, 2);
  50329. mp_set(m, 4);
  50330. ret = mp_invmod(a, m, r);
  50331. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50332. return WC_TEST_RET_ENC_EC(ret);
  50333. mp_set(a, 3);
  50334. mp_set(m, 6);
  50335. ret = mp_invmod(a, m, r);
  50336. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50337. return WC_TEST_RET_ENC_EC(ret);
  50338. mp_set(a, 5*9);
  50339. mp_set(m, 6*9);
  50340. ret = mp_invmod(a, m, r);
  50341. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50342. return WC_TEST_RET_ENC_EC(ret);
  50343. mp_set(a, 1);
  50344. mp_set(m, 4);
  50345. ret = mp_invmod(a, m, r);
  50346. if (ret != MP_OKAY)
  50347. return WC_TEST_RET_ENC_EC(ret);
  50348. if (!mp_isone(r))
  50349. return WC_TEST_RET_ENC_NC;
  50350. mp_set(a, 3);
  50351. mp_set(m, 4);
  50352. ret = mp_invmod(a, m, r);
  50353. if (ret != MP_OKAY)
  50354. return WC_TEST_RET_ENC_EC(ret);
  50355. ret = mp_cmp_d(r, 3);
  50356. if (ret != 0)
  50357. return WC_TEST_RET_ENC_EC(ret);
  50358. mp_set(a, 3);
  50359. mp_set(m, 5);
  50360. ret = mp_invmod(a, m, r);
  50361. if (ret != MP_OKAY)
  50362. return WC_TEST_RET_ENC_EC(ret);
  50363. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50364. /* Maximum 'a' */
  50365. mp_set(a, 0);
  50366. mp_set_bit(a, (r->size / 2)* SP_WORD_SIZE - 1);
  50367. mp_sub_d(a, 1, a);
  50368. /* Modulus too big. */
  50369. mp_set(m, 0);
  50370. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE);
  50371. ret = mp_invmod(a, m, r);
  50372. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50373. return WC_TEST_RET_ENC_EC(ret);
  50374. /* Maximum modulus - even. */
  50375. mp_set(m, 0);
  50376. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE - 1);
  50377. ret = mp_invmod(a, m, r);
  50378. if (ret != MP_OKAY)
  50379. return WC_TEST_RET_ENC_EC(ret);
  50380. #endif
  50381. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_INT_NEGATIVE)
  50382. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50383. mp_read_radix(a, "-3", 16);
  50384. ret = mp_invmod(a, m, r);
  50385. if (ret != MP_OKAY)
  50386. return WC_TEST_RET_ENC_EC(ret);
  50387. #endif
  50388. #endif
  50389. #if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC)
  50390. mp_set(a, 0);
  50391. mp_set(m, 3);
  50392. ret = mp_invmod_mont_ct(a, m, r, 1);
  50393. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50394. return WC_TEST_RET_ENC_EC(ret);
  50395. mp_set(a, 1);
  50396. mp_set(m, 0);
  50397. ret = mp_invmod_mont_ct(a, m, r, 1);
  50398. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50399. return WC_TEST_RET_ENC_EC(ret);
  50400. mp_set(a, 1);
  50401. mp_set(m, 1);
  50402. ret = mp_invmod_mont_ct(a, m, r, 1);
  50403. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50404. return WC_TEST_RET_ENC_EC(ret);
  50405. mp_set(a, 1);
  50406. mp_set(m, 2);
  50407. ret = mp_invmod_mont_ct(a, m, r, 1);
  50408. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50409. return WC_TEST_RET_ENC_EC(ret);
  50410. mp_set(a, 1);
  50411. mp_set(m, 3);
  50412. ret = mp_invmod_mont_ct(a, m, r, 1);
  50413. if (ret != MP_OKAY)
  50414. return WC_TEST_RET_ENC_EC(ret);
  50415. #endif
  50416. return 0;
  50417. }
  50418. #endif /* !NO_RSA || HAVE_ECC || !NO_DSA || OPENSSL_EXTRA */
  50419. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  50420. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  50421. static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r)
  50422. {
  50423. wc_test_ret_t ret;
  50424. mp_set(b, 0x2);
  50425. mp_set(e, 0x3);
  50426. mp_set(m, 0x0);
  50427. ret = mp_exptmod_ex(b, e, 1, m, r);
  50428. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50429. return WC_TEST_RET_ENC_EC(ret);
  50430. ret = mp_exptmod_nct(b, e, m, r);
  50431. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50432. return WC_TEST_RET_ENC_EC(ret);
  50433. mp_set(b, 0x2);
  50434. mp_set(e, 0x3);
  50435. mp_set(m, 0x1);
  50436. ret = mp_exptmod_ex(b, e, 1, m, r);
  50437. if (ret != MP_OKAY)
  50438. return WC_TEST_RET_ENC_EC(ret);
  50439. if (!mp_iszero(r))
  50440. return WC_TEST_RET_ENC_NC;
  50441. ret = mp_exptmod_nct(b, e, m, r);
  50442. if (ret != MP_OKAY)
  50443. return WC_TEST_RET_ENC_EC(ret);
  50444. if (!mp_iszero(r))
  50445. return WC_TEST_RET_ENC_NC;
  50446. mp_set(b, 0x2);
  50447. mp_set(e, 0x0);
  50448. mp_set(m, 0x7);
  50449. ret = mp_exptmod_ex(b, e, 1, m, r);
  50450. if (ret != MP_OKAY)
  50451. return WC_TEST_RET_ENC_EC(ret);
  50452. if (!mp_isone(r))
  50453. return WC_TEST_RET_ENC_NC;
  50454. ret = mp_exptmod_nct(b, e, m, r);
  50455. if (ret != MP_OKAY)
  50456. return WC_TEST_RET_ENC_EC(ret);
  50457. if (!mp_isone(r))
  50458. return WC_TEST_RET_ENC_NC;
  50459. mp_set(b, 0x0);
  50460. mp_set(e, 0x3);
  50461. mp_set(m, 0x7);
  50462. ret = mp_exptmod_ex(b, e, 1, m, r);
  50463. if (ret != MP_OKAY)
  50464. return WC_TEST_RET_ENC_EC(ret);
  50465. if (!mp_iszero(r))
  50466. return WC_TEST_RET_ENC_NC;
  50467. ret = mp_exptmod_nct(b, e, m, r);
  50468. if (ret != MP_OKAY)
  50469. return WC_TEST_RET_ENC_EC(ret);
  50470. if (!mp_iszero(r))
  50471. return WC_TEST_RET_ENC_NC;
  50472. mp_set(b, 0x10);
  50473. mp_set(e, 0x3);
  50474. mp_set(m, 0x7);
  50475. ret = mp_exptmod_ex(b, e, 1, m, r);
  50476. if (ret != MP_OKAY)
  50477. return WC_TEST_RET_ENC_EC(ret);
  50478. ret = mp_exptmod_nct(b, e, m, r);
  50479. if (ret != MP_OKAY)
  50480. return WC_TEST_RET_ENC_EC(ret);
  50481. mp_set(b, 0x7);
  50482. mp_set(e, 0x3);
  50483. mp_set(m, 0x7);
  50484. ret = mp_exptmod_ex(b, e, 1, m, r);
  50485. if (ret != MP_OKAY)
  50486. return WC_TEST_RET_ENC_EC(ret);
  50487. if (!mp_iszero(r))
  50488. return WC_TEST_RET_ENC_NC;
  50489. ret = mp_exptmod_nct(b, e, m, r);
  50490. if (ret != MP_OKAY)
  50491. return WC_TEST_RET_ENC_EC(ret);
  50492. if (!mp_iszero(r))
  50493. return WC_TEST_RET_ENC_NC;
  50494. #ifndef WOLFSSL_SP_MATH
  50495. mp_set(b, 0x01);
  50496. mp_mul_2d(b, DIGIT_BIT, b);
  50497. mp_add_d(b, 1, b);
  50498. mp_set(e, 0x3);
  50499. mp_copy(b, m);
  50500. ret = mp_exptmod_ex(b, e, 1, m, r);
  50501. if (ret != MP_OKAY)
  50502. return WC_TEST_RET_ENC_EC(ret);
  50503. if (!mp_iszero(r))
  50504. return WC_TEST_RET_ENC_NC;
  50505. ret = mp_exptmod_nct(b, e, m, r);
  50506. if (ret != MP_OKAY)
  50507. return WC_TEST_RET_ENC_EC(ret);
  50508. if (!mp_iszero(r))
  50509. return WC_TEST_RET_ENC_NC;
  50510. #endif
  50511. mp_set(b, 0x2);
  50512. mp_set(e, 0x3);
  50513. mp_set(m, 0x7);
  50514. ret = mp_exptmod_ex(b, e, 1, m, r);
  50515. if (ret != MP_OKAY)
  50516. return WC_TEST_RET_ENC_EC(ret);
  50517. ret = mp_exptmod_nct(b, e, m, r);
  50518. if (ret != MP_OKAY)
  50519. return WC_TEST_RET_ENC_EC(ret);
  50520. #ifdef WOLFSSL_SP_MATH_ALL
  50521. mp_set(b, 0x2);
  50522. mp_set(e, 0x3);
  50523. mp_set(m, 0x01);
  50524. mp_mul_2d(m, SP_WORD_SIZE * SP_INT_DIGITS / 2, m);
  50525. mp_add_d(m, 0x01, m);
  50526. ret = mp_exptmod_ex(b, e, 1, m, r);
  50527. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50528. return WC_TEST_RET_ENC_EC(ret);
  50529. ret = mp_exptmod_nct(b, e, m, r);
  50530. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50531. return WC_TEST_RET_ENC_EC(ret);
  50532. #endif
  50533. return 0;
  50534. }
  50535. #endif /* !NO_RSA || !NO_DSA || !NO_DH || (HAVE_ECC && HAVE_COMP_KEY) ||
  50536. * OPENSSL_EXTRA */
  50537. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50538. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50539. static wc_test_ret_t mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng)
  50540. {
  50541. wc_test_ret_t ret;
  50542. mp_digit mp;
  50543. static int exp[] = { 7, 8, 16, 27, 32, 64,
  50544. 127, 128, 255, 256,
  50545. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  50546. 383, 384, 2033, 2048
  50547. #endif
  50548. };
  50549. static mp_digit sub[] = { 0x01, 0x05, 0x0f, 0x27, 0x05, 0x3b,
  50550. 0x01, 0x9f, 0x13, 0xbd,
  50551. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  50552. 0x1f, 0x13d, 0x45, 0x615
  50553. #endif
  50554. };
  50555. int bits[] = { 256, 384,
  50556. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 4096
  50557. 2048,
  50558. #endif
  50559. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 6144
  50560. 3072
  50561. #endif
  50562. };
  50563. int i;
  50564. int j;
  50565. for (i = 0; i < (int)(sizeof(exp) / sizeof(*exp)); i++) {
  50566. if (exp[i] >= DIGIT_BIT)
  50567. continue;
  50568. mp_zero(m);
  50569. ret = mp_set_bit(m, exp[i]);
  50570. if (ret != MP_OKAY)
  50571. return WC_TEST_RET_ENC_EC(ret);
  50572. ret = mp_sub_d(m, sub[i], m);
  50573. if (ret != MP_OKAY)
  50574. return WC_TEST_RET_ENC_EC(ret);
  50575. ret = mp_montgomery_setup(m, &mp);
  50576. if (ret != MP_OKAY)
  50577. return WC_TEST_RET_ENC_EC(ret);
  50578. ret = mp_montgomery_calc_normalization(n, m);
  50579. if (ret != MP_OKAY)
  50580. return WC_TEST_RET_ENC_EC(ret);
  50581. for (j = 0; j < 10; j++) {
  50582. ret = randNum(a, (exp[i] + DIGIT_BIT - 1) / DIGIT_BIT, rng, NULL);
  50583. if (ret != 0)
  50584. return WC_TEST_RET_ENC_EC(ret);
  50585. ret = mp_mod(a, m, a);
  50586. if (ret != 0)
  50587. return WC_TEST_RET_ENC_EC(ret);
  50588. /* r = a * a */
  50589. ret = mp_sqrmod(a, m, r);
  50590. if (ret != MP_OKAY)
  50591. return WC_TEST_RET_ENC_EC(ret);
  50592. /* Convert to Montgomery form = a*n */
  50593. ret = mp_mulmod(a, n, m, a);
  50594. if (ret != MP_OKAY)
  50595. return WC_TEST_RET_ENC_EC(ret);
  50596. /* a*a mod m == ((a*n) * (a*n)) / n / n */
  50597. ret = mp_sqr(a, a);
  50598. if (ret != MP_OKAY)
  50599. return WC_TEST_RET_ENC_EC(ret);
  50600. ret = mp_montgomery_reduce(a, m, mp);
  50601. if (ret != MP_OKAY)
  50602. return WC_TEST_RET_ENC_EC(ret);
  50603. ret = mp_montgomery_reduce(a, m, mp);
  50604. if (ret != MP_OKAY)
  50605. return WC_TEST_RET_ENC_EC(ret);
  50606. if (mp_cmp(a, r) != MP_EQ)
  50607. return WC_TEST_RET_ENC_NC;
  50608. }
  50609. }
  50610. /* Force carries. */
  50611. for (i = 0; i < (int)(sizeof(bits) / sizeof(*bits)); i++) {
  50612. /* a = 2^(bits*2) - 1 */
  50613. mp_zero(a);
  50614. mp_set_bit(a, bits[i] * 2);
  50615. mp_sub_d(a, 1, a);
  50616. /* m = 2^(bits) - 1 */
  50617. mp_zero(m);
  50618. mp_set_bit(m, bits[i]);
  50619. mp_sub_d(m, 1, m);
  50620. mp = 1;
  50621. /* result = r = 2^(bits) - 1 */
  50622. mp_zero(r);
  50623. mp_set_bit(r, bits[i]);
  50624. mp_sub_d(r, 1, r);
  50625. ret = mp_montgomery_reduce(a, m, mp);
  50626. if (ret != MP_OKAY)
  50627. return WC_TEST_RET_ENC_EC(ret);
  50628. /* Result is m or 0 if reduced to range of modulus. */
  50629. if (mp_cmp(a, r) != MP_EQ && mp_iszero(a) != MP_YES)
  50630. return WC_TEST_RET_ENC_NC;
  50631. }
  50632. return 0;
  50633. }
  50634. #endif
  50635. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
  50636. {
  50637. WC_RNG rng;
  50638. int rng_inited = 0;
  50639. wc_test_ret_t ret;
  50640. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  50641. int i, j;
  50642. #ifndef WOLFSSL_SP_MATH
  50643. int k;
  50644. #endif
  50645. mp_digit d = 0;
  50646. #endif
  50647. #ifdef WOLFSSL_SMALL_STACK
  50648. mp_int *a = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50649. DYNAMIC_TYPE_TMP_BUFFER),
  50650. *b = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50651. DYNAMIC_TYPE_TMP_BUFFER),
  50652. *r1 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50653. DYNAMIC_TYPE_TMP_BUFFER),
  50654. *r2 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50655. DYNAMIC_TYPE_TMP_BUFFER),
  50656. *p = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  50657. DYNAMIC_TYPE_TMP_BUFFER);
  50658. if ((a == NULL) ||
  50659. (b == NULL) ||
  50660. (r1 == NULL) ||
  50661. (r2 == NULL) ||
  50662. (p == NULL))
  50663. {
  50664. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  50665. }
  50666. #else
  50667. mp_int a[1], b[1], r1[1], r2[1], p[1];
  50668. #endif
  50669. WOLFSSL_ENTER("mp_test");
  50670. ret = mp_init_multi(a, b, r1, r2, NULL, NULL);
  50671. if (ret != 0)
  50672. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50673. #ifdef WOLFSSL_SP_MATH_ALL
  50674. mp_init_copy(p, a);
  50675. #else
  50676. ret = mp_init(p);
  50677. if (ret != 0)
  50678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50679. #endif
  50680. #ifndef HAVE_FIPS
  50681. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  50682. #else
  50683. ret = wc_InitRng(&rng);
  50684. #endif
  50685. if (ret != 0)
  50686. goto done;
  50687. rng_inited = 1;
  50688. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  50689. mp_set_int(a, 0);
  50690. if (a->used != 0 || a->dp[0] != 0)
  50691. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50692. for (j = 1; j <= MP_MAX_TEST_BYTE_LEN; j++) {
  50693. for (i = 0; i < 4 * j; i++) {
  50694. /* New values to use. */
  50695. ret = randNum(p, j, &rng, NULL);
  50696. if (ret != 0)
  50697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50698. ret = randNum(a, j, &rng, NULL);
  50699. if (ret != 0)
  50700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50701. ret = randNum(b, j, &rng, NULL);
  50702. if (ret != 0)
  50703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50704. ret = wc_RNG_GenerateBlock(&rng, (byte*)&d, sizeof(d));
  50705. if (ret != 0)
  50706. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50707. d &= MP_MASK;
  50708. #if !defined(WOLFSSL_SP_MATH) || (defined(HAVE_ECC) && \
  50709. (defined(ECC_SHAMIR) || defined(FP_ECC)))
  50710. /* Ensure sqrmod produce same result as mulmod. */
  50711. ret = mp_sqrmod(a, p, r1);
  50712. if (ret != 0)
  50713. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50714. ret = mp_mulmod(a, a, p, r2);
  50715. if (ret != 0)
  50716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50717. if (mp_cmp(r1, r2) != 0) {
  50718. WOLFSSL_MSG("Fail: mp_mulmod result does not match mp_sqrmod!");
  50719. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50720. }
  50721. #endif
  50722. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50723. #if defined(WOLFSSL_SP_MATH) || (defined(WOLFSSL_SP_MATH_ALL) && \
  50724. !defined(WOLFSSL_SP_INT_NEGATIVE))
  50725. ret = mp_addmod(a, b, p, r1);
  50726. if (ret != 0)
  50727. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50728. ret = mp_submod(r1, b, p, r2);
  50729. if (ret != 0)
  50730. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50731. ret = mp_mod(a, p, r1);
  50732. if (ret != 0)
  50733. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50734. if (mp_cmp(r1, r2) != MP_EQ)
  50735. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50736. #else
  50737. /* Ensure add with mod produce same result as sub with mod. */
  50738. ret = mp_addmod(a, b, p, r1);
  50739. if (ret != 0)
  50740. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50741. b->sign ^= 1;
  50742. ret = mp_submod(a, b, p, r2);
  50743. if (ret != 0)
  50744. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50745. if (mp_cmp(r1, r2) != 0)
  50746. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50747. #endif
  50748. #endif
  50749. /* Ensure add digit produce same result as sub digit. */
  50750. ret = mp_add_d(a, d, r1);
  50751. if (ret != 0)
  50752. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50753. ret = mp_sub_d(r1, d, r2);
  50754. if (ret != 0)
  50755. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50756. if (mp_cmp(a, r2) != 0)
  50757. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50758. /* Invert - if p is even it will use the slow impl.
  50759. * - if p and a are even it will fail.
  50760. */
  50761. ret = mp_invmod(a, p, r1);
  50762. if (ret != 0 && ret != WC_NO_ERR_TRACE(MP_VAL))
  50763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50764. #ifndef WOLFSSL_SP_MATH
  50765. /* Shift up and down number all bits in a digit. */
  50766. for (k = 0; k < DIGIT_BIT; k++) {
  50767. mp_mul_2d(a, k, r1);
  50768. mp_div_2d(r1, k, r2, p);
  50769. if (mp_cmp(a, r2) != 0)
  50770. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50771. if (!mp_iszero(p))
  50772. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50773. mp_rshb(r1, k);
  50774. if (mp_cmp(a, r1) != 0)
  50775. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50776. }
  50777. #endif
  50778. }
  50779. }
  50780. /* Test adding and subtracting zero from zero. */
  50781. mp_zero(a);
  50782. ret = mp_add_d(a, 0, r1);
  50783. if (ret != 0)
  50784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50785. if (!mp_iszero(r1)) {
  50786. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50787. }
  50788. ret = mp_sub_d(a, 0, r2);
  50789. if (ret != 0)
  50790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  50791. if (!mp_iszero(r2)) {
  50792. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50793. }
  50794. #if DIGIT_BIT >= 32
  50795. /* Check that setting a 32-bit digit works. */
  50796. d &= 0xffffffffU;
  50797. mp_set_int(a, d);
  50798. if (a->used != 1 || a->dp[0] != d)
  50799. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50800. #endif
  50801. /* Check setting a bit and testing a bit works. */
  50802. for (i = 0; i < MP_MAX_TEST_BYTE_LEN * 8; i++) {
  50803. mp_zero(a);
  50804. mp_set_bit(a, i);
  50805. if (!mp_is_bit_set(a, i))
  50806. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  50807. }
  50808. #endif
  50809. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  50810. mp_zero(a);
  50811. i = mp_cnt_lsb(a);
  50812. if (i != 0)
  50813. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  50814. mp_set(a, 1);
  50815. i = mp_cnt_lsb(a);
  50816. if (i != 0)
  50817. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  50818. mp_set(a, 32);
  50819. i = mp_cnt_lsb(a);
  50820. if (i != 5)
  50821. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  50822. mp_zero(a);
  50823. mp_set_bit(a, 129);
  50824. i = mp_cnt_lsb(a);
  50825. if (i != 129)
  50826. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  50827. #endif
  50828. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50829. if ((ret = mp_test_param(a, b, r1, &rng)) != 0)
  50830. goto done;
  50831. #endif
  50832. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  50833. if ((ret = mp_test_div_3(a, r1, &rng)) != 0)
  50834. goto done;
  50835. #endif
  50836. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  50837. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  50838. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  50839. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  50840. if ((ret = mp_test_radix_10(a, r1, &rng)) != 0)
  50841. goto done;
  50842. #endif
  50843. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  50844. defined(HAVE_ECC))
  50845. if ((ret = mp_test_radix_16(a, r1, &rng)) != 0)
  50846. goto done;
  50847. #endif
  50848. if ((ret = mp_test_shift(a, r1, &rng)) != 0)
  50849. goto done;
  50850. if ((ret = mp_test_add_sub_d(a, r1)) != 0)
  50851. goto done;
  50852. if ((ret = mp_test_read_to_bin(a)) != 0)
  50853. goto done;
  50854. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50855. if ((ret = mp_test_set_int(a)) != 0)
  50856. goto done;
  50857. #endif
  50858. if ((ret = mp_test_cmp(a, r1)) != 0)
  50859. goto done;
  50860. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50861. if ((ret = mp_test_shbd(a, b, &rng)) != 0)
  50862. goto done;
  50863. #endif
  50864. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50865. if ((ret = mp_test_set_is_bit(a)) != 0)
  50866. goto done;
  50867. #endif
  50868. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50869. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  50870. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  50871. if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0)
  50872. goto done;
  50873. #endif
  50874. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50875. !defined(WC_NO_RNG)
  50876. if ((ret = mp_test_prime(a, &rng)) != 0)
  50877. goto done;
  50878. #endif
  50879. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  50880. if ((ret = mp_test_lcm_gcd(a, b, r1, r2, &rng)) != 0)
  50881. goto done;
  50882. #endif
  50883. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50884. defined(WOLFSSL_SP_MATH_ALL)
  50885. if ((ret = mp_test_mod_2d(a, r1, p, &rng)) != 0)
  50886. goto done;
  50887. #endif
  50888. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50889. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50890. if ((ret = mp_test_mod_d(a, &rng)) != 0)
  50891. goto done;
  50892. #endif
  50893. if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0)
  50894. goto done;
  50895. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  50896. defined(OPENSSL_EXTRA)
  50897. if ((ret = mp_test_invmod(a, b, r1)) != 0)
  50898. goto done;
  50899. #endif
  50900. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  50901. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  50902. if ((ret = mp_test_exptmod(a, b, r1, r2)) != 0)
  50903. goto done;
  50904. #endif
  50905. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50906. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50907. if ((ret = mp_test_mont(a, b, r1, r2, &rng)) != 0)
  50908. goto done;
  50909. #endif
  50910. done:
  50911. #ifdef WOLFSSL_SMALL_STACK
  50912. if (p) {
  50913. mp_clear(p);
  50914. XFREE(p, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50915. }
  50916. if (r2) {
  50917. mp_clear(r2);
  50918. XFREE(r2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50919. }
  50920. if (r1) {
  50921. mp_clear(r1);
  50922. XFREE(r1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50923. }
  50924. if (b) {
  50925. mp_clear(b);
  50926. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50927. }
  50928. if (a) {
  50929. mp_clear(a);
  50930. XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50931. }
  50932. #else
  50933. mp_clear(p);
  50934. mp_clear(r2);
  50935. mp_clear(r1);
  50936. mp_clear(b);
  50937. mp_clear(a);
  50938. #endif
  50939. if (rng_inited)
  50940. wc_FreeRng(&rng);
  50941. return ret;
  50942. }
  50943. #endif /* WOLFSSL_PUBLIC_MP && ((WOLFSSL_SP_MATH_ALL &&
  50944. * !WOLFSSL_RSA_VERIFY_ONLY) || USE_FAST_MATH) */
  50945. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  50946. typedef struct pairs_t {
  50947. const unsigned char* coeff;
  50948. int coeffSz;
  50949. int exp;
  50950. } pairs_t;
  50951. /*
  50952. n =p1p2p3, where pi = ki(p1-1)+1 with (k2,k3) = (173,293)
  50953. p1 = 2^192 * 0x000000000000e24fd4f6d6363200bf2323ec46285cac1d3a
  50954. + 2^0 * 0x0b2488b0c29d96c5e67f8bec15b54b189ae5636efe89b45b
  50955. */
  50956. static const unsigned char c192a[] =
  50957. {
  50958. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x4f,
  50959. 0xd4, 0xf6, 0xd6, 0x36, 0x32, 0x00, 0xbf, 0x23,
  50960. 0x23, 0xec, 0x46, 0x28, 0x5c, 0xac, 0x1d, 0x3a
  50961. };
  50962. static const unsigned char c0a[] =
  50963. {
  50964. 0x0b, 0x24, 0x88, 0xb0, 0xc2, 0x9d, 0x96, 0xc5,
  50965. 0xe6, 0x7f, 0x8b, 0xec, 0x15, 0xb5, 0x4b, 0x18,
  50966. 0x9a, 0xe5, 0x63, 0x6e, 0xfe, 0x89, 0xb4, 0x5b
  50967. };
  50968. static const pairs_t ecPairsA[] =
  50969. {
  50970. {c192a, sizeof(c192a), 192},
  50971. {c0a, sizeof(c0a), 0}
  50972. };
  50973. static const int kA[] = {173, 293};
  50974. static const unsigned char controlPrime[] = {
  50975. 0xe1, 0x76, 0x45, 0x80, 0x59, 0xb6, 0xd3, 0x49,
  50976. 0xdf, 0x0a, 0xef, 0x12, 0xd6, 0x0f, 0xf0, 0xb7,
  50977. 0xcb, 0x2a, 0x37, 0xbf, 0xa7, 0xf8, 0xb5, 0x4d,
  50978. 0xf5, 0x31, 0x35, 0xad, 0xe4, 0xa3, 0x94, 0xa1,
  50979. 0xdb, 0xf1, 0x96, 0xad, 0xb5, 0x05, 0x64, 0x85,
  50980. 0x83, 0xfc, 0x1b, 0x5b, 0x29, 0xaa, 0xbe, 0xf8,
  50981. 0x26, 0x3f, 0x76, 0x7e, 0xad, 0x1c, 0xf0, 0xcb,
  50982. 0xd7, 0x26, 0xb4, 0x1b, 0x05, 0x8e, 0x56, 0x86,
  50983. 0x7e, 0x08, 0x62, 0x21, 0xc1, 0x86, 0xd6, 0x47,
  50984. 0x79, 0x3e, 0xb7, 0x5d, 0xa4, 0xc6, 0x3a, 0xd7,
  50985. 0xb1, 0x74, 0x20, 0xf6, 0x50, 0x97, 0x41, 0x04,
  50986. 0x53, 0xed, 0x3f, 0x26, 0xd6, 0x6f, 0x91, 0xfa,
  50987. 0x68, 0x26, 0xec, 0x2a, 0xdc, 0x9a, 0xf1, 0xe7,
  50988. 0xdc, 0xfb, 0x73, 0xf0, 0x79, 0x43, 0x1b, 0x21,
  50989. 0xa3, 0x59, 0x04, 0x63, 0x52, 0x07, 0xc9, 0xd7,
  50990. 0xe6, 0xd1, 0x1b, 0x5d, 0x5e, 0x96, 0xfa, 0x53
  50991. };
  50992. static const unsigned char testOne[] = { 1 };
  50993. static wc_test_ret_t GenerateNextP(mp_int* p1, mp_int* p2, int k)
  50994. {
  50995. wc_test_ret_t ret;
  50996. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  50997. mp_int *ki = (mp_int *)XMALLOC(sizeof(*ki), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  50998. if (ki == NULL)
  50999. return MEMORY_E;
  51000. #else
  51001. mp_int ki[1];
  51002. #endif
  51003. ret = mp_init(ki);
  51004. if (ret != 0)
  51005. ret = WC_TEST_RET_ENC_EC(ret);
  51006. if (ret == 0) {
  51007. ret = mp_set(ki, (mp_digit)k);
  51008. if (ret != 0)
  51009. ret = WC_TEST_RET_ENC_EC(ret);
  51010. }
  51011. if (ret == 0) {
  51012. ret = mp_sub_d(p1, 1, p2);
  51013. if (ret != 0)
  51014. ret = WC_TEST_RET_ENC_EC(ret);
  51015. }
  51016. if (ret == 0) {
  51017. ret = mp_mul(p2, ki, p2);
  51018. if (ret != 0)
  51019. ret = WC_TEST_RET_ENC_EC(ret);
  51020. }
  51021. if (ret == 0) {
  51022. ret = mp_add_d(p2, 1, p2);
  51023. if (ret != 0)
  51024. ret = WC_TEST_RET_ENC_EC(ret);
  51025. }
  51026. mp_clear(ki);
  51027. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51028. XFREE(ki, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51029. #endif
  51030. return ret;
  51031. }
  51032. static wc_test_ret_t GenerateP(mp_int* p1, mp_int* p2, mp_int* p3,
  51033. const pairs_t* ecPairs, int ecPairsSz,
  51034. const int* k)
  51035. {
  51036. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51037. mp_int *x = NULL, *y = NULL;
  51038. #else
  51039. mp_int x[1], y[1];
  51040. #endif
  51041. wc_test_ret_t ret;
  51042. int i;
  51043. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51044. if (((x = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) ||
  51045. ((y = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)) {
  51046. ret = MEMORY_E;
  51047. goto out;
  51048. }
  51049. #endif
  51050. ret = mp_init_multi(x, y, NULL, NULL, NULL, NULL);
  51051. if (ret != 0) {
  51052. ret = WC_TEST_RET_ENC_EC(ret);
  51053. goto out;
  51054. }
  51055. for (i = 0; ret == 0 && i < ecPairsSz; i++) {
  51056. ret = mp_read_unsigned_bin(x, ecPairs[i].coeff, (word32)ecPairs[i].coeffSz);
  51057. if (ret != 0) {
  51058. ret = WC_TEST_RET_ENC_EC(ret);
  51059. break;
  51060. }
  51061. /* p1 = 2^exp */
  51062. ret = mp_2expt(y, ecPairs[i].exp);
  51063. if (ret != 0) {
  51064. ret = WC_TEST_RET_ENC_EC(ret);
  51065. break;
  51066. }
  51067. /* p1 = p1 * m */
  51068. ret = mp_mul(x, y, x);
  51069. if (ret != 0) {
  51070. ret = WC_TEST_RET_ENC_EC(ret);
  51071. break;
  51072. }
  51073. /* p1 += */
  51074. ret = mp_add(p1, x, p1);
  51075. if (ret != 0) {
  51076. ret = WC_TEST_RET_ENC_EC(ret);
  51077. break;
  51078. }
  51079. mp_zero(x);
  51080. mp_zero(y);
  51081. }
  51082. if (ret == 0)
  51083. ret = GenerateNextP(p1, p2, k[0]);
  51084. if (ret == 0)
  51085. ret = GenerateNextP(p1, p3, k[1]);
  51086. out:
  51087. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51088. if (x != NULL) {
  51089. mp_clear(x);
  51090. XFREE(x, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51091. }
  51092. if (y != NULL) {
  51093. mp_clear(y);
  51094. XFREE(y, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51095. }
  51096. #else
  51097. mp_clear(x);
  51098. mp_clear(y);
  51099. #endif
  51100. return ret;
  51101. }
  51102. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void)
  51103. {
  51104. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51105. mp_int *n = (mp_int *)XMALLOC(sizeof *n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51106. *p1 = (mp_int *)XMALLOC(sizeof *p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51107. *p2 = (mp_int *)XMALLOC(sizeof *p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51108. *p3 = (mp_int *)XMALLOC(sizeof *p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51109. #else
  51110. mp_int n[1],
  51111. p1[1],
  51112. p2[1],
  51113. p3[1];
  51114. #endif
  51115. wc_test_ret_t ret;
  51116. int isPrime = 0;
  51117. WC_RNG rng;
  51118. WOLFSSL_ENTER("prime_test");
  51119. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51120. if ((n == NULL) ||
  51121. (p1 == NULL) ||
  51122. (p2 == NULL) ||
  51123. (p3 == NULL))
  51124. ERROR_OUT(MEMORY_E, out);
  51125. #endif
  51126. ret = wc_InitRng(&rng);
  51127. if (ret != 0)
  51128. ret = WC_TEST_RET_ENC_EC(ret);
  51129. if (ret == 0) {
  51130. ret = mp_init_multi(n, p1, p2, p3, NULL, NULL);
  51131. if (ret != 0)
  51132. ret = WC_TEST_RET_ENC_EC(ret);
  51133. }
  51134. if (ret == 0)
  51135. ret = GenerateP(p1, p2, p3,
  51136. ecPairsA, sizeof(ecPairsA) / sizeof(ecPairsA[0]), kA);
  51137. if (ret == 0) {
  51138. ret = mp_mul(p1, p2, n);
  51139. if (ret != 0)
  51140. ret = WC_TEST_RET_ENC_EC(ret);
  51141. }
  51142. if (ret == 0) {
  51143. ret = mp_mul(n, p3, n);
  51144. if (ret != 0)
  51145. ret = WC_TEST_RET_ENC_EC(ret);
  51146. }
  51147. if (ret != 0)
  51148. ERROR_OUT(ret, out);
  51149. /* Check the old prime test using the number that false positives.
  51150. * This test result should indicate as not prime. */
  51151. ret = mp_prime_is_prime(n, 40, &isPrime);
  51152. if (ret != 0)
  51153. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51154. if (isPrime)
  51155. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51156. /* This test result should fail. It should indicate the value as prime. */
  51157. ret = mp_prime_is_prime(n, 8, &isPrime);
  51158. if (ret != 0)
  51159. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51160. if (!isPrime)
  51161. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51162. /* This test result should indicate the value as not prime. */
  51163. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51164. if (ret != 0)
  51165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51166. if (isPrime)
  51167. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51168. ret = mp_read_unsigned_bin(n, controlPrime, sizeof(controlPrime));
  51169. if (ret != 0)
  51170. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51171. /* This test result should indicate the value as prime. */
  51172. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51173. if (ret != 0)
  51174. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51175. if (!isPrime)
  51176. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51177. /* This test result should indicate the value as prime. */
  51178. isPrime = -1;
  51179. ret = mp_prime_is_prime(n, 8, &isPrime);
  51180. if (ret != 0)
  51181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51182. if (!isPrime)
  51183. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51184. ret = mp_read_unsigned_bin(n, testOne, sizeof(testOne));
  51185. if (ret != 0)
  51186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51187. /* This test result should indicate the value as not prime. */
  51188. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51189. if (ret != 0)
  51190. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51191. if (isPrime)
  51192. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51193. ret = mp_prime_is_prime(n, 8, &isPrime);
  51194. if (ret != 0)
  51195. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51196. if (isPrime)
  51197. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51198. ret = 0;
  51199. out:
  51200. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51201. if (n != NULL) {
  51202. mp_clear(n);
  51203. XFREE(n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51204. }
  51205. if (p1 != NULL) {
  51206. mp_clear(p1);
  51207. XFREE(p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51208. }
  51209. if (p2 != NULL) {
  51210. mp_clear(p2);
  51211. XFREE(p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51212. }
  51213. if (p3 != NULL) {
  51214. mp_clear(p3);
  51215. XFREE(p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51216. }
  51217. #else
  51218. mp_clear(p3);
  51219. mp_clear(p2);
  51220. mp_clear(p1);
  51221. mp_clear(n);
  51222. #endif
  51223. wc_FreeRng(&rng);
  51224. return ret;
  51225. }
  51226. #endif /* WOLFSSL_PUBLIC_MP */
  51227. #ifdef ASN_BER_TO_DER
  51228. /* wc_BerToDer is only public facing in the case of test cert or opensslextra */
  51229. typedef struct berDerTestData {
  51230. const byte *in;
  51231. word32 inSz;
  51232. const byte *out;
  51233. word32 outSz;
  51234. } berDerTestData;
  51235. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void)
  51236. {
  51237. wc_test_ret_t ret;
  51238. int i;
  51239. word32 len = 0, l;
  51240. byte out[32];
  51241. WOLFSSL_SMALL_STACK_STATIC const byte good1_in[] = { 0x30, 0x80, 0x00, 0x00 };
  51242. WOLFSSL_SMALL_STACK_STATIC const byte good1_out[] = { 0x30, 0x00 };
  51243. WOLFSSL_SMALL_STACK_STATIC const byte good2_in[] = { 0x30, 0x80, 0x02, 0x01, 0x01, 0x00, 0x00 };
  51244. WOLFSSL_SMALL_STACK_STATIC const byte good2_out[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51245. WOLFSSL_SMALL_STACK_STATIC const byte good3_in[] = {
  51246. 0x24, 0x80, 0x04, 0x01, 0x01, 0x00, 0x00
  51247. };
  51248. WOLFSSL_SMALL_STACK_STATIC const byte good3_out[] = { 0x04, 0x1, 0x01 };
  51249. WOLFSSL_SMALL_STACK_STATIC const byte good4_in[] = {
  51250. 0x30, 0x80,
  51251. 0x02, 0x01, 0x01,
  51252. 0x30, 0x80,
  51253. 0x24, 0x80,
  51254. 0x04, 0x01, 0x01,
  51255. 0x04, 0x02, 0x02, 0x03,
  51256. 0x00, 0x00,
  51257. 0x06, 0x01, 0x01,
  51258. 0x00, 0x00,
  51259. 0x31, 0x80,
  51260. 0x06, 0x01, 0x01,
  51261. 0x00, 0x00,
  51262. 0x00, 0x00,
  51263. };
  51264. WOLFSSL_SMALL_STACK_STATIC const byte good4_out[] = {
  51265. 0x30, 0x12,
  51266. 0x02, 0x01, 0x01,
  51267. 0x30, 0x08,
  51268. 0x04, 0x03, 0x01, 0x02, 0x03,
  51269. 0x06, 0x01, 0x01,
  51270. 0x31, 0x03,
  51271. 0x06, 0x01, 0x01
  51272. };
  51273. WOLFSSL_SMALL_STACK_STATIC const byte good5_in[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51274. berDerTestData testData[] = {
  51275. { good1_in, sizeof(good1_in), good1_out, sizeof(good1_out) },
  51276. { good2_in, sizeof(good2_in), good2_out, sizeof(good2_out) },
  51277. { good3_in, sizeof(good3_in), good3_out, sizeof(good3_out) },
  51278. { good4_in, sizeof(good4_in), good4_out, sizeof(good4_out) },
  51279. { good5_in, sizeof(good5_in), good5_in , sizeof(good5_in ) },
  51280. };
  51281. WOLFSSL_ENTER("berder_test");
  51282. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  51283. ret = wc_BerToDer(testData[i].in, testData[i].inSz, NULL, &len);
  51284. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  51285. return WC_TEST_RET_ENC_I(i);
  51286. if (len != testData[i].outSz)
  51287. return WC_TEST_RET_ENC_I(i);
  51288. len = testData[i].outSz;
  51289. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &len);
  51290. if (ret != 0)
  51291. return WC_TEST_RET_ENC_I(i);
  51292. if (XMEMCMP(out, testData[i].out, len) != 0)
  51293. return WC_TEST_RET_ENC_I(i);
  51294. for (l = 1; l < testData[i].inSz; l++) {
  51295. ret = wc_BerToDer(testData[i].in, l, NULL, &len);
  51296. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  51297. return WC_TEST_RET_ENC_EC(ret);
  51298. len = testData[i].outSz;
  51299. ret = wc_BerToDer(testData[i].in, l, out, &len);
  51300. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  51301. return WC_TEST_RET_ENC_EC(ret);
  51302. }
  51303. for (l = 0; l < testData[i].outSz-1; l++) {
  51304. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &l);
  51305. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  51306. return WC_TEST_RET_ENC_EC(ret);
  51307. }
  51308. }
  51309. ret = wc_BerToDer(NULL, 4, NULL, NULL);
  51310. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51311. return WC_TEST_RET_ENC_EC(ret);
  51312. ret = wc_BerToDer(out, 4, NULL, NULL);
  51313. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51314. return WC_TEST_RET_ENC_EC(ret);
  51315. ret = wc_BerToDer(NULL, 4, NULL, &len);
  51316. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51317. return WC_TEST_RET_ENC_EC(ret);
  51318. ret = wc_BerToDer(NULL, 4, out, NULL);
  51319. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51320. return WC_TEST_RET_ENC_EC(ret);
  51321. ret = wc_BerToDer(out, 4, out, NULL);
  51322. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51323. return WC_TEST_RET_ENC_EC(ret);
  51324. ret = wc_BerToDer(NULL, 4, out, &len);
  51325. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51326. return WC_TEST_RET_ENC_EC(ret);
  51327. for (l = 1; l < sizeof(good4_out); l++) {
  51328. len = l;
  51329. ret = wc_BerToDer(good4_in, sizeof(good4_in), out, &len);
  51330. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  51331. return WC_TEST_RET_ENC_EC(ret);
  51332. }
  51333. return 0;
  51334. }
  51335. #endif /* ASN_BER_TO_DER */
  51336. #ifdef DEBUG_WOLFSSL
  51337. static THREAD_LS_T int log_cnt = 0;
  51338. static void my_Logging_cb(const int logLevel, const char *const logMessage)
  51339. {
  51340. (void)logLevel;
  51341. (void)logMessage;
  51342. log_cnt++;
  51343. }
  51344. #endif /* DEBUG_WOLFSSL */
  51345. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void)
  51346. {
  51347. wc_test_ret_t ret;
  51348. #ifdef DEBUG_WOLFSSL
  51349. const char* msg = "Testing, testing. 1, 2, 3, 4 ...";
  51350. byte a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  51351. byte b[256];
  51352. int i;
  51353. WOLFSSL_ENTER("logging_test (debug)");
  51354. for (i = 0; i < (int)sizeof(b); i++)
  51355. b[i] = i;
  51356. ret = wolfSSL_Debugging_ON();
  51357. if (ret != 0)
  51358. return WC_TEST_RET_ENC_EC(ret);
  51359. ret = wolfSSL_SetLoggingCb(my_Logging_cb);
  51360. if (ret != 0)
  51361. return WC_TEST_RET_ENC_EC(ret);
  51362. WOLFSSL_MSG(msg);
  51363. WOLFSSL_BUFFER(a, sizeof(a));
  51364. WOLFSSL_BUFFER(b, sizeof(b));
  51365. WOLFSSL_BUFFER(NULL, 0);
  51366. WOLFSSL_ERROR(MEMORY_E);
  51367. WOLFSSL_ERROR_MSG(msg);
  51368. /* turn off logs */
  51369. wolfSSL_Debugging_OFF();
  51370. /* capture log count */
  51371. i = log_cnt;
  51372. /* validate no logs are output when disabled */
  51373. WOLFSSL_MSG(msg);
  51374. WOLFSSL_BUFFER(a, sizeof(a));
  51375. WOLFSSL_BUFFER(b, sizeof(b));
  51376. WOLFSSL_BUFFER(NULL, 0);
  51377. WOLFSSL_ERROR(MEMORY_E);
  51378. WOLFSSL_ERROR_MSG(msg);
  51379. /* check the logs were disabled */
  51380. if (i != log_cnt)
  51381. return WC_TEST_RET_ENC_NC;
  51382. /* restore callback and leave logging enabled */
  51383. wolfSSL_SetLoggingCb(NULL);
  51384. wolfSSL_Debugging_ON();
  51385. /* suppress unused args */
  51386. (void)a;
  51387. (void)b;
  51388. #else
  51389. WOLFSSL_ENTER("logging_test");
  51390. ret = wolfSSL_Debugging_ON();
  51391. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  51392. return WC_TEST_RET_ENC_EC(ret);
  51393. wolfSSL_Debugging_OFF();
  51394. ret = wolfSSL_SetLoggingCb(NULL);
  51395. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  51396. return WC_TEST_RET_ENC_EC(ret);
  51397. #endif /* DEBUG_WOLFSSL */
  51398. return 0;
  51399. }
  51400. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  51401. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void)
  51402. #else
  51403. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void)
  51404. #endif
  51405. {
  51406. #ifdef WOLFSSL_PTHREADS
  51407. wolfSSL_Mutex m;
  51408. #endif
  51409. #if defined(WOLFSSL_PTHREADS) || (!defined(WOLFSSL_NO_MALLOC) && \
  51410. !defined(WOLFSSL_USER_MUTEX) && defined(WOLFSSL_STATIC_MEMORY))
  51411. wc_test_ret_t ret;
  51412. #endif
  51413. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_USER_MUTEX)
  51414. #ifndef WOLFSSL_STATIC_MEMORY
  51415. wolfSSL_Mutex *mm = wc_InitAndAllocMutex();
  51416. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (1)");
  51417. #else
  51418. wolfSSL_Mutex *mm = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex),
  51419. HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51420. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (2)");
  51421. if (mm != NULL) {
  51422. ret = wc_InitMutex(mm);
  51423. if (ret != 0) {
  51424. WOLFSSL_MSG("Init Mutex failed");
  51425. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51426. return WC_TEST_RET_ENC_EC(ret);
  51427. }
  51428. }
  51429. #endif
  51430. if (mm == NULL)
  51431. return WC_TEST_RET_ENC_ERRNO;
  51432. wc_FreeMutex(mm);
  51433. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51434. #endif
  51435. /* Can optionally enable advanced pthread tests using "ENABLE_PTHREAD_LOCKFREE_TESTS" */
  51436. #ifdef WOLFSSL_PTHREADS
  51437. ret = wc_InitMutex(&m);
  51438. if (ret != 0)
  51439. return WC_TEST_RET_ENC_EC(ret);
  51440. ret = wc_LockMutex(&m);
  51441. if (ret != 0)
  51442. return WC_TEST_RET_ENC_EC(ret);
  51443. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  51444. /* trying to free a locked mutex is not portable behavior with pthread */
  51445. /* Attempting to destroy a locked mutex results in undefined behavior */
  51446. ret = wc_FreeMutex(&m);
  51447. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51448. return WC_TEST_RET_ENC_EC(ret);
  51449. #endif
  51450. ret = wc_UnLockMutex(&m);
  51451. if (ret != 0)
  51452. return WC_TEST_RET_ENC_EC(ret);
  51453. ret = wc_FreeMutex(&m);
  51454. if (ret != 0)
  51455. return WC_TEST_RET_ENC_EC(ret);
  51456. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  51457. /* Trying to use a pthread after free'ing is not portable behavior */
  51458. ret = wc_LockMutex(&m);
  51459. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51460. return WC_TEST_RET_ENC_EC(ret);
  51461. ret = wc_UnLockMutex(&m);
  51462. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51463. return WC_TEST_RET_ENC_EC(ret);
  51464. #endif
  51465. #endif
  51466. return 0;
  51467. }
  51468. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  51469. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \
  51470. !defined(WOLFSSL_STATIC_MEMORY)
  51471. static wc_test_ret_t malloc_cnt = 0;
  51472. static wc_test_ret_t realloc_cnt = 0;
  51473. static wc_test_ret_t free_cnt = 0;
  51474. #ifdef WOLFSSL_DEBUG_MEMORY
  51475. static void *my_Malloc_cb(size_t size, const char* func, unsigned int line)
  51476. {
  51477. (void) func;
  51478. (void) line;
  51479. #else
  51480. static void *my_Malloc_cb(size_t size)
  51481. {
  51482. #endif
  51483. malloc_cnt++;
  51484. #ifndef WOLFSSL_NO_MALLOC
  51485. return malloc(size);
  51486. #else
  51487. WOLFSSL_MSG("No malloc available");
  51488. (void)size;
  51489. return NULL;
  51490. #endif
  51491. }
  51492. #ifdef WOLFSSL_DEBUG_MEMORY
  51493. static void my_Free_cb(void *ptr, const char* func, unsigned int line)
  51494. {
  51495. (void) func;
  51496. (void) line;
  51497. #else
  51498. static void my_Free_cb(void *ptr)
  51499. {
  51500. #endif
  51501. free_cnt++;
  51502. #ifndef WOLFSSL_NO_MALLOC
  51503. free(ptr);
  51504. #else
  51505. WOLFSSL_MSG("No free available");
  51506. (void)ptr;
  51507. #endif
  51508. }
  51509. #ifdef WOLFSSL_DEBUG_MEMORY
  51510. static void *my_Realloc_cb(void *ptr, size_t size, const char* func, unsigned int line)
  51511. {
  51512. (void) func;
  51513. (void) line;
  51514. #else
  51515. static void *my_Realloc_cb(void *ptr, size_t size)
  51516. {
  51517. #endif
  51518. realloc_cnt++;
  51519. #ifndef WOLFSSL_NO_MALLOC
  51520. return realloc(ptr, size);
  51521. #else
  51522. WOLFSSL_MSG("No realloc available");
  51523. (void)ptr;
  51524. (void)size;
  51525. return NULL;
  51526. #endif
  51527. }
  51528. #endif /* !WOLFSSL_NO_MALLOC */
  51529. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void)
  51530. {
  51531. wc_test_ret_t ret = 0;
  51532. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51533. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51534. byte* b = NULL;
  51535. #endif
  51536. wolfSSL_Malloc_cb mc;
  51537. wolfSSL_Free_cb fc;
  51538. wolfSSL_Realloc_cb rc;
  51539. WOLFSSL_ENTER("memcb_test");
  51540. /* Save existing memory callbacks */
  51541. ret = wolfSSL_GetAllocators(&mc, &fc, &rc);
  51542. if (ret != 0)
  51543. return WC_TEST_RET_ENC_EC(ret);
  51544. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51545. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51546. /* test realloc */
  51547. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51548. if (b == NULL) {
  51549. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_memcb);
  51550. }
  51551. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51552. b = NULL;
  51553. /* Use API. */
  51554. ret = wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb,
  51555. (wolfSSL_Free_cb)my_Free_cb,
  51556. (wolfSSL_Realloc_cb)my_Realloc_cb);
  51557. if (ret != 0) {
  51558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_memcb);
  51559. }
  51560. b = (byte*)XMALLOC(1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51561. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51562. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51563. #ifndef WOLFSSL_STATIC_MEMORY
  51564. #ifndef WOLFSSL_CHECK_MEM_ZERO
  51565. if (malloc_cnt != 1 || free_cnt != 1 || realloc_cnt != 1)
  51566. #else
  51567. /* Checking zeroized memory means realloc is a malloc and free. */
  51568. if (malloc_cnt != 2 || free_cnt != 2 || realloc_cnt != 0)
  51569. #endif
  51570. #else
  51571. if (malloc_cnt != 0 || free_cnt != 0 || realloc_cnt != 0)
  51572. #endif
  51573. ret = WC_TEST_RET_ENC_NC;
  51574. #endif /* !WOLFSSL_NO_MALLOC */
  51575. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51576. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51577. exit_memcb:
  51578. /* reset malloc/free/realloc counts */
  51579. malloc_cnt = 0;
  51580. free_cnt = 0;
  51581. realloc_cnt = 0;
  51582. #endif
  51583. /* restore memory callbacks */
  51584. wolfSSL_SetAllocators(mc, fc, rc);
  51585. return ret;
  51586. }
  51587. #endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_NO_MALLOC */
  51588. #if defined(WOLFSSL_CAAM_BLOB)
  51589. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void)
  51590. {
  51591. wc_test_ret_t ret = 0;
  51592. byte out[112];
  51593. byte blob[112];
  51594. word32 outSz;
  51595. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  51596. {
  51597. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  51598. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  51599. };
  51600. WOLFSSL_SMALL_STACK_STATIC const byte text[] =
  51601. {
  51602. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  51603. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  51604. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  51605. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  51606. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  51607. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  51608. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  51609. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  51610. };
  51611. WOLFSSL_ENTER("blob_test");
  51612. XMEMSET(blob, 0, sizeof(blob));
  51613. XMEMSET(out, 0, sizeof(out));
  51614. outSz = sizeof(blob);
  51615. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  51616. if (ret != 0)
  51617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51618. blob[outSz - 2] += 1;
  51619. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51620. if (ret == 0) { /* should fail with altered blob */
  51621. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51622. }
  51623. XMEMSET(blob, 0, sizeof(blob));
  51624. outSz = sizeof(blob);
  51625. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  51626. if (ret != 0)
  51627. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51628. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51629. if (ret != 0)
  51630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51631. if (XMEMCMP(out, iv, sizeof(iv))) {
  51632. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51633. }
  51634. XMEMSET(blob, 0, sizeof(blob));
  51635. outSz = sizeof(blob);
  51636. ret = wc_caamCreateBlob((byte*)text, sizeof(text), blob, &outSz);
  51637. if (ret != 0)
  51638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51639. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51640. if (ret != 0)
  51641. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51642. if (XMEMCMP(out, text, sizeof(text))) {
  51643. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51644. }
  51645. exit_blob:
  51646. return ret;
  51647. }
  51648. #endif /* WOLFSSL_CAAM_BLOB */
  51649. #ifdef WOLF_CRYPTO_CB
  51650. /* Example custom context for crypto callback */
  51651. typedef struct {
  51652. int exampleVar; /* flag for testing if only crypt is enabled. */
  51653. } myCryptoDevCtx;
  51654. #ifdef WOLF_CRYPTO_CB_ONLY_RSA
  51655. /* Testing rsa cb when CB_ONLY_RSA is enabled
  51656. * When CB_ONLY_RSA is enabled, software imple. is not available.
  51657. *
  51658. * ctx callback ctx
  51659. * returen 0 on success, otherwise return negative
  51660. */
  51661. static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
  51662. {
  51663. wc_test_ret_t ret = 0;
  51664. #if !defined(NO_RSA)
  51665. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51666. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key,
  51667. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51668. byte* tmp = NULL;
  51669. #else
  51670. RsaKey key[1];
  51671. byte tmp[FOURK_BUF];
  51672. #endif
  51673. size_t bytes;
  51674. const word32 inLen = (word32)TEST_STRING_SZ;
  51675. word32 idx = 0;
  51676. word32 sigSz;
  51677. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  51678. byte out[RSA_TEST_BYTES];
  51679. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  51680. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  51681. !defined(NO_FILESYSTEM)
  51682. XFILE file;
  51683. #endif
  51684. #ifdef WOLFSSL_KEY_GEN
  51685. WC_RNG rng;
  51686. #endif
  51687. #ifdef USE_CERT_BUFFERS_1024
  51688. bytes = (size_t)sizeof_client_key_der_1024;
  51689. if (bytes < (size_t)sizeof_client_cert_der_1024)
  51690. bytes = (size_t)sizeof_client_cert_der_1024;
  51691. #elif defined(USE_CERT_BUFFERS_2048)
  51692. bytes = (size_t)sizeof_client_key_der_2048;
  51693. if (bytes < (size_t)sizeof_client_cert_der_2048)
  51694. bytes = (size_t)sizeof_client_cert_der_2048;
  51695. #elif defined(USE_CERT_BUFFERS_3072)
  51696. bytes = (size_t)sizeof_client_key_der_3072;
  51697. if (bytes < (size_t)sizeof_client_cert_der_3072)
  51698. bytes = (size_t)sizeof_client_cert_der_3072;
  51699. #elif defined(USE_CERT_BUFFERS_4096)
  51700. bytes = (size_t)sizeof_client_key_der_4096;
  51701. if (bytes < (size_t)sizeof_client_cert_der_4096)
  51702. bytes = (size_t)sizeof_client_cert_der_4096;
  51703. #else
  51704. bytes = FOURK_BUF;
  51705. #endif
  51706. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51707. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51708. if (tmp == NULL)
  51709. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  51710. #endif
  51711. #ifdef USE_CERT_BUFFERS_1024
  51712. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  51713. #elif defined(USE_CERT_BUFFERS_2048)
  51714. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  51715. #elif defined(USE_CERT_BUFFERS_3072)
  51716. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  51717. #elif defined(USE_CERT_BUFFERS_4096)
  51718. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  51719. #elif !defined(NO_FILESYSTEM)
  51720. file = XFOPEN(clientKey, "rb");
  51721. if (!file) {
  51722. ret = WC_TEST_RET_ENC_ERRNO;
  51723. err_sys("can't open ./certs/client-key.der, "
  51724. "Please run from wolfSSL home dir", ret);
  51725. ERROR_OUT(ret, exit_onlycb);
  51726. }
  51727. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  51728. XFCLOSE(file);
  51729. if (bytes == 0)
  51730. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  51731. #endif
  51732. #ifdef WOLFSSL_KEY_GEN
  51733. /* wc_CryptoCb_MakeRsaKey cb test, no actual making key
  51734. * wc_MakeRsaKey() -> rsa cb ->
  51735. * myCryptoDevCb -> wc_MakeRsaKey(CBONLY_TEST_DEVID)
  51736. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
  51737. */
  51738. ctx->exampleVar = 99;
  51739. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  51740. if (ret != 0)
  51741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51742. /* wc_MakeRsaKey() -> rsa cb ->
  51743. * myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
  51744. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
  51745. */
  51746. ctx->exampleVar = 1;
  51747. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  51748. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51750. } else
  51751. /* reset return code */
  51752. ret = 0;
  51753. #endif
  51754. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  51755. if (ret != 0)
  51756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51757. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  51758. if (ret != 0)
  51759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51760. sigSz = (word32)wc_RsaEncryptSize(key);
  51761. /* wc_CryptoCb_Rsa cb test, no actual rsa operation */
  51762. if (ret == 0) {
  51763. /* wc_SignatureGenerate() -> rsa cb ->
  51764. * myCryptoDevCb -> wc_RsaFunction(CBONLY_TEST_DEVID)
  51765. * wc_RsaFunction(CBONLY_TEST_DEVID) expects to return 0(success)
  51766. */
  51767. ctx->exampleVar = 99;
  51768. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  51769. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  51770. if (ret != 0)
  51771. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51772. }
  51773. if (ret == 0) {
  51774. /* wc_SignatureGenerate() -> rsa cb ->
  51775. * myCryptoDevCb -> wc_RsaFunction(INVALID_DEVID)
  51776. * wc_SignatureGenerate(INVALID_DEVID) expects to
  51777. * return NO_VALID_DEVID(failure)
  51778. */
  51779. ctx->exampleVar = 1;
  51780. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  51781. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  51782. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51784. } else
  51785. /* reset return code */
  51786. ret = 0;
  51787. }
  51788. exit_onlycb:
  51789. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51790. if (key != NULL) {
  51791. wc_FreeRsaKey(key);
  51792. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51793. }
  51794. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51795. #else
  51796. wc_FreeRsaKey(key);
  51797. #endif
  51798. #endif
  51799. return ret;
  51800. }
  51801. #endif
  51802. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  51803. /* Testing rsa cb when CB_ONLY_ECC is enabled
  51804. * When CB_ONLY_ECC is enabled, software imple. is not available.
  51805. *
  51806. * ctx callback ctx
  51807. * returen 0 on success, otherwise return negative
  51808. */
  51809. static wc_test_ret_t ecc_onlycb_test(myCryptoDevCtx *ctx)
  51810. {
  51811. wc_test_ret_t ret = 0;
  51812. #if defined(HAVE_ECC)
  51813. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51814. ecc_key* key = (ecc_key *)XMALLOC(sizeof *key,
  51815. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51816. ecc_key* pub = (ecc_key *)XMALLOC(sizeof *pub,
  51817. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51818. byte* out = (byte*)XMALLOC(sizeof(byte),
  51819. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51820. #ifdef OPENSSL_EXTRA
  51821. byte* check = (byte*)XMALLOC(sizeof(byte)*(256), HEAP_HINT,
  51822. DYNAMIC_TYPE_TMP_BUFFER);
  51823. #endif
  51824. #else
  51825. ecc_key key[1];
  51826. ecc_key pub[1];
  51827. byte out[256];
  51828. #ifdef OPENSSL_EXTRA
  51829. unsigned char check[256];
  51830. #endif
  51831. #endif
  51832. #ifdef OPENSSL_EXTRA
  51833. EVP_PKEY* privKey = NULL;
  51834. EVP_PKEY* pubKey = NULL;
  51835. #ifdef USE_CERT_BUFFERS_256
  51836. ecc_key* pkey;
  51837. const unsigned char* cp;
  51838. #endif
  51839. EVP_MD_CTX mdCtx;
  51840. const char testData[] = "Hi There";
  51841. size_t checkSz = -1;
  51842. const unsigned char* p;
  51843. const unsigned char check_v[256] = {
  51844. 0x30,0x45,0x02,0x20,0x1b,0x5c,0x2a,0xf0,0x18,0x09,
  51845. 0x74,0x65,0xa1,0x04,0x76,0x3a,0xce,0xcc,0xe5,0x34,
  51846. 0x5e,0x89,0xed,0x40,0x1e,0x5a,0xb1,0x53,0xb4,0xff,
  51847. 0xc7,0x18,0xfe,0x0f,0xc7,0xa6,0x02,0x21,0x00,0xe5,
  51848. 0x70,0x21,0xfc,0xf9,0x63,0x36,0xfd,0x16,0x18,0x08,
  51849. 0x9a,0x63,0x61,0x0f,0xe7,0x7c,0xa3,0xc9,0x14,0xa3,
  51850. 0x30,0x87,0xf7,0xf5,0x70,0x19,0xaf,0x56,0x96,0x9b,
  51851. 0xd8,0x64,0xcd,0xd9,0xff,0x7b,0x2a,0x55,0x52,0xca,
  51852. 0x41,0xb2,0xa6,0xa4,0x8a,0x3b,0x02,0x20,0x8c,0xc5,
  51853. 0xf9,0xc1,0x7d,0x2a,0x65,0x6c,0xe6,0x5a,0xe3,0x76,
  51854. 0x9b,0xab,0x0b,0x9f,0xaf,0x62,0x5d,0xb2,0x60,0xd7,
  51855. 0xeb,0xb4,0x1b,0x73,0xdc,0x01,0x7d,0x7b,0xab,0xc1,
  51856. 0x0c,0x74,0x96,0x41,0xe6,0x3f,0xc5,0x86,0xe6,0x7d,
  51857. 0x2b,0x9d,0x54,0x6b,0xcd,0x31,0x35,0x1f,0xdb,0x49,
  51858. 0x1f,0x32,0x34,0xf8,0x57,0x12,0x86,0x5c,0x0e,0x80,
  51859. 0x55,0x8d,0xff,0xd8,0xbd,0xdf,0x32,0x26,0x62,0x42,
  51860. 0x09,0xda,0xf7,0x74,0xf2,0x3f,0xe6,0xf1,0x77,0x82,
  51861. 0xce,0xe4,0xbb,0x61,0xa6,0xc0,0x17,0x0c,0x6c,0x47,
  51862. 0x2a,0x40,0x1c,0x2b,0xe0,0x98,0x3b,0xbf,0xc6,0xf8,
  51863. 0x6d,0xfd,0xd0,0xfa,0xc1,0x02,0xfb,0x5f,0xfb,0xb0,
  51864. 0xcb,0xd9,0xa3,0x59,0x94,0xe9,0x0f,0x74,0xbb,0x3f,
  51865. 0x64,0xa3,0x83,0xc4,0x2b,0xf7,0xd2,0x97,0xbf,0x3b,
  51866. 0xcf,0xbb,0x60,0x81,0x33,0x94,0xfa,0x0d,0x35,0xd2,
  51867. 0x3d,0xb9,0x99,0xe3,0x12,0xf8,0xf4,0xa3,0x74,0xf4,
  51868. 0x94,0x1d,0x7a,0x66,0xf8,0xd1,0x1d,0xcf,0xb0,0x48,
  51869. 0xef,0x8c,0x94,0x6f,0xdd,0x62,
  51870. };
  51871. #endif
  51872. WC_RNG rng;
  51873. EncryptedInfo encInfo;
  51874. int keyFormat = 0;
  51875. word32 keyIdx = 0;
  51876. byte in[] = "Everyone gets Friday off. ecc p";
  51877. word32 inLen = (word32)XSTRLEN((char*)in);
  51878. word32 outLen;
  51879. int verify;
  51880. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51881. if (key == NULL || pub == NULL) {
  51882. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  51883. }
  51884. #endif
  51885. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  51886. if (ret != 0)
  51887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51888. /* wc_CryptoCb_MakeEccKey cb test, , no actual testing */
  51889. ctx->exampleVar = 99;
  51890. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  51891. if (ret != 0)
  51892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51893. ctx->exampleVar = 1;
  51894. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  51895. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51897. } else
  51898. /* reset return code */
  51899. ret = 0;
  51900. #ifdef USE_CERT_BUFFERS_256
  51901. if (ret == 0) {
  51902. /* load ECC private key and perform private transform */
  51903. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &keyIdx,
  51904. key, sizeof_ecc_key_der_256);
  51905. }
  51906. if (ret != 0)
  51907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51908. /* wc_CryptoCb_EccSign cb test, no actual testing */
  51909. ctx->exampleVar = 99;
  51910. if (ret == 0) {
  51911. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  51912. }
  51913. if (ret != 0)
  51914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51915. ctx->exampleVar = 1;
  51916. if (ret == 0) {
  51917. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  51918. }
  51919. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51921. }
  51922. else
  51923. ret = 0;
  51924. /* wc_CryptoCb_EccVerify cb test, no actual testing */
  51925. ctx->exampleVar = 99;
  51926. if (ret == 0) {
  51927. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  51928. }
  51929. if (ret != 0)
  51930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51931. ctx->exampleVar = 1;
  51932. if (ret == 0) {
  51933. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  51934. }
  51935. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51936. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51937. }
  51938. else
  51939. ret = 0;
  51940. /* wc_CryptoCb_Ecdh cb test, no actual testing */
  51941. /* make public key for shared secret */
  51942. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  51943. ctx->exampleVar = 99;
  51944. if (ret == 0) {
  51945. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  51946. }
  51947. if (ret != 0)
  51948. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51949. ctx->exampleVar = 1;
  51950. if (ret == 0) {
  51951. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  51952. }
  51953. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  51954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51955. }
  51956. else
  51957. ret = 0;
  51958. #ifdef OPENSSL_EXTRA
  51959. (void)pkey;
  51960. cp = ecc_clikey_der_256;
  51961. privKey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp,
  51962. sizeof_ecc_clikey_der_256);
  51963. if (privKey == NULL) {
  51964. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51965. }
  51966. pkey = (ecc_key*)privKey->ecc->internal;
  51967. pkey->devId = devId;
  51968. p = ecc_clikeypub_der_256;
  51969. pubKey = d2i_PUBKEY(NULL, &p, sizeof_ecc_clikeypub_der_256);
  51970. if (pubKey == NULL) {
  51971. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51972. }
  51973. pkey = (ecc_key*)pubKey->ecc->internal;
  51974. pkey->devId = devId;
  51975. /* sign */
  51976. EVP_MD_CTX_init(&mdCtx);
  51977. ret = EVP_DigestSignInit(&mdCtx, NULL, EVP_sha256(), NULL, privKey);
  51978. if (ret != WOLFSSL_SUCCESS) {
  51979. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51980. }
  51981. ret = EVP_DigestSignUpdate(&mdCtx, testData,
  51982. (unsigned int)XSTRLEN(testData));
  51983. if (ret != WOLFSSL_SUCCESS) {
  51984. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51985. }
  51986. ret = EVP_DigestSignFinal(&mdCtx, NULL, &checkSz);
  51987. if (ret != WOLFSSL_SUCCESS) {
  51988. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  51989. }
  51990. ctx->exampleVar = 99;
  51991. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  51992. /* just called crypt callback as dummy
  51993. * EVP_DigestSignFinal returns 0 internally.
  51994. */
  51995. if (ret != 0)
  51996. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  51997. ctx->exampleVar = 1;
  51998. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  51999. /* just called crypt callback as dummy
  52000. * EVP_DigestSignFinal returns 0 internally.
  52001. */
  52002. if (ret != 0)
  52003. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52004. /* restore checkSz for verify */
  52005. checkSz = 71;
  52006. ret = EVP_MD_CTX_cleanup(&mdCtx);
  52007. if (ret != SSL_SUCCESS) {
  52008. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52009. }
  52010. /* verify */
  52011. EVP_MD_CTX_init(&mdCtx);
  52012. if (ret == SSL_SUCCESS) {
  52013. ret = EVP_DigestVerifyInit(&mdCtx, NULL, EVP_sha256(), NULL, pubKey);
  52014. }
  52015. if (ret != WOLFSSL_SUCCESS) {
  52016. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52017. }
  52018. if (ret == WOLFSSL_SUCCESS) {
  52019. ret = EVP_DigestVerifyUpdate(&mdCtx, testData,
  52020. (unsigned int)XSTRLEN(testData));
  52021. }
  52022. if (ret != WOLFSSL_SUCCESS) {
  52023. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52024. }
  52025. ctx->exampleVar = 99;
  52026. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52027. /* just called crypt callback as dummy
  52028. * EVP_DigestSignFinal returns 0 internally.
  52029. */
  52030. if (ret != 0)
  52031. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52032. ctx->exampleVar = 1;
  52033. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52034. /* just called crypt callback as dummy
  52035. * EVP_DigestVerifyFinal returns -1 internally rather than NO_VALID_DEVID.
  52036. */
  52037. if (ret != -1) {
  52038. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52039. }
  52040. ret = EVP_MD_CTX_cleanup(&mdCtx);
  52041. if (ret != SSL_SUCCESS) {
  52042. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52043. } else
  52044. ret = 0;
  52045. #endif
  52046. #else
  52047. (void)verify;
  52048. (void)outLen;
  52049. (void)inLen;
  52050. (void)out;
  52051. (void)pub;
  52052. #ifdef OPENSSL_EXTRA
  52053. (void)privKey;
  52054. (void)pubKey;
  52055. (void)mdCtx;
  52056. (void)check;
  52057. (void)checkSz;
  52058. (void)p;
  52059. #endif
  52060. #endif
  52061. (void)keyFormat;
  52062. (void)encInfo;
  52063. exit_onlycb:
  52064. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52065. if (key != NULL) {
  52066. wc_ecc_free(key);
  52067. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52068. }
  52069. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52070. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52071. #ifdef OPENSSL_EXTRA
  52072. if (check) {
  52073. FREE(check, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52074. }
  52075. #endif
  52076. #else
  52077. wc_ecc_free(key);
  52078. #ifdef OPENSSL_EXTRA
  52079. if (privKey)
  52080. EVP_PKEY_free(privKey);
  52081. if (pubKey)
  52082. EVP_PKEY_free(pubKey);
  52083. #endif
  52084. #endif
  52085. #endif /* HAVE_ECC */
  52086. return ret;
  52087. }
  52088. #endif
  52089. /* Example crypto dev callback function that calls software version */
  52090. static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
  52091. {
  52092. int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN); /* return this to bypass HW and
  52093. use SW */
  52094. myCryptoDevCtx* myCtx = (myCryptoDevCtx*)ctx;
  52095. if (info == NULL)
  52096. return BAD_FUNC_ARG;
  52097. #ifdef DEBUG_WOLFSSL
  52098. WOLFSSL_MSG_EX("CryptoDevCb: Algo Type %d\n", info->algo_type);
  52099. #endif
  52100. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  52101. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  52102. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  52103. /* if RNG only supports crypto callback, just use seed */
  52104. ret = wc_GenerateSeed(&info->rng.rng->seed,
  52105. info->rng.out, info->rng.sz);
  52106. #elif !defined(WC_NO_RNG)
  52107. /* set devId to invalid, so software is used */
  52108. info->rng.rng->devId = INVALID_DEVID;
  52109. ret = wc_RNG_GenerateBlock(info->rng.rng,
  52110. info->rng.out, info->rng.sz);
  52111. /* reset devId */
  52112. info->rng.rng->devId = devIdArg;
  52113. #endif
  52114. }
  52115. else if (info->algo_type == WC_ALGO_TYPE_SEED) {
  52116. #ifndef WC_NO_RNG
  52117. ALIGN32 static byte seed[sizeof(word32)] = { 0x00, 0x00, 0x00, 0x01 };
  52118. word32* seedWord32 = (word32*)seed;
  52119. word32 len;
  52120. /* wc_GenerateSeed is a local symbol so we need to fake the entropy. */
  52121. while (info->seed.sz > 0) {
  52122. len = (word32)sizeof(seed);
  52123. if (info->seed.sz < len)
  52124. len = info->seed.sz;
  52125. XMEMCPY(info->seed.seed, seed, sizeof(seed));
  52126. info->seed.seed += len;
  52127. info->seed.sz -= len;
  52128. (*seedWord32)++;
  52129. }
  52130. ret = 0;
  52131. #endif
  52132. }
  52133. else if (info->algo_type == WC_ALGO_TYPE_PK) {
  52134. #ifdef DEBUG_WOLFSSL
  52135. WOLFSSL_MSG_EX("CryptoDevCb: Pk Type %d\n", info->pk.type);
  52136. #endif
  52137. #ifndef NO_RSA
  52138. if (info->pk.type == WC_PK_TYPE_RSA) {
  52139. /* set devId to invalid, so software is used */
  52140. info->pk.rsa.key->devId = INVALID_DEVID;
  52141. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52142. #ifdef DEBUG_WOLFSSL
  52143. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52144. #endif
  52145. if (myCtx->exampleVar == 99) {
  52146. info->pk.rsa.key->devId = devIdArg;
  52147. return 0;
  52148. }
  52149. #endif
  52150. switch (info->pk.rsa.type) {
  52151. case RSA_PUBLIC_ENCRYPT:
  52152. case RSA_PUBLIC_DECRYPT:
  52153. /* perform software based RSA public op */
  52154. ret = wc_RsaFunction(
  52155. info->pk.rsa.in, info->pk.rsa.inLen,
  52156. info->pk.rsa.out, info->pk.rsa.outLen,
  52157. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52158. break;
  52159. case RSA_PRIVATE_ENCRYPT:
  52160. case RSA_PRIVATE_DECRYPT:
  52161. /* perform software based RSA private op */
  52162. ret = wc_RsaFunction(
  52163. info->pk.rsa.in, info->pk.rsa.inLen,
  52164. info->pk.rsa.out, info->pk.rsa.outLen,
  52165. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52166. break;
  52167. }
  52168. /* reset devId */
  52169. info->pk.rsa.key->devId = devIdArg;
  52170. }
  52171. #ifdef WOLFSSL_KEY_GEN
  52172. else if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN) {
  52173. info->pk.rsakg.key->devId = INVALID_DEVID;
  52174. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52175. #ifdef DEBUG_WOLFSSL
  52176. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52177. #endif
  52178. if (myCtx->exampleVar == 99) {
  52179. info->pk.rsakg.key->devId = devIdArg;
  52180. return 0;
  52181. }
  52182. #endif
  52183. #ifdef HAVE_FIPS
  52184. for (;;) {
  52185. #endif
  52186. ret = wc_MakeRsaKey(info->pk.rsakg.key, info->pk.rsakg.size,
  52187. info->pk.rsakg.e, info->pk.rsakg.rng);
  52188. #ifdef HAVE_FIPS
  52189. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  52190. continue;
  52191. break;
  52192. }
  52193. #endif
  52194. /* reset devId */
  52195. info->pk.rsakg.key->devId = devIdArg;
  52196. }
  52197. #endif
  52198. #endif /* !NO_RSA */
  52199. #ifdef HAVE_ECC
  52200. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  52201. /* set devId to invalid, so software is used */
  52202. info->pk.eckg.key->devId = INVALID_DEVID;
  52203. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52204. #ifdef DEBUG_WOLFSSL
  52205. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52206. #endif
  52207. if (myCtx->exampleVar == 99) {
  52208. info->pk.eckg.key->devId = devIdArg;
  52209. return 0;
  52210. }
  52211. #endif
  52212. ret = wc_ecc_make_key_ex(info->pk.eckg.rng, info->pk.eckg.size,
  52213. info->pk.eckg.key, info->pk.eckg.curveId);
  52214. /* reset devId */
  52215. info->pk.eckg.key->devId = devIdArg;
  52216. }
  52217. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  52218. /* set devId to invalid, so software is used */
  52219. info->pk.eccsign.key->devId = INVALID_DEVID;
  52220. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52221. #ifdef DEBUG_WOLFSSL
  52222. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52223. #endif
  52224. if (myCtx->exampleVar == 99) {
  52225. info->pk.eccsign.key->devId = devIdArg;
  52226. return 0;
  52227. }
  52228. #endif
  52229. ret = wc_ecc_sign_hash(
  52230. info->pk.eccsign.in, info->pk.eccsign.inlen,
  52231. info->pk.eccsign.out, info->pk.eccsign.outlen,
  52232. info->pk.eccsign.rng, info->pk.eccsign.key);
  52233. /* reset devId */
  52234. info->pk.eccsign.key->devId = devIdArg;
  52235. }
  52236. else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
  52237. /* set devId to invalid, so software is used */
  52238. info->pk.eccverify.key->devId = INVALID_DEVID;
  52239. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52240. #ifdef DEBUG_WOLFSSL
  52241. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52242. #endif
  52243. if (myCtx->exampleVar == 99) {
  52244. info->pk.eccverify.key->devId = devIdArg;
  52245. return 0;
  52246. }
  52247. #endif
  52248. ret = wc_ecc_verify_hash(
  52249. info->pk.eccverify.sig, info->pk.eccverify.siglen,
  52250. info->pk.eccverify.hash, info->pk.eccverify.hashlen,
  52251. info->pk.eccverify.res, info->pk.eccverify.key);
  52252. /* reset devId */
  52253. info->pk.eccverify.key->devId = devIdArg;
  52254. }
  52255. else if (info->pk.type == WC_PK_TYPE_ECDH) {
  52256. /* set devId to invalid, so software is used */
  52257. info->pk.ecdh.private_key->devId = INVALID_DEVID;
  52258. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52259. #ifdef DEBUG_WOLFSSL
  52260. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52261. #endif
  52262. if (myCtx->exampleVar == 99) {
  52263. info->pk.ecdh.private_key->devId = devIdArg;
  52264. return 0;
  52265. }
  52266. #endif
  52267. ret = wc_ecc_shared_secret(
  52268. info->pk.ecdh.private_key, info->pk.ecdh.public_key,
  52269. info->pk.ecdh.out, info->pk.ecdh.outlen);
  52270. /* reset devId */
  52271. info->pk.ecdh.private_key->devId = devIdArg;
  52272. }
  52273. #endif /* HAVE_ECC */
  52274. #ifdef HAVE_CURVE25519
  52275. if (info->pk.type == WC_PK_TYPE_CURVE25519_KEYGEN) {
  52276. /* set devId to invalid, so software is used */
  52277. info->pk.curve25519kg.key->devId = INVALID_DEVID;
  52278. ret = wc_curve25519_make_key(info->pk.curve25519kg.rng,
  52279. info->pk.curve25519kg.size, info->pk.curve25519kg.key);
  52280. /* reset devId */
  52281. info->pk.curve25519kg.key->devId = devIdArg;
  52282. }
  52283. else if (info->pk.type == WC_PK_TYPE_CURVE25519) {
  52284. /* set devId to invalid, so software is used */
  52285. info->pk.curve25519.private_key->devId = INVALID_DEVID;
  52286. ret = wc_curve25519_shared_secret_ex(
  52287. info->pk.curve25519.private_key, info->pk.curve25519.public_key,
  52288. info->pk.curve25519.out, info->pk.curve25519.outlen,
  52289. info->pk.curve25519.endian);
  52290. /* reset devId */
  52291. info->pk.curve25519.private_key->devId = devIdArg;
  52292. }
  52293. #endif /* HAVE_CURVE25519 */
  52294. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  52295. if (info->pk.type == WC_PK_TYPE_ED25519_KEYGEN) {
  52296. /* set devId to invalid, so software is used */
  52297. info->pk.ed25519kg.key->devId = INVALID_DEVID;
  52298. ret = wc_ed25519_make_key(info->pk.ed25519kg.rng,
  52299. info->pk.ed25519kg.size, info->pk.ed25519kg.key);
  52300. /* reset devId */
  52301. info->pk.ed25519kg.key->devId = devIdArg;
  52302. }
  52303. #ifdef HAVE_ED25519_SIGN
  52304. else if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  52305. /* set devId to invalid, so software is used */
  52306. info->pk.ed25519sign.key->devId = INVALID_DEVID;
  52307. ret = wc_ed25519_sign_msg_ex(
  52308. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  52309. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  52310. info->pk.ed25519sign.key, info->pk.ed25519sign.type,
  52311. info->pk.ed25519sign.context, info->pk.ed25519sign.contextLen);
  52312. /* reset devId */
  52313. info->pk.ed25519sign.key->devId = devIdArg;
  52314. }
  52315. #endif
  52316. #ifdef HAVE_ED25519_VERIFY
  52317. else if (info->pk.type == WC_PK_TYPE_ED25519_VERIFY) {
  52318. /* set devId to invalid, so software is used */
  52319. info->pk.ed25519verify.key->devId = INVALID_DEVID;
  52320. ret = wc_ed25519_verify_msg_ex(
  52321. info->pk.ed25519verify.sig, info->pk.ed25519verify.sigLen,
  52322. info->pk.ed25519verify.msg, info->pk.ed25519verify.msgLen,
  52323. info->pk.ed25519verify.res, info->pk.ed25519verify.key,
  52324. info->pk.ed25519verify.type, info->pk.ed25519verify.context,
  52325. info->pk.ed25519verify.contextLen);
  52326. /* reset devId */
  52327. info->pk.ed25519verify.key->devId = devIdArg;
  52328. }
  52329. #endif
  52330. #endif /* HAVE_ED25519 */
  52331. }
  52332. else if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
  52333. #if !defined(NO_AES) || !defined(NO_DES3)
  52334. #ifdef HAVE_AESGCM
  52335. if (info->cipher.type == WC_CIPHER_AES_GCM) {
  52336. if (info->cipher.enc) {
  52337. /* set devId to invalid, so software is used */
  52338. info->cipher.aesgcm_enc.aes->devId = INVALID_DEVID;
  52339. ret = wc_AesGcmEncrypt(
  52340. info->cipher.aesgcm_enc.aes,
  52341. info->cipher.aesgcm_enc.out,
  52342. info->cipher.aesgcm_enc.in,
  52343. info->cipher.aesgcm_enc.sz,
  52344. info->cipher.aesgcm_enc.iv,
  52345. info->cipher.aesgcm_enc.ivSz,
  52346. info->cipher.aesgcm_enc.authTag,
  52347. info->cipher.aesgcm_enc.authTagSz,
  52348. info->cipher.aesgcm_enc.authIn,
  52349. info->cipher.aesgcm_enc.authInSz);
  52350. /* reset devId */
  52351. info->cipher.aesgcm_enc.aes->devId = devIdArg;
  52352. }
  52353. else {
  52354. /* set devId to invalid, so software is used */
  52355. info->cipher.aesgcm_dec.aes->devId = INVALID_DEVID;
  52356. ret = wc_AesGcmDecrypt(
  52357. info->cipher.aesgcm_dec.aes,
  52358. info->cipher.aesgcm_dec.out,
  52359. info->cipher.aesgcm_dec.in,
  52360. info->cipher.aesgcm_dec.sz,
  52361. info->cipher.aesgcm_dec.iv,
  52362. info->cipher.aesgcm_dec.ivSz,
  52363. info->cipher.aesgcm_dec.authTag,
  52364. info->cipher.aesgcm_dec.authTagSz,
  52365. info->cipher.aesgcm_dec.authIn,
  52366. info->cipher.aesgcm_dec.authInSz);
  52367. /* reset devId */
  52368. info->cipher.aesgcm_dec.aes->devId = devIdArg;
  52369. }
  52370. }
  52371. #endif /* HAVE_AESGCM */
  52372. #ifdef HAVE_AES_CBC
  52373. if (info->cipher.type == WC_CIPHER_AES_CBC) {
  52374. if (info->cipher.enc) {
  52375. /* set devId to invalid, so software is used */
  52376. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  52377. ret = wc_AesCbcEncrypt(
  52378. info->cipher.aescbc.aes,
  52379. info->cipher.aescbc.out,
  52380. info->cipher.aescbc.in,
  52381. info->cipher.aescbc.sz);
  52382. /* reset devId */
  52383. info->cipher.aescbc.aes->devId = devIdArg;
  52384. }
  52385. else {
  52386. /* set devId to invalid, so software is used */
  52387. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  52388. ret = wc_AesCbcDecrypt(
  52389. info->cipher.aescbc.aes,
  52390. info->cipher.aescbc.out,
  52391. info->cipher.aescbc.in,
  52392. info->cipher.aescbc.sz);
  52393. /* reset devId */
  52394. info->cipher.aescbc.aes->devId = devIdArg;
  52395. }
  52396. }
  52397. #endif /* HAVE_AES_CBC */
  52398. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  52399. if (info->cipher.type == WC_CIPHER_AES_ECB) {
  52400. if (info->cipher.enc) {
  52401. /* set devId to invalid, so software is used */
  52402. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  52403. ret = wc_AesEcbEncrypt(
  52404. info->cipher.aesecb.aes,
  52405. info->cipher.aesecb.out,
  52406. info->cipher.aesecb.in,
  52407. info->cipher.aesecb.sz);
  52408. /* reset devId */
  52409. info->cipher.aesecb.aes->devId = devIdArg;
  52410. }
  52411. else {
  52412. /* set devId to invalid, so software is used */
  52413. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  52414. ret = wc_AesEcbDecrypt(
  52415. info->cipher.aesecb.aes,
  52416. info->cipher.aesecb.out,
  52417. info->cipher.aesecb.in,
  52418. info->cipher.aesecb.sz);
  52419. /* reset devId */
  52420. info->cipher.aesecb.aes->devId = devIdArg;
  52421. }
  52422. }
  52423. #endif /* HAVE_AES_ECB */
  52424. #if defined(WOLFSSL_AES_COUNTER) && !defined(HAVE_FIPS) && \
  52425. !defined(HAVE_SELFTEST)
  52426. if (info->cipher.type == WC_CIPHER_AES_CTR) {
  52427. /* set devId to invalid, so software is used */
  52428. info->cipher.aesctr.aes->devId = INVALID_DEVID;
  52429. ret = wc_AesCtrEncrypt(
  52430. info->cipher.aesctr.aes,
  52431. info->cipher.aesctr.out,
  52432. info->cipher.aesctr.in,
  52433. info->cipher.aesctr.sz);
  52434. /* reset devId */
  52435. info->cipher.aesctr.aes->devId = devIdArg;
  52436. }
  52437. #endif /* WOLFSSL_AES_COUNTER */
  52438. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  52439. if (info->cipher.type == WC_CIPHER_AES_CCM) {
  52440. if (info->cipher.enc) {
  52441. /* set devId to invalid, so software is used */
  52442. info->cipher.aesccm_enc.aes->devId = INVALID_DEVID;
  52443. ret = wc_AesCcmEncrypt(
  52444. info->cipher.aesccm_enc.aes,
  52445. info->cipher.aesccm_enc.out,
  52446. info->cipher.aesccm_enc.in,
  52447. info->cipher.aesccm_enc.sz,
  52448. info->cipher.aesccm_enc.nonce,
  52449. info->cipher.aesccm_enc.nonceSz,
  52450. info->cipher.aesccm_enc.authTag,
  52451. info->cipher.aesccm_enc.authTagSz,
  52452. info->cipher.aesccm_enc.authIn,
  52453. info->cipher.aesccm_enc.authInSz);
  52454. /* reset devId */
  52455. info->cipher.aesccm_enc.aes->devId = devIdArg;
  52456. }
  52457. else {
  52458. /* set devId to invalid, so software is used */
  52459. info->cipher.aesccm_dec.aes->devId = INVALID_DEVID;
  52460. ret = wc_AesCcmDecrypt(
  52461. info->cipher.aesccm_dec.aes,
  52462. info->cipher.aesccm_dec.out,
  52463. info->cipher.aesccm_dec.in,
  52464. info->cipher.aesccm_dec.sz,
  52465. info->cipher.aesccm_dec.nonce,
  52466. info->cipher.aesccm_dec.nonceSz,
  52467. info->cipher.aesccm_dec.authTag,
  52468. info->cipher.aesccm_dec.authTagSz,
  52469. info->cipher.aesccm_dec.authIn,
  52470. info->cipher.aesccm_dec.authInSz);
  52471. /* reset devId */
  52472. info->cipher.aesccm_dec.aes->devId = devIdArg;
  52473. }
  52474. }
  52475. #endif
  52476. #ifndef NO_DES3
  52477. if (info->cipher.type == WC_CIPHER_DES3) {
  52478. if (info->cipher.enc) {
  52479. /* set devId to invalid, so software is used */
  52480. info->cipher.des3.des->devId = INVALID_DEVID;
  52481. ret = wc_Des3_CbcEncrypt(
  52482. info->cipher.des3.des,
  52483. info->cipher.des3.out,
  52484. info->cipher.des3.in,
  52485. info->cipher.des3.sz);
  52486. /* reset devId */
  52487. info->cipher.des3.des->devId = devIdArg;
  52488. }
  52489. else {
  52490. /* set devId to invalid, so software is used */
  52491. info->cipher.des3.des->devId = INVALID_DEVID;
  52492. ret = wc_Des3_CbcDecrypt(
  52493. info->cipher.des3.des,
  52494. info->cipher.des3.out,
  52495. info->cipher.des3.in,
  52496. info->cipher.des3.sz);
  52497. /* reset devId */
  52498. info->cipher.des3.des->devId = devIdArg;
  52499. }
  52500. }
  52501. #endif /* !NO_DES3 */
  52502. #endif /* !NO_AES || !NO_DES3 */
  52503. }
  52504. #if !defined(NO_SHA) || !defined(NO_SHA256) || \
  52505. defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
  52506. else if (info->algo_type == WC_ALGO_TYPE_HASH) {
  52507. #if !defined(NO_SHA)
  52508. if (info->hash.type == WC_HASH_TYPE_SHA) {
  52509. if (info->hash.sha1 == NULL)
  52510. return NOT_COMPILED_IN;
  52511. /* set devId to invalid, so software is used */
  52512. info->hash.sha1->devId = INVALID_DEVID;
  52513. if (info->hash.in != NULL) {
  52514. ret = wc_ShaUpdate(
  52515. info->hash.sha1,
  52516. info->hash.in,
  52517. info->hash.inSz);
  52518. }
  52519. if (info->hash.digest != NULL) {
  52520. ret = wc_ShaFinal(
  52521. info->hash.sha1,
  52522. info->hash.digest);
  52523. }
  52524. /* reset devId */
  52525. info->hash.sha1->devId = devIdArg;
  52526. }
  52527. else
  52528. #endif
  52529. #if !defined(NO_SHA256)
  52530. if (info->hash.type == WC_HASH_TYPE_SHA256) {
  52531. if (info->hash.sha256 == NULL)
  52532. return NOT_COMPILED_IN;
  52533. /* set devId to invalid, so software is used */
  52534. info->hash.sha256->devId = INVALID_DEVID;
  52535. if (info->hash.in != NULL) {
  52536. ret = wc_Sha256Update(
  52537. info->hash.sha256,
  52538. info->hash.in,
  52539. info->hash.inSz);
  52540. }
  52541. if (info->hash.digest != NULL) {
  52542. ret = wc_Sha256Final(
  52543. info->hash.sha256,
  52544. info->hash.digest);
  52545. }
  52546. /* reset devId */
  52547. info->hash.sha256->devId = devIdArg;
  52548. }
  52549. else
  52550. #endif
  52551. #ifdef WOLFSSL_SHA384
  52552. if (info->hash.type == WC_HASH_TYPE_SHA384) {
  52553. if (info->hash.sha384 == NULL)
  52554. return NOT_COMPILED_IN;
  52555. #ifndef NO_SHA2_CRYPTO_CB
  52556. /* set devId to invalid, so software is used */
  52557. info->hash.sha384->devId = INVALID_DEVID;
  52558. #endif
  52559. if (info->hash.in != NULL) {
  52560. ret = wc_Sha384Update(
  52561. info->hash.sha384,
  52562. info->hash.in,
  52563. info->hash.inSz);
  52564. }
  52565. if (info->hash.digest != NULL) {
  52566. ret = wc_Sha384Final(
  52567. info->hash.sha384,
  52568. info->hash.digest);
  52569. }
  52570. #ifndef NO_SHA2_CRYPTO_CB
  52571. /* reset devId */
  52572. info->hash.sha384->devId = devIdArg;
  52573. #endif
  52574. }
  52575. else
  52576. #endif
  52577. #ifdef WOLFSSL_SHA512
  52578. if (info->hash.type == WC_HASH_TYPE_SHA512) {
  52579. if (info->hash.sha512 == NULL)
  52580. return NOT_COMPILED_IN;
  52581. #ifndef NO_SHA2_CRYPTO_CB
  52582. /* set devId to invalid, so software is used */
  52583. info->hash.sha512->devId = INVALID_DEVID;
  52584. #endif
  52585. if (info->hash.in != NULL) {
  52586. ret = wc_Sha512Update(
  52587. info->hash.sha512,
  52588. info->hash.in,
  52589. info->hash.inSz);
  52590. }
  52591. if (info->hash.digest != NULL) {
  52592. ret = wc_Sha512Final(
  52593. info->hash.sha512,
  52594. info->hash.digest);
  52595. }
  52596. #ifndef NO_SHA2_CRYPTO_CB
  52597. /* reset devId */
  52598. info->hash.sha512->devId = devIdArg;
  52599. #endif
  52600. }
  52601. else
  52602. #endif
  52603. #if defined(WOLFSSL_SHA3) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0))
  52604. if (info->hash.type == WC_HASH_TYPE_SHA3_224) {
  52605. if (info->hash.sha3 == NULL)
  52606. return NOT_COMPILED_IN;
  52607. /* set devId to invalid, so software is used */
  52608. info->hash.sha3->devId = INVALID_DEVID;
  52609. if (info->hash.in != NULL) {
  52610. ret = wc_Sha3_224_Update(
  52611. info->hash.sha3,
  52612. info->hash.in,
  52613. info->hash.inSz);
  52614. }
  52615. if (info->hash.digest != NULL) {
  52616. ret = wc_Sha3_224_Final(
  52617. info->hash.sha3,
  52618. info->hash.digest);
  52619. }
  52620. /* reset devId */
  52621. info->hash.sha3->devId = devIdArg;
  52622. }
  52623. else if (info->hash.type == WC_HASH_TYPE_SHA3_256) {
  52624. if (info->hash.sha3 == NULL)
  52625. return NOT_COMPILED_IN;
  52626. /* set devId to invalid, so software is used */
  52627. info->hash.sha3->devId = INVALID_DEVID;
  52628. if (info->hash.in != NULL) {
  52629. ret = wc_Sha3_256_Update(
  52630. info->hash.sha3,
  52631. info->hash.in,
  52632. info->hash.inSz);
  52633. }
  52634. if (info->hash.digest != NULL) {
  52635. ret = wc_Sha3_256_Final(
  52636. info->hash.sha3,
  52637. info->hash.digest);
  52638. }
  52639. /* reset devId */
  52640. info->hash.sha3->devId = devIdArg;
  52641. }
  52642. else if (info->hash.type == WC_HASH_TYPE_SHA3_384) {
  52643. if (info->hash.sha3 == NULL)
  52644. return NOT_COMPILED_IN;
  52645. /* set devId to invalid, so software is used */
  52646. info->hash.sha3->devId = INVALID_DEVID;
  52647. if (info->hash.in != NULL) {
  52648. ret = wc_Sha3_384_Update(
  52649. info->hash.sha3,
  52650. info->hash.in,
  52651. info->hash.inSz);
  52652. }
  52653. if (info->hash.digest != NULL) {
  52654. ret = wc_Sha3_384_Final(
  52655. info->hash.sha3,
  52656. info->hash.digest);
  52657. }
  52658. /* reset devId */
  52659. info->hash.sha3->devId = devIdArg;
  52660. }
  52661. else if (info->hash.type == WC_HASH_TYPE_SHA3_512) {
  52662. if (info->hash.sha3 == NULL)
  52663. return NOT_COMPILED_IN;
  52664. /* set devId to invalid, so software is used */
  52665. info->hash.sha3->devId = INVALID_DEVID;
  52666. if (info->hash.in != NULL) {
  52667. ret = wc_Sha3_512_Update(
  52668. info->hash.sha3,
  52669. info->hash.in,
  52670. info->hash.inSz);
  52671. }
  52672. if (info->hash.digest != NULL) {
  52673. ret = wc_Sha3_512_Final(
  52674. info->hash.sha3,
  52675. info->hash.digest);
  52676. }
  52677. /* reset devId */
  52678. info->hash.sha3->devId = devIdArg;
  52679. }
  52680. else
  52681. #endif
  52682. {
  52683. }
  52684. }
  52685. #endif /* !NO_SHA || !NO_SHA256 */
  52686. #ifndef NO_HMAC
  52687. else if (info->algo_type == WC_ALGO_TYPE_HMAC) {
  52688. if (info->hmac.hmac == NULL)
  52689. return NOT_COMPILED_IN;
  52690. /* set devId to invalid, so software is used */
  52691. info->hmac.hmac->devId = INVALID_DEVID;
  52692. if (info->hmac.in != NULL) {
  52693. ret = wc_HmacUpdate(
  52694. info->hmac.hmac,
  52695. info->hmac.in,
  52696. info->hmac.inSz);
  52697. }
  52698. else if (info->hmac.digest != NULL) {
  52699. ret = wc_HmacFinal(
  52700. info->hmac.hmac,
  52701. info->hmac.digest);
  52702. }
  52703. /* reset devId */
  52704. info->hmac.hmac->devId = devIdArg;
  52705. }
  52706. #endif
  52707. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  52708. else if (info->algo_type == WC_ALGO_TYPE_CMAC) {
  52709. if (info->cmac.cmac == NULL) {
  52710. return NOT_COMPILED_IN;
  52711. }
  52712. /* set devId to invalid so software is used */
  52713. info->cmac.cmac->devId = INVALID_DEVID;
  52714. /* Handle one-shot cases */
  52715. if (info->cmac.key != NULL && info->cmac.in != NULL
  52716. && info->cmac.out != NULL) {
  52717. ret = wc_AesCmacGenerate(info->cmac.out,
  52718. info->cmac.outSz,
  52719. info->cmac.in,
  52720. info->cmac.inSz,
  52721. info->cmac.key,
  52722. info->cmac.keySz);
  52723. /* Sequentially handle incremental cases */
  52724. } else {
  52725. if (info->cmac.key != NULL) {
  52726. ret = wc_InitCmac(info->cmac.cmac,
  52727. info->cmac.key,
  52728. info->cmac.keySz,
  52729. info->cmac.type,
  52730. NULL);
  52731. }
  52732. if ((ret == 0) && (info->cmac.in != NULL)) {
  52733. ret = wc_CmacUpdate(info->cmac.cmac,
  52734. info->cmac.in,
  52735. info->cmac.inSz);
  52736. }
  52737. if ((ret ==0) && (info->cmac.out != NULL)) {
  52738. ret = wc_CmacFinal(info->cmac.cmac,
  52739. info->cmac.out,
  52740. info->cmac.outSz);
  52741. }
  52742. }
  52743. /* reset devId */
  52744. info->cmac.cmac->devId = devIdArg;
  52745. }
  52746. #endif /* WOLFSSL_CMAC && !(NO_AES) && WOLFSSL_AES_DIRECT */
  52747. (void)devIdArg;
  52748. (void)myCtx;
  52749. return ret;
  52750. }
  52751. #ifdef WOLF_CRYPTO_CB_FIND
  52752. static int myCryptoCbFind(int currentId, int algoType)
  52753. {
  52754. /* can have algo specific overrides here
  52755. switch (algoType) {
  52756. i.e.
  52757. WC_ALGO_TYPE_CMAC
  52758. WC_ALGO_TYPE_SEED
  52759. WC_ALGO_TYPE_HMAC
  52760. WC_ALGO_TYPE_HASH
  52761. WC_ALGO_TYPE_CIPHER
  52762. WC_ALGO_TYPE_PK
  52763. }
  52764. */
  52765. (void)algoType;
  52766. if (currentId == INVALID_DEVID) {
  52767. /* can override invalid devid found with 1 */
  52768. }
  52769. return currentId;
  52770. }
  52771. #endif /* WOLF_CRYPTO_CB_FIND */
  52772. #if !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  52773. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void)
  52774. {
  52775. wc_test_ret_t ret = 0;
  52776. int origDevId = devId;
  52777. myCryptoDevCtx myCtx;
  52778. WOLFSSL_ENTER("cryptocb_test");
  52779. /* example data for callback */
  52780. myCtx.exampleVar = 1;
  52781. /* set devId to something other than INVALID_DEVID */
  52782. devId = 1;
  52783. ret = wc_CryptoCb_RegisterDevice(devId, myCryptoDevCb, &myCtx);
  52784. #ifdef WOLF_CRYPTO_CB_FIND
  52785. wc_CryptoCb_SetDeviceFindCb(myCryptoCbFind);
  52786. #endif /* WOLF_CRYPTO_CB_FIND */
  52787. #ifndef WC_NO_RNG
  52788. if (ret == 0)
  52789. ret = random_test();
  52790. #endif /* WC_NO_RNG */
  52791. #if !defined(NO_RSA)
  52792. PRIVATE_KEY_UNLOCK();
  52793. if (ret == 0)
  52794. ret = rsa_test();
  52795. PRIVATE_KEY_LOCK();
  52796. #endif
  52797. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52798. PRIVATE_KEY_UNLOCK();
  52799. if (ret == 0)
  52800. ret = rsa_onlycb_test(&myCtx);
  52801. PRIVATE_KEY_LOCK();
  52802. #endif
  52803. #if defined(HAVE_ECC)
  52804. PRIVATE_KEY_UNLOCK();
  52805. if (ret == 0)
  52806. ret = ecc_test();
  52807. PRIVATE_KEY_LOCK();
  52808. #endif
  52809. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52810. PRIVATE_KEY_UNLOCK();
  52811. if (ret == 0)
  52812. ret = ecc_onlycb_test(&myCtx);
  52813. PRIVATE_KEY_LOCK();
  52814. #endif
  52815. #ifdef HAVE_ED25519
  52816. PRIVATE_KEY_UNLOCK();
  52817. if (ret == 0)
  52818. ret = ed25519_test();
  52819. PRIVATE_KEY_LOCK();
  52820. #endif
  52821. #ifdef HAVE_CURVE25519
  52822. if (ret == 0)
  52823. ret = curve25519_test();
  52824. #endif
  52825. #ifndef NO_AES
  52826. #ifdef HAVE_AESGCM
  52827. if (ret == 0)
  52828. ret = aesgcm_test();
  52829. #endif
  52830. #ifdef HAVE_AES_CBC
  52831. if (ret == 0)
  52832. ret = aes_test();
  52833. #endif
  52834. #ifdef WOLFSSL_AES_XTS
  52835. if (ret == 0)
  52836. ret = aes_xts_test();
  52837. #endif
  52838. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  52839. if (ret == 0)
  52840. ret = aesccm_test();
  52841. #endif
  52842. #endif /* !NO_AES */
  52843. #ifndef NO_DES3
  52844. if (ret == 0)
  52845. ret = des3_test();
  52846. #endif /* !NO_DES3 */
  52847. #ifndef NO_SHA
  52848. if (ret == 0)
  52849. ret = sha_test();
  52850. #endif
  52851. #ifndef NO_SHA256
  52852. if (ret == 0)
  52853. ret = sha256_test();
  52854. #endif
  52855. #ifdef WOLFSSL_SHA384
  52856. if (ret == 0)
  52857. ret = sha384_test();
  52858. #endif
  52859. #ifdef WOLFSSL_SHA512
  52860. if (ret == 0)
  52861. ret = sha512_test();
  52862. #ifdef WOLFSSL_SHA3
  52863. if (ret == 0)
  52864. ret = sha3_test();
  52865. #endif
  52866. #endif
  52867. #ifndef NO_HMAC
  52868. #ifndef NO_SHA
  52869. if (ret == 0)
  52870. ret = hmac_sha_test();
  52871. #endif
  52872. #ifndef NO_SHA256
  52873. if (ret == 0)
  52874. ret = hmac_sha256_test();
  52875. #endif
  52876. #ifdef WOLFSSL_SHA3
  52877. if (ret == 0)
  52878. ret = hmac_sha3_test();
  52879. #endif
  52880. #endif
  52881. #ifndef NO_PWDBASED
  52882. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  52883. PRIVATE_KEY_UNLOCK();
  52884. if (ret == 0)
  52885. ret = pbkdf2_test();
  52886. PRIVATE_KEY_LOCK();
  52887. #endif
  52888. #endif
  52889. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  52890. if (ret == 0)
  52891. ret = cmac_test();
  52892. #endif
  52893. /* restore devId */
  52894. devId = origDevId;
  52895. return ret;
  52896. }
  52897. #endif /* ! WC_TEST_NO_CRYPTOCB_SW_TEST */
  52898. #endif /* WOLF_CRYPTO_CB */
  52899. #ifdef WOLFSSL_CERT_PIV
  52900. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void)
  52901. {
  52902. wc_test_ret_t ret;
  52903. wc_CertPIV piv;
  52904. /* Template for Identiv PIV cert, nonce and signature */
  52905. WOLFSSL_SMALL_STACK_STATIC const byte pivCertIdentiv[] = {
  52906. 0x0A, 0x0B,
  52907. 0x53, 0x09, /* NIST PIV Cert */
  52908. 0x70, 0x02, /* Certificate */
  52909. 0x30, 0x00,
  52910. 0x71, 0x01, 0x05, /* Cert Info */
  52911. 0xFE, 0x00, /* Error Detection */
  52912. 0x0B, 0x01, 0x00, /* Nonce */
  52913. 0x0C, 0x01, 0x00, /* Signed Nonce */
  52914. };
  52915. /* PIV certificate data including certificate, info and error detection. */
  52916. WOLFSSL_SMALL_STACK_STATIC const byte pivCert[] = {
  52917. 0x53, 0x09, /* NIST PIV Cert */
  52918. 0x70, 0x02, /* Certificate */
  52919. 0x30, 0x00,
  52920. 0x71, 0x01, 0x04, /* Cert Info */
  52921. 0xFE, 0x00, /* Error Detection */
  52922. };
  52923. WOLFSSL_ENTER("certpiv_test");
  52924. XMEMSET(&piv, 0, sizeof(piv));
  52925. /* Test with Identiv 0x0A, 0x0B and 0x0C markers */
  52926. ret = wc_ParseCertPIV(&piv, pivCertIdentiv, sizeof(pivCertIdentiv));
  52927. if (ret != 0) {
  52928. return WC_TEST_RET_ENC_EC(ret);
  52929. }
  52930. if (!piv.isIdentiv) {
  52931. return WC_TEST_RET_ENC_NC;
  52932. }
  52933. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  52934. return WC_TEST_RET_ENC_NC;
  52935. }
  52936. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  52937. return WC_TEST_RET_ENC_NC;
  52938. }
  52939. if ((piv.compression != ASN_PIV_CERT_INFO_GZIP)) {
  52940. return WC_TEST_RET_ENC_NC;
  52941. }
  52942. if (!piv.isX509) {
  52943. return WC_TEST_RET_ENC_NC;
  52944. }
  52945. if ((piv.nonce == NULL) || (piv.nonceSz != 1)) {
  52946. return WC_TEST_RET_ENC_NC;
  52947. }
  52948. if ((piv.signedNonce == NULL) || (piv.signedNonceSz != 1)) {
  52949. return WC_TEST_RET_ENC_NC;
  52950. }
  52951. XMEMSET(&piv, 0, sizeof(piv));
  52952. /* Test with NIST PIV format */
  52953. ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert));
  52954. if (ret != 0) {
  52955. return WC_TEST_RET_ENC_EC(ret);
  52956. }
  52957. if (piv.isIdentiv) {
  52958. return WC_TEST_RET_ENC_NC;
  52959. }
  52960. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  52961. return WC_TEST_RET_ENC_NC;
  52962. }
  52963. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  52964. return WC_TEST_RET_ENC_NC;
  52965. }
  52966. if ((piv.compression != 0)) {
  52967. return WC_TEST_RET_ENC_NC;
  52968. }
  52969. if (!piv.isX509) {
  52970. return WC_TEST_RET_ENC_NC;
  52971. }
  52972. return ret;
  52973. }
  52974. #endif /* WOLFSSL_CERT_PIV */
  52975. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  52976. static time_t time_cb(time_t* t)
  52977. {
  52978. if (t != NULL) {
  52979. *t = 99;
  52980. }
  52981. return 99;
  52982. }
  52983. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void)
  52984. {
  52985. time_t t;
  52986. wc_test_ret_t ret;
  52987. WOLFSSL_ENTER("time_test");
  52988. ret = wc_SetTimeCb(time_cb);
  52989. if (ret != 0)
  52990. return WC_TEST_RET_ENC_EC(ret);
  52991. t = wc_Time(NULL);
  52992. if (t != 99)
  52993. return WC_TEST_RET_ENC_NC;
  52994. ret = wc_GetTime(&t, sizeof(time_t));
  52995. if (ret != 0)
  52996. return WC_TEST_RET_ENC_EC(ret);
  52997. if (t != 99)
  52998. return WC_TEST_RET_ENC_NC;
  52999. ret = wc_SetTimeCb(NULL);
  53000. if (ret != 0)
  53001. return WC_TEST_RET_ENC_EC(ret);
  53002. return 0;
  53003. }
  53004. #endif
  53005. #ifdef WOLFSSL_AES_SIV
  53006. typedef struct {
  53007. const byte key[33];
  53008. word32 keySz;
  53009. const byte nonce[49];
  53010. word32 nonceSz;
  53011. byte numAssoc;
  53012. const byte assoc1[81];
  53013. word32 assoc1Sz;
  53014. const byte assoc2[11];
  53015. word32 assoc2Sz;
  53016. const byte plaintext[83];
  53017. word32 plaintextSz;
  53018. const byte siv[AES_BLOCK_SIZE+1];
  53019. const byte ciphertext[82];
  53020. word32 ciphertextSz;
  53021. } AesSivTestVector;
  53022. #define AES_SIV_TEST_VECTORS 9
  53023. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
  53024. {
  53025. WOLFSSL_SMALL_STACK_STATIC const AesSivTestVector testVectors[AES_SIV_TEST_VECTORS] = {
  53026. /* These test vectors come from chrony 4.1's SIV unit tests. */
  53027. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53028. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53029. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53030. 1,
  53031. "", 0,
  53032. "", 0,
  53033. "", 0,
  53034. "\x22\x3e\xb5\x94\xe0\xe0\x25\x4b\x00\x25\x8e\x21\x9a\x1c\xa4\x21",
  53035. "", 0
  53036. },
  53037. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53038. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53039. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53040. 1,
  53041. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53042. "", 0,
  53043. "", 0,
  53044. "\xd7\x20\x19\x89\xc6\xdb\xc6\xd6\x61\xfc\x62\xbc\x86\x5e\xee\xef",
  53045. "", 0
  53046. },
  53047. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53048. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53049. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53050. 1,
  53051. "", 0,
  53052. "", 0,
  53053. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53054. "\xb6\xc1\x60\xe9\xc2\xfd\x2a\xe8\xde\xc5\x36\x8b\x2a\x33\xed\xe1",
  53055. "\x14\xff\xb3\x97\x34\x5c\xcb\xe4\x4a\xa4\xde\xac\xd9\x36\x90\x46", 16
  53056. },
  53057. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53058. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53059. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e", 15,
  53060. 1,
  53061. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c", 15,
  53062. "", 0,
  53063. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4", 15,
  53064. "\x03\x8c\x41\x51\xba\x7a\x8f\x77\x6e\x56\x31\x99\x42\x0b\xc7\x03",
  53065. "\xe7\x6c\x67\xc9\xda\xb7\x0d\x5b\x44\x06\x26\x5a\xd0\xd2\x3b", 15
  53066. },
  53067. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53068. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53069. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53070. 1,
  53071. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53072. "", 0,
  53073. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7", 16,
  53074. "\x5c\x05\x23\x65\xf4\x57\x0a\xa0\xfb\x38\x3e\xce\x9b\x75\x85\xeb",
  53075. "\x68\x85\x19\x36\x0c\x7c\x48\x11\x40\xcb\x9b\x57\x9a\x0e\x65\x32", 16
  53076. },
  53077. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53078. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53079. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53080. "\xd5", 17,
  53081. 1,
  53082. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b"
  53083. "\xa0", 17,
  53084. "", 0,
  53085. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7"
  53086. "\x08", 17,
  53087. "\xaf\x58\x4b\xe7\x82\x1e\x96\x19\x29\x91\x25\xe0\xdd\x80\x3b\x49",
  53088. "\xa5\x11\xcd\xb6\x08\xf3\x76\xa0\xb6\xfa\x15\x82\xf3\x95\xe1\xeb"
  53089. "\xbd", 17
  53090. },
  53091. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53092. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53093. "\xb0\x5a\x1b\xc7\x56\xe7\xb6\x2c\xb4\x85\xe5\x56\xa5\x28\xc0\x6c"
  53094. "\x2f\x3b\x0b\x9d\x1a\x0c\xdf\x69\x47\xe0\xcc\xc0\x87\xaa\x5c\x09"
  53095. "\x98\x48\x8d\x6a\x8e\x1e\x05\xd7\x8b\x68\x74\x83\xb5\x1d\xf1\x2c", 48,
  53096. 1,
  53097. "\xe5\x8b\xd2\x6a\x30\xc5\xc5\x61\xcc\xbd\x7c\x27\xbf\xfe\xf9\x06"
  53098. "\x00\x5b\xd7\xfc\x11\x0b\xcf\x16\x61\xef\xac\x05\xa7\xaf\xec\x27"
  53099. "\x41\xc8\x5e\x9e\x0d\xf9\x2f\xaf\x20\x79\x17\xe5\x17\x91\x2a\x27"
  53100. "\x34\x1c\xbc\xaf\xeb\xef\x7f\x52\xe7\x1e\x4c\x2a\xca\xbd\x2b\xbe"
  53101. "\x34\xd6\xfb\x69\xd3\x3e\x49\x59\x60\xb4\x26\xc9\xb8\xce\xba", 79,
  53102. "", 0,
  53103. "\x6c\xe7\xcf\x7e\xab\x7b\xa0\xe1\xa7\x22\xcb\x88\xde\x5e\x42\xd2"
  53104. "\xec\x79\xe0\xa2\xcf\x5f\x0f\x6f\x6b\x89\x57\xcd\xae\x17\xd4\xc2"
  53105. "\xf3\x1b\xa2\xa8\x13\x78\x23\x2f\x83\xa8\xd4\x0c\xc0\xd2\xf3\x99"
  53106. "\xae\x81\xa1\xca\x5b\x5f\x45\xa6\x6f\x0c\x8a\xf3\xd4\x67\x40\x81"
  53107. "\x26\xe2\x01\x86\xe8\x5a\xd5\xf8\x58\x80\x9f\x56\xaa\x76\x96\xbf"
  53108. "\x31", 81,
  53109. "\x9a\x06\x33\xe0\xee\x00\x6a\x9b\xc8\x20\xd5\xe2\xc2\xed\xb5\x75",
  53110. "\xfa\x9e\x42\x2a\x31\x6b\xda\xca\xaa\x7d\x31\x8b\x84\x7a\xb8\xd7"
  53111. "\x8a\x81\x25\x64\xed\x41\x9b\xa9\x77\x10\xbd\x05\x0c\x4e\xc5\x31"
  53112. "\x0c\xa2\x86\xec\x8a\x94\xc8\x24\x23\x3c\x13\xee\xa5\x51\xc9\xdf"
  53113. "\x48\xc9\x55\xc5\x2f\x40\x73\x3f\x98\xbb\x8d\x69\x78\x46\x64\x17"
  53114. "\x8d\x49\x2f\x14\x62\xa4\x7c\x2a\x57\x38\x87\xce\xc6\x72\xd3\x5c"
  53115. "\xa1", 81
  53116. },
  53117. /* Example A.1 from RFC5297 */
  53118. {
  53119. "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0"
  53120. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 32,
  53121. "", 0,
  53122. 1,
  53123. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53124. "\x20\x21\x22\x23\x24\x25\x26\x27", 24,
  53125. "", 0,
  53126. "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee", 14,
  53127. "\x85\x63\x2d\x07\xc6\xe8\xf3\x7f\x95\x0a\xcd\x32\x0a\x2e\xcc\x93",
  53128. "\x40\xc0\x2b\x96\x90\xc4\xdc\x04\xda\xef\x7f\x6a\xfe\x5c", 14
  53129. },
  53130. /* Example A.2 from RFC5297 */
  53131. {
  53132. "\x7f\x7e\x7d\x7c\x7b\x7a\x79\x78\x77\x76\x75\x74\x73\x72\x71\x70"
  53133. "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", 32,
  53134. "\x09\xf9\x11\x02\x9d\x74\xe3\x5b\xd8\x41\x56\xc5\x63\x56\x88\xc0", 16,
  53135. 2,
  53136. "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
  53137. "\xde\xad\xda\xda\xde\xad\xda\xda\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
  53138. "\x77\x66\x55\x44\x33\x22\x11\x00", 40,
  53139. "\x10\x20\x30\x40\x50\x60\x70\x80\x90\xa0", 10,
  53140. "\x74\x68\x69\x73\x20\x69\x73\x20\x73\x6f\x6d\x65\x20\x70\x6c\x61"
  53141. "\x69\x6e\x74\x65\x78\x74\x20\x74\x6f\x20\x65\x6e\x63\x72\x79\x70"
  53142. "\x74\x20\x75\x73\x69\x6e\x67\x20\x53\x49\x56\x2d\x41\x45\x53", 47,
  53143. "\x7b\xdb\x6e\x3b\x43\x26\x67\xeb\x06\xf4\xd1\x4b\xff\x2f\xbd\x0f",
  53144. "\xcb\x90\x0f\x2f\xdd\xbe\x40\x43\x26\x60\x19\x65\xc8\x89\xbf\x17"
  53145. "\xdb\xa7\x7c\xeb\x09\x4f\xa6\x63\xb7\xa3\xf7\x48\xba\x8a\xf8\x29"
  53146. "\xea\x64\xad\x54\x4a\x27\x2e\x9c\x48\x5b\x62\xa3\xfd\x5c\x0d", 47
  53147. }
  53148. };
  53149. int i;
  53150. byte computedCiphertext[82];
  53151. byte computedPlaintext[82];
  53152. byte siv[AES_BLOCK_SIZE];
  53153. wc_test_ret_t ret = 0;
  53154. WOLFSSL_ENTER("aes_siv_test");
  53155. /* First test legacy "exactly one Assoc" interface. */
  53156. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53157. if (testVectors[i].numAssoc != 1)
  53158. continue;
  53159. ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz,
  53160. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53161. testVectors[i].nonce, testVectors[i].nonceSz,
  53162. testVectors[i].plaintext,
  53163. testVectors[i].plaintextSz, siv,
  53164. computedCiphertext);
  53165. if (ret != 0) {
  53166. return WC_TEST_RET_ENC_EC(ret);
  53167. }
  53168. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53169. if (ret != 0) {
  53170. return WC_TEST_RET_ENC_NC;
  53171. }
  53172. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53173. testVectors[i].ciphertextSz);
  53174. if (ret != 0) {
  53175. return WC_TEST_RET_ENC_NC;
  53176. }
  53177. ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz,
  53178. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53179. testVectors[i].nonce, testVectors[i].nonceSz,
  53180. computedCiphertext, testVectors[i].plaintextSz,
  53181. siv, computedPlaintext);
  53182. if (ret != 0) {
  53183. return WC_TEST_RET_ENC_EC(ret);
  53184. }
  53185. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53186. testVectors[i].plaintextSz);
  53187. if (ret != 0) {
  53188. return WC_TEST_RET_ENC_NC;
  53189. }
  53190. }
  53191. /* Then test "multiple Assoc" interface. */
  53192. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53193. const struct AesSivAssoc assoc[2] = {
  53194. { testVectors[i].assoc1, testVectors[i].assoc1Sz },
  53195. { testVectors[i].assoc2, testVectors[i].assoc2Sz }
  53196. };
  53197. ret = wc_AesSivEncrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53198. assoc, testVectors[i].numAssoc,
  53199. testVectors[i].nonce, testVectors[i].nonceSz,
  53200. testVectors[i].plaintext,
  53201. testVectors[i].plaintextSz, siv,
  53202. computedCiphertext);
  53203. if (ret != 0) {
  53204. return WC_TEST_RET_ENC_EC(ret);
  53205. }
  53206. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53207. if (ret != 0) {
  53208. return WC_TEST_RET_ENC_NC;
  53209. }
  53210. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53211. testVectors[i].ciphertextSz);
  53212. if (ret != 0) {
  53213. return WC_TEST_RET_ENC_NC;
  53214. }
  53215. ret = wc_AesSivDecrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53216. assoc, testVectors[i].numAssoc,
  53217. testVectors[i].nonce, testVectors[i].nonceSz,
  53218. computedCiphertext,
  53219. testVectors[i].plaintextSz, siv,
  53220. computedPlaintext);
  53221. if (ret != 0) {
  53222. return WC_TEST_RET_ENC_EC(ret);
  53223. }
  53224. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53225. testVectors[i].plaintextSz);
  53226. if (ret != 0) {
  53227. return WC_TEST_RET_ENC_NC;
  53228. }
  53229. }
  53230. return 0;
  53231. }
  53232. #endif
  53233. #undef ERROR_OUT
  53234. static const int fiducial4 = WC_TEST_RET_LN;
  53235. /* print the fiducial line numbers assigned above, allowing confirmation of
  53236. * source code version match when in doubt.
  53237. */
  53238. static void print_fiducials(void) {
  53239. printf(" [fiducial line numbers: %d %d %d %d]\n",
  53240. fiducial1, fiducial2, fiducial3, fiducial4);
  53241. }
  53242. #else
  53243. #ifndef NO_MAIN_DRIVER
  53244. int main(void) { return 0; }
  53245. #endif
  53246. #endif /* NO_CRYPT_TEST */