mbedtls.h 943 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901
  1. /*
  2. * MbedTLS Source Code Library Header
  3. */
  4. #include "me.h"
  5. #if ME_COM_MBEDTLS
  6. #if defined(MBEDTLS_CONFIG_FILE)
  7. #include MBEDTLS_CONFIG_FILE
  8. #endif
  9. /********* Start of file include/mbedtls/config.h ************/
  10. /**
  11. * \file config.h
  12. *
  13. * \brief Configuration options (set of defines)
  14. *
  15. * This set of compile-time options may be used to enable
  16. * or disable features selectively, and reduce the global
  17. * memory footprint.
  18. */
  19. /*
  20. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  21. * SPDX-License-Identifier: Apache-2.0
  22. *
  23. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  24. * not use this file except in compliance with the License.
  25. * You may obtain a copy of the License at
  26. *
  27. * http://www.apache.org/licenses/LICENSE-2.0
  28. *
  29. * Unless required by applicable law or agreed to in writing, software
  30. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  31. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  32. * See the License for the specific language governing permissions and
  33. * limitations under the License.
  34. *
  35. * This file is part of mbed TLS (https://tls.mbed.org)
  36. */
  37. #ifndef MBEDTLS_CONFIG_H
  38. #define MBEDTLS_CONFIG_H
  39. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
  40. #define _CRT_SECURE_NO_DEPRECATE 1
  41. #endif
  42. /**
  43. * \name SECTION: System support
  44. *
  45. * This section sets system specific settings.
  46. * \{
  47. */
  48. /**
  49. * \def MBEDTLS_HAVE_ASM
  50. *
  51. * The compiler has support for asm().
  52. *
  53. * Requires support for asm() in compiler.
  54. *
  55. * Used in:
  56. * library/timing.c
  57. * library/padlock.c
  58. * include/mbedtls/bn_mul.h
  59. *
  60. * Comment to disable the use of assembly code.
  61. */
  62. #define MBEDTLS_HAVE_ASM
  63. /**
  64. * \def MBEDTLS_NO_UDBL_DIVISION
  65. *
  66. * The platform lacks support for double-width integer division (64-bit
  67. * division on a 32-bit platform, 128-bit division on a 64-bit platform).
  68. *
  69. * Used in:
  70. * include/mbedtls/bignum.h
  71. * library/bignum.c
  72. *
  73. * The bignum code uses double-width division to speed up some operations.
  74. * Double-width division is often implemented in software that needs to
  75. * be linked with the program. The presence of a double-width integer
  76. * type is usually detected automatically through preprocessor macros,
  77. * but the automatic detection cannot know whether the code needs to
  78. * and can be linked with an implementation of division for that type.
  79. * By default division is assumed to be usable if the type is present.
  80. * Uncomment this option to prevent the use of double-width division.
  81. *
  82. * Note that division for the native integer type is always required.
  83. * Furthermore, a 64-bit type is always required even on a 32-bit
  84. * platform, but it need not support multiplication or division. In some
  85. * cases it is also desirable to disable some double-width operations. For
  86. * example, if double-width division is implemented in software, disabling
  87. * it can reduce code size in some embedded targets.
  88. */
  89. //#define MBEDTLS_NO_UDBL_DIVISION
  90. /**
  91. * \def MBEDTLS_HAVE_SSE2
  92. *
  93. * CPU supports SSE2 instruction set.
  94. *
  95. * Uncomment if the CPU supports SSE2 (IA-32 specific).
  96. */
  97. //#define MBEDTLS_HAVE_SSE2
  98. /**
  99. * \def MBEDTLS_HAVE_TIME
  100. *
  101. * System has time.h and time().
  102. * The time does not need to be correct, only time differences are used,
  103. * by contrast with MBEDTLS_HAVE_TIME_DATE
  104. *
  105. * Defining MBEDTLS_HAVE_TIME allows you to specify MBEDTLS_PLATFORM_TIME_ALT,
  106. * MBEDTLS_PLATFORM_TIME_MACRO, MBEDTLS_PLATFORM_TIME_TYPE_MACRO and
  107. * MBEDTLS_PLATFORM_STD_TIME.
  108. *
  109. * Comment if your system does not support time functions
  110. */
  111. #define MBEDTLS_HAVE_TIME
  112. /**
  113. * \def MBEDTLS_HAVE_TIME_DATE
  114. *
  115. * System has time.h and time(), gmtime() and the clock is correct.
  116. * The time needs to be correct (not necesarily very accurate, but at least
  117. * the date should be correct). This is used to verify the validity period of
  118. * X.509 certificates.
  119. *
  120. * Comment if your system does not have a correct clock.
  121. */
  122. #define MBEDTLS_HAVE_TIME_DATE
  123. /**
  124. * \def MBEDTLS_PLATFORM_MEMORY
  125. *
  126. * Enable the memory allocation layer.
  127. *
  128. * By default mbed TLS uses the system-provided calloc() and free().
  129. * This allows different allocators (self-implemented or provided) to be
  130. * provided to the platform abstraction layer.
  131. *
  132. * Enabling MBEDTLS_PLATFORM_MEMORY without the
  133. * MBEDTLS_PLATFORM_{FREE,CALLOC}_MACROs will provide
  134. * "mbedtls_platform_set_calloc_free()" allowing you to set an alternative calloc() and
  135. * free() function pointer at runtime.
  136. *
  137. * Enabling MBEDTLS_PLATFORM_MEMORY and specifying
  138. * MBEDTLS_PLATFORM_{CALLOC,FREE}_MACROs will allow you to specify the
  139. * alternate function at compile time.
  140. *
  141. * Requires: MBEDTLS_PLATFORM_C
  142. *
  143. * Enable this layer to allow use of alternative memory allocators.
  144. */
  145. //#define MBEDTLS_PLATFORM_MEMORY
  146. /**
  147. * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
  148. *
  149. * Do not assign standard functions in the platform layer (e.g. calloc() to
  150. * MBEDTLS_PLATFORM_STD_CALLOC and printf() to MBEDTLS_PLATFORM_STD_PRINTF)
  151. *
  152. * This makes sure there are no linking errors on platforms that do not support
  153. * these functions. You will HAVE to provide alternatives, either at runtime
  154. * via the platform_set_xxx() functions or at compile time by setting
  155. * the MBEDTLS_PLATFORM_STD_XXX defines, or enabling a
  156. * MBEDTLS_PLATFORM_XXX_MACRO.
  157. *
  158. * Requires: MBEDTLS_PLATFORM_C
  159. *
  160. * Uncomment to prevent default assignment of standard functions in the
  161. * platform layer.
  162. */
  163. //#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
  164. /**
  165. * \def MBEDTLS_PLATFORM_EXIT_ALT
  166. *
  167. * MBEDTLS_PLATFORM_XXX_ALT: Uncomment a macro to let mbed TLS support the
  168. * function in the platform abstraction layer.
  169. *
  170. * Example: In case you uncomment MBEDTLS_PLATFORM_PRINTF_ALT, mbed TLS will
  171. * provide a function "mbedtls_platform_set_printf()" that allows you to set an
  172. * alternative printf function pointer.
  173. *
  174. * All these define require MBEDTLS_PLATFORM_C to be defined!
  175. *
  176. * \note MBEDTLS_PLATFORM_SNPRINTF_ALT is required on Windows;
  177. * it will be enabled automatically by check_config.h
  178. *
  179. * \warning MBEDTLS_PLATFORM_XXX_ALT cannot be defined at the same time as
  180. * MBEDTLS_PLATFORM_XXX_MACRO!
  181. *
  182. * Requires: MBEDTLS_PLATFORM_TIME_ALT requires MBEDTLS_HAVE_TIME
  183. *
  184. * Uncomment a macro to enable alternate implementation of specific base
  185. * platform function
  186. */
  187. //#define MBEDTLS_PLATFORM_EXIT_ALT
  188. //#define MBEDTLS_PLATFORM_TIME_ALT
  189. //#define MBEDTLS_PLATFORM_FPRINTF_ALT
  190. //#define MBEDTLS_PLATFORM_PRINTF_ALT
  191. //#define MBEDTLS_PLATFORM_SNPRINTF_ALT
  192. //#define MBEDTLS_PLATFORM_NV_SEED_ALT
  193. //#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
  194. /**
  195. * \def MBEDTLS_DEPRECATED_WARNING
  196. *
  197. * Mark deprecated functions so that they generate a warning if used.
  198. * Functions deprecated in one version will usually be removed in the next
  199. * version. You can enable this to help you prepare the transition to a new
  200. * major version by making sure your code is not using these functions.
  201. *
  202. * This only works with GCC and Clang. With other compilers, you may want to
  203. * use MBEDTLS_DEPRECATED_REMOVED
  204. *
  205. * Uncomment to get warnings on using deprecated functions.
  206. */
  207. //#define MBEDTLS_DEPRECATED_WARNING
  208. /**
  209. * \def MBEDTLS_DEPRECATED_REMOVED
  210. *
  211. * Remove deprecated functions so that they generate an error if used.
  212. * Functions deprecated in one version will usually be removed in the next
  213. * version. You can enable this to help you prepare the transition to a new
  214. * major version by making sure your code is not using these functions.
  215. *
  216. * Uncomment to get errors on using deprecated functions.
  217. */
  218. //#define MBEDTLS_DEPRECATED_REMOVED
  219. /* \} name SECTION: System support */
  220. /**
  221. * \name SECTION: mbed TLS feature support
  222. *
  223. * This section sets support for features that are or are not needed
  224. * within the modules that are enabled.
  225. * \{
  226. */
  227. /**
  228. * \def MBEDTLS_TIMING_ALT
  229. *
  230. * Uncomment to provide your own alternate implementation for mbedtls_timing_hardclock(),
  231. * mbedtls_timing_get_timer(), mbedtls_set_alarm(), mbedtls_set/get_delay()
  232. *
  233. * Only works if you have MBEDTLS_TIMING_C enabled.
  234. *
  235. * You will need to provide a header "timing_alt.h" and an implementation at
  236. * compile time.
  237. */
  238. //#define MBEDTLS_TIMING_ALT
  239. /**
  240. * \def MBEDTLS_AES_ALT
  241. *
  242. * MBEDTLS__MODULE_NAME__ALT: Uncomment a macro to let mbed TLS use your
  243. * alternate core implementation of a symmetric crypto, an arithmetic or hash
  244. * module (e.g. platform specific assembly optimized implementations). Keep
  245. * in mind that the function prototypes should remain the same.
  246. *
  247. * This replaces the whole module. If you only want to replace one of the
  248. * functions, use one of the MBEDTLS__FUNCTION_NAME__ALT flags.
  249. *
  250. * Example: In case you uncomment MBEDTLS_AES_ALT, mbed TLS will no longer
  251. * provide the "struct mbedtls_aes_context" definition and omit the base
  252. * function declarations and implementations. "aes_alt.h" will be included from
  253. * "aes.h" to include the new function definitions.
  254. *
  255. * Uncomment a macro to enable alternate implementation of the corresponding
  256. * module.
  257. *
  258. * \warning MD2, MD4, MD5, ARC4, DES and SHA-1 are considered weak and their
  259. * use constitutes a security risk. If possible, we recommend
  260. * avoiding dependencies on them, and considering stronger message
  261. * digests and ciphers instead.
  262. *
  263. */
  264. //#define MBEDTLS_AES_ALT
  265. //#define MBEDTLS_ARC4_ALT
  266. //#define MBEDTLS_BLOWFISH_ALT
  267. //#define MBEDTLS_CAMELLIA_ALT
  268. //#define MBEDTLS_CCM_ALT
  269. //#define MBEDTLS_CMAC_ALT
  270. //#define MBEDTLS_DES_ALT
  271. //#define MBEDTLS_DHM_ALT
  272. //#define MBEDTLS_ECJPAKE_ALT
  273. //#define MBEDTLS_GCM_ALT
  274. //#define MBEDTLS_MD2_ALT
  275. //#define MBEDTLS_MD4_ALT
  276. //#define MBEDTLS_MD5_ALT
  277. //#define MBEDTLS_RIPEMD160_ALT
  278. //#define MBEDTLS_RSA_ALT
  279. //#define MBEDTLS_SHA1_ALT
  280. //#define MBEDTLS_SHA256_ALT
  281. //#define MBEDTLS_SHA512_ALT
  282. //#define MBEDTLS_XTEA_ALT
  283. /*
  284. * When replacing the elliptic curve module, pleace consider, that it is
  285. * implemented with two .c files:
  286. * - ecp.c
  287. * - ecp_curves.c
  288. * You can replace them very much like all the other MBEDTLS__MODULE_NAME__ALT
  289. * macros as described above. The only difference is that you have to make sure
  290. * that you provide functionality for both .c files.
  291. */
  292. //#define MBEDTLS_ECP_ALT
  293. /**
  294. * \def MBEDTLS_MD2_PROCESS_ALT
  295. *
  296. * MBEDTLS__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use you
  297. * alternate core implementation of symmetric crypto or hash function. Keep in
  298. * mind that function prototypes should remain the same.
  299. *
  300. * This replaces only one function. The header file from mbed TLS is still
  301. * used, in contrast to the MBEDTLS__MODULE_NAME__ALT flags.
  302. *
  303. * Example: In case you uncomment MBEDTLS_SHA256_PROCESS_ALT, mbed TLS will
  304. * no longer provide the mbedtls_sha1_process() function, but it will still provide
  305. * the other function (using your mbedtls_sha1_process() function) and the definition
  306. * of mbedtls_sha1_context, so your implementation of mbedtls_sha1_process must be compatible
  307. * with this definition.
  308. *
  309. * \note Because of a signature change, the core AES encryption and decryption routines are
  310. * currently named mbedtls_aes_internal_encrypt and mbedtls_aes_internal_decrypt,
  311. * respectively. When setting up alternative implementations, these functions should
  312. * be overriden, but the wrapper functions mbedtls_aes_decrypt and mbedtls_aes_encrypt
  313. * must stay untouched.
  314. *
  315. * \note If you use the AES_xxx_ALT macros, then is is recommended to also set
  316. * MBEDTLS_AES_ROM_TABLES in order to help the linker garbage-collect the AES
  317. * tables.
  318. *
  319. * Uncomment a macro to enable alternate implementation of the corresponding
  320. * function.
  321. *
  322. * \warning MD2, MD4, MD5, DES and SHA-1 are considered weak and their use
  323. * constitutes a security risk. If possible, we recommend avoiding
  324. * dependencies on them, and considering stronger message digests
  325. * and ciphers instead.
  326. *
  327. */
  328. //#define MBEDTLS_MD2_PROCESS_ALT
  329. //#define MBEDTLS_MD4_PROCESS_ALT
  330. //#define MBEDTLS_MD5_PROCESS_ALT
  331. //#define MBEDTLS_RIPEMD160_PROCESS_ALT
  332. //#define MBEDTLS_SHA1_PROCESS_ALT
  333. //#define MBEDTLS_SHA256_PROCESS_ALT
  334. //#define MBEDTLS_SHA512_PROCESS_ALT
  335. //#define MBEDTLS_DES_SETKEY_ALT
  336. //#define MBEDTLS_DES_CRYPT_ECB_ALT
  337. //#define MBEDTLS_DES3_CRYPT_ECB_ALT
  338. //#define MBEDTLS_AES_SETKEY_ENC_ALT
  339. //#define MBEDTLS_AES_SETKEY_DEC_ALT
  340. //#define MBEDTLS_AES_ENCRYPT_ALT
  341. //#define MBEDTLS_AES_DECRYPT_ALT
  342. //#define MBEDTLS_ECDH_GEN_PUBLIC_ALT
  343. //#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT
  344. //#define MBEDTLS_ECDSA_VERIFY_ALT
  345. //#define MBEDTLS_ECDSA_SIGN_ALT
  346. //#define MBEDTLS_ECDSA_GENKEY_ALT
  347. /**
  348. * \def MBEDTLS_ECP_INTERNAL_ALT
  349. *
  350. * Expose a part of the internal interface of the Elliptic Curve Point module.
  351. *
  352. * MBEDTLS_ECP__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use your
  353. * alternative core implementation of elliptic curve arithmetic. Keep in mind
  354. * that function prototypes should remain the same.
  355. *
  356. * This partially replaces one function. The header file from mbed TLS is still
  357. * used, in contrast to the MBEDTLS_ECP_ALT flag. The original implementation
  358. * is still present and it is used for group structures not supported by the
  359. * alternative.
  360. *
  361. * Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT
  362. * and implementing the following functions:
  363. * unsigned char mbedtls_internal_ecp_grp_capable(
  364. * const mbedtls_ecp_group *grp )
  365. * int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp )
  366. * void mbedtls_internal_ecp_deinit( const mbedtls_ecp_group *grp )
  367. * The mbedtls_internal_ecp_grp_capable function should return 1 if the
  368. * replacement functions implement arithmetic for the given group and 0
  369. * otherwise.
  370. * The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_deinit are
  371. * called before and after each point operation and provide an opportunity to
  372. * implement optimized set up and tear down instructions.
  373. *
  374. * Example: In case you uncomment MBEDTLS_ECP_INTERNAL_ALT and
  375. * MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac
  376. * function, but will use your mbedtls_internal_ecp_double_jac if the group is
  377. * supported (your mbedtls_internal_ecp_grp_capable function returns 1 when
  378. * receives it as an argument). If the group is not supported then the original
  379. * implementation is used. The other functions and the definition of
  380. * mbedtls_ecp_group and mbedtls_ecp_point will not change, so your
  381. * implementation of mbedtls_internal_ecp_double_jac and
  382. * mbedtls_internal_ecp_grp_capable must be compatible with this definition.
  383. *
  384. * Uncomment a macro to enable alternate implementation of the corresponding
  385. * function.
  386. */
  387. /* Required for all the functions in this section */
  388. //#define MBEDTLS_ECP_INTERNAL_ALT
  389. /* Support for Weierstrass curves with Jacobi representation */
  390. //#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT
  391. //#define MBEDTLS_ECP_ADD_MIXED_ALT
  392. //#define MBEDTLS_ECP_DOUBLE_JAC_ALT
  393. //#define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT
  394. //#define MBEDTLS_ECP_NORMALIZE_JAC_ALT
  395. /* Support for curves with Montgomery arithmetic */
  396. //#define MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT
  397. //#define MBEDTLS_ECP_RANDOMIZE_MXZ_ALT
  398. //#define MBEDTLS_ECP_NORMALIZE_MXZ_ALT
  399. /**
  400. * \def MBEDTLS_TEST_NULL_ENTROPY
  401. *
  402. * Enables testing and use of mbed TLS without any configured entropy sources.
  403. * This permits use of the library on platforms before an entropy source has
  404. * been integrated (see for example the MBEDTLS_ENTROPY_HARDWARE_ALT or the
  405. * MBEDTLS_ENTROPY_NV_SEED switches).
  406. *
  407. * WARNING! This switch MUST be disabled in production builds, and is suitable
  408. * only for development.
  409. * Enabling the switch negates any security provided by the library.
  410. *
  411. * Requires MBEDTLS_ENTROPY_C, MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
  412. *
  413. */
  414. //#define MBEDTLS_TEST_NULL_ENTROPY
  415. /**
  416. * \def MBEDTLS_ENTROPY_HARDWARE_ALT
  417. *
  418. * Uncomment this macro to let mbed TLS use your own implementation of a
  419. * hardware entropy collector.
  420. *
  421. * Your function must be called \c mbedtls_hardware_poll(), have the same
  422. * prototype as declared in entropy_poll.h, and accept NULL as first argument.
  423. *
  424. * Uncomment to use your own hardware entropy collector.
  425. */
  426. //#define MBEDTLS_ENTROPY_HARDWARE_ALT
  427. /**
  428. * \def MBEDTLS_AES_ROM_TABLES
  429. *
  430. * Store the AES tables in ROM.
  431. *
  432. * Uncomment this macro to store the AES tables in ROM.
  433. */
  434. //#define MBEDTLS_AES_ROM_TABLES
  435. /**
  436. * \def MBEDTLS_CAMELLIA_SMALL_MEMORY
  437. *
  438. * Use less ROM for the Camellia implementation (saves about 768 bytes).
  439. *
  440. * Uncomment this macro to use less memory for Camellia.
  441. */
  442. //#define MBEDTLS_CAMELLIA_SMALL_MEMORY
  443. /**
  444. * \def MBEDTLS_CIPHER_MODE_CBC
  445. *
  446. * Enable Cipher Block Chaining mode (CBC) for symmetric ciphers.
  447. */
  448. #define MBEDTLS_CIPHER_MODE_CBC
  449. /**
  450. * \def MBEDTLS_CIPHER_MODE_CFB
  451. *
  452. * Enable Cipher Feedback mode (CFB) for symmetric ciphers.
  453. */
  454. #define MBEDTLS_CIPHER_MODE_CFB
  455. /**
  456. * \def MBEDTLS_CIPHER_MODE_CTR
  457. *
  458. * Enable Counter Block Cipher mode (CTR) for symmetric ciphers.
  459. */
  460. #define MBEDTLS_CIPHER_MODE_CTR
  461. /**
  462. * \def MBEDTLS_CIPHER_NULL_CIPHER
  463. *
  464. * Enable NULL cipher.
  465. * Warning: Only do so when you know what you are doing. This allows for
  466. * encryption or channels without any security!
  467. *
  468. * Requires MBEDTLS_ENABLE_WEAK_CIPHERSUITES as well to enable
  469. * the following ciphersuites:
  470. * MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA
  471. * MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA
  472. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA
  473. * MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA
  474. * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384
  475. * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256
  476. * MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA
  477. * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384
  478. * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256
  479. * MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA
  480. * MBEDTLS_TLS_RSA_WITH_NULL_SHA256
  481. * MBEDTLS_TLS_RSA_WITH_NULL_SHA
  482. * MBEDTLS_TLS_RSA_WITH_NULL_MD5
  483. * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384
  484. * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256
  485. * MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA
  486. * MBEDTLS_TLS_PSK_WITH_NULL_SHA384
  487. * MBEDTLS_TLS_PSK_WITH_NULL_SHA256
  488. * MBEDTLS_TLS_PSK_WITH_NULL_SHA
  489. *
  490. * Uncomment this macro to enable the NULL cipher and ciphersuites
  491. */
  492. //#define MBEDTLS_CIPHER_NULL_CIPHER
  493. /**
  494. * \def MBEDTLS_CIPHER_PADDING_PKCS7
  495. *
  496. * MBEDTLS_CIPHER_PADDING_XXX: Uncomment or comment macros to add support for
  497. * specific padding modes in the cipher layer with cipher modes that support
  498. * padding (e.g. CBC)
  499. *
  500. * If you disable all padding modes, only full blocks can be used with CBC.
  501. *
  502. * Enable padding modes in the cipher layer.
  503. */
  504. #define MBEDTLS_CIPHER_PADDING_PKCS7
  505. #define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
  506. #define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN
  507. #define MBEDTLS_CIPHER_PADDING_ZEROS
  508. /**
  509. * \def MBEDTLS_ENABLE_WEAK_CIPHERSUITES
  510. *
  511. * Enable weak ciphersuites in SSL / TLS.
  512. * Warning: Only do so when you know what you are doing. This allows for
  513. * channels with virtually no security at all!
  514. *
  515. * This enables the following ciphersuites:
  516. * MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA
  517. * MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA
  518. *
  519. * Uncomment this macro to enable weak ciphersuites
  520. *
  521. * \warning DES is considered a weak cipher and its use constitutes a
  522. * security risk. We recommend considering stronger ciphers instead.
  523. */
  524. //#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES
  525. /**
  526. * \def MBEDTLS_REMOVE_ARC4_CIPHERSUITES
  527. *
  528. * Remove RC4 ciphersuites by default in SSL / TLS.
  529. * This flag removes the ciphersuites based on RC4 from the default list as
  530. * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible to
  531. * enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including them
  532. * explicitly.
  533. *
  534. * Uncomment this macro to remove RC4 ciphersuites by default.
  535. */
  536. #define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
  537. /**
  538. * \def MBEDTLS_ECP_DP_SECP192R1_ENABLED
  539. *
  540. * MBEDTLS_ECP_XXXX_ENABLED: Enables specific curves within the Elliptic Curve
  541. * module. By default all supported curves are enabled.
  542. *
  543. * Comment macros to disable the curve and functions for it
  544. */
  545. #define MBEDTLS_ECP_DP_SECP192R1_ENABLED
  546. #define MBEDTLS_ECP_DP_SECP224R1_ENABLED
  547. #define MBEDTLS_ECP_DP_SECP256R1_ENABLED
  548. #define MBEDTLS_ECP_DP_SECP384R1_ENABLED
  549. #define MBEDTLS_ECP_DP_SECP521R1_ENABLED
  550. #define MBEDTLS_ECP_DP_SECP192K1_ENABLED
  551. #define MBEDTLS_ECP_DP_SECP224K1_ENABLED
  552. #define MBEDTLS_ECP_DP_SECP256K1_ENABLED
  553. #define MBEDTLS_ECP_DP_BP256R1_ENABLED
  554. #define MBEDTLS_ECP_DP_BP384R1_ENABLED
  555. #define MBEDTLS_ECP_DP_BP512R1_ENABLED
  556. #define MBEDTLS_ECP_DP_CURVE25519_ENABLED
  557. /**
  558. * \def MBEDTLS_ECP_NIST_OPTIM
  559. *
  560. * Enable specific 'modulo p' routines for each NIST prime.
  561. * Depending on the prime and architecture, makes operations 4 to 8 times
  562. * faster on the corresponding curve.
  563. *
  564. * Comment this macro to disable NIST curves optimisation.
  565. */
  566. #define MBEDTLS_ECP_NIST_OPTIM
  567. /**
  568. * \def MBEDTLS_ECDSA_DETERMINISTIC
  569. *
  570. * Enable deterministic ECDSA (RFC 6979).
  571. * Standard ECDSA is "fragile" in the sense that lack of entropy when signing
  572. * may result in a compromise of the long-term signing key. This is avoided by
  573. * the deterministic variant.
  574. *
  575. * Requires: MBEDTLS_HMAC_DRBG_C
  576. *
  577. * Comment this macro to disable deterministic ECDSA.
  578. */
  579. #define MBEDTLS_ECDSA_DETERMINISTIC
  580. /**
  581. * \def MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
  582. *
  583. * Enable the PSK based ciphersuite modes in SSL / TLS.
  584. *
  585. * This enables the following ciphersuites (if other requisites are
  586. * enabled as well):
  587. * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384
  588. * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384
  589. * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA
  590. * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384
  591. * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384
  592. * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256
  593. * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256
  594. * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA
  595. * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
  596. * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
  597. * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
  598. * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
  599. */
  600. #define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
  601. /**
  602. * \def MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
  603. *
  604. * Enable the DHE-PSK based ciphersuite modes in SSL / TLS.
  605. *
  606. * Requires: MBEDTLS_DHM_C
  607. *
  608. * This enables the following ciphersuites (if other requisites are
  609. * enabled as well):
  610. * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
  611. * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
  612. * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA
  613. * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384
  614. * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
  615. * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
  616. * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
  617. * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA
  618. * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
  619. * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
  620. * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
  621. * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
  622. *
  623. * \warning Using DHE constitutes a security risk as it
  624. * is not possible to validate custom DH parameters.
  625. * If possible, it is recommended users should consider
  626. * preferring other methods of key exchange.
  627. * See dhm.h for more details.
  628. *
  629. */
  630. #define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
  631. /**
  632. * \def MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
  633. *
  634. * Enable the ECDHE-PSK based ciphersuite modes in SSL / TLS.
  635. *
  636. * Requires: MBEDTLS_ECDH_C
  637. *
  638. * This enables the following ciphersuites (if other requisites are
  639. * enabled as well):
  640. * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
  641. * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
  642. * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
  643. * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
  644. * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
  645. * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
  646. * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
  647. * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
  648. */
  649. #define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
  650. /**
  651. * \def MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
  652. *
  653. * Enable the RSA-PSK based ciphersuite modes in SSL / TLS.
  654. *
  655. * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
  656. * MBEDTLS_X509_CRT_PARSE_C
  657. *
  658. * This enables the following ciphersuites (if other requisites are
  659. * enabled as well):
  660. * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
  661. * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
  662. * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA
  663. * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384
  664. * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384
  665. * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
  666. * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
  667. * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA
  668. * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
  669. * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
  670. * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
  671. * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
  672. */
  673. #define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
  674. /**
  675. * \def MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
  676. *
  677. * Enable the RSA-only based ciphersuite modes in SSL / TLS.
  678. *
  679. * Requires: MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
  680. * MBEDTLS_X509_CRT_PARSE_C
  681. *
  682. * This enables the following ciphersuites (if other requisites are
  683. * enabled as well):
  684. * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384
  685. * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256
  686. * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA
  687. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384
  688. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
  689. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
  690. * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256
  691. * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256
  692. * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA
  693. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256
  694. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
  695. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
  696. * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
  697. * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
  698. * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
  699. */
  700. #define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
  701. /**
  702. * \def MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
  703. *
  704. * Enable the DHE-RSA based ciphersuite modes in SSL / TLS.
  705. *
  706. * Requires: MBEDTLS_DHM_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
  707. * MBEDTLS_X509_CRT_PARSE_C
  708. *
  709. * This enables the following ciphersuites (if other requisites are
  710. * enabled as well):
  711. * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
  712. * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
  713. * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
  714. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
  715. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
  716. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
  717. * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
  718. * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
  719. * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  720. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
  721. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
  722. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
  723. * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
  724. *
  725. * \warning Using DHE constitutes a security risk as it
  726. * is not possible to validate custom DH parameters.
  727. * If possible, it is recommended users should consider
  728. * preferring other methods of key exchange.
  729. * See dhm.h for more details.
  730. *
  731. */
  732. #define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
  733. /**
  734. * \def MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  735. *
  736. * Enable the ECDHE-RSA based ciphersuite modes in SSL / TLS.
  737. *
  738. * Requires: MBEDTLS_ECDH_C, MBEDTLS_RSA_C, MBEDTLS_PKCS1_V15,
  739. * MBEDTLS_X509_CRT_PARSE_C
  740. *
  741. * This enables the following ciphersuites (if other requisites are
  742. * enabled as well):
  743. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  744. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
  745. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
  746. * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
  747. * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384
  748. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  749. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
  750. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
  751. * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
  752. * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
  753. * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
  754. * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
  755. */
  756. #define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  757. /**
  758. * \def MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  759. *
  760. * Enable the ECDHE-ECDSA based ciphersuite modes in SSL / TLS.
  761. *
  762. * Requires: MBEDTLS_ECDH_C, MBEDTLS_ECDSA_C, MBEDTLS_X509_CRT_PARSE_C,
  763. *
  764. * This enables the following ciphersuites (if other requisites are
  765. * enabled as well):
  766. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
  767. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
  768. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
  769. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
  770. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
  771. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
  772. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
  773. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
  774. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
  775. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
  776. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
  777. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
  778. */
  779. #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  780. /**
  781. * \def MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  782. *
  783. * Enable the ECDH-ECDSA based ciphersuite modes in SSL / TLS.
  784. *
  785. * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C
  786. *
  787. * This enables the following ciphersuites (if other requisites are
  788. * enabled as well):
  789. * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
  790. * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
  791. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
  792. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
  793. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
  794. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
  795. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
  796. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
  797. * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
  798. * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
  799. * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
  800. * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
  801. */
  802. #define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  803. /**
  804. * \def MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  805. *
  806. * Enable the ECDH-RSA based ciphersuite modes in SSL / TLS.
  807. *
  808. * Requires: MBEDTLS_ECDH_C, MBEDTLS_X509_CRT_PARSE_C
  809. *
  810. * This enables the following ciphersuites (if other requisites are
  811. * enabled as well):
  812. * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
  813. * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
  814. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
  815. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
  816. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
  817. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
  818. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
  819. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
  820. * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256
  821. * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384
  822. * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256
  823. * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384
  824. */
  825. #define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  826. /**
  827. * \def MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
  828. *
  829. * Enable the ECJPAKE based ciphersuite modes in SSL / TLS.
  830. *
  831. * \warning This is currently experimental. EC J-PAKE support is based on the
  832. * Thread v1.0.0 specification; incompatible changes to the specification
  833. * might still happen. For this reason, this is disabled by default.
  834. *
  835. * Requires: MBEDTLS_ECJPAKE_C
  836. * MBEDTLS_SHA256_C
  837. * MBEDTLS_ECP_DP_SECP256R1_ENABLED
  838. *
  839. * This enables the following ciphersuites (if other requisites are
  840. * enabled as well):
  841. * MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8
  842. */
  843. //#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
  844. /**
  845. * \def MBEDTLS_PK_PARSE_EC_EXTENDED
  846. *
  847. * Enhance support for reading EC keys using variants of SEC1 not allowed by
  848. * RFC 5915 and RFC 5480.
  849. *
  850. * Currently this means parsing the SpecifiedECDomain choice of EC
  851. * parameters (only known groups are supported, not arbitrary domains, to
  852. * avoid validation issues).
  853. *
  854. * Disable if you only need to support RFC 5915 + 5480 key formats.
  855. */
  856. #define MBEDTLS_PK_PARSE_EC_EXTENDED
  857. /**
  858. * \def MBEDTLS_ERROR_STRERROR_DUMMY
  859. *
  860. * Enable a dummy error function to make use of mbedtls_strerror() in
  861. * third party libraries easier when MBEDTLS_ERROR_C is disabled
  862. * (no effect when MBEDTLS_ERROR_C is enabled).
  863. *
  864. * You can safely disable this if MBEDTLS_ERROR_C is enabled, or if you're
  865. * not using mbedtls_strerror() or error_strerror() in your application.
  866. *
  867. * Disable if you run into name conflicts and want to really remove the
  868. * mbedtls_strerror()
  869. */
  870. #define MBEDTLS_ERROR_STRERROR_DUMMY
  871. /**
  872. * \def MBEDTLS_GENPRIME
  873. *
  874. * Enable the prime-number generation code.
  875. *
  876. * Requires: MBEDTLS_BIGNUM_C
  877. */
  878. #define MBEDTLS_GENPRIME
  879. /**
  880. * \def MBEDTLS_FS_IO
  881. *
  882. * Enable functions that use the filesystem.
  883. */
  884. #define MBEDTLS_FS_IO
  885. /**
  886. * \def MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
  887. *
  888. * Do not add default entropy sources. These are the platform specific,
  889. * mbedtls_timing_hardclock and HAVEGE based poll functions.
  890. *
  891. * This is useful to have more control over the added entropy sources in an
  892. * application.
  893. *
  894. * Uncomment this macro to prevent loading of default entropy functions.
  895. */
  896. //#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
  897. /**
  898. * \def MBEDTLS_NO_PLATFORM_ENTROPY
  899. *
  900. * Do not use built-in platform entropy functions.
  901. * This is useful if your platform does not support
  902. * standards like the /dev/urandom or Windows CryptoAPI.
  903. *
  904. * Uncomment this macro to disable the built-in platform entropy functions.
  905. */
  906. //#define MBEDTLS_NO_PLATFORM_ENTROPY
  907. /**
  908. * \def MBEDTLS_ENTROPY_FORCE_SHA256
  909. *
  910. * Force the entropy accumulator to use a SHA-256 accumulator instead of the
  911. * default SHA-512 based one (if both are available).
  912. *
  913. * Requires: MBEDTLS_SHA256_C
  914. *
  915. * On 32-bit systems SHA-256 can be much faster than SHA-512. Use this option
  916. * if you have performance concerns.
  917. *
  918. * This option is only useful if both MBEDTLS_SHA256_C and
  919. * MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used.
  920. */
  921. //#define MBEDTLS_ENTROPY_FORCE_SHA256
  922. /**
  923. * \def MBEDTLS_ENTROPY_NV_SEED
  924. *
  925. * Enable the non-volatile (NV) seed file-based entropy source.
  926. * (Also enables the NV seed read/write functions in the platform layer)
  927. *
  928. * This is crucial (if not required) on systems that do not have a
  929. * cryptographic entropy source (in hardware or kernel) available.
  930. *
  931. * Requires: MBEDTLS_ENTROPY_C, MBEDTLS_PLATFORM_C
  932. *
  933. * \note The read/write functions that are used by the entropy source are
  934. * determined in the platform layer, and can be modified at runtime and/or
  935. * compile-time depending on the flags (MBEDTLS_PLATFORM_NV_SEED_*) used.
  936. *
  937. * \note If you use the default implementation functions that read a seedfile
  938. * with regular fopen(), please make sure you make a seedfile with the
  939. * proper name (defined in MBEDTLS_PLATFORM_STD_NV_SEED_FILE) and at
  940. * least MBEDTLS_ENTROPY_BLOCK_SIZE bytes in size that can be read from
  941. * and written to or you will get an entropy source error! The default
  942. * implementation will only use the first MBEDTLS_ENTROPY_BLOCK_SIZE
  943. * bytes from the file.
  944. *
  945. * \note The entropy collector will write to the seed file before entropy is
  946. * given to an external source, to update it.
  947. */
  948. //#define MBEDTLS_ENTROPY_NV_SEED
  949. /**
  950. * \def MBEDTLS_MEMORY_DEBUG
  951. *
  952. * Enable debugging of buffer allocator memory issues. Automatically prints
  953. * (to stderr) all (fatal) messages on memory allocation issues. Enables
  954. * function for 'debug output' of allocated memory.
  955. *
  956. * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C
  957. *
  958. * Uncomment this macro to let the buffer allocator print out error messages.
  959. */
  960. //#define MBEDTLS_MEMORY_DEBUG
  961. /**
  962. * \def MBEDTLS_MEMORY_BACKTRACE
  963. *
  964. * Include backtrace information with each allocated block.
  965. *
  966. * Requires: MBEDTLS_MEMORY_BUFFER_ALLOC_C
  967. * GLIBC-compatible backtrace() an backtrace_symbols() support
  968. *
  969. * Uncomment this macro to include backtrace information
  970. */
  971. //#define MBEDTLS_MEMORY_BACKTRACE
  972. /**
  973. * \def MBEDTLS_PK_RSA_ALT_SUPPORT
  974. *
  975. * Support external private RSA keys (eg from a HSM) in the PK layer.
  976. *
  977. * Comment this macro to disable support for external private RSA keys.
  978. */
  979. #define MBEDTLS_PK_RSA_ALT_SUPPORT
  980. /**
  981. * \def MBEDTLS_PKCS1_V15
  982. *
  983. * Enable support for PKCS#1 v1.5 encoding.
  984. *
  985. * Requires: MBEDTLS_RSA_C
  986. *
  987. * This enables support for PKCS#1 v1.5 operations.
  988. */
  989. #define MBEDTLS_PKCS1_V15
  990. /**
  991. * \def MBEDTLS_PKCS1_V21
  992. *
  993. * Enable support for PKCS#1 v2.1 encoding.
  994. *
  995. * Requires: MBEDTLS_MD_C, MBEDTLS_RSA_C
  996. *
  997. * This enables support for RSAES-OAEP and RSASSA-PSS operations.
  998. */
  999. #define MBEDTLS_PKCS1_V21
  1000. /**
  1001. * \def MBEDTLS_RSA_NO_CRT
  1002. *
  1003. * Do not use the Chinese Remainder Theorem
  1004. * for the RSA private operation.
  1005. *
  1006. * Uncomment this macro to disable the use of CRT in RSA.
  1007. *
  1008. */
  1009. //#define MBEDTLS_RSA_NO_CRT
  1010. /**
  1011. * \def MBEDTLS_SELF_TEST
  1012. *
  1013. * Enable the checkup functions (*_self_test).
  1014. */
  1015. #define MBEDTLS_SELF_TEST
  1016. /**
  1017. * \def MBEDTLS_SHA256_SMALLER
  1018. *
  1019. * Enable an implementation of SHA-256 that has lower ROM footprint but also
  1020. * lower performance.
  1021. *
  1022. * The default implementation is meant to be a reasonnable compromise between
  1023. * performance and size. This version optimizes more aggressively for size at
  1024. * the expense of performance. Eg on Cortex-M4 it reduces the size of
  1025. * mbedtls_sha256_process() from ~2KB to ~0.5KB for a performance hit of about
  1026. * 30%.
  1027. *
  1028. * Uncomment to enable the smaller implementation of SHA256.
  1029. */
  1030. //#define MBEDTLS_SHA256_SMALLER
  1031. /**
  1032. * \def MBEDTLS_SSL_ALL_ALERT_MESSAGES
  1033. *
  1034. * Enable sending of alert messages in case of encountered errors as per RFC.
  1035. * If you choose not to send the alert messages, mbed TLS can still communicate
  1036. * with other servers, only debugging of failures is harder.
  1037. *
  1038. * The advantage of not sending alert messages, is that no information is given
  1039. * about reasons for failures thus preventing adversaries of gaining intel.
  1040. *
  1041. * Enable sending of all alert messages
  1042. */
  1043. #define MBEDTLS_SSL_ALL_ALERT_MESSAGES
  1044. /**
  1045. * \def MBEDTLS_SSL_DEBUG_ALL
  1046. *
  1047. * Enable the debug messages in SSL module for all issues.
  1048. * Debug messages have been disabled in some places to prevent timing
  1049. * attacks due to (unbalanced) debugging function calls.
  1050. *
  1051. * If you need all error reporting you should enable this during debugging,
  1052. * but remove this for production servers that should log as well.
  1053. *
  1054. * Uncomment this macro to report all debug messages on errors introducing
  1055. * a timing side-channel.
  1056. *
  1057. */
  1058. //#define MBEDTLS_SSL_DEBUG_ALL
  1059. /** \def MBEDTLS_SSL_ENCRYPT_THEN_MAC
  1060. *
  1061. * Enable support for Encrypt-then-MAC, RFC 7366.
  1062. *
  1063. * This allows peers that both support it to use a more robust protection for
  1064. * ciphersuites using CBC, providing deep resistance against timing attacks
  1065. * on the padding or underlying cipher.
  1066. *
  1067. * This only affects CBC ciphersuites, and is useless if none is defined.
  1068. *
  1069. * Requires: MBEDTLS_SSL_PROTO_TLS1 or
  1070. * MBEDTLS_SSL_PROTO_TLS1_1 or
  1071. * MBEDTLS_SSL_PROTO_TLS1_2
  1072. *
  1073. * Comment this macro to disable support for Encrypt-then-MAC
  1074. */
  1075. #define MBEDTLS_SSL_ENCRYPT_THEN_MAC
  1076. /** \def MBEDTLS_SSL_EXTENDED_MASTER_SECRET
  1077. *
  1078. * Enable support for Extended Master Secret, aka Session Hash
  1079. * (draft-ietf-tls-session-hash-02).
  1080. *
  1081. * This was introduced as "the proper fix" to the Triple Handshake familiy of
  1082. * attacks, but it is recommended to always use it (even if you disable
  1083. * renegotiation), since it actually fixes a more fundamental issue in the
  1084. * original SSL/TLS design, and has implications beyond Triple Handshake.
  1085. *
  1086. * Requires: MBEDTLS_SSL_PROTO_TLS1 or
  1087. * MBEDTLS_SSL_PROTO_TLS1_1 or
  1088. * MBEDTLS_SSL_PROTO_TLS1_2
  1089. *
  1090. * Comment this macro to disable support for Extended Master Secret.
  1091. */
  1092. #define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
  1093. /**
  1094. * \def MBEDTLS_SSL_FALLBACK_SCSV
  1095. *
  1096. * Enable support for FALLBACK_SCSV (draft-ietf-tls-downgrade-scsv-00).
  1097. *
  1098. * For servers, it is recommended to always enable this, unless you support
  1099. * only one version of TLS, or know for sure that none of your clients
  1100. * implements a fallback strategy.
  1101. *
  1102. * For clients, you only need this if you're using a fallback strategy, which
  1103. * is not recommended in the first place, unless you absolutely need it to
  1104. * interoperate with buggy (version-intolerant) servers.
  1105. *
  1106. * Comment this macro to disable support for FALLBACK_SCSV
  1107. */
  1108. #define MBEDTLS_SSL_FALLBACK_SCSV
  1109. /**
  1110. * \def MBEDTLS_SSL_HW_RECORD_ACCEL
  1111. *
  1112. * Enable hooking functions in SSL module for hardware acceleration of
  1113. * individual records.
  1114. *
  1115. * Uncomment this macro to enable hooking functions.
  1116. */
  1117. //#define MBEDTLS_SSL_HW_RECORD_ACCEL
  1118. /**
  1119. * \def MBEDTLS_SSL_CBC_RECORD_SPLITTING
  1120. *
  1121. * Enable 1/n-1 record splitting for CBC mode in SSLv3 and TLS 1.0.
  1122. *
  1123. * This is a countermeasure to the BEAST attack, which also minimizes the risk
  1124. * of interoperability issues compared to sending 0-length records.
  1125. *
  1126. * Comment this macro to disable 1/n-1 record splitting.
  1127. */
  1128. #define MBEDTLS_SSL_CBC_RECORD_SPLITTING
  1129. /**
  1130. * \def MBEDTLS_SSL_RENEGOTIATION
  1131. *
  1132. * Disable support for TLS renegotiation.
  1133. *
  1134. * The two main uses of renegotiation are (1) refresh keys on long-lived
  1135. * connections and (2) client authentication after the initial handshake.
  1136. * If you don't need renegotiation, it's probably better to disable it, since
  1137. * it has been associated with security issues in the past and is easy to
  1138. * misuse/misunderstand.
  1139. *
  1140. * Comment this to disable support for renegotiation.
  1141. *
  1142. * \note Even if this option is disabled, both client and server are aware
  1143. * of the Renegotiation Indication Extension (RFC 5746) used to
  1144. * prevent the SSL renegotiation attack (see RFC 5746 Sect. 1).
  1145. * (See \c mbedtls_ssl_conf_legacy_renegotiation for the
  1146. * configuration of this extension).
  1147. *
  1148. */
  1149. #define MBEDTLS_SSL_RENEGOTIATION
  1150. /**
  1151. * \def MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
  1152. *
  1153. * Enable support for receiving and parsing SSLv2 Client Hello messages for the
  1154. * SSL Server module (MBEDTLS_SSL_SRV_C).
  1155. *
  1156. * Uncomment this macro to enable support for SSLv2 Client Hello messages.
  1157. */
  1158. //#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
  1159. /**
  1160. * \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
  1161. *
  1162. * Pick the ciphersuite according to the client's preferences rather than ours
  1163. * in the SSL Server module (MBEDTLS_SSL_SRV_C).
  1164. *
  1165. * Uncomment this macro to respect client's ciphersuite order
  1166. */
  1167. //#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
  1168. /**
  1169. * \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  1170. *
  1171. * Enable support for RFC 6066 max_fragment_length extension in SSL.
  1172. *
  1173. * Comment this macro to disable support for the max_fragment_length extension
  1174. */
  1175. #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  1176. /**
  1177. * \def MBEDTLS_SSL_PROTO_SSL3
  1178. *
  1179. * Enable support for SSL 3.0.
  1180. *
  1181. * Requires: MBEDTLS_MD5_C
  1182. * MBEDTLS_SHA1_C
  1183. *
  1184. * Comment this macro to disable support for SSL 3.0
  1185. */
  1186. //#define MBEDTLS_SSL_PROTO_SSL3
  1187. /**
  1188. * \def MBEDTLS_SSL_PROTO_TLS1
  1189. *
  1190. * Enable support for TLS 1.0.
  1191. *
  1192. * Requires: MBEDTLS_MD5_C
  1193. * MBEDTLS_SHA1_C
  1194. *
  1195. * Comment this macro to disable support for TLS 1.0
  1196. */
  1197. #define MBEDTLS_SSL_PROTO_TLS1
  1198. /**
  1199. * \def MBEDTLS_SSL_PROTO_TLS1_1
  1200. *
  1201. * Enable support for TLS 1.1 (and DTLS 1.0 if DTLS is enabled).
  1202. *
  1203. * Requires: MBEDTLS_MD5_C
  1204. * MBEDTLS_SHA1_C
  1205. *
  1206. * Comment this macro to disable support for TLS 1.1 / DTLS 1.0
  1207. */
  1208. #define MBEDTLS_SSL_PROTO_TLS1_1
  1209. /**
  1210. * \def MBEDTLS_SSL_PROTO_TLS1_2
  1211. *
  1212. * Enable support for TLS 1.2 (and DTLS 1.2 if DTLS is enabled).
  1213. *
  1214. * Requires: MBEDTLS_SHA1_C or MBEDTLS_SHA256_C or MBEDTLS_SHA512_C
  1215. * (Depends on ciphersuites)
  1216. *
  1217. * Comment this macro to disable support for TLS 1.2 / DTLS 1.2
  1218. */
  1219. #define MBEDTLS_SSL_PROTO_TLS1_2
  1220. /**
  1221. * \def MBEDTLS_SSL_PROTO_DTLS
  1222. *
  1223. * Enable support for DTLS (all available versions).
  1224. *
  1225. * Enable this and MBEDTLS_SSL_PROTO_TLS1_1 to enable DTLS 1.0,
  1226. * and/or this and MBEDTLS_SSL_PROTO_TLS1_2 to enable DTLS 1.2.
  1227. *
  1228. * Requires: MBEDTLS_SSL_PROTO_TLS1_1
  1229. * or MBEDTLS_SSL_PROTO_TLS1_2
  1230. *
  1231. * Comment this macro to disable support for DTLS
  1232. */
  1233. #define MBEDTLS_SSL_PROTO_DTLS
  1234. /**
  1235. * \def MBEDTLS_SSL_ALPN
  1236. *
  1237. * Enable support for RFC 7301 Application Layer Protocol Negotiation.
  1238. *
  1239. * Comment this macro to disable support for ALPN.
  1240. */
  1241. #define MBEDTLS_SSL_ALPN
  1242. /**
  1243. * \def MBEDTLS_SSL_DTLS_ANTI_REPLAY
  1244. *
  1245. * Enable support for the anti-replay mechanism in DTLS.
  1246. *
  1247. * Requires: MBEDTLS_SSL_TLS_C
  1248. * MBEDTLS_SSL_PROTO_DTLS
  1249. *
  1250. * \warning Disabling this is often a security risk!
  1251. * See mbedtls_ssl_conf_dtls_anti_replay() for details.
  1252. *
  1253. * Comment this to disable anti-replay in DTLS.
  1254. */
  1255. #define MBEDTLS_SSL_DTLS_ANTI_REPLAY
  1256. /**
  1257. * \def MBEDTLS_SSL_DTLS_HELLO_VERIFY
  1258. *
  1259. * Enable support for HelloVerifyRequest on DTLS servers.
  1260. *
  1261. * This feature is highly recommended to prevent DTLS servers being used as
  1262. * amplifiers in DoS attacks against other hosts. It should always be enabled
  1263. * unless you know for sure amplification cannot be a problem in the
  1264. * environment in which your server operates.
  1265. *
  1266. * \warning Disabling this can ba a security risk! (see above)
  1267. *
  1268. * Requires: MBEDTLS_SSL_PROTO_DTLS
  1269. *
  1270. * Comment this to disable support for HelloVerifyRequest.
  1271. */
  1272. #define MBEDTLS_SSL_DTLS_HELLO_VERIFY
  1273. /**
  1274. * \def MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
  1275. *
  1276. * Enable server-side support for clients that reconnect from the same port.
  1277. *
  1278. * Some clients unexpectedly close the connection and try to reconnect using the
  1279. * same source port. This needs special support from the server to handle the
  1280. * new connection securely, as described in section 4.2.8 of RFC 6347. This
  1281. * flag enables that support.
  1282. *
  1283. * Requires: MBEDTLS_SSL_DTLS_HELLO_VERIFY
  1284. *
  1285. * Comment this to disable support for clients reusing the source port.
  1286. */
  1287. #define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
  1288. /**
  1289. * \def MBEDTLS_SSL_DTLS_BADMAC_LIMIT
  1290. *
  1291. * Enable support for a limit of records with bad MAC.
  1292. *
  1293. * See mbedtls_ssl_conf_dtls_badmac_limit().
  1294. *
  1295. * Requires: MBEDTLS_SSL_PROTO_DTLS
  1296. */
  1297. #define MBEDTLS_SSL_DTLS_BADMAC_LIMIT
  1298. /**
  1299. * \def MBEDTLS_SSL_SESSION_TICKETS
  1300. *
  1301. * Enable support for RFC 5077 session tickets in SSL.
  1302. * Client-side, provides full support for session tickets (maintainance of a
  1303. * session store remains the responsibility of the application, though).
  1304. * Server-side, you also need to provide callbacks for writing and parsing
  1305. * tickets, including authenticated encryption and key management. Example
  1306. * callbacks are provided by MBEDTLS_SSL_TICKET_C.
  1307. *
  1308. * Comment this macro to disable support for SSL session tickets
  1309. */
  1310. #define MBEDTLS_SSL_SESSION_TICKETS
  1311. /**
  1312. * \def MBEDTLS_SSL_EXPORT_KEYS
  1313. *
  1314. * Enable support for exporting key block and master secret.
  1315. * This is required for certain users of TLS, e.g. EAP-TLS.
  1316. *
  1317. * Comment this macro to disable support for key export
  1318. */
  1319. #define MBEDTLS_SSL_EXPORT_KEYS
  1320. /**
  1321. * \def MBEDTLS_SSL_SERVER_NAME_INDICATION
  1322. *
  1323. * Enable support for RFC 6066 server name indication (SNI) in SSL.
  1324. *
  1325. * Requires: MBEDTLS_X509_CRT_PARSE_C
  1326. *
  1327. * Comment this macro to disable support for server name indication in SSL
  1328. */
  1329. #define MBEDTLS_SSL_SERVER_NAME_INDICATION
  1330. /**
  1331. * \def MBEDTLS_SSL_TRUNCATED_HMAC
  1332. *
  1333. * Enable support for RFC 6066 truncated HMAC in SSL.
  1334. *
  1335. * Comment this macro to disable support for truncated HMAC in SSL
  1336. */
  1337. #define MBEDTLS_SSL_TRUNCATED_HMAC
  1338. /**
  1339. * \def MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
  1340. *
  1341. * Fallback to old (pre-2.7), non-conforming implementation of the truncated
  1342. * HMAC extension which also truncates the HMAC key. Note that this option is
  1343. * only meant for a transitory upgrade period and is likely to be removed in
  1344. * a future version of the library.
  1345. *
  1346. * \warning The old implementation is non-compliant and has a security weakness
  1347. * (2^80 brute force attack on the HMAC key used for a single,
  1348. * uninterrupted connection). This should only be enabled temporarily
  1349. * when (1) the use of truncated HMAC is essential in order to save
  1350. * bandwidth, and (2) the peer is an Mbed TLS stack that doesn't use
  1351. * the fixed implementation yet (pre-2.7).
  1352. *
  1353. * \deprecated This option is deprecated and will likely be removed in a
  1354. * future version of Mbed TLS.
  1355. *
  1356. * Uncomment to fallback to old, non-compliant truncated HMAC implementation.
  1357. *
  1358. * Requires: MBEDTLS_SSL_TRUNCATED_HMAC
  1359. */
  1360. //#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT
  1361. /**
  1362. * \def MBEDTLS_THREADING_ALT
  1363. *
  1364. * Provide your own alternate threading implementation.
  1365. *
  1366. * Requires: MBEDTLS_THREADING_C
  1367. *
  1368. * Uncomment this to allow your own alternate threading implementation.
  1369. */
  1370. //#define MBEDTLS_THREADING_ALT
  1371. /**
  1372. * \def MBEDTLS_THREADING_PTHREAD
  1373. *
  1374. * Enable the pthread wrapper layer for the threading layer.
  1375. *
  1376. * Requires: MBEDTLS_THREADING_C
  1377. *
  1378. * Uncomment this to enable pthread mutexes.
  1379. */
  1380. //#define MBEDTLS_THREADING_PTHREAD
  1381. /**
  1382. * \def MBEDTLS_VERSION_FEATURES
  1383. *
  1384. * Allow run-time checking of compile-time enabled features. Thus allowing users
  1385. * to check at run-time if the library is for instance compiled with threading
  1386. * support via mbedtls_version_check_feature().
  1387. *
  1388. * Requires: MBEDTLS_VERSION_C
  1389. *
  1390. * Comment this to disable run-time checking and save ROM space
  1391. */
  1392. #define MBEDTLS_VERSION_FEATURES
  1393. /**
  1394. * \def MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
  1395. *
  1396. * If set, the X509 parser will not break-off when parsing an X509 certificate
  1397. * and encountering an extension in a v1 or v2 certificate.
  1398. *
  1399. * Uncomment to prevent an error.
  1400. */
  1401. //#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
  1402. /**
  1403. * \def MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
  1404. *
  1405. * If set, the X509 parser will not break-off when parsing an X509 certificate
  1406. * and encountering an unknown critical extension.
  1407. *
  1408. * \warning Depending on your PKI use, enabling this can be a security risk!
  1409. *
  1410. * Uncomment to prevent an error.
  1411. */
  1412. //#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
  1413. /**
  1414. * \def MBEDTLS_X509_CHECK_KEY_USAGE
  1415. *
  1416. * Enable verification of the keyUsage extension (CA and leaf certificates).
  1417. *
  1418. * Disabling this avoids problems with mis-issued and/or misused
  1419. * (intermediate) CA and leaf certificates.
  1420. *
  1421. * \warning Depending on your PKI use, disabling this can be a security risk!
  1422. *
  1423. * Comment to skip keyUsage checking for both CA and leaf certificates.
  1424. */
  1425. #define MBEDTLS_X509_CHECK_KEY_USAGE
  1426. /**
  1427. * \def MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
  1428. *
  1429. * Enable verification of the extendedKeyUsage extension (leaf certificates).
  1430. *
  1431. * Disabling this avoids problems with mis-issued and/or misused certificates.
  1432. *
  1433. * \warning Depending on your PKI use, disabling this can be a security risk!
  1434. *
  1435. * Comment to skip extendedKeyUsage checking for certificates.
  1436. */
  1437. #define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
  1438. /**
  1439. * \def MBEDTLS_X509_RSASSA_PSS_SUPPORT
  1440. *
  1441. * Enable parsing and verification of X.509 certificates, CRLs and CSRS
  1442. * signed with RSASSA-PSS (aka PKCS#1 v2.1).
  1443. *
  1444. * Comment this macro to disallow using RSASSA-PSS in certificates.
  1445. */
  1446. #define MBEDTLS_X509_RSASSA_PSS_SUPPORT
  1447. /**
  1448. * \def MBEDTLS_ZLIB_SUPPORT
  1449. *
  1450. * If set, the SSL/TLS module uses ZLIB to support compression and
  1451. * decompression of packet data.
  1452. *
  1453. * \warning TLS-level compression MAY REDUCE SECURITY! See for example the
  1454. * CRIME attack. Before enabling this option, you should examine with care if
  1455. * CRIME or similar exploits may be a applicable to your use case.
  1456. *
  1457. * \note Currently compression can't be used with DTLS.
  1458. *
  1459. * \deprecated This feature is deprecated and will be removed
  1460. * in the next major revision of the library.
  1461. *
  1462. * Used in: library/ssl_tls.c
  1463. * library/ssl_cli.c
  1464. * library/ssl_srv.c
  1465. *
  1466. * This feature requires zlib library and headers to be present.
  1467. *
  1468. * Uncomment to enable use of ZLIB
  1469. */
  1470. //#define MBEDTLS_ZLIB_SUPPORT
  1471. /* \} name SECTION: mbed TLS feature support */
  1472. /**
  1473. * \name SECTION: mbed TLS modules
  1474. *
  1475. * This section enables or disables entire modules in mbed TLS
  1476. * \{
  1477. */
  1478. /**
  1479. * \def MBEDTLS_AESNI_C
  1480. *
  1481. * Enable AES-NI support on x86-64.
  1482. *
  1483. * Module: library/aesni.c
  1484. * Caller: library/aes.c
  1485. *
  1486. * Requires: MBEDTLS_HAVE_ASM
  1487. *
  1488. * This modules adds support for the AES-NI instructions on x86-64
  1489. */
  1490. #define MBEDTLS_AESNI_C
  1491. /**
  1492. * \def MBEDTLS_AES_C
  1493. *
  1494. * Enable the AES block cipher.
  1495. *
  1496. * Module: library/aes.c
  1497. * Caller: library/ssl_tls.c
  1498. * library/pem.c
  1499. * library/ctr_drbg.c
  1500. *
  1501. * This module enables the following ciphersuites (if other requisites are
  1502. * enabled as well):
  1503. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
  1504. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
  1505. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
  1506. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
  1507. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
  1508. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
  1509. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
  1510. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
  1511. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
  1512. * MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
  1513. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
  1514. * MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
  1515. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
  1516. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
  1517. * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
  1518. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
  1519. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
  1520. * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
  1521. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
  1522. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
  1523. * MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA
  1524. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
  1525. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  1526. * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
  1527. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
  1528. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
  1529. * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
  1530. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
  1531. * MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
  1532. * MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  1533. * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
  1534. * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
  1535. * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
  1536. * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
  1537. * MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA
  1538. * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
  1539. * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
  1540. * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
  1541. * MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
  1542. * MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA
  1543. * MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384
  1544. * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256
  1545. * MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA
  1546. * MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256
  1547. * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256
  1548. * MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA
  1549. * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
  1550. * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
  1551. * MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA
  1552. * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
  1553. * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
  1554. * MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA
  1555. * MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384
  1556. * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384
  1557. * MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA
  1558. * MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256
  1559. * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256
  1560. * MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA
  1561. *
  1562. * PEM_PARSE uses AES for decrypting encrypted keys.
  1563. */
  1564. #define MBEDTLS_AES_C
  1565. /**
  1566. * \def MBEDTLS_ARC4_C
  1567. *
  1568. * Enable the ARCFOUR stream cipher.
  1569. *
  1570. * Module: library/arc4.c
  1571. * Caller: library/ssl_tls.c
  1572. *
  1573. * This module enables the following ciphersuites (if other requisites are
  1574. * enabled as well):
  1575. * MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA
  1576. * MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA
  1577. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
  1578. * MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA
  1579. * MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA
  1580. * MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA
  1581. * MBEDTLS_TLS_RSA_WITH_RC4_128_SHA
  1582. * MBEDTLS_TLS_RSA_WITH_RC4_128_MD5
  1583. * MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA
  1584. * MBEDTLS_TLS_PSK_WITH_RC4_128_SHA
  1585. *
  1586. * \warning ARC4 is considered a weak cipher and its use constitutes a
  1587. * security risk. If possible, we recommend avoidng dependencies on
  1588. * it, and considering stronger ciphers instead.
  1589. *
  1590. */
  1591. #define MBEDTLS_ARC4_C
  1592. /**
  1593. * \def MBEDTLS_ASN1_PARSE_C
  1594. *
  1595. * Enable the generic ASN1 parser.
  1596. *
  1597. * Module: library/asn1.c
  1598. * Caller: library/x509.c
  1599. * library/dhm.c
  1600. * library/pkcs12.c
  1601. * library/pkcs5.c
  1602. * library/pkparse.c
  1603. */
  1604. #define MBEDTLS_ASN1_PARSE_C
  1605. /**
  1606. * \def MBEDTLS_ASN1_WRITE_C
  1607. *
  1608. * Enable the generic ASN1 writer.
  1609. *
  1610. * Module: library/asn1write.c
  1611. * Caller: library/ecdsa.c
  1612. * library/pkwrite.c
  1613. * library/x509_create.c
  1614. * library/x509write_crt.c
  1615. * library/x509write_csr.c
  1616. */
  1617. #define MBEDTLS_ASN1_WRITE_C
  1618. /**
  1619. * \def MBEDTLS_BASE64_C
  1620. *
  1621. * Enable the Base64 module.
  1622. *
  1623. * Module: library/base64.c
  1624. * Caller: library/pem.c
  1625. *
  1626. * This module is required for PEM support (required by X.509).
  1627. */
  1628. #define MBEDTLS_BASE64_C
  1629. /**
  1630. * \def MBEDTLS_BIGNUM_C
  1631. *
  1632. * Enable the multi-precision integer library.
  1633. *
  1634. * Module: library/bignum.c
  1635. * Caller: library/dhm.c
  1636. * library/ecp.c
  1637. * library/ecdsa.c
  1638. * library/rsa.c
  1639. * library/rsa_internal.c
  1640. * library/ssl_tls.c
  1641. *
  1642. * This module is required for RSA, DHM and ECC (ECDH, ECDSA) support.
  1643. */
  1644. #define MBEDTLS_BIGNUM_C
  1645. /**
  1646. * \def MBEDTLS_BLOWFISH_C
  1647. *
  1648. * Enable the Blowfish block cipher.
  1649. *
  1650. * Module: library/blowfish.c
  1651. */
  1652. #define MBEDTLS_BLOWFISH_C
  1653. /**
  1654. * \def MBEDTLS_CAMELLIA_C
  1655. *
  1656. * Enable the Camellia block cipher.
  1657. *
  1658. * Module: library/camellia.c
  1659. * Caller: library/ssl_tls.c
  1660. *
  1661. * This module enables the following ciphersuites (if other requisites are
  1662. * enabled as well):
  1663. * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
  1664. * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
  1665. * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256
  1666. * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384
  1667. * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
  1668. * MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
  1669. * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256
  1670. * MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384
  1671. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384
  1672. * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
  1673. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384
  1674. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384
  1675. * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384
  1676. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
  1677. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
  1678. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256
  1679. * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
  1680. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256
  1681. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256
  1682. * MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
  1683. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
  1684. * MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
  1685. * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384
  1686. * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
  1687. * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384
  1688. * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256
  1689. * MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
  1690. * MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256
  1691. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384
  1692. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
  1693. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
  1694. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256
  1695. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
  1696. * MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
  1697. * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384
  1698. * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384
  1699. * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256
  1700. * MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256
  1701. * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384
  1702. * MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384
  1703. * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
  1704. * MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
  1705. */
  1706. #define MBEDTLS_CAMELLIA_C
  1707. /**
  1708. * \def MBEDTLS_CCM_C
  1709. *
  1710. * Enable the Counter with CBC-MAC (CCM) mode for 128-bit block cipher.
  1711. *
  1712. * Module: library/ccm.c
  1713. *
  1714. * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C
  1715. *
  1716. * This module enables the AES-CCM ciphersuites, if other requisites are
  1717. * enabled as well.
  1718. */
  1719. #define MBEDTLS_CCM_C
  1720. /**
  1721. * \def MBEDTLS_CERTS_C
  1722. *
  1723. * Enable the test certificates.
  1724. *
  1725. * Module: library/certs.c
  1726. * Caller:
  1727. *
  1728. * This module is used for testing (ssl_client/server).
  1729. */
  1730. #define MBEDTLS_CERTS_C
  1731. /**
  1732. * \def MBEDTLS_CIPHER_C
  1733. *
  1734. * Enable the generic cipher layer.
  1735. *
  1736. * Module: library/cipher.c
  1737. * Caller: library/ssl_tls.c
  1738. *
  1739. * Uncomment to enable generic cipher wrappers.
  1740. */
  1741. #define MBEDTLS_CIPHER_C
  1742. /**
  1743. * \def MBEDTLS_CMAC_C
  1744. *
  1745. * Enable the CMAC (Cipher-based Message Authentication Code) mode for block
  1746. * ciphers.
  1747. *
  1748. * Module: library/cmac.c
  1749. *
  1750. * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
  1751. *
  1752. */
  1753. //#define MBEDTLS_CMAC_C
  1754. /**
  1755. * \def MBEDTLS_CTR_DRBG_C
  1756. *
  1757. * Enable the CTR_DRBG AES-256-based random generator.
  1758. *
  1759. * Module: library/ctr_drbg.c
  1760. * Caller:
  1761. *
  1762. * Requires: MBEDTLS_AES_C
  1763. *
  1764. * This module provides the CTR_DRBG AES-256 random number generator.
  1765. */
  1766. #define MBEDTLS_CTR_DRBG_C
  1767. /**
  1768. * \def MBEDTLS_DEBUG_C
  1769. *
  1770. * Enable the debug functions.
  1771. *
  1772. * Module: library/debug.c
  1773. * Caller: library/ssl_cli.c
  1774. * library/ssl_srv.c
  1775. * library/ssl_tls.c
  1776. *
  1777. * This module provides debugging functions.
  1778. */
  1779. #define MBEDTLS_DEBUG_C
  1780. /**
  1781. * \def MBEDTLS_DES_C
  1782. *
  1783. * Enable the DES block cipher.
  1784. *
  1785. * Module: library/des.c
  1786. * Caller: library/pem.c
  1787. * library/ssl_tls.c
  1788. *
  1789. * This module enables the following ciphersuites (if other requisites are
  1790. * enabled as well):
  1791. * MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
  1792. * MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
  1793. * MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
  1794. * MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
  1795. * MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
  1796. * MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
  1797. * MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
  1798. * MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA
  1799. * MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
  1800. * MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA
  1801. *
  1802. * PEM_PARSE uses DES/3DES for decrypting encrypted keys.
  1803. *
  1804. * \warning DES is considered a weak cipher and its use constitutes a
  1805. * security risk. We recommend considering stronger ciphers instead.
  1806. */
  1807. #define MBEDTLS_DES_C
  1808. /**
  1809. * \def MBEDTLS_DHM_C
  1810. *
  1811. * Enable the Diffie-Hellman-Merkle module.
  1812. *
  1813. * Module: library/dhm.c
  1814. * Caller: library/ssl_cli.c
  1815. * library/ssl_srv.c
  1816. *
  1817. * This module is used by the following key exchanges:
  1818. * DHE-RSA, DHE-PSK
  1819. *
  1820. * \warning Using DHE constitutes a security risk as it
  1821. * is not possible to validate custom DH parameters.
  1822. * If possible, it is recommended users should consider
  1823. * preferring other methods of key exchange.
  1824. * See dhm.h for more details.
  1825. *
  1826. */
  1827. #define MBEDTLS_DHM_C
  1828. /**
  1829. * \def MBEDTLS_ECDH_C
  1830. *
  1831. * Enable the elliptic curve Diffie-Hellman library.
  1832. *
  1833. * Module: library/ecdh.c
  1834. * Caller: library/ssl_cli.c
  1835. * library/ssl_srv.c
  1836. *
  1837. * This module is used by the following key exchanges:
  1838. * ECDHE-ECDSA, ECDHE-RSA, DHE-PSK
  1839. *
  1840. * Requires: MBEDTLS_ECP_C
  1841. */
  1842. #define MBEDTLS_ECDH_C
  1843. /**
  1844. * \def MBEDTLS_ECDSA_C
  1845. *
  1846. * Enable the elliptic curve DSA library.
  1847. *
  1848. * Module: library/ecdsa.c
  1849. * Caller:
  1850. *
  1851. * This module is used by the following key exchanges:
  1852. * ECDHE-ECDSA
  1853. *
  1854. * Requires: MBEDTLS_ECP_C, MBEDTLS_ASN1_WRITE_C, MBEDTLS_ASN1_PARSE_C
  1855. */
  1856. #define MBEDTLS_ECDSA_C
  1857. /**
  1858. * \def MBEDTLS_ECJPAKE_C
  1859. *
  1860. * Enable the elliptic curve J-PAKE library.
  1861. *
  1862. * \warning This is currently experimental. EC J-PAKE support is based on the
  1863. * Thread v1.0.0 specification; incompatible changes to the specification
  1864. * might still happen. For this reason, this is disabled by default.
  1865. *
  1866. * Module: library/ecjpake.c
  1867. * Caller:
  1868. *
  1869. * This module is used by the following key exchanges:
  1870. * ECJPAKE
  1871. *
  1872. * Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C
  1873. */
  1874. //#define MBEDTLS_ECJPAKE_C
  1875. /**
  1876. * \def MBEDTLS_ECP_C
  1877. *
  1878. * Enable the elliptic curve over GF(p) library.
  1879. *
  1880. * Module: library/ecp.c
  1881. * Caller: library/ecdh.c
  1882. * library/ecdsa.c
  1883. * library/ecjpake.c
  1884. *
  1885. * Requires: MBEDTLS_BIGNUM_C and at least one MBEDTLS_ECP_DP_XXX_ENABLED
  1886. */
  1887. #define MBEDTLS_ECP_C
  1888. /**
  1889. * \def MBEDTLS_ENTROPY_C
  1890. *
  1891. * Enable the platform-specific entropy code.
  1892. *
  1893. * Module: library/entropy.c
  1894. * Caller:
  1895. *
  1896. * Requires: MBEDTLS_SHA512_C or MBEDTLS_SHA256_C
  1897. *
  1898. * This module provides a generic entropy pool
  1899. */
  1900. #define MBEDTLS_ENTROPY_C
  1901. /**
  1902. * \def MBEDTLS_ERROR_C
  1903. *
  1904. * Enable error code to error string conversion.
  1905. *
  1906. * Module: library/error.c
  1907. * Caller:
  1908. *
  1909. * This module enables mbedtls_strerror().
  1910. */
  1911. #define MBEDTLS_ERROR_C
  1912. /**
  1913. * \def MBEDTLS_GCM_C
  1914. *
  1915. * Enable the Galois/Counter Mode (GCM) for AES.
  1916. *
  1917. * Module: library/gcm.c
  1918. *
  1919. * Requires: MBEDTLS_AES_C or MBEDTLS_CAMELLIA_C
  1920. *
  1921. * This module enables the AES-GCM and CAMELLIA-GCM ciphersuites, if other
  1922. * requisites are enabled as well.
  1923. */
  1924. #define MBEDTLS_GCM_C
  1925. /**
  1926. * \def MBEDTLS_HAVEGE_C
  1927. *
  1928. * Enable the HAVEGE random generator.
  1929. *
  1930. * Warning: the HAVEGE random generator is not suitable for virtualized
  1931. * environments
  1932. *
  1933. * Warning: the HAVEGE random generator is dependent on timing and specific
  1934. * processor traits. It is therefore not advised to use HAVEGE as
  1935. * your applications primary random generator or primary entropy pool
  1936. * input. As a secondary input to your entropy pool, it IS able add
  1937. * the (limited) extra entropy it provides.
  1938. *
  1939. * Module: library/havege.c
  1940. * Caller:
  1941. *
  1942. * Requires: MBEDTLS_TIMING_C
  1943. *
  1944. * Uncomment to enable the HAVEGE random generator.
  1945. */
  1946. //#define MBEDTLS_HAVEGE_C
  1947. /**
  1948. * \def MBEDTLS_HMAC_DRBG_C
  1949. *
  1950. * Enable the HMAC_DRBG random generator.
  1951. *
  1952. * Module: library/hmac_drbg.c
  1953. * Caller:
  1954. *
  1955. * Requires: MBEDTLS_MD_C
  1956. *
  1957. * Uncomment to enable the HMAC_DRBG random number geerator.
  1958. */
  1959. #define MBEDTLS_HMAC_DRBG_C
  1960. /**
  1961. * \def MBEDTLS_MD_C
  1962. *
  1963. * Enable the generic message digest layer.
  1964. *
  1965. * Module: library/md.c
  1966. * Caller:
  1967. *
  1968. * Uncomment to enable generic message digest wrappers.
  1969. */
  1970. #define MBEDTLS_MD_C
  1971. /**
  1972. * \def MBEDTLS_MD2_C
  1973. *
  1974. * Enable the MD2 hash algorithm.
  1975. *
  1976. * Module: library/md2.c
  1977. * Caller:
  1978. *
  1979. * Uncomment to enable support for (rare) MD2-signed X.509 certs.
  1980. *
  1981. * \warning MD2 is considered a weak message digest and its use constitutes a
  1982. * security risk. If possible, we recommend avoiding dependencies on
  1983. * it, and considering stronger message digests instead.
  1984. *
  1985. */
  1986. //#define MBEDTLS_MD2_C
  1987. /**
  1988. * \def MBEDTLS_MD4_C
  1989. *
  1990. * Enable the MD4 hash algorithm.
  1991. *
  1992. * Module: library/md4.c
  1993. * Caller:
  1994. *
  1995. * Uncomment to enable support for (rare) MD4-signed X.509 certs.
  1996. *
  1997. * \warning MD4 is considered a weak message digest and its use constitutes a
  1998. * security risk. If possible, we recommend avoiding dependencies on
  1999. * it, and considering stronger message digests instead.
  2000. *
  2001. */
  2002. //#define MBEDTLS_MD4_C
  2003. /**
  2004. * \def MBEDTLS_MD5_C
  2005. *
  2006. * Enable the MD5 hash algorithm.
  2007. *
  2008. * Module: library/md5.c
  2009. * Caller: library/md.c
  2010. * library/pem.c
  2011. * library/ssl_tls.c
  2012. *
  2013. * This module is required for SSL/TLS up to version 1.1, and for TLS 1.2
  2014. * depending on the handshake parameters. Further, it is used for checking
  2015. * MD5-signed certificates, and for PBKDF1 when decrypting PEM-encoded
  2016. * encrypted keys.
  2017. *
  2018. * \warning MD5 is considered a weak message digest and its use constitutes a
  2019. * security risk. If possible, we recommend avoiding dependencies on
  2020. * it, and considering stronger message digests instead.
  2021. *
  2022. */
  2023. #define MBEDTLS_MD5_C
  2024. /**
  2025. * \def MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2026. *
  2027. * Enable the buffer allocator implementation that makes use of a (stack)
  2028. * based buffer to 'allocate' dynamic memory. (replaces calloc() and free()
  2029. * calls)
  2030. *
  2031. * Module: library/memory_buffer_alloc.c
  2032. *
  2033. * Requires: MBEDTLS_PLATFORM_C
  2034. * MBEDTLS_PLATFORM_MEMORY (to use it within mbed TLS)
  2035. *
  2036. * Enable this module to enable the buffer memory allocator.
  2037. */
  2038. //#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2039. /**
  2040. * \def MBEDTLS_NET_C
  2041. *
  2042. * Enable the TCP and UDP over IPv6/IPv4 networking routines.
  2043. *
  2044. * \note This module only works on POSIX/Unix (including Linux, BSD and OS X)
  2045. * and Windows. For other platforms, you'll want to disable it, and write your
  2046. * own networking callbacks to be passed to \c mbedtls_ssl_set_bio().
  2047. *
  2048. * \note See also our Knowledge Base article about porting to a new
  2049. * environment:
  2050. * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
  2051. *
  2052. * Module: library/net_sockets.c
  2053. *
  2054. * This module provides networking routines.
  2055. */
  2056. #define MBEDTLS_NET_C
  2057. /**
  2058. * \def MBEDTLS_OID_C
  2059. *
  2060. * Enable the OID database.
  2061. *
  2062. * Module: library/oid.c
  2063. * Caller: library/asn1write.c
  2064. * library/pkcs5.c
  2065. * library/pkparse.c
  2066. * library/pkwrite.c
  2067. * library/rsa.c
  2068. * library/x509.c
  2069. * library/x509_create.c
  2070. * library/x509_crl.c
  2071. * library/x509_crt.c
  2072. * library/x509_csr.c
  2073. * library/x509write_crt.c
  2074. * library/x509write_csr.c
  2075. *
  2076. * This modules translates between OIDs and internal values.
  2077. */
  2078. #define MBEDTLS_OID_C
  2079. /**
  2080. * \def MBEDTLS_PADLOCK_C
  2081. *
  2082. * Enable VIA Padlock support on x86.
  2083. *
  2084. * Module: library/padlock.c
  2085. * Caller: library/aes.c
  2086. *
  2087. * Requires: MBEDTLS_HAVE_ASM
  2088. *
  2089. * This modules adds support for the VIA PadLock on x86.
  2090. */
  2091. #define MBEDTLS_PADLOCK_C
  2092. /**
  2093. * \def MBEDTLS_PEM_PARSE_C
  2094. *
  2095. * Enable PEM decoding / parsing.
  2096. *
  2097. * Module: library/pem.c
  2098. * Caller: library/dhm.c
  2099. * library/pkparse.c
  2100. * library/x509_crl.c
  2101. * library/x509_crt.c
  2102. * library/x509_csr.c
  2103. *
  2104. * Requires: MBEDTLS_BASE64_C
  2105. *
  2106. * This modules adds support for decoding / parsing PEM files.
  2107. */
  2108. #define MBEDTLS_PEM_PARSE_C
  2109. /**
  2110. * \def MBEDTLS_PEM_WRITE_C
  2111. *
  2112. * Enable PEM encoding / writing.
  2113. *
  2114. * Module: library/pem.c
  2115. * Caller: library/pkwrite.c
  2116. * library/x509write_crt.c
  2117. * library/x509write_csr.c
  2118. *
  2119. * Requires: MBEDTLS_BASE64_C
  2120. *
  2121. * This modules adds support for encoding / writing PEM files.
  2122. */
  2123. #define MBEDTLS_PEM_WRITE_C
  2124. /**
  2125. * \def MBEDTLS_PK_C
  2126. *
  2127. * Enable the generic public (asymetric) key layer.
  2128. *
  2129. * Module: library/pk.c
  2130. * Caller: library/ssl_tls.c
  2131. * library/ssl_cli.c
  2132. * library/ssl_srv.c
  2133. *
  2134. * Requires: MBEDTLS_RSA_C or MBEDTLS_ECP_C
  2135. *
  2136. * Uncomment to enable generic public key wrappers.
  2137. */
  2138. #define MBEDTLS_PK_C
  2139. /**
  2140. * \def MBEDTLS_PK_PARSE_C
  2141. *
  2142. * Enable the generic public (asymetric) key parser.
  2143. *
  2144. * Module: library/pkparse.c
  2145. * Caller: library/x509_crt.c
  2146. * library/x509_csr.c
  2147. *
  2148. * Requires: MBEDTLS_PK_C
  2149. *
  2150. * Uncomment to enable generic public key parse functions.
  2151. */
  2152. #define MBEDTLS_PK_PARSE_C
  2153. /**
  2154. * \def MBEDTLS_PK_WRITE_C
  2155. *
  2156. * Enable the generic public (asymetric) key writer.
  2157. *
  2158. * Module: library/pkwrite.c
  2159. * Caller: library/x509write.c
  2160. *
  2161. * Requires: MBEDTLS_PK_C
  2162. *
  2163. * Uncomment to enable generic public key write functions.
  2164. */
  2165. #define MBEDTLS_PK_WRITE_C
  2166. /**
  2167. * \def MBEDTLS_PKCS5_C
  2168. *
  2169. * Enable PKCS#5 functions.
  2170. *
  2171. * Module: library/pkcs5.c
  2172. *
  2173. * Requires: MBEDTLS_MD_C
  2174. *
  2175. * This module adds support for the PKCS#5 functions.
  2176. */
  2177. #define MBEDTLS_PKCS5_C
  2178. /**
  2179. * \def MBEDTLS_PKCS11_C
  2180. *
  2181. * Enable wrapper for PKCS#11 smartcard support.
  2182. *
  2183. * Module: library/pkcs11.c
  2184. * Caller: library/pk.c
  2185. *
  2186. * Requires: MBEDTLS_PK_C
  2187. *
  2188. * This module enables SSL/TLS PKCS #11 smartcard support.
  2189. * Requires the presence of the PKCS#11 helper library (libpkcs11-helper)
  2190. */
  2191. //#define MBEDTLS_PKCS11_C
  2192. /**
  2193. * \def MBEDTLS_PKCS12_C
  2194. *
  2195. * Enable PKCS#12 PBE functions.
  2196. * Adds algorithms for parsing PKCS#8 encrypted private keys
  2197. *
  2198. * Module: library/pkcs12.c
  2199. * Caller: library/pkparse.c
  2200. *
  2201. * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_CIPHER_C, MBEDTLS_MD_C
  2202. * Can use: MBEDTLS_ARC4_C
  2203. *
  2204. * This module enables PKCS#12 functions.
  2205. */
  2206. #define MBEDTLS_PKCS12_C
  2207. /**
  2208. * \def MBEDTLS_PLATFORM_C
  2209. *
  2210. * Enable the platform abstraction layer that allows you to re-assign
  2211. * functions like calloc(), free(), snprintf(), printf(), fprintf(), exit().
  2212. *
  2213. * Enabling MBEDTLS_PLATFORM_C enables to use of MBEDTLS_PLATFORM_XXX_ALT
  2214. * or MBEDTLS_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
  2215. * above to be specified at runtime or compile time respectively.
  2216. *
  2217. * \note This abstraction layer must be enabled on Windows (including MSYS2)
  2218. * as other module rely on it for a fixed snprintf implementation.
  2219. *
  2220. * Module: library/platform.c
  2221. * Caller: Most other .c files
  2222. *
  2223. * This module enables abstraction of common (libc) functions.
  2224. */
  2225. #define MBEDTLS_PLATFORM_C
  2226. /**
  2227. * \def MBEDTLS_RIPEMD160_C
  2228. *
  2229. * Enable the RIPEMD-160 hash algorithm.
  2230. *
  2231. * Module: library/ripemd160.c
  2232. * Caller: library/md.c
  2233. *
  2234. */
  2235. #define MBEDTLS_RIPEMD160_C
  2236. /**
  2237. * \def MBEDTLS_RSA_C
  2238. *
  2239. * Enable the RSA public-key cryptosystem.
  2240. *
  2241. * Module: library/rsa.c
  2242. * library/rsa_internal.c
  2243. * Caller: library/ssl_cli.c
  2244. * library/ssl_srv.c
  2245. * library/ssl_tls.c
  2246. * library/x509.c
  2247. *
  2248. * This module is used by the following key exchanges:
  2249. * RSA, DHE-RSA, ECDHE-RSA, RSA-PSK
  2250. *
  2251. * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C
  2252. */
  2253. #define MBEDTLS_RSA_C
  2254. /**
  2255. * \def MBEDTLS_SHA1_C
  2256. *
  2257. * Enable the SHA1 cryptographic hash algorithm.
  2258. *
  2259. * Module: library/sha1.c
  2260. * Caller: library/md.c
  2261. * library/ssl_cli.c
  2262. * library/ssl_srv.c
  2263. * library/ssl_tls.c
  2264. * library/x509write_crt.c
  2265. *
  2266. * This module is required for SSL/TLS up to version 1.1, for TLS 1.2
  2267. * depending on the handshake parameters, and for SHA1-signed certificates.
  2268. *
  2269. * \warning SHA-1 is considered a weak message digest and its use constitutes
  2270. * a security risk. If possible, we recommend avoiding dependencies
  2271. * on it, and considering stronger message digests instead.
  2272. *
  2273. */
  2274. #define MBEDTLS_SHA1_C
  2275. /**
  2276. * \def MBEDTLS_SHA256_C
  2277. *
  2278. * Enable the SHA-224 and SHA-256 cryptographic hash algorithms.
  2279. *
  2280. * Module: library/sha256.c
  2281. * Caller: library/entropy.c
  2282. * library/md.c
  2283. * library/ssl_cli.c
  2284. * library/ssl_srv.c
  2285. * library/ssl_tls.c
  2286. *
  2287. * This module adds support for SHA-224 and SHA-256.
  2288. * This module is required for the SSL/TLS 1.2 PRF function.
  2289. */
  2290. #define MBEDTLS_SHA256_C
  2291. /**
  2292. * \def MBEDTLS_SHA512_C
  2293. *
  2294. * Enable the SHA-384 and SHA-512 cryptographic hash algorithms.
  2295. *
  2296. * Module: library/sha512.c
  2297. * Caller: library/entropy.c
  2298. * library/md.c
  2299. * library/ssl_cli.c
  2300. * library/ssl_srv.c
  2301. *
  2302. * This module adds support for SHA-384 and SHA-512.
  2303. */
  2304. #define MBEDTLS_SHA512_C
  2305. /**
  2306. * \def MBEDTLS_SSL_CACHE_C
  2307. *
  2308. * Enable simple SSL cache implementation.
  2309. *
  2310. * Module: library/ssl_cache.c
  2311. * Caller:
  2312. *
  2313. * Requires: MBEDTLS_SSL_CACHE_C
  2314. */
  2315. #define MBEDTLS_SSL_CACHE_C
  2316. /**
  2317. * \def MBEDTLS_SSL_COOKIE_C
  2318. *
  2319. * Enable basic implementation of DTLS cookies for hello verification.
  2320. *
  2321. * Module: library/ssl_cookie.c
  2322. * Caller:
  2323. */
  2324. #define MBEDTLS_SSL_COOKIE_C
  2325. /**
  2326. * \def MBEDTLS_SSL_TICKET_C
  2327. *
  2328. * Enable an implementation of TLS server-side callbacks for session tickets.
  2329. *
  2330. * Module: library/ssl_ticket.c
  2331. * Caller:
  2332. *
  2333. * Requires: MBEDTLS_CIPHER_C
  2334. */
  2335. #define MBEDTLS_SSL_TICKET_C
  2336. /**
  2337. * \def MBEDTLS_SSL_CLI_C
  2338. *
  2339. * Enable the SSL/TLS client code.
  2340. *
  2341. * Module: library/ssl_cli.c
  2342. * Caller:
  2343. *
  2344. * Requires: MBEDTLS_SSL_TLS_C
  2345. *
  2346. * This module is required for SSL/TLS client support.
  2347. */
  2348. #define MBEDTLS_SSL_CLI_C
  2349. /**
  2350. * \def MBEDTLS_SSL_SRV_C
  2351. *
  2352. * Enable the SSL/TLS server code.
  2353. *
  2354. * Module: library/ssl_srv.c
  2355. * Caller:
  2356. *
  2357. * Requires: MBEDTLS_SSL_TLS_C
  2358. *
  2359. * This module is required for SSL/TLS server support.
  2360. */
  2361. #define MBEDTLS_SSL_SRV_C
  2362. /**
  2363. * \def MBEDTLS_SSL_TLS_C
  2364. *
  2365. * Enable the generic SSL/TLS code.
  2366. *
  2367. * Module: library/ssl_tls.c
  2368. * Caller: library/ssl_cli.c
  2369. * library/ssl_srv.c
  2370. *
  2371. * Requires: MBEDTLS_CIPHER_C, MBEDTLS_MD_C
  2372. * and at least one of the MBEDTLS_SSL_PROTO_XXX defines
  2373. *
  2374. * This module is required for SSL/TLS.
  2375. */
  2376. #define MBEDTLS_SSL_TLS_C
  2377. /**
  2378. * \def MBEDTLS_THREADING_C
  2379. *
  2380. * Enable the threading abstraction layer.
  2381. * By default mbed TLS assumes it is used in a non-threaded environment or that
  2382. * contexts are not shared between threads. If you do intend to use contexts
  2383. * between threads, you will need to enable this layer to prevent race
  2384. * conditions. See also our Knowledge Base article about threading:
  2385. * https://tls.mbed.org/kb/development/thread-safety-and-multi-threading
  2386. *
  2387. * Module: library/threading.c
  2388. *
  2389. * This allows different threading implementations (self-implemented or
  2390. * provided).
  2391. *
  2392. * You will have to enable either MBEDTLS_THREADING_ALT or
  2393. * MBEDTLS_THREADING_PTHREAD.
  2394. *
  2395. * Enable this layer to allow use of mutexes within mbed TLS
  2396. */
  2397. //#define MBEDTLS_THREADING_C
  2398. /**
  2399. * \def MBEDTLS_TIMING_C
  2400. *
  2401. * Enable the semi-portable timing interface.
  2402. *
  2403. * \note The provided implementation only works on POSIX/Unix (including Linux,
  2404. * BSD and OS X) and Windows. On other platforms, you can either disable that
  2405. * module and provide your own implementations of the callbacks needed by
  2406. * \c mbedtls_ssl_set_timer_cb() for DTLS, or leave it enabled and provide
  2407. * your own implementation of the whole module by setting
  2408. * \c MBEDTLS_TIMING_ALT in the current file.
  2409. *
  2410. * \note See also our Knowledge Base article about porting to a new
  2411. * environment:
  2412. * https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS
  2413. *
  2414. * Module: library/timing.c
  2415. * Caller: library/havege.c
  2416. *
  2417. * This module is used by the HAVEGE random number generator.
  2418. */
  2419. #define MBEDTLS_TIMING_C
  2420. /**
  2421. * \def MBEDTLS_VERSION_C
  2422. *
  2423. * Enable run-time version information.
  2424. *
  2425. * Module: library/version.c
  2426. *
  2427. * This module provides run-time version information.
  2428. */
  2429. #define MBEDTLS_VERSION_C
  2430. /**
  2431. * \def MBEDTLS_X509_USE_C
  2432. *
  2433. * Enable X.509 core for using certificates.
  2434. *
  2435. * Module: library/x509.c
  2436. * Caller: library/x509_crl.c
  2437. * library/x509_crt.c
  2438. * library/x509_csr.c
  2439. *
  2440. * Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_BIGNUM_C, MBEDTLS_OID_C,
  2441. * MBEDTLS_PK_PARSE_C
  2442. *
  2443. * This module is required for the X.509 parsing modules.
  2444. */
  2445. #define MBEDTLS_X509_USE_C
  2446. /**
  2447. * \def MBEDTLS_X509_CRT_PARSE_C
  2448. *
  2449. * Enable X.509 certificate parsing.
  2450. *
  2451. * Module: library/x509_crt.c
  2452. * Caller: library/ssl_cli.c
  2453. * library/ssl_srv.c
  2454. * library/ssl_tls.c
  2455. *
  2456. * Requires: MBEDTLS_X509_USE_C
  2457. *
  2458. * This module is required for X.509 certificate parsing.
  2459. */
  2460. #define MBEDTLS_X509_CRT_PARSE_C
  2461. /**
  2462. * \def MBEDTLS_X509_CRL_PARSE_C
  2463. *
  2464. * Enable X.509 CRL parsing.
  2465. *
  2466. * Module: library/x509_crl.c
  2467. * Caller: library/x509_crt.c
  2468. *
  2469. * Requires: MBEDTLS_X509_USE_C
  2470. *
  2471. * This module is required for X.509 CRL parsing.
  2472. */
  2473. #define MBEDTLS_X509_CRL_PARSE_C
  2474. /**
  2475. * \def MBEDTLS_X509_CSR_PARSE_C
  2476. *
  2477. * Enable X.509 Certificate Signing Request (CSR) parsing.
  2478. *
  2479. * Module: library/x509_csr.c
  2480. * Caller: library/x509_crt_write.c
  2481. *
  2482. * Requires: MBEDTLS_X509_USE_C
  2483. *
  2484. * This module is used for reading X.509 certificate request.
  2485. */
  2486. #define MBEDTLS_X509_CSR_PARSE_C
  2487. /**
  2488. * \def MBEDTLS_X509_CREATE_C
  2489. *
  2490. * Enable X.509 core for creating certificates.
  2491. *
  2492. * Module: library/x509_create.c
  2493. *
  2494. * Requires: MBEDTLS_BIGNUM_C, MBEDTLS_OID_C, MBEDTLS_PK_WRITE_C
  2495. *
  2496. * This module is the basis for creating X.509 certificates and CSRs.
  2497. */
  2498. #define MBEDTLS_X509_CREATE_C
  2499. /**
  2500. * \def MBEDTLS_X509_CRT_WRITE_C
  2501. *
  2502. * Enable creating X.509 certificates.
  2503. *
  2504. * Module: library/x509_crt_write.c
  2505. *
  2506. * Requires: MBEDTLS_X509_CREATE_C
  2507. *
  2508. * This module is required for X.509 certificate creation.
  2509. */
  2510. #define MBEDTLS_X509_CRT_WRITE_C
  2511. /**
  2512. * \def MBEDTLS_X509_CSR_WRITE_C
  2513. *
  2514. * Enable creating X.509 Certificate Signing Requests (CSR).
  2515. *
  2516. * Module: library/x509_csr_write.c
  2517. *
  2518. * Requires: MBEDTLS_X509_CREATE_C
  2519. *
  2520. * This module is required for X.509 certificate request writing.
  2521. */
  2522. #define MBEDTLS_X509_CSR_WRITE_C
  2523. /**
  2524. * \def MBEDTLS_XTEA_C
  2525. *
  2526. * Enable the XTEA block cipher.
  2527. *
  2528. * Module: library/xtea.c
  2529. * Caller:
  2530. */
  2531. #define MBEDTLS_XTEA_C
  2532. /* \} name SECTION: mbed TLS modules */
  2533. /**
  2534. * \name SECTION: Module configuration options
  2535. *
  2536. * This section allows for the setting of module specific sizes and
  2537. * configuration options. The default values are already present in the
  2538. * relevant header files and should suffice for the regular use cases.
  2539. *
  2540. * Our advice is to enable options and change their values here
  2541. * only if you have a good reason and know the consequences.
  2542. *
  2543. * Please check the respective header file for documentation on these
  2544. * parameters (to prevent duplicate documentation).
  2545. * \{
  2546. */
  2547. /* MPI / BIGNUM options */
  2548. //#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */
  2549. //#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
  2550. /* CTR_DRBG options */
  2551. //#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */
  2552. //#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
  2553. //#define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
  2554. //#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
  2555. //#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
  2556. /* HMAC_DRBG options */
  2557. //#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
  2558. //#define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
  2559. //#define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
  2560. //#define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
  2561. /* ECP options */
  2562. //#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */
  2563. //#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */
  2564. //#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
  2565. /* Entropy options */
  2566. //#define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */
  2567. //#define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */
  2568. //#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Default minimum number of bytes required for the hardware entropy source mbedtls_hardware_poll() before entropy is released */
  2569. /* Memory buffer allocator options */
  2570. //#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
  2571. /* Platform options */
  2572. //#define MBEDTLS_PLATFORM_STD_MEM_HDR <stdlib.h> /**< Header to include if MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */
  2573. //#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be undefined */
  2574. //#define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, can be undefined */
  2575. //#define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit to use, can be undefined */
  2576. //#define MBEDTLS_PLATFORM_STD_TIME time /**< Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
  2577. //#define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined */
  2578. //#define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
  2579. /* Note: your snprintf must correclty zero-terminate the buffer! */
  2580. //#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */
  2581. //#define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value to use, can be undefined */
  2582. //#define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< Default exit value to use, can be undefined */
  2583. //#define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
  2584. //#define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
  2585. //#define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" /**< Seed file to read/write with default implementation */
  2586. /* To Use Function Macros MBEDTLS_PLATFORM_C must be enabled */
  2587. /* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */
  2588. //#define MBEDTLS_PLATFORM_CALLOC_MACRO calloc /**< Default allocator macro to use, can be undefined */
  2589. //#define MBEDTLS_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */
  2590. //#define MBEDTLS_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */
  2591. //#define MBEDTLS_PLATFORM_TIME_MACRO time /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
  2592. //#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t /**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */
  2593. //#define MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be undefined */
  2594. //#define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf macro to use, can be undefined */
  2595. /* Note: your snprintf must correclty zero-terminate the buffer! */
  2596. //#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, can be undefined */
  2597. //#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */
  2598. //#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */
  2599. /* SSL Cache options */
  2600. //#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */
  2601. //#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */
  2602. /* SSL options */
  2603. //#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Maxium fragment length in bytes, determines the size of each of the two internal I/O buffers */
  2604. //#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
  2605. //#define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */
  2606. //#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */
  2607. /**
  2608. * Complete list of ciphersuites to use, in order of preference.
  2609. *
  2610. * \warning No dependency checking is done on that field! This option can only
  2611. * be used to restrict the set of available ciphersuites. It is your
  2612. * responsibility to make sure the needed modules are active.
  2613. *
  2614. * Use this to save a few hundred bytes of ROM (default ordering of all
  2615. * available ciphersuites) and a few to a few hundred bytes of RAM.
  2616. *
  2617. * The value below is only an example, not the default.
  2618. */
  2619. //#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
  2620. /* X509 options */
  2621. //#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs in a verification chain. */
  2622. //#define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum length of a path/filename string in bytes including the null terminator character ('\0'). */
  2623. /**
  2624. * Allow SHA-1 in the default TLS configuration for certificate signing.
  2625. * Without this build-time option, SHA-1 support must be activated explicitly
  2626. * through mbedtls_ssl_conf_cert_profile. Turning on this option is not
  2627. * recommended because of it is possible to generate SHA-1 collisions, however
  2628. * this may be safe for legacy infrastructure where additional controls apply.
  2629. *
  2630. * \warning SHA-1 is considered a weak message digest and its use constitutes
  2631. * a security risk. If possible, we recommend avoiding dependencies
  2632. * on it, and considering stronger message digests instead.
  2633. *
  2634. */
  2635. // #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES
  2636. /**
  2637. * Allow SHA-1 in the default TLS configuration for TLS 1.2 handshake
  2638. * signature and ciphersuite selection. Without this build-time option, SHA-1
  2639. * support must be activated explicitly through mbedtls_ssl_conf_sig_hashes.
  2640. * The use of SHA-1 in TLS <= 1.1 and in HMAC-SHA-1 is always allowed by
  2641. * default. At the time of writing, there is no practical attack on the use
  2642. * of SHA-1 in handshake signatures, hence this option is turned on by default
  2643. * to preserve compatibility with existing peers, but the general
  2644. * warning applies nonetheless:
  2645. *
  2646. * \warning SHA-1 is considered a weak message digest and its use constitutes
  2647. * a security risk. If possible, we recommend avoiding dependencies
  2648. * on it, and considering stronger message digests instead.
  2649. *
  2650. */
  2651. #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE
  2652. /* \} name SECTION: Customisation configuration options */
  2653. /* Target and application specific configurations */
  2654. //#define YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE "mbedtls/target_config.h"
  2655. #if defined(TARGET_LIKE_MBED) && defined(YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE)
  2656. #include YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE
  2657. #endif
  2658. /*
  2659. * Allow user to override any previous default.
  2660. *
  2661. * Use two macro names for that, as:
  2662. * - with yotta the prefix YOTTA_CFG_ is forced
  2663. * - without yotta is looks weird to have a YOTTA prefix.
  2664. */
  2665. #if defined(YOTTA_CFG_MBEDTLS_USER_CONFIG_FILE)
  2666. #include YOTTA_CFG_MBEDTLS_USER_CONFIG_FILE
  2667. #elif defined(MBEDTLS_USER_CONFIG_FILE)
  2668. #include MBEDTLS_USER_CONFIG_FILE
  2669. #endif
  2670. #endif /* MBEDTLS_CONFIG_H */
  2671. /********* Start of file include/mbedtls/check_config.h ************/
  2672. /**
  2673. * \file check_config.h
  2674. *
  2675. * \brief Consistency checks for configuration options
  2676. */
  2677. /*
  2678. * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
  2679. * SPDX-License-Identifier: Apache-2.0
  2680. *
  2681. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  2682. * not use this file except in compliance with the License.
  2683. * You may obtain a copy of the License at
  2684. *
  2685. * http://www.apache.org/licenses/LICENSE-2.0
  2686. *
  2687. * Unless required by applicable law or agreed to in writing, software
  2688. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  2689. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2690. * See the License for the specific language governing permissions and
  2691. * limitations under the License.
  2692. *
  2693. * This file is part of mbed TLS (https://tls.mbed.org)
  2694. */
  2695. /*
  2696. * It is recommended to include this file from your config.h
  2697. * in order to catch dependency issues early.
  2698. */
  2699. #ifndef MBEDTLS_CHECK_CONFIG_H
  2700. #define MBEDTLS_CHECK_CONFIG_H
  2701. /*
  2702. * We assume CHAR_BIT is 8 in many places. In practice, this is true on our
  2703. * target platforms, so not an issue, but let's just be extra sure.
  2704. */
  2705. #include <limits.h>
  2706. #if CHAR_BIT != 8
  2707. #error "mbed TLS requires a platform with 8-bit chars"
  2708. #endif
  2709. #if defined(_WIN32)
  2710. #if !defined(MBEDTLS_PLATFORM_C)
  2711. #error "MBEDTLS_PLATFORM_C is required on Windows"
  2712. #endif
  2713. /* Fix the config here. Not convenient to put an #ifdef _WIN32 in config.h as
  2714. * it would confuse config.pl. */
  2715. #if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \
  2716. !defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
  2717. #define MBEDTLS_PLATFORM_SNPRINTF_ALT
  2718. #endif
  2719. #endif /* _WIN32 */
  2720. #if defined(TARGET_LIKE_MBED) && \
  2721. ( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
  2722. #error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
  2723. #endif
  2724. #if defined(MBEDTLS_DEPRECATED_WARNING) && \
  2725. !defined(__GNUC__) && !defined(__clang__)
  2726. #error "MBEDTLS_DEPRECATED_WARNING only works with GCC and Clang"
  2727. #endif
  2728. #if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_HAVE_TIME)
  2729. #error "MBEDTLS_HAVE_TIME_DATE without MBEDTLS_HAVE_TIME does not make sense"
  2730. #endif
  2731. #if defined(MBEDTLS_AESNI_C) && !defined(MBEDTLS_HAVE_ASM)
  2732. #error "MBEDTLS_AESNI_C defined, but not all prerequisites"
  2733. #endif
  2734. #if defined(MBEDTLS_CTR_DRBG_C) && !defined(MBEDTLS_AES_C)
  2735. #error "MBEDTLS_CTR_DRBG_C defined, but not all prerequisites"
  2736. #endif
  2737. #if defined(MBEDTLS_DHM_C) && !defined(MBEDTLS_BIGNUM_C)
  2738. #error "MBEDTLS_DHM_C defined, but not all prerequisites"
  2739. #endif
  2740. #if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT) && !defined(MBEDTLS_SSL_TRUNCATED_HMAC)
  2741. #error "MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT defined, but not all prerequisites"
  2742. #endif
  2743. #if defined(MBEDTLS_CMAC_C) && \
  2744. !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C)
  2745. #error "MBEDTLS_CMAC_C defined, but not all prerequisites"
  2746. #endif
  2747. #if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C)
  2748. #error "MBEDTLS_ECDH_C defined, but not all prerequisites"
  2749. #endif
  2750. #if defined(MBEDTLS_ECDSA_C) && \
  2751. ( !defined(MBEDTLS_ECP_C) || \
  2752. !defined(MBEDTLS_ASN1_PARSE_C) || \
  2753. !defined(MBEDTLS_ASN1_WRITE_C) )
  2754. #error "MBEDTLS_ECDSA_C defined, but not all prerequisites"
  2755. #endif
  2756. #if defined(MBEDTLS_ECJPAKE_C) && \
  2757. ( !defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_MD_C) )
  2758. #error "MBEDTLS_ECJPAKE_C defined, but not all prerequisites"
  2759. #endif
  2760. #if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C)
  2761. #error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites"
  2762. #endif
  2763. #if defined(MBEDTLS_ECP_C) && ( !defined(MBEDTLS_BIGNUM_C) || ( \
  2764. !defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) && \
  2765. !defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) && \
  2766. !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) && \
  2767. !defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) && \
  2768. !defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) && \
  2769. !defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) && \
  2770. !defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) && \
  2771. !defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) && \
  2772. !defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) && \
  2773. !defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) && \
  2774. !defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) ) )
  2775. #error "MBEDTLS_ECP_C defined, but not all prerequisites"
  2776. #endif
  2777. #if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && \
  2778. !defined(MBEDTLS_SHA256_C))
  2779. #error "MBEDTLS_ENTROPY_C defined, but not all prerequisites"
  2780. #endif
  2781. #if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_SHA512_C) && \
  2782. defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 64)
  2783. #error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
  2784. #endif
  2785. #if defined(MBEDTLS_ENTROPY_C) && \
  2786. ( !defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_ENTROPY_FORCE_SHA256) ) \
  2787. && defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 32)
  2788. #error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high"
  2789. #endif
  2790. #if defined(MBEDTLS_ENTROPY_C) && \
  2791. defined(MBEDTLS_ENTROPY_FORCE_SHA256) && !defined(MBEDTLS_SHA256_C)
  2792. #error "MBEDTLS_ENTROPY_FORCE_SHA256 defined, but not all prerequisites"
  2793. #endif
  2794. #if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
  2795. ( !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) )
  2796. #error "MBEDTLS_TEST_NULL_ENTROPY defined, but not all prerequisites"
  2797. #endif
  2798. #if defined(MBEDTLS_TEST_NULL_ENTROPY) && \
  2799. ( defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
  2800. defined(MBEDTLS_HAVEGE_C) )
  2801. #error "MBEDTLS_TEST_NULL_ENTROPY defined, but entropy sources too"
  2802. #endif
  2803. #if defined(MBEDTLS_GCM_C) && ( \
  2804. !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) )
  2805. #error "MBEDTLS_GCM_C defined, but not all prerequisites"
  2806. #endif
  2807. #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
  2808. #error "MBEDTLS_ECP_RANDOMIZE_JAC_ALT defined, but not all prerequisites"
  2809. #endif
  2810. #if defined(MBEDTLS_ECP_ADD_MIXED_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
  2811. #error "MBEDTLS_ECP_ADD_MIXED_ALT defined, but not all prerequisites"
  2812. #endif
  2813. #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
  2814. #error "MBEDTLS_ECP_DOUBLE_JAC_ALT defined, but not all prerequisites"
  2815. #endif
  2816. #if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
  2817. #error "MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT defined, but not all prerequisites"
  2818. #endif
  2819. #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
  2820. #error "MBEDTLS_ECP_NORMALIZE_JAC_ALT defined, but not all prerequisites"
  2821. #endif
  2822. #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
  2823. #error "MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT defined, but not all prerequisites"
  2824. #endif
  2825. #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
  2826. #error "MBEDTLS_ECP_RANDOMIZE_MXZ_ALT defined, but not all prerequisites"
  2827. #endif
  2828. #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
  2829. #error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites"
  2830. #endif
  2831. #if defined(MBEDTLS_HAVEGE_C) && !defined(MBEDTLS_TIMING_C)
  2832. #error "MBEDTLS_HAVEGE_C defined, but not all prerequisites"
  2833. #endif
  2834. #if defined(MBEDTLS_HMAC_DRBG_C) && !defined(MBEDTLS_MD_C)
  2835. #error "MBEDTLS_HMAC_DRBG_C defined, but not all prerequisites"
  2836. #endif
  2837. #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && \
  2838. ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) )
  2839. #error "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED defined, but not all prerequisites"
  2840. #endif
  2841. #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
  2842. ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) )
  2843. #error "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED defined, but not all prerequisites"
  2844. #endif
  2845. #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) && !defined(MBEDTLS_DHM_C)
  2846. #error "MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED defined, but not all prerequisites"
  2847. #endif
  2848. #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) && \
  2849. !defined(MBEDTLS_ECDH_C)
  2850. #error "MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED defined, but not all prerequisites"
  2851. #endif
  2852. #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
  2853. ( !defined(MBEDTLS_DHM_C) || !defined(MBEDTLS_RSA_C) || \
  2854. !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
  2855. #error "MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED defined, but not all prerequisites"
  2856. #endif
  2857. #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
  2858. ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \
  2859. !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) )
  2860. #error "MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED defined, but not all prerequisites"
  2861. #endif
  2862. #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && \
  2863. ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \
  2864. !defined(MBEDTLS_X509_CRT_PARSE_C) )
  2865. #error "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED defined, but not all prerequisites"
  2866. #endif
  2867. #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) && \
  2868. ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
  2869. !defined(MBEDTLS_PKCS1_V15) )
  2870. #error "MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED defined, but not all prerequisites"
  2871. #endif
  2872. #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && \
  2873. ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \
  2874. !defined(MBEDTLS_PKCS1_V15) )
  2875. #error "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites"
  2876. #endif
  2877. #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
  2878. ( !defined(MBEDTLS_ECJPAKE_C) || !defined(MBEDTLS_SHA256_C) || \
  2879. !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) )
  2880. #error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
  2881. #endif
  2882. #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
  2883. ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
  2884. #error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
  2885. #endif
  2886. #if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM)
  2887. #error "MBEDTLS_PADLOCK_C defined, but not all prerequisites"
  2888. #endif
  2889. #if defined(MBEDTLS_PEM_PARSE_C) && !defined(MBEDTLS_BASE64_C)
  2890. #error "MBEDTLS_PEM_PARSE_C defined, but not all prerequisites"
  2891. #endif
  2892. #if defined(MBEDTLS_PEM_WRITE_C) && !defined(MBEDTLS_BASE64_C)
  2893. #error "MBEDTLS_PEM_WRITE_C defined, but not all prerequisites"
  2894. #endif
  2895. #if defined(MBEDTLS_PK_C) && \
  2896. ( !defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_ECP_C) )
  2897. #error "MBEDTLS_PK_C defined, but not all prerequisites"
  2898. #endif
  2899. #if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_PK_C)
  2900. #error "MBEDTLS_PK_PARSE_C defined, but not all prerequisites"
  2901. #endif
  2902. #if defined(MBEDTLS_PK_WRITE_C) && !defined(MBEDTLS_PK_C)
  2903. #error "MBEDTLS_PK_WRITE_C defined, but not all prerequisites"
  2904. #endif
  2905. #if defined(MBEDTLS_PKCS11_C) && !defined(MBEDTLS_PK_C)
  2906. #error "MBEDTLS_PKCS11_C defined, but not all prerequisites"
  2907. #endif
  2908. #if defined(MBEDTLS_PLATFORM_EXIT_ALT) && !defined(MBEDTLS_PLATFORM_C)
  2909. #error "MBEDTLS_PLATFORM_EXIT_ALT defined, but not all prerequisites"
  2910. #endif
  2911. #if defined(MBEDTLS_PLATFORM_EXIT_MACRO) && !defined(MBEDTLS_PLATFORM_C)
  2912. #error "MBEDTLS_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
  2913. #endif
  2914. #if defined(MBEDTLS_PLATFORM_EXIT_MACRO) &&\
  2915. ( defined(MBEDTLS_PLATFORM_STD_EXIT) ||\
  2916. defined(MBEDTLS_PLATFORM_EXIT_ALT) )
  2917. #error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously"
  2918. #endif
  2919. #if defined(MBEDTLS_PLATFORM_TIME_ALT) &&\
  2920. ( !defined(MBEDTLS_PLATFORM_C) ||\
  2921. !defined(MBEDTLS_HAVE_TIME) )
  2922. #error "MBEDTLS_PLATFORM_TIME_ALT defined, but not all prerequisites"
  2923. #endif
  2924. #if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
  2925. ( !defined(MBEDTLS_PLATFORM_C) ||\
  2926. !defined(MBEDTLS_HAVE_TIME) )
  2927. #error "MBEDTLS_PLATFORM_TIME_MACRO defined, but not all prerequisites"
  2928. #endif
  2929. #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
  2930. ( !defined(MBEDTLS_PLATFORM_C) ||\
  2931. !defined(MBEDTLS_HAVE_TIME) )
  2932. #error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO defined, but not all prerequisites"
  2933. #endif
  2934. #if defined(MBEDTLS_PLATFORM_TIME_MACRO) &&\
  2935. ( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
  2936. defined(MBEDTLS_PLATFORM_TIME_ALT) )
  2937. #error "MBEDTLS_PLATFORM_TIME_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
  2938. #endif
  2939. #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\
  2940. ( defined(MBEDTLS_PLATFORM_STD_TIME) ||\
  2941. defined(MBEDTLS_PLATFORM_TIME_ALT) )
  2942. #error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously"
  2943. #endif
  2944. #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
  2945. #error "MBEDTLS_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
  2946. #endif
  2947. #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
  2948. #error "MBEDTLS_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
  2949. #endif
  2950. #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) &&\
  2951. ( defined(MBEDTLS_PLATFORM_STD_FPRINTF) ||\
  2952. defined(MBEDTLS_PLATFORM_FPRINTF_ALT) )
  2953. #error "MBEDTLS_PLATFORM_FPRINTF_MACRO and MBEDTLS_PLATFORM_STD_FPRINTF/MBEDTLS_PLATFORM_FPRINTF_ALT cannot be defined simultaneously"
  2954. #endif
  2955. #if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
  2956. ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
  2957. #error "MBEDTLS_PLATFORM_FREE_MACRO defined, but not all prerequisites"
  2958. #endif
  2959. #if defined(MBEDTLS_PLATFORM_FREE_MACRO) &&\
  2960. defined(MBEDTLS_PLATFORM_STD_FREE)
  2961. #error "MBEDTLS_PLATFORM_FREE_MACRO and MBEDTLS_PLATFORM_STD_FREE cannot be defined simultaneously"
  2962. #endif
  2963. #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && !defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
  2964. #error "MBEDTLS_PLATFORM_CALLOC_MACRO must be defined if MBEDTLS_PLATFORM_FREE_MACRO is"
  2965. #endif
  2966. #if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
  2967. ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
  2968. #error "MBEDTLS_PLATFORM_CALLOC_MACRO defined, but not all prerequisites"
  2969. #endif
  2970. #if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) &&\
  2971. defined(MBEDTLS_PLATFORM_STD_CALLOC)
  2972. #error "MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_STD_CALLOC cannot be defined simultaneously"
  2973. #endif
  2974. #if defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && !defined(MBEDTLS_PLATFORM_FREE_MACRO)
  2975. #error "MBEDTLS_PLATFORM_FREE_MACRO must be defined if MBEDTLS_PLATFORM_CALLOC_MACRO is"
  2976. #endif
  2977. #if defined(MBEDTLS_PLATFORM_MEMORY) && !defined(MBEDTLS_PLATFORM_C)
  2978. #error "MBEDTLS_PLATFORM_MEMORY defined, but not all prerequisites"
  2979. #endif
  2980. #if defined(MBEDTLS_PLATFORM_PRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
  2981. #error "MBEDTLS_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
  2982. #endif
  2983. #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
  2984. #error "MBEDTLS_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
  2985. #endif
  2986. #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) &&\
  2987. ( defined(MBEDTLS_PLATFORM_STD_PRINTF) ||\
  2988. defined(MBEDTLS_PLATFORM_PRINTF_ALT) )
  2989. #error "MBEDTLS_PLATFORM_PRINTF_MACRO and MBEDTLS_PLATFORM_STD_PRINTF/MBEDTLS_PLATFORM_PRINTF_ALT cannot be defined simultaneously"
  2990. #endif
  2991. #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C)
  2992. #error "MBEDTLS_PLATFORM_SNPRINTF_ALT defined, but not all prerequisites"
  2993. #endif
  2994. #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C)
  2995. #error "MBEDTLS_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
  2996. #endif
  2997. #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) &&\
  2998. ( defined(MBEDTLS_PLATFORM_STD_SNPRINTF) ||\
  2999. defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) )
  3000. #error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously"
  3001. #endif
  3002. #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) &&\
  3003. !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
  3004. #error "MBEDTLS_PLATFORM_STD_MEM_HDR defined, but not all prerequisites"
  3005. #endif
  3006. #if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
  3007. #error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
  3008. #endif
  3009. #if defined(MBEDTLS_PLATFORM_STD_CALLOC) && !defined(MBEDTLS_PLATFORM_MEMORY)
  3010. #error "MBEDTLS_PLATFORM_STD_CALLOC defined, but not all prerequisites"
  3011. #endif
  3012. #if defined(MBEDTLS_PLATFORM_STD_FREE) && !defined(MBEDTLS_PLATFORM_MEMORY)
  3013. #error "MBEDTLS_PLATFORM_STD_FREE defined, but not all prerequisites"
  3014. #endif
  3015. #if defined(MBEDTLS_PLATFORM_STD_EXIT) &&\
  3016. !defined(MBEDTLS_PLATFORM_EXIT_ALT)
  3017. #error "MBEDTLS_PLATFORM_STD_EXIT defined, but not all prerequisites"
  3018. #endif
  3019. #if defined(MBEDTLS_PLATFORM_STD_TIME) &&\
  3020. ( !defined(MBEDTLS_PLATFORM_TIME_ALT) ||\
  3021. !defined(MBEDTLS_HAVE_TIME) )
  3022. #error "MBEDTLS_PLATFORM_STD_TIME defined, but not all prerequisites"
  3023. #endif
  3024. #if defined(MBEDTLS_PLATFORM_STD_FPRINTF) &&\
  3025. !defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
  3026. #error "MBEDTLS_PLATFORM_STD_FPRINTF defined, but not all prerequisites"
  3027. #endif
  3028. #if defined(MBEDTLS_PLATFORM_STD_PRINTF) &&\
  3029. !defined(MBEDTLS_PLATFORM_PRINTF_ALT)
  3030. #error "MBEDTLS_PLATFORM_STD_PRINTF defined, but not all prerequisites"
  3031. #endif
  3032. #if defined(MBEDTLS_PLATFORM_STD_SNPRINTF) &&\
  3033. !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
  3034. #error "MBEDTLS_PLATFORM_STD_SNPRINTF defined, but not all prerequisites"
  3035. #endif
  3036. #if defined(MBEDTLS_ENTROPY_NV_SEED) &&\
  3037. ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_ENTROPY_C) )
  3038. #error "MBEDTLS_ENTROPY_NV_SEED defined, but not all prerequisites"
  3039. #endif
  3040. #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT) &&\
  3041. !defined(MBEDTLS_ENTROPY_NV_SEED)
  3042. #error "MBEDTLS_PLATFORM_NV_SEED_ALT defined, but not all prerequisites"
  3043. #endif
  3044. #if defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) &&\
  3045. !defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
  3046. #error "MBEDTLS_PLATFORM_STD_NV_SEED_READ defined, but not all prerequisites"
  3047. #endif
  3048. #if defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) &&\
  3049. !defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
  3050. #error "MBEDTLS_PLATFORM_STD_NV_SEED_WRITE defined, but not all prerequisites"
  3051. #endif
  3052. #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) &&\
  3053. ( defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) ||\
  3054. defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
  3055. #error "MBEDTLS_PLATFORM_NV_SEED_READ_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_READ cannot be defined simultaneously"
  3056. #endif
  3057. #if defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) &&\
  3058. ( defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) ||\
  3059. defined(MBEDTLS_PLATFORM_NV_SEED_ALT) )
  3060. #error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously"
  3061. #endif
  3062. #if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
  3063. !defined(MBEDTLS_OID_C) )
  3064. #error "MBEDTLS_RSA_C defined, but not all prerequisites"
  3065. #endif
  3066. #if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_PKCS1_V21) && \
  3067. !defined(MBEDTLS_PKCS1_V15) )
  3068. #error "MBEDTLS_RSA_C defined, but none of the PKCS1 versions enabled"
  3069. #endif
  3070. #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) && \
  3071. ( !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_PKCS1_V21) )
  3072. #error "MBEDTLS_X509_RSASSA_PSS_SUPPORT defined, but not all prerequisites"
  3073. #endif
  3074. #if defined(MBEDTLS_SSL_PROTO_SSL3) && ( !defined(MBEDTLS_MD5_C) || \
  3075. !defined(MBEDTLS_SHA1_C) )
  3076. #error "MBEDTLS_SSL_PROTO_SSL3 defined, but not all prerequisites"
  3077. #endif
  3078. #if defined(MBEDTLS_SSL_PROTO_TLS1) && ( !defined(MBEDTLS_MD5_C) || \
  3079. !defined(MBEDTLS_SHA1_C) )
  3080. #error "MBEDTLS_SSL_PROTO_TLS1 defined, but not all prerequisites"
  3081. #endif
  3082. #if defined(MBEDTLS_SSL_PROTO_TLS1_1) && ( !defined(MBEDTLS_MD5_C) || \
  3083. !defined(MBEDTLS_SHA1_C) )
  3084. #error "MBEDTLS_SSL_PROTO_TLS1_1 defined, but not all prerequisites"
  3085. #endif
  3086. #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && ( !defined(MBEDTLS_SHA1_C) && \
  3087. !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C) )
  3088. #error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites"
  3089. #endif
  3090. #if defined(MBEDTLS_SSL_PROTO_DTLS) && \
  3091. !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
  3092. !defined(MBEDTLS_SSL_PROTO_TLS1_2)
  3093. #error "MBEDTLS_SSL_PROTO_DTLS defined, but not all prerequisites"
  3094. #endif
  3095. #if defined(MBEDTLS_SSL_CLI_C) && !defined(MBEDTLS_SSL_TLS_C)
  3096. #error "MBEDTLS_SSL_CLI_C defined, but not all prerequisites"
  3097. #endif
  3098. #if defined(MBEDTLS_SSL_TLS_C) && ( !defined(MBEDTLS_CIPHER_C) || \
  3099. !defined(MBEDTLS_MD_C) )
  3100. #error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites"
  3101. #endif
  3102. #if defined(MBEDTLS_SSL_SRV_C) && !defined(MBEDTLS_SSL_TLS_C)
  3103. #error "MBEDTLS_SSL_SRV_C defined, but not all prerequisites"
  3104. #endif
  3105. #if defined(MBEDTLS_SSL_TLS_C) && (!defined(MBEDTLS_SSL_PROTO_SSL3) && \
  3106. !defined(MBEDTLS_SSL_PROTO_TLS1) && !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
  3107. !defined(MBEDTLS_SSL_PROTO_TLS1_2))
  3108. #error "MBEDTLS_SSL_TLS_C defined, but no protocols are active"
  3109. #endif
  3110. #if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
  3111. defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1))
  3112. #error "Illegal protocol selection"
  3113. #endif
  3114. #if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_TLS1) && \
  3115. defined(MBEDTLS_SSL_PROTO_TLS1_2) && !defined(MBEDTLS_SSL_PROTO_TLS1_1))
  3116. #error "Illegal protocol selection"
  3117. #endif
  3118. #if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
  3119. defined(MBEDTLS_SSL_PROTO_TLS1_2) && (!defined(MBEDTLS_SSL_PROTO_TLS1) || \
  3120. !defined(MBEDTLS_SSL_PROTO_TLS1_1)))
  3121. #error "Illegal protocol selection"
  3122. #endif
  3123. #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && !defined(MBEDTLS_SSL_PROTO_DTLS)
  3124. #error "MBEDTLS_SSL_DTLS_HELLO_VERIFY defined, but not all prerequisites"
  3125. #endif
  3126. #if defined(MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE) && \
  3127. !defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
  3128. #error "MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE defined, but not all prerequisites"
  3129. #endif
  3130. #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY) && \
  3131. ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
  3132. #error "MBEDTLS_SSL_DTLS_ANTI_REPLAY defined, but not all prerequisites"
  3133. #endif
  3134. #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT) && \
  3135. ( !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) )
  3136. #error "MBEDTLS_SSL_DTLS_BADMAC_LIMIT defined, but not all prerequisites"
  3137. #endif
  3138. #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \
  3139. !defined(MBEDTLS_SSL_PROTO_TLS1) && \
  3140. !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
  3141. !defined(MBEDTLS_SSL_PROTO_TLS1_2)
  3142. #error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequsites"
  3143. #endif
  3144. #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) && \
  3145. !defined(MBEDTLS_SSL_PROTO_TLS1) && \
  3146. !defined(MBEDTLS_SSL_PROTO_TLS1_1) && \
  3147. !defined(MBEDTLS_SSL_PROTO_TLS1_2)
  3148. #error "MBEDTLS_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequsites"
  3149. #endif
  3150. #if defined(MBEDTLS_SSL_TICKET_C) && !defined(MBEDTLS_CIPHER_C)
  3151. #error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites"
  3152. #endif
  3153. #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING) && \
  3154. !defined(MBEDTLS_SSL_PROTO_SSL3) && !defined(MBEDTLS_SSL_PROTO_TLS1)
  3155. #error "MBEDTLS_SSL_CBC_RECORD_SPLITTING defined, but not all prerequisites"
  3156. #endif
  3157. #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && \
  3158. !defined(MBEDTLS_X509_CRT_PARSE_C)
  3159. #error "MBEDTLS_SSL_SERVER_NAME_INDICATION defined, but not all prerequisites"
  3160. #endif
  3161. #if defined(MBEDTLS_THREADING_PTHREAD)
  3162. #if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
  3163. #error "MBEDTLS_THREADING_PTHREAD defined, but not all prerequisites"
  3164. #endif
  3165. #define MBEDTLS_THREADING_IMPL
  3166. #endif
  3167. #if defined(MBEDTLS_THREADING_ALT)
  3168. #if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL)
  3169. #error "MBEDTLS_THREADING_ALT defined, but not all prerequisites"
  3170. #endif
  3171. #define MBEDTLS_THREADING_IMPL
  3172. #endif
  3173. #if defined(MBEDTLS_THREADING_C) && !defined(MBEDTLS_THREADING_IMPL)
  3174. #error "MBEDTLS_THREADING_C defined, single threading implementation required"
  3175. #endif
  3176. #undef MBEDTLS_THREADING_IMPL
  3177. #if defined(MBEDTLS_VERSION_FEATURES) && !defined(MBEDTLS_VERSION_C)
  3178. #error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites"
  3179. #endif
  3180. #if defined(MBEDTLS_X509_USE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
  3181. !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || \
  3182. !defined(MBEDTLS_PK_PARSE_C) )
  3183. #error "MBEDTLS_X509_USE_C defined, but not all prerequisites"
  3184. #endif
  3185. #if defined(MBEDTLS_X509_CREATE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \
  3186. !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) || \
  3187. !defined(MBEDTLS_PK_WRITE_C) )
  3188. #error "MBEDTLS_X509_CREATE_C defined, but not all prerequisites"
  3189. #endif
  3190. #if defined(MBEDTLS_X509_CRT_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
  3191. #error "MBEDTLS_X509_CRT_PARSE_C defined, but not all prerequisites"
  3192. #endif
  3193. #if defined(MBEDTLS_X509_CRL_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
  3194. #error "MBEDTLS_X509_CRL_PARSE_C defined, but not all prerequisites"
  3195. #endif
  3196. #if defined(MBEDTLS_X509_CSR_PARSE_C) && ( !defined(MBEDTLS_X509_USE_C) )
  3197. #error "MBEDTLS_X509_CSR_PARSE_C defined, but not all prerequisites"
  3198. #endif
  3199. #if defined(MBEDTLS_X509_CRT_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
  3200. #error "MBEDTLS_X509_CRT_WRITE_C defined, but not all prerequisites"
  3201. #endif
  3202. #if defined(MBEDTLS_X509_CSR_WRITE_C) && ( !defined(MBEDTLS_X509_CREATE_C) )
  3203. #error "MBEDTLS_X509_CSR_WRITE_C defined, but not all prerequisites"
  3204. #endif
  3205. #if defined(MBEDTLS_HAVE_INT32) && defined(MBEDTLS_HAVE_INT64)
  3206. #error "MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 cannot be defined simultaneously"
  3207. #endif /* MBEDTLS_HAVE_INT32 && MBEDTLS_HAVE_INT64 */
  3208. #if ( defined(MBEDTLS_HAVE_INT32) || defined(MBEDTLS_HAVE_INT64) ) && \
  3209. defined(MBEDTLS_HAVE_ASM)
  3210. #error "MBEDTLS_HAVE_INT32/MBEDTLS_HAVE_INT64 and MBEDTLS_HAVE_ASM cannot be defined simultaneously"
  3211. #endif /* (MBEDTLS_HAVE_INT32 || MBEDTLS_HAVE_INT64) && MBEDTLS_HAVE_ASM */
  3212. /*
  3213. * Avoid warning from -pedantic. This is a convenient place for this
  3214. * workaround since this is included by every single file before the
  3215. * #if defined(MBEDTLS_xxx_C) that results in emtpy translation units.
  3216. */
  3217. typedef int mbedtls_iso_c_forbids_empty_translation_units;
  3218. #endif /* MBEDTLS_CHECK_CONFIG_H */
  3219. /********* Start of file include/mbedtls/platform.h ************/
  3220. /**
  3221. * \file platform.h
  3222. *
  3223. * \brief The Mbed TLS platform abstraction layer.
  3224. */
  3225. /*
  3226. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  3227. * SPDX-License-Identifier: Apache-2.0
  3228. *
  3229. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  3230. * not use this file except in compliance with the License.
  3231. * You may obtain a copy of the License at
  3232. *
  3233. * http://www.apache.org/licenses/LICENSE-2.0
  3234. *
  3235. * Unless required by applicable law or agreed to in writing, software
  3236. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  3237. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3238. * See the License for the specific language governing permissions and
  3239. * limitations under the License.
  3240. *
  3241. * This file is part of Mbed TLS (https://tls.mbed.org)
  3242. */
  3243. #ifndef MBEDTLS_PLATFORM_H
  3244. #define MBEDTLS_PLATFORM_H
  3245. #if !defined(MBEDTLS_CONFIG_FILE)
  3246. #else
  3247. #endif
  3248. #if defined(MBEDTLS_HAVE_TIME)
  3249. #endif
  3250. #ifdef __cplusplus
  3251. extern "C" {
  3252. #endif
  3253. /**
  3254. * \name SECTION: Module settings
  3255. *
  3256. * The configuration options you can set for this module are in this section.
  3257. * Either change them in config.h or define them on the compiler command line.
  3258. * \{
  3259. */
  3260. #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
  3261. #include <stdio.h>
  3262. #include <stdlib.h>
  3263. #include <time.h>
  3264. #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
  3265. #if defined(_WIN32)
  3266. #define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< The default \c snprintf function to use. */
  3267. #else
  3268. #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< The default \c snprintf function to use. */
  3269. #endif
  3270. #endif
  3271. #if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
  3272. #define MBEDTLS_PLATFORM_STD_PRINTF printf /**< The default \c printf function to use. */
  3273. #endif
  3274. #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
  3275. #define MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< The default \c fprintf function to use. */
  3276. #endif
  3277. #if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
  3278. #define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< The default \c calloc function to use. */
  3279. #endif
  3280. #if !defined(MBEDTLS_PLATFORM_STD_FREE)
  3281. #define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */
  3282. #endif
  3283. #if !defined(MBEDTLS_PLATFORM_STD_EXIT)
  3284. #define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */
  3285. #endif
  3286. #if !defined(MBEDTLS_PLATFORM_STD_TIME)
  3287. #define MBEDTLS_PLATFORM_STD_TIME time /**< The default \c time function to use. */
  3288. #endif
  3289. #if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
  3290. #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS /**< The default exit value to use. */
  3291. #endif
  3292. #if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
  3293. #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE /**< The default exit value to use. */
  3294. #endif
  3295. #if defined(MBEDTLS_FS_IO)
  3296. #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
  3297. #define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
  3298. #endif
  3299. #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
  3300. #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
  3301. #endif
  3302. #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
  3303. #define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
  3304. #endif
  3305. #endif /* MBEDTLS_FS_IO */
  3306. #else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
  3307. #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
  3308. #include MBEDTLS_PLATFORM_STD_MEM_HDR
  3309. #endif
  3310. #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
  3311. /* \} name SECTION: Module settings */
  3312. /*
  3313. * The function pointers for calloc and free
  3314. */
  3315. #if defined(MBEDTLS_PLATFORM_MEMORY)
  3316. #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
  3317. defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
  3318. #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
  3319. #define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
  3320. #else
  3321. /* For size_t */
  3322. #include <stddef.h>
  3323. extern void * (*mbedtls_calloc)( size_t n, size_t size );
  3324. extern void (*mbedtls_free)( void *ptr );
  3325. /**
  3326. * \brief This function allows configuring custom memory-management functions.
  3327. *
  3328. * \param calloc_func The \c calloc function implementation.
  3329. * \param free_func The \c free function implementation.
  3330. *
  3331. * \return \c 0.
  3332. */
  3333. int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
  3334. void (*free_func)( void * ) );
  3335. #endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
  3336. #else /* !MBEDTLS_PLATFORM_MEMORY */
  3337. #define mbedtls_free free
  3338. #define mbedtls_calloc calloc
  3339. #endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
  3340. /*
  3341. * The function pointers for fprintf
  3342. */
  3343. #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
  3344. /* We need FILE * */
  3345. #include <stdio.h>
  3346. extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
  3347. /**
  3348. * \brief This function allows configuring a custom \p fprintf function pointer.
  3349. *
  3350. * \param fprintf_func The \c fprintf function implementation.
  3351. *
  3352. * \return \c 0.
  3353. */
  3354. int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
  3355. ... ) );
  3356. #else
  3357. #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
  3358. #define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
  3359. #else
  3360. #define mbedtls_fprintf fprintf
  3361. #endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
  3362. #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
  3363. /*
  3364. * The function pointers for printf
  3365. */
  3366. #if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
  3367. extern int (*mbedtls_printf)( const char *format, ... );
  3368. /**
  3369. * \brief This function allows configuring a custom \c printf function
  3370. * pointer.
  3371. *
  3372. * \param printf_func The \c printf function implementation.
  3373. *
  3374. * \return \c 0 on success.
  3375. */
  3376. int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
  3377. #else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
  3378. #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
  3379. #define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
  3380. #else
  3381. #define mbedtls_printf printf
  3382. #endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
  3383. #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
  3384. /*
  3385. * The function pointers for snprintf
  3386. *
  3387. * The snprintf implementation should conform to C99:
  3388. * - it *must* always correctly zero-terminate the buffer
  3389. * (except when n == 0, then it must leave the buffer untouched)
  3390. * - however it is acceptable to return -1 instead of the required length when
  3391. * the destination buffer is too short.
  3392. */
  3393. #if defined(_WIN32)
  3394. /* For Windows (inc. MSYS2), we provide our own fixed implementation */
  3395. int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
  3396. #endif
  3397. #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
  3398. extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
  3399. /**
  3400. * \brief This function allows configuring a custom \c snprintf function
  3401. * pointer.
  3402. *
  3403. * \param snprintf_func The \c snprintf function implementation.
  3404. *
  3405. * \return \c 0 on success.
  3406. */
  3407. int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
  3408. const char * format, ... ) );
  3409. #else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
  3410. #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
  3411. #define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
  3412. #else
  3413. #define mbedtls_snprintf snprintf
  3414. #endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
  3415. #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
  3416. /*
  3417. * The function pointers for exit
  3418. */
  3419. #if defined(MBEDTLS_PLATFORM_EXIT_ALT)
  3420. extern void (*mbedtls_exit)( int status );
  3421. /**
  3422. * \brief This function allows configuring a custom \c exit function
  3423. * pointer.
  3424. *
  3425. * \param exit_func The \c exit function implementation.
  3426. *
  3427. * \return \c 0 on success.
  3428. */
  3429. int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
  3430. #else
  3431. #if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
  3432. #define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
  3433. #else
  3434. #define mbedtls_exit exit
  3435. #endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
  3436. #endif /* MBEDTLS_PLATFORM_EXIT_ALT */
  3437. /*
  3438. * The default exit values
  3439. */
  3440. #if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
  3441. #define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
  3442. #else
  3443. #define MBEDTLS_EXIT_SUCCESS 0
  3444. #endif
  3445. #if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
  3446. #define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
  3447. #else
  3448. #define MBEDTLS_EXIT_FAILURE 1
  3449. #endif
  3450. /*
  3451. * The function pointers for reading from and writing a seed file to
  3452. * Non-Volatile storage (NV) in a platform-independent way
  3453. *
  3454. * Only enabled when the NV seed entropy source is enabled
  3455. */
  3456. #if defined(MBEDTLS_ENTROPY_NV_SEED)
  3457. #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
  3458. /* Internal standard platform definitions */
  3459. int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
  3460. int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
  3461. #endif
  3462. #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
  3463. extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
  3464. extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
  3465. /**
  3466. * \brief This function allows configuring custom seed file writing and
  3467. * reading functions.
  3468. *
  3469. * \param nv_seed_read_func The seed reading function implementation.
  3470. * \param nv_seed_write_func The seed writing function implementation.
  3471. *
  3472. * \return \c 0 on success.
  3473. */
  3474. int mbedtls_platform_set_nv_seed(
  3475. int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
  3476. int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
  3477. );
  3478. #else
  3479. #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
  3480. defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
  3481. #define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
  3482. #define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
  3483. #else
  3484. #define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
  3485. #define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
  3486. #endif
  3487. #endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
  3488. #endif /* MBEDTLS_ENTROPY_NV_SEED */
  3489. #if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
  3490. /**
  3491. * \brief The platform context structure.
  3492. *
  3493. * \note This structure may be used to assist platform-specific
  3494. * setup or teardown operations.
  3495. */
  3496. typedef struct {
  3497. char dummy; /**< Placeholder member, as empty structs are not portable. */
  3498. }
  3499. mbedtls_platform_context;
  3500. #else
  3501. #endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
  3502. /**
  3503. * \brief This function performs any platform initialization operations.
  3504. *
  3505. * \param ctx The Mbed TLS context.
  3506. *
  3507. * \return \c 0 on success.
  3508. *
  3509. * \note This function is intended to allow platform-specific initialization,
  3510. * and should be called before any other library functions. Its
  3511. * implementation is platform-specific, and unless
  3512. * platform-specific code is provided, it does nothing.
  3513. *
  3514. * Its use and whether it is necessary to call it is dependent on the
  3515. * platform.
  3516. */
  3517. int mbedtls_platform_setup( mbedtls_platform_context *ctx );
  3518. /**
  3519. * \brief This function performs any platform teardown operations.
  3520. *
  3521. * \param ctx The Mbed TLS context.
  3522. *
  3523. * \note This function should be called after every other Mbed TLS module
  3524. * has been correctly freed using the appropriate free function.
  3525. * Its implementation is platform-specific, and unless
  3526. * platform-specific code is provided, it does nothing.
  3527. *
  3528. * Its use and whether it is necessary to call it is dependent on the
  3529. * platform.
  3530. */
  3531. void mbedtls_platform_teardown( mbedtls_platform_context *ctx );
  3532. #ifdef __cplusplus
  3533. }
  3534. #endif
  3535. #endif /* platform.h */
  3536. /********* Start of file include/mbedtls/platform_time.h ************/
  3537. /**
  3538. * \file platform_time.h
  3539. *
  3540. * \brief mbed TLS Platform time abstraction
  3541. */
  3542. /*
  3543. * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
  3544. * SPDX-License-Identifier: Apache-2.0
  3545. *
  3546. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  3547. * not use this file except in compliance with the License.
  3548. * You may obtain a copy of the License at
  3549. *
  3550. * http://www.apache.org/licenses/LICENSE-2.0
  3551. *
  3552. * Unless required by applicable law or agreed to in writing, software
  3553. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  3554. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3555. * See the License for the specific language governing permissions and
  3556. * limitations under the License.
  3557. *
  3558. * This file is part of mbed TLS (https://tls.mbed.org)
  3559. */
  3560. #ifndef MBEDTLS_PLATFORM_TIME_H
  3561. #define MBEDTLS_PLATFORM_TIME_H
  3562. #if !defined(MBEDTLS_CONFIG_FILE)
  3563. #else
  3564. #endif
  3565. #ifdef __cplusplus
  3566. extern "C" {
  3567. #endif
  3568. /**
  3569. * \name SECTION: Module settings
  3570. *
  3571. * The configuration options you can set for this module are in this section.
  3572. * Either change them in config.h or define them on the compiler command line.
  3573. * \{
  3574. */
  3575. /*
  3576. * The time_t datatype
  3577. */
  3578. #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO)
  3579. typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t;
  3580. #else
  3581. /* For time_t */
  3582. #include <time.h>
  3583. typedef time_t mbedtls_time_t;
  3584. #endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */
  3585. /*
  3586. * The function pointers for time
  3587. */
  3588. #if defined(MBEDTLS_PLATFORM_TIME_ALT)
  3589. extern mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* time );
  3590. /**
  3591. * \brief Set your own time function pointer
  3592. *
  3593. * \param time_func the time function implementation
  3594. *
  3595. * \return 0
  3596. */
  3597. int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* time ) );
  3598. #else
  3599. #if defined(MBEDTLS_PLATFORM_TIME_MACRO)
  3600. #define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO
  3601. #else
  3602. #define mbedtls_time time
  3603. #endif /* MBEDTLS_PLATFORM_TIME_MACRO */
  3604. #endif /* MBEDTLS_PLATFORM_TIME_ALT */
  3605. #ifdef __cplusplus
  3606. }
  3607. #endif
  3608. #endif /* platform_time.h */
  3609. /********* Start of file include/mbedtls/threading.h ************/
  3610. /**
  3611. * \file threading.h
  3612. *
  3613. * \brief Threading abstraction layer
  3614. */
  3615. /*
  3616. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  3617. * SPDX-License-Identifier: Apache-2.0
  3618. *
  3619. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  3620. * not use this file except in compliance with the License.
  3621. * You may obtain a copy of the License at
  3622. *
  3623. * http://www.apache.org/licenses/LICENSE-2.0
  3624. *
  3625. * Unless required by applicable law or agreed to in writing, software
  3626. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  3627. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3628. * See the License for the specific language governing permissions and
  3629. * limitations under the License.
  3630. *
  3631. * This file is part of mbed TLS (https://tls.mbed.org)
  3632. */
  3633. #ifndef MBEDTLS_THREADING_H
  3634. #define MBEDTLS_THREADING_H
  3635. #if !defined(MBEDTLS_CONFIG_FILE)
  3636. #else
  3637. #endif
  3638. #include <stdlib.h>
  3639. #ifdef __cplusplus
  3640. extern "C" {
  3641. #endif
  3642. #define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */
  3643. #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */
  3644. #define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */
  3645. #if defined(MBEDTLS_THREADING_PTHREAD)
  3646. #include <pthread.h>
  3647. typedef struct
  3648. {
  3649. pthread_mutex_t mutex;
  3650. char is_valid;
  3651. } mbedtls_threading_mutex_t;
  3652. #endif
  3653. #if defined(MBEDTLS_THREADING_ALT)
  3654. /* You should define the mbedtls_threading_mutex_t type in your header */
  3655. /**
  3656. * \brief Set your alternate threading implementation function
  3657. * pointers and initialize global mutexes. If used, this
  3658. * function must be called once in the main thread before any
  3659. * other mbed TLS function is called, and
  3660. * mbedtls_threading_free_alt() must be called once in the main
  3661. * thread after all other mbed TLS functions.
  3662. *
  3663. * \note mutex_init() and mutex_free() don't return a status code.
  3664. * If mutex_init() fails, it should leave its argument (the
  3665. * mutex) in a state such that mutex_lock() will fail when
  3666. * called with this argument.
  3667. *
  3668. * \param mutex_init the init function implementation
  3669. * \param mutex_free the free function implementation
  3670. * \param mutex_lock the lock function implementation
  3671. * \param mutex_unlock the unlock function implementation
  3672. */
  3673. void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
  3674. void (*mutex_free)( mbedtls_threading_mutex_t * ),
  3675. int (*mutex_lock)( mbedtls_threading_mutex_t * ),
  3676. int (*mutex_unlock)( mbedtls_threading_mutex_t * ) );
  3677. /**
  3678. * \brief Free global mutexes.
  3679. */
  3680. void mbedtls_threading_free_alt( void );
  3681. #endif /* MBEDTLS_THREADING_ALT */
  3682. #if defined(MBEDTLS_THREADING_C)
  3683. /*
  3684. * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
  3685. *
  3686. * All these functions are expected to work or the result will be undefined.
  3687. */
  3688. extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex );
  3689. extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex );
  3690. extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex );
  3691. extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex );
  3692. /*
  3693. * Global mutexes
  3694. */
  3695. extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex;
  3696. extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex;
  3697. #endif /* MBEDTLS_THREADING_C */
  3698. #ifdef __cplusplus
  3699. }
  3700. #endif
  3701. #endif /* threading.h */
  3702. /********* Start of file include/mbedtls/bignum.h ************/
  3703. /**
  3704. * \file bignum.h
  3705. *
  3706. * \brief Multi-precision integer library
  3707. */
  3708. /*
  3709. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  3710. * SPDX-License-Identifier: Apache-2.0
  3711. *
  3712. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  3713. * not use this file except in compliance with the License.
  3714. * You may obtain a copy of the License at
  3715. *
  3716. * http://www.apache.org/licenses/LICENSE-2.0
  3717. *
  3718. * Unless required by applicable law or agreed to in writing, software
  3719. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  3720. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3721. * See the License for the specific language governing permissions and
  3722. * limitations under the License.
  3723. *
  3724. * This file is part of mbed TLS (https://tls.mbed.org)
  3725. */
  3726. #ifndef MBEDTLS_BIGNUM_H
  3727. #define MBEDTLS_BIGNUM_H
  3728. #if !defined(MBEDTLS_CONFIG_FILE)
  3729. #else
  3730. #endif
  3731. #include <stddef.h>
  3732. #include <stdint.h>
  3733. #if defined(MBEDTLS_FS_IO)
  3734. #include <stdio.h>
  3735. #endif
  3736. #define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002 /**< An error occurred while reading from or writing to a file. */
  3737. #define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004 /**< Bad input parameters to function. */
  3738. #define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006 /**< There is an invalid character in the digit string. */
  3739. #define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008 /**< The buffer is too small to write to. */
  3740. #define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A /**< The input arguments are negative or result in illegal output. */
  3741. #define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C /**< The input argument for division is zero, which is not allowed. */
  3742. #define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */
  3743. #define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 /**< Memory allocation failed. */
  3744. #define MBEDTLS_MPI_CHK(f) do { if( ( ret = f ) != 0 ) goto cleanup; } while( 0 )
  3745. /*
  3746. * Maximum size MPIs are allowed to grow to in number of limbs.
  3747. */
  3748. #define MBEDTLS_MPI_MAX_LIMBS 10000
  3749. #if !defined(MBEDTLS_MPI_WINDOW_SIZE)
  3750. /*
  3751. * Maximum window size used for modular exponentiation. Default: 6
  3752. * Minimum value: 1. Maximum value: 6.
  3753. *
  3754. * Result is an array of ( 2 << MBEDTLS_MPI_WINDOW_SIZE ) MPIs used
  3755. * for the sliding window calculation. (So 64 by default)
  3756. *
  3757. * Reduction in size, reduces speed.
  3758. */
  3759. #define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */
  3760. #endif /* !MBEDTLS_MPI_WINDOW_SIZE */
  3761. #if !defined(MBEDTLS_MPI_MAX_SIZE)
  3762. /*
  3763. * Maximum size of MPIs allowed in bits and bytes for user-MPIs.
  3764. * ( Default: 512 bytes => 4096 bits, Maximum tested: 2048 bytes => 16384 bits )
  3765. *
  3766. * Note: Calculations can temporarily result in larger MPIs. So the number
  3767. * of limbs required (MBEDTLS_MPI_MAX_LIMBS) is higher.
  3768. */
  3769. #define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */
  3770. #endif /* !MBEDTLS_MPI_MAX_SIZE */
  3771. #define MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */
  3772. /*
  3773. * When reading from files with mbedtls_mpi_read_file() and writing to files with
  3774. * mbedtls_mpi_write_file() the buffer should have space
  3775. * for a (short) label, the MPI (in the provided radix), the newline
  3776. * characters and the '\0'.
  3777. *
  3778. * By default we assume at least a 10 char label, a minimum radix of 10
  3779. * (decimal) and a maximum of 4096 bit numbers (1234 decimal chars).
  3780. * Autosized at compile time for at least a 10 char label, a minimum radix
  3781. * of 10 (decimal) for a number of MBEDTLS_MPI_MAX_BITS size.
  3782. *
  3783. * This used to be statically sized to 1250 for a maximum of 4096 bit
  3784. * numbers (1234 decimal chars).
  3785. *
  3786. * Calculate using the formula:
  3787. * MBEDTLS_MPI_RW_BUFFER_SIZE = ceil(MBEDTLS_MPI_MAX_BITS / ln(10) * ln(2)) +
  3788. * LabelSize + 6
  3789. */
  3790. #define MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS )
  3791. #define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332
  3792. #define MBEDTLS_MPI_RW_BUFFER_SIZE ( ((MBEDTLS_MPI_MAX_BITS_SCALE100 + MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6 )
  3793. /*
  3794. * Define the base integer type, architecture-wise.
  3795. *
  3796. * 32 or 64-bit integer types can be forced regardless of the underlying
  3797. * architecture by defining MBEDTLS_HAVE_INT32 or MBEDTLS_HAVE_INT64
  3798. * respectively and undefining MBEDTLS_HAVE_ASM.
  3799. *
  3800. * Double-width integers (e.g. 128-bit in 64-bit architectures) can be
  3801. * disabled by defining MBEDTLS_NO_UDBL_DIVISION.
  3802. */
  3803. #if !defined(MBEDTLS_HAVE_INT32)
  3804. #if defined(_MSC_VER) && defined(_M_AMD64)
  3805. /* Always choose 64-bit when using MSC */
  3806. #if !defined(MBEDTLS_HAVE_INT64)
  3807. #define MBEDTLS_HAVE_INT64
  3808. #endif /* !MBEDTLS_HAVE_INT64 */
  3809. typedef int64_t mbedtls_mpi_sint;
  3810. typedef uint64_t mbedtls_mpi_uint;
  3811. #elif defined(__GNUC__) && ( \
  3812. defined(__amd64__) || defined(__x86_64__) || \
  3813. defined(__ppc64__) || defined(__powerpc64__) || \
  3814. defined(__ia64__) || defined(__alpha__) || \
  3815. ( defined(__sparc__) && defined(__arch64__) ) || \
  3816. defined(__s390x__) || defined(__mips64) )
  3817. #if !defined(MBEDTLS_HAVE_INT64)
  3818. #define MBEDTLS_HAVE_INT64
  3819. #endif /* MBEDTLS_HAVE_INT64 */
  3820. typedef int64_t mbedtls_mpi_sint;
  3821. typedef uint64_t mbedtls_mpi_uint;
  3822. #if !defined(MBEDTLS_NO_UDBL_DIVISION)
  3823. /* mbedtls_t_udbl defined as 128-bit unsigned int */
  3824. typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
  3825. #define MBEDTLS_HAVE_UDBL
  3826. #endif /* !MBEDTLS_NO_UDBL_DIVISION */
  3827. #elif defined(__ARMCC_VERSION) && defined(__aarch64__)
  3828. /*
  3829. * __ARMCC_VERSION is defined for both armcc and armclang and
  3830. * __aarch64__ is only defined by armclang when compiling 64-bit code
  3831. */
  3832. #if !defined(MBEDTLS_HAVE_INT64)
  3833. #define MBEDTLS_HAVE_INT64
  3834. #endif /* !MBEDTLS_HAVE_INT64 */
  3835. typedef int64_t mbedtls_mpi_sint;
  3836. typedef uint64_t mbedtls_mpi_uint;
  3837. #if !defined(MBEDTLS_NO_UDBL_DIVISION)
  3838. /* mbedtls_t_udbl defined as 128-bit unsigned int */
  3839. typedef __uint128_t mbedtls_t_udbl;
  3840. #define MBEDTLS_HAVE_UDBL
  3841. #endif /* !MBEDTLS_NO_UDBL_DIVISION */
  3842. #elif defined(MBEDTLS_HAVE_INT64)
  3843. /* Force 64-bit integers with unknown compiler */
  3844. typedef int64_t mbedtls_mpi_sint;
  3845. typedef uint64_t mbedtls_mpi_uint;
  3846. #endif
  3847. #endif /* !MBEDTLS_HAVE_INT32 */
  3848. #if !defined(MBEDTLS_HAVE_INT64)
  3849. /* Default to 32-bit compilation */
  3850. #if !defined(MBEDTLS_HAVE_INT32)
  3851. #define MBEDTLS_HAVE_INT32
  3852. #endif /* !MBEDTLS_HAVE_INT32 */
  3853. typedef int32_t mbedtls_mpi_sint;
  3854. typedef uint32_t mbedtls_mpi_uint;
  3855. #if !defined(MBEDTLS_NO_UDBL_DIVISION)
  3856. typedef uint64_t mbedtls_t_udbl;
  3857. #define MBEDTLS_HAVE_UDBL
  3858. #endif /* !MBEDTLS_NO_UDBL_DIVISION */
  3859. #endif /* !MBEDTLS_HAVE_INT64 */
  3860. #ifdef __cplusplus
  3861. extern "C" {
  3862. #endif
  3863. /**
  3864. * \brief MPI structure
  3865. */
  3866. typedef struct
  3867. {
  3868. int s; /*!< integer sign */
  3869. size_t n; /*!< total # of limbs */
  3870. mbedtls_mpi_uint *p; /*!< pointer to limbs */
  3871. }
  3872. mbedtls_mpi;
  3873. /**
  3874. * \brief Initialize one MPI (make internal references valid)
  3875. * This just makes it ready to be set or freed,
  3876. * but does not define a value for the MPI.
  3877. *
  3878. * \param X One MPI to initialize.
  3879. */
  3880. void mbedtls_mpi_init( mbedtls_mpi *X );
  3881. /**
  3882. * \brief Unallocate one MPI
  3883. *
  3884. * \param X One MPI to unallocate.
  3885. */
  3886. void mbedtls_mpi_free( mbedtls_mpi *X );
  3887. /**
  3888. * \brief Enlarge to the specified number of limbs
  3889. *
  3890. * \param X MPI to grow
  3891. * \param nblimbs The target number of limbs
  3892. *
  3893. * \return 0 if successful,
  3894. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  3895. */
  3896. int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs );
  3897. /**
  3898. * \brief Resize down, keeping at least the specified number of limbs
  3899. *
  3900. * \param X MPI to shrink
  3901. * \param nblimbs The minimum number of limbs to keep
  3902. *
  3903. * \return 0 if successful,
  3904. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  3905. */
  3906. int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs );
  3907. /**
  3908. * \brief Copy the contents of Y into X
  3909. *
  3910. * \param X Destination MPI
  3911. * \param Y Source MPI
  3912. *
  3913. * \return 0 if successful,
  3914. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  3915. */
  3916. int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y );
  3917. /**
  3918. * \brief Swap the contents of X and Y
  3919. *
  3920. * \param X First MPI value
  3921. * \param Y Second MPI value
  3922. */
  3923. void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y );
  3924. /**
  3925. * \brief Safe conditional assignement X = Y if assign is 1
  3926. *
  3927. * \param X MPI to conditionally assign to
  3928. * \param Y Value to be assigned
  3929. * \param assign 1: perform the assignment, 0: keep X's original value
  3930. *
  3931. * \return 0 if successful,
  3932. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  3933. *
  3934. * \note This function is equivalent to
  3935. * if( assign ) mbedtls_mpi_copy( X, Y );
  3936. * except that it avoids leaking any information about whether
  3937. * the assignment was done or not (the above code may leak
  3938. * information through branch prediction and/or memory access
  3939. * patterns analysis).
  3940. */
  3941. int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign );
  3942. /**
  3943. * \brief Safe conditional swap X <-> Y if swap is 1
  3944. *
  3945. * \param X First mbedtls_mpi value
  3946. * \param Y Second mbedtls_mpi value
  3947. * \param assign 1: perform the swap, 0: keep X and Y's original values
  3948. *
  3949. * \return 0 if successful,
  3950. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  3951. *
  3952. * \note This function is equivalent to
  3953. * if( assign ) mbedtls_mpi_swap( X, Y );
  3954. * except that it avoids leaking any information about whether
  3955. * the assignment was done or not (the above code may leak
  3956. * information through branch prediction and/or memory access
  3957. * patterns analysis).
  3958. */
  3959. int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign );
  3960. /**
  3961. * \brief Set value from integer
  3962. *
  3963. * \param X MPI to set
  3964. * \param z Value to use
  3965. *
  3966. * \return 0 if successful,
  3967. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  3968. */
  3969. int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z );
  3970. /**
  3971. * \brief Get a specific bit from X
  3972. *
  3973. * \param X MPI to use
  3974. * \param pos Zero-based index of the bit in X
  3975. *
  3976. * \return Either a 0 or a 1
  3977. */
  3978. int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos );
  3979. /**
  3980. * \brief Set a bit of X to a specific value of 0 or 1
  3981. *
  3982. * \note Will grow X if necessary to set a bit to 1 in a not yet
  3983. * existing limb. Will not grow if bit should be set to 0
  3984. *
  3985. * \param X MPI to use
  3986. * \param pos Zero-based index of the bit in X
  3987. * \param val The value to set the bit to (0 or 1)
  3988. *
  3989. * \return 0 if successful,
  3990. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  3991. * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if val is not 0 or 1
  3992. */
  3993. int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val );
  3994. /**
  3995. * \brief Return the number of zero-bits before the least significant
  3996. * '1' bit
  3997. *
  3998. * Note: Thus also the zero-based index of the least significant '1' bit
  3999. *
  4000. * \param X MPI to use
  4001. */
  4002. size_t mbedtls_mpi_lsb( const mbedtls_mpi *X );
  4003. /**
  4004. * \brief Return the number of bits up to and including the most
  4005. * significant '1' bit'
  4006. *
  4007. * Note: Thus also the one-based index of the most significant '1' bit
  4008. *
  4009. * \param X MPI to use
  4010. */
  4011. size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X );
  4012. /**
  4013. * \brief Return the total size in bytes
  4014. *
  4015. * \param X MPI to use
  4016. */
  4017. size_t mbedtls_mpi_size( const mbedtls_mpi *X );
  4018. /**
  4019. * \brief Import from an ASCII string
  4020. *
  4021. * \param X Destination MPI
  4022. * \param radix Input numeric base
  4023. * \param s Null-terminated string buffer
  4024. *
  4025. * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
  4026. */
  4027. int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s );
  4028. /**
  4029. * \brief Export into an ASCII string
  4030. *
  4031. * \param X Source MPI
  4032. * \param radix Output numeric base
  4033. * \param buf Buffer to write the string to
  4034. * \param buflen Length of buf
  4035. * \param olen Length of the string written, including final NUL byte
  4036. *
  4037. * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code.
  4038. * *olen is always updated to reflect the amount
  4039. * of data that has (or would have) been written.
  4040. *
  4041. * \note Call this function with buflen = 0 to obtain the
  4042. * minimum required buffer size in *olen.
  4043. */
  4044. int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
  4045. char *buf, size_t buflen, size_t *olen );
  4046. #if defined(MBEDTLS_FS_IO)
  4047. /**
  4048. * \brief Read MPI from a line in an opened file
  4049. *
  4050. * \param X Destination MPI
  4051. * \param radix Input numeric base
  4052. * \param fin Input file handle
  4053. *
  4054. * \return 0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if
  4055. * the file read buffer is too small or a
  4056. * MBEDTLS_ERR_MPI_XXX error code
  4057. *
  4058. * \note On success, this function advances the file stream
  4059. * to the end of the current line or to EOF.
  4060. *
  4061. * The function returns 0 on an empty line.
  4062. *
  4063. * Leading whitespaces are ignored, as is a
  4064. * '0x' prefix for radix 16.
  4065. *
  4066. */
  4067. int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
  4068. /**
  4069. * \brief Write X into an opened file, or stdout if fout is NULL
  4070. *
  4071. * \param p Prefix, can be NULL
  4072. * \param X Source MPI
  4073. * \param radix Output numeric base
  4074. * \param fout Output file handle (can be NULL)
  4075. *
  4076. * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
  4077. *
  4078. * \note Set fout == NULL to print X on the console.
  4079. */
  4080. int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE *fout );
  4081. #endif /* MBEDTLS_FS_IO */
  4082. /**
  4083. * \brief Import X from unsigned binary data, big endian
  4084. *
  4085. * \param X Destination MPI
  4086. * \param buf Input buffer
  4087. * \param buflen Input buffer size
  4088. *
  4089. * \return 0 if successful,
  4090. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4091. */
  4092. int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen );
  4093. /**
  4094. * \brief Export X into unsigned binary data, big endian.
  4095. * Always fills the whole buffer, which will start with zeros
  4096. * if the number is smaller.
  4097. *
  4098. * \param X Source MPI
  4099. * \param buf Output buffer
  4100. * \param buflen Output buffer size
  4101. *
  4102. * \return 0 if successful,
  4103. * MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough
  4104. */
  4105. int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf, size_t buflen );
  4106. /**
  4107. * \brief Left-shift: X <<= count
  4108. *
  4109. * \param X MPI to shift
  4110. * \param count Amount to shift
  4111. *
  4112. * \return 0 if successful,
  4113. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4114. */
  4115. int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count );
  4116. /**
  4117. * \brief Right-shift: X >>= count
  4118. *
  4119. * \param X MPI to shift
  4120. * \param count Amount to shift
  4121. *
  4122. * \return 0 if successful,
  4123. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4124. */
  4125. int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count );
  4126. /**
  4127. * \brief Compare unsigned values
  4128. *
  4129. * \param X Left-hand MPI
  4130. * \param Y Right-hand MPI
  4131. *
  4132. * \return 1 if |X| is greater than |Y|,
  4133. * -1 if |X| is lesser than |Y| or
  4134. * 0 if |X| is equal to |Y|
  4135. */
  4136. int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y );
  4137. /**
  4138. * \brief Compare signed values
  4139. *
  4140. * \param X Left-hand MPI
  4141. * \param Y Right-hand MPI
  4142. *
  4143. * \return 1 if X is greater than Y,
  4144. * -1 if X is lesser than Y or
  4145. * 0 if X is equal to Y
  4146. */
  4147. int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y );
  4148. /**
  4149. * \brief Compare signed values
  4150. *
  4151. * \param X Left-hand MPI
  4152. * \param z The integer value to compare to
  4153. *
  4154. * \return 1 if X is greater than z,
  4155. * -1 if X is lesser than z or
  4156. * 0 if X is equal to z
  4157. */
  4158. int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z );
  4159. /**
  4160. * \brief Unsigned addition: X = |A| + |B|
  4161. *
  4162. * \param X Destination MPI
  4163. * \param A Left-hand MPI
  4164. * \param B Right-hand MPI
  4165. *
  4166. * \return 0 if successful,
  4167. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4168. */
  4169. int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
  4170. /**
  4171. * \brief Unsigned subtraction: X = |A| - |B|
  4172. *
  4173. * \param X Destination MPI
  4174. * \param A Left-hand MPI
  4175. * \param B Right-hand MPI
  4176. *
  4177. * \return 0 if successful,
  4178. * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B is greater than A
  4179. */
  4180. int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
  4181. /**
  4182. * \brief Signed addition: X = A + B
  4183. *
  4184. * \param X Destination MPI
  4185. * \param A Left-hand MPI
  4186. * \param B Right-hand MPI
  4187. *
  4188. * \return 0 if successful,
  4189. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4190. */
  4191. int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
  4192. /**
  4193. * \brief Signed subtraction: X = A - B
  4194. *
  4195. * \param X Destination MPI
  4196. * \param A Left-hand MPI
  4197. * \param B Right-hand MPI
  4198. *
  4199. * \return 0 if successful,
  4200. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4201. */
  4202. int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
  4203. /**
  4204. * \brief Signed addition: X = A + b
  4205. *
  4206. * \param X Destination MPI
  4207. * \param A Left-hand MPI
  4208. * \param b The integer value to add
  4209. *
  4210. * \return 0 if successful,
  4211. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4212. */
  4213. int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b );
  4214. /**
  4215. * \brief Signed subtraction: X = A - b
  4216. *
  4217. * \param X Destination MPI
  4218. * \param A Left-hand MPI
  4219. * \param b The integer value to subtract
  4220. *
  4221. * \return 0 if successful,
  4222. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4223. */
  4224. int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b );
  4225. /**
  4226. * \brief Baseline multiplication: X = A * B
  4227. *
  4228. * \param X Destination MPI
  4229. * \param A Left-hand MPI
  4230. * \param B Right-hand MPI
  4231. *
  4232. * \return 0 if successful,
  4233. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4234. */
  4235. int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B );
  4236. /**
  4237. * \brief Baseline multiplication: X = A * b
  4238. *
  4239. * \param X Destination MPI
  4240. * \param A Left-hand MPI
  4241. * \param b The unsigned integer value to multiply with
  4242. *
  4243. * \note b is unsigned
  4244. *
  4245. * \return 0 if successful,
  4246. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4247. */
  4248. int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b );
  4249. /**
  4250. * \brief Division by mbedtls_mpi: A = Q * B + R
  4251. *
  4252. * \param Q Destination MPI for the quotient
  4253. * \param R Destination MPI for the rest value
  4254. * \param A Left-hand MPI
  4255. * \param B Right-hand MPI
  4256. *
  4257. * \return 0 if successful,
  4258. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  4259. * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0
  4260. *
  4261. * \note Either Q or R can be NULL.
  4262. */
  4263. int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B );
  4264. /**
  4265. * \brief Division by int: A = Q * b + R
  4266. *
  4267. * \param Q Destination MPI for the quotient
  4268. * \param R Destination MPI for the rest value
  4269. * \param A Left-hand MPI
  4270. * \param b Integer to divide by
  4271. *
  4272. * \return 0 if successful,
  4273. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  4274. * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0
  4275. *
  4276. * \note Either Q or R can be NULL.
  4277. */
  4278. int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b );
  4279. /**
  4280. * \brief Modulo: R = A mod B
  4281. *
  4282. * \param R Destination MPI for the rest value
  4283. * \param A Left-hand MPI
  4284. * \param B Right-hand MPI
  4285. *
  4286. * \return 0 if successful,
  4287. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  4288. * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0,
  4289. * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B < 0
  4290. */
  4291. int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B );
  4292. /**
  4293. * \brief Modulo: r = A mod b
  4294. *
  4295. * \param r Destination mbedtls_mpi_uint
  4296. * \param A Left-hand MPI
  4297. * \param b Integer to divide by
  4298. *
  4299. * \return 0 if successful,
  4300. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  4301. * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0,
  4302. * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if b < 0
  4303. */
  4304. int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b );
  4305. /**
  4306. * \brief Sliding-window exponentiation: X = A^E mod N
  4307. *
  4308. * \param X Destination MPI
  4309. * \param A Left-hand MPI
  4310. * \param E Exponent MPI
  4311. * \param N Modular MPI
  4312. * \param _RR Speed-up MPI used for recalculations
  4313. *
  4314. * \return 0 if successful,
  4315. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  4316. * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or even or
  4317. * if E is negative
  4318. *
  4319. * \note _RR is used to avoid re-computing R*R mod N across
  4320. * multiple calls, which speeds up things a bit. It can
  4321. * be set to NULL if the extra performance is unneeded.
  4322. */
  4323. int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *_RR );
  4324. /**
  4325. * \brief Fill an MPI X with size bytes of random
  4326. *
  4327. * \param X Destination MPI
  4328. * \param size Size in bytes
  4329. * \param f_rng RNG function
  4330. * \param p_rng RNG parameter
  4331. *
  4332. * \return 0 if successful,
  4333. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4334. *
  4335. * \note The bytes obtained from the PRNG are interpreted
  4336. * as a big-endian representation of an MPI; this can
  4337. * be relevant in applications like deterministic ECDSA.
  4338. */
  4339. int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size,
  4340. int (*f_rng)(void *, unsigned char *, size_t),
  4341. void *p_rng );
  4342. /**
  4343. * \brief Greatest common divisor: G = gcd(A, B)
  4344. *
  4345. * \param G Destination MPI
  4346. * \param A Left-hand MPI
  4347. * \param B Right-hand MPI
  4348. *
  4349. * \return 0 if successful,
  4350. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  4351. */
  4352. int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B );
  4353. /**
  4354. * \brief Modular inverse: X = A^-1 mod N
  4355. *
  4356. * \param X Destination MPI
  4357. * \param A Left-hand MPI
  4358. * \param N Right-hand MPI
  4359. *
  4360. * \return 0 if successful,
  4361. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  4362. * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is <= 1,
  4363. MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N.
  4364. */
  4365. int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N );
  4366. /**
  4367. * \brief Miller-Rabin primality test
  4368. *
  4369. * \param X MPI to check
  4370. * \param f_rng RNG function
  4371. * \param p_rng RNG parameter
  4372. *
  4373. * \return 0 if successful (probably prime),
  4374. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  4375. * MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if X is not prime
  4376. */
  4377. int mbedtls_mpi_is_prime( const mbedtls_mpi *X,
  4378. int (*f_rng)(void *, unsigned char *, size_t),
  4379. void *p_rng );
  4380. /**
  4381. * \brief Prime number generation
  4382. *
  4383. * \param X Destination MPI
  4384. * \param nbits Required size of X in bits
  4385. * ( 3 <= nbits <= MBEDTLS_MPI_MAX_BITS )
  4386. * \param dh_flag If 1, then (X-1)/2 will be prime too
  4387. * \param f_rng RNG function
  4388. * \param p_rng RNG parameter
  4389. *
  4390. * \return 0 if successful (probably prime),
  4391. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  4392. * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if nbits is < 3
  4393. */
  4394. int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag,
  4395. int (*f_rng)(void *, unsigned char *, size_t),
  4396. void *p_rng );
  4397. /**
  4398. * \brief Checkup routine
  4399. *
  4400. * \return 0 if successful, or 1 if the test failed
  4401. */
  4402. int mbedtls_mpi_self_test( int verbose );
  4403. #ifdef __cplusplus
  4404. }
  4405. #endif
  4406. #endif /* bignum.h */
  4407. /********* Start of file include/mbedtls/net.h ************/
  4408. /**
  4409. * \file net.h
  4410. *
  4411. * \brief Deprecated header file that includes mbedtls/net_sockets.h
  4412. *
  4413. * \deprecated Superseded by mbedtls/net_sockets.h
  4414. */
  4415. /*
  4416. * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
  4417. * SPDX-License-Identifier: Apache-2.0
  4418. *
  4419. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  4420. * not use this file except in compliance with the License.
  4421. * You may obtain a copy of the License at
  4422. *
  4423. * http://www.apache.org/licenses/LICENSE-2.0
  4424. *
  4425. * Unless required by applicable law or agreed to in writing, software
  4426. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  4427. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4428. * See the License for the specific language governing permissions and
  4429. * limitations under the License.
  4430. *
  4431. * This file is part of mbed TLS (https://tls.mbed.org)
  4432. */
  4433. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  4434. #if defined(MBEDTLS_DEPRECATED_WARNING)
  4435. #warning "Deprecated header file: Superseded by mbedtls/net_sockets.h"
  4436. #endif /* MBEDTLS_DEPRECATED_WARNING */
  4437. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  4438. /********* Start of file include/mbedtls/net_sockets.h ************/
  4439. /**
  4440. * \file net_sockets.h
  4441. *
  4442. * \brief Network communication functions
  4443. */
  4444. /*
  4445. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  4446. * SPDX-License-Identifier: Apache-2.0
  4447. *
  4448. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  4449. * not use this file except in compliance with the License.
  4450. * You may obtain a copy of the License at
  4451. *
  4452. * http://www.apache.org/licenses/LICENSE-2.0
  4453. *
  4454. * Unless required by applicable law or agreed to in writing, software
  4455. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  4456. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4457. * See the License for the specific language governing permissions and
  4458. * limitations under the License.
  4459. *
  4460. * This file is part of mbed TLS (https://tls.mbed.org)
  4461. */
  4462. #ifndef MBEDTLS_NET_SOCKETS_H
  4463. #define MBEDTLS_NET_SOCKETS_H
  4464. #if !defined(MBEDTLS_CONFIG_FILE)
  4465. #else
  4466. #endif
  4467. #include <stddef.h>
  4468. #include <stdint.h>
  4469. #define MBEDTLS_ERR_NET_SOCKET_FAILED -0x0042 /**< Failed to open a socket. */
  4470. #define MBEDTLS_ERR_NET_CONNECT_FAILED -0x0044 /**< The connection to the given server / port failed. */
  4471. #define MBEDTLS_ERR_NET_BIND_FAILED -0x0046 /**< Binding of the socket failed. */
  4472. #define MBEDTLS_ERR_NET_LISTEN_FAILED -0x0048 /**< Could not listen on the socket. */
  4473. #define MBEDTLS_ERR_NET_ACCEPT_FAILED -0x004A /**< Could not accept the incoming connection. */
  4474. #define MBEDTLS_ERR_NET_RECV_FAILED -0x004C /**< Reading information from the socket failed. */
  4475. #define MBEDTLS_ERR_NET_SEND_FAILED -0x004E /**< Sending information through the socket failed. */
  4476. #define MBEDTLS_ERR_NET_CONN_RESET -0x0050 /**< Connection was reset by peer. */
  4477. #define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052 /**< Failed to get an IP address for the given hostname. */
  4478. #define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043 /**< Buffer is too small to hold the data. */
  4479. #define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045 /**< The context is invalid, eg because it was free()ed. */
  4480. #define MBEDTLS_NET_LISTEN_BACKLOG 10 /**< The backlog that listen() should use. */
  4481. #define MBEDTLS_NET_PROTO_TCP 0 /**< The TCP transport protocol */
  4482. #define MBEDTLS_NET_PROTO_UDP 1 /**< The UDP transport protocol */
  4483. #ifdef __cplusplus
  4484. extern "C" {
  4485. #endif
  4486. /**
  4487. * Wrapper type for sockets.
  4488. *
  4489. * Currently backed by just a file descriptor, but might be more in the future
  4490. * (eg two file descriptors for combined IPv4 + IPv6 support, or additional
  4491. * structures for hand-made UDP demultiplexing).
  4492. */
  4493. typedef struct
  4494. {
  4495. int fd; /**< The underlying file descriptor */
  4496. }
  4497. mbedtls_net_context;
  4498. /**
  4499. * \brief Initialize a context
  4500. * Just makes the context ready to be used or freed safely.
  4501. *
  4502. * \param ctx Context to initialize
  4503. */
  4504. void mbedtls_net_init( mbedtls_net_context *ctx );
  4505. /**
  4506. * \brief Initiate a connection with host:port in the given protocol
  4507. *
  4508. * \param ctx Socket to use
  4509. * \param host Host to connect to
  4510. * \param port Port to connect to
  4511. * \param proto Protocol: MBEDTLS_NET_PROTO_TCP or MBEDTLS_NET_PROTO_UDP
  4512. *
  4513. * \return 0 if successful, or one of:
  4514. * MBEDTLS_ERR_NET_SOCKET_FAILED,
  4515. * MBEDTLS_ERR_NET_UNKNOWN_HOST,
  4516. * MBEDTLS_ERR_NET_CONNECT_FAILED
  4517. *
  4518. * \note Sets the socket in connected mode even with UDP.
  4519. */
  4520. int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto );
  4521. /**
  4522. * \brief Create a receiving socket on bind_ip:port in the chosen
  4523. * protocol. If bind_ip == NULL, all interfaces are bound.
  4524. *
  4525. * \param ctx Socket to use
  4526. * \param bind_ip IP to bind to, can be NULL
  4527. * \param port Port number to use
  4528. * \param proto Protocol: MBEDTLS_NET_PROTO_TCP or MBEDTLS_NET_PROTO_UDP
  4529. *
  4530. * \return 0 if successful, or one of:
  4531. * MBEDTLS_ERR_NET_SOCKET_FAILED,
  4532. * MBEDTLS_ERR_NET_BIND_FAILED,
  4533. * MBEDTLS_ERR_NET_LISTEN_FAILED
  4534. *
  4535. * \note Regardless of the protocol, opens the sockets and binds it.
  4536. * In addition, make the socket listening if protocol is TCP.
  4537. */
  4538. int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char *port, int proto );
  4539. /**
  4540. * \brief Accept a connection from a remote client
  4541. *
  4542. * \param bind_ctx Relevant socket
  4543. * \param client_ctx Will contain the connected client socket
  4544. * \param client_ip Will contain the client IP address
  4545. * \param buf_size Size of the client_ip buffer
  4546. * \param ip_len Will receive the size of the client IP written
  4547. *
  4548. * \return 0 if successful, or
  4549. * MBEDTLS_ERR_NET_ACCEPT_FAILED, or
  4550. * MBEDTLS_ERR_NET_BUFFER_TOO_SMALL if buf_size is too small,
  4551. * MBEDTLS_ERR_SSL_WANT_READ if bind_fd was set to
  4552. * non-blocking and accept() would block.
  4553. */
  4554. int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
  4555. mbedtls_net_context *client_ctx,
  4556. void *client_ip, size_t buf_size, size_t *ip_len );
  4557. /**
  4558. * \brief Set the socket blocking
  4559. *
  4560. * \param ctx Socket to set
  4561. *
  4562. * \return 0 if successful, or a non-zero error code
  4563. */
  4564. int mbedtls_net_set_block( mbedtls_net_context *ctx );
  4565. /**
  4566. * \brief Set the socket non-blocking
  4567. *
  4568. * \param ctx Socket to set
  4569. *
  4570. * \return 0 if successful, or a non-zero error code
  4571. */
  4572. int mbedtls_net_set_nonblock( mbedtls_net_context *ctx );
  4573. /**
  4574. * \brief Portable usleep helper
  4575. *
  4576. * \param usec Amount of microseconds to sleep
  4577. *
  4578. * \note Real amount of time slept will not be less than
  4579. * select()'s timeout granularity (typically, 10ms).
  4580. */
  4581. void mbedtls_net_usleep( unsigned long usec );
  4582. /**
  4583. * \brief Read at most 'len' characters. If no error occurs,
  4584. * the actual amount read is returned.
  4585. *
  4586. * \param ctx Socket
  4587. * \param buf The buffer to write to
  4588. * \param len Maximum length of the buffer
  4589. *
  4590. * \return the number of bytes received,
  4591. * or a non-zero error code; with a non-blocking socket,
  4592. * MBEDTLS_ERR_SSL_WANT_READ indicates read() would block.
  4593. */
  4594. int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len );
  4595. /**
  4596. * \brief Write at most 'len' characters. If no error occurs,
  4597. * the actual amount read is returned.
  4598. *
  4599. * \param ctx Socket
  4600. * \param buf The buffer to read from
  4601. * \param len The length of the buffer
  4602. *
  4603. * \return the number of bytes sent,
  4604. * or a non-zero error code; with a non-blocking socket,
  4605. * MBEDTLS_ERR_SSL_WANT_WRITE indicates write() would block.
  4606. */
  4607. int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len );
  4608. /**
  4609. * \brief Read at most 'len' characters, blocking for at most
  4610. * 'timeout' seconds. If no error occurs, the actual amount
  4611. * read is returned.
  4612. *
  4613. * \param ctx Socket
  4614. * \param buf The buffer to write to
  4615. * \param len Maximum length of the buffer
  4616. * \param timeout Maximum number of milliseconds to wait for data
  4617. * 0 means no timeout (wait forever)
  4618. *
  4619. * \return the number of bytes received,
  4620. * or a non-zero error code:
  4621. * MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out,
  4622. * MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal.
  4623. *
  4624. * \note This function will block (until data becomes available or
  4625. * timeout is reached) even if the socket is set to
  4626. * non-blocking. Handling timeouts with non-blocking reads
  4627. * requires a different strategy.
  4628. */
  4629. int mbedtls_net_recv_timeout( void *ctx, unsigned char *buf, size_t len,
  4630. uint32_t timeout );
  4631. /**
  4632. * \brief Gracefully shutdown the connection and free associated data
  4633. *
  4634. * \param ctx The context to free
  4635. */
  4636. void mbedtls_net_free( mbedtls_net_context *ctx );
  4637. #ifdef __cplusplus
  4638. }
  4639. #endif
  4640. #endif /* net_sockets.h */
  4641. /********* Start of file include/mbedtls/dhm.h ************/
  4642. /**
  4643. * \file dhm.h
  4644. *
  4645. * \brief Diffie-Hellman-Merkle key exchange.
  4646. *
  4647. * <em>RFC-3526: More Modular Exponential (MODP) Diffie-Hellman groups for
  4648. * Internet Key Exchange (IKE)</em> defines a number of standardized
  4649. * Diffie-Hellman groups for IKE.
  4650. *
  4651. * <em>RFC-5114: Additional Diffie-Hellman Groups for Use with IETF
  4652. * Standards</em> defines a number of standardized Diffie-Hellman
  4653. * groups that can be used.
  4654. *
  4655. * \warning The security of the DHM key exchange relies on the proper choice
  4656. * of prime modulus - optimally, it should be a safe prime. The usage
  4657. * of non-safe primes both decreases the difficulty of the underlying
  4658. * discrete logarithm problem and can lead to small subgroup attacks
  4659. * leaking private exponent bits when invalid public keys are used
  4660. * and not detected. This is especially relevant if the same DHM
  4661. * parameters are reused for multiple key exchanges as in static DHM,
  4662. * while the criticality of small-subgroup attacks is lower for
  4663. * ephemeral DHM.
  4664. *
  4665. * \warning For performance reasons, the code does neither perform primality
  4666. * nor safe primality tests, nor the expensive checks for invalid
  4667. * subgroups. Moreover, even if these were performed, non-standardized
  4668. * primes cannot be trusted because of the possibility of backdoors
  4669. * that can't be effectively checked for.
  4670. *
  4671. * \warning Diffie-Hellman-Merkle is therefore a security risk when not using
  4672. * standardized primes generated using a trustworthy ("nothing up
  4673. * my sleeve") method, such as the RFC 3526 / 7919 primes. In the TLS
  4674. * protocol, DH parameters need to be negotiated, so using the default
  4675. * primes systematically is not always an option. If possible, use
  4676. * Elliptic Curve Diffie-Hellman (ECDH), which has better performance,
  4677. * and for which the TLS protocol mandates the use of standard
  4678. * parameters.
  4679. *
  4680. */
  4681. /*
  4682. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  4683. * SPDX-License-Identifier: Apache-2.0
  4684. *
  4685. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  4686. * not use this file except in compliance with the License.
  4687. * You may obtain a copy of the License at
  4688. *
  4689. * http://www.apache.org/licenses/LICENSE-2.0
  4690. *
  4691. * Unless required by applicable law or agreed to in writing, software
  4692. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  4693. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4694. * See the License for the specific language governing permissions and
  4695. * limitations under the License.
  4696. *
  4697. * This file is part of Mbed TLS (https://tls.mbed.org)
  4698. */
  4699. #ifndef MBEDTLS_DHM_H
  4700. #define MBEDTLS_DHM_H
  4701. #if !defined(MBEDTLS_CONFIG_FILE)
  4702. #else
  4703. #endif
  4704. #if !defined(MBEDTLS_DHM_ALT)
  4705. /*
  4706. * DHM Error codes
  4707. */
  4708. #define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080 /**< Bad input parameters. */
  4709. #define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100 /**< Reading of the DHM parameters failed. */
  4710. #define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 /**< Making of the DHM parameters failed. */
  4711. #define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200 /**< Reading of the public values failed. */
  4712. #define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 /**< Making of the public value failed. */
  4713. #define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300 /**< Calculation of the DHM secret failed. */
  4714. #define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */
  4715. #define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 /**< Allocation of memory failed. */
  4716. #define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read or write of file failed. */
  4717. #define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500 /**< DHM hardware accelerator failed. */
  4718. #define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580 /**< Setting the modulus and generator failed. */
  4719. #ifdef __cplusplus
  4720. extern "C" {
  4721. #endif
  4722. /**
  4723. * \brief The DHM context structure.
  4724. */
  4725. typedef struct
  4726. {
  4727. size_t len; /*!< The size of \p P in Bytes. */
  4728. mbedtls_mpi P; /*!< The prime modulus. */
  4729. mbedtls_mpi G; /*!< The generator. */
  4730. mbedtls_mpi X; /*!< Our secret value. */
  4731. mbedtls_mpi GX; /*!< Our public key = \c G^X mod \c P. */
  4732. mbedtls_mpi GY; /*!< The public key of the peer = \c G^Y mod \c P. */
  4733. mbedtls_mpi K; /*!< The shared secret = \c G^(XY) mod \c P. */
  4734. mbedtls_mpi RP; /*!< The cached value = \c R^2 mod \c P. */
  4735. mbedtls_mpi Vi; /*!< The blinding value. */
  4736. mbedtls_mpi Vf; /*!< The unblinding value. */
  4737. mbedtls_mpi pX; /*!< The previous \c X. */
  4738. }
  4739. mbedtls_dhm_context;
  4740. /**
  4741. * \brief This function initializes the DHM context.
  4742. *
  4743. * \param ctx The DHM context to initialize.
  4744. */
  4745. void mbedtls_dhm_init( mbedtls_dhm_context *ctx );
  4746. /**
  4747. * \brief This function parses the ServerKeyExchange parameters.
  4748. *
  4749. * \param ctx The DHM context.
  4750. * \param p On input, *p must be the start of the input buffer.
  4751. * On output, *p is updated to point to the end of the data
  4752. * that has been read. On success, this is the first byte
  4753. * past the end of the ServerKeyExchange parameters.
  4754. * On error, this is the point at which an error has been
  4755. * detected, which is usually not useful except to debug
  4756. * failures.
  4757. * \param end The end of the input buffer.
  4758. *
  4759. * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
  4760. * on failure.
  4761. */
  4762. int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx,
  4763. unsigned char **p,
  4764. const unsigned char *end );
  4765. /**
  4766. * \brief This function sets up and writes the ServerKeyExchange
  4767. * parameters.
  4768. *
  4769. * \param ctx The DHM context.
  4770. * \param x_size The private value size in Bytes.
  4771. * \param olen The number of characters written.
  4772. * \param output The destination buffer.
  4773. * \param f_rng The RNG function.
  4774. * \param p_rng The RNG parameter.
  4775. *
  4776. * \note The destination buffer must be large enough to hold
  4777. * the reduced binary presentation of the modulus, the generator
  4778. * and the public key, each wrapped with a 2-byte length field.
  4779. * It is the responsibility of the caller to ensure that enough
  4780. * space is available. Refer to \c mbedtls_mpi_size to computing
  4781. * the byte-size of an MPI.
  4782. *
  4783. * \note This function assumes that \c ctx->P and \c ctx->G
  4784. * have already been properly set. For that, use
  4785. * mbedtls_dhm_set_group() below in conjunction with
  4786. * mbedtls_mpi_read_binary() and mbedtls_mpi_read_string().
  4787. *
  4788. * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
  4789. * on failure.
  4790. */
  4791. int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
  4792. unsigned char *output, size_t *olen,
  4793. int (*f_rng)(void *, unsigned char *, size_t),
  4794. void *p_rng );
  4795. /**
  4796. * \brief Set prime modulus and generator
  4797. *
  4798. * \param ctx The DHM context.
  4799. * \param P The MPI holding DHM prime modulus.
  4800. * \param G The MPI holding DHM generator.
  4801. *
  4802. * \note This function can be used to set P, G
  4803. * in preparation for \c mbedtls_dhm_make_params.
  4804. *
  4805. * \return \c 0 if successful, or an \c MBEDTLS_ERR_DHM_XXX error code
  4806. * on failure.
  4807. */
  4808. int mbedtls_dhm_set_group( mbedtls_dhm_context *ctx,
  4809. const mbedtls_mpi *P,
  4810. const mbedtls_mpi *G );
  4811. /**
  4812. * \brief This function imports the public value G^Y of the peer.
  4813. *
  4814. * \param ctx The DHM context.
  4815. * \param input The input buffer.
  4816. * \param ilen The size of the input buffer.
  4817. *
  4818. * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
  4819. * on failure.
  4820. */
  4821. int mbedtls_dhm_read_public( mbedtls_dhm_context *ctx,
  4822. const unsigned char *input, size_t ilen );
  4823. /**
  4824. * \brief This function creates its own private value \c X and
  4825. * exports \c G^X.
  4826. *
  4827. * \param ctx The DHM context.
  4828. * \param x_size The private value size in Bytes.
  4829. * \param output The destination buffer.
  4830. * \param olen The length of the destination buffer. Must be at least
  4831. equal to ctx->len (the size of \c P).
  4832. * \param f_rng The RNG function.
  4833. * \param p_rng The RNG parameter.
  4834. *
  4835. * \note The destination buffer will always be fully written
  4836. * so as to contain a big-endian presentation of G^X mod P.
  4837. * If it is larger than ctx->len, it will accordingly be
  4838. * padded with zero-bytes in the beginning.
  4839. *
  4840. * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
  4841. * on failure.
  4842. */
  4843. int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size,
  4844. unsigned char *output, size_t olen,
  4845. int (*f_rng)(void *, unsigned char *, size_t),
  4846. void *p_rng );
  4847. /**
  4848. * \brief This function derives and exports the shared secret
  4849. * \c (G^Y)^X mod \c P.
  4850. *
  4851. * \param ctx The DHM context.
  4852. * \param output The destination buffer.
  4853. * \param output_size The size of the destination buffer. Must be at least
  4854. * the size of ctx->len.
  4855. * \param olen On exit, holds the actual number of Bytes written.
  4856. * \param f_rng The RNG function, for blinding purposes.
  4857. * \param p_rng The RNG parameter.
  4858. *
  4859. * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code
  4860. * on failure.
  4861. *
  4862. * \note If non-NULL, \p f_rng is used to blind the input as
  4863. * a countermeasure against timing attacks. Blinding is used
  4864. * only if our secret value \p X is re-used and omitted
  4865. * otherwise. Therefore, we recommend always passing a
  4866. * non-NULL \p f_rng argument.
  4867. */
  4868. int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx,
  4869. unsigned char *output, size_t output_size, size_t *olen,
  4870. int (*f_rng)(void *, unsigned char *, size_t),
  4871. void *p_rng );
  4872. /**
  4873. * \brief This function frees and clears the components of a DHM key.
  4874. *
  4875. * \param ctx The DHM context to free and clear.
  4876. */
  4877. void mbedtls_dhm_free( mbedtls_dhm_context *ctx );
  4878. #if defined(MBEDTLS_ASN1_PARSE_C)
  4879. /** \ingroup x509_module */
  4880. /**
  4881. * \brief This function parses DHM parameters in PEM or DER format.
  4882. *
  4883. * \param dhm The DHM context to initialize.
  4884. * \param dhmin The input buffer.
  4885. * \param dhminlen The size of the buffer, including the terminating null
  4886. * Byte for PEM data.
  4887. *
  4888. * \return \c 0 on success, or a specific DHM or PEM error code
  4889. * on failure.
  4890. */
  4891. int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin,
  4892. size_t dhminlen );
  4893. #if defined(MBEDTLS_FS_IO)
  4894. /** \ingroup x509_module */
  4895. /**
  4896. * \brief This function loads and parses DHM parameters from a file.
  4897. *
  4898. * \param dhm The DHM context to load the parameters to.
  4899. * \param path The filename to read the DHM parameters from.
  4900. *
  4901. * \return \c 0 on success, or a specific DHM or PEM error code
  4902. * on failure.
  4903. */
  4904. int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
  4905. #endif /* MBEDTLS_FS_IO */
  4906. #endif /* MBEDTLS_ASN1_PARSE_C */
  4907. #ifdef __cplusplus
  4908. }
  4909. #endif
  4910. #else /* MBEDTLS_DHM_ALT */
  4911. #endif /* MBEDTLS_DHM_ALT */
  4912. #ifdef __cplusplus
  4913. extern "C" {
  4914. #endif
  4915. /**
  4916. * \brief The DMH checkup routine.
  4917. *
  4918. * \return \c 0 on success, or \c 1 on failure.
  4919. */
  4920. int mbedtls_dhm_self_test( int verbose );
  4921. #ifdef __cplusplus
  4922. }
  4923. #endif
  4924. /**
  4925. * RFC 3526, RFC 5114 and RFC 7919 standardize a number of
  4926. * Diffie-Hellman groups, some of which are included here
  4927. * for use within the SSL/TLS module and the user's convenience
  4928. * when configuring the Diffie-Hellman parameters by hand
  4929. * through \c mbedtls_ssl_conf_dh_param.
  4930. *
  4931. * The following lists the source of the above groups in the standards:
  4932. * - RFC 5114 section 2.2: 2048-bit MODP Group with 224-bit Prime Order Subgroup
  4933. * - RFC 3526 section 3: 2048-bit MODP Group
  4934. * - RFC 3526 section 4: 3072-bit MODP Group
  4935. * - RFC 3526 section 5: 4096-bit MODP Group
  4936. * - RFC 7919 section A.1: ffdhe2048
  4937. * - RFC 7919 section A.2: ffdhe3072
  4938. * - RFC 7919 section A.3: ffdhe4096
  4939. * - RFC 7919 section A.4: ffdhe6144
  4940. * - RFC 7919 section A.5: ffdhe8192
  4941. *
  4942. * The constants with suffix "_p" denote the chosen prime moduli, while
  4943. * the constants with suffix "_g" denote the chosen generator
  4944. * of the associated prime field.
  4945. *
  4946. * The constants further suffixed with "_bin" are provided in binary format,
  4947. * while all other constants represent null-terminated strings holding the
  4948. * hexadecimal presentation of the respective numbers.
  4949. *
  4950. * The primes from RFC 3526 and RFC 7919 have been generating by the following
  4951. * trust-worthy procedure:
  4952. * - Fix N in { 2048, 3072, 4096, 6144, 8192 } and consider the N-bit number
  4953. * the first and last 64 bits are all 1, and the remaining N - 128 bits of
  4954. * which are 0x7ff...ff.
  4955. * - Add the smallest multiple of the first N - 129 bits of the binary expansion
  4956. * of pi (for RFC 5236) or e (for RFC 7919) to this intermediate bit-string
  4957. * such that the resulting integer is a safe-prime.
  4958. * - The result is the respective RFC 3526 / 7919 prime, and the corresponding
  4959. * generator is always chosen to be 2 (which is a square for these prime,
  4960. * hence the corresponding subgroup has order (p-1)/2 and avoids leaking a
  4961. * bit in the private exponent).
  4962. *
  4963. */
  4964. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  4965. #if defined(MBEDTLS_DEPRECATED_WARNING)
  4966. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  4967. MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_constant_t;
  4968. #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \
  4969. ( (mbedtls_deprecated_constant_t) ( VAL ) )
  4970. #else
  4971. #define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL
  4972. #endif /* ! MBEDTLS_DEPRECATED_WARNING */
  4973. /**
  4974. * \warning The origin of the primes in RFC 5114 is not documented and
  4975. * their use therefore constitutes a security risk!
  4976. *
  4977. * \deprecated The hex-encoded primes from RFC 5114 are deprecated and are
  4978. * likely to be removed in a future version of the library without
  4979. * replacement.
  4980. */
  4981. /**
  4982. * The hexadecimal presentation of the prime underlying the
  4983. * 2048-bit MODP Group with 224-bit Prime Order Subgroup, as defined
  4984. * in <em>RFC-5114: Additional Diffie-Hellman Groups for Use with
  4985. * IETF Standards</em>.
  4986. */
  4987. #define MBEDTLS_DHM_RFC5114_MODP_2048_P \
  4988. MBEDTLS_DEPRECATED_STRING_CONSTANT( \
  4989. "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1" \
  4990. "B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15" \
  4991. "EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC212" \
  4992. "9037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207" \
  4993. "C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708" \
  4994. "B3BF8A317091883681286130BC8985DB1602E714415D9330" \
  4995. "278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486D" \
  4996. "CDF93ACC44328387315D75E198C641A480CD86A1B9E587E8" \
  4997. "BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763" \
  4998. "C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71" \
  4999. "CF9DE5384E71B81C0AC4DFFE0C10E64F" )
  5000. /**
  5001. * The hexadecimal presentation of the chosen generator of the 2048-bit MODP
  5002. * Group with 224-bit Prime Order Subgroup, as defined in <em>RFC-5114:
  5003. * Additional Diffie-Hellman Groups for Use with IETF Standards</em>.
  5004. */
  5005. #define MBEDTLS_DHM_RFC5114_MODP_2048_G \
  5006. MBEDTLS_DEPRECATED_STRING_CONSTANT( \
  5007. "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF" \
  5008. "74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFA" \
  5009. "AB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7" \
  5010. "C17669101999024AF4D027275AC1348BB8A762D0521BC98A" \
  5011. "E247150422EA1ED409939D54DA7460CDB5F6C6B250717CBE" \
  5012. "F180EB34118E98D119529A45D6F834566E3025E316A330EF" \
  5013. "BB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB" \
  5014. "10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381" \
  5015. "B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269" \
  5016. "EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC0179" \
  5017. "81BC087F2A7065B384B890D3191F2BFA" )
  5018. /**
  5019. * The hexadecimal presentation of the prime underlying the 2048-bit MODP
  5020. * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
  5021. * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
  5022. *
  5023. * \deprecated The hex-encoded primes from RFC 3625 are deprecated and
  5024. * superseded by the corresponding macros providing them as
  5025. * binary constants. Their hex-encoded constants are likely
  5026. * to be removed in a future version of the library.
  5027. *
  5028. */
  5029. #define MBEDTLS_DHM_RFC3526_MODP_2048_P \
  5030. MBEDTLS_DEPRECATED_STRING_CONSTANT( \
  5031. "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
  5032. "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
  5033. "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
  5034. "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
  5035. "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
  5036. "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
  5037. "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
  5038. "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
  5039. "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
  5040. "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
  5041. "15728E5A8AACAA68FFFFFFFFFFFFFFFF" )
  5042. /**
  5043. * The hexadecimal presentation of the chosen generator of the 2048-bit MODP
  5044. * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
  5045. * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
  5046. */
  5047. #define MBEDTLS_DHM_RFC3526_MODP_2048_G \
  5048. MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
  5049. /**
  5050. * The hexadecimal presentation of the prime underlying the 3072-bit MODP
  5051. * Group, as defined in <em>RFC-3072: More Modular Exponential (MODP)
  5052. * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
  5053. */
  5054. #define MBEDTLS_DHM_RFC3526_MODP_3072_P \
  5055. MBEDTLS_DEPRECATED_STRING_CONSTANT( \
  5056. "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
  5057. "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
  5058. "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
  5059. "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
  5060. "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
  5061. "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
  5062. "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
  5063. "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
  5064. "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
  5065. "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
  5066. "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
  5067. "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
  5068. "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
  5069. "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
  5070. "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
  5071. "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF" )
  5072. /**
  5073. * The hexadecimal presentation of the chosen generator of the 3072-bit MODP
  5074. * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
  5075. * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
  5076. */
  5077. #define MBEDTLS_DHM_RFC3526_MODP_3072_G \
  5078. MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
  5079. /**
  5080. * The hexadecimal presentation of the prime underlying the 4096-bit MODP
  5081. * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
  5082. * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
  5083. */
  5084. #define MBEDTLS_DHM_RFC3526_MODP_4096_P \
  5085. MBEDTLS_DEPRECATED_STRING_CONSTANT( \
  5086. "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
  5087. "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
  5088. "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
  5089. "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
  5090. "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
  5091. "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
  5092. "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
  5093. "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
  5094. "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
  5095. "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
  5096. "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
  5097. "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
  5098. "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
  5099. "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
  5100. "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
  5101. "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \
  5102. "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \
  5103. "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \
  5104. "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \
  5105. "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \
  5106. "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" \
  5107. "FFFFFFFFFFFFFFFF" )
  5108. /**
  5109. * The hexadecimal presentation of the chosen generator of the 4096-bit MODP
  5110. * Group, as defined in <em>RFC-3526: More Modular Exponential (MODP)
  5111. * Diffie-Hellman groups for Internet Key Exchange (IKE)</em>.
  5112. */
  5113. #define MBEDTLS_DHM_RFC3526_MODP_4096_G \
  5114. MBEDTLS_DEPRECATED_STRING_CONSTANT( "02" )
  5115. #endif /* MBEDTLS_DEPRECATED_REMOVED */
  5116. /*
  5117. * Trustworthy DHM parameters in binary form
  5118. */
  5119. #define MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN { \
  5120. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
  5121. 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
  5122. 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
  5123. 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
  5124. 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
  5125. 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
  5126. 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
  5127. 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
  5128. 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
  5129. 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
  5130. 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
  5131. 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
  5132. 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
  5133. 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
  5134. 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
  5135. 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
  5136. 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
  5137. 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
  5138. 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
  5139. 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
  5140. 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
  5141. 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
  5142. 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
  5143. 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
  5144. 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
  5145. 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
  5146. 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
  5147. 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
  5148. 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
  5149. 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
  5150. 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, \
  5151. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
  5152. #define MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN { 0x02 }
  5153. #define MBEDTLS_DHM_RFC3526_MODP_3072_P_BIN { \
  5154. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
  5155. 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
  5156. 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
  5157. 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
  5158. 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
  5159. 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
  5160. 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
  5161. 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
  5162. 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
  5163. 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
  5164. 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
  5165. 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
  5166. 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
  5167. 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
  5168. 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
  5169. 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
  5170. 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
  5171. 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
  5172. 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
  5173. 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
  5174. 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
  5175. 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
  5176. 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
  5177. 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
  5178. 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
  5179. 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
  5180. 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
  5181. 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
  5182. 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
  5183. 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
  5184. 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, \
  5185. 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, \
  5186. 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, \
  5187. 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, \
  5188. 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, \
  5189. 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, \
  5190. 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, \
  5191. 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, \
  5192. 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, \
  5193. 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, \
  5194. 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, \
  5195. 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, \
  5196. 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, \
  5197. 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, \
  5198. 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, \
  5199. 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, \
  5200. 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, 0xCA, \
  5201. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
  5202. #define MBEDTLS_DHM_RFC3526_MODP_3072_G_BIN { 0x02 }
  5203. #define MBEDTLS_DHM_RFC3526_MODP_4096_P_BIN { \
  5204. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
  5205. 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, \
  5206. 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, \
  5207. 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, \
  5208. 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, \
  5209. 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, \
  5210. 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, \
  5211. 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, \
  5212. 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, \
  5213. 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, \
  5214. 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, \
  5215. 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, \
  5216. 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, \
  5217. 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, \
  5218. 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \
  5219. 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, \
  5220. 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, \
  5221. 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, \
  5222. 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, \
  5223. 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, \
  5224. 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, \
  5225. 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, \
  5226. 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, \
  5227. 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, \
  5228. 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, \
  5229. 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, \
  5230. 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, \
  5231. 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, \
  5232. 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, \
  5233. 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, \
  5234. 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, \
  5235. 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, \
  5236. 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, \
  5237. 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, \
  5238. 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, \
  5239. 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, \
  5240. 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, \
  5241. 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, \
  5242. 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, \
  5243. 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, \
  5244. 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, \
  5245. 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, \
  5246. 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, \
  5247. 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, \
  5248. 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, \
  5249. 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, \
  5250. 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01, \
  5251. 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, \
  5252. 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, \
  5253. 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C, \
  5254. 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, \
  5255. 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, \
  5256. 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, \
  5257. 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6, \
  5258. 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, \
  5259. 0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2, \
  5260. 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, \
  5261. 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF, \
  5262. 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, \
  5263. 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9, \
  5264. 0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, \
  5265. 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F, \
  5266. 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, \
  5267. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
  5268. #define MBEDTLS_DHM_RFC3526_MODP_4096_G_BIN { 0x02 }
  5269. #define MBEDTLS_DHM_RFC7919_FFDHE2048_P_BIN { \
  5270. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
  5271. 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
  5272. 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
  5273. 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
  5274. 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
  5275. 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
  5276. 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
  5277. 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
  5278. 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
  5279. 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
  5280. 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
  5281. 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
  5282. 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
  5283. 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
  5284. 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
  5285. 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
  5286. 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
  5287. 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
  5288. 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
  5289. 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
  5290. 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
  5291. 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
  5292. 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
  5293. 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
  5294. 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
  5295. 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
  5296. 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
  5297. 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
  5298. 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
  5299. 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
  5300. 0x88, 0x6B, 0x42, 0x38, 0x61, 0x28, 0x5C, 0x97, \
  5301. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }
  5302. #define MBEDTLS_DHM_RFC7919_FFDHE2048_G_BIN { 0x02 }
  5303. #define MBEDTLS_DHM_RFC7919_FFDHE3072_P_BIN { \
  5304. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
  5305. 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
  5306. 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
  5307. 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
  5308. 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
  5309. 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
  5310. 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
  5311. 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
  5312. 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
  5313. 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
  5314. 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
  5315. 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
  5316. 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
  5317. 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
  5318. 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
  5319. 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
  5320. 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
  5321. 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
  5322. 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
  5323. 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
  5324. 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
  5325. 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
  5326. 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
  5327. 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
  5328. 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
  5329. 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
  5330. 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
  5331. 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
  5332. 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
  5333. 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
  5334. 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
  5335. 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
  5336. 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
  5337. 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
  5338. 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
  5339. 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
  5340. 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
  5341. 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
  5342. 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
  5343. 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
  5344. 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
  5345. 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
  5346. 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
  5347. 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
  5348. 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
  5349. 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
  5350. 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, 0x37, \
  5351. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
  5352. #define MBEDTLS_DHM_RFC7919_FFDHE3072_G_BIN { 0x02 }
  5353. #define MBEDTLS_DHM_RFC7919_FFDHE4096_P_BIN { \
  5354. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
  5355. 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
  5356. 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
  5357. 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
  5358. 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
  5359. 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
  5360. 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
  5361. 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
  5362. 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
  5363. 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
  5364. 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
  5365. 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
  5366. 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
  5367. 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
  5368. 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
  5369. 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
  5370. 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
  5371. 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
  5372. 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
  5373. 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
  5374. 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
  5375. 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
  5376. 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
  5377. 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
  5378. 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
  5379. 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
  5380. 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
  5381. 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
  5382. 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
  5383. 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
  5384. 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
  5385. 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
  5386. 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
  5387. 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
  5388. 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
  5389. 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
  5390. 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
  5391. 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
  5392. 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
  5393. 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
  5394. 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
  5395. 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
  5396. 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
  5397. 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
  5398. 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
  5399. 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
  5400. 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
  5401. 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
  5402. 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
  5403. 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
  5404. 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
  5405. 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
  5406. 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
  5407. 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
  5408. 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
  5409. 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
  5410. 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
  5411. 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
  5412. 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
  5413. 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
  5414. 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
  5415. 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
  5416. 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A, \
  5417. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
  5418. #define MBEDTLS_DHM_RFC7919_FFDHE4096_G_BIN { 0x02 }
  5419. #define MBEDTLS_DHM_RFC7919_FFDHE6144_P_BIN { \
  5420. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
  5421. 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
  5422. 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
  5423. 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
  5424. 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
  5425. 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
  5426. 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
  5427. 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
  5428. 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
  5429. 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
  5430. 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
  5431. 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
  5432. 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
  5433. 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
  5434. 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
  5435. 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
  5436. 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
  5437. 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
  5438. 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
  5439. 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
  5440. 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
  5441. 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
  5442. 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
  5443. 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
  5444. 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
  5445. 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
  5446. 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
  5447. 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
  5448. 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
  5449. 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
  5450. 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
  5451. 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
  5452. 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
  5453. 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
  5454. 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
  5455. 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
  5456. 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
  5457. 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
  5458. 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
  5459. 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
  5460. 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
  5461. 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
  5462. 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
  5463. 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
  5464. 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
  5465. 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
  5466. 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
  5467. 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
  5468. 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
  5469. 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
  5470. 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
  5471. 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
  5472. 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
  5473. 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
  5474. 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
  5475. 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
  5476. 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
  5477. 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
  5478. 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
  5479. 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
  5480. 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
  5481. 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
  5482. 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, \
  5483. 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, \
  5484. 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, \
  5485. 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, \
  5486. 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, \
  5487. 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, \
  5488. 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, \
  5489. 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, \
  5490. 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, \
  5491. 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, \
  5492. 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, \
  5493. 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, \
  5494. 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, \
  5495. 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, \
  5496. 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, \
  5497. 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, \
  5498. 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, \
  5499. 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, \
  5500. 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, \
  5501. 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, \
  5502. 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, \
  5503. 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, \
  5504. 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, \
  5505. 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, \
  5506. 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, \
  5507. 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, \
  5508. 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, \
  5509. 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, \
  5510. 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, \
  5511. 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, \
  5512. 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, \
  5513. 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, \
  5514. 0xA4, 0x0E, 0x32, 0x9C, 0xD0, 0xE4, 0x0E, 0x65, \
  5515. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
  5516. #define MBEDTLS_DHM_RFC7919_FFDHE6144_G_BIN { 0x02 }
  5517. #define MBEDTLS_DHM_RFC7919_FFDHE8192_P_BIN { \
  5518. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \
  5519. 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, \
  5520. 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, \
  5521. 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, \
  5522. 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, \
  5523. 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, \
  5524. 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, \
  5525. 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, \
  5526. 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, 0xFD, 0x65, 0x61, \
  5527. 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, \
  5528. 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, \
  5529. 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, \
  5530. 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, \
  5531. 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, \
  5532. 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \
  5533. 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, \
  5534. 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, \
  5535. 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, \
  5536. 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, \
  5537. 0x1D, 0x4F, 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, \
  5538. 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, \
  5539. 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, \
  5540. 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, \
  5541. 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, \
  5542. 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, \
  5543. 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, \
  5544. 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, \
  5545. 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, 0x20, 0x05, \
  5546. 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, \
  5547. 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, \
  5548. 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, \
  5549. 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \
  5550. 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, \
  5551. 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, \
  5552. 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, \
  5553. 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, \
  5554. 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, \
  5555. 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, \
  5556. 0xF4, 0xFD, 0x44, 0x52, 0xE2, 0xD7, 0x4D, 0xD3, \
  5557. 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, \
  5558. 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, \
  5559. 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, \
  5560. 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, \
  5561. 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, \
  5562. 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, \
  5563. 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, \
  5564. 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, 0xF1, \
  5565. 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, \
  5566. 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \
  5567. 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, \
  5568. 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, \
  5569. 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, \
  5570. 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, \
  5571. 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, \
  5572. 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, \
  5573. 0x6D, 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, \
  5574. 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, \
  5575. 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, 0x3C, \
  5576. 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, \
  5577. 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, \
  5578. 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, \
  5579. 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, \
  5580. 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, \
  5581. 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, 0x7A, \
  5582. 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, \
  5583. 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, \
  5584. 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, \
  5585. 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, \
  5586. 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, \
  5587. 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, \
  5588. 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, \
  5589. 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, \
  5590. 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, \
  5591. 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, \
  5592. 0xA0, 0x0E, 0xF0, 0x92, 0x35, 0x05, 0x11, 0xE3, \
  5593. 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, \
  5594. 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, \
  5595. 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, \
  5596. 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, \
  5597. 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, \
  5598. 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, \
  5599. 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, \
  5600. 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, \
  5601. 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, \
  5602. 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, \
  5603. 0x62, 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, \
  5604. 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, \
  5605. 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, \
  5606. 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, \
  5607. 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, \
  5608. 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, \
  5609. 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, \
  5610. 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, \
  5611. 0xA4, 0x1D, 0x57, 0x0D, 0x79, 0x38, 0xDA, 0xD4, \
  5612. 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA, \
  5613. 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, 0xC8, 0x38, \
  5614. 0x1E, 0x42, 0x5A, 0x31, 0xD9, 0x51, 0xAE, 0x64, \
  5615. 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, 0x43, \
  5616. 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E, \
  5617. 0x0B, 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF, \
  5618. 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29, \
  5619. 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, 0x65, \
  5620. 0xCB, 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02, \
  5621. 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4, \
  5622. 0x54, 0x50, 0x4A, 0xC7, 0x8B, 0x75, 0x82, 0x82, \
  5623. 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C, \
  5624. 0x59, 0x16, 0x0C, 0xC0, 0x46, 0xFD, 0x82, 0x51, \
  5625. 0x54, 0x1F, 0xC6, 0x8C, 0x9C, 0x86, 0xB0, 0x22, \
  5626. 0xBB, 0x70, 0x99, 0x87, 0x6A, 0x46, 0x0E, 0x74, \
  5627. 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE, \
  5628. 0x1C, 0x21, 0x7E, 0x6C, 0x38, 0x26, 0xE5, 0x2C, \
  5629. 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC, \
  5630. 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, 0x21, 0x7B, \
  5631. 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9, \
  5632. 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, 0xA0, \
  5633. 0xA1, 0xFE, 0x30, 0x75, 0xA5, 0x77, 0xE2, 0x31, \
  5634. 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57, \
  5635. 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8, \
  5636. 0xB6, 0x85, 0x5D, 0xFE, 0x72, 0xB0, 0xA6, 0x6E, \
  5637. 0xDE, 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30, \
  5638. 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E, \
  5639. 0x2F, 0x74, 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE, \
  5640. 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D, \
  5641. 0x97, 0xD1, 0x1D, 0x49, 0xF7, 0xA8, 0x44, 0x3D, \
  5642. 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E, \
  5643. 0x01, 0x1E, 0x2A, 0x94, 0x83, 0x8F, 0xF8, 0x8C, \
  5644. 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, 0xC6, 0x42, 0x4C, \
  5645. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
  5646. #define MBEDTLS_DHM_RFC7919_FFDHE8192_G_BIN { 0x02 }
  5647. #endif /* dhm.h */
  5648. /********* Start of file include/mbedtls/error.h ************/
  5649. /**
  5650. * \file error.h
  5651. *
  5652. * \brief Error to string translation
  5653. */
  5654. /*
  5655. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  5656. * SPDX-License-Identifier: Apache-2.0
  5657. *
  5658. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  5659. * not use this file except in compliance with the License.
  5660. * You may obtain a copy of the License at
  5661. *
  5662. * http://www.apache.org/licenses/LICENSE-2.0
  5663. *
  5664. * Unless required by applicable law or agreed to in writing, software
  5665. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  5666. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5667. * See the License for the specific language governing permissions and
  5668. * limitations under the License.
  5669. *
  5670. * This file is part of mbed TLS (https://tls.mbed.org)
  5671. */
  5672. #ifndef MBEDTLS_ERROR_H
  5673. #define MBEDTLS_ERROR_H
  5674. #include <stddef.h>
  5675. /**
  5676. * Error code layout.
  5677. *
  5678. * Currently we try to keep all error codes within the negative space of 16
  5679. * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In
  5680. * addition we'd like to give two layers of information on the error if
  5681. * possible.
  5682. *
  5683. * For that purpose the error codes are segmented in the following manner:
  5684. *
  5685. * 16 bit error code bit-segmentation
  5686. *
  5687. * 1 bit - Unused (sign bit)
  5688. * 3 bits - High level module ID
  5689. * 5 bits - Module-dependent error code
  5690. * 7 bits - Low level module errors
  5691. *
  5692. * For historical reasons, low-level error codes are divided in even and odd,
  5693. * even codes were assigned first, and -1 is reserved for other errors.
  5694. *
  5695. * Low-level module errors (0x0002-0x007E, 0x0003-0x007F)
  5696. *
  5697. * Module Nr Codes assigned
  5698. * MPI 7 0x0002-0x0010
  5699. * GCM 3 0x0012-0x0014 0x0013-0x0013
  5700. * BLOWFISH 3 0x0016-0x0018 0x0017-0x0017
  5701. * THREADING 3 0x001A-0x001E
  5702. * AES 4 0x0020-0x0022 0x0023-0x0025
  5703. * CAMELLIA 3 0x0024-0x0026 0x0027-0x0027
  5704. * XTEA 2 0x0028-0x0028 0x0029-0x0029
  5705. * BASE64 2 0x002A-0x002C
  5706. * OID 1 0x002E-0x002E 0x000B-0x000B
  5707. * PADLOCK 1 0x0030-0x0030
  5708. * DES 2 0x0032-0x0032 0x0033-0x0033
  5709. * CTR_DBRG 4 0x0034-0x003A
  5710. * ENTROPY 3 0x003C-0x0040 0x003D-0x003F
  5711. * NET 11 0x0042-0x0052 0x0043-0x0045
  5712. * ASN1 7 0x0060-0x006C
  5713. * CMAC 1 0x007A-0x007A
  5714. * PBKDF2 1 0x007C-0x007C
  5715. * HMAC_DRBG 4 0x0003-0x0009
  5716. * CCM 3 0x000D-0x0011
  5717. * ARC4 1 0x0019-0x0019
  5718. * MD2 1 0x002B-0x002B
  5719. * MD4 1 0x002D-0x002D
  5720. * MD5 1 0x002F-0x002F
  5721. * RIPEMD160 1 0x0031-0x0031
  5722. * SHA1 1 0x0035-0x0035
  5723. * SHA256 1 0x0037-0x0037
  5724. * SHA512 1 0x0039-0x0039
  5725. *
  5726. * High-level module nr (3 bits - 0x0...-0x7...)
  5727. * Name ID Nr of Errors
  5728. * PEM 1 9
  5729. * PKCS#12 1 4 (Started from top)
  5730. * X509 2 20
  5731. * PKCS5 2 4 (Started from top)
  5732. * DHM 3 11
  5733. * PK 3 15 (Started from top)
  5734. * RSA 4 11
  5735. * ECP 4 9 (Started from top)
  5736. * MD 5 5
  5737. * CIPHER 6 8
  5738. * SSL 6 17 (Started from top)
  5739. * SSL 7 31
  5740. *
  5741. * Module dependent error code (5 bits 0x.00.-0x.F8.)
  5742. */
  5743. #ifdef __cplusplus
  5744. extern "C" {
  5745. #endif
  5746. /**
  5747. * \brief Translate a mbed TLS error code into a string representation,
  5748. * Result is truncated if necessary and always includes a terminating
  5749. * null byte.
  5750. *
  5751. * \param errnum error code
  5752. * \param buffer buffer to place representation in
  5753. * \param buflen length of the buffer
  5754. */
  5755. void mbedtls_strerror( int errnum, char *buffer, size_t buflen );
  5756. #ifdef __cplusplus
  5757. }
  5758. #endif
  5759. #endif /* error.h */
  5760. /********* Start of file include/mbedtls/md.h ************/
  5761. /**
  5762. * \file md.h
  5763. *
  5764. * \brief The generic message-digest wrapper.
  5765. *
  5766. * \author Adriaan de Jong <dejong@fox-it.com>
  5767. */
  5768. /*
  5769. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  5770. * SPDX-License-Identifier: Apache-2.0
  5771. *
  5772. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  5773. * not use this file except in compliance with the License.
  5774. * You may obtain a copy of the License at
  5775. *
  5776. * http://www.apache.org/licenses/LICENSE-2.0
  5777. *
  5778. * Unless required by applicable law or agreed to in writing, software
  5779. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  5780. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5781. * See the License for the specific language governing permissions and
  5782. * limitations under the License.
  5783. *
  5784. * This file is part of Mbed TLS (https://tls.mbed.org)
  5785. */
  5786. #ifndef MBEDTLS_MD_H
  5787. #define MBEDTLS_MD_H
  5788. #include <stddef.h>
  5789. #if !defined(MBEDTLS_CONFIG_FILE)
  5790. #else
  5791. #endif
  5792. #define MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE -0x5080 /**< The selected feature is not available. */
  5793. #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */
  5794. #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */
  5795. #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */
  5796. #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280 /**< MD hardware accelerator failed. */
  5797. #ifdef __cplusplus
  5798. extern "C" {
  5799. #endif
  5800. /**
  5801. * \brief Enumeration of supported message digests
  5802. *
  5803. * \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and
  5804. * their use constitutes a security risk. We recommend considering
  5805. * stronger message digests instead.
  5806. *
  5807. */
  5808. typedef enum {
  5809. MBEDTLS_MD_NONE=0,
  5810. MBEDTLS_MD_MD2,
  5811. MBEDTLS_MD_MD4,
  5812. MBEDTLS_MD_MD5,
  5813. MBEDTLS_MD_SHA1,
  5814. MBEDTLS_MD_SHA224,
  5815. MBEDTLS_MD_SHA256,
  5816. MBEDTLS_MD_SHA384,
  5817. MBEDTLS_MD_SHA512,
  5818. MBEDTLS_MD_RIPEMD160,
  5819. } mbedtls_md_type_t;
  5820. #if defined(MBEDTLS_SHA512_C)
  5821. #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */
  5822. #else
  5823. #define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */
  5824. #endif
  5825. /**
  5826. * Opaque struct defined in md_internal.h.
  5827. */
  5828. typedef struct mbedtls_md_info_t mbedtls_md_info_t;
  5829. /**
  5830. * The generic message-digest context.
  5831. */
  5832. typedef struct {
  5833. /** Information about the associated message digest. */
  5834. const mbedtls_md_info_t *md_info;
  5835. /** The digest-specific context. */
  5836. void *md_ctx;
  5837. /** The HMAC part of the context. */
  5838. void *hmac_ctx;
  5839. } mbedtls_md_context_t;
  5840. /**
  5841. * \brief This function returns the list of digests supported by the
  5842. * generic digest module.
  5843. *
  5844. * \return A statically allocated array of digests. Each element
  5845. * in the returned list is an integer belonging to the
  5846. * message-digest enumeration #mbedtls_md_type_t.
  5847. * The last entry is 0.
  5848. */
  5849. const int *mbedtls_md_list( void );
  5850. /**
  5851. * \brief This function returns the message-digest information
  5852. * associated with the given digest name.
  5853. *
  5854. * \param md_name The name of the digest to search for.
  5855. *
  5856. * \return The message-digest information associated with \p md_name,
  5857. * or NULL if not found.
  5858. */
  5859. const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name );
  5860. /**
  5861. * \brief This function returns the message-digest information
  5862. * associated with the given digest type.
  5863. *
  5864. * \param md_type The type of digest to search for.
  5865. *
  5866. * \return The message-digest information associated with \p md_type,
  5867. * or NULL if not found.
  5868. */
  5869. const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type );
  5870. /**
  5871. * \brief This function initializes a message-digest context without
  5872. * binding it to a particular message-digest algorithm.
  5873. *
  5874. * This function should always be called first. It prepares the
  5875. * context for mbedtls_md_setup() for binding it to a
  5876. * message-digest algorithm.
  5877. */
  5878. void mbedtls_md_init( mbedtls_md_context_t *ctx );
  5879. /**
  5880. * \brief This function clears the internal structure of \p ctx and
  5881. * frees any embedded internal structure, but does not free
  5882. * \p ctx itself.
  5883. *
  5884. * If you have called mbedtls_md_setup() on \p ctx, you must
  5885. * call mbedtls_md_free() when you are no longer using the
  5886. * context.
  5887. * Calling this function if you have previously
  5888. * called mbedtls_md_init() and nothing else is optional.
  5889. * You must not call this function if you have not called
  5890. * mbedtls_md_init().
  5891. */
  5892. void mbedtls_md_free( mbedtls_md_context_t *ctx );
  5893. #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
  5894. #if defined(MBEDTLS_DEPRECATED_WARNING)
  5895. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  5896. #else
  5897. #define MBEDTLS_DEPRECATED
  5898. #endif
  5899. /**
  5900. * \brief This function selects the message digest algorithm to use,
  5901. * and allocates internal structures.
  5902. *
  5903. * It should be called after mbedtls_md_init() or mbedtls_md_free().
  5904. * Makes it necessary to call mbedtls_md_free() later.
  5905. *
  5906. * \deprecated Superseded by mbedtls_md_setup() in 2.0.0
  5907. *
  5908. * \param ctx The context to set up.
  5909. * \param md_info The information structure of the message-digest algorithm
  5910. * to use.
  5911. *
  5912. * \returns \c 0 on success,
  5913. * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure,
  5914. * #MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure.
  5915. */
  5916. int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED;
  5917. #undef MBEDTLS_DEPRECATED
  5918. #endif /* MBEDTLS_DEPRECATED_REMOVED */
  5919. /**
  5920. * \brief This function selects the message digest algorithm to use,
  5921. * and allocates internal structures.
  5922. *
  5923. * It should be called after mbedtls_md_init() or
  5924. * mbedtls_md_free(). Makes it necessary to call
  5925. * mbedtls_md_free() later.
  5926. *
  5927. * \param ctx The context to set up.
  5928. * \param md_info The information structure of the message-digest algorithm
  5929. * to use.
  5930. * \param hmac <ul><li>0: HMAC is not used. Saves some memory.</li>
  5931. * <li>non-zero: HMAC is used with this context.</li></ul>
  5932. *
  5933. * \returns \c 0 on success,
  5934. * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, or
  5935. * #MBEDTLS_ERR_MD_ALLOC_FAILED on memory allocation failure.
  5936. */
  5937. int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac );
  5938. /**
  5939. * \brief This function clones the state of an message-digest
  5940. * context.
  5941. *
  5942. * \note You must call mbedtls_md_setup() on \c dst before calling
  5943. * this function.
  5944. *
  5945. * \note The two contexts must have the same type,
  5946. * for example, both are SHA-256.
  5947. *
  5948. * \warning This function clones the message-digest state, not the
  5949. * HMAC state.
  5950. *
  5951. * \param dst The destination context.
  5952. * \param src The context to be cloned.
  5953. *
  5954. * \return \c 0 on success,
  5955. * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure.
  5956. */
  5957. int mbedtls_md_clone( mbedtls_md_context_t *dst,
  5958. const mbedtls_md_context_t *src );
  5959. /**
  5960. * \brief This function extracts the message-digest size from the
  5961. * message-digest information structure.
  5962. *
  5963. * \param md_info The information structure of the message-digest algorithm
  5964. * to use.
  5965. *
  5966. * \return The size of the message-digest output in Bytes.
  5967. */
  5968. unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info );
  5969. /**
  5970. * \brief This function extracts the message-digest type from the
  5971. * message-digest information structure.
  5972. *
  5973. * \param md_info The information structure of the message-digest algorithm
  5974. * to use.
  5975. *
  5976. * \return The type of the message digest.
  5977. */
  5978. mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info );
  5979. /**
  5980. * \brief This function extracts the message-digest name from the
  5981. * message-digest information structure.
  5982. *
  5983. * \param md_info The information structure of the message-digest algorithm
  5984. * to use.
  5985. *
  5986. * \return The name of the message digest.
  5987. */
  5988. const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info );
  5989. /**
  5990. * \brief This function starts a message-digest computation.
  5991. *
  5992. * You must call this function after setting up the context
  5993. * with mbedtls_md_setup(), and before passing data with
  5994. * mbedtls_md_update().
  5995. *
  5996. * \param ctx The generic message-digest context.
  5997. *
  5998. * \returns \c 0 on success, #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  5999. * parameter verification fails.
  6000. */
  6001. int mbedtls_md_starts( mbedtls_md_context_t *ctx );
  6002. /**
  6003. * \brief This function feeds an input buffer into an ongoing
  6004. * message-digest computation.
  6005. *
  6006. * You must call mbedtls_md_starts() before calling this
  6007. * function. You may call this function multiple times.
  6008. * Afterwards, call mbedtls_md_finish().
  6009. *
  6010. * \param ctx The generic message-digest context.
  6011. * \param input The buffer holding the input data.
  6012. * \param ilen The length of the input data.
  6013. *
  6014. * \returns \c 0 on success, #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  6015. * parameter verification fails.
  6016. */
  6017. int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen );
  6018. /**
  6019. * \brief This function finishes the digest operation,
  6020. * and writes the result to the output buffer.
  6021. *
  6022. * Call this function after a call to mbedtls_md_starts(),
  6023. * followed by any number of calls to mbedtls_md_update().
  6024. * Afterwards, you may either clear the context with
  6025. * mbedtls_md_free(), or call mbedtls_md_starts() to reuse
  6026. * the context for another digest operation with the same
  6027. * algorithm.
  6028. *
  6029. * \param ctx The generic message-digest context.
  6030. * \param output The buffer for the generic message-digest checksum result.
  6031. *
  6032. * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  6033. * parameter verification fails.
  6034. */
  6035. int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output );
  6036. /**
  6037. * \brief This function calculates the message-digest of a buffer,
  6038. * with respect to a configurable message-digest algorithm
  6039. * in a single call.
  6040. *
  6041. * The result is calculated as
  6042. * Output = message_digest(input buffer).
  6043. *
  6044. * \param md_info The information structure of the message-digest algorithm
  6045. * to use.
  6046. * \param input The buffer holding the data.
  6047. * \param ilen The length of the input data.
  6048. * \param output The generic message-digest checksum result.
  6049. *
  6050. * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  6051. * parameter verification fails.
  6052. */
  6053. int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen,
  6054. unsigned char *output );
  6055. #if defined(MBEDTLS_FS_IO)
  6056. /**
  6057. * \brief This function calculates the message-digest checksum
  6058. * result of the contents of the provided file.
  6059. *
  6060. * The result is calculated as
  6061. * Output = message_digest(file contents).
  6062. *
  6063. * \param md_info The information structure of the message-digest algorithm
  6064. * to use.
  6065. * \param path The input file name.
  6066. * \param output The generic message-digest checksum result.
  6067. *
  6068. * \return \c 0 on success,
  6069. * #MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed, or
  6070. * #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL.
  6071. */
  6072. int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path,
  6073. unsigned char *output );
  6074. #endif /* MBEDTLS_FS_IO */
  6075. /**
  6076. * \brief This function sets the HMAC key and prepares to
  6077. * authenticate a new message.
  6078. *
  6079. * Call this function after mbedtls_md_setup(), to use
  6080. * the MD context for an HMAC calculation, then call
  6081. * mbedtls_md_hmac_update() to provide the input data, and
  6082. * mbedtls_md_hmac_finish() to get the HMAC value.
  6083. *
  6084. * \param ctx The message digest context containing an embedded HMAC
  6085. * context.
  6086. * \param key The HMAC secret key.
  6087. * \param keylen The length of the HMAC key in Bytes.
  6088. *
  6089. * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  6090. * parameter verification fails.
  6091. */
  6092. int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key,
  6093. size_t keylen );
  6094. /**
  6095. * \brief This function feeds an input buffer into an ongoing HMAC
  6096. * computation.
  6097. *
  6098. * Call mbedtls_md_hmac_starts() or mbedtls_md_hmac_reset()
  6099. * before calling this function.
  6100. * You may call this function multiple times to pass the
  6101. * input piecewise.
  6102. * Afterwards, call mbedtls_md_hmac_finish().
  6103. *
  6104. * \param ctx The message digest context containing an embedded HMAC
  6105. * context.
  6106. * \param input The buffer holding the input data.
  6107. * \param ilen The length of the input data.
  6108. *
  6109. * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  6110. * parameter verification fails.
  6111. */
  6112. int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input,
  6113. size_t ilen );
  6114. /**
  6115. * \brief This function finishes the HMAC operation, and writes
  6116. * the result to the output buffer.
  6117. *
  6118. * Call this function after mbedtls_md_hmac_starts() and
  6119. * mbedtls_md_hmac_update() to get the HMAC value. Afterwards
  6120. * you may either call mbedtls_md_free() to clear the context,
  6121. * or call mbedtls_md_hmac_reset() to reuse the context with
  6122. * the same HMAC key.
  6123. *
  6124. * \param ctx The message digest context containing an embedded HMAC
  6125. * context.
  6126. * \param output The generic HMAC checksum result.
  6127. *
  6128. * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  6129. * parameter verification fails.
  6130. */
  6131. int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output);
  6132. /**
  6133. * \brief This function prepares to authenticate a new message with
  6134. * the same key as the previous HMAC operation.
  6135. *
  6136. * You may call this function after mbedtls_md_hmac_finish().
  6137. * Afterwards call mbedtls_md_hmac_update() to pass the new
  6138. * input.
  6139. *
  6140. * \param ctx The message digest context containing an embedded HMAC
  6141. * context.
  6142. *
  6143. * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  6144. * parameter verification fails.
  6145. */
  6146. int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx );
  6147. /**
  6148. * \brief This function calculates the full generic HMAC
  6149. * on the input buffer with the provided key.
  6150. *
  6151. * The function allocates the context, performs the
  6152. * calculation, and frees the context.
  6153. *
  6154. * The HMAC result is calculated as
  6155. * output = generic HMAC(hmac key, input buffer).
  6156. *
  6157. * \param md_info The information structure of the message-digest algorithm
  6158. * to use.
  6159. * \param key The HMAC secret key.
  6160. * \param keylen The length of the HMAC secret key in Bytes.
  6161. * \param input The buffer holding the input data.
  6162. * \param ilen The length of the input data.
  6163. * \param output The generic HMAC result.
  6164. *
  6165. * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if
  6166. * parameter verification fails.
  6167. */
  6168. int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen,
  6169. const unsigned char *input, size_t ilen,
  6170. unsigned char *output );
  6171. /* Internal use */
  6172. int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data );
  6173. #ifdef __cplusplus
  6174. }
  6175. #endif
  6176. #endif /* MBEDTLS_MD_H */
  6177. /********* Start of file include/mbedtls/md_internal.h ************/
  6178. /**
  6179. * \file md_internal.h
  6180. *
  6181. * \brief Message digest wrappers.
  6182. *
  6183. * \warning This in an internal header. Do not include directly.
  6184. *
  6185. * \author Adriaan de Jong <dejong@fox-it.com>
  6186. */
  6187. /*
  6188. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  6189. * SPDX-License-Identifier: Apache-2.0
  6190. *
  6191. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6192. * not use this file except in compliance with the License.
  6193. * You may obtain a copy of the License at
  6194. *
  6195. * http://www.apache.org/licenses/LICENSE-2.0
  6196. *
  6197. * Unless required by applicable law or agreed to in writing, software
  6198. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  6199. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6200. * See the License for the specific language governing permissions and
  6201. * limitations under the License.
  6202. *
  6203. * This file is part of mbed TLS (https://tls.mbed.org)
  6204. */
  6205. #ifndef MBEDTLS_MD_WRAP_H
  6206. #define MBEDTLS_MD_WRAP_H
  6207. #if !defined(MBEDTLS_CONFIG_FILE)
  6208. #else
  6209. #endif
  6210. #ifdef __cplusplus
  6211. extern "C" {
  6212. #endif
  6213. /**
  6214. * Message digest information.
  6215. * Allows message digest functions to be called in a generic way.
  6216. */
  6217. struct mbedtls_md_info_t
  6218. {
  6219. /** Digest identifier */
  6220. mbedtls_md_type_t type;
  6221. /** Name of the message digest */
  6222. const char * name;
  6223. /** Output length of the digest function in bytes */
  6224. int size;
  6225. /** Block length of the digest function in bytes */
  6226. int block_size;
  6227. /** Digest initialisation function */
  6228. int (*starts_func)( void *ctx );
  6229. /** Digest update function */
  6230. int (*update_func)( void *ctx, const unsigned char *input, size_t ilen );
  6231. /** Digest finalisation function */
  6232. int (*finish_func)( void *ctx, unsigned char *output );
  6233. /** Generic digest function */
  6234. int (*digest_func)( const unsigned char *input, size_t ilen,
  6235. unsigned char *output );
  6236. /** Allocate a new context */
  6237. void * (*ctx_alloc_func)( void );
  6238. /** Free the given context */
  6239. void (*ctx_free_func)( void *ctx );
  6240. /** Clone state from a context */
  6241. void (*clone_func)( void *dst, const void *src );
  6242. /** Internal use only */
  6243. int (*process_func)( void *ctx, const unsigned char *input );
  6244. };
  6245. #if defined(MBEDTLS_MD2_C)
  6246. extern const mbedtls_md_info_t mbedtls_md2_info;
  6247. #endif
  6248. #if defined(MBEDTLS_MD4_C)
  6249. extern const mbedtls_md_info_t mbedtls_md4_info;
  6250. #endif
  6251. #if defined(MBEDTLS_MD5_C)
  6252. extern const mbedtls_md_info_t mbedtls_md5_info;
  6253. #endif
  6254. #if defined(MBEDTLS_RIPEMD160_C)
  6255. extern const mbedtls_md_info_t mbedtls_ripemd160_info;
  6256. #endif
  6257. #if defined(MBEDTLS_SHA1_C)
  6258. extern const mbedtls_md_info_t mbedtls_sha1_info;
  6259. #endif
  6260. #if defined(MBEDTLS_SHA256_C)
  6261. extern const mbedtls_md_info_t mbedtls_sha224_info;
  6262. extern const mbedtls_md_info_t mbedtls_sha256_info;
  6263. #endif
  6264. #if defined(MBEDTLS_SHA512_C)
  6265. extern const mbedtls_md_info_t mbedtls_sha384_info;
  6266. extern const mbedtls_md_info_t mbedtls_sha512_info;
  6267. #endif
  6268. #ifdef __cplusplus
  6269. }
  6270. #endif
  6271. #endif /* MBEDTLS_MD_WRAP_H */
  6272. /********* Start of file include/mbedtls/md5.h ************/
  6273. /**
  6274. * \file md5.h
  6275. *
  6276. * \brief MD5 message digest algorithm (hash function)
  6277. *
  6278. * \warning MD5 is considered a weak message digest and its use constitutes a
  6279. * security risk. We recommend considering stronger message
  6280. * digests instead.
  6281. */
  6282. /*
  6283. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  6284. * SPDX-License-Identifier: Apache-2.0
  6285. *
  6286. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6287. * not use this file except in compliance with the License.
  6288. * You may obtain a copy of the License at
  6289. *
  6290. * http://www.apache.org/licenses/LICENSE-2.0
  6291. *
  6292. * Unless required by applicable law or agreed to in writing, software
  6293. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  6294. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6295. * See the License for the specific language governing permissions and
  6296. * limitations under the License.
  6297. *
  6298. * This file is part of mbed TLS (https://tls.mbed.org)
  6299. */
  6300. #ifndef MBEDTLS_MD5_H
  6301. #define MBEDTLS_MD5_H
  6302. #if !defined(MBEDTLS_CONFIG_FILE)
  6303. #else
  6304. #endif
  6305. #include <stddef.h>
  6306. #include <stdint.h>
  6307. #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */
  6308. #if !defined(MBEDTLS_MD5_ALT)
  6309. // Regular implementation
  6310. //
  6311. #ifdef __cplusplus
  6312. extern "C" {
  6313. #endif
  6314. /**
  6315. * \brief MD5 context structure
  6316. *
  6317. * \warning MD5 is considered a weak message digest and its use
  6318. * constitutes a security risk. We recommend considering
  6319. * stronger message digests instead.
  6320. *
  6321. */
  6322. typedef struct
  6323. {
  6324. uint32_t total[2]; /*!< number of bytes processed */
  6325. uint32_t state[4]; /*!< intermediate digest state */
  6326. unsigned char buffer[64]; /*!< data block being processed */
  6327. }
  6328. mbedtls_md5_context;
  6329. /**
  6330. * \brief Initialize MD5 context
  6331. *
  6332. * \param ctx MD5 context to be initialized
  6333. *
  6334. * \warning MD5 is considered a weak message digest and its use
  6335. * constitutes a security risk. We recommend considering
  6336. * stronger message digests instead.
  6337. *
  6338. */
  6339. void mbedtls_md5_init( mbedtls_md5_context *ctx );
  6340. /**
  6341. * \brief Clear MD5 context
  6342. *
  6343. * \param ctx MD5 context to be cleared
  6344. *
  6345. * \warning MD5 is considered a weak message digest and its use
  6346. * constitutes a security risk. We recommend considering
  6347. * stronger message digests instead.
  6348. *
  6349. */
  6350. void mbedtls_md5_free( mbedtls_md5_context *ctx );
  6351. /**
  6352. * \brief Clone (the state of) an MD5 context
  6353. *
  6354. * \param dst The destination context
  6355. * \param src The context to be cloned
  6356. *
  6357. * \warning MD5 is considered a weak message digest and its use
  6358. * constitutes a security risk. We recommend considering
  6359. * stronger message digests instead.
  6360. *
  6361. */
  6362. void mbedtls_md5_clone( mbedtls_md5_context *dst,
  6363. const mbedtls_md5_context *src );
  6364. /**
  6365. * \brief MD5 context setup
  6366. *
  6367. * \param ctx context to be initialized
  6368. *
  6369. * \return 0 if successful
  6370. *
  6371. * \warning MD5 is considered a weak message digest and its use
  6372. * constitutes a security risk. We recommend considering
  6373. * stronger message digests instead.
  6374. *
  6375. */
  6376. int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
  6377. /**
  6378. * \brief MD5 process buffer
  6379. *
  6380. * \param ctx MD5 context
  6381. * \param input buffer holding the data
  6382. * \param ilen length of the input data
  6383. *
  6384. * \return 0 if successful
  6385. *
  6386. * \warning MD5 is considered a weak message digest and its use
  6387. * constitutes a security risk. We recommend considering
  6388. * stronger message digests instead.
  6389. *
  6390. */
  6391. int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
  6392. const unsigned char *input,
  6393. size_t ilen );
  6394. /**
  6395. * \brief MD5 final digest
  6396. *
  6397. * \param ctx MD5 context
  6398. * \param output MD5 checksum result
  6399. *
  6400. * \return 0 if successful
  6401. *
  6402. * \warning MD5 is considered a weak message digest and its use
  6403. * constitutes a security risk. We recommend considering
  6404. * stronger message digests instead.
  6405. *
  6406. */
  6407. int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
  6408. unsigned char output[16] );
  6409. /**
  6410. * \brief MD5 process data block (internal use only)
  6411. *
  6412. * \param ctx MD5 context
  6413. * \param data buffer holding one block of data
  6414. *
  6415. * \return 0 if successful
  6416. *
  6417. * \warning MD5 is considered a weak message digest and its use
  6418. * constitutes a security risk. We recommend considering
  6419. * stronger message digests instead.
  6420. *
  6421. */
  6422. int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
  6423. const unsigned char data[64] );
  6424. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  6425. #if defined(MBEDTLS_DEPRECATED_WARNING)
  6426. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  6427. #else
  6428. #define MBEDTLS_DEPRECATED
  6429. #endif
  6430. /**
  6431. * \brief MD5 context setup
  6432. *
  6433. * \deprecated Superseded by mbedtls_md5_starts_ret() in 2.7.0
  6434. *
  6435. * \param ctx context to be initialized
  6436. *
  6437. * \warning MD5 is considered a weak message digest and its use
  6438. * constitutes a security risk. We recommend considering
  6439. * stronger message digests instead.
  6440. *
  6441. */
  6442. MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
  6443. /**
  6444. * \brief MD5 process buffer
  6445. *
  6446. * \deprecated Superseded by mbedtls_md5_update_ret() in 2.7.0
  6447. *
  6448. * \param ctx MD5 context
  6449. * \param input buffer holding the data
  6450. * \param ilen length of the input data
  6451. *
  6452. * \warning MD5 is considered a weak message digest and its use
  6453. * constitutes a security risk. We recommend considering
  6454. * stronger message digests instead.
  6455. *
  6456. */
  6457. MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
  6458. const unsigned char *input,
  6459. size_t ilen );
  6460. /**
  6461. * \brief MD5 final digest
  6462. *
  6463. * \deprecated Superseded by mbedtls_md5_finish_ret() in 2.7.0
  6464. *
  6465. * \param ctx MD5 context
  6466. * \param output MD5 checksum result
  6467. *
  6468. * \warning MD5 is considered a weak message digest and its use
  6469. * constitutes a security risk. We recommend considering
  6470. * stronger message digests instead.
  6471. *
  6472. */
  6473. MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
  6474. unsigned char output[16] );
  6475. /**
  6476. * \brief MD5 process data block (internal use only)
  6477. *
  6478. * \deprecated Superseded by mbedtls_internal_md5_process() in 2.7.0
  6479. *
  6480. * \param ctx MD5 context
  6481. * \param data buffer holding one block of data
  6482. *
  6483. * \warning MD5 is considered a weak message digest and its use
  6484. * constitutes a security risk. We recommend considering
  6485. * stronger message digests instead.
  6486. *
  6487. */
  6488. MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
  6489. const unsigned char data[64] );
  6490. #undef MBEDTLS_DEPRECATED
  6491. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  6492. #ifdef __cplusplus
  6493. }
  6494. #endif
  6495. #else /* MBEDTLS_MD5_ALT */
  6496. #endif /* MBEDTLS_MD5_ALT */
  6497. #ifdef __cplusplus
  6498. extern "C" {
  6499. #endif
  6500. /**
  6501. * \brief Output = MD5( input buffer )
  6502. *
  6503. * \param input buffer holding the data
  6504. * \param ilen length of the input data
  6505. * \param output MD5 checksum result
  6506. *
  6507. * \return 0 if successful
  6508. *
  6509. * \warning MD5 is considered a weak message digest and its use
  6510. * constitutes a security risk. We recommend considering
  6511. * stronger message digests instead.
  6512. *
  6513. */
  6514. int mbedtls_md5_ret( const unsigned char *input,
  6515. size_t ilen,
  6516. unsigned char output[16] );
  6517. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  6518. #if defined(MBEDTLS_DEPRECATED_WARNING)
  6519. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  6520. #else
  6521. #define MBEDTLS_DEPRECATED
  6522. #endif
  6523. /**
  6524. * \brief Output = MD5( input buffer )
  6525. *
  6526. * \deprecated Superseded by mbedtls_md5_ret() in 2.7.0
  6527. *
  6528. * \param input buffer holding the data
  6529. * \param ilen length of the input data
  6530. * \param output MD5 checksum result
  6531. *
  6532. * \warning MD5 is considered a weak message digest and its use
  6533. * constitutes a security risk. We recommend considering
  6534. * stronger message digests instead.
  6535. *
  6536. */
  6537. MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
  6538. size_t ilen,
  6539. unsigned char output[16] );
  6540. #undef MBEDTLS_DEPRECATED
  6541. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  6542. /**
  6543. * \brief Checkup routine
  6544. *
  6545. * \return 0 if successful, or 1 if the test failed
  6546. *
  6547. * \warning MD5 is considered a weak message digest and its use
  6548. * constitutes a security risk. We recommend considering
  6549. * stronger message digests instead.
  6550. *
  6551. */
  6552. int mbedtls_md5_self_test( int verbose );
  6553. #ifdef __cplusplus
  6554. }
  6555. #endif
  6556. #endif /* mbedtls_md5.h */
  6557. /********* Start of file include/mbedtls/md2.h ************/
  6558. /**
  6559. * \file md2.h
  6560. *
  6561. * \brief MD2 message digest algorithm (hash function)
  6562. *
  6563. * \warning MD2 is considered a weak message digest and its use constitutes a
  6564. * security risk. We recommend considering stronger message digests
  6565. * instead.
  6566. */
  6567. /*
  6568. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  6569. * SPDX-License-Identifier: Apache-2.0
  6570. *
  6571. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6572. * not use this file except in compliance with the License.
  6573. * You may obtain a copy of the License at
  6574. *
  6575. * http://www.apache.org/licenses/LICENSE-2.0
  6576. *
  6577. * Unless required by applicable law or agreed to in writing, software
  6578. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  6579. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6580. * See the License for the specific language governing permissions and
  6581. * limitations under the License.
  6582. *
  6583. * This file is part of mbed TLS (https://tls.mbed.org)
  6584. *
  6585. */
  6586. #ifndef MBEDTLS_MD2_H
  6587. #define MBEDTLS_MD2_H
  6588. #if !defined(MBEDTLS_CONFIG_FILE)
  6589. #else
  6590. #endif
  6591. #include <stddef.h>
  6592. #define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
  6593. #if !defined(MBEDTLS_MD2_ALT)
  6594. // Regular implementation
  6595. //
  6596. #ifdef __cplusplus
  6597. extern "C" {
  6598. #endif
  6599. /**
  6600. * \brief MD2 context structure
  6601. *
  6602. * \warning MD2 is considered a weak message digest and its use
  6603. * constitutes a security risk. We recommend considering
  6604. * stronger message digests instead.
  6605. *
  6606. */
  6607. typedef struct
  6608. {
  6609. unsigned char cksum[16]; /*!< checksum of the data block */
  6610. unsigned char state[48]; /*!< intermediate digest state */
  6611. unsigned char buffer[16]; /*!< data block being processed */
  6612. size_t left; /*!< amount of data in buffer */
  6613. }
  6614. mbedtls_md2_context;
  6615. /**
  6616. * \brief Initialize MD2 context
  6617. *
  6618. * \param ctx MD2 context to be initialized
  6619. *
  6620. * \warning MD2 is considered a weak message digest and its use
  6621. * constitutes a security risk. We recommend considering
  6622. * stronger message digests instead.
  6623. *
  6624. */
  6625. void mbedtls_md2_init( mbedtls_md2_context *ctx );
  6626. /**
  6627. * \brief Clear MD2 context
  6628. *
  6629. * \param ctx MD2 context to be cleared
  6630. *
  6631. * \warning MD2 is considered a weak message digest and its use
  6632. * constitutes a security risk. We recommend considering
  6633. * stronger message digests instead.
  6634. *
  6635. */
  6636. void mbedtls_md2_free( mbedtls_md2_context *ctx );
  6637. /**
  6638. * \brief Clone (the state of) an MD2 context
  6639. *
  6640. * \param dst The destination context
  6641. * \param src The context to be cloned
  6642. *
  6643. * \warning MD2 is considered a weak message digest and its use
  6644. * constitutes a security risk. We recommend considering
  6645. * stronger message digests instead.
  6646. *
  6647. */
  6648. void mbedtls_md2_clone( mbedtls_md2_context *dst,
  6649. const mbedtls_md2_context *src );
  6650. /**
  6651. * \brief MD2 context setup
  6652. *
  6653. * \param ctx context to be initialized
  6654. *
  6655. * \return 0 if successful
  6656. *
  6657. * \warning MD2 is considered a weak message digest and its use
  6658. * constitutes a security risk. We recommend considering
  6659. * stronger message digests instead.
  6660. *
  6661. */
  6662. int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
  6663. /**
  6664. * \brief MD2 process buffer
  6665. *
  6666. * \param ctx MD2 context
  6667. * \param input buffer holding the data
  6668. * \param ilen length of the input data
  6669. *
  6670. * \return 0 if successful
  6671. *
  6672. * \warning MD2 is considered a weak message digest and its use
  6673. * constitutes a security risk. We recommend considering
  6674. * stronger message digests instead.
  6675. *
  6676. */
  6677. int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
  6678. const unsigned char *input,
  6679. size_t ilen );
  6680. /**
  6681. * \brief MD2 final digest
  6682. *
  6683. * \param ctx MD2 context
  6684. * \param output MD2 checksum result
  6685. *
  6686. * \return 0 if successful
  6687. *
  6688. * \warning MD2 is considered a weak message digest and its use
  6689. * constitutes a security risk. We recommend considering
  6690. * stronger message digests instead.
  6691. *
  6692. */
  6693. int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
  6694. unsigned char output[16] );
  6695. /**
  6696. * \brief MD2 process data block (internal use only)
  6697. *
  6698. * \param ctx MD2 context
  6699. *
  6700. * \return 0 if successful
  6701. *
  6702. * \warning MD2 is considered a weak message digest and its use
  6703. * constitutes a security risk. We recommend considering
  6704. * stronger message digests instead.
  6705. *
  6706. */
  6707. int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
  6708. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  6709. #if defined(MBEDTLS_DEPRECATED_WARNING)
  6710. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  6711. #else
  6712. #define MBEDTLS_DEPRECATED
  6713. #endif
  6714. /**
  6715. * \brief MD2 context setup
  6716. *
  6717. * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
  6718. *
  6719. * \param ctx context to be initialized
  6720. *
  6721. * \warning MD2 is considered a weak message digest and its use
  6722. * constitutes a security risk. We recommend considering
  6723. * stronger message digests instead.
  6724. *
  6725. */
  6726. MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
  6727. /**
  6728. * \brief MD2 process buffer
  6729. *
  6730. * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
  6731. *
  6732. * \param ctx MD2 context
  6733. * \param input buffer holding the data
  6734. * \param ilen length of the input data
  6735. *
  6736. * \warning MD2 is considered a weak message digest and its use
  6737. * constitutes a security risk. We recommend considering
  6738. * stronger message digests instead.
  6739. *
  6740. */
  6741. MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
  6742. const unsigned char *input,
  6743. size_t ilen );
  6744. /**
  6745. * \brief MD2 final digest
  6746. *
  6747. * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
  6748. *
  6749. * \param ctx MD2 context
  6750. * \param output MD2 checksum result
  6751. *
  6752. * \warning MD2 is considered a weak message digest and its use
  6753. * constitutes a security risk. We recommend considering
  6754. * stronger message digests instead.
  6755. *
  6756. */
  6757. MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
  6758. unsigned char output[16] );
  6759. /**
  6760. * \brief MD2 process data block (internal use only)
  6761. *
  6762. * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
  6763. *
  6764. * \param ctx MD2 context
  6765. *
  6766. * \warning MD2 is considered a weak message digest and its use
  6767. * constitutes a security risk. We recommend considering
  6768. * stronger message digests instead.
  6769. *
  6770. */
  6771. MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
  6772. #undef MBEDTLS_DEPRECATED
  6773. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  6774. #ifdef __cplusplus
  6775. }
  6776. #endif
  6777. #else /* MBEDTLS_MD2_ALT */
  6778. #endif /* MBEDTLS_MD2_ALT */
  6779. #ifdef __cplusplus
  6780. extern "C" {
  6781. #endif
  6782. /**
  6783. * \brief Output = MD2( input buffer )
  6784. *
  6785. * \param input buffer holding the data
  6786. * \param ilen length of the input data
  6787. * \param output MD2 checksum result
  6788. *
  6789. * \warning MD2 is considered a weak message digest and its use
  6790. * constitutes a security risk. We recommend considering
  6791. * stronger message digests instead.
  6792. *
  6793. */
  6794. int mbedtls_md2_ret( const unsigned char *input,
  6795. size_t ilen,
  6796. unsigned char output[16] );
  6797. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  6798. #if defined(MBEDTLS_DEPRECATED_WARNING)
  6799. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  6800. #else
  6801. #define MBEDTLS_DEPRECATED
  6802. #endif
  6803. /**
  6804. * \brief Output = MD2( input buffer )
  6805. *
  6806. * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
  6807. *
  6808. * \param input buffer holding the data
  6809. * \param ilen length of the input data
  6810. * \param output MD2 checksum result
  6811. *
  6812. * \warning MD2 is considered a weak message digest and its use
  6813. * constitutes a security risk. We recommend considering
  6814. * stronger message digests instead.
  6815. *
  6816. */
  6817. MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
  6818. size_t ilen,
  6819. unsigned char output[16] );
  6820. #undef MBEDTLS_DEPRECATED
  6821. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  6822. /**
  6823. * \brief Checkup routine
  6824. *
  6825. * \return 0 if successful, or 1 if the test failed
  6826. *
  6827. * \warning MD2 is considered a weak message digest and its use
  6828. * constitutes a security risk. We recommend considering
  6829. * stronger message digests instead.
  6830. *
  6831. */
  6832. int mbedtls_md2_self_test( int verbose );
  6833. #ifdef __cplusplus
  6834. }
  6835. #endif
  6836. #endif /* mbedtls_md2.h */
  6837. /********* Start of file include/mbedtls/md4.h ************/
  6838. /**
  6839. * \file md4.h
  6840. *
  6841. * \brief MD4 message digest algorithm (hash function)
  6842. *
  6843. * \warning MD4 is considered a weak message digest and its use constitutes a
  6844. * security risk. We recommend considering stronger message digests
  6845. * instead.
  6846. */
  6847. /*
  6848. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  6849. * SPDX-License-Identifier: Apache-2.0
  6850. *
  6851. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6852. * not use this file except in compliance with the License.
  6853. * You may obtain a copy of the License at
  6854. *
  6855. * http://www.apache.org/licenses/LICENSE-2.0
  6856. *
  6857. * Unless required by applicable law or agreed to in writing, software
  6858. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  6859. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6860. * See the License for the specific language governing permissions and
  6861. * limitations under the License.
  6862. *
  6863. * This file is part of mbed TLS (https://tls.mbed.org)
  6864. *
  6865. */
  6866. #ifndef MBEDTLS_MD4_H
  6867. #define MBEDTLS_MD4_H
  6868. #if !defined(MBEDTLS_CONFIG_FILE)
  6869. #else
  6870. #endif
  6871. #include <stddef.h>
  6872. #include <stdint.h>
  6873. #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
  6874. #if !defined(MBEDTLS_MD4_ALT)
  6875. // Regular implementation
  6876. //
  6877. #ifdef __cplusplus
  6878. extern "C" {
  6879. #endif
  6880. /**
  6881. * \brief MD4 context structure
  6882. *
  6883. * \warning MD4 is considered a weak message digest and its use
  6884. * constitutes a security risk. We recommend considering
  6885. * stronger message digests instead.
  6886. *
  6887. */
  6888. typedef struct
  6889. {
  6890. uint32_t total[2]; /*!< number of bytes processed */
  6891. uint32_t state[4]; /*!< intermediate digest state */
  6892. unsigned char buffer[64]; /*!< data block being processed */
  6893. }
  6894. mbedtls_md4_context;
  6895. /**
  6896. * \brief Initialize MD4 context
  6897. *
  6898. * \param ctx MD4 context to be initialized
  6899. *
  6900. * \warning MD4 is considered a weak message digest and its use
  6901. * constitutes a security risk. We recommend considering
  6902. * stronger message digests instead.
  6903. *
  6904. */
  6905. void mbedtls_md4_init( mbedtls_md4_context *ctx );
  6906. /**
  6907. * \brief Clear MD4 context
  6908. *
  6909. * \param ctx MD4 context to be cleared
  6910. *
  6911. * \warning MD4 is considered a weak message digest and its use
  6912. * constitutes a security risk. We recommend considering
  6913. * stronger message digests instead.
  6914. *
  6915. */
  6916. void mbedtls_md4_free( mbedtls_md4_context *ctx );
  6917. /**
  6918. * \brief Clone (the state of) an MD4 context
  6919. *
  6920. * \param dst The destination context
  6921. * \param src The context to be cloned
  6922. *
  6923. * \warning MD4 is considered a weak message digest and its use
  6924. * constitutes a security risk. We recommend considering
  6925. * stronger message digests instead.
  6926. *
  6927. */
  6928. void mbedtls_md4_clone( mbedtls_md4_context *dst,
  6929. const mbedtls_md4_context *src );
  6930. /**
  6931. * \brief MD4 context setup
  6932. *
  6933. * \param ctx context to be initialized
  6934. *
  6935. * \return 0 if successful
  6936. *
  6937. * \warning MD4 is considered a weak message digest and its use
  6938. * constitutes a security risk. We recommend considering
  6939. * stronger message digests instead.
  6940. */
  6941. int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
  6942. /**
  6943. * \brief MD4 process buffer
  6944. *
  6945. * \param ctx MD4 context
  6946. * \param input buffer holding the data
  6947. * \param ilen length of the input data
  6948. *
  6949. * \return 0 if successful
  6950. *
  6951. * \warning MD4 is considered a weak message digest and its use
  6952. * constitutes a security risk. We recommend considering
  6953. * stronger message digests instead.
  6954. *
  6955. */
  6956. int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
  6957. const unsigned char *input,
  6958. size_t ilen );
  6959. /**
  6960. * \brief MD4 final digest
  6961. *
  6962. * \param ctx MD4 context
  6963. * \param output MD4 checksum result
  6964. *
  6965. * \return 0 if successful
  6966. *
  6967. * \warning MD4 is considered a weak message digest and its use
  6968. * constitutes a security risk. We recommend considering
  6969. * stronger message digests instead.
  6970. *
  6971. */
  6972. int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
  6973. unsigned char output[16] );
  6974. /**
  6975. * \brief MD4 process data block (internal use only)
  6976. *
  6977. * \param ctx MD4 context
  6978. * \param data buffer holding one block of data
  6979. *
  6980. * \return 0 if successful
  6981. *
  6982. * \warning MD4 is considered a weak message digest and its use
  6983. * constitutes a security risk. We recommend considering
  6984. * stronger message digests instead.
  6985. *
  6986. */
  6987. int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
  6988. const unsigned char data[64] );
  6989. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  6990. #if defined(MBEDTLS_DEPRECATED_WARNING)
  6991. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  6992. #else
  6993. #define MBEDTLS_DEPRECATED
  6994. #endif
  6995. /**
  6996. * \brief MD4 context setup
  6997. *
  6998. * \deprecated Superseded by mbedtls_md4_starts_ret() in 2.7.0
  6999. *
  7000. * \param ctx context to be initialized
  7001. *
  7002. * \warning MD4 is considered a weak message digest and its use
  7003. * constitutes a security risk. We recommend considering
  7004. * stronger message digests instead.
  7005. *
  7006. */
  7007. MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
  7008. /**
  7009. * \brief MD4 process buffer
  7010. *
  7011. * \deprecated Superseded by mbedtls_md4_update_ret() in 2.7.0
  7012. *
  7013. * \param ctx MD4 context
  7014. * \param input buffer holding the data
  7015. * \param ilen length of the input data
  7016. *
  7017. * \warning MD4 is considered a weak message digest and its use
  7018. * constitutes a security risk. We recommend considering
  7019. * stronger message digests instead.
  7020. *
  7021. */
  7022. MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
  7023. const unsigned char *input,
  7024. size_t ilen );
  7025. /**
  7026. * \brief MD4 final digest
  7027. *
  7028. * \deprecated Superseded by mbedtls_md4_finish_ret() in 2.7.0
  7029. *
  7030. * \param ctx MD4 context
  7031. * \param output MD4 checksum result
  7032. *
  7033. * \warning MD4 is considered a weak message digest and its use
  7034. * constitutes a security risk. We recommend considering
  7035. * stronger message digests instead.
  7036. *
  7037. */
  7038. MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
  7039. unsigned char output[16] );
  7040. /**
  7041. * \brief MD4 process data block (internal use only)
  7042. *
  7043. * \deprecated Superseded by mbedtls_internal_md4_process() in 2.7.0
  7044. *
  7045. * \param ctx MD4 context
  7046. * \param data buffer holding one block of data
  7047. *
  7048. * \warning MD4 is considered a weak message digest and its use
  7049. * constitutes a security risk. We recommend considering
  7050. * stronger message digests instead.
  7051. *
  7052. */
  7053. MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
  7054. const unsigned char data[64] );
  7055. #undef MBEDTLS_DEPRECATED
  7056. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  7057. #ifdef __cplusplus
  7058. }
  7059. #endif
  7060. #else /* MBEDTLS_MD4_ALT */
  7061. #endif /* MBEDTLS_MD4_ALT */
  7062. #ifdef __cplusplus
  7063. extern "C" {
  7064. #endif
  7065. /**
  7066. * \brief Output = MD4( input buffer )
  7067. *
  7068. * \param input buffer holding the data
  7069. * \param ilen length of the input data
  7070. * \param output MD4 checksum result
  7071. *
  7072. * \return 0 if successful
  7073. *
  7074. * \warning MD4 is considered a weak message digest and its use
  7075. * constitutes a security risk. We recommend considering
  7076. * stronger message digests instead.
  7077. *
  7078. */
  7079. int mbedtls_md4_ret( const unsigned char *input,
  7080. size_t ilen,
  7081. unsigned char output[16] );
  7082. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  7083. #if defined(MBEDTLS_DEPRECATED_WARNING)
  7084. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  7085. #else
  7086. #define MBEDTLS_DEPRECATED
  7087. #endif
  7088. /**
  7089. * \brief Output = MD4( input buffer )
  7090. *
  7091. * \deprecated Superseded by mbedtls_md4_ret() in 2.7.0
  7092. *
  7093. * \param input buffer holding the data
  7094. * \param ilen length of the input data
  7095. * \param output MD4 checksum result
  7096. *
  7097. * \warning MD4 is considered a weak message digest and its use
  7098. * constitutes a security risk. We recommend considering
  7099. * stronger message digests instead.
  7100. *
  7101. */
  7102. MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
  7103. size_t ilen,
  7104. unsigned char output[16] );
  7105. #undef MBEDTLS_DEPRECATED
  7106. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  7107. /**
  7108. * \brief Checkup routine
  7109. *
  7110. * \return 0 if successful, or 1 if the test failed
  7111. *
  7112. * \warning MD4 is considered a weak message digest and its use
  7113. * constitutes a security risk. We recommend considering
  7114. * stronger message digests instead.
  7115. *
  7116. */
  7117. int mbedtls_md4_self_test( int verbose );
  7118. #ifdef __cplusplus
  7119. }
  7120. #endif
  7121. #endif /* mbedtls_md4.h */
  7122. /********* Start of file include/mbedtls/rsa.h ************/
  7123. /**
  7124. * \file rsa.h
  7125. *
  7126. * \brief The RSA public-key cryptosystem.
  7127. *
  7128. * For more information, see <em>Public-Key Cryptography Standards (PKCS)
  7129. * #1 v1.5: RSA Encryption</em> and <em>Public-Key Cryptography Standards
  7130. * (PKCS) #1 v2.1: RSA Cryptography Specifications</em>.
  7131. *
  7132. */
  7133. /*
  7134. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  7135. * SPDX-License-Identifier: Apache-2.0
  7136. *
  7137. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  7138. * not use this file except in compliance with the License.
  7139. * You may obtain a copy of the License at
  7140. *
  7141. * http://www.apache.org/licenses/LICENSE-2.0
  7142. *
  7143. * Unless required by applicable law or agreed to in writing, software
  7144. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  7145. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7146. * See the License for the specific language governing permissions and
  7147. * limitations under the License.
  7148. *
  7149. * This file is part of Mbed TLS (https://tls.mbed.org)
  7150. */
  7151. #ifndef MBEDTLS_RSA_H
  7152. #define MBEDTLS_RSA_H
  7153. #if !defined(MBEDTLS_CONFIG_FILE)
  7154. #else
  7155. #endif
  7156. #if defined(MBEDTLS_THREADING_C)
  7157. #endif
  7158. /*
  7159. * RSA Error codes
  7160. */
  7161. #define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */
  7162. #define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */
  7163. #define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */
  7164. #define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the validity check of the library. */
  7165. #define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */
  7166. #define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */
  7167. #define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */
  7168. #define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */
  7169. #define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */
  7170. #define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500 /**< The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */
  7171. #define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580 /**< RSA hardware accelerator failed. */
  7172. /*
  7173. * RSA constants
  7174. */
  7175. #define MBEDTLS_RSA_PUBLIC 0 /**< Request private key operation. */
  7176. #define MBEDTLS_RSA_PRIVATE 1 /**< Request public key operation. */
  7177. #define MBEDTLS_RSA_PKCS_V15 0 /**< Use PKCS-1 v1.5 encoding. */
  7178. #define MBEDTLS_RSA_PKCS_V21 1 /**< Use PKCS-1 v2.1 encoding. */
  7179. #define MBEDTLS_RSA_SIGN 1 /**< Identifier for RSA signature operations. */
  7180. #define MBEDTLS_RSA_CRYPT 2 /**< Identifier for RSA encryption and decryption operations. */
  7181. #define MBEDTLS_RSA_SALT_LEN_ANY -1
  7182. /*
  7183. * The above constants may be used even if the RSA module is compile out,
  7184. * eg for alternative (PKCS#11) RSA implemenations in the PK layers.
  7185. */
  7186. #if !defined(MBEDTLS_RSA_ALT)
  7187. // Regular implementation
  7188. //
  7189. #ifdef __cplusplus
  7190. extern "C" {
  7191. #endif
  7192. /**
  7193. * \brief The RSA context structure.
  7194. *
  7195. * \note Direct manipulation of the members of this structure
  7196. * is deprecated. All manipulation should instead be done through
  7197. * the public interface functions.
  7198. */
  7199. typedef struct
  7200. {
  7201. int ver; /*!< Always 0.*/
  7202. size_t len; /*!< The size of \p N in Bytes. */
  7203. mbedtls_mpi N; /*!< The public modulus. */
  7204. mbedtls_mpi E; /*!< The public exponent. */
  7205. mbedtls_mpi D; /*!< The private exponent. */
  7206. mbedtls_mpi P; /*!< The first prime factor. */
  7207. mbedtls_mpi Q; /*!< The second prime factor. */
  7208. mbedtls_mpi DP; /*!< \p D % (P - 1) */
  7209. mbedtls_mpi DQ; /*!< \p D % (Q - 1) */
  7210. mbedtls_mpi QP; /*!< 1 / (Q % P) */
  7211. mbedtls_mpi RN; /*!< cached R^2 mod \p N */
  7212. mbedtls_mpi RP; /*!< cached R^2 mod \p P */
  7213. mbedtls_mpi RQ; /*!< cached R^2 mod \p Q */
  7214. mbedtls_mpi Vi; /*!< The cached blinding value. */
  7215. mbedtls_mpi Vf; /*!< The cached un-blinding value. */
  7216. int padding; /*!< Selects padding mode:
  7217. #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and
  7218. #MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */
  7219. int hash_id; /*!< Hash identifier of mbedtls_md_type_t type,
  7220. as specified in md.h for use in the MGF
  7221. mask generating function used in the
  7222. EME-OAEP and EMSA-PSS encodings. */
  7223. #if defined(MBEDTLS_THREADING_C)
  7224. mbedtls_threading_mutex_t mutex; /*!< Thread-safety mutex. */
  7225. #endif
  7226. }
  7227. mbedtls_rsa_context;
  7228. /**
  7229. * \brief This function initializes an RSA context.
  7230. *
  7231. * \note Set padding to #MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP
  7232. * encryption scheme and the RSASSA-PSS signature scheme.
  7233. *
  7234. * \param ctx The RSA context to initialize.
  7235. * \param padding Selects padding mode: #MBEDTLS_RSA_PKCS_V15 or
  7236. * #MBEDTLS_RSA_PKCS_V21.
  7237. * \param hash_id The hash identifier of #mbedtls_md_type_t type, if
  7238. * \p padding is #MBEDTLS_RSA_PKCS_V21.
  7239. *
  7240. * \note The \p hash_id parameter is ignored when using
  7241. * #MBEDTLS_RSA_PKCS_V15 padding.
  7242. *
  7243. * \note The choice of padding mode is strictly enforced for private key
  7244. * operations, since there might be security concerns in
  7245. * mixing padding modes. For public key operations it is
  7246. * a default value, which can be overriden by calling specific
  7247. * \c rsa_rsaes_xxx or \c rsa_rsassa_xxx functions.
  7248. *
  7249. * \note The hash selected in \p hash_id is always used for OEAP
  7250. * encryption. For PSS signatures, it is always used for
  7251. * making signatures, but can be overriden for verifying them.
  7252. * If set to #MBEDTLS_MD_NONE, it is always overriden.
  7253. */
  7254. void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
  7255. int padding,
  7256. int hash_id);
  7257. /**
  7258. * \brief This function imports a set of core parameters into an
  7259. * RSA context.
  7260. *
  7261. * \param ctx The initialized RSA context to store the parameters in.
  7262. * \param N The RSA modulus, or NULL.
  7263. * \param P The first prime factor of \p N, or NULL.
  7264. * \param Q The second prime factor of \p N, or NULL.
  7265. * \param D The private exponent, or NULL.
  7266. * \param E The public exponent, or NULL.
  7267. *
  7268. * \note This function can be called multiple times for successive
  7269. * imports, if the parameters are not simultaneously present.
  7270. *
  7271. * Any sequence of calls to this function should be followed
  7272. * by a call to mbedtls_rsa_complete(), which checks and
  7273. * completes the provided information to a ready-for-use
  7274. * public or private RSA key.
  7275. *
  7276. * \note See mbedtls_rsa_complete() for more information on which
  7277. * parameters are necessary to set up a private or public
  7278. * RSA key.
  7279. *
  7280. * \note The imported parameters are copied and need not be preserved
  7281. * for the lifetime of the RSA context being set up.
  7282. *
  7283. * \return \c 0 on success, or a non-zero error code on failure.
  7284. */
  7285. int mbedtls_rsa_import( mbedtls_rsa_context *ctx,
  7286. const mbedtls_mpi *N,
  7287. const mbedtls_mpi *P, const mbedtls_mpi *Q,
  7288. const mbedtls_mpi *D, const mbedtls_mpi *E );
  7289. /**
  7290. * \brief This function imports core RSA parameters, in raw big-endian
  7291. * binary format, into an RSA context.
  7292. *
  7293. * \param ctx The initialized RSA context to store the parameters in.
  7294. * \param N The RSA modulus, or NULL.
  7295. * \param N_len The Byte length of \p N, ignored if \p N == NULL.
  7296. * \param P The first prime factor of \p N, or NULL.
  7297. * \param P_len The Byte length of \p P, ignored if \p P == NULL.
  7298. * \param Q The second prime factor of \p N, or NULL.
  7299. * \param Q_len The Byte length of \p Q, ignored if \p Q == NULL.
  7300. * \param D The private exponent, or NULL.
  7301. * \param D_len The Byte length of \p D, ignored if \p D == NULL.
  7302. * \param E The public exponent, or NULL.
  7303. * \param E_len The Byte length of \p E, ignored if \p E == NULL.
  7304. *
  7305. * \note This function can be called multiple times for successive
  7306. * imports, if the parameters are not simultaneously present.
  7307. *
  7308. * Any sequence of calls to this function should be followed
  7309. * by a call to mbedtls_rsa_complete(), which checks and
  7310. * completes the provided information to a ready-for-use
  7311. * public or private RSA key.
  7312. *
  7313. * \note See mbedtls_rsa_complete() for more information on which
  7314. * parameters are necessary to set up a private or public
  7315. * RSA key.
  7316. *
  7317. * \note The imported parameters are copied and need not be preserved
  7318. * for the lifetime of the RSA context being set up.
  7319. *
  7320. * \return \c 0 on success, or a non-zero error code on failure.
  7321. */
  7322. int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx,
  7323. unsigned char const *N, size_t N_len,
  7324. unsigned char const *P, size_t P_len,
  7325. unsigned char const *Q, size_t Q_len,
  7326. unsigned char const *D, size_t D_len,
  7327. unsigned char const *E, size_t E_len );
  7328. /**
  7329. * \brief This function completes an RSA context from
  7330. * a set of imported core parameters.
  7331. *
  7332. * To setup an RSA public key, precisely \p N and \p E
  7333. * must have been imported.
  7334. *
  7335. * To setup an RSA private key, sufficient information must
  7336. * be present for the other parameters to be derivable.
  7337. *
  7338. * The default implementation supports the following:
  7339. * <ul><li>Derive \p P, \p Q from \p N, \p D, \p E.</li>
  7340. * <li>Derive \p N, \p D from \p P, \p Q, \p E.</li></ul>
  7341. * Alternative implementations need not support these.
  7342. *
  7343. * If this function runs successfully, it guarantees that
  7344. * the RSA context can be used for RSA operations without
  7345. * the risk of failure or crash.
  7346. *
  7347. * \param ctx The initialized RSA context holding imported parameters.
  7348. *
  7349. * \return \c 0 on success, or #MBEDTLS_ERR_RSA_BAD_INPUT_DATA if the
  7350. * attempted derivations failed.
  7351. *
  7352. * \warning This function need not perform consistency checks
  7353. * for the imported parameters. In particular, parameters that
  7354. * are not needed by the implementation might be silently
  7355. * discarded and left unchecked. To check the consistency
  7356. * of the key material, see mbedtls_rsa_check_privkey().
  7357. *
  7358. */
  7359. int mbedtls_rsa_complete( mbedtls_rsa_context *ctx );
  7360. /**
  7361. * \brief This function exports the core parameters of an RSA key.
  7362. *
  7363. * If this function runs successfully, the non-NULL buffers
  7364. * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
  7365. * written, with additional unused space filled leading by
  7366. * zero Bytes.
  7367. *
  7368. * Possible reasons for returning
  7369. * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION:<ul>
  7370. * <li>An alternative RSA implementation is in use, which
  7371. * stores the key externally, and either cannot or should
  7372. * not export it into RAM.</li>
  7373. * <li>A SW or HW implementation might not support a certain
  7374. * deduction. For example, \p P, \p Q from \p N, \p D,
  7375. * and \p E if the former are not part of the
  7376. * implementation.</li></ul>
  7377. *
  7378. * If the function fails due to an unsupported operation,
  7379. * the RSA context stays intact and remains usable.
  7380. *
  7381. * \param ctx The initialized RSA context.
  7382. * \param N The MPI to hold the RSA modulus, or NULL.
  7383. * \param P The MPI to hold the first prime factor of \p N, or NULL.
  7384. * \param Q The MPI to hold the second prime factor of \p N, or NULL.
  7385. * \param D The MPI to hold the private exponent, or NULL.
  7386. * \param E The MPI to hold the public exponent, or NULL.
  7387. *
  7388. * \return \c 0 on success,
  7389. * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION if exporting the
  7390. * requested parameters cannot be done due to missing
  7391. * functionality or because of security policies,
  7392. * or a non-zero return code on any other failure.
  7393. *
  7394. */
  7395. int mbedtls_rsa_export( const mbedtls_rsa_context *ctx,
  7396. mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q,
  7397. mbedtls_mpi *D, mbedtls_mpi *E );
  7398. /**
  7399. * \brief This function exports core parameters of an RSA key
  7400. * in raw big-endian binary format.
  7401. *
  7402. * If this function runs successfully, the non-NULL buffers
  7403. * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
  7404. * written, with additional unused space filled leading by
  7405. * zero Bytes.
  7406. *
  7407. * Possible reasons for returning
  7408. * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION:<ul>
  7409. * <li>An alternative RSA implementation is in use, which
  7410. * stores the key externally, and either cannot or should
  7411. * not export it into RAM.</li>
  7412. * <li>A SW or HW implementation might not support a certain
  7413. * deduction. For example, \p P, \p Q from \p N, \p D,
  7414. * and \p E if the former are not part of the
  7415. * implementation.</li></ul>
  7416. * If the function fails due to an unsupported operation,
  7417. * the RSA context stays intact and remains usable.
  7418. *
  7419. * \param ctx The initialized RSA context.
  7420. * \param N The Byte array to store the RSA modulus, or NULL.
  7421. * \param N_len The size of the buffer for the modulus.
  7422. * \param P The Byte array to hold the first prime factor of \p N, or
  7423. * NULL.
  7424. * \param P_len The size of the buffer for the first prime factor.
  7425. * \param Q The Byte array to hold the second prime factor of \p N, or
  7426. NULL.
  7427. * \param Q_len The size of the buffer for the second prime factor.
  7428. * \param D The Byte array to hold the private exponent, or NULL.
  7429. * \param D_len The size of the buffer for the private exponent.
  7430. * \param E The Byte array to hold the public exponent, or NULL.
  7431. * \param E_len The size of the buffer for the public exponent.
  7432. *
  7433. * \note The length fields are ignored if the corresponding
  7434. * buffer pointers are NULL.
  7435. *
  7436. * \return \c 0 on success,
  7437. * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION if exporting the
  7438. * requested parameters cannot be done due to missing
  7439. * functionality or because of security policies,
  7440. * or a non-zero return code on any other failure.
  7441. */
  7442. int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx,
  7443. unsigned char *N, size_t N_len,
  7444. unsigned char *P, size_t P_len,
  7445. unsigned char *Q, size_t Q_len,
  7446. unsigned char *D, size_t D_len,
  7447. unsigned char *E, size_t E_len );
  7448. /**
  7449. * \brief This function exports CRT parameters of a private RSA key.
  7450. *
  7451. * \param ctx The initialized RSA context.
  7452. * \param DP The MPI to hold D modulo P-1, or NULL.
  7453. * \param DQ The MPI to hold D modulo Q-1, or NULL.
  7454. * \param QP The MPI to hold modular inverse of Q modulo P, or NULL.
  7455. *
  7456. * \return \c 0 on success, non-zero error code otherwise.
  7457. *
  7458. * \note Alternative RSA implementations not using CRT-parameters
  7459. * internally can implement this function based on
  7460. * mbedtls_rsa_deduce_opt().
  7461. *
  7462. */
  7463. int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx,
  7464. mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP );
  7465. /**
  7466. * \brief This function sets padding for an already initialized RSA
  7467. * context. See mbedtls_rsa_init() for details.
  7468. *
  7469. * \param ctx The RSA context to be set.
  7470. * \param padding Selects padding mode: #MBEDTLS_RSA_PKCS_V15 or
  7471. * #MBEDTLS_RSA_PKCS_V21.
  7472. * \param hash_id The #MBEDTLS_RSA_PKCS_V21 hash identifier.
  7473. */
  7474. void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
  7475. int hash_id);
  7476. /**
  7477. * \brief This function retrieves the length of RSA modulus in Bytes.
  7478. *
  7479. * \param ctx The initialized RSA context.
  7480. *
  7481. * \return The length of the RSA modulus in Bytes.
  7482. *
  7483. */
  7484. size_t mbedtls_rsa_get_len( const mbedtls_rsa_context *ctx );
  7485. /**
  7486. * \brief This function generates an RSA keypair.
  7487. *
  7488. * \param ctx The RSA context used to hold the key.
  7489. * \param f_rng The RNG function.
  7490. * \param p_rng The RNG parameter.
  7491. * \param nbits The size of the public key in bits.
  7492. * \param exponent The public exponent. For example, 65537.
  7493. *
  7494. * \note mbedtls_rsa_init() must be called before this function,
  7495. * to set up the RSA context.
  7496. *
  7497. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7498. on failure.
  7499. */
  7500. int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
  7501. int (*f_rng)(void *, unsigned char *, size_t),
  7502. void *p_rng,
  7503. unsigned int nbits, int exponent );
  7504. /**
  7505. * \brief This function checks if a context contains at least an RSA
  7506. * public key.
  7507. *
  7508. * If the function runs successfully, it is guaranteed that
  7509. * enough information is present to perform an RSA public key
  7510. * operation using mbedtls_rsa_public().
  7511. *
  7512. * \param ctx The RSA context to check.
  7513. *
  7514. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7515. * on failure.
  7516. *
  7517. */
  7518. int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx );
  7519. /**
  7520. * \brief This function checks if a context contains an RSA private key
  7521. * and perform basic consistency checks.
  7522. *
  7523. * \param ctx The RSA context to check.
  7524. *
  7525. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code on
  7526. * failure.
  7527. *
  7528. * \note The consistency checks performed by this function not only
  7529. * ensure that mbedtls_rsa_private() can be called successfully
  7530. * on the given context, but that the various parameters are
  7531. * mutually consistent with high probability, in the sense that
  7532. * mbedtls_rsa_public() and mbedtls_rsa_private() are inverses.
  7533. *
  7534. * \warning This function should catch accidental misconfigurations
  7535. * like swapping of parameters, but it cannot establish full
  7536. * trust in neither the quality nor the consistency of the key
  7537. * material that was used to setup the given RSA context:
  7538. * <ul><li>Consistency: Imported parameters that are irrelevant
  7539. * for the implementation might be silently dropped. If dropped,
  7540. * the current function does not have access to them,
  7541. * and therefore cannot check them. See mbedtls_rsa_complete().
  7542. * If you want to check the consistency of the entire
  7543. * content of an PKCS1-encoded RSA private key, for example, you
  7544. * should use mbedtls_rsa_validate_params() before setting
  7545. * up the RSA context.
  7546. * Additionally, if the implementation performs empirical checks,
  7547. * these checks substantiate but do not guarantee consistency.</li>
  7548. * <li>Quality: This function is not expected to perform
  7549. * extended quality assessments like checking that the prime
  7550. * factors are safe. Additionally, it is the responsibility of the
  7551. * user to ensure the trustworthiness of the source of his RSA
  7552. * parameters, which goes beyond what is effectively checkable
  7553. * by the library.</li></ul>
  7554. */
  7555. int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx );
  7556. /**
  7557. * \brief This function checks a public-private RSA key pair.
  7558. *
  7559. * It checks each of the contexts, and makes sure they match.
  7560. *
  7561. * \param pub The RSA context holding the public key.
  7562. * \param prv The RSA context holding the private key.
  7563. *
  7564. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7565. * on failure.
  7566. */
  7567. int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub,
  7568. const mbedtls_rsa_context *prv );
  7569. /**
  7570. * \brief This function performs an RSA public key operation.
  7571. *
  7572. * \param ctx The RSA context.
  7573. * \param input The input buffer.
  7574. * \param output The output buffer.
  7575. *
  7576. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7577. * on failure.
  7578. *
  7579. * \note This function does not handle message padding.
  7580. *
  7581. * \note Make sure to set \p input[0] = 0 or ensure that
  7582. * input is smaller than \p N.
  7583. *
  7584. * \note The input and output buffers must be large
  7585. * enough. For example, 128 Bytes if RSA-1024 is used.
  7586. */
  7587. int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
  7588. const unsigned char *input,
  7589. unsigned char *output );
  7590. /**
  7591. * \brief This function performs an RSA private key operation.
  7592. *
  7593. * \param ctx The RSA context.
  7594. * \param f_rng The RNG function. Needed for blinding.
  7595. * \param p_rng The RNG parameter.
  7596. * \param input The input buffer.
  7597. * \param output The output buffer.
  7598. *
  7599. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7600. * on failure.
  7601. *
  7602. * \note The input and output buffers must be large
  7603. * enough. For example, 128 Bytes if RSA-1024 is used.
  7604. *
  7605. * \note Blinding is used if and only if a PRNG is provided.
  7606. *
  7607. * \note If blinding is used, both the base of exponentation
  7608. * and the exponent are blinded, providing protection
  7609. * against some side-channel attacks.
  7610. *
  7611. * \warning It is deprecated and a security risk to not provide
  7612. * a PRNG here and thereby prevent the use of blinding.
  7613. * Future versions of the library may enforce the presence
  7614. * of a PRNG.
  7615. *
  7616. */
  7617. int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
  7618. int (*f_rng)(void *, unsigned char *, size_t),
  7619. void *p_rng,
  7620. const unsigned char *input,
  7621. unsigned char *output );
  7622. /**
  7623. * \brief This function adds the message padding, then performs an RSA
  7624. * operation.
  7625. *
  7626. * It is the generic wrapper for performing a PKCS#1 encryption
  7627. * operation using the \p mode from the context.
  7628. *
  7629. *
  7630. * \param ctx The RSA context.
  7631. * \param f_rng The RNG function. Needed for padding, PKCS#1 v2.1
  7632. * encoding, and #MBEDTLS_RSA_PRIVATE.
  7633. * \param p_rng The RNG parameter.
  7634. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7635. * \param ilen The length of the plaintext.
  7636. * \param input The buffer holding the data to encrypt.
  7637. * \param output The buffer used to hold the ciphertext.
  7638. *
  7639. * \deprecated It is deprecated and discouraged to call this function
  7640. * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
  7641. * are likely to remove the \p mode argument and have it
  7642. * implicitly set to #MBEDTLS_RSA_PUBLIC.
  7643. *
  7644. * \note Alternative implementations of RSA need not support
  7645. * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
  7646. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7647. *
  7648. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7649. * on failure.
  7650. *
  7651. * \note The input and output buffers must be as large as the size
  7652. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7653. */
  7654. int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
  7655. int (*f_rng)(void *, unsigned char *, size_t),
  7656. void *p_rng,
  7657. int mode, size_t ilen,
  7658. const unsigned char *input,
  7659. unsigned char *output );
  7660. /**
  7661. * \brief This function performs a PKCS#1 v1.5 encryption operation
  7662. * (RSAES-PKCS1-v1_5-ENCRYPT).
  7663. *
  7664. * \param ctx The RSA context.
  7665. * \param f_rng The RNG function. Needed for padding and
  7666. * #MBEDTLS_RSA_PRIVATE.
  7667. * \param p_rng The RNG parameter.
  7668. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7669. * \param ilen The length of the plaintext.
  7670. * \param input The buffer holding the data to encrypt.
  7671. * \param output The buffer used to hold the ciphertext.
  7672. *
  7673. * \deprecated It is deprecated and discouraged to call this function
  7674. * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
  7675. * are likely to remove the \p mode argument and have it
  7676. * implicitly set to #MBEDTLS_RSA_PUBLIC.
  7677. *
  7678. * \note Alternative implementations of RSA need not support
  7679. * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
  7680. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7681. *
  7682. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7683. * on failure.
  7684. *
  7685. * \note The output buffer must be as large as the size
  7686. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7687. */
  7688. int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
  7689. int (*f_rng)(void *, unsigned char *, size_t),
  7690. void *p_rng,
  7691. int mode, size_t ilen,
  7692. const unsigned char *input,
  7693. unsigned char *output );
  7694. /**
  7695. * \brief This function performs a PKCS#1 v2.1 OAEP encryption
  7696. * operation (RSAES-OAEP-ENCRYPT).
  7697. *
  7698. * \param ctx The RSA context.
  7699. * \param f_rng The RNG function. Needed for padding and PKCS#1 v2.1
  7700. * encoding and #MBEDTLS_RSA_PRIVATE.
  7701. * \param p_rng The RNG parameter.
  7702. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7703. * \param label The buffer holding the custom label to use.
  7704. * \param label_len The length of the label.
  7705. * \param ilen The length of the plaintext.
  7706. * \param input The buffer holding the data to encrypt.
  7707. * \param output The buffer used to hold the ciphertext.
  7708. *
  7709. * \deprecated It is deprecated and discouraged to call this function
  7710. * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
  7711. * are likely to remove the \p mode argument and have it
  7712. * implicitly set to #MBEDTLS_RSA_PUBLIC.
  7713. *
  7714. * \note Alternative implementations of RSA need not support
  7715. * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
  7716. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7717. *
  7718. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7719. * on failure.
  7720. *
  7721. * \note The output buffer must be as large as the size
  7722. * of ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7723. */
  7724. int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
  7725. int (*f_rng)(void *, unsigned char *, size_t),
  7726. void *p_rng,
  7727. int mode,
  7728. const unsigned char *label, size_t label_len,
  7729. size_t ilen,
  7730. const unsigned char *input,
  7731. unsigned char *output );
  7732. /**
  7733. * \brief This function performs an RSA operation, then removes the
  7734. * message padding.
  7735. *
  7736. * It is the generic wrapper for performing a PKCS#1 decryption
  7737. * operation using the \p mode from the context.
  7738. *
  7739. * \param ctx The RSA context.
  7740. * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
  7741. * \param p_rng The RNG parameter.
  7742. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7743. * \param olen The length of the plaintext.
  7744. * \param input The buffer holding the encrypted data.
  7745. * \param output The buffer used to hold the plaintext.
  7746. * \param output_max_len The maximum length of the output buffer.
  7747. *
  7748. * \deprecated It is deprecated and discouraged to call this function
  7749. * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
  7750. * are likely to remove the \p mode argument and have it
  7751. * implicitly set to #MBEDTLS_RSA_PRIVATE.
  7752. *
  7753. * \note Alternative implementations of RSA need not support
  7754. * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
  7755. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7756. *
  7757. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7758. * on failure.
  7759. *
  7760. * \note The output buffer length \c output_max_len should be
  7761. * as large as the size \p ctx->len of \p ctx->N (for example,
  7762. * 128 Bytes if RSA-1024 is used) to be able to hold an
  7763. * arbitrary decrypted message. If it is not large enough to
  7764. * hold the decryption of the particular ciphertext provided,
  7765. * the function returns \c MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
  7766. *
  7767. * \note The input buffer must be as large as the size
  7768. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7769. */
  7770. int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx,
  7771. int (*f_rng)(void *, unsigned char *, size_t),
  7772. void *p_rng,
  7773. int mode, size_t *olen,
  7774. const unsigned char *input,
  7775. unsigned char *output,
  7776. size_t output_max_len );
  7777. /**
  7778. * \brief This function performs a PKCS#1 v1.5 decryption
  7779. * operation (RSAES-PKCS1-v1_5-DECRYPT).
  7780. *
  7781. * \param ctx The RSA context.
  7782. * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
  7783. * \param p_rng The RNG parameter.
  7784. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7785. * \param olen The length of the plaintext.
  7786. * \param input The buffer holding the encrypted data.
  7787. * \param output The buffer to hold the plaintext.
  7788. * \param output_max_len The maximum length of the output buffer.
  7789. *
  7790. * \deprecated It is deprecated and discouraged to call this function
  7791. * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
  7792. * are likely to remove the \p mode argument and have it
  7793. * implicitly set to #MBEDTLS_RSA_PRIVATE.
  7794. *
  7795. * \note Alternative implementations of RSA need not support
  7796. * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
  7797. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7798. *
  7799. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7800. * on failure.
  7801. *
  7802. * \note The output buffer length \c output_max_len should be
  7803. * as large as the size \p ctx->len of \p ctx->N, for example,
  7804. * 128 Bytes if RSA-1024 is used, to be able to hold an
  7805. * arbitrary decrypted message. If it is not large enough to
  7806. * hold the decryption of the particular ciphertext provided,
  7807. * the function returns #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
  7808. *
  7809. * \note The input buffer must be as large as the size
  7810. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7811. */
  7812. int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx,
  7813. int (*f_rng)(void *, unsigned char *, size_t),
  7814. void *p_rng,
  7815. int mode, size_t *olen,
  7816. const unsigned char *input,
  7817. unsigned char *output,
  7818. size_t output_max_len );
  7819. /**
  7820. * \brief This function performs a PKCS#1 v2.1 OAEP decryption
  7821. * operation (RSAES-OAEP-DECRYPT).
  7822. *
  7823. * \param ctx The RSA context.
  7824. * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
  7825. * \param p_rng The RNG parameter.
  7826. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7827. * \param label The buffer holding the custom label to use.
  7828. * \param label_len The length of the label.
  7829. * \param olen The length of the plaintext.
  7830. * \param input The buffer holding the encrypted data.
  7831. * \param output The buffer to hold the plaintext.
  7832. * \param output_max_len The maximum length of the output buffer.
  7833. *
  7834. * \deprecated It is deprecated and discouraged to call this function
  7835. * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
  7836. * are likely to remove the \p mode argument and have it
  7837. * implicitly set to #MBEDTLS_RSA_PRIVATE.
  7838. *
  7839. * \note Alternative implementations of RSA need not support
  7840. * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
  7841. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7842. *
  7843. * \return \c 0 on success, or an \c MBEDTLS_ERR_RSA_XXX error code
  7844. * on failure.
  7845. *
  7846. * \note The output buffer length \c output_max_len should be
  7847. * as large as the size \p ctx->len of \p ctx->N, for
  7848. * example, 128 Bytes if RSA-1024 is used, to be able to
  7849. * hold an arbitrary decrypted message. If it is not
  7850. * large enough to hold the decryption of the particular
  7851. * ciphertext provided, the function returns
  7852. * #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
  7853. *
  7854. * \note The input buffer must be as large as the size
  7855. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7856. */
  7857. int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx,
  7858. int (*f_rng)(void *, unsigned char *, size_t),
  7859. void *p_rng,
  7860. int mode,
  7861. const unsigned char *label, size_t label_len,
  7862. size_t *olen,
  7863. const unsigned char *input,
  7864. unsigned char *output,
  7865. size_t output_max_len );
  7866. /**
  7867. * \brief This function performs a private RSA operation to sign
  7868. * a message digest using PKCS#1.
  7869. *
  7870. * It is the generic wrapper for performing a PKCS#1
  7871. * signature using the \p mode from the context.
  7872. *
  7873. * \param ctx The RSA context.
  7874. * \param f_rng The RNG function. Needed for PKCS#1 v2.1 encoding and for
  7875. * #MBEDTLS_RSA_PRIVATE.
  7876. * \param p_rng The RNG parameter.
  7877. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7878. * \param md_alg The message-digest algorithm used to hash the original data.
  7879. * Use #MBEDTLS_MD_NONE for signing raw data.
  7880. * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
  7881. * \param hash The buffer holding the message digest.
  7882. * \param sig The buffer to hold the ciphertext.
  7883. *
  7884. * \deprecated It is deprecated and discouraged to call this function
  7885. * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
  7886. * are likely to remove the \p mode argument and have it
  7887. * implicitly set to #MBEDTLS_RSA_PRIVATE.
  7888. *
  7889. * \note Alternative implementations of RSA need not support
  7890. * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
  7891. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7892. *
  7893. * \return \c 0 if the signing operation was successful,
  7894. * or an \c MBEDTLS_ERR_RSA_XXX error code on failure.
  7895. *
  7896. * \note The \p sig buffer must be as large as the size
  7897. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7898. *
  7899. * \note For PKCS#1 v2.1 encoding, see comments on
  7900. * mbedtls_rsa_rsassa_pss_sign() for details on
  7901. * \p md_alg and \p hash_id.
  7902. */
  7903. int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx,
  7904. int (*f_rng)(void *, unsigned char *, size_t),
  7905. void *p_rng,
  7906. int mode,
  7907. mbedtls_md_type_t md_alg,
  7908. unsigned int hashlen,
  7909. const unsigned char *hash,
  7910. unsigned char *sig );
  7911. /**
  7912. * \brief This function performs a PKCS#1 v1.5 signature
  7913. * operation (RSASSA-PKCS1-v1_5-SIGN).
  7914. *
  7915. * \param ctx The RSA context.
  7916. * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
  7917. * \param p_rng The RNG parameter.
  7918. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7919. * \param md_alg The message-digest algorithm used to hash the original data.
  7920. * Use #MBEDTLS_MD_NONE for signing raw data.
  7921. * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
  7922. * \param hash The buffer holding the message digest.
  7923. * \param sig The buffer to hold the ciphertext.
  7924. *
  7925. * \deprecated It is deprecated and discouraged to call this function
  7926. * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
  7927. * are likely to remove the \p mode argument and have it
  7928. * implicitly set to #MBEDTLS_RSA_PRIVATE.
  7929. *
  7930. * \note Alternative implementations of RSA need not support
  7931. * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
  7932. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7933. *
  7934. * \return \c 0 if the signing operation was successful,
  7935. * or an \c MBEDTLS_ERR_RSA_XXX error code
  7936. * on failure.
  7937. *
  7938. * \note The \p sig buffer must be as large as the size
  7939. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7940. */
  7941. int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
  7942. int (*f_rng)(void *, unsigned char *, size_t),
  7943. void *p_rng,
  7944. int mode,
  7945. mbedtls_md_type_t md_alg,
  7946. unsigned int hashlen,
  7947. const unsigned char *hash,
  7948. unsigned char *sig );
  7949. /**
  7950. * \brief This function performs a PKCS#1 v2.1 PSS signature
  7951. * operation (RSASSA-PSS-SIGN).
  7952. *
  7953. * \param ctx The RSA context.
  7954. * \param f_rng The RNG function. Needed for PKCS#1 v2.1 encoding and for
  7955. * #MBEDTLS_RSA_PRIVATE.
  7956. * \param p_rng The RNG parameter.
  7957. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  7958. * \param md_alg The message-digest algorithm used to hash the original data.
  7959. * Use #MBEDTLS_MD_NONE for signing raw data.
  7960. * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
  7961. * \param hash The buffer holding the message digest.
  7962. * \param sig The buffer to hold the ciphertext.
  7963. *
  7964. * \deprecated It is deprecated and discouraged to call this function
  7965. * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
  7966. * are likely to remove the \p mode argument and have it
  7967. * implicitly set to #MBEDTLS_RSA_PRIVATE.
  7968. *
  7969. * \note Alternative implementations of RSA need not support
  7970. * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
  7971. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  7972. *
  7973. * \return \c 0 if the signing operation was successful,
  7974. * or an \c MBEDTLS_ERR_RSA_XXX error code
  7975. * on failure.
  7976. *
  7977. * \note The \p sig buffer must be as large as the size
  7978. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  7979. *
  7980. * \note The \p hash_id in the RSA context is the one used for the
  7981. * encoding. \p md_alg in the function call is the type of hash
  7982. * that is encoded. According to <em>RFC-3447: Public-Key
  7983. * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
  7984. * Specifications</em> it is advised to keep both hashes the
  7985. * same.
  7986. */
  7987. int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx,
  7988. int (*f_rng)(void *, unsigned char *, size_t),
  7989. void *p_rng,
  7990. int mode,
  7991. mbedtls_md_type_t md_alg,
  7992. unsigned int hashlen,
  7993. const unsigned char *hash,
  7994. unsigned char *sig );
  7995. /**
  7996. * \brief This function performs a public RSA operation and checks
  7997. * the message digest.
  7998. *
  7999. * This is the generic wrapper for performing a PKCS#1
  8000. * verification using the mode from the context.
  8001. *
  8002. * \param ctx The RSA public key context.
  8003. * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
  8004. * \param p_rng The RNG parameter.
  8005. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  8006. * \param md_alg The message-digest algorithm used to hash the original data.
  8007. * Use #MBEDTLS_MD_NONE for signing raw data.
  8008. * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
  8009. * \param hash The buffer holding the message digest.
  8010. * \param sig The buffer holding the ciphertext.
  8011. *
  8012. * \deprecated It is deprecated and discouraged to call this function
  8013. * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
  8014. * are likely to remove the \p mode argument and have it
  8015. * set to #MBEDTLS_RSA_PUBLIC.
  8016. *
  8017. * \note Alternative implementations of RSA need not support
  8018. * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
  8019. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  8020. *
  8021. * \return \c 0 if the verify operation was successful,
  8022. * or an \c MBEDTLS_ERR_RSA_XXX error code
  8023. * on failure.
  8024. *
  8025. * \note The \p sig buffer must be as large as the size
  8026. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  8027. *
  8028. * \note For PKCS#1 v2.1 encoding, see comments on
  8029. * mbedtls_rsa_rsassa_pss_verify() about \p md_alg and
  8030. * \p hash_id.
  8031. */
  8032. int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx,
  8033. int (*f_rng)(void *, unsigned char *, size_t),
  8034. void *p_rng,
  8035. int mode,
  8036. mbedtls_md_type_t md_alg,
  8037. unsigned int hashlen,
  8038. const unsigned char *hash,
  8039. const unsigned char *sig );
  8040. /**
  8041. * \brief This function performs a PKCS#1 v1.5 verification
  8042. * operation (RSASSA-PKCS1-v1_5-VERIFY).
  8043. *
  8044. * \param ctx The RSA public key context.
  8045. * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
  8046. * \param p_rng The RNG parameter.
  8047. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  8048. * \param md_alg The message-digest algorithm used to hash the original data.
  8049. * Use #MBEDTLS_MD_NONE for signing raw data.
  8050. * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
  8051. * \param hash The buffer holding the message digest.
  8052. * \param sig The buffer holding the ciphertext.
  8053. *
  8054. * \deprecated It is deprecated and discouraged to call this function
  8055. * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
  8056. * are likely to remove the \p mode argument and have it
  8057. * set to #MBEDTLS_RSA_PUBLIC.
  8058. *
  8059. * \note Alternative implementations of RSA need not support
  8060. * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
  8061. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  8062. *
  8063. * \return \c 0 if the verify operation was successful,
  8064. * or an \c MBEDTLS_ERR_RSA_XXX error code
  8065. * on failure.
  8066. *
  8067. * \note The \p sig buffer must be as large as the size
  8068. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  8069. */
  8070. int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
  8071. int (*f_rng)(void *, unsigned char *, size_t),
  8072. void *p_rng,
  8073. int mode,
  8074. mbedtls_md_type_t md_alg,
  8075. unsigned int hashlen,
  8076. const unsigned char *hash,
  8077. const unsigned char *sig );
  8078. /**
  8079. * \brief This function performs a PKCS#1 v2.1 PSS verification
  8080. * operation (RSASSA-PSS-VERIFY).
  8081. *
  8082. * The hash function for the MGF mask generating function
  8083. * is that specified in the RSA context.
  8084. *
  8085. * \param ctx The RSA public key context.
  8086. * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
  8087. * \param p_rng The RNG parameter.
  8088. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  8089. * \param md_alg The message-digest algorithm used to hash the original data.
  8090. * Use #MBEDTLS_MD_NONE for signing raw data.
  8091. * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
  8092. * \param hash The buffer holding the message digest.
  8093. * \param sig The buffer holding the ciphertext.
  8094. *
  8095. * \deprecated It is deprecated and discouraged to call this function
  8096. * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
  8097. * are likely to remove the \p mode argument and have it
  8098. * implicitly set to #MBEDTLS_RSA_PUBLIC.
  8099. *
  8100. * \note Alternative implementations of RSA need not support
  8101. * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
  8102. * return #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION.
  8103. *
  8104. * \return \c 0 if the verify operation was successful,
  8105. * or an \c MBEDTLS_ERR_RSA_XXX error code
  8106. * on failure.
  8107. *
  8108. * \note The \p sig buffer must be as large as the size
  8109. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  8110. *
  8111. * \note The \p hash_id in the RSA context is the one used for the
  8112. * verification. \p md_alg in the function call is the type of
  8113. * hash that is verified. According to <em>RFC-3447: Public-Key
  8114. * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
  8115. * Specifications</em> it is advised to keep both hashes the
  8116. * same. If \p hash_id in the RSA context is unset,
  8117. * the \p md_alg from the function call is used.
  8118. */
  8119. int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
  8120. int (*f_rng)(void *, unsigned char *, size_t),
  8121. void *p_rng,
  8122. int mode,
  8123. mbedtls_md_type_t md_alg,
  8124. unsigned int hashlen,
  8125. const unsigned char *hash,
  8126. const unsigned char *sig );
  8127. /**
  8128. * \brief This function performs a PKCS#1 v2.1 PSS verification
  8129. * operation (RSASSA-PSS-VERIFY).
  8130. *
  8131. * The hash function for the MGF mask generating function
  8132. * is that specified in \p mgf1_hash_id.
  8133. *
  8134. * \param ctx The RSA public key context.
  8135. * \param f_rng The RNG function. Only needed for #MBEDTLS_RSA_PRIVATE.
  8136. * \param p_rng The RNG parameter.
  8137. * \param mode #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
  8138. * \param md_alg The message-digest algorithm used to hash the original data.
  8139. * Use #MBEDTLS_MD_NONE for signing raw data.
  8140. * \param hashlen The length of the message digest. Only used if \p md_alg is #MBEDTLS_MD_NONE.
  8141. * \param hash The buffer holding the message digest.
  8142. * \param mgf1_hash_id The message digest used for mask generation.
  8143. * \param expected_salt_len The length of the salt used in padding. Use
  8144. * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length.
  8145. * \param sig The buffer holding the ciphertext.
  8146. *
  8147. * \return \c 0 if the verify operation was successful,
  8148. * or an \c MBEDTLS_ERR_RSA_XXX error code
  8149. * on failure.
  8150. *
  8151. * \note The \p sig buffer must be as large as the size
  8152. * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
  8153. *
  8154. * \note The \p hash_id in the RSA context is ignored.
  8155. */
  8156. int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx,
  8157. int (*f_rng)(void *, unsigned char *, size_t),
  8158. void *p_rng,
  8159. int mode,
  8160. mbedtls_md_type_t md_alg,
  8161. unsigned int hashlen,
  8162. const unsigned char *hash,
  8163. mbedtls_md_type_t mgf1_hash_id,
  8164. int expected_salt_len,
  8165. const unsigned char *sig );
  8166. /**
  8167. * \brief This function copies the components of an RSA context.
  8168. *
  8169. * \param dst The destination context.
  8170. * \param src The source context.
  8171. *
  8172. * \return \c 0 on success,
  8173. * #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory allocation failure.
  8174. */
  8175. int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src );
  8176. /**
  8177. * \brief This function frees the components of an RSA key.
  8178. *
  8179. * \param ctx The RSA Context to free.
  8180. */
  8181. void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
  8182. #ifdef __cplusplus
  8183. }
  8184. #endif
  8185. #else /* MBEDTLS_RSA_ALT */
  8186. #endif /* MBEDTLS_RSA_ALT */
  8187. #ifdef __cplusplus
  8188. extern "C" {
  8189. #endif
  8190. /**
  8191. * \brief The RSA checkup routine.
  8192. *
  8193. * \return \c 0 on success, or \c 1 on failure.
  8194. */
  8195. int mbedtls_rsa_self_test( int verbose );
  8196. #ifdef __cplusplus
  8197. }
  8198. #endif
  8199. #endif /* rsa.h */
  8200. /********* Start of file include/mbedtls/rsa_internal.h ************/
  8201. /**
  8202. * \file rsa_internal.h
  8203. *
  8204. * \brief Context-independent RSA helper functions
  8205. */
  8206. /*
  8207. * Copyright (C) 2006-2017, ARM Limited, All Rights Reserved
  8208. * SPDX-License-Identifier: Apache-2.0
  8209. *
  8210. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  8211. * not use this file except in compliance with the License.
  8212. * You may obtain a copy of the License at
  8213. *
  8214. * http://www.apache.org/licenses/LICENSE-2.0
  8215. *
  8216. * Unless required by applicable law or agreed to in writing, software
  8217. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  8218. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8219. * See the License for the specific language governing permissions and
  8220. * limitations under the License.
  8221. *
  8222. * This file is part of mbed TLS (https://tls.mbed.org)
  8223. *
  8224. *
  8225. * This file declares some RSA-related helper functions useful when
  8226. * implementing the RSA interface. They are public and provided in a
  8227. * separate compilation unit in order to make it easy for designers of
  8228. * alternative RSA implementations to use them in their code, as it is
  8229. * conceived that the functionality they provide will be necessary
  8230. * for most complete implementations.
  8231. *
  8232. * End-users of Mbed TLS not intending to re-implement the RSA functionality
  8233. * are not expected to get into the need of making use of these functions directly,
  8234. * but instead should be able to use the functions declared in rsa.h.
  8235. *
  8236. * There are two classes of helper functions:
  8237. * (1) Parameter-generating helpers. These are:
  8238. * - mbedtls_rsa_deduce_primes
  8239. * - mbedtls_rsa_deduce_private_exponent
  8240. * - mbedtls_rsa_deduce_crt
  8241. * Each of these functions takes a set of core RSA parameters
  8242. * and generates some other, or CRT related parameters.
  8243. * (2) Parameter-checking helpers. These are:
  8244. * - mbedtls_rsa_validate_params
  8245. * - mbedtls_rsa_validate_crt
  8246. * They take a set of core or CRT related RSA parameters
  8247. * and check their validity.
  8248. *
  8249. */
  8250. #ifndef MBEDTLS_RSA_INTERNAL_H
  8251. #define MBEDTLS_RSA_INTERNAL_H
  8252. #if !defined(MBEDTLS_CONFIG_FILE)
  8253. #else
  8254. #endif
  8255. #ifdef __cplusplus
  8256. extern "C" {
  8257. #endif
  8258. /**
  8259. * \brief Compute RSA prime moduli P, Q from public modulus N=PQ
  8260. * and a pair of private and public key.
  8261. *
  8262. * \note This is a 'static' helper function not operating on
  8263. * an RSA context. Alternative implementations need not
  8264. * overwrite it.
  8265. *
  8266. * \param N RSA modulus N = PQ, with P, Q to be found
  8267. * \param E RSA public exponent
  8268. * \param D RSA private exponent
  8269. * \param P Pointer to MPI holding first prime factor of N on success
  8270. * \param Q Pointer to MPI holding second prime factor of N on success
  8271. *
  8272. * \return
  8273. * - 0 if successful. In this case, P and Q constitute a
  8274. * factorization of N.
  8275. * - A non-zero error code otherwise.
  8276. *
  8277. * \note It is neither checked that P, Q are prime nor that
  8278. * D, E are modular inverses wrt. P-1 and Q-1. For that,
  8279. * use the helper function \c mbedtls_rsa_validate_params.
  8280. *
  8281. */
  8282. int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, mbedtls_mpi const *E,
  8283. mbedtls_mpi const *D,
  8284. mbedtls_mpi *P, mbedtls_mpi *Q );
  8285. /**
  8286. * \brief Compute RSA private exponent from
  8287. * prime moduli and public key.
  8288. *
  8289. * \note This is a 'static' helper function not operating on
  8290. * an RSA context. Alternative implementations need not
  8291. * overwrite it.
  8292. *
  8293. * \param P First prime factor of RSA modulus
  8294. * \param Q Second prime factor of RSA modulus
  8295. * \param E RSA public exponent
  8296. * \param D Pointer to MPI holding the private exponent on success.
  8297. *
  8298. * \return
  8299. * - 0 if successful. In this case, D is set to a simultaneous
  8300. * modular inverse of E modulo both P-1 and Q-1.
  8301. * - A non-zero error code otherwise.
  8302. *
  8303. * \note This function does not check whether P and Q are primes.
  8304. *
  8305. */
  8306. int mbedtls_rsa_deduce_private_exponent( mbedtls_mpi const *P,
  8307. mbedtls_mpi const *Q,
  8308. mbedtls_mpi const *E,
  8309. mbedtls_mpi *D );
  8310. /**
  8311. * \brief Generate RSA-CRT parameters
  8312. *
  8313. * \note This is a 'static' helper function not operating on
  8314. * an RSA context. Alternative implementations need not
  8315. * overwrite it.
  8316. *
  8317. * \param P First prime factor of N
  8318. * \param Q Second prime factor of N
  8319. * \param D RSA private exponent
  8320. * \param DP Output variable for D modulo P-1
  8321. * \param DQ Output variable for D modulo Q-1
  8322. * \param QP Output variable for the modular inverse of Q modulo P.
  8323. *
  8324. * \return 0 on success, non-zero error code otherwise.
  8325. *
  8326. * \note This function does not check whether P, Q are
  8327. * prime and whether D is a valid private exponent.
  8328. *
  8329. */
  8330. int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
  8331. const mbedtls_mpi *D, mbedtls_mpi *DP,
  8332. mbedtls_mpi *DQ, mbedtls_mpi *QP );
  8333. /**
  8334. * \brief Check validity of core RSA parameters
  8335. *
  8336. * \note This is a 'static' helper function not operating on
  8337. * an RSA context. Alternative implementations need not
  8338. * overwrite it.
  8339. *
  8340. * \param N RSA modulus N = PQ
  8341. * \param P First prime factor of N
  8342. * \param Q Second prime factor of N
  8343. * \param D RSA private exponent
  8344. * \param E RSA public exponent
  8345. * \param f_rng PRNG to be used for primality check, or NULL
  8346. * \param p_rng PRNG context for f_rng, or NULL
  8347. *
  8348. * \return
  8349. * - 0 if the following conditions are satisfied
  8350. * if all relevant parameters are provided:
  8351. * - P prime if f_rng != NULL (%)
  8352. * - Q prime if f_rng != NULL (%)
  8353. * - 1 < N = P * Q
  8354. * - 1 < D, E < N
  8355. * - D and E are modular inverses modulo P-1 and Q-1
  8356. * (%) This is only done if MBEDTLS_GENPRIME is defined.
  8357. * - A non-zero error code otherwise.
  8358. *
  8359. * \note The function can be used with a restricted set of arguments
  8360. * to perform specific checks only. E.g., calling it with
  8361. * (-,P,-,-,-) and a PRNG amounts to a primality check for P.
  8362. */
  8363. int mbedtls_rsa_validate_params( const mbedtls_mpi *N, const mbedtls_mpi *P,
  8364. const mbedtls_mpi *Q, const mbedtls_mpi *D,
  8365. const mbedtls_mpi *E,
  8366. int (*f_rng)(void *, unsigned char *, size_t),
  8367. void *p_rng );
  8368. /**
  8369. * \brief Check validity of RSA CRT parameters
  8370. *
  8371. * \note This is a 'static' helper function not operating on
  8372. * an RSA context. Alternative implementations need not
  8373. * overwrite it.
  8374. *
  8375. * \param P First prime factor of RSA modulus
  8376. * \param Q Second prime factor of RSA modulus
  8377. * \param D RSA private exponent
  8378. * \param DP MPI to check for D modulo P-1
  8379. * \param DQ MPI to check for D modulo P-1
  8380. * \param QP MPI to check for the modular inverse of Q modulo P.
  8381. *
  8382. * \return
  8383. * - 0 if the following conditions are satisfied:
  8384. * - D = DP mod P-1 if P, D, DP != NULL
  8385. * - Q = DQ mod P-1 if P, D, DQ != NULL
  8386. * - QP = Q^-1 mod P if P, Q, QP != NULL
  8387. * - \c MBEDTLS_ERR_RSA_KEY_CHECK_FAILED if check failed,
  8388. * potentially including \c MBEDTLS_ERR_MPI_XXX if some
  8389. * MPI calculations failed.
  8390. * - \c MBEDTLS_ERR_RSA_BAD_INPUT_DATA if insufficient
  8391. * data was provided to check DP, DQ or QP.
  8392. *
  8393. * \note The function can be used with a restricted set of arguments
  8394. * to perform specific checks only. E.g., calling it with the
  8395. * parameters (P, -, D, DP, -, -) will check DP = D mod P-1.
  8396. */
  8397. int mbedtls_rsa_validate_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q,
  8398. const mbedtls_mpi *D, const mbedtls_mpi *DP,
  8399. const mbedtls_mpi *DQ, const mbedtls_mpi *QP );
  8400. #endif /* rsa_internal.h */
  8401. /********* Start of file include/mbedtls/asn1.h ************/
  8402. /**
  8403. * \file asn1.h
  8404. *
  8405. * \brief Generic ASN.1 parsing
  8406. */
  8407. /*
  8408. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  8409. * SPDX-License-Identifier: Apache-2.0
  8410. *
  8411. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  8412. * not use this file except in compliance with the License.
  8413. * You may obtain a copy of the License at
  8414. *
  8415. * http://www.apache.org/licenses/LICENSE-2.0
  8416. *
  8417. * Unless required by applicable law or agreed to in writing, software
  8418. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  8419. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8420. * See the License for the specific language governing permissions and
  8421. * limitations under the License.
  8422. *
  8423. * This file is part of mbed TLS (https://tls.mbed.org)
  8424. */
  8425. #ifndef MBEDTLS_ASN1_H
  8426. #define MBEDTLS_ASN1_H
  8427. #if !defined(MBEDTLS_CONFIG_FILE)
  8428. #else
  8429. #endif
  8430. #include <stddef.h>
  8431. #if defined(MBEDTLS_BIGNUM_C)
  8432. #endif
  8433. /**
  8434. * \addtogroup asn1_module
  8435. * \{
  8436. */
  8437. /**
  8438. * \name ASN1 Error codes
  8439. * These error codes are OR'ed to X509 error codes for
  8440. * higher error granularity.
  8441. * ASN1 is a standard to specify data structures.
  8442. * \{
  8443. */
  8444. #define MBEDTLS_ERR_ASN1_OUT_OF_DATA -0x0060 /**< Out of data when parsing an ASN1 data structure. */
  8445. #define MBEDTLS_ERR_ASN1_UNEXPECTED_TAG -0x0062 /**< ASN1 tag was of an unexpected value. */
  8446. #define MBEDTLS_ERR_ASN1_INVALID_LENGTH -0x0064 /**< Error when trying to determine the length or invalid length. */
  8447. #define MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -0x0066 /**< Actual length differs from expected length. */
  8448. #define MBEDTLS_ERR_ASN1_INVALID_DATA -0x0068 /**< Data is invalid. (not used) */
  8449. #define MBEDTLS_ERR_ASN1_ALLOC_FAILED -0x006A /**< Memory allocation failed */
  8450. #define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C /**< Buffer too small when writing ASN.1 data structure. */
  8451. /* \} name */
  8452. /**
  8453. * \name DER constants
  8454. * These constants comply with the DER encoded ASN.1 type tags.
  8455. * DER encoding uses hexadecimal representation.
  8456. * An example DER sequence is:\n
  8457. * - 0x02 -- tag indicating INTEGER
  8458. * - 0x01 -- length in octets
  8459. * - 0x05 -- value
  8460. * Such sequences are typically read into \c ::mbedtls_x509_buf.
  8461. * \{
  8462. */
  8463. #define MBEDTLS_ASN1_BOOLEAN 0x01
  8464. #define MBEDTLS_ASN1_INTEGER 0x02
  8465. #define MBEDTLS_ASN1_BIT_STRING 0x03
  8466. #define MBEDTLS_ASN1_OCTET_STRING 0x04
  8467. #define MBEDTLS_ASN1_NULL 0x05
  8468. #define MBEDTLS_ASN1_OID 0x06
  8469. #define MBEDTLS_ASN1_UTF8_STRING 0x0C
  8470. #define MBEDTLS_ASN1_SEQUENCE 0x10
  8471. #define MBEDTLS_ASN1_SET 0x11
  8472. #define MBEDTLS_ASN1_PRINTABLE_STRING 0x13
  8473. #define MBEDTLS_ASN1_T61_STRING 0x14
  8474. #define MBEDTLS_ASN1_IA5_STRING 0x16
  8475. #define MBEDTLS_ASN1_UTC_TIME 0x17
  8476. #define MBEDTLS_ASN1_GENERALIZED_TIME 0x18
  8477. #define MBEDTLS_ASN1_UNIVERSAL_STRING 0x1C
  8478. #define MBEDTLS_ASN1_BMP_STRING 0x1E
  8479. #define MBEDTLS_ASN1_PRIMITIVE 0x00
  8480. #define MBEDTLS_ASN1_CONSTRUCTED 0x20
  8481. #define MBEDTLS_ASN1_CONTEXT_SPECIFIC 0x80
  8482. /*
  8483. * Bit masks for each of the components of an ASN.1 tag as specified in
  8484. * ITU X.690 (08/2015), section 8.1 "General rules for encoding",
  8485. * paragraph 8.1.2.2:
  8486. *
  8487. * Bit 8 7 6 5 1
  8488. * +-------+-----+------------+
  8489. * | Class | P/C | Tag number |
  8490. * +-------+-----+------------+
  8491. */
  8492. #define MBEDTLS_ASN1_TAG_CLASS_MASK 0xC0
  8493. #define MBEDTLS_ASN1_TAG_PC_MASK 0x20
  8494. #define MBEDTLS_ASN1_TAG_VALUE_MASK 0x1F
  8495. /* \} name */
  8496. /* \} addtogroup asn1_module */
  8497. /** Returns the size of the binary string, without the trailing \\0 */
  8498. #define MBEDTLS_OID_SIZE(x) (sizeof(x) - 1)
  8499. /**
  8500. * Compares an mbedtls_asn1_buf structure to a reference OID.
  8501. *
  8502. * Only works for 'defined' oid_str values (MBEDTLS_OID_HMAC_SHA1), you cannot use a
  8503. * 'unsigned char *oid' here!
  8504. */
  8505. #define MBEDTLS_OID_CMP(oid_str, oid_buf) \
  8506. ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len ) || \
  8507. memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) != 0 )
  8508. #ifdef __cplusplus
  8509. extern "C" {
  8510. #endif
  8511. /**
  8512. * \name Functions to parse ASN.1 data structures
  8513. * \{
  8514. */
  8515. /**
  8516. * Type-length-value structure that allows for ASN1 using DER.
  8517. */
  8518. typedef struct mbedtls_asn1_buf
  8519. {
  8520. int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */
  8521. size_t len; /**< ASN1 length, in octets. */
  8522. unsigned char *p; /**< ASN1 data, e.g. in ASCII. */
  8523. }
  8524. mbedtls_asn1_buf;
  8525. /**
  8526. * Container for ASN1 bit strings.
  8527. */
  8528. typedef struct mbedtls_asn1_bitstring
  8529. {
  8530. size_t len; /**< ASN1 length, in octets. */
  8531. unsigned char unused_bits; /**< Number of unused bits at the end of the string */
  8532. unsigned char *p; /**< Raw ASN1 data for the bit string */
  8533. }
  8534. mbedtls_asn1_bitstring;
  8535. /**
  8536. * Container for a sequence of ASN.1 items
  8537. */
  8538. typedef struct mbedtls_asn1_sequence
  8539. {
  8540. mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */
  8541. struct mbedtls_asn1_sequence *next; /**< The next entry in the sequence. */
  8542. }
  8543. mbedtls_asn1_sequence;
  8544. /**
  8545. * Container for a sequence or list of 'named' ASN.1 data items
  8546. */
  8547. typedef struct mbedtls_asn1_named_data
  8548. {
  8549. mbedtls_asn1_buf oid; /**< The object identifier. */
  8550. mbedtls_asn1_buf val; /**< The named value. */
  8551. struct mbedtls_asn1_named_data *next; /**< The next entry in the sequence. */
  8552. unsigned char next_merged; /**< Merge next item into the current one? */
  8553. }
  8554. mbedtls_asn1_named_data;
  8555. /**
  8556. * \brief Get the length of an ASN.1 element.
  8557. * Updates the pointer to immediately behind the length.
  8558. *
  8559. * \param p The position in the ASN.1 data
  8560. * \param end End of data
  8561. * \param len The variable that will receive the value
  8562. *
  8563. * \return 0 if successful, MBEDTLS_ERR_ASN1_OUT_OF_DATA on reaching
  8564. * end of data, MBEDTLS_ERR_ASN1_INVALID_LENGTH if length is
  8565. * unparseable.
  8566. */
  8567. int mbedtls_asn1_get_len( unsigned char **p,
  8568. const unsigned char *end,
  8569. size_t *len );
  8570. /**
  8571. * \brief Get the tag and length of the tag. Check for the requested tag.
  8572. * Updates the pointer to immediately behind the tag and length.
  8573. *
  8574. * \param p The position in the ASN.1 data
  8575. * \param end End of data
  8576. * \param len The variable that will receive the length
  8577. * \param tag The expected tag
  8578. *
  8579. * \return 0 if successful, MBEDTLS_ERR_ASN1_UNEXPECTED_TAG if tag did
  8580. * not match requested tag, or another specific ASN.1 error code.
  8581. */
  8582. int mbedtls_asn1_get_tag( unsigned char **p,
  8583. const unsigned char *end,
  8584. size_t *len, int tag );
  8585. /**
  8586. * \brief Retrieve a boolean ASN.1 tag and its value.
  8587. * Updates the pointer to immediately behind the full tag.
  8588. *
  8589. * \param p The position in the ASN.1 data
  8590. * \param end End of data
  8591. * \param val The variable that will receive the value
  8592. *
  8593. * \return 0 if successful or a specific ASN.1 error code.
  8594. */
  8595. int mbedtls_asn1_get_bool( unsigned char **p,
  8596. const unsigned char *end,
  8597. int *val );
  8598. /**
  8599. * \brief Retrieve an integer ASN.1 tag and its value.
  8600. * Updates the pointer to immediately behind the full tag.
  8601. *
  8602. * \param p The position in the ASN.1 data
  8603. * \param end End of data
  8604. * \param val The variable that will receive the value
  8605. *
  8606. * \return 0 if successful or a specific ASN.1 error code.
  8607. */
  8608. int mbedtls_asn1_get_int( unsigned char **p,
  8609. const unsigned char *end,
  8610. int *val );
  8611. /**
  8612. * \brief Retrieve a bitstring ASN.1 tag and its value.
  8613. * Updates the pointer to immediately behind the full tag.
  8614. *
  8615. * \param p The position in the ASN.1 data
  8616. * \param end End of data
  8617. * \param bs The variable that will receive the value
  8618. *
  8619. * \return 0 if successful or a specific ASN.1 error code.
  8620. */
  8621. int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end,
  8622. mbedtls_asn1_bitstring *bs);
  8623. /**
  8624. * \brief Retrieve a bitstring ASN.1 tag without unused bits and its
  8625. * value.
  8626. * Updates the pointer to the beginning of the bit/octet string.
  8627. *
  8628. * \param p The position in the ASN.1 data
  8629. * \param end End of data
  8630. * \param len Length of the actual bit/octect string in bytes
  8631. *
  8632. * \return 0 if successful or a specific ASN.1 error code.
  8633. */
  8634. int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end,
  8635. size_t *len );
  8636. /**
  8637. * \brief Parses and splits an ASN.1 "SEQUENCE OF <tag>"
  8638. * Updated the pointer to immediately behind the full sequence tag.
  8639. *
  8640. * \param p The position in the ASN.1 data
  8641. * \param end End of data
  8642. * \param cur First variable in the chain to fill
  8643. * \param tag Type of sequence
  8644. *
  8645. * \return 0 if successful or a specific ASN.1 error code.
  8646. */
  8647. int mbedtls_asn1_get_sequence_of( unsigned char **p,
  8648. const unsigned char *end,
  8649. mbedtls_asn1_sequence *cur,
  8650. int tag);
  8651. #if defined(MBEDTLS_BIGNUM_C)
  8652. /**
  8653. * \brief Retrieve a MPI value from an integer ASN.1 tag.
  8654. * Updates the pointer to immediately behind the full tag.
  8655. *
  8656. * \param p The position in the ASN.1 data
  8657. * \param end End of data
  8658. * \param X The MPI that will receive the value
  8659. *
  8660. * \return 0 if successful or a specific ASN.1 or MPI error code.
  8661. */
  8662. int mbedtls_asn1_get_mpi( unsigned char **p,
  8663. const unsigned char *end,
  8664. mbedtls_mpi *X );
  8665. #endif /* MBEDTLS_BIGNUM_C */
  8666. /**
  8667. * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence.
  8668. * Updates the pointer to immediately behind the full
  8669. * AlgorithmIdentifier.
  8670. *
  8671. * \param p The position in the ASN.1 data
  8672. * \param end End of data
  8673. * \param alg The buffer to receive the OID
  8674. * \param params The buffer to receive the params (if any)
  8675. *
  8676. * \return 0 if successful or a specific ASN.1 or MPI error code.
  8677. */
  8678. int mbedtls_asn1_get_alg( unsigned char **p,
  8679. const unsigned char *end,
  8680. mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params );
  8681. /**
  8682. * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no
  8683. * params.
  8684. * Updates the pointer to immediately behind the full
  8685. * AlgorithmIdentifier.
  8686. *
  8687. * \param p The position in the ASN.1 data
  8688. * \param end End of data
  8689. * \param alg The buffer to receive the OID
  8690. *
  8691. * \return 0 if successful or a specific ASN.1 or MPI error code.
  8692. */
  8693. int mbedtls_asn1_get_alg_null( unsigned char **p,
  8694. const unsigned char *end,
  8695. mbedtls_asn1_buf *alg );
  8696. /**
  8697. * \brief Find a specific named_data entry in a sequence or list based on
  8698. * the OID.
  8699. *
  8700. * \param list The list to seek through
  8701. * \param oid The OID to look for
  8702. * \param len Size of the OID
  8703. *
  8704. * \return NULL if not found, or a pointer to the existing entry.
  8705. */
  8706. mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( mbedtls_asn1_named_data *list,
  8707. const char *oid, size_t len );
  8708. /**
  8709. * \brief Free a mbedtls_asn1_named_data entry
  8710. *
  8711. * \param entry The named data entry to free
  8712. */
  8713. void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *entry );
  8714. /**
  8715. * \brief Free all entries in a mbedtls_asn1_named_data list
  8716. * Head will be set to NULL
  8717. *
  8718. * \param head Pointer to the head of the list of named data entries to free
  8719. */
  8720. void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head );
  8721. #ifdef __cplusplus
  8722. }
  8723. #endif
  8724. #endif /* asn1.h */
  8725. /********* Start of file include/mbedtls/ecp.h ************/
  8726. /**
  8727. * \file ecp.h
  8728. *
  8729. * \brief Elliptic curves over GF(p)
  8730. */
  8731. /*
  8732. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  8733. * SPDX-License-Identifier: Apache-2.0
  8734. *
  8735. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  8736. * not use this file except in compliance with the License.
  8737. * You may obtain a copy of the License at
  8738. *
  8739. * http://www.apache.org/licenses/LICENSE-2.0
  8740. *
  8741. * Unless required by applicable law or agreed to in writing, software
  8742. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  8743. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8744. * See the License for the specific language governing permissions and
  8745. * limitations under the License.
  8746. *
  8747. * This file is part of mbed TLS (https://tls.mbed.org)
  8748. */
  8749. #ifndef MBEDTLS_ECP_H
  8750. #define MBEDTLS_ECP_H
  8751. /*
  8752. * ECP error codes
  8753. */
  8754. #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */
  8755. #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 /**< The buffer is too small to write to. */
  8756. #define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 /**< Requested curve not available. */
  8757. #define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 /**< The signature is not valid. */
  8758. #define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 /**< Memory allocation failed. */
  8759. #define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as (ephemeral) key, failed. */
  8760. #define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 /**< Invalid private or public key. */
  8761. #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< Signature is valid but shorter than the user-supplied length. */
  8762. #define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 /**< ECP hardware accelerator failed. */
  8763. #if !defined(MBEDTLS_ECP_ALT)
  8764. /*
  8765. * default mbed TLS elliptic curve arithmetic implementation
  8766. *
  8767. * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
  8768. * alternative implementation for the whole module and it will replace this
  8769. * one.)
  8770. */
  8771. #ifdef __cplusplus
  8772. extern "C" {
  8773. #endif
  8774. /**
  8775. * Domain parameters (curve, subgroup and generator) identifiers.
  8776. *
  8777. * Only curves over prime fields are supported.
  8778. *
  8779. * \warning This library does not support validation of arbitrary domain
  8780. * parameters. Therefore, only well-known domain parameters from trusted
  8781. * sources should be used. See mbedtls_ecp_group_load().
  8782. */
  8783. typedef enum
  8784. {
  8785. MBEDTLS_ECP_DP_NONE = 0,
  8786. MBEDTLS_ECP_DP_SECP192R1, /*!< 192-bits NIST curve */
  8787. MBEDTLS_ECP_DP_SECP224R1, /*!< 224-bits NIST curve */
  8788. MBEDTLS_ECP_DP_SECP256R1, /*!< 256-bits NIST curve */
  8789. MBEDTLS_ECP_DP_SECP384R1, /*!< 384-bits NIST curve */
  8790. MBEDTLS_ECP_DP_SECP521R1, /*!< 521-bits NIST curve */
  8791. MBEDTLS_ECP_DP_BP256R1, /*!< 256-bits Brainpool curve */
  8792. MBEDTLS_ECP_DP_BP384R1, /*!< 384-bits Brainpool curve */
  8793. MBEDTLS_ECP_DP_BP512R1, /*!< 512-bits Brainpool curve */
  8794. MBEDTLS_ECP_DP_CURVE25519, /*!< Curve25519 */
  8795. MBEDTLS_ECP_DP_SECP192K1, /*!< 192-bits "Koblitz" curve */
  8796. MBEDTLS_ECP_DP_SECP224K1, /*!< 224-bits "Koblitz" curve */
  8797. MBEDTLS_ECP_DP_SECP256K1, /*!< 256-bits "Koblitz" curve */
  8798. } mbedtls_ecp_group_id;
  8799. /**
  8800. * Number of supported curves (plus one for NONE).
  8801. *
  8802. * (Montgomery curves excluded for now.)
  8803. */
  8804. #define MBEDTLS_ECP_DP_MAX 12
  8805. /**
  8806. * Curve information for use by other modules
  8807. */
  8808. typedef struct
  8809. {
  8810. mbedtls_ecp_group_id grp_id; /*!< Internal identifier */
  8811. uint16_t tls_id; /*!< TLS NamedCurve identifier */
  8812. uint16_t bit_size; /*!< Curve size in bits */
  8813. const char *name; /*!< Human-friendly name */
  8814. } mbedtls_ecp_curve_info;
  8815. /**
  8816. * \brief ECP point structure (jacobian coordinates)
  8817. *
  8818. * \note All functions expect and return points satisfying
  8819. * the following condition: Z == 0 or Z == 1. (Other
  8820. * values of Z are used by internal functions only.)
  8821. * The point is zero, or "at infinity", if Z == 0.
  8822. * Otherwise, X and Y are its standard (affine) coordinates.
  8823. */
  8824. typedef struct
  8825. {
  8826. mbedtls_mpi X; /*!< the point's X coordinate */
  8827. mbedtls_mpi Y; /*!< the point's Y coordinate */
  8828. mbedtls_mpi Z; /*!< the point's Z coordinate */
  8829. }
  8830. mbedtls_ecp_point;
  8831. /**
  8832. * \brief ECP group structure
  8833. *
  8834. * We consider two types of curves equations:
  8835. * 1. Short Weierstrass y^2 = x^3 + A x + B mod P (SEC1 + RFC 4492)
  8836. * 2. Montgomery, y^2 = x^3 + A x^2 + x mod P (Curve25519 + draft)
  8837. * In both cases, a generator G for a prime-order subgroup is fixed. In the
  8838. * short weierstrass, this subgroup is actually the whole curve, and its
  8839. * cardinal is denoted by N.
  8840. *
  8841. * In the case of Short Weierstrass curves, our code requires that N is an odd
  8842. * prime. (Use odd in mbedtls_ecp_mul() and prime in mbedtls_ecdsa_sign() for blinding.)
  8843. *
  8844. * In the case of Montgomery curves, we don't store A but (A + 2) / 4 which is
  8845. * the quantity actually used in the formulas. Also, nbits is not the size of N
  8846. * but the required size for private keys.
  8847. *
  8848. * If modp is NULL, reduction modulo P is done using a generic algorithm.
  8849. * Otherwise, it must point to a function that takes an mbedtls_mpi in the range
  8850. * 0..2^(2*pbits)-1 and transforms it in-place in an integer of little more
  8851. * than pbits, so that the integer may be efficiently brought in the 0..P-1
  8852. * range by a few additions or substractions. It must return 0 on success and
  8853. * non-zero on failure.
  8854. */
  8855. typedef struct
  8856. {
  8857. mbedtls_ecp_group_id id; /*!< internal group identifier */
  8858. mbedtls_mpi P; /*!< prime modulus of the base field */
  8859. mbedtls_mpi A; /*!< 1. A in the equation, or 2. (A + 2) / 4 */
  8860. mbedtls_mpi B; /*!< 1. B in the equation, or 2. unused */
  8861. mbedtls_ecp_point G; /*!< generator of the (sub)group used */
  8862. mbedtls_mpi N; /*!< 1. the order of G, or 2. unused */
  8863. size_t pbits; /*!< number of bits in P */
  8864. size_t nbits; /*!< number of bits in 1. P, or 2. private keys */
  8865. unsigned int h; /*!< internal: 1 if the constants are static */
  8866. int (*modp)(mbedtls_mpi *); /*!< function for fast reduction mod P */
  8867. int (*t_pre)(mbedtls_ecp_point *, void *); /*!< unused */
  8868. int (*t_post)(mbedtls_ecp_point *, void *); /*!< unused */
  8869. void *t_data; /*!< unused */
  8870. mbedtls_ecp_point *T; /*!< pre-computed points for ecp_mul_comb() */
  8871. size_t T_size; /*!< number for pre-computed points */
  8872. }
  8873. mbedtls_ecp_group;
  8874. /**
  8875. * \brief ECP key pair structure
  8876. *
  8877. * A generic key pair that could be used for ECDSA, fixed ECDH, etc.
  8878. *
  8879. * \note Members purposefully in the same order as struc mbedtls_ecdsa_context.
  8880. */
  8881. typedef struct
  8882. {
  8883. mbedtls_ecp_group grp; /*!< Elliptic curve and base point */
  8884. mbedtls_mpi d; /*!< our secret value */
  8885. mbedtls_ecp_point Q; /*!< our public value */
  8886. }
  8887. mbedtls_ecp_keypair;
  8888. /**
  8889. * \name SECTION: Module settings
  8890. *
  8891. * The configuration options you can set for this module are in this section.
  8892. * Either change them in config.h or define them on the compiler command line.
  8893. * \{
  8894. */
  8895. #if !defined(MBEDTLS_ECP_MAX_BITS)
  8896. /**
  8897. * Maximum size of the groups (that is, of N and P)
  8898. */
  8899. #define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */
  8900. #endif
  8901. #define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 )
  8902. #define MBEDTLS_ECP_MAX_PT_LEN ( 2 * MBEDTLS_ECP_MAX_BYTES + 1 )
  8903. #if !defined(MBEDTLS_ECP_WINDOW_SIZE)
  8904. /*
  8905. * Maximum "window" size used for point multiplication.
  8906. * Default: 6.
  8907. * Minimum value: 2. Maximum value: 7.
  8908. *
  8909. * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) )
  8910. * points used for point multiplication. This value is directly tied to EC
  8911. * peak memory usage, so decreasing it by one should roughly cut memory usage
  8912. * by two (if large curves are in use).
  8913. *
  8914. * Reduction in size may reduce speed, but larger curves are impacted first.
  8915. * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1):
  8916. * w-size: 6 5 4 3 2
  8917. * 521 145 141 135 120 97
  8918. * 384 214 209 198 177 146
  8919. * 256 320 320 303 262 226
  8920. * 224 475 475 453 398 342
  8921. * 192 640 640 633 587 476
  8922. */
  8923. #define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */
  8924. #endif /* MBEDTLS_ECP_WINDOW_SIZE */
  8925. #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM)
  8926. /*
  8927. * Trade memory for speed on fixed-point multiplication.
  8928. *
  8929. * This speeds up repeated multiplication of the generator (that is, the
  8930. * multiplication in ECDSA signatures, and half of the multiplications in
  8931. * ECDSA verification and ECDHE) by a factor roughly 3 to 4.
  8932. *
  8933. * The cost is increasing EC peak memory usage by a factor roughly 2.
  8934. *
  8935. * Change this value to 0 to reduce peak memory usage.
  8936. */
  8937. #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */
  8938. #endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */
  8939. /* \} name SECTION: Module settings */
  8940. /*
  8941. * Point formats, from RFC 4492's enum ECPointFormat
  8942. */
  8943. #define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format */
  8944. #define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format */
  8945. /*
  8946. * Some other constants from RFC 4492
  8947. */
  8948. #define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */
  8949. /**
  8950. * \brief Get the list of supported curves in order of preferrence
  8951. * (full information)
  8952. *
  8953. * \return A statically allocated array, the last entry is 0.
  8954. */
  8955. const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void );
  8956. /**
  8957. * \brief Get the list of supported curves in order of preferrence
  8958. * (grp_id only)
  8959. *
  8960. * \return A statically allocated array,
  8961. * terminated with MBEDTLS_ECP_DP_NONE.
  8962. */
  8963. const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void );
  8964. /**
  8965. * \brief Get curve information from an internal group identifier
  8966. *
  8967. * \param grp_id A MBEDTLS_ECP_DP_XXX value
  8968. *
  8969. * \return The associated curve information or NULL
  8970. */
  8971. const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_group_id grp_id );
  8972. /**
  8973. * \brief Get curve information from a TLS NamedCurve value
  8974. *
  8975. * \param tls_id A MBEDTLS_ECP_DP_XXX value
  8976. *
  8977. * \return The associated curve information or NULL
  8978. */
  8979. const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_id );
  8980. /**
  8981. * \brief Get curve information from a human-readable name
  8982. *
  8983. * \param name The name
  8984. *
  8985. * \return The associated curve information or NULL
  8986. */
  8987. const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name );
  8988. /**
  8989. * \brief Initialize a point (as zero)
  8990. */
  8991. void mbedtls_ecp_point_init( mbedtls_ecp_point *pt );
  8992. /**
  8993. * \brief Initialize a group (to something meaningless)
  8994. */
  8995. void mbedtls_ecp_group_init( mbedtls_ecp_group *grp );
  8996. /**
  8997. * \brief Initialize a key pair (as an invalid one)
  8998. */
  8999. void mbedtls_ecp_keypair_init( mbedtls_ecp_keypair *key );
  9000. /**
  9001. * \brief Free the components of a point
  9002. */
  9003. void mbedtls_ecp_point_free( mbedtls_ecp_point *pt );
  9004. /**
  9005. * \brief Free the components of an ECP group
  9006. */
  9007. void mbedtls_ecp_group_free( mbedtls_ecp_group *grp );
  9008. /**
  9009. * \brief Free the components of a key pair
  9010. */
  9011. void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key );
  9012. /**
  9013. * \brief Copy the contents of point Q into P
  9014. *
  9015. * \param P Destination point
  9016. * \param Q Source point
  9017. *
  9018. * \return 0 if successful,
  9019. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  9020. */
  9021. int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q );
  9022. /**
  9023. * \brief Copy the contents of a group object
  9024. *
  9025. * \param dst Destination group
  9026. * \param src Source group
  9027. *
  9028. * \return 0 if successful,
  9029. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  9030. */
  9031. int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst, const mbedtls_ecp_group *src );
  9032. /**
  9033. * \brief Set a point to zero
  9034. *
  9035. * \param pt Destination point
  9036. *
  9037. * \return 0 if successful,
  9038. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  9039. */
  9040. int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt );
  9041. /**
  9042. * \brief Tell if a point is zero
  9043. *
  9044. * \param pt Point to test
  9045. *
  9046. * \return 1 if point is zero, 0 otherwise
  9047. */
  9048. int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt );
  9049. /**
  9050. * \brief Compare two points
  9051. *
  9052. * \note This assumes the points are normalized. Otherwise,
  9053. * they may compare as "not equal" even if they are.
  9054. *
  9055. * \param P First point to compare
  9056. * \param Q Second point to compare
  9057. *
  9058. * \return 0 if the points are equal,
  9059. * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise
  9060. */
  9061. int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P,
  9062. const mbedtls_ecp_point *Q );
  9063. /**
  9064. * \brief Import a non-zero point from two ASCII strings
  9065. *
  9066. * \param P Destination point
  9067. * \param radix Input numeric base
  9068. * \param x First affine coordinate as a null-terminated string
  9069. * \param y Second affine coordinate as a null-terminated string
  9070. *
  9071. * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code
  9072. */
  9073. int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix,
  9074. const char *x, const char *y );
  9075. /**
  9076. * \brief Export a point into unsigned binary data
  9077. *
  9078. * \param grp Group to which the point should belong
  9079. * \param P Point to export
  9080. * \param format Point format, should be a MBEDTLS_ECP_PF_XXX macro
  9081. * \param olen Length of the actual output
  9082. * \param buf Output buffer
  9083. * \param buflen Length of the output buffer
  9084. *
  9085. * \return 0 if successful,
  9086. * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA
  9087. * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
  9088. */
  9089. int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P,
  9090. int format, size_t *olen,
  9091. unsigned char *buf, size_t buflen );
  9092. /**
  9093. * \brief Import a point from unsigned binary data
  9094. *
  9095. * \param grp Group to which the point should belong
  9096. * \param P Point to import
  9097. * \param buf Input buffer
  9098. * \param ilen Actual length of input
  9099. *
  9100. * \return 0 if successful,
  9101. * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid,
  9102. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed,
  9103. * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format
  9104. * is not implemented.
  9105. *
  9106. * \note This function does NOT check that the point actually
  9107. * belongs to the given group, see mbedtls_ecp_check_pubkey() for
  9108. * that.
  9109. */
  9110. int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P,
  9111. const unsigned char *buf, size_t ilen );
  9112. /**
  9113. * \brief Import a point from a TLS ECPoint record
  9114. *
  9115. * \param grp ECP group used
  9116. * \param pt Destination point
  9117. * \param buf $(Start of input buffer)
  9118. * \param len Buffer length
  9119. *
  9120. * \note buf is updated to point right after the ECPoint on exit
  9121. *
  9122. * \return 0 if successful,
  9123. * MBEDTLS_ERR_MPI_XXX if initialization failed
  9124. * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid
  9125. */
  9126. int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt,
  9127. const unsigned char **buf, size_t len );
  9128. /**
  9129. * \brief Export a point as a TLS ECPoint record
  9130. *
  9131. * \param grp ECP group used
  9132. * \param pt Point to export
  9133. * \param format Export format
  9134. * \param olen length of data written
  9135. * \param buf Buffer to write to
  9136. * \param blen Buffer length
  9137. *
  9138. * \return 0 if successful,
  9139. * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA
  9140. * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
  9141. */
  9142. int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt,
  9143. int format, size_t *olen,
  9144. unsigned char *buf, size_t blen );
  9145. /**
  9146. * \brief Set a group using well-known domain parameters
  9147. *
  9148. * \param grp Destination group
  9149. * \param id Index in the list of well-known domain parameters
  9150. *
  9151. * \return 0 if successful,
  9152. * MBEDTLS_ERR_MPI_XXX if initialization failed
  9153. * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE for unkownn groups
  9154. *
  9155. * \note Index should be a value of RFC 4492's enum NamedCurve,
  9156. * usually in the form of a MBEDTLS_ECP_DP_XXX macro.
  9157. */
  9158. int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id );
  9159. /**
  9160. * \brief Set a group from a TLS ECParameters record
  9161. *
  9162. * \param grp Destination group
  9163. * \param buf &(Start of input buffer)
  9164. * \param len Buffer length
  9165. *
  9166. * \note buf is updated to point right after ECParameters on exit
  9167. *
  9168. * \return 0 if successful,
  9169. * MBEDTLS_ERR_MPI_XXX if initialization failed
  9170. * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid
  9171. */
  9172. int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len );
  9173. /**
  9174. * \brief Write the TLS ECParameters record for a group
  9175. *
  9176. * \param grp ECP group used
  9177. * \param olen Number of bytes actually written
  9178. * \param buf Buffer to write to
  9179. * \param blen Buffer length
  9180. *
  9181. * \return 0 if successful,
  9182. * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL
  9183. */
  9184. int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen,
  9185. unsigned char *buf, size_t blen );
  9186. /**
  9187. * \brief Multiplication by an integer: R = m * P
  9188. * (Not thread-safe to use same group in multiple threads)
  9189. *
  9190. * \note In order to prevent timing attacks, this function
  9191. * executes the exact same sequence of (base field)
  9192. * operations for any valid m. It avoids any if-branch or
  9193. * array index depending on the value of m.
  9194. *
  9195. * \note If f_rng is not NULL, it is used to randomize intermediate
  9196. * results in order to prevent potential timing attacks
  9197. * targeting these results. It is recommended to always
  9198. * provide a non-NULL f_rng (the overhead is negligible).
  9199. *
  9200. * \param grp ECP group
  9201. * \param R Destination point
  9202. * \param m Integer by which to multiply
  9203. * \param P Point to multiply
  9204. * \param f_rng RNG function (see notes)
  9205. * \param p_rng RNG parameter
  9206. *
  9207. * \return 0 if successful,
  9208. * MBEDTLS_ERR_ECP_INVALID_KEY if m is not a valid privkey
  9209. * or P is not a valid pubkey,
  9210. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  9211. */
  9212. int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
  9213. const mbedtls_mpi *m, const mbedtls_ecp_point *P,
  9214. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
  9215. /**
  9216. * \brief Multiplication and addition of two points by integers:
  9217. * R = m * P + n * Q
  9218. * (Not thread-safe to use same group in multiple threads)
  9219. *
  9220. * \note In contrast to mbedtls_ecp_mul(), this function does not guarantee
  9221. * a constant execution flow and timing.
  9222. *
  9223. * \param grp ECP group
  9224. * \param R Destination point
  9225. * \param m Integer by which to multiply P
  9226. * \param P Point to multiply by m
  9227. * \param n Integer by which to multiply Q
  9228. * \param Q Point to be multiplied by n
  9229. *
  9230. * \return 0 if successful,
  9231. * MBEDTLS_ERR_ECP_INVALID_KEY if m or n is not a valid privkey
  9232. * or P or Q is not a valid pubkey,
  9233. * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed
  9234. */
  9235. int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
  9236. const mbedtls_mpi *m, const mbedtls_ecp_point *P,
  9237. const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
  9238. /**
  9239. * \brief Check that a point is a valid public key on this curve
  9240. *
  9241. * \param grp Curve/group the point should belong to
  9242. * \param pt Point to check
  9243. *
  9244. * \return 0 if point is a valid public key,
  9245. * MBEDTLS_ERR_ECP_INVALID_KEY otherwise.
  9246. *
  9247. * \note This function only checks the point is non-zero, has valid
  9248. * coordinates and lies on the curve, but not that it is
  9249. * indeed a multiple of G. This is additional check is more
  9250. * expensive, isn't required by standards, and shouldn't be
  9251. * necessary if the group used has a small cofactor. In
  9252. * particular, it is useless for the NIST groups which all
  9253. * have a cofactor of 1.
  9254. *
  9255. * \note Uses bare components rather than an mbedtls_ecp_keypair structure
  9256. * in order to ease use with other structures such as
  9257. * mbedtls_ecdh_context of mbedtls_ecdsa_context.
  9258. */
  9259. int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt );
  9260. /**
  9261. * \brief Check that an mbedtls_mpi is a valid private key for this curve
  9262. *
  9263. * \param grp Group used
  9264. * \param d Integer to check
  9265. *
  9266. * \return 0 if point is a valid private key,
  9267. * MBEDTLS_ERR_ECP_INVALID_KEY otherwise.
  9268. *
  9269. * \note Uses bare components rather than an mbedtls_ecp_keypair structure
  9270. * in order to ease use with other structures such as
  9271. * mbedtls_ecdh_context of mbedtls_ecdsa_context.
  9272. */
  9273. int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, const mbedtls_mpi *d );
  9274. /**
  9275. * \brief Generate a keypair with configurable base point
  9276. *
  9277. * \param grp ECP group
  9278. * \param G Chosen base point
  9279. * \param d Destination MPI (secret part)
  9280. * \param Q Destination point (public part)
  9281. * \param f_rng RNG function
  9282. * \param p_rng RNG parameter
  9283. *
  9284. * \return 0 if successful,
  9285. * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
  9286. *
  9287. * \note Uses bare components rather than an mbedtls_ecp_keypair structure
  9288. * in order to ease use with other structures such as
  9289. * mbedtls_ecdh_context of mbedtls_ecdsa_context.
  9290. */
  9291. int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp,
  9292. const mbedtls_ecp_point *G,
  9293. mbedtls_mpi *d, mbedtls_ecp_point *Q,
  9294. int (*f_rng)(void *, unsigned char *, size_t),
  9295. void *p_rng );
  9296. /**
  9297. * \brief Generate a keypair
  9298. *
  9299. * \param grp ECP group
  9300. * \param d Destination MPI (secret part)
  9301. * \param Q Destination point (public part)
  9302. * \param f_rng RNG function
  9303. * \param p_rng RNG parameter
  9304. *
  9305. * \return 0 if successful,
  9306. * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
  9307. *
  9308. * \note Uses bare components rather than an mbedtls_ecp_keypair structure
  9309. * in order to ease use with other structures such as
  9310. * mbedtls_ecdh_context of mbedtls_ecdsa_context.
  9311. */
  9312. int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
  9313. int (*f_rng)(void *, unsigned char *, size_t),
  9314. void *p_rng );
  9315. /**
  9316. * \brief Generate a keypair
  9317. *
  9318. * \param grp_id ECP group identifier
  9319. * \param key Destination keypair
  9320. * \param f_rng RNG function
  9321. * \param p_rng RNG parameter
  9322. *
  9323. * \return 0 if successful,
  9324. * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code
  9325. */
  9326. int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key,
  9327. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
  9328. /**
  9329. * \brief Check a public-private key pair
  9330. *
  9331. * \param pub Keypair structure holding a public key
  9332. * \param prv Keypair structure holding a private (plus public) key
  9333. *
  9334. * \return 0 if successful (keys are valid and match), or
  9335. * MBEDTLS_ERR_ECP_BAD_INPUT_DATA, or
  9336. * a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX code.
  9337. */
  9338. int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv );
  9339. #if defined(MBEDTLS_SELF_TEST)
  9340. /**
  9341. * \brief Checkup routine
  9342. *
  9343. * \return 0 if successful, or 1 if a test failed
  9344. */
  9345. int mbedtls_ecp_self_test( int verbose );
  9346. #endif /* MBEDTLS_SELF_TEST */
  9347. #ifdef __cplusplus
  9348. }
  9349. #endif
  9350. #else /* MBEDTLS_ECP_ALT */
  9351. #endif /* MBEDTLS_ECP_ALT */
  9352. #endif /* ecp.h */
  9353. /********* Start of file include/mbedtls/ecdsa.h ************/
  9354. /**
  9355. * \file ecdsa.h
  9356. *
  9357. * \brief The Elliptic Curve Digital Signature Algorithm (ECDSA).
  9358. *
  9359. * ECDSA is defined in <em>Standards for Efficient Cryptography Group (SECG):
  9360. * SEC1 Elliptic Curve Cryptography</em>.
  9361. * The use of ECDSA for TLS is defined in <em>RFC-4492: Elliptic Curve
  9362. * Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS)</em>.
  9363. *
  9364. */
  9365. /*
  9366. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  9367. * SPDX-License-Identifier: Apache-2.0
  9368. *
  9369. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  9370. * not use this file except in compliance with the License.
  9371. * You may obtain a copy of the License at
  9372. *
  9373. * http://www.apache.org/licenses/LICENSE-2.0
  9374. *
  9375. * Unless required by applicable law or agreed to in writing, software
  9376. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9377. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9378. * See the License for the specific language governing permissions and
  9379. * limitations under the License.
  9380. *
  9381. * This file is part of Mbed TLS (https://tls.mbed.org)
  9382. */
  9383. #ifndef MBEDTLS_ECDSA_H
  9384. #define MBEDTLS_ECDSA_H
  9385. /*
  9386. * RFC-4492 page 20:
  9387. *
  9388. * Ecdsa-Sig-Value ::= SEQUENCE {
  9389. * r INTEGER,
  9390. * s INTEGER
  9391. * }
  9392. *
  9393. * Size is at most
  9394. * 1 (tag) + 1 (len) + 1 (initial 0) + ECP_MAX_BYTES for each of r and s,
  9395. * twice that + 1 (tag) + 2 (len) for the sequence
  9396. * (assuming ECP_MAX_BYTES is less than 126 for r and s,
  9397. * and less than 124 (total len <= 255) for the sequence)
  9398. */
  9399. #if MBEDTLS_ECP_MAX_BYTES > 124
  9400. #error "MBEDTLS_ECP_MAX_BYTES bigger than expected, please fix MBEDTLS_ECDSA_MAX_LEN"
  9401. #endif
  9402. /** The maximal size of an ECDSA signature in Bytes. */
  9403. #define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) )
  9404. /**
  9405. * \brief The ECDSA context structure.
  9406. */
  9407. typedef mbedtls_ecp_keypair mbedtls_ecdsa_context;
  9408. #ifdef __cplusplus
  9409. extern "C" {
  9410. #endif
  9411. /**
  9412. * \brief This function computes the ECDSA signature of a
  9413. * previously-hashed message.
  9414. *
  9415. * \note The deterministic version is usually preferred.
  9416. *
  9417. * \param grp The ECP group.
  9418. * \param r The first output integer.
  9419. * \param s The second output integer.
  9420. * \param d The private signing key.
  9421. * \param buf The message hash.
  9422. * \param blen The length of \p buf.
  9423. * \param f_rng The RNG function.
  9424. * \param p_rng The RNG parameter.
  9425. *
  9426. * \note If the bitlength of the message hash is larger than the
  9427. * bitlength of the group order, then the hash is truncated
  9428. * as defined in <em>Standards for Efficient Cryptography Group
  9429. * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
  9430. * 4.1.3, step 5.
  9431. *
  9432. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX
  9433. * or \c MBEDTLS_MPI_XXX error code on failure.
  9434. *
  9435. * \see ecp.h
  9436. */
  9437. int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
  9438. const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
  9439. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
  9440. #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
  9441. /**
  9442. * \brief This function computes the ECDSA signature of a
  9443. * previously-hashed message, deterministic version.
  9444. * For more information, see <em>RFC-6979: Deterministic
  9445. * Usage of the Digital Signature Algorithm (DSA) and Elliptic
  9446. * Curve Digital Signature Algorithm (ECDSA)</em>.
  9447. *
  9448. * \param grp The ECP group.
  9449. * \param r The first output integer.
  9450. * \param s The second output integer.
  9451. * \param d The private signing key.
  9452. * \param buf The message hash.
  9453. * \param blen The length of \p buf.
  9454. * \param md_alg The MD algorithm used to hash the message.
  9455. *
  9456. * \note If the bitlength of the message hash is larger than the
  9457. * bitlength of the group order, then the hash is truncated as
  9458. * defined in <em>Standards for Efficient Cryptography Group
  9459. * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
  9460. * 4.1.3, step 5.
  9461. *
  9462. * \return \c 0 on success,
  9463. * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
  9464. * error code on failure.
  9465. *
  9466. * \see ecp.h
  9467. */
  9468. int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s,
  9469. const mbedtls_mpi *d, const unsigned char *buf, size_t blen,
  9470. mbedtls_md_type_t md_alg );
  9471. #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
  9472. /**
  9473. * \brief This function verifies the ECDSA signature of a
  9474. * previously-hashed message.
  9475. *
  9476. * \param grp The ECP group.
  9477. * \param buf The message hash.
  9478. * \param blen The length of \p buf.
  9479. * \param Q The public key to use for verification.
  9480. * \param r The first integer of the signature.
  9481. * \param s The second integer of the signature.
  9482. *
  9483. * \note If the bitlength of the message hash is larger than the
  9484. * bitlength of the group order, then the hash is truncated as
  9485. * defined in <em>Standards for Efficient Cryptography Group
  9486. * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
  9487. * 4.1.4, step 3.
  9488. *
  9489. * \return \c 0 on success,
  9490. * #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid,
  9491. * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX
  9492. * error code on failure for any other reason.
  9493. *
  9494. * \see ecp.h
  9495. */
  9496. int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp,
  9497. const unsigned char *buf, size_t blen,
  9498. const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s);
  9499. /**
  9500. * \brief This function computes the ECDSA signature and writes it
  9501. * to a buffer, serialized as defined in <em>RFC-4492:
  9502. * Elliptic Curve Cryptography (ECC) Cipher Suites for
  9503. * Transport Layer Security (TLS)</em>.
  9504. *
  9505. * \warning It is not thread-safe to use the same context in
  9506. * multiple threads.
  9507. *
  9508. * \note The deterministic version is used if
  9509. * #MBEDTLS_ECDSA_DETERMINISTIC is defined. For more
  9510. * information, see <em>RFC-6979: Deterministic Usage
  9511. * of the Digital Signature Algorithm (DSA) and Elliptic
  9512. * Curve Digital Signature Algorithm (ECDSA)</em>.
  9513. *
  9514. * \param ctx The ECDSA context.
  9515. * \param md_alg The message digest that was used to hash the message.
  9516. * \param hash The message hash.
  9517. * \param hlen The length of the hash.
  9518. * \param sig The buffer that holds the signature.
  9519. * \param slen The length of the signature written.
  9520. * \param f_rng The RNG function.
  9521. * \param p_rng The RNG parameter.
  9522. *
  9523. * \note The \p sig buffer must be at least twice as large as the
  9524. * size of the curve used, plus 9. For example, 73 Bytes if
  9525. * a 256-bit curve is used. A buffer length of
  9526. * #MBEDTLS_ECDSA_MAX_LEN is always safe.
  9527. *
  9528. * \note If the bitlength of the message hash is larger than the
  9529. * bitlength of the group order, then the hash is truncated as
  9530. * defined in <em>Standards for Efficient Cryptography Group
  9531. * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
  9532. * 4.1.3, step 5.
  9533. *
  9534. * \return \c 0 on success,
  9535. * or an \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
  9536. * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
  9537. *
  9538. * \see ecp.h
  9539. */
  9540. int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg,
  9541. const unsigned char *hash, size_t hlen,
  9542. unsigned char *sig, size_t *slen,
  9543. int (*f_rng)(void *, unsigned char *, size_t),
  9544. void *p_rng );
  9545. #if defined(MBEDTLS_ECDSA_DETERMINISTIC)
  9546. #if ! defined(MBEDTLS_DEPRECATED_REMOVED)
  9547. #if defined(MBEDTLS_DEPRECATED_WARNING)
  9548. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  9549. #else
  9550. #define MBEDTLS_DEPRECATED
  9551. #endif
  9552. /**
  9553. * \brief This function computes an ECDSA signature and writes it to a buffer,
  9554. * serialized as defined in <em>RFC-4492: Elliptic Curve Cryptography
  9555. * (ECC) Cipher Suites for Transport Layer Security (TLS)</em>.
  9556. *
  9557. * The deterministic version is defined in <em>RFC-6979:
  9558. * Deterministic Usage of the Digital Signature Algorithm (DSA) and
  9559. * Elliptic Curve Digital Signature Algorithm (ECDSA)</em>.
  9560. *
  9561. * \warning It is not thread-safe to use the same context in
  9562. * multiple threads.
  9563. *
  9564. * \deprecated Superseded by mbedtls_ecdsa_write_signature() in 2.0.0
  9565. *
  9566. * \param ctx The ECDSA context.
  9567. * \param hash The Message hash.
  9568. * \param hlen The length of the hash.
  9569. * \param sig The buffer that holds the signature.
  9570. * \param slen The length of the signature written.
  9571. * \param md_alg The MD algorithm used to hash the message.
  9572. *
  9573. * \note The \p sig buffer must be at least twice as large as the
  9574. * size of the curve used, plus 9. For example, 73 Bytes if a
  9575. * 256-bit curve is used. A buffer length of
  9576. * #MBEDTLS_ECDSA_MAX_LEN is always safe.
  9577. *
  9578. * \note If the bitlength of the message hash is larger than the
  9579. * bitlength of the group order, then the hash is truncated as
  9580. * defined in <em>Standards for Efficient Cryptography Group
  9581. * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
  9582. * 4.1.3, step 5.
  9583. *
  9584. * \return \c 0 on success,
  9585. * or an \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or
  9586. * \c MBEDTLS_ERR_ASN1_XXX error code on failure.
  9587. *
  9588. * \see ecp.h
  9589. */
  9590. int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx,
  9591. const unsigned char *hash, size_t hlen,
  9592. unsigned char *sig, size_t *slen,
  9593. mbedtls_md_type_t md_alg ) MBEDTLS_DEPRECATED;
  9594. #undef MBEDTLS_DEPRECATED
  9595. #endif /* MBEDTLS_DEPRECATED_REMOVED */
  9596. #endif /* MBEDTLS_ECDSA_DETERMINISTIC */
  9597. /**
  9598. * \brief This function reads and verifies an ECDSA signature.
  9599. *
  9600. * \param ctx The ECDSA context.
  9601. * \param hash The message hash.
  9602. * \param hlen The size of the hash.
  9603. * \param sig The signature to read and verify.
  9604. * \param slen The size of \p sig.
  9605. *
  9606. * \note If the bitlength of the message hash is larger than the
  9607. * bitlength of the group order, then the hash is truncated as
  9608. * defined in <em>Standards for Efficient Cryptography Group
  9609. * (SECG): SEC1 Elliptic Curve Cryptography</em>, section
  9610. * 4.1.4, step 3.
  9611. *
  9612. * \return \c 0 on success,
  9613. * #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid,
  9614. * #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if the signature is
  9615. * valid but its actual length is less than \p siglen,
  9616. * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX
  9617. * error code on failure for any other reason.
  9618. *
  9619. * \see ecp.h
  9620. */
  9621. int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx,
  9622. const unsigned char *hash, size_t hlen,
  9623. const unsigned char *sig, size_t slen );
  9624. /**
  9625. * \brief This function generates an ECDSA keypair on the given curve.
  9626. *
  9627. * \param ctx The ECDSA context to store the keypair in.
  9628. * \param gid The elliptic curve to use. One of the various
  9629. * \c MBEDTLS_ECP_DP_XXX macros depending on configuration.
  9630. * \param f_rng The RNG function.
  9631. * \param p_rng The RNG parameter.
  9632. *
  9633. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX code on
  9634. * failure.
  9635. *
  9636. * \see ecp.h
  9637. */
  9638. int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid,
  9639. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
  9640. /**
  9641. * \brief This function sets an ECDSA context from an EC key pair.
  9642. *
  9643. * \param ctx The ECDSA context to set.
  9644. * \param key The EC key to use.
  9645. *
  9646. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX code on
  9647. * failure.
  9648. *
  9649. * \see ecp.h
  9650. */
  9651. int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key );
  9652. /**
  9653. * \brief This function initializes an ECDSA context.
  9654. *
  9655. * \param ctx The ECDSA context to initialize.
  9656. */
  9657. void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx );
  9658. /**
  9659. * \brief This function frees an ECDSA context.
  9660. *
  9661. * \param ctx The ECDSA context to free.
  9662. */
  9663. void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx );
  9664. #ifdef __cplusplus
  9665. }
  9666. #endif
  9667. #endif /* ecdsa.h */
  9668. /********* Start of file include/mbedtls/ecjpake.h ************/
  9669. /**
  9670. * \file ecjpake.h
  9671. *
  9672. * \brief Elliptic curve J-PAKE
  9673. */
  9674. /*
  9675. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  9676. * SPDX-License-Identifier: Apache-2.0
  9677. *
  9678. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  9679. * not use this file except in compliance with the License.
  9680. * You may obtain a copy of the License at
  9681. *
  9682. * http://www.apache.org/licenses/LICENSE-2.0
  9683. *
  9684. * Unless required by applicable law or agreed to in writing, software
  9685. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9686. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9687. * See the License for the specific language governing permissions and
  9688. * limitations under the License.
  9689. *
  9690. * This file is part of mbed TLS (https://tls.mbed.org)
  9691. */
  9692. #ifndef MBEDTLS_ECJPAKE_H
  9693. #define MBEDTLS_ECJPAKE_H
  9694. /*
  9695. * J-PAKE is a password-authenticated key exchange that allows deriving a
  9696. * strong shared secret from a (potentially low entropy) pre-shared
  9697. * passphrase, with forward secrecy and mutual authentication.
  9698. * https://en.wikipedia.org/wiki/Password_Authenticated_Key_Exchange_by_Juggling
  9699. *
  9700. * This file implements the Elliptic Curve variant of J-PAKE,
  9701. * as defined in Chapter 7.4 of the Thread v1.0 Specification,
  9702. * available to members of the Thread Group http://threadgroup.org/
  9703. *
  9704. * As the J-PAKE algorithm is inherently symmetric, so is our API.
  9705. * Each party needs to send its first round message, in any order, to the
  9706. * other party, then each sends its second round message, in any order.
  9707. * The payloads are serialized in a way suitable for use in TLS, but could
  9708. * also be use outside TLS.
  9709. */
  9710. #if !defined(MBEDTLS_ECJPAKE_ALT)
  9711. #ifdef __cplusplus
  9712. extern "C" {
  9713. #endif
  9714. /**
  9715. * Roles in the EC J-PAKE exchange
  9716. */
  9717. typedef enum {
  9718. MBEDTLS_ECJPAKE_CLIENT = 0, /**< Client */
  9719. MBEDTLS_ECJPAKE_SERVER, /**< Server */
  9720. } mbedtls_ecjpake_role;
  9721. /**
  9722. * EC J-PAKE context structure.
  9723. *
  9724. * J-PAKE is a symmetric protocol, except for the identifiers used in
  9725. * Zero-Knowledge Proofs, and the serialization of the second message
  9726. * (KeyExchange) as defined by the Thread spec.
  9727. *
  9728. * In order to benefit from this symmetry, we choose a different naming
  9729. * convetion from the Thread v1.0 spec. Correspondance is indicated in the
  9730. * description as a pair C: client name, S: server name
  9731. */
  9732. typedef struct
  9733. {
  9734. const mbedtls_md_info_t *md_info; /**< Hash to use */
  9735. mbedtls_ecp_group grp; /**< Elliptic curve */
  9736. mbedtls_ecjpake_role role; /**< Are we client or server? */
  9737. int point_format; /**< Format for point export */
  9738. mbedtls_ecp_point Xm1; /**< My public key 1 C: X1, S: X3 */
  9739. mbedtls_ecp_point Xm2; /**< My public key 2 C: X2, S: X4 */
  9740. mbedtls_ecp_point Xp1; /**< Peer public key 1 C: X3, S: X1 */
  9741. mbedtls_ecp_point Xp2; /**< Peer public key 2 C: X4, S: X2 */
  9742. mbedtls_ecp_point Xp; /**< Peer public key C: Xs, S: Xc */
  9743. mbedtls_mpi xm1; /**< My private key 1 C: x1, S: x3 */
  9744. mbedtls_mpi xm2; /**< My private key 2 C: x2, S: x4 */
  9745. mbedtls_mpi s; /**< Pre-shared secret (passphrase) */
  9746. } mbedtls_ecjpake_context;
  9747. /**
  9748. * \brief Initialize a context
  9749. * (just makes it ready for setup() or free()).
  9750. *
  9751. * \param ctx context to initialize
  9752. */
  9753. void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx );
  9754. /**
  9755. * \brief Set up a context for use
  9756. *
  9757. * \note Currently the only values for hash/curve allowed by the
  9758. * standard are MBEDTLS_MD_SHA256/MBEDTLS_ECP_DP_SECP256R1.
  9759. *
  9760. * \param ctx context to set up
  9761. * \param role Our role: client or server
  9762. * \param hash hash function to use (MBEDTLS_MD_XXX)
  9763. * \param curve elliptic curve identifier (MBEDTLS_ECP_DP_XXX)
  9764. * \param secret pre-shared secret (passphrase)
  9765. * \param len length of the shared secret
  9766. *
  9767. * \return 0 if successfull,
  9768. * a negative error code otherwise
  9769. */
  9770. int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
  9771. mbedtls_ecjpake_role role,
  9772. mbedtls_md_type_t hash,
  9773. mbedtls_ecp_group_id curve,
  9774. const unsigned char *secret,
  9775. size_t len );
  9776. /**
  9777. * \brief Check if a context is ready for use
  9778. *
  9779. * \param ctx Context to check
  9780. *
  9781. * \return 0 if the context is ready for use,
  9782. * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise
  9783. */
  9784. int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx );
  9785. /**
  9786. * \brief Generate and write the first round message
  9787. * (TLS: contents of the Client/ServerHello extension,
  9788. * excluding extension type and length bytes)
  9789. *
  9790. * \param ctx Context to use
  9791. * \param buf Buffer to write the contents to
  9792. * \param len Buffer size
  9793. * \param olen Will be updated with the number of bytes written
  9794. * \param f_rng RNG function
  9795. * \param p_rng RNG parameter
  9796. *
  9797. * \return 0 if successfull,
  9798. * a negative error code otherwise
  9799. */
  9800. int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx,
  9801. unsigned char *buf, size_t len, size_t *olen,
  9802. int (*f_rng)(void *, unsigned char *, size_t),
  9803. void *p_rng );
  9804. /**
  9805. * \brief Read and process the first round message
  9806. * (TLS: contents of the Client/ServerHello extension,
  9807. * excluding extension type and length bytes)
  9808. *
  9809. * \param ctx Context to use
  9810. * \param buf Pointer to extension contents
  9811. * \param len Extension length
  9812. *
  9813. * \return 0 if successfull,
  9814. * a negative error code otherwise
  9815. */
  9816. int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx,
  9817. const unsigned char *buf,
  9818. size_t len );
  9819. /**
  9820. * \brief Generate and write the second round message
  9821. * (TLS: contents of the Client/ServerKeyExchange)
  9822. *
  9823. * \param ctx Context to use
  9824. * \param buf Buffer to write the contents to
  9825. * \param len Buffer size
  9826. * \param olen Will be updated with the number of bytes written
  9827. * \param f_rng RNG function
  9828. * \param p_rng RNG parameter
  9829. *
  9830. * \return 0 if successfull,
  9831. * a negative error code otherwise
  9832. */
  9833. int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx,
  9834. unsigned char *buf, size_t len, size_t *olen,
  9835. int (*f_rng)(void *, unsigned char *, size_t),
  9836. void *p_rng );
  9837. /**
  9838. * \brief Read and process the second round message
  9839. * (TLS: contents of the Client/ServerKeyExchange)
  9840. *
  9841. * \param ctx Context to use
  9842. * \param buf Pointer to the message
  9843. * \param len Message length
  9844. *
  9845. * \return 0 if successfull,
  9846. * a negative error code otherwise
  9847. */
  9848. int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx,
  9849. const unsigned char *buf,
  9850. size_t len );
  9851. /**
  9852. * \brief Derive the shared secret
  9853. * (TLS: Pre-Master Secret)
  9854. *
  9855. * \param ctx Context to use
  9856. * \param buf Buffer to write the contents to
  9857. * \param len Buffer size
  9858. * \param olen Will be updated with the number of bytes written
  9859. * \param f_rng RNG function
  9860. * \param p_rng RNG parameter
  9861. *
  9862. * \return 0 if successfull,
  9863. * a negative error code otherwise
  9864. */
  9865. int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx,
  9866. unsigned char *buf, size_t len, size_t *olen,
  9867. int (*f_rng)(void *, unsigned char *, size_t),
  9868. void *p_rng );
  9869. /**
  9870. * \brief Free a context's content
  9871. *
  9872. * \param ctx context to free
  9873. */
  9874. void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
  9875. #ifdef __cplusplus
  9876. }
  9877. #endif
  9878. #else /* MBEDTLS_ECJPAKE_ALT */
  9879. #endif /* MBEDTLS_ECJPAKE_ALT */
  9880. #if defined(MBEDTLS_SELF_TEST)
  9881. #ifdef __cplusplus
  9882. extern "C" {
  9883. #endif
  9884. /**
  9885. * \brief Checkup routine
  9886. *
  9887. * \return 0 if successful, or 1 if a test failed
  9888. */
  9889. int mbedtls_ecjpake_self_test( int verbose );
  9890. #ifdef __cplusplus
  9891. }
  9892. #endif
  9893. #endif /* MBEDTLS_SELF_TEST */
  9894. #endif /* ecjpake.h */
  9895. /********* Start of file include/mbedtls/pk.h ************/
  9896. /**
  9897. * \file pk.h
  9898. *
  9899. * \brief Public Key abstraction layer
  9900. */
  9901. /*
  9902. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  9903. * SPDX-License-Identifier: Apache-2.0
  9904. *
  9905. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  9906. * not use this file except in compliance with the License.
  9907. * You may obtain a copy of the License at
  9908. *
  9909. * http://www.apache.org/licenses/LICENSE-2.0
  9910. *
  9911. * Unless required by applicable law or agreed to in writing, software
  9912. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9913. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9914. * See the License for the specific language governing permissions and
  9915. * limitations under the License.
  9916. *
  9917. * This file is part of mbed TLS (https://tls.mbed.org)
  9918. */
  9919. #ifndef MBEDTLS_PK_H
  9920. #define MBEDTLS_PK_H
  9921. #if !defined(MBEDTLS_CONFIG_FILE)
  9922. #else
  9923. #endif
  9924. #if defined(MBEDTLS_RSA_C)
  9925. #endif
  9926. #if defined(MBEDTLS_ECP_C)
  9927. #endif
  9928. #if defined(MBEDTLS_ECDSA_C)
  9929. #endif
  9930. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  9931. !defined(inline) && !defined(__cplusplus)
  9932. #define inline __inline
  9933. #endif
  9934. #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80 /**< Memory allocation failed. */
  9935. #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00 /**< Type mismatch, eg attempt to encrypt with an ECDSA key */
  9936. #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80 /**< Bad input parameters to function. */
  9937. #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00 /**< Read/write of file failed. */
  9938. #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80 /**< Unsupported key version */
  9939. #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00 /**< Invalid key tag or value. */
  9940. #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80 /**< Key algorithm is unsupported (only RSA and EC are supported). */
  9941. #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00 /**< Private key password can't be empty. */
  9942. #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80 /**< Given private key password does not allow for correct decryption. */
  9943. #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */
  9944. #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80 /**< The algorithm tag or value is invalid. */
  9945. #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */
  9946. #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980 /**< Unavailable feature, e.g. RSA disabled for RSA key. */
  9947. #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900 /**< The signature is valid but its length is less than expected. */
  9948. #define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880 /**< PK hardware accelerator failed. */
  9949. #ifdef __cplusplus
  9950. extern "C" {
  9951. #endif
  9952. /**
  9953. * \brief Public key types
  9954. */
  9955. typedef enum {
  9956. MBEDTLS_PK_NONE=0,
  9957. MBEDTLS_PK_RSA,
  9958. MBEDTLS_PK_ECKEY,
  9959. MBEDTLS_PK_ECKEY_DH,
  9960. MBEDTLS_PK_ECDSA,
  9961. MBEDTLS_PK_RSA_ALT,
  9962. MBEDTLS_PK_RSASSA_PSS,
  9963. } mbedtls_pk_type_t;
  9964. /**
  9965. * \brief Options for RSASSA-PSS signature verification.
  9966. * See \c mbedtls_rsa_rsassa_pss_verify_ext()
  9967. */
  9968. typedef struct
  9969. {
  9970. mbedtls_md_type_t mgf1_hash_id;
  9971. int expected_salt_len;
  9972. } mbedtls_pk_rsassa_pss_options;
  9973. /**
  9974. * \brief Types for interfacing with the debug module
  9975. */
  9976. typedef enum
  9977. {
  9978. MBEDTLS_PK_DEBUG_NONE = 0,
  9979. MBEDTLS_PK_DEBUG_MPI,
  9980. MBEDTLS_PK_DEBUG_ECP,
  9981. } mbedtls_pk_debug_type;
  9982. /**
  9983. * \brief Item to send to the debug module
  9984. */
  9985. typedef struct
  9986. {
  9987. mbedtls_pk_debug_type type;
  9988. const char *name;
  9989. void *value;
  9990. } mbedtls_pk_debug_item;
  9991. /** Maximum number of item send for debugging, plus 1 */
  9992. #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
  9993. /**
  9994. * \brief Public key information and operations
  9995. */
  9996. typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;
  9997. /**
  9998. * \brief Public key container
  9999. */
  10000. typedef struct
  10001. {
  10002. const mbedtls_pk_info_t * pk_info; /**< Public key informations */
  10003. void * pk_ctx; /**< Underlying public key context */
  10004. } mbedtls_pk_context;
  10005. #if defined(MBEDTLS_RSA_C)
  10006. /**
  10007. * Quick access to an RSA context inside a PK context.
  10008. *
  10009. * \warning You must make sure the PK context actually holds an RSA context
  10010. * before using this function!
  10011. */
  10012. static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
  10013. {
  10014. return( (mbedtls_rsa_context *) (pk).pk_ctx );
  10015. }
  10016. #endif /* MBEDTLS_RSA_C */
  10017. #if defined(MBEDTLS_ECP_C)
  10018. /**
  10019. * Quick access to an EC context inside a PK context.
  10020. *
  10021. * \warning You must make sure the PK context actually holds an EC context
  10022. * before using this function!
  10023. */
  10024. static inline mbedtls_ecp_keypair *mbedtls_pk_ec( const mbedtls_pk_context pk )
  10025. {
  10026. return( (mbedtls_ecp_keypair *) (pk).pk_ctx );
  10027. }
  10028. #endif /* MBEDTLS_ECP_C */
  10029. #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
  10030. /**
  10031. * \brief Types for RSA-alt abstraction
  10032. */
  10033. typedef int (*mbedtls_pk_rsa_alt_decrypt_func)( void *ctx, int mode, size_t *olen,
  10034. const unsigned char *input, unsigned char *output,
  10035. size_t output_max_len );
  10036. typedef int (*mbedtls_pk_rsa_alt_sign_func)( void *ctx,
  10037. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
  10038. int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
  10039. const unsigned char *hash, unsigned char *sig );
  10040. typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)( void *ctx );
  10041. #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
  10042. /**
  10043. * \brief Return information associated with the given PK type
  10044. *
  10045. * \param pk_type PK type to search for.
  10046. *
  10047. * \return The PK info associated with the type or NULL if not found.
  10048. */
  10049. const mbedtls_pk_info_t *mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type );
  10050. /**
  10051. * \brief Initialize a mbedtls_pk_context (as NONE)
  10052. */
  10053. void mbedtls_pk_init( mbedtls_pk_context *ctx );
  10054. /**
  10055. * \brief Free a mbedtls_pk_context
  10056. */
  10057. void mbedtls_pk_free( mbedtls_pk_context *ctx );
  10058. /**
  10059. * \brief Initialize a PK context with the information given
  10060. * and allocates the type-specific PK subcontext.
  10061. *
  10062. * \param ctx Context to initialize. Must be empty (type NONE).
  10063. * \param info Information to use
  10064. *
  10065. * \return 0 on success,
  10066. * MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input,
  10067. * MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
  10068. *
  10069. * \note For contexts holding an RSA-alt key, use
  10070. * \c mbedtls_pk_setup_rsa_alt() instead.
  10071. */
  10072. int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info );
  10073. #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
  10074. /**
  10075. * \brief Initialize an RSA-alt context
  10076. *
  10077. * \param ctx Context to initialize. Must be empty (type NONE).
  10078. * \param key RSA key pointer
  10079. * \param decrypt_func Decryption function
  10080. * \param sign_func Signing function
  10081. * \param key_len_func Function returning key length in bytes
  10082. *
  10083. * \return 0 on success, or MBEDTLS_ERR_PK_BAD_INPUT_DATA if the
  10084. * context wasn't already initialized as RSA_ALT.
  10085. *
  10086. * \note This function replaces \c mbedtls_pk_setup() for RSA-alt.
  10087. */
  10088. int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key,
  10089. mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
  10090. mbedtls_pk_rsa_alt_sign_func sign_func,
  10091. mbedtls_pk_rsa_alt_key_len_func key_len_func );
  10092. #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
  10093. /**
  10094. * \brief Get the size in bits of the underlying key
  10095. *
  10096. * \param ctx Context to use
  10097. *
  10098. * \return Key size in bits, or 0 on error
  10099. */
  10100. size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx );
  10101. /**
  10102. * \brief Get the length in bytes of the underlying key
  10103. * \param ctx Context to use
  10104. *
  10105. * \return Key length in bytes, or 0 on error
  10106. */
  10107. static inline size_t mbedtls_pk_get_len( const mbedtls_pk_context *ctx )
  10108. {
  10109. return( ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 );
  10110. }
  10111. /**
  10112. * \brief Tell if a context can do the operation given by type
  10113. *
  10114. * \param ctx Context to test
  10115. * \param type Target type
  10116. *
  10117. * \return 0 if context can't do the operations,
  10118. * 1 otherwise.
  10119. */
  10120. int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type );
  10121. /**
  10122. * \brief Verify signature (including padding if relevant).
  10123. *
  10124. * \param ctx PK context to use
  10125. * \param md_alg Hash algorithm used (see notes)
  10126. * \param hash Hash of the message to sign
  10127. * \param hash_len Hash length or 0 (see notes)
  10128. * \param sig Signature to verify
  10129. * \param sig_len Signature length
  10130. *
  10131. * \return 0 on success (signature is valid),
  10132. * MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if the signature is
  10133. * valid but its actual length is less than sig_len,
  10134. * or a specific error code.
  10135. *
  10136. * \note For RSA keys, the default padding type is PKCS#1 v1.5.
  10137. * Use \c mbedtls_pk_verify_ext( MBEDTLS_PK_RSASSA_PSS, ... )
  10138. * to verify RSASSA_PSS signatures.
  10139. *
  10140. * \note If hash_len is 0, then the length associated with md_alg
  10141. * is used instead, or an error returned if it is invalid.
  10142. *
  10143. * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
  10144. */
  10145. int mbedtls_pk_verify( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
  10146. const unsigned char *hash, size_t hash_len,
  10147. const unsigned char *sig, size_t sig_len );
  10148. /**
  10149. * \brief Verify signature, with options.
  10150. * (Includes verification of the padding depending on type.)
  10151. *
  10152. * \param type Signature type (inc. possible padding type) to verify
  10153. * \param options Pointer to type-specific options, or NULL
  10154. * \param ctx PK context to use
  10155. * \param md_alg Hash algorithm used (see notes)
  10156. * \param hash Hash of the message to sign
  10157. * \param hash_len Hash length or 0 (see notes)
  10158. * \param sig Signature to verify
  10159. * \param sig_len Signature length
  10160. *
  10161. * \return 0 on success (signature is valid),
  10162. * MBEDTLS_ERR_PK_TYPE_MISMATCH if the PK context can't be
  10163. * used for this type of signatures,
  10164. * MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if the signature is
  10165. * valid but its actual length is less than sig_len,
  10166. * or a specific error code.
  10167. *
  10168. * \note If hash_len is 0, then the length associated with md_alg
  10169. * is used instead, or an error returned if it is invalid.
  10170. *
  10171. * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
  10172. *
  10173. * \note If type is MBEDTLS_PK_RSASSA_PSS, then options must point
  10174. * to a mbedtls_pk_rsassa_pss_options structure,
  10175. * otherwise it must be NULL.
  10176. */
  10177. int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
  10178. mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
  10179. const unsigned char *hash, size_t hash_len,
  10180. const unsigned char *sig, size_t sig_len );
  10181. /**
  10182. * \brief Make signature, including padding if relevant.
  10183. *
  10184. * \param ctx PK context to use - must hold a private key
  10185. * \param md_alg Hash algorithm used (see notes)
  10186. * \param hash Hash of the message to sign
  10187. * \param hash_len Hash length or 0 (see notes)
  10188. * \param sig Place to write the signature
  10189. * \param sig_len Number of bytes written
  10190. * \param f_rng RNG function
  10191. * \param p_rng RNG parameter
  10192. *
  10193. * \return 0 on success, or a specific error code.
  10194. *
  10195. * \note For RSA keys, the default padding type is PKCS#1 v1.5.
  10196. * There is no interface in the PK module to make RSASSA-PSS
  10197. * signatures yet.
  10198. *
  10199. * \note If hash_len is 0, then the length associated with md_alg
  10200. * is used instead, or an error returned if it is invalid.
  10201. *
  10202. * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0.
  10203. * For ECDSA, md_alg may never be MBEDTLS_MD_NONE.
  10204. */
  10205. int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
  10206. const unsigned char *hash, size_t hash_len,
  10207. unsigned char *sig, size_t *sig_len,
  10208. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
  10209. /**
  10210. * \brief Decrypt message (including padding if relevant).
  10211. *
  10212. * \param ctx PK context to use - must hold a private key
  10213. * \param input Input to decrypt
  10214. * \param ilen Input size
  10215. * \param output Decrypted output
  10216. * \param olen Decrypted message length
  10217. * \param osize Size of the output buffer
  10218. * \param f_rng RNG function
  10219. * \param p_rng RNG parameter
  10220. *
  10221. * \note For RSA keys, the default padding type is PKCS#1 v1.5.
  10222. *
  10223. * \return 0 on success, or a specific error code.
  10224. */
  10225. int mbedtls_pk_decrypt( mbedtls_pk_context *ctx,
  10226. const unsigned char *input, size_t ilen,
  10227. unsigned char *output, size_t *olen, size_t osize,
  10228. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
  10229. /**
  10230. * \brief Encrypt message (including padding if relevant).
  10231. *
  10232. * \param ctx PK context to use
  10233. * \param input Message to encrypt
  10234. * \param ilen Message size
  10235. * \param output Encrypted output
  10236. * \param olen Encrypted output length
  10237. * \param osize Size of the output buffer
  10238. * \param f_rng RNG function
  10239. * \param p_rng RNG parameter
  10240. *
  10241. * \note For RSA keys, the default padding type is PKCS#1 v1.5.
  10242. *
  10243. * \return 0 on success, or a specific error code.
  10244. */
  10245. int mbedtls_pk_encrypt( mbedtls_pk_context *ctx,
  10246. const unsigned char *input, size_t ilen,
  10247. unsigned char *output, size_t *olen, size_t osize,
  10248. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
  10249. /**
  10250. * \brief Check if a public-private pair of keys matches.
  10251. *
  10252. * \param pub Context holding a public key.
  10253. * \param prv Context holding a private (and public) key.
  10254. *
  10255. * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
  10256. */
  10257. int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_context *prv );
  10258. /**
  10259. * \brief Export debug information
  10260. *
  10261. * \param ctx Context to use
  10262. * \param items Place to write debug items
  10263. *
  10264. * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
  10265. */
  10266. int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items );
  10267. /**
  10268. * \brief Access the type name
  10269. *
  10270. * \param ctx Context to use
  10271. *
  10272. * \return Type name on success, or "invalid PK"
  10273. */
  10274. const char * mbedtls_pk_get_name( const mbedtls_pk_context *ctx );
  10275. /**
  10276. * \brief Get the key type
  10277. *
  10278. * \param ctx Context to use
  10279. *
  10280. * \return Type on success, or MBEDTLS_PK_NONE
  10281. */
  10282. mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx );
  10283. #if defined(MBEDTLS_PK_PARSE_C)
  10284. /** \ingroup pk_module */
  10285. /**
  10286. * \brief Parse a private key in PEM or DER format
  10287. *
  10288. * \param ctx key to be initialized
  10289. * \param key input buffer
  10290. * \param keylen size of the buffer
  10291. * (including the terminating null byte for PEM data)
  10292. * \param pwd password for decryption (optional)
  10293. * \param pwdlen size of the password
  10294. *
  10295. * \note On entry, ctx must be empty, either freshly initialised
  10296. * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
  10297. * specific key type, check the result with mbedtls_pk_can_do().
  10298. *
  10299. * \note The key is also checked for correctness.
  10300. *
  10301. * \return 0 if successful, or a specific PK or PEM error code
  10302. */
  10303. int mbedtls_pk_parse_key( mbedtls_pk_context *ctx,
  10304. const unsigned char *key, size_t keylen,
  10305. const unsigned char *pwd, size_t pwdlen );
  10306. /** \ingroup pk_module */
  10307. /**
  10308. * \brief Parse a public key in PEM or DER format
  10309. *
  10310. * \param ctx key to be initialized
  10311. * \param key input buffer
  10312. * \param keylen size of the buffer
  10313. * (including the terminating null byte for PEM data)
  10314. *
  10315. * \note On entry, ctx must be empty, either freshly initialised
  10316. * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
  10317. * specific key type, check the result with mbedtls_pk_can_do().
  10318. *
  10319. * \note The key is also checked for correctness.
  10320. *
  10321. * \return 0 if successful, or a specific PK or PEM error code
  10322. */
  10323. int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx,
  10324. const unsigned char *key, size_t keylen );
  10325. #if defined(MBEDTLS_FS_IO)
  10326. /** \ingroup pk_module */
  10327. /**
  10328. * \brief Load and parse a private key
  10329. *
  10330. * \param ctx key to be initialized
  10331. * \param path filename to read the private key from
  10332. * \param password password to decrypt the file (can be NULL)
  10333. *
  10334. * \note On entry, ctx must be empty, either freshly initialised
  10335. * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
  10336. * specific key type, check the result with mbedtls_pk_can_do().
  10337. *
  10338. * \note The key is also checked for correctness.
  10339. *
  10340. * \return 0 if successful, or a specific PK or PEM error code
  10341. */
  10342. int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx,
  10343. const char *path, const char *password );
  10344. /** \ingroup pk_module */
  10345. /**
  10346. * \brief Load and parse a public key
  10347. *
  10348. * \param ctx key to be initialized
  10349. * \param path filename to read the public key from
  10350. *
  10351. * \note On entry, ctx must be empty, either freshly initialised
  10352. * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If
  10353. * you need a specific key type, check the result with
  10354. * mbedtls_pk_can_do().
  10355. *
  10356. * \note The key is also checked for correctness.
  10357. *
  10358. * \return 0 if successful, or a specific PK or PEM error code
  10359. */
  10360. int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path );
  10361. #endif /* MBEDTLS_FS_IO */
  10362. #endif /* MBEDTLS_PK_PARSE_C */
  10363. #if defined(MBEDTLS_PK_WRITE_C)
  10364. /**
  10365. * \brief Write a private key to a PKCS#1 or SEC1 DER structure
  10366. * Note: data is written at the end of the buffer! Use the
  10367. * return value to determine where you should start
  10368. * using the buffer
  10369. *
  10370. * \param ctx private to write away
  10371. * \param buf buffer to write to
  10372. * \param size size of the buffer
  10373. *
  10374. * \return length of data written if successful, or a specific
  10375. * error code
  10376. */
  10377. int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
  10378. /**
  10379. * \brief Write a public key to a SubjectPublicKeyInfo DER structure
  10380. * Note: data is written at the end of the buffer! Use the
  10381. * return value to determine where you should start
  10382. * using the buffer
  10383. *
  10384. * \param ctx public key to write away
  10385. * \param buf buffer to write to
  10386. * \param size size of the buffer
  10387. *
  10388. * \return length of data written if successful, or a specific
  10389. * error code
  10390. */
  10391. int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
  10392. #if defined(MBEDTLS_PEM_WRITE_C)
  10393. /**
  10394. * \brief Write a public key to a PEM string
  10395. *
  10396. * \param ctx public key to write away
  10397. * \param buf buffer to write to
  10398. * \param size size of the buffer
  10399. *
  10400. * \return 0 if successful, or a specific error code
  10401. */
  10402. int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
  10403. /**
  10404. * \brief Write a private key to a PKCS#1 or SEC1 PEM string
  10405. *
  10406. * \param ctx private to write away
  10407. * \param buf buffer to write to
  10408. * \param size size of the buffer
  10409. *
  10410. * \return 0 if successful, or a specific error code
  10411. */
  10412. int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_t size );
  10413. #endif /* MBEDTLS_PEM_WRITE_C */
  10414. #endif /* MBEDTLS_PK_WRITE_C */
  10415. /*
  10416. * WARNING: Low-level functions. You probably do not want to use these unless
  10417. * you are certain you do ;)
  10418. */
  10419. #if defined(MBEDTLS_PK_PARSE_C)
  10420. /**
  10421. * \brief Parse a SubjectPublicKeyInfo DER structure
  10422. *
  10423. * \param p the position in the ASN.1 data
  10424. * \param end end of the buffer
  10425. * \param pk the key to fill
  10426. *
  10427. * \return 0 if successful, or a specific PK error code
  10428. */
  10429. int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
  10430. mbedtls_pk_context *pk );
  10431. #endif /* MBEDTLS_PK_PARSE_C */
  10432. #if defined(MBEDTLS_PK_WRITE_C)
  10433. /**
  10434. * \brief Write a subjectPublicKey to ASN.1 data
  10435. * Note: function works backwards in data buffer
  10436. *
  10437. * \param p reference to current position pointer
  10438. * \param start start of the buffer (for bounds-checking)
  10439. * \param key public key to write away
  10440. *
  10441. * \return the length written or a negative error code
  10442. */
  10443. int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start,
  10444. const mbedtls_pk_context *key );
  10445. #endif /* MBEDTLS_PK_WRITE_C */
  10446. /*
  10447. * Internal module functions. You probably do not want to use these unless you
  10448. * know you do.
  10449. */
  10450. #if defined(MBEDTLS_FS_IO)
  10451. int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n );
  10452. #endif
  10453. #ifdef __cplusplus
  10454. }
  10455. #endif
  10456. #endif /* MBEDTLS_PK_H */
  10457. /********* Start of file include/mbedtls/pk_internal.h ************/
  10458. /**
  10459. * \file pk_internal.h
  10460. *
  10461. * \brief Public Key abstraction layer: wrapper functions
  10462. */
  10463. /*
  10464. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  10465. * SPDX-License-Identifier: Apache-2.0
  10466. *
  10467. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  10468. * not use this file except in compliance with the License.
  10469. * You may obtain a copy of the License at
  10470. *
  10471. * http://www.apache.org/licenses/LICENSE-2.0
  10472. *
  10473. * Unless required by applicable law or agreed to in writing, software
  10474. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  10475. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10476. * See the License for the specific language governing permissions and
  10477. * limitations under the License.
  10478. *
  10479. * This file is part of mbed TLS (https://tls.mbed.org)
  10480. */
  10481. #ifndef MBEDTLS_PK_WRAP_H
  10482. #define MBEDTLS_PK_WRAP_H
  10483. #if !defined(MBEDTLS_CONFIG_FILE)
  10484. #else
  10485. #endif
  10486. struct mbedtls_pk_info_t
  10487. {
  10488. /** Public key type */
  10489. mbedtls_pk_type_t type;
  10490. /** Type name */
  10491. const char *name;
  10492. /** Get key size in bits */
  10493. size_t (*get_bitlen)( const void * );
  10494. /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */
  10495. int (*can_do)( mbedtls_pk_type_t type );
  10496. /** Verify signature */
  10497. int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg,
  10498. const unsigned char *hash, size_t hash_len,
  10499. const unsigned char *sig, size_t sig_len );
  10500. /** Make signature */
  10501. int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg,
  10502. const unsigned char *hash, size_t hash_len,
  10503. unsigned char *sig, size_t *sig_len,
  10504. int (*f_rng)(void *, unsigned char *, size_t),
  10505. void *p_rng );
  10506. /** Decrypt message */
  10507. int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
  10508. unsigned char *output, size_t *olen, size_t osize,
  10509. int (*f_rng)(void *, unsigned char *, size_t),
  10510. void *p_rng );
  10511. /** Encrypt message */
  10512. int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen,
  10513. unsigned char *output, size_t *olen, size_t osize,
  10514. int (*f_rng)(void *, unsigned char *, size_t),
  10515. void *p_rng );
  10516. /** Check public-private key pair */
  10517. int (*check_pair_func)( const void *pub, const void *prv );
  10518. /** Allocate a new context */
  10519. void * (*ctx_alloc_func)( void );
  10520. /** Free the given context */
  10521. void (*ctx_free_func)( void *ctx );
  10522. /** Interface with the debug module */
  10523. void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items );
  10524. };
  10525. #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
  10526. /* Container for RSA-alt */
  10527. typedef struct
  10528. {
  10529. void *key;
  10530. mbedtls_pk_rsa_alt_decrypt_func decrypt_func;
  10531. mbedtls_pk_rsa_alt_sign_func sign_func;
  10532. mbedtls_pk_rsa_alt_key_len_func key_len_func;
  10533. } mbedtls_rsa_alt_context;
  10534. #endif
  10535. #if defined(MBEDTLS_RSA_C)
  10536. extern const mbedtls_pk_info_t mbedtls_rsa_info;
  10537. #endif
  10538. #if defined(MBEDTLS_ECP_C)
  10539. extern const mbedtls_pk_info_t mbedtls_eckey_info;
  10540. extern const mbedtls_pk_info_t mbedtls_eckeydh_info;
  10541. #endif
  10542. #if defined(MBEDTLS_ECDSA_C)
  10543. extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
  10544. #endif
  10545. #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
  10546. extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
  10547. #endif
  10548. #endif /* MBEDTLS_PK_WRAP_H */
  10549. /********* Start of file include/mbedtls/x509.h ************/
  10550. /**
  10551. * \file x509.h
  10552. *
  10553. * \brief X.509 generic defines and structures
  10554. */
  10555. /*
  10556. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  10557. * SPDX-License-Identifier: Apache-2.0
  10558. *
  10559. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  10560. * not use this file except in compliance with the License.
  10561. * You may obtain a copy of the License at
  10562. *
  10563. * http://www.apache.org/licenses/LICENSE-2.0
  10564. *
  10565. * Unless required by applicable law or agreed to in writing, software
  10566. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  10567. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10568. * See the License for the specific language governing permissions and
  10569. * limitations under the License.
  10570. *
  10571. * This file is part of mbed TLS (https://tls.mbed.org)
  10572. */
  10573. #ifndef MBEDTLS_X509_H
  10574. #define MBEDTLS_X509_H
  10575. #if !defined(MBEDTLS_CONFIG_FILE)
  10576. #else
  10577. #endif
  10578. #if defined(MBEDTLS_RSA_C)
  10579. #endif
  10580. /**
  10581. * \addtogroup x509_module
  10582. * \{
  10583. */
  10584. #if !defined(MBEDTLS_X509_MAX_INTERMEDIATE_CA)
  10585. /**
  10586. * Maximum number of intermediate CAs in a verification chain.
  10587. * That is, maximum length of the chain, excluding the end-entity certificate
  10588. * and the trusted root certificate.
  10589. *
  10590. * Set this to a low value to prevent an adversary from making you waste
  10591. * resources verifying an overlong certificate chain.
  10592. */
  10593. #define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8
  10594. #endif
  10595. /**
  10596. * \name X509 Error codes
  10597. * \{
  10598. */
  10599. #define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */
  10600. #define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100 /**< Requested OID is unknown. */
  10601. #define MBEDTLS_ERR_X509_INVALID_FORMAT -0x2180 /**< The CRT/CRL/CSR format is invalid, e.g. different type expected. */
  10602. #define MBEDTLS_ERR_X509_INVALID_VERSION -0x2200 /**< The CRT/CRL/CSR version element is invalid. */
  10603. #define MBEDTLS_ERR_X509_INVALID_SERIAL -0x2280 /**< The serial tag or value is invalid. */
  10604. #define MBEDTLS_ERR_X509_INVALID_ALG -0x2300 /**< The algorithm tag or value is invalid. */
  10605. #define MBEDTLS_ERR_X509_INVALID_NAME -0x2380 /**< The name tag or value is invalid. */
  10606. #define MBEDTLS_ERR_X509_INVALID_DATE -0x2400 /**< The date tag or value is invalid. */
  10607. #define MBEDTLS_ERR_X509_INVALID_SIGNATURE -0x2480 /**< The signature tag or value invalid. */
  10608. #define MBEDTLS_ERR_X509_INVALID_EXTENSIONS -0x2500 /**< The extension tag or value is invalid. */
  10609. #define MBEDTLS_ERR_X509_UNKNOWN_VERSION -0x2580 /**< CRT/CRL/CSR has an unsupported version number. */
  10610. #define MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG -0x2600 /**< Signature algorithm (oid) is unsupported. */
  10611. #define MBEDTLS_ERR_X509_SIG_MISMATCH -0x2680 /**< Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) */
  10612. #define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED -0x2700 /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */
  10613. #define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 /**< Format not recognized as DER or PEM. */
  10614. #define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800 /**< Input invalid. */
  10615. #define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880 /**< Allocation of memory failed. */
  10616. #define MBEDTLS_ERR_X509_FILE_IO_ERROR -0x2900 /**< Read/write of file failed. */
  10617. #define MBEDTLS_ERR_X509_BUFFER_TOO_SMALL -0x2980 /**< Destination buffer is too small. */
  10618. #define MBEDTLS_ERR_X509_FATAL_ERROR -0x3000 /**< A fatal error occured, eg the chain is too long or the vrfy callback failed. */
  10619. /* \} name */
  10620. /**
  10621. * \name X509 Verify codes
  10622. * \{
  10623. */
  10624. /* Reminder: update x509_crt_verify_strings[] in library/x509_crt.c */
  10625. #define MBEDTLS_X509_BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */
  10626. #define MBEDTLS_X509_BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */
  10627. #define MBEDTLS_X509_BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */
  10628. #define MBEDTLS_X509_BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */
  10629. #define MBEDTLS_X509_BADCRL_NOT_TRUSTED 0x10 /**< The CRL is not correctly signed by the trusted CA. */
  10630. #define MBEDTLS_X509_BADCRL_EXPIRED 0x20 /**< The CRL is expired. */
  10631. #define MBEDTLS_X509_BADCERT_MISSING 0x40 /**< Certificate was missing. */
  10632. #define MBEDTLS_X509_BADCERT_SKIP_VERIFY 0x80 /**< Certificate verification was skipped. */
  10633. #define MBEDTLS_X509_BADCERT_OTHER 0x0100 /**< Other reason (can be used by verify callback) */
  10634. #define MBEDTLS_X509_BADCERT_FUTURE 0x0200 /**< The certificate validity starts in the future. */
  10635. #define MBEDTLS_X509_BADCRL_FUTURE 0x0400 /**< The CRL is from the future */
  10636. #define MBEDTLS_X509_BADCERT_KEY_USAGE 0x0800 /**< Usage does not match the keyUsage extension. */
  10637. #define MBEDTLS_X509_BADCERT_EXT_KEY_USAGE 0x1000 /**< Usage does not match the extendedKeyUsage extension. */
  10638. #define MBEDTLS_X509_BADCERT_NS_CERT_TYPE 0x2000 /**< Usage does not match the nsCertType extension. */
  10639. #define MBEDTLS_X509_BADCERT_BAD_MD 0x4000 /**< The certificate is signed with an unacceptable hash. */
  10640. #define MBEDTLS_X509_BADCERT_BAD_PK 0x8000 /**< The certificate is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
  10641. #define MBEDTLS_X509_BADCERT_BAD_KEY 0x010000 /**< The certificate is signed with an unacceptable key (eg bad curve, RSA too short). */
  10642. #define MBEDTLS_X509_BADCRL_BAD_MD 0x020000 /**< The CRL is signed with an unacceptable hash. */
  10643. #define MBEDTLS_X509_BADCRL_BAD_PK 0x040000 /**< The CRL is signed with an unacceptable PK alg (eg RSA vs ECDSA). */
  10644. #define MBEDTLS_X509_BADCRL_BAD_KEY 0x080000 /**< The CRL is signed with an unacceptable key (eg bad curve, RSA too short). */
  10645. /* \} name */
  10646. /* \} addtogroup x509_module */
  10647. /*
  10648. * X.509 v3 Key Usage Extension flags
  10649. * Reminder: update x509_info_key_usage() when adding new flags.
  10650. */
  10651. #define MBEDTLS_X509_KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
  10652. #define MBEDTLS_X509_KU_NON_REPUDIATION (0x40) /* bit 1 */
  10653. #define MBEDTLS_X509_KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
  10654. #define MBEDTLS_X509_KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
  10655. #define MBEDTLS_X509_KU_KEY_AGREEMENT (0x08) /* bit 4 */
  10656. #define MBEDTLS_X509_KU_KEY_CERT_SIGN (0x04) /* bit 5 */
  10657. #define MBEDTLS_X509_KU_CRL_SIGN (0x02) /* bit 6 */
  10658. #define MBEDTLS_X509_KU_ENCIPHER_ONLY (0x01) /* bit 7 */
  10659. #define MBEDTLS_X509_KU_DECIPHER_ONLY (0x8000) /* bit 8 */
  10660. /*
  10661. * Netscape certificate types
  10662. * (http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn3.html)
  10663. */
  10664. #define MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
  10665. #define MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
  10666. #define MBEDTLS_X509_NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
  10667. #define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
  10668. #define MBEDTLS_X509_NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
  10669. #define MBEDTLS_X509_NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
  10670. #define MBEDTLS_X509_NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
  10671. #define MBEDTLS_X509_NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
  10672. /*
  10673. * X.509 extension types
  10674. *
  10675. * Comments refer to the status for using certificates. Status can be
  10676. * different for writing certificates or reading CRLs or CSRs.
  10677. */
  10678. #define MBEDTLS_X509_EXT_AUTHORITY_KEY_IDENTIFIER (1 << 0)
  10679. #define MBEDTLS_X509_EXT_SUBJECT_KEY_IDENTIFIER (1 << 1)
  10680. #define MBEDTLS_X509_EXT_KEY_USAGE (1 << 2)
  10681. #define MBEDTLS_X509_EXT_CERTIFICATE_POLICIES (1 << 3)
  10682. #define MBEDTLS_X509_EXT_POLICY_MAPPINGS (1 << 4)
  10683. #define MBEDTLS_X509_EXT_SUBJECT_ALT_NAME (1 << 5) /* Supported (DNS) */
  10684. #define MBEDTLS_X509_EXT_ISSUER_ALT_NAME (1 << 6)
  10685. #define MBEDTLS_X509_EXT_SUBJECT_DIRECTORY_ATTRS (1 << 7)
  10686. #define MBEDTLS_X509_EXT_BASIC_CONSTRAINTS (1 << 8) /* Supported */
  10687. #define MBEDTLS_X509_EXT_NAME_CONSTRAINTS (1 << 9)
  10688. #define MBEDTLS_X509_EXT_POLICY_CONSTRAINTS (1 << 10)
  10689. #define MBEDTLS_X509_EXT_EXTENDED_KEY_USAGE (1 << 11)
  10690. #define MBEDTLS_X509_EXT_CRL_DISTRIBUTION_POINTS (1 << 12)
  10691. #define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13)
  10692. #define MBEDTLS_X509_EXT_FRESHEST_CRL (1 << 14)
  10693. #define MBEDTLS_X509_EXT_NS_CERT_TYPE (1 << 16)
  10694. /*
  10695. * Storage format identifiers
  10696. * Recognized formats: PEM and DER
  10697. */
  10698. #define MBEDTLS_X509_FORMAT_DER 1
  10699. #define MBEDTLS_X509_FORMAT_PEM 2
  10700. #define MBEDTLS_X509_MAX_DN_NAME_SIZE 256 /**< Maximum value size of a DN entry */
  10701. #ifdef __cplusplus
  10702. extern "C" {
  10703. #endif
  10704. /**
  10705. * \addtogroup x509_module
  10706. * \{ */
  10707. /**
  10708. * \name Structures for parsing X.509 certificates, CRLs and CSRs
  10709. * \{
  10710. */
  10711. /**
  10712. * Type-length-value structure that allows for ASN1 using DER.
  10713. */
  10714. typedef mbedtls_asn1_buf mbedtls_x509_buf;
  10715. /**
  10716. * Container for ASN1 bit strings.
  10717. */
  10718. typedef mbedtls_asn1_bitstring mbedtls_x509_bitstring;
  10719. /**
  10720. * Container for ASN1 named information objects.
  10721. * It allows for Relative Distinguished Names (e.g. cn=localhost,ou=code,etc.).
  10722. */
  10723. typedef mbedtls_asn1_named_data mbedtls_x509_name;
  10724. /**
  10725. * Container for a sequence of ASN.1 items
  10726. */
  10727. typedef mbedtls_asn1_sequence mbedtls_x509_sequence;
  10728. /** Container for date and time (precision in seconds). */
  10729. typedef struct mbedtls_x509_time
  10730. {
  10731. int year, mon, day; /**< Date. */
  10732. int hour, min, sec; /**< Time. */
  10733. }
  10734. mbedtls_x509_time;
  10735. /** \} name Structures for parsing X.509 certificates, CRLs and CSRs */
  10736. /** \} addtogroup x509_module */
  10737. /**
  10738. * \brief Store the certificate DN in printable form into buf;
  10739. * no more than size characters will be written.
  10740. *
  10741. * \param buf Buffer to write to
  10742. * \param size Maximum size of buffer
  10743. * \param dn The X509 name to represent
  10744. *
  10745. * \return The length of the string written (not including the
  10746. * terminated nul byte), or a negative error code.
  10747. */
  10748. int mbedtls_x509_dn_gets( char *buf, size_t size, const mbedtls_x509_name *dn );
  10749. /**
  10750. * \brief Store the certificate serial in printable form into buf;
  10751. * no more than size characters will be written.
  10752. *
  10753. * \param buf Buffer to write to
  10754. * \param size Maximum size of buffer
  10755. * \param serial The X509 serial to represent
  10756. *
  10757. * \return The length of the string written (not including the
  10758. * terminated nul byte), or a negative error code.
  10759. */
  10760. int mbedtls_x509_serial_gets( char *buf, size_t size, const mbedtls_x509_buf *serial );
  10761. /**
  10762. * \brief Check a given mbedtls_x509_time against the system time
  10763. * and tell if it's in the past.
  10764. *
  10765. * \note Intended usage is "if( is_past( valid_to ) ) ERROR".
  10766. * Hence the return value of 1 if on internal errors.
  10767. *
  10768. * \param to mbedtls_x509_time to check
  10769. *
  10770. * \return 1 if the given time is in the past or an error occured,
  10771. * 0 otherwise.
  10772. */
  10773. int mbedtls_x509_time_is_past( const mbedtls_x509_time *to );
  10774. /**
  10775. * \brief Check a given mbedtls_x509_time against the system time
  10776. * and tell if it's in the future.
  10777. *
  10778. * \note Intended usage is "if( is_future( valid_from ) ) ERROR".
  10779. * Hence the return value of 1 if on internal errors.
  10780. *
  10781. * \param from mbedtls_x509_time to check
  10782. *
  10783. * \return 1 if the given time is in the future or an error occured,
  10784. * 0 otherwise.
  10785. */
  10786. int mbedtls_x509_time_is_future( const mbedtls_x509_time *from );
  10787. /**
  10788. * \brief Checkup routine
  10789. *
  10790. * \return 0 if successful, or 1 if the test failed
  10791. */
  10792. int mbedtls_x509_self_test( int verbose );
  10793. /*
  10794. * Internal module functions. You probably do not want to use these unless you
  10795. * know you do.
  10796. */
  10797. int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
  10798. mbedtls_x509_name *cur );
  10799. int mbedtls_x509_get_alg_null( unsigned char **p, const unsigned char *end,
  10800. mbedtls_x509_buf *alg );
  10801. int mbedtls_x509_get_alg( unsigned char **p, const unsigned char *end,
  10802. mbedtls_x509_buf *alg, mbedtls_x509_buf *params );
  10803. #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT)
  10804. int mbedtls_x509_get_rsassa_pss_params( const mbedtls_x509_buf *params,
  10805. mbedtls_md_type_t *md_alg, mbedtls_md_type_t *mgf_md,
  10806. int *salt_len );
  10807. #endif
  10808. int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig );
  10809. int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x509_buf *sig_params,
  10810. mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg,
  10811. void **sig_opts );
  10812. int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
  10813. mbedtls_x509_time *t );
  10814. int mbedtls_x509_get_serial( unsigned char **p, const unsigned char *end,
  10815. mbedtls_x509_buf *serial );
  10816. int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
  10817. mbedtls_x509_buf *ext, int tag );
  10818. int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *sig_oid,
  10819. mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
  10820. const void *sig_opts );
  10821. int mbedtls_x509_key_size_helper( char *buf, size_t buf_size, const char *name );
  10822. int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name );
  10823. int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len,
  10824. int critical, const unsigned char *val,
  10825. size_t val_len );
  10826. int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start,
  10827. mbedtls_asn1_named_data *first );
  10828. int mbedtls_x509_write_names( unsigned char **p, unsigned char *start,
  10829. mbedtls_asn1_named_data *first );
  10830. int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start,
  10831. const char *oid, size_t oid_len,
  10832. unsigned char *sig, size_t size );
  10833. #define MBEDTLS_X509_SAFE_SNPRINTF \
  10834. do { \
  10835. if( ret < 0 || (size_t) ret >= n ) \
  10836. return( MBEDTLS_ERR_X509_BUFFER_TOO_SMALL ); \
  10837. \
  10838. n -= (size_t) ret; \
  10839. p += (size_t) ret; \
  10840. } while( 0 )
  10841. #ifdef __cplusplus
  10842. }
  10843. #endif
  10844. #endif /* x509.h */
  10845. /********* Start of file include/mbedtls/x509_crl.h ************/
  10846. /**
  10847. * \file x509_crl.h
  10848. *
  10849. * \brief X.509 certificate revocation list parsing
  10850. */
  10851. /*
  10852. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  10853. * SPDX-License-Identifier: Apache-2.0
  10854. *
  10855. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  10856. * not use this file except in compliance with the License.
  10857. * You may obtain a copy of the License at
  10858. *
  10859. * http://www.apache.org/licenses/LICENSE-2.0
  10860. *
  10861. * Unless required by applicable law or agreed to in writing, software
  10862. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  10863. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10864. * See the License for the specific language governing permissions and
  10865. * limitations under the License.
  10866. *
  10867. * This file is part of mbed TLS (https://tls.mbed.org)
  10868. */
  10869. #ifndef MBEDTLS_X509_CRL_H
  10870. #define MBEDTLS_X509_CRL_H
  10871. #if !defined(MBEDTLS_CONFIG_FILE)
  10872. #else
  10873. #endif
  10874. #ifdef __cplusplus
  10875. extern "C" {
  10876. #endif
  10877. /**
  10878. * \addtogroup x509_module
  10879. * \{ */
  10880. /**
  10881. * \name Structures and functions for parsing CRLs
  10882. * \{
  10883. */
  10884. /**
  10885. * Certificate revocation list entry.
  10886. * Contains the CA-specific serial numbers and revocation dates.
  10887. */
  10888. typedef struct mbedtls_x509_crl_entry
  10889. {
  10890. mbedtls_x509_buf raw;
  10891. mbedtls_x509_buf serial;
  10892. mbedtls_x509_time revocation_date;
  10893. mbedtls_x509_buf entry_ext;
  10894. struct mbedtls_x509_crl_entry *next;
  10895. }
  10896. mbedtls_x509_crl_entry;
  10897. /**
  10898. * Certificate revocation list structure.
  10899. * Every CRL may have multiple entries.
  10900. */
  10901. typedef struct mbedtls_x509_crl
  10902. {
  10903. mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
  10904. mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
  10905. int version; /**< CRL version (1=v1, 2=v2) */
  10906. mbedtls_x509_buf sig_oid; /**< CRL signature type identifier */
  10907. mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). */
  10908. mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
  10909. mbedtls_x509_time this_update;
  10910. mbedtls_x509_time next_update;
  10911. mbedtls_x509_crl_entry entry; /**< The CRL entries containing the certificate revocation times for this CA. */
  10912. mbedtls_x509_buf crl_ext;
  10913. mbedtls_x509_buf sig_oid2;
  10914. mbedtls_x509_buf sig;
  10915. mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
  10916. mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
  10917. void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
  10918. struct mbedtls_x509_crl *next;
  10919. }
  10920. mbedtls_x509_crl;
  10921. /**
  10922. * \brief Parse a DER-encoded CRL and append it to the chained list
  10923. *
  10924. * \param chain points to the start of the chain
  10925. * \param buf buffer holding the CRL data in DER format
  10926. * \param buflen size of the buffer
  10927. * (including the terminating null byte for PEM data)
  10928. *
  10929. * \return 0 if successful, or a specific X509 or PEM error code
  10930. */
  10931. int mbedtls_x509_crl_parse_der( mbedtls_x509_crl *chain,
  10932. const unsigned char *buf, size_t buflen );
  10933. /**
  10934. * \brief Parse one or more CRLs and append them to the chained list
  10935. *
  10936. * \note Mutliple CRLs are accepted only if using PEM format
  10937. *
  10938. * \param chain points to the start of the chain
  10939. * \param buf buffer holding the CRL data in PEM or DER format
  10940. * \param buflen size of the buffer
  10941. * (including the terminating null byte for PEM data)
  10942. *
  10943. * \return 0 if successful, or a specific X509 or PEM error code
  10944. */
  10945. int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, size_t buflen );
  10946. #if defined(MBEDTLS_FS_IO)
  10947. /**
  10948. * \brief Load one or more CRLs and append them to the chained list
  10949. *
  10950. * \note Mutliple CRLs are accepted only if using PEM format
  10951. *
  10952. * \param chain points to the start of the chain
  10953. * \param path filename to read the CRLs from (in PEM or DER encoding)
  10954. *
  10955. * \return 0 if successful, or a specific X509 or PEM error code
  10956. */
  10957. int mbedtls_x509_crl_parse_file( mbedtls_x509_crl *chain, const char *path );
  10958. #endif /* MBEDTLS_FS_IO */
  10959. /**
  10960. * \brief Returns an informational string about the CRL.
  10961. *
  10962. * \param buf Buffer to write to
  10963. * \param size Maximum size of buffer
  10964. * \param prefix A line prefix
  10965. * \param crl The X509 CRL to represent
  10966. *
  10967. * \return The length of the string written (not including the
  10968. * terminated nul byte), or a negative error code.
  10969. */
  10970. int mbedtls_x509_crl_info( char *buf, size_t size, const char *prefix,
  10971. const mbedtls_x509_crl *crl );
  10972. /**
  10973. * \brief Initialize a CRL (chain)
  10974. *
  10975. * \param crl CRL chain to initialize
  10976. */
  10977. void mbedtls_x509_crl_init( mbedtls_x509_crl *crl );
  10978. /**
  10979. * \brief Unallocate all CRL data
  10980. *
  10981. * \param crl CRL chain to free
  10982. */
  10983. void mbedtls_x509_crl_free( mbedtls_x509_crl *crl );
  10984. /* \} name */
  10985. /* \} addtogroup x509_module */
  10986. #ifdef __cplusplus
  10987. }
  10988. #endif
  10989. #endif /* mbedtls_x509_crl.h */
  10990. /********* Start of file include/mbedtls/x509_crt.h ************/
  10991. /**
  10992. * \file x509_crt.h
  10993. *
  10994. * \brief X.509 certificate parsing and writing
  10995. */
  10996. /*
  10997. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  10998. * SPDX-License-Identifier: Apache-2.0
  10999. *
  11000. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  11001. * not use this file except in compliance with the License.
  11002. * You may obtain a copy of the License at
  11003. *
  11004. * http://www.apache.org/licenses/LICENSE-2.0
  11005. *
  11006. * Unless required by applicable law or agreed to in writing, software
  11007. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11008. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11009. * See the License for the specific language governing permissions and
  11010. * limitations under the License.
  11011. *
  11012. * This file is part of mbed TLS (https://tls.mbed.org)
  11013. */
  11014. #ifndef MBEDTLS_X509_CRT_H
  11015. #define MBEDTLS_X509_CRT_H
  11016. #if !defined(MBEDTLS_CONFIG_FILE)
  11017. #else
  11018. #endif
  11019. /**
  11020. * \addtogroup x509_module
  11021. * \{
  11022. */
  11023. #ifdef __cplusplus
  11024. extern "C" {
  11025. #endif
  11026. /**
  11027. * \name Structures and functions for parsing and writing X.509 certificates
  11028. * \{
  11029. */
  11030. /**
  11031. * Container for an X.509 certificate. The certificate may be chained.
  11032. */
  11033. typedef struct mbedtls_x509_crt
  11034. {
  11035. mbedtls_x509_buf raw; /**< The raw certificate data (DER). */
  11036. mbedtls_x509_buf tbs; /**< The raw certificate body (DER). The part that is To Be Signed. */
  11037. int version; /**< The X.509 version. (1=v1, 2=v2, 3=v3) */
  11038. mbedtls_x509_buf serial; /**< Unique id for certificate issued by a specific CA. */
  11039. mbedtls_x509_buf sig_oid; /**< Signature algorithm, e.g. sha1RSA */
  11040. mbedtls_x509_buf issuer_raw; /**< The raw issuer data (DER). Used for quick comparison. */
  11041. mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). Used for quick comparison. */
  11042. mbedtls_x509_name issuer; /**< The parsed issuer data (named information object). */
  11043. mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
  11044. mbedtls_x509_time valid_from; /**< Start time of certificate validity. */
  11045. mbedtls_x509_time valid_to; /**< End time of certificate validity. */
  11046. mbedtls_pk_context pk; /**< Container for the public key context. */
  11047. mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
  11048. mbedtls_x509_buf subject_id; /**< Optional X.509 v2/v3 subject unique identifier. */
  11049. mbedtls_x509_buf v3_ext; /**< Optional X.509 v3 extensions. */
  11050. mbedtls_x509_sequence subject_alt_names; /**< Optional list of Subject Alternative Names (Only dNSName supported). */
  11051. int ext_types; /**< Bit string containing detected and parsed extensions */
  11052. int ca_istrue; /**< Optional Basic Constraint extension value: 1 if this certificate belongs to a CA, 0 otherwise. */
  11053. int max_pathlen; /**< Optional Basic Constraint extension value: The maximum path length to the root certificate. Path length is 1 higher than RFC 5280 'meaning', so 1+ */
  11054. unsigned int key_usage; /**< Optional key usage extension value: See the values in x509.h */
  11055. mbedtls_x509_sequence ext_key_usage; /**< Optional list of extended key usage OIDs. */
  11056. unsigned char ns_cert_type; /**< Optional Netscape certificate type extension value: See the values in x509.h */
  11057. mbedtls_x509_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
  11058. mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
  11059. mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
  11060. void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
  11061. struct mbedtls_x509_crt *next; /**< Next certificate in the CA-chain. */
  11062. }
  11063. mbedtls_x509_crt;
  11064. /**
  11065. * Build flag from an algorithm/curve identifier (pk, md, ecp)
  11066. * Since 0 is always XXX_NONE, ignore it.
  11067. */
  11068. #define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( id - 1 ) )
  11069. /**
  11070. * Security profile for certificate verification.
  11071. *
  11072. * All lists are bitfields, built by ORing flags from MBEDTLS_X509_ID_FLAG().
  11073. */
  11074. typedef struct
  11075. {
  11076. uint32_t allowed_mds; /**< MDs for signatures */
  11077. uint32_t allowed_pks; /**< PK algs for signatures */
  11078. uint32_t allowed_curves; /**< Elliptic curves for ECDSA */
  11079. uint32_t rsa_min_bitlen; /**< Minimum size for RSA keys */
  11080. }
  11081. mbedtls_x509_crt_profile;
  11082. #define MBEDTLS_X509_CRT_VERSION_1 0
  11083. #define MBEDTLS_X509_CRT_VERSION_2 1
  11084. #define MBEDTLS_X509_CRT_VERSION_3 2
  11085. #define MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN 32
  11086. #define MBEDTLS_X509_RFC5280_UTC_TIME_LEN 15
  11087. #if !defined( MBEDTLS_X509_MAX_FILE_PATH_LEN )
  11088. #define MBEDTLS_X509_MAX_FILE_PATH_LEN 512
  11089. #endif
  11090. /**
  11091. * Container for writing a certificate (CRT)
  11092. */
  11093. typedef struct mbedtls_x509write_cert
  11094. {
  11095. int version;
  11096. mbedtls_mpi serial;
  11097. mbedtls_pk_context *subject_key;
  11098. mbedtls_pk_context *issuer_key;
  11099. mbedtls_asn1_named_data *subject;
  11100. mbedtls_asn1_named_data *issuer;
  11101. mbedtls_md_type_t md_alg;
  11102. char not_before[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
  11103. char not_after[MBEDTLS_X509_RFC5280_UTC_TIME_LEN + 1];
  11104. mbedtls_asn1_named_data *extensions;
  11105. }
  11106. mbedtls_x509write_cert;
  11107. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  11108. /**
  11109. * Default security profile. Should provide a good balance between security
  11110. * and compatibility with current deployments.
  11111. */
  11112. extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default;
  11113. /**
  11114. * Expected next default profile. Recommended for new deployments.
  11115. * Currently targets a 128-bit security level, except for RSA-2048.
  11116. */
  11117. extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next;
  11118. /**
  11119. * NSA Suite B profile.
  11120. */
  11121. extern const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_suiteb;
  11122. /**
  11123. * \brief Parse a single DER formatted certificate and add it
  11124. * to the chained list.
  11125. *
  11126. * \param chain points to the start of the chain
  11127. * \param buf buffer holding the certificate DER data
  11128. * \param buflen size of the buffer
  11129. *
  11130. * \return 0 if successful, or a specific X509 or PEM error code
  11131. */
  11132. int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *buf,
  11133. size_t buflen );
  11134. /**
  11135. * \brief Parse one or more certificates and add them
  11136. * to the chained list. Parses permissively. If some
  11137. * certificates can be parsed, the result is the number
  11138. * of failed certificates it encountered. If none complete
  11139. * correctly, the first error is returned.
  11140. *
  11141. * \param chain points to the start of the chain
  11142. * \param buf buffer holding the certificate data in PEM or DER format
  11143. * \param buflen size of the buffer
  11144. * (including the terminating null byte for PEM data)
  11145. *
  11146. * \return 0 if all certificates parsed successfully, a positive number
  11147. * if partly successful or a specific X509 or PEM error code
  11148. */
  11149. int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen );
  11150. #if defined(MBEDTLS_FS_IO)
  11151. /**
  11152. * \brief Load one or more certificates and add them
  11153. * to the chained list. Parses permissively. If some
  11154. * certificates can be parsed, the result is the number
  11155. * of failed certificates it encountered. If none complete
  11156. * correctly, the first error is returned.
  11157. *
  11158. * \param chain points to the start of the chain
  11159. * \param path filename to read the certificates from
  11160. *
  11161. * \return 0 if all certificates parsed successfully, a positive number
  11162. * if partly successful or a specific X509 or PEM error code
  11163. */
  11164. int mbedtls_x509_crt_parse_file( mbedtls_x509_crt *chain, const char *path );
  11165. /**
  11166. * \brief Load one or more certificate files from a path and add them
  11167. * to the chained list. Parses permissively. If some
  11168. * certificates can be parsed, the result is the number
  11169. * of failed certificates it encountered. If none complete
  11170. * correctly, the first error is returned.
  11171. *
  11172. * \param chain points to the start of the chain
  11173. * \param path directory / folder to read the certificate files from
  11174. *
  11175. * \return 0 if all certificates parsed successfully, a positive number
  11176. * if partly successful or a specific X509 or PEM error code
  11177. */
  11178. int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path );
  11179. #endif /* MBEDTLS_FS_IO */
  11180. /**
  11181. * \brief Returns an informational string about the
  11182. * certificate.
  11183. *
  11184. * \param buf Buffer to write to
  11185. * \param size Maximum size of buffer
  11186. * \param prefix A line prefix
  11187. * \param crt The X509 certificate to represent
  11188. *
  11189. * \return The length of the string written (not including the
  11190. * terminated nul byte), or a negative error code.
  11191. */
  11192. int mbedtls_x509_crt_info( char *buf, size_t size, const char *prefix,
  11193. const mbedtls_x509_crt *crt );
  11194. /**
  11195. * \brief Returns an informational string about the
  11196. * verification status of a certificate.
  11197. *
  11198. * \param buf Buffer to write to
  11199. * \param size Maximum size of buffer
  11200. * \param prefix A line prefix
  11201. * \param flags Verification flags created by mbedtls_x509_crt_verify()
  11202. *
  11203. * \return The length of the string written (not including the
  11204. * terminated nul byte), or a negative error code.
  11205. */
  11206. int mbedtls_x509_crt_verify_info( char *buf, size_t size, const char *prefix,
  11207. uint32_t flags );
  11208. /**
  11209. * \brief Verify the certificate signature
  11210. *
  11211. * The verify callback is a user-supplied callback that
  11212. * can clear / modify / add flags for a certificate. If set,
  11213. * the verification callback is called for each
  11214. * certificate in the chain (from the trust-ca down to the
  11215. * presented crt). The parameters for the callback are:
  11216. * (void *parameter, mbedtls_x509_crt *crt, int certificate_depth,
  11217. * int *flags). With the flags representing current flags for
  11218. * that specific certificate and the certificate depth from
  11219. * the bottom (Peer cert depth = 0).
  11220. *
  11221. * All flags left after returning from the callback
  11222. * are also returned to the application. The function should
  11223. * return 0 for anything (including invalid certificates)
  11224. * other than fatal error, as a non-zero return code
  11225. * immediately aborts the verification process. For fatal
  11226. * errors, a specific error code should be used (different
  11227. * from MBEDTLS_ERR_X509_CERT_VERIFY_FAILED which should not
  11228. * be returned at this point), or MBEDTLS_ERR_X509_FATAL_ERROR
  11229. * can be used if no better code is available.
  11230. *
  11231. * \note In case verification failed, the results can be displayed
  11232. * using \c mbedtls_x509_crt_verify_info()
  11233. *
  11234. * \note Same as \c mbedtls_x509_crt_verify_with_profile() with the
  11235. * default security profile.
  11236. *
  11237. * \note It is your responsibility to provide up-to-date CRLs for
  11238. * all trusted CAs. If no CRL is provided for the CA that was
  11239. * used to sign the certificate, CRL verification is skipped
  11240. * silently, that is *without* setting any flag.
  11241. *
  11242. * \param crt a certificate (chain) to be verified
  11243. * \param trust_ca the list of trusted CAs
  11244. * \param ca_crl the list of CRLs for trusted CAs (see note above)
  11245. * \param cn expected Common Name (can be set to
  11246. * NULL if the CN must not be verified)
  11247. * \param flags result of the verification
  11248. * \param f_vrfy verification function
  11249. * \param p_vrfy verification parameter
  11250. *
  11251. * \return 0 (and flags set to 0) if the chain was verified and valid,
  11252. * MBEDTLS_ERR_X509_CERT_VERIFY_FAILED if the chain was verified
  11253. * but found to be invalid, in which case *flags will have one
  11254. * or more MBEDTLS_X509_BADCERT_XXX or MBEDTLS_X509_BADCRL_XXX
  11255. * flags set, or another error (and flags set to 0xffffffff)
  11256. * in case of a fatal error encountered during the
  11257. * verification process.
  11258. */
  11259. int mbedtls_x509_crt_verify( mbedtls_x509_crt *crt,
  11260. mbedtls_x509_crt *trust_ca,
  11261. mbedtls_x509_crl *ca_crl,
  11262. const char *cn, uint32_t *flags,
  11263. int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
  11264. void *p_vrfy );
  11265. /**
  11266. * \brief Verify the certificate signature according to profile
  11267. *
  11268. * \note Same as \c mbedtls_x509_crt_verify(), but with explicit
  11269. * security profile.
  11270. *
  11271. * \note The restrictions on keys (RSA minimum size, allowed curves
  11272. * for ECDSA) apply to all certificates: trusted root,
  11273. * intermediate CAs if any, and end entity certificate.
  11274. *
  11275. * \param crt a certificate (chain) to be verified
  11276. * \param trust_ca the list of trusted CAs
  11277. * \param ca_crl the list of CRLs for trusted CAs
  11278. * \param profile security profile for verification
  11279. * \param cn expected Common Name (can be set to
  11280. * NULL if the CN must not be verified)
  11281. * \param flags result of the verification
  11282. * \param f_vrfy verification function
  11283. * \param p_vrfy verification parameter
  11284. *
  11285. * \return 0 if successful or MBEDTLS_ERR_X509_CERT_VERIFY_FAILED
  11286. * in which case *flags will have one or more
  11287. * MBEDTLS_X509_BADCERT_XXX or MBEDTLS_X509_BADCRL_XXX flags
  11288. * set,
  11289. * or another error in case of a fatal error encountered
  11290. * during the verification process.
  11291. */
  11292. int mbedtls_x509_crt_verify_with_profile( mbedtls_x509_crt *crt,
  11293. mbedtls_x509_crt *trust_ca,
  11294. mbedtls_x509_crl *ca_crl,
  11295. const mbedtls_x509_crt_profile *profile,
  11296. const char *cn, uint32_t *flags,
  11297. int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
  11298. void *p_vrfy );
  11299. #if defined(MBEDTLS_X509_CHECK_KEY_USAGE)
  11300. /**
  11301. * \brief Check usage of certificate against keyUsage extension.
  11302. *
  11303. * \param crt Leaf certificate used.
  11304. * \param usage Intended usage(s) (eg MBEDTLS_X509_KU_KEY_ENCIPHERMENT
  11305. * before using the certificate to perform an RSA key
  11306. * exchange).
  11307. *
  11308. * \note Except for decipherOnly and encipherOnly, a bit set in the
  11309. * usage argument means this bit MUST be set in the
  11310. * certificate. For decipherOnly and encipherOnly, it means
  11311. * that bit MAY be set.
  11312. *
  11313. * \return 0 is these uses of the certificate are allowed,
  11314. * MBEDTLS_ERR_X509_BAD_INPUT_DATA if the keyUsage extension
  11315. * is present but does not match the usage argument.
  11316. *
  11317. * \note You should only call this function on leaf certificates, on
  11318. * (intermediate) CAs the keyUsage extension is automatically
  11319. * checked by \c mbedtls_x509_crt_verify().
  11320. */
  11321. int mbedtls_x509_crt_check_key_usage( const mbedtls_x509_crt *crt,
  11322. unsigned int usage );
  11323. #endif /* MBEDTLS_X509_CHECK_KEY_USAGE) */
  11324. #if defined(MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE)
  11325. /**
  11326. * \brief Check usage of certificate against extendedKeyUsage.
  11327. *
  11328. * \param crt Leaf certificate used.
  11329. * \param usage_oid Intended usage (eg MBEDTLS_OID_SERVER_AUTH or
  11330. * MBEDTLS_OID_CLIENT_AUTH).
  11331. * \param usage_len Length of usage_oid (eg given by MBEDTLS_OID_SIZE()).
  11332. *
  11333. * \return 0 if this use of the certificate is allowed,
  11334. * MBEDTLS_ERR_X509_BAD_INPUT_DATA if not.
  11335. *
  11336. * \note Usually only makes sense on leaf certificates.
  11337. */
  11338. int mbedtls_x509_crt_check_extended_key_usage( const mbedtls_x509_crt *crt,
  11339. const char *usage_oid,
  11340. size_t usage_len );
  11341. #endif /* MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE */
  11342. #if defined(MBEDTLS_X509_CRL_PARSE_C)
  11343. /**
  11344. * \brief Verify the certificate revocation status
  11345. *
  11346. * \param crt a certificate to be verified
  11347. * \param crl the CRL to verify against
  11348. *
  11349. * \return 1 if the certificate is revoked, 0 otherwise
  11350. *
  11351. */
  11352. int mbedtls_x509_crt_is_revoked( const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl );
  11353. #endif /* MBEDTLS_X509_CRL_PARSE_C */
  11354. /**
  11355. * \brief Initialize a certificate (chain)
  11356. *
  11357. * \param crt Certificate chain to initialize
  11358. */
  11359. void mbedtls_x509_crt_init( mbedtls_x509_crt *crt );
  11360. /**
  11361. * \brief Unallocate all certificate data
  11362. *
  11363. * \param crt Certificate chain to free
  11364. */
  11365. void mbedtls_x509_crt_free( mbedtls_x509_crt *crt );
  11366. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  11367. /* \} name */
  11368. /* \} addtogroup x509_module */
  11369. #if defined(MBEDTLS_X509_CRT_WRITE_C)
  11370. /**
  11371. * \brief Initialize a CRT writing context
  11372. *
  11373. * \param ctx CRT context to initialize
  11374. */
  11375. void mbedtls_x509write_crt_init( mbedtls_x509write_cert *ctx );
  11376. /**
  11377. * \brief Set the verion for a Certificate
  11378. * Default: MBEDTLS_X509_CRT_VERSION_3
  11379. *
  11380. * \param ctx CRT context to use
  11381. * \param version version to set (MBEDTLS_X509_CRT_VERSION_1, MBEDTLS_X509_CRT_VERSION_2 or
  11382. * MBEDTLS_X509_CRT_VERSION_3)
  11383. */
  11384. void mbedtls_x509write_crt_set_version( mbedtls_x509write_cert *ctx, int version );
  11385. /**
  11386. * \brief Set the serial number for a Certificate.
  11387. *
  11388. * \param ctx CRT context to use
  11389. * \param serial serial number to set
  11390. *
  11391. * \return 0 if successful
  11392. */
  11393. int mbedtls_x509write_crt_set_serial( mbedtls_x509write_cert *ctx, const mbedtls_mpi *serial );
  11394. /**
  11395. * \brief Set the validity period for a Certificate
  11396. * Timestamps should be in string format for UTC timezone
  11397. * i.e. "YYYYMMDDhhmmss"
  11398. * e.g. "20131231235959" for December 31st 2013
  11399. * at 23:59:59
  11400. *
  11401. * \param ctx CRT context to use
  11402. * \param not_before not_before timestamp
  11403. * \param not_after not_after timestamp
  11404. *
  11405. * \return 0 if timestamp was parsed successfully, or
  11406. * a specific error code
  11407. */
  11408. int mbedtls_x509write_crt_set_validity( mbedtls_x509write_cert *ctx, const char *not_before,
  11409. const char *not_after );
  11410. /**
  11411. * \brief Set the issuer name for a Certificate
  11412. * Issuer names should contain a comma-separated list
  11413. * of OID types and values:
  11414. * e.g. "C=UK,O=ARM,CN=mbed TLS CA"
  11415. *
  11416. * \param ctx CRT context to use
  11417. * \param issuer_name issuer name to set
  11418. *
  11419. * \return 0 if issuer name was parsed successfully, or
  11420. * a specific error code
  11421. */
  11422. int mbedtls_x509write_crt_set_issuer_name( mbedtls_x509write_cert *ctx,
  11423. const char *issuer_name );
  11424. /**
  11425. * \brief Set the subject name for a Certificate
  11426. * Subject names should contain a comma-separated list
  11427. * of OID types and values:
  11428. * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
  11429. *
  11430. * \param ctx CRT context to use
  11431. * \param subject_name subject name to set
  11432. *
  11433. * \return 0 if subject name was parsed successfully, or
  11434. * a specific error code
  11435. */
  11436. int mbedtls_x509write_crt_set_subject_name( mbedtls_x509write_cert *ctx,
  11437. const char *subject_name );
  11438. /**
  11439. * \brief Set the subject public key for the certificate
  11440. *
  11441. * \param ctx CRT context to use
  11442. * \param key public key to include
  11443. */
  11444. void mbedtls_x509write_crt_set_subject_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
  11445. /**
  11446. * \brief Set the issuer key used for signing the certificate
  11447. *
  11448. * \param ctx CRT context to use
  11449. * \param key private key to sign with
  11450. */
  11451. void mbedtls_x509write_crt_set_issuer_key( mbedtls_x509write_cert *ctx, mbedtls_pk_context *key );
  11452. /**
  11453. * \brief Set the MD algorithm to use for the signature
  11454. * (e.g. MBEDTLS_MD_SHA1)
  11455. *
  11456. * \param ctx CRT context to use
  11457. * \param md_alg MD algorithm to use
  11458. */
  11459. void mbedtls_x509write_crt_set_md_alg( mbedtls_x509write_cert *ctx, mbedtls_md_type_t md_alg );
  11460. /**
  11461. * \brief Generic function to add to or replace an extension in the
  11462. * CRT
  11463. *
  11464. * \param ctx CRT context to use
  11465. * \param oid OID of the extension
  11466. * \param oid_len length of the OID
  11467. * \param critical if the extension is critical (per the RFC's definition)
  11468. * \param val value of the extension OCTET STRING
  11469. * \param val_len length of the value data
  11470. *
  11471. * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
  11472. */
  11473. int mbedtls_x509write_crt_set_extension( mbedtls_x509write_cert *ctx,
  11474. const char *oid, size_t oid_len,
  11475. int critical,
  11476. const unsigned char *val, size_t val_len );
  11477. /**
  11478. * \brief Set the basicConstraints extension for a CRT
  11479. *
  11480. * \param ctx CRT context to use
  11481. * \param is_ca is this a CA certificate
  11482. * \param max_pathlen maximum length of certificate chains below this
  11483. * certificate (only for CA certificates, -1 is
  11484. * inlimited)
  11485. *
  11486. * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
  11487. */
  11488. int mbedtls_x509write_crt_set_basic_constraints( mbedtls_x509write_cert *ctx,
  11489. int is_ca, int max_pathlen );
  11490. #if defined(MBEDTLS_SHA1_C)
  11491. /**
  11492. * \brief Set the subjectKeyIdentifier extension for a CRT
  11493. * Requires that mbedtls_x509write_crt_set_subject_key() has been
  11494. * called before
  11495. *
  11496. * \param ctx CRT context to use
  11497. *
  11498. * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
  11499. */
  11500. int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ctx );
  11501. /**
  11502. * \brief Set the authorityKeyIdentifier extension for a CRT
  11503. * Requires that mbedtls_x509write_crt_set_issuer_key() has been
  11504. * called before
  11505. *
  11506. * \param ctx CRT context to use
  11507. *
  11508. * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
  11509. */
  11510. int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert *ctx );
  11511. #endif /* MBEDTLS_SHA1_C */
  11512. /**
  11513. * \brief Set the Key Usage Extension flags
  11514. * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
  11515. *
  11516. * \param ctx CRT context to use
  11517. * \param key_usage key usage flags to set
  11518. *
  11519. * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
  11520. */
  11521. int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx,
  11522. unsigned int key_usage );
  11523. /**
  11524. * \brief Set the Netscape Cert Type flags
  11525. * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
  11526. *
  11527. * \param ctx CRT context to use
  11528. * \param ns_cert_type Netscape Cert Type flags to set
  11529. *
  11530. * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
  11531. */
  11532. int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx,
  11533. unsigned char ns_cert_type );
  11534. /**
  11535. * \brief Free the contents of a CRT write context
  11536. *
  11537. * \param ctx CRT context to free
  11538. */
  11539. void mbedtls_x509write_crt_free( mbedtls_x509write_cert *ctx );
  11540. /**
  11541. * \brief Write a built up certificate to a X509 DER structure
  11542. * Note: data is written at the end of the buffer! Use the
  11543. * return value to determine where you should start
  11544. * using the buffer
  11545. *
  11546. * \param ctx certificate to write away
  11547. * \param buf buffer to write to
  11548. * \param size size of the buffer
  11549. * \param f_rng RNG function (for signature, see note)
  11550. * \param p_rng RNG parameter
  11551. *
  11552. * \return length of data written if successful, or a specific
  11553. * error code
  11554. *
  11555. * \note f_rng may be NULL if RSA is used for signature and the
  11556. * signature is made offline (otherwise f_rng is desirable
  11557. * for countermeasures against timing attacks).
  11558. * ECDSA signatures always require a non-NULL f_rng.
  11559. */
  11560. int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
  11561. int (*f_rng)(void *, unsigned char *, size_t),
  11562. void *p_rng );
  11563. #if defined(MBEDTLS_PEM_WRITE_C)
  11564. /**
  11565. * \brief Write a built up certificate to a X509 PEM string
  11566. *
  11567. * \param ctx certificate to write away
  11568. * \param buf buffer to write to
  11569. * \param size size of the buffer
  11570. * \param f_rng RNG function (for signature, see note)
  11571. * \param p_rng RNG parameter
  11572. *
  11573. * \return 0 if successful, or a specific error code
  11574. *
  11575. * \note f_rng may be NULL if RSA is used for signature and the
  11576. * signature is made offline (otherwise f_rng is desirable
  11577. * for countermeasures against timing attacks).
  11578. * ECDSA signatures always require a non-NULL f_rng.
  11579. */
  11580. int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
  11581. int (*f_rng)(void *, unsigned char *, size_t),
  11582. void *p_rng );
  11583. #endif /* MBEDTLS_PEM_WRITE_C */
  11584. #endif /* MBEDTLS_X509_CRT_WRITE_C */
  11585. #ifdef __cplusplus
  11586. }
  11587. #endif
  11588. #endif /* mbedtls_x509_crt.h */
  11589. /********* Start of file include/mbedtls/x509_csr.h ************/
  11590. /**
  11591. * \file x509_csr.h
  11592. *
  11593. * \brief X.509 certificate signing request parsing and writing
  11594. */
  11595. /*
  11596. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  11597. * SPDX-License-Identifier: Apache-2.0
  11598. *
  11599. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  11600. * not use this file except in compliance with the License.
  11601. * You may obtain a copy of the License at
  11602. *
  11603. * http://www.apache.org/licenses/LICENSE-2.0
  11604. *
  11605. * Unless required by applicable law or agreed to in writing, software
  11606. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11607. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11608. * See the License for the specific language governing permissions and
  11609. * limitations under the License.
  11610. *
  11611. * This file is part of mbed TLS (https://tls.mbed.org)
  11612. */
  11613. #ifndef MBEDTLS_X509_CSR_H
  11614. #define MBEDTLS_X509_CSR_H
  11615. #if !defined(MBEDTLS_CONFIG_FILE)
  11616. #else
  11617. #endif
  11618. #ifdef __cplusplus
  11619. extern "C" {
  11620. #endif
  11621. /**
  11622. * \addtogroup x509_module
  11623. * \{ */
  11624. /**
  11625. * \name Structures and functions for X.509 Certificate Signing Requests (CSR)
  11626. * \{
  11627. */
  11628. /**
  11629. * Certificate Signing Request (CSR) structure.
  11630. */
  11631. typedef struct mbedtls_x509_csr
  11632. {
  11633. mbedtls_x509_buf raw; /**< The raw CSR data (DER). */
  11634. mbedtls_x509_buf cri; /**< The raw CertificateRequestInfo body (DER). */
  11635. int version; /**< CSR version (1=v1). */
  11636. mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). */
  11637. mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
  11638. mbedtls_pk_context pk; /**< Container for the public key context. */
  11639. mbedtls_x509_buf sig_oid;
  11640. mbedtls_x509_buf sig;
  11641. mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
  11642. mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
  11643. void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
  11644. }
  11645. mbedtls_x509_csr;
  11646. /**
  11647. * Container for writing a CSR
  11648. */
  11649. typedef struct mbedtls_x509write_csr
  11650. {
  11651. mbedtls_pk_context *key;
  11652. mbedtls_asn1_named_data *subject;
  11653. mbedtls_md_type_t md_alg;
  11654. mbedtls_asn1_named_data *extensions;
  11655. }
  11656. mbedtls_x509write_csr;
  11657. #if defined(MBEDTLS_X509_CSR_PARSE_C)
  11658. /**
  11659. * \brief Load a Certificate Signing Request (CSR) in DER format
  11660. *
  11661. * \note CSR attributes (if any) are currently silently ignored.
  11662. *
  11663. * \param csr CSR context to fill
  11664. * \param buf buffer holding the CRL data
  11665. * \param buflen size of the buffer
  11666. *
  11667. * \return 0 if successful, or a specific X509 error code
  11668. */
  11669. int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
  11670. const unsigned char *buf, size_t buflen );
  11671. /**
  11672. * \brief Load a Certificate Signing Request (CSR), DER or PEM format
  11673. *
  11674. * \note See notes for \c mbedtls_x509_csr_parse_der()
  11675. *
  11676. * \param csr CSR context to fill
  11677. * \param buf buffer holding the CRL data
  11678. * \param buflen size of the buffer
  11679. * (including the terminating null byte for PEM data)
  11680. *
  11681. * \return 0 if successful, or a specific X509 or PEM error code
  11682. */
  11683. int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, size_t buflen );
  11684. #if defined(MBEDTLS_FS_IO)
  11685. /**
  11686. * \brief Load a Certificate Signing Request (CSR)
  11687. *
  11688. * \note See notes for \c mbedtls_x509_csr_parse()
  11689. *
  11690. * \param csr CSR context to fill
  11691. * \param path filename to read the CSR from
  11692. *
  11693. * \return 0 if successful, or a specific X509 or PEM error code
  11694. */
  11695. int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path );
  11696. #endif /* MBEDTLS_FS_IO */
  11697. /**
  11698. * \brief Returns an informational string about the
  11699. * CSR.
  11700. *
  11701. * \param buf Buffer to write to
  11702. * \param size Maximum size of buffer
  11703. * \param prefix A line prefix
  11704. * \param csr The X509 CSR to represent
  11705. *
  11706. * \return The length of the string written (not including the
  11707. * terminated nul byte), or a negative error code.
  11708. */
  11709. int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
  11710. const mbedtls_x509_csr *csr );
  11711. /**
  11712. * \brief Initialize a CSR
  11713. *
  11714. * \param csr CSR to initialize
  11715. */
  11716. void mbedtls_x509_csr_init( mbedtls_x509_csr *csr );
  11717. /**
  11718. * \brief Unallocate all CSR data
  11719. *
  11720. * \param csr CSR to free
  11721. */
  11722. void mbedtls_x509_csr_free( mbedtls_x509_csr *csr );
  11723. #endif /* MBEDTLS_X509_CSR_PARSE_C */
  11724. /* \} name */
  11725. /* \} addtogroup x509_module */
  11726. #if defined(MBEDTLS_X509_CSR_WRITE_C)
  11727. /**
  11728. * \brief Initialize a CSR context
  11729. *
  11730. * \param ctx CSR context to initialize
  11731. */
  11732. void mbedtls_x509write_csr_init( mbedtls_x509write_csr *ctx );
  11733. /**
  11734. * \brief Set the subject name for a CSR
  11735. * Subject names should contain a comma-separated list
  11736. * of OID types and values:
  11737. * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
  11738. *
  11739. * \param ctx CSR context to use
  11740. * \param subject_name subject name to set
  11741. *
  11742. * \return 0 if subject name was parsed successfully, or
  11743. * a specific error code
  11744. */
  11745. int mbedtls_x509write_csr_set_subject_name( mbedtls_x509write_csr *ctx,
  11746. const char *subject_name );
  11747. /**
  11748. * \brief Set the key for a CSR (public key will be included,
  11749. * private key used to sign the CSR when writing it)
  11750. *
  11751. * \param ctx CSR context to use
  11752. * \param key Asymetric key to include
  11753. */
  11754. void mbedtls_x509write_csr_set_key( mbedtls_x509write_csr *ctx, mbedtls_pk_context *key );
  11755. /**
  11756. * \brief Set the MD algorithm to use for the signature
  11757. * (e.g. MBEDTLS_MD_SHA1)
  11758. *
  11759. * \param ctx CSR context to use
  11760. * \param md_alg MD algorithm to use
  11761. */
  11762. void mbedtls_x509write_csr_set_md_alg( mbedtls_x509write_csr *ctx, mbedtls_md_type_t md_alg );
  11763. /**
  11764. * \brief Set the Key Usage Extension flags
  11765. * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
  11766. *
  11767. * \param ctx CSR context to use
  11768. * \param key_usage key usage flags to set
  11769. *
  11770. * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
  11771. */
  11772. int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage );
  11773. /**
  11774. * \brief Set the Netscape Cert Type flags
  11775. * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
  11776. *
  11777. * \param ctx CSR context to use
  11778. * \param ns_cert_type Netscape Cert Type flags to set
  11779. *
  11780. * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
  11781. */
  11782. int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx,
  11783. unsigned char ns_cert_type );
  11784. /**
  11785. * \brief Generic function to add to or replace an extension in the
  11786. * CSR
  11787. *
  11788. * \param ctx CSR context to use
  11789. * \param oid OID of the extension
  11790. * \param oid_len length of the OID
  11791. * \param val value of the extension OCTET STRING
  11792. * \param val_len length of the value data
  11793. *
  11794. * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
  11795. */
  11796. int mbedtls_x509write_csr_set_extension( mbedtls_x509write_csr *ctx,
  11797. const char *oid, size_t oid_len,
  11798. const unsigned char *val, size_t val_len );
  11799. /**
  11800. * \brief Free the contents of a CSR context
  11801. *
  11802. * \param ctx CSR context to free
  11803. */
  11804. void mbedtls_x509write_csr_free( mbedtls_x509write_csr *ctx );
  11805. /**
  11806. * \brief Write a CSR (Certificate Signing Request) to a
  11807. * DER structure
  11808. * Note: data is written at the end of the buffer! Use the
  11809. * return value to determine where you should start
  11810. * using the buffer
  11811. *
  11812. * \param ctx CSR to write away
  11813. * \param buf buffer to write to
  11814. * \param size size of the buffer
  11815. * \param f_rng RNG function (for signature, see note)
  11816. * \param p_rng RNG parameter
  11817. *
  11818. * \return length of data written if successful, or a specific
  11819. * error code
  11820. *
  11821. * \note f_rng may be NULL if RSA is used for signature and the
  11822. * signature is made offline (otherwise f_rng is desirable
  11823. * for countermeasures against timing attacks).
  11824. * ECDSA signatures always require a non-NULL f_rng.
  11825. */
  11826. int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
  11827. int (*f_rng)(void *, unsigned char *, size_t),
  11828. void *p_rng );
  11829. #if defined(MBEDTLS_PEM_WRITE_C)
  11830. /**
  11831. * \brief Write a CSR (Certificate Signing Request) to a
  11832. * PEM string
  11833. *
  11834. * \param ctx CSR to write away
  11835. * \param buf buffer to write to
  11836. * \param size size of the buffer
  11837. * \param f_rng RNG function (for signature, see note)
  11838. * \param p_rng RNG parameter
  11839. *
  11840. * \return 0 if successful, or a specific error code
  11841. *
  11842. * \note f_rng may be NULL if RSA is used for signature and the
  11843. * signature is made offline (otherwise f_rng is desirable
  11844. * for countermeasures against timing attacks).
  11845. * ECDSA signatures always require a non-NULL f_rng.
  11846. */
  11847. int mbedtls_x509write_csr_pem( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
  11848. int (*f_rng)(void *, unsigned char *, size_t),
  11849. void *p_rng );
  11850. #endif /* MBEDTLS_PEM_WRITE_C */
  11851. #endif /* MBEDTLS_X509_CSR_WRITE_C */
  11852. #ifdef __cplusplus
  11853. }
  11854. #endif
  11855. #endif /* mbedtls_x509_csr.h */
  11856. /********* Start of file include/mbedtls/cipher.h ************/
  11857. /**
  11858. * \file cipher.h
  11859. *
  11860. * \brief The generic cipher wrapper.
  11861. *
  11862. * \author Adriaan de Jong <dejong@fox-it.com>
  11863. */
  11864. /*
  11865. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  11866. * SPDX-License-Identifier: Apache-2.0
  11867. *
  11868. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  11869. * not use this file except in compliance with the License.
  11870. * You may obtain a copy of the License at
  11871. *
  11872. * http://www.apache.org/licenses/LICENSE-2.0
  11873. *
  11874. * Unless required by applicable law or agreed to in writing, software
  11875. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11876. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11877. * See the License for the specific language governing permissions and
  11878. * limitations under the License.
  11879. *
  11880. * This file is part of Mbed TLS (https://tls.mbed.org)
  11881. */
  11882. #ifndef MBEDTLS_CIPHER_H
  11883. #define MBEDTLS_CIPHER_H
  11884. #if !defined(MBEDTLS_CONFIG_FILE)
  11885. #else
  11886. #endif
  11887. #include <stddef.h>
  11888. #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C)
  11889. #define MBEDTLS_CIPHER_MODE_AEAD
  11890. #endif
  11891. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  11892. #define MBEDTLS_CIPHER_MODE_WITH_PADDING
  11893. #endif
  11894. #if defined(MBEDTLS_ARC4_C)
  11895. #define MBEDTLS_CIPHER_MODE_STREAM
  11896. #endif
  11897. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  11898. !defined(inline) && !defined(__cplusplus)
  11899. #define inline __inline
  11900. #endif
  11901. #define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 /**< The selected feature is not available. */
  11902. #define MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA -0x6100 /**< Bad input parameters. */
  11903. #define MBEDTLS_ERR_CIPHER_ALLOC_FAILED -0x6180 /**< Failed to allocate memory. */
  11904. #define MBEDTLS_ERR_CIPHER_INVALID_PADDING -0x6200 /**< Input data contains invalid padding and is rejected. */
  11905. #define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 /**< Decryption of block requires a full block. */
  11906. #define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 /**< Authentication failed (for AEAD modes). */
  11907. #define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 /**< The context is invalid. For example, because it was freed. */
  11908. #define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400 /**< Cipher hardware accelerator failed. */
  11909. #define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 /**< Cipher accepts IVs of variable length. */
  11910. #define MBEDTLS_CIPHER_VARIABLE_KEY_LEN 0x02 /**< Cipher accepts keys of variable length. */
  11911. #ifdef __cplusplus
  11912. extern "C" {
  11913. #endif
  11914. /**
  11915. * \brief An enumeration of supported ciphers.
  11916. *
  11917. * \warning ARC4 and DES are considered weak ciphers and their use
  11918. * constitutes a security risk. We recommend considering stronger
  11919. * ciphers instead.
  11920. */
  11921. typedef enum {
  11922. MBEDTLS_CIPHER_ID_NONE = 0,
  11923. MBEDTLS_CIPHER_ID_NULL,
  11924. MBEDTLS_CIPHER_ID_AES,
  11925. MBEDTLS_CIPHER_ID_DES,
  11926. MBEDTLS_CIPHER_ID_3DES,
  11927. MBEDTLS_CIPHER_ID_CAMELLIA,
  11928. MBEDTLS_CIPHER_ID_BLOWFISH,
  11929. MBEDTLS_CIPHER_ID_ARC4,
  11930. } mbedtls_cipher_id_t;
  11931. /**
  11932. * \brief An enumeration of supported (cipher, mode) pairs.
  11933. *
  11934. * \warning ARC4 and DES are considered weak ciphers and their use
  11935. * constitutes a security risk. We recommend considering stronger
  11936. * ciphers instead.
  11937. */
  11938. typedef enum {
  11939. MBEDTLS_CIPHER_NONE = 0,
  11940. MBEDTLS_CIPHER_NULL,
  11941. MBEDTLS_CIPHER_AES_128_ECB,
  11942. MBEDTLS_CIPHER_AES_192_ECB,
  11943. MBEDTLS_CIPHER_AES_256_ECB,
  11944. MBEDTLS_CIPHER_AES_128_CBC,
  11945. MBEDTLS_CIPHER_AES_192_CBC,
  11946. MBEDTLS_CIPHER_AES_256_CBC,
  11947. MBEDTLS_CIPHER_AES_128_CFB128,
  11948. MBEDTLS_CIPHER_AES_192_CFB128,
  11949. MBEDTLS_CIPHER_AES_256_CFB128,
  11950. MBEDTLS_CIPHER_AES_128_CTR,
  11951. MBEDTLS_CIPHER_AES_192_CTR,
  11952. MBEDTLS_CIPHER_AES_256_CTR,
  11953. MBEDTLS_CIPHER_AES_128_GCM,
  11954. MBEDTLS_CIPHER_AES_192_GCM,
  11955. MBEDTLS_CIPHER_AES_256_GCM,
  11956. MBEDTLS_CIPHER_CAMELLIA_128_ECB,
  11957. MBEDTLS_CIPHER_CAMELLIA_192_ECB,
  11958. MBEDTLS_CIPHER_CAMELLIA_256_ECB,
  11959. MBEDTLS_CIPHER_CAMELLIA_128_CBC,
  11960. MBEDTLS_CIPHER_CAMELLIA_192_CBC,
  11961. MBEDTLS_CIPHER_CAMELLIA_256_CBC,
  11962. MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
  11963. MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
  11964. MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
  11965. MBEDTLS_CIPHER_CAMELLIA_128_CTR,
  11966. MBEDTLS_CIPHER_CAMELLIA_192_CTR,
  11967. MBEDTLS_CIPHER_CAMELLIA_256_CTR,
  11968. MBEDTLS_CIPHER_CAMELLIA_128_GCM,
  11969. MBEDTLS_CIPHER_CAMELLIA_192_GCM,
  11970. MBEDTLS_CIPHER_CAMELLIA_256_GCM,
  11971. MBEDTLS_CIPHER_DES_ECB,
  11972. MBEDTLS_CIPHER_DES_CBC,
  11973. MBEDTLS_CIPHER_DES_EDE_ECB,
  11974. MBEDTLS_CIPHER_DES_EDE_CBC,
  11975. MBEDTLS_CIPHER_DES_EDE3_ECB,
  11976. MBEDTLS_CIPHER_DES_EDE3_CBC,
  11977. MBEDTLS_CIPHER_BLOWFISH_ECB,
  11978. MBEDTLS_CIPHER_BLOWFISH_CBC,
  11979. MBEDTLS_CIPHER_BLOWFISH_CFB64,
  11980. MBEDTLS_CIPHER_BLOWFISH_CTR,
  11981. MBEDTLS_CIPHER_ARC4_128,
  11982. MBEDTLS_CIPHER_AES_128_CCM,
  11983. MBEDTLS_CIPHER_AES_192_CCM,
  11984. MBEDTLS_CIPHER_AES_256_CCM,
  11985. MBEDTLS_CIPHER_CAMELLIA_128_CCM,
  11986. MBEDTLS_CIPHER_CAMELLIA_192_CCM,
  11987. MBEDTLS_CIPHER_CAMELLIA_256_CCM,
  11988. } mbedtls_cipher_type_t;
  11989. /** Supported cipher modes. */
  11990. typedef enum {
  11991. MBEDTLS_MODE_NONE = 0,
  11992. MBEDTLS_MODE_ECB,
  11993. MBEDTLS_MODE_CBC,
  11994. MBEDTLS_MODE_CFB,
  11995. MBEDTLS_MODE_OFB, /* Unused! */
  11996. MBEDTLS_MODE_CTR,
  11997. MBEDTLS_MODE_GCM,
  11998. MBEDTLS_MODE_STREAM,
  11999. MBEDTLS_MODE_CCM,
  12000. } mbedtls_cipher_mode_t;
  12001. /** Supported cipher padding types. */
  12002. typedef enum {
  12003. MBEDTLS_PADDING_PKCS7 = 0, /**< PKCS7 padding (default). */
  12004. MBEDTLS_PADDING_ONE_AND_ZEROS, /**< ISO/IEC 7816-4 padding. */
  12005. MBEDTLS_PADDING_ZEROS_AND_LEN, /**< ANSI X.923 padding. */
  12006. MBEDTLS_PADDING_ZEROS, /**< zero padding (not reversible). */
  12007. MBEDTLS_PADDING_NONE, /**< never pad (full blocks only). */
  12008. } mbedtls_cipher_padding_t;
  12009. /** Type of operation. */
  12010. typedef enum {
  12011. MBEDTLS_OPERATION_NONE = -1,
  12012. MBEDTLS_DECRYPT = 0,
  12013. MBEDTLS_ENCRYPT,
  12014. } mbedtls_operation_t;
  12015. enum {
  12016. /** Undefined key length. */
  12017. MBEDTLS_KEY_LENGTH_NONE = 0,
  12018. /** Key length, in bits (including parity), for DES keys. */
  12019. MBEDTLS_KEY_LENGTH_DES = 64,
  12020. /** Key length in bits, including parity, for DES in two-key EDE. */
  12021. MBEDTLS_KEY_LENGTH_DES_EDE = 128,
  12022. /** Key length in bits, including parity, for DES in three-key EDE. */
  12023. MBEDTLS_KEY_LENGTH_DES_EDE3 = 192,
  12024. };
  12025. /** Maximum length of any IV, in Bytes. */
  12026. #define MBEDTLS_MAX_IV_LENGTH 16
  12027. /** Maximum block size of any cipher, in Bytes. */
  12028. #define MBEDTLS_MAX_BLOCK_LENGTH 16
  12029. /**
  12030. * Base cipher information (opaque struct).
  12031. */
  12032. typedef struct mbedtls_cipher_base_t mbedtls_cipher_base_t;
  12033. /**
  12034. * CMAC context (opaque struct).
  12035. */
  12036. typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t;
  12037. /**
  12038. * Cipher information. Allows calling cipher functions
  12039. * in a generic way.
  12040. */
  12041. typedef struct {
  12042. /** Full cipher identifier. For example,
  12043. * MBEDTLS_CIPHER_AES_256_CBC.
  12044. */
  12045. mbedtls_cipher_type_t type;
  12046. /** The cipher mode. For example, MBEDTLS_MODE_CBC. */
  12047. mbedtls_cipher_mode_t mode;
  12048. /** The cipher key length, in bits. This is the
  12049. * default length for variable sized ciphers.
  12050. * Includes parity bits for ciphers like DES.
  12051. */
  12052. unsigned int key_bitlen;
  12053. /** Name of the cipher. */
  12054. const char * name;
  12055. /** IV or nonce size, in Bytes.
  12056. * For ciphers that accept variable IV sizes,
  12057. * this is the recommended size.
  12058. */
  12059. unsigned int iv_size;
  12060. /** Flags to set. For example, if the cipher supports variable IV sizes or variable key sizes. */
  12061. int flags;
  12062. /** The block size, in Bytes. */
  12063. unsigned int block_size;
  12064. /** Struct for base cipher information and functions. */
  12065. const mbedtls_cipher_base_t *base;
  12066. } mbedtls_cipher_info_t;
  12067. /**
  12068. * Generic cipher context.
  12069. */
  12070. typedef struct {
  12071. /** Information about the associated cipher. */
  12072. const mbedtls_cipher_info_t *cipher_info;
  12073. /** Key length to use. */
  12074. int key_bitlen;
  12075. /** Operation that the key of the context has been
  12076. * initialized for.
  12077. */
  12078. mbedtls_operation_t operation;
  12079. #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
  12080. /** Padding functions to use, if relevant for
  12081. * the specific cipher mode.
  12082. */
  12083. void (*add_padding)( unsigned char *output, size_t olen, size_t data_len );
  12084. int (*get_padding)( unsigned char *input, size_t ilen, size_t *data_len );
  12085. #endif
  12086. /** Buffer for input that has not been processed yet. */
  12087. unsigned char unprocessed_data[MBEDTLS_MAX_BLOCK_LENGTH];
  12088. /** Number of Bytes that have not been processed yet. */
  12089. size_t unprocessed_len;
  12090. /** Current IV or NONCE_COUNTER for CTR-mode. */
  12091. unsigned char iv[MBEDTLS_MAX_IV_LENGTH];
  12092. /** IV size in Bytes, for ciphers with variable-length IVs. */
  12093. size_t iv_size;
  12094. /** The cipher-specific context. */
  12095. void *cipher_ctx;
  12096. #if defined(MBEDTLS_CMAC_C)
  12097. /** CMAC-specific context. */
  12098. mbedtls_cmac_context_t *cmac_ctx;
  12099. #endif
  12100. } mbedtls_cipher_context_t;
  12101. /**
  12102. * \brief This function retrieves the list of ciphers supported by the generic
  12103. * cipher module.
  12104. *
  12105. * \return A statically-allocated array of ciphers. The last entry
  12106. * is zero.
  12107. */
  12108. const int *mbedtls_cipher_list( void );
  12109. /**
  12110. * \brief This function retrieves the cipher-information
  12111. * structure associated with the given cipher name.
  12112. *
  12113. * \param cipher_name Name of the cipher to search for.
  12114. *
  12115. * \return The cipher information structure associated with the
  12116. * given \p cipher_name, or NULL if not found.
  12117. */
  12118. const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name );
  12119. /**
  12120. * \brief This function retrieves the cipher-information
  12121. * structure associated with the given cipher type.
  12122. *
  12123. * \param cipher_type Type of the cipher to search for.
  12124. *
  12125. * \return The cipher information structure associated with the
  12126. * given \p cipher_type, or NULL if not found.
  12127. */
  12128. const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type );
  12129. /**
  12130. * \brief This function retrieves the cipher-information
  12131. * structure associated with the given cipher ID,
  12132. * key size and mode.
  12133. *
  12134. * \param cipher_id The ID of the cipher to search for. For example,
  12135. * #MBEDTLS_CIPHER_ID_AES.
  12136. * \param key_bitlen The length of the key in bits.
  12137. * \param mode The cipher mode. For example, #MBEDTLS_MODE_CBC.
  12138. *
  12139. * \return The cipher information structure associated with the
  12140. * given \p cipher_id, or NULL if not found.
  12141. */
  12142. const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id,
  12143. int key_bitlen,
  12144. const mbedtls_cipher_mode_t mode );
  12145. /**
  12146. * \brief This function initializes a \p cipher_context as NONE.
  12147. */
  12148. void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx );
  12149. /**
  12150. * \brief This function frees and clears the cipher-specific
  12151. * context of \p ctx. Freeing \p ctx itself remains the
  12152. * responsibility of the caller.
  12153. */
  12154. void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx );
  12155. /**
  12156. * \brief This function initializes and fills the cipher-context
  12157. * structure with the appropriate values. It also clears
  12158. * the structure.
  12159. *
  12160. * \param ctx The context to initialize. May not be NULL.
  12161. * \param cipher_info The cipher to use.
  12162. *
  12163. * \return \c 0 on success,
  12164. * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on parameter failure,
  12165. * #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the
  12166. * cipher-specific context failed.
  12167. *
  12168. * \internal Currently, the function also clears the structure.
  12169. * In future versions, the caller will be required to call
  12170. * mbedtls_cipher_init() on the structure first.
  12171. */
  12172. int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info );
  12173. /**
  12174. * \brief This function returns the block size of the given cipher.
  12175. *
  12176. * \param ctx The context of the cipher. Must be initialized.
  12177. *
  12178. * \return The size of the blocks of the cipher, or zero if \p ctx
  12179. * has not been initialized.
  12180. */
  12181. static inline unsigned int mbedtls_cipher_get_block_size( const mbedtls_cipher_context_t *ctx )
  12182. {
  12183. if( NULL == ctx || NULL == ctx->cipher_info )
  12184. return 0;
  12185. return ctx->cipher_info->block_size;
  12186. }
  12187. /**
  12188. * \brief This function returns the mode of operation for
  12189. * the cipher. For example, MBEDTLS_MODE_CBC.
  12190. *
  12191. * \param ctx The context of the cipher. Must be initialized.
  12192. *
  12193. * \return The mode of operation, or #MBEDTLS_MODE_NONE if
  12194. * \p ctx has not been initialized.
  12195. */
  12196. static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( const mbedtls_cipher_context_t *ctx )
  12197. {
  12198. if( NULL == ctx || NULL == ctx->cipher_info )
  12199. return MBEDTLS_MODE_NONE;
  12200. return ctx->cipher_info->mode;
  12201. }
  12202. /**
  12203. * \brief This function returns the size of the IV or nonce
  12204. * of the cipher, in Bytes.
  12205. *
  12206. * \param ctx The context of the cipher. Must be initialized.
  12207. *
  12208. * \return <ul><li>If no IV has been set: the recommended IV size.
  12209. * 0 for ciphers not using IV or nonce.</li>
  12210. * <li>If IV has already been set: the actual size.</li></ul>
  12211. */
  12212. static inline int mbedtls_cipher_get_iv_size( const mbedtls_cipher_context_t *ctx )
  12213. {
  12214. if( NULL == ctx || NULL == ctx->cipher_info )
  12215. return 0;
  12216. if( ctx->iv_size != 0 )
  12217. return (int) ctx->iv_size;
  12218. return (int) ctx->cipher_info->iv_size;
  12219. }
  12220. /**
  12221. * \brief This function returns the type of the given cipher.
  12222. *
  12223. * \param ctx The context of the cipher. Must be initialized.
  12224. *
  12225. * \return The type of the cipher, or #MBEDTLS_CIPHER_NONE if
  12226. * \p ctx has not been initialized.
  12227. */
  12228. static inline mbedtls_cipher_type_t mbedtls_cipher_get_type( const mbedtls_cipher_context_t *ctx )
  12229. {
  12230. if( NULL == ctx || NULL == ctx->cipher_info )
  12231. return MBEDTLS_CIPHER_NONE;
  12232. return ctx->cipher_info->type;
  12233. }
  12234. /**
  12235. * \brief This function returns the name of the given cipher
  12236. * as a string.
  12237. *
  12238. * \param ctx The context of the cipher. Must be initialized.
  12239. *
  12240. * \return The name of the cipher, or NULL if \p ctx has not
  12241. * been not initialized.
  12242. */
  12243. static inline const char *mbedtls_cipher_get_name( const mbedtls_cipher_context_t *ctx )
  12244. {
  12245. if( NULL == ctx || NULL == ctx->cipher_info )
  12246. return 0;
  12247. return ctx->cipher_info->name;
  12248. }
  12249. /**
  12250. * \brief This function returns the key length of the cipher.
  12251. *
  12252. * \param ctx The context of the cipher. Must be initialized.
  12253. *
  12254. * \return The key length of the cipher in bits, or
  12255. * #MBEDTLS_KEY_LENGTH_NONE if ctx \p has not been
  12256. * initialized.
  12257. */
  12258. static inline int mbedtls_cipher_get_key_bitlen( const mbedtls_cipher_context_t *ctx )
  12259. {
  12260. if( NULL == ctx || NULL == ctx->cipher_info )
  12261. return MBEDTLS_KEY_LENGTH_NONE;
  12262. return (int) ctx->cipher_info->key_bitlen;
  12263. }
  12264. /**
  12265. * \brief This function returns the operation of the given cipher.
  12266. *
  12267. * \param ctx The context of the cipher. Must be initialized.
  12268. *
  12269. * \return The type of operation: #MBEDTLS_ENCRYPT or
  12270. * #MBEDTLS_DECRYPT, or #MBEDTLS_OPERATION_NONE if \p ctx
  12271. * has not been initialized.
  12272. */
  12273. static inline mbedtls_operation_t mbedtls_cipher_get_operation( const mbedtls_cipher_context_t *ctx )
  12274. {
  12275. if( NULL == ctx || NULL == ctx->cipher_info )
  12276. return MBEDTLS_OPERATION_NONE;
  12277. return ctx->operation;
  12278. }
  12279. /**
  12280. * \brief This function sets the key to use with the given context.
  12281. *
  12282. * \param ctx The generic cipher context. May not be NULL. Must have
  12283. * been initialized using mbedtls_cipher_info_from_type()
  12284. * or mbedtls_cipher_info_from_string().
  12285. * \param key The key to use.
  12286. * \param key_bitlen The key length to use, in bits.
  12287. * \param operation The operation that the key will be used for:
  12288. * #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT.
  12289. *
  12290. * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if
  12291. * parameter verification fails, or a cipher-specific
  12292. * error code.
  12293. */
  12294. int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *key,
  12295. int key_bitlen, const mbedtls_operation_t operation );
  12296. #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
  12297. /**
  12298. * \brief This function sets the padding mode, for cipher modes
  12299. * that use padding.
  12300. *
  12301. * The default passing mode is PKCS7 padding.
  12302. *
  12303. * \param ctx The generic cipher context.
  12304. * \param mode The padding mode.
  12305. *
  12306. * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
  12307. * if the selected padding mode is not supported, or
  12308. * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode
  12309. * does not support padding.
  12310. */
  12311. int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, mbedtls_cipher_padding_t mode );
  12312. #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
  12313. /**
  12314. * \brief This function sets the initialization vector (IV)
  12315. * or nonce.
  12316. *
  12317. * \param ctx The generic cipher context.
  12318. * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
  12319. * \param iv_len The IV length for ciphers with variable-size IV.
  12320. * This parameter is discarded by ciphers with fixed-size IV.
  12321. *
  12322. * \returns \c 0 on success, or #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA
  12323. *
  12324. * \note Some ciphers do not use IVs nor nonce. For these
  12325. * ciphers, this function has no effect.
  12326. */
  12327. int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
  12328. const unsigned char *iv, size_t iv_len );
  12329. /**
  12330. * \brief This function resets the cipher state.
  12331. *
  12332. * \param ctx The generic cipher context.
  12333. *
  12334. * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA
  12335. * if parameter verification fails.
  12336. */
  12337. int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx );
  12338. #if defined(MBEDTLS_GCM_C)
  12339. /**
  12340. * \brief This function adds additional data for AEAD ciphers.
  12341. * Only supported with GCM. Must be called
  12342. * exactly once, after mbedtls_cipher_reset().
  12343. *
  12344. * \param ctx The generic cipher context.
  12345. * \param ad The additional data to use.
  12346. * \param ad_len the Length of \p ad.
  12347. *
  12348. * \return \c 0 on success, or a specific error code on failure.
  12349. */
  12350. int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
  12351. const unsigned char *ad, size_t ad_len );
  12352. #endif /* MBEDTLS_GCM_C */
  12353. /**
  12354. * \brief The generic cipher update function. It encrypts or
  12355. * decrypts using the given cipher context. Writes as
  12356. * many block-sized blocks of data as possible to output.
  12357. * Any data that cannot be written immediately is either
  12358. * added to the next block, or flushed when
  12359. * mbedtls_cipher_finish() is called.
  12360. * Exception: For MBEDTLS_MODE_ECB, expects a single block
  12361. * in size. For example, 16 Bytes for AES.
  12362. *
  12363. * \param ctx The generic cipher context.
  12364. * \param input The buffer holding the input data.
  12365. * \param ilen The length of the input data.
  12366. * \param output The buffer for the output data. Must be able to hold at
  12367. * least \p ilen + block_size. Must not be the same buffer
  12368. * as input.
  12369. * \param olen The length of the output data, to be updated with the
  12370. * actual number of Bytes written.
  12371. *
  12372. * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if
  12373. * parameter verification fails,
  12374. * #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE on an
  12375. * unsupported mode for a cipher, or a cipher-specific
  12376. * error code.
  12377. *
  12378. * \note If the underlying cipher is GCM, all calls to this
  12379. * function, except the last one before
  12380. * mbedtls_cipher_finish(). Must have \p ilen as a
  12381. * multiple of the block_size.
  12382. */
  12383. int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input,
  12384. size_t ilen, unsigned char *output, size_t *olen );
  12385. /**
  12386. * \brief The generic cipher finalization function. If data still
  12387. * needs to be flushed from an incomplete block, the data
  12388. * contained in it is padded to the size of
  12389. * the last block, and written to the \p output buffer.
  12390. *
  12391. * \param ctx The generic cipher context.
  12392. * \param output The buffer to write data to. Needs block_size available.
  12393. * \param olen The length of the data written to the \p output buffer.
  12394. *
  12395. * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if
  12396. * parameter verification fails,
  12397. * #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED if decryption
  12398. * expected a full block but was not provided one,
  12399. * #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
  12400. * while decrypting, or a cipher-specific error code
  12401. * on failure for any other reason.
  12402. */
  12403. int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
  12404. unsigned char *output, size_t *olen );
  12405. #if defined(MBEDTLS_GCM_C)
  12406. /**
  12407. * \brief This function writes a tag for AEAD ciphers.
  12408. * Only supported with GCM.
  12409. * Must be called after mbedtls_cipher_finish().
  12410. *
  12411. * \param ctx The generic cipher context.
  12412. * \param tag The buffer to write the tag to.
  12413. * \param tag_len The length of the tag to write.
  12414. *
  12415. * \return \c 0 on success, or a specific error code on failure.
  12416. */
  12417. int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
  12418. unsigned char *tag, size_t tag_len );
  12419. /**
  12420. * \brief This function checks the tag for AEAD ciphers.
  12421. * Only supported with GCM.
  12422. * Must be called after mbedtls_cipher_finish().
  12423. *
  12424. * \param ctx The generic cipher context.
  12425. * \param tag The buffer holding the tag.
  12426. * \param tag_len The length of the tag to check.
  12427. *
  12428. * \return \c 0 on success, or a specific error code on failure.
  12429. */
  12430. int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
  12431. const unsigned char *tag, size_t tag_len );
  12432. #endif /* MBEDTLS_GCM_C */
  12433. /**
  12434. * \brief The generic all-in-one encryption/decryption function,
  12435. * for all ciphers except AEAD constructs.
  12436. *
  12437. * \param ctx The generic cipher context.
  12438. * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
  12439. * \param iv_len The IV length for ciphers with variable-size IV.
  12440. * This parameter is discarded by ciphers with fixed-size
  12441. * IV.
  12442. * \param input The buffer holding the input data.
  12443. * \param ilen The length of the input data.
  12444. * \param output The buffer for the output data. Must be able to hold at
  12445. * least \p ilen + block_size. Must not be the same buffer
  12446. * as input.
  12447. * \param olen The length of the output data, to be updated with the
  12448. * actual number of Bytes written.
  12449. *
  12450. * \note Some ciphers do not use IVs nor nonce. For these
  12451. * ciphers, use \p iv = NULL and \p iv_len = 0.
  12452. *
  12453. * \returns \c 0 on success, or
  12454. * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or
  12455. * #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED if decryption
  12456. * expected a full block but was not provided one, or
  12457. * #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding
  12458. * while decrypting, or a cipher-specific error code on
  12459. * failure for any other reason.
  12460. */
  12461. int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
  12462. const unsigned char *iv, size_t iv_len,
  12463. const unsigned char *input, size_t ilen,
  12464. unsigned char *output, size_t *olen );
  12465. #if defined(MBEDTLS_CIPHER_MODE_AEAD)
  12466. /**
  12467. * \brief The generic autenticated encryption (AEAD) function.
  12468. *
  12469. * \param ctx The generic cipher context.
  12470. * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
  12471. * \param iv_len The IV length for ciphers with variable-size IV.
  12472. * This parameter is discarded by ciphers with fixed-size IV.
  12473. * \param ad The additional data to authenticate.
  12474. * \param ad_len The length of \p ad.
  12475. * \param input The buffer holding the input data.
  12476. * \param ilen The length of the input data.
  12477. * \param output The buffer for the output data.
  12478. * Must be able to hold at least \p ilen.
  12479. * \param olen The length of the output data, to be updated with the
  12480. * actual number of Bytes written.
  12481. * \param tag The buffer for the authentication tag.
  12482. * \param tag_len The desired length of the authentication tag.
  12483. *
  12484. * \returns \c 0 on success, or
  12485. * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or
  12486. * a cipher-specific error code.
  12487. */
  12488. int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx,
  12489. const unsigned char *iv, size_t iv_len,
  12490. const unsigned char *ad, size_t ad_len,
  12491. const unsigned char *input, size_t ilen,
  12492. unsigned char *output, size_t *olen,
  12493. unsigned char *tag, size_t tag_len );
  12494. /**
  12495. * \brief The generic autenticated decryption (AEAD) function.
  12496. *
  12497. * \param ctx The generic cipher context.
  12498. * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers.
  12499. * \param iv_len The IV length for ciphers with variable-size IV.
  12500. * This parameter is discarded by ciphers with fixed-size IV.
  12501. * \param ad The additional data to be authenticated.
  12502. * \param ad_len The length of \p ad.
  12503. * \param input The buffer holding the input data.
  12504. * \param ilen The length of the input data.
  12505. * \param output The buffer for the output data.
  12506. * Must be able to hold at least \p ilen.
  12507. * \param olen The length of the output data, to be updated with the
  12508. * actual number of Bytes written.
  12509. * \param tag The buffer holding the authentication tag.
  12510. * \param tag_len The length of the authentication tag.
  12511. *
  12512. * \returns \c 0 on success, or
  12513. * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or
  12514. * #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic,
  12515. * or a cipher-specific error code on failure for any other reason.
  12516. *
  12517. * \note If the data is not authentic, then the output buffer
  12518. * is zeroed out to prevent the unauthentic plaintext being
  12519. * used, making this interface safer.
  12520. */
  12521. int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx,
  12522. const unsigned char *iv, size_t iv_len,
  12523. const unsigned char *ad, size_t ad_len,
  12524. const unsigned char *input, size_t ilen,
  12525. unsigned char *output, size_t *olen,
  12526. const unsigned char *tag, size_t tag_len );
  12527. #endif /* MBEDTLS_CIPHER_MODE_AEAD */
  12528. #ifdef __cplusplus
  12529. }
  12530. #endif
  12531. #endif /* MBEDTLS_CIPHER_H */
  12532. /********* Start of file include/mbedtls/cipher_internal.h ************/
  12533. /**
  12534. * \file cipher_internal.h
  12535. *
  12536. * \brief Cipher wrappers.
  12537. *
  12538. * \author Adriaan de Jong <dejong@fox-it.com>
  12539. */
  12540. /*
  12541. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  12542. * SPDX-License-Identifier: Apache-2.0
  12543. *
  12544. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  12545. * not use this file except in compliance with the License.
  12546. * You may obtain a copy of the License at
  12547. *
  12548. * http://www.apache.org/licenses/LICENSE-2.0
  12549. *
  12550. * Unless required by applicable law or agreed to in writing, software
  12551. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12552. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12553. * See the License for the specific language governing permissions and
  12554. * limitations under the License.
  12555. *
  12556. * This file is part of mbed TLS (https://tls.mbed.org)
  12557. */
  12558. #ifndef MBEDTLS_CIPHER_WRAP_H
  12559. #define MBEDTLS_CIPHER_WRAP_H
  12560. #if !defined(MBEDTLS_CONFIG_FILE)
  12561. #else
  12562. #endif
  12563. #ifdef __cplusplus
  12564. extern "C" {
  12565. #endif
  12566. /**
  12567. * Base cipher information. The non-mode specific functions and values.
  12568. */
  12569. struct mbedtls_cipher_base_t
  12570. {
  12571. /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
  12572. mbedtls_cipher_id_t cipher;
  12573. /** Encrypt using ECB */
  12574. int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
  12575. const unsigned char *input, unsigned char *output );
  12576. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  12577. /** Encrypt using CBC */
  12578. int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
  12579. unsigned char *iv, const unsigned char *input,
  12580. unsigned char *output );
  12581. #endif
  12582. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  12583. /** Encrypt using CFB (Full length) */
  12584. int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
  12585. unsigned char *iv, const unsigned char *input,
  12586. unsigned char *output );
  12587. #endif
  12588. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  12589. /** Encrypt using CTR */
  12590. int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
  12591. unsigned char *nonce_counter, unsigned char *stream_block,
  12592. const unsigned char *input, unsigned char *output );
  12593. #endif
  12594. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  12595. /** Encrypt using STREAM */
  12596. int (*stream_func)( void *ctx, size_t length,
  12597. const unsigned char *input, unsigned char *output );
  12598. #endif
  12599. /** Set key for encryption purposes */
  12600. int (*setkey_enc_func)( void *ctx, const unsigned char *key,
  12601. unsigned int key_bitlen );
  12602. /** Set key for decryption purposes */
  12603. int (*setkey_dec_func)( void *ctx, const unsigned char *key,
  12604. unsigned int key_bitlen);
  12605. /** Allocate a new context */
  12606. void * (*ctx_alloc_func)( void );
  12607. /** Free the given context */
  12608. void (*ctx_free_func)( void *ctx );
  12609. };
  12610. typedef struct
  12611. {
  12612. mbedtls_cipher_type_t type;
  12613. const mbedtls_cipher_info_t *info;
  12614. } mbedtls_cipher_definition_t;
  12615. extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
  12616. extern int mbedtls_cipher_supported[];
  12617. #ifdef __cplusplus
  12618. }
  12619. #endif
  12620. #endif /* MBEDTLS_CIPHER_WRAP_H */
  12621. /********* Start of file include/mbedtls/ssl_ciphersuites.h ************/
  12622. /**
  12623. * \file ssl_ciphersuites.h
  12624. *
  12625. * \brief SSL Ciphersuites for mbed TLS
  12626. */
  12627. /*
  12628. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  12629. * SPDX-License-Identifier: Apache-2.0
  12630. *
  12631. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  12632. * not use this file except in compliance with the License.
  12633. * You may obtain a copy of the License at
  12634. *
  12635. * http://www.apache.org/licenses/LICENSE-2.0
  12636. *
  12637. * Unless required by applicable law or agreed to in writing, software
  12638. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12639. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12640. * See the License for the specific language governing permissions and
  12641. * limitations under the License.
  12642. *
  12643. * This file is part of mbed TLS (https://tls.mbed.org)
  12644. */
  12645. #ifndef MBEDTLS_SSL_CIPHERSUITES_H
  12646. #define MBEDTLS_SSL_CIPHERSUITES_H
  12647. #ifdef __cplusplus
  12648. extern "C" {
  12649. #endif
  12650. /*
  12651. * Supported ciphersuites (Official IANA names)
  12652. */
  12653. #define MBEDTLS_TLS_RSA_WITH_NULL_MD5 0x01 /**< Weak! */
  12654. #define MBEDTLS_TLS_RSA_WITH_NULL_SHA 0x02 /**< Weak! */
  12655. #define MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 0x04
  12656. #define MBEDTLS_TLS_RSA_WITH_RC4_128_SHA 0x05
  12657. #define MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA 0x09 /**< Weak! Not in TLS 1.2 */
  12658. #define MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x0A
  12659. #define MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA 0x15 /**< Weak! Not in TLS 1.2 */
  12660. #define MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x16
  12661. #define MBEDTLS_TLS_PSK_WITH_NULL_SHA 0x2C /**< Weak! */
  12662. #define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA 0x2D /**< Weak! */
  12663. #define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA 0x2E /**< Weak! */
  12664. #define MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA 0x2F
  12665. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x33
  12666. #define MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA 0x35
  12667. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x39
  12668. #define MBEDTLS_TLS_RSA_WITH_NULL_SHA256 0x3B /**< Weak! */
  12669. #define MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 0x3C /**< TLS 1.2 */
  12670. #define MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 0x3D /**< TLS 1.2 */
  12671. #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA 0x41
  12672. #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x45
  12673. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 0x67 /**< TLS 1.2 */
  12674. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 0x6B /**< TLS 1.2 */
  12675. #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA 0x84
  12676. #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x88
  12677. #define MBEDTLS_TLS_PSK_WITH_RC4_128_SHA 0x8A
  12678. #define MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA 0x8B
  12679. #define MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA 0x8C
  12680. #define MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA 0x8D
  12681. #define MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA 0x8E
  12682. #define MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA 0x8F
  12683. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA 0x90
  12684. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA 0x91
  12685. #define MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA 0x92
  12686. #define MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA 0x93
  12687. #define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA 0x94
  12688. #define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA 0x95
  12689. #define MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 0x9C /**< TLS 1.2 */
  12690. #define MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 0x9D /**< TLS 1.2 */
  12691. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x9E /**< TLS 1.2 */
  12692. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x9F /**< TLS 1.2 */
  12693. #define MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 0xA8 /**< TLS 1.2 */
  12694. #define MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 0xA9 /**< TLS 1.2 */
  12695. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 0xAA /**< TLS 1.2 */
  12696. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 0xAB /**< TLS 1.2 */
  12697. #define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 0xAC /**< TLS 1.2 */
  12698. #define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 0xAD /**< TLS 1.2 */
  12699. #define MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 0xAE
  12700. #define MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 0xAF
  12701. #define MBEDTLS_TLS_PSK_WITH_NULL_SHA256 0xB0 /**< Weak! */
  12702. #define MBEDTLS_TLS_PSK_WITH_NULL_SHA384 0xB1 /**< Weak! */
  12703. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 0xB2
  12704. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 0xB3
  12705. #define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256 0xB4 /**< Weak! */
  12706. #define MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384 0xB5 /**< Weak! */
  12707. #define MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 0xB6
  12708. #define MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 0xB7
  12709. #define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256 0xB8 /**< Weak! */
  12710. #define MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384 0xB9 /**< Weak! */
  12711. #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBA /**< TLS 1.2 */
  12712. #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBE /**< TLS 1.2 */
  12713. #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC0 /**< TLS 1.2 */
  12714. #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC4 /**< TLS 1.2 */
  12715. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA 0xC001 /**< Weak! */
  12716. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA 0xC002 /**< Not in SSL3! */
  12717. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC003 /**< Not in SSL3! */
  12718. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0xC004 /**< Not in SSL3! */
  12719. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0xC005 /**< Not in SSL3! */
  12720. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA 0xC006 /**< Weak! */
  12721. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA 0xC007 /**< Not in SSL3! */
  12722. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC008 /**< Not in SSL3! */
  12723. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009 /**< Not in SSL3! */
  12724. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A /**< Not in SSL3! */
  12725. #define MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA 0xC00B /**< Weak! */
  12726. #define MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA 0xC00C /**< Not in SSL3! */
  12727. #define MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA 0xC00D /**< Not in SSL3! */
  12728. #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 0xC00E /**< Not in SSL3! */
  12729. #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 0xC00F /**< Not in SSL3! */
  12730. #define MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA 0xC010 /**< Weak! */
  12731. #define MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA 0xC011 /**< Not in SSL3! */
  12732. #define MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA 0xC012 /**< Not in SSL3! */
  12733. #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013 /**< Not in SSL3! */
  12734. #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014 /**< Not in SSL3! */
  12735. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023 /**< TLS 1.2 */
  12736. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024 /**< TLS 1.2 */
  12737. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 0xC025 /**< TLS 1.2 */
  12738. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 0xC026 /**< TLS 1.2 */
  12739. #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 0xC027 /**< TLS 1.2 */
  12740. #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 0xC028 /**< TLS 1.2 */
  12741. #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 0xC029 /**< TLS 1.2 */
  12742. #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 0xC02A /**< TLS 1.2 */
  12743. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B /**< TLS 1.2 */
  12744. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C /**< TLS 1.2 */
  12745. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0xC02D /**< TLS 1.2 */
  12746. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0xC02E /**< TLS 1.2 */
  12747. #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F /**< TLS 1.2 */
  12748. #define MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030 /**< TLS 1.2 */
  12749. #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 0xC031 /**< TLS 1.2 */
  12750. #define MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 0xC032 /**< TLS 1.2 */
  12751. #define MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA 0xC033 /**< Not in SSL3! */
  12752. #define MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA 0xC034 /**< Not in SSL3! */
  12753. #define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 0xC035 /**< Not in SSL3! */
  12754. #define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 0xC036 /**< Not in SSL3! */
  12755. #define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0xC037 /**< Not in SSL3! */
  12756. #define MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0xC038 /**< Not in SSL3! */
  12757. #define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA 0xC039 /**< Weak! No SSL3! */
  12758. #define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 0xC03A /**< Weak! No SSL3! */
  12759. #define MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 0xC03B /**< Weak! No SSL3! */
  12760. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC072 /**< Not in SSL3! */
  12761. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC073 /**< Not in SSL3! */
  12762. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC074 /**< Not in SSL3! */
  12763. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC075 /**< Not in SSL3! */
  12764. #define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC076 /**< Not in SSL3! */
  12765. #define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC077 /**< Not in SSL3! */
  12766. #define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC078 /**< Not in SSL3! */
  12767. #define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC079 /**< Not in SSL3! */
  12768. #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07A /**< TLS 1.2 */
  12769. #define MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07B /**< TLS 1.2 */
  12770. #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07C /**< TLS 1.2 */
  12771. #define MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07D /**< TLS 1.2 */
  12772. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC086 /**< TLS 1.2 */
  12773. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC087 /**< TLS 1.2 */
  12774. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC088 /**< TLS 1.2 */
  12775. #define MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC089 /**< TLS 1.2 */
  12776. #define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08A /**< TLS 1.2 */
  12777. #define MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08B /**< TLS 1.2 */
  12778. #define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08C /**< TLS 1.2 */
  12779. #define MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08D /**< TLS 1.2 */
  12780. #define MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC08E /**< TLS 1.2 */
  12781. #define MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC08F /**< TLS 1.2 */
  12782. #define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC090 /**< TLS 1.2 */
  12783. #define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC091 /**< TLS 1.2 */
  12784. #define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC092 /**< TLS 1.2 */
  12785. #define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC093 /**< TLS 1.2 */
  12786. #define MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC094
  12787. #define MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC095
  12788. #define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC096
  12789. #define MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC097
  12790. #define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC098
  12791. #define MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC099
  12792. #define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC09A /**< Not in SSL3! */
  12793. #define MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC09B /**< Not in SSL3! */
  12794. #define MBEDTLS_TLS_RSA_WITH_AES_128_CCM 0xC09C /**< TLS 1.2 */
  12795. #define MBEDTLS_TLS_RSA_WITH_AES_256_CCM 0xC09D /**< TLS 1.2 */
  12796. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM 0xC09E /**< TLS 1.2 */
  12797. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM 0xC09F /**< TLS 1.2 */
  12798. #define MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8 0xC0A0 /**< TLS 1.2 */
  12799. #define MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8 0xC0A1 /**< TLS 1.2 */
  12800. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8 0xC0A2 /**< TLS 1.2 */
  12801. #define MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8 0xC0A3 /**< TLS 1.2 */
  12802. #define MBEDTLS_TLS_PSK_WITH_AES_128_CCM 0xC0A4 /**< TLS 1.2 */
  12803. #define MBEDTLS_TLS_PSK_WITH_AES_256_CCM 0xC0A5 /**< TLS 1.2 */
  12804. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM 0xC0A6 /**< TLS 1.2 */
  12805. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM 0xC0A7 /**< TLS 1.2 */
  12806. #define MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8 0xC0A8 /**< TLS 1.2 */
  12807. #define MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8 0xC0A9 /**< TLS 1.2 */
  12808. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8 0xC0AA /**< TLS 1.2 */
  12809. #define MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8 0xC0AB /**< TLS 1.2 */
  12810. /* The last two are named with PSK_DHE in the RFC, which looks like a typo */
  12811. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM 0xC0AC /**< TLS 1.2 */
  12812. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM 0xC0AD /**< TLS 1.2 */
  12813. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 0xC0AE /**< TLS 1.2 */
  12814. #define MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 0xC0AF /**< TLS 1.2 */
  12815. #define MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 0xC0FF /**< experimental */
  12816. /* Reminder: update mbedtls_ssl_premaster_secret when adding a new key exchange.
  12817. * Reminder: update MBEDTLS_KEY_EXCHANGE__xxx below
  12818. */
  12819. typedef enum {
  12820. MBEDTLS_KEY_EXCHANGE_NONE = 0,
  12821. MBEDTLS_KEY_EXCHANGE_RSA,
  12822. MBEDTLS_KEY_EXCHANGE_DHE_RSA,
  12823. MBEDTLS_KEY_EXCHANGE_ECDHE_RSA,
  12824. MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA,
  12825. MBEDTLS_KEY_EXCHANGE_PSK,
  12826. MBEDTLS_KEY_EXCHANGE_DHE_PSK,
  12827. MBEDTLS_KEY_EXCHANGE_RSA_PSK,
  12828. MBEDTLS_KEY_EXCHANGE_ECDHE_PSK,
  12829. MBEDTLS_KEY_EXCHANGE_ECDH_RSA,
  12830. MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA,
  12831. MBEDTLS_KEY_EXCHANGE_ECJPAKE,
  12832. } mbedtls_key_exchange_type_t;
  12833. /* Key exchanges using a certificate */
  12834. #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
  12835. defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
  12836. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
  12837. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
  12838. defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
  12839. defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
  12840. defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
  12841. #define MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED
  12842. #endif
  12843. /* Key exchanges allowing client certificate requests */
  12844. #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
  12845. defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
  12846. defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
  12847. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
  12848. defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || \
  12849. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
  12850. #define MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED
  12851. #endif
  12852. /* Key exchanges involving server signature in ServerKeyExchange */
  12853. #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
  12854. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
  12855. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
  12856. #define MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED
  12857. #endif
  12858. /* Key exchanges using ECDH */
  12859. #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
  12860. defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
  12861. #define MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED
  12862. #endif
  12863. /* Key exchanges that don't involve ephemeral keys */
  12864. #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || \
  12865. defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
  12866. defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
  12867. defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED)
  12868. #define MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED
  12869. #endif
  12870. /* Key exchanges that involve ephemeral keys */
  12871. #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
  12872. defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
  12873. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
  12874. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) || \
  12875. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
  12876. defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
  12877. #define MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED
  12878. #endif
  12879. /* Key exchanges using a PSK */
  12880. #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
  12881. defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
  12882. defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
  12883. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
  12884. #define MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED
  12885. #endif
  12886. /* Key exchanges using DHE */
  12887. #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
  12888. defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
  12889. #define MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED
  12890. #endif
  12891. /* Key exchanges using ECDHE */
  12892. #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
  12893. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
  12894. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
  12895. #define MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED
  12896. #endif
  12897. typedef struct mbedtls_ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t;
  12898. #define MBEDTLS_CIPHERSUITE_WEAK 0x01 /**< Weak ciphersuite flag */
  12899. #define MBEDTLS_CIPHERSUITE_SHORT_TAG 0x02 /**< Short authentication tag,
  12900. eg for CCM_8 */
  12901. #define MBEDTLS_CIPHERSUITE_NODTLS 0x04 /**< Can't be used with DTLS */
  12902. /**
  12903. * \brief This structure is used for storing ciphersuite information
  12904. */
  12905. struct mbedtls_ssl_ciphersuite_t
  12906. {
  12907. int id;
  12908. const char * name;
  12909. mbedtls_cipher_type_t cipher;
  12910. mbedtls_md_type_t mac;
  12911. mbedtls_key_exchange_type_t key_exchange;
  12912. int min_major_ver;
  12913. int min_minor_ver;
  12914. int max_major_ver;
  12915. int max_minor_ver;
  12916. unsigned char flags;
  12917. };
  12918. const int *mbedtls_ssl_list_ciphersuites( void );
  12919. const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_string( const char *ciphersuite_name );
  12920. const mbedtls_ssl_ciphersuite_t *mbedtls_ssl_ciphersuite_from_id( int ciphersuite_id );
  12921. #if defined(MBEDTLS_PK_C)
  12922. mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_pk_alg( const mbedtls_ssl_ciphersuite_t *info );
  12923. mbedtls_pk_type_t mbedtls_ssl_get_ciphersuite_sig_alg( const mbedtls_ssl_ciphersuite_t *info );
  12924. #endif
  12925. int mbedtls_ssl_ciphersuite_uses_ec( const mbedtls_ssl_ciphersuite_t *info );
  12926. int mbedtls_ssl_ciphersuite_uses_psk( const mbedtls_ssl_ciphersuite_t *info );
  12927. #if defined(MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED)
  12928. static inline int mbedtls_ssl_ciphersuite_has_pfs( const mbedtls_ssl_ciphersuite_t *info )
  12929. {
  12930. switch( info->key_exchange )
  12931. {
  12932. case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
  12933. case MBEDTLS_KEY_EXCHANGE_DHE_PSK:
  12934. case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
  12935. case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
  12936. case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
  12937. case MBEDTLS_KEY_EXCHANGE_ECJPAKE:
  12938. return( 1 );
  12939. default:
  12940. return( 0 );
  12941. }
  12942. }
  12943. #endif /* MBEDTLS_KEY_EXCHANGE__SOME_PFS__ENABLED */
  12944. #if defined(MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED)
  12945. static inline int mbedtls_ssl_ciphersuite_no_pfs( const mbedtls_ssl_ciphersuite_t *info )
  12946. {
  12947. switch( info->key_exchange )
  12948. {
  12949. case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
  12950. case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
  12951. case MBEDTLS_KEY_EXCHANGE_RSA:
  12952. case MBEDTLS_KEY_EXCHANGE_PSK:
  12953. case MBEDTLS_KEY_EXCHANGE_RSA_PSK:
  12954. return( 1 );
  12955. default:
  12956. return( 0 );
  12957. }
  12958. }
  12959. #endif /* MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED */
  12960. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED)
  12961. static inline int mbedtls_ssl_ciphersuite_uses_ecdh( const mbedtls_ssl_ciphersuite_t *info )
  12962. {
  12963. switch( info->key_exchange )
  12964. {
  12965. case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
  12966. case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
  12967. return( 1 );
  12968. default:
  12969. return( 0 );
  12970. }
  12971. }
  12972. #endif /* MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED */
  12973. static inline int mbedtls_ssl_ciphersuite_cert_req_allowed( const mbedtls_ssl_ciphersuite_t *info )
  12974. {
  12975. switch( info->key_exchange )
  12976. {
  12977. case MBEDTLS_KEY_EXCHANGE_RSA:
  12978. case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
  12979. case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
  12980. case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
  12981. case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
  12982. case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
  12983. return( 1 );
  12984. default:
  12985. return( 0 );
  12986. }
  12987. }
  12988. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED)
  12989. static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuite_t *info )
  12990. {
  12991. switch( info->key_exchange )
  12992. {
  12993. case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
  12994. case MBEDTLS_KEY_EXCHANGE_DHE_PSK:
  12995. return( 1 );
  12996. default:
  12997. return( 0 );
  12998. }
  12999. }
  13000. #endif /* MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED) */
  13001. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED)
  13002. static inline int mbedtls_ssl_ciphersuite_uses_ecdhe( const mbedtls_ssl_ciphersuite_t *info )
  13003. {
  13004. switch( info->key_exchange )
  13005. {
  13006. case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
  13007. case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
  13008. case MBEDTLS_KEY_EXCHANGE_ECDHE_PSK:
  13009. return( 1 );
  13010. default:
  13011. return( 0 );
  13012. }
  13013. }
  13014. #endif /* MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED) */
  13015. #if defined(MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED)
  13016. static inline int mbedtls_ssl_ciphersuite_uses_server_signature( const mbedtls_ssl_ciphersuite_t *info )
  13017. {
  13018. switch( info->key_exchange )
  13019. {
  13020. case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
  13021. case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
  13022. case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
  13023. return( 1 );
  13024. default:
  13025. return( 0 );
  13026. }
  13027. }
  13028. #endif /* MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED */
  13029. #ifdef __cplusplus
  13030. }
  13031. #endif
  13032. #endif /* ssl_ciphersuites.h */
  13033. /********* Start of file include/mbedtls/ecdh.h ************/
  13034. /**
  13035. * \file ecdh.h
  13036. *
  13037. * \brief The Elliptic Curve Diffie-Hellman (ECDH) protocol APIs.
  13038. *
  13039. * ECDH is an anonymous key agreement protocol allowing two parties to
  13040. * establish a shared secret over an insecure channel. Each party must have an
  13041. * elliptic-curve public–private key pair.
  13042. *
  13043. * For more information, see <em>NIST SP 800-56A Rev. 2: Recommendation for
  13044. * Pair-Wise Key Establishment Schemes Using Discrete Logarithm
  13045. * Cryptography</em>.
  13046. */
  13047. /*
  13048. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  13049. * SPDX-License-Identifier: Apache-2.0
  13050. *
  13051. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  13052. * not use this file except in compliance with the License.
  13053. * You may obtain a copy of the License at
  13054. *
  13055. * http://www.apache.org/licenses/LICENSE-2.0
  13056. *
  13057. * Unless required by applicable law or agreed to in writing, software
  13058. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13059. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13060. * See the License for the specific language governing permissions and
  13061. * limitations under the License.
  13062. *
  13063. * This file is part of Mbed TLS (https://tls.mbed.org)
  13064. */
  13065. #ifndef MBEDTLS_ECDH_H
  13066. #define MBEDTLS_ECDH_H
  13067. #ifdef __cplusplus
  13068. extern "C" {
  13069. #endif
  13070. /**
  13071. * Defines the source of the imported EC key:
  13072. * <ul><li>Our key.</li>
  13073. * <li>The key of the peer.</li></ul>
  13074. */
  13075. typedef enum
  13076. {
  13077. MBEDTLS_ECDH_OURS,
  13078. MBEDTLS_ECDH_THEIRS,
  13079. } mbedtls_ecdh_side;
  13080. /**
  13081. * \brief The ECDH context structure.
  13082. */
  13083. typedef struct
  13084. {
  13085. mbedtls_ecp_group grp; /*!< The elliptic curve used. */
  13086. mbedtls_mpi d; /*!< The private key. */
  13087. mbedtls_ecp_point Q; /*!< The public key. */
  13088. mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */
  13089. mbedtls_mpi z; /*!< The shared secret. */
  13090. int point_format; /*!< The format of point export in TLS messages. */
  13091. mbedtls_ecp_point Vi; /*!< The blinding value. */
  13092. mbedtls_ecp_point Vf; /*!< The unblinding value. */
  13093. mbedtls_mpi _d; /*!< The previous \p d. */
  13094. }
  13095. mbedtls_ecdh_context;
  13096. /**
  13097. * \brief This function generates an ECDH keypair on an elliptic
  13098. * curve.
  13099. *
  13100. * This function performs the first of two core computations
  13101. * implemented during the ECDH key exchange. The second core
  13102. * computation is performed by mbedtls_ecdh_compute_shared().
  13103. *
  13104. * \param grp The ECP group.
  13105. * \param d The destination MPI (private key).
  13106. * \param Q The destination point (public key).
  13107. * \param f_rng The RNG function.
  13108. * \param p_rng The RNG parameter.
  13109. *
  13110. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX or
  13111. * \c MBEDTLS_MPI_XXX error code on failure.
  13112. *
  13113. * \see ecp.h
  13114. */
  13115. int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
  13116. int (*f_rng)(void *, unsigned char *, size_t),
  13117. void *p_rng );
  13118. /**
  13119. * \brief This function computes the shared secret.
  13120. *
  13121. * This function performs the second of two core computations
  13122. * implemented during the ECDH key exchange. The first core
  13123. * computation is performed by mbedtls_ecdh_gen_public().
  13124. *
  13125. * \param grp The ECP group.
  13126. * \param z The destination MPI (shared secret).
  13127. * \param Q The public key from another party.
  13128. * \param d Our secret exponent (private key).
  13129. * \param f_rng The RNG function.
  13130. * \param p_rng The RNG parameter.
  13131. *
  13132. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX or
  13133. * \c MBEDTLS_MPI_XXX error code on failure.
  13134. *
  13135. * \see ecp.h
  13136. *
  13137. * \note If \p f_rng is not NULL, it is used to implement
  13138. * countermeasures against potential elaborate timing
  13139. * attacks. For more information, see mbedtls_ecp_mul().
  13140. */
  13141. int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
  13142. const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
  13143. int (*f_rng)(void *, unsigned char *, size_t),
  13144. void *p_rng );
  13145. /**
  13146. * \brief This function initializes an ECDH context.
  13147. *
  13148. * \param ctx The ECDH context to initialize.
  13149. */
  13150. void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
  13151. /**
  13152. * \brief This function frees a context.
  13153. *
  13154. * \param ctx The context to free.
  13155. */
  13156. void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
  13157. /**
  13158. * \brief This function generates a public key and a TLS
  13159. * ServerKeyExchange payload.
  13160. *
  13161. * This is the first function used by a TLS server for ECDHE
  13162. * ciphersuites.
  13163. *
  13164. * \param ctx The ECDH context.
  13165. * \param olen The number of characters written.
  13166. * \param buf The destination buffer.
  13167. * \param blen The length of the destination buffer.
  13168. * \param f_rng The RNG function.
  13169. * \param p_rng The RNG parameter.
  13170. *
  13171. * \note This function assumes that the ECP group (grp) of the
  13172. * \p ctx context has already been properly set,
  13173. * for example, using mbedtls_ecp_group_load().
  13174. *
  13175. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
  13176. * on failure.
  13177. *
  13178. * \see ecp.h
  13179. */
  13180. int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
  13181. unsigned char *buf, size_t blen,
  13182. int (*f_rng)(void *, unsigned char *, size_t),
  13183. void *p_rng );
  13184. /**
  13185. * \brief This function parses and processes a TLS ServerKeyExhange
  13186. * payload.
  13187. *
  13188. * This is the first function used by a TLS client for ECDHE
  13189. * ciphersuites.
  13190. *
  13191. * \param ctx The ECDH context.
  13192. * \param buf The pointer to the start of the input buffer.
  13193. * \param end The address for one Byte past the end of the buffer.
  13194. *
  13195. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
  13196. * on failure.
  13197. *
  13198. * \see ecp.h
  13199. */
  13200. int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
  13201. const unsigned char **buf, const unsigned char *end );
  13202. /**
  13203. * \brief This function sets up an ECDH context from an EC key.
  13204. *
  13205. * It is used by clients and servers in place of the
  13206. * ServerKeyEchange for static ECDH, and imports ECDH
  13207. * parameters from the EC key information of a certificate.
  13208. *
  13209. * \param ctx The ECDH context to set up.
  13210. * \param key The EC key to use.
  13211. * \param side Defines the source of the key:
  13212. * <ul><li>1: Our key.</li>
  13213. <li>0: The key of the peer.</li></ul>
  13214. *
  13215. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
  13216. * on failure.
  13217. *
  13218. * \see ecp.h
  13219. */
  13220. int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key,
  13221. mbedtls_ecdh_side side );
  13222. /**
  13223. * \brief This function generates a public key and a TLS
  13224. * ClientKeyExchange payload.
  13225. *
  13226. * This is the second function used by a TLS client for ECDH(E)
  13227. * ciphersuites.
  13228. *
  13229. * \param ctx The ECDH context.
  13230. * \param olen The number of Bytes written.
  13231. * \param buf The destination buffer.
  13232. * \param blen The size of the destination buffer.
  13233. * \param f_rng The RNG function.
  13234. * \param p_rng The RNG parameter.
  13235. *
  13236. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
  13237. * on failure.
  13238. *
  13239. * \see ecp.h
  13240. */
  13241. int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
  13242. unsigned char *buf, size_t blen,
  13243. int (*f_rng)(void *, unsigned char *, size_t),
  13244. void *p_rng );
  13245. /**
  13246. * \brief This function parses and processes a TLS ClientKeyExchange
  13247. * payload.
  13248. *
  13249. * This is the second function used by a TLS server for ECDH(E)
  13250. * ciphersuites.
  13251. *
  13252. * \param ctx The ECDH context.
  13253. * \param buf The start of the input buffer.
  13254. * \param blen The length of the input buffer.
  13255. *
  13256. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
  13257. * on failure.
  13258. *
  13259. * \see ecp.h
  13260. */
  13261. int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
  13262. const unsigned char *buf, size_t blen );
  13263. /**
  13264. * \brief This function derives and exports the shared secret.
  13265. *
  13266. * This is the last function used by both TLS client
  13267. * and servers.
  13268. *
  13269. * \param ctx The ECDH context.
  13270. * \param olen The number of Bytes written.
  13271. * \param buf The destination buffer.
  13272. * \param blen The length of the destination buffer.
  13273. * \param f_rng The RNG function.
  13274. * \param p_rng The RNG parameter.
  13275. *
  13276. * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code
  13277. * on failure.
  13278. *
  13279. * \see ecp.h
  13280. *
  13281. * \note If \p f_rng is not NULL, it is used to implement
  13282. * countermeasures against potential elaborate timing
  13283. * attacks. For more information, see mbedtls_ecp_mul().
  13284. */
  13285. int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
  13286. unsigned char *buf, size_t blen,
  13287. int (*f_rng)(void *, unsigned char *, size_t),
  13288. void *p_rng );
  13289. #ifdef __cplusplus
  13290. }
  13291. #endif
  13292. #endif /* ecdh.h */
  13293. /********* Start of file include/mbedtls/sha1.h ************/
  13294. /**
  13295. * \file sha1.h
  13296. *
  13297. * \brief The SHA-1 cryptographic hash function.
  13298. *
  13299. * \warning SHA-1 is considered a weak message digest and its use constitutes
  13300. * a security risk. We recommend considering stronger message
  13301. * digests instead.
  13302. */
  13303. /*
  13304. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  13305. * SPDX-License-Identifier: Apache-2.0
  13306. *
  13307. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  13308. * not use this file except in compliance with the License.
  13309. * You may obtain a copy of the License at
  13310. *
  13311. * http://www.apache.org/licenses/LICENSE-2.0
  13312. *
  13313. * Unless required by applicable law or agreed to in writing, software
  13314. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13315. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13316. * See the License for the specific language governing permissions and
  13317. * limitations under the License.
  13318. *
  13319. * This file is part of Mbed TLS (https://tls.mbed.org)
  13320. */
  13321. #ifndef MBEDTLS_SHA1_H
  13322. #define MBEDTLS_SHA1_H
  13323. #if !defined(MBEDTLS_CONFIG_FILE)
  13324. #else
  13325. #endif
  13326. #include <stddef.h>
  13327. #include <stdint.h>
  13328. #define MBEDTLS_ERR_SHA1_HW_ACCEL_FAILED -0x0035 /**< SHA-1 hardware accelerator failed */
  13329. #if !defined(MBEDTLS_SHA1_ALT)
  13330. // Regular implementation
  13331. //
  13332. #ifdef __cplusplus
  13333. extern "C" {
  13334. #endif
  13335. /**
  13336. * \brief The SHA-1 context structure.
  13337. *
  13338. * \warning SHA-1 is considered a weak message digest and its use
  13339. * constitutes a security risk. We recommend considering
  13340. * stronger message digests instead.
  13341. *
  13342. */
  13343. typedef struct
  13344. {
  13345. uint32_t total[2]; /*!< The number of Bytes processed. */
  13346. uint32_t state[5]; /*!< The intermediate digest state. */
  13347. unsigned char buffer[64]; /*!< The data block being processed. */
  13348. }
  13349. mbedtls_sha1_context;
  13350. /**
  13351. * \brief This function initializes a SHA-1 context.
  13352. *
  13353. * \param ctx The SHA-1 context to initialize.
  13354. *
  13355. * \warning SHA-1 is considered a weak message digest and its use
  13356. * constitutes a security risk. We recommend considering
  13357. * stronger message digests instead.
  13358. *
  13359. */
  13360. void mbedtls_sha1_init( mbedtls_sha1_context *ctx );
  13361. /**
  13362. * \brief This function clears a SHA-1 context.
  13363. *
  13364. * \param ctx The SHA-1 context to clear.
  13365. *
  13366. * \warning SHA-1 is considered a weak message digest and its use
  13367. * constitutes a security risk. We recommend considering
  13368. * stronger message digests instead.
  13369. *
  13370. */
  13371. void mbedtls_sha1_free( mbedtls_sha1_context *ctx );
  13372. /**
  13373. * \brief This function clones the state of a SHA-1 context.
  13374. *
  13375. * \param dst The destination context.
  13376. * \param src The context to clone.
  13377. *
  13378. * \warning SHA-1 is considered a weak message digest and its use
  13379. * constitutes a security risk. We recommend considering
  13380. * stronger message digests instead.
  13381. *
  13382. */
  13383. void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
  13384. const mbedtls_sha1_context *src );
  13385. /**
  13386. * \brief This function starts a SHA-1 checksum calculation.
  13387. *
  13388. * \param ctx The context to initialize.
  13389. *
  13390. * \return \c 0 if successful
  13391. *
  13392. * \warning SHA-1 is considered a weak message digest and its use
  13393. * constitutes a security risk. We recommend considering
  13394. * stronger message digests instead.
  13395. *
  13396. */
  13397. int mbedtls_sha1_starts_ret( mbedtls_sha1_context *ctx );
  13398. /**
  13399. * \brief This function feeds an input buffer into an ongoing SHA-1
  13400. * checksum calculation.
  13401. *
  13402. * \param ctx The SHA-1 context.
  13403. * \param input The buffer holding the input data.
  13404. * \param ilen The length of the input data.
  13405. *
  13406. * \return \c 0 if successful
  13407. *
  13408. * \warning SHA-1 is considered a weak message digest and its use
  13409. * constitutes a security risk. We recommend considering
  13410. * stronger message digests instead.
  13411. *
  13412. */
  13413. int mbedtls_sha1_update_ret( mbedtls_sha1_context *ctx,
  13414. const unsigned char *input,
  13415. size_t ilen );
  13416. /**
  13417. * \brief This function finishes the SHA-1 operation, and writes
  13418. * the result to the output buffer.
  13419. *
  13420. * \param ctx The SHA-1 context.
  13421. * \param output The SHA-1 checksum result.
  13422. *
  13423. * \return \c 0 if successful
  13424. *
  13425. * \warning SHA-1 is considered a weak message digest and its use
  13426. * constitutes a security risk. We recommend considering
  13427. * stronger message digests instead.
  13428. *
  13429. */
  13430. int mbedtls_sha1_finish_ret( mbedtls_sha1_context *ctx,
  13431. unsigned char output[20] );
  13432. /**
  13433. * \brief SHA-1 process data block (internal use only)
  13434. *
  13435. * \param ctx SHA-1 context
  13436. * \param data The data block being processed.
  13437. *
  13438. * \return \c 0 if successful
  13439. *
  13440. * \warning SHA-1 is considered a weak message digest and its use
  13441. * constitutes a security risk. We recommend considering
  13442. * stronger message digests instead.
  13443. *
  13444. */
  13445. int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx,
  13446. const unsigned char data[64] );
  13447. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  13448. #if defined(MBEDTLS_DEPRECATED_WARNING)
  13449. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  13450. #else
  13451. #define MBEDTLS_DEPRECATED
  13452. #endif
  13453. /**
  13454. * \brief SHA-1 context setup
  13455. *
  13456. * \deprecated Superseded by mbedtls_sha1_starts_ret() in 2.7.0
  13457. *
  13458. * \param ctx The SHA-1 context to be initialized.
  13459. *
  13460. * \warning SHA-1 is considered a weak message digest and its use
  13461. * constitutes a security risk. We recommend considering
  13462. * stronger message digests instead.
  13463. *
  13464. */
  13465. MBEDTLS_DEPRECATED void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
  13466. /**
  13467. * \brief SHA-1 process buffer
  13468. *
  13469. * \deprecated Superseded by mbedtls_sha1_update_ret() in 2.7.0
  13470. *
  13471. * \param ctx The SHA-1 context.
  13472. * \param input The buffer holding the input data.
  13473. * \param ilen The length of the input data.
  13474. *
  13475. * \warning SHA-1 is considered a weak message digest and its use
  13476. * constitutes a security risk. We recommend considering
  13477. * stronger message digests instead.
  13478. *
  13479. */
  13480. MBEDTLS_DEPRECATED void mbedtls_sha1_update( mbedtls_sha1_context *ctx,
  13481. const unsigned char *input,
  13482. size_t ilen );
  13483. /**
  13484. * \brief SHA-1 final digest
  13485. *
  13486. * \deprecated Superseded by mbedtls_sha1_finish_ret() in 2.7.0
  13487. *
  13488. * \param ctx The SHA-1 context.
  13489. * \param output The SHA-1 checksum result.
  13490. *
  13491. * \warning SHA-1 is considered a weak message digest and its use
  13492. * constitutes a security risk. We recommend considering
  13493. * stronger message digests instead.
  13494. *
  13495. */
  13496. MBEDTLS_DEPRECATED void mbedtls_sha1_finish( mbedtls_sha1_context *ctx,
  13497. unsigned char output[20] );
  13498. /**
  13499. * \brief SHA-1 process data block (internal use only)
  13500. *
  13501. * \deprecated Superseded by mbedtls_internal_sha1_process() in 2.7.0
  13502. *
  13503. * \param ctx The SHA-1 context.
  13504. * \param data The data block being processed.
  13505. *
  13506. * \warning SHA-1 is considered a weak message digest and its use
  13507. * constitutes a security risk. We recommend considering
  13508. * stronger message digests instead.
  13509. *
  13510. */
  13511. MBEDTLS_DEPRECATED void mbedtls_sha1_process( mbedtls_sha1_context *ctx,
  13512. const unsigned char data[64] );
  13513. #undef MBEDTLS_DEPRECATED
  13514. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  13515. #ifdef __cplusplus
  13516. }
  13517. #endif
  13518. #else /* MBEDTLS_SHA1_ALT */
  13519. #endif /* MBEDTLS_SHA1_ALT */
  13520. #ifdef __cplusplus
  13521. extern "C" {
  13522. #endif
  13523. /**
  13524. * \brief This function calculates the SHA-1 checksum of a buffer.
  13525. *
  13526. * The function allocates the context, performs the
  13527. * calculation, and frees the context.
  13528. *
  13529. * The SHA-1 result is calculated as
  13530. * output = SHA-1(input buffer).
  13531. *
  13532. * \param input The buffer holding the input data.
  13533. * \param ilen The length of the input data.
  13534. * \param output The SHA-1 checksum result.
  13535. *
  13536. * \return \c 0 if successful
  13537. *
  13538. * \warning SHA-1 is considered a weak message digest and its use
  13539. * constitutes a security risk. We recommend considering
  13540. * stronger message digests instead.
  13541. *
  13542. */
  13543. int mbedtls_sha1_ret( const unsigned char *input,
  13544. size_t ilen,
  13545. unsigned char output[20] );
  13546. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  13547. #if defined(MBEDTLS_DEPRECATED_WARNING)
  13548. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  13549. #else
  13550. #define MBEDTLS_DEPRECATED
  13551. #endif
  13552. /**
  13553. * \brief Output = SHA-1( input buffer )
  13554. *
  13555. * \deprecated Superseded by mbedtls_sha1_ret() in 2.7.0
  13556. *
  13557. * \param input The buffer holding the input data.
  13558. * \param ilen The length of the input data.
  13559. * \param output The SHA-1 checksum result.
  13560. *
  13561. * \warning SHA-1 is considered a weak message digest and its use
  13562. * constitutes a security risk. We recommend considering
  13563. * stronger message digests instead.
  13564. *
  13565. */
  13566. MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,
  13567. size_t ilen,
  13568. unsigned char output[20] );
  13569. #undef MBEDTLS_DEPRECATED
  13570. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  13571. /**
  13572. * \brief The SHA-1 checkup routine.
  13573. *
  13574. * \return \c 0 on success, or \c 1 on failure.
  13575. *
  13576. * \warning SHA-1 is considered a weak message digest and its use
  13577. * constitutes a security risk. We recommend considering
  13578. * stronger message digests instead.
  13579. *
  13580. */
  13581. int mbedtls_sha1_self_test( int verbose );
  13582. #ifdef __cplusplus
  13583. }
  13584. #endif
  13585. #endif /* mbedtls_sha1.h */
  13586. /********* Start of file include/mbedtls/sha256.h ************/
  13587. /**
  13588. * \file sha256.h
  13589. *
  13590. * \brief The SHA-224 and SHA-256 cryptographic hash function.
  13591. */
  13592. /*
  13593. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  13594. * SPDX-License-Identifier: Apache-2.0
  13595. *
  13596. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  13597. * not use this file except in compliance with the License.
  13598. * You may obtain a copy of the License at
  13599. *
  13600. * http://www.apache.org/licenses/LICENSE-2.0
  13601. *
  13602. * Unless required by applicable law or agreed to in writing, software
  13603. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13604. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13605. * See the License for the specific language governing permissions and
  13606. * limitations under the License.
  13607. *
  13608. * This file is part of Mbed TLS (https://tls.mbed.org)
  13609. */
  13610. #ifndef MBEDTLS_SHA256_H
  13611. #define MBEDTLS_SHA256_H
  13612. #if !defined(MBEDTLS_CONFIG_FILE)
  13613. #else
  13614. #endif
  13615. #include <stddef.h>
  13616. #include <stdint.h>
  13617. #define MBEDTLS_ERR_SHA256_HW_ACCEL_FAILED -0x0037 /**< SHA-256 hardware accelerator failed */
  13618. #if !defined(MBEDTLS_SHA256_ALT)
  13619. // Regular implementation
  13620. //
  13621. #ifdef __cplusplus
  13622. extern "C" {
  13623. #endif
  13624. /**
  13625. * \brief The SHA-256 context structure.
  13626. *
  13627. * The structure is used both for SHA-256 and for SHA-224
  13628. * checksum calculations. The choice between these two is
  13629. * made in the call to mbedtls_sha256_starts_ret().
  13630. */
  13631. typedef struct
  13632. {
  13633. uint32_t total[2]; /*!< The number of Bytes processed. */
  13634. uint32_t state[8]; /*!< The intermediate digest state. */
  13635. unsigned char buffer[64]; /*!< The data block being processed. */
  13636. int is224; /*!< Determines which function to use.
  13637. <ul><li>0: Use SHA-256.</li>
  13638. <li>1: Use SHA-224.</li></ul> */
  13639. }
  13640. mbedtls_sha256_context;
  13641. /**
  13642. * \brief This function initializes a SHA-256 context.
  13643. *
  13644. * \param ctx The SHA-256 context to initialize.
  13645. */
  13646. void mbedtls_sha256_init( mbedtls_sha256_context *ctx );
  13647. /**
  13648. * \brief This function clears a SHA-256 context.
  13649. *
  13650. * \param ctx The SHA-256 context to clear.
  13651. */
  13652. void mbedtls_sha256_free( mbedtls_sha256_context *ctx );
  13653. /**
  13654. * \brief This function clones the state of a SHA-256 context.
  13655. *
  13656. * \param dst The destination context.
  13657. * \param src The context to clone.
  13658. */
  13659. void mbedtls_sha256_clone( mbedtls_sha256_context *dst,
  13660. const mbedtls_sha256_context *src );
  13661. /**
  13662. * \brief This function starts a SHA-224 or SHA-256 checksum
  13663. * calculation.
  13664. *
  13665. * \param ctx The context to initialize.
  13666. * \param is224 Determines which function to use.
  13667. * <ul><li>0: Use SHA-256.</li>
  13668. * <li>1: Use SHA-224.</li></ul>
  13669. *
  13670. * \return \c 0 on success.
  13671. */
  13672. int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 );
  13673. /**
  13674. * \brief This function feeds an input buffer into an ongoing
  13675. * SHA-256 checksum calculation.
  13676. *
  13677. * \param ctx SHA-256 context
  13678. * \param input buffer holding the data
  13679. * \param ilen length of the input data
  13680. *
  13681. * \return \c 0 on success.
  13682. */
  13683. int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx,
  13684. const unsigned char *input,
  13685. size_t ilen );
  13686. /**
  13687. * \brief This function finishes the SHA-256 operation, and writes
  13688. * the result to the output buffer.
  13689. *
  13690. * \param ctx The SHA-256 context.
  13691. * \param output The SHA-224 or SHA-256 checksum result.
  13692. *
  13693. * \return \c 0 on success.
  13694. */
  13695. int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx,
  13696. unsigned char output[32] );
  13697. /**
  13698. * \brief This function processes a single data block within
  13699. * the ongoing SHA-256 computation. This function is for
  13700. * internal use only.
  13701. *
  13702. * \param ctx The SHA-256 context.
  13703. * \param data The buffer holding one block of data.
  13704. *
  13705. * \return \c 0 on success.
  13706. */
  13707. int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx,
  13708. const unsigned char data[64] );
  13709. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  13710. #if defined(MBEDTLS_DEPRECATED_WARNING)
  13711. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  13712. #else
  13713. #define MBEDTLS_DEPRECATED
  13714. #endif
  13715. /**
  13716. * \brief This function starts a SHA-256 checksum calculation.
  13717. *
  13718. * \deprecated Superseded by mbedtls_sha256_starts_ret() in 2.7.0.
  13719. *
  13720. * \param ctx The SHA-256 context to initialize.
  13721. * \param is224 Determines which function to use.
  13722. * <ul><li>0: Use SHA-256.</li>
  13723. * <li>1: Use SHA-224.</li></ul>
  13724. */
  13725. MBEDTLS_DEPRECATED void mbedtls_sha256_starts( mbedtls_sha256_context *ctx,
  13726. int is224 );
  13727. /**
  13728. * \brief This function feeds an input buffer into an ongoing
  13729. * SHA-256 checksum calculation.
  13730. *
  13731. * \deprecated Superseded by mbedtls_sha256_update_ret() in 2.7.0.
  13732. *
  13733. * \param ctx The SHA-256 context to initialize.
  13734. * \param input The buffer holding the data.
  13735. * \param ilen The length of the input data.
  13736. */
  13737. MBEDTLS_DEPRECATED void mbedtls_sha256_update( mbedtls_sha256_context *ctx,
  13738. const unsigned char *input,
  13739. size_t ilen );
  13740. /**
  13741. * \brief This function finishes the SHA-256 operation, and writes
  13742. * the result to the output buffer.
  13743. *
  13744. * \deprecated Superseded by mbedtls_sha256_finish_ret() in 2.7.0.
  13745. *
  13746. * \param ctx The SHA-256 context.
  13747. * \param output The SHA-224or SHA-256 checksum result.
  13748. */
  13749. MBEDTLS_DEPRECATED void mbedtls_sha256_finish( mbedtls_sha256_context *ctx,
  13750. unsigned char output[32] );
  13751. /**
  13752. * \brief This function processes a single data block within
  13753. * the ongoing SHA-256 computation. This function is for
  13754. * internal use only.
  13755. *
  13756. * \deprecated Superseded by mbedtls_internal_sha256_process() in 2.7.0.
  13757. *
  13758. * \param ctx The SHA-256 context.
  13759. * \param data The buffer holding one block of data.
  13760. */
  13761. MBEDTLS_DEPRECATED void mbedtls_sha256_process( mbedtls_sha256_context *ctx,
  13762. const unsigned char data[64] );
  13763. #undef MBEDTLS_DEPRECATED
  13764. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  13765. #ifdef __cplusplus
  13766. }
  13767. #endif
  13768. #else /* MBEDTLS_SHA256_ALT */
  13769. #endif /* MBEDTLS_SHA256_ALT */
  13770. #ifdef __cplusplus
  13771. extern "C" {
  13772. #endif
  13773. /**
  13774. * \brief This function calculates the SHA-224 or SHA-256
  13775. * checksum of a buffer.
  13776. *
  13777. * The function allocates the context, performs the
  13778. * calculation, and frees the context.
  13779. *
  13780. * The SHA-256 result is calculated as
  13781. * output = SHA-256(input buffer).
  13782. *
  13783. * \param input The buffer holding the input data.
  13784. * \param ilen The length of the input data.
  13785. * \param output The SHA-224 or SHA-256 checksum result.
  13786. * \param is224 Determines which function to use.
  13787. * <ul><li>0: Use SHA-256.</li>
  13788. * <li>1: Use SHA-224.</li></ul>
  13789. */
  13790. int mbedtls_sha256_ret( const unsigned char *input,
  13791. size_t ilen,
  13792. unsigned char output[32],
  13793. int is224 );
  13794. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  13795. #if defined(MBEDTLS_DEPRECATED_WARNING)
  13796. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  13797. #else
  13798. #define MBEDTLS_DEPRECATED
  13799. #endif
  13800. /**
  13801. * \brief This function calculates the SHA-224 or SHA-256 checksum
  13802. * of a buffer.
  13803. *
  13804. * The function allocates the context, performs the
  13805. * calculation, and frees the context.
  13806. *
  13807. * The SHA-256 result is calculated as
  13808. * output = SHA-256(input buffer).
  13809. *
  13810. * \deprecated Superseded by mbedtls_sha256_ret() in 2.7.0.
  13811. *
  13812. * \param input The buffer holding the data.
  13813. * \param ilen The length of the input data.
  13814. * \param output The SHA-224 or SHA-256 checksum result.
  13815. * \param is224 Determines which function to use.
  13816. * <ul><li>0: Use SHA-256.</li>
  13817. * <li>1: Use SHA-224.</li></ul>
  13818. */
  13819. MBEDTLS_DEPRECATED void mbedtls_sha256( const unsigned char *input,
  13820. size_t ilen,
  13821. unsigned char output[32],
  13822. int is224 );
  13823. #undef MBEDTLS_DEPRECATED
  13824. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  13825. /**
  13826. * \brief The SHA-224 and SHA-256 checkup routine.
  13827. *
  13828. * \return \c 0 on success, or \c 1 on failure.
  13829. */
  13830. int mbedtls_sha256_self_test( int verbose );
  13831. #ifdef __cplusplus
  13832. }
  13833. #endif
  13834. #endif /* mbedtls_sha256.h */
  13835. /********* Start of file include/mbedtls/sha512.h ************/
  13836. /**
  13837. * \file sha512.h
  13838. *
  13839. * \brief The SHA-384 and SHA-512 cryptographic hash function.
  13840. */
  13841. /*
  13842. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  13843. * SPDX-License-Identifier: Apache-2.0
  13844. *
  13845. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  13846. * not use this file except in compliance with the License.
  13847. * You may obtain a copy of the License at
  13848. *
  13849. * http://www.apache.org/licenses/LICENSE-2.0
  13850. *
  13851. * Unless required by applicable law or agreed to in writing, software
  13852. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13853. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13854. * See the License for the specific language governing permissions and
  13855. * limitations under the License.
  13856. *
  13857. * This file is part of Mbed TLS (https://tls.mbed.org)
  13858. */
  13859. #ifndef MBEDTLS_SHA512_H
  13860. #define MBEDTLS_SHA512_H
  13861. #if !defined(MBEDTLS_CONFIG_FILE)
  13862. #else
  13863. #endif
  13864. #include <stddef.h>
  13865. #include <stdint.h>
  13866. #define MBEDTLS_ERR_SHA512_HW_ACCEL_FAILED -0x0039 /**< SHA-512 hardware accelerator failed */
  13867. #if !defined(MBEDTLS_SHA512_ALT)
  13868. // Regular implementation
  13869. //
  13870. #ifdef __cplusplus
  13871. extern "C" {
  13872. #endif
  13873. /**
  13874. * \brief The SHA-512 context structure.
  13875. *
  13876. * The structure is used both for SHA-384 and for SHA-512
  13877. * checksum calculations. The choice between these two is
  13878. * made in the call to mbedtls_sha512_starts_ret().
  13879. */
  13880. typedef struct
  13881. {
  13882. uint64_t total[2]; /*!< The number of Bytes processed. */
  13883. uint64_t state[8]; /*!< The intermediate digest state. */
  13884. unsigned char buffer[128]; /*!< The data block being processed. */
  13885. int is384; /*!< Determines which function to use.
  13886. * <ul><li>0: Use SHA-512.</li>
  13887. * <li>1: Use SHA-384.</li></ul> */
  13888. }
  13889. mbedtls_sha512_context;
  13890. /**
  13891. * \brief This function initializes a SHA-512 context.
  13892. *
  13893. * \param ctx The SHA-512 context to initialize.
  13894. */
  13895. void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
  13896. /**
  13897. * \brief This function clears a SHA-512 context.
  13898. *
  13899. * \param ctx The SHA-512 context to clear.
  13900. */
  13901. void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
  13902. /**
  13903. * \brief This function clones the state of a SHA-512 context.
  13904. *
  13905. * \param dst The destination context.
  13906. * \param src The context to clone.
  13907. */
  13908. void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
  13909. const mbedtls_sha512_context *src );
  13910. /**
  13911. * \brief This function starts a SHA-384 or SHA-512 checksum
  13912. * calculation.
  13913. *
  13914. * \param ctx The SHA-512 context to initialize.
  13915. * \param is384 Determines which function to use.
  13916. * <ul><li>0: Use SHA-512.</li>
  13917. * <li>1: Use SHA-384.</li></ul>
  13918. *
  13919. * \return \c 0 on success.
  13920. */
  13921. int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 );
  13922. /**
  13923. * \brief This function feeds an input buffer into an ongoing
  13924. * SHA-512 checksum calculation.
  13925. *
  13926. * \param ctx The SHA-512 context.
  13927. * \param input The buffer holding the input data.
  13928. * \param ilen The length of the input data.
  13929. *
  13930. * \return \c 0 on success.
  13931. */
  13932. int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx,
  13933. const unsigned char *input,
  13934. size_t ilen );
  13935. /**
  13936. * \brief This function finishes the SHA-512 operation, and writes
  13937. * the result to the output buffer. This function is for
  13938. * internal use only.
  13939. *
  13940. * \param ctx The SHA-512 context.
  13941. * \param output The SHA-384 or SHA-512 checksum result.
  13942. *
  13943. * \return \c 0 on success.
  13944. */
  13945. int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx,
  13946. unsigned char output[64] );
  13947. /**
  13948. * \brief This function processes a single data block within
  13949. * the ongoing SHA-512 computation.
  13950. *
  13951. * \param ctx The SHA-512 context.
  13952. * \param data The buffer holding one block of data.
  13953. *
  13954. * \return \c 0 on success.
  13955. */
  13956. int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx,
  13957. const unsigned char data[128] );
  13958. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  13959. #if defined(MBEDTLS_DEPRECATED_WARNING)
  13960. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  13961. #else
  13962. #define MBEDTLS_DEPRECATED
  13963. #endif
  13964. /**
  13965. * \brief This function starts a SHA-384 or SHA-512 checksum
  13966. * calculation.
  13967. *
  13968. * \deprecated Superseded by mbedtls_sha512_starts_ret() in 2.7.0
  13969. *
  13970. * \param ctx The SHA-512 context to initialize.
  13971. * \param is384 Determines which function to use.
  13972. * <ul><li>0: Use SHA-512.</li>
  13973. * <li>1: Use SHA-384.</li></ul>
  13974. */
  13975. MBEDTLS_DEPRECATED void mbedtls_sha512_starts( mbedtls_sha512_context *ctx,
  13976. int is384 );
  13977. /**
  13978. * \brief This function feeds an input buffer into an ongoing
  13979. * SHA-512 checksum calculation.
  13980. *
  13981. * \deprecated Superseded by mbedtls_sha512_update_ret() in 2.7.0
  13982. *
  13983. * \param ctx The SHA-512 context.
  13984. * \param input The buffer holding the data.
  13985. * \param ilen The length of the input data.
  13986. */
  13987. MBEDTLS_DEPRECATED void mbedtls_sha512_update( mbedtls_sha512_context *ctx,
  13988. const unsigned char *input,
  13989. size_t ilen );
  13990. /**
  13991. * \brief This function finishes the SHA-512 operation, and writes
  13992. * the result to the output buffer.
  13993. *
  13994. * \deprecated Superseded by mbedtls_sha512_finish_ret() in 2.7.0
  13995. *
  13996. * \param ctx The SHA-512 context.
  13997. * \param output The SHA-384 or SHA-512 checksum result.
  13998. */
  13999. MBEDTLS_DEPRECATED void mbedtls_sha512_finish( mbedtls_sha512_context *ctx,
  14000. unsigned char output[64] );
  14001. /**
  14002. * \brief This function processes a single data block within
  14003. * the ongoing SHA-512 computation. This function is for
  14004. * internal use only.
  14005. *
  14006. * \deprecated Superseded by mbedtls_internal_sha512_process() in 2.7.0
  14007. *
  14008. * \param ctx The SHA-512 context.
  14009. * \param data The buffer holding one block of data.
  14010. */
  14011. MBEDTLS_DEPRECATED void mbedtls_sha512_process(
  14012. mbedtls_sha512_context *ctx,
  14013. const unsigned char data[128] );
  14014. #undef MBEDTLS_DEPRECATED
  14015. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  14016. #ifdef __cplusplus
  14017. }
  14018. #endif
  14019. #else /* MBEDTLS_SHA512_ALT */
  14020. #endif /* MBEDTLS_SHA512_ALT */
  14021. #ifdef __cplusplus
  14022. extern "C" {
  14023. #endif
  14024. /**
  14025. * \brief This function calculates the SHA-512 or SHA-384
  14026. * checksum of a buffer.
  14027. *
  14028. * The function allocates the context, performs the
  14029. * calculation, and frees the context.
  14030. *
  14031. * The SHA-512 result is calculated as
  14032. * output = SHA-512(input buffer).
  14033. *
  14034. * \param input The buffer holding the input data.
  14035. * \param ilen The length of the input data.
  14036. * \param output The SHA-384 or SHA-512 checksum result.
  14037. * \param is384 Determines which function to use.
  14038. * <ul><li>0: Use SHA-512.</li>
  14039. * <li>1: Use SHA-384.</li></ul>
  14040. *
  14041. * \return \c 0 on success.
  14042. */
  14043. int mbedtls_sha512_ret( const unsigned char *input,
  14044. size_t ilen,
  14045. unsigned char output[64],
  14046. int is384 );
  14047. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  14048. #if defined(MBEDTLS_DEPRECATED_WARNING)
  14049. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  14050. #else
  14051. #define MBEDTLS_DEPRECATED
  14052. #endif
  14053. /**
  14054. * \brief This function calculates the SHA-512 or SHA-384
  14055. * checksum of a buffer.
  14056. *
  14057. * The function allocates the context, performs the
  14058. * calculation, and frees the context.
  14059. *
  14060. * The SHA-512 result is calculated as
  14061. * output = SHA-512(input buffer).
  14062. *
  14063. * \deprecated Superseded by mbedtls_sha512_ret() in 2.7.0
  14064. *
  14065. * \param input The buffer holding the data.
  14066. * \param ilen The length of the input data.
  14067. * \param output The SHA-384 or SHA-512 checksum result.
  14068. * \param is384 Determines which function to use.
  14069. * <ul><li>0: Use SHA-512.</li>
  14070. * <li>1: Use SHA-384.</li></ul>
  14071. */
  14072. MBEDTLS_DEPRECATED void mbedtls_sha512( const unsigned char *input,
  14073. size_t ilen,
  14074. unsigned char output[64],
  14075. int is384 );
  14076. #undef MBEDTLS_DEPRECATED
  14077. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  14078. /**
  14079. * \brief The SHA-384 or SHA-512 checkup routine.
  14080. *
  14081. * \return \c 0 on success, or \c 1 on failure.
  14082. */
  14083. int mbedtls_sha512_self_test( int verbose );
  14084. #ifdef __cplusplus
  14085. }
  14086. #endif
  14087. #endif /* mbedtls_sha512.h */
  14088. /********* Start of file include/mbedtls/aes.h ************/
  14089. /**
  14090. * \file aes.h
  14091. *
  14092. * \brief The Advanced Encryption Standard (AES) specifies a FIPS-approved
  14093. * cryptographic algorithm that can be used to protect electronic
  14094. * data.
  14095. *
  14096. * The AES algorithm is a symmetric block cipher that can
  14097. * encrypt and decrypt information. For more information, see
  14098. * <em>FIPS Publication 197: Advanced Encryption Standard</em> and
  14099. * <em>ISO/IEC 18033-2:2006: Information technology -- Security
  14100. * techniques -- Encryption algorithms -- Part 2: Asymmetric
  14101. * ciphers</em>.
  14102. */
  14103. /* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
  14104. * SPDX-License-Identifier: Apache-2.0
  14105. *
  14106. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  14107. * not use this file except in compliance with the License.
  14108. * You may obtain a copy of the License at
  14109. *
  14110. * http://www.apache.org/licenses/LICENSE-2.0
  14111. *
  14112. * Unless required by applicable law or agreed to in writing, software
  14113. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14114. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14115. * See the License for the specific language governing permissions and
  14116. * limitations under the License.
  14117. *
  14118. * This file is part of Mbed TLS (https://tls.mbed.org)
  14119. */
  14120. #ifndef MBEDTLS_AES_H
  14121. #define MBEDTLS_AES_H
  14122. #if !defined(MBEDTLS_CONFIG_FILE)
  14123. #else
  14124. #endif
  14125. #include <stddef.h>
  14126. #include <stdint.h>
  14127. /* padlock.c and aesni.c rely on these values! */
  14128. #define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
  14129. #define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
  14130. /* Error codes in range 0x0020-0x0022 */
  14131. #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
  14132. #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
  14133. /* Error codes in range 0x0023-0x0025 */
  14134. #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
  14135. #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
  14136. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  14137. !defined(inline) && !defined(__cplusplus)
  14138. #define inline __inline
  14139. #endif
  14140. #if !defined(MBEDTLS_AES_ALT)
  14141. // Regular implementation
  14142. //
  14143. #ifdef __cplusplus
  14144. extern "C" {
  14145. #endif
  14146. /**
  14147. * \brief The AES context-type definition.
  14148. */
  14149. typedef struct
  14150. {
  14151. int nr; /*!< The number of rounds. */
  14152. uint32_t *rk; /*!< AES round keys. */
  14153. uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
  14154. hold 32 extra Bytes, which can be used for
  14155. one of the following purposes:
  14156. <ul><li>Alignment if VIA padlock is
  14157. used.</li>
  14158. <li>Simplifying key expansion in the 256-bit
  14159. case by generating an extra round key.
  14160. </li></ul> */
  14161. }
  14162. mbedtls_aes_context;
  14163. /**
  14164. * \brief This function initializes the specified AES context.
  14165. *
  14166. * It must be the first API called before using
  14167. * the context.
  14168. *
  14169. * \param ctx The AES context to initialize.
  14170. */
  14171. void mbedtls_aes_init( mbedtls_aes_context *ctx );
  14172. /**
  14173. * \brief This function releases and clears the specified AES context.
  14174. *
  14175. * \param ctx The AES context to clear.
  14176. */
  14177. void mbedtls_aes_free( mbedtls_aes_context *ctx );
  14178. /**
  14179. * \brief This function sets the encryption key.
  14180. *
  14181. * \param ctx The AES context to which the key should be bound.
  14182. * \param key The encryption key.
  14183. * \param keybits The size of data passed in bits. Valid options are:
  14184. * <ul><li>128 bits</li>
  14185. * <li>192 bits</li>
  14186. * <li>256 bits</li></ul>
  14187. *
  14188. * \return \c 0 on success or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
  14189. * on failure.
  14190. */
  14191. int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
  14192. unsigned int keybits );
  14193. /**
  14194. * \brief This function sets the decryption key.
  14195. *
  14196. * \param ctx The AES context to which the key should be bound.
  14197. * \param key The decryption key.
  14198. * \param keybits The size of data passed. Valid options are:
  14199. * <ul><li>128 bits</li>
  14200. * <li>192 bits</li>
  14201. * <li>256 bits</li></ul>
  14202. *
  14203. * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
  14204. */
  14205. int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
  14206. unsigned int keybits );
  14207. /**
  14208. * \brief This function performs an AES single-block encryption or
  14209. * decryption operation.
  14210. *
  14211. * It performs the operation defined in the \p mode parameter
  14212. * (encrypt or decrypt), on the input data buffer defined in
  14213. * the \p input parameter.
  14214. *
  14215. * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
  14216. * mbedtls_aes_setkey_dec() must be called before the first
  14217. * call to this API with the same context.
  14218. *
  14219. * \param ctx The AES context to use for encryption or decryption.
  14220. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  14221. * #MBEDTLS_AES_DECRYPT.
  14222. * \param input The 16-Byte buffer holding the input data.
  14223. * \param output The 16-Byte buffer holding the output data.
  14224. * \return \c 0 on success.
  14225. */
  14226. int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
  14227. int mode,
  14228. const unsigned char input[16],
  14229. unsigned char output[16] );
  14230. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  14231. /**
  14232. * \brief This function performs an AES-CBC encryption or decryption operation
  14233. * on full blocks.
  14234. *
  14235. * It performs the operation defined in the \p mode
  14236. * parameter (encrypt/decrypt), on the input data buffer defined in
  14237. * the \p input parameter.
  14238. *
  14239. * It can be called as many times as needed, until all the input
  14240. * data is processed. mbedtls_aes_init(), and either
  14241. * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
  14242. * before the first call to this API with the same context.
  14243. *
  14244. * \note This function operates on aligned blocks, that is, the input size
  14245. * must be a multiple of the AES block size of 16 Bytes.
  14246. *
  14247. * \note Upon exit, the content of the IV is updated so that you can
  14248. * call the same function again on the next
  14249. * block(s) of data and get the same result as if it was
  14250. * encrypted in one call. This allows a "streaming" usage.
  14251. * If you need to retain the contents of the IV, you should
  14252. * either save it manually or use the cipher module instead.
  14253. *
  14254. *
  14255. * \param ctx The AES context to use for encryption or decryption.
  14256. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  14257. * #MBEDTLS_AES_DECRYPT.
  14258. * \param length The length of the input data in Bytes. This must be a
  14259. * multiple of the block size (16 Bytes).
  14260. * \param iv Initialization vector (updated after use).
  14261. * \param input The buffer holding the input data.
  14262. * \param output The buffer holding the output data.
  14263. *
  14264. * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
  14265. * on failure.
  14266. */
  14267. int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
  14268. int mode,
  14269. size_t length,
  14270. unsigned char iv[16],
  14271. const unsigned char *input,
  14272. unsigned char *output );
  14273. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  14274. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  14275. /**
  14276. * \brief This function performs an AES-CFB128 encryption or decryption
  14277. * operation.
  14278. *
  14279. * It performs the operation defined in the \p mode
  14280. * parameter (encrypt or decrypt), on the input data buffer
  14281. * defined in the \p input parameter.
  14282. *
  14283. * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
  14284. * regardless of whether you are performing an encryption or decryption
  14285. * operation, that is, regardless of the \p mode parameter. This is
  14286. * because CFB mode uses the same key schedule for encryption and
  14287. * decryption.
  14288. *
  14289. * \note Upon exit, the content of the IV is updated so that you can
  14290. * call the same function again on the next
  14291. * block(s) of data and get the same result as if it was
  14292. * encrypted in one call. This allows a "streaming" usage.
  14293. * If you need to retain the contents of the
  14294. * IV, you must either save it manually or use the cipher
  14295. * module instead.
  14296. *
  14297. *
  14298. * \param ctx The AES context to use for encryption or decryption.
  14299. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  14300. * #MBEDTLS_AES_DECRYPT.
  14301. * \param length The length of the input data.
  14302. * \param iv_off The offset in IV (updated after use).
  14303. * \param iv The initialization vector (updated after use).
  14304. * \param input The buffer holding the input data.
  14305. * \param output The buffer holding the output data.
  14306. *
  14307. * \return \c 0 on success.
  14308. */
  14309. int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
  14310. int mode,
  14311. size_t length,
  14312. size_t *iv_off,
  14313. unsigned char iv[16],
  14314. const unsigned char *input,
  14315. unsigned char *output );
  14316. /**
  14317. * \brief This function performs an AES-CFB8 encryption or decryption
  14318. * operation.
  14319. *
  14320. * It performs the operation defined in the \p mode
  14321. * parameter (encrypt/decrypt), on the input data buffer defined
  14322. * in the \p input parameter.
  14323. *
  14324. * Due to the nature of CFB, you must use the same key schedule for
  14325. * both encryption and decryption operations. Therefore, you must
  14326. * use the context initialized with mbedtls_aes_setkey_enc() for
  14327. * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
  14328. *
  14329. * \note Upon exit, the content of the IV is updated so that you can
  14330. * call the same function again on the next
  14331. * block(s) of data and get the same result as if it was
  14332. * encrypted in one call. This allows a "streaming" usage.
  14333. * If you need to retain the contents of the
  14334. * IV, you should either save it manually or use the cipher
  14335. * module instead.
  14336. *
  14337. *
  14338. * \param ctx The AES context to use for encryption or decryption.
  14339. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  14340. * #MBEDTLS_AES_DECRYPT
  14341. * \param length The length of the input data.
  14342. * \param iv The initialization vector (updated after use).
  14343. * \param input The buffer holding the input data.
  14344. * \param output The buffer holding the output data.
  14345. *
  14346. * \return \c 0 on success.
  14347. */
  14348. int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
  14349. int mode,
  14350. size_t length,
  14351. unsigned char iv[16],
  14352. const unsigned char *input,
  14353. unsigned char *output );
  14354. #endif /*MBEDTLS_CIPHER_MODE_CFB */
  14355. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  14356. /**
  14357. * \brief This function performs an AES-CTR encryption or decryption
  14358. * operation.
  14359. *
  14360. * This function performs the operation defined in the \p mode
  14361. * parameter (encrypt/decrypt), on the input data buffer
  14362. * defined in the \p input parameter.
  14363. *
  14364. * Due to the nature of CTR, you must use the same key schedule
  14365. * for both encryption and decryption operations. Therefore, you
  14366. * must use the context initialized with mbedtls_aes_setkey_enc()
  14367. * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
  14368. *
  14369. * \warning You must keep the maximum use of your counter in mind.
  14370. *
  14371. * \param ctx The AES context to use for encryption or decryption.
  14372. * \param length The length of the input data.
  14373. * \param nc_off The offset in the current \p stream_block, for
  14374. * resuming within the current cipher stream. The
  14375. * offset pointer should be 0 at the start of a stream.
  14376. * \param nonce_counter The 128-bit nonce and counter.
  14377. * \param stream_block The saved stream block for resuming. This is
  14378. * overwritten by the function.
  14379. * \param input The buffer holding the input data.
  14380. * \param output The buffer holding the output data.
  14381. *
  14382. * \return \c 0 on success.
  14383. */
  14384. int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
  14385. size_t length,
  14386. size_t *nc_off,
  14387. unsigned char nonce_counter[16],
  14388. unsigned char stream_block[16],
  14389. const unsigned char *input,
  14390. unsigned char *output );
  14391. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  14392. /**
  14393. * \brief Internal AES block encryption function. This is only
  14394. * exposed to allow overriding it using
  14395. * \c MBEDTLS_AES_ENCRYPT_ALT.
  14396. *
  14397. * \param ctx The AES context to use for encryption.
  14398. * \param input The plaintext block.
  14399. * \param output The output (ciphertext) block.
  14400. *
  14401. * \return \c 0 on success.
  14402. */
  14403. int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
  14404. const unsigned char input[16],
  14405. unsigned char output[16] );
  14406. /**
  14407. * \brief Internal AES block decryption function. This is only
  14408. * exposed to allow overriding it using see
  14409. * \c MBEDTLS_AES_DECRYPT_ALT.
  14410. *
  14411. * \param ctx The AES context to use for decryption.
  14412. * \param input The ciphertext block.
  14413. * \param output The output (plaintext) block.
  14414. *
  14415. * \return \c 0 on success.
  14416. */
  14417. int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
  14418. const unsigned char input[16],
  14419. unsigned char output[16] );
  14420. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  14421. #if defined(MBEDTLS_DEPRECATED_WARNING)
  14422. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  14423. #else
  14424. #define MBEDTLS_DEPRECATED
  14425. #endif
  14426. /**
  14427. * \brief Deprecated internal AES block encryption function
  14428. * without return value.
  14429. *
  14430. * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
  14431. *
  14432. * \param ctx The AES context to use for encryption.
  14433. * \param input Plaintext block.
  14434. * \param output Output (ciphertext) block.
  14435. */
  14436. MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
  14437. const unsigned char input[16],
  14438. unsigned char output[16] );
  14439. /**
  14440. * \brief Deprecated internal AES block decryption function
  14441. * without return value.
  14442. *
  14443. * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
  14444. *
  14445. * \param ctx The AES context to use for decryption.
  14446. * \param input Ciphertext block.
  14447. * \param output Output (plaintext) block.
  14448. */
  14449. MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
  14450. const unsigned char input[16],
  14451. unsigned char output[16] );
  14452. #undef MBEDTLS_DEPRECATED
  14453. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  14454. #ifdef __cplusplus
  14455. }
  14456. #endif
  14457. #else /* MBEDTLS_AES_ALT */
  14458. #endif /* MBEDTLS_AES_ALT */
  14459. #ifdef __cplusplus
  14460. extern "C" {
  14461. #endif
  14462. /**
  14463. * \brief Checkup routine.
  14464. *
  14465. * \return \c 0 on success, or \c 1 on failure.
  14466. */
  14467. int mbedtls_aes_self_test( int verbose );
  14468. #ifdef __cplusplus
  14469. }
  14470. #endif
  14471. #endif /* aes.h */
  14472. /********* Start of file include/mbedtls/aesni.h ************/
  14473. /**
  14474. * \file aesni.h
  14475. *
  14476. * \brief AES-NI for hardware AES acceleration on some Intel processors
  14477. */
  14478. /*
  14479. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  14480. * SPDX-License-Identifier: Apache-2.0
  14481. *
  14482. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  14483. * not use this file except in compliance with the License.
  14484. * You may obtain a copy of the License at
  14485. *
  14486. * http://www.apache.org/licenses/LICENSE-2.0
  14487. *
  14488. * Unless required by applicable law or agreed to in writing, software
  14489. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14490. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14491. * See the License for the specific language governing permissions and
  14492. * limitations under the License.
  14493. *
  14494. * This file is part of mbed TLS (https://tls.mbed.org)
  14495. */
  14496. #ifndef MBEDTLS_AESNI_H
  14497. #define MBEDTLS_AESNI_H
  14498. #define MBEDTLS_AESNI_AES 0x02000000u
  14499. #define MBEDTLS_AESNI_CLMUL 0x00000002u
  14500. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
  14501. ( defined(__amd64__) || defined(__x86_64__) ) && \
  14502. ! defined(MBEDTLS_HAVE_X86_64)
  14503. #define MBEDTLS_HAVE_X86_64
  14504. #endif
  14505. #if defined(MBEDTLS_HAVE_X86_64)
  14506. #ifdef __cplusplus
  14507. extern "C" {
  14508. #endif
  14509. /**
  14510. * \brief AES-NI features detection routine
  14511. *
  14512. * \param what The feature to detect
  14513. * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL)
  14514. *
  14515. * \return 1 if CPU has support for the feature, 0 otherwise
  14516. */
  14517. int mbedtls_aesni_has_support( unsigned int what );
  14518. /**
  14519. * \brief AES-NI AES-ECB block en(de)cryption
  14520. *
  14521. * \param ctx AES context
  14522. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  14523. * \param input 16-byte input block
  14524. * \param output 16-byte output block
  14525. *
  14526. * \return 0 on success (cannot fail)
  14527. */
  14528. int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
  14529. int mode,
  14530. const unsigned char input[16],
  14531. unsigned char output[16] );
  14532. /**
  14533. * \brief GCM multiplication: c = a * b in GF(2^128)
  14534. *
  14535. * \param c Result
  14536. * \param a First operand
  14537. * \param b Second operand
  14538. *
  14539. * \note Both operands and result are bit strings interpreted as
  14540. * elements of GF(2^128) as per the GCM spec.
  14541. */
  14542. void mbedtls_aesni_gcm_mult( unsigned char c[16],
  14543. const unsigned char a[16],
  14544. const unsigned char b[16] );
  14545. /**
  14546. * \brief Compute decryption round keys from encryption round keys
  14547. *
  14548. * \param invkey Round keys for the equivalent inverse cipher
  14549. * \param fwdkey Original round keys (for encryption)
  14550. * \param nr Number of rounds (that is, number of round keys minus one)
  14551. */
  14552. void mbedtls_aesni_inverse_key( unsigned char *invkey,
  14553. const unsigned char *fwdkey, int nr );
  14554. /**
  14555. * \brief Perform key expansion (for encryption)
  14556. *
  14557. * \param rk Destination buffer where the round keys are written
  14558. * \param key Encryption key
  14559. * \param bits Key size in bits (must be 128, 192 or 256)
  14560. *
  14561. * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH
  14562. */
  14563. int mbedtls_aesni_setkey_enc( unsigned char *rk,
  14564. const unsigned char *key,
  14565. size_t bits );
  14566. #ifdef __cplusplus
  14567. }
  14568. #endif
  14569. #endif /* MBEDTLS_HAVE_X86_64 */
  14570. #endif /* MBEDTLS_AESNI_H */
  14571. /********* Start of file include/mbedtls/arc4.h ************/
  14572. /**
  14573. * \file arc4.h
  14574. *
  14575. * \brief The ARCFOUR stream cipher
  14576. *
  14577. * \warning ARC4 is considered a weak cipher and its use constitutes a
  14578. * security risk. We recommend considering stronger ciphers instead.
  14579. */
  14580. /*
  14581. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  14582. * SPDX-License-Identifier: Apache-2.0
  14583. *
  14584. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  14585. * not use this file except in compliance with the License.
  14586. * You may obtain a copy of the License at
  14587. *
  14588. * http://www.apache.org/licenses/LICENSE-2.0
  14589. *
  14590. * Unless required by applicable law or agreed to in writing, software
  14591. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14592. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14593. * See the License for the specific language governing permissions and
  14594. * limitations under the License.
  14595. *
  14596. * This file is part of mbed TLS (https://tls.mbed.org)
  14597. *
  14598. */
  14599. #ifndef MBEDTLS_ARC4_H
  14600. #define MBEDTLS_ARC4_H
  14601. #if !defined(MBEDTLS_CONFIG_FILE)
  14602. #else
  14603. #endif
  14604. #include <stddef.h>
  14605. #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */
  14606. #if !defined(MBEDTLS_ARC4_ALT)
  14607. // Regular implementation
  14608. //
  14609. #ifdef __cplusplus
  14610. extern "C" {
  14611. #endif
  14612. /**
  14613. * \brief ARC4 context structure
  14614. *
  14615. * \warning ARC4 is considered a weak cipher and its use constitutes a
  14616. * security risk. We recommend considering stronger ciphers instead.
  14617. *
  14618. */
  14619. typedef struct
  14620. {
  14621. int x; /*!< permutation index */
  14622. int y; /*!< permutation index */
  14623. unsigned char m[256]; /*!< permutation table */
  14624. }
  14625. mbedtls_arc4_context;
  14626. /**
  14627. * \brief Initialize ARC4 context
  14628. *
  14629. * \param ctx ARC4 context to be initialized
  14630. *
  14631. * \warning ARC4 is considered a weak cipher and its use constitutes a
  14632. * security risk. We recommend considering stronger ciphers
  14633. * instead.
  14634. *
  14635. */
  14636. void mbedtls_arc4_init( mbedtls_arc4_context *ctx );
  14637. /**
  14638. * \brief Clear ARC4 context
  14639. *
  14640. * \param ctx ARC4 context to be cleared
  14641. *
  14642. * \warning ARC4 is considered a weak cipher and its use constitutes a
  14643. * security risk. We recommend considering stronger ciphers
  14644. * instead.
  14645. *
  14646. */
  14647. void mbedtls_arc4_free( mbedtls_arc4_context *ctx );
  14648. /**
  14649. * \brief ARC4 key schedule
  14650. *
  14651. * \param ctx ARC4 context to be setup
  14652. * \param key the secret key
  14653. * \param keylen length of the key, in bytes
  14654. *
  14655. * \warning ARC4 is considered a weak cipher and its use constitutes a
  14656. * security risk. We recommend considering stronger ciphers
  14657. * instead.
  14658. *
  14659. */
  14660. void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key,
  14661. unsigned int keylen );
  14662. /**
  14663. * \brief ARC4 cipher function
  14664. *
  14665. * \param ctx ARC4 context
  14666. * \param length length of the input data
  14667. * \param input buffer holding the input data
  14668. * \param output buffer for the output data
  14669. *
  14670. * \return 0 if successful
  14671. *
  14672. * \warning ARC4 is considered a weak cipher and its use constitutes a
  14673. * security risk. We recommend considering stronger ciphers
  14674. * instead.
  14675. *
  14676. */
  14677. int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input,
  14678. unsigned char *output );
  14679. #ifdef __cplusplus
  14680. }
  14681. #endif
  14682. #else /* MBEDTLS_ARC4_ALT */
  14683. #endif /* MBEDTLS_ARC4_ALT */
  14684. #ifdef __cplusplus
  14685. extern "C" {
  14686. #endif
  14687. /**
  14688. * \brief Checkup routine
  14689. *
  14690. * \return 0 if successful, or 1 if the test failed
  14691. *
  14692. * \warning ARC4 is considered a weak cipher and its use constitutes a
  14693. * security risk. We recommend considering stronger ciphers
  14694. * instead.
  14695. *
  14696. */
  14697. int mbedtls_arc4_self_test( int verbose );
  14698. #ifdef __cplusplus
  14699. }
  14700. #endif
  14701. #endif /* arc4.h */
  14702. /********* Start of file include/mbedtls/base64.h ************/
  14703. /**
  14704. * \file base64.h
  14705. *
  14706. * \brief RFC 1521 base64 encoding/decoding
  14707. */
  14708. /*
  14709. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  14710. * SPDX-License-Identifier: Apache-2.0
  14711. *
  14712. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  14713. * not use this file except in compliance with the License.
  14714. * You may obtain a copy of the License at
  14715. *
  14716. * http://www.apache.org/licenses/LICENSE-2.0
  14717. *
  14718. * Unless required by applicable law or agreed to in writing, software
  14719. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14720. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14721. * See the License for the specific language governing permissions and
  14722. * limitations under the License.
  14723. *
  14724. * This file is part of mbed TLS (https://tls.mbed.org)
  14725. */
  14726. #ifndef MBEDTLS_BASE64_H
  14727. #define MBEDTLS_BASE64_H
  14728. #include <stddef.h>
  14729. #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
  14730. #define MBEDTLS_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
  14731. #ifdef __cplusplus
  14732. extern "C" {
  14733. #endif
  14734. /**
  14735. * \brief Encode a buffer into base64 format
  14736. *
  14737. * \param dst destination buffer
  14738. * \param dlen size of the destination buffer
  14739. * \param olen number of bytes written
  14740. * \param src source buffer
  14741. * \param slen amount of data to be encoded
  14742. *
  14743. * \return 0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
  14744. * *olen is always updated to reflect the amount
  14745. * of data that has (or would have) been written.
  14746. * If that length cannot be represented, then no data is
  14747. * written to the buffer and *olen is set to the maximum
  14748. * length representable as a size_t.
  14749. *
  14750. * \note Call this function with dlen = 0 to obtain the
  14751. * required buffer size in *olen
  14752. */
  14753. int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
  14754. const unsigned char *src, size_t slen );
  14755. /**
  14756. * \brief Decode a base64-formatted buffer
  14757. *
  14758. * \param dst destination buffer (can be NULL for checking size)
  14759. * \param dlen size of the destination buffer
  14760. * \param olen number of bytes written
  14761. * \param src source buffer
  14762. * \param slen amount of data to be decoded
  14763. *
  14764. * \return 0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
  14765. * MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
  14766. * not correct. *olen is always updated to reflect the amount
  14767. * of data that has (or would have) been written.
  14768. *
  14769. * \note Call this function with *dst = NULL or dlen = 0 to obtain
  14770. * the required buffer size in *olen
  14771. */
  14772. int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
  14773. const unsigned char *src, size_t slen );
  14774. /**
  14775. * \brief Checkup routine
  14776. *
  14777. * \return 0 if successful, or 1 if the test failed
  14778. */
  14779. int mbedtls_base64_self_test( int verbose );
  14780. #ifdef __cplusplus
  14781. }
  14782. #endif
  14783. #endif /* base64.h */
  14784. /********* Start of file include/mbedtls/bn_mul.h ************/
  14785. /**
  14786. * \file bn_mul.h
  14787. *
  14788. * \brief Multi-precision integer library
  14789. */
  14790. /*
  14791. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  14792. * SPDX-License-Identifier: Apache-2.0
  14793. *
  14794. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  14795. * not use this file except in compliance with the License.
  14796. * You may obtain a copy of the License at
  14797. *
  14798. * http://www.apache.org/licenses/LICENSE-2.0
  14799. *
  14800. * Unless required by applicable law or agreed to in writing, software
  14801. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14802. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14803. * See the License for the specific language governing permissions and
  14804. * limitations under the License.
  14805. *
  14806. * This file is part of mbed TLS (https://tls.mbed.org)
  14807. */
  14808. /*
  14809. * Multiply source vector [s] with b, add result
  14810. * to destination vector [d] and set carry c.
  14811. *
  14812. * Currently supports:
  14813. *
  14814. * . IA-32 (386+) . AMD64 / EM64T
  14815. * . IA-32 (SSE2) . Motorola 68000
  14816. * . PowerPC, 32-bit . MicroBlaze
  14817. * . PowerPC, 64-bit . TriCore
  14818. * . SPARC v8 . ARM v3+
  14819. * . Alpha . MIPS32
  14820. * . C, longlong . C, generic
  14821. */
  14822. #ifndef MBEDTLS_BN_MUL_H
  14823. #define MBEDTLS_BN_MUL_H
  14824. #if defined(MBEDTLS_HAVE_ASM)
  14825. #ifndef asm
  14826. #define asm __asm
  14827. #endif
  14828. /* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
  14829. #if defined(__GNUC__) && \
  14830. ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
  14831. #if defined(__i386__)
  14832. #define MULADDC_INIT \
  14833. asm( \
  14834. "movl %%ebx, %0 \n\t" \
  14835. "movl %5, %%esi \n\t" \
  14836. "movl %6, %%edi \n\t" \
  14837. "movl %7, %%ecx \n\t" \
  14838. "movl %8, %%ebx \n\t"
  14839. #define MULADDC_CORE \
  14840. "lodsl \n\t" \
  14841. "mull %%ebx \n\t" \
  14842. "addl %%ecx, %%eax \n\t" \
  14843. "adcl $0, %%edx \n\t" \
  14844. "addl (%%edi), %%eax \n\t" \
  14845. "adcl $0, %%edx \n\t" \
  14846. "movl %%edx, %%ecx \n\t" \
  14847. "stosl \n\t"
  14848. #if defined(MBEDTLS_HAVE_SSE2)
  14849. #define MULADDC_HUIT \
  14850. "movd %%ecx, %%mm1 \n\t" \
  14851. "movd %%ebx, %%mm0 \n\t" \
  14852. "movd (%%edi), %%mm3 \n\t" \
  14853. "paddq %%mm3, %%mm1 \n\t" \
  14854. "movd (%%esi), %%mm2 \n\t" \
  14855. "pmuludq %%mm0, %%mm2 \n\t" \
  14856. "movd 4(%%esi), %%mm4 \n\t" \
  14857. "pmuludq %%mm0, %%mm4 \n\t" \
  14858. "movd 8(%%esi), %%mm6 \n\t" \
  14859. "pmuludq %%mm0, %%mm6 \n\t" \
  14860. "movd 12(%%esi), %%mm7 \n\t" \
  14861. "pmuludq %%mm0, %%mm7 \n\t" \
  14862. "paddq %%mm2, %%mm1 \n\t" \
  14863. "movd 4(%%edi), %%mm3 \n\t" \
  14864. "paddq %%mm4, %%mm3 \n\t" \
  14865. "movd 8(%%edi), %%mm5 \n\t" \
  14866. "paddq %%mm6, %%mm5 \n\t" \
  14867. "movd 12(%%edi), %%mm4 \n\t" \
  14868. "paddq %%mm4, %%mm7 \n\t" \
  14869. "movd %%mm1, (%%edi) \n\t" \
  14870. "movd 16(%%esi), %%mm2 \n\t" \
  14871. "pmuludq %%mm0, %%mm2 \n\t" \
  14872. "psrlq $32, %%mm1 \n\t" \
  14873. "movd 20(%%esi), %%mm4 \n\t" \
  14874. "pmuludq %%mm0, %%mm4 \n\t" \
  14875. "paddq %%mm3, %%mm1 \n\t" \
  14876. "movd 24(%%esi), %%mm6 \n\t" \
  14877. "pmuludq %%mm0, %%mm6 \n\t" \
  14878. "movd %%mm1, 4(%%edi) \n\t" \
  14879. "psrlq $32, %%mm1 \n\t" \
  14880. "movd 28(%%esi), %%mm3 \n\t" \
  14881. "pmuludq %%mm0, %%mm3 \n\t" \
  14882. "paddq %%mm5, %%mm1 \n\t" \
  14883. "movd 16(%%edi), %%mm5 \n\t" \
  14884. "paddq %%mm5, %%mm2 \n\t" \
  14885. "movd %%mm1, 8(%%edi) \n\t" \
  14886. "psrlq $32, %%mm1 \n\t" \
  14887. "paddq %%mm7, %%mm1 \n\t" \
  14888. "movd 20(%%edi), %%mm5 \n\t" \
  14889. "paddq %%mm5, %%mm4 \n\t" \
  14890. "movd %%mm1, 12(%%edi) \n\t" \
  14891. "psrlq $32, %%mm1 \n\t" \
  14892. "paddq %%mm2, %%mm1 \n\t" \
  14893. "movd 24(%%edi), %%mm5 \n\t" \
  14894. "paddq %%mm5, %%mm6 \n\t" \
  14895. "movd %%mm1, 16(%%edi) \n\t" \
  14896. "psrlq $32, %%mm1 \n\t" \
  14897. "paddq %%mm4, %%mm1 \n\t" \
  14898. "movd 28(%%edi), %%mm5 \n\t" \
  14899. "paddq %%mm5, %%mm3 \n\t" \
  14900. "movd %%mm1, 20(%%edi) \n\t" \
  14901. "psrlq $32, %%mm1 \n\t" \
  14902. "paddq %%mm6, %%mm1 \n\t" \
  14903. "movd %%mm1, 24(%%edi) \n\t" \
  14904. "psrlq $32, %%mm1 \n\t" \
  14905. "paddq %%mm3, %%mm1 \n\t" \
  14906. "movd %%mm1, 28(%%edi) \n\t" \
  14907. "addl $32, %%edi \n\t" \
  14908. "addl $32, %%esi \n\t" \
  14909. "psrlq $32, %%mm1 \n\t" \
  14910. "movd %%mm1, %%ecx \n\t"
  14911. #define MULADDC_STOP \
  14912. "emms \n\t" \
  14913. "movl %4, %%ebx \n\t" \
  14914. "movl %%ecx, %1 \n\t" \
  14915. "movl %%edi, %2 \n\t" \
  14916. "movl %%esi, %3 \n\t" \
  14917. : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
  14918. : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
  14919. : "eax", "ecx", "edx", "esi", "edi" \
  14920. );
  14921. #else
  14922. #define MULADDC_STOP \
  14923. "movl %4, %%ebx \n\t" \
  14924. "movl %%ecx, %1 \n\t" \
  14925. "movl %%edi, %2 \n\t" \
  14926. "movl %%esi, %3 \n\t" \
  14927. : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
  14928. : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
  14929. : "eax", "ecx", "edx", "esi", "edi" \
  14930. );
  14931. #endif /* SSE2 */
  14932. #endif /* i386 */
  14933. #if defined(__amd64__) || defined (__x86_64__)
  14934. #define MULADDC_INIT \
  14935. asm( \
  14936. "xorq %%r8, %%r8 \n\t"
  14937. #define MULADDC_CORE \
  14938. "movq (%%rsi), %%rax \n\t" \
  14939. "mulq %%rbx \n\t" \
  14940. "addq $8, %%rsi \n\t" \
  14941. "addq %%rcx, %%rax \n\t" \
  14942. "movq %%r8, %%rcx \n\t" \
  14943. "adcq $0, %%rdx \n\t" \
  14944. "nop \n\t" \
  14945. "addq %%rax, (%%rdi) \n\t" \
  14946. "adcq %%rdx, %%rcx \n\t" \
  14947. "addq $8, %%rdi \n\t"
  14948. #define MULADDC_STOP \
  14949. : "+c" (c), "+D" (d), "+S" (s) \
  14950. : "b" (b) \
  14951. : "rax", "rdx", "r8" \
  14952. );
  14953. #endif /* AMD64 */
  14954. #if defined(__mc68020__) || defined(__mcpu32__)
  14955. #define MULADDC_INIT \
  14956. asm( \
  14957. "movl %3, %%a2 \n\t" \
  14958. "movl %4, %%a3 \n\t" \
  14959. "movl %5, %%d3 \n\t" \
  14960. "movl %6, %%d2 \n\t" \
  14961. "moveq #0, %%d0 \n\t"
  14962. #define MULADDC_CORE \
  14963. "movel %%a2@+, %%d1 \n\t" \
  14964. "mulul %%d2, %%d4:%%d1 \n\t" \
  14965. "addl %%d3, %%d1 \n\t" \
  14966. "addxl %%d0, %%d4 \n\t" \
  14967. "moveq #0, %%d3 \n\t" \
  14968. "addl %%d1, %%a3@+ \n\t" \
  14969. "addxl %%d4, %%d3 \n\t"
  14970. #define MULADDC_STOP \
  14971. "movl %%d3, %0 \n\t" \
  14972. "movl %%a3, %1 \n\t" \
  14973. "movl %%a2, %2 \n\t" \
  14974. : "=m" (c), "=m" (d), "=m" (s) \
  14975. : "m" (s), "m" (d), "m" (c), "m" (b) \
  14976. : "d0", "d1", "d2", "d3", "d4", "a2", "a3" \
  14977. );
  14978. #define MULADDC_HUIT \
  14979. "movel %%a2@+, %%d1 \n\t" \
  14980. "mulul %%d2, %%d4:%%d1 \n\t" \
  14981. "addxl %%d3, %%d1 \n\t" \
  14982. "addxl %%d0, %%d4 \n\t" \
  14983. "addl %%d1, %%a3@+ \n\t" \
  14984. "movel %%a2@+, %%d1 \n\t" \
  14985. "mulul %%d2, %%d3:%%d1 \n\t" \
  14986. "addxl %%d4, %%d1 \n\t" \
  14987. "addxl %%d0, %%d3 \n\t" \
  14988. "addl %%d1, %%a3@+ \n\t" \
  14989. "movel %%a2@+, %%d1 \n\t" \
  14990. "mulul %%d2, %%d4:%%d1 \n\t" \
  14991. "addxl %%d3, %%d1 \n\t" \
  14992. "addxl %%d0, %%d4 \n\t" \
  14993. "addl %%d1, %%a3@+ \n\t" \
  14994. "movel %%a2@+, %%d1 \n\t" \
  14995. "mulul %%d2, %%d3:%%d1 \n\t" \
  14996. "addxl %%d4, %%d1 \n\t" \
  14997. "addxl %%d0, %%d3 \n\t" \
  14998. "addl %%d1, %%a3@+ \n\t" \
  14999. "movel %%a2@+, %%d1 \n\t" \
  15000. "mulul %%d2, %%d4:%%d1 \n\t" \
  15001. "addxl %%d3, %%d1 \n\t" \
  15002. "addxl %%d0, %%d4 \n\t" \
  15003. "addl %%d1, %%a3@+ \n\t" \
  15004. "movel %%a2@+, %%d1 \n\t" \
  15005. "mulul %%d2, %%d3:%%d1 \n\t" \
  15006. "addxl %%d4, %%d1 \n\t" \
  15007. "addxl %%d0, %%d3 \n\t" \
  15008. "addl %%d1, %%a3@+ \n\t" \
  15009. "movel %%a2@+, %%d1 \n\t" \
  15010. "mulul %%d2, %%d4:%%d1 \n\t" \
  15011. "addxl %%d3, %%d1 \n\t" \
  15012. "addxl %%d0, %%d4 \n\t" \
  15013. "addl %%d1, %%a3@+ \n\t" \
  15014. "movel %%a2@+, %%d1 \n\t" \
  15015. "mulul %%d2, %%d3:%%d1 \n\t" \
  15016. "addxl %%d4, %%d1 \n\t" \
  15017. "addxl %%d0, %%d3 \n\t" \
  15018. "addl %%d1, %%a3@+ \n\t" \
  15019. "addxl %%d0, %%d3 \n\t"
  15020. #endif /* MC68000 */
  15021. #if defined(__powerpc64__) || defined(__ppc64__)
  15022. #if defined(__MACH__) && defined(__APPLE__)
  15023. #define MULADDC_INIT \
  15024. asm( \
  15025. "ld r3, %3 \n\t" \
  15026. "ld r4, %4 \n\t" \
  15027. "ld r5, %5 \n\t" \
  15028. "ld r6, %6 \n\t" \
  15029. "addi r3, r3, -8 \n\t" \
  15030. "addi r4, r4, -8 \n\t" \
  15031. "addic r5, r5, 0 \n\t"
  15032. #define MULADDC_CORE \
  15033. "ldu r7, 8(r3) \n\t" \
  15034. "mulld r8, r7, r6 \n\t" \
  15035. "mulhdu r9, r7, r6 \n\t" \
  15036. "adde r8, r8, r5 \n\t" \
  15037. "ld r7, 8(r4) \n\t" \
  15038. "addze r5, r9 \n\t" \
  15039. "addc r8, r8, r7 \n\t" \
  15040. "stdu r8, 8(r4) \n\t"
  15041. #define MULADDC_STOP \
  15042. "addze r5, r5 \n\t" \
  15043. "addi r4, r4, 8 \n\t" \
  15044. "addi r3, r3, 8 \n\t" \
  15045. "std r5, %0 \n\t" \
  15046. "std r4, %1 \n\t" \
  15047. "std r3, %2 \n\t" \
  15048. : "=m" (c), "=m" (d), "=m" (s) \
  15049. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15050. : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
  15051. );
  15052. #else /* __MACH__ && __APPLE__ */
  15053. #define MULADDC_INIT \
  15054. asm( \
  15055. "ld %%r3, %3 \n\t" \
  15056. "ld %%r4, %4 \n\t" \
  15057. "ld %%r5, %5 \n\t" \
  15058. "ld %%r6, %6 \n\t" \
  15059. "addi %%r3, %%r3, -8 \n\t" \
  15060. "addi %%r4, %%r4, -8 \n\t" \
  15061. "addic %%r5, %%r5, 0 \n\t"
  15062. #define MULADDC_CORE \
  15063. "ldu %%r7, 8(%%r3) \n\t" \
  15064. "mulld %%r8, %%r7, %%r6 \n\t" \
  15065. "mulhdu %%r9, %%r7, %%r6 \n\t" \
  15066. "adde %%r8, %%r8, %%r5 \n\t" \
  15067. "ld %%r7, 8(%%r4) \n\t" \
  15068. "addze %%r5, %%r9 \n\t" \
  15069. "addc %%r8, %%r8, %%r7 \n\t" \
  15070. "stdu %%r8, 8(%%r4) \n\t"
  15071. #define MULADDC_STOP \
  15072. "addze %%r5, %%r5 \n\t" \
  15073. "addi %%r4, %%r4, 8 \n\t" \
  15074. "addi %%r3, %%r3, 8 \n\t" \
  15075. "std %%r5, %0 \n\t" \
  15076. "std %%r4, %1 \n\t" \
  15077. "std %%r3, %2 \n\t" \
  15078. : "=m" (c), "=m" (d), "=m" (s) \
  15079. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15080. : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
  15081. );
  15082. #endif /* __MACH__ && __APPLE__ */
  15083. #elif defined(__powerpc__) || defined(__ppc__) /* end PPC64/begin PPC32 */
  15084. #if defined(__MACH__) && defined(__APPLE__)
  15085. #define MULADDC_INIT \
  15086. asm( \
  15087. "lwz r3, %3 \n\t" \
  15088. "lwz r4, %4 \n\t" \
  15089. "lwz r5, %5 \n\t" \
  15090. "lwz r6, %6 \n\t" \
  15091. "addi r3, r3, -4 \n\t" \
  15092. "addi r4, r4, -4 \n\t" \
  15093. "addic r5, r5, 0 \n\t"
  15094. #define MULADDC_CORE \
  15095. "lwzu r7, 4(r3) \n\t" \
  15096. "mullw r8, r7, r6 \n\t" \
  15097. "mulhwu r9, r7, r6 \n\t" \
  15098. "adde r8, r8, r5 \n\t" \
  15099. "lwz r7, 4(r4) \n\t" \
  15100. "addze r5, r9 \n\t" \
  15101. "addc r8, r8, r7 \n\t" \
  15102. "stwu r8, 4(r4) \n\t"
  15103. #define MULADDC_STOP \
  15104. "addze r5, r5 \n\t" \
  15105. "addi r4, r4, 4 \n\t" \
  15106. "addi r3, r3, 4 \n\t" \
  15107. "stw r5, %0 \n\t" \
  15108. "stw r4, %1 \n\t" \
  15109. "stw r3, %2 \n\t" \
  15110. : "=m" (c), "=m" (d), "=m" (s) \
  15111. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15112. : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
  15113. );
  15114. #else /* __MACH__ && __APPLE__ */
  15115. #define MULADDC_INIT \
  15116. asm( \
  15117. "lwz %%r3, %3 \n\t" \
  15118. "lwz %%r4, %4 \n\t" \
  15119. "lwz %%r5, %5 \n\t" \
  15120. "lwz %%r6, %6 \n\t" \
  15121. "addi %%r3, %%r3, -4 \n\t" \
  15122. "addi %%r4, %%r4, -4 \n\t" \
  15123. "addic %%r5, %%r5, 0 \n\t"
  15124. #define MULADDC_CORE \
  15125. "lwzu %%r7, 4(%%r3) \n\t" \
  15126. "mullw %%r8, %%r7, %%r6 \n\t" \
  15127. "mulhwu %%r9, %%r7, %%r6 \n\t" \
  15128. "adde %%r8, %%r8, %%r5 \n\t" \
  15129. "lwz %%r7, 4(%%r4) \n\t" \
  15130. "addze %%r5, %%r9 \n\t" \
  15131. "addc %%r8, %%r8, %%r7 \n\t" \
  15132. "stwu %%r8, 4(%%r4) \n\t"
  15133. #define MULADDC_STOP \
  15134. "addze %%r5, %%r5 \n\t" \
  15135. "addi %%r4, %%r4, 4 \n\t" \
  15136. "addi %%r3, %%r3, 4 \n\t" \
  15137. "stw %%r5, %0 \n\t" \
  15138. "stw %%r4, %1 \n\t" \
  15139. "stw %%r3, %2 \n\t" \
  15140. : "=m" (c), "=m" (d), "=m" (s) \
  15141. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15142. : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
  15143. );
  15144. #endif /* __MACH__ && __APPLE__ */
  15145. #endif /* PPC32 */
  15146. /*
  15147. * The Sparc(64) assembly is reported to be broken.
  15148. * Disable it for now, until we're able to fix it.
  15149. */
  15150. #if 0 && defined(__sparc__)
  15151. #if defined(__sparc64__)
  15152. #define MULADDC_INIT \
  15153. asm( \
  15154. "ldx %3, %%o0 \n\t" \
  15155. "ldx %4, %%o1 \n\t" \
  15156. "ld %5, %%o2 \n\t" \
  15157. "ld %6, %%o3 \n\t"
  15158. #define MULADDC_CORE \
  15159. "ld [%%o0], %%o4 \n\t" \
  15160. "inc 4, %%o0 \n\t" \
  15161. "ld [%%o1], %%o5 \n\t" \
  15162. "umul %%o3, %%o4, %%o4 \n\t" \
  15163. "addcc %%o4, %%o2, %%o4 \n\t" \
  15164. "rd %%y, %%g1 \n\t" \
  15165. "addx %%g1, 0, %%g1 \n\t" \
  15166. "addcc %%o4, %%o5, %%o4 \n\t" \
  15167. "st %%o4, [%%o1] \n\t" \
  15168. "addx %%g1, 0, %%o2 \n\t" \
  15169. "inc 4, %%o1 \n\t"
  15170. #define MULADDC_STOP \
  15171. "st %%o2, %0 \n\t" \
  15172. "stx %%o1, %1 \n\t" \
  15173. "stx %%o0, %2 \n\t" \
  15174. : "=m" (c), "=m" (d), "=m" (s) \
  15175. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15176. : "g1", "o0", "o1", "o2", "o3", "o4", \
  15177. "o5" \
  15178. );
  15179. #else /* __sparc64__ */
  15180. #define MULADDC_INIT \
  15181. asm( \
  15182. "ld %3, %%o0 \n\t" \
  15183. "ld %4, %%o1 \n\t" \
  15184. "ld %5, %%o2 \n\t" \
  15185. "ld %6, %%o3 \n\t"
  15186. #define MULADDC_CORE \
  15187. "ld [%%o0], %%o4 \n\t" \
  15188. "inc 4, %%o0 \n\t" \
  15189. "ld [%%o1], %%o5 \n\t" \
  15190. "umul %%o3, %%o4, %%o4 \n\t" \
  15191. "addcc %%o4, %%o2, %%o4 \n\t" \
  15192. "rd %%y, %%g1 \n\t" \
  15193. "addx %%g1, 0, %%g1 \n\t" \
  15194. "addcc %%o4, %%o5, %%o4 \n\t" \
  15195. "st %%o4, [%%o1] \n\t" \
  15196. "addx %%g1, 0, %%o2 \n\t" \
  15197. "inc 4, %%o1 \n\t"
  15198. #define MULADDC_STOP \
  15199. "st %%o2, %0 \n\t" \
  15200. "st %%o1, %1 \n\t" \
  15201. "st %%o0, %2 \n\t" \
  15202. : "=m" (c), "=m" (d), "=m" (s) \
  15203. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15204. : "g1", "o0", "o1", "o2", "o3", "o4", \
  15205. "o5" \
  15206. );
  15207. #endif /* __sparc64__ */
  15208. #endif /* __sparc__ */
  15209. #if defined(__microblaze__) || defined(microblaze)
  15210. #define MULADDC_INIT \
  15211. asm( \
  15212. "lwi r3, %3 \n\t" \
  15213. "lwi r4, %4 \n\t" \
  15214. "lwi r5, %5 \n\t" \
  15215. "lwi r6, %6 \n\t" \
  15216. "andi r7, r6, 0xffff \n\t" \
  15217. "bsrli r6, r6, 16 \n\t"
  15218. #define MULADDC_CORE \
  15219. "lhui r8, r3, 0 \n\t" \
  15220. "addi r3, r3, 2 \n\t" \
  15221. "lhui r9, r3, 0 \n\t" \
  15222. "addi r3, r3, 2 \n\t" \
  15223. "mul r10, r9, r6 \n\t" \
  15224. "mul r11, r8, r7 \n\t" \
  15225. "mul r12, r9, r7 \n\t" \
  15226. "mul r13, r8, r6 \n\t" \
  15227. "bsrli r8, r10, 16 \n\t" \
  15228. "bsrli r9, r11, 16 \n\t" \
  15229. "add r13, r13, r8 \n\t" \
  15230. "add r13, r13, r9 \n\t" \
  15231. "bslli r10, r10, 16 \n\t" \
  15232. "bslli r11, r11, 16 \n\t" \
  15233. "add r12, r12, r10 \n\t" \
  15234. "addc r13, r13, r0 \n\t" \
  15235. "add r12, r12, r11 \n\t" \
  15236. "addc r13, r13, r0 \n\t" \
  15237. "lwi r10, r4, 0 \n\t" \
  15238. "add r12, r12, r10 \n\t" \
  15239. "addc r13, r13, r0 \n\t" \
  15240. "add r12, r12, r5 \n\t" \
  15241. "addc r5, r13, r0 \n\t" \
  15242. "swi r12, r4, 0 \n\t" \
  15243. "addi r4, r4, 4 \n\t"
  15244. #define MULADDC_STOP \
  15245. "swi r5, %0 \n\t" \
  15246. "swi r4, %1 \n\t" \
  15247. "swi r3, %2 \n\t" \
  15248. : "=m" (c), "=m" (d), "=m" (s) \
  15249. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15250. : "r3", "r4" "r5", "r6", "r7", "r8", \
  15251. "r9", "r10", "r11", "r12", "r13" \
  15252. );
  15253. #endif /* MicroBlaze */
  15254. #if defined(__tricore__)
  15255. #define MULADDC_INIT \
  15256. asm( \
  15257. "ld.a %%a2, %3 \n\t" \
  15258. "ld.a %%a3, %4 \n\t" \
  15259. "ld.w %%d4, %5 \n\t" \
  15260. "ld.w %%d1, %6 \n\t" \
  15261. "xor %%d5, %%d5 \n\t"
  15262. #define MULADDC_CORE \
  15263. "ld.w %%d0, [%%a2+] \n\t" \
  15264. "madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \
  15265. "ld.w %%d0, [%%a3] \n\t" \
  15266. "addx %%d2, %%d2, %%d0 \n\t" \
  15267. "addc %%d3, %%d3, 0 \n\t" \
  15268. "mov %%d4, %%d3 \n\t" \
  15269. "st.w [%%a3+], %%d2 \n\t"
  15270. #define MULADDC_STOP \
  15271. "st.w %0, %%d4 \n\t" \
  15272. "st.a %1, %%a3 \n\t" \
  15273. "st.a %2, %%a2 \n\t" \
  15274. : "=m" (c), "=m" (d), "=m" (s) \
  15275. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15276. : "d0", "d1", "e2", "d4", "a2", "a3" \
  15277. );
  15278. #endif /* TriCore */
  15279. /*
  15280. * gcc -O0 by default uses r7 for the frame pointer, so it complains about our
  15281. * use of r7 below, unless -fomit-frame-pointer is passed. Unfortunately,
  15282. * passing that option is not easy when building with yotta.
  15283. *
  15284. * On the other hand, -fomit-frame-pointer is implied by any -Ox options with
  15285. * x !=0, which we can detect using __OPTIMIZE__ (which is also defined by
  15286. * clang and armcc5 under the same conditions).
  15287. *
  15288. * So, only use the optimized assembly below for optimized build, which avoids
  15289. * the build error and is pretty reasonable anyway.
  15290. */
  15291. #if defined(__GNUC__) && !defined(__OPTIMIZE__)
  15292. #define MULADDC_CANNOT_USE_R7
  15293. #endif
  15294. #if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7)
  15295. #if defined(__thumb__) && !defined(__thumb2__)
  15296. #define MULADDC_INIT \
  15297. asm( \
  15298. "ldr r0, %3 \n\t" \
  15299. "ldr r1, %4 \n\t" \
  15300. "ldr r2, %5 \n\t" \
  15301. "ldr r3, %6 \n\t" \
  15302. "lsr r7, r3, #16 \n\t" \
  15303. "mov r9, r7 \n\t" \
  15304. "lsl r7, r3, #16 \n\t" \
  15305. "lsr r7, r7, #16 \n\t" \
  15306. "mov r8, r7 \n\t"
  15307. #define MULADDC_CORE \
  15308. "ldmia r0!, {r6} \n\t" \
  15309. "lsr r7, r6, #16 \n\t" \
  15310. "lsl r6, r6, #16 \n\t" \
  15311. "lsr r6, r6, #16 \n\t" \
  15312. "mov r4, r8 \n\t" \
  15313. "mul r4, r6 \n\t" \
  15314. "mov r3, r9 \n\t" \
  15315. "mul r6, r3 \n\t" \
  15316. "mov r5, r9 \n\t" \
  15317. "mul r5, r7 \n\t" \
  15318. "mov r3, r8 \n\t" \
  15319. "mul r7, r3 \n\t" \
  15320. "lsr r3, r6, #16 \n\t" \
  15321. "add r5, r5, r3 \n\t" \
  15322. "lsr r3, r7, #16 \n\t" \
  15323. "add r5, r5, r3 \n\t" \
  15324. "add r4, r4, r2 \n\t" \
  15325. "mov r2, #0 \n\t" \
  15326. "adc r5, r2 \n\t" \
  15327. "lsl r3, r6, #16 \n\t" \
  15328. "add r4, r4, r3 \n\t" \
  15329. "adc r5, r2 \n\t" \
  15330. "lsl r3, r7, #16 \n\t" \
  15331. "add r4, r4, r3 \n\t" \
  15332. "adc r5, r2 \n\t" \
  15333. "ldr r3, [r1] \n\t" \
  15334. "add r4, r4, r3 \n\t" \
  15335. "adc r2, r5 \n\t" \
  15336. "stmia r1!, {r4} \n\t"
  15337. #define MULADDC_STOP \
  15338. "str r2, %0 \n\t" \
  15339. "str r1, %1 \n\t" \
  15340. "str r0, %2 \n\t" \
  15341. : "=m" (c), "=m" (d), "=m" (s) \
  15342. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15343. : "r0", "r1", "r2", "r3", "r4", "r5", \
  15344. "r6", "r7", "r8", "r9", "cc" \
  15345. );
  15346. #else
  15347. #define MULADDC_INIT \
  15348. asm( \
  15349. "ldr r0, %3 \n\t" \
  15350. "ldr r1, %4 \n\t" \
  15351. "ldr r2, %5 \n\t" \
  15352. "ldr r3, %6 \n\t"
  15353. #define MULADDC_CORE \
  15354. "ldr r4, [r0], #4 \n\t" \
  15355. "mov r5, #0 \n\t" \
  15356. "ldr r6, [r1] \n\t" \
  15357. "umlal r2, r5, r3, r4 \n\t" \
  15358. "adds r7, r6, r2 \n\t" \
  15359. "adc r2, r5, #0 \n\t" \
  15360. "str r7, [r1], #4 \n\t"
  15361. #define MULADDC_STOP \
  15362. "str r2, %0 \n\t" \
  15363. "str r1, %1 \n\t" \
  15364. "str r0, %2 \n\t" \
  15365. : "=m" (c), "=m" (d), "=m" (s) \
  15366. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15367. : "r0", "r1", "r2", "r3", "r4", "r5", \
  15368. "r6", "r7", "cc" \
  15369. );
  15370. #endif /* Thumb */
  15371. #endif /* ARMv3 */
  15372. #if defined(__alpha__)
  15373. #define MULADDC_INIT \
  15374. asm( \
  15375. "ldq $1, %3 \n\t" \
  15376. "ldq $2, %4 \n\t" \
  15377. "ldq $3, %5 \n\t" \
  15378. "ldq $4, %6 \n\t"
  15379. #define MULADDC_CORE \
  15380. "ldq $6, 0($1) \n\t" \
  15381. "addq $1, 8, $1 \n\t" \
  15382. "mulq $6, $4, $7 \n\t" \
  15383. "umulh $6, $4, $6 \n\t" \
  15384. "addq $7, $3, $7 \n\t" \
  15385. "cmpult $7, $3, $3 \n\t" \
  15386. "ldq $5, 0($2) \n\t" \
  15387. "addq $7, $5, $7 \n\t" \
  15388. "cmpult $7, $5, $5 \n\t" \
  15389. "stq $7, 0($2) \n\t" \
  15390. "addq $2, 8, $2 \n\t" \
  15391. "addq $6, $3, $3 \n\t" \
  15392. "addq $5, $3, $3 \n\t"
  15393. #define MULADDC_STOP \
  15394. "stq $3, %0 \n\t" \
  15395. "stq $2, %1 \n\t" \
  15396. "stq $1, %2 \n\t" \
  15397. : "=m" (c), "=m" (d), "=m" (s) \
  15398. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15399. : "$1", "$2", "$3", "$4", "$5", "$6", "$7" \
  15400. );
  15401. #endif /* Alpha */
  15402. #if defined(__mips__) && !defined(__mips64)
  15403. #define MULADDC_INIT \
  15404. asm( \
  15405. "lw $10, %3 \n\t" \
  15406. "lw $11, %4 \n\t" \
  15407. "lw $12, %5 \n\t" \
  15408. "lw $13, %6 \n\t"
  15409. #define MULADDC_CORE \
  15410. "lw $14, 0($10) \n\t" \
  15411. "multu $13, $14 \n\t" \
  15412. "addi $10, $10, 4 \n\t" \
  15413. "mflo $14 \n\t" \
  15414. "mfhi $9 \n\t" \
  15415. "addu $14, $12, $14 \n\t" \
  15416. "lw $15, 0($11) \n\t" \
  15417. "sltu $12, $14, $12 \n\t" \
  15418. "addu $15, $14, $15 \n\t" \
  15419. "sltu $14, $15, $14 \n\t" \
  15420. "addu $12, $12, $9 \n\t" \
  15421. "sw $15, 0($11) \n\t" \
  15422. "addu $12, $12, $14 \n\t" \
  15423. "addi $11, $11, 4 \n\t"
  15424. #define MULADDC_STOP \
  15425. "sw $12, %0 \n\t" \
  15426. "sw $11, %1 \n\t" \
  15427. "sw $10, %2 \n\t" \
  15428. : "=m" (c), "=m" (d), "=m" (s) \
  15429. : "m" (s), "m" (d), "m" (c), "m" (b) \
  15430. : "$9", "$10", "$11", "$12", "$13", "$14", "$15" \
  15431. );
  15432. #endif /* MIPS */
  15433. #endif /* GNUC */
  15434. #if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
  15435. #define MULADDC_INIT \
  15436. __asm mov esi, s \
  15437. __asm mov edi, d \
  15438. __asm mov ecx, c \
  15439. __asm mov ebx, b
  15440. #define MULADDC_CORE \
  15441. __asm lodsd \
  15442. __asm mul ebx \
  15443. __asm add eax, ecx \
  15444. __asm adc edx, 0 \
  15445. __asm add eax, [edi] \
  15446. __asm adc edx, 0 \
  15447. __asm mov ecx, edx \
  15448. __asm stosd
  15449. #if defined(MBEDTLS_HAVE_SSE2)
  15450. #define EMIT __asm _emit
  15451. #define MULADDC_HUIT \
  15452. EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
  15453. EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
  15454. EMIT 0x0F EMIT 0x6E EMIT 0x1F \
  15455. EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
  15456. EMIT 0x0F EMIT 0x6E EMIT 0x16 \
  15457. EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
  15458. EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x04 \
  15459. EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
  15460. EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x08 \
  15461. EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
  15462. EMIT 0x0F EMIT 0x6E EMIT 0x7E EMIT 0x0C \
  15463. EMIT 0x0F EMIT 0xF4 EMIT 0xF8 \
  15464. EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
  15465. EMIT 0x0F EMIT 0x6E EMIT 0x5F EMIT 0x04 \
  15466. EMIT 0x0F EMIT 0xD4 EMIT 0xDC \
  15467. EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x08 \
  15468. EMIT 0x0F EMIT 0xD4 EMIT 0xEE \
  15469. EMIT 0x0F EMIT 0x6E EMIT 0x67 EMIT 0x0C \
  15470. EMIT 0x0F EMIT 0xD4 EMIT 0xFC \
  15471. EMIT 0x0F EMIT 0x7E EMIT 0x0F \
  15472. EMIT 0x0F EMIT 0x6E EMIT 0x56 EMIT 0x10 \
  15473. EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
  15474. EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
  15475. EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x14 \
  15476. EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
  15477. EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
  15478. EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x18 \
  15479. EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
  15480. EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x04 \
  15481. EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
  15482. EMIT 0x0F EMIT 0x6E EMIT 0x5E EMIT 0x1C \
  15483. EMIT 0x0F EMIT 0xF4 EMIT 0xD8 \
  15484. EMIT 0x0F EMIT 0xD4 EMIT 0xCD \
  15485. EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x10 \
  15486. EMIT 0x0F EMIT 0xD4 EMIT 0xD5 \
  15487. EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x08 \
  15488. EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
  15489. EMIT 0x0F EMIT 0xD4 EMIT 0xCF \
  15490. EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x14 \
  15491. EMIT 0x0F EMIT 0xD4 EMIT 0xE5 \
  15492. EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x0C \
  15493. EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
  15494. EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
  15495. EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x18 \
  15496. EMIT 0x0F EMIT 0xD4 EMIT 0xF5 \
  15497. EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x10 \
  15498. EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
  15499. EMIT 0x0F EMIT 0xD4 EMIT 0xCC \
  15500. EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x1C \
  15501. EMIT 0x0F EMIT 0xD4 EMIT 0xDD \
  15502. EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x14 \
  15503. EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
  15504. EMIT 0x0F EMIT 0xD4 EMIT 0xCE \
  15505. EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x18 \
  15506. EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
  15507. EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
  15508. EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x1C \
  15509. EMIT 0x83 EMIT 0xC7 EMIT 0x20 \
  15510. EMIT 0x83 EMIT 0xC6 EMIT 0x20 \
  15511. EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
  15512. EMIT 0x0F EMIT 0x7E EMIT 0xC9
  15513. #define MULADDC_STOP \
  15514. EMIT 0x0F EMIT 0x77 \
  15515. __asm mov c, ecx \
  15516. __asm mov d, edi \
  15517. __asm mov s, esi \
  15518. #else
  15519. #define MULADDC_STOP \
  15520. __asm mov c, ecx \
  15521. __asm mov d, edi \
  15522. __asm mov s, esi \
  15523. #endif /* SSE2 */
  15524. #endif /* MSVC */
  15525. #endif /* MBEDTLS_HAVE_ASM */
  15526. #if !defined(MULADDC_CORE)
  15527. #if defined(MBEDTLS_HAVE_UDBL)
  15528. #define MULADDC_INIT \
  15529. { \
  15530. mbedtls_t_udbl r; \
  15531. mbedtls_mpi_uint r0, r1;
  15532. #define MULADDC_CORE \
  15533. r = *(s++) * (mbedtls_t_udbl) b; \
  15534. r0 = (mbedtls_mpi_uint) r; \
  15535. r1 = (mbedtls_mpi_uint)( r >> biL ); \
  15536. r0 += c; r1 += (r0 < c); \
  15537. r0 += *d; r1 += (r0 < *d); \
  15538. c = r1; *(d++) = r0;
  15539. #define MULADDC_STOP \
  15540. }
  15541. #else
  15542. #define MULADDC_INIT \
  15543. { \
  15544. mbedtls_mpi_uint s0, s1, b0, b1; \
  15545. mbedtls_mpi_uint r0, r1, rx, ry; \
  15546. b0 = ( b << biH ) >> biH; \
  15547. b1 = ( b >> biH );
  15548. #define MULADDC_CORE \
  15549. s0 = ( *s << biH ) >> biH; \
  15550. s1 = ( *s >> biH ); s++; \
  15551. rx = s0 * b1; r0 = s0 * b0; \
  15552. ry = s1 * b0; r1 = s1 * b1; \
  15553. r1 += ( rx >> biH ); \
  15554. r1 += ( ry >> biH ); \
  15555. rx <<= biH; ry <<= biH; \
  15556. r0 += rx; r1 += (r0 < rx); \
  15557. r0 += ry; r1 += (r0 < ry); \
  15558. r0 += c; r1 += (r0 < c); \
  15559. r0 += *d; r1 += (r0 < *d); \
  15560. c = r1; *(d++) = r0;
  15561. #define MULADDC_STOP \
  15562. }
  15563. #endif /* C (generic) */
  15564. #endif /* C (longlong) */
  15565. #endif /* bn_mul.h */
  15566. /********* Start of file include/mbedtls/camellia.h ************/
  15567. /**
  15568. * \file camellia.h
  15569. *
  15570. * \brief Camellia block cipher
  15571. */
  15572. /*
  15573. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  15574. * SPDX-License-Identifier: Apache-2.0
  15575. *
  15576. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  15577. * not use this file except in compliance with the License.
  15578. * You may obtain a copy of the License at
  15579. *
  15580. * http://www.apache.org/licenses/LICENSE-2.0
  15581. *
  15582. * Unless required by applicable law or agreed to in writing, software
  15583. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15584. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15585. * See the License for the specific language governing permissions and
  15586. * limitations under the License.
  15587. *
  15588. * This file is part of mbed TLS (https://tls.mbed.org)
  15589. */
  15590. #ifndef MBEDTLS_CAMELLIA_H
  15591. #define MBEDTLS_CAMELLIA_H
  15592. #if !defined(MBEDTLS_CONFIG_FILE)
  15593. #else
  15594. #endif
  15595. #include <stddef.h>
  15596. #include <stdint.h>
  15597. #define MBEDTLS_CAMELLIA_ENCRYPT 1
  15598. #define MBEDTLS_CAMELLIA_DECRYPT 0
  15599. #define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024 /**< Invalid key length. */
  15600. #define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */
  15601. #define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */
  15602. #if !defined(MBEDTLS_CAMELLIA_ALT)
  15603. // Regular implementation
  15604. //
  15605. #ifdef __cplusplus
  15606. extern "C" {
  15607. #endif
  15608. /**
  15609. * \brief CAMELLIA context structure
  15610. */
  15611. typedef struct
  15612. {
  15613. int nr; /*!< number of rounds */
  15614. uint32_t rk[68]; /*!< CAMELLIA round keys */
  15615. }
  15616. mbedtls_camellia_context;
  15617. /**
  15618. * \brief Initialize CAMELLIA context
  15619. *
  15620. * \param ctx CAMELLIA context to be initialized
  15621. */
  15622. void mbedtls_camellia_init( mbedtls_camellia_context *ctx );
  15623. /**
  15624. * \brief Clear CAMELLIA context
  15625. *
  15626. * \param ctx CAMELLIA context to be cleared
  15627. */
  15628. void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
  15629. /**
  15630. * \brief CAMELLIA key schedule (encryption)
  15631. *
  15632. * \param ctx CAMELLIA context to be initialized
  15633. * \param key encryption key
  15634. * \param keybits must be 128, 192 or 256
  15635. *
  15636. * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH
  15637. */
  15638. int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, const unsigned char *key,
  15639. unsigned int keybits );
  15640. /**
  15641. * \brief CAMELLIA key schedule (decryption)
  15642. *
  15643. * \param ctx CAMELLIA context to be initialized
  15644. * \param key decryption key
  15645. * \param keybits must be 128, 192 or 256
  15646. *
  15647. * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH
  15648. */
  15649. int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, const unsigned char *key,
  15650. unsigned int keybits );
  15651. /**
  15652. * \brief CAMELLIA-ECB block encryption/decryption
  15653. *
  15654. * \param ctx CAMELLIA context
  15655. * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT
  15656. * \param input 16-byte input block
  15657. * \param output 16-byte output block
  15658. *
  15659. * \return 0 if successful
  15660. */
  15661. int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
  15662. int mode,
  15663. const unsigned char input[16],
  15664. unsigned char output[16] );
  15665. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  15666. /**
  15667. * \brief CAMELLIA-CBC buffer encryption/decryption
  15668. * Length should be a multiple of the block
  15669. * size (16 bytes)
  15670. *
  15671. * \note Upon exit, the content of the IV is updated so that you can
  15672. * call the function same function again on the following
  15673. * block(s) of data and get the same result as if it was
  15674. * encrypted in one call. This allows a "streaming" usage.
  15675. * If on the other hand you need to retain the contents of the
  15676. * IV, you should either save it manually or use the cipher
  15677. * module instead.
  15678. *
  15679. * \param ctx CAMELLIA context
  15680. * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT
  15681. * \param length length of the input data
  15682. * \param iv initialization vector (updated after use)
  15683. * \param input buffer holding the input data
  15684. * \param output buffer holding the output data
  15685. *
  15686. * \return 0 if successful, or
  15687. * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH
  15688. */
  15689. int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
  15690. int mode,
  15691. size_t length,
  15692. unsigned char iv[16],
  15693. const unsigned char *input,
  15694. unsigned char *output );
  15695. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  15696. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  15697. /**
  15698. * \brief CAMELLIA-CFB128 buffer encryption/decryption
  15699. *
  15700. * Note: Due to the nature of CFB you should use the same key schedule for
  15701. * both encryption and decryption. So a context initialized with
  15702. * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and CAMELLIE_DECRYPT.
  15703. *
  15704. * \note Upon exit, the content of the IV is updated so that you can
  15705. * call the function same function again on the following
  15706. * block(s) of data and get the same result as if it was
  15707. * encrypted in one call. This allows a "streaming" usage.
  15708. * If on the other hand you need to retain the contents of the
  15709. * IV, you should either save it manually or use the cipher
  15710. * module instead.
  15711. *
  15712. * \param ctx CAMELLIA context
  15713. * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT
  15714. * \param length length of the input data
  15715. * \param iv_off offset in IV (updated after use)
  15716. * \param iv initialization vector (updated after use)
  15717. * \param input buffer holding the input data
  15718. * \param output buffer holding the output data
  15719. *
  15720. * \return 0 if successful, or
  15721. * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH
  15722. */
  15723. int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx,
  15724. int mode,
  15725. size_t length,
  15726. size_t *iv_off,
  15727. unsigned char iv[16],
  15728. const unsigned char *input,
  15729. unsigned char *output );
  15730. #endif /* MBEDTLS_CIPHER_MODE_CFB */
  15731. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  15732. /**
  15733. * \brief CAMELLIA-CTR buffer encryption/decryption
  15734. *
  15735. * Warning: You have to keep the maximum use of your counter in mind!
  15736. *
  15737. * Note: Due to the nature of CTR you should use the same key schedule for
  15738. * both encryption and decryption. So a context initialized with
  15739. * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and MBEDTLS_CAMELLIA_DECRYPT.
  15740. *
  15741. * \param ctx CAMELLIA context
  15742. * \param length The length of the data
  15743. * \param nc_off The offset in the current stream_block (for resuming
  15744. * within current cipher stream). The offset pointer to
  15745. * should be 0 at the start of a stream.
  15746. * \param nonce_counter The 128-bit nonce and counter.
  15747. * \param stream_block The saved stream-block for resuming. Is overwritten
  15748. * by the function.
  15749. * \param input The input data stream
  15750. * \param output The output data stream
  15751. *
  15752. * \return 0 if successful
  15753. */
  15754. int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx,
  15755. size_t length,
  15756. size_t *nc_off,
  15757. unsigned char nonce_counter[16],
  15758. unsigned char stream_block[16],
  15759. const unsigned char *input,
  15760. unsigned char *output );
  15761. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  15762. #ifdef __cplusplus
  15763. }
  15764. #endif
  15765. #else /* MBEDTLS_CAMELLIA_ALT */
  15766. #endif /* MBEDTLS_CAMELLIA_ALT */
  15767. #ifdef __cplusplus
  15768. extern "C" {
  15769. #endif
  15770. /**
  15771. * \brief Checkup routine
  15772. *
  15773. * \return 0 if successful, or 1 if the test failed
  15774. */
  15775. int mbedtls_camellia_self_test( int verbose );
  15776. #ifdef __cplusplus
  15777. }
  15778. #endif
  15779. #endif /* camellia.h */
  15780. /********* Start of file include/mbedtls/ctr_drbg.h ************/
  15781. /**
  15782. * \file ctr_drbg.h
  15783. *
  15784. * \brief CTR_DRBG is based on AES-256, as defined in <em>NIST SP 800-90A:
  15785. * Recommendation for Random Number Generation Using Deterministic
  15786. * Random Bit Generators</em>.
  15787. *
  15788. */
  15789. /*
  15790. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  15791. * SPDX-License-Identifier: Apache-2.0
  15792. *
  15793. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  15794. * not use this file except in compliance with the License.
  15795. * You may obtain a copy of the License at
  15796. *
  15797. * http://www.apache.org/licenses/LICENSE-2.0
  15798. *
  15799. * Unless required by applicable law or agreed to in writing, software
  15800. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15801. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15802. * See the License for the specific language governing permissions and
  15803. * limitations under the License.
  15804. *
  15805. * This file is part of Mbed TLS (https://tls.mbed.org)
  15806. */
  15807. #ifndef MBEDTLS_CTR_DRBG_H
  15808. #define MBEDTLS_CTR_DRBG_H
  15809. #if defined(MBEDTLS_THREADING_C)
  15810. #endif
  15811. #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 /**< The entropy source failed. */
  15812. #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 /**< The requested random buffer length is too big. */
  15813. #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 /**< The input (entropy + additional data) is too large. */
  15814. #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A /**< Read or write error in file. */
  15815. #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< The block size used by the cipher. */
  15816. #define MBEDTLS_CTR_DRBG_KEYSIZE 32 /**< The key size used by the cipher. */
  15817. #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) /**< The key size for the DRBG operation, in bits. */
  15818. #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) /**< The seed length, calculated as (counter + AES key). */
  15819. /**
  15820. * \name SECTION: Module settings
  15821. *
  15822. * The configuration options you can set for this module are in this section.
  15823. * Either change them in config.h or define them using the compiler command
  15824. * line.
  15825. * \{
  15826. */
  15827. #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
  15828. #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
  15829. #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
  15830. /**< The amount of entropy used per seed by default:
  15831. * <ul><li>48 with SHA-512.</li>
  15832. * <li>32 with SHA-256.</li></ul>
  15833. */
  15834. #else
  15835. #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
  15836. /**< Amount of entropy used per seed by default:
  15837. * <ul><li>48 with SHA-512.</li>
  15838. * <li>32 with SHA-256.</li></ul>
  15839. */
  15840. #endif
  15841. #endif
  15842. #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
  15843. #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
  15844. /**< The interval before reseed is performed by default. */
  15845. #endif
  15846. #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
  15847. #define MBEDTLS_CTR_DRBG_MAX_INPUT 256
  15848. /**< The maximum number of additional input Bytes. */
  15849. #endif
  15850. #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
  15851. #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
  15852. /**< The maximum number of requested Bytes per call. */
  15853. #endif
  15854. #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
  15855. #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
  15856. /**< The maximum size of seed or reseed buffer. */
  15857. #endif
  15858. /* \} name SECTION: Module settings */
  15859. #define MBEDTLS_CTR_DRBG_PR_OFF 0
  15860. /**< Prediction resistance is disabled. */
  15861. #define MBEDTLS_CTR_DRBG_PR_ON 1
  15862. /**< Prediction resistance is enabled. */
  15863. #ifdef __cplusplus
  15864. extern "C" {
  15865. #endif
  15866. /**
  15867. * \brief The CTR_DRBG context structure.
  15868. */
  15869. typedef struct
  15870. {
  15871. unsigned char counter[16]; /*!< The counter (V). */
  15872. int reseed_counter; /*!< The reseed counter. */
  15873. int prediction_resistance; /*!< This determines whether prediction
  15874. resistance is enabled, that is
  15875. whether to systematically reseed before
  15876. each random generation. */
  15877. size_t entropy_len; /*!< The amount of entropy grabbed on each
  15878. seed or reseed operation. */
  15879. int reseed_interval; /*!< The reseed interval. */
  15880. mbedtls_aes_context aes_ctx; /*!< The AES context. */
  15881. /*
  15882. * Callbacks (Entropy)
  15883. */
  15884. int (*f_entropy)(void *, unsigned char *, size_t);
  15885. /*!< The entropy callback function. */
  15886. void *p_entropy; /*!< The context for the entropy function. */
  15887. #if defined(MBEDTLS_THREADING_C)
  15888. mbedtls_threading_mutex_t mutex;
  15889. #endif
  15890. }
  15891. mbedtls_ctr_drbg_context;
  15892. /**
  15893. * \brief This function initializes the CTR_DRBG context,
  15894. * and prepares it for mbedtls_ctr_drbg_seed()
  15895. * or mbedtls_ctr_drbg_free().
  15896. *
  15897. * \param ctx The CTR_DRBG context to initialize.
  15898. */
  15899. void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx );
  15900. /**
  15901. * \brief This function seeds and sets up the CTR_DRBG
  15902. * entropy source for future reseeds.
  15903. *
  15904. * \note Personalization data can be provided in addition to the more generic
  15905. * entropy source, to make this instantiation as unique as possible.
  15906. *
  15907. * \param ctx The CTR_DRBG context to seed.
  15908. * \param f_entropy The entropy callback, taking as arguments the
  15909. * \p p_entropy context, the buffer to fill, and the
  15910. length of the buffer.
  15911. * \param p_entropy The entropy context.
  15912. * \param custom Personalization data, that is device-specific
  15913. identifiers. Can be NULL.
  15914. * \param len The length of the personalization data.
  15915. *
  15916. * \return \c 0 on success, or
  15917. * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
  15918. */
  15919. int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx,
  15920. int (*f_entropy)(void *, unsigned char *, size_t),
  15921. void *p_entropy,
  15922. const unsigned char *custom,
  15923. size_t len );
  15924. /**
  15925. * \brief This function clears CTR_CRBG context data.
  15926. *
  15927. * \param ctx The CTR_DRBG context to clear.
  15928. */
  15929. void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx );
  15930. /**
  15931. * \brief This function turns prediction resistance on or off.
  15932. * The default value is off.
  15933. *
  15934. * \note If enabled, entropy is gathered at the beginning of
  15935. * every call to mbedtls_ctr_drbg_random_with_add().
  15936. * Only use this if your entropy source has sufficient
  15937. * throughput.
  15938. *
  15939. * \param ctx The CTR_DRBG context.
  15940. * \param resistance #MBEDTLS_CTR_DRBG_PR_ON or #MBEDTLS_CTR_DRBG_PR_OFF.
  15941. */
  15942. void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx,
  15943. int resistance );
  15944. /**
  15945. * \brief This function sets the amount of entropy grabbed on each
  15946. * seed or reseed. The default value is
  15947. * #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
  15948. *
  15949. * \param ctx The CTR_DRBG context.
  15950. * \param len The amount of entropy to grab.
  15951. */
  15952. void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx,
  15953. size_t len );
  15954. /**
  15955. * \brief This function sets the reseed interval.
  15956. * The default value is #MBEDTLS_CTR_DRBG_RESEED_INTERVAL.
  15957. *
  15958. * \param ctx The CTR_DRBG context.
  15959. * \param interval The reseed interval.
  15960. */
  15961. void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx,
  15962. int interval );
  15963. /**
  15964. * \brief This function reseeds the CTR_DRBG context, that is
  15965. * extracts data from the entropy source.
  15966. *
  15967. * \param ctx The CTR_DRBG context.
  15968. * \param additional Additional data to add to the state. Can be NULL.
  15969. * \param len The length of the additional data.
  15970. *
  15971. * \return \c 0 on success, or
  15972. * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure.
  15973. */
  15974. int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
  15975. const unsigned char *additional, size_t len );
  15976. /**
  15977. * \brief This function updates the state of the CTR_DRBG context.
  15978. *
  15979. * \param ctx The CTR_DRBG context.
  15980. * \param additional The data to update the state with.
  15981. * \param add_len Length of \p additional data.
  15982. *
  15983. * \note If \p add_len is greater than #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT,
  15984. * only the first #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT Bytes are used.
  15985. * The remaining Bytes are silently discarded.
  15986. */
  15987. void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx,
  15988. const unsigned char *additional, size_t add_len );
  15989. /**
  15990. * \brief This function updates a CTR_DRBG instance with additional
  15991. * data and uses it to generate random data.
  15992. *
  15993. * \note The function automatically reseeds if the reseed counter is exceeded.
  15994. *
  15995. * \param p_rng The CTR_DRBG context. This must be a pointer to a
  15996. * #mbedtls_ctr_drbg_context structure.
  15997. * \param output The buffer to fill.
  15998. * \param output_len The length of the buffer.
  15999. * \param additional Additional data to update. Can be NULL.
  16000. * \param add_len The length of the additional data.
  16001. *
  16002. * \return \c 0 on success, or
  16003. * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
  16004. * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
  16005. */
  16006. int mbedtls_ctr_drbg_random_with_add( void *p_rng,
  16007. unsigned char *output, size_t output_len,
  16008. const unsigned char *additional, size_t add_len );
  16009. /**
  16010. * \brief This function uses CTR_DRBG to generate random data.
  16011. *
  16012. * \note The function automatically reseeds if the reseed counter is exceeded.
  16013. *
  16014. * \param p_rng The CTR_DRBG context. This must be a pointer to a
  16015. * #mbedtls_ctr_drbg_context structure.
  16016. * \param output The buffer to fill.
  16017. * \param output_len The length of the buffer.
  16018. *
  16019. * \return \c 0 on success, or
  16020. * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
  16021. * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure.
  16022. */
  16023. int mbedtls_ctr_drbg_random( void *p_rng,
  16024. unsigned char *output, size_t output_len );
  16025. #if defined(MBEDTLS_FS_IO)
  16026. /**
  16027. * \brief This function writes a seed file.
  16028. *
  16029. * \param ctx The CTR_DRBG context.
  16030. * \param path The name of the file.
  16031. *
  16032. * \return \c 0 on success,
  16033. * #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or
  16034. * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on
  16035. * failure.
  16036. */
  16037. int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
  16038. /**
  16039. * \brief This function reads and updates a seed file. The seed
  16040. * is added to this instance.
  16041. *
  16042. * \param ctx The CTR_DRBG context.
  16043. * \param path The name of the file.
  16044. *
  16045. * \return \c 0 on success,
  16046. * #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error,
  16047. * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or
  16048. * #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG on failure.
  16049. */
  16050. int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path );
  16051. #endif /* MBEDTLS_FS_IO */
  16052. /**
  16053. * \brief The CTR_DRBG checkup routine.
  16054. *
  16055. * \return \c 0 on success, or \c 1 on failure.
  16056. */
  16057. int mbedtls_ctr_drbg_self_test( int verbose );
  16058. /* Internal functions (do not call directly) */
  16059. int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *,
  16060. int (*)(void *, unsigned char *, size_t), void *,
  16061. const unsigned char *, size_t, size_t );
  16062. #ifdef __cplusplus
  16063. }
  16064. #endif
  16065. #endif /* ctr_drbg.h */
  16066. /********* Start of file include/mbedtls/des.h ************/
  16067. /**
  16068. * \file des.h
  16069. *
  16070. * \brief DES block cipher
  16071. *
  16072. * \warning DES is considered a weak cipher and its use constitutes a
  16073. * security risk. We recommend considering stronger ciphers
  16074. * instead.
  16075. */
  16076. /*
  16077. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  16078. * SPDX-License-Identifier: Apache-2.0
  16079. *
  16080. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  16081. * not use this file except in compliance with the License.
  16082. * You may obtain a copy of the License at
  16083. *
  16084. * http://www.apache.org/licenses/LICENSE-2.0
  16085. *
  16086. * Unless required by applicable law or agreed to in writing, software
  16087. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16088. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16089. * See the License for the specific language governing permissions and
  16090. * limitations under the License.
  16091. *
  16092. * This file is part of mbed TLS (https://tls.mbed.org)
  16093. *
  16094. */
  16095. #ifndef MBEDTLS_DES_H
  16096. #define MBEDTLS_DES_H
  16097. #if !defined(MBEDTLS_CONFIG_FILE)
  16098. #else
  16099. #endif
  16100. #include <stddef.h>
  16101. #include <stdint.h>
  16102. #define MBEDTLS_DES_ENCRYPT 1
  16103. #define MBEDTLS_DES_DECRYPT 0
  16104. #define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032 /**< The data input has an invalid length. */
  16105. #define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033 /**< DES hardware accelerator failed. */
  16106. #define MBEDTLS_DES_KEY_SIZE 8
  16107. #if !defined(MBEDTLS_DES_ALT)
  16108. // Regular implementation
  16109. //
  16110. #ifdef __cplusplus
  16111. extern "C" {
  16112. #endif
  16113. /**
  16114. * \brief DES context structure
  16115. *
  16116. * \warning DES is considered a weak cipher and its use constitutes a
  16117. * security risk. We recommend considering stronger ciphers
  16118. * instead.
  16119. */
  16120. typedef struct
  16121. {
  16122. uint32_t sk[32]; /*!< DES subkeys */
  16123. }
  16124. mbedtls_des_context;
  16125. /**
  16126. * \brief Triple-DES context structure
  16127. */
  16128. typedef struct
  16129. {
  16130. uint32_t sk[96]; /*!< 3DES subkeys */
  16131. }
  16132. mbedtls_des3_context;
  16133. /**
  16134. * \brief Initialize DES context
  16135. *
  16136. * \param ctx DES context to be initialized
  16137. *
  16138. * \warning DES is considered a weak cipher and its use constitutes a
  16139. * security risk. We recommend considering stronger ciphers
  16140. * instead.
  16141. */
  16142. void mbedtls_des_init( mbedtls_des_context *ctx );
  16143. /**
  16144. * \brief Clear DES context
  16145. *
  16146. * \param ctx DES context to be cleared
  16147. *
  16148. * \warning DES is considered a weak cipher and its use constitutes a
  16149. * security risk. We recommend considering stronger ciphers
  16150. * instead.
  16151. */
  16152. void mbedtls_des_free( mbedtls_des_context *ctx );
  16153. /**
  16154. * \brief Initialize Triple-DES context
  16155. *
  16156. * \param ctx DES3 context to be initialized
  16157. */
  16158. void mbedtls_des3_init( mbedtls_des3_context *ctx );
  16159. /**
  16160. * \brief Clear Triple-DES context
  16161. *
  16162. * \param ctx DES3 context to be cleared
  16163. */
  16164. void mbedtls_des3_free( mbedtls_des3_context *ctx );
  16165. /**
  16166. * \brief Set key parity on the given key to odd.
  16167. *
  16168. * DES keys are 56 bits long, but each byte is padded with
  16169. * a parity bit to allow verification.
  16170. *
  16171. * \param key 8-byte secret key
  16172. *
  16173. * \warning DES is considered a weak cipher and its use constitutes a
  16174. * security risk. We recommend considering stronger ciphers
  16175. * instead.
  16176. */
  16177. void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] );
  16178. /**
  16179. * \brief Check that key parity on the given key is odd.
  16180. *
  16181. * DES keys are 56 bits long, but each byte is padded with
  16182. * a parity bit to allow verification.
  16183. *
  16184. * \param key 8-byte secret key
  16185. *
  16186. * \return 0 is parity was ok, 1 if parity was not correct.
  16187. *
  16188. * \warning DES is considered a weak cipher and its use constitutes a
  16189. * security risk. We recommend considering stronger ciphers
  16190. * instead.
  16191. */
  16192. int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
  16193. /**
  16194. * \brief Check that key is not a weak or semi-weak DES key
  16195. *
  16196. * \param key 8-byte secret key
  16197. *
  16198. * \return 0 if no weak key was found, 1 if a weak key was identified.
  16199. *
  16200. * \warning DES is considered a weak cipher and its use constitutes a
  16201. * security risk. We recommend considering stronger ciphers
  16202. * instead.
  16203. */
  16204. int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
  16205. /**
  16206. * \brief DES key schedule (56-bit, encryption)
  16207. *
  16208. * \param ctx DES context to be initialized
  16209. * \param key 8-byte secret key
  16210. *
  16211. * \return 0
  16212. *
  16213. * \warning DES is considered a weak cipher and its use constitutes a
  16214. * security risk. We recommend considering stronger ciphers
  16215. * instead.
  16216. */
  16217. int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
  16218. /**
  16219. * \brief DES key schedule (56-bit, decryption)
  16220. *
  16221. * \param ctx DES context to be initialized
  16222. * \param key 8-byte secret key
  16223. *
  16224. * \return 0
  16225. *
  16226. * \warning DES is considered a weak cipher and its use constitutes a
  16227. * security risk. We recommend considering stronger ciphers
  16228. * instead.
  16229. */
  16230. int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
  16231. /**
  16232. * \brief Triple-DES key schedule (112-bit, encryption)
  16233. *
  16234. * \param ctx 3DES context to be initialized
  16235. * \param key 16-byte secret key
  16236. *
  16237. * \return 0
  16238. */
  16239. int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx,
  16240. const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
  16241. /**
  16242. * \brief Triple-DES key schedule (112-bit, decryption)
  16243. *
  16244. * \param ctx 3DES context to be initialized
  16245. * \param key 16-byte secret key
  16246. *
  16247. * \return 0
  16248. */
  16249. int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx,
  16250. const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] );
  16251. /**
  16252. * \brief Triple-DES key schedule (168-bit, encryption)
  16253. *
  16254. * \param ctx 3DES context to be initialized
  16255. * \param key 24-byte secret key
  16256. *
  16257. * \return 0
  16258. */
  16259. int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx,
  16260. const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
  16261. /**
  16262. * \brief Triple-DES key schedule (168-bit, decryption)
  16263. *
  16264. * \param ctx 3DES context to be initialized
  16265. * \param key 24-byte secret key
  16266. *
  16267. * \return 0
  16268. */
  16269. int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx,
  16270. const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] );
  16271. /**
  16272. * \brief DES-ECB block encryption/decryption
  16273. *
  16274. * \param ctx DES context
  16275. * \param input 64-bit input block
  16276. * \param output 64-bit output block
  16277. *
  16278. * \return 0 if successful
  16279. *
  16280. * \warning DES is considered a weak cipher and its use constitutes a
  16281. * security risk. We recommend considering stronger ciphers
  16282. * instead.
  16283. */
  16284. int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx,
  16285. const unsigned char input[8],
  16286. unsigned char output[8] );
  16287. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  16288. /**
  16289. * \brief DES-CBC buffer encryption/decryption
  16290. *
  16291. * \note Upon exit, the content of the IV is updated so that you can
  16292. * call the function same function again on the following
  16293. * block(s) of data and get the same result as if it was
  16294. * encrypted in one call. This allows a "streaming" usage.
  16295. * If on the other hand you need to retain the contents of the
  16296. * IV, you should either save it manually or use the cipher
  16297. * module instead.
  16298. *
  16299. * \param ctx DES context
  16300. * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
  16301. * \param length length of the input data
  16302. * \param iv initialization vector (updated after use)
  16303. * \param input buffer holding the input data
  16304. * \param output buffer holding the output data
  16305. *
  16306. * \warning DES is considered a weak cipher and its use constitutes a
  16307. * security risk. We recommend considering stronger ciphers
  16308. * instead.
  16309. */
  16310. int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
  16311. int mode,
  16312. size_t length,
  16313. unsigned char iv[8],
  16314. const unsigned char *input,
  16315. unsigned char *output );
  16316. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  16317. /**
  16318. * \brief 3DES-ECB block encryption/decryption
  16319. *
  16320. * \param ctx 3DES context
  16321. * \param input 64-bit input block
  16322. * \param output 64-bit output block
  16323. *
  16324. * \return 0 if successful
  16325. */
  16326. int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx,
  16327. const unsigned char input[8],
  16328. unsigned char output[8] );
  16329. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  16330. /**
  16331. * \brief 3DES-CBC buffer encryption/decryption
  16332. *
  16333. * \note Upon exit, the content of the IV is updated so that you can
  16334. * call the function same function again on the following
  16335. * block(s) of data and get the same result as if it was
  16336. * encrypted in one call. This allows a "streaming" usage.
  16337. * If on the other hand you need to retain the contents of the
  16338. * IV, you should either save it manually or use the cipher
  16339. * module instead.
  16340. *
  16341. * \param ctx 3DES context
  16342. * \param mode MBEDTLS_DES_ENCRYPT or MBEDTLS_DES_DECRYPT
  16343. * \param length length of the input data
  16344. * \param iv initialization vector (updated after use)
  16345. * \param input buffer holding the input data
  16346. * \param output buffer holding the output data
  16347. *
  16348. * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH
  16349. */
  16350. int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
  16351. int mode,
  16352. size_t length,
  16353. unsigned char iv[8],
  16354. const unsigned char *input,
  16355. unsigned char *output );
  16356. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  16357. /**
  16358. * \brief Internal function for key expansion.
  16359. * (Only exposed to allow overriding it,
  16360. * see MBEDTLS_DES_SETKEY_ALT)
  16361. *
  16362. * \param SK Round keys
  16363. * \param key Base key
  16364. *
  16365. * \warning DES is considered a weak cipher and its use constitutes a
  16366. * security risk. We recommend considering stronger ciphers
  16367. * instead.
  16368. */
  16369. void mbedtls_des_setkey( uint32_t SK[32],
  16370. const unsigned char key[MBEDTLS_DES_KEY_SIZE] );
  16371. #ifdef __cplusplus
  16372. }
  16373. #endif
  16374. #else /* MBEDTLS_DES_ALT */
  16375. #endif /* MBEDTLS_DES_ALT */
  16376. #ifdef __cplusplus
  16377. extern "C" {
  16378. #endif
  16379. /**
  16380. * \brief Checkup routine
  16381. *
  16382. * \return 0 if successful, or 1 if the test failed
  16383. */
  16384. int mbedtls_des_self_test( int verbose );
  16385. #ifdef __cplusplus
  16386. }
  16387. #endif
  16388. #endif /* des.h */
  16389. /********* Start of file include/mbedtls/entropy.h ************/
  16390. /**
  16391. * \file entropy.h
  16392. *
  16393. * \brief Entropy accumulator implementation
  16394. */
  16395. /*
  16396. * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
  16397. * SPDX-License-Identifier: Apache-2.0
  16398. *
  16399. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  16400. * not use this file except in compliance with the License.
  16401. * You may obtain a copy of the License at
  16402. *
  16403. * http://www.apache.org/licenses/LICENSE-2.0
  16404. *
  16405. * Unless required by applicable law or agreed to in writing, software
  16406. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16407. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16408. * See the License for the specific language governing permissions and
  16409. * limitations under the License.
  16410. *
  16411. * This file is part of mbed TLS (https://tls.mbed.org)
  16412. */
  16413. #ifndef MBEDTLS_ENTROPY_H
  16414. #define MBEDTLS_ENTROPY_H
  16415. #if !defined(MBEDTLS_CONFIG_FILE)
  16416. #else
  16417. #endif
  16418. #include <stddef.h>
  16419. #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
  16420. #define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR
  16421. #else
  16422. #if defined(MBEDTLS_SHA256_C)
  16423. #define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR
  16424. #endif
  16425. #endif
  16426. #if defined(MBEDTLS_THREADING_C)
  16427. #endif
  16428. #if defined(MBEDTLS_HAVEGE_C)
  16429. #endif
  16430. #define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C /**< Critical entropy source failure. */
  16431. #define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E /**< No more sources can be added. */
  16432. #define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040 /**< No sources have been added to poll. */
  16433. #define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D /**< No strong sources have been added to poll. */
  16434. #define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F /**< Read/write error in file. */
  16435. /**
  16436. * \name SECTION: Module settings
  16437. *
  16438. * The configuration options you can set for this module are in this section.
  16439. * Either change them in config.h or define them on the compiler command line.
  16440. * \{
  16441. */
  16442. #if !defined(MBEDTLS_ENTROPY_MAX_SOURCES)
  16443. #define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */
  16444. #endif
  16445. #if !defined(MBEDTLS_ENTROPY_MAX_GATHER)
  16446. #define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */
  16447. #endif
  16448. /* \} name SECTION: Module settings */
  16449. #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
  16450. #define MBEDTLS_ENTROPY_BLOCK_SIZE 64 /**< Block size of entropy accumulator (SHA-512) */
  16451. #else
  16452. #define MBEDTLS_ENTROPY_BLOCK_SIZE 32 /**< Block size of entropy accumulator (SHA-256) */
  16453. #endif
  16454. #define MBEDTLS_ENTROPY_MAX_SEED_SIZE 1024 /**< Maximum size of seed we read from seed file */
  16455. #define MBEDTLS_ENTROPY_SOURCE_MANUAL MBEDTLS_ENTROPY_MAX_SOURCES
  16456. #define MBEDTLS_ENTROPY_SOURCE_STRONG 1 /**< Entropy source is strong */
  16457. #define MBEDTLS_ENTROPY_SOURCE_WEAK 0 /**< Entropy source is weak */
  16458. #ifdef __cplusplus
  16459. extern "C" {
  16460. #endif
  16461. /**
  16462. * \brief Entropy poll callback pointer
  16463. *
  16464. * \param data Callback-specific data pointer
  16465. * \param output Data to fill
  16466. * \param len Maximum size to provide
  16467. * \param olen The actual amount of bytes put into the buffer (Can be 0)
  16468. *
  16469. * \return 0 if no critical failures occurred,
  16470. * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED otherwise
  16471. */
  16472. typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len,
  16473. size_t *olen);
  16474. /**
  16475. * \brief Entropy source state
  16476. */
  16477. typedef struct
  16478. {
  16479. mbedtls_entropy_f_source_ptr f_source; /**< The entropy source callback */
  16480. void * p_source; /**< The callback data pointer */
  16481. size_t size; /**< Amount received in bytes */
  16482. size_t threshold; /**< Minimum bytes required before release */
  16483. int strong; /**< Is the source strong? */
  16484. }
  16485. mbedtls_entropy_source_state;
  16486. /**
  16487. * \brief Entropy context structure
  16488. */
  16489. typedef struct
  16490. {
  16491. int accumulator_started;
  16492. #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
  16493. mbedtls_sha512_context accumulator;
  16494. #else
  16495. mbedtls_sha256_context accumulator;
  16496. #endif
  16497. int source_count;
  16498. mbedtls_entropy_source_state source[MBEDTLS_ENTROPY_MAX_SOURCES];
  16499. #if defined(MBEDTLS_HAVEGE_C)
  16500. mbedtls_havege_state havege_data;
  16501. #endif
  16502. #if defined(MBEDTLS_THREADING_C)
  16503. mbedtls_threading_mutex_t mutex; /*!< mutex */
  16504. #endif
  16505. #if defined(MBEDTLS_ENTROPY_NV_SEED)
  16506. int initial_entropy_run;
  16507. #endif
  16508. }
  16509. mbedtls_entropy_context;
  16510. /**
  16511. * \brief Initialize the context
  16512. *
  16513. * \param ctx Entropy context to initialize
  16514. */
  16515. void mbedtls_entropy_init( mbedtls_entropy_context *ctx );
  16516. /**
  16517. * \brief Free the data in the context
  16518. *
  16519. * \param ctx Entropy context to free
  16520. */
  16521. void mbedtls_entropy_free( mbedtls_entropy_context *ctx );
  16522. /**
  16523. * \brief Adds an entropy source to poll
  16524. * (Thread-safe if MBEDTLS_THREADING_C is enabled)
  16525. *
  16526. * \param ctx Entropy context
  16527. * \param f_source Entropy function
  16528. * \param p_source Function data
  16529. * \param threshold Minimum required from source before entropy is released
  16530. * ( with mbedtls_entropy_func() ) (in bytes)
  16531. * \param strong MBEDTLS_ENTROPY_SOURCE_STRONG or
  16532. * MBEDTSL_ENTROPY_SOURCE_WEAK.
  16533. * At least one strong source needs to be added.
  16534. * Weaker sources (such as the cycle counter) can be used as
  16535. * a complement.
  16536. *
  16537. * \return 0 if successful or MBEDTLS_ERR_ENTROPY_MAX_SOURCES
  16538. */
  16539. int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx,
  16540. mbedtls_entropy_f_source_ptr f_source, void *p_source,
  16541. size_t threshold, int strong );
  16542. /**
  16543. * \brief Trigger an extra gather poll for the accumulator
  16544. * (Thread-safe if MBEDTLS_THREADING_C is enabled)
  16545. *
  16546. * \param ctx Entropy context
  16547. *
  16548. * \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
  16549. */
  16550. int mbedtls_entropy_gather( mbedtls_entropy_context *ctx );
  16551. /**
  16552. * \brief Retrieve entropy from the accumulator
  16553. * (Maximum length: MBEDTLS_ENTROPY_BLOCK_SIZE)
  16554. * (Thread-safe if MBEDTLS_THREADING_C is enabled)
  16555. *
  16556. * \param data Entropy context
  16557. * \param output Buffer to fill
  16558. * \param len Number of bytes desired, must be at most MBEDTLS_ENTROPY_BLOCK_SIZE
  16559. *
  16560. * \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
  16561. */
  16562. int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
  16563. /**
  16564. * \brief Add data to the accumulator manually
  16565. * (Thread-safe if MBEDTLS_THREADING_C is enabled)
  16566. *
  16567. * \param ctx Entropy context
  16568. * \param data Data to add
  16569. * \param len Length of data
  16570. *
  16571. * \return 0 if successful
  16572. */
  16573. int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx,
  16574. const unsigned char *data, size_t len );
  16575. #if defined(MBEDTLS_ENTROPY_NV_SEED)
  16576. /**
  16577. * \brief Trigger an update of the seed file in NV by using the
  16578. * current entropy pool.
  16579. *
  16580. * \param ctx Entropy context
  16581. *
  16582. * \return 0 if successful
  16583. */
  16584. int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx );
  16585. #endif /* MBEDTLS_ENTROPY_NV_SEED */
  16586. #if defined(MBEDTLS_FS_IO)
  16587. /**
  16588. * \brief Write a seed file
  16589. *
  16590. * \param ctx Entropy context
  16591. * \param path Name of the file
  16592. *
  16593. * \return 0 if successful,
  16594. * MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error, or
  16595. * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
  16596. */
  16597. int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path );
  16598. /**
  16599. * \brief Read and update a seed file. Seed is added to this
  16600. * instance. No more than MBEDTLS_ENTROPY_MAX_SEED_SIZE bytes are
  16601. * read from the seed file. The rest is ignored.
  16602. *
  16603. * \param ctx Entropy context
  16604. * \param path Name of the file
  16605. *
  16606. * \return 0 if successful,
  16607. * MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error,
  16608. * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED
  16609. */
  16610. int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
  16611. #endif /* MBEDTLS_FS_IO */
  16612. #if defined(MBEDTLS_SELF_TEST)
  16613. /**
  16614. * \brief Checkup routine
  16615. *
  16616. * This module self-test also calls the entropy self-test,
  16617. * mbedtls_entropy_source_self_test();
  16618. *
  16619. * \return 0 if successful, or 1 if a test failed
  16620. */
  16621. int mbedtls_entropy_self_test( int verbose );
  16622. #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
  16623. /**
  16624. * \brief Checkup routine
  16625. *
  16626. * Verifies the integrity of the hardware entropy source
  16627. * provided by the function 'mbedtls_hardware_poll()'.
  16628. *
  16629. * Note this is the only hardware entropy source that is known
  16630. * at link time, and other entropy sources configured
  16631. * dynamically at runtime by the function
  16632. * mbedtls_entropy_add_source() will not be tested.
  16633. *
  16634. * \return 0 if successful, or 1 if a test failed
  16635. */
  16636. int mbedtls_entropy_source_self_test( int verbose );
  16637. #endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
  16638. #endif /* MBEDTLS_SELF_TEST */
  16639. #ifdef __cplusplus
  16640. }
  16641. #endif
  16642. #endif /* entropy.h */
  16643. /********* Start of file include/mbedtls/entropy_poll.h ************/
  16644. /**
  16645. * \file entropy_poll.h
  16646. *
  16647. * \brief Platform-specific and custom entropy polling functions
  16648. */
  16649. /*
  16650. * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
  16651. * SPDX-License-Identifier: Apache-2.0
  16652. *
  16653. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  16654. * not use this file except in compliance with the License.
  16655. * You may obtain a copy of the License at
  16656. *
  16657. * http://www.apache.org/licenses/LICENSE-2.0
  16658. *
  16659. * Unless required by applicable law or agreed to in writing, software
  16660. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16661. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16662. * See the License for the specific language governing permissions and
  16663. * limitations under the License.
  16664. *
  16665. * This file is part of mbed TLS (https://tls.mbed.org)
  16666. */
  16667. #ifndef MBEDTLS_ENTROPY_POLL_H
  16668. #define MBEDTLS_ENTROPY_POLL_H
  16669. #if !defined(MBEDTLS_CONFIG_FILE)
  16670. #else
  16671. #endif
  16672. #include <stddef.h>
  16673. #ifdef __cplusplus
  16674. extern "C" {
  16675. #endif
  16676. /*
  16677. * Default thresholds for built-in sources, in bytes
  16678. */
  16679. #define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */
  16680. #define MBEDTLS_ENTROPY_MIN_HAVEGE 32 /**< Minimum for HAVEGE */
  16681. #define MBEDTLS_ENTROPY_MIN_HARDCLOCK 4 /**< Minimum for mbedtls_timing_hardclock() */
  16682. #if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE)
  16683. #define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */
  16684. #endif
  16685. /**
  16686. * \brief Entropy poll callback that provides 0 entropy.
  16687. */
  16688. #if defined(MBEDTLS_TEST_NULL_ENTROPY)
  16689. int mbedtls_null_entropy_poll( void *data,
  16690. unsigned char *output, size_t len, size_t *olen );
  16691. #endif
  16692. #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY)
  16693. /**
  16694. * \brief Platform-specific entropy poll callback
  16695. */
  16696. int mbedtls_platform_entropy_poll( void *data,
  16697. unsigned char *output, size_t len, size_t *olen );
  16698. #endif
  16699. #if defined(MBEDTLS_HAVEGE_C)
  16700. /**
  16701. * \brief HAVEGE based entropy poll callback
  16702. *
  16703. * Requires an HAVEGE state as its data pointer.
  16704. */
  16705. int mbedtls_havege_poll( void *data,
  16706. unsigned char *output, size_t len, size_t *olen );
  16707. #endif
  16708. #if defined(MBEDTLS_TIMING_C)
  16709. /**
  16710. * \brief mbedtls_timing_hardclock-based entropy poll callback
  16711. */
  16712. int mbedtls_hardclock_poll( void *data,
  16713. unsigned char *output, size_t len, size_t *olen );
  16714. #endif
  16715. #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
  16716. /**
  16717. * \brief Entropy poll callback for a hardware source
  16718. *
  16719. * \warning This is not provided by mbed TLS!
  16720. * See \c MBEDTLS_ENTROPY_HARDWARE_ALT in config.h.
  16721. *
  16722. * \note This must accept NULL as its first argument.
  16723. */
  16724. int mbedtls_hardware_poll( void *data,
  16725. unsigned char *output, size_t len, size_t *olen );
  16726. #endif
  16727. #if defined(MBEDTLS_ENTROPY_NV_SEED)
  16728. /**
  16729. * \brief Entropy poll callback for a non-volatile seed file
  16730. *
  16731. * \note This must accept NULL as its first argument.
  16732. */
  16733. int mbedtls_nv_seed_poll( void *data,
  16734. unsigned char *output, size_t len, size_t *olen );
  16735. #endif
  16736. #ifdef __cplusplus
  16737. }
  16738. #endif
  16739. #endif /* entropy_poll.h */
  16740. /********* Start of file include/mbedtls/havege.h ************/
  16741. /**
  16742. * \file havege.h
  16743. *
  16744. * \brief HAVEGE: HArdware Volatile Entropy Gathering and Expansion
  16745. */
  16746. /*
  16747. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  16748. * SPDX-License-Identifier: Apache-2.0
  16749. *
  16750. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  16751. * not use this file except in compliance with the License.
  16752. * You may obtain a copy of the License at
  16753. *
  16754. * http://www.apache.org/licenses/LICENSE-2.0
  16755. *
  16756. * Unless required by applicable law or agreed to in writing, software
  16757. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16758. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16759. * See the License for the specific language governing permissions and
  16760. * limitations under the License.
  16761. *
  16762. * This file is part of mbed TLS (https://tls.mbed.org)
  16763. */
  16764. #ifndef MBEDTLS_HAVEGE_H
  16765. #define MBEDTLS_HAVEGE_H
  16766. #include <stddef.h>
  16767. #define MBEDTLS_HAVEGE_COLLECT_SIZE 1024
  16768. #ifdef __cplusplus
  16769. extern "C" {
  16770. #endif
  16771. /**
  16772. * \brief HAVEGE state structure
  16773. */
  16774. typedef struct
  16775. {
  16776. int PT1, PT2, offset[2];
  16777. int pool[MBEDTLS_HAVEGE_COLLECT_SIZE];
  16778. int WALK[8192];
  16779. }
  16780. mbedtls_havege_state;
  16781. /**
  16782. * \brief HAVEGE initialization
  16783. *
  16784. * \param hs HAVEGE state to be initialized
  16785. */
  16786. void mbedtls_havege_init( mbedtls_havege_state *hs );
  16787. /**
  16788. * \brief Clear HAVEGE state
  16789. *
  16790. * \param hs HAVEGE state to be cleared
  16791. */
  16792. void mbedtls_havege_free( mbedtls_havege_state *hs );
  16793. /**
  16794. * \brief HAVEGE rand function
  16795. *
  16796. * \param p_rng A HAVEGE state
  16797. * \param output Buffer to fill
  16798. * \param len Length of buffer
  16799. *
  16800. * \return 0
  16801. */
  16802. int mbedtls_havege_random( void *p_rng, unsigned char *output, size_t len );
  16803. #ifdef __cplusplus
  16804. }
  16805. #endif
  16806. #endif /* havege.h */
  16807. /********* Start of file include/mbedtls/memory_buffer_alloc.h ************/
  16808. /**
  16809. * \file memory_buffer_alloc.h
  16810. *
  16811. * \brief Buffer-based memory allocator
  16812. */
  16813. /*
  16814. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  16815. * SPDX-License-Identifier: Apache-2.0
  16816. *
  16817. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  16818. * not use this file except in compliance with the License.
  16819. * You may obtain a copy of the License at
  16820. *
  16821. * http://www.apache.org/licenses/LICENSE-2.0
  16822. *
  16823. * Unless required by applicable law or agreed to in writing, software
  16824. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16825. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16826. * See the License for the specific language governing permissions and
  16827. * limitations under the License.
  16828. *
  16829. * This file is part of mbed TLS (https://tls.mbed.org)
  16830. */
  16831. #ifndef MBEDTLS_MEMORY_BUFFER_ALLOC_H
  16832. #define MBEDTLS_MEMORY_BUFFER_ALLOC_H
  16833. #if !defined(MBEDTLS_CONFIG_FILE)
  16834. #else
  16835. #endif
  16836. #include <stddef.h>
  16837. /**
  16838. * \name SECTION: Module settings
  16839. *
  16840. * The configuration options you can set for this module are in this section.
  16841. * Either change them in config.h or define them on the compiler command line.
  16842. * \{
  16843. */
  16844. #if !defined(MBEDTLS_MEMORY_ALIGN_MULTIPLE)
  16845. #define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */
  16846. #endif
  16847. /* \} name SECTION: Module settings */
  16848. #define MBEDTLS_MEMORY_VERIFY_NONE 0
  16849. #define MBEDTLS_MEMORY_VERIFY_ALLOC (1 << 0)
  16850. #define MBEDTLS_MEMORY_VERIFY_FREE (1 << 1)
  16851. #define MBEDTLS_MEMORY_VERIFY_ALWAYS (MBEDTLS_MEMORY_VERIFY_ALLOC | MBEDTLS_MEMORY_VERIFY_FREE)
  16852. #ifdef __cplusplus
  16853. extern "C" {
  16854. #endif
  16855. /**
  16856. * \brief Initialize use of stack-based memory allocator.
  16857. * The stack-based allocator does memory management inside the
  16858. * presented buffer and does not call calloc() and free().
  16859. * It sets the global mbedtls_calloc() and mbedtls_free() pointers
  16860. * to its own functions.
  16861. * (Provided mbedtls_calloc() and mbedtls_free() are thread-safe if
  16862. * MBEDTLS_THREADING_C is defined)
  16863. *
  16864. * \note This code is not optimized and provides a straight-forward
  16865. * implementation of a stack-based memory allocator.
  16866. *
  16867. * \param buf buffer to use as heap
  16868. * \param len size of the buffer
  16869. */
  16870. void mbedtls_memory_buffer_alloc_init( unsigned char *buf, size_t len );
  16871. /**
  16872. * \brief Free the mutex for thread-safety and clear remaining memory
  16873. */
  16874. void mbedtls_memory_buffer_alloc_free( void );
  16875. /**
  16876. * \brief Determine when the allocator should automatically verify the state
  16877. * of the entire chain of headers / meta-data.
  16878. * (Default: MBEDTLS_MEMORY_VERIFY_NONE)
  16879. *
  16880. * \param verify One of MBEDTLS_MEMORY_VERIFY_NONE, MBEDTLS_MEMORY_VERIFY_ALLOC,
  16881. * MBEDTLS_MEMORY_VERIFY_FREE or MBEDTLS_MEMORY_VERIFY_ALWAYS
  16882. */
  16883. void mbedtls_memory_buffer_set_verify( int verify );
  16884. #if defined(MBEDTLS_MEMORY_DEBUG)
  16885. /**
  16886. * \brief Print out the status of the allocated memory (primarily for use
  16887. * after a program should have de-allocated all memory)
  16888. * Prints out a list of 'still allocated' blocks and their stack
  16889. * trace if MBEDTLS_MEMORY_BACKTRACE is defined.
  16890. */
  16891. void mbedtls_memory_buffer_alloc_status( void );
  16892. /**
  16893. * \brief Get the peak heap usage so far
  16894. *
  16895. * \param max_used Peak number of bytes in use or committed. This
  16896. * includes bytes in allocated blocks too small to split
  16897. * into smaller blocks but larger than the requested size.
  16898. * \param max_blocks Peak number of blocks in use, including free and used
  16899. */
  16900. void mbedtls_memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks );
  16901. /**
  16902. * \brief Reset peak statistics
  16903. */
  16904. void mbedtls_memory_buffer_alloc_max_reset( void );
  16905. /**
  16906. * \brief Get the current heap usage
  16907. *
  16908. * \param cur_used Current number of bytes in use or committed. This
  16909. * includes bytes in allocated blocks too small to split
  16910. * into smaller blocks but larger than the requested size.
  16911. * \param cur_blocks Current number of blocks in use, including free and used
  16912. */
  16913. void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks );
  16914. #endif /* MBEDTLS_MEMORY_DEBUG */
  16915. /**
  16916. * \brief Verifies that all headers in the memory buffer are correct
  16917. * and contain sane values. Helps debug buffer-overflow errors.
  16918. *
  16919. * Prints out first failure if MBEDTLS_MEMORY_DEBUG is defined.
  16920. * Prints out full header information if MBEDTLS_MEMORY_DEBUG
  16921. * is defined. (Includes stack trace information for each block if
  16922. * MBEDTLS_MEMORY_BACKTRACE is defined as well).
  16923. *
  16924. * \return 0 if verified, 1 otherwise
  16925. */
  16926. int mbedtls_memory_buffer_alloc_verify( void );
  16927. #if defined(MBEDTLS_SELF_TEST)
  16928. /**
  16929. * \brief Checkup routine
  16930. *
  16931. * \return 0 if successful, or 1 if a test failed
  16932. */
  16933. int mbedtls_memory_buffer_alloc_self_test( int verbose );
  16934. #endif
  16935. #ifdef __cplusplus
  16936. }
  16937. #endif
  16938. #endif /* memory_buffer_alloc.h */
  16939. /********* Start of file include/mbedtls/padlock.h ************/
  16940. /**
  16941. * \file padlock.h
  16942. *
  16943. * \brief VIA PadLock ACE for HW encryption/decryption supported by some
  16944. * processors
  16945. */
  16946. /*
  16947. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  16948. * SPDX-License-Identifier: Apache-2.0
  16949. *
  16950. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  16951. * not use this file except in compliance with the License.
  16952. * You may obtain a copy of the License at
  16953. *
  16954. * http://www.apache.org/licenses/LICENSE-2.0
  16955. *
  16956. * Unless required by applicable law or agreed to in writing, software
  16957. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16958. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16959. * See the License for the specific language governing permissions and
  16960. * limitations under the License.
  16961. *
  16962. * This file is part of mbed TLS (https://tls.mbed.org)
  16963. */
  16964. #ifndef MBEDTLS_PADLOCK_H
  16965. #define MBEDTLS_PADLOCK_H
  16966. #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */
  16967. #if defined(__has_feature)
  16968. #if __has_feature(address_sanitizer)
  16969. #define MBEDTLS_HAVE_ASAN
  16970. #endif
  16971. #endif
  16972. /* Some versions of ASan result in errors about not enough registers */
  16973. #if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && defined(__i386__) && \
  16974. !defined(MBEDTLS_HAVE_ASAN)
  16975. #ifndef MBEDTLS_HAVE_X86
  16976. #define MBEDTLS_HAVE_X86
  16977. #endif
  16978. #include <stdint.h>
  16979. #define MBEDTLS_PADLOCK_RNG 0x000C
  16980. #define MBEDTLS_PADLOCK_ACE 0x00C0
  16981. #define MBEDTLS_PADLOCK_PHE 0x0C00
  16982. #define MBEDTLS_PADLOCK_PMM 0x3000
  16983. #define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15))
  16984. #ifdef __cplusplus
  16985. extern "C" {
  16986. #endif
  16987. /**
  16988. * \brief PadLock detection routine
  16989. *
  16990. * \param feature The feature to detect
  16991. *
  16992. * \return 1 if CPU has support for the feature, 0 otherwise
  16993. */
  16994. int mbedtls_padlock_has_support( int feature );
  16995. /**
  16996. * \brief PadLock AES-ECB block en(de)cryption
  16997. *
  16998. * \param ctx AES context
  16999. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  17000. * \param input 16-byte input block
  17001. * \param output 16-byte output block
  17002. *
  17003. * \return 0 if success, 1 if operation failed
  17004. */
  17005. int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx,
  17006. int mode,
  17007. const unsigned char input[16],
  17008. unsigned char output[16] );
  17009. /**
  17010. * \brief PadLock AES-CBC buffer en(de)cryption
  17011. *
  17012. * \param ctx AES context
  17013. * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT
  17014. * \param length length of the input data
  17015. * \param iv initialization vector (updated after use)
  17016. * \param input buffer holding the input data
  17017. * \param output buffer holding the output data
  17018. *
  17019. * \return 0 if success, 1 if operation failed
  17020. */
  17021. int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx,
  17022. int mode,
  17023. size_t length,
  17024. unsigned char iv[16],
  17025. const unsigned char *input,
  17026. unsigned char *output );
  17027. #ifdef __cplusplus
  17028. }
  17029. #endif
  17030. #endif /* HAVE_X86 */
  17031. #endif /* padlock.h */
  17032. /********* Start of file include/mbedtls/timing.h ************/
  17033. /**
  17034. * \file timing.h
  17035. *
  17036. * \brief Portable interface to timeouts and to the CPU cycle counter
  17037. */
  17038. /*
  17039. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  17040. * SPDX-License-Identifier: Apache-2.0
  17041. *
  17042. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  17043. * not use this file except in compliance with the License.
  17044. * You may obtain a copy of the License at
  17045. *
  17046. * http://www.apache.org/licenses/LICENSE-2.0
  17047. *
  17048. * Unless required by applicable law or agreed to in writing, software
  17049. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  17050. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17051. * See the License for the specific language governing permissions and
  17052. * limitations under the License.
  17053. *
  17054. * This file is part of mbed TLS (https://tls.mbed.org)
  17055. */
  17056. #ifndef MBEDTLS_TIMING_H
  17057. #define MBEDTLS_TIMING_H
  17058. #if !defined(MBEDTLS_CONFIG_FILE)
  17059. #else
  17060. #endif
  17061. #if !defined(MBEDTLS_TIMING_ALT)
  17062. // Regular implementation
  17063. //
  17064. #include <stdint.h>
  17065. #ifdef __cplusplus
  17066. extern "C" {
  17067. #endif
  17068. /**
  17069. * \brief timer structure
  17070. */
  17071. struct mbedtls_timing_hr_time
  17072. {
  17073. unsigned char opaque[32];
  17074. };
  17075. /**
  17076. * \brief Context for mbedtls_timing_set/get_delay()
  17077. */
  17078. typedef struct
  17079. {
  17080. struct mbedtls_timing_hr_time timer;
  17081. uint32_t int_ms;
  17082. uint32_t fin_ms;
  17083. } mbedtls_timing_delay_context;
  17084. extern volatile int mbedtls_timing_alarmed;
  17085. /**
  17086. * \brief Return the CPU cycle counter value
  17087. *
  17088. * \warning This is only a best effort! Do not rely on this!
  17089. * In particular, it is known to be unreliable on virtual
  17090. * machines.
  17091. *
  17092. * \note This value starts at an unspecified origin and
  17093. * may wrap around.
  17094. */
  17095. unsigned long mbedtls_timing_hardclock( void );
  17096. /**
  17097. * \brief Return the elapsed time in milliseconds
  17098. *
  17099. * \param val points to a timer structure
  17100. * \param reset If 0, query the elapsed time. Otherwise (re)start the timer.
  17101. *
  17102. * \return Elapsed time since the previous reset in ms. When
  17103. * restarting, this is always 0.
  17104. *
  17105. * \note To initialize a timer, call this function with reset=1.
  17106. *
  17107. * Determining the elapsed time and resetting the timer is not
  17108. * atomic on all platforms, so after the sequence
  17109. * `{ get_timer(1); ...; time1 = get_timer(1); ...; time2 =
  17110. * get_timer(0) }` the value time1+time2 is only approximately
  17111. * the delay since the first reset.
  17112. */
  17113. unsigned long mbedtls_timing_get_timer( struct mbedtls_timing_hr_time *val, int reset );
  17114. /**
  17115. * \brief Setup an alarm clock
  17116. *
  17117. * \param seconds delay before the "mbedtls_timing_alarmed" flag is set
  17118. * (must be >=0)
  17119. *
  17120. * \warning Only one alarm at a time is supported. In a threaded
  17121. * context, this means one for the whole process, not one per
  17122. * thread.
  17123. */
  17124. void mbedtls_set_alarm( int seconds );
  17125. /**
  17126. * \brief Set a pair of delays to watch
  17127. * (See \c mbedtls_timing_get_delay().)
  17128. *
  17129. * \param data Pointer to timing data.
  17130. * Must point to a valid \c mbedtls_timing_delay_context struct.
  17131. * \param int_ms First (intermediate) delay in milliseconds.
  17132. * The effect if int_ms > fin_ms is unspecified.
  17133. * \param fin_ms Second (final) delay in milliseconds.
  17134. * Pass 0 to cancel the current delay.
  17135. *
  17136. * \note To set a single delay, either use \c mbedtls_timing_set_timer
  17137. * directly or use this function with int_ms == fin_ms.
  17138. */
  17139. void mbedtls_timing_set_delay( void *data, uint32_t int_ms, uint32_t fin_ms );
  17140. /**
  17141. * \brief Get the status of delays
  17142. * (Memory helper: number of delays passed.)
  17143. *
  17144. * \param data Pointer to timing data
  17145. * Must point to a valid \c mbedtls_timing_delay_context struct.
  17146. *
  17147. * \return -1 if cancelled (fin_ms = 0),
  17148. * 0 if none of the delays are passed,
  17149. * 1 if only the intermediate delay is passed,
  17150. * 2 if the final delay is passed.
  17151. */
  17152. int mbedtls_timing_get_delay( void *data );
  17153. #ifdef __cplusplus
  17154. }
  17155. #endif
  17156. #else /* MBEDTLS_TIMING_ALT */
  17157. #endif /* MBEDTLS_TIMING_ALT */
  17158. #ifdef __cplusplus
  17159. extern "C" {
  17160. #endif
  17161. #if defined(MBEDTLS_SELF_TEST)
  17162. /**
  17163. * \brief Checkup routine
  17164. *
  17165. * \return 0 if successful, or 1 if a test failed
  17166. */
  17167. int mbedtls_timing_self_test( int verbose );
  17168. #endif
  17169. #ifdef __cplusplus
  17170. }
  17171. #endif
  17172. #endif /* timing.h */
  17173. /********* Start of file include/mbedtls/xtea.h ************/
  17174. /**
  17175. * \file xtea.h
  17176. *
  17177. * \brief XTEA block cipher (32-bit)
  17178. */
  17179. /*
  17180. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  17181. * SPDX-License-Identifier: Apache-2.0
  17182. *
  17183. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  17184. * not use this file except in compliance with the License.
  17185. * You may obtain a copy of the License at
  17186. *
  17187. * http://www.apache.org/licenses/LICENSE-2.0
  17188. *
  17189. * Unless required by applicable law or agreed to in writing, software
  17190. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  17191. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17192. * See the License for the specific language governing permissions and
  17193. * limitations under the License.
  17194. *
  17195. * This file is part of mbed TLS (https://tls.mbed.org)
  17196. */
  17197. #ifndef MBEDTLS_XTEA_H
  17198. #define MBEDTLS_XTEA_H
  17199. #if !defined(MBEDTLS_CONFIG_FILE)
  17200. #else
  17201. #endif
  17202. #include <stddef.h>
  17203. #include <stdint.h>
  17204. #define MBEDTLS_XTEA_ENCRYPT 1
  17205. #define MBEDTLS_XTEA_DECRYPT 0
  17206. #define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
  17207. #define MBEDTLS_ERR_XTEA_HW_ACCEL_FAILED -0x0029 /**< XTEA hardware accelerator failed. */
  17208. #if !defined(MBEDTLS_XTEA_ALT)
  17209. // Regular implementation
  17210. //
  17211. #ifdef __cplusplus
  17212. extern "C" {
  17213. #endif
  17214. /**
  17215. * \brief XTEA context structure
  17216. */
  17217. typedef struct
  17218. {
  17219. uint32_t k[4]; /*!< key */
  17220. }
  17221. mbedtls_xtea_context;
  17222. /**
  17223. * \brief Initialize XTEA context
  17224. *
  17225. * \param ctx XTEA context to be initialized
  17226. */
  17227. void mbedtls_xtea_init( mbedtls_xtea_context *ctx );
  17228. /**
  17229. * \brief Clear XTEA context
  17230. *
  17231. * \param ctx XTEA context to be cleared
  17232. */
  17233. void mbedtls_xtea_free( mbedtls_xtea_context *ctx );
  17234. /**
  17235. * \brief XTEA key schedule
  17236. *
  17237. * \param ctx XTEA context to be initialized
  17238. * \param key the secret key
  17239. */
  17240. void mbedtls_xtea_setup( mbedtls_xtea_context *ctx, const unsigned char key[16] );
  17241. /**
  17242. * \brief XTEA cipher function
  17243. *
  17244. * \param ctx XTEA context
  17245. * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
  17246. * \param input 8-byte input block
  17247. * \param output 8-byte output block
  17248. *
  17249. * \return 0 if successful
  17250. */
  17251. int mbedtls_xtea_crypt_ecb( mbedtls_xtea_context *ctx,
  17252. int mode,
  17253. const unsigned char input[8],
  17254. unsigned char output[8] );
  17255. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  17256. /**
  17257. * \brief XTEA CBC cipher function
  17258. *
  17259. * \param ctx XTEA context
  17260. * \param mode MBEDTLS_XTEA_ENCRYPT or MBEDTLS_XTEA_DECRYPT
  17261. * \param length the length of input, multiple of 8
  17262. * \param iv initialization vector for CBC mode
  17263. * \param input input block
  17264. * \param output output block
  17265. *
  17266. * \return 0 if successful,
  17267. * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
  17268. */
  17269. int mbedtls_xtea_crypt_cbc( mbedtls_xtea_context *ctx,
  17270. int mode,
  17271. size_t length,
  17272. unsigned char iv[8],
  17273. const unsigned char *input,
  17274. unsigned char *output);
  17275. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  17276. #ifdef __cplusplus
  17277. }
  17278. #endif
  17279. #else /* MBEDTLS_XTEA_ALT */
  17280. #endif /* MBEDTLS_XTEA_ALT */
  17281. #ifdef __cplusplus
  17282. extern "C" {
  17283. #endif
  17284. /**
  17285. * \brief Checkup routine
  17286. *
  17287. * \return 0 if successful, or 1 if the test failed
  17288. */
  17289. int mbedtls_xtea_self_test( int verbose );
  17290. #ifdef __cplusplus
  17291. }
  17292. #endif
  17293. #endif /* xtea.h */
  17294. /********* Start of file include/mbedtls/ssl.h ************/
  17295. /**
  17296. * \file ssl.h
  17297. *
  17298. * \brief SSL/TLS functions.
  17299. */
  17300. /*
  17301. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  17302. * SPDX-License-Identifier: Apache-2.0
  17303. *
  17304. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  17305. * not use this file except in compliance with the License.
  17306. * You may obtain a copy of the License at
  17307. *
  17308. * http://www.apache.org/licenses/LICENSE-2.0
  17309. *
  17310. * Unless required by applicable law or agreed to in writing, software
  17311. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  17312. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17313. * See the License for the specific language governing permissions and
  17314. * limitations under the License.
  17315. *
  17316. * This file is part of mbed TLS (https://tls.mbed.org)
  17317. */
  17318. #ifndef MBEDTLS_SSL_H
  17319. #define MBEDTLS_SSL_H
  17320. #if !defined(MBEDTLS_CONFIG_FILE)
  17321. #else
  17322. #endif
  17323. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  17324. #endif
  17325. #if defined(MBEDTLS_DHM_C)
  17326. #endif
  17327. #if defined(MBEDTLS_ECDH_C)
  17328. #endif
  17329. #if defined(MBEDTLS_ZLIB_SUPPORT)
  17330. #if defined(MBEDTLS_DEPRECATED_WARNING)
  17331. #warning "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and will be removed in the next major revision of the library"
  17332. #endif
  17333. #if defined(MBEDTLS_DEPRECATED_REMOVED)
  17334. #error "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and cannot be used if MBEDTLS_DEPRECATED_REMOVED is set"
  17335. #endif
  17336. #endif
  17337. #if defined(MBEDTLS_HAVE_TIME)
  17338. #endif
  17339. /*
  17340. * SSL Error codes
  17341. */
  17342. #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 /**< The requested feature is not available. */
  17343. #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 /**< Bad input parameters to function. */
  17344. #define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 /**< Verification of the message MAC failed. */
  17345. #define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 /**< An invalid SSL record was received. */
  17346. #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 /**< The connection indicated an EOF. */
  17347. #define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300 /**< An unknown cipher was received. */
  17348. #define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */
  17349. #define MBEDTLS_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */
  17350. #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */
  17351. #define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */
  17352. #define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */
  17353. #define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */
  17354. #define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */
  17355. #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */
  17356. #define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */
  17357. #define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */
  17358. #define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */
  17359. #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */
  17360. #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */
  17361. #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */
  17362. #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */
  17363. #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */
  17364. #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */
  17365. #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */
  17366. #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */
  17367. #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */
  17368. #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */
  17369. #define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */
  17370. #define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */
  17371. #define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */
  17372. #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */
  17373. #define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */
  17374. #define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */
  17375. #define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */
  17376. #define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */
  17377. #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80 /**< Session ticket has expired. */
  17378. #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */
  17379. #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 /**< Unknown identity received (eg, PSK identity) */
  17380. #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */
  17381. #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */
  17382. #define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 /**< Unexpected message at ServerHello in renegotiation. */
  17383. #define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80 /**< DTLS client must retry for hello verification */
  17384. #define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00 /**< A buffer is too small to receive or write a message */
  17385. #define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980 /**< None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */
  17386. #define MBEDTLS_ERR_SSL_WANT_READ -0x6900 /**< Connection requires a read call. */
  17387. #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 /**< Connection requires a write call. */
  17388. #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */
  17389. #define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */
  17390. #define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700 /**< Record header looks valid but is not expected. */
  17391. #define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 /**< The alert message received indicates a non-fatal error. */
  17392. #define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 /**< Couldn't set the hash for verifying CertificateVerify */
  17393. /*
  17394. * Various constants
  17395. */
  17396. #define MBEDTLS_SSL_MAJOR_VERSION_3 3
  17397. #define MBEDTLS_SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */
  17398. #define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */
  17399. #define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */
  17400. #define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
  17401. #define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */
  17402. #define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */
  17403. #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255 /*!< Maximum host name defined in RFC 1035 */
  17404. /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
  17405. * NONE must be zero so that memset()ing structure to zero works */
  17406. #define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0 /*!< don't use this extension */
  17407. #define MBEDTLS_SSL_MAX_FRAG_LEN_512 1 /*!< MaxFragmentLength 2^9 */
  17408. #define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2 /*!< MaxFragmentLength 2^10 */
  17409. #define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3 /*!< MaxFragmentLength 2^11 */
  17410. #define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4 /*!< MaxFragmentLength 2^12 */
  17411. #define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5 /*!< first invalid value */
  17412. #define MBEDTLS_SSL_IS_CLIENT 0
  17413. #define MBEDTLS_SSL_IS_SERVER 1
  17414. #define MBEDTLS_SSL_IS_NOT_FALLBACK 0
  17415. #define MBEDTLS_SSL_IS_FALLBACK 1
  17416. #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
  17417. #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
  17418. #define MBEDTLS_SSL_ETM_DISABLED 0
  17419. #define MBEDTLS_SSL_ETM_ENABLED 1
  17420. #define MBEDTLS_SSL_COMPRESS_NULL 0
  17421. #define MBEDTLS_SSL_COMPRESS_DEFLATE 1
  17422. #define MBEDTLS_SSL_VERIFY_NONE 0
  17423. #define MBEDTLS_SSL_VERIFY_OPTIONAL 1
  17424. #define MBEDTLS_SSL_VERIFY_REQUIRED 2
  17425. #define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
  17426. #define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
  17427. #define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
  17428. #define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
  17429. #define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
  17430. #define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
  17431. #define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
  17432. #define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
  17433. #define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
  17434. #define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
  17435. #define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
  17436. #define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
  17437. #define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
  17438. #define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
  17439. #define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
  17440. #define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
  17441. #define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
  17442. #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
  17443. #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
  17444. #define MBEDTLS_SSL_ARC4_ENABLED 0
  17445. #define MBEDTLS_SSL_ARC4_DISABLED 1
  17446. #define MBEDTLS_SSL_PRESET_DEFAULT 0
  17447. #define MBEDTLS_SSL_PRESET_SUITEB 2
  17448. #define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED 1
  17449. #define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 0
  17450. /*
  17451. * Default range for DTLS retransmission timer value, in milliseconds.
  17452. * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
  17453. */
  17454. #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
  17455. #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
  17456. /**
  17457. * \name SECTION: Module settings
  17458. *
  17459. * The configuration options you can set for this module are in this section.
  17460. * Either change them in config.h or define them on the compiler command line.
  17461. * \{
  17462. */
  17463. #if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
  17464. #define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
  17465. #endif
  17466. /*
  17467. * Maxium fragment length in bytes,
  17468. * determines the size of each of the two internal I/O buffers.
  17469. *
  17470. * Note: the RFC defines the default size of SSL / TLS messages. If you
  17471. * change the value here, other clients / servers may not be able to
  17472. * communicate with you anymore. Only change this value if you control
  17473. * both sides of the connection and have it reduced at both sides, or
  17474. * if you're using the Max Fragment Length extension and you know all your
  17475. * peers are using it too!
  17476. */
  17477. #if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
  17478. #define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Size of the input / output buffer */
  17479. #endif
  17480. /* \} name SECTION: Module settings */
  17481. /*
  17482. * Length of the verify data for secure renegotiation
  17483. */
  17484. #if defined(MBEDTLS_SSL_PROTO_SSL3)
  17485. #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
  17486. #else
  17487. #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
  17488. #endif
  17489. /*
  17490. * Signaling ciphersuite values (SCSV)
  17491. */
  17492. #define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */
  17493. #define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600 /**< RFC 7507 section 2 */
  17494. /*
  17495. * Supported Signature and Hash algorithms (For TLS 1.2)
  17496. * RFC 5246 section 7.4.1.4.1
  17497. */
  17498. #define MBEDTLS_SSL_HASH_NONE 0
  17499. #define MBEDTLS_SSL_HASH_MD5 1
  17500. #define MBEDTLS_SSL_HASH_SHA1 2
  17501. #define MBEDTLS_SSL_HASH_SHA224 3
  17502. #define MBEDTLS_SSL_HASH_SHA256 4
  17503. #define MBEDTLS_SSL_HASH_SHA384 5
  17504. #define MBEDTLS_SSL_HASH_SHA512 6
  17505. #define MBEDTLS_SSL_SIG_ANON 0
  17506. #define MBEDTLS_SSL_SIG_RSA 1
  17507. #define MBEDTLS_SSL_SIG_ECDSA 3
  17508. /*
  17509. * Client Certificate Types
  17510. * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
  17511. */
  17512. #define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
  17513. #define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
  17514. /*
  17515. * Message, alert and handshake types
  17516. */
  17517. #define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
  17518. #define MBEDTLS_SSL_MSG_ALERT 21
  17519. #define MBEDTLS_SSL_MSG_HANDSHAKE 22
  17520. #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
  17521. #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
  17522. #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
  17523. #define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
  17524. #define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
  17525. #define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
  17526. #define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
  17527. #define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
  17528. #define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
  17529. #define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
  17530. #define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
  17531. #define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
  17532. #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
  17533. #define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
  17534. #define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
  17535. #define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
  17536. #define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
  17537. #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
  17538. #define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
  17539. #define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
  17540. #define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
  17541. #define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
  17542. #define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
  17543. #define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
  17544. #define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
  17545. #define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
  17546. #define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
  17547. #define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
  17548. #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
  17549. #define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
  17550. #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
  17551. #define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
  17552. #define MBEDTLS_SSL_HS_HELLO_REQUEST 0
  17553. #define MBEDTLS_SSL_HS_CLIENT_HELLO 1
  17554. #define MBEDTLS_SSL_HS_SERVER_HELLO 2
  17555. #define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
  17556. #define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
  17557. #define MBEDTLS_SSL_HS_CERTIFICATE 11
  17558. #define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
  17559. #define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
  17560. #define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
  17561. #define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
  17562. #define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
  17563. #define MBEDTLS_SSL_HS_FINISHED 20
  17564. /*
  17565. * TLS extensions
  17566. */
  17567. #define MBEDTLS_TLS_EXT_SERVERNAME 0
  17568. #define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
  17569. #define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
  17570. #define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
  17571. #define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
  17572. #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
  17573. #define MBEDTLS_TLS_EXT_SIG_ALG 13
  17574. #define MBEDTLS_TLS_EXT_ALPN 16
  17575. #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
  17576. #define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
  17577. #define MBEDTLS_TLS_EXT_SESSION_TICKET 35
  17578. #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
  17579. #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
  17580. /*
  17581. * Size defines
  17582. */
  17583. #if !defined(MBEDTLS_PSK_MAX_LEN)
  17584. #define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
  17585. #endif
  17586. /* Dummy type used only for its size */
  17587. union mbedtls_ssl_premaster_secret
  17588. {
  17589. #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
  17590. unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
  17591. #endif
  17592. #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
  17593. unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
  17594. #endif
  17595. #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
  17596. defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
  17597. defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
  17598. defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
  17599. unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
  17600. #endif
  17601. #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
  17602. unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
  17603. #endif
  17604. #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
  17605. unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE
  17606. + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
  17607. #endif
  17608. #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
  17609. unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
  17610. #endif
  17611. #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
  17612. unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
  17613. + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
  17614. #endif
  17615. #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
  17616. unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
  17617. #endif
  17618. };
  17619. #define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret )
  17620. #ifdef __cplusplus
  17621. extern "C" {
  17622. #endif
  17623. /*
  17624. * SSL state machine
  17625. */
  17626. typedef enum
  17627. {
  17628. MBEDTLS_SSL_HELLO_REQUEST,
  17629. MBEDTLS_SSL_CLIENT_HELLO,
  17630. MBEDTLS_SSL_SERVER_HELLO,
  17631. MBEDTLS_SSL_SERVER_CERTIFICATE,
  17632. MBEDTLS_SSL_SERVER_KEY_EXCHANGE,
  17633. MBEDTLS_SSL_CERTIFICATE_REQUEST,
  17634. MBEDTLS_SSL_SERVER_HELLO_DONE,
  17635. MBEDTLS_SSL_CLIENT_CERTIFICATE,
  17636. MBEDTLS_SSL_CLIENT_KEY_EXCHANGE,
  17637. MBEDTLS_SSL_CERTIFICATE_VERIFY,
  17638. MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC,
  17639. MBEDTLS_SSL_CLIENT_FINISHED,
  17640. MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC,
  17641. MBEDTLS_SSL_SERVER_FINISHED,
  17642. MBEDTLS_SSL_FLUSH_BUFFERS,
  17643. MBEDTLS_SSL_HANDSHAKE_WRAPUP,
  17644. MBEDTLS_SSL_HANDSHAKE_OVER,
  17645. MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET,
  17646. MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT,
  17647. }
  17648. mbedtls_ssl_states;
  17649. /**
  17650. * \brief Callback type: send data on the network.
  17651. *
  17652. * \note That callback may be either blocking or non-blocking.
  17653. *
  17654. * \param ctx Context for the send callback (typically a file descriptor)
  17655. * \param buf Buffer holding the data to send
  17656. * \param len Length of the data to send
  17657. *
  17658. * \return The callback must return the number of bytes sent if any,
  17659. * or a non-zero error code.
  17660. * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_WRITE
  17661. * must be returned when the operation would block.
  17662. *
  17663. * \note The callback is allowed to send fewer bytes than requested.
  17664. * It must always return the number of bytes actually sent.
  17665. */
  17666. typedef int mbedtls_ssl_send_t( void *ctx,
  17667. const unsigned char *buf,
  17668. size_t len );
  17669. /**
  17670. * \brief Callback type: receive data from the network.
  17671. *
  17672. * \note That callback may be either blocking or non-blocking.
  17673. *
  17674. * \param ctx Context for the receive callback (typically a file
  17675. * descriptor)
  17676. * \param buf Buffer to write the received data to
  17677. * \param len Length of the receive buffer
  17678. *
  17679. * \return The callback must return the number of bytes received,
  17680. * or a non-zero error code.
  17681. * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ
  17682. * must be returned when the operation would block.
  17683. *
  17684. * \note The callback may receive fewer bytes than the length of the
  17685. * buffer. It must always return the number of bytes actually
  17686. * received and written to the buffer.
  17687. */
  17688. typedef int mbedtls_ssl_recv_t( void *ctx,
  17689. unsigned char *buf,
  17690. size_t len );
  17691. /**
  17692. * \brief Callback type: receive data from the network, with timeout
  17693. *
  17694. * \note That callback must block until data is received, or the
  17695. * timeout delay expires, or the operation is interrupted by a
  17696. * signal.
  17697. *
  17698. * \param ctx Context for the receive callback (typically a file descriptor)
  17699. * \param buf Buffer to write the received data to
  17700. * \param len Length of the receive buffer
  17701. * \param timeout Maximum nomber of millisecondes to wait for data
  17702. * 0 means no timeout (potentially waiting forever)
  17703. *
  17704. * \return The callback must return the number of bytes received,
  17705. * or a non-zero error code:
  17706. * \c MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out,
  17707. * \c MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal.
  17708. *
  17709. * \note The callback may receive fewer bytes than the length of the
  17710. * buffer. It must always return the number of bytes actually
  17711. * received and written to the buffer.
  17712. */
  17713. typedef int mbedtls_ssl_recv_timeout_t( void *ctx,
  17714. unsigned char *buf,
  17715. size_t len,
  17716. uint32_t timeout );
  17717. /**
  17718. * \brief Callback type: set a pair of timers/delays to watch
  17719. *
  17720. * \param ctx Context pointer
  17721. * \param int_ms Intermediate delay in milliseconds
  17722. * \param fin_ms Final delay in milliseconds
  17723. * 0 cancels the current timer.
  17724. *
  17725. * \note This callback must at least store the necessary information
  17726. * for the associated \c mbedtls_ssl_get_timer_t callback to
  17727. * return correct information.
  17728. *
  17729. * \note If using a event-driven style of programming, an event must
  17730. * be generated when the final delay is passed. The event must
  17731. * cause a call to \c mbedtls_ssl_handshake() with the proper
  17732. * SSL context to be scheduled. Care must be taken to ensure
  17733. * that at most one such call happens at a time.
  17734. *
  17735. * \note Only one timer at a time must be running. Calling this
  17736. * function while a timer is running must cancel it. Cancelled
  17737. * timers must not generate any event.
  17738. */
  17739. typedef void mbedtls_ssl_set_timer_t( void * ctx,
  17740. uint32_t int_ms,
  17741. uint32_t fin_ms );
  17742. /**
  17743. * \brief Callback type: get status of timers/delays
  17744. *
  17745. * \param ctx Context pointer
  17746. *
  17747. * \return This callback must return:
  17748. * -1 if cancelled (fin_ms == 0),
  17749. * 0 if none of the delays have passed,
  17750. * 1 if only the intermediate delay has passed,
  17751. * 2 if the final delay has passed.
  17752. */
  17753. typedef int mbedtls_ssl_get_timer_t( void * ctx );
  17754. /* Defined below */
  17755. typedef struct mbedtls_ssl_session mbedtls_ssl_session;
  17756. typedef struct mbedtls_ssl_context mbedtls_ssl_context;
  17757. typedef struct mbedtls_ssl_config mbedtls_ssl_config;
  17758. /* Defined in ssl_internal.h */
  17759. typedef struct mbedtls_ssl_transform mbedtls_ssl_transform;
  17760. typedef struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params;
  17761. typedef struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t;
  17762. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  17763. typedef struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert;
  17764. #endif
  17765. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  17766. typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item;
  17767. #endif
  17768. /*
  17769. * This structure is used for storing current session data.
  17770. */
  17771. struct mbedtls_ssl_session
  17772. {
  17773. #if defined(MBEDTLS_HAVE_TIME)
  17774. mbedtls_time_t start; /*!< starting time */
  17775. #endif
  17776. int ciphersuite; /*!< chosen ciphersuite */
  17777. int compression; /*!< chosen compression */
  17778. size_t id_len; /*!< session id length */
  17779. unsigned char id[32]; /*!< session identifier */
  17780. unsigned char master[48]; /*!< the master secret */
  17781. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  17782. mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */
  17783. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  17784. uint32_t verify_result; /*!< verification result */
  17785. #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
  17786. unsigned char *ticket; /*!< RFC 5077 session ticket */
  17787. size_t ticket_len; /*!< session ticket length */
  17788. uint32_t ticket_lifetime; /*!< ticket lifetime hint */
  17789. #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
  17790. #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
  17791. unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */
  17792. #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
  17793. #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
  17794. int trunc_hmac; /*!< flag for truncated hmac activation */
  17795. #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
  17796. #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  17797. int encrypt_then_mac; /*!< flag for EtM activation */
  17798. #endif
  17799. };
  17800. /**
  17801. * SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
  17802. */
  17803. struct mbedtls_ssl_config
  17804. {
  17805. /* Group items by size (largest first) to minimize padding overhead */
  17806. /*
  17807. * Pointers
  17808. */
  17809. const int *ciphersuite_list[4]; /*!< allowed ciphersuites per version */
  17810. /** Callback for printing debug output */
  17811. void (*f_dbg)(void *, int, const char *, int, const char *);
  17812. void *p_dbg; /*!< context for the debug function */
  17813. /** Callback for getting (pseudo-)random numbers */
  17814. int (*f_rng)(void *, unsigned char *, size_t);
  17815. void *p_rng; /*!< context for the RNG function */
  17816. /** Callback to retrieve a session from the cache */
  17817. int (*f_get_cache)(void *, mbedtls_ssl_session *);
  17818. /** Callback to store a session into the cache */
  17819. int (*f_set_cache)(void *, const mbedtls_ssl_session *);
  17820. void *p_cache; /*!< context for cache callbacks */
  17821. #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
  17822. /** Callback for setting cert according to SNI extension */
  17823. int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
  17824. void *p_sni; /*!< context for SNI callback */
  17825. #endif
  17826. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  17827. /** Callback to customize X.509 certificate chain verification */
  17828. int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
  17829. void *p_vrfy; /*!< context for X.509 verify calllback */
  17830. #endif
  17831. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
  17832. /** Callback to retrieve PSK key from identity */
  17833. int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
  17834. void *p_psk; /*!< context for PSK callback */
  17835. #endif
  17836. #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
  17837. /** Callback to create & write a cookie for ClientHello veirifcation */
  17838. int (*f_cookie_write)( void *, unsigned char **, unsigned char *,
  17839. const unsigned char *, size_t );
  17840. /** Callback to verify validity of a ClientHello cookie */
  17841. int (*f_cookie_check)( void *, const unsigned char *, size_t,
  17842. const unsigned char *, size_t );
  17843. void *p_cookie; /*!< context for the cookie callbacks */
  17844. #endif
  17845. #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
  17846. /** Callback to create & write a session ticket */
  17847. int (*f_ticket_write)( void *, const mbedtls_ssl_session *,
  17848. unsigned char *, const unsigned char *, size_t *, uint32_t * );
  17849. /** Callback to parse a session ticket into a session structure */
  17850. int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t);
  17851. void *p_ticket; /*!< context for the ticket callbacks */
  17852. #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
  17853. #if defined(MBEDTLS_SSL_EXPORT_KEYS)
  17854. /** Callback to export key block and master secret */
  17855. int (*f_export_keys)( void *, const unsigned char *,
  17856. const unsigned char *, size_t, size_t, size_t );
  17857. void *p_export_keys; /*!< context for key export callback */
  17858. #endif
  17859. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  17860. const mbedtls_x509_crt_profile *cert_profile; /*!< verification profile */
  17861. mbedtls_ssl_key_cert *key_cert; /*!< own certificate/key pair(s) */
  17862. mbedtls_x509_crt *ca_chain; /*!< trusted CAs */
  17863. mbedtls_x509_crl *ca_crl; /*!< trusted CAs CRLs */
  17864. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  17865. #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
  17866. const int *sig_hashes; /*!< allowed signature hashes */
  17867. #endif
  17868. #if defined(MBEDTLS_ECP_C)
  17869. const mbedtls_ecp_group_id *curve_list; /*!< allowed curves */
  17870. #endif
  17871. #if defined(MBEDTLS_DHM_C)
  17872. mbedtls_mpi dhm_P; /*!< prime modulus for DHM */
  17873. mbedtls_mpi dhm_G; /*!< generator for DHM */
  17874. #endif
  17875. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
  17876. unsigned char *psk; /*!< pre-shared key */
  17877. size_t psk_len; /*!< length of the pre-shared key */
  17878. unsigned char *psk_identity; /*!< identity for PSK negotiation */
  17879. size_t psk_identity_len;/*!< length of identity */
  17880. #endif
  17881. #if defined(MBEDTLS_SSL_ALPN)
  17882. const char **alpn_list; /*!< ordered list of protocols */
  17883. #endif
  17884. /*
  17885. * Numerical settings (int then char)
  17886. */
  17887. uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */
  17888. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  17889. uint32_t hs_timeout_min; /*!< initial value of the handshake
  17890. retransmission timeout (ms) */
  17891. uint32_t hs_timeout_max; /*!< maximum value of the handshake
  17892. retransmission timeout (ms) */
  17893. #endif
  17894. #if defined(MBEDTLS_SSL_RENEGOTIATION)
  17895. int renego_max_records; /*!< grace period for renegotiation */
  17896. unsigned char renego_period[8]; /*!< value of the record counters
  17897. that triggers renegotiation */
  17898. #endif
  17899. #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
  17900. unsigned int badmac_limit; /*!< limit of records with a bad MAC */
  17901. #endif
  17902. #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
  17903. unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
  17904. #endif
  17905. unsigned char max_major_ver; /*!< max. major version used */
  17906. unsigned char max_minor_ver; /*!< max. minor version used */
  17907. unsigned char min_major_ver; /*!< min. major version used */
  17908. unsigned char min_minor_ver; /*!< min. minor version used */
  17909. /*
  17910. * Flags (bitfields)
  17911. */
  17912. unsigned int endpoint : 1; /*!< 0: client, 1: server */
  17913. unsigned int transport : 1; /*!< stream (TLS) or datagram (DTLS) */
  17914. unsigned int authmode : 2; /*!< MBEDTLS_SSL_VERIFY_XXX */
  17915. /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
  17916. unsigned int allow_legacy_renegotiation : 2 ; /*!< MBEDTLS_LEGACY_XXX */
  17917. #if defined(MBEDTLS_ARC4_C)
  17918. unsigned int arc4_disabled : 1; /*!< blacklist RC4 ciphersuites? */
  17919. #endif
  17920. #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
  17921. unsigned int mfl_code : 3; /*!< desired fragment length */
  17922. #endif
  17923. #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  17924. unsigned int encrypt_then_mac : 1 ; /*!< negotiate encrypt-then-mac? */
  17925. #endif
  17926. #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
  17927. unsigned int extended_ms : 1; /*!< negotiate extended master secret? */
  17928. #endif
  17929. #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
  17930. unsigned int anti_replay : 1; /*!< detect and prevent replay? */
  17931. #endif
  17932. #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
  17933. unsigned int cbc_record_splitting : 1; /*!< do cbc record splitting */
  17934. #endif
  17935. #if defined(MBEDTLS_SSL_RENEGOTIATION)
  17936. unsigned int disable_renegotiation : 1; /*!< disable renegotiation? */
  17937. #endif
  17938. #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
  17939. unsigned int trunc_hmac : 1; /*!< negotiate truncated hmac? */
  17940. #endif
  17941. #if defined(MBEDTLS_SSL_SESSION_TICKETS)
  17942. unsigned int session_tickets : 1; /*!< use session tickets? */
  17943. #endif
  17944. #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
  17945. unsigned int fallback : 1; /*!< is this a fallback? */
  17946. #endif
  17947. #if defined(MBEDTLS_SSL_SRV_C)
  17948. unsigned int cert_req_ca_list : 1; /*!< enable sending CA list in
  17949. Certificate Request messages? */
  17950. #endif
  17951. };
  17952. struct mbedtls_ssl_context
  17953. {
  17954. const mbedtls_ssl_config *conf; /*!< configuration information */
  17955. /*
  17956. * Miscellaneous
  17957. */
  17958. int state; /*!< SSL handshake: current state */
  17959. #if defined(MBEDTLS_SSL_RENEGOTIATION)
  17960. int renego_status; /*!< Initial, in progress, pending? */
  17961. int renego_records_seen; /*!< Records since renego request, or with DTLS,
  17962. number of retransmissions of request if
  17963. renego_max_records is < 0 */
  17964. #endif
  17965. int major_ver; /*!< equal to MBEDTLS_SSL_MAJOR_VERSION_3 */
  17966. int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
  17967. #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
  17968. unsigned badmac_seen; /*!< records with a bad MAC received */
  17969. #endif
  17970. mbedtls_ssl_send_t *f_send; /*!< Callback for network send */
  17971. mbedtls_ssl_recv_t *f_recv; /*!< Callback for network receive */
  17972. mbedtls_ssl_recv_timeout_t *f_recv_timeout;
  17973. /*!< Callback for network receive with timeout */
  17974. void *p_bio; /*!< context for I/O operations */
  17975. /*
  17976. * Session layer
  17977. */
  17978. mbedtls_ssl_session *session_in; /*!< current session data (in) */
  17979. mbedtls_ssl_session *session_out; /*!< current session data (out) */
  17980. mbedtls_ssl_session *session; /*!< negotiated session data */
  17981. mbedtls_ssl_session *session_negotiate; /*!< session data in negotiation */
  17982. mbedtls_ssl_handshake_params *handshake; /*!< params required only during
  17983. the handshake process */
  17984. /*
  17985. * Record layer transformations
  17986. */
  17987. mbedtls_ssl_transform *transform_in; /*!< current transform params (in) */
  17988. mbedtls_ssl_transform *transform_out; /*!< current transform params (in) */
  17989. mbedtls_ssl_transform *transform; /*!< negotiated transform params */
  17990. mbedtls_ssl_transform *transform_negotiate; /*!< transform params in negotiation */
  17991. /*
  17992. * Timers
  17993. */
  17994. void *p_timer; /*!< context for the timer callbacks */
  17995. mbedtls_ssl_set_timer_t *f_set_timer; /*!< set timer callback */
  17996. mbedtls_ssl_get_timer_t *f_get_timer; /*!< get timer callback */
  17997. /*
  17998. * Record layer (incoming data)
  17999. */
  18000. unsigned char *in_buf; /*!< input buffer */
  18001. unsigned char *in_ctr; /*!< 64-bit incoming message counter
  18002. TLS: maintained by us
  18003. DTLS: read from peer */
  18004. unsigned char *in_hdr; /*!< start of record header */
  18005. unsigned char *in_len; /*!< two-bytes message length field */
  18006. unsigned char *in_iv; /*!< ivlen-byte IV */
  18007. unsigned char *in_msg; /*!< message contents (in_iv+ivlen) */
  18008. unsigned char *in_offt; /*!< read offset in application data */
  18009. int in_msgtype; /*!< record header: message type */
  18010. size_t in_msglen; /*!< record header: message length */
  18011. size_t in_left; /*!< amount of data read so far */
  18012. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  18013. uint16_t in_epoch; /*!< DTLS epoch for incoming records */
  18014. size_t next_record_offset; /*!< offset of the next record in datagram
  18015. (equal to in_left if none) */
  18016. #endif
  18017. #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
  18018. uint64_t in_window_top; /*!< last validated record seq_num */
  18019. uint64_t in_window; /*!< bitmask for replay detection */
  18020. #endif
  18021. size_t in_hslen; /*!< current handshake message length,
  18022. including the handshake header */
  18023. int nb_zero; /*!< # of 0-length encrypted messages */
  18024. int keep_current_message; /*!< drop or reuse current message
  18025. on next call to record layer? */
  18026. /*
  18027. * Record layer (outgoing data)
  18028. */
  18029. unsigned char *out_buf; /*!< output buffer */
  18030. unsigned char *out_ctr; /*!< 64-bit outgoing message counter */
  18031. unsigned char *out_hdr; /*!< start of record header */
  18032. unsigned char *out_len; /*!< two-bytes message length field */
  18033. unsigned char *out_iv; /*!< ivlen-byte IV */
  18034. unsigned char *out_msg; /*!< message contents (out_iv+ivlen) */
  18035. int out_msgtype; /*!< record header: message type */
  18036. size_t out_msglen; /*!< record header: message length */
  18037. size_t out_left; /*!< amount of data not yet written */
  18038. #if defined(MBEDTLS_ZLIB_SUPPORT)
  18039. unsigned char *compress_buf; /*!< zlib data buffer */
  18040. #endif
  18041. #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
  18042. signed char split_done; /*!< current record already splitted? */
  18043. #endif
  18044. /*
  18045. * PKI layer
  18046. */
  18047. int client_auth; /*!< flag for client auth. */
  18048. /*
  18049. * User settings
  18050. */
  18051. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  18052. char *hostname; /*!< expected peer CN for verification
  18053. (and SNI if available) */
  18054. #endif
  18055. #if defined(MBEDTLS_SSL_ALPN)
  18056. const char *alpn_chosen; /*!< negotiated protocol */
  18057. #endif
  18058. /*
  18059. * Information for DTLS hello verify
  18060. */
  18061. #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
  18062. unsigned char *cli_id; /*!< transport-level ID of the client */
  18063. size_t cli_id_len; /*!< length of cli_id */
  18064. #endif
  18065. /*
  18066. * Secure renegotiation
  18067. */
  18068. /* needed to know when to send extension on server */
  18069. int secure_renegotiation; /*!< does peer support legacy or
  18070. secure renegotiation */
  18071. #if defined(MBEDTLS_SSL_RENEGOTIATION)
  18072. size_t verify_data_len; /*!< length of verify data stored */
  18073. char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
  18074. char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
  18075. #endif
  18076. void *appData;
  18077. };
  18078. #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
  18079. #define MBEDTLS_SSL_CHANNEL_OUTBOUND 0
  18080. #define MBEDTLS_SSL_CHANNEL_INBOUND 1
  18081. extern int (*mbedtls_ssl_hw_record_init)(mbedtls_ssl_context *ssl,
  18082. const unsigned char *key_enc, const unsigned char *key_dec,
  18083. size_t keylen,
  18084. const unsigned char *iv_enc, const unsigned char *iv_dec,
  18085. size_t ivlen,
  18086. const unsigned char *mac_enc, const unsigned char *mac_dec,
  18087. size_t maclen);
  18088. extern int (*mbedtls_ssl_hw_record_activate)(mbedtls_ssl_context *ssl, int direction);
  18089. extern int (*mbedtls_ssl_hw_record_reset)(mbedtls_ssl_context *ssl);
  18090. extern int (*mbedtls_ssl_hw_record_write)(mbedtls_ssl_context *ssl);
  18091. extern int (*mbedtls_ssl_hw_record_read)(mbedtls_ssl_context *ssl);
  18092. extern int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context *ssl);
  18093. #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
  18094. /**
  18095. * \brief Returns the list of ciphersuites supported by the SSL/TLS module.
  18096. *
  18097. * \return a statically allocated array of ciphersuites, the last
  18098. * entry is 0.
  18099. */
  18100. const int *mbedtls_ssl_list_ciphersuites( void );
  18101. /**
  18102. * \brief Return the name of the ciphersuite associated with the
  18103. * given ID
  18104. *
  18105. * \param ciphersuite_id SSL ciphersuite ID
  18106. *
  18107. * \return a string containing the ciphersuite name
  18108. */
  18109. const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id );
  18110. /**
  18111. * \brief Return the ID of the ciphersuite associated with the
  18112. * given name
  18113. *
  18114. * \param ciphersuite_name SSL ciphersuite name
  18115. *
  18116. * \return the ID with the ciphersuite or 0 if not found
  18117. */
  18118. int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name );
  18119. /**
  18120. * \brief Initialize an SSL context
  18121. * Just makes the context ready for mbedtls_ssl_setup() or
  18122. * mbedtls_ssl_free()
  18123. *
  18124. * \param ssl SSL context
  18125. */
  18126. void mbedtls_ssl_init( mbedtls_ssl_context *ssl );
  18127. /**
  18128. * \brief Set up an SSL context for use
  18129. *
  18130. * \note No copy of the configuration context is made, it can be
  18131. * shared by many mbedtls_ssl_context structures.
  18132. *
  18133. * \warning The conf structure will be accessed during the session.
  18134. * It must not be modified or freed as long as the session
  18135. * is active.
  18136. *
  18137. * \warning This function must be called exactly once per context.
  18138. * Calling mbedtls_ssl_setup again is not supported, even
  18139. * if no session is active.
  18140. *
  18141. * \param ssl SSL context
  18142. * \param conf SSL configuration to use
  18143. *
  18144. * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED if
  18145. * memory allocation failed
  18146. */
  18147. int mbedtls_ssl_setup( mbedtls_ssl_context *ssl,
  18148. const mbedtls_ssl_config *conf );
  18149. /**
  18150. * \brief Reset an already initialized SSL context for re-use
  18151. * while retaining application-set variables, function
  18152. * pointers and data.
  18153. *
  18154. * \param ssl SSL context
  18155. * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED,
  18156. MBEDTLS_ERR_SSL_HW_ACCEL_FAILED or
  18157. * MBEDTLS_ERR_SSL_COMPRESSION_FAILED
  18158. */
  18159. int mbedtls_ssl_session_reset( mbedtls_ssl_context *ssl );
  18160. /**
  18161. * \brief Set the current endpoint type
  18162. *
  18163. * \param conf SSL configuration
  18164. * \param endpoint must be MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
  18165. */
  18166. void mbedtls_ssl_conf_endpoint( mbedtls_ssl_config *conf, int endpoint );
  18167. /**
  18168. * \brief Set the transport type (TLS or DTLS).
  18169. * Default: TLS
  18170. *
  18171. * \note For DTLS, you must either provide a recv callback that
  18172. * doesn't block, or one that handles timeouts, see
  18173. * \c mbedtls_ssl_set_bio(). You also need to provide timer
  18174. * callbacks with \c mbedtls_ssl_set_timer_cb().
  18175. *
  18176. * \param conf SSL configuration
  18177. * \param transport transport type:
  18178. * MBEDTLS_SSL_TRANSPORT_STREAM for TLS,
  18179. * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS.
  18180. */
  18181. void mbedtls_ssl_conf_transport( mbedtls_ssl_config *conf, int transport );
  18182. /**
  18183. * \brief Set the certificate verification mode
  18184. * Default: NONE on server, REQUIRED on client
  18185. *
  18186. * \param conf SSL configuration
  18187. * \param authmode can be:
  18188. *
  18189. * MBEDTLS_SSL_VERIFY_NONE: peer certificate is not checked
  18190. * (default on server)
  18191. * (insecure on client)
  18192. *
  18193. * MBEDTLS_SSL_VERIFY_OPTIONAL: peer certificate is checked, however the
  18194. * handshake continues even if verification failed;
  18195. * mbedtls_ssl_get_verify_result() can be called after the
  18196. * handshake is complete.
  18197. *
  18198. * MBEDTLS_SSL_VERIFY_REQUIRED: peer *must* present a valid certificate,
  18199. * handshake is aborted if verification failed.
  18200. * (default on client)
  18201. *
  18202. * \note On client, MBEDTLS_SSL_VERIFY_REQUIRED is the recommended mode.
  18203. * With MBEDTLS_SSL_VERIFY_OPTIONAL, the user needs to call mbedtls_ssl_get_verify_result() at
  18204. * the right time(s), which may not be obvious, while REQUIRED always perform
  18205. * the verification as soon as possible. For example, REQUIRED was protecting
  18206. * against the "triple handshake" attack even before it was found.
  18207. */
  18208. void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
  18209. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  18210. /**
  18211. * \brief Set the verification callback (Optional).
  18212. *
  18213. * If set, the verify callback is called for each
  18214. * certificate in the chain. For implementation
  18215. * information, please see \c mbedtls_x509_crt_verify()
  18216. *
  18217. * \param conf SSL configuration
  18218. * \param f_vrfy verification function
  18219. * \param p_vrfy verification parameter
  18220. */
  18221. void mbedtls_ssl_conf_verify( mbedtls_ssl_config *conf,
  18222. int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
  18223. void *p_vrfy );
  18224. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  18225. /**
  18226. * \brief Set the random number generator callback
  18227. *
  18228. * \param conf SSL configuration
  18229. * \param f_rng RNG function
  18230. * \param p_rng RNG parameter
  18231. */
  18232. void mbedtls_ssl_conf_rng( mbedtls_ssl_config *conf,
  18233. int (*f_rng)(void *, unsigned char *, size_t),
  18234. void *p_rng );
  18235. /**
  18236. * \brief Set the debug callback
  18237. *
  18238. * The callback has the following argument:
  18239. * void * opaque context for the callback
  18240. * int debug level
  18241. * const char * file name
  18242. * int line number
  18243. * const char * message
  18244. *
  18245. * \param conf SSL configuration
  18246. * \param f_dbg debug function
  18247. * \param p_dbg debug parameter
  18248. */
  18249. void mbedtls_ssl_conf_dbg( mbedtls_ssl_config *conf,
  18250. void (*f_dbg)(void *, int, const char *, int, const char *),
  18251. void *p_dbg );
  18252. /**
  18253. * \brief Set the underlying BIO callbacks for write, read and
  18254. * read-with-timeout.
  18255. *
  18256. * \param ssl SSL context
  18257. * \param p_bio parameter (context) shared by BIO callbacks
  18258. * \param f_send write callback
  18259. * \param f_recv read callback
  18260. * \param f_recv_timeout blocking read callback with timeout.
  18261. *
  18262. * \note One of f_recv or f_recv_timeout can be NULL, in which case
  18263. * the other is used. If both are non-NULL, f_recv_timeout is
  18264. * used and f_recv is ignored (as if it were NULL).
  18265. *
  18266. * \note The two most common use cases are:
  18267. * - non-blocking I/O, f_recv != NULL, f_recv_timeout == NULL
  18268. * - blocking I/O, f_recv == NULL, f_recv_timout != NULL
  18269. *
  18270. * \note For DTLS, you need to provide either a non-NULL
  18271. * f_recv_timeout callback, or a f_recv that doesn't block.
  18272. *
  18273. * \note See the documentations of \c mbedtls_ssl_sent_t,
  18274. * \c mbedtls_ssl_recv_t and \c mbedtls_ssl_recv_timeout_t for
  18275. * the conventions those callbacks must follow.
  18276. *
  18277. * \note On some platforms, net_sockets.c provides
  18278. * \c mbedtls_net_send(), \c mbedtls_net_recv() and
  18279. * \c mbedtls_net_recv_timeout() that are suitable to be used
  18280. * here.
  18281. */
  18282. void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
  18283. void *p_bio,
  18284. mbedtls_ssl_send_t *f_send,
  18285. mbedtls_ssl_recv_t *f_recv,
  18286. mbedtls_ssl_recv_timeout_t *f_recv_timeout );
  18287. /**
  18288. * \brief Set the timeout period for mbedtls_ssl_read()
  18289. * (Default: no timeout.)
  18290. *
  18291. * \param conf SSL configuration context
  18292. * \param timeout Timeout value in milliseconds.
  18293. * Use 0 for no timeout (default).
  18294. *
  18295. * \note With blocking I/O, this will only work if a non-NULL
  18296. * \c f_recv_timeout was set with \c mbedtls_ssl_set_bio().
  18297. * With non-blocking I/O, this will only work if timer
  18298. * callbacks were set with \c mbedtls_ssl_set_timer_cb().
  18299. *
  18300. * \note With non-blocking I/O, you may also skip this function
  18301. * altogether and handle timeouts at the application layer.
  18302. */
  18303. void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
  18304. /**
  18305. * \brief Set the timer callbacks (Mandatory for DTLS.)
  18306. *
  18307. * \param ssl SSL context
  18308. * \param p_timer parameter (context) shared by timer callbacks
  18309. * \param f_set_timer set timer callback
  18310. * \param f_get_timer get timer callback. Must return:
  18311. *
  18312. * \note See the documentation of \c mbedtls_ssl_set_timer_t and
  18313. * \c mbedtls_ssl_get_timer_t for the conventions this pair of
  18314. * callbacks must follow.
  18315. *
  18316. * \note On some platforms, timing.c provides
  18317. * \c mbedtls_timing_set_delay() and
  18318. * \c mbedtls_timing_get_delay() that are suitable for using
  18319. * here, except if using an event-driven style.
  18320. *
  18321. * \note See also the "DTLS tutorial" article in our knowledge base.
  18322. * https://tls.mbed.org/kb/how-to/dtls-tutorial
  18323. */
  18324. void mbedtls_ssl_set_timer_cb( mbedtls_ssl_context *ssl,
  18325. void *p_timer,
  18326. mbedtls_ssl_set_timer_t *f_set_timer,
  18327. mbedtls_ssl_get_timer_t *f_get_timer );
  18328. /**
  18329. * \brief Callback type: generate and write session ticket
  18330. *
  18331. * \note This describes what a callback implementation should do.
  18332. * This callback should generate an encrypted and
  18333. * authenticated ticket for the session and write it to the
  18334. * output buffer. Here, ticket means the opaque ticket part
  18335. * of the NewSessionTicket structure of RFC 5077.
  18336. *
  18337. * \param p_ticket Context for the callback
  18338. * \param session SSL session to be written in the ticket
  18339. * \param start Start of the output buffer
  18340. * \param end End of the output buffer
  18341. * \param tlen On exit, holds the length written
  18342. * \param lifetime On exit, holds the lifetime of the ticket in seconds
  18343. *
  18344. * \return 0 if successful, or
  18345. * a specific MBEDTLS_ERR_XXX code.
  18346. */
  18347. typedef int mbedtls_ssl_ticket_write_t( void *p_ticket,
  18348. const mbedtls_ssl_session *session,
  18349. unsigned char *start,
  18350. const unsigned char *end,
  18351. size_t *tlen,
  18352. uint32_t *lifetime );
  18353. #if defined(MBEDTLS_SSL_EXPORT_KEYS)
  18354. /**
  18355. * \brief Callback type: Export key block and master secret
  18356. *
  18357. * \note This is required for certain uses of TLS, e.g. EAP-TLS
  18358. * (RFC 5216) and Thread. The key pointers are ephemeral and
  18359. * therefore must not be stored. The master secret and keys
  18360. * should not be used directly except as an input to a key
  18361. * derivation function.
  18362. *
  18363. * \param p_expkey Context for the callback
  18364. * \param ms Pointer to master secret (fixed length: 48 bytes)
  18365. * \param kb Pointer to key block, see RFC 5246 section 6.3
  18366. * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
  18367. * \param maclen MAC length
  18368. * \param keylen Key length
  18369. * \param ivlen IV length
  18370. *
  18371. * \return 0 if successful, or
  18372. * a specific MBEDTLS_ERR_XXX code.
  18373. */
  18374. typedef int mbedtls_ssl_export_keys_t( void *p_expkey,
  18375. const unsigned char *ms,
  18376. const unsigned char *kb,
  18377. size_t maclen,
  18378. size_t keylen,
  18379. size_t ivlen );
  18380. #endif /* MBEDTLS_SSL_EXPORT_KEYS */
  18381. /**
  18382. * \brief Callback type: parse and load session ticket
  18383. *
  18384. * \note This describes what a callback implementation should do.
  18385. * This callback should parse a session ticket as generated
  18386. * by the corresponding mbedtls_ssl_ticket_write_t function,
  18387. * and, if the ticket is authentic and valid, load the
  18388. * session.
  18389. *
  18390. * \note The implementation is allowed to modify the first len
  18391. * bytes of the input buffer, eg to use it as a temporary
  18392. * area for the decrypted ticket contents.
  18393. *
  18394. * \param p_ticket Context for the callback
  18395. * \param session SSL session to be loaded
  18396. * \param buf Start of the buffer containing the ticket
  18397. * \param len Length of the ticket.
  18398. *
  18399. * \return 0 if successful, or
  18400. * MBEDTLS_ERR_SSL_INVALID_MAC if not authentic, or
  18401. * MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED if expired, or
  18402. * any other non-zero code for other failures.
  18403. */
  18404. typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket,
  18405. mbedtls_ssl_session *session,
  18406. unsigned char *buf,
  18407. size_t len );
  18408. #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
  18409. /**
  18410. * \brief Configure SSL session ticket callbacks (server only).
  18411. * (Default: none.)
  18412. *
  18413. * \note On server, session tickets are enabled by providing
  18414. * non-NULL callbacks.
  18415. *
  18416. * \note On client, use \c mbedtls_ssl_conf_session_tickets().
  18417. *
  18418. * \param conf SSL configuration context
  18419. * \param f_ticket_write Callback for writing a ticket
  18420. * \param f_ticket_parse Callback for parsing a ticket
  18421. * \param p_ticket Context shared by the two callbacks
  18422. */
  18423. void mbedtls_ssl_conf_session_tickets_cb( mbedtls_ssl_config *conf,
  18424. mbedtls_ssl_ticket_write_t *f_ticket_write,
  18425. mbedtls_ssl_ticket_parse_t *f_ticket_parse,
  18426. void *p_ticket );
  18427. #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
  18428. #if defined(MBEDTLS_SSL_EXPORT_KEYS)
  18429. /**
  18430. * \brief Configure key export callback.
  18431. * (Default: none.)
  18432. *
  18433. * \note See \c mbedtls_ssl_export_keys_t.
  18434. *
  18435. * \param conf SSL configuration context
  18436. * \param f_export_keys Callback for exporting keys
  18437. * \param p_export_keys Context for the callback
  18438. */
  18439. void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf,
  18440. mbedtls_ssl_export_keys_t *f_export_keys,
  18441. void *p_export_keys );
  18442. #endif /* MBEDTLS_SSL_EXPORT_KEYS */
  18443. /**
  18444. * \brief Callback type: generate a cookie
  18445. *
  18446. * \param ctx Context for the callback
  18447. * \param p Buffer to write to,
  18448. * must be updated to point right after the cookie
  18449. * \param end Pointer to one past the end of the output buffer
  18450. * \param info Client ID info that was passed to
  18451. * \c mbedtls_ssl_set_client_transport_id()
  18452. * \param ilen Length of info in bytes
  18453. *
  18454. * \return The callback must return 0 on success,
  18455. * or a negative error code.
  18456. */
  18457. typedef int mbedtls_ssl_cookie_write_t( void *ctx,
  18458. unsigned char **p, unsigned char *end,
  18459. const unsigned char *info, size_t ilen );
  18460. /**
  18461. * \brief Callback type: verify a cookie
  18462. *
  18463. * \param ctx Context for the callback
  18464. * \param cookie Cookie to verify
  18465. * \param clen Length of cookie
  18466. * \param info Client ID info that was passed to
  18467. * \c mbedtls_ssl_set_client_transport_id()
  18468. * \param ilen Length of info in bytes
  18469. *
  18470. * \return The callback must return 0 if cookie is valid,
  18471. * or a negative error code.
  18472. */
  18473. typedef int mbedtls_ssl_cookie_check_t( void *ctx,
  18474. const unsigned char *cookie, size_t clen,
  18475. const unsigned char *info, size_t ilen );
  18476. #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
  18477. /**
  18478. * \brief Register callbacks for DTLS cookies
  18479. * (Server only. DTLS only.)
  18480. *
  18481. * Default: dummy callbacks that fail, in order to force you to
  18482. * register working callbacks (and initialize their context).
  18483. *
  18484. * To disable HelloVerifyRequest, register NULL callbacks.
  18485. *
  18486. * \warning Disabling hello verification allows your server to be used
  18487. * for amplification in DoS attacks against other hosts.
  18488. * Only disable if you known this can't happen in your
  18489. * particular environment.
  18490. *
  18491. * \note See comments on \c mbedtls_ssl_handshake() about handling
  18492. * the MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED that is expected
  18493. * on the first handshake attempt when this is enabled.
  18494. *
  18495. * \note This is also necessary to handle client reconnection from
  18496. * the same port as described in RFC 6347 section 4.2.8 (only
  18497. * the variant with cookies is supported currently). See
  18498. * comments on \c mbedtls_ssl_read() for details.
  18499. *
  18500. * \param conf SSL configuration
  18501. * \param f_cookie_write Cookie write callback
  18502. * \param f_cookie_check Cookie check callback
  18503. * \param p_cookie Context for both callbacks
  18504. */
  18505. void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf,
  18506. mbedtls_ssl_cookie_write_t *f_cookie_write,
  18507. mbedtls_ssl_cookie_check_t *f_cookie_check,
  18508. void *p_cookie );
  18509. /**
  18510. * \brief Set client's transport-level identification info.
  18511. * (Server only. DTLS only.)
  18512. *
  18513. * This is usually the IP address (and port), but could be
  18514. * anything identify the client depending on the underlying
  18515. * network stack. Used for HelloVerifyRequest with DTLS.
  18516. * This is *not* used to route the actual packets.
  18517. *
  18518. * \param ssl SSL context
  18519. * \param info Transport-level info identifying the client (eg IP + port)
  18520. * \param ilen Length of info in bytes
  18521. *
  18522. * \note An internal copy is made, so the info buffer can be reused.
  18523. *
  18524. * \return 0 on success,
  18525. * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used on client,
  18526. * MBEDTLS_ERR_SSL_ALLOC_FAILED if out of memory.
  18527. */
  18528. int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl,
  18529. const unsigned char *info,
  18530. size_t ilen );
  18531. #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
  18532. #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
  18533. /**
  18534. * \brief Enable or disable anti-replay protection for DTLS.
  18535. * (DTLS only, no effect on TLS.)
  18536. * Default: enabled.
  18537. *
  18538. * \param conf SSL configuration
  18539. * \param mode MBEDTLS_SSL_ANTI_REPLAY_ENABLED or MBEDTLS_SSL_ANTI_REPLAY_DISABLED.
  18540. *
  18541. * \warning Disabling this is a security risk unless the application
  18542. * protocol handles duplicated packets in a safe way. You
  18543. * should not disable this without careful consideration.
  18544. * However, if your application already detects duplicated
  18545. * packets and needs information about them to adjust its
  18546. * transmission strategy, then you'll want to disable this.
  18547. */
  18548. void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode );
  18549. #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
  18550. #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
  18551. /**
  18552. * \brief Set a limit on the number of records with a bad MAC
  18553. * before terminating the connection.
  18554. * (DTLS only, no effect on TLS.)
  18555. * Default: 0 (disabled).
  18556. *
  18557. * \param conf SSL configuration
  18558. * \param limit Limit, or 0 to disable.
  18559. *
  18560. * \note If the limit is N, then the connection is terminated when
  18561. * the Nth non-authentic record is seen.
  18562. *
  18563. * \note Records with an invalid header are not counted, only the
  18564. * ones going through the authentication-decryption phase.
  18565. *
  18566. * \note This is a security trade-off related to the fact that it's
  18567. * often relatively easy for an active attacker ot inject UDP
  18568. * datagrams. On one hand, setting a low limit here makes it
  18569. * easier for such an attacker to forcibly terminated a
  18570. * connection. On the other hand, a high limit or no limit
  18571. * might make us waste resources checking authentication on
  18572. * many bogus packets.
  18573. */
  18574. void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit );
  18575. #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
  18576. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  18577. /**
  18578. * \brief Set retransmit timeout values for the DTLS handshake.
  18579. * (DTLS only, no effect on TLS.)
  18580. *
  18581. * \param conf SSL configuration
  18582. * \param min Initial timeout value in milliseconds.
  18583. * Default: 1000 (1 second).
  18584. * \param max Maximum timeout value in milliseconds.
  18585. * Default: 60000 (60 seconds).
  18586. *
  18587. * \note Default values are from RFC 6347 section 4.2.4.1.
  18588. *
  18589. * \note The 'min' value should typically be slightly above the
  18590. * expected round-trip time to your peer, plus whatever time
  18591. * it takes for the peer to process the message. For example,
  18592. * if your RTT is about 600ms and you peer needs up to 1s to
  18593. * do the cryptographic operations in the handshake, then you
  18594. * should set 'min' slightly above 1600. Lower values of 'min'
  18595. * might cause spurious resends which waste network resources,
  18596. * while larger value of 'min' will increase overall latency
  18597. * on unreliable network links.
  18598. *
  18599. * \note The more unreliable your network connection is, the larger
  18600. * your max / min ratio needs to be in order to achieve
  18601. * reliable handshakes.
  18602. *
  18603. * \note Messages are retransmitted up to log2(ceil(max/min)) times.
  18604. * For example, if min = 1s and max = 5s, the retransmit plan
  18605. * goes: send ... 1s -> resend ... 2s -> resend ... 4s ->
  18606. * resend ... 5s -> give up and return a timeout error.
  18607. */
  18608. void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max );
  18609. #endif /* MBEDTLS_SSL_PROTO_DTLS */
  18610. #if defined(MBEDTLS_SSL_SRV_C)
  18611. /**
  18612. * \brief Set the session cache callbacks (server-side only)
  18613. * If not set, no session resuming is done (except if session
  18614. * tickets are enabled too).
  18615. *
  18616. * The session cache has the responsibility to check for stale
  18617. * entries based on timeout. See RFC 5246 for recommendations.
  18618. *
  18619. * Warning: session.peer_cert is cleared by the SSL/TLS layer on
  18620. * connection shutdown, so do not cache the pointer! Either set
  18621. * it to NULL or make a full copy of the certificate.
  18622. *
  18623. * The get callback is called once during the initial handshake
  18624. * to enable session resuming. The get function has the
  18625. * following parameters: (void *parameter, mbedtls_ssl_session *session)
  18626. * If a valid entry is found, it should fill the master of
  18627. * the session object with the cached values and return 0,
  18628. * return 1 otherwise. Optionally peer_cert can be set as well
  18629. * if it is properly present in cache entry.
  18630. *
  18631. * The set callback is called once during the initial handshake
  18632. * to enable session resuming after the entire handshake has
  18633. * been finished. The set function has the following parameters:
  18634. * (void *parameter, const mbedtls_ssl_session *session). The function
  18635. * should create a cache entry for future retrieval based on
  18636. * the data in the session structure and should keep in mind
  18637. * that the mbedtls_ssl_session object presented (and all its referenced
  18638. * data) is cleared by the SSL/TLS layer when the connection is
  18639. * terminated. It is recommended to add metadata to determine if
  18640. * an entry is still valid in the future. Return 0 if
  18641. * successfully cached, return 1 otherwise.
  18642. *
  18643. * \param conf SSL configuration
  18644. * \param p_cache parmater (context) for both callbacks
  18645. * \param f_get_cache session get callback
  18646. * \param f_set_cache session set callback
  18647. */
  18648. void mbedtls_ssl_conf_session_cache( mbedtls_ssl_config *conf,
  18649. void *p_cache,
  18650. int (*f_get_cache)(void *, mbedtls_ssl_session *),
  18651. int (*f_set_cache)(void *, const mbedtls_ssl_session *) );
  18652. #endif /* MBEDTLS_SSL_SRV_C */
  18653. #if defined(MBEDTLS_SSL_CLI_C)
  18654. /**
  18655. * \brief Request resumption of session (client-side only)
  18656. * Session data is copied from presented session structure.
  18657. *
  18658. * \param ssl SSL context
  18659. * \param session session context
  18660. *
  18661. * \return 0 if successful,
  18662. * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
  18663. * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
  18664. * arguments are otherwise invalid
  18665. *
  18666. * \sa mbedtls_ssl_get_session()
  18667. */
  18668. int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session );
  18669. #endif /* MBEDTLS_SSL_CLI_C */
  18670. /**
  18671. * \brief Set the list of allowed ciphersuites and the preference
  18672. * order. First in the list has the highest preference.
  18673. * (Overrides all version-specific lists)
  18674. *
  18675. * The ciphersuites array is not copied, and must remain
  18676. * valid for the lifetime of the ssl_config.
  18677. *
  18678. * Note: The server uses its own preferences
  18679. * over the preference of the client unless
  18680. * MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE is defined!
  18681. *
  18682. * \param conf SSL configuration
  18683. * \param ciphersuites 0-terminated list of allowed ciphersuites
  18684. */
  18685. void mbedtls_ssl_conf_ciphersuites( mbedtls_ssl_config *conf,
  18686. const int *ciphersuites );
  18687. /**
  18688. * \brief Set the list of allowed ciphersuites and the
  18689. * preference order for a specific version of the protocol.
  18690. * (Only useful on the server side)
  18691. *
  18692. * The ciphersuites array is not copied, and must remain
  18693. * valid for the lifetime of the ssl_config.
  18694. *
  18695. * \param conf SSL configuration
  18696. * \param ciphersuites 0-terminated list of allowed ciphersuites
  18697. * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3
  18698. * supported)
  18699. * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
  18700. * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
  18701. * MBEDTLS_SSL_MINOR_VERSION_3 supported)
  18702. *
  18703. * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0
  18704. * and MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
  18705. */
  18706. void mbedtls_ssl_conf_ciphersuites_for_version( mbedtls_ssl_config *conf,
  18707. const int *ciphersuites,
  18708. int major, int minor );
  18709. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  18710. /**
  18711. * \brief Set the X.509 security profile used for verification
  18712. *
  18713. * \note The restrictions are enforced for all certificates in the
  18714. * chain. However, signatures in the handshake are not covered
  18715. * by this setting but by \b mbedtls_ssl_conf_sig_hashes().
  18716. *
  18717. * \param conf SSL configuration
  18718. * \param profile Profile to use
  18719. */
  18720. void mbedtls_ssl_conf_cert_profile( mbedtls_ssl_config *conf,
  18721. const mbedtls_x509_crt_profile *profile );
  18722. /**
  18723. * \brief Set the data required to verify peer certificate
  18724. *
  18725. * \param conf SSL configuration
  18726. * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
  18727. * \param ca_crl trusted CA CRLs
  18728. */
  18729. void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf,
  18730. mbedtls_x509_crt *ca_chain,
  18731. mbedtls_x509_crl *ca_crl );
  18732. /**
  18733. * \brief Set own certificate chain and private key
  18734. *
  18735. * \note own_cert should contain in order from the bottom up your
  18736. * certificate chain. The top certificate (self-signed)
  18737. * can be omitted.
  18738. *
  18739. * \note On server, this function can be called multiple times to
  18740. * provision more than one cert/key pair (eg one ECDSA, one
  18741. * RSA with SHA-256, one RSA with SHA-1). An adequate
  18742. * certificate will be selected according to the client's
  18743. * advertised capabilities. In case mutliple certificates are
  18744. * adequate, preference is given to the one set by the first
  18745. * call to this function, then second, etc.
  18746. *
  18747. * \note On client, only the first call has any effect. That is,
  18748. * only one client certificate can be provisioned. The
  18749. * server's preferences in its CertficateRequest message will
  18750. * be ignored and our only cert will be sent regardless of
  18751. * whether it matches those preferences - the server can then
  18752. * decide what it wants to do with it.
  18753. *
  18754. * \param conf SSL configuration
  18755. * \param own_cert own public certificate chain
  18756. * \param pk_key own private key
  18757. *
  18758. * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
  18759. */
  18760. int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *conf,
  18761. mbedtls_x509_crt *own_cert,
  18762. mbedtls_pk_context *pk_key );
  18763. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  18764. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
  18765. /**
  18766. * \brief Set the Pre Shared Key (PSK) and the expected identity name
  18767. *
  18768. * \note This is mainly useful for clients. Servers will usually
  18769. * want to use \c mbedtls_ssl_conf_psk_cb() instead.
  18770. *
  18771. * \note Currently clients can only register one pre-shared key.
  18772. * In other words, the servers' identity hint is ignored.
  18773. * Support for setting multiple PSKs on clients and selecting
  18774. * one based on the identity hint is not a planned feature but
  18775. * feedback is welcomed.
  18776. *
  18777. * \param conf SSL configuration
  18778. * \param psk pointer to the pre-shared key
  18779. * \param psk_len pre-shared key length
  18780. * \param psk_identity pointer to the pre-shared key identity
  18781. * \param psk_identity_len identity key length
  18782. *
  18783. * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED
  18784. */
  18785. int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
  18786. const unsigned char *psk, size_t psk_len,
  18787. const unsigned char *psk_identity, size_t psk_identity_len );
  18788. /**
  18789. * \brief Set the Pre Shared Key (PSK) for the current handshake
  18790. *
  18791. * \note This should only be called inside the PSK callback,
  18792. * ie the function passed to \c mbedtls_ssl_conf_psk_cb().
  18793. *
  18794. * \param ssl SSL context
  18795. * \param psk pointer to the pre-shared key
  18796. * \param psk_len pre-shared key length
  18797. *
  18798. * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED
  18799. */
  18800. int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
  18801. const unsigned char *psk, size_t psk_len );
  18802. /**
  18803. * \brief Set the PSK callback (server-side only).
  18804. *
  18805. * If set, the PSK callback is called for each
  18806. * handshake where a PSK ciphersuite was negotiated.
  18807. * The caller provides the identity received and wants to
  18808. * receive the actual PSK data and length.
  18809. *
  18810. * The callback has the following parameters: (void *parameter,
  18811. * mbedtls_ssl_context *ssl, const unsigned char *psk_identity,
  18812. * size_t identity_len)
  18813. * If a valid PSK identity is found, the callback should use
  18814. * \c mbedtls_ssl_set_hs_psk() on the ssl context to set the
  18815. * correct PSK and return 0.
  18816. * Any other return value will result in a denied PSK identity.
  18817. *
  18818. * \note If you set a PSK callback using this function, then you
  18819. * don't need to set a PSK key and identity using
  18820. * \c mbedtls_ssl_conf_psk().
  18821. *
  18822. * \param conf SSL configuration
  18823. * \param f_psk PSK identity function
  18824. * \param p_psk PSK identity parameter
  18825. */
  18826. void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf,
  18827. int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
  18828. size_t),
  18829. void *p_psk );
  18830. #endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
  18831. #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
  18832. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  18833. #if defined(MBEDTLS_DEPRECATED_WARNING)
  18834. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  18835. #else
  18836. #define MBEDTLS_DEPRECATED
  18837. #endif
  18838. /**
  18839. * \brief Set the Diffie-Hellman public P and G values,
  18840. * read as hexadecimal strings (server-side only)
  18841. * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG])
  18842. *
  18843. * \param conf SSL configuration
  18844. * \param dhm_P Diffie-Hellman-Merkle modulus
  18845. * \param dhm_G Diffie-Hellman-Merkle generator
  18846. *
  18847. * \deprecated Superseded by \c mbedtls_ssl_conf_dh_param_bin.
  18848. *
  18849. * \return 0 if successful
  18850. */
  18851. MBEDTLS_DEPRECATED int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf,
  18852. const char *dhm_P,
  18853. const char *dhm_G );
  18854. #endif /* MBEDTLS_DEPRECATED_REMOVED */
  18855. /**
  18856. * \brief Set the Diffie-Hellman public P and G values
  18857. * from big-endian binary presentations.
  18858. * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG]_BIN)
  18859. *
  18860. * \param conf SSL configuration
  18861. * \param dhm_P Diffie-Hellman-Merkle modulus in big-endian binary form
  18862. * \param P_len Length of DHM modulus
  18863. * \param dhm_G Diffie-Hellman-Merkle generator in big-endian binary form
  18864. * \param G_len Length of DHM generator
  18865. *
  18866. * \return 0 if successful
  18867. */
  18868. int mbedtls_ssl_conf_dh_param_bin( mbedtls_ssl_config *conf,
  18869. const unsigned char *dhm_P, size_t P_len,
  18870. const unsigned char *dhm_G, size_t G_len );
  18871. /**
  18872. * \brief Set the Diffie-Hellman public P and G values,
  18873. * read from existing context (server-side only)
  18874. *
  18875. * \param conf SSL configuration
  18876. * \param dhm_ctx Diffie-Hellman-Merkle context
  18877. *
  18878. * \return 0 if successful
  18879. */
  18880. int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx );
  18881. #endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
  18882. #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
  18883. /**
  18884. * \brief Set the minimum length for Diffie-Hellman parameters.
  18885. * (Client-side only.)
  18886. * (Default: 1024 bits.)
  18887. *
  18888. * \param conf SSL configuration
  18889. * \param bitlen Minimum bit length of the DHM prime
  18890. */
  18891. void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,
  18892. unsigned int bitlen );
  18893. #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
  18894. #if defined(MBEDTLS_ECP_C)
  18895. /**
  18896. * \brief Set the allowed curves in order of preference.
  18897. * (Default: all defined curves.)
  18898. *
  18899. * On server: this only affects selection of the ECDHE curve;
  18900. * the curves used for ECDH and ECDSA are determined by the
  18901. * list of available certificates instead.
  18902. *
  18903. * On client: this affects the list of curves offered for any
  18904. * use. The server can override our preference order.
  18905. *
  18906. * Both sides: limits the set of curves accepted for use in
  18907. * ECDHE and in the peer's end-entity certificate.
  18908. *
  18909. * \note This has no influence on which curves are allowed inside the
  18910. * certificate chains, see \c mbedtls_ssl_conf_cert_profile()
  18911. * for that. For the end-entity certificate however, the key
  18912. * will be accepted only if it is allowed both by this list
  18913. * and by the cert profile.
  18914. *
  18915. * \note This list should be ordered by decreasing preference
  18916. * (preferred curve first).
  18917. *
  18918. * \param conf SSL configuration
  18919. * \param curves Ordered list of allowed curves,
  18920. * terminated by MBEDTLS_ECP_DP_NONE.
  18921. */
  18922. void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf,
  18923. const mbedtls_ecp_group_id *curves );
  18924. #endif /* MBEDTLS_ECP_C */
  18925. #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
  18926. /**
  18927. * \brief Set the allowed hashes for signatures during the handshake.
  18928. * (Default: all available hashes except MD5.)
  18929. *
  18930. * \note This only affects which hashes are offered and can be used
  18931. * for signatures during the handshake. Hashes for message
  18932. * authentication and the TLS PRF are controlled by the
  18933. * ciphersuite, see \c mbedtls_ssl_conf_ciphersuites(). Hashes
  18934. * used for certificate signature are controlled by the
  18935. * verification profile, see \c mbedtls_ssl_conf_cert_profile().
  18936. *
  18937. * \note This list should be ordered by decreasing preference
  18938. * (preferred hash first).
  18939. *
  18940. * \param conf SSL configuration
  18941. * \param hashes Ordered list of allowed signature hashes,
  18942. * terminated by \c MBEDTLS_MD_NONE.
  18943. */
  18944. void mbedtls_ssl_conf_sig_hashes( mbedtls_ssl_config *conf,
  18945. const int *hashes );
  18946. #endif /* MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */
  18947. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  18948. /**
  18949. * \brief Set or reset the hostname to check against the received
  18950. * server certificate. It sets the ServerName TLS extension,
  18951. * too, if that extension is enabled. (client-side only)
  18952. *
  18953. * \param ssl SSL context
  18954. * \param hostname the server hostname, may be NULL to clear hostname
  18955. * \note Maximum hostname length MBEDTLS_SSL_MAX_HOST_NAME_LEN.
  18956. *
  18957. * \return 0 if successful, MBEDTLS_ERR_SSL_ALLOC_FAILED on
  18958. * allocation failure, MBEDTLS_ERR_SSL_BAD_INPUT_DATA on
  18959. * too long input hostname.
  18960. *
  18961. * Hostname set to the one provided on success (cleared
  18962. * when NULL). On allocation failure hostname is cleared.
  18963. * On too long input failure, old hostname is unchanged.
  18964. */
  18965. int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname );
  18966. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  18967. #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
  18968. /**
  18969. * \brief Set own certificate and key for the current handshake
  18970. *
  18971. * \note Same as \c mbedtls_ssl_conf_own_cert() but for use within
  18972. * the SNI callback.
  18973. *
  18974. * \param ssl SSL context
  18975. * \param own_cert own public certificate chain
  18976. * \param pk_key own private key
  18977. *
  18978. * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
  18979. */
  18980. int mbedtls_ssl_set_hs_own_cert( mbedtls_ssl_context *ssl,
  18981. mbedtls_x509_crt *own_cert,
  18982. mbedtls_pk_context *pk_key );
  18983. /**
  18984. * \brief Set the data required to verify peer certificate for the
  18985. * current handshake
  18986. *
  18987. * \note Same as \c mbedtls_ssl_conf_ca_chain() but for use within
  18988. * the SNI callback.
  18989. *
  18990. * \param ssl SSL context
  18991. * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
  18992. * \param ca_crl trusted CA CRLs
  18993. */
  18994. void mbedtls_ssl_set_hs_ca_chain( mbedtls_ssl_context *ssl,
  18995. mbedtls_x509_crt *ca_chain,
  18996. mbedtls_x509_crl *ca_crl );
  18997. /**
  18998. * \brief Set authmode for the current handshake.
  18999. *
  19000. * \note Same as \c mbedtls_ssl_conf_authmode() but for use within
  19001. * the SNI callback.
  19002. *
  19003. * \param ssl SSL context
  19004. * \param authmode MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL or
  19005. * MBEDTLS_SSL_VERIFY_REQUIRED
  19006. */
  19007. void mbedtls_ssl_set_hs_authmode( mbedtls_ssl_context *ssl,
  19008. int authmode );
  19009. /**
  19010. * \brief Set server side ServerName TLS extension callback
  19011. * (optional, server-side only).
  19012. *
  19013. * If set, the ServerName callback is called whenever the
  19014. * server receives a ServerName TLS extension from the client
  19015. * during a handshake. The ServerName callback has the
  19016. * following parameters: (void *parameter, mbedtls_ssl_context *ssl,
  19017. * const unsigned char *hostname, size_t len). If a suitable
  19018. * certificate is found, the callback must set the
  19019. * certificate(s) and key(s) to use with \c
  19020. * mbedtls_ssl_set_hs_own_cert() (can be called repeatedly),
  19021. * and may optionally adjust the CA and associated CRL with \c
  19022. * mbedtls_ssl_set_hs_ca_chain() as well as the client
  19023. * authentication mode with \c mbedtls_ssl_set_hs_authmode(),
  19024. * then must return 0. If no matching name is found, the
  19025. * callback must either set a default cert, or
  19026. * return non-zero to abort the handshake at this point.
  19027. *
  19028. * \param conf SSL configuration
  19029. * \param f_sni verification function
  19030. * \param p_sni verification parameter
  19031. */
  19032. void mbedtls_ssl_conf_sni( mbedtls_ssl_config *conf,
  19033. int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
  19034. size_t),
  19035. void *p_sni );
  19036. #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
  19037. #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
  19038. /**
  19039. * \brief Set the EC J-PAKE password for current handshake.
  19040. *
  19041. * \note An internal copy is made, and destroyed as soon as the
  19042. * handshake is completed, or when the SSL context is reset or
  19043. * freed.
  19044. *
  19045. * \note The SSL context needs to be already set up. The right place
  19046. * to call this function is between \c mbedtls_ssl_setup() or
  19047. * \c mbedtls_ssl_reset() and \c mbedtls_ssl_handshake().
  19048. *
  19049. * \param ssl SSL context
  19050. * \param pw EC J-PAKE password (pre-shared secret)
  19051. * \param pw_len length of pw in bytes
  19052. *
  19053. * \return 0 on success, or a negative error code.
  19054. */
  19055. int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl,
  19056. const unsigned char *pw,
  19057. size_t pw_len );
  19058. #endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
  19059. #if defined(MBEDTLS_SSL_ALPN)
  19060. /**
  19061. * \brief Set the supported Application Layer Protocols.
  19062. *
  19063. * \param conf SSL configuration
  19064. * \param protos Pointer to a NULL-terminated list of supported protocols,
  19065. * in decreasing preference order. The pointer to the list is
  19066. * recorded by the library for later reference as required, so
  19067. * the lifetime of the table must be atleast as long as the
  19068. * lifetime of the SSL configuration structure.
  19069. *
  19070. * \return 0 on success, or MBEDTLS_ERR_SSL_BAD_INPUT_DATA.
  19071. */
  19072. int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos );
  19073. /**
  19074. * \brief Get the name of the negotiated Application Layer Protocol.
  19075. * This function should be called after the handshake is
  19076. * completed.
  19077. *
  19078. * \param ssl SSL context
  19079. *
  19080. * \return Protcol name, or NULL if no protocol was negotiated.
  19081. */
  19082. const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl );
  19083. #endif /* MBEDTLS_SSL_ALPN */
  19084. /**
  19085. * \brief Set the maximum supported version sent from the client side
  19086. * and/or accepted at the server side
  19087. * (Default: MBEDTLS_SSL_MAX_MAJOR_VERSION, MBEDTLS_SSL_MAX_MINOR_VERSION)
  19088. *
  19089. * \note This ignores ciphersuites from higher versions.
  19090. *
  19091. * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
  19092. * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
  19093. *
  19094. * \param conf SSL configuration
  19095. * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
  19096. * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
  19097. * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
  19098. * MBEDTLS_SSL_MINOR_VERSION_3 supported)
  19099. */
  19100. void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
  19101. /**
  19102. * \brief Set the minimum accepted SSL/TLS protocol version
  19103. * (Default: TLS 1.0)
  19104. *
  19105. * \note Input outside of the SSL_MAX_XXXXX_VERSION and
  19106. * SSL_MIN_XXXXX_VERSION range is ignored.
  19107. *
  19108. * \note MBEDTLS_SSL_MINOR_VERSION_0 (SSL v3) should be avoided.
  19109. *
  19110. * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
  19111. * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
  19112. *
  19113. * \param conf SSL configuration
  19114. * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
  19115. * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
  19116. * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
  19117. * MBEDTLS_SSL_MINOR_VERSION_3 supported)
  19118. */
  19119. void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
  19120. #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
  19121. /**
  19122. * \brief Set the fallback flag (client-side only).
  19123. * (Default: MBEDTLS_SSL_IS_NOT_FALLBACK).
  19124. *
  19125. * \note Set to MBEDTLS_SSL_IS_FALLBACK when preparing a fallback
  19126. * connection, that is a connection with max_version set to a
  19127. * lower value than the value you're willing to use. Such
  19128. * fallback connections are not recommended but are sometimes
  19129. * necessary to interoperate with buggy (version-intolerant)
  19130. * servers.
  19131. *
  19132. * \warning You should NOT set this to MBEDTLS_SSL_IS_FALLBACK for
  19133. * non-fallback connections! This would appear to work for a
  19134. * while, then cause failures when the server is upgraded to
  19135. * support a newer TLS version.
  19136. *
  19137. * \param conf SSL configuration
  19138. * \param fallback MBEDTLS_SSL_IS_NOT_FALLBACK or MBEDTLS_SSL_IS_FALLBACK
  19139. */
  19140. void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback );
  19141. #endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */
  19142. #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  19143. /**
  19144. * \brief Enable or disable Encrypt-then-MAC
  19145. * (Default: MBEDTLS_SSL_ETM_ENABLED)
  19146. *
  19147. * \note This should always be enabled, it is a security
  19148. * improvement, and should not cause any interoperability
  19149. * issue (used only if the peer supports it too).
  19150. *
  19151. * \param conf SSL configuration
  19152. * \param etm MBEDTLS_SSL_ETM_ENABLED or MBEDTLS_SSL_ETM_DISABLED
  19153. */
  19154. void mbedtls_ssl_conf_encrypt_then_mac( mbedtls_ssl_config *conf, char etm );
  19155. #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
  19156. #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
  19157. /**
  19158. * \brief Enable or disable Extended Master Secret negotiation.
  19159. * (Default: MBEDTLS_SSL_EXTENDED_MS_ENABLED)
  19160. *
  19161. * \note This should always be enabled, it is a security fix to the
  19162. * protocol, and should not cause any interoperability issue
  19163. * (used only if the peer supports it too).
  19164. *
  19165. * \param conf SSL configuration
  19166. * \param ems MBEDTLS_SSL_EXTENDED_MS_ENABLED or MBEDTLS_SSL_EXTENDED_MS_DISABLED
  19167. */
  19168. void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems );
  19169. #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
  19170. #if defined(MBEDTLS_ARC4_C)
  19171. /**
  19172. * \brief Disable or enable support for RC4
  19173. * (Default: MBEDTLS_SSL_ARC4_DISABLED)
  19174. *
  19175. * \warning Use of RC4 in DTLS/TLS has been prohibited by RFC 7465
  19176. * for security reasons. Use at your own risk.
  19177. *
  19178. * \note This function is deprecated and will likely be removed in
  19179. * a future version of the library.
  19180. * RC4 is disabled by default at compile time and needs to be
  19181. * actively enabled for use with legacy systems.
  19182. *
  19183. * \param conf SSL configuration
  19184. * \param arc4 MBEDTLS_SSL_ARC4_ENABLED or MBEDTLS_SSL_ARC4_DISABLED
  19185. */
  19186. void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
  19187. #endif /* MBEDTLS_ARC4_C */
  19188. #if defined(MBEDTLS_SSL_SRV_C)
  19189. /**
  19190. * \brief Whether to send a list of acceptable CAs in
  19191. * CertificateRequest messages.
  19192. * (Default: do send)
  19193. *
  19194. * \param conf SSL configuration
  19195. * \param cert_req_ca_list MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED or
  19196. * MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED
  19197. */
  19198. void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf,
  19199. char cert_req_ca_list );
  19200. #endif /* MBEDTLS_SSL_SRV_C */
  19201. #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
  19202. /**
  19203. * \brief Set the maximum fragment length to emit and/or negotiate
  19204. * (Default: MBEDTLS_SSL_MAX_CONTENT_LEN, usually 2^14 bytes)
  19205. * (Server: set maximum fragment length to emit,
  19206. * usually negotiated by the client during handshake
  19207. * (Client: set maximum fragment length to emit *and*
  19208. * negotiate with the server during handshake)
  19209. *
  19210. * \param conf SSL configuration
  19211. * \param mfl_code Code for maximum fragment length (allowed values:
  19212. * MBEDTLS_SSL_MAX_FRAG_LEN_512, MBEDTLS_SSL_MAX_FRAG_LEN_1024,
  19213. * MBEDTLS_SSL_MAX_FRAG_LEN_2048, MBEDTLS_SSL_MAX_FRAG_LEN_4096)
  19214. *
  19215. * \return 0 if successful or MBEDTLS_ERR_SSL_BAD_INPUT_DATA
  19216. */
  19217. int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code );
  19218. #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
  19219. #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
  19220. /**
  19221. * \brief Activate negotiation of truncated HMAC
  19222. * (Default: MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
  19223. *
  19224. * \param conf SSL configuration
  19225. * \param truncate Enable or disable (MBEDTLS_SSL_TRUNC_HMAC_ENABLED or
  19226. * MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
  19227. */
  19228. void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
  19229. #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
  19230. #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
  19231. /**
  19232. * \brief Enable / Disable 1/n-1 record splitting
  19233. * (Default: MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED)
  19234. *
  19235. * \note Only affects SSLv3 and TLS 1.0, not higher versions.
  19236. * Does not affect non-CBC ciphersuites in any version.
  19237. *
  19238. * \param conf SSL configuration
  19239. * \param split MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED or
  19240. * MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED
  19241. */
  19242. void mbedtls_ssl_conf_cbc_record_splitting( mbedtls_ssl_config *conf, char split );
  19243. #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
  19244. #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
  19245. /**
  19246. * \brief Enable / Disable session tickets (client only).
  19247. * (Default: MBEDTLS_SSL_SESSION_TICKETS_ENABLED.)
  19248. *
  19249. * \note On server, use \c mbedtls_ssl_conf_session_tickets_cb().
  19250. *
  19251. * \param conf SSL configuration
  19252. * \param use_tickets Enable or disable (MBEDTLS_SSL_SESSION_TICKETS_ENABLED or
  19253. * MBEDTLS_SSL_SESSION_TICKETS_DISABLED)
  19254. */
  19255. void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets );
  19256. #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
  19257. #if defined(MBEDTLS_SSL_RENEGOTIATION)
  19258. /**
  19259. * \brief Enable / Disable renegotiation support for connection when
  19260. * initiated by peer
  19261. * (Default: MBEDTLS_SSL_RENEGOTIATION_DISABLED)
  19262. *
  19263. * \warning It is recommended to always disable renegotation unless you
  19264. * know you need it and you know what you're doing. In the
  19265. * past, there have been several issues associated with
  19266. * renegotiation or a poor understanding of its properties.
  19267. *
  19268. * \note Server-side, enabling renegotiation also makes the server
  19269. * susceptible to a resource DoS by a malicious client.
  19270. *
  19271. * \param conf SSL configuration
  19272. * \param renegotiation Enable or disable (MBEDTLS_SSL_RENEGOTIATION_ENABLED or
  19273. * MBEDTLS_SSL_RENEGOTIATION_DISABLED)
  19274. */
  19275. void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation );
  19276. #endif /* MBEDTLS_SSL_RENEGOTIATION */
  19277. /**
  19278. * \brief Prevent or allow legacy renegotiation.
  19279. * (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION)
  19280. *
  19281. * MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION allows connections to
  19282. * be established even if the peer does not support
  19283. * secure renegotiation, but does not allow renegotiation
  19284. * to take place if not secure.
  19285. * (Interoperable and secure option)
  19286. *
  19287. * MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION allows renegotiations
  19288. * with non-upgraded peers. Allowing legacy renegotiation
  19289. * makes the connection vulnerable to specific man in the
  19290. * middle attacks. (See RFC 5746)
  19291. * (Most interoperable and least secure option)
  19292. *
  19293. * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE breaks off connections
  19294. * if peer does not support secure renegotiation. Results
  19295. * in interoperability issues with non-upgraded peers
  19296. * that do not support renegotiation altogether.
  19297. * (Most secure option, interoperability issues)
  19298. *
  19299. * \param conf SSL configuration
  19300. * \param allow_legacy Prevent or allow (SSL_NO_LEGACY_RENEGOTIATION,
  19301. * SSL_ALLOW_LEGACY_RENEGOTIATION or
  19302. * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE)
  19303. */
  19304. void mbedtls_ssl_conf_legacy_renegotiation( mbedtls_ssl_config *conf, int allow_legacy );
  19305. #if defined(MBEDTLS_SSL_RENEGOTIATION)
  19306. /**
  19307. * \brief Enforce renegotiation requests.
  19308. * (Default: enforced, max_records = 16)
  19309. *
  19310. * When we request a renegotiation, the peer can comply or
  19311. * ignore the request. This function allows us to decide
  19312. * whether to enforce our renegotiation requests by closing
  19313. * the connection if the peer doesn't comply.
  19314. *
  19315. * However, records could already be in transit from the peer
  19316. * when the request is emitted. In order to increase
  19317. * reliability, we can accept a number of records before the
  19318. * expected handshake records.
  19319. *
  19320. * The optimal value is highly dependent on the specific usage
  19321. * scenario.
  19322. *
  19323. * \note With DTLS and server-initiated renegotiation, the
  19324. * HelloRequest is retransmited every time mbedtls_ssl_read() times
  19325. * out or receives Application Data, until:
  19326. * - max_records records have beens seen, if it is >= 0, or
  19327. * - the number of retransmits that would happen during an
  19328. * actual handshake has been reached.
  19329. * Please remember the request might be lost a few times
  19330. * if you consider setting max_records to a really low value.
  19331. *
  19332. * \warning On client, the grace period can only happen during
  19333. * mbedtls_ssl_read(), as opposed to mbedtls_ssl_write() and mbedtls_ssl_renegotiate()
  19334. * which always behave as if max_record was 0. The reason is,
  19335. * if we receive application data from the server, we need a
  19336. * place to write it, which only happens during mbedtls_ssl_read().
  19337. *
  19338. * \param conf SSL configuration
  19339. * \param max_records Use MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED if you don't want to
  19340. * enforce renegotiation, or a non-negative value to enforce
  19341. * it but allow for a grace period of max_records records.
  19342. */
  19343. void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records );
  19344. /**
  19345. * \brief Set record counter threshold for periodic renegotiation.
  19346. * (Default: 2^48 - 1)
  19347. *
  19348. * Renegotiation is automatically triggered when a record
  19349. * counter (outgoing or ingoing) crosses the defined
  19350. * threshold. The default value is meant to prevent the
  19351. * connection from being closed when the counter is about to
  19352. * reached its maximal value (it is not allowed to wrap).
  19353. *
  19354. * Lower values can be used to enforce policies such as "keys
  19355. * must be refreshed every N packets with cipher X".
  19356. *
  19357. * The renegotiation period can be disabled by setting
  19358. * conf->disable_renegotiation to
  19359. * MBEDTLS_SSL_RENEGOTIATION_DISABLED.
  19360. *
  19361. * \note When the configured transport is
  19362. * MBEDTLS_SSL_TRANSPORT_DATAGRAM the maximum renegotiation
  19363. * period is 2^48 - 1, and for MBEDTLS_SSL_TRANSPORT_STREAM,
  19364. * the maximum renegotiation period is 2^64 - 1.
  19365. *
  19366. * \param conf SSL configuration
  19367. * \param period The threshold value: a big-endian 64-bit number.
  19368. */
  19369. void mbedtls_ssl_conf_renegotiation_period( mbedtls_ssl_config *conf,
  19370. const unsigned char period[8] );
  19371. #endif /* MBEDTLS_SSL_RENEGOTIATION */
  19372. /**
  19373. * \brief Return the number of data bytes available to read
  19374. *
  19375. * \param ssl SSL context
  19376. *
  19377. * \return how many bytes are available in the read buffer
  19378. */
  19379. size_t mbedtls_ssl_get_bytes_avail( const mbedtls_ssl_context *ssl );
  19380. /**
  19381. * \brief Return the result of the certificate verification
  19382. *
  19383. * \param ssl SSL context
  19384. *
  19385. * \return 0 if successful,
  19386. * -1 if result is not available (eg because the handshake was
  19387. * aborted too early), or
  19388. * a combination of BADCERT_xxx and BADCRL_xxx flags, see
  19389. * x509.h
  19390. */
  19391. uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl );
  19392. /**
  19393. * \brief Return the name of the current ciphersuite
  19394. *
  19395. * \param ssl SSL context
  19396. *
  19397. * \return a string containing the ciphersuite name
  19398. */
  19399. const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl );
  19400. /**
  19401. * \brief Return the current SSL version (SSLv3/TLSv1/etc)
  19402. *
  19403. * \param ssl SSL context
  19404. *
  19405. * \return a string containing the SSL version
  19406. */
  19407. const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
  19408. /**
  19409. * \brief Return the (maximum) number of bytes added by the record
  19410. * layer: header + encryption/MAC overhead (inc. padding)
  19411. *
  19412. * \param ssl SSL context
  19413. *
  19414. * \return Current maximum record expansion in bytes, or
  19415. * MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE if compression is
  19416. * enabled, which makes expansion much less predictable
  19417. */
  19418. int mbedtls_ssl_get_record_expansion( const mbedtls_ssl_context *ssl );
  19419. #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
  19420. /**
  19421. * \brief Return the maximum fragment length (payload, in bytes).
  19422. * This is the value negotiated with peer if any,
  19423. * or the locally configured value.
  19424. *
  19425. * \note With DTLS, \c mbedtls_ssl_write() will return an error if
  19426. * called with a larger length value.
  19427. * With TLS, \c mbedtls_ssl_write() will fragment the input if
  19428. * necessary and return the number of bytes written; it is up
  19429. * to the caller to call \c mbedtls_ssl_write() again in
  19430. * order to send the remaining bytes if any.
  19431. *
  19432. * \param ssl SSL context
  19433. *
  19434. * \return Current maximum fragment length.
  19435. */
  19436. size_t mbedtls_ssl_get_max_frag_len( const mbedtls_ssl_context *ssl );
  19437. #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
  19438. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  19439. /**
  19440. * \brief Return the peer certificate from the current connection
  19441. *
  19442. * Note: Can be NULL in case no certificate was sent during
  19443. * the handshake. Different calls for the same connection can
  19444. * return the same or different pointers for the same
  19445. * certificate and even a different certificate altogether.
  19446. * The peer cert CAN change in a single connection if
  19447. * renegotiation is performed.
  19448. *
  19449. * \param ssl SSL context
  19450. *
  19451. * \return the current peer certificate
  19452. */
  19453. const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl );
  19454. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  19455. #if defined(MBEDTLS_SSL_CLI_C)
  19456. /**
  19457. * \brief Save session in order to resume it later (client-side only)
  19458. * Session data is copied to presented session structure.
  19459. *
  19460. * \warning Currently, peer certificate is lost in the operation.
  19461. *
  19462. * \param ssl SSL context
  19463. * \param session session context
  19464. *
  19465. * \return 0 if successful,
  19466. * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
  19467. * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
  19468. * arguments are otherwise invalid
  19469. *
  19470. * \sa mbedtls_ssl_set_session()
  19471. */
  19472. int mbedtls_ssl_get_session( const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session );
  19473. #endif /* MBEDTLS_SSL_CLI_C */
  19474. /**
  19475. * \brief Perform the SSL handshake
  19476. *
  19477. * \param ssl SSL context
  19478. *
  19479. * \return 0 if successful, or
  19480. * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
  19481. * MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED (see below), or
  19482. * a specific SSL error code.
  19483. *
  19484. * \note If this function returns something other than 0 or
  19485. * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
  19486. * becomes unusable, and you should either free it or call
  19487. * \c mbedtls_ssl_session_reset() on it before re-using it for
  19488. * a new connection; the current connection must be closed.
  19489. *
  19490. * \note If DTLS is in use, then you may choose to handle
  19491. * MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED specially for logging
  19492. * purposes, as it is an expected return value rather than an
  19493. * actual error, but you still need to reset/free the context.
  19494. */
  19495. int mbedtls_ssl_handshake( mbedtls_ssl_context *ssl );
  19496. /**
  19497. * \brief Perform a single step of the SSL handshake
  19498. *
  19499. * \note The state of the context (ssl->state) will be at
  19500. * the next state after execution of this function. Do not
  19501. * call this function if state is MBEDTLS_SSL_HANDSHAKE_OVER.
  19502. *
  19503. * \note If this function returns something other than 0 or
  19504. * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
  19505. * becomes unusable, and you should either free it or call
  19506. * \c mbedtls_ssl_session_reset() on it before re-using it for
  19507. * a new connection; the current connection must be closed.
  19508. *
  19509. * \param ssl SSL context
  19510. *
  19511. * \return 0 if successful, or
  19512. * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
  19513. * a specific SSL error code.
  19514. */
  19515. int mbedtls_ssl_handshake_step( mbedtls_ssl_context *ssl );
  19516. #if defined(MBEDTLS_SSL_RENEGOTIATION)
  19517. /**
  19518. * \brief Initiate an SSL renegotiation on the running connection.
  19519. * Client: perform the renegotiation right now.
  19520. * Server: request renegotiation, which will be performed
  19521. * during the next call to mbedtls_ssl_read() if honored by
  19522. * client.
  19523. *
  19524. * \param ssl SSL context
  19525. *
  19526. * \return 0 if successful, or any mbedtls_ssl_handshake() return
  19527. * value.
  19528. *
  19529. * \note If this function returns something other than 0 or
  19530. * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
  19531. * becomes unusable, and you should either free it or call
  19532. * \c mbedtls_ssl_session_reset() on it before re-using it for
  19533. * a new connection; the current connection must be closed.
  19534. */
  19535. int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl );
  19536. #endif /* MBEDTLS_SSL_RENEGOTIATION */
  19537. /**
  19538. * \brief Read at most 'len' application data bytes
  19539. *
  19540. * \param ssl SSL context
  19541. * \param buf buffer that will hold the data
  19542. * \param len maximum number of bytes to read
  19543. *
  19544. * \return the number of bytes read, or
  19545. * 0 for EOF, or
  19546. * MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE, or
  19547. * MBEDTLS_ERR_SSL_CLIENT_RECONNECT (see below), or
  19548. * another negative error code.
  19549. *
  19550. * \note If this function returns something other than a positive
  19551. * value or MBEDTLS_ERR_SSL_WANT_READ/WRITE or
  19552. * MBEDTLS_ERR_SSL_CLIENT_RECONNECT, then the ssl context
  19553. * becomes unusable, and you should either free it or call
  19554. * \c mbedtls_ssl_session_reset() on it before re-using it for
  19555. * a new connection; the current connection must be closed.
  19556. *
  19557. * \note When this function return MBEDTLS_ERR_SSL_CLIENT_RECONNECT
  19558. * (which can only happen server-side), it means that a client
  19559. * is initiating a new connection using the same source port.
  19560. * You can either treat that as a connection close and wait
  19561. * for the client to resend a ClientHello, or directly
  19562. * continue with \c mbedtls_ssl_handshake() with the same
  19563. * context (as it has beeen reset internally). Either way, you
  19564. * should make sure this is seen by the application as a new
  19565. * connection: application state, if any, should be reset, and
  19566. * most importantly the identity of the client must be checked
  19567. * again. WARNING: not validating the identity of the client
  19568. * again, or not transmitting the new identity to the
  19569. * application layer, would allow authentication bypass!
  19570. */
  19571. int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len );
  19572. /**
  19573. * \brief Try to write exactly 'len' application data bytes
  19574. *
  19575. * \warning This function will do partial writes in some cases. If the
  19576. * return value is non-negative but less than length, the
  19577. * function must be called again with updated arguments:
  19578. * buf + ret, len - ret (if ret is the return value) until
  19579. * it returns a value equal to the last 'len' argument.
  19580. *
  19581. * \param ssl SSL context
  19582. * \param buf buffer holding the data
  19583. * \param len how many bytes must be written
  19584. *
  19585. * \return the number of bytes actually written (may be less than len),
  19586. * or MBEDTLS_ERR_SSL_WANT_WRITE or MBEDTLS_ERR_SSL_WANT_READ,
  19587. * or another negative error code.
  19588. *
  19589. * \note If this function returns something other than a positive
  19590. * value or MBEDTLS_ERR_SSL_WANT_READ/WRITE, the ssl context
  19591. * becomes unusable, and you should either free it or call
  19592. * \c mbedtls_ssl_session_reset() on it before re-using it for
  19593. * a new connection; the current connection must be closed.
  19594. *
  19595. * \note When this function returns MBEDTLS_ERR_SSL_WANT_WRITE/READ,
  19596. * it must be called later with the *same* arguments,
  19597. * until it returns a positive value.
  19598. *
  19599. * \note If the requested length is greater than the maximum
  19600. * fragment length (either the built-in limit or the one set
  19601. * or negotiated with the peer), then:
  19602. * - with TLS, less bytes than requested are written.
  19603. * - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned.
  19604. * \c mbedtls_ssl_get_max_frag_len() may be used to query the
  19605. * active maximum fragment length.
  19606. */
  19607. int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len );
  19608. /**
  19609. * \brief Send an alert message
  19610. *
  19611. * \param ssl SSL context
  19612. * \param level The alert level of the message
  19613. * (MBEDTLS_SSL_ALERT_LEVEL_WARNING or MBEDTLS_SSL_ALERT_LEVEL_FATAL)
  19614. * \param message The alert message (SSL_ALERT_MSG_*)
  19615. *
  19616. * \return 0 if successful, or a specific SSL error code.
  19617. *
  19618. * \note If this function returns something other than 0 or
  19619. * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
  19620. * becomes unusable, and you should either free it or call
  19621. * \c mbedtls_ssl_session_reset() on it before re-using it for
  19622. * a new connection; the current connection must be closed.
  19623. */
  19624. int mbedtls_ssl_send_alert_message( mbedtls_ssl_context *ssl,
  19625. unsigned char level,
  19626. unsigned char message );
  19627. /**
  19628. * \brief Notify the peer that the connection is being closed
  19629. *
  19630. * \param ssl SSL context
  19631. *
  19632. * \return 0 if successful, or a specific SSL error code.
  19633. *
  19634. * \note If this function returns something other than 0 or
  19635. * MBEDTLS_ERR_SSL_WANT_READ/WRITE, then the ssl context
  19636. * becomes unusable, and you should either free it or call
  19637. * \c mbedtls_ssl_session_reset() on it before re-using it for
  19638. * a new connection; the current connection must be closed.
  19639. */
  19640. int mbedtls_ssl_close_notify( mbedtls_ssl_context *ssl );
  19641. /**
  19642. * \brief Free referenced items in an SSL context and clear memory
  19643. *
  19644. * \param ssl SSL context
  19645. */
  19646. void mbedtls_ssl_free( mbedtls_ssl_context *ssl );
  19647. /**
  19648. * \brief Initialize an SSL configuration context
  19649. * Just makes the context ready for
  19650. * mbedtls_ssl_config_defaults() or mbedtls_ssl_config_free().
  19651. *
  19652. * \note You need to call mbedtls_ssl_config_defaults() unless you
  19653. * manually set all of the relevent fields yourself.
  19654. *
  19655. * \param conf SSL configuration context
  19656. */
  19657. void mbedtls_ssl_config_init( mbedtls_ssl_config *conf );
  19658. /**
  19659. * \brief Load reasonnable default SSL configuration values.
  19660. * (You need to call mbedtls_ssl_config_init() first.)
  19661. *
  19662. * \param conf SSL configuration context
  19663. * \param endpoint MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
  19664. * \param transport MBEDTLS_SSL_TRANSPORT_STREAM for TLS, or
  19665. * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS
  19666. * \param preset a MBEDTLS_SSL_PRESET_XXX value
  19667. *
  19668. * \note See \c mbedtls_ssl_conf_transport() for notes on DTLS.
  19669. *
  19670. * \return 0 if successful, or
  19671. * MBEDTLS_ERR_XXX_ALLOC_FAILED on memory allocation error.
  19672. */
  19673. int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf,
  19674. int endpoint, int transport, int preset );
  19675. /**
  19676. * \brief Free an SSL configuration context
  19677. *
  19678. * \param conf SSL configuration context
  19679. */
  19680. void mbedtls_ssl_config_free( mbedtls_ssl_config *conf );
  19681. /**
  19682. * \brief Initialize SSL session structure
  19683. *
  19684. * \param session SSL session
  19685. */
  19686. void mbedtls_ssl_session_init( mbedtls_ssl_session *session );
  19687. /**
  19688. * \brief Free referenced items in an SSL session including the
  19689. * peer certificate and clear memory
  19690. *
  19691. * \param session SSL session
  19692. */
  19693. void mbedtls_ssl_session_free( mbedtls_ssl_session *session );
  19694. #ifdef __cplusplus
  19695. }
  19696. #endif
  19697. #endif /* ssl.h */
  19698. /********* Start of file include/mbedtls/ssl_cookie.h ************/
  19699. /**
  19700. * \file ssl_cookie.h
  19701. *
  19702. * \brief DTLS cookie callbacks implementation
  19703. */
  19704. /*
  19705. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  19706. * SPDX-License-Identifier: Apache-2.0
  19707. *
  19708. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  19709. * not use this file except in compliance with the License.
  19710. * You may obtain a copy of the License at
  19711. *
  19712. * http://www.apache.org/licenses/LICENSE-2.0
  19713. *
  19714. * Unless required by applicable law or agreed to in writing, software
  19715. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  19716. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19717. * See the License for the specific language governing permissions and
  19718. * limitations under the License.
  19719. *
  19720. * This file is part of mbed TLS (https://tls.mbed.org)
  19721. */
  19722. #ifndef MBEDTLS_SSL_COOKIE_H
  19723. #define MBEDTLS_SSL_COOKIE_H
  19724. #if defined(MBEDTLS_THREADING_C)
  19725. #endif
  19726. /**
  19727. * \name SECTION: Module settings
  19728. *
  19729. * The configuration options you can set for this module are in this section.
  19730. * Either change them in config.h or define them on the compiler command line.
  19731. * \{
  19732. */
  19733. #ifndef MBEDTLS_SSL_COOKIE_TIMEOUT
  19734. #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */
  19735. #endif
  19736. /* \} name SECTION: Module settings */
  19737. #ifdef __cplusplus
  19738. extern "C" {
  19739. #endif
  19740. /**
  19741. * \brief Context for the default cookie functions.
  19742. */
  19743. typedef struct
  19744. {
  19745. mbedtls_md_context_t hmac_ctx; /*!< context for the HMAC portion */
  19746. #if !defined(MBEDTLS_HAVE_TIME)
  19747. unsigned long serial; /*!< serial number for expiration */
  19748. #endif
  19749. unsigned long timeout; /*!< timeout delay, in seconds if HAVE_TIME,
  19750. or in number of tickets issued */
  19751. #if defined(MBEDTLS_THREADING_C)
  19752. mbedtls_threading_mutex_t mutex;
  19753. #endif
  19754. } mbedtls_ssl_cookie_ctx;
  19755. /**
  19756. * \brief Initialize cookie context
  19757. */
  19758. void mbedtls_ssl_cookie_init( mbedtls_ssl_cookie_ctx *ctx );
  19759. /**
  19760. * \brief Setup cookie context (generate keys)
  19761. */
  19762. int mbedtls_ssl_cookie_setup( mbedtls_ssl_cookie_ctx *ctx,
  19763. int (*f_rng)(void *, unsigned char *, size_t),
  19764. void *p_rng );
  19765. /**
  19766. * \brief Set expiration delay for cookies
  19767. * (Default MBEDTLS_SSL_COOKIE_TIMEOUT)
  19768. *
  19769. * \param ctx Cookie contex
  19770. * \param delay Delay, in seconds if HAVE_TIME, or in number of cookies
  19771. * issued in the meantime.
  19772. * 0 to disable expiration (NOT recommended)
  19773. */
  19774. void mbedtls_ssl_cookie_set_timeout( mbedtls_ssl_cookie_ctx *ctx, unsigned long delay );
  19775. /**
  19776. * \brief Free cookie context
  19777. */
  19778. void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx );
  19779. /**
  19780. * \brief Generate cookie, see \c mbedtls_ssl_cookie_write_t
  19781. */
  19782. mbedtls_ssl_cookie_write_t mbedtls_ssl_cookie_write;
  19783. /**
  19784. * \brief Verify cookie, see \c mbedtls_ssl_cookie_write_t
  19785. */
  19786. mbedtls_ssl_cookie_check_t mbedtls_ssl_cookie_check;
  19787. #ifdef __cplusplus
  19788. }
  19789. #endif
  19790. #endif /* ssl_cookie.h */
  19791. /********* Start of file include/mbedtls/ssl_internal.h ************/
  19792. /**
  19793. * \file ssl_internal.h
  19794. *
  19795. * \brief Internal functions shared by the SSL modules
  19796. */
  19797. /*
  19798. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  19799. * SPDX-License-Identifier: Apache-2.0
  19800. *
  19801. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  19802. * not use this file except in compliance with the License.
  19803. * You may obtain a copy of the License at
  19804. *
  19805. * http://www.apache.org/licenses/LICENSE-2.0
  19806. *
  19807. * Unless required by applicable law or agreed to in writing, software
  19808. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  19809. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19810. * See the License for the specific language governing permissions and
  19811. * limitations under the License.
  19812. *
  19813. * This file is part of mbed TLS (https://tls.mbed.org)
  19814. */
  19815. #ifndef MBEDTLS_SSL_INTERNAL_H
  19816. #define MBEDTLS_SSL_INTERNAL_H
  19817. #if defined(MBEDTLS_MD5_C)
  19818. #endif
  19819. #if defined(MBEDTLS_SHA1_C)
  19820. #endif
  19821. #if defined(MBEDTLS_SHA256_C)
  19822. #endif
  19823. #if defined(MBEDTLS_SHA512_C)
  19824. #endif
  19825. #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
  19826. #endif
  19827. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  19828. !defined(inline) && !defined(__cplusplus)
  19829. #define inline __inline
  19830. #endif
  19831. /* Determine minimum supported version */
  19832. #define MBEDTLS_SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
  19833. #if defined(MBEDTLS_SSL_PROTO_SSL3)
  19834. #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0
  19835. #else
  19836. #if defined(MBEDTLS_SSL_PROTO_TLS1)
  19837. #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
  19838. #else
  19839. #if defined(MBEDTLS_SSL_PROTO_TLS1_1)
  19840. #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2
  19841. #else
  19842. #if defined(MBEDTLS_SSL_PROTO_TLS1_2)
  19843. #define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3
  19844. #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
  19845. #endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
  19846. #endif /* MBEDTLS_SSL_PROTO_TLS1 */
  19847. #endif /* MBEDTLS_SSL_PROTO_SSL3 */
  19848. #define MBEDTLS_SSL_MIN_VALID_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
  19849. #define MBEDTLS_SSL_MIN_VALID_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
  19850. /* Determine maximum supported version */
  19851. #define MBEDTLS_SSL_MAX_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
  19852. #if defined(MBEDTLS_SSL_PROTO_TLS1_2)
  19853. #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3
  19854. #else
  19855. #if defined(MBEDTLS_SSL_PROTO_TLS1_1)
  19856. #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2
  19857. #else
  19858. #if defined(MBEDTLS_SSL_PROTO_TLS1)
  19859. #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
  19860. #else
  19861. #if defined(MBEDTLS_SSL_PROTO_SSL3)
  19862. #define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0
  19863. #endif /* MBEDTLS_SSL_PROTO_SSL3 */
  19864. #endif /* MBEDTLS_SSL_PROTO_TLS1 */
  19865. #endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
  19866. #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
  19867. #define MBEDTLS_SSL_INITIAL_HANDSHAKE 0
  19868. #define MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS 1 /* In progress */
  19869. #define MBEDTLS_SSL_RENEGOTIATION_DONE 2 /* Done or aborted */
  19870. #define MBEDTLS_SSL_RENEGOTIATION_PENDING 3 /* Requested (server only) */
  19871. /*
  19872. * DTLS retransmission states, see RFC 6347 4.2.4
  19873. *
  19874. * The SENDING state is merged in PREPARING for initial sends,
  19875. * but is distinct for resends.
  19876. *
  19877. * Note: initial state is wrong for server, but is not used anyway.
  19878. */
  19879. #define MBEDTLS_SSL_RETRANS_PREPARING 0
  19880. #define MBEDTLS_SSL_RETRANS_SENDING 1
  19881. #define MBEDTLS_SSL_RETRANS_WAITING 2
  19882. #define MBEDTLS_SSL_RETRANS_FINISHED 3
  19883. /*
  19884. * Allow extra bytes for record, authentication and encryption overhead:
  19885. * counter (8) + header (5) + IV(16) + MAC (16-48) + padding (0-256)
  19886. * and allow for a maximum of 1024 of compression expansion if
  19887. * enabled.
  19888. */
  19889. #if defined(MBEDTLS_ZLIB_SUPPORT)
  19890. #define MBEDTLS_SSL_COMPRESSION_ADD 1024
  19891. #else
  19892. #define MBEDTLS_SSL_COMPRESSION_ADD 0
  19893. #endif
  19894. #if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_MODE_CBC)
  19895. /* Ciphersuites using HMAC */
  19896. #if defined(MBEDTLS_SHA512_C)
  19897. #define MBEDTLS_SSL_MAC_ADD 48 /* SHA-384 used for HMAC */
  19898. #elif defined(MBEDTLS_SHA256_C)
  19899. #define MBEDTLS_SSL_MAC_ADD 32 /* SHA-256 used for HMAC */
  19900. #else
  19901. #define MBEDTLS_SSL_MAC_ADD 20 /* SHA-1 used for HMAC */
  19902. #endif
  19903. #else
  19904. /* AEAD ciphersuites: GCM and CCM use a 128 bits tag */
  19905. #define MBEDTLS_SSL_MAC_ADD 16
  19906. #endif
  19907. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  19908. #define MBEDTLS_SSL_PADDING_ADD 256
  19909. #else
  19910. #define MBEDTLS_SSL_PADDING_ADD 0
  19911. #endif
  19912. #define MBEDTLS_SSL_PAYLOAD_LEN ( MBEDTLS_SSL_MAX_CONTENT_LEN \
  19913. + MBEDTLS_SSL_COMPRESSION_ADD \
  19914. + MBEDTLS_MAX_IV_LENGTH \
  19915. + MBEDTLS_SSL_MAC_ADD \
  19916. + MBEDTLS_SSL_PADDING_ADD \
  19917. )
  19918. /*
  19919. * Check that we obey the standard's message size bounds
  19920. */
  19921. #if MBEDTLS_SSL_MAX_CONTENT_LEN > 16384
  19922. #error Bad configuration - record content too large.
  19923. #endif
  19924. #if MBEDTLS_SSL_PAYLOAD_LEN > 16384 + 2048
  19925. #error Bad configuration - protected record payload too large.
  19926. #endif
  19927. /* Note: Even though the TLS record header is only 5 bytes
  19928. long, we're internally using 8 bytes to store the
  19929. implicit sequence number. */
  19930. #define MBEDTLS_SSL_HEADER_LEN 13
  19931. #define MBEDTLS_SSL_BUFFER_LEN \
  19932. ( ( MBEDTLS_SSL_HEADER_LEN ) + ( MBEDTLS_SSL_PAYLOAD_LEN ) )
  19933. /*
  19934. * TLS extension flags (for extensions with outgoing ServerHello content
  19935. * that need it (e.g. for RENEGOTIATION_INFO the server already knows because
  19936. * of state of the renegotiation flag, so no indicator is required)
  19937. */
  19938. #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
  19939. #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK (1 << 1)
  19940. #ifdef __cplusplus
  19941. extern "C" {
  19942. #endif
  19943. #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
  19944. defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
  19945. /*
  19946. * Abstraction for a grid of allowed signature-hash-algorithm pairs.
  19947. */
  19948. struct mbedtls_ssl_sig_hash_set_t
  19949. {
  19950. /* At the moment, we only need to remember a single suitable
  19951. * hash algorithm per signature algorithm. As long as that's
  19952. * the case - and we don't need a general lookup function -
  19953. * we can implement the sig-hash-set as a map from signatures
  19954. * to hash algorithms. */
  19955. mbedtls_md_type_t rsa;
  19956. mbedtls_md_type_t ecdsa;
  19957. };
  19958. #endif /* MBEDTLS_SSL_PROTO_TLS1_2 &&
  19959. MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */
  19960. /*
  19961. * This structure contains the parameters only needed during handshake.
  19962. */
  19963. struct mbedtls_ssl_handshake_params
  19964. {
  19965. /*
  19966. * Handshake specific crypto variables
  19967. */
  19968. #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
  19969. defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
  19970. mbedtls_ssl_sig_hash_set_t hash_algs; /*!< Set of suitable sig-hash pairs */
  19971. #endif
  19972. #if defined(MBEDTLS_DHM_C)
  19973. mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */
  19974. #endif
  19975. #if defined(MBEDTLS_ECDH_C)
  19976. mbedtls_ecdh_context ecdh_ctx; /*!< ECDH key exchange */
  19977. #endif
  19978. #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
  19979. mbedtls_ecjpake_context ecjpake_ctx; /*!< EC J-PAKE key exchange */
  19980. #if defined(MBEDTLS_SSL_CLI_C)
  19981. unsigned char *ecjpake_cache; /*!< Cache for ClientHello ext */
  19982. size_t ecjpake_cache_len; /*!< Length of cached data */
  19983. #endif
  19984. #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
  19985. #if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
  19986. defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
  19987. const mbedtls_ecp_curve_info **curves; /*!< Supported elliptic curves */
  19988. #endif
  19989. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
  19990. unsigned char *psk; /*!< PSK from the callback */
  19991. size_t psk_len; /*!< Length of PSK from callback */
  19992. #endif
  19993. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  19994. mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */
  19995. #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
  19996. int sni_authmode; /*!< authmode from SNI callback */
  19997. mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI */
  19998. mbedtls_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */
  19999. mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */
  20000. #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
  20001. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  20002. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  20003. unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
  20004. unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
  20005. unsigned char *verify_cookie; /*!< Cli: HelloVerifyRequest cookie
  20006. Srv: unused */
  20007. unsigned char verify_cookie_len; /*!< Cli: cookie length
  20008. Srv: flag for sending a cookie */
  20009. unsigned char *hs_msg; /*!< Reassembled handshake message */
  20010. uint32_t retransmit_timeout; /*!< Current value of timeout */
  20011. unsigned char retransmit_state; /*!< Retransmission state */
  20012. mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */
  20013. mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */
  20014. unsigned int in_flight_start_seq; /*!< Minimum message sequence in the
  20015. flight being received */
  20016. mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for
  20017. resending messages */
  20018. unsigned char alt_out_ctr[8]; /*!< Alternative record epoch/counter
  20019. for resending messages */
  20020. #endif /* MBEDTLS_SSL_PROTO_DTLS */
  20021. /*
  20022. * Checksum contexts
  20023. */
  20024. #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
  20025. defined(MBEDTLS_SSL_PROTO_TLS1_1)
  20026. mbedtls_md5_context fin_md5;
  20027. mbedtls_sha1_context fin_sha1;
  20028. #endif
  20029. #if defined(MBEDTLS_SSL_PROTO_TLS1_2)
  20030. #if defined(MBEDTLS_SHA256_C)
  20031. mbedtls_sha256_context fin_sha256;
  20032. #endif
  20033. #if defined(MBEDTLS_SHA512_C)
  20034. mbedtls_sha512_context fin_sha512;
  20035. #endif
  20036. #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
  20037. void (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t);
  20038. void (*calc_verify)(mbedtls_ssl_context *, unsigned char *);
  20039. void (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int);
  20040. int (*tls_prf)(const unsigned char *, size_t, const char *,
  20041. const unsigned char *, size_t,
  20042. unsigned char *, size_t);
  20043. size_t pmslen; /*!< premaster length */
  20044. unsigned char randbytes[64]; /*!< random bytes */
  20045. unsigned char premaster[MBEDTLS_PREMASTER_SIZE];
  20046. /*!< premaster secret */
  20047. int resume; /*!< session resume indicator*/
  20048. int max_major_ver; /*!< max. major version client*/
  20049. int max_minor_ver; /*!< max. minor version client*/
  20050. int cli_exts; /*!< client extension presence*/
  20051. #if defined(MBEDTLS_SSL_SESSION_TICKETS)
  20052. int new_session_ticket; /*!< use NewSessionTicket? */
  20053. #endif /* MBEDTLS_SSL_SESSION_TICKETS */
  20054. #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
  20055. int extended_ms; /*!< use Extended Master Secret? */
  20056. #endif
  20057. };
  20058. /*
  20059. * This structure contains a full set of runtime transform parameters
  20060. * either in negotiation or active.
  20061. */
  20062. struct mbedtls_ssl_transform
  20063. {
  20064. /*
  20065. * Session specific crypto layer
  20066. */
  20067. const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
  20068. /*!< Chosen cipersuite_info */
  20069. unsigned int keylen; /*!< symmetric key length (bytes) */
  20070. size_t minlen; /*!< min. ciphertext length */
  20071. size_t ivlen; /*!< IV length */
  20072. size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */
  20073. size_t maclen; /*!< MAC length */
  20074. unsigned char iv_enc[16]; /*!< IV (encryption) */
  20075. unsigned char iv_dec[16]; /*!< IV (decryption) */
  20076. #if defined(MBEDTLS_SSL_PROTO_SSL3)
  20077. /* Needed only for SSL v3.0 secret */
  20078. unsigned char mac_enc[20]; /*!< SSL v3.0 secret (enc) */
  20079. unsigned char mac_dec[20]; /*!< SSL v3.0 secret (dec) */
  20080. #endif /* MBEDTLS_SSL_PROTO_SSL3 */
  20081. mbedtls_md_context_t md_ctx_enc; /*!< MAC (encryption) */
  20082. mbedtls_md_context_t md_ctx_dec; /*!< MAC (decryption) */
  20083. mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
  20084. mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
  20085. /*
  20086. * Session specific compression layer
  20087. */
  20088. #if defined(MBEDTLS_ZLIB_SUPPORT)
  20089. z_stream ctx_deflate; /*!< compression context */
  20090. z_stream ctx_inflate; /*!< decompression context */
  20091. #endif
  20092. };
  20093. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  20094. /*
  20095. * List of certificate + private key pairs
  20096. */
  20097. struct mbedtls_ssl_key_cert
  20098. {
  20099. mbedtls_x509_crt *cert; /*!< cert */
  20100. mbedtls_pk_context *key; /*!< private key */
  20101. mbedtls_ssl_key_cert *next; /*!< next key/cert pair */
  20102. };
  20103. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  20104. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  20105. /*
  20106. * List of handshake messages kept around for resending
  20107. */
  20108. struct mbedtls_ssl_flight_item
  20109. {
  20110. unsigned char *p; /*!< message, including handshake headers */
  20111. size_t len; /*!< length of p */
  20112. unsigned char type; /*!< type of the message: handshake or CCS */
  20113. mbedtls_ssl_flight_item *next; /*!< next handshake message(s) */
  20114. };
  20115. #endif /* MBEDTLS_SSL_PROTO_DTLS */
  20116. #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
  20117. defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
  20118. /* Find an entry in a signature-hash set matching a given hash algorithm. */
  20119. mbedtls_md_type_t mbedtls_ssl_sig_hash_set_find( mbedtls_ssl_sig_hash_set_t *set,
  20120. mbedtls_pk_type_t sig_alg );
  20121. /* Add a signature-hash-pair to a signature-hash set */
  20122. void mbedtls_ssl_sig_hash_set_add( mbedtls_ssl_sig_hash_set_t *set,
  20123. mbedtls_pk_type_t sig_alg,
  20124. mbedtls_md_type_t md_alg );
  20125. /* Allow exactly one hash algorithm for each signature. */
  20126. void mbedtls_ssl_sig_hash_set_const_hash( mbedtls_ssl_sig_hash_set_t *set,
  20127. mbedtls_md_type_t md_alg );
  20128. /* Setup an empty signature-hash set */
  20129. static inline void mbedtls_ssl_sig_hash_set_init( mbedtls_ssl_sig_hash_set_t *set )
  20130. {
  20131. mbedtls_ssl_sig_hash_set_const_hash( set, MBEDTLS_MD_NONE );
  20132. }
  20133. #endif /* MBEDTLS_SSL_PROTO_TLS1_2) &&
  20134. MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */
  20135. /**
  20136. * \brief Free referenced items in an SSL transform context and clear
  20137. * memory
  20138. *
  20139. * \param transform SSL transform context
  20140. */
  20141. void mbedtls_ssl_transform_free( mbedtls_ssl_transform *transform );
  20142. /**
  20143. * \brief Free referenced items in an SSL handshake context and clear
  20144. * memory
  20145. *
  20146. * \param handshake SSL handshake context
  20147. */
  20148. void mbedtls_ssl_handshake_free( mbedtls_ssl_handshake_params *handshake );
  20149. int mbedtls_ssl_handshake_client_step( mbedtls_ssl_context *ssl );
  20150. int mbedtls_ssl_handshake_server_step( mbedtls_ssl_context *ssl );
  20151. void mbedtls_ssl_handshake_wrapup( mbedtls_ssl_context *ssl );
  20152. int mbedtls_ssl_send_fatal_handshake_failure( mbedtls_ssl_context *ssl );
  20153. void mbedtls_ssl_reset_checksum( mbedtls_ssl_context *ssl );
  20154. int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl );
  20155. int mbedtls_ssl_read_record_layer( mbedtls_ssl_context *ssl );
  20156. int mbedtls_ssl_handle_message_type( mbedtls_ssl_context *ssl );
  20157. int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl );
  20158. void mbedtls_ssl_update_handshake_status( mbedtls_ssl_context *ssl );
  20159. /**
  20160. * \brief Update record layer
  20161. *
  20162. * This function roughly separates the implementation
  20163. * of the logic of (D)TLS from the implementation
  20164. * of the secure transport.
  20165. *
  20166. * \param ssl SSL context to use
  20167. *
  20168. * \return 0 or non-zero error code.
  20169. *
  20170. * \note A clarification on what is called 'record layer' here
  20171. * is in order, as many sensible definitions are possible:
  20172. *
  20173. * The record layer takes as input an untrusted underlying
  20174. * transport (stream or datagram) and transforms it into
  20175. * a serially multiplexed, secure transport, which
  20176. * conceptually provides the following:
  20177. *
  20178. * (1) Three datagram based, content-agnostic transports
  20179. * for handshake, alert and CCS messages.
  20180. * (2) One stream- or datagram-based transport
  20181. * for application data.
  20182. * (3) Functionality for changing the underlying transform
  20183. * securing the contents.
  20184. *
  20185. * The interface to this functionality is given as follows:
  20186. *
  20187. * a Updating
  20188. * [Currently implemented by mbedtls_ssl_read_record]
  20189. *
  20190. * Check if and on which of the four 'ports' data is pending:
  20191. * Nothing, a controlling datagram of type (1), or application
  20192. * data (2). In any case data is present, internal buffers
  20193. * provide access to the data for the user to process it.
  20194. * Consumption of type (1) datagrams is done automatically
  20195. * on the next update, invalidating that the internal buffers
  20196. * for previous datagrams, while consumption of application
  20197. * data (2) is user-controlled.
  20198. *
  20199. * b Reading of application data
  20200. * [Currently manual adaption of ssl->in_offt pointer]
  20201. *
  20202. * As mentioned in the last paragraph, consumption of data
  20203. * is different from the automatic consumption of control
  20204. * datagrams (1) because application data is treated as a stream.
  20205. *
  20206. * c Tracking availability of application data
  20207. * [Currently manually through decreasing ssl->in_msglen]
  20208. *
  20209. * For efficiency and to retain datagram semantics for
  20210. * application data in case of DTLS, the record layer
  20211. * provides functionality for checking how much application
  20212. * data is still available in the internal buffer.
  20213. *
  20214. * d Changing the transformation securing the communication.
  20215. *
  20216. * Given an opaque implementation of the record layer in the
  20217. * above sense, it should be possible to implement the logic
  20218. * of (D)TLS on top of it without the need to know anything
  20219. * about the record layer's internals. This is done e.g.
  20220. * in all the handshake handling functions, and in the
  20221. * application data reading function mbedtls_ssl_read.
  20222. *
  20223. * \note The above tries to give a conceptual picture of the
  20224. * record layer, but the current implementation deviates
  20225. * from it in some places. For example, our implementation of
  20226. * the update functionality through mbedtls_ssl_read_record
  20227. * discards datagrams depending on the current state, which
  20228. * wouldn't fall under the record layer's responsibility
  20229. * following the above definition.
  20230. *
  20231. */
  20232. int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl );
  20233. int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want );
  20234. int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl );
  20235. int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl );
  20236. int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl );
  20237. int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl );
  20238. int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl );
  20239. int mbedtls_ssl_write_change_cipher_spec( mbedtls_ssl_context *ssl );
  20240. int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl );
  20241. int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl );
  20242. void mbedtls_ssl_optimize_checksum( mbedtls_ssl_context *ssl,
  20243. const mbedtls_ssl_ciphersuite_t *ciphersuite_info );
  20244. #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
  20245. int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exchange_type_t key_ex );
  20246. #endif
  20247. #if defined(MBEDTLS_PK_C)
  20248. unsigned char mbedtls_ssl_sig_from_pk( mbedtls_pk_context *pk );
  20249. unsigned char mbedtls_ssl_sig_from_pk_alg( mbedtls_pk_type_t type );
  20250. mbedtls_pk_type_t mbedtls_ssl_pk_alg_from_sig( unsigned char sig );
  20251. #endif
  20252. mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash( unsigned char hash );
  20253. unsigned char mbedtls_ssl_hash_from_md_alg( int md );
  20254. int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md );
  20255. #if defined(MBEDTLS_ECP_C)
  20256. int mbedtls_ssl_check_curve( const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id );
  20257. #endif
  20258. #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
  20259. int mbedtls_ssl_check_sig_hash( const mbedtls_ssl_context *ssl,
  20260. mbedtls_md_type_t md );
  20261. #endif
  20262. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  20263. static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl )
  20264. {
  20265. mbedtls_ssl_key_cert *key_cert;
  20266. if( ssl->handshake != NULL && ssl->handshake->key_cert != NULL )
  20267. key_cert = ssl->handshake->key_cert;
  20268. else
  20269. key_cert = ssl->conf->key_cert;
  20270. return( key_cert == NULL ? NULL : key_cert->key );
  20271. }
  20272. static inline mbedtls_x509_crt *mbedtls_ssl_own_cert( mbedtls_ssl_context *ssl )
  20273. {
  20274. mbedtls_ssl_key_cert *key_cert;
  20275. if( ssl->handshake != NULL && ssl->handshake->key_cert != NULL )
  20276. key_cert = ssl->handshake->key_cert;
  20277. else
  20278. key_cert = ssl->conf->key_cert;
  20279. return( key_cert == NULL ? NULL : key_cert->cert );
  20280. }
  20281. /*
  20282. * Check usage of a certificate wrt extensions:
  20283. * keyUsage, extendedKeyUsage (later), and nSCertType (later).
  20284. *
  20285. * Warning: cert_endpoint is the endpoint of the cert (ie, of our peer when we
  20286. * check a cert we received from them)!
  20287. *
  20288. * Return 0 if everything is OK, -1 if not.
  20289. */
  20290. int mbedtls_ssl_check_cert_usage( const mbedtls_x509_crt *cert,
  20291. const mbedtls_ssl_ciphersuite_t *ciphersuite,
  20292. int cert_endpoint,
  20293. uint32_t *flags );
  20294. #endif /* MBEDTLS_X509_CRT_PARSE_C */
  20295. void mbedtls_ssl_write_version( int major, int minor, int transport,
  20296. unsigned char ver[2] );
  20297. void mbedtls_ssl_read_version( int *major, int *minor, int transport,
  20298. const unsigned char ver[2] );
  20299. static inline size_t mbedtls_ssl_hdr_len( const mbedtls_ssl_context *ssl )
  20300. {
  20301. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  20302. if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
  20303. return( 13 );
  20304. #else
  20305. ((void) ssl);
  20306. #endif
  20307. return( 5 );
  20308. }
  20309. static inline size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl )
  20310. {
  20311. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  20312. if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
  20313. return( 12 );
  20314. #else
  20315. ((void) ssl);
  20316. #endif
  20317. return( 4 );
  20318. }
  20319. #if defined(MBEDTLS_SSL_PROTO_DTLS)
  20320. void mbedtls_ssl_send_flight_completed( mbedtls_ssl_context *ssl );
  20321. void mbedtls_ssl_recv_flight_completed( mbedtls_ssl_context *ssl );
  20322. int mbedtls_ssl_resend( mbedtls_ssl_context *ssl );
  20323. #endif
  20324. /* Visible for testing purposes only */
  20325. #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
  20326. int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context *ssl );
  20327. void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
  20328. #endif
  20329. /* constant-time buffer comparison */
  20330. static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n )
  20331. {
  20332. size_t i;
  20333. volatile const unsigned char *A = (volatile const unsigned char *) a;
  20334. volatile const unsigned char *B = (volatile const unsigned char *) b;
  20335. volatile unsigned char diff = 0;
  20336. for( i = 0; i < n; i++ )
  20337. diff |= A[i] ^ B[i];
  20338. return( diff );
  20339. }
  20340. #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
  20341. defined(MBEDTLS_SSL_PROTO_TLS1_1)
  20342. int mbedtls_ssl_get_key_exchange_md_ssl_tls( mbedtls_ssl_context *ssl,
  20343. unsigned char *output,
  20344. unsigned char *data, size_t data_len );
  20345. #endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \
  20346. MBEDTLS_SSL_PROTO_TLS1_1 */
  20347. #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \
  20348. defined(MBEDTLS_SSL_PROTO_TLS1_2)
  20349. int mbedtls_ssl_get_key_exchange_md_tls1_2( mbedtls_ssl_context *ssl,
  20350. unsigned char *output,
  20351. unsigned char *data, size_t data_len,
  20352. mbedtls_md_type_t md_alg );
  20353. #endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \
  20354. MBEDTLS_SSL_PROTO_TLS1_2 */
  20355. #ifdef __cplusplus
  20356. }
  20357. #endif
  20358. #endif /* ssl_internal.h */
  20359. /********* Start of file include/mbedtls/ssl_cache.h ************/
  20360. /**
  20361. * \file ssl_cache.h
  20362. *
  20363. * \brief SSL session cache implementation
  20364. */
  20365. /*
  20366. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  20367. * SPDX-License-Identifier: Apache-2.0
  20368. *
  20369. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  20370. * not use this file except in compliance with the License.
  20371. * You may obtain a copy of the License at
  20372. *
  20373. * http://www.apache.org/licenses/LICENSE-2.0
  20374. *
  20375. * Unless required by applicable law or agreed to in writing, software
  20376. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  20377. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20378. * See the License for the specific language governing permissions and
  20379. * limitations under the License.
  20380. *
  20381. * This file is part of mbed TLS (https://tls.mbed.org)
  20382. */
  20383. #ifndef MBEDTLS_SSL_CACHE_H
  20384. #define MBEDTLS_SSL_CACHE_H
  20385. #if defined(MBEDTLS_THREADING_C)
  20386. #endif
  20387. /**
  20388. * \name SECTION: Module settings
  20389. *
  20390. * The configuration options you can set for this module are in this section.
  20391. * Either change them in config.h or define them on the compiler command line.
  20392. * \{
  20393. */
  20394. #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT)
  20395. #define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */
  20396. #endif
  20397. #if !defined(MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES)
  20398. #define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /*!< Maximum entries in cache */
  20399. #endif
  20400. /* \} name SECTION: Module settings */
  20401. #ifdef __cplusplus
  20402. extern "C" {
  20403. #endif
  20404. typedef struct mbedtls_ssl_cache_context mbedtls_ssl_cache_context;
  20405. typedef struct mbedtls_ssl_cache_entry mbedtls_ssl_cache_entry;
  20406. /**
  20407. * \brief This structure is used for storing cache entries
  20408. */
  20409. struct mbedtls_ssl_cache_entry
  20410. {
  20411. #if defined(MBEDTLS_HAVE_TIME)
  20412. mbedtls_time_t timestamp; /*!< entry timestamp */
  20413. #endif
  20414. mbedtls_ssl_session session; /*!< entry session */
  20415. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  20416. mbedtls_x509_buf peer_cert; /*!< entry peer_cert */
  20417. #endif
  20418. mbedtls_ssl_cache_entry *next; /*!< chain pointer */
  20419. };
  20420. /**
  20421. * \brief Cache context
  20422. */
  20423. struct mbedtls_ssl_cache_context
  20424. {
  20425. mbedtls_ssl_cache_entry *chain; /*!< start of the chain */
  20426. int timeout; /*!< cache entry timeout */
  20427. int max_entries; /*!< maximum entries */
  20428. #if defined(MBEDTLS_THREADING_C)
  20429. mbedtls_threading_mutex_t mutex; /*!< mutex */
  20430. #endif
  20431. };
  20432. /**
  20433. * \brief Initialize an SSL cache context
  20434. *
  20435. * \param cache SSL cache context
  20436. */
  20437. void mbedtls_ssl_cache_init( mbedtls_ssl_cache_context *cache );
  20438. /**
  20439. * \brief Cache get callback implementation
  20440. * (Thread-safe if MBEDTLS_THREADING_C is enabled)
  20441. *
  20442. * \param data SSL cache context
  20443. * \param session session to retrieve entry for
  20444. */
  20445. int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session );
  20446. /**
  20447. * \brief Cache set callback implementation
  20448. * (Thread-safe if MBEDTLS_THREADING_C is enabled)
  20449. *
  20450. * \param data SSL cache context
  20451. * \param session session to store entry for
  20452. */
  20453. int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session );
  20454. #if defined(MBEDTLS_HAVE_TIME)
  20455. /**
  20456. * \brief Set the cache timeout
  20457. * (Default: MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT (1 day))
  20458. *
  20459. * A timeout of 0 indicates no timeout.
  20460. *
  20461. * \param cache SSL cache context
  20462. * \param timeout cache entry timeout in seconds
  20463. */
  20464. void mbedtls_ssl_cache_set_timeout( mbedtls_ssl_cache_context *cache, int timeout );
  20465. #endif /* MBEDTLS_HAVE_TIME */
  20466. /**
  20467. * \brief Set the maximum number of cache entries
  20468. * (Default: MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES (50))
  20469. *
  20470. * \param cache SSL cache context
  20471. * \param max cache entry maximum
  20472. */
  20473. void mbedtls_ssl_cache_set_max_entries( mbedtls_ssl_cache_context *cache, int max );
  20474. /**
  20475. * \brief Free referenced items in a cache context and clear memory
  20476. *
  20477. * \param cache SSL cache context
  20478. */
  20479. void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache );
  20480. #ifdef __cplusplus
  20481. }
  20482. #endif
  20483. #endif /* ssl_cache.h */
  20484. /********* Start of file include/mbedtls/ssl_ticket.h ************/
  20485. /**
  20486. * \file ssl_ticket.h
  20487. *
  20488. * \brief TLS server ticket callbacks implementation
  20489. */
  20490. /*
  20491. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  20492. * SPDX-License-Identifier: Apache-2.0
  20493. *
  20494. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  20495. * not use this file except in compliance with the License.
  20496. * You may obtain a copy of the License at
  20497. *
  20498. * http://www.apache.org/licenses/LICENSE-2.0
  20499. *
  20500. * Unless required by applicable law or agreed to in writing, software
  20501. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  20502. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20503. * See the License for the specific language governing permissions and
  20504. * limitations under the License.
  20505. *
  20506. * This file is part of mbed TLS (https://tls.mbed.org)
  20507. */
  20508. #ifndef MBEDTLS_SSL_TICKET_H
  20509. #define MBEDTLS_SSL_TICKET_H
  20510. /*
  20511. * This implementation of the session ticket callbacks includes key
  20512. * management, rotating the keys periodically in order to preserve forward
  20513. * secrecy, when MBEDTLS_HAVE_TIME is defined.
  20514. */
  20515. #if defined(MBEDTLS_THREADING_C)
  20516. #endif
  20517. #ifdef __cplusplus
  20518. extern "C" {
  20519. #endif
  20520. /**
  20521. * \brief Information for session ticket protection
  20522. */
  20523. typedef struct
  20524. {
  20525. unsigned char name[4]; /*!< random key identifier */
  20526. uint32_t generation_time; /*!< key generation timestamp (seconds) */
  20527. mbedtls_cipher_context_t ctx; /*!< context for auth enc/decryption */
  20528. }
  20529. mbedtls_ssl_ticket_key;
  20530. /**
  20531. * \brief Context for session ticket handling functions
  20532. */
  20533. typedef struct
  20534. {
  20535. mbedtls_ssl_ticket_key keys[2]; /*!< ticket protection keys */
  20536. unsigned char active; /*!< index of the currently active key */
  20537. uint32_t ticket_lifetime; /*!< lifetime of tickets in seconds */
  20538. /** Callback for getting (pseudo-)random numbers */
  20539. int (*f_rng)(void *, unsigned char *, size_t);
  20540. void *p_rng; /*!< context for the RNG function */
  20541. #if defined(MBEDTLS_THREADING_C)
  20542. mbedtls_threading_mutex_t mutex;
  20543. #endif
  20544. }
  20545. mbedtls_ssl_ticket_context;
  20546. /**
  20547. * \brief Initialize a ticket context.
  20548. * (Just make it ready for mbedtls_ssl_ticket_setup()
  20549. * or mbedtls_ssl_ticket_free().)
  20550. *
  20551. * \param ctx Context to be initialized
  20552. */
  20553. void mbedtls_ssl_ticket_init( mbedtls_ssl_ticket_context *ctx );
  20554. /**
  20555. * \brief Prepare context to be actually used
  20556. *
  20557. * \param ctx Context to be set up
  20558. * \param f_rng RNG callback function
  20559. * \param p_rng RNG callback context
  20560. * \param cipher AEAD cipher to use for ticket protection.
  20561. * Recommended value: MBEDTLS_CIPHER_AES_256_GCM.
  20562. * \param lifetime Tickets lifetime in seconds
  20563. * Recommended value: 86400 (one day).
  20564. *
  20565. * \note It is highly recommended to select a cipher that is at
  20566. * least as strong as the the strongest ciphersuite
  20567. * supported. Usually that means a 256-bit key.
  20568. *
  20569. * \note The lifetime of the keys is twice the lifetime of tickets.
  20570. * It is recommended to pick a reasonnable lifetime so as not
  20571. * to negate the benefits of forward secrecy.
  20572. *
  20573. * \return 0 if successful,
  20574. * or a specific MBEDTLS_ERR_XXX error code
  20575. */
  20576. int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx,
  20577. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
  20578. mbedtls_cipher_type_t cipher,
  20579. uint32_t lifetime );
  20580. /**
  20581. * \brief Implementation of the ticket write callback
  20582. *
  20583. * \note See \c mbedlts_ssl_ticket_write_t for description
  20584. */
  20585. mbedtls_ssl_ticket_write_t mbedtls_ssl_ticket_write;
  20586. /**
  20587. * \brief Implementation of the ticket parse callback
  20588. *
  20589. * \note See \c mbedlts_ssl_ticket_parse_t for description
  20590. */
  20591. mbedtls_ssl_ticket_parse_t mbedtls_ssl_ticket_parse;
  20592. /**
  20593. * \brief Free a context's content and zeroize it.
  20594. *
  20595. * \param ctx Context to be cleaned up
  20596. */
  20597. void mbedtls_ssl_ticket_free( mbedtls_ssl_ticket_context *ctx );
  20598. #ifdef __cplusplus
  20599. }
  20600. #endif
  20601. #endif /* ssl_ticket.h */
  20602. /********* Start of file include/mbedtls/debug.h ************/
  20603. /**
  20604. * \file debug.h
  20605. *
  20606. * \brief Functions for controlling and providing debug output from the library.
  20607. */
  20608. /*
  20609. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  20610. * SPDX-License-Identifier: Apache-2.0
  20611. *
  20612. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  20613. * not use this file except in compliance with the License.
  20614. * You may obtain a copy of the License at
  20615. *
  20616. * http://www.apache.org/licenses/LICENSE-2.0
  20617. *
  20618. * Unless required by applicable law or agreed to in writing, software
  20619. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  20620. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20621. * See the License for the specific language governing permissions and
  20622. * limitations under the License.
  20623. *
  20624. * This file is part of mbed TLS (https://tls.mbed.org)
  20625. */
  20626. #ifndef MBEDTLS_DEBUG_H
  20627. #define MBEDTLS_DEBUG_H
  20628. #if !defined(MBEDTLS_CONFIG_FILE)
  20629. #else
  20630. #endif
  20631. #if defined(MBEDTLS_ECP_C)
  20632. #endif
  20633. #if defined(MBEDTLS_DEBUG_C)
  20634. #define MBEDTLS_DEBUG_STRIP_PARENS( ... ) __VA_ARGS__
  20635. #define MBEDTLS_SSL_DEBUG_MSG( level, args ) \
  20636. mbedtls_debug_print_msg( ssl, level, __FILE__, __LINE__, \
  20637. MBEDTLS_DEBUG_STRIP_PARENS args )
  20638. #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) \
  20639. mbedtls_debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret )
  20640. #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) \
  20641. mbedtls_debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len )
  20642. #if defined(MBEDTLS_BIGNUM_C)
  20643. #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) \
  20644. mbedtls_debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X )
  20645. #endif
  20646. #if defined(MBEDTLS_ECP_C)
  20647. #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) \
  20648. mbedtls_debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X )
  20649. #endif
  20650. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  20651. #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) \
  20652. mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt )
  20653. #endif
  20654. #else /* MBEDTLS_DEBUG_C */
  20655. #define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 )
  20656. #define MBEDTLS_SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
  20657. #define MBEDTLS_SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
  20658. #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
  20659. #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
  20660. #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
  20661. #endif /* MBEDTLS_DEBUG_C */
  20662. #ifdef __cplusplus
  20663. extern "C" {
  20664. #endif
  20665. /**
  20666. * \brief Set the threshold error level to handle globally all debug output.
  20667. * Debug messages that have a level over the threshold value are
  20668. * discarded.
  20669. * (Default value: 0 = No debug )
  20670. *
  20671. * \param threshold theshold level of messages to filter on. Messages at a
  20672. * higher level will be discarded.
  20673. * - Debug levels
  20674. * - 0 No debug
  20675. * - 1 Error
  20676. * - 2 State change
  20677. * - 3 Informational
  20678. * - 4 Verbose
  20679. */
  20680. void mbedtls_debug_set_threshold( int threshold );
  20681. /**
  20682. * \brief Print a message to the debug output. This function is always used
  20683. * through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl
  20684. * context, file and line number parameters.
  20685. *
  20686. * \param ssl SSL context
  20687. * \param level error level of the debug message
  20688. * \param file file the message has occurred in
  20689. * \param line line number the message has occurred at
  20690. * \param format format specifier, in printf format
  20691. * \param ... variables used by the format specifier
  20692. *
  20693. * \attention This function is intended for INTERNAL usage within the
  20694. * library only.
  20695. */
  20696. void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
  20697. const char *file, int line,
  20698. const char *format, ... );
  20699. /**
  20700. * \brief Print the return value of a function to the debug output. This
  20701. * function is always used through the MBEDTLS_SSL_DEBUG_RET() macro,
  20702. * which supplies the ssl context, file and line number parameters.
  20703. *
  20704. * \param ssl SSL context
  20705. * \param level error level of the debug message
  20706. * \param file file the error has occurred in
  20707. * \param line line number the error has occurred in
  20708. * \param text the name of the function that returned the error
  20709. * \param ret the return code value
  20710. *
  20711. * \attention This function is intended for INTERNAL usage within the
  20712. * library only.
  20713. */
  20714. void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
  20715. const char *file, int line,
  20716. const char *text, int ret );
  20717. /**
  20718. * \brief Output a buffer of size len bytes to the debug output. This function
  20719. * is always used through the MBEDTLS_SSL_DEBUG_BUF() macro,
  20720. * which supplies the ssl context, file and line number parameters.
  20721. *
  20722. * \param ssl SSL context
  20723. * \param level error level of the debug message
  20724. * \param file file the error has occurred in
  20725. * \param line line number the error has occurred in
  20726. * \param text a name or label for the buffer being dumped. Normally the
  20727. * variable or buffer name
  20728. * \param buf the buffer to be outputted
  20729. * \param len length of the buffer
  20730. *
  20731. * \attention This function is intended for INTERNAL usage within the
  20732. * library only.
  20733. */
  20734. void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
  20735. const char *file, int line, const char *text,
  20736. const unsigned char *buf, size_t len );
  20737. #if defined(MBEDTLS_BIGNUM_C)
  20738. /**
  20739. * \brief Print a MPI variable to the debug output. This function is always
  20740. * used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the
  20741. * ssl context, file and line number parameters.
  20742. *
  20743. * \param ssl SSL context
  20744. * \param level error level of the debug message
  20745. * \param file file the error has occurred in
  20746. * \param line line number the error has occurred in
  20747. * \param text a name or label for the MPI being output. Normally the
  20748. * variable name
  20749. * \param X the MPI variable
  20750. *
  20751. * \attention This function is intended for INTERNAL usage within the
  20752. * library only.
  20753. */
  20754. void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
  20755. const char *file, int line,
  20756. const char *text, const mbedtls_mpi *X );
  20757. #endif
  20758. #if defined(MBEDTLS_ECP_C)
  20759. /**
  20760. * \brief Print an ECP point to the debug output. This function is always
  20761. * used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the
  20762. * ssl context, file and line number parameters.
  20763. *
  20764. * \param ssl SSL context
  20765. * \param level error level of the debug message
  20766. * \param file file the error has occurred in
  20767. * \param line line number the error has occurred in
  20768. * \param text a name or label for the ECP point being output. Normally the
  20769. * variable name
  20770. * \param X the ECP point
  20771. *
  20772. * \attention This function is intended for INTERNAL usage within the
  20773. * library only.
  20774. */
  20775. void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level,
  20776. const char *file, int line,
  20777. const char *text, const mbedtls_ecp_point *X );
  20778. #endif
  20779. #if defined(MBEDTLS_X509_CRT_PARSE_C)
  20780. /**
  20781. * \brief Print a X.509 certificate structure to the debug output. This
  20782. * function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro,
  20783. * which supplies the ssl context, file and line number parameters.
  20784. *
  20785. * \param ssl SSL context
  20786. * \param level error level of the debug message
  20787. * \param file file the error has occurred in
  20788. * \param line line number the error has occurred in
  20789. * \param text a name or label for the certificate being output
  20790. * \param crt X.509 certificate structure
  20791. *
  20792. * \attention This function is intended for INTERNAL usage within the
  20793. * library only.
  20794. */
  20795. void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
  20796. const char *file, int line,
  20797. const char *text, const mbedtls_x509_crt *crt );
  20798. #endif
  20799. #ifdef __cplusplus
  20800. }
  20801. #endif
  20802. #endif /* debug.h */
  20803. /********* Start of file include/mbedtls/blowfish.h ************/
  20804. /**
  20805. * \file blowfish.h
  20806. *
  20807. * \brief Blowfish block cipher
  20808. */
  20809. /*
  20810. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  20811. * SPDX-License-Identifier: Apache-2.0
  20812. *
  20813. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  20814. * not use this file except in compliance with the License.
  20815. * You may obtain a copy of the License at
  20816. *
  20817. * http://www.apache.org/licenses/LICENSE-2.0
  20818. *
  20819. * Unless required by applicable law or agreed to in writing, software
  20820. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  20821. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20822. * See the License for the specific language governing permissions and
  20823. * limitations under the License.
  20824. *
  20825. * This file is part of mbed TLS (https://tls.mbed.org)
  20826. */
  20827. #ifndef MBEDTLS_BLOWFISH_H
  20828. #define MBEDTLS_BLOWFISH_H
  20829. #if !defined(MBEDTLS_CONFIG_FILE)
  20830. #else
  20831. #endif
  20832. #include <stddef.h>
  20833. #include <stdint.h>
  20834. #define MBEDTLS_BLOWFISH_ENCRYPT 1
  20835. #define MBEDTLS_BLOWFISH_DECRYPT 0
  20836. #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
  20837. #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
  20838. #define MBEDTLS_BLOWFISH_ROUNDS 16 /**< Rounds to use. When increasing this value, make sure to extend the initialisation vectors */
  20839. #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
  20840. #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016 /**< Invalid key length. */
  20841. #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017 /**< Blowfish hardware accelerator failed. */
  20842. #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */
  20843. #if !defined(MBEDTLS_BLOWFISH_ALT)
  20844. // Regular implementation
  20845. //
  20846. #ifdef __cplusplus
  20847. extern "C" {
  20848. #endif
  20849. /**
  20850. * \brief Blowfish context structure
  20851. */
  20852. typedef struct
  20853. {
  20854. uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */
  20855. uint32_t S[4][256]; /*!< key dependent S-boxes */
  20856. }
  20857. mbedtls_blowfish_context;
  20858. /**
  20859. * \brief Initialize Blowfish context
  20860. *
  20861. * \param ctx Blowfish context to be initialized
  20862. */
  20863. void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx );
  20864. /**
  20865. * \brief Clear Blowfish context
  20866. *
  20867. * \param ctx Blowfish context to be cleared
  20868. */
  20869. void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx );
  20870. /**
  20871. * \brief Blowfish key schedule
  20872. *
  20873. * \param ctx Blowfish context to be initialized
  20874. * \param key encryption key
  20875. * \param keybits must be between 32 and 448 bits
  20876. *
  20877. * \return 0 if successful, or MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH
  20878. */
  20879. int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
  20880. unsigned int keybits );
  20881. /**
  20882. * \brief Blowfish-ECB block encryption/decryption
  20883. *
  20884. * \param ctx Blowfish context
  20885. * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT
  20886. * \param input 8-byte input block
  20887. * \param output 8-byte output block
  20888. *
  20889. * \return 0 if successful
  20890. */
  20891. int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx,
  20892. int mode,
  20893. const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
  20894. unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
  20895. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  20896. /**
  20897. * \brief Blowfish-CBC buffer encryption/decryption
  20898. * Length should be a multiple of the block
  20899. * size (8 bytes)
  20900. *
  20901. * \note Upon exit, the content of the IV is updated so that you can
  20902. * call the function same function again on the following
  20903. * block(s) of data and get the same result as if it was
  20904. * encrypted in one call. This allows a "streaming" usage.
  20905. * If on the other hand you need to retain the contents of the
  20906. * IV, you should either save it manually or use the cipher
  20907. * module instead.
  20908. *
  20909. * \param ctx Blowfish context
  20910. * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT
  20911. * \param length length of the input data
  20912. * \param iv initialization vector (updated after use)
  20913. * \param input buffer holding the input data
  20914. * \param output buffer holding the output data
  20915. *
  20916. * \return 0 if successful, or
  20917. * MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH
  20918. */
  20919. int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
  20920. int mode,
  20921. size_t length,
  20922. unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
  20923. const unsigned char *input,
  20924. unsigned char *output );
  20925. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  20926. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  20927. /**
  20928. * \brief Blowfish CFB buffer encryption/decryption.
  20929. *
  20930. * \note Upon exit, the content of the IV is updated so that you can
  20931. * call the function same function again on the following
  20932. * block(s) of data and get the same result as if it was
  20933. * encrypted in one call. This allows a "streaming" usage.
  20934. * If on the other hand you need to retain the contents of the
  20935. * IV, you should either save it manually or use the cipher
  20936. * module instead.
  20937. *
  20938. * \param ctx Blowfish context
  20939. * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT
  20940. * \param length length of the input data
  20941. * \param iv_off offset in IV (updated after use)
  20942. * \param iv initialization vector (updated after use)
  20943. * \param input buffer holding the input data
  20944. * \param output buffer holding the output data
  20945. *
  20946. * \return 0 if successful
  20947. */
  20948. int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
  20949. int mode,
  20950. size_t length,
  20951. size_t *iv_off,
  20952. unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
  20953. const unsigned char *input,
  20954. unsigned char *output );
  20955. #endif /*MBEDTLS_CIPHER_MODE_CFB */
  20956. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  20957. /**
  20958. * \brief Blowfish-CTR buffer encryption/decryption
  20959. *
  20960. * Warning: You have to keep the maximum use of your counter in mind!
  20961. *
  20962. * \param ctx Blowfish context
  20963. * \param length The length of the data
  20964. * \param nc_off The offset in the current stream_block (for resuming
  20965. * within current cipher stream). The offset pointer to
  20966. * should be 0 at the start of a stream.
  20967. * \param nonce_counter The 64-bit nonce and counter.
  20968. * \param stream_block The saved stream-block for resuming. Is overwritten
  20969. * by the function.
  20970. * \param input The input data stream
  20971. * \param output The output data stream
  20972. *
  20973. * \return 0 if successful
  20974. */
  20975. int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
  20976. size_t length,
  20977. size_t *nc_off,
  20978. unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
  20979. unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
  20980. const unsigned char *input,
  20981. unsigned char *output );
  20982. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  20983. #ifdef __cplusplus
  20984. }
  20985. #endif
  20986. #else /* MBEDTLS_BLOWFISH_ALT */
  20987. #endif /* MBEDTLS_BLOWFISH_ALT */
  20988. #endif /* blowfish.h */
  20989. /********* Start of file include/mbedtls/ccm.h ************/
  20990. /**
  20991. * \file ccm.h
  20992. *
  20993. * \brief CCM combines Counter mode encryption with CBC-MAC authentication
  20994. * for 128-bit block ciphers.
  20995. *
  20996. * Input to CCM includes the following elements:
  20997. * <ul><li>Payload - data that is both authenticated and encrypted.</li>
  20998. * <li>Associated data (Adata) - data that is authenticated but not
  20999. * encrypted, For example, a header.</li>
  21000. * <li>Nonce - A unique value that is assigned to the payload and the
  21001. * associated data.</li></ul>
  21002. *
  21003. */
  21004. /*
  21005. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  21006. * SPDX-License-Identifier: Apache-2.0
  21007. *
  21008. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  21009. * not use this file except in compliance with the License.
  21010. * You may obtain a copy of the License at
  21011. *
  21012. * http://www.apache.org/licenses/LICENSE-2.0
  21013. *
  21014. * Unless required by applicable law or agreed to in writing, software
  21015. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21016. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21017. * See the License for the specific language governing permissions and
  21018. * limitations under the License.
  21019. *
  21020. * This file is part of Mbed TLS (https://tls.mbed.org)
  21021. */
  21022. #ifndef MBEDTLS_CCM_H
  21023. #define MBEDTLS_CCM_H
  21024. #define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to the function. */
  21025. #define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */
  21026. #define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 /**< CCM hardware accelerator failed. */
  21027. #if !defined(MBEDTLS_CCM_ALT)
  21028. // Regular implementation
  21029. //
  21030. #ifdef __cplusplus
  21031. extern "C" {
  21032. #endif
  21033. /**
  21034. * \brief The CCM context-type definition. The CCM context is passed
  21035. * to the APIs called.
  21036. */
  21037. typedef struct {
  21038. mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
  21039. }
  21040. mbedtls_ccm_context;
  21041. /**
  21042. * \brief This function initializes the specified CCM context,
  21043. * to make references valid, and prepare the context
  21044. * for mbedtls_ccm_setkey() or mbedtls_ccm_free().
  21045. *
  21046. * \param ctx The CCM context to initialize.
  21047. */
  21048. void mbedtls_ccm_init( mbedtls_ccm_context *ctx );
  21049. /**
  21050. * \brief This function initializes the CCM context set in the
  21051. * \p ctx parameter and sets the encryption key.
  21052. *
  21053. * \param ctx The CCM context to initialize.
  21054. * \param cipher The 128-bit block cipher to use.
  21055. * \param key The encryption key.
  21056. * \param keybits The key size in bits. This must be acceptable by the cipher.
  21057. *
  21058. * \return \c 0 on success, or a cipher-specific error code.
  21059. */
  21060. int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
  21061. mbedtls_cipher_id_t cipher,
  21062. const unsigned char *key,
  21063. unsigned int keybits );
  21064. /**
  21065. * \brief This function releases and clears the specified CCM context
  21066. * and underlying cipher sub-context.
  21067. *
  21068. * \param ctx The CCM context to clear.
  21069. */
  21070. void mbedtls_ccm_free( mbedtls_ccm_context *ctx );
  21071. /**
  21072. * \brief This function encrypts a buffer using CCM.
  21073. *
  21074. * \param ctx The CCM context to use for encryption.
  21075. * \param length The length of the input data in Bytes.
  21076. * \param iv Initialization vector (nonce).
  21077. * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13.
  21078. * \param add The additional data field.
  21079. * \param add_len The length of additional data in Bytes.
  21080. * Must be less than 2^16 - 2^8.
  21081. * \param input The buffer holding the input data.
  21082. * \param output The buffer holding the output data.
  21083. * Must be at least \p length Bytes wide.
  21084. * \param tag The buffer holding the tag.
  21085. * \param tag_len The length of the tag to generate in Bytes:
  21086. * 4, 6, 8, 10, 12, 14 or 16.
  21087. *
  21088. * \note The tag is written to a separate buffer. To concatenate
  21089. * the \p tag with the \p output, as done in <em>RFC-3610:
  21090. * Counter with CBC-MAC (CCM)</em>, use
  21091. * \p tag = \p output + \p length, and make sure that the
  21092. * output buffer is at least \p length + \p tag_len wide.
  21093. *
  21094. * \return \c 0 on success.
  21095. */
  21096. int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length,
  21097. const unsigned char *iv, size_t iv_len,
  21098. const unsigned char *add, size_t add_len,
  21099. const unsigned char *input, unsigned char *output,
  21100. unsigned char *tag, size_t tag_len );
  21101. /**
  21102. * \brief This function performs a CCM authenticated decryption of a
  21103. * buffer.
  21104. *
  21105. * \param ctx The CCM context to use for decryption.
  21106. * \param length The length of the input data in Bytes.
  21107. * \param iv Initialization vector.
  21108. * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13.
  21109. * \param add The additional data field.
  21110. * \param add_len The length of additional data in Bytes.
  21111. * Must be less than 2^16 - 2^8.
  21112. * \param input The buffer holding the input data.
  21113. * \param output The buffer holding the output data.
  21114. * Must be at least \p length Bytes wide.
  21115. * \param tag The buffer holding the tag.
  21116. * \param tag_len The length of the tag in Bytes.
  21117. * 4, 6, 8, 10, 12, 14 or 16.
  21118. *
  21119. * \return 0 if successful and authenticated, or
  21120. * #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match.
  21121. */
  21122. int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length,
  21123. const unsigned char *iv, size_t iv_len,
  21124. const unsigned char *add, size_t add_len,
  21125. const unsigned char *input, unsigned char *output,
  21126. const unsigned char *tag, size_t tag_len );
  21127. #ifdef __cplusplus
  21128. }
  21129. #endif
  21130. #else /* MBEDTLS_CCM_ALT */
  21131. #endif /* MBEDTLS_CCM_ALT */
  21132. #ifdef __cplusplus
  21133. extern "C" {
  21134. #endif
  21135. #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C)
  21136. /**
  21137. * \brief The CCM checkup routine.
  21138. *
  21139. * \return \c 0 on success, or \c 1 on failure.
  21140. */
  21141. int mbedtls_ccm_self_test( int verbose );
  21142. #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */
  21143. #ifdef __cplusplus
  21144. }
  21145. #endif
  21146. #endif /* MBEDTLS_CCM_H */
  21147. /********* Start of file include/mbedtls/gcm.h ************/
  21148. /**
  21149. * \file gcm.h
  21150. *
  21151. * \brief Galois/Counter Mode (GCM) for 128-bit block ciphers, as defined
  21152. * in <em>D. McGrew, J. Viega, The Galois/Counter Mode of Operation
  21153. * (GCM), Natl. Inst. Stand. Technol.</em>
  21154. *
  21155. * For more information on GCM, see <em>NIST SP 800-38D: Recommendation for
  21156. * Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC</em>.
  21157. *
  21158. */
  21159. /*
  21160. * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
  21161. * SPDX-License-Identifier: Apache-2.0
  21162. *
  21163. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  21164. * not use this file except in compliance with the License.
  21165. * You may obtain a copy of the License at
  21166. *
  21167. * http://www.apache.org/licenses/LICENSE-2.0
  21168. *
  21169. * Unless required by applicable law or agreed to in writing, software
  21170. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21171. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21172. * See the License for the specific language governing permissions and
  21173. * limitations under the License.
  21174. *
  21175. * This file is part of Mbed TLS (https://tls.mbed.org)
  21176. */
  21177. #ifndef MBEDTLS_GCM_H
  21178. #define MBEDTLS_GCM_H
  21179. #include <stdint.h>
  21180. #define MBEDTLS_GCM_ENCRYPT 1
  21181. #define MBEDTLS_GCM_DECRYPT 0
  21182. #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012 /**< Authenticated decryption failed. */
  21183. #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013 /**< GCM hardware accelerator failed. */
  21184. #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 /**< Bad input parameters to function. */
  21185. #if !defined(MBEDTLS_GCM_ALT)
  21186. #ifdef __cplusplus
  21187. extern "C" {
  21188. #endif
  21189. /**
  21190. * \brief The GCM context structure.
  21191. */
  21192. typedef struct {
  21193. mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */
  21194. uint64_t HL[16]; /*!< Precalculated HTable low. */
  21195. uint64_t HH[16]; /*!< Precalculated HTable high. */
  21196. uint64_t len; /*!< The total length of the encrypted data. */
  21197. uint64_t add_len; /*!< The total length of the additional data. */
  21198. unsigned char base_ectr[16]; /*!< The first ECTR for tag. */
  21199. unsigned char y[16]; /*!< The Y working value. */
  21200. unsigned char buf[16]; /*!< The buf working value. */
  21201. int mode; /*!< The operation to perform:
  21202. #MBEDTLS_GCM_ENCRYPT or
  21203. #MBEDTLS_GCM_DECRYPT. */
  21204. }
  21205. mbedtls_gcm_context;
  21206. /**
  21207. * \brief This function initializes the specified GCM context,
  21208. * to make references valid, and prepares the context
  21209. * for mbedtls_gcm_setkey() or mbedtls_gcm_free().
  21210. *
  21211. * The function does not bind the GCM context to a particular
  21212. * cipher, nor set the key. For this purpose, use
  21213. * mbedtls_gcm_setkey().
  21214. *
  21215. * \param ctx The GCM context to initialize.
  21216. */
  21217. void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
  21218. /**
  21219. * \brief This function associates a GCM context with a
  21220. * cipher algorithm and a key.
  21221. *
  21222. * \param ctx The GCM context to initialize.
  21223. * \param cipher The 128-bit block cipher to use.
  21224. * \param key The encryption key.
  21225. * \param keybits The key size in bits. Valid options are:
  21226. * <ul><li>128 bits</li>
  21227. * <li>192 bits</li>
  21228. * <li>256 bits</li></ul>
  21229. *
  21230. * \return \c 0 on success, or a cipher specific error code.
  21231. */
  21232. int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
  21233. mbedtls_cipher_id_t cipher,
  21234. const unsigned char *key,
  21235. unsigned int keybits );
  21236. /**
  21237. * \brief This function performs GCM encryption or decryption of a buffer.
  21238. *
  21239. * \note For encryption, the output buffer can be the same as the input buffer.
  21240. * For decryption, the output buffer cannot be the same as input buffer.
  21241. * If the buffers overlap, the output buffer must trail at least 8 Bytes
  21242. * behind the input buffer.
  21243. *
  21244. * \param ctx The GCM context to use for encryption or decryption.
  21245. * \param mode The operation to perform: #MBEDTLS_GCM_ENCRYPT or
  21246. * #MBEDTLS_GCM_DECRYPT.
  21247. * \param length The length of the input data. This must be a multiple of 16 except in the last call before mbedtls_gcm_finish().
  21248. * \param iv The initialization vector.
  21249. * \param iv_len The length of the IV.
  21250. * \param add The buffer holding the additional data.
  21251. * \param add_len The length of the additional data.
  21252. * \param input The buffer holding the input data.
  21253. * \param output The buffer for holding the output data.
  21254. * \param tag_len The length of the tag to generate.
  21255. * \param tag The buffer for holding the tag.
  21256. *
  21257. * \return \c 0 on success.
  21258. */
  21259. int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
  21260. int mode,
  21261. size_t length,
  21262. const unsigned char *iv,
  21263. size_t iv_len,
  21264. const unsigned char *add,
  21265. size_t add_len,
  21266. const unsigned char *input,
  21267. unsigned char *output,
  21268. size_t tag_len,
  21269. unsigned char *tag );
  21270. /**
  21271. * \brief This function performs a GCM authenticated decryption of a
  21272. * buffer.
  21273. *
  21274. * \note For decryption, the output buffer cannot be the same as input buffer.
  21275. * If the buffers overlap, the output buffer must trail at least 8 Bytes
  21276. * behind the input buffer.
  21277. *
  21278. * \param ctx The GCM context.
  21279. * \param length The length of the input data. This must be a multiple of 16 except in the last call before mbedtls_gcm_finish().
  21280. * \param iv The initialization vector.
  21281. * \param iv_len The length of the IV.
  21282. * \param add The buffer holding the additional data.
  21283. * \param add_len The length of the additional data.
  21284. * \param tag The buffer holding the tag.
  21285. * \param tag_len The length of the tag.
  21286. * \param input The buffer holding the input data.
  21287. * \param output The buffer for holding the output data.
  21288. *
  21289. * \return 0 if successful and authenticated, or
  21290. * #MBEDTLS_ERR_GCM_AUTH_FAILED if tag does not match.
  21291. */
  21292. int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
  21293. size_t length,
  21294. const unsigned char *iv,
  21295. size_t iv_len,
  21296. const unsigned char *add,
  21297. size_t add_len,
  21298. const unsigned char *tag,
  21299. size_t tag_len,
  21300. const unsigned char *input,
  21301. unsigned char *output );
  21302. /**
  21303. * \brief This function starts a GCM encryption or decryption
  21304. * operation.
  21305. *
  21306. * \param ctx The GCM context.
  21307. * \param mode The operation to perform: #MBEDTLS_GCM_ENCRYPT or
  21308. * #MBEDTLS_GCM_DECRYPT.
  21309. * \param iv The initialization vector.
  21310. * \param iv_len The length of the IV.
  21311. * \param add The buffer holding the additional data, or NULL if \p add_len is 0.
  21312. * \param add_len The length of the additional data. If 0, \p add is NULL.
  21313. *
  21314. * \return \c 0 on success.
  21315. */
  21316. int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
  21317. int mode,
  21318. const unsigned char *iv,
  21319. size_t iv_len,
  21320. const unsigned char *add,
  21321. size_t add_len );
  21322. /**
  21323. * \brief This function feeds an input buffer into an ongoing GCM
  21324. * encryption or decryption operation.
  21325. *
  21326. * ` The function expects input to be a multiple of 16
  21327. * Bytes. Only the last call before calling
  21328. * mbedtls_gcm_finish() can be less than 16 Bytes.
  21329. *
  21330. * \note For decryption, the output buffer cannot be the same as input buffer.
  21331. * If the buffers overlap, the output buffer must trail at least 8 Bytes
  21332. * behind the input buffer.
  21333. *
  21334. * \param ctx The GCM context.
  21335. * \param length The length of the input data. This must be a multiple of 16 except in the last call before mbedtls_gcm_finish().
  21336. * \param input The buffer holding the input data.
  21337. * \param output The buffer for holding the output data.
  21338. *
  21339. * \return \c 0 on success, or #MBEDTLS_ERR_GCM_BAD_INPUT on failure.
  21340. */
  21341. int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
  21342. size_t length,
  21343. const unsigned char *input,
  21344. unsigned char *output );
  21345. /**
  21346. * \brief This function finishes the GCM operation and generates
  21347. * the authentication tag.
  21348. *
  21349. * It wraps up the GCM stream, and generates the
  21350. * tag. The tag can have a maximum length of 16 Bytes.
  21351. *
  21352. * \param ctx The GCM context.
  21353. * \param tag The buffer for holding the tag.
  21354. * \param tag_len The length of the tag to generate. Must be at least four.
  21355. *
  21356. * \return \c 0 on success, or #MBEDTLS_ERR_GCM_BAD_INPUT on failure.
  21357. */
  21358. int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
  21359. unsigned char *tag,
  21360. size_t tag_len );
  21361. /**
  21362. * \brief This function clears a GCM context and the underlying
  21363. * cipher sub-context.
  21364. *
  21365. * \param ctx The GCM context to clear.
  21366. */
  21367. void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
  21368. #ifdef __cplusplus
  21369. }
  21370. #endif
  21371. #else /* !MBEDTLS_GCM_ALT */
  21372. #endif /* !MBEDTLS_GCM_ALT */
  21373. #ifdef __cplusplus
  21374. extern "C" {
  21375. #endif
  21376. /**
  21377. * \brief The GCM checkup routine.
  21378. *
  21379. * \return \c 0 on success, or \c 1 on failure.
  21380. */
  21381. int mbedtls_gcm_self_test( int verbose );
  21382. #ifdef __cplusplus
  21383. }
  21384. #endif
  21385. #endif /* gcm.h */
  21386. /********* Start of file include/mbedtls/pem.h ************/
  21387. /**
  21388. * \file pem.h
  21389. *
  21390. * \brief Privacy Enhanced Mail (PEM) decoding
  21391. */
  21392. /*
  21393. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  21394. * SPDX-License-Identifier: Apache-2.0
  21395. *
  21396. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  21397. * not use this file except in compliance with the License.
  21398. * You may obtain a copy of the License at
  21399. *
  21400. * http://www.apache.org/licenses/LICENSE-2.0
  21401. *
  21402. * Unless required by applicable law or agreed to in writing, software
  21403. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21404. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21405. * See the License for the specific language governing permissions and
  21406. * limitations under the License.
  21407. *
  21408. * This file is part of mbed TLS (https://tls.mbed.org)
  21409. */
  21410. #ifndef MBEDTLS_PEM_H
  21411. #define MBEDTLS_PEM_H
  21412. #include <stddef.h>
  21413. /**
  21414. * \name PEM Error codes
  21415. * These error codes are returned in case of errors reading the
  21416. * PEM data.
  21417. * \{
  21418. */
  21419. #define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080 /**< No PEM header or footer found. */
  21420. #define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100 /**< PEM string is not as expected. */
  21421. #define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180 /**< Failed to allocate memory. */
  21422. #define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */
  21423. #define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */
  21424. #define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */
  21425. #define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */
  21426. #define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */
  21427. #define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */
  21428. /* \} name */
  21429. #ifdef __cplusplus
  21430. extern "C" {
  21431. #endif
  21432. #if defined(MBEDTLS_PEM_PARSE_C)
  21433. /**
  21434. * \brief PEM context structure
  21435. */
  21436. typedef struct
  21437. {
  21438. unsigned char *buf; /*!< buffer for decoded data */
  21439. size_t buflen; /*!< length of the buffer */
  21440. unsigned char *info; /*!< buffer for extra header information */
  21441. }
  21442. mbedtls_pem_context;
  21443. /**
  21444. * \brief PEM context setup
  21445. *
  21446. * \param ctx context to be initialized
  21447. */
  21448. void mbedtls_pem_init( mbedtls_pem_context *ctx );
  21449. /**
  21450. * \brief Read a buffer for PEM information and store the resulting
  21451. * data into the specified context buffers.
  21452. *
  21453. * \param ctx context to use
  21454. * \param header header string to seek and expect
  21455. * \param footer footer string to seek and expect
  21456. * \param data source data to look in (must be nul-terminated)
  21457. * \param pwd password for decryption (can be NULL)
  21458. * \param pwdlen length of password
  21459. * \param use_len destination for total length used (set after header is
  21460. * correctly read, so unless you get
  21461. * MBEDTLS_ERR_PEM_BAD_INPUT_DATA or
  21462. * MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is
  21463. * the length to skip)
  21464. *
  21465. * \note Attempts to check password correctness by verifying if
  21466. * the decrypted text starts with an ASN.1 sequence of
  21467. * appropriate length
  21468. *
  21469. * \return 0 on success, or a specific PEM error code
  21470. */
  21471. int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer,
  21472. const unsigned char *data,
  21473. const unsigned char *pwd,
  21474. size_t pwdlen, size_t *use_len );
  21475. /**
  21476. * \brief PEM context memory freeing
  21477. *
  21478. * \param ctx context to be freed
  21479. */
  21480. void mbedtls_pem_free( mbedtls_pem_context *ctx );
  21481. #endif /* MBEDTLS_PEM_PARSE_C */
  21482. #if defined(MBEDTLS_PEM_WRITE_C)
  21483. /**
  21484. * \brief Write a buffer of PEM information from a DER encoded
  21485. * buffer.
  21486. *
  21487. * \param header header string to write
  21488. * \param footer footer string to write
  21489. * \param der_data DER data to write
  21490. * \param der_len length of the DER data
  21491. * \param buf buffer to write to
  21492. * \param buf_len length of output buffer
  21493. * \param olen total length written / required (if buf_len is not enough)
  21494. *
  21495. * \return 0 on success, or a specific PEM or BASE64 error code. On
  21496. * MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL olen is the required
  21497. * size.
  21498. */
  21499. int mbedtls_pem_write_buffer( const char *header, const char *footer,
  21500. const unsigned char *der_data, size_t der_len,
  21501. unsigned char *buf, size_t buf_len, size_t *olen );
  21502. #endif /* MBEDTLS_PEM_WRITE_C */
  21503. #ifdef __cplusplus
  21504. }
  21505. #endif
  21506. #endif /* pem.h */
  21507. /********* Start of file include/mbedtls/asn1write.h ************/
  21508. /**
  21509. * \file asn1write.h
  21510. *
  21511. * \brief ASN.1 buffer writing functionality
  21512. */
  21513. /*
  21514. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  21515. * SPDX-License-Identifier: Apache-2.0
  21516. *
  21517. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  21518. * not use this file except in compliance with the License.
  21519. * You may obtain a copy of the License at
  21520. *
  21521. * http://www.apache.org/licenses/LICENSE-2.0
  21522. *
  21523. * Unless required by applicable law or agreed to in writing, software
  21524. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21525. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21526. * See the License for the specific language governing permissions and
  21527. * limitations under the License.
  21528. *
  21529. * This file is part of mbed TLS (https://tls.mbed.org)
  21530. */
  21531. #ifndef MBEDTLS_ASN1_WRITE_H
  21532. #define MBEDTLS_ASN1_WRITE_H
  21533. #define MBEDTLS_ASN1_CHK_ADD(g, f) do { if( ( ret = f ) < 0 ) return( ret ); else \
  21534. g += ret; } while( 0 )
  21535. #ifdef __cplusplus
  21536. extern "C" {
  21537. #endif
  21538. /**
  21539. * \brief Write a length field in ASN.1 format
  21540. * Note: function works backwards in data buffer
  21541. *
  21542. * \param p reference to current position pointer
  21543. * \param start start of the buffer (for bounds-checking)
  21544. * \param len the length to write
  21545. *
  21546. * \return the length written or a negative error code
  21547. */
  21548. int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len );
  21549. /**
  21550. * \brief Write a ASN.1 tag in ASN.1 format
  21551. * Note: function works backwards in data buffer
  21552. *
  21553. * \param p reference to current position pointer
  21554. * \param start start of the buffer (for bounds-checking)
  21555. * \param tag the tag to write
  21556. *
  21557. * \return the length written or a negative error code
  21558. */
  21559. int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start,
  21560. unsigned char tag );
  21561. /**
  21562. * \brief Write raw buffer data
  21563. * Note: function works backwards in data buffer
  21564. *
  21565. * \param p reference to current position pointer
  21566. * \param start start of the buffer (for bounds-checking)
  21567. * \param buf data buffer to write
  21568. * \param size length of the data buffer
  21569. *
  21570. * \return the length written or a negative error code
  21571. */
  21572. int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start,
  21573. const unsigned char *buf, size_t size );
  21574. #if defined(MBEDTLS_BIGNUM_C)
  21575. /**
  21576. * \brief Write a big number (MBEDTLS_ASN1_INTEGER) in ASN.1 format
  21577. * Note: function works backwards in data buffer
  21578. *
  21579. * \param p reference to current position pointer
  21580. * \param start start of the buffer (for bounds-checking)
  21581. * \param X the MPI to write
  21582. *
  21583. * \return the length written or a negative error code
  21584. */
  21585. int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedtls_mpi *X );
  21586. #endif /* MBEDTLS_BIGNUM_C */
  21587. /**
  21588. * \brief Write a NULL tag (MBEDTLS_ASN1_NULL) with zero data in ASN.1 format
  21589. * Note: function works backwards in data buffer
  21590. *
  21591. * \param p reference to current position pointer
  21592. * \param start start of the buffer (for bounds-checking)
  21593. *
  21594. * \return the length written or a negative error code
  21595. */
  21596. int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start );
  21597. /**
  21598. * \brief Write an OID tag (MBEDTLS_ASN1_OID) and data in ASN.1 format
  21599. * Note: function works backwards in data buffer
  21600. *
  21601. * \param p reference to current position pointer
  21602. * \param start start of the buffer (for bounds-checking)
  21603. * \param oid the OID to write
  21604. * \param oid_len length of the OID
  21605. *
  21606. * \return the length written or a negative error code
  21607. */
  21608. int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start,
  21609. const char *oid, size_t oid_len );
  21610. /**
  21611. * \brief Write an AlgorithmIdentifier sequence in ASN.1 format
  21612. * Note: function works backwards in data buffer
  21613. *
  21614. * \param p reference to current position pointer
  21615. * \param start start of the buffer (for bounds-checking)
  21616. * \param oid the OID of the algorithm
  21617. * \param oid_len length of the OID
  21618. * \param par_len length of parameters, which must be already written.
  21619. * If 0, NULL parameters are added
  21620. *
  21621. * \return the length written or a negative error code
  21622. */
  21623. int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start,
  21624. const char *oid, size_t oid_len,
  21625. size_t par_len );
  21626. /**
  21627. * \brief Write a boolean tag (MBEDTLS_ASN1_BOOLEAN) and value in ASN.1 format
  21628. * Note: function works backwards in data buffer
  21629. *
  21630. * \param p reference to current position pointer
  21631. * \param start start of the buffer (for bounds-checking)
  21632. * \param boolean 0 or 1
  21633. *
  21634. * \return the length written or a negative error code
  21635. */
  21636. int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, int boolean );
  21637. /**
  21638. * \brief Write an int tag (MBEDTLS_ASN1_INTEGER) and value in ASN.1 format
  21639. * Note: function works backwards in data buffer
  21640. *
  21641. * \param p reference to current position pointer
  21642. * \param start start of the buffer (for bounds-checking)
  21643. * \param val the integer value
  21644. *
  21645. * \return the length written or a negative error code
  21646. */
  21647. int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val );
  21648. /**
  21649. * \brief Write a printable string tag (MBEDTLS_ASN1_PRINTABLE_STRING) and
  21650. * value in ASN.1 format
  21651. * Note: function works backwards in data buffer
  21652. *
  21653. * \param p reference to current position pointer
  21654. * \param start start of the buffer (for bounds-checking)
  21655. * \param text the text to write
  21656. * \param text_len length of the text
  21657. *
  21658. * \return the length written or a negative error code
  21659. */
  21660. int mbedtls_asn1_write_printable_string( unsigned char **p, unsigned char *start,
  21661. const char *text, size_t text_len );
  21662. /**
  21663. * \brief Write an IA5 string tag (MBEDTLS_ASN1_IA5_STRING) and
  21664. * value in ASN.1 format
  21665. * Note: function works backwards in data buffer
  21666. *
  21667. * \param p reference to current position pointer
  21668. * \param start start of the buffer (for bounds-checking)
  21669. * \param text the text to write
  21670. * \param text_len length of the text
  21671. *
  21672. * \return the length written or a negative error code
  21673. */
  21674. int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start,
  21675. const char *text, size_t text_len );
  21676. /**
  21677. * \brief Write a bitstring tag (MBEDTLS_ASN1_BIT_STRING) and
  21678. * value in ASN.1 format
  21679. * Note: function works backwards in data buffer
  21680. *
  21681. * \param p reference to current position pointer
  21682. * \param start start of the buffer (for bounds-checking)
  21683. * \param buf the bitstring
  21684. * \param bits the total number of bits in the bitstring
  21685. *
  21686. * \return the length written or a negative error code
  21687. */
  21688. int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start,
  21689. const unsigned char *buf, size_t bits );
  21690. /**
  21691. * \brief Write an octet string tag (MBEDTLS_ASN1_OCTET_STRING) and
  21692. * value in ASN.1 format
  21693. * Note: function works backwards in data buffer
  21694. *
  21695. * \param p reference to current position pointer
  21696. * \param start start of the buffer (for bounds-checking)
  21697. * \param buf data buffer to write
  21698. * \param size length of the data buffer
  21699. *
  21700. * \return the length written or a negative error code
  21701. */
  21702. int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start,
  21703. const unsigned char *buf, size_t size );
  21704. /**
  21705. * \brief Create or find a specific named_data entry for writing in a
  21706. * sequence or list based on the OID. If not already in there,
  21707. * a new entry is added to the head of the list.
  21708. * Warning: Destructive behaviour for the val data!
  21709. *
  21710. * \param list Pointer to the location of the head of the list to seek
  21711. * through (will be updated in case of a new entry)
  21712. * \param oid The OID to look for
  21713. * \param oid_len Size of the OID
  21714. * \param val Data to store (can be NULL if you want to fill it by hand)
  21715. * \param val_len Minimum length of the data buffer needed
  21716. *
  21717. * \return NULL if if there was a memory allocation error, or a pointer
  21718. * to the new / existing entry.
  21719. */
  21720. mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **list,
  21721. const char *oid, size_t oid_len,
  21722. const unsigned char *val,
  21723. size_t val_len );
  21724. #ifdef __cplusplus
  21725. }
  21726. #endif
  21727. #endif /* MBEDTLS_ASN1_WRITE_H */
  21728. /********* Start of file include/mbedtls/hmac_drbg.h ************/
  21729. /**
  21730. * \file hmac_drbg.h
  21731. *
  21732. * \brief HMAC_DRBG (NIST SP 800-90A)
  21733. */
  21734. /*
  21735. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  21736. * SPDX-License-Identifier: Apache-2.0
  21737. *
  21738. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  21739. * not use this file except in compliance with the License.
  21740. * You may obtain a copy of the License at
  21741. *
  21742. * http://www.apache.org/licenses/LICENSE-2.0
  21743. *
  21744. * Unless required by applicable law or agreed to in writing, software
  21745. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  21746. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21747. * See the License for the specific language governing permissions and
  21748. * limitations under the License.
  21749. *
  21750. * This file is part of mbed TLS (https://tls.mbed.org)
  21751. */
  21752. #ifndef MBEDTLS_HMAC_DRBG_H
  21753. #define MBEDTLS_HMAC_DRBG_H
  21754. #if defined(MBEDTLS_THREADING_C)
  21755. #endif
  21756. /*
  21757. * Error codes
  21758. */
  21759. #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003 /**< Too many random requested in single call. */
  21760. #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005 /**< Input too large (Entropy + additional). */
  21761. #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007 /**< Read/write error in file. */
  21762. #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009 /**< The entropy source failed. */
  21763. /**
  21764. * \name SECTION: Module settings
  21765. *
  21766. * The configuration options you can set for this module are in this section.
  21767. * Either change them in config.h or define them on the compiler command line.
  21768. * \{
  21769. */
  21770. #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
  21771. #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
  21772. #endif
  21773. #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
  21774. #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
  21775. #endif
  21776. #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
  21777. #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
  21778. #endif
  21779. #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
  21780. #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
  21781. #endif
  21782. /* \} name SECTION: Module settings */
  21783. #define MBEDTLS_HMAC_DRBG_PR_OFF 0 /**< No prediction resistance */
  21784. #define MBEDTLS_HMAC_DRBG_PR_ON 1 /**< Prediction resistance enabled */
  21785. #ifdef __cplusplus
  21786. extern "C" {
  21787. #endif
  21788. /**
  21789. * HMAC_DRBG context.
  21790. */
  21791. typedef struct
  21792. {
  21793. /* Working state: the key K is not stored explicitely,
  21794. * but is implied by the HMAC context */
  21795. mbedtls_md_context_t md_ctx; /*!< HMAC context (inc. K) */
  21796. unsigned char V[MBEDTLS_MD_MAX_SIZE]; /*!< V in the spec */
  21797. int reseed_counter; /*!< reseed counter */
  21798. /* Administrative state */
  21799. size_t entropy_len; /*!< entropy bytes grabbed on each (re)seed */
  21800. int prediction_resistance; /*!< enable prediction resistance (Automatic
  21801. reseed before every random generation) */
  21802. int reseed_interval; /*!< reseed interval */
  21803. /* Callbacks */
  21804. int (*f_entropy)(void *, unsigned char *, size_t); /*!< entropy function */
  21805. void *p_entropy; /*!< context for the entropy function */
  21806. #if defined(MBEDTLS_THREADING_C)
  21807. mbedtls_threading_mutex_t mutex;
  21808. #endif
  21809. } mbedtls_hmac_drbg_context;
  21810. /**
  21811. * \brief HMAC_DRBG context initialization
  21812. * Makes the context ready for mbedtls_hmac_drbg_seed(),
  21813. * mbedtls_hmac_drbg_seed_buf() or
  21814. * mbedtls_hmac_drbg_free().
  21815. *
  21816. * \param ctx HMAC_DRBG context to be initialized
  21817. */
  21818. void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
  21819. /**
  21820. * \brief HMAC_DRBG initial seeding
  21821. * Seed and setup entropy source for future reseeds.
  21822. *
  21823. * \param ctx HMAC_DRBG context to be seeded
  21824. * \param md_info MD algorithm to use for HMAC_DRBG
  21825. * \param f_entropy Entropy callback (p_entropy, buffer to fill, buffer
  21826. * length)
  21827. * \param p_entropy Entropy context
  21828. * \param custom Personalization data (Device specific identifiers)
  21829. * (Can be NULL)
  21830. * \param len Length of personalization data
  21831. *
  21832. * \note The "security strength" as defined by NIST is set to:
  21833. * 128 bits if md_alg is SHA-1,
  21834. * 192 bits if md_alg is SHA-224,
  21835. * 256 bits if md_alg is SHA-256 or higher.
  21836. * Note that SHA-256 is just as efficient as SHA-224.
  21837. *
  21838. * \return 0 if successful, or
  21839. * MBEDTLS_ERR_MD_BAD_INPUT_DATA, or
  21840. * MBEDTLS_ERR_MD_ALLOC_FAILED, or
  21841. * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED.
  21842. */
  21843. int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
  21844. const mbedtls_md_info_t * md_info,
  21845. int (*f_entropy)(void *, unsigned char *, size_t),
  21846. void *p_entropy,
  21847. const unsigned char *custom,
  21848. size_t len );
  21849. /**
  21850. * \brief Initilisation of simpified HMAC_DRBG (never reseeds).
  21851. * (For use with deterministic ECDSA.)
  21852. *
  21853. * \param ctx HMAC_DRBG context to be initialised
  21854. * \param md_info MD algorithm to use for HMAC_DRBG
  21855. * \param data Concatenation of entropy string and additional data
  21856. * \param data_len Length of data in bytes
  21857. *
  21858. * \return 0 if successful, or
  21859. * MBEDTLS_ERR_MD_BAD_INPUT_DATA, or
  21860. * MBEDTLS_ERR_MD_ALLOC_FAILED.
  21861. */
  21862. int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
  21863. const mbedtls_md_info_t * md_info,
  21864. const unsigned char *data, size_t data_len );
  21865. /**
  21866. * \brief Enable / disable prediction resistance (Default: Off)
  21867. *
  21868. * Note: If enabled, entropy is used for ctx->entropy_len before each call!
  21869. * Only use this if you have ample supply of good entropy!
  21870. *
  21871. * \param ctx HMAC_DRBG context
  21872. * \param resistance MBEDTLS_HMAC_DRBG_PR_ON or MBEDTLS_HMAC_DRBG_PR_OFF
  21873. */
  21874. void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
  21875. int resistance );
  21876. /**
  21877. * \brief Set the amount of entropy grabbed on each reseed
  21878. * (Default: given by the security strength, which
  21879. * depends on the hash used, see \c mbedtls_hmac_drbg_init() )
  21880. *
  21881. * \param ctx HMAC_DRBG context
  21882. * \param len Amount of entropy to grab, in bytes
  21883. */
  21884. void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
  21885. size_t len );
  21886. /**
  21887. * \brief Set the reseed interval
  21888. * (Default: MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
  21889. *
  21890. * \param ctx HMAC_DRBG context
  21891. * \param interval Reseed interval
  21892. */
  21893. void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
  21894. int interval );
  21895. /**
  21896. * \brief HMAC_DRBG update state
  21897. *
  21898. * \param ctx HMAC_DRBG context
  21899. * \param additional Additional data to update state with, or NULL
  21900. * \param add_len Length of additional data, or 0
  21901. *
  21902. * \note Additional data is optional, pass NULL and 0 as second
  21903. * third argument if no additional data is being used.
  21904. */
  21905. void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
  21906. const unsigned char *additional, size_t add_len );
  21907. /**
  21908. * \brief HMAC_DRBG reseeding (extracts data from entropy source)
  21909. *
  21910. * \param ctx HMAC_DRBG context
  21911. * \param additional Additional data to add to state (Can be NULL)
  21912. * \param len Length of additional data
  21913. *
  21914. * \return 0 if successful, or
  21915. * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
  21916. */
  21917. int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
  21918. const unsigned char *additional, size_t len );
  21919. /**
  21920. * \brief HMAC_DRBG generate random with additional update input
  21921. *
  21922. * Note: Automatically reseeds if reseed_counter is reached or PR is enabled.
  21923. *
  21924. * \param p_rng HMAC_DRBG context
  21925. * \param output Buffer to fill
  21926. * \param output_len Length of the buffer
  21927. * \param additional Additional data to update with (can be NULL)
  21928. * \param add_len Length of additional data (can be 0)
  21929. *
  21930. * \return 0 if successful, or
  21931. * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or
  21932. * MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG, or
  21933. * MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG.
  21934. */
  21935. int mbedtls_hmac_drbg_random_with_add( void *p_rng,
  21936. unsigned char *output, size_t output_len,
  21937. const unsigned char *additional,
  21938. size_t add_len );
  21939. /**
  21940. * \brief HMAC_DRBG generate random
  21941. *
  21942. * Note: Automatically reseeds if reseed_counter is reached or PR is enabled.
  21943. *
  21944. * \param p_rng HMAC_DRBG context
  21945. * \param output Buffer to fill
  21946. * \param out_len Length of the buffer
  21947. *
  21948. * \return 0 if successful, or
  21949. * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED, or
  21950. * MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG
  21951. */
  21952. int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
  21953. /**
  21954. * \brief Free an HMAC_DRBG context
  21955. *
  21956. * \param ctx HMAC_DRBG context to free.
  21957. */
  21958. void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
  21959. #if defined(MBEDTLS_FS_IO)
  21960. /**
  21961. * \brief Write a seed file
  21962. *
  21963. * \param ctx HMAC_DRBG context
  21964. * \param path Name of the file
  21965. *
  21966. * \return 0 if successful, 1 on file error, or
  21967. * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED
  21968. */
  21969. int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
  21970. /**
  21971. * \brief Read and update a seed file. Seed is added to this
  21972. * instance
  21973. *
  21974. * \param ctx HMAC_DRBG context
  21975. * \param path Name of the file
  21976. *
  21977. * \return 0 if successful, 1 on file error,
  21978. * MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED or
  21979. * MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG
  21980. */
  21981. int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
  21982. #endif /* MBEDTLS_FS_IO */
  21983. #if defined(MBEDTLS_SELF_TEST)
  21984. /**
  21985. * \brief Checkup routine
  21986. *
  21987. * \return 0 if successful, or 1 if the test failed
  21988. */
  21989. int mbedtls_hmac_drbg_self_test( int verbose );
  21990. #endif
  21991. #ifdef __cplusplus
  21992. }
  21993. #endif
  21994. #endif /* hmac_drbg.h */
  21995. /********* Start of file include/mbedtls/pkcs12.h ************/
  21996. /**
  21997. * \file pkcs12.h
  21998. *
  21999. * \brief PKCS#12 Personal Information Exchange Syntax
  22000. */
  22001. /*
  22002. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  22003. * SPDX-License-Identifier: Apache-2.0
  22004. *
  22005. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  22006. * not use this file except in compliance with the License.
  22007. * You may obtain a copy of the License at
  22008. *
  22009. * http://www.apache.org/licenses/LICENSE-2.0
  22010. *
  22011. * Unless required by applicable law or agreed to in writing, software
  22012. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22013. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22014. * See the License for the specific language governing permissions and
  22015. * limitations under the License.
  22016. *
  22017. * This file is part of mbed TLS (https://tls.mbed.org)
  22018. */
  22019. #ifndef MBEDTLS_PKCS12_H
  22020. #define MBEDTLS_PKCS12_H
  22021. #include <stddef.h>
  22022. #define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */
  22023. #define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */
  22024. #define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */
  22025. #define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */
  22026. #define MBEDTLS_PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */
  22027. #define MBEDTLS_PKCS12_DERIVE_IV 2 /**< initialization vector */
  22028. #define MBEDTLS_PKCS12_DERIVE_MAC_KEY 3 /**< integrity / MAC key */
  22029. #define MBEDTLS_PKCS12_PBE_DECRYPT 0
  22030. #define MBEDTLS_PKCS12_PBE_ENCRYPT 1
  22031. #ifdef __cplusplus
  22032. extern "C" {
  22033. #endif
  22034. /**
  22035. * \brief PKCS12 Password Based function (encryption / decryption)
  22036. * for pbeWithSHAAnd128BitRC4
  22037. *
  22038. * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
  22039. * \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
  22040. * \param pwd the password used (may be NULL if no password is used)
  22041. * \param pwdlen length of the password (may be 0)
  22042. * \param input the input data
  22043. * \param len data length
  22044. * \param output the output buffer
  22045. *
  22046. * \return 0 if successful, or a MBEDTLS_ERR_XXX code
  22047. */
  22048. int mbedtls_pkcs12_pbe_sha1_rc4_128( mbedtls_asn1_buf *pbe_params, int mode,
  22049. const unsigned char *pwd, size_t pwdlen,
  22050. const unsigned char *input, size_t len,
  22051. unsigned char *output );
  22052. /**
  22053. * \brief PKCS12 Password Based function (encryption / decryption)
  22054. * for cipher-based and mbedtls_md-based PBE's
  22055. *
  22056. * \param pbe_params an ASN1 buffer containing the pkcs-12PbeParams structure
  22057. * \param mode either MBEDTLS_PKCS12_PBE_ENCRYPT or MBEDTLS_PKCS12_PBE_DECRYPT
  22058. * \param cipher_type the cipher used
  22059. * \param md_type the mbedtls_md used
  22060. * \param pwd the password used (may be NULL if no password is used)
  22061. * \param pwdlen length of the password (may be 0)
  22062. * \param input the input data
  22063. * \param len data length
  22064. * \param output the output buffer
  22065. *
  22066. * \return 0 if successful, or a MBEDTLS_ERR_XXX code
  22067. */
  22068. int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
  22069. mbedtls_cipher_type_t cipher_type, mbedtls_md_type_t md_type,
  22070. const unsigned char *pwd, size_t pwdlen,
  22071. const unsigned char *input, size_t len,
  22072. unsigned char *output );
  22073. /**
  22074. * \brief The PKCS#12 derivation function uses a password and a salt
  22075. * to produce pseudo-random bits for a particular "purpose".
  22076. *
  22077. * Depending on the given id, this function can produce an
  22078. * encryption/decryption key, an nitialization vector or an
  22079. * integrity key.
  22080. *
  22081. * \param data buffer to store the derived data in
  22082. * \param datalen length to fill
  22083. * \param pwd password to use (may be NULL if no password is used)
  22084. * \param pwdlen length of the password (may be 0)
  22085. * \param salt salt buffer to use
  22086. * \param saltlen length of the salt
  22087. * \param mbedtls_md mbedtls_md type to use during the derivation
  22088. * \param id id that describes the purpose (can be MBEDTLS_PKCS12_DERIVE_KEY,
  22089. * MBEDTLS_PKCS12_DERIVE_IV or MBEDTLS_PKCS12_DERIVE_MAC_KEY)
  22090. * \param iterations number of iterations
  22091. *
  22092. * \return 0 if successful, or a MD, BIGNUM type error.
  22093. */
  22094. int mbedtls_pkcs12_derivation( unsigned char *data, size_t datalen,
  22095. const unsigned char *pwd, size_t pwdlen,
  22096. const unsigned char *salt, size_t saltlen,
  22097. mbedtls_md_type_t mbedtls_md, int id, int iterations );
  22098. #ifdef __cplusplus
  22099. }
  22100. #endif
  22101. #endif /* pkcs12.h */
  22102. /********* Start of file include/mbedtls/pkcs11.h ************/
  22103. /**
  22104. * \file pkcs11.h
  22105. *
  22106. * \brief Wrapper for PKCS#11 library libpkcs11-helper
  22107. *
  22108. * \author Adriaan de Jong <dejong@fox-it.com>
  22109. */
  22110. /*
  22111. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  22112. * SPDX-License-Identifier: Apache-2.0
  22113. *
  22114. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  22115. * not use this file except in compliance with the License.
  22116. * You may obtain a copy of the License at
  22117. *
  22118. * http://www.apache.org/licenses/LICENSE-2.0
  22119. *
  22120. * Unless required by applicable law or agreed to in writing, software
  22121. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22122. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22123. * See the License for the specific language governing permissions and
  22124. * limitations under the License.
  22125. *
  22126. * This file is part of mbed TLS (https://tls.mbed.org)
  22127. */
  22128. #ifndef MBEDTLS_PKCS11_H
  22129. #define MBEDTLS_PKCS11_H
  22130. #if !defined(MBEDTLS_CONFIG_FILE)
  22131. #else
  22132. #endif
  22133. #if defined(MBEDTLS_PKCS11_C)
  22134. #include <pkcs11-helper-1.0/pkcs11h-certificate.h>
  22135. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  22136. !defined(inline) && !defined(__cplusplus)
  22137. #define inline __inline
  22138. #endif
  22139. #ifdef __cplusplus
  22140. extern "C" {
  22141. #endif
  22142. /**
  22143. * Context for PKCS #11 private keys.
  22144. */
  22145. typedef struct {
  22146. pkcs11h_certificate_t pkcs11h_cert;
  22147. int len;
  22148. } mbedtls_pkcs11_context;
  22149. /**
  22150. * Initialize a mbedtls_pkcs11_context.
  22151. * (Just making memory references valid.)
  22152. */
  22153. void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
  22154. /**
  22155. * Fill in a mbed TLS certificate, based on the given PKCS11 helper certificate.
  22156. *
  22157. * \param cert X.509 certificate to fill
  22158. * \param pkcs11h_cert PKCS #11 helper certificate
  22159. *
  22160. * \return 0 on success.
  22161. */
  22162. int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
  22163. /**
  22164. * Set up a mbedtls_pkcs11_context storing the given certificate. Note that the
  22165. * mbedtls_pkcs11_context will take over control of the certificate, freeing it when
  22166. * done.
  22167. *
  22168. * \param priv_key Private key structure to fill.
  22169. * \param pkcs11_cert PKCS #11 helper certificate
  22170. *
  22171. * \return 0 on success
  22172. */
  22173. int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
  22174. pkcs11h_certificate_t pkcs11_cert );
  22175. /**
  22176. * Free the contents of the given private key context. Note that the structure
  22177. * itself is not freed.
  22178. *
  22179. * \param priv_key Private key structure to cleanup
  22180. */
  22181. void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key );
  22182. /**
  22183. * \brief Do an RSA private key decrypt, then remove the message
  22184. * padding
  22185. *
  22186. * \param ctx PKCS #11 context
  22187. * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
  22188. * \param input buffer holding the encrypted data
  22189. * \param output buffer that will hold the plaintext
  22190. * \param olen will contain the plaintext length
  22191. * \param output_max_len maximum length of the output buffer
  22192. *
  22193. * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
  22194. *
  22195. * \note The output buffer must be as large as the size
  22196. * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise
  22197. * an error is thrown.
  22198. */
  22199. int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
  22200. int mode, size_t *olen,
  22201. const unsigned char *input,
  22202. unsigned char *output,
  22203. size_t output_max_len );
  22204. /**
  22205. * \brief Do a private RSA to sign a message digest
  22206. *
  22207. * \param ctx PKCS #11 context
  22208. * \param mode must be MBEDTLS_RSA_PRIVATE, for compatibility with rsa.c's signature
  22209. * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
  22210. * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
  22211. * \param hash buffer holding the message digest
  22212. * \param sig buffer that will hold the ciphertext
  22213. *
  22214. * \return 0 if the signing operation was successful,
  22215. * or an MBEDTLS_ERR_RSA_XXX error code
  22216. *
  22217. * \note The "sig" buffer must be as large as the size
  22218. * of ctx->N (eg. 128 bytes if RSA-1024 is used).
  22219. */
  22220. int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
  22221. int mode,
  22222. mbedtls_md_type_t md_alg,
  22223. unsigned int hashlen,
  22224. const unsigned char *hash,
  22225. unsigned char *sig );
  22226. /**
  22227. * SSL/TLS wrappers for PKCS#11 functions
  22228. */
  22229. static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
  22230. const unsigned char *input, unsigned char *output,
  22231. size_t output_max_len )
  22232. {
  22233. return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output,
  22234. output_max_len );
  22235. }
  22236. static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
  22237. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
  22238. int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
  22239. const unsigned char *hash, unsigned char *sig )
  22240. {
  22241. ((void) f_rng);
  22242. ((void) p_rng);
  22243. return mbedtls_pkcs11_sign( (mbedtls_pkcs11_context *) ctx, mode, md_alg,
  22244. hashlen, hash, sig );
  22245. }
  22246. static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
  22247. {
  22248. return ( (mbedtls_pkcs11_context *) ctx )->len;
  22249. }
  22250. #ifdef __cplusplus
  22251. }
  22252. #endif
  22253. #endif /* MBEDTLS_PKCS11_C */
  22254. #endif /* MBEDTLS_PKCS11_H */
  22255. /********* Start of file include/mbedtls/pkcs5.h ************/
  22256. /**
  22257. * \file pkcs5.h
  22258. *
  22259. * \brief PKCS#5 functions
  22260. *
  22261. * \author Mathias Olsson <mathias@kompetensum.com>
  22262. */
  22263. /*
  22264. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  22265. * SPDX-License-Identifier: Apache-2.0
  22266. *
  22267. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  22268. * not use this file except in compliance with the License.
  22269. * You may obtain a copy of the License at
  22270. *
  22271. * http://www.apache.org/licenses/LICENSE-2.0
  22272. *
  22273. * Unless required by applicable law or agreed to in writing, software
  22274. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22275. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22276. * See the License for the specific language governing permissions and
  22277. * limitations under the License.
  22278. *
  22279. * This file is part of mbed TLS (https://tls.mbed.org)
  22280. */
  22281. #ifndef MBEDTLS_PKCS5_H
  22282. #define MBEDTLS_PKCS5_H
  22283. #include <stddef.h>
  22284. #include <stdint.h>
  22285. #define MBEDTLS_ERR_PKCS5_BAD_INPUT_DATA -0x2f80 /**< Bad input parameters to function. */
  22286. #define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 /**< Unexpected ASN.1 data. */
  22287. #define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 /**< Requested encryption or digest alg not available. */
  22288. #define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 /**< Given private key password does not allow for correct decryption. */
  22289. #define MBEDTLS_PKCS5_DECRYPT 0
  22290. #define MBEDTLS_PKCS5_ENCRYPT 1
  22291. #ifdef __cplusplus
  22292. extern "C" {
  22293. #endif
  22294. /**
  22295. * \brief PKCS#5 PBES2 function
  22296. *
  22297. * \param pbe_params the ASN.1 algorithm parameters
  22298. * \param mode either MBEDTLS_PKCS5_DECRYPT or MBEDTLS_PKCS5_ENCRYPT
  22299. * \param pwd password to use when generating key
  22300. * \param pwdlen length of password
  22301. * \param data data to process
  22302. * \param datalen length of data
  22303. * \param output output buffer
  22304. *
  22305. * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
  22306. */
  22307. int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
  22308. const unsigned char *pwd, size_t pwdlen,
  22309. const unsigned char *data, size_t datalen,
  22310. unsigned char *output );
  22311. /**
  22312. * \brief PKCS#5 PBKDF2 using HMAC
  22313. *
  22314. * \param ctx Generic HMAC context
  22315. * \param password Password to use when generating key
  22316. * \param plen Length of password
  22317. * \param salt Salt to use when generating key
  22318. * \param slen Length of salt
  22319. * \param iteration_count Iteration count
  22320. * \param key_length Length of generated key in bytes
  22321. * \param output Generated key. Must be at least as big as key_length
  22322. *
  22323. * \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
  22324. */
  22325. int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *password,
  22326. size_t plen, const unsigned char *salt, size_t slen,
  22327. unsigned int iteration_count,
  22328. uint32_t key_length, unsigned char *output );
  22329. /**
  22330. * \brief Checkup routine
  22331. *
  22332. * \return 0 if successful, or 1 if the test failed
  22333. */
  22334. int mbedtls_pkcs5_self_test( int verbose );
  22335. #ifdef __cplusplus
  22336. }
  22337. #endif
  22338. #endif /* pkcs5.h */
  22339. /********* Start of file include/mbedtls/oid.h ************/
  22340. /**
  22341. * \file oid.h
  22342. *
  22343. * \brief Object Identifier (OID) database
  22344. */
  22345. /*
  22346. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  22347. * SPDX-License-Identifier: Apache-2.0
  22348. *
  22349. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  22350. * not use this file except in compliance with the License.
  22351. * You may obtain a copy of the License at
  22352. *
  22353. * http://www.apache.org/licenses/LICENSE-2.0
  22354. *
  22355. * Unless required by applicable law or agreed to in writing, software
  22356. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22357. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22358. * See the License for the specific language governing permissions and
  22359. * limitations under the License.
  22360. *
  22361. * This file is part of mbed TLS (https://tls.mbed.org)
  22362. */
  22363. #ifndef MBEDTLS_OID_H
  22364. #define MBEDTLS_OID_H
  22365. #if !defined(MBEDTLS_CONFIG_FILE)
  22366. #else
  22367. #endif
  22368. #include <stddef.h>
  22369. #if defined(MBEDTLS_CIPHER_C)
  22370. #endif
  22371. #if defined(MBEDTLS_MD_C)
  22372. #endif
  22373. #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
  22374. #endif
  22375. #define MBEDTLS_ERR_OID_NOT_FOUND -0x002E /**< OID is not found. */
  22376. #define MBEDTLS_ERR_OID_BUF_TOO_SMALL -0x000B /**< output buffer is too small */
  22377. /*
  22378. * Top level OID tuples
  22379. */
  22380. #define MBEDTLS_OID_ISO_MEMBER_BODIES "\x2a" /* {iso(1) member-body(2)} */
  22381. #define MBEDTLS_OID_ISO_IDENTIFIED_ORG "\x2b" /* {iso(1) identified-organization(3)} */
  22382. #define MBEDTLS_OID_ISO_CCITT_DS "\x55" /* {joint-iso-ccitt(2) ds(5)} */
  22383. #define MBEDTLS_OID_ISO_ITU_COUNTRY "\x60" /* {joint-iso-itu-t(2) country(16)} */
  22384. /*
  22385. * ISO Member bodies OID parts
  22386. */
  22387. #define MBEDTLS_OID_COUNTRY_US "\x86\x48" /* {us(840)} */
  22388. #define MBEDTLS_OID_ORG_RSA_DATA_SECURITY "\x86\xf7\x0d" /* {rsadsi(113549)} */
  22389. #define MBEDTLS_OID_RSA_COMPANY MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \
  22390. MBEDTLS_OID_ORG_RSA_DATA_SECURITY /* {iso(1) member-body(2) us(840) rsadsi(113549)} */
  22391. #define MBEDTLS_OID_ORG_ANSI_X9_62 "\xce\x3d" /* ansi-X9-62(10045) */
  22392. #define MBEDTLS_OID_ANSI_X9_62 MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \
  22393. MBEDTLS_OID_ORG_ANSI_X9_62
  22394. /*
  22395. * ISO Identified organization OID parts
  22396. */
  22397. #define MBEDTLS_OID_ORG_DOD "\x06" /* {dod(6)} */
  22398. #define MBEDTLS_OID_ORG_OIW "\x0e"
  22399. #define MBEDTLS_OID_OIW_SECSIG MBEDTLS_OID_ORG_OIW "\x03"
  22400. #define MBEDTLS_OID_OIW_SECSIG_ALG MBEDTLS_OID_OIW_SECSIG "\x02"
  22401. #define MBEDTLS_OID_OIW_SECSIG_SHA1 MBEDTLS_OID_OIW_SECSIG_ALG "\x1a"
  22402. #define MBEDTLS_OID_ORG_CERTICOM "\x81\x04" /* certicom(132) */
  22403. #define MBEDTLS_OID_CERTICOM MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_CERTICOM
  22404. #define MBEDTLS_OID_ORG_TELETRUST "\x24" /* teletrust(36) */
  22405. #define MBEDTLS_OID_TELETRUST MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_TELETRUST
  22406. /*
  22407. * ISO ITU OID parts
  22408. */
  22409. #define MBEDTLS_OID_ORGANIZATION "\x01" /* {organization(1)} */
  22410. #define MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ISO_ITU_COUNTRY MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORGANIZATION /* {joint-iso-itu-t(2) country(16) us(840) organization(1)} */
  22411. #define MBEDTLS_OID_ORG_GOV "\x65" /* {gov(101)} */
  22412. #define MBEDTLS_OID_GOV MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_GOV /* {joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101)} */
  22413. #define MBEDTLS_OID_ORG_NETSCAPE "\x86\xF8\x42" /* {netscape(113730)} */
  22414. #define MBEDTLS_OID_NETSCAPE MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_NETSCAPE /* Netscape OID {joint-iso-itu-t(2) country(16) us(840) organization(1) netscape(113730)} */
  22415. /* ISO arc for standard certificate and CRL extensions */
  22416. #define MBEDTLS_OID_ID_CE MBEDTLS_OID_ISO_CCITT_DS "\x1D" /**< id-ce OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 29} */
  22417. /**
  22418. * Private Internet Extensions
  22419. * { iso(1) identified-organization(3) dod(6) internet(1)
  22420. * security(5) mechanisms(5) pkix(7) }
  22421. */
  22422. #define MBEDTLS_OID_PKIX MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01\x05\x05\x07"
  22423. /*
  22424. * Arc for standard naming attributes
  22425. */
  22426. #define MBEDTLS_OID_AT MBEDTLS_OID_ISO_CCITT_DS "\x04" /**< id-at OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 4} */
  22427. #define MBEDTLS_OID_AT_CN MBEDTLS_OID_AT "\x03" /**< id-at-commonName AttributeType:= {id-at 3} */
  22428. #define MBEDTLS_OID_AT_SUR_NAME MBEDTLS_OID_AT "\x04" /**< id-at-surName AttributeType:= {id-at 4} */
  22429. #define MBEDTLS_OID_AT_SERIAL_NUMBER MBEDTLS_OID_AT "\x05" /**< id-at-serialNumber AttributeType:= {id-at 5} */
  22430. #define MBEDTLS_OID_AT_COUNTRY MBEDTLS_OID_AT "\x06" /**< id-at-countryName AttributeType:= {id-at 6} */
  22431. #define MBEDTLS_OID_AT_LOCALITY MBEDTLS_OID_AT "\x07" /**< id-at-locality AttributeType:= {id-at 7} */
  22432. #define MBEDTLS_OID_AT_STATE MBEDTLS_OID_AT "\x08" /**< id-at-state AttributeType:= {id-at 8} */
  22433. #define MBEDTLS_OID_AT_ORGANIZATION MBEDTLS_OID_AT "\x0A" /**< id-at-organizationName AttributeType:= {id-at 10} */
  22434. #define MBEDTLS_OID_AT_ORG_UNIT MBEDTLS_OID_AT "\x0B" /**< id-at-organizationalUnitName AttributeType:= {id-at 11} */
  22435. #define MBEDTLS_OID_AT_TITLE MBEDTLS_OID_AT "\x0C" /**< id-at-title AttributeType:= {id-at 12} */
  22436. #define MBEDTLS_OID_AT_POSTAL_ADDRESS MBEDTLS_OID_AT "\x10" /**< id-at-postalAddress AttributeType:= {id-at 16} */
  22437. #define MBEDTLS_OID_AT_POSTAL_CODE MBEDTLS_OID_AT "\x11" /**< id-at-postalCode AttributeType:= {id-at 17} */
  22438. #define MBEDTLS_OID_AT_GIVEN_NAME MBEDTLS_OID_AT "\x2A" /**< id-at-givenName AttributeType:= {id-at 42} */
  22439. #define MBEDTLS_OID_AT_INITIALS MBEDTLS_OID_AT "\x2B" /**< id-at-initials AttributeType:= {id-at 43} */
  22440. #define MBEDTLS_OID_AT_GENERATION_QUALIFIER MBEDTLS_OID_AT "\x2C" /**< id-at-generationQualifier AttributeType:= {id-at 44} */
  22441. #define MBEDTLS_OID_AT_UNIQUE_IDENTIFIER MBEDTLS_OID_AT "\x2D" /**< id-at-uniqueIdentifier AttributType:= {id-at 45} */
  22442. #define MBEDTLS_OID_AT_DN_QUALIFIER MBEDTLS_OID_AT "\x2E" /**< id-at-dnQualifier AttributeType:= {id-at 46} */
  22443. #define MBEDTLS_OID_AT_PSEUDONYM MBEDTLS_OID_AT "\x41" /**< id-at-pseudonym AttributeType:= {id-at 65} */
  22444. #define MBEDTLS_OID_DOMAIN_COMPONENT "\x09\x92\x26\x89\x93\xF2\x2C\x64\x01\x19" /** id-domainComponent AttributeType:= {itu-t(0) data(9) pss(2342) ucl(19200300) pilot(100) pilotAttributeType(1) domainComponent(25)} */
  22445. /*
  22446. * OIDs for standard certificate extensions
  22447. */
  22448. #define MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER MBEDTLS_OID_ID_CE "\x23" /**< id-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 } */
  22449. #define MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER MBEDTLS_OID_ID_CE "\x0E" /**< id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } */
  22450. #define MBEDTLS_OID_KEY_USAGE MBEDTLS_OID_ID_CE "\x0F" /**< id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } */
  22451. #define MBEDTLS_OID_CERTIFICATE_POLICIES MBEDTLS_OID_ID_CE "\x20" /**< id-ce-certificatePolicies OBJECT IDENTIFIER ::= { id-ce 32 } */
  22452. #define MBEDTLS_OID_POLICY_MAPPINGS MBEDTLS_OID_ID_CE "\x21" /**< id-ce-policyMappings OBJECT IDENTIFIER ::= { id-ce 33 } */
  22453. #define MBEDTLS_OID_SUBJECT_ALT_NAME MBEDTLS_OID_ID_CE "\x11" /**< id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } */
  22454. #define MBEDTLS_OID_ISSUER_ALT_NAME MBEDTLS_OID_ID_CE "\x12" /**< id-ce-issuerAltName OBJECT IDENTIFIER ::= { id-ce 18 } */
  22455. #define MBEDTLS_OID_SUBJECT_DIRECTORY_ATTRS MBEDTLS_OID_ID_CE "\x09" /**< id-ce-subjectDirectoryAttributes OBJECT IDENTIFIER ::= { id-ce 9 } */
  22456. #define MBEDTLS_OID_BASIC_CONSTRAINTS MBEDTLS_OID_ID_CE "\x13" /**< id-ce-basicConstraints OBJECT IDENTIFIER ::= { id-ce 19 } */
  22457. #define MBEDTLS_OID_NAME_CONSTRAINTS MBEDTLS_OID_ID_CE "\x1E" /**< id-ce-nameConstraints OBJECT IDENTIFIER ::= { id-ce 30 } */
  22458. #define MBEDTLS_OID_POLICY_CONSTRAINTS MBEDTLS_OID_ID_CE "\x24" /**< id-ce-policyConstraints OBJECT IDENTIFIER ::= { id-ce 36 } */
  22459. #define MBEDTLS_OID_EXTENDED_KEY_USAGE MBEDTLS_OID_ID_CE "\x25" /**< id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 } */
  22460. #define MBEDTLS_OID_CRL_DISTRIBUTION_POINTS MBEDTLS_OID_ID_CE "\x1F" /**< id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 } */
  22461. #define MBEDTLS_OID_INIHIBIT_ANYPOLICY MBEDTLS_OID_ID_CE "\x36" /**< id-ce-inhibitAnyPolicy OBJECT IDENTIFIER ::= { id-ce 54 } */
  22462. #define MBEDTLS_OID_FRESHEST_CRL MBEDTLS_OID_ID_CE "\x2E" /**< id-ce-freshestCRL OBJECT IDENTIFIER ::= { id-ce 46 } */
  22463. /*
  22464. * Netscape certificate extensions
  22465. */
  22466. #define MBEDTLS_OID_NS_CERT MBEDTLS_OID_NETSCAPE "\x01"
  22467. #define MBEDTLS_OID_NS_CERT_TYPE MBEDTLS_OID_NS_CERT "\x01"
  22468. #define MBEDTLS_OID_NS_BASE_URL MBEDTLS_OID_NS_CERT "\x02"
  22469. #define MBEDTLS_OID_NS_REVOCATION_URL MBEDTLS_OID_NS_CERT "\x03"
  22470. #define MBEDTLS_OID_NS_CA_REVOCATION_URL MBEDTLS_OID_NS_CERT "\x04"
  22471. #define MBEDTLS_OID_NS_RENEWAL_URL MBEDTLS_OID_NS_CERT "\x07"
  22472. #define MBEDTLS_OID_NS_CA_POLICY_URL MBEDTLS_OID_NS_CERT "\x08"
  22473. #define MBEDTLS_OID_NS_SSL_SERVER_NAME MBEDTLS_OID_NS_CERT "\x0C"
  22474. #define MBEDTLS_OID_NS_COMMENT MBEDTLS_OID_NS_CERT "\x0D"
  22475. #define MBEDTLS_OID_NS_DATA_TYPE MBEDTLS_OID_NETSCAPE "\x02"
  22476. #define MBEDTLS_OID_NS_CERT_SEQUENCE MBEDTLS_OID_NS_DATA_TYPE "\x05"
  22477. /*
  22478. * OIDs for CRL extensions
  22479. */
  22480. #define MBEDTLS_OID_PRIVATE_KEY_USAGE_PERIOD MBEDTLS_OID_ID_CE "\x10"
  22481. #define MBEDTLS_OID_CRL_NUMBER MBEDTLS_OID_ID_CE "\x14" /**< id-ce-cRLNumber OBJECT IDENTIFIER ::= { id-ce 20 } */
  22482. /*
  22483. * X.509 v3 Extended key usage OIDs
  22484. */
  22485. #define MBEDTLS_OID_ANY_EXTENDED_KEY_USAGE MBEDTLS_OID_EXTENDED_KEY_USAGE "\x00" /**< anyExtendedKeyUsage OBJECT IDENTIFIER ::= { id-ce-extKeyUsage 0 } */
  22486. #define MBEDTLS_OID_KP MBEDTLS_OID_PKIX "\x03" /**< id-kp OBJECT IDENTIFIER ::= { id-pkix 3 } */
  22487. #define MBEDTLS_OID_SERVER_AUTH MBEDTLS_OID_KP "\x01" /**< id-kp-serverAuth OBJECT IDENTIFIER ::= { id-kp 1 } */
  22488. #define MBEDTLS_OID_CLIENT_AUTH MBEDTLS_OID_KP "\x02" /**< id-kp-clientAuth OBJECT IDENTIFIER ::= { id-kp 2 } */
  22489. #define MBEDTLS_OID_CODE_SIGNING MBEDTLS_OID_KP "\x03" /**< id-kp-codeSigning OBJECT IDENTIFIER ::= { id-kp 3 } */
  22490. #define MBEDTLS_OID_EMAIL_PROTECTION MBEDTLS_OID_KP "\x04" /**< id-kp-emailProtection OBJECT IDENTIFIER ::= { id-kp 4 } */
  22491. #define MBEDTLS_OID_TIME_STAMPING MBEDTLS_OID_KP "\x08" /**< id-kp-timeStamping OBJECT IDENTIFIER ::= { id-kp 8 } */
  22492. #define MBEDTLS_OID_OCSP_SIGNING MBEDTLS_OID_KP "\x09" /**< id-kp-OCSPSigning OBJECT IDENTIFIER ::= { id-kp 9 } */
  22493. /*
  22494. * PKCS definition OIDs
  22495. */
  22496. #define MBEDTLS_OID_PKCS MBEDTLS_OID_RSA_COMPANY "\x01" /**< pkcs OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) 1 } */
  22497. #define MBEDTLS_OID_PKCS1 MBEDTLS_OID_PKCS "\x01" /**< pkcs-1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1 } */
  22498. #define MBEDTLS_OID_PKCS5 MBEDTLS_OID_PKCS "\x05" /**< pkcs-5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 5 } */
  22499. #define MBEDTLS_OID_PKCS9 MBEDTLS_OID_PKCS "\x09" /**< pkcs-9 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 9 } */
  22500. #define MBEDTLS_OID_PKCS12 MBEDTLS_OID_PKCS "\x0c" /**< pkcs-12 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 12 } */
  22501. /*
  22502. * PKCS#1 OIDs
  22503. */
  22504. #define MBEDTLS_OID_PKCS1_RSA MBEDTLS_OID_PKCS1 "\x01" /**< rsaEncryption OBJECT IDENTIFIER ::= { pkcs-1 1 } */
  22505. #define MBEDTLS_OID_PKCS1_MD2 MBEDTLS_OID_PKCS1 "\x02" /**< md2WithRSAEncryption ::= { pkcs-1 2 } */
  22506. #define MBEDTLS_OID_PKCS1_MD4 MBEDTLS_OID_PKCS1 "\x03" /**< md4WithRSAEncryption ::= { pkcs-1 3 } */
  22507. #define MBEDTLS_OID_PKCS1_MD5 MBEDTLS_OID_PKCS1 "\x04" /**< md5WithRSAEncryption ::= { pkcs-1 4 } */
  22508. #define MBEDTLS_OID_PKCS1_SHA1 MBEDTLS_OID_PKCS1 "\x05" /**< sha1WithRSAEncryption ::= { pkcs-1 5 } */
  22509. #define MBEDTLS_OID_PKCS1_SHA224 MBEDTLS_OID_PKCS1 "\x0e" /**< sha224WithRSAEncryption ::= { pkcs-1 14 } */
  22510. #define MBEDTLS_OID_PKCS1_SHA256 MBEDTLS_OID_PKCS1 "\x0b" /**< sha256WithRSAEncryption ::= { pkcs-1 11 } */
  22511. #define MBEDTLS_OID_PKCS1_SHA384 MBEDTLS_OID_PKCS1 "\x0c" /**< sha384WithRSAEncryption ::= { pkcs-1 12 } */
  22512. #define MBEDTLS_OID_PKCS1_SHA512 MBEDTLS_OID_PKCS1 "\x0d" /**< sha512WithRSAEncryption ::= { pkcs-1 13 } */
  22513. #define MBEDTLS_OID_RSA_SHA_OBS "\x2B\x0E\x03\x02\x1D"
  22514. #define MBEDTLS_OID_PKCS9_EMAIL MBEDTLS_OID_PKCS9 "\x01" /**< emailAddress AttributeType ::= { pkcs-9 1 } */
  22515. /* RFC 4055 */
  22516. #define MBEDTLS_OID_RSASSA_PSS MBEDTLS_OID_PKCS1 "\x0a" /**< id-RSASSA-PSS ::= { pkcs-1 10 } */
  22517. #define MBEDTLS_OID_MGF1 MBEDTLS_OID_PKCS1 "\x08" /**< id-mgf1 ::= { pkcs-1 8 } */
  22518. /*
  22519. * Digest algorithms
  22520. */
  22521. #define MBEDTLS_OID_DIGEST_ALG_MD2 MBEDTLS_OID_RSA_COMPANY "\x02\x02" /**< id-mbedtls_md2 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 2 } */
  22522. #define MBEDTLS_OID_DIGEST_ALG_MD4 MBEDTLS_OID_RSA_COMPANY "\x02\x04" /**< id-mbedtls_md4 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 4 } */
  22523. #define MBEDTLS_OID_DIGEST_ALG_MD5 MBEDTLS_OID_RSA_COMPANY "\x02\x05" /**< id-mbedtls_md5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5 } */
  22524. #define MBEDTLS_OID_DIGEST_ALG_SHA1 MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_SHA1 /**< id-mbedtls_sha1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 26 } */
  22525. #define MBEDTLS_OID_DIGEST_ALG_SHA224 MBEDTLS_OID_GOV "\x03\x04\x02\x04" /**< id-sha224 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 4 } */
  22526. #define MBEDTLS_OID_DIGEST_ALG_SHA256 MBEDTLS_OID_GOV "\x03\x04\x02\x01" /**< id-mbedtls_sha256 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 1 } */
  22527. #define MBEDTLS_OID_DIGEST_ALG_SHA384 MBEDTLS_OID_GOV "\x03\x04\x02\x02" /**< id-sha384 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 2 } */
  22528. #define MBEDTLS_OID_DIGEST_ALG_SHA512 MBEDTLS_OID_GOV "\x03\x04\x02\x03" /**< id-mbedtls_sha512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 3 } */
  22529. #define MBEDTLS_OID_HMAC_SHA1 MBEDTLS_OID_RSA_COMPANY "\x02\x07" /**< id-hmacWithSHA1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 7 } */
  22530. #define MBEDTLS_OID_HMAC_SHA224 MBEDTLS_OID_RSA_COMPANY "\x02\x08" /**< id-hmacWithSHA224 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 8 } */
  22531. #define MBEDTLS_OID_HMAC_SHA256 MBEDTLS_OID_RSA_COMPANY "\x02\x09" /**< id-hmacWithSHA256 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 9 } */
  22532. #define MBEDTLS_OID_HMAC_SHA384 MBEDTLS_OID_RSA_COMPANY "\x02\x0A" /**< id-hmacWithSHA384 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 10 } */
  22533. #define MBEDTLS_OID_HMAC_SHA512 MBEDTLS_OID_RSA_COMPANY "\x02\x0B" /**< id-hmacWithSHA512 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 11 } */
  22534. /*
  22535. * Encryption algorithms
  22536. */
  22537. #define MBEDTLS_OID_DES_CBC MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_ALG "\x07" /**< desCBC OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 7 } */
  22538. #define MBEDTLS_OID_DES_EDE3_CBC MBEDTLS_OID_RSA_COMPANY "\x03\x07" /**< des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) -- us(840) rsadsi(113549) encryptionAlgorithm(3) 7 } */
  22539. /*
  22540. * PKCS#5 OIDs
  22541. */
  22542. #define MBEDTLS_OID_PKCS5_PBKDF2 MBEDTLS_OID_PKCS5 "\x0c" /**< id-PBKDF2 OBJECT IDENTIFIER ::= {pkcs-5 12} */
  22543. #define MBEDTLS_OID_PKCS5_PBES2 MBEDTLS_OID_PKCS5 "\x0d" /**< id-PBES2 OBJECT IDENTIFIER ::= {pkcs-5 13} */
  22544. #define MBEDTLS_OID_PKCS5_PBMAC1 MBEDTLS_OID_PKCS5 "\x0e" /**< id-PBMAC1 OBJECT IDENTIFIER ::= {pkcs-5 14} */
  22545. /*
  22546. * PKCS#5 PBES1 algorithms
  22547. */
  22548. #define MBEDTLS_OID_PKCS5_PBE_MD2_DES_CBC MBEDTLS_OID_PKCS5 "\x01" /**< pbeWithMD2AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 1} */
  22549. #define MBEDTLS_OID_PKCS5_PBE_MD2_RC2_CBC MBEDTLS_OID_PKCS5 "\x04" /**< pbeWithMD2AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 4} */
  22550. #define MBEDTLS_OID_PKCS5_PBE_MD5_DES_CBC MBEDTLS_OID_PKCS5 "\x03" /**< pbeWithMD5AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 3} */
  22551. #define MBEDTLS_OID_PKCS5_PBE_MD5_RC2_CBC MBEDTLS_OID_PKCS5 "\x06" /**< pbeWithMD5AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 6} */
  22552. #define MBEDTLS_OID_PKCS5_PBE_SHA1_DES_CBC MBEDTLS_OID_PKCS5 "\x0a" /**< pbeWithSHA1AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 10} */
  22553. #define MBEDTLS_OID_PKCS5_PBE_SHA1_RC2_CBC MBEDTLS_OID_PKCS5 "\x0b" /**< pbeWithSHA1AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 11} */
  22554. /*
  22555. * PKCS#8 OIDs
  22556. */
  22557. #define MBEDTLS_OID_PKCS9_CSR_EXT_REQ MBEDTLS_OID_PKCS9 "\x0e" /**< extensionRequest OBJECT IDENTIFIER ::= {pkcs-9 14} */
  22558. /*
  22559. * PKCS#12 PBE OIDs
  22560. */
  22561. #define MBEDTLS_OID_PKCS12_PBE MBEDTLS_OID_PKCS12 "\x01" /**< pkcs-12PbeIds OBJECT IDENTIFIER ::= {pkcs-12 1} */
  22562. #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_128 MBEDTLS_OID_PKCS12_PBE "\x01" /**< pbeWithSHAAnd128BitRC4 OBJECT IDENTIFIER ::= {pkcs-12PbeIds 1} */
  22563. #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_40 MBEDTLS_OID_PKCS12_PBE "\x02" /**< pbeWithSHAAnd40BitRC4 OBJECT IDENTIFIER ::= {pkcs-12PbeIds 2} */
  22564. #define MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC MBEDTLS_OID_PKCS12_PBE "\x03" /**< pbeWithSHAAnd3-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 3} */
  22565. #define MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC MBEDTLS_OID_PKCS12_PBE "\x04" /**< pbeWithSHAAnd2-KeyTripleDES-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 4} */
  22566. #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_128_CBC MBEDTLS_OID_PKCS12_PBE "\x05" /**< pbeWithSHAAnd128BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 5} */
  22567. #define MBEDTLS_OID_PKCS12_PBE_SHA1_RC2_40_CBC MBEDTLS_OID_PKCS12_PBE "\x06" /**< pbeWithSHAAnd40BitRC2-CBC OBJECT IDENTIFIER ::= {pkcs-12PbeIds 6} */
  22568. /*
  22569. * EC key algorithms from RFC 5480
  22570. */
  22571. /* id-ecPublicKey OBJECT IDENTIFIER ::= {
  22572. * iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 } */
  22573. #define MBEDTLS_OID_EC_ALG_UNRESTRICTED MBEDTLS_OID_ANSI_X9_62 "\x02\01"
  22574. /* id-ecDH OBJECT IDENTIFIER ::= {
  22575. * iso(1) identified-organization(3) certicom(132)
  22576. * schemes(1) ecdh(12) } */
  22577. #define MBEDTLS_OID_EC_ALG_ECDH MBEDTLS_OID_CERTICOM "\x01\x0c"
  22578. /*
  22579. * ECParameters namedCurve identifiers, from RFC 5480, RFC 5639, and SEC2
  22580. */
  22581. /* secp192r1 OBJECT IDENTIFIER ::= {
  22582. * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 1 } */
  22583. #define MBEDTLS_OID_EC_GRP_SECP192R1 MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x01"
  22584. /* secp224r1 OBJECT IDENTIFIER ::= {
  22585. * iso(1) identified-organization(3) certicom(132) curve(0) 33 } */
  22586. #define MBEDTLS_OID_EC_GRP_SECP224R1 MBEDTLS_OID_CERTICOM "\x00\x21"
  22587. /* secp256r1 OBJECT IDENTIFIER ::= {
  22588. * iso(1) member-body(2) us(840) ansi-X9-62(10045) curves(3) prime(1) 7 } */
  22589. #define MBEDTLS_OID_EC_GRP_SECP256R1 MBEDTLS_OID_ANSI_X9_62 "\x03\x01\x07"
  22590. /* secp384r1 OBJECT IDENTIFIER ::= {
  22591. * iso(1) identified-organization(3) certicom(132) curve(0) 34 } */
  22592. #define MBEDTLS_OID_EC_GRP_SECP384R1 MBEDTLS_OID_CERTICOM "\x00\x22"
  22593. /* secp521r1 OBJECT IDENTIFIER ::= {
  22594. * iso(1) identified-organization(3) certicom(132) curve(0) 35 } */
  22595. #define MBEDTLS_OID_EC_GRP_SECP521R1 MBEDTLS_OID_CERTICOM "\x00\x23"
  22596. /* secp192k1 OBJECT IDENTIFIER ::= {
  22597. * iso(1) identified-organization(3) certicom(132) curve(0) 31 } */
  22598. #define MBEDTLS_OID_EC_GRP_SECP192K1 MBEDTLS_OID_CERTICOM "\x00\x1f"
  22599. /* secp224k1 OBJECT IDENTIFIER ::= {
  22600. * iso(1) identified-organization(3) certicom(132) curve(0) 32 } */
  22601. #define MBEDTLS_OID_EC_GRP_SECP224K1 MBEDTLS_OID_CERTICOM "\x00\x20"
  22602. /* secp256k1 OBJECT IDENTIFIER ::= {
  22603. * iso(1) identified-organization(3) certicom(132) curve(0) 10 } */
  22604. #define MBEDTLS_OID_EC_GRP_SECP256K1 MBEDTLS_OID_CERTICOM "\x00\x0a"
  22605. /* RFC 5639 4.1
  22606. * ecStdCurvesAndGeneration OBJECT IDENTIFIER::= {iso(1)
  22607. * identified-organization(3) teletrust(36) algorithm(3) signature-
  22608. * algorithm(3) ecSign(2) 8}
  22609. * ellipticCurve OBJECT IDENTIFIER ::= {ecStdCurvesAndGeneration 1}
  22610. * versionOne OBJECT IDENTIFIER ::= {ellipticCurve 1} */
  22611. #define MBEDTLS_OID_EC_BRAINPOOL_V1 MBEDTLS_OID_TELETRUST "\x03\x03\x02\x08\x01\x01"
  22612. /* brainpoolP256r1 OBJECT IDENTIFIER ::= {versionOne 7} */
  22613. #define MBEDTLS_OID_EC_GRP_BP256R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x07"
  22614. /* brainpoolP384r1 OBJECT IDENTIFIER ::= {versionOne 11} */
  22615. #define MBEDTLS_OID_EC_GRP_BP384R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0B"
  22616. /* brainpoolP512r1 OBJECT IDENTIFIER ::= {versionOne 13} */
  22617. #define MBEDTLS_OID_EC_GRP_BP512R1 MBEDTLS_OID_EC_BRAINPOOL_V1 "\x0D"
  22618. /*
  22619. * SEC1 C.1
  22620. *
  22621. * prime-field OBJECT IDENTIFIER ::= { id-fieldType 1 }
  22622. * id-fieldType OBJECT IDENTIFIER ::= { ansi-X9-62 fieldType(1)}
  22623. */
  22624. #define MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE MBEDTLS_OID_ANSI_X9_62 "\x01"
  22625. #define MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD MBEDTLS_OID_ANSI_X9_62_FIELD_TYPE "\x01"
  22626. /*
  22627. * ECDSA signature identifiers, from RFC 5480
  22628. */
  22629. #define MBEDTLS_OID_ANSI_X9_62_SIG MBEDTLS_OID_ANSI_X9_62 "\x04" /* signatures(4) */
  22630. #define MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 MBEDTLS_OID_ANSI_X9_62_SIG "\x03" /* ecdsa-with-SHA2(3) */
  22631. /* ecdsa-with-SHA1 OBJECT IDENTIFIER ::= {
  22632. * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4) 1 } */
  22633. #define MBEDTLS_OID_ECDSA_SHA1 MBEDTLS_OID_ANSI_X9_62_SIG "\x01"
  22634. /* ecdsa-with-SHA224 OBJECT IDENTIFIER ::= {
  22635. * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
  22636. * ecdsa-with-SHA2(3) 1 } */
  22637. #define MBEDTLS_OID_ECDSA_SHA224 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x01"
  22638. /* ecdsa-with-SHA256 OBJECT IDENTIFIER ::= {
  22639. * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
  22640. * ecdsa-with-SHA2(3) 2 } */
  22641. #define MBEDTLS_OID_ECDSA_SHA256 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x02"
  22642. /* ecdsa-with-SHA384 OBJECT IDENTIFIER ::= {
  22643. * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
  22644. * ecdsa-with-SHA2(3) 3 } */
  22645. #define MBEDTLS_OID_ECDSA_SHA384 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x03"
  22646. /* ecdsa-with-SHA512 OBJECT IDENTIFIER ::= {
  22647. * iso(1) member-body(2) us(840) ansi-X9-62(10045) signatures(4)
  22648. * ecdsa-with-SHA2(3) 4 } */
  22649. #define MBEDTLS_OID_ECDSA_SHA512 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x04"
  22650. #ifdef __cplusplus
  22651. extern "C" {
  22652. #endif
  22653. /**
  22654. * \brief Base OID descriptor structure
  22655. */
  22656. typedef struct {
  22657. const char *asn1; /*!< OID ASN.1 representation */
  22658. size_t asn1_len; /*!< length of asn1 */
  22659. const char *name; /*!< official name (e.g. from RFC) */
  22660. const char *description; /*!< human friendly description */
  22661. } mbedtls_oid_descriptor_t;
  22662. /**
  22663. * \brief Translate an ASN.1 OID into its numeric representation
  22664. * (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1.2.840.113549")
  22665. *
  22666. * \param buf buffer to put representation in
  22667. * \param size size of the buffer
  22668. * \param oid OID to translate
  22669. *
  22670. * \return Length of the string written (excluding final NULL) or
  22671. * MBEDTLS_ERR_OID_BUF_TOO_SMALL in case of error
  22672. */
  22673. int mbedtls_oid_get_numeric_string( char *buf, size_t size, const mbedtls_asn1_buf *oid );
  22674. #if defined(MBEDTLS_X509_USE_C) || defined(MBEDTLS_X509_CREATE_C)
  22675. /**
  22676. * \brief Translate an X.509 extension OID into local values
  22677. *
  22678. * \param oid OID to use
  22679. * \param ext_type place to store the extension type
  22680. *
  22681. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22682. */
  22683. int mbedtls_oid_get_x509_ext_type( const mbedtls_asn1_buf *oid, int *ext_type );
  22684. #endif
  22685. /**
  22686. * \brief Translate an X.509 attribute type OID into the short name
  22687. * (e.g. the OID for an X520 Common Name into "CN")
  22688. *
  22689. * \param oid OID to use
  22690. * \param short_name place to store the string pointer
  22691. *
  22692. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22693. */
  22694. int mbedtls_oid_get_attr_short_name( const mbedtls_asn1_buf *oid, const char **short_name );
  22695. /**
  22696. * \brief Translate PublicKeyAlgorithm OID into pk_type
  22697. *
  22698. * \param oid OID to use
  22699. * \param pk_alg place to store public key algorithm
  22700. *
  22701. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22702. */
  22703. int mbedtls_oid_get_pk_alg( const mbedtls_asn1_buf *oid, mbedtls_pk_type_t *pk_alg );
  22704. /**
  22705. * \brief Translate pk_type into PublicKeyAlgorithm OID
  22706. *
  22707. * \param pk_alg Public key type to look for
  22708. * \param oid place to store ASN.1 OID string pointer
  22709. * \param olen length of the OID
  22710. *
  22711. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22712. */
  22713. int mbedtls_oid_get_oid_by_pk_alg( mbedtls_pk_type_t pk_alg,
  22714. const char **oid, size_t *olen );
  22715. #if defined(MBEDTLS_ECP_C)
  22716. /**
  22717. * \brief Translate NamedCurve OID into an EC group identifier
  22718. *
  22719. * \param oid OID to use
  22720. * \param grp_id place to store group id
  22721. *
  22722. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22723. */
  22724. int mbedtls_oid_get_ec_grp( const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *grp_id );
  22725. /**
  22726. * \brief Translate EC group identifier into NamedCurve OID
  22727. *
  22728. * \param grp_id EC group identifier
  22729. * \param oid place to store ASN.1 OID string pointer
  22730. * \param olen length of the OID
  22731. *
  22732. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22733. */
  22734. int mbedtls_oid_get_oid_by_ec_grp( mbedtls_ecp_group_id grp_id,
  22735. const char **oid, size_t *olen );
  22736. #endif /* MBEDTLS_ECP_C */
  22737. #if defined(MBEDTLS_MD_C)
  22738. /**
  22739. * \brief Translate SignatureAlgorithm OID into md_type and pk_type
  22740. *
  22741. * \param oid OID to use
  22742. * \param md_alg place to store message digest algorithm
  22743. * \param pk_alg place to store public key algorithm
  22744. *
  22745. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22746. */
  22747. int mbedtls_oid_get_sig_alg( const mbedtls_asn1_buf *oid,
  22748. mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg );
  22749. /**
  22750. * \brief Translate SignatureAlgorithm OID into description
  22751. *
  22752. * \param oid OID to use
  22753. * \param desc place to store string pointer
  22754. *
  22755. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22756. */
  22757. int mbedtls_oid_get_sig_alg_desc( const mbedtls_asn1_buf *oid, const char **desc );
  22758. /**
  22759. * \brief Translate md_type and pk_type into SignatureAlgorithm OID
  22760. *
  22761. * \param md_alg message digest algorithm
  22762. * \param pk_alg public key algorithm
  22763. * \param oid place to store ASN.1 OID string pointer
  22764. * \param olen length of the OID
  22765. *
  22766. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22767. */
  22768. int mbedtls_oid_get_oid_by_sig_alg( mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg,
  22769. const char **oid, size_t *olen );
  22770. /**
  22771. * \brief Translate hash algorithm OID into md_type
  22772. *
  22773. * \param oid OID to use
  22774. * \param md_alg place to store message digest algorithm
  22775. *
  22776. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22777. */
  22778. int mbedtls_oid_get_md_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg );
  22779. /**
  22780. * \brief Translate hmac algorithm OID into md_type
  22781. *
  22782. * \param oid OID to use
  22783. * \param md_hmac place to store message hmac algorithm
  22784. *
  22785. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22786. */
  22787. int mbedtls_oid_get_md_hmac( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_hmac );
  22788. #endif /* MBEDTLS_MD_C */
  22789. /**
  22790. * \brief Translate Extended Key Usage OID into description
  22791. *
  22792. * \param oid OID to use
  22793. * \param desc place to store string pointer
  22794. *
  22795. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22796. */
  22797. int mbedtls_oid_get_extended_key_usage( const mbedtls_asn1_buf *oid, const char **desc );
  22798. /**
  22799. * \brief Translate md_type into hash algorithm OID
  22800. *
  22801. * \param md_alg message digest algorithm
  22802. * \param oid place to store ASN.1 OID string pointer
  22803. * \param olen length of the OID
  22804. *
  22805. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22806. */
  22807. int mbedtls_oid_get_oid_by_md( mbedtls_md_type_t md_alg, const char **oid, size_t *olen );
  22808. #if defined(MBEDTLS_CIPHER_C)
  22809. /**
  22810. * \brief Translate encryption algorithm OID into cipher_type
  22811. *
  22812. * \param oid OID to use
  22813. * \param cipher_alg place to store cipher algorithm
  22814. *
  22815. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22816. */
  22817. int mbedtls_oid_get_cipher_alg( const mbedtls_asn1_buf *oid, mbedtls_cipher_type_t *cipher_alg );
  22818. #endif /* MBEDTLS_CIPHER_C */
  22819. #if defined(MBEDTLS_PKCS12_C)
  22820. /**
  22821. * \brief Translate PKCS#12 PBE algorithm OID into md_type and
  22822. * cipher_type
  22823. *
  22824. * \param oid OID to use
  22825. * \param md_alg place to store message digest algorithm
  22826. * \param cipher_alg place to store cipher algorithm
  22827. *
  22828. * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND
  22829. */
  22830. int mbedtls_oid_get_pkcs12_pbe_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg,
  22831. mbedtls_cipher_type_t *cipher_alg );
  22832. #endif /* MBEDTLS_PKCS12_C */
  22833. #ifdef __cplusplus
  22834. }
  22835. #endif
  22836. #endif /* oid.h */
  22837. /********* Start of file include/mbedtls/ripemd160.h ************/
  22838. /**
  22839. * \file ripemd160.h
  22840. *
  22841. * \brief RIPE MD-160 message digest
  22842. */
  22843. /*
  22844. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  22845. * SPDX-License-Identifier: Apache-2.0
  22846. *
  22847. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  22848. * not use this file except in compliance with the License.
  22849. * You may obtain a copy of the License at
  22850. *
  22851. * http://www.apache.org/licenses/LICENSE-2.0
  22852. *
  22853. * Unless required by applicable law or agreed to in writing, software
  22854. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22855. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22856. * See the License for the specific language governing permissions and
  22857. * limitations under the License.
  22858. *
  22859. * This file is part of mbed TLS (https://tls.mbed.org)
  22860. */
  22861. #ifndef MBEDTLS_RIPEMD160_H
  22862. #define MBEDTLS_RIPEMD160_H
  22863. #if !defined(MBEDTLS_CONFIG_FILE)
  22864. #else
  22865. #endif
  22866. #include <stddef.h>
  22867. #include <stdint.h>
  22868. #define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */
  22869. #if !defined(MBEDTLS_RIPEMD160_ALT)
  22870. // Regular implementation
  22871. //
  22872. #ifdef __cplusplus
  22873. extern "C" {
  22874. #endif
  22875. /**
  22876. * \brief RIPEMD-160 context structure
  22877. */
  22878. typedef struct
  22879. {
  22880. uint32_t total[2]; /*!< number of bytes processed */
  22881. uint32_t state[5]; /*!< intermediate digest state */
  22882. unsigned char buffer[64]; /*!< data block being processed */
  22883. }
  22884. mbedtls_ripemd160_context;
  22885. /**
  22886. * \brief Initialize RIPEMD-160 context
  22887. *
  22888. * \param ctx RIPEMD-160 context to be initialized
  22889. */
  22890. void mbedtls_ripemd160_init( mbedtls_ripemd160_context *ctx );
  22891. /**
  22892. * \brief Clear RIPEMD-160 context
  22893. *
  22894. * \param ctx RIPEMD-160 context to be cleared
  22895. */
  22896. void mbedtls_ripemd160_free( mbedtls_ripemd160_context *ctx );
  22897. /**
  22898. * \brief Clone (the state of) an RIPEMD-160 context
  22899. *
  22900. * \param dst The destination context
  22901. * \param src The context to be cloned
  22902. */
  22903. void mbedtls_ripemd160_clone( mbedtls_ripemd160_context *dst,
  22904. const mbedtls_ripemd160_context *src );
  22905. /**
  22906. * \brief RIPEMD-160 context setup
  22907. *
  22908. * \param ctx context to be initialized
  22909. *
  22910. * \return 0 if successful
  22911. */
  22912. int mbedtls_ripemd160_starts_ret( mbedtls_ripemd160_context *ctx );
  22913. /**
  22914. * \brief RIPEMD-160 process buffer
  22915. *
  22916. * \param ctx RIPEMD-160 context
  22917. * \param input buffer holding the data
  22918. * \param ilen length of the input data
  22919. *
  22920. * \return 0 if successful
  22921. */
  22922. int mbedtls_ripemd160_update_ret( mbedtls_ripemd160_context *ctx,
  22923. const unsigned char *input,
  22924. size_t ilen );
  22925. /**
  22926. * \brief RIPEMD-160 final digest
  22927. *
  22928. * \param ctx RIPEMD-160 context
  22929. * \param output RIPEMD-160 checksum result
  22930. *
  22931. * \return 0 if successful
  22932. */
  22933. int mbedtls_ripemd160_finish_ret( mbedtls_ripemd160_context *ctx,
  22934. unsigned char output[20] );
  22935. /**
  22936. * \brief RIPEMD-160 process data block (internal use only)
  22937. *
  22938. * \param ctx RIPEMD-160 context
  22939. * \param data buffer holding one block of data
  22940. *
  22941. * \return 0 if successful
  22942. */
  22943. int mbedtls_internal_ripemd160_process( mbedtls_ripemd160_context *ctx,
  22944. const unsigned char data[64] );
  22945. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  22946. #if defined(MBEDTLS_DEPRECATED_WARNING)
  22947. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  22948. #else
  22949. #define MBEDTLS_DEPRECATED
  22950. #endif
  22951. /**
  22952. * \brief RIPEMD-160 context setup
  22953. *
  22954. * \deprecated Superseded by mbedtls_ripemd160_starts_ret() in 2.7.0
  22955. *
  22956. * \param ctx context to be initialized
  22957. */
  22958. MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(
  22959. mbedtls_ripemd160_context *ctx );
  22960. /**
  22961. * \brief RIPEMD-160 process buffer
  22962. *
  22963. * \deprecated Superseded by mbedtls_ripemd160_update_ret() in 2.7.0
  22964. *
  22965. * \param ctx RIPEMD-160 context
  22966. * \param input buffer holding the data
  22967. * \param ilen length of the input data
  22968. */
  22969. MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(
  22970. mbedtls_ripemd160_context *ctx,
  22971. const unsigned char *input,
  22972. size_t ilen );
  22973. /**
  22974. * \brief RIPEMD-160 final digest
  22975. *
  22976. * \deprecated Superseded by mbedtls_ripemd160_finish_ret() in 2.7.0
  22977. *
  22978. * \param ctx RIPEMD-160 context
  22979. * \param output RIPEMD-160 checksum result
  22980. */
  22981. MBEDTLS_DEPRECATED void mbedtls_ripemd160_finish(
  22982. mbedtls_ripemd160_context *ctx,
  22983. unsigned char output[20] );
  22984. /**
  22985. * \brief RIPEMD-160 process data block (internal use only)
  22986. *
  22987. * \deprecated Superseded by mbedtls_internal_ripemd160_process() in 2.7.0
  22988. *
  22989. * \param ctx RIPEMD-160 context
  22990. * \param data buffer holding one block of data
  22991. */
  22992. MBEDTLS_DEPRECATED void mbedtls_ripemd160_process(
  22993. mbedtls_ripemd160_context *ctx,
  22994. const unsigned char data[64] );
  22995. #undef MBEDTLS_DEPRECATED
  22996. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  22997. #ifdef __cplusplus
  22998. }
  22999. #endif
  23000. #else /* MBEDTLS_RIPEMD160_ALT */
  23001. #endif /* MBEDTLS_RIPEMD160_ALT */
  23002. #ifdef __cplusplus
  23003. extern "C" {
  23004. #endif
  23005. /**
  23006. * \brief Output = RIPEMD-160( input buffer )
  23007. *
  23008. * \param input buffer holding the data
  23009. * \param ilen length of the input data
  23010. * \param output RIPEMD-160 checksum result
  23011. *
  23012. * \return 0 if successful
  23013. */
  23014. int mbedtls_ripemd160_ret( const unsigned char *input,
  23015. size_t ilen,
  23016. unsigned char output[20] );
  23017. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  23018. #if defined(MBEDTLS_DEPRECATED_WARNING)
  23019. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  23020. #else
  23021. #define MBEDTLS_DEPRECATED
  23022. #endif
  23023. /**
  23024. * \brief Output = RIPEMD-160( input buffer )
  23025. *
  23026. * \deprecated Superseded by mbedtls_ripemd160_ret() in 2.7.0
  23027. *
  23028. * \param input buffer holding the data
  23029. * \param ilen length of the input data
  23030. * \param output RIPEMD-160 checksum result
  23031. */
  23032. MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input,
  23033. size_t ilen,
  23034. unsigned char output[20] );
  23035. #undef MBEDTLS_DEPRECATED
  23036. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  23037. /**
  23038. * \brief Checkup routine
  23039. *
  23040. * \return 0 if successful, or 1 if the test failed
  23041. */
  23042. int mbedtls_ripemd160_self_test( int verbose );
  23043. #ifdef __cplusplus
  23044. }
  23045. #endif
  23046. #endif /* mbedtls_ripemd160.h */
  23047. /********* Start of file include/mbedtls/version.h ************/
  23048. /**
  23049. * \file version.h
  23050. *
  23051. * \brief Run-time version information
  23052. */
  23053. /*
  23054. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  23055. * SPDX-License-Identifier: Apache-2.0
  23056. *
  23057. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  23058. * not use this file except in compliance with the License.
  23059. * You may obtain a copy of the License at
  23060. *
  23061. * http://www.apache.org/licenses/LICENSE-2.0
  23062. *
  23063. * Unless required by applicable law or agreed to in writing, software
  23064. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  23065. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23066. * See the License for the specific language governing permissions and
  23067. * limitations under the License.
  23068. *
  23069. * This file is part of mbed TLS (https://tls.mbed.org)
  23070. */
  23071. /*
  23072. * This set of compile-time defines and run-time variables can be used to
  23073. * determine the version number of the mbed TLS library used.
  23074. */
  23075. #ifndef MBEDTLS_VERSION_H
  23076. #define MBEDTLS_VERSION_H
  23077. #if !defined(MBEDTLS_CONFIG_FILE)
  23078. #else
  23079. #endif
  23080. /**
  23081. * The version number x.y.z is split into three parts.
  23082. * Major, Minor, Patchlevel
  23083. */
  23084. #define MBEDTLS_VERSION_MAJOR 2
  23085. #define MBEDTLS_VERSION_MINOR 8
  23086. #define MBEDTLS_VERSION_PATCH 0
  23087. /**
  23088. * The single version number has the following structure:
  23089. * MMNNPP00
  23090. * Major version | Minor version | Patch version
  23091. */
  23092. #define MBEDTLS_VERSION_NUMBER 0x02080000
  23093. #define MBEDTLS_VERSION_STRING "2.8.0"
  23094. #define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.8.0"
  23095. #if defined(MBEDTLS_VERSION_C)
  23096. #ifdef __cplusplus
  23097. extern "C" {
  23098. #endif
  23099. /**
  23100. * Get the version number.
  23101. *
  23102. * \return The constructed version number in the format
  23103. * MMNNPP00 (Major, Minor, Patch).
  23104. */
  23105. unsigned int mbedtls_version_get_number( void );
  23106. /**
  23107. * Get the version string ("x.y.z").
  23108. *
  23109. * \param string The string that will receive the value.
  23110. * (Should be at least 9 bytes in size)
  23111. */
  23112. void mbedtls_version_get_string( char *string );
  23113. /**
  23114. * Get the full version string ("mbed TLS x.y.z").
  23115. *
  23116. * \param string The string that will receive the value. The mbed TLS version
  23117. * string will use 18 bytes AT MOST including a terminating
  23118. * null byte.
  23119. * (So the buffer should be at least 18 bytes to receive this
  23120. * version string).
  23121. */
  23122. void mbedtls_version_get_string_full( char *string );
  23123. /**
  23124. * \brief Check if support for a feature was compiled into this
  23125. * mbed TLS binary. This allows you to see at runtime if the
  23126. * library was for instance compiled with or without
  23127. * Multi-threading support.
  23128. *
  23129. * \note only checks against defines in the sections "System
  23130. * support", "mbed TLS modules" and "mbed TLS feature
  23131. * support" in config.h
  23132. *
  23133. * \param feature The string for the define to check (e.g. "MBEDTLS_AES_C")
  23134. *
  23135. * \return 0 if the feature is present,
  23136. * -1 if the feature is not present and
  23137. * -2 if support for feature checking as a whole was not
  23138. * compiled in.
  23139. */
  23140. int mbedtls_version_check_feature( const char *feature );
  23141. #ifdef __cplusplus
  23142. }
  23143. #endif
  23144. #endif /* MBEDTLS_VERSION_C */
  23145. #endif /* version.h */
  23146. #endif /* ME_COM_MBEDTLS */